FlashPoint.c 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560
  1. /*
  2. FlashPoint.c -- FlashPoint SCCB Manager for Linux
  3. This file contains the FlashPoint SCCB Manager from BusLogic's FlashPoint
  4. Driver Developer's Kit, with minor modifications by Leonard N. Zubkoff for
  5. Linux compatibility. It was provided by BusLogic in the form of 16 separate
  6. source files, which would have unnecessarily cluttered the scsi directory, so
  7. the individual files have been combined into this single file.
  8. Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
  9. This file is available under both the GNU General Public License
  10. and a BSD-style copyright; see LICENSE.FlashPoint for details.
  11. */
  12. #ifdef CONFIG_SCSI_FLASHPOINT
  13. #define MAX_CARDS 8
  14. #undef BUSTYPE_PCI
  15. #define CRCMASK 0xA001
  16. #define FAILURE 0xFFFFFFFFL
  17. struct sccb;
  18. typedef void (*CALL_BK_FN) (struct sccb *);
  19. struct sccb_mgr_info {
  20. u32 si_baseaddr;
  21. unsigned char si_present;
  22. unsigned char si_intvect;
  23. unsigned char si_id;
  24. unsigned char si_lun;
  25. u16 si_fw_revision;
  26. u16 si_per_targ_init_sync;
  27. u16 si_per_targ_fast_nego;
  28. u16 si_per_targ_ultra_nego;
  29. u16 si_per_targ_no_disc;
  30. u16 si_per_targ_wide_nego;
  31. u16 si_mflags;
  32. unsigned char si_card_family;
  33. unsigned char si_bustype;
  34. unsigned char si_card_model[3];
  35. unsigned char si_relative_cardnum;
  36. unsigned char si_reserved[4];
  37. u32 si_OS_reserved;
  38. unsigned char si_XlatInfo[4];
  39. u32 si_reserved2[5];
  40. u32 si_secondary_range;
  41. };
  42. #define SCSI_PARITY_ENA 0x0001
  43. #define LOW_BYTE_TERM 0x0010
  44. #define HIGH_BYTE_TERM 0x0020
  45. #define BUSTYPE_PCI 0x3
  46. #define SUPPORT_16TAR_32LUN 0x0002
  47. #define SOFT_RESET 0x0004
  48. #define EXTENDED_TRANSLATION 0x0008
  49. #define POST_ALL_UNDERRRUNS 0x0040
  50. #define FLAG_SCAM_ENABLED 0x0080
  51. #define FLAG_SCAM_LEVEL2 0x0100
  52. #define HARPOON_FAMILY 0x02
  53. /* SCCB struct used for both SCCB and UCB manager compiles!
  54. * The UCB Manager treats the SCCB as it's 'native hardware structure'
  55. */
  56. /*#pragma pack(1)*/
  57. struct sccb {
  58. unsigned char OperationCode;
  59. unsigned char ControlByte;
  60. unsigned char CdbLength;
  61. unsigned char RequestSenseLength;
  62. u32 DataLength;
  63. void *DataPointer;
  64. unsigned char CcbRes[2];
  65. unsigned char HostStatus;
  66. unsigned char TargetStatus;
  67. unsigned char TargID;
  68. unsigned char Lun;
  69. unsigned char Cdb[12];
  70. unsigned char CcbRes1;
  71. unsigned char Reserved1;
  72. u32 Reserved2;
  73. u32 SensePointer;
  74. CALL_BK_FN SccbCallback; /* VOID (*SccbCallback)(); */
  75. u32 SccbIOPort; /* Identifies board base port */
  76. unsigned char SccbStatus;
  77. unsigned char SCCBRes2;
  78. u16 SccbOSFlags;
  79. u32 Sccb_XferCnt; /* actual transfer count */
  80. u32 Sccb_ATC;
  81. u32 SccbVirtDataPtr; /* virtual addr for OS/2 */
  82. u32 Sccb_res1;
  83. u16 Sccb_MGRFlags;
  84. u16 Sccb_sgseg;
  85. unsigned char Sccb_scsimsg; /* identify msg for selection */
  86. unsigned char Sccb_tag;
  87. unsigned char Sccb_scsistat;
  88. unsigned char Sccb_idmsg; /* image of last msg in */
  89. struct sccb *Sccb_forwardlink;
  90. struct sccb *Sccb_backlink;
  91. u32 Sccb_savedATC;
  92. unsigned char Save_Cdb[6];
  93. unsigned char Save_CdbLen;
  94. unsigned char Sccb_XferState;
  95. u32 Sccb_SGoffset;
  96. };
  97. #pragma pack()
  98. #define SCATTER_GATHER_COMMAND 0x02
  99. #define RESIDUAL_COMMAND 0x03
  100. #define RESIDUAL_SG_COMMAND 0x04
  101. #define RESET_COMMAND 0x81
  102. #define F_USE_CMD_Q 0x20 /*Inidcates TAGGED command. */
  103. #define TAG_TYPE_MASK 0xC0 /*Type of tag msg to send. */
  104. #define SCCB_DATA_XFER_OUT 0x10 /* Write */
  105. #define SCCB_DATA_XFER_IN 0x08 /* Read */
  106. #define NO_AUTO_REQUEST_SENSE 0x01 /* No Request Sense Buffer */
  107. #define BUS_FREE_ST 0
  108. #define SELECT_ST 1
  109. #define SELECT_BDR_ST 2 /* Select w\ Bus Device Reset */
  110. #define SELECT_SN_ST 3 /* Select w\ Sync Nego */
  111. #define SELECT_WN_ST 4 /* Select w\ Wide Data Nego */
  112. #define SELECT_Q_ST 5 /* Select w\ Tagged Q'ing */
  113. #define COMMAND_ST 6
  114. #define DATA_OUT_ST 7
  115. #define DATA_IN_ST 8
  116. #define DISCONNECT_ST 9
  117. #define ABORT_ST 11
  118. #define F_HOST_XFER_DIR 0x01
  119. #define F_ALL_XFERRED 0x02
  120. #define F_SG_XFER 0x04
  121. #define F_AUTO_SENSE 0x08
  122. #define F_ODD_BALL_CNT 0x10
  123. #define F_NO_DATA_YET 0x80
  124. #define F_STATUSLOADED 0x01
  125. #define F_DEV_SELECTED 0x04
  126. #define SCCB_COMPLETE 0x00 /* SCCB completed without error */
  127. #define SCCB_DATA_UNDER_RUN 0x0C
  128. #define SCCB_SELECTION_TIMEOUT 0x11 /* Set SCSI selection timed out */
  129. #define SCCB_DATA_OVER_RUN 0x12
  130. #define SCCB_PHASE_SEQUENCE_FAIL 0x14 /* Target bus phase sequence failure */
  131. #define SCCB_GROSS_FW_ERR 0x27 /* Major problem! */
  132. #define SCCB_BM_ERR 0x30 /* BusMaster error. */
  133. #define SCCB_PARITY_ERR 0x34 /* SCSI parity error */
  134. #define SCCB_IN_PROCESS 0x00
  135. #define SCCB_SUCCESS 0x01
  136. #define SCCB_ABORT 0x02
  137. #define SCCB_ERROR 0x04
  138. #define ORION_FW_REV 3110
  139. #define QUEUE_DEPTH 254+1 /*1 for Normal disconnect 32 for Q'ing. */
  140. #define MAX_MB_CARDS 4 /* Max. no of cards suppoerted on Mother Board */
  141. #define MAX_SCSI_TAR 16
  142. #define MAX_LUN 32
  143. #define LUN_MASK 0x1f
  144. #define SG_BUF_CNT 16 /*Number of prefetched elements. */
  145. #define SG_ELEMENT_SIZE 8 /*Eight byte per element. */
  146. #define RD_HARPOON(ioport) inb((u32)ioport)
  147. #define RDW_HARPOON(ioport) inw((u32)ioport)
  148. #define RD_HARP32(ioport,offset,data) (data = inl((u32)(ioport + offset)))
  149. #define WR_HARPOON(ioport,val) outb((u8) val, (u32)ioport)
  150. #define WRW_HARPOON(ioport,val) outw((u16)val, (u32)ioport)
  151. #define WR_HARP32(ioport,offset,data) outl(data, (u32)(ioport + offset))
  152. #define TAR_SYNC_MASK (BIT(7)+BIT(6))
  153. #define SYNC_TRYING BIT(6)
  154. #define SYNC_SUPPORTED (BIT(7)+BIT(6))
  155. #define TAR_WIDE_MASK (BIT(5)+BIT(4))
  156. #define WIDE_ENABLED BIT(4)
  157. #define WIDE_NEGOCIATED BIT(5)
  158. #define TAR_TAG_Q_MASK (BIT(3)+BIT(2))
  159. #define TAG_Q_TRYING BIT(2)
  160. #define TAG_Q_REJECT BIT(3)
  161. #define TAR_ALLOW_DISC BIT(0)
  162. #define EE_SYNC_MASK (BIT(0)+BIT(1))
  163. #define EE_SYNC_5MB BIT(0)
  164. #define EE_SYNC_10MB BIT(1)
  165. #define EE_SYNC_20MB (BIT(0)+BIT(1))
  166. #define EE_WIDE_SCSI BIT(7)
  167. struct sccb_mgr_tar_info {
  168. struct sccb *TarSelQ_Head;
  169. struct sccb *TarSelQ_Tail;
  170. unsigned char TarLUN_CA; /*Contingent Allgiance */
  171. unsigned char TarTagQ_Cnt;
  172. unsigned char TarSelQ_Cnt;
  173. unsigned char TarStatus;
  174. unsigned char TarEEValue;
  175. unsigned char TarSyncCtrl;
  176. unsigned char TarReserved[2]; /* for alignment */
  177. unsigned char LunDiscQ_Idx[MAX_LUN];
  178. unsigned char TarLUNBusy[MAX_LUN];
  179. };
  180. struct nvram_info {
  181. unsigned char niModel; /* Model No. of card */
  182. unsigned char niCardNo; /* Card no. */
  183. u32 niBaseAddr; /* Port Address of card */
  184. unsigned char niSysConf; /* Adapter Configuration byte -
  185. Byte 16 of eeprom map */
  186. unsigned char niScsiConf; /* SCSI Configuration byte -
  187. Byte 17 of eeprom map */
  188. unsigned char niScamConf; /* SCAM Configuration byte -
  189. Byte 20 of eeprom map */
  190. unsigned char niAdapId; /* Host Adapter ID -
  191. Byte 24 of eerpom map */
  192. unsigned char niSyncTbl[MAX_SCSI_TAR / 2]; /* Sync/Wide byte
  193. of targets */
  194. unsigned char niScamTbl[MAX_SCSI_TAR][4]; /* Compressed Scam name
  195. string of Targets */
  196. };
  197. #define MODEL_LT 1
  198. #define MODEL_DL 2
  199. #define MODEL_LW 3
  200. #define MODEL_DW 4
  201. struct sccb_card {
  202. struct sccb *currentSCCB;
  203. struct sccb_mgr_info *cardInfo;
  204. u32 ioPort;
  205. unsigned short cmdCounter;
  206. unsigned char discQCount;
  207. unsigned char tagQ_Lst;
  208. unsigned char cardIndex;
  209. unsigned char scanIndex;
  210. unsigned char globalFlags;
  211. unsigned char ourId;
  212. struct nvram_info *pNvRamInfo;
  213. struct sccb *discQ_Tbl[QUEUE_DEPTH];
  214. };
  215. #define F_TAG_STARTED 0x01
  216. #define F_CONLUN_IO 0x02
  217. #define F_DO_RENEGO 0x04
  218. #define F_NO_FILTER 0x08
  219. #define F_GREEN_PC 0x10
  220. #define F_HOST_XFER_ACT 0x20
  221. #define F_NEW_SCCB_CMD 0x40
  222. #define F_UPDATE_EEPROM 0x80
  223. #define ID_STRING_LENGTH 32
  224. #define TYPE_CODE0 0x63 /*Level2 Mstr (bits 7-6), */
  225. #define SLV_TYPE_CODE0 0xA3 /*Priority Bit set (bits 7-6), */
  226. #define ASSIGN_ID 0x00
  227. #define SET_P_FLAG 0x01
  228. #define CFG_CMPLT 0x03
  229. #define DOM_MSTR 0x0F
  230. #define SYNC_PTRN 0x1F
  231. #define ID_0_7 0x18
  232. #define ID_8_F 0x11
  233. #define MISC_CODE 0x14
  234. #define CLR_P_FLAG 0x18
  235. #define INIT_SELTD 0x01
  236. #define LEVEL2_TAR 0x02
  237. enum scam_id_st { ID0, ID1, ID2, ID3, ID4, ID5, ID6, ID7, ID8, ID9, ID10, ID11,
  238. ID12,
  239. ID13, ID14, ID15, ID_UNUSED, ID_UNASSIGNED, ID_ASSIGNED, LEGACY,
  240. CLR_PRIORITY, NO_ID_AVAIL
  241. };
  242. typedef struct SCCBscam_info {
  243. unsigned char id_string[ID_STRING_LENGTH];
  244. enum scam_id_st state;
  245. } SCCBSCAM_INFO;
  246. #define SMIDENT 0x80
  247. #define DISC_PRIV 0x40
  248. #define SM8BIT 0x00
  249. #define SM16BIT 0x01
  250. #define SIX_BYTE_CMD 0x06
  251. #define TWELVE_BYTE_CMD 0x0C
  252. #define ASYNC 0x00
  253. #define MAX_OFFSET 0x0F /* Maxbyteoffset for Sync Xfers */
  254. #define EEPROM_WD_CNT 256
  255. #define EEPROM_CHECK_SUM 0
  256. #define FW_SIGNATURE 2
  257. #define MODEL_NUMB_0 4
  258. #define MODEL_NUMB_2 6
  259. #define MODEL_NUMB_4 8
  260. #define SYSTEM_CONFIG 16
  261. #define SCSI_CONFIG 17
  262. #define BIOS_CONFIG 18
  263. #define SCAM_CONFIG 20
  264. #define ADAPTER_SCSI_ID 24
  265. #define IGNORE_B_SCAN 32
  266. #define SEND_START_ENA 34
  267. #define DEVICE_ENABLE 36
  268. #define SYNC_RATE_TBL 38
  269. #define SYNC_RATE_TBL01 38
  270. #define SYNC_RATE_TBL23 40
  271. #define SYNC_RATE_TBL45 42
  272. #define SYNC_RATE_TBL67 44
  273. #define SYNC_RATE_TBL89 46
  274. #define SYNC_RATE_TBLab 48
  275. #define SYNC_RATE_TBLcd 50
  276. #define SYNC_RATE_TBLef 52
  277. #define EE_SCAMBASE 256
  278. #define SCAM_ENABLED BIT(2)
  279. #define SCAM_LEVEL2 BIT(3)
  280. #define RENEGO_ENA BIT(10)
  281. #define CONNIO_ENA BIT(11)
  282. #define GREEN_PC_ENA BIT(12)
  283. #define AUTO_RATE_00 00
  284. #define AUTO_RATE_05 01
  285. #define AUTO_RATE_10 02
  286. #define AUTO_RATE_20 03
  287. #define WIDE_NEGO_BIT BIT(7)
  288. #define DISC_ENABLE_BIT BIT(6)
  289. #define hp_vendor_id_0 0x00 /* LSB */
  290. #define ORION_VEND_0 0x4B
  291. #define hp_vendor_id_1 0x01 /* MSB */
  292. #define ORION_VEND_1 0x10
  293. #define hp_device_id_0 0x02 /* LSB */
  294. #define ORION_DEV_0 0x30
  295. #define hp_device_id_1 0x03 /* MSB */
  296. #define ORION_DEV_1 0x81
  297. /* Sub Vendor ID and Sub Device ID only available in
  298. Harpoon Version 2 and higher */
  299. #define hp_sub_device_id_0 0x06 /* LSB */
  300. #define hp_semaphore 0x0C
  301. #define SCCB_MGR_ACTIVE BIT(0)
  302. #define TICKLE_ME BIT(1)
  303. #define SCCB_MGR_PRESENT BIT(3)
  304. #define BIOS_IN_USE BIT(4)
  305. #define hp_sys_ctrl 0x0F
  306. #define STOP_CLK BIT(0) /*Turn off BusMaster Clock */
  307. #define DRVR_RST BIT(1) /*Firmware Reset to 80C15 chip */
  308. #define HALT_MACH BIT(3) /*Halt State Machine */
  309. #define HARD_ABORT BIT(4) /*Hard Abort */
  310. #define hp_host_blk_cnt 0x13
  311. #define XFER_BLK64 0x06 /* 1 1 0 64 byte per block */
  312. #define BM_THRESHOLD 0x40 /* PCI mode can only xfer 16 bytes */
  313. #define hp_int_mask 0x17
  314. #define INT_CMD_COMPL BIT(0) /* DMA command complete */
  315. #define INT_EXT_STATUS BIT(1) /* Extended Status Set */
  316. #define hp_xfer_cnt_lo 0x18
  317. #define hp_xfer_cnt_hi 0x1A
  318. #define hp_xfer_cmd 0x1B
  319. #define XFER_HOST_DMA 0x00 /* 0 0 0 Transfer Host -> DMA */
  320. #define XFER_DMA_HOST 0x01 /* 0 0 1 Transfer DMA -> Host */
  321. #define XFER_HOST_AUTO 0x00 /* 0 0 Auto Transfer Size */
  322. #define XFER_DMA_8BIT 0x20 /* 0 1 8 BIT Transfer Size */
  323. #define DISABLE_INT BIT(7) /*Do not interrupt at end of cmd. */
  324. #define HOST_WRT_CMD ((DISABLE_INT + XFER_HOST_DMA + XFER_HOST_AUTO + XFER_DMA_8BIT))
  325. #define HOST_RD_CMD ((DISABLE_INT + XFER_DMA_HOST + XFER_HOST_AUTO + XFER_DMA_8BIT))
  326. #define hp_host_addr_lo 0x1C
  327. #define hp_host_addr_hmi 0x1E
  328. #define hp_ee_ctrl 0x22
  329. #define EXT_ARB_ACK BIT(7)
  330. #define SCSI_TERM_ENA_H BIT(6) /* SCSI high byte terminator */
  331. #define SEE_MS BIT(5)
  332. #define SEE_CS BIT(3)
  333. #define SEE_CLK BIT(2)
  334. #define SEE_DO BIT(1)
  335. #define SEE_DI BIT(0)
  336. #define EE_READ 0x06
  337. #define EE_WRITE 0x05
  338. #define EWEN 0x04
  339. #define EWEN_ADDR 0x03C0
  340. #define EWDS 0x04
  341. #define EWDS_ADDR 0x0000
  342. #define hp_bm_ctrl 0x26
  343. #define SCSI_TERM_ENA_L BIT(0) /*Enable/Disable external terminators */
  344. #define FLUSH_XFER_CNTR BIT(1) /*Flush transfer counter */
  345. #define FORCE1_XFER BIT(5) /*Always xfer one byte in byte mode */
  346. #define FAST_SINGLE BIT(6) /*?? */
  347. #define BMCTRL_DEFAULT (FORCE1_XFER|FAST_SINGLE|SCSI_TERM_ENA_L)
  348. #define hp_sg_addr 0x28
  349. #define hp_page_ctrl 0x29
  350. #define SCATTER_EN BIT(0)
  351. #define SGRAM_ARAM BIT(1)
  352. #define G_INT_DISABLE BIT(3) /* Enable/Disable all Interrupts */
  353. #define NARROW_SCSI_CARD BIT(4) /* NARROW/WIDE SCSI config pin */
  354. #define hp_pci_stat_cfg 0x2D
  355. #define REC_MASTER_ABORT BIT(5) /*received Master abort */
  356. #define hp_rev_num 0x33
  357. #define hp_stack_data 0x34
  358. #define hp_stack_addr 0x35
  359. #define hp_ext_status 0x36
  360. #define BM_FORCE_OFF BIT(0) /*Bus Master is forced to get off */
  361. #define PCI_TGT_ABORT BIT(0) /*PCI bus master transaction aborted */
  362. #define PCI_DEV_TMOUT BIT(1) /*PCI Device Time out */
  363. #define CMD_ABORTED BIT(4) /*Command aborted */
  364. #define BM_PARITY_ERR BIT(5) /*parity error on data received */
  365. #define PIO_OVERRUN BIT(6) /*Slave data overrun */
  366. #define BM_CMD_BUSY BIT(7) /*Bus master transfer command busy */
  367. #define BAD_EXT_STATUS (BM_FORCE_OFF | PCI_DEV_TMOUT | CMD_ABORTED | \
  368. BM_PARITY_ERR | PIO_OVERRUN)
  369. #define hp_int_status 0x37
  370. #define EXT_STATUS_ON BIT(1) /*Extended status is valid */
  371. #define SCSI_INTERRUPT BIT(2) /*Global indication of a SCSI int. */
  372. #define INT_ASSERTED BIT(5) /* */
  373. #define hp_fifo_cnt 0x38
  374. #define hp_intena 0x40
  375. #define RESET BIT(7)
  376. #define PROG_HLT BIT(6)
  377. #define PARITY BIT(5)
  378. #define FIFO BIT(4)
  379. #define SEL BIT(3)
  380. #define SCAM_SEL BIT(2)
  381. #define RSEL BIT(1)
  382. #define TIMEOUT BIT(0)
  383. #define BUS_FREE BIT(15)
  384. #define XFER_CNT_0 BIT(14)
  385. #define PHASE BIT(13)
  386. #define IUNKWN BIT(12)
  387. #define ICMD_COMP BIT(11)
  388. #define ITICKLE BIT(10)
  389. #define IDO_STRT BIT(9)
  390. #define ITAR_DISC BIT(8)
  391. #define AUTO_INT (BIT(12)+BIT(11)+BIT(10)+BIT(9)+BIT(8))
  392. #define CLR_ALL_INT 0xFFFF
  393. #define CLR_ALL_INT_1 0xFF00
  394. #define hp_intstat 0x42
  395. #define hp_scsisig 0x44
  396. #define SCSI_SEL BIT(7)
  397. #define SCSI_BSY BIT(6)
  398. #define SCSI_REQ BIT(5)
  399. #define SCSI_ACK BIT(4)
  400. #define SCSI_ATN BIT(3)
  401. #define SCSI_CD BIT(2)
  402. #define SCSI_MSG BIT(1)
  403. #define SCSI_IOBIT BIT(0)
  404. #define S_SCSI_PHZ (BIT(2)+BIT(1)+BIT(0))
  405. #define S_MSGO_PH (BIT(2)+BIT(1) )
  406. #define S_MSGI_PH (BIT(2)+BIT(1)+BIT(0))
  407. #define S_DATAI_PH ( BIT(0))
  408. #define S_DATAO_PH 0x00
  409. #define S_ILL_PH ( BIT(1) )
  410. #define hp_scsictrl_0 0x45
  411. #define SEL_TAR BIT(6)
  412. #define ENA_ATN BIT(4)
  413. #define ENA_RESEL BIT(2)
  414. #define SCSI_RST BIT(1)
  415. #define ENA_SCAM_SEL BIT(0)
  416. #define hp_portctrl_0 0x46
  417. #define SCSI_PORT BIT(7)
  418. #define SCSI_INBIT BIT(6)
  419. #define DMA_PORT BIT(5)
  420. #define DMA_RD BIT(4)
  421. #define HOST_PORT BIT(3)
  422. #define HOST_WRT BIT(2)
  423. #define SCSI_BUS_EN BIT(1)
  424. #define START_TO BIT(0)
  425. #define hp_scsireset 0x47
  426. #define SCSI_INI BIT(6)
  427. #define SCAM_EN BIT(5)
  428. #define DMA_RESET BIT(3)
  429. #define HPSCSI_RESET BIT(2)
  430. #define PROG_RESET BIT(1)
  431. #define FIFO_CLR BIT(0)
  432. #define hp_xfercnt_0 0x48
  433. #define hp_xfercnt_2 0x4A
  434. #define hp_fifodata_0 0x4C
  435. #define hp_addstat 0x4E
  436. #define SCAM_TIMER BIT(7)
  437. #define SCSI_MODE8 BIT(3)
  438. #define SCSI_PAR_ERR BIT(0)
  439. #define hp_prgmcnt_0 0x4F
  440. #define hp_selfid_0 0x50
  441. #define hp_selfid_1 0x51
  442. #define hp_arb_id 0x52
  443. #define hp_select_id 0x53
  444. #define hp_synctarg_base 0x54
  445. #define hp_synctarg_12 0x54
  446. #define hp_synctarg_13 0x55
  447. #define hp_synctarg_14 0x56
  448. #define hp_synctarg_15 0x57
  449. #define hp_synctarg_8 0x58
  450. #define hp_synctarg_9 0x59
  451. #define hp_synctarg_10 0x5A
  452. #define hp_synctarg_11 0x5B
  453. #define hp_synctarg_4 0x5C
  454. #define hp_synctarg_5 0x5D
  455. #define hp_synctarg_6 0x5E
  456. #define hp_synctarg_7 0x5F
  457. #define hp_synctarg_0 0x60
  458. #define hp_synctarg_1 0x61
  459. #define hp_synctarg_2 0x62
  460. #define hp_synctarg_3 0x63
  461. #define NARROW_SCSI BIT(4)
  462. #define DEFAULT_OFFSET 0x0F
  463. #define hp_autostart_0 0x64
  464. #define hp_autostart_1 0x65
  465. #define hp_autostart_3 0x67
  466. #define AUTO_IMMED BIT(5)
  467. #define SELECT BIT(6)
  468. #define END_DATA (BIT(7)+BIT(6))
  469. #define hp_gp_reg_0 0x68
  470. #define hp_gp_reg_1 0x69
  471. #define hp_gp_reg_3 0x6B
  472. #define hp_seltimeout 0x6C
  473. #define TO_4ms 0x67 /* 3.9959ms */
  474. #define TO_5ms 0x03 /* 4.9152ms */
  475. #define TO_10ms 0x07 /* 11.xxxms */
  476. #define TO_250ms 0x99 /* 250.68ms */
  477. #define TO_290ms 0xB1 /* 289.99ms */
  478. #define hp_clkctrl_0 0x6D
  479. #define PWR_DWN BIT(6)
  480. #define ACTdeassert BIT(4)
  481. #define CLK_40MHZ (BIT(1) + BIT(0))
  482. #define CLKCTRL_DEFAULT (ACTdeassert | CLK_40MHZ)
  483. #define hp_fiforead 0x6E
  484. #define hp_fifowrite 0x6F
  485. #define hp_offsetctr 0x70
  486. #define hp_xferstat 0x71
  487. #define FIFO_EMPTY BIT(6)
  488. #define hp_portctrl_1 0x72
  489. #define CHK_SCSI_P BIT(3)
  490. #define HOST_MODE8 BIT(0)
  491. #define hp_xfer_pad 0x73
  492. #define ID_UNLOCK BIT(3)
  493. #define hp_scsidata_0 0x74
  494. #define hp_scsidata_1 0x75
  495. #define hp_aramBase 0x80
  496. #define BIOS_DATA_OFFSET 0x60
  497. #define BIOS_RELATIVE_CARD 0x64
  498. #define AR3 (BIT(9) + BIT(8))
  499. #define SDATA BIT(10)
  500. #define CRD_OP BIT(11) /* Cmp Reg. w/ Data */
  501. #define CRR_OP BIT(12) /* Cmp Reg. w. Reg. */
  502. #define CPE_OP (BIT(14)+BIT(11)) /* Cmp SCSI phs & Branch EQ */
  503. #define CPN_OP (BIT(14)+BIT(12)) /* Cmp SCSI phs & Branch NOT EQ */
  504. #define ADATA_OUT 0x00
  505. #define ADATA_IN BIT(8)
  506. #define ACOMMAND BIT(10)
  507. #define ASTATUS (BIT(10)+BIT(8))
  508. #define AMSG_OUT (BIT(10)+BIT(9))
  509. #define AMSG_IN (BIT(10)+BIT(9)+BIT(8))
  510. #define BRH_OP BIT(13) /* Branch */
  511. #define ALWAYS 0x00
  512. #define EQUAL BIT(8)
  513. #define NOT_EQ BIT(9)
  514. #define TCB_OP (BIT(13)+BIT(11)) /* Test condition & branch */
  515. #define FIFO_0 BIT(10)
  516. #define MPM_OP BIT(15) /* Match phase and move data */
  517. #define MRR_OP BIT(14) /* Move DReg. to Reg. */
  518. #define S_IDREG (BIT(2)+BIT(1)+BIT(0))
  519. #define D_AR0 0x00
  520. #define D_AR1 BIT(0)
  521. #define D_BUCKET (BIT(2) + BIT(1) + BIT(0))
  522. #define RAT_OP (BIT(14)+BIT(13)+BIT(11))
  523. #define SSI_OP (BIT(15)+BIT(11))
  524. #define SSI_ITAR_DISC (ITAR_DISC >> 8)
  525. #define SSI_IDO_STRT (IDO_STRT >> 8)
  526. #define SSI_ICMD_COMP (ICMD_COMP >> 8)
  527. #define SSI_ITICKLE (ITICKLE >> 8)
  528. #define SSI_IUNKWN (IUNKWN >> 8)
  529. #define SSI_INO_CC (IUNKWN >> 8)
  530. #define SSI_IRFAIL (IUNKWN >> 8)
  531. #define NP 0x10 /*Next Phase */
  532. #define NTCMD 0x02 /*Non- Tagged Command start */
  533. #define CMDPZ 0x04 /*Command phase */
  534. #define DINT 0x12 /*Data Out/In interrupt */
  535. #define DI 0x13 /*Data Out */
  536. #define DC 0x19 /*Disconnect Message */
  537. #define ST 0x1D /*Status Phase */
  538. #define UNKNWN 0x24 /*Unknown bus action */
  539. #define CC 0x25 /*Command Completion failure */
  540. #define TICK 0x26 /*New target reselected us. */
  541. #define SELCHK 0x28 /*Select & Check SCSI ID latch reg */
  542. #define ID_MSG_STRT hp_aramBase + 0x00
  543. #define NON_TAG_ID_MSG hp_aramBase + 0x06
  544. #define CMD_STRT hp_aramBase + 0x08
  545. #define SYNC_MSGS hp_aramBase + 0x08
  546. #define TAG_STRT 0x00
  547. #define DISCONNECT_START 0x10/2
  548. #define END_DATA_START 0x14/2
  549. #define CMD_ONLY_STRT CMDPZ/2
  550. #define SELCHK_STRT SELCHK/2
  551. #define GET_XFER_CNT(port, xfercnt) {RD_HARP32(port,hp_xfercnt_0,xfercnt); xfercnt &= 0xFFFFFF;}
  552. /* #define GET_XFER_CNT(port, xfercnt) (xfercnt = RD_HARPOON(port+hp_xfercnt_2), \
  553. xfercnt <<= 16,\
  554. xfercnt |= RDW_HARPOON((unsigned short)(port+hp_xfercnt_0)))
  555. */
  556. #define HP_SETUP_ADDR_CNT(port,addr,count) (WRW_HARPOON((port+hp_host_addr_lo), (unsigned short)(addr & 0x0000FFFFL)),\
  557. addr >>= 16,\
  558. WRW_HARPOON((port+hp_host_addr_hmi), (unsigned short)(addr & 0x0000FFFFL)),\
  559. WR_HARP32(port,hp_xfercnt_0,count),\
  560. WRW_HARPOON((port+hp_xfer_cnt_lo), (unsigned short)(count & 0x0000FFFFL)),\
  561. count >>= 16,\
  562. WR_HARPOON(port+hp_xfer_cnt_hi, (count & 0xFF)))
  563. #define ACCEPT_MSG(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
  564. WR_HARPOON(port+hp_scsisig, S_ILL_PH);}
  565. #define ACCEPT_MSG_ATN(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
  566. WR_HARPOON(port+hp_scsisig, (S_ILL_PH|SCSI_ATN));}
  567. #define DISABLE_AUTO(port) (WR_HARPOON(port+hp_scsireset, PROG_RESET),\
  568. WR_HARPOON(port+hp_scsireset, 0x00))
  569. #define ARAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
  570. (RD_HARPOON(p_port+hp_page_ctrl) | SGRAM_ARAM)))
  571. #define SGRAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
  572. (RD_HARPOON(p_port+hp_page_ctrl) & ~SGRAM_ARAM)))
  573. #define MDISABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
  574. (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE)))
  575. #define MENABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
  576. (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE)))
  577. static unsigned char FPT_sisyncn(u32 port, unsigned char p_card,
  578. unsigned char syncFlag);
  579. static void FPT_ssel(u32 port, unsigned char p_card);
  580. static void FPT_sres(u32 port, unsigned char p_card,
  581. struct sccb_card *pCurrCard);
  582. static void FPT_shandem(u32 port, unsigned char p_card,
  583. struct sccb *pCurrSCCB);
  584. static void FPT_stsyncn(u32 port, unsigned char p_card);
  585. static void FPT_sisyncr(u32 port, unsigned char sync_pulse,
  586. unsigned char offset);
  587. static void FPT_sssyncv(u32 p_port, unsigned char p_id,
  588. unsigned char p_sync_value,
  589. struct sccb_mgr_tar_info *currTar_Info);
  590. static void FPT_sresb(u32 port, unsigned char p_card);
  591. static void FPT_sxfrp(u32 p_port, unsigned char p_card);
  592. static void FPT_schkdd(u32 port, unsigned char p_card);
  593. static unsigned char FPT_RdStack(u32 port, unsigned char index);
  594. static void FPT_WrStack(u32 portBase, unsigned char index,
  595. unsigned char data);
  596. static unsigned char FPT_ChkIfChipInitialized(u32 ioPort);
  597. static void FPT_SendMsg(u32 port, unsigned char message);
  598. static void FPT_queueFlushTargSccb(unsigned char p_card, unsigned char thisTarg,
  599. unsigned char error_code);
  600. static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card);
  601. static void FPT_RNVRamData(struct nvram_info *pNvRamInfo);
  602. static unsigned char FPT_siwidn(u32 port, unsigned char p_card);
  603. static void FPT_stwidn(u32 port, unsigned char p_card);
  604. static void FPT_siwidr(u32 port, unsigned char width);
  605. static void FPT_queueSelectFail(struct sccb_card *pCurrCard,
  606. unsigned char p_card);
  607. static void FPT_queueDisconnect(struct sccb *p_SCCB, unsigned char p_card);
  608. static void FPT_queueCmdComplete(struct sccb_card *pCurrCard,
  609. struct sccb *p_SCCB, unsigned char p_card);
  610. static void FPT_queueSearchSelect(struct sccb_card *pCurrCard,
  611. unsigned char p_card);
  612. static void FPT_queueFlushSccb(unsigned char p_card, unsigned char error_code);
  613. static void FPT_queueAddSccb(struct sccb *p_SCCB, unsigned char card);
  614. static unsigned char FPT_queueFindSccb(struct sccb *p_SCCB,
  615. unsigned char p_card);
  616. static void FPT_utilUpdateResidual(struct sccb *p_SCCB);
  617. static unsigned short FPT_CalcCrc16(unsigned char buffer[]);
  618. static unsigned char FPT_CalcLrc(unsigned char buffer[]);
  619. static void FPT_Wait1Second(u32 p_port);
  620. static void FPT_Wait(u32 p_port, unsigned char p_delay);
  621. static void FPT_utilEEWriteOnOff(u32 p_port, unsigned char p_mode);
  622. static void FPT_utilEEWrite(u32 p_port, unsigned short ee_data,
  623. unsigned short ee_addr);
  624. static unsigned short FPT_utilEERead(u32 p_port,
  625. unsigned short ee_addr);
  626. static unsigned short FPT_utilEEReadOrg(u32 p_port,
  627. unsigned short ee_addr);
  628. static void FPT_utilEESendCmdAddr(u32 p_port, unsigned char ee_cmd,
  629. unsigned short ee_addr);
  630. static void FPT_phaseDataOut(u32 port, unsigned char p_card);
  631. static void FPT_phaseDataIn(u32 port, unsigned char p_card);
  632. static void FPT_phaseCommand(u32 port, unsigned char p_card);
  633. static void FPT_phaseStatus(u32 port, unsigned char p_card);
  634. static void FPT_phaseMsgOut(u32 port, unsigned char p_card);
  635. static void FPT_phaseMsgIn(u32 port, unsigned char p_card);
  636. static void FPT_phaseIllegal(u32 port, unsigned char p_card);
  637. static void FPT_phaseDecode(u32 port, unsigned char p_card);
  638. static void FPT_phaseChkFifo(u32 port, unsigned char p_card);
  639. static void FPT_phaseBusFree(u32 p_port, unsigned char p_card);
  640. static void FPT_XbowInit(u32 port, unsigned char scamFlg);
  641. static void FPT_BusMasterInit(u32 p_port);
  642. static void FPT_DiagEEPROM(u32 p_port);
  643. static void FPT_dataXferProcessor(u32 port,
  644. struct sccb_card *pCurrCard);
  645. static void FPT_busMstrSGDataXferStart(u32 port,
  646. struct sccb *pCurrSCCB);
  647. static void FPT_busMstrDataXferStart(u32 port,
  648. struct sccb *pCurrSCCB);
  649. static void FPT_hostDataXferAbort(u32 port, unsigned char p_card,
  650. struct sccb *pCurrSCCB);
  651. static void FPT_hostDataXferRestart(struct sccb *currSCCB);
  652. static unsigned char FPT_SccbMgr_bad_isr(u32 p_port,
  653. unsigned char p_card,
  654. struct sccb_card *pCurrCard,
  655. unsigned short p_int);
  656. static void FPT_SccbMgrTableInitAll(void);
  657. static void FPT_SccbMgrTableInitCard(struct sccb_card *pCurrCard,
  658. unsigned char p_card);
  659. static void FPT_SccbMgrTableInitTarget(unsigned char p_card,
  660. unsigned char target);
  661. static void FPT_scini(unsigned char p_card, unsigned char p_our_id,
  662. unsigned char p_power_up);
  663. static int FPT_scarb(u32 p_port, unsigned char p_sel_type);
  664. static void FPT_scbusf(u32 p_port);
  665. static void FPT_scsel(u32 p_port);
  666. static void FPT_scasid(unsigned char p_card, u32 p_port);
  667. static unsigned char FPT_scxferc(u32 p_port, unsigned char p_data);
  668. static unsigned char FPT_scsendi(u32 p_port,
  669. unsigned char p_id_string[]);
  670. static unsigned char FPT_sciso(u32 p_port,
  671. unsigned char p_id_string[]);
  672. static void FPT_scwirod(u32 p_port, unsigned char p_data_bit);
  673. static void FPT_scwiros(u32 p_port, unsigned char p_data_bit);
  674. static unsigned char FPT_scvalq(unsigned char p_quintet);
  675. static unsigned char FPT_scsell(u32 p_port, unsigned char targ_id);
  676. static void FPT_scwtsel(u32 p_port);
  677. static void FPT_inisci(unsigned char p_card, u32 p_port,
  678. unsigned char p_our_id);
  679. static void FPT_scsavdi(unsigned char p_card, u32 p_port);
  680. static unsigned char FPT_scmachid(unsigned char p_card,
  681. unsigned char p_id_string[]);
  682. static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card);
  683. static void FPT_autoLoadDefaultMap(u32 p_port);
  684. static struct sccb_mgr_tar_info FPT_sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR] =
  685. { {{0}} };
  686. static struct sccb_card FPT_BL_Card[MAX_CARDS] = { {0} };
  687. static SCCBSCAM_INFO FPT_scamInfo[MAX_SCSI_TAR] = { {{0}} };
  688. static struct nvram_info FPT_nvRamInfo[MAX_MB_CARDS] = { {0} };
  689. static unsigned char FPT_mbCards = 0;
  690. static unsigned char FPT_scamHAString[] =
  691. { 0x63, 0x07, 'B', 'U', 'S', 'L', 'O', 'G', 'I', 'C',
  692. ' ', 'B', 'T', '-', '9', '3', '0',
  693. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  694. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  695. };
  696. static unsigned short FPT_default_intena = 0;
  697. static void (*FPT_s_PhaseTbl[8]) (u32, unsigned char) = {
  698. 0};
  699. /*---------------------------------------------------------------------
  700. *
  701. * Function: FlashPoint_ProbeHostAdapter
  702. *
  703. * Description: Setup and/or Search for cards and return info to caller.
  704. *
  705. *---------------------------------------------------------------------*/
  706. static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo)
  707. {
  708. static unsigned char first_time = 1;
  709. unsigned char i, j, id, ScamFlg;
  710. unsigned short temp, temp2, temp3, temp4, temp5, temp6;
  711. u32 ioport;
  712. struct nvram_info *pCurrNvRam;
  713. ioport = pCardInfo->si_baseaddr;
  714. if (RD_HARPOON(ioport + hp_vendor_id_0) != ORION_VEND_0)
  715. return (int)FAILURE;
  716. if ((RD_HARPOON(ioport + hp_vendor_id_1) != ORION_VEND_1))
  717. return (int)FAILURE;
  718. if ((RD_HARPOON(ioport + hp_device_id_0) != ORION_DEV_0))
  719. return (int)FAILURE;
  720. if ((RD_HARPOON(ioport + hp_device_id_1) != ORION_DEV_1))
  721. return (int)FAILURE;
  722. if (RD_HARPOON(ioport + hp_rev_num) != 0x0f) {
  723. /* For new Harpoon then check for sub_device ID LSB
  724. the bits(0-3) must be all ZERO for compatible with
  725. current version of SCCBMgr, else skip this Harpoon
  726. device. */
  727. if (RD_HARPOON(ioport + hp_sub_device_id_0) & 0x0f)
  728. return (int)FAILURE;
  729. }
  730. if (first_time) {
  731. FPT_SccbMgrTableInitAll();
  732. first_time = 0;
  733. FPT_mbCards = 0;
  734. }
  735. if (FPT_RdStack(ioport, 0) != 0x00) {
  736. if (FPT_ChkIfChipInitialized(ioport) == 0) {
  737. pCurrNvRam = NULL;
  738. WR_HARPOON(ioport + hp_semaphore, 0x00);
  739. FPT_XbowInit(ioport, 0); /*Must Init the SCSI before attempting */
  740. FPT_DiagEEPROM(ioport);
  741. } else {
  742. if (FPT_mbCards < MAX_MB_CARDS) {
  743. pCurrNvRam = &FPT_nvRamInfo[FPT_mbCards];
  744. FPT_mbCards++;
  745. pCurrNvRam->niBaseAddr = ioport;
  746. FPT_RNVRamData(pCurrNvRam);
  747. } else
  748. return (int)FAILURE;
  749. }
  750. } else
  751. pCurrNvRam = NULL;
  752. WR_HARPOON(ioport + hp_clkctrl_0, CLKCTRL_DEFAULT);
  753. WR_HARPOON(ioport + hp_sys_ctrl, 0x00);
  754. if (pCurrNvRam)
  755. pCardInfo->si_id = pCurrNvRam->niAdapId;
  756. else
  757. pCardInfo->si_id =
  758. (unsigned
  759. char)(FPT_utilEERead(ioport,
  760. (ADAPTER_SCSI_ID /
  761. 2)) & (unsigned char)0x0FF);
  762. pCardInfo->si_lun = 0x00;
  763. pCardInfo->si_fw_revision = ORION_FW_REV;
  764. temp2 = 0x0000;
  765. temp3 = 0x0000;
  766. temp4 = 0x0000;
  767. temp5 = 0x0000;
  768. temp6 = 0x0000;
  769. for (id = 0; id < (16 / 2); id++) {
  770. if (pCurrNvRam) {
  771. temp = (unsigned short)pCurrNvRam->niSyncTbl[id];
  772. temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
  773. (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
  774. } else
  775. temp =
  776. FPT_utilEERead(ioport,
  777. (unsigned short)((SYNC_RATE_TBL / 2)
  778. + id));
  779. for (i = 0; i < 2; temp >>= 8, i++) {
  780. temp2 >>= 1;
  781. temp3 >>= 1;
  782. temp4 >>= 1;
  783. temp5 >>= 1;
  784. temp6 >>= 1;
  785. switch (temp & 0x3) {
  786. case AUTO_RATE_20: /* Synchronous, 20 mega-transfers/second */
  787. temp6 |= 0x8000;
  788. fallthrough;
  789. case AUTO_RATE_10: /* Synchronous, 10 mega-transfers/second */
  790. temp5 |= 0x8000;
  791. fallthrough;
  792. case AUTO_RATE_05: /* Synchronous, 5 mega-transfers/second */
  793. temp2 |= 0x8000;
  794. fallthrough;
  795. case AUTO_RATE_00: /* Asynchronous */
  796. break;
  797. }
  798. if (temp & DISC_ENABLE_BIT)
  799. temp3 |= 0x8000;
  800. if (temp & WIDE_NEGO_BIT)
  801. temp4 |= 0x8000;
  802. }
  803. }
  804. pCardInfo->si_per_targ_init_sync = temp2;
  805. pCardInfo->si_per_targ_no_disc = temp3;
  806. pCardInfo->si_per_targ_wide_nego = temp4;
  807. pCardInfo->si_per_targ_fast_nego = temp5;
  808. pCardInfo->si_per_targ_ultra_nego = temp6;
  809. if (pCurrNvRam)
  810. i = pCurrNvRam->niSysConf;
  811. else
  812. i = (unsigned
  813. char)(FPT_utilEERead(ioport, (SYSTEM_CONFIG / 2)));
  814. if (pCurrNvRam)
  815. ScamFlg = pCurrNvRam->niScamConf;
  816. else
  817. ScamFlg =
  818. (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2);
  819. pCardInfo->si_mflags = 0x0000;
  820. if (i & 0x01)
  821. pCardInfo->si_mflags |= SCSI_PARITY_ENA;
  822. if (!(i & 0x02))
  823. pCardInfo->si_mflags |= SOFT_RESET;
  824. if (i & 0x10)
  825. pCardInfo->si_mflags |= EXTENDED_TRANSLATION;
  826. if (ScamFlg & SCAM_ENABLED)
  827. pCardInfo->si_mflags |= FLAG_SCAM_ENABLED;
  828. if (ScamFlg & SCAM_LEVEL2)
  829. pCardInfo->si_mflags |= FLAG_SCAM_LEVEL2;
  830. j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
  831. if (i & 0x04) {
  832. j |= SCSI_TERM_ENA_L;
  833. }
  834. WR_HARPOON(ioport + hp_bm_ctrl, j);
  835. j = (RD_HARPOON(ioport + hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
  836. if (i & 0x08) {
  837. j |= SCSI_TERM_ENA_H;
  838. }
  839. WR_HARPOON(ioport + hp_ee_ctrl, j);
  840. if (!(RD_HARPOON(ioport + hp_page_ctrl) & NARROW_SCSI_CARD))
  841. pCardInfo->si_mflags |= SUPPORT_16TAR_32LUN;
  842. pCardInfo->si_card_family = HARPOON_FAMILY;
  843. pCardInfo->si_bustype = BUSTYPE_PCI;
  844. if (pCurrNvRam) {
  845. pCardInfo->si_card_model[0] = '9';
  846. switch (pCurrNvRam->niModel & 0x0f) {
  847. case MODEL_LT:
  848. pCardInfo->si_card_model[1] = '3';
  849. pCardInfo->si_card_model[2] = '0';
  850. break;
  851. case MODEL_LW:
  852. pCardInfo->si_card_model[1] = '5';
  853. pCardInfo->si_card_model[2] = '0';
  854. break;
  855. case MODEL_DL:
  856. pCardInfo->si_card_model[1] = '3';
  857. pCardInfo->si_card_model[2] = '2';
  858. break;
  859. case MODEL_DW:
  860. pCardInfo->si_card_model[1] = '5';
  861. pCardInfo->si_card_model[2] = '2';
  862. break;
  863. }
  864. } else {
  865. temp = FPT_utilEERead(ioport, (MODEL_NUMB_0 / 2));
  866. pCardInfo->si_card_model[0] = (unsigned char)(temp >> 8);
  867. temp = FPT_utilEERead(ioport, (MODEL_NUMB_2 / 2));
  868. pCardInfo->si_card_model[1] = (unsigned char)(temp & 0x00FF);
  869. pCardInfo->si_card_model[2] = (unsigned char)(temp >> 8);
  870. }
  871. if (pCardInfo->si_card_model[1] == '3') {
  872. if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
  873. pCardInfo->si_mflags |= LOW_BYTE_TERM;
  874. } else if (pCardInfo->si_card_model[2] == '0') {
  875. temp = RD_HARPOON(ioport + hp_xfer_pad);
  876. WR_HARPOON(ioport + hp_xfer_pad, (temp & ~BIT(4)));
  877. if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
  878. pCardInfo->si_mflags |= LOW_BYTE_TERM;
  879. WR_HARPOON(ioport + hp_xfer_pad, (temp | BIT(4)));
  880. if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
  881. pCardInfo->si_mflags |= HIGH_BYTE_TERM;
  882. WR_HARPOON(ioport + hp_xfer_pad, temp);
  883. } else {
  884. temp = RD_HARPOON(ioport + hp_ee_ctrl);
  885. temp2 = RD_HARPOON(ioport + hp_xfer_pad);
  886. WR_HARPOON(ioport + hp_ee_ctrl, (temp | SEE_CS));
  887. WR_HARPOON(ioport + hp_xfer_pad, (temp2 | BIT(4)));
  888. temp3 = 0;
  889. for (i = 0; i < 8; i++) {
  890. temp3 <<= 1;
  891. if (!(RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)))
  892. temp3 |= 1;
  893. WR_HARPOON(ioport + hp_xfer_pad, (temp2 & ~BIT(4)));
  894. WR_HARPOON(ioport + hp_xfer_pad, (temp2 | BIT(4)));
  895. }
  896. WR_HARPOON(ioport + hp_ee_ctrl, temp);
  897. WR_HARPOON(ioport + hp_xfer_pad, temp2);
  898. if (!(temp3 & BIT(7)))
  899. pCardInfo->si_mflags |= LOW_BYTE_TERM;
  900. if (!(temp3 & BIT(6)))
  901. pCardInfo->si_mflags |= HIGH_BYTE_TERM;
  902. }
  903. ARAM_ACCESS(ioport);
  904. for (i = 0; i < 4; i++) {
  905. pCardInfo->si_XlatInfo[i] =
  906. RD_HARPOON(ioport + hp_aramBase + BIOS_DATA_OFFSET + i);
  907. }
  908. /* return with -1 if no sort, else return with
  909. logical card number sorted by BIOS (zero-based) */
  910. pCardInfo->si_relative_cardnum =
  911. (unsigned
  912. char)(RD_HARPOON(ioport + hp_aramBase + BIOS_RELATIVE_CARD) - 1);
  913. SGRAM_ACCESS(ioport);
  914. FPT_s_PhaseTbl[0] = FPT_phaseDataOut;
  915. FPT_s_PhaseTbl[1] = FPT_phaseDataIn;
  916. FPT_s_PhaseTbl[2] = FPT_phaseIllegal;
  917. FPT_s_PhaseTbl[3] = FPT_phaseIllegal;
  918. FPT_s_PhaseTbl[4] = FPT_phaseCommand;
  919. FPT_s_PhaseTbl[5] = FPT_phaseStatus;
  920. FPT_s_PhaseTbl[6] = FPT_phaseMsgOut;
  921. FPT_s_PhaseTbl[7] = FPT_phaseMsgIn;
  922. pCardInfo->si_present = 0x01;
  923. return 0;
  924. }
  925. /*---------------------------------------------------------------------
  926. *
  927. * Function: FlashPoint_HardwareResetHostAdapter
  928. *
  929. * Description: Setup adapter for normal operation (hard reset).
  930. *
  931. *---------------------------------------------------------------------*/
  932. static void *FlashPoint_HardwareResetHostAdapter(struct sccb_mgr_info
  933. *pCardInfo)
  934. {
  935. struct sccb_card *CurrCard = NULL;
  936. struct nvram_info *pCurrNvRam;
  937. unsigned char i, j, thisCard, ScamFlg;
  938. unsigned short temp, sync_bit_map, id;
  939. u32 ioport;
  940. ioport = pCardInfo->si_baseaddr;
  941. for (thisCard = 0; thisCard <= MAX_CARDS; thisCard++) {
  942. if (thisCard == MAX_CARDS)
  943. return (void *)FAILURE;
  944. if (FPT_BL_Card[thisCard].ioPort == ioport) {
  945. CurrCard = &FPT_BL_Card[thisCard];
  946. FPT_SccbMgrTableInitCard(CurrCard, thisCard);
  947. break;
  948. }
  949. else if (FPT_BL_Card[thisCard].ioPort == 0x00) {
  950. FPT_BL_Card[thisCard].ioPort = ioport;
  951. CurrCard = &FPT_BL_Card[thisCard];
  952. if (FPT_mbCards)
  953. for (i = 0; i < FPT_mbCards; i++) {
  954. if (CurrCard->ioPort ==
  955. FPT_nvRamInfo[i].niBaseAddr)
  956. CurrCard->pNvRamInfo =
  957. &FPT_nvRamInfo[i];
  958. }
  959. FPT_SccbMgrTableInitCard(CurrCard, thisCard);
  960. CurrCard->cardIndex = thisCard;
  961. CurrCard->cardInfo = pCardInfo;
  962. break;
  963. }
  964. }
  965. pCurrNvRam = CurrCard->pNvRamInfo;
  966. if (pCurrNvRam) {
  967. ScamFlg = pCurrNvRam->niScamConf;
  968. } else {
  969. ScamFlg =
  970. (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2);
  971. }
  972. FPT_BusMasterInit(ioport);
  973. FPT_XbowInit(ioport, ScamFlg);
  974. FPT_autoLoadDefaultMap(ioport);
  975. for (i = 0, id = 0x01; i != pCardInfo->si_id; i++, id <<= 1) {
  976. }
  977. WR_HARPOON(ioport + hp_selfid_0, id);
  978. WR_HARPOON(ioport + hp_selfid_1, 0x00);
  979. WR_HARPOON(ioport + hp_arb_id, pCardInfo->si_id);
  980. CurrCard->ourId = pCardInfo->si_id;
  981. i = (unsigned char)pCardInfo->si_mflags;
  982. if (i & SCSI_PARITY_ENA)
  983. WR_HARPOON(ioport + hp_portctrl_1, (HOST_MODE8 | CHK_SCSI_P));
  984. j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
  985. if (i & LOW_BYTE_TERM)
  986. j |= SCSI_TERM_ENA_L;
  987. WR_HARPOON(ioport + hp_bm_ctrl, j);
  988. j = (RD_HARPOON(ioport + hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
  989. if (i & HIGH_BYTE_TERM)
  990. j |= SCSI_TERM_ENA_H;
  991. WR_HARPOON(ioport + hp_ee_ctrl, j);
  992. if (!(pCardInfo->si_mflags & SOFT_RESET)) {
  993. FPT_sresb(ioport, thisCard);
  994. FPT_scini(thisCard, pCardInfo->si_id, 0);
  995. }
  996. if (pCardInfo->si_mflags & POST_ALL_UNDERRRUNS)
  997. CurrCard->globalFlags |= F_NO_FILTER;
  998. if (pCurrNvRam) {
  999. if (pCurrNvRam->niSysConf & 0x10)
  1000. CurrCard->globalFlags |= F_GREEN_PC;
  1001. } else {
  1002. if (FPT_utilEERead(ioport, (SYSTEM_CONFIG / 2)) & GREEN_PC_ENA)
  1003. CurrCard->globalFlags |= F_GREEN_PC;
  1004. }
  1005. /* Set global flag to indicate Re-Negotiation to be done on all
  1006. ckeck condition */
  1007. if (pCurrNvRam) {
  1008. if (pCurrNvRam->niScsiConf & 0x04)
  1009. CurrCard->globalFlags |= F_DO_RENEGO;
  1010. } else {
  1011. if (FPT_utilEERead(ioport, (SCSI_CONFIG / 2)) & RENEGO_ENA)
  1012. CurrCard->globalFlags |= F_DO_RENEGO;
  1013. }
  1014. if (pCurrNvRam) {
  1015. if (pCurrNvRam->niScsiConf & 0x08)
  1016. CurrCard->globalFlags |= F_CONLUN_IO;
  1017. } else {
  1018. if (FPT_utilEERead(ioport, (SCSI_CONFIG / 2)) & CONNIO_ENA)
  1019. CurrCard->globalFlags |= F_CONLUN_IO;
  1020. }
  1021. temp = pCardInfo->si_per_targ_no_disc;
  1022. for (i = 0, id = 1; i < MAX_SCSI_TAR; i++, id <<= 1) {
  1023. if (temp & id)
  1024. FPT_sccbMgrTbl[thisCard][i].TarStatus |= TAR_ALLOW_DISC;
  1025. }
  1026. sync_bit_map = 0x0001;
  1027. for (id = 0; id < (MAX_SCSI_TAR / 2); id++) {
  1028. if (pCurrNvRam) {
  1029. temp = (unsigned short)pCurrNvRam->niSyncTbl[id];
  1030. temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
  1031. (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
  1032. } else
  1033. temp =
  1034. FPT_utilEERead(ioport,
  1035. (unsigned short)((SYNC_RATE_TBL / 2)
  1036. + id));
  1037. for (i = 0; i < 2; temp >>= 8, i++) {
  1038. if (pCardInfo->si_per_targ_init_sync & sync_bit_map) {
  1039. FPT_sccbMgrTbl[thisCard][id * 2 +
  1040. i].TarEEValue =
  1041. (unsigned char)temp;
  1042. }
  1043. else {
  1044. FPT_sccbMgrTbl[thisCard][id * 2 +
  1045. i].TarStatus |=
  1046. SYNC_SUPPORTED;
  1047. FPT_sccbMgrTbl[thisCard][id * 2 +
  1048. i].TarEEValue =
  1049. (unsigned char)(temp & ~EE_SYNC_MASK);
  1050. }
  1051. /* if ((pCardInfo->si_per_targ_wide_nego & sync_bit_map) ||
  1052. (id*2+i >= 8)){
  1053. */
  1054. if (pCardInfo->si_per_targ_wide_nego & sync_bit_map) {
  1055. FPT_sccbMgrTbl[thisCard][id * 2 +
  1056. i].TarEEValue |=
  1057. EE_WIDE_SCSI;
  1058. }
  1059. else { /* NARROW SCSI */
  1060. FPT_sccbMgrTbl[thisCard][id * 2 +
  1061. i].TarStatus |=
  1062. WIDE_NEGOCIATED;
  1063. }
  1064. sync_bit_map <<= 1;
  1065. }
  1066. }
  1067. WR_HARPOON((ioport + hp_semaphore),
  1068. (unsigned char)(RD_HARPOON((ioport + hp_semaphore)) |
  1069. SCCB_MGR_PRESENT));
  1070. return (void *)CurrCard;
  1071. }
  1072. static void FlashPoint_ReleaseHostAdapter(void *pCurrCard)
  1073. {
  1074. unsigned char i;
  1075. u32 portBase;
  1076. u32 regOffset;
  1077. u32 scamData;
  1078. u32 *pScamTbl;
  1079. struct nvram_info *pCurrNvRam;
  1080. pCurrNvRam = ((struct sccb_card *)pCurrCard)->pNvRamInfo;
  1081. if (pCurrNvRam) {
  1082. FPT_WrStack(pCurrNvRam->niBaseAddr, 0, pCurrNvRam->niModel);
  1083. FPT_WrStack(pCurrNvRam->niBaseAddr, 1, pCurrNvRam->niSysConf);
  1084. FPT_WrStack(pCurrNvRam->niBaseAddr, 2, pCurrNvRam->niScsiConf);
  1085. FPT_WrStack(pCurrNvRam->niBaseAddr, 3, pCurrNvRam->niScamConf);
  1086. FPT_WrStack(pCurrNvRam->niBaseAddr, 4, pCurrNvRam->niAdapId);
  1087. for (i = 0; i < MAX_SCSI_TAR / 2; i++)
  1088. FPT_WrStack(pCurrNvRam->niBaseAddr,
  1089. (unsigned char)(i + 5),
  1090. pCurrNvRam->niSyncTbl[i]);
  1091. portBase = pCurrNvRam->niBaseAddr;
  1092. for (i = 0; i < MAX_SCSI_TAR; i++) {
  1093. regOffset = hp_aramBase + 64 + i * 4;
  1094. pScamTbl = (u32 *)&pCurrNvRam->niScamTbl[i];
  1095. scamData = *pScamTbl;
  1096. WR_HARP32(portBase, regOffset, scamData);
  1097. }
  1098. } else {
  1099. FPT_WrStack(((struct sccb_card *)pCurrCard)->ioPort, 0, 0);
  1100. }
  1101. }
  1102. static void FPT_RNVRamData(struct nvram_info *pNvRamInfo)
  1103. {
  1104. unsigned char i;
  1105. u32 portBase;
  1106. u32 regOffset;
  1107. u32 scamData;
  1108. u32 *pScamTbl;
  1109. pNvRamInfo->niModel = FPT_RdStack(pNvRamInfo->niBaseAddr, 0);
  1110. pNvRamInfo->niSysConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 1);
  1111. pNvRamInfo->niScsiConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 2);
  1112. pNvRamInfo->niScamConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 3);
  1113. pNvRamInfo->niAdapId = FPT_RdStack(pNvRamInfo->niBaseAddr, 4);
  1114. for (i = 0; i < MAX_SCSI_TAR / 2; i++)
  1115. pNvRamInfo->niSyncTbl[i] =
  1116. FPT_RdStack(pNvRamInfo->niBaseAddr, (unsigned char)(i + 5));
  1117. portBase = pNvRamInfo->niBaseAddr;
  1118. for (i = 0; i < MAX_SCSI_TAR; i++) {
  1119. regOffset = hp_aramBase + 64 + i * 4;
  1120. RD_HARP32(portBase, regOffset, scamData);
  1121. pScamTbl = (u32 *)&pNvRamInfo->niScamTbl[i];
  1122. *pScamTbl = scamData;
  1123. }
  1124. }
  1125. static unsigned char FPT_RdStack(u32 portBase, unsigned char index)
  1126. {
  1127. WR_HARPOON(portBase + hp_stack_addr, index);
  1128. return RD_HARPOON(portBase + hp_stack_data);
  1129. }
  1130. static void FPT_WrStack(u32 portBase, unsigned char index, unsigned char data)
  1131. {
  1132. WR_HARPOON(portBase + hp_stack_addr, index);
  1133. WR_HARPOON(portBase + hp_stack_data, data);
  1134. }
  1135. static unsigned char FPT_ChkIfChipInitialized(u32 ioPort)
  1136. {
  1137. if ((RD_HARPOON(ioPort + hp_arb_id) & 0x0f) != FPT_RdStack(ioPort, 4))
  1138. return 0;
  1139. if ((RD_HARPOON(ioPort + hp_clkctrl_0) & CLKCTRL_DEFAULT)
  1140. != CLKCTRL_DEFAULT)
  1141. return 0;
  1142. if ((RD_HARPOON(ioPort + hp_seltimeout) == TO_250ms) ||
  1143. (RD_HARPOON(ioPort + hp_seltimeout) == TO_290ms))
  1144. return 1;
  1145. return 0;
  1146. }
  1147. /*---------------------------------------------------------------------
  1148. *
  1149. * Function: FlashPoint_StartCCB
  1150. *
  1151. * Description: Start a command pointed to by p_Sccb. When the
  1152. * command is completed it will be returned via the
  1153. * callback function.
  1154. *
  1155. *---------------------------------------------------------------------*/
  1156. static void FlashPoint_StartCCB(void *curr_card, struct sccb *p_Sccb)
  1157. {
  1158. u32 ioport;
  1159. unsigned char thisCard, lun;
  1160. struct sccb *pSaveSccb;
  1161. CALL_BK_FN callback;
  1162. struct sccb_card *pCurrCard = curr_card;
  1163. thisCard = pCurrCard->cardIndex;
  1164. ioport = pCurrCard->ioPort;
  1165. if ((p_Sccb->TargID >= MAX_SCSI_TAR) || (p_Sccb->Lun >= MAX_LUN)) {
  1166. p_Sccb->HostStatus = SCCB_COMPLETE;
  1167. p_Sccb->SccbStatus = SCCB_ERROR;
  1168. callback = (CALL_BK_FN) p_Sccb->SccbCallback;
  1169. if (callback)
  1170. callback(p_Sccb);
  1171. return;
  1172. }
  1173. FPT_sinits(p_Sccb, thisCard);
  1174. if (!pCurrCard->cmdCounter) {
  1175. WR_HARPOON(ioport + hp_semaphore,
  1176. (RD_HARPOON(ioport + hp_semaphore)
  1177. | SCCB_MGR_ACTIVE));
  1178. if (pCurrCard->globalFlags & F_GREEN_PC) {
  1179. WR_HARPOON(ioport + hp_clkctrl_0, CLKCTRL_DEFAULT);
  1180. WR_HARPOON(ioport + hp_sys_ctrl, 0x00);
  1181. }
  1182. }
  1183. pCurrCard->cmdCounter++;
  1184. if (RD_HARPOON(ioport + hp_semaphore) & BIOS_IN_USE) {
  1185. WR_HARPOON(ioport + hp_semaphore,
  1186. (RD_HARPOON(ioport + hp_semaphore)
  1187. | TICKLE_ME));
  1188. if (p_Sccb->OperationCode == RESET_COMMAND) {
  1189. pSaveSccb =
  1190. pCurrCard->currentSCCB;
  1191. pCurrCard->currentSCCB = p_Sccb;
  1192. FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
  1193. pCurrCard->currentSCCB =
  1194. pSaveSccb;
  1195. } else {
  1196. FPT_queueAddSccb(p_Sccb, thisCard);
  1197. }
  1198. }
  1199. else if ((RD_HARPOON(ioport + hp_page_ctrl) & G_INT_DISABLE)) {
  1200. if (p_Sccb->OperationCode == RESET_COMMAND) {
  1201. pSaveSccb =
  1202. pCurrCard->currentSCCB;
  1203. pCurrCard->currentSCCB = p_Sccb;
  1204. FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
  1205. pCurrCard->currentSCCB =
  1206. pSaveSccb;
  1207. } else {
  1208. FPT_queueAddSccb(p_Sccb, thisCard);
  1209. }
  1210. }
  1211. else {
  1212. MDISABLE_INT(ioport);
  1213. if ((pCurrCard->globalFlags & F_CONLUN_IO) &&
  1214. ((FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].
  1215. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
  1216. lun = p_Sccb->Lun;
  1217. else
  1218. lun = 0;
  1219. if ((pCurrCard->currentSCCB == NULL) &&
  1220. (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarSelQ_Cnt == 0)
  1221. && (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarLUNBusy[lun]
  1222. == 0)) {
  1223. pCurrCard->currentSCCB = p_Sccb;
  1224. FPT_ssel(p_Sccb->SccbIOPort, thisCard);
  1225. }
  1226. else {
  1227. if (p_Sccb->OperationCode == RESET_COMMAND) {
  1228. pSaveSccb = pCurrCard->currentSCCB;
  1229. pCurrCard->currentSCCB = p_Sccb;
  1230. FPT_queueSelectFail(&FPT_BL_Card[thisCard],
  1231. thisCard);
  1232. pCurrCard->currentSCCB = pSaveSccb;
  1233. } else {
  1234. FPT_queueAddSccb(p_Sccb, thisCard);
  1235. }
  1236. }
  1237. MENABLE_INT(ioport);
  1238. }
  1239. }
  1240. /*---------------------------------------------------------------------
  1241. *
  1242. * Function: FlashPoint_AbortCCB
  1243. *
  1244. * Description: Abort the command pointed to by p_Sccb. When the
  1245. * command is completed it will be returned via the
  1246. * callback function.
  1247. *
  1248. *---------------------------------------------------------------------*/
  1249. static int FlashPoint_AbortCCB(void *pCurrCard, struct sccb *p_Sccb)
  1250. {
  1251. u32 ioport;
  1252. unsigned char thisCard;
  1253. CALL_BK_FN callback;
  1254. struct sccb *pSaveSCCB;
  1255. struct sccb_mgr_tar_info *currTar_Info;
  1256. ioport = ((struct sccb_card *)pCurrCard)->ioPort;
  1257. thisCard = ((struct sccb_card *)pCurrCard)->cardIndex;
  1258. if (!(RD_HARPOON(ioport + hp_page_ctrl) & G_INT_DISABLE)) {
  1259. if (FPT_queueFindSccb(p_Sccb, thisCard)) {
  1260. ((struct sccb_card *)pCurrCard)->cmdCounter--;
  1261. if (!((struct sccb_card *)pCurrCard)->cmdCounter)
  1262. WR_HARPOON(ioport + hp_semaphore,
  1263. (RD_HARPOON(ioport + hp_semaphore)
  1264. & (unsigned
  1265. char)(~(SCCB_MGR_ACTIVE |
  1266. TICKLE_ME))));
  1267. p_Sccb->SccbStatus = SCCB_ABORT;
  1268. callback = p_Sccb->SccbCallback;
  1269. callback(p_Sccb);
  1270. return 0;
  1271. }
  1272. else {
  1273. if (((struct sccb_card *)pCurrCard)->currentSCCB ==
  1274. p_Sccb) {
  1275. p_Sccb->SccbStatus = SCCB_ABORT;
  1276. return 0;
  1277. }
  1278. else {
  1279. if (p_Sccb->Sccb_tag) {
  1280. MDISABLE_INT(ioport);
  1281. if (((struct sccb_card *)pCurrCard)->
  1282. discQ_Tbl[p_Sccb->Sccb_tag] ==
  1283. p_Sccb) {
  1284. p_Sccb->SccbStatus = SCCB_ABORT;
  1285. p_Sccb->Sccb_scsistat =
  1286. ABORT_ST;
  1287. p_Sccb->Sccb_scsimsg =
  1288. ABORT_TASK;
  1289. if (((struct sccb_card *)
  1290. pCurrCard)->currentSCCB ==
  1291. NULL) {
  1292. ((struct sccb_card *)
  1293. pCurrCard)->
  1294. currentSCCB = p_Sccb;
  1295. FPT_ssel(ioport,
  1296. thisCard);
  1297. } else {
  1298. pSaveSCCB =
  1299. ((struct sccb_card
  1300. *)pCurrCard)->
  1301. currentSCCB;
  1302. ((struct sccb_card *)
  1303. pCurrCard)->
  1304. currentSCCB = p_Sccb;
  1305. FPT_queueSelectFail((struct sccb_card *)pCurrCard, thisCard);
  1306. ((struct sccb_card *)
  1307. pCurrCard)->
  1308. currentSCCB = pSaveSCCB;
  1309. }
  1310. }
  1311. MENABLE_INT(ioport);
  1312. return 0;
  1313. } else {
  1314. currTar_Info =
  1315. &FPT_sccbMgrTbl[thisCard][p_Sccb->
  1316. TargID];
  1317. if (FPT_BL_Card[thisCard].
  1318. discQ_Tbl[currTar_Info->
  1319. LunDiscQ_Idx[p_Sccb->Lun]]
  1320. == p_Sccb) {
  1321. p_Sccb->SccbStatus = SCCB_ABORT;
  1322. return 0;
  1323. }
  1324. }
  1325. }
  1326. }
  1327. }
  1328. return -1;
  1329. }
  1330. /*---------------------------------------------------------------------
  1331. *
  1332. * Function: FlashPoint_InterruptPending
  1333. *
  1334. * Description: Do a quick check to determine if there is a pending
  1335. * interrupt for this card and disable the IRQ Pin if so.
  1336. *
  1337. *---------------------------------------------------------------------*/
  1338. static unsigned char FlashPoint_InterruptPending(void *pCurrCard)
  1339. {
  1340. u32 ioport;
  1341. ioport = ((struct sccb_card *)pCurrCard)->ioPort;
  1342. if (RD_HARPOON(ioport + hp_int_status) & INT_ASSERTED) {
  1343. return 1;
  1344. }
  1345. else
  1346. return 0;
  1347. }
  1348. /*---------------------------------------------------------------------
  1349. *
  1350. * Function: FlashPoint_HandleInterrupt
  1351. *
  1352. * Description: This is our entry point when an interrupt is generated
  1353. * by the card and the upper level driver passes it on to
  1354. * us.
  1355. *
  1356. *---------------------------------------------------------------------*/
  1357. static int FlashPoint_HandleInterrupt(void *pcard)
  1358. {
  1359. struct sccb *currSCCB;
  1360. unsigned char thisCard, result, bm_status;
  1361. unsigned short hp_int;
  1362. unsigned char i, target;
  1363. struct sccb_card *pCurrCard = pcard;
  1364. u32 ioport;
  1365. thisCard = pCurrCard->cardIndex;
  1366. ioport = pCurrCard->ioPort;
  1367. MDISABLE_INT(ioport);
  1368. if (RD_HARPOON(ioport + hp_int_status) & EXT_STATUS_ON)
  1369. bm_status = RD_HARPOON(ioport + hp_ext_status) &
  1370. (unsigned char)BAD_EXT_STATUS;
  1371. else
  1372. bm_status = 0;
  1373. WR_HARPOON(ioport + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
  1374. while ((hp_int = RDW_HARPOON((ioport + hp_intstat)) &
  1375. FPT_default_intena) | bm_status) {
  1376. currSCCB = pCurrCard->currentSCCB;
  1377. if (hp_int & (FIFO | TIMEOUT | RESET | SCAM_SEL) || bm_status) {
  1378. result =
  1379. FPT_SccbMgr_bad_isr(ioport, thisCard, pCurrCard,
  1380. hp_int);
  1381. WRW_HARPOON((ioport + hp_intstat),
  1382. (FIFO | TIMEOUT | RESET | SCAM_SEL));
  1383. bm_status = 0;
  1384. if (result) {
  1385. MENABLE_INT(ioport);
  1386. return result;
  1387. }
  1388. }
  1389. else if (hp_int & ICMD_COMP) {
  1390. if (!(hp_int & BUS_FREE)) {
  1391. /* Wait for the BusFree before starting a new command. We
  1392. must also check for being reselected since the BusFree
  1393. may not show up if another device reselects us in 1.5us or
  1394. less. SRR Wednesday, 3/8/1995.
  1395. */
  1396. while (!
  1397. (RDW_HARPOON((ioport + hp_intstat)) &
  1398. (BUS_FREE | RSEL))) ;
  1399. }
  1400. if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
  1401. FPT_phaseChkFifo(ioport, thisCard);
  1402. /* WRW_HARPOON((ioport+hp_intstat),
  1403. (BUS_FREE | ICMD_COMP | ITAR_DISC | XFER_CNT_0));
  1404. */
  1405. WRW_HARPOON((ioport + hp_intstat), CLR_ALL_INT_1);
  1406. FPT_autoCmdCmplt(ioport, thisCard);
  1407. }
  1408. else if (hp_int & ITAR_DISC) {
  1409. if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
  1410. FPT_phaseChkFifo(ioport, thisCard);
  1411. if (RD_HARPOON(ioport + hp_gp_reg_1) ==
  1412. SAVE_POINTERS) {
  1413. WR_HARPOON(ioport + hp_gp_reg_1, 0x00);
  1414. currSCCB->Sccb_XferState |= F_NO_DATA_YET;
  1415. currSCCB->Sccb_savedATC = currSCCB->Sccb_ATC;
  1416. }
  1417. currSCCB->Sccb_scsistat = DISCONNECT_ST;
  1418. FPT_queueDisconnect(currSCCB, thisCard);
  1419. /* Wait for the BusFree before starting a new command. We
  1420. must also check for being reselected since the BusFree
  1421. may not show up if another device reselects us in 1.5us or
  1422. less. SRR Wednesday, 3/8/1995.
  1423. */
  1424. while (!
  1425. (RDW_HARPOON((ioport + hp_intstat)) &
  1426. (BUS_FREE | RSEL))
  1427. && !((RDW_HARPOON((ioport + hp_intstat)) & PHASE)
  1428. && RD_HARPOON((ioport + hp_scsisig)) ==
  1429. (SCSI_BSY | SCSI_REQ | SCSI_CD | SCSI_MSG |
  1430. SCSI_IOBIT))) ;
  1431. /*
  1432. The additional loop exit condition above detects a timing problem
  1433. with the revision D/E harpoon chips. The caller should reset the
  1434. host adapter to recover when 0xFE is returned.
  1435. */
  1436. if (!
  1437. (RDW_HARPOON((ioport + hp_intstat)) &
  1438. (BUS_FREE | RSEL))) {
  1439. MENABLE_INT(ioport);
  1440. return 0xFE;
  1441. }
  1442. WRW_HARPOON((ioport + hp_intstat),
  1443. (BUS_FREE | ITAR_DISC));
  1444. pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
  1445. }
  1446. else if (hp_int & RSEL) {
  1447. WRW_HARPOON((ioport + hp_intstat),
  1448. (PROG_HLT | RSEL | PHASE | BUS_FREE));
  1449. if (RDW_HARPOON((ioport + hp_intstat)) & ITAR_DISC) {
  1450. if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
  1451. FPT_phaseChkFifo(ioport, thisCard);
  1452. if (RD_HARPOON(ioport + hp_gp_reg_1) ==
  1453. SAVE_POINTERS) {
  1454. WR_HARPOON(ioport + hp_gp_reg_1, 0x00);
  1455. currSCCB->Sccb_XferState |=
  1456. F_NO_DATA_YET;
  1457. currSCCB->Sccb_savedATC =
  1458. currSCCB->Sccb_ATC;
  1459. }
  1460. WRW_HARPOON((ioport + hp_intstat),
  1461. (BUS_FREE | ITAR_DISC));
  1462. currSCCB->Sccb_scsistat = DISCONNECT_ST;
  1463. FPT_queueDisconnect(currSCCB, thisCard);
  1464. }
  1465. FPT_sres(ioport, thisCard, pCurrCard);
  1466. FPT_phaseDecode(ioport, thisCard);
  1467. }
  1468. else if ((hp_int & IDO_STRT) && (!(hp_int & BUS_FREE))) {
  1469. WRW_HARPOON((ioport + hp_intstat),
  1470. (IDO_STRT | XFER_CNT_0));
  1471. FPT_phaseDecode(ioport, thisCard);
  1472. }
  1473. else if ((hp_int & IUNKWN) || (hp_int & PROG_HLT)) {
  1474. WRW_HARPOON((ioport + hp_intstat),
  1475. (PHASE | IUNKWN | PROG_HLT));
  1476. if ((RD_HARPOON(ioport + hp_prgmcnt_0) & (unsigned char)
  1477. 0x3f) < (unsigned char)SELCHK) {
  1478. FPT_phaseDecode(ioport, thisCard);
  1479. } else {
  1480. /* Harpoon problem some SCSI target device respond to selection
  1481. with short BUSY pulse (<400ns) this will make the Harpoon is not able
  1482. to latch the correct Target ID into reg. x53.
  1483. The work around require to correct this reg. But when write to this
  1484. reg. (0x53) also increment the FIFO write addr reg (0x6f), thus we
  1485. need to read this reg first then restore it later. After update to 0x53 */
  1486. i = (unsigned
  1487. char)(RD_HARPOON(ioport + hp_fifowrite));
  1488. target =
  1489. (unsigned
  1490. char)(RD_HARPOON(ioport + hp_gp_reg_3));
  1491. WR_HARPOON(ioport + hp_xfer_pad,
  1492. (unsigned char)ID_UNLOCK);
  1493. WR_HARPOON(ioport + hp_select_id,
  1494. (unsigned char)(target | target <<
  1495. 4));
  1496. WR_HARPOON(ioport + hp_xfer_pad,
  1497. (unsigned char)0x00);
  1498. WR_HARPOON(ioport + hp_fifowrite, i);
  1499. WR_HARPOON(ioport + hp_autostart_3,
  1500. (AUTO_IMMED + TAG_STRT));
  1501. }
  1502. }
  1503. else if (hp_int & XFER_CNT_0) {
  1504. WRW_HARPOON((ioport + hp_intstat), XFER_CNT_0);
  1505. FPT_schkdd(ioport, thisCard);
  1506. }
  1507. else if (hp_int & BUS_FREE) {
  1508. WRW_HARPOON((ioport + hp_intstat), BUS_FREE);
  1509. if (pCurrCard->globalFlags & F_HOST_XFER_ACT) {
  1510. FPT_hostDataXferAbort(ioport, thisCard,
  1511. currSCCB);
  1512. }
  1513. FPT_phaseBusFree(ioport, thisCard);
  1514. }
  1515. else if (hp_int & ITICKLE) {
  1516. WRW_HARPOON((ioport + hp_intstat), ITICKLE);
  1517. pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
  1518. }
  1519. if (((struct sccb_card *)pCurrCard)->
  1520. globalFlags & F_NEW_SCCB_CMD) {
  1521. pCurrCard->globalFlags &= ~F_NEW_SCCB_CMD;
  1522. if (pCurrCard->currentSCCB == NULL)
  1523. FPT_queueSearchSelect(pCurrCard, thisCard);
  1524. if (pCurrCard->currentSCCB != NULL) {
  1525. pCurrCard->globalFlags &= ~F_NEW_SCCB_CMD;
  1526. FPT_ssel(ioport, thisCard);
  1527. }
  1528. break;
  1529. }
  1530. } /*end while */
  1531. MENABLE_INT(ioport);
  1532. return 0;
  1533. }
  1534. /*---------------------------------------------------------------------
  1535. *
  1536. * Function: Sccb_bad_isr
  1537. *
  1538. * Description: Some type of interrupt has occurred which is slightly
  1539. * out of the ordinary. We will now decode it fully, in
  1540. * this routine. This is broken up in an attempt to save
  1541. * processing time.
  1542. *
  1543. *---------------------------------------------------------------------*/
  1544. static unsigned char FPT_SccbMgr_bad_isr(u32 p_port, unsigned char p_card,
  1545. struct sccb_card *pCurrCard,
  1546. unsigned short p_int)
  1547. {
  1548. unsigned char temp, ScamFlg;
  1549. struct sccb_mgr_tar_info *currTar_Info;
  1550. struct nvram_info *pCurrNvRam;
  1551. if (RD_HARPOON(p_port + hp_ext_status) &
  1552. (BM_FORCE_OFF | PCI_DEV_TMOUT | BM_PARITY_ERR | PIO_OVERRUN)) {
  1553. if (pCurrCard->globalFlags & F_HOST_XFER_ACT) {
  1554. FPT_hostDataXferAbort(p_port, p_card,
  1555. pCurrCard->currentSCCB);
  1556. }
  1557. if (RD_HARPOON(p_port + hp_pci_stat_cfg) & REC_MASTER_ABORT)
  1558. {
  1559. WR_HARPOON(p_port + hp_pci_stat_cfg,
  1560. (RD_HARPOON(p_port + hp_pci_stat_cfg) &
  1561. ~REC_MASTER_ABORT));
  1562. WR_HARPOON(p_port + hp_host_blk_cnt, 0x00);
  1563. }
  1564. if (pCurrCard->currentSCCB != NULL) {
  1565. if (!pCurrCard->currentSCCB->HostStatus)
  1566. pCurrCard->currentSCCB->HostStatus =
  1567. SCCB_BM_ERR;
  1568. FPT_sxfrp(p_port, p_card);
  1569. temp = (unsigned char)(RD_HARPOON(p_port + hp_ee_ctrl) &
  1570. (EXT_ARB_ACK | SCSI_TERM_ENA_H));
  1571. WR_HARPOON(p_port + hp_ee_ctrl,
  1572. ((unsigned char)temp | SEE_MS | SEE_CS));
  1573. WR_HARPOON(p_port + hp_ee_ctrl, temp);
  1574. if (!
  1575. (RDW_HARPOON((p_port + hp_intstat)) &
  1576. (BUS_FREE | RESET))) {
  1577. FPT_phaseDecode(p_port, p_card);
  1578. }
  1579. }
  1580. }
  1581. else if (p_int & RESET) {
  1582. WR_HARPOON(p_port + hp_clkctrl_0, CLKCTRL_DEFAULT);
  1583. WR_HARPOON(p_port + hp_sys_ctrl, 0x00);
  1584. if (pCurrCard->currentSCCB != NULL) {
  1585. if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
  1586. FPT_hostDataXferAbort(p_port, p_card,
  1587. pCurrCard->currentSCCB);
  1588. }
  1589. DISABLE_AUTO(p_port);
  1590. FPT_sresb(p_port, p_card);
  1591. while (RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST) {
  1592. }
  1593. pCurrNvRam = pCurrCard->pNvRamInfo;
  1594. if (pCurrNvRam) {
  1595. ScamFlg = pCurrNvRam->niScamConf;
  1596. } else {
  1597. ScamFlg =
  1598. (unsigned char)FPT_utilEERead(p_port,
  1599. SCAM_CONFIG / 2);
  1600. }
  1601. FPT_XbowInit(p_port, ScamFlg);
  1602. FPT_scini(p_card, pCurrCard->ourId, 0);
  1603. return 0xFF;
  1604. }
  1605. else if (p_int & FIFO) {
  1606. WRW_HARPOON((p_port + hp_intstat), FIFO);
  1607. if (pCurrCard->currentSCCB != NULL)
  1608. FPT_sxfrp(p_port, p_card);
  1609. }
  1610. else if (p_int & TIMEOUT) {
  1611. DISABLE_AUTO(p_port);
  1612. WRW_HARPOON((p_port + hp_intstat),
  1613. (PROG_HLT | TIMEOUT | SEL | BUS_FREE | PHASE |
  1614. IUNKWN));
  1615. pCurrCard->currentSCCB->HostStatus = SCCB_SELECTION_TIMEOUT;
  1616. currTar_Info =
  1617. &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
  1618. if ((pCurrCard->globalFlags & F_CONLUN_IO)
  1619. && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
  1620. TAG_Q_TRYING))
  1621. currTar_Info->TarLUNBusy[pCurrCard->currentSCCB->Lun] =
  1622. 0;
  1623. else
  1624. currTar_Info->TarLUNBusy[0] = 0;
  1625. if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
  1626. currTar_Info->TarSyncCtrl = 0;
  1627. currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
  1628. }
  1629. if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
  1630. currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
  1631. }
  1632. FPT_sssyncv(p_port, pCurrCard->currentSCCB->TargID, NARROW_SCSI,
  1633. currTar_Info);
  1634. FPT_queueCmdComplete(pCurrCard, pCurrCard->currentSCCB, p_card);
  1635. }
  1636. else if (p_int & SCAM_SEL) {
  1637. FPT_scarb(p_port, LEVEL2_TAR);
  1638. FPT_scsel(p_port);
  1639. FPT_scasid(p_card, p_port);
  1640. FPT_scbusf(p_port);
  1641. WRW_HARPOON((p_port + hp_intstat), SCAM_SEL);
  1642. }
  1643. return 0x00;
  1644. }
  1645. /*---------------------------------------------------------------------
  1646. *
  1647. * Function: SccbMgrTableInit
  1648. *
  1649. * Description: Initialize all Sccb manager data structures.
  1650. *
  1651. *---------------------------------------------------------------------*/
  1652. static void FPT_SccbMgrTableInitAll(void)
  1653. {
  1654. unsigned char thisCard;
  1655. for (thisCard = 0; thisCard < MAX_CARDS; thisCard++) {
  1656. FPT_SccbMgrTableInitCard(&FPT_BL_Card[thisCard], thisCard);
  1657. FPT_BL_Card[thisCard].ioPort = 0x00;
  1658. FPT_BL_Card[thisCard].cardInfo = NULL;
  1659. FPT_BL_Card[thisCard].cardIndex = 0xFF;
  1660. FPT_BL_Card[thisCard].ourId = 0x00;
  1661. FPT_BL_Card[thisCard].pNvRamInfo = NULL;
  1662. }
  1663. }
  1664. /*---------------------------------------------------------------------
  1665. *
  1666. * Function: SccbMgrTableInit
  1667. *
  1668. * Description: Initialize all Sccb manager data structures.
  1669. *
  1670. *---------------------------------------------------------------------*/
  1671. static void FPT_SccbMgrTableInitCard(struct sccb_card *pCurrCard,
  1672. unsigned char p_card)
  1673. {
  1674. unsigned char scsiID, qtag;
  1675. for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
  1676. FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
  1677. }
  1678. for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++) {
  1679. FPT_sccbMgrTbl[p_card][scsiID].TarStatus = 0;
  1680. FPT_sccbMgrTbl[p_card][scsiID].TarEEValue = 0;
  1681. FPT_SccbMgrTableInitTarget(p_card, scsiID);
  1682. }
  1683. pCurrCard->scanIndex = 0x00;
  1684. pCurrCard->currentSCCB = NULL;
  1685. pCurrCard->globalFlags = 0x00;
  1686. pCurrCard->cmdCounter = 0x00;
  1687. pCurrCard->tagQ_Lst = 0x01;
  1688. pCurrCard->discQCount = 0;
  1689. }
  1690. /*---------------------------------------------------------------------
  1691. *
  1692. * Function: SccbMgrTableInit
  1693. *
  1694. * Description: Initialize all Sccb manager data structures.
  1695. *
  1696. *---------------------------------------------------------------------*/
  1697. static void FPT_SccbMgrTableInitTarget(unsigned char p_card,
  1698. unsigned char target)
  1699. {
  1700. unsigned char lun, qtag;
  1701. struct sccb_mgr_tar_info *currTar_Info;
  1702. currTar_Info = &FPT_sccbMgrTbl[p_card][target];
  1703. currTar_Info->TarSelQ_Cnt = 0;
  1704. currTar_Info->TarSyncCtrl = 0;
  1705. currTar_Info->TarSelQ_Head = NULL;
  1706. currTar_Info->TarSelQ_Tail = NULL;
  1707. currTar_Info->TarTagQ_Cnt = 0;
  1708. currTar_Info->TarLUN_CA = 0;
  1709. for (lun = 0; lun < MAX_LUN; lun++) {
  1710. currTar_Info->TarLUNBusy[lun] = 0;
  1711. currTar_Info->LunDiscQ_Idx[lun] = 0;
  1712. }
  1713. for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
  1714. if (FPT_BL_Card[p_card].discQ_Tbl[qtag] != NULL) {
  1715. if (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID ==
  1716. target) {
  1717. FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
  1718. FPT_BL_Card[p_card].discQCount--;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. /*---------------------------------------------------------------------
  1724. *
  1725. * Function: sfetm
  1726. *
  1727. * Description: Read in a message byte from the SCSI bus, and check
  1728. * for a parity error.
  1729. *
  1730. *---------------------------------------------------------------------*/
  1731. static unsigned char FPT_sfm(u32 port, struct sccb *pCurrSCCB)
  1732. {
  1733. unsigned char message;
  1734. unsigned short TimeOutLoop;
  1735. TimeOutLoop = 0;
  1736. while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
  1737. (TimeOutLoop++ < 20000)) {
  1738. }
  1739. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  1740. message = RD_HARPOON(port + hp_scsidata_0);
  1741. WR_HARPOON(port + hp_scsisig, SCSI_ACK + S_MSGI_PH);
  1742. if (TimeOutLoop > 20000)
  1743. message = 0x00; /* force message byte = 0 if Time Out on Req */
  1744. if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
  1745. (RD_HARPOON(port + hp_addstat) & SCSI_PAR_ERR)) {
  1746. WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
  1747. WR_HARPOON(port + hp_xferstat, 0);
  1748. WR_HARPOON(port + hp_fiforead, 0);
  1749. WR_HARPOON(port + hp_fifowrite, 0);
  1750. if (pCurrSCCB != NULL) {
  1751. pCurrSCCB->Sccb_scsimsg = MSG_PARITY_ERROR;
  1752. }
  1753. message = 0x00;
  1754. do {
  1755. ACCEPT_MSG_ATN(port);
  1756. TimeOutLoop = 0;
  1757. while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
  1758. (TimeOutLoop++ < 20000)) {
  1759. }
  1760. if (TimeOutLoop > 20000) {
  1761. WRW_HARPOON((port + hp_intstat), PARITY);
  1762. return message;
  1763. }
  1764. if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) !=
  1765. S_MSGI_PH) {
  1766. WRW_HARPOON((port + hp_intstat), PARITY);
  1767. return message;
  1768. }
  1769. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  1770. RD_HARPOON(port + hp_scsidata_0);
  1771. WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
  1772. } while (1);
  1773. }
  1774. WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
  1775. WR_HARPOON(port + hp_xferstat, 0);
  1776. WR_HARPOON(port + hp_fiforead, 0);
  1777. WR_HARPOON(port + hp_fifowrite, 0);
  1778. return message;
  1779. }
  1780. /*---------------------------------------------------------------------
  1781. *
  1782. * Function: FPT_ssel
  1783. *
  1784. * Description: Load up automation and select target device.
  1785. *
  1786. *---------------------------------------------------------------------*/
  1787. static void FPT_ssel(u32 port, unsigned char p_card)
  1788. {
  1789. unsigned char auto_loaded, i, target, *theCCB;
  1790. u32 cdb_reg;
  1791. struct sccb_card *CurrCard;
  1792. struct sccb *currSCCB;
  1793. struct sccb_mgr_tar_info *currTar_Info;
  1794. unsigned char lastTag, lun;
  1795. CurrCard = &FPT_BL_Card[p_card];
  1796. currSCCB = CurrCard->currentSCCB;
  1797. target = currSCCB->TargID;
  1798. currTar_Info = &FPT_sccbMgrTbl[p_card][target];
  1799. lastTag = CurrCard->tagQ_Lst;
  1800. ARAM_ACCESS(port);
  1801. if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
  1802. currSCCB->ControlByte &= ~F_USE_CMD_Q;
  1803. if (((CurrCard->globalFlags & F_CONLUN_IO) &&
  1804. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
  1805. lun = currSCCB->Lun;
  1806. else
  1807. lun = 0;
  1808. if (CurrCard->globalFlags & F_TAG_STARTED) {
  1809. if (!(currSCCB->ControlByte & F_USE_CMD_Q)) {
  1810. if ((currTar_Info->TarLUN_CA == 0)
  1811. && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
  1812. == TAG_Q_TRYING)) {
  1813. if (currTar_Info->TarTagQ_Cnt != 0) {
  1814. currTar_Info->TarLUNBusy[lun] = 1;
  1815. FPT_queueSelectFail(CurrCard, p_card);
  1816. SGRAM_ACCESS(port);
  1817. return;
  1818. }
  1819. else {
  1820. currTar_Info->TarLUNBusy[lun] = 1;
  1821. }
  1822. }
  1823. /*End non-tagged */
  1824. else {
  1825. currTar_Info->TarLUNBusy[lun] = 1;
  1826. }
  1827. }
  1828. /*!Use cmd Q Tagged */
  1829. else {
  1830. if (currTar_Info->TarLUN_CA == 1) {
  1831. FPT_queueSelectFail(CurrCard, p_card);
  1832. SGRAM_ACCESS(port);
  1833. return;
  1834. }
  1835. currTar_Info->TarLUNBusy[lun] = 1;
  1836. } /*else use cmd Q tagged */
  1837. }
  1838. /*if glob tagged started */
  1839. else {
  1840. currTar_Info->TarLUNBusy[lun] = 1;
  1841. }
  1842. if ((((CurrCard->globalFlags & F_CONLUN_IO) &&
  1843. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
  1844. || (!(currSCCB->ControlByte & F_USE_CMD_Q)))) {
  1845. if (CurrCard->discQCount >= QUEUE_DEPTH) {
  1846. currTar_Info->TarLUNBusy[lun] = 1;
  1847. FPT_queueSelectFail(CurrCard, p_card);
  1848. SGRAM_ACCESS(port);
  1849. return;
  1850. }
  1851. for (i = 1; i < QUEUE_DEPTH; i++) {
  1852. if (++lastTag >= QUEUE_DEPTH)
  1853. lastTag = 1;
  1854. if (CurrCard->discQ_Tbl[lastTag] == NULL) {
  1855. CurrCard->tagQ_Lst = lastTag;
  1856. currTar_Info->LunDiscQ_Idx[lun] = lastTag;
  1857. CurrCard->discQ_Tbl[lastTag] = currSCCB;
  1858. CurrCard->discQCount++;
  1859. break;
  1860. }
  1861. }
  1862. if (i == QUEUE_DEPTH) {
  1863. currTar_Info->TarLUNBusy[lun] = 1;
  1864. FPT_queueSelectFail(CurrCard, p_card);
  1865. SGRAM_ACCESS(port);
  1866. return;
  1867. }
  1868. }
  1869. auto_loaded = 0;
  1870. WR_HARPOON(port + hp_select_id, target);
  1871. WR_HARPOON(port + hp_gp_reg_3, target); /* Use by new automation logic */
  1872. if (currSCCB->OperationCode == RESET_COMMAND) {
  1873. WRW_HARPOON((port + ID_MSG_STRT), (MPM_OP + AMSG_OUT +
  1874. (currSCCB->
  1875. Sccb_idmsg & ~DISC_PRIV)));
  1876. WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + NP);
  1877. currSCCB->Sccb_scsimsg = TARGET_RESET;
  1878. WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
  1879. auto_loaded = 1;
  1880. currSCCB->Sccb_scsistat = SELECT_BDR_ST;
  1881. if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
  1882. currTar_Info->TarSyncCtrl = 0;
  1883. currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
  1884. }
  1885. if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
  1886. currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
  1887. }
  1888. FPT_sssyncv(port, target, NARROW_SCSI, currTar_Info);
  1889. FPT_SccbMgrTableInitTarget(p_card, target);
  1890. }
  1891. else if (currSCCB->Sccb_scsistat == ABORT_ST) {
  1892. WRW_HARPOON((port + ID_MSG_STRT), (MPM_OP + AMSG_OUT +
  1893. (currSCCB->
  1894. Sccb_idmsg & ~DISC_PRIV)));
  1895. WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
  1896. WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT +
  1897. (((unsigned
  1898. char)(currSCCB->
  1899. ControlByte &
  1900. TAG_TYPE_MASK)
  1901. >> 6) | (unsigned char)
  1902. 0x20)));
  1903. WRW_HARPOON((port + SYNC_MSGS + 2),
  1904. (MPM_OP + AMSG_OUT + currSCCB->Sccb_tag));
  1905. WRW_HARPOON((port + SYNC_MSGS + 4), (BRH_OP + ALWAYS + NP));
  1906. WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
  1907. auto_loaded = 1;
  1908. }
  1909. else if (!(currTar_Info->TarStatus & WIDE_NEGOCIATED)) {
  1910. auto_loaded = FPT_siwidn(port, p_card);
  1911. currSCCB->Sccb_scsistat = SELECT_WN_ST;
  1912. }
  1913. else if (!((currTar_Info->TarStatus & TAR_SYNC_MASK)
  1914. == SYNC_SUPPORTED)) {
  1915. auto_loaded = FPT_sisyncn(port, p_card, 0);
  1916. currSCCB->Sccb_scsistat = SELECT_SN_ST;
  1917. }
  1918. if (!auto_loaded) {
  1919. if (currSCCB->ControlByte & F_USE_CMD_Q) {
  1920. CurrCard->globalFlags |= F_TAG_STARTED;
  1921. if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
  1922. == TAG_Q_REJECT) {
  1923. currSCCB->ControlByte &= ~F_USE_CMD_Q;
  1924. /* Fix up the start instruction with a jump to
  1925. Non-Tag-CMD handling */
  1926. WRW_HARPOON((port + ID_MSG_STRT),
  1927. BRH_OP + ALWAYS + NTCMD);
  1928. WRW_HARPOON((port + NON_TAG_ID_MSG),
  1929. (MPM_OP + AMSG_OUT +
  1930. currSCCB->Sccb_idmsg));
  1931. WR_HARPOON(port + hp_autostart_3,
  1932. (SELECT + SELCHK_STRT));
  1933. /* Setup our STATE so we know what happened when
  1934. the wheels fall off. */
  1935. currSCCB->Sccb_scsistat = SELECT_ST;
  1936. currTar_Info->TarLUNBusy[lun] = 1;
  1937. }
  1938. else {
  1939. WRW_HARPOON((port + ID_MSG_STRT),
  1940. (MPM_OP + AMSG_OUT +
  1941. currSCCB->Sccb_idmsg));
  1942. WRW_HARPOON((port + ID_MSG_STRT + 2),
  1943. (MPM_OP + AMSG_OUT +
  1944. (((unsigned char)(currSCCB->
  1945. ControlByte &
  1946. TAG_TYPE_MASK)
  1947. >> 6) | (unsigned char)0x20)));
  1948. for (i = 1; i < QUEUE_DEPTH; i++) {
  1949. if (++lastTag >= QUEUE_DEPTH)
  1950. lastTag = 1;
  1951. if (CurrCard->discQ_Tbl[lastTag] ==
  1952. NULL) {
  1953. WRW_HARPOON((port +
  1954. ID_MSG_STRT + 6),
  1955. (MPM_OP + AMSG_OUT +
  1956. lastTag));
  1957. CurrCard->tagQ_Lst = lastTag;
  1958. currSCCB->Sccb_tag = lastTag;
  1959. CurrCard->discQ_Tbl[lastTag] =
  1960. currSCCB;
  1961. CurrCard->discQCount++;
  1962. break;
  1963. }
  1964. }
  1965. if (i == QUEUE_DEPTH) {
  1966. currTar_Info->TarLUNBusy[lun] = 1;
  1967. FPT_queueSelectFail(CurrCard, p_card);
  1968. SGRAM_ACCESS(port);
  1969. return;
  1970. }
  1971. currSCCB->Sccb_scsistat = SELECT_Q_ST;
  1972. WR_HARPOON(port + hp_autostart_3,
  1973. (SELECT + SELCHK_STRT));
  1974. }
  1975. }
  1976. else {
  1977. WRW_HARPOON((port + ID_MSG_STRT),
  1978. BRH_OP + ALWAYS + NTCMD);
  1979. WRW_HARPOON((port + NON_TAG_ID_MSG),
  1980. (MPM_OP + AMSG_OUT + currSCCB->Sccb_idmsg));
  1981. currSCCB->Sccb_scsistat = SELECT_ST;
  1982. WR_HARPOON(port + hp_autostart_3,
  1983. (SELECT + SELCHK_STRT));
  1984. }
  1985. theCCB = (unsigned char *)&currSCCB->Cdb[0];
  1986. cdb_reg = port + CMD_STRT;
  1987. for (i = 0; i < currSCCB->CdbLength; i++) {
  1988. WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + *theCCB));
  1989. cdb_reg += 2;
  1990. theCCB++;
  1991. }
  1992. if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
  1993. WRW_HARPOON(cdb_reg, (BRH_OP + ALWAYS + NP));
  1994. }
  1995. /* auto_loaded */
  1996. WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
  1997. WR_HARPOON(port + hp_xferstat, 0x00);
  1998. WRW_HARPOON((port + hp_intstat), (PROG_HLT | TIMEOUT | SEL | BUS_FREE));
  1999. WR_HARPOON(port + hp_portctrl_0, (SCSI_PORT));
  2000. if (!(currSCCB->Sccb_MGRFlags & F_DEV_SELECTED)) {
  2001. WR_HARPOON(port + hp_scsictrl_0,
  2002. (SEL_TAR | ENA_ATN | ENA_RESEL | ENA_SCAM_SEL));
  2003. } else {
  2004. /* auto_loaded = (RD_HARPOON(port+hp_autostart_3) & (unsigned char)0x1F);
  2005. auto_loaded |= AUTO_IMMED; */
  2006. auto_loaded = AUTO_IMMED;
  2007. DISABLE_AUTO(port);
  2008. WR_HARPOON(port + hp_autostart_3, auto_loaded);
  2009. }
  2010. SGRAM_ACCESS(port);
  2011. }
  2012. /*---------------------------------------------------------------------
  2013. *
  2014. * Function: FPT_sres
  2015. *
  2016. * Description: Hookup the correct CCB and handle the incoming messages.
  2017. *
  2018. *---------------------------------------------------------------------*/
  2019. static void FPT_sres(u32 port, unsigned char p_card,
  2020. struct sccb_card *pCurrCard)
  2021. {
  2022. unsigned char our_target, message, lun = 0, tag, msgRetryCount;
  2023. struct sccb_mgr_tar_info *currTar_Info;
  2024. struct sccb *currSCCB;
  2025. if (pCurrCard->currentSCCB != NULL) {
  2026. currTar_Info =
  2027. &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
  2028. DISABLE_AUTO(port);
  2029. WR_HARPOON((port + hp_scsictrl_0), (ENA_RESEL | ENA_SCAM_SEL));
  2030. currSCCB = pCurrCard->currentSCCB;
  2031. if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
  2032. currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
  2033. currSCCB->Sccb_scsistat = BUS_FREE_ST;
  2034. }
  2035. if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
  2036. currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
  2037. currSCCB->Sccb_scsistat = BUS_FREE_ST;
  2038. }
  2039. if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
  2040. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
  2041. TAG_Q_TRYING))) {
  2042. currTar_Info->TarLUNBusy[currSCCB->Lun] = 0;
  2043. if (currSCCB->Sccb_scsistat != ABORT_ST) {
  2044. pCurrCard->discQCount--;
  2045. pCurrCard->discQ_Tbl[currTar_Info->
  2046. LunDiscQ_Idx[currSCCB->
  2047. Lun]]
  2048. = NULL;
  2049. }
  2050. } else {
  2051. currTar_Info->TarLUNBusy[0] = 0;
  2052. if (currSCCB->Sccb_tag) {
  2053. if (currSCCB->Sccb_scsistat != ABORT_ST) {
  2054. pCurrCard->discQCount--;
  2055. pCurrCard->discQ_Tbl[currSCCB->
  2056. Sccb_tag] = NULL;
  2057. }
  2058. } else {
  2059. if (currSCCB->Sccb_scsistat != ABORT_ST) {
  2060. pCurrCard->discQCount--;
  2061. pCurrCard->discQ_Tbl[currTar_Info->
  2062. LunDiscQ_Idx[0]] =
  2063. NULL;
  2064. }
  2065. }
  2066. }
  2067. FPT_queueSelectFail(&FPT_BL_Card[p_card], p_card);
  2068. }
  2069. WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
  2070. our_target = (unsigned char)(RD_HARPOON(port + hp_select_id) >> 4);
  2071. currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
  2072. msgRetryCount = 0;
  2073. do {
  2074. currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
  2075. tag = 0;
  2076. while (!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) {
  2077. if (!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) {
  2078. WRW_HARPOON((port + hp_intstat), PHASE);
  2079. return;
  2080. }
  2081. }
  2082. WRW_HARPOON((port + hp_intstat), PHASE);
  2083. if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) == S_MSGI_PH) {
  2084. message = FPT_sfm(port, pCurrCard->currentSCCB);
  2085. if (message) {
  2086. if (message <= (0x80 | LUN_MASK)) {
  2087. lun = message & (unsigned char)LUN_MASK;
  2088. if ((currTar_Info->
  2089. TarStatus & TAR_TAG_Q_MASK) ==
  2090. TAG_Q_TRYING) {
  2091. if (currTar_Info->TarTagQ_Cnt !=
  2092. 0) {
  2093. if (!
  2094. (currTar_Info->
  2095. TarLUN_CA)) {
  2096. ACCEPT_MSG(port); /*Release the ACK for ID msg. */
  2097. message =
  2098. FPT_sfm
  2099. (port,
  2100. pCurrCard->
  2101. currentSCCB);
  2102. if (message) {
  2103. ACCEPT_MSG
  2104. (port);
  2105. }
  2106. else
  2107. message
  2108. = 0;
  2109. if (message !=
  2110. 0) {
  2111. tag =
  2112. FPT_sfm
  2113. (port,
  2114. pCurrCard->
  2115. currentSCCB);
  2116. if (!
  2117. (tag))
  2118. message
  2119. =
  2120. 0;
  2121. }
  2122. }
  2123. /*C.A. exists! */
  2124. }
  2125. /*End Q cnt != 0 */
  2126. }
  2127. /*End Tag cmds supported! */
  2128. }
  2129. /*End valid ID message. */
  2130. else {
  2131. ACCEPT_MSG_ATN(port);
  2132. }
  2133. }
  2134. /* End good id message. */
  2135. else {
  2136. message = 0;
  2137. }
  2138. } else {
  2139. ACCEPT_MSG_ATN(port);
  2140. while (!
  2141. (RDW_HARPOON((port + hp_intstat)) &
  2142. (PHASE | RESET))
  2143. && !(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)
  2144. && (RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ;
  2145. return;
  2146. }
  2147. if (message == 0) {
  2148. msgRetryCount++;
  2149. if (msgRetryCount == 1) {
  2150. FPT_SendMsg(port, MSG_PARITY_ERROR);
  2151. } else {
  2152. FPT_SendMsg(port, TARGET_RESET);
  2153. FPT_sssyncv(port, our_target, NARROW_SCSI,
  2154. currTar_Info);
  2155. if (FPT_sccbMgrTbl[p_card][our_target].
  2156. TarEEValue & EE_SYNC_MASK) {
  2157. FPT_sccbMgrTbl[p_card][our_target].
  2158. TarStatus &= ~TAR_SYNC_MASK;
  2159. }
  2160. if (FPT_sccbMgrTbl[p_card][our_target].
  2161. TarEEValue & EE_WIDE_SCSI) {
  2162. FPT_sccbMgrTbl[p_card][our_target].
  2163. TarStatus &= ~TAR_WIDE_MASK;
  2164. }
  2165. FPT_queueFlushTargSccb(p_card, our_target,
  2166. SCCB_COMPLETE);
  2167. FPT_SccbMgrTableInitTarget(p_card, our_target);
  2168. return;
  2169. }
  2170. }
  2171. } while (message == 0);
  2172. if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
  2173. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
  2174. currTar_Info->TarLUNBusy[lun] = 1;
  2175. pCurrCard->currentSCCB =
  2176. pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[lun]];
  2177. if (pCurrCard->currentSCCB != NULL) {
  2178. ACCEPT_MSG(port);
  2179. } else {
  2180. ACCEPT_MSG_ATN(port);
  2181. }
  2182. } else {
  2183. currTar_Info->TarLUNBusy[0] = 1;
  2184. if (tag) {
  2185. if (pCurrCard->discQ_Tbl[tag] != NULL) {
  2186. pCurrCard->currentSCCB =
  2187. pCurrCard->discQ_Tbl[tag];
  2188. currTar_Info->TarTagQ_Cnt--;
  2189. ACCEPT_MSG(port);
  2190. } else {
  2191. ACCEPT_MSG_ATN(port);
  2192. }
  2193. } else {
  2194. pCurrCard->currentSCCB =
  2195. pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]];
  2196. if (pCurrCard->currentSCCB != NULL) {
  2197. ACCEPT_MSG(port);
  2198. } else {
  2199. ACCEPT_MSG_ATN(port);
  2200. }
  2201. }
  2202. }
  2203. if (pCurrCard->currentSCCB != NULL) {
  2204. if (pCurrCard->currentSCCB->Sccb_scsistat == ABORT_ST) {
  2205. /* During Abort Tag command, the target could have got re-selected
  2206. and completed the command. Check the select Q and remove the CCB
  2207. if it is in the Select Q */
  2208. FPT_queueFindSccb(pCurrCard->currentSCCB, p_card);
  2209. }
  2210. }
  2211. while (!(RDW_HARPOON((port + hp_intstat)) & (PHASE | RESET)) &&
  2212. !(RD_HARPOON(port + hp_scsisig) & SCSI_REQ) &&
  2213. (RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ;
  2214. }
  2215. static void FPT_SendMsg(u32 port, unsigned char message)
  2216. {
  2217. while (!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) {
  2218. if (!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) {
  2219. WRW_HARPOON((port + hp_intstat), PHASE);
  2220. return;
  2221. }
  2222. }
  2223. WRW_HARPOON((port + hp_intstat), PHASE);
  2224. if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) == S_MSGO_PH) {
  2225. WRW_HARPOON((port + hp_intstat),
  2226. (BUS_FREE | PHASE | XFER_CNT_0));
  2227. WR_HARPOON(port + hp_portctrl_0, SCSI_BUS_EN);
  2228. WR_HARPOON(port + hp_scsidata_0, message);
  2229. WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
  2230. ACCEPT_MSG(port);
  2231. WR_HARPOON(port + hp_portctrl_0, 0x00);
  2232. if ((message == ABORT_TASK_SET) || (message == TARGET_RESET) ||
  2233. (message == ABORT_TASK)) {
  2234. while (!
  2235. (RDW_HARPOON((port + hp_intstat)) &
  2236. (BUS_FREE | PHASE))) {
  2237. }
  2238. if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
  2239. WRW_HARPOON((port + hp_intstat), BUS_FREE);
  2240. }
  2241. }
  2242. }
  2243. }
  2244. /*---------------------------------------------------------------------
  2245. *
  2246. * Function: FPT_sdecm
  2247. *
  2248. * Description: Determine the proper response to the message from the
  2249. * target device.
  2250. *
  2251. *---------------------------------------------------------------------*/
  2252. static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card)
  2253. {
  2254. struct sccb *currSCCB;
  2255. struct sccb_card *CurrCard;
  2256. struct sccb_mgr_tar_info *currTar_Info;
  2257. CurrCard = &FPT_BL_Card[p_card];
  2258. currSCCB = CurrCard->currentSCCB;
  2259. currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
  2260. if (message == RESTORE_POINTERS) {
  2261. if (!(currSCCB->Sccb_XferState & F_NO_DATA_YET)) {
  2262. currSCCB->Sccb_ATC = currSCCB->Sccb_savedATC;
  2263. FPT_hostDataXferRestart(currSCCB);
  2264. }
  2265. ACCEPT_MSG(port);
  2266. WR_HARPOON(port + hp_autostart_1,
  2267. (AUTO_IMMED + DISCONNECT_START));
  2268. }
  2269. else if (message == COMMAND_COMPLETE) {
  2270. if (currSCCB->Sccb_scsistat == SELECT_Q_ST) {
  2271. currTar_Info->TarStatus &=
  2272. ~(unsigned char)TAR_TAG_Q_MASK;
  2273. currTar_Info->TarStatus |= (unsigned char)TAG_Q_REJECT;
  2274. }
  2275. ACCEPT_MSG(port);
  2276. }
  2277. else if ((message == NOP) || (message >= IDENTIFY_BASE) ||
  2278. (message == INITIATE_RECOVERY) ||
  2279. (message == RELEASE_RECOVERY)) {
  2280. ACCEPT_MSG(port);
  2281. WR_HARPOON(port + hp_autostart_1,
  2282. (AUTO_IMMED + DISCONNECT_START));
  2283. }
  2284. else if (message == MESSAGE_REJECT) {
  2285. if ((currSCCB->Sccb_scsistat == SELECT_SN_ST) ||
  2286. (currSCCB->Sccb_scsistat == SELECT_WN_ST) ||
  2287. ((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)
  2288. || ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) ==
  2289. TAG_Q_TRYING))
  2290. {
  2291. WRW_HARPOON((port + hp_intstat), BUS_FREE);
  2292. ACCEPT_MSG(port);
  2293. while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
  2294. (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)))
  2295. {
  2296. }
  2297. if (currSCCB->Lun == 0x00) {
  2298. if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
  2299. currTar_Info->TarStatus |=
  2300. (unsigned char)SYNC_SUPPORTED;
  2301. currTar_Info->TarEEValue &=
  2302. ~EE_SYNC_MASK;
  2303. }
  2304. else if (currSCCB->Sccb_scsistat ==
  2305. SELECT_WN_ST) {
  2306. currTar_Info->TarStatus =
  2307. (currTar_Info->
  2308. TarStatus & ~WIDE_ENABLED) |
  2309. WIDE_NEGOCIATED;
  2310. currTar_Info->TarEEValue &=
  2311. ~EE_WIDE_SCSI;
  2312. }
  2313. else if ((currTar_Info->
  2314. TarStatus & TAR_TAG_Q_MASK) ==
  2315. TAG_Q_TRYING) {
  2316. currTar_Info->TarStatus =
  2317. (currTar_Info->
  2318. TarStatus & ~(unsigned char)
  2319. TAR_TAG_Q_MASK) | TAG_Q_REJECT;
  2320. currSCCB->ControlByte &= ~F_USE_CMD_Q;
  2321. CurrCard->discQCount--;
  2322. CurrCard->discQ_Tbl[currSCCB->
  2323. Sccb_tag] = NULL;
  2324. currSCCB->Sccb_tag = 0x00;
  2325. }
  2326. }
  2327. if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
  2328. if (currSCCB->Lun == 0x00) {
  2329. WRW_HARPOON((port + hp_intstat),
  2330. BUS_FREE);
  2331. CurrCard->globalFlags |= F_NEW_SCCB_CMD;
  2332. }
  2333. }
  2334. else {
  2335. if ((CurrCard->globalFlags & F_CONLUN_IO) &&
  2336. ((currTar_Info->
  2337. TarStatus & TAR_TAG_Q_MASK) !=
  2338. TAG_Q_TRYING))
  2339. currTar_Info->TarLUNBusy[currSCCB->
  2340. Lun] = 1;
  2341. else
  2342. currTar_Info->TarLUNBusy[0] = 1;
  2343. currSCCB->ControlByte &=
  2344. ~(unsigned char)F_USE_CMD_Q;
  2345. WR_HARPOON(port + hp_autostart_1,
  2346. (AUTO_IMMED + DISCONNECT_START));
  2347. }
  2348. }
  2349. else {
  2350. ACCEPT_MSG(port);
  2351. while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
  2352. (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)))
  2353. {
  2354. }
  2355. if (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)) {
  2356. WR_HARPOON(port + hp_autostart_1,
  2357. (AUTO_IMMED + DISCONNECT_START));
  2358. }
  2359. }
  2360. }
  2361. else if (message == EXTENDED_MESSAGE) {
  2362. ACCEPT_MSG(port);
  2363. FPT_shandem(port, p_card, currSCCB);
  2364. }
  2365. else if (message == IGNORE_WIDE_RESIDUE) {
  2366. ACCEPT_MSG(port); /* ACK the RESIDUE MSG */
  2367. message = FPT_sfm(port, currSCCB);
  2368. if (currSCCB->Sccb_scsimsg != MSG_PARITY_ERROR)
  2369. ACCEPT_MSG(port);
  2370. WR_HARPOON(port + hp_autostart_1,
  2371. (AUTO_IMMED + DISCONNECT_START));
  2372. }
  2373. else {
  2374. currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
  2375. currSCCB->Sccb_scsimsg = MESSAGE_REJECT;
  2376. ACCEPT_MSG_ATN(port);
  2377. WR_HARPOON(port + hp_autostart_1,
  2378. (AUTO_IMMED + DISCONNECT_START));
  2379. }
  2380. }
  2381. /*---------------------------------------------------------------------
  2382. *
  2383. * Function: FPT_shandem
  2384. *
  2385. * Description: Decide what to do with the extended message.
  2386. *
  2387. *---------------------------------------------------------------------*/
  2388. static void FPT_shandem(u32 port, unsigned char p_card, struct sccb *pCurrSCCB)
  2389. {
  2390. unsigned char length, message;
  2391. length = FPT_sfm(port, pCurrSCCB);
  2392. if (length) {
  2393. ACCEPT_MSG(port);
  2394. message = FPT_sfm(port, pCurrSCCB);
  2395. if (message) {
  2396. if (message == EXTENDED_SDTR) {
  2397. if (length == 0x03) {
  2398. ACCEPT_MSG(port);
  2399. FPT_stsyncn(port, p_card);
  2400. } else {
  2401. pCurrSCCB->Sccb_scsimsg = MESSAGE_REJECT;
  2402. ACCEPT_MSG_ATN(port);
  2403. }
  2404. } else if (message == EXTENDED_WDTR) {
  2405. if (length == 0x02) {
  2406. ACCEPT_MSG(port);
  2407. FPT_stwidn(port, p_card);
  2408. } else {
  2409. pCurrSCCB->Sccb_scsimsg = MESSAGE_REJECT;
  2410. ACCEPT_MSG_ATN(port);
  2411. WR_HARPOON(port + hp_autostart_1,
  2412. (AUTO_IMMED +
  2413. DISCONNECT_START));
  2414. }
  2415. } else {
  2416. pCurrSCCB->Sccb_scsimsg = MESSAGE_REJECT;
  2417. ACCEPT_MSG_ATN(port);
  2418. WR_HARPOON(port + hp_autostart_1,
  2419. (AUTO_IMMED + DISCONNECT_START));
  2420. }
  2421. } else {
  2422. if (pCurrSCCB->Sccb_scsimsg != MSG_PARITY_ERROR)
  2423. ACCEPT_MSG(port);
  2424. WR_HARPOON(port + hp_autostart_1,
  2425. (AUTO_IMMED + DISCONNECT_START));
  2426. }
  2427. } else {
  2428. if (pCurrSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)
  2429. WR_HARPOON(port + hp_autostart_1,
  2430. (AUTO_IMMED + DISCONNECT_START));
  2431. }
  2432. }
  2433. /*---------------------------------------------------------------------
  2434. *
  2435. * Function: FPT_sisyncn
  2436. *
  2437. * Description: Read in a message byte from the SCSI bus, and check
  2438. * for a parity error.
  2439. *
  2440. *---------------------------------------------------------------------*/
  2441. static unsigned char FPT_sisyncn(u32 port, unsigned char p_card,
  2442. unsigned char syncFlag)
  2443. {
  2444. struct sccb *currSCCB;
  2445. struct sccb_mgr_tar_info *currTar_Info;
  2446. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  2447. currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
  2448. if (!((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)) {
  2449. WRW_HARPOON((port + ID_MSG_STRT),
  2450. (MPM_OP + AMSG_OUT +
  2451. (currSCCB->
  2452. Sccb_idmsg & ~(unsigned char)DISC_PRIV)));
  2453. WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
  2454. WRW_HARPOON((port + SYNC_MSGS + 0),
  2455. (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE));
  2456. WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03));
  2457. WRW_HARPOON((port + SYNC_MSGS + 4),
  2458. (MPM_OP + AMSG_OUT + EXTENDED_SDTR));
  2459. if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
  2460. WRW_HARPOON((port + SYNC_MSGS + 6),
  2461. (MPM_OP + AMSG_OUT + 12));
  2462. else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) ==
  2463. EE_SYNC_10MB)
  2464. WRW_HARPOON((port + SYNC_MSGS + 6),
  2465. (MPM_OP + AMSG_OUT + 25));
  2466. else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) ==
  2467. EE_SYNC_5MB)
  2468. WRW_HARPOON((port + SYNC_MSGS + 6),
  2469. (MPM_OP + AMSG_OUT + 50));
  2470. else
  2471. WRW_HARPOON((port + SYNC_MSGS + 6),
  2472. (MPM_OP + AMSG_OUT + 00));
  2473. WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP));
  2474. WRW_HARPOON((port + SYNC_MSGS + 10),
  2475. (MPM_OP + AMSG_OUT + DEFAULT_OFFSET));
  2476. WRW_HARPOON((port + SYNC_MSGS + 12), (BRH_OP + ALWAYS + NP));
  2477. if (syncFlag == 0) {
  2478. WR_HARPOON(port + hp_autostart_3,
  2479. (SELECT + SELCHK_STRT));
  2480. currTar_Info->TarStatus =
  2481. ((currTar_Info->
  2482. TarStatus & ~(unsigned char)TAR_SYNC_MASK) |
  2483. (unsigned char)SYNC_TRYING);
  2484. } else {
  2485. WR_HARPOON(port + hp_autostart_3,
  2486. (AUTO_IMMED + CMD_ONLY_STRT));
  2487. }
  2488. return 1;
  2489. }
  2490. else {
  2491. currTar_Info->TarStatus |= (unsigned char)SYNC_SUPPORTED;
  2492. currTar_Info->TarEEValue &= ~EE_SYNC_MASK;
  2493. return 0;
  2494. }
  2495. }
  2496. /*---------------------------------------------------------------------
  2497. *
  2498. * Function: FPT_stsyncn
  2499. *
  2500. * Description: The has sent us a Sync Nego message so handle it as
  2501. * necessary.
  2502. *
  2503. *---------------------------------------------------------------------*/
  2504. static void FPT_stsyncn(u32 port, unsigned char p_card)
  2505. {
  2506. unsigned char sync_msg, offset, sync_reg, our_sync_msg;
  2507. struct sccb *currSCCB;
  2508. struct sccb_mgr_tar_info *currTar_Info;
  2509. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  2510. currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
  2511. sync_msg = FPT_sfm(port, currSCCB);
  2512. if ((sync_msg == 0x00) && (currSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)) {
  2513. WR_HARPOON(port + hp_autostart_1,
  2514. (AUTO_IMMED + DISCONNECT_START));
  2515. return;
  2516. }
  2517. ACCEPT_MSG(port);
  2518. offset = FPT_sfm(port, currSCCB);
  2519. if ((offset == 0x00) && (currSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)) {
  2520. WR_HARPOON(port + hp_autostart_1,
  2521. (AUTO_IMMED + DISCONNECT_START));
  2522. return;
  2523. }
  2524. if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
  2525. our_sync_msg = 12; /* Setup our Message to 20mb/s */
  2526. else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_10MB)
  2527. our_sync_msg = 25; /* Setup our Message to 10mb/s */
  2528. else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_5MB)
  2529. our_sync_msg = 50; /* Setup our Message to 5mb/s */
  2530. else
  2531. our_sync_msg = 0; /* Message = Async */
  2532. if (sync_msg < our_sync_msg) {
  2533. sync_msg = our_sync_msg; /*if faster, then set to max. */
  2534. }
  2535. if (offset == ASYNC)
  2536. sync_msg = ASYNC;
  2537. if (offset > MAX_OFFSET)
  2538. offset = MAX_OFFSET;
  2539. sync_reg = 0x00;
  2540. if (sync_msg > 12)
  2541. sync_reg = 0x20; /* Use 10MB/s */
  2542. if (sync_msg > 25)
  2543. sync_reg = 0x40; /* Use 6.6MB/s */
  2544. if (sync_msg > 38)
  2545. sync_reg = 0x60; /* Use 5MB/s */
  2546. if (sync_msg > 50)
  2547. sync_reg = 0x80; /* Use 4MB/s */
  2548. if (sync_msg > 62)
  2549. sync_reg = 0xA0; /* Use 3.33MB/s */
  2550. if (sync_msg > 75)
  2551. sync_reg = 0xC0; /* Use 2.85MB/s */
  2552. if (sync_msg > 87)
  2553. sync_reg = 0xE0; /* Use 2.5MB/s */
  2554. if (sync_msg > 100) {
  2555. sync_reg = 0x00; /* Use ASYNC */
  2556. offset = 0x00;
  2557. }
  2558. if (currTar_Info->TarStatus & WIDE_ENABLED)
  2559. sync_reg |= offset;
  2560. else
  2561. sync_reg |= (offset | NARROW_SCSI);
  2562. FPT_sssyncv(port, currSCCB->TargID, sync_reg, currTar_Info);
  2563. if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
  2564. ACCEPT_MSG(port);
  2565. currTar_Info->TarStatus = ((currTar_Info->TarStatus &
  2566. ~(unsigned char)TAR_SYNC_MASK) |
  2567. (unsigned char)SYNC_SUPPORTED);
  2568. WR_HARPOON(port + hp_autostart_1,
  2569. (AUTO_IMMED + DISCONNECT_START));
  2570. }
  2571. else {
  2572. ACCEPT_MSG_ATN(port);
  2573. FPT_sisyncr(port, sync_msg, offset);
  2574. currTar_Info->TarStatus = ((currTar_Info->TarStatus &
  2575. ~(unsigned char)TAR_SYNC_MASK) |
  2576. (unsigned char)SYNC_SUPPORTED);
  2577. }
  2578. }
  2579. /*---------------------------------------------------------------------
  2580. *
  2581. * Function: FPT_sisyncr
  2582. *
  2583. * Description: Answer the targets sync message.
  2584. *
  2585. *---------------------------------------------------------------------*/
  2586. static void FPT_sisyncr(u32 port, unsigned char sync_pulse,
  2587. unsigned char offset)
  2588. {
  2589. ARAM_ACCESS(port);
  2590. WRW_HARPOON((port + SYNC_MSGS + 0),
  2591. (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE));
  2592. WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03));
  2593. WRW_HARPOON((port + SYNC_MSGS + 4),
  2594. (MPM_OP + AMSG_OUT + EXTENDED_SDTR));
  2595. WRW_HARPOON((port + SYNC_MSGS + 6), (MPM_OP + AMSG_OUT + sync_pulse));
  2596. WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP));
  2597. WRW_HARPOON((port + SYNC_MSGS + 10), (MPM_OP + AMSG_OUT + offset));
  2598. WRW_HARPOON((port + SYNC_MSGS + 12), (BRH_OP + ALWAYS + NP));
  2599. SGRAM_ACCESS(port);
  2600. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  2601. WRW_HARPOON((port + hp_intstat), CLR_ALL_INT_1);
  2602. WR_HARPOON(port + hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
  2603. while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | AUTO_INT))) {
  2604. }
  2605. }
  2606. /*---------------------------------------------------------------------
  2607. *
  2608. * Function: FPT_siwidn
  2609. *
  2610. * Description: Read in a message byte from the SCSI bus, and check
  2611. * for a parity error.
  2612. *
  2613. *---------------------------------------------------------------------*/
  2614. static unsigned char FPT_siwidn(u32 port, unsigned char p_card)
  2615. {
  2616. struct sccb *currSCCB;
  2617. struct sccb_mgr_tar_info *currTar_Info;
  2618. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  2619. currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
  2620. if (!((currTar_Info->TarStatus & TAR_WIDE_MASK) == WIDE_NEGOCIATED)) {
  2621. WRW_HARPOON((port + ID_MSG_STRT),
  2622. (MPM_OP + AMSG_OUT +
  2623. (currSCCB->
  2624. Sccb_idmsg & ~(unsigned char)DISC_PRIV)));
  2625. WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
  2626. WRW_HARPOON((port + SYNC_MSGS + 0),
  2627. (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE));
  2628. WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02));
  2629. WRW_HARPOON((port + SYNC_MSGS + 4),
  2630. (MPM_OP + AMSG_OUT + EXTENDED_WDTR));
  2631. WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP));
  2632. WRW_HARPOON((port + SYNC_MSGS + 8),
  2633. (MPM_OP + AMSG_OUT + SM16BIT));
  2634. WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP));
  2635. WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
  2636. currTar_Info->TarStatus = ((currTar_Info->TarStatus &
  2637. ~(unsigned char)TAR_WIDE_MASK) |
  2638. (unsigned char)WIDE_ENABLED);
  2639. return 1;
  2640. }
  2641. else {
  2642. currTar_Info->TarStatus = ((currTar_Info->TarStatus &
  2643. ~(unsigned char)TAR_WIDE_MASK) |
  2644. WIDE_NEGOCIATED);
  2645. currTar_Info->TarEEValue &= ~EE_WIDE_SCSI;
  2646. return 0;
  2647. }
  2648. }
  2649. /*---------------------------------------------------------------------
  2650. *
  2651. * Function: FPT_stwidn
  2652. *
  2653. * Description: The has sent us a Wide Nego message so handle it as
  2654. * necessary.
  2655. *
  2656. *---------------------------------------------------------------------*/
  2657. static void FPT_stwidn(u32 port, unsigned char p_card)
  2658. {
  2659. unsigned char width;
  2660. struct sccb *currSCCB;
  2661. struct sccb_mgr_tar_info *currTar_Info;
  2662. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  2663. currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
  2664. width = FPT_sfm(port, currSCCB);
  2665. if ((width == 0x00) && (currSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)) {
  2666. WR_HARPOON(port + hp_autostart_1,
  2667. (AUTO_IMMED + DISCONNECT_START));
  2668. return;
  2669. }
  2670. if (!(currTar_Info->TarEEValue & EE_WIDE_SCSI))
  2671. width = 0;
  2672. if (width) {
  2673. currTar_Info->TarStatus |= WIDE_ENABLED;
  2674. width = 0;
  2675. } else {
  2676. width = NARROW_SCSI;
  2677. currTar_Info->TarStatus &= ~WIDE_ENABLED;
  2678. }
  2679. FPT_sssyncv(port, currSCCB->TargID, width, currTar_Info);
  2680. if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
  2681. currTar_Info->TarStatus |= WIDE_NEGOCIATED;
  2682. if (!
  2683. ((currTar_Info->TarStatus & TAR_SYNC_MASK) ==
  2684. SYNC_SUPPORTED)) {
  2685. ACCEPT_MSG_ATN(port);
  2686. ARAM_ACCESS(port);
  2687. FPT_sisyncn(port, p_card, 1);
  2688. currSCCB->Sccb_scsistat = SELECT_SN_ST;
  2689. SGRAM_ACCESS(port);
  2690. } else {
  2691. ACCEPT_MSG(port);
  2692. WR_HARPOON(port + hp_autostart_1,
  2693. (AUTO_IMMED + DISCONNECT_START));
  2694. }
  2695. }
  2696. else {
  2697. ACCEPT_MSG_ATN(port);
  2698. if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
  2699. width = SM16BIT;
  2700. else
  2701. width = SM8BIT;
  2702. FPT_siwidr(port, width);
  2703. currTar_Info->TarStatus |= (WIDE_NEGOCIATED | WIDE_ENABLED);
  2704. }
  2705. }
  2706. /*---------------------------------------------------------------------
  2707. *
  2708. * Function: FPT_siwidr
  2709. *
  2710. * Description: Answer the targets Wide nego message.
  2711. *
  2712. *---------------------------------------------------------------------*/
  2713. static void FPT_siwidr(u32 port, unsigned char width)
  2714. {
  2715. ARAM_ACCESS(port);
  2716. WRW_HARPOON((port + SYNC_MSGS + 0),
  2717. (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE));
  2718. WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02));
  2719. WRW_HARPOON((port + SYNC_MSGS + 4),
  2720. (MPM_OP + AMSG_OUT + EXTENDED_WDTR));
  2721. WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP));
  2722. WRW_HARPOON((port + SYNC_MSGS + 8), (MPM_OP + AMSG_OUT + width));
  2723. WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP));
  2724. SGRAM_ACCESS(port);
  2725. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  2726. WRW_HARPOON((port + hp_intstat), CLR_ALL_INT_1);
  2727. WR_HARPOON(port + hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
  2728. while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | AUTO_INT))) {
  2729. }
  2730. }
  2731. /*---------------------------------------------------------------------
  2732. *
  2733. * Function: FPT_sssyncv
  2734. *
  2735. * Description: Write the desired value to the Sync Register for the
  2736. * ID specified.
  2737. *
  2738. *---------------------------------------------------------------------*/
  2739. static void FPT_sssyncv(u32 p_port, unsigned char p_id,
  2740. unsigned char p_sync_value,
  2741. struct sccb_mgr_tar_info *currTar_Info)
  2742. {
  2743. unsigned char index;
  2744. index = p_id;
  2745. switch (index) {
  2746. case 0:
  2747. index = 12; /* hp_synctarg_0 */
  2748. break;
  2749. case 1:
  2750. index = 13; /* hp_synctarg_1 */
  2751. break;
  2752. case 2:
  2753. index = 14; /* hp_synctarg_2 */
  2754. break;
  2755. case 3:
  2756. index = 15; /* hp_synctarg_3 */
  2757. break;
  2758. case 4:
  2759. index = 8; /* hp_synctarg_4 */
  2760. break;
  2761. case 5:
  2762. index = 9; /* hp_synctarg_5 */
  2763. break;
  2764. case 6:
  2765. index = 10; /* hp_synctarg_6 */
  2766. break;
  2767. case 7:
  2768. index = 11; /* hp_synctarg_7 */
  2769. break;
  2770. case 8:
  2771. index = 4; /* hp_synctarg_8 */
  2772. break;
  2773. case 9:
  2774. index = 5; /* hp_synctarg_9 */
  2775. break;
  2776. case 10:
  2777. index = 6; /* hp_synctarg_10 */
  2778. break;
  2779. case 11:
  2780. index = 7; /* hp_synctarg_11 */
  2781. break;
  2782. case 12:
  2783. index = 0; /* hp_synctarg_12 */
  2784. break;
  2785. case 13:
  2786. index = 1; /* hp_synctarg_13 */
  2787. break;
  2788. case 14:
  2789. index = 2; /* hp_synctarg_14 */
  2790. break;
  2791. case 15:
  2792. index = 3; /* hp_synctarg_15 */
  2793. }
  2794. WR_HARPOON(p_port + hp_synctarg_base + index, p_sync_value);
  2795. currTar_Info->TarSyncCtrl = p_sync_value;
  2796. }
  2797. /*---------------------------------------------------------------------
  2798. *
  2799. * Function: FPT_sresb
  2800. *
  2801. * Description: Reset the desired card's SCSI bus.
  2802. *
  2803. *---------------------------------------------------------------------*/
  2804. static void FPT_sresb(u32 port, unsigned char p_card)
  2805. {
  2806. unsigned char scsiID, i;
  2807. struct sccb_mgr_tar_info *currTar_Info;
  2808. WR_HARPOON(port + hp_page_ctrl,
  2809. (RD_HARPOON(port + hp_page_ctrl) | G_INT_DISABLE));
  2810. WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
  2811. WR_HARPOON(port + hp_scsictrl_0, SCSI_RST);
  2812. scsiID = RD_HARPOON(port + hp_seltimeout);
  2813. WR_HARPOON(port + hp_seltimeout, TO_5ms);
  2814. WRW_HARPOON((port + hp_intstat), TIMEOUT);
  2815. WR_HARPOON(port + hp_portctrl_0, (SCSI_PORT | START_TO));
  2816. while (!(RDW_HARPOON((port + hp_intstat)) & TIMEOUT)) {
  2817. }
  2818. WR_HARPOON(port + hp_seltimeout, scsiID);
  2819. WR_HARPOON(port + hp_scsictrl_0, ENA_SCAM_SEL);
  2820. FPT_Wait(port, TO_5ms);
  2821. WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
  2822. WR_HARPOON(port + hp_int_mask, (RD_HARPOON(port + hp_int_mask) | 0x00));
  2823. for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++) {
  2824. currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
  2825. if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
  2826. currTar_Info->TarSyncCtrl = 0;
  2827. currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
  2828. }
  2829. if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
  2830. currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
  2831. }
  2832. FPT_sssyncv(port, scsiID, NARROW_SCSI, currTar_Info);
  2833. FPT_SccbMgrTableInitTarget(p_card, scsiID);
  2834. }
  2835. FPT_BL_Card[p_card].scanIndex = 0x00;
  2836. FPT_BL_Card[p_card].currentSCCB = NULL;
  2837. FPT_BL_Card[p_card].globalFlags &= ~(F_TAG_STARTED | F_HOST_XFER_ACT
  2838. | F_NEW_SCCB_CMD);
  2839. FPT_BL_Card[p_card].cmdCounter = 0x00;
  2840. FPT_BL_Card[p_card].discQCount = 0x00;
  2841. FPT_BL_Card[p_card].tagQ_Lst = 0x01;
  2842. for (i = 0; i < QUEUE_DEPTH; i++)
  2843. FPT_BL_Card[p_card].discQ_Tbl[i] = NULL;
  2844. WR_HARPOON(port + hp_page_ctrl,
  2845. (RD_HARPOON(port + hp_page_ctrl) & ~G_INT_DISABLE));
  2846. }
  2847. /*---------------------------------------------------------------------
  2848. *
  2849. * Function: FPT_ssenss
  2850. *
  2851. * Description: Setup for the Auto Sense command.
  2852. *
  2853. *---------------------------------------------------------------------*/
  2854. static void FPT_ssenss(struct sccb_card *pCurrCard)
  2855. {
  2856. unsigned char i;
  2857. struct sccb *currSCCB;
  2858. currSCCB = pCurrCard->currentSCCB;
  2859. currSCCB->Save_CdbLen = currSCCB->CdbLength;
  2860. for (i = 0; i < 6; i++) {
  2861. currSCCB->Save_Cdb[i] = currSCCB->Cdb[i];
  2862. }
  2863. currSCCB->CdbLength = SIX_BYTE_CMD;
  2864. currSCCB->Cdb[0] = REQUEST_SENSE;
  2865. currSCCB->Cdb[1] = currSCCB->Cdb[1] & (unsigned char)0xE0; /*Keep LUN. */
  2866. currSCCB->Cdb[2] = 0x00;
  2867. currSCCB->Cdb[3] = 0x00;
  2868. currSCCB->Cdb[4] = currSCCB->RequestSenseLength;
  2869. currSCCB->Cdb[5] = 0x00;
  2870. currSCCB->Sccb_XferCnt = (u32)currSCCB->RequestSenseLength;
  2871. currSCCB->Sccb_ATC = 0x00;
  2872. currSCCB->Sccb_XferState |= F_AUTO_SENSE;
  2873. currSCCB->Sccb_XferState &= ~F_SG_XFER;
  2874. currSCCB->Sccb_idmsg = currSCCB->Sccb_idmsg & ~(unsigned char)DISC_PRIV;
  2875. currSCCB->ControlByte = 0x00;
  2876. currSCCB->Sccb_MGRFlags &= F_STATUSLOADED;
  2877. }
  2878. /*---------------------------------------------------------------------
  2879. *
  2880. * Function: FPT_sxfrp
  2881. *
  2882. * Description: Transfer data into the bit bucket until the device
  2883. * decides to switch phase.
  2884. *
  2885. *---------------------------------------------------------------------*/
  2886. static void FPT_sxfrp(u32 p_port, unsigned char p_card)
  2887. {
  2888. unsigned char curr_phz;
  2889. DISABLE_AUTO(p_port);
  2890. if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
  2891. FPT_hostDataXferAbort(p_port, p_card,
  2892. FPT_BL_Card[p_card].currentSCCB);
  2893. }
  2894. /* If the Automation handled the end of the transfer then do not
  2895. match the phase or we will get out of sync with the ISR. */
  2896. if (RDW_HARPOON((p_port + hp_intstat)) &
  2897. (BUS_FREE | XFER_CNT_0 | AUTO_INT))
  2898. return;
  2899. WR_HARPOON(p_port + hp_xfercnt_0, 0x00);
  2900. curr_phz = RD_HARPOON(p_port + hp_scsisig) & (unsigned char)S_SCSI_PHZ;
  2901. WRW_HARPOON((p_port + hp_intstat), XFER_CNT_0);
  2902. WR_HARPOON(p_port + hp_scsisig, curr_phz);
  2903. while (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET)) &&
  2904. (curr_phz ==
  2905. (RD_HARPOON(p_port + hp_scsisig) & (unsigned char)S_SCSI_PHZ)))
  2906. {
  2907. if (curr_phz & (unsigned char)SCSI_IOBIT) {
  2908. WR_HARPOON(p_port + hp_portctrl_0,
  2909. (SCSI_PORT | HOST_PORT | SCSI_INBIT));
  2910. if (!(RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY)) {
  2911. RD_HARPOON(p_port + hp_fifodata_0);
  2912. }
  2913. } else {
  2914. WR_HARPOON(p_port + hp_portctrl_0,
  2915. (SCSI_PORT | HOST_PORT | HOST_WRT));
  2916. if (RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY) {
  2917. WR_HARPOON(p_port + hp_fifodata_0, 0xFA);
  2918. }
  2919. }
  2920. } /* End of While loop for padding data I/O phase */
  2921. while (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET))) {
  2922. if (RD_HARPOON(p_port + hp_scsisig) & SCSI_REQ)
  2923. break;
  2924. }
  2925. WR_HARPOON(p_port + hp_portctrl_0,
  2926. (SCSI_PORT | HOST_PORT | SCSI_INBIT));
  2927. while (!(RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY)) {
  2928. RD_HARPOON(p_port + hp_fifodata_0);
  2929. }
  2930. if (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET))) {
  2931. WR_HARPOON(p_port + hp_autostart_0,
  2932. (AUTO_IMMED + DISCONNECT_START));
  2933. while (!(RDW_HARPOON((p_port + hp_intstat)) & AUTO_INT)) {
  2934. }
  2935. if (RDW_HARPOON((p_port + hp_intstat)) &
  2936. (ICMD_COMP | ITAR_DISC))
  2937. while (!
  2938. (RDW_HARPOON((p_port + hp_intstat)) &
  2939. (BUS_FREE | RSEL))) ;
  2940. }
  2941. }
  2942. /*---------------------------------------------------------------------
  2943. *
  2944. * Function: FPT_schkdd
  2945. *
  2946. * Description: Make sure data has been flushed from both FIFOs and abort
  2947. * the operations if necessary.
  2948. *
  2949. *---------------------------------------------------------------------*/
  2950. static void FPT_schkdd(u32 port, unsigned char p_card)
  2951. {
  2952. unsigned short TimeOutLoop;
  2953. unsigned char sPhase;
  2954. struct sccb *currSCCB;
  2955. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  2956. if ((currSCCB->Sccb_scsistat != DATA_OUT_ST) &&
  2957. (currSCCB->Sccb_scsistat != DATA_IN_ST)) {
  2958. return;
  2959. }
  2960. if (currSCCB->Sccb_XferState & F_ODD_BALL_CNT) {
  2961. currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - 1);
  2962. currSCCB->Sccb_XferCnt = 1;
  2963. currSCCB->Sccb_XferState &= ~F_ODD_BALL_CNT;
  2964. WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
  2965. WR_HARPOON(port + hp_xferstat, 0x00);
  2966. }
  2967. else {
  2968. currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
  2969. currSCCB->Sccb_XferCnt = 0;
  2970. }
  2971. if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
  2972. (currSCCB->HostStatus == SCCB_COMPLETE)) {
  2973. currSCCB->HostStatus = SCCB_PARITY_ERR;
  2974. WRW_HARPOON((port + hp_intstat), PARITY);
  2975. }
  2976. FPT_hostDataXferAbort(port, p_card, currSCCB);
  2977. while (RD_HARPOON(port + hp_scsisig) & SCSI_ACK) {
  2978. }
  2979. TimeOutLoop = 0;
  2980. while (RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY) {
  2981. if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
  2982. return;
  2983. }
  2984. if (RD_HARPOON(port + hp_offsetctr) & (unsigned char)0x1F) {
  2985. break;
  2986. }
  2987. if (RDW_HARPOON((port + hp_intstat)) & RESET) {
  2988. return;
  2989. }
  2990. if ((RD_HARPOON(port + hp_scsisig) & SCSI_REQ)
  2991. || (TimeOutLoop++ > 0x3000))
  2992. break;
  2993. }
  2994. sPhase = RD_HARPOON(port + hp_scsisig) & (SCSI_BSY | S_SCSI_PHZ);
  2995. if ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) ||
  2996. (RD_HARPOON(port + hp_offsetctr) & (unsigned char)0x1F) ||
  2997. (sPhase == (SCSI_BSY | S_DATAO_PH)) ||
  2998. (sPhase == (SCSI_BSY | S_DATAI_PH))) {
  2999. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  3000. if (!(currSCCB->Sccb_XferState & F_ALL_XFERRED)) {
  3001. if (currSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
  3002. FPT_phaseDataIn(port, p_card);
  3003. }
  3004. else {
  3005. FPT_phaseDataOut(port, p_card);
  3006. }
  3007. } else {
  3008. FPT_sxfrp(port, p_card);
  3009. if (!(RDW_HARPOON((port + hp_intstat)) &
  3010. (BUS_FREE | ICMD_COMP | ITAR_DISC | RESET))) {
  3011. WRW_HARPOON((port + hp_intstat), AUTO_INT);
  3012. FPT_phaseDecode(port, p_card);
  3013. }
  3014. }
  3015. }
  3016. else {
  3017. WR_HARPOON(port + hp_portctrl_0, 0x00);
  3018. }
  3019. }
  3020. /*---------------------------------------------------------------------
  3021. *
  3022. * Function: FPT_sinits
  3023. *
  3024. * Description: Setup SCCB manager fields in this SCCB.
  3025. *
  3026. *---------------------------------------------------------------------*/
  3027. static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card)
  3028. {
  3029. struct sccb_mgr_tar_info *currTar_Info;
  3030. if ((p_sccb->TargID >= MAX_SCSI_TAR) || (p_sccb->Lun >= MAX_LUN)) {
  3031. return;
  3032. }
  3033. currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
  3034. p_sccb->Sccb_XferState = 0x00;
  3035. p_sccb->Sccb_XferCnt = p_sccb->DataLength;
  3036. if ((p_sccb->OperationCode == SCATTER_GATHER_COMMAND) ||
  3037. (p_sccb->OperationCode == RESIDUAL_SG_COMMAND)) {
  3038. p_sccb->Sccb_SGoffset = 0;
  3039. p_sccb->Sccb_XferState = F_SG_XFER;
  3040. p_sccb->Sccb_XferCnt = 0x00;
  3041. }
  3042. if (p_sccb->DataLength == 0x00)
  3043. p_sccb->Sccb_XferState |= F_ALL_XFERRED;
  3044. if (p_sccb->ControlByte & F_USE_CMD_Q) {
  3045. if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
  3046. p_sccb->ControlByte &= ~F_USE_CMD_Q;
  3047. else
  3048. currTar_Info->TarStatus |= TAG_Q_TRYING;
  3049. }
  3050. /* For !single SCSI device in system & device allow Disconnect
  3051. or command is tag_q type then send Cmd with Disconnect Enable
  3052. else send Cmd with Disconnect Disable */
  3053. /*
  3054. if (((!(FPT_BL_Card[p_card].globalFlags & F_SINGLE_DEVICE)) &&
  3055. (currTar_Info->TarStatus & TAR_ALLOW_DISC)) ||
  3056. (currTar_Info->TarStatus & TAG_Q_TRYING)) {
  3057. */
  3058. if ((currTar_Info->TarStatus & TAR_ALLOW_DISC) ||
  3059. (currTar_Info->TarStatus & TAG_Q_TRYING)) {
  3060. p_sccb->Sccb_idmsg = IDENTIFY(true, p_sccb->Lun);
  3061. } else {
  3062. p_sccb->Sccb_idmsg = IDENTIFY(false, p_sccb->Lun);
  3063. }
  3064. p_sccb->HostStatus = 0x00;
  3065. p_sccb->TargetStatus = 0x00;
  3066. p_sccb->Sccb_tag = 0x00;
  3067. p_sccb->Sccb_MGRFlags = 0x00;
  3068. p_sccb->Sccb_sgseg = 0x00;
  3069. p_sccb->Sccb_ATC = 0x00;
  3070. p_sccb->Sccb_savedATC = 0x00;
  3071. /*
  3072. p_sccb->SccbVirtDataPtr = 0x00;
  3073. p_sccb->Sccb_forwardlink = NULL;
  3074. p_sccb->Sccb_backlink = NULL;
  3075. */
  3076. p_sccb->Sccb_scsistat = BUS_FREE_ST;
  3077. p_sccb->SccbStatus = SCCB_IN_PROCESS;
  3078. p_sccb->Sccb_scsimsg = NOP;
  3079. }
  3080. /*---------------------------------------------------------------------
  3081. *
  3082. * Function: Phase Decode
  3083. *
  3084. * Description: Determine the phase and call the appropriate function.
  3085. *
  3086. *---------------------------------------------------------------------*/
  3087. static void FPT_phaseDecode(u32 p_port, unsigned char p_card)
  3088. {
  3089. unsigned char phase_ref;
  3090. void (*phase) (u32, unsigned char);
  3091. DISABLE_AUTO(p_port);
  3092. phase_ref =
  3093. (unsigned char)(RD_HARPOON(p_port + hp_scsisig) & S_SCSI_PHZ);
  3094. phase = FPT_s_PhaseTbl[phase_ref];
  3095. (*phase) (p_port, p_card); /* Call the correct phase func */
  3096. }
  3097. /*---------------------------------------------------------------------
  3098. *
  3099. * Function: Data Out Phase
  3100. *
  3101. * Description: Start up both the BusMaster and Xbow.
  3102. *
  3103. *---------------------------------------------------------------------*/
  3104. static void FPT_phaseDataOut(u32 port, unsigned char p_card)
  3105. {
  3106. struct sccb *currSCCB;
  3107. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3108. if (currSCCB == NULL) {
  3109. return; /* Exit if No SCCB record */
  3110. }
  3111. currSCCB->Sccb_scsistat = DATA_OUT_ST;
  3112. currSCCB->Sccb_XferState &= ~(F_HOST_XFER_DIR | F_NO_DATA_YET);
  3113. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  3114. WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
  3115. WR_HARPOON(port + hp_autostart_0, (END_DATA + END_DATA_START));
  3116. FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
  3117. if (currSCCB->Sccb_XferCnt == 0) {
  3118. if ((currSCCB->ControlByte & SCCB_DATA_XFER_OUT) &&
  3119. (currSCCB->HostStatus == SCCB_COMPLETE))
  3120. currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
  3121. FPT_sxfrp(port, p_card);
  3122. if (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | RESET)))
  3123. FPT_phaseDecode(port, p_card);
  3124. }
  3125. }
  3126. /*---------------------------------------------------------------------
  3127. *
  3128. * Function: Data In Phase
  3129. *
  3130. * Description: Startup the BusMaster and the XBOW.
  3131. *
  3132. *---------------------------------------------------------------------*/
  3133. static void FPT_phaseDataIn(u32 port, unsigned char p_card)
  3134. {
  3135. struct sccb *currSCCB;
  3136. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3137. if (currSCCB == NULL) {
  3138. return; /* Exit if No SCCB record */
  3139. }
  3140. currSCCB->Sccb_scsistat = DATA_IN_ST;
  3141. currSCCB->Sccb_XferState |= F_HOST_XFER_DIR;
  3142. currSCCB->Sccb_XferState &= ~F_NO_DATA_YET;
  3143. WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
  3144. WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
  3145. WR_HARPOON(port + hp_autostart_0, (END_DATA + END_DATA_START));
  3146. FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
  3147. if (currSCCB->Sccb_XferCnt == 0) {
  3148. if ((currSCCB->ControlByte & SCCB_DATA_XFER_IN) &&
  3149. (currSCCB->HostStatus == SCCB_COMPLETE))
  3150. currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
  3151. FPT_sxfrp(port, p_card);
  3152. if (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | RESET)))
  3153. FPT_phaseDecode(port, p_card);
  3154. }
  3155. }
  3156. /*---------------------------------------------------------------------
  3157. *
  3158. * Function: Command Phase
  3159. *
  3160. * Description: Load the CDB into the automation and start it up.
  3161. *
  3162. *---------------------------------------------------------------------*/
  3163. static void FPT_phaseCommand(u32 p_port, unsigned char p_card)
  3164. {
  3165. struct sccb *currSCCB;
  3166. u32 cdb_reg;
  3167. unsigned char i;
  3168. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3169. if (currSCCB->OperationCode == RESET_COMMAND) {
  3170. currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
  3171. currSCCB->CdbLength = SIX_BYTE_CMD;
  3172. }
  3173. WR_HARPOON(p_port + hp_scsisig, 0x00);
  3174. ARAM_ACCESS(p_port);
  3175. cdb_reg = p_port + CMD_STRT;
  3176. for (i = 0; i < currSCCB->CdbLength; i++) {
  3177. if (currSCCB->OperationCode == RESET_COMMAND)
  3178. WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + 0x00));
  3179. else
  3180. WRW_HARPOON(cdb_reg,
  3181. (MPM_OP + ACOMMAND + currSCCB->Cdb[i]));
  3182. cdb_reg += 2;
  3183. }
  3184. if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
  3185. WRW_HARPOON(cdb_reg, (BRH_OP + ALWAYS + NP));
  3186. WR_HARPOON(p_port + hp_portctrl_0, (SCSI_PORT));
  3187. currSCCB->Sccb_scsistat = COMMAND_ST;
  3188. WR_HARPOON(p_port + hp_autostart_3, (AUTO_IMMED | CMD_ONLY_STRT));
  3189. SGRAM_ACCESS(p_port);
  3190. }
  3191. /*---------------------------------------------------------------------
  3192. *
  3193. * Function: Status phase
  3194. *
  3195. * Description: Bring in the status and command complete message bytes
  3196. *
  3197. *---------------------------------------------------------------------*/
  3198. static void FPT_phaseStatus(u32 port, unsigned char p_card)
  3199. {
  3200. /* Start-up the automation to finish off this command and let the
  3201. isr handle the interrupt for command complete when it comes in.
  3202. We could wait here for the interrupt to be generated?
  3203. */
  3204. WR_HARPOON(port + hp_scsisig, 0x00);
  3205. WR_HARPOON(port + hp_autostart_0, (AUTO_IMMED + END_DATA_START));
  3206. }
  3207. /*---------------------------------------------------------------------
  3208. *
  3209. * Function: Phase Message Out
  3210. *
  3211. * Description: Send out our message (if we have one) and handle whatever
  3212. * else is involed.
  3213. *
  3214. *---------------------------------------------------------------------*/
  3215. static void FPT_phaseMsgOut(u32 port, unsigned char p_card)
  3216. {
  3217. unsigned char message, scsiID;
  3218. struct sccb *currSCCB;
  3219. struct sccb_mgr_tar_info *currTar_Info;
  3220. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3221. if (currSCCB != NULL) {
  3222. message = currSCCB->Sccb_scsimsg;
  3223. scsiID = currSCCB->TargID;
  3224. if (message == TARGET_RESET) {
  3225. currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
  3226. currTar_Info->TarSyncCtrl = 0;
  3227. FPT_sssyncv(port, scsiID, NARROW_SCSI, currTar_Info);
  3228. if (FPT_sccbMgrTbl[p_card][scsiID].
  3229. TarEEValue & EE_SYNC_MASK) {
  3230. FPT_sccbMgrTbl[p_card][scsiID].TarStatus &=
  3231. ~TAR_SYNC_MASK;
  3232. }
  3233. if (FPT_sccbMgrTbl[p_card][scsiID].
  3234. TarEEValue & EE_WIDE_SCSI) {
  3235. FPT_sccbMgrTbl[p_card][scsiID].TarStatus &=
  3236. ~TAR_WIDE_MASK;
  3237. }
  3238. FPT_queueFlushSccb(p_card, SCCB_COMPLETE);
  3239. FPT_SccbMgrTableInitTarget(p_card, scsiID);
  3240. } else if (currSCCB->Sccb_scsistat == ABORT_ST) {
  3241. currSCCB->HostStatus = SCCB_COMPLETE;
  3242. if (FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] !=
  3243. NULL) {
  3244. FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
  3245. Sccb_tag] = NULL;
  3246. FPT_sccbMgrTbl[p_card][scsiID].TarTagQ_Cnt--;
  3247. }
  3248. }
  3249. else if (currSCCB->Sccb_scsistat < COMMAND_ST) {
  3250. if (message == NOP) {
  3251. currSCCB->Sccb_MGRFlags |= F_DEV_SELECTED;
  3252. FPT_ssel(port, p_card);
  3253. return;
  3254. }
  3255. } else {
  3256. if (message == ABORT_TASK_SET)
  3257. FPT_queueFlushSccb(p_card, SCCB_COMPLETE);
  3258. }
  3259. } else {
  3260. message = ABORT_TASK_SET;
  3261. }
  3262. WRW_HARPOON((port + hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0));
  3263. WR_HARPOON(port + hp_portctrl_0, SCSI_BUS_EN);
  3264. WR_HARPOON(port + hp_scsidata_0, message);
  3265. WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
  3266. ACCEPT_MSG(port);
  3267. WR_HARPOON(port + hp_portctrl_0, 0x00);
  3268. if ((message == ABORT_TASK_SET) || (message == TARGET_RESET) ||
  3269. (message == ABORT_TASK)) {
  3270. while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | PHASE))) {
  3271. }
  3272. if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
  3273. WRW_HARPOON((port + hp_intstat), BUS_FREE);
  3274. if (currSCCB != NULL) {
  3275. if ((FPT_BL_Card[p_card].
  3276. globalFlags & F_CONLUN_IO)
  3277. &&
  3278. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3279. TarStatus & TAR_TAG_Q_MASK) !=
  3280. TAG_Q_TRYING))
  3281. FPT_sccbMgrTbl[p_card][currSCCB->
  3282. TargID].
  3283. TarLUNBusy[currSCCB->Lun] = 0;
  3284. else
  3285. FPT_sccbMgrTbl[p_card][currSCCB->
  3286. TargID].
  3287. TarLUNBusy[0] = 0;
  3288. FPT_queueCmdComplete(&FPT_BL_Card[p_card],
  3289. currSCCB, p_card);
  3290. }
  3291. else {
  3292. FPT_BL_Card[p_card].globalFlags |=
  3293. F_NEW_SCCB_CMD;
  3294. }
  3295. }
  3296. else {
  3297. FPT_sxfrp(port, p_card);
  3298. }
  3299. }
  3300. else {
  3301. if (message == MSG_PARITY_ERROR) {
  3302. currSCCB->Sccb_scsimsg = NOP;
  3303. WR_HARPOON(port + hp_autostart_1,
  3304. (AUTO_IMMED + DISCONNECT_START));
  3305. } else {
  3306. FPT_sxfrp(port, p_card);
  3307. }
  3308. }
  3309. }
  3310. /*---------------------------------------------------------------------
  3311. *
  3312. * Function: Message In phase
  3313. *
  3314. * Description: Bring in the message and determine what to do with it.
  3315. *
  3316. *---------------------------------------------------------------------*/
  3317. static void FPT_phaseMsgIn(u32 port, unsigned char p_card)
  3318. {
  3319. unsigned char message;
  3320. struct sccb *currSCCB;
  3321. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3322. if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
  3323. FPT_phaseChkFifo(port, p_card);
  3324. }
  3325. message = RD_HARPOON(port + hp_scsidata_0);
  3326. if ((message == DISCONNECT) || (message == SAVE_POINTERS)) {
  3327. WR_HARPOON(port + hp_autostart_1,
  3328. (AUTO_IMMED + END_DATA_START));
  3329. }
  3330. else {
  3331. message = FPT_sfm(port, currSCCB);
  3332. if (message) {
  3333. FPT_sdecm(message, port, p_card);
  3334. } else {
  3335. if (currSCCB->Sccb_scsimsg != MSG_PARITY_ERROR)
  3336. ACCEPT_MSG(port);
  3337. WR_HARPOON(port + hp_autostart_1,
  3338. (AUTO_IMMED + DISCONNECT_START));
  3339. }
  3340. }
  3341. }
  3342. /*---------------------------------------------------------------------
  3343. *
  3344. * Function: Illegal phase
  3345. *
  3346. * Description: Target switched to some illegal phase, so all we can do
  3347. * is report an error back to the host (if that is possible)
  3348. * and send an ABORT message to the misbehaving target.
  3349. *
  3350. *---------------------------------------------------------------------*/
  3351. static void FPT_phaseIllegal(u32 port, unsigned char p_card)
  3352. {
  3353. struct sccb *currSCCB;
  3354. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3355. WR_HARPOON(port + hp_scsisig, RD_HARPOON(port + hp_scsisig));
  3356. if (currSCCB != NULL) {
  3357. currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
  3358. currSCCB->Sccb_scsistat = ABORT_ST;
  3359. currSCCB->Sccb_scsimsg = ABORT_TASK_SET;
  3360. }
  3361. ACCEPT_MSG_ATN(port);
  3362. }
  3363. /*---------------------------------------------------------------------
  3364. *
  3365. * Function: Phase Check FIFO
  3366. *
  3367. * Description: Make sure data has been flushed from both FIFOs and abort
  3368. * the operations if necessary.
  3369. *
  3370. *---------------------------------------------------------------------*/
  3371. static void FPT_phaseChkFifo(u32 port, unsigned char p_card)
  3372. {
  3373. u32 xfercnt;
  3374. struct sccb *currSCCB;
  3375. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3376. if (currSCCB->Sccb_scsistat == DATA_IN_ST) {
  3377. while ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) &&
  3378. (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)) {
  3379. }
  3380. if (!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) {
  3381. currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
  3382. currSCCB->Sccb_XferCnt = 0;
  3383. if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
  3384. (currSCCB->HostStatus == SCCB_COMPLETE)) {
  3385. currSCCB->HostStatus = SCCB_PARITY_ERR;
  3386. WRW_HARPOON((port + hp_intstat), PARITY);
  3387. }
  3388. FPT_hostDataXferAbort(port, p_card, currSCCB);
  3389. FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
  3390. while ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY))
  3391. && (RD_HARPOON(port + hp_ext_status) &
  3392. BM_CMD_BUSY)) {
  3393. }
  3394. }
  3395. }
  3396. /*End Data In specific code. */
  3397. GET_XFER_CNT(port, xfercnt);
  3398. WR_HARPOON(port + hp_xfercnt_0, 0x00);
  3399. WR_HARPOON(port + hp_portctrl_0, 0x00);
  3400. currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - xfercnt);
  3401. currSCCB->Sccb_XferCnt = xfercnt;
  3402. if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
  3403. (currSCCB->HostStatus == SCCB_COMPLETE)) {
  3404. currSCCB->HostStatus = SCCB_PARITY_ERR;
  3405. WRW_HARPOON((port + hp_intstat), PARITY);
  3406. }
  3407. FPT_hostDataXferAbort(port, p_card, currSCCB);
  3408. WR_HARPOON(port + hp_fifowrite, 0x00);
  3409. WR_HARPOON(port + hp_fiforead, 0x00);
  3410. WR_HARPOON(port + hp_xferstat, 0x00);
  3411. WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
  3412. }
  3413. /*---------------------------------------------------------------------
  3414. *
  3415. * Function: Phase Bus Free
  3416. *
  3417. * Description: We just went bus free so figure out if it was
  3418. * because of command complete or from a disconnect.
  3419. *
  3420. *---------------------------------------------------------------------*/
  3421. static void FPT_phaseBusFree(u32 port, unsigned char p_card)
  3422. {
  3423. struct sccb *currSCCB;
  3424. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3425. if (currSCCB != NULL) {
  3426. DISABLE_AUTO(port);
  3427. if (currSCCB->OperationCode == RESET_COMMAND) {
  3428. if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  3429. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3430. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
  3431. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3432. TarLUNBusy[currSCCB->Lun] = 0;
  3433. else
  3434. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3435. TarLUNBusy[0] = 0;
  3436. FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB,
  3437. p_card);
  3438. FPT_queueSearchSelect(&FPT_BL_Card[p_card], p_card);
  3439. }
  3440. else if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
  3441. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
  3442. (unsigned char)SYNC_SUPPORTED;
  3443. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
  3444. ~EE_SYNC_MASK;
  3445. }
  3446. else if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
  3447. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
  3448. (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3449. TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
  3450. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
  3451. ~EE_WIDE_SCSI;
  3452. }
  3453. else if (currSCCB->Sccb_scsistat == SELECT_Q_ST) {
  3454. /* Make sure this is not a phony BUS_FREE. If we were
  3455. reselected or if BUSY is NOT on then this is a
  3456. valid BUS FREE. SRR Wednesday, 5/10/1995. */
  3457. if ((!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ||
  3458. (RDW_HARPOON((port + hp_intstat)) & RSEL)) {
  3459. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3460. TarStatus &= ~TAR_TAG_Q_MASK;
  3461. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3462. TarStatus |= TAG_Q_REJECT;
  3463. }
  3464. else {
  3465. return;
  3466. }
  3467. }
  3468. else {
  3469. currSCCB->Sccb_scsistat = BUS_FREE_ST;
  3470. if (!currSCCB->HostStatus) {
  3471. currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
  3472. }
  3473. if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  3474. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3475. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
  3476. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3477. TarLUNBusy[currSCCB->Lun] = 0;
  3478. else
  3479. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3480. TarLUNBusy[0] = 0;
  3481. FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB,
  3482. p_card);
  3483. return;
  3484. }
  3485. FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
  3486. } /*end if !=null */
  3487. }
  3488. /*---------------------------------------------------------------------
  3489. *
  3490. * Function: Auto Load Default Map
  3491. *
  3492. * Description: Load the Automation RAM with the default map values.
  3493. *
  3494. *---------------------------------------------------------------------*/
  3495. static void FPT_autoLoadDefaultMap(u32 p_port)
  3496. {
  3497. u32 map_addr;
  3498. ARAM_ACCESS(p_port);
  3499. map_addr = p_port + hp_aramBase;
  3500. WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0xC0)); /*ID MESSAGE */
  3501. map_addr += 2;
  3502. WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0x20)); /*SIMPLE TAG QUEUEING MSG */
  3503. map_addr += 2;
  3504. WRW_HARPOON(map_addr, RAT_OP); /*RESET ATTENTION */
  3505. map_addr += 2;
  3506. WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0x00)); /*TAG ID MSG */
  3507. map_addr += 2;
  3508. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 0 */
  3509. map_addr += 2;
  3510. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 1 */
  3511. map_addr += 2;
  3512. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 2 */
  3513. map_addr += 2;
  3514. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 3 */
  3515. map_addr += 2;
  3516. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 4 */
  3517. map_addr += 2;
  3518. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 5 */
  3519. map_addr += 2;
  3520. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 6 */
  3521. map_addr += 2;
  3522. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 7 */
  3523. map_addr += 2;
  3524. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 8 */
  3525. map_addr += 2;
  3526. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 9 */
  3527. map_addr += 2;
  3528. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 10 */
  3529. map_addr += 2;
  3530. WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 11 */
  3531. map_addr += 2;
  3532. WRW_HARPOON(map_addr, (CPE_OP + ADATA_OUT + DINT)); /*JUMP IF DATA OUT */
  3533. map_addr += 2;
  3534. WRW_HARPOON(map_addr, (TCB_OP + FIFO_0 + DI)); /*JUMP IF NO DATA IN FIFO */
  3535. map_addr += 2; /*This means AYNC DATA IN */
  3536. WRW_HARPOON(map_addr, (SSI_OP + SSI_IDO_STRT)); /*STOP AND INTERRUPT */
  3537. map_addr += 2;
  3538. WRW_HARPOON(map_addr, (CPE_OP + ADATA_IN + DINT)); /*JUMP IF NOT DATA IN PHZ */
  3539. map_addr += 2;
  3540. WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + ST)); /*IF NOT MSG IN CHECK 4 DATA IN */
  3541. map_addr += 2;
  3542. WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x02)); /*SAVE DATA PTR MSG? */
  3543. map_addr += 2;
  3544. WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + DC)); /*GO CHECK FOR DISCONNECT MSG */
  3545. map_addr += 2;
  3546. WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_AR1)); /*SAVE DATA PTRS MSG */
  3547. map_addr += 2;
  3548. WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + ST)); /*IF NOT MSG IN CHECK DATA IN */
  3549. map_addr += 2;
  3550. WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x04)); /*DISCONNECT MSG? */
  3551. map_addr += 2;
  3552. WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + UNKNWN)); /*UKNKNOWN MSG */
  3553. map_addr += 2;
  3554. WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_BUCKET)); /*XFER DISCONNECT MSG */
  3555. map_addr += 2;
  3556. WRW_HARPOON(map_addr, (SSI_OP + SSI_ITAR_DISC)); /*STOP AND INTERRUPT */
  3557. map_addr += 2;
  3558. WRW_HARPOON(map_addr, (CPN_OP + ASTATUS + UNKNWN)); /*JUMP IF NOT STATUS PHZ. */
  3559. map_addr += 2;
  3560. WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_AR0)); /*GET STATUS BYTE */
  3561. map_addr += 2;
  3562. WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + CC)); /*ERROR IF NOT MSG IN PHZ */
  3563. map_addr += 2;
  3564. WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x00)); /*CHECK FOR CMD COMPLETE MSG. */
  3565. map_addr += 2;
  3566. WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + CC)); /*ERROR IF NOT CMD COMPLETE MSG. */
  3567. map_addr += 2;
  3568. WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_BUCKET)); /*GET CMD COMPLETE MSG */
  3569. map_addr += 2;
  3570. WRW_HARPOON(map_addr, (SSI_OP + SSI_ICMD_COMP)); /*END OF COMMAND */
  3571. map_addr += 2;
  3572. WRW_HARPOON(map_addr, (SSI_OP + SSI_IUNKWN)); /*RECEIVED UNKNOWN MSG BYTE */
  3573. map_addr += 2;
  3574. WRW_HARPOON(map_addr, (SSI_OP + SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
  3575. map_addr += 2;
  3576. WRW_HARPOON(map_addr, (SSI_OP + SSI_ITICKLE)); /*BIOS Tickled the Mgr */
  3577. map_addr += 2;
  3578. WRW_HARPOON(map_addr, (SSI_OP + SSI_IRFAIL)); /*EXPECTED ID/TAG MESSAGES AND */
  3579. map_addr += 2; /* DIDN'T GET ONE */
  3580. WRW_HARPOON(map_addr, (CRR_OP + AR3 + S_IDREG)); /* comp SCSI SEL ID & AR3 */
  3581. map_addr += 2;
  3582. WRW_HARPOON(map_addr, (BRH_OP + EQUAL + 0x00)); /*SEL ID OK then Conti. */
  3583. map_addr += 2;
  3584. WRW_HARPOON(map_addr, (SSI_OP + SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
  3585. SGRAM_ACCESS(p_port);
  3586. }
  3587. /*---------------------------------------------------------------------
  3588. *
  3589. * Function: Auto Command Complete
  3590. *
  3591. * Description: Post command back to host and find another command
  3592. * to execute.
  3593. *
  3594. *---------------------------------------------------------------------*/
  3595. static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card)
  3596. {
  3597. struct sccb *currSCCB;
  3598. unsigned char status_byte;
  3599. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  3600. status_byte = RD_HARPOON(p_port + hp_gp_reg_0);
  3601. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = 0;
  3602. if (status_byte != SAM_STAT_GOOD) {
  3603. if (status_byte == SAM_STAT_TASK_SET_FULL) {
  3604. if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  3605. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3606. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
  3607. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3608. TarLUNBusy[currSCCB->Lun] = 1;
  3609. if (FPT_BL_Card[p_card].discQCount != 0)
  3610. FPT_BL_Card[p_card].discQCount--;
  3611. FPT_BL_Card[p_card].
  3612. discQ_Tbl[FPT_sccbMgrTbl[p_card]
  3613. [currSCCB->TargID].
  3614. LunDiscQ_Idx[currSCCB->Lun]] =
  3615. NULL;
  3616. } else {
  3617. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3618. TarLUNBusy[0] = 1;
  3619. if (currSCCB->Sccb_tag) {
  3620. if (FPT_BL_Card[p_card].discQCount != 0)
  3621. FPT_BL_Card[p_card].
  3622. discQCount--;
  3623. FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
  3624. Sccb_tag]
  3625. = NULL;
  3626. } else {
  3627. if (FPT_BL_Card[p_card].discQCount != 0)
  3628. FPT_BL_Card[p_card].
  3629. discQCount--;
  3630. FPT_BL_Card[p_card].
  3631. discQ_Tbl[FPT_sccbMgrTbl[p_card]
  3632. [currSCCB->TargID].
  3633. LunDiscQ_Idx[0]] = NULL;
  3634. }
  3635. }
  3636. currSCCB->Sccb_MGRFlags |= F_STATUSLOADED;
  3637. FPT_queueSelectFail(&FPT_BL_Card[p_card], p_card);
  3638. return;
  3639. }
  3640. if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
  3641. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
  3642. (unsigned char)SYNC_SUPPORTED;
  3643. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
  3644. ~EE_SYNC_MASK;
  3645. FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
  3646. if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  3647. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3648. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
  3649. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3650. TarLUNBusy[currSCCB->Lun] = 1;
  3651. if (FPT_BL_Card[p_card].discQCount != 0)
  3652. FPT_BL_Card[p_card].discQCount--;
  3653. FPT_BL_Card[p_card].
  3654. discQ_Tbl[FPT_sccbMgrTbl[p_card]
  3655. [currSCCB->TargID].
  3656. LunDiscQ_Idx[currSCCB->Lun]] =
  3657. NULL;
  3658. } else {
  3659. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3660. TarLUNBusy[0] = 1;
  3661. if (currSCCB->Sccb_tag) {
  3662. if (FPT_BL_Card[p_card].discQCount != 0)
  3663. FPT_BL_Card[p_card].
  3664. discQCount--;
  3665. FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
  3666. Sccb_tag]
  3667. = NULL;
  3668. } else {
  3669. if (FPT_BL_Card[p_card].discQCount != 0)
  3670. FPT_BL_Card[p_card].
  3671. discQCount--;
  3672. FPT_BL_Card[p_card].
  3673. discQ_Tbl[FPT_sccbMgrTbl[p_card]
  3674. [currSCCB->TargID].
  3675. LunDiscQ_Idx[0]] = NULL;
  3676. }
  3677. }
  3678. return;
  3679. }
  3680. if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
  3681. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
  3682. (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3683. TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
  3684. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
  3685. ~EE_WIDE_SCSI;
  3686. FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
  3687. if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  3688. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3689. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
  3690. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3691. TarLUNBusy[currSCCB->Lun] = 1;
  3692. if (FPT_BL_Card[p_card].discQCount != 0)
  3693. FPT_BL_Card[p_card].discQCount--;
  3694. FPT_BL_Card[p_card].
  3695. discQ_Tbl[FPT_sccbMgrTbl[p_card]
  3696. [currSCCB->TargID].
  3697. LunDiscQ_Idx[currSCCB->Lun]] =
  3698. NULL;
  3699. } else {
  3700. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3701. TarLUNBusy[0] = 1;
  3702. if (currSCCB->Sccb_tag) {
  3703. if (FPT_BL_Card[p_card].discQCount != 0)
  3704. FPT_BL_Card[p_card].
  3705. discQCount--;
  3706. FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
  3707. Sccb_tag]
  3708. = NULL;
  3709. } else {
  3710. if (FPT_BL_Card[p_card].discQCount != 0)
  3711. FPT_BL_Card[p_card].
  3712. discQCount--;
  3713. FPT_BL_Card[p_card].
  3714. discQ_Tbl[FPT_sccbMgrTbl[p_card]
  3715. [currSCCB->TargID].
  3716. LunDiscQ_Idx[0]] = NULL;
  3717. }
  3718. }
  3719. return;
  3720. }
  3721. if (status_byte == SAM_STAT_CHECK_CONDITION) {
  3722. if (FPT_BL_Card[p_card].globalFlags & F_DO_RENEGO) {
  3723. if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3724. TarEEValue & EE_SYNC_MASK) {
  3725. FPT_sccbMgrTbl[p_card][currSCCB->
  3726. TargID].
  3727. TarStatus &= ~TAR_SYNC_MASK;
  3728. }
  3729. if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3730. TarEEValue & EE_WIDE_SCSI) {
  3731. FPT_sccbMgrTbl[p_card][currSCCB->
  3732. TargID].
  3733. TarStatus &= ~TAR_WIDE_MASK;
  3734. }
  3735. }
  3736. }
  3737. if (!(currSCCB->Sccb_XferState & F_AUTO_SENSE)) {
  3738. currSCCB->SccbStatus = SCCB_ERROR;
  3739. currSCCB->TargetStatus = status_byte;
  3740. if (status_byte == SAM_STAT_CHECK_CONDITION) {
  3741. FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3742. TarLUN_CA = 1;
  3743. if (currSCCB->RequestSenseLength !=
  3744. NO_AUTO_REQUEST_SENSE) {
  3745. if (currSCCB->RequestSenseLength == 0)
  3746. currSCCB->RequestSenseLength =
  3747. 14;
  3748. FPT_ssenss(&FPT_BL_Card[p_card]);
  3749. FPT_BL_Card[p_card].globalFlags |=
  3750. F_NEW_SCCB_CMD;
  3751. if (((FPT_BL_Card[p_card].
  3752. globalFlags & F_CONLUN_IO)
  3753. &&
  3754. ((FPT_sccbMgrTbl[p_card]
  3755. [currSCCB->TargID].
  3756. TarStatus & TAR_TAG_Q_MASK) !=
  3757. TAG_Q_TRYING))) {
  3758. FPT_sccbMgrTbl[p_card]
  3759. [currSCCB->TargID].
  3760. TarLUNBusy[currSCCB->Lun] =
  3761. 1;
  3762. if (FPT_BL_Card[p_card].
  3763. discQCount != 0)
  3764. FPT_BL_Card[p_card].
  3765. discQCount--;
  3766. FPT_BL_Card[p_card].
  3767. discQ_Tbl[FPT_sccbMgrTbl
  3768. [p_card]
  3769. [currSCCB->
  3770. TargID].
  3771. LunDiscQ_Idx
  3772. [currSCCB->Lun]] =
  3773. NULL;
  3774. } else {
  3775. FPT_sccbMgrTbl[p_card]
  3776. [currSCCB->TargID].
  3777. TarLUNBusy[0] = 1;
  3778. if (currSCCB->Sccb_tag) {
  3779. if (FPT_BL_Card[p_card].
  3780. discQCount != 0)
  3781. FPT_BL_Card
  3782. [p_card].
  3783. discQCount--;
  3784. FPT_BL_Card[p_card].
  3785. discQ_Tbl[currSCCB->
  3786. Sccb_tag]
  3787. = NULL;
  3788. } else {
  3789. if (FPT_BL_Card[p_card].
  3790. discQCount != 0)
  3791. FPT_BL_Card
  3792. [p_card].
  3793. discQCount--;
  3794. FPT_BL_Card[p_card].
  3795. discQ_Tbl
  3796. [FPT_sccbMgrTbl
  3797. [p_card][currSCCB->
  3798. TargID].
  3799. LunDiscQ_Idx[0]] =
  3800. NULL;
  3801. }
  3802. }
  3803. return;
  3804. }
  3805. }
  3806. }
  3807. }
  3808. if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  3809. ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
  3810. TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
  3811. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->
  3812. Lun] = 0;
  3813. else
  3814. FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
  3815. FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB, p_card);
  3816. }
  3817. #define SHORT_WAIT 0x0000000F
  3818. #define LONG_WAIT 0x0000FFFFL
  3819. /*---------------------------------------------------------------------
  3820. *
  3821. * Function: Data Transfer Processor
  3822. *
  3823. * Description: This routine performs two tasks.
  3824. * (1) Start data transfer by calling HOST_DATA_XFER_START
  3825. * function. Once data transfer is started, (2) Depends
  3826. * on the type of data transfer mode Scatter/Gather mode
  3827. * or NON Scatter/Gather mode. In NON Scatter/Gather mode,
  3828. * this routine checks Sccb_MGRFlag (F_HOST_XFER_ACT bit) for
  3829. * data transfer done. In Scatter/Gather mode, this routine
  3830. * checks bus master command complete and dual rank busy
  3831. * bit to keep chaining SC transfer command. Similarly,
  3832. * in Scatter/Gather mode, it checks Sccb_MGRFlag
  3833. * (F_HOST_XFER_ACT bit) for data transfer done.
  3834. *
  3835. *---------------------------------------------------------------------*/
  3836. static void FPT_dataXferProcessor(u32 port, struct sccb_card *pCurrCard)
  3837. {
  3838. struct sccb *currSCCB;
  3839. currSCCB = pCurrCard->currentSCCB;
  3840. if (currSCCB->Sccb_XferState & F_SG_XFER) {
  3841. if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
  3842. {
  3843. currSCCB->Sccb_sgseg += (unsigned char)SG_BUF_CNT;
  3844. currSCCB->Sccb_SGoffset = 0x00;
  3845. }
  3846. pCurrCard->globalFlags |= F_HOST_XFER_ACT;
  3847. FPT_busMstrSGDataXferStart(port, currSCCB);
  3848. }
  3849. else {
  3850. if (!(pCurrCard->globalFlags & F_HOST_XFER_ACT)) {
  3851. pCurrCard->globalFlags |= F_HOST_XFER_ACT;
  3852. FPT_busMstrDataXferStart(port, currSCCB);
  3853. }
  3854. }
  3855. }
  3856. /*---------------------------------------------------------------------
  3857. *
  3858. * Function: BusMaster Scatter Gather Data Transfer Start
  3859. *
  3860. * Description:
  3861. *
  3862. *---------------------------------------------------------------------*/
  3863. static void FPT_busMstrSGDataXferStart(u32 p_port, struct sccb *pcurrSCCB)
  3864. {
  3865. u32 count, addr, tmpSGCnt;
  3866. unsigned int sg_index;
  3867. unsigned char sg_count, i;
  3868. u32 reg_offset;
  3869. struct blogic_sg_seg *segp;
  3870. if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)
  3871. count = ((u32)HOST_RD_CMD) << 24;
  3872. else
  3873. count = ((u32)HOST_WRT_CMD) << 24;
  3874. sg_count = 0;
  3875. tmpSGCnt = 0;
  3876. sg_index = pcurrSCCB->Sccb_sgseg;
  3877. reg_offset = hp_aramBase;
  3878. i = (unsigned char)(RD_HARPOON(p_port + hp_page_ctrl) &
  3879. ~(SGRAM_ARAM | SCATTER_EN));
  3880. WR_HARPOON(p_port + hp_page_ctrl, i);
  3881. while ((sg_count < (unsigned char)SG_BUF_CNT) &&
  3882. ((sg_index * (unsigned int)SG_ELEMENT_SIZE) <
  3883. pcurrSCCB->DataLength)) {
  3884. segp = (struct blogic_sg_seg *)(pcurrSCCB->DataPointer) +
  3885. sg_index;
  3886. tmpSGCnt += segp->segbytes;
  3887. count |= segp->segbytes;
  3888. addr = segp->segdata;
  3889. if ((!sg_count) && (pcurrSCCB->Sccb_SGoffset)) {
  3890. addr +=
  3891. ((count & 0x00FFFFFFL) - pcurrSCCB->Sccb_SGoffset);
  3892. count =
  3893. (count & 0xFF000000L) | pcurrSCCB->Sccb_SGoffset;
  3894. tmpSGCnt = count & 0x00FFFFFFL;
  3895. }
  3896. WR_HARP32(p_port, reg_offset, addr);
  3897. reg_offset += 4;
  3898. WR_HARP32(p_port, reg_offset, count);
  3899. reg_offset += 4;
  3900. count &= 0xFF000000L;
  3901. sg_index++;
  3902. sg_count++;
  3903. } /*End While */
  3904. pcurrSCCB->Sccb_XferCnt = tmpSGCnt;
  3905. WR_HARPOON(p_port + hp_sg_addr, (sg_count << 4));
  3906. if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
  3907. WR_HARP32(p_port, hp_xfercnt_0, tmpSGCnt);
  3908. WR_HARPOON(p_port + hp_portctrl_0,
  3909. (DMA_PORT | SCSI_PORT | SCSI_INBIT));
  3910. WR_HARPOON(p_port + hp_scsisig, S_DATAI_PH);
  3911. }
  3912. else {
  3913. if ((!(RD_HARPOON(p_port + hp_synctarg_0) & NARROW_SCSI)) &&
  3914. (tmpSGCnt & 0x000000001)) {
  3915. pcurrSCCB->Sccb_XferState |= F_ODD_BALL_CNT;
  3916. tmpSGCnt--;
  3917. }
  3918. WR_HARP32(p_port, hp_xfercnt_0, tmpSGCnt);
  3919. WR_HARPOON(p_port + hp_portctrl_0,
  3920. (SCSI_PORT | DMA_PORT | DMA_RD));
  3921. WR_HARPOON(p_port + hp_scsisig, S_DATAO_PH);
  3922. }
  3923. WR_HARPOON(p_port + hp_page_ctrl, (unsigned char)(i | SCATTER_EN));
  3924. }
  3925. /*---------------------------------------------------------------------
  3926. *
  3927. * Function: BusMaster Data Transfer Start
  3928. *
  3929. * Description:
  3930. *
  3931. *---------------------------------------------------------------------*/
  3932. static void FPT_busMstrDataXferStart(u32 p_port, struct sccb *pcurrSCCB)
  3933. {
  3934. u32 addr, count;
  3935. if (!(pcurrSCCB->Sccb_XferState & F_AUTO_SENSE)) {
  3936. count = pcurrSCCB->Sccb_XferCnt;
  3937. addr = (u32)(unsigned long)pcurrSCCB->DataPointer + pcurrSCCB->Sccb_ATC;
  3938. }
  3939. else {
  3940. addr = pcurrSCCB->SensePointer;
  3941. count = pcurrSCCB->RequestSenseLength;
  3942. }
  3943. HP_SETUP_ADDR_CNT(p_port, addr, count);
  3944. if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
  3945. WR_HARPOON(p_port + hp_portctrl_0,
  3946. (DMA_PORT | SCSI_PORT | SCSI_INBIT));
  3947. WR_HARPOON(p_port + hp_scsisig, S_DATAI_PH);
  3948. WR_HARPOON(p_port + hp_xfer_cmd,
  3949. (XFER_DMA_HOST | XFER_HOST_AUTO | XFER_DMA_8BIT));
  3950. }
  3951. else {
  3952. WR_HARPOON(p_port + hp_portctrl_0,
  3953. (SCSI_PORT | DMA_PORT | DMA_RD));
  3954. WR_HARPOON(p_port + hp_scsisig, S_DATAO_PH);
  3955. WR_HARPOON(p_port + hp_xfer_cmd,
  3956. (XFER_HOST_DMA | XFER_HOST_AUTO | XFER_DMA_8BIT));
  3957. }
  3958. }
  3959. /*---------------------------------------------------------------------
  3960. *
  3961. * Function: BusMaster Timeout Handler
  3962. *
  3963. * Description: This function is called after a bus master command busy time
  3964. * out is detected. This routines issue halt state machine
  3965. * with a software time out for command busy. If command busy
  3966. * is still asserted at the end of the time out, it issues
  3967. * hard abort with another software time out. It hard abort
  3968. * command busy is also time out, it'll just give up.
  3969. *
  3970. *---------------------------------------------------------------------*/
  3971. static unsigned char FPT_busMstrTimeOut(u32 p_port)
  3972. {
  3973. unsigned long timeout;
  3974. timeout = LONG_WAIT;
  3975. WR_HARPOON(p_port + hp_sys_ctrl, HALT_MACH);
  3976. while ((!(RD_HARPOON(p_port + hp_ext_status) & CMD_ABORTED))
  3977. && timeout--) {
  3978. }
  3979. if (RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY) {
  3980. WR_HARPOON(p_port + hp_sys_ctrl, HARD_ABORT);
  3981. timeout = LONG_WAIT;
  3982. while ((RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY)
  3983. && timeout--) {
  3984. }
  3985. }
  3986. RD_HARPOON(p_port + hp_int_status); /*Clear command complete */
  3987. if (RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY) {
  3988. return 1;
  3989. }
  3990. else {
  3991. return 0;
  3992. }
  3993. }
  3994. /*---------------------------------------------------------------------
  3995. *
  3996. * Function: Host Data Transfer Abort
  3997. *
  3998. * Description: Abort any in progress transfer.
  3999. *
  4000. *---------------------------------------------------------------------*/
  4001. static void FPT_hostDataXferAbort(u32 port, unsigned char p_card,
  4002. struct sccb *pCurrSCCB)
  4003. {
  4004. unsigned long timeout;
  4005. unsigned long remain_cnt;
  4006. u32 sg_ptr;
  4007. struct blogic_sg_seg *segp;
  4008. FPT_BL_Card[p_card].globalFlags &= ~F_HOST_XFER_ACT;
  4009. if (pCurrSCCB->Sccb_XferState & F_AUTO_SENSE) {
  4010. if (!(RD_HARPOON(port + hp_int_status) & INT_CMD_COMPL)) {
  4011. WR_HARPOON(port + hp_bm_ctrl,
  4012. (RD_HARPOON(port + hp_bm_ctrl) |
  4013. FLUSH_XFER_CNTR));
  4014. timeout = LONG_WAIT;
  4015. while ((RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)
  4016. && timeout--) {
  4017. }
  4018. WR_HARPOON(port + hp_bm_ctrl,
  4019. (RD_HARPOON(port + hp_bm_ctrl) &
  4020. ~FLUSH_XFER_CNTR));
  4021. if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
  4022. if (FPT_busMstrTimeOut(port)) {
  4023. if (pCurrSCCB->HostStatus == 0x00)
  4024. pCurrSCCB->HostStatus =
  4025. SCCB_BM_ERR;
  4026. }
  4027. if (RD_HARPOON(port + hp_int_status) &
  4028. INT_EXT_STATUS)
  4029. if (RD_HARPOON(port + hp_ext_status) &
  4030. BAD_EXT_STATUS)
  4031. if (pCurrSCCB->HostStatus ==
  4032. 0x00)
  4033. {
  4034. pCurrSCCB->HostStatus =
  4035. SCCB_BM_ERR;
  4036. }
  4037. }
  4038. }
  4039. }
  4040. else if (pCurrSCCB->Sccb_XferCnt) {
  4041. if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
  4042. WR_HARPOON(port + hp_page_ctrl,
  4043. (RD_HARPOON(port + hp_page_ctrl) &
  4044. ~SCATTER_EN));
  4045. WR_HARPOON(port + hp_sg_addr, 0x00);
  4046. sg_ptr = pCurrSCCB->Sccb_sgseg + SG_BUF_CNT;
  4047. if (sg_ptr >
  4048. (unsigned int)(pCurrSCCB->DataLength /
  4049. SG_ELEMENT_SIZE)) {
  4050. sg_ptr = (u32)(pCurrSCCB->DataLength /
  4051. SG_ELEMENT_SIZE);
  4052. }
  4053. remain_cnt = pCurrSCCB->Sccb_XferCnt;
  4054. while (remain_cnt < 0x01000000L) {
  4055. sg_ptr--;
  4056. segp = (struct blogic_sg_seg *)(pCurrSCCB->
  4057. DataPointer) + (sg_ptr * 2);
  4058. if (remain_cnt > (unsigned long)segp->segbytes)
  4059. remain_cnt -=
  4060. (unsigned long)segp->segbytes;
  4061. else
  4062. break;
  4063. }
  4064. if (remain_cnt < 0x01000000L) {
  4065. pCurrSCCB->Sccb_SGoffset = remain_cnt;
  4066. pCurrSCCB->Sccb_sgseg = (unsigned short)sg_ptr;
  4067. if ((unsigned long)(sg_ptr * SG_ELEMENT_SIZE) ==
  4068. pCurrSCCB->DataLength && (remain_cnt == 0))
  4069. pCurrSCCB->Sccb_XferState |=
  4070. F_ALL_XFERRED;
  4071. }
  4072. else {
  4073. if (pCurrSCCB->HostStatus == 0x00) {
  4074. pCurrSCCB->HostStatus =
  4075. SCCB_GROSS_FW_ERR;
  4076. }
  4077. }
  4078. }
  4079. if (!(pCurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)) {
  4080. if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
  4081. FPT_busMstrTimeOut(port);
  4082. }
  4083. else {
  4084. if (RD_HARPOON(port + hp_int_status) &
  4085. INT_EXT_STATUS) {
  4086. if (RD_HARPOON(port + hp_ext_status) &
  4087. BAD_EXT_STATUS) {
  4088. if (pCurrSCCB->HostStatus ==
  4089. 0x00) {
  4090. pCurrSCCB->HostStatus =
  4091. SCCB_BM_ERR;
  4092. }
  4093. }
  4094. }
  4095. }
  4096. }
  4097. else {
  4098. if ((RD_HARPOON(port + hp_fifo_cnt)) >= BM_THRESHOLD) {
  4099. timeout = SHORT_WAIT;
  4100. while ((RD_HARPOON(port + hp_ext_status) &
  4101. BM_CMD_BUSY)
  4102. && ((RD_HARPOON(port + hp_fifo_cnt)) >=
  4103. BM_THRESHOLD) && timeout--) {
  4104. }
  4105. }
  4106. if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
  4107. WR_HARPOON(port + hp_bm_ctrl,
  4108. (RD_HARPOON(port + hp_bm_ctrl) |
  4109. FLUSH_XFER_CNTR));
  4110. timeout = LONG_WAIT;
  4111. while ((RD_HARPOON(port + hp_ext_status) &
  4112. BM_CMD_BUSY) && timeout--) {
  4113. }
  4114. WR_HARPOON(port + hp_bm_ctrl,
  4115. (RD_HARPOON(port + hp_bm_ctrl) &
  4116. ~FLUSH_XFER_CNTR));
  4117. if (RD_HARPOON(port + hp_ext_status) &
  4118. BM_CMD_BUSY) {
  4119. if (pCurrSCCB->HostStatus == 0x00) {
  4120. pCurrSCCB->HostStatus =
  4121. SCCB_BM_ERR;
  4122. }
  4123. FPT_busMstrTimeOut(port);
  4124. }
  4125. }
  4126. if (RD_HARPOON(port + hp_int_status) & INT_EXT_STATUS) {
  4127. if (RD_HARPOON(port + hp_ext_status) &
  4128. BAD_EXT_STATUS) {
  4129. if (pCurrSCCB->HostStatus == 0x00) {
  4130. pCurrSCCB->HostStatus =
  4131. SCCB_BM_ERR;
  4132. }
  4133. }
  4134. }
  4135. }
  4136. }
  4137. else {
  4138. if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
  4139. timeout = LONG_WAIT;
  4140. while ((RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)
  4141. && timeout--) {
  4142. }
  4143. if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
  4144. if (pCurrSCCB->HostStatus == 0x00) {
  4145. pCurrSCCB->HostStatus = SCCB_BM_ERR;
  4146. }
  4147. FPT_busMstrTimeOut(port);
  4148. }
  4149. }
  4150. if (RD_HARPOON(port + hp_int_status) & INT_EXT_STATUS) {
  4151. if (RD_HARPOON(port + hp_ext_status) & BAD_EXT_STATUS) {
  4152. if (pCurrSCCB->HostStatus == 0x00) {
  4153. pCurrSCCB->HostStatus = SCCB_BM_ERR;
  4154. }
  4155. }
  4156. }
  4157. if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
  4158. WR_HARPOON(port + hp_page_ctrl,
  4159. (RD_HARPOON(port + hp_page_ctrl) &
  4160. ~SCATTER_EN));
  4161. WR_HARPOON(port + hp_sg_addr, 0x00);
  4162. pCurrSCCB->Sccb_sgseg += SG_BUF_CNT;
  4163. pCurrSCCB->Sccb_SGoffset = 0x00;
  4164. if ((u32)(pCurrSCCB->Sccb_sgseg * SG_ELEMENT_SIZE) >=
  4165. pCurrSCCB->DataLength) {
  4166. pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
  4167. pCurrSCCB->Sccb_sgseg =
  4168. (unsigned short)(pCurrSCCB->DataLength /
  4169. SG_ELEMENT_SIZE);
  4170. }
  4171. }
  4172. else {
  4173. if (!(pCurrSCCB->Sccb_XferState & F_AUTO_SENSE))
  4174. pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
  4175. }
  4176. }
  4177. WR_HARPOON(port + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
  4178. }
  4179. /*---------------------------------------------------------------------
  4180. *
  4181. * Function: Host Data Transfer Restart
  4182. *
  4183. * Description: Reset the available count due to a restore data
  4184. * pointers message.
  4185. *
  4186. *---------------------------------------------------------------------*/
  4187. static void FPT_hostDataXferRestart(struct sccb *currSCCB)
  4188. {
  4189. unsigned long data_count;
  4190. unsigned int sg_index;
  4191. struct blogic_sg_seg *segp;
  4192. if (currSCCB->Sccb_XferState & F_SG_XFER) {
  4193. currSCCB->Sccb_XferCnt = 0;
  4194. sg_index = 0xffff; /*Index by long words into sg list. */
  4195. data_count = 0; /*Running count of SG xfer counts. */
  4196. while (data_count < currSCCB->Sccb_ATC) {
  4197. sg_index++;
  4198. segp = (struct blogic_sg_seg *)(currSCCB->DataPointer) +
  4199. (sg_index * 2);
  4200. data_count += segp->segbytes;
  4201. }
  4202. if (data_count == currSCCB->Sccb_ATC) {
  4203. currSCCB->Sccb_SGoffset = 0;
  4204. sg_index++;
  4205. }
  4206. else {
  4207. currSCCB->Sccb_SGoffset =
  4208. data_count - currSCCB->Sccb_ATC;
  4209. }
  4210. currSCCB->Sccb_sgseg = (unsigned short)sg_index;
  4211. }
  4212. else {
  4213. currSCCB->Sccb_XferCnt =
  4214. currSCCB->DataLength - currSCCB->Sccb_ATC;
  4215. }
  4216. }
  4217. /*---------------------------------------------------------------------
  4218. *
  4219. * Function: FPT_scini
  4220. *
  4221. * Description: Setup all data structures necessary for SCAM selection.
  4222. *
  4223. *---------------------------------------------------------------------*/
  4224. static void FPT_scini(unsigned char p_card, unsigned char p_our_id,
  4225. unsigned char p_power_up)
  4226. {
  4227. unsigned char loser, assigned_id;
  4228. u32 p_port;
  4229. unsigned char i, k, ScamFlg;
  4230. struct sccb_card *currCard;
  4231. struct nvram_info *pCurrNvRam;
  4232. currCard = &FPT_BL_Card[p_card];
  4233. p_port = currCard->ioPort;
  4234. pCurrNvRam = currCard->pNvRamInfo;
  4235. if (pCurrNvRam) {
  4236. ScamFlg = pCurrNvRam->niScamConf;
  4237. i = pCurrNvRam->niSysConf;
  4238. } else {
  4239. ScamFlg =
  4240. (unsigned char)FPT_utilEERead(p_port, SCAM_CONFIG / 2);
  4241. i = (unsigned
  4242. char)(FPT_utilEERead(p_port, (SYSTEM_CONFIG / 2)));
  4243. }
  4244. if (!(i & 0x02)) /* check if reset bus in AutoSCSI parameter set */
  4245. return;
  4246. FPT_inisci(p_card, p_port, p_our_id);
  4247. /* Force to wait 1 sec after SCSI bus reset. Some SCAM device FW
  4248. too slow to return to SCAM selection */
  4249. /* if (p_power_up)
  4250. FPT_Wait1Second(p_port);
  4251. else
  4252. FPT_Wait(p_port, TO_250ms); */
  4253. FPT_Wait1Second(p_port);
  4254. if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2)) {
  4255. while (!(FPT_scarb(p_port, INIT_SELTD))) {
  4256. }
  4257. FPT_scsel(p_port);
  4258. do {
  4259. FPT_scxferc(p_port, SYNC_PTRN);
  4260. FPT_scxferc(p_port, DOM_MSTR);
  4261. loser =
  4262. FPT_scsendi(p_port,
  4263. &FPT_scamInfo[p_our_id].id_string[0]);
  4264. } while (loser == 0xFF);
  4265. FPT_scbusf(p_port);
  4266. if ((p_power_up) && (!loser)) {
  4267. FPT_sresb(p_port, p_card);
  4268. FPT_Wait(p_port, TO_250ms);
  4269. while (!(FPT_scarb(p_port, INIT_SELTD))) {
  4270. }
  4271. FPT_scsel(p_port);
  4272. do {
  4273. FPT_scxferc(p_port, SYNC_PTRN);
  4274. FPT_scxferc(p_port, DOM_MSTR);
  4275. loser =
  4276. FPT_scsendi(p_port,
  4277. &FPT_scamInfo[p_our_id].
  4278. id_string[0]);
  4279. } while (loser == 0xFF);
  4280. FPT_scbusf(p_port);
  4281. }
  4282. }
  4283. else {
  4284. loser = 0;
  4285. }
  4286. if (!loser) {
  4287. FPT_scamInfo[p_our_id].state = ID_ASSIGNED;
  4288. if (ScamFlg & SCAM_ENABLED) {
  4289. for (i = 0; i < MAX_SCSI_TAR; i++) {
  4290. if ((FPT_scamInfo[i].state == ID_UNASSIGNED) ||
  4291. (FPT_scamInfo[i].state == ID_UNUSED)) {
  4292. if (FPT_scsell(p_port, i)) {
  4293. FPT_scamInfo[i].state = LEGACY;
  4294. if ((FPT_scamInfo[i].
  4295. id_string[0] != 0xFF)
  4296. || (FPT_scamInfo[i].
  4297. id_string[1] != 0xFA)) {
  4298. FPT_scamInfo[i].
  4299. id_string[0] = 0xFF;
  4300. FPT_scamInfo[i].
  4301. id_string[1] = 0xFA;
  4302. if (pCurrNvRam == NULL)
  4303. currCard->
  4304. globalFlags
  4305. |=
  4306. F_UPDATE_EEPROM;
  4307. }
  4308. }
  4309. }
  4310. }
  4311. FPT_sresb(p_port, p_card);
  4312. FPT_Wait1Second(p_port);
  4313. while (!(FPT_scarb(p_port, INIT_SELTD))) {
  4314. }
  4315. FPT_scsel(p_port);
  4316. FPT_scasid(p_card, p_port);
  4317. }
  4318. }
  4319. else if ((loser) && (ScamFlg & SCAM_ENABLED)) {
  4320. FPT_scamInfo[p_our_id].id_string[0] = SLV_TYPE_CODE0;
  4321. assigned_id = 0;
  4322. FPT_scwtsel(p_port);
  4323. do {
  4324. while (FPT_scxferc(p_port, 0x00) != SYNC_PTRN) {
  4325. }
  4326. i = FPT_scxferc(p_port, 0x00);
  4327. if (i == ASSIGN_ID) {
  4328. if (!
  4329. (FPT_scsendi
  4330. (p_port,
  4331. &FPT_scamInfo[p_our_id].id_string[0]))) {
  4332. i = FPT_scxferc(p_port, 0x00);
  4333. if (FPT_scvalq(i)) {
  4334. k = FPT_scxferc(p_port, 0x00);
  4335. if (FPT_scvalq(k)) {
  4336. currCard->ourId =
  4337. ((unsigned char)(i
  4338. <<
  4339. 3)
  4340. +
  4341. (k &
  4342. (unsigned char)7))
  4343. & (unsigned char)
  4344. 0x3F;
  4345. FPT_inisci(p_card,
  4346. p_port,
  4347. p_our_id);
  4348. FPT_scamInfo[currCard->
  4349. ourId].
  4350. state = ID_ASSIGNED;
  4351. FPT_scamInfo[currCard->
  4352. ourId].
  4353. id_string[0]
  4354. = SLV_TYPE_CODE0;
  4355. assigned_id = 1;
  4356. }
  4357. }
  4358. }
  4359. }
  4360. else if (i == SET_P_FLAG) {
  4361. if (!(FPT_scsendi(p_port,
  4362. &FPT_scamInfo[p_our_id].
  4363. id_string[0])))
  4364. FPT_scamInfo[p_our_id].id_string[0] |=
  4365. 0x80;
  4366. }
  4367. } while (!assigned_id);
  4368. while (FPT_scxferc(p_port, 0x00) != CFG_CMPLT) {
  4369. }
  4370. }
  4371. if (ScamFlg & SCAM_ENABLED) {
  4372. FPT_scbusf(p_port);
  4373. if (currCard->globalFlags & F_UPDATE_EEPROM) {
  4374. FPT_scsavdi(p_card, p_port);
  4375. currCard->globalFlags &= ~F_UPDATE_EEPROM;
  4376. }
  4377. }
  4378. /*
  4379. for (i=0,k=0; i < MAX_SCSI_TAR; i++)
  4380. {
  4381. if ((FPT_scamInfo[i].state == ID_ASSIGNED) ||
  4382. (FPT_scamInfo[i].state == LEGACY))
  4383. k++;
  4384. }
  4385. if (k==2)
  4386. currCard->globalFlags |= F_SINGLE_DEVICE;
  4387. else
  4388. currCard->globalFlags &= ~F_SINGLE_DEVICE;
  4389. */
  4390. }
  4391. /*---------------------------------------------------------------------
  4392. *
  4393. * Function: FPT_scarb
  4394. *
  4395. * Description: Gain control of the bus and wait SCAM select time (250ms)
  4396. *
  4397. *---------------------------------------------------------------------*/
  4398. static int FPT_scarb(u32 p_port, unsigned char p_sel_type)
  4399. {
  4400. if (p_sel_type == INIT_SELTD) {
  4401. while (RD_HARPOON(p_port + hp_scsisig) & (SCSI_SEL | SCSI_BSY)) {
  4402. }
  4403. if (RD_HARPOON(p_port + hp_scsisig) & SCSI_SEL)
  4404. return 0;
  4405. if (RD_HARPOON(p_port + hp_scsidata_0) != 00)
  4406. return 0;
  4407. WR_HARPOON(p_port + hp_scsisig,
  4408. (RD_HARPOON(p_port + hp_scsisig) | SCSI_BSY));
  4409. if (RD_HARPOON(p_port + hp_scsisig) & SCSI_SEL) {
  4410. WR_HARPOON(p_port + hp_scsisig,
  4411. (RD_HARPOON(p_port + hp_scsisig) &
  4412. ~SCSI_BSY));
  4413. return 0;
  4414. }
  4415. WR_HARPOON(p_port + hp_scsisig,
  4416. (RD_HARPOON(p_port + hp_scsisig) | SCSI_SEL));
  4417. if (RD_HARPOON(p_port + hp_scsidata_0) != 00) {
  4418. WR_HARPOON(p_port + hp_scsisig,
  4419. (RD_HARPOON(p_port + hp_scsisig) &
  4420. ~(SCSI_BSY | SCSI_SEL)));
  4421. return 0;
  4422. }
  4423. }
  4424. WR_HARPOON(p_port + hp_clkctrl_0, (RD_HARPOON(p_port + hp_clkctrl_0)
  4425. & ~ACTdeassert));
  4426. WR_HARPOON(p_port + hp_scsireset, SCAM_EN);
  4427. WR_HARPOON(p_port + hp_scsidata_0, 0x00);
  4428. WR_HARPOON(p_port + hp_scsidata_1, 0x00);
  4429. WR_HARPOON(p_port + hp_portctrl_0, SCSI_BUS_EN);
  4430. WR_HARPOON(p_port + hp_scsisig,
  4431. (RD_HARPOON(p_port + hp_scsisig) | SCSI_MSG));
  4432. WR_HARPOON(p_port + hp_scsisig, (RD_HARPOON(p_port + hp_scsisig)
  4433. & ~SCSI_BSY));
  4434. FPT_Wait(p_port, TO_250ms);
  4435. return 1;
  4436. }
  4437. /*---------------------------------------------------------------------
  4438. *
  4439. * Function: FPT_scbusf
  4440. *
  4441. * Description: Release the SCSI bus and disable SCAM selection.
  4442. *
  4443. *---------------------------------------------------------------------*/
  4444. static void FPT_scbusf(u32 p_port)
  4445. {
  4446. WR_HARPOON(p_port + hp_page_ctrl,
  4447. (RD_HARPOON(p_port + hp_page_ctrl) | G_INT_DISABLE));
  4448. WR_HARPOON(p_port + hp_scsidata_0, 0x00);
  4449. WR_HARPOON(p_port + hp_portctrl_0, (RD_HARPOON(p_port + hp_portctrl_0)
  4450. & ~SCSI_BUS_EN));
  4451. WR_HARPOON(p_port + hp_scsisig, 0x00);
  4452. WR_HARPOON(p_port + hp_scsireset, (RD_HARPOON(p_port + hp_scsireset)
  4453. & ~SCAM_EN));
  4454. WR_HARPOON(p_port + hp_clkctrl_0, (RD_HARPOON(p_port + hp_clkctrl_0)
  4455. | ACTdeassert));
  4456. WRW_HARPOON((p_port + hp_intstat), (BUS_FREE | AUTO_INT | SCAM_SEL));
  4457. WR_HARPOON(p_port + hp_page_ctrl,
  4458. (RD_HARPOON(p_port + hp_page_ctrl) & ~G_INT_DISABLE));
  4459. }
  4460. /*---------------------------------------------------------------------
  4461. *
  4462. * Function: FPT_scasid
  4463. *
  4464. * Description: Assign an ID to all the SCAM devices.
  4465. *
  4466. *---------------------------------------------------------------------*/
  4467. static void FPT_scasid(unsigned char p_card, u32 p_port)
  4468. {
  4469. unsigned char temp_id_string[ID_STRING_LENGTH];
  4470. unsigned char i, k, scam_id;
  4471. unsigned char crcBytes[3];
  4472. struct nvram_info *pCurrNvRam;
  4473. unsigned short *pCrcBytes;
  4474. pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
  4475. i = 0;
  4476. while (!i) {
  4477. for (k = 0; k < ID_STRING_LENGTH; k++) {
  4478. temp_id_string[k] = (unsigned char)0x00;
  4479. }
  4480. FPT_scxferc(p_port, SYNC_PTRN);
  4481. FPT_scxferc(p_port, ASSIGN_ID);
  4482. if (!(FPT_sciso(p_port, &temp_id_string[0]))) {
  4483. if (pCurrNvRam) {
  4484. pCrcBytes = (unsigned short *)&crcBytes[0];
  4485. *pCrcBytes = FPT_CalcCrc16(&temp_id_string[0]);
  4486. crcBytes[2] = FPT_CalcLrc(&temp_id_string[0]);
  4487. temp_id_string[1] = crcBytes[2];
  4488. temp_id_string[2] = crcBytes[0];
  4489. temp_id_string[3] = crcBytes[1];
  4490. for (k = 4; k < ID_STRING_LENGTH; k++)
  4491. temp_id_string[k] = (unsigned char)0x00;
  4492. }
  4493. i = FPT_scmachid(p_card, temp_id_string);
  4494. if (i == CLR_PRIORITY) {
  4495. FPT_scxferc(p_port, MISC_CODE);
  4496. FPT_scxferc(p_port, CLR_P_FLAG);
  4497. i = 0; /*Not the last ID yet. */
  4498. }
  4499. else if (i != NO_ID_AVAIL) {
  4500. if (i < 8)
  4501. FPT_scxferc(p_port, ID_0_7);
  4502. else
  4503. FPT_scxferc(p_port, ID_8_F);
  4504. scam_id = (i & (unsigned char)0x07);
  4505. for (k = 1; k < 0x08; k <<= 1)
  4506. if (!(k & i))
  4507. scam_id += 0x08; /*Count number of zeros in DB0-3. */
  4508. FPT_scxferc(p_port, scam_id);
  4509. i = 0; /*Not the last ID yet. */
  4510. }
  4511. }
  4512. else {
  4513. i = 1;
  4514. }
  4515. } /*End while */
  4516. FPT_scxferc(p_port, SYNC_PTRN);
  4517. FPT_scxferc(p_port, CFG_CMPLT);
  4518. }
  4519. /*---------------------------------------------------------------------
  4520. *
  4521. * Function: FPT_scsel
  4522. *
  4523. * Description: Select all the SCAM devices.
  4524. *
  4525. *---------------------------------------------------------------------*/
  4526. static void FPT_scsel(u32 p_port)
  4527. {
  4528. WR_HARPOON(p_port + hp_scsisig, SCSI_SEL);
  4529. FPT_scwiros(p_port, SCSI_MSG);
  4530. WR_HARPOON(p_port + hp_scsisig, (SCSI_SEL | SCSI_BSY));
  4531. WR_HARPOON(p_port + hp_scsisig,
  4532. (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
  4533. WR_HARPOON(p_port + hp_scsidata_0,
  4534. (unsigned char)(RD_HARPOON(p_port + hp_scsidata_0) |
  4535. (unsigned char)(BIT(7) + BIT(6))));
  4536. WR_HARPOON(p_port + hp_scsisig, (SCSI_BSY | SCSI_IOBIT | SCSI_CD));
  4537. FPT_scwiros(p_port, SCSI_SEL);
  4538. WR_HARPOON(p_port + hp_scsidata_0,
  4539. (unsigned char)(RD_HARPOON(p_port + hp_scsidata_0) &
  4540. ~(unsigned char)BIT(6)));
  4541. FPT_scwirod(p_port, BIT(6));
  4542. WR_HARPOON(p_port + hp_scsisig,
  4543. (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
  4544. }
  4545. /*---------------------------------------------------------------------
  4546. *
  4547. * Function: FPT_scxferc
  4548. *
  4549. * Description: Handshake the p_data (DB4-0) across the bus.
  4550. *
  4551. *---------------------------------------------------------------------*/
  4552. static unsigned char FPT_scxferc(u32 p_port, unsigned char p_data)
  4553. {
  4554. unsigned char curr_data, ret_data;
  4555. curr_data = p_data | BIT(7) | BIT(5); /*Start with DB7 & DB5 asserted. */
  4556. WR_HARPOON(p_port + hp_scsidata_0, curr_data);
  4557. curr_data &= ~BIT(7);
  4558. WR_HARPOON(p_port + hp_scsidata_0, curr_data);
  4559. FPT_scwirod(p_port, BIT(7)); /*Wait for DB7 to be released. */
  4560. while (!(RD_HARPOON(p_port + hp_scsidata_0) & BIT(5))) ;
  4561. ret_data = (RD_HARPOON(p_port + hp_scsidata_0) & (unsigned char)0x1F);
  4562. curr_data |= BIT(6);
  4563. WR_HARPOON(p_port + hp_scsidata_0, curr_data);
  4564. curr_data &= ~BIT(5);
  4565. WR_HARPOON(p_port + hp_scsidata_0, curr_data);
  4566. FPT_scwirod(p_port, BIT(5)); /*Wait for DB5 to be released. */
  4567. curr_data &= ~(BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0)); /*Release data bits */
  4568. curr_data |= BIT(7);
  4569. WR_HARPOON(p_port + hp_scsidata_0, curr_data);
  4570. curr_data &= ~BIT(6);
  4571. WR_HARPOON(p_port + hp_scsidata_0, curr_data);
  4572. FPT_scwirod(p_port, BIT(6)); /*Wait for DB6 to be released. */
  4573. return ret_data;
  4574. }
  4575. /*---------------------------------------------------------------------
  4576. *
  4577. * Function: FPT_scsendi
  4578. *
  4579. * Description: Transfer our Identification string to determine if we
  4580. * will be the dominant master.
  4581. *
  4582. *---------------------------------------------------------------------*/
  4583. static unsigned char FPT_scsendi(u32 p_port, unsigned char p_id_string[])
  4584. {
  4585. unsigned char ret_data, byte_cnt, bit_cnt, defer;
  4586. defer = 0;
  4587. for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
  4588. for (bit_cnt = 0x80; bit_cnt != 0; bit_cnt >>= 1) {
  4589. if (defer)
  4590. ret_data = FPT_scxferc(p_port, 00);
  4591. else if (p_id_string[byte_cnt] & bit_cnt)
  4592. ret_data = FPT_scxferc(p_port, 02);
  4593. else {
  4594. ret_data = FPT_scxferc(p_port, 01);
  4595. if (ret_data & 02)
  4596. defer = 1;
  4597. }
  4598. if ((ret_data & 0x1C) == 0x10)
  4599. return 0x00; /*End of isolation stage, we won! */
  4600. if (ret_data & 0x1C)
  4601. return 0xFF;
  4602. if ((defer) && (!(ret_data & 0x1F)))
  4603. return 0x01; /*End of isolation stage, we lost. */
  4604. } /*bit loop */
  4605. } /*byte loop */
  4606. if (defer)
  4607. return 0x01; /*We lost */
  4608. else
  4609. return 0; /*We WON! Yeeessss! */
  4610. }
  4611. /*---------------------------------------------------------------------
  4612. *
  4613. * Function: FPT_sciso
  4614. *
  4615. * Description: Transfer the Identification string.
  4616. *
  4617. *---------------------------------------------------------------------*/
  4618. static unsigned char FPT_sciso(u32 p_port, unsigned char p_id_string[])
  4619. {
  4620. unsigned char ret_data, the_data, byte_cnt, bit_cnt;
  4621. the_data = 0;
  4622. for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
  4623. for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
  4624. ret_data = FPT_scxferc(p_port, 0);
  4625. if (ret_data & 0xFC)
  4626. return 0xFF;
  4627. else {
  4628. the_data <<= 1;
  4629. if (ret_data & BIT(1)) {
  4630. the_data |= 1;
  4631. }
  4632. }
  4633. if ((ret_data & 0x1F) == 0) {
  4634. /*
  4635. if(bit_cnt != 0 || bit_cnt != 8)
  4636. {
  4637. byte_cnt = 0;
  4638. bit_cnt = 0;
  4639. FPT_scxferc(p_port, SYNC_PTRN);
  4640. FPT_scxferc(p_port, ASSIGN_ID);
  4641. continue;
  4642. }
  4643. */
  4644. if (byte_cnt)
  4645. return 0x00;
  4646. else
  4647. return 0xFF;
  4648. }
  4649. } /*bit loop */
  4650. p_id_string[byte_cnt] = the_data;
  4651. } /*byte loop */
  4652. return 0;
  4653. }
  4654. /*---------------------------------------------------------------------
  4655. *
  4656. * Function: FPT_scwirod
  4657. *
  4658. * Description: Sample the SCSI data bus making sure the signal has been
  4659. * deasserted for the correct number of consecutive samples.
  4660. *
  4661. *---------------------------------------------------------------------*/
  4662. static void FPT_scwirod(u32 p_port, unsigned char p_data_bit)
  4663. {
  4664. unsigned char i;
  4665. i = 0;
  4666. while (i < MAX_SCSI_TAR) {
  4667. if (RD_HARPOON(p_port + hp_scsidata_0) & p_data_bit)
  4668. i = 0;
  4669. else
  4670. i++;
  4671. }
  4672. }
  4673. /*---------------------------------------------------------------------
  4674. *
  4675. * Function: FPT_scwiros
  4676. *
  4677. * Description: Sample the SCSI Signal lines making sure the signal has been
  4678. * deasserted for the correct number of consecutive samples.
  4679. *
  4680. *---------------------------------------------------------------------*/
  4681. static void FPT_scwiros(u32 p_port, unsigned char p_data_bit)
  4682. {
  4683. unsigned char i;
  4684. i = 0;
  4685. while (i < MAX_SCSI_TAR) {
  4686. if (RD_HARPOON(p_port + hp_scsisig) & p_data_bit)
  4687. i = 0;
  4688. else
  4689. i++;
  4690. }
  4691. }
  4692. /*---------------------------------------------------------------------
  4693. *
  4694. * Function: FPT_scvalq
  4695. *
  4696. * Description: Make sure we received a valid data byte.
  4697. *
  4698. *---------------------------------------------------------------------*/
  4699. static unsigned char FPT_scvalq(unsigned char p_quintet)
  4700. {
  4701. unsigned char count;
  4702. for (count = 1; count < 0x08; count <<= 1) {
  4703. if (!(p_quintet & count))
  4704. p_quintet -= 0x80;
  4705. }
  4706. if (p_quintet & 0x18)
  4707. return 0;
  4708. else
  4709. return 1;
  4710. }
  4711. /*---------------------------------------------------------------------
  4712. *
  4713. * Function: FPT_scsell
  4714. *
  4715. * Description: Select the specified device ID using a selection timeout
  4716. * less than 4ms. If somebody responds then it is a legacy
  4717. * drive and this ID must be marked as such.
  4718. *
  4719. *---------------------------------------------------------------------*/
  4720. static unsigned char FPT_scsell(u32 p_port, unsigned char targ_id)
  4721. {
  4722. unsigned long i;
  4723. WR_HARPOON(p_port + hp_page_ctrl,
  4724. (RD_HARPOON(p_port + hp_page_ctrl) | G_INT_DISABLE));
  4725. ARAM_ACCESS(p_port);
  4726. WR_HARPOON(p_port + hp_addstat,
  4727. (RD_HARPOON(p_port + hp_addstat) | SCAM_TIMER));
  4728. WR_HARPOON(p_port + hp_seltimeout, TO_4ms);
  4729. for (i = p_port + CMD_STRT; i < p_port + CMD_STRT + 12; i += 2) {
  4730. WRW_HARPOON(i, (MPM_OP + ACOMMAND));
  4731. }
  4732. WRW_HARPOON(i, (BRH_OP + ALWAYS + NP));
  4733. WRW_HARPOON((p_port + hp_intstat),
  4734. (RESET | TIMEOUT | SEL | BUS_FREE | AUTO_INT));
  4735. WR_HARPOON(p_port + hp_select_id, targ_id);
  4736. WR_HARPOON(p_port + hp_portctrl_0, SCSI_PORT);
  4737. WR_HARPOON(p_port + hp_autostart_3, (SELECT | CMD_ONLY_STRT));
  4738. WR_HARPOON(p_port + hp_scsictrl_0, (SEL_TAR | ENA_RESEL));
  4739. while (!(RDW_HARPOON((p_port + hp_intstat)) &
  4740. (RESET | PROG_HLT | TIMEOUT | AUTO_INT))) {
  4741. }
  4742. if (RDW_HARPOON((p_port + hp_intstat)) & RESET)
  4743. FPT_Wait(p_port, TO_250ms);
  4744. DISABLE_AUTO(p_port);
  4745. WR_HARPOON(p_port + hp_addstat,
  4746. (RD_HARPOON(p_port + hp_addstat) & ~SCAM_TIMER));
  4747. WR_HARPOON(p_port + hp_seltimeout, TO_290ms);
  4748. SGRAM_ACCESS(p_port);
  4749. if (RDW_HARPOON((p_port + hp_intstat)) & (RESET | TIMEOUT)) {
  4750. WRW_HARPOON((p_port + hp_intstat),
  4751. (RESET | TIMEOUT | SEL | BUS_FREE | PHASE));
  4752. WR_HARPOON(p_port + hp_page_ctrl,
  4753. (RD_HARPOON(p_port + hp_page_ctrl) &
  4754. ~G_INT_DISABLE));
  4755. return 0; /*No legacy device */
  4756. }
  4757. else {
  4758. while (!(RDW_HARPOON((p_port + hp_intstat)) & BUS_FREE)) {
  4759. if (RD_HARPOON(p_port + hp_scsisig) & SCSI_REQ) {
  4760. WR_HARPOON(p_port + hp_scsisig,
  4761. (SCSI_ACK + S_ILL_PH));
  4762. ACCEPT_MSG(p_port);
  4763. }
  4764. }
  4765. WRW_HARPOON((p_port + hp_intstat), CLR_ALL_INT_1);
  4766. WR_HARPOON(p_port + hp_page_ctrl,
  4767. (RD_HARPOON(p_port + hp_page_ctrl) &
  4768. ~G_INT_DISABLE));
  4769. return 1; /*Found one of them oldies! */
  4770. }
  4771. }
  4772. /*---------------------------------------------------------------------
  4773. *
  4774. * Function: FPT_scwtsel
  4775. *
  4776. * Description: Wait to be selected by another SCAM initiator.
  4777. *
  4778. *---------------------------------------------------------------------*/
  4779. static void FPT_scwtsel(u32 p_port)
  4780. {
  4781. while (!(RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL)) {
  4782. }
  4783. }
  4784. /*---------------------------------------------------------------------
  4785. *
  4786. * Function: FPT_inisci
  4787. *
  4788. * Description: Setup the data Structure with the info from the EEPROM.
  4789. *
  4790. *---------------------------------------------------------------------*/
  4791. static void FPT_inisci(unsigned char p_card, u32 p_port, unsigned char p_our_id)
  4792. {
  4793. unsigned char i, k, max_id;
  4794. unsigned short ee_data;
  4795. struct nvram_info *pCurrNvRam;
  4796. pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
  4797. if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
  4798. max_id = 0x08;
  4799. else
  4800. max_id = 0x10;
  4801. if (pCurrNvRam) {
  4802. for (i = 0; i < max_id; i++) {
  4803. for (k = 0; k < 4; k++)
  4804. FPT_scamInfo[i].id_string[k] =
  4805. pCurrNvRam->niScamTbl[i][k];
  4806. for (k = 4; k < ID_STRING_LENGTH; k++)
  4807. FPT_scamInfo[i].id_string[k] =
  4808. (unsigned char)0x00;
  4809. if (FPT_scamInfo[i].id_string[0] == 0x00)
  4810. FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
  4811. else
  4812. FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
  4813. }
  4814. } else {
  4815. for (i = 0; i < max_id; i++) {
  4816. for (k = 0; k < ID_STRING_LENGTH; k += 2) {
  4817. ee_data =
  4818. FPT_utilEERead(p_port,
  4819. (unsigned
  4820. short)((EE_SCAMBASE / 2) +
  4821. (unsigned short)(i *
  4822. ((unsigned short)ID_STRING_LENGTH / 2)) + (unsigned short)(k / 2)));
  4823. FPT_scamInfo[i].id_string[k] =
  4824. (unsigned char)ee_data;
  4825. ee_data >>= 8;
  4826. FPT_scamInfo[i].id_string[k + 1] =
  4827. (unsigned char)ee_data;
  4828. }
  4829. if ((FPT_scamInfo[i].id_string[0] == 0x00) ||
  4830. (FPT_scamInfo[i].id_string[0] == 0xFF))
  4831. FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
  4832. else
  4833. FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
  4834. }
  4835. }
  4836. for (k = 0; k < ID_STRING_LENGTH; k++)
  4837. FPT_scamInfo[p_our_id].id_string[k] = FPT_scamHAString[k];
  4838. }
  4839. /*---------------------------------------------------------------------
  4840. *
  4841. * Function: FPT_scmachid
  4842. *
  4843. * Description: Match the Device ID string with our values stored in
  4844. * the EEPROM.
  4845. *
  4846. *---------------------------------------------------------------------*/
  4847. static unsigned char FPT_scmachid(unsigned char p_card,
  4848. unsigned char p_id_string[])
  4849. {
  4850. unsigned char i, k, match;
  4851. for (i = 0; i < MAX_SCSI_TAR; i++) {
  4852. match = 1;
  4853. for (k = 0; k < ID_STRING_LENGTH; k++) {
  4854. if (p_id_string[k] != FPT_scamInfo[i].id_string[k])
  4855. match = 0;
  4856. }
  4857. if (match) {
  4858. FPT_scamInfo[i].state = ID_ASSIGNED;
  4859. return i;
  4860. }
  4861. }
  4862. if (p_id_string[0] & BIT(5))
  4863. i = 8;
  4864. else
  4865. i = MAX_SCSI_TAR;
  4866. if (((p_id_string[0] & 0x06) == 0x02)
  4867. || ((p_id_string[0] & 0x06) == 0x04))
  4868. match = p_id_string[1] & (unsigned char)0x1F;
  4869. else
  4870. match = 7;
  4871. while (i > 0) {
  4872. i--;
  4873. if (FPT_scamInfo[match].state == ID_UNUSED) {
  4874. for (k = 0; k < ID_STRING_LENGTH; k++) {
  4875. FPT_scamInfo[match].id_string[k] =
  4876. p_id_string[k];
  4877. }
  4878. FPT_scamInfo[match].state = ID_ASSIGNED;
  4879. if (FPT_BL_Card[p_card].pNvRamInfo == NULL)
  4880. FPT_BL_Card[p_card].globalFlags |=
  4881. F_UPDATE_EEPROM;
  4882. return match;
  4883. }
  4884. match--;
  4885. if (match == 0xFF) {
  4886. if (p_id_string[0] & BIT(5))
  4887. match = 7;
  4888. else
  4889. match = MAX_SCSI_TAR - 1;
  4890. }
  4891. }
  4892. if (p_id_string[0] & BIT(7)) {
  4893. return CLR_PRIORITY;
  4894. }
  4895. if (p_id_string[0] & BIT(5))
  4896. i = 8;
  4897. else
  4898. i = MAX_SCSI_TAR;
  4899. if (((p_id_string[0] & 0x06) == 0x02)
  4900. || ((p_id_string[0] & 0x06) == 0x04))
  4901. match = p_id_string[1] & (unsigned char)0x1F;
  4902. else
  4903. match = 7;
  4904. while (i > 0) {
  4905. i--;
  4906. if (FPT_scamInfo[match].state == ID_UNASSIGNED) {
  4907. for (k = 0; k < ID_STRING_LENGTH; k++) {
  4908. FPT_scamInfo[match].id_string[k] =
  4909. p_id_string[k];
  4910. }
  4911. FPT_scamInfo[match].id_string[0] |= BIT(7);
  4912. FPT_scamInfo[match].state = ID_ASSIGNED;
  4913. if (FPT_BL_Card[p_card].pNvRamInfo == NULL)
  4914. FPT_BL_Card[p_card].globalFlags |=
  4915. F_UPDATE_EEPROM;
  4916. return match;
  4917. }
  4918. match--;
  4919. if (match == 0xFF) {
  4920. if (p_id_string[0] & BIT(5))
  4921. match = 7;
  4922. else
  4923. match = MAX_SCSI_TAR - 1;
  4924. }
  4925. }
  4926. return NO_ID_AVAIL;
  4927. }
  4928. /*---------------------------------------------------------------------
  4929. *
  4930. * Function: FPT_scsavdi
  4931. *
  4932. * Description: Save off the device SCAM ID strings.
  4933. *
  4934. *---------------------------------------------------------------------*/
  4935. static void FPT_scsavdi(unsigned char p_card, u32 p_port)
  4936. {
  4937. unsigned char i, k, max_id;
  4938. unsigned short ee_data, sum_data;
  4939. sum_data = 0x0000;
  4940. for (i = 1; i < EE_SCAMBASE / 2; i++) {
  4941. sum_data += FPT_utilEERead(p_port, i);
  4942. }
  4943. FPT_utilEEWriteOnOff(p_port, 1); /* Enable write access to the EEPROM */
  4944. if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
  4945. max_id = 0x08;
  4946. else
  4947. max_id = 0x10;
  4948. for (i = 0; i < max_id; i++) {
  4949. for (k = 0; k < ID_STRING_LENGTH; k += 2) {
  4950. ee_data = FPT_scamInfo[i].id_string[k + 1];
  4951. ee_data <<= 8;
  4952. ee_data |= FPT_scamInfo[i].id_string[k];
  4953. sum_data += ee_data;
  4954. FPT_utilEEWrite(p_port, ee_data,
  4955. (unsigned short)((EE_SCAMBASE / 2) +
  4956. (unsigned short)(i *
  4957. ((unsigned short)ID_STRING_LENGTH / 2)) + (unsigned short)(k / 2)));
  4958. }
  4959. }
  4960. FPT_utilEEWrite(p_port, sum_data, EEPROM_CHECK_SUM / 2);
  4961. FPT_utilEEWriteOnOff(p_port, 0); /* Turn off write access */
  4962. }
  4963. /*---------------------------------------------------------------------
  4964. *
  4965. * Function: FPT_XbowInit
  4966. *
  4967. * Description: Setup the Xbow for normal operation.
  4968. *
  4969. *---------------------------------------------------------------------*/
  4970. static void FPT_XbowInit(u32 port, unsigned char ScamFlg)
  4971. {
  4972. unsigned char i;
  4973. i = RD_HARPOON(port + hp_page_ctrl);
  4974. WR_HARPOON(port + hp_page_ctrl, (unsigned char)(i | G_INT_DISABLE));
  4975. WR_HARPOON(port + hp_scsireset, 0x00);
  4976. WR_HARPOON(port + hp_portctrl_1, HOST_MODE8);
  4977. WR_HARPOON(port + hp_scsireset, (DMA_RESET | HPSCSI_RESET | PROG_RESET |
  4978. FIFO_CLR));
  4979. WR_HARPOON(port + hp_scsireset, SCSI_INI);
  4980. WR_HARPOON(port + hp_clkctrl_0, CLKCTRL_DEFAULT);
  4981. WR_HARPOON(port + hp_scsisig, 0x00); /* Clear any signals we might */
  4982. WR_HARPOON(port + hp_scsictrl_0, ENA_SCAM_SEL);
  4983. WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
  4984. FPT_default_intena = RESET | RSEL | PROG_HLT | TIMEOUT |
  4985. BUS_FREE | XFER_CNT_0 | AUTO_INT;
  4986. if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
  4987. FPT_default_intena |= SCAM_SEL;
  4988. WRW_HARPOON((port + hp_intena), FPT_default_intena);
  4989. WR_HARPOON(port + hp_seltimeout, TO_290ms);
  4990. /* Turn on SCSI_MODE8 for narrow cards to fix the
  4991. strapping issue with the DUAL CHANNEL card */
  4992. if (RD_HARPOON(port + hp_page_ctrl) & NARROW_SCSI_CARD)
  4993. WR_HARPOON(port + hp_addstat, SCSI_MODE8);
  4994. WR_HARPOON(port + hp_page_ctrl, i);
  4995. }
  4996. /*---------------------------------------------------------------------
  4997. *
  4998. * Function: FPT_BusMasterInit
  4999. *
  5000. * Description: Initialize the BusMaster for normal operations.
  5001. *
  5002. *---------------------------------------------------------------------*/
  5003. static void FPT_BusMasterInit(u32 p_port)
  5004. {
  5005. WR_HARPOON(p_port + hp_sys_ctrl, DRVR_RST);
  5006. WR_HARPOON(p_port + hp_sys_ctrl, 0x00);
  5007. WR_HARPOON(p_port + hp_host_blk_cnt, XFER_BLK64);
  5008. WR_HARPOON(p_port + hp_bm_ctrl, (BMCTRL_DEFAULT));
  5009. WR_HARPOON(p_port + hp_ee_ctrl, (SCSI_TERM_ENA_H));
  5010. RD_HARPOON(p_port + hp_int_status); /*Clear interrupts. */
  5011. WR_HARPOON(p_port + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
  5012. WR_HARPOON(p_port + hp_page_ctrl, (RD_HARPOON(p_port + hp_page_ctrl) &
  5013. ~SCATTER_EN));
  5014. }
  5015. /*---------------------------------------------------------------------
  5016. *
  5017. * Function: FPT_DiagEEPROM
  5018. *
  5019. * Description: Verfiy checksum and 'Key' and initialize the EEPROM if
  5020. * necessary.
  5021. *
  5022. *---------------------------------------------------------------------*/
  5023. static void FPT_DiagEEPROM(u32 p_port)
  5024. {
  5025. unsigned short index, temp, max_wd_cnt;
  5026. if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
  5027. max_wd_cnt = EEPROM_WD_CNT;
  5028. else
  5029. max_wd_cnt = EEPROM_WD_CNT * 2;
  5030. temp = FPT_utilEERead(p_port, FW_SIGNATURE / 2);
  5031. if (temp == 0x4641) {
  5032. for (index = 2; index < max_wd_cnt; index++) {
  5033. temp += FPT_utilEERead(p_port, index);
  5034. }
  5035. if (temp == FPT_utilEERead(p_port, EEPROM_CHECK_SUM / 2)) {
  5036. return; /*EEPROM is Okay so return now! */
  5037. }
  5038. }
  5039. FPT_utilEEWriteOnOff(p_port, (unsigned char)1);
  5040. for (index = 0; index < max_wd_cnt; index++) {
  5041. FPT_utilEEWrite(p_port, 0x0000, index);
  5042. }
  5043. temp = 0;
  5044. FPT_utilEEWrite(p_port, 0x4641, FW_SIGNATURE / 2);
  5045. temp += 0x4641;
  5046. FPT_utilEEWrite(p_port, 0x3920, MODEL_NUMB_0 / 2);
  5047. temp += 0x3920;
  5048. FPT_utilEEWrite(p_port, 0x3033, MODEL_NUMB_2 / 2);
  5049. temp += 0x3033;
  5050. FPT_utilEEWrite(p_port, 0x2020, MODEL_NUMB_4 / 2);
  5051. temp += 0x2020;
  5052. FPT_utilEEWrite(p_port, 0x70D3, SYSTEM_CONFIG / 2);
  5053. temp += 0x70D3;
  5054. FPT_utilEEWrite(p_port, 0x0010, BIOS_CONFIG / 2);
  5055. temp += 0x0010;
  5056. FPT_utilEEWrite(p_port, 0x0003, SCAM_CONFIG / 2);
  5057. temp += 0x0003;
  5058. FPT_utilEEWrite(p_port, 0x0007, ADAPTER_SCSI_ID / 2);
  5059. temp += 0x0007;
  5060. FPT_utilEEWrite(p_port, 0x0000, IGNORE_B_SCAN / 2);
  5061. temp += 0x0000;
  5062. FPT_utilEEWrite(p_port, 0x0000, SEND_START_ENA / 2);
  5063. temp += 0x0000;
  5064. FPT_utilEEWrite(p_port, 0x0000, DEVICE_ENABLE / 2);
  5065. temp += 0x0000;
  5066. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL01 / 2);
  5067. temp += 0x4242;
  5068. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL23 / 2);
  5069. temp += 0x4242;
  5070. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL45 / 2);
  5071. temp += 0x4242;
  5072. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL67 / 2);
  5073. temp += 0x4242;
  5074. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL89 / 2);
  5075. temp += 0x4242;
  5076. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLab / 2);
  5077. temp += 0x4242;
  5078. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLcd / 2);
  5079. temp += 0x4242;
  5080. FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLef / 2);
  5081. temp += 0x4242;
  5082. FPT_utilEEWrite(p_port, 0x6C46, 64 / 2); /*PRODUCT ID */
  5083. temp += 0x6C46;
  5084. FPT_utilEEWrite(p_port, 0x7361, 66 / 2); /* FlashPoint LT */
  5085. temp += 0x7361;
  5086. FPT_utilEEWrite(p_port, 0x5068, 68 / 2);
  5087. temp += 0x5068;
  5088. FPT_utilEEWrite(p_port, 0x696F, 70 / 2);
  5089. temp += 0x696F;
  5090. FPT_utilEEWrite(p_port, 0x746E, 72 / 2);
  5091. temp += 0x746E;
  5092. FPT_utilEEWrite(p_port, 0x4C20, 74 / 2);
  5093. temp += 0x4C20;
  5094. FPT_utilEEWrite(p_port, 0x2054, 76 / 2);
  5095. temp += 0x2054;
  5096. FPT_utilEEWrite(p_port, 0x2020, 78 / 2);
  5097. temp += 0x2020;
  5098. index = ((EE_SCAMBASE / 2) + (7 * 16));
  5099. FPT_utilEEWrite(p_port, (0x0700 + TYPE_CODE0), index);
  5100. temp += (0x0700 + TYPE_CODE0);
  5101. index++;
  5102. FPT_utilEEWrite(p_port, 0x5542, index); /*Vendor ID code */
  5103. temp += 0x5542; /* BUSLOGIC */
  5104. index++;
  5105. FPT_utilEEWrite(p_port, 0x4C53, index);
  5106. temp += 0x4C53;
  5107. index++;
  5108. FPT_utilEEWrite(p_port, 0x474F, index);
  5109. temp += 0x474F;
  5110. index++;
  5111. FPT_utilEEWrite(p_port, 0x4349, index);
  5112. temp += 0x4349;
  5113. index++;
  5114. FPT_utilEEWrite(p_port, 0x5442, index); /*Vendor unique code */
  5115. temp += 0x5442; /* BT- 930 */
  5116. index++;
  5117. FPT_utilEEWrite(p_port, 0x202D, index);
  5118. temp += 0x202D;
  5119. index++;
  5120. FPT_utilEEWrite(p_port, 0x3339, index);
  5121. temp += 0x3339;
  5122. index++; /*Serial # */
  5123. FPT_utilEEWrite(p_port, 0x2030, index); /* 01234567 */
  5124. temp += 0x2030;
  5125. index++;
  5126. FPT_utilEEWrite(p_port, 0x5453, index);
  5127. temp += 0x5453;
  5128. index++;
  5129. FPT_utilEEWrite(p_port, 0x5645, index);
  5130. temp += 0x5645;
  5131. index++;
  5132. FPT_utilEEWrite(p_port, 0x2045, index);
  5133. temp += 0x2045;
  5134. index++;
  5135. FPT_utilEEWrite(p_port, 0x202F, index);
  5136. temp += 0x202F;
  5137. index++;
  5138. FPT_utilEEWrite(p_port, 0x4F4A, index);
  5139. temp += 0x4F4A;
  5140. index++;
  5141. FPT_utilEEWrite(p_port, 0x204E, index);
  5142. temp += 0x204E;
  5143. index++;
  5144. FPT_utilEEWrite(p_port, 0x3539, index);
  5145. temp += 0x3539;
  5146. FPT_utilEEWrite(p_port, temp, EEPROM_CHECK_SUM / 2);
  5147. FPT_utilEEWriteOnOff(p_port, (unsigned char)0);
  5148. }
  5149. /*---------------------------------------------------------------------
  5150. *
  5151. * Function: Queue Search Select
  5152. *
  5153. * Description: Try to find a new command to execute.
  5154. *
  5155. *---------------------------------------------------------------------*/
  5156. static void FPT_queueSearchSelect(struct sccb_card *pCurrCard,
  5157. unsigned char p_card)
  5158. {
  5159. unsigned char scan_ptr, lun;
  5160. struct sccb_mgr_tar_info *currTar_Info;
  5161. struct sccb *pOldSccb;
  5162. scan_ptr = pCurrCard->scanIndex;
  5163. do {
  5164. currTar_Info = &FPT_sccbMgrTbl[p_card][scan_ptr];
  5165. if ((pCurrCard->globalFlags & F_CONLUN_IO) &&
  5166. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
  5167. TAG_Q_TRYING)) {
  5168. if (currTar_Info->TarSelQ_Cnt != 0) {
  5169. scan_ptr++;
  5170. if (scan_ptr == MAX_SCSI_TAR)
  5171. scan_ptr = 0;
  5172. for (lun = 0; lun < MAX_LUN; lun++) {
  5173. if (currTar_Info->TarLUNBusy[lun] == 0) {
  5174. pCurrCard->currentSCCB =
  5175. currTar_Info->TarSelQ_Head;
  5176. pOldSccb = NULL;
  5177. while ((pCurrCard->
  5178. currentSCCB != NULL)
  5179. && (lun !=
  5180. pCurrCard->
  5181. currentSCCB->Lun)) {
  5182. pOldSccb =
  5183. pCurrCard->
  5184. currentSCCB;
  5185. pCurrCard->currentSCCB =
  5186. (struct sccb
  5187. *)(pCurrCard->
  5188. currentSCCB)->
  5189. Sccb_forwardlink;
  5190. }
  5191. if (pCurrCard->currentSCCB ==
  5192. NULL)
  5193. continue;
  5194. if (pOldSccb != NULL) {
  5195. pOldSccb->
  5196. Sccb_forwardlink =
  5197. (struct sccb
  5198. *)(pCurrCard->
  5199. currentSCCB)->
  5200. Sccb_forwardlink;
  5201. pOldSccb->
  5202. Sccb_backlink =
  5203. (struct sccb
  5204. *)(pCurrCard->
  5205. currentSCCB)->
  5206. Sccb_backlink;
  5207. currTar_Info->
  5208. TarSelQ_Cnt--;
  5209. } else {
  5210. currTar_Info->
  5211. TarSelQ_Head =
  5212. (struct sccb
  5213. *)(pCurrCard->
  5214. currentSCCB)->
  5215. Sccb_forwardlink;
  5216. if (currTar_Info->
  5217. TarSelQ_Head ==
  5218. NULL) {
  5219. currTar_Info->
  5220. TarSelQ_Tail
  5221. = NULL;
  5222. currTar_Info->
  5223. TarSelQ_Cnt
  5224. = 0;
  5225. } else {
  5226. currTar_Info->
  5227. TarSelQ_Cnt--;
  5228. currTar_Info->
  5229. TarSelQ_Head->
  5230. Sccb_backlink
  5231. =
  5232. (struct sccb
  5233. *)NULL;
  5234. }
  5235. }
  5236. pCurrCard->scanIndex = scan_ptr;
  5237. pCurrCard->globalFlags |=
  5238. F_NEW_SCCB_CMD;
  5239. break;
  5240. }
  5241. }
  5242. }
  5243. else {
  5244. scan_ptr++;
  5245. if (scan_ptr == MAX_SCSI_TAR) {
  5246. scan_ptr = 0;
  5247. }
  5248. }
  5249. } else {
  5250. if ((currTar_Info->TarSelQ_Cnt != 0) &&
  5251. (currTar_Info->TarLUNBusy[0] == 0)) {
  5252. pCurrCard->currentSCCB =
  5253. currTar_Info->TarSelQ_Head;
  5254. currTar_Info->TarSelQ_Head =
  5255. (struct sccb *)(pCurrCard->currentSCCB)->
  5256. Sccb_forwardlink;
  5257. if (currTar_Info->TarSelQ_Head == NULL) {
  5258. currTar_Info->TarSelQ_Tail = NULL;
  5259. currTar_Info->TarSelQ_Cnt = 0;
  5260. } else {
  5261. currTar_Info->TarSelQ_Cnt--;
  5262. currTar_Info->TarSelQ_Head->
  5263. Sccb_backlink = (struct sccb *)NULL;
  5264. }
  5265. scan_ptr++;
  5266. if (scan_ptr == MAX_SCSI_TAR)
  5267. scan_ptr = 0;
  5268. pCurrCard->scanIndex = scan_ptr;
  5269. pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
  5270. break;
  5271. }
  5272. else {
  5273. scan_ptr++;
  5274. if (scan_ptr == MAX_SCSI_TAR) {
  5275. scan_ptr = 0;
  5276. }
  5277. }
  5278. }
  5279. } while (scan_ptr != pCurrCard->scanIndex);
  5280. }
  5281. /*---------------------------------------------------------------------
  5282. *
  5283. * Function: Queue Select Fail
  5284. *
  5285. * Description: Add the current SCCB to the head of the Queue.
  5286. *
  5287. *---------------------------------------------------------------------*/
  5288. static void FPT_queueSelectFail(struct sccb_card *pCurrCard,
  5289. unsigned char p_card)
  5290. {
  5291. unsigned char thisTarg;
  5292. struct sccb_mgr_tar_info *currTar_Info;
  5293. if (pCurrCard->currentSCCB != NULL) {
  5294. thisTarg =
  5295. (unsigned char)(((struct sccb *)(pCurrCard->currentSCCB))->
  5296. TargID);
  5297. currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
  5298. pCurrCard->currentSCCB->Sccb_backlink = (struct sccb *)NULL;
  5299. pCurrCard->currentSCCB->Sccb_forwardlink =
  5300. currTar_Info->TarSelQ_Head;
  5301. if (currTar_Info->TarSelQ_Cnt == 0) {
  5302. currTar_Info->TarSelQ_Tail = pCurrCard->currentSCCB;
  5303. }
  5304. else {
  5305. currTar_Info->TarSelQ_Head->Sccb_backlink =
  5306. pCurrCard->currentSCCB;
  5307. }
  5308. currTar_Info->TarSelQ_Head = pCurrCard->currentSCCB;
  5309. pCurrCard->currentSCCB = NULL;
  5310. currTar_Info->TarSelQ_Cnt++;
  5311. }
  5312. }
  5313. /*---------------------------------------------------------------------
  5314. *
  5315. * Function: Queue Command Complete
  5316. *
  5317. * Description: Call the callback function with the current SCCB.
  5318. *
  5319. *---------------------------------------------------------------------*/
  5320. static void FPT_queueCmdComplete(struct sccb_card *pCurrCard,
  5321. struct sccb *p_sccb, unsigned char p_card)
  5322. {
  5323. unsigned char i, SCSIcmd;
  5324. CALL_BK_FN callback;
  5325. struct sccb_mgr_tar_info *currTar_Info;
  5326. SCSIcmd = p_sccb->Cdb[0];
  5327. if (!(p_sccb->Sccb_XferState & F_ALL_XFERRED)) {
  5328. if ((p_sccb->
  5329. ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN))
  5330. && (p_sccb->HostStatus == SCCB_COMPLETE)
  5331. && (p_sccb->TargetStatus != SAM_STAT_CHECK_CONDITION))
  5332. if ((SCSIcmd == READ_6) ||
  5333. (SCSIcmd == WRITE_6) ||
  5334. (SCSIcmd == READ_10) ||
  5335. (SCSIcmd == WRITE_10) ||
  5336. (SCSIcmd == WRITE_VERIFY) ||
  5337. (SCSIcmd == START_STOP) ||
  5338. (pCurrCard->globalFlags & F_NO_FILTER)
  5339. )
  5340. p_sccb->HostStatus = SCCB_DATA_UNDER_RUN;
  5341. }
  5342. if (p_sccb->SccbStatus == SCCB_IN_PROCESS) {
  5343. if (p_sccb->HostStatus || p_sccb->TargetStatus)
  5344. p_sccb->SccbStatus = SCCB_ERROR;
  5345. else
  5346. p_sccb->SccbStatus = SCCB_SUCCESS;
  5347. }
  5348. if (p_sccb->Sccb_XferState & F_AUTO_SENSE) {
  5349. p_sccb->CdbLength = p_sccb->Save_CdbLen;
  5350. for (i = 0; i < 6; i++) {
  5351. p_sccb->Cdb[i] = p_sccb->Save_Cdb[i];
  5352. }
  5353. }
  5354. if ((p_sccb->OperationCode == RESIDUAL_SG_COMMAND) ||
  5355. (p_sccb->OperationCode == RESIDUAL_COMMAND)) {
  5356. FPT_utilUpdateResidual(p_sccb);
  5357. }
  5358. pCurrCard->cmdCounter--;
  5359. if (!pCurrCard->cmdCounter) {
  5360. if (pCurrCard->globalFlags & F_GREEN_PC) {
  5361. WR_HARPOON(pCurrCard->ioPort + hp_clkctrl_0,
  5362. (PWR_DWN | CLKCTRL_DEFAULT));
  5363. WR_HARPOON(pCurrCard->ioPort + hp_sys_ctrl, STOP_CLK);
  5364. }
  5365. WR_HARPOON(pCurrCard->ioPort + hp_semaphore,
  5366. (RD_HARPOON(pCurrCard->ioPort + hp_semaphore) &
  5367. ~SCCB_MGR_ACTIVE));
  5368. }
  5369. if (pCurrCard->discQCount != 0) {
  5370. currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
  5371. if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
  5372. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
  5373. TAG_Q_TRYING))) {
  5374. pCurrCard->discQCount--;
  5375. pCurrCard->discQ_Tbl[currTar_Info->
  5376. LunDiscQ_Idx[p_sccb->Lun]] = NULL;
  5377. } else {
  5378. if (p_sccb->Sccb_tag) {
  5379. pCurrCard->discQCount--;
  5380. pCurrCard->discQ_Tbl[p_sccb->Sccb_tag] = NULL;
  5381. } else {
  5382. pCurrCard->discQCount--;
  5383. pCurrCard->discQ_Tbl[currTar_Info->
  5384. LunDiscQ_Idx[0]] = NULL;
  5385. }
  5386. }
  5387. }
  5388. callback = (CALL_BK_FN) p_sccb->SccbCallback;
  5389. callback(p_sccb);
  5390. pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
  5391. pCurrCard->currentSCCB = NULL;
  5392. }
  5393. /*---------------------------------------------------------------------
  5394. *
  5395. * Function: Queue Disconnect
  5396. *
  5397. * Description: Add SCCB to our disconnect array.
  5398. *
  5399. *---------------------------------------------------------------------*/
  5400. static void FPT_queueDisconnect(struct sccb *p_sccb, unsigned char p_card)
  5401. {
  5402. struct sccb_mgr_tar_info *currTar_Info;
  5403. currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
  5404. if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
  5405. ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
  5406. FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->
  5407. LunDiscQ_Idx[p_sccb->Lun]] =
  5408. p_sccb;
  5409. } else {
  5410. if (p_sccb->Sccb_tag) {
  5411. FPT_BL_Card[p_card].discQ_Tbl[p_sccb->Sccb_tag] =
  5412. p_sccb;
  5413. FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarLUNBusy[0] =
  5414. 0;
  5415. FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarTagQ_Cnt++;
  5416. } else {
  5417. FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->
  5418. LunDiscQ_Idx[0]] = p_sccb;
  5419. }
  5420. }
  5421. FPT_BL_Card[p_card].currentSCCB = NULL;
  5422. }
  5423. /*---------------------------------------------------------------------
  5424. *
  5425. * Function: Queue Flush SCCB
  5426. *
  5427. * Description: Flush all SCCB's back to the host driver for this target.
  5428. *
  5429. *---------------------------------------------------------------------*/
  5430. static void FPT_queueFlushSccb(unsigned char p_card, unsigned char error_code)
  5431. {
  5432. unsigned char qtag, thisTarg;
  5433. struct sccb *currSCCB;
  5434. struct sccb_mgr_tar_info *currTar_Info;
  5435. currSCCB = FPT_BL_Card[p_card].currentSCCB;
  5436. if (currSCCB != NULL) {
  5437. thisTarg = (unsigned char)currSCCB->TargID;
  5438. currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
  5439. for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
  5440. if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
  5441. (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID ==
  5442. thisTarg)) {
  5443. FPT_BL_Card[p_card].discQ_Tbl[qtag]->
  5444. HostStatus = (unsigned char)error_code;
  5445. FPT_queueCmdComplete(&FPT_BL_Card[p_card],
  5446. FPT_BL_Card[p_card].
  5447. discQ_Tbl[qtag], p_card);
  5448. FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
  5449. currTar_Info->TarTagQ_Cnt--;
  5450. }
  5451. }
  5452. }
  5453. }
  5454. /*---------------------------------------------------------------------
  5455. *
  5456. * Function: Queue Flush Target SCCB
  5457. *
  5458. * Description: Flush all SCCB's back to the host driver for this target.
  5459. *
  5460. *---------------------------------------------------------------------*/
  5461. static void FPT_queueFlushTargSccb(unsigned char p_card, unsigned char thisTarg,
  5462. unsigned char error_code)
  5463. {
  5464. unsigned char qtag;
  5465. struct sccb_mgr_tar_info *currTar_Info;
  5466. currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
  5467. for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
  5468. if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
  5469. (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg)) {
  5470. FPT_BL_Card[p_card].discQ_Tbl[qtag]->HostStatus =
  5471. (unsigned char)error_code;
  5472. FPT_queueCmdComplete(&FPT_BL_Card[p_card],
  5473. FPT_BL_Card[p_card].
  5474. discQ_Tbl[qtag], p_card);
  5475. FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
  5476. currTar_Info->TarTagQ_Cnt--;
  5477. }
  5478. }
  5479. }
  5480. static void FPT_queueAddSccb(struct sccb *p_SCCB, unsigned char p_card)
  5481. {
  5482. struct sccb_mgr_tar_info *currTar_Info;
  5483. currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
  5484. p_SCCB->Sccb_forwardlink = NULL;
  5485. p_SCCB->Sccb_backlink = currTar_Info->TarSelQ_Tail;
  5486. if (currTar_Info->TarSelQ_Cnt == 0) {
  5487. currTar_Info->TarSelQ_Head = p_SCCB;
  5488. }
  5489. else {
  5490. currTar_Info->TarSelQ_Tail->Sccb_forwardlink = p_SCCB;
  5491. }
  5492. currTar_Info->TarSelQ_Tail = p_SCCB;
  5493. currTar_Info->TarSelQ_Cnt++;
  5494. }
  5495. /*---------------------------------------------------------------------
  5496. *
  5497. * Function: Queue Find SCCB
  5498. *
  5499. * Description: Search the target select Queue for this SCCB, and
  5500. * remove it if found.
  5501. *
  5502. *---------------------------------------------------------------------*/
  5503. static unsigned char FPT_queueFindSccb(struct sccb *p_SCCB,
  5504. unsigned char p_card)
  5505. {
  5506. struct sccb *q_ptr;
  5507. struct sccb_mgr_tar_info *currTar_Info;
  5508. currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
  5509. q_ptr = currTar_Info->TarSelQ_Head;
  5510. while (q_ptr != NULL) {
  5511. if (q_ptr == p_SCCB) {
  5512. if (currTar_Info->TarSelQ_Head == q_ptr) {
  5513. currTar_Info->TarSelQ_Head =
  5514. q_ptr->Sccb_forwardlink;
  5515. }
  5516. if (currTar_Info->TarSelQ_Tail == q_ptr) {
  5517. currTar_Info->TarSelQ_Tail =
  5518. q_ptr->Sccb_backlink;
  5519. }
  5520. if (q_ptr->Sccb_forwardlink != NULL) {
  5521. q_ptr->Sccb_forwardlink->Sccb_backlink =
  5522. q_ptr->Sccb_backlink;
  5523. }
  5524. if (q_ptr->Sccb_backlink != NULL) {
  5525. q_ptr->Sccb_backlink->Sccb_forwardlink =
  5526. q_ptr->Sccb_forwardlink;
  5527. }
  5528. currTar_Info->TarSelQ_Cnt--;
  5529. return 1;
  5530. }
  5531. else {
  5532. q_ptr = q_ptr->Sccb_forwardlink;
  5533. }
  5534. }
  5535. return 0;
  5536. }
  5537. /*---------------------------------------------------------------------
  5538. *
  5539. * Function: Utility Update Residual Count
  5540. *
  5541. * Description: Update the XferCnt to the remaining byte count.
  5542. * If we transferred all the data then just write zero.
  5543. * If Non-SG transfer then report Total Cnt - Actual Transfer
  5544. * Cnt. For SG transfers add the count fields of all
  5545. * remaining SG elements, as well as any partial remaining
  5546. * element.
  5547. *
  5548. *---------------------------------------------------------------------*/
  5549. static void FPT_utilUpdateResidual(struct sccb *p_SCCB)
  5550. {
  5551. unsigned long partial_cnt;
  5552. unsigned int sg_index;
  5553. struct blogic_sg_seg *segp;
  5554. if (p_SCCB->Sccb_XferState & F_ALL_XFERRED) {
  5555. p_SCCB->DataLength = 0x0000;
  5556. }
  5557. else if (p_SCCB->Sccb_XferState & F_SG_XFER) {
  5558. partial_cnt = 0x0000;
  5559. sg_index = p_SCCB->Sccb_sgseg;
  5560. if (p_SCCB->Sccb_SGoffset) {
  5561. partial_cnt = p_SCCB->Sccb_SGoffset;
  5562. sg_index++;
  5563. }
  5564. while (((unsigned long)sg_index *
  5565. (unsigned long)SG_ELEMENT_SIZE) < p_SCCB->DataLength) {
  5566. segp = (struct blogic_sg_seg *)(p_SCCB->DataPointer) +
  5567. (sg_index * 2);
  5568. partial_cnt += segp->segbytes;
  5569. sg_index++;
  5570. }
  5571. p_SCCB->DataLength = partial_cnt;
  5572. }
  5573. else {
  5574. p_SCCB->DataLength -= p_SCCB->Sccb_ATC;
  5575. }
  5576. }
  5577. /*---------------------------------------------------------------------
  5578. *
  5579. * Function: Wait 1 Second
  5580. *
  5581. * Description: Wait for 1 second.
  5582. *
  5583. *---------------------------------------------------------------------*/
  5584. static void FPT_Wait1Second(u32 p_port)
  5585. {
  5586. unsigned char i;
  5587. for (i = 0; i < 4; i++) {
  5588. FPT_Wait(p_port, TO_250ms);
  5589. if ((RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST))
  5590. break;
  5591. if ((RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL))
  5592. break;
  5593. }
  5594. }
  5595. /*---------------------------------------------------------------------
  5596. *
  5597. * Function: FPT_Wait
  5598. *
  5599. * Description: Wait the desired delay.
  5600. *
  5601. *---------------------------------------------------------------------*/
  5602. static void FPT_Wait(u32 p_port, unsigned char p_delay)
  5603. {
  5604. unsigned char old_timer;
  5605. unsigned char green_flag;
  5606. old_timer = RD_HARPOON(p_port + hp_seltimeout);
  5607. green_flag = RD_HARPOON(p_port + hp_clkctrl_0);
  5608. WR_HARPOON(p_port + hp_clkctrl_0, CLKCTRL_DEFAULT);
  5609. WR_HARPOON(p_port + hp_seltimeout, p_delay);
  5610. WRW_HARPOON((p_port + hp_intstat), TIMEOUT);
  5611. WRW_HARPOON((p_port + hp_intena), (FPT_default_intena & ~TIMEOUT));
  5612. WR_HARPOON(p_port + hp_portctrl_0,
  5613. (RD_HARPOON(p_port + hp_portctrl_0) | START_TO));
  5614. while (!(RDW_HARPOON((p_port + hp_intstat)) & TIMEOUT)) {
  5615. if ((RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST))
  5616. break;
  5617. if ((RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL))
  5618. break;
  5619. }
  5620. WR_HARPOON(p_port + hp_portctrl_0,
  5621. (RD_HARPOON(p_port + hp_portctrl_0) & ~START_TO));
  5622. WRW_HARPOON((p_port + hp_intstat), TIMEOUT);
  5623. WRW_HARPOON((p_port + hp_intena), FPT_default_intena);
  5624. WR_HARPOON(p_port + hp_clkctrl_0, green_flag);
  5625. WR_HARPOON(p_port + hp_seltimeout, old_timer);
  5626. }
  5627. /*---------------------------------------------------------------------
  5628. *
  5629. * Function: Enable/Disable Write to EEPROM
  5630. *
  5631. * Description: The EEPROM must first be enabled for writes
  5632. * A total of 9 clocks are needed.
  5633. *
  5634. *---------------------------------------------------------------------*/
  5635. static void FPT_utilEEWriteOnOff(u32 p_port, unsigned char p_mode)
  5636. {
  5637. unsigned char ee_value;
  5638. ee_value =
  5639. (unsigned char)(RD_HARPOON(p_port + hp_ee_ctrl) &
  5640. (EXT_ARB_ACK | SCSI_TERM_ENA_H));
  5641. if (p_mode)
  5642. FPT_utilEESendCmdAddr(p_port, EWEN, EWEN_ADDR);
  5643. else
  5644. FPT_utilEESendCmdAddr(p_port, EWDS, EWDS_ADDR);
  5645. WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
  5646. WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /*Turn off Master Select */
  5647. }
  5648. /*---------------------------------------------------------------------
  5649. *
  5650. * Function: Write EEPROM
  5651. *
  5652. * Description: Write a word to the EEPROM at the specified
  5653. * address.
  5654. *
  5655. *---------------------------------------------------------------------*/
  5656. static void FPT_utilEEWrite(u32 p_port, unsigned short ee_data,
  5657. unsigned short ee_addr)
  5658. {
  5659. unsigned char ee_value;
  5660. unsigned short i;
  5661. ee_value =
  5662. (unsigned
  5663. char)((RD_HARPOON(p_port + hp_ee_ctrl) &
  5664. (EXT_ARB_ACK | SCSI_TERM_ENA_H)) | (SEE_MS | SEE_CS));
  5665. FPT_utilEESendCmdAddr(p_port, EE_WRITE, ee_addr);
  5666. ee_value |= (SEE_MS + SEE_CS);
  5667. for (i = 0x8000; i != 0; i >>= 1) {
  5668. if (i & ee_data)
  5669. ee_value |= SEE_DO;
  5670. else
  5671. ee_value &= ~SEE_DO;
  5672. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5673. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5674. ee_value |= SEE_CLK; /* Clock data! */
  5675. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5676. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5677. ee_value &= ~SEE_CLK;
  5678. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5679. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5680. }
  5681. ee_value &= (EXT_ARB_ACK | SCSI_TERM_ENA_H);
  5682. WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS));
  5683. FPT_Wait(p_port, TO_10ms);
  5684. WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS | SEE_CS)); /* Set CS to EEPROM */
  5685. WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /* Turn off CS */
  5686. WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /* Turn off Master Select */
  5687. }
  5688. /*---------------------------------------------------------------------
  5689. *
  5690. * Function: Read EEPROM
  5691. *
  5692. * Description: Read a word from the EEPROM at the desired
  5693. * address.
  5694. *
  5695. *---------------------------------------------------------------------*/
  5696. static unsigned short FPT_utilEERead(u32 p_port,
  5697. unsigned short ee_addr)
  5698. {
  5699. unsigned short i, ee_data1, ee_data2;
  5700. i = 0;
  5701. ee_data1 = FPT_utilEEReadOrg(p_port, ee_addr);
  5702. do {
  5703. ee_data2 = FPT_utilEEReadOrg(p_port, ee_addr);
  5704. if (ee_data1 == ee_data2)
  5705. return ee_data1;
  5706. ee_data1 = ee_data2;
  5707. i++;
  5708. } while (i < 4);
  5709. return ee_data1;
  5710. }
  5711. /*---------------------------------------------------------------------
  5712. *
  5713. * Function: Read EEPROM Original
  5714. *
  5715. * Description: Read a word from the EEPROM at the desired
  5716. * address.
  5717. *
  5718. *---------------------------------------------------------------------*/
  5719. static unsigned short FPT_utilEEReadOrg(u32 p_port, unsigned short ee_addr)
  5720. {
  5721. unsigned char ee_value;
  5722. unsigned short i, ee_data;
  5723. ee_value =
  5724. (unsigned
  5725. char)((RD_HARPOON(p_port + hp_ee_ctrl) &
  5726. (EXT_ARB_ACK | SCSI_TERM_ENA_H)) | (SEE_MS | SEE_CS));
  5727. FPT_utilEESendCmdAddr(p_port, EE_READ, ee_addr);
  5728. ee_value |= (SEE_MS + SEE_CS);
  5729. ee_data = 0;
  5730. for (i = 1; i <= 16; i++) {
  5731. ee_value |= SEE_CLK; /* Clock data! */
  5732. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5733. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5734. ee_value &= ~SEE_CLK;
  5735. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5736. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5737. ee_data <<= 1;
  5738. if (RD_HARPOON(p_port + hp_ee_ctrl) & SEE_DI)
  5739. ee_data |= 1;
  5740. }
  5741. ee_value &= ~(SEE_MS + SEE_CS);
  5742. WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
  5743. WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /*Turn off Master Select */
  5744. return ee_data;
  5745. }
  5746. /*---------------------------------------------------------------------
  5747. *
  5748. * Function: Send EE command and Address to the EEPROM
  5749. *
  5750. * Description: Transfers the correct command and sends the address
  5751. * to the eeprom.
  5752. *
  5753. *---------------------------------------------------------------------*/
  5754. static void FPT_utilEESendCmdAddr(u32 p_port, unsigned char ee_cmd,
  5755. unsigned short ee_addr)
  5756. {
  5757. unsigned char ee_value;
  5758. unsigned char narrow_flg;
  5759. unsigned short i;
  5760. narrow_flg =
  5761. (unsigned char)(RD_HARPOON(p_port + hp_page_ctrl) &
  5762. NARROW_SCSI_CARD);
  5763. ee_value = SEE_MS;
  5764. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5765. ee_value |= SEE_CS; /* Set CS to EEPROM */
  5766. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5767. for (i = 0x04; i != 0; i >>= 1) {
  5768. if (i & ee_cmd)
  5769. ee_value |= SEE_DO;
  5770. else
  5771. ee_value &= ~SEE_DO;
  5772. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5773. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5774. ee_value |= SEE_CLK; /* Clock data! */
  5775. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5776. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5777. ee_value &= ~SEE_CLK;
  5778. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5779. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5780. }
  5781. if (narrow_flg)
  5782. i = 0x0080;
  5783. else
  5784. i = 0x0200;
  5785. while (i != 0) {
  5786. if (i & ee_addr)
  5787. ee_value |= SEE_DO;
  5788. else
  5789. ee_value &= ~SEE_DO;
  5790. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5791. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5792. ee_value |= SEE_CLK; /* Clock data! */
  5793. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5794. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5795. ee_value &= ~SEE_CLK;
  5796. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5797. WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
  5798. i >>= 1;
  5799. }
  5800. }
  5801. static unsigned short FPT_CalcCrc16(unsigned char buffer[])
  5802. {
  5803. unsigned short crc = 0;
  5804. int i, j;
  5805. unsigned short ch;
  5806. for (i = 0; i < ID_STRING_LENGTH; i++) {
  5807. ch = (unsigned short)buffer[i];
  5808. for (j = 0; j < 8; j++) {
  5809. if ((crc ^ ch) & 1)
  5810. crc = (crc >> 1) ^ CRCMASK;
  5811. else
  5812. crc >>= 1;
  5813. ch >>= 1;
  5814. }
  5815. }
  5816. return crc;
  5817. }
  5818. static unsigned char FPT_CalcLrc(unsigned char buffer[])
  5819. {
  5820. int i;
  5821. unsigned char lrc;
  5822. lrc = 0;
  5823. for (i = 0; i < ID_STRING_LENGTH; i++)
  5824. lrc ^= buffer[i];
  5825. return lrc;
  5826. }
  5827. /*
  5828. The following inline definitions avoid type conflicts.
  5829. */
  5830. static inline unsigned char
  5831. FlashPoint__ProbeHostAdapter(struct fpoint_info *FlashPointInfo)
  5832. {
  5833. return FlashPoint_ProbeHostAdapter((struct sccb_mgr_info *)
  5834. FlashPointInfo);
  5835. }
  5836. static inline void *
  5837. FlashPoint__HardwareResetHostAdapter(struct fpoint_info *FlashPointInfo)
  5838. {
  5839. return FlashPoint_HardwareResetHostAdapter((struct sccb_mgr_info *)
  5840. FlashPointInfo);
  5841. }
  5842. static inline void
  5843. FlashPoint__ReleaseHostAdapter(void *CardHandle)
  5844. {
  5845. FlashPoint_ReleaseHostAdapter(CardHandle);
  5846. }
  5847. static inline void
  5848. FlashPoint__StartCCB(void *CardHandle, struct blogic_ccb *CCB)
  5849. {
  5850. FlashPoint_StartCCB(CardHandle, (struct sccb *)CCB);
  5851. }
  5852. static inline void
  5853. FlashPoint__AbortCCB(void *CardHandle, struct blogic_ccb *CCB)
  5854. {
  5855. FlashPoint_AbortCCB(CardHandle, (struct sccb *)CCB);
  5856. }
  5857. static inline bool
  5858. FlashPoint__InterruptPending(void *CardHandle)
  5859. {
  5860. return FlashPoint_InterruptPending(CardHandle);
  5861. }
  5862. static inline int
  5863. FlashPoint__HandleInterrupt(void *CardHandle)
  5864. {
  5865. return FlashPoint_HandleInterrupt(CardHandle);
  5866. }
  5867. #define FlashPoint_ProbeHostAdapter FlashPoint__ProbeHostAdapter
  5868. #define FlashPoint_HardwareResetHostAdapter FlashPoint__HardwareResetHostAdapter
  5869. #define FlashPoint_ReleaseHostAdapter FlashPoint__ReleaseHostAdapter
  5870. #define FlashPoint_StartCCB FlashPoint__StartCCB
  5871. #define FlashPoint_AbortCCB FlashPoint__AbortCCB
  5872. #define FlashPoint_InterruptPending FlashPoint__InterruptPending
  5873. #define FlashPoint_HandleInterrupt FlashPoint__HandleInterrupt
  5874. #else /* !CONFIG_SCSI_FLASHPOINT */
  5875. /*
  5876. Define prototypes for the FlashPoint SCCB Manager Functions.
  5877. */
  5878. extern unsigned char FlashPoint_ProbeHostAdapter(struct fpoint_info *);
  5879. extern void *FlashPoint_HardwareResetHostAdapter(struct fpoint_info *);
  5880. extern void FlashPoint_StartCCB(void *, struct blogic_ccb *);
  5881. extern int FlashPoint_AbortCCB(void *, struct blogic_ccb *);
  5882. extern bool FlashPoint_InterruptPending(void *);
  5883. extern int FlashPoint_HandleInterrupt(void *);
  5884. extern void FlashPoint_ReleaseHostAdapter(void *);
  5885. #endif /* CONFIG_SCSI_FLASHPOINT */