FlashPoint.c 202 KB

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