FlashPoint.c 202 KB

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