aic7xxx_old.c 361 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203
  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 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 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. struct 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(struct 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, struct 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(struct 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(struct 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(struct 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(struct 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. kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
  7916. p->scb_data->scb_array[i] = NULL;
  7917. }
  7918. /*
  7919. * Free the SCB data area.
  7920. */
  7921. kfree(p->scb_data);
  7922. }
  7923. pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
  7924. }
  7925. /*+F*************************************************************************
  7926. * Function:
  7927. * aic7xxx_load_seeprom
  7928. *
  7929. * Description:
  7930. * Load the seeprom and configure adapter and target settings.
  7931. * Returns 1 if the load was successful and 0 otherwise.
  7932. *-F*************************************************************************/
  7933. static void
  7934. aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
  7935. {
  7936. int have_seeprom = 0;
  7937. int i, max_targets, mask;
  7938. unsigned char scsirate, scsi_conf;
  7939. unsigned short scarray[128];
  7940. struct seeprom_config *sc = (struct seeprom_config *) scarray;
  7941. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7942. {
  7943. printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
  7944. }
  7945. switch (p->chip)
  7946. {
  7947. case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
  7948. if (aic_inb(p, SCSICONF) & TERM_ENB)
  7949. p->flags |= AHC_TERM_ENB_A;
  7950. if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
  7951. p->flags |= AHC_TERM_ENB_B;
  7952. break;
  7953. case (AHC_AIC7770|AHC_VL):
  7954. have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
  7955. break;
  7956. default:
  7957. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7958. scarray, p->sc_size, p->sc_type);
  7959. if (!have_seeprom)
  7960. {
  7961. if(p->sc_type == C46)
  7962. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7963. scarray, p->sc_size, C56_66);
  7964. else
  7965. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7966. scarray, p->sc_size, C46);
  7967. }
  7968. if (!have_seeprom)
  7969. {
  7970. p->sc_size = 128;
  7971. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7972. scarray, p->sc_size, p->sc_type);
  7973. if (!have_seeprom)
  7974. {
  7975. if(p->sc_type == C46)
  7976. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7977. scarray, p->sc_size, C56_66);
  7978. else
  7979. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7980. scarray, p->sc_size, C46);
  7981. }
  7982. }
  7983. break;
  7984. }
  7985. if (!have_seeprom)
  7986. {
  7987. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7988. {
  7989. printk("\naic7xxx: No SEEPROM available.\n");
  7990. }
  7991. p->flags |= AHC_NEWEEPROM_FMT;
  7992. if (aic_inb(p, SCSISEQ) == 0)
  7993. {
  7994. p->flags |= AHC_USEDEFAULTS;
  7995. p->flags &= ~AHC_BIOS_ENABLED;
  7996. p->scsi_id = p->scsi_id_b = 7;
  7997. *sxfrctl1 |= STPWEN;
  7998. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7999. {
  8000. printk("aic7xxx: Using default values.\n");
  8001. }
  8002. }
  8003. else if (aic7xxx_verbose & VERBOSE_PROBE2)
  8004. {
  8005. printk("aic7xxx: Using leftover BIOS values.\n");
  8006. }
  8007. if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
  8008. {
  8009. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8010. sc->adapter_control &= ~CFAUTOTERM;
  8011. sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
  8012. }
  8013. if (aic7xxx_extended)
  8014. p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  8015. else
  8016. p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  8017. }
  8018. else
  8019. {
  8020. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8021. {
  8022. printk("done\n");
  8023. }
  8024. /*
  8025. * Note things in our flags
  8026. */
  8027. p->flags |= AHC_SEEPROM_FOUND;
  8028. /*
  8029. * Update the settings in sxfrctl1 to match the termination settings.
  8030. */
  8031. *sxfrctl1 = 0;
  8032. /*
  8033. * Get our SCSI ID from the SEEPROM setting...
  8034. */
  8035. p->scsi_id = (sc->brtime_id & CFSCSIID);
  8036. /*
  8037. * First process the settings that are different between the VLB
  8038. * and PCI adapter seeproms.
  8039. */
  8040. if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
  8041. {
  8042. /* VLB adapter seeproms */
  8043. if (sc->bios_control & CF284XEXTEND)
  8044. p->flags |= AHC_EXTEND_TRANS_A;
  8045. if (sc->adapter_control & CF284XSTERM)
  8046. {
  8047. *sxfrctl1 |= STPWEN;
  8048. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8049. }
  8050. }
  8051. else
  8052. {
  8053. /* PCI adapter seeproms */
  8054. if (sc->bios_control & CFEXTEND)
  8055. p->flags |= AHC_EXTEND_TRANS_A;
  8056. if (sc->bios_control & CFBIOSEN)
  8057. p->flags |= AHC_BIOS_ENABLED;
  8058. else
  8059. p->flags &= ~AHC_BIOS_ENABLED;
  8060. if (sc->adapter_control & CFSTERM)
  8061. {
  8062. *sxfrctl1 |= STPWEN;
  8063. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8064. }
  8065. }
  8066. memcpy(&p->sc, sc, sizeof(struct seeprom_config));
  8067. }
  8068. p->discenable = 0;
  8069. /*
  8070. * Limit to 16 targets just in case. The 2842 for one is known to
  8071. * blow the max_targets setting, future cards might also.
  8072. */
  8073. max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
  8074. if (have_seeprom)
  8075. {
  8076. for (i = 0; i < max_targets; i++)
  8077. {
  8078. if( ((p->features & AHC_ULTRA) &&
  8079. !(sc->adapter_control & CFULTRAEN) &&
  8080. (sc->device_flags[i] & CFSYNCHISULTRA)) ||
  8081. (sc->device_flags[i] & CFNEWULTRAFORMAT) )
  8082. {
  8083. p->flags |= AHC_NEWEEPROM_FMT;
  8084. break;
  8085. }
  8086. }
  8087. }
  8088. for (i = 0; i < max_targets; i++)
  8089. {
  8090. mask = (0x01 << i);
  8091. if (!have_seeprom)
  8092. {
  8093. if (aic_inb(p, SCSISEQ) != 0)
  8094. {
  8095. /*
  8096. * OK...the BIOS set things up and left behind the settings we need.
  8097. * Just make our sc->device_flags[i] entry match what the card has
  8098. * set for this device.
  8099. */
  8100. p->discenable =
  8101. ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
  8102. p->ultraenb =
  8103. (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
  8104. sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
  8105. if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
  8106. sc->device_flags[i] |= CFWIDEB;
  8107. if (p->features & AHC_ULTRA2)
  8108. {
  8109. if (aic_inb(p, TARG_OFFSET + i))
  8110. {
  8111. sc->device_flags[i] |= CFSYNCH;
  8112. sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
  8113. if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
  8114. sc->device_flags[i] |= CFSYNCHISULTRA;
  8115. }
  8116. }
  8117. else
  8118. {
  8119. if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
  8120. {
  8121. sc->device_flags[i] |= CFSYNCH;
  8122. if (p->features & AHC_ULTRA)
  8123. sc->device_flags[i] |= ((p->ultraenb & mask) ?
  8124. CFSYNCHISULTRA : 0);
  8125. }
  8126. }
  8127. }
  8128. else
  8129. {
  8130. /*
  8131. * Assume the BIOS has NOT been run on this card and nothing between
  8132. * the card and the devices is configured yet.
  8133. */
  8134. sc->device_flags[i] = CFDISC;
  8135. if (p->features & AHC_WIDE)
  8136. sc->device_flags[i] |= CFWIDEB;
  8137. if (p->features & AHC_ULTRA3)
  8138. sc->device_flags[i] |= 2;
  8139. else if (p->features & AHC_ULTRA2)
  8140. sc->device_flags[i] |= 3;
  8141. else if (p->features & AHC_ULTRA)
  8142. sc->device_flags[i] |= CFSYNCHISULTRA;
  8143. sc->device_flags[i] |= CFSYNCH;
  8144. aic_outb(p, 0, TARG_SCSIRATE + i);
  8145. if (p->features & AHC_ULTRA2)
  8146. aic_outb(p, 0, TARG_OFFSET + i);
  8147. }
  8148. }
  8149. if (sc->device_flags[i] & CFDISC)
  8150. {
  8151. p->discenable |= mask;
  8152. }
  8153. if (p->flags & AHC_NEWEEPROM_FMT)
  8154. {
  8155. if ( !(p->features & AHC_ULTRA2) )
  8156. {
  8157. /*
  8158. * I know of two different Ultra BIOSes that do this differently.
  8159. * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
  8160. * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
  8161. * while on the IBM Netfinity 5000 they want the same thing
  8162. * to be something else, while flags[i] & CFXFER == 0x03 and
  8163. * SYNCHISULTRA false should be 40MByte/s. So, we set both to
  8164. * 40MByte/s and the lower speeds be damned. People will have
  8165. * to select around the conversely mapped lower speeds in order
  8166. * to select lower speeds on these boards.
  8167. */
  8168. if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8169. ((sc->device_flags[i] & CFXFER) == 0x03) )
  8170. {
  8171. sc->device_flags[i] &= ~CFXFER;
  8172. sc->device_flags[i] |= CFSYNCHISULTRA;
  8173. }
  8174. if (sc->device_flags[i] & CFSYNCHISULTRA)
  8175. {
  8176. p->ultraenb |= mask;
  8177. }
  8178. }
  8179. else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8180. (p->features & AHC_ULTRA2) &&
  8181. (sc->device_flags[i] & CFSYNCHISULTRA) )
  8182. {
  8183. p->ultraenb |= mask;
  8184. }
  8185. }
  8186. else if (sc->adapter_control & CFULTRAEN)
  8187. {
  8188. p->ultraenb |= mask;
  8189. }
  8190. if ( (sc->device_flags[i] & CFSYNCH) == 0)
  8191. {
  8192. sc->device_flags[i] &= ~CFXFER;
  8193. p->ultraenb &= ~mask;
  8194. p->user[i].offset = 0;
  8195. p->user[i].period = 0;
  8196. p->user[i].options = 0;
  8197. }
  8198. else
  8199. {
  8200. if (p->features & AHC_ULTRA3)
  8201. {
  8202. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8203. if( (sc->device_flags[i] & CFXFER) < 0x03 )
  8204. {
  8205. scsirate = (sc->device_flags[i] & CFXFER);
  8206. p->user[i].options = MSG_EXT_PPR_OPTION_DT_CRC;
  8207. }
  8208. else
  8209. {
  8210. scsirate = (sc->device_flags[i] & CFXFER) |
  8211. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8212. p->user[i].options = 0;
  8213. }
  8214. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8215. AHC_SYNCRATE_ULTRA3);
  8216. }
  8217. else if (p->features & AHC_ULTRA2)
  8218. {
  8219. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8220. scsirate = (sc->device_flags[i] & CFXFER) |
  8221. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8222. p->user[i].options = 0;
  8223. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8224. AHC_SYNCRATE_ULTRA2);
  8225. }
  8226. else
  8227. {
  8228. scsirate = (sc->device_flags[i] & CFXFER) << 4;
  8229. p->user[i].options = 0;
  8230. p->user[i].offset = MAX_OFFSET_8BIT;
  8231. if (p->features & AHC_ULTRA)
  8232. {
  8233. short ultraenb;
  8234. ultraenb = aic_inb(p, ULTRA_ENB) |
  8235. (aic_inb(p, ULTRA_ENB + 1) << 8);
  8236. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8237. (p->ultraenb & mask) ?
  8238. AHC_SYNCRATE_ULTRA :
  8239. AHC_SYNCRATE_FAST);
  8240. }
  8241. else
  8242. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8243. AHC_SYNCRATE_FAST);
  8244. }
  8245. }
  8246. if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
  8247. {
  8248. p->user[i].width = MSG_EXT_WDTR_BUS_16_BIT;
  8249. }
  8250. else
  8251. {
  8252. p->user[i].width = MSG_EXT_WDTR_BUS_8_BIT;
  8253. }
  8254. }
  8255. aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
  8256. aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
  8257. /*
  8258. * We set the p->ultraenb from the SEEPROM to begin with, but now we make
  8259. * it match what is already down in the card. If we are doing a reset
  8260. * on the card then this will get put back to a default state anyway.
  8261. * This allows us to not have to pre-emptively negotiate when using the
  8262. * no_reset option.
  8263. */
  8264. if (p->features & AHC_ULTRA)
  8265. p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
  8266. scsi_conf = (p->scsi_id & HSCSIID);
  8267. if(have_seeprom)
  8268. {
  8269. p->adapter_control = sc->adapter_control;
  8270. p->bios_control = sc->bios_control;
  8271. switch (p->chip & AHC_CHIPID_MASK)
  8272. {
  8273. case AHC_AIC7895:
  8274. case AHC_AIC7896:
  8275. case AHC_AIC7899:
  8276. if (p->adapter_control & CFBPRIMARY)
  8277. p->flags |= AHC_CHANNEL_B_PRIMARY;
  8278. default:
  8279. break;
  8280. }
  8281. if (sc->adapter_control & CFSPARITY)
  8282. scsi_conf |= ENSPCHK;
  8283. }
  8284. else
  8285. {
  8286. scsi_conf |= ENSPCHK | RESET_SCSI;
  8287. }
  8288. /*
  8289. * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
  8290. * The 2842 and 2742 cards already have these registers set and we don't
  8291. * want to muck with them since we don't set all the bits they do.
  8292. */
  8293. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  8294. {
  8295. /* Set the host ID */
  8296. aic_outb(p, scsi_conf, SCSICONF);
  8297. /* In case we are a wide card */
  8298. aic_outb(p, p->scsi_id, SCSICONF + 1);
  8299. }
  8300. }
  8301. /*+F*************************************************************************
  8302. * Function:
  8303. * aic7xxx_configure_bugs
  8304. *
  8305. * Description:
  8306. * Take the card passed in and set the appropriate bug flags based upon
  8307. * the card model. Also make any changes needed to device registers or
  8308. * PCI registers while we are here.
  8309. *-F*************************************************************************/
  8310. static void
  8311. aic7xxx_configure_bugs(struct aic7xxx_host *p)
  8312. {
  8313. unsigned short tmp_word;
  8314. switch(p->chip & AHC_CHIPID_MASK)
  8315. {
  8316. case AHC_AIC7860:
  8317. p->bugs |= AHC_BUG_PCI_2_1_RETRY;
  8318. /* fall through */
  8319. case AHC_AIC7850:
  8320. case AHC_AIC7870:
  8321. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8322. break;
  8323. case AHC_AIC7880:
  8324. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8325. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8326. break;
  8327. case AHC_AIC7890:
  8328. p->bugs |= AHC_BUG_AUTOFLUSH | AHC_BUG_CACHETHEN;
  8329. break;
  8330. case AHC_AIC7892:
  8331. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8332. break;
  8333. case AHC_AIC7895:
  8334. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8335. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8336. break;
  8337. case AHC_AIC7896:
  8338. p->bugs |= AHC_BUG_CACHETHEN_DIS;
  8339. break;
  8340. case AHC_AIC7899:
  8341. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8342. break;
  8343. default:
  8344. /* Nothing to do */
  8345. break;
  8346. }
  8347. /*
  8348. * Now handle the bugs that require PCI register or card register tweaks
  8349. */
  8350. pci_read_config_word(p->pdev, PCI_COMMAND, &tmp_word);
  8351. if(p->bugs & AHC_BUG_PCI_MWI)
  8352. {
  8353. tmp_word &= ~PCI_COMMAND_INVALIDATE;
  8354. }
  8355. else
  8356. {
  8357. tmp_word |= PCI_COMMAND_INVALIDATE;
  8358. }
  8359. pci_write_config_word(p->pdev, PCI_COMMAND, tmp_word);
  8360. if(p->bugs & AHC_BUG_CACHETHEN)
  8361. {
  8362. aic_outb(p, aic_inb(p, DSCOMMAND0) & ~CACHETHEN, DSCOMMAND0);
  8363. }
  8364. else if (p->bugs & AHC_BUG_CACHETHEN_DIS)
  8365. {
  8366. aic_outb(p, aic_inb(p, DSCOMMAND0) | CACHETHEN, DSCOMMAND0);
  8367. }
  8368. return;
  8369. }
  8370. /*+F*************************************************************************
  8371. * Function:
  8372. * aic7xxx_detect
  8373. *
  8374. * Description:
  8375. * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
  8376. *
  8377. * XXX - This should really be called aic7xxx_probe(). A sequence of
  8378. * probe(), attach()/detach(), and init() makes more sense than
  8379. * one do-it-all function. This may be useful when (and if) the
  8380. * mid-level SCSI code is overhauled.
  8381. *-F*************************************************************************/
  8382. static int
  8383. aic7xxx_detect(struct scsi_host_template *template)
  8384. {
  8385. struct aic7xxx_host *temp_p = NULL;
  8386. struct aic7xxx_host *current_p = NULL;
  8387. struct aic7xxx_host *list_p = NULL;
  8388. int found = 0;
  8389. #if defined(__i386__) || defined(__alpha__)
  8390. ahc_flag_type flags = 0;
  8391. int type;
  8392. #endif
  8393. unsigned char sxfrctl1;
  8394. #if defined(__i386__) || defined(__alpha__)
  8395. unsigned char hcntrl, hostconf;
  8396. unsigned int slot, base;
  8397. #endif
  8398. #ifdef MODULE
  8399. /*
  8400. * If we are called as a module, the aic7xxx pointer may not be null
  8401. * and it would point to our bootup string, just like on the lilo
  8402. * command line. IF not NULL, then process this config string with
  8403. * aic7xxx_setup
  8404. */
  8405. if(aic7xxx)
  8406. aic7xxx_setup(aic7xxx);
  8407. #endif
  8408. template->proc_name = "aic7xxx";
  8409. template->sg_tablesize = AIC7XXX_MAX_SG;
  8410. #ifdef CONFIG_PCI
  8411. /*
  8412. * PCI-bus probe.
  8413. */
  8414. {
  8415. static struct
  8416. {
  8417. unsigned short vendor_id;
  8418. unsigned short device_id;
  8419. ahc_chip chip;
  8420. ahc_flag_type flags;
  8421. ahc_feature features;
  8422. int board_name_index;
  8423. unsigned short seeprom_size;
  8424. unsigned short seeprom_type;
  8425. } const aic_pdevs[] = {
  8426. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
  8427. AHC_FNONE, AHC_FENONE, 1,
  8428. 32, C46 },
  8429. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
  8430. AHC_PAGESCBS, AHC_AIC7850_FE, 5,
  8431. 32, C46 },
  8432. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
  8433. AHC_PAGESCBS, AHC_AIC7850_FE, 6,
  8434. 32, C46 },
  8435. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
  8436. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8437. AHC_AIC7860_FE, 7,
  8438. 32, C46 },
  8439. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
  8440. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8441. AHC_AIC7860_FE, 7,
  8442. 32, C46 },
  8443. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8444. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8445. AHC_AIC7860_FE, 7,
  8446. 32, C46 },
  8447. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8448. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8449. AHC_AIC7860_FE, 7,
  8450. 32, C46 },
  8451. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
  8452. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8453. AHC_AIC7860_FE, 7,
  8454. 32, C46 },
  8455. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
  8456. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8457. AHC_AIC7860_FE, 8,
  8458. 32, C46 },
  8459. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
  8460. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8461. AHC_AIC7870_FE, 9,
  8462. 32, C46 },
  8463. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
  8464. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
  8465. 32, C46 },
  8466. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
  8467. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8468. AHC_AIC7870_FE, 11,
  8469. 32, C56_66 },
  8470. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
  8471. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8472. AHC_AIC7870_FE, 12,
  8473. 32, C56_66 },
  8474. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
  8475. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
  8476. 32, C46 },
  8477. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
  8478. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8479. AHC_AIC7880_FE, 14,
  8480. 32, C46 },
  8481. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
  8482. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
  8483. 32, C46 },
  8484. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
  8485. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8486. AHC_AIC7880_FE, 16,
  8487. 32, C56_66 },
  8488. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
  8489. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8490. AHC_AIC7880_FE, 17,
  8491. 32, C56_66 },
  8492. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
  8493. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8494. 32, C46 },
  8495. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
  8496. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8497. 32, C46 },
  8498. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
  8499. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8500. 32, C46 },
  8501. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
  8502. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 19,
  8503. 32, C46 },
  8504. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
  8505. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8506. 32, C46 },
  8507. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
  8508. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8509. AHC_AIC7895_FE, 20,
  8510. 32, C56_66 },
  8511. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
  8512. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8513. AHC_AIC7890_FE, 21,
  8514. 32, C46 },
  8515. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
  8516. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8517. AHC_AIC7890_FE, 21,
  8518. 32, C46 },
  8519. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
  8520. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8521. AHC_AIC7890_FE, 22,
  8522. 32, C46 },
  8523. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
  8524. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8525. AHC_AIC7890_FE, 23,
  8526. 32, C46 },
  8527. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
  8528. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8529. AHC_AIC7896_FE, 24,
  8530. 32, C56_66 },
  8531. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
  8532. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8533. AHC_AIC7896_FE, 25,
  8534. 32, C56_66 },
  8535. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
  8536. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8537. AHC_AIC7896_FE, 26,
  8538. 32, C56_66 },
  8539. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
  8540. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWEN,
  8541. AHC_AIC7860_FE, 27,
  8542. 32, C46 },
  8543. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
  8544. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8545. AHC_AIC7892_FE, 28,
  8546. 32, C46 },
  8547. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
  8548. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8549. AHC_AIC7892_FE, 28,
  8550. 32, C46 },
  8551. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
  8552. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8553. AHC_AIC7892_FE, 28,
  8554. 32, C46 },
  8555. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
  8556. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8557. AHC_AIC7892_FE, 28,
  8558. 32, C46 },
  8559. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
  8560. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8561. AHC_AIC7899_FE, 29,
  8562. 32, C56_66 },
  8563. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
  8564. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8565. AHC_AIC7899_FE, 29,
  8566. 32, C56_66 },
  8567. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
  8568. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8569. AHC_AIC7899_FE, 29,
  8570. 32, C56_66 },
  8571. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
  8572. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8573. AHC_AIC7899_FE, 29,
  8574. 32, C56_66 },
  8575. };
  8576. unsigned short command;
  8577. unsigned int devconfig, i, oldverbose;
  8578. struct pci_dev *pdev = NULL;
  8579. for (i = 0; i < ARRAY_SIZE(aic_pdevs); i++)
  8580. {
  8581. pdev = NULL;
  8582. while ((pdev = pci_find_device(aic_pdevs[i].vendor_id,
  8583. aic_pdevs[i].device_id,
  8584. pdev))) {
  8585. if (pci_enable_device(pdev))
  8586. continue;
  8587. if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
  8588. {
  8589. if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
  8590. {
  8591. printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
  8592. "supported by\n");
  8593. printk(KERN_INFO " this driver, we are ignoring it.\n");
  8594. }
  8595. }
  8596. else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
  8597. GFP_ATOMIC)) != NULL )
  8598. {
  8599. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  8600. temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
  8601. temp_p->flags = aic_pdevs[i].flags;
  8602. temp_p->features = aic_pdevs[i].features;
  8603. temp_p->board_name_index = aic_pdevs[i].board_name_index;
  8604. temp_p->sc_size = aic_pdevs[i].seeprom_size;
  8605. temp_p->sc_type = aic_pdevs[i].seeprom_type;
  8606. /*
  8607. * Read sundry information from PCI BIOS.
  8608. */
  8609. temp_p->irq = pdev->irq;
  8610. temp_p->pdev = pdev;
  8611. temp_p->pci_bus = pdev->bus->number;
  8612. temp_p->pci_device_fn = pdev->devfn;
  8613. temp_p->base = pci_resource_start(pdev, 0);
  8614. temp_p->mbase = pci_resource_start(pdev, 1);
  8615. current_p = list_p;
  8616. while(current_p && temp_p)
  8617. {
  8618. if ( ((current_p->pci_bus == temp_p->pci_bus) &&
  8619. (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
  8620. (temp_p->base && (current_p->base == temp_p->base)) ||
  8621. (temp_p->mbase && (current_p->mbase == temp_p->mbase)) )
  8622. {
  8623. /* duplicate PCI entry, skip it */
  8624. kfree(temp_p);
  8625. temp_p = NULL;
  8626. continue;
  8627. }
  8628. current_p = current_p->next;
  8629. }
  8630. if(pci_request_regions(temp_p->pdev, "aic7xxx"))
  8631. {
  8632. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8633. board_names[aic_pdevs[i].board_name_index],
  8634. temp_p->pci_bus,
  8635. PCI_SLOT(temp_p->pci_device_fn),
  8636. PCI_FUNC(temp_p->pci_device_fn));
  8637. printk("aic7xxx: I/O ports already in use, ignoring.\n");
  8638. kfree(temp_p);
  8639. continue;
  8640. }
  8641. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8642. printk("aic7xxx: <%s> at PCI %d/%d\n",
  8643. board_names[aic_pdevs[i].board_name_index],
  8644. PCI_SLOT(pdev->devfn),
  8645. PCI_FUNC(pdev->devfn));
  8646. pci_read_config_word(pdev, PCI_COMMAND, &command);
  8647. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8648. {
  8649. printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
  8650. (int)command);
  8651. }
  8652. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8653. command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  8654. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8655. #else
  8656. command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8657. #endif
  8658. command &= ~PCI_COMMAND_INVALIDATE;
  8659. if (aic7xxx_pci_parity == 0)
  8660. command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  8661. pci_write_config_word(pdev, PCI_COMMAND, command);
  8662. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8663. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8664. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8665. {
  8666. printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
  8667. }
  8668. devconfig |= 0x80000040;
  8669. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8670. #endif /* AIC7XXX_STRICT_PCI_SETUP */
  8671. temp_p->unpause = INTEN;
  8672. temp_p->pause = temp_p->unpause | PAUSE;
  8673. if ( ((temp_p->base == 0) &&
  8674. (temp_p->mbase == 0)) ||
  8675. (temp_p->irq == 0) )
  8676. {
  8677. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8678. board_names[aic_pdevs[i].board_name_index],
  8679. temp_p->pci_bus,
  8680. PCI_SLOT(temp_p->pci_device_fn),
  8681. PCI_FUNC(temp_p->pci_device_fn));
  8682. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8683. goto skip_pci_controller;
  8684. }
  8685. #ifdef MMAPIO
  8686. if ( !(temp_p->base) || !(temp_p->flags & AHC_MULTI_CHANNEL) ||
  8687. ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
  8688. (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
  8689. {
  8690. temp_p->maddr = ioremap_nocache(temp_p->mbase, 256);
  8691. if(temp_p->maddr)
  8692. {
  8693. /*
  8694. * We need to check the I/O with the MMAPed address. Some machines
  8695. * simply fail to work with MMAPed I/O and certain controllers.
  8696. */
  8697. if(aic_inb(temp_p, HCNTRL) == 0xff)
  8698. {
  8699. /*
  8700. * OK.....we failed our test....go back to programmed I/O
  8701. */
  8702. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8703. board_names[aic_pdevs[i].board_name_index],
  8704. temp_p->pci_bus,
  8705. PCI_SLOT(temp_p->pci_device_fn),
  8706. PCI_FUNC(temp_p->pci_device_fn));
  8707. printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
  8708. "Programmed I/O.\n");
  8709. iounmap(temp_p->maddr);
  8710. temp_p->maddr = NULL;
  8711. if(temp_p->base == 0)
  8712. {
  8713. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8714. board_names[aic_pdevs[i].board_name_index],
  8715. temp_p->pci_bus,
  8716. PCI_SLOT(temp_p->pci_device_fn),
  8717. PCI_FUNC(temp_p->pci_device_fn));
  8718. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8719. goto skip_pci_controller;
  8720. }
  8721. }
  8722. }
  8723. }
  8724. #endif
  8725. /*
  8726. * We HAVE to make sure the first pause_sequencer() and all other
  8727. * subsequent I/O that isn't PCI config space I/O takes place
  8728. * after the MMAPed I/O region is configured and tested. The
  8729. * problem is the PowerPC architecture that doesn't support
  8730. * programmed I/O at all, so we have to have the MMAP I/O set up
  8731. * for this pause to even work on those machines.
  8732. */
  8733. pause_sequencer(temp_p);
  8734. /*
  8735. * Clear out any pending PCI error status messages. Also set
  8736. * verbose to 0 so that we don't emit strange PCI error messages
  8737. * while cleaning out the current status bits.
  8738. */
  8739. oldverbose = aic7xxx_verbose;
  8740. aic7xxx_verbose = 0;
  8741. aic7xxx_pci_intr(temp_p);
  8742. aic7xxx_verbose = oldverbose;
  8743. temp_p->bios_address = 0;
  8744. /*
  8745. * Remember how the card was setup in case there is no seeprom.
  8746. */
  8747. if (temp_p->features & AHC_ULTRA2)
  8748. temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
  8749. else
  8750. temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
  8751. /*
  8752. * Get current termination setting
  8753. */
  8754. sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
  8755. if (aic7xxx_chip_reset(temp_p) == -1)
  8756. {
  8757. goto skip_pci_controller;
  8758. }
  8759. /*
  8760. * Very quickly put the term setting back into the register since
  8761. * the chip reset may cause odd things to happen. This is to keep
  8762. * LVD busses with lots of drives from draining the power out of
  8763. * the diffsense line before we get around to running the
  8764. * configure_termination() function. Also restore the STPWLEVEL
  8765. * bit of DEVCONFIG
  8766. */
  8767. aic_outb(temp_p, sxfrctl1, SXFRCTL1);
  8768. pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
  8769. sxfrctl1 &= STPWEN;
  8770. /*
  8771. * We need to set the CHNL? assignments before loading the SEEPROM
  8772. * The 3940 and 3985 cards (original stuff, not any of the later
  8773. * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
  8774. * under 7896 and 7897. The 7895 is in a class by itself :)
  8775. */
  8776. switch (temp_p->chip & AHC_CHIPID_MASK)
  8777. {
  8778. case AHC_AIC7870: /* 3840 / 3985 */
  8779. case AHC_AIC7880: /* 3840 UW / 3985 UW */
  8780. if(temp_p->flags & AHC_MULTI_CHANNEL)
  8781. {
  8782. switch(PCI_SLOT(temp_p->pci_device_fn))
  8783. {
  8784. case 5:
  8785. temp_p->flags |= AHC_CHNLB;
  8786. break;
  8787. case 8:
  8788. temp_p->flags |= AHC_CHNLB;
  8789. break;
  8790. case 12:
  8791. temp_p->flags |= AHC_CHNLC;
  8792. break;
  8793. default:
  8794. break;
  8795. }
  8796. }
  8797. break;
  8798. case AHC_AIC7895: /* 7895 */
  8799. case AHC_AIC7896: /* 7896/7 */
  8800. case AHC_AIC7899: /* 7899 */
  8801. if (PCI_FUNC(pdev->devfn) != 0)
  8802. {
  8803. temp_p->flags |= AHC_CHNLB;
  8804. }
  8805. /*
  8806. * The 7895 is the only chipset that sets the SCBSIZE32 param
  8807. * in the DEVCONFIG register. The Ultra2 chipsets use
  8808. * the DSCOMMAND0 register instead.
  8809. */
  8810. if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
  8811. {
  8812. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8813. devconfig |= SCBSIZE32;
  8814. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8815. }
  8816. break;
  8817. default:
  8818. break;
  8819. }
  8820. /*
  8821. * Loading of the SEEPROM needs to come after we've set the flags
  8822. * to indicate possible CHNLB and CHNLC assigments. Otherwise,
  8823. * on 394x and 398x cards we'll end up reading the wrong settings
  8824. * for channels B and C
  8825. */
  8826. switch (temp_p->chip & AHC_CHIPID_MASK)
  8827. {
  8828. case AHC_AIC7892:
  8829. case AHC_AIC7899:
  8830. aic_outb(temp_p, 0, SCAMCTL);
  8831. /*
  8832. * Switch to the alt mode of the chip...
  8833. */
  8834. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
  8835. /*
  8836. * Set our options...the last two items set our CRC after x byte
  8837. * count in target mode...
  8838. */
  8839. aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
  8840. aic_outb(temp_p, 0x00, 0x0b);
  8841. aic_outb(temp_p, 0x10, 0x0a);
  8842. /*
  8843. * switch back to normal mode...
  8844. */
  8845. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
  8846. aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
  8847. TARGCRCENDEN | TARGCRCCNTEN,
  8848. CRCCONTROL1);
  8849. aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
  8850. MPARCKEN | CIOPARCKEN | CACHETHEN) &
  8851. ~DPARCKEN), DSCOMMAND0);
  8852. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8853. break;
  8854. case AHC_AIC7890:
  8855. case AHC_AIC7896:
  8856. aic_outb(temp_p, 0, SCAMCTL);
  8857. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8858. CACHETHEN | MPARCKEN | USCBSIZE32 |
  8859. CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
  8860. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8861. break;
  8862. case AHC_AIC7850:
  8863. case AHC_AIC7860:
  8864. /*
  8865. * Set the DSCOMMAND0 register on these cards different from
  8866. * on the 789x cards. Also, read the SEEPROM as well.
  8867. */
  8868. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8869. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8870. DSCOMMAND0);
  8871. /* FALLTHROUGH */
  8872. default:
  8873. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8874. break;
  8875. case AHC_AIC7880:
  8876. /*
  8877. * Check the rev of the chipset before we change DSCOMMAND0
  8878. */
  8879. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8880. if ((devconfig & 0xff) >= 1)
  8881. {
  8882. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8883. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8884. DSCOMMAND0);
  8885. }
  8886. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8887. break;
  8888. }
  8889. /*
  8890. * and then we need another switch based on the type in order to
  8891. * make sure the channel B primary flag is set properly on 7895
  8892. * controllers....Arrrgggghhh!!! We also have to catch the fact
  8893. * that when you disable the BIOS on the 7895 on the Intel DK440LX
  8894. * motherboard, and possibly others, it only sets the BIOS disabled
  8895. * bit on the A channel...I think I'm starting to lean towards
  8896. * going postal....
  8897. */
  8898. switch(temp_p->chip & AHC_CHIPID_MASK)
  8899. {
  8900. case AHC_AIC7895:
  8901. case AHC_AIC7896:
  8902. case AHC_AIC7899:
  8903. current_p = list_p;
  8904. while(current_p != NULL)
  8905. {
  8906. if ( (current_p->pci_bus == temp_p->pci_bus) &&
  8907. (PCI_SLOT(current_p->pci_device_fn) ==
  8908. PCI_SLOT(temp_p->pci_device_fn)) )
  8909. {
  8910. if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
  8911. {
  8912. temp_p->flags |=
  8913. (current_p->flags & AHC_CHANNEL_B_PRIMARY);
  8914. temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8915. temp_p->flags |=
  8916. (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8917. }
  8918. else
  8919. {
  8920. current_p->flags |=
  8921. (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
  8922. current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8923. current_p->flags |=
  8924. (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8925. }
  8926. }
  8927. current_p = current_p->next;
  8928. }
  8929. break;
  8930. default:
  8931. break;
  8932. }
  8933. /*
  8934. * We only support external SCB RAM on the 7895/6/7 chipsets.
  8935. * We could support it on the 7890/1 easy enough, but I don't
  8936. * know of any 7890/1 based cards that have it. I do know
  8937. * of 7895/6/7 cards that have it and they work properly.
  8938. */
  8939. switch(temp_p->chip & AHC_CHIPID_MASK)
  8940. {
  8941. default:
  8942. break;
  8943. case AHC_AIC7895:
  8944. case AHC_AIC7896:
  8945. case AHC_AIC7899:
  8946. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8947. if (temp_p->features & AHC_ULTRA2)
  8948. {
  8949. if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
  8950. (aic7xxx_scbram) )
  8951. {
  8952. aic_outb(temp_p,
  8953. aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
  8954. DSCOMMAND0);
  8955. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8956. devconfig |= EXTSCBPEN;
  8957. }
  8958. else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
  8959. {
  8960. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8961. board_names[aic_pdevs[i].board_name_index],
  8962. temp_p->pci_bus,
  8963. PCI_SLOT(temp_p->pci_device_fn),
  8964. PCI_FUNC(temp_p->pci_device_fn));
  8965. printk("aic7xxx: external SCB RAM detected, "
  8966. "but not enabled\n");
  8967. }
  8968. }
  8969. else
  8970. {
  8971. if ((devconfig & RAMPSM) && (aic7xxx_scbram))
  8972. {
  8973. devconfig &= ~SCBRAMSEL;
  8974. devconfig |= EXTSCBPEN;
  8975. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8976. }
  8977. else if (devconfig & RAMPSM)
  8978. {
  8979. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8980. board_names[aic_pdevs[i].board_name_index],
  8981. temp_p->pci_bus,
  8982. PCI_SLOT(temp_p->pci_device_fn),
  8983. PCI_FUNC(temp_p->pci_device_fn));
  8984. printk("aic7xxx: external SCB RAM detected, "
  8985. "but not enabled\n");
  8986. }
  8987. }
  8988. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8989. if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
  8990. (temp_p->flags & AHC_CHNLB) )
  8991. aic_outb(temp_p, 1, CCSCBBADDR);
  8992. break;
  8993. }
  8994. /*
  8995. * Take the LED out of diagnostic mode
  8996. */
  8997. aic_outb(temp_p,
  8998. (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
  8999. SBLKCTL);
  9000. /*
  9001. * We don't know where this is set in the SEEPROM or by the
  9002. * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
  9003. * instead.
  9004. */
  9005. if (temp_p->features & AHC_ULTRA2)
  9006. {
  9007. aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
  9008. }
  9009. else
  9010. {
  9011. aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
  9012. }
  9013. /*
  9014. * Call our function to fixup any bugs that exist on this chipset.
  9015. * This may muck with PCI settings and other device settings, so
  9016. * make sure it's after all the other PCI and device register
  9017. * tweaks so it can back out bad settings on specific broken cards.
  9018. */
  9019. aic7xxx_configure_bugs(temp_p);
  9020. if ( list_p == NULL )
  9021. {
  9022. list_p = current_p = temp_p;
  9023. }
  9024. else
  9025. {
  9026. current_p = list_p;
  9027. while(current_p->next != NULL)
  9028. current_p = current_p->next;
  9029. current_p->next = temp_p;
  9030. }
  9031. temp_p->next = NULL;
  9032. found++;
  9033. continue;
  9034. skip_pci_controller:
  9035. #ifdef CONFIG_PCI
  9036. pci_release_regions(temp_p->pdev);
  9037. #endif
  9038. kfree(temp_p);
  9039. } /* Found an Adaptec PCI device. */
  9040. else /* Well, we found one, but we couldn't get any memory */
  9041. {
  9042. printk("aic7xxx: Found <%s>\n",
  9043. board_names[aic_pdevs[i].board_name_index]);
  9044. printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
  9045. "skipping.\n");
  9046. }
  9047. } /* while(pdev=....) */
  9048. } /* for PCI_DEVICES */
  9049. }
  9050. #endif /* CONFIG_PCI */
  9051. #if defined(__i386__) || defined(__alpha__)
  9052. /*
  9053. * EISA/VL-bus card signature probe.
  9054. */
  9055. slot = MINSLOT;
  9056. while ( (slot <= MAXSLOT) &&
  9057. !(aic7xxx_no_probe) )
  9058. {
  9059. base = SLOTBASE(slot) + MINREG;
  9060. if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
  9061. {
  9062. /*
  9063. * Some other driver has staked a
  9064. * claim to this i/o region already.
  9065. */
  9066. slot++;
  9067. continue; /* back to the beginning of the for loop */
  9068. }
  9069. flags = 0;
  9070. type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
  9071. if (type == -1)
  9072. {
  9073. release_region(base, MAXREG - MINREG);
  9074. slot++;
  9075. continue;
  9076. }
  9077. temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
  9078. if (temp_p == NULL)
  9079. {
  9080. printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
  9081. release_region(base, MAXREG - MINREG);
  9082. slot++;
  9083. continue; /* back to the beginning of the while loop */
  9084. }
  9085. /*
  9086. * Pause the card preserving the IRQ type. Allow the operator
  9087. * to override the IRQ trigger.
  9088. */
  9089. if (aic7xxx_irq_trigger == 1)
  9090. hcntrl = IRQMS; /* Level */
  9091. else if (aic7xxx_irq_trigger == 0)
  9092. hcntrl = 0; /* Edge */
  9093. else
  9094. hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
  9095. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  9096. temp_p->unpause = hcntrl | INTEN;
  9097. temp_p->pause = hcntrl | PAUSE | INTEN;
  9098. temp_p->base = base;
  9099. temp_p->mbase = 0;
  9100. temp_p->maddr = NULL;
  9101. temp_p->pci_bus = 0;
  9102. temp_p->pci_device_fn = slot;
  9103. aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
  9104. while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
  9105. if (aic7xxx_chip_reset(temp_p) == -1)
  9106. temp_p->irq = 0;
  9107. else
  9108. temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
  9109. temp_p->flags |= AHC_PAGESCBS;
  9110. switch (temp_p->irq)
  9111. {
  9112. case 9:
  9113. case 10:
  9114. case 11:
  9115. case 12:
  9116. case 14:
  9117. case 15:
  9118. break;
  9119. default:
  9120. printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
  9121. "level %d, ignoring.\n", temp_p->irq);
  9122. kfree(temp_p);
  9123. release_region(base, MAXREG - MINREG);
  9124. slot++;
  9125. continue; /* back to the beginning of the while loop */
  9126. }
  9127. /*
  9128. * We are commited now, everything has been checked and this card
  9129. * has been found, now we just set it up
  9130. */
  9131. /*
  9132. * Insert our new struct into the list at the end
  9133. */
  9134. if (list_p == NULL)
  9135. {
  9136. list_p = current_p = temp_p;
  9137. }
  9138. else
  9139. {
  9140. current_p = list_p;
  9141. while (current_p->next != NULL)
  9142. current_p = current_p->next;
  9143. current_p->next = temp_p;
  9144. }
  9145. switch (type)
  9146. {
  9147. case 0:
  9148. temp_p->board_name_index = 2;
  9149. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9150. printk("aic7xxx: <%s> at EISA %d\n",
  9151. board_names[2], slot);
  9152. /* FALLTHROUGH */
  9153. case 1:
  9154. {
  9155. temp_p->chip = AHC_AIC7770 | AHC_EISA;
  9156. temp_p->features |= AHC_AIC7770_FE;
  9157. temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
  9158. /*
  9159. * Get the primary channel information. Right now we don't
  9160. * do anything with this, but someday we will be able to inform
  9161. * the mid-level SCSI code which channel is primary.
  9162. */
  9163. if (temp_p->board_name_index == 0)
  9164. {
  9165. temp_p->board_name_index = 3;
  9166. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9167. printk("aic7xxx: <%s> at EISA %d\n",
  9168. board_names[3], slot);
  9169. }
  9170. if (temp_p->bios_control & CHANNEL_B_PRIMARY)
  9171. {
  9172. temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
  9173. }
  9174. if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
  9175. {
  9176. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9177. }
  9178. else
  9179. {
  9180. temp_p->flags &= ~AHC_USEDEFAULTS;
  9181. temp_p->flags |= AHC_BIOS_ENABLED;
  9182. if ( (temp_p->bios_control & 0x20) == 0 )
  9183. {
  9184. temp_p->bios_address = 0xcc000;
  9185. temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
  9186. }
  9187. else
  9188. {
  9189. temp_p->bios_address = 0xd0000;
  9190. temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
  9191. }
  9192. }
  9193. temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
  9194. temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
  9195. if (temp_p->features & AHC_WIDE)
  9196. {
  9197. temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
  9198. temp_p->scsi_id_b = temp_p->scsi_id;
  9199. }
  9200. else
  9201. {
  9202. temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
  9203. temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
  9204. }
  9205. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9206. break;
  9207. }
  9208. case 2:
  9209. case 3:
  9210. temp_p->chip = AHC_AIC7770 | AHC_VL;
  9211. temp_p->features |= AHC_AIC7770_FE;
  9212. if (type == 2)
  9213. temp_p->flags |= AHC_BIOS_ENABLED;
  9214. else
  9215. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9216. if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
  9217. sxfrctl1 = STPWEN;
  9218. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9219. temp_p->board_name_index = 4;
  9220. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9221. printk("aic7xxx: <%s> at VLB %d\n",
  9222. board_names[2], slot);
  9223. switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
  9224. {
  9225. case 0x00:
  9226. temp_p->bios_address = 0xe0000;
  9227. break;
  9228. case 0x20:
  9229. temp_p->bios_address = 0xc8000;
  9230. break;
  9231. case 0x40:
  9232. temp_p->bios_address = 0xd0000;
  9233. break;
  9234. case 0x60:
  9235. temp_p->bios_address = 0xd8000;
  9236. break;
  9237. default:
  9238. break; /* can't get here */
  9239. }
  9240. break;
  9241. default: /* Won't get here. */
  9242. break;
  9243. }
  9244. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9245. {
  9246. printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
  9247. (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
  9248. temp_p->irq,
  9249. (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
  9250. printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
  9251. (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
  9252. }
  9253. /*
  9254. * All the 7770 based chipsets have this bug
  9255. */
  9256. temp_p->bugs |= AHC_BUG_TMODE_WIDEODD;
  9257. /*
  9258. * Set the FIFO threshold and the bus off time.
  9259. */
  9260. hostconf = aic_inb(temp_p, HOSTCONF);
  9261. aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
  9262. aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
  9263. slot++;
  9264. found++;
  9265. }
  9266. #endif /* defined(__i386__) || defined(__alpha__) */
  9267. /*
  9268. * Now, we re-order the probed devices by BIOS address and BUS class.
  9269. * In general, we follow this algorithm to make the adapters show up
  9270. * in the same order under linux that the computer finds them.
  9271. * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
  9272. * address, going from lowest to highest.
  9273. * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
  9274. * address, going from lowest to highest.
  9275. * 3: Remaining VLB/EISA controllers going in slot order.
  9276. * 4: Remaining PCI controllers, going in PCI device order (reversable)
  9277. */
  9278. {
  9279. struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
  9280. struct aic7xxx_host *vlb, *pci;
  9281. struct aic7xxx_host *prev_p;
  9282. struct aic7xxx_host *p;
  9283. unsigned char left;
  9284. prev_p = vlb = pci = NULL;
  9285. temp_p = list_p;
  9286. while (temp_p != NULL)
  9287. {
  9288. switch(temp_p->chip & ~AHC_CHIPID_MASK)
  9289. {
  9290. case AHC_EISA:
  9291. case AHC_VL:
  9292. {
  9293. p = temp_p;
  9294. if (p->flags & AHC_BIOS_ENABLED)
  9295. vlb = sort_list[0];
  9296. else
  9297. vlb = sort_list[2];
  9298. if (vlb == NULL)
  9299. {
  9300. vlb = temp_p;
  9301. temp_p = temp_p->next;
  9302. vlb->next = NULL;
  9303. }
  9304. else
  9305. {
  9306. current_p = vlb;
  9307. prev_p = NULL;
  9308. while ( (current_p != NULL) &&
  9309. (current_p->bios_address < temp_p->bios_address))
  9310. {
  9311. prev_p = current_p;
  9312. current_p = current_p->next;
  9313. }
  9314. if (prev_p != NULL)
  9315. {
  9316. prev_p->next = temp_p;
  9317. temp_p = temp_p->next;
  9318. prev_p->next->next = current_p;
  9319. }
  9320. else
  9321. {
  9322. vlb = temp_p;
  9323. temp_p = temp_p->next;
  9324. vlb->next = current_p;
  9325. }
  9326. }
  9327. if (p->flags & AHC_BIOS_ENABLED)
  9328. sort_list[0] = vlb;
  9329. else
  9330. sort_list[2] = vlb;
  9331. break;
  9332. }
  9333. default: /* All PCI controllers fall through to default */
  9334. {
  9335. p = temp_p;
  9336. if (p->flags & AHC_BIOS_ENABLED)
  9337. pci = sort_list[1];
  9338. else
  9339. pci = sort_list[3];
  9340. if (pci == NULL)
  9341. {
  9342. pci = temp_p;
  9343. temp_p = temp_p->next;
  9344. pci->next = NULL;
  9345. }
  9346. else
  9347. {
  9348. current_p = pci;
  9349. prev_p = NULL;
  9350. if (!aic7xxx_reverse_scan)
  9351. {
  9352. while ( (current_p != NULL) &&
  9353. ( (PCI_SLOT(current_p->pci_device_fn) |
  9354. (current_p->pci_bus << 8)) <
  9355. (PCI_SLOT(temp_p->pci_device_fn) |
  9356. (temp_p->pci_bus << 8)) ) )
  9357. {
  9358. prev_p = current_p;
  9359. current_p = current_p->next;
  9360. }
  9361. }
  9362. else
  9363. {
  9364. while ( (current_p != NULL) &&
  9365. ( (PCI_SLOT(current_p->pci_device_fn) |
  9366. (current_p->pci_bus << 8)) >
  9367. (PCI_SLOT(temp_p->pci_device_fn) |
  9368. (temp_p->pci_bus << 8)) ) )
  9369. {
  9370. prev_p = current_p;
  9371. current_p = current_p->next;
  9372. }
  9373. }
  9374. /*
  9375. * Are we dealing with a 7895/6/7/9 where we need to sort the
  9376. * channels as well, if so, the bios_address values should
  9377. * be the same
  9378. */
  9379. if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
  9380. (temp_p->pci_bus == current_p->pci_bus) &&
  9381. (PCI_SLOT(temp_p->pci_device_fn) ==
  9382. PCI_SLOT(current_p->pci_device_fn)) )
  9383. {
  9384. if (temp_p->flags & AHC_CHNLB)
  9385. {
  9386. if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
  9387. {
  9388. prev_p = current_p;
  9389. current_p = current_p->next;
  9390. }
  9391. }
  9392. else
  9393. {
  9394. if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
  9395. {
  9396. prev_p = current_p;
  9397. current_p = current_p->next;
  9398. }
  9399. }
  9400. }
  9401. if (prev_p != NULL)
  9402. {
  9403. prev_p->next = temp_p;
  9404. temp_p = temp_p->next;
  9405. prev_p->next->next = current_p;
  9406. }
  9407. else
  9408. {
  9409. pci = temp_p;
  9410. temp_p = temp_p->next;
  9411. pci->next = current_p;
  9412. }
  9413. }
  9414. if (p->flags & AHC_BIOS_ENABLED)
  9415. sort_list[1] = pci;
  9416. else
  9417. sort_list[3] = pci;
  9418. break;
  9419. }
  9420. } /* End of switch(temp_p->type) */
  9421. } /* End of while (temp_p != NULL) */
  9422. /*
  9423. * At this point, the cards have been broken into 4 sorted lists, now
  9424. * we run through the lists in order and register each controller
  9425. */
  9426. {
  9427. int i;
  9428. left = found;
  9429. for (i=0; i<ARRAY_SIZE(sort_list); i++)
  9430. {
  9431. temp_p = sort_list[i];
  9432. while(temp_p != NULL)
  9433. {
  9434. template->name = board_names[temp_p->board_name_index];
  9435. p = aic7xxx_alloc(template, temp_p);
  9436. if (p != NULL)
  9437. {
  9438. p->instance = found - left;
  9439. if (aic7xxx_register(template, p, (--left)) == 0)
  9440. {
  9441. found--;
  9442. aic7xxx_release(p->host);
  9443. scsi_unregister(p->host);
  9444. }
  9445. else if (aic7xxx_dump_card)
  9446. {
  9447. pause_sequencer(p);
  9448. aic7xxx_print_card(p);
  9449. aic7xxx_print_scratch_ram(p);
  9450. unpause_sequencer(p, TRUE);
  9451. }
  9452. }
  9453. current_p = temp_p;
  9454. temp_p = (struct aic7xxx_host *)temp_p->next;
  9455. kfree(current_p);
  9456. }
  9457. }
  9458. }
  9459. }
  9460. return (found);
  9461. }
  9462. /*+F*************************************************************************
  9463. * Function:
  9464. * aic7xxx_buildscb
  9465. *
  9466. * Description:
  9467. * Build a SCB.
  9468. *-F*************************************************************************/
  9469. static void
  9470. aic7xxx_buildscb(struct aic7xxx_host *p, Scsi_Cmnd *cmd,
  9471. struct aic7xxx_scb *scb)
  9472. {
  9473. unsigned short mask;
  9474. struct aic7xxx_hwscb *hscb;
  9475. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  9476. struct scsi_device *sdptr = cmd->device;
  9477. unsigned char tindex = TARGET_INDEX(cmd);
  9478. struct request *req = cmd->request;
  9479. mask = (0x01 << tindex);
  9480. hscb = scb->hscb;
  9481. /*
  9482. * Setup the control byte if we need negotiation and have not
  9483. * already requested it.
  9484. */
  9485. hscb->control = 0;
  9486. scb->tag_action = 0;
  9487. if (p->discenable & mask)
  9488. {
  9489. hscb->control |= DISCENB;
  9490. /* We always force TEST_UNIT_READY to untagged */
  9491. if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
  9492. {
  9493. if (req->flags & REQ_HARDBARRIER)
  9494. {
  9495. if(sdptr->ordered_tags)
  9496. {
  9497. hscb->control |= MSG_ORDERED_Q_TAG;
  9498. scb->tag_action = MSG_ORDERED_Q_TAG;
  9499. }
  9500. }
  9501. else
  9502. {
  9503. hscb->control |= MSG_SIMPLE_Q_TAG;
  9504. scb->tag_action = MSG_SIMPLE_Q_TAG;
  9505. }
  9506. }
  9507. }
  9508. if ( !(aic_dev->dtr_pending) &&
  9509. (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&
  9510. (aic_dev->flags & DEVICE_DTR_SCANNED) )
  9511. {
  9512. aic_dev->dtr_pending = 1;
  9513. scb->tag_action = 0;
  9514. hscb->control &= DISCENB;
  9515. hscb->control |= MK_MESSAGE;
  9516. if(aic_dev->needppr)
  9517. {
  9518. scb->flags |= SCB_MSGOUT_PPR;
  9519. }
  9520. else if(aic_dev->needwdtr)
  9521. {
  9522. scb->flags |= SCB_MSGOUT_WDTR;
  9523. }
  9524. else if(aic_dev->needsdtr)
  9525. {
  9526. scb->flags |= SCB_MSGOUT_SDTR;
  9527. }
  9528. scb->flags |= SCB_DTR_SCB;
  9529. }
  9530. hscb->target_channel_lun = ((cmd->device->id << 4) & 0xF0) |
  9531. ((cmd->device->channel & 0x01) << 3) | (cmd->device->lun & 0x07);
  9532. /*
  9533. * The interpretation of request_buffer and request_bufflen
  9534. * changes depending on whether or not use_sg is zero; a
  9535. * non-zero use_sg indicates the number of elements in the
  9536. * scatter-gather array.
  9537. */
  9538. /*
  9539. * XXX - this relies on the host data being stored in a
  9540. * little-endian format.
  9541. */
  9542. hscb->SCSI_cmd_length = cmd->cmd_len;
  9543. memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
  9544. hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
  9545. if (cmd->use_sg)
  9546. {
  9547. struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
  9548. /*
  9549. * We must build an SG list in adapter format, as the kernel's SG list
  9550. * cannot be used directly because of data field size (__alpha__)
  9551. * differences and the kernel SG list uses virtual addresses where
  9552. * we need physical addresses.
  9553. */
  9554. int i, use_sg;
  9555. sg = (struct scatterlist *)cmd->request_buffer;
  9556. scb->sg_length = 0;
  9557. use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, cmd->sc_data_direction);
  9558. /*
  9559. * Copy the segments into the SG array. NOTE!!! - We used to
  9560. * have the first entry both in the data_pointer area and the first
  9561. * SG element. That has changed somewhat. We still have the first
  9562. * entry in both places, but now we download the address of
  9563. * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
  9564. */
  9565. for (i = 0; i < use_sg; i++)
  9566. {
  9567. unsigned int len = sg_dma_len(sg+i);
  9568. scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));
  9569. scb->sg_list[i].length = cpu_to_le32(len);
  9570. scb->sg_length += len;
  9571. }
  9572. /* Copy the first SG into the data pointer area. */
  9573. hscb->data_pointer = scb->sg_list[0].address;
  9574. hscb->data_count = scb->sg_list[0].length;
  9575. scb->sg_count = i;
  9576. hscb->SG_segment_count = i;
  9577. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
  9578. }
  9579. else
  9580. {
  9581. if (cmd->request_bufflen)
  9582. {
  9583. unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,
  9584. cmd->request_bufflen,
  9585. cmd->sc_data_direction);
  9586. aic7xxx_mapping(cmd) = address;
  9587. scb->sg_list[0].address = cpu_to_le32(address);
  9588. scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
  9589. scb->sg_count = 1;
  9590. scb->sg_length = cmd->request_bufflen;
  9591. hscb->SG_segment_count = 1;
  9592. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));
  9593. hscb->data_count = scb->sg_list[0].length;
  9594. hscb->data_pointer = scb->sg_list[0].address;
  9595. }
  9596. else
  9597. {
  9598. scb->sg_count = 0;
  9599. scb->sg_length = 0;
  9600. hscb->SG_segment_count = 0;
  9601. hscb->SG_list_pointer = 0;
  9602. hscb->data_count = 0;
  9603. hscb->data_pointer = 0;
  9604. }
  9605. }
  9606. }
  9607. /*+F*************************************************************************
  9608. * Function:
  9609. * aic7xxx_queue
  9610. *
  9611. * Description:
  9612. * Queue a SCB to the controller.
  9613. *-F*************************************************************************/
  9614. static int
  9615. aic7xxx_queue(Scsi_Cmnd *cmd, void (*fn)(Scsi_Cmnd *))
  9616. {
  9617. struct aic7xxx_host *p;
  9618. struct aic7xxx_scb *scb;
  9619. struct aic_dev_data *aic_dev;
  9620. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  9621. aic_dev = cmd->device->hostdata;
  9622. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  9623. if (aic_dev->active_cmds > aic_dev->max_q_depth)
  9624. {
  9625. printk(WARN_LEAD "Commands queued exceeds queue "
  9626. "depth, active=%d\n",
  9627. p->host_no, CTL_OF_CMD(cmd),
  9628. aic_dev->active_cmds);
  9629. }
  9630. #endif
  9631. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9632. if (scb == NULL)
  9633. {
  9634. aic7xxx_allocate_scb(p);
  9635. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9636. if(scb == NULL)
  9637. {
  9638. printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
  9639. CTL_OF_CMD(cmd));
  9640. return 1;
  9641. }
  9642. }
  9643. scb->cmd = cmd;
  9644. /*
  9645. * Make sure the Scsi_Cmnd pointer is saved, the struct it points to
  9646. * is set up properly, and the parity error flag is reset, then send
  9647. * the SCB to the sequencer and watch the fun begin.
  9648. */
  9649. aic7xxx_position(cmd) = scb->hscb->tag;
  9650. cmd->scsi_done = fn;
  9651. cmd->result = DID_OK;
  9652. memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
  9653. aic7xxx_error(cmd) = DID_OK;
  9654. aic7xxx_status(cmd) = 0;
  9655. cmd->host_scribble = NULL;
  9656. /*
  9657. * Construct the SCB beforehand, so the sequencer is
  9658. * paused a minimal amount of time.
  9659. */
  9660. aic7xxx_buildscb(p, cmd, scb);
  9661. scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
  9662. scbq_insert_tail(&p->waiting_scbs, scb);
  9663. aic7xxx_run_waiting_queues(p);
  9664. return (0);
  9665. }
  9666. /*+F*************************************************************************
  9667. * Function:
  9668. * aic7xxx_bus_device_reset
  9669. *
  9670. * Description:
  9671. * Abort or reset the current SCSI command(s). If the scb has not
  9672. * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
  9673. * message to the target. If the scb has previously been unsuccessfully
  9674. * aborted, then we will reset the channel and have all devices renegotiate.
  9675. * Returns an enumerated type that indicates the status of the operation.
  9676. *-F*************************************************************************/
  9677. static int
  9678. __aic7xxx_bus_device_reset(Scsi_Cmnd *cmd)
  9679. {
  9680. struct aic7xxx_host *p;
  9681. struct aic7xxx_scb *scb;
  9682. struct aic7xxx_hwscb *hscb;
  9683. int channel;
  9684. unsigned char saved_scbptr, lastphase;
  9685. unsigned char hscb_index;
  9686. int disconnected;
  9687. struct aic_dev_data *aic_dev;
  9688. if(cmd == NULL)
  9689. {
  9690. printk(KERN_ERR "aic7xxx_bus_device_reset: called with NULL cmd!\n");
  9691. return FAILED;
  9692. }
  9693. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9694. aic_dev = AIC_DEV(cmd);
  9695. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9696. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9697. else
  9698. return FAILED;
  9699. hscb = scb->hscb;
  9700. aic7xxx_isr(p->irq, (void *)p, NULL);
  9701. aic7xxx_done_cmds_complete(p);
  9702. /* If the command was already complete or just completed, then we didn't
  9703. * do a reset, return FAILED */
  9704. if(!(scb->flags & SCB_ACTIVE))
  9705. return FAILED;
  9706. pause_sequencer(p);
  9707. lastphase = aic_inb(p, LASTPHASE);
  9708. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9709. {
  9710. printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
  9711. p->host_no, CTL_OF_SCB(scb), scb->flags);
  9712. switch (lastphase)
  9713. {
  9714. case P_DATAOUT:
  9715. printk("Data-Out phase\n");
  9716. break;
  9717. case P_DATAIN:
  9718. printk("Data-In phase\n");
  9719. break;
  9720. case P_COMMAND:
  9721. printk("Command phase\n");
  9722. break;
  9723. case P_MESGOUT:
  9724. printk("Message-Out phase\n");
  9725. break;
  9726. case P_STATUS:
  9727. printk("Status phase\n");
  9728. break;
  9729. case P_MESGIN:
  9730. printk("Message-In phase\n");
  9731. break;
  9732. default:
  9733. /*
  9734. * We're not in a valid phase, so assume we're idle.
  9735. */
  9736. printk("while idle, LASTPHASE = 0x%x\n", lastphase);
  9737. break;
  9738. }
  9739. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  9740. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  9741. aic_inb(p, SCSISIGI),
  9742. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9743. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  9744. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n", p->host_no,
  9745. CTL_OF_SCB(scb),
  9746. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  9747. aic_inb(p, SSTAT2),
  9748. aic_inb(p, STCNT + 2) << 16 | aic_inb(p, STCNT + 1) << 8 |
  9749. aic_inb(p, STCNT));
  9750. }
  9751. channel = cmd->device->channel;
  9752. /*
  9753. * Send a Device Reset Message:
  9754. * The target that is holding up the bus may not be the same as
  9755. * the one that triggered this timeout (different commands have
  9756. * different timeout lengths). Our strategy here is to queue an
  9757. * abort message to the timed out target if it is disconnected.
  9758. * Otherwise, if we have an active target we stuff the message buffer
  9759. * with an abort message and assert ATN in the hopes that the target
  9760. * will let go of the bus and go to the mesgout phase. If this
  9761. * fails, we'll get another timeout a few seconds later which will
  9762. * attempt a bus reset.
  9763. */
  9764. saved_scbptr = aic_inb(p, SCBPTR);
  9765. disconnected = FALSE;
  9766. if (lastphase != P_BUSFREE)
  9767. {
  9768. if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
  9769. {
  9770. printk(WARN_LEAD "Invalid SCB ID %d is active, "
  9771. "SCB flags = 0x%x.\n", p->host_no,
  9772. CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
  9773. unpause_sequencer(p, FALSE);
  9774. return FAILED;
  9775. }
  9776. if (scb->hscb->tag == aic_inb(p, SCB_TAG))
  9777. {
  9778. if ( (lastphase == P_MESGOUT) || (lastphase == P_MESGIN) )
  9779. {
  9780. printk(WARN_LEAD "Device reset, Message buffer "
  9781. "in use\n", p->host_no, CTL_OF_SCB(scb));
  9782. unpause_sequencer(p, FALSE);
  9783. return FAILED;
  9784. }
  9785. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9786. printk(INFO_LEAD "Device reset message in "
  9787. "message buffer\n", p->host_no, CTL_OF_SCB(scb));
  9788. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9789. aic7xxx_error(cmd) = DID_RESET;
  9790. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9791. /* Send the abort message to the active SCB. */
  9792. aic_outb(p, HOST_MSG, MSG_OUT);
  9793. aic_outb(p, lastphase | ATNO, SCSISIGO);
  9794. unpause_sequencer(p, FALSE);
  9795. spin_unlock_irq(p->host->host_lock);
  9796. ssleep(1);
  9797. spin_lock_irq(p->host->host_lock);
  9798. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9799. return FAILED;
  9800. else
  9801. return SUCCESS;
  9802. }
  9803. } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
  9804. /*
  9805. * Simply set the MK_MESSAGE flag and the SEQINT handler will do
  9806. * the rest on a reconnect/connect.
  9807. */
  9808. scb->hscb->control |= MK_MESSAGE;
  9809. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9810. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9811. /*
  9812. * Check to see if the command is on the qinfifo. If it is, then we will
  9813. * not need to queue the command again since the card should start it soon
  9814. */
  9815. if (aic7xxx_search_qinfifo(p, cmd->device->channel, cmd->device->id, cmd->device->lun, hscb->tag,
  9816. 0, TRUE, NULL) == 0)
  9817. {
  9818. disconnected = TRUE;
  9819. if ((hscb_index = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9820. {
  9821. unsigned char scb_control;
  9822. aic_outb(p, hscb_index, SCBPTR);
  9823. scb_control = aic_inb(p, SCB_CONTROL);
  9824. /*
  9825. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9826. * actually on the waiting list, not disconnected, and we don't
  9827. * need to requeue the command.
  9828. */
  9829. disconnected = (scb_control & DISCONNECTED);
  9830. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  9831. }
  9832. if (disconnected)
  9833. {
  9834. /*
  9835. * Actually requeue this SCB in case we can select the
  9836. * device before it reconnects. This can result in the command
  9837. * being on the qinfifo twice, but we don't care because it will
  9838. * all get cleaned up if/when the reset takes place.
  9839. */
  9840. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9841. printk(INFO_LEAD "Queueing device reset command.\n", p->host_no,
  9842. CTL_OF_SCB(scb));
  9843. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  9844. if (p->features & AHC_QUEUE_REGS)
  9845. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  9846. else
  9847. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  9848. scb->flags |= SCB_QUEUED_ABORT;
  9849. }
  9850. }
  9851. aic_outb(p, saved_scbptr, SCBPTR);
  9852. unpause_sequencer(p, FALSE);
  9853. spin_unlock_irq(p->host->host_lock);
  9854. msleep(1000/4);
  9855. spin_lock_irq(p->host->host_lock);
  9856. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9857. return FAILED;
  9858. else
  9859. return SUCCESS;
  9860. }
  9861. static int
  9862. aic7xxx_bus_device_reset(Scsi_Cmnd *cmd)
  9863. {
  9864. int rc;
  9865. spin_lock_irq(cmd->device->host->host_lock);
  9866. rc = __aic7xxx_bus_device_reset(cmd);
  9867. spin_unlock_irq(cmd->device->host->host_lock);
  9868. return rc;
  9869. }
  9870. /*+F*************************************************************************
  9871. * Function:
  9872. * aic7xxx_panic_abort
  9873. *
  9874. * Description:
  9875. * Abort the current SCSI command(s).
  9876. *-F*************************************************************************/
  9877. static void
  9878. aic7xxx_panic_abort(struct aic7xxx_host *p, Scsi_Cmnd *cmd)
  9879. {
  9880. printk("aic7xxx driver version %s\n", AIC7XXX_C_VERSION);
  9881. printk("Controller type:\n %s\n", board_names[p->board_name_index]);
  9882. printk("p->flags=0x%lx, p->chip=0x%x, p->features=0x%x, "
  9883. "sequencer %s paused\n",
  9884. p->flags, p->chip, p->features,
  9885. (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
  9886. pause_sequencer(p);
  9887. disable_irq(p->irq);
  9888. aic7xxx_print_card(p);
  9889. aic7xxx_print_scratch_ram(p);
  9890. spin_unlock_irq(p->host->host_lock);
  9891. for(;;) barrier();
  9892. }
  9893. /*+F*************************************************************************
  9894. * Function:
  9895. * aic7xxx_abort
  9896. *
  9897. * Description:
  9898. * Abort the current SCSI command(s).
  9899. *-F*************************************************************************/
  9900. static int
  9901. __aic7xxx_abort(Scsi_Cmnd *cmd)
  9902. {
  9903. struct aic7xxx_scb *scb = NULL;
  9904. struct aic7xxx_host *p;
  9905. int found=0, disconnected;
  9906. unsigned char saved_hscbptr, hscbptr, scb_control;
  9907. struct aic_dev_data *aic_dev;
  9908. if(cmd == NULL)
  9909. {
  9910. printk(KERN_ERR "aic7xxx_abort: called with NULL cmd!\n");
  9911. return FAILED;
  9912. }
  9913. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9914. aic_dev = AIC_DEV(cmd);
  9915. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9916. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9917. else
  9918. return FAILED;
  9919. aic7xxx_isr(p->irq, (void *)p, NULL);
  9920. aic7xxx_done_cmds_complete(p);
  9921. /* If the command was already complete or just completed, then we didn't
  9922. * do a reset, return FAILED */
  9923. if(!(scb->flags & SCB_ACTIVE))
  9924. return FAILED;
  9925. pause_sequencer(p);
  9926. /*
  9927. * I added a new config option to the driver: "panic_on_abort" that will
  9928. * cause the driver to panic and the machine to stop on the first abort
  9929. * or reset call into the driver. At that point, it prints out a lot of
  9930. * useful information for me which I can then use to try and debug the
  9931. * problem. Simply enable the boot time prompt in order to activate this
  9932. * code.
  9933. */
  9934. if (aic7xxx_panic_on_abort)
  9935. aic7xxx_panic_abort(p, cmd);
  9936. if (aic7xxx_verbose & VERBOSE_ABORT)
  9937. {
  9938. printk(INFO_LEAD "Aborting scb %d, flags 0x%x, SEQADDR 0x%x, LASTPHASE "
  9939. "0x%x\n",
  9940. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags,
  9941. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9942. aic_inb(p, LASTPHASE));
  9943. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  9944. p->host_no, CTL_OF_SCB(scb), (p->features & AHC_ULTRA2) ?
  9945. aic_inb(p, SG_CACHEPTR) : 0, aic_inb(p, SG_COUNT),
  9946. aic_inb(p, SCSISIGI));
  9947. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  9948. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SSTAT0),
  9949. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  9950. }
  9951. if (scb->flags & SCB_WAITINGQ)
  9952. {
  9953. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9954. printk(INFO_LEAD "SCB found on waiting list and "
  9955. "aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9956. scbq_remove(&p->waiting_scbs, scb);
  9957. scbq_remove(&aic_dev->delayed_scbs, scb);
  9958. aic_dev->active_cmds++;
  9959. p->activescbs++;
  9960. scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
  9961. scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
  9962. goto success;
  9963. }
  9964. /*
  9965. * We just checked the waiting_q, now for the QINFIFO
  9966. */
  9967. if ( ((found = aic7xxx_search_qinfifo(p, cmd->device->id, cmd->device->channel,
  9968. cmd->device->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
  9969. FALSE, NULL)) != 0) &&
  9970. (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
  9971. {
  9972. printk(INFO_LEAD "SCB found in QINFIFO and aborted.\n", p->host_no,
  9973. CTL_OF_SCB(scb));
  9974. goto success;
  9975. }
  9976. /*
  9977. * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
  9978. */
  9979. saved_hscbptr = aic_inb(p, SCBPTR);
  9980. if ((hscbptr = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9981. {
  9982. aic_outb(p, hscbptr, SCBPTR);
  9983. scb_control = aic_inb(p, SCB_CONTROL);
  9984. disconnected = scb_control & DISCONNECTED;
  9985. /*
  9986. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9987. * either currently active or on the waiting list.
  9988. */
  9989. if(!disconnected && aic_inb(p, LASTPHASE) == P_BUSFREE) {
  9990. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9991. printk(INFO_LEAD "SCB found on hardware waiting"
  9992. " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9993. /* If we are the only waiting command, stop the selection engine */
  9994. if (aic_inb(p, WAITING_SCBH) == hscbptr && aic_inb(p, SCB_NEXT) ==
  9995. SCB_LIST_NULL)
  9996. {
  9997. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  9998. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  9999. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  10000. }
  10001. else
  10002. {
  10003. unsigned char prev, next;
  10004. prev = SCB_LIST_NULL;
  10005. next = aic_inb(p, WAITING_SCBH);
  10006. while(next != SCB_LIST_NULL)
  10007. {
  10008. aic_outb(p, next, SCBPTR);
  10009. if (next == hscbptr)
  10010. {
  10011. next = aic_inb(p, SCB_NEXT);
  10012. if (prev != SCB_LIST_NULL)
  10013. {
  10014. aic_outb(p, prev, SCBPTR);
  10015. aic_outb(p, next, SCB_NEXT);
  10016. }
  10017. else
  10018. aic_outb(p, next, WAITING_SCBH);
  10019. aic_outb(p, hscbptr, SCBPTR);
  10020. next = SCB_LIST_NULL;
  10021. }
  10022. else
  10023. {
  10024. prev = next;
  10025. next = aic_inb(p, SCB_NEXT);
  10026. }
  10027. }
  10028. }
  10029. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  10030. aic_outb(p, 0, SCB_CONTROL);
  10031. aic7xxx_add_curscb_to_free_list(p);
  10032. scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
  10033. goto success;
  10034. }
  10035. else if (!disconnected)
  10036. {
  10037. /*
  10038. * We are the currently active command
  10039. */
  10040. if((aic_inb(p, LASTPHASE) == P_MESGIN) ||
  10041. (aic_inb(p, LASTPHASE) == P_MESGOUT))
  10042. {
  10043. /*
  10044. * Message buffer busy, unable to abort
  10045. */
  10046. printk(INFO_LEAD "message buffer busy, unable to abort.\n",
  10047. p->host_no, CTL_OF_SCB(scb));
  10048. unpause_sequencer(p, FALSE);
  10049. return FAILED;
  10050. }
  10051. /* Fallthrough to below, set ATNO after we set SCB_CONTROL */
  10052. }
  10053. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  10054. if(!disconnected)
  10055. {
  10056. aic_outb(p, HOST_MSG, MSG_OUT);
  10057. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  10058. }
  10059. aic_outb(p, saved_hscbptr, SCBPTR);
  10060. }
  10061. else
  10062. {
  10063. /*
  10064. * The scb isn't in the card at all and it is active and it isn't in
  10065. * any of the queues, so it must be disconnected and paged out. Fall
  10066. * through to the code below.
  10067. */
  10068. disconnected = 1;
  10069. }
  10070. p->flags |= AHC_ABORT_PENDING;
  10071. scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
  10072. scb->hscb->control |= MK_MESSAGE;
  10073. if(disconnected)
  10074. {
  10075. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  10076. printk(INFO_LEAD "SCB disconnected. Queueing Abort"
  10077. " SCB.\n", p->host_no, CTL_OF_SCB(scb));
  10078. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  10079. if (p->features & AHC_QUEUE_REGS)
  10080. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  10081. else
  10082. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  10083. }
  10084. unpause_sequencer(p, FALSE);
  10085. spin_unlock_irq(p->host->host_lock);
  10086. msleep(1000/4);
  10087. spin_lock_irq(p->host->host_lock);
  10088. if (p->flags & AHC_ABORT_PENDING)
  10089. {
  10090. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10091. printk(INFO_LEAD "Abort never delivered, returning FAILED\n", p->host_no,
  10092. CTL_OF_CMD(cmd));
  10093. p->flags &= ~AHC_ABORT_PENDING;
  10094. return FAILED;
  10095. }
  10096. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10097. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10098. return SUCCESS;
  10099. success:
  10100. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10101. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10102. aic7xxx_run_done_queue(p, TRUE);
  10103. unpause_sequencer(p, FALSE);
  10104. return SUCCESS;
  10105. }
  10106. static int
  10107. aic7xxx_abort(Scsi_Cmnd *cmd)
  10108. {
  10109. int rc;
  10110. spin_lock_irq(cmd->device->host->host_lock);
  10111. rc = __aic7xxx_abort(cmd);
  10112. spin_unlock_irq(cmd->device->host->host_lock);
  10113. return rc;
  10114. }
  10115. /*+F*************************************************************************
  10116. * Function:
  10117. * aic7xxx_reset
  10118. *
  10119. * Description:
  10120. * Resetting the bus always succeeds - is has to, otherwise the
  10121. * kernel will panic! Try a surgical technique - sending a BUS
  10122. * DEVICE RESET message - on the offending target before pulling
  10123. * the SCSI bus reset line.
  10124. *-F*************************************************************************/
  10125. static int
  10126. aic7xxx_reset(Scsi_Cmnd *cmd)
  10127. {
  10128. struct aic7xxx_scb *scb;
  10129. struct aic7xxx_host *p;
  10130. struct aic_dev_data *aic_dev;
  10131. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  10132. spin_lock_irq(p->host->host_lock);
  10133. aic_dev = AIC_DEV(cmd);
  10134. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  10135. {
  10136. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  10137. if (scb->cmd != cmd)
  10138. scb = NULL;
  10139. }
  10140. else
  10141. {
  10142. scb = NULL;
  10143. }
  10144. /*
  10145. * I added a new config option to the driver: "panic_on_abort" that will
  10146. * cause the driver to panic and the machine to stop on the first abort
  10147. * or reset call into the driver. At that point, it prints out a lot of
  10148. * useful information for me which I can then use to try and debug the
  10149. * problem. Simply enable the boot time prompt in order to activate this
  10150. * code.
  10151. */
  10152. if (aic7xxx_panic_on_abort)
  10153. aic7xxx_panic_abort(p, cmd);
  10154. pause_sequencer(p);
  10155. while((aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
  10156. {
  10157. aic7xxx_isr(p->irq, p, (void *)NULL );
  10158. pause_sequencer(p);
  10159. }
  10160. aic7xxx_done_cmds_complete(p);
  10161. if(scb && (scb->cmd == NULL))
  10162. {
  10163. /*
  10164. * We just completed the command when we ran the isr stuff, so we no
  10165. * longer have it.
  10166. */
  10167. unpause_sequencer(p, FALSE);
  10168. spin_unlock_irq(p->host->host_lock);
  10169. return SUCCESS;
  10170. }
  10171. /*
  10172. * By this point, we want to already know what we are going to do and
  10173. * only have the following code implement our course of action.
  10174. */
  10175. aic7xxx_reset_channel(p, cmd->device->channel, TRUE);
  10176. if (p->features & AHC_TWIN)
  10177. {
  10178. aic7xxx_reset_channel(p, cmd->device->channel ^ 0x01, TRUE);
  10179. restart_sequencer(p);
  10180. }
  10181. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  10182. aic7xxx_clear_intstat(p);
  10183. p->flags &= ~AHC_HANDLING_REQINITS;
  10184. p->msg_type = MSG_TYPE_NONE;
  10185. p->msg_index = 0;
  10186. p->msg_len = 0;
  10187. aic7xxx_run_done_queue(p, TRUE);
  10188. unpause_sequencer(p, FALSE);
  10189. spin_unlock_irq(p->host->host_lock);
  10190. ssleep(2);
  10191. return SUCCESS;
  10192. }
  10193. /*+F*************************************************************************
  10194. * Function:
  10195. * aic7xxx_biosparam
  10196. *
  10197. * Description:
  10198. * Return the disk geometry for the given SCSI device.
  10199. *
  10200. * Note:
  10201. * This function is broken for today's really large drives and needs
  10202. * fixed.
  10203. *-F*************************************************************************/
  10204. static int
  10205. aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  10206. sector_t capacity, int geom[])
  10207. {
  10208. sector_t heads, sectors, cylinders;
  10209. int ret;
  10210. struct aic7xxx_host *p;
  10211. unsigned char *buf;
  10212. p = (struct aic7xxx_host *) sdev->host->hostdata;
  10213. buf = scsi_bios_ptable(bdev);
  10214. if ( buf )
  10215. {
  10216. ret = scsi_partsize(buf, capacity, &geom[2], &geom[0], &geom[1]);
  10217. kfree(buf);
  10218. if ( ret != -1 )
  10219. return(ret);
  10220. }
  10221. heads = 64;
  10222. sectors = 32;
  10223. cylinders = capacity >> 11;
  10224. if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
  10225. {
  10226. heads = 255;
  10227. sectors = 63;
  10228. cylinders = capacity >> 14;
  10229. if(capacity > (65535 * heads * sectors))
  10230. cylinders = 65535;
  10231. else
  10232. cylinders = ((unsigned int)capacity) / (unsigned int)(heads * sectors);
  10233. }
  10234. geom[0] = (int)heads;
  10235. geom[1] = (int)sectors;
  10236. geom[2] = (int)cylinders;
  10237. return (0);
  10238. }
  10239. /*+F*************************************************************************
  10240. * Function:
  10241. * aic7xxx_release
  10242. *
  10243. * Description:
  10244. * Free the passed in Scsi_Host memory structures prior to unloading the
  10245. * module.
  10246. *-F*************************************************************************/
  10247. static int
  10248. aic7xxx_release(struct Scsi_Host *host)
  10249. {
  10250. struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
  10251. struct aic7xxx_host *next, *prev;
  10252. if(p->irq)
  10253. free_irq(p->irq, p);
  10254. #ifdef MMAPIO
  10255. if(p->maddr)
  10256. {
  10257. iounmap(p->maddr);
  10258. }
  10259. #endif /* MMAPIO */
  10260. if(!p->pdev)
  10261. release_region(p->base, MAXREG - MINREG);
  10262. #ifdef CONFIG_PCI
  10263. else
  10264. pci_release_regions(p->pdev);
  10265. #endif
  10266. prev = NULL;
  10267. next = first_aic7xxx;
  10268. while(next != NULL)
  10269. {
  10270. if(next == p)
  10271. {
  10272. if(prev == NULL)
  10273. first_aic7xxx = next->next;
  10274. else
  10275. prev->next = next->next;
  10276. }
  10277. else
  10278. {
  10279. prev = next;
  10280. }
  10281. next = next->next;
  10282. }
  10283. aic7xxx_free(p);
  10284. return(0);
  10285. }
  10286. /*+F*************************************************************************
  10287. * Function:
  10288. * aic7xxx_print_card
  10289. *
  10290. * Description:
  10291. * Print out all of the control registers on the card
  10292. *
  10293. * NOTE: This function is not yet safe for use on the VLB and EISA
  10294. * controllers, so it isn't used on those controllers at all.
  10295. *-F*************************************************************************/
  10296. static void
  10297. aic7xxx_print_card(struct aic7xxx_host *p)
  10298. {
  10299. int i, j, k, chip;
  10300. static struct register_ranges {
  10301. int num_ranges;
  10302. int range_val[32];
  10303. } cards_ds[] = {
  10304. { 0, {0,} }, /* none */
  10305. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
  10306. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
  10307. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
  10308. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10309. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
  10310. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10311. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
  10312. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10313. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
  10314. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10315. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
  10316. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10317. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10318. 0xfe, 0xff} },
  10319. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
  10320. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
  10321. 0x9f, 0x9f, 0xe0, 0xf1} },
  10322. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
  10323. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10324. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10325. 0xfe, 0xff} },
  10326. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
  10327. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10328. 0xe0, 0xf1, 0xf4, 0xfc} },
  10329. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
  10330. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10331. 0xe0, 0xf1, 0xf4, 0xfc} },
  10332. };
  10333. chip = p->chip & AHC_CHIPID_MASK;
  10334. printk("%s at ",
  10335. board_names[p->board_name_index]);
  10336. switch(p->chip & ~AHC_CHIPID_MASK)
  10337. {
  10338. case AHC_VL:
  10339. printk("VLB Slot %d.\n", p->pci_device_fn);
  10340. break;
  10341. case AHC_EISA:
  10342. printk("EISA Slot %d.\n", p->pci_device_fn);
  10343. break;
  10344. case AHC_PCI:
  10345. default:
  10346. printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  10347. PCI_FUNC(p->pci_device_fn));
  10348. break;
  10349. }
  10350. /*
  10351. * the registers on the card....
  10352. */
  10353. printk("Card Dump:\n");
  10354. k = 0;
  10355. for(i=0; i<cards_ds[chip].num_ranges; i++)
  10356. {
  10357. for(j = cards_ds[chip].range_val[ i * 2 ];
  10358. j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
  10359. j++)
  10360. {
  10361. printk("%02x:%02x ", j, aic_inb(p, j));
  10362. if(++k == 13)
  10363. {
  10364. printk("\n");
  10365. k=0;
  10366. }
  10367. }
  10368. }
  10369. if(k != 0)
  10370. printk("\n");
  10371. /*
  10372. * If this was an Ultra2 controller, then we just hosed the card in terms
  10373. * of the QUEUE REGS. This function is only called at init time or by
  10374. * the panic_abort function, so it's safe to assume a generic init time
  10375. * setting here
  10376. */
  10377. if(p->features & AHC_QUEUE_REGS)
  10378. {
  10379. aic_outb(p, 0, SDSCB_QOFF);
  10380. aic_outb(p, 0, SNSCB_QOFF);
  10381. aic_outb(p, 0, HNSCB_QOFF);
  10382. }
  10383. }
  10384. /*+F*************************************************************************
  10385. * Function:
  10386. * aic7xxx_print_scratch_ram
  10387. *
  10388. * Description:
  10389. * Print out the scratch RAM values on the card.
  10390. *-F*************************************************************************/
  10391. static void
  10392. aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
  10393. {
  10394. int i, k;
  10395. k = 0;
  10396. printk("Scratch RAM:\n");
  10397. for(i = SRAM_BASE; i < SEQCTL; i++)
  10398. {
  10399. printk("%02x:%02x ", i, aic_inb(p, i));
  10400. if(++k == 13)
  10401. {
  10402. printk("\n");
  10403. k=0;
  10404. }
  10405. }
  10406. if (p->features & AHC_MORE_SRAM)
  10407. {
  10408. for(i = TARG_OFFSET; i < 0x80; i++)
  10409. {
  10410. printk("%02x:%02x ", i, aic_inb(p, i));
  10411. if(++k == 13)
  10412. {
  10413. printk("\n");
  10414. k=0;
  10415. }
  10416. }
  10417. }
  10418. printk("\n");
  10419. }
  10420. #include "aic7xxx_old/aic7xxx_proc.c"
  10421. MODULE_LICENSE("Dual BSD/GPL");
  10422. MODULE_VERSION(AIC7XXX_H_VERSION);
  10423. static struct scsi_host_template driver_template = {
  10424. .proc_info = aic7xxx_proc_info,
  10425. .detect = aic7xxx_detect,
  10426. .release = aic7xxx_release,
  10427. .info = aic7xxx_info,
  10428. .queuecommand = aic7xxx_queue,
  10429. .slave_alloc = aic7xxx_slave_alloc,
  10430. .slave_configure = aic7xxx_slave_configure,
  10431. .slave_destroy = aic7xxx_slave_destroy,
  10432. .bios_param = aic7xxx_biosparam,
  10433. .eh_abort_handler = aic7xxx_abort,
  10434. .eh_device_reset_handler = aic7xxx_bus_device_reset,
  10435. .eh_host_reset_handler = aic7xxx_reset,
  10436. .can_queue = 255,
  10437. .this_id = -1,
  10438. .max_sectors = 2048,
  10439. .cmd_per_lun = 3,
  10440. .use_clustering = ENABLE_CLUSTERING,
  10441. };
  10442. #include "scsi_module.c"
  10443. /*
  10444. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  10445. * Emacs will notice this stuff at the end of the file and automatically
  10446. * adjust the settings for this buffer only. This must remain at the end
  10447. * of the file.
  10448. * ---------------------------------------------------------------------------
  10449. * Local variables:
  10450. * c-indent-level: 2
  10451. * c-brace-imaginary-offset: 0
  10452. * c-brace-offset: -2
  10453. * c-argdecl-indent: 2
  10454. * c-label-offset: -2
  10455. * c-continued-statement-offset: 2
  10456. * c-continued-brace-offset: 0
  10457. * indent-tabs-mode: nil
  10458. * tab-width: 8
  10459. * End:
  10460. */