advansys.c 337 KB

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