aic7xxx_old.c 361 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204
  1. /*+M*************************************************************************
  2. * Adaptec AIC7xxx device driver for Linux.
  3. *
  4. * Copyright (c) 1994 John Aycock
  5. * The University of Calgary Department of Computer Science.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, write to
  19. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
  22. * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
  23. * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
  24. * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
  25. * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
  26. * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
  27. * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
  28. * ANSI SCSI-2 specification (draft 10c), ...
  29. *
  30. * --------------------------------------------------------------------------
  31. *
  32. * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
  33. *
  34. * Substantially modified to include support for wide and twin bus
  35. * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
  36. * SCB paging, and other rework of the code.
  37. *
  38. * Parts of this driver were also based on the FreeBSD driver by
  39. * Justin T. Gibbs. His copyright follows:
  40. *
  41. * --------------------------------------------------------------------------
  42. * Copyright (c) 1994-1997 Justin Gibbs.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms, with or without
  46. * modification, are permitted provided that the following conditions
  47. * are met:
  48. * 1. Redistributions of source code must retain the above copyright
  49. * notice, this list of conditions, and the following disclaimer,
  50. * without modification, immediately at the beginning of the file.
  51. * 2. Redistributions in binary form must reproduce the above copyright
  52. * notice, this list of conditions and the following disclaimer in the
  53. * documentation and/or other materials provided with the distribution.
  54. * 3. The name of the author may not be used to endorse or promote products
  55. * derived from this software without specific prior written permission.
  56. *
  57. * Where this Software is combined with software released under the terms of
  58. * the GNU General Public License ("GPL") and the terms of the GPL would require the
  59. * combined work to also be released under the terms of the GPL, the terms
  60. * and conditions of this License will apply in addition to those of the
  61. * GPL with the exception of any terms or conditions of this License that
  62. * conflict with, or are expressly prohibited by, the GPL.
  63. *
  64. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  65. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  68. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  69. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  70. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  71. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  74. * SUCH DAMAGE.
  75. *
  76. * $Id: aic7xxx.c,v 1.119 1997/06/27 19:39:18 gibbs Exp $
  77. *---------------------------------------------------------------------------
  78. *
  79. * Thanks also go to (in alphabetical order) the following:
  80. *
  81. * Rory Bolt - Sequencer bug fixes
  82. * Jay Estabrook - Initial DEC Alpha support
  83. * Doug Ledford - Much needed abort/reset bug fixes
  84. * Kai Makisara - DMAing of SCBs
  85. *
  86. * A Boot time option was also added for not resetting the scsi bus.
  87. *
  88. * Form: aic7xxx=extended
  89. * aic7xxx=no_reset
  90. * aic7xxx=ultra
  91. * aic7xxx=irq_trigger:[0,1] # 0 edge, 1 level
  92. * aic7xxx=verbose
  93. *
  94. * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
  95. *
  96. * $Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp $
  97. *-M*************************************************************************/
  98. /*+M**************************************************************************
  99. *
  100. * Further driver modifications made by Doug Ledford <dledford@redhat.com>
  101. *
  102. * Copyright (c) 1997-1999 Doug Ledford
  103. *
  104. * These changes are released under the same licensing terms as the FreeBSD
  105. * driver written by Justin Gibbs. Please see his Copyright notice above
  106. * for the exact terms and conditions covering my changes as well as the
  107. * warranty statement.
  108. *
  109. * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
  110. * but are not limited to:
  111. *
  112. * 1: Import of the latest FreeBSD sequencer code for this driver
  113. * 2: Modification of kernel code to accommodate different sequencer semantics
  114. * 3: Extensive changes throughout kernel portion of driver to improve
  115. * abort/reset processing and error hanndling
  116. * 4: Other work contributed by various people on the Internet
  117. * 5: Changes to printk information and verbosity selection code
  118. * 6: General reliability related changes, especially in IRQ management
  119. * 7: Modifications to the default probe/attach order for supported cards
  120. * 8: SMP friendliness has been improved
  121. *
  122. * Overall, this driver represents a significant departure from the official
  123. * aic7xxx driver released by Dan Eischen in two ways. First, in the code
  124. * itself. A diff between the two version of the driver is now a several
  125. * thousand line diff. Second, in approach to solving the same problem. The
  126. * problem is importing the FreeBSD aic7xxx driver code to linux can be a
  127. * difficult and time consuming process, that also can be error prone. Dan
  128. * Eischen's official driver uses the approach that the linux and FreeBSD
  129. * drivers should be as identical as possible. To that end, his next version
  130. * of this driver will be using a mid-layer code library that he is developing
  131. * to moderate communications between the linux mid-level SCSI code and the
  132. * low level FreeBSD driver. He intends to be able to essentially drop the
  133. * FreeBSD driver into the linux kernel with only a few minor tweaks to some
  134. * include files and the like and get things working, making for fast easy
  135. * imports of the FreeBSD code into linux.
  136. *
  137. * I disagree with Dan's approach. Not that I don't think his way of doing
  138. * things would be nice, easy to maintain, and create a more uniform driver
  139. * between FreeBSD and Linux. I have no objection to those issues. My
  140. * disagreement is on the needed functionality. There simply are certain
  141. * things that are done differently in FreeBSD than linux that will cause
  142. * problems for this driver regardless of any middle ware Dan implements.
  143. * The biggest example of this at the moment is interrupt semantics. Linux
  144. * doesn't provide the same protection techniques as FreeBSD does, nor can
  145. * they be easily implemented in any middle ware code since they would truly
  146. * belong in the kernel proper and would effect all drivers. For the time
  147. * being, I see issues such as these as major stumbling blocks to the
  148. * reliability of code based upon such middle ware. Therefore, I choose to
  149. * use a different approach to importing the FreeBSD code that doesn't
  150. * involve any middle ware type code. My approach is to import the sequencer
  151. * code from FreeBSD wholesale. Then, to only make changes in the kernel
  152. * portion of the driver as they are needed for the new sequencer semantics.
  153. * In this way, the portion of the driver that speaks to the rest of the
  154. * linux kernel is fairly static and can be changed/modified to solve
  155. * any problems one might encounter without concern for the FreeBSD driver.
  156. *
  157. * Note: If time and experience should prove me wrong that the middle ware
  158. * code Dan writes is reliable in its operation, then I'll retract my above
  159. * statements. But, for those that don't know, I'm from Missouri (in the US)
  160. * and our state motto is "The Show-Me State". Well, before I will put
  161. * faith into it, you'll have to show me that it works :)
  162. *
  163. *_M*************************************************************************/
  164. /*
  165. * The next three defines are user configurable. These should be the only
  166. * defines a user might need to get in here and change. There are other
  167. * defines buried deeper in the code, but those really shouldn't need touched
  168. * under normal conditions.
  169. */
  170. /*
  171. * AIC7XXX_STRICT_PCI_SETUP
  172. * Should we assume the PCI config options on our controllers are set with
  173. * sane and proper values, or should we be anal about our PCI config
  174. * registers and force them to what we want? The main advantage to
  175. * defining this option is on non-Intel hardware where the BIOS may not
  176. * have been run to set things up, or if you have one of the BIOSless
  177. * Adaptec controllers, such as a 2910, that don't get set up by the
  178. * BIOS. However, keep in mind that we really do set the most important
  179. * items in the driver regardless of this setting, this only controls some
  180. * of the more esoteric PCI options on these cards. In that sense, I
  181. * would default to leaving this off. However, if people wish to try
  182. * things both ways, that would also help me to know if there are some
  183. * machines where it works one way but not another.
  184. *
  185. * -- July 7, 17:09
  186. * OK...I need this on my machine for testing, so the default is to
  187. * leave it defined.
  188. *
  189. * -- July 7, 18:49
  190. * I needed it for testing, but it didn't make any difference, so back
  191. * off she goes.
  192. *
  193. * -- July 16, 23:04
  194. * I turned it back on to try and compensate for the 2.1.x PCI code
  195. * which no longer relies solely on the BIOS and now tries to set
  196. * things itself.
  197. */
  198. #define AIC7XXX_STRICT_PCI_SETUP
  199. /*
  200. * AIC7XXX_VERBOSE_DEBUGGING
  201. * This option enables a lot of extra printk();s in the code, surrounded
  202. * by if (aic7xxx_verbose ...) statements. Executing all of those if
  203. * statements and the extra checks can get to where it actually does have
  204. * an impact on CPU usage and such, as well as code size. Disabling this
  205. * define will keep some of those from becoming part of the code.
  206. *
  207. * NOTE: Currently, this option has no real effect, I will be adding the
  208. * various #ifdef's in the code later when I've decided a section is
  209. * complete and no longer needs debugging. OK...a lot of things are now
  210. * surrounded by this define, so turning this off does have an impact.
  211. */
  212. /*
  213. * #define AIC7XXX_VERBOSE_DEBUGGING
  214. */
  215. #include <linux/module.h>
  216. #include <stdarg.h>
  217. #include <asm/io.h>
  218. #include <asm/irq.h>
  219. #include <asm/byteorder.h>
  220. #include <linux/string.h>
  221. #include <linux/errno.h>
  222. #include <linux/kernel.h>
  223. #include <linux/ioport.h>
  224. #include <linux/delay.h>
  225. #include <linux/sched.h>
  226. #include <linux/pci.h>
  227. #include <linux/proc_fs.h>
  228. #include <linux/blkdev.h>
  229. #include <linux/init.h>
  230. #include <linux/spinlock.h>
  231. #include <linux/smp.h>
  232. #include <linux/interrupt.h>
  233. #include "scsi.h"
  234. #include <scsi/scsi_host.h>
  235. #include "aic7xxx_old/aic7xxx.h"
  236. #include "aic7xxx_old/sequencer.h"
  237. #include "aic7xxx_old/scsi_message.h"
  238. #include "aic7xxx_old/aic7xxx_reg.h"
  239. #include <scsi/scsicam.h>
  240. #include <linux/stat.h>
  241. #include <linux/slab.h> /* for kmalloc() */
  242. #include <linux/config.h> /* for CONFIG_PCI */
  243. #define AIC7XXX_C_VERSION "5.2.6"
  244. #define ALL_TARGETS -1
  245. #define ALL_CHANNELS -1
  246. #define ALL_LUNS -1
  247. #define MAX_TARGETS 16
  248. #define MAX_LUNS 8
  249. #ifndef TRUE
  250. # define TRUE 1
  251. #endif
  252. #ifndef FALSE
  253. # define FALSE 0
  254. #endif
  255. #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
  256. # define MMAPIO
  257. #endif
  258. /*
  259. * You can try raising me for better performance or lowering me if you have
  260. * flaky devices that go off the scsi bus when hit with too many tagged
  261. * commands (like some IBM SCSI-3 LVD drives).
  262. */
  263. #define AIC7XXX_CMDS_PER_DEVICE 32
  264. typedef struct
  265. {
  266. unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
  267. } adapter_tag_info_t;
  268. /*
  269. * Make a define that will tell the driver not to the default tag depth
  270. * everywhere.
  271. */
  272. #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
  273. 0, 0, 0, 0, 0, 0, 0, 0}
  274. /*
  275. * Modify this as you see fit for your system. By setting tag_commands
  276. * to 0, the driver will use it's own algorithm for determining the
  277. * number of commands to use (see above). When 255, the driver will
  278. * not enable tagged queueing for that particular device. When positive
  279. * (> 0) and (< 255) the values in the array are used for the queue_depth.
  280. * Note that the maximum value for an entry is 254, but you're insane if
  281. * you try to use that many commands on one device.
  282. *
  283. * In this example, the first line will disable tagged queueing for all
  284. * the devices on the first probed aic7xxx adapter.
  285. *
  286. * The second line enables tagged queueing with 4 commands/LUN for IDs
  287. * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  288. * driver to use its own algorithm for ID 1.
  289. *
  290. * The third line is the same as the first line.
  291. *
  292. * The fourth line disables tagged queueing for devices 0 and 3. It
  293. * enables tagged queueing for the other IDs, with 16 commands/LUN
  294. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  295. * IDs 2, 5-7, and 9-15.
  296. */
  297. /*
  298. * NOTE: The below structure is for reference only, the actual structure
  299. * to modify in order to change things is found after this fake one.
  300. *
  301. adapter_tag_info_t aic7xxx_tag_info[] =
  302. {
  303. {DEFAULT_TAG_COMMANDS},
  304. {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
  305. {DEFAULT_TAG_COMMANDS},
  306. {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  307. };
  308. */
  309. static adapter_tag_info_t aic7xxx_tag_info[] =
  310. {
  311. {DEFAULT_TAG_COMMANDS},
  312. {DEFAULT_TAG_COMMANDS},
  313. {DEFAULT_TAG_COMMANDS},
  314. {DEFAULT_TAG_COMMANDS},
  315. {DEFAULT_TAG_COMMANDS},
  316. {DEFAULT_TAG_COMMANDS},
  317. {DEFAULT_TAG_COMMANDS},
  318. {DEFAULT_TAG_COMMANDS},
  319. {DEFAULT_TAG_COMMANDS},
  320. {DEFAULT_TAG_COMMANDS},
  321. {DEFAULT_TAG_COMMANDS},
  322. {DEFAULT_TAG_COMMANDS},
  323. {DEFAULT_TAG_COMMANDS},
  324. {DEFAULT_TAG_COMMANDS},
  325. {DEFAULT_TAG_COMMANDS},
  326. {DEFAULT_TAG_COMMANDS}
  327. };
  328. /*
  329. * Define an array of board names that can be indexed by aha_type.
  330. * Don't forget to change this when changing the types!
  331. */
  332. static const char *board_names[] = {
  333. "AIC-7xxx Unknown", /* AIC_NONE */
  334. "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
  335. "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
  336. "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
  337. "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
  338. "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
  339. "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
  340. "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
  341. "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
  342. "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
  343. "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
  344. "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
  345. "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
  346. "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
  347. "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
  348. "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
  349. "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
  350. "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
  351. "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
  352. "Adaptec AHA-2940UW Pro Ultra SCSI host adapter", /* AIC_7887 */
  353. "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
  354. "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
  355. "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
  356. "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
  357. "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
  358. "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
  359. "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
  360. "Adaptec PCMCIA SCSI controller", /* card bus stuff */
  361. "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
  362. "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
  363. };
  364. /*
  365. * There should be a specific return value for this in scsi.h, but
  366. * it seems that most drivers ignore it.
  367. */
  368. #define DID_UNDERFLOW DID_ERROR
  369. /*
  370. * What we want to do is have the higher level scsi driver requeue
  371. * the command to us. There is no specific driver status for this
  372. * condition, but the higher level scsi driver will requeue the
  373. * command on a DID_BUS_BUSY error.
  374. *
  375. * Upon further inspection and testing, it seems that DID_BUS_BUSY
  376. * will *always* retry the command. We can get into an infinite loop
  377. * if this happens when we really want some sort of counter that
  378. * will automatically abort/reset the command after so many retries.
  379. * Using DID_ERROR will do just that. (Made by a suggestion by
  380. * Doug Ledford 8/1/96)
  381. */
  382. #define DID_RETRY_COMMAND DID_ERROR
  383. #define HSCSIID 0x07
  384. #define SCSI_RESET 0x040
  385. /*
  386. * EISA/VL-bus stuff
  387. */
  388. #define MINSLOT 1
  389. #define MAXSLOT 15
  390. #define SLOTBASE(x) ((x) << 12)
  391. #define BASE_TO_SLOT(x) ((x) >> 12)
  392. /*
  393. * Standard EISA Host ID regs (Offset from slot base)
  394. */
  395. #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
  396. #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
  397. #define AHC_HID2 0x82 /* product */
  398. #define AHC_HID3 0x83 /* firmware revision */
  399. /*
  400. * AIC-7770 I/O range to reserve for a card
  401. */
  402. #define MINREG 0xC00
  403. #define MAXREG 0xCFF
  404. #define INTDEF 0x5C /* Interrupt Definition Register */
  405. /*
  406. * AIC-78X0 PCI registers
  407. */
  408. #define CLASS_PROGIF_REVID 0x08
  409. #define DEVREVID 0x000000FFul
  410. #define PROGINFC 0x0000FF00ul
  411. #define SUBCLASS 0x00FF0000ul
  412. #define BASECLASS 0xFF000000ul
  413. #define CSIZE_LATTIME 0x0C
  414. #define CACHESIZE 0x0000003Ful /* only 5 bits */
  415. #define LATTIME 0x0000FF00ul
  416. #define DEVCONFIG 0x40
  417. #define SCBSIZE32 0x00010000ul /* aic789X only */
  418. #define MPORTMODE 0x00000400ul /* aic7870 only */
  419. #define RAMPSM 0x00000200ul /* aic7870 only */
  420. #define RAMPSM_ULTRA2 0x00000004
  421. #define VOLSENSE 0x00000100ul
  422. #define SCBRAMSEL 0x00000080ul
  423. #define SCBRAMSEL_ULTRA2 0x00000008
  424. #define MRDCEN 0x00000040ul
  425. #define EXTSCBTIME 0x00000020ul /* aic7870 only */
  426. #define EXTSCBPEN 0x00000010ul /* aic7870 only */
  427. #define BERREN 0x00000008ul
  428. #define DACEN 0x00000004ul
  429. #define STPWLEVEL 0x00000002ul
  430. #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
  431. #define SCAMCTL 0x1a /* Ultra2 only */
  432. #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
  433. /*
  434. * Define the different types of SEEPROMs on aic7xxx adapters
  435. * and make it also represent the address size used in accessing
  436. * its registers. The 93C46 chips have 1024 bits organized into
  437. * 64 16-bit words, while the 93C56 chips have 2048 bits organized
  438. * into 128 16-bit words. The C46 chips use 6 bits to address
  439. * each word, while the C56 and C66 (4096 bits) use 8 bits to
  440. * address each word.
  441. */
  442. typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
  443. /*
  444. *
  445. * Define the format of the SEEPROM registers (16 bits).
  446. *
  447. */
  448. struct seeprom_config {
  449. /*
  450. * SCSI ID Configuration Flags
  451. */
  452. #define CFXFER 0x0007 /* synchronous transfer rate */
  453. #define CFSYNCH 0x0008 /* enable synchronous transfer */
  454. #define CFDISC 0x0010 /* enable disconnection */
  455. #define CFWIDEB 0x0020 /* wide bus device (wide card) */
  456. #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
  457. #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
  458. #define CFSTART 0x0100 /* send start unit SCSI command */
  459. #define CFINCBIOS 0x0200 /* include in BIOS scan */
  460. #define CFRNFOUND 0x0400 /* report even if not found */
  461. #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
  462. #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
  463. #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
  464. /* UNUSED 0x3000 */
  465. unsigned short device_flags[16]; /* words 0-15 */
  466. /*
  467. * BIOS Control Bits
  468. */
  469. #define CFSUPREM 0x0001 /* support all removable drives */
  470. #define CFSUPREMB 0x0002 /* support removable drives for boot only */
  471. #define CFBIOSEN 0x0004 /* BIOS enabled */
  472. /* UNUSED 0x0008 */
  473. #define CFSM2DRV 0x0010 /* support more than two drives */
  474. #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
  475. /* UNUSED 0x0040 */
  476. #define CFEXTEND 0x0080 /* extended translation enabled */
  477. /* UNUSED 0xFF00 */
  478. unsigned short bios_control; /* word 16 */
  479. /*
  480. * Host Adapter Control Bits
  481. */
  482. #define CFAUTOTERM 0x0001 /* Perform Auto termination */
  483. #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
  484. #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
  485. #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
  486. #define CFSTERM 0x0004 /* SCSI low byte termination */
  487. #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
  488. #define CFSPARITY 0x0010 /* SCSI parity */
  489. #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
  490. #define CFRESETB 0x0040 /* reset SCSI bus at boot */
  491. #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
  492. #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
  493. #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
  494. /* UNUSED 0xF280 */
  495. unsigned short adapter_control; /* word 17 */
  496. /*
  497. * Bus Release, Host Adapter ID
  498. */
  499. #define CFSCSIID 0x000F /* host adapter SCSI ID */
  500. /* UNUSED 0x00F0 */
  501. #define CFBRTIME 0xFF00 /* bus release time */
  502. unsigned short brtime_id; /* word 18 */
  503. /*
  504. * Maximum targets
  505. */
  506. #define CFMAXTARG 0x00FF /* maximum targets */
  507. /* UNUSED 0xFF00 */
  508. unsigned short max_targets; /* word 19 */
  509. unsigned short res_1[11]; /* words 20-30 */
  510. unsigned short checksum; /* word 31 */
  511. };
  512. #define SELBUS_MASK 0x0a
  513. #define SELNARROW 0x00
  514. #define SELBUSB 0x08
  515. #define SINGLE_BUS 0x00
  516. #define SCB_TARGET(scb) \
  517. (((scb)->hscb->target_channel_lun & TID) >> 4)
  518. #define SCB_LUN(scb) \
  519. ((scb)->hscb->target_channel_lun & LID)
  520. #define SCB_IS_SCSIBUS_B(scb) \
  521. (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
  522. /*
  523. * If an error occurs during a data transfer phase, run the command
  524. * to completion - it's easier that way - making a note of the error
  525. * condition in this location. This then will modify a DID_OK status
  526. * into an appropriate error for the higher-level SCSI code.
  527. */
  528. #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
  529. /*
  530. * Keep track of the targets returned status.
  531. */
  532. #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
  533. /*
  534. * The position of the SCSI commands scb within the scb array.
  535. */
  536. #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
  537. /*
  538. * The stored DMA mapping for single-buffer data transfers.
  539. */
  540. #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
  541. /*
  542. * Get out private data area from a scsi cmd pointer
  543. */
  544. #define AIC_DEV(cmd) ((struct aic_dev_data *)(cmd)->device->hostdata)
  545. /*
  546. * So we can keep track of our host structs
  547. */
  548. static struct aic7xxx_host *first_aic7xxx = NULL;
  549. /*
  550. * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
  551. * in the scatter-gather lists. We need to convert the virtual
  552. * addresses to physical addresses.
  553. */
  554. struct hw_scatterlist {
  555. unsigned int address;
  556. unsigned int length;
  557. };
  558. /*
  559. * Maximum number of SG segments these cards can support.
  560. */
  561. #define AIC7XXX_MAX_SG 128
  562. /*
  563. * The maximum number of SCBs we could have for ANY type
  564. * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
  565. * SEQUENCER CODE IF THIS IS MODIFIED!
  566. */
  567. #define AIC7XXX_MAXSCB 255
  568. struct aic7xxx_hwscb {
  569. /* ------------ Begin hardware supported fields ---------------- */
  570. /* 0*/ unsigned char control;
  571. /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
  572. /* 2*/ unsigned char target_status;
  573. /* 3*/ unsigned char SG_segment_count;
  574. /* 4*/ unsigned int SG_list_pointer;
  575. /* 8*/ unsigned char residual_SG_segment_count;
  576. /* 9*/ unsigned char residual_data_count[3];
  577. /*12*/ unsigned int data_pointer;
  578. /*16*/ unsigned int data_count;
  579. /*20*/ unsigned int SCSI_cmd_pointer;
  580. /*24*/ unsigned char SCSI_cmd_length;
  581. /*25*/ unsigned char tag; /* Index into our kernel SCB array.
  582. * Also used as the tag for tagged I/O
  583. */
  584. #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
  585. * via PIO to initialize a transaction.
  586. */
  587. /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
  588. * or disconnected down in the sequencer.
  589. */
  590. /*27*/ unsigned char prev;
  591. /*28*/ unsigned int pad; /*
  592. * Unused by the kernel, but we require
  593. * the padding so that the array of
  594. * hardware SCBs is aligned on 32 byte
  595. * boundaries so the sequencer can index
  596. */
  597. };
  598. typedef enum {
  599. SCB_FREE = 0x0000,
  600. SCB_DTR_SCB = 0x0001,
  601. SCB_WAITINGQ = 0x0002,
  602. SCB_ACTIVE = 0x0004,
  603. SCB_SENSE = 0x0008,
  604. SCB_ABORT = 0x0010,
  605. SCB_DEVICE_RESET = 0x0020,
  606. SCB_RESET = 0x0040,
  607. SCB_RECOVERY_SCB = 0x0080,
  608. SCB_MSGOUT_PPR = 0x0100,
  609. SCB_MSGOUT_SENT = 0x0200,
  610. SCB_MSGOUT_SDTR = 0x0400,
  611. SCB_MSGOUT_WDTR = 0x0800,
  612. SCB_MSGOUT_BITS = SCB_MSGOUT_PPR |
  613. SCB_MSGOUT_SENT |
  614. SCB_MSGOUT_SDTR |
  615. SCB_MSGOUT_WDTR,
  616. SCB_QUEUED_ABORT = 0x1000,
  617. SCB_QUEUED_FOR_DONE = 0x2000,
  618. SCB_WAS_BUSY = 0x4000,
  619. SCB_QUEUE_FULL = 0x8000
  620. } scb_flag_type;
  621. typedef enum {
  622. AHC_FNONE = 0x00000000,
  623. AHC_PAGESCBS = 0x00000001,
  624. AHC_CHANNEL_B_PRIMARY = 0x00000002,
  625. AHC_USEDEFAULTS = 0x00000004,
  626. AHC_INDIRECT_PAGING = 0x00000008,
  627. AHC_CHNLB = 0x00000020,
  628. AHC_CHNLC = 0x00000040,
  629. AHC_EXTEND_TRANS_A = 0x00000100,
  630. AHC_EXTEND_TRANS_B = 0x00000200,
  631. AHC_TERM_ENB_A = 0x00000400,
  632. AHC_TERM_ENB_SE_LOW = 0x00000400,
  633. AHC_TERM_ENB_B = 0x00000800,
  634. AHC_TERM_ENB_SE_HIGH = 0x00000800,
  635. AHC_HANDLING_REQINITS = 0x00001000,
  636. AHC_TARGETMODE = 0x00002000,
  637. AHC_NEWEEPROM_FMT = 0x00004000,
  638. /*
  639. * Here ends the FreeBSD defined flags and here begins the linux defined
  640. * flags. NOTE: I did not preserve the old flag name during this change
  641. * specifically to force me to evaluate what flags were being used properly
  642. * and what flags weren't. This way, I could clean up the flag usage on
  643. * a use by use basis. Doug Ledford
  644. */
  645. AHC_MOTHERBOARD = 0x00020000,
  646. AHC_NO_STPWEN = 0x00040000,
  647. AHC_RESET_DELAY = 0x00080000,
  648. AHC_A_SCANNED = 0x00100000,
  649. AHC_B_SCANNED = 0x00200000,
  650. AHC_MULTI_CHANNEL = 0x00400000,
  651. AHC_BIOS_ENABLED = 0x00800000,
  652. AHC_SEEPROM_FOUND = 0x01000000,
  653. AHC_TERM_ENB_LVD = 0x02000000,
  654. AHC_ABORT_PENDING = 0x04000000,
  655. AHC_RESET_PENDING = 0x08000000,
  656. #define AHC_IN_ISR_BIT 28
  657. AHC_IN_ISR = 0x10000000,
  658. AHC_IN_ABORT = 0x20000000,
  659. AHC_IN_RESET = 0x40000000,
  660. AHC_EXTERNAL_SRAM = 0x80000000
  661. } ahc_flag_type;
  662. typedef enum {
  663. AHC_NONE = 0x0000,
  664. AHC_CHIPID_MASK = 0x00ff,
  665. AHC_AIC7770 = 0x0001,
  666. AHC_AIC7850 = 0x0002,
  667. AHC_AIC7860 = 0x0003,
  668. AHC_AIC7870 = 0x0004,
  669. AHC_AIC7880 = 0x0005,
  670. AHC_AIC7890 = 0x0006,
  671. AHC_AIC7895 = 0x0007,
  672. AHC_AIC7896 = 0x0008,
  673. AHC_AIC7892 = 0x0009,
  674. AHC_AIC7899 = 0x000a,
  675. AHC_VL = 0x0100,
  676. AHC_EISA = 0x0200,
  677. AHC_PCI = 0x0400,
  678. } ahc_chip;
  679. typedef enum {
  680. AHC_FENONE = 0x0000,
  681. AHC_ULTRA = 0x0001,
  682. AHC_ULTRA2 = 0x0002,
  683. AHC_WIDE = 0x0004,
  684. AHC_TWIN = 0x0008,
  685. AHC_MORE_SRAM = 0x0010,
  686. AHC_CMD_CHAN = 0x0020,
  687. AHC_QUEUE_REGS = 0x0040,
  688. AHC_SG_PRELOAD = 0x0080,
  689. AHC_SPIOCAP = 0x0100,
  690. AHC_ULTRA3 = 0x0200,
  691. AHC_NEW_AUTOTERM = 0x0400,
  692. AHC_AIC7770_FE = AHC_FENONE,
  693. AHC_AIC7850_FE = AHC_SPIOCAP,
  694. AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
  695. AHC_AIC7870_FE = AHC_FENONE,
  696. AHC_AIC7880_FE = AHC_ULTRA,
  697. AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
  698. AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_NEW_AUTOTERM,
  699. AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
  700. AHC_AIC7896_FE = AHC_AIC7890_FE,
  701. AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_ULTRA3,
  702. AHC_AIC7899_FE = AHC_AIC7890_FE|AHC_ULTRA3,
  703. } ahc_feature;
  704. #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
  705. struct aic7xxx_scb_dma {
  706. unsigned long dma_offset; /* Correction you have to add
  707. * to virtual address to get
  708. * dma handle in this region */
  709. dma_addr_t dma_address; /* DMA handle of the start,
  710. * for unmap */
  711. unsigned int dma_len; /* DMA length */
  712. };
  713. typedef enum {
  714. AHC_BUG_NONE = 0x0000,
  715. AHC_BUG_TMODE_WIDEODD = 0x0001,
  716. AHC_BUG_AUTOFLUSH = 0x0002,
  717. AHC_BUG_CACHETHEN = 0x0004,
  718. AHC_BUG_CACHETHEN_DIS = 0x0008,
  719. AHC_BUG_PCI_2_1_RETRY = 0x0010,
  720. AHC_BUG_PCI_MWI = 0x0020,
  721. AHC_BUG_SCBCHAN_UPLOAD = 0x0040,
  722. } ahc_bugs;
  723. struct aic7xxx_scb {
  724. struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
  725. Scsi_Cmnd *cmd; /* Scsi_Cmnd for this scb */
  726. struct aic7xxx_scb *q_next; /* next scb in queue */
  727. volatile scb_flag_type flags; /* current state of scb */
  728. struct hw_scatterlist *sg_list; /* SG list in adapter format */
  729. unsigned char tag_action;
  730. unsigned char sg_count;
  731. unsigned char *sense_cmd; /*
  732. * Allocate 6 characters for
  733. * sense command.
  734. */
  735. unsigned char *cmnd;
  736. unsigned int sg_length; /* We init this during buildscb so we
  737. * don't have to calculate anything
  738. * during underflow/overflow/stat code
  739. */
  740. void *kmalloc_ptr;
  741. struct aic7xxx_scb_dma *scb_dma;
  742. };
  743. /*
  744. * Define a linked list of SCBs.
  745. */
  746. typedef struct {
  747. struct aic7xxx_scb *head;
  748. struct aic7xxx_scb *tail;
  749. } scb_queue_type;
  750. static struct {
  751. unsigned char errno;
  752. const char *errmesg;
  753. } hard_error[] = {
  754. { ILLHADDR, "Illegal Host Access" },
  755. { ILLSADDR, "Illegal Sequencer Address referenced" },
  756. { ILLOPCODE, "Illegal Opcode in sequencer program" },
  757. { SQPARERR, "Sequencer Ram Parity Error" },
  758. { DPARERR, "Data-Path Ram Parity Error" },
  759. { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
  760. { PCIERRSTAT,"PCI Error detected" },
  761. { CIOPARERR, "CIOBUS Parity Error" }
  762. };
  763. static unsigned char
  764. generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
  765. typedef struct {
  766. scb_queue_type free_scbs; /*
  767. * SCBs assigned to free slot on
  768. * card (no paging required)
  769. */
  770. struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
  771. struct aic7xxx_hwscb *hscbs;
  772. unsigned char numscbs; /* current number of scbs */
  773. unsigned char maxhscbs; /* hardware scbs */
  774. unsigned char maxscbs; /* max scbs including pageable scbs */
  775. dma_addr_t hscbs_dma; /* DMA handle to hscbs */
  776. unsigned int hscbs_dma_len; /* length of the above DMA area */
  777. void *hscb_kmalloc_ptr;
  778. } scb_data_type;
  779. struct target_cmd {
  780. unsigned char mesg_bytes[4];
  781. unsigned char command[28];
  782. };
  783. #define AHC_TRANS_CUR 0x0001
  784. #define AHC_TRANS_ACTIVE 0x0002
  785. #define AHC_TRANS_GOAL 0x0004
  786. #define AHC_TRANS_USER 0x0008
  787. #define AHC_TRANS_QUITE 0x0010
  788. typedef struct {
  789. unsigned char width;
  790. unsigned char period;
  791. unsigned char offset;
  792. unsigned char options;
  793. } transinfo_type;
  794. struct aic_dev_data {
  795. volatile scb_queue_type delayed_scbs;
  796. volatile unsigned short temp_q_depth;
  797. unsigned short max_q_depth;
  798. volatile unsigned char active_cmds;
  799. /*
  800. * Statistics Kept:
  801. *
  802. * Total Xfers (count for each command that has a data xfer),
  803. * broken down by reads && writes.
  804. *
  805. * Further sorted into a few bins for keeping tabs on how many commands
  806. * we get of various sizes.
  807. *
  808. */
  809. long w_total; /* total writes */
  810. long r_total; /* total reads */
  811. long barrier_total; /* total num of REQ_BARRIER commands */
  812. long ordered_total; /* How many REQ_BARRIER commands we
  813. used ordered tags to satisfy */
  814. long w_bins[6]; /* binned write */
  815. long r_bins[6]; /* binned reads */
  816. transinfo_type cur;
  817. transinfo_type goal;
  818. #define BUS_DEVICE_RESET_PENDING 0x01
  819. #define DEVICE_RESET_DELAY 0x02
  820. #define DEVICE_PRINT_DTR 0x04
  821. #define DEVICE_WAS_BUSY 0x08
  822. #define DEVICE_DTR_SCANNED 0x10
  823. #define DEVICE_SCSI_3 0x20
  824. volatile unsigned char flags;
  825. unsigned needppr:1;
  826. unsigned needppr_copy:1;
  827. unsigned needsdtr:1;
  828. unsigned needsdtr_copy:1;
  829. unsigned needwdtr:1;
  830. unsigned needwdtr_copy:1;
  831. unsigned dtr_pending:1;
  832. struct scsi_device *SDptr;
  833. struct list_head list;
  834. };
  835. /*
  836. * Define a structure used for each host adapter. Note, in order to avoid
  837. * problems with architectures I can't test on (because I don't have one,
  838. * such as the Alpha based systems) which happen to give faults for
  839. * non-aligned memory accesses, care was taken to align this structure
  840. * in a way that gauranteed all accesses larger than 8 bits were aligned
  841. * on the appropriate boundary. It's also organized to try and be more
  842. * cache line efficient. Be careful when changing this lest you might hurt
  843. * overall performance and bring down the wrath of the masses.
  844. */
  845. struct aic7xxx_host {
  846. /*
  847. * This is the first 64 bytes in the host struct
  848. */
  849. /*
  850. * We are grouping things here....first, items that get either read or
  851. * written with nearly every interrupt
  852. */
  853. volatile long flags;
  854. ahc_feature features; /* chip features */
  855. unsigned long base; /* card base address */
  856. volatile unsigned char __iomem *maddr; /* memory mapped address */
  857. unsigned long isr_count; /* Interrupt count */
  858. unsigned long spurious_int;
  859. scb_data_type *scb_data;
  860. struct aic7xxx_cmd_queue {
  861. Scsi_Cmnd *head;
  862. Scsi_Cmnd *tail;
  863. } completeq;
  864. /*
  865. * Things read/written on nearly every entry into aic7xxx_queue()
  866. */
  867. volatile scb_queue_type waiting_scbs;
  868. unsigned char unpause; /* unpause value for HCNTRL */
  869. unsigned char pause; /* pause value for HCNTRL */
  870. volatile unsigned char qoutfifonext;
  871. volatile unsigned char activescbs; /* active scbs */
  872. volatile unsigned char max_activescbs;
  873. volatile unsigned char qinfifonext;
  874. volatile unsigned char *untagged_scbs;
  875. volatile unsigned char *qoutfifo;
  876. volatile unsigned char *qinfifo;
  877. unsigned char dev_last_queue_full[MAX_TARGETS];
  878. unsigned char dev_last_queue_full_count[MAX_TARGETS];
  879. unsigned short ultraenb; /* Gets downloaded to card as a
  880. bitmap */
  881. unsigned short discenable; /* Gets downloaded to card as a
  882. bitmap */
  883. transinfo_type user[MAX_TARGETS];
  884. unsigned char msg_buf[13]; /* The message for the target */
  885. unsigned char msg_type;
  886. #define MSG_TYPE_NONE 0x00
  887. #define MSG_TYPE_INITIATOR_MSGOUT 0x01
  888. #define MSG_TYPE_INITIATOR_MSGIN 0x02
  889. unsigned char msg_len; /* Length of message */
  890. unsigned char msg_index; /* Index into msg_buf array */
  891. /*
  892. * We put the less frequently used host structure items after the more
  893. * frequently used items to try and ease the burden on the cache subsystem.
  894. * These entries are not *commonly* accessed, whereas the preceding entries
  895. * are accessed very often.
  896. */
  897. unsigned int irq; /* IRQ for this adapter */
  898. int instance; /* aic7xxx instance number */
  899. int scsi_id; /* host adapter SCSI ID */
  900. int scsi_id_b; /* channel B for twin adapters */
  901. unsigned int bios_address;
  902. int board_name_index;
  903. unsigned short bios_control; /* bios control - SEEPROM */
  904. unsigned short adapter_control; /* adapter control - SEEPROM */
  905. struct pci_dev *pdev;
  906. unsigned char pci_bus;
  907. unsigned char pci_device_fn;
  908. struct seeprom_config sc;
  909. unsigned short sc_type;
  910. unsigned short sc_size;
  911. struct aic7xxx_host *next; /* allow for multiple IRQs */
  912. struct Scsi_Host *host; /* pointer to scsi host */
  913. struct list_head aic_devs; /* all aic_dev structs on host */
  914. int host_no; /* SCSI host number */
  915. unsigned long mbase; /* I/O memory address */
  916. ahc_chip chip; /* chip type */
  917. ahc_bugs bugs;
  918. dma_addr_t fifo_dma; /* DMA handle for fifo arrays */
  919. };
  920. /*
  921. * Valid SCSIRATE values. (p. 3-17)
  922. * Provides a mapping of transfer periods in ns/4 to the proper value to
  923. * stick in the SCSIRATE reg to use that transfer rate.
  924. */
  925. #define AHC_SYNCRATE_ULTRA3 0
  926. #define AHC_SYNCRATE_ULTRA2 1
  927. #define AHC_SYNCRATE_ULTRA 3
  928. #define AHC_SYNCRATE_FAST 6
  929. #define AHC_SYNCRATE_CRC 0x40
  930. #define AHC_SYNCRATE_SE 0x10
  931. static struct aic7xxx_syncrate {
  932. /* Rates in Ultra mode have bit 8 of sxfr set */
  933. #define ULTRA_SXFR 0x100
  934. int sxfr_ultra2;
  935. int sxfr;
  936. unsigned char period;
  937. const char *rate[2];
  938. } aic7xxx_syncrates[] = {
  939. { 0x42, 0x000, 9, {"80.0", "160.0"} },
  940. { 0x13, 0x000, 10, {"40.0", "80.0"} },
  941. { 0x14, 0x000, 11, {"33.0", "66.6"} },
  942. { 0x15, 0x100, 12, {"20.0", "40.0"} },
  943. { 0x16, 0x110, 15, {"16.0", "32.0"} },
  944. { 0x17, 0x120, 18, {"13.4", "26.8"} },
  945. { 0x18, 0x000, 25, {"10.0", "20.0"} },
  946. { 0x19, 0x010, 31, {"8.0", "16.0"} },
  947. { 0x1a, 0x020, 37, {"6.67", "13.3"} },
  948. { 0x1b, 0x030, 43, {"5.7", "11.4"} },
  949. { 0x10, 0x040, 50, {"5.0", "10.0"} },
  950. { 0x00, 0x050, 56, {"4.4", "8.8" } },
  951. { 0x00, 0x060, 62, {"4.0", "8.0" } },
  952. { 0x00, 0x070, 68, {"3.6", "7.2" } },
  953. { 0x00, 0x000, 0, {NULL, NULL} },
  954. };
  955. #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
  956. (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
  957. ((scb->hscb)->target_channel_lun & 0x07)
  958. #define CTL_OF_CMD(cmd) ((cmd->device->channel) & 0x01), \
  959. ((cmd->device->id) & 0x0f), \
  960. ((cmd->device->lun) & 0x07)
  961. #define TARGET_INDEX(cmd) ((cmd)->device->id | ((cmd)->device->channel << 3))
  962. /*
  963. * A nice little define to make doing our printks a little easier
  964. */
  965. #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
  966. #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
  967. /*
  968. * XXX - these options apply unilaterally to _all_ 274x/284x/294x
  969. * cards in the system. This should be fixed. Exceptions to this
  970. * rule are noted in the comments.
  971. */
  972. /*
  973. * Use this as the default queue depth when setting tagged queueing on.
  974. */
  975. static unsigned int aic7xxx_default_queue_depth = AIC7XXX_CMDS_PER_DEVICE;
  976. /*
  977. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  978. * has no effect on any later resets that might occur due to things like
  979. * SCSI bus timeouts.
  980. */
  981. static unsigned int aic7xxx_no_reset = 0;
  982. /*
  983. * Certain PCI motherboards will scan PCI devices from highest to lowest,
  984. * others scan from lowest to highest, and they tend to do all kinds of
  985. * strange things when they come into contact with PCI bridge chips. The
  986. * net result of all this is that the PCI card that is actually used to boot
  987. * the machine is very hard to detect. Most motherboards go from lowest
  988. * PCI slot number to highest, and the first SCSI controller found is the
  989. * one you boot from. The only exceptions to this are when a controller
  990. * has its BIOS disabled. So, we by default sort all of our SCSI controllers
  991. * from lowest PCI slot number to highest PCI slot number. We also force
  992. * all controllers with their BIOS disabled to the end of the list. This
  993. * works on *almost* all computers. Where it doesn't work, we have this
  994. * option. Setting this option to non-0 will reverse the order of the sort
  995. * to highest first, then lowest, but will still leave cards with their BIOS
  996. * disabled at the very end. That should fix everyone up unless there are
  997. * really strange cirumstances.
  998. */
  999. static int aic7xxx_reverse_scan = 0;
  1000. /*
  1001. * Should we force EXTENDED translation on a controller.
  1002. * 0 == Use whatever is in the SEEPROM or default to off
  1003. * 1 == Use whatever is in the SEEPROM or default to on
  1004. */
  1005. static unsigned int aic7xxx_extended = 0;
  1006. /*
  1007. * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
  1008. * -1 = Use detected settings.
  1009. * 0 = Force Edge triggered mode.
  1010. * 1 = Force Level triggered mode.
  1011. */
  1012. static int aic7xxx_irq_trigger = -1;
  1013. /*
  1014. * This variable is used to override the termination settings on a controller.
  1015. * This should not be used under normal conditions. However, in the case
  1016. * that a controller does not have a readable SEEPROM (so that we can't
  1017. * read the SEEPROM settings directly) and that a controller has a buggered
  1018. * version of the cable detection logic, this can be used to force the
  1019. * correct termination. It is preferable to use the manual termination
  1020. * settings in the BIOS if possible, but some motherboard controllers store
  1021. * those settings in a format we can't read. In other cases, auto term
  1022. * should also work, but the chipset was put together with no auto term
  1023. * logic (common on motherboard controllers). In those cases, we have
  1024. * 32 bits here to work with. That's good for 8 controllers/channels. The
  1025. * bits are organized as 4 bits per channel, with scsi0 getting the lowest
  1026. * 4 bits in the int. A 1 in a bit position indicates the termination setting
  1027. * that corresponds to that bit should be enabled, a 0 is disabled.
  1028. * It looks something like this:
  1029. *
  1030. * 0x0f = 1111-Single Ended Low Byte Termination on/off
  1031. * ||\-Single Ended High Byte Termination on/off
  1032. * |\-LVD Low Byte Termination on/off
  1033. * \-LVD High Byte Termination on/off
  1034. *
  1035. * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
  1036. * enable both high byte and low byte termination on scsi0, I would need to
  1037. * make sure that the override_term variable was set to 0x03 (bits 0011).
  1038. * To make sure that all termination is enabled on an Ultra2 controller at
  1039. * scsi2 and only high byte termination on scsi1 and high and low byte
  1040. * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
  1041. *
  1042. * For the most part, users should never have to use this, that's why I
  1043. * left it fairly cryptic instead of easy to understand. If you need it,
  1044. * most likely someone will be telling you what your's needs to be set to.
  1045. */
  1046. static int aic7xxx_override_term = -1;
  1047. /*
  1048. * Certain motherboard chipset controllers tend to screw
  1049. * up the polarity of the term enable output pin. Use this variable
  1050. * to force the correct polarity for your system. This is a bitfield variable
  1051. * similar to the previous one, but this one has one bit per channel instead
  1052. * of four.
  1053. * 0 = Force the setting to active low.
  1054. * 1 = Force setting to active high.
  1055. * Most Adaptec cards are active high, several motherboards are active low.
  1056. * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
  1057. * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
  1058. * to active high, you would need to set stpwlev=0x9 (bits 1001).
  1059. *
  1060. * People shouldn't need to use this, but if you are experiencing lots of
  1061. * SCSI timeout problems, this may help. There is one sure way to test what
  1062. * this option needs to be. Using a boot floppy to boot the system, configure
  1063. * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
  1064. * if needed then also pass a value to override_term to make sure that the
  1065. * driver is enabling SCSI termination, then set this variable to either 0
  1066. * or 1. When the driver boots, make sure there are *NO* SCSI cables
  1067. * connected to your controller. If it finds and inits the controller
  1068. * without problem, then the setting you passed to stpwlev was correct. If
  1069. * the driver goes into a reset loop and hangs the system, then you need the
  1070. * other setting for this variable. If neither setting lets the machine
  1071. * boot then you have definite termination problems that may not be fixable.
  1072. */
  1073. static int aic7xxx_stpwlev = -1;
  1074. /*
  1075. * Set this to non-0 in order to force the driver to panic the kernel
  1076. * and print out debugging info on a SCSI abort or reset cycle.
  1077. */
  1078. static int aic7xxx_panic_on_abort = 0;
  1079. /*
  1080. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  1081. * dubious at best. To my knowledge, this option has never actually
  1082. * solved a PCI parity problem, but on certain machines with broken PCI
  1083. * chipset configurations, it can generate tons of false error messages.
  1084. * It's included in the driver for completeness.
  1085. * 0 = Shut off PCI parity check
  1086. * -1 = Normal polarity pci parity checking
  1087. * 1 = reverse polarity pci parity checking
  1088. *
  1089. * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
  1090. * variable to -1 you would actually want to simply pass the variable
  1091. * name without a number. That will invert the 0 which will result in
  1092. * -1.
  1093. */
  1094. static int aic7xxx_pci_parity = 0;
  1095. /*
  1096. * Set this to any non-0 value to cause us to dump the contents of all
  1097. * the card's registers in a hex dump format tailored to each model of
  1098. * controller.
  1099. *
  1100. * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
  1101. * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
  1102. * ONLY
  1103. */
  1104. static int aic7xxx_dump_card = 0;
  1105. /*
  1106. * Set this to a non-0 value to make us dump out the 32 bit instruction
  1107. * registers on the card after completing the sequencer download. This
  1108. * allows the actual sequencer download to be verified. It is possible
  1109. * to use this option and still boot up and run your system. This is
  1110. * only intended for debugging purposes.
  1111. */
  1112. static int aic7xxx_dump_sequencer = 0;
  1113. /*
  1114. * Certain newer motherboards have put new PCI based devices into the
  1115. * IO spaces that used to typically be occupied by VLB or EISA cards.
  1116. * This overlap can cause these newer motherboards to lock up when scanned
  1117. * for older EISA and VLB devices. Setting this option to non-0 will
  1118. * cause the driver to skip scanning for any VLB or EISA controllers and
  1119. * only support the PCI controllers. NOTE: this means that if the kernel
  1120. * os compiled with PCI support disabled, then setting this to non-0
  1121. * would result in never finding any devices :)
  1122. */
  1123. static int aic7xxx_no_probe = 0;
  1124. /*
  1125. * On some machines, enabling the external SCB RAM isn't reliable yet. I
  1126. * haven't had time to make test patches for things like changing the
  1127. * timing mode on that external RAM either. Some of those changes may
  1128. * fix the problem. Until then though, we default to external SCB RAM
  1129. * off and give a command line option to enable it.
  1130. */
  1131. static int aic7xxx_scbram = 0;
  1132. /*
  1133. * So that we can set how long each device is given as a selection timeout.
  1134. * The table of values goes like this:
  1135. * 0 - 256ms
  1136. * 1 - 128ms
  1137. * 2 - 64ms
  1138. * 3 - 32ms
  1139. * We default to 64ms because it's fast. Some old SCSI-I devices need a
  1140. * longer time. The final value has to be left shifted by 3, hence 0x10
  1141. * is the final value.
  1142. */
  1143. static int aic7xxx_seltime = 0x10;
  1144. /*
  1145. * So that insmod can find the variable and make it point to something
  1146. */
  1147. #ifdef MODULE
  1148. static char * aic7xxx = NULL;
  1149. module_param(aic7xxx, charp, 0);
  1150. #endif
  1151. #define VERBOSE_NORMAL 0x0000
  1152. #define VERBOSE_NEGOTIATION 0x0001
  1153. #define VERBOSE_SEQINT 0x0002
  1154. #define VERBOSE_SCSIINT 0x0004
  1155. #define VERBOSE_PROBE 0x0008
  1156. #define VERBOSE_PROBE2 0x0010
  1157. #define VERBOSE_NEGOTIATION2 0x0020
  1158. #define VERBOSE_MINOR_ERROR 0x0040
  1159. #define VERBOSE_TRACING 0x0080
  1160. #define VERBOSE_ABORT 0x0f00
  1161. #define VERBOSE_ABORT_MID 0x0100
  1162. #define VERBOSE_ABORT_FIND 0x0200
  1163. #define VERBOSE_ABORT_PROCESS 0x0400
  1164. #define VERBOSE_ABORT_RETURN 0x0800
  1165. #define VERBOSE_RESET 0xf000
  1166. #define VERBOSE_RESET_MID 0x1000
  1167. #define VERBOSE_RESET_FIND 0x2000
  1168. #define VERBOSE_RESET_PROCESS 0x4000
  1169. #define VERBOSE_RESET_RETURN 0x8000
  1170. static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
  1171. VERBOSE_PROBE; /* verbose messages */
  1172. /****************************************************************************
  1173. *
  1174. * We're going to start putting in function declarations so that order of
  1175. * functions is no longer important. As needed, they are added here.
  1176. *
  1177. ***************************************************************************/
  1178. static int aic7xxx_release(struct Scsi_Host *host);
  1179. static void aic7xxx_set_syncrate(struct aic7xxx_host *p,
  1180. struct aic7xxx_syncrate *syncrate, int target, int channel,
  1181. unsigned int period, unsigned int offset, unsigned char options,
  1182. unsigned int type, struct aic_dev_data *aic_dev);
  1183. static void aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel,
  1184. int lun, unsigned int width, unsigned int type,
  1185. struct aic_dev_data *aic_dev);
  1186. static void aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd);
  1187. static void aic7xxx_print_card(struct aic7xxx_host *p);
  1188. static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
  1189. static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
  1190. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  1191. static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
  1192. #endif
  1193. /****************************************************************************
  1194. *
  1195. * These functions are now used. They happen to be wrapped in useless
  1196. * inb/outb port read/writes around the real reads and writes because it
  1197. * seems that certain very fast CPUs have a problem dealing with us when
  1198. * going at full speed.
  1199. *
  1200. ***************************************************************************/
  1201. static inline unsigned char
  1202. aic_inb(struct aic7xxx_host *p, long port)
  1203. {
  1204. #ifdef MMAPIO
  1205. unsigned char x;
  1206. if(p->maddr)
  1207. {
  1208. x = readb(p->maddr + port);
  1209. }
  1210. else
  1211. {
  1212. x = inb(p->base + port);
  1213. }
  1214. return(x);
  1215. #else
  1216. return(inb(p->base + port));
  1217. #endif
  1218. }
  1219. static inline void
  1220. aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
  1221. {
  1222. #ifdef MMAPIO
  1223. if(p->maddr)
  1224. {
  1225. writeb(val, p->maddr + port);
  1226. mb(); /* locked operation in order to force CPU ordering */
  1227. readb(p->maddr + HCNTRL); /* dummy read to flush the PCI write */
  1228. }
  1229. else
  1230. {
  1231. outb(val, p->base + port);
  1232. mb(); /* locked operation in order to force CPU ordering */
  1233. }
  1234. #else
  1235. outb(val, p->base + port);
  1236. mb(); /* locked operation in order to force CPU ordering */
  1237. #endif
  1238. }
  1239. /*+F*************************************************************************
  1240. * Function:
  1241. * aic7xxx_setup
  1242. *
  1243. * Description:
  1244. * Handle Linux boot parameters. This routine allows for assigning a value
  1245. * to a parameter with a ':' between the parameter and the value.
  1246. * ie. aic7xxx=unpause:0x0A,extended
  1247. *-F*************************************************************************/
  1248. static int
  1249. aic7xxx_setup(char *s)
  1250. {
  1251. int i, n;
  1252. char *p;
  1253. char *end;
  1254. static struct {
  1255. const char *name;
  1256. unsigned int *flag;
  1257. } options[] = {
  1258. { "extended", &aic7xxx_extended },
  1259. { "no_reset", &aic7xxx_no_reset },
  1260. { "irq_trigger", &aic7xxx_irq_trigger },
  1261. { "verbose", &aic7xxx_verbose },
  1262. { "reverse_scan",&aic7xxx_reverse_scan },
  1263. { "override_term", &aic7xxx_override_term },
  1264. { "stpwlev", &aic7xxx_stpwlev },
  1265. { "no_probe", &aic7xxx_no_probe },
  1266. { "panic_on_abort", &aic7xxx_panic_on_abort },
  1267. { "pci_parity", &aic7xxx_pci_parity },
  1268. { "dump_card", &aic7xxx_dump_card },
  1269. { "dump_sequencer", &aic7xxx_dump_sequencer },
  1270. { "default_queue_depth", &aic7xxx_default_queue_depth },
  1271. { "scbram", &aic7xxx_scbram },
  1272. { "seltime", &aic7xxx_seltime },
  1273. { "tag_info", NULL }
  1274. };
  1275. end = strchr(s, '\0');
  1276. while ((p = strsep(&s, ",.")) != NULL)
  1277. {
  1278. for (i = 0; i < ARRAY_SIZE(options); i++)
  1279. {
  1280. n = strlen(options[i].name);
  1281. if (!strncmp(options[i].name, p, n))
  1282. {
  1283. if (!strncmp(p, "tag_info", n))
  1284. {
  1285. if (p[n] == ':')
  1286. {
  1287. char *base;
  1288. char *tok, *tok_end, *tok_end2;
  1289. char tok_list[] = { '.', ',', '{', '}', '\0' };
  1290. int i, instance = -1, device = -1;
  1291. unsigned char done = FALSE;
  1292. base = p;
  1293. tok = base + n + 1; /* Forward us just past the ':' */
  1294. tok_end = strchr(tok, '\0');
  1295. if (tok_end < end)
  1296. *tok_end = ',';
  1297. while(!done)
  1298. {
  1299. switch(*tok)
  1300. {
  1301. case '{':
  1302. if (instance == -1)
  1303. instance = 0;
  1304. else if (device == -1)
  1305. device = 0;
  1306. tok++;
  1307. break;
  1308. case '}':
  1309. if (device != -1)
  1310. device = -1;
  1311. else if (instance != -1)
  1312. instance = -1;
  1313. tok++;
  1314. break;
  1315. case ',':
  1316. case '.':
  1317. if (instance == -1)
  1318. done = TRUE;
  1319. else if (device >= 0)
  1320. device++;
  1321. else if (instance >= 0)
  1322. instance++;
  1323. if ( (device >= MAX_TARGETS) ||
  1324. (instance >= ARRAY_SIZE(aic7xxx_tag_info)) )
  1325. done = TRUE;
  1326. tok++;
  1327. if (!done)
  1328. {
  1329. base = tok;
  1330. }
  1331. break;
  1332. case '\0':
  1333. done = TRUE;
  1334. break;
  1335. default:
  1336. done = TRUE;
  1337. tok_end = strchr(tok, '\0');
  1338. for(i=0; tok_list[i]; i++)
  1339. {
  1340. tok_end2 = strchr(tok, tok_list[i]);
  1341. if ( (tok_end2) && (tok_end2 < tok_end) )
  1342. {
  1343. tok_end = tok_end2;
  1344. done = FALSE;
  1345. }
  1346. }
  1347. if ( (instance >= 0) && (device >= 0) &&
  1348. (instance < ARRAY_SIZE(aic7xxx_tag_info)) &&
  1349. (device < MAX_TARGETS) )
  1350. aic7xxx_tag_info[instance].tag_commands[device] =
  1351. simple_strtoul(tok, NULL, 0) & 0xff;
  1352. tok = tok_end;
  1353. break;
  1354. }
  1355. }
  1356. while((p != base) && (p != NULL))
  1357. p = strsep(&s, ",.");
  1358. }
  1359. }
  1360. else if (p[n] == ':')
  1361. {
  1362. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1363. if(!strncmp(p, "seltime", n))
  1364. {
  1365. *(options[i].flag) = (*(options[i].flag) % 4) << 3;
  1366. }
  1367. }
  1368. else if (!strncmp(p, "verbose", n))
  1369. {
  1370. *(options[i].flag) = 0xff29;
  1371. }
  1372. else
  1373. {
  1374. *(options[i].flag) = ~(*(options[i].flag));
  1375. if(!strncmp(p, "seltime", n))
  1376. {
  1377. *(options[i].flag) = (*(options[i].flag) % 4) << 3;
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. return 1;
  1384. }
  1385. __setup("aic7xxx=", aic7xxx_setup);
  1386. /*+F*************************************************************************
  1387. * Function:
  1388. * pause_sequencer
  1389. *
  1390. * Description:
  1391. * Pause the sequencer and wait for it to actually stop - this
  1392. * is important since the sequencer can disable pausing for critical
  1393. * sections.
  1394. *-F*************************************************************************/
  1395. static void
  1396. pause_sequencer(struct aic7xxx_host *p)
  1397. {
  1398. aic_outb(p, p->pause, HCNTRL);
  1399. while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
  1400. {
  1401. ;
  1402. }
  1403. if(p->features & AHC_ULTRA2)
  1404. {
  1405. aic_inb(p, CCSCBCTL);
  1406. }
  1407. }
  1408. /*+F*************************************************************************
  1409. * Function:
  1410. * unpause_sequencer
  1411. *
  1412. * Description:
  1413. * Unpause the sequencer. Unremarkable, yet done often enough to
  1414. * warrant an easy way to do it.
  1415. *-F*************************************************************************/
  1416. static void
  1417. unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
  1418. {
  1419. if (unpause_always ||
  1420. ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
  1421. !(p->flags & AHC_HANDLING_REQINITS) ) )
  1422. {
  1423. aic_outb(p, p->unpause, HCNTRL);
  1424. }
  1425. }
  1426. /*+F*************************************************************************
  1427. * Function:
  1428. * restart_sequencer
  1429. *
  1430. * Description:
  1431. * Restart the sequencer program from address zero. This assumes
  1432. * that the sequencer is already paused.
  1433. *-F*************************************************************************/
  1434. static void
  1435. restart_sequencer(struct aic7xxx_host *p)
  1436. {
  1437. aic_outb(p, 0, SEQADDR0);
  1438. aic_outb(p, 0, SEQADDR1);
  1439. aic_outb(p, FASTMODE, SEQCTL);
  1440. }
  1441. /*
  1442. * We include the aic7xxx_seq.c file here so that the other defines have
  1443. * already been made, and so that it comes before the code that actually
  1444. * downloads the instructions (since we don't typically use function
  1445. * prototype, our code has to be ordered that way, it's a left-over from
  1446. * the original driver days.....I should fix it some time DL).
  1447. */
  1448. #include "aic7xxx_old/aic7xxx_seq.c"
  1449. /*+F*************************************************************************
  1450. * Function:
  1451. * aic7xxx_check_patch
  1452. *
  1453. * Description:
  1454. * See if the next patch to download should be downloaded.
  1455. *-F*************************************************************************/
  1456. static int
  1457. aic7xxx_check_patch(struct aic7xxx_host *p,
  1458. struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
  1459. {
  1460. struct sequencer_patch *cur_patch;
  1461. struct sequencer_patch *last_patch;
  1462. int num_patches;
  1463. num_patches = sizeof(sequencer_patches)/sizeof(struct sequencer_patch);
  1464. last_patch = &sequencer_patches[num_patches];
  1465. cur_patch = *start_patch;
  1466. while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
  1467. {
  1468. if (cur_patch->patch_func(p) == 0)
  1469. {
  1470. /*
  1471. * Start rejecting code.
  1472. */
  1473. *skip_addr = start_instr + cur_patch->skip_instr;
  1474. cur_patch += cur_patch->skip_patch;
  1475. }
  1476. else
  1477. {
  1478. /*
  1479. * Found an OK patch. Advance the patch pointer to the next patch
  1480. * and wait for our instruction pointer to get here.
  1481. */
  1482. cur_patch++;
  1483. }
  1484. }
  1485. *start_patch = cur_patch;
  1486. if (start_instr < *skip_addr)
  1487. /*
  1488. * Still skipping
  1489. */
  1490. return (0);
  1491. return(1);
  1492. }
  1493. /*+F*************************************************************************
  1494. * Function:
  1495. * aic7xxx_download_instr
  1496. *
  1497. * Description:
  1498. * Find the next patch to download.
  1499. *-F*************************************************************************/
  1500. static void
  1501. aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
  1502. unsigned char *dconsts)
  1503. {
  1504. union ins_formats instr;
  1505. struct ins_format1 *fmt1_ins;
  1506. struct ins_format3 *fmt3_ins;
  1507. unsigned char opcode;
  1508. instr = *(union ins_formats*) &seqprog[instrptr * 4];
  1509. instr.integer = le32_to_cpu(instr.integer);
  1510. fmt1_ins = &instr.format1;
  1511. fmt3_ins = NULL;
  1512. /* Pull the opcode */
  1513. opcode = instr.format1.opcode;
  1514. switch (opcode)
  1515. {
  1516. case AIC_OP_JMP:
  1517. case AIC_OP_JC:
  1518. case AIC_OP_JNC:
  1519. case AIC_OP_CALL:
  1520. case AIC_OP_JNE:
  1521. case AIC_OP_JNZ:
  1522. case AIC_OP_JE:
  1523. case AIC_OP_JZ:
  1524. {
  1525. struct sequencer_patch *cur_patch;
  1526. int address_offset;
  1527. unsigned int address;
  1528. int skip_addr;
  1529. int i;
  1530. fmt3_ins = &instr.format3;
  1531. address_offset = 0;
  1532. address = fmt3_ins->address;
  1533. cur_patch = sequencer_patches;
  1534. skip_addr = 0;
  1535. for (i = 0; i < address;)
  1536. {
  1537. aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
  1538. if (skip_addr > i)
  1539. {
  1540. int end_addr;
  1541. end_addr = min_t(int, address, skip_addr);
  1542. address_offset += end_addr - i;
  1543. i = skip_addr;
  1544. }
  1545. else
  1546. {
  1547. i++;
  1548. }
  1549. }
  1550. address -= address_offset;
  1551. fmt3_ins->address = address;
  1552. /* Fall Through to the next code section */
  1553. }
  1554. case AIC_OP_OR:
  1555. case AIC_OP_AND:
  1556. case AIC_OP_XOR:
  1557. case AIC_OP_ADD:
  1558. case AIC_OP_ADC:
  1559. case AIC_OP_BMOV:
  1560. if (fmt1_ins->parity != 0)
  1561. {
  1562. fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
  1563. }
  1564. fmt1_ins->parity = 0;
  1565. /* Fall Through to the next code section */
  1566. case AIC_OP_ROL:
  1567. if ((p->features & AHC_ULTRA2) != 0)
  1568. {
  1569. int i, count;
  1570. /* Calculate odd parity for the instruction */
  1571. for ( i=0, count=0; i < 31; i++)
  1572. {
  1573. unsigned int mask;
  1574. mask = 0x01 << i;
  1575. if ((instr.integer & mask) != 0)
  1576. count++;
  1577. }
  1578. if (!(count & 0x01))
  1579. instr.format1.parity = 1;
  1580. }
  1581. else
  1582. {
  1583. if (fmt3_ins != NULL)
  1584. {
  1585. instr.integer = fmt3_ins->immediate |
  1586. (fmt3_ins->source << 8) |
  1587. (fmt3_ins->address << 16) |
  1588. (fmt3_ins->opcode << 25);
  1589. }
  1590. else
  1591. {
  1592. instr.integer = fmt1_ins->immediate |
  1593. (fmt1_ins->source << 8) |
  1594. (fmt1_ins->destination << 16) |
  1595. (fmt1_ins->ret << 24) |
  1596. (fmt1_ins->opcode << 25);
  1597. }
  1598. }
  1599. aic_outb(p, (instr.integer & 0xff), SEQRAM);
  1600. aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
  1601. aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
  1602. aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
  1603. udelay(10);
  1604. break;
  1605. default:
  1606. panic("aic7xxx: Unknown opcode encountered in sequencer program.");
  1607. break;
  1608. }
  1609. }
  1610. /*+F*************************************************************************
  1611. * Function:
  1612. * aic7xxx_loadseq
  1613. *
  1614. * Description:
  1615. * Load the sequencer code into the controller memory.
  1616. *-F*************************************************************************/
  1617. static void
  1618. aic7xxx_loadseq(struct aic7xxx_host *p)
  1619. {
  1620. struct sequencer_patch *cur_patch;
  1621. int i;
  1622. int downloaded;
  1623. int skip_addr;
  1624. unsigned char download_consts[4] = {0, 0, 0, 0};
  1625. if (aic7xxx_verbose & VERBOSE_PROBE)
  1626. {
  1627. printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
  1628. }
  1629. #if 0
  1630. download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
  1631. #endif
  1632. download_consts[TMODE_NUMCMDS] = 0;
  1633. cur_patch = &sequencer_patches[0];
  1634. downloaded = 0;
  1635. skip_addr = 0;
  1636. aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
  1637. aic_outb(p, 0, SEQADDR0);
  1638. aic_outb(p, 0, SEQADDR1);
  1639. for (i = 0; i < sizeof(seqprog) / 4; i++)
  1640. {
  1641. if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
  1642. {
  1643. /* Skip this instruction for this configuration. */
  1644. continue;
  1645. }
  1646. aic7xxx_download_instr(p, i, &download_consts[0]);
  1647. downloaded++;
  1648. }
  1649. aic_outb(p, 0, SEQADDR0);
  1650. aic_outb(p, 0, SEQADDR1);
  1651. aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
  1652. unpause_sequencer(p, TRUE);
  1653. mdelay(1);
  1654. pause_sequencer(p);
  1655. aic_outb(p, FASTMODE, SEQCTL);
  1656. if (aic7xxx_verbose & VERBOSE_PROBE)
  1657. {
  1658. printk(" %d instructions downloaded\n", downloaded);
  1659. }
  1660. if (aic7xxx_dump_sequencer)
  1661. aic7xxx_print_sequencer(p, downloaded);
  1662. }
  1663. /*+F*************************************************************************
  1664. * Function:
  1665. * aic7xxx_print_sequencer
  1666. *
  1667. * Description:
  1668. * Print the contents of the sequencer memory to the screen.
  1669. *-F*************************************************************************/
  1670. static void
  1671. aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
  1672. {
  1673. int i, k, temp;
  1674. aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
  1675. aic_outb(p, 0, SEQADDR0);
  1676. aic_outb(p, 0, SEQADDR1);
  1677. k = 0;
  1678. for (i=0; i < downloaded; i++)
  1679. {
  1680. if ( k == 0 )
  1681. printk("%03x: ", i);
  1682. temp = aic_inb(p, SEQRAM);
  1683. temp |= (aic_inb(p, SEQRAM) << 8);
  1684. temp |= (aic_inb(p, SEQRAM) << 16);
  1685. temp |= (aic_inb(p, SEQRAM) << 24);
  1686. printk("%08x", temp);
  1687. if ( ++k == 8 )
  1688. {
  1689. printk("\n");
  1690. k = 0;
  1691. }
  1692. else
  1693. printk(" ");
  1694. }
  1695. aic_outb(p, 0, SEQADDR0);
  1696. aic_outb(p, 0, SEQADDR1);
  1697. aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
  1698. unpause_sequencer(p, TRUE);
  1699. mdelay(1);
  1700. pause_sequencer(p);
  1701. aic_outb(p, FASTMODE, SEQCTL);
  1702. printk("\n");
  1703. }
  1704. /*+F*************************************************************************
  1705. * Function:
  1706. * aic7xxx_info
  1707. *
  1708. * Description:
  1709. * Return a string describing the driver.
  1710. *-F*************************************************************************/
  1711. static const char *
  1712. aic7xxx_info(struct Scsi_Host *dooh)
  1713. {
  1714. static char buffer[256];
  1715. char *bp;
  1716. struct aic7xxx_host *p;
  1717. bp = &buffer[0];
  1718. p = (struct aic7xxx_host *)dooh->hostdata;
  1719. memset(bp, 0, sizeof(buffer));
  1720. strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
  1721. strcat(bp, AIC7XXX_C_VERSION);
  1722. strcat(bp, "/");
  1723. strcat(bp, AIC7XXX_H_VERSION);
  1724. strcat(bp, "\n");
  1725. strcat(bp, " <");
  1726. strcat(bp, board_names[p->board_name_index]);
  1727. strcat(bp, ">");
  1728. return(bp);
  1729. }
  1730. /*+F*************************************************************************
  1731. * Function:
  1732. * aic7xxx_find_syncrate
  1733. *
  1734. * Description:
  1735. * Look up the valid period to SCSIRATE conversion in our table
  1736. *-F*************************************************************************/
  1737. static struct aic7xxx_syncrate *
  1738. aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
  1739. unsigned int maxsync, unsigned char *options)
  1740. {
  1741. struct aic7xxx_syncrate *syncrate;
  1742. int done = FALSE;
  1743. switch(*options)
  1744. {
  1745. case MSG_EXT_PPR_OPTION_DT_CRC:
  1746. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1747. if(!(p->features & AHC_ULTRA3))
  1748. {
  1749. *options = 0;
  1750. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1751. }
  1752. break;
  1753. case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
  1754. case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
  1755. if(!(p->features & AHC_ULTRA3))
  1756. {
  1757. *options = 0;
  1758. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1759. }
  1760. else
  1761. {
  1762. /*
  1763. * we don't support the Quick Arbitration variants of dual edge
  1764. * clocking. As it turns out, we want to send back the
  1765. * same basic option, but without the QA attribute.
  1766. * We know that we are responding because we would never set
  1767. * these options ourself, we would only respond to them.
  1768. */
  1769. switch(*options)
  1770. {
  1771. case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
  1772. *options = MSG_EXT_PPR_OPTION_DT_CRC;
  1773. break;
  1774. case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
  1775. *options = MSG_EXT_PPR_OPTION_DT_UNITS;
  1776. break;
  1777. }
  1778. }
  1779. break;
  1780. default:
  1781. *options = 0;
  1782. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1783. break;
  1784. }
  1785. syncrate = &aic7xxx_syncrates[maxsync];
  1786. while ( (syncrate->rate[0] != NULL) &&
  1787. (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
  1788. {
  1789. if (*period <= syncrate->period)
  1790. {
  1791. switch(*options)
  1792. {
  1793. case MSG_EXT_PPR_OPTION_DT_CRC:
  1794. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1795. if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
  1796. {
  1797. done = TRUE;
  1798. /*
  1799. * oops, we went too low for the CRC/DualEdge signalling, so
  1800. * clear the options byte
  1801. */
  1802. *options = 0;
  1803. /*
  1804. * We'll be sending a reply to this packet to set the options
  1805. * properly, so unilaterally set the period as well.
  1806. */
  1807. *period = syncrate->period;
  1808. }
  1809. else
  1810. {
  1811. done = TRUE;
  1812. if(syncrate == &aic7xxx_syncrates[maxsync])
  1813. {
  1814. *period = syncrate->period;
  1815. }
  1816. }
  1817. break;
  1818. default:
  1819. if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
  1820. {
  1821. done = TRUE;
  1822. if(syncrate == &aic7xxx_syncrates[maxsync])
  1823. {
  1824. *period = syncrate->period;
  1825. }
  1826. }
  1827. break;
  1828. }
  1829. if(done)
  1830. {
  1831. break;
  1832. }
  1833. }
  1834. syncrate++;
  1835. }
  1836. if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
  1837. ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
  1838. {
  1839. /*
  1840. * Use async transfers for this target
  1841. */
  1842. *options = 0;
  1843. *period = 255;
  1844. syncrate = NULL;
  1845. }
  1846. return (syncrate);
  1847. }
  1848. /*+F*************************************************************************
  1849. * Function:
  1850. * aic7xxx_find_period
  1851. *
  1852. * Description:
  1853. * Look up the valid SCSIRATE to period conversion in our table
  1854. *-F*************************************************************************/
  1855. static unsigned int
  1856. aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
  1857. unsigned int maxsync)
  1858. {
  1859. struct aic7xxx_syncrate *syncrate;
  1860. if (p->features & AHC_ULTRA2)
  1861. {
  1862. scsirate &= SXFR_ULTRA2;
  1863. }
  1864. else
  1865. {
  1866. scsirate &= SXFR;
  1867. }
  1868. syncrate = &aic7xxx_syncrates[maxsync];
  1869. while (syncrate->rate[0] != NULL)
  1870. {
  1871. if (p->features & AHC_ULTRA2)
  1872. {
  1873. if (syncrate->sxfr_ultra2 == 0)
  1874. break;
  1875. else if (scsirate == syncrate->sxfr_ultra2)
  1876. return (syncrate->period);
  1877. else if (scsirate == (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC))
  1878. return (syncrate->period);
  1879. }
  1880. else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
  1881. {
  1882. return (syncrate->period);
  1883. }
  1884. syncrate++;
  1885. }
  1886. return (0); /* async */
  1887. }
  1888. /*+F*************************************************************************
  1889. * Function:
  1890. * aic7xxx_validate_offset
  1891. *
  1892. * Description:
  1893. * Set a valid offset value for a particular card in use and transfer
  1894. * settings in use.
  1895. *-F*************************************************************************/
  1896. static void
  1897. aic7xxx_validate_offset(struct aic7xxx_host *p,
  1898. struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
  1899. {
  1900. unsigned int maxoffset;
  1901. /* Limit offset to what the card (and device) can do */
  1902. if (syncrate == NULL)
  1903. {
  1904. maxoffset = 0;
  1905. }
  1906. else if (p->features & AHC_ULTRA2)
  1907. {
  1908. maxoffset = MAX_OFFSET_ULTRA2;
  1909. }
  1910. else
  1911. {
  1912. if (wide)
  1913. maxoffset = MAX_OFFSET_16BIT;
  1914. else
  1915. maxoffset = MAX_OFFSET_8BIT;
  1916. }
  1917. *offset = min(*offset, maxoffset);
  1918. }
  1919. /*+F*************************************************************************
  1920. * Function:
  1921. * aic7xxx_set_syncrate
  1922. *
  1923. * Description:
  1924. * Set the actual syncrate down in the card and in our host structs
  1925. *-F*************************************************************************/
  1926. static void
  1927. aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
  1928. int target, int channel, unsigned int period, unsigned int offset,
  1929. unsigned char options, unsigned int type, struct aic_dev_data *aic_dev)
  1930. {
  1931. unsigned char tindex;
  1932. unsigned short target_mask;
  1933. unsigned char lun, old_options;
  1934. unsigned int old_period, old_offset;
  1935. tindex = target | (channel << 3);
  1936. target_mask = 0x01 << tindex;
  1937. lun = aic_inb(p, SCB_TCL) & 0x07;
  1938. if (syncrate == NULL)
  1939. {
  1940. period = 0;
  1941. offset = 0;
  1942. }
  1943. old_period = aic_dev->cur.period;
  1944. old_offset = aic_dev->cur.offset;
  1945. old_options = aic_dev->cur.options;
  1946. if (type & AHC_TRANS_CUR)
  1947. {
  1948. unsigned int scsirate;
  1949. scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  1950. if (p->features & AHC_ULTRA2)
  1951. {
  1952. scsirate &= ~SXFR_ULTRA2;
  1953. if (syncrate != NULL)
  1954. {
  1955. switch(options)
  1956. {
  1957. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1958. /*
  1959. * mask off the CRC bit in the xfer settings
  1960. */
  1961. scsirate |= (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC);
  1962. break;
  1963. default:
  1964. scsirate |= syncrate->sxfr_ultra2;
  1965. break;
  1966. }
  1967. }
  1968. if (type & AHC_TRANS_ACTIVE)
  1969. {
  1970. aic_outb(p, offset, SCSIOFFSET);
  1971. }
  1972. aic_outb(p, offset, TARG_OFFSET + tindex);
  1973. }
  1974. else /* Not an Ultra2 controller */
  1975. {
  1976. scsirate &= ~(SXFR|SOFS);
  1977. p->ultraenb &= ~target_mask;
  1978. if (syncrate != NULL)
  1979. {
  1980. if (syncrate->sxfr & ULTRA_SXFR)
  1981. {
  1982. p->ultraenb |= target_mask;
  1983. }
  1984. scsirate |= (syncrate->sxfr & SXFR);
  1985. scsirate |= (offset & SOFS);
  1986. }
  1987. if (type & AHC_TRANS_ACTIVE)
  1988. {
  1989. unsigned char sxfrctl0;
  1990. sxfrctl0 = aic_inb(p, SXFRCTL0);
  1991. sxfrctl0 &= ~FAST20;
  1992. if (p->ultraenb & target_mask)
  1993. sxfrctl0 |= FAST20;
  1994. aic_outb(p, sxfrctl0, SXFRCTL0);
  1995. }
  1996. aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
  1997. aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
  1998. }
  1999. if (type & AHC_TRANS_ACTIVE)
  2000. {
  2001. aic_outb(p, scsirate, SCSIRATE);
  2002. }
  2003. aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
  2004. aic_dev->cur.period = period;
  2005. aic_dev->cur.offset = offset;
  2006. aic_dev->cur.options = options;
  2007. if ( !(type & AHC_TRANS_QUITE) &&
  2008. (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
  2009. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2010. {
  2011. if (offset)
  2012. {
  2013. int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
  2014. printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
  2015. "offset %d.\n", p->host_no, channel, target, lun,
  2016. syncrate->rate[rate_mod], offset);
  2017. }
  2018. else
  2019. {
  2020. printk(INFO_LEAD "Using asynchronous transfers.\n",
  2021. p->host_no, channel, target, lun);
  2022. }
  2023. aic_dev->flags &= ~DEVICE_PRINT_DTR;
  2024. }
  2025. }
  2026. if (type & AHC_TRANS_GOAL)
  2027. {
  2028. aic_dev->goal.period = period;
  2029. aic_dev->goal.offset = offset;
  2030. aic_dev->goal.options = options;
  2031. }
  2032. if (type & AHC_TRANS_USER)
  2033. {
  2034. p->user[tindex].period = period;
  2035. p->user[tindex].offset = offset;
  2036. p->user[tindex].options = options;
  2037. }
  2038. }
  2039. /*+F*************************************************************************
  2040. * Function:
  2041. * aic7xxx_set_width
  2042. *
  2043. * Description:
  2044. * Set the actual width down in the card and in our host structs
  2045. *-F*************************************************************************/
  2046. static void
  2047. aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
  2048. unsigned int width, unsigned int type, struct aic_dev_data *aic_dev)
  2049. {
  2050. unsigned char tindex;
  2051. unsigned short target_mask;
  2052. unsigned int old_width;
  2053. tindex = target | (channel << 3);
  2054. target_mask = 1 << tindex;
  2055. old_width = aic_dev->cur.width;
  2056. if (type & AHC_TRANS_CUR)
  2057. {
  2058. unsigned char scsirate;
  2059. scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  2060. scsirate &= ~WIDEXFER;
  2061. if (width == MSG_EXT_WDTR_BUS_16_BIT)
  2062. scsirate |= WIDEXFER;
  2063. aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
  2064. if (type & AHC_TRANS_ACTIVE)
  2065. aic_outb(p, scsirate, SCSIRATE);
  2066. aic_dev->cur.width = width;
  2067. if ( !(type & AHC_TRANS_QUITE) &&
  2068. (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2069. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2070. {
  2071. printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
  2072. lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
  2073. }
  2074. }
  2075. if (type & AHC_TRANS_GOAL)
  2076. aic_dev->goal.width = width;
  2077. if (type & AHC_TRANS_USER)
  2078. p->user[tindex].width = width;
  2079. if (aic_dev->goal.offset)
  2080. {
  2081. if (p->features & AHC_ULTRA2)
  2082. {
  2083. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  2084. }
  2085. else if (width == MSG_EXT_WDTR_BUS_16_BIT)
  2086. {
  2087. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  2088. }
  2089. else
  2090. {
  2091. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  2092. }
  2093. }
  2094. }
  2095. /*+F*************************************************************************
  2096. * Function:
  2097. * scbq_init
  2098. *
  2099. * Description:
  2100. * SCB queue initialization.
  2101. *
  2102. *-F*************************************************************************/
  2103. static void
  2104. scbq_init(volatile scb_queue_type *queue)
  2105. {
  2106. queue->head = NULL;
  2107. queue->tail = NULL;
  2108. }
  2109. /*+F*************************************************************************
  2110. * Function:
  2111. * scbq_insert_head
  2112. *
  2113. * Description:
  2114. * Add an SCB to the head of the list.
  2115. *
  2116. *-F*************************************************************************/
  2117. static inline void
  2118. scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2119. {
  2120. scb->q_next = queue->head;
  2121. queue->head = scb;
  2122. if (queue->tail == NULL) /* If list was empty, update tail. */
  2123. queue->tail = queue->head;
  2124. }
  2125. /*+F*************************************************************************
  2126. * Function:
  2127. * scbq_remove_head
  2128. *
  2129. * Description:
  2130. * Remove an SCB from the head of the list.
  2131. *
  2132. *-F*************************************************************************/
  2133. static inline struct aic7xxx_scb *
  2134. scbq_remove_head(volatile scb_queue_type *queue)
  2135. {
  2136. struct aic7xxx_scb * scbp;
  2137. scbp = queue->head;
  2138. if (queue->head != NULL)
  2139. queue->head = queue->head->q_next;
  2140. if (queue->head == NULL) /* If list is now empty, update tail. */
  2141. queue->tail = NULL;
  2142. return(scbp);
  2143. }
  2144. /*+F*************************************************************************
  2145. * Function:
  2146. * scbq_remove
  2147. *
  2148. * Description:
  2149. * Removes an SCB from the list.
  2150. *
  2151. *-F*************************************************************************/
  2152. static inline void
  2153. scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2154. {
  2155. if (queue->head == scb)
  2156. {
  2157. /* At beginning of queue, remove from head. */
  2158. scbq_remove_head(queue);
  2159. }
  2160. else
  2161. {
  2162. struct aic7xxx_scb *curscb = queue->head;
  2163. /*
  2164. * Search until the next scb is the one we're looking for, or
  2165. * we run out of queue.
  2166. */
  2167. while ((curscb != NULL) && (curscb->q_next != scb))
  2168. {
  2169. curscb = curscb->q_next;
  2170. }
  2171. if (curscb != NULL)
  2172. {
  2173. /* Found it. */
  2174. curscb->q_next = scb->q_next;
  2175. if (scb->q_next == NULL)
  2176. {
  2177. /* Update the tail when removing the tail. */
  2178. queue->tail = curscb;
  2179. }
  2180. }
  2181. }
  2182. }
  2183. /*+F*************************************************************************
  2184. * Function:
  2185. * scbq_insert_tail
  2186. *
  2187. * Description:
  2188. * Add an SCB at the tail of the list.
  2189. *
  2190. *-F*************************************************************************/
  2191. static inline void
  2192. scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2193. {
  2194. scb->q_next = NULL;
  2195. if (queue->tail != NULL) /* Add the scb at the end of the list. */
  2196. queue->tail->q_next = scb;
  2197. queue->tail = scb; /* Update the tail. */
  2198. if (queue->head == NULL) /* If list was empty, update head. */
  2199. queue->head = queue->tail;
  2200. }
  2201. /*+F*************************************************************************
  2202. * Function:
  2203. * aic7xxx_match_scb
  2204. *
  2205. * Description:
  2206. * Checks to see if an scb matches the target/channel as specified.
  2207. * If target is ALL_TARGETS (-1), then we're looking for any device
  2208. * on the specified channel; this happens when a channel is going
  2209. * to be reset and all devices on that channel must be aborted.
  2210. *-F*************************************************************************/
  2211. static int
  2212. aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
  2213. int target, int channel, int lun, unsigned char tag)
  2214. {
  2215. int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
  2216. int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
  2217. int slun = scb->hscb->target_channel_lun & 0x07;
  2218. int match;
  2219. match = ((chan == channel) || (channel == ALL_CHANNELS));
  2220. if (match != 0)
  2221. match = ((targ == target) || (target == ALL_TARGETS));
  2222. if (match != 0)
  2223. match = ((lun == slun) || (lun == ALL_LUNS));
  2224. if (match != 0)
  2225. match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
  2226. return (match);
  2227. }
  2228. /*+F*************************************************************************
  2229. * Function:
  2230. * aic7xxx_add_curscb_to_free_list
  2231. *
  2232. * Description:
  2233. * Adds the current scb (in SCBPTR) to the list of free SCBs.
  2234. *-F*************************************************************************/
  2235. static void
  2236. aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
  2237. {
  2238. /*
  2239. * Invalidate the tag so that aic7xxx_find_scb doesn't think
  2240. * it's active
  2241. */
  2242. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  2243. aic_outb(p, 0, SCB_CONTROL);
  2244. aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
  2245. aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
  2246. }
  2247. /*+F*************************************************************************
  2248. * Function:
  2249. * aic7xxx_rem_scb_from_disc_list
  2250. *
  2251. * Description:
  2252. * Removes the current SCB from the disconnected list and adds it
  2253. * to the free list.
  2254. *-F*************************************************************************/
  2255. static unsigned char
  2256. aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr,
  2257. unsigned char prev)
  2258. {
  2259. unsigned char next;
  2260. aic_outb(p, scbptr, SCBPTR);
  2261. next = aic_inb(p, SCB_NEXT);
  2262. aic7xxx_add_curscb_to_free_list(p);
  2263. if (prev != SCB_LIST_NULL)
  2264. {
  2265. aic_outb(p, prev, SCBPTR);
  2266. aic_outb(p, next, SCB_NEXT);
  2267. }
  2268. else
  2269. {
  2270. aic_outb(p, next, DISCONNECTED_SCBH);
  2271. }
  2272. return next;
  2273. }
  2274. /*+F*************************************************************************
  2275. * Function:
  2276. * aic7xxx_busy_target
  2277. *
  2278. * Description:
  2279. * Set the specified target busy.
  2280. *-F*************************************************************************/
  2281. static inline void
  2282. aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2283. {
  2284. p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
  2285. }
  2286. /*+F*************************************************************************
  2287. * Function:
  2288. * aic7xxx_index_busy_target
  2289. *
  2290. * Description:
  2291. * Returns the index of the busy target, and optionally sets the
  2292. * target inactive.
  2293. *-F*************************************************************************/
  2294. static inline unsigned char
  2295. aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
  2296. int unbusy)
  2297. {
  2298. unsigned char busy_scbid;
  2299. busy_scbid = p->untagged_scbs[tcl];
  2300. if (unbusy)
  2301. {
  2302. p->untagged_scbs[tcl] = SCB_LIST_NULL;
  2303. }
  2304. return (busy_scbid);
  2305. }
  2306. /*+F*************************************************************************
  2307. * Function:
  2308. * aic7xxx_find_scb
  2309. *
  2310. * Description:
  2311. * Look through the SCB array of the card and attempt to find the
  2312. * hardware SCB that corresponds to the passed in SCB. Return
  2313. * SCB_LIST_NULL if unsuccessful. This routine assumes that the
  2314. * card is already paused.
  2315. *-F*************************************************************************/
  2316. static unsigned char
  2317. aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2318. {
  2319. unsigned char saved_scbptr;
  2320. unsigned char curindex;
  2321. saved_scbptr = aic_inb(p, SCBPTR);
  2322. curindex = 0;
  2323. for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
  2324. {
  2325. aic_outb(p, curindex, SCBPTR);
  2326. if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
  2327. {
  2328. break;
  2329. }
  2330. }
  2331. aic_outb(p, saved_scbptr, SCBPTR);
  2332. if (curindex >= p->scb_data->maxhscbs)
  2333. {
  2334. curindex = SCB_LIST_NULL;
  2335. }
  2336. return (curindex);
  2337. }
  2338. /*+F*************************************************************************
  2339. * Function:
  2340. * aic7xxx_allocate_scb
  2341. *
  2342. * Description:
  2343. * Get an SCB from the free list or by allocating a new one.
  2344. *-F*************************************************************************/
  2345. static int
  2346. aic7xxx_allocate_scb(struct aic7xxx_host *p)
  2347. {
  2348. struct aic7xxx_scb *scbp = NULL;
  2349. int scb_size = (sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG) + 12 + 6;
  2350. int i;
  2351. int step = PAGE_SIZE / 1024;
  2352. unsigned long scb_count = 0;
  2353. struct hw_scatterlist *hsgp;
  2354. struct aic7xxx_scb *scb_ap;
  2355. struct aic7xxx_scb_dma *scb_dma;
  2356. unsigned char *bufs;
  2357. if (p->scb_data->numscbs < p->scb_data->maxscbs)
  2358. {
  2359. /*
  2360. * Calculate the optimal number of SCBs to allocate.
  2361. *
  2362. * NOTE: This formula works because the sizeof(sg_array) is always
  2363. * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
  2364. * (i/step). The (i-1) allows the left hand side of the equation
  2365. * to grow into the right hand side to a point of near perfect
  2366. * efficiency since scb_size * (i -1) is growing slightly faster
  2367. * than the right hand side. If the number of SG array elements
  2368. * is changed, this function may not be near so efficient any more.
  2369. *
  2370. * Since the DMA'able buffers are now allocated in a separate
  2371. * chunk this algorithm has been modified to match. The '12'
  2372. * and '6' factors in scb_size are for the DMA'able command byte
  2373. * and sensebuffers respectively. -DaveM
  2374. */
  2375. for ( i=step;; i *= 2 )
  2376. {
  2377. if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
  2378. {
  2379. i /= 2;
  2380. break;
  2381. }
  2382. }
  2383. scb_count = min( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
  2384. scb_ap = (struct aic7xxx_scb *)kmalloc(sizeof (struct aic7xxx_scb) * scb_count
  2385. + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC);
  2386. if (scb_ap == NULL)
  2387. return(0);
  2388. scb_dma = (struct aic7xxx_scb_dma *)&scb_ap[scb_count];
  2389. hsgp = (struct hw_scatterlist *)
  2390. pci_alloc_consistent(p->pdev, scb_size * scb_count,
  2391. &scb_dma->dma_address);
  2392. if (hsgp == NULL)
  2393. {
  2394. kfree(scb_ap);
  2395. return(0);
  2396. }
  2397. bufs = (unsigned char *)&hsgp[scb_count * AIC7XXX_MAX_SG];
  2398. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  2399. if (aic7xxx_verbose > 0xffff)
  2400. {
  2401. if (p->scb_data->numscbs == 0)
  2402. printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
  2403. p->host_no, -1, -1, -1, scb_count);
  2404. else
  2405. printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
  2406. p->host_no, -1, -1, -1, scb_count);
  2407. }
  2408. #endif
  2409. memset(scb_ap, 0, sizeof (struct aic7xxx_scb) * scb_count);
  2410. scb_dma->dma_offset = (unsigned long)scb_dma->dma_address
  2411. - (unsigned long)hsgp;
  2412. scb_dma->dma_len = scb_size * scb_count;
  2413. for (i=0; i < scb_count; i++)
  2414. {
  2415. scbp = &scb_ap[i];
  2416. scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
  2417. scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
  2418. scbp->sense_cmd = bufs;
  2419. scbp->cmnd = bufs + 6;
  2420. bufs += 12 + 6;
  2421. scbp->scb_dma = scb_dma;
  2422. memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
  2423. scbp->hscb->tag = p->scb_data->numscbs;
  2424. /*
  2425. * Place in the scb array; never is removed
  2426. */
  2427. p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
  2428. scbq_insert_tail(&p->scb_data->free_scbs, scbp);
  2429. }
  2430. scbp->kmalloc_ptr = scb_ap;
  2431. }
  2432. return(scb_count);
  2433. }
  2434. /*+F*************************************************************************
  2435. * Function:
  2436. * aic7xxx_queue_cmd_complete
  2437. *
  2438. * Description:
  2439. * Due to race conditions present in the SCSI subsystem, it is easier
  2440. * to queue completed commands, then call scsi_done() on them when
  2441. * we're finished. This function queues the completed commands.
  2442. *-F*************************************************************************/
  2443. static void
  2444. aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
  2445. {
  2446. aic7xxx_position(cmd) = SCB_LIST_NULL;
  2447. cmd->host_scribble = (char *)p->completeq.head;
  2448. p->completeq.head = cmd;
  2449. }
  2450. /*+F*************************************************************************
  2451. * Function:
  2452. * aic7xxx_done_cmds_complete
  2453. *
  2454. * Description:
  2455. * Process the completed command queue.
  2456. *-F*************************************************************************/
  2457. static void
  2458. aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
  2459. {
  2460. Scsi_Cmnd *cmd;
  2461. while (p->completeq.head != NULL)
  2462. {
  2463. cmd = p->completeq.head;
  2464. p->completeq.head = (Scsi_Cmnd *)cmd->host_scribble;
  2465. cmd->host_scribble = NULL;
  2466. cmd->scsi_done(cmd);
  2467. }
  2468. }
  2469. /*+F*************************************************************************
  2470. * Function:
  2471. * aic7xxx_free_scb
  2472. *
  2473. * Description:
  2474. * Free the scb and insert into the free scb list.
  2475. *-F*************************************************************************/
  2476. static void
  2477. aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2478. {
  2479. scb->flags = SCB_FREE;
  2480. scb->cmd = NULL;
  2481. scb->sg_count = 0;
  2482. scb->sg_length = 0;
  2483. scb->tag_action = 0;
  2484. scb->hscb->control = 0;
  2485. scb->hscb->target_status = 0;
  2486. scb->hscb->target_channel_lun = SCB_LIST_NULL;
  2487. scbq_insert_head(&p->scb_data->free_scbs, scb);
  2488. }
  2489. /*+F*************************************************************************
  2490. * Function:
  2491. * aic7xxx_done
  2492. *
  2493. * Description:
  2494. * Calls the higher level scsi done function and frees the scb.
  2495. *-F*************************************************************************/
  2496. static void
  2497. aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2498. {
  2499. Scsi_Cmnd *cmd = scb->cmd;
  2500. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  2501. int tindex = TARGET_INDEX(cmd);
  2502. struct aic7xxx_scb *scbp;
  2503. unsigned char queue_depth;
  2504. if (cmd->use_sg > 1)
  2505. {
  2506. struct scatterlist *sg;
  2507. sg = (struct scatterlist *)cmd->request_buffer;
  2508. pci_unmap_sg(p->pdev, sg, cmd->use_sg, cmd->sc_data_direction);
  2509. }
  2510. else if (cmd->request_bufflen)
  2511. pci_unmap_single(p->pdev, aic7xxx_mapping(cmd),
  2512. cmd->request_bufflen,
  2513. cmd->sc_data_direction);
  2514. if (scb->flags & SCB_SENSE)
  2515. {
  2516. pci_unmap_single(p->pdev,
  2517. le32_to_cpu(scb->sg_list[0].address),
  2518. sizeof(cmd->sense_buffer),
  2519. PCI_DMA_FROMDEVICE);
  2520. }
  2521. if (scb->flags & SCB_RECOVERY_SCB)
  2522. {
  2523. p->flags &= ~AHC_ABORT_PENDING;
  2524. }
  2525. if (scb->flags & (SCB_RESET|SCB_ABORT))
  2526. {
  2527. cmd->result |= (DID_RESET << 16);
  2528. }
  2529. if ((scb->flags & SCB_MSGOUT_BITS) != 0)
  2530. {
  2531. unsigned short mask;
  2532. int message_error = FALSE;
  2533. mask = 0x01 << tindex;
  2534. /*
  2535. * Check to see if we get an invalid message or a message error
  2536. * after failing to negotiate a wide or sync transfer message.
  2537. */
  2538. if ((scb->flags & SCB_SENSE) &&
  2539. ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
  2540. (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
  2541. {
  2542. message_error = TRUE;
  2543. }
  2544. if (scb->flags & SCB_MSGOUT_WDTR)
  2545. {
  2546. if (message_error)
  2547. {
  2548. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2549. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2550. {
  2551. printk(INFO_LEAD "Device failed to complete Wide Negotiation "
  2552. "processing and\n", p->host_no, CTL_OF_SCB(scb));
  2553. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2554. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2555. printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
  2556. CTL_OF_SCB(scb));
  2557. }
  2558. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  2559. }
  2560. }
  2561. if (scb->flags & SCB_MSGOUT_SDTR)
  2562. {
  2563. if (message_error)
  2564. {
  2565. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2566. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2567. {
  2568. printk(INFO_LEAD "Device failed to complete Sync Negotiation "
  2569. "processing and\n", p->host_no, CTL_OF_SCB(scb));
  2570. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2571. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2572. printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
  2573. CTL_OF_SCB(scb));
  2574. aic_dev->flags &= ~DEVICE_PRINT_DTR;
  2575. }
  2576. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  2577. }
  2578. }
  2579. if (scb->flags & SCB_MSGOUT_PPR)
  2580. {
  2581. if(message_error)
  2582. {
  2583. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2584. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2585. {
  2586. printk(INFO_LEAD "Device failed to complete Parallel Protocol "
  2587. "Request processing and\n", p->host_no, CTL_OF_SCB(scb));
  2588. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2589. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2590. printk(INFO_LEAD "Parallel Protocol Request negotiation to this "
  2591. "device.\n", p->host_no, CTL_OF_SCB(scb));
  2592. }
  2593. /*
  2594. * Disable PPR negotiation and revert back to WDTR and SDTR setup
  2595. */
  2596. aic_dev->needppr = aic_dev->needppr_copy = 0;
  2597. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  2598. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  2599. }
  2600. }
  2601. }
  2602. queue_depth = aic_dev->temp_q_depth;
  2603. if (queue_depth >= aic_dev->active_cmds)
  2604. {
  2605. scbp = scbq_remove_head(&aic_dev->delayed_scbs);
  2606. if (scbp)
  2607. {
  2608. if (queue_depth == 1)
  2609. {
  2610. /*
  2611. * Give extra preference to untagged devices, such as CD-R devices
  2612. * This makes it more likely that a drive *won't* stuff up while
  2613. * waiting on data at a critical time, such as CD-R writing and
  2614. * audio CD ripping operations. Should also benefit tape drives.
  2615. */
  2616. scbq_insert_head(&p->waiting_scbs, scbp);
  2617. }
  2618. else
  2619. {
  2620. scbq_insert_tail(&p->waiting_scbs, scbp);
  2621. }
  2622. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  2623. if (aic7xxx_verbose > 0xffff)
  2624. printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
  2625. p->host_no, CTL_OF_SCB(scbp));
  2626. #endif
  2627. if (queue_depth > aic_dev->active_cmds)
  2628. {
  2629. scbp = scbq_remove_head(&aic_dev->delayed_scbs);
  2630. if (scbp)
  2631. scbq_insert_tail(&p->waiting_scbs, scbp);
  2632. }
  2633. }
  2634. }
  2635. if (!(scb->tag_action))
  2636. {
  2637. aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun,
  2638. /* unbusy */ TRUE);
  2639. if (cmd->device->simple_tags)
  2640. {
  2641. aic_dev->temp_q_depth = aic_dev->max_q_depth;
  2642. }
  2643. }
  2644. if(scb->flags & SCB_DTR_SCB)
  2645. {
  2646. aic_dev->dtr_pending = 0;
  2647. }
  2648. aic_dev->active_cmds--;
  2649. p->activescbs--;
  2650. if ((scb->sg_length >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
  2651. {
  2652. long *ptr;
  2653. int x, i;
  2654. if (rq_data_dir(cmd->request) == WRITE)
  2655. {
  2656. aic_dev->w_total++;
  2657. ptr = aic_dev->w_bins;
  2658. }
  2659. else
  2660. {
  2661. aic_dev->r_total++;
  2662. ptr = aic_dev->r_bins;
  2663. }
  2664. if(cmd->device->simple_tags && cmd->request->flags & REQ_HARDBARRIER)
  2665. {
  2666. aic_dev->barrier_total++;
  2667. if(scb->tag_action == MSG_ORDERED_Q_TAG)
  2668. aic_dev->ordered_total++;
  2669. }
  2670. x = scb->sg_length;
  2671. x >>= 10;
  2672. for(i=0; i<6; i++)
  2673. {
  2674. x >>= 2;
  2675. if(!x) {
  2676. ptr[i]++;
  2677. break;
  2678. }
  2679. }
  2680. if(i == 6 && x)
  2681. ptr[5]++;
  2682. }
  2683. aic7xxx_free_scb(p, scb);
  2684. aic7xxx_queue_cmd_complete(p, cmd);
  2685. }
  2686. /*+F*************************************************************************
  2687. * Function:
  2688. * aic7xxx_run_done_queue
  2689. *
  2690. * Description:
  2691. * Calls the aic7xxx_done() for the Scsi_Cmnd of each scb in the
  2692. * aborted list, and adds each scb to the free list. If complete
  2693. * is TRUE, we also process the commands complete list.
  2694. *-F*************************************************************************/
  2695. static void
  2696. aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
  2697. {
  2698. struct aic7xxx_scb *scb;
  2699. int i, found = 0;
  2700. for (i = 0; i < p->scb_data->numscbs; i++)
  2701. {
  2702. scb = p->scb_data->scb_array[i];
  2703. if (scb->flags & SCB_QUEUED_FOR_DONE)
  2704. {
  2705. if (scb->flags & SCB_QUEUE_FULL)
  2706. {
  2707. scb->cmd->result = QUEUE_FULL << 1;
  2708. }
  2709. else
  2710. {
  2711. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2712. printk(INFO_LEAD "Aborting scb %d\n",
  2713. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
  2714. /*
  2715. * Clear any residual information since the normal aic7xxx_done() path
  2716. * doesn't touch the residuals.
  2717. */
  2718. scb->hscb->residual_SG_segment_count = 0;
  2719. scb->hscb->residual_data_count[0] = 0;
  2720. scb->hscb->residual_data_count[1] = 0;
  2721. scb->hscb->residual_data_count[2] = 0;
  2722. }
  2723. found++;
  2724. aic7xxx_done(p, scb);
  2725. }
  2726. }
  2727. if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
  2728. {
  2729. printk(INFO_LEAD "%d commands found and queued for "
  2730. "completion.\n", p->host_no, -1, -1, -1, found);
  2731. }
  2732. if (complete)
  2733. {
  2734. aic7xxx_done_cmds_complete(p);
  2735. }
  2736. }
  2737. /*+F*************************************************************************
  2738. * Function:
  2739. * aic7xxx_abort_waiting_scb
  2740. *
  2741. * Description:
  2742. * Manipulate the waiting for selection list and return the
  2743. * scb that follows the one that we remove.
  2744. *-F*************************************************************************/
  2745. static unsigned char
  2746. aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
  2747. unsigned char scbpos, unsigned char prev)
  2748. {
  2749. unsigned char curscb, next;
  2750. /*
  2751. * Select the SCB we want to abort and pull the next pointer out of it.
  2752. */
  2753. curscb = aic_inb(p, SCBPTR);
  2754. aic_outb(p, scbpos, SCBPTR);
  2755. next = aic_inb(p, SCB_NEXT);
  2756. aic7xxx_add_curscb_to_free_list(p);
  2757. /*
  2758. * Update the waiting list
  2759. */
  2760. if (prev == SCB_LIST_NULL)
  2761. {
  2762. /*
  2763. * First in the list
  2764. */
  2765. aic_outb(p, next, WAITING_SCBH);
  2766. }
  2767. else
  2768. {
  2769. /*
  2770. * Select the scb that pointed to us and update its next pointer.
  2771. */
  2772. aic_outb(p, prev, SCBPTR);
  2773. aic_outb(p, next, SCB_NEXT);
  2774. }
  2775. /*
  2776. * Point us back at the original scb position and inform the SCSI
  2777. * system that the command has been aborted.
  2778. */
  2779. aic_outb(p, curscb, SCBPTR);
  2780. return (next);
  2781. }
  2782. /*+F*************************************************************************
  2783. * Function:
  2784. * aic7xxx_search_qinfifo
  2785. *
  2786. * Description:
  2787. * Search the queue-in FIFO for matching SCBs and conditionally
  2788. * requeue. Returns the number of matching SCBs.
  2789. *-F*************************************************************************/
  2790. static int
  2791. aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
  2792. int lun, unsigned char tag, int flags, int requeue,
  2793. volatile scb_queue_type *queue)
  2794. {
  2795. int found;
  2796. unsigned char qinpos, qintail;
  2797. struct aic7xxx_scb *scbp;
  2798. found = 0;
  2799. qinpos = aic_inb(p, QINPOS);
  2800. qintail = p->qinfifonext;
  2801. p->qinfifonext = qinpos;
  2802. while (qinpos != qintail)
  2803. {
  2804. scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
  2805. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  2806. {
  2807. /*
  2808. * We found an scb that needs to be removed.
  2809. */
  2810. if (requeue && (queue != NULL))
  2811. {
  2812. if (scbp->flags & SCB_WAITINGQ)
  2813. {
  2814. scbq_remove(queue, scbp);
  2815. scbq_remove(&p->waiting_scbs, scbp);
  2816. scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
  2817. AIC_DEV(scbp->cmd)->active_cmds++;
  2818. p->activescbs++;
  2819. }
  2820. scbq_insert_tail(queue, scbp);
  2821. AIC_DEV(scbp->cmd)->active_cmds--;
  2822. p->activescbs--;
  2823. scbp->flags |= SCB_WAITINGQ;
  2824. if ( !(scbp->tag_action & TAG_ENB) )
  2825. {
  2826. aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2827. TRUE);
  2828. }
  2829. }
  2830. else if (requeue)
  2831. {
  2832. p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
  2833. }
  2834. else
  2835. {
  2836. /*
  2837. * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
  2838. * flags we were called with, presumeably so aic7xxx_run_done_queue
  2839. * can find this scb
  2840. */
  2841. scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
  2842. if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2843. FALSE) == scbp->hscb->tag)
  2844. {
  2845. aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2846. TRUE);
  2847. }
  2848. }
  2849. found++;
  2850. }
  2851. else
  2852. {
  2853. p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
  2854. }
  2855. }
  2856. /*
  2857. * Now that we've done the work, clear out any left over commands in the
  2858. * qinfifo and update the KERNEL_QINPOS down on the card.
  2859. *
  2860. * NOTE: This routine expect the sequencer to already be paused when
  2861. * it is run....make sure it's that way!
  2862. */
  2863. qinpos = p->qinfifonext;
  2864. while(qinpos != qintail)
  2865. {
  2866. p->qinfifo[qinpos++] = SCB_LIST_NULL;
  2867. }
  2868. if (p->features & AHC_QUEUE_REGS)
  2869. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  2870. else
  2871. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  2872. return (found);
  2873. }
  2874. /*+F*************************************************************************
  2875. * Function:
  2876. * aic7xxx_scb_on_qoutfifo
  2877. *
  2878. * Description:
  2879. * Is the scb that was passed to us currently on the qoutfifo?
  2880. *-F*************************************************************************/
  2881. static int
  2882. aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2883. {
  2884. int i=0;
  2885. while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
  2886. {
  2887. if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
  2888. return TRUE;
  2889. else
  2890. i++;
  2891. }
  2892. return FALSE;
  2893. }
  2894. /*+F*************************************************************************
  2895. * Function:
  2896. * aic7xxx_reset_device
  2897. *
  2898. * Description:
  2899. * The device at the given target/channel has been reset. Abort
  2900. * all active and queued scbs for that target/channel. This function
  2901. * need not worry about linked next pointers because if was a MSG_ABORT_TAG
  2902. * then we had a tagged command (no linked next), if it was MSG_ABORT or
  2903. * MSG_BUS_DEV_RESET then the device won't know about any commands any more
  2904. * and no busy commands will exist, and if it was a bus reset, then nothing
  2905. * knows about any linked next commands any more. In all cases, we don't
  2906. * need to worry about the linked next or busy scb, we just need to clear
  2907. * them.
  2908. *-F*************************************************************************/
  2909. static void
  2910. aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
  2911. int lun, unsigned char tag)
  2912. {
  2913. struct aic7xxx_scb *scbp, *prev_scbp;
  2914. struct scsi_device *sd;
  2915. unsigned char active_scb, tcl, scb_tag;
  2916. int i = 0, init_lists = FALSE;
  2917. struct aic_dev_data *aic_dev;
  2918. /*
  2919. * Restore this when we're done
  2920. */
  2921. active_scb = aic_inb(p, SCBPTR);
  2922. scb_tag = aic_inb(p, SCB_TAG);
  2923. if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
  2924. {
  2925. printk(INFO_LEAD "Reset device, hardware_scb %d,\n",
  2926. p->host_no, channel, target, lun, active_scb);
  2927. printk(INFO_LEAD "Current scb %d, SEQADDR 0x%x, LASTPHASE "
  2928. "0x%x\n",
  2929. p->host_no, channel, target, lun, scb_tag,
  2930. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  2931. aic_inb(p, LASTPHASE));
  2932. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  2933. p->host_no, channel, target, lun,
  2934. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  2935. aic_inb(p, SG_COUNT), aic_inb(p, SCSISIGI));
  2936. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  2937. p->host_no, channel, target, lun, aic_inb(p, SSTAT0),
  2938. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  2939. }
  2940. /*
  2941. * Deal with the busy target and linked next issues.
  2942. */
  2943. list_for_each_entry(aic_dev, &p->aic_devs, list)
  2944. {
  2945. if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
  2946. printk(INFO_LEAD "processing aic_dev %p\n", p->host_no, channel, target,
  2947. lun, aic_dev);
  2948. sd = aic_dev->SDptr;
  2949. if((target != ALL_TARGETS && target != sd->id) ||
  2950. (channel != ALL_CHANNELS && channel != sd->channel))
  2951. continue;
  2952. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2953. printk(INFO_LEAD "Cleaning up status information "
  2954. "and delayed_scbs.\n", p->host_no, sd->channel, sd->id, sd->lun);
  2955. aic_dev->flags &= ~BUS_DEVICE_RESET_PENDING;
  2956. if ( tag == SCB_LIST_NULL )
  2957. {
  2958. aic_dev->dtr_pending = 0;
  2959. aic_dev->needppr = aic_dev->needppr_copy;
  2960. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  2961. aic_dev->needwdtr = aic_dev->needwdtr_copy;
  2962. aic_dev->flags = DEVICE_PRINT_DTR;
  2963. aic_dev->temp_q_depth = aic_dev->max_q_depth;
  2964. }
  2965. tcl = (sd->id << 4) | (sd->channel << 3) | sd->lun;
  2966. if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
  2967. (tag == SCB_LIST_NULL) )
  2968. aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
  2969. prev_scbp = NULL;
  2970. scbp = aic_dev->delayed_scbs.head;
  2971. while (scbp != NULL)
  2972. {
  2973. prev_scbp = scbp;
  2974. scbp = scbp->q_next;
  2975. if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
  2976. {
  2977. scbq_remove(&aic_dev->delayed_scbs, prev_scbp);
  2978. if (prev_scbp->flags & SCB_WAITINGQ)
  2979. {
  2980. aic_dev->active_cmds++;
  2981. p->activescbs++;
  2982. }
  2983. prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  2984. prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  2985. }
  2986. }
  2987. }
  2988. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2989. printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
  2990. aic7xxx_search_qinfifo(p, target, channel, lun, tag,
  2991. SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
  2992. /*
  2993. * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
  2994. * ABORT/RESET commands.
  2995. */
  2996. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2997. printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
  2998. target, lun );
  2999. {
  3000. struct aic7xxx_scb *scbp, *prev_scbp;
  3001. prev_scbp = NULL;
  3002. scbp = p->waiting_scbs.head;
  3003. while (scbp != NULL)
  3004. {
  3005. prev_scbp = scbp;
  3006. scbp = scbp->q_next;
  3007. if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
  3008. {
  3009. scbq_remove(&p->waiting_scbs, prev_scbp);
  3010. if (prev_scbp->flags & SCB_WAITINGQ)
  3011. {
  3012. AIC_DEV(prev_scbp->cmd)->active_cmds++;
  3013. p->activescbs++;
  3014. }
  3015. prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3016. prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3017. }
  3018. }
  3019. }
  3020. /*
  3021. * Search waiting for selection list.
  3022. */
  3023. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  3024. printk(INFO_LEAD "Cleaning waiting for selection "
  3025. "list.\n", p->host_no, channel, target, lun);
  3026. {
  3027. unsigned char next, prev, scb_index;
  3028. next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
  3029. prev = SCB_LIST_NULL;
  3030. while (next != SCB_LIST_NULL)
  3031. {
  3032. aic_outb(p, next, SCBPTR);
  3033. scb_index = aic_inb(p, SCB_TAG);
  3034. if (scb_index >= p->scb_data->numscbs)
  3035. {
  3036. /*
  3037. * No aic7xxx_verbose check here.....we want to see this since it
  3038. * means either the kernel driver or the sequencer screwed things up
  3039. */
  3040. printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
  3041. "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
  3042. p->scb_data->numscbs);
  3043. next = aic_inb(p, SCB_NEXT);
  3044. aic7xxx_add_curscb_to_free_list(p);
  3045. }
  3046. else
  3047. {
  3048. scbp = p->scb_data->scb_array[scb_index];
  3049. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3050. {
  3051. next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
  3052. if (scbp->flags & SCB_WAITINGQ)
  3053. {
  3054. AIC_DEV(scbp->cmd)->active_cmds++;
  3055. p->activescbs++;
  3056. }
  3057. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3058. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3059. if (prev == SCB_LIST_NULL)
  3060. {
  3061. /*
  3062. * This is either the first scb on the waiting list, or we
  3063. * have already yanked the first and haven't left any behind.
  3064. * Either way, we need to turn off the selection hardware if
  3065. * it isn't already off.
  3066. */
  3067. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  3068. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  3069. }
  3070. }
  3071. else
  3072. {
  3073. prev = next;
  3074. next = aic_inb(p, SCB_NEXT);
  3075. }
  3076. }
  3077. }
  3078. }
  3079. /*
  3080. * Go through disconnected list and remove any entries we have queued
  3081. * for completion, zeroing their control byte too.
  3082. */
  3083. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  3084. printk(INFO_LEAD "Cleaning disconnected scbs "
  3085. "list.\n", p->host_no, channel, target, lun);
  3086. if (p->flags & AHC_PAGESCBS)
  3087. {
  3088. unsigned char next, prev, scb_index;
  3089. next = aic_inb(p, DISCONNECTED_SCBH);
  3090. prev = SCB_LIST_NULL;
  3091. while (next != SCB_LIST_NULL)
  3092. {
  3093. aic_outb(p, next, SCBPTR);
  3094. scb_index = aic_inb(p, SCB_TAG);
  3095. if (scb_index > p->scb_data->numscbs)
  3096. {
  3097. printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
  3098. "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
  3099. p->scb_data->numscbs);
  3100. next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
  3101. }
  3102. else
  3103. {
  3104. scbp = p->scb_data->scb_array[scb_index];
  3105. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3106. {
  3107. next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
  3108. if (scbp->flags & SCB_WAITINGQ)
  3109. {
  3110. AIC_DEV(scbp->cmd)->active_cmds++;
  3111. p->activescbs++;
  3112. }
  3113. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3114. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3115. scbp->hscb->control = 0;
  3116. }
  3117. else
  3118. {
  3119. prev = next;
  3120. next = aic_inb(p, SCB_NEXT);
  3121. }
  3122. }
  3123. }
  3124. }
  3125. /*
  3126. * Walk the free list making sure no entries on the free list have
  3127. * a valid SCB_TAG value or SCB_CONTROL byte.
  3128. */
  3129. if (p->flags & AHC_PAGESCBS)
  3130. {
  3131. unsigned char next;
  3132. next = aic_inb(p, FREE_SCBH);
  3133. while (next != SCB_LIST_NULL)
  3134. {
  3135. aic_outb(p, next, SCBPTR);
  3136. if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
  3137. {
  3138. printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
  3139. target, lun);
  3140. init_lists = TRUE;
  3141. next = SCB_LIST_NULL;
  3142. }
  3143. else
  3144. {
  3145. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3146. aic_outb(p, 0, SCB_CONTROL);
  3147. next = aic_inb(p, SCB_NEXT);
  3148. }
  3149. }
  3150. }
  3151. /*
  3152. * Go through the hardware SCB array looking for commands that
  3153. * were active but not on any list.
  3154. */
  3155. if (init_lists)
  3156. {
  3157. aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
  3158. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  3159. aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
  3160. }
  3161. for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
  3162. {
  3163. unsigned char scbid;
  3164. aic_outb(p, i, SCBPTR);
  3165. if (init_lists)
  3166. {
  3167. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3168. aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
  3169. aic_outb(p, 0, SCB_CONTROL);
  3170. aic7xxx_add_curscb_to_free_list(p);
  3171. }
  3172. else
  3173. {
  3174. scbid = aic_inb(p, SCB_TAG);
  3175. if (scbid < p->scb_data->numscbs)
  3176. {
  3177. scbp = p->scb_data->scb_array[scbid];
  3178. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3179. {
  3180. aic_outb(p, 0, SCB_CONTROL);
  3181. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3182. aic7xxx_add_curscb_to_free_list(p);
  3183. }
  3184. }
  3185. }
  3186. }
  3187. /*
  3188. * Go through the entire SCB array now and look for commands for
  3189. * for this target that are stillactive. These are other (most likely
  3190. * tagged) commands that were disconnected when the reset occurred.
  3191. * Any commands we find here we know this about, it wasn't on any queue,
  3192. * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
  3193. * lists, so it really must have been a paged out SCB. In that case,
  3194. * we shouldn't need to bother with updating any counters, just mark
  3195. * the correct flags and go on.
  3196. */
  3197. for (i = 0; i < p->scb_data->numscbs; i++)
  3198. {
  3199. scbp = p->scb_data->scb_array[i];
  3200. if ((scbp->flags & SCB_ACTIVE) &&
  3201. aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
  3202. !aic7xxx_scb_on_qoutfifo(p, scbp))
  3203. {
  3204. if (scbp->flags & SCB_WAITINGQ)
  3205. {
  3206. scbq_remove(&p->waiting_scbs, scbp);
  3207. scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
  3208. AIC_DEV(scbp->cmd)->active_cmds++;
  3209. p->activescbs++;
  3210. }
  3211. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3212. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3213. }
  3214. }
  3215. aic_outb(p, active_scb, SCBPTR);
  3216. }
  3217. /*+F*************************************************************************
  3218. * Function:
  3219. * aic7xxx_clear_intstat
  3220. *
  3221. * Description:
  3222. * Clears the interrupt status.
  3223. *-F*************************************************************************/
  3224. static void
  3225. aic7xxx_clear_intstat(struct aic7xxx_host *p)
  3226. {
  3227. /* Clear any interrupt conditions this may have caused. */
  3228. aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
  3229. aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
  3230. CLRPHASECHG | CLRREQINIT, CLRSINT1);
  3231. aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
  3232. }
  3233. /*+F*************************************************************************
  3234. * Function:
  3235. * aic7xxx_reset_current_bus
  3236. *
  3237. * Description:
  3238. * Reset the current SCSI bus.
  3239. *-F*************************************************************************/
  3240. static void
  3241. aic7xxx_reset_current_bus(struct aic7xxx_host *p)
  3242. {
  3243. /* Disable reset interrupts. */
  3244. aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
  3245. /* Turn off the bus' current operations, after all, we shouldn't have any
  3246. * valid commands left to cause a RSELI and SELO once we've tossed the
  3247. * bus away with this reset, so we might as well shut down the sequencer
  3248. * until the bus is restarted as oppossed to saving the current settings
  3249. * and restoring them (which makes no sense to me). */
  3250. /* Turn on the bus reset. */
  3251. aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
  3252. while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
  3253. mdelay(5);
  3254. /*
  3255. * Some of the new Ultra2 chipsets need a longer delay after a chip
  3256. * reset than just the init setup creates, so we have to delay here
  3257. * before we go into a reset in order to make the chips happy.
  3258. */
  3259. if (p->features & AHC_ULTRA2)
  3260. mdelay(250);
  3261. else
  3262. mdelay(50);
  3263. /* Turn off the bus reset. */
  3264. aic_outb(p, 0, SCSISEQ);
  3265. mdelay(10);
  3266. aic7xxx_clear_intstat(p);
  3267. /* Re-enable reset interrupts. */
  3268. aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
  3269. }
  3270. /*+F*************************************************************************
  3271. * Function:
  3272. * aic7xxx_reset_channel
  3273. *
  3274. * Description:
  3275. * Reset the channel.
  3276. *-F*************************************************************************/
  3277. static void
  3278. aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
  3279. {
  3280. unsigned long offset_min, offset_max;
  3281. unsigned char sblkctl;
  3282. int cur_channel;
  3283. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3284. printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
  3285. p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
  3286. if (channel == 1)
  3287. {
  3288. offset_min = 8;
  3289. offset_max = 16;
  3290. }
  3291. else
  3292. {
  3293. if (p->features & AHC_TWIN)
  3294. {
  3295. /* Channel A */
  3296. offset_min = 0;
  3297. offset_max = 8;
  3298. }
  3299. else
  3300. {
  3301. offset_min = 0;
  3302. if (p->features & AHC_WIDE)
  3303. {
  3304. offset_max = 16;
  3305. }
  3306. else
  3307. {
  3308. offset_max = 8;
  3309. }
  3310. }
  3311. }
  3312. while (offset_min < offset_max)
  3313. {
  3314. /*
  3315. * Revert to async/narrow transfers until we renegotiate.
  3316. */
  3317. aic_outb(p, 0, TARG_SCSIRATE + offset_min);
  3318. if (p->features & AHC_ULTRA2)
  3319. {
  3320. aic_outb(p, 0, TARG_OFFSET + offset_min);
  3321. }
  3322. offset_min++;
  3323. }
  3324. /*
  3325. * Reset the bus and unpause/restart the controller
  3326. */
  3327. sblkctl = aic_inb(p, SBLKCTL);
  3328. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  3329. cur_channel = (sblkctl & SELBUSB) >> 3;
  3330. else
  3331. cur_channel = 0;
  3332. if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
  3333. {
  3334. /*
  3335. * Case 1: Command for another bus is active
  3336. */
  3337. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3338. printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
  3339. channel, -1, -1);
  3340. /*
  3341. * Stealthily reset the other bus without upsetting the current bus.
  3342. */
  3343. aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
  3344. aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
  3345. if (initiate_reset)
  3346. {
  3347. aic7xxx_reset_current_bus(p);
  3348. }
  3349. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
  3350. aic7xxx_clear_intstat(p);
  3351. aic_outb(p, sblkctl, SBLKCTL);
  3352. }
  3353. else
  3354. {
  3355. /*
  3356. * Case 2: A command from this bus is active or we're idle.
  3357. */
  3358. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3359. printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
  3360. channel, -1, -1);
  3361. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
  3362. SIMODE1);
  3363. p->flags &= ~AHC_HANDLING_REQINITS;
  3364. p->msg_type = MSG_TYPE_NONE;
  3365. p->msg_len = 0;
  3366. if (initiate_reset)
  3367. {
  3368. aic7xxx_reset_current_bus(p);
  3369. }
  3370. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
  3371. aic7xxx_clear_intstat(p);
  3372. }
  3373. if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
  3374. printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
  3375. /*
  3376. * Clean up all the state information for the pending transactions
  3377. * on this bus.
  3378. */
  3379. aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
  3380. if ( !(p->features & AHC_TWIN) )
  3381. {
  3382. restart_sequencer(p);
  3383. }
  3384. return;
  3385. }
  3386. /*+F*************************************************************************
  3387. * Function:
  3388. * aic7xxx_run_waiting_queues
  3389. *
  3390. * Description:
  3391. * Scan the awaiting_scbs queue downloading and starting as many
  3392. * scbs as we can.
  3393. *-F*************************************************************************/
  3394. static void
  3395. aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
  3396. {
  3397. struct aic7xxx_scb *scb;
  3398. struct aic_dev_data *aic_dev;
  3399. int sent;
  3400. if (p->waiting_scbs.head == NULL)
  3401. return;
  3402. sent = 0;
  3403. /*
  3404. * First handle SCBs that are waiting but have been assigned a slot.
  3405. */
  3406. while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
  3407. {
  3408. aic_dev = scb->cmd->device->hostdata;
  3409. if ( !scb->tag_action )
  3410. {
  3411. aic_dev->temp_q_depth = 1;
  3412. }
  3413. if ( aic_dev->active_cmds >= aic_dev->temp_q_depth)
  3414. {
  3415. scbq_insert_tail(&aic_dev->delayed_scbs, scb);
  3416. }
  3417. else
  3418. {
  3419. scb->flags &= ~SCB_WAITINGQ;
  3420. aic_dev->active_cmds++;
  3421. p->activescbs++;
  3422. if ( !(scb->tag_action) )
  3423. {
  3424. aic7xxx_busy_target(p, scb);
  3425. }
  3426. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  3427. sent++;
  3428. }
  3429. }
  3430. if (sent)
  3431. {
  3432. if (p->features & AHC_QUEUE_REGS)
  3433. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  3434. else
  3435. {
  3436. pause_sequencer(p);
  3437. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  3438. unpause_sequencer(p, FALSE);
  3439. }
  3440. if (p->activescbs > p->max_activescbs)
  3441. p->max_activescbs = p->activescbs;
  3442. }
  3443. }
  3444. #ifdef CONFIG_PCI
  3445. #define DPE 0x80
  3446. #define SSE 0x40
  3447. #define RMA 0x20
  3448. #define RTA 0x10
  3449. #define STA 0x08
  3450. #define DPR 0x01
  3451. /*+F*************************************************************************
  3452. * Function:
  3453. * aic7xxx_pci_intr
  3454. *
  3455. * Description:
  3456. * Check the scsi card for PCI errors and clear the interrupt
  3457. *
  3458. * NOTE: If you don't have this function and a 2940 card encounters
  3459. * a PCI error condition, the machine will end up locked as the
  3460. * interrupt handler gets slammed with non-stop PCI error interrupts
  3461. *-F*************************************************************************/
  3462. static void
  3463. aic7xxx_pci_intr(struct aic7xxx_host *p)
  3464. {
  3465. unsigned char status1;
  3466. pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
  3467. if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3468. printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
  3469. "phase.\n", p->host_no, -1, -1, -1);
  3470. if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3471. printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
  3472. -1, -1, -1);
  3473. if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3474. printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
  3475. -1, -1, -1);
  3476. if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3477. printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
  3478. -1, -1, -1);
  3479. if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3480. printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
  3481. -1, -1, -1);
  3482. if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3483. printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
  3484. "PERR#\n", p->host_no, -1, -1, -1);
  3485. pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
  3486. if (status1 & (DPR|RMA|RTA))
  3487. aic_outb(p, CLRPARERR, CLRINT);
  3488. if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
  3489. aic7xxx_panic_abort(p, NULL);
  3490. }
  3491. #endif /* CONFIG_PCI */
  3492. /*+F*************************************************************************
  3493. * Function:
  3494. * aic7xxx_construct_ppr
  3495. *
  3496. * Description:
  3497. * Build up a Parallel Protocol Request message for use with SCSI-3
  3498. * devices.
  3499. *-F*************************************************************************/
  3500. static void
  3501. aic7xxx_construct_ppr(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  3502. {
  3503. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3504. p->msg_buf[p->msg_index++] = MSG_EXT_PPR_LEN;
  3505. p->msg_buf[p->msg_index++] = MSG_EXT_PPR;
  3506. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.period;
  3507. p->msg_buf[p->msg_index++] = 0;
  3508. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.offset;
  3509. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.width;
  3510. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.options;
  3511. p->msg_len += 8;
  3512. }
  3513. /*+F*************************************************************************
  3514. * Function:
  3515. * aic7xxx_construct_sdtr
  3516. *
  3517. * Description:
  3518. * Constucts a synchronous data transfer message in the message
  3519. * buffer on the sequencer.
  3520. *-F*************************************************************************/
  3521. static void
  3522. aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
  3523. unsigned char offset)
  3524. {
  3525. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3526. p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
  3527. p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
  3528. p->msg_buf[p->msg_index++] = period;
  3529. p->msg_buf[p->msg_index++] = offset;
  3530. p->msg_len += 5;
  3531. }
  3532. /*+F*************************************************************************
  3533. * Function:
  3534. * aic7xxx_construct_wdtr
  3535. *
  3536. * Description:
  3537. * Constucts a wide data transfer message in the message buffer
  3538. * on the sequencer.
  3539. *-F*************************************************************************/
  3540. static void
  3541. aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
  3542. {
  3543. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3544. p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
  3545. p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
  3546. p->msg_buf[p->msg_index++] = bus_width;
  3547. p->msg_len += 4;
  3548. }
  3549. /*+F*************************************************************************
  3550. * Function:
  3551. * aic7xxx_calc_residual
  3552. *
  3553. * Description:
  3554. * Calculate the residual data not yet transferred.
  3555. *-F*************************************************************************/
  3556. static void
  3557. aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  3558. {
  3559. struct aic7xxx_hwscb *hscb;
  3560. Scsi_Cmnd *cmd;
  3561. int actual, i;
  3562. cmd = scb->cmd;
  3563. hscb = scb->hscb;
  3564. /*
  3565. * Don't destroy valid residual information with
  3566. * residual coming from a check sense operation.
  3567. */
  3568. if (((scb->hscb->control & DISCONNECTED) == 0) &&
  3569. (scb->flags & SCB_SENSE) == 0)
  3570. {
  3571. /*
  3572. * We had an underflow. At this time, there's only
  3573. * one other driver that bothers to check for this,
  3574. * and cmd->underflow seems to be set rather half-
  3575. * heartedly in the higher-level SCSI code.
  3576. */
  3577. actual = scb->sg_length;
  3578. for (i=1; i < hscb->residual_SG_segment_count; i++)
  3579. {
  3580. actual -= scb->sg_list[scb->sg_count - i].length;
  3581. }
  3582. actual -= (hscb->residual_data_count[2] << 16) |
  3583. (hscb->residual_data_count[1] << 8) |
  3584. hscb->residual_data_count[0];
  3585. if (actual < cmd->underflow)
  3586. {
  3587. if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  3588. {
  3589. printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
  3590. "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
  3591. (rq_data_dir(cmd->request) == WRITE) ? "wrote" : "read", actual,
  3592. hscb->residual_SG_segment_count);
  3593. printk(INFO_LEAD "status 0x%x.\n", p->host_no, CTL_OF_SCB(scb),
  3594. hscb->target_status);
  3595. }
  3596. /*
  3597. * In 2.4, only send back the residual information, don't flag this
  3598. * as an error. Before 2.4 we had to flag this as an error because
  3599. * the mid layer didn't check residual data counts to see if the
  3600. * command needs retried.
  3601. */
  3602. cmd->resid = scb->sg_length - actual;
  3603. aic7xxx_status(cmd) = hscb->target_status;
  3604. }
  3605. }
  3606. /*
  3607. * Clean out the residual information in the SCB for the
  3608. * next consumer.
  3609. */
  3610. hscb->residual_data_count[2] = 0;
  3611. hscb->residual_data_count[1] = 0;
  3612. hscb->residual_data_count[0] = 0;
  3613. hscb->residual_SG_segment_count = 0;
  3614. }
  3615. /*+F*************************************************************************
  3616. * Function:
  3617. * aic7xxx_handle_device_reset
  3618. *
  3619. * Description:
  3620. * Interrupt handler for sequencer interrupts (SEQINT).
  3621. *-F*************************************************************************/
  3622. static void
  3623. aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
  3624. {
  3625. unsigned char tindex = target;
  3626. tindex |= ((channel & 0x01) << 3);
  3627. /*
  3628. * Go back to async/narrow transfers and renegotiate.
  3629. */
  3630. aic_outb(p, 0, TARG_SCSIRATE + tindex);
  3631. if (p->features & AHC_ULTRA2)
  3632. aic_outb(p, 0, TARG_OFFSET + tindex);
  3633. aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
  3634. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3635. printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
  3636. target, -1);
  3637. aic7xxx_run_done_queue(p, /*complete*/ TRUE);
  3638. }
  3639. /*+F*************************************************************************
  3640. * Function:
  3641. * aic7xxx_handle_seqint
  3642. *
  3643. * Description:
  3644. * Interrupt handler for sequencer interrupts (SEQINT).
  3645. *-F*************************************************************************/
  3646. static void
  3647. aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
  3648. {
  3649. struct aic7xxx_scb *scb;
  3650. struct aic_dev_data *aic_dev;
  3651. unsigned short target_mask;
  3652. unsigned char target, lun, tindex;
  3653. unsigned char queue_flag = FALSE;
  3654. char channel;
  3655. int result;
  3656. target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
  3657. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  3658. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  3659. else
  3660. channel = 0;
  3661. tindex = target + (channel << 3);
  3662. lun = aic_inb(p, SAVED_TCL) & 0x07;
  3663. target_mask = (0x01 << tindex);
  3664. /*
  3665. * Go ahead and clear the SEQINT now, that avoids any interrupt race
  3666. * conditions later on in case we enable some other interrupt.
  3667. */
  3668. aic_outb(p, CLRSEQINT, CLRINT);
  3669. switch (intstat & SEQINT_MASK)
  3670. {
  3671. case NO_MATCH:
  3672. {
  3673. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
  3674. SCSISEQ);
  3675. printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
  3676. "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
  3677. printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
  3678. p->host_no, channel, target, lun,
  3679. aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
  3680. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  3681. if (aic7xxx_panic_on_abort)
  3682. aic7xxx_panic_abort(p, NULL);
  3683. }
  3684. break;
  3685. case SEND_REJECT:
  3686. {
  3687. if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  3688. printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
  3689. "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
  3690. aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
  3691. }
  3692. break;
  3693. case NO_IDENT:
  3694. {
  3695. /*
  3696. * The reconnecting target either did not send an identify
  3697. * message, or did, but we didn't find an SCB to match and
  3698. * before it could respond to our ATN/abort, it hit a dataphase.
  3699. * The only safe thing to do is to blow it away with a bus
  3700. * reset.
  3701. */
  3702. if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
  3703. printk(INFO_LEAD "Target did not send an IDENTIFY message; "
  3704. "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
  3705. lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
  3706. aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
  3707. aic7xxx_run_done_queue(p, TRUE);
  3708. }
  3709. break;
  3710. case BAD_PHASE:
  3711. if (aic_inb(p, LASTPHASE) == P_BUSFREE)
  3712. {
  3713. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3714. printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
  3715. target, lun);
  3716. restart_sequencer(p);
  3717. }
  3718. else
  3719. {
  3720. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3721. printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
  3722. channel, target, lun);
  3723. }
  3724. break;
  3725. case EXTENDED_MSG:
  3726. {
  3727. p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
  3728. p->msg_len = 0;
  3729. p->msg_index = 0;
  3730. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  3731. if (aic7xxx_verbose > 0xffff)
  3732. printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
  3733. channel, target, lun);
  3734. #endif
  3735. /*
  3736. * To actually receive the message, simply turn on
  3737. * REQINIT interrupts and let our interrupt handler
  3738. * do the rest (REQINIT should already be true).
  3739. */
  3740. p->flags |= AHC_HANDLING_REQINITS;
  3741. aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
  3742. /*
  3743. * We don't want the sequencer unpaused yet so we return early
  3744. */
  3745. return;
  3746. }
  3747. case REJECT_MSG:
  3748. {
  3749. /*
  3750. * What we care about here is if we had an outstanding SDTR
  3751. * or WDTR message for this target. If we did, this is a
  3752. * signal that the target is refusing negotiation.
  3753. */
  3754. unsigned char scb_index;
  3755. unsigned char last_msg;
  3756. scb_index = aic_inb(p, SCB_TAG);
  3757. scb = p->scb_data->scb_array[scb_index];
  3758. aic_dev = AIC_DEV(scb->cmd);
  3759. last_msg = aic_inb(p, LAST_MSG);
  3760. if ( (last_msg == MSG_IDENTIFYFLAG) &&
  3761. (scb->tag_action) &&
  3762. !(scb->flags & SCB_MSGOUT_BITS) )
  3763. {
  3764. if (scb->tag_action == MSG_ORDERED_Q_TAG)
  3765. {
  3766. /*
  3767. * OK...the device seems able to accept tagged commands, but
  3768. * not ordered tag commands, only simple tag commands. So, we
  3769. * disable ordered tag commands and go on with life just like
  3770. * normal.
  3771. */
  3772. scsi_adjust_queue_depth(scb->cmd->device, MSG_SIMPLE_TAG,
  3773. scb->cmd->device->queue_depth);
  3774. scb->tag_action = MSG_SIMPLE_Q_TAG;
  3775. scb->hscb->control &= ~SCB_TAG_TYPE;
  3776. scb->hscb->control |= MSG_SIMPLE_Q_TAG;
  3777. aic_outb(p, scb->hscb->control, SCB_CONTROL);
  3778. /*
  3779. * OK..we set the tag type to simple tag command, now we re-assert
  3780. * ATNO and hope this will take us into the identify phase again
  3781. * so we can resend the tag type and info to the device.
  3782. */
  3783. aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
  3784. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3785. }
  3786. else if (scb->tag_action == MSG_SIMPLE_Q_TAG)
  3787. {
  3788. unsigned char i;
  3789. struct aic7xxx_scb *scbp;
  3790. int old_verbose;
  3791. /*
  3792. * Hmmmm....the device is flaking out on tagged commands.
  3793. */
  3794. scsi_adjust_queue_depth(scb->cmd->device, 0 /* untagged */,
  3795. p->host->cmd_per_lun);
  3796. aic_dev->max_q_depth = aic_dev->temp_q_depth = 1;
  3797. /*
  3798. * We set this command up as a bus device reset. However, we have
  3799. * to clear the tag type as it's causing us problems. We shouldnt
  3800. * have to worry about any other commands being active, since if
  3801. * the device is refusing tagged commands, this should be the
  3802. * first tagged command sent to the device, however, we do have
  3803. * to worry about any other tagged commands that may already be
  3804. * in the qinfifo. The easiest way to do this, is to issue a BDR,
  3805. * send all the commands back to the mid level code, then let them
  3806. * come back and get rebuilt as untagged commands.
  3807. */
  3808. scb->tag_action = 0;
  3809. scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
  3810. aic_outb(p, scb->hscb->control, SCB_CONTROL);
  3811. old_verbose = aic7xxx_verbose;
  3812. aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
  3813. for (i=0; i < p->scb_data->numscbs; i++)
  3814. {
  3815. scbp = p->scb_data->scb_array[i];
  3816. if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
  3817. {
  3818. if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
  3819. {
  3820. aic7xxx_reset_device(p, target, channel, lun, i);
  3821. }
  3822. }
  3823. }
  3824. aic7xxx_run_done_queue(p, TRUE);
  3825. aic7xxx_verbose = old_verbose;
  3826. /*
  3827. * Wait until after the for loop to set the busy index since
  3828. * aic7xxx_reset_device will clear the busy index during its
  3829. * operation.
  3830. */
  3831. aic7xxx_busy_target(p, scb);
  3832. printk(INFO_LEAD "Device is refusing tagged commands, using "
  3833. "untagged I/O.\n", p->host_no, channel, target, lun);
  3834. aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
  3835. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3836. }
  3837. }
  3838. else if (scb->flags & SCB_MSGOUT_PPR)
  3839. {
  3840. /*
  3841. * As per the draft specs, any device capable of supporting any of
  3842. * the option values other than 0 are not allowed to reject the
  3843. * PPR message. Instead, they must negotiate out what they do
  3844. * support instead of rejecting our offering or else they cause
  3845. * a parity error during msg_out phase to signal that they don't
  3846. * like our settings.
  3847. */
  3848. aic_dev->needppr = aic_dev->needppr_copy = 0;
  3849. aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
  3850. (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE), aic_dev);
  3851. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3852. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  3853. aic_dev);
  3854. aic_dev->goal.options = aic_dev->dtr_pending = 0;
  3855. scb->flags &= ~SCB_MSGOUT_BITS;
  3856. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3857. {
  3858. printk(INFO_LEAD "Device is rejecting PPR messages, falling "
  3859. "back.\n", p->host_no, channel, target, lun);
  3860. }
  3861. if ( aic_dev->goal.width )
  3862. {
  3863. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  3864. aic_dev->dtr_pending = 1;
  3865. scb->flags |= SCB_MSGOUT_WDTR;
  3866. }
  3867. if ( aic_dev->goal.offset )
  3868. {
  3869. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  3870. if( !aic_dev->dtr_pending )
  3871. {
  3872. aic_dev->dtr_pending = 1;
  3873. scb->flags |= SCB_MSGOUT_SDTR;
  3874. }
  3875. }
  3876. if ( aic_dev->dtr_pending )
  3877. {
  3878. aic_outb(p, HOST_MSG, MSG_OUT);
  3879. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3880. }
  3881. }
  3882. else if (scb->flags & SCB_MSGOUT_WDTR)
  3883. {
  3884. /*
  3885. * note 8bit xfers and clear flag
  3886. */
  3887. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  3888. scb->flags &= ~SCB_MSGOUT_BITS;
  3889. aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
  3890. (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR), aic_dev);
  3891. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3892. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  3893. aic_dev);
  3894. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3895. {
  3896. printk(INFO_LEAD "Device is rejecting WDTR messages, using "
  3897. "narrow transfers.\n", p->host_no, channel, target, lun);
  3898. }
  3899. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  3900. }
  3901. else if (scb->flags & SCB_MSGOUT_SDTR)
  3902. {
  3903. /*
  3904. * note asynch xfers and clear flag
  3905. */
  3906. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  3907. scb->flags &= ~SCB_MSGOUT_BITS;
  3908. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3909. (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL), aic_dev);
  3910. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3911. {
  3912. printk(INFO_LEAD "Device is rejecting SDTR messages, using "
  3913. "async transfers.\n", p->host_no, channel, target, lun);
  3914. }
  3915. }
  3916. else if (aic7xxx_verbose & VERBOSE_SEQINT)
  3917. {
  3918. /*
  3919. * Otherwise, we ignore it.
  3920. */
  3921. printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
  3922. "Ignoring.\n", p->host_no, channel, target, lun);
  3923. }
  3924. }
  3925. break;
  3926. case BAD_STATUS:
  3927. {
  3928. unsigned char scb_index;
  3929. struct aic7xxx_hwscb *hscb;
  3930. Scsi_Cmnd *cmd;
  3931. /* The sequencer will notify us when a command has an error that
  3932. * would be of interest to the kernel. This allows us to leave
  3933. * the sequencer running in the common case of command completes
  3934. * without error. The sequencer will have DMA'd the SCB back
  3935. * up to us, so we can reference the drivers SCB array.
  3936. *
  3937. * Set the default return value to 0 indicating not to send
  3938. * sense. The sense code will change this if needed and this
  3939. * reduces code duplication.
  3940. */
  3941. aic_outb(p, 0, RETURN_1);
  3942. scb_index = aic_inb(p, SCB_TAG);
  3943. if (scb_index > p->scb_data->numscbs)
  3944. {
  3945. printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
  3946. p->host_no, channel, target, lun, intstat, scb_index);
  3947. break;
  3948. }
  3949. scb = p->scb_data->scb_array[scb_index];
  3950. hscb = scb->hscb;
  3951. if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  3952. {
  3953. printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
  3954. " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
  3955. scb_index, scb->flags, (unsigned long) scb->cmd);
  3956. }
  3957. else
  3958. {
  3959. cmd = scb->cmd;
  3960. aic_dev = AIC_DEV(scb->cmd);
  3961. hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
  3962. aic7xxx_status(cmd) = hscb->target_status;
  3963. cmd->result = hscb->target_status;
  3964. switch (status_byte(hscb->target_status))
  3965. {
  3966. case GOOD:
  3967. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3968. printk(INFO_LEAD "Interrupted for status of GOOD???\n",
  3969. p->host_no, CTL_OF_SCB(scb));
  3970. break;
  3971. case COMMAND_TERMINATED:
  3972. case CHECK_CONDITION:
  3973. if ( !(scb->flags & SCB_SENSE) )
  3974. {
  3975. /*
  3976. * Send a sense command to the requesting target.
  3977. * XXX - revisit this and get rid of the memcopys.
  3978. */
  3979. memcpy(scb->sense_cmd, &generic_sense[0],
  3980. sizeof(generic_sense));
  3981. scb->sense_cmd[1] = (cmd->device->lun << 5);
  3982. scb->sense_cmd[4] = sizeof(cmd->sense_buffer);
  3983. scb->sg_list[0].length =
  3984. cpu_to_le32(sizeof(cmd->sense_buffer));
  3985. scb->sg_list[0].address =
  3986. cpu_to_le32(pci_map_single(p->pdev, cmd->sense_buffer,
  3987. sizeof(cmd->sense_buffer),
  3988. PCI_DMA_FROMDEVICE));
  3989. /*
  3990. * XXX - We should allow disconnection, but can't as it
  3991. * might allow overlapped tagged commands.
  3992. */
  3993. /* hscb->control &= DISCENB; */
  3994. hscb->control = 0;
  3995. hscb->target_status = 0;
  3996. hscb->SG_list_pointer =
  3997. cpu_to_le32(SCB_DMA_ADDR(scb, scb->sg_list));
  3998. hscb->SCSI_cmd_pointer =
  3999. cpu_to_le32(SCB_DMA_ADDR(scb, scb->sense_cmd));
  4000. hscb->data_count = scb->sg_list[0].length;
  4001. hscb->data_pointer = scb->sg_list[0].address;
  4002. hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
  4003. hscb->residual_SG_segment_count = 0;
  4004. hscb->residual_data_count[0] = 0;
  4005. hscb->residual_data_count[1] = 0;
  4006. hscb->residual_data_count[2] = 0;
  4007. scb->sg_count = hscb->SG_segment_count = 1;
  4008. scb->sg_length = sizeof(cmd->sense_buffer);
  4009. scb->tag_action = 0;
  4010. scb->flags |= SCB_SENSE;
  4011. /*
  4012. * Ensure the target is busy since this will be an
  4013. * an untagged request.
  4014. */
  4015. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  4016. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4017. {
  4018. if (scb->flags & SCB_MSGOUT_BITS)
  4019. printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
  4020. CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
  4021. "SDTR" : "WDTR");
  4022. else
  4023. printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
  4024. CTL_OF_SCB(scb));
  4025. }
  4026. #endif
  4027. aic7xxx_busy_target(p, scb);
  4028. aic_outb(p, SEND_SENSE, RETURN_1);
  4029. aic7xxx_error(cmd) = DID_OK;
  4030. break;
  4031. } /* first time sense, no errors */
  4032. printk(INFO_LEAD "CHECK_CONDITION on REQUEST_SENSE, returning "
  4033. "an error.\n", p->host_no, CTL_OF_SCB(scb));
  4034. aic7xxx_error(cmd) = DID_ERROR;
  4035. scb->flags &= ~SCB_SENSE;
  4036. break;
  4037. case QUEUE_FULL:
  4038. queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
  4039. case BUSY: /* drop through to here */
  4040. {
  4041. struct aic7xxx_scb *next_scbp, *prev_scbp;
  4042. unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
  4043. /*
  4044. * We have to look three places for queued commands:
  4045. * 1: p->waiting_scbs queue
  4046. * 2: QINFIFO
  4047. * 3: WAITING_SCBS list on card (for commands that are started
  4048. * but haven't yet made it to the device)
  4049. *
  4050. * Of special note here is that commands on 2 or 3 above will
  4051. * have already been marked as active, while commands on 1 will
  4052. * not. The aic7xxx_done() function will want to unmark them
  4053. * from active, so any commands we pull off of 1 need to
  4054. * up the active count.
  4055. */
  4056. next_scbp = p->waiting_scbs.head;
  4057. while ( next_scbp != NULL )
  4058. {
  4059. prev_scbp = next_scbp;
  4060. next_scbp = next_scbp->q_next;
  4061. if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
  4062. SCB_LIST_NULL) )
  4063. {
  4064. scbq_remove(&p->waiting_scbs, prev_scbp);
  4065. scb->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
  4066. p->activescbs++;
  4067. aic_dev->active_cmds++;
  4068. }
  4069. }
  4070. aic7xxx_search_qinfifo(p, target, channel, lun,
  4071. SCB_LIST_NULL, SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL,
  4072. FALSE, NULL);
  4073. next_scbp = NULL;
  4074. active_hscb = aic_inb(p, SCBPTR);
  4075. prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
  4076. next_hscb = aic_inb(p, WAITING_SCBH);
  4077. while (next_hscb != SCB_LIST_NULL)
  4078. {
  4079. aic_outb(p, next_hscb, SCBPTR);
  4080. scb_index = aic_inb(p, SCB_TAG);
  4081. if (scb_index < p->scb_data->numscbs)
  4082. {
  4083. next_scbp = p->scb_data->scb_array[scb_index];
  4084. if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
  4085. SCB_LIST_NULL) )
  4086. {
  4087. next_scbp->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
  4088. next_hscb = aic_inb(p, SCB_NEXT);
  4089. aic_outb(p, 0, SCB_CONTROL);
  4090. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  4091. aic7xxx_add_curscb_to_free_list(p);
  4092. if (prev_hscb == SCB_LIST_NULL)
  4093. {
  4094. /* We were first on the list,
  4095. * so we kill the selection
  4096. * hardware. Let the sequencer
  4097. * re-init the hardware itself
  4098. */
  4099. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  4100. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  4101. aic_outb(p, next_hscb, WAITING_SCBH);
  4102. }
  4103. else
  4104. {
  4105. aic_outb(p, prev_hscb, SCBPTR);
  4106. aic_outb(p, next_hscb, SCB_NEXT);
  4107. }
  4108. }
  4109. else
  4110. {
  4111. prev_hscb = next_hscb;
  4112. next_hscb = aic_inb(p, SCB_NEXT);
  4113. }
  4114. } /* scb_index >= p->scb_data->numscbs */
  4115. }
  4116. aic_outb(p, active_hscb, SCBPTR);
  4117. aic7xxx_run_done_queue(p, FALSE);
  4118. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  4119. if( (aic7xxx_verbose & VERBOSE_MINOR_ERROR) ||
  4120. (aic7xxx_verbose > 0xffff) )
  4121. {
  4122. if (queue_flag)
  4123. printk(INFO_LEAD "Queue full received; queue depth %d, "
  4124. "active %d\n", p->host_no, CTL_OF_SCB(scb),
  4125. aic_dev->max_q_depth, aic_dev->active_cmds);
  4126. else
  4127. printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
  4128. }
  4129. #endif
  4130. if (queue_flag)
  4131. {
  4132. int diff;
  4133. result = scsi_track_queue_full(cmd->device,
  4134. aic_dev->active_cmds);
  4135. if ( result < 0 )
  4136. {
  4137. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4138. printk(INFO_LEAD "Tagged Command Queueing disabled.\n",
  4139. p->host_no, CTL_OF_SCB(scb));
  4140. diff = aic_dev->max_q_depth - p->host->cmd_per_lun;
  4141. aic_dev->temp_q_depth = 1;
  4142. aic_dev->max_q_depth = 1;
  4143. }
  4144. else if ( result > 0 )
  4145. {
  4146. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4147. printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
  4148. CTL_OF_SCB(scb), result);
  4149. diff = aic_dev->max_q_depth - result;
  4150. aic_dev->max_q_depth = result;
  4151. /* temp_q_depth could have been dropped to 1 for an untagged
  4152. * command that might be coming up */
  4153. if(aic_dev->temp_q_depth > result)
  4154. aic_dev->temp_q_depth = result;
  4155. }
  4156. /* We should free up the no unused SCB entries. But, that's
  4157. * a difficult thing to do because we use a direct indexed
  4158. * array, so we can't just take any entries and free them,
  4159. * we *have* to free the ones at the end of the array, and
  4160. * they very well could be in use right now, which means
  4161. * in order to do this right, we have to add a delayed
  4162. * freeing mechanism tied into the scb_free() code area.
  4163. * We'll add that later.
  4164. */
  4165. }
  4166. break;
  4167. }
  4168. default:
  4169. if (aic7xxx_verbose & VERBOSE_SEQINT)
  4170. printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
  4171. CTL_OF_SCB(scb), scb->hscb->target_status);
  4172. if (!aic7xxx_error(cmd))
  4173. {
  4174. aic7xxx_error(cmd) = DID_RETRY_COMMAND;
  4175. }
  4176. break;
  4177. } /* end switch */
  4178. } /* end else of */
  4179. }
  4180. break;
  4181. case AWAITING_MSG:
  4182. {
  4183. unsigned char scb_index, msg_out;
  4184. scb_index = aic_inb(p, SCB_TAG);
  4185. msg_out = aic_inb(p, MSG_OUT);
  4186. scb = p->scb_data->scb_array[scb_index];
  4187. aic_dev = AIC_DEV(scb->cmd);
  4188. p->msg_index = p->msg_len = 0;
  4189. /*
  4190. * This SCB had a MK_MESSAGE set in its control byte informing
  4191. * the sequencer that we wanted to send a special message to
  4192. * this target.
  4193. */
  4194. if ( !(scb->flags & SCB_DEVICE_RESET) &&
  4195. (msg_out == MSG_IDENTIFYFLAG) &&
  4196. (scb->hscb->control & TAG_ENB) )
  4197. {
  4198. p->msg_buf[p->msg_index++] = scb->tag_action;
  4199. p->msg_buf[p->msg_index++] = scb->hscb->tag;
  4200. p->msg_len += 2;
  4201. }
  4202. if (scb->flags & SCB_DEVICE_RESET)
  4203. {
  4204. p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
  4205. p->msg_len++;
  4206. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  4207. printk(INFO_LEAD "Bus device reset mailed.\n",
  4208. p->host_no, CTL_OF_SCB(scb));
  4209. }
  4210. else if (scb->flags & SCB_ABORT)
  4211. {
  4212. if (scb->tag_action)
  4213. {
  4214. p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
  4215. }
  4216. else
  4217. {
  4218. p->msg_buf[p->msg_index++] = MSG_ABORT;
  4219. }
  4220. p->msg_len++;
  4221. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  4222. printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
  4223. CTL_OF_SCB(scb));
  4224. }
  4225. else if (scb->flags & SCB_MSGOUT_PPR)
  4226. {
  4227. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4228. {
  4229. printk(INFO_LEAD "Sending PPR (%d/%d/%d/%d) message.\n",
  4230. p->host_no, CTL_OF_SCB(scb),
  4231. aic_dev->goal.period,
  4232. aic_dev->goal.offset,
  4233. aic_dev->goal.width,
  4234. aic_dev->goal.options);
  4235. }
  4236. aic7xxx_construct_ppr(p, scb);
  4237. }
  4238. else if (scb->flags & SCB_MSGOUT_WDTR)
  4239. {
  4240. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4241. {
  4242. printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
  4243. CTL_OF_SCB(scb));
  4244. }
  4245. aic7xxx_construct_wdtr(p, aic_dev->goal.width);
  4246. }
  4247. else if (scb->flags & SCB_MSGOUT_SDTR)
  4248. {
  4249. unsigned int max_sync, period;
  4250. unsigned char options = 0;
  4251. /*
  4252. * Now that the device is selected, use the bits in SBLKCTL and
  4253. * SSTAT2 to determine the max sync rate for this device.
  4254. */
  4255. if (p->features & AHC_ULTRA2)
  4256. {
  4257. if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
  4258. !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
  4259. {
  4260. max_sync = AHC_SYNCRATE_ULTRA2;
  4261. }
  4262. else
  4263. {
  4264. max_sync = AHC_SYNCRATE_ULTRA;
  4265. }
  4266. }
  4267. else if (p->features & AHC_ULTRA)
  4268. {
  4269. max_sync = AHC_SYNCRATE_ULTRA;
  4270. }
  4271. else
  4272. {
  4273. max_sync = AHC_SYNCRATE_FAST;
  4274. }
  4275. period = aic_dev->goal.period;
  4276. aic7xxx_find_syncrate(p, &period, max_sync, &options);
  4277. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4278. {
  4279. printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
  4280. CTL_OF_SCB(scb), period,
  4281. aic_dev->goal.offset);
  4282. }
  4283. aic7xxx_construct_sdtr(p, period, aic_dev->goal.offset);
  4284. }
  4285. else
  4286. {
  4287. panic("aic7xxx: AWAITING_MSG for an SCB that does "
  4288. "not have a waiting message.\n");
  4289. }
  4290. /*
  4291. * We've set everything up to send our message, now to actually do
  4292. * so we need to enable reqinit interrupts and let the interrupt
  4293. * handler do the rest. We don't want to unpause the sequencer yet
  4294. * though so we'll return early. We also have to make sure that
  4295. * we clear the SEQINT *BEFORE* we set the REQINIT handler active
  4296. * or else it's possible on VLB cards to lose the first REQINIT
  4297. * interrupt. Edge triggered EISA cards could also lose this
  4298. * interrupt, although PCI and level triggered cards should not
  4299. * have this problem since they continually interrupt the kernel
  4300. * until we take care of the situation.
  4301. */
  4302. scb->flags |= SCB_MSGOUT_SENT;
  4303. p->msg_index = 0;
  4304. p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
  4305. p->flags |= AHC_HANDLING_REQINITS;
  4306. aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
  4307. return;
  4308. }
  4309. break;
  4310. case DATA_OVERRUN:
  4311. {
  4312. unsigned char scb_index = aic_inb(p, SCB_TAG);
  4313. unsigned char lastphase = aic_inb(p, LASTPHASE);
  4314. unsigned int i;
  4315. scb = (p->scb_data->scb_array[scb_index]);
  4316. /*
  4317. * XXX - What do we really want to do on an overrun? The
  4318. * mid-level SCSI code should handle this, but for now,
  4319. * we'll just indicate that the command should retried.
  4320. * If we retrieved sense info on this target, then the
  4321. * base SENSE info should have been saved prior to the
  4322. * overrun error. In that case, we return DID_OK and let
  4323. * the mid level code pick up on the sense info. Otherwise
  4324. * we return DID_ERROR so the command will get retried.
  4325. */
  4326. if ( !(scb->flags & SCB_SENSE) )
  4327. {
  4328. printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
  4329. p->host_no, CTL_OF_SCB(scb),
  4330. (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
  4331. printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
  4332. (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
  4333. scb->sg_length, scb->sg_count);
  4334. printk(KERN_WARNING " Raw SCSI Command: 0x");
  4335. for (i = 0; i < scb->hscb->SCSI_cmd_length; i++)
  4336. {
  4337. printk("%02x ", scb->cmd->cmnd[i]);
  4338. }
  4339. printk("\n");
  4340. if(aic7xxx_verbose > 0xffff)
  4341. {
  4342. for (i = 0; i < scb->sg_count; i++)
  4343. {
  4344. printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
  4345. i,
  4346. le32_to_cpu(scb->sg_list[i].address),
  4347. le32_to_cpu(scb->sg_list[i].length) );
  4348. }
  4349. }
  4350. aic7xxx_error(scb->cmd) = DID_ERROR;
  4351. }
  4352. else
  4353. printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
  4354. p->host_no, CTL_OF_SCB(scb));
  4355. }
  4356. break;
  4357. case WIDE_RESIDUE:
  4358. {
  4359. unsigned char resid_sgcnt, index;
  4360. unsigned char scb_index = aic_inb(p, SCB_TAG);
  4361. unsigned int cur_addr, resid_dcnt;
  4362. unsigned int native_addr, native_length, sg_addr;
  4363. int i;
  4364. if(scb_index > p->scb_data->numscbs)
  4365. {
  4366. printk(WARN_LEAD "invalid scb_index during WIDE_RESIDUE.\n",
  4367. p->host_no, -1, -1, -1);
  4368. /*
  4369. * XXX: Add error handling here
  4370. */
  4371. break;
  4372. }
  4373. scb = p->scb_data->scb_array[scb_index];
  4374. if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  4375. {
  4376. printk(WARN_LEAD "invalid scb during WIDE_RESIDUE flags:0x%x "
  4377. "scb->cmd:0x%lx\n", p->host_no, CTL_OF_SCB(scb),
  4378. scb->flags, (unsigned long)scb->cmd);
  4379. break;
  4380. }
  4381. if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  4382. printk(INFO_LEAD "Got WIDE_RESIDUE message, patching up data "
  4383. "pointer.\n", p->host_no, CTL_OF_SCB(scb));
  4384. /*
  4385. * We have a valid scb to use on this WIDE_RESIDUE message, so
  4386. * we need to walk the sg list looking for this particular sg
  4387. * segment, then see if we happen to be at the very beginning of
  4388. * the segment. If we are, then we have to back things up to
  4389. * the previous segment. If not, then we simply need to remove
  4390. * one byte from this segments address and add one to the byte
  4391. * count.
  4392. */
  4393. cur_addr = aic_inb(p, SHADDR) | (aic_inb(p, SHADDR + 1) << 8) |
  4394. (aic_inb(p, SHADDR + 2) << 16) | (aic_inb(p, SHADDR + 3) << 24);
  4395. sg_addr = aic_inb(p, SG_COUNT + 1) | (aic_inb(p, SG_COUNT + 2) << 8) |
  4396. (aic_inb(p, SG_COUNT + 3) << 16) | (aic_inb(p, SG_COUNT + 4) << 24);
  4397. resid_sgcnt = aic_inb(p, SCB_RESID_SGCNT);
  4398. resid_dcnt = aic_inb(p, SCB_RESID_DCNT) |
  4399. (aic_inb(p, SCB_RESID_DCNT + 1) << 8) |
  4400. (aic_inb(p, SCB_RESID_DCNT + 2) << 16);
  4401. index = scb->sg_count - ((resid_sgcnt) ? resid_sgcnt : 1);
  4402. native_addr = le32_to_cpu(scb->sg_list[index].address);
  4403. native_length = le32_to_cpu(scb->sg_list[index].length);
  4404. /*
  4405. * If resid_dcnt == native_length, then we just loaded this SG
  4406. * segment and we need to back it up one...
  4407. */
  4408. if(resid_dcnt == native_length)
  4409. {
  4410. if(index == 0)
  4411. {
  4412. /*
  4413. * Oops, this isn't right, we can't back up to before the
  4414. * beginning. This must be a bogus message, ignore it.
  4415. */
  4416. break;
  4417. }
  4418. resid_dcnt = 1;
  4419. resid_sgcnt += 1;
  4420. native_addr = le32_to_cpu(scb->sg_list[index - 1].address);
  4421. native_length = le32_to_cpu(scb->sg_list[index - 1].length);
  4422. cur_addr = native_addr + (native_length - 1);
  4423. sg_addr -= sizeof(struct hw_scatterlist);
  4424. }
  4425. else
  4426. {
  4427. /*
  4428. * resid_dcnt != native_length, so we are in the middle of a SG
  4429. * element. Back it up one byte and leave the rest alone.
  4430. */
  4431. resid_dcnt += 1;
  4432. cur_addr -= 1;
  4433. }
  4434. /*
  4435. * Output the new addresses and counts to the right places on the
  4436. * card.
  4437. */
  4438. aic_outb(p, resid_sgcnt, SG_COUNT);
  4439. aic_outb(p, resid_sgcnt, SCB_RESID_SGCNT);
  4440. aic_outb(p, sg_addr & 0xff, SG_COUNT + 1);
  4441. aic_outb(p, (sg_addr >> 8) & 0xff, SG_COUNT + 2);
  4442. aic_outb(p, (sg_addr >> 16) & 0xff, SG_COUNT + 3);
  4443. aic_outb(p, (sg_addr >> 24) & 0xff, SG_COUNT + 4);
  4444. aic_outb(p, resid_dcnt & 0xff, SCB_RESID_DCNT);
  4445. aic_outb(p, (resid_dcnt >> 8) & 0xff, SCB_RESID_DCNT + 1);
  4446. aic_outb(p, (resid_dcnt >> 16) & 0xff, SCB_RESID_DCNT + 2);
  4447. /*
  4448. * The sequencer actually wants to find the new address
  4449. * in the SHADDR register set. On the Ultra2 and later controllers
  4450. * this register set is readonly. In order to get the right number
  4451. * into the register, you actually have to enter it in HADDR and then
  4452. * use the PRELOADEN bit of DFCNTRL to drop it through from the
  4453. * HADDR register to the SHADDR register. On non-Ultra2 controllers,
  4454. * we simply write it direct.
  4455. */
  4456. if(p->features & AHC_ULTRA2)
  4457. {
  4458. /*
  4459. * We might as well be accurate and drop both the resid_dcnt and
  4460. * cur_addr into HCNT and HADDR and have both of them drop
  4461. * through to the shadow layer together.
  4462. */
  4463. aic_outb(p, resid_dcnt & 0xff, HCNT);
  4464. aic_outb(p, (resid_dcnt >> 8) & 0xff, HCNT + 1);
  4465. aic_outb(p, (resid_dcnt >> 16) & 0xff, HCNT + 2);
  4466. aic_outb(p, cur_addr & 0xff, HADDR);
  4467. aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
  4468. aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
  4469. aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
  4470. aic_outb(p, aic_inb(p, DMAPARAMS) | PRELOADEN, DFCNTRL);
  4471. udelay(1);
  4472. aic_outb(p, aic_inb(p, DMAPARAMS) & ~(SCSIEN|HDMAEN), DFCNTRL);
  4473. i=0;
  4474. while(((aic_inb(p, DFCNTRL) & (SCSIEN|HDMAEN)) != 0) && (i++ < 1000))
  4475. {
  4476. udelay(1);
  4477. }
  4478. }
  4479. else
  4480. {
  4481. aic_outb(p, cur_addr & 0xff, SHADDR);
  4482. aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
  4483. aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
  4484. aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
  4485. }
  4486. }
  4487. break;
  4488. case SEQ_SG_FIXUP:
  4489. {
  4490. unsigned char scb_index, tmp;
  4491. int sg_addr, sg_length;
  4492. scb_index = aic_inb(p, SCB_TAG);
  4493. if(scb_index > p->scb_data->numscbs)
  4494. {
  4495. printk(WARN_LEAD "invalid scb_index during SEQ_SG_FIXUP.\n",
  4496. p->host_no, -1, -1, -1);
  4497. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  4498. "0x%x\n", p->host_no, -1, -1, -1,
  4499. aic_inb(p, SCSISIGI),
  4500. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  4501. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  4502. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
  4503. p->host_no, -1, -1, -1, aic_inb(p, SG_CACHEPTR),
  4504. aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
  4505. aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
  4506. /*
  4507. * XXX: Add error handling here
  4508. */
  4509. break;
  4510. }
  4511. scb = p->scb_data->scb_array[scb_index];
  4512. if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  4513. {
  4514. printk(WARN_LEAD "invalid scb during SEQ_SG_FIXUP flags:0x%x "
  4515. "scb->cmd:0x%p\n", p->host_no, CTL_OF_SCB(scb),
  4516. scb->flags, scb->cmd);
  4517. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  4518. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  4519. aic_inb(p, SCSISIGI),
  4520. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  4521. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  4522. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
  4523. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SG_CACHEPTR),
  4524. aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
  4525. aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
  4526. break;
  4527. }
  4528. if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  4529. printk(INFO_LEAD "Fixing up SG address for sequencer.\n", p->host_no,
  4530. CTL_OF_SCB(scb));
  4531. /*
  4532. * Advance the SG pointer to the next element in the list
  4533. */
  4534. tmp = aic_inb(p, SG_NEXT);
  4535. tmp += SG_SIZEOF;
  4536. aic_outb(p, tmp, SG_NEXT);
  4537. if( tmp < SG_SIZEOF )
  4538. aic_outb(p, aic_inb(p, SG_NEXT + 1) + 1, SG_NEXT + 1);
  4539. tmp = aic_inb(p, SG_COUNT) - 1;
  4540. aic_outb(p, tmp, SG_COUNT);
  4541. sg_addr = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].address);
  4542. sg_length = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].length);
  4543. /*
  4544. * Now stuff the element we just advanced past down onto the
  4545. * card so it can be stored in the residual area.
  4546. */
  4547. aic_outb(p, sg_addr & 0xff, HADDR);
  4548. aic_outb(p, (sg_addr >> 8) & 0xff, HADDR + 1);
  4549. aic_outb(p, (sg_addr >> 16) & 0xff, HADDR + 2);
  4550. aic_outb(p, (sg_addr >> 24) & 0xff, HADDR + 3);
  4551. aic_outb(p, sg_length & 0xff, HCNT);
  4552. aic_outb(p, (sg_length >> 8) & 0xff, HCNT + 1);
  4553. aic_outb(p, (sg_length >> 16) & 0xff, HCNT + 2);
  4554. aic_outb(p, (tmp << 2) | ((tmp == 1) ? LAST_SEG : 0), SG_CACHEPTR);
  4555. aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
  4556. while(aic_inb(p, SSTAT0) & SDONE) udelay(1);
  4557. while(aic_inb(p, DFCNTRL) & (HDMAEN|SCSIEN)) aic_outb(p, 0, DFCNTRL);
  4558. }
  4559. break;
  4560. #ifdef AIC7XXX_NOT_YET
  4561. case TRACEPOINT2:
  4562. {
  4563. printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no,
  4564. channel, target, lun);
  4565. }
  4566. break;
  4567. /* XXX Fill these in later */
  4568. case MSG_BUFFER_BUSY:
  4569. printk("aic7xxx: Message buffer busy.\n");
  4570. break;
  4571. case MSGIN_PHASEMIS:
  4572. printk("aic7xxx: Message-in phasemis.\n");
  4573. break;
  4574. #endif
  4575. default: /* unknown */
  4576. printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
  4577. p->host_no, channel, target, lun, intstat,
  4578. aic_inb(p, SCSISIGI));
  4579. break;
  4580. }
  4581. /*
  4582. * Clear the sequencer interrupt and unpause the sequencer.
  4583. */
  4584. unpause_sequencer(p, /* unpause always */ TRUE);
  4585. }
  4586. /*+F*************************************************************************
  4587. * Function:
  4588. * aic7xxx_parse_msg
  4589. *
  4590. * Description:
  4591. * Parses incoming messages into actions on behalf of
  4592. * aic7xxx_handle_reqinit
  4593. *_F*************************************************************************/
  4594. static int
  4595. aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  4596. {
  4597. int reject, reply, done;
  4598. unsigned char target_scsirate, tindex;
  4599. unsigned short target_mask;
  4600. unsigned char target, channel, lun;
  4601. unsigned char bus_width, new_bus_width;
  4602. unsigned char trans_options, new_trans_options;
  4603. unsigned int period, new_period, offset, new_offset, maxsync;
  4604. struct aic7xxx_syncrate *syncrate;
  4605. struct aic_dev_data *aic_dev;
  4606. target = scb->cmd->device->id;
  4607. channel = scb->cmd->device->channel;
  4608. lun = scb->cmd->device->lun;
  4609. reply = reject = done = FALSE;
  4610. tindex = TARGET_INDEX(scb->cmd);
  4611. aic_dev = AIC_DEV(scb->cmd);
  4612. target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  4613. target_mask = (0x01 << tindex);
  4614. /*
  4615. * Parse as much of the message as is available,
  4616. * rejecting it if we don't support it. When
  4617. * the entire message is available and has been
  4618. * handled, return TRUE indicating that we have
  4619. * parsed an entire message.
  4620. */
  4621. if (p->msg_buf[0] != MSG_EXTENDED)
  4622. {
  4623. reject = TRUE;
  4624. }
  4625. /*
  4626. * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
  4627. * using the SDTR messages. We need the PPR messages to enable the
  4628. * higher speeds that include things like Dual Edge clocking.
  4629. */
  4630. if (p->features & AHC_ULTRA2)
  4631. {
  4632. if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
  4633. !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
  4634. {
  4635. if (p->features & AHC_ULTRA3)
  4636. maxsync = AHC_SYNCRATE_ULTRA3;
  4637. else
  4638. maxsync = AHC_SYNCRATE_ULTRA2;
  4639. }
  4640. else
  4641. {
  4642. maxsync = AHC_SYNCRATE_ULTRA;
  4643. }
  4644. }
  4645. else if (p->features & AHC_ULTRA)
  4646. {
  4647. maxsync = AHC_SYNCRATE_ULTRA;
  4648. }
  4649. else
  4650. {
  4651. maxsync = AHC_SYNCRATE_FAST;
  4652. }
  4653. /*
  4654. * Just accept the length byte outright and perform
  4655. * more checking once we know the message type.
  4656. */
  4657. if ( !reject && (p->msg_len > 2) )
  4658. {
  4659. switch(p->msg_buf[2])
  4660. {
  4661. case MSG_EXT_SDTR:
  4662. {
  4663. if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
  4664. {
  4665. reject = TRUE;
  4666. break;
  4667. }
  4668. if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
  4669. {
  4670. break;
  4671. }
  4672. period = new_period = p->msg_buf[3];
  4673. offset = new_offset = p->msg_buf[4];
  4674. trans_options = new_trans_options = 0;
  4675. bus_width = new_bus_width = target_scsirate & WIDEXFER;
  4676. /*
  4677. * If our current max syncrate is in the Ultra3 range, bump it back
  4678. * down to Ultra2 since we can't negotiate DT transfers using SDTR
  4679. */
  4680. if(maxsync == AHC_SYNCRATE_ULTRA3)
  4681. maxsync = AHC_SYNCRATE_ULTRA2;
  4682. /*
  4683. * We might have a device that is starting negotiation with us
  4684. * before we can start up negotiation with it....be prepared to
  4685. * have a device ask for a higher speed then we want to give it
  4686. * in that case
  4687. */
  4688. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
  4689. (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) )
  4690. {
  4691. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  4692. {
  4693. /*
  4694. * We shouldn't get here unless this is a narrow drive, wide
  4695. * devices should trigger this same section of code in the WDTR
  4696. * handler first instead.
  4697. */
  4698. aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
  4699. aic_dev->goal.options = 0;
  4700. if(p->user[tindex].offset)
  4701. {
  4702. aic_dev->needsdtr_copy = 1;
  4703. aic_dev->goal.period = max_t(unsigned char, 10,p->user[tindex].period);
  4704. if(p->features & AHC_ULTRA2)
  4705. {
  4706. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4707. }
  4708. else
  4709. {
  4710. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  4711. }
  4712. }
  4713. else
  4714. {
  4715. aic_dev->needsdtr_copy = 0;
  4716. aic_dev->goal.period = 255;
  4717. aic_dev->goal.offset = 0;
  4718. }
  4719. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  4720. }
  4721. else if (aic_dev->needsdtr_copy == 0)
  4722. {
  4723. /*
  4724. * This is a preemptive message from the target, we've already
  4725. * scanned this target and set our options for it, and we
  4726. * don't need a SDTR with this target (for whatever reason),
  4727. * so reject this incoming SDTR
  4728. */
  4729. reject = TRUE;
  4730. break;
  4731. }
  4732. /* The device is sending this message first and we have to reply */
  4733. reply = TRUE;
  4734. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4735. {
  4736. printk(INFO_LEAD "Received pre-emptive SDTR message from "
  4737. "target.\n", p->host_no, CTL_OF_SCB(scb));
  4738. }
  4739. /*
  4740. * Validate the values the device passed to us against our SEEPROM
  4741. * settings. We don't have to do this if we aren't replying since
  4742. * the device isn't allowed to send values greater than the ones
  4743. * we first sent to it.
  4744. */
  4745. new_period = max_t(unsigned int, period, aic_dev->goal.period);
  4746. new_offset = min_t(unsigned int, offset, aic_dev->goal.offset);
  4747. }
  4748. /*
  4749. * Use our new_period, new_offset, bus_width, and card options
  4750. * to determine the actual syncrate settings
  4751. */
  4752. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  4753. &trans_options);
  4754. aic7xxx_validate_offset(p, syncrate, &new_offset, bus_width);
  4755. /*
  4756. * Did we drop to async? If so, send a reply regardless of whether
  4757. * or not we initiated this negotiation.
  4758. */
  4759. if ((new_offset == 0) && (new_offset != offset))
  4760. {
  4761. aic_dev->needsdtr_copy = 0;
  4762. reply = TRUE;
  4763. }
  4764. /*
  4765. * Did we start this, if not, or if we went too low and had to
  4766. * go async, then send an SDTR back to the target
  4767. */
  4768. if(reply)
  4769. {
  4770. /* when sending a reply, make sure that the goal settings are
  4771. * updated along with current and active since the code that
  4772. * will actually build the message for the sequencer uses the
  4773. * goal settings as its guidelines.
  4774. */
  4775. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  4776. new_offset, trans_options,
  4777. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  4778. aic_dev);
  4779. scb->flags &= ~SCB_MSGOUT_BITS;
  4780. scb->flags |= SCB_MSGOUT_SDTR;
  4781. aic_outb(p, HOST_MSG, MSG_OUT);
  4782. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  4783. }
  4784. else
  4785. {
  4786. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  4787. new_offset, trans_options,
  4788. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  4789. aic_dev->needsdtr = 0;
  4790. }
  4791. done = TRUE;
  4792. break;
  4793. }
  4794. case MSG_EXT_WDTR:
  4795. {
  4796. if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
  4797. {
  4798. reject = TRUE;
  4799. break;
  4800. }
  4801. if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
  4802. {
  4803. break;
  4804. }
  4805. bus_width = new_bus_width = p->msg_buf[3];
  4806. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
  4807. (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
  4808. {
  4809. switch(bus_width)
  4810. {
  4811. default:
  4812. {
  4813. reject = TRUE;
  4814. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  4815. ((aic_dev->flags & DEVICE_PRINT_DTR) ||
  4816. (aic7xxx_verbose > 0xffff)) )
  4817. {
  4818. printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
  4819. p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
  4820. }
  4821. } /* We fall through on purpose */
  4822. case MSG_EXT_WDTR_BUS_8_BIT:
  4823. {
  4824. aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
  4825. aic_dev->needwdtr_copy &= ~target_mask;
  4826. break;
  4827. }
  4828. case MSG_EXT_WDTR_BUS_16_BIT:
  4829. {
  4830. break;
  4831. }
  4832. }
  4833. aic_dev->needwdtr = 0;
  4834. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  4835. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  4836. }
  4837. else
  4838. {
  4839. if ( !(aic_dev->flags & DEVICE_DTR_SCANNED) )
  4840. {
  4841. /*
  4842. * Well, we now know the WDTR and SYNC caps of this device since
  4843. * it contacted us first, mark it as such and copy the user stuff
  4844. * over to the goal stuff.
  4845. */
  4846. if( (p->features & AHC_WIDE) && p->user[tindex].width )
  4847. {
  4848. aic_dev->goal.width = MSG_EXT_WDTR_BUS_16_BIT;
  4849. aic_dev->needwdtr_copy = 1;
  4850. }
  4851. /*
  4852. * Devices that support DT transfers don't start WDTR requests
  4853. */
  4854. aic_dev->goal.options = 0;
  4855. if(p->user[tindex].offset)
  4856. {
  4857. aic_dev->needsdtr_copy = 1;
  4858. aic_dev->goal.period = max_t(unsigned char, 10, p->user[tindex].period);
  4859. if(p->features & AHC_ULTRA2)
  4860. {
  4861. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4862. }
  4863. else if( aic_dev->goal.width )
  4864. {
  4865. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  4866. }
  4867. else
  4868. {
  4869. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  4870. }
  4871. } else {
  4872. aic_dev->needsdtr_copy = 0;
  4873. aic_dev->goal.period = 255;
  4874. aic_dev->goal.offset = 0;
  4875. }
  4876. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  4877. }
  4878. else if (aic_dev->needwdtr_copy == 0)
  4879. {
  4880. /*
  4881. * This is a preemptive message from the target, we've already
  4882. * scanned this target and set our options for it, and we
  4883. * don't need a WDTR with this target (for whatever reason),
  4884. * so reject this incoming WDTR
  4885. */
  4886. reject = TRUE;
  4887. break;
  4888. }
  4889. /* The device is sending this message first and we have to reply */
  4890. reply = TRUE;
  4891. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4892. {
  4893. printk(INFO_LEAD "Received pre-emptive WDTR message from "
  4894. "target.\n", p->host_no, CTL_OF_SCB(scb));
  4895. }
  4896. switch(bus_width)
  4897. {
  4898. case MSG_EXT_WDTR_BUS_16_BIT:
  4899. {
  4900. if ( (p->features & AHC_WIDE) &&
  4901. (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) )
  4902. {
  4903. new_bus_width = MSG_EXT_WDTR_BUS_16_BIT;
  4904. break;
  4905. }
  4906. } /* Fall through if we aren't a wide card */
  4907. default:
  4908. case MSG_EXT_WDTR_BUS_8_BIT:
  4909. {
  4910. aic_dev->needwdtr_copy = 0;
  4911. new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
  4912. break;
  4913. }
  4914. }
  4915. scb->flags &= ~SCB_MSGOUT_BITS;
  4916. scb->flags |= SCB_MSGOUT_WDTR;
  4917. aic_dev->needwdtr = 0;
  4918. if(aic_dev->dtr_pending == 0)
  4919. {
  4920. /* there is no other command with SCB_DTR_SCB already set that will
  4921. * trigger the release of the dtr_pending bit. Both set the bit
  4922. * and set scb->flags |= SCB_DTR_SCB
  4923. */
  4924. aic_dev->dtr_pending = 1;
  4925. scb->flags |= SCB_DTR_SCB;
  4926. }
  4927. aic_outb(p, HOST_MSG, MSG_OUT);
  4928. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  4929. /* when sending a reply, make sure that the goal settings are
  4930. * updated along with current and active since the code that
  4931. * will actually build the message for the sequencer uses the
  4932. * goal settings as its guidelines.
  4933. */
  4934. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  4935. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  4936. aic_dev);
  4937. }
  4938. /*
  4939. * By virtue of the SCSI spec, a WDTR message negates any existing
  4940. * SDTR negotiations. So, even if needsdtr isn't marked for this
  4941. * device, we still have to do a new SDTR message if the device
  4942. * supports SDTR at all. Therefore, we check needsdtr_copy instead
  4943. * of needstr.
  4944. */
  4945. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  4946. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  4947. aic_dev);
  4948. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  4949. done = TRUE;
  4950. break;
  4951. }
  4952. case MSG_EXT_PPR:
  4953. {
  4954. if (p->msg_buf[1] != MSG_EXT_PPR_LEN)
  4955. {
  4956. reject = TRUE;
  4957. break;
  4958. }
  4959. if (p->msg_len < (MSG_EXT_PPR_LEN + 2))
  4960. {
  4961. break;
  4962. }
  4963. period = new_period = p->msg_buf[3];
  4964. offset = new_offset = p->msg_buf[5];
  4965. bus_width = new_bus_width = p->msg_buf[6];
  4966. trans_options = new_trans_options = p->msg_buf[7] & 0xf;
  4967. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4968. {
  4969. printk(INFO_LEAD "Parsing PPR message (%d/%d/%d/%d)\n",
  4970. p->host_no, CTL_OF_SCB(scb), period, offset, bus_width,
  4971. trans_options);
  4972. }
  4973. /*
  4974. * We might have a device that is starting negotiation with us
  4975. * before we can start up negotiation with it....be prepared to
  4976. * have a device ask for a higher speed then we want to give it
  4977. * in that case
  4978. */
  4979. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
  4980. (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR) )
  4981. {
  4982. /* Have we scanned the device yet? */
  4983. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  4984. {
  4985. /* The device is electing to use PPR messages, so we will too until
  4986. * we know better */
  4987. aic_dev->needppr = aic_dev->needppr_copy = 1;
  4988. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  4989. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  4990. /* We know the device is SCSI-3 compliant due to PPR */
  4991. aic_dev->flags |= DEVICE_SCSI_3;
  4992. /*
  4993. * Not only is the device starting this up, but it also hasn't
  4994. * been scanned yet, so this would likely be our TUR or our
  4995. * INQUIRY command at scan time, so we need to use the
  4996. * settings from the SEEPROM if they existed. Of course, even
  4997. * if we didn't find a SEEPROM, we stuffed default values into
  4998. * the user settings anyway, so use those in all cases.
  4999. */
  5000. aic_dev->goal.width = p->user[tindex].width;
  5001. if(p->user[tindex].offset)
  5002. {
  5003. aic_dev->goal.period = p->user[tindex].period;
  5004. aic_dev->goal.options = p->user[tindex].options;
  5005. if(p->features & AHC_ULTRA2)
  5006. {
  5007. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  5008. }
  5009. else if( aic_dev->goal.width &&
  5010. (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
  5011. p->features & AHC_WIDE )
  5012. {
  5013. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  5014. }
  5015. else
  5016. {
  5017. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  5018. }
  5019. }
  5020. else
  5021. {
  5022. aic_dev->goal.period = 255;
  5023. aic_dev->goal.offset = 0;
  5024. aic_dev->goal.options = 0;
  5025. }
  5026. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  5027. }
  5028. else if (aic_dev->needppr_copy == 0)
  5029. {
  5030. /*
  5031. * This is a preemptive message from the target, we've already
  5032. * scanned this target and set our options for it, and we
  5033. * don't need a PPR with this target (for whatever reason),
  5034. * so reject this incoming PPR
  5035. */
  5036. reject = TRUE;
  5037. break;
  5038. }
  5039. /* The device is sending this message first and we have to reply */
  5040. reply = TRUE;
  5041. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  5042. {
  5043. printk(INFO_LEAD "Received pre-emptive PPR message from "
  5044. "target.\n", p->host_no, CTL_OF_SCB(scb));
  5045. }
  5046. }
  5047. switch(bus_width)
  5048. {
  5049. case MSG_EXT_WDTR_BUS_16_BIT:
  5050. {
  5051. if ( (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) &&
  5052. p->features & AHC_WIDE)
  5053. {
  5054. break;
  5055. }
  5056. }
  5057. default:
  5058. {
  5059. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  5060. ((aic_dev->flags & DEVICE_PRINT_DTR) ||
  5061. (aic7xxx_verbose > 0xffff)) )
  5062. {
  5063. reply = TRUE;
  5064. printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
  5065. p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
  5066. }
  5067. } /* We fall through on purpose */
  5068. case MSG_EXT_WDTR_BUS_8_BIT:
  5069. {
  5070. /*
  5071. * According to the spec, if we aren't wide, we also can't be
  5072. * Dual Edge so clear the options byte
  5073. */
  5074. new_trans_options = 0;
  5075. new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
  5076. break;
  5077. }
  5078. }
  5079. if(reply)
  5080. {
  5081. /* when sending a reply, make sure that the goal settings are
  5082. * updated along with current and active since the code that
  5083. * will actually build the message for the sequencer uses the
  5084. * goal settings as its guidelines.
  5085. */
  5086. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  5087. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  5088. aic_dev);
  5089. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  5090. &new_trans_options);
  5091. aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
  5092. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  5093. new_offset, new_trans_options,
  5094. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  5095. aic_dev);
  5096. }
  5097. else
  5098. {
  5099. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  5100. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  5101. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  5102. &new_trans_options);
  5103. aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
  5104. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  5105. new_offset, new_trans_options,
  5106. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  5107. }
  5108. /*
  5109. * As it turns out, if we don't *have* to have PPR messages, then
  5110. * configure ourselves not to use them since that makes some
  5111. * external drive chassis work (those chassis can't parse PPR
  5112. * messages and they mangle the SCSI bus until you send a WDTR
  5113. * and SDTR that they can understand).
  5114. */
  5115. if(new_trans_options == 0)
  5116. {
  5117. aic_dev->needppr = aic_dev->needppr_copy = 0;
  5118. if(new_offset)
  5119. {
  5120. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  5121. }
  5122. if (new_bus_width)
  5123. {
  5124. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  5125. }
  5126. }
  5127. if((new_offset == 0) && (offset != 0))
  5128. {
  5129. /*
  5130. * Oops, the syncrate went to low for this card and we fell off
  5131. * to async (should never happen with a device that uses PPR
  5132. * messages, but have to be complete)
  5133. */
  5134. reply = TRUE;
  5135. }
  5136. if(reply)
  5137. {
  5138. scb->flags &= ~SCB_MSGOUT_BITS;
  5139. scb->flags |= SCB_MSGOUT_PPR;
  5140. aic_outb(p, HOST_MSG, MSG_OUT);
  5141. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  5142. }
  5143. else
  5144. {
  5145. aic_dev->needppr = 0;
  5146. }
  5147. done = TRUE;
  5148. break;
  5149. }
  5150. default:
  5151. {
  5152. reject = TRUE;
  5153. break;
  5154. }
  5155. } /* end of switch(p->msg_type) */
  5156. } /* end of if (!reject && (p->msg_len > 2)) */
  5157. if (!reply && reject)
  5158. {
  5159. aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
  5160. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  5161. done = TRUE;
  5162. }
  5163. return(done);
  5164. }
  5165. /*+F*************************************************************************
  5166. * Function:
  5167. * aic7xxx_handle_reqinit
  5168. *
  5169. * Description:
  5170. * Interrupt handler for REQINIT interrupts (used to transfer messages to
  5171. * and from devices).
  5172. *_F*************************************************************************/
  5173. static void
  5174. aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  5175. {
  5176. unsigned char lastbyte;
  5177. unsigned char phasemis;
  5178. int done = FALSE;
  5179. switch(p->msg_type)
  5180. {
  5181. case MSG_TYPE_INITIATOR_MSGOUT:
  5182. {
  5183. if (p->msg_len == 0)
  5184. panic("aic7xxx: REQINIT with no active message!\n");
  5185. lastbyte = (p->msg_index == (p->msg_len - 1));
  5186. phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
  5187. if (lastbyte || phasemis)
  5188. {
  5189. /* Time to end the message */
  5190. p->msg_len = 0;
  5191. p->msg_type = MSG_TYPE_NONE;
  5192. /*
  5193. * NOTE-TO-MYSELF: If you clear the REQINIT after you
  5194. * disable REQINITs, then cases of REJECT_MSG stop working
  5195. * and hang the bus
  5196. */
  5197. aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
  5198. aic_outb(p, CLRSCSIINT, CLRINT);
  5199. p->flags &= ~AHC_HANDLING_REQINITS;
  5200. if (phasemis == 0)
  5201. {
  5202. aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
  5203. aic_outb(p, 0, RETURN_1);
  5204. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5205. if (aic7xxx_verbose > 0xffff)
  5206. printk(INFO_LEAD "Completed sending of REQINIT message.\n",
  5207. p->host_no, CTL_OF_SCB(scb));
  5208. #endif
  5209. }
  5210. else
  5211. {
  5212. aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
  5213. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5214. if (aic7xxx_verbose > 0xffff)
  5215. printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
  5216. p->host_no, CTL_OF_SCB(scb));
  5217. #endif
  5218. }
  5219. unpause_sequencer(p, TRUE);
  5220. }
  5221. else
  5222. {
  5223. /*
  5224. * Present the byte on the bus (clearing REQINIT) but don't
  5225. * unpause the sequencer.
  5226. */
  5227. aic_outb(p, CLRREQINIT, CLRSINT1);
  5228. aic_outb(p, CLRSCSIINT, CLRINT);
  5229. aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
  5230. }
  5231. break;
  5232. }
  5233. case MSG_TYPE_INITIATOR_MSGIN:
  5234. {
  5235. phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
  5236. if (phasemis == 0)
  5237. {
  5238. p->msg_len++;
  5239. /* Pull the byte in without acking it */
  5240. p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
  5241. done = aic7xxx_parse_msg(p, scb);
  5242. /* Ack the byte */
  5243. aic_outb(p, CLRREQINIT, CLRSINT1);
  5244. aic_outb(p, CLRSCSIINT, CLRINT);
  5245. aic_inb(p, SCSIDATL);
  5246. p->msg_index++;
  5247. }
  5248. if (phasemis || done)
  5249. {
  5250. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5251. if (aic7xxx_verbose > 0xffff)
  5252. {
  5253. if (phasemis)
  5254. printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
  5255. p->host_no, CTL_OF_SCB(scb));
  5256. else
  5257. printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
  5258. p->host_no, CTL_OF_SCB(scb));
  5259. }
  5260. #endif
  5261. /* Time to end our message session */
  5262. p->msg_len = 0;
  5263. p->msg_type = MSG_TYPE_NONE;
  5264. aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
  5265. aic_outb(p, CLRSCSIINT, CLRINT);
  5266. p->flags &= ~AHC_HANDLING_REQINITS;
  5267. unpause_sequencer(p, TRUE);
  5268. }
  5269. break;
  5270. }
  5271. default:
  5272. {
  5273. panic("aic7xxx: Unknown REQINIT message type.\n");
  5274. break;
  5275. }
  5276. } /* End of switch(p->msg_type) */
  5277. }
  5278. /*+F*************************************************************************
  5279. * Function:
  5280. * aic7xxx_handle_scsiint
  5281. *
  5282. * Description:
  5283. * Interrupt handler for SCSI interrupts (SCSIINT).
  5284. *-F*************************************************************************/
  5285. static void
  5286. aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
  5287. {
  5288. unsigned char scb_index;
  5289. unsigned char status;
  5290. struct aic7xxx_scb *scb;
  5291. struct aic_dev_data *aic_dev;
  5292. scb_index = aic_inb(p, SCB_TAG);
  5293. status = aic_inb(p, SSTAT1);
  5294. if (scb_index < p->scb_data->numscbs)
  5295. {
  5296. scb = p->scb_data->scb_array[scb_index];
  5297. if ((scb->flags & SCB_ACTIVE) == 0)
  5298. {
  5299. scb = NULL;
  5300. }
  5301. }
  5302. else
  5303. {
  5304. scb = NULL;
  5305. }
  5306. if ((status & SCSIRSTI) != 0)
  5307. {
  5308. int channel;
  5309. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  5310. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  5311. else
  5312. channel = 0;
  5313. if (aic7xxx_verbose & VERBOSE_RESET)
  5314. printk(WARN_LEAD "Someone else reset the channel!!\n",
  5315. p->host_no, channel, -1, -1);
  5316. if (aic7xxx_panic_on_abort)
  5317. aic7xxx_panic_abort(p, NULL);
  5318. /*
  5319. * Go through and abort all commands for the channel, but do not
  5320. * reset the channel again.
  5321. */
  5322. aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
  5323. aic7xxx_run_done_queue(p, TRUE);
  5324. scb = NULL;
  5325. }
  5326. else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
  5327. {
  5328. /*
  5329. * First look at what phase we were last in. If it's message-out,
  5330. * chances are pretty good that the bus free was in response to
  5331. * one of our abort requests.
  5332. */
  5333. unsigned char lastphase = aic_inb(p, LASTPHASE);
  5334. unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
  5335. unsigned char target = (saved_tcl >> 4) & 0x0F;
  5336. int channel;
  5337. int printerror = TRUE;
  5338. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  5339. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  5340. else
  5341. channel = 0;
  5342. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
  5343. SCSISEQ);
  5344. if (lastphase == P_MESGOUT)
  5345. {
  5346. unsigned char message;
  5347. message = aic_inb(p, SINDEX);
  5348. if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
  5349. {
  5350. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  5351. printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
  5352. CTL_OF_SCB(scb), scb->hscb->tag);
  5353. aic7xxx_reset_device(p, target, channel, ALL_LUNS,
  5354. (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
  5355. aic7xxx_run_done_queue(p, TRUE);
  5356. scb = NULL;
  5357. printerror = 0;
  5358. }
  5359. else if (message == MSG_BUS_DEV_RESET)
  5360. {
  5361. aic7xxx_handle_device_reset(p, target, channel);
  5362. scb = NULL;
  5363. printerror = 0;
  5364. }
  5365. }
  5366. if ( (scb != NULL) && (scb->flags & SCB_DTR_SCB) )
  5367. {
  5368. /*
  5369. * Hmmm...error during a negotiation command. Either we have a
  5370. * borken bus, or the device doesn't like our negotiation message.
  5371. * Since we check the INQUIRY data of a device before sending it
  5372. * negotiation messages, assume the bus is borken for whatever
  5373. * reason. Complete the command.
  5374. */
  5375. printerror = 0;
  5376. aic7xxx_reset_device(p, target, channel, ALL_LUNS, scb->hscb->tag);
  5377. aic7xxx_run_done_queue(p, TRUE);
  5378. scb = NULL;
  5379. }
  5380. if (printerror != 0)
  5381. {
  5382. if (scb != NULL)
  5383. {
  5384. unsigned char tag;
  5385. if ((scb->hscb->control & TAG_ENB) != 0)
  5386. {
  5387. tag = scb->hscb->tag;
  5388. }
  5389. else
  5390. {
  5391. tag = SCB_LIST_NULL;
  5392. }
  5393. aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
  5394. aic7xxx_run_done_queue(p, TRUE);
  5395. }
  5396. else
  5397. {
  5398. aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
  5399. aic7xxx_run_done_queue(p, TRUE);
  5400. }
  5401. printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
  5402. "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
  5403. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  5404. scb = NULL;
  5405. }
  5406. aic_outb(p, MSG_NOOP, MSG_OUT);
  5407. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
  5408. SIMODE1);
  5409. p->flags &= ~AHC_HANDLING_REQINITS;
  5410. aic_outb(p, CLRBUSFREE, CLRSINT1);
  5411. aic_outb(p, CLRSCSIINT, CLRINT);
  5412. restart_sequencer(p);
  5413. unpause_sequencer(p, TRUE);
  5414. }
  5415. else if ((status & SELTO) != 0)
  5416. {
  5417. unsigned char scbptr;
  5418. unsigned char nextscb;
  5419. Scsi_Cmnd *cmd;
  5420. scbptr = aic_inb(p, WAITING_SCBH);
  5421. if (scbptr > p->scb_data->maxhscbs)
  5422. {
  5423. /*
  5424. * I'm still trying to track down exactly how this happens, but until
  5425. * I find it, this code will make sure we aren't passing bogus values
  5426. * into the SCBPTR register, even if that register will just wrap
  5427. * things around, we still don't like having out of range variables.
  5428. *
  5429. * NOTE: Don't check the aic7xxx_verbose variable, I want this message
  5430. * to always be displayed.
  5431. */
  5432. printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
  5433. p->host_no, -1, -1, -1, scbptr);
  5434. if (p->scb_data->maxhscbs > 4)
  5435. scbptr &= (p->scb_data->maxhscbs - 1);
  5436. else
  5437. scbptr &= 0x03;
  5438. }
  5439. aic_outb(p, scbptr, SCBPTR);
  5440. scb_index = aic_inb(p, SCB_TAG);
  5441. scb = NULL;
  5442. if (scb_index < p->scb_data->numscbs)
  5443. {
  5444. scb = p->scb_data->scb_array[scb_index];
  5445. if ((scb->flags & SCB_ACTIVE) == 0)
  5446. {
  5447. scb = NULL;
  5448. }
  5449. }
  5450. if (scb == NULL)
  5451. {
  5452. printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
  5453. p->host_no, -1, -1, -1, scb_index);
  5454. printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
  5455. "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
  5456. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  5457. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  5458. if (aic7xxx_panic_on_abort)
  5459. aic7xxx_panic_abort(p, NULL);
  5460. }
  5461. else
  5462. {
  5463. cmd = scb->cmd;
  5464. cmd->result = (DID_TIME_OUT << 16);
  5465. /*
  5466. * Clear out this hardware SCB
  5467. */
  5468. aic_outb(p, 0, SCB_CONTROL);
  5469. /*
  5470. * Clear out a few values in the card that are in an undetermined
  5471. * state.
  5472. */
  5473. aic_outb(p, MSG_NOOP, MSG_OUT);
  5474. /*
  5475. * Shift the waiting for selection queue forward
  5476. */
  5477. nextscb = aic_inb(p, SCB_NEXT);
  5478. aic_outb(p, nextscb, WAITING_SCBH);
  5479. /*
  5480. * Put this SCB back on the free list.
  5481. */
  5482. aic7xxx_add_curscb_to_free_list(p);
  5483. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5484. if (aic7xxx_verbose > 0xffff)
  5485. printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
  5486. #endif
  5487. if (scb->flags & SCB_QUEUED_ABORT)
  5488. {
  5489. /*
  5490. * We know that this particular SCB had to be the queued abort since
  5491. * the disconnected SCB would have gotten a reconnect instead.
  5492. * What we need to do then is to let the command timeout again so
  5493. * we get a reset since this abort just failed.
  5494. */
  5495. cmd->result = 0;
  5496. scb = NULL;
  5497. }
  5498. }
  5499. /*
  5500. * Keep the sequencer from trying to restart any selections
  5501. */
  5502. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  5503. /*
  5504. * Make sure the data bits on the bus are released
  5505. * Don't do this on 7770 chipsets, it makes them give us
  5506. * a BRKADDRINT and kills the card.
  5507. */
  5508. if( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  5509. aic_outb(p, 0, SCSIBUSL);
  5510. /*
  5511. * Delay for the selection timeout delay period then stop the selection
  5512. */
  5513. udelay(301);
  5514. aic_outb(p, CLRSELINGO, CLRSINT0);
  5515. /*
  5516. * Clear out all the interrupt status bits
  5517. */
  5518. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  5519. p->flags &= ~AHC_HANDLING_REQINITS;
  5520. aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
  5521. aic_outb(p, CLRSCSIINT, CLRINT);
  5522. /*
  5523. * Restarting the sequencer will stop the selection and make sure devices
  5524. * are allowed to reselect in.
  5525. */
  5526. restart_sequencer(p);
  5527. unpause_sequencer(p, TRUE);
  5528. }
  5529. else if (scb == NULL)
  5530. {
  5531. printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
  5532. "during scsiint 0x%x scb(%d)\n"
  5533. " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
  5534. p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
  5535. aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
  5536. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  5537. /*
  5538. * Turn off the interrupt and set status to zero, so that it
  5539. * falls through the rest of the SCSIINT code.
  5540. */
  5541. aic_outb(p, status, CLRSINT1);
  5542. aic_outb(p, CLRSCSIINT, CLRINT);
  5543. unpause_sequencer(p, /* unpause always */ TRUE);
  5544. scb = NULL;
  5545. }
  5546. else if (status & SCSIPERR)
  5547. {
  5548. /*
  5549. * Determine the bus phase and queue an appropriate message.
  5550. */
  5551. char *phase;
  5552. Scsi_Cmnd *cmd;
  5553. unsigned char mesg_out = MSG_NOOP;
  5554. unsigned char lastphase = aic_inb(p, LASTPHASE);
  5555. unsigned char sstat2 = aic_inb(p, SSTAT2);
  5556. cmd = scb->cmd;
  5557. switch (lastphase)
  5558. {
  5559. case P_DATAOUT:
  5560. phase = "Data-Out";
  5561. break;
  5562. case P_DATAIN:
  5563. phase = "Data-In";
  5564. mesg_out = MSG_INITIATOR_DET_ERR;
  5565. break;
  5566. case P_COMMAND:
  5567. phase = "Command";
  5568. break;
  5569. case P_MESGOUT:
  5570. phase = "Message-Out";
  5571. break;
  5572. case P_STATUS:
  5573. phase = "Status";
  5574. mesg_out = MSG_INITIATOR_DET_ERR;
  5575. break;
  5576. case P_MESGIN:
  5577. phase = "Message-In";
  5578. mesg_out = MSG_PARITY_ERROR;
  5579. break;
  5580. default:
  5581. phase = "unknown";
  5582. break;
  5583. }
  5584. /*
  5585. * A parity error has occurred during a data
  5586. * transfer phase. Flag it and continue.
  5587. */
  5588. if( (p->features & AHC_ULTRA3) &&
  5589. (aic_inb(p, SCSIRATE) & AHC_SYNCRATE_CRC) &&
  5590. (lastphase == P_DATAIN) )
  5591. {
  5592. printk(WARN_LEAD "CRC error during %s phase.\n",
  5593. p->host_no, CTL_OF_SCB(scb), phase);
  5594. if(sstat2 & CRCVALERR)
  5595. {
  5596. printk(WARN_LEAD " CRC error in intermediate CRC packet.\n",
  5597. p->host_no, CTL_OF_SCB(scb));
  5598. }
  5599. if(sstat2 & CRCENDERR)
  5600. {
  5601. printk(WARN_LEAD " CRC error in ending CRC packet.\n",
  5602. p->host_no, CTL_OF_SCB(scb));
  5603. }
  5604. if(sstat2 & CRCREQERR)
  5605. {
  5606. printk(WARN_LEAD " Target incorrectly requested a CRC packet.\n",
  5607. p->host_no, CTL_OF_SCB(scb));
  5608. }
  5609. if(sstat2 & DUAL_EDGE_ERROR)
  5610. {
  5611. printk(WARN_LEAD " Dual Edge transmission error.\n",
  5612. p->host_no, CTL_OF_SCB(scb));
  5613. }
  5614. }
  5615. else if( (lastphase == P_MESGOUT) &&
  5616. (scb->flags & SCB_MSGOUT_PPR) )
  5617. {
  5618. /*
  5619. * As per the draft specs, any device capable of supporting any of
  5620. * the option values other than 0 are not allowed to reject the
  5621. * PPR message. Instead, they must negotiate out what they do
  5622. * support instead of rejecting our offering or else they cause
  5623. * a parity error during msg_out phase to signal that they don't
  5624. * like our settings.
  5625. */
  5626. aic_dev = AIC_DEV(scb->cmd);
  5627. aic_dev->needppr = aic_dev->needppr_copy = 0;
  5628. aic7xxx_set_width(p, scb->cmd->device->id, scb->cmd->device->channel, scb->cmd->device->lun,
  5629. MSG_EXT_WDTR_BUS_8_BIT,
  5630. (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE),
  5631. aic_dev);
  5632. aic7xxx_set_syncrate(p, NULL, scb->cmd->device->id, scb->cmd->device->channel, 0, 0,
  5633. 0, AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  5634. aic_dev);
  5635. aic_dev->goal.options = 0;
  5636. scb->flags &= ~SCB_MSGOUT_BITS;
  5637. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  5638. {
  5639. printk(INFO_LEAD "parity error during PPR message, reverting "
  5640. "to WDTR/SDTR\n", p->host_no, CTL_OF_SCB(scb));
  5641. }
  5642. if ( aic_dev->goal.width )
  5643. {
  5644. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  5645. }
  5646. if ( aic_dev->goal.offset )
  5647. {
  5648. if( aic_dev->goal.period <= 9 )
  5649. {
  5650. aic_dev->goal.period = 10;
  5651. }
  5652. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  5653. }
  5654. scb = NULL;
  5655. }
  5656. /*
  5657. * We've set the hardware to assert ATN if we get a parity
  5658. * error on "in" phases, so all we need to do is stuff the
  5659. * message buffer with the appropriate message. "In" phases
  5660. * have set mesg_out to something other than MSG_NOP.
  5661. */
  5662. if (mesg_out != MSG_NOOP)
  5663. {
  5664. aic_outb(p, mesg_out, MSG_OUT);
  5665. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  5666. scb = NULL;
  5667. }
  5668. aic_outb(p, CLRSCSIPERR, CLRSINT1);
  5669. aic_outb(p, CLRSCSIINT, CLRINT);
  5670. unpause_sequencer(p, /* unpause_always */ TRUE);
  5671. }
  5672. else if ( (status & REQINIT) &&
  5673. (p->flags & AHC_HANDLING_REQINITS) )
  5674. {
  5675. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5676. if (aic7xxx_verbose > 0xffff)
  5677. printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
  5678. CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
  5679. #endif
  5680. aic7xxx_handle_reqinit(p, scb);
  5681. return;
  5682. }
  5683. else
  5684. {
  5685. /*
  5686. * We don't know what's going on. Turn off the
  5687. * interrupt source and try to continue.
  5688. */
  5689. if (aic7xxx_verbose & VERBOSE_SCSIINT)
  5690. printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
  5691. p->host_no, -1, -1, -1, status);
  5692. aic_outb(p, status, CLRSINT1);
  5693. aic_outb(p, CLRSCSIINT, CLRINT);
  5694. unpause_sequencer(p, /* unpause always */ TRUE);
  5695. scb = NULL;
  5696. }
  5697. if (scb != NULL)
  5698. {
  5699. aic7xxx_done(p, scb);
  5700. }
  5701. }
  5702. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5703. static void
  5704. aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
  5705. {
  5706. unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
  5707. int i, bogus, lost;
  5708. static unsigned char scb_status[AIC7XXX_MAXSCB];
  5709. #define SCB_NO_LIST 0
  5710. #define SCB_FREE_LIST 1
  5711. #define SCB_WAITING_LIST 2
  5712. #define SCB_DISCONNECTED_LIST 4
  5713. #define SCB_CURRENTLY_ACTIVE 8
  5714. /*
  5715. * Note, these checks will fail on a regular basis once the machine moves
  5716. * beyond the bus scan phase. The problem is race conditions concerning
  5717. * the scbs and where they are linked in. When you have 30 or so commands
  5718. * outstanding on the bus, and run this twice with every interrupt, the
  5719. * chances get pretty good that you'll catch the sequencer with an SCB
  5720. * only partially linked in. Therefore, once we pass the scan phase
  5721. * of the bus, we really should disable this function.
  5722. */
  5723. bogus = FALSE;
  5724. memset(&scb_status[0], 0, sizeof(scb_status));
  5725. pause_sequencer(p);
  5726. saved_scbptr = aic_inb(p, SCBPTR);
  5727. if (saved_scbptr >= p->scb_data->maxhscbs)
  5728. {
  5729. printk("Bogus SCBPTR %d\n", saved_scbptr);
  5730. bogus = TRUE;
  5731. }
  5732. scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
  5733. free_scbh = aic_inb(p, FREE_SCBH);
  5734. if ( (free_scbh != SCB_LIST_NULL) &&
  5735. (free_scbh >= p->scb_data->maxhscbs) )
  5736. {
  5737. printk("Bogus FREE_SCBH %d\n", free_scbh);
  5738. bogus = TRUE;
  5739. }
  5740. else
  5741. {
  5742. temp = free_scbh;
  5743. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5744. {
  5745. if(scb_status[temp] & 0x07)
  5746. {
  5747. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5748. scb_status[temp] | SCB_FREE_LIST);
  5749. bogus = TRUE;
  5750. }
  5751. scb_status[temp] |= SCB_FREE_LIST;
  5752. aic_outb(p, temp, SCBPTR);
  5753. temp = aic_inb(p, SCB_NEXT);
  5754. }
  5755. }
  5756. dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
  5757. if ( (dis_scbh != SCB_LIST_NULL) &&
  5758. (dis_scbh >= p->scb_data->maxhscbs) )
  5759. {
  5760. printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
  5761. bogus = TRUE;
  5762. }
  5763. else
  5764. {
  5765. temp = dis_scbh;
  5766. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5767. {
  5768. if(scb_status[temp] & 0x07)
  5769. {
  5770. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5771. scb_status[temp] | SCB_DISCONNECTED_LIST);
  5772. bogus = TRUE;
  5773. }
  5774. scb_status[temp] |= SCB_DISCONNECTED_LIST;
  5775. aic_outb(p, temp, SCBPTR);
  5776. temp = aic_inb(p, SCB_NEXT);
  5777. }
  5778. }
  5779. wait_scbh = aic_inb(p, WAITING_SCBH);
  5780. if ( (wait_scbh != SCB_LIST_NULL) &&
  5781. (wait_scbh >= p->scb_data->maxhscbs) )
  5782. {
  5783. printk("Bogus WAITING_SCBH %d\n", wait_scbh);
  5784. bogus = TRUE;
  5785. }
  5786. else
  5787. {
  5788. temp = wait_scbh;
  5789. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5790. {
  5791. if(scb_status[temp] & 0x07)
  5792. {
  5793. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5794. scb_status[temp] | SCB_WAITING_LIST);
  5795. bogus = TRUE;
  5796. }
  5797. scb_status[temp] |= SCB_WAITING_LIST;
  5798. aic_outb(p, temp, SCBPTR);
  5799. temp = aic_inb(p, SCB_NEXT);
  5800. }
  5801. }
  5802. lost=0;
  5803. for(i=0; i < p->scb_data->maxhscbs; i++)
  5804. {
  5805. aic_outb(p, i, SCBPTR);
  5806. temp = aic_inb(p, SCB_NEXT);
  5807. if ( ((temp != SCB_LIST_NULL) &&
  5808. (temp >= p->scb_data->maxhscbs)) )
  5809. {
  5810. printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
  5811. bogus = TRUE;
  5812. }
  5813. if ( temp == i )
  5814. {
  5815. printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
  5816. bogus = TRUE;
  5817. }
  5818. if (scb_status[i] == 0)
  5819. lost++;
  5820. if (lost > 1)
  5821. {
  5822. printk("Too many lost scbs.\n");
  5823. bogus=TRUE;
  5824. }
  5825. }
  5826. aic_outb(p, saved_scbptr, SCBPTR);
  5827. unpause_sequencer(p, FALSE);
  5828. if (bogus)
  5829. {
  5830. printk("Bogus parameters found in card SCB array structures.\n");
  5831. printk("%s\n", buffer);
  5832. aic7xxx_panic_abort(p, NULL);
  5833. }
  5834. return;
  5835. }
  5836. #endif
  5837. /*+F*************************************************************************
  5838. * Function:
  5839. * aic7xxx_handle_command_completion_intr
  5840. *
  5841. * Description:
  5842. * SCSI command completion interrupt handler.
  5843. *-F*************************************************************************/
  5844. static void
  5845. aic7xxx_handle_command_completion_intr(struct aic7xxx_host *p)
  5846. {
  5847. struct aic7xxx_scb *scb = NULL;
  5848. struct aic_dev_data *aic_dev;
  5849. Scsi_Cmnd *cmd;
  5850. unsigned char scb_index, tindex;
  5851. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5852. if( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) )
  5853. printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
  5854. #endif
  5855. /*
  5856. * Read the INTSTAT location after clearing the CMDINT bit. This forces
  5857. * any posted PCI writes to flush to memory. Gerard Roudier suggested
  5858. * this fix to the possible race of clearing the CMDINT bit but not
  5859. * having all command bytes flushed onto the qoutfifo.
  5860. */
  5861. aic_outb(p, CLRCMDINT, CLRINT);
  5862. aic_inb(p, INTSTAT);
  5863. /*
  5864. * The sequencer will continue running when it
  5865. * issues this interrupt. There may be >1 commands
  5866. * finished, so loop until we've processed them all.
  5867. */
  5868. while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
  5869. {
  5870. scb_index = p->qoutfifo[p->qoutfifonext];
  5871. p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
  5872. if ( scb_index >= p->scb_data->numscbs )
  5873. {
  5874. printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
  5875. -1, -1, -1, scb_index);
  5876. continue;
  5877. }
  5878. scb = p->scb_data->scb_array[scb_index];
  5879. if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  5880. {
  5881. printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
  5882. "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
  5883. (unsigned long) scb->cmd);
  5884. continue;
  5885. }
  5886. tindex = TARGET_INDEX(scb->cmd);
  5887. aic_dev = AIC_DEV(scb->cmd);
  5888. if (scb->flags & SCB_QUEUED_ABORT)
  5889. {
  5890. pause_sequencer(p);
  5891. if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
  5892. (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
  5893. {
  5894. unpause_sequencer(p, FALSE);
  5895. continue;
  5896. }
  5897. aic7xxx_reset_device(p, scb->cmd->device->id, scb->cmd->device->channel,
  5898. scb->cmd->device->lun, scb->hscb->tag);
  5899. scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
  5900. SCB_QUEUED_ABORT);
  5901. unpause_sequencer(p, FALSE);
  5902. }
  5903. else if (scb->flags & SCB_ABORT)
  5904. {
  5905. /*
  5906. * We started to abort this, but it completed on us, let it
  5907. * through as successful
  5908. */
  5909. scb->flags &= ~(SCB_ABORT|SCB_RESET);
  5910. }
  5911. else if (scb->flags & SCB_SENSE)
  5912. {
  5913. char *buffer = &scb->cmd->sense_buffer[0];
  5914. if (buffer[12] == 0x47 || buffer[12] == 0x54)
  5915. {
  5916. /*
  5917. * Signal that we need to re-negotiate things.
  5918. */
  5919. aic_dev->needppr = aic_dev->needppr_copy;
  5920. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  5921. aic_dev->needwdtr = aic_dev->needwdtr_copy;
  5922. }
  5923. }
  5924. cmd = scb->cmd;
  5925. if (scb->hscb->residual_SG_segment_count != 0)
  5926. {
  5927. aic7xxx_calculate_residual(p, scb);
  5928. }
  5929. cmd->result |= (aic7xxx_error(cmd) << 16);
  5930. aic7xxx_done(p, scb);
  5931. }
  5932. }
  5933. /*+F*************************************************************************
  5934. * Function:
  5935. * aic7xxx_isr
  5936. *
  5937. * Description:
  5938. * SCSI controller interrupt handler.
  5939. *-F*************************************************************************/
  5940. static void
  5941. aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
  5942. {
  5943. struct aic7xxx_host *p;
  5944. unsigned char intstat;
  5945. p = (struct aic7xxx_host *)dev_id;
  5946. /*
  5947. * Just a few sanity checks. Make sure that we have an int pending.
  5948. * Also, if PCI, then we are going to check for a PCI bus error status
  5949. * should we get too many spurious interrupts.
  5950. */
  5951. if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
  5952. {
  5953. #ifdef CONFIG_PCI
  5954. if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
  5955. !(p->flags & AHC_HANDLING_REQINITS) )
  5956. {
  5957. if ( aic_inb(p, ERROR) & PCIERRSTAT )
  5958. {
  5959. aic7xxx_pci_intr(p);
  5960. }
  5961. p->spurious_int = 0;
  5962. }
  5963. else if ( !(p->flags & AHC_HANDLING_REQINITS) )
  5964. {
  5965. p->spurious_int++;
  5966. }
  5967. #endif
  5968. return;
  5969. }
  5970. p->spurious_int = 0;
  5971. /*
  5972. * Keep track of interrupts for /proc/scsi
  5973. */
  5974. p->isr_count++;
  5975. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5976. if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
  5977. (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
  5978. aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
  5979. #endif
  5980. /*
  5981. * Handle all the interrupt sources - especially for SCSI
  5982. * interrupts, we won't get a second chance at them.
  5983. */
  5984. if (intstat & CMDCMPLT)
  5985. {
  5986. aic7xxx_handle_command_completion_intr(p);
  5987. }
  5988. if (intstat & BRKADRINT)
  5989. {
  5990. int i;
  5991. unsigned char errno = aic_inb(p, ERROR);
  5992. printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
  5993. for (i = 0; i < ARRAY_SIZE(hard_error); i++)
  5994. {
  5995. if (errno & hard_error[i].errno)
  5996. {
  5997. printk(KERN_ERR " %s\n", hard_error[i].errmesg);
  5998. }
  5999. }
  6000. printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
  6001. (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
  6002. if (aic7xxx_panic_on_abort)
  6003. aic7xxx_panic_abort(p, NULL);
  6004. #ifdef CONFIG_PCI
  6005. if (errno & PCIERRSTAT)
  6006. aic7xxx_pci_intr(p);
  6007. #endif
  6008. if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
  6009. {
  6010. panic("aic7xxx: unrecoverable BRKADRINT.\n");
  6011. }
  6012. if (errno & ILLHADDR)
  6013. {
  6014. printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
  6015. "pausing controller!\n", p->host_no);
  6016. }
  6017. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  6018. if (errno & DPARERR)
  6019. {
  6020. if (aic_inb(p, DMAPARAMS) & DIRECTION)
  6021. printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
  6022. else
  6023. printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
  6024. }
  6025. #endif
  6026. aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
  6027. unpause_sequencer(p, FALSE);
  6028. }
  6029. if (intstat & SEQINT)
  6030. {
  6031. /*
  6032. * Read the CCSCBCTL register to work around a bug in the Ultra2 cards
  6033. */
  6034. if(p->features & AHC_ULTRA2)
  6035. {
  6036. aic_inb(p, CCSCBCTL);
  6037. }
  6038. aic7xxx_handle_seqint(p, intstat);
  6039. }
  6040. if (intstat & SCSIINT)
  6041. {
  6042. aic7xxx_handle_scsiint(p, intstat);
  6043. }
  6044. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  6045. if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
  6046. (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
  6047. aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
  6048. #endif
  6049. }
  6050. /*+F*************************************************************************
  6051. * Function:
  6052. * do_aic7xxx_isr
  6053. *
  6054. * Description:
  6055. * This is a gross hack to solve a problem in linux kernels 2.1.85 and
  6056. * above. Please, children, do not try this at home, and if you ever see
  6057. * anything like it, please inform the Gross Hack Police immediately
  6058. *-F*************************************************************************/
  6059. static irqreturn_t
  6060. do_aic7xxx_isr(int irq, void *dev_id, struct pt_regs *regs)
  6061. {
  6062. unsigned long cpu_flags;
  6063. struct aic7xxx_host *p;
  6064. p = (struct aic7xxx_host *)dev_id;
  6065. if(!p)
  6066. return IRQ_NONE;
  6067. spin_lock_irqsave(p->host->host_lock, cpu_flags);
  6068. p->flags |= AHC_IN_ISR;
  6069. do
  6070. {
  6071. aic7xxx_isr(irq, dev_id, regs);
  6072. } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
  6073. aic7xxx_done_cmds_complete(p);
  6074. aic7xxx_run_waiting_queues(p);
  6075. p->flags &= ~AHC_IN_ISR;
  6076. spin_unlock_irqrestore(p->host->host_lock, cpu_flags);
  6077. return IRQ_HANDLED;
  6078. }
  6079. /*+F*************************************************************************
  6080. * Function:
  6081. * aic7xxx_init_transinfo
  6082. *
  6083. * Description:
  6084. * Set up the initial aic_dev values from the BIOS settings and from
  6085. * INQUIRY results
  6086. *-F*************************************************************************/
  6087. static void
  6088. aic7xxx_init_transinfo(struct aic7xxx_host *p, struct aic_dev_data *aic_dev)
  6089. {
  6090. Scsi_Device *sdpnt = aic_dev->SDptr;
  6091. unsigned char tindex;
  6092. tindex = sdpnt->id | (sdpnt->channel << 3);
  6093. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  6094. {
  6095. aic_dev->flags |= DEVICE_DTR_SCANNED;
  6096. if ( sdpnt->wdtr && (p->features & AHC_WIDE) )
  6097. {
  6098. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  6099. aic_dev->goal.width = p->user[tindex].width;
  6100. }
  6101. else
  6102. {
  6103. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  6104. pause_sequencer(p);
  6105. aic7xxx_set_width(p, sdpnt->id, sdpnt->channel, sdpnt->lun,
  6106. MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
  6107. AHC_TRANS_GOAL |
  6108. AHC_TRANS_CUR), aic_dev );
  6109. unpause_sequencer(p, FALSE);
  6110. }
  6111. if ( sdpnt->sdtr && p->user[tindex].offset )
  6112. {
  6113. aic_dev->goal.period = p->user[tindex].period;
  6114. aic_dev->goal.options = p->user[tindex].options;
  6115. if (p->features & AHC_ULTRA2)
  6116. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  6117. else if (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT)
  6118. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  6119. else
  6120. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  6121. if ( sdpnt->ppr && p->user[tindex].period <= 9 &&
  6122. p->user[tindex].options )
  6123. {
  6124. aic_dev->needppr = aic_dev->needppr_copy = 1;
  6125. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  6126. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  6127. aic_dev->flags |= DEVICE_SCSI_3;
  6128. }
  6129. else
  6130. {
  6131. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  6132. aic_dev->goal.period = max_t(unsigned char, 10, aic_dev->goal.period);
  6133. aic_dev->goal.options = 0;
  6134. }
  6135. }
  6136. else
  6137. {
  6138. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  6139. aic_dev->goal.period = 255;
  6140. aic_dev->goal.offset = 0;
  6141. aic_dev->goal.options = 0;
  6142. }
  6143. aic_dev->flags |= DEVICE_PRINT_DTR;
  6144. }
  6145. }
  6146. /*+F*************************************************************************
  6147. * Function:
  6148. * aic7xxx_slave_alloc
  6149. *
  6150. * Description:
  6151. * Set up the initial aic_dev struct pointers
  6152. *-F*************************************************************************/
  6153. static int
  6154. aic7xxx_slave_alloc(Scsi_Device *SDptr)
  6155. {
  6156. struct aic7xxx_host *p = (struct aic7xxx_host *)SDptr->host->hostdata;
  6157. struct aic_dev_data *aic_dev;
  6158. aic_dev = kmalloc(sizeof(struct aic_dev_data), GFP_ATOMIC | GFP_KERNEL);
  6159. if(!aic_dev)
  6160. return 1;
  6161. /*
  6162. * Check to see if channel was scanned.
  6163. */
  6164. if (!(p->flags & AHC_A_SCANNED) && (SDptr->channel == 0))
  6165. {
  6166. if (aic7xxx_verbose & VERBOSE_PROBE2)
  6167. printk(INFO_LEAD "Scanning channel for devices.\n",
  6168. p->host_no, 0, -1, -1);
  6169. p->flags |= AHC_A_SCANNED;
  6170. }
  6171. else
  6172. {
  6173. if (!(p->flags & AHC_B_SCANNED) && (SDptr->channel == 1))
  6174. {
  6175. if (aic7xxx_verbose & VERBOSE_PROBE2)
  6176. printk(INFO_LEAD "Scanning channel for devices.\n",
  6177. p->host_no, 1, -1, -1);
  6178. p->flags |= AHC_B_SCANNED;
  6179. }
  6180. }
  6181. memset(aic_dev, 0, sizeof(struct aic_dev_data));
  6182. SDptr->hostdata = aic_dev;
  6183. aic_dev->SDptr = SDptr;
  6184. aic_dev->max_q_depth = 1;
  6185. aic_dev->temp_q_depth = 1;
  6186. scbq_init(&aic_dev->delayed_scbs);
  6187. INIT_LIST_HEAD(&aic_dev->list);
  6188. list_add_tail(&aic_dev->list, &p->aic_devs);
  6189. return 0;
  6190. }
  6191. /*+F*************************************************************************
  6192. * Function:
  6193. * aic7xxx_device_queue_depth
  6194. *
  6195. * Description:
  6196. * Determines the queue depth for a given device. There are two ways
  6197. * a queue depth can be obtained for a tagged queueing device. One
  6198. * way is the default queue depth which is determined by whether
  6199. * aic7xxx_default_queue_depth. The other is by the aic7xxx_tag_info
  6200. * array.
  6201. *
  6202. * If tagged queueing isn't supported on the device, then we set the
  6203. * depth to p->host->hostt->cmd_per_lun for internal driver queueing.
  6204. * as the default queue depth. Otherwise, we use either 4 or 8 as the
  6205. * default queue depth (dependent on the number of hardware SCBs).
  6206. * The other way we determine queue depth is through the use of the
  6207. * aic7xxx_tag_info array which is enabled by defining
  6208. * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
  6209. * with queue depths for individual devices. It also allows tagged
  6210. * queueing to be [en|dis]abled for a specific adapter.
  6211. *-F*************************************************************************/
  6212. static void
  6213. aic7xxx_device_queue_depth(struct aic7xxx_host *p, Scsi_Device *device)
  6214. {
  6215. int tag_enabled = FALSE;
  6216. struct aic_dev_data *aic_dev = device->hostdata;
  6217. unsigned char tindex;
  6218. tindex = device->id | (device->channel << 3);
  6219. if (device->simple_tags)
  6220. return; // We've already enabled this device
  6221. if (device->tagged_supported)
  6222. {
  6223. tag_enabled = TRUE;
  6224. if (!(p->discenable & (1 << tindex)))
  6225. {
  6226. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6227. printk(INFO_LEAD "Disconnection disabled, unable to "
  6228. "enable tagged queueing.\n",
  6229. p->host_no, device->channel, device->id, device->lun);
  6230. tag_enabled = FALSE;
  6231. }
  6232. else
  6233. {
  6234. if (p->instance >= ARRAY_SIZE(aic7xxx_tag_info))
  6235. {
  6236. static int print_warning = TRUE;
  6237. if(print_warning)
  6238. {
  6239. printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
  6240. " installed controllers.\n");
  6241. printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
  6242. " the aic7xxx.c source file.\n");
  6243. print_warning = FALSE;
  6244. }
  6245. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6246. aic7xxx_default_queue_depth;
  6247. }
  6248. else
  6249. {
  6250. if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
  6251. {
  6252. tag_enabled = FALSE;
  6253. }
  6254. else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
  6255. {
  6256. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6257. aic7xxx_default_queue_depth;
  6258. }
  6259. else
  6260. {
  6261. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6262. aic7xxx_tag_info[p->instance].tag_commands[tindex];
  6263. }
  6264. }
  6265. }
  6266. }
  6267. if (tag_enabled)
  6268. {
  6269. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6270. {
  6271. printk(INFO_LEAD "Tagged queuing enabled, queue depth %d.\n",
  6272. p->host_no, device->channel, device->id,
  6273. device->lun, aic_dev->max_q_depth);
  6274. }
  6275. scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, aic_dev->max_q_depth);
  6276. }
  6277. else
  6278. {
  6279. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6280. {
  6281. printk(INFO_LEAD "Tagged queuing disabled, queue depth %d.\n",
  6282. p->host_no, device->channel, device->id,
  6283. device->lun, device->host->cmd_per_lun);
  6284. }
  6285. scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
  6286. }
  6287. return;
  6288. }
  6289. /*+F*************************************************************************
  6290. * Function:
  6291. * aic7xxx_slave_destroy
  6292. *
  6293. * Description:
  6294. * prepare for this device to go away
  6295. *-F*************************************************************************/
  6296. static void
  6297. aic7xxx_slave_destroy(Scsi_Device *SDptr)
  6298. {
  6299. struct aic_dev_data *aic_dev = SDptr->hostdata;
  6300. list_del(&aic_dev->list);
  6301. SDptr->hostdata = NULL;
  6302. kfree(aic_dev);
  6303. return;
  6304. }
  6305. /*+F*************************************************************************
  6306. * Function:
  6307. * aic7xxx_slave_configure
  6308. *
  6309. * Description:
  6310. * Configure the device we are attaching to the controller. This is
  6311. * where we get to do things like scan the INQUIRY data, set queue
  6312. * depths, allocate command structs, etc.
  6313. *-F*************************************************************************/
  6314. static int
  6315. aic7xxx_slave_configure(Scsi_Device *SDptr)
  6316. {
  6317. struct aic7xxx_host *p = (struct aic7xxx_host *) SDptr->host->hostdata;
  6318. struct aic_dev_data *aic_dev;
  6319. int scbnum;
  6320. aic_dev = (struct aic_dev_data *)SDptr->hostdata;
  6321. aic7xxx_init_transinfo(p, aic_dev);
  6322. aic7xxx_device_queue_depth(p, SDptr);
  6323. if(list_empty(&aic_dev->list))
  6324. list_add_tail(&aic_dev->list, &p->aic_devs);
  6325. scbnum = 0;
  6326. list_for_each_entry(aic_dev, &p->aic_devs, list) {
  6327. scbnum += aic_dev->max_q_depth;
  6328. }
  6329. while (scbnum > p->scb_data->numscbs)
  6330. {
  6331. /*
  6332. * Pre-allocate the needed SCBs to get around the possibility of having
  6333. * to allocate some when memory is more or less exhausted and we need
  6334. * the SCB in order to perform a swap operation (possible deadlock)
  6335. */
  6336. if ( aic7xxx_allocate_scb(p) == 0 )
  6337. break;
  6338. }
  6339. return(0);
  6340. }
  6341. /*+F*************************************************************************
  6342. * Function:
  6343. * aic7xxx_probe
  6344. *
  6345. * Description:
  6346. * Probing for EISA boards: it looks like the first two bytes
  6347. * are a manufacturer code - three characters, five bits each:
  6348. *
  6349. * BYTE 0 BYTE 1 BYTE 2 BYTE 3
  6350. * ?1111122 22233333 PPPPPPPP RRRRRRRR
  6351. *
  6352. * The characters are baselined off ASCII '@', so add that value
  6353. * to each to get the real ASCII code for it. The next two bytes
  6354. * appear to be a product and revision number, probably vendor-
  6355. * specific. This is what is being searched for at each port,
  6356. * and what should probably correspond to the ID= field in the
  6357. * ECU's .cfg file for the card - if your card is not detected,
  6358. * make sure your signature is listed in the array.
  6359. *
  6360. * The fourth byte's lowest bit seems to be an enabled/disabled
  6361. * flag (rest of the bits are reserved?).
  6362. *
  6363. * NOTE: This function is only needed on Intel and Alpha platforms,
  6364. * the other platforms we support don't have EISA/VLB busses. So,
  6365. * we #ifdef this entire function to avoid compiler warnings about
  6366. * an unused function.
  6367. *-F*************************************************************************/
  6368. #if defined(__i386__) || defined(__alpha__)
  6369. static int
  6370. aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
  6371. {
  6372. int i;
  6373. unsigned char buf[4];
  6374. static struct {
  6375. int n;
  6376. unsigned char signature[sizeof(buf)];
  6377. ahc_chip type;
  6378. int bios_disabled;
  6379. } AIC7xxx[] = {
  6380. { 4, { 0x04, 0x90, 0x77, 0x70 },
  6381. AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
  6382. { 4, { 0x04, 0x90, 0x77, 0x71 },
  6383. AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
  6384. { 4, { 0x04, 0x90, 0x77, 0x56 },
  6385. AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
  6386. { 4, { 0x04, 0x90, 0x77, 0x57 },
  6387. AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
  6388. };
  6389. /*
  6390. * The VL-bus cards need to be primed by
  6391. * writing before a signature check.
  6392. */
  6393. for (i = 0; i < sizeof(buf); i++)
  6394. {
  6395. outb(0x80 + i, base);
  6396. buf[i] = inb(base + i);
  6397. }
  6398. for (i = 0; i < ARRAY_SIZE(AIC7xxx); i++)
  6399. {
  6400. /*
  6401. * Signature match on enabled card?
  6402. */
  6403. if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
  6404. {
  6405. if (inb(base + 4) & 1)
  6406. {
  6407. if (AIC7xxx[i].bios_disabled)
  6408. {
  6409. *flags |= AHC_USEDEFAULTS;
  6410. }
  6411. else
  6412. {
  6413. *flags |= AHC_BIOS_ENABLED;
  6414. }
  6415. return (i);
  6416. }
  6417. printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
  6418. "disabled at slot %d, ignored.\n", slot);
  6419. }
  6420. }
  6421. return (-1);
  6422. }
  6423. #endif /* (__i386__) || (__alpha__) */
  6424. /*+F*************************************************************************
  6425. * Function:
  6426. * read_2840_seeprom
  6427. *
  6428. * Description:
  6429. * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
  6430. * not successful.
  6431. *
  6432. * See read_seeprom (for the 2940) for the instruction set of the 93C46
  6433. * chip.
  6434. *
  6435. * The 2840 interface to the 93C46 serial EEPROM is through the
  6436. * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
  6437. * DO_2840 bits of the SEECTL_2840 register are connected to the chip
  6438. * select, clock, and data out lines respectively of the serial EEPROM.
  6439. * The DI_2840 bit of the STATUS_2840 is connected to the data in line
  6440. * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
  6441. * useful in that it gives us an 800 nsec timer. After a read from the
  6442. * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
  6443. * later.
  6444. *-F*************************************************************************/
  6445. static int
  6446. read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
  6447. {
  6448. int i = 0, k = 0;
  6449. unsigned char temp;
  6450. unsigned short checksum = 0;
  6451. unsigned short *seeprom = (unsigned short *) sc;
  6452. struct seeprom_cmd {
  6453. unsigned char len;
  6454. unsigned char bits[3];
  6455. };
  6456. struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
  6457. #define CLOCK_PULSE(p) \
  6458. while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
  6459. { \
  6460. ; /* Do nothing */ \
  6461. } \
  6462. (void) aic_inb(p, SEECTL_2840);
  6463. /*
  6464. * Read the first 32 registers of the seeprom. For the 2840,
  6465. * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
  6466. * but only the first 32 are used by Adaptec BIOS. The loop
  6467. * will range from 0 to 31.
  6468. */
  6469. for (k = 0; k < (sizeof(*sc) / 2); k++)
  6470. {
  6471. /*
  6472. * Send chip select for one clock cycle.
  6473. */
  6474. aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
  6475. CLOCK_PULSE(p);
  6476. /*
  6477. * Now we're ready to send the read command followed by the
  6478. * address of the 16-bit register we want to read.
  6479. */
  6480. for (i = 0; i < seeprom_read.len; i++)
  6481. {
  6482. temp = CS_2840 | seeprom_read.bits[i];
  6483. aic_outb(p, temp, SEECTL_2840);
  6484. CLOCK_PULSE(p);
  6485. temp = temp ^ CK_2840;
  6486. aic_outb(p, temp, SEECTL_2840);
  6487. CLOCK_PULSE(p);
  6488. }
  6489. /*
  6490. * Send the 6 bit address (MSB first, LSB last).
  6491. */
  6492. for (i = 5; i >= 0; i--)
  6493. {
  6494. temp = k;
  6495. temp = (temp >> i) & 1; /* Mask out all but lower bit. */
  6496. temp = CS_2840 | temp;
  6497. aic_outb(p, temp, SEECTL_2840);
  6498. CLOCK_PULSE(p);
  6499. temp = temp ^ CK_2840;
  6500. aic_outb(p, temp, SEECTL_2840);
  6501. CLOCK_PULSE(p);
  6502. }
  6503. /*
  6504. * Now read the 16 bit register. An initial 0 precedes the
  6505. * register contents which begins with bit 15 (MSB) and ends
  6506. * with bit 0 (LSB). The initial 0 will be shifted off the
  6507. * top of our word as we let the loop run from 0 to 16.
  6508. */
  6509. for (i = 0; i <= 16; i++)
  6510. {
  6511. temp = CS_2840;
  6512. aic_outb(p, temp, SEECTL_2840);
  6513. CLOCK_PULSE(p);
  6514. temp = temp ^ CK_2840;
  6515. seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
  6516. aic_outb(p, temp, SEECTL_2840);
  6517. CLOCK_PULSE(p);
  6518. }
  6519. /*
  6520. * The serial EEPROM has a checksum in the last word. Keep a
  6521. * running checksum for all words read except for the last
  6522. * word. We'll verify the checksum after all words have been
  6523. * read.
  6524. */
  6525. if (k < (sizeof(*sc) / 2) - 1)
  6526. {
  6527. checksum = checksum + seeprom[k];
  6528. }
  6529. /*
  6530. * Reset the chip select for the next command cycle.
  6531. */
  6532. aic_outb(p, 0, SEECTL_2840);
  6533. CLOCK_PULSE(p);
  6534. aic_outb(p, CK_2840, SEECTL_2840);
  6535. CLOCK_PULSE(p);
  6536. aic_outb(p, 0, SEECTL_2840);
  6537. CLOCK_PULSE(p);
  6538. }
  6539. #if 0
  6540. printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
  6541. printk("Serial EEPROM:");
  6542. for (k = 0; k < (sizeof(*sc) / 2); k++)
  6543. {
  6544. if (((k % 8) == 0) && (k != 0))
  6545. {
  6546. printk("\n ");
  6547. }
  6548. printk(" 0x%x", seeprom[k]);
  6549. }
  6550. printk("\n");
  6551. #endif
  6552. if (checksum != sc->checksum)
  6553. {
  6554. printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
  6555. return (0);
  6556. }
  6557. return (1);
  6558. #undef CLOCK_PULSE
  6559. }
  6560. #define CLOCK_PULSE(p) \
  6561. do { \
  6562. int limit = 0; \
  6563. do { \
  6564. mb(); \
  6565. pause_sequencer(p); /* This is just to generate some PCI */ \
  6566. /* traffic so the PCI read is flushed */ \
  6567. /* it shouldn't be needed, but some */ \
  6568. /* chipsets do indeed appear to need */ \
  6569. /* something to force PCI reads to get */ \
  6570. /* flushed */ \
  6571. udelay(1); /* Do nothing */ \
  6572. } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
  6573. } while(0)
  6574. /*+F*************************************************************************
  6575. * Function:
  6576. * acquire_seeprom
  6577. *
  6578. * Description:
  6579. * Acquires access to the memory port on PCI controllers.
  6580. *-F*************************************************************************/
  6581. static int
  6582. acquire_seeprom(struct aic7xxx_host *p)
  6583. {
  6584. /*
  6585. * Request access of the memory port. When access is
  6586. * granted, SEERDY will go high. We use a 1 second
  6587. * timeout which should be near 1 second more than
  6588. * is needed. Reason: after the 7870 chip reset, there
  6589. * should be no contention.
  6590. */
  6591. aic_outb(p, SEEMS, SEECTL);
  6592. CLOCK_PULSE(p);
  6593. if ((aic_inb(p, SEECTL) & SEERDY) == 0)
  6594. {
  6595. aic_outb(p, 0, SEECTL);
  6596. return (0);
  6597. }
  6598. return (1);
  6599. }
  6600. /*+F*************************************************************************
  6601. * Function:
  6602. * release_seeprom
  6603. *
  6604. * Description:
  6605. * Releases access to the memory port on PCI controllers.
  6606. *-F*************************************************************************/
  6607. static void
  6608. release_seeprom(struct aic7xxx_host *p)
  6609. {
  6610. /*
  6611. * Make sure the SEEPROM is ready before we release it.
  6612. */
  6613. CLOCK_PULSE(p);
  6614. aic_outb(p, 0, SEECTL);
  6615. }
  6616. /*+F*************************************************************************
  6617. * Function:
  6618. * read_seeprom
  6619. *
  6620. * Description:
  6621. * Reads the serial EEPROM and returns 1 if successful and 0 if
  6622. * not successful.
  6623. *
  6624. * The instruction set of the 93C46/56/66 chips is as follows:
  6625. *
  6626. * Start OP
  6627. * Function Bit Code Address Data Description
  6628. * -------------------------------------------------------------------
  6629. * READ 1 10 A5 - A0 Reads data stored in memory,
  6630. * starting at specified address
  6631. * EWEN 1 00 11XXXX Write enable must precede
  6632. * all programming modes
  6633. * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
  6634. * WRITE 1 01 A5 - A0 D15 - D0 Writes register
  6635. * ERAL 1 00 10XXXX Erase all registers
  6636. * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
  6637. * EWDS 1 00 00XXXX Disables all programming
  6638. * instructions
  6639. * *Note: A value of X for address is a don't care condition.
  6640. * *Note: The 93C56 and 93C66 have 8 address bits.
  6641. *
  6642. *
  6643. * The 93C46 has a four wire interface: clock, chip select, data in, and
  6644. * data out. In order to perform one of the above functions, you need
  6645. * to enable the chip select for a clock period (typically a minimum of
  6646. * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
  6647. * respectively. While the chip select remains high, you can clock in
  6648. * the instructions (above) starting with the start bit, followed by the
  6649. * OP code, Address, and Data (if needed). For the READ instruction, the
  6650. * requested 16-bit register contents is read from the data out line but
  6651. * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
  6652. * first). The clock cycling from low to high initiates the next data
  6653. * bit to be sent from the chip.
  6654. *
  6655. * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
  6656. * register. After successful arbitration for the memory port, the
  6657. * SEECS bit of the SEECTL register is connected to the chip select.
  6658. * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
  6659. * and data in lines respectively. The SEERDY bit of SEECTL is useful
  6660. * in that it gives us an 800 nsec timer. After a write to the SEECTL
  6661. * register, the SEERDY goes high 800 nsec later. The one exception
  6662. * to this is when we first request access to the memory port. The
  6663. * SEERDY goes high to signify that access has been granted and, for
  6664. * this case, has no implied timing.
  6665. *-F*************************************************************************/
  6666. static int
  6667. read_seeprom(struct aic7xxx_host *p, int offset,
  6668. unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
  6669. {
  6670. int i = 0, k;
  6671. unsigned char temp;
  6672. unsigned short checksum = 0;
  6673. struct seeprom_cmd {
  6674. unsigned char len;
  6675. unsigned char bits[3];
  6676. };
  6677. struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
  6678. /*
  6679. * Request access of the memory port.
  6680. */
  6681. if (acquire_seeprom(p) == 0)
  6682. {
  6683. return (0);
  6684. }
  6685. /*
  6686. * Read 'len' registers of the seeprom. For the 7870, the 93C46
  6687. * SEEPROM is a 1024-bit device with 64 16-bit registers but only
  6688. * the first 32 are used by Adaptec BIOS. Some adapters use the
  6689. * 93C56 SEEPROM which is a 2048-bit device. The loop will range
  6690. * from 0 to 'len' - 1.
  6691. */
  6692. for (k = 0; k < len; k++)
  6693. {
  6694. /*
  6695. * Send chip select for one clock cycle.
  6696. */
  6697. aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
  6698. CLOCK_PULSE(p);
  6699. /*
  6700. * Now we're ready to send the read command followed by the
  6701. * address of the 16-bit register we want to read.
  6702. */
  6703. for (i = 0; i < seeprom_read.len; i++)
  6704. {
  6705. temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
  6706. aic_outb(p, temp, SEECTL);
  6707. CLOCK_PULSE(p);
  6708. temp = temp ^ SEECK;
  6709. aic_outb(p, temp, SEECTL);
  6710. CLOCK_PULSE(p);
  6711. }
  6712. /*
  6713. * Send the 6 or 8 bit address (MSB first, LSB last).
  6714. */
  6715. for (i = ((int) chip - 1); i >= 0; i--)
  6716. {
  6717. temp = k + offset;
  6718. temp = (temp >> i) & 1; /* Mask out all but lower bit. */
  6719. temp = SEEMS | SEECS | (temp << 1);
  6720. aic_outb(p, temp, SEECTL);
  6721. CLOCK_PULSE(p);
  6722. temp = temp ^ SEECK;
  6723. aic_outb(p, temp, SEECTL);
  6724. CLOCK_PULSE(p);
  6725. }
  6726. /*
  6727. * Now read the 16 bit register. An initial 0 precedes the
  6728. * register contents which begins with bit 15 (MSB) and ends
  6729. * with bit 0 (LSB). The initial 0 will be shifted off the
  6730. * top of our word as we let the loop run from 0 to 16.
  6731. */
  6732. for (i = 0; i <= 16; i++)
  6733. {
  6734. temp = SEEMS | SEECS;
  6735. aic_outb(p, temp, SEECTL);
  6736. CLOCK_PULSE(p);
  6737. temp = temp ^ SEECK;
  6738. scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
  6739. aic_outb(p, temp, SEECTL);
  6740. CLOCK_PULSE(p);
  6741. }
  6742. /*
  6743. * The serial EEPROM should have a checksum in the last word.
  6744. * Keep a running checksum for all words read except for the
  6745. * last word. We'll verify the checksum after all words have
  6746. * been read.
  6747. */
  6748. if (k < (len - 1))
  6749. {
  6750. checksum = checksum + scarray[k];
  6751. }
  6752. /*
  6753. * Reset the chip select for the next command cycle.
  6754. */
  6755. aic_outb(p, SEEMS, SEECTL);
  6756. CLOCK_PULSE(p);
  6757. aic_outb(p, SEEMS | SEECK, SEECTL);
  6758. CLOCK_PULSE(p);
  6759. aic_outb(p, SEEMS, SEECTL);
  6760. CLOCK_PULSE(p);
  6761. }
  6762. /*
  6763. * Release access to the memory port and the serial EEPROM.
  6764. */
  6765. release_seeprom(p);
  6766. #if 0
  6767. printk("Computed checksum 0x%x, checksum read 0x%x\n",
  6768. checksum, scarray[len - 1]);
  6769. printk("Serial EEPROM:");
  6770. for (k = 0; k < len; k++)
  6771. {
  6772. if (((k % 8) == 0) && (k != 0))
  6773. {
  6774. printk("\n ");
  6775. }
  6776. printk(" 0x%x", scarray[k]);
  6777. }
  6778. printk("\n");
  6779. #endif
  6780. if ( (checksum != scarray[len - 1]) || (checksum == 0) )
  6781. {
  6782. return (0);
  6783. }
  6784. return (1);
  6785. }
  6786. /*+F*************************************************************************
  6787. * Function:
  6788. * read_brdctl
  6789. *
  6790. * Description:
  6791. * Reads the BRDCTL register.
  6792. *-F*************************************************************************/
  6793. static unsigned char
  6794. read_brdctl(struct aic7xxx_host *p)
  6795. {
  6796. unsigned char brdctl, value;
  6797. /*
  6798. * Make sure the SEEPROM is ready before we access it
  6799. */
  6800. CLOCK_PULSE(p);
  6801. if (p->features & AHC_ULTRA2)
  6802. {
  6803. brdctl = BRDRW_ULTRA2;
  6804. aic_outb(p, brdctl, BRDCTL);
  6805. CLOCK_PULSE(p);
  6806. value = aic_inb(p, BRDCTL);
  6807. CLOCK_PULSE(p);
  6808. return(value);
  6809. }
  6810. brdctl = BRDRW;
  6811. if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
  6812. (p->flags & AHC_CHNLB) )
  6813. {
  6814. brdctl |= BRDCS;
  6815. }
  6816. aic_outb(p, brdctl, BRDCTL);
  6817. CLOCK_PULSE(p);
  6818. value = aic_inb(p, BRDCTL);
  6819. CLOCK_PULSE(p);
  6820. aic_outb(p, 0, BRDCTL);
  6821. CLOCK_PULSE(p);
  6822. return (value);
  6823. }
  6824. /*+F*************************************************************************
  6825. * Function:
  6826. * write_brdctl
  6827. *
  6828. * Description:
  6829. * Writes a value to the BRDCTL register.
  6830. *-F*************************************************************************/
  6831. static void
  6832. write_brdctl(struct aic7xxx_host *p, unsigned char value)
  6833. {
  6834. unsigned char brdctl;
  6835. /*
  6836. * Make sure the SEEPROM is ready before we access it
  6837. */
  6838. CLOCK_PULSE(p);
  6839. if (p->features & AHC_ULTRA2)
  6840. {
  6841. brdctl = value;
  6842. aic_outb(p, brdctl, BRDCTL);
  6843. CLOCK_PULSE(p);
  6844. brdctl |= BRDSTB_ULTRA2;
  6845. aic_outb(p, brdctl, BRDCTL);
  6846. CLOCK_PULSE(p);
  6847. brdctl &= ~BRDSTB_ULTRA2;
  6848. aic_outb(p, brdctl, BRDCTL);
  6849. CLOCK_PULSE(p);
  6850. read_brdctl(p);
  6851. CLOCK_PULSE(p);
  6852. }
  6853. else
  6854. {
  6855. brdctl = BRDSTB;
  6856. if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
  6857. (p->flags & AHC_CHNLB) )
  6858. {
  6859. brdctl |= BRDCS;
  6860. }
  6861. brdctl = BRDSTB | BRDCS;
  6862. aic_outb(p, brdctl, BRDCTL);
  6863. CLOCK_PULSE(p);
  6864. brdctl |= value;
  6865. aic_outb(p, brdctl, BRDCTL);
  6866. CLOCK_PULSE(p);
  6867. brdctl &= ~BRDSTB;
  6868. aic_outb(p, brdctl, BRDCTL);
  6869. CLOCK_PULSE(p);
  6870. brdctl &= ~BRDCS;
  6871. aic_outb(p, brdctl, BRDCTL);
  6872. CLOCK_PULSE(p);
  6873. }
  6874. }
  6875. /*+F*************************************************************************
  6876. * Function:
  6877. * aic785x_cable_detect
  6878. *
  6879. * Description:
  6880. * Detect the cables that are present on aic785x class controller chips
  6881. *-F*************************************************************************/
  6882. static void
  6883. aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
  6884. int *ext_present, int *eeprom)
  6885. {
  6886. unsigned char brdctl;
  6887. aic_outb(p, BRDRW | BRDCS, BRDCTL);
  6888. CLOCK_PULSE(p);
  6889. aic_outb(p, 0, BRDCTL);
  6890. CLOCK_PULSE(p);
  6891. brdctl = aic_inb(p, BRDCTL);
  6892. CLOCK_PULSE(p);
  6893. *int_50 = !(brdctl & BRDDAT5);
  6894. *ext_present = !(brdctl & BRDDAT6);
  6895. *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
  6896. }
  6897. #undef CLOCK_PULSE
  6898. /*+F*************************************************************************
  6899. * Function:
  6900. * aic2940_uwpro_cable_detect
  6901. *
  6902. * Description:
  6903. * Detect the cables that are present on the 2940-UWPro cards
  6904. *
  6905. * NOTE: This function assumes the SEEPROM will have already been acquired
  6906. * prior to invocation of this function.
  6907. *-F*************************************************************************/
  6908. static void
  6909. aic2940_uwpro_wide_cable_detect(struct aic7xxx_host *p, int *int_68,
  6910. int *ext_68, int *eeprom)
  6911. {
  6912. unsigned char brdctl;
  6913. /*
  6914. * First read the status of our cables. Set the rom bank to
  6915. * 0 since the bank setting serves as a multiplexor for the
  6916. * cable detection logic. BRDDAT5 controls the bank switch.
  6917. */
  6918. write_brdctl(p, 0);
  6919. /*
  6920. * Now we read the state of the internal 68 connector. BRDDAT6
  6921. * is don't care, BRDDAT7 is internal 68. The cable is
  6922. * present if the bit is 0
  6923. */
  6924. brdctl = read_brdctl(p);
  6925. *int_68 = !(brdctl & BRDDAT7);
  6926. /*
  6927. * Set the bank bit in brdctl and then read the external cable state
  6928. * and the EEPROM status
  6929. */
  6930. write_brdctl(p, BRDDAT5);
  6931. brdctl = read_brdctl(p);
  6932. *ext_68 = !(brdctl & BRDDAT6);
  6933. *eeprom = !(brdctl & BRDDAT7);
  6934. /*
  6935. * We're done, the calling function will release the SEEPROM for us
  6936. */
  6937. }
  6938. /*+F*************************************************************************
  6939. * Function:
  6940. * aic787x_cable_detect
  6941. *
  6942. * Description:
  6943. * Detect the cables that are present on aic787x class controller chips
  6944. *
  6945. * NOTE: This function assumes the SEEPROM will have already been acquired
  6946. * prior to invocation of this function.
  6947. *-F*************************************************************************/
  6948. static void
  6949. aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
  6950. int *ext_present, int *eeprom)
  6951. {
  6952. unsigned char brdctl;
  6953. /*
  6954. * First read the status of our cables. Set the rom bank to
  6955. * 0 since the bank setting serves as a multiplexor for the
  6956. * cable detection logic. BRDDAT5 controls the bank switch.
  6957. */
  6958. write_brdctl(p, 0);
  6959. /*
  6960. * Now we read the state of the two internal connectors. BRDDAT6
  6961. * is internal 50, BRDDAT7 is internal 68. For each, the cable is
  6962. * present if the bit is 0
  6963. */
  6964. brdctl = read_brdctl(p);
  6965. *int_50 = !(brdctl & BRDDAT6);
  6966. *int_68 = !(brdctl & BRDDAT7);
  6967. /*
  6968. * Set the bank bit in brdctl and then read the external cable state
  6969. * and the EEPROM status
  6970. */
  6971. write_brdctl(p, BRDDAT5);
  6972. brdctl = read_brdctl(p);
  6973. *ext_present = !(brdctl & BRDDAT6);
  6974. *eeprom = !(brdctl & BRDDAT7);
  6975. /*
  6976. * We're done, the calling function will release the SEEPROM for us
  6977. */
  6978. }
  6979. /*+F*************************************************************************
  6980. * Function:
  6981. * aic787x_ultra2_term_detect
  6982. *
  6983. * Description:
  6984. * Detect the termination settings present on ultra2 class controllers
  6985. *
  6986. * NOTE: This function assumes the SEEPROM will have already been acquired
  6987. * prior to invocation of this function.
  6988. *-F*************************************************************************/
  6989. static void
  6990. aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
  6991. int *enableSE_high, int *enableLVD_low,
  6992. int *enableLVD_high, int *eprom_present)
  6993. {
  6994. unsigned char brdctl;
  6995. brdctl = read_brdctl(p);
  6996. *eprom_present = (brdctl & BRDDAT7);
  6997. *enableSE_high = (brdctl & BRDDAT6);
  6998. *enableSE_low = (brdctl & BRDDAT5);
  6999. *enableLVD_high = (brdctl & BRDDAT4);
  7000. *enableLVD_low = (brdctl & BRDDAT3);
  7001. }
  7002. /*+F*************************************************************************
  7003. * Function:
  7004. * configure_termination
  7005. *
  7006. * Description:
  7007. * Configures the termination settings on PCI adapters that have
  7008. * SEEPROMs available.
  7009. *-F*************************************************************************/
  7010. static void
  7011. configure_termination(struct aic7xxx_host *p)
  7012. {
  7013. int internal50_present = 0;
  7014. int internal68_present = 0;
  7015. int external_present = 0;
  7016. int eprom_present = 0;
  7017. int enableSE_low = 0;
  7018. int enableSE_high = 0;
  7019. int enableLVD_low = 0;
  7020. int enableLVD_high = 0;
  7021. unsigned char brddat = 0;
  7022. unsigned char max_target = 0;
  7023. unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
  7024. if (acquire_seeprom(p))
  7025. {
  7026. if (p->features & (AHC_WIDE|AHC_TWIN))
  7027. max_target = 16;
  7028. else
  7029. max_target = 8;
  7030. aic_outb(p, SEEMS | SEECS, SEECTL);
  7031. sxfrctl1 &= ~STPWEN;
  7032. /*
  7033. * The termination/cable detection logic is split into three distinct
  7034. * groups. Ultra2 and later controllers, 2940UW-Pro controllers, and
  7035. * older 7850, 7860, 7870, 7880, and 7895 controllers. Each has its
  7036. * own unique way of detecting their cables and writing the results
  7037. * back to the card.
  7038. */
  7039. if (p->features & AHC_ULTRA2)
  7040. {
  7041. /*
  7042. * As long as user hasn't overridden term settings, always check the
  7043. * cable detection logic
  7044. */
  7045. if (aic7xxx_override_term == -1)
  7046. {
  7047. aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
  7048. &enableLVD_low, &enableLVD_high,
  7049. &eprom_present);
  7050. }
  7051. /*
  7052. * If the user is overriding settings, then they have been preserved
  7053. * to here as fake adapter_control entries. Parse them and allow
  7054. * them to override the detected settings (if we even did detection).
  7055. */
  7056. if (!(p->adapter_control & CFSEAUTOTERM))
  7057. {
  7058. enableSE_low = (p->adapter_control & CFSTERM);
  7059. enableSE_high = (p->adapter_control & CFWSTERM);
  7060. }
  7061. if (!(p->adapter_control & CFAUTOTERM))
  7062. {
  7063. enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
  7064. }
  7065. /*
  7066. * Now take those settings that we have and translate them into the
  7067. * values that must be written into the registers.
  7068. *
  7069. * Flash Enable = BRDDAT7
  7070. * Secondary High Term Enable = BRDDAT6
  7071. * Secondary Low Term Enable = BRDDAT5
  7072. * LVD/Primary High Term Enable = BRDDAT4
  7073. * LVD/Primary Low Term Enable = STPWEN bit in SXFRCTL1
  7074. */
  7075. if (enableLVD_low != 0)
  7076. {
  7077. sxfrctl1 |= STPWEN;
  7078. p->flags |= AHC_TERM_ENB_LVD;
  7079. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7080. printk(KERN_INFO "(scsi%d) LVD/Primary Low byte termination "
  7081. "Enabled\n", p->host_no);
  7082. }
  7083. if (enableLVD_high != 0)
  7084. {
  7085. brddat |= BRDDAT4;
  7086. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7087. printk(KERN_INFO "(scsi%d) LVD/Primary High byte termination "
  7088. "Enabled\n", p->host_no);
  7089. }
  7090. if (enableSE_low != 0)
  7091. {
  7092. brddat |= BRDDAT5;
  7093. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7094. printk(KERN_INFO "(scsi%d) Secondary Low byte termination "
  7095. "Enabled\n", p->host_no);
  7096. }
  7097. if (enableSE_high != 0)
  7098. {
  7099. brddat |= BRDDAT6;
  7100. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7101. printk(KERN_INFO "(scsi%d) Secondary High byte termination "
  7102. "Enabled\n", p->host_no);
  7103. }
  7104. }
  7105. else if (p->features & AHC_NEW_AUTOTERM)
  7106. {
  7107. /*
  7108. * The 50 pin connector termination is controlled by STPWEN in the
  7109. * SXFRCTL1 register. Since the Adaptec docs typically say the
  7110. * controller is not allowed to be in the middle of a cable and
  7111. * this is the only connection on that stub of the bus, there is
  7112. * no need to even check for narrow termination, it's simply
  7113. * always on.
  7114. */
  7115. sxfrctl1 |= STPWEN;
  7116. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7117. printk(KERN_INFO "(scsi%d) Narrow channel termination Enabled\n",
  7118. p->host_no);
  7119. if (p->adapter_control & CFAUTOTERM)
  7120. {
  7121. aic2940_uwpro_wide_cable_detect(p, &internal68_present,
  7122. &external_present,
  7123. &eprom_present);
  7124. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
  7125. "Ext-68 %s)\n", p->host_no,
  7126. "Don't Care",
  7127. internal68_present ? "YES" : "NO",
  7128. external_present ? "YES" : "NO");
  7129. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7130. printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
  7131. eprom_present ? "is" : "is not");
  7132. if (internal68_present && external_present)
  7133. {
  7134. brddat = 0;
  7135. p->flags &= ~AHC_TERM_ENB_SE_HIGH;
  7136. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7137. printk(KERN_INFO "(scsi%d) Wide channel termination Disabled\n",
  7138. p->host_no);
  7139. }
  7140. else
  7141. {
  7142. brddat = BRDDAT6;
  7143. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7144. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7145. printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
  7146. p->host_no);
  7147. }
  7148. }
  7149. else
  7150. {
  7151. /*
  7152. * The termination of the Wide channel is done more like normal
  7153. * though, and the setting of this termination is done by writing
  7154. * either a 0 or 1 to BRDDAT6 of the BRDDAT register
  7155. */
  7156. if (p->adapter_control & CFWSTERM)
  7157. {
  7158. brddat = BRDDAT6;
  7159. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7160. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7161. printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
  7162. p->host_no);
  7163. }
  7164. else
  7165. {
  7166. brddat = 0;
  7167. }
  7168. }
  7169. }
  7170. else
  7171. {
  7172. if (p->adapter_control & CFAUTOTERM)
  7173. {
  7174. if (p->flags & AHC_MOTHERBOARD)
  7175. {
  7176. printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
  7177. p->host_no);
  7178. printk(KERN_INFO "(scsi%d) Please verify driver detected settings "
  7179. "are correct.\n", p->host_no);
  7180. printk(KERN_INFO "(scsi%d) If not, then please properly set the "
  7181. "device termination\n", p->host_no);
  7182. printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting "
  7183. "CTRL-A when prompted\n", p->host_no);
  7184. printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
  7185. }
  7186. /* Configure auto termination. */
  7187. if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
  7188. {
  7189. aic787x_cable_detect(p, &internal50_present, &internal68_present,
  7190. &external_present, &eprom_present);
  7191. }
  7192. else
  7193. {
  7194. aic785x_cable_detect(p, &internal50_present, &external_present,
  7195. &eprom_present);
  7196. }
  7197. if (max_target <= 8)
  7198. internal68_present = 0;
  7199. if (max_target > 8)
  7200. {
  7201. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
  7202. "Ext-68 %s)\n", p->host_no,
  7203. internal50_present ? "YES" : "NO",
  7204. internal68_present ? "YES" : "NO",
  7205. external_present ? "YES" : "NO");
  7206. }
  7207. else
  7208. {
  7209. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
  7210. p->host_no,
  7211. internal50_present ? "YES" : "NO",
  7212. external_present ? "YES" : "NO");
  7213. }
  7214. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7215. printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
  7216. eprom_present ? "is" : "is not");
  7217. /*
  7218. * Now set the termination based on what we found. BRDDAT6
  7219. * controls wide termination enable.
  7220. * Flash Enable = BRDDAT7
  7221. * SE High Term Enable = BRDDAT6
  7222. */
  7223. if (internal50_present && internal68_present && external_present)
  7224. {
  7225. printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
  7226. p->host_no);
  7227. printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
  7228. "in use at a time!\n", p->host_no);
  7229. /*
  7230. * Force termination (low and high byte) on. This is safer than
  7231. * leaving it completely off, especially since this message comes
  7232. * most often from motherboard controllers that don't even have 3
  7233. * connectors, but instead are failing the cable detection.
  7234. */
  7235. internal50_present = external_present = 0;
  7236. enableSE_high = enableSE_low = 1;
  7237. }
  7238. if ((max_target > 8) &&
  7239. ((external_present == 0) || (internal68_present == 0)) )
  7240. {
  7241. brddat |= BRDDAT6;
  7242. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7243. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7244. printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
  7245. p->host_no);
  7246. }
  7247. if ( ((internal50_present ? 1 : 0) +
  7248. (internal68_present ? 1 : 0) +
  7249. (external_present ? 1 : 0)) <= 1 )
  7250. {
  7251. sxfrctl1 |= STPWEN;
  7252. p->flags |= AHC_TERM_ENB_SE_LOW;
  7253. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7254. printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
  7255. p->host_no);
  7256. }
  7257. }
  7258. else /* p->adapter_control & CFAUTOTERM */
  7259. {
  7260. if (p->adapter_control & CFSTERM)
  7261. {
  7262. sxfrctl1 |= STPWEN;
  7263. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7264. printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
  7265. p->host_no);
  7266. }
  7267. if (p->adapter_control & CFWSTERM)
  7268. {
  7269. brddat |= BRDDAT6;
  7270. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7271. printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
  7272. p->host_no);
  7273. }
  7274. }
  7275. }
  7276. aic_outb(p, sxfrctl1, SXFRCTL1);
  7277. write_brdctl(p, brddat);
  7278. release_seeprom(p);
  7279. }
  7280. }
  7281. /*+F*************************************************************************
  7282. * Function:
  7283. * detect_maxscb
  7284. *
  7285. * Description:
  7286. * Detects the maximum number of SCBs for the controller and returns
  7287. * the count and a mask in p (p->maxscbs, p->qcntmask).
  7288. *-F*************************************************************************/
  7289. static void
  7290. detect_maxscb(struct aic7xxx_host *p)
  7291. {
  7292. int i;
  7293. /*
  7294. * It's possible that we've already done this for multichannel
  7295. * adapters.
  7296. */
  7297. if (p->scb_data->maxhscbs == 0)
  7298. {
  7299. /*
  7300. * We haven't initialized the SCB settings yet. Walk the SCBs to
  7301. * determince how many there are.
  7302. */
  7303. aic_outb(p, 0, FREE_SCBH);
  7304. for (i = 0; i < AIC7XXX_MAXSCB; i++)
  7305. {
  7306. aic_outb(p, i, SCBPTR);
  7307. aic_outb(p, i, SCB_CONTROL);
  7308. if (aic_inb(p, SCB_CONTROL) != i)
  7309. break;
  7310. aic_outb(p, 0, SCBPTR);
  7311. if (aic_inb(p, SCB_CONTROL) != 0)
  7312. break;
  7313. aic_outb(p, i, SCBPTR);
  7314. aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
  7315. aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
  7316. aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
  7317. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
  7318. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
  7319. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
  7320. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
  7321. }
  7322. /* Make sure the last SCB terminates the free list. */
  7323. aic_outb(p, i - 1, SCBPTR);
  7324. aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
  7325. /* Ensure we clear the first (0) SCBs control byte. */
  7326. aic_outb(p, 0, SCBPTR);
  7327. aic_outb(p, 0, SCB_CONTROL);
  7328. p->scb_data->maxhscbs = i;
  7329. /*
  7330. * Use direct indexing instead for speed
  7331. */
  7332. if ( i == AIC7XXX_MAXSCB )
  7333. p->flags &= ~AHC_PAGESCBS;
  7334. }
  7335. }
  7336. /*+F*************************************************************************
  7337. * Function:
  7338. * aic7xxx_register
  7339. *
  7340. * Description:
  7341. * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
  7342. *-F*************************************************************************/
  7343. static int
  7344. aic7xxx_register(Scsi_Host_Template *template, struct aic7xxx_host *p,
  7345. int reset_delay)
  7346. {
  7347. int i, result;
  7348. int max_targets;
  7349. int found = 1;
  7350. unsigned char term, scsi_conf;
  7351. struct Scsi_Host *host;
  7352. host = p->host;
  7353. p->scb_data->maxscbs = AIC7XXX_MAXSCB;
  7354. host->can_queue = AIC7XXX_MAXSCB;
  7355. host->cmd_per_lun = 3;
  7356. host->sg_tablesize = AIC7XXX_MAX_SG;
  7357. host->this_id = p->scsi_id;
  7358. host->io_port = p->base;
  7359. host->n_io_port = 0xFF;
  7360. host->base = p->mbase;
  7361. host->irq = p->irq;
  7362. if (p->features & AHC_WIDE)
  7363. {
  7364. host->max_id = 16;
  7365. }
  7366. if (p->features & AHC_TWIN)
  7367. {
  7368. host->max_channel = 1;
  7369. }
  7370. p->host = host;
  7371. p->host_no = host->host_no;
  7372. host->unique_id = p->instance;
  7373. p->isr_count = 0;
  7374. p->next = NULL;
  7375. p->completeq.head = NULL;
  7376. p->completeq.tail = NULL;
  7377. scbq_init(&p->scb_data->free_scbs);
  7378. scbq_init(&p->waiting_scbs);
  7379. INIT_LIST_HEAD(&p->aic_devs);
  7380. /*
  7381. * We currently have no commands of any type
  7382. */
  7383. p->qinfifonext = 0;
  7384. p->qoutfifonext = 0;
  7385. printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
  7386. board_names[p->board_name_index]);
  7387. switch(p->chip)
  7388. {
  7389. case (AHC_AIC7770|AHC_EISA):
  7390. printk("EISA slot %d\n", p->pci_device_fn);
  7391. break;
  7392. case (AHC_AIC7770|AHC_VL):
  7393. printk("VLB slot %d\n", p->pci_device_fn);
  7394. break;
  7395. default:
  7396. printk("PCI %d/%d/%d\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  7397. PCI_FUNC(p->pci_device_fn));
  7398. break;
  7399. }
  7400. if (p->features & AHC_TWIN)
  7401. {
  7402. printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
  7403. p->host_no, p->scsi_id, p->scsi_id_b);
  7404. }
  7405. else
  7406. {
  7407. char *channel;
  7408. channel = "";
  7409. if ((p->flags & AHC_MULTI_CHANNEL) != 0)
  7410. {
  7411. channel = " A";
  7412. if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
  7413. {
  7414. channel = (p->flags & AHC_CHNLB) ? " B" : " C";
  7415. }
  7416. }
  7417. if (p->features & AHC_WIDE)
  7418. {
  7419. printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
  7420. }
  7421. else
  7422. {
  7423. printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
  7424. }
  7425. printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
  7426. }
  7427. aic_outb(p, 0, SEQ_FLAGS);
  7428. detect_maxscb(p);
  7429. printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
  7430. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7431. {
  7432. printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
  7433. p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
  7434. p->base, p->irq);
  7435. printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at %p\n",
  7436. p->host_no, p->mbase, p->maddr);
  7437. }
  7438. #ifdef CONFIG_PCI
  7439. /*
  7440. * Now that we know our instance number, we can set the flags we need to
  7441. * force termination if need be.
  7442. */
  7443. if (aic7xxx_stpwlev != -1)
  7444. {
  7445. /*
  7446. * This option only applies to PCI controllers.
  7447. */
  7448. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
  7449. {
  7450. unsigned char devconfig;
  7451. pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
  7452. if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
  7453. {
  7454. devconfig |= STPWLEVEL;
  7455. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7456. printk("(scsi%d) Force setting STPWLEVEL bit\n", p->host_no);
  7457. }
  7458. else
  7459. {
  7460. devconfig &= ~STPWLEVEL;
  7461. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7462. printk("(scsi%d) Force clearing STPWLEVEL bit\n", p->host_no);
  7463. }
  7464. pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
  7465. }
  7466. }
  7467. #endif
  7468. /*
  7469. * That took care of devconfig and stpwlev, now for the actual termination
  7470. * settings.
  7471. */
  7472. if (aic7xxx_override_term != -1)
  7473. {
  7474. /*
  7475. * Again, this only applies to PCI controllers. We don't have problems
  7476. * with the termination on 274x controllers to the best of my knowledge.
  7477. */
  7478. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
  7479. {
  7480. unsigned char term_override;
  7481. term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
  7482. p->adapter_control &=
  7483. ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
  7484. if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
  7485. {
  7486. p->adapter_control |= CFLVDSTERM;
  7487. }
  7488. if (term_override & 0x02)
  7489. {
  7490. p->adapter_control |= CFWSTERM;
  7491. }
  7492. if (term_override & 0x01)
  7493. {
  7494. p->adapter_control |= CFSTERM;
  7495. }
  7496. }
  7497. }
  7498. if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
  7499. {
  7500. if (p->features & AHC_SPIOCAP)
  7501. {
  7502. if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
  7503. /*
  7504. * Update the settings in sxfrctl1 to match the termination
  7505. * settings.
  7506. */
  7507. configure_termination(p);
  7508. }
  7509. else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
  7510. {
  7511. configure_termination(p);
  7512. }
  7513. }
  7514. /*
  7515. * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
  7516. */
  7517. if (p->features & AHC_TWIN)
  7518. {
  7519. /* Select channel B */
  7520. aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
  7521. if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
  7522. term = (aic_inb(p, SXFRCTL1) & STPWEN);
  7523. else
  7524. term = ((p->flags & AHC_TERM_ENB_B) ? STPWEN : 0);
  7525. aic_outb(p, p->scsi_id_b, SCSIID);
  7526. scsi_conf = aic_inb(p, SCSICONF + 1);
  7527. aic_outb(p, DFON | SPIOEN, SXFRCTL0);
  7528. aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
  7529. ENSTIMER | ACTNEGEN, SXFRCTL1);
  7530. aic_outb(p, 0, SIMODE0);
  7531. aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
  7532. aic_outb(p, 0, SCSIRATE);
  7533. /* Select channel A */
  7534. aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
  7535. }
  7536. if (p->features & AHC_ULTRA2)
  7537. {
  7538. aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
  7539. }
  7540. else
  7541. {
  7542. aic_outb(p, p->scsi_id, SCSIID);
  7543. }
  7544. if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
  7545. term = (aic_inb(p, SXFRCTL1) & STPWEN);
  7546. else
  7547. term = ((p->flags & (AHC_TERM_ENB_A|AHC_TERM_ENB_LVD)) ? STPWEN : 0);
  7548. scsi_conf = aic_inb(p, SCSICONF);
  7549. aic_outb(p, DFON | SPIOEN, SXFRCTL0);
  7550. aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
  7551. ENSTIMER | ACTNEGEN, SXFRCTL1);
  7552. aic_outb(p, 0, SIMODE0);
  7553. /*
  7554. * If we are a cardbus adapter then don't enable SCSI reset detection.
  7555. * We shouldn't likely be sharing SCSI busses with someone else, and
  7556. * if we don't have a cable currently plugged into the controller then
  7557. * we won't have a power source for the SCSI termination, which means
  7558. * we'll see infinite incoming bus resets.
  7559. */
  7560. if(p->flags & AHC_NO_STPWEN)
  7561. aic_outb(p, ENSELTIMO | ENSCSIPERR, SIMODE1);
  7562. else
  7563. aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
  7564. aic_outb(p, 0, SCSIRATE);
  7565. if ( p->features & AHC_ULTRA2)
  7566. aic_outb(p, 0, SCSIOFFSET);
  7567. /*
  7568. * Look at the information that board initialization or the board
  7569. * BIOS has left us. In the lower four bits of each target's
  7570. * scratch space any value other than 0 indicates that we should
  7571. * initiate synchronous transfers. If it's zero, the user or the
  7572. * BIOS has decided to disable synchronous negotiation to that
  7573. * target so we don't activate the needsdtr flag.
  7574. */
  7575. if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
  7576. {
  7577. max_targets = 8;
  7578. }
  7579. else
  7580. {
  7581. max_targets = 16;
  7582. }
  7583. if (!(aic7xxx_no_reset))
  7584. {
  7585. /*
  7586. * If we reset the bus, then clear the transfer settings, else leave
  7587. * them be.
  7588. */
  7589. aic_outb(p, 0, ULTRA_ENB);
  7590. aic_outb(p, 0, ULTRA_ENB + 1);
  7591. p->ultraenb = 0;
  7592. }
  7593. /*
  7594. * Allocate enough hardware scbs to handle the maximum number of
  7595. * concurrent transactions we can have. We have to make sure that
  7596. * the allocated memory is contiguous memory. The Linux kmalloc
  7597. * routine should only allocate contiguous memory, but note that
  7598. * this could be a problem if kmalloc() is changed.
  7599. */
  7600. {
  7601. size_t array_size;
  7602. unsigned int hscb_physaddr;
  7603. array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
  7604. if (p->scb_data->hscbs == NULL)
  7605. {
  7606. /* pci_alloc_consistent enforces the alignment already and
  7607. * clears the area as well.
  7608. */
  7609. p->scb_data->hscbs = pci_alloc_consistent(p->pdev, array_size,
  7610. &p->scb_data->hscbs_dma);
  7611. /* We have to use pci_free_consistent, not kfree */
  7612. p->scb_data->hscb_kmalloc_ptr = NULL;
  7613. p->scb_data->hscbs_dma_len = array_size;
  7614. }
  7615. if (p->scb_data->hscbs == NULL)
  7616. {
  7617. printk("(scsi%d) Unable to allocate hardware SCB array; "
  7618. "failing detection.\n", p->host_no);
  7619. aic_outb(p, 0, SIMODE1);
  7620. p->irq = 0;
  7621. return(0);
  7622. }
  7623. hscb_physaddr = p->scb_data->hscbs_dma;
  7624. aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
  7625. aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
  7626. aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
  7627. aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
  7628. /* Set up the fifo areas at the same time */
  7629. p->untagged_scbs = pci_alloc_consistent(p->pdev, 3*256, &p->fifo_dma);
  7630. if (p->untagged_scbs == NULL)
  7631. {
  7632. printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
  7633. "failing detection.\n", p->host_no);
  7634. p->irq = 0;
  7635. return(0);
  7636. }
  7637. p->qoutfifo = p->untagged_scbs + 256;
  7638. p->qinfifo = p->qoutfifo + 256;
  7639. for (i = 0; i < 256; i++)
  7640. {
  7641. p->untagged_scbs[i] = SCB_LIST_NULL;
  7642. p->qinfifo[i] = SCB_LIST_NULL;
  7643. p->qoutfifo[i] = SCB_LIST_NULL;
  7644. }
  7645. hscb_physaddr = p->fifo_dma;
  7646. aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
  7647. aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
  7648. aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
  7649. aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
  7650. }
  7651. /* The Q-FIFOs we just set up are all empty */
  7652. aic_outb(p, 0, QINPOS);
  7653. aic_outb(p, 0, KERNEL_QINPOS);
  7654. aic_outb(p, 0, QOUTPOS);
  7655. if(p->features & AHC_QUEUE_REGS)
  7656. {
  7657. aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
  7658. aic_outb(p, 0, SDSCB_QOFF);
  7659. aic_outb(p, 0, SNSCB_QOFF);
  7660. aic_outb(p, 0, HNSCB_QOFF);
  7661. }
  7662. /*
  7663. * We don't have any waiting selections or disconnected SCBs.
  7664. */
  7665. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  7666. aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
  7667. /*
  7668. * Message out buffer starts empty
  7669. */
  7670. aic_outb(p, MSG_NOOP, MSG_OUT);
  7671. aic_outb(p, MSG_NOOP, LAST_MSG);
  7672. /*
  7673. * Set all the other asundry items that haven't been set yet.
  7674. * This includes just dumping init values to a lot of registers simply
  7675. * to make sure they've been touched and are ready for use parity wise
  7676. * speaking.
  7677. */
  7678. aic_outb(p, 0, TMODE_CMDADDR);
  7679. aic_outb(p, 0, TMODE_CMDADDR + 1);
  7680. aic_outb(p, 0, TMODE_CMDADDR + 2);
  7681. aic_outb(p, 0, TMODE_CMDADDR + 3);
  7682. aic_outb(p, 0, TMODE_CMDADDR_NEXT);
  7683. /*
  7684. * Link us into the list of valid hosts
  7685. */
  7686. p->next = first_aic7xxx;
  7687. first_aic7xxx = p;
  7688. /*
  7689. * Allocate the first set of scbs for this controller. This is to stream-
  7690. * line code elsewhere in the driver. If we have to check for the existence
  7691. * of scbs in certain code sections, it slows things down. However, as
  7692. * soon as we register the IRQ for this card, we could get an interrupt that
  7693. * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
  7694. * then we are likely to segfault if we don't have at least one chunk of
  7695. * SCBs allocated or add checks all through the reset code to make sure
  7696. * that the SCBs have been allocated which is an invalid running condition
  7697. * and therefore I think it's preferable to simply pre-allocate the first
  7698. * chunk of SCBs.
  7699. */
  7700. aic7xxx_allocate_scb(p);
  7701. /*
  7702. * Load the sequencer program, then re-enable the board -
  7703. * resetting the AIC-7770 disables it, leaving the lights
  7704. * on with nobody home.
  7705. */
  7706. aic7xxx_loadseq(p);
  7707. /*
  7708. * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
  7709. */
  7710. aic_outb(p, aic_inb(p, SBLKCTL) & ~AUTOFLUSHDIS, SBLKCTL);
  7711. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  7712. {
  7713. aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
  7714. }
  7715. if ( !(aic7xxx_no_reset) )
  7716. {
  7717. if (p->features & AHC_TWIN)
  7718. {
  7719. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7720. printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
  7721. aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
  7722. aic7xxx_reset_current_bus(p);
  7723. aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
  7724. }
  7725. /* Reset SCSI bus A. */
  7726. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7727. { /* In case we are a 3940, 3985, or 7895, print the right channel */
  7728. char *channel = "";
  7729. if (p->flags & AHC_MULTI_CHANNEL)
  7730. {
  7731. channel = " A";
  7732. if (p->flags & (AHC_CHNLB|AHC_CHNLC))
  7733. channel = (p->flags & AHC_CHNLB) ? " B" : " C";
  7734. }
  7735. printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
  7736. }
  7737. aic7xxx_reset_current_bus(p);
  7738. }
  7739. else
  7740. {
  7741. if (!reset_delay)
  7742. {
  7743. printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
  7744. "the no_reset\n", p->host_no);
  7745. printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
  7746. "for it.\n", p->host_no);
  7747. }
  7748. }
  7749. /*
  7750. * Register IRQ with the kernel. Only allow sharing IRQs with
  7751. * PCI devices.
  7752. */
  7753. if (!(p->chip & AHC_PCI))
  7754. {
  7755. result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
  7756. }
  7757. else
  7758. {
  7759. result = (request_irq(p->irq, do_aic7xxx_isr, SA_SHIRQ,
  7760. "aic7xxx", p));
  7761. if (result < 0)
  7762. {
  7763. result = (request_irq(p->irq, do_aic7xxx_isr, SA_INTERRUPT | SA_SHIRQ,
  7764. "aic7xxx", p));
  7765. }
  7766. }
  7767. if (result < 0)
  7768. {
  7769. printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
  7770. "controller.\n", p->host_no, p->irq);
  7771. aic_outb(p, 0, SIMODE1);
  7772. p->irq = 0;
  7773. return (0);
  7774. }
  7775. if(aic_inb(p, INTSTAT) & INT_PEND)
  7776. printk(INFO_LEAD "spurious interrupt during configuration, cleared.\n",
  7777. p->host_no, -1, -1 , -1);
  7778. aic7xxx_clear_intstat(p);
  7779. unpause_sequencer(p, /* unpause_always */ TRUE);
  7780. return (found);
  7781. }
  7782. /*+F*************************************************************************
  7783. * Function:
  7784. * aic7xxx_chip_reset
  7785. *
  7786. * Description:
  7787. * Perform a chip reset on the aic7xxx SCSI controller. The controller
  7788. * is paused upon return.
  7789. *-F*************************************************************************/
  7790. static int
  7791. aic7xxx_chip_reset(struct aic7xxx_host *p)
  7792. {
  7793. unsigned char sblkctl;
  7794. int wait;
  7795. /*
  7796. * For some 274x boards, we must clear the CHIPRST bit and pause
  7797. * the sequencer. For some reason, this makes the driver work.
  7798. */
  7799. aic_outb(p, PAUSE | CHIPRST, HCNTRL);
  7800. /*
  7801. * In the future, we may call this function as a last resort for
  7802. * error handling. Let's be nice and not do any unnecessary delays.
  7803. */
  7804. wait = 1000; /* 1 msec (1000 * 1 msec) */
  7805. while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
  7806. {
  7807. udelay(1); /* 1 usec */
  7808. }
  7809. pause_sequencer(p);
  7810. sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
  7811. if (p->chip & AHC_PCI)
  7812. sblkctl &= ~SELBUSB;
  7813. switch( sblkctl )
  7814. {
  7815. case 0: /* normal narrow card */
  7816. break;
  7817. case 2: /* Wide card */
  7818. p->features |= AHC_WIDE;
  7819. break;
  7820. case 8: /* Twin card */
  7821. p->features |= AHC_TWIN;
  7822. p->flags |= AHC_MULTI_CHANNEL;
  7823. break;
  7824. default: /* hmmm...we don't know what this is */
  7825. printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
  7826. aic_inb(p, SBLKCTL) & 0x0a);
  7827. return(-1);
  7828. }
  7829. return(0);
  7830. }
  7831. /*+F*************************************************************************
  7832. * Function:
  7833. * aic7xxx_alloc
  7834. *
  7835. * Description:
  7836. * Allocate and initialize a host structure. Returns NULL upon error
  7837. * and a pointer to a aic7xxx_host struct upon success.
  7838. *-F*************************************************************************/
  7839. static struct aic7xxx_host *
  7840. aic7xxx_alloc(Scsi_Host_Template *sht, struct aic7xxx_host *temp)
  7841. {
  7842. struct aic7xxx_host *p = NULL;
  7843. struct Scsi_Host *host;
  7844. /*
  7845. * Allocate a storage area by registering us with the mid-level
  7846. * SCSI layer.
  7847. */
  7848. host = scsi_register(sht, sizeof(struct aic7xxx_host));
  7849. if (host != NULL)
  7850. {
  7851. p = (struct aic7xxx_host *) host->hostdata;
  7852. memset(p, 0, sizeof(struct aic7xxx_host));
  7853. *p = *temp;
  7854. p->host = host;
  7855. p->scb_data = kmalloc(sizeof(scb_data_type), GFP_ATOMIC);
  7856. if (p->scb_data != NULL)
  7857. {
  7858. memset(p->scb_data, 0, sizeof(scb_data_type));
  7859. scbq_init (&p->scb_data->free_scbs);
  7860. }
  7861. else
  7862. {
  7863. /*
  7864. * For some reason we don't have enough memory. Free the
  7865. * allocated memory for the aic7xxx_host struct, and return NULL.
  7866. */
  7867. release_region(p->base, MAXREG - MINREG);
  7868. scsi_unregister(host);
  7869. return(NULL);
  7870. }
  7871. p->host_no = host->host_no;
  7872. }
  7873. return (p);
  7874. }
  7875. /*+F*************************************************************************
  7876. * Function:
  7877. * aic7xxx_free
  7878. *
  7879. * Description:
  7880. * Frees and releases all resources associated with an instance of
  7881. * the driver (struct aic7xxx_host *).
  7882. *-F*************************************************************************/
  7883. static void
  7884. aic7xxx_free(struct aic7xxx_host *p)
  7885. {
  7886. int i;
  7887. /*
  7888. * Free the allocated hardware SCB space.
  7889. */
  7890. if (p->scb_data != NULL)
  7891. {
  7892. struct aic7xxx_scb_dma *scb_dma = NULL;
  7893. if (p->scb_data->hscbs != NULL)
  7894. {
  7895. pci_free_consistent(p->pdev, p->scb_data->hscbs_dma_len,
  7896. p->scb_data->hscbs, p->scb_data->hscbs_dma);
  7897. p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
  7898. }
  7899. /*
  7900. * Free the driver SCBs. These were allocated on an as-need
  7901. * basis. We allocated these in groups depending on how many
  7902. * we could fit into a given amount of RAM. The tail SCB for
  7903. * these allocations has a pointer to the alloced area.
  7904. */
  7905. for (i = 0; i < p->scb_data->numscbs; i++)
  7906. {
  7907. if (p->scb_data->scb_array[i]->scb_dma != scb_dma)
  7908. {
  7909. scb_dma = p->scb_data->scb_array[i]->scb_dma;
  7910. pci_free_consistent(p->pdev, scb_dma->dma_len,
  7911. (void *)((unsigned long)scb_dma->dma_address
  7912. - scb_dma->dma_offset),
  7913. scb_dma->dma_address);
  7914. }
  7915. if (p->scb_data->scb_array[i]->kmalloc_ptr != NULL)
  7916. kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
  7917. p->scb_data->scb_array[i] = NULL;
  7918. }
  7919. /*
  7920. * Free the SCB data area.
  7921. */
  7922. kfree(p->scb_data);
  7923. }
  7924. pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
  7925. }
  7926. /*+F*************************************************************************
  7927. * Function:
  7928. * aic7xxx_load_seeprom
  7929. *
  7930. * Description:
  7931. * Load the seeprom and configure adapter and target settings.
  7932. * Returns 1 if the load was successful and 0 otherwise.
  7933. *-F*************************************************************************/
  7934. static void
  7935. aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
  7936. {
  7937. int have_seeprom = 0;
  7938. int i, max_targets, mask;
  7939. unsigned char scsirate, scsi_conf;
  7940. unsigned short scarray[128];
  7941. struct seeprom_config *sc = (struct seeprom_config *) scarray;
  7942. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7943. {
  7944. printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
  7945. }
  7946. switch (p->chip)
  7947. {
  7948. case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
  7949. if (aic_inb(p, SCSICONF) & TERM_ENB)
  7950. p->flags |= AHC_TERM_ENB_A;
  7951. if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
  7952. p->flags |= AHC_TERM_ENB_B;
  7953. break;
  7954. case (AHC_AIC7770|AHC_VL):
  7955. have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
  7956. break;
  7957. default:
  7958. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7959. scarray, p->sc_size, p->sc_type);
  7960. if (!have_seeprom)
  7961. {
  7962. if(p->sc_type == C46)
  7963. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7964. scarray, p->sc_size, C56_66);
  7965. else
  7966. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7967. scarray, p->sc_size, C46);
  7968. }
  7969. if (!have_seeprom)
  7970. {
  7971. p->sc_size = 128;
  7972. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7973. scarray, p->sc_size, p->sc_type);
  7974. if (!have_seeprom)
  7975. {
  7976. if(p->sc_type == C46)
  7977. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7978. scarray, p->sc_size, C56_66);
  7979. else
  7980. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7981. scarray, p->sc_size, C46);
  7982. }
  7983. }
  7984. break;
  7985. }
  7986. if (!have_seeprom)
  7987. {
  7988. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7989. {
  7990. printk("\naic7xxx: No SEEPROM available.\n");
  7991. }
  7992. p->flags |= AHC_NEWEEPROM_FMT;
  7993. if (aic_inb(p, SCSISEQ) == 0)
  7994. {
  7995. p->flags |= AHC_USEDEFAULTS;
  7996. p->flags &= ~AHC_BIOS_ENABLED;
  7997. p->scsi_id = p->scsi_id_b = 7;
  7998. *sxfrctl1 |= STPWEN;
  7999. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8000. {
  8001. printk("aic7xxx: Using default values.\n");
  8002. }
  8003. }
  8004. else if (aic7xxx_verbose & VERBOSE_PROBE2)
  8005. {
  8006. printk("aic7xxx: Using leftover BIOS values.\n");
  8007. }
  8008. if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
  8009. {
  8010. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8011. sc->adapter_control &= ~CFAUTOTERM;
  8012. sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
  8013. }
  8014. if (aic7xxx_extended)
  8015. p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  8016. else
  8017. p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  8018. }
  8019. else
  8020. {
  8021. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8022. {
  8023. printk("done\n");
  8024. }
  8025. /*
  8026. * Note things in our flags
  8027. */
  8028. p->flags |= AHC_SEEPROM_FOUND;
  8029. /*
  8030. * Update the settings in sxfrctl1 to match the termination settings.
  8031. */
  8032. *sxfrctl1 = 0;
  8033. /*
  8034. * Get our SCSI ID from the SEEPROM setting...
  8035. */
  8036. p->scsi_id = (sc->brtime_id & CFSCSIID);
  8037. /*
  8038. * First process the settings that are different between the VLB
  8039. * and PCI adapter seeproms.
  8040. */
  8041. if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
  8042. {
  8043. /* VLB adapter seeproms */
  8044. if (sc->bios_control & CF284XEXTEND)
  8045. p->flags |= AHC_EXTEND_TRANS_A;
  8046. if (sc->adapter_control & CF284XSTERM)
  8047. {
  8048. *sxfrctl1 |= STPWEN;
  8049. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8050. }
  8051. }
  8052. else
  8053. {
  8054. /* PCI adapter seeproms */
  8055. if (sc->bios_control & CFEXTEND)
  8056. p->flags |= AHC_EXTEND_TRANS_A;
  8057. if (sc->bios_control & CFBIOSEN)
  8058. p->flags |= AHC_BIOS_ENABLED;
  8059. else
  8060. p->flags &= ~AHC_BIOS_ENABLED;
  8061. if (sc->adapter_control & CFSTERM)
  8062. {
  8063. *sxfrctl1 |= STPWEN;
  8064. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8065. }
  8066. }
  8067. memcpy(&p->sc, sc, sizeof(struct seeprom_config));
  8068. }
  8069. p->discenable = 0;
  8070. /*
  8071. * Limit to 16 targets just in case. The 2842 for one is known to
  8072. * blow the max_targets setting, future cards might also.
  8073. */
  8074. max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
  8075. if (have_seeprom)
  8076. {
  8077. for (i = 0; i < max_targets; i++)
  8078. {
  8079. if( ((p->features & AHC_ULTRA) &&
  8080. !(sc->adapter_control & CFULTRAEN) &&
  8081. (sc->device_flags[i] & CFSYNCHISULTRA)) ||
  8082. (sc->device_flags[i] & CFNEWULTRAFORMAT) )
  8083. {
  8084. p->flags |= AHC_NEWEEPROM_FMT;
  8085. break;
  8086. }
  8087. }
  8088. }
  8089. for (i = 0; i < max_targets; i++)
  8090. {
  8091. mask = (0x01 << i);
  8092. if (!have_seeprom)
  8093. {
  8094. if (aic_inb(p, SCSISEQ) != 0)
  8095. {
  8096. /*
  8097. * OK...the BIOS set things up and left behind the settings we need.
  8098. * Just make our sc->device_flags[i] entry match what the card has
  8099. * set for this device.
  8100. */
  8101. p->discenable =
  8102. ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
  8103. p->ultraenb =
  8104. (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
  8105. sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
  8106. if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
  8107. sc->device_flags[i] |= CFWIDEB;
  8108. if (p->features & AHC_ULTRA2)
  8109. {
  8110. if (aic_inb(p, TARG_OFFSET + i))
  8111. {
  8112. sc->device_flags[i] |= CFSYNCH;
  8113. sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
  8114. if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
  8115. sc->device_flags[i] |= CFSYNCHISULTRA;
  8116. }
  8117. }
  8118. else
  8119. {
  8120. if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
  8121. {
  8122. sc->device_flags[i] |= CFSYNCH;
  8123. if (p->features & AHC_ULTRA)
  8124. sc->device_flags[i] |= ((p->ultraenb & mask) ?
  8125. CFSYNCHISULTRA : 0);
  8126. }
  8127. }
  8128. }
  8129. else
  8130. {
  8131. /*
  8132. * Assume the BIOS has NOT been run on this card and nothing between
  8133. * the card and the devices is configured yet.
  8134. */
  8135. sc->device_flags[i] = CFDISC;
  8136. if (p->features & AHC_WIDE)
  8137. sc->device_flags[i] |= CFWIDEB;
  8138. if (p->features & AHC_ULTRA3)
  8139. sc->device_flags[i] |= 2;
  8140. else if (p->features & AHC_ULTRA2)
  8141. sc->device_flags[i] |= 3;
  8142. else if (p->features & AHC_ULTRA)
  8143. sc->device_flags[i] |= CFSYNCHISULTRA;
  8144. sc->device_flags[i] |= CFSYNCH;
  8145. aic_outb(p, 0, TARG_SCSIRATE + i);
  8146. if (p->features & AHC_ULTRA2)
  8147. aic_outb(p, 0, TARG_OFFSET + i);
  8148. }
  8149. }
  8150. if (sc->device_flags[i] & CFDISC)
  8151. {
  8152. p->discenable |= mask;
  8153. }
  8154. if (p->flags & AHC_NEWEEPROM_FMT)
  8155. {
  8156. if ( !(p->features & AHC_ULTRA2) )
  8157. {
  8158. /*
  8159. * I know of two different Ultra BIOSes that do this differently.
  8160. * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
  8161. * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
  8162. * while on the IBM Netfinity 5000 they want the same thing
  8163. * to be something else, while flags[i] & CFXFER == 0x03 and
  8164. * SYNCHISULTRA false should be 40MByte/s. So, we set both to
  8165. * 40MByte/s and the lower speeds be damned. People will have
  8166. * to select around the conversely mapped lower speeds in order
  8167. * to select lower speeds on these boards.
  8168. */
  8169. if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8170. ((sc->device_flags[i] & CFXFER) == 0x03) )
  8171. {
  8172. sc->device_flags[i] &= ~CFXFER;
  8173. sc->device_flags[i] |= CFSYNCHISULTRA;
  8174. }
  8175. if (sc->device_flags[i] & CFSYNCHISULTRA)
  8176. {
  8177. p->ultraenb |= mask;
  8178. }
  8179. }
  8180. else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8181. (p->features & AHC_ULTRA2) &&
  8182. (sc->device_flags[i] & CFSYNCHISULTRA) )
  8183. {
  8184. p->ultraenb |= mask;
  8185. }
  8186. }
  8187. else if (sc->adapter_control & CFULTRAEN)
  8188. {
  8189. p->ultraenb |= mask;
  8190. }
  8191. if ( (sc->device_flags[i] & CFSYNCH) == 0)
  8192. {
  8193. sc->device_flags[i] &= ~CFXFER;
  8194. p->ultraenb &= ~mask;
  8195. p->user[i].offset = 0;
  8196. p->user[i].period = 0;
  8197. p->user[i].options = 0;
  8198. }
  8199. else
  8200. {
  8201. if (p->features & AHC_ULTRA3)
  8202. {
  8203. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8204. if( (sc->device_flags[i] & CFXFER) < 0x03 )
  8205. {
  8206. scsirate = (sc->device_flags[i] & CFXFER);
  8207. p->user[i].options = MSG_EXT_PPR_OPTION_DT_CRC;
  8208. }
  8209. else
  8210. {
  8211. scsirate = (sc->device_flags[i] & CFXFER) |
  8212. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8213. p->user[i].options = 0;
  8214. }
  8215. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8216. AHC_SYNCRATE_ULTRA3);
  8217. }
  8218. else if (p->features & AHC_ULTRA2)
  8219. {
  8220. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8221. scsirate = (sc->device_flags[i] & CFXFER) |
  8222. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8223. p->user[i].options = 0;
  8224. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8225. AHC_SYNCRATE_ULTRA2);
  8226. }
  8227. else
  8228. {
  8229. scsirate = (sc->device_flags[i] & CFXFER) << 4;
  8230. p->user[i].options = 0;
  8231. p->user[i].offset = MAX_OFFSET_8BIT;
  8232. if (p->features & AHC_ULTRA)
  8233. {
  8234. short ultraenb;
  8235. ultraenb = aic_inb(p, ULTRA_ENB) |
  8236. (aic_inb(p, ULTRA_ENB + 1) << 8);
  8237. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8238. (p->ultraenb & mask) ?
  8239. AHC_SYNCRATE_ULTRA :
  8240. AHC_SYNCRATE_FAST);
  8241. }
  8242. else
  8243. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8244. AHC_SYNCRATE_FAST);
  8245. }
  8246. }
  8247. if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
  8248. {
  8249. p->user[i].width = MSG_EXT_WDTR_BUS_16_BIT;
  8250. }
  8251. else
  8252. {
  8253. p->user[i].width = MSG_EXT_WDTR_BUS_8_BIT;
  8254. }
  8255. }
  8256. aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
  8257. aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
  8258. /*
  8259. * We set the p->ultraenb from the SEEPROM to begin with, but now we make
  8260. * it match what is already down in the card. If we are doing a reset
  8261. * on the card then this will get put back to a default state anyway.
  8262. * This allows us to not have to pre-emptively negotiate when using the
  8263. * no_reset option.
  8264. */
  8265. if (p->features & AHC_ULTRA)
  8266. p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
  8267. scsi_conf = (p->scsi_id & HSCSIID);
  8268. if(have_seeprom)
  8269. {
  8270. p->adapter_control = sc->adapter_control;
  8271. p->bios_control = sc->bios_control;
  8272. switch (p->chip & AHC_CHIPID_MASK)
  8273. {
  8274. case AHC_AIC7895:
  8275. case AHC_AIC7896:
  8276. case AHC_AIC7899:
  8277. if (p->adapter_control & CFBPRIMARY)
  8278. p->flags |= AHC_CHANNEL_B_PRIMARY;
  8279. default:
  8280. break;
  8281. }
  8282. if (sc->adapter_control & CFSPARITY)
  8283. scsi_conf |= ENSPCHK;
  8284. }
  8285. else
  8286. {
  8287. scsi_conf |= ENSPCHK | RESET_SCSI;
  8288. }
  8289. /*
  8290. * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
  8291. * The 2842 and 2742 cards already have these registers set and we don't
  8292. * want to muck with them since we don't set all the bits they do.
  8293. */
  8294. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  8295. {
  8296. /* Set the host ID */
  8297. aic_outb(p, scsi_conf, SCSICONF);
  8298. /* In case we are a wide card */
  8299. aic_outb(p, p->scsi_id, SCSICONF + 1);
  8300. }
  8301. }
  8302. /*+F*************************************************************************
  8303. * Function:
  8304. * aic7xxx_configure_bugs
  8305. *
  8306. * Description:
  8307. * Take the card passed in and set the appropriate bug flags based upon
  8308. * the card model. Also make any changes needed to device registers or
  8309. * PCI registers while we are here.
  8310. *-F*************************************************************************/
  8311. static void
  8312. aic7xxx_configure_bugs(struct aic7xxx_host *p)
  8313. {
  8314. unsigned short tmp_word;
  8315. switch(p->chip & AHC_CHIPID_MASK)
  8316. {
  8317. case AHC_AIC7860:
  8318. p->bugs |= AHC_BUG_PCI_2_1_RETRY;
  8319. /* fall through */
  8320. case AHC_AIC7850:
  8321. case AHC_AIC7870:
  8322. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8323. break;
  8324. case AHC_AIC7880:
  8325. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8326. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8327. break;
  8328. case AHC_AIC7890:
  8329. p->bugs |= AHC_BUG_AUTOFLUSH | AHC_BUG_CACHETHEN;
  8330. break;
  8331. case AHC_AIC7892:
  8332. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8333. break;
  8334. case AHC_AIC7895:
  8335. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8336. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8337. break;
  8338. case AHC_AIC7896:
  8339. p->bugs |= AHC_BUG_CACHETHEN_DIS;
  8340. break;
  8341. case AHC_AIC7899:
  8342. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8343. break;
  8344. default:
  8345. /* Nothing to do */
  8346. break;
  8347. }
  8348. /*
  8349. * Now handle the bugs that require PCI register or card register tweaks
  8350. */
  8351. pci_read_config_word(p->pdev, PCI_COMMAND, &tmp_word);
  8352. if(p->bugs & AHC_BUG_PCI_MWI)
  8353. {
  8354. tmp_word &= ~PCI_COMMAND_INVALIDATE;
  8355. }
  8356. else
  8357. {
  8358. tmp_word |= PCI_COMMAND_INVALIDATE;
  8359. }
  8360. pci_write_config_word(p->pdev, PCI_COMMAND, tmp_word);
  8361. if(p->bugs & AHC_BUG_CACHETHEN)
  8362. {
  8363. aic_outb(p, aic_inb(p, DSCOMMAND0) & ~CACHETHEN, DSCOMMAND0);
  8364. }
  8365. else if (p->bugs & AHC_BUG_CACHETHEN_DIS)
  8366. {
  8367. aic_outb(p, aic_inb(p, DSCOMMAND0) | CACHETHEN, DSCOMMAND0);
  8368. }
  8369. return;
  8370. }
  8371. /*+F*************************************************************************
  8372. * Function:
  8373. * aic7xxx_detect
  8374. *
  8375. * Description:
  8376. * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
  8377. *
  8378. * XXX - This should really be called aic7xxx_probe(). A sequence of
  8379. * probe(), attach()/detach(), and init() makes more sense than
  8380. * one do-it-all function. This may be useful when (and if) the
  8381. * mid-level SCSI code is overhauled.
  8382. *-F*************************************************************************/
  8383. static int
  8384. aic7xxx_detect(Scsi_Host_Template *template)
  8385. {
  8386. struct aic7xxx_host *temp_p = NULL;
  8387. struct aic7xxx_host *current_p = NULL;
  8388. struct aic7xxx_host *list_p = NULL;
  8389. int found = 0;
  8390. #if defined(__i386__) || defined(__alpha__)
  8391. ahc_flag_type flags = 0;
  8392. int type;
  8393. #endif
  8394. unsigned char sxfrctl1;
  8395. #if defined(__i386__) || defined(__alpha__)
  8396. unsigned char hcntrl, hostconf;
  8397. unsigned int slot, base;
  8398. #endif
  8399. #ifdef MODULE
  8400. /*
  8401. * If we are called as a module, the aic7xxx pointer may not be null
  8402. * and it would point to our bootup string, just like on the lilo
  8403. * command line. IF not NULL, then process this config string with
  8404. * aic7xxx_setup
  8405. */
  8406. if(aic7xxx)
  8407. aic7xxx_setup(aic7xxx);
  8408. #endif
  8409. template->proc_name = "aic7xxx";
  8410. template->sg_tablesize = AIC7XXX_MAX_SG;
  8411. #ifdef CONFIG_PCI
  8412. /*
  8413. * PCI-bus probe.
  8414. */
  8415. {
  8416. static struct
  8417. {
  8418. unsigned short vendor_id;
  8419. unsigned short device_id;
  8420. ahc_chip chip;
  8421. ahc_flag_type flags;
  8422. ahc_feature features;
  8423. int board_name_index;
  8424. unsigned short seeprom_size;
  8425. unsigned short seeprom_type;
  8426. } const aic_pdevs[] = {
  8427. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
  8428. AHC_FNONE, AHC_FENONE, 1,
  8429. 32, C46 },
  8430. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
  8431. AHC_PAGESCBS, AHC_AIC7850_FE, 5,
  8432. 32, C46 },
  8433. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
  8434. AHC_PAGESCBS, AHC_AIC7850_FE, 6,
  8435. 32, C46 },
  8436. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
  8437. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8438. AHC_AIC7860_FE, 7,
  8439. 32, C46 },
  8440. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
  8441. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8442. AHC_AIC7860_FE, 7,
  8443. 32, C46 },
  8444. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8445. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8446. AHC_AIC7860_FE, 7,
  8447. 32, C46 },
  8448. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8449. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8450. AHC_AIC7860_FE, 7,
  8451. 32, C46 },
  8452. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
  8453. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8454. AHC_AIC7860_FE, 7,
  8455. 32, C46 },
  8456. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
  8457. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8458. AHC_AIC7860_FE, 8,
  8459. 32, C46 },
  8460. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
  8461. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8462. AHC_AIC7870_FE, 9,
  8463. 32, C46 },
  8464. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
  8465. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
  8466. 32, C46 },
  8467. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
  8468. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8469. AHC_AIC7870_FE, 11,
  8470. 32, C56_66 },
  8471. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
  8472. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8473. AHC_AIC7870_FE, 12,
  8474. 32, C56_66 },
  8475. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
  8476. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
  8477. 32, C46 },
  8478. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
  8479. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8480. AHC_AIC7880_FE, 14,
  8481. 32, C46 },
  8482. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
  8483. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
  8484. 32, C46 },
  8485. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
  8486. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8487. AHC_AIC7880_FE, 16,
  8488. 32, C56_66 },
  8489. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
  8490. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8491. AHC_AIC7880_FE, 17,
  8492. 32, C56_66 },
  8493. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
  8494. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8495. 32, C46 },
  8496. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
  8497. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8498. 32, C46 },
  8499. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
  8500. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8501. 32, C46 },
  8502. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
  8503. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 19,
  8504. 32, C46 },
  8505. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
  8506. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8507. 32, C46 },
  8508. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
  8509. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8510. AHC_AIC7895_FE, 20,
  8511. 32, C56_66 },
  8512. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
  8513. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8514. AHC_AIC7890_FE, 21,
  8515. 32, C46 },
  8516. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
  8517. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8518. AHC_AIC7890_FE, 21,
  8519. 32, C46 },
  8520. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
  8521. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8522. AHC_AIC7890_FE, 22,
  8523. 32, C46 },
  8524. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
  8525. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8526. AHC_AIC7890_FE, 23,
  8527. 32, C46 },
  8528. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
  8529. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8530. AHC_AIC7896_FE, 24,
  8531. 32, C56_66 },
  8532. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
  8533. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8534. AHC_AIC7896_FE, 25,
  8535. 32, C56_66 },
  8536. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
  8537. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8538. AHC_AIC7896_FE, 26,
  8539. 32, C56_66 },
  8540. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
  8541. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWEN,
  8542. AHC_AIC7860_FE, 27,
  8543. 32, C46 },
  8544. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
  8545. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8546. AHC_AIC7892_FE, 28,
  8547. 32, C46 },
  8548. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
  8549. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8550. AHC_AIC7892_FE, 28,
  8551. 32, C46 },
  8552. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
  8553. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8554. AHC_AIC7892_FE, 28,
  8555. 32, C46 },
  8556. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
  8557. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8558. AHC_AIC7892_FE, 28,
  8559. 32, C46 },
  8560. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
  8561. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8562. AHC_AIC7899_FE, 29,
  8563. 32, C56_66 },
  8564. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
  8565. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8566. AHC_AIC7899_FE, 29,
  8567. 32, C56_66 },
  8568. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
  8569. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8570. AHC_AIC7899_FE, 29,
  8571. 32, C56_66 },
  8572. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
  8573. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8574. AHC_AIC7899_FE, 29,
  8575. 32, C56_66 },
  8576. };
  8577. unsigned short command;
  8578. unsigned int devconfig, i, oldverbose;
  8579. struct pci_dev *pdev = NULL;
  8580. for (i = 0; i < ARRAY_SIZE(aic_pdevs); i++)
  8581. {
  8582. pdev = NULL;
  8583. while ((pdev = pci_find_device(aic_pdevs[i].vendor_id,
  8584. aic_pdevs[i].device_id,
  8585. pdev))) {
  8586. if (pci_enable_device(pdev))
  8587. continue;
  8588. if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
  8589. {
  8590. if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
  8591. {
  8592. printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
  8593. "supported by\n");
  8594. printk(KERN_INFO " this driver, we are ignoring it.\n");
  8595. }
  8596. }
  8597. else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
  8598. GFP_ATOMIC)) != NULL )
  8599. {
  8600. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  8601. temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
  8602. temp_p->flags = aic_pdevs[i].flags;
  8603. temp_p->features = aic_pdevs[i].features;
  8604. temp_p->board_name_index = aic_pdevs[i].board_name_index;
  8605. temp_p->sc_size = aic_pdevs[i].seeprom_size;
  8606. temp_p->sc_type = aic_pdevs[i].seeprom_type;
  8607. /*
  8608. * Read sundry information from PCI BIOS.
  8609. */
  8610. temp_p->irq = pdev->irq;
  8611. temp_p->pdev = pdev;
  8612. temp_p->pci_bus = pdev->bus->number;
  8613. temp_p->pci_device_fn = pdev->devfn;
  8614. temp_p->base = pci_resource_start(pdev, 0);
  8615. temp_p->mbase = pci_resource_start(pdev, 1);
  8616. current_p = list_p;
  8617. while(current_p && temp_p)
  8618. {
  8619. if ( ((current_p->pci_bus == temp_p->pci_bus) &&
  8620. (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
  8621. (temp_p->base && (current_p->base == temp_p->base)) ||
  8622. (temp_p->mbase && (current_p->mbase == temp_p->mbase)) )
  8623. {
  8624. /* duplicate PCI entry, skip it */
  8625. kfree(temp_p);
  8626. temp_p = NULL;
  8627. continue;
  8628. }
  8629. current_p = current_p->next;
  8630. }
  8631. if(pci_request_regions(temp_p->pdev, "aic7xxx"))
  8632. {
  8633. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8634. board_names[aic_pdevs[i].board_name_index],
  8635. temp_p->pci_bus,
  8636. PCI_SLOT(temp_p->pci_device_fn),
  8637. PCI_FUNC(temp_p->pci_device_fn));
  8638. printk("aic7xxx: I/O ports already in use, ignoring.\n");
  8639. kfree(temp_p);
  8640. continue;
  8641. }
  8642. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8643. printk("aic7xxx: <%s> at PCI %d/%d\n",
  8644. board_names[aic_pdevs[i].board_name_index],
  8645. PCI_SLOT(pdev->devfn),
  8646. PCI_FUNC(pdev->devfn));
  8647. pci_read_config_word(pdev, PCI_COMMAND, &command);
  8648. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8649. {
  8650. printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
  8651. (int)command);
  8652. }
  8653. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8654. command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  8655. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8656. #else
  8657. command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8658. #endif
  8659. command &= ~PCI_COMMAND_INVALIDATE;
  8660. if (aic7xxx_pci_parity == 0)
  8661. command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  8662. pci_write_config_word(pdev, PCI_COMMAND, command);
  8663. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8664. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8665. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8666. {
  8667. printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
  8668. }
  8669. devconfig |= 0x80000040;
  8670. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8671. #endif /* AIC7XXX_STRICT_PCI_SETUP */
  8672. temp_p->unpause = INTEN;
  8673. temp_p->pause = temp_p->unpause | PAUSE;
  8674. if ( ((temp_p->base == 0) &&
  8675. (temp_p->mbase == 0)) ||
  8676. (temp_p->irq == 0) )
  8677. {
  8678. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8679. board_names[aic_pdevs[i].board_name_index],
  8680. temp_p->pci_bus,
  8681. PCI_SLOT(temp_p->pci_device_fn),
  8682. PCI_FUNC(temp_p->pci_device_fn));
  8683. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8684. goto skip_pci_controller;
  8685. }
  8686. #ifdef MMAPIO
  8687. if ( !(temp_p->base) || !(temp_p->flags & AHC_MULTI_CHANNEL) ||
  8688. ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
  8689. (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
  8690. {
  8691. temp_p->maddr = ioremap_nocache(temp_p->mbase, 256);
  8692. if(temp_p->maddr)
  8693. {
  8694. /*
  8695. * We need to check the I/O with the MMAPed address. Some machines
  8696. * simply fail to work with MMAPed I/O and certain controllers.
  8697. */
  8698. if(aic_inb(temp_p, HCNTRL) == 0xff)
  8699. {
  8700. /*
  8701. * OK.....we failed our test....go back to programmed I/O
  8702. */
  8703. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8704. board_names[aic_pdevs[i].board_name_index],
  8705. temp_p->pci_bus,
  8706. PCI_SLOT(temp_p->pci_device_fn),
  8707. PCI_FUNC(temp_p->pci_device_fn));
  8708. printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
  8709. "Programmed I/O.\n");
  8710. iounmap(temp_p->maddr);
  8711. temp_p->maddr = NULL;
  8712. if(temp_p->base == 0)
  8713. {
  8714. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8715. board_names[aic_pdevs[i].board_name_index],
  8716. temp_p->pci_bus,
  8717. PCI_SLOT(temp_p->pci_device_fn),
  8718. PCI_FUNC(temp_p->pci_device_fn));
  8719. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8720. goto skip_pci_controller;
  8721. }
  8722. }
  8723. }
  8724. }
  8725. #endif
  8726. /*
  8727. * We HAVE to make sure the first pause_sequencer() and all other
  8728. * subsequent I/O that isn't PCI config space I/O takes place
  8729. * after the MMAPed I/O region is configured and tested. The
  8730. * problem is the PowerPC architecture that doesn't support
  8731. * programmed I/O at all, so we have to have the MMAP I/O set up
  8732. * for this pause to even work on those machines.
  8733. */
  8734. pause_sequencer(temp_p);
  8735. /*
  8736. * Clear out any pending PCI error status messages. Also set
  8737. * verbose to 0 so that we don't emit strange PCI error messages
  8738. * while cleaning out the current status bits.
  8739. */
  8740. oldverbose = aic7xxx_verbose;
  8741. aic7xxx_verbose = 0;
  8742. aic7xxx_pci_intr(temp_p);
  8743. aic7xxx_verbose = oldverbose;
  8744. temp_p->bios_address = 0;
  8745. /*
  8746. * Remember how the card was setup in case there is no seeprom.
  8747. */
  8748. if (temp_p->features & AHC_ULTRA2)
  8749. temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
  8750. else
  8751. temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
  8752. /*
  8753. * Get current termination setting
  8754. */
  8755. sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
  8756. if (aic7xxx_chip_reset(temp_p) == -1)
  8757. {
  8758. goto skip_pci_controller;
  8759. }
  8760. /*
  8761. * Very quickly put the term setting back into the register since
  8762. * the chip reset may cause odd things to happen. This is to keep
  8763. * LVD busses with lots of drives from draining the power out of
  8764. * the diffsense line before we get around to running the
  8765. * configure_termination() function. Also restore the STPWLEVEL
  8766. * bit of DEVCONFIG
  8767. */
  8768. aic_outb(temp_p, sxfrctl1, SXFRCTL1);
  8769. pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
  8770. sxfrctl1 &= STPWEN;
  8771. /*
  8772. * We need to set the CHNL? assignments before loading the SEEPROM
  8773. * The 3940 and 3985 cards (original stuff, not any of the later
  8774. * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
  8775. * under 7896 and 7897. The 7895 is in a class by itself :)
  8776. */
  8777. switch (temp_p->chip & AHC_CHIPID_MASK)
  8778. {
  8779. case AHC_AIC7870: /* 3840 / 3985 */
  8780. case AHC_AIC7880: /* 3840 UW / 3985 UW */
  8781. if(temp_p->flags & AHC_MULTI_CHANNEL)
  8782. {
  8783. switch(PCI_SLOT(temp_p->pci_device_fn))
  8784. {
  8785. case 5:
  8786. temp_p->flags |= AHC_CHNLB;
  8787. break;
  8788. case 8:
  8789. temp_p->flags |= AHC_CHNLB;
  8790. break;
  8791. case 12:
  8792. temp_p->flags |= AHC_CHNLC;
  8793. break;
  8794. default:
  8795. break;
  8796. }
  8797. }
  8798. break;
  8799. case AHC_AIC7895: /* 7895 */
  8800. case AHC_AIC7896: /* 7896/7 */
  8801. case AHC_AIC7899: /* 7899 */
  8802. if (PCI_FUNC(pdev->devfn) != 0)
  8803. {
  8804. temp_p->flags |= AHC_CHNLB;
  8805. }
  8806. /*
  8807. * The 7895 is the only chipset that sets the SCBSIZE32 param
  8808. * in the DEVCONFIG register. The Ultra2 chipsets use
  8809. * the DSCOMMAND0 register instead.
  8810. */
  8811. if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
  8812. {
  8813. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8814. devconfig |= SCBSIZE32;
  8815. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8816. }
  8817. break;
  8818. default:
  8819. break;
  8820. }
  8821. /*
  8822. * Loading of the SEEPROM needs to come after we've set the flags
  8823. * to indicate possible CHNLB and CHNLC assigments. Otherwise,
  8824. * on 394x and 398x cards we'll end up reading the wrong settings
  8825. * for channels B and C
  8826. */
  8827. switch (temp_p->chip & AHC_CHIPID_MASK)
  8828. {
  8829. case AHC_AIC7892:
  8830. case AHC_AIC7899:
  8831. aic_outb(temp_p, 0, SCAMCTL);
  8832. /*
  8833. * Switch to the alt mode of the chip...
  8834. */
  8835. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
  8836. /*
  8837. * Set our options...the last two items set our CRC after x byte
  8838. * count in target mode...
  8839. */
  8840. aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
  8841. aic_outb(temp_p, 0x00, 0x0b);
  8842. aic_outb(temp_p, 0x10, 0x0a);
  8843. /*
  8844. * switch back to normal mode...
  8845. */
  8846. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
  8847. aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
  8848. TARGCRCENDEN | TARGCRCCNTEN,
  8849. CRCCONTROL1);
  8850. aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
  8851. MPARCKEN | CIOPARCKEN | CACHETHEN) &
  8852. ~DPARCKEN), DSCOMMAND0);
  8853. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8854. break;
  8855. case AHC_AIC7890:
  8856. case AHC_AIC7896:
  8857. aic_outb(temp_p, 0, SCAMCTL);
  8858. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8859. CACHETHEN | MPARCKEN | USCBSIZE32 |
  8860. CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
  8861. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8862. break;
  8863. case AHC_AIC7850:
  8864. case AHC_AIC7860:
  8865. /*
  8866. * Set the DSCOMMAND0 register on these cards different from
  8867. * on the 789x cards. Also, read the SEEPROM as well.
  8868. */
  8869. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8870. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8871. DSCOMMAND0);
  8872. /* FALLTHROUGH */
  8873. default:
  8874. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8875. break;
  8876. case AHC_AIC7880:
  8877. /*
  8878. * Check the rev of the chipset before we change DSCOMMAND0
  8879. */
  8880. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8881. if ((devconfig & 0xff) >= 1)
  8882. {
  8883. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8884. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8885. DSCOMMAND0);
  8886. }
  8887. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8888. break;
  8889. }
  8890. /*
  8891. * and then we need another switch based on the type in order to
  8892. * make sure the channel B primary flag is set properly on 7895
  8893. * controllers....Arrrgggghhh!!! We also have to catch the fact
  8894. * that when you disable the BIOS on the 7895 on the Intel DK440LX
  8895. * motherboard, and possibly others, it only sets the BIOS disabled
  8896. * bit on the A channel...I think I'm starting to lean towards
  8897. * going postal....
  8898. */
  8899. switch(temp_p->chip & AHC_CHIPID_MASK)
  8900. {
  8901. case AHC_AIC7895:
  8902. case AHC_AIC7896:
  8903. case AHC_AIC7899:
  8904. current_p = list_p;
  8905. while(current_p != NULL)
  8906. {
  8907. if ( (current_p->pci_bus == temp_p->pci_bus) &&
  8908. (PCI_SLOT(current_p->pci_device_fn) ==
  8909. PCI_SLOT(temp_p->pci_device_fn)) )
  8910. {
  8911. if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
  8912. {
  8913. temp_p->flags |=
  8914. (current_p->flags & AHC_CHANNEL_B_PRIMARY);
  8915. temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8916. temp_p->flags |=
  8917. (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8918. }
  8919. else
  8920. {
  8921. current_p->flags |=
  8922. (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
  8923. current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8924. current_p->flags |=
  8925. (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8926. }
  8927. }
  8928. current_p = current_p->next;
  8929. }
  8930. break;
  8931. default:
  8932. break;
  8933. }
  8934. /*
  8935. * We only support external SCB RAM on the 7895/6/7 chipsets.
  8936. * We could support it on the 7890/1 easy enough, but I don't
  8937. * know of any 7890/1 based cards that have it. I do know
  8938. * of 7895/6/7 cards that have it and they work properly.
  8939. */
  8940. switch(temp_p->chip & AHC_CHIPID_MASK)
  8941. {
  8942. default:
  8943. break;
  8944. case AHC_AIC7895:
  8945. case AHC_AIC7896:
  8946. case AHC_AIC7899:
  8947. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8948. if (temp_p->features & AHC_ULTRA2)
  8949. {
  8950. if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
  8951. (aic7xxx_scbram) )
  8952. {
  8953. aic_outb(temp_p,
  8954. aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
  8955. DSCOMMAND0);
  8956. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8957. devconfig |= EXTSCBPEN;
  8958. }
  8959. else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
  8960. {
  8961. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8962. board_names[aic_pdevs[i].board_name_index],
  8963. temp_p->pci_bus,
  8964. PCI_SLOT(temp_p->pci_device_fn),
  8965. PCI_FUNC(temp_p->pci_device_fn));
  8966. printk("aic7xxx: external SCB RAM detected, "
  8967. "but not enabled\n");
  8968. }
  8969. }
  8970. else
  8971. {
  8972. if ((devconfig & RAMPSM) && (aic7xxx_scbram))
  8973. {
  8974. devconfig &= ~SCBRAMSEL;
  8975. devconfig |= EXTSCBPEN;
  8976. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8977. }
  8978. else if (devconfig & RAMPSM)
  8979. {
  8980. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8981. board_names[aic_pdevs[i].board_name_index],
  8982. temp_p->pci_bus,
  8983. PCI_SLOT(temp_p->pci_device_fn),
  8984. PCI_FUNC(temp_p->pci_device_fn));
  8985. printk("aic7xxx: external SCB RAM detected, "
  8986. "but not enabled\n");
  8987. }
  8988. }
  8989. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8990. if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
  8991. (temp_p->flags & AHC_CHNLB) )
  8992. aic_outb(temp_p, 1, CCSCBBADDR);
  8993. break;
  8994. }
  8995. /*
  8996. * Take the LED out of diagnostic mode
  8997. */
  8998. aic_outb(temp_p,
  8999. (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
  9000. SBLKCTL);
  9001. /*
  9002. * We don't know where this is set in the SEEPROM or by the
  9003. * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
  9004. * instead.
  9005. */
  9006. if (temp_p->features & AHC_ULTRA2)
  9007. {
  9008. aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
  9009. }
  9010. else
  9011. {
  9012. aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
  9013. }
  9014. /*
  9015. * Call our function to fixup any bugs that exist on this chipset.
  9016. * This may muck with PCI settings and other device settings, so
  9017. * make sure it's after all the other PCI and device register
  9018. * tweaks so it can back out bad settings on specific broken cards.
  9019. */
  9020. aic7xxx_configure_bugs(temp_p);
  9021. if ( list_p == NULL )
  9022. {
  9023. list_p = current_p = temp_p;
  9024. }
  9025. else
  9026. {
  9027. current_p = list_p;
  9028. while(current_p->next != NULL)
  9029. current_p = current_p->next;
  9030. current_p->next = temp_p;
  9031. }
  9032. temp_p->next = NULL;
  9033. found++;
  9034. continue;
  9035. skip_pci_controller:
  9036. #ifdef CONFIG_PCI
  9037. pci_release_regions(temp_p->pdev);
  9038. #endif
  9039. kfree(temp_p);
  9040. } /* Found an Adaptec PCI device. */
  9041. else /* Well, we found one, but we couldn't get any memory */
  9042. {
  9043. printk("aic7xxx: Found <%s>\n",
  9044. board_names[aic_pdevs[i].board_name_index]);
  9045. printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
  9046. "skipping.\n");
  9047. }
  9048. } /* while(pdev=....) */
  9049. } /* for PCI_DEVICES */
  9050. }
  9051. #endif /* CONFIG_PCI */
  9052. #if defined(__i386__) || defined(__alpha__)
  9053. /*
  9054. * EISA/VL-bus card signature probe.
  9055. */
  9056. slot = MINSLOT;
  9057. while ( (slot <= MAXSLOT) &&
  9058. !(aic7xxx_no_probe) )
  9059. {
  9060. base = SLOTBASE(slot) + MINREG;
  9061. if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
  9062. {
  9063. /*
  9064. * Some other driver has staked a
  9065. * claim to this i/o region already.
  9066. */
  9067. slot++;
  9068. continue; /* back to the beginning of the for loop */
  9069. }
  9070. flags = 0;
  9071. type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
  9072. if (type == -1)
  9073. {
  9074. release_region(base, MAXREG - MINREG);
  9075. slot++;
  9076. continue;
  9077. }
  9078. temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
  9079. if (temp_p == NULL)
  9080. {
  9081. printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
  9082. release_region(base, MAXREG - MINREG);
  9083. slot++;
  9084. continue; /* back to the beginning of the while loop */
  9085. }
  9086. /*
  9087. * Pause the card preserving the IRQ type. Allow the operator
  9088. * to override the IRQ trigger.
  9089. */
  9090. if (aic7xxx_irq_trigger == 1)
  9091. hcntrl = IRQMS; /* Level */
  9092. else if (aic7xxx_irq_trigger == 0)
  9093. hcntrl = 0; /* Edge */
  9094. else
  9095. hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
  9096. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  9097. temp_p->unpause = hcntrl | INTEN;
  9098. temp_p->pause = hcntrl | PAUSE | INTEN;
  9099. temp_p->base = base;
  9100. temp_p->mbase = 0;
  9101. temp_p->maddr = NULL;
  9102. temp_p->pci_bus = 0;
  9103. temp_p->pci_device_fn = slot;
  9104. aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
  9105. while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
  9106. if (aic7xxx_chip_reset(temp_p) == -1)
  9107. temp_p->irq = 0;
  9108. else
  9109. temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
  9110. temp_p->flags |= AHC_PAGESCBS;
  9111. switch (temp_p->irq)
  9112. {
  9113. case 9:
  9114. case 10:
  9115. case 11:
  9116. case 12:
  9117. case 14:
  9118. case 15:
  9119. break;
  9120. default:
  9121. printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
  9122. "level %d, ignoring.\n", temp_p->irq);
  9123. kfree(temp_p);
  9124. release_region(base, MAXREG - MINREG);
  9125. slot++;
  9126. continue; /* back to the beginning of the while loop */
  9127. }
  9128. /*
  9129. * We are commited now, everything has been checked and this card
  9130. * has been found, now we just set it up
  9131. */
  9132. /*
  9133. * Insert our new struct into the list at the end
  9134. */
  9135. if (list_p == NULL)
  9136. {
  9137. list_p = current_p = temp_p;
  9138. }
  9139. else
  9140. {
  9141. current_p = list_p;
  9142. while (current_p->next != NULL)
  9143. current_p = current_p->next;
  9144. current_p->next = temp_p;
  9145. }
  9146. switch (type)
  9147. {
  9148. case 0:
  9149. temp_p->board_name_index = 2;
  9150. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9151. printk("aic7xxx: <%s> at EISA %d\n",
  9152. board_names[2], slot);
  9153. /* FALLTHROUGH */
  9154. case 1:
  9155. {
  9156. temp_p->chip = AHC_AIC7770 | AHC_EISA;
  9157. temp_p->features |= AHC_AIC7770_FE;
  9158. temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
  9159. /*
  9160. * Get the primary channel information. Right now we don't
  9161. * do anything with this, but someday we will be able to inform
  9162. * the mid-level SCSI code which channel is primary.
  9163. */
  9164. if (temp_p->board_name_index == 0)
  9165. {
  9166. temp_p->board_name_index = 3;
  9167. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9168. printk("aic7xxx: <%s> at EISA %d\n",
  9169. board_names[3], slot);
  9170. }
  9171. if (temp_p->bios_control & CHANNEL_B_PRIMARY)
  9172. {
  9173. temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
  9174. }
  9175. if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
  9176. {
  9177. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9178. }
  9179. else
  9180. {
  9181. temp_p->flags &= ~AHC_USEDEFAULTS;
  9182. temp_p->flags |= AHC_BIOS_ENABLED;
  9183. if ( (temp_p->bios_control & 0x20) == 0 )
  9184. {
  9185. temp_p->bios_address = 0xcc000;
  9186. temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
  9187. }
  9188. else
  9189. {
  9190. temp_p->bios_address = 0xd0000;
  9191. temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
  9192. }
  9193. }
  9194. temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
  9195. temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
  9196. if (temp_p->features & AHC_WIDE)
  9197. {
  9198. temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
  9199. temp_p->scsi_id_b = temp_p->scsi_id;
  9200. }
  9201. else
  9202. {
  9203. temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
  9204. temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
  9205. }
  9206. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9207. break;
  9208. }
  9209. case 2:
  9210. case 3:
  9211. temp_p->chip = AHC_AIC7770 | AHC_VL;
  9212. temp_p->features |= AHC_AIC7770_FE;
  9213. if (type == 2)
  9214. temp_p->flags |= AHC_BIOS_ENABLED;
  9215. else
  9216. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9217. if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
  9218. sxfrctl1 = STPWEN;
  9219. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9220. temp_p->board_name_index = 4;
  9221. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9222. printk("aic7xxx: <%s> at VLB %d\n",
  9223. board_names[2], slot);
  9224. switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
  9225. {
  9226. case 0x00:
  9227. temp_p->bios_address = 0xe0000;
  9228. break;
  9229. case 0x20:
  9230. temp_p->bios_address = 0xc8000;
  9231. break;
  9232. case 0x40:
  9233. temp_p->bios_address = 0xd0000;
  9234. break;
  9235. case 0x60:
  9236. temp_p->bios_address = 0xd8000;
  9237. break;
  9238. default:
  9239. break; /* can't get here */
  9240. }
  9241. break;
  9242. default: /* Won't get here. */
  9243. break;
  9244. }
  9245. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9246. {
  9247. printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
  9248. (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
  9249. temp_p->irq,
  9250. (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
  9251. printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
  9252. (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
  9253. }
  9254. /*
  9255. * All the 7770 based chipsets have this bug
  9256. */
  9257. temp_p->bugs |= AHC_BUG_TMODE_WIDEODD;
  9258. /*
  9259. * Set the FIFO threshold and the bus off time.
  9260. */
  9261. hostconf = aic_inb(temp_p, HOSTCONF);
  9262. aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
  9263. aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
  9264. slot++;
  9265. found++;
  9266. }
  9267. #endif /* defined(__i386__) || defined(__alpha__) */
  9268. /*
  9269. * Now, we re-order the probed devices by BIOS address and BUS class.
  9270. * In general, we follow this algorithm to make the adapters show up
  9271. * in the same order under linux that the computer finds them.
  9272. * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
  9273. * address, going from lowest to highest.
  9274. * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
  9275. * address, going from lowest to highest.
  9276. * 3: Remaining VLB/EISA controllers going in slot order.
  9277. * 4: Remaining PCI controllers, going in PCI device order (reversable)
  9278. */
  9279. {
  9280. struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
  9281. struct aic7xxx_host *vlb, *pci;
  9282. struct aic7xxx_host *prev_p;
  9283. struct aic7xxx_host *p;
  9284. unsigned char left;
  9285. prev_p = vlb = pci = NULL;
  9286. temp_p = list_p;
  9287. while (temp_p != NULL)
  9288. {
  9289. switch(temp_p->chip & ~AHC_CHIPID_MASK)
  9290. {
  9291. case AHC_EISA:
  9292. case AHC_VL:
  9293. {
  9294. p = temp_p;
  9295. if (p->flags & AHC_BIOS_ENABLED)
  9296. vlb = sort_list[0];
  9297. else
  9298. vlb = sort_list[2];
  9299. if (vlb == NULL)
  9300. {
  9301. vlb = temp_p;
  9302. temp_p = temp_p->next;
  9303. vlb->next = NULL;
  9304. }
  9305. else
  9306. {
  9307. current_p = vlb;
  9308. prev_p = NULL;
  9309. while ( (current_p != NULL) &&
  9310. (current_p->bios_address < temp_p->bios_address))
  9311. {
  9312. prev_p = current_p;
  9313. current_p = current_p->next;
  9314. }
  9315. if (prev_p != NULL)
  9316. {
  9317. prev_p->next = temp_p;
  9318. temp_p = temp_p->next;
  9319. prev_p->next->next = current_p;
  9320. }
  9321. else
  9322. {
  9323. vlb = temp_p;
  9324. temp_p = temp_p->next;
  9325. vlb->next = current_p;
  9326. }
  9327. }
  9328. if (p->flags & AHC_BIOS_ENABLED)
  9329. sort_list[0] = vlb;
  9330. else
  9331. sort_list[2] = vlb;
  9332. break;
  9333. }
  9334. default: /* All PCI controllers fall through to default */
  9335. {
  9336. p = temp_p;
  9337. if (p->flags & AHC_BIOS_ENABLED)
  9338. pci = sort_list[1];
  9339. else
  9340. pci = sort_list[3];
  9341. if (pci == NULL)
  9342. {
  9343. pci = temp_p;
  9344. temp_p = temp_p->next;
  9345. pci->next = NULL;
  9346. }
  9347. else
  9348. {
  9349. current_p = pci;
  9350. prev_p = NULL;
  9351. if (!aic7xxx_reverse_scan)
  9352. {
  9353. while ( (current_p != NULL) &&
  9354. ( (PCI_SLOT(current_p->pci_device_fn) |
  9355. (current_p->pci_bus << 8)) <
  9356. (PCI_SLOT(temp_p->pci_device_fn) |
  9357. (temp_p->pci_bus << 8)) ) )
  9358. {
  9359. prev_p = current_p;
  9360. current_p = current_p->next;
  9361. }
  9362. }
  9363. else
  9364. {
  9365. while ( (current_p != NULL) &&
  9366. ( (PCI_SLOT(current_p->pci_device_fn) |
  9367. (current_p->pci_bus << 8)) >
  9368. (PCI_SLOT(temp_p->pci_device_fn) |
  9369. (temp_p->pci_bus << 8)) ) )
  9370. {
  9371. prev_p = current_p;
  9372. current_p = current_p->next;
  9373. }
  9374. }
  9375. /*
  9376. * Are we dealing with a 7895/6/7/9 where we need to sort the
  9377. * channels as well, if so, the bios_address values should
  9378. * be the same
  9379. */
  9380. if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
  9381. (temp_p->pci_bus == current_p->pci_bus) &&
  9382. (PCI_SLOT(temp_p->pci_device_fn) ==
  9383. PCI_SLOT(current_p->pci_device_fn)) )
  9384. {
  9385. if (temp_p->flags & AHC_CHNLB)
  9386. {
  9387. if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
  9388. {
  9389. prev_p = current_p;
  9390. current_p = current_p->next;
  9391. }
  9392. }
  9393. else
  9394. {
  9395. if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
  9396. {
  9397. prev_p = current_p;
  9398. current_p = current_p->next;
  9399. }
  9400. }
  9401. }
  9402. if (prev_p != NULL)
  9403. {
  9404. prev_p->next = temp_p;
  9405. temp_p = temp_p->next;
  9406. prev_p->next->next = current_p;
  9407. }
  9408. else
  9409. {
  9410. pci = temp_p;
  9411. temp_p = temp_p->next;
  9412. pci->next = current_p;
  9413. }
  9414. }
  9415. if (p->flags & AHC_BIOS_ENABLED)
  9416. sort_list[1] = pci;
  9417. else
  9418. sort_list[3] = pci;
  9419. break;
  9420. }
  9421. } /* End of switch(temp_p->type) */
  9422. } /* End of while (temp_p != NULL) */
  9423. /*
  9424. * At this point, the cards have been broken into 4 sorted lists, now
  9425. * we run through the lists in order and register each controller
  9426. */
  9427. {
  9428. int i;
  9429. left = found;
  9430. for (i=0; i<ARRAY_SIZE(sort_list); i++)
  9431. {
  9432. temp_p = sort_list[i];
  9433. while(temp_p != NULL)
  9434. {
  9435. template->name = board_names[temp_p->board_name_index];
  9436. p = aic7xxx_alloc(template, temp_p);
  9437. if (p != NULL)
  9438. {
  9439. p->instance = found - left;
  9440. if (aic7xxx_register(template, p, (--left)) == 0)
  9441. {
  9442. found--;
  9443. aic7xxx_release(p->host);
  9444. scsi_unregister(p->host);
  9445. }
  9446. else if (aic7xxx_dump_card)
  9447. {
  9448. pause_sequencer(p);
  9449. aic7xxx_print_card(p);
  9450. aic7xxx_print_scratch_ram(p);
  9451. unpause_sequencer(p, TRUE);
  9452. }
  9453. }
  9454. current_p = temp_p;
  9455. temp_p = (struct aic7xxx_host *)temp_p->next;
  9456. kfree(current_p);
  9457. }
  9458. }
  9459. }
  9460. }
  9461. return (found);
  9462. }
  9463. /*+F*************************************************************************
  9464. * Function:
  9465. * aic7xxx_buildscb
  9466. *
  9467. * Description:
  9468. * Build a SCB.
  9469. *-F*************************************************************************/
  9470. static void
  9471. aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
  9472. struct aic7xxx_scb *scb)
  9473. {
  9474. unsigned short mask;
  9475. struct aic7xxx_hwscb *hscb;
  9476. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  9477. struct scsi_device *sdptr = cmd->device;
  9478. unsigned char tindex = TARGET_INDEX(cmd);
  9479. struct request *req = cmd->request;
  9480. mask = (0x01 << tindex);
  9481. hscb = scb->hscb;
  9482. /*
  9483. * Setup the control byte if we need negotiation and have not
  9484. * already requested it.
  9485. */
  9486. hscb->control = 0;
  9487. scb->tag_action = 0;
  9488. if (p->discenable & mask)
  9489. {
  9490. hscb->control |= DISCENB;
  9491. /* We always force TEST_UNIT_READY to untagged */
  9492. if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
  9493. {
  9494. if (req->flags & REQ_HARDBARRIER)
  9495. {
  9496. if(sdptr->ordered_tags)
  9497. {
  9498. hscb->control |= MSG_ORDERED_Q_TAG;
  9499. scb->tag_action = MSG_ORDERED_Q_TAG;
  9500. }
  9501. }
  9502. else
  9503. {
  9504. hscb->control |= MSG_SIMPLE_Q_TAG;
  9505. scb->tag_action = MSG_SIMPLE_Q_TAG;
  9506. }
  9507. }
  9508. }
  9509. if ( !(aic_dev->dtr_pending) &&
  9510. (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&
  9511. (aic_dev->flags & DEVICE_DTR_SCANNED) )
  9512. {
  9513. aic_dev->dtr_pending = 1;
  9514. scb->tag_action = 0;
  9515. hscb->control &= DISCENB;
  9516. hscb->control |= MK_MESSAGE;
  9517. if(aic_dev->needppr)
  9518. {
  9519. scb->flags |= SCB_MSGOUT_PPR;
  9520. }
  9521. else if(aic_dev->needwdtr)
  9522. {
  9523. scb->flags |= SCB_MSGOUT_WDTR;
  9524. }
  9525. else if(aic_dev->needsdtr)
  9526. {
  9527. scb->flags |= SCB_MSGOUT_SDTR;
  9528. }
  9529. scb->flags |= SCB_DTR_SCB;
  9530. }
  9531. hscb->target_channel_lun = ((cmd->device->id << 4) & 0xF0) |
  9532. ((cmd->device->channel & 0x01) << 3) | (cmd->device->lun & 0x07);
  9533. /*
  9534. * The interpretation of request_buffer and request_bufflen
  9535. * changes depending on whether or not use_sg is zero; a
  9536. * non-zero use_sg indicates the number of elements in the
  9537. * scatter-gather array.
  9538. */
  9539. /*
  9540. * XXX - this relies on the host data being stored in a
  9541. * little-endian format.
  9542. */
  9543. hscb->SCSI_cmd_length = cmd->cmd_len;
  9544. memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
  9545. hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
  9546. if (cmd->use_sg)
  9547. {
  9548. struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
  9549. /*
  9550. * We must build an SG list in adapter format, as the kernel's SG list
  9551. * cannot be used directly because of data field size (__alpha__)
  9552. * differences and the kernel SG list uses virtual addresses where
  9553. * we need physical addresses.
  9554. */
  9555. int i, use_sg;
  9556. sg = (struct scatterlist *)cmd->request_buffer;
  9557. scb->sg_length = 0;
  9558. use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, cmd->sc_data_direction);
  9559. /*
  9560. * Copy the segments into the SG array. NOTE!!! - We used to
  9561. * have the first entry both in the data_pointer area and the first
  9562. * SG element. That has changed somewhat. We still have the first
  9563. * entry in both places, but now we download the address of
  9564. * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
  9565. */
  9566. for (i = 0; i < use_sg; i++)
  9567. {
  9568. unsigned int len = sg_dma_len(sg+i);
  9569. scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));
  9570. scb->sg_list[i].length = cpu_to_le32(len);
  9571. scb->sg_length += len;
  9572. }
  9573. /* Copy the first SG into the data pointer area. */
  9574. hscb->data_pointer = scb->sg_list[0].address;
  9575. hscb->data_count = scb->sg_list[0].length;
  9576. scb->sg_count = i;
  9577. hscb->SG_segment_count = i;
  9578. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
  9579. }
  9580. else
  9581. {
  9582. if (cmd->request_bufflen)
  9583. {
  9584. unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,
  9585. cmd->request_bufflen,
  9586. cmd->sc_data_direction);
  9587. aic7xxx_mapping(cmd) = address;
  9588. scb->sg_list[0].address = cpu_to_le32(address);
  9589. scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
  9590. scb->sg_count = 1;
  9591. scb->sg_length = cmd->request_bufflen;
  9592. hscb->SG_segment_count = 1;
  9593. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));
  9594. hscb->data_count = scb->sg_list[0].length;
  9595. hscb->data_pointer = scb->sg_list[0].address;
  9596. }
  9597. else
  9598. {
  9599. scb->sg_count = 0;
  9600. scb->sg_length = 0;
  9601. hscb->SG_segment_count = 0;
  9602. hscb->SG_list_pointer = 0;
  9603. hscb->data_count = 0;
  9604. hscb->data_pointer = 0;
  9605. }
  9606. }
  9607. }
  9608. /*+F*************************************************************************
  9609. * Function:
  9610. * aic7xxx_queue
  9611. *
  9612. * Description:
  9613. * Queue a SCB to the controller.
  9614. *-F*************************************************************************/
  9615. static int
  9616. aic7xxx_queue(Scsi_Cmnd *cmd, void (*fn)(Scsi_Cmnd *))
  9617. {
  9618. struct aic7xxx_host *p;
  9619. struct aic7xxx_scb *scb;
  9620. struct aic_dev_data *aic_dev;
  9621. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  9622. aic_dev = cmd->device->hostdata;
  9623. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  9624. if (aic_dev->active_cmds > aic_dev->max_q_depth)
  9625. {
  9626. printk(WARN_LEAD "Commands queued exceeds queue "
  9627. "depth, active=%d\n",
  9628. p->host_no, CTL_OF_CMD(cmd),
  9629. aic_dev->active_cmds);
  9630. }
  9631. #endif
  9632. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9633. if (scb == NULL)
  9634. {
  9635. aic7xxx_allocate_scb(p);
  9636. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9637. if(scb == NULL)
  9638. {
  9639. printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
  9640. CTL_OF_CMD(cmd));
  9641. return 1;
  9642. }
  9643. }
  9644. scb->cmd = cmd;
  9645. /*
  9646. * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
  9647. * is set up properly, and the parity error flag is reset, then send
  9648. * the SCB to the sequencer and watch the fun begin.
  9649. */
  9650. aic7xxx_position(cmd) = scb->hscb->tag;
  9651. cmd->scsi_done = fn;
  9652. cmd->result = DID_OK;
  9653. memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
  9654. aic7xxx_error(cmd) = DID_OK;
  9655. aic7xxx_status(cmd) = 0;
  9656. cmd->host_scribble = NULL;
  9657. /*
  9658. * Construct the SCB beforehand, so the sequencer is
  9659. * paused a minimal amount of time.
  9660. */
  9661. aic7xxx_buildscb(p, cmd, scb);
  9662. scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
  9663. scbq_insert_tail(&p->waiting_scbs, scb);
  9664. aic7xxx_run_waiting_queues(p);
  9665. return (0);
  9666. }
  9667. /*+F*************************************************************************
  9668. * Function:
  9669. * aic7xxx_bus_device_reset
  9670. *
  9671. * Description:
  9672. * Abort or reset the current SCSI command(s). If the scb has not
  9673. * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
  9674. * message to the target. If the scb has previously been unsuccessfully
  9675. * aborted, then we will reset the channel and have all devices renegotiate.
  9676. * Returns an enumerated type that indicates the status of the operation.
  9677. *-F*************************************************************************/
  9678. static int
  9679. __aic7xxx_bus_device_reset(Scsi_Cmnd *cmd)
  9680. {
  9681. struct aic7xxx_host *p;
  9682. struct aic7xxx_scb *scb;
  9683. struct aic7xxx_hwscb *hscb;
  9684. int channel;
  9685. unsigned char saved_scbptr, lastphase;
  9686. unsigned char hscb_index;
  9687. int disconnected;
  9688. struct aic_dev_data *aic_dev;
  9689. if(cmd == NULL)
  9690. {
  9691. printk(KERN_ERR "aic7xxx_bus_device_reset: called with NULL cmd!\n");
  9692. return FAILED;
  9693. }
  9694. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9695. aic_dev = AIC_DEV(cmd);
  9696. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9697. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9698. else
  9699. return FAILED;
  9700. hscb = scb->hscb;
  9701. aic7xxx_isr(p->irq, (void *)p, NULL);
  9702. aic7xxx_done_cmds_complete(p);
  9703. /* If the command was already complete or just completed, then we didn't
  9704. * do a reset, return FAILED */
  9705. if(!(scb->flags & SCB_ACTIVE))
  9706. return FAILED;
  9707. pause_sequencer(p);
  9708. lastphase = aic_inb(p, LASTPHASE);
  9709. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9710. {
  9711. printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
  9712. p->host_no, CTL_OF_SCB(scb), scb->flags);
  9713. switch (lastphase)
  9714. {
  9715. case P_DATAOUT:
  9716. printk("Data-Out phase\n");
  9717. break;
  9718. case P_DATAIN:
  9719. printk("Data-In phase\n");
  9720. break;
  9721. case P_COMMAND:
  9722. printk("Command phase\n");
  9723. break;
  9724. case P_MESGOUT:
  9725. printk("Message-Out phase\n");
  9726. break;
  9727. case P_STATUS:
  9728. printk("Status phase\n");
  9729. break;
  9730. case P_MESGIN:
  9731. printk("Message-In phase\n");
  9732. break;
  9733. default:
  9734. /*
  9735. * We're not in a valid phase, so assume we're idle.
  9736. */
  9737. printk("while idle, LASTPHASE = 0x%x\n", lastphase);
  9738. break;
  9739. }
  9740. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  9741. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  9742. aic_inb(p, SCSISIGI),
  9743. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9744. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  9745. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n", p->host_no,
  9746. CTL_OF_SCB(scb),
  9747. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  9748. aic_inb(p, SSTAT2),
  9749. aic_inb(p, STCNT + 2) << 16 | aic_inb(p, STCNT + 1) << 8 |
  9750. aic_inb(p, STCNT));
  9751. }
  9752. channel = cmd->device->channel;
  9753. /*
  9754. * Send a Device Reset Message:
  9755. * The target that is holding up the bus may not be the same as
  9756. * the one that triggered this timeout (different commands have
  9757. * different timeout lengths). Our strategy here is to queue an
  9758. * abort message to the timed out target if it is disconnected.
  9759. * Otherwise, if we have an active target we stuff the message buffer
  9760. * with an abort message and assert ATN in the hopes that the target
  9761. * will let go of the bus and go to the mesgout phase. If this
  9762. * fails, we'll get another timeout a few seconds later which will
  9763. * attempt a bus reset.
  9764. */
  9765. saved_scbptr = aic_inb(p, SCBPTR);
  9766. disconnected = FALSE;
  9767. if (lastphase != P_BUSFREE)
  9768. {
  9769. if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
  9770. {
  9771. printk(WARN_LEAD "Invalid SCB ID %d is active, "
  9772. "SCB flags = 0x%x.\n", p->host_no,
  9773. CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
  9774. unpause_sequencer(p, FALSE);
  9775. return FAILED;
  9776. }
  9777. if (scb->hscb->tag == aic_inb(p, SCB_TAG))
  9778. {
  9779. if ( (lastphase == P_MESGOUT) || (lastphase == P_MESGIN) )
  9780. {
  9781. printk(WARN_LEAD "Device reset, Message buffer "
  9782. "in use\n", p->host_no, CTL_OF_SCB(scb));
  9783. unpause_sequencer(p, FALSE);
  9784. return FAILED;
  9785. }
  9786. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9787. printk(INFO_LEAD "Device reset message in "
  9788. "message buffer\n", p->host_no, CTL_OF_SCB(scb));
  9789. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9790. aic7xxx_error(cmd) = DID_RESET;
  9791. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9792. /* Send the abort message to the active SCB. */
  9793. aic_outb(p, HOST_MSG, MSG_OUT);
  9794. aic_outb(p, lastphase | ATNO, SCSISIGO);
  9795. unpause_sequencer(p, FALSE);
  9796. spin_unlock_irq(p->host->host_lock);
  9797. ssleep(1);
  9798. spin_lock_irq(p->host->host_lock);
  9799. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9800. return FAILED;
  9801. else
  9802. return SUCCESS;
  9803. }
  9804. } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
  9805. /*
  9806. * Simply set the MK_MESSAGE flag and the SEQINT handler will do
  9807. * the rest on a reconnect/connect.
  9808. */
  9809. scb->hscb->control |= MK_MESSAGE;
  9810. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9811. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9812. /*
  9813. * Check to see if the command is on the qinfifo. If it is, then we will
  9814. * not need to queue the command again since the card should start it soon
  9815. */
  9816. if (aic7xxx_search_qinfifo(p, cmd->device->channel, cmd->device->id, cmd->device->lun, hscb->tag,
  9817. 0, TRUE, NULL) == 0)
  9818. {
  9819. disconnected = TRUE;
  9820. if ((hscb_index = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9821. {
  9822. unsigned char scb_control;
  9823. aic_outb(p, hscb_index, SCBPTR);
  9824. scb_control = aic_inb(p, SCB_CONTROL);
  9825. /*
  9826. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9827. * actually on the waiting list, not disconnected, and we don't
  9828. * need to requeue the command.
  9829. */
  9830. disconnected = (scb_control & DISCONNECTED);
  9831. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  9832. }
  9833. if (disconnected)
  9834. {
  9835. /*
  9836. * Actually requeue this SCB in case we can select the
  9837. * device before it reconnects. This can result in the command
  9838. * being on the qinfifo twice, but we don't care because it will
  9839. * all get cleaned up if/when the reset takes place.
  9840. */
  9841. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9842. printk(INFO_LEAD "Queueing device reset command.\n", p->host_no,
  9843. CTL_OF_SCB(scb));
  9844. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  9845. if (p->features & AHC_QUEUE_REGS)
  9846. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  9847. else
  9848. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  9849. scb->flags |= SCB_QUEUED_ABORT;
  9850. }
  9851. }
  9852. aic_outb(p, saved_scbptr, SCBPTR);
  9853. unpause_sequencer(p, FALSE);
  9854. spin_unlock_irq(p->host->host_lock);
  9855. msleep(1000/4);
  9856. spin_lock_irq(p->host->host_lock);
  9857. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9858. return FAILED;
  9859. else
  9860. return SUCCESS;
  9861. }
  9862. static int
  9863. aic7xxx_bus_device_reset(Scsi_Cmnd *cmd)
  9864. {
  9865. int rc;
  9866. spin_lock_irq(cmd->device->host->host_lock);
  9867. rc = __aic7xxx_bus_device_reset(cmd);
  9868. spin_unlock_irq(cmd->device->host->host_lock);
  9869. return rc;
  9870. }
  9871. /*+F*************************************************************************
  9872. * Function:
  9873. * aic7xxx_panic_abort
  9874. *
  9875. * Description:
  9876. * Abort the current SCSI command(s).
  9877. *-F*************************************************************************/
  9878. static void
  9879. aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
  9880. {
  9881. printk("aic7xxx driver version %s\n", AIC7XXX_C_VERSION);
  9882. printk("Controller type:\n %s\n", board_names[p->board_name_index]);
  9883. printk("p->flags=0x%lx, p->chip=0x%x, p->features=0x%x, "
  9884. "sequencer %s paused\n",
  9885. p->flags, p->chip, p->features,
  9886. (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
  9887. pause_sequencer(p);
  9888. disable_irq(p->irq);
  9889. aic7xxx_print_card(p);
  9890. aic7xxx_print_scratch_ram(p);
  9891. spin_unlock_irq(p->host->host_lock);
  9892. for(;;) barrier();
  9893. }
  9894. /*+F*************************************************************************
  9895. * Function:
  9896. * aic7xxx_abort
  9897. *
  9898. * Description:
  9899. * Abort the current SCSI command(s).
  9900. *-F*************************************************************************/
  9901. static int
  9902. __aic7xxx_abort(Scsi_Cmnd *cmd)
  9903. {
  9904. struct aic7xxx_scb *scb = NULL;
  9905. struct aic7xxx_host *p;
  9906. int found=0, disconnected;
  9907. unsigned char saved_hscbptr, hscbptr, scb_control;
  9908. struct aic_dev_data *aic_dev;
  9909. if(cmd == NULL)
  9910. {
  9911. printk(KERN_ERR "aic7xxx_abort: called with NULL cmd!\n");
  9912. return FAILED;
  9913. }
  9914. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9915. aic_dev = AIC_DEV(cmd);
  9916. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9917. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9918. else
  9919. return FAILED;
  9920. aic7xxx_isr(p->irq, (void *)p, NULL);
  9921. aic7xxx_done_cmds_complete(p);
  9922. /* If the command was already complete or just completed, then we didn't
  9923. * do a reset, return FAILED */
  9924. if(!(scb->flags & SCB_ACTIVE))
  9925. return FAILED;
  9926. pause_sequencer(p);
  9927. /*
  9928. * I added a new config option to the driver: "panic_on_abort" that will
  9929. * cause the driver to panic and the machine to stop on the first abort
  9930. * or reset call into the driver. At that point, it prints out a lot of
  9931. * useful information for me which I can then use to try and debug the
  9932. * problem. Simply enable the boot time prompt in order to activate this
  9933. * code.
  9934. */
  9935. if (aic7xxx_panic_on_abort)
  9936. aic7xxx_panic_abort(p, cmd);
  9937. if (aic7xxx_verbose & VERBOSE_ABORT)
  9938. {
  9939. printk(INFO_LEAD "Aborting scb %d, flags 0x%x, SEQADDR 0x%x, LASTPHASE "
  9940. "0x%x\n",
  9941. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags,
  9942. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9943. aic_inb(p, LASTPHASE));
  9944. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  9945. p->host_no, CTL_OF_SCB(scb), (p->features & AHC_ULTRA2) ?
  9946. aic_inb(p, SG_CACHEPTR) : 0, aic_inb(p, SG_COUNT),
  9947. aic_inb(p, SCSISIGI));
  9948. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  9949. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SSTAT0),
  9950. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  9951. }
  9952. if (scb->flags & SCB_WAITINGQ)
  9953. {
  9954. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9955. printk(INFO_LEAD "SCB found on waiting list and "
  9956. "aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9957. scbq_remove(&p->waiting_scbs, scb);
  9958. scbq_remove(&aic_dev->delayed_scbs, scb);
  9959. aic_dev->active_cmds++;
  9960. p->activescbs++;
  9961. scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
  9962. scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
  9963. goto success;
  9964. }
  9965. /*
  9966. * We just checked the waiting_q, now for the QINFIFO
  9967. */
  9968. if ( ((found = aic7xxx_search_qinfifo(p, cmd->device->id, cmd->device->channel,
  9969. cmd->device->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
  9970. FALSE, NULL)) != 0) &&
  9971. (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
  9972. {
  9973. printk(INFO_LEAD "SCB found in QINFIFO and aborted.\n", p->host_no,
  9974. CTL_OF_SCB(scb));
  9975. goto success;
  9976. }
  9977. /*
  9978. * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
  9979. */
  9980. saved_hscbptr = aic_inb(p, SCBPTR);
  9981. if ((hscbptr = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9982. {
  9983. aic_outb(p, hscbptr, SCBPTR);
  9984. scb_control = aic_inb(p, SCB_CONTROL);
  9985. disconnected = scb_control & DISCONNECTED;
  9986. /*
  9987. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9988. * either currently active or on the waiting list.
  9989. */
  9990. if(!disconnected && aic_inb(p, LASTPHASE) == P_BUSFREE) {
  9991. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9992. printk(INFO_LEAD "SCB found on hardware waiting"
  9993. " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9994. /* If we are the only waiting command, stop the selection engine */
  9995. if (aic_inb(p, WAITING_SCBH) == hscbptr && aic_inb(p, SCB_NEXT) ==
  9996. SCB_LIST_NULL)
  9997. {
  9998. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  9999. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  10000. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  10001. }
  10002. else
  10003. {
  10004. unsigned char prev, next;
  10005. prev = SCB_LIST_NULL;
  10006. next = aic_inb(p, WAITING_SCBH);
  10007. while(next != SCB_LIST_NULL)
  10008. {
  10009. aic_outb(p, next, SCBPTR);
  10010. if (next == hscbptr)
  10011. {
  10012. next = aic_inb(p, SCB_NEXT);
  10013. if (prev != SCB_LIST_NULL)
  10014. {
  10015. aic_outb(p, prev, SCBPTR);
  10016. aic_outb(p, next, SCB_NEXT);
  10017. }
  10018. else
  10019. aic_outb(p, next, WAITING_SCBH);
  10020. aic_outb(p, hscbptr, SCBPTR);
  10021. next = SCB_LIST_NULL;
  10022. }
  10023. else
  10024. {
  10025. prev = next;
  10026. next = aic_inb(p, SCB_NEXT);
  10027. }
  10028. }
  10029. }
  10030. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  10031. aic_outb(p, 0, SCB_CONTROL);
  10032. aic7xxx_add_curscb_to_free_list(p);
  10033. scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
  10034. goto success;
  10035. }
  10036. else if (!disconnected)
  10037. {
  10038. /*
  10039. * We are the currently active command
  10040. */
  10041. if((aic_inb(p, LASTPHASE) == P_MESGIN) ||
  10042. (aic_inb(p, LASTPHASE) == P_MESGOUT))
  10043. {
  10044. /*
  10045. * Message buffer busy, unable to abort
  10046. */
  10047. printk(INFO_LEAD "message buffer busy, unable to abort.\n",
  10048. p->host_no, CTL_OF_SCB(scb));
  10049. unpause_sequencer(p, FALSE);
  10050. return FAILED;
  10051. }
  10052. /* Fallthrough to below, set ATNO after we set SCB_CONTROL */
  10053. }
  10054. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  10055. if(!disconnected)
  10056. {
  10057. aic_outb(p, HOST_MSG, MSG_OUT);
  10058. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  10059. }
  10060. aic_outb(p, saved_hscbptr, SCBPTR);
  10061. }
  10062. else
  10063. {
  10064. /*
  10065. * The scb isn't in the card at all and it is active and it isn't in
  10066. * any of the queues, so it must be disconnected and paged out. Fall
  10067. * through to the code below.
  10068. */
  10069. disconnected = 1;
  10070. }
  10071. p->flags |= AHC_ABORT_PENDING;
  10072. scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
  10073. scb->hscb->control |= MK_MESSAGE;
  10074. if(disconnected)
  10075. {
  10076. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  10077. printk(INFO_LEAD "SCB disconnected. Queueing Abort"
  10078. " SCB.\n", p->host_no, CTL_OF_SCB(scb));
  10079. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  10080. if (p->features & AHC_QUEUE_REGS)
  10081. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  10082. else
  10083. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  10084. }
  10085. unpause_sequencer(p, FALSE);
  10086. spin_unlock_irq(p->host->host_lock);
  10087. msleep(1000/4);
  10088. spin_lock_irq(p->host->host_lock);
  10089. if (p->flags & AHC_ABORT_PENDING)
  10090. {
  10091. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10092. printk(INFO_LEAD "Abort never delivered, returning FAILED\n", p->host_no,
  10093. CTL_OF_CMD(cmd));
  10094. p->flags &= ~AHC_ABORT_PENDING;
  10095. return FAILED;
  10096. }
  10097. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10098. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10099. return SUCCESS;
  10100. success:
  10101. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10102. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10103. aic7xxx_run_done_queue(p, TRUE);
  10104. unpause_sequencer(p, FALSE);
  10105. return SUCCESS;
  10106. }
  10107. static int
  10108. aic7xxx_abort(Scsi_Cmnd *cmd)
  10109. {
  10110. int rc;
  10111. spin_lock_irq(cmd->device->host->host_lock);
  10112. rc = __aic7xxx_abort(cmd);
  10113. spin_unlock_irq(cmd->device->host->host_lock);
  10114. return rc;
  10115. }
  10116. /*+F*************************************************************************
  10117. * Function:
  10118. * aic7xxx_reset
  10119. *
  10120. * Description:
  10121. * Resetting the bus always succeeds - is has to, otherwise the
  10122. * kernel will panic! Try a surgical technique - sending a BUS
  10123. * DEVICE RESET message - on the offending target before pulling
  10124. * the SCSI bus reset line.
  10125. *-F*************************************************************************/
  10126. static int
  10127. aic7xxx_reset(Scsi_Cmnd *cmd)
  10128. {
  10129. struct aic7xxx_scb *scb;
  10130. struct aic7xxx_host *p;
  10131. struct aic_dev_data *aic_dev;
  10132. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  10133. spin_lock_irq(p->host->host_lock);
  10134. aic_dev = AIC_DEV(cmd);
  10135. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  10136. {
  10137. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  10138. if (scb->cmd != cmd)
  10139. scb = NULL;
  10140. }
  10141. else
  10142. {
  10143. scb = NULL;
  10144. }
  10145. /*
  10146. * I added a new config option to the driver: "panic_on_abort" that will
  10147. * cause the driver to panic and the machine to stop on the first abort
  10148. * or reset call into the driver. At that point, it prints out a lot of
  10149. * useful information for me which I can then use to try and debug the
  10150. * problem. Simply enable the boot time prompt in order to activate this
  10151. * code.
  10152. */
  10153. if (aic7xxx_panic_on_abort)
  10154. aic7xxx_panic_abort(p, cmd);
  10155. pause_sequencer(p);
  10156. while((aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
  10157. {
  10158. aic7xxx_isr(p->irq, p, (void *)NULL );
  10159. pause_sequencer(p);
  10160. }
  10161. aic7xxx_done_cmds_complete(p);
  10162. if(scb && (scb->cmd == NULL))
  10163. {
  10164. /*
  10165. * We just completed the command when we ran the isr stuff, so we no
  10166. * longer have it.
  10167. */
  10168. unpause_sequencer(p, FALSE);
  10169. spin_unlock_irq(p->host->host_lock);
  10170. return SUCCESS;
  10171. }
  10172. /*
  10173. * By this point, we want to already know what we are going to do and
  10174. * only have the following code implement our course of action.
  10175. */
  10176. aic7xxx_reset_channel(p, cmd->device->channel, TRUE);
  10177. if (p->features & AHC_TWIN)
  10178. {
  10179. aic7xxx_reset_channel(p, cmd->device->channel ^ 0x01, TRUE);
  10180. restart_sequencer(p);
  10181. }
  10182. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  10183. aic7xxx_clear_intstat(p);
  10184. p->flags &= ~AHC_HANDLING_REQINITS;
  10185. p->msg_type = MSG_TYPE_NONE;
  10186. p->msg_index = 0;
  10187. p->msg_len = 0;
  10188. aic7xxx_run_done_queue(p, TRUE);
  10189. unpause_sequencer(p, FALSE);
  10190. spin_unlock_irq(p->host->host_lock);
  10191. ssleep(2);
  10192. return SUCCESS;
  10193. }
  10194. /*+F*************************************************************************
  10195. * Function:
  10196. * aic7xxx_biosparam
  10197. *
  10198. * Description:
  10199. * Return the disk geometry for the given SCSI device.
  10200. *
  10201. * Note:
  10202. * This function is broken for today's really large drives and needs
  10203. * fixed.
  10204. *-F*************************************************************************/
  10205. static int
  10206. aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  10207. sector_t capacity, int geom[])
  10208. {
  10209. sector_t heads, sectors, cylinders;
  10210. int ret;
  10211. struct aic7xxx_host *p;
  10212. unsigned char *buf;
  10213. p = (struct aic7xxx_host *) sdev->host->hostdata;
  10214. buf = scsi_bios_ptable(bdev);
  10215. if ( buf )
  10216. {
  10217. ret = scsi_partsize(buf, capacity, &geom[2], &geom[0], &geom[1]);
  10218. kfree(buf);
  10219. if ( ret != -1 )
  10220. return(ret);
  10221. }
  10222. heads = 64;
  10223. sectors = 32;
  10224. cylinders = capacity >> 11;
  10225. if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
  10226. {
  10227. heads = 255;
  10228. sectors = 63;
  10229. cylinders = capacity >> 14;
  10230. if(capacity > (65535 * heads * sectors))
  10231. cylinders = 65535;
  10232. else
  10233. cylinders = ((unsigned int)capacity) / (unsigned int)(heads * sectors);
  10234. }
  10235. geom[0] = (int)heads;
  10236. geom[1] = (int)sectors;
  10237. geom[2] = (int)cylinders;
  10238. return (0);
  10239. }
  10240. /*+F*************************************************************************
  10241. * Function:
  10242. * aic7xxx_release
  10243. *
  10244. * Description:
  10245. * Free the passed in Scsi_Host memory structures prior to unloading the
  10246. * module.
  10247. *-F*************************************************************************/
  10248. static int
  10249. aic7xxx_release(struct Scsi_Host *host)
  10250. {
  10251. struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
  10252. struct aic7xxx_host *next, *prev;
  10253. if(p->irq)
  10254. free_irq(p->irq, p);
  10255. #ifdef MMAPIO
  10256. if(p->maddr)
  10257. {
  10258. iounmap(p->maddr);
  10259. }
  10260. #endif /* MMAPIO */
  10261. if(!p->pdev)
  10262. release_region(p->base, MAXREG - MINREG);
  10263. #ifdef CONFIG_PCI
  10264. else
  10265. pci_release_regions(p->pdev);
  10266. #endif
  10267. prev = NULL;
  10268. next = first_aic7xxx;
  10269. while(next != NULL)
  10270. {
  10271. if(next == p)
  10272. {
  10273. if(prev == NULL)
  10274. first_aic7xxx = next->next;
  10275. else
  10276. prev->next = next->next;
  10277. }
  10278. else
  10279. {
  10280. prev = next;
  10281. }
  10282. next = next->next;
  10283. }
  10284. aic7xxx_free(p);
  10285. return(0);
  10286. }
  10287. /*+F*************************************************************************
  10288. * Function:
  10289. * aic7xxx_print_card
  10290. *
  10291. * Description:
  10292. * Print out all of the control registers on the card
  10293. *
  10294. * NOTE: This function is not yet safe for use on the VLB and EISA
  10295. * controllers, so it isn't used on those controllers at all.
  10296. *-F*************************************************************************/
  10297. static void
  10298. aic7xxx_print_card(struct aic7xxx_host *p)
  10299. {
  10300. int i, j, k, chip;
  10301. static struct register_ranges {
  10302. int num_ranges;
  10303. int range_val[32];
  10304. } cards_ds[] = {
  10305. { 0, {0,} }, /* none */
  10306. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
  10307. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
  10308. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
  10309. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10310. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
  10311. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10312. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
  10313. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10314. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
  10315. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10316. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
  10317. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10318. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10319. 0xfe, 0xff} },
  10320. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
  10321. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
  10322. 0x9f, 0x9f, 0xe0, 0xf1} },
  10323. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
  10324. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10325. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10326. 0xfe, 0xff} },
  10327. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
  10328. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10329. 0xe0, 0xf1, 0xf4, 0xfc} },
  10330. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
  10331. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10332. 0xe0, 0xf1, 0xf4, 0xfc} },
  10333. };
  10334. chip = p->chip & AHC_CHIPID_MASK;
  10335. printk("%s at ",
  10336. board_names[p->board_name_index]);
  10337. switch(p->chip & ~AHC_CHIPID_MASK)
  10338. {
  10339. case AHC_VL:
  10340. printk("VLB Slot %d.\n", p->pci_device_fn);
  10341. break;
  10342. case AHC_EISA:
  10343. printk("EISA Slot %d.\n", p->pci_device_fn);
  10344. break;
  10345. case AHC_PCI:
  10346. default:
  10347. printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  10348. PCI_FUNC(p->pci_device_fn));
  10349. break;
  10350. }
  10351. /*
  10352. * the registers on the card....
  10353. */
  10354. printk("Card Dump:\n");
  10355. k = 0;
  10356. for(i=0; i<cards_ds[chip].num_ranges; i++)
  10357. {
  10358. for(j = cards_ds[chip].range_val[ i * 2 ];
  10359. j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
  10360. j++)
  10361. {
  10362. printk("%02x:%02x ", j, aic_inb(p, j));
  10363. if(++k == 13)
  10364. {
  10365. printk("\n");
  10366. k=0;
  10367. }
  10368. }
  10369. }
  10370. if(k != 0)
  10371. printk("\n");
  10372. /*
  10373. * If this was an Ultra2 controller, then we just hosed the card in terms
  10374. * of the QUEUE REGS. This function is only called at init time or by
  10375. * the panic_abort function, so it's safe to assume a generic init time
  10376. * setting here
  10377. */
  10378. if(p->features & AHC_QUEUE_REGS)
  10379. {
  10380. aic_outb(p, 0, SDSCB_QOFF);
  10381. aic_outb(p, 0, SNSCB_QOFF);
  10382. aic_outb(p, 0, HNSCB_QOFF);
  10383. }
  10384. }
  10385. /*+F*************************************************************************
  10386. * Function:
  10387. * aic7xxx_print_scratch_ram
  10388. *
  10389. * Description:
  10390. * Print out the scratch RAM values on the card.
  10391. *-F*************************************************************************/
  10392. static void
  10393. aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
  10394. {
  10395. int i, k;
  10396. k = 0;
  10397. printk("Scratch RAM:\n");
  10398. for(i = SRAM_BASE; i < SEQCTL; i++)
  10399. {
  10400. printk("%02x:%02x ", i, aic_inb(p, i));
  10401. if(++k == 13)
  10402. {
  10403. printk("\n");
  10404. k=0;
  10405. }
  10406. }
  10407. if (p->features & AHC_MORE_SRAM)
  10408. {
  10409. for(i = TARG_OFFSET; i < 0x80; i++)
  10410. {
  10411. printk("%02x:%02x ", i, aic_inb(p, i));
  10412. if(++k == 13)
  10413. {
  10414. printk("\n");
  10415. k=0;
  10416. }
  10417. }
  10418. }
  10419. printk("\n");
  10420. }
  10421. #include "aic7xxx_old/aic7xxx_proc.c"
  10422. MODULE_LICENSE("Dual BSD/GPL");
  10423. MODULE_VERSION(AIC7XXX_H_VERSION);
  10424. static Scsi_Host_Template driver_template = {
  10425. .proc_info = aic7xxx_proc_info,
  10426. .detect = aic7xxx_detect,
  10427. .release = aic7xxx_release,
  10428. .info = aic7xxx_info,
  10429. .queuecommand = aic7xxx_queue,
  10430. .slave_alloc = aic7xxx_slave_alloc,
  10431. .slave_configure = aic7xxx_slave_configure,
  10432. .slave_destroy = aic7xxx_slave_destroy,
  10433. .bios_param = aic7xxx_biosparam,
  10434. .eh_abort_handler = aic7xxx_abort,
  10435. .eh_device_reset_handler = aic7xxx_bus_device_reset,
  10436. .eh_host_reset_handler = aic7xxx_reset,
  10437. .can_queue = 255,
  10438. .this_id = -1,
  10439. .max_sectors = 2048,
  10440. .cmd_per_lun = 3,
  10441. .use_clustering = ENABLE_CLUSTERING,
  10442. };
  10443. #include "scsi_module.c"
  10444. /*
  10445. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  10446. * Emacs will notice this stuff at the end of the file and automatically
  10447. * adjust the settings for this buffer only. This must remain at the end
  10448. * of the file.
  10449. * ---------------------------------------------------------------------------
  10450. * Local variables:
  10451. * c-indent-level: 2
  10452. * c-brace-imaginary-offset: 0
  10453. * c-brace-offset: -2
  10454. * c-argdecl-indent: 2
  10455. * c-label-offset: -2
  10456. * c-continued-statement-offset: 2
  10457. * c-continued-brace-offset: 0
  10458. * indent-tabs-mode: nil
  10459. * tab-width: 8
  10460. * End:
  10461. */