FlashPoint.c 196 KB

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