advansys.c 337 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
  4. *
  5. * Copyright (c) 1995-2000 Advanced System Products, Inc.
  6. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
  7. * Copyright (c) 2007 Matthew Wilcox <[email protected]>
  8. * Copyright (c) 2014 Hannes Reinecke <[email protected]>
  9. * All Rights Reserved.
  10. */
  11. /*
  12. * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
  13. * changed its name to ConnectCom Solutions, Inc.
  14. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
  15. */
  16. #include <linux/module.h>
  17. #include <linux/string.h>
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/ioport.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/mm.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/init.h>
  27. #include <linux/blkdev.h>
  28. #include <linux/isa.h>
  29. #include <linux/eisa.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/firmware.h>
  34. #include <linux/dmapool.h>
  35. #include <asm/io.h>
  36. #include <asm/dma.h>
  37. #include <scsi/scsi_cmnd.h>
  38. #include <scsi/scsi_device.h>
  39. #include <scsi/scsi_tcq.h>
  40. #include <scsi/scsi.h>
  41. #include <scsi/scsi_host.h>
  42. #define DRV_NAME "advansys"
  43. #define ASC_VERSION "3.5" /* AdvanSys Driver Version */
  44. /* FIXME:
  45. *
  46. * 1. Use scsi_transport_spi
  47. * 2. advansys_info is not safe against multiple simultaneous callers
  48. * 3. Add module_param to override ISA/VLB ioport array
  49. */
  50. /* Enable driver /proc statistics. */
  51. #define ADVANSYS_STATS
  52. /* Enable driver tracing. */
  53. #undef ADVANSYS_DEBUG
  54. typedef unsigned char uchar;
  55. #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
  56. #define PCI_VENDOR_ID_ASP 0x10cd
  57. #define PCI_DEVICE_ID_ASP_1200A 0x1100
  58. #define PCI_DEVICE_ID_ASP_ABP940 0x1200
  59. #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
  60. #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
  61. #define PCI_DEVICE_ID_38C0800_REV1 0x2500
  62. #define PCI_DEVICE_ID_38C1600_REV1 0x2700
  63. #define PortAddr unsigned int /* port address size */
  64. #define inp(port) inb(port)
  65. #define outp(port, byte) outb((byte), (port))
  66. #define inpw(port) inw(port)
  67. #define outpw(port, word) outw((word), (port))
  68. #define ASC_MAX_SG_QUEUE 7
  69. #define ASC_MAX_SG_LIST 255
  70. #define ASC_CS_TYPE unsigned short
  71. #define ASC_IS_EISA (0x0002)
  72. #define ASC_IS_PCI (0x0004)
  73. #define ASC_IS_PCI_ULTRA (0x0104)
  74. #define ASC_IS_PCMCIA (0x0008)
  75. #define ASC_IS_MCA (0x0020)
  76. #define ASC_IS_VL (0x0040)
  77. #define ASC_IS_WIDESCSI_16 (0x0100)
  78. #define ASC_IS_WIDESCSI_32 (0x0200)
  79. #define ASC_IS_BIG_ENDIAN (0x8000)
  80. #define ASC_CHIP_MIN_VER_VL (0x01)
  81. #define ASC_CHIP_MAX_VER_VL (0x07)
  82. #define ASC_CHIP_MIN_VER_PCI (0x09)
  83. #define ASC_CHIP_MAX_VER_PCI (0x0F)
  84. #define ASC_CHIP_VER_PCI_BIT (0x08)
  85. #define ASC_CHIP_VER_ASYN_BUG (0x21)
  86. #define ASC_CHIP_VER_PCI 0x08
  87. #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
  88. #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
  89. #define ASC_CHIP_MIN_VER_EISA (0x41)
  90. #define ASC_CHIP_MAX_VER_EISA (0x47)
  91. #define ASC_CHIP_VER_EISA_BIT (0x40)
  92. #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
  93. #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
  94. #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
  95. #define ASC_SCSI_ID_BITS 3
  96. #define ASC_SCSI_TIX_TYPE uchar
  97. #define ASC_ALL_DEVICE_BIT_SET 0xFF
  98. #define ASC_SCSI_BIT_ID_TYPE uchar
  99. #define ASC_MAX_TID 7
  100. #define ASC_MAX_LUN 7
  101. #define ASC_SCSI_WIDTH_BIT_SET 0xFF
  102. #define ASC_MAX_SENSE_LEN 32
  103. #define ASC_MIN_SENSE_LEN 14
  104. #define ASC_SCSI_RESET_HOLD_TIME_US 60
  105. /*
  106. * Narrow boards only support 12-byte commands, while wide boards
  107. * extend to 16-byte commands.
  108. */
  109. #define ASC_MAX_CDB_LEN 12
  110. #define ADV_MAX_CDB_LEN 16
  111. #define MS_SDTR_LEN 0x03
  112. #define MS_WDTR_LEN 0x02
  113. #define ASC_SG_LIST_PER_Q 7
  114. #define QS_FREE 0x00
  115. #define QS_READY 0x01
  116. #define QS_DISC1 0x02
  117. #define QS_DISC2 0x04
  118. #define QS_BUSY 0x08
  119. #define QS_ABORTED 0x40
  120. #define QS_DONE 0x80
  121. #define QC_NO_CALLBACK 0x01
  122. #define QC_SG_SWAP_QUEUE 0x02
  123. #define QC_SG_HEAD 0x04
  124. #define QC_DATA_IN 0x08
  125. #define QC_DATA_OUT 0x10
  126. #define QC_URGENT 0x20
  127. #define QC_MSG_OUT 0x40
  128. #define QC_REQ_SENSE 0x80
  129. #define QCSG_SG_XFER_LIST 0x02
  130. #define QCSG_SG_XFER_MORE 0x04
  131. #define QCSG_SG_XFER_END 0x08
  132. #define QD_IN_PROGRESS 0x00
  133. #define QD_NO_ERROR 0x01
  134. #define QD_ABORTED_BY_HOST 0x02
  135. #define QD_WITH_ERROR 0x04
  136. #define QD_INVALID_REQUEST 0x80
  137. #define QD_INVALID_HOST_NUM 0x81
  138. #define QD_INVALID_DEVICE 0x82
  139. #define QD_ERR_INTERNAL 0xFF
  140. #define QHSTA_NO_ERROR 0x00
  141. #define QHSTA_M_SEL_TIMEOUT 0x11
  142. #define QHSTA_M_DATA_OVER_RUN 0x12
  143. #define QHSTA_M_DATA_UNDER_RUN 0x12
  144. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  145. #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
  146. #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
  147. #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
  148. #define QHSTA_D_HOST_ABORT_FAILED 0x23
  149. #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
  150. #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
  151. #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
  152. #define QHSTA_M_WTM_TIMEOUT 0x41
  153. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  154. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  155. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  156. #define QHSTA_M_TARGET_STATUS_BUSY 0x45
  157. #define QHSTA_M_BAD_TAG_CODE 0x46
  158. #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
  159. #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
  160. #define QHSTA_D_LRAM_CMP_ERROR 0x81
  161. #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
  162. #define ASC_FLAG_SCSIQ_REQ 0x01
  163. #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
  164. #define ASC_FLAG_BIOS_ASYNC_IO 0x04
  165. #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
  166. #define ASC_FLAG_WIN16 0x10
  167. #define ASC_FLAG_WIN32 0x20
  168. #define ASC_FLAG_DOS_VM_CALLBACK 0x80
  169. #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
  170. #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
  171. #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
  172. #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
  173. #define ASC_SCSIQ_CPY_BEG 4
  174. #define ASC_SCSIQ_SGHD_CPY_BEG 2
  175. #define ASC_SCSIQ_B_FWD 0
  176. #define ASC_SCSIQ_B_BWD 1
  177. #define ASC_SCSIQ_B_STATUS 2
  178. #define ASC_SCSIQ_B_QNO 3
  179. #define ASC_SCSIQ_B_CNTL 4
  180. #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
  181. #define ASC_SCSIQ_D_DATA_ADDR 8
  182. #define ASC_SCSIQ_D_DATA_CNT 12
  183. #define ASC_SCSIQ_B_SENSE_LEN 20
  184. #define ASC_SCSIQ_DONE_INFO_BEG 22
  185. #define ASC_SCSIQ_D_SRBPTR 22
  186. #define ASC_SCSIQ_B_TARGET_IX 26
  187. #define ASC_SCSIQ_B_CDB_LEN 28
  188. #define ASC_SCSIQ_B_TAG_CODE 29
  189. #define ASC_SCSIQ_W_VM_ID 30
  190. #define ASC_SCSIQ_DONE_STATUS 32
  191. #define ASC_SCSIQ_HOST_STATUS 33
  192. #define ASC_SCSIQ_SCSI_STATUS 34
  193. #define ASC_SCSIQ_CDB_BEG 36
  194. #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
  195. #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
  196. #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
  197. #define ASC_SCSIQ_B_SG_WK_QP 49
  198. #define ASC_SCSIQ_B_SG_WK_IX 50
  199. #define ASC_SCSIQ_W_ALT_DC1 52
  200. #define ASC_SCSIQ_B_LIST_CNT 6
  201. #define ASC_SCSIQ_B_CUR_LIST_CNT 7
  202. #define ASC_SGQ_B_SG_CNTL 4
  203. #define ASC_SGQ_B_SG_HEAD_QP 5
  204. #define ASC_SGQ_B_SG_LIST_CNT 6
  205. #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
  206. #define ASC_SGQ_LIST_BEG 8
  207. #define ASC_DEF_SCSI1_QNG 4
  208. #define ASC_MAX_SCSI1_QNG 4
  209. #define ASC_DEF_SCSI2_QNG 16
  210. #define ASC_MAX_SCSI2_QNG 32
  211. #define ASC_TAG_CODE_MASK 0x23
  212. #define ASC_STOP_REQ_RISC_STOP 0x01
  213. #define ASC_STOP_ACK_RISC_STOP 0x03
  214. #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
  215. #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
  216. #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
  217. #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
  218. #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
  219. #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
  220. #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
  221. #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
  222. #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
  223. #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
  224. typedef struct asc_scsiq_1 {
  225. uchar status;
  226. uchar q_no;
  227. uchar cntl;
  228. uchar sg_queue_cnt;
  229. uchar target_id;
  230. uchar target_lun;
  231. __le32 data_addr;
  232. __le32 data_cnt;
  233. __le32 sense_addr;
  234. uchar sense_len;
  235. uchar extra_bytes;
  236. } ASC_SCSIQ_1;
  237. typedef struct asc_scsiq_2 {
  238. u32 srb_tag;
  239. uchar target_ix;
  240. uchar flag;
  241. uchar cdb_len;
  242. uchar tag_code;
  243. ushort vm_id;
  244. } ASC_SCSIQ_2;
  245. typedef struct asc_scsiq_3 {
  246. uchar done_stat;
  247. uchar host_stat;
  248. uchar scsi_stat;
  249. uchar scsi_msg;
  250. } ASC_SCSIQ_3;
  251. typedef struct asc_scsiq_4 {
  252. uchar cdb[ASC_MAX_CDB_LEN];
  253. uchar y_first_sg_list_qp;
  254. uchar y_working_sg_qp;
  255. uchar y_working_sg_ix;
  256. uchar y_res;
  257. ushort x_req_count;
  258. ushort x_reconnect_rtn;
  259. __le32 x_saved_data_addr;
  260. __le32 x_saved_data_cnt;
  261. } ASC_SCSIQ_4;
  262. typedef struct asc_q_done_info {
  263. ASC_SCSIQ_2 d2;
  264. ASC_SCSIQ_3 d3;
  265. uchar q_status;
  266. uchar q_no;
  267. uchar cntl;
  268. uchar sense_len;
  269. uchar extra_bytes;
  270. uchar res;
  271. u32 remain_bytes;
  272. } ASC_QDONE_INFO;
  273. typedef struct asc_sg_list {
  274. __le32 addr;
  275. __le32 bytes;
  276. } ASC_SG_LIST;
  277. typedef struct asc_sg_head {
  278. ushort entry_cnt;
  279. ushort queue_cnt;
  280. ushort entry_to_copy;
  281. ushort res;
  282. ASC_SG_LIST sg_list[];
  283. } ASC_SG_HEAD;
  284. typedef struct asc_scsi_q {
  285. ASC_SCSIQ_1 q1;
  286. ASC_SCSIQ_2 q2;
  287. uchar *cdbptr;
  288. ASC_SG_HEAD *sg_head;
  289. ushort remain_sg_entry_cnt;
  290. ushort next_sg_index;
  291. } ASC_SCSI_Q;
  292. typedef struct asc_scsi_bios_req_q {
  293. ASC_SCSIQ_1 r1;
  294. ASC_SCSIQ_2 r2;
  295. uchar *cdbptr;
  296. ASC_SG_HEAD *sg_head;
  297. uchar *sense_ptr;
  298. ASC_SCSIQ_3 r3;
  299. uchar cdb[ASC_MAX_CDB_LEN];
  300. uchar sense[ASC_MIN_SENSE_LEN];
  301. } ASC_SCSI_BIOS_REQ_Q;
  302. typedef struct asc_risc_q {
  303. uchar fwd;
  304. uchar bwd;
  305. ASC_SCSIQ_1 i1;
  306. ASC_SCSIQ_2 i2;
  307. ASC_SCSIQ_3 i3;
  308. ASC_SCSIQ_4 i4;
  309. } ASC_RISC_Q;
  310. typedef struct asc_sg_list_q {
  311. uchar seq_no;
  312. uchar q_no;
  313. uchar cntl;
  314. uchar sg_head_qp;
  315. uchar sg_list_cnt;
  316. uchar sg_cur_list_cnt;
  317. } ASC_SG_LIST_Q;
  318. typedef struct asc_risc_sg_list_q {
  319. uchar fwd;
  320. uchar bwd;
  321. ASC_SG_LIST_Q sg;
  322. ASC_SG_LIST sg_list[7];
  323. } ASC_RISC_SG_LIST_Q;
  324. #define ASCQ_ERR_Q_STATUS 0x0D
  325. #define ASCQ_ERR_CUR_QNG 0x17
  326. #define ASCQ_ERR_SG_Q_LINKS 0x18
  327. #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
  328. #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
  329. #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
  330. /*
  331. * Warning code values are set in ASC_DVC_VAR 'warn_code'.
  332. */
  333. #define ASC_WARN_NO_ERROR 0x0000
  334. #define ASC_WARN_IO_PORT_ROTATE 0x0001
  335. #define ASC_WARN_EEPROM_CHKSUM 0x0002
  336. #define ASC_WARN_IRQ_MODIFIED 0x0004
  337. #define ASC_WARN_AUTO_CONFIG 0x0008
  338. #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
  339. #define ASC_WARN_EEPROM_RECOVER 0x0020
  340. #define ASC_WARN_CFG_MSW_RECOVER 0x0040
  341. /*
  342. * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
  343. */
  344. #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
  345. #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
  346. #define ASC_IERR_SET_PC_ADDR 0x0004
  347. #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
  348. #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
  349. #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
  350. #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
  351. #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
  352. #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
  353. #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
  354. #define ASC_IERR_NO_BUS_TYPE 0x0400
  355. #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
  356. #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
  357. #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
  358. #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
  359. #define ASC_MIN_TAG_Q_PER_DVC (0x04)
  360. #define ASC_MIN_FREE_Q (0x02)
  361. #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
  362. #define ASC_MAX_TOTAL_QNG 240
  363. #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
  364. #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
  365. #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
  366. #define ASC_MAX_INRAM_TAG_QNG 16
  367. #define ASC_IOADR_GAP 0x10
  368. #define ASC_SYN_MAX_OFFSET 0x0F
  369. #define ASC_DEF_SDTR_OFFSET 0x0F
  370. #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
  371. #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
  372. /* The narrow chip only supports a limited selection of transfer rates.
  373. * These are encoded in the range 0..7 or 0..15 depending whether the chip
  374. * is Ultra-capable or not. These tables let us convert from one to the other.
  375. */
  376. static const unsigned char asc_syn_xfer_period[8] = {
  377. 25, 30, 35, 40, 50, 60, 70, 85
  378. };
  379. static const unsigned char asc_syn_ultra_xfer_period[16] = {
  380. 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
  381. };
  382. typedef struct ext_msg {
  383. uchar msg_type;
  384. uchar msg_len;
  385. uchar msg_req;
  386. union {
  387. struct {
  388. uchar sdtr_xfer_period;
  389. uchar sdtr_req_ack_offset;
  390. } sdtr;
  391. struct {
  392. uchar wdtr_width;
  393. } wdtr;
  394. struct {
  395. uchar mdp_b3;
  396. uchar mdp_b2;
  397. uchar mdp_b1;
  398. uchar mdp_b0;
  399. } mdp;
  400. } u_ext_msg;
  401. uchar res;
  402. } EXT_MSG;
  403. #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
  404. #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
  405. #define wdtr_width u_ext_msg.wdtr.wdtr_width
  406. #define mdp_b3 u_ext_msg.mdp_b3
  407. #define mdp_b2 u_ext_msg.mdp_b2
  408. #define mdp_b1 u_ext_msg.mdp_b1
  409. #define mdp_b0 u_ext_msg.mdp_b0
  410. typedef struct asc_dvc_cfg {
  411. ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
  412. ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
  413. ASC_SCSI_BIT_ID_TYPE disc_enable;
  414. ASC_SCSI_BIT_ID_TYPE sdtr_enable;
  415. uchar chip_scsi_id;
  416. uchar chip_version;
  417. ushort mcode_date;
  418. ushort mcode_version;
  419. uchar max_tag_qng[ASC_MAX_TID + 1];
  420. uchar sdtr_period_offset[ASC_MAX_TID + 1];
  421. uchar adapter_info[6];
  422. } ASC_DVC_CFG;
  423. #define ASC_DEF_DVC_CNTL 0xFFFF
  424. #define ASC_DEF_CHIP_SCSI_ID 7
  425. #define ASC_DEF_ISA_DMA_SPEED 4
  426. #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
  427. #define ASC_INIT_STATE_END_GET_CFG 0x0002
  428. #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
  429. #define ASC_INIT_STATE_END_SET_CFG 0x0008
  430. #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
  431. #define ASC_INIT_STATE_END_LOAD_MC 0x0020
  432. #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
  433. #define ASC_INIT_STATE_END_INQUIRY 0x0080
  434. #define ASC_INIT_RESET_SCSI_DONE 0x0100
  435. #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
  436. #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
  437. #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
  438. #define ASC_MIN_TAGGED_CMD 7
  439. #define ASC_MAX_SCSI_RESET_WAIT 30
  440. #define ASC_OVERRUN_BSIZE 64
  441. struct asc_dvc_var; /* Forward Declaration. */
  442. typedef struct asc_dvc_var {
  443. PortAddr iop_base;
  444. ushort err_code;
  445. ushort dvc_cntl;
  446. ushort bug_fix_cntl;
  447. ushort bus_type;
  448. ASC_SCSI_BIT_ID_TYPE init_sdtr;
  449. ASC_SCSI_BIT_ID_TYPE sdtr_done;
  450. ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
  451. ASC_SCSI_BIT_ID_TYPE unit_not_ready;
  452. ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
  453. ASC_SCSI_BIT_ID_TYPE start_motor;
  454. uchar *overrun_buf;
  455. dma_addr_t overrun_dma;
  456. uchar scsi_reset_wait;
  457. uchar chip_no;
  458. bool is_in_int;
  459. uchar max_total_qng;
  460. uchar cur_total_qng;
  461. uchar in_critical_cnt;
  462. uchar last_q_shortage;
  463. ushort init_state;
  464. uchar cur_dvc_qng[ASC_MAX_TID + 1];
  465. uchar max_dvc_qng[ASC_MAX_TID + 1];
  466. ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
  467. ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
  468. const uchar *sdtr_period_tbl;
  469. ASC_DVC_CFG *cfg;
  470. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
  471. char redo_scam;
  472. ushort res2;
  473. uchar dos_int13_table[ASC_MAX_TID + 1];
  474. unsigned int max_dma_count;
  475. ASC_SCSI_BIT_ID_TYPE no_scam;
  476. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
  477. uchar min_sdtr_index;
  478. uchar max_sdtr_index;
  479. struct asc_board *drv_ptr;
  480. unsigned int uc_break;
  481. } ASC_DVC_VAR;
  482. typedef struct asc_dvc_inq_info {
  483. uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  484. } ASC_DVC_INQ_INFO;
  485. typedef struct asc_cap_info {
  486. u32 lba;
  487. u32 blk_size;
  488. } ASC_CAP_INFO;
  489. typedef struct asc_cap_info_array {
  490. ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  491. } ASC_CAP_INFO_ARRAY;
  492. #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
  493. #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
  494. #define ASC_CNTL_INITIATOR (ushort)0x0001
  495. #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
  496. #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
  497. #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
  498. #define ASC_CNTL_NO_SCAM (ushort)0x0010
  499. #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
  500. #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
  501. #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
  502. #define ASC_CNTL_RESET_SCSI (ushort)0x0200
  503. #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
  504. #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
  505. #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
  506. #define ASC_CNTL_BURST_MODE (ushort)0x2000
  507. #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
  508. #define ASC_EEP_DVC_CFG_BEG_VL 2
  509. #define ASC_EEP_MAX_DVC_ADDR_VL 15
  510. #define ASC_EEP_DVC_CFG_BEG 32
  511. #define ASC_EEP_MAX_DVC_ADDR 45
  512. #define ASC_EEP_MAX_RETRY 20
  513. /*
  514. * These macros keep the chip SCSI id bitfields in board order. C bitfields
  515. * aren't portable between big and little-endian platforms so they are not used.
  516. */
  517. #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
  518. #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
  519. #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
  520. ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
  521. #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
  522. ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
  523. typedef struct asceep_config {
  524. ushort cfg_lsw;
  525. ushort cfg_msw;
  526. uchar init_sdtr;
  527. uchar disc_enable;
  528. uchar use_cmd_qng;
  529. uchar start_motor;
  530. uchar max_total_qng;
  531. uchar max_tag_qng;
  532. uchar bios_scan;
  533. uchar power_up_wait;
  534. uchar no_scam;
  535. uchar id_speed; /* low order 4 bits is chip scsi id */
  536. /* high order 4 bits is isa dma speed */
  537. uchar dos_int13_table[ASC_MAX_TID + 1];
  538. uchar adapter_info[6];
  539. ushort cntl;
  540. ushort chksum;
  541. } ASCEEP_CONFIG;
  542. #define ASC_EEP_CMD_READ 0x80
  543. #define ASC_EEP_CMD_WRITE 0x40
  544. #define ASC_EEP_CMD_WRITE_ABLE 0x30
  545. #define ASC_EEP_CMD_WRITE_DISABLE 0x00
  546. #define ASCV_MSGOUT_BEG 0x0000
  547. #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
  548. #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
  549. #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
  550. #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
  551. #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
  552. #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
  553. #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
  554. #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
  555. #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
  556. #define ASCV_BREAK_ADDR (ushort)0x0028
  557. #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
  558. #define ASCV_BREAK_CONTROL (ushort)0x002C
  559. #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
  560. #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
  561. #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
  562. #define ASCV_MCODE_SIZE_W (ushort)0x0034
  563. #define ASCV_STOP_CODE_B (ushort)0x0036
  564. #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
  565. #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
  566. #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
  567. #define ASCV_HALTCODE_W (ushort)0x0040
  568. #define ASCV_CHKSUM_W (ushort)0x0042
  569. #define ASCV_MC_DATE_W (ushort)0x0044
  570. #define ASCV_MC_VER_W (ushort)0x0046
  571. #define ASCV_NEXTRDY_B (ushort)0x0048
  572. #define ASCV_DONENEXT_B (ushort)0x0049
  573. #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
  574. #define ASCV_SCSIBUSY_B (ushort)0x004B
  575. #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
  576. #define ASCV_CURCDB_B (ushort)0x004D
  577. #define ASCV_RCLUN_B (ushort)0x004E
  578. #define ASCV_BUSY_QHEAD_B (ushort)0x004F
  579. #define ASCV_DISC1_QHEAD_B (ushort)0x0050
  580. #define ASCV_DISC_ENABLE_B (ushort)0x0052
  581. #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
  582. #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
  583. #define ASCV_MCODE_CNTL_B (ushort)0x0056
  584. #define ASCV_NULL_TARGET_B (ushort)0x0057
  585. #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
  586. #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
  587. #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
  588. #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
  589. #define ASCV_HOST_FLAG_B (ushort)0x005D
  590. #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
  591. #define ASCV_VER_SERIAL_B (ushort)0x0065
  592. #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
  593. #define ASCV_WTM_FLAG_B (ushort)0x0068
  594. #define ASCV_RISC_FLAG_B (ushort)0x006A
  595. #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
  596. #define ASC_HOST_FLAG_IN_ISR 0x01
  597. #define ASC_HOST_FLAG_ACK_INT 0x02
  598. #define ASC_RISC_FLAG_GEN_INT 0x01
  599. #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
  600. #define IOP_CTRL (0x0F)
  601. #define IOP_STATUS (0x0E)
  602. #define IOP_INT_ACK IOP_STATUS
  603. #define IOP_REG_IFC (0x0D)
  604. #define IOP_SYN_OFFSET (0x0B)
  605. #define IOP_EXTRA_CONTROL (0x0D)
  606. #define IOP_REG_PC (0x0C)
  607. #define IOP_RAM_ADDR (0x0A)
  608. #define IOP_RAM_DATA (0x08)
  609. #define IOP_EEP_DATA (0x06)
  610. #define IOP_EEP_CMD (0x07)
  611. #define IOP_VERSION (0x03)
  612. #define IOP_CONFIG_HIGH (0x04)
  613. #define IOP_CONFIG_LOW (0x02)
  614. #define IOP_SIG_BYTE (0x01)
  615. #define IOP_SIG_WORD (0x00)
  616. #define IOP_REG_DC1 (0x0E)
  617. #define IOP_REG_DC0 (0x0C)
  618. #define IOP_REG_SB (0x0B)
  619. #define IOP_REG_DA1 (0x0A)
  620. #define IOP_REG_DA0 (0x08)
  621. #define IOP_REG_SC (0x09)
  622. #define IOP_DMA_SPEED (0x07)
  623. #define IOP_REG_FLAG (0x07)
  624. #define IOP_FIFO_H (0x06)
  625. #define IOP_FIFO_L (0x04)
  626. #define IOP_REG_ID (0x05)
  627. #define IOP_REG_QP (0x03)
  628. #define IOP_REG_IH (0x02)
  629. #define IOP_REG_IX (0x01)
  630. #define IOP_REG_AX (0x00)
  631. #define IFC_REG_LOCK (0x00)
  632. #define IFC_REG_UNLOCK (0x09)
  633. #define IFC_WR_EN_FILTER (0x10)
  634. #define IFC_RD_NO_EEPROM (0x10)
  635. #define IFC_SLEW_RATE (0x20)
  636. #define IFC_ACT_NEG (0x40)
  637. #define IFC_INP_FILTER (0x80)
  638. #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
  639. #define SC_SEL (uchar)(0x80)
  640. #define SC_BSY (uchar)(0x40)
  641. #define SC_ACK (uchar)(0x20)
  642. #define SC_REQ (uchar)(0x10)
  643. #define SC_ATN (uchar)(0x08)
  644. #define SC_IO (uchar)(0x04)
  645. #define SC_CD (uchar)(0x02)
  646. #define SC_MSG (uchar)(0x01)
  647. #define SEC_SCSI_CTL (uchar)(0x80)
  648. #define SEC_ACTIVE_NEGATE (uchar)(0x40)
  649. #define SEC_SLEW_RATE (uchar)(0x20)
  650. #define SEC_ENABLE_FILTER (uchar)(0x10)
  651. #define ASC_HALT_EXTMSG_IN (ushort)0x8000
  652. #define ASC_HALT_CHK_CONDITION (ushort)0x8100
  653. #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
  654. #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
  655. #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
  656. #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
  657. #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
  658. #define ASC_MAX_QNO 0xF8
  659. #define ASC_DATA_SEC_BEG (ushort)0x0080
  660. #define ASC_DATA_SEC_END (ushort)0x0080
  661. #define ASC_CODE_SEC_BEG (ushort)0x0080
  662. #define ASC_CODE_SEC_END (ushort)0x0080
  663. #define ASC_QADR_BEG (0x4000)
  664. #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
  665. #define ASC_QADR_END (ushort)0x7FFF
  666. #define ASC_QLAST_ADR (ushort)0x7FC0
  667. #define ASC_QBLK_SIZE 0x40
  668. #define ASC_BIOS_DATA_QBEG 0xF8
  669. #define ASC_MIN_ACTIVE_QNO 0x01
  670. #define ASC_QLINK_END 0xFF
  671. #define ASC_EEPROM_WORDS 0x10
  672. #define ASC_MAX_MGS_LEN 0x10
  673. #define ASC_BIOS_ADDR_DEF 0xDC00
  674. #define ASC_BIOS_SIZE 0x3800
  675. #define ASC_BIOS_RAM_OFF 0x3800
  676. #define ASC_BIOS_RAM_SIZE 0x800
  677. #define ASC_BIOS_MIN_ADDR 0xC000
  678. #define ASC_BIOS_MAX_ADDR 0xEC00
  679. #define ASC_BIOS_BANK_SIZE 0x0400
  680. #define ASC_MCODE_START_ADDR 0x0080
  681. #define ASC_CFG0_HOST_INT_ON 0x0020
  682. #define ASC_CFG0_BIOS_ON 0x0040
  683. #define ASC_CFG0_VERA_BURST_ON 0x0080
  684. #define ASC_CFG0_SCSI_PARITY_ON 0x0800
  685. #define ASC_CFG1_SCSI_TARGET_ON 0x0080
  686. #define ASC_CFG1_LRAM_8BITS_ON 0x0800
  687. #define ASC_CFG_MSW_CLR_MASK 0x3080
  688. #define CSW_TEST1 (ASC_CS_TYPE)0x8000
  689. #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
  690. #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
  691. #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
  692. #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
  693. #define CSW_TEST2 (ASC_CS_TYPE)0x0400
  694. #define CSW_TEST3 (ASC_CS_TYPE)0x0200
  695. #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
  696. #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
  697. #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
  698. #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
  699. #define CSW_HALTED (ASC_CS_TYPE)0x0010
  700. #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
  701. #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
  702. #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
  703. #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
  704. #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
  705. #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
  706. #define CIW_TEST1 (ASC_CS_TYPE)0x0200
  707. #define CIW_TEST2 (ASC_CS_TYPE)0x0400
  708. #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
  709. #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
  710. #define CC_CHIP_RESET (uchar)0x80
  711. #define CC_SCSI_RESET (uchar)0x40
  712. #define CC_HALT (uchar)0x20
  713. #define CC_SINGLE_STEP (uchar)0x10
  714. #define CC_DMA_ABLE (uchar)0x08
  715. #define CC_TEST (uchar)0x04
  716. #define CC_BANK_ONE (uchar)0x02
  717. #define CC_DIAG (uchar)0x01
  718. #define ASC_1000_ID0W 0x04C1
  719. #define ASC_1000_ID0W_FIX 0x00C1
  720. #define ASC_1000_ID1B 0x25
  721. #define ASC_EISA_REV_IOP_MASK (0x0C83)
  722. #define ASC_EISA_CFG_IOP_MASK (0x0C86)
  723. #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
  724. #define INS_HALTINT (ushort)0x6281
  725. #define INS_HALT (ushort)0x6280
  726. #define INS_SINT (ushort)0x6200
  727. #define INS_RFLAG_WTM (ushort)0x7380
  728. #define ASC_MC_SAVE_CODE_WSIZE 0x500
  729. #define ASC_MC_SAVE_DATA_WSIZE 0x40
  730. typedef struct asc_mc_saved {
  731. ushort data[ASC_MC_SAVE_DATA_WSIZE];
  732. ushort code[ASC_MC_SAVE_CODE_WSIZE];
  733. } ASC_MC_SAVED;
  734. #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
  735. #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
  736. #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
  737. #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
  738. #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
  739. #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
  740. #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
  741. #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
  742. #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
  743. #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
  744. #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
  745. #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
  746. #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
  747. #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
  748. #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
  749. #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
  750. #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
  751. #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
  752. #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
  753. #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
  754. #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
  755. #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
  756. #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
  757. #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
  758. #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
  759. #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
  760. #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
  761. #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
  762. #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
  763. #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
  764. #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
  765. #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
  766. #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
  767. #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
  768. #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
  769. #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
  770. #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
  771. #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
  772. #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
  773. #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
  774. #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
  775. #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
  776. #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
  777. #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
  778. #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
  779. #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
  780. #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
  781. #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
  782. #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
  783. #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
  784. #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
  785. #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
  786. #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
  787. #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
  788. #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
  789. #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
  790. #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
  791. #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
  792. #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
  793. #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
  794. #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
  795. #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
  796. #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
  797. #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
  798. #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
  799. #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
  800. #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
  801. #define AdvPortAddr void __iomem * /* Virtual memory address size */
  802. /*
  803. * Define Adv Library required memory access macros.
  804. */
  805. #define ADV_MEM_READB(addr) readb(addr)
  806. #define ADV_MEM_READW(addr) readw(addr)
  807. #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
  808. #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
  809. #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
  810. /*
  811. * Define total number of simultaneous maximum element scatter-gather
  812. * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
  813. * maximum number of outstanding commands per wide host adapter. Each
  814. * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
  815. * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
  816. * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
  817. * structures or 255 scatter-gather elements.
  818. */
  819. #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
  820. /*
  821. * Define maximum number of scatter-gather elements per request.
  822. */
  823. #define ADV_MAX_SG_LIST 255
  824. #define NO_OF_SG_PER_BLOCK 15
  825. #define ADV_EEP_DVC_CFG_BEGIN (0x00)
  826. #define ADV_EEP_DVC_CFG_END (0x15)
  827. #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
  828. #define ADV_EEP_MAX_WORD_ADDR (0x1E)
  829. #define ADV_EEP_DELAY_MS 100
  830. #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
  831. #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
  832. /*
  833. * For the ASC3550 Bit 13 is Termination Polarity control bit.
  834. * For later ICs Bit 13 controls whether the CIS (Card Information
  835. * Service Section) is loaded from EEPROM.
  836. */
  837. #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
  838. #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
  839. /*
  840. * ASC38C1600 Bit 11
  841. *
  842. * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
  843. * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
  844. * Function 0 will specify INT B.
  845. *
  846. * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
  847. * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
  848. * Function 1 will specify INT A.
  849. */
  850. #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
  851. typedef struct adveep_3550_config {
  852. /* Word Offset, Description */
  853. ushort cfg_lsw; /* 00 power up initialization */
  854. /* bit 13 set - Term Polarity Control */
  855. /* bit 14 set - BIOS Enable */
  856. /* bit 15 set - Big Endian Mode */
  857. ushort cfg_msw; /* 01 unused */
  858. ushort disc_enable; /* 02 disconnect enable */
  859. ushort wdtr_able; /* 03 Wide DTR able */
  860. ushort sdtr_able; /* 04 Synchronous DTR able */
  861. ushort start_motor; /* 05 send start up motor */
  862. ushort tagqng_able; /* 06 tag queuing able */
  863. ushort bios_scan; /* 07 BIOS device control */
  864. ushort scam_tolerant; /* 08 no scam */
  865. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  866. uchar bios_boot_delay; /* power up wait */
  867. uchar scsi_reset_delay; /* 10 reset delay */
  868. uchar bios_id_lun; /* first boot device scsi id & lun */
  869. /* high nibble is lun */
  870. /* low nibble is scsi id */
  871. uchar termination; /* 11 0 - automatic */
  872. /* 1 - low off / high off */
  873. /* 2 - low off / high on */
  874. /* 3 - low on / high on */
  875. /* There is no low on / high off */
  876. uchar reserved1; /* reserved byte (not used) */
  877. ushort bios_ctrl; /* 12 BIOS control bits */
  878. /* bit 0 BIOS don't act as initiator. */
  879. /* bit 1 BIOS > 1 GB support */
  880. /* bit 2 BIOS > 2 Disk Support */
  881. /* bit 3 BIOS don't support removables */
  882. /* bit 4 BIOS support bootable CD */
  883. /* bit 5 BIOS scan enabled */
  884. /* bit 6 BIOS support multiple LUNs */
  885. /* bit 7 BIOS display of message */
  886. /* bit 8 SCAM disabled */
  887. /* bit 9 Reset SCSI bus during init. */
  888. /* bit 10 */
  889. /* bit 11 No verbose initialization. */
  890. /* bit 12 SCSI parity enabled */
  891. /* bit 13 */
  892. /* bit 14 */
  893. /* bit 15 */
  894. ushort ultra_able; /* 13 ULTRA speed able */
  895. ushort reserved2; /* 14 reserved */
  896. uchar max_host_qng; /* 15 maximum host queuing */
  897. uchar max_dvc_qng; /* maximum per device queuing */
  898. ushort dvc_cntl; /* 16 control bit for driver */
  899. ushort bug_fix; /* 17 control bit for bug fix */
  900. ushort serial_number_word1; /* 18 Board serial number word 1 */
  901. ushort serial_number_word2; /* 19 Board serial number word 2 */
  902. ushort serial_number_word3; /* 20 Board serial number word 3 */
  903. ushort check_sum; /* 21 EEP check sum */
  904. uchar oem_name[16]; /* 22 OEM name */
  905. ushort dvc_err_code; /* 30 last device driver error code */
  906. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  907. ushort adv_err_addr; /* 32 last uc error address */
  908. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  909. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  910. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  911. ushort num_of_err; /* 36 number of error */
  912. } ADVEEP_3550_CONFIG;
  913. typedef struct adveep_38C0800_config {
  914. /* Word Offset, Description */
  915. ushort cfg_lsw; /* 00 power up initialization */
  916. /* bit 13 set - Load CIS */
  917. /* bit 14 set - BIOS Enable */
  918. /* bit 15 set - Big Endian Mode */
  919. ushort cfg_msw; /* 01 unused */
  920. ushort disc_enable; /* 02 disconnect enable */
  921. ushort wdtr_able; /* 03 Wide DTR able */
  922. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  923. ushort start_motor; /* 05 send start up motor */
  924. ushort tagqng_able; /* 06 tag queuing able */
  925. ushort bios_scan; /* 07 BIOS device control */
  926. ushort scam_tolerant; /* 08 no scam */
  927. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  928. uchar bios_boot_delay; /* power up wait */
  929. uchar scsi_reset_delay; /* 10 reset delay */
  930. uchar bios_id_lun; /* first boot device scsi id & lun */
  931. /* high nibble is lun */
  932. /* low nibble is scsi id */
  933. uchar termination_se; /* 11 0 - automatic */
  934. /* 1 - low off / high off */
  935. /* 2 - low off / high on */
  936. /* 3 - low on / high on */
  937. /* There is no low on / high off */
  938. uchar termination_lvd; /* 11 0 - automatic */
  939. /* 1 - low off / high off */
  940. /* 2 - low off / high on */
  941. /* 3 - low on / high on */
  942. /* There is no low on / high off */
  943. ushort bios_ctrl; /* 12 BIOS control bits */
  944. /* bit 0 BIOS don't act as initiator. */
  945. /* bit 1 BIOS > 1 GB support */
  946. /* bit 2 BIOS > 2 Disk Support */
  947. /* bit 3 BIOS don't support removables */
  948. /* bit 4 BIOS support bootable CD */
  949. /* bit 5 BIOS scan enabled */
  950. /* bit 6 BIOS support multiple LUNs */
  951. /* bit 7 BIOS display of message */
  952. /* bit 8 SCAM disabled */
  953. /* bit 9 Reset SCSI bus during init. */
  954. /* bit 10 */
  955. /* bit 11 No verbose initialization. */
  956. /* bit 12 SCSI parity enabled */
  957. /* bit 13 */
  958. /* bit 14 */
  959. /* bit 15 */
  960. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  961. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  962. uchar max_host_qng; /* 15 maximum host queueing */
  963. uchar max_dvc_qng; /* maximum per device queuing */
  964. ushort dvc_cntl; /* 16 control bit for driver */
  965. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  966. ushort serial_number_word1; /* 18 Board serial number word 1 */
  967. ushort serial_number_word2; /* 19 Board serial number word 2 */
  968. ushort serial_number_word3; /* 20 Board serial number word 3 */
  969. ushort check_sum; /* 21 EEP check sum */
  970. uchar oem_name[16]; /* 22 OEM name */
  971. ushort dvc_err_code; /* 30 last device driver error code */
  972. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  973. ushort adv_err_addr; /* 32 last uc error address */
  974. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  975. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  976. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  977. ushort reserved36; /* 36 reserved */
  978. ushort reserved37; /* 37 reserved */
  979. ushort reserved38; /* 38 reserved */
  980. ushort reserved39; /* 39 reserved */
  981. ushort reserved40; /* 40 reserved */
  982. ushort reserved41; /* 41 reserved */
  983. ushort reserved42; /* 42 reserved */
  984. ushort reserved43; /* 43 reserved */
  985. ushort reserved44; /* 44 reserved */
  986. ushort reserved45; /* 45 reserved */
  987. ushort reserved46; /* 46 reserved */
  988. ushort reserved47; /* 47 reserved */
  989. ushort reserved48; /* 48 reserved */
  990. ushort reserved49; /* 49 reserved */
  991. ushort reserved50; /* 50 reserved */
  992. ushort reserved51; /* 51 reserved */
  993. ushort reserved52; /* 52 reserved */
  994. ushort reserved53; /* 53 reserved */
  995. ushort reserved54; /* 54 reserved */
  996. ushort reserved55; /* 55 reserved */
  997. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  998. ushort cisprt_msw; /* 57 CIS PTR MSW */
  999. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1000. ushort subsysid; /* 59 SubSystem ID */
  1001. ushort reserved60; /* 60 reserved */
  1002. ushort reserved61; /* 61 reserved */
  1003. ushort reserved62; /* 62 reserved */
  1004. ushort reserved63; /* 63 reserved */
  1005. } ADVEEP_38C0800_CONFIG;
  1006. typedef struct adveep_38C1600_config {
  1007. /* Word Offset, Description */
  1008. ushort cfg_lsw; /* 00 power up initialization */
  1009. /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
  1010. /* clear - Func. 0 INTA, Func. 1 INTB */
  1011. /* bit 13 set - Load CIS */
  1012. /* bit 14 set - BIOS Enable */
  1013. /* bit 15 set - Big Endian Mode */
  1014. ushort cfg_msw; /* 01 unused */
  1015. ushort disc_enable; /* 02 disconnect enable */
  1016. ushort wdtr_able; /* 03 Wide DTR able */
  1017. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1018. ushort start_motor; /* 05 send start up motor */
  1019. ushort tagqng_able; /* 06 tag queuing able */
  1020. ushort bios_scan; /* 07 BIOS device control */
  1021. ushort scam_tolerant; /* 08 no scam */
  1022. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1023. uchar bios_boot_delay; /* power up wait */
  1024. uchar scsi_reset_delay; /* 10 reset delay */
  1025. uchar bios_id_lun; /* first boot device scsi id & lun */
  1026. /* high nibble is lun */
  1027. /* low nibble is scsi id */
  1028. uchar termination_se; /* 11 0 - automatic */
  1029. /* 1 - low off / high off */
  1030. /* 2 - low off / high on */
  1031. /* 3 - low on / high on */
  1032. /* There is no low on / high off */
  1033. uchar termination_lvd; /* 11 0 - automatic */
  1034. /* 1 - low off / high off */
  1035. /* 2 - low off / high on */
  1036. /* 3 - low on / high on */
  1037. /* There is no low on / high off */
  1038. ushort bios_ctrl; /* 12 BIOS control bits */
  1039. /* bit 0 BIOS don't act as initiator. */
  1040. /* bit 1 BIOS > 1 GB support */
  1041. /* bit 2 BIOS > 2 Disk Support */
  1042. /* bit 3 BIOS don't support removables */
  1043. /* bit 4 BIOS support bootable CD */
  1044. /* bit 5 BIOS scan enabled */
  1045. /* bit 6 BIOS support multiple LUNs */
  1046. /* bit 7 BIOS display of message */
  1047. /* bit 8 SCAM disabled */
  1048. /* bit 9 Reset SCSI bus during init. */
  1049. /* bit 10 Basic Integrity Checking disabled */
  1050. /* bit 11 No verbose initialization. */
  1051. /* bit 12 SCSI parity enabled */
  1052. /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
  1053. /* bit 14 */
  1054. /* bit 15 */
  1055. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1056. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1057. uchar max_host_qng; /* 15 maximum host queueing */
  1058. uchar max_dvc_qng; /* maximum per device queuing */
  1059. ushort dvc_cntl; /* 16 control bit for driver */
  1060. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1061. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1062. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1063. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1064. ushort check_sum; /* 21 EEP check sum */
  1065. uchar oem_name[16]; /* 22 OEM name */
  1066. ushort dvc_err_code; /* 30 last device driver error code */
  1067. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1068. ushort adv_err_addr; /* 32 last uc error address */
  1069. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1070. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1071. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1072. ushort reserved36; /* 36 reserved */
  1073. ushort reserved37; /* 37 reserved */
  1074. ushort reserved38; /* 38 reserved */
  1075. ushort reserved39; /* 39 reserved */
  1076. ushort reserved40; /* 40 reserved */
  1077. ushort reserved41; /* 41 reserved */
  1078. ushort reserved42; /* 42 reserved */
  1079. ushort reserved43; /* 43 reserved */
  1080. ushort reserved44; /* 44 reserved */
  1081. ushort reserved45; /* 45 reserved */
  1082. ushort reserved46; /* 46 reserved */
  1083. ushort reserved47; /* 47 reserved */
  1084. ushort reserved48; /* 48 reserved */
  1085. ushort reserved49; /* 49 reserved */
  1086. ushort reserved50; /* 50 reserved */
  1087. ushort reserved51; /* 51 reserved */
  1088. ushort reserved52; /* 52 reserved */
  1089. ushort reserved53; /* 53 reserved */
  1090. ushort reserved54; /* 54 reserved */
  1091. ushort reserved55; /* 55 reserved */
  1092. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1093. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1094. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1095. ushort subsysid; /* 59 SubSystem ID */
  1096. ushort reserved60; /* 60 reserved */
  1097. ushort reserved61; /* 61 reserved */
  1098. ushort reserved62; /* 62 reserved */
  1099. ushort reserved63; /* 63 reserved */
  1100. } ADVEEP_38C1600_CONFIG;
  1101. /*
  1102. * EEPROM Commands
  1103. */
  1104. #define ASC_EEP_CMD_DONE 0x0200
  1105. /* bios_ctrl */
  1106. #define BIOS_CTRL_BIOS 0x0001
  1107. #define BIOS_CTRL_EXTENDED_XLAT 0x0002
  1108. #define BIOS_CTRL_GT_2_DISK 0x0004
  1109. #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
  1110. #define BIOS_CTRL_BOOTABLE_CD 0x0010
  1111. #define BIOS_CTRL_MULTIPLE_LUN 0x0040
  1112. #define BIOS_CTRL_DISPLAY_MSG 0x0080
  1113. #define BIOS_CTRL_NO_SCAM 0x0100
  1114. #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
  1115. #define BIOS_CTRL_INIT_VERBOSE 0x0800
  1116. #define BIOS_CTRL_SCSI_PARITY 0x1000
  1117. #define BIOS_CTRL_AIPP_DIS 0x2000
  1118. #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
  1119. #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1120. /*
  1121. * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
  1122. * a special 16K Adv Library and Microcode version. After the issue is
  1123. * resolved, should restore 32K support.
  1124. *
  1125. * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
  1126. */
  1127. #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1128. /*
  1129. * Byte I/O register address from base of 'iop_base'.
  1130. */
  1131. #define IOPB_INTR_STATUS_REG 0x00
  1132. #define IOPB_CHIP_ID_1 0x01
  1133. #define IOPB_INTR_ENABLES 0x02
  1134. #define IOPB_CHIP_TYPE_REV 0x03
  1135. #define IOPB_RES_ADDR_4 0x04
  1136. #define IOPB_RES_ADDR_5 0x05
  1137. #define IOPB_RAM_DATA 0x06
  1138. #define IOPB_RES_ADDR_7 0x07
  1139. #define IOPB_FLAG_REG 0x08
  1140. #define IOPB_RES_ADDR_9 0x09
  1141. #define IOPB_RISC_CSR 0x0A
  1142. #define IOPB_RES_ADDR_B 0x0B
  1143. #define IOPB_RES_ADDR_C 0x0C
  1144. #define IOPB_RES_ADDR_D 0x0D
  1145. #define IOPB_SOFT_OVER_WR 0x0E
  1146. #define IOPB_RES_ADDR_F 0x0F
  1147. #define IOPB_MEM_CFG 0x10
  1148. #define IOPB_RES_ADDR_11 0x11
  1149. #define IOPB_GPIO_DATA 0x12
  1150. #define IOPB_RES_ADDR_13 0x13
  1151. #define IOPB_FLASH_PAGE 0x14
  1152. #define IOPB_RES_ADDR_15 0x15
  1153. #define IOPB_GPIO_CNTL 0x16
  1154. #define IOPB_RES_ADDR_17 0x17
  1155. #define IOPB_FLASH_DATA 0x18
  1156. #define IOPB_RES_ADDR_19 0x19
  1157. #define IOPB_RES_ADDR_1A 0x1A
  1158. #define IOPB_RES_ADDR_1B 0x1B
  1159. #define IOPB_RES_ADDR_1C 0x1C
  1160. #define IOPB_RES_ADDR_1D 0x1D
  1161. #define IOPB_RES_ADDR_1E 0x1E
  1162. #define IOPB_RES_ADDR_1F 0x1F
  1163. #define IOPB_DMA_CFG0 0x20
  1164. #define IOPB_DMA_CFG1 0x21
  1165. #define IOPB_TICKLE 0x22
  1166. #define IOPB_DMA_REG_WR 0x23
  1167. #define IOPB_SDMA_STATUS 0x24
  1168. #define IOPB_SCSI_BYTE_CNT 0x25
  1169. #define IOPB_HOST_BYTE_CNT 0x26
  1170. #define IOPB_BYTE_LEFT_TO_XFER 0x27
  1171. #define IOPB_BYTE_TO_XFER_0 0x28
  1172. #define IOPB_BYTE_TO_XFER_1 0x29
  1173. #define IOPB_BYTE_TO_XFER_2 0x2A
  1174. #define IOPB_BYTE_TO_XFER_3 0x2B
  1175. #define IOPB_ACC_GRP 0x2C
  1176. #define IOPB_RES_ADDR_2D 0x2D
  1177. #define IOPB_DEV_ID 0x2E
  1178. #define IOPB_RES_ADDR_2F 0x2F
  1179. #define IOPB_SCSI_DATA 0x30
  1180. #define IOPB_RES_ADDR_31 0x31
  1181. #define IOPB_RES_ADDR_32 0x32
  1182. #define IOPB_SCSI_DATA_HSHK 0x33
  1183. #define IOPB_SCSI_CTRL 0x34
  1184. #define IOPB_RES_ADDR_35 0x35
  1185. #define IOPB_RES_ADDR_36 0x36
  1186. #define IOPB_RES_ADDR_37 0x37
  1187. #define IOPB_RAM_BIST 0x38
  1188. #define IOPB_PLL_TEST 0x39
  1189. #define IOPB_PCI_INT_CFG 0x3A
  1190. #define IOPB_RES_ADDR_3B 0x3B
  1191. #define IOPB_RFIFO_CNT 0x3C
  1192. #define IOPB_RES_ADDR_3D 0x3D
  1193. #define IOPB_RES_ADDR_3E 0x3E
  1194. #define IOPB_RES_ADDR_3F 0x3F
  1195. /*
  1196. * Word I/O register address from base of 'iop_base'.
  1197. */
  1198. #define IOPW_CHIP_ID_0 0x00 /* CID0 */
  1199. #define IOPW_CTRL_REG 0x02 /* CC */
  1200. #define IOPW_RAM_ADDR 0x04 /* LA */
  1201. #define IOPW_RAM_DATA 0x06 /* LD */
  1202. #define IOPW_RES_ADDR_08 0x08
  1203. #define IOPW_RISC_CSR 0x0A /* CSR */
  1204. #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
  1205. #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
  1206. #define IOPW_RES_ADDR_10 0x10
  1207. #define IOPW_SEL_MASK 0x12 /* SM */
  1208. #define IOPW_RES_ADDR_14 0x14
  1209. #define IOPW_FLASH_ADDR 0x16 /* FA */
  1210. #define IOPW_RES_ADDR_18 0x18
  1211. #define IOPW_EE_CMD 0x1A /* EC */
  1212. #define IOPW_EE_DATA 0x1C /* ED */
  1213. #define IOPW_SFIFO_CNT 0x1E /* SFC */
  1214. #define IOPW_RES_ADDR_20 0x20
  1215. #define IOPW_Q_BASE 0x22 /* QB */
  1216. #define IOPW_QP 0x24 /* QP */
  1217. #define IOPW_IX 0x26 /* IX */
  1218. #define IOPW_SP 0x28 /* SP */
  1219. #define IOPW_PC 0x2A /* PC */
  1220. #define IOPW_RES_ADDR_2C 0x2C
  1221. #define IOPW_RES_ADDR_2E 0x2E
  1222. #define IOPW_SCSI_DATA 0x30 /* SD */
  1223. #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
  1224. #define IOPW_SCSI_CTRL 0x34 /* SC */
  1225. #define IOPW_HSHK_CFG 0x36 /* HCFG */
  1226. #define IOPW_SXFR_STATUS 0x36 /* SXS */
  1227. #define IOPW_SXFR_CNTL 0x38 /* SXL */
  1228. #define IOPW_SXFR_CNTH 0x3A /* SXH */
  1229. #define IOPW_RES_ADDR_3C 0x3C
  1230. #define IOPW_RFIFO_DATA 0x3E /* RFD */
  1231. /*
  1232. * Doubleword I/O register address from base of 'iop_base'.
  1233. */
  1234. #define IOPDW_RES_ADDR_0 0x00
  1235. #define IOPDW_RAM_DATA 0x04
  1236. #define IOPDW_RES_ADDR_8 0x08
  1237. #define IOPDW_RES_ADDR_C 0x0C
  1238. #define IOPDW_RES_ADDR_10 0x10
  1239. #define IOPDW_COMMA 0x14
  1240. #define IOPDW_COMMB 0x18
  1241. #define IOPDW_RES_ADDR_1C 0x1C
  1242. #define IOPDW_SDMA_ADDR0 0x20
  1243. #define IOPDW_SDMA_ADDR1 0x24
  1244. #define IOPDW_SDMA_COUNT 0x28
  1245. #define IOPDW_SDMA_ERROR 0x2C
  1246. #define IOPDW_RDMA_ADDR0 0x30
  1247. #define IOPDW_RDMA_ADDR1 0x34
  1248. #define IOPDW_RDMA_COUNT 0x38
  1249. #define IOPDW_RDMA_ERROR 0x3C
  1250. #define ADV_CHIP_ID_BYTE 0x25
  1251. #define ADV_CHIP_ID_WORD 0x04C1
  1252. #define ADV_INTR_ENABLE_HOST_INTR 0x01
  1253. #define ADV_INTR_ENABLE_SEL_INTR 0x02
  1254. #define ADV_INTR_ENABLE_DPR_INTR 0x04
  1255. #define ADV_INTR_ENABLE_RTA_INTR 0x08
  1256. #define ADV_INTR_ENABLE_RMA_INTR 0x10
  1257. #define ADV_INTR_ENABLE_RST_INTR 0x20
  1258. #define ADV_INTR_ENABLE_DPE_INTR 0x40
  1259. #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
  1260. #define ADV_INTR_STATUS_INTRA 0x01
  1261. #define ADV_INTR_STATUS_INTRB 0x02
  1262. #define ADV_INTR_STATUS_INTRC 0x04
  1263. #define ADV_RISC_CSR_STOP (0x0000)
  1264. #define ADV_RISC_TEST_COND (0x2000)
  1265. #define ADV_RISC_CSR_RUN (0x4000)
  1266. #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
  1267. #define ADV_CTRL_REG_HOST_INTR 0x0100
  1268. #define ADV_CTRL_REG_SEL_INTR 0x0200
  1269. #define ADV_CTRL_REG_DPR_INTR 0x0400
  1270. #define ADV_CTRL_REG_RTA_INTR 0x0800
  1271. #define ADV_CTRL_REG_RMA_INTR 0x1000
  1272. #define ADV_CTRL_REG_RES_BIT14 0x2000
  1273. #define ADV_CTRL_REG_DPE_INTR 0x4000
  1274. #define ADV_CTRL_REG_POWER_DONE 0x8000
  1275. #define ADV_CTRL_REG_ANY_INTR 0xFF00
  1276. #define ADV_CTRL_REG_CMD_RESET 0x00C6
  1277. #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
  1278. #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
  1279. #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
  1280. #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
  1281. #define ADV_TICKLE_NOP 0x00
  1282. #define ADV_TICKLE_A 0x01
  1283. #define ADV_TICKLE_B 0x02
  1284. #define ADV_TICKLE_C 0x03
  1285. #define AdvIsIntPending(port) \
  1286. (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
  1287. /*
  1288. * SCSI_CFG0 Register bit definitions
  1289. */
  1290. #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
  1291. #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
  1292. #define EVEN_PARITY 0x1000 /* Select Even Parity */
  1293. #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
  1294. #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
  1295. #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
  1296. #define SCAM_EN 0x0080 /* Enable SCAM selection */
  1297. #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
  1298. #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
  1299. #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
  1300. #define OUR_ID 0x000F /* SCSI ID */
  1301. /*
  1302. * SCSI_CFG1 Register bit definitions
  1303. */
  1304. #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
  1305. #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
  1306. #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
  1307. #define FILTER_SEL 0x0C00 /* Filter Period Selection */
  1308. #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
  1309. #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
  1310. #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
  1311. #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
  1312. #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
  1313. #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
  1314. #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
  1315. #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
  1316. #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
  1317. #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
  1318. #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
  1319. /*
  1320. * Addendum for ASC-38C0800 Chip
  1321. *
  1322. * The ASC-38C1600 Chip uses the same definitions except that the
  1323. * bus mode override bits [12:10] have been moved to byte register
  1324. * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
  1325. * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
  1326. * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
  1327. * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
  1328. * and [1:0]. Bits [14], [7:6], [3:2] are unused.
  1329. */
  1330. #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
  1331. #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
  1332. #define HVD 0x1000 /* HVD Device Detect */
  1333. #define LVD 0x0800 /* LVD Device Detect */
  1334. #define SE 0x0400 /* SE Device Detect */
  1335. #define TERM_LVD 0x00C0 /* LVD Termination Bits */
  1336. #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
  1337. #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
  1338. #define TERM_SE 0x0030 /* SE Termination Bits */
  1339. #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
  1340. #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
  1341. #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
  1342. #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
  1343. #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
  1344. #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
  1345. #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
  1346. #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
  1347. #define CABLE_ILLEGAL_A 0x7
  1348. /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
  1349. #define CABLE_ILLEGAL_B 0xB
  1350. /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
  1351. /*
  1352. * MEM_CFG Register bit definitions
  1353. */
  1354. #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
  1355. #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
  1356. #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
  1357. #define RAM_SZ_2KB 0x00 /* 2 KB */
  1358. #define RAM_SZ_4KB 0x04 /* 4 KB */
  1359. #define RAM_SZ_8KB 0x08 /* 8 KB */
  1360. #define RAM_SZ_16KB 0x0C /* 16 KB */
  1361. #define RAM_SZ_32KB 0x10 /* 32 KB */
  1362. #define RAM_SZ_64KB 0x14 /* 64 KB */
  1363. /*
  1364. * DMA_CFG0 Register bit definitions
  1365. *
  1366. * This register is only accessible to the host.
  1367. */
  1368. #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
  1369. #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
  1370. #define FIFO_THRESH_16B 0x00 /* 16 bytes */
  1371. #define FIFO_THRESH_32B 0x20 /* 32 bytes */
  1372. #define FIFO_THRESH_48B 0x30 /* 48 bytes */
  1373. #define FIFO_THRESH_64B 0x40 /* 64 bytes */
  1374. #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
  1375. #define FIFO_THRESH_96B 0x60 /* 96 bytes */
  1376. #define FIFO_THRESH_112B 0x70 /* 112 bytes */
  1377. #define START_CTL 0x0C /* DMA start conditions */
  1378. #define START_CTL_TH 0x00 /* Wait threshold level (default) */
  1379. #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
  1380. #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
  1381. #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
  1382. #define READ_CMD 0x03 /* Memory Read Method */
  1383. #define READ_CMD_MR 0x00 /* Memory Read */
  1384. #define READ_CMD_MRL 0x02 /* Memory Read Long */
  1385. #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
  1386. /*
  1387. * ASC-38C0800 RAM BIST Register bit definitions
  1388. */
  1389. #define RAM_TEST_MODE 0x80
  1390. #define PRE_TEST_MODE 0x40
  1391. #define NORMAL_MODE 0x00
  1392. #define RAM_TEST_DONE 0x10
  1393. #define RAM_TEST_STATUS 0x0F
  1394. #define RAM_TEST_HOST_ERROR 0x08
  1395. #define RAM_TEST_INTRAM_ERROR 0x04
  1396. #define RAM_TEST_RISC_ERROR 0x02
  1397. #define RAM_TEST_SCSI_ERROR 0x01
  1398. #define RAM_TEST_SUCCESS 0x00
  1399. #define PRE_TEST_VALUE 0x05
  1400. #define NORMAL_VALUE 0x00
  1401. /*
  1402. * ASC38C1600 Definitions
  1403. *
  1404. * IOPB_PCI_INT_CFG Bit Field Definitions
  1405. */
  1406. #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
  1407. /*
  1408. * Bit 1 can be set to change the interrupt for the Function to operate in
  1409. * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
  1410. * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
  1411. * mode, otherwise the operating mode is undefined.
  1412. */
  1413. #define TOTEMPOLE 0x02
  1414. /*
  1415. * Bit 0 can be used to change the Int Pin for the Function. The value is
  1416. * 0 by default for both Functions with Function 0 using INT A and Function
  1417. * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
  1418. * INT A is used.
  1419. *
  1420. * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
  1421. * value specified in the PCI Configuration Space.
  1422. */
  1423. #define INTAB 0x01
  1424. /*
  1425. * Adv Library Status Definitions
  1426. */
  1427. #define ADV_TRUE 1
  1428. #define ADV_FALSE 0
  1429. #define ADV_SUCCESS 1
  1430. #define ADV_BUSY 0
  1431. #define ADV_ERROR (-1)
  1432. /*
  1433. * ADV_DVC_VAR 'warn_code' values
  1434. */
  1435. #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
  1436. #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
  1437. #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
  1438. #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
  1439. #define ADV_MAX_TID 15 /* max. target identifier */
  1440. #define ADV_MAX_LUN 7 /* max. logical unit number */
  1441. /*
  1442. * Fixed locations of microcode operating variables.
  1443. */
  1444. #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
  1445. #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
  1446. #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
  1447. #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
  1448. #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
  1449. #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
  1450. #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
  1451. #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
  1452. #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
  1453. #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
  1454. #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
  1455. #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
  1456. #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
  1457. #define ASC_MC_CHIP_TYPE 0x009A
  1458. #define ASC_MC_INTRB_CODE 0x009B
  1459. #define ASC_MC_WDTR_ABLE 0x009C
  1460. #define ASC_MC_SDTR_ABLE 0x009E
  1461. #define ASC_MC_TAGQNG_ABLE 0x00A0
  1462. #define ASC_MC_DISC_ENABLE 0x00A2
  1463. #define ASC_MC_IDLE_CMD_STATUS 0x00A4
  1464. #define ASC_MC_IDLE_CMD 0x00A6
  1465. #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
  1466. #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
  1467. #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
  1468. #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
  1469. #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
  1470. #define ASC_MC_SDTR_DONE 0x00B6
  1471. #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
  1472. #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
  1473. #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
  1474. #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
  1475. #define ASC_MC_WDTR_DONE 0x0124
  1476. #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
  1477. #define ASC_MC_ICQ 0x0160
  1478. #define ASC_MC_IRQ 0x0164
  1479. #define ASC_MC_PPR_ABLE 0x017A
  1480. /*
  1481. * BIOS LRAM variable absolute offsets.
  1482. */
  1483. #define BIOS_CODESEG 0x54
  1484. #define BIOS_CODELEN 0x56
  1485. #define BIOS_SIGNATURE 0x58
  1486. #define BIOS_VERSION 0x5A
  1487. /*
  1488. * Microcode Control Flags
  1489. *
  1490. * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
  1491. * and handled by the microcode.
  1492. */
  1493. #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
  1494. #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
  1495. /*
  1496. * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
  1497. */
  1498. #define HSHK_CFG_WIDE_XFR 0x8000
  1499. #define HSHK_CFG_RATE 0x0F00
  1500. #define HSHK_CFG_OFFSET 0x001F
  1501. #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
  1502. #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
  1503. #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
  1504. #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
  1505. #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
  1506. #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
  1507. #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
  1508. #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
  1509. #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
  1510. #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
  1511. #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
  1512. #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
  1513. #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
  1514. #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
  1515. /*
  1516. * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
  1517. * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
  1518. */
  1519. #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
  1520. #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
  1521. /*
  1522. * All fields here are accessed by the board microcode and need to be
  1523. * little-endian.
  1524. */
  1525. typedef struct adv_carr_t {
  1526. __le32 carr_va; /* Carrier Virtual Address */
  1527. __le32 carr_pa; /* Carrier Physical Address */
  1528. __le32 areq_vpa; /* ADV_SCSI_REQ_Q Virtual or Physical Address */
  1529. /*
  1530. * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
  1531. *
  1532. * next_vpa [3:1] Reserved Bits
  1533. * next_vpa [0] Done Flag set in Response Queue.
  1534. */
  1535. __le32 next_vpa;
  1536. } ADV_CARR_T;
  1537. /*
  1538. * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
  1539. */
  1540. #define ADV_NEXT_VPA_MASK 0xFFFFFFF0
  1541. #define ADV_RQ_DONE 0x00000001
  1542. #define ADV_RQ_GOOD 0x00000002
  1543. #define ADV_CQ_STOPPER 0x00000000
  1544. #define ADV_GET_CARRP(carrp) ((carrp) & ADV_NEXT_VPA_MASK)
  1545. /*
  1546. * Each carrier is 64 bytes, and we need three additional
  1547. * carrier for icq, irq, and the termination carrier.
  1548. */
  1549. #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3)
  1550. #define ADV_CARRIER_BUFSIZE \
  1551. (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T))
  1552. #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
  1553. #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
  1554. #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
  1555. /*
  1556. * Adapter temporary configuration structure
  1557. *
  1558. * This structure can be discarded after initialization. Don't add
  1559. * fields here needed after initialization.
  1560. *
  1561. * Field naming convention:
  1562. *
  1563. * *_enable indicates the field enables or disables a feature. The
  1564. * value of the field is never reset.
  1565. */
  1566. typedef struct adv_dvc_cfg {
  1567. ushort disc_enable; /* enable disconnection */
  1568. uchar chip_version; /* chip version */
  1569. uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
  1570. ushort control_flag; /* Microcode Control Flag */
  1571. ushort mcode_date; /* Microcode date */
  1572. ushort mcode_version; /* Microcode version */
  1573. ushort serial1; /* EEPROM serial number word 1 */
  1574. ushort serial2; /* EEPROM serial number word 2 */
  1575. ushort serial3; /* EEPROM serial number word 3 */
  1576. } ADV_DVC_CFG;
  1577. struct adv_dvc_var;
  1578. struct adv_scsi_req_q;
  1579. typedef struct adv_sg_block {
  1580. uchar reserved1;
  1581. uchar reserved2;
  1582. uchar reserved3;
  1583. uchar sg_cnt; /* Valid entries in block. */
  1584. __le32 sg_ptr; /* Pointer to next sg block. */
  1585. struct {
  1586. __le32 sg_addr; /* SG element address. */
  1587. __le32 sg_count; /* SG element count. */
  1588. } sg_list[NO_OF_SG_PER_BLOCK];
  1589. } ADV_SG_BLOCK;
  1590. /*
  1591. * ADV_SCSI_REQ_Q - microcode request structure
  1592. *
  1593. * All fields in this structure up to byte 60 are used by the microcode.
  1594. * The microcode makes assumptions about the size and ordering of fields
  1595. * in this structure. Do not change the structure definition here without
  1596. * coordinating the change with the microcode.
  1597. *
  1598. * All fields accessed by microcode must be maintained in little_endian
  1599. * order.
  1600. */
  1601. typedef struct adv_scsi_req_q {
  1602. uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
  1603. uchar target_cmd;
  1604. uchar target_id; /* Device target identifier. */
  1605. uchar target_lun; /* Device target logical unit number. */
  1606. __le32 data_addr; /* Data buffer physical address. */
  1607. __le32 data_cnt; /* Data count. Ucode sets to residual. */
  1608. __le32 sense_addr;
  1609. __le32 carr_pa;
  1610. uchar mflag;
  1611. uchar sense_len;
  1612. uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
  1613. uchar scsi_cntl;
  1614. uchar done_status; /* Completion status. */
  1615. uchar scsi_status; /* SCSI status byte. */
  1616. uchar host_status; /* Ucode host status. */
  1617. uchar sg_working_ix;
  1618. uchar cdb[12]; /* SCSI CDB bytes 0-11. */
  1619. __le32 sg_real_addr; /* SG list physical address. */
  1620. __le32 scsiq_rptr;
  1621. uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
  1622. __le32 scsiq_ptr;
  1623. __le32 carr_va;
  1624. /*
  1625. * End of microcode structure - 60 bytes. The rest of the structure
  1626. * is used by the Adv Library and ignored by the microcode.
  1627. */
  1628. u32 srb_tag;
  1629. ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
  1630. } ADV_SCSI_REQ_Q;
  1631. /*
  1632. * The following two structures are used to process Wide Board requests.
  1633. *
  1634. * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
  1635. * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the
  1636. * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points
  1637. * to the Mid-Level SCSI request structure.
  1638. *
  1639. * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
  1640. * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
  1641. * up to 255 scatter-gather elements may be used per request or
  1642. * ADV_SCSI_REQ_Q.
  1643. *
  1644. * Both structures must be 32 byte aligned.
  1645. */
  1646. typedef struct adv_sgblk {
  1647. ADV_SG_BLOCK sg_block; /* Sgblock structure. */
  1648. dma_addr_t sg_addr; /* Physical address */
  1649. struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
  1650. } adv_sgblk_t;
  1651. typedef struct adv_req {
  1652. ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
  1653. uchar align[24]; /* Request structure padding. */
  1654. struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
  1655. dma_addr_t req_addr;
  1656. adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
  1657. } adv_req_t __aligned(32);
  1658. /*
  1659. * Adapter operation variable structure.
  1660. *
  1661. * One structure is required per host adapter.
  1662. *
  1663. * Field naming convention:
  1664. *
  1665. * *_able indicates both whether a feature should be enabled or disabled
  1666. * and whether a device is capable of the feature. At initialization
  1667. * this field may be set, but later if a device is found to be incapable
  1668. * of the feature, the field is cleared.
  1669. */
  1670. typedef struct adv_dvc_var {
  1671. AdvPortAddr iop_base; /* I/O port address */
  1672. ushort err_code; /* fatal error code */
  1673. ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
  1674. ushort wdtr_able; /* try WDTR for a device */
  1675. ushort sdtr_able; /* try SDTR for a device */
  1676. ushort ultra_able; /* try SDTR Ultra speed for a device */
  1677. ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
  1678. ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
  1679. ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
  1680. ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
  1681. ushort tagqng_able; /* try tagged queuing with a device */
  1682. ushort ppr_able; /* PPR message capable per TID bitmask. */
  1683. uchar max_dvc_qng; /* maximum number of tagged commands per device */
  1684. ushort start_motor; /* start motor command allowed */
  1685. uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
  1686. uchar chip_no; /* should be assigned by caller */
  1687. uchar max_host_qng; /* maximum number of Q'ed command allowed */
  1688. ushort no_scam; /* scam_tolerant of EEPROM */
  1689. struct asc_board *drv_ptr; /* driver pointer to private structure */
  1690. uchar chip_scsi_id; /* chip SCSI target ID */
  1691. uchar chip_type;
  1692. uchar bist_err_code;
  1693. ADV_CARR_T *carrier;
  1694. ADV_CARR_T *carr_freelist; /* Carrier free list. */
  1695. dma_addr_t carrier_addr;
  1696. ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
  1697. ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
  1698. ushort carr_pending_cnt; /* Count of pending carriers. */
  1699. /*
  1700. * Note: The following fields will not be used after initialization. The
  1701. * driver may discard the buffer after initialization is done.
  1702. */
  1703. ADV_DVC_CFG *cfg; /* temporary configuration structure */
  1704. } ADV_DVC_VAR;
  1705. /*
  1706. * Microcode idle loop commands
  1707. */
  1708. #define IDLE_CMD_COMPLETED 0
  1709. #define IDLE_CMD_STOP_CHIP 0x0001
  1710. #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
  1711. #define IDLE_CMD_SEND_INT 0x0004
  1712. #define IDLE_CMD_ABORT 0x0008
  1713. #define IDLE_CMD_DEVICE_RESET 0x0010
  1714. #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
  1715. #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
  1716. #define IDLE_CMD_SCSIREQ 0x0080
  1717. #define IDLE_CMD_STATUS_SUCCESS 0x0001
  1718. #define IDLE_CMD_STATUS_FAILURE 0x0002
  1719. /*
  1720. * AdvSendIdleCmd() flag definitions.
  1721. */
  1722. #define ADV_NOWAIT 0x01
  1723. /*
  1724. * Wait loop time out values.
  1725. */
  1726. #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
  1727. #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
  1728. #define SCSI_MAX_RETRY 10 /* retry count */
  1729. #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
  1730. #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
  1731. #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
  1732. #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
  1733. #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
  1734. /* Read byte from a register. */
  1735. #define AdvReadByteRegister(iop_base, reg_off) \
  1736. (ADV_MEM_READB((iop_base) + (reg_off)))
  1737. /* Write byte to a register. */
  1738. #define AdvWriteByteRegister(iop_base, reg_off, byte) \
  1739. (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
  1740. /* Read word (2 bytes) from a register. */
  1741. #define AdvReadWordRegister(iop_base, reg_off) \
  1742. (ADV_MEM_READW((iop_base) + (reg_off)))
  1743. /* Write word (2 bytes) to a register. */
  1744. #define AdvWriteWordRegister(iop_base, reg_off, word) \
  1745. (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
  1746. /* Write dword (4 bytes) to a register. */
  1747. #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
  1748. (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
  1749. /* Read byte from LRAM. */
  1750. #define AdvReadByteLram(iop_base, addr, byte) \
  1751. do { \
  1752. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1753. (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
  1754. } while (0)
  1755. /* Write byte to LRAM. */
  1756. #define AdvWriteByteLram(iop_base, addr, byte) \
  1757. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1758. ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
  1759. /* Read word (2 bytes) from LRAM. */
  1760. #define AdvReadWordLram(iop_base, addr, word) \
  1761. do { \
  1762. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1763. (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
  1764. } while (0)
  1765. /* Write word (2 bytes) to LRAM. */
  1766. #define AdvWriteWordLram(iop_base, addr, word) \
  1767. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1768. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1769. /* Write little-endian double word (4 bytes) to LRAM */
  1770. /* Because of unspecified C language ordering don't use auto-increment. */
  1771. #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
  1772. ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1773. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1774. cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
  1775. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
  1776. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1777. cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
  1778. /* Read word (2 bytes) from LRAM assuming that the address is already set. */
  1779. #define AdvReadWordAutoIncLram(iop_base) \
  1780. (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
  1781. /* Write word (2 bytes) to LRAM assuming that the address is already set. */
  1782. #define AdvWriteWordAutoIncLram(iop_base, word) \
  1783. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1784. /*
  1785. * Define macro to check for Condor signature.
  1786. *
  1787. * Evaluate to ADV_TRUE if a Condor chip is found the specified port
  1788. * address 'iop_base'. Otherwise evalue to ADV_FALSE.
  1789. */
  1790. #define AdvFindSignature(iop_base) \
  1791. (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
  1792. ADV_CHIP_ID_BYTE) && \
  1793. (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
  1794. ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
  1795. /*
  1796. * Define macro to Return the version number of the chip at 'iop_base'.
  1797. *
  1798. * The second parameter 'bus_type' is currently unused.
  1799. */
  1800. #define AdvGetChipVersion(iop_base, bus_type) \
  1801. AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
  1802. /*
  1803. * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must
  1804. * match the ADV_SCSI_REQ_Q 'srb_tag' field.
  1805. *
  1806. * If the request has not yet been sent to the device it will simply be
  1807. * aborted from RISC memory. If the request is disconnected it will be
  1808. * aborted on reselection by sending an Abort Message to the target ID.
  1809. *
  1810. * Return value:
  1811. * ADV_TRUE(1) - Queue was successfully aborted.
  1812. * ADV_FALSE(0) - Queue was not found on the active queue list.
  1813. */
  1814. #define AdvAbortQueue(asc_dvc, srb_tag) \
  1815. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
  1816. (ADV_DCNT) (srb_tag))
  1817. /*
  1818. * Send a Bus Device Reset Message to the specified target ID.
  1819. *
  1820. * All outstanding commands will be purged if sending the
  1821. * Bus Device Reset Message is successful.
  1822. *
  1823. * Return Value:
  1824. * ADV_TRUE(1) - All requests on the target are purged.
  1825. * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
  1826. * are not purged.
  1827. */
  1828. #define AdvResetDevice(asc_dvc, target_id) \
  1829. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
  1830. (ADV_DCNT) (target_id))
  1831. /*
  1832. * SCSI Wide Type definition.
  1833. */
  1834. #define ADV_SCSI_BIT_ID_TYPE ushort
  1835. /*
  1836. * AdvInitScsiTarget() 'cntl_flag' options.
  1837. */
  1838. #define ADV_SCAN_LUN 0x01
  1839. #define ADV_CAPINFO_NOLUN 0x02
  1840. /*
  1841. * Convert target id to target id bit mask.
  1842. */
  1843. #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
  1844. /*
  1845. * ADV_SCSI_REQ_Q 'done_status' and 'host_status' return values.
  1846. */
  1847. #define QD_NO_STATUS 0x00 /* Request not completed yet. */
  1848. #define QD_NO_ERROR 0x01
  1849. #define QD_ABORTED_BY_HOST 0x02
  1850. #define QD_WITH_ERROR 0x04
  1851. #define QHSTA_NO_ERROR 0x00
  1852. #define QHSTA_M_SEL_TIMEOUT 0x11
  1853. #define QHSTA_M_DATA_OVER_RUN 0x12
  1854. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  1855. #define QHSTA_M_QUEUE_ABORTED 0x15
  1856. #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
  1857. #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
  1858. #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
  1859. #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
  1860. #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
  1861. #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
  1862. #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
  1863. /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
  1864. #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
  1865. #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
  1866. #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
  1867. #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
  1868. #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
  1869. #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
  1870. #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
  1871. #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
  1872. #define QHSTA_M_WTM_TIMEOUT 0x41
  1873. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  1874. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  1875. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  1876. #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
  1877. #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
  1878. #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
  1879. /* Return the address that is aligned at the next doubleword >= to 'addr'. */
  1880. #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
  1881. /*
  1882. * Total contiguous memory needed for driver SG blocks.
  1883. *
  1884. * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
  1885. * number of scatter-gather elements the driver supports in a
  1886. * single request.
  1887. */
  1888. #define ADV_SG_LIST_MAX_BYTE_SIZE \
  1889. (sizeof(ADV_SG_BLOCK) * \
  1890. ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
  1891. /* struct asc_board flags */
  1892. #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
  1893. #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
  1894. #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
  1895. #define ASC_INFO_SIZE 128 /* advansys_info() line size */
  1896. /* Asc Library return codes */
  1897. #define ASC_TRUE 1
  1898. #define ASC_FALSE 0
  1899. #define ASC_NOERROR 1
  1900. #define ASC_BUSY 0
  1901. #define ASC_ERROR (-1)
  1902. #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
  1903. #ifndef ADVANSYS_STATS
  1904. #define ASC_STATS_ADD(shost, counter, count)
  1905. #else /* ADVANSYS_STATS */
  1906. #define ASC_STATS_ADD(shost, counter, count) \
  1907. (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
  1908. #endif /* ADVANSYS_STATS */
  1909. /* If the result wraps when calculating tenths, return 0. */
  1910. #define ASC_TENTHS(num, den) \
  1911. (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
  1912. 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
  1913. /*
  1914. * Display a message to the console.
  1915. */
  1916. #define ASC_PRINT(s) \
  1917. { \
  1918. printk("advansys: "); \
  1919. printk(s); \
  1920. }
  1921. #define ASC_PRINT1(s, a1) \
  1922. { \
  1923. printk("advansys: "); \
  1924. printk((s), (a1)); \
  1925. }
  1926. #define ASC_PRINT2(s, a1, a2) \
  1927. { \
  1928. printk("advansys: "); \
  1929. printk((s), (a1), (a2)); \
  1930. }
  1931. #define ASC_PRINT3(s, a1, a2, a3) \
  1932. { \
  1933. printk("advansys: "); \
  1934. printk((s), (a1), (a2), (a3)); \
  1935. }
  1936. #define ASC_PRINT4(s, a1, a2, a3, a4) \
  1937. { \
  1938. printk("advansys: "); \
  1939. printk((s), (a1), (a2), (a3), (a4)); \
  1940. }
  1941. #ifndef ADVANSYS_DEBUG
  1942. #define ASC_DBG(lvl, s...)
  1943. #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
  1944. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
  1945. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  1946. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
  1947. #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  1948. #define ASC_DBG_PRT_HEX(lvl, name, start, length)
  1949. #define ASC_DBG_PRT_CDB(lvl, cdb, len)
  1950. #define ASC_DBG_PRT_SENSE(lvl, sense, len)
  1951. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
  1952. #else /* ADVANSYS_DEBUG */
  1953. /*
  1954. * Debugging Message Levels:
  1955. * 0: Errors Only
  1956. * 1: High-Level Tracing
  1957. * 2-N: Verbose Tracing
  1958. */
  1959. #define ASC_DBG(lvl, format, arg...) { \
  1960. if (asc_dbglvl >= (lvl)) \
  1961. printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
  1962. __func__ , ## arg); \
  1963. }
  1964. #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
  1965. { \
  1966. if (asc_dbglvl >= (lvl)) { \
  1967. asc_prt_scsi_host(s); \
  1968. } \
  1969. }
  1970. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
  1971. { \
  1972. if (asc_dbglvl >= (lvl)) { \
  1973. asc_prt_asc_scsi_q(scsiqp); \
  1974. } \
  1975. }
  1976. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
  1977. { \
  1978. if (asc_dbglvl >= (lvl)) { \
  1979. asc_prt_asc_qdone_info(qdone); \
  1980. } \
  1981. }
  1982. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
  1983. { \
  1984. if (asc_dbglvl >= (lvl)) { \
  1985. asc_prt_adv_scsi_req_q(scsiqp); \
  1986. } \
  1987. }
  1988. #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
  1989. { \
  1990. if (asc_dbglvl >= (lvl)) { \
  1991. asc_prt_hex((name), (start), (length)); \
  1992. } \
  1993. }
  1994. #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
  1995. ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
  1996. #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
  1997. ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
  1998. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
  1999. ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
  2000. #endif /* ADVANSYS_DEBUG */
  2001. #ifdef ADVANSYS_STATS
  2002. /* Per board statistics structure */
  2003. struct asc_stats {
  2004. /* Driver Entrypoint Statistics */
  2005. unsigned int queuecommand; /* # calls to advansys_queuecommand() */
  2006. unsigned int reset; /* # calls to advansys_eh_bus_reset() */
  2007. unsigned int biosparam; /* # calls to advansys_biosparam() */
  2008. unsigned int interrupt; /* # advansys_interrupt() calls */
  2009. unsigned int callback; /* # calls to asc/adv_isr_callback() */
  2010. unsigned int done; /* # calls to request's scsi_done function */
  2011. unsigned int build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
  2012. unsigned int adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
  2013. unsigned int adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
  2014. /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
  2015. unsigned int exe_noerror; /* # ASC_NOERROR returns. */
  2016. unsigned int exe_busy; /* # ASC_BUSY returns. */
  2017. unsigned int exe_error; /* # ASC_ERROR returns. */
  2018. unsigned int exe_unknown; /* # unknown returns. */
  2019. /* Data Transfer Statistics */
  2020. unsigned int xfer_cnt; /* # I/O requests received */
  2021. unsigned int xfer_elem; /* # scatter-gather elements */
  2022. unsigned int xfer_sect; /* # 512-byte blocks */
  2023. };
  2024. #endif /* ADVANSYS_STATS */
  2025. /*
  2026. * Structure allocated for each board.
  2027. *
  2028. * This structure is allocated by scsi_host_alloc() at the end
  2029. * of the 'Scsi_Host' structure starting at the 'hostdata'
  2030. * field. It is guaranteed to be allocated from DMA-able memory.
  2031. */
  2032. struct asc_board {
  2033. struct device *dev;
  2034. struct Scsi_Host *shost;
  2035. uint flags; /* Board flags */
  2036. unsigned int irq;
  2037. union {
  2038. ASC_DVC_VAR asc_dvc_var; /* Narrow board */
  2039. ADV_DVC_VAR adv_dvc_var; /* Wide board */
  2040. } dvc_var;
  2041. union {
  2042. ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
  2043. ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
  2044. } dvc_cfg;
  2045. ushort asc_n_io_port; /* Number I/O ports. */
  2046. ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
  2047. ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
  2048. ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
  2049. ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
  2050. union {
  2051. ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
  2052. ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
  2053. ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
  2054. ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
  2055. } eep_config;
  2056. /* /proc/scsi/advansys/[0...] */
  2057. #ifdef ADVANSYS_STATS
  2058. struct asc_stats asc_stats; /* Board statistics */
  2059. #endif /* ADVANSYS_STATS */
  2060. /*
  2061. * The following fields are used only for Narrow Boards.
  2062. */
  2063. uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
  2064. /*
  2065. * The following fields are used only for Wide Boards.
  2066. */
  2067. void __iomem *ioremap_addr; /* I/O Memory remap address. */
  2068. ushort ioport; /* I/O Port address. */
  2069. adv_req_t *adv_reqp; /* Request structures. */
  2070. dma_addr_t adv_reqp_addr;
  2071. size_t adv_reqp_size;
  2072. struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */
  2073. ushort bios_signature; /* BIOS Signature. */
  2074. ushort bios_version; /* BIOS Version. */
  2075. ushort bios_codeseg; /* BIOS Code Segment. */
  2076. ushort bios_codelen; /* BIOS Code Segment Length. */
  2077. };
  2078. #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
  2079. dvc_var.asc_dvc_var)
  2080. #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
  2081. dvc_var.adv_dvc_var)
  2082. #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
  2083. struct advansys_cmd {
  2084. dma_addr_t dma_handle;
  2085. };
  2086. static struct advansys_cmd *advansys_cmd(struct scsi_cmnd *cmd)
  2087. {
  2088. return scsi_cmd_priv(cmd);
  2089. }
  2090. #ifdef ADVANSYS_DEBUG
  2091. static int asc_dbglvl = 3;
  2092. /*
  2093. * asc_prt_asc_dvc_var()
  2094. */
  2095. static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
  2096. {
  2097. printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2098. printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
  2099. "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
  2100. printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
  2101. (unsigned)h->init_sdtr);
  2102. printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
  2103. "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
  2104. (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
  2105. (unsigned)h->chip_no);
  2106. printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
  2107. "%u,\n", (unsigned)h->queue_full_or_busy,
  2108. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2109. printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
  2110. "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
  2111. (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
  2112. (unsigned)h->in_critical_cnt);
  2113. printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
  2114. "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
  2115. (unsigned)h->init_state, (unsigned)h->no_scam,
  2116. (unsigned)h->pci_fix_asyn_xfer);
  2117. printk(" cfg 0x%lx\n", (ulong)h->cfg);
  2118. }
  2119. /*
  2120. * asc_prt_asc_dvc_cfg()
  2121. */
  2122. static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
  2123. {
  2124. printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2125. printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
  2126. h->can_tagged_qng, h->cmd_qng_enabled);
  2127. printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
  2128. h->disc_enable, h->sdtr_enable);
  2129. printk(" chip_scsi_id %d, chip_version %d,\n",
  2130. h->chip_scsi_id, h->chip_version);
  2131. printk(" mcode_date 0x%x, mcode_version %d\n",
  2132. h->mcode_date, h->mcode_version);
  2133. }
  2134. /*
  2135. * asc_prt_adv_dvc_var()
  2136. *
  2137. * Display an ADV_DVC_VAR structure.
  2138. */
  2139. static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
  2140. {
  2141. printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2142. printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
  2143. (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
  2144. printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
  2145. (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
  2146. printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
  2147. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2148. printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n",
  2149. (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
  2150. h->carr_freelist);
  2151. printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp);
  2152. printk(" no_scam 0x%x, tagqng_able 0x%x\n",
  2153. (unsigned)h->no_scam, (unsigned)h->tagqng_able);
  2154. printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
  2155. (unsigned)h->chip_scsi_id, (ulong)h->cfg);
  2156. }
  2157. /*
  2158. * asc_prt_adv_dvc_cfg()
  2159. *
  2160. * Display an ADV_DVC_CFG structure.
  2161. */
  2162. static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
  2163. {
  2164. printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2165. printk(" disc_enable 0x%x, termination 0x%x\n",
  2166. h->disc_enable, h->termination);
  2167. printk(" chip_version 0x%x, mcode_date 0x%x\n",
  2168. h->chip_version, h->mcode_date);
  2169. printk(" mcode_version 0x%x, control_flag 0x%x\n",
  2170. h->mcode_version, h->control_flag);
  2171. }
  2172. /*
  2173. * asc_prt_scsi_host()
  2174. */
  2175. static void asc_prt_scsi_host(struct Scsi_Host *s)
  2176. {
  2177. struct asc_board *boardp = shost_priv(s);
  2178. printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
  2179. printk(" host_busy %d, host_no %d,\n",
  2180. scsi_host_busy(s), s->host_no);
  2181. printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
  2182. (ulong)s->base, (ulong)s->io_port, boardp->irq);
  2183. printk(" dma_channel %d, this_id %d, can_queue %d,\n",
  2184. s->dma_channel, s->this_id, s->can_queue);
  2185. printk(" cmd_per_lun %d, sg_tablesize %d\n",
  2186. s->cmd_per_lun, s->sg_tablesize);
  2187. if (ASC_NARROW_BOARD(boardp)) {
  2188. asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
  2189. asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
  2190. } else {
  2191. asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
  2192. asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
  2193. }
  2194. }
  2195. /*
  2196. * asc_prt_hex()
  2197. *
  2198. * Print hexadecimal output in 4 byte groupings 32 bytes
  2199. * or 8 double-words per line.
  2200. */
  2201. static void asc_prt_hex(char *f, uchar *s, int l)
  2202. {
  2203. int i;
  2204. int j;
  2205. int k;
  2206. int m;
  2207. printk("%s: (%d bytes)\n", f, l);
  2208. for (i = 0; i < l; i += 32) {
  2209. /* Display a maximum of 8 double-words per line. */
  2210. if ((k = (l - i) / 4) >= 8) {
  2211. k = 8;
  2212. m = 0;
  2213. } else {
  2214. m = (l - i) % 4;
  2215. }
  2216. for (j = 0; j < k; j++) {
  2217. printk(" %2.2X%2.2X%2.2X%2.2X",
  2218. (unsigned)s[i + (j * 4)],
  2219. (unsigned)s[i + (j * 4) + 1],
  2220. (unsigned)s[i + (j * 4) + 2],
  2221. (unsigned)s[i + (j * 4) + 3]);
  2222. }
  2223. switch (m) {
  2224. case 0:
  2225. default:
  2226. break;
  2227. case 1:
  2228. printk(" %2.2X", (unsigned)s[i + (j * 4)]);
  2229. break;
  2230. case 2:
  2231. printk(" %2.2X%2.2X",
  2232. (unsigned)s[i + (j * 4)],
  2233. (unsigned)s[i + (j * 4) + 1]);
  2234. break;
  2235. case 3:
  2236. printk(" %2.2X%2.2X%2.2X",
  2237. (unsigned)s[i + (j * 4) + 1],
  2238. (unsigned)s[i + (j * 4) + 2],
  2239. (unsigned)s[i + (j * 4) + 3]);
  2240. break;
  2241. }
  2242. printk("\n");
  2243. }
  2244. }
  2245. /*
  2246. * asc_prt_asc_scsi_q()
  2247. */
  2248. static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
  2249. {
  2250. ASC_SG_HEAD *sgp;
  2251. int i;
  2252. printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
  2253. printk
  2254. (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n",
  2255. q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag,
  2256. q->q2.tag_code);
  2257. printk
  2258. (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2259. (ulong)le32_to_cpu(q->q1.data_addr),
  2260. (ulong)le32_to_cpu(q->q1.data_cnt),
  2261. (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
  2262. printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
  2263. (ulong)q->cdbptr, q->q2.cdb_len,
  2264. (ulong)q->sg_head, q->q1.sg_queue_cnt);
  2265. if (q->sg_head) {
  2266. sgp = q->sg_head;
  2267. printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
  2268. printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
  2269. sgp->queue_cnt);
  2270. for (i = 0; i < sgp->entry_cnt; i++) {
  2271. printk(" [%u]: addr 0x%lx, bytes %lu\n",
  2272. i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
  2273. (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
  2274. }
  2275. }
  2276. }
  2277. /*
  2278. * asc_prt_asc_qdone_info()
  2279. */
  2280. static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
  2281. {
  2282. printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
  2283. printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n",
  2284. q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len,
  2285. q->d2.tag_code);
  2286. printk
  2287. (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
  2288. q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
  2289. }
  2290. /*
  2291. * asc_prt_adv_sgblock()
  2292. *
  2293. * Display an ADV_SG_BLOCK structure.
  2294. */
  2295. static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
  2296. {
  2297. int i;
  2298. printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
  2299. (ulong)b, sgblockno);
  2300. printk(" sg_cnt %u, sg_ptr 0x%x\n",
  2301. b->sg_cnt, (u32)le32_to_cpu(b->sg_ptr));
  2302. BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
  2303. if (b->sg_ptr != 0)
  2304. BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
  2305. for (i = 0; i < b->sg_cnt; i++) {
  2306. printk(" [%u]: sg_addr 0x%x, sg_count 0x%x\n",
  2307. i, (u32)le32_to_cpu(b->sg_list[i].sg_addr),
  2308. (u32)le32_to_cpu(b->sg_list[i].sg_count));
  2309. }
  2310. }
  2311. /*
  2312. * asc_prt_adv_scsi_req_q()
  2313. *
  2314. * Display an ADV_SCSI_REQ_Q structure.
  2315. */
  2316. static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
  2317. {
  2318. int sg_blk_cnt;
  2319. struct adv_sg_block *sg_ptr;
  2320. adv_sgblk_t *sgblkp;
  2321. printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
  2322. printk(" target_id %u, target_lun %u, srb_tag 0x%x\n",
  2323. q->target_id, q->target_lun, q->srb_tag);
  2324. printk(" cntl 0x%x, data_addr 0x%lx\n",
  2325. q->cntl, (ulong)le32_to_cpu(q->data_addr));
  2326. printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2327. (ulong)le32_to_cpu(q->data_cnt),
  2328. (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
  2329. printk
  2330. (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
  2331. q->cdb_len, q->done_status, q->host_status, q->scsi_status);
  2332. printk(" sg_working_ix 0x%x, target_cmd %u\n",
  2333. q->sg_working_ix, q->target_cmd);
  2334. printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
  2335. (ulong)le32_to_cpu(q->scsiq_rptr),
  2336. (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
  2337. /* Display the request's ADV_SG_BLOCK structures. */
  2338. if (q->sg_list_ptr != NULL) {
  2339. sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block);
  2340. sg_blk_cnt = 0;
  2341. while (sgblkp) {
  2342. sg_ptr = &sgblkp->sg_block;
  2343. asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
  2344. if (sg_ptr->sg_ptr == 0) {
  2345. break;
  2346. }
  2347. sgblkp = sgblkp->next_sgblkp;
  2348. sg_blk_cnt++;
  2349. }
  2350. }
  2351. }
  2352. #endif /* ADVANSYS_DEBUG */
  2353. /*
  2354. * advansys_info()
  2355. *
  2356. * Return suitable for printing on the console with the argument
  2357. * adapter's configuration information.
  2358. *
  2359. * Note: The information line should not exceed ASC_INFO_SIZE bytes,
  2360. * otherwise the static 'info' array will be overrun.
  2361. */
  2362. static const char *advansys_info(struct Scsi_Host *shost)
  2363. {
  2364. static char info[ASC_INFO_SIZE];
  2365. struct asc_board *boardp = shost_priv(shost);
  2366. ASC_DVC_VAR *asc_dvc_varp;
  2367. ADV_DVC_VAR *adv_dvc_varp;
  2368. char *busname;
  2369. char *widename = NULL;
  2370. if (ASC_NARROW_BOARD(boardp)) {
  2371. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2372. ASC_DBG(1, "begin\n");
  2373. if (asc_dvc_varp->bus_type & ASC_IS_VL) {
  2374. busname = "VL";
  2375. } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
  2376. busname = "EISA";
  2377. } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
  2378. if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
  2379. == ASC_IS_PCI_ULTRA) {
  2380. busname = "PCI Ultra";
  2381. } else {
  2382. busname = "PCI";
  2383. }
  2384. } else {
  2385. busname = "?";
  2386. shost_printk(KERN_ERR, shost, "unknown bus "
  2387. "type %d\n", asc_dvc_varp->bus_type);
  2388. }
  2389. sprintf(info,
  2390. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
  2391. ASC_VERSION, busname, (ulong)shost->io_port,
  2392. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2393. boardp->irq);
  2394. } else {
  2395. /*
  2396. * Wide Adapter Information
  2397. *
  2398. * Memory-mapped I/O is used instead of I/O space to access
  2399. * the adapter, but display the I/O Port range. The Memory
  2400. * I/O address is displayed through the driver /proc file.
  2401. */
  2402. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2403. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2404. widename = "Ultra-Wide";
  2405. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2406. widename = "Ultra2-Wide";
  2407. } else {
  2408. widename = "Ultra3-Wide";
  2409. }
  2410. sprintf(info,
  2411. "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
  2412. ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
  2413. (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
  2414. }
  2415. BUG_ON(strlen(info) >= ASC_INFO_SIZE);
  2416. ASC_DBG(1, "end\n");
  2417. return info;
  2418. }
  2419. #ifdef CONFIG_PROC_FS
  2420. /*
  2421. * asc_prt_board_devices()
  2422. *
  2423. * Print driver information for devices attached to the board.
  2424. */
  2425. static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
  2426. {
  2427. struct asc_board *boardp = shost_priv(shost);
  2428. int chip_scsi_id;
  2429. int i;
  2430. seq_printf(m,
  2431. "\nDevice Information for AdvanSys SCSI Host %d:\n",
  2432. shost->host_no);
  2433. if (ASC_NARROW_BOARD(boardp)) {
  2434. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2435. } else {
  2436. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2437. }
  2438. seq_puts(m, "Target IDs Detected:");
  2439. for (i = 0; i <= ADV_MAX_TID; i++) {
  2440. if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
  2441. seq_printf(m, " %X,", i);
  2442. }
  2443. seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
  2444. }
  2445. /*
  2446. * Display Wide Board BIOS Information.
  2447. */
  2448. static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
  2449. {
  2450. struct asc_board *boardp = shost_priv(shost);
  2451. ushort major, minor, letter;
  2452. seq_puts(m, "\nROM BIOS Version: ");
  2453. /*
  2454. * If the BIOS saved a valid signature, then fill in
  2455. * the BIOS code segment base address.
  2456. */
  2457. if (boardp->bios_signature != 0x55AA) {
  2458. seq_puts(m, "Disabled or Pre-3.1\n"
  2459. "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n"
  2460. "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
  2461. } else {
  2462. major = (boardp->bios_version >> 12) & 0xF;
  2463. minor = (boardp->bios_version >> 8) & 0xF;
  2464. letter = (boardp->bios_version & 0xFF);
  2465. seq_printf(m, "%d.%d%c\n",
  2466. major, minor,
  2467. letter >= 26 ? '?' : letter + 'A');
  2468. /*
  2469. * Current available ROM BIOS release is 3.1I for UW
  2470. * and 3.2I for U2W. This code doesn't differentiate
  2471. * UW and U2W boards.
  2472. */
  2473. if (major < 3 || (major <= 3 && minor < 1) ||
  2474. (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
  2475. seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n"
  2476. "ftp://ftp.connectcom.net/pub\n");
  2477. }
  2478. }
  2479. }
  2480. /*
  2481. * Add serial number to information bar if signature AAh
  2482. * is found in at bit 15-9 (7 bits) of word 1.
  2483. *
  2484. * Serial Number consists fo 12 alpha-numeric digits.
  2485. *
  2486. * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
  2487. * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
  2488. * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
  2489. * 5 - Product revision (A-J) Word0: " "
  2490. *
  2491. * Signature Word1: 15-9 (7 bits)
  2492. * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
  2493. * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
  2494. *
  2495. * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
  2496. *
  2497. * Note 1: Only production cards will have a serial number.
  2498. *
  2499. * Note 2: Signature is most significant 7 bits (0xFE).
  2500. *
  2501. * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
  2502. */
  2503. static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
  2504. {
  2505. ushort w, num;
  2506. if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
  2507. return ASC_FALSE;
  2508. } else {
  2509. /*
  2510. * First word - 6 digits.
  2511. */
  2512. w = serialnum[0];
  2513. /* Product type - 1st digit. */
  2514. if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
  2515. /* Product type is P=Prototype */
  2516. *cp += 0x8;
  2517. }
  2518. cp++;
  2519. /* Manufacturing location - 2nd digit. */
  2520. *cp++ = 'A' + ((w & 0x1C00) >> 10);
  2521. /* Product ID - 3rd, 4th digits. */
  2522. num = w & 0x3FF;
  2523. *cp++ = '0' + (num / 100);
  2524. num %= 100;
  2525. *cp++ = '0' + (num / 10);
  2526. /* Product revision - 5th digit. */
  2527. *cp++ = 'A' + (num % 10);
  2528. /*
  2529. * Second word
  2530. */
  2531. w = serialnum[1];
  2532. /*
  2533. * Year - 6th digit.
  2534. *
  2535. * If bit 15 of third word is set, then the
  2536. * last digit of the year is greater than 7.
  2537. */
  2538. if (serialnum[2] & 0x8000) {
  2539. *cp++ = '8' + ((w & 0x1C0) >> 6);
  2540. } else {
  2541. *cp++ = '0' + ((w & 0x1C0) >> 6);
  2542. }
  2543. /* Week of year - 7th, 8th digits. */
  2544. num = w & 0x003F;
  2545. *cp++ = '0' + num / 10;
  2546. num %= 10;
  2547. *cp++ = '0' + num;
  2548. /*
  2549. * Third word
  2550. */
  2551. w = serialnum[2] & 0x7FFF;
  2552. /* Serial number - 9th digit. */
  2553. *cp++ = 'A' + (w / 1000);
  2554. /* 10th, 11th, 12th digits. */
  2555. num = w % 1000;
  2556. *cp++ = '0' + num / 100;
  2557. num %= 100;
  2558. *cp++ = '0' + num / 10;
  2559. num %= 10;
  2560. *cp++ = '0' + num;
  2561. *cp = '\0'; /* Null Terminate the string. */
  2562. return ASC_TRUE;
  2563. }
  2564. }
  2565. /*
  2566. * asc_prt_asc_board_eeprom()
  2567. *
  2568. * Print board EEPROM configuration.
  2569. */
  2570. static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2571. {
  2572. struct asc_board *boardp = shost_priv(shost);
  2573. ASCEEP_CONFIG *ep;
  2574. int i;
  2575. uchar serialstr[13];
  2576. ep = &boardp->eep_config.asc_eep;
  2577. seq_printf(m,
  2578. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2579. shost->host_no);
  2580. if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
  2581. == ASC_TRUE)
  2582. seq_printf(m, " Serial Number: %s\n", serialstr);
  2583. else if (ep->adapter_info[5] == 0xBB)
  2584. seq_puts(m,
  2585. " Default Settings Used for EEPROM-less Adapter.\n");
  2586. else
  2587. seq_puts(m, " Serial Number Signature Not Present.\n");
  2588. seq_printf(m,
  2589. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2590. ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
  2591. ep->max_tag_qng);
  2592. seq_printf(m,
  2593. " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
  2594. seq_puts(m, " Target ID: ");
  2595. for (i = 0; i <= ASC_MAX_TID; i++)
  2596. seq_printf(m, " %d", i);
  2597. seq_puts(m, "\n Disconnects: ");
  2598. for (i = 0; i <= ASC_MAX_TID; i++)
  2599. seq_printf(m, " %c",
  2600. (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2601. seq_puts(m, "\n Command Queuing: ");
  2602. for (i = 0; i <= ASC_MAX_TID; i++)
  2603. seq_printf(m, " %c",
  2604. (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2605. seq_puts(m, "\n Start Motor: ");
  2606. for (i = 0; i <= ASC_MAX_TID; i++)
  2607. seq_printf(m, " %c",
  2608. (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2609. seq_puts(m, "\n Synchronous Transfer:");
  2610. for (i = 0; i <= ASC_MAX_TID; i++)
  2611. seq_printf(m, " %c",
  2612. (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2613. seq_putc(m, '\n');
  2614. }
  2615. /*
  2616. * asc_prt_adv_board_eeprom()
  2617. *
  2618. * Print board EEPROM configuration.
  2619. */
  2620. static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2621. {
  2622. struct asc_board *boardp = shost_priv(shost);
  2623. ADV_DVC_VAR *adv_dvc_varp;
  2624. int i;
  2625. char *termstr;
  2626. uchar serialstr[13];
  2627. ADVEEP_3550_CONFIG *ep_3550 = NULL;
  2628. ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
  2629. ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
  2630. ushort word;
  2631. ushort *wordp;
  2632. ushort sdtr_speed = 0;
  2633. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2634. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2635. ep_3550 = &boardp->eep_config.adv_3550_eep;
  2636. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2637. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  2638. } else {
  2639. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  2640. }
  2641. seq_printf(m,
  2642. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2643. shost->host_no);
  2644. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2645. wordp = &ep_3550->serial_number_word1;
  2646. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2647. wordp = &ep_38C0800->serial_number_word1;
  2648. } else {
  2649. wordp = &ep_38C1600->serial_number_word1;
  2650. }
  2651. if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
  2652. seq_printf(m, " Serial Number: %s\n", serialstr);
  2653. else
  2654. seq_puts(m, " Serial Number Signature Not Present.\n");
  2655. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2656. seq_printf(m,
  2657. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2658. ep_3550->adapter_scsi_id,
  2659. ep_3550->max_host_qng, ep_3550->max_dvc_qng);
  2660. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2661. seq_printf(m,
  2662. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2663. ep_38C0800->adapter_scsi_id,
  2664. ep_38C0800->max_host_qng,
  2665. ep_38C0800->max_dvc_qng);
  2666. else
  2667. seq_printf(m,
  2668. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2669. ep_38C1600->adapter_scsi_id,
  2670. ep_38C1600->max_host_qng,
  2671. ep_38C1600->max_dvc_qng);
  2672. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2673. word = ep_3550->termination;
  2674. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2675. word = ep_38C0800->termination_lvd;
  2676. } else {
  2677. word = ep_38C1600->termination_lvd;
  2678. }
  2679. switch (word) {
  2680. case 1:
  2681. termstr = "Low Off/High Off";
  2682. break;
  2683. case 2:
  2684. termstr = "Low Off/High On";
  2685. break;
  2686. case 3:
  2687. termstr = "Low On/High On";
  2688. break;
  2689. default:
  2690. case 0:
  2691. termstr = "Automatic";
  2692. break;
  2693. }
  2694. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2695. seq_printf(m,
  2696. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2697. ep_3550->termination, termstr,
  2698. ep_3550->bios_ctrl);
  2699. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2700. seq_printf(m,
  2701. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2702. ep_38C0800->termination_lvd, termstr,
  2703. ep_38C0800->bios_ctrl);
  2704. else
  2705. seq_printf(m,
  2706. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2707. ep_38C1600->termination_lvd, termstr,
  2708. ep_38C1600->bios_ctrl);
  2709. seq_puts(m, " Target ID: ");
  2710. for (i = 0; i <= ADV_MAX_TID; i++)
  2711. seq_printf(m, " %X", i);
  2712. seq_putc(m, '\n');
  2713. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2714. word = ep_3550->disc_enable;
  2715. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2716. word = ep_38C0800->disc_enable;
  2717. } else {
  2718. word = ep_38C1600->disc_enable;
  2719. }
  2720. seq_puts(m, " Disconnects: ");
  2721. for (i = 0; i <= ADV_MAX_TID; i++)
  2722. seq_printf(m, " %c",
  2723. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2724. seq_putc(m, '\n');
  2725. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2726. word = ep_3550->tagqng_able;
  2727. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2728. word = ep_38C0800->tagqng_able;
  2729. } else {
  2730. word = ep_38C1600->tagqng_able;
  2731. }
  2732. seq_puts(m, " Command Queuing: ");
  2733. for (i = 0; i <= ADV_MAX_TID; i++)
  2734. seq_printf(m, " %c",
  2735. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2736. seq_putc(m, '\n');
  2737. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2738. word = ep_3550->start_motor;
  2739. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2740. word = ep_38C0800->start_motor;
  2741. } else {
  2742. word = ep_38C1600->start_motor;
  2743. }
  2744. seq_puts(m, " Start Motor: ");
  2745. for (i = 0; i <= ADV_MAX_TID; i++)
  2746. seq_printf(m, " %c",
  2747. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2748. seq_putc(m, '\n');
  2749. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2750. seq_puts(m, " Synchronous Transfer:");
  2751. for (i = 0; i <= ADV_MAX_TID; i++)
  2752. seq_printf(m, " %c",
  2753. (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
  2754. 'Y' : 'N');
  2755. seq_putc(m, '\n');
  2756. }
  2757. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2758. seq_puts(m, " Ultra Transfer: ");
  2759. for (i = 0; i <= ADV_MAX_TID; i++)
  2760. seq_printf(m, " %c",
  2761. (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
  2762. ? 'Y' : 'N');
  2763. seq_putc(m, '\n');
  2764. }
  2765. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2766. word = ep_3550->wdtr_able;
  2767. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2768. word = ep_38C0800->wdtr_able;
  2769. } else {
  2770. word = ep_38C1600->wdtr_able;
  2771. }
  2772. seq_puts(m, " Wide Transfer: ");
  2773. for (i = 0; i <= ADV_MAX_TID; i++)
  2774. seq_printf(m, " %c",
  2775. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2776. seq_putc(m, '\n');
  2777. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
  2778. adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
  2779. seq_puts(m, " Synchronous Transfer Speed (Mhz):\n ");
  2780. for (i = 0; i <= ADV_MAX_TID; i++) {
  2781. char *speed_str;
  2782. if (i == 0) {
  2783. sdtr_speed = adv_dvc_varp->sdtr_speed1;
  2784. } else if (i == 4) {
  2785. sdtr_speed = adv_dvc_varp->sdtr_speed2;
  2786. } else if (i == 8) {
  2787. sdtr_speed = adv_dvc_varp->sdtr_speed3;
  2788. } else if (i == 12) {
  2789. sdtr_speed = adv_dvc_varp->sdtr_speed4;
  2790. }
  2791. switch (sdtr_speed & ADV_MAX_TID) {
  2792. case 0:
  2793. speed_str = "Off";
  2794. break;
  2795. case 1:
  2796. speed_str = " 5";
  2797. break;
  2798. case 2:
  2799. speed_str = " 10";
  2800. break;
  2801. case 3:
  2802. speed_str = " 20";
  2803. break;
  2804. case 4:
  2805. speed_str = " 40";
  2806. break;
  2807. case 5:
  2808. speed_str = " 80";
  2809. break;
  2810. default:
  2811. speed_str = "Unk";
  2812. break;
  2813. }
  2814. seq_printf(m, "%X:%s ", i, speed_str);
  2815. if (i == 7)
  2816. seq_puts(m, "\n ");
  2817. sdtr_speed >>= 4;
  2818. }
  2819. seq_putc(m, '\n');
  2820. }
  2821. }
  2822. /*
  2823. * asc_prt_driver_conf()
  2824. */
  2825. static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
  2826. {
  2827. struct asc_board *boardp = shost_priv(shost);
  2828. seq_printf(m,
  2829. "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
  2830. shost->host_no);
  2831. seq_printf(m,
  2832. " host_busy %d, max_id %u, max_lun %llu, max_channel %u\n",
  2833. scsi_host_busy(shost), shost->max_id,
  2834. shost->max_lun, shost->max_channel);
  2835. seq_printf(m,
  2836. " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
  2837. shost->unique_id, shost->can_queue, shost->this_id,
  2838. shost->sg_tablesize, shost->cmd_per_lun);
  2839. seq_printf(m,
  2840. " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
  2841. boardp->flags, shost->last_reset, jiffies,
  2842. boardp->asc_n_io_port);
  2843. seq_printf(m, " io_port 0x%lx\n", shost->io_port);
  2844. }
  2845. /*
  2846. * asc_prt_asc_board_info()
  2847. *
  2848. * Print dynamic board configuration information.
  2849. */
  2850. static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
  2851. {
  2852. struct asc_board *boardp = shost_priv(shost);
  2853. int chip_scsi_id;
  2854. ASC_DVC_VAR *v;
  2855. ASC_DVC_CFG *c;
  2856. int i;
  2857. int renegotiate = 0;
  2858. v = &boardp->dvc_var.asc_dvc_var;
  2859. c = &boardp->dvc_cfg.asc_dvc_cfg;
  2860. chip_scsi_id = c->chip_scsi_id;
  2861. seq_printf(m,
  2862. "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  2863. shost->host_no);
  2864. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  2865. "mcode_version 0x%x, err_code %u\n",
  2866. c->chip_version, c->mcode_date, c->mcode_version,
  2867. v->err_code);
  2868. /* Current number of commands waiting for the host. */
  2869. seq_printf(m,
  2870. " Total Command Pending: %d\n", v->cur_total_qng);
  2871. seq_puts(m, " Command Queuing:");
  2872. for (i = 0; i <= ASC_MAX_TID; i++) {
  2873. if ((chip_scsi_id == i) ||
  2874. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2875. continue;
  2876. }
  2877. seq_printf(m, " %X:%c",
  2878. i,
  2879. (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2880. }
  2881. /* Current number of commands waiting for a device. */
  2882. seq_puts(m, "\n Command Queue Pending:");
  2883. for (i = 0; i <= ASC_MAX_TID; i++) {
  2884. if ((chip_scsi_id == i) ||
  2885. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2886. continue;
  2887. }
  2888. seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
  2889. }
  2890. /* Current limit on number of commands that can be sent to a device. */
  2891. seq_puts(m, "\n Command Queue Limit:");
  2892. for (i = 0; i <= ASC_MAX_TID; i++) {
  2893. if ((chip_scsi_id == i) ||
  2894. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2895. continue;
  2896. }
  2897. seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
  2898. }
  2899. /* Indicate whether the device has returned queue full status. */
  2900. seq_puts(m, "\n Command Queue Full:");
  2901. for (i = 0; i <= ASC_MAX_TID; i++) {
  2902. if ((chip_scsi_id == i) ||
  2903. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2904. continue;
  2905. }
  2906. if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
  2907. seq_printf(m, " %X:Y-%d",
  2908. i, boardp->queue_full_cnt[i]);
  2909. else
  2910. seq_printf(m, " %X:N", i);
  2911. }
  2912. seq_puts(m, "\n Synchronous Transfer:");
  2913. for (i = 0; i <= ASC_MAX_TID; i++) {
  2914. if ((chip_scsi_id == i) ||
  2915. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2916. continue;
  2917. }
  2918. seq_printf(m, " %X:%c",
  2919. i,
  2920. (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2921. }
  2922. seq_putc(m, '\n');
  2923. for (i = 0; i <= ASC_MAX_TID; i++) {
  2924. uchar syn_period_ix;
  2925. if ((chip_scsi_id == i) ||
  2926. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  2927. ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2928. continue;
  2929. }
  2930. seq_printf(m, " %X:", i);
  2931. if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
  2932. seq_puts(m, " Asynchronous");
  2933. } else {
  2934. syn_period_ix =
  2935. (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
  2936. 1);
  2937. seq_printf(m,
  2938. " Transfer Period Factor: %d (%d.%d Mhz),",
  2939. v->sdtr_period_tbl[syn_period_ix],
  2940. 250 / v->sdtr_period_tbl[syn_period_ix],
  2941. ASC_TENTHS(250,
  2942. v->sdtr_period_tbl[syn_period_ix]));
  2943. seq_printf(m, " REQ/ACK Offset: %d",
  2944. boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
  2945. }
  2946. if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  2947. seq_puts(m, "*\n");
  2948. renegotiate = 1;
  2949. } else {
  2950. seq_putc(m, '\n');
  2951. }
  2952. }
  2953. if (renegotiate) {
  2954. seq_puts(m, " * = Re-negotiation pending before next command.\n");
  2955. }
  2956. }
  2957. /*
  2958. * asc_prt_adv_board_info()
  2959. *
  2960. * Print dynamic board configuration information.
  2961. */
  2962. static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
  2963. {
  2964. struct asc_board *boardp = shost_priv(shost);
  2965. int i;
  2966. ADV_DVC_VAR *v;
  2967. ADV_DVC_CFG *c;
  2968. AdvPortAddr iop_base;
  2969. ushort chip_scsi_id;
  2970. ushort lramword;
  2971. uchar lrambyte;
  2972. ushort tagqng_able;
  2973. ushort sdtr_able, wdtr_able;
  2974. ushort wdtr_done, sdtr_done;
  2975. ushort period = 0;
  2976. int renegotiate = 0;
  2977. v = &boardp->dvc_var.adv_dvc_var;
  2978. c = &boardp->dvc_cfg.adv_dvc_cfg;
  2979. iop_base = v->iop_base;
  2980. chip_scsi_id = v->chip_scsi_id;
  2981. seq_printf(m,
  2982. "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  2983. shost->host_no);
  2984. seq_printf(m,
  2985. " iop_base 0x%p, cable_detect: %X, err_code %u\n",
  2986. v->iop_base,
  2987. AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
  2988. v->err_code);
  2989. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  2990. "mcode_version 0x%x\n", c->chip_version,
  2991. c->mcode_date, c->mcode_version);
  2992. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  2993. seq_puts(m, " Queuing Enabled:");
  2994. for (i = 0; i <= ADV_MAX_TID; i++) {
  2995. if ((chip_scsi_id == i) ||
  2996. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2997. continue;
  2998. }
  2999. seq_printf(m, " %X:%c",
  3000. i,
  3001. (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3002. }
  3003. seq_puts(m, "\n Queue Limit:");
  3004. for (i = 0; i <= ADV_MAX_TID; i++) {
  3005. if ((chip_scsi_id == i) ||
  3006. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3007. continue;
  3008. }
  3009. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
  3010. lrambyte);
  3011. seq_printf(m, " %X:%d", i, lrambyte);
  3012. }
  3013. seq_puts(m, "\n Command Pending:");
  3014. for (i = 0; i <= ADV_MAX_TID; i++) {
  3015. if ((chip_scsi_id == i) ||
  3016. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3017. continue;
  3018. }
  3019. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
  3020. lrambyte);
  3021. seq_printf(m, " %X:%d", i, lrambyte);
  3022. }
  3023. seq_putc(m, '\n');
  3024. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3025. seq_puts(m, " Wide Enabled:");
  3026. for (i = 0; i <= ADV_MAX_TID; i++) {
  3027. if ((chip_scsi_id == i) ||
  3028. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3029. continue;
  3030. }
  3031. seq_printf(m, " %X:%c",
  3032. i,
  3033. (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3034. }
  3035. seq_putc(m, '\n');
  3036. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
  3037. seq_puts(m, " Transfer Bit Width:");
  3038. for (i = 0; i <= ADV_MAX_TID; i++) {
  3039. if ((chip_scsi_id == i) ||
  3040. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3041. continue;
  3042. }
  3043. AdvReadWordLram(iop_base,
  3044. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3045. lramword);
  3046. seq_printf(m, " %X:%d",
  3047. i, (lramword & 0x8000) ? 16 : 8);
  3048. if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
  3049. (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3050. seq_putc(m, '*');
  3051. renegotiate = 1;
  3052. }
  3053. }
  3054. seq_putc(m, '\n');
  3055. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3056. seq_puts(m, " Synchronous Enabled:");
  3057. for (i = 0; i <= ADV_MAX_TID; i++) {
  3058. if ((chip_scsi_id == i) ||
  3059. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3060. continue;
  3061. }
  3062. seq_printf(m, " %X:%c",
  3063. i,
  3064. (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3065. }
  3066. seq_putc(m, '\n');
  3067. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
  3068. for (i = 0; i <= ADV_MAX_TID; i++) {
  3069. AdvReadWordLram(iop_base,
  3070. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3071. lramword);
  3072. lramword &= ~0x8000;
  3073. if ((chip_scsi_id == i) ||
  3074. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3075. ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3076. continue;
  3077. }
  3078. seq_printf(m, " %X:", i);
  3079. if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
  3080. seq_puts(m, " Asynchronous");
  3081. } else {
  3082. seq_puts(m, " Transfer Period Factor: ");
  3083. if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
  3084. seq_puts(m, "9 (80.0 Mhz),");
  3085. } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
  3086. seq_puts(m, "10 (40.0 Mhz),");
  3087. } else { /* 20 Mhz or below. */
  3088. period = (((lramword >> 8) * 25) + 50) / 4;
  3089. if (period == 0) { /* Should never happen. */
  3090. seq_printf(m, "%d (? Mhz), ", period);
  3091. } else {
  3092. seq_printf(m,
  3093. "%d (%d.%d Mhz),",
  3094. period, 250 / period,
  3095. ASC_TENTHS(250, period));
  3096. }
  3097. }
  3098. seq_printf(m, " REQ/ACK Offset: %d",
  3099. lramword & 0x1F);
  3100. }
  3101. if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3102. seq_puts(m, "*\n");
  3103. renegotiate = 1;
  3104. } else {
  3105. seq_putc(m, '\n');
  3106. }
  3107. }
  3108. if (renegotiate) {
  3109. seq_puts(m, " * = Re-negotiation pending before next command.\n");
  3110. }
  3111. }
  3112. #ifdef ADVANSYS_STATS
  3113. /*
  3114. * asc_prt_board_stats()
  3115. */
  3116. static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
  3117. {
  3118. struct asc_board *boardp = shost_priv(shost);
  3119. struct asc_stats *s = &boardp->asc_stats;
  3120. seq_printf(m,
  3121. "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
  3122. shost->host_no);
  3123. seq_printf(m,
  3124. " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
  3125. s->queuecommand, s->reset, s->biosparam,
  3126. s->interrupt);
  3127. seq_printf(m,
  3128. " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
  3129. s->callback, s->done, s->build_error,
  3130. s->adv_build_noreq, s->adv_build_nosg);
  3131. seq_printf(m,
  3132. " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
  3133. s->exe_noerror, s->exe_busy, s->exe_error,
  3134. s->exe_unknown);
  3135. /*
  3136. * Display data transfer statistics.
  3137. */
  3138. if (s->xfer_cnt > 0) {
  3139. seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
  3140. s->xfer_cnt, s->xfer_elem);
  3141. seq_printf(m, "xfer_bytes %u.%01u kb\n",
  3142. s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
  3143. /* Scatter gather transfer statistics */
  3144. seq_printf(m, " avg_num_elem %u.%01u, ",
  3145. s->xfer_elem / s->xfer_cnt,
  3146. ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
  3147. seq_printf(m, "avg_elem_size %u.%01u kb, ",
  3148. (s->xfer_sect / 2) / s->xfer_elem,
  3149. ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
  3150. seq_printf(m, "avg_xfer_size %u.%01u kb\n",
  3151. (s->xfer_sect / 2) / s->xfer_cnt,
  3152. ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
  3153. }
  3154. }
  3155. #endif /* ADVANSYS_STATS */
  3156. /*
  3157. * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
  3158. *
  3159. * m: seq_file to print into
  3160. * shost: Scsi_Host
  3161. *
  3162. * Return the number of bytes read from or written to a
  3163. * /proc/scsi/advansys/[0...] file.
  3164. */
  3165. static int
  3166. advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
  3167. {
  3168. struct asc_board *boardp = shost_priv(shost);
  3169. ASC_DBG(1, "begin\n");
  3170. /*
  3171. * User read of /proc/scsi/advansys/[0...] file.
  3172. */
  3173. /*
  3174. * Get board configuration information.
  3175. *
  3176. * advansys_info() returns the board string from its own static buffer.
  3177. */
  3178. /* Copy board information. */
  3179. seq_printf(m, "%s\n", (char *)advansys_info(shost));
  3180. /*
  3181. * Display Wide Board BIOS Information.
  3182. */
  3183. if (!ASC_NARROW_BOARD(boardp))
  3184. asc_prt_adv_bios(m, shost);
  3185. /*
  3186. * Display driver information for each device attached to the board.
  3187. */
  3188. asc_prt_board_devices(m, shost);
  3189. /*
  3190. * Display EEPROM configuration for the board.
  3191. */
  3192. if (ASC_NARROW_BOARD(boardp))
  3193. asc_prt_asc_board_eeprom(m, shost);
  3194. else
  3195. asc_prt_adv_board_eeprom(m, shost);
  3196. /*
  3197. * Display driver configuration and information for the board.
  3198. */
  3199. asc_prt_driver_conf(m, shost);
  3200. #ifdef ADVANSYS_STATS
  3201. /*
  3202. * Display driver statistics for the board.
  3203. */
  3204. asc_prt_board_stats(m, shost);
  3205. #endif /* ADVANSYS_STATS */
  3206. /*
  3207. * Display Asc Library dynamic configuration information
  3208. * for the board.
  3209. */
  3210. if (ASC_NARROW_BOARD(boardp))
  3211. asc_prt_asc_board_info(m, shost);
  3212. else
  3213. asc_prt_adv_board_info(m, shost);
  3214. return 0;
  3215. }
  3216. #endif /* CONFIG_PROC_FS */
  3217. static void asc_scsi_done(struct scsi_cmnd *scp)
  3218. {
  3219. scsi_dma_unmap(scp);
  3220. ASC_STATS(scp->device->host, done);
  3221. scsi_done(scp);
  3222. }
  3223. static void AscSetBank(PortAddr iop_base, uchar bank)
  3224. {
  3225. uchar val;
  3226. val = AscGetChipControl(iop_base) &
  3227. (~
  3228. (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
  3229. CC_CHIP_RESET));
  3230. if (bank == 1) {
  3231. val |= CC_BANK_ONE;
  3232. } else if (bank == 2) {
  3233. val |= CC_DIAG | CC_BANK_ONE;
  3234. } else {
  3235. val &= ~CC_BANK_ONE;
  3236. }
  3237. AscSetChipControl(iop_base, val);
  3238. }
  3239. static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
  3240. {
  3241. AscSetBank(iop_base, 1);
  3242. AscWriteChipIH(iop_base, ins_code);
  3243. AscSetBank(iop_base, 0);
  3244. }
  3245. static int AscStartChip(PortAddr iop_base)
  3246. {
  3247. AscSetChipControl(iop_base, 0);
  3248. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3249. return (0);
  3250. }
  3251. return (1);
  3252. }
  3253. static bool AscStopChip(PortAddr iop_base)
  3254. {
  3255. uchar cc_val;
  3256. cc_val =
  3257. AscGetChipControl(iop_base) &
  3258. (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
  3259. AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
  3260. AscSetChipIH(iop_base, INS_HALT);
  3261. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3262. if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
  3263. return false;
  3264. }
  3265. return true;
  3266. }
  3267. static bool AscIsChipHalted(PortAddr iop_base)
  3268. {
  3269. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3270. if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
  3271. return true;
  3272. }
  3273. }
  3274. return false;
  3275. }
  3276. static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
  3277. {
  3278. PortAddr iop_base;
  3279. int i = 10;
  3280. iop_base = asc_dvc->iop_base;
  3281. while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
  3282. && (i-- > 0)) {
  3283. mdelay(100);
  3284. }
  3285. AscStopChip(iop_base);
  3286. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
  3287. udelay(60);
  3288. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3289. AscSetChipIH(iop_base, INS_HALT);
  3290. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
  3291. AscSetChipControl(iop_base, CC_HALT);
  3292. mdelay(200);
  3293. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  3294. AscSetChipStatus(iop_base, 0);
  3295. return (AscIsChipHalted(iop_base));
  3296. }
  3297. static int AscFindSignature(PortAddr iop_base)
  3298. {
  3299. ushort sig_word;
  3300. ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
  3301. iop_base, AscGetChipSignatureByte(iop_base));
  3302. if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
  3303. ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
  3304. iop_base, AscGetChipSignatureWord(iop_base));
  3305. sig_word = AscGetChipSignatureWord(iop_base);
  3306. if ((sig_word == (ushort)ASC_1000_ID0W) ||
  3307. (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
  3308. return (1);
  3309. }
  3310. }
  3311. return (0);
  3312. }
  3313. static void AscEnableInterrupt(PortAddr iop_base)
  3314. {
  3315. ushort cfg;
  3316. cfg = AscGetChipCfgLsw(iop_base);
  3317. AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
  3318. }
  3319. static void AscDisableInterrupt(PortAddr iop_base)
  3320. {
  3321. ushort cfg;
  3322. cfg = AscGetChipCfgLsw(iop_base);
  3323. AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
  3324. }
  3325. static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
  3326. {
  3327. unsigned char byte_data;
  3328. unsigned short word_data;
  3329. if (isodd_word(addr)) {
  3330. AscSetChipLramAddr(iop_base, addr - 1);
  3331. word_data = AscGetChipLramData(iop_base);
  3332. byte_data = (word_data >> 8) & 0xFF;
  3333. } else {
  3334. AscSetChipLramAddr(iop_base, addr);
  3335. word_data = AscGetChipLramData(iop_base);
  3336. byte_data = word_data & 0xFF;
  3337. }
  3338. return byte_data;
  3339. }
  3340. static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
  3341. {
  3342. ushort word_data;
  3343. AscSetChipLramAddr(iop_base, addr);
  3344. word_data = AscGetChipLramData(iop_base);
  3345. return (word_data);
  3346. }
  3347. static void
  3348. AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
  3349. {
  3350. int i;
  3351. AscSetChipLramAddr(iop_base, s_addr);
  3352. for (i = 0; i < words; i++) {
  3353. AscSetChipLramData(iop_base, set_wval);
  3354. }
  3355. }
  3356. static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
  3357. {
  3358. AscSetChipLramAddr(iop_base, addr);
  3359. AscSetChipLramData(iop_base, word_val);
  3360. }
  3361. static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
  3362. {
  3363. ushort word_data;
  3364. if (isodd_word(addr)) {
  3365. addr--;
  3366. word_data = AscReadLramWord(iop_base, addr);
  3367. word_data &= 0x00FF;
  3368. word_data |= (((ushort)byte_val << 8) & 0xFF00);
  3369. } else {
  3370. word_data = AscReadLramWord(iop_base, addr);
  3371. word_data &= 0xFF00;
  3372. word_data |= ((ushort)byte_val & 0x00FF);
  3373. }
  3374. AscWriteLramWord(iop_base, addr, word_data);
  3375. }
  3376. /*
  3377. * Copy 2 bytes to LRAM.
  3378. *
  3379. * The source data is assumed to be in little-endian order in memory
  3380. * and is maintained in little-endian order when written to LRAM.
  3381. */
  3382. static void
  3383. AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
  3384. const uchar *s_buffer, int words)
  3385. {
  3386. int i;
  3387. AscSetChipLramAddr(iop_base, s_addr);
  3388. for (i = 0; i < 2 * words; i += 2) {
  3389. /*
  3390. * On a little-endian system the second argument below
  3391. * produces a little-endian ushort which is written to
  3392. * LRAM in little-endian order. On a big-endian system
  3393. * the second argument produces a big-endian ushort which
  3394. * is "transparently" byte-swapped by outpw() and written
  3395. * in little-endian order to LRAM.
  3396. */
  3397. outpw(iop_base + IOP_RAM_DATA,
  3398. ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
  3399. }
  3400. }
  3401. /*
  3402. * Copy 4 bytes to LRAM.
  3403. *
  3404. * The source data is assumed to be in little-endian order in memory
  3405. * and is maintained in little-endian order when written to LRAM.
  3406. */
  3407. static void
  3408. AscMemDWordCopyPtrToLram(PortAddr iop_base,
  3409. ushort s_addr, uchar *s_buffer, int dwords)
  3410. {
  3411. int i;
  3412. AscSetChipLramAddr(iop_base, s_addr);
  3413. for (i = 0; i < 4 * dwords; i += 4) {
  3414. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
  3415. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
  3416. }
  3417. }
  3418. /*
  3419. * Copy 2 bytes from LRAM.
  3420. *
  3421. * The source data is assumed to be in little-endian order in LRAM
  3422. * and is maintained in little-endian order when written to memory.
  3423. */
  3424. static void
  3425. AscMemWordCopyPtrFromLram(PortAddr iop_base,
  3426. ushort s_addr, uchar *d_buffer, int words)
  3427. {
  3428. int i;
  3429. ushort word;
  3430. AscSetChipLramAddr(iop_base, s_addr);
  3431. for (i = 0; i < 2 * words; i += 2) {
  3432. word = inpw(iop_base + IOP_RAM_DATA);
  3433. d_buffer[i] = word & 0xff;
  3434. d_buffer[i + 1] = (word >> 8) & 0xff;
  3435. }
  3436. }
  3437. static u32 AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
  3438. {
  3439. u32 sum = 0;
  3440. int i;
  3441. for (i = 0; i < words; i++, s_addr += 2) {
  3442. sum += AscReadLramWord(iop_base, s_addr);
  3443. }
  3444. return (sum);
  3445. }
  3446. static void AscInitLram(ASC_DVC_VAR *asc_dvc)
  3447. {
  3448. uchar i;
  3449. ushort s_addr;
  3450. PortAddr iop_base;
  3451. iop_base = asc_dvc->iop_base;
  3452. AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
  3453. (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
  3454. 64) >> 1));
  3455. i = ASC_MIN_ACTIVE_QNO;
  3456. s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
  3457. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3458. (uchar)(i + 1));
  3459. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3460. (uchar)(asc_dvc->max_total_qng));
  3461. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3462. (uchar)i);
  3463. i++;
  3464. s_addr += ASC_QBLK_SIZE;
  3465. for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
  3466. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3467. (uchar)(i + 1));
  3468. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3469. (uchar)(i - 1));
  3470. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3471. (uchar)i);
  3472. }
  3473. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3474. (uchar)ASC_QLINK_END);
  3475. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3476. (uchar)(asc_dvc->max_total_qng - 1));
  3477. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3478. (uchar)asc_dvc->max_total_qng);
  3479. i++;
  3480. s_addr += ASC_QBLK_SIZE;
  3481. for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
  3482. i++, s_addr += ASC_QBLK_SIZE) {
  3483. AscWriteLramByte(iop_base,
  3484. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
  3485. AscWriteLramByte(iop_base,
  3486. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
  3487. AscWriteLramByte(iop_base,
  3488. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
  3489. }
  3490. }
  3491. static u32
  3492. AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
  3493. const uchar *mcode_buf, ushort mcode_size)
  3494. {
  3495. u32 chksum;
  3496. ushort mcode_word_size;
  3497. ushort mcode_chksum;
  3498. /* Write the microcode buffer starting at LRAM address 0. */
  3499. mcode_word_size = (ushort)(mcode_size >> 1);
  3500. AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
  3501. AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
  3502. chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
  3503. ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
  3504. mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
  3505. (ushort)ASC_CODE_SEC_BEG,
  3506. (ushort)((mcode_size -
  3507. s_addr - (ushort)
  3508. ASC_CODE_SEC_BEG) /
  3509. 2));
  3510. ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
  3511. AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
  3512. AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
  3513. return chksum;
  3514. }
  3515. static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
  3516. {
  3517. PortAddr iop_base;
  3518. int i;
  3519. ushort lram_addr;
  3520. iop_base = asc_dvc->iop_base;
  3521. AscPutRiscVarFreeQHead(iop_base, 1);
  3522. AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3523. AscPutVarFreeQHead(iop_base, 1);
  3524. AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3525. AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
  3526. (uchar)((int)asc_dvc->max_total_qng + 1));
  3527. AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
  3528. (uchar)((int)asc_dvc->max_total_qng + 2));
  3529. AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
  3530. asc_dvc->max_total_qng);
  3531. AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
  3532. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  3533. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
  3534. AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
  3535. AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
  3536. AscPutQDoneInProgress(iop_base, 0);
  3537. lram_addr = ASC_QADR_BEG;
  3538. for (i = 0; i < 32; i++, lram_addr += 2) {
  3539. AscWriteLramWord(iop_base, lram_addr, 0);
  3540. }
  3541. }
  3542. static int AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
  3543. {
  3544. int i;
  3545. int warn_code;
  3546. PortAddr iop_base;
  3547. __le32 phy_addr;
  3548. __le32 phy_size;
  3549. struct asc_board *board = asc_dvc_to_board(asc_dvc);
  3550. iop_base = asc_dvc->iop_base;
  3551. warn_code = 0;
  3552. for (i = 0; i <= ASC_MAX_TID; i++) {
  3553. AscPutMCodeInitSDTRAtID(iop_base, i,
  3554. asc_dvc->cfg->sdtr_period_offset[i]);
  3555. }
  3556. AscInitQLinkVar(asc_dvc);
  3557. AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
  3558. asc_dvc->cfg->disc_enable);
  3559. AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
  3560. ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
  3561. /* Ensure overrun buffer is aligned on an 8 byte boundary. */
  3562. BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
  3563. asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
  3564. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3565. if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
  3566. warn_code = -ENOMEM;
  3567. goto err_dma_map;
  3568. }
  3569. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  3570. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  3571. (uchar *)&phy_addr, 1);
  3572. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  3573. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  3574. (uchar *)&phy_size, 1);
  3575. asc_dvc->cfg->mcode_date =
  3576. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  3577. asc_dvc->cfg->mcode_version =
  3578. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  3579. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  3580. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  3581. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  3582. warn_code = -EINVAL;
  3583. goto err_mcode_start;
  3584. }
  3585. if (AscStartChip(iop_base) != 1) {
  3586. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  3587. warn_code = -EIO;
  3588. goto err_mcode_start;
  3589. }
  3590. return warn_code;
  3591. err_mcode_start:
  3592. dma_unmap_single(board->dev, asc_dvc->overrun_dma,
  3593. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3594. err_dma_map:
  3595. asc_dvc->overrun_dma = 0;
  3596. return warn_code;
  3597. }
  3598. static int AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  3599. {
  3600. const struct firmware *fw;
  3601. const char fwname[] = "advansys/mcode.bin";
  3602. int err;
  3603. unsigned long chksum;
  3604. int warn_code;
  3605. PortAddr iop_base;
  3606. iop_base = asc_dvc->iop_base;
  3607. warn_code = 0;
  3608. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  3609. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  3610. AscResetChipAndScsiBus(asc_dvc);
  3611. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3612. }
  3613. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  3614. if (asc_dvc->err_code != 0)
  3615. return ASC_ERROR;
  3616. if (!AscFindSignature(asc_dvc->iop_base)) {
  3617. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  3618. return warn_code;
  3619. }
  3620. AscDisableInterrupt(iop_base);
  3621. AscInitLram(asc_dvc);
  3622. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3623. if (err) {
  3624. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  3625. fwname, err);
  3626. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3627. return err;
  3628. }
  3629. if (fw->size < 4) {
  3630. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  3631. fw->size, fwname);
  3632. release_firmware(fw);
  3633. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3634. return -EINVAL;
  3635. }
  3636. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  3637. (fw->data[1] << 8) | fw->data[0];
  3638. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  3639. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  3640. fw->size - 4) != chksum) {
  3641. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3642. release_firmware(fw);
  3643. return warn_code;
  3644. }
  3645. release_firmware(fw);
  3646. warn_code |= AscInitMicroCodeVar(asc_dvc);
  3647. if (!asc_dvc->overrun_dma)
  3648. return warn_code;
  3649. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  3650. AscEnableInterrupt(iop_base);
  3651. return warn_code;
  3652. }
  3653. /*
  3654. * Load the Microcode
  3655. *
  3656. * Write the microcode image to RISC memory starting at address 0.
  3657. *
  3658. * The microcode is stored compressed in the following format:
  3659. *
  3660. * 254 word (508 byte) table indexed by byte code followed
  3661. * by the following byte codes:
  3662. *
  3663. * 1-Byte Code:
  3664. * 00: Emit word 0 in table.
  3665. * 01: Emit word 1 in table.
  3666. * .
  3667. * FD: Emit word 253 in table.
  3668. *
  3669. * Multi-Byte Code:
  3670. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  3671. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  3672. *
  3673. * Returns 0 or an error if the checksum doesn't match
  3674. */
  3675. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  3676. int size, int memsize, int chksum)
  3677. {
  3678. int i, j, end, len = 0;
  3679. u32 sum;
  3680. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3681. for (i = 253 * 2; i < size; i++) {
  3682. if (buf[i] == 0xff) {
  3683. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  3684. for (j = 0; j < buf[i + 1]; j++) {
  3685. AdvWriteWordAutoIncLram(iop_base, word);
  3686. len += 2;
  3687. }
  3688. i += 3;
  3689. } else if (buf[i] == 0xfe) {
  3690. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  3691. AdvWriteWordAutoIncLram(iop_base, word);
  3692. i += 2;
  3693. len += 2;
  3694. } else {
  3695. unsigned int off = buf[i] * 2;
  3696. unsigned short word = (buf[off + 1] << 8) | buf[off];
  3697. AdvWriteWordAutoIncLram(iop_base, word);
  3698. len += 2;
  3699. }
  3700. }
  3701. end = len;
  3702. while (len < memsize) {
  3703. AdvWriteWordAutoIncLram(iop_base, 0);
  3704. len += 2;
  3705. }
  3706. /* Verify the microcode checksum. */
  3707. sum = 0;
  3708. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3709. for (len = 0; len < end; len += 2) {
  3710. sum += AdvReadWordAutoIncLram(iop_base);
  3711. }
  3712. if (sum != chksum)
  3713. return ASC_IERR_MCODE_CHKSUM;
  3714. return 0;
  3715. }
  3716. static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc)
  3717. {
  3718. off_t carr_offset = 0, next_offset;
  3719. dma_addr_t carr_paddr;
  3720. int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i;
  3721. for (i = 0; i < carr_num; i++) {
  3722. carr_offset = i * sizeof(ADV_CARR_T);
  3723. /* Get physical address of the carrier 'carrp'. */
  3724. carr_paddr = adv_dvc->carrier_addr + carr_offset;
  3725. adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr);
  3726. adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset);
  3727. adv_dvc->carrier[i].areq_vpa = 0;
  3728. next_offset = carr_offset + sizeof(ADV_CARR_T);
  3729. if (i == carr_num)
  3730. next_offset = ~0;
  3731. adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset);
  3732. }
  3733. /*
  3734. * We cannot have a carrier with 'carr_va' of '0', as
  3735. * a reference to this carrier would be interpreted as
  3736. * list termination.
  3737. * So start at carrier 1 with the freelist.
  3738. */
  3739. adv_dvc->carr_freelist = &adv_dvc->carrier[1];
  3740. }
  3741. static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset)
  3742. {
  3743. int index;
  3744. BUG_ON(offset > ADV_CARRIER_BUFSIZE);
  3745. index = offset / sizeof(ADV_CARR_T);
  3746. return &adv_dvc->carrier[index];
  3747. }
  3748. static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc)
  3749. {
  3750. ADV_CARR_T *carrp = adv_dvc->carr_freelist;
  3751. u32 next_vpa = le32_to_cpu(carrp->next_vpa);
  3752. if (next_vpa == 0 || next_vpa == ~0) {
  3753. ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa);
  3754. return NULL;
  3755. }
  3756. adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa);
  3757. /*
  3758. * insert stopper carrier to terminate list
  3759. */
  3760. carrp->next_vpa = cpu_to_le32(ADV_CQ_STOPPER);
  3761. return carrp;
  3762. }
  3763. /*
  3764. * 'offset' is the index in the request pointer array
  3765. */
  3766. static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset)
  3767. {
  3768. struct asc_board *boardp = adv_dvc->drv_ptr;
  3769. BUG_ON(offset > adv_dvc->max_host_qng);
  3770. return &boardp->adv_reqp[offset];
  3771. }
  3772. /*
  3773. * Send an idle command to the chip and wait for completion.
  3774. *
  3775. * Command completion is polled for once per microsecond.
  3776. *
  3777. * The function can be called from anywhere including an interrupt handler.
  3778. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  3779. * functions to prevent reentrancy.
  3780. *
  3781. * Return Values:
  3782. * ADV_TRUE - command completed successfully
  3783. * ADV_FALSE - command failed
  3784. * ADV_ERROR - command timed out
  3785. */
  3786. static int
  3787. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  3788. ushort idle_cmd, u32 idle_cmd_parameter)
  3789. {
  3790. int result, i, j;
  3791. AdvPortAddr iop_base;
  3792. iop_base = asc_dvc->iop_base;
  3793. /*
  3794. * Clear the idle command status which is set by the microcode
  3795. * to a non-zero value to indicate when the command is completed.
  3796. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  3797. */
  3798. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  3799. /*
  3800. * Write the idle command value after the idle command parameter
  3801. * has been written to avoid a race condition. If the order is not
  3802. * followed, the microcode may process the idle command before the
  3803. * parameters have been written to LRAM.
  3804. */
  3805. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  3806. cpu_to_le32(idle_cmd_parameter));
  3807. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  3808. /*
  3809. * Tickle the RISC to tell it to process the idle command.
  3810. */
  3811. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  3812. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  3813. /*
  3814. * Clear the tickle value. In the ASC-3550 the RISC flag
  3815. * command 'clr_tickle_b' does not work unless the host
  3816. * value is cleared.
  3817. */
  3818. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  3819. }
  3820. /* Wait for up to 100 millisecond for the idle command to timeout. */
  3821. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  3822. /* Poll once each microsecond for command completion. */
  3823. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  3824. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  3825. result);
  3826. if (result != 0)
  3827. return result;
  3828. udelay(1);
  3829. }
  3830. }
  3831. BUG(); /* The idle command should never timeout. */
  3832. return ADV_ERROR;
  3833. }
  3834. /*
  3835. * Reset SCSI Bus and purge all outstanding requests.
  3836. *
  3837. * Return Value:
  3838. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  3839. * ADV_FALSE(0) - Microcode command failed.
  3840. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  3841. * may be hung which requires driver recovery.
  3842. */
  3843. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  3844. {
  3845. int status;
  3846. /*
  3847. * Send the SCSI Bus Reset idle start idle command which asserts
  3848. * the SCSI Bus Reset signal.
  3849. */
  3850. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  3851. if (status != ADV_TRUE) {
  3852. return status;
  3853. }
  3854. /*
  3855. * Delay for the specified SCSI Bus Reset hold time.
  3856. *
  3857. * The hold time delay is done on the host because the RISC has no
  3858. * microsecond accurate timer.
  3859. */
  3860. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  3861. /*
  3862. * Send the SCSI Bus Reset end idle command which de-asserts
  3863. * the SCSI Bus Reset signal and purges any pending requests.
  3864. */
  3865. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  3866. if (status != ADV_TRUE) {
  3867. return status;
  3868. }
  3869. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3870. return status;
  3871. }
  3872. /*
  3873. * Initialize the ASC-3550.
  3874. *
  3875. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  3876. *
  3877. * For a non-fatal error return a warning code. If there are no warnings
  3878. * then 0 is returned.
  3879. *
  3880. * Needed after initialization for error recovery.
  3881. */
  3882. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  3883. {
  3884. const struct firmware *fw;
  3885. const char fwname[] = "advansys/3550.bin";
  3886. AdvPortAddr iop_base;
  3887. ushort warn_code;
  3888. int begin_addr;
  3889. int end_addr;
  3890. ushort code_sum;
  3891. int word;
  3892. int i;
  3893. int err;
  3894. unsigned long chksum;
  3895. ushort scsi_cfg1;
  3896. uchar tid;
  3897. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  3898. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  3899. uchar max_cmd[ADV_MAX_TID + 1];
  3900. /* If there is already an error, don't continue. */
  3901. if (asc_dvc->err_code != 0)
  3902. return ADV_ERROR;
  3903. /*
  3904. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  3905. */
  3906. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  3907. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  3908. return ADV_ERROR;
  3909. }
  3910. warn_code = 0;
  3911. iop_base = asc_dvc->iop_base;
  3912. /*
  3913. * Save the RISC memory BIOS region before writing the microcode.
  3914. * The BIOS may already be loaded and using its RISC LRAM region
  3915. * so its region must be saved and restored.
  3916. *
  3917. * Note: This code makes the assumption, which is currently true,
  3918. * that a chip reset does not clear RISC LRAM.
  3919. */
  3920. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  3921. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  3922. bios_mem[i]);
  3923. }
  3924. /*
  3925. * Save current per TID negotiated values.
  3926. */
  3927. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  3928. ushort bios_version, major, minor;
  3929. bios_version =
  3930. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  3931. major = (bios_version >> 12) & 0xF;
  3932. minor = (bios_version >> 8) & 0xF;
  3933. if (major < 3 || (major == 3 && minor == 1)) {
  3934. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  3935. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  3936. } else {
  3937. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3938. }
  3939. }
  3940. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3941. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3942. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  3943. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  3944. max_cmd[tid]);
  3945. }
  3946. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3947. if (err) {
  3948. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  3949. fwname, err);
  3950. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  3951. return err;
  3952. }
  3953. if (fw->size < 4) {
  3954. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  3955. fw->size, fwname);
  3956. release_firmware(fw);
  3957. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  3958. return -EINVAL;
  3959. }
  3960. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  3961. (fw->data[1] << 8) | fw->data[0];
  3962. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  3963. fw->size - 4, ADV_3550_MEMSIZE,
  3964. chksum);
  3965. release_firmware(fw);
  3966. if (asc_dvc->err_code)
  3967. return ADV_ERROR;
  3968. /*
  3969. * Restore the RISC memory BIOS region.
  3970. */
  3971. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  3972. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  3973. bios_mem[i]);
  3974. }
  3975. /*
  3976. * Calculate and write the microcode code checksum to the microcode
  3977. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  3978. */
  3979. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  3980. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  3981. code_sum = 0;
  3982. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  3983. for (word = begin_addr; word < end_addr; word += 2) {
  3984. code_sum += AdvReadWordAutoIncLram(iop_base);
  3985. }
  3986. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  3987. /*
  3988. * Read and save microcode version and date.
  3989. */
  3990. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  3991. asc_dvc->cfg->mcode_date);
  3992. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  3993. asc_dvc->cfg->mcode_version);
  3994. /*
  3995. * Set the chip type to indicate the ASC3550.
  3996. */
  3997. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  3998. /*
  3999. * If the PCI Configuration Command Register "Parity Error Response
  4000. * Control" Bit was clear (0), then set the microcode variable
  4001. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4002. * to ignore DMA parity errors.
  4003. */
  4004. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4005. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4006. word |= CONTROL_FLAG_IGNORE_PERR;
  4007. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4008. }
  4009. /*
  4010. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4011. * threshold of 128 bytes. This register is only accessible to the host.
  4012. */
  4013. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4014. START_CTL_EMFU | READ_CMD_MRM);
  4015. /*
  4016. * Microcode operating variables for WDTR, SDTR, and command tag
  4017. * queuing will be set in slave_configure() based on what a
  4018. * device reports it is capable of in Inquiry byte 7.
  4019. *
  4020. * If SCSI Bus Resets have been disabled, then directly set
  4021. * SDTR and WDTR from the EEPROM configuration. This will allow
  4022. * the BIOS and warm boot to work without a SCSI bus hang on
  4023. * the Inquiry caused by host and target mismatched DTR values.
  4024. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4025. * be assumed to be in Asynchronous, Narrow mode.
  4026. */
  4027. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4028. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4029. asc_dvc->wdtr_able);
  4030. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4031. asc_dvc->sdtr_able);
  4032. }
  4033. /*
  4034. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4035. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4036. * bitmask. These values determine the maximum SDTR speed negotiated
  4037. * with a device.
  4038. *
  4039. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4040. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4041. * without determining here whether the device supports SDTR.
  4042. *
  4043. * 4-bit speed SDTR speed name
  4044. * =========== ===============
  4045. * 0000b (0x0) SDTR disabled
  4046. * 0001b (0x1) 5 Mhz
  4047. * 0010b (0x2) 10 Mhz
  4048. * 0011b (0x3) 20 Mhz (Ultra)
  4049. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4050. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4051. * 0110b (0x6) Undefined
  4052. * .
  4053. * 1111b (0xF) Undefined
  4054. */
  4055. word = 0;
  4056. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4057. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4058. /* Set Ultra speed for TID 'tid'. */
  4059. word |= (0x3 << (4 * (tid % 4)));
  4060. } else {
  4061. /* Set Fast speed for TID 'tid'. */
  4062. word |= (0x2 << (4 * (tid % 4)));
  4063. }
  4064. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4065. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4066. word = 0;
  4067. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4068. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4069. word = 0;
  4070. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4071. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4072. word = 0;
  4073. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4074. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4075. /* End of loop. */
  4076. }
  4077. }
  4078. /*
  4079. * Set microcode operating variable for the disconnect per TID bitmask.
  4080. */
  4081. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4082. asc_dvc->cfg->disc_enable);
  4083. /*
  4084. * Set SCSI_CFG0 Microcode Default Value.
  4085. *
  4086. * The microcode will set the SCSI_CFG0 register using this value
  4087. * after it is started below.
  4088. */
  4089. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4090. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4091. asc_dvc->chip_scsi_id);
  4092. /*
  4093. * Determine SCSI_CFG1 Microcode Default Value.
  4094. *
  4095. * The microcode will set the SCSI_CFG1 register using this value
  4096. * after it is started below.
  4097. */
  4098. /* Read current SCSI_CFG1 Register value. */
  4099. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4100. /*
  4101. * If all three connectors are in use, return an error.
  4102. */
  4103. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4104. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4105. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4106. return ADV_ERROR;
  4107. }
  4108. /*
  4109. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4110. * register signals will be set. Check for and return an error if
  4111. * this condition is found.
  4112. */
  4113. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4114. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4115. return ADV_ERROR;
  4116. }
  4117. /*
  4118. * If this is a differential board and a single-ended device
  4119. * is attached to one of the connectors, return an error.
  4120. */
  4121. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4122. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4123. return ADV_ERROR;
  4124. }
  4125. /*
  4126. * If automatic termination control is enabled, then set the
  4127. * termination value based on a table listed in a_condor.h.
  4128. *
  4129. * If manual termination was specified with an EEPROM setting
  4130. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4131. * is ready to be 'ored' into SCSI_CFG1.
  4132. */
  4133. if (asc_dvc->cfg->termination == 0) {
  4134. /*
  4135. * The software always controls termination by setting TERM_CTL_SEL.
  4136. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4137. */
  4138. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4139. switch (scsi_cfg1 & CABLE_DETECT) {
  4140. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4141. case 0x3:
  4142. case 0x7:
  4143. case 0xB:
  4144. case 0xD:
  4145. case 0xE:
  4146. case 0xF:
  4147. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4148. break;
  4149. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4150. case 0x1:
  4151. case 0x5:
  4152. case 0x9:
  4153. case 0xA:
  4154. case 0xC:
  4155. asc_dvc->cfg->termination |= TERM_CTL_H;
  4156. break;
  4157. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4158. case 0x2:
  4159. case 0x6:
  4160. break;
  4161. }
  4162. }
  4163. /*
  4164. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4165. */
  4166. scsi_cfg1 &= ~TERM_CTL;
  4167. /*
  4168. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4169. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4170. * referenced, because the hardware internally inverts
  4171. * the Termination High and Low bits if TERM_POL is set.
  4172. */
  4173. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4174. /*
  4175. * Set SCSI_CFG1 Microcode Default Value
  4176. *
  4177. * Set filter value and possibly modified termination control
  4178. * bits in the Microcode SCSI_CFG1 Register Value.
  4179. *
  4180. * The microcode will set the SCSI_CFG1 register using this value
  4181. * after it is started below.
  4182. */
  4183. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4184. FLTR_DISABLE | scsi_cfg1);
  4185. /*
  4186. * Set MEM_CFG Microcode Default Value
  4187. *
  4188. * The microcode will set the MEM_CFG register using this value
  4189. * after it is started below.
  4190. *
  4191. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4192. * are defined.
  4193. *
  4194. * ASC-3550 has 8KB internal memory.
  4195. */
  4196. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4197. BIOS_EN | RAM_SZ_8KB);
  4198. /*
  4199. * Set SEL_MASK Microcode Default Value
  4200. *
  4201. * The microcode will set the SEL_MASK register using this value
  4202. * after it is started below.
  4203. */
  4204. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4205. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4206. AdvBuildCarrierFreelist(asc_dvc);
  4207. /*
  4208. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4209. */
  4210. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  4211. if (!asc_dvc->icq_sp) {
  4212. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4213. return ADV_ERROR;
  4214. }
  4215. /*
  4216. * Set RISC ICQ physical address start value.
  4217. */
  4218. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4219. /*
  4220. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4221. */
  4222. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  4223. if (!asc_dvc->irq_sp) {
  4224. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4225. return ADV_ERROR;
  4226. }
  4227. /*
  4228. * Set RISC IRQ physical address start value.
  4229. */
  4230. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4231. asc_dvc->carr_pending_cnt = 0;
  4232. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4233. (ADV_INTR_ENABLE_HOST_INTR |
  4234. ADV_INTR_ENABLE_GLOBAL_INTR));
  4235. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4236. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4237. /* finally, finally, gentlemen, start your engine */
  4238. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4239. /*
  4240. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4241. * Resets should be performed. The RISC has to be running
  4242. * to issue a SCSI Bus Reset.
  4243. */
  4244. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4245. /*
  4246. * If the BIOS Signature is present in memory, restore the
  4247. * BIOS Handshake Configuration Table and do not perform
  4248. * a SCSI Bus Reset.
  4249. */
  4250. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4251. 0x55AA) {
  4252. /*
  4253. * Restore per TID negotiated values.
  4254. */
  4255. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4256. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4257. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4258. tagqng_able);
  4259. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4260. AdvWriteByteLram(iop_base,
  4261. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4262. max_cmd[tid]);
  4263. }
  4264. } else {
  4265. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4266. warn_code = ASC_WARN_BUSRESET_ERROR;
  4267. }
  4268. }
  4269. }
  4270. return warn_code;
  4271. }
  4272. /*
  4273. * Initialize the ASC-38C0800.
  4274. *
  4275. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4276. *
  4277. * For a non-fatal error return a warning code. If there are no warnings
  4278. * then 0 is returned.
  4279. *
  4280. * Needed after initialization for error recovery.
  4281. */
  4282. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4283. {
  4284. const struct firmware *fw;
  4285. const char fwname[] = "advansys/38C0800.bin";
  4286. AdvPortAddr iop_base;
  4287. ushort warn_code;
  4288. int begin_addr;
  4289. int end_addr;
  4290. ushort code_sum;
  4291. int word;
  4292. int i;
  4293. int err;
  4294. unsigned long chksum;
  4295. ushort scsi_cfg1;
  4296. uchar byte;
  4297. uchar tid;
  4298. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4299. ushort wdtr_able, sdtr_able, tagqng_able;
  4300. uchar max_cmd[ADV_MAX_TID + 1];
  4301. /* If there is already an error, don't continue. */
  4302. if (asc_dvc->err_code != 0)
  4303. return ADV_ERROR;
  4304. /*
  4305. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4306. */
  4307. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4308. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4309. return ADV_ERROR;
  4310. }
  4311. warn_code = 0;
  4312. iop_base = asc_dvc->iop_base;
  4313. /*
  4314. * Save the RISC memory BIOS region before writing the microcode.
  4315. * The BIOS may already be loaded and using its RISC LRAM region
  4316. * so its region must be saved and restored.
  4317. *
  4318. * Note: This code makes the assumption, which is currently true,
  4319. * that a chip reset does not clear RISC LRAM.
  4320. */
  4321. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4322. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4323. bios_mem[i]);
  4324. }
  4325. /*
  4326. * Save current per TID negotiated values.
  4327. */
  4328. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4329. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4330. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4331. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4332. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4333. max_cmd[tid]);
  4334. }
  4335. /*
  4336. * RAM BIST (RAM Built-In Self Test)
  4337. *
  4338. * Address : I/O base + offset 0x38h register (byte).
  4339. * Function: Bit 7-6(RW) : RAM mode
  4340. * Normal Mode : 0x00
  4341. * Pre-test Mode : 0x40
  4342. * RAM Test Mode : 0x80
  4343. * Bit 5 : unused
  4344. * Bit 4(RO) : Done bit
  4345. * Bit 3-0(RO) : Status
  4346. * Host Error : 0x08
  4347. * Int_RAM Error : 0x04
  4348. * RISC Error : 0x02
  4349. * SCSI Error : 0x01
  4350. * No Error : 0x00
  4351. *
  4352. * Note: RAM BIST code should be put right here, before loading the
  4353. * microcode and after saving the RISC memory BIOS region.
  4354. */
  4355. /*
  4356. * LRAM Pre-test
  4357. *
  4358. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4359. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4360. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4361. * to NORMAL_MODE, return an error too.
  4362. */
  4363. for (i = 0; i < 2; i++) {
  4364. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4365. mdelay(10); /* Wait for 10ms before reading back. */
  4366. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4367. if ((byte & RAM_TEST_DONE) == 0
  4368. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4369. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4370. return ADV_ERROR;
  4371. }
  4372. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4373. mdelay(10); /* Wait for 10ms before reading back. */
  4374. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4375. != NORMAL_VALUE) {
  4376. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4377. return ADV_ERROR;
  4378. }
  4379. }
  4380. /*
  4381. * LRAM Test - It takes about 1.5 ms to run through the test.
  4382. *
  4383. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4384. * If Done bit not set or Status not 0, save register byte, set the
  4385. * err_code, and return an error.
  4386. */
  4387. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4388. mdelay(10); /* Wait for 10ms before checking status. */
  4389. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4390. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4391. /* Get here if Done bit not set or Status not 0. */
  4392. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4393. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4394. return ADV_ERROR;
  4395. }
  4396. /* We need to reset back to normal mode after LRAM test passes. */
  4397. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4398. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4399. if (err) {
  4400. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4401. fwname, err);
  4402. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4403. return err;
  4404. }
  4405. if (fw->size < 4) {
  4406. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4407. fw->size, fwname);
  4408. release_firmware(fw);
  4409. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4410. return -EINVAL;
  4411. }
  4412. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4413. (fw->data[1] << 8) | fw->data[0];
  4414. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4415. fw->size - 4, ADV_38C0800_MEMSIZE,
  4416. chksum);
  4417. release_firmware(fw);
  4418. if (asc_dvc->err_code)
  4419. return ADV_ERROR;
  4420. /*
  4421. * Restore the RISC memory BIOS region.
  4422. */
  4423. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4424. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4425. bios_mem[i]);
  4426. }
  4427. /*
  4428. * Calculate and write the microcode code checksum to the microcode
  4429. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4430. */
  4431. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4432. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4433. code_sum = 0;
  4434. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4435. for (word = begin_addr; word < end_addr; word += 2) {
  4436. code_sum += AdvReadWordAutoIncLram(iop_base);
  4437. }
  4438. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4439. /*
  4440. * Read microcode version and date.
  4441. */
  4442. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4443. asc_dvc->cfg->mcode_date);
  4444. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4445. asc_dvc->cfg->mcode_version);
  4446. /*
  4447. * Set the chip type to indicate the ASC38C0800.
  4448. */
  4449. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  4450. /*
  4451. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4452. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4453. * cable detection and then we are able to read C_DET[3:0].
  4454. *
  4455. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4456. * Microcode Default Value' section below.
  4457. */
  4458. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4459. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4460. scsi_cfg1 | DIS_TERM_DRV);
  4461. /*
  4462. * If the PCI Configuration Command Register "Parity Error Response
  4463. * Control" Bit was clear (0), then set the microcode variable
  4464. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4465. * to ignore DMA parity errors.
  4466. */
  4467. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4468. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4469. word |= CONTROL_FLAG_IGNORE_PERR;
  4470. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4471. }
  4472. /*
  4473. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  4474. * bits for the default FIFO threshold.
  4475. *
  4476. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  4477. *
  4478. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  4479. */
  4480. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4481. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  4482. READ_CMD_MRM);
  4483. /*
  4484. * Microcode operating variables for WDTR, SDTR, and command tag
  4485. * queuing will be set in slave_configure() based on what a
  4486. * device reports it is capable of in Inquiry byte 7.
  4487. *
  4488. * If SCSI Bus Resets have been disabled, then directly set
  4489. * SDTR and WDTR from the EEPROM configuration. This will allow
  4490. * the BIOS and warm boot to work without a SCSI bus hang on
  4491. * the Inquiry caused by host and target mismatched DTR values.
  4492. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4493. * be assumed to be in Asynchronous, Narrow mode.
  4494. */
  4495. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4496. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4497. asc_dvc->wdtr_able);
  4498. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4499. asc_dvc->sdtr_able);
  4500. }
  4501. /*
  4502. * Set microcode operating variables for DISC and SDTR_SPEED1,
  4503. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  4504. * configuration values.
  4505. *
  4506. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4507. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4508. * without determining here whether the device supports SDTR.
  4509. */
  4510. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4511. asc_dvc->cfg->disc_enable);
  4512. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  4513. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  4514. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  4515. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  4516. /*
  4517. * Set SCSI_CFG0 Microcode Default Value.
  4518. *
  4519. * The microcode will set the SCSI_CFG0 register using this value
  4520. * after it is started below.
  4521. */
  4522. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4523. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4524. asc_dvc->chip_scsi_id);
  4525. /*
  4526. * Determine SCSI_CFG1 Microcode Default Value.
  4527. *
  4528. * The microcode will set the SCSI_CFG1 register using this value
  4529. * after it is started below.
  4530. */
  4531. /* Read current SCSI_CFG1 Register value. */
  4532. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4533. /*
  4534. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4535. * register signals will be set. Check for and return an error if
  4536. * this condition is found.
  4537. */
  4538. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4539. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4540. return ADV_ERROR;
  4541. }
  4542. /*
  4543. * All kind of combinations of devices attached to one of four
  4544. * connectors are acceptable except HVD device attached. For example,
  4545. * LVD device can be attached to SE connector while SE device attached
  4546. * to LVD connector. If LVD device attached to SE connector, it only
  4547. * runs up to Ultra speed.
  4548. *
  4549. * If an HVD device is attached to one of LVD connectors, return an
  4550. * error. However, there is no way to detect HVD device attached to
  4551. * SE connectors.
  4552. */
  4553. if (scsi_cfg1 & HVD) {
  4554. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  4555. return ADV_ERROR;
  4556. }
  4557. /*
  4558. * If either SE or LVD automatic termination control is enabled, then
  4559. * set the termination value based on a table listed in a_condor.h.
  4560. *
  4561. * If manual termination was specified with an EEPROM setting then
  4562. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  4563. * to be 'ored' into SCSI_CFG1.
  4564. */
  4565. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  4566. /* SE automatic termination control is enabled. */
  4567. switch (scsi_cfg1 & C_DET_SE) {
  4568. /* TERM_SE_HI: on, TERM_SE_LO: on */
  4569. case 0x1:
  4570. case 0x2:
  4571. case 0x3:
  4572. asc_dvc->cfg->termination |= TERM_SE;
  4573. break;
  4574. /* TERM_SE_HI: on, TERM_SE_LO: off */
  4575. case 0x0:
  4576. asc_dvc->cfg->termination |= TERM_SE_HI;
  4577. break;
  4578. }
  4579. }
  4580. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  4581. /* LVD automatic termination control is enabled. */
  4582. switch (scsi_cfg1 & C_DET_LVD) {
  4583. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  4584. case 0x4:
  4585. case 0x8:
  4586. case 0xC:
  4587. asc_dvc->cfg->termination |= TERM_LVD;
  4588. break;
  4589. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  4590. case 0x0:
  4591. break;
  4592. }
  4593. }
  4594. /*
  4595. * Clear any set TERM_SE and TERM_LVD bits.
  4596. */
  4597. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  4598. /*
  4599. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  4600. */
  4601. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  4602. /*
  4603. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  4604. * bits and set possibly modified termination control bits in the
  4605. * Microcode SCSI_CFG1 Register Value.
  4606. */
  4607. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  4608. /*
  4609. * Set SCSI_CFG1 Microcode Default Value
  4610. *
  4611. * Set possibly modified termination control and reset DIS_TERM_DRV
  4612. * bits in the Microcode SCSI_CFG1 Register Value.
  4613. *
  4614. * The microcode will set the SCSI_CFG1 register using this value
  4615. * after it is started below.
  4616. */
  4617. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  4618. /*
  4619. * Set MEM_CFG Microcode Default Value
  4620. *
  4621. * The microcode will set the MEM_CFG register using this value
  4622. * after it is started below.
  4623. *
  4624. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4625. * are defined.
  4626. *
  4627. * ASC-38C0800 has 16KB internal memory.
  4628. */
  4629. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4630. BIOS_EN | RAM_SZ_16KB);
  4631. /*
  4632. * Set SEL_MASK Microcode Default Value
  4633. *
  4634. * The microcode will set the SEL_MASK register using this value
  4635. * after it is started below.
  4636. */
  4637. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4638. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4639. AdvBuildCarrierFreelist(asc_dvc);
  4640. /*
  4641. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4642. */
  4643. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  4644. if (!asc_dvc->icq_sp) {
  4645. ASC_DBG(0, "Failed to get ICQ carrier\n");
  4646. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4647. return ADV_ERROR;
  4648. }
  4649. /*
  4650. * Set RISC ICQ physical address start value.
  4651. * carr_pa is LE, must be native before write
  4652. */
  4653. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4654. /*
  4655. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4656. */
  4657. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  4658. if (!asc_dvc->irq_sp) {
  4659. ASC_DBG(0, "Failed to get IRQ carrier\n");
  4660. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4661. return ADV_ERROR;
  4662. }
  4663. /*
  4664. * Set RISC IRQ physical address start value.
  4665. *
  4666. * carr_pa is LE, must be native before write *
  4667. */
  4668. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4669. asc_dvc->carr_pending_cnt = 0;
  4670. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4671. (ADV_INTR_ENABLE_HOST_INTR |
  4672. ADV_INTR_ENABLE_GLOBAL_INTR));
  4673. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4674. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4675. /* finally, finally, gentlemen, start your engine */
  4676. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4677. /*
  4678. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4679. * Resets should be performed. The RISC has to be running
  4680. * to issue a SCSI Bus Reset.
  4681. */
  4682. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4683. /*
  4684. * If the BIOS Signature is present in memory, restore the
  4685. * BIOS Handshake Configuration Table and do not perform
  4686. * a SCSI Bus Reset.
  4687. */
  4688. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4689. 0x55AA) {
  4690. /*
  4691. * Restore per TID negotiated values.
  4692. */
  4693. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4694. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4695. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4696. tagqng_able);
  4697. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4698. AdvWriteByteLram(iop_base,
  4699. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4700. max_cmd[tid]);
  4701. }
  4702. } else {
  4703. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4704. warn_code = ASC_WARN_BUSRESET_ERROR;
  4705. }
  4706. }
  4707. }
  4708. return warn_code;
  4709. }
  4710. /*
  4711. * Initialize the ASC-38C1600.
  4712. *
  4713. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  4714. *
  4715. * For a non-fatal error return a warning code. If there are no warnings
  4716. * then 0 is returned.
  4717. *
  4718. * Needed after initialization for error recovery.
  4719. */
  4720. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  4721. {
  4722. const struct firmware *fw;
  4723. const char fwname[] = "advansys/38C1600.bin";
  4724. AdvPortAddr iop_base;
  4725. ushort warn_code;
  4726. int begin_addr;
  4727. int end_addr;
  4728. ushort code_sum;
  4729. long word;
  4730. int i;
  4731. int err;
  4732. unsigned long chksum;
  4733. ushort scsi_cfg1;
  4734. uchar byte;
  4735. uchar tid;
  4736. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4737. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  4738. uchar max_cmd[ASC_MAX_TID + 1];
  4739. /* If there is already an error, don't continue. */
  4740. if (asc_dvc->err_code != 0) {
  4741. return ADV_ERROR;
  4742. }
  4743. /*
  4744. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  4745. */
  4746. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  4747. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4748. return ADV_ERROR;
  4749. }
  4750. warn_code = 0;
  4751. iop_base = asc_dvc->iop_base;
  4752. /*
  4753. * Save the RISC memory BIOS region before writing the microcode.
  4754. * The BIOS may already be loaded and using its RISC LRAM region
  4755. * so its region must be saved and restored.
  4756. *
  4757. * Note: This code makes the assumption, which is currently true,
  4758. * that a chip reset does not clear RISC LRAM.
  4759. */
  4760. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4761. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4762. bios_mem[i]);
  4763. }
  4764. /*
  4765. * Save current per TID negotiated values.
  4766. */
  4767. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4768. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4769. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  4770. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4771. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  4772. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4773. max_cmd[tid]);
  4774. }
  4775. /*
  4776. * RAM BIST (Built-In Self Test)
  4777. *
  4778. * Address : I/O base + offset 0x38h register (byte).
  4779. * Function: Bit 7-6(RW) : RAM mode
  4780. * Normal Mode : 0x00
  4781. * Pre-test Mode : 0x40
  4782. * RAM Test Mode : 0x80
  4783. * Bit 5 : unused
  4784. * Bit 4(RO) : Done bit
  4785. * Bit 3-0(RO) : Status
  4786. * Host Error : 0x08
  4787. * Int_RAM Error : 0x04
  4788. * RISC Error : 0x02
  4789. * SCSI Error : 0x01
  4790. * No Error : 0x00
  4791. *
  4792. * Note: RAM BIST code should be put right here, before loading the
  4793. * microcode and after saving the RISC memory BIOS region.
  4794. */
  4795. /*
  4796. * LRAM Pre-test
  4797. *
  4798. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4799. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4800. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4801. * to NORMAL_MODE, return an error too.
  4802. */
  4803. for (i = 0; i < 2; i++) {
  4804. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4805. mdelay(10); /* Wait for 10ms before reading back. */
  4806. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4807. if ((byte & RAM_TEST_DONE) == 0
  4808. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4809. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4810. return ADV_ERROR;
  4811. }
  4812. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4813. mdelay(10); /* Wait for 10ms before reading back. */
  4814. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4815. != NORMAL_VALUE) {
  4816. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4817. return ADV_ERROR;
  4818. }
  4819. }
  4820. /*
  4821. * LRAM Test - It takes about 1.5 ms to run through the test.
  4822. *
  4823. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4824. * If Done bit not set or Status not 0, save register byte, set the
  4825. * err_code, and return an error.
  4826. */
  4827. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4828. mdelay(10); /* Wait for 10ms before checking status. */
  4829. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4830. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4831. /* Get here if Done bit not set or Status not 0. */
  4832. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4833. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4834. return ADV_ERROR;
  4835. }
  4836. /* We need to reset back to normal mode after LRAM test passes. */
  4837. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4838. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4839. if (err) {
  4840. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4841. fwname, err);
  4842. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4843. return err;
  4844. }
  4845. if (fw->size < 4) {
  4846. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4847. fw->size, fwname);
  4848. release_firmware(fw);
  4849. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4850. return -EINVAL;
  4851. }
  4852. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4853. (fw->data[1] << 8) | fw->data[0];
  4854. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4855. fw->size - 4, ADV_38C1600_MEMSIZE,
  4856. chksum);
  4857. release_firmware(fw);
  4858. if (asc_dvc->err_code)
  4859. return ADV_ERROR;
  4860. /*
  4861. * Restore the RISC memory BIOS region.
  4862. */
  4863. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4864. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4865. bios_mem[i]);
  4866. }
  4867. /*
  4868. * Calculate and write the microcode code checksum to the microcode
  4869. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4870. */
  4871. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4872. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4873. code_sum = 0;
  4874. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4875. for (word = begin_addr; word < end_addr; word += 2) {
  4876. code_sum += AdvReadWordAutoIncLram(iop_base);
  4877. }
  4878. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4879. /*
  4880. * Read microcode version and date.
  4881. */
  4882. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4883. asc_dvc->cfg->mcode_date);
  4884. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4885. asc_dvc->cfg->mcode_version);
  4886. /*
  4887. * Set the chip type to indicate the ASC38C1600.
  4888. */
  4889. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  4890. /*
  4891. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4892. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4893. * cable detection and then we are able to read C_DET[3:0].
  4894. *
  4895. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4896. * Microcode Default Value' section below.
  4897. */
  4898. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4899. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4900. scsi_cfg1 | DIS_TERM_DRV);
  4901. /*
  4902. * If the PCI Configuration Command Register "Parity Error Response
  4903. * Control" Bit was clear (0), then set the microcode variable
  4904. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4905. * to ignore DMA parity errors.
  4906. */
  4907. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4908. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4909. word |= CONTROL_FLAG_IGNORE_PERR;
  4910. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4911. }
  4912. /*
  4913. * If the BIOS control flag AIPP (Asynchronous Information
  4914. * Phase Protection) disable bit is not set, then set the firmware
  4915. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  4916. * AIPP checking and encoding.
  4917. */
  4918. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  4919. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4920. word |= CONTROL_FLAG_ENABLE_AIPP;
  4921. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4922. }
  4923. /*
  4924. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  4925. * and START_CTL_TH [3:2].
  4926. */
  4927. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4928. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  4929. /*
  4930. * Microcode operating variables for WDTR, SDTR, and command tag
  4931. * queuing will be set in slave_configure() based on what a
  4932. * device reports it is capable of in Inquiry byte 7.
  4933. *
  4934. * If SCSI Bus Resets have been disabled, then directly set
  4935. * SDTR and WDTR from the EEPROM configuration. This will allow
  4936. * the BIOS and warm boot to work without a SCSI bus hang on
  4937. * the Inquiry caused by host and target mismatched DTR values.
  4938. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4939. * be assumed to be in Asynchronous, Narrow mode.
  4940. */
  4941. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4942. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4943. asc_dvc->wdtr_able);
  4944. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4945. asc_dvc->sdtr_able);
  4946. }
  4947. /*
  4948. * Set microcode operating variables for DISC and SDTR_SPEED1,
  4949. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  4950. * configuration values.
  4951. *
  4952. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4953. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4954. * without determining here whether the device supports SDTR.
  4955. */
  4956. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4957. asc_dvc->cfg->disc_enable);
  4958. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  4959. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  4960. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  4961. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  4962. /*
  4963. * Set SCSI_CFG0 Microcode Default Value.
  4964. *
  4965. * The microcode will set the SCSI_CFG0 register using this value
  4966. * after it is started below.
  4967. */
  4968. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4969. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4970. asc_dvc->chip_scsi_id);
  4971. /*
  4972. * Calculate SCSI_CFG1 Microcode Default Value.
  4973. *
  4974. * The microcode will set the SCSI_CFG1 register using this value
  4975. * after it is started below.
  4976. *
  4977. * Each ASC-38C1600 function has only two cable detect bits.
  4978. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  4979. */
  4980. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4981. /*
  4982. * If the cable is reversed all of the SCSI_CTRL register signals
  4983. * will be set. Check for and return an error if this condition is
  4984. * found.
  4985. */
  4986. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4987. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4988. return ADV_ERROR;
  4989. }
  4990. /*
  4991. * Each ASC-38C1600 function has two connectors. Only an HVD device
  4992. * can not be connected to either connector. An LVD device or SE device
  4993. * may be connected to either connecor. If an SE device is connected,
  4994. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  4995. *
  4996. * If an HVD device is attached, return an error.
  4997. */
  4998. if (scsi_cfg1 & HVD) {
  4999. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5000. return ADV_ERROR;
  5001. }
  5002. /*
  5003. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5004. * termination because there are two connectors for each function. Each
  5005. * function may use either LVD or SE mode. Corresponding the SE automatic
  5006. * termination control EEPROM bits are used for each function. Each
  5007. * function has its own EEPROM. If SE automatic control is enabled for
  5008. * the function, then set the termination value based on a table listed
  5009. * in a_condor.h.
  5010. *
  5011. * If manual termination is specified in the EEPROM for the function,
  5012. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5013. * ready to be 'ored' into SCSI_CFG1.
  5014. */
  5015. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5016. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5017. /* SE automatic termination control is enabled. */
  5018. switch (scsi_cfg1 & C_DET_SE) {
  5019. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5020. case 0x1:
  5021. case 0x2:
  5022. case 0x3:
  5023. asc_dvc->cfg->termination |= TERM_SE;
  5024. break;
  5025. case 0x0:
  5026. if (PCI_FUNC(pdev->devfn) == 0) {
  5027. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5028. } else {
  5029. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5030. asc_dvc->cfg->termination |= TERM_SE_HI;
  5031. }
  5032. break;
  5033. }
  5034. }
  5035. /*
  5036. * Clear any set TERM_SE bits.
  5037. */
  5038. scsi_cfg1 &= ~TERM_SE;
  5039. /*
  5040. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5041. */
  5042. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5043. /*
  5044. * Clear Big Endian and Terminator Polarity bits and set possibly
  5045. * modified termination control bits in the Microcode SCSI_CFG1
  5046. * Register Value.
  5047. *
  5048. * Big Endian bit is not used even on big endian machines.
  5049. */
  5050. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5051. /*
  5052. * Set SCSI_CFG1 Microcode Default Value
  5053. *
  5054. * Set possibly modified termination control bits in the Microcode
  5055. * SCSI_CFG1 Register Value.
  5056. *
  5057. * The microcode will set the SCSI_CFG1 register using this value
  5058. * after it is started below.
  5059. */
  5060. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5061. /*
  5062. * Set MEM_CFG Microcode Default Value
  5063. *
  5064. * The microcode will set the MEM_CFG register using this value
  5065. * after it is started below.
  5066. *
  5067. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5068. * are defined.
  5069. *
  5070. * ASC-38C1600 has 32KB internal memory.
  5071. *
  5072. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5073. * out a special 16K Adv Library and Microcode version. After the issue
  5074. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5075. * mcode.sas files also need to be updated.
  5076. *
  5077. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5078. * BIOS_EN | RAM_SZ_32KB);
  5079. */
  5080. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5081. BIOS_EN | RAM_SZ_16KB);
  5082. /*
  5083. * Set SEL_MASK Microcode Default Value
  5084. *
  5085. * The microcode will set the SEL_MASK register using this value
  5086. * after it is started below.
  5087. */
  5088. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5089. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5090. AdvBuildCarrierFreelist(asc_dvc);
  5091. /*
  5092. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5093. */
  5094. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  5095. if (!asc_dvc->icq_sp) {
  5096. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5097. return ADV_ERROR;
  5098. }
  5099. /*
  5100. * Set RISC ICQ physical address start value. Initialize the
  5101. * COMMA register to the same value otherwise the RISC will
  5102. * prematurely detect a command is available.
  5103. */
  5104. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5105. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5106. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5107. /*
  5108. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5109. */
  5110. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  5111. if (!asc_dvc->irq_sp) {
  5112. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5113. return ADV_ERROR;
  5114. }
  5115. /*
  5116. * Set RISC IRQ physical address start value.
  5117. */
  5118. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5119. asc_dvc->carr_pending_cnt = 0;
  5120. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5121. (ADV_INTR_ENABLE_HOST_INTR |
  5122. ADV_INTR_ENABLE_GLOBAL_INTR));
  5123. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5124. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5125. /* finally, finally, gentlemen, start your engine */
  5126. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5127. /*
  5128. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5129. * Resets should be performed. The RISC has to be running
  5130. * to issue a SCSI Bus Reset.
  5131. */
  5132. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5133. /*
  5134. * If the BIOS Signature is present in memory, restore the
  5135. * per TID microcode operating variables.
  5136. */
  5137. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5138. 0x55AA) {
  5139. /*
  5140. * Restore per TID negotiated values.
  5141. */
  5142. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5143. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5144. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5145. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5146. tagqng_able);
  5147. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5148. AdvWriteByteLram(iop_base,
  5149. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5150. max_cmd[tid]);
  5151. }
  5152. } else {
  5153. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5154. warn_code = ASC_WARN_BUSRESET_ERROR;
  5155. }
  5156. }
  5157. }
  5158. return warn_code;
  5159. }
  5160. /*
  5161. * Reset chip and SCSI Bus.
  5162. *
  5163. * Return Value:
  5164. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5165. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5166. */
  5167. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5168. {
  5169. int status;
  5170. ushort wdtr_able, sdtr_able, tagqng_able;
  5171. ushort ppr_able = 0;
  5172. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5173. AdvPortAddr iop_base;
  5174. ushort bios_sig;
  5175. iop_base = asc_dvc->iop_base;
  5176. /*
  5177. * Save current per TID negotiated values.
  5178. */
  5179. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5180. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5181. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5182. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5183. }
  5184. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5185. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5186. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5187. max_cmd[tid]);
  5188. }
  5189. /*
  5190. * Force the AdvInitAsc3550/38C0800Driver() function to
  5191. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5192. * The initialization functions assumes a SCSI Bus Reset is not
  5193. * needed if the BIOS signature word is present.
  5194. */
  5195. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5196. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5197. /*
  5198. * Stop chip and reset it.
  5199. */
  5200. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5201. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5202. mdelay(100);
  5203. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5204. ADV_CTRL_REG_CMD_WR_IO_REG);
  5205. /*
  5206. * Reset Adv Library error code, if any, and try
  5207. * re-initializing the chip.
  5208. */
  5209. asc_dvc->err_code = 0;
  5210. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5211. status = AdvInitAsc38C1600Driver(asc_dvc);
  5212. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5213. status = AdvInitAsc38C0800Driver(asc_dvc);
  5214. } else {
  5215. status = AdvInitAsc3550Driver(asc_dvc);
  5216. }
  5217. /* Translate initialization return value to status value. */
  5218. if (status == 0) {
  5219. status = ADV_TRUE;
  5220. } else {
  5221. status = ADV_FALSE;
  5222. }
  5223. /*
  5224. * Restore the BIOS signature word.
  5225. */
  5226. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5227. /*
  5228. * Restore per TID negotiated values.
  5229. */
  5230. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5231. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5232. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5233. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5234. }
  5235. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5236. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5237. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5238. max_cmd[tid]);
  5239. }
  5240. return status;
  5241. }
  5242. /*
  5243. * adv_async_callback() - Adv Library asynchronous event callback function.
  5244. */
  5245. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5246. {
  5247. switch (code) {
  5248. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5249. /*
  5250. * The firmware detected a SCSI Bus reset.
  5251. */
  5252. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5253. break;
  5254. case ADV_ASYNC_RDMA_FAILURE:
  5255. /*
  5256. * Handle RDMA failure by resetting the SCSI Bus and
  5257. * possibly the chip if it is unresponsive. Log the error
  5258. * with a unique code.
  5259. */
  5260. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5261. AdvResetChipAndSB(adv_dvc_varp);
  5262. break;
  5263. case ADV_HOST_SCSI_BUS_RESET:
  5264. /*
  5265. * Host generated SCSI bus reset occurred.
  5266. */
  5267. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5268. break;
  5269. default:
  5270. ASC_DBG(0, "unknown code 0x%x\n", code);
  5271. break;
  5272. }
  5273. }
  5274. /*
  5275. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5276. *
  5277. * Callback function for the Wide SCSI Adv Library.
  5278. */
  5279. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5280. {
  5281. struct asc_board *boardp = adv_dvc_varp->drv_ptr;
  5282. adv_req_t *reqp;
  5283. adv_sgblk_t *sgblkp;
  5284. struct scsi_cmnd *scp;
  5285. u32 resid_cnt;
  5286. dma_addr_t sense_addr;
  5287. ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n",
  5288. adv_dvc_varp, scsiqp);
  5289. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5290. /*
  5291. * Get the adv_req_t structure for the command that has been
  5292. * completed. The adv_req_t structure actually contains the
  5293. * completed ADV_SCSI_REQ_Q structure.
  5294. */
  5295. scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag);
  5296. ASC_DBG(1, "scp 0x%p\n", scp);
  5297. if (scp == NULL) {
  5298. ASC_PRINT
  5299. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  5300. return;
  5301. }
  5302. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  5303. reqp = (adv_req_t *)scp->host_scribble;
  5304. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  5305. if (reqp == NULL) {
  5306. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  5307. return;
  5308. }
  5309. /*
  5310. * Remove backreferences to avoid duplicate
  5311. * command completions.
  5312. */
  5313. scp->host_scribble = NULL;
  5314. reqp->cmndp = NULL;
  5315. ASC_STATS(boardp->shost, callback);
  5316. ASC_DBG(1, "shost 0x%p\n", boardp->shost);
  5317. sense_addr = le32_to_cpu(scsiqp->sense_addr);
  5318. dma_unmap_single(boardp->dev, sense_addr,
  5319. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  5320. /*
  5321. * 'done_status' contains the command's ending status.
  5322. */
  5323. scp->result = 0;
  5324. switch (scsiqp->done_status) {
  5325. case QD_NO_ERROR:
  5326. ASC_DBG(2, "QD_NO_ERROR\n");
  5327. /*
  5328. * Check for an underrun condition.
  5329. *
  5330. * If there was no error and an underrun condition, then
  5331. * then return the number of underrun bytes.
  5332. */
  5333. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  5334. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  5335. resid_cnt <= scsi_bufflen(scp)) {
  5336. ASC_DBG(1, "underrun condition %lu bytes\n",
  5337. (ulong)resid_cnt);
  5338. scsi_set_resid(scp, resid_cnt);
  5339. }
  5340. break;
  5341. case QD_WITH_ERROR:
  5342. ASC_DBG(2, "QD_WITH_ERROR\n");
  5343. switch (scsiqp->host_status) {
  5344. case QHSTA_NO_ERROR:
  5345. set_status_byte(scp, scsiqp->scsi_status);
  5346. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  5347. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  5348. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  5349. SCSI_SENSE_BUFFERSIZE);
  5350. }
  5351. break;
  5352. default:
  5353. /* Some other QHSTA error occurred. */
  5354. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  5355. set_host_byte(scp, DID_BAD_TARGET);
  5356. break;
  5357. }
  5358. break;
  5359. case QD_ABORTED_BY_HOST:
  5360. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  5361. set_status_byte(scp, scsiqp->scsi_status);
  5362. set_host_byte(scp, DID_ABORT);
  5363. break;
  5364. default:
  5365. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  5366. set_status_byte(scp, scsiqp->scsi_status);
  5367. set_host_byte(scp, DID_ERROR);
  5368. break;
  5369. }
  5370. /*
  5371. * If the 'init_tidmask' bit isn't already set for the target and the
  5372. * current request finished normally, then set the bit for the target
  5373. * to indicate that a device is present.
  5374. */
  5375. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  5376. scsiqp->done_status == QD_NO_ERROR &&
  5377. scsiqp->host_status == QHSTA_NO_ERROR) {
  5378. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  5379. }
  5380. asc_scsi_done(scp);
  5381. /*
  5382. * Free all 'adv_sgblk_t' structures allocated for the request.
  5383. */
  5384. while ((sgblkp = reqp->sgblkp) != NULL) {
  5385. /* Remove 'sgblkp' from the request list. */
  5386. reqp->sgblkp = sgblkp->next_sgblkp;
  5387. dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
  5388. sgblkp->sg_addr);
  5389. }
  5390. ASC_DBG(1, "done\n");
  5391. }
  5392. /*
  5393. * Adv Library Interrupt Service Routine
  5394. *
  5395. * This function is called by a driver's interrupt service routine.
  5396. * The function disables and re-enables interrupts.
  5397. *
  5398. * When a microcode idle command is completed, the ADV_DVC_VAR
  5399. * 'idle_cmd_done' field is set to ADV_TRUE.
  5400. *
  5401. * Note: AdvISR() can be called when interrupts are disabled or even
  5402. * when there is no hardware interrupt condition present. It will
  5403. * always check for completed idle commands and microcode requests.
  5404. * This is an important feature that shouldn't be changed because it
  5405. * allows commands to be completed from polling mode loops.
  5406. *
  5407. * Return:
  5408. * ADV_TRUE(1) - interrupt was pending
  5409. * ADV_FALSE(0) - no interrupt was pending
  5410. */
  5411. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  5412. {
  5413. AdvPortAddr iop_base;
  5414. uchar int_stat;
  5415. ADV_CARR_T *free_carrp;
  5416. __le32 irq_next_vpa;
  5417. ADV_SCSI_REQ_Q *scsiq;
  5418. adv_req_t *reqp;
  5419. iop_base = asc_dvc->iop_base;
  5420. /* Reading the register clears the interrupt. */
  5421. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  5422. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  5423. ADV_INTR_STATUS_INTRC)) == 0) {
  5424. return ADV_FALSE;
  5425. }
  5426. /*
  5427. * Notify the driver of an asynchronous microcode condition by
  5428. * calling the adv_async_callback function. The function
  5429. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  5430. */
  5431. if (int_stat & ADV_INTR_STATUS_INTRB) {
  5432. uchar intrb_code;
  5433. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  5434. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  5435. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5436. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  5437. asc_dvc->carr_pending_cnt != 0) {
  5438. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  5439. ADV_TICKLE_A);
  5440. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  5441. AdvWriteByteRegister(iop_base,
  5442. IOPB_TICKLE,
  5443. ADV_TICKLE_NOP);
  5444. }
  5445. }
  5446. }
  5447. adv_async_callback(asc_dvc, intrb_code);
  5448. }
  5449. /*
  5450. * Check if the IRQ stopper carrier contains a completed request.
  5451. */
  5452. while (((irq_next_vpa =
  5453. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ADV_RQ_DONE) != 0) {
  5454. /*
  5455. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  5456. * The RISC will have set 'areq_vpa' to a virtual address.
  5457. *
  5458. * The firmware will have copied the ADV_SCSI_REQ_Q.scsiq_ptr
  5459. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  5460. * below complements the conversion of ADV_SCSI_REQ_Q.scsiq_ptr'
  5461. * in AdvExeScsiQueue().
  5462. */
  5463. u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa);
  5464. ASC_DBG(1, "irq_sp %p areq_vpa %u\n",
  5465. asc_dvc->irq_sp, pa_offset);
  5466. reqp = adv_get_reqp(asc_dvc, pa_offset);
  5467. scsiq = &reqp->scsi_req_q;
  5468. /*
  5469. * Request finished with good status and the queue was not
  5470. * DMAed to host memory by the firmware. Set all status fields
  5471. * to indicate good status.
  5472. */
  5473. if ((irq_next_vpa & ADV_RQ_GOOD) != 0) {
  5474. scsiq->done_status = QD_NO_ERROR;
  5475. scsiq->host_status = scsiq->scsi_status = 0;
  5476. scsiq->data_cnt = 0L;
  5477. }
  5478. /*
  5479. * Advance the stopper pointer to the next carrier
  5480. * ignoring the lower four bits. Free the previous
  5481. * stopper carrier.
  5482. */
  5483. free_carrp = asc_dvc->irq_sp;
  5484. asc_dvc->irq_sp = adv_get_carrier(asc_dvc,
  5485. ADV_GET_CARRP(irq_next_vpa));
  5486. free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va;
  5487. asc_dvc->carr_freelist = free_carrp;
  5488. asc_dvc->carr_pending_cnt--;
  5489. /*
  5490. * Clear request microcode control flag.
  5491. */
  5492. scsiq->cntl = 0;
  5493. /*
  5494. * Notify the driver of the completed request by passing
  5495. * the ADV_SCSI_REQ_Q pointer to its callback function.
  5496. */
  5497. adv_isr_callback(asc_dvc, scsiq);
  5498. /*
  5499. * Note: After the driver callback function is called, 'scsiq'
  5500. * can no longer be referenced.
  5501. *
  5502. * Fall through and continue processing other completed
  5503. * requests...
  5504. */
  5505. }
  5506. return ADV_TRUE;
  5507. }
  5508. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  5509. {
  5510. if (asc_dvc->err_code == 0) {
  5511. asc_dvc->err_code = err_code;
  5512. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  5513. err_code);
  5514. }
  5515. return err_code;
  5516. }
  5517. static void AscAckInterrupt(PortAddr iop_base)
  5518. {
  5519. uchar host_flag;
  5520. uchar risc_flag;
  5521. ushort loop;
  5522. loop = 0;
  5523. do {
  5524. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  5525. if (loop++ > 0x7FFF) {
  5526. break;
  5527. }
  5528. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  5529. host_flag =
  5530. AscReadLramByte(iop_base,
  5531. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  5532. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  5533. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  5534. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5535. loop = 0;
  5536. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  5537. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5538. if (loop++ > 3) {
  5539. break;
  5540. }
  5541. }
  5542. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  5543. }
  5544. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  5545. {
  5546. const uchar *period_table;
  5547. int max_index;
  5548. int min_index;
  5549. int i;
  5550. period_table = asc_dvc->sdtr_period_tbl;
  5551. max_index = (int)asc_dvc->max_sdtr_index;
  5552. min_index = (int)asc_dvc->min_sdtr_index;
  5553. if ((syn_time <= period_table[max_index])) {
  5554. for (i = min_index; i < (max_index - 1); i++) {
  5555. if (syn_time <= period_table[i]) {
  5556. return (uchar)i;
  5557. }
  5558. }
  5559. return (uchar)max_index;
  5560. } else {
  5561. return (uchar)(max_index + 1);
  5562. }
  5563. }
  5564. static uchar
  5565. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  5566. {
  5567. PortAddr iop_base = asc_dvc->iop_base;
  5568. uchar sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5569. EXT_MSG sdtr_buf = {
  5570. .msg_type = EXTENDED_MESSAGE,
  5571. .msg_len = MS_SDTR_LEN,
  5572. .msg_req = EXTENDED_SDTR,
  5573. .xfer_period = sdtr_period,
  5574. .req_ack_offset = sdtr_offset,
  5575. };
  5576. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  5577. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  5578. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5579. (uchar *)&sdtr_buf,
  5580. sizeof(EXT_MSG) >> 1);
  5581. return ((sdtr_period_index << 4) | sdtr_offset);
  5582. } else {
  5583. sdtr_buf.req_ack_offset = 0;
  5584. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5585. (uchar *)&sdtr_buf,
  5586. sizeof(EXT_MSG) >> 1);
  5587. return 0;
  5588. }
  5589. }
  5590. static uchar
  5591. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  5592. {
  5593. uchar byte;
  5594. uchar sdtr_period_ix;
  5595. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5596. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  5597. return 0xFF;
  5598. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  5599. return byte;
  5600. }
  5601. static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  5602. {
  5603. ASC_SCSI_BIT_ID_TYPE org_id;
  5604. int i;
  5605. bool sta = true;
  5606. AscSetBank(iop_base, 1);
  5607. org_id = AscReadChipDvcID(iop_base);
  5608. for (i = 0; i <= ASC_MAX_TID; i++) {
  5609. if (org_id == (0x01 << i))
  5610. break;
  5611. }
  5612. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  5613. AscWriteChipDvcID(iop_base, id);
  5614. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  5615. AscSetBank(iop_base, 0);
  5616. AscSetChipSyn(iop_base, sdtr_data);
  5617. if (AscGetChipSyn(iop_base) != sdtr_data) {
  5618. sta = false;
  5619. }
  5620. } else {
  5621. sta = false;
  5622. }
  5623. AscSetBank(iop_base, 1);
  5624. AscWriteChipDvcID(iop_base, org_id);
  5625. AscSetBank(iop_base, 0);
  5626. return (sta);
  5627. }
  5628. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  5629. {
  5630. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  5631. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  5632. }
  5633. static void AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  5634. {
  5635. EXT_MSG ext_msg;
  5636. EXT_MSG out_msg;
  5637. ushort halt_q_addr;
  5638. bool sdtr_accept;
  5639. ushort int_halt_code;
  5640. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  5641. ASC_SCSI_BIT_ID_TYPE target_id;
  5642. PortAddr iop_base;
  5643. uchar tag_code;
  5644. uchar q_status;
  5645. uchar halt_qp;
  5646. uchar sdtr_data;
  5647. uchar target_ix;
  5648. uchar q_cntl, tid_no;
  5649. uchar cur_dvc_qng;
  5650. uchar asyn_sdtr;
  5651. uchar scsi_status;
  5652. struct asc_board *boardp;
  5653. BUG_ON(!asc_dvc->drv_ptr);
  5654. boardp = asc_dvc->drv_ptr;
  5655. iop_base = asc_dvc->iop_base;
  5656. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  5657. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  5658. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  5659. target_ix = AscReadLramByte(iop_base,
  5660. (ushort)(halt_q_addr +
  5661. (ushort)ASC_SCSIQ_B_TARGET_IX));
  5662. q_cntl = AscReadLramByte(iop_base,
  5663. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  5664. tid_no = ASC_TIX_TO_TID(target_ix);
  5665. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  5666. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5667. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  5668. } else {
  5669. asyn_sdtr = 0;
  5670. }
  5671. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  5672. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5673. AscSetChipSDTR(iop_base, 0, tid_no);
  5674. boardp->sdtr_data[tid_no] = 0;
  5675. }
  5676. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5677. return;
  5678. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  5679. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5680. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5681. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5682. }
  5683. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5684. return;
  5685. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  5686. AscMemWordCopyPtrFromLram(iop_base,
  5687. ASCV_MSGIN_BEG,
  5688. (uchar *)&ext_msg,
  5689. sizeof(EXT_MSG) >> 1);
  5690. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5691. ext_msg.msg_req == EXTENDED_SDTR &&
  5692. ext_msg.msg_len == MS_SDTR_LEN) {
  5693. sdtr_accept = true;
  5694. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  5695. sdtr_accept = false;
  5696. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  5697. }
  5698. if ((ext_msg.xfer_period <
  5699. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  5700. || (ext_msg.xfer_period >
  5701. asc_dvc->sdtr_period_tbl[asc_dvc->
  5702. max_sdtr_index])) {
  5703. sdtr_accept = false;
  5704. ext_msg.xfer_period =
  5705. asc_dvc->sdtr_period_tbl[asc_dvc->
  5706. min_sdtr_index];
  5707. }
  5708. if (sdtr_accept) {
  5709. sdtr_data =
  5710. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  5711. ext_msg.req_ack_offset);
  5712. if (sdtr_data == 0xFF) {
  5713. q_cntl |= QC_MSG_OUT;
  5714. asc_dvc->init_sdtr &= ~target_id;
  5715. asc_dvc->sdtr_done &= ~target_id;
  5716. AscSetChipSDTR(iop_base, asyn_sdtr,
  5717. tid_no);
  5718. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5719. }
  5720. }
  5721. if (ext_msg.req_ack_offset == 0) {
  5722. q_cntl &= ~QC_MSG_OUT;
  5723. asc_dvc->init_sdtr &= ~target_id;
  5724. asc_dvc->sdtr_done &= ~target_id;
  5725. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5726. } else {
  5727. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  5728. q_cntl &= ~QC_MSG_OUT;
  5729. asc_dvc->sdtr_done |= target_id;
  5730. asc_dvc->init_sdtr |= target_id;
  5731. asc_dvc->pci_fix_asyn_xfer &=
  5732. ~target_id;
  5733. sdtr_data =
  5734. AscCalSDTRData(asc_dvc,
  5735. ext_msg.xfer_period,
  5736. ext_msg.
  5737. req_ack_offset);
  5738. AscSetChipSDTR(iop_base, sdtr_data,
  5739. tid_no);
  5740. boardp->sdtr_data[tid_no] = sdtr_data;
  5741. } else {
  5742. q_cntl |= QC_MSG_OUT;
  5743. AscMsgOutSDTR(asc_dvc,
  5744. ext_msg.xfer_period,
  5745. ext_msg.req_ack_offset);
  5746. asc_dvc->pci_fix_asyn_xfer &=
  5747. ~target_id;
  5748. sdtr_data =
  5749. AscCalSDTRData(asc_dvc,
  5750. ext_msg.xfer_period,
  5751. ext_msg.
  5752. req_ack_offset);
  5753. AscSetChipSDTR(iop_base, sdtr_data,
  5754. tid_no);
  5755. boardp->sdtr_data[tid_no] = sdtr_data;
  5756. asc_dvc->sdtr_done |= target_id;
  5757. asc_dvc->init_sdtr |= target_id;
  5758. }
  5759. }
  5760. AscWriteLramByte(iop_base,
  5761. (ushort)(halt_q_addr +
  5762. (ushort)ASC_SCSIQ_B_CNTL),
  5763. q_cntl);
  5764. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5765. return;
  5766. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5767. ext_msg.msg_req == EXTENDED_WDTR &&
  5768. ext_msg.msg_len == MS_WDTR_LEN) {
  5769. ext_msg.wdtr_width = 0;
  5770. AscMemWordCopyPtrToLram(iop_base,
  5771. ASCV_MSGOUT_BEG,
  5772. (uchar *)&ext_msg,
  5773. sizeof(EXT_MSG) >> 1);
  5774. q_cntl |= QC_MSG_OUT;
  5775. AscWriteLramByte(iop_base,
  5776. (ushort)(halt_q_addr +
  5777. (ushort)ASC_SCSIQ_B_CNTL),
  5778. q_cntl);
  5779. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5780. return;
  5781. } else {
  5782. ext_msg.msg_type = MESSAGE_REJECT;
  5783. AscMemWordCopyPtrToLram(iop_base,
  5784. ASCV_MSGOUT_BEG,
  5785. (uchar *)&ext_msg,
  5786. sizeof(EXT_MSG) >> 1);
  5787. q_cntl |= QC_MSG_OUT;
  5788. AscWriteLramByte(iop_base,
  5789. (ushort)(halt_q_addr +
  5790. (ushort)ASC_SCSIQ_B_CNTL),
  5791. q_cntl);
  5792. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5793. return;
  5794. }
  5795. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  5796. q_cntl |= QC_REQ_SENSE;
  5797. if ((asc_dvc->init_sdtr & target_id) != 0) {
  5798. asc_dvc->sdtr_done &= ~target_id;
  5799. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  5800. q_cntl |= QC_MSG_OUT;
  5801. AscMsgOutSDTR(asc_dvc,
  5802. asc_dvc->
  5803. sdtr_period_tbl[(sdtr_data >> 4) &
  5804. (uchar)(asc_dvc->
  5805. max_sdtr_index -
  5806. 1)],
  5807. (uchar)(sdtr_data & (uchar)
  5808. ASC_SYN_MAX_OFFSET));
  5809. }
  5810. AscWriteLramByte(iop_base,
  5811. (ushort)(halt_q_addr +
  5812. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  5813. tag_code = AscReadLramByte(iop_base,
  5814. (ushort)(halt_q_addr + (ushort)
  5815. ASC_SCSIQ_B_TAG_CODE));
  5816. tag_code &= 0xDC;
  5817. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  5818. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  5819. ) {
  5820. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  5821. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  5822. }
  5823. AscWriteLramByte(iop_base,
  5824. (ushort)(halt_q_addr +
  5825. (ushort)ASC_SCSIQ_B_TAG_CODE),
  5826. tag_code);
  5827. q_status = AscReadLramByte(iop_base,
  5828. (ushort)(halt_q_addr + (ushort)
  5829. ASC_SCSIQ_B_STATUS));
  5830. q_status |= (QS_READY | QS_BUSY);
  5831. AscWriteLramByte(iop_base,
  5832. (ushort)(halt_q_addr +
  5833. (ushort)ASC_SCSIQ_B_STATUS),
  5834. q_status);
  5835. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  5836. scsi_busy &= ~target_id;
  5837. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  5838. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5839. return;
  5840. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  5841. AscMemWordCopyPtrFromLram(iop_base,
  5842. ASCV_MSGOUT_BEG,
  5843. (uchar *)&out_msg,
  5844. sizeof(EXT_MSG) >> 1);
  5845. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  5846. (out_msg.msg_len == MS_SDTR_LEN) &&
  5847. (out_msg.msg_req == EXTENDED_SDTR)) {
  5848. asc_dvc->init_sdtr &= ~target_id;
  5849. asc_dvc->sdtr_done &= ~target_id;
  5850. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5851. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5852. }
  5853. q_cntl &= ~QC_MSG_OUT;
  5854. AscWriteLramByte(iop_base,
  5855. (ushort)(halt_q_addr +
  5856. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  5857. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5858. return;
  5859. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  5860. scsi_status = AscReadLramByte(iop_base,
  5861. (ushort)((ushort)halt_q_addr +
  5862. (ushort)
  5863. ASC_SCSIQ_SCSI_STATUS));
  5864. cur_dvc_qng =
  5865. AscReadLramByte(iop_base,
  5866. (ushort)((ushort)ASC_QADR_BEG +
  5867. (ushort)target_ix));
  5868. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  5869. scsi_busy = AscReadLramByte(iop_base,
  5870. (ushort)ASCV_SCSIBUSY_B);
  5871. scsi_busy |= target_id;
  5872. AscWriteLramByte(iop_base,
  5873. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  5874. asc_dvc->queue_full_or_busy |= target_id;
  5875. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  5876. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  5877. cur_dvc_qng -= 1;
  5878. asc_dvc->max_dvc_qng[tid_no] =
  5879. cur_dvc_qng;
  5880. AscWriteLramByte(iop_base,
  5881. (ushort)((ushort)
  5882. ASCV_MAX_DVC_QNG_BEG
  5883. + (ushort)
  5884. tid_no),
  5885. cur_dvc_qng);
  5886. /*
  5887. * Set the device queue depth to the
  5888. * number of active requests when the
  5889. * QUEUE FULL condition was encountered.
  5890. */
  5891. boardp->queue_full |= target_id;
  5892. boardp->queue_full_cnt[tid_no] =
  5893. cur_dvc_qng;
  5894. }
  5895. }
  5896. }
  5897. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5898. return;
  5899. }
  5900. return;
  5901. }
  5902. /*
  5903. * void
  5904. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  5905. *
  5906. * Calling/Exit State:
  5907. * none
  5908. *
  5909. * Description:
  5910. * Input an ASC_QDONE_INFO structure from the chip
  5911. */
  5912. static void
  5913. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  5914. {
  5915. int i;
  5916. ushort word;
  5917. AscSetChipLramAddr(iop_base, s_addr);
  5918. for (i = 0; i < 2 * words; i += 2) {
  5919. if (i == 10) {
  5920. continue;
  5921. }
  5922. word = inpw(iop_base + IOP_RAM_DATA);
  5923. inbuf[i] = word & 0xff;
  5924. inbuf[i + 1] = (word >> 8) & 0xff;
  5925. }
  5926. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  5927. }
  5928. static uchar
  5929. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  5930. ushort q_addr,
  5931. ASC_QDONE_INFO *scsiq, unsigned int max_dma_count)
  5932. {
  5933. ushort _val;
  5934. uchar sg_queue_cnt;
  5935. DvcGetQinfo(iop_base,
  5936. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  5937. (uchar *)scsiq,
  5938. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  5939. _val = AscReadLramWord(iop_base,
  5940. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  5941. scsiq->q_status = (uchar)_val;
  5942. scsiq->q_no = (uchar)(_val >> 8);
  5943. _val = AscReadLramWord(iop_base,
  5944. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  5945. scsiq->cntl = (uchar)_val;
  5946. sg_queue_cnt = (uchar)(_val >> 8);
  5947. _val = AscReadLramWord(iop_base,
  5948. (ushort)(q_addr +
  5949. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  5950. scsiq->sense_len = (uchar)_val;
  5951. scsiq->extra_bytes = (uchar)(_val >> 8);
  5952. /*
  5953. * Read high word of remain bytes from alternate location.
  5954. */
  5955. scsiq->remain_bytes = (((u32)AscReadLramWord(iop_base,
  5956. (ushort)(q_addr +
  5957. (ushort)
  5958. ASC_SCSIQ_W_ALT_DC1)))
  5959. << 16);
  5960. /*
  5961. * Read low word of remain bytes from original location.
  5962. */
  5963. scsiq->remain_bytes += AscReadLramWord(iop_base,
  5964. (ushort)(q_addr + (ushort)
  5965. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  5966. scsiq->remain_bytes &= max_dma_count;
  5967. return sg_queue_cnt;
  5968. }
  5969. /*
  5970. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  5971. *
  5972. * Interrupt callback function for the Narrow SCSI Asc Library.
  5973. */
  5974. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  5975. {
  5976. struct asc_board *boardp = asc_dvc_varp->drv_ptr;
  5977. u32 srb_tag;
  5978. struct scsi_cmnd *scp;
  5979. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  5980. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  5981. /*
  5982. * Decrease the srb_tag by 1 to find the SCSI command
  5983. */
  5984. srb_tag = qdonep->d2.srb_tag - 1;
  5985. scp = scsi_host_find_tag(boardp->shost, srb_tag);
  5986. if (!scp)
  5987. return;
  5988. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  5989. ASC_STATS(boardp->shost, callback);
  5990. dma_unmap_single(boardp->dev, advansys_cmd(scp)->dma_handle,
  5991. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  5992. /*
  5993. * 'qdonep' contains the command's ending status.
  5994. */
  5995. scp->result = 0;
  5996. switch (qdonep->d3.done_stat) {
  5997. case QD_NO_ERROR:
  5998. ASC_DBG(2, "QD_NO_ERROR\n");
  5999. /*
  6000. * Check for an underrun condition.
  6001. *
  6002. * If there was no error and an underrun condition, then
  6003. * return the number of underrun bytes.
  6004. */
  6005. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6006. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6007. ASC_DBG(1, "underrun condition %u bytes\n",
  6008. (unsigned)qdonep->remain_bytes);
  6009. scsi_set_resid(scp, qdonep->remain_bytes);
  6010. }
  6011. break;
  6012. case QD_WITH_ERROR:
  6013. ASC_DBG(2, "QD_WITH_ERROR\n");
  6014. switch (qdonep->d3.host_stat) {
  6015. case QHSTA_NO_ERROR:
  6016. set_status_byte(scp, qdonep->d3.scsi_stat);
  6017. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6018. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6019. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6020. SCSI_SENSE_BUFFERSIZE);
  6021. }
  6022. break;
  6023. default:
  6024. /* QHSTA error occurred */
  6025. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6026. set_host_byte(scp, DID_BAD_TARGET);
  6027. break;
  6028. }
  6029. break;
  6030. case QD_ABORTED_BY_HOST:
  6031. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6032. set_status_byte(scp, qdonep->d3.scsi_stat);
  6033. set_host_byte(scp, DID_ABORT);
  6034. break;
  6035. default:
  6036. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6037. set_status_byte(scp, qdonep->d3.scsi_stat);
  6038. set_host_byte(scp, DID_ERROR);
  6039. break;
  6040. }
  6041. /*
  6042. * If the 'init_tidmask' bit isn't already set for the target and the
  6043. * current request finished normally, then set the bit for the target
  6044. * to indicate that a device is present.
  6045. */
  6046. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6047. qdonep->d3.done_stat == QD_NO_ERROR &&
  6048. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6049. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6050. }
  6051. asc_scsi_done(scp);
  6052. }
  6053. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6054. {
  6055. uchar next_qp;
  6056. uchar n_q_used;
  6057. uchar sg_list_qp;
  6058. uchar sg_queue_cnt;
  6059. uchar q_cnt;
  6060. uchar done_q_tail;
  6061. uchar tid_no;
  6062. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6063. ASC_SCSI_BIT_ID_TYPE target_id;
  6064. PortAddr iop_base;
  6065. ushort q_addr;
  6066. ushort sg_q_addr;
  6067. uchar cur_target_qng;
  6068. ASC_QDONE_INFO scsiq_buf;
  6069. ASC_QDONE_INFO *scsiq;
  6070. bool false_overrun;
  6071. iop_base = asc_dvc->iop_base;
  6072. n_q_used = 1;
  6073. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6074. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6075. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6076. next_qp = AscReadLramByte(iop_base,
  6077. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6078. if (next_qp != ASC_QLINK_END) {
  6079. AscPutVarDoneQTail(iop_base, next_qp);
  6080. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6081. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6082. asc_dvc->max_dma_count);
  6083. AscWriteLramByte(iop_base,
  6084. (ushort)(q_addr +
  6085. (ushort)ASC_SCSIQ_B_STATUS),
  6086. (uchar)(scsiq->
  6087. q_status & (uchar)~(QS_READY |
  6088. QS_ABORTED)));
  6089. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6090. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6091. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6092. sg_q_addr = q_addr;
  6093. sg_list_qp = next_qp;
  6094. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6095. sg_list_qp = AscReadLramByte(iop_base,
  6096. (ushort)(sg_q_addr
  6097. + (ushort)
  6098. ASC_SCSIQ_B_FWD));
  6099. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6100. if (sg_list_qp == ASC_QLINK_END) {
  6101. AscSetLibErrorCode(asc_dvc,
  6102. ASCQ_ERR_SG_Q_LINKS);
  6103. scsiq->d3.done_stat = QD_WITH_ERROR;
  6104. scsiq->d3.host_stat =
  6105. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6106. goto FATAL_ERR_QDONE;
  6107. }
  6108. AscWriteLramByte(iop_base,
  6109. (ushort)(sg_q_addr + (ushort)
  6110. ASC_SCSIQ_B_STATUS),
  6111. QS_FREE);
  6112. }
  6113. n_q_used = sg_queue_cnt + 1;
  6114. AscPutVarDoneQTail(iop_base, sg_list_qp);
  6115. }
  6116. if (asc_dvc->queue_full_or_busy & target_id) {
  6117. cur_target_qng = AscReadLramByte(iop_base,
  6118. (ushort)((ushort)
  6119. ASC_QADR_BEG
  6120. + (ushort)
  6121. scsiq->d2.
  6122. target_ix));
  6123. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  6124. scsi_busy = AscReadLramByte(iop_base, (ushort)
  6125. ASCV_SCSIBUSY_B);
  6126. scsi_busy &= ~target_id;
  6127. AscWriteLramByte(iop_base,
  6128. (ushort)ASCV_SCSIBUSY_B,
  6129. scsi_busy);
  6130. asc_dvc->queue_full_or_busy &= ~target_id;
  6131. }
  6132. }
  6133. if (asc_dvc->cur_total_qng >= n_q_used) {
  6134. asc_dvc->cur_total_qng -= n_q_used;
  6135. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  6136. asc_dvc->cur_dvc_qng[tid_no]--;
  6137. }
  6138. } else {
  6139. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  6140. scsiq->d3.done_stat = QD_WITH_ERROR;
  6141. goto FATAL_ERR_QDONE;
  6142. }
  6143. if ((scsiq->d2.srb_tag == 0UL) ||
  6144. ((scsiq->q_status & QS_ABORTED) != 0)) {
  6145. return (0x11);
  6146. } else if (scsiq->q_status == QS_DONE) {
  6147. /*
  6148. * This is also curious.
  6149. * false_overrun will _always_ be set to 'false'
  6150. */
  6151. false_overrun = false;
  6152. if (scsiq->extra_bytes != 0) {
  6153. scsiq->remain_bytes += scsiq->extra_bytes;
  6154. }
  6155. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  6156. if (scsiq->d3.host_stat ==
  6157. QHSTA_M_DATA_OVER_RUN) {
  6158. if ((scsiq->
  6159. cntl & (QC_DATA_IN | QC_DATA_OUT))
  6160. == 0) {
  6161. scsiq->d3.done_stat =
  6162. QD_NO_ERROR;
  6163. scsiq->d3.host_stat =
  6164. QHSTA_NO_ERROR;
  6165. } else if (false_overrun) {
  6166. scsiq->d3.done_stat =
  6167. QD_NO_ERROR;
  6168. scsiq->d3.host_stat =
  6169. QHSTA_NO_ERROR;
  6170. }
  6171. } else if (scsiq->d3.host_stat ==
  6172. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  6173. AscStopChip(iop_base);
  6174. AscSetChipControl(iop_base,
  6175. (uchar)(CC_SCSI_RESET
  6176. | CC_HALT));
  6177. udelay(60);
  6178. AscSetChipControl(iop_base, CC_HALT);
  6179. AscSetChipStatus(iop_base,
  6180. CIW_CLR_SCSI_RESET_INT);
  6181. AscSetChipStatus(iop_base, 0);
  6182. AscSetChipControl(iop_base, 0);
  6183. }
  6184. }
  6185. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6186. asc_isr_callback(asc_dvc, scsiq);
  6187. } else {
  6188. if ((AscReadLramByte(iop_base,
  6189. (ushort)(q_addr + (ushort)
  6190. ASC_SCSIQ_CDB_BEG))
  6191. == START_STOP)) {
  6192. asc_dvc->unit_not_ready &= ~target_id;
  6193. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  6194. asc_dvc->start_motor &=
  6195. ~target_id;
  6196. }
  6197. }
  6198. }
  6199. return (1);
  6200. } else {
  6201. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  6202. FATAL_ERR_QDONE:
  6203. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6204. asc_isr_callback(asc_dvc, scsiq);
  6205. }
  6206. return (0x80);
  6207. }
  6208. }
  6209. return (0);
  6210. }
  6211. static int AscISR(ASC_DVC_VAR *asc_dvc)
  6212. {
  6213. ASC_CS_TYPE chipstat;
  6214. PortAddr iop_base;
  6215. ushort saved_ram_addr;
  6216. uchar ctrl_reg;
  6217. uchar saved_ctrl_reg;
  6218. int int_pending;
  6219. int status;
  6220. uchar host_flag;
  6221. iop_base = asc_dvc->iop_base;
  6222. int_pending = ASC_FALSE;
  6223. if (AscIsIntPending(iop_base) == 0)
  6224. return int_pending;
  6225. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  6226. return ASC_ERROR;
  6227. }
  6228. if (asc_dvc->in_critical_cnt != 0) {
  6229. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  6230. return ASC_ERROR;
  6231. }
  6232. if (asc_dvc->is_in_int) {
  6233. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  6234. return ASC_ERROR;
  6235. }
  6236. asc_dvc->is_in_int = true;
  6237. ctrl_reg = AscGetChipControl(iop_base);
  6238. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  6239. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  6240. chipstat = AscGetChipStatus(iop_base);
  6241. if (chipstat & CSW_SCSI_RESET_LATCH) {
  6242. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  6243. int i = 10;
  6244. int_pending = ASC_TRUE;
  6245. asc_dvc->sdtr_done = 0;
  6246. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6247. while ((AscGetChipStatus(iop_base) &
  6248. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  6249. mdelay(100);
  6250. }
  6251. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  6252. AscSetChipControl(iop_base, CC_HALT);
  6253. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  6254. AscSetChipStatus(iop_base, 0);
  6255. chipstat = AscGetChipStatus(iop_base);
  6256. }
  6257. }
  6258. saved_ram_addr = AscGetChipLramAddr(iop_base);
  6259. host_flag = AscReadLramByte(iop_base,
  6260. ASCV_HOST_FLAG_B) &
  6261. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  6262. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6263. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  6264. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  6265. AscAckInterrupt(iop_base);
  6266. int_pending = ASC_TRUE;
  6267. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  6268. AscIsrChipHalted(asc_dvc);
  6269. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6270. } else {
  6271. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  6272. while (((status =
  6273. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  6274. }
  6275. } else {
  6276. do {
  6277. if ((status =
  6278. AscIsrQDone(asc_dvc)) == 1) {
  6279. break;
  6280. }
  6281. } while (status == 0x11);
  6282. }
  6283. if ((status & 0x80) != 0)
  6284. int_pending = ASC_ERROR;
  6285. }
  6286. }
  6287. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6288. AscSetChipLramAddr(iop_base, saved_ram_addr);
  6289. AscSetChipControl(iop_base, saved_ctrl_reg);
  6290. asc_dvc->is_in_int = false;
  6291. return int_pending;
  6292. }
  6293. /*
  6294. * advansys_reset()
  6295. *
  6296. * Reset the host associated with the command 'scp'.
  6297. *
  6298. * This function runs its own thread. Interrupts must be blocked but
  6299. * sleeping is allowed and no locking other than for host structures is
  6300. * required. Returns SUCCESS or FAILED.
  6301. */
  6302. static int advansys_reset(struct scsi_cmnd *scp)
  6303. {
  6304. struct Scsi_Host *shost = scp->device->host;
  6305. struct asc_board *boardp = shost_priv(shost);
  6306. unsigned long flags;
  6307. int status;
  6308. int ret = SUCCESS;
  6309. ASC_DBG(1, "0x%p\n", scp);
  6310. ASC_STATS(shost, reset);
  6311. scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n");
  6312. if (ASC_NARROW_BOARD(boardp)) {
  6313. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6314. /* Reset the chip and SCSI bus. */
  6315. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  6316. status = AscInitAsc1000Driver(asc_dvc);
  6317. /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
  6318. if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
  6319. scmd_printk(KERN_INFO, scp, "SCSI host reset error: "
  6320. "0x%x, status: 0x%x\n", asc_dvc->err_code,
  6321. status);
  6322. ret = FAILED;
  6323. } else if (status) {
  6324. scmd_printk(KERN_INFO, scp, "SCSI host reset warning: "
  6325. "0x%x\n", status);
  6326. } else {
  6327. scmd_printk(KERN_INFO, scp, "SCSI host reset "
  6328. "successful\n");
  6329. }
  6330. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  6331. } else {
  6332. /*
  6333. * If the suggest reset bus flags are set, then reset the bus.
  6334. * Otherwise only reset the device.
  6335. */
  6336. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  6337. /*
  6338. * Reset the chip and SCSI bus.
  6339. */
  6340. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  6341. switch (AdvResetChipAndSB(adv_dvc)) {
  6342. case ASC_TRUE:
  6343. scmd_printk(KERN_INFO, scp, "SCSI host reset "
  6344. "successful\n");
  6345. break;
  6346. case ASC_FALSE:
  6347. default:
  6348. scmd_printk(KERN_INFO, scp, "SCSI host reset error\n");
  6349. ret = FAILED;
  6350. break;
  6351. }
  6352. spin_lock_irqsave(shost->host_lock, flags);
  6353. AdvISR(adv_dvc);
  6354. spin_unlock_irqrestore(shost->host_lock, flags);
  6355. }
  6356. ASC_DBG(1, "ret %d\n", ret);
  6357. return ret;
  6358. }
  6359. /*
  6360. * advansys_biosparam()
  6361. *
  6362. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  6363. * support is enabled for a drive.
  6364. *
  6365. * ip (information pointer) is an int array with the following definition:
  6366. * ip[0]: heads
  6367. * ip[1]: sectors
  6368. * ip[2]: cylinders
  6369. */
  6370. static int
  6371. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  6372. sector_t capacity, int ip[])
  6373. {
  6374. struct asc_board *boardp = shost_priv(sdev->host);
  6375. ASC_DBG(1, "begin\n");
  6376. ASC_STATS(sdev->host, biosparam);
  6377. if (ASC_NARROW_BOARD(boardp)) {
  6378. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  6379. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  6380. ip[0] = 255;
  6381. ip[1] = 63;
  6382. } else {
  6383. ip[0] = 64;
  6384. ip[1] = 32;
  6385. }
  6386. } else {
  6387. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  6388. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  6389. ip[0] = 255;
  6390. ip[1] = 63;
  6391. } else {
  6392. ip[0] = 64;
  6393. ip[1] = 32;
  6394. }
  6395. }
  6396. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  6397. ASC_DBG(1, "end\n");
  6398. return 0;
  6399. }
  6400. /*
  6401. * First-level interrupt handler.
  6402. *
  6403. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  6404. */
  6405. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  6406. {
  6407. struct Scsi_Host *shost = dev_id;
  6408. struct asc_board *boardp = shost_priv(shost);
  6409. irqreturn_t result = IRQ_NONE;
  6410. unsigned long flags;
  6411. ASC_DBG(2, "boardp 0x%p\n", boardp);
  6412. spin_lock_irqsave(shost->host_lock, flags);
  6413. if (ASC_NARROW_BOARD(boardp)) {
  6414. if (AscIsIntPending(shost->io_port)) {
  6415. result = IRQ_HANDLED;
  6416. ASC_STATS(shost, interrupt);
  6417. ASC_DBG(1, "before AscISR()\n");
  6418. AscISR(&boardp->dvc_var.asc_dvc_var);
  6419. }
  6420. } else {
  6421. ASC_DBG(1, "before AdvISR()\n");
  6422. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  6423. result = IRQ_HANDLED;
  6424. ASC_STATS(shost, interrupt);
  6425. }
  6426. }
  6427. spin_unlock_irqrestore(shost->host_lock, flags);
  6428. ASC_DBG(1, "end\n");
  6429. return result;
  6430. }
  6431. static bool AscHostReqRiscHalt(PortAddr iop_base)
  6432. {
  6433. int count = 0;
  6434. bool sta = false;
  6435. uchar saved_stop_code;
  6436. if (AscIsChipHalted(iop_base))
  6437. return true;
  6438. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  6439. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  6440. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  6441. do {
  6442. if (AscIsChipHalted(iop_base)) {
  6443. sta = true;
  6444. break;
  6445. }
  6446. mdelay(100);
  6447. } while (count++ < 20);
  6448. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  6449. return sta;
  6450. }
  6451. static bool
  6452. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  6453. {
  6454. bool sta = false;
  6455. if (AscHostReqRiscHalt(iop_base)) {
  6456. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6457. AscStartChip(iop_base);
  6458. }
  6459. return sta;
  6460. }
  6461. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  6462. {
  6463. char type = sdev->type;
  6464. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  6465. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  6466. return;
  6467. if (asc_dvc->init_sdtr & tid_bits)
  6468. return;
  6469. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  6470. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  6471. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  6472. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  6473. (type == TYPE_ROM) || (type == TYPE_TAPE))
  6474. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  6475. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  6476. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  6477. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  6478. }
  6479. static void
  6480. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  6481. {
  6482. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  6483. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  6484. if (sdev->lun == 0) {
  6485. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  6486. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  6487. asc_dvc->init_sdtr |= tid_bit;
  6488. } else {
  6489. asc_dvc->init_sdtr &= ~tid_bit;
  6490. }
  6491. if (orig_init_sdtr != asc_dvc->init_sdtr)
  6492. AscAsyncFix(asc_dvc, sdev);
  6493. }
  6494. if (sdev->tagged_supported) {
  6495. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  6496. if (sdev->lun == 0) {
  6497. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  6498. asc_dvc->use_tagged_qng |= tid_bit;
  6499. }
  6500. scsi_change_queue_depth(sdev,
  6501. asc_dvc->max_dvc_qng[sdev->id]);
  6502. }
  6503. } else {
  6504. if (sdev->lun == 0) {
  6505. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  6506. asc_dvc->use_tagged_qng &= ~tid_bit;
  6507. }
  6508. }
  6509. if ((sdev->lun == 0) &&
  6510. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  6511. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  6512. asc_dvc->cfg->disc_enable);
  6513. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  6514. asc_dvc->use_tagged_qng);
  6515. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  6516. asc_dvc->cfg->can_tagged_qng);
  6517. asc_dvc->max_dvc_qng[sdev->id] =
  6518. asc_dvc->cfg->max_tag_qng[sdev->id];
  6519. AscWriteLramByte(asc_dvc->iop_base,
  6520. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  6521. asc_dvc->max_dvc_qng[sdev->id]);
  6522. }
  6523. }
  6524. /*
  6525. * Wide Transfers
  6526. *
  6527. * If the EEPROM enabled WDTR for the device and the device supports wide
  6528. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  6529. * write the new value to the microcode.
  6530. */
  6531. static void
  6532. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6533. {
  6534. unsigned short cfg_word;
  6535. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6536. if ((cfg_word & tidmask) != 0)
  6537. return;
  6538. cfg_word |= tidmask;
  6539. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6540. /*
  6541. * Clear the microcode SDTR and WDTR negotiation done indicators for
  6542. * the target to cause it to negotiate with the new setting set above.
  6543. * WDTR when accepted causes the target to enter asynchronous mode, so
  6544. * SDTR must be negotiated.
  6545. */
  6546. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6547. cfg_word &= ~tidmask;
  6548. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6549. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6550. cfg_word &= ~tidmask;
  6551. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6552. }
  6553. /*
  6554. * Synchronous Transfers
  6555. *
  6556. * If the EEPROM enabled SDTR for the device and the device
  6557. * supports synchronous transfers, then turn on the device's
  6558. * 'sdtr_able' bit. Write the new value to the microcode.
  6559. */
  6560. static void
  6561. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6562. {
  6563. unsigned short cfg_word;
  6564. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6565. if ((cfg_word & tidmask) != 0)
  6566. return;
  6567. cfg_word |= tidmask;
  6568. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6569. /*
  6570. * Clear the microcode "SDTR negotiation" done indicator for the
  6571. * target to cause it to negotiate with the new setting set above.
  6572. */
  6573. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6574. cfg_word &= ~tidmask;
  6575. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6576. }
  6577. /*
  6578. * PPR (Parallel Protocol Request) Capable
  6579. *
  6580. * If the device supports DT mode, then it must be PPR capable.
  6581. * The PPR message will be used in place of the SDTR and WDTR
  6582. * messages to negotiate synchronous speed and offset, transfer
  6583. * width, and protocol options.
  6584. */
  6585. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  6586. AdvPortAddr iop_base, unsigned short tidmask)
  6587. {
  6588. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  6589. adv_dvc->ppr_able |= tidmask;
  6590. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  6591. }
  6592. static void
  6593. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  6594. {
  6595. AdvPortAddr iop_base = adv_dvc->iop_base;
  6596. unsigned short tidmask = 1 << sdev->id;
  6597. if (sdev->lun == 0) {
  6598. /*
  6599. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  6600. * is enabled in the EEPROM and the device supports the
  6601. * feature, then enable it in the microcode.
  6602. */
  6603. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  6604. advansys_wide_enable_wdtr(iop_base, tidmask);
  6605. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  6606. advansys_wide_enable_sdtr(iop_base, tidmask);
  6607. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  6608. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  6609. /*
  6610. * Tag Queuing is disabled for the BIOS which runs in polled
  6611. * mode and would see no benefit from Tag Queuing. Also by
  6612. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  6613. * bugs will at least work with the BIOS.
  6614. */
  6615. if ((adv_dvc->tagqng_able & tidmask) &&
  6616. sdev->tagged_supported) {
  6617. unsigned short cfg_word;
  6618. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  6619. cfg_word |= tidmask;
  6620. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  6621. cfg_word);
  6622. AdvWriteByteLram(iop_base,
  6623. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  6624. adv_dvc->max_dvc_qng);
  6625. }
  6626. }
  6627. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
  6628. scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
  6629. }
  6630. /*
  6631. * Set the number of commands to queue per device for the
  6632. * specified host adapter.
  6633. */
  6634. static int advansys_slave_configure(struct scsi_device *sdev)
  6635. {
  6636. struct asc_board *boardp = shost_priv(sdev->host);
  6637. if (ASC_NARROW_BOARD(boardp))
  6638. advansys_narrow_slave_configure(sdev,
  6639. &boardp->dvc_var.asc_dvc_var);
  6640. else
  6641. advansys_wide_slave_configure(sdev,
  6642. &boardp->dvc_var.adv_dvc_var);
  6643. return 0;
  6644. }
  6645. static __le32 asc_get_sense_buffer_dma(struct scsi_cmnd *scp)
  6646. {
  6647. struct asc_board *board = shost_priv(scp->device->host);
  6648. struct advansys_cmd *acmd = advansys_cmd(scp);
  6649. acmd->dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  6650. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6651. if (dma_mapping_error(board->dev, acmd->dma_handle)) {
  6652. ASC_DBG(1, "failed to map sense buffer\n");
  6653. return 0;
  6654. }
  6655. return cpu_to_le32(acmd->dma_handle);
  6656. }
  6657. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  6658. struct asc_scsi_q *asc_scsi_q)
  6659. {
  6660. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6661. int use_sg;
  6662. u32 srb_tag;
  6663. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  6664. /*
  6665. * Set the srb_tag to the command tag + 1, as
  6666. * srb_tag '0' is used internally by the chip.
  6667. */
  6668. srb_tag = scsi_cmd_to_rq(scp)->tag + 1;
  6669. asc_scsi_q->q2.srb_tag = srb_tag;
  6670. /*
  6671. * Build the ASC_SCSI_Q request.
  6672. */
  6673. asc_scsi_q->cdbptr = &scp->cmnd[0];
  6674. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  6675. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  6676. asc_scsi_q->q1.target_lun = scp->device->lun;
  6677. asc_scsi_q->q2.target_ix =
  6678. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  6679. asc_scsi_q->q1.sense_addr = asc_get_sense_buffer_dma(scp);
  6680. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  6681. if (!asc_scsi_q->q1.sense_addr)
  6682. return ASC_BUSY;
  6683. /*
  6684. * If there are any outstanding requests for the current target,
  6685. * then every 255th request send an ORDERED request. This heuristic
  6686. * tries to retain the benefit of request sorting while preventing
  6687. * request starvation. 255 is the max number of tags or pending commands
  6688. * a device may have outstanding.
  6689. *
  6690. * The request count is incremented below for every successfully
  6691. * started request.
  6692. *
  6693. */
  6694. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  6695. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  6696. asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG;
  6697. } else {
  6698. asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG;
  6699. }
  6700. /* Build ASC_SCSI_Q */
  6701. use_sg = scsi_dma_map(scp);
  6702. if (use_sg < 0) {
  6703. ASC_DBG(1, "failed to map sglist\n");
  6704. return ASC_BUSY;
  6705. } else if (use_sg > 0) {
  6706. int sgcnt;
  6707. struct scatterlist *slp;
  6708. struct asc_sg_head *asc_sg_head;
  6709. if (use_sg > scp->device->host->sg_tablesize) {
  6710. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  6711. "sg_tablesize %d\n", use_sg,
  6712. scp->device->host->sg_tablesize);
  6713. scsi_dma_unmap(scp);
  6714. set_host_byte(scp, DID_ERROR);
  6715. return ASC_ERROR;
  6716. }
  6717. asc_sg_head = kzalloc(struct_size(asc_sg_head, sg_list, use_sg),
  6718. GFP_ATOMIC);
  6719. if (!asc_sg_head) {
  6720. scsi_dma_unmap(scp);
  6721. set_host_byte(scp, DID_SOFT_ERROR);
  6722. return ASC_ERROR;
  6723. }
  6724. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  6725. asc_scsi_q->sg_head = asc_sg_head;
  6726. asc_scsi_q->q1.data_cnt = 0;
  6727. asc_scsi_q->q1.data_addr = 0;
  6728. /* This is a byte value, otherwise it would need to be swapped. */
  6729. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  6730. ASC_STATS_ADD(scp->device->host, xfer_elem,
  6731. asc_sg_head->entry_cnt);
  6732. /*
  6733. * Convert scatter-gather list into ASC_SG_HEAD list.
  6734. */
  6735. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  6736. asc_sg_head->sg_list[sgcnt].addr =
  6737. cpu_to_le32(sg_dma_address(slp));
  6738. asc_sg_head->sg_list[sgcnt].bytes =
  6739. cpu_to_le32(sg_dma_len(slp));
  6740. ASC_STATS_ADD(scp->device->host, xfer_sect,
  6741. DIV_ROUND_UP(sg_dma_len(slp), 512));
  6742. }
  6743. }
  6744. ASC_STATS(scp->device->host, xfer_cnt);
  6745. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  6746. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  6747. return ASC_NOERROR;
  6748. }
  6749. /*
  6750. * Build scatter-gather list for Adv Library (Wide Board).
  6751. *
  6752. * Additional ADV_SG_BLOCK structures will need to be allocated
  6753. * if the total number of scatter-gather elements exceeds
  6754. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  6755. * assumed to be physically contiguous.
  6756. *
  6757. * Return:
  6758. * ADV_SUCCESS(1) - SG List successfully created
  6759. * ADV_ERROR(-1) - SG List creation failed
  6760. */
  6761. static int
  6762. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
  6763. ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg)
  6764. {
  6765. adv_sgblk_t *sgblkp, *prev_sgblkp;
  6766. struct scatterlist *slp;
  6767. int sg_elem_cnt;
  6768. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  6769. dma_addr_t sgblk_paddr;
  6770. int i;
  6771. slp = scsi_sglist(scp);
  6772. sg_elem_cnt = use_sg;
  6773. prev_sgblkp = NULL;
  6774. prev_sg_block = NULL;
  6775. reqp->sgblkp = NULL;
  6776. for (;;) {
  6777. /*
  6778. * Allocate a 'adv_sgblk_t' structure from the board free
  6779. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  6780. * (15) scatter-gather elements.
  6781. */
  6782. sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC,
  6783. &sgblk_paddr);
  6784. if (!sgblkp) {
  6785. ASC_DBG(1, "no free adv_sgblk_t\n");
  6786. ASC_STATS(scp->device->host, adv_build_nosg);
  6787. /*
  6788. * Allocation failed. Free 'adv_sgblk_t' structures
  6789. * already allocated for the request.
  6790. */
  6791. while ((sgblkp = reqp->sgblkp) != NULL) {
  6792. /* Remove 'sgblkp' from the request list. */
  6793. reqp->sgblkp = sgblkp->next_sgblkp;
  6794. sgblkp->next_sgblkp = NULL;
  6795. dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
  6796. sgblkp->sg_addr);
  6797. }
  6798. return ASC_BUSY;
  6799. }
  6800. /* Complete 'adv_sgblk_t' board allocation. */
  6801. sgblkp->sg_addr = sgblk_paddr;
  6802. sgblkp->next_sgblkp = NULL;
  6803. sg_block = &sgblkp->sg_block;
  6804. /*
  6805. * Check if this is the first 'adv_sgblk_t' for the
  6806. * request.
  6807. */
  6808. if (reqp->sgblkp == NULL) {
  6809. /* Request's first scatter-gather block. */
  6810. reqp->sgblkp = sgblkp;
  6811. /*
  6812. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  6813. * address pointers.
  6814. */
  6815. scsiqp->sg_list_ptr = sg_block;
  6816. scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr);
  6817. } else {
  6818. /* Request's second or later scatter-gather block. */
  6819. prev_sgblkp->next_sgblkp = sgblkp;
  6820. /*
  6821. * Point the previous ADV_SG_BLOCK structure to
  6822. * the newly allocated ADV_SG_BLOCK structure.
  6823. */
  6824. prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr);
  6825. }
  6826. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  6827. sg_block->sg_list[i].sg_addr =
  6828. cpu_to_le32(sg_dma_address(slp));
  6829. sg_block->sg_list[i].sg_count =
  6830. cpu_to_le32(sg_dma_len(slp));
  6831. ASC_STATS_ADD(scp->device->host, xfer_sect,
  6832. DIV_ROUND_UP(sg_dma_len(slp), 512));
  6833. if (--sg_elem_cnt == 0) {
  6834. /*
  6835. * Last ADV_SG_BLOCK and scatter-gather entry.
  6836. */
  6837. sg_block->sg_cnt = i + 1;
  6838. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  6839. return ADV_SUCCESS;
  6840. }
  6841. slp = sg_next(slp);
  6842. }
  6843. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  6844. prev_sg_block = sg_block;
  6845. prev_sgblkp = sgblkp;
  6846. }
  6847. }
  6848. /*
  6849. * Build a request structure for the Adv Library (Wide Board).
  6850. *
  6851. * If an adv_req_t can not be allocated to issue the request,
  6852. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  6853. *
  6854. * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the
  6855. * microcode for DMA addresses or math operations are byte swapped
  6856. * to little-endian order.
  6857. */
  6858. static int
  6859. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  6860. adv_req_t **adv_reqpp)
  6861. {
  6862. u32 srb_tag = scsi_cmd_to_rq(scp)->tag;
  6863. adv_req_t *reqp;
  6864. ADV_SCSI_REQ_Q *scsiqp;
  6865. int ret;
  6866. int use_sg;
  6867. dma_addr_t sense_addr;
  6868. /*
  6869. * Allocate an adv_req_t structure from the board to execute
  6870. * the command.
  6871. */
  6872. reqp = &boardp->adv_reqp[srb_tag];
  6873. if (reqp->cmndp && reqp->cmndp != scp ) {
  6874. ASC_DBG(1, "no free adv_req_t\n");
  6875. ASC_STATS(scp->device->host, adv_build_noreq);
  6876. return ASC_BUSY;
  6877. }
  6878. reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t));
  6879. scsiqp = &reqp->scsi_req_q;
  6880. /*
  6881. * Initialize the structure.
  6882. */
  6883. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  6884. /*
  6885. * Set the srb_tag to the command tag.
  6886. */
  6887. scsiqp->srb_tag = srb_tag;
  6888. /*
  6889. * Set 'host_scribble' to point to the adv_req_t structure.
  6890. */
  6891. reqp->cmndp = scp;
  6892. scp->host_scribble = (void *)reqp;
  6893. /*
  6894. * Build the ADV_SCSI_REQ_Q request.
  6895. */
  6896. /* Set CDB length and copy it to the request structure. */
  6897. scsiqp->cdb_len = scp->cmd_len;
  6898. /* Copy first 12 CDB bytes to cdb[]. */
  6899. memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12);
  6900. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  6901. if (scp->cmd_len > 12) {
  6902. int cdb16_len = scp->cmd_len - 12;
  6903. memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len);
  6904. }
  6905. scsiqp->target_id = scp->device->id;
  6906. scsiqp->target_lun = scp->device->lun;
  6907. sense_addr = dma_map_single(boardp->dev, scp->sense_buffer,
  6908. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6909. if (dma_mapping_error(boardp->dev, sense_addr)) {
  6910. ASC_DBG(1, "failed to map sense buffer\n");
  6911. ASC_STATS(scp->device->host, adv_build_noreq);
  6912. return ASC_BUSY;
  6913. }
  6914. scsiqp->sense_addr = cpu_to_le32(sense_addr);
  6915. scsiqp->sense_len = SCSI_SENSE_BUFFERSIZE;
  6916. /* Build ADV_SCSI_REQ_Q */
  6917. use_sg = scsi_dma_map(scp);
  6918. if (use_sg < 0) {
  6919. ASC_DBG(1, "failed to map SG list\n");
  6920. ASC_STATS(scp->device->host, adv_build_noreq);
  6921. return ASC_BUSY;
  6922. } else if (use_sg == 0) {
  6923. /* Zero-length transfer */
  6924. reqp->sgblkp = NULL;
  6925. scsiqp->data_cnt = 0;
  6926. scsiqp->data_addr = 0;
  6927. scsiqp->sg_list_ptr = NULL;
  6928. scsiqp->sg_real_addr = 0;
  6929. } else {
  6930. if (use_sg > ADV_MAX_SG_LIST) {
  6931. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  6932. "ADV_MAX_SG_LIST %d\n", use_sg,
  6933. scp->device->host->sg_tablesize);
  6934. scsi_dma_unmap(scp);
  6935. set_host_byte(scp, DID_ERROR);
  6936. reqp->cmndp = NULL;
  6937. scp->host_scribble = NULL;
  6938. return ASC_ERROR;
  6939. }
  6940. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  6941. ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
  6942. if (ret != ADV_SUCCESS) {
  6943. scsi_dma_unmap(scp);
  6944. set_host_byte(scp, DID_ERROR);
  6945. reqp->cmndp = NULL;
  6946. scp->host_scribble = NULL;
  6947. return ret;
  6948. }
  6949. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  6950. }
  6951. ASC_STATS(scp->device->host, xfer_cnt);
  6952. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  6953. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  6954. *adv_reqpp = reqp;
  6955. return ASC_NOERROR;
  6956. }
  6957. static int AscSgListToQueue(int sg_list)
  6958. {
  6959. int n_sg_list_qs;
  6960. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  6961. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  6962. n_sg_list_qs++;
  6963. return n_sg_list_qs + 1;
  6964. }
  6965. static uint
  6966. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  6967. {
  6968. uint cur_used_qs;
  6969. uint cur_free_qs;
  6970. ASC_SCSI_BIT_ID_TYPE target_id;
  6971. uchar tid_no;
  6972. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  6973. tid_no = ASC_TIX_TO_TID(target_ix);
  6974. if ((asc_dvc->unit_not_ready & target_id) ||
  6975. (asc_dvc->queue_full_or_busy & target_id)) {
  6976. return 0;
  6977. }
  6978. if (n_qs == 1) {
  6979. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  6980. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  6981. } else {
  6982. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  6983. (uint) ASC_MIN_FREE_Q;
  6984. }
  6985. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  6986. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  6987. if (asc_dvc->cur_dvc_qng[tid_no] >=
  6988. asc_dvc->max_dvc_qng[tid_no]) {
  6989. return 0;
  6990. }
  6991. return cur_free_qs;
  6992. }
  6993. if (n_qs > 1) {
  6994. if ((n_qs > asc_dvc->last_q_shortage)
  6995. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  6996. asc_dvc->last_q_shortage = n_qs;
  6997. }
  6998. }
  6999. return 0;
  7000. }
  7001. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7002. {
  7003. ushort q_addr;
  7004. uchar next_qp;
  7005. uchar q_status;
  7006. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7007. q_status = (uchar)AscReadLramByte(iop_base,
  7008. (ushort)(q_addr +
  7009. ASC_SCSIQ_B_STATUS));
  7010. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7011. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7012. return next_qp;
  7013. return ASC_QLINK_END;
  7014. }
  7015. static uchar
  7016. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7017. {
  7018. uchar i;
  7019. for (i = 0; i < n_free_q; i++) {
  7020. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7021. if (free_q_head == ASC_QLINK_END)
  7022. break;
  7023. }
  7024. return free_q_head;
  7025. }
  7026. /*
  7027. * void
  7028. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7029. *
  7030. * Calling/Exit State:
  7031. * none
  7032. *
  7033. * Description:
  7034. * Output an ASC_SCSI_Q structure to the chip
  7035. */
  7036. static void
  7037. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7038. {
  7039. int i;
  7040. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7041. AscSetChipLramAddr(iop_base, s_addr);
  7042. for (i = 0; i < 2 * words; i += 2) {
  7043. if (i == 4 || i == 20) {
  7044. continue;
  7045. }
  7046. outpw(iop_base + IOP_RAM_DATA,
  7047. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7048. }
  7049. }
  7050. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7051. {
  7052. ushort q_addr;
  7053. uchar tid_no;
  7054. uchar sdtr_data;
  7055. uchar syn_period_ix;
  7056. uchar syn_offset;
  7057. PortAddr iop_base;
  7058. iop_base = asc_dvc->iop_base;
  7059. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7060. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7061. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7062. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7063. syn_period_ix =
  7064. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7065. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7066. AscMsgOutSDTR(asc_dvc,
  7067. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7068. syn_offset);
  7069. scsiq->q1.cntl |= QC_MSG_OUT;
  7070. }
  7071. q_addr = ASC_QNO_TO_QADDR(q_no);
  7072. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7073. scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
  7074. }
  7075. scsiq->q1.status = QS_FREE;
  7076. AscMemWordCopyPtrToLram(iop_base,
  7077. q_addr + ASC_SCSIQ_CDB_BEG,
  7078. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7079. DvcPutScsiQ(iop_base,
  7080. q_addr + ASC_SCSIQ_CPY_BEG,
  7081. (uchar *)&scsiq->q1.cntl,
  7082. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7083. AscWriteLramWord(iop_base,
  7084. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7085. (ushort)(((ushort)scsiq->q1.
  7086. q_no << 8) | (ushort)QS_READY));
  7087. return 1;
  7088. }
  7089. static int
  7090. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7091. {
  7092. int sta;
  7093. int i;
  7094. ASC_SG_HEAD *sg_head;
  7095. ASC_SG_LIST_Q scsi_sg_q;
  7096. __le32 saved_data_addr;
  7097. __le32 saved_data_cnt;
  7098. PortAddr iop_base;
  7099. ushort sg_list_dwords;
  7100. ushort sg_index;
  7101. ushort sg_entry_cnt;
  7102. ushort q_addr;
  7103. uchar next_qp;
  7104. iop_base = asc_dvc->iop_base;
  7105. sg_head = scsiq->sg_head;
  7106. saved_data_addr = scsiq->q1.data_addr;
  7107. saved_data_cnt = scsiq->q1.data_cnt;
  7108. scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
  7109. scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
  7110. /*
  7111. * Set sg_entry_cnt to be the number of SG elements that
  7112. * will fit in the allocated SG queues. It is minus 1, because
  7113. * the first SG element is handled above.
  7114. */
  7115. sg_entry_cnt = sg_head->entry_cnt - 1;
  7116. if (sg_entry_cnt != 0) {
  7117. scsiq->q1.cntl |= QC_SG_HEAD;
  7118. q_addr = ASC_QNO_TO_QADDR(q_no);
  7119. sg_index = 1;
  7120. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  7121. scsi_sg_q.sg_head_qp = q_no;
  7122. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  7123. for (i = 0; i < sg_head->queue_cnt; i++) {
  7124. scsi_sg_q.seq_no = i + 1;
  7125. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  7126. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  7127. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  7128. if (i == 0) {
  7129. scsi_sg_q.sg_list_cnt =
  7130. ASC_SG_LIST_PER_Q;
  7131. scsi_sg_q.sg_cur_list_cnt =
  7132. ASC_SG_LIST_PER_Q;
  7133. } else {
  7134. scsi_sg_q.sg_list_cnt =
  7135. ASC_SG_LIST_PER_Q - 1;
  7136. scsi_sg_q.sg_cur_list_cnt =
  7137. ASC_SG_LIST_PER_Q - 1;
  7138. }
  7139. } else {
  7140. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  7141. sg_list_dwords = sg_entry_cnt << 1;
  7142. if (i == 0) {
  7143. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  7144. scsi_sg_q.sg_cur_list_cnt =
  7145. sg_entry_cnt;
  7146. } else {
  7147. scsi_sg_q.sg_list_cnt =
  7148. sg_entry_cnt - 1;
  7149. scsi_sg_q.sg_cur_list_cnt =
  7150. sg_entry_cnt - 1;
  7151. }
  7152. sg_entry_cnt = 0;
  7153. }
  7154. next_qp = AscReadLramByte(iop_base,
  7155. (ushort)(q_addr +
  7156. ASC_SCSIQ_B_FWD));
  7157. scsi_sg_q.q_no = next_qp;
  7158. q_addr = ASC_QNO_TO_QADDR(next_qp);
  7159. AscMemWordCopyPtrToLram(iop_base,
  7160. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  7161. (uchar *)&scsi_sg_q,
  7162. sizeof(ASC_SG_LIST_Q) >> 1);
  7163. AscMemDWordCopyPtrToLram(iop_base,
  7164. q_addr + ASC_SGQ_LIST_BEG,
  7165. (uchar *)&sg_head->
  7166. sg_list[sg_index],
  7167. sg_list_dwords);
  7168. sg_index += ASC_SG_LIST_PER_Q;
  7169. scsiq->next_sg_index = sg_index;
  7170. }
  7171. } else {
  7172. scsiq->q1.cntl &= ~QC_SG_HEAD;
  7173. }
  7174. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  7175. scsiq->q1.data_addr = saved_data_addr;
  7176. scsiq->q1.data_cnt = saved_data_cnt;
  7177. return (sta);
  7178. }
  7179. static int
  7180. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  7181. {
  7182. PortAddr iop_base;
  7183. uchar free_q_head;
  7184. uchar next_qp;
  7185. uchar tid_no;
  7186. uchar target_ix;
  7187. int sta;
  7188. iop_base = asc_dvc->iop_base;
  7189. target_ix = scsiq->q2.target_ix;
  7190. tid_no = ASC_TIX_TO_TID(target_ix);
  7191. sta = 0;
  7192. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  7193. if (n_q_required > 1) {
  7194. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  7195. (uchar)n_q_required);
  7196. if (next_qp != ASC_QLINK_END) {
  7197. asc_dvc->last_q_shortage = 0;
  7198. scsiq->sg_head->queue_cnt = n_q_required - 1;
  7199. scsiq->q1.q_no = free_q_head;
  7200. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  7201. free_q_head);
  7202. }
  7203. } else if (n_q_required == 1) {
  7204. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  7205. if (next_qp != ASC_QLINK_END) {
  7206. scsiq->q1.q_no = free_q_head;
  7207. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  7208. }
  7209. }
  7210. if (sta == 1) {
  7211. AscPutVarFreeQHead(iop_base, next_qp);
  7212. asc_dvc->cur_total_qng += n_q_required;
  7213. asc_dvc->cur_dvc_qng[tid_no]++;
  7214. }
  7215. return sta;
  7216. }
  7217. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  7218. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  7219. INQUIRY,
  7220. REQUEST_SENSE,
  7221. READ_CAPACITY,
  7222. READ_TOC,
  7223. MODE_SELECT,
  7224. MODE_SENSE,
  7225. MODE_SELECT_10,
  7226. MODE_SENSE_10,
  7227. 0xFF,
  7228. 0xFF,
  7229. 0xFF,
  7230. 0xFF,
  7231. 0xFF,
  7232. 0xFF,
  7233. 0xFF,
  7234. 0xFF
  7235. };
  7236. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  7237. {
  7238. PortAddr iop_base;
  7239. int sta;
  7240. int n_q_required;
  7241. bool disable_syn_offset_one_fix;
  7242. int i;
  7243. u32 addr;
  7244. ushort sg_entry_cnt = 0;
  7245. ushort sg_entry_cnt_minus_one = 0;
  7246. uchar target_ix;
  7247. uchar tid_no;
  7248. uchar sdtr_data;
  7249. uchar extra_bytes;
  7250. uchar scsi_cmd;
  7251. uchar disable_cmd;
  7252. ASC_SG_HEAD *sg_head;
  7253. unsigned long data_cnt;
  7254. iop_base = asc_dvc->iop_base;
  7255. sg_head = scsiq->sg_head;
  7256. if (asc_dvc->err_code != 0)
  7257. return ASC_ERROR;
  7258. scsiq->q1.q_no = 0;
  7259. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  7260. scsiq->q1.extra_bytes = 0;
  7261. }
  7262. sta = 0;
  7263. target_ix = scsiq->q2.target_ix;
  7264. tid_no = ASC_TIX_TO_TID(target_ix);
  7265. n_q_required = 1;
  7266. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  7267. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  7268. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  7269. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7270. AscMsgOutSDTR(asc_dvc,
  7271. asc_dvc->
  7272. sdtr_period_tbl[(sdtr_data >> 4) &
  7273. (uchar)(asc_dvc->
  7274. max_sdtr_index -
  7275. 1)],
  7276. (uchar)(sdtr_data & (uchar)
  7277. ASC_SYN_MAX_OFFSET));
  7278. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  7279. }
  7280. }
  7281. if (asc_dvc->in_critical_cnt != 0) {
  7282. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  7283. return ASC_ERROR;
  7284. }
  7285. asc_dvc->in_critical_cnt++;
  7286. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7287. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  7288. asc_dvc->in_critical_cnt--;
  7289. return ASC_ERROR;
  7290. }
  7291. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  7292. asc_dvc->in_critical_cnt--;
  7293. return ASC_ERROR;
  7294. }
  7295. if (sg_entry_cnt == 1) {
  7296. scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
  7297. scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
  7298. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  7299. }
  7300. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  7301. }
  7302. scsi_cmd = scsiq->cdbptr[0];
  7303. disable_syn_offset_one_fix = false;
  7304. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  7305. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  7306. if (scsiq->q1.cntl & QC_SG_HEAD) {
  7307. data_cnt = 0;
  7308. for (i = 0; i < sg_entry_cnt; i++) {
  7309. data_cnt += le32_to_cpu(sg_head->sg_list[i].
  7310. bytes);
  7311. }
  7312. } else {
  7313. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  7314. }
  7315. if (data_cnt != 0UL) {
  7316. if (data_cnt < 512UL) {
  7317. disable_syn_offset_one_fix = true;
  7318. } else {
  7319. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  7320. i++) {
  7321. disable_cmd =
  7322. _syn_offset_one_disable_cmd[i];
  7323. if (disable_cmd == 0xFF) {
  7324. break;
  7325. }
  7326. if (scsi_cmd == disable_cmd) {
  7327. disable_syn_offset_one_fix =
  7328. true;
  7329. break;
  7330. }
  7331. }
  7332. }
  7333. }
  7334. }
  7335. if (disable_syn_offset_one_fix) {
  7336. scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
  7337. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  7338. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  7339. } else {
  7340. scsiq->q2.tag_code &= 0x27;
  7341. }
  7342. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7343. if (asc_dvc->bug_fix_cntl) {
  7344. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7345. if ((scsi_cmd == READ_6) ||
  7346. (scsi_cmd == READ_10)) {
  7347. addr = le32_to_cpu(sg_head->
  7348. sg_list
  7349. [sg_entry_cnt_minus_one].
  7350. addr) +
  7351. le32_to_cpu(sg_head->
  7352. sg_list
  7353. [sg_entry_cnt_minus_one].
  7354. bytes);
  7355. extra_bytes =
  7356. (uchar)((ushort)addr & 0x0003);
  7357. if ((extra_bytes != 0)
  7358. &&
  7359. ((scsiq->q2.
  7360. tag_code &
  7361. ASC_TAG_FLAG_EXTRA_BYTES)
  7362. == 0)) {
  7363. scsiq->q2.tag_code |=
  7364. ASC_TAG_FLAG_EXTRA_BYTES;
  7365. scsiq->q1.extra_bytes =
  7366. extra_bytes;
  7367. data_cnt =
  7368. le32_to_cpu(sg_head->
  7369. sg_list
  7370. [sg_entry_cnt_minus_one].
  7371. bytes);
  7372. data_cnt -= extra_bytes;
  7373. sg_head->
  7374. sg_list
  7375. [sg_entry_cnt_minus_one].
  7376. bytes =
  7377. cpu_to_le32(data_cnt);
  7378. }
  7379. }
  7380. }
  7381. }
  7382. sg_head->entry_to_copy = sg_head->entry_cnt;
  7383. n_q_required = AscSgListToQueue(sg_entry_cnt);
  7384. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  7385. (uint) n_q_required)
  7386. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7387. if ((sta =
  7388. AscSendScsiQueue(asc_dvc, scsiq,
  7389. n_q_required)) == 1) {
  7390. asc_dvc->in_critical_cnt--;
  7391. return (sta);
  7392. }
  7393. }
  7394. } else {
  7395. if (asc_dvc->bug_fix_cntl) {
  7396. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7397. if ((scsi_cmd == READ_6) ||
  7398. (scsi_cmd == READ_10)) {
  7399. addr =
  7400. le32_to_cpu(scsiq->q1.data_addr) +
  7401. le32_to_cpu(scsiq->q1.data_cnt);
  7402. extra_bytes =
  7403. (uchar)((ushort)addr & 0x0003);
  7404. if ((extra_bytes != 0)
  7405. &&
  7406. ((scsiq->q2.
  7407. tag_code &
  7408. ASC_TAG_FLAG_EXTRA_BYTES)
  7409. == 0)) {
  7410. data_cnt =
  7411. le32_to_cpu(scsiq->q1.
  7412. data_cnt);
  7413. if (((ushort)data_cnt & 0x01FF)
  7414. == 0) {
  7415. scsiq->q2.tag_code |=
  7416. ASC_TAG_FLAG_EXTRA_BYTES;
  7417. data_cnt -= extra_bytes;
  7418. scsiq->q1.data_cnt =
  7419. cpu_to_le32
  7420. (data_cnt);
  7421. scsiq->q1.extra_bytes =
  7422. extra_bytes;
  7423. }
  7424. }
  7425. }
  7426. }
  7427. }
  7428. n_q_required = 1;
  7429. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  7430. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7431. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  7432. n_q_required)) == 1) {
  7433. asc_dvc->in_critical_cnt--;
  7434. return (sta);
  7435. }
  7436. }
  7437. }
  7438. asc_dvc->in_critical_cnt--;
  7439. return (sta);
  7440. }
  7441. /*
  7442. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  7443. *
  7444. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  7445. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  7446. * RISC to notify it a new command is ready to be executed.
  7447. *
  7448. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  7449. * set to SCSI_MAX_RETRY.
  7450. *
  7451. * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the microcode
  7452. * for DMA addresses or math operations are byte swapped to little-endian
  7453. * order.
  7454. *
  7455. * Return:
  7456. * ADV_SUCCESS(1) - The request was successfully queued.
  7457. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  7458. * request completes.
  7459. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  7460. * host IC error.
  7461. */
  7462. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp)
  7463. {
  7464. AdvPortAddr iop_base;
  7465. ADV_CARR_T *new_carrp;
  7466. ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q;
  7467. /*
  7468. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  7469. */
  7470. if (scsiq->target_id > ADV_MAX_TID) {
  7471. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  7472. scsiq->done_status = QD_WITH_ERROR;
  7473. return ADV_ERROR;
  7474. }
  7475. iop_base = asc_dvc->iop_base;
  7476. /*
  7477. * Allocate a carrier ensuring at least one carrier always
  7478. * remains on the freelist and initialize fields.
  7479. */
  7480. new_carrp = adv_get_next_carrier(asc_dvc);
  7481. if (!new_carrp) {
  7482. ASC_DBG(1, "No free carriers\n");
  7483. return ADV_BUSY;
  7484. }
  7485. asc_dvc->carr_pending_cnt++;
  7486. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  7487. scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag);
  7488. scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr);
  7489. scsiq->carr_va = asc_dvc->icq_sp->carr_va;
  7490. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  7491. /*
  7492. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  7493. * the microcode. The newly allocated stopper will become the new
  7494. * stopper.
  7495. */
  7496. asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr;
  7497. /*
  7498. * Set the 'next_vpa' pointer for the old stopper to be the
  7499. * physical address of the new stopper. The RISC can only
  7500. * follow physical addresses.
  7501. */
  7502. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  7503. /*
  7504. * Set the host adapter stopper pointer to point to the new carrier.
  7505. */
  7506. asc_dvc->icq_sp = new_carrp;
  7507. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  7508. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  7509. /*
  7510. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  7511. */
  7512. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  7513. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  7514. /*
  7515. * Clear the tickle value. In the ASC-3550 the RISC flag
  7516. * command 'clr_tickle_a' does not work unless the host
  7517. * value is cleared.
  7518. */
  7519. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  7520. ADV_TICKLE_NOP);
  7521. }
  7522. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  7523. /*
  7524. * Notify the RISC a carrier is ready by writing the physical
  7525. * address of the new carrier stopper to the COMMA register.
  7526. */
  7527. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  7528. le32_to_cpu(new_carrp->carr_pa));
  7529. }
  7530. return ADV_SUCCESS;
  7531. }
  7532. /*
  7533. * Execute a single 'struct scsi_cmnd'.
  7534. */
  7535. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  7536. {
  7537. int ret, err_code;
  7538. struct asc_board *boardp = shost_priv(scp->device->host);
  7539. ASC_DBG(1, "scp 0x%p\n", scp);
  7540. if (ASC_NARROW_BOARD(boardp)) {
  7541. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7542. struct asc_scsi_q asc_scsi_q;
  7543. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  7544. if (ret != ASC_NOERROR) {
  7545. ASC_STATS(scp->device->host, build_error);
  7546. return ret;
  7547. }
  7548. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  7549. kfree(asc_scsi_q.sg_head);
  7550. err_code = asc_dvc->err_code;
  7551. } else {
  7552. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  7553. adv_req_t *adv_reqp;
  7554. switch (adv_build_req(boardp, scp, &adv_reqp)) {
  7555. case ASC_NOERROR:
  7556. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  7557. break;
  7558. case ASC_BUSY:
  7559. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  7560. /*
  7561. * The asc_stats fields 'adv_build_noreq' and
  7562. * 'adv_build_nosg' count wide board busy conditions.
  7563. * They are updated in adv_build_req and
  7564. * adv_get_sglist, respectively.
  7565. */
  7566. return ASC_BUSY;
  7567. case ASC_ERROR:
  7568. default:
  7569. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  7570. ASC_STATS(scp->device->host, build_error);
  7571. return ASC_ERROR;
  7572. }
  7573. ret = AdvExeScsiQueue(adv_dvc, adv_reqp);
  7574. err_code = adv_dvc->err_code;
  7575. }
  7576. switch (ret) {
  7577. case ASC_NOERROR:
  7578. ASC_STATS(scp->device->host, exe_noerror);
  7579. /*
  7580. * Increment monotonically increasing per device
  7581. * successful request counter. Wrapping doesn't matter.
  7582. */
  7583. boardp->reqcnt[scp->device->id]++;
  7584. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  7585. break;
  7586. case ASC_BUSY:
  7587. ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n");
  7588. ASC_STATS(scp->device->host, exe_busy);
  7589. break;
  7590. case ASC_ERROR:
  7591. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  7592. "err_code 0x%x\n", err_code);
  7593. ASC_STATS(scp->device->host, exe_error);
  7594. set_host_byte(scp, DID_ERROR);
  7595. break;
  7596. default:
  7597. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  7598. "err_code 0x%x\n", err_code);
  7599. ASC_STATS(scp->device->host, exe_unknown);
  7600. set_host_byte(scp, DID_ERROR);
  7601. break;
  7602. }
  7603. ASC_DBG(1, "end\n");
  7604. return ret;
  7605. }
  7606. /*
  7607. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  7608. *
  7609. * This function always returns 0. Command return status is saved
  7610. * in the 'scp' result field.
  7611. */
  7612. static int advansys_queuecommand_lck(struct scsi_cmnd *scp)
  7613. {
  7614. struct Scsi_Host *shost = scp->device->host;
  7615. int asc_res, result = 0;
  7616. ASC_STATS(shost, queuecommand);
  7617. asc_res = asc_execute_scsi_cmnd(scp);
  7618. switch (asc_res) {
  7619. case ASC_NOERROR:
  7620. break;
  7621. case ASC_BUSY:
  7622. result = SCSI_MLQUEUE_HOST_BUSY;
  7623. break;
  7624. case ASC_ERROR:
  7625. default:
  7626. asc_scsi_done(scp);
  7627. break;
  7628. }
  7629. return result;
  7630. }
  7631. static DEF_SCSI_QCMD(advansys_queuecommand)
  7632. static ushort AscGetEisaChipCfg(PortAddr iop_base)
  7633. {
  7634. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  7635. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  7636. return inpw(eisa_cfg_iop);
  7637. }
  7638. /*
  7639. * Return the BIOS address of the adapter at the specified
  7640. * I/O port and with the specified bus type.
  7641. */
  7642. static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
  7643. unsigned short bus_type)
  7644. {
  7645. unsigned short cfg_lsw;
  7646. unsigned short bios_addr;
  7647. /*
  7648. * The PCI BIOS is re-located by the motherboard BIOS. Because
  7649. * of this the driver can not determine where a PCI BIOS is
  7650. * loaded and executes.
  7651. */
  7652. if (bus_type & ASC_IS_PCI)
  7653. return 0;
  7654. if ((bus_type & ASC_IS_EISA) != 0) {
  7655. cfg_lsw = AscGetEisaChipCfg(iop_base);
  7656. cfg_lsw &= 0x000F;
  7657. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  7658. return bios_addr;
  7659. }
  7660. cfg_lsw = AscGetChipCfgLsw(iop_base);
  7661. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  7662. return bios_addr;
  7663. }
  7664. static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  7665. {
  7666. ushort cfg_lsw;
  7667. if (AscGetChipScsiID(iop_base) == new_host_id) {
  7668. return (new_host_id);
  7669. }
  7670. cfg_lsw = AscGetChipCfgLsw(iop_base);
  7671. cfg_lsw &= 0xF8FF;
  7672. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  7673. AscSetChipCfgLsw(iop_base, cfg_lsw);
  7674. return (AscGetChipScsiID(iop_base));
  7675. }
  7676. static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
  7677. {
  7678. unsigned char sc;
  7679. AscSetBank(iop_base, 1);
  7680. sc = inp(iop_base + IOP_REG_SC);
  7681. AscSetBank(iop_base, 0);
  7682. return sc;
  7683. }
  7684. static unsigned char AscGetChipVersion(PortAddr iop_base,
  7685. unsigned short bus_type)
  7686. {
  7687. if (bus_type & ASC_IS_EISA) {
  7688. PortAddr eisa_iop;
  7689. unsigned char revision;
  7690. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  7691. (PortAddr) ASC_EISA_REV_IOP_MASK;
  7692. revision = inp(eisa_iop);
  7693. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  7694. }
  7695. return AscGetChipVerNo(iop_base);
  7696. }
  7697. static int AscStopQueueExe(PortAddr iop_base)
  7698. {
  7699. int count = 0;
  7700. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  7701. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  7702. ASC_STOP_REQ_RISC_STOP);
  7703. do {
  7704. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  7705. ASC_STOP_ACK_RISC_STOP) {
  7706. return (1);
  7707. }
  7708. mdelay(100);
  7709. } while (count++ < 20);
  7710. }
  7711. return (0);
  7712. }
  7713. static unsigned int AscGetMaxDmaCount(ushort bus_type)
  7714. {
  7715. if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  7716. return ASC_MAX_VL_DMA_COUNT;
  7717. return ASC_MAX_PCI_DMA_COUNT;
  7718. }
  7719. static void AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  7720. {
  7721. int i;
  7722. PortAddr iop_base;
  7723. uchar chip_version;
  7724. iop_base = asc_dvc->iop_base;
  7725. asc_dvc->err_code = 0;
  7726. if ((asc_dvc->bus_type &
  7727. (ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  7728. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  7729. }
  7730. AscSetChipControl(iop_base, CC_HALT);
  7731. AscSetChipStatus(iop_base, 0);
  7732. asc_dvc->bug_fix_cntl = 0;
  7733. asc_dvc->pci_fix_asyn_xfer = 0;
  7734. asc_dvc->pci_fix_asyn_xfer_always = 0;
  7735. /* asc_dvc->init_state initialized in AscInitGetConfig(). */
  7736. asc_dvc->sdtr_done = 0;
  7737. asc_dvc->cur_total_qng = 0;
  7738. asc_dvc->is_in_int = false;
  7739. asc_dvc->in_critical_cnt = 0;
  7740. asc_dvc->last_q_shortage = 0;
  7741. asc_dvc->use_tagged_qng = 0;
  7742. asc_dvc->no_scam = 0;
  7743. asc_dvc->unit_not_ready = 0;
  7744. asc_dvc->queue_full_or_busy = 0;
  7745. asc_dvc->redo_scam = 0;
  7746. asc_dvc->res2 = 0;
  7747. asc_dvc->min_sdtr_index = 0;
  7748. asc_dvc->cfg->can_tagged_qng = 0;
  7749. asc_dvc->cfg->cmd_qng_enabled = 0;
  7750. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  7751. asc_dvc->init_sdtr = 0;
  7752. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  7753. asc_dvc->scsi_reset_wait = 3;
  7754. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  7755. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  7756. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  7757. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  7758. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  7759. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  7760. asc_dvc->cfg->chip_version = chip_version;
  7761. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  7762. asc_dvc->max_sdtr_index = 7;
  7763. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  7764. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  7765. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  7766. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  7767. asc_dvc->max_sdtr_index = 15;
  7768. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  7769. AscSetExtraControl(iop_base,
  7770. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  7771. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  7772. AscSetExtraControl(iop_base,
  7773. (SEC_ACTIVE_NEGATE |
  7774. SEC_ENABLE_FILTER));
  7775. }
  7776. }
  7777. if (asc_dvc->bus_type == ASC_IS_PCI) {
  7778. AscSetExtraControl(iop_base,
  7779. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  7780. }
  7781. for (i = 0; i <= ASC_MAX_TID; i++) {
  7782. asc_dvc->cur_dvc_qng[i] = 0;
  7783. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  7784. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  7785. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  7786. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  7787. }
  7788. }
  7789. static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  7790. {
  7791. int retry;
  7792. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  7793. unsigned char read_back;
  7794. AscSetChipEEPCmd(iop_base, cmd_reg);
  7795. mdelay(1);
  7796. read_back = AscGetChipEEPCmd(iop_base);
  7797. if (read_back == cmd_reg)
  7798. return 1;
  7799. }
  7800. return 0;
  7801. }
  7802. static void AscWaitEEPRead(void)
  7803. {
  7804. mdelay(1);
  7805. }
  7806. static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
  7807. {
  7808. ushort read_wval;
  7809. uchar cmd_reg;
  7810. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  7811. AscWaitEEPRead();
  7812. cmd_reg = addr | ASC_EEP_CMD_READ;
  7813. AscWriteEEPCmdReg(iop_base, cmd_reg);
  7814. AscWaitEEPRead();
  7815. read_wval = AscGetChipEEPData(iop_base);
  7816. AscWaitEEPRead();
  7817. return read_wval;
  7818. }
  7819. static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  7820. ushort bus_type)
  7821. {
  7822. ushort wval;
  7823. ushort sum;
  7824. ushort *wbuf;
  7825. int cfg_beg;
  7826. int cfg_end;
  7827. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  7828. int s_addr;
  7829. wbuf = (ushort *)cfg_buf;
  7830. sum = 0;
  7831. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  7832. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  7833. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  7834. sum += *wbuf;
  7835. }
  7836. if (bus_type & ASC_IS_VL) {
  7837. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  7838. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  7839. } else {
  7840. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  7841. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  7842. }
  7843. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  7844. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  7845. if (s_addr <= uchar_end_in_config) {
  7846. /*
  7847. * Swap all char fields - must unswap bytes already swapped
  7848. * by AscReadEEPWord().
  7849. */
  7850. *wbuf = le16_to_cpu(wval);
  7851. } else {
  7852. /* Don't swap word field at the end - cntl field. */
  7853. *wbuf = wval;
  7854. }
  7855. sum += wval; /* Checksum treats all EEPROM data as words. */
  7856. }
  7857. /*
  7858. * Read the checksum word which will be compared against 'sum'
  7859. * by the caller. Word field already swapped.
  7860. */
  7861. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  7862. return sum;
  7863. }
  7864. static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  7865. {
  7866. PortAddr iop_base;
  7867. ushort q_addr;
  7868. ushort saved_word;
  7869. int sta;
  7870. iop_base = asc_dvc->iop_base;
  7871. sta = 0;
  7872. q_addr = ASC_QNO_TO_QADDR(241);
  7873. saved_word = AscReadLramWord(iop_base, q_addr);
  7874. AscSetChipLramAddr(iop_base, q_addr);
  7875. AscSetChipLramData(iop_base, 0x55AA);
  7876. mdelay(10);
  7877. AscSetChipLramAddr(iop_base, q_addr);
  7878. if (AscGetChipLramData(iop_base) == 0x55AA) {
  7879. sta = 1;
  7880. AscWriteLramWord(iop_base, q_addr, saved_word);
  7881. }
  7882. return (sta);
  7883. }
  7884. static void AscWaitEEPWrite(void)
  7885. {
  7886. mdelay(20);
  7887. }
  7888. static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  7889. {
  7890. ushort read_back;
  7891. int retry;
  7892. retry = 0;
  7893. while (true) {
  7894. AscSetChipEEPData(iop_base, data_reg);
  7895. mdelay(1);
  7896. read_back = AscGetChipEEPData(iop_base);
  7897. if (read_back == data_reg) {
  7898. return (1);
  7899. }
  7900. if (retry++ > ASC_EEP_MAX_RETRY) {
  7901. return (0);
  7902. }
  7903. }
  7904. }
  7905. static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  7906. {
  7907. ushort read_wval;
  7908. read_wval = AscReadEEPWord(iop_base, addr);
  7909. if (read_wval != word_val) {
  7910. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  7911. AscWaitEEPRead();
  7912. AscWriteEEPDataReg(iop_base, word_val);
  7913. AscWaitEEPRead();
  7914. AscWriteEEPCmdReg(iop_base,
  7915. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  7916. AscWaitEEPWrite();
  7917. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  7918. AscWaitEEPRead();
  7919. return (AscReadEEPWord(iop_base, addr));
  7920. }
  7921. return (read_wval);
  7922. }
  7923. static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  7924. ushort bus_type)
  7925. {
  7926. int n_error;
  7927. ushort *wbuf;
  7928. ushort word;
  7929. ushort sum;
  7930. int s_addr;
  7931. int cfg_beg;
  7932. int cfg_end;
  7933. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  7934. wbuf = (ushort *)cfg_buf;
  7935. n_error = 0;
  7936. sum = 0;
  7937. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  7938. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  7939. sum += *wbuf;
  7940. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  7941. n_error++;
  7942. }
  7943. }
  7944. if (bus_type & ASC_IS_VL) {
  7945. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  7946. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  7947. } else {
  7948. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  7949. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  7950. }
  7951. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  7952. if (s_addr <= uchar_end_in_config) {
  7953. /*
  7954. * This is a char field. Swap char fields before they are
  7955. * swapped again by AscWriteEEPWord().
  7956. */
  7957. word = cpu_to_le16(*wbuf);
  7958. if (word !=
  7959. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  7960. n_error++;
  7961. }
  7962. } else {
  7963. /* Don't swap word field at the end - cntl field. */
  7964. if (*wbuf !=
  7965. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  7966. n_error++;
  7967. }
  7968. }
  7969. sum += *wbuf; /* Checksum calculated from word values. */
  7970. }
  7971. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  7972. *wbuf = sum;
  7973. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  7974. n_error++;
  7975. }
  7976. /* Read EEPROM back again. */
  7977. wbuf = (ushort *)cfg_buf;
  7978. /*
  7979. * Read two config words; Byte-swapping done by AscReadEEPWord().
  7980. */
  7981. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  7982. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  7983. n_error++;
  7984. }
  7985. }
  7986. if (bus_type & ASC_IS_VL) {
  7987. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  7988. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  7989. } else {
  7990. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  7991. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  7992. }
  7993. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  7994. if (s_addr <= uchar_end_in_config) {
  7995. /*
  7996. * Swap all char fields. Must unswap bytes already swapped
  7997. * by AscReadEEPWord().
  7998. */
  7999. word =
  8000. le16_to_cpu(AscReadEEPWord
  8001. (iop_base, (uchar)s_addr));
  8002. } else {
  8003. /* Don't swap word field at the end - cntl field. */
  8004. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  8005. }
  8006. if (*wbuf != word) {
  8007. n_error++;
  8008. }
  8009. }
  8010. /* Read checksum; Byte swapping not needed. */
  8011. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  8012. n_error++;
  8013. }
  8014. return n_error;
  8015. }
  8016. static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8017. ushort bus_type)
  8018. {
  8019. int retry;
  8020. int n_error;
  8021. retry = 0;
  8022. while (true) {
  8023. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  8024. bus_type)) == 0) {
  8025. break;
  8026. }
  8027. if (++retry > ASC_EEP_MAX_RETRY) {
  8028. break;
  8029. }
  8030. }
  8031. return n_error;
  8032. }
  8033. static int AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  8034. {
  8035. ASCEEP_CONFIG eep_config_buf;
  8036. ASCEEP_CONFIG *eep_config;
  8037. PortAddr iop_base;
  8038. ushort chksum;
  8039. ushort warn_code;
  8040. ushort cfg_msw, cfg_lsw;
  8041. int i;
  8042. int write_eep = 0;
  8043. iop_base = asc_dvc->iop_base;
  8044. warn_code = 0;
  8045. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  8046. AscStopQueueExe(iop_base);
  8047. if ((AscStopChip(iop_base)) ||
  8048. (AscGetChipScsiCtrl(iop_base) != 0)) {
  8049. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  8050. AscResetChipAndScsiBus(asc_dvc);
  8051. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  8052. }
  8053. if (!AscIsChipHalted(iop_base)) {
  8054. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  8055. return (warn_code);
  8056. }
  8057. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  8058. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  8059. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  8060. return (warn_code);
  8061. }
  8062. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  8063. cfg_msw = AscGetChipCfgMsw(iop_base);
  8064. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8065. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8066. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8067. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8068. AscSetChipCfgMsw(iop_base, cfg_msw);
  8069. }
  8070. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  8071. ASC_DBG(1, "chksum 0x%x\n", chksum);
  8072. if (chksum == 0) {
  8073. chksum = 0xaa55;
  8074. }
  8075. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8076. warn_code |= ASC_WARN_AUTO_CONFIG;
  8077. if (asc_dvc->cfg->chip_version == 3) {
  8078. if (eep_config->cfg_lsw != cfg_lsw) {
  8079. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8080. eep_config->cfg_lsw =
  8081. AscGetChipCfgLsw(iop_base);
  8082. }
  8083. if (eep_config->cfg_msw != cfg_msw) {
  8084. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8085. eep_config->cfg_msw =
  8086. AscGetChipCfgMsw(iop_base);
  8087. }
  8088. }
  8089. }
  8090. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8091. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  8092. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  8093. if (chksum != eep_config->chksum) {
  8094. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  8095. ASC_CHIP_VER_PCI_ULTRA_3050) {
  8096. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  8097. eep_config->init_sdtr = 0xFF;
  8098. eep_config->disc_enable = 0xFF;
  8099. eep_config->start_motor = 0xFF;
  8100. eep_config->use_cmd_qng = 0;
  8101. eep_config->max_total_qng = 0xF0;
  8102. eep_config->max_tag_qng = 0x20;
  8103. eep_config->cntl = 0xBFFF;
  8104. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  8105. eep_config->no_scam = 0;
  8106. eep_config->adapter_info[0] = 0;
  8107. eep_config->adapter_info[1] = 0;
  8108. eep_config->adapter_info[2] = 0;
  8109. eep_config->adapter_info[3] = 0;
  8110. eep_config->adapter_info[4] = 0;
  8111. /* Indicate EEPROM-less board. */
  8112. eep_config->adapter_info[5] = 0xBB;
  8113. } else {
  8114. ASC_PRINT
  8115. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  8116. write_eep = 1;
  8117. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  8118. }
  8119. }
  8120. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  8121. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  8122. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  8123. asc_dvc->start_motor = eep_config->start_motor;
  8124. asc_dvc->dvc_cntl = eep_config->cntl;
  8125. asc_dvc->no_scam = eep_config->no_scam;
  8126. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  8127. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  8128. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  8129. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  8130. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  8131. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  8132. if (!AscTestExternalLram(asc_dvc)) {
  8133. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  8134. ASC_IS_PCI_ULTRA)) {
  8135. eep_config->max_total_qng =
  8136. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  8137. eep_config->max_tag_qng =
  8138. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  8139. } else {
  8140. eep_config->cfg_msw |= 0x0800;
  8141. cfg_msw |= 0x0800;
  8142. AscSetChipCfgMsw(iop_base, cfg_msw);
  8143. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  8144. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  8145. }
  8146. } else {
  8147. }
  8148. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  8149. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  8150. }
  8151. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  8152. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  8153. }
  8154. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  8155. eep_config->max_tag_qng = eep_config->max_total_qng;
  8156. }
  8157. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  8158. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  8159. }
  8160. asc_dvc->max_total_qng = eep_config->max_total_qng;
  8161. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  8162. eep_config->use_cmd_qng) {
  8163. eep_config->disc_enable = eep_config->use_cmd_qng;
  8164. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8165. }
  8166. ASC_EEP_SET_CHIP_ID(eep_config,
  8167. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  8168. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  8169. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  8170. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  8171. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  8172. }
  8173. for (i = 0; i <= ASC_MAX_TID; i++) {
  8174. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  8175. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  8176. asc_dvc->cfg->sdtr_period_offset[i] =
  8177. (uchar)(ASC_DEF_SDTR_OFFSET |
  8178. (asc_dvc->min_sdtr_index << 4));
  8179. }
  8180. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  8181. if (write_eep) {
  8182. if ((i = AscSetEEPConfig(iop_base, eep_config,
  8183. asc_dvc->bus_type)) != 0) {
  8184. ASC_PRINT1
  8185. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  8186. i);
  8187. } else {
  8188. ASC_PRINT
  8189. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  8190. }
  8191. }
  8192. return (warn_code);
  8193. }
  8194. static int AscInitGetConfig(struct Scsi_Host *shost)
  8195. {
  8196. struct asc_board *board = shost_priv(shost);
  8197. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8198. unsigned short warn_code = 0;
  8199. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  8200. if (asc_dvc->err_code != 0)
  8201. return asc_dvc->err_code;
  8202. if (AscFindSignature(asc_dvc->iop_base)) {
  8203. AscInitAscDvcVar(asc_dvc);
  8204. warn_code = AscInitFromEEP(asc_dvc);
  8205. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  8206. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  8207. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  8208. } else {
  8209. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8210. }
  8211. switch (warn_code) {
  8212. case 0: /* No error */
  8213. break;
  8214. case ASC_WARN_IO_PORT_ROTATE:
  8215. shost_printk(KERN_WARNING, shost, "I/O port address "
  8216. "modified\n");
  8217. break;
  8218. case ASC_WARN_AUTO_CONFIG:
  8219. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8220. "enabled\n");
  8221. break;
  8222. case ASC_WARN_EEPROM_CHKSUM:
  8223. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8224. break;
  8225. case ASC_WARN_IRQ_MODIFIED:
  8226. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8227. break;
  8228. case ASC_WARN_CMD_QNG_CONFLICT:
  8229. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  8230. "disconnects\n");
  8231. break;
  8232. default:
  8233. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8234. warn_code);
  8235. break;
  8236. }
  8237. if (asc_dvc->err_code != 0)
  8238. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8239. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8240. return asc_dvc->err_code;
  8241. }
  8242. static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  8243. {
  8244. struct asc_board *board = shost_priv(shost);
  8245. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8246. PortAddr iop_base = asc_dvc->iop_base;
  8247. unsigned short cfg_msw;
  8248. unsigned short warn_code = 0;
  8249. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  8250. if (asc_dvc->err_code != 0)
  8251. return asc_dvc->err_code;
  8252. if (!AscFindSignature(asc_dvc->iop_base)) {
  8253. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8254. return asc_dvc->err_code;
  8255. }
  8256. cfg_msw = AscGetChipCfgMsw(iop_base);
  8257. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8258. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8259. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8260. AscSetChipCfgMsw(iop_base, cfg_msw);
  8261. }
  8262. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  8263. asc_dvc->cfg->cmd_qng_enabled) {
  8264. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  8265. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8266. }
  8267. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8268. warn_code |= ASC_WARN_AUTO_CONFIG;
  8269. }
  8270. #ifdef CONFIG_PCI
  8271. if (asc_dvc->bus_type & ASC_IS_PCI) {
  8272. cfg_msw &= 0xFFC0;
  8273. AscSetChipCfgMsw(iop_base, cfg_msw);
  8274. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  8275. } else {
  8276. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  8277. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  8278. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  8279. asc_dvc->bug_fix_cntl |=
  8280. ASC_BUG_FIX_ASYN_USE_SYN;
  8281. }
  8282. }
  8283. } else
  8284. #endif /* CONFIG_PCI */
  8285. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  8286. asc_dvc->cfg->chip_scsi_id) {
  8287. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  8288. }
  8289. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  8290. switch (warn_code) {
  8291. case 0: /* No error. */
  8292. break;
  8293. case ASC_WARN_IO_PORT_ROTATE:
  8294. shost_printk(KERN_WARNING, shost, "I/O port address "
  8295. "modified\n");
  8296. break;
  8297. case ASC_WARN_AUTO_CONFIG:
  8298. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8299. "enabled\n");
  8300. break;
  8301. case ASC_WARN_EEPROM_CHKSUM:
  8302. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8303. break;
  8304. case ASC_WARN_IRQ_MODIFIED:
  8305. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8306. break;
  8307. case ASC_WARN_CMD_QNG_CONFLICT:
  8308. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  8309. "disconnects\n");
  8310. break;
  8311. default:
  8312. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8313. warn_code);
  8314. break;
  8315. }
  8316. if (asc_dvc->err_code != 0)
  8317. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8318. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8319. return asc_dvc->err_code;
  8320. }
  8321. /*
  8322. * EEPROM Configuration.
  8323. *
  8324. * All drivers should use this structure to set the default EEPROM
  8325. * configuration. The BIOS now uses this structure when it is built.
  8326. * Additional structure information can be found in a_condor.h where
  8327. * the structure is defined.
  8328. *
  8329. * The *_Field_IsChar structs are needed to correct for endianness.
  8330. * These values are read from the board 16 bits at a time directly
  8331. * into the structs. Because some fields are char, the values will be
  8332. * in the wrong order. The *_Field_IsChar tells when to flip the
  8333. * bytes. Data read and written to PCI memory is automatically swapped
  8334. * on big-endian platforms so char fields read as words are actually being
  8335. * unswapped on big-endian platforms.
  8336. */
  8337. #ifdef CONFIG_PCI
  8338. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
  8339. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  8340. 0x0000, /* cfg_msw */
  8341. 0xFFFF, /* disc_enable */
  8342. 0xFFFF, /* wdtr_able */
  8343. 0xFFFF, /* sdtr_able */
  8344. 0xFFFF, /* start_motor */
  8345. 0xFFFF, /* tagqng_able */
  8346. 0xFFFF, /* bios_scan */
  8347. 0, /* scam_tolerant */
  8348. 7, /* adapter_scsi_id */
  8349. 0, /* bios_boot_delay */
  8350. 3, /* scsi_reset_delay */
  8351. 0, /* bios_id_lun */
  8352. 0, /* termination */
  8353. 0, /* reserved1 */
  8354. 0xFFE7, /* bios_ctrl */
  8355. 0xFFFF, /* ultra_able */
  8356. 0, /* reserved2 */
  8357. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  8358. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8359. 0, /* dvc_cntl */
  8360. 0, /* bug_fix */
  8361. 0, /* serial_number_word1 */
  8362. 0, /* serial_number_word2 */
  8363. 0, /* serial_number_word3 */
  8364. 0, /* check_sum */
  8365. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8366. , /* oem_name[16] */
  8367. 0, /* dvc_err_code */
  8368. 0, /* adv_err_code */
  8369. 0, /* adv_err_addr */
  8370. 0, /* saved_dvc_err_code */
  8371. 0, /* saved_adv_err_code */
  8372. 0, /* saved_adv_err_addr */
  8373. 0 /* num_of_err */
  8374. };
  8375. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
  8376. 0, /* cfg_lsw */
  8377. 0, /* cfg_msw */
  8378. 0, /* -disc_enable */
  8379. 0, /* wdtr_able */
  8380. 0, /* sdtr_able */
  8381. 0, /* start_motor */
  8382. 0, /* tagqng_able */
  8383. 0, /* bios_scan */
  8384. 0, /* scam_tolerant */
  8385. 1, /* adapter_scsi_id */
  8386. 1, /* bios_boot_delay */
  8387. 1, /* scsi_reset_delay */
  8388. 1, /* bios_id_lun */
  8389. 1, /* termination */
  8390. 1, /* reserved1 */
  8391. 0, /* bios_ctrl */
  8392. 0, /* ultra_able */
  8393. 0, /* reserved2 */
  8394. 1, /* max_host_qng */
  8395. 1, /* max_dvc_qng */
  8396. 0, /* dvc_cntl */
  8397. 0, /* bug_fix */
  8398. 0, /* serial_number_word1 */
  8399. 0, /* serial_number_word2 */
  8400. 0, /* serial_number_word3 */
  8401. 0, /* check_sum */
  8402. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8403. , /* oem_name[16] */
  8404. 0, /* dvc_err_code */
  8405. 0, /* adv_err_code */
  8406. 0, /* adv_err_addr */
  8407. 0, /* saved_dvc_err_code */
  8408. 0, /* saved_adv_err_code */
  8409. 0, /* saved_adv_err_addr */
  8410. 0 /* num_of_err */
  8411. };
  8412. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
  8413. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  8414. 0x0000, /* 01 cfg_msw */
  8415. 0xFFFF, /* 02 disc_enable */
  8416. 0xFFFF, /* 03 wdtr_able */
  8417. 0x4444, /* 04 sdtr_speed1 */
  8418. 0xFFFF, /* 05 start_motor */
  8419. 0xFFFF, /* 06 tagqng_able */
  8420. 0xFFFF, /* 07 bios_scan */
  8421. 0, /* 08 scam_tolerant */
  8422. 7, /* 09 adapter_scsi_id */
  8423. 0, /* bios_boot_delay */
  8424. 3, /* 10 scsi_reset_delay */
  8425. 0, /* bios_id_lun */
  8426. 0, /* 11 termination_se */
  8427. 0, /* termination_lvd */
  8428. 0xFFE7, /* 12 bios_ctrl */
  8429. 0x4444, /* 13 sdtr_speed2 */
  8430. 0x4444, /* 14 sdtr_speed3 */
  8431. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  8432. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8433. 0, /* 16 dvc_cntl */
  8434. 0x4444, /* 17 sdtr_speed4 */
  8435. 0, /* 18 serial_number_word1 */
  8436. 0, /* 19 serial_number_word2 */
  8437. 0, /* 20 serial_number_word3 */
  8438. 0, /* 21 check_sum */
  8439. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8440. , /* 22-29 oem_name[16] */
  8441. 0, /* 30 dvc_err_code */
  8442. 0, /* 31 adv_err_code */
  8443. 0, /* 32 adv_err_addr */
  8444. 0, /* 33 saved_dvc_err_code */
  8445. 0, /* 34 saved_adv_err_code */
  8446. 0, /* 35 saved_adv_err_addr */
  8447. 0, /* 36 reserved */
  8448. 0, /* 37 reserved */
  8449. 0, /* 38 reserved */
  8450. 0, /* 39 reserved */
  8451. 0, /* 40 reserved */
  8452. 0, /* 41 reserved */
  8453. 0, /* 42 reserved */
  8454. 0, /* 43 reserved */
  8455. 0, /* 44 reserved */
  8456. 0, /* 45 reserved */
  8457. 0, /* 46 reserved */
  8458. 0, /* 47 reserved */
  8459. 0, /* 48 reserved */
  8460. 0, /* 49 reserved */
  8461. 0, /* 50 reserved */
  8462. 0, /* 51 reserved */
  8463. 0, /* 52 reserved */
  8464. 0, /* 53 reserved */
  8465. 0, /* 54 reserved */
  8466. 0, /* 55 reserved */
  8467. 0, /* 56 cisptr_lsw */
  8468. 0, /* 57 cisprt_msw */
  8469. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  8470. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  8471. 0, /* 60 reserved */
  8472. 0, /* 61 reserved */
  8473. 0, /* 62 reserved */
  8474. 0 /* 63 reserved */
  8475. };
  8476. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
  8477. 0, /* 00 cfg_lsw */
  8478. 0, /* 01 cfg_msw */
  8479. 0, /* 02 disc_enable */
  8480. 0, /* 03 wdtr_able */
  8481. 0, /* 04 sdtr_speed1 */
  8482. 0, /* 05 start_motor */
  8483. 0, /* 06 tagqng_able */
  8484. 0, /* 07 bios_scan */
  8485. 0, /* 08 scam_tolerant */
  8486. 1, /* 09 adapter_scsi_id */
  8487. 1, /* bios_boot_delay */
  8488. 1, /* 10 scsi_reset_delay */
  8489. 1, /* bios_id_lun */
  8490. 1, /* 11 termination_se */
  8491. 1, /* termination_lvd */
  8492. 0, /* 12 bios_ctrl */
  8493. 0, /* 13 sdtr_speed2 */
  8494. 0, /* 14 sdtr_speed3 */
  8495. 1, /* 15 max_host_qng */
  8496. 1, /* max_dvc_qng */
  8497. 0, /* 16 dvc_cntl */
  8498. 0, /* 17 sdtr_speed4 */
  8499. 0, /* 18 serial_number_word1 */
  8500. 0, /* 19 serial_number_word2 */
  8501. 0, /* 20 serial_number_word3 */
  8502. 0, /* 21 check_sum */
  8503. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8504. , /* 22-29 oem_name[16] */
  8505. 0, /* 30 dvc_err_code */
  8506. 0, /* 31 adv_err_code */
  8507. 0, /* 32 adv_err_addr */
  8508. 0, /* 33 saved_dvc_err_code */
  8509. 0, /* 34 saved_adv_err_code */
  8510. 0, /* 35 saved_adv_err_addr */
  8511. 0, /* 36 reserved */
  8512. 0, /* 37 reserved */
  8513. 0, /* 38 reserved */
  8514. 0, /* 39 reserved */
  8515. 0, /* 40 reserved */
  8516. 0, /* 41 reserved */
  8517. 0, /* 42 reserved */
  8518. 0, /* 43 reserved */
  8519. 0, /* 44 reserved */
  8520. 0, /* 45 reserved */
  8521. 0, /* 46 reserved */
  8522. 0, /* 47 reserved */
  8523. 0, /* 48 reserved */
  8524. 0, /* 49 reserved */
  8525. 0, /* 50 reserved */
  8526. 0, /* 51 reserved */
  8527. 0, /* 52 reserved */
  8528. 0, /* 53 reserved */
  8529. 0, /* 54 reserved */
  8530. 0, /* 55 reserved */
  8531. 0, /* 56 cisptr_lsw */
  8532. 0, /* 57 cisprt_msw */
  8533. 0, /* 58 subsysvid */
  8534. 0, /* 59 subsysid */
  8535. 0, /* 60 reserved */
  8536. 0, /* 61 reserved */
  8537. 0, /* 62 reserved */
  8538. 0 /* 63 reserved */
  8539. };
  8540. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
  8541. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  8542. 0x0000, /* 01 cfg_msw */
  8543. 0xFFFF, /* 02 disc_enable */
  8544. 0xFFFF, /* 03 wdtr_able */
  8545. 0x5555, /* 04 sdtr_speed1 */
  8546. 0xFFFF, /* 05 start_motor */
  8547. 0xFFFF, /* 06 tagqng_able */
  8548. 0xFFFF, /* 07 bios_scan */
  8549. 0, /* 08 scam_tolerant */
  8550. 7, /* 09 adapter_scsi_id */
  8551. 0, /* bios_boot_delay */
  8552. 3, /* 10 scsi_reset_delay */
  8553. 0, /* bios_id_lun */
  8554. 0, /* 11 termination_se */
  8555. 0, /* termination_lvd */
  8556. 0xFFE7, /* 12 bios_ctrl */
  8557. 0x5555, /* 13 sdtr_speed2 */
  8558. 0x5555, /* 14 sdtr_speed3 */
  8559. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  8560. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8561. 0, /* 16 dvc_cntl */
  8562. 0x5555, /* 17 sdtr_speed4 */
  8563. 0, /* 18 serial_number_word1 */
  8564. 0, /* 19 serial_number_word2 */
  8565. 0, /* 20 serial_number_word3 */
  8566. 0, /* 21 check_sum */
  8567. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8568. , /* 22-29 oem_name[16] */
  8569. 0, /* 30 dvc_err_code */
  8570. 0, /* 31 adv_err_code */
  8571. 0, /* 32 adv_err_addr */
  8572. 0, /* 33 saved_dvc_err_code */
  8573. 0, /* 34 saved_adv_err_code */
  8574. 0, /* 35 saved_adv_err_addr */
  8575. 0, /* 36 reserved */
  8576. 0, /* 37 reserved */
  8577. 0, /* 38 reserved */
  8578. 0, /* 39 reserved */
  8579. 0, /* 40 reserved */
  8580. 0, /* 41 reserved */
  8581. 0, /* 42 reserved */
  8582. 0, /* 43 reserved */
  8583. 0, /* 44 reserved */
  8584. 0, /* 45 reserved */
  8585. 0, /* 46 reserved */
  8586. 0, /* 47 reserved */
  8587. 0, /* 48 reserved */
  8588. 0, /* 49 reserved */
  8589. 0, /* 50 reserved */
  8590. 0, /* 51 reserved */
  8591. 0, /* 52 reserved */
  8592. 0, /* 53 reserved */
  8593. 0, /* 54 reserved */
  8594. 0, /* 55 reserved */
  8595. 0, /* 56 cisptr_lsw */
  8596. 0, /* 57 cisprt_msw */
  8597. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  8598. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  8599. 0, /* 60 reserved */
  8600. 0, /* 61 reserved */
  8601. 0, /* 62 reserved */
  8602. 0 /* 63 reserved */
  8603. };
  8604. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
  8605. 0, /* 00 cfg_lsw */
  8606. 0, /* 01 cfg_msw */
  8607. 0, /* 02 disc_enable */
  8608. 0, /* 03 wdtr_able */
  8609. 0, /* 04 sdtr_speed1 */
  8610. 0, /* 05 start_motor */
  8611. 0, /* 06 tagqng_able */
  8612. 0, /* 07 bios_scan */
  8613. 0, /* 08 scam_tolerant */
  8614. 1, /* 09 adapter_scsi_id */
  8615. 1, /* bios_boot_delay */
  8616. 1, /* 10 scsi_reset_delay */
  8617. 1, /* bios_id_lun */
  8618. 1, /* 11 termination_se */
  8619. 1, /* termination_lvd */
  8620. 0, /* 12 bios_ctrl */
  8621. 0, /* 13 sdtr_speed2 */
  8622. 0, /* 14 sdtr_speed3 */
  8623. 1, /* 15 max_host_qng */
  8624. 1, /* max_dvc_qng */
  8625. 0, /* 16 dvc_cntl */
  8626. 0, /* 17 sdtr_speed4 */
  8627. 0, /* 18 serial_number_word1 */
  8628. 0, /* 19 serial_number_word2 */
  8629. 0, /* 20 serial_number_word3 */
  8630. 0, /* 21 check_sum */
  8631. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8632. , /* 22-29 oem_name[16] */
  8633. 0, /* 30 dvc_err_code */
  8634. 0, /* 31 adv_err_code */
  8635. 0, /* 32 adv_err_addr */
  8636. 0, /* 33 saved_dvc_err_code */
  8637. 0, /* 34 saved_adv_err_code */
  8638. 0, /* 35 saved_adv_err_addr */
  8639. 0, /* 36 reserved */
  8640. 0, /* 37 reserved */
  8641. 0, /* 38 reserved */
  8642. 0, /* 39 reserved */
  8643. 0, /* 40 reserved */
  8644. 0, /* 41 reserved */
  8645. 0, /* 42 reserved */
  8646. 0, /* 43 reserved */
  8647. 0, /* 44 reserved */
  8648. 0, /* 45 reserved */
  8649. 0, /* 46 reserved */
  8650. 0, /* 47 reserved */
  8651. 0, /* 48 reserved */
  8652. 0, /* 49 reserved */
  8653. 0, /* 50 reserved */
  8654. 0, /* 51 reserved */
  8655. 0, /* 52 reserved */
  8656. 0, /* 53 reserved */
  8657. 0, /* 54 reserved */
  8658. 0, /* 55 reserved */
  8659. 0, /* 56 cisptr_lsw */
  8660. 0, /* 57 cisprt_msw */
  8661. 0, /* 58 subsysvid */
  8662. 0, /* 59 subsysid */
  8663. 0, /* 60 reserved */
  8664. 0, /* 61 reserved */
  8665. 0, /* 62 reserved */
  8666. 0 /* 63 reserved */
  8667. };
  8668. /*
  8669. * Wait for EEPROM command to complete
  8670. */
  8671. static void AdvWaitEEPCmd(AdvPortAddr iop_base)
  8672. {
  8673. int eep_delay_ms;
  8674. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  8675. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  8676. ASC_EEP_CMD_DONE) {
  8677. break;
  8678. }
  8679. mdelay(1);
  8680. }
  8681. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  8682. 0)
  8683. BUG();
  8684. }
  8685. /*
  8686. * Read the EEPROM from specified location
  8687. */
  8688. static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  8689. {
  8690. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8691. ASC_EEP_CMD_READ | eep_word_addr);
  8692. AdvWaitEEPCmd(iop_base);
  8693. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  8694. }
  8695. /*
  8696. * Write the EEPROM from 'cfg_buf'.
  8697. */
  8698. static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
  8699. ADVEEP_3550_CONFIG *cfg_buf)
  8700. {
  8701. ushort *wbuf;
  8702. ushort addr, chksum;
  8703. ushort *charfields;
  8704. wbuf = (ushort *)cfg_buf;
  8705. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  8706. chksum = 0;
  8707. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8708. AdvWaitEEPCmd(iop_base);
  8709. /*
  8710. * Write EEPROM from word 0 to word 20.
  8711. */
  8712. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8713. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8714. ushort word;
  8715. if (*charfields++) {
  8716. word = cpu_to_le16(*wbuf);
  8717. } else {
  8718. word = *wbuf;
  8719. }
  8720. chksum += *wbuf; /* Checksum is calculated from word values. */
  8721. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8722. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8723. ASC_EEP_CMD_WRITE | addr);
  8724. AdvWaitEEPCmd(iop_base);
  8725. mdelay(ADV_EEP_DELAY_MS);
  8726. }
  8727. /*
  8728. * Write EEPROM checksum at word 21.
  8729. */
  8730. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8731. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8732. AdvWaitEEPCmd(iop_base);
  8733. wbuf++;
  8734. charfields++;
  8735. /*
  8736. * Write EEPROM OEM name at words 22 to 29.
  8737. */
  8738. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8739. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8740. ushort word;
  8741. if (*charfields++) {
  8742. word = cpu_to_le16(*wbuf);
  8743. } else {
  8744. word = *wbuf;
  8745. }
  8746. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8747. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8748. ASC_EEP_CMD_WRITE | addr);
  8749. AdvWaitEEPCmd(iop_base);
  8750. }
  8751. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8752. AdvWaitEEPCmd(iop_base);
  8753. }
  8754. /*
  8755. * Write the EEPROM from 'cfg_buf'.
  8756. */
  8757. static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
  8758. ADVEEP_38C0800_CONFIG *cfg_buf)
  8759. {
  8760. ushort *wbuf;
  8761. ushort *charfields;
  8762. ushort addr, chksum;
  8763. wbuf = (ushort *)cfg_buf;
  8764. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  8765. chksum = 0;
  8766. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8767. AdvWaitEEPCmd(iop_base);
  8768. /*
  8769. * Write EEPROM from word 0 to word 20.
  8770. */
  8771. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8772. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8773. ushort word;
  8774. if (*charfields++) {
  8775. word = cpu_to_le16(*wbuf);
  8776. } else {
  8777. word = *wbuf;
  8778. }
  8779. chksum += *wbuf; /* Checksum is calculated from word values. */
  8780. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8781. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8782. ASC_EEP_CMD_WRITE | addr);
  8783. AdvWaitEEPCmd(iop_base);
  8784. mdelay(ADV_EEP_DELAY_MS);
  8785. }
  8786. /*
  8787. * Write EEPROM checksum at word 21.
  8788. */
  8789. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8790. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8791. AdvWaitEEPCmd(iop_base);
  8792. wbuf++;
  8793. charfields++;
  8794. /*
  8795. * Write EEPROM OEM name at words 22 to 29.
  8796. */
  8797. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8798. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8799. ushort word;
  8800. if (*charfields++) {
  8801. word = cpu_to_le16(*wbuf);
  8802. } else {
  8803. word = *wbuf;
  8804. }
  8805. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8806. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8807. ASC_EEP_CMD_WRITE | addr);
  8808. AdvWaitEEPCmd(iop_base);
  8809. }
  8810. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8811. AdvWaitEEPCmd(iop_base);
  8812. }
  8813. /*
  8814. * Write the EEPROM from 'cfg_buf'.
  8815. */
  8816. static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
  8817. ADVEEP_38C1600_CONFIG *cfg_buf)
  8818. {
  8819. ushort *wbuf;
  8820. ushort *charfields;
  8821. ushort addr, chksum;
  8822. wbuf = (ushort *)cfg_buf;
  8823. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  8824. chksum = 0;
  8825. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8826. AdvWaitEEPCmd(iop_base);
  8827. /*
  8828. * Write EEPROM from word 0 to word 20.
  8829. */
  8830. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8831. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8832. ushort word;
  8833. if (*charfields++) {
  8834. word = cpu_to_le16(*wbuf);
  8835. } else {
  8836. word = *wbuf;
  8837. }
  8838. chksum += *wbuf; /* Checksum is calculated from word values. */
  8839. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8840. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8841. ASC_EEP_CMD_WRITE | addr);
  8842. AdvWaitEEPCmd(iop_base);
  8843. mdelay(ADV_EEP_DELAY_MS);
  8844. }
  8845. /*
  8846. * Write EEPROM checksum at word 21.
  8847. */
  8848. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8849. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8850. AdvWaitEEPCmd(iop_base);
  8851. wbuf++;
  8852. charfields++;
  8853. /*
  8854. * Write EEPROM OEM name at words 22 to 29.
  8855. */
  8856. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8857. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8858. ushort word;
  8859. if (*charfields++) {
  8860. word = cpu_to_le16(*wbuf);
  8861. } else {
  8862. word = *wbuf;
  8863. }
  8864. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8865. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8866. ASC_EEP_CMD_WRITE | addr);
  8867. AdvWaitEEPCmd(iop_base);
  8868. }
  8869. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8870. AdvWaitEEPCmd(iop_base);
  8871. }
  8872. /*
  8873. * Read EEPROM configuration into the specified buffer.
  8874. *
  8875. * Return a checksum based on the EEPROM configuration read.
  8876. */
  8877. static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
  8878. ADVEEP_3550_CONFIG *cfg_buf)
  8879. {
  8880. ushort wval, chksum;
  8881. ushort *wbuf;
  8882. int eep_addr;
  8883. ushort *charfields;
  8884. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  8885. wbuf = (ushort *)cfg_buf;
  8886. chksum = 0;
  8887. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  8888. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  8889. wval = AdvReadEEPWord(iop_base, eep_addr);
  8890. chksum += wval; /* Checksum is calculated from word values. */
  8891. if (*charfields++) {
  8892. *wbuf = le16_to_cpu(wval);
  8893. } else {
  8894. *wbuf = wval;
  8895. }
  8896. }
  8897. /* Read checksum word. */
  8898. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  8899. wbuf++;
  8900. charfields++;
  8901. /* Read rest of EEPROM not covered by the checksum. */
  8902. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  8903. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  8904. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  8905. if (*charfields++) {
  8906. *wbuf = le16_to_cpu(*wbuf);
  8907. }
  8908. }
  8909. return chksum;
  8910. }
  8911. /*
  8912. * Read EEPROM configuration into the specified buffer.
  8913. *
  8914. * Return a checksum based on the EEPROM configuration read.
  8915. */
  8916. static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
  8917. ADVEEP_38C0800_CONFIG *cfg_buf)
  8918. {
  8919. ushort wval, chksum;
  8920. ushort *wbuf;
  8921. int eep_addr;
  8922. ushort *charfields;
  8923. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  8924. wbuf = (ushort *)cfg_buf;
  8925. chksum = 0;
  8926. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  8927. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  8928. wval = AdvReadEEPWord(iop_base, eep_addr);
  8929. chksum += wval; /* Checksum is calculated from word values. */
  8930. if (*charfields++) {
  8931. *wbuf = le16_to_cpu(wval);
  8932. } else {
  8933. *wbuf = wval;
  8934. }
  8935. }
  8936. /* Read checksum word. */
  8937. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  8938. wbuf++;
  8939. charfields++;
  8940. /* Read rest of EEPROM not covered by the checksum. */
  8941. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  8942. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  8943. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  8944. if (*charfields++) {
  8945. *wbuf = le16_to_cpu(*wbuf);
  8946. }
  8947. }
  8948. return chksum;
  8949. }
  8950. /*
  8951. * Read EEPROM configuration into the specified buffer.
  8952. *
  8953. * Return a checksum based on the EEPROM configuration read.
  8954. */
  8955. static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
  8956. ADVEEP_38C1600_CONFIG *cfg_buf)
  8957. {
  8958. ushort wval, chksum;
  8959. ushort *wbuf;
  8960. int eep_addr;
  8961. ushort *charfields;
  8962. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  8963. wbuf = (ushort *)cfg_buf;
  8964. chksum = 0;
  8965. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  8966. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  8967. wval = AdvReadEEPWord(iop_base, eep_addr);
  8968. chksum += wval; /* Checksum is calculated from word values. */
  8969. if (*charfields++) {
  8970. *wbuf = le16_to_cpu(wval);
  8971. } else {
  8972. *wbuf = wval;
  8973. }
  8974. }
  8975. /* Read checksum word. */
  8976. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  8977. wbuf++;
  8978. charfields++;
  8979. /* Read rest of EEPROM not covered by the checksum. */
  8980. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  8981. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  8982. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  8983. if (*charfields++) {
  8984. *wbuf = le16_to_cpu(*wbuf);
  8985. }
  8986. }
  8987. return chksum;
  8988. }
  8989. /*
  8990. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  8991. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  8992. * all of this is done.
  8993. *
  8994. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  8995. *
  8996. * For a non-fatal error return a warning code. If there are no warnings
  8997. * then 0 is returned.
  8998. *
  8999. * Note: Chip is stopped on entry.
  9000. */
  9001. static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  9002. {
  9003. AdvPortAddr iop_base;
  9004. ushort warn_code;
  9005. ADVEEP_3550_CONFIG eep_config;
  9006. iop_base = asc_dvc->iop_base;
  9007. warn_code = 0;
  9008. /*
  9009. * Read the board's EEPROM configuration.
  9010. *
  9011. * Set default values if a bad checksum is found.
  9012. */
  9013. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  9014. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9015. /*
  9016. * Set EEPROM default values.
  9017. */
  9018. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  9019. sizeof(ADVEEP_3550_CONFIG));
  9020. /*
  9021. * Assume the 6 byte board serial number that was read from
  9022. * EEPROM is correct even if the EEPROM checksum failed.
  9023. */
  9024. eep_config.serial_number_word3 =
  9025. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9026. eep_config.serial_number_word2 =
  9027. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9028. eep_config.serial_number_word1 =
  9029. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9030. AdvSet3550EEPConfig(iop_base, &eep_config);
  9031. }
  9032. /*
  9033. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9034. * EEPROM configuration that was read.
  9035. *
  9036. * This is the mapping of EEPROM fields to Adv Library fields.
  9037. */
  9038. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9039. asc_dvc->sdtr_able = eep_config.sdtr_able;
  9040. asc_dvc->ultra_able = eep_config.ultra_able;
  9041. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9042. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9043. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9044. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9045. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9046. asc_dvc->start_motor = eep_config.start_motor;
  9047. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9048. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9049. asc_dvc->no_scam = eep_config.scam_tolerant;
  9050. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9051. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9052. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9053. /*
  9054. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9055. * maximum queuing (max. 63, min. 4).
  9056. */
  9057. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9058. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9059. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9060. /* If the value is zero, assume it is uninitialized. */
  9061. if (eep_config.max_host_qng == 0) {
  9062. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9063. } else {
  9064. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9065. }
  9066. }
  9067. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9068. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9069. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9070. /* If the value is zero, assume it is uninitialized. */
  9071. if (eep_config.max_dvc_qng == 0) {
  9072. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9073. } else {
  9074. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9075. }
  9076. }
  9077. /*
  9078. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9079. * set 'max_dvc_qng' to 'max_host_qng'.
  9080. */
  9081. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9082. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9083. }
  9084. /*
  9085. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9086. * values based on possibly adjusted EEPROM values.
  9087. */
  9088. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9089. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9090. /*
  9091. * If the EEPROM 'termination' field is set to automatic (0), then set
  9092. * the ADV_DVC_CFG 'termination' field to automatic also.
  9093. *
  9094. * If the termination is specified with a non-zero 'termination'
  9095. * value check that a legal value is set and set the ADV_DVC_CFG
  9096. * 'termination' field appropriately.
  9097. */
  9098. if (eep_config.termination == 0) {
  9099. asc_dvc->cfg->termination = 0; /* auto termination */
  9100. } else {
  9101. /* Enable manual control with low off / high off. */
  9102. if (eep_config.termination == 1) {
  9103. asc_dvc->cfg->termination = TERM_CTL_SEL;
  9104. /* Enable manual control with low off / high on. */
  9105. } else if (eep_config.termination == 2) {
  9106. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  9107. /* Enable manual control with low on / high on. */
  9108. } else if (eep_config.termination == 3) {
  9109. asc_dvc->cfg->termination =
  9110. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  9111. } else {
  9112. /*
  9113. * The EEPROM 'termination' field contains a bad value. Use
  9114. * automatic termination instead.
  9115. */
  9116. asc_dvc->cfg->termination = 0;
  9117. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9118. }
  9119. }
  9120. return warn_code;
  9121. }
  9122. /*
  9123. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9124. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9125. * all of this is done.
  9126. *
  9127. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9128. *
  9129. * For a non-fatal error return a warning code. If there are no warnings
  9130. * then 0 is returned.
  9131. *
  9132. * Note: Chip is stopped on entry.
  9133. */
  9134. static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  9135. {
  9136. AdvPortAddr iop_base;
  9137. ushort warn_code;
  9138. ADVEEP_38C0800_CONFIG eep_config;
  9139. uchar tid, termination;
  9140. ushort sdtr_speed = 0;
  9141. iop_base = asc_dvc->iop_base;
  9142. warn_code = 0;
  9143. /*
  9144. * Read the board's EEPROM configuration.
  9145. *
  9146. * Set default values if a bad checksum is found.
  9147. */
  9148. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  9149. eep_config.check_sum) {
  9150. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9151. /*
  9152. * Set EEPROM default values.
  9153. */
  9154. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  9155. sizeof(ADVEEP_38C0800_CONFIG));
  9156. /*
  9157. * Assume the 6 byte board serial number that was read from
  9158. * EEPROM is correct even if the EEPROM checksum failed.
  9159. */
  9160. eep_config.serial_number_word3 =
  9161. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9162. eep_config.serial_number_word2 =
  9163. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9164. eep_config.serial_number_word1 =
  9165. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9166. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  9167. }
  9168. /*
  9169. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  9170. * EEPROM configuration that was read.
  9171. *
  9172. * This is the mapping of EEPROM fields to Adv Library fields.
  9173. */
  9174. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9175. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9176. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9177. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9178. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9179. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9180. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9181. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9182. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9183. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9184. asc_dvc->start_motor = eep_config.start_motor;
  9185. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9186. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9187. asc_dvc->no_scam = eep_config.scam_tolerant;
  9188. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9189. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9190. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9191. /*
  9192. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9193. * are set, then set an 'sdtr_able' bit for it.
  9194. */
  9195. asc_dvc->sdtr_able = 0;
  9196. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  9197. if (tid == 0) {
  9198. sdtr_speed = asc_dvc->sdtr_speed1;
  9199. } else if (tid == 4) {
  9200. sdtr_speed = asc_dvc->sdtr_speed2;
  9201. } else if (tid == 8) {
  9202. sdtr_speed = asc_dvc->sdtr_speed3;
  9203. } else if (tid == 12) {
  9204. sdtr_speed = asc_dvc->sdtr_speed4;
  9205. }
  9206. if (sdtr_speed & ADV_MAX_TID) {
  9207. asc_dvc->sdtr_able |= (1 << tid);
  9208. }
  9209. sdtr_speed >>= 4;
  9210. }
  9211. /*
  9212. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9213. * maximum queuing (max. 63, min. 4).
  9214. */
  9215. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9216. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9217. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9218. /* If the value is zero, assume it is uninitialized. */
  9219. if (eep_config.max_host_qng == 0) {
  9220. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9221. } else {
  9222. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9223. }
  9224. }
  9225. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9226. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9227. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9228. /* If the value is zero, assume it is uninitialized. */
  9229. if (eep_config.max_dvc_qng == 0) {
  9230. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9231. } else {
  9232. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9233. }
  9234. }
  9235. /*
  9236. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9237. * set 'max_dvc_qng' to 'max_host_qng'.
  9238. */
  9239. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9240. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9241. }
  9242. /*
  9243. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9244. * values based on possibly adjusted EEPROM values.
  9245. */
  9246. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9247. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9248. /*
  9249. * If the EEPROM 'termination' field is set to automatic (0), then set
  9250. * the ADV_DVC_CFG 'termination' field to automatic also.
  9251. *
  9252. * If the termination is specified with a non-zero 'termination'
  9253. * value check that a legal value is set and set the ADV_DVC_CFG
  9254. * 'termination' field appropriately.
  9255. */
  9256. if (eep_config.termination_se == 0) {
  9257. termination = 0; /* auto termination for SE */
  9258. } else {
  9259. /* Enable manual control with low off / high off. */
  9260. if (eep_config.termination_se == 1) {
  9261. termination = 0;
  9262. /* Enable manual control with low off / high on. */
  9263. } else if (eep_config.termination_se == 2) {
  9264. termination = TERM_SE_HI;
  9265. /* Enable manual control with low on / high on. */
  9266. } else if (eep_config.termination_se == 3) {
  9267. termination = TERM_SE;
  9268. } else {
  9269. /*
  9270. * The EEPROM 'termination_se' field contains a bad value.
  9271. * Use automatic termination instead.
  9272. */
  9273. termination = 0;
  9274. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9275. }
  9276. }
  9277. if (eep_config.termination_lvd == 0) {
  9278. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9279. } else {
  9280. /* Enable manual control with low off / high off. */
  9281. if (eep_config.termination_lvd == 1) {
  9282. asc_dvc->cfg->termination = termination;
  9283. /* Enable manual control with low off / high on. */
  9284. } else if (eep_config.termination_lvd == 2) {
  9285. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9286. /* Enable manual control with low on / high on. */
  9287. } else if (eep_config.termination_lvd == 3) {
  9288. asc_dvc->cfg->termination = termination | TERM_LVD;
  9289. } else {
  9290. /*
  9291. * The EEPROM 'termination_lvd' field contains a bad value.
  9292. * Use automatic termination instead.
  9293. */
  9294. asc_dvc->cfg->termination = termination;
  9295. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9296. }
  9297. }
  9298. return warn_code;
  9299. }
  9300. /*
  9301. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  9302. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9303. * all of this is done.
  9304. *
  9305. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  9306. *
  9307. * For a non-fatal error return a warning code. If there are no warnings
  9308. * then 0 is returned.
  9309. *
  9310. * Note: Chip is stopped on entry.
  9311. */
  9312. static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  9313. {
  9314. AdvPortAddr iop_base;
  9315. ushort warn_code;
  9316. ADVEEP_38C1600_CONFIG eep_config;
  9317. uchar tid, termination;
  9318. ushort sdtr_speed = 0;
  9319. iop_base = asc_dvc->iop_base;
  9320. warn_code = 0;
  9321. /*
  9322. * Read the board's EEPROM configuration.
  9323. *
  9324. * Set default values if a bad checksum is found.
  9325. */
  9326. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  9327. eep_config.check_sum) {
  9328. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  9329. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9330. /*
  9331. * Set EEPROM default values.
  9332. */
  9333. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  9334. sizeof(ADVEEP_38C1600_CONFIG));
  9335. if (PCI_FUNC(pdev->devfn) != 0) {
  9336. u8 ints;
  9337. /*
  9338. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  9339. * and old Mac system booting problem. The Expansion
  9340. * ROM must be disabled in Function 1 for these systems
  9341. */
  9342. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  9343. /*
  9344. * Clear the INTAB (bit 11) if the GPIO 0 input
  9345. * indicates the Function 1 interrupt line is wired
  9346. * to INTB.
  9347. *
  9348. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  9349. * 1 - Function 1 interrupt line wired to INT A.
  9350. * 0 - Function 1 interrupt line wired to INT B.
  9351. *
  9352. * Note: Function 0 is always wired to INTA.
  9353. * Put all 5 GPIO bits in input mode and then read
  9354. * their input values.
  9355. */
  9356. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  9357. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  9358. if ((ints & 0x01) == 0)
  9359. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  9360. }
  9361. /*
  9362. * Assume the 6 byte board serial number that was read from
  9363. * EEPROM is correct even if the EEPROM checksum failed.
  9364. */
  9365. eep_config.serial_number_word3 =
  9366. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9367. eep_config.serial_number_word2 =
  9368. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9369. eep_config.serial_number_word1 =
  9370. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9371. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  9372. }
  9373. /*
  9374. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9375. * EEPROM configuration that was read.
  9376. *
  9377. * This is the mapping of EEPROM fields to Adv Library fields.
  9378. */
  9379. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9380. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9381. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9382. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9383. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9384. asc_dvc->ppr_able = 0;
  9385. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9386. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9387. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9388. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9389. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  9390. asc_dvc->start_motor = eep_config.start_motor;
  9391. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9392. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9393. asc_dvc->no_scam = eep_config.scam_tolerant;
  9394. /*
  9395. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9396. * are set, then set an 'sdtr_able' bit for it.
  9397. */
  9398. asc_dvc->sdtr_able = 0;
  9399. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  9400. if (tid == 0) {
  9401. sdtr_speed = asc_dvc->sdtr_speed1;
  9402. } else if (tid == 4) {
  9403. sdtr_speed = asc_dvc->sdtr_speed2;
  9404. } else if (tid == 8) {
  9405. sdtr_speed = asc_dvc->sdtr_speed3;
  9406. } else if (tid == 12) {
  9407. sdtr_speed = asc_dvc->sdtr_speed4;
  9408. }
  9409. if (sdtr_speed & ASC_MAX_TID) {
  9410. asc_dvc->sdtr_able |= (1 << tid);
  9411. }
  9412. sdtr_speed >>= 4;
  9413. }
  9414. /*
  9415. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9416. * maximum queuing (max. 63, min. 4).
  9417. */
  9418. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9419. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9420. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9421. /* If the value is zero, assume it is uninitialized. */
  9422. if (eep_config.max_host_qng == 0) {
  9423. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9424. } else {
  9425. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9426. }
  9427. }
  9428. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9429. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9430. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9431. /* If the value is zero, assume it is uninitialized. */
  9432. if (eep_config.max_dvc_qng == 0) {
  9433. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9434. } else {
  9435. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9436. }
  9437. }
  9438. /*
  9439. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9440. * set 'max_dvc_qng' to 'max_host_qng'.
  9441. */
  9442. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9443. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9444. }
  9445. /*
  9446. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  9447. * values based on possibly adjusted EEPROM values.
  9448. */
  9449. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9450. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9451. /*
  9452. * If the EEPROM 'termination' field is set to automatic (0), then set
  9453. * the ASC_DVC_CFG 'termination' field to automatic also.
  9454. *
  9455. * If the termination is specified with a non-zero 'termination'
  9456. * value check that a legal value is set and set the ASC_DVC_CFG
  9457. * 'termination' field appropriately.
  9458. */
  9459. if (eep_config.termination_se == 0) {
  9460. termination = 0; /* auto termination for SE */
  9461. } else {
  9462. /* Enable manual control with low off / high off. */
  9463. if (eep_config.termination_se == 1) {
  9464. termination = 0;
  9465. /* Enable manual control with low off / high on. */
  9466. } else if (eep_config.termination_se == 2) {
  9467. termination = TERM_SE_HI;
  9468. /* Enable manual control with low on / high on. */
  9469. } else if (eep_config.termination_se == 3) {
  9470. termination = TERM_SE;
  9471. } else {
  9472. /*
  9473. * The EEPROM 'termination_se' field contains a bad value.
  9474. * Use automatic termination instead.
  9475. */
  9476. termination = 0;
  9477. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9478. }
  9479. }
  9480. if (eep_config.termination_lvd == 0) {
  9481. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9482. } else {
  9483. /* Enable manual control with low off / high off. */
  9484. if (eep_config.termination_lvd == 1) {
  9485. asc_dvc->cfg->termination = termination;
  9486. /* Enable manual control with low off / high on. */
  9487. } else if (eep_config.termination_lvd == 2) {
  9488. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9489. /* Enable manual control with low on / high on. */
  9490. } else if (eep_config.termination_lvd == 3) {
  9491. asc_dvc->cfg->termination = termination | TERM_LVD;
  9492. } else {
  9493. /*
  9494. * The EEPROM 'termination_lvd' field contains a bad value.
  9495. * Use automatic termination instead.
  9496. */
  9497. asc_dvc->cfg->termination = termination;
  9498. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9499. }
  9500. }
  9501. return warn_code;
  9502. }
  9503. /*
  9504. * Initialize the ADV_DVC_VAR structure.
  9505. *
  9506. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9507. *
  9508. * For a non-fatal error return a warning code. If there are no warnings
  9509. * then 0 is returned.
  9510. */
  9511. static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  9512. {
  9513. struct asc_board *board = shost_priv(shost);
  9514. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  9515. unsigned short warn_code = 0;
  9516. AdvPortAddr iop_base = asc_dvc->iop_base;
  9517. u16 cmd;
  9518. int status;
  9519. asc_dvc->err_code = 0;
  9520. /*
  9521. * Save the state of the PCI Configuration Command Register
  9522. * "Parity Error Response Control" Bit. If the bit is clear (0),
  9523. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  9524. * DMA parity errors.
  9525. */
  9526. asc_dvc->cfg->control_flag = 0;
  9527. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  9528. if ((cmd & PCI_COMMAND_PARITY) == 0)
  9529. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  9530. asc_dvc->cfg->chip_version =
  9531. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  9532. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  9533. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  9534. (ushort)ADV_CHIP_ID_BYTE);
  9535. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  9536. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  9537. (ushort)ADV_CHIP_ID_WORD);
  9538. /*
  9539. * Reset the chip to start and allow register writes.
  9540. */
  9541. if (AdvFindSignature(iop_base) == 0) {
  9542. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9543. return ADV_ERROR;
  9544. } else {
  9545. /*
  9546. * The caller must set 'chip_type' to a valid setting.
  9547. */
  9548. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  9549. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  9550. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  9551. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  9552. return ADV_ERROR;
  9553. }
  9554. /*
  9555. * Reset Chip.
  9556. */
  9557. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  9558. ADV_CTRL_REG_CMD_RESET);
  9559. mdelay(100);
  9560. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  9561. ADV_CTRL_REG_CMD_WR_IO_REG);
  9562. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  9563. status = AdvInitFrom38C1600EEP(asc_dvc);
  9564. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  9565. status = AdvInitFrom38C0800EEP(asc_dvc);
  9566. } else {
  9567. status = AdvInitFrom3550EEP(asc_dvc);
  9568. }
  9569. warn_code |= status;
  9570. }
  9571. if (warn_code != 0)
  9572. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  9573. if (asc_dvc->err_code)
  9574. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  9575. asc_dvc->err_code);
  9576. return asc_dvc->err_code;
  9577. }
  9578. #endif
  9579. static struct scsi_host_template advansys_template = {
  9580. .proc_name = DRV_NAME,
  9581. #ifdef CONFIG_PROC_FS
  9582. .show_info = advansys_show_info,
  9583. #endif
  9584. .name = DRV_NAME,
  9585. .info = advansys_info,
  9586. .queuecommand = advansys_queuecommand,
  9587. .eh_host_reset_handler = advansys_reset,
  9588. .bios_param = advansys_biosparam,
  9589. .slave_configure = advansys_slave_configure,
  9590. .cmd_size = sizeof(struct advansys_cmd),
  9591. };
  9592. static int advansys_wide_init_chip(struct Scsi_Host *shost)
  9593. {
  9594. struct asc_board *board = shost_priv(shost);
  9595. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  9596. size_t sgblk_pool_size;
  9597. int warn_code, err_code;
  9598. /*
  9599. * Allocate buffer carrier structures. The total size
  9600. * is about 8 KB, so allocate all at once.
  9601. */
  9602. adv_dvc->carrier = dma_alloc_coherent(board->dev,
  9603. ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL);
  9604. ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier);
  9605. if (!adv_dvc->carrier)
  9606. goto kmalloc_failed;
  9607. /*
  9608. * Allocate up to 'max_host_qng' request structures for the Wide
  9609. * board. The total size is about 16 KB, so allocate all at once.
  9610. * If the allocation fails decrement and try again.
  9611. */
  9612. board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t);
  9613. if (board->adv_reqp_size & 0x1f) {
  9614. ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t));
  9615. board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size);
  9616. }
  9617. board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size,
  9618. &board->adv_reqp_addr, GFP_KERNEL);
  9619. if (!board->adv_reqp)
  9620. goto kmalloc_failed;
  9621. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp,
  9622. adv_dvc->max_host_qng, board->adv_reqp_size);
  9623. /*
  9624. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  9625. * the Wide board. Each structure is about 136 bytes.
  9626. */
  9627. sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK;
  9628. board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev,
  9629. sgblk_pool_size, 32, 0);
  9630. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK,
  9631. sizeof(adv_sgblk_t), sgblk_pool_size);
  9632. if (!board->adv_sgblk_pool)
  9633. goto kmalloc_failed;
  9634. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  9635. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  9636. warn_code = AdvInitAsc3550Driver(adv_dvc);
  9637. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  9638. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  9639. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  9640. } else {
  9641. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  9642. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  9643. }
  9644. err_code = adv_dvc->err_code;
  9645. if (warn_code || err_code) {
  9646. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  9647. "0x%x\n", warn_code, err_code);
  9648. }
  9649. goto exit;
  9650. kmalloc_failed:
  9651. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  9652. err_code = ADV_ERROR;
  9653. exit:
  9654. return err_code;
  9655. }
  9656. static void advansys_wide_free_mem(struct asc_board *board)
  9657. {
  9658. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  9659. if (adv_dvc->carrier) {
  9660. dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE,
  9661. adv_dvc->carrier, adv_dvc->carrier_addr);
  9662. adv_dvc->carrier = NULL;
  9663. }
  9664. if (board->adv_reqp) {
  9665. dma_free_coherent(board->dev, board->adv_reqp_size,
  9666. board->adv_reqp, board->adv_reqp_addr);
  9667. board->adv_reqp = NULL;
  9668. }
  9669. if (board->adv_sgblk_pool) {
  9670. dma_pool_destroy(board->adv_sgblk_pool);
  9671. board->adv_sgblk_pool = NULL;
  9672. }
  9673. }
  9674. static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
  9675. int bus_type)
  9676. {
  9677. struct pci_dev *pdev;
  9678. struct asc_board *boardp = shost_priv(shost);
  9679. ASC_DVC_VAR *asc_dvc_varp = NULL;
  9680. ADV_DVC_VAR *adv_dvc_varp = NULL;
  9681. int share_irq, warn_code, ret;
  9682. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  9683. if (ASC_NARROW_BOARD(boardp)) {
  9684. ASC_DBG(1, "narrow board\n");
  9685. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  9686. asc_dvc_varp->bus_type = bus_type;
  9687. asc_dvc_varp->drv_ptr = boardp;
  9688. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  9689. asc_dvc_varp->iop_base = iop;
  9690. } else {
  9691. #ifdef CONFIG_PCI
  9692. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  9693. adv_dvc_varp->drv_ptr = boardp;
  9694. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  9695. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  9696. ASC_DBG(1, "wide board ASC-3550\n");
  9697. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  9698. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  9699. ASC_DBG(1, "wide board ASC-38C0800\n");
  9700. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  9701. } else {
  9702. ASC_DBG(1, "wide board ASC-38C1600\n");
  9703. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  9704. }
  9705. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  9706. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  9707. if (!boardp->ioremap_addr) {
  9708. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  9709. "returned NULL\n",
  9710. (long)pci_resource_start(pdev, 1),
  9711. boardp->asc_n_io_port);
  9712. ret = -ENODEV;
  9713. goto err_shost;
  9714. }
  9715. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  9716. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  9717. /*
  9718. * Even though it isn't used to access wide boards, other
  9719. * than for the debug line below, save I/O Port address so
  9720. * that it can be reported.
  9721. */
  9722. boardp->ioport = iop;
  9723. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  9724. (ushort)inp(iop + 1), (ushort)inpw(iop));
  9725. #endif /* CONFIG_PCI */
  9726. }
  9727. if (ASC_NARROW_BOARD(boardp)) {
  9728. /*
  9729. * Set the board bus type and PCI IRQ before
  9730. * calling AscInitGetConfig().
  9731. */
  9732. switch (asc_dvc_varp->bus_type) {
  9733. #ifdef CONFIG_ISA
  9734. case ASC_IS_VL:
  9735. share_irq = 0;
  9736. break;
  9737. case ASC_IS_EISA:
  9738. share_irq = IRQF_SHARED;
  9739. break;
  9740. #endif /* CONFIG_ISA */
  9741. #ifdef CONFIG_PCI
  9742. case ASC_IS_PCI:
  9743. share_irq = IRQF_SHARED;
  9744. break;
  9745. #endif /* CONFIG_PCI */
  9746. default:
  9747. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  9748. "%d\n", asc_dvc_varp->bus_type);
  9749. share_irq = 0;
  9750. break;
  9751. }
  9752. /*
  9753. * NOTE: AscInitGetConfig() may change the board's
  9754. * bus_type value. The bus_type value should no
  9755. * longer be used. If the bus_type field must be
  9756. * referenced only use the bit-wise AND operator "&".
  9757. */
  9758. ASC_DBG(2, "AscInitGetConfig()\n");
  9759. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  9760. } else {
  9761. #ifdef CONFIG_PCI
  9762. /*
  9763. * For Wide boards set PCI information before calling
  9764. * AdvInitGetConfig().
  9765. */
  9766. share_irq = IRQF_SHARED;
  9767. ASC_DBG(2, "AdvInitGetConfig()\n");
  9768. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  9769. #else
  9770. share_irq = 0;
  9771. ret = -ENODEV;
  9772. #endif /* CONFIG_PCI */
  9773. }
  9774. if (ret)
  9775. goto err_unmap;
  9776. /*
  9777. * Save the EEPROM configuration so that it can be displayed
  9778. * from /proc/scsi/advansys/[0...].
  9779. */
  9780. if (ASC_NARROW_BOARD(boardp)) {
  9781. ASCEEP_CONFIG *ep;
  9782. /*
  9783. * Set the adapter's target id bit in the 'init_tidmask' field.
  9784. */
  9785. boardp->init_tidmask |=
  9786. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  9787. /*
  9788. * Save EEPROM settings for the board.
  9789. */
  9790. ep = &boardp->eep_config.asc_eep;
  9791. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  9792. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  9793. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  9794. ASC_EEP_SET_DMA_SPD(ep, ASC_DEF_ISA_DMA_SPEED);
  9795. ep->start_motor = asc_dvc_varp->start_motor;
  9796. ep->cntl = asc_dvc_varp->dvc_cntl;
  9797. ep->no_scam = asc_dvc_varp->no_scam;
  9798. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  9799. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  9800. /* 'max_tag_qng' is set to the same value for every device. */
  9801. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  9802. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  9803. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  9804. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  9805. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  9806. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  9807. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  9808. /*
  9809. * Modify board configuration.
  9810. */
  9811. ASC_DBG(2, "AscInitSetConfig()\n");
  9812. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  9813. if (ret)
  9814. goto err_unmap;
  9815. } else {
  9816. ADVEEP_3550_CONFIG *ep_3550;
  9817. ADVEEP_38C0800_CONFIG *ep_38C0800;
  9818. ADVEEP_38C1600_CONFIG *ep_38C1600;
  9819. /*
  9820. * Save Wide EEP Configuration Information.
  9821. */
  9822. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  9823. ep_3550 = &boardp->eep_config.adv_3550_eep;
  9824. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  9825. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  9826. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  9827. ep_3550->termination = adv_dvc_varp->cfg->termination;
  9828. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  9829. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  9830. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  9831. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  9832. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  9833. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  9834. ep_3550->start_motor = adv_dvc_varp->start_motor;
  9835. ep_3550->scsi_reset_delay =
  9836. adv_dvc_varp->scsi_reset_wait;
  9837. ep_3550->serial_number_word1 =
  9838. adv_dvc_varp->cfg->serial1;
  9839. ep_3550->serial_number_word2 =
  9840. adv_dvc_varp->cfg->serial2;
  9841. ep_3550->serial_number_word3 =
  9842. adv_dvc_varp->cfg->serial3;
  9843. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  9844. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  9845. ep_38C0800->adapter_scsi_id =
  9846. adv_dvc_varp->chip_scsi_id;
  9847. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  9848. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  9849. ep_38C0800->termination_lvd =
  9850. adv_dvc_varp->cfg->termination;
  9851. ep_38C0800->disc_enable =
  9852. adv_dvc_varp->cfg->disc_enable;
  9853. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  9854. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  9855. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  9856. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  9857. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  9858. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  9859. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  9860. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  9861. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  9862. ep_38C0800->scsi_reset_delay =
  9863. adv_dvc_varp->scsi_reset_wait;
  9864. ep_38C0800->serial_number_word1 =
  9865. adv_dvc_varp->cfg->serial1;
  9866. ep_38C0800->serial_number_word2 =
  9867. adv_dvc_varp->cfg->serial2;
  9868. ep_38C0800->serial_number_word3 =
  9869. adv_dvc_varp->cfg->serial3;
  9870. } else {
  9871. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  9872. ep_38C1600->adapter_scsi_id =
  9873. adv_dvc_varp->chip_scsi_id;
  9874. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  9875. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  9876. ep_38C1600->termination_lvd =
  9877. adv_dvc_varp->cfg->termination;
  9878. ep_38C1600->disc_enable =
  9879. adv_dvc_varp->cfg->disc_enable;
  9880. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  9881. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  9882. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  9883. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  9884. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  9885. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  9886. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  9887. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  9888. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  9889. ep_38C1600->scsi_reset_delay =
  9890. adv_dvc_varp->scsi_reset_wait;
  9891. ep_38C1600->serial_number_word1 =
  9892. adv_dvc_varp->cfg->serial1;
  9893. ep_38C1600->serial_number_word2 =
  9894. adv_dvc_varp->cfg->serial2;
  9895. ep_38C1600->serial_number_word3 =
  9896. adv_dvc_varp->cfg->serial3;
  9897. }
  9898. /*
  9899. * Set the adapter's target id bit in the 'init_tidmask' field.
  9900. */
  9901. boardp->init_tidmask |=
  9902. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  9903. }
  9904. /*
  9905. * Channels are numbered beginning with 0. For AdvanSys one host
  9906. * structure supports one channel. Multi-channel boards have a
  9907. * separate host structure for each channel.
  9908. */
  9909. shost->max_channel = 0;
  9910. if (ASC_NARROW_BOARD(boardp)) {
  9911. shost->max_id = ASC_MAX_TID + 1;
  9912. shost->max_lun = ASC_MAX_LUN + 1;
  9913. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  9914. shost->io_port = asc_dvc_varp->iop_base;
  9915. boardp->asc_n_io_port = ASC_IOADR_GAP;
  9916. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  9917. /* Set maximum number of queues the adapter can handle. */
  9918. shost->can_queue = asc_dvc_varp->max_total_qng;
  9919. } else {
  9920. shost->max_id = ADV_MAX_TID + 1;
  9921. shost->max_lun = ADV_MAX_LUN + 1;
  9922. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  9923. /*
  9924. * Save the I/O Port address and length even though
  9925. * I/O ports are not used to access Wide boards.
  9926. * Instead the Wide boards are accessed with
  9927. * PCI Memory Mapped I/O.
  9928. */
  9929. shost->io_port = iop;
  9930. shost->this_id = adv_dvc_varp->chip_scsi_id;
  9931. /* Set maximum number of queues the adapter can handle. */
  9932. shost->can_queue = adv_dvc_varp->max_host_qng;
  9933. }
  9934. /*
  9935. * Set the maximum number of scatter-gather elements the
  9936. * adapter can handle.
  9937. */
  9938. if (ASC_NARROW_BOARD(boardp)) {
  9939. /*
  9940. * Allow two commands with 'sg_tablesize' scatter-gather
  9941. * elements to be executed simultaneously. This value is
  9942. * the theoretical hardware limit. It may be decreased
  9943. * below.
  9944. */
  9945. shost->sg_tablesize =
  9946. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  9947. ASC_SG_LIST_PER_Q) + 1;
  9948. } else {
  9949. shost->sg_tablesize = ADV_MAX_SG_LIST;
  9950. }
  9951. /*
  9952. * The value of 'sg_tablesize' can not exceed the SCSI
  9953. * mid-level driver definition of SG_ALL. SG_ALL also
  9954. * must not be exceeded, because it is used to define the
  9955. * size of the scatter-gather table in 'struct asc_sg_head'.
  9956. */
  9957. if (shost->sg_tablesize > SG_ALL) {
  9958. shost->sg_tablesize = SG_ALL;
  9959. }
  9960. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  9961. /* BIOS start address. */
  9962. if (ASC_NARROW_BOARD(boardp)) {
  9963. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  9964. asc_dvc_varp->bus_type);
  9965. } else {
  9966. /*
  9967. * Fill-in BIOS board variables. The Wide BIOS saves
  9968. * information in LRAM that is used by the driver.
  9969. */
  9970. AdvReadWordLram(adv_dvc_varp->iop_base,
  9971. BIOS_SIGNATURE, boardp->bios_signature);
  9972. AdvReadWordLram(adv_dvc_varp->iop_base,
  9973. BIOS_VERSION, boardp->bios_version);
  9974. AdvReadWordLram(adv_dvc_varp->iop_base,
  9975. BIOS_CODESEG, boardp->bios_codeseg);
  9976. AdvReadWordLram(adv_dvc_varp->iop_base,
  9977. BIOS_CODELEN, boardp->bios_codelen);
  9978. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  9979. boardp->bios_signature, boardp->bios_version);
  9980. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  9981. boardp->bios_codeseg, boardp->bios_codelen);
  9982. /*
  9983. * If the BIOS saved a valid signature, then fill in
  9984. * the BIOS code segment base address.
  9985. */
  9986. if (boardp->bios_signature == 0x55AA) {
  9987. /*
  9988. * Convert x86 realmode code segment to a linear
  9989. * address by shifting left 4.
  9990. */
  9991. shost->base = ((ulong)boardp->bios_codeseg << 4);
  9992. } else {
  9993. shost->base = 0;
  9994. }
  9995. }
  9996. /*
  9997. * Register Board Resources - I/O Port, DMA, IRQ
  9998. */
  9999. /* Register DMA Channel for Narrow boards. */
  10000. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  10001. /* Register IRQ Number. */
  10002. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  10003. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  10004. DRV_NAME, shost);
  10005. if (ret) {
  10006. if (ret == -EBUSY) {
  10007. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10008. "already in use\n", boardp->irq);
  10009. } else if (ret == -EINVAL) {
  10010. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10011. "not valid\n", boardp->irq);
  10012. } else {
  10013. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10014. "failed with %d\n", boardp->irq, ret);
  10015. }
  10016. goto err_unmap;
  10017. }
  10018. /*
  10019. * Initialize board RISC chip and enable interrupts.
  10020. */
  10021. if (ASC_NARROW_BOARD(boardp)) {
  10022. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  10023. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  10024. if (!asc_dvc_varp->overrun_buf) {
  10025. ret = -ENOMEM;
  10026. goto err_free_irq;
  10027. }
  10028. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  10029. if (warn_code || asc_dvc_varp->err_code) {
  10030. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  10031. "warn 0x%x, error 0x%x\n",
  10032. asc_dvc_varp->init_state, warn_code,
  10033. asc_dvc_varp->err_code);
  10034. if (!asc_dvc_varp->overrun_dma) {
  10035. ret = -ENODEV;
  10036. goto err_free_mem;
  10037. }
  10038. }
  10039. } else {
  10040. if (advansys_wide_init_chip(shost)) {
  10041. ret = -ENODEV;
  10042. goto err_free_mem;
  10043. }
  10044. }
  10045. ASC_DBG_PRT_SCSI_HOST(2, shost);
  10046. ret = scsi_add_host(shost, boardp->dev);
  10047. if (ret)
  10048. goto err_free_mem;
  10049. scsi_scan_host(shost);
  10050. return 0;
  10051. err_free_mem:
  10052. if (ASC_NARROW_BOARD(boardp)) {
  10053. if (asc_dvc_varp->overrun_dma)
  10054. dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
  10055. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10056. kfree(asc_dvc_varp->overrun_buf);
  10057. } else
  10058. advansys_wide_free_mem(boardp);
  10059. err_free_irq:
  10060. free_irq(boardp->irq, shost);
  10061. err_unmap:
  10062. if (boardp->ioremap_addr)
  10063. iounmap(boardp->ioremap_addr);
  10064. #ifdef CONFIG_PCI
  10065. err_shost:
  10066. #endif
  10067. return ret;
  10068. }
  10069. /*
  10070. * advansys_release()
  10071. *
  10072. * Release resources allocated for a single AdvanSys adapter.
  10073. */
  10074. static int advansys_release(struct Scsi_Host *shost)
  10075. {
  10076. struct asc_board *board = shost_priv(shost);
  10077. ASC_DBG(1, "begin\n");
  10078. scsi_remove_host(shost);
  10079. free_irq(board->irq, shost);
  10080. if (ASC_NARROW_BOARD(board)) {
  10081. dma_unmap_single(board->dev,
  10082. board->dvc_var.asc_dvc_var.overrun_dma,
  10083. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10084. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  10085. } else {
  10086. iounmap(board->ioremap_addr);
  10087. advansys_wide_free_mem(board);
  10088. }
  10089. scsi_host_put(shost);
  10090. ASC_DBG(1, "end\n");
  10091. return 0;
  10092. }
  10093. #define ASC_IOADR_TABLE_MAX_IX 11
  10094. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  10095. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  10096. 0x0210, 0x0230, 0x0250, 0x0330
  10097. };
  10098. static void advansys_vlb_remove(struct device *dev, unsigned int id)
  10099. {
  10100. int ioport = _asc_def_iop_base[id];
  10101. advansys_release(dev_get_drvdata(dev));
  10102. release_region(ioport, ASC_IOADR_GAP);
  10103. }
  10104. /*
  10105. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  10106. * 000: invalid
  10107. * 001: 10
  10108. * 010: 11
  10109. * 011: 12
  10110. * 100: invalid
  10111. * 101: 14
  10112. * 110: 15
  10113. * 111: invalid
  10114. */
  10115. static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
  10116. {
  10117. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10118. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  10119. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  10120. return 0;
  10121. return chip_irq;
  10122. }
  10123. static int advansys_vlb_probe(struct device *dev, unsigned int id)
  10124. {
  10125. int err = -ENODEV;
  10126. PortAddr iop_base = _asc_def_iop_base[id];
  10127. struct Scsi_Host *shost;
  10128. struct asc_board *board;
  10129. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10130. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10131. return -ENODEV;
  10132. }
  10133. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10134. if (!AscFindSignature(iop_base))
  10135. goto release_region;
  10136. /*
  10137. * I don't think this condition can actually happen, but the old
  10138. * driver did it, and the chances of finding a VLB setup in 2007
  10139. * to do testing with is slight to none.
  10140. */
  10141. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  10142. goto release_region;
  10143. err = -ENOMEM;
  10144. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10145. if (!shost)
  10146. goto release_region;
  10147. board = shost_priv(shost);
  10148. board->irq = advansys_vlb_irq_no(iop_base);
  10149. board->dev = dev;
  10150. board->shost = shost;
  10151. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  10152. if (err)
  10153. goto free_host;
  10154. dev_set_drvdata(dev, shost);
  10155. return 0;
  10156. free_host:
  10157. scsi_host_put(shost);
  10158. release_region:
  10159. release_region(iop_base, ASC_IOADR_GAP);
  10160. return -ENODEV;
  10161. }
  10162. static struct isa_driver advansys_vlb_driver = {
  10163. .probe = advansys_vlb_probe,
  10164. .remove = advansys_vlb_remove,
  10165. .driver = {
  10166. .owner = THIS_MODULE,
  10167. .name = "advansys_vlb",
  10168. },
  10169. };
  10170. static struct eisa_device_id advansys_eisa_table[] = {
  10171. { "ABP7401" },
  10172. { "ABP7501" },
  10173. { "" }
  10174. };
  10175. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  10176. /*
  10177. * EISA is a little more tricky than PCI; each EISA device may have two
  10178. * channels, and this driver is written to make each channel its own Scsi_Host
  10179. */
  10180. struct eisa_scsi_data {
  10181. struct Scsi_Host *host[2];
  10182. };
  10183. /*
  10184. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  10185. * 000: 10
  10186. * 001: 11
  10187. * 010: 12
  10188. * 011: invalid
  10189. * 100: 14
  10190. * 101: 15
  10191. * 110: invalid
  10192. * 111: invalid
  10193. */
  10194. static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
  10195. {
  10196. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  10197. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  10198. if ((chip_irq == 13) || (chip_irq > 15))
  10199. return 0;
  10200. return chip_irq;
  10201. }
  10202. static int advansys_eisa_probe(struct device *dev)
  10203. {
  10204. int i, ioport, irq = 0;
  10205. int err;
  10206. struct eisa_device *edev = to_eisa_device(dev);
  10207. struct eisa_scsi_data *data;
  10208. err = -ENOMEM;
  10209. data = kzalloc(sizeof(*data), GFP_KERNEL);
  10210. if (!data)
  10211. goto fail;
  10212. ioport = edev->base_addr + 0xc30;
  10213. err = -ENODEV;
  10214. for (i = 0; i < 2; i++, ioport += 0x20) {
  10215. struct asc_board *board;
  10216. struct Scsi_Host *shost;
  10217. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  10218. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  10219. ioport + ASC_IOADR_GAP - 1);
  10220. continue;
  10221. }
  10222. if (!AscFindSignature(ioport)) {
  10223. release_region(ioport, ASC_IOADR_GAP);
  10224. continue;
  10225. }
  10226. /*
  10227. * I don't know why we need to do this for EISA chips, but
  10228. * not for any others. It looks to be equivalent to
  10229. * AscGetChipCfgMsw, but I may have overlooked something,
  10230. * so I'm not converting it until I get an EISA board to
  10231. * test with.
  10232. */
  10233. inw(ioport + 4);
  10234. if (!irq)
  10235. irq = advansys_eisa_irq_no(edev);
  10236. err = -ENOMEM;
  10237. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10238. if (!shost)
  10239. goto release_region;
  10240. board = shost_priv(shost);
  10241. board->irq = irq;
  10242. board->dev = dev;
  10243. board->shost = shost;
  10244. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  10245. if (!err) {
  10246. data->host[i] = shost;
  10247. continue;
  10248. }
  10249. scsi_host_put(shost);
  10250. release_region:
  10251. release_region(ioport, ASC_IOADR_GAP);
  10252. break;
  10253. }
  10254. if (err)
  10255. goto free_data;
  10256. dev_set_drvdata(dev, data);
  10257. return 0;
  10258. free_data:
  10259. kfree(data->host[0]);
  10260. kfree(data->host[1]);
  10261. kfree(data);
  10262. fail:
  10263. return err;
  10264. }
  10265. static int advansys_eisa_remove(struct device *dev)
  10266. {
  10267. int i;
  10268. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  10269. for (i = 0; i < 2; i++) {
  10270. int ioport;
  10271. struct Scsi_Host *shost = data->host[i];
  10272. if (!shost)
  10273. continue;
  10274. ioport = shost->io_port;
  10275. advansys_release(shost);
  10276. release_region(ioport, ASC_IOADR_GAP);
  10277. }
  10278. kfree(data);
  10279. return 0;
  10280. }
  10281. static struct eisa_driver advansys_eisa_driver = {
  10282. .id_table = advansys_eisa_table,
  10283. .driver = {
  10284. .name = DRV_NAME,
  10285. .probe = advansys_eisa_probe,
  10286. .remove = advansys_eisa_remove,
  10287. }
  10288. };
  10289. /* PCI Devices supported by this driver */
  10290. static struct pci_device_id advansys_pci_tbl[] = {
  10291. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  10292. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10293. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  10294. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10295. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  10296. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10297. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  10298. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10299. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  10300. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10301. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  10302. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10303. {}
  10304. };
  10305. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  10306. static void advansys_set_latency(struct pci_dev *pdev)
  10307. {
  10308. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  10309. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  10310. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  10311. } else {
  10312. u8 latency;
  10313. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  10314. if (latency < 0x20)
  10315. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  10316. }
  10317. }
  10318. static int advansys_pci_probe(struct pci_dev *pdev,
  10319. const struct pci_device_id *ent)
  10320. {
  10321. int err, ioport;
  10322. struct Scsi_Host *shost;
  10323. struct asc_board *board;
  10324. err = pci_enable_device(pdev);
  10325. if (err)
  10326. goto fail;
  10327. err = pci_request_regions(pdev, DRV_NAME);
  10328. if (err)
  10329. goto disable_device;
  10330. pci_set_master(pdev);
  10331. advansys_set_latency(pdev);
  10332. err = -ENODEV;
  10333. if (pci_resource_len(pdev, 0) == 0)
  10334. goto release_region;
  10335. ioport = pci_resource_start(pdev, 0);
  10336. err = -ENOMEM;
  10337. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10338. if (!shost)
  10339. goto release_region;
  10340. board = shost_priv(shost);
  10341. board->irq = pdev->irq;
  10342. board->dev = &pdev->dev;
  10343. board->shost = shost;
  10344. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  10345. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  10346. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  10347. board->flags |= ASC_IS_WIDE_BOARD;
  10348. }
  10349. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  10350. if (err)
  10351. goto free_host;
  10352. pci_set_drvdata(pdev, shost);
  10353. return 0;
  10354. free_host:
  10355. scsi_host_put(shost);
  10356. release_region:
  10357. pci_release_regions(pdev);
  10358. disable_device:
  10359. pci_disable_device(pdev);
  10360. fail:
  10361. return err;
  10362. }
  10363. static void advansys_pci_remove(struct pci_dev *pdev)
  10364. {
  10365. advansys_release(pci_get_drvdata(pdev));
  10366. pci_release_regions(pdev);
  10367. pci_disable_device(pdev);
  10368. }
  10369. static struct pci_driver advansys_pci_driver = {
  10370. .name = DRV_NAME,
  10371. .id_table = advansys_pci_tbl,
  10372. .probe = advansys_pci_probe,
  10373. .remove = advansys_pci_remove,
  10374. };
  10375. static int __init advansys_init(void)
  10376. {
  10377. int error;
  10378. error = isa_register_driver(&advansys_vlb_driver,
  10379. ASC_IOADR_TABLE_MAX_IX);
  10380. if (error)
  10381. goto fail;
  10382. error = eisa_driver_register(&advansys_eisa_driver);
  10383. if (error)
  10384. goto unregister_vlb;
  10385. error = pci_register_driver(&advansys_pci_driver);
  10386. if (error)
  10387. goto unregister_eisa;
  10388. return 0;
  10389. unregister_eisa:
  10390. eisa_driver_unregister(&advansys_eisa_driver);
  10391. unregister_vlb:
  10392. isa_unregister_driver(&advansys_vlb_driver);
  10393. fail:
  10394. return error;
  10395. }
  10396. static void __exit advansys_exit(void)
  10397. {
  10398. pci_unregister_driver(&advansys_pci_driver);
  10399. eisa_driver_unregister(&advansys_eisa_driver);
  10400. isa_unregister_driver(&advansys_vlb_driver);
  10401. }
  10402. module_init(advansys_init);
  10403. module_exit(advansys_exit);
  10404. MODULE_LICENSE("GPL");
  10405. MODULE_FIRMWARE("advansys/mcode.bin");
  10406. MODULE_FIRMWARE("advansys/3550.bin");
  10407. MODULE_FIRMWARE("advansys/38C0800.bin");
  10408. MODULE_FIRMWARE("advansys/38C1600.bin");