advansys.c 346 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866
  1. /*
  2. * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
  3. *
  4. * Copyright (c) 1995-2000 Advanced System Products, Inc.
  5. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
  6. * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
  7. * Copyright (c) 2014 Hannes Reinecke <hare@suse.de>
  8. * All Rights Reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. */
  15. /*
  16. * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
  17. * changed its name to ConnectCom Solutions, Inc.
  18. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
  19. */
  20. #include <linux/module.h>
  21. #include <linux/string.h>
  22. #include <linux/kernel.h>
  23. #include <linux/types.h>
  24. #include <linux/ioport.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/mm.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/init.h>
  31. #include <linux/blkdev.h>
  32. #include <linux/isa.h>
  33. #include <linux/eisa.h>
  34. #include <linux/pci.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/firmware.h>
  38. #include <linux/dmapool.h>
  39. #include <asm/io.h>
  40. #include <asm/dma.h>
  41. #include <scsi/scsi_cmnd.h>
  42. #include <scsi/scsi_device.h>
  43. #include <scsi/scsi_tcq.h>
  44. #include <scsi/scsi.h>
  45. #include <scsi/scsi_host.h>
  46. #define DRV_NAME "advansys"
  47. #define ASC_VERSION "3.5" /* AdvanSys Driver Version */
  48. /* FIXME:
  49. *
  50. * 1. Use scsi_transport_spi
  51. * 2. advansys_info is not safe against multiple simultaneous callers
  52. * 3. Add module_param to override ISA/VLB ioport array
  53. */
  54. /* Enable driver /proc statistics. */
  55. #define ADVANSYS_STATS
  56. /* Enable driver tracing. */
  57. #undef ADVANSYS_DEBUG
  58. typedef unsigned char uchar;
  59. #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
  60. #define PCI_VENDOR_ID_ASP 0x10cd
  61. #define PCI_DEVICE_ID_ASP_1200A 0x1100
  62. #define PCI_DEVICE_ID_ASP_ABP940 0x1200
  63. #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
  64. #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
  65. #define PCI_DEVICE_ID_38C0800_REV1 0x2500
  66. #define PCI_DEVICE_ID_38C1600_REV1 0x2700
  67. #define PortAddr unsigned int /* port address size */
  68. #define inp(port) inb(port)
  69. #define outp(port, byte) outb((byte), (port))
  70. #define inpw(port) inw(port)
  71. #define outpw(port, word) outw((word), (port))
  72. #define ASC_MAX_SG_QUEUE 7
  73. #define ASC_MAX_SG_LIST 255
  74. #define ASC_CS_TYPE unsigned short
  75. #define ASC_IS_ISA (0x0001)
  76. #define ASC_IS_ISAPNP (0x0081)
  77. #define ASC_IS_EISA (0x0002)
  78. #define ASC_IS_PCI (0x0004)
  79. #define ASC_IS_PCI_ULTRA (0x0104)
  80. #define ASC_IS_PCMCIA (0x0008)
  81. #define ASC_IS_MCA (0x0020)
  82. #define ASC_IS_VL (0x0040)
  83. #define ASC_IS_WIDESCSI_16 (0x0100)
  84. #define ASC_IS_WIDESCSI_32 (0x0200)
  85. #define ASC_IS_BIG_ENDIAN (0x8000)
  86. #define ASC_CHIP_MIN_VER_VL (0x01)
  87. #define ASC_CHIP_MAX_VER_VL (0x07)
  88. #define ASC_CHIP_MIN_VER_PCI (0x09)
  89. #define ASC_CHIP_MAX_VER_PCI (0x0F)
  90. #define ASC_CHIP_VER_PCI_BIT (0x08)
  91. #define ASC_CHIP_MIN_VER_ISA (0x11)
  92. #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
  93. #define ASC_CHIP_MAX_VER_ISA (0x27)
  94. #define ASC_CHIP_VER_ISA_BIT (0x30)
  95. #define ASC_CHIP_VER_ISAPNP_BIT (0x20)
  96. #define ASC_CHIP_VER_ASYN_BUG (0x21)
  97. #define ASC_CHIP_VER_PCI 0x08
  98. #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
  99. #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
  100. #define ASC_CHIP_MIN_VER_EISA (0x41)
  101. #define ASC_CHIP_MAX_VER_EISA (0x47)
  102. #define ASC_CHIP_VER_EISA_BIT (0x40)
  103. #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
  104. #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
  105. #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
  106. #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
  107. #define ASC_SCSI_ID_BITS 3
  108. #define ASC_SCSI_TIX_TYPE uchar
  109. #define ASC_ALL_DEVICE_BIT_SET 0xFF
  110. #define ASC_SCSI_BIT_ID_TYPE uchar
  111. #define ASC_MAX_TID 7
  112. #define ASC_MAX_LUN 7
  113. #define ASC_SCSI_WIDTH_BIT_SET 0xFF
  114. #define ASC_MAX_SENSE_LEN 32
  115. #define ASC_MIN_SENSE_LEN 14
  116. #define ASC_SCSI_RESET_HOLD_TIME_US 60
  117. /*
  118. * Narrow boards only support 12-byte commands, while wide boards
  119. * extend to 16-byte commands.
  120. */
  121. #define ASC_MAX_CDB_LEN 12
  122. #define ADV_MAX_CDB_LEN 16
  123. #define MS_SDTR_LEN 0x03
  124. #define MS_WDTR_LEN 0x02
  125. #define ASC_SG_LIST_PER_Q 7
  126. #define QS_FREE 0x00
  127. #define QS_READY 0x01
  128. #define QS_DISC1 0x02
  129. #define QS_DISC2 0x04
  130. #define QS_BUSY 0x08
  131. #define QS_ABORTED 0x40
  132. #define QS_DONE 0x80
  133. #define QC_NO_CALLBACK 0x01
  134. #define QC_SG_SWAP_QUEUE 0x02
  135. #define QC_SG_HEAD 0x04
  136. #define QC_DATA_IN 0x08
  137. #define QC_DATA_OUT 0x10
  138. #define QC_URGENT 0x20
  139. #define QC_MSG_OUT 0x40
  140. #define QC_REQ_SENSE 0x80
  141. #define QCSG_SG_XFER_LIST 0x02
  142. #define QCSG_SG_XFER_MORE 0x04
  143. #define QCSG_SG_XFER_END 0x08
  144. #define QD_IN_PROGRESS 0x00
  145. #define QD_NO_ERROR 0x01
  146. #define QD_ABORTED_BY_HOST 0x02
  147. #define QD_WITH_ERROR 0x04
  148. #define QD_INVALID_REQUEST 0x80
  149. #define QD_INVALID_HOST_NUM 0x81
  150. #define QD_INVALID_DEVICE 0x82
  151. #define QD_ERR_INTERNAL 0xFF
  152. #define QHSTA_NO_ERROR 0x00
  153. #define QHSTA_M_SEL_TIMEOUT 0x11
  154. #define QHSTA_M_DATA_OVER_RUN 0x12
  155. #define QHSTA_M_DATA_UNDER_RUN 0x12
  156. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  157. #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
  158. #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
  159. #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
  160. #define QHSTA_D_HOST_ABORT_FAILED 0x23
  161. #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
  162. #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
  163. #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
  164. #define QHSTA_M_WTM_TIMEOUT 0x41
  165. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  166. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  167. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  168. #define QHSTA_M_TARGET_STATUS_BUSY 0x45
  169. #define QHSTA_M_BAD_TAG_CODE 0x46
  170. #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
  171. #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
  172. #define QHSTA_D_LRAM_CMP_ERROR 0x81
  173. #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
  174. #define ASC_FLAG_SCSIQ_REQ 0x01
  175. #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
  176. #define ASC_FLAG_BIOS_ASYNC_IO 0x04
  177. #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
  178. #define ASC_FLAG_WIN16 0x10
  179. #define ASC_FLAG_WIN32 0x20
  180. #define ASC_FLAG_ISA_OVER_16MB 0x40
  181. #define ASC_FLAG_DOS_VM_CALLBACK 0x80
  182. #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
  183. #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
  184. #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
  185. #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
  186. #define ASC_SCSIQ_CPY_BEG 4
  187. #define ASC_SCSIQ_SGHD_CPY_BEG 2
  188. #define ASC_SCSIQ_B_FWD 0
  189. #define ASC_SCSIQ_B_BWD 1
  190. #define ASC_SCSIQ_B_STATUS 2
  191. #define ASC_SCSIQ_B_QNO 3
  192. #define ASC_SCSIQ_B_CNTL 4
  193. #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
  194. #define ASC_SCSIQ_D_DATA_ADDR 8
  195. #define ASC_SCSIQ_D_DATA_CNT 12
  196. #define ASC_SCSIQ_B_SENSE_LEN 20
  197. #define ASC_SCSIQ_DONE_INFO_BEG 22
  198. #define ASC_SCSIQ_D_SRBPTR 22
  199. #define ASC_SCSIQ_B_TARGET_IX 26
  200. #define ASC_SCSIQ_B_CDB_LEN 28
  201. #define ASC_SCSIQ_B_TAG_CODE 29
  202. #define ASC_SCSIQ_W_VM_ID 30
  203. #define ASC_SCSIQ_DONE_STATUS 32
  204. #define ASC_SCSIQ_HOST_STATUS 33
  205. #define ASC_SCSIQ_SCSI_STATUS 34
  206. #define ASC_SCSIQ_CDB_BEG 36
  207. #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
  208. #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
  209. #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
  210. #define ASC_SCSIQ_B_SG_WK_QP 49
  211. #define ASC_SCSIQ_B_SG_WK_IX 50
  212. #define ASC_SCSIQ_W_ALT_DC1 52
  213. #define ASC_SCSIQ_B_LIST_CNT 6
  214. #define ASC_SCSIQ_B_CUR_LIST_CNT 7
  215. #define ASC_SGQ_B_SG_CNTL 4
  216. #define ASC_SGQ_B_SG_HEAD_QP 5
  217. #define ASC_SGQ_B_SG_LIST_CNT 6
  218. #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
  219. #define ASC_SGQ_LIST_BEG 8
  220. #define ASC_DEF_SCSI1_QNG 4
  221. #define ASC_MAX_SCSI1_QNG 4
  222. #define ASC_DEF_SCSI2_QNG 16
  223. #define ASC_MAX_SCSI2_QNG 32
  224. #define ASC_TAG_CODE_MASK 0x23
  225. #define ASC_STOP_REQ_RISC_STOP 0x01
  226. #define ASC_STOP_ACK_RISC_STOP 0x03
  227. #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
  228. #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
  229. #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
  230. #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
  231. #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
  232. #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
  233. #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
  234. #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
  235. #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
  236. #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
  237. typedef struct asc_scsiq_1 {
  238. uchar status;
  239. uchar q_no;
  240. uchar cntl;
  241. uchar sg_queue_cnt;
  242. uchar target_id;
  243. uchar target_lun;
  244. __le32 data_addr;
  245. __le32 data_cnt;
  246. __le32 sense_addr;
  247. uchar sense_len;
  248. uchar extra_bytes;
  249. } ASC_SCSIQ_1;
  250. typedef struct asc_scsiq_2 {
  251. u32 srb_tag;
  252. uchar target_ix;
  253. uchar flag;
  254. uchar cdb_len;
  255. uchar tag_code;
  256. ushort vm_id;
  257. } ASC_SCSIQ_2;
  258. typedef struct asc_scsiq_3 {
  259. uchar done_stat;
  260. uchar host_stat;
  261. uchar scsi_stat;
  262. uchar scsi_msg;
  263. } ASC_SCSIQ_3;
  264. typedef struct asc_scsiq_4 {
  265. uchar cdb[ASC_MAX_CDB_LEN];
  266. uchar y_first_sg_list_qp;
  267. uchar y_working_sg_qp;
  268. uchar y_working_sg_ix;
  269. uchar y_res;
  270. ushort x_req_count;
  271. ushort x_reconnect_rtn;
  272. __le32 x_saved_data_addr;
  273. __le32 x_saved_data_cnt;
  274. } ASC_SCSIQ_4;
  275. typedef struct asc_q_done_info {
  276. ASC_SCSIQ_2 d2;
  277. ASC_SCSIQ_3 d3;
  278. uchar q_status;
  279. uchar q_no;
  280. uchar cntl;
  281. uchar sense_len;
  282. uchar extra_bytes;
  283. uchar res;
  284. u32 remain_bytes;
  285. } ASC_QDONE_INFO;
  286. typedef struct asc_sg_list {
  287. __le32 addr;
  288. __le32 bytes;
  289. } ASC_SG_LIST;
  290. typedef struct asc_sg_head {
  291. ushort entry_cnt;
  292. ushort queue_cnt;
  293. ushort entry_to_copy;
  294. ushort res;
  295. ASC_SG_LIST sg_list[0];
  296. } ASC_SG_HEAD;
  297. typedef struct asc_scsi_q {
  298. ASC_SCSIQ_1 q1;
  299. ASC_SCSIQ_2 q2;
  300. uchar *cdbptr;
  301. ASC_SG_HEAD *sg_head;
  302. ushort remain_sg_entry_cnt;
  303. ushort next_sg_index;
  304. } ASC_SCSI_Q;
  305. typedef struct asc_scsi_bios_req_q {
  306. ASC_SCSIQ_1 r1;
  307. ASC_SCSIQ_2 r2;
  308. uchar *cdbptr;
  309. ASC_SG_HEAD *sg_head;
  310. uchar *sense_ptr;
  311. ASC_SCSIQ_3 r3;
  312. uchar cdb[ASC_MAX_CDB_LEN];
  313. uchar sense[ASC_MIN_SENSE_LEN];
  314. } ASC_SCSI_BIOS_REQ_Q;
  315. typedef struct asc_risc_q {
  316. uchar fwd;
  317. uchar bwd;
  318. ASC_SCSIQ_1 i1;
  319. ASC_SCSIQ_2 i2;
  320. ASC_SCSIQ_3 i3;
  321. ASC_SCSIQ_4 i4;
  322. } ASC_RISC_Q;
  323. typedef struct asc_sg_list_q {
  324. uchar seq_no;
  325. uchar q_no;
  326. uchar cntl;
  327. uchar sg_head_qp;
  328. uchar sg_list_cnt;
  329. uchar sg_cur_list_cnt;
  330. } ASC_SG_LIST_Q;
  331. typedef struct asc_risc_sg_list_q {
  332. uchar fwd;
  333. uchar bwd;
  334. ASC_SG_LIST_Q sg;
  335. ASC_SG_LIST sg_list[7];
  336. } ASC_RISC_SG_LIST_Q;
  337. #define ASCQ_ERR_Q_STATUS 0x0D
  338. #define ASCQ_ERR_CUR_QNG 0x17
  339. #define ASCQ_ERR_SG_Q_LINKS 0x18
  340. #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
  341. #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
  342. #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
  343. /*
  344. * Warning code values are set in ASC_DVC_VAR 'warn_code'.
  345. */
  346. #define ASC_WARN_NO_ERROR 0x0000
  347. #define ASC_WARN_IO_PORT_ROTATE 0x0001
  348. #define ASC_WARN_EEPROM_CHKSUM 0x0002
  349. #define ASC_WARN_IRQ_MODIFIED 0x0004
  350. #define ASC_WARN_AUTO_CONFIG 0x0008
  351. #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
  352. #define ASC_WARN_EEPROM_RECOVER 0x0020
  353. #define ASC_WARN_CFG_MSW_RECOVER 0x0040
  354. /*
  355. * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
  356. */
  357. #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
  358. #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
  359. #define ASC_IERR_SET_PC_ADDR 0x0004
  360. #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
  361. #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
  362. #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
  363. #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
  364. #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
  365. #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
  366. #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
  367. #define ASC_IERR_NO_BUS_TYPE 0x0400
  368. #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
  369. #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
  370. #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
  371. #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
  372. #define ASC_MIN_TAG_Q_PER_DVC (0x04)
  373. #define ASC_MIN_FREE_Q (0x02)
  374. #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
  375. #define ASC_MAX_TOTAL_QNG 240
  376. #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
  377. #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
  378. #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
  379. #define ASC_MAX_INRAM_TAG_QNG 16
  380. #define ASC_IOADR_GAP 0x10
  381. #define ASC_SYN_MAX_OFFSET 0x0F
  382. #define ASC_DEF_SDTR_OFFSET 0x0F
  383. #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
  384. #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
  385. /* The narrow chip only supports a limited selection of transfer rates.
  386. * These are encoded in the range 0..7 or 0..15 depending whether the chip
  387. * is Ultra-capable or not. These tables let us convert from one to the other.
  388. */
  389. static const unsigned char asc_syn_xfer_period[8] = {
  390. 25, 30, 35, 40, 50, 60, 70, 85
  391. };
  392. static const unsigned char asc_syn_ultra_xfer_period[16] = {
  393. 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
  394. };
  395. typedef struct ext_msg {
  396. uchar msg_type;
  397. uchar msg_len;
  398. uchar msg_req;
  399. union {
  400. struct {
  401. uchar sdtr_xfer_period;
  402. uchar sdtr_req_ack_offset;
  403. } sdtr;
  404. struct {
  405. uchar wdtr_width;
  406. } wdtr;
  407. struct {
  408. uchar mdp_b3;
  409. uchar mdp_b2;
  410. uchar mdp_b1;
  411. uchar mdp_b0;
  412. } mdp;
  413. } u_ext_msg;
  414. uchar res;
  415. } EXT_MSG;
  416. #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
  417. #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
  418. #define wdtr_width u_ext_msg.wdtr.wdtr_width
  419. #define mdp_b3 u_ext_msg.mdp_b3
  420. #define mdp_b2 u_ext_msg.mdp_b2
  421. #define mdp_b1 u_ext_msg.mdp_b1
  422. #define mdp_b0 u_ext_msg.mdp_b0
  423. typedef struct asc_dvc_cfg {
  424. ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
  425. ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
  426. ASC_SCSI_BIT_ID_TYPE disc_enable;
  427. ASC_SCSI_BIT_ID_TYPE sdtr_enable;
  428. uchar chip_scsi_id;
  429. uchar isa_dma_speed;
  430. uchar isa_dma_channel;
  431. uchar chip_version;
  432. ushort mcode_date;
  433. ushort mcode_version;
  434. uchar max_tag_qng[ASC_MAX_TID + 1];
  435. uchar sdtr_period_offset[ASC_MAX_TID + 1];
  436. uchar adapter_info[6];
  437. } ASC_DVC_CFG;
  438. #define ASC_DEF_DVC_CNTL 0xFFFF
  439. #define ASC_DEF_CHIP_SCSI_ID 7
  440. #define ASC_DEF_ISA_DMA_SPEED 4
  441. #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
  442. #define ASC_INIT_STATE_END_GET_CFG 0x0002
  443. #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
  444. #define ASC_INIT_STATE_END_SET_CFG 0x0008
  445. #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
  446. #define ASC_INIT_STATE_END_LOAD_MC 0x0020
  447. #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
  448. #define ASC_INIT_STATE_END_INQUIRY 0x0080
  449. #define ASC_INIT_RESET_SCSI_DONE 0x0100
  450. #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
  451. #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
  452. #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
  453. #define ASC_MIN_TAGGED_CMD 7
  454. #define ASC_MAX_SCSI_RESET_WAIT 30
  455. #define ASC_OVERRUN_BSIZE 64
  456. struct asc_dvc_var; /* Forward Declaration. */
  457. typedef struct asc_dvc_var {
  458. PortAddr iop_base;
  459. ushort err_code;
  460. ushort dvc_cntl;
  461. ushort bug_fix_cntl;
  462. ushort bus_type;
  463. ASC_SCSI_BIT_ID_TYPE init_sdtr;
  464. ASC_SCSI_BIT_ID_TYPE sdtr_done;
  465. ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
  466. ASC_SCSI_BIT_ID_TYPE unit_not_ready;
  467. ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
  468. ASC_SCSI_BIT_ID_TYPE start_motor;
  469. uchar *overrun_buf;
  470. dma_addr_t overrun_dma;
  471. uchar scsi_reset_wait;
  472. uchar chip_no;
  473. bool is_in_int;
  474. uchar max_total_qng;
  475. uchar cur_total_qng;
  476. uchar in_critical_cnt;
  477. uchar last_q_shortage;
  478. ushort init_state;
  479. uchar cur_dvc_qng[ASC_MAX_TID + 1];
  480. uchar max_dvc_qng[ASC_MAX_TID + 1];
  481. ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
  482. ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
  483. const uchar *sdtr_period_tbl;
  484. ASC_DVC_CFG *cfg;
  485. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
  486. char redo_scam;
  487. ushort res2;
  488. uchar dos_int13_table[ASC_MAX_TID + 1];
  489. unsigned int max_dma_count;
  490. ASC_SCSI_BIT_ID_TYPE no_scam;
  491. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
  492. uchar min_sdtr_index;
  493. uchar max_sdtr_index;
  494. struct asc_board *drv_ptr;
  495. unsigned int uc_break;
  496. } ASC_DVC_VAR;
  497. typedef struct asc_dvc_inq_info {
  498. uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  499. } ASC_DVC_INQ_INFO;
  500. typedef struct asc_cap_info {
  501. u32 lba;
  502. u32 blk_size;
  503. } ASC_CAP_INFO;
  504. typedef struct asc_cap_info_array {
  505. ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  506. } ASC_CAP_INFO_ARRAY;
  507. #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
  508. #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
  509. #define ASC_CNTL_INITIATOR (ushort)0x0001
  510. #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
  511. #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
  512. #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
  513. #define ASC_CNTL_NO_SCAM (ushort)0x0010
  514. #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
  515. #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
  516. #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
  517. #define ASC_CNTL_RESET_SCSI (ushort)0x0200
  518. #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
  519. #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
  520. #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
  521. #define ASC_CNTL_BURST_MODE (ushort)0x2000
  522. #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
  523. #define ASC_EEP_DVC_CFG_BEG_VL 2
  524. #define ASC_EEP_MAX_DVC_ADDR_VL 15
  525. #define ASC_EEP_DVC_CFG_BEG 32
  526. #define ASC_EEP_MAX_DVC_ADDR 45
  527. #define ASC_EEP_MAX_RETRY 20
  528. /*
  529. * These macros keep the chip SCSI id and ISA DMA speed
  530. * bitfields in board order. C bitfields aren't portable
  531. * between big and little-endian platforms so they are
  532. * not used.
  533. */
  534. #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
  535. #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
  536. #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
  537. ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
  538. #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
  539. ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
  540. typedef struct asceep_config {
  541. ushort cfg_lsw;
  542. ushort cfg_msw;
  543. uchar init_sdtr;
  544. uchar disc_enable;
  545. uchar use_cmd_qng;
  546. uchar start_motor;
  547. uchar max_total_qng;
  548. uchar max_tag_qng;
  549. uchar bios_scan;
  550. uchar power_up_wait;
  551. uchar no_scam;
  552. uchar id_speed; /* low order 4 bits is chip scsi id */
  553. /* high order 4 bits is isa dma speed */
  554. uchar dos_int13_table[ASC_MAX_TID + 1];
  555. uchar adapter_info[6];
  556. ushort cntl;
  557. ushort chksum;
  558. } ASCEEP_CONFIG;
  559. #define ASC_EEP_CMD_READ 0x80
  560. #define ASC_EEP_CMD_WRITE 0x40
  561. #define ASC_EEP_CMD_WRITE_ABLE 0x30
  562. #define ASC_EEP_CMD_WRITE_DISABLE 0x00
  563. #define ASCV_MSGOUT_BEG 0x0000
  564. #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
  565. #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
  566. #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
  567. #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
  568. #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
  569. #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
  570. #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
  571. #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
  572. #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
  573. #define ASCV_BREAK_ADDR (ushort)0x0028
  574. #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
  575. #define ASCV_BREAK_CONTROL (ushort)0x002C
  576. #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
  577. #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
  578. #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
  579. #define ASCV_MCODE_SIZE_W (ushort)0x0034
  580. #define ASCV_STOP_CODE_B (ushort)0x0036
  581. #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
  582. #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
  583. #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
  584. #define ASCV_HALTCODE_W (ushort)0x0040
  585. #define ASCV_CHKSUM_W (ushort)0x0042
  586. #define ASCV_MC_DATE_W (ushort)0x0044
  587. #define ASCV_MC_VER_W (ushort)0x0046
  588. #define ASCV_NEXTRDY_B (ushort)0x0048
  589. #define ASCV_DONENEXT_B (ushort)0x0049
  590. #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
  591. #define ASCV_SCSIBUSY_B (ushort)0x004B
  592. #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
  593. #define ASCV_CURCDB_B (ushort)0x004D
  594. #define ASCV_RCLUN_B (ushort)0x004E
  595. #define ASCV_BUSY_QHEAD_B (ushort)0x004F
  596. #define ASCV_DISC1_QHEAD_B (ushort)0x0050
  597. #define ASCV_DISC_ENABLE_B (ushort)0x0052
  598. #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
  599. #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
  600. #define ASCV_MCODE_CNTL_B (ushort)0x0056
  601. #define ASCV_NULL_TARGET_B (ushort)0x0057
  602. #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
  603. #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
  604. #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
  605. #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
  606. #define ASCV_HOST_FLAG_B (ushort)0x005D
  607. #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
  608. #define ASCV_VER_SERIAL_B (ushort)0x0065
  609. #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
  610. #define ASCV_WTM_FLAG_B (ushort)0x0068
  611. #define ASCV_RISC_FLAG_B (ushort)0x006A
  612. #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
  613. #define ASC_HOST_FLAG_IN_ISR 0x01
  614. #define ASC_HOST_FLAG_ACK_INT 0x02
  615. #define ASC_RISC_FLAG_GEN_INT 0x01
  616. #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
  617. #define IOP_CTRL (0x0F)
  618. #define IOP_STATUS (0x0E)
  619. #define IOP_INT_ACK IOP_STATUS
  620. #define IOP_REG_IFC (0x0D)
  621. #define IOP_SYN_OFFSET (0x0B)
  622. #define IOP_EXTRA_CONTROL (0x0D)
  623. #define IOP_REG_PC (0x0C)
  624. #define IOP_RAM_ADDR (0x0A)
  625. #define IOP_RAM_DATA (0x08)
  626. #define IOP_EEP_DATA (0x06)
  627. #define IOP_EEP_CMD (0x07)
  628. #define IOP_VERSION (0x03)
  629. #define IOP_CONFIG_HIGH (0x04)
  630. #define IOP_CONFIG_LOW (0x02)
  631. #define IOP_SIG_BYTE (0x01)
  632. #define IOP_SIG_WORD (0x00)
  633. #define IOP_REG_DC1 (0x0E)
  634. #define IOP_REG_DC0 (0x0C)
  635. #define IOP_REG_SB (0x0B)
  636. #define IOP_REG_DA1 (0x0A)
  637. #define IOP_REG_DA0 (0x08)
  638. #define IOP_REG_SC (0x09)
  639. #define IOP_DMA_SPEED (0x07)
  640. #define IOP_REG_FLAG (0x07)
  641. #define IOP_FIFO_H (0x06)
  642. #define IOP_FIFO_L (0x04)
  643. #define IOP_REG_ID (0x05)
  644. #define IOP_REG_QP (0x03)
  645. #define IOP_REG_IH (0x02)
  646. #define IOP_REG_IX (0x01)
  647. #define IOP_REG_AX (0x00)
  648. #define IFC_REG_LOCK (0x00)
  649. #define IFC_REG_UNLOCK (0x09)
  650. #define IFC_WR_EN_FILTER (0x10)
  651. #define IFC_RD_NO_EEPROM (0x10)
  652. #define IFC_SLEW_RATE (0x20)
  653. #define IFC_ACT_NEG (0x40)
  654. #define IFC_INP_FILTER (0x80)
  655. #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
  656. #define SC_SEL (uchar)(0x80)
  657. #define SC_BSY (uchar)(0x40)
  658. #define SC_ACK (uchar)(0x20)
  659. #define SC_REQ (uchar)(0x10)
  660. #define SC_ATN (uchar)(0x08)
  661. #define SC_IO (uchar)(0x04)
  662. #define SC_CD (uchar)(0x02)
  663. #define SC_MSG (uchar)(0x01)
  664. #define SEC_SCSI_CTL (uchar)(0x80)
  665. #define SEC_ACTIVE_NEGATE (uchar)(0x40)
  666. #define SEC_SLEW_RATE (uchar)(0x20)
  667. #define SEC_ENABLE_FILTER (uchar)(0x10)
  668. #define ASC_HALT_EXTMSG_IN (ushort)0x8000
  669. #define ASC_HALT_CHK_CONDITION (ushort)0x8100
  670. #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
  671. #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
  672. #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
  673. #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
  674. #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
  675. #define ASC_MAX_QNO 0xF8
  676. #define ASC_DATA_SEC_BEG (ushort)0x0080
  677. #define ASC_DATA_SEC_END (ushort)0x0080
  678. #define ASC_CODE_SEC_BEG (ushort)0x0080
  679. #define ASC_CODE_SEC_END (ushort)0x0080
  680. #define ASC_QADR_BEG (0x4000)
  681. #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
  682. #define ASC_QADR_END (ushort)0x7FFF
  683. #define ASC_QLAST_ADR (ushort)0x7FC0
  684. #define ASC_QBLK_SIZE 0x40
  685. #define ASC_BIOS_DATA_QBEG 0xF8
  686. #define ASC_MIN_ACTIVE_QNO 0x01
  687. #define ASC_QLINK_END 0xFF
  688. #define ASC_EEPROM_WORDS 0x10
  689. #define ASC_MAX_MGS_LEN 0x10
  690. #define ASC_BIOS_ADDR_DEF 0xDC00
  691. #define ASC_BIOS_SIZE 0x3800
  692. #define ASC_BIOS_RAM_OFF 0x3800
  693. #define ASC_BIOS_RAM_SIZE 0x800
  694. #define ASC_BIOS_MIN_ADDR 0xC000
  695. #define ASC_BIOS_MAX_ADDR 0xEC00
  696. #define ASC_BIOS_BANK_SIZE 0x0400
  697. #define ASC_MCODE_START_ADDR 0x0080
  698. #define ASC_CFG0_HOST_INT_ON 0x0020
  699. #define ASC_CFG0_BIOS_ON 0x0040
  700. #define ASC_CFG0_VERA_BURST_ON 0x0080
  701. #define ASC_CFG0_SCSI_PARITY_ON 0x0800
  702. #define ASC_CFG1_SCSI_TARGET_ON 0x0080
  703. #define ASC_CFG1_LRAM_8BITS_ON 0x0800
  704. #define ASC_CFG_MSW_CLR_MASK 0x3080
  705. #define CSW_TEST1 (ASC_CS_TYPE)0x8000
  706. #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
  707. #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
  708. #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
  709. #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
  710. #define CSW_TEST2 (ASC_CS_TYPE)0x0400
  711. #define CSW_TEST3 (ASC_CS_TYPE)0x0200
  712. #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
  713. #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
  714. #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
  715. #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
  716. #define CSW_HALTED (ASC_CS_TYPE)0x0010
  717. #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
  718. #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
  719. #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
  720. #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
  721. #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
  722. #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
  723. #define CIW_TEST1 (ASC_CS_TYPE)0x0200
  724. #define CIW_TEST2 (ASC_CS_TYPE)0x0400
  725. #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
  726. #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
  727. #define CC_CHIP_RESET (uchar)0x80
  728. #define CC_SCSI_RESET (uchar)0x40
  729. #define CC_HALT (uchar)0x20
  730. #define CC_SINGLE_STEP (uchar)0x10
  731. #define CC_DMA_ABLE (uchar)0x08
  732. #define CC_TEST (uchar)0x04
  733. #define CC_BANK_ONE (uchar)0x02
  734. #define CC_DIAG (uchar)0x01
  735. #define ASC_1000_ID0W 0x04C1
  736. #define ASC_1000_ID0W_FIX 0x00C1
  737. #define ASC_1000_ID1B 0x25
  738. #define ASC_EISA_REV_IOP_MASK (0x0C83)
  739. #define ASC_EISA_CFG_IOP_MASK (0x0C86)
  740. #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
  741. #define INS_HALTINT (ushort)0x6281
  742. #define INS_HALT (ushort)0x6280
  743. #define INS_SINT (ushort)0x6200
  744. #define INS_RFLAG_WTM (ushort)0x7380
  745. #define ASC_MC_SAVE_CODE_WSIZE 0x500
  746. #define ASC_MC_SAVE_DATA_WSIZE 0x40
  747. typedef struct asc_mc_saved {
  748. ushort data[ASC_MC_SAVE_DATA_WSIZE];
  749. ushort code[ASC_MC_SAVE_CODE_WSIZE];
  750. } ASC_MC_SAVED;
  751. #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
  752. #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
  753. #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
  754. #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
  755. #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
  756. #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
  757. #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
  758. #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
  759. #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
  760. #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
  761. #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
  762. #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
  763. #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
  764. #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
  765. #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
  766. #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
  767. #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
  768. #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
  769. #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
  770. #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
  771. #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
  772. #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
  773. #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
  774. #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
  775. #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
  776. #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
  777. #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
  778. #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
  779. #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
  780. #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
  781. #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
  782. #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
  783. #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
  784. #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
  785. #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
  786. #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
  787. #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
  788. #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
  789. #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
  790. #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
  791. #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
  792. #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
  793. #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
  794. #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
  795. #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
  796. #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
  797. #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
  798. #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
  799. #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
  800. #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
  801. #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
  802. #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
  803. #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
  804. #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
  805. #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
  806. #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
  807. #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
  808. #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
  809. #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
  810. #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
  811. #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
  812. #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
  813. #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
  814. #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
  815. #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
  816. #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
  817. #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
  818. #define AdvPortAddr void __iomem * /* Virtual memory address size */
  819. /*
  820. * Define Adv Library required memory access macros.
  821. */
  822. #define ADV_MEM_READB(addr) readb(addr)
  823. #define ADV_MEM_READW(addr) readw(addr)
  824. #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
  825. #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
  826. #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
  827. /*
  828. * Define total number of simultaneous maximum element scatter-gather
  829. * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
  830. * maximum number of outstanding commands per wide host adapter. Each
  831. * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
  832. * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
  833. * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
  834. * structures or 255 scatter-gather elements.
  835. */
  836. #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
  837. /*
  838. * Define maximum number of scatter-gather elements per request.
  839. */
  840. #define ADV_MAX_SG_LIST 255
  841. #define NO_OF_SG_PER_BLOCK 15
  842. #define ADV_EEP_DVC_CFG_BEGIN (0x00)
  843. #define ADV_EEP_DVC_CFG_END (0x15)
  844. #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
  845. #define ADV_EEP_MAX_WORD_ADDR (0x1E)
  846. #define ADV_EEP_DELAY_MS 100
  847. #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
  848. #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
  849. /*
  850. * For the ASC3550 Bit 13 is Termination Polarity control bit.
  851. * For later ICs Bit 13 controls whether the CIS (Card Information
  852. * Service Section) is loaded from EEPROM.
  853. */
  854. #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
  855. #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
  856. /*
  857. * ASC38C1600 Bit 11
  858. *
  859. * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
  860. * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
  861. * Function 0 will specify INT B.
  862. *
  863. * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
  864. * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
  865. * Function 1 will specify INT A.
  866. */
  867. #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
  868. typedef struct adveep_3550_config {
  869. /* Word Offset, Description */
  870. ushort cfg_lsw; /* 00 power up initialization */
  871. /* bit 13 set - Term Polarity Control */
  872. /* bit 14 set - BIOS Enable */
  873. /* bit 15 set - Big Endian Mode */
  874. ushort cfg_msw; /* 01 unused */
  875. ushort disc_enable; /* 02 disconnect enable */
  876. ushort wdtr_able; /* 03 Wide DTR able */
  877. ushort sdtr_able; /* 04 Synchronous DTR able */
  878. ushort start_motor; /* 05 send start up motor */
  879. ushort tagqng_able; /* 06 tag queuing able */
  880. ushort bios_scan; /* 07 BIOS device control */
  881. ushort scam_tolerant; /* 08 no scam */
  882. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  883. uchar bios_boot_delay; /* power up wait */
  884. uchar scsi_reset_delay; /* 10 reset delay */
  885. uchar bios_id_lun; /* first boot device scsi id & lun */
  886. /* high nibble is lun */
  887. /* low nibble is scsi id */
  888. uchar termination; /* 11 0 - automatic */
  889. /* 1 - low off / high off */
  890. /* 2 - low off / high on */
  891. /* 3 - low on / high on */
  892. /* There is no low on / high off */
  893. uchar reserved1; /* reserved byte (not used) */
  894. ushort bios_ctrl; /* 12 BIOS control bits */
  895. /* bit 0 BIOS don't act as initiator. */
  896. /* bit 1 BIOS > 1 GB support */
  897. /* bit 2 BIOS > 2 Disk Support */
  898. /* bit 3 BIOS don't support removables */
  899. /* bit 4 BIOS support bootable CD */
  900. /* bit 5 BIOS scan enabled */
  901. /* bit 6 BIOS support multiple LUNs */
  902. /* bit 7 BIOS display of message */
  903. /* bit 8 SCAM disabled */
  904. /* bit 9 Reset SCSI bus during init. */
  905. /* bit 10 */
  906. /* bit 11 No verbose initialization. */
  907. /* bit 12 SCSI parity enabled */
  908. /* bit 13 */
  909. /* bit 14 */
  910. /* bit 15 */
  911. ushort ultra_able; /* 13 ULTRA speed able */
  912. ushort reserved2; /* 14 reserved */
  913. uchar max_host_qng; /* 15 maximum host queuing */
  914. uchar max_dvc_qng; /* maximum per device queuing */
  915. ushort dvc_cntl; /* 16 control bit for driver */
  916. ushort bug_fix; /* 17 control bit for bug fix */
  917. ushort serial_number_word1; /* 18 Board serial number word 1 */
  918. ushort serial_number_word2; /* 19 Board serial number word 2 */
  919. ushort serial_number_word3; /* 20 Board serial number word 3 */
  920. ushort check_sum; /* 21 EEP check sum */
  921. uchar oem_name[16]; /* 22 OEM name */
  922. ushort dvc_err_code; /* 30 last device driver error code */
  923. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  924. ushort adv_err_addr; /* 32 last uc error address */
  925. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  926. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  927. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  928. ushort num_of_err; /* 36 number of error */
  929. } ADVEEP_3550_CONFIG;
  930. typedef struct adveep_38C0800_config {
  931. /* Word Offset, Description */
  932. ushort cfg_lsw; /* 00 power up initialization */
  933. /* bit 13 set - Load CIS */
  934. /* bit 14 set - BIOS Enable */
  935. /* bit 15 set - Big Endian Mode */
  936. ushort cfg_msw; /* 01 unused */
  937. ushort disc_enable; /* 02 disconnect enable */
  938. ushort wdtr_able; /* 03 Wide DTR able */
  939. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  940. ushort start_motor; /* 05 send start up motor */
  941. ushort tagqng_able; /* 06 tag queuing able */
  942. ushort bios_scan; /* 07 BIOS device control */
  943. ushort scam_tolerant; /* 08 no scam */
  944. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  945. uchar bios_boot_delay; /* power up wait */
  946. uchar scsi_reset_delay; /* 10 reset delay */
  947. uchar bios_id_lun; /* first boot device scsi id & lun */
  948. /* high nibble is lun */
  949. /* low nibble is scsi id */
  950. uchar termination_se; /* 11 0 - automatic */
  951. /* 1 - low off / high off */
  952. /* 2 - low off / high on */
  953. /* 3 - low on / high on */
  954. /* There is no low on / high off */
  955. uchar termination_lvd; /* 11 0 - automatic */
  956. /* 1 - low off / high off */
  957. /* 2 - low off / high on */
  958. /* 3 - low on / high on */
  959. /* There is no low on / high off */
  960. ushort bios_ctrl; /* 12 BIOS control bits */
  961. /* bit 0 BIOS don't act as initiator. */
  962. /* bit 1 BIOS > 1 GB support */
  963. /* bit 2 BIOS > 2 Disk Support */
  964. /* bit 3 BIOS don't support removables */
  965. /* bit 4 BIOS support bootable CD */
  966. /* bit 5 BIOS scan enabled */
  967. /* bit 6 BIOS support multiple LUNs */
  968. /* bit 7 BIOS display of message */
  969. /* bit 8 SCAM disabled */
  970. /* bit 9 Reset SCSI bus during init. */
  971. /* bit 10 */
  972. /* bit 11 No verbose initialization. */
  973. /* bit 12 SCSI parity enabled */
  974. /* bit 13 */
  975. /* bit 14 */
  976. /* bit 15 */
  977. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  978. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  979. uchar max_host_qng; /* 15 maximum host queueing */
  980. uchar max_dvc_qng; /* maximum per device queuing */
  981. ushort dvc_cntl; /* 16 control bit for driver */
  982. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  983. ushort serial_number_word1; /* 18 Board serial number word 1 */
  984. ushort serial_number_word2; /* 19 Board serial number word 2 */
  985. ushort serial_number_word3; /* 20 Board serial number word 3 */
  986. ushort check_sum; /* 21 EEP check sum */
  987. uchar oem_name[16]; /* 22 OEM name */
  988. ushort dvc_err_code; /* 30 last device driver error code */
  989. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  990. ushort adv_err_addr; /* 32 last uc error address */
  991. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  992. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  993. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  994. ushort reserved36; /* 36 reserved */
  995. ushort reserved37; /* 37 reserved */
  996. ushort reserved38; /* 38 reserved */
  997. ushort reserved39; /* 39 reserved */
  998. ushort reserved40; /* 40 reserved */
  999. ushort reserved41; /* 41 reserved */
  1000. ushort reserved42; /* 42 reserved */
  1001. ushort reserved43; /* 43 reserved */
  1002. ushort reserved44; /* 44 reserved */
  1003. ushort reserved45; /* 45 reserved */
  1004. ushort reserved46; /* 46 reserved */
  1005. ushort reserved47; /* 47 reserved */
  1006. ushort reserved48; /* 48 reserved */
  1007. ushort reserved49; /* 49 reserved */
  1008. ushort reserved50; /* 50 reserved */
  1009. ushort reserved51; /* 51 reserved */
  1010. ushort reserved52; /* 52 reserved */
  1011. ushort reserved53; /* 53 reserved */
  1012. ushort reserved54; /* 54 reserved */
  1013. ushort reserved55; /* 55 reserved */
  1014. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1015. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1016. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1017. ushort subsysid; /* 59 SubSystem ID */
  1018. ushort reserved60; /* 60 reserved */
  1019. ushort reserved61; /* 61 reserved */
  1020. ushort reserved62; /* 62 reserved */
  1021. ushort reserved63; /* 63 reserved */
  1022. } ADVEEP_38C0800_CONFIG;
  1023. typedef struct adveep_38C1600_config {
  1024. /* Word Offset, Description */
  1025. ushort cfg_lsw; /* 00 power up initialization */
  1026. /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
  1027. /* clear - Func. 0 INTA, Func. 1 INTB */
  1028. /* bit 13 set - Load CIS */
  1029. /* bit 14 set - BIOS Enable */
  1030. /* bit 15 set - Big Endian Mode */
  1031. ushort cfg_msw; /* 01 unused */
  1032. ushort disc_enable; /* 02 disconnect enable */
  1033. ushort wdtr_able; /* 03 Wide DTR able */
  1034. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1035. ushort start_motor; /* 05 send start up motor */
  1036. ushort tagqng_able; /* 06 tag queuing able */
  1037. ushort bios_scan; /* 07 BIOS device control */
  1038. ushort scam_tolerant; /* 08 no scam */
  1039. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1040. uchar bios_boot_delay; /* power up wait */
  1041. uchar scsi_reset_delay; /* 10 reset delay */
  1042. uchar bios_id_lun; /* first boot device scsi id & lun */
  1043. /* high nibble is lun */
  1044. /* low nibble is scsi id */
  1045. uchar termination_se; /* 11 0 - automatic */
  1046. /* 1 - low off / high off */
  1047. /* 2 - low off / high on */
  1048. /* 3 - low on / high on */
  1049. /* There is no low on / high off */
  1050. uchar termination_lvd; /* 11 0 - automatic */
  1051. /* 1 - low off / high off */
  1052. /* 2 - low off / high on */
  1053. /* 3 - low on / high on */
  1054. /* There is no low on / high off */
  1055. ushort bios_ctrl; /* 12 BIOS control bits */
  1056. /* bit 0 BIOS don't act as initiator. */
  1057. /* bit 1 BIOS > 1 GB support */
  1058. /* bit 2 BIOS > 2 Disk Support */
  1059. /* bit 3 BIOS don't support removables */
  1060. /* bit 4 BIOS support bootable CD */
  1061. /* bit 5 BIOS scan enabled */
  1062. /* bit 6 BIOS support multiple LUNs */
  1063. /* bit 7 BIOS display of message */
  1064. /* bit 8 SCAM disabled */
  1065. /* bit 9 Reset SCSI bus during init. */
  1066. /* bit 10 Basic Integrity Checking disabled */
  1067. /* bit 11 No verbose initialization. */
  1068. /* bit 12 SCSI parity enabled */
  1069. /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
  1070. /* bit 14 */
  1071. /* bit 15 */
  1072. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1073. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1074. uchar max_host_qng; /* 15 maximum host queueing */
  1075. uchar max_dvc_qng; /* maximum per device queuing */
  1076. ushort dvc_cntl; /* 16 control bit for driver */
  1077. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1078. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1079. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1080. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1081. ushort check_sum; /* 21 EEP check sum */
  1082. uchar oem_name[16]; /* 22 OEM name */
  1083. ushort dvc_err_code; /* 30 last device driver error code */
  1084. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1085. ushort adv_err_addr; /* 32 last uc error address */
  1086. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1087. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1088. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1089. ushort reserved36; /* 36 reserved */
  1090. ushort reserved37; /* 37 reserved */
  1091. ushort reserved38; /* 38 reserved */
  1092. ushort reserved39; /* 39 reserved */
  1093. ushort reserved40; /* 40 reserved */
  1094. ushort reserved41; /* 41 reserved */
  1095. ushort reserved42; /* 42 reserved */
  1096. ushort reserved43; /* 43 reserved */
  1097. ushort reserved44; /* 44 reserved */
  1098. ushort reserved45; /* 45 reserved */
  1099. ushort reserved46; /* 46 reserved */
  1100. ushort reserved47; /* 47 reserved */
  1101. ushort reserved48; /* 48 reserved */
  1102. ushort reserved49; /* 49 reserved */
  1103. ushort reserved50; /* 50 reserved */
  1104. ushort reserved51; /* 51 reserved */
  1105. ushort reserved52; /* 52 reserved */
  1106. ushort reserved53; /* 53 reserved */
  1107. ushort reserved54; /* 54 reserved */
  1108. ushort reserved55; /* 55 reserved */
  1109. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1110. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1111. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1112. ushort subsysid; /* 59 SubSystem ID */
  1113. ushort reserved60; /* 60 reserved */
  1114. ushort reserved61; /* 61 reserved */
  1115. ushort reserved62; /* 62 reserved */
  1116. ushort reserved63; /* 63 reserved */
  1117. } ADVEEP_38C1600_CONFIG;
  1118. /*
  1119. * EEPROM Commands
  1120. */
  1121. #define ASC_EEP_CMD_DONE 0x0200
  1122. /* bios_ctrl */
  1123. #define BIOS_CTRL_BIOS 0x0001
  1124. #define BIOS_CTRL_EXTENDED_XLAT 0x0002
  1125. #define BIOS_CTRL_GT_2_DISK 0x0004
  1126. #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
  1127. #define BIOS_CTRL_BOOTABLE_CD 0x0010
  1128. #define BIOS_CTRL_MULTIPLE_LUN 0x0040
  1129. #define BIOS_CTRL_DISPLAY_MSG 0x0080
  1130. #define BIOS_CTRL_NO_SCAM 0x0100
  1131. #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
  1132. #define BIOS_CTRL_INIT_VERBOSE 0x0800
  1133. #define BIOS_CTRL_SCSI_PARITY 0x1000
  1134. #define BIOS_CTRL_AIPP_DIS 0x2000
  1135. #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
  1136. #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1137. /*
  1138. * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
  1139. * a special 16K Adv Library and Microcode version. After the issue is
  1140. * resolved, should restore 32K support.
  1141. *
  1142. * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
  1143. */
  1144. #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1145. /*
  1146. * Byte I/O register address from base of 'iop_base'.
  1147. */
  1148. #define IOPB_INTR_STATUS_REG 0x00
  1149. #define IOPB_CHIP_ID_1 0x01
  1150. #define IOPB_INTR_ENABLES 0x02
  1151. #define IOPB_CHIP_TYPE_REV 0x03
  1152. #define IOPB_RES_ADDR_4 0x04
  1153. #define IOPB_RES_ADDR_5 0x05
  1154. #define IOPB_RAM_DATA 0x06
  1155. #define IOPB_RES_ADDR_7 0x07
  1156. #define IOPB_FLAG_REG 0x08
  1157. #define IOPB_RES_ADDR_9 0x09
  1158. #define IOPB_RISC_CSR 0x0A
  1159. #define IOPB_RES_ADDR_B 0x0B
  1160. #define IOPB_RES_ADDR_C 0x0C
  1161. #define IOPB_RES_ADDR_D 0x0D
  1162. #define IOPB_SOFT_OVER_WR 0x0E
  1163. #define IOPB_RES_ADDR_F 0x0F
  1164. #define IOPB_MEM_CFG 0x10
  1165. #define IOPB_RES_ADDR_11 0x11
  1166. #define IOPB_GPIO_DATA 0x12
  1167. #define IOPB_RES_ADDR_13 0x13
  1168. #define IOPB_FLASH_PAGE 0x14
  1169. #define IOPB_RES_ADDR_15 0x15
  1170. #define IOPB_GPIO_CNTL 0x16
  1171. #define IOPB_RES_ADDR_17 0x17
  1172. #define IOPB_FLASH_DATA 0x18
  1173. #define IOPB_RES_ADDR_19 0x19
  1174. #define IOPB_RES_ADDR_1A 0x1A
  1175. #define IOPB_RES_ADDR_1B 0x1B
  1176. #define IOPB_RES_ADDR_1C 0x1C
  1177. #define IOPB_RES_ADDR_1D 0x1D
  1178. #define IOPB_RES_ADDR_1E 0x1E
  1179. #define IOPB_RES_ADDR_1F 0x1F
  1180. #define IOPB_DMA_CFG0 0x20
  1181. #define IOPB_DMA_CFG1 0x21
  1182. #define IOPB_TICKLE 0x22
  1183. #define IOPB_DMA_REG_WR 0x23
  1184. #define IOPB_SDMA_STATUS 0x24
  1185. #define IOPB_SCSI_BYTE_CNT 0x25
  1186. #define IOPB_HOST_BYTE_CNT 0x26
  1187. #define IOPB_BYTE_LEFT_TO_XFER 0x27
  1188. #define IOPB_BYTE_TO_XFER_0 0x28
  1189. #define IOPB_BYTE_TO_XFER_1 0x29
  1190. #define IOPB_BYTE_TO_XFER_2 0x2A
  1191. #define IOPB_BYTE_TO_XFER_3 0x2B
  1192. #define IOPB_ACC_GRP 0x2C
  1193. #define IOPB_RES_ADDR_2D 0x2D
  1194. #define IOPB_DEV_ID 0x2E
  1195. #define IOPB_RES_ADDR_2F 0x2F
  1196. #define IOPB_SCSI_DATA 0x30
  1197. #define IOPB_RES_ADDR_31 0x31
  1198. #define IOPB_RES_ADDR_32 0x32
  1199. #define IOPB_SCSI_DATA_HSHK 0x33
  1200. #define IOPB_SCSI_CTRL 0x34
  1201. #define IOPB_RES_ADDR_35 0x35
  1202. #define IOPB_RES_ADDR_36 0x36
  1203. #define IOPB_RES_ADDR_37 0x37
  1204. #define IOPB_RAM_BIST 0x38
  1205. #define IOPB_PLL_TEST 0x39
  1206. #define IOPB_PCI_INT_CFG 0x3A
  1207. #define IOPB_RES_ADDR_3B 0x3B
  1208. #define IOPB_RFIFO_CNT 0x3C
  1209. #define IOPB_RES_ADDR_3D 0x3D
  1210. #define IOPB_RES_ADDR_3E 0x3E
  1211. #define IOPB_RES_ADDR_3F 0x3F
  1212. /*
  1213. * Word I/O register address from base of 'iop_base'.
  1214. */
  1215. #define IOPW_CHIP_ID_0 0x00 /* CID0 */
  1216. #define IOPW_CTRL_REG 0x02 /* CC */
  1217. #define IOPW_RAM_ADDR 0x04 /* LA */
  1218. #define IOPW_RAM_DATA 0x06 /* LD */
  1219. #define IOPW_RES_ADDR_08 0x08
  1220. #define IOPW_RISC_CSR 0x0A /* CSR */
  1221. #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
  1222. #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
  1223. #define IOPW_RES_ADDR_10 0x10
  1224. #define IOPW_SEL_MASK 0x12 /* SM */
  1225. #define IOPW_RES_ADDR_14 0x14
  1226. #define IOPW_FLASH_ADDR 0x16 /* FA */
  1227. #define IOPW_RES_ADDR_18 0x18
  1228. #define IOPW_EE_CMD 0x1A /* EC */
  1229. #define IOPW_EE_DATA 0x1C /* ED */
  1230. #define IOPW_SFIFO_CNT 0x1E /* SFC */
  1231. #define IOPW_RES_ADDR_20 0x20
  1232. #define IOPW_Q_BASE 0x22 /* QB */
  1233. #define IOPW_QP 0x24 /* QP */
  1234. #define IOPW_IX 0x26 /* IX */
  1235. #define IOPW_SP 0x28 /* SP */
  1236. #define IOPW_PC 0x2A /* PC */
  1237. #define IOPW_RES_ADDR_2C 0x2C
  1238. #define IOPW_RES_ADDR_2E 0x2E
  1239. #define IOPW_SCSI_DATA 0x30 /* SD */
  1240. #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
  1241. #define IOPW_SCSI_CTRL 0x34 /* SC */
  1242. #define IOPW_HSHK_CFG 0x36 /* HCFG */
  1243. #define IOPW_SXFR_STATUS 0x36 /* SXS */
  1244. #define IOPW_SXFR_CNTL 0x38 /* SXL */
  1245. #define IOPW_SXFR_CNTH 0x3A /* SXH */
  1246. #define IOPW_RES_ADDR_3C 0x3C
  1247. #define IOPW_RFIFO_DATA 0x3E /* RFD */
  1248. /*
  1249. * Doubleword I/O register address from base of 'iop_base'.
  1250. */
  1251. #define IOPDW_RES_ADDR_0 0x00
  1252. #define IOPDW_RAM_DATA 0x04
  1253. #define IOPDW_RES_ADDR_8 0x08
  1254. #define IOPDW_RES_ADDR_C 0x0C
  1255. #define IOPDW_RES_ADDR_10 0x10
  1256. #define IOPDW_COMMA 0x14
  1257. #define IOPDW_COMMB 0x18
  1258. #define IOPDW_RES_ADDR_1C 0x1C
  1259. #define IOPDW_SDMA_ADDR0 0x20
  1260. #define IOPDW_SDMA_ADDR1 0x24
  1261. #define IOPDW_SDMA_COUNT 0x28
  1262. #define IOPDW_SDMA_ERROR 0x2C
  1263. #define IOPDW_RDMA_ADDR0 0x30
  1264. #define IOPDW_RDMA_ADDR1 0x34
  1265. #define IOPDW_RDMA_COUNT 0x38
  1266. #define IOPDW_RDMA_ERROR 0x3C
  1267. #define ADV_CHIP_ID_BYTE 0x25
  1268. #define ADV_CHIP_ID_WORD 0x04C1
  1269. #define ADV_INTR_ENABLE_HOST_INTR 0x01
  1270. #define ADV_INTR_ENABLE_SEL_INTR 0x02
  1271. #define ADV_INTR_ENABLE_DPR_INTR 0x04
  1272. #define ADV_INTR_ENABLE_RTA_INTR 0x08
  1273. #define ADV_INTR_ENABLE_RMA_INTR 0x10
  1274. #define ADV_INTR_ENABLE_RST_INTR 0x20
  1275. #define ADV_INTR_ENABLE_DPE_INTR 0x40
  1276. #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
  1277. #define ADV_INTR_STATUS_INTRA 0x01
  1278. #define ADV_INTR_STATUS_INTRB 0x02
  1279. #define ADV_INTR_STATUS_INTRC 0x04
  1280. #define ADV_RISC_CSR_STOP (0x0000)
  1281. #define ADV_RISC_TEST_COND (0x2000)
  1282. #define ADV_RISC_CSR_RUN (0x4000)
  1283. #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
  1284. #define ADV_CTRL_REG_HOST_INTR 0x0100
  1285. #define ADV_CTRL_REG_SEL_INTR 0x0200
  1286. #define ADV_CTRL_REG_DPR_INTR 0x0400
  1287. #define ADV_CTRL_REG_RTA_INTR 0x0800
  1288. #define ADV_CTRL_REG_RMA_INTR 0x1000
  1289. #define ADV_CTRL_REG_RES_BIT14 0x2000
  1290. #define ADV_CTRL_REG_DPE_INTR 0x4000
  1291. #define ADV_CTRL_REG_POWER_DONE 0x8000
  1292. #define ADV_CTRL_REG_ANY_INTR 0xFF00
  1293. #define ADV_CTRL_REG_CMD_RESET 0x00C6
  1294. #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
  1295. #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
  1296. #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
  1297. #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
  1298. #define ADV_TICKLE_NOP 0x00
  1299. #define ADV_TICKLE_A 0x01
  1300. #define ADV_TICKLE_B 0x02
  1301. #define ADV_TICKLE_C 0x03
  1302. #define AdvIsIntPending(port) \
  1303. (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
  1304. /*
  1305. * SCSI_CFG0 Register bit definitions
  1306. */
  1307. #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
  1308. #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
  1309. #define EVEN_PARITY 0x1000 /* Select Even Parity */
  1310. #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
  1311. #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
  1312. #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
  1313. #define SCAM_EN 0x0080 /* Enable SCAM selection */
  1314. #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
  1315. #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
  1316. #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
  1317. #define OUR_ID 0x000F /* SCSI ID */
  1318. /*
  1319. * SCSI_CFG1 Register bit definitions
  1320. */
  1321. #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
  1322. #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
  1323. #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
  1324. #define FILTER_SEL 0x0C00 /* Filter Period Selection */
  1325. #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
  1326. #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
  1327. #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
  1328. #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
  1329. #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
  1330. #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
  1331. #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
  1332. #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
  1333. #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
  1334. #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
  1335. #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
  1336. /*
  1337. * Addendum for ASC-38C0800 Chip
  1338. *
  1339. * The ASC-38C1600 Chip uses the same definitions except that the
  1340. * bus mode override bits [12:10] have been moved to byte register
  1341. * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
  1342. * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
  1343. * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
  1344. * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
  1345. * and [1:0]. Bits [14], [7:6], [3:2] are unused.
  1346. */
  1347. #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
  1348. #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
  1349. #define HVD 0x1000 /* HVD Device Detect */
  1350. #define LVD 0x0800 /* LVD Device Detect */
  1351. #define SE 0x0400 /* SE Device Detect */
  1352. #define TERM_LVD 0x00C0 /* LVD Termination Bits */
  1353. #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
  1354. #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
  1355. #define TERM_SE 0x0030 /* SE Termination Bits */
  1356. #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
  1357. #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
  1358. #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
  1359. #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
  1360. #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
  1361. #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
  1362. #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
  1363. #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
  1364. #define CABLE_ILLEGAL_A 0x7
  1365. /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
  1366. #define CABLE_ILLEGAL_B 0xB
  1367. /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
  1368. /*
  1369. * MEM_CFG Register bit definitions
  1370. */
  1371. #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
  1372. #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
  1373. #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
  1374. #define RAM_SZ_2KB 0x00 /* 2 KB */
  1375. #define RAM_SZ_4KB 0x04 /* 4 KB */
  1376. #define RAM_SZ_8KB 0x08 /* 8 KB */
  1377. #define RAM_SZ_16KB 0x0C /* 16 KB */
  1378. #define RAM_SZ_32KB 0x10 /* 32 KB */
  1379. #define RAM_SZ_64KB 0x14 /* 64 KB */
  1380. /*
  1381. * DMA_CFG0 Register bit definitions
  1382. *
  1383. * This register is only accessible to the host.
  1384. */
  1385. #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
  1386. #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
  1387. #define FIFO_THRESH_16B 0x00 /* 16 bytes */
  1388. #define FIFO_THRESH_32B 0x20 /* 32 bytes */
  1389. #define FIFO_THRESH_48B 0x30 /* 48 bytes */
  1390. #define FIFO_THRESH_64B 0x40 /* 64 bytes */
  1391. #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
  1392. #define FIFO_THRESH_96B 0x60 /* 96 bytes */
  1393. #define FIFO_THRESH_112B 0x70 /* 112 bytes */
  1394. #define START_CTL 0x0C /* DMA start conditions */
  1395. #define START_CTL_TH 0x00 /* Wait threshold level (default) */
  1396. #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
  1397. #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
  1398. #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
  1399. #define READ_CMD 0x03 /* Memory Read Method */
  1400. #define READ_CMD_MR 0x00 /* Memory Read */
  1401. #define READ_CMD_MRL 0x02 /* Memory Read Long */
  1402. #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
  1403. /*
  1404. * ASC-38C0800 RAM BIST Register bit definitions
  1405. */
  1406. #define RAM_TEST_MODE 0x80
  1407. #define PRE_TEST_MODE 0x40
  1408. #define NORMAL_MODE 0x00
  1409. #define RAM_TEST_DONE 0x10
  1410. #define RAM_TEST_STATUS 0x0F
  1411. #define RAM_TEST_HOST_ERROR 0x08
  1412. #define RAM_TEST_INTRAM_ERROR 0x04
  1413. #define RAM_TEST_RISC_ERROR 0x02
  1414. #define RAM_TEST_SCSI_ERROR 0x01
  1415. #define RAM_TEST_SUCCESS 0x00
  1416. #define PRE_TEST_VALUE 0x05
  1417. #define NORMAL_VALUE 0x00
  1418. /*
  1419. * ASC38C1600 Definitions
  1420. *
  1421. * IOPB_PCI_INT_CFG Bit Field Definitions
  1422. */
  1423. #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
  1424. /*
  1425. * Bit 1 can be set to change the interrupt for the Function to operate in
  1426. * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
  1427. * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
  1428. * mode, otherwise the operating mode is undefined.
  1429. */
  1430. #define TOTEMPOLE 0x02
  1431. /*
  1432. * Bit 0 can be used to change the Int Pin for the Function. The value is
  1433. * 0 by default for both Functions with Function 0 using INT A and Function
  1434. * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
  1435. * INT A is used.
  1436. *
  1437. * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
  1438. * value specified in the PCI Configuration Space.
  1439. */
  1440. #define INTAB 0x01
  1441. /*
  1442. * Adv Library Status Definitions
  1443. */
  1444. #define ADV_TRUE 1
  1445. #define ADV_FALSE 0
  1446. #define ADV_SUCCESS 1
  1447. #define ADV_BUSY 0
  1448. #define ADV_ERROR (-1)
  1449. /*
  1450. * ADV_DVC_VAR 'warn_code' values
  1451. */
  1452. #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
  1453. #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
  1454. #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
  1455. #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
  1456. #define ADV_MAX_TID 15 /* max. target identifier */
  1457. #define ADV_MAX_LUN 7 /* max. logical unit number */
  1458. /*
  1459. * Fixed locations of microcode operating variables.
  1460. */
  1461. #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
  1462. #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
  1463. #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
  1464. #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
  1465. #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
  1466. #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
  1467. #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
  1468. #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
  1469. #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
  1470. #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
  1471. #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
  1472. #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
  1473. #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
  1474. #define ASC_MC_CHIP_TYPE 0x009A
  1475. #define ASC_MC_INTRB_CODE 0x009B
  1476. #define ASC_MC_WDTR_ABLE 0x009C
  1477. #define ASC_MC_SDTR_ABLE 0x009E
  1478. #define ASC_MC_TAGQNG_ABLE 0x00A0
  1479. #define ASC_MC_DISC_ENABLE 0x00A2
  1480. #define ASC_MC_IDLE_CMD_STATUS 0x00A4
  1481. #define ASC_MC_IDLE_CMD 0x00A6
  1482. #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
  1483. #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
  1484. #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
  1485. #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
  1486. #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
  1487. #define ASC_MC_SDTR_DONE 0x00B6
  1488. #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
  1489. #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
  1490. #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
  1491. #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
  1492. #define ASC_MC_WDTR_DONE 0x0124
  1493. #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
  1494. #define ASC_MC_ICQ 0x0160
  1495. #define ASC_MC_IRQ 0x0164
  1496. #define ASC_MC_PPR_ABLE 0x017A
  1497. /*
  1498. * BIOS LRAM variable absolute offsets.
  1499. */
  1500. #define BIOS_CODESEG 0x54
  1501. #define BIOS_CODELEN 0x56
  1502. #define BIOS_SIGNATURE 0x58
  1503. #define BIOS_VERSION 0x5A
  1504. /*
  1505. * Microcode Control Flags
  1506. *
  1507. * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
  1508. * and handled by the microcode.
  1509. */
  1510. #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
  1511. #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
  1512. /*
  1513. * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
  1514. */
  1515. #define HSHK_CFG_WIDE_XFR 0x8000
  1516. #define HSHK_CFG_RATE 0x0F00
  1517. #define HSHK_CFG_OFFSET 0x001F
  1518. #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
  1519. #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
  1520. #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
  1521. #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
  1522. #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
  1523. #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
  1524. #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
  1525. #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
  1526. #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
  1527. #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
  1528. #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
  1529. #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
  1530. #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
  1531. #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
  1532. /*
  1533. * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
  1534. * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
  1535. */
  1536. #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
  1537. #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
  1538. /*
  1539. * All fields here are accessed by the board microcode and need to be
  1540. * little-endian.
  1541. */
  1542. typedef struct adv_carr_t {
  1543. __le32 carr_va; /* Carrier Virtual Address */
  1544. __le32 carr_pa; /* Carrier Physical Address */
  1545. __le32 areq_vpa; /* ADV_SCSI_REQ_Q Virtual or Physical Address */
  1546. /*
  1547. * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
  1548. *
  1549. * next_vpa [3:1] Reserved Bits
  1550. * next_vpa [0] Done Flag set in Response Queue.
  1551. */
  1552. __le32 next_vpa;
  1553. } ADV_CARR_T;
  1554. /*
  1555. * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
  1556. */
  1557. #define ADV_NEXT_VPA_MASK 0xFFFFFFF0
  1558. #define ADV_RQ_DONE 0x00000001
  1559. #define ADV_RQ_GOOD 0x00000002
  1560. #define ADV_CQ_STOPPER 0x00000000
  1561. #define ADV_GET_CARRP(carrp) ((carrp) & ADV_NEXT_VPA_MASK)
  1562. /*
  1563. * Each carrier is 64 bytes, and we need three additional
  1564. * carrier for icq, irq, and the termination carrier.
  1565. */
  1566. #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3)
  1567. #define ADV_CARRIER_BUFSIZE \
  1568. (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T))
  1569. #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
  1570. #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
  1571. #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
  1572. /*
  1573. * Adapter temporary configuration structure
  1574. *
  1575. * This structure can be discarded after initialization. Don't add
  1576. * fields here needed after initialization.
  1577. *
  1578. * Field naming convention:
  1579. *
  1580. * *_enable indicates the field enables or disables a feature. The
  1581. * value of the field is never reset.
  1582. */
  1583. typedef struct adv_dvc_cfg {
  1584. ushort disc_enable; /* enable disconnection */
  1585. uchar chip_version; /* chip version */
  1586. uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
  1587. ushort control_flag; /* Microcode Control Flag */
  1588. ushort mcode_date; /* Microcode date */
  1589. ushort mcode_version; /* Microcode version */
  1590. ushort serial1; /* EEPROM serial number word 1 */
  1591. ushort serial2; /* EEPROM serial number word 2 */
  1592. ushort serial3; /* EEPROM serial number word 3 */
  1593. } ADV_DVC_CFG;
  1594. struct adv_dvc_var;
  1595. struct adv_scsi_req_q;
  1596. typedef struct adv_sg_block {
  1597. uchar reserved1;
  1598. uchar reserved2;
  1599. uchar reserved3;
  1600. uchar sg_cnt; /* Valid entries in block. */
  1601. __le32 sg_ptr; /* Pointer to next sg block. */
  1602. struct {
  1603. __le32 sg_addr; /* SG element address. */
  1604. __le32 sg_count; /* SG element count. */
  1605. } sg_list[NO_OF_SG_PER_BLOCK];
  1606. } ADV_SG_BLOCK;
  1607. /*
  1608. * ADV_SCSI_REQ_Q - microcode request structure
  1609. *
  1610. * All fields in this structure up to byte 60 are used by the microcode.
  1611. * The microcode makes assumptions about the size and ordering of fields
  1612. * in this structure. Do not change the structure definition here without
  1613. * coordinating the change with the microcode.
  1614. *
  1615. * All fields accessed by microcode must be maintained in little_endian
  1616. * order.
  1617. */
  1618. typedef struct adv_scsi_req_q {
  1619. uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
  1620. uchar target_cmd;
  1621. uchar target_id; /* Device target identifier. */
  1622. uchar target_lun; /* Device target logical unit number. */
  1623. __le32 data_addr; /* Data buffer physical address. */
  1624. __le32 data_cnt; /* Data count. Ucode sets to residual. */
  1625. __le32 sense_addr;
  1626. __le32 carr_pa;
  1627. uchar mflag;
  1628. uchar sense_len;
  1629. uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
  1630. uchar scsi_cntl;
  1631. uchar done_status; /* Completion status. */
  1632. uchar scsi_status; /* SCSI status byte. */
  1633. uchar host_status; /* Ucode host status. */
  1634. uchar sg_working_ix;
  1635. uchar cdb[12]; /* SCSI CDB bytes 0-11. */
  1636. __le32 sg_real_addr; /* SG list physical address. */
  1637. __le32 scsiq_rptr;
  1638. uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
  1639. __le32 scsiq_ptr;
  1640. __le32 carr_va;
  1641. /*
  1642. * End of microcode structure - 60 bytes. The rest of the structure
  1643. * is used by the Adv Library and ignored by the microcode.
  1644. */
  1645. u32 srb_tag;
  1646. ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
  1647. } ADV_SCSI_REQ_Q;
  1648. /*
  1649. * The following two structures are used to process Wide Board requests.
  1650. *
  1651. * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
  1652. * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the
  1653. * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points
  1654. * to the Mid-Level SCSI request structure.
  1655. *
  1656. * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
  1657. * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
  1658. * up to 255 scatter-gather elements may be used per request or
  1659. * ADV_SCSI_REQ_Q.
  1660. *
  1661. * Both structures must be 32 byte aligned.
  1662. */
  1663. typedef struct adv_sgblk {
  1664. ADV_SG_BLOCK sg_block; /* Sgblock structure. */
  1665. dma_addr_t sg_addr; /* Physical address */
  1666. struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
  1667. } adv_sgblk_t;
  1668. typedef struct adv_req {
  1669. ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
  1670. uchar align[24]; /* Request structure padding. */
  1671. struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
  1672. dma_addr_t req_addr;
  1673. adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
  1674. } adv_req_t __aligned(32);
  1675. /*
  1676. * Adapter operation variable structure.
  1677. *
  1678. * One structure is required per host adapter.
  1679. *
  1680. * Field naming convention:
  1681. *
  1682. * *_able indicates both whether a feature should be enabled or disabled
  1683. * and whether a device isi capable of the feature. At initialization
  1684. * this field may be set, but later if a device is found to be incapable
  1685. * of the feature, the field is cleared.
  1686. */
  1687. typedef struct adv_dvc_var {
  1688. AdvPortAddr iop_base; /* I/O port address */
  1689. ushort err_code; /* fatal error code */
  1690. ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
  1691. ushort wdtr_able; /* try WDTR for a device */
  1692. ushort sdtr_able; /* try SDTR for a device */
  1693. ushort ultra_able; /* try SDTR Ultra speed for a device */
  1694. ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
  1695. ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
  1696. ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
  1697. ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
  1698. ushort tagqng_able; /* try tagged queuing with a device */
  1699. ushort ppr_able; /* PPR message capable per TID bitmask. */
  1700. uchar max_dvc_qng; /* maximum number of tagged commands per device */
  1701. ushort start_motor; /* start motor command allowed */
  1702. uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
  1703. uchar chip_no; /* should be assigned by caller */
  1704. uchar max_host_qng; /* maximum number of Q'ed command allowed */
  1705. ushort no_scam; /* scam_tolerant of EEPROM */
  1706. struct asc_board *drv_ptr; /* driver pointer to private structure */
  1707. uchar chip_scsi_id; /* chip SCSI target ID */
  1708. uchar chip_type;
  1709. uchar bist_err_code;
  1710. ADV_CARR_T *carrier;
  1711. ADV_CARR_T *carr_freelist; /* Carrier free list. */
  1712. dma_addr_t carrier_addr;
  1713. ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
  1714. ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
  1715. ushort carr_pending_cnt; /* Count of pending carriers. */
  1716. /*
  1717. * Note: The following fields will not be used after initialization. The
  1718. * driver may discard the buffer after initialization is done.
  1719. */
  1720. ADV_DVC_CFG *cfg; /* temporary configuration structure */
  1721. } ADV_DVC_VAR;
  1722. /*
  1723. * Microcode idle loop commands
  1724. */
  1725. #define IDLE_CMD_COMPLETED 0
  1726. #define IDLE_CMD_STOP_CHIP 0x0001
  1727. #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
  1728. #define IDLE_CMD_SEND_INT 0x0004
  1729. #define IDLE_CMD_ABORT 0x0008
  1730. #define IDLE_CMD_DEVICE_RESET 0x0010
  1731. #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
  1732. #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
  1733. #define IDLE_CMD_SCSIREQ 0x0080
  1734. #define IDLE_CMD_STATUS_SUCCESS 0x0001
  1735. #define IDLE_CMD_STATUS_FAILURE 0x0002
  1736. /*
  1737. * AdvSendIdleCmd() flag definitions.
  1738. */
  1739. #define ADV_NOWAIT 0x01
  1740. /*
  1741. * Wait loop time out values.
  1742. */
  1743. #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
  1744. #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
  1745. #define SCSI_MAX_RETRY 10 /* retry count */
  1746. #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
  1747. #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
  1748. #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
  1749. #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
  1750. #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
  1751. /* Read byte from a register. */
  1752. #define AdvReadByteRegister(iop_base, reg_off) \
  1753. (ADV_MEM_READB((iop_base) + (reg_off)))
  1754. /* Write byte to a register. */
  1755. #define AdvWriteByteRegister(iop_base, reg_off, byte) \
  1756. (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
  1757. /* Read word (2 bytes) from a register. */
  1758. #define AdvReadWordRegister(iop_base, reg_off) \
  1759. (ADV_MEM_READW((iop_base) + (reg_off)))
  1760. /* Write word (2 bytes) to a register. */
  1761. #define AdvWriteWordRegister(iop_base, reg_off, word) \
  1762. (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
  1763. /* Write dword (4 bytes) to a register. */
  1764. #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
  1765. (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
  1766. /* Read byte from LRAM. */
  1767. #define AdvReadByteLram(iop_base, addr, byte) \
  1768. do { \
  1769. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1770. (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
  1771. } while (0)
  1772. /* Write byte to LRAM. */
  1773. #define AdvWriteByteLram(iop_base, addr, byte) \
  1774. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1775. ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
  1776. /* Read word (2 bytes) from LRAM. */
  1777. #define AdvReadWordLram(iop_base, addr, word) \
  1778. do { \
  1779. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1780. (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
  1781. } while (0)
  1782. /* Write word (2 bytes) to LRAM. */
  1783. #define AdvWriteWordLram(iop_base, addr, word) \
  1784. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1785. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1786. /* Write little-endian double word (4 bytes) to LRAM */
  1787. /* Because of unspecified C language ordering don't use auto-increment. */
  1788. #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
  1789. ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1790. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1791. cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
  1792. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
  1793. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1794. cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
  1795. /* Read word (2 bytes) from LRAM assuming that the address is already set. */
  1796. #define AdvReadWordAutoIncLram(iop_base) \
  1797. (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
  1798. /* Write word (2 bytes) to LRAM assuming that the address is already set. */
  1799. #define AdvWriteWordAutoIncLram(iop_base, word) \
  1800. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1801. /*
  1802. * Define macro to check for Condor signature.
  1803. *
  1804. * Evaluate to ADV_TRUE if a Condor chip is found the specified port
  1805. * address 'iop_base'. Otherwise evalue to ADV_FALSE.
  1806. */
  1807. #define AdvFindSignature(iop_base) \
  1808. (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
  1809. ADV_CHIP_ID_BYTE) && \
  1810. (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
  1811. ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
  1812. /*
  1813. * Define macro to Return the version number of the chip at 'iop_base'.
  1814. *
  1815. * The second parameter 'bus_type' is currently unused.
  1816. */
  1817. #define AdvGetChipVersion(iop_base, bus_type) \
  1818. AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
  1819. /*
  1820. * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must
  1821. * match the ADV_SCSI_REQ_Q 'srb_tag' field.
  1822. *
  1823. * If the request has not yet been sent to the device it will simply be
  1824. * aborted from RISC memory. If the request is disconnected it will be
  1825. * aborted on reselection by sending an Abort Message to the target ID.
  1826. *
  1827. * Return value:
  1828. * ADV_TRUE(1) - Queue was successfully aborted.
  1829. * ADV_FALSE(0) - Queue was not found on the active queue list.
  1830. */
  1831. #define AdvAbortQueue(asc_dvc, srb_tag) \
  1832. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
  1833. (ADV_DCNT) (srb_tag))
  1834. /*
  1835. * Send a Bus Device Reset Message to the specified target ID.
  1836. *
  1837. * All outstanding commands will be purged if sending the
  1838. * Bus Device Reset Message is successful.
  1839. *
  1840. * Return Value:
  1841. * ADV_TRUE(1) - All requests on the target are purged.
  1842. * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
  1843. * are not purged.
  1844. */
  1845. #define AdvResetDevice(asc_dvc, target_id) \
  1846. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
  1847. (ADV_DCNT) (target_id))
  1848. /*
  1849. * SCSI Wide Type definition.
  1850. */
  1851. #define ADV_SCSI_BIT_ID_TYPE ushort
  1852. /*
  1853. * AdvInitScsiTarget() 'cntl_flag' options.
  1854. */
  1855. #define ADV_SCAN_LUN 0x01
  1856. #define ADV_CAPINFO_NOLUN 0x02
  1857. /*
  1858. * Convert target id to target id bit mask.
  1859. */
  1860. #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
  1861. /*
  1862. * ADV_SCSI_REQ_Q 'done_status' and 'host_status' return values.
  1863. */
  1864. #define QD_NO_STATUS 0x00 /* Request not completed yet. */
  1865. #define QD_NO_ERROR 0x01
  1866. #define QD_ABORTED_BY_HOST 0x02
  1867. #define QD_WITH_ERROR 0x04
  1868. #define QHSTA_NO_ERROR 0x00
  1869. #define QHSTA_M_SEL_TIMEOUT 0x11
  1870. #define QHSTA_M_DATA_OVER_RUN 0x12
  1871. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  1872. #define QHSTA_M_QUEUE_ABORTED 0x15
  1873. #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
  1874. #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
  1875. #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
  1876. #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
  1877. #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
  1878. #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
  1879. #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
  1880. /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
  1881. #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
  1882. #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
  1883. #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
  1884. #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
  1885. #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
  1886. #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
  1887. #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
  1888. #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
  1889. #define QHSTA_M_WTM_TIMEOUT 0x41
  1890. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  1891. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  1892. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  1893. #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
  1894. #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
  1895. #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
  1896. /* Return the address that is aligned at the next doubleword >= to 'addr'. */
  1897. #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
  1898. /*
  1899. * Total contiguous memory needed for driver SG blocks.
  1900. *
  1901. * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
  1902. * number of scatter-gather elements the driver supports in a
  1903. * single request.
  1904. */
  1905. #define ADV_SG_LIST_MAX_BYTE_SIZE \
  1906. (sizeof(ADV_SG_BLOCK) * \
  1907. ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
  1908. /* struct asc_board flags */
  1909. #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
  1910. #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
  1911. #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
  1912. #define ASC_INFO_SIZE 128 /* advansys_info() line size */
  1913. /* Asc Library return codes */
  1914. #define ASC_TRUE 1
  1915. #define ASC_FALSE 0
  1916. #define ASC_NOERROR 1
  1917. #define ASC_BUSY 0
  1918. #define ASC_ERROR (-1)
  1919. /* struct scsi_cmnd function return codes */
  1920. #define STATUS_BYTE(byte) (byte)
  1921. #define MSG_BYTE(byte) ((byte) << 8)
  1922. #define HOST_BYTE(byte) ((byte) << 16)
  1923. #define DRIVER_BYTE(byte) ((byte) << 24)
  1924. #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
  1925. #ifndef ADVANSYS_STATS
  1926. #define ASC_STATS_ADD(shost, counter, count)
  1927. #else /* ADVANSYS_STATS */
  1928. #define ASC_STATS_ADD(shost, counter, count) \
  1929. (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
  1930. #endif /* ADVANSYS_STATS */
  1931. /* If the result wraps when calculating tenths, return 0. */
  1932. #define ASC_TENTHS(num, den) \
  1933. (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
  1934. 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
  1935. /*
  1936. * Display a message to the console.
  1937. */
  1938. #define ASC_PRINT(s) \
  1939. { \
  1940. printk("advansys: "); \
  1941. printk(s); \
  1942. }
  1943. #define ASC_PRINT1(s, a1) \
  1944. { \
  1945. printk("advansys: "); \
  1946. printk((s), (a1)); \
  1947. }
  1948. #define ASC_PRINT2(s, a1, a2) \
  1949. { \
  1950. printk("advansys: "); \
  1951. printk((s), (a1), (a2)); \
  1952. }
  1953. #define ASC_PRINT3(s, a1, a2, a3) \
  1954. { \
  1955. printk("advansys: "); \
  1956. printk((s), (a1), (a2), (a3)); \
  1957. }
  1958. #define ASC_PRINT4(s, a1, a2, a3, a4) \
  1959. { \
  1960. printk("advansys: "); \
  1961. printk((s), (a1), (a2), (a3), (a4)); \
  1962. }
  1963. #ifndef ADVANSYS_DEBUG
  1964. #define ASC_DBG(lvl, s...)
  1965. #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
  1966. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
  1967. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  1968. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
  1969. #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  1970. #define ASC_DBG_PRT_HEX(lvl, name, start, length)
  1971. #define ASC_DBG_PRT_CDB(lvl, cdb, len)
  1972. #define ASC_DBG_PRT_SENSE(lvl, sense, len)
  1973. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
  1974. #else /* ADVANSYS_DEBUG */
  1975. /*
  1976. * Debugging Message Levels:
  1977. * 0: Errors Only
  1978. * 1: High-Level Tracing
  1979. * 2-N: Verbose Tracing
  1980. */
  1981. #define ASC_DBG(lvl, format, arg...) { \
  1982. if (asc_dbglvl >= (lvl)) \
  1983. printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
  1984. __func__ , ## arg); \
  1985. }
  1986. #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
  1987. { \
  1988. if (asc_dbglvl >= (lvl)) { \
  1989. asc_prt_scsi_host(s); \
  1990. } \
  1991. }
  1992. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
  1993. { \
  1994. if (asc_dbglvl >= (lvl)) { \
  1995. asc_prt_asc_scsi_q(scsiqp); \
  1996. } \
  1997. }
  1998. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
  1999. { \
  2000. if (asc_dbglvl >= (lvl)) { \
  2001. asc_prt_asc_qdone_info(qdone); \
  2002. } \
  2003. }
  2004. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
  2005. { \
  2006. if (asc_dbglvl >= (lvl)) { \
  2007. asc_prt_adv_scsi_req_q(scsiqp); \
  2008. } \
  2009. }
  2010. #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
  2011. { \
  2012. if (asc_dbglvl >= (lvl)) { \
  2013. asc_prt_hex((name), (start), (length)); \
  2014. } \
  2015. }
  2016. #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
  2017. ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
  2018. #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
  2019. ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
  2020. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
  2021. ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
  2022. #endif /* ADVANSYS_DEBUG */
  2023. #ifdef ADVANSYS_STATS
  2024. /* Per board statistics structure */
  2025. struct asc_stats {
  2026. /* Driver Entrypoint Statistics */
  2027. unsigned int queuecommand; /* # calls to advansys_queuecommand() */
  2028. unsigned int reset; /* # calls to advansys_eh_bus_reset() */
  2029. unsigned int biosparam; /* # calls to advansys_biosparam() */
  2030. unsigned int interrupt; /* # advansys_interrupt() calls */
  2031. unsigned int callback; /* # calls to asc/adv_isr_callback() */
  2032. unsigned int done; /* # calls to request's scsi_done function */
  2033. unsigned int build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
  2034. unsigned int adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
  2035. unsigned int adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
  2036. /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
  2037. unsigned int exe_noerror; /* # ASC_NOERROR returns. */
  2038. unsigned int exe_busy; /* # ASC_BUSY returns. */
  2039. unsigned int exe_error; /* # ASC_ERROR returns. */
  2040. unsigned int exe_unknown; /* # unknown returns. */
  2041. /* Data Transfer Statistics */
  2042. unsigned int xfer_cnt; /* # I/O requests received */
  2043. unsigned int xfer_elem; /* # scatter-gather elements */
  2044. unsigned int xfer_sect; /* # 512-byte blocks */
  2045. };
  2046. #endif /* ADVANSYS_STATS */
  2047. /*
  2048. * Structure allocated for each board.
  2049. *
  2050. * This structure is allocated by scsi_host_alloc() at the end
  2051. * of the 'Scsi_Host' structure starting at the 'hostdata'
  2052. * field. It is guaranteed to be allocated from DMA-able memory.
  2053. */
  2054. struct asc_board {
  2055. struct device *dev;
  2056. struct Scsi_Host *shost;
  2057. uint flags; /* Board flags */
  2058. unsigned int irq;
  2059. union {
  2060. ASC_DVC_VAR asc_dvc_var; /* Narrow board */
  2061. ADV_DVC_VAR adv_dvc_var; /* Wide board */
  2062. } dvc_var;
  2063. union {
  2064. ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
  2065. ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
  2066. } dvc_cfg;
  2067. ushort asc_n_io_port; /* Number I/O ports. */
  2068. ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
  2069. ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
  2070. ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
  2071. ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
  2072. union {
  2073. ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
  2074. ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
  2075. ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
  2076. ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
  2077. } eep_config;
  2078. /* /proc/scsi/advansys/[0...] */
  2079. #ifdef ADVANSYS_STATS
  2080. struct asc_stats asc_stats; /* Board statistics */
  2081. #endif /* ADVANSYS_STATS */
  2082. /*
  2083. * The following fields are used only for Narrow Boards.
  2084. */
  2085. uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
  2086. /*
  2087. * The following fields are used only for Wide Boards.
  2088. */
  2089. void __iomem *ioremap_addr; /* I/O Memory remap address. */
  2090. ushort ioport; /* I/O Port address. */
  2091. adv_req_t *adv_reqp; /* Request structures. */
  2092. dma_addr_t adv_reqp_addr;
  2093. size_t adv_reqp_size;
  2094. struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */
  2095. ushort bios_signature; /* BIOS Signature. */
  2096. ushort bios_version; /* BIOS Version. */
  2097. ushort bios_codeseg; /* BIOS Code Segment. */
  2098. ushort bios_codelen; /* BIOS Code Segment Length. */
  2099. };
  2100. #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
  2101. dvc_var.asc_dvc_var)
  2102. #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
  2103. dvc_var.adv_dvc_var)
  2104. #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
  2105. #ifdef ADVANSYS_DEBUG
  2106. static int asc_dbglvl = 3;
  2107. /*
  2108. * asc_prt_asc_dvc_var()
  2109. */
  2110. static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
  2111. {
  2112. printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2113. printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
  2114. "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
  2115. printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
  2116. (unsigned)h->init_sdtr);
  2117. printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
  2118. "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
  2119. (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
  2120. (unsigned)h->chip_no);
  2121. printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
  2122. "%u,\n", (unsigned)h->queue_full_or_busy,
  2123. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2124. printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
  2125. "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
  2126. (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
  2127. (unsigned)h->in_critical_cnt);
  2128. printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
  2129. "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
  2130. (unsigned)h->init_state, (unsigned)h->no_scam,
  2131. (unsigned)h->pci_fix_asyn_xfer);
  2132. printk(" cfg 0x%lx\n", (ulong)h->cfg);
  2133. }
  2134. /*
  2135. * asc_prt_asc_dvc_cfg()
  2136. */
  2137. static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
  2138. {
  2139. printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2140. printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
  2141. h->can_tagged_qng, h->cmd_qng_enabled);
  2142. printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
  2143. h->disc_enable, h->sdtr_enable);
  2144. printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
  2145. "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
  2146. h->isa_dma_channel, h->chip_version);
  2147. printk(" mcode_date 0x%x, mcode_version %d\n",
  2148. h->mcode_date, h->mcode_version);
  2149. }
  2150. /*
  2151. * asc_prt_adv_dvc_var()
  2152. *
  2153. * Display an ADV_DVC_VAR structure.
  2154. */
  2155. static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
  2156. {
  2157. printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2158. printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
  2159. (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
  2160. printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
  2161. (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
  2162. printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
  2163. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2164. printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n",
  2165. (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
  2166. h->carr_freelist);
  2167. printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp);
  2168. printk(" no_scam 0x%x, tagqng_able 0x%x\n",
  2169. (unsigned)h->no_scam, (unsigned)h->tagqng_able);
  2170. printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
  2171. (unsigned)h->chip_scsi_id, (ulong)h->cfg);
  2172. }
  2173. /*
  2174. * asc_prt_adv_dvc_cfg()
  2175. *
  2176. * Display an ADV_DVC_CFG structure.
  2177. */
  2178. static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
  2179. {
  2180. printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2181. printk(" disc_enable 0x%x, termination 0x%x\n",
  2182. h->disc_enable, h->termination);
  2183. printk(" chip_version 0x%x, mcode_date 0x%x\n",
  2184. h->chip_version, h->mcode_date);
  2185. printk(" mcode_version 0x%x, control_flag 0x%x\n",
  2186. h->mcode_version, h->control_flag);
  2187. }
  2188. /*
  2189. * asc_prt_scsi_host()
  2190. */
  2191. static void asc_prt_scsi_host(struct Scsi_Host *s)
  2192. {
  2193. struct asc_board *boardp = shost_priv(s);
  2194. printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
  2195. printk(" host_busy %u, host_no %d,\n",
  2196. atomic_read(&s->host_busy), s->host_no);
  2197. printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
  2198. (ulong)s->base, (ulong)s->io_port, boardp->irq);
  2199. printk(" dma_channel %d, this_id %d, can_queue %d,\n",
  2200. s->dma_channel, s->this_id, s->can_queue);
  2201. printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
  2202. s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
  2203. if (ASC_NARROW_BOARD(boardp)) {
  2204. asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
  2205. asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
  2206. } else {
  2207. asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
  2208. asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
  2209. }
  2210. }
  2211. /*
  2212. * asc_prt_hex()
  2213. *
  2214. * Print hexadecimal output in 4 byte groupings 32 bytes
  2215. * or 8 double-words per line.
  2216. */
  2217. static void asc_prt_hex(char *f, uchar *s, int l)
  2218. {
  2219. int i;
  2220. int j;
  2221. int k;
  2222. int m;
  2223. printk("%s: (%d bytes)\n", f, l);
  2224. for (i = 0; i < l; i += 32) {
  2225. /* Display a maximum of 8 double-words per line. */
  2226. if ((k = (l - i) / 4) >= 8) {
  2227. k = 8;
  2228. m = 0;
  2229. } else {
  2230. m = (l - i) % 4;
  2231. }
  2232. for (j = 0; j < k; j++) {
  2233. printk(" %2.2X%2.2X%2.2X%2.2X",
  2234. (unsigned)s[i + (j * 4)],
  2235. (unsigned)s[i + (j * 4) + 1],
  2236. (unsigned)s[i + (j * 4) + 2],
  2237. (unsigned)s[i + (j * 4) + 3]);
  2238. }
  2239. switch (m) {
  2240. case 0:
  2241. default:
  2242. break;
  2243. case 1:
  2244. printk(" %2.2X", (unsigned)s[i + (j * 4)]);
  2245. break;
  2246. case 2:
  2247. printk(" %2.2X%2.2X",
  2248. (unsigned)s[i + (j * 4)],
  2249. (unsigned)s[i + (j * 4) + 1]);
  2250. break;
  2251. case 3:
  2252. printk(" %2.2X%2.2X%2.2X",
  2253. (unsigned)s[i + (j * 4) + 1],
  2254. (unsigned)s[i + (j * 4) + 2],
  2255. (unsigned)s[i + (j * 4) + 3]);
  2256. break;
  2257. }
  2258. printk("\n");
  2259. }
  2260. }
  2261. /*
  2262. * asc_prt_asc_scsi_q()
  2263. */
  2264. static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
  2265. {
  2266. ASC_SG_HEAD *sgp;
  2267. int i;
  2268. printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
  2269. printk
  2270. (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n",
  2271. q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag,
  2272. q->q2.tag_code);
  2273. printk
  2274. (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2275. (ulong)le32_to_cpu(q->q1.data_addr),
  2276. (ulong)le32_to_cpu(q->q1.data_cnt),
  2277. (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
  2278. printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
  2279. (ulong)q->cdbptr, q->q2.cdb_len,
  2280. (ulong)q->sg_head, q->q1.sg_queue_cnt);
  2281. if (q->sg_head) {
  2282. sgp = q->sg_head;
  2283. printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
  2284. printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
  2285. sgp->queue_cnt);
  2286. for (i = 0; i < sgp->entry_cnt; i++) {
  2287. printk(" [%u]: addr 0x%lx, bytes %lu\n",
  2288. i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
  2289. (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
  2290. }
  2291. }
  2292. }
  2293. /*
  2294. * asc_prt_asc_qdone_info()
  2295. */
  2296. static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
  2297. {
  2298. printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
  2299. printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n",
  2300. q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len,
  2301. q->d2.tag_code);
  2302. printk
  2303. (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
  2304. q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
  2305. }
  2306. /*
  2307. * asc_prt_adv_sgblock()
  2308. *
  2309. * Display an ADV_SG_BLOCK structure.
  2310. */
  2311. static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
  2312. {
  2313. int i;
  2314. printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
  2315. (ulong)b, sgblockno);
  2316. printk(" sg_cnt %u, sg_ptr 0x%x\n",
  2317. b->sg_cnt, (u32)le32_to_cpu(b->sg_ptr));
  2318. BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
  2319. if (b->sg_ptr != 0)
  2320. BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
  2321. for (i = 0; i < b->sg_cnt; i++) {
  2322. printk(" [%u]: sg_addr 0x%x, sg_count 0x%x\n",
  2323. i, (u32)le32_to_cpu(b->sg_list[i].sg_addr),
  2324. (u32)le32_to_cpu(b->sg_list[i].sg_count));
  2325. }
  2326. }
  2327. /*
  2328. * asc_prt_adv_scsi_req_q()
  2329. *
  2330. * Display an ADV_SCSI_REQ_Q structure.
  2331. */
  2332. static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
  2333. {
  2334. int sg_blk_cnt;
  2335. struct adv_sg_block *sg_ptr;
  2336. adv_sgblk_t *sgblkp;
  2337. printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
  2338. printk(" target_id %u, target_lun %u, srb_tag 0x%x\n",
  2339. q->target_id, q->target_lun, q->srb_tag);
  2340. printk(" cntl 0x%x, data_addr 0x%lx\n",
  2341. q->cntl, (ulong)le32_to_cpu(q->data_addr));
  2342. printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2343. (ulong)le32_to_cpu(q->data_cnt),
  2344. (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
  2345. printk
  2346. (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
  2347. q->cdb_len, q->done_status, q->host_status, q->scsi_status);
  2348. printk(" sg_working_ix 0x%x, target_cmd %u\n",
  2349. q->sg_working_ix, q->target_cmd);
  2350. printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
  2351. (ulong)le32_to_cpu(q->scsiq_rptr),
  2352. (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
  2353. /* Display the request's ADV_SG_BLOCK structures. */
  2354. if (q->sg_list_ptr != NULL) {
  2355. sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block);
  2356. sg_blk_cnt = 0;
  2357. while (sgblkp) {
  2358. sg_ptr = &sgblkp->sg_block;
  2359. asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
  2360. if (sg_ptr->sg_ptr == 0) {
  2361. break;
  2362. }
  2363. sgblkp = sgblkp->next_sgblkp;
  2364. sg_blk_cnt++;
  2365. }
  2366. }
  2367. }
  2368. #endif /* ADVANSYS_DEBUG */
  2369. /*
  2370. * advansys_info()
  2371. *
  2372. * Return suitable for printing on the console with the argument
  2373. * adapter's configuration information.
  2374. *
  2375. * Note: The information line should not exceed ASC_INFO_SIZE bytes,
  2376. * otherwise the static 'info' array will be overrun.
  2377. */
  2378. static const char *advansys_info(struct Scsi_Host *shost)
  2379. {
  2380. static char info[ASC_INFO_SIZE];
  2381. struct asc_board *boardp = shost_priv(shost);
  2382. ASC_DVC_VAR *asc_dvc_varp;
  2383. ADV_DVC_VAR *adv_dvc_varp;
  2384. char *busname;
  2385. char *widename = NULL;
  2386. if (ASC_NARROW_BOARD(boardp)) {
  2387. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2388. ASC_DBG(1, "begin\n");
  2389. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2390. if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
  2391. ASC_IS_ISAPNP) {
  2392. busname = "ISA PnP";
  2393. } else {
  2394. busname = "ISA";
  2395. }
  2396. sprintf(info,
  2397. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
  2398. ASC_VERSION, busname,
  2399. (ulong)shost->io_port,
  2400. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2401. boardp->irq, shost->dma_channel);
  2402. } else {
  2403. if (asc_dvc_varp->bus_type & ASC_IS_VL) {
  2404. busname = "VL";
  2405. } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
  2406. busname = "EISA";
  2407. } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
  2408. if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
  2409. == ASC_IS_PCI_ULTRA) {
  2410. busname = "PCI Ultra";
  2411. } else {
  2412. busname = "PCI";
  2413. }
  2414. } else {
  2415. busname = "?";
  2416. shost_printk(KERN_ERR, shost, "unknown bus "
  2417. "type %d\n", asc_dvc_varp->bus_type);
  2418. }
  2419. sprintf(info,
  2420. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
  2421. ASC_VERSION, busname, (ulong)shost->io_port,
  2422. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2423. boardp->irq);
  2424. }
  2425. } else {
  2426. /*
  2427. * Wide Adapter Information
  2428. *
  2429. * Memory-mapped I/O is used instead of I/O space to access
  2430. * the adapter, but display the I/O Port range. The Memory
  2431. * I/O address is displayed through the driver /proc file.
  2432. */
  2433. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2434. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2435. widename = "Ultra-Wide";
  2436. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2437. widename = "Ultra2-Wide";
  2438. } else {
  2439. widename = "Ultra3-Wide";
  2440. }
  2441. sprintf(info,
  2442. "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
  2443. ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
  2444. (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
  2445. }
  2446. BUG_ON(strlen(info) >= ASC_INFO_SIZE);
  2447. ASC_DBG(1, "end\n");
  2448. return info;
  2449. }
  2450. #ifdef CONFIG_PROC_FS
  2451. /*
  2452. * asc_prt_board_devices()
  2453. *
  2454. * Print driver information for devices attached to the board.
  2455. */
  2456. static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
  2457. {
  2458. struct asc_board *boardp = shost_priv(shost);
  2459. int chip_scsi_id;
  2460. int i;
  2461. seq_printf(m,
  2462. "\nDevice Information for AdvanSys SCSI Host %d:\n",
  2463. shost->host_no);
  2464. if (ASC_NARROW_BOARD(boardp)) {
  2465. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2466. } else {
  2467. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2468. }
  2469. seq_puts(m, "Target IDs Detected:");
  2470. for (i = 0; i <= ADV_MAX_TID; i++) {
  2471. if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
  2472. seq_printf(m, " %X,", i);
  2473. }
  2474. seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
  2475. }
  2476. /*
  2477. * Display Wide Board BIOS Information.
  2478. */
  2479. static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
  2480. {
  2481. struct asc_board *boardp = shost_priv(shost);
  2482. ushort major, minor, letter;
  2483. seq_puts(m, "\nROM BIOS Version: ");
  2484. /*
  2485. * If the BIOS saved a valid signature, then fill in
  2486. * the BIOS code segment base address.
  2487. */
  2488. if (boardp->bios_signature != 0x55AA) {
  2489. seq_puts(m, "Disabled or Pre-3.1\n"
  2490. "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n"
  2491. "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
  2492. } else {
  2493. major = (boardp->bios_version >> 12) & 0xF;
  2494. minor = (boardp->bios_version >> 8) & 0xF;
  2495. letter = (boardp->bios_version & 0xFF);
  2496. seq_printf(m, "%d.%d%c\n",
  2497. major, minor,
  2498. letter >= 26 ? '?' : letter + 'A');
  2499. /*
  2500. * Current available ROM BIOS release is 3.1I for UW
  2501. * and 3.2I for U2W. This code doesn't differentiate
  2502. * UW and U2W boards.
  2503. */
  2504. if (major < 3 || (major <= 3 && minor < 1) ||
  2505. (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
  2506. seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n"
  2507. "ftp://ftp.connectcom.net/pub\n");
  2508. }
  2509. }
  2510. }
  2511. /*
  2512. * Add serial number to information bar if signature AAh
  2513. * is found in at bit 15-9 (7 bits) of word 1.
  2514. *
  2515. * Serial Number consists fo 12 alpha-numeric digits.
  2516. *
  2517. * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
  2518. * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
  2519. * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
  2520. * 5 - Product revision (A-J) Word0: " "
  2521. *
  2522. * Signature Word1: 15-9 (7 bits)
  2523. * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
  2524. * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
  2525. *
  2526. * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
  2527. *
  2528. * Note 1: Only production cards will have a serial number.
  2529. *
  2530. * Note 2: Signature is most significant 7 bits (0xFE).
  2531. *
  2532. * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
  2533. */
  2534. static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
  2535. {
  2536. ushort w, num;
  2537. if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
  2538. return ASC_FALSE;
  2539. } else {
  2540. /*
  2541. * First word - 6 digits.
  2542. */
  2543. w = serialnum[0];
  2544. /* Product type - 1st digit. */
  2545. if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
  2546. /* Product type is P=Prototype */
  2547. *cp += 0x8;
  2548. }
  2549. cp++;
  2550. /* Manufacturing location - 2nd digit. */
  2551. *cp++ = 'A' + ((w & 0x1C00) >> 10);
  2552. /* Product ID - 3rd, 4th digits. */
  2553. num = w & 0x3FF;
  2554. *cp++ = '0' + (num / 100);
  2555. num %= 100;
  2556. *cp++ = '0' + (num / 10);
  2557. /* Product revision - 5th digit. */
  2558. *cp++ = 'A' + (num % 10);
  2559. /*
  2560. * Second word
  2561. */
  2562. w = serialnum[1];
  2563. /*
  2564. * Year - 6th digit.
  2565. *
  2566. * If bit 15 of third word is set, then the
  2567. * last digit of the year is greater than 7.
  2568. */
  2569. if (serialnum[2] & 0x8000) {
  2570. *cp++ = '8' + ((w & 0x1C0) >> 6);
  2571. } else {
  2572. *cp++ = '0' + ((w & 0x1C0) >> 6);
  2573. }
  2574. /* Week of year - 7th, 8th digits. */
  2575. num = w & 0x003F;
  2576. *cp++ = '0' + num / 10;
  2577. num %= 10;
  2578. *cp++ = '0' + num;
  2579. /*
  2580. * Third word
  2581. */
  2582. w = serialnum[2] & 0x7FFF;
  2583. /* Serial number - 9th digit. */
  2584. *cp++ = 'A' + (w / 1000);
  2585. /* 10th, 11th, 12th digits. */
  2586. num = w % 1000;
  2587. *cp++ = '0' + num / 100;
  2588. num %= 100;
  2589. *cp++ = '0' + num / 10;
  2590. num %= 10;
  2591. *cp++ = '0' + num;
  2592. *cp = '\0'; /* Null Terminate the string. */
  2593. return ASC_TRUE;
  2594. }
  2595. }
  2596. /*
  2597. * asc_prt_asc_board_eeprom()
  2598. *
  2599. * Print board EEPROM configuration.
  2600. */
  2601. static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2602. {
  2603. struct asc_board *boardp = shost_priv(shost);
  2604. ASC_DVC_VAR *asc_dvc_varp;
  2605. ASCEEP_CONFIG *ep;
  2606. int i;
  2607. #ifdef CONFIG_ISA
  2608. int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
  2609. #endif /* CONFIG_ISA */
  2610. uchar serialstr[13];
  2611. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2612. ep = &boardp->eep_config.asc_eep;
  2613. seq_printf(m,
  2614. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2615. shost->host_no);
  2616. if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
  2617. == ASC_TRUE)
  2618. seq_printf(m, " Serial Number: %s\n", serialstr);
  2619. else if (ep->adapter_info[5] == 0xBB)
  2620. seq_puts(m,
  2621. " Default Settings Used for EEPROM-less Adapter.\n");
  2622. else
  2623. seq_puts(m, " Serial Number Signature Not Present.\n");
  2624. seq_printf(m,
  2625. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2626. ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
  2627. ep->max_tag_qng);
  2628. seq_printf(m,
  2629. " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
  2630. seq_puts(m, " Target ID: ");
  2631. for (i = 0; i <= ASC_MAX_TID; i++)
  2632. seq_printf(m, " %d", i);
  2633. seq_puts(m, "\n Disconnects: ");
  2634. for (i = 0; i <= ASC_MAX_TID; i++)
  2635. seq_printf(m, " %c",
  2636. (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2637. seq_puts(m, "\n Command Queuing: ");
  2638. for (i = 0; i <= ASC_MAX_TID; i++)
  2639. seq_printf(m, " %c",
  2640. (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2641. seq_puts(m, "\n Start Motor: ");
  2642. for (i = 0; i <= ASC_MAX_TID; i++)
  2643. seq_printf(m, " %c",
  2644. (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2645. seq_puts(m, "\n Synchronous Transfer:");
  2646. for (i = 0; i <= ASC_MAX_TID; i++)
  2647. seq_printf(m, " %c",
  2648. (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2649. seq_putc(m, '\n');
  2650. #ifdef CONFIG_ISA
  2651. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2652. seq_printf(m,
  2653. " Host ISA DMA speed: %d MB/S\n",
  2654. isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
  2655. }
  2656. #endif /* CONFIG_ISA */
  2657. }
  2658. /*
  2659. * asc_prt_adv_board_eeprom()
  2660. *
  2661. * Print board EEPROM configuration.
  2662. */
  2663. static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2664. {
  2665. struct asc_board *boardp = shost_priv(shost);
  2666. ADV_DVC_VAR *adv_dvc_varp;
  2667. int i;
  2668. char *termstr;
  2669. uchar serialstr[13];
  2670. ADVEEP_3550_CONFIG *ep_3550 = NULL;
  2671. ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
  2672. ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
  2673. ushort word;
  2674. ushort *wordp;
  2675. ushort sdtr_speed = 0;
  2676. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2677. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2678. ep_3550 = &boardp->eep_config.adv_3550_eep;
  2679. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2680. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  2681. } else {
  2682. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  2683. }
  2684. seq_printf(m,
  2685. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2686. shost->host_no);
  2687. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2688. wordp = &ep_3550->serial_number_word1;
  2689. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2690. wordp = &ep_38C0800->serial_number_word1;
  2691. } else {
  2692. wordp = &ep_38C1600->serial_number_word1;
  2693. }
  2694. if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
  2695. seq_printf(m, " Serial Number: %s\n", serialstr);
  2696. else
  2697. seq_puts(m, " Serial Number Signature Not Present.\n");
  2698. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2699. seq_printf(m,
  2700. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2701. ep_3550->adapter_scsi_id,
  2702. ep_3550->max_host_qng, ep_3550->max_dvc_qng);
  2703. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2704. seq_printf(m,
  2705. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2706. ep_38C0800->adapter_scsi_id,
  2707. ep_38C0800->max_host_qng,
  2708. ep_38C0800->max_dvc_qng);
  2709. else
  2710. seq_printf(m,
  2711. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2712. ep_38C1600->adapter_scsi_id,
  2713. ep_38C1600->max_host_qng,
  2714. ep_38C1600->max_dvc_qng);
  2715. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2716. word = ep_3550->termination;
  2717. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2718. word = ep_38C0800->termination_lvd;
  2719. } else {
  2720. word = ep_38C1600->termination_lvd;
  2721. }
  2722. switch (word) {
  2723. case 1:
  2724. termstr = "Low Off/High Off";
  2725. break;
  2726. case 2:
  2727. termstr = "Low Off/High On";
  2728. break;
  2729. case 3:
  2730. termstr = "Low On/High On";
  2731. break;
  2732. default:
  2733. case 0:
  2734. termstr = "Automatic";
  2735. break;
  2736. }
  2737. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2738. seq_printf(m,
  2739. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2740. ep_3550->termination, termstr,
  2741. ep_3550->bios_ctrl);
  2742. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2743. seq_printf(m,
  2744. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2745. ep_38C0800->termination_lvd, termstr,
  2746. ep_38C0800->bios_ctrl);
  2747. else
  2748. seq_printf(m,
  2749. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2750. ep_38C1600->termination_lvd, termstr,
  2751. ep_38C1600->bios_ctrl);
  2752. seq_puts(m, " Target ID: ");
  2753. for (i = 0; i <= ADV_MAX_TID; i++)
  2754. seq_printf(m, " %X", i);
  2755. seq_putc(m, '\n');
  2756. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2757. word = ep_3550->disc_enable;
  2758. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2759. word = ep_38C0800->disc_enable;
  2760. } else {
  2761. word = ep_38C1600->disc_enable;
  2762. }
  2763. seq_puts(m, " Disconnects: ");
  2764. for (i = 0; i <= ADV_MAX_TID; i++)
  2765. seq_printf(m, " %c",
  2766. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2767. seq_putc(m, '\n');
  2768. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2769. word = ep_3550->tagqng_able;
  2770. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2771. word = ep_38C0800->tagqng_able;
  2772. } else {
  2773. word = ep_38C1600->tagqng_able;
  2774. }
  2775. seq_puts(m, " Command Queuing: ");
  2776. for (i = 0; i <= ADV_MAX_TID; i++)
  2777. seq_printf(m, " %c",
  2778. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2779. seq_putc(m, '\n');
  2780. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2781. word = ep_3550->start_motor;
  2782. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2783. word = ep_38C0800->start_motor;
  2784. } else {
  2785. word = ep_38C1600->start_motor;
  2786. }
  2787. seq_puts(m, " Start Motor: ");
  2788. for (i = 0; i <= ADV_MAX_TID; i++)
  2789. seq_printf(m, " %c",
  2790. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2791. seq_putc(m, '\n');
  2792. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2793. seq_puts(m, " Synchronous Transfer:");
  2794. for (i = 0; i <= ADV_MAX_TID; i++)
  2795. seq_printf(m, " %c",
  2796. (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
  2797. 'Y' : 'N');
  2798. seq_putc(m, '\n');
  2799. }
  2800. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2801. seq_puts(m, " Ultra Transfer: ");
  2802. for (i = 0; i <= ADV_MAX_TID; i++)
  2803. seq_printf(m, " %c",
  2804. (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
  2805. ? 'Y' : 'N');
  2806. seq_putc(m, '\n');
  2807. }
  2808. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2809. word = ep_3550->wdtr_able;
  2810. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2811. word = ep_38C0800->wdtr_able;
  2812. } else {
  2813. word = ep_38C1600->wdtr_able;
  2814. }
  2815. seq_puts(m, " Wide Transfer: ");
  2816. for (i = 0; i <= ADV_MAX_TID; i++)
  2817. seq_printf(m, " %c",
  2818. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2819. seq_putc(m, '\n');
  2820. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
  2821. adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
  2822. seq_puts(m, " Synchronous Transfer Speed (Mhz):\n ");
  2823. for (i = 0; i <= ADV_MAX_TID; i++) {
  2824. char *speed_str;
  2825. if (i == 0) {
  2826. sdtr_speed = adv_dvc_varp->sdtr_speed1;
  2827. } else if (i == 4) {
  2828. sdtr_speed = adv_dvc_varp->sdtr_speed2;
  2829. } else if (i == 8) {
  2830. sdtr_speed = adv_dvc_varp->sdtr_speed3;
  2831. } else if (i == 12) {
  2832. sdtr_speed = adv_dvc_varp->sdtr_speed4;
  2833. }
  2834. switch (sdtr_speed & ADV_MAX_TID) {
  2835. case 0:
  2836. speed_str = "Off";
  2837. break;
  2838. case 1:
  2839. speed_str = " 5";
  2840. break;
  2841. case 2:
  2842. speed_str = " 10";
  2843. break;
  2844. case 3:
  2845. speed_str = " 20";
  2846. break;
  2847. case 4:
  2848. speed_str = " 40";
  2849. break;
  2850. case 5:
  2851. speed_str = " 80";
  2852. break;
  2853. default:
  2854. speed_str = "Unk";
  2855. break;
  2856. }
  2857. seq_printf(m, "%X:%s ", i, speed_str);
  2858. if (i == 7)
  2859. seq_puts(m, "\n ");
  2860. sdtr_speed >>= 4;
  2861. }
  2862. seq_putc(m, '\n');
  2863. }
  2864. }
  2865. /*
  2866. * asc_prt_driver_conf()
  2867. */
  2868. static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
  2869. {
  2870. struct asc_board *boardp = shost_priv(shost);
  2871. int chip_scsi_id;
  2872. seq_printf(m,
  2873. "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
  2874. shost->host_no);
  2875. seq_printf(m,
  2876. " host_busy %u, max_id %u, max_lun %llu, max_channel %u\n",
  2877. atomic_read(&shost->host_busy), shost->max_id,
  2878. shost->max_lun, shost->max_channel);
  2879. seq_printf(m,
  2880. " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
  2881. shost->unique_id, shost->can_queue, shost->this_id,
  2882. shost->sg_tablesize, shost->cmd_per_lun);
  2883. seq_printf(m,
  2884. " unchecked_isa_dma %d, use_clustering %d\n",
  2885. shost->unchecked_isa_dma, shost->use_clustering);
  2886. seq_printf(m,
  2887. " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
  2888. boardp->flags, shost->last_reset, jiffies,
  2889. boardp->asc_n_io_port);
  2890. seq_printf(m, " io_port 0x%lx\n", shost->io_port);
  2891. if (ASC_NARROW_BOARD(boardp)) {
  2892. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2893. } else {
  2894. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2895. }
  2896. }
  2897. /*
  2898. * asc_prt_asc_board_info()
  2899. *
  2900. * Print dynamic board configuration information.
  2901. */
  2902. static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
  2903. {
  2904. struct asc_board *boardp = shost_priv(shost);
  2905. int chip_scsi_id;
  2906. ASC_DVC_VAR *v;
  2907. ASC_DVC_CFG *c;
  2908. int i;
  2909. int renegotiate = 0;
  2910. v = &boardp->dvc_var.asc_dvc_var;
  2911. c = &boardp->dvc_cfg.asc_dvc_cfg;
  2912. chip_scsi_id = c->chip_scsi_id;
  2913. seq_printf(m,
  2914. "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  2915. shost->host_no);
  2916. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  2917. "mcode_version 0x%x, err_code %u\n",
  2918. c->chip_version, c->mcode_date, c->mcode_version,
  2919. v->err_code);
  2920. /* Current number of commands waiting for the host. */
  2921. seq_printf(m,
  2922. " Total Command Pending: %d\n", v->cur_total_qng);
  2923. seq_puts(m, " Command Queuing:");
  2924. for (i = 0; i <= ASC_MAX_TID; i++) {
  2925. if ((chip_scsi_id == i) ||
  2926. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2927. continue;
  2928. }
  2929. seq_printf(m, " %X:%c",
  2930. i,
  2931. (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2932. }
  2933. /* Current number of commands waiting for a device. */
  2934. seq_puts(m, "\n Command Queue Pending:");
  2935. for (i = 0; i <= ASC_MAX_TID; i++) {
  2936. if ((chip_scsi_id == i) ||
  2937. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2938. continue;
  2939. }
  2940. seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
  2941. }
  2942. /* Current limit on number of commands that can be sent to a device. */
  2943. seq_puts(m, "\n Command Queue Limit:");
  2944. for (i = 0; i <= ASC_MAX_TID; i++) {
  2945. if ((chip_scsi_id == i) ||
  2946. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2947. continue;
  2948. }
  2949. seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
  2950. }
  2951. /* Indicate whether the device has returned queue full status. */
  2952. seq_puts(m, "\n Command Queue Full:");
  2953. for (i = 0; i <= ASC_MAX_TID; i++) {
  2954. if ((chip_scsi_id == i) ||
  2955. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2956. continue;
  2957. }
  2958. if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
  2959. seq_printf(m, " %X:Y-%d",
  2960. i, boardp->queue_full_cnt[i]);
  2961. else
  2962. seq_printf(m, " %X:N", i);
  2963. }
  2964. seq_puts(m, "\n Synchronous Transfer:");
  2965. for (i = 0; i <= ASC_MAX_TID; i++) {
  2966. if ((chip_scsi_id == i) ||
  2967. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2968. continue;
  2969. }
  2970. seq_printf(m, " %X:%c",
  2971. i,
  2972. (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2973. }
  2974. seq_putc(m, '\n');
  2975. for (i = 0; i <= ASC_MAX_TID; i++) {
  2976. uchar syn_period_ix;
  2977. if ((chip_scsi_id == i) ||
  2978. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  2979. ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2980. continue;
  2981. }
  2982. seq_printf(m, " %X:", i);
  2983. if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
  2984. seq_puts(m, " Asynchronous");
  2985. } else {
  2986. syn_period_ix =
  2987. (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
  2988. 1);
  2989. seq_printf(m,
  2990. " Transfer Period Factor: %d (%d.%d Mhz),",
  2991. v->sdtr_period_tbl[syn_period_ix],
  2992. 250 / v->sdtr_period_tbl[syn_period_ix],
  2993. ASC_TENTHS(250,
  2994. v->sdtr_period_tbl[syn_period_ix]));
  2995. seq_printf(m, " REQ/ACK Offset: %d",
  2996. boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
  2997. }
  2998. if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  2999. seq_puts(m, "*\n");
  3000. renegotiate = 1;
  3001. } else {
  3002. seq_putc(m, '\n');
  3003. }
  3004. }
  3005. if (renegotiate) {
  3006. seq_puts(m, " * = Re-negotiation pending before next command.\n");
  3007. }
  3008. }
  3009. /*
  3010. * asc_prt_adv_board_info()
  3011. *
  3012. * Print dynamic board configuration information.
  3013. */
  3014. static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
  3015. {
  3016. struct asc_board *boardp = shost_priv(shost);
  3017. int i;
  3018. ADV_DVC_VAR *v;
  3019. ADV_DVC_CFG *c;
  3020. AdvPortAddr iop_base;
  3021. ushort chip_scsi_id;
  3022. ushort lramword;
  3023. uchar lrambyte;
  3024. ushort tagqng_able;
  3025. ushort sdtr_able, wdtr_able;
  3026. ushort wdtr_done, sdtr_done;
  3027. ushort period = 0;
  3028. int renegotiate = 0;
  3029. v = &boardp->dvc_var.adv_dvc_var;
  3030. c = &boardp->dvc_cfg.adv_dvc_cfg;
  3031. iop_base = v->iop_base;
  3032. chip_scsi_id = v->chip_scsi_id;
  3033. seq_printf(m,
  3034. "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3035. shost->host_no);
  3036. seq_printf(m,
  3037. " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
  3038. (unsigned long)v->iop_base,
  3039. AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
  3040. v->err_code);
  3041. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  3042. "mcode_version 0x%x\n", c->chip_version,
  3043. c->mcode_date, c->mcode_version);
  3044. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3045. seq_puts(m, " Queuing Enabled:");
  3046. for (i = 0; i <= ADV_MAX_TID; i++) {
  3047. if ((chip_scsi_id == i) ||
  3048. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3049. continue;
  3050. }
  3051. seq_printf(m, " %X:%c",
  3052. i,
  3053. (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3054. }
  3055. seq_puts(m, "\n Queue Limit:");
  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. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
  3062. lrambyte);
  3063. seq_printf(m, " %X:%d", i, lrambyte);
  3064. }
  3065. seq_puts(m, "\n Command Pending:");
  3066. for (i = 0; i <= ADV_MAX_TID; i++) {
  3067. if ((chip_scsi_id == i) ||
  3068. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3069. continue;
  3070. }
  3071. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
  3072. lrambyte);
  3073. seq_printf(m, " %X:%d", i, lrambyte);
  3074. }
  3075. seq_putc(m, '\n');
  3076. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3077. seq_puts(m, " Wide Enabled:");
  3078. for (i = 0; i <= ADV_MAX_TID; i++) {
  3079. if ((chip_scsi_id == i) ||
  3080. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3081. continue;
  3082. }
  3083. seq_printf(m, " %X:%c",
  3084. i,
  3085. (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3086. }
  3087. seq_putc(m, '\n');
  3088. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
  3089. seq_puts(m, " Transfer Bit Width:");
  3090. for (i = 0; i <= ADV_MAX_TID; i++) {
  3091. if ((chip_scsi_id == i) ||
  3092. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3093. continue;
  3094. }
  3095. AdvReadWordLram(iop_base,
  3096. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3097. lramword);
  3098. seq_printf(m, " %X:%d",
  3099. i, (lramword & 0x8000) ? 16 : 8);
  3100. if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
  3101. (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3102. seq_putc(m, '*');
  3103. renegotiate = 1;
  3104. }
  3105. }
  3106. seq_putc(m, '\n');
  3107. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3108. seq_puts(m, " Synchronous Enabled:");
  3109. for (i = 0; i <= ADV_MAX_TID; i++) {
  3110. if ((chip_scsi_id == i) ||
  3111. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3112. continue;
  3113. }
  3114. seq_printf(m, " %X:%c",
  3115. i,
  3116. (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3117. }
  3118. seq_putc(m, '\n');
  3119. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
  3120. for (i = 0; i <= ADV_MAX_TID; i++) {
  3121. AdvReadWordLram(iop_base,
  3122. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3123. lramword);
  3124. lramword &= ~0x8000;
  3125. if ((chip_scsi_id == i) ||
  3126. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3127. ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3128. continue;
  3129. }
  3130. seq_printf(m, " %X:", i);
  3131. if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
  3132. seq_puts(m, " Asynchronous");
  3133. } else {
  3134. seq_puts(m, " Transfer Period Factor: ");
  3135. if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
  3136. seq_puts(m, "9 (80.0 Mhz),");
  3137. } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
  3138. seq_puts(m, "10 (40.0 Mhz),");
  3139. } else { /* 20 Mhz or below. */
  3140. period = (((lramword >> 8) * 25) + 50) / 4;
  3141. if (period == 0) { /* Should never happen. */
  3142. seq_printf(m, "%d (? Mhz), ", period);
  3143. } else {
  3144. seq_printf(m,
  3145. "%d (%d.%d Mhz),",
  3146. period, 250 / period,
  3147. ASC_TENTHS(250, period));
  3148. }
  3149. }
  3150. seq_printf(m, " REQ/ACK Offset: %d",
  3151. lramword & 0x1F);
  3152. }
  3153. if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3154. seq_puts(m, "*\n");
  3155. renegotiate = 1;
  3156. } else {
  3157. seq_putc(m, '\n');
  3158. }
  3159. }
  3160. if (renegotiate) {
  3161. seq_puts(m, " * = Re-negotiation pending before next command.\n");
  3162. }
  3163. }
  3164. #ifdef ADVANSYS_STATS
  3165. /*
  3166. * asc_prt_board_stats()
  3167. */
  3168. static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
  3169. {
  3170. struct asc_board *boardp = shost_priv(shost);
  3171. struct asc_stats *s = &boardp->asc_stats;
  3172. seq_printf(m,
  3173. "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
  3174. shost->host_no);
  3175. seq_printf(m,
  3176. " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
  3177. s->queuecommand, s->reset, s->biosparam,
  3178. s->interrupt);
  3179. seq_printf(m,
  3180. " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
  3181. s->callback, s->done, s->build_error,
  3182. s->adv_build_noreq, s->adv_build_nosg);
  3183. seq_printf(m,
  3184. " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
  3185. s->exe_noerror, s->exe_busy, s->exe_error,
  3186. s->exe_unknown);
  3187. /*
  3188. * Display data transfer statistics.
  3189. */
  3190. if (s->xfer_cnt > 0) {
  3191. seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
  3192. s->xfer_cnt, s->xfer_elem);
  3193. seq_printf(m, "xfer_bytes %u.%01u kb\n",
  3194. s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
  3195. /* Scatter gather transfer statistics */
  3196. seq_printf(m, " avg_num_elem %u.%01u, ",
  3197. s->xfer_elem / s->xfer_cnt,
  3198. ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
  3199. seq_printf(m, "avg_elem_size %u.%01u kb, ",
  3200. (s->xfer_sect / 2) / s->xfer_elem,
  3201. ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
  3202. seq_printf(m, "avg_xfer_size %u.%01u kb\n",
  3203. (s->xfer_sect / 2) / s->xfer_cnt,
  3204. ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
  3205. }
  3206. }
  3207. #endif /* ADVANSYS_STATS */
  3208. /*
  3209. * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
  3210. *
  3211. * m: seq_file to print into
  3212. * shost: Scsi_Host
  3213. *
  3214. * Return the number of bytes read from or written to a
  3215. * /proc/scsi/advansys/[0...] file.
  3216. */
  3217. static int
  3218. advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
  3219. {
  3220. struct asc_board *boardp = shost_priv(shost);
  3221. ASC_DBG(1, "begin\n");
  3222. /*
  3223. * User read of /proc/scsi/advansys/[0...] file.
  3224. */
  3225. /*
  3226. * Get board configuration information.
  3227. *
  3228. * advansys_info() returns the board string from its own static buffer.
  3229. */
  3230. /* Copy board information. */
  3231. seq_printf(m, "%s\n", (char *)advansys_info(shost));
  3232. /*
  3233. * Display Wide Board BIOS Information.
  3234. */
  3235. if (!ASC_NARROW_BOARD(boardp))
  3236. asc_prt_adv_bios(m, shost);
  3237. /*
  3238. * Display driver information for each device attached to the board.
  3239. */
  3240. asc_prt_board_devices(m, shost);
  3241. /*
  3242. * Display EEPROM configuration for the board.
  3243. */
  3244. if (ASC_NARROW_BOARD(boardp))
  3245. asc_prt_asc_board_eeprom(m, shost);
  3246. else
  3247. asc_prt_adv_board_eeprom(m, shost);
  3248. /*
  3249. * Display driver configuration and information for the board.
  3250. */
  3251. asc_prt_driver_conf(m, shost);
  3252. #ifdef ADVANSYS_STATS
  3253. /*
  3254. * Display driver statistics for the board.
  3255. */
  3256. asc_prt_board_stats(m, shost);
  3257. #endif /* ADVANSYS_STATS */
  3258. /*
  3259. * Display Asc Library dynamic configuration information
  3260. * for the board.
  3261. */
  3262. if (ASC_NARROW_BOARD(boardp))
  3263. asc_prt_asc_board_info(m, shost);
  3264. else
  3265. asc_prt_adv_board_info(m, shost);
  3266. return 0;
  3267. }
  3268. #endif /* CONFIG_PROC_FS */
  3269. static void asc_scsi_done(struct scsi_cmnd *scp)
  3270. {
  3271. scsi_dma_unmap(scp);
  3272. ASC_STATS(scp->device->host, done);
  3273. scp->scsi_done(scp);
  3274. }
  3275. static void AscSetBank(PortAddr iop_base, uchar bank)
  3276. {
  3277. uchar val;
  3278. val = AscGetChipControl(iop_base) &
  3279. (~
  3280. (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
  3281. CC_CHIP_RESET));
  3282. if (bank == 1) {
  3283. val |= CC_BANK_ONE;
  3284. } else if (bank == 2) {
  3285. val |= CC_DIAG | CC_BANK_ONE;
  3286. } else {
  3287. val &= ~CC_BANK_ONE;
  3288. }
  3289. AscSetChipControl(iop_base, val);
  3290. }
  3291. static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
  3292. {
  3293. AscSetBank(iop_base, 1);
  3294. AscWriteChipIH(iop_base, ins_code);
  3295. AscSetBank(iop_base, 0);
  3296. }
  3297. static int AscStartChip(PortAddr iop_base)
  3298. {
  3299. AscSetChipControl(iop_base, 0);
  3300. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3301. return (0);
  3302. }
  3303. return (1);
  3304. }
  3305. static bool AscStopChip(PortAddr iop_base)
  3306. {
  3307. uchar cc_val;
  3308. cc_val =
  3309. AscGetChipControl(iop_base) &
  3310. (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
  3311. AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
  3312. AscSetChipIH(iop_base, INS_HALT);
  3313. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3314. if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
  3315. return false;
  3316. }
  3317. return true;
  3318. }
  3319. static bool AscIsChipHalted(PortAddr iop_base)
  3320. {
  3321. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3322. if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
  3323. return true;
  3324. }
  3325. }
  3326. return false;
  3327. }
  3328. static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
  3329. {
  3330. PortAddr iop_base;
  3331. int i = 10;
  3332. iop_base = asc_dvc->iop_base;
  3333. while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
  3334. && (i-- > 0)) {
  3335. mdelay(100);
  3336. }
  3337. AscStopChip(iop_base);
  3338. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
  3339. udelay(60);
  3340. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3341. AscSetChipIH(iop_base, INS_HALT);
  3342. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
  3343. AscSetChipControl(iop_base, CC_HALT);
  3344. mdelay(200);
  3345. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  3346. AscSetChipStatus(iop_base, 0);
  3347. return (AscIsChipHalted(iop_base));
  3348. }
  3349. static int AscFindSignature(PortAddr iop_base)
  3350. {
  3351. ushort sig_word;
  3352. ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
  3353. iop_base, AscGetChipSignatureByte(iop_base));
  3354. if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
  3355. ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
  3356. iop_base, AscGetChipSignatureWord(iop_base));
  3357. sig_word = AscGetChipSignatureWord(iop_base);
  3358. if ((sig_word == (ushort)ASC_1000_ID0W) ||
  3359. (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
  3360. return (1);
  3361. }
  3362. }
  3363. return (0);
  3364. }
  3365. static void AscEnableInterrupt(PortAddr iop_base)
  3366. {
  3367. ushort cfg;
  3368. cfg = AscGetChipCfgLsw(iop_base);
  3369. AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
  3370. }
  3371. static void AscDisableInterrupt(PortAddr iop_base)
  3372. {
  3373. ushort cfg;
  3374. cfg = AscGetChipCfgLsw(iop_base);
  3375. AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
  3376. }
  3377. static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
  3378. {
  3379. unsigned char byte_data;
  3380. unsigned short word_data;
  3381. if (isodd_word(addr)) {
  3382. AscSetChipLramAddr(iop_base, addr - 1);
  3383. word_data = AscGetChipLramData(iop_base);
  3384. byte_data = (word_data >> 8) & 0xFF;
  3385. } else {
  3386. AscSetChipLramAddr(iop_base, addr);
  3387. word_data = AscGetChipLramData(iop_base);
  3388. byte_data = word_data & 0xFF;
  3389. }
  3390. return byte_data;
  3391. }
  3392. static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
  3393. {
  3394. ushort word_data;
  3395. AscSetChipLramAddr(iop_base, addr);
  3396. word_data = AscGetChipLramData(iop_base);
  3397. return (word_data);
  3398. }
  3399. static void
  3400. AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
  3401. {
  3402. int i;
  3403. AscSetChipLramAddr(iop_base, s_addr);
  3404. for (i = 0; i < words; i++) {
  3405. AscSetChipLramData(iop_base, set_wval);
  3406. }
  3407. }
  3408. static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
  3409. {
  3410. AscSetChipLramAddr(iop_base, addr);
  3411. AscSetChipLramData(iop_base, word_val);
  3412. }
  3413. static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
  3414. {
  3415. ushort word_data;
  3416. if (isodd_word(addr)) {
  3417. addr--;
  3418. word_data = AscReadLramWord(iop_base, addr);
  3419. word_data &= 0x00FF;
  3420. word_data |= (((ushort)byte_val << 8) & 0xFF00);
  3421. } else {
  3422. word_data = AscReadLramWord(iop_base, addr);
  3423. word_data &= 0xFF00;
  3424. word_data |= ((ushort)byte_val & 0x00FF);
  3425. }
  3426. AscWriteLramWord(iop_base, addr, word_data);
  3427. }
  3428. /*
  3429. * Copy 2 bytes to LRAM.
  3430. *
  3431. * The source data is assumed to be in little-endian order in memory
  3432. * and is maintained in little-endian order when written to LRAM.
  3433. */
  3434. static void
  3435. AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
  3436. const uchar *s_buffer, int words)
  3437. {
  3438. int i;
  3439. AscSetChipLramAddr(iop_base, s_addr);
  3440. for (i = 0; i < 2 * words; i += 2) {
  3441. /*
  3442. * On a little-endian system the second argument below
  3443. * produces a little-endian ushort which is written to
  3444. * LRAM in little-endian order. On a big-endian system
  3445. * the second argument produces a big-endian ushort which
  3446. * is "transparently" byte-swapped by outpw() and written
  3447. * in little-endian order to LRAM.
  3448. */
  3449. outpw(iop_base + IOP_RAM_DATA,
  3450. ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
  3451. }
  3452. }
  3453. /*
  3454. * Copy 4 bytes to LRAM.
  3455. *
  3456. * The source data is assumed to be in little-endian order in memory
  3457. * and is maintained in little-endian order when written to LRAM.
  3458. */
  3459. static void
  3460. AscMemDWordCopyPtrToLram(PortAddr iop_base,
  3461. ushort s_addr, uchar *s_buffer, int dwords)
  3462. {
  3463. int i;
  3464. AscSetChipLramAddr(iop_base, s_addr);
  3465. for (i = 0; i < 4 * dwords; i += 4) {
  3466. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
  3467. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
  3468. }
  3469. }
  3470. /*
  3471. * Copy 2 bytes from LRAM.
  3472. *
  3473. * The source data is assumed to be in little-endian order in LRAM
  3474. * and is maintained in little-endian order when written to memory.
  3475. */
  3476. static void
  3477. AscMemWordCopyPtrFromLram(PortAddr iop_base,
  3478. ushort s_addr, uchar *d_buffer, int words)
  3479. {
  3480. int i;
  3481. ushort word;
  3482. AscSetChipLramAddr(iop_base, s_addr);
  3483. for (i = 0; i < 2 * words; i += 2) {
  3484. word = inpw(iop_base + IOP_RAM_DATA);
  3485. d_buffer[i] = word & 0xff;
  3486. d_buffer[i + 1] = (word >> 8) & 0xff;
  3487. }
  3488. }
  3489. static u32 AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
  3490. {
  3491. u32 sum = 0;
  3492. int i;
  3493. for (i = 0; i < words; i++, s_addr += 2) {
  3494. sum += AscReadLramWord(iop_base, s_addr);
  3495. }
  3496. return (sum);
  3497. }
  3498. static void AscInitLram(ASC_DVC_VAR *asc_dvc)
  3499. {
  3500. uchar i;
  3501. ushort s_addr;
  3502. PortAddr iop_base;
  3503. iop_base = asc_dvc->iop_base;
  3504. AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
  3505. (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
  3506. 64) >> 1));
  3507. i = ASC_MIN_ACTIVE_QNO;
  3508. s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
  3509. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3510. (uchar)(i + 1));
  3511. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3512. (uchar)(asc_dvc->max_total_qng));
  3513. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3514. (uchar)i);
  3515. i++;
  3516. s_addr += ASC_QBLK_SIZE;
  3517. for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
  3518. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3519. (uchar)(i + 1));
  3520. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3521. (uchar)(i - 1));
  3522. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3523. (uchar)i);
  3524. }
  3525. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3526. (uchar)ASC_QLINK_END);
  3527. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3528. (uchar)(asc_dvc->max_total_qng - 1));
  3529. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3530. (uchar)asc_dvc->max_total_qng);
  3531. i++;
  3532. s_addr += ASC_QBLK_SIZE;
  3533. for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
  3534. i++, s_addr += ASC_QBLK_SIZE) {
  3535. AscWriteLramByte(iop_base,
  3536. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
  3537. AscWriteLramByte(iop_base,
  3538. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
  3539. AscWriteLramByte(iop_base,
  3540. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
  3541. }
  3542. }
  3543. static u32
  3544. AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
  3545. const uchar *mcode_buf, ushort mcode_size)
  3546. {
  3547. u32 chksum;
  3548. ushort mcode_word_size;
  3549. ushort mcode_chksum;
  3550. /* Write the microcode buffer starting at LRAM address 0. */
  3551. mcode_word_size = (ushort)(mcode_size >> 1);
  3552. AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
  3553. AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
  3554. chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
  3555. ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
  3556. mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
  3557. (ushort)ASC_CODE_SEC_BEG,
  3558. (ushort)((mcode_size -
  3559. s_addr - (ushort)
  3560. ASC_CODE_SEC_BEG) /
  3561. 2));
  3562. ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
  3563. AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
  3564. AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
  3565. return chksum;
  3566. }
  3567. static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
  3568. {
  3569. PortAddr iop_base;
  3570. int i;
  3571. ushort lram_addr;
  3572. iop_base = asc_dvc->iop_base;
  3573. AscPutRiscVarFreeQHead(iop_base, 1);
  3574. AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3575. AscPutVarFreeQHead(iop_base, 1);
  3576. AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3577. AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
  3578. (uchar)((int)asc_dvc->max_total_qng + 1));
  3579. AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
  3580. (uchar)((int)asc_dvc->max_total_qng + 2));
  3581. AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
  3582. asc_dvc->max_total_qng);
  3583. AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
  3584. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  3585. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
  3586. AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
  3587. AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
  3588. AscPutQDoneInProgress(iop_base, 0);
  3589. lram_addr = ASC_QADR_BEG;
  3590. for (i = 0; i < 32; i++, lram_addr += 2) {
  3591. AscWriteLramWord(iop_base, lram_addr, 0);
  3592. }
  3593. }
  3594. static int AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
  3595. {
  3596. int i;
  3597. int warn_code;
  3598. PortAddr iop_base;
  3599. __le32 phy_addr;
  3600. __le32 phy_size;
  3601. struct asc_board *board = asc_dvc_to_board(asc_dvc);
  3602. iop_base = asc_dvc->iop_base;
  3603. warn_code = 0;
  3604. for (i = 0; i <= ASC_MAX_TID; i++) {
  3605. AscPutMCodeInitSDTRAtID(iop_base, i,
  3606. asc_dvc->cfg->sdtr_period_offset[i]);
  3607. }
  3608. AscInitQLinkVar(asc_dvc);
  3609. AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
  3610. asc_dvc->cfg->disc_enable);
  3611. AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
  3612. ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
  3613. /* Ensure overrun buffer is aligned on an 8 byte boundary. */
  3614. BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
  3615. asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
  3616. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3617. if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
  3618. warn_code = -ENOMEM;
  3619. goto err_dma_map;
  3620. }
  3621. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  3622. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  3623. (uchar *)&phy_addr, 1);
  3624. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  3625. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  3626. (uchar *)&phy_size, 1);
  3627. asc_dvc->cfg->mcode_date =
  3628. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  3629. asc_dvc->cfg->mcode_version =
  3630. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  3631. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  3632. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  3633. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  3634. warn_code = -EINVAL;
  3635. goto err_mcode_start;
  3636. }
  3637. if (AscStartChip(iop_base) != 1) {
  3638. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  3639. warn_code = -EIO;
  3640. goto err_mcode_start;
  3641. }
  3642. return warn_code;
  3643. err_mcode_start:
  3644. dma_unmap_single(board->dev, asc_dvc->overrun_dma,
  3645. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3646. err_dma_map:
  3647. asc_dvc->overrun_dma = 0;
  3648. return warn_code;
  3649. }
  3650. static int AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  3651. {
  3652. const struct firmware *fw;
  3653. const char fwname[] = "advansys/mcode.bin";
  3654. int err;
  3655. unsigned long chksum;
  3656. int warn_code;
  3657. PortAddr iop_base;
  3658. iop_base = asc_dvc->iop_base;
  3659. warn_code = 0;
  3660. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  3661. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  3662. AscResetChipAndScsiBus(asc_dvc);
  3663. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3664. }
  3665. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  3666. if (asc_dvc->err_code != 0)
  3667. return ASC_ERROR;
  3668. if (!AscFindSignature(asc_dvc->iop_base)) {
  3669. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  3670. return warn_code;
  3671. }
  3672. AscDisableInterrupt(iop_base);
  3673. AscInitLram(asc_dvc);
  3674. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3675. if (err) {
  3676. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  3677. fwname, err);
  3678. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3679. return err;
  3680. }
  3681. if (fw->size < 4) {
  3682. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  3683. fw->size, fwname);
  3684. release_firmware(fw);
  3685. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3686. return -EINVAL;
  3687. }
  3688. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  3689. (fw->data[1] << 8) | fw->data[0];
  3690. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  3691. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  3692. fw->size - 4) != chksum) {
  3693. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3694. release_firmware(fw);
  3695. return warn_code;
  3696. }
  3697. release_firmware(fw);
  3698. warn_code |= AscInitMicroCodeVar(asc_dvc);
  3699. if (!asc_dvc->overrun_dma)
  3700. return warn_code;
  3701. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  3702. AscEnableInterrupt(iop_base);
  3703. return warn_code;
  3704. }
  3705. /*
  3706. * Load the Microcode
  3707. *
  3708. * Write the microcode image to RISC memory starting at address 0.
  3709. *
  3710. * The microcode is stored compressed in the following format:
  3711. *
  3712. * 254 word (508 byte) table indexed by byte code followed
  3713. * by the following byte codes:
  3714. *
  3715. * 1-Byte Code:
  3716. * 00: Emit word 0 in table.
  3717. * 01: Emit word 1 in table.
  3718. * .
  3719. * FD: Emit word 253 in table.
  3720. *
  3721. * Multi-Byte Code:
  3722. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  3723. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  3724. *
  3725. * Returns 0 or an error if the checksum doesn't match
  3726. */
  3727. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  3728. int size, int memsize, int chksum)
  3729. {
  3730. int i, j, end, len = 0;
  3731. u32 sum;
  3732. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3733. for (i = 253 * 2; i < size; i++) {
  3734. if (buf[i] == 0xff) {
  3735. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  3736. for (j = 0; j < buf[i + 1]; j++) {
  3737. AdvWriteWordAutoIncLram(iop_base, word);
  3738. len += 2;
  3739. }
  3740. i += 3;
  3741. } else if (buf[i] == 0xfe) {
  3742. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  3743. AdvWriteWordAutoIncLram(iop_base, word);
  3744. i += 2;
  3745. len += 2;
  3746. } else {
  3747. unsigned int off = buf[i] * 2;
  3748. unsigned short word = (buf[off + 1] << 8) | buf[off];
  3749. AdvWriteWordAutoIncLram(iop_base, word);
  3750. len += 2;
  3751. }
  3752. }
  3753. end = len;
  3754. while (len < memsize) {
  3755. AdvWriteWordAutoIncLram(iop_base, 0);
  3756. len += 2;
  3757. }
  3758. /* Verify the microcode checksum. */
  3759. sum = 0;
  3760. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3761. for (len = 0; len < end; len += 2) {
  3762. sum += AdvReadWordAutoIncLram(iop_base);
  3763. }
  3764. if (sum != chksum)
  3765. return ASC_IERR_MCODE_CHKSUM;
  3766. return 0;
  3767. }
  3768. static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc)
  3769. {
  3770. off_t carr_offset = 0, next_offset;
  3771. dma_addr_t carr_paddr;
  3772. int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i;
  3773. for (i = 0; i < carr_num; i++) {
  3774. carr_offset = i * sizeof(ADV_CARR_T);
  3775. /* Get physical address of the carrier 'carrp'. */
  3776. carr_paddr = adv_dvc->carrier_addr + carr_offset;
  3777. adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr);
  3778. adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset);
  3779. adv_dvc->carrier[i].areq_vpa = 0;
  3780. next_offset = carr_offset + sizeof(ADV_CARR_T);
  3781. if (i == carr_num)
  3782. next_offset = ~0;
  3783. adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset);
  3784. }
  3785. /*
  3786. * We cannot have a carrier with 'carr_va' of '0', as
  3787. * a reference to this carrier would be interpreted as
  3788. * list termination.
  3789. * So start at carrier 1 with the freelist.
  3790. */
  3791. adv_dvc->carr_freelist = &adv_dvc->carrier[1];
  3792. }
  3793. static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset)
  3794. {
  3795. int index;
  3796. BUG_ON(offset > ADV_CARRIER_BUFSIZE);
  3797. index = offset / sizeof(ADV_CARR_T);
  3798. return &adv_dvc->carrier[index];
  3799. }
  3800. static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc)
  3801. {
  3802. ADV_CARR_T *carrp = adv_dvc->carr_freelist;
  3803. u32 next_vpa = le32_to_cpu(carrp->next_vpa);
  3804. if (next_vpa == 0 || next_vpa == ~0) {
  3805. ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa);
  3806. return NULL;
  3807. }
  3808. adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa);
  3809. /*
  3810. * insert stopper carrier to terminate list
  3811. */
  3812. carrp->next_vpa = cpu_to_le32(ADV_CQ_STOPPER);
  3813. return carrp;
  3814. }
  3815. /*
  3816. * 'offset' is the index in the request pointer array
  3817. */
  3818. static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset)
  3819. {
  3820. struct asc_board *boardp = adv_dvc->drv_ptr;
  3821. BUG_ON(offset > adv_dvc->max_host_qng);
  3822. return &boardp->adv_reqp[offset];
  3823. }
  3824. /*
  3825. * Send an idle command to the chip and wait for completion.
  3826. *
  3827. * Command completion is polled for once per microsecond.
  3828. *
  3829. * The function can be called from anywhere including an interrupt handler.
  3830. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  3831. * functions to prevent reentrancy.
  3832. *
  3833. * Return Values:
  3834. * ADV_TRUE - command completed successfully
  3835. * ADV_FALSE - command failed
  3836. * ADV_ERROR - command timed out
  3837. */
  3838. static int
  3839. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  3840. ushort idle_cmd, u32 idle_cmd_parameter)
  3841. {
  3842. int result, i, j;
  3843. AdvPortAddr iop_base;
  3844. iop_base = asc_dvc->iop_base;
  3845. /*
  3846. * Clear the idle command status which is set by the microcode
  3847. * to a non-zero value to indicate when the command is completed.
  3848. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  3849. */
  3850. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  3851. /*
  3852. * Write the idle command value after the idle command parameter
  3853. * has been written to avoid a race condition. If the order is not
  3854. * followed, the microcode may process the idle command before the
  3855. * parameters have been written to LRAM.
  3856. */
  3857. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  3858. cpu_to_le32(idle_cmd_parameter));
  3859. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  3860. /*
  3861. * Tickle the RISC to tell it to process the idle command.
  3862. */
  3863. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  3864. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  3865. /*
  3866. * Clear the tickle value. In the ASC-3550 the RISC flag
  3867. * command 'clr_tickle_b' does not work unless the host
  3868. * value is cleared.
  3869. */
  3870. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  3871. }
  3872. /* Wait for up to 100 millisecond for the idle command to timeout. */
  3873. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  3874. /* Poll once each microsecond for command completion. */
  3875. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  3876. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  3877. result);
  3878. if (result != 0)
  3879. return result;
  3880. udelay(1);
  3881. }
  3882. }
  3883. BUG(); /* The idle command should never timeout. */
  3884. return ADV_ERROR;
  3885. }
  3886. /*
  3887. * Reset SCSI Bus and purge all outstanding requests.
  3888. *
  3889. * Return Value:
  3890. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  3891. * ADV_FALSE(0) - Microcode command failed.
  3892. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  3893. * may be hung which requires driver recovery.
  3894. */
  3895. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  3896. {
  3897. int status;
  3898. /*
  3899. * Send the SCSI Bus Reset idle start idle command which asserts
  3900. * the SCSI Bus Reset signal.
  3901. */
  3902. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  3903. if (status != ADV_TRUE) {
  3904. return status;
  3905. }
  3906. /*
  3907. * Delay for the specified SCSI Bus Reset hold time.
  3908. *
  3909. * The hold time delay is done on the host because the RISC has no
  3910. * microsecond accurate timer.
  3911. */
  3912. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  3913. /*
  3914. * Send the SCSI Bus Reset end idle command which de-asserts
  3915. * the SCSI Bus Reset signal and purges any pending requests.
  3916. */
  3917. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  3918. if (status != ADV_TRUE) {
  3919. return status;
  3920. }
  3921. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3922. return status;
  3923. }
  3924. /*
  3925. * Initialize the ASC-3550.
  3926. *
  3927. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  3928. *
  3929. * For a non-fatal error return a warning code. If there are no warnings
  3930. * then 0 is returned.
  3931. *
  3932. * Needed after initialization for error recovery.
  3933. */
  3934. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  3935. {
  3936. const struct firmware *fw;
  3937. const char fwname[] = "advansys/3550.bin";
  3938. AdvPortAddr iop_base;
  3939. ushort warn_code;
  3940. int begin_addr;
  3941. int end_addr;
  3942. ushort code_sum;
  3943. int word;
  3944. int i;
  3945. int err;
  3946. unsigned long chksum;
  3947. ushort scsi_cfg1;
  3948. uchar tid;
  3949. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  3950. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  3951. uchar max_cmd[ADV_MAX_TID + 1];
  3952. /* If there is already an error, don't continue. */
  3953. if (asc_dvc->err_code != 0)
  3954. return ADV_ERROR;
  3955. /*
  3956. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  3957. */
  3958. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  3959. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  3960. return ADV_ERROR;
  3961. }
  3962. warn_code = 0;
  3963. iop_base = asc_dvc->iop_base;
  3964. /*
  3965. * Save the RISC memory BIOS region before writing the microcode.
  3966. * The BIOS may already be loaded and using its RISC LRAM region
  3967. * so its region must be saved and restored.
  3968. *
  3969. * Note: This code makes the assumption, which is currently true,
  3970. * that a chip reset does not clear RISC LRAM.
  3971. */
  3972. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  3973. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  3974. bios_mem[i]);
  3975. }
  3976. /*
  3977. * Save current per TID negotiated values.
  3978. */
  3979. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  3980. ushort bios_version, major, minor;
  3981. bios_version =
  3982. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  3983. major = (bios_version >> 12) & 0xF;
  3984. minor = (bios_version >> 8) & 0xF;
  3985. if (major < 3 || (major == 3 && minor == 1)) {
  3986. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  3987. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  3988. } else {
  3989. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3990. }
  3991. }
  3992. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3993. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3994. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  3995. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  3996. max_cmd[tid]);
  3997. }
  3998. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3999. if (err) {
  4000. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4001. fwname, err);
  4002. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4003. return err;
  4004. }
  4005. if (fw->size < 4) {
  4006. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4007. fw->size, fwname);
  4008. release_firmware(fw);
  4009. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4010. return -EINVAL;
  4011. }
  4012. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4013. (fw->data[1] << 8) | fw->data[0];
  4014. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4015. fw->size - 4, ADV_3550_MEMSIZE,
  4016. chksum);
  4017. release_firmware(fw);
  4018. if (asc_dvc->err_code)
  4019. return ADV_ERROR;
  4020. /*
  4021. * Restore the RISC memory BIOS region.
  4022. */
  4023. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4024. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4025. bios_mem[i]);
  4026. }
  4027. /*
  4028. * Calculate and write the microcode code checksum to the microcode
  4029. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4030. */
  4031. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4032. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4033. code_sum = 0;
  4034. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4035. for (word = begin_addr; word < end_addr; word += 2) {
  4036. code_sum += AdvReadWordAutoIncLram(iop_base);
  4037. }
  4038. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4039. /*
  4040. * Read and save microcode version and date.
  4041. */
  4042. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4043. asc_dvc->cfg->mcode_date);
  4044. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4045. asc_dvc->cfg->mcode_version);
  4046. /*
  4047. * Set the chip type to indicate the ASC3550.
  4048. */
  4049. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  4050. /*
  4051. * If the PCI Configuration Command Register "Parity Error Response
  4052. * Control" Bit was clear (0), then set the microcode variable
  4053. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4054. * to ignore DMA parity errors.
  4055. */
  4056. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4057. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4058. word |= CONTROL_FLAG_IGNORE_PERR;
  4059. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4060. }
  4061. /*
  4062. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4063. * threshold of 128 bytes. This register is only accessible to the host.
  4064. */
  4065. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4066. START_CTL_EMFU | READ_CMD_MRM);
  4067. /*
  4068. * Microcode operating variables for WDTR, SDTR, and command tag
  4069. * queuing will be set in slave_configure() based on what a
  4070. * device reports it is capable of in Inquiry byte 7.
  4071. *
  4072. * If SCSI Bus Resets have been disabled, then directly set
  4073. * SDTR and WDTR from the EEPROM configuration. This will allow
  4074. * the BIOS and warm boot to work without a SCSI bus hang on
  4075. * the Inquiry caused by host and target mismatched DTR values.
  4076. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4077. * be assumed to be in Asynchronous, Narrow mode.
  4078. */
  4079. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4080. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4081. asc_dvc->wdtr_able);
  4082. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4083. asc_dvc->sdtr_able);
  4084. }
  4085. /*
  4086. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4087. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4088. * bitmask. These values determine the maximum SDTR speed negotiated
  4089. * with a device.
  4090. *
  4091. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4092. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4093. * without determining here whether the device supports SDTR.
  4094. *
  4095. * 4-bit speed SDTR speed name
  4096. * =========== ===============
  4097. * 0000b (0x0) SDTR disabled
  4098. * 0001b (0x1) 5 Mhz
  4099. * 0010b (0x2) 10 Mhz
  4100. * 0011b (0x3) 20 Mhz (Ultra)
  4101. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4102. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4103. * 0110b (0x6) Undefined
  4104. * .
  4105. * 1111b (0xF) Undefined
  4106. */
  4107. word = 0;
  4108. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4109. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4110. /* Set Ultra speed for TID 'tid'. */
  4111. word |= (0x3 << (4 * (tid % 4)));
  4112. } else {
  4113. /* Set Fast speed for TID 'tid'. */
  4114. word |= (0x2 << (4 * (tid % 4)));
  4115. }
  4116. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4117. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4118. word = 0;
  4119. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4120. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4121. word = 0;
  4122. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4123. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4124. word = 0;
  4125. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4126. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4127. /* End of loop. */
  4128. }
  4129. }
  4130. /*
  4131. * Set microcode operating variable for the disconnect per TID bitmask.
  4132. */
  4133. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4134. asc_dvc->cfg->disc_enable);
  4135. /*
  4136. * Set SCSI_CFG0 Microcode Default Value.
  4137. *
  4138. * The microcode will set the SCSI_CFG0 register using this value
  4139. * after it is started below.
  4140. */
  4141. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4142. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4143. asc_dvc->chip_scsi_id);
  4144. /*
  4145. * Determine SCSI_CFG1 Microcode Default Value.
  4146. *
  4147. * The microcode will set the SCSI_CFG1 register using this value
  4148. * after it is started below.
  4149. */
  4150. /* Read current SCSI_CFG1 Register value. */
  4151. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4152. /*
  4153. * If all three connectors are in use, return an error.
  4154. */
  4155. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4156. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4157. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4158. return ADV_ERROR;
  4159. }
  4160. /*
  4161. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4162. * register signals will be set. Check for and return an error if
  4163. * this condition is found.
  4164. */
  4165. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4166. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4167. return ADV_ERROR;
  4168. }
  4169. /*
  4170. * If this is a differential board and a single-ended device
  4171. * is attached to one of the connectors, return an error.
  4172. */
  4173. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4174. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4175. return ADV_ERROR;
  4176. }
  4177. /*
  4178. * If automatic termination control is enabled, then set the
  4179. * termination value based on a table listed in a_condor.h.
  4180. *
  4181. * If manual termination was specified with an EEPROM setting
  4182. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4183. * is ready to be 'ored' into SCSI_CFG1.
  4184. */
  4185. if (asc_dvc->cfg->termination == 0) {
  4186. /*
  4187. * The software always controls termination by setting TERM_CTL_SEL.
  4188. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4189. */
  4190. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4191. switch (scsi_cfg1 & CABLE_DETECT) {
  4192. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4193. case 0x3:
  4194. case 0x7:
  4195. case 0xB:
  4196. case 0xD:
  4197. case 0xE:
  4198. case 0xF:
  4199. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4200. break;
  4201. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4202. case 0x1:
  4203. case 0x5:
  4204. case 0x9:
  4205. case 0xA:
  4206. case 0xC:
  4207. asc_dvc->cfg->termination |= TERM_CTL_H;
  4208. break;
  4209. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4210. case 0x2:
  4211. case 0x6:
  4212. break;
  4213. }
  4214. }
  4215. /*
  4216. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4217. */
  4218. scsi_cfg1 &= ~TERM_CTL;
  4219. /*
  4220. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4221. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4222. * referenced, because the hardware internally inverts
  4223. * the Termination High and Low bits if TERM_POL is set.
  4224. */
  4225. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4226. /*
  4227. * Set SCSI_CFG1 Microcode Default Value
  4228. *
  4229. * Set filter value and possibly modified termination control
  4230. * bits in the Microcode SCSI_CFG1 Register Value.
  4231. *
  4232. * The microcode will set the SCSI_CFG1 register using this value
  4233. * after it is started below.
  4234. */
  4235. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4236. FLTR_DISABLE | scsi_cfg1);
  4237. /*
  4238. * Set MEM_CFG Microcode Default Value
  4239. *
  4240. * The microcode will set the MEM_CFG register using this value
  4241. * after it is started below.
  4242. *
  4243. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4244. * are defined.
  4245. *
  4246. * ASC-3550 has 8KB internal memory.
  4247. */
  4248. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4249. BIOS_EN | RAM_SZ_8KB);
  4250. /*
  4251. * Set SEL_MASK Microcode Default Value
  4252. *
  4253. * The microcode will set the SEL_MASK register using this value
  4254. * after it is started below.
  4255. */
  4256. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4257. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4258. AdvBuildCarrierFreelist(asc_dvc);
  4259. /*
  4260. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4261. */
  4262. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  4263. if (!asc_dvc->icq_sp) {
  4264. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4265. return ADV_ERROR;
  4266. }
  4267. /*
  4268. * Set RISC ICQ physical address start value.
  4269. */
  4270. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4271. /*
  4272. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4273. */
  4274. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  4275. if (!asc_dvc->irq_sp) {
  4276. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4277. return ADV_ERROR;
  4278. }
  4279. /*
  4280. * Set RISC IRQ physical address start value.
  4281. */
  4282. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4283. asc_dvc->carr_pending_cnt = 0;
  4284. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4285. (ADV_INTR_ENABLE_HOST_INTR |
  4286. ADV_INTR_ENABLE_GLOBAL_INTR));
  4287. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4288. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4289. /* finally, finally, gentlemen, start your engine */
  4290. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4291. /*
  4292. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4293. * Resets should be performed. The RISC has to be running
  4294. * to issue a SCSI Bus Reset.
  4295. */
  4296. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4297. /*
  4298. * If the BIOS Signature is present in memory, restore the
  4299. * BIOS Handshake Configuration Table and do not perform
  4300. * a SCSI Bus Reset.
  4301. */
  4302. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4303. 0x55AA) {
  4304. /*
  4305. * Restore per TID negotiated values.
  4306. */
  4307. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4308. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4309. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4310. tagqng_able);
  4311. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4312. AdvWriteByteLram(iop_base,
  4313. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4314. max_cmd[tid]);
  4315. }
  4316. } else {
  4317. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4318. warn_code = ASC_WARN_BUSRESET_ERROR;
  4319. }
  4320. }
  4321. }
  4322. return warn_code;
  4323. }
  4324. /*
  4325. * Initialize the ASC-38C0800.
  4326. *
  4327. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4328. *
  4329. * For a non-fatal error return a warning code. If there are no warnings
  4330. * then 0 is returned.
  4331. *
  4332. * Needed after initialization for error recovery.
  4333. */
  4334. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4335. {
  4336. const struct firmware *fw;
  4337. const char fwname[] = "advansys/38C0800.bin";
  4338. AdvPortAddr iop_base;
  4339. ushort warn_code;
  4340. int begin_addr;
  4341. int end_addr;
  4342. ushort code_sum;
  4343. int word;
  4344. int i;
  4345. int err;
  4346. unsigned long chksum;
  4347. ushort scsi_cfg1;
  4348. uchar byte;
  4349. uchar tid;
  4350. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4351. ushort wdtr_able, sdtr_able, tagqng_able;
  4352. uchar max_cmd[ADV_MAX_TID + 1];
  4353. /* If there is already an error, don't continue. */
  4354. if (asc_dvc->err_code != 0)
  4355. return ADV_ERROR;
  4356. /*
  4357. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4358. */
  4359. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4360. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4361. return ADV_ERROR;
  4362. }
  4363. warn_code = 0;
  4364. iop_base = asc_dvc->iop_base;
  4365. /*
  4366. * Save the RISC memory BIOS region before writing the microcode.
  4367. * The BIOS may already be loaded and using its RISC LRAM region
  4368. * so its region must be saved and restored.
  4369. *
  4370. * Note: This code makes the assumption, which is currently true,
  4371. * that a chip reset does not clear RISC LRAM.
  4372. */
  4373. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4374. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4375. bios_mem[i]);
  4376. }
  4377. /*
  4378. * Save current per TID negotiated values.
  4379. */
  4380. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4381. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4382. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4383. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4384. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4385. max_cmd[tid]);
  4386. }
  4387. /*
  4388. * RAM BIST (RAM Built-In Self Test)
  4389. *
  4390. * Address : I/O base + offset 0x38h register (byte).
  4391. * Function: Bit 7-6(RW) : RAM mode
  4392. * Normal Mode : 0x00
  4393. * Pre-test Mode : 0x40
  4394. * RAM Test Mode : 0x80
  4395. * Bit 5 : unused
  4396. * Bit 4(RO) : Done bit
  4397. * Bit 3-0(RO) : Status
  4398. * Host Error : 0x08
  4399. * Int_RAM Error : 0x04
  4400. * RISC Error : 0x02
  4401. * SCSI Error : 0x01
  4402. * No Error : 0x00
  4403. *
  4404. * Note: RAM BIST code should be put right here, before loading the
  4405. * microcode and after saving the RISC memory BIOS region.
  4406. */
  4407. /*
  4408. * LRAM Pre-test
  4409. *
  4410. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4411. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4412. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4413. * to NORMAL_MODE, return an error too.
  4414. */
  4415. for (i = 0; i < 2; i++) {
  4416. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4417. mdelay(10); /* Wait for 10ms before reading back. */
  4418. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4419. if ((byte & RAM_TEST_DONE) == 0
  4420. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4421. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4422. return ADV_ERROR;
  4423. }
  4424. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4425. mdelay(10); /* Wait for 10ms before reading back. */
  4426. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4427. != NORMAL_VALUE) {
  4428. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4429. return ADV_ERROR;
  4430. }
  4431. }
  4432. /*
  4433. * LRAM Test - It takes about 1.5 ms to run through the test.
  4434. *
  4435. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4436. * If Done bit not set or Status not 0, save register byte, set the
  4437. * err_code, and return an error.
  4438. */
  4439. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4440. mdelay(10); /* Wait for 10ms before checking status. */
  4441. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4442. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4443. /* Get here if Done bit not set or Status not 0. */
  4444. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4445. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4446. return ADV_ERROR;
  4447. }
  4448. /* We need to reset back to normal mode after LRAM test passes. */
  4449. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4450. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4451. if (err) {
  4452. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4453. fwname, err);
  4454. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4455. return err;
  4456. }
  4457. if (fw->size < 4) {
  4458. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4459. fw->size, fwname);
  4460. release_firmware(fw);
  4461. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4462. return -EINVAL;
  4463. }
  4464. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4465. (fw->data[1] << 8) | fw->data[0];
  4466. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4467. fw->size - 4, ADV_38C0800_MEMSIZE,
  4468. chksum);
  4469. release_firmware(fw);
  4470. if (asc_dvc->err_code)
  4471. return ADV_ERROR;
  4472. /*
  4473. * Restore the RISC memory BIOS region.
  4474. */
  4475. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4476. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4477. bios_mem[i]);
  4478. }
  4479. /*
  4480. * Calculate and write the microcode code checksum to the microcode
  4481. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4482. */
  4483. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4484. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4485. code_sum = 0;
  4486. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4487. for (word = begin_addr; word < end_addr; word += 2) {
  4488. code_sum += AdvReadWordAutoIncLram(iop_base);
  4489. }
  4490. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4491. /*
  4492. * Read microcode version and date.
  4493. */
  4494. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4495. asc_dvc->cfg->mcode_date);
  4496. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4497. asc_dvc->cfg->mcode_version);
  4498. /*
  4499. * Set the chip type to indicate the ASC38C0800.
  4500. */
  4501. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  4502. /*
  4503. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4504. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4505. * cable detection and then we are able to read C_DET[3:0].
  4506. *
  4507. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4508. * Microcode Default Value' section below.
  4509. */
  4510. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4511. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4512. scsi_cfg1 | DIS_TERM_DRV);
  4513. /*
  4514. * If the PCI Configuration Command Register "Parity Error Response
  4515. * Control" Bit was clear (0), then set the microcode variable
  4516. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4517. * to ignore DMA parity errors.
  4518. */
  4519. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4520. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4521. word |= CONTROL_FLAG_IGNORE_PERR;
  4522. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4523. }
  4524. /*
  4525. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  4526. * bits for the default FIFO threshold.
  4527. *
  4528. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  4529. *
  4530. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  4531. */
  4532. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4533. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  4534. READ_CMD_MRM);
  4535. /*
  4536. * Microcode operating variables for WDTR, SDTR, and command tag
  4537. * queuing will be set in slave_configure() based on what a
  4538. * device reports it is capable of in Inquiry byte 7.
  4539. *
  4540. * If SCSI Bus Resets have been disabled, then directly set
  4541. * SDTR and WDTR from the EEPROM configuration. This will allow
  4542. * the BIOS and warm boot to work without a SCSI bus hang on
  4543. * the Inquiry caused by host and target mismatched DTR values.
  4544. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4545. * be assumed to be in Asynchronous, Narrow mode.
  4546. */
  4547. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4548. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4549. asc_dvc->wdtr_able);
  4550. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4551. asc_dvc->sdtr_able);
  4552. }
  4553. /*
  4554. * Set microcode operating variables for DISC and SDTR_SPEED1,
  4555. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  4556. * configuration values.
  4557. *
  4558. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4559. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4560. * without determining here whether the device supports SDTR.
  4561. */
  4562. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4563. asc_dvc->cfg->disc_enable);
  4564. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  4565. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  4566. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  4567. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  4568. /*
  4569. * Set SCSI_CFG0 Microcode Default Value.
  4570. *
  4571. * The microcode will set the SCSI_CFG0 register using this value
  4572. * after it is started below.
  4573. */
  4574. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4575. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4576. asc_dvc->chip_scsi_id);
  4577. /*
  4578. * Determine SCSI_CFG1 Microcode Default Value.
  4579. *
  4580. * The microcode will set the SCSI_CFG1 register using this value
  4581. * after it is started below.
  4582. */
  4583. /* Read current SCSI_CFG1 Register value. */
  4584. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4585. /*
  4586. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4587. * register signals will be set. Check for and return an error if
  4588. * this condition is found.
  4589. */
  4590. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4591. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4592. return ADV_ERROR;
  4593. }
  4594. /*
  4595. * All kind of combinations of devices attached to one of four
  4596. * connectors are acceptable except HVD device attached. For example,
  4597. * LVD device can be attached to SE connector while SE device attached
  4598. * to LVD connector. If LVD device attached to SE connector, it only
  4599. * runs up to Ultra speed.
  4600. *
  4601. * If an HVD device is attached to one of LVD connectors, return an
  4602. * error. However, there is no way to detect HVD device attached to
  4603. * SE connectors.
  4604. */
  4605. if (scsi_cfg1 & HVD) {
  4606. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  4607. return ADV_ERROR;
  4608. }
  4609. /*
  4610. * If either SE or LVD automatic termination control is enabled, then
  4611. * set the termination value based on a table listed in a_condor.h.
  4612. *
  4613. * If manual termination was specified with an EEPROM setting then
  4614. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  4615. * to be 'ored' into SCSI_CFG1.
  4616. */
  4617. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  4618. /* SE automatic termination control is enabled. */
  4619. switch (scsi_cfg1 & C_DET_SE) {
  4620. /* TERM_SE_HI: on, TERM_SE_LO: on */
  4621. case 0x1:
  4622. case 0x2:
  4623. case 0x3:
  4624. asc_dvc->cfg->termination |= TERM_SE;
  4625. break;
  4626. /* TERM_SE_HI: on, TERM_SE_LO: off */
  4627. case 0x0:
  4628. asc_dvc->cfg->termination |= TERM_SE_HI;
  4629. break;
  4630. }
  4631. }
  4632. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  4633. /* LVD automatic termination control is enabled. */
  4634. switch (scsi_cfg1 & C_DET_LVD) {
  4635. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  4636. case 0x4:
  4637. case 0x8:
  4638. case 0xC:
  4639. asc_dvc->cfg->termination |= TERM_LVD;
  4640. break;
  4641. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  4642. case 0x0:
  4643. break;
  4644. }
  4645. }
  4646. /*
  4647. * Clear any set TERM_SE and TERM_LVD bits.
  4648. */
  4649. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  4650. /*
  4651. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  4652. */
  4653. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  4654. /*
  4655. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  4656. * bits and set possibly modified termination control bits in the
  4657. * Microcode SCSI_CFG1 Register Value.
  4658. */
  4659. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  4660. /*
  4661. * Set SCSI_CFG1 Microcode Default Value
  4662. *
  4663. * Set possibly modified termination control and reset DIS_TERM_DRV
  4664. * bits in the Microcode SCSI_CFG1 Register Value.
  4665. *
  4666. * The microcode will set the SCSI_CFG1 register using this value
  4667. * after it is started below.
  4668. */
  4669. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  4670. /*
  4671. * Set MEM_CFG Microcode Default Value
  4672. *
  4673. * The microcode will set the MEM_CFG register using this value
  4674. * after it is started below.
  4675. *
  4676. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4677. * are defined.
  4678. *
  4679. * ASC-38C0800 has 16KB internal memory.
  4680. */
  4681. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4682. BIOS_EN | RAM_SZ_16KB);
  4683. /*
  4684. * Set SEL_MASK Microcode Default Value
  4685. *
  4686. * The microcode will set the SEL_MASK register using this value
  4687. * after it is started below.
  4688. */
  4689. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4690. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4691. AdvBuildCarrierFreelist(asc_dvc);
  4692. /*
  4693. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4694. */
  4695. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  4696. if (!asc_dvc->icq_sp) {
  4697. ASC_DBG(0, "Failed to get ICQ carrier\n");
  4698. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4699. return ADV_ERROR;
  4700. }
  4701. /*
  4702. * Set RISC ICQ physical address start value.
  4703. * carr_pa is LE, must be native before write
  4704. */
  4705. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4706. /*
  4707. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4708. */
  4709. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  4710. if (!asc_dvc->irq_sp) {
  4711. ASC_DBG(0, "Failed to get IRQ carrier\n");
  4712. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4713. return ADV_ERROR;
  4714. }
  4715. /*
  4716. * Set RISC IRQ physical address start value.
  4717. *
  4718. * carr_pa is LE, must be native before write *
  4719. */
  4720. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4721. asc_dvc->carr_pending_cnt = 0;
  4722. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4723. (ADV_INTR_ENABLE_HOST_INTR |
  4724. ADV_INTR_ENABLE_GLOBAL_INTR));
  4725. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4726. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4727. /* finally, finally, gentlemen, start your engine */
  4728. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4729. /*
  4730. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4731. * Resets should be performed. The RISC has to be running
  4732. * to issue a SCSI Bus Reset.
  4733. */
  4734. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4735. /*
  4736. * If the BIOS Signature is present in memory, restore the
  4737. * BIOS Handshake Configuration Table and do not perform
  4738. * a SCSI Bus Reset.
  4739. */
  4740. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4741. 0x55AA) {
  4742. /*
  4743. * Restore per TID negotiated values.
  4744. */
  4745. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4746. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4747. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4748. tagqng_able);
  4749. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4750. AdvWriteByteLram(iop_base,
  4751. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4752. max_cmd[tid]);
  4753. }
  4754. } else {
  4755. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4756. warn_code = ASC_WARN_BUSRESET_ERROR;
  4757. }
  4758. }
  4759. }
  4760. return warn_code;
  4761. }
  4762. /*
  4763. * Initialize the ASC-38C1600.
  4764. *
  4765. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  4766. *
  4767. * For a non-fatal error return a warning code. If there are no warnings
  4768. * then 0 is returned.
  4769. *
  4770. * Needed after initialization for error recovery.
  4771. */
  4772. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  4773. {
  4774. const struct firmware *fw;
  4775. const char fwname[] = "advansys/38C1600.bin";
  4776. AdvPortAddr iop_base;
  4777. ushort warn_code;
  4778. int begin_addr;
  4779. int end_addr;
  4780. ushort code_sum;
  4781. long word;
  4782. int i;
  4783. int err;
  4784. unsigned long chksum;
  4785. ushort scsi_cfg1;
  4786. uchar byte;
  4787. uchar tid;
  4788. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4789. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  4790. uchar max_cmd[ASC_MAX_TID + 1];
  4791. /* If there is already an error, don't continue. */
  4792. if (asc_dvc->err_code != 0) {
  4793. return ADV_ERROR;
  4794. }
  4795. /*
  4796. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  4797. */
  4798. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  4799. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4800. return ADV_ERROR;
  4801. }
  4802. warn_code = 0;
  4803. iop_base = asc_dvc->iop_base;
  4804. /*
  4805. * Save the RISC memory BIOS region before writing the microcode.
  4806. * The BIOS may already be loaded and using its RISC LRAM region
  4807. * so its region must be saved and restored.
  4808. *
  4809. * Note: This code makes the assumption, which is currently true,
  4810. * that a chip reset does not clear RISC LRAM.
  4811. */
  4812. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4813. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4814. bios_mem[i]);
  4815. }
  4816. /*
  4817. * Save current per TID negotiated values.
  4818. */
  4819. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4820. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4821. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  4822. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4823. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  4824. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4825. max_cmd[tid]);
  4826. }
  4827. /*
  4828. * RAM BIST (Built-In Self Test)
  4829. *
  4830. * Address : I/O base + offset 0x38h register (byte).
  4831. * Function: Bit 7-6(RW) : RAM mode
  4832. * Normal Mode : 0x00
  4833. * Pre-test Mode : 0x40
  4834. * RAM Test Mode : 0x80
  4835. * Bit 5 : unused
  4836. * Bit 4(RO) : Done bit
  4837. * Bit 3-0(RO) : Status
  4838. * Host Error : 0x08
  4839. * Int_RAM Error : 0x04
  4840. * RISC Error : 0x02
  4841. * SCSI Error : 0x01
  4842. * No Error : 0x00
  4843. *
  4844. * Note: RAM BIST code should be put right here, before loading the
  4845. * microcode and after saving the RISC memory BIOS region.
  4846. */
  4847. /*
  4848. * LRAM Pre-test
  4849. *
  4850. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4851. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4852. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4853. * to NORMAL_MODE, return an error too.
  4854. */
  4855. for (i = 0; i < 2; i++) {
  4856. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4857. mdelay(10); /* Wait for 10ms before reading back. */
  4858. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4859. if ((byte & RAM_TEST_DONE) == 0
  4860. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4861. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4862. return ADV_ERROR;
  4863. }
  4864. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4865. mdelay(10); /* Wait for 10ms before reading back. */
  4866. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4867. != NORMAL_VALUE) {
  4868. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4869. return ADV_ERROR;
  4870. }
  4871. }
  4872. /*
  4873. * LRAM Test - It takes about 1.5 ms to run through the test.
  4874. *
  4875. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4876. * If Done bit not set or Status not 0, save register byte, set the
  4877. * err_code, and return an error.
  4878. */
  4879. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4880. mdelay(10); /* Wait for 10ms before checking status. */
  4881. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4882. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4883. /* Get here if Done bit not set or Status not 0. */
  4884. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4885. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4886. return ADV_ERROR;
  4887. }
  4888. /* We need to reset back to normal mode after LRAM test passes. */
  4889. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4890. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4891. if (err) {
  4892. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4893. fwname, err);
  4894. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4895. return err;
  4896. }
  4897. if (fw->size < 4) {
  4898. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4899. fw->size, fwname);
  4900. release_firmware(fw);
  4901. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4902. return -EINVAL;
  4903. }
  4904. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4905. (fw->data[1] << 8) | fw->data[0];
  4906. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4907. fw->size - 4, ADV_38C1600_MEMSIZE,
  4908. chksum);
  4909. release_firmware(fw);
  4910. if (asc_dvc->err_code)
  4911. return ADV_ERROR;
  4912. /*
  4913. * Restore the RISC memory BIOS region.
  4914. */
  4915. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4916. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4917. bios_mem[i]);
  4918. }
  4919. /*
  4920. * Calculate and write the microcode code checksum to the microcode
  4921. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4922. */
  4923. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4924. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4925. code_sum = 0;
  4926. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4927. for (word = begin_addr; word < end_addr; word += 2) {
  4928. code_sum += AdvReadWordAutoIncLram(iop_base);
  4929. }
  4930. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4931. /*
  4932. * Read microcode version and date.
  4933. */
  4934. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4935. asc_dvc->cfg->mcode_date);
  4936. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4937. asc_dvc->cfg->mcode_version);
  4938. /*
  4939. * Set the chip type to indicate the ASC38C1600.
  4940. */
  4941. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  4942. /*
  4943. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4944. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4945. * cable detection and then we are able to read C_DET[3:0].
  4946. *
  4947. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4948. * Microcode Default Value' section below.
  4949. */
  4950. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4951. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4952. scsi_cfg1 | DIS_TERM_DRV);
  4953. /*
  4954. * If the PCI Configuration Command Register "Parity Error Response
  4955. * Control" Bit was clear (0), then set the microcode variable
  4956. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4957. * to ignore DMA parity errors.
  4958. */
  4959. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4960. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4961. word |= CONTROL_FLAG_IGNORE_PERR;
  4962. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4963. }
  4964. /*
  4965. * If the BIOS control flag AIPP (Asynchronous Information
  4966. * Phase Protection) disable bit is not set, then set the firmware
  4967. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  4968. * AIPP checking and encoding.
  4969. */
  4970. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  4971. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4972. word |= CONTROL_FLAG_ENABLE_AIPP;
  4973. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4974. }
  4975. /*
  4976. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  4977. * and START_CTL_TH [3:2].
  4978. */
  4979. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4980. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  4981. /*
  4982. * Microcode operating variables for WDTR, SDTR, and command tag
  4983. * queuing will be set in slave_configure() based on what a
  4984. * device reports it is capable of in Inquiry byte 7.
  4985. *
  4986. * If SCSI Bus Resets have been disabled, then directly set
  4987. * SDTR and WDTR from the EEPROM configuration. This will allow
  4988. * the BIOS and warm boot to work without a SCSI bus hang on
  4989. * the Inquiry caused by host and target mismatched DTR values.
  4990. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4991. * be assumed to be in Asynchronous, Narrow mode.
  4992. */
  4993. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4994. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4995. asc_dvc->wdtr_able);
  4996. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4997. asc_dvc->sdtr_able);
  4998. }
  4999. /*
  5000. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5001. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5002. * configuration values.
  5003. *
  5004. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5005. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5006. * without determining here whether the device supports SDTR.
  5007. */
  5008. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5009. asc_dvc->cfg->disc_enable);
  5010. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5011. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5012. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5013. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5014. /*
  5015. * Set SCSI_CFG0 Microcode Default Value.
  5016. *
  5017. * The microcode will set the SCSI_CFG0 register using this value
  5018. * after it is started below.
  5019. */
  5020. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5021. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5022. asc_dvc->chip_scsi_id);
  5023. /*
  5024. * Calculate SCSI_CFG1 Microcode Default Value.
  5025. *
  5026. * The microcode will set the SCSI_CFG1 register using this value
  5027. * after it is started below.
  5028. *
  5029. * Each ASC-38C1600 function has only two cable detect bits.
  5030. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  5031. */
  5032. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5033. /*
  5034. * If the cable is reversed all of the SCSI_CTRL register signals
  5035. * will be set. Check for and return an error if this condition is
  5036. * found.
  5037. */
  5038. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5039. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5040. return ADV_ERROR;
  5041. }
  5042. /*
  5043. * Each ASC-38C1600 function has two connectors. Only an HVD device
  5044. * can not be connected to either connector. An LVD device or SE device
  5045. * may be connected to either connecor. If an SE device is connected,
  5046. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  5047. *
  5048. * If an HVD device is attached, return an error.
  5049. */
  5050. if (scsi_cfg1 & HVD) {
  5051. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5052. return ADV_ERROR;
  5053. }
  5054. /*
  5055. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5056. * termination because there are two connectors for each function. Each
  5057. * function may use either LVD or SE mode. Corresponding the SE automatic
  5058. * termination control EEPROM bits are used for each function. Each
  5059. * function has its own EEPROM. If SE automatic control is enabled for
  5060. * the function, then set the termination value based on a table listed
  5061. * in a_condor.h.
  5062. *
  5063. * If manual termination is specified in the EEPROM for the function,
  5064. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5065. * ready to be 'ored' into SCSI_CFG1.
  5066. */
  5067. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5068. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5069. /* SE automatic termination control is enabled. */
  5070. switch (scsi_cfg1 & C_DET_SE) {
  5071. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5072. case 0x1:
  5073. case 0x2:
  5074. case 0x3:
  5075. asc_dvc->cfg->termination |= TERM_SE;
  5076. break;
  5077. case 0x0:
  5078. if (PCI_FUNC(pdev->devfn) == 0) {
  5079. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5080. } else {
  5081. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5082. asc_dvc->cfg->termination |= TERM_SE_HI;
  5083. }
  5084. break;
  5085. }
  5086. }
  5087. /*
  5088. * Clear any set TERM_SE bits.
  5089. */
  5090. scsi_cfg1 &= ~TERM_SE;
  5091. /*
  5092. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5093. */
  5094. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5095. /*
  5096. * Clear Big Endian and Terminator Polarity bits and set possibly
  5097. * modified termination control bits in the Microcode SCSI_CFG1
  5098. * Register Value.
  5099. *
  5100. * Big Endian bit is not used even on big endian machines.
  5101. */
  5102. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5103. /*
  5104. * Set SCSI_CFG1 Microcode Default Value
  5105. *
  5106. * Set possibly modified termination control bits in the Microcode
  5107. * SCSI_CFG1 Register Value.
  5108. *
  5109. * The microcode will set the SCSI_CFG1 register using this value
  5110. * after it is started below.
  5111. */
  5112. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5113. /*
  5114. * Set MEM_CFG Microcode Default Value
  5115. *
  5116. * The microcode will set the MEM_CFG register using this value
  5117. * after it is started below.
  5118. *
  5119. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5120. * are defined.
  5121. *
  5122. * ASC-38C1600 has 32KB internal memory.
  5123. *
  5124. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5125. * out a special 16K Adv Library and Microcode version. After the issue
  5126. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5127. * mcode.sas files also need to be updated.
  5128. *
  5129. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5130. * BIOS_EN | RAM_SZ_32KB);
  5131. */
  5132. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5133. BIOS_EN | RAM_SZ_16KB);
  5134. /*
  5135. * Set SEL_MASK Microcode Default Value
  5136. *
  5137. * The microcode will set the SEL_MASK register using this value
  5138. * after it is started below.
  5139. */
  5140. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5141. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5142. AdvBuildCarrierFreelist(asc_dvc);
  5143. /*
  5144. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5145. */
  5146. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  5147. if (!asc_dvc->icq_sp) {
  5148. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5149. return ADV_ERROR;
  5150. }
  5151. /*
  5152. * Set RISC ICQ physical address start value. Initialize the
  5153. * COMMA register to the same value otherwise the RISC will
  5154. * prematurely detect a command is available.
  5155. */
  5156. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5157. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5158. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5159. /*
  5160. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5161. */
  5162. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  5163. if (!asc_dvc->irq_sp) {
  5164. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5165. return ADV_ERROR;
  5166. }
  5167. /*
  5168. * Set RISC IRQ physical address start value.
  5169. */
  5170. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5171. asc_dvc->carr_pending_cnt = 0;
  5172. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5173. (ADV_INTR_ENABLE_HOST_INTR |
  5174. ADV_INTR_ENABLE_GLOBAL_INTR));
  5175. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5176. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5177. /* finally, finally, gentlemen, start your engine */
  5178. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5179. /*
  5180. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5181. * Resets should be performed. The RISC has to be running
  5182. * to issue a SCSI Bus Reset.
  5183. */
  5184. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5185. /*
  5186. * If the BIOS Signature is present in memory, restore the
  5187. * per TID microcode operating variables.
  5188. */
  5189. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5190. 0x55AA) {
  5191. /*
  5192. * Restore per TID negotiated values.
  5193. */
  5194. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5195. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5196. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5197. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5198. tagqng_able);
  5199. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5200. AdvWriteByteLram(iop_base,
  5201. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5202. max_cmd[tid]);
  5203. }
  5204. } else {
  5205. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5206. warn_code = ASC_WARN_BUSRESET_ERROR;
  5207. }
  5208. }
  5209. }
  5210. return warn_code;
  5211. }
  5212. /*
  5213. * Reset chip and SCSI Bus.
  5214. *
  5215. * Return Value:
  5216. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5217. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5218. */
  5219. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5220. {
  5221. int status;
  5222. ushort wdtr_able, sdtr_able, tagqng_able;
  5223. ushort ppr_able = 0;
  5224. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5225. AdvPortAddr iop_base;
  5226. ushort bios_sig;
  5227. iop_base = asc_dvc->iop_base;
  5228. /*
  5229. * Save current per TID negotiated values.
  5230. */
  5231. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5232. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5233. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5234. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5235. }
  5236. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5237. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5238. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5239. max_cmd[tid]);
  5240. }
  5241. /*
  5242. * Force the AdvInitAsc3550/38C0800Driver() function to
  5243. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5244. * The initialization functions assumes a SCSI Bus Reset is not
  5245. * needed if the BIOS signature word is present.
  5246. */
  5247. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5248. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5249. /*
  5250. * Stop chip and reset it.
  5251. */
  5252. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5253. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5254. mdelay(100);
  5255. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5256. ADV_CTRL_REG_CMD_WR_IO_REG);
  5257. /*
  5258. * Reset Adv Library error code, if any, and try
  5259. * re-initializing the chip.
  5260. */
  5261. asc_dvc->err_code = 0;
  5262. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5263. status = AdvInitAsc38C1600Driver(asc_dvc);
  5264. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5265. status = AdvInitAsc38C0800Driver(asc_dvc);
  5266. } else {
  5267. status = AdvInitAsc3550Driver(asc_dvc);
  5268. }
  5269. /* Translate initialization return value to status value. */
  5270. if (status == 0) {
  5271. status = ADV_TRUE;
  5272. } else {
  5273. status = ADV_FALSE;
  5274. }
  5275. /*
  5276. * Restore the BIOS signature word.
  5277. */
  5278. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5279. /*
  5280. * Restore per TID negotiated values.
  5281. */
  5282. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5283. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5284. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5285. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5286. }
  5287. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5288. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5289. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5290. max_cmd[tid]);
  5291. }
  5292. return status;
  5293. }
  5294. /*
  5295. * adv_async_callback() - Adv Library asynchronous event callback function.
  5296. */
  5297. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5298. {
  5299. switch (code) {
  5300. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5301. /*
  5302. * The firmware detected a SCSI Bus reset.
  5303. */
  5304. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5305. break;
  5306. case ADV_ASYNC_RDMA_FAILURE:
  5307. /*
  5308. * Handle RDMA failure by resetting the SCSI Bus and
  5309. * possibly the chip if it is unresponsive. Log the error
  5310. * with a unique code.
  5311. */
  5312. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5313. AdvResetChipAndSB(adv_dvc_varp);
  5314. break;
  5315. case ADV_HOST_SCSI_BUS_RESET:
  5316. /*
  5317. * Host generated SCSI bus reset occurred.
  5318. */
  5319. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5320. break;
  5321. default:
  5322. ASC_DBG(0, "unknown code 0x%x\n", code);
  5323. break;
  5324. }
  5325. }
  5326. /*
  5327. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5328. *
  5329. * Callback function for the Wide SCSI Adv Library.
  5330. */
  5331. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5332. {
  5333. struct asc_board *boardp = adv_dvc_varp->drv_ptr;
  5334. u32 srb_tag;
  5335. adv_req_t *reqp;
  5336. adv_sgblk_t *sgblkp;
  5337. struct scsi_cmnd *scp;
  5338. u32 resid_cnt;
  5339. dma_addr_t sense_addr;
  5340. ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n",
  5341. adv_dvc_varp, scsiqp);
  5342. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5343. /*
  5344. * Get the adv_req_t structure for the command that has been
  5345. * completed. The adv_req_t structure actually contains the
  5346. * completed ADV_SCSI_REQ_Q structure.
  5347. */
  5348. srb_tag = le32_to_cpu(scsiqp->srb_tag);
  5349. scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag);
  5350. ASC_DBG(1, "scp 0x%p\n", scp);
  5351. if (scp == NULL) {
  5352. ASC_PRINT
  5353. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  5354. return;
  5355. }
  5356. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  5357. reqp = (adv_req_t *)scp->host_scribble;
  5358. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  5359. if (reqp == NULL) {
  5360. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  5361. return;
  5362. }
  5363. /*
  5364. * Remove backreferences to avoid duplicate
  5365. * command completions.
  5366. */
  5367. scp->host_scribble = NULL;
  5368. reqp->cmndp = NULL;
  5369. ASC_STATS(boardp->shost, callback);
  5370. ASC_DBG(1, "shost 0x%p\n", boardp->shost);
  5371. sense_addr = le32_to_cpu(scsiqp->sense_addr);
  5372. dma_unmap_single(boardp->dev, sense_addr,
  5373. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  5374. /*
  5375. * 'done_status' contains the command's ending status.
  5376. */
  5377. switch (scsiqp->done_status) {
  5378. case QD_NO_ERROR:
  5379. ASC_DBG(2, "QD_NO_ERROR\n");
  5380. scp->result = 0;
  5381. /*
  5382. * Check for an underrun condition.
  5383. *
  5384. * If there was no error and an underrun condition, then
  5385. * then return the number of underrun bytes.
  5386. */
  5387. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  5388. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  5389. resid_cnt <= scsi_bufflen(scp)) {
  5390. ASC_DBG(1, "underrun condition %lu bytes\n",
  5391. (ulong)resid_cnt);
  5392. scsi_set_resid(scp, resid_cnt);
  5393. }
  5394. break;
  5395. case QD_WITH_ERROR:
  5396. ASC_DBG(2, "QD_WITH_ERROR\n");
  5397. switch (scsiqp->host_status) {
  5398. case QHSTA_NO_ERROR:
  5399. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  5400. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  5401. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  5402. SCSI_SENSE_BUFFERSIZE);
  5403. /*
  5404. * Note: The 'status_byte()' macro used by
  5405. * target drivers defined in scsi.h shifts the
  5406. * status byte returned by host drivers right
  5407. * by 1 bit. This is why target drivers also
  5408. * use right shifted status byte definitions.
  5409. * For instance target drivers use
  5410. * CHECK_CONDITION, defined to 0x1, instead of
  5411. * the SCSI defined check condition value of
  5412. * 0x2. Host drivers are supposed to return
  5413. * the status byte as it is defined by SCSI.
  5414. */
  5415. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  5416. STATUS_BYTE(scsiqp->scsi_status);
  5417. } else {
  5418. scp->result = STATUS_BYTE(scsiqp->scsi_status);
  5419. }
  5420. break;
  5421. default:
  5422. /* Some other QHSTA error occurred. */
  5423. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  5424. scp->result = HOST_BYTE(DID_BAD_TARGET);
  5425. break;
  5426. }
  5427. break;
  5428. case QD_ABORTED_BY_HOST:
  5429. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  5430. scp->result =
  5431. HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
  5432. break;
  5433. default:
  5434. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  5435. scp->result =
  5436. HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
  5437. break;
  5438. }
  5439. /*
  5440. * If the 'init_tidmask' bit isn't already set for the target and the
  5441. * current request finished normally, then set the bit for the target
  5442. * to indicate that a device is present.
  5443. */
  5444. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  5445. scsiqp->done_status == QD_NO_ERROR &&
  5446. scsiqp->host_status == QHSTA_NO_ERROR) {
  5447. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  5448. }
  5449. asc_scsi_done(scp);
  5450. /*
  5451. * Free all 'adv_sgblk_t' structures allocated for the request.
  5452. */
  5453. while ((sgblkp = reqp->sgblkp) != NULL) {
  5454. /* Remove 'sgblkp' from the request list. */
  5455. reqp->sgblkp = sgblkp->next_sgblkp;
  5456. dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
  5457. sgblkp->sg_addr);
  5458. }
  5459. ASC_DBG(1, "done\n");
  5460. }
  5461. /*
  5462. * Adv Library Interrupt Service Routine
  5463. *
  5464. * This function is called by a driver's interrupt service routine.
  5465. * The function disables and re-enables interrupts.
  5466. *
  5467. * When a microcode idle command is completed, the ADV_DVC_VAR
  5468. * 'idle_cmd_done' field is set to ADV_TRUE.
  5469. *
  5470. * Note: AdvISR() can be called when interrupts are disabled or even
  5471. * when there is no hardware interrupt condition present. It will
  5472. * always check for completed idle commands and microcode requests.
  5473. * This is an important feature that shouldn't be changed because it
  5474. * allows commands to be completed from polling mode loops.
  5475. *
  5476. * Return:
  5477. * ADV_TRUE(1) - interrupt was pending
  5478. * ADV_FALSE(0) - no interrupt was pending
  5479. */
  5480. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  5481. {
  5482. AdvPortAddr iop_base;
  5483. uchar int_stat;
  5484. ushort target_bit;
  5485. ADV_CARR_T *free_carrp;
  5486. __le32 irq_next_vpa;
  5487. ADV_SCSI_REQ_Q *scsiq;
  5488. adv_req_t *reqp;
  5489. iop_base = asc_dvc->iop_base;
  5490. /* Reading the register clears the interrupt. */
  5491. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  5492. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  5493. ADV_INTR_STATUS_INTRC)) == 0) {
  5494. return ADV_FALSE;
  5495. }
  5496. /*
  5497. * Notify the driver of an asynchronous microcode condition by
  5498. * calling the adv_async_callback function. The function
  5499. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  5500. */
  5501. if (int_stat & ADV_INTR_STATUS_INTRB) {
  5502. uchar intrb_code;
  5503. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  5504. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  5505. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5506. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  5507. asc_dvc->carr_pending_cnt != 0) {
  5508. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  5509. ADV_TICKLE_A);
  5510. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  5511. AdvWriteByteRegister(iop_base,
  5512. IOPB_TICKLE,
  5513. ADV_TICKLE_NOP);
  5514. }
  5515. }
  5516. }
  5517. adv_async_callback(asc_dvc, intrb_code);
  5518. }
  5519. /*
  5520. * Check if the IRQ stopper carrier contains a completed request.
  5521. */
  5522. while (((irq_next_vpa =
  5523. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ADV_RQ_DONE) != 0) {
  5524. /*
  5525. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  5526. * The RISC will have set 'areq_vpa' to a virtual address.
  5527. *
  5528. * The firmware will have copied the ADV_SCSI_REQ_Q.scsiq_ptr
  5529. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  5530. * below complements the conversion of ADV_SCSI_REQ_Q.scsiq_ptr'
  5531. * in AdvExeScsiQueue().
  5532. */
  5533. u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa);
  5534. ASC_DBG(1, "irq_sp %p areq_vpa %u\n",
  5535. asc_dvc->irq_sp, pa_offset);
  5536. reqp = adv_get_reqp(asc_dvc, pa_offset);
  5537. scsiq = &reqp->scsi_req_q;
  5538. /*
  5539. * Request finished with good status and the queue was not
  5540. * DMAed to host memory by the firmware. Set all status fields
  5541. * to indicate good status.
  5542. */
  5543. if ((irq_next_vpa & ADV_RQ_GOOD) != 0) {
  5544. scsiq->done_status = QD_NO_ERROR;
  5545. scsiq->host_status = scsiq->scsi_status = 0;
  5546. scsiq->data_cnt = 0L;
  5547. }
  5548. /*
  5549. * Advance the stopper pointer to the next carrier
  5550. * ignoring the lower four bits. Free the previous
  5551. * stopper carrier.
  5552. */
  5553. free_carrp = asc_dvc->irq_sp;
  5554. asc_dvc->irq_sp = adv_get_carrier(asc_dvc,
  5555. ADV_GET_CARRP(irq_next_vpa));
  5556. free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va;
  5557. asc_dvc->carr_freelist = free_carrp;
  5558. asc_dvc->carr_pending_cnt--;
  5559. target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
  5560. /*
  5561. * Clear request microcode control flag.
  5562. */
  5563. scsiq->cntl = 0;
  5564. /*
  5565. * Notify the driver of the completed request by passing
  5566. * the ADV_SCSI_REQ_Q pointer to its callback function.
  5567. */
  5568. adv_isr_callback(asc_dvc, scsiq);
  5569. /*
  5570. * Note: After the driver callback function is called, 'scsiq'
  5571. * can no longer be referenced.
  5572. *
  5573. * Fall through and continue processing other completed
  5574. * requests...
  5575. */
  5576. }
  5577. return ADV_TRUE;
  5578. }
  5579. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  5580. {
  5581. if (asc_dvc->err_code == 0) {
  5582. asc_dvc->err_code = err_code;
  5583. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  5584. err_code);
  5585. }
  5586. return err_code;
  5587. }
  5588. static void AscAckInterrupt(PortAddr iop_base)
  5589. {
  5590. uchar host_flag;
  5591. uchar risc_flag;
  5592. ushort loop;
  5593. loop = 0;
  5594. do {
  5595. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  5596. if (loop++ > 0x7FFF) {
  5597. break;
  5598. }
  5599. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  5600. host_flag =
  5601. AscReadLramByte(iop_base,
  5602. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  5603. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  5604. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  5605. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5606. loop = 0;
  5607. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  5608. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5609. if (loop++ > 3) {
  5610. break;
  5611. }
  5612. }
  5613. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  5614. }
  5615. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  5616. {
  5617. const uchar *period_table;
  5618. int max_index;
  5619. int min_index;
  5620. int i;
  5621. period_table = asc_dvc->sdtr_period_tbl;
  5622. max_index = (int)asc_dvc->max_sdtr_index;
  5623. min_index = (int)asc_dvc->min_sdtr_index;
  5624. if ((syn_time <= period_table[max_index])) {
  5625. for (i = min_index; i < (max_index - 1); i++) {
  5626. if (syn_time <= period_table[i]) {
  5627. return (uchar)i;
  5628. }
  5629. }
  5630. return (uchar)max_index;
  5631. } else {
  5632. return (uchar)(max_index + 1);
  5633. }
  5634. }
  5635. static uchar
  5636. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  5637. {
  5638. PortAddr iop_base = asc_dvc->iop_base;
  5639. uchar sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5640. EXT_MSG sdtr_buf = {
  5641. .msg_type = EXTENDED_MESSAGE,
  5642. .msg_len = MS_SDTR_LEN,
  5643. .msg_req = EXTENDED_SDTR,
  5644. .xfer_period = sdtr_period,
  5645. .req_ack_offset = sdtr_offset,
  5646. };
  5647. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  5648. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  5649. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5650. (uchar *)&sdtr_buf,
  5651. sizeof(EXT_MSG) >> 1);
  5652. return ((sdtr_period_index << 4) | sdtr_offset);
  5653. } else {
  5654. sdtr_buf.req_ack_offset = 0;
  5655. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5656. (uchar *)&sdtr_buf,
  5657. sizeof(EXT_MSG) >> 1);
  5658. return 0;
  5659. }
  5660. }
  5661. static uchar
  5662. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  5663. {
  5664. uchar byte;
  5665. uchar sdtr_period_ix;
  5666. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5667. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  5668. return 0xFF;
  5669. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  5670. return byte;
  5671. }
  5672. static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  5673. {
  5674. ASC_SCSI_BIT_ID_TYPE org_id;
  5675. int i;
  5676. bool sta = true;
  5677. AscSetBank(iop_base, 1);
  5678. org_id = AscReadChipDvcID(iop_base);
  5679. for (i = 0; i <= ASC_MAX_TID; i++) {
  5680. if (org_id == (0x01 << i))
  5681. break;
  5682. }
  5683. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  5684. AscWriteChipDvcID(iop_base, id);
  5685. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  5686. AscSetBank(iop_base, 0);
  5687. AscSetChipSyn(iop_base, sdtr_data);
  5688. if (AscGetChipSyn(iop_base) != sdtr_data) {
  5689. sta = false;
  5690. }
  5691. } else {
  5692. sta = false;
  5693. }
  5694. AscSetBank(iop_base, 1);
  5695. AscWriteChipDvcID(iop_base, org_id);
  5696. AscSetBank(iop_base, 0);
  5697. return (sta);
  5698. }
  5699. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  5700. {
  5701. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  5702. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  5703. }
  5704. static void AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  5705. {
  5706. EXT_MSG ext_msg;
  5707. EXT_MSG out_msg;
  5708. ushort halt_q_addr;
  5709. bool sdtr_accept;
  5710. ushort int_halt_code;
  5711. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  5712. ASC_SCSI_BIT_ID_TYPE target_id;
  5713. PortAddr iop_base;
  5714. uchar tag_code;
  5715. uchar q_status;
  5716. uchar halt_qp;
  5717. uchar sdtr_data;
  5718. uchar target_ix;
  5719. uchar q_cntl, tid_no;
  5720. uchar cur_dvc_qng;
  5721. uchar asyn_sdtr;
  5722. uchar scsi_status;
  5723. struct asc_board *boardp;
  5724. BUG_ON(!asc_dvc->drv_ptr);
  5725. boardp = asc_dvc->drv_ptr;
  5726. iop_base = asc_dvc->iop_base;
  5727. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  5728. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  5729. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  5730. target_ix = AscReadLramByte(iop_base,
  5731. (ushort)(halt_q_addr +
  5732. (ushort)ASC_SCSIQ_B_TARGET_IX));
  5733. q_cntl = AscReadLramByte(iop_base,
  5734. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  5735. tid_no = ASC_TIX_TO_TID(target_ix);
  5736. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  5737. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5738. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  5739. } else {
  5740. asyn_sdtr = 0;
  5741. }
  5742. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  5743. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5744. AscSetChipSDTR(iop_base, 0, tid_no);
  5745. boardp->sdtr_data[tid_no] = 0;
  5746. }
  5747. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5748. return;
  5749. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  5750. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5751. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5752. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5753. }
  5754. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5755. return;
  5756. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  5757. AscMemWordCopyPtrFromLram(iop_base,
  5758. ASCV_MSGIN_BEG,
  5759. (uchar *)&ext_msg,
  5760. sizeof(EXT_MSG) >> 1);
  5761. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5762. ext_msg.msg_req == EXTENDED_SDTR &&
  5763. ext_msg.msg_len == MS_SDTR_LEN) {
  5764. sdtr_accept = true;
  5765. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  5766. sdtr_accept = false;
  5767. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  5768. }
  5769. if ((ext_msg.xfer_period <
  5770. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  5771. || (ext_msg.xfer_period >
  5772. asc_dvc->sdtr_period_tbl[asc_dvc->
  5773. max_sdtr_index])) {
  5774. sdtr_accept = false;
  5775. ext_msg.xfer_period =
  5776. asc_dvc->sdtr_period_tbl[asc_dvc->
  5777. min_sdtr_index];
  5778. }
  5779. if (sdtr_accept) {
  5780. sdtr_data =
  5781. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  5782. ext_msg.req_ack_offset);
  5783. if ((sdtr_data == 0xFF)) {
  5784. q_cntl |= QC_MSG_OUT;
  5785. asc_dvc->init_sdtr &= ~target_id;
  5786. asc_dvc->sdtr_done &= ~target_id;
  5787. AscSetChipSDTR(iop_base, asyn_sdtr,
  5788. tid_no);
  5789. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5790. }
  5791. }
  5792. if (ext_msg.req_ack_offset == 0) {
  5793. q_cntl &= ~QC_MSG_OUT;
  5794. asc_dvc->init_sdtr &= ~target_id;
  5795. asc_dvc->sdtr_done &= ~target_id;
  5796. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5797. } else {
  5798. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  5799. q_cntl &= ~QC_MSG_OUT;
  5800. asc_dvc->sdtr_done |= target_id;
  5801. asc_dvc->init_sdtr |= target_id;
  5802. asc_dvc->pci_fix_asyn_xfer &=
  5803. ~target_id;
  5804. sdtr_data =
  5805. AscCalSDTRData(asc_dvc,
  5806. ext_msg.xfer_period,
  5807. ext_msg.
  5808. req_ack_offset);
  5809. AscSetChipSDTR(iop_base, sdtr_data,
  5810. tid_no);
  5811. boardp->sdtr_data[tid_no] = sdtr_data;
  5812. } else {
  5813. q_cntl |= QC_MSG_OUT;
  5814. AscMsgOutSDTR(asc_dvc,
  5815. ext_msg.xfer_period,
  5816. ext_msg.req_ack_offset);
  5817. asc_dvc->pci_fix_asyn_xfer &=
  5818. ~target_id;
  5819. sdtr_data =
  5820. AscCalSDTRData(asc_dvc,
  5821. ext_msg.xfer_period,
  5822. ext_msg.
  5823. req_ack_offset);
  5824. AscSetChipSDTR(iop_base, sdtr_data,
  5825. tid_no);
  5826. boardp->sdtr_data[tid_no] = sdtr_data;
  5827. asc_dvc->sdtr_done |= target_id;
  5828. asc_dvc->init_sdtr |= target_id;
  5829. }
  5830. }
  5831. AscWriteLramByte(iop_base,
  5832. (ushort)(halt_q_addr +
  5833. (ushort)ASC_SCSIQ_B_CNTL),
  5834. q_cntl);
  5835. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5836. return;
  5837. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5838. ext_msg.msg_req == EXTENDED_WDTR &&
  5839. ext_msg.msg_len == MS_WDTR_LEN) {
  5840. ext_msg.wdtr_width = 0;
  5841. AscMemWordCopyPtrToLram(iop_base,
  5842. ASCV_MSGOUT_BEG,
  5843. (uchar *)&ext_msg,
  5844. sizeof(EXT_MSG) >> 1);
  5845. q_cntl |= QC_MSG_OUT;
  5846. AscWriteLramByte(iop_base,
  5847. (ushort)(halt_q_addr +
  5848. (ushort)ASC_SCSIQ_B_CNTL),
  5849. q_cntl);
  5850. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5851. return;
  5852. } else {
  5853. ext_msg.msg_type = MESSAGE_REJECT;
  5854. AscMemWordCopyPtrToLram(iop_base,
  5855. ASCV_MSGOUT_BEG,
  5856. (uchar *)&ext_msg,
  5857. sizeof(EXT_MSG) >> 1);
  5858. q_cntl |= QC_MSG_OUT;
  5859. AscWriteLramByte(iop_base,
  5860. (ushort)(halt_q_addr +
  5861. (ushort)ASC_SCSIQ_B_CNTL),
  5862. q_cntl);
  5863. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5864. return;
  5865. }
  5866. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  5867. q_cntl |= QC_REQ_SENSE;
  5868. if ((asc_dvc->init_sdtr & target_id) != 0) {
  5869. asc_dvc->sdtr_done &= ~target_id;
  5870. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  5871. q_cntl |= QC_MSG_OUT;
  5872. AscMsgOutSDTR(asc_dvc,
  5873. asc_dvc->
  5874. sdtr_period_tbl[(sdtr_data >> 4) &
  5875. (uchar)(asc_dvc->
  5876. max_sdtr_index -
  5877. 1)],
  5878. (uchar)(sdtr_data & (uchar)
  5879. ASC_SYN_MAX_OFFSET));
  5880. }
  5881. AscWriteLramByte(iop_base,
  5882. (ushort)(halt_q_addr +
  5883. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  5884. tag_code = AscReadLramByte(iop_base,
  5885. (ushort)(halt_q_addr + (ushort)
  5886. ASC_SCSIQ_B_TAG_CODE));
  5887. tag_code &= 0xDC;
  5888. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  5889. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  5890. ) {
  5891. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  5892. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  5893. }
  5894. AscWriteLramByte(iop_base,
  5895. (ushort)(halt_q_addr +
  5896. (ushort)ASC_SCSIQ_B_TAG_CODE),
  5897. tag_code);
  5898. q_status = AscReadLramByte(iop_base,
  5899. (ushort)(halt_q_addr + (ushort)
  5900. ASC_SCSIQ_B_STATUS));
  5901. q_status |= (QS_READY | QS_BUSY);
  5902. AscWriteLramByte(iop_base,
  5903. (ushort)(halt_q_addr +
  5904. (ushort)ASC_SCSIQ_B_STATUS),
  5905. q_status);
  5906. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  5907. scsi_busy &= ~target_id;
  5908. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  5909. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5910. return;
  5911. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  5912. AscMemWordCopyPtrFromLram(iop_base,
  5913. ASCV_MSGOUT_BEG,
  5914. (uchar *)&out_msg,
  5915. sizeof(EXT_MSG) >> 1);
  5916. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  5917. (out_msg.msg_len == MS_SDTR_LEN) &&
  5918. (out_msg.msg_req == EXTENDED_SDTR)) {
  5919. asc_dvc->init_sdtr &= ~target_id;
  5920. asc_dvc->sdtr_done &= ~target_id;
  5921. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5922. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5923. }
  5924. q_cntl &= ~QC_MSG_OUT;
  5925. AscWriteLramByte(iop_base,
  5926. (ushort)(halt_q_addr +
  5927. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  5928. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5929. return;
  5930. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  5931. scsi_status = AscReadLramByte(iop_base,
  5932. (ushort)((ushort)halt_q_addr +
  5933. (ushort)
  5934. ASC_SCSIQ_SCSI_STATUS));
  5935. cur_dvc_qng =
  5936. AscReadLramByte(iop_base,
  5937. (ushort)((ushort)ASC_QADR_BEG +
  5938. (ushort)target_ix));
  5939. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  5940. scsi_busy = AscReadLramByte(iop_base,
  5941. (ushort)ASCV_SCSIBUSY_B);
  5942. scsi_busy |= target_id;
  5943. AscWriteLramByte(iop_base,
  5944. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  5945. asc_dvc->queue_full_or_busy |= target_id;
  5946. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  5947. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  5948. cur_dvc_qng -= 1;
  5949. asc_dvc->max_dvc_qng[tid_no] =
  5950. cur_dvc_qng;
  5951. AscWriteLramByte(iop_base,
  5952. (ushort)((ushort)
  5953. ASCV_MAX_DVC_QNG_BEG
  5954. + (ushort)
  5955. tid_no),
  5956. cur_dvc_qng);
  5957. /*
  5958. * Set the device queue depth to the
  5959. * number of active requests when the
  5960. * QUEUE FULL condition was encountered.
  5961. */
  5962. boardp->queue_full |= target_id;
  5963. boardp->queue_full_cnt[tid_no] =
  5964. cur_dvc_qng;
  5965. }
  5966. }
  5967. }
  5968. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5969. return;
  5970. }
  5971. return;
  5972. }
  5973. /*
  5974. * void
  5975. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  5976. *
  5977. * Calling/Exit State:
  5978. * none
  5979. *
  5980. * Description:
  5981. * Input an ASC_QDONE_INFO structure from the chip
  5982. */
  5983. static void
  5984. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  5985. {
  5986. int i;
  5987. ushort word;
  5988. AscSetChipLramAddr(iop_base, s_addr);
  5989. for (i = 0; i < 2 * words; i += 2) {
  5990. if (i == 10) {
  5991. continue;
  5992. }
  5993. word = inpw(iop_base + IOP_RAM_DATA);
  5994. inbuf[i] = word & 0xff;
  5995. inbuf[i + 1] = (word >> 8) & 0xff;
  5996. }
  5997. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  5998. }
  5999. static uchar
  6000. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  6001. ushort q_addr,
  6002. ASC_QDONE_INFO *scsiq, unsigned int max_dma_count)
  6003. {
  6004. ushort _val;
  6005. uchar sg_queue_cnt;
  6006. DvcGetQinfo(iop_base,
  6007. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  6008. (uchar *)scsiq,
  6009. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  6010. _val = AscReadLramWord(iop_base,
  6011. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  6012. scsiq->q_status = (uchar)_val;
  6013. scsiq->q_no = (uchar)(_val >> 8);
  6014. _val = AscReadLramWord(iop_base,
  6015. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6016. scsiq->cntl = (uchar)_val;
  6017. sg_queue_cnt = (uchar)(_val >> 8);
  6018. _val = AscReadLramWord(iop_base,
  6019. (ushort)(q_addr +
  6020. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  6021. scsiq->sense_len = (uchar)_val;
  6022. scsiq->extra_bytes = (uchar)(_val >> 8);
  6023. /*
  6024. * Read high word of remain bytes from alternate location.
  6025. */
  6026. scsiq->remain_bytes = (((u32)AscReadLramWord(iop_base,
  6027. (ushort)(q_addr +
  6028. (ushort)
  6029. ASC_SCSIQ_W_ALT_DC1)))
  6030. << 16);
  6031. /*
  6032. * Read low word of remain bytes from original location.
  6033. */
  6034. scsiq->remain_bytes += AscReadLramWord(iop_base,
  6035. (ushort)(q_addr + (ushort)
  6036. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  6037. scsiq->remain_bytes &= max_dma_count;
  6038. return sg_queue_cnt;
  6039. }
  6040. /*
  6041. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  6042. *
  6043. * Interrupt callback function for the Narrow SCSI Asc Library.
  6044. */
  6045. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  6046. {
  6047. struct asc_board *boardp = asc_dvc_varp->drv_ptr;
  6048. u32 srb_tag;
  6049. struct scsi_cmnd *scp;
  6050. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  6051. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  6052. /*
  6053. * Decrease the srb_tag by 1 to find the SCSI command
  6054. */
  6055. srb_tag = qdonep->d2.srb_tag - 1;
  6056. scp = scsi_host_find_tag(boardp->shost, srb_tag);
  6057. if (!scp)
  6058. return;
  6059. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6060. ASC_STATS(boardp->shost, callback);
  6061. dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
  6062. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6063. /*
  6064. * 'qdonep' contains the command's ending status.
  6065. */
  6066. switch (qdonep->d3.done_stat) {
  6067. case QD_NO_ERROR:
  6068. ASC_DBG(2, "QD_NO_ERROR\n");
  6069. scp->result = 0;
  6070. /*
  6071. * Check for an underrun condition.
  6072. *
  6073. * If there was no error and an underrun condition, then
  6074. * return the number of underrun bytes.
  6075. */
  6076. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6077. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6078. ASC_DBG(1, "underrun condition %u bytes\n",
  6079. (unsigned)qdonep->remain_bytes);
  6080. scsi_set_resid(scp, qdonep->remain_bytes);
  6081. }
  6082. break;
  6083. case QD_WITH_ERROR:
  6084. ASC_DBG(2, "QD_WITH_ERROR\n");
  6085. switch (qdonep->d3.host_stat) {
  6086. case QHSTA_NO_ERROR:
  6087. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6088. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6089. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6090. SCSI_SENSE_BUFFERSIZE);
  6091. /*
  6092. * Note: The 'status_byte()' macro used by
  6093. * target drivers defined in scsi.h shifts the
  6094. * status byte returned by host drivers right
  6095. * by 1 bit. This is why target drivers also
  6096. * use right shifted status byte definitions.
  6097. * For instance target drivers use
  6098. * CHECK_CONDITION, defined to 0x1, instead of
  6099. * the SCSI defined check condition value of
  6100. * 0x2. Host drivers are supposed to return
  6101. * the status byte as it is defined by SCSI.
  6102. */
  6103. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6104. STATUS_BYTE(qdonep->d3.scsi_stat);
  6105. } else {
  6106. scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
  6107. }
  6108. break;
  6109. default:
  6110. /* QHSTA error occurred */
  6111. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6112. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6113. break;
  6114. }
  6115. break;
  6116. case QD_ABORTED_BY_HOST:
  6117. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6118. scp->result =
  6119. HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
  6120. scsi_msg) |
  6121. STATUS_BYTE(qdonep->d3.scsi_stat);
  6122. break;
  6123. default:
  6124. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6125. scp->result =
  6126. HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
  6127. scsi_msg) |
  6128. STATUS_BYTE(qdonep->d3.scsi_stat);
  6129. break;
  6130. }
  6131. /*
  6132. * If the 'init_tidmask' bit isn't already set for the target and the
  6133. * current request finished normally, then set the bit for the target
  6134. * to indicate that a device is present.
  6135. */
  6136. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6137. qdonep->d3.done_stat == QD_NO_ERROR &&
  6138. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6139. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6140. }
  6141. asc_scsi_done(scp);
  6142. }
  6143. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6144. {
  6145. uchar next_qp;
  6146. uchar n_q_used;
  6147. uchar sg_list_qp;
  6148. uchar sg_queue_cnt;
  6149. uchar q_cnt;
  6150. uchar done_q_tail;
  6151. uchar tid_no;
  6152. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6153. ASC_SCSI_BIT_ID_TYPE target_id;
  6154. PortAddr iop_base;
  6155. ushort q_addr;
  6156. ushort sg_q_addr;
  6157. uchar cur_target_qng;
  6158. ASC_QDONE_INFO scsiq_buf;
  6159. ASC_QDONE_INFO *scsiq;
  6160. bool false_overrun;
  6161. iop_base = asc_dvc->iop_base;
  6162. n_q_used = 1;
  6163. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6164. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6165. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6166. next_qp = AscReadLramByte(iop_base,
  6167. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6168. if (next_qp != ASC_QLINK_END) {
  6169. AscPutVarDoneQTail(iop_base, next_qp);
  6170. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6171. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6172. asc_dvc->max_dma_count);
  6173. AscWriteLramByte(iop_base,
  6174. (ushort)(q_addr +
  6175. (ushort)ASC_SCSIQ_B_STATUS),
  6176. (uchar)(scsiq->
  6177. q_status & (uchar)~(QS_READY |
  6178. QS_ABORTED)));
  6179. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6180. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6181. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6182. sg_q_addr = q_addr;
  6183. sg_list_qp = next_qp;
  6184. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6185. sg_list_qp = AscReadLramByte(iop_base,
  6186. (ushort)(sg_q_addr
  6187. + (ushort)
  6188. ASC_SCSIQ_B_FWD));
  6189. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6190. if (sg_list_qp == ASC_QLINK_END) {
  6191. AscSetLibErrorCode(asc_dvc,
  6192. ASCQ_ERR_SG_Q_LINKS);
  6193. scsiq->d3.done_stat = QD_WITH_ERROR;
  6194. scsiq->d3.host_stat =
  6195. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6196. goto FATAL_ERR_QDONE;
  6197. }
  6198. AscWriteLramByte(iop_base,
  6199. (ushort)(sg_q_addr + (ushort)
  6200. ASC_SCSIQ_B_STATUS),
  6201. QS_FREE);
  6202. }
  6203. n_q_used = sg_queue_cnt + 1;
  6204. AscPutVarDoneQTail(iop_base, sg_list_qp);
  6205. }
  6206. if (asc_dvc->queue_full_or_busy & target_id) {
  6207. cur_target_qng = AscReadLramByte(iop_base,
  6208. (ushort)((ushort)
  6209. ASC_QADR_BEG
  6210. + (ushort)
  6211. scsiq->d2.
  6212. target_ix));
  6213. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  6214. scsi_busy = AscReadLramByte(iop_base, (ushort)
  6215. ASCV_SCSIBUSY_B);
  6216. scsi_busy &= ~target_id;
  6217. AscWriteLramByte(iop_base,
  6218. (ushort)ASCV_SCSIBUSY_B,
  6219. scsi_busy);
  6220. asc_dvc->queue_full_or_busy &= ~target_id;
  6221. }
  6222. }
  6223. if (asc_dvc->cur_total_qng >= n_q_used) {
  6224. asc_dvc->cur_total_qng -= n_q_used;
  6225. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  6226. asc_dvc->cur_dvc_qng[tid_no]--;
  6227. }
  6228. } else {
  6229. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  6230. scsiq->d3.done_stat = QD_WITH_ERROR;
  6231. goto FATAL_ERR_QDONE;
  6232. }
  6233. if ((scsiq->d2.srb_tag == 0UL) ||
  6234. ((scsiq->q_status & QS_ABORTED) != 0)) {
  6235. return (0x11);
  6236. } else if (scsiq->q_status == QS_DONE) {
  6237. /*
  6238. * This is also curious.
  6239. * false_overrun will _always_ be set to 'false'
  6240. */
  6241. false_overrun = false;
  6242. if (scsiq->extra_bytes != 0) {
  6243. scsiq->remain_bytes += scsiq->extra_bytes;
  6244. }
  6245. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  6246. if (scsiq->d3.host_stat ==
  6247. QHSTA_M_DATA_OVER_RUN) {
  6248. if ((scsiq->
  6249. cntl & (QC_DATA_IN | QC_DATA_OUT))
  6250. == 0) {
  6251. scsiq->d3.done_stat =
  6252. QD_NO_ERROR;
  6253. scsiq->d3.host_stat =
  6254. QHSTA_NO_ERROR;
  6255. } else if (false_overrun) {
  6256. scsiq->d3.done_stat =
  6257. QD_NO_ERROR;
  6258. scsiq->d3.host_stat =
  6259. QHSTA_NO_ERROR;
  6260. }
  6261. } else if (scsiq->d3.host_stat ==
  6262. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  6263. AscStopChip(iop_base);
  6264. AscSetChipControl(iop_base,
  6265. (uchar)(CC_SCSI_RESET
  6266. | CC_HALT));
  6267. udelay(60);
  6268. AscSetChipControl(iop_base, CC_HALT);
  6269. AscSetChipStatus(iop_base,
  6270. CIW_CLR_SCSI_RESET_INT);
  6271. AscSetChipStatus(iop_base, 0);
  6272. AscSetChipControl(iop_base, 0);
  6273. }
  6274. }
  6275. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6276. asc_isr_callback(asc_dvc, scsiq);
  6277. } else {
  6278. if ((AscReadLramByte(iop_base,
  6279. (ushort)(q_addr + (ushort)
  6280. ASC_SCSIQ_CDB_BEG))
  6281. == START_STOP)) {
  6282. asc_dvc->unit_not_ready &= ~target_id;
  6283. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  6284. asc_dvc->start_motor &=
  6285. ~target_id;
  6286. }
  6287. }
  6288. }
  6289. return (1);
  6290. } else {
  6291. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  6292. FATAL_ERR_QDONE:
  6293. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6294. asc_isr_callback(asc_dvc, scsiq);
  6295. }
  6296. return (0x80);
  6297. }
  6298. }
  6299. return (0);
  6300. }
  6301. static int AscISR(ASC_DVC_VAR *asc_dvc)
  6302. {
  6303. ASC_CS_TYPE chipstat;
  6304. PortAddr iop_base;
  6305. ushort saved_ram_addr;
  6306. uchar ctrl_reg;
  6307. uchar saved_ctrl_reg;
  6308. int int_pending;
  6309. int status;
  6310. uchar host_flag;
  6311. iop_base = asc_dvc->iop_base;
  6312. int_pending = ASC_FALSE;
  6313. if (AscIsIntPending(iop_base) == 0)
  6314. return int_pending;
  6315. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  6316. return ASC_ERROR;
  6317. }
  6318. if (asc_dvc->in_critical_cnt != 0) {
  6319. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  6320. return ASC_ERROR;
  6321. }
  6322. if (asc_dvc->is_in_int) {
  6323. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  6324. return ASC_ERROR;
  6325. }
  6326. asc_dvc->is_in_int = true;
  6327. ctrl_reg = AscGetChipControl(iop_base);
  6328. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  6329. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  6330. chipstat = AscGetChipStatus(iop_base);
  6331. if (chipstat & CSW_SCSI_RESET_LATCH) {
  6332. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  6333. int i = 10;
  6334. int_pending = ASC_TRUE;
  6335. asc_dvc->sdtr_done = 0;
  6336. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6337. while ((AscGetChipStatus(iop_base) &
  6338. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  6339. mdelay(100);
  6340. }
  6341. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  6342. AscSetChipControl(iop_base, CC_HALT);
  6343. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  6344. AscSetChipStatus(iop_base, 0);
  6345. chipstat = AscGetChipStatus(iop_base);
  6346. }
  6347. }
  6348. saved_ram_addr = AscGetChipLramAddr(iop_base);
  6349. host_flag = AscReadLramByte(iop_base,
  6350. ASCV_HOST_FLAG_B) &
  6351. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  6352. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6353. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  6354. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  6355. AscAckInterrupt(iop_base);
  6356. int_pending = ASC_TRUE;
  6357. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  6358. AscIsrChipHalted(asc_dvc);
  6359. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6360. } else {
  6361. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  6362. while (((status =
  6363. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  6364. }
  6365. } else {
  6366. do {
  6367. if ((status =
  6368. AscIsrQDone(asc_dvc)) == 1) {
  6369. break;
  6370. }
  6371. } while (status == 0x11);
  6372. }
  6373. if ((status & 0x80) != 0)
  6374. int_pending = ASC_ERROR;
  6375. }
  6376. }
  6377. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6378. AscSetChipLramAddr(iop_base, saved_ram_addr);
  6379. AscSetChipControl(iop_base, saved_ctrl_reg);
  6380. asc_dvc->is_in_int = false;
  6381. return int_pending;
  6382. }
  6383. /*
  6384. * advansys_reset()
  6385. *
  6386. * Reset the host associated with the command 'scp'.
  6387. *
  6388. * This function runs its own thread. Interrupts must be blocked but
  6389. * sleeping is allowed and no locking other than for host structures is
  6390. * required. Returns SUCCESS or FAILED.
  6391. */
  6392. static int advansys_reset(struct scsi_cmnd *scp)
  6393. {
  6394. struct Scsi_Host *shost = scp->device->host;
  6395. struct asc_board *boardp = shost_priv(shost);
  6396. unsigned long flags;
  6397. int status;
  6398. int ret = SUCCESS;
  6399. ASC_DBG(1, "0x%p\n", scp);
  6400. ASC_STATS(shost, reset);
  6401. scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n");
  6402. if (ASC_NARROW_BOARD(boardp)) {
  6403. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6404. /* Reset the chip and SCSI bus. */
  6405. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  6406. status = AscInitAsc1000Driver(asc_dvc);
  6407. /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
  6408. if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
  6409. scmd_printk(KERN_INFO, scp, "SCSI host reset error: "
  6410. "0x%x, status: 0x%x\n", asc_dvc->err_code,
  6411. status);
  6412. ret = FAILED;
  6413. } else if (status) {
  6414. scmd_printk(KERN_INFO, scp, "SCSI host reset warning: "
  6415. "0x%x\n", status);
  6416. } else {
  6417. scmd_printk(KERN_INFO, scp, "SCSI host reset "
  6418. "successful\n");
  6419. }
  6420. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  6421. } else {
  6422. /*
  6423. * If the suggest reset bus flags are set, then reset the bus.
  6424. * Otherwise only reset the device.
  6425. */
  6426. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  6427. /*
  6428. * Reset the chip and SCSI bus.
  6429. */
  6430. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  6431. switch (AdvResetChipAndSB(adv_dvc)) {
  6432. case ASC_TRUE:
  6433. scmd_printk(KERN_INFO, scp, "SCSI host reset "
  6434. "successful\n");
  6435. break;
  6436. case ASC_FALSE:
  6437. default:
  6438. scmd_printk(KERN_INFO, scp, "SCSI host reset error\n");
  6439. ret = FAILED;
  6440. break;
  6441. }
  6442. spin_lock_irqsave(shost->host_lock, flags);
  6443. AdvISR(adv_dvc);
  6444. spin_unlock_irqrestore(shost->host_lock, flags);
  6445. }
  6446. ASC_DBG(1, "ret %d\n", ret);
  6447. return ret;
  6448. }
  6449. /*
  6450. * advansys_biosparam()
  6451. *
  6452. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  6453. * support is enabled for a drive.
  6454. *
  6455. * ip (information pointer) is an int array with the following definition:
  6456. * ip[0]: heads
  6457. * ip[1]: sectors
  6458. * ip[2]: cylinders
  6459. */
  6460. static int
  6461. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  6462. sector_t capacity, int ip[])
  6463. {
  6464. struct asc_board *boardp = shost_priv(sdev->host);
  6465. ASC_DBG(1, "begin\n");
  6466. ASC_STATS(sdev->host, biosparam);
  6467. if (ASC_NARROW_BOARD(boardp)) {
  6468. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  6469. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  6470. ip[0] = 255;
  6471. ip[1] = 63;
  6472. } else {
  6473. ip[0] = 64;
  6474. ip[1] = 32;
  6475. }
  6476. } else {
  6477. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  6478. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  6479. ip[0] = 255;
  6480. ip[1] = 63;
  6481. } else {
  6482. ip[0] = 64;
  6483. ip[1] = 32;
  6484. }
  6485. }
  6486. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  6487. ASC_DBG(1, "end\n");
  6488. return 0;
  6489. }
  6490. /*
  6491. * First-level interrupt handler.
  6492. *
  6493. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  6494. */
  6495. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  6496. {
  6497. struct Scsi_Host *shost = dev_id;
  6498. struct asc_board *boardp = shost_priv(shost);
  6499. irqreturn_t result = IRQ_NONE;
  6500. unsigned long flags;
  6501. ASC_DBG(2, "boardp 0x%p\n", boardp);
  6502. spin_lock_irqsave(shost->host_lock, flags);
  6503. if (ASC_NARROW_BOARD(boardp)) {
  6504. if (AscIsIntPending(shost->io_port)) {
  6505. result = IRQ_HANDLED;
  6506. ASC_STATS(shost, interrupt);
  6507. ASC_DBG(1, "before AscISR()\n");
  6508. AscISR(&boardp->dvc_var.asc_dvc_var);
  6509. }
  6510. } else {
  6511. ASC_DBG(1, "before AdvISR()\n");
  6512. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  6513. result = IRQ_HANDLED;
  6514. ASC_STATS(shost, interrupt);
  6515. }
  6516. }
  6517. spin_unlock_irqrestore(shost->host_lock, flags);
  6518. ASC_DBG(1, "end\n");
  6519. return result;
  6520. }
  6521. static bool AscHostReqRiscHalt(PortAddr iop_base)
  6522. {
  6523. int count = 0;
  6524. bool sta = false;
  6525. uchar saved_stop_code;
  6526. if (AscIsChipHalted(iop_base))
  6527. return true;
  6528. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  6529. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  6530. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  6531. do {
  6532. if (AscIsChipHalted(iop_base)) {
  6533. sta = true;
  6534. break;
  6535. }
  6536. mdelay(100);
  6537. } while (count++ < 20);
  6538. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  6539. return sta;
  6540. }
  6541. static bool
  6542. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  6543. {
  6544. bool sta = false;
  6545. if (AscHostReqRiscHalt(iop_base)) {
  6546. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6547. AscStartChip(iop_base);
  6548. }
  6549. return sta;
  6550. }
  6551. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  6552. {
  6553. char type = sdev->type;
  6554. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  6555. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  6556. return;
  6557. if (asc_dvc->init_sdtr & tid_bits)
  6558. return;
  6559. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  6560. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  6561. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  6562. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  6563. (type == TYPE_ROM) || (type == TYPE_TAPE))
  6564. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  6565. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  6566. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  6567. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  6568. }
  6569. static void
  6570. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  6571. {
  6572. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  6573. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  6574. if (sdev->lun == 0) {
  6575. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  6576. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  6577. asc_dvc->init_sdtr |= tid_bit;
  6578. } else {
  6579. asc_dvc->init_sdtr &= ~tid_bit;
  6580. }
  6581. if (orig_init_sdtr != asc_dvc->init_sdtr)
  6582. AscAsyncFix(asc_dvc, sdev);
  6583. }
  6584. if (sdev->tagged_supported) {
  6585. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  6586. if (sdev->lun == 0) {
  6587. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  6588. asc_dvc->use_tagged_qng |= tid_bit;
  6589. }
  6590. scsi_change_queue_depth(sdev,
  6591. asc_dvc->max_dvc_qng[sdev->id]);
  6592. }
  6593. } else {
  6594. if (sdev->lun == 0) {
  6595. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  6596. asc_dvc->use_tagged_qng &= ~tid_bit;
  6597. }
  6598. }
  6599. if ((sdev->lun == 0) &&
  6600. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  6601. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  6602. asc_dvc->cfg->disc_enable);
  6603. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  6604. asc_dvc->use_tagged_qng);
  6605. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  6606. asc_dvc->cfg->can_tagged_qng);
  6607. asc_dvc->max_dvc_qng[sdev->id] =
  6608. asc_dvc->cfg->max_tag_qng[sdev->id];
  6609. AscWriteLramByte(asc_dvc->iop_base,
  6610. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  6611. asc_dvc->max_dvc_qng[sdev->id]);
  6612. }
  6613. }
  6614. /*
  6615. * Wide Transfers
  6616. *
  6617. * If the EEPROM enabled WDTR for the device and the device supports wide
  6618. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  6619. * write the new value to the microcode.
  6620. */
  6621. static void
  6622. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6623. {
  6624. unsigned short cfg_word;
  6625. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6626. if ((cfg_word & tidmask) != 0)
  6627. return;
  6628. cfg_word |= tidmask;
  6629. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6630. /*
  6631. * Clear the microcode SDTR and WDTR negotiation done indicators for
  6632. * the target to cause it to negotiate with the new setting set above.
  6633. * WDTR when accepted causes the target to enter asynchronous mode, so
  6634. * SDTR must be negotiated.
  6635. */
  6636. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6637. cfg_word &= ~tidmask;
  6638. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6639. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6640. cfg_word &= ~tidmask;
  6641. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6642. }
  6643. /*
  6644. * Synchronous Transfers
  6645. *
  6646. * If the EEPROM enabled SDTR for the device and the device
  6647. * supports synchronous transfers, then turn on the device's
  6648. * 'sdtr_able' bit. Write the new value to the microcode.
  6649. */
  6650. static void
  6651. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6652. {
  6653. unsigned short cfg_word;
  6654. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6655. if ((cfg_word & tidmask) != 0)
  6656. return;
  6657. cfg_word |= tidmask;
  6658. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6659. /*
  6660. * Clear the microcode "SDTR negotiation" done indicator for the
  6661. * target to cause it to negotiate with the new setting set above.
  6662. */
  6663. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6664. cfg_word &= ~tidmask;
  6665. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6666. }
  6667. /*
  6668. * PPR (Parallel Protocol Request) Capable
  6669. *
  6670. * If the device supports DT mode, then it must be PPR capable.
  6671. * The PPR message will be used in place of the SDTR and WDTR
  6672. * messages to negotiate synchronous speed and offset, transfer
  6673. * width, and protocol options.
  6674. */
  6675. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  6676. AdvPortAddr iop_base, unsigned short tidmask)
  6677. {
  6678. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  6679. adv_dvc->ppr_able |= tidmask;
  6680. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  6681. }
  6682. static void
  6683. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  6684. {
  6685. AdvPortAddr iop_base = adv_dvc->iop_base;
  6686. unsigned short tidmask = 1 << sdev->id;
  6687. if (sdev->lun == 0) {
  6688. /*
  6689. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  6690. * is enabled in the EEPROM and the device supports the
  6691. * feature, then enable it in the microcode.
  6692. */
  6693. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  6694. advansys_wide_enable_wdtr(iop_base, tidmask);
  6695. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  6696. advansys_wide_enable_sdtr(iop_base, tidmask);
  6697. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  6698. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  6699. /*
  6700. * Tag Queuing is disabled for the BIOS which runs in polled
  6701. * mode and would see no benefit from Tag Queuing. Also by
  6702. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  6703. * bugs will at least work with the BIOS.
  6704. */
  6705. if ((adv_dvc->tagqng_able & tidmask) &&
  6706. sdev->tagged_supported) {
  6707. unsigned short cfg_word;
  6708. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  6709. cfg_word |= tidmask;
  6710. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  6711. cfg_word);
  6712. AdvWriteByteLram(iop_base,
  6713. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  6714. adv_dvc->max_dvc_qng);
  6715. }
  6716. }
  6717. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
  6718. scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
  6719. }
  6720. /*
  6721. * Set the number of commands to queue per device for the
  6722. * specified host adapter.
  6723. */
  6724. static int advansys_slave_configure(struct scsi_device *sdev)
  6725. {
  6726. struct asc_board *boardp = shost_priv(sdev->host);
  6727. if (ASC_NARROW_BOARD(boardp))
  6728. advansys_narrow_slave_configure(sdev,
  6729. &boardp->dvc_var.asc_dvc_var);
  6730. else
  6731. advansys_wide_slave_configure(sdev,
  6732. &boardp->dvc_var.adv_dvc_var);
  6733. return 0;
  6734. }
  6735. static __le32 asc_get_sense_buffer_dma(struct scsi_cmnd *scp)
  6736. {
  6737. struct asc_board *board = shost_priv(scp->device->host);
  6738. scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  6739. SCSI_SENSE_BUFFERSIZE,
  6740. DMA_FROM_DEVICE);
  6741. if (dma_mapping_error(board->dev, scp->SCp.dma_handle)) {
  6742. ASC_DBG(1, "failed to map sense buffer\n");
  6743. return 0;
  6744. }
  6745. return cpu_to_le32(scp->SCp.dma_handle);
  6746. }
  6747. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  6748. struct asc_scsi_q *asc_scsi_q)
  6749. {
  6750. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6751. int use_sg;
  6752. u32 srb_tag;
  6753. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  6754. /*
  6755. * Set the srb_tag to the command tag + 1, as
  6756. * srb_tag '0' is used internally by the chip.
  6757. */
  6758. srb_tag = scp->request->tag + 1;
  6759. asc_scsi_q->q2.srb_tag = srb_tag;
  6760. /*
  6761. * Build the ASC_SCSI_Q request.
  6762. */
  6763. asc_scsi_q->cdbptr = &scp->cmnd[0];
  6764. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  6765. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  6766. asc_scsi_q->q1.target_lun = scp->device->lun;
  6767. asc_scsi_q->q2.target_ix =
  6768. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  6769. asc_scsi_q->q1.sense_addr = asc_get_sense_buffer_dma(scp);
  6770. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  6771. if (!asc_scsi_q->q1.sense_addr)
  6772. return ASC_BUSY;
  6773. /*
  6774. * If there are any outstanding requests for the current target,
  6775. * then every 255th request send an ORDERED request. This heuristic
  6776. * tries to retain the benefit of request sorting while preventing
  6777. * request starvation. 255 is the max number of tags or pending commands
  6778. * a device may have outstanding.
  6779. *
  6780. * The request count is incremented below for every successfully
  6781. * started request.
  6782. *
  6783. */
  6784. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  6785. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  6786. asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG;
  6787. } else {
  6788. asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG;
  6789. }
  6790. /* Build ASC_SCSI_Q */
  6791. use_sg = scsi_dma_map(scp);
  6792. if (use_sg < 0) {
  6793. ASC_DBG(1, "failed to map sglist\n");
  6794. return ASC_BUSY;
  6795. } else if (use_sg > 0) {
  6796. int sgcnt;
  6797. struct scatterlist *slp;
  6798. struct asc_sg_head *asc_sg_head;
  6799. if (use_sg > scp->device->host->sg_tablesize) {
  6800. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  6801. "sg_tablesize %d\n", use_sg,
  6802. scp->device->host->sg_tablesize);
  6803. scsi_dma_unmap(scp);
  6804. scp->result = HOST_BYTE(DID_ERROR);
  6805. return ASC_ERROR;
  6806. }
  6807. asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
  6808. use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
  6809. if (!asc_sg_head) {
  6810. scsi_dma_unmap(scp);
  6811. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  6812. return ASC_ERROR;
  6813. }
  6814. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  6815. asc_scsi_q->sg_head = asc_sg_head;
  6816. asc_scsi_q->q1.data_cnt = 0;
  6817. asc_scsi_q->q1.data_addr = 0;
  6818. /* This is a byte value, otherwise it would need to be swapped. */
  6819. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  6820. ASC_STATS_ADD(scp->device->host, xfer_elem,
  6821. asc_sg_head->entry_cnt);
  6822. /*
  6823. * Convert scatter-gather list into ASC_SG_HEAD list.
  6824. */
  6825. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  6826. asc_sg_head->sg_list[sgcnt].addr =
  6827. cpu_to_le32(sg_dma_address(slp));
  6828. asc_sg_head->sg_list[sgcnt].bytes =
  6829. cpu_to_le32(sg_dma_len(slp));
  6830. ASC_STATS_ADD(scp->device->host, xfer_sect,
  6831. DIV_ROUND_UP(sg_dma_len(slp), 512));
  6832. }
  6833. }
  6834. ASC_STATS(scp->device->host, xfer_cnt);
  6835. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  6836. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  6837. return ASC_NOERROR;
  6838. }
  6839. /*
  6840. * Build scatter-gather list for Adv Library (Wide Board).
  6841. *
  6842. * Additional ADV_SG_BLOCK structures will need to be allocated
  6843. * if the total number of scatter-gather elements exceeds
  6844. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  6845. * assumed to be physically contiguous.
  6846. *
  6847. * Return:
  6848. * ADV_SUCCESS(1) - SG List successfully created
  6849. * ADV_ERROR(-1) - SG List creation failed
  6850. */
  6851. static int
  6852. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
  6853. ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg)
  6854. {
  6855. adv_sgblk_t *sgblkp, *prev_sgblkp;
  6856. struct scatterlist *slp;
  6857. int sg_elem_cnt;
  6858. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  6859. dma_addr_t sgblk_paddr;
  6860. int i;
  6861. slp = scsi_sglist(scp);
  6862. sg_elem_cnt = use_sg;
  6863. prev_sgblkp = NULL;
  6864. prev_sg_block = NULL;
  6865. reqp->sgblkp = NULL;
  6866. for (;;) {
  6867. /*
  6868. * Allocate a 'adv_sgblk_t' structure from the board free
  6869. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  6870. * (15) scatter-gather elements.
  6871. */
  6872. sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC,
  6873. &sgblk_paddr);
  6874. if (!sgblkp) {
  6875. ASC_DBG(1, "no free adv_sgblk_t\n");
  6876. ASC_STATS(scp->device->host, adv_build_nosg);
  6877. /*
  6878. * Allocation failed. Free 'adv_sgblk_t' structures
  6879. * already allocated for the request.
  6880. */
  6881. while ((sgblkp = reqp->sgblkp) != NULL) {
  6882. /* Remove 'sgblkp' from the request list. */
  6883. reqp->sgblkp = sgblkp->next_sgblkp;
  6884. sgblkp->next_sgblkp = NULL;
  6885. dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
  6886. sgblkp->sg_addr);
  6887. }
  6888. return ASC_BUSY;
  6889. }
  6890. /* Complete 'adv_sgblk_t' board allocation. */
  6891. sgblkp->sg_addr = sgblk_paddr;
  6892. sgblkp->next_sgblkp = NULL;
  6893. sg_block = &sgblkp->sg_block;
  6894. /*
  6895. * Check if this is the first 'adv_sgblk_t' for the
  6896. * request.
  6897. */
  6898. if (reqp->sgblkp == NULL) {
  6899. /* Request's first scatter-gather block. */
  6900. reqp->sgblkp = sgblkp;
  6901. /*
  6902. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  6903. * address pointers.
  6904. */
  6905. scsiqp->sg_list_ptr = sg_block;
  6906. scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr);
  6907. } else {
  6908. /* Request's second or later scatter-gather block. */
  6909. prev_sgblkp->next_sgblkp = sgblkp;
  6910. /*
  6911. * Point the previous ADV_SG_BLOCK structure to
  6912. * the newly allocated ADV_SG_BLOCK structure.
  6913. */
  6914. prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr);
  6915. }
  6916. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  6917. sg_block->sg_list[i].sg_addr =
  6918. cpu_to_le32(sg_dma_address(slp));
  6919. sg_block->sg_list[i].sg_count =
  6920. cpu_to_le32(sg_dma_len(slp));
  6921. ASC_STATS_ADD(scp->device->host, xfer_sect,
  6922. DIV_ROUND_UP(sg_dma_len(slp), 512));
  6923. if (--sg_elem_cnt == 0) {
  6924. /*
  6925. * Last ADV_SG_BLOCK and scatter-gather entry.
  6926. */
  6927. sg_block->sg_cnt = i + 1;
  6928. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  6929. return ADV_SUCCESS;
  6930. }
  6931. slp++;
  6932. }
  6933. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  6934. prev_sg_block = sg_block;
  6935. prev_sgblkp = sgblkp;
  6936. }
  6937. }
  6938. /*
  6939. * Build a request structure for the Adv Library (Wide Board).
  6940. *
  6941. * If an adv_req_t can not be allocated to issue the request,
  6942. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  6943. *
  6944. * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the
  6945. * microcode for DMA addresses or math operations are byte swapped
  6946. * to little-endian order.
  6947. */
  6948. static int
  6949. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  6950. adv_req_t **adv_reqpp)
  6951. {
  6952. u32 srb_tag = scp->request->tag;
  6953. adv_req_t *reqp;
  6954. ADV_SCSI_REQ_Q *scsiqp;
  6955. int ret;
  6956. int use_sg;
  6957. dma_addr_t sense_addr;
  6958. /*
  6959. * Allocate an adv_req_t structure from the board to execute
  6960. * the command.
  6961. */
  6962. reqp = &boardp->adv_reqp[srb_tag];
  6963. if (reqp->cmndp && reqp->cmndp != scp ) {
  6964. ASC_DBG(1, "no free adv_req_t\n");
  6965. ASC_STATS(scp->device->host, adv_build_noreq);
  6966. return ASC_BUSY;
  6967. }
  6968. reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t));
  6969. scsiqp = &reqp->scsi_req_q;
  6970. /*
  6971. * Initialize the structure.
  6972. */
  6973. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  6974. /*
  6975. * Set the srb_tag to the command tag.
  6976. */
  6977. scsiqp->srb_tag = srb_tag;
  6978. /*
  6979. * Set 'host_scribble' to point to the adv_req_t structure.
  6980. */
  6981. reqp->cmndp = scp;
  6982. scp->host_scribble = (void *)reqp;
  6983. /*
  6984. * Build the ADV_SCSI_REQ_Q request.
  6985. */
  6986. /* Set CDB length and copy it to the request structure. */
  6987. scsiqp->cdb_len = scp->cmd_len;
  6988. /* Copy first 12 CDB bytes to cdb[]. */
  6989. memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12);
  6990. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  6991. if (scp->cmd_len > 12) {
  6992. int cdb16_len = scp->cmd_len - 12;
  6993. memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len);
  6994. }
  6995. scsiqp->target_id = scp->device->id;
  6996. scsiqp->target_lun = scp->device->lun;
  6997. sense_addr = dma_map_single(boardp->dev, scp->sense_buffer,
  6998. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6999. if (dma_mapping_error(boardp->dev, sense_addr)) {
  7000. ASC_DBG(1, "failed to map sense buffer\n");
  7001. ASC_STATS(scp->device->host, adv_build_noreq);
  7002. return ASC_BUSY;
  7003. }
  7004. scsiqp->sense_addr = cpu_to_le32(sense_addr);
  7005. scsiqp->sense_len = SCSI_SENSE_BUFFERSIZE;
  7006. /* Build ADV_SCSI_REQ_Q */
  7007. use_sg = scsi_dma_map(scp);
  7008. if (use_sg < 0) {
  7009. ASC_DBG(1, "failed to map SG list\n");
  7010. ASC_STATS(scp->device->host, adv_build_noreq);
  7011. return ASC_BUSY;
  7012. } else if (use_sg == 0) {
  7013. /* Zero-length transfer */
  7014. reqp->sgblkp = NULL;
  7015. scsiqp->data_cnt = 0;
  7016. scsiqp->data_addr = 0;
  7017. scsiqp->sg_list_ptr = NULL;
  7018. scsiqp->sg_real_addr = 0;
  7019. } else {
  7020. if (use_sg > ADV_MAX_SG_LIST) {
  7021. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7022. "ADV_MAX_SG_LIST %d\n", use_sg,
  7023. scp->device->host->sg_tablesize);
  7024. scsi_dma_unmap(scp);
  7025. scp->result = HOST_BYTE(DID_ERROR);
  7026. reqp->cmndp = NULL;
  7027. scp->host_scribble = NULL;
  7028. return ASC_ERROR;
  7029. }
  7030. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  7031. ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
  7032. if (ret != ADV_SUCCESS) {
  7033. scsi_dma_unmap(scp);
  7034. scp->result = HOST_BYTE(DID_ERROR);
  7035. reqp->cmndp = NULL;
  7036. scp->host_scribble = NULL;
  7037. return ret;
  7038. }
  7039. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  7040. }
  7041. ASC_STATS(scp->device->host, xfer_cnt);
  7042. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  7043. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7044. *adv_reqpp = reqp;
  7045. return ASC_NOERROR;
  7046. }
  7047. static int AscSgListToQueue(int sg_list)
  7048. {
  7049. int n_sg_list_qs;
  7050. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  7051. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  7052. n_sg_list_qs++;
  7053. return n_sg_list_qs + 1;
  7054. }
  7055. static uint
  7056. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  7057. {
  7058. uint cur_used_qs;
  7059. uint cur_free_qs;
  7060. ASC_SCSI_BIT_ID_TYPE target_id;
  7061. uchar tid_no;
  7062. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  7063. tid_no = ASC_TIX_TO_TID(target_ix);
  7064. if ((asc_dvc->unit_not_ready & target_id) ||
  7065. (asc_dvc->queue_full_or_busy & target_id)) {
  7066. return 0;
  7067. }
  7068. if (n_qs == 1) {
  7069. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7070. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  7071. } else {
  7072. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7073. (uint) ASC_MIN_FREE_Q;
  7074. }
  7075. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  7076. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  7077. if (asc_dvc->cur_dvc_qng[tid_no] >=
  7078. asc_dvc->max_dvc_qng[tid_no]) {
  7079. return 0;
  7080. }
  7081. return cur_free_qs;
  7082. }
  7083. if (n_qs > 1) {
  7084. if ((n_qs > asc_dvc->last_q_shortage)
  7085. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  7086. asc_dvc->last_q_shortage = n_qs;
  7087. }
  7088. }
  7089. return 0;
  7090. }
  7091. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7092. {
  7093. ushort q_addr;
  7094. uchar next_qp;
  7095. uchar q_status;
  7096. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7097. q_status = (uchar)AscReadLramByte(iop_base,
  7098. (ushort)(q_addr +
  7099. ASC_SCSIQ_B_STATUS));
  7100. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7101. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7102. return next_qp;
  7103. return ASC_QLINK_END;
  7104. }
  7105. static uchar
  7106. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7107. {
  7108. uchar i;
  7109. for (i = 0; i < n_free_q; i++) {
  7110. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7111. if (free_q_head == ASC_QLINK_END)
  7112. break;
  7113. }
  7114. return free_q_head;
  7115. }
  7116. /*
  7117. * void
  7118. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7119. *
  7120. * Calling/Exit State:
  7121. * none
  7122. *
  7123. * Description:
  7124. * Output an ASC_SCSI_Q structure to the chip
  7125. */
  7126. static void
  7127. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7128. {
  7129. int i;
  7130. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7131. AscSetChipLramAddr(iop_base, s_addr);
  7132. for (i = 0; i < 2 * words; i += 2) {
  7133. if (i == 4 || i == 20) {
  7134. continue;
  7135. }
  7136. outpw(iop_base + IOP_RAM_DATA,
  7137. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7138. }
  7139. }
  7140. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7141. {
  7142. ushort q_addr;
  7143. uchar tid_no;
  7144. uchar sdtr_data;
  7145. uchar syn_period_ix;
  7146. uchar syn_offset;
  7147. PortAddr iop_base;
  7148. iop_base = asc_dvc->iop_base;
  7149. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7150. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7151. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7152. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7153. syn_period_ix =
  7154. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7155. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7156. AscMsgOutSDTR(asc_dvc,
  7157. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7158. syn_offset);
  7159. scsiq->q1.cntl |= QC_MSG_OUT;
  7160. }
  7161. q_addr = ASC_QNO_TO_QADDR(q_no);
  7162. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7163. scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
  7164. }
  7165. scsiq->q1.status = QS_FREE;
  7166. AscMemWordCopyPtrToLram(iop_base,
  7167. q_addr + ASC_SCSIQ_CDB_BEG,
  7168. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7169. DvcPutScsiQ(iop_base,
  7170. q_addr + ASC_SCSIQ_CPY_BEG,
  7171. (uchar *)&scsiq->q1.cntl,
  7172. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7173. AscWriteLramWord(iop_base,
  7174. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7175. (ushort)(((ushort)scsiq->q1.
  7176. q_no << 8) | (ushort)QS_READY));
  7177. return 1;
  7178. }
  7179. static int
  7180. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7181. {
  7182. int sta;
  7183. int i;
  7184. ASC_SG_HEAD *sg_head;
  7185. ASC_SG_LIST_Q scsi_sg_q;
  7186. __le32 saved_data_addr;
  7187. __le32 saved_data_cnt;
  7188. PortAddr iop_base;
  7189. ushort sg_list_dwords;
  7190. ushort sg_index;
  7191. ushort sg_entry_cnt;
  7192. ushort q_addr;
  7193. uchar next_qp;
  7194. iop_base = asc_dvc->iop_base;
  7195. sg_head = scsiq->sg_head;
  7196. saved_data_addr = scsiq->q1.data_addr;
  7197. saved_data_cnt = scsiq->q1.data_cnt;
  7198. scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
  7199. scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
  7200. /*
  7201. * Set sg_entry_cnt to be the number of SG elements that
  7202. * will fit in the allocated SG queues. It is minus 1, because
  7203. * the first SG element is handled above.
  7204. */
  7205. sg_entry_cnt = sg_head->entry_cnt - 1;
  7206. if (sg_entry_cnt != 0) {
  7207. scsiq->q1.cntl |= QC_SG_HEAD;
  7208. q_addr = ASC_QNO_TO_QADDR(q_no);
  7209. sg_index = 1;
  7210. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  7211. scsi_sg_q.sg_head_qp = q_no;
  7212. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  7213. for (i = 0; i < sg_head->queue_cnt; i++) {
  7214. scsi_sg_q.seq_no = i + 1;
  7215. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  7216. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  7217. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  7218. if (i == 0) {
  7219. scsi_sg_q.sg_list_cnt =
  7220. ASC_SG_LIST_PER_Q;
  7221. scsi_sg_q.sg_cur_list_cnt =
  7222. ASC_SG_LIST_PER_Q;
  7223. } else {
  7224. scsi_sg_q.sg_list_cnt =
  7225. ASC_SG_LIST_PER_Q - 1;
  7226. scsi_sg_q.sg_cur_list_cnt =
  7227. ASC_SG_LIST_PER_Q - 1;
  7228. }
  7229. } else {
  7230. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  7231. sg_list_dwords = sg_entry_cnt << 1;
  7232. if (i == 0) {
  7233. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  7234. scsi_sg_q.sg_cur_list_cnt =
  7235. sg_entry_cnt;
  7236. } else {
  7237. scsi_sg_q.sg_list_cnt =
  7238. sg_entry_cnt - 1;
  7239. scsi_sg_q.sg_cur_list_cnt =
  7240. sg_entry_cnt - 1;
  7241. }
  7242. sg_entry_cnt = 0;
  7243. }
  7244. next_qp = AscReadLramByte(iop_base,
  7245. (ushort)(q_addr +
  7246. ASC_SCSIQ_B_FWD));
  7247. scsi_sg_q.q_no = next_qp;
  7248. q_addr = ASC_QNO_TO_QADDR(next_qp);
  7249. AscMemWordCopyPtrToLram(iop_base,
  7250. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  7251. (uchar *)&scsi_sg_q,
  7252. sizeof(ASC_SG_LIST_Q) >> 1);
  7253. AscMemDWordCopyPtrToLram(iop_base,
  7254. q_addr + ASC_SGQ_LIST_BEG,
  7255. (uchar *)&sg_head->
  7256. sg_list[sg_index],
  7257. sg_list_dwords);
  7258. sg_index += ASC_SG_LIST_PER_Q;
  7259. scsiq->next_sg_index = sg_index;
  7260. }
  7261. } else {
  7262. scsiq->q1.cntl &= ~QC_SG_HEAD;
  7263. }
  7264. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  7265. scsiq->q1.data_addr = saved_data_addr;
  7266. scsiq->q1.data_cnt = saved_data_cnt;
  7267. return (sta);
  7268. }
  7269. static int
  7270. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  7271. {
  7272. PortAddr iop_base;
  7273. uchar free_q_head;
  7274. uchar next_qp;
  7275. uchar tid_no;
  7276. uchar target_ix;
  7277. int sta;
  7278. iop_base = asc_dvc->iop_base;
  7279. target_ix = scsiq->q2.target_ix;
  7280. tid_no = ASC_TIX_TO_TID(target_ix);
  7281. sta = 0;
  7282. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  7283. if (n_q_required > 1) {
  7284. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  7285. (uchar)n_q_required);
  7286. if (next_qp != ASC_QLINK_END) {
  7287. asc_dvc->last_q_shortage = 0;
  7288. scsiq->sg_head->queue_cnt = n_q_required - 1;
  7289. scsiq->q1.q_no = free_q_head;
  7290. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  7291. free_q_head);
  7292. }
  7293. } else if (n_q_required == 1) {
  7294. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  7295. if (next_qp != ASC_QLINK_END) {
  7296. scsiq->q1.q_no = free_q_head;
  7297. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  7298. }
  7299. }
  7300. if (sta == 1) {
  7301. AscPutVarFreeQHead(iop_base, next_qp);
  7302. asc_dvc->cur_total_qng += n_q_required;
  7303. asc_dvc->cur_dvc_qng[tid_no]++;
  7304. }
  7305. return sta;
  7306. }
  7307. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  7308. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  7309. INQUIRY,
  7310. REQUEST_SENSE,
  7311. READ_CAPACITY,
  7312. READ_TOC,
  7313. MODE_SELECT,
  7314. MODE_SENSE,
  7315. MODE_SELECT_10,
  7316. MODE_SENSE_10,
  7317. 0xFF,
  7318. 0xFF,
  7319. 0xFF,
  7320. 0xFF,
  7321. 0xFF,
  7322. 0xFF,
  7323. 0xFF,
  7324. 0xFF
  7325. };
  7326. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  7327. {
  7328. PortAddr iop_base;
  7329. int sta;
  7330. int n_q_required;
  7331. bool disable_syn_offset_one_fix;
  7332. int i;
  7333. u32 addr;
  7334. ushort sg_entry_cnt = 0;
  7335. ushort sg_entry_cnt_minus_one = 0;
  7336. uchar target_ix;
  7337. uchar tid_no;
  7338. uchar sdtr_data;
  7339. uchar extra_bytes;
  7340. uchar scsi_cmd;
  7341. uchar disable_cmd;
  7342. ASC_SG_HEAD *sg_head;
  7343. unsigned long data_cnt;
  7344. iop_base = asc_dvc->iop_base;
  7345. sg_head = scsiq->sg_head;
  7346. if (asc_dvc->err_code != 0)
  7347. return ASC_ERROR;
  7348. scsiq->q1.q_no = 0;
  7349. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  7350. scsiq->q1.extra_bytes = 0;
  7351. }
  7352. sta = 0;
  7353. target_ix = scsiq->q2.target_ix;
  7354. tid_no = ASC_TIX_TO_TID(target_ix);
  7355. n_q_required = 1;
  7356. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  7357. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  7358. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  7359. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7360. AscMsgOutSDTR(asc_dvc,
  7361. asc_dvc->
  7362. sdtr_period_tbl[(sdtr_data >> 4) &
  7363. (uchar)(asc_dvc->
  7364. max_sdtr_index -
  7365. 1)],
  7366. (uchar)(sdtr_data & (uchar)
  7367. ASC_SYN_MAX_OFFSET));
  7368. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  7369. }
  7370. }
  7371. if (asc_dvc->in_critical_cnt != 0) {
  7372. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  7373. return ASC_ERROR;
  7374. }
  7375. asc_dvc->in_critical_cnt++;
  7376. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7377. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  7378. asc_dvc->in_critical_cnt--;
  7379. return ASC_ERROR;
  7380. }
  7381. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  7382. asc_dvc->in_critical_cnt--;
  7383. return ASC_ERROR;
  7384. }
  7385. if (sg_entry_cnt == 1) {
  7386. scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
  7387. scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
  7388. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  7389. }
  7390. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  7391. }
  7392. scsi_cmd = scsiq->cdbptr[0];
  7393. disable_syn_offset_one_fix = false;
  7394. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  7395. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  7396. if (scsiq->q1.cntl & QC_SG_HEAD) {
  7397. data_cnt = 0;
  7398. for (i = 0; i < sg_entry_cnt; i++) {
  7399. data_cnt += le32_to_cpu(sg_head->sg_list[i].
  7400. bytes);
  7401. }
  7402. } else {
  7403. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  7404. }
  7405. if (data_cnt != 0UL) {
  7406. if (data_cnt < 512UL) {
  7407. disable_syn_offset_one_fix = true;
  7408. } else {
  7409. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  7410. i++) {
  7411. disable_cmd =
  7412. _syn_offset_one_disable_cmd[i];
  7413. if (disable_cmd == 0xFF) {
  7414. break;
  7415. }
  7416. if (scsi_cmd == disable_cmd) {
  7417. disable_syn_offset_one_fix =
  7418. true;
  7419. break;
  7420. }
  7421. }
  7422. }
  7423. }
  7424. }
  7425. if (disable_syn_offset_one_fix) {
  7426. scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
  7427. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  7428. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  7429. } else {
  7430. scsiq->q2.tag_code &= 0x27;
  7431. }
  7432. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7433. if (asc_dvc->bug_fix_cntl) {
  7434. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7435. if ((scsi_cmd == READ_6) ||
  7436. (scsi_cmd == READ_10)) {
  7437. addr = le32_to_cpu(sg_head->
  7438. sg_list
  7439. [sg_entry_cnt_minus_one].
  7440. addr) +
  7441. le32_to_cpu(sg_head->
  7442. sg_list
  7443. [sg_entry_cnt_minus_one].
  7444. bytes);
  7445. extra_bytes =
  7446. (uchar)((ushort)addr & 0x0003);
  7447. if ((extra_bytes != 0)
  7448. &&
  7449. ((scsiq->q2.
  7450. tag_code &
  7451. ASC_TAG_FLAG_EXTRA_BYTES)
  7452. == 0)) {
  7453. scsiq->q2.tag_code |=
  7454. ASC_TAG_FLAG_EXTRA_BYTES;
  7455. scsiq->q1.extra_bytes =
  7456. extra_bytes;
  7457. data_cnt =
  7458. le32_to_cpu(sg_head->
  7459. sg_list
  7460. [sg_entry_cnt_minus_one].
  7461. bytes);
  7462. data_cnt -= extra_bytes;
  7463. sg_head->
  7464. sg_list
  7465. [sg_entry_cnt_minus_one].
  7466. bytes =
  7467. cpu_to_le32(data_cnt);
  7468. }
  7469. }
  7470. }
  7471. }
  7472. sg_head->entry_to_copy = sg_head->entry_cnt;
  7473. n_q_required = AscSgListToQueue(sg_entry_cnt);
  7474. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  7475. (uint) n_q_required)
  7476. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7477. if ((sta =
  7478. AscSendScsiQueue(asc_dvc, scsiq,
  7479. n_q_required)) == 1) {
  7480. asc_dvc->in_critical_cnt--;
  7481. return (sta);
  7482. }
  7483. }
  7484. } else {
  7485. if (asc_dvc->bug_fix_cntl) {
  7486. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7487. if ((scsi_cmd == READ_6) ||
  7488. (scsi_cmd == READ_10)) {
  7489. addr =
  7490. le32_to_cpu(scsiq->q1.data_addr) +
  7491. le32_to_cpu(scsiq->q1.data_cnt);
  7492. extra_bytes =
  7493. (uchar)((ushort)addr & 0x0003);
  7494. if ((extra_bytes != 0)
  7495. &&
  7496. ((scsiq->q2.
  7497. tag_code &
  7498. ASC_TAG_FLAG_EXTRA_BYTES)
  7499. == 0)) {
  7500. data_cnt =
  7501. le32_to_cpu(scsiq->q1.
  7502. data_cnt);
  7503. if (((ushort)data_cnt & 0x01FF)
  7504. == 0) {
  7505. scsiq->q2.tag_code |=
  7506. ASC_TAG_FLAG_EXTRA_BYTES;
  7507. data_cnt -= extra_bytes;
  7508. scsiq->q1.data_cnt =
  7509. cpu_to_le32
  7510. (data_cnt);
  7511. scsiq->q1.extra_bytes =
  7512. extra_bytes;
  7513. }
  7514. }
  7515. }
  7516. }
  7517. }
  7518. n_q_required = 1;
  7519. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  7520. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7521. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  7522. n_q_required)) == 1) {
  7523. asc_dvc->in_critical_cnt--;
  7524. return (sta);
  7525. }
  7526. }
  7527. }
  7528. asc_dvc->in_critical_cnt--;
  7529. return (sta);
  7530. }
  7531. /*
  7532. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  7533. *
  7534. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  7535. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  7536. * RISC to notify it a new command is ready to be executed.
  7537. *
  7538. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  7539. * set to SCSI_MAX_RETRY.
  7540. *
  7541. * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the microcode
  7542. * for DMA addresses or math operations are byte swapped to little-endian
  7543. * order.
  7544. *
  7545. * Return:
  7546. * ADV_SUCCESS(1) - The request was successfully queued.
  7547. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  7548. * request completes.
  7549. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  7550. * host IC error.
  7551. */
  7552. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp)
  7553. {
  7554. AdvPortAddr iop_base;
  7555. ADV_CARR_T *new_carrp;
  7556. ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q;
  7557. /*
  7558. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  7559. */
  7560. if (scsiq->target_id > ADV_MAX_TID) {
  7561. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  7562. scsiq->done_status = QD_WITH_ERROR;
  7563. return ADV_ERROR;
  7564. }
  7565. iop_base = asc_dvc->iop_base;
  7566. /*
  7567. * Allocate a carrier ensuring at least one carrier always
  7568. * remains on the freelist and initialize fields.
  7569. */
  7570. new_carrp = adv_get_next_carrier(asc_dvc);
  7571. if (!new_carrp) {
  7572. ASC_DBG(1, "No free carriers\n");
  7573. return ADV_BUSY;
  7574. }
  7575. asc_dvc->carr_pending_cnt++;
  7576. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  7577. scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag);
  7578. scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr);
  7579. scsiq->carr_va = asc_dvc->icq_sp->carr_va;
  7580. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  7581. /*
  7582. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  7583. * the microcode. The newly allocated stopper will become the new
  7584. * stopper.
  7585. */
  7586. asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr;
  7587. /*
  7588. * Set the 'next_vpa' pointer for the old stopper to be the
  7589. * physical address of the new stopper. The RISC can only
  7590. * follow physical addresses.
  7591. */
  7592. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  7593. /*
  7594. * Set the host adapter stopper pointer to point to the new carrier.
  7595. */
  7596. asc_dvc->icq_sp = new_carrp;
  7597. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  7598. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  7599. /*
  7600. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  7601. */
  7602. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  7603. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  7604. /*
  7605. * Clear the tickle value. In the ASC-3550 the RISC flag
  7606. * command 'clr_tickle_a' does not work unless the host
  7607. * value is cleared.
  7608. */
  7609. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  7610. ADV_TICKLE_NOP);
  7611. }
  7612. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  7613. /*
  7614. * Notify the RISC a carrier is ready by writing the physical
  7615. * address of the new carrier stopper to the COMMA register.
  7616. */
  7617. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  7618. le32_to_cpu(new_carrp->carr_pa));
  7619. }
  7620. return ADV_SUCCESS;
  7621. }
  7622. /*
  7623. * Execute a single 'Scsi_Cmnd'.
  7624. */
  7625. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  7626. {
  7627. int ret, err_code;
  7628. struct asc_board *boardp = shost_priv(scp->device->host);
  7629. ASC_DBG(1, "scp 0x%p\n", scp);
  7630. if (ASC_NARROW_BOARD(boardp)) {
  7631. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7632. struct asc_scsi_q asc_scsi_q;
  7633. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  7634. if (ret != ASC_NOERROR) {
  7635. ASC_STATS(scp->device->host, build_error);
  7636. return ret;
  7637. }
  7638. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  7639. kfree(asc_scsi_q.sg_head);
  7640. err_code = asc_dvc->err_code;
  7641. } else {
  7642. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  7643. adv_req_t *adv_reqp;
  7644. switch (adv_build_req(boardp, scp, &adv_reqp)) {
  7645. case ASC_NOERROR:
  7646. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  7647. break;
  7648. case ASC_BUSY:
  7649. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  7650. /*
  7651. * The asc_stats fields 'adv_build_noreq' and
  7652. * 'adv_build_nosg' count wide board busy conditions.
  7653. * They are updated in adv_build_req and
  7654. * adv_get_sglist, respectively.
  7655. */
  7656. return ASC_BUSY;
  7657. case ASC_ERROR:
  7658. default:
  7659. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  7660. ASC_STATS(scp->device->host, build_error);
  7661. return ASC_ERROR;
  7662. }
  7663. ret = AdvExeScsiQueue(adv_dvc, adv_reqp);
  7664. err_code = adv_dvc->err_code;
  7665. }
  7666. switch (ret) {
  7667. case ASC_NOERROR:
  7668. ASC_STATS(scp->device->host, exe_noerror);
  7669. /*
  7670. * Increment monotonically increasing per device
  7671. * successful request counter. Wrapping doesn't matter.
  7672. */
  7673. boardp->reqcnt[scp->device->id]++;
  7674. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  7675. break;
  7676. case ASC_BUSY:
  7677. ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n");
  7678. ASC_STATS(scp->device->host, exe_busy);
  7679. break;
  7680. case ASC_ERROR:
  7681. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  7682. "err_code 0x%x\n", err_code);
  7683. ASC_STATS(scp->device->host, exe_error);
  7684. scp->result = HOST_BYTE(DID_ERROR);
  7685. break;
  7686. default:
  7687. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  7688. "err_code 0x%x\n", err_code);
  7689. ASC_STATS(scp->device->host, exe_unknown);
  7690. scp->result = HOST_BYTE(DID_ERROR);
  7691. break;
  7692. }
  7693. ASC_DBG(1, "end\n");
  7694. return ret;
  7695. }
  7696. /*
  7697. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  7698. *
  7699. * This function always returns 0. Command return status is saved
  7700. * in the 'scp' result field.
  7701. */
  7702. static int
  7703. advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
  7704. {
  7705. struct Scsi_Host *shost = scp->device->host;
  7706. int asc_res, result = 0;
  7707. ASC_STATS(shost, queuecommand);
  7708. scp->scsi_done = done;
  7709. asc_res = asc_execute_scsi_cmnd(scp);
  7710. switch (asc_res) {
  7711. case ASC_NOERROR:
  7712. break;
  7713. case ASC_BUSY:
  7714. result = SCSI_MLQUEUE_HOST_BUSY;
  7715. break;
  7716. case ASC_ERROR:
  7717. default:
  7718. asc_scsi_done(scp);
  7719. break;
  7720. }
  7721. return result;
  7722. }
  7723. static DEF_SCSI_QCMD(advansys_queuecommand)
  7724. static ushort AscGetEisaChipCfg(PortAddr iop_base)
  7725. {
  7726. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  7727. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  7728. return inpw(eisa_cfg_iop);
  7729. }
  7730. /*
  7731. * Return the BIOS address of the adapter at the specified
  7732. * I/O port and with the specified bus type.
  7733. */
  7734. static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
  7735. unsigned short bus_type)
  7736. {
  7737. unsigned short cfg_lsw;
  7738. unsigned short bios_addr;
  7739. /*
  7740. * The PCI BIOS is re-located by the motherboard BIOS. Because
  7741. * of this the driver can not determine where a PCI BIOS is
  7742. * loaded and executes.
  7743. */
  7744. if (bus_type & ASC_IS_PCI)
  7745. return 0;
  7746. if ((bus_type & ASC_IS_EISA) != 0) {
  7747. cfg_lsw = AscGetEisaChipCfg(iop_base);
  7748. cfg_lsw &= 0x000F;
  7749. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  7750. return bios_addr;
  7751. }
  7752. cfg_lsw = AscGetChipCfgLsw(iop_base);
  7753. /*
  7754. * ISA PnP uses the top bit as the 32K BIOS flag
  7755. */
  7756. if (bus_type == ASC_IS_ISAPNP)
  7757. cfg_lsw &= 0x7FFF;
  7758. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  7759. return bios_addr;
  7760. }
  7761. static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  7762. {
  7763. ushort cfg_lsw;
  7764. if (AscGetChipScsiID(iop_base) == new_host_id) {
  7765. return (new_host_id);
  7766. }
  7767. cfg_lsw = AscGetChipCfgLsw(iop_base);
  7768. cfg_lsw &= 0xF8FF;
  7769. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  7770. AscSetChipCfgLsw(iop_base, cfg_lsw);
  7771. return (AscGetChipScsiID(iop_base));
  7772. }
  7773. static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
  7774. {
  7775. unsigned char sc;
  7776. AscSetBank(iop_base, 1);
  7777. sc = inp(iop_base + IOP_REG_SC);
  7778. AscSetBank(iop_base, 0);
  7779. return sc;
  7780. }
  7781. static unsigned char AscGetChipVersion(PortAddr iop_base,
  7782. unsigned short bus_type)
  7783. {
  7784. if (bus_type & ASC_IS_EISA) {
  7785. PortAddr eisa_iop;
  7786. unsigned char revision;
  7787. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  7788. (PortAddr) ASC_EISA_REV_IOP_MASK;
  7789. revision = inp(eisa_iop);
  7790. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  7791. }
  7792. return AscGetChipVerNo(iop_base);
  7793. }
  7794. #ifdef CONFIG_ISA
  7795. static void AscEnableIsaDma(uchar dma_channel)
  7796. {
  7797. if (dma_channel < 4) {
  7798. outp(0x000B, (ushort)(0xC0 | dma_channel));
  7799. outp(0x000A, dma_channel);
  7800. } else if (dma_channel < 8) {
  7801. outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
  7802. outp(0x00D4, (ushort)(dma_channel - 4));
  7803. }
  7804. }
  7805. #endif /* CONFIG_ISA */
  7806. static int AscStopQueueExe(PortAddr iop_base)
  7807. {
  7808. int count = 0;
  7809. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  7810. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  7811. ASC_STOP_REQ_RISC_STOP);
  7812. do {
  7813. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  7814. ASC_STOP_ACK_RISC_STOP) {
  7815. return (1);
  7816. }
  7817. mdelay(100);
  7818. } while (count++ < 20);
  7819. }
  7820. return (0);
  7821. }
  7822. static unsigned int AscGetMaxDmaCount(ushort bus_type)
  7823. {
  7824. if (bus_type & ASC_IS_ISA)
  7825. return ASC_MAX_ISA_DMA_COUNT;
  7826. else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  7827. return ASC_MAX_VL_DMA_COUNT;
  7828. return ASC_MAX_PCI_DMA_COUNT;
  7829. }
  7830. #ifdef CONFIG_ISA
  7831. static ushort AscGetIsaDmaChannel(PortAddr iop_base)
  7832. {
  7833. ushort channel;
  7834. channel = AscGetChipCfgLsw(iop_base) & 0x0003;
  7835. if (channel == 0x03)
  7836. return (0);
  7837. else if (channel == 0x00)
  7838. return (7);
  7839. return (channel + 4);
  7840. }
  7841. static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
  7842. {
  7843. ushort cfg_lsw;
  7844. uchar value;
  7845. if ((dma_channel >= 5) && (dma_channel <= 7)) {
  7846. if (dma_channel == 7)
  7847. value = 0x00;
  7848. else
  7849. value = dma_channel - 4;
  7850. cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
  7851. cfg_lsw |= value;
  7852. AscSetChipCfgLsw(iop_base, cfg_lsw);
  7853. return (AscGetIsaDmaChannel(iop_base));
  7854. }
  7855. return 0;
  7856. }
  7857. static uchar AscGetIsaDmaSpeed(PortAddr iop_base)
  7858. {
  7859. uchar speed_value;
  7860. AscSetBank(iop_base, 1);
  7861. speed_value = AscReadChipDmaSpeed(iop_base);
  7862. speed_value &= 0x07;
  7863. AscSetBank(iop_base, 0);
  7864. return speed_value;
  7865. }
  7866. static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
  7867. {
  7868. speed_value &= 0x07;
  7869. AscSetBank(iop_base, 1);
  7870. AscWriteChipDmaSpeed(iop_base, speed_value);
  7871. AscSetBank(iop_base, 0);
  7872. return AscGetIsaDmaSpeed(iop_base);
  7873. }
  7874. #endif /* CONFIG_ISA */
  7875. static void AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  7876. {
  7877. int i;
  7878. PortAddr iop_base;
  7879. uchar chip_version;
  7880. iop_base = asc_dvc->iop_base;
  7881. asc_dvc->err_code = 0;
  7882. if ((asc_dvc->bus_type &
  7883. (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  7884. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  7885. }
  7886. AscSetChipControl(iop_base, CC_HALT);
  7887. AscSetChipStatus(iop_base, 0);
  7888. asc_dvc->bug_fix_cntl = 0;
  7889. asc_dvc->pci_fix_asyn_xfer = 0;
  7890. asc_dvc->pci_fix_asyn_xfer_always = 0;
  7891. /* asc_dvc->init_state initialized in AscInitGetConfig(). */
  7892. asc_dvc->sdtr_done = 0;
  7893. asc_dvc->cur_total_qng = 0;
  7894. asc_dvc->is_in_int = false;
  7895. asc_dvc->in_critical_cnt = 0;
  7896. asc_dvc->last_q_shortage = 0;
  7897. asc_dvc->use_tagged_qng = 0;
  7898. asc_dvc->no_scam = 0;
  7899. asc_dvc->unit_not_ready = 0;
  7900. asc_dvc->queue_full_or_busy = 0;
  7901. asc_dvc->redo_scam = 0;
  7902. asc_dvc->res2 = 0;
  7903. asc_dvc->min_sdtr_index = 0;
  7904. asc_dvc->cfg->can_tagged_qng = 0;
  7905. asc_dvc->cfg->cmd_qng_enabled = 0;
  7906. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  7907. asc_dvc->init_sdtr = 0;
  7908. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  7909. asc_dvc->scsi_reset_wait = 3;
  7910. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  7911. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  7912. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  7913. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  7914. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  7915. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  7916. asc_dvc->cfg->chip_version = chip_version;
  7917. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  7918. asc_dvc->max_sdtr_index = 7;
  7919. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  7920. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  7921. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  7922. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  7923. asc_dvc->max_sdtr_index = 15;
  7924. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  7925. AscSetExtraControl(iop_base,
  7926. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  7927. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  7928. AscSetExtraControl(iop_base,
  7929. (SEC_ACTIVE_NEGATE |
  7930. SEC_ENABLE_FILTER));
  7931. }
  7932. }
  7933. if (asc_dvc->bus_type == ASC_IS_PCI) {
  7934. AscSetExtraControl(iop_base,
  7935. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  7936. }
  7937. asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
  7938. #ifdef CONFIG_ISA
  7939. if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
  7940. if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
  7941. AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
  7942. asc_dvc->bus_type = ASC_IS_ISAPNP;
  7943. }
  7944. asc_dvc->cfg->isa_dma_channel =
  7945. (uchar)AscGetIsaDmaChannel(iop_base);
  7946. }
  7947. #endif /* CONFIG_ISA */
  7948. for (i = 0; i <= ASC_MAX_TID; i++) {
  7949. asc_dvc->cur_dvc_qng[i] = 0;
  7950. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  7951. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  7952. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  7953. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  7954. }
  7955. }
  7956. static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  7957. {
  7958. int retry;
  7959. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  7960. unsigned char read_back;
  7961. AscSetChipEEPCmd(iop_base, cmd_reg);
  7962. mdelay(1);
  7963. read_back = AscGetChipEEPCmd(iop_base);
  7964. if (read_back == cmd_reg)
  7965. return 1;
  7966. }
  7967. return 0;
  7968. }
  7969. static void AscWaitEEPRead(void)
  7970. {
  7971. mdelay(1);
  7972. }
  7973. static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
  7974. {
  7975. ushort read_wval;
  7976. uchar cmd_reg;
  7977. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  7978. AscWaitEEPRead();
  7979. cmd_reg = addr | ASC_EEP_CMD_READ;
  7980. AscWriteEEPCmdReg(iop_base, cmd_reg);
  7981. AscWaitEEPRead();
  7982. read_wval = AscGetChipEEPData(iop_base);
  7983. AscWaitEEPRead();
  7984. return read_wval;
  7985. }
  7986. static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  7987. ushort bus_type)
  7988. {
  7989. ushort wval;
  7990. ushort sum;
  7991. ushort *wbuf;
  7992. int cfg_beg;
  7993. int cfg_end;
  7994. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  7995. int s_addr;
  7996. wbuf = (ushort *)cfg_buf;
  7997. sum = 0;
  7998. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  7999. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8000. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8001. sum += *wbuf;
  8002. }
  8003. if (bus_type & ASC_IS_VL) {
  8004. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8005. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8006. } else {
  8007. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8008. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8009. }
  8010. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8011. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  8012. if (s_addr <= uchar_end_in_config) {
  8013. /*
  8014. * Swap all char fields - must unswap bytes already swapped
  8015. * by AscReadEEPWord().
  8016. */
  8017. *wbuf = le16_to_cpu(wval);
  8018. } else {
  8019. /* Don't swap word field at the end - cntl field. */
  8020. *wbuf = wval;
  8021. }
  8022. sum += wval; /* Checksum treats all EEPROM data as words. */
  8023. }
  8024. /*
  8025. * Read the checksum word which will be compared against 'sum'
  8026. * by the caller. Word field already swapped.
  8027. */
  8028. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8029. return sum;
  8030. }
  8031. static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  8032. {
  8033. PortAddr iop_base;
  8034. ushort q_addr;
  8035. ushort saved_word;
  8036. int sta;
  8037. iop_base = asc_dvc->iop_base;
  8038. sta = 0;
  8039. q_addr = ASC_QNO_TO_QADDR(241);
  8040. saved_word = AscReadLramWord(iop_base, q_addr);
  8041. AscSetChipLramAddr(iop_base, q_addr);
  8042. AscSetChipLramData(iop_base, 0x55AA);
  8043. mdelay(10);
  8044. AscSetChipLramAddr(iop_base, q_addr);
  8045. if (AscGetChipLramData(iop_base) == 0x55AA) {
  8046. sta = 1;
  8047. AscWriteLramWord(iop_base, q_addr, saved_word);
  8048. }
  8049. return (sta);
  8050. }
  8051. static void AscWaitEEPWrite(void)
  8052. {
  8053. mdelay(20);
  8054. }
  8055. static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  8056. {
  8057. ushort read_back;
  8058. int retry;
  8059. retry = 0;
  8060. while (true) {
  8061. AscSetChipEEPData(iop_base, data_reg);
  8062. mdelay(1);
  8063. read_back = AscGetChipEEPData(iop_base);
  8064. if (read_back == data_reg) {
  8065. return (1);
  8066. }
  8067. if (retry++ > ASC_EEP_MAX_RETRY) {
  8068. return (0);
  8069. }
  8070. }
  8071. }
  8072. static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  8073. {
  8074. ushort read_wval;
  8075. read_wval = AscReadEEPWord(iop_base, addr);
  8076. if (read_wval != word_val) {
  8077. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  8078. AscWaitEEPRead();
  8079. AscWriteEEPDataReg(iop_base, word_val);
  8080. AscWaitEEPRead();
  8081. AscWriteEEPCmdReg(iop_base,
  8082. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  8083. AscWaitEEPWrite();
  8084. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8085. AscWaitEEPRead();
  8086. return (AscReadEEPWord(iop_base, addr));
  8087. }
  8088. return (read_wval);
  8089. }
  8090. static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8091. ushort bus_type)
  8092. {
  8093. int n_error;
  8094. ushort *wbuf;
  8095. ushort word;
  8096. ushort sum;
  8097. int s_addr;
  8098. int cfg_beg;
  8099. int cfg_end;
  8100. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8101. wbuf = (ushort *)cfg_buf;
  8102. n_error = 0;
  8103. sum = 0;
  8104. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  8105. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8106. sum += *wbuf;
  8107. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8108. n_error++;
  8109. }
  8110. }
  8111. if (bus_type & ASC_IS_VL) {
  8112. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8113. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8114. } else {
  8115. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8116. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8117. }
  8118. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8119. if (s_addr <= uchar_end_in_config) {
  8120. /*
  8121. * This is a char field. Swap char fields before they are
  8122. * swapped again by AscWriteEEPWord().
  8123. */
  8124. word = cpu_to_le16(*wbuf);
  8125. if (word !=
  8126. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  8127. n_error++;
  8128. }
  8129. } else {
  8130. /* Don't swap word field at the end - cntl field. */
  8131. if (*wbuf !=
  8132. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8133. n_error++;
  8134. }
  8135. }
  8136. sum += *wbuf; /* Checksum calculated from word values. */
  8137. }
  8138. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  8139. *wbuf = sum;
  8140. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  8141. n_error++;
  8142. }
  8143. /* Read EEPROM back again. */
  8144. wbuf = (ushort *)cfg_buf;
  8145. /*
  8146. * Read two config words; Byte-swapping done by AscReadEEPWord().
  8147. */
  8148. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8149. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  8150. n_error++;
  8151. }
  8152. }
  8153. if (bus_type & ASC_IS_VL) {
  8154. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8155. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8156. } else {
  8157. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8158. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8159. }
  8160. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8161. if (s_addr <= uchar_end_in_config) {
  8162. /*
  8163. * Swap all char fields. Must unswap bytes already swapped
  8164. * by AscReadEEPWord().
  8165. */
  8166. word =
  8167. le16_to_cpu(AscReadEEPWord
  8168. (iop_base, (uchar)s_addr));
  8169. } else {
  8170. /* Don't swap word field at the end - cntl field. */
  8171. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  8172. }
  8173. if (*wbuf != word) {
  8174. n_error++;
  8175. }
  8176. }
  8177. /* Read checksum; Byte swapping not needed. */
  8178. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  8179. n_error++;
  8180. }
  8181. return n_error;
  8182. }
  8183. static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8184. ushort bus_type)
  8185. {
  8186. int retry;
  8187. int n_error;
  8188. retry = 0;
  8189. while (true) {
  8190. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  8191. bus_type)) == 0) {
  8192. break;
  8193. }
  8194. if (++retry > ASC_EEP_MAX_RETRY) {
  8195. break;
  8196. }
  8197. }
  8198. return n_error;
  8199. }
  8200. static int AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  8201. {
  8202. ASCEEP_CONFIG eep_config_buf;
  8203. ASCEEP_CONFIG *eep_config;
  8204. PortAddr iop_base;
  8205. ushort chksum;
  8206. ushort warn_code;
  8207. ushort cfg_msw, cfg_lsw;
  8208. int i;
  8209. int write_eep = 0;
  8210. iop_base = asc_dvc->iop_base;
  8211. warn_code = 0;
  8212. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  8213. AscStopQueueExe(iop_base);
  8214. if ((AscStopChip(iop_base)) ||
  8215. (AscGetChipScsiCtrl(iop_base) != 0)) {
  8216. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  8217. AscResetChipAndScsiBus(asc_dvc);
  8218. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  8219. }
  8220. if (!AscIsChipHalted(iop_base)) {
  8221. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  8222. return (warn_code);
  8223. }
  8224. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  8225. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  8226. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  8227. return (warn_code);
  8228. }
  8229. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  8230. cfg_msw = AscGetChipCfgMsw(iop_base);
  8231. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8232. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8233. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8234. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8235. AscSetChipCfgMsw(iop_base, cfg_msw);
  8236. }
  8237. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  8238. ASC_DBG(1, "chksum 0x%x\n", chksum);
  8239. if (chksum == 0) {
  8240. chksum = 0xaa55;
  8241. }
  8242. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8243. warn_code |= ASC_WARN_AUTO_CONFIG;
  8244. if (asc_dvc->cfg->chip_version == 3) {
  8245. if (eep_config->cfg_lsw != cfg_lsw) {
  8246. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8247. eep_config->cfg_lsw =
  8248. AscGetChipCfgLsw(iop_base);
  8249. }
  8250. if (eep_config->cfg_msw != cfg_msw) {
  8251. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8252. eep_config->cfg_msw =
  8253. AscGetChipCfgMsw(iop_base);
  8254. }
  8255. }
  8256. }
  8257. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8258. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  8259. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  8260. if (chksum != eep_config->chksum) {
  8261. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  8262. ASC_CHIP_VER_PCI_ULTRA_3050) {
  8263. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  8264. eep_config->init_sdtr = 0xFF;
  8265. eep_config->disc_enable = 0xFF;
  8266. eep_config->start_motor = 0xFF;
  8267. eep_config->use_cmd_qng = 0;
  8268. eep_config->max_total_qng = 0xF0;
  8269. eep_config->max_tag_qng = 0x20;
  8270. eep_config->cntl = 0xBFFF;
  8271. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  8272. eep_config->no_scam = 0;
  8273. eep_config->adapter_info[0] = 0;
  8274. eep_config->adapter_info[1] = 0;
  8275. eep_config->adapter_info[2] = 0;
  8276. eep_config->adapter_info[3] = 0;
  8277. eep_config->adapter_info[4] = 0;
  8278. /* Indicate EEPROM-less board. */
  8279. eep_config->adapter_info[5] = 0xBB;
  8280. } else {
  8281. ASC_PRINT
  8282. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  8283. write_eep = 1;
  8284. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  8285. }
  8286. }
  8287. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  8288. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  8289. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  8290. asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
  8291. asc_dvc->start_motor = eep_config->start_motor;
  8292. asc_dvc->dvc_cntl = eep_config->cntl;
  8293. asc_dvc->no_scam = eep_config->no_scam;
  8294. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  8295. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  8296. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  8297. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  8298. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  8299. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  8300. if (!AscTestExternalLram(asc_dvc)) {
  8301. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  8302. ASC_IS_PCI_ULTRA)) {
  8303. eep_config->max_total_qng =
  8304. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  8305. eep_config->max_tag_qng =
  8306. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  8307. } else {
  8308. eep_config->cfg_msw |= 0x0800;
  8309. cfg_msw |= 0x0800;
  8310. AscSetChipCfgMsw(iop_base, cfg_msw);
  8311. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  8312. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  8313. }
  8314. } else {
  8315. }
  8316. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  8317. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  8318. }
  8319. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  8320. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  8321. }
  8322. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  8323. eep_config->max_tag_qng = eep_config->max_total_qng;
  8324. }
  8325. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  8326. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  8327. }
  8328. asc_dvc->max_total_qng = eep_config->max_total_qng;
  8329. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  8330. eep_config->use_cmd_qng) {
  8331. eep_config->disc_enable = eep_config->use_cmd_qng;
  8332. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8333. }
  8334. ASC_EEP_SET_CHIP_ID(eep_config,
  8335. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  8336. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  8337. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  8338. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  8339. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  8340. }
  8341. for (i = 0; i <= ASC_MAX_TID; i++) {
  8342. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  8343. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  8344. asc_dvc->cfg->sdtr_period_offset[i] =
  8345. (uchar)(ASC_DEF_SDTR_OFFSET |
  8346. (asc_dvc->min_sdtr_index << 4));
  8347. }
  8348. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  8349. if (write_eep) {
  8350. if ((i = AscSetEEPConfig(iop_base, eep_config,
  8351. asc_dvc->bus_type)) != 0) {
  8352. ASC_PRINT1
  8353. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  8354. i);
  8355. } else {
  8356. ASC_PRINT
  8357. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  8358. }
  8359. }
  8360. return (warn_code);
  8361. }
  8362. static int AscInitGetConfig(struct Scsi_Host *shost)
  8363. {
  8364. struct asc_board *board = shost_priv(shost);
  8365. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8366. unsigned short warn_code = 0;
  8367. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  8368. if (asc_dvc->err_code != 0)
  8369. return asc_dvc->err_code;
  8370. if (AscFindSignature(asc_dvc->iop_base)) {
  8371. AscInitAscDvcVar(asc_dvc);
  8372. warn_code = AscInitFromEEP(asc_dvc);
  8373. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  8374. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  8375. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  8376. } else {
  8377. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8378. }
  8379. switch (warn_code) {
  8380. case 0: /* No error */
  8381. break;
  8382. case ASC_WARN_IO_PORT_ROTATE:
  8383. shost_printk(KERN_WARNING, shost, "I/O port address "
  8384. "modified\n");
  8385. break;
  8386. case ASC_WARN_AUTO_CONFIG:
  8387. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8388. "enabled\n");
  8389. break;
  8390. case ASC_WARN_EEPROM_CHKSUM:
  8391. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8392. break;
  8393. case ASC_WARN_IRQ_MODIFIED:
  8394. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8395. break;
  8396. case ASC_WARN_CMD_QNG_CONFLICT:
  8397. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  8398. "disconnects\n");
  8399. break;
  8400. default:
  8401. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8402. warn_code);
  8403. break;
  8404. }
  8405. if (asc_dvc->err_code != 0)
  8406. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8407. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8408. return asc_dvc->err_code;
  8409. }
  8410. static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  8411. {
  8412. struct asc_board *board = shost_priv(shost);
  8413. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8414. PortAddr iop_base = asc_dvc->iop_base;
  8415. unsigned short cfg_msw;
  8416. unsigned short warn_code = 0;
  8417. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  8418. if (asc_dvc->err_code != 0)
  8419. return asc_dvc->err_code;
  8420. if (!AscFindSignature(asc_dvc->iop_base)) {
  8421. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8422. return asc_dvc->err_code;
  8423. }
  8424. cfg_msw = AscGetChipCfgMsw(iop_base);
  8425. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8426. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8427. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8428. AscSetChipCfgMsw(iop_base, cfg_msw);
  8429. }
  8430. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  8431. asc_dvc->cfg->cmd_qng_enabled) {
  8432. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  8433. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8434. }
  8435. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8436. warn_code |= ASC_WARN_AUTO_CONFIG;
  8437. }
  8438. #ifdef CONFIG_PCI
  8439. if (asc_dvc->bus_type & ASC_IS_PCI) {
  8440. cfg_msw &= 0xFFC0;
  8441. AscSetChipCfgMsw(iop_base, cfg_msw);
  8442. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  8443. } else {
  8444. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  8445. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  8446. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  8447. asc_dvc->bug_fix_cntl |=
  8448. ASC_BUG_FIX_ASYN_USE_SYN;
  8449. }
  8450. }
  8451. } else
  8452. #endif /* CONFIG_PCI */
  8453. if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
  8454. if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
  8455. == ASC_CHIP_VER_ASYN_BUG) {
  8456. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
  8457. }
  8458. }
  8459. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  8460. asc_dvc->cfg->chip_scsi_id) {
  8461. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  8462. }
  8463. #ifdef CONFIG_ISA
  8464. if (asc_dvc->bus_type & ASC_IS_ISA) {
  8465. AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
  8466. AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
  8467. }
  8468. #endif /* CONFIG_ISA */
  8469. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  8470. switch (warn_code) {
  8471. case 0: /* No error. */
  8472. break;
  8473. case ASC_WARN_IO_PORT_ROTATE:
  8474. shost_printk(KERN_WARNING, shost, "I/O port address "
  8475. "modified\n");
  8476. break;
  8477. case ASC_WARN_AUTO_CONFIG:
  8478. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8479. "enabled\n");
  8480. break;
  8481. case ASC_WARN_EEPROM_CHKSUM:
  8482. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8483. break;
  8484. case ASC_WARN_IRQ_MODIFIED:
  8485. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8486. break;
  8487. case ASC_WARN_CMD_QNG_CONFLICT:
  8488. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  8489. "disconnects\n");
  8490. break;
  8491. default:
  8492. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8493. warn_code);
  8494. break;
  8495. }
  8496. if (asc_dvc->err_code != 0)
  8497. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8498. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8499. return asc_dvc->err_code;
  8500. }
  8501. /*
  8502. * EEPROM Configuration.
  8503. *
  8504. * All drivers should use this structure to set the default EEPROM
  8505. * configuration. The BIOS now uses this structure when it is built.
  8506. * Additional structure information can be found in a_condor.h where
  8507. * the structure is defined.
  8508. *
  8509. * The *_Field_IsChar structs are needed to correct for endianness.
  8510. * These values are read from the board 16 bits at a time directly
  8511. * into the structs. Because some fields are char, the values will be
  8512. * in the wrong order. The *_Field_IsChar tells when to flip the
  8513. * bytes. Data read and written to PCI memory is automatically swapped
  8514. * on big-endian platforms so char fields read as words are actually being
  8515. * unswapped on big-endian platforms.
  8516. */
  8517. #ifdef CONFIG_PCI
  8518. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
  8519. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  8520. 0x0000, /* cfg_msw */
  8521. 0xFFFF, /* disc_enable */
  8522. 0xFFFF, /* wdtr_able */
  8523. 0xFFFF, /* sdtr_able */
  8524. 0xFFFF, /* start_motor */
  8525. 0xFFFF, /* tagqng_able */
  8526. 0xFFFF, /* bios_scan */
  8527. 0, /* scam_tolerant */
  8528. 7, /* adapter_scsi_id */
  8529. 0, /* bios_boot_delay */
  8530. 3, /* scsi_reset_delay */
  8531. 0, /* bios_id_lun */
  8532. 0, /* termination */
  8533. 0, /* reserved1 */
  8534. 0xFFE7, /* bios_ctrl */
  8535. 0xFFFF, /* ultra_able */
  8536. 0, /* reserved2 */
  8537. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  8538. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8539. 0, /* dvc_cntl */
  8540. 0, /* bug_fix */
  8541. 0, /* serial_number_word1 */
  8542. 0, /* serial_number_word2 */
  8543. 0, /* serial_number_word3 */
  8544. 0, /* check_sum */
  8545. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8546. , /* oem_name[16] */
  8547. 0, /* dvc_err_code */
  8548. 0, /* adv_err_code */
  8549. 0, /* adv_err_addr */
  8550. 0, /* saved_dvc_err_code */
  8551. 0, /* saved_adv_err_code */
  8552. 0, /* saved_adv_err_addr */
  8553. 0 /* num_of_err */
  8554. };
  8555. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
  8556. 0, /* cfg_lsw */
  8557. 0, /* cfg_msw */
  8558. 0, /* -disc_enable */
  8559. 0, /* wdtr_able */
  8560. 0, /* sdtr_able */
  8561. 0, /* start_motor */
  8562. 0, /* tagqng_able */
  8563. 0, /* bios_scan */
  8564. 0, /* scam_tolerant */
  8565. 1, /* adapter_scsi_id */
  8566. 1, /* bios_boot_delay */
  8567. 1, /* scsi_reset_delay */
  8568. 1, /* bios_id_lun */
  8569. 1, /* termination */
  8570. 1, /* reserved1 */
  8571. 0, /* bios_ctrl */
  8572. 0, /* ultra_able */
  8573. 0, /* reserved2 */
  8574. 1, /* max_host_qng */
  8575. 1, /* max_dvc_qng */
  8576. 0, /* dvc_cntl */
  8577. 0, /* bug_fix */
  8578. 0, /* serial_number_word1 */
  8579. 0, /* serial_number_word2 */
  8580. 0, /* serial_number_word3 */
  8581. 0, /* check_sum */
  8582. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8583. , /* oem_name[16] */
  8584. 0, /* dvc_err_code */
  8585. 0, /* adv_err_code */
  8586. 0, /* adv_err_addr */
  8587. 0, /* saved_dvc_err_code */
  8588. 0, /* saved_adv_err_code */
  8589. 0, /* saved_adv_err_addr */
  8590. 0 /* num_of_err */
  8591. };
  8592. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
  8593. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  8594. 0x0000, /* 01 cfg_msw */
  8595. 0xFFFF, /* 02 disc_enable */
  8596. 0xFFFF, /* 03 wdtr_able */
  8597. 0x4444, /* 04 sdtr_speed1 */
  8598. 0xFFFF, /* 05 start_motor */
  8599. 0xFFFF, /* 06 tagqng_able */
  8600. 0xFFFF, /* 07 bios_scan */
  8601. 0, /* 08 scam_tolerant */
  8602. 7, /* 09 adapter_scsi_id */
  8603. 0, /* bios_boot_delay */
  8604. 3, /* 10 scsi_reset_delay */
  8605. 0, /* bios_id_lun */
  8606. 0, /* 11 termination_se */
  8607. 0, /* termination_lvd */
  8608. 0xFFE7, /* 12 bios_ctrl */
  8609. 0x4444, /* 13 sdtr_speed2 */
  8610. 0x4444, /* 14 sdtr_speed3 */
  8611. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  8612. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8613. 0, /* 16 dvc_cntl */
  8614. 0x4444, /* 17 sdtr_speed4 */
  8615. 0, /* 18 serial_number_word1 */
  8616. 0, /* 19 serial_number_word2 */
  8617. 0, /* 20 serial_number_word3 */
  8618. 0, /* 21 check_sum */
  8619. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8620. , /* 22-29 oem_name[16] */
  8621. 0, /* 30 dvc_err_code */
  8622. 0, /* 31 adv_err_code */
  8623. 0, /* 32 adv_err_addr */
  8624. 0, /* 33 saved_dvc_err_code */
  8625. 0, /* 34 saved_adv_err_code */
  8626. 0, /* 35 saved_adv_err_addr */
  8627. 0, /* 36 reserved */
  8628. 0, /* 37 reserved */
  8629. 0, /* 38 reserved */
  8630. 0, /* 39 reserved */
  8631. 0, /* 40 reserved */
  8632. 0, /* 41 reserved */
  8633. 0, /* 42 reserved */
  8634. 0, /* 43 reserved */
  8635. 0, /* 44 reserved */
  8636. 0, /* 45 reserved */
  8637. 0, /* 46 reserved */
  8638. 0, /* 47 reserved */
  8639. 0, /* 48 reserved */
  8640. 0, /* 49 reserved */
  8641. 0, /* 50 reserved */
  8642. 0, /* 51 reserved */
  8643. 0, /* 52 reserved */
  8644. 0, /* 53 reserved */
  8645. 0, /* 54 reserved */
  8646. 0, /* 55 reserved */
  8647. 0, /* 56 cisptr_lsw */
  8648. 0, /* 57 cisprt_msw */
  8649. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  8650. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  8651. 0, /* 60 reserved */
  8652. 0, /* 61 reserved */
  8653. 0, /* 62 reserved */
  8654. 0 /* 63 reserved */
  8655. };
  8656. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
  8657. 0, /* 00 cfg_lsw */
  8658. 0, /* 01 cfg_msw */
  8659. 0, /* 02 disc_enable */
  8660. 0, /* 03 wdtr_able */
  8661. 0, /* 04 sdtr_speed1 */
  8662. 0, /* 05 start_motor */
  8663. 0, /* 06 tagqng_able */
  8664. 0, /* 07 bios_scan */
  8665. 0, /* 08 scam_tolerant */
  8666. 1, /* 09 adapter_scsi_id */
  8667. 1, /* bios_boot_delay */
  8668. 1, /* 10 scsi_reset_delay */
  8669. 1, /* bios_id_lun */
  8670. 1, /* 11 termination_se */
  8671. 1, /* termination_lvd */
  8672. 0, /* 12 bios_ctrl */
  8673. 0, /* 13 sdtr_speed2 */
  8674. 0, /* 14 sdtr_speed3 */
  8675. 1, /* 15 max_host_qng */
  8676. 1, /* max_dvc_qng */
  8677. 0, /* 16 dvc_cntl */
  8678. 0, /* 17 sdtr_speed4 */
  8679. 0, /* 18 serial_number_word1 */
  8680. 0, /* 19 serial_number_word2 */
  8681. 0, /* 20 serial_number_word3 */
  8682. 0, /* 21 check_sum */
  8683. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8684. , /* 22-29 oem_name[16] */
  8685. 0, /* 30 dvc_err_code */
  8686. 0, /* 31 adv_err_code */
  8687. 0, /* 32 adv_err_addr */
  8688. 0, /* 33 saved_dvc_err_code */
  8689. 0, /* 34 saved_adv_err_code */
  8690. 0, /* 35 saved_adv_err_addr */
  8691. 0, /* 36 reserved */
  8692. 0, /* 37 reserved */
  8693. 0, /* 38 reserved */
  8694. 0, /* 39 reserved */
  8695. 0, /* 40 reserved */
  8696. 0, /* 41 reserved */
  8697. 0, /* 42 reserved */
  8698. 0, /* 43 reserved */
  8699. 0, /* 44 reserved */
  8700. 0, /* 45 reserved */
  8701. 0, /* 46 reserved */
  8702. 0, /* 47 reserved */
  8703. 0, /* 48 reserved */
  8704. 0, /* 49 reserved */
  8705. 0, /* 50 reserved */
  8706. 0, /* 51 reserved */
  8707. 0, /* 52 reserved */
  8708. 0, /* 53 reserved */
  8709. 0, /* 54 reserved */
  8710. 0, /* 55 reserved */
  8711. 0, /* 56 cisptr_lsw */
  8712. 0, /* 57 cisprt_msw */
  8713. 0, /* 58 subsysvid */
  8714. 0, /* 59 subsysid */
  8715. 0, /* 60 reserved */
  8716. 0, /* 61 reserved */
  8717. 0, /* 62 reserved */
  8718. 0 /* 63 reserved */
  8719. };
  8720. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
  8721. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  8722. 0x0000, /* 01 cfg_msw */
  8723. 0xFFFF, /* 02 disc_enable */
  8724. 0xFFFF, /* 03 wdtr_able */
  8725. 0x5555, /* 04 sdtr_speed1 */
  8726. 0xFFFF, /* 05 start_motor */
  8727. 0xFFFF, /* 06 tagqng_able */
  8728. 0xFFFF, /* 07 bios_scan */
  8729. 0, /* 08 scam_tolerant */
  8730. 7, /* 09 adapter_scsi_id */
  8731. 0, /* bios_boot_delay */
  8732. 3, /* 10 scsi_reset_delay */
  8733. 0, /* bios_id_lun */
  8734. 0, /* 11 termination_se */
  8735. 0, /* termination_lvd */
  8736. 0xFFE7, /* 12 bios_ctrl */
  8737. 0x5555, /* 13 sdtr_speed2 */
  8738. 0x5555, /* 14 sdtr_speed3 */
  8739. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  8740. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8741. 0, /* 16 dvc_cntl */
  8742. 0x5555, /* 17 sdtr_speed4 */
  8743. 0, /* 18 serial_number_word1 */
  8744. 0, /* 19 serial_number_word2 */
  8745. 0, /* 20 serial_number_word3 */
  8746. 0, /* 21 check_sum */
  8747. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8748. , /* 22-29 oem_name[16] */
  8749. 0, /* 30 dvc_err_code */
  8750. 0, /* 31 adv_err_code */
  8751. 0, /* 32 adv_err_addr */
  8752. 0, /* 33 saved_dvc_err_code */
  8753. 0, /* 34 saved_adv_err_code */
  8754. 0, /* 35 saved_adv_err_addr */
  8755. 0, /* 36 reserved */
  8756. 0, /* 37 reserved */
  8757. 0, /* 38 reserved */
  8758. 0, /* 39 reserved */
  8759. 0, /* 40 reserved */
  8760. 0, /* 41 reserved */
  8761. 0, /* 42 reserved */
  8762. 0, /* 43 reserved */
  8763. 0, /* 44 reserved */
  8764. 0, /* 45 reserved */
  8765. 0, /* 46 reserved */
  8766. 0, /* 47 reserved */
  8767. 0, /* 48 reserved */
  8768. 0, /* 49 reserved */
  8769. 0, /* 50 reserved */
  8770. 0, /* 51 reserved */
  8771. 0, /* 52 reserved */
  8772. 0, /* 53 reserved */
  8773. 0, /* 54 reserved */
  8774. 0, /* 55 reserved */
  8775. 0, /* 56 cisptr_lsw */
  8776. 0, /* 57 cisprt_msw */
  8777. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  8778. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  8779. 0, /* 60 reserved */
  8780. 0, /* 61 reserved */
  8781. 0, /* 62 reserved */
  8782. 0 /* 63 reserved */
  8783. };
  8784. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
  8785. 0, /* 00 cfg_lsw */
  8786. 0, /* 01 cfg_msw */
  8787. 0, /* 02 disc_enable */
  8788. 0, /* 03 wdtr_able */
  8789. 0, /* 04 sdtr_speed1 */
  8790. 0, /* 05 start_motor */
  8791. 0, /* 06 tagqng_able */
  8792. 0, /* 07 bios_scan */
  8793. 0, /* 08 scam_tolerant */
  8794. 1, /* 09 adapter_scsi_id */
  8795. 1, /* bios_boot_delay */
  8796. 1, /* 10 scsi_reset_delay */
  8797. 1, /* bios_id_lun */
  8798. 1, /* 11 termination_se */
  8799. 1, /* termination_lvd */
  8800. 0, /* 12 bios_ctrl */
  8801. 0, /* 13 sdtr_speed2 */
  8802. 0, /* 14 sdtr_speed3 */
  8803. 1, /* 15 max_host_qng */
  8804. 1, /* max_dvc_qng */
  8805. 0, /* 16 dvc_cntl */
  8806. 0, /* 17 sdtr_speed4 */
  8807. 0, /* 18 serial_number_word1 */
  8808. 0, /* 19 serial_number_word2 */
  8809. 0, /* 20 serial_number_word3 */
  8810. 0, /* 21 check_sum */
  8811. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8812. , /* 22-29 oem_name[16] */
  8813. 0, /* 30 dvc_err_code */
  8814. 0, /* 31 adv_err_code */
  8815. 0, /* 32 adv_err_addr */
  8816. 0, /* 33 saved_dvc_err_code */
  8817. 0, /* 34 saved_adv_err_code */
  8818. 0, /* 35 saved_adv_err_addr */
  8819. 0, /* 36 reserved */
  8820. 0, /* 37 reserved */
  8821. 0, /* 38 reserved */
  8822. 0, /* 39 reserved */
  8823. 0, /* 40 reserved */
  8824. 0, /* 41 reserved */
  8825. 0, /* 42 reserved */
  8826. 0, /* 43 reserved */
  8827. 0, /* 44 reserved */
  8828. 0, /* 45 reserved */
  8829. 0, /* 46 reserved */
  8830. 0, /* 47 reserved */
  8831. 0, /* 48 reserved */
  8832. 0, /* 49 reserved */
  8833. 0, /* 50 reserved */
  8834. 0, /* 51 reserved */
  8835. 0, /* 52 reserved */
  8836. 0, /* 53 reserved */
  8837. 0, /* 54 reserved */
  8838. 0, /* 55 reserved */
  8839. 0, /* 56 cisptr_lsw */
  8840. 0, /* 57 cisprt_msw */
  8841. 0, /* 58 subsysvid */
  8842. 0, /* 59 subsysid */
  8843. 0, /* 60 reserved */
  8844. 0, /* 61 reserved */
  8845. 0, /* 62 reserved */
  8846. 0 /* 63 reserved */
  8847. };
  8848. /*
  8849. * Wait for EEPROM command to complete
  8850. */
  8851. static void AdvWaitEEPCmd(AdvPortAddr iop_base)
  8852. {
  8853. int eep_delay_ms;
  8854. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  8855. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  8856. ASC_EEP_CMD_DONE) {
  8857. break;
  8858. }
  8859. mdelay(1);
  8860. }
  8861. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  8862. 0)
  8863. BUG();
  8864. }
  8865. /*
  8866. * Read the EEPROM from specified location
  8867. */
  8868. static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  8869. {
  8870. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8871. ASC_EEP_CMD_READ | eep_word_addr);
  8872. AdvWaitEEPCmd(iop_base);
  8873. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  8874. }
  8875. /*
  8876. * Write the EEPROM from 'cfg_buf'.
  8877. */
  8878. static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
  8879. ADVEEP_3550_CONFIG *cfg_buf)
  8880. {
  8881. ushort *wbuf;
  8882. ushort addr, chksum;
  8883. ushort *charfields;
  8884. wbuf = (ushort *)cfg_buf;
  8885. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  8886. chksum = 0;
  8887. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8888. AdvWaitEEPCmd(iop_base);
  8889. /*
  8890. * Write EEPROM from word 0 to word 20.
  8891. */
  8892. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8893. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8894. ushort word;
  8895. if (*charfields++) {
  8896. word = cpu_to_le16(*wbuf);
  8897. } else {
  8898. word = *wbuf;
  8899. }
  8900. chksum += *wbuf; /* Checksum is calculated from word values. */
  8901. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8902. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8903. ASC_EEP_CMD_WRITE | addr);
  8904. AdvWaitEEPCmd(iop_base);
  8905. mdelay(ADV_EEP_DELAY_MS);
  8906. }
  8907. /*
  8908. * Write EEPROM checksum at word 21.
  8909. */
  8910. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8911. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8912. AdvWaitEEPCmd(iop_base);
  8913. wbuf++;
  8914. charfields++;
  8915. /*
  8916. * Write EEPROM OEM name at words 22 to 29.
  8917. */
  8918. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8919. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8920. ushort word;
  8921. if (*charfields++) {
  8922. word = cpu_to_le16(*wbuf);
  8923. } else {
  8924. word = *wbuf;
  8925. }
  8926. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8927. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8928. ASC_EEP_CMD_WRITE | addr);
  8929. AdvWaitEEPCmd(iop_base);
  8930. }
  8931. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8932. AdvWaitEEPCmd(iop_base);
  8933. }
  8934. /*
  8935. * Write the EEPROM from 'cfg_buf'.
  8936. */
  8937. static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
  8938. ADVEEP_38C0800_CONFIG *cfg_buf)
  8939. {
  8940. ushort *wbuf;
  8941. ushort *charfields;
  8942. ushort addr, chksum;
  8943. wbuf = (ushort *)cfg_buf;
  8944. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  8945. chksum = 0;
  8946. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8947. AdvWaitEEPCmd(iop_base);
  8948. /*
  8949. * Write EEPROM from word 0 to word 20.
  8950. */
  8951. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8952. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8953. ushort word;
  8954. if (*charfields++) {
  8955. word = cpu_to_le16(*wbuf);
  8956. } else {
  8957. word = *wbuf;
  8958. }
  8959. chksum += *wbuf; /* Checksum is calculated from word values. */
  8960. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8961. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8962. ASC_EEP_CMD_WRITE | addr);
  8963. AdvWaitEEPCmd(iop_base);
  8964. mdelay(ADV_EEP_DELAY_MS);
  8965. }
  8966. /*
  8967. * Write EEPROM checksum at word 21.
  8968. */
  8969. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8970. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8971. AdvWaitEEPCmd(iop_base);
  8972. wbuf++;
  8973. charfields++;
  8974. /*
  8975. * Write EEPROM OEM name at words 22 to 29.
  8976. */
  8977. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8978. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8979. ushort word;
  8980. if (*charfields++) {
  8981. word = cpu_to_le16(*wbuf);
  8982. } else {
  8983. word = *wbuf;
  8984. }
  8985. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8986. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8987. ASC_EEP_CMD_WRITE | addr);
  8988. AdvWaitEEPCmd(iop_base);
  8989. }
  8990. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8991. AdvWaitEEPCmd(iop_base);
  8992. }
  8993. /*
  8994. * Write the EEPROM from 'cfg_buf'.
  8995. */
  8996. static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
  8997. ADVEEP_38C1600_CONFIG *cfg_buf)
  8998. {
  8999. ushort *wbuf;
  9000. ushort *charfields;
  9001. ushort addr, chksum;
  9002. wbuf = (ushort *)cfg_buf;
  9003. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9004. chksum = 0;
  9005. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9006. AdvWaitEEPCmd(iop_base);
  9007. /*
  9008. * Write EEPROM from word 0 to word 20.
  9009. */
  9010. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9011. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9012. ushort word;
  9013. if (*charfields++) {
  9014. word = cpu_to_le16(*wbuf);
  9015. } else {
  9016. word = *wbuf;
  9017. }
  9018. chksum += *wbuf; /* Checksum is calculated from word values. */
  9019. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9020. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9021. ASC_EEP_CMD_WRITE | addr);
  9022. AdvWaitEEPCmd(iop_base);
  9023. mdelay(ADV_EEP_DELAY_MS);
  9024. }
  9025. /*
  9026. * Write EEPROM checksum at word 21.
  9027. */
  9028. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9029. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9030. AdvWaitEEPCmd(iop_base);
  9031. wbuf++;
  9032. charfields++;
  9033. /*
  9034. * Write EEPROM OEM name at words 22 to 29.
  9035. */
  9036. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9037. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9038. ushort word;
  9039. if (*charfields++) {
  9040. word = cpu_to_le16(*wbuf);
  9041. } else {
  9042. word = *wbuf;
  9043. }
  9044. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9045. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9046. ASC_EEP_CMD_WRITE | addr);
  9047. AdvWaitEEPCmd(iop_base);
  9048. }
  9049. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9050. AdvWaitEEPCmd(iop_base);
  9051. }
  9052. /*
  9053. * Read EEPROM configuration into the specified buffer.
  9054. *
  9055. * Return a checksum based on the EEPROM configuration read.
  9056. */
  9057. static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
  9058. ADVEEP_3550_CONFIG *cfg_buf)
  9059. {
  9060. ushort wval, chksum;
  9061. ushort *wbuf;
  9062. int eep_addr;
  9063. ushort *charfields;
  9064. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9065. wbuf = (ushort *)cfg_buf;
  9066. chksum = 0;
  9067. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9068. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9069. wval = AdvReadEEPWord(iop_base, eep_addr);
  9070. chksum += wval; /* Checksum is calculated from word values. */
  9071. if (*charfields++) {
  9072. *wbuf = le16_to_cpu(wval);
  9073. } else {
  9074. *wbuf = wval;
  9075. }
  9076. }
  9077. /* Read checksum word. */
  9078. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9079. wbuf++;
  9080. charfields++;
  9081. /* Read rest of EEPROM not covered by the checksum. */
  9082. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9083. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9084. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9085. if (*charfields++) {
  9086. *wbuf = le16_to_cpu(*wbuf);
  9087. }
  9088. }
  9089. return chksum;
  9090. }
  9091. /*
  9092. * Read EEPROM configuration into the specified buffer.
  9093. *
  9094. * Return a checksum based on the EEPROM configuration read.
  9095. */
  9096. static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
  9097. ADVEEP_38C0800_CONFIG *cfg_buf)
  9098. {
  9099. ushort wval, chksum;
  9100. ushort *wbuf;
  9101. int eep_addr;
  9102. ushort *charfields;
  9103. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9104. wbuf = (ushort *)cfg_buf;
  9105. chksum = 0;
  9106. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9107. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9108. wval = AdvReadEEPWord(iop_base, eep_addr);
  9109. chksum += wval; /* Checksum is calculated from word values. */
  9110. if (*charfields++) {
  9111. *wbuf = le16_to_cpu(wval);
  9112. } else {
  9113. *wbuf = wval;
  9114. }
  9115. }
  9116. /* Read checksum word. */
  9117. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9118. wbuf++;
  9119. charfields++;
  9120. /* Read rest of EEPROM not covered by the checksum. */
  9121. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9122. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9123. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9124. if (*charfields++) {
  9125. *wbuf = le16_to_cpu(*wbuf);
  9126. }
  9127. }
  9128. return chksum;
  9129. }
  9130. /*
  9131. * Read EEPROM configuration into the specified buffer.
  9132. *
  9133. * Return a checksum based on the EEPROM configuration read.
  9134. */
  9135. static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
  9136. ADVEEP_38C1600_CONFIG *cfg_buf)
  9137. {
  9138. ushort wval, chksum;
  9139. ushort *wbuf;
  9140. int eep_addr;
  9141. ushort *charfields;
  9142. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9143. wbuf = (ushort *)cfg_buf;
  9144. chksum = 0;
  9145. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9146. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9147. wval = AdvReadEEPWord(iop_base, eep_addr);
  9148. chksum += wval; /* Checksum is calculated from word values. */
  9149. if (*charfields++) {
  9150. *wbuf = le16_to_cpu(wval);
  9151. } else {
  9152. *wbuf = wval;
  9153. }
  9154. }
  9155. /* Read checksum word. */
  9156. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9157. wbuf++;
  9158. charfields++;
  9159. /* Read rest of EEPROM not covered by the checksum. */
  9160. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9161. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9162. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9163. if (*charfields++) {
  9164. *wbuf = le16_to_cpu(*wbuf);
  9165. }
  9166. }
  9167. return chksum;
  9168. }
  9169. /*
  9170. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9171. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9172. * all of this is done.
  9173. *
  9174. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9175. *
  9176. * For a non-fatal error return a warning code. If there are no warnings
  9177. * then 0 is returned.
  9178. *
  9179. * Note: Chip is stopped on entry.
  9180. */
  9181. static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  9182. {
  9183. AdvPortAddr iop_base;
  9184. ushort warn_code;
  9185. ADVEEP_3550_CONFIG eep_config;
  9186. iop_base = asc_dvc->iop_base;
  9187. warn_code = 0;
  9188. /*
  9189. * Read the board's EEPROM configuration.
  9190. *
  9191. * Set default values if a bad checksum is found.
  9192. */
  9193. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  9194. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9195. /*
  9196. * Set EEPROM default values.
  9197. */
  9198. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  9199. sizeof(ADVEEP_3550_CONFIG));
  9200. /*
  9201. * Assume the 6 byte board serial number that was read from
  9202. * EEPROM is correct even if the EEPROM checksum failed.
  9203. */
  9204. eep_config.serial_number_word3 =
  9205. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9206. eep_config.serial_number_word2 =
  9207. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9208. eep_config.serial_number_word1 =
  9209. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9210. AdvSet3550EEPConfig(iop_base, &eep_config);
  9211. }
  9212. /*
  9213. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9214. * EEPROM configuration that was read.
  9215. *
  9216. * This is the mapping of EEPROM fields to Adv Library fields.
  9217. */
  9218. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9219. asc_dvc->sdtr_able = eep_config.sdtr_able;
  9220. asc_dvc->ultra_able = eep_config.ultra_able;
  9221. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9222. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9223. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9224. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9225. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9226. asc_dvc->start_motor = eep_config.start_motor;
  9227. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9228. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9229. asc_dvc->no_scam = eep_config.scam_tolerant;
  9230. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9231. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9232. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9233. /*
  9234. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9235. * maximum queuing (max. 63, min. 4).
  9236. */
  9237. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9238. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9239. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9240. /* If the value is zero, assume it is uninitialized. */
  9241. if (eep_config.max_host_qng == 0) {
  9242. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9243. } else {
  9244. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9245. }
  9246. }
  9247. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9248. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9249. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9250. /* If the value is zero, assume it is uninitialized. */
  9251. if (eep_config.max_dvc_qng == 0) {
  9252. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9253. } else {
  9254. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9255. }
  9256. }
  9257. /*
  9258. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9259. * set 'max_dvc_qng' to 'max_host_qng'.
  9260. */
  9261. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9262. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9263. }
  9264. /*
  9265. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9266. * values based on possibly adjusted EEPROM values.
  9267. */
  9268. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9269. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9270. /*
  9271. * If the EEPROM 'termination' field is set to automatic (0), then set
  9272. * the ADV_DVC_CFG 'termination' field to automatic also.
  9273. *
  9274. * If the termination is specified with a non-zero 'termination'
  9275. * value check that a legal value is set and set the ADV_DVC_CFG
  9276. * 'termination' field appropriately.
  9277. */
  9278. if (eep_config.termination == 0) {
  9279. asc_dvc->cfg->termination = 0; /* auto termination */
  9280. } else {
  9281. /* Enable manual control with low off / high off. */
  9282. if (eep_config.termination == 1) {
  9283. asc_dvc->cfg->termination = TERM_CTL_SEL;
  9284. /* Enable manual control with low off / high on. */
  9285. } else if (eep_config.termination == 2) {
  9286. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  9287. /* Enable manual control with low on / high on. */
  9288. } else if (eep_config.termination == 3) {
  9289. asc_dvc->cfg->termination =
  9290. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  9291. } else {
  9292. /*
  9293. * The EEPROM 'termination' field contains a bad value. Use
  9294. * automatic termination instead.
  9295. */
  9296. asc_dvc->cfg->termination = 0;
  9297. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9298. }
  9299. }
  9300. return warn_code;
  9301. }
  9302. /*
  9303. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9304. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9305. * all of this is done.
  9306. *
  9307. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9308. *
  9309. * For a non-fatal error return a warning code. If there are no warnings
  9310. * then 0 is returned.
  9311. *
  9312. * Note: Chip is stopped on entry.
  9313. */
  9314. static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  9315. {
  9316. AdvPortAddr iop_base;
  9317. ushort warn_code;
  9318. ADVEEP_38C0800_CONFIG eep_config;
  9319. uchar tid, termination;
  9320. ushort sdtr_speed = 0;
  9321. iop_base = asc_dvc->iop_base;
  9322. warn_code = 0;
  9323. /*
  9324. * Read the board's EEPROM configuration.
  9325. *
  9326. * Set default values if a bad checksum is found.
  9327. */
  9328. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  9329. eep_config.check_sum) {
  9330. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9331. /*
  9332. * Set EEPROM default values.
  9333. */
  9334. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  9335. sizeof(ADVEEP_38C0800_CONFIG));
  9336. /*
  9337. * Assume the 6 byte board serial number that was read from
  9338. * EEPROM is correct even if the EEPROM checksum failed.
  9339. */
  9340. eep_config.serial_number_word3 =
  9341. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9342. eep_config.serial_number_word2 =
  9343. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9344. eep_config.serial_number_word1 =
  9345. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9346. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  9347. }
  9348. /*
  9349. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  9350. * EEPROM configuration that was read.
  9351. *
  9352. * This is the mapping of EEPROM fields to Adv Library fields.
  9353. */
  9354. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9355. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9356. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9357. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9358. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9359. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9360. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9361. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9362. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9363. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9364. asc_dvc->start_motor = eep_config.start_motor;
  9365. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9366. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9367. asc_dvc->no_scam = eep_config.scam_tolerant;
  9368. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9369. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9370. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9371. /*
  9372. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9373. * are set, then set an 'sdtr_able' bit for it.
  9374. */
  9375. asc_dvc->sdtr_able = 0;
  9376. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  9377. if (tid == 0) {
  9378. sdtr_speed = asc_dvc->sdtr_speed1;
  9379. } else if (tid == 4) {
  9380. sdtr_speed = asc_dvc->sdtr_speed2;
  9381. } else if (tid == 8) {
  9382. sdtr_speed = asc_dvc->sdtr_speed3;
  9383. } else if (tid == 12) {
  9384. sdtr_speed = asc_dvc->sdtr_speed4;
  9385. }
  9386. if (sdtr_speed & ADV_MAX_TID) {
  9387. asc_dvc->sdtr_able |= (1 << tid);
  9388. }
  9389. sdtr_speed >>= 4;
  9390. }
  9391. /*
  9392. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9393. * maximum queuing (max. 63, min. 4).
  9394. */
  9395. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9396. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9397. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9398. /* If the value is zero, assume it is uninitialized. */
  9399. if (eep_config.max_host_qng == 0) {
  9400. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9401. } else {
  9402. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9403. }
  9404. }
  9405. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9406. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9407. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9408. /* If the value is zero, assume it is uninitialized. */
  9409. if (eep_config.max_dvc_qng == 0) {
  9410. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9411. } else {
  9412. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9413. }
  9414. }
  9415. /*
  9416. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9417. * set 'max_dvc_qng' to 'max_host_qng'.
  9418. */
  9419. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9420. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9421. }
  9422. /*
  9423. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9424. * values based on possibly adjusted EEPROM values.
  9425. */
  9426. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9427. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9428. /*
  9429. * If the EEPROM 'termination' field is set to automatic (0), then set
  9430. * the ADV_DVC_CFG 'termination' field to automatic also.
  9431. *
  9432. * If the termination is specified with a non-zero 'termination'
  9433. * value check that a legal value is set and set the ADV_DVC_CFG
  9434. * 'termination' field appropriately.
  9435. */
  9436. if (eep_config.termination_se == 0) {
  9437. termination = 0; /* auto termination for SE */
  9438. } else {
  9439. /* Enable manual control with low off / high off. */
  9440. if (eep_config.termination_se == 1) {
  9441. termination = 0;
  9442. /* Enable manual control with low off / high on. */
  9443. } else if (eep_config.termination_se == 2) {
  9444. termination = TERM_SE_HI;
  9445. /* Enable manual control with low on / high on. */
  9446. } else if (eep_config.termination_se == 3) {
  9447. termination = TERM_SE;
  9448. } else {
  9449. /*
  9450. * The EEPROM 'termination_se' field contains a bad value.
  9451. * Use automatic termination instead.
  9452. */
  9453. termination = 0;
  9454. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9455. }
  9456. }
  9457. if (eep_config.termination_lvd == 0) {
  9458. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9459. } else {
  9460. /* Enable manual control with low off / high off. */
  9461. if (eep_config.termination_lvd == 1) {
  9462. asc_dvc->cfg->termination = termination;
  9463. /* Enable manual control with low off / high on. */
  9464. } else if (eep_config.termination_lvd == 2) {
  9465. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9466. /* Enable manual control with low on / high on. */
  9467. } else if (eep_config.termination_lvd == 3) {
  9468. asc_dvc->cfg->termination = termination | TERM_LVD;
  9469. } else {
  9470. /*
  9471. * The EEPROM 'termination_lvd' field contains a bad value.
  9472. * Use automatic termination instead.
  9473. */
  9474. asc_dvc->cfg->termination = termination;
  9475. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9476. }
  9477. }
  9478. return warn_code;
  9479. }
  9480. /*
  9481. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  9482. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9483. * all of this is done.
  9484. *
  9485. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  9486. *
  9487. * For a non-fatal error return a warning code. If there are no warnings
  9488. * then 0 is returned.
  9489. *
  9490. * Note: Chip is stopped on entry.
  9491. */
  9492. static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  9493. {
  9494. AdvPortAddr iop_base;
  9495. ushort warn_code;
  9496. ADVEEP_38C1600_CONFIG eep_config;
  9497. uchar tid, termination;
  9498. ushort sdtr_speed = 0;
  9499. iop_base = asc_dvc->iop_base;
  9500. warn_code = 0;
  9501. /*
  9502. * Read the board's EEPROM configuration.
  9503. *
  9504. * Set default values if a bad checksum is found.
  9505. */
  9506. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  9507. eep_config.check_sum) {
  9508. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  9509. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9510. /*
  9511. * Set EEPROM default values.
  9512. */
  9513. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  9514. sizeof(ADVEEP_38C1600_CONFIG));
  9515. if (PCI_FUNC(pdev->devfn) != 0) {
  9516. u8 ints;
  9517. /*
  9518. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  9519. * and old Mac system booting problem. The Expansion
  9520. * ROM must be disabled in Function 1 for these systems
  9521. */
  9522. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  9523. /*
  9524. * Clear the INTAB (bit 11) if the GPIO 0 input
  9525. * indicates the Function 1 interrupt line is wired
  9526. * to INTB.
  9527. *
  9528. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  9529. * 1 - Function 1 interrupt line wired to INT A.
  9530. * 0 - Function 1 interrupt line wired to INT B.
  9531. *
  9532. * Note: Function 0 is always wired to INTA.
  9533. * Put all 5 GPIO bits in input mode and then read
  9534. * their input values.
  9535. */
  9536. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  9537. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  9538. if ((ints & 0x01) == 0)
  9539. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  9540. }
  9541. /*
  9542. * Assume the 6 byte board serial number that was read from
  9543. * EEPROM is correct even if the EEPROM checksum failed.
  9544. */
  9545. eep_config.serial_number_word3 =
  9546. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9547. eep_config.serial_number_word2 =
  9548. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9549. eep_config.serial_number_word1 =
  9550. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9551. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  9552. }
  9553. /*
  9554. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9555. * EEPROM configuration that was read.
  9556. *
  9557. * This is the mapping of EEPROM fields to Adv Library fields.
  9558. */
  9559. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9560. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9561. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9562. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9563. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9564. asc_dvc->ppr_able = 0;
  9565. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9566. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9567. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9568. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9569. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  9570. asc_dvc->start_motor = eep_config.start_motor;
  9571. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9572. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9573. asc_dvc->no_scam = eep_config.scam_tolerant;
  9574. /*
  9575. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9576. * are set, then set an 'sdtr_able' bit for it.
  9577. */
  9578. asc_dvc->sdtr_able = 0;
  9579. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  9580. if (tid == 0) {
  9581. sdtr_speed = asc_dvc->sdtr_speed1;
  9582. } else if (tid == 4) {
  9583. sdtr_speed = asc_dvc->sdtr_speed2;
  9584. } else if (tid == 8) {
  9585. sdtr_speed = asc_dvc->sdtr_speed3;
  9586. } else if (tid == 12) {
  9587. sdtr_speed = asc_dvc->sdtr_speed4;
  9588. }
  9589. if (sdtr_speed & ASC_MAX_TID) {
  9590. asc_dvc->sdtr_able |= (1 << tid);
  9591. }
  9592. sdtr_speed >>= 4;
  9593. }
  9594. /*
  9595. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9596. * maximum queuing (max. 63, min. 4).
  9597. */
  9598. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9599. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9600. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9601. /* If the value is zero, assume it is uninitialized. */
  9602. if (eep_config.max_host_qng == 0) {
  9603. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9604. } else {
  9605. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9606. }
  9607. }
  9608. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9609. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9610. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9611. /* If the value is zero, assume it is uninitialized. */
  9612. if (eep_config.max_dvc_qng == 0) {
  9613. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9614. } else {
  9615. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9616. }
  9617. }
  9618. /*
  9619. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9620. * set 'max_dvc_qng' to 'max_host_qng'.
  9621. */
  9622. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9623. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9624. }
  9625. /*
  9626. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  9627. * values based on possibly adjusted EEPROM values.
  9628. */
  9629. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9630. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9631. /*
  9632. * If the EEPROM 'termination' field is set to automatic (0), then set
  9633. * the ASC_DVC_CFG 'termination' field to automatic also.
  9634. *
  9635. * If the termination is specified with a non-zero 'termination'
  9636. * value check that a legal value is set and set the ASC_DVC_CFG
  9637. * 'termination' field appropriately.
  9638. */
  9639. if (eep_config.termination_se == 0) {
  9640. termination = 0; /* auto termination for SE */
  9641. } else {
  9642. /* Enable manual control with low off / high off. */
  9643. if (eep_config.termination_se == 1) {
  9644. termination = 0;
  9645. /* Enable manual control with low off / high on. */
  9646. } else if (eep_config.termination_se == 2) {
  9647. termination = TERM_SE_HI;
  9648. /* Enable manual control with low on / high on. */
  9649. } else if (eep_config.termination_se == 3) {
  9650. termination = TERM_SE;
  9651. } else {
  9652. /*
  9653. * The EEPROM 'termination_se' field contains a bad value.
  9654. * Use automatic termination instead.
  9655. */
  9656. termination = 0;
  9657. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9658. }
  9659. }
  9660. if (eep_config.termination_lvd == 0) {
  9661. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9662. } else {
  9663. /* Enable manual control with low off / high off. */
  9664. if (eep_config.termination_lvd == 1) {
  9665. asc_dvc->cfg->termination = termination;
  9666. /* Enable manual control with low off / high on. */
  9667. } else if (eep_config.termination_lvd == 2) {
  9668. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9669. /* Enable manual control with low on / high on. */
  9670. } else if (eep_config.termination_lvd == 3) {
  9671. asc_dvc->cfg->termination = termination | TERM_LVD;
  9672. } else {
  9673. /*
  9674. * The EEPROM 'termination_lvd' field contains a bad value.
  9675. * Use automatic termination instead.
  9676. */
  9677. asc_dvc->cfg->termination = termination;
  9678. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9679. }
  9680. }
  9681. return warn_code;
  9682. }
  9683. /*
  9684. * Initialize the ADV_DVC_VAR structure.
  9685. *
  9686. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9687. *
  9688. * For a non-fatal error return a warning code. If there are no warnings
  9689. * then 0 is returned.
  9690. */
  9691. static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  9692. {
  9693. struct asc_board *board = shost_priv(shost);
  9694. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  9695. unsigned short warn_code = 0;
  9696. AdvPortAddr iop_base = asc_dvc->iop_base;
  9697. u16 cmd;
  9698. int status;
  9699. asc_dvc->err_code = 0;
  9700. /*
  9701. * Save the state of the PCI Configuration Command Register
  9702. * "Parity Error Response Control" Bit. If the bit is clear (0),
  9703. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  9704. * DMA parity errors.
  9705. */
  9706. asc_dvc->cfg->control_flag = 0;
  9707. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  9708. if ((cmd & PCI_COMMAND_PARITY) == 0)
  9709. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  9710. asc_dvc->cfg->chip_version =
  9711. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  9712. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  9713. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  9714. (ushort)ADV_CHIP_ID_BYTE);
  9715. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  9716. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  9717. (ushort)ADV_CHIP_ID_WORD);
  9718. /*
  9719. * Reset the chip to start and allow register writes.
  9720. */
  9721. if (AdvFindSignature(iop_base) == 0) {
  9722. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9723. return ADV_ERROR;
  9724. } else {
  9725. /*
  9726. * The caller must set 'chip_type' to a valid setting.
  9727. */
  9728. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  9729. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  9730. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  9731. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  9732. return ADV_ERROR;
  9733. }
  9734. /*
  9735. * Reset Chip.
  9736. */
  9737. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  9738. ADV_CTRL_REG_CMD_RESET);
  9739. mdelay(100);
  9740. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  9741. ADV_CTRL_REG_CMD_WR_IO_REG);
  9742. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  9743. status = AdvInitFrom38C1600EEP(asc_dvc);
  9744. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  9745. status = AdvInitFrom38C0800EEP(asc_dvc);
  9746. } else {
  9747. status = AdvInitFrom3550EEP(asc_dvc);
  9748. }
  9749. warn_code |= status;
  9750. }
  9751. if (warn_code != 0)
  9752. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  9753. if (asc_dvc->err_code)
  9754. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  9755. asc_dvc->err_code);
  9756. return asc_dvc->err_code;
  9757. }
  9758. #endif
  9759. static struct scsi_host_template advansys_template = {
  9760. .proc_name = DRV_NAME,
  9761. #ifdef CONFIG_PROC_FS
  9762. .show_info = advansys_show_info,
  9763. #endif
  9764. .name = DRV_NAME,
  9765. .info = advansys_info,
  9766. .queuecommand = advansys_queuecommand,
  9767. .eh_host_reset_handler = advansys_reset,
  9768. .bios_param = advansys_biosparam,
  9769. .slave_configure = advansys_slave_configure,
  9770. /*
  9771. * Because the driver may control an ISA adapter 'unchecked_isa_dma'
  9772. * must be set. The flag will be cleared in advansys_board_found
  9773. * for non-ISA adapters.
  9774. */
  9775. .unchecked_isa_dma = true,
  9776. /*
  9777. * All adapters controlled by this driver are capable of large
  9778. * scatter-gather lists. According to the mid-level SCSI documentation
  9779. * this obviates any performance gain provided by setting
  9780. * 'use_clustering'. But empirically while CPU utilization is increased
  9781. * by enabling clustering, I/O throughput increases as well.
  9782. */
  9783. .use_clustering = ENABLE_CLUSTERING,
  9784. };
  9785. static int advansys_wide_init_chip(struct Scsi_Host *shost)
  9786. {
  9787. struct asc_board *board = shost_priv(shost);
  9788. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  9789. size_t sgblk_pool_size;
  9790. int warn_code, err_code;
  9791. /*
  9792. * Allocate buffer carrier structures. The total size
  9793. * is about 8 KB, so allocate all at once.
  9794. */
  9795. adv_dvc->carrier = dma_alloc_coherent(board->dev,
  9796. ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL);
  9797. ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier);
  9798. if (!adv_dvc->carrier)
  9799. goto kmalloc_failed;
  9800. /*
  9801. * Allocate up to 'max_host_qng' request structures for the Wide
  9802. * board. The total size is about 16 KB, so allocate all at once.
  9803. * If the allocation fails decrement and try again.
  9804. */
  9805. board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t);
  9806. if (board->adv_reqp_size & 0x1f) {
  9807. ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t));
  9808. board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size);
  9809. }
  9810. board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size,
  9811. &board->adv_reqp_addr, GFP_KERNEL);
  9812. if (!board->adv_reqp)
  9813. goto kmalloc_failed;
  9814. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp,
  9815. adv_dvc->max_host_qng, board->adv_reqp_size);
  9816. /*
  9817. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  9818. * the Wide board. Each structure is about 136 bytes.
  9819. */
  9820. sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK;
  9821. board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev,
  9822. sgblk_pool_size, 32, 0);
  9823. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK,
  9824. sizeof(adv_sgblk_t), sgblk_pool_size);
  9825. if (!board->adv_sgblk_pool)
  9826. goto kmalloc_failed;
  9827. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  9828. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  9829. warn_code = AdvInitAsc3550Driver(adv_dvc);
  9830. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  9831. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  9832. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  9833. } else {
  9834. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  9835. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  9836. }
  9837. err_code = adv_dvc->err_code;
  9838. if (warn_code || err_code) {
  9839. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  9840. "0x%x\n", warn_code, err_code);
  9841. }
  9842. goto exit;
  9843. kmalloc_failed:
  9844. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  9845. err_code = ADV_ERROR;
  9846. exit:
  9847. return err_code;
  9848. }
  9849. static void advansys_wide_free_mem(struct asc_board *board)
  9850. {
  9851. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  9852. if (adv_dvc->carrier) {
  9853. dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE,
  9854. adv_dvc->carrier, adv_dvc->carrier_addr);
  9855. adv_dvc->carrier = NULL;
  9856. }
  9857. if (board->adv_reqp) {
  9858. dma_free_coherent(board->dev, board->adv_reqp_size,
  9859. board->adv_reqp, board->adv_reqp_addr);
  9860. board->adv_reqp = NULL;
  9861. }
  9862. if (board->adv_sgblk_pool) {
  9863. dma_pool_destroy(board->adv_sgblk_pool);
  9864. board->adv_sgblk_pool = NULL;
  9865. }
  9866. }
  9867. static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
  9868. int bus_type)
  9869. {
  9870. struct pci_dev *pdev;
  9871. struct asc_board *boardp = shost_priv(shost);
  9872. ASC_DVC_VAR *asc_dvc_varp = NULL;
  9873. ADV_DVC_VAR *adv_dvc_varp = NULL;
  9874. int share_irq, warn_code, ret;
  9875. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  9876. if (ASC_NARROW_BOARD(boardp)) {
  9877. ASC_DBG(1, "narrow board\n");
  9878. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  9879. asc_dvc_varp->bus_type = bus_type;
  9880. asc_dvc_varp->drv_ptr = boardp;
  9881. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  9882. asc_dvc_varp->iop_base = iop;
  9883. } else {
  9884. #ifdef CONFIG_PCI
  9885. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  9886. adv_dvc_varp->drv_ptr = boardp;
  9887. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  9888. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  9889. ASC_DBG(1, "wide board ASC-3550\n");
  9890. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  9891. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  9892. ASC_DBG(1, "wide board ASC-38C0800\n");
  9893. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  9894. } else {
  9895. ASC_DBG(1, "wide board ASC-38C1600\n");
  9896. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  9897. }
  9898. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  9899. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  9900. if (!boardp->ioremap_addr) {
  9901. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  9902. "returned NULL\n",
  9903. (long)pci_resource_start(pdev, 1),
  9904. boardp->asc_n_io_port);
  9905. ret = -ENODEV;
  9906. goto err_shost;
  9907. }
  9908. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  9909. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  9910. /*
  9911. * Even though it isn't used to access wide boards, other
  9912. * than for the debug line below, save I/O Port address so
  9913. * that it can be reported.
  9914. */
  9915. boardp->ioport = iop;
  9916. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  9917. (ushort)inp(iop + 1), (ushort)inpw(iop));
  9918. #endif /* CONFIG_PCI */
  9919. }
  9920. if (ASC_NARROW_BOARD(boardp)) {
  9921. /*
  9922. * Set the board bus type and PCI IRQ before
  9923. * calling AscInitGetConfig().
  9924. */
  9925. switch (asc_dvc_varp->bus_type) {
  9926. #ifdef CONFIG_ISA
  9927. case ASC_IS_ISA:
  9928. shost->unchecked_isa_dma = true;
  9929. share_irq = 0;
  9930. break;
  9931. case ASC_IS_VL:
  9932. shost->unchecked_isa_dma = false;
  9933. share_irq = 0;
  9934. break;
  9935. case ASC_IS_EISA:
  9936. shost->unchecked_isa_dma = false;
  9937. share_irq = IRQF_SHARED;
  9938. break;
  9939. #endif /* CONFIG_ISA */
  9940. #ifdef CONFIG_PCI
  9941. case ASC_IS_PCI:
  9942. shost->unchecked_isa_dma = false;
  9943. share_irq = IRQF_SHARED;
  9944. break;
  9945. #endif /* CONFIG_PCI */
  9946. default:
  9947. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  9948. "%d\n", asc_dvc_varp->bus_type);
  9949. shost->unchecked_isa_dma = false;
  9950. share_irq = 0;
  9951. break;
  9952. }
  9953. /*
  9954. * NOTE: AscInitGetConfig() may change the board's
  9955. * bus_type value. The bus_type value should no
  9956. * longer be used. If the bus_type field must be
  9957. * referenced only use the bit-wise AND operator "&".
  9958. */
  9959. ASC_DBG(2, "AscInitGetConfig()\n");
  9960. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  9961. } else {
  9962. #ifdef CONFIG_PCI
  9963. /*
  9964. * For Wide boards set PCI information before calling
  9965. * AdvInitGetConfig().
  9966. */
  9967. shost->unchecked_isa_dma = false;
  9968. share_irq = IRQF_SHARED;
  9969. ASC_DBG(2, "AdvInitGetConfig()\n");
  9970. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  9971. #else
  9972. share_irq = 0;
  9973. ret = -ENODEV;
  9974. #endif /* CONFIG_PCI */
  9975. }
  9976. if (ret)
  9977. goto err_unmap;
  9978. /*
  9979. * Save the EEPROM configuration so that it can be displayed
  9980. * from /proc/scsi/advansys/[0...].
  9981. */
  9982. if (ASC_NARROW_BOARD(boardp)) {
  9983. ASCEEP_CONFIG *ep;
  9984. /*
  9985. * Set the adapter's target id bit in the 'init_tidmask' field.
  9986. */
  9987. boardp->init_tidmask |=
  9988. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  9989. /*
  9990. * Save EEPROM settings for the board.
  9991. */
  9992. ep = &boardp->eep_config.asc_eep;
  9993. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  9994. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  9995. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  9996. ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
  9997. ep->start_motor = asc_dvc_varp->start_motor;
  9998. ep->cntl = asc_dvc_varp->dvc_cntl;
  9999. ep->no_scam = asc_dvc_varp->no_scam;
  10000. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  10001. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  10002. /* 'max_tag_qng' is set to the same value for every device. */
  10003. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  10004. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  10005. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  10006. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  10007. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  10008. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  10009. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  10010. /*
  10011. * Modify board configuration.
  10012. */
  10013. ASC_DBG(2, "AscInitSetConfig()\n");
  10014. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  10015. if (ret)
  10016. goto err_unmap;
  10017. } else {
  10018. ADVEEP_3550_CONFIG *ep_3550;
  10019. ADVEEP_38C0800_CONFIG *ep_38C0800;
  10020. ADVEEP_38C1600_CONFIG *ep_38C1600;
  10021. /*
  10022. * Save Wide EEP Configuration Information.
  10023. */
  10024. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  10025. ep_3550 = &boardp->eep_config.adv_3550_eep;
  10026. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  10027. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  10028. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10029. ep_3550->termination = adv_dvc_varp->cfg->termination;
  10030. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  10031. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10032. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  10033. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  10034. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  10035. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  10036. ep_3550->start_motor = adv_dvc_varp->start_motor;
  10037. ep_3550->scsi_reset_delay =
  10038. adv_dvc_varp->scsi_reset_wait;
  10039. ep_3550->serial_number_word1 =
  10040. adv_dvc_varp->cfg->serial1;
  10041. ep_3550->serial_number_word2 =
  10042. adv_dvc_varp->cfg->serial2;
  10043. ep_3550->serial_number_word3 =
  10044. adv_dvc_varp->cfg->serial3;
  10045. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  10046. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  10047. ep_38C0800->adapter_scsi_id =
  10048. adv_dvc_varp->chip_scsi_id;
  10049. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  10050. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10051. ep_38C0800->termination_lvd =
  10052. adv_dvc_varp->cfg->termination;
  10053. ep_38C0800->disc_enable =
  10054. adv_dvc_varp->cfg->disc_enable;
  10055. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10056. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  10057. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10058. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10059. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10060. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10061. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10062. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10063. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  10064. ep_38C0800->scsi_reset_delay =
  10065. adv_dvc_varp->scsi_reset_wait;
  10066. ep_38C0800->serial_number_word1 =
  10067. adv_dvc_varp->cfg->serial1;
  10068. ep_38C0800->serial_number_word2 =
  10069. adv_dvc_varp->cfg->serial2;
  10070. ep_38C0800->serial_number_word3 =
  10071. adv_dvc_varp->cfg->serial3;
  10072. } else {
  10073. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  10074. ep_38C1600->adapter_scsi_id =
  10075. adv_dvc_varp->chip_scsi_id;
  10076. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  10077. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10078. ep_38C1600->termination_lvd =
  10079. adv_dvc_varp->cfg->termination;
  10080. ep_38C1600->disc_enable =
  10081. adv_dvc_varp->cfg->disc_enable;
  10082. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10083. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  10084. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10085. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10086. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10087. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10088. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10089. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10090. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  10091. ep_38C1600->scsi_reset_delay =
  10092. adv_dvc_varp->scsi_reset_wait;
  10093. ep_38C1600->serial_number_word1 =
  10094. adv_dvc_varp->cfg->serial1;
  10095. ep_38C1600->serial_number_word2 =
  10096. adv_dvc_varp->cfg->serial2;
  10097. ep_38C1600->serial_number_word3 =
  10098. adv_dvc_varp->cfg->serial3;
  10099. }
  10100. /*
  10101. * Set the adapter's target id bit in the 'init_tidmask' field.
  10102. */
  10103. boardp->init_tidmask |=
  10104. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  10105. }
  10106. /*
  10107. * Channels are numbered beginning with 0. For AdvanSys one host
  10108. * structure supports one channel. Multi-channel boards have a
  10109. * separate host structure for each channel.
  10110. */
  10111. shost->max_channel = 0;
  10112. if (ASC_NARROW_BOARD(boardp)) {
  10113. shost->max_id = ASC_MAX_TID + 1;
  10114. shost->max_lun = ASC_MAX_LUN + 1;
  10115. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  10116. shost->io_port = asc_dvc_varp->iop_base;
  10117. boardp->asc_n_io_port = ASC_IOADR_GAP;
  10118. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  10119. /* Set maximum number of queues the adapter can handle. */
  10120. shost->can_queue = asc_dvc_varp->max_total_qng;
  10121. } else {
  10122. shost->max_id = ADV_MAX_TID + 1;
  10123. shost->max_lun = ADV_MAX_LUN + 1;
  10124. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  10125. /*
  10126. * Save the I/O Port address and length even though
  10127. * I/O ports are not used to access Wide boards.
  10128. * Instead the Wide boards are accessed with
  10129. * PCI Memory Mapped I/O.
  10130. */
  10131. shost->io_port = iop;
  10132. shost->this_id = adv_dvc_varp->chip_scsi_id;
  10133. /* Set maximum number of queues the adapter can handle. */
  10134. shost->can_queue = adv_dvc_varp->max_host_qng;
  10135. }
  10136. /*
  10137. * Set the maximum number of scatter-gather elements the
  10138. * adapter can handle.
  10139. */
  10140. if (ASC_NARROW_BOARD(boardp)) {
  10141. /*
  10142. * Allow two commands with 'sg_tablesize' scatter-gather
  10143. * elements to be executed simultaneously. This value is
  10144. * the theoretical hardware limit. It may be decreased
  10145. * below.
  10146. */
  10147. shost->sg_tablesize =
  10148. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  10149. ASC_SG_LIST_PER_Q) + 1;
  10150. } else {
  10151. shost->sg_tablesize = ADV_MAX_SG_LIST;
  10152. }
  10153. /*
  10154. * The value of 'sg_tablesize' can not exceed the SCSI
  10155. * mid-level driver definition of SG_ALL. SG_ALL also
  10156. * must not be exceeded, because it is used to define the
  10157. * size of the scatter-gather table in 'struct asc_sg_head'.
  10158. */
  10159. if (shost->sg_tablesize > SG_ALL) {
  10160. shost->sg_tablesize = SG_ALL;
  10161. }
  10162. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  10163. /* BIOS start address. */
  10164. if (ASC_NARROW_BOARD(boardp)) {
  10165. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  10166. asc_dvc_varp->bus_type);
  10167. } else {
  10168. /*
  10169. * Fill-in BIOS board variables. The Wide BIOS saves
  10170. * information in LRAM that is used by the driver.
  10171. */
  10172. AdvReadWordLram(adv_dvc_varp->iop_base,
  10173. BIOS_SIGNATURE, boardp->bios_signature);
  10174. AdvReadWordLram(adv_dvc_varp->iop_base,
  10175. BIOS_VERSION, boardp->bios_version);
  10176. AdvReadWordLram(adv_dvc_varp->iop_base,
  10177. BIOS_CODESEG, boardp->bios_codeseg);
  10178. AdvReadWordLram(adv_dvc_varp->iop_base,
  10179. BIOS_CODELEN, boardp->bios_codelen);
  10180. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  10181. boardp->bios_signature, boardp->bios_version);
  10182. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  10183. boardp->bios_codeseg, boardp->bios_codelen);
  10184. /*
  10185. * If the BIOS saved a valid signature, then fill in
  10186. * the BIOS code segment base address.
  10187. */
  10188. if (boardp->bios_signature == 0x55AA) {
  10189. /*
  10190. * Convert x86 realmode code segment to a linear
  10191. * address by shifting left 4.
  10192. */
  10193. shost->base = ((ulong)boardp->bios_codeseg << 4);
  10194. } else {
  10195. shost->base = 0;
  10196. }
  10197. }
  10198. /*
  10199. * Register Board Resources - I/O Port, DMA, IRQ
  10200. */
  10201. /* Register DMA Channel for Narrow boards. */
  10202. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  10203. #ifdef CONFIG_ISA
  10204. if (ASC_NARROW_BOARD(boardp)) {
  10205. /* Register DMA channel for ISA bus. */
  10206. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  10207. shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
  10208. ret = request_dma(shost->dma_channel, DRV_NAME);
  10209. if (ret) {
  10210. shost_printk(KERN_ERR, shost, "request_dma() "
  10211. "%d failed %d\n",
  10212. shost->dma_channel, ret);
  10213. goto err_unmap;
  10214. }
  10215. AscEnableIsaDma(shost->dma_channel);
  10216. }
  10217. }
  10218. #endif /* CONFIG_ISA */
  10219. /* Register IRQ Number. */
  10220. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  10221. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  10222. DRV_NAME, shost);
  10223. if (ret) {
  10224. if (ret == -EBUSY) {
  10225. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10226. "already in use\n", boardp->irq);
  10227. } else if (ret == -EINVAL) {
  10228. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10229. "not valid\n", boardp->irq);
  10230. } else {
  10231. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10232. "failed with %d\n", boardp->irq, ret);
  10233. }
  10234. goto err_free_dma;
  10235. }
  10236. /*
  10237. * Initialize board RISC chip and enable interrupts.
  10238. */
  10239. if (ASC_NARROW_BOARD(boardp)) {
  10240. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  10241. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  10242. if (!asc_dvc_varp->overrun_buf) {
  10243. ret = -ENOMEM;
  10244. goto err_free_irq;
  10245. }
  10246. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  10247. if (warn_code || asc_dvc_varp->err_code) {
  10248. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  10249. "warn 0x%x, error 0x%x\n",
  10250. asc_dvc_varp->init_state, warn_code,
  10251. asc_dvc_varp->err_code);
  10252. if (!asc_dvc_varp->overrun_dma) {
  10253. ret = -ENODEV;
  10254. goto err_free_mem;
  10255. }
  10256. }
  10257. } else {
  10258. if (advansys_wide_init_chip(shost)) {
  10259. ret = -ENODEV;
  10260. goto err_free_mem;
  10261. }
  10262. }
  10263. ASC_DBG_PRT_SCSI_HOST(2, shost);
  10264. ret = scsi_add_host(shost, boardp->dev);
  10265. if (ret)
  10266. goto err_free_mem;
  10267. scsi_scan_host(shost);
  10268. return 0;
  10269. err_free_mem:
  10270. if (ASC_NARROW_BOARD(boardp)) {
  10271. if (asc_dvc_varp->overrun_dma)
  10272. dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
  10273. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10274. kfree(asc_dvc_varp->overrun_buf);
  10275. } else
  10276. advansys_wide_free_mem(boardp);
  10277. err_free_irq:
  10278. free_irq(boardp->irq, shost);
  10279. err_free_dma:
  10280. #ifdef CONFIG_ISA
  10281. if (shost->dma_channel != NO_ISA_DMA)
  10282. free_dma(shost->dma_channel);
  10283. #endif
  10284. err_unmap:
  10285. if (boardp->ioremap_addr)
  10286. iounmap(boardp->ioremap_addr);
  10287. #ifdef CONFIG_PCI
  10288. err_shost:
  10289. #endif
  10290. return ret;
  10291. }
  10292. /*
  10293. * advansys_release()
  10294. *
  10295. * Release resources allocated for a single AdvanSys adapter.
  10296. */
  10297. static int advansys_release(struct Scsi_Host *shost)
  10298. {
  10299. struct asc_board *board = shost_priv(shost);
  10300. ASC_DBG(1, "begin\n");
  10301. scsi_remove_host(shost);
  10302. free_irq(board->irq, shost);
  10303. #ifdef CONFIG_ISA
  10304. if (shost->dma_channel != NO_ISA_DMA) {
  10305. ASC_DBG(1, "free_dma()\n");
  10306. free_dma(shost->dma_channel);
  10307. }
  10308. #endif
  10309. if (ASC_NARROW_BOARD(board)) {
  10310. dma_unmap_single(board->dev,
  10311. board->dvc_var.asc_dvc_var.overrun_dma,
  10312. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10313. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  10314. } else {
  10315. iounmap(board->ioremap_addr);
  10316. advansys_wide_free_mem(board);
  10317. }
  10318. scsi_host_put(shost);
  10319. ASC_DBG(1, "end\n");
  10320. return 0;
  10321. }
  10322. #define ASC_IOADR_TABLE_MAX_IX 11
  10323. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  10324. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  10325. 0x0210, 0x0230, 0x0250, 0x0330
  10326. };
  10327. /*
  10328. * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
  10329. * 00: 10
  10330. * 01: 11
  10331. * 10: 12
  10332. * 11: 15
  10333. */
  10334. static unsigned int advansys_isa_irq_no(PortAddr iop_base)
  10335. {
  10336. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10337. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
  10338. if (chip_irq == 13)
  10339. chip_irq = 15;
  10340. return chip_irq;
  10341. }
  10342. static int advansys_isa_probe(struct device *dev, unsigned int id)
  10343. {
  10344. int err = -ENODEV;
  10345. PortAddr iop_base = _asc_def_iop_base[id];
  10346. struct Scsi_Host *shost;
  10347. struct asc_board *board;
  10348. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10349. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10350. return -ENODEV;
  10351. }
  10352. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10353. if (!AscFindSignature(iop_base))
  10354. goto release_region;
  10355. if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
  10356. goto release_region;
  10357. err = -ENOMEM;
  10358. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10359. if (!shost)
  10360. goto release_region;
  10361. board = shost_priv(shost);
  10362. board->irq = advansys_isa_irq_no(iop_base);
  10363. board->dev = dev;
  10364. board->shost = shost;
  10365. err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
  10366. if (err)
  10367. goto free_host;
  10368. dev_set_drvdata(dev, shost);
  10369. return 0;
  10370. free_host:
  10371. scsi_host_put(shost);
  10372. release_region:
  10373. release_region(iop_base, ASC_IOADR_GAP);
  10374. return err;
  10375. }
  10376. static int advansys_isa_remove(struct device *dev, unsigned int id)
  10377. {
  10378. int ioport = _asc_def_iop_base[id];
  10379. advansys_release(dev_get_drvdata(dev));
  10380. release_region(ioport, ASC_IOADR_GAP);
  10381. return 0;
  10382. }
  10383. static struct isa_driver advansys_isa_driver = {
  10384. .probe = advansys_isa_probe,
  10385. .remove = advansys_isa_remove,
  10386. .driver = {
  10387. .owner = THIS_MODULE,
  10388. .name = DRV_NAME,
  10389. },
  10390. };
  10391. /*
  10392. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  10393. * 000: invalid
  10394. * 001: 10
  10395. * 010: 11
  10396. * 011: 12
  10397. * 100: invalid
  10398. * 101: 14
  10399. * 110: 15
  10400. * 111: invalid
  10401. */
  10402. static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
  10403. {
  10404. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10405. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  10406. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  10407. return 0;
  10408. return chip_irq;
  10409. }
  10410. static int advansys_vlb_probe(struct device *dev, unsigned int id)
  10411. {
  10412. int err = -ENODEV;
  10413. PortAddr iop_base = _asc_def_iop_base[id];
  10414. struct Scsi_Host *shost;
  10415. struct asc_board *board;
  10416. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10417. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10418. return -ENODEV;
  10419. }
  10420. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10421. if (!AscFindSignature(iop_base))
  10422. goto release_region;
  10423. /*
  10424. * I don't think this condition can actually happen, but the old
  10425. * driver did it, and the chances of finding a VLB setup in 2007
  10426. * to do testing with is slight to none.
  10427. */
  10428. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  10429. goto release_region;
  10430. err = -ENOMEM;
  10431. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10432. if (!shost)
  10433. goto release_region;
  10434. board = shost_priv(shost);
  10435. board->irq = advansys_vlb_irq_no(iop_base);
  10436. board->dev = dev;
  10437. board->shost = shost;
  10438. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  10439. if (err)
  10440. goto free_host;
  10441. dev_set_drvdata(dev, shost);
  10442. return 0;
  10443. free_host:
  10444. scsi_host_put(shost);
  10445. release_region:
  10446. release_region(iop_base, ASC_IOADR_GAP);
  10447. return -ENODEV;
  10448. }
  10449. static struct isa_driver advansys_vlb_driver = {
  10450. .probe = advansys_vlb_probe,
  10451. .remove = advansys_isa_remove,
  10452. .driver = {
  10453. .owner = THIS_MODULE,
  10454. .name = "advansys_vlb",
  10455. },
  10456. };
  10457. static struct eisa_device_id advansys_eisa_table[] = {
  10458. { "ABP7401" },
  10459. { "ABP7501" },
  10460. { "" }
  10461. };
  10462. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  10463. /*
  10464. * EISA is a little more tricky than PCI; each EISA device may have two
  10465. * channels, and this driver is written to make each channel its own Scsi_Host
  10466. */
  10467. struct eisa_scsi_data {
  10468. struct Scsi_Host *host[2];
  10469. };
  10470. /*
  10471. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  10472. * 000: 10
  10473. * 001: 11
  10474. * 010: 12
  10475. * 011: invalid
  10476. * 100: 14
  10477. * 101: 15
  10478. * 110: invalid
  10479. * 111: invalid
  10480. */
  10481. static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
  10482. {
  10483. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  10484. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  10485. if ((chip_irq == 13) || (chip_irq > 15))
  10486. return 0;
  10487. return chip_irq;
  10488. }
  10489. static int advansys_eisa_probe(struct device *dev)
  10490. {
  10491. int i, ioport, irq = 0;
  10492. int err;
  10493. struct eisa_device *edev = to_eisa_device(dev);
  10494. struct eisa_scsi_data *data;
  10495. err = -ENOMEM;
  10496. data = kzalloc(sizeof(*data), GFP_KERNEL);
  10497. if (!data)
  10498. goto fail;
  10499. ioport = edev->base_addr + 0xc30;
  10500. err = -ENODEV;
  10501. for (i = 0; i < 2; i++, ioport += 0x20) {
  10502. struct asc_board *board;
  10503. struct Scsi_Host *shost;
  10504. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  10505. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  10506. ioport + ASC_IOADR_GAP - 1);
  10507. continue;
  10508. }
  10509. if (!AscFindSignature(ioport)) {
  10510. release_region(ioport, ASC_IOADR_GAP);
  10511. continue;
  10512. }
  10513. /*
  10514. * I don't know why we need to do this for EISA chips, but
  10515. * not for any others. It looks to be equivalent to
  10516. * AscGetChipCfgMsw, but I may have overlooked something,
  10517. * so I'm not converting it until I get an EISA board to
  10518. * test with.
  10519. */
  10520. inw(ioport + 4);
  10521. if (!irq)
  10522. irq = advansys_eisa_irq_no(edev);
  10523. err = -ENOMEM;
  10524. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10525. if (!shost)
  10526. goto release_region;
  10527. board = shost_priv(shost);
  10528. board->irq = irq;
  10529. board->dev = dev;
  10530. board->shost = shost;
  10531. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  10532. if (!err) {
  10533. data->host[i] = shost;
  10534. continue;
  10535. }
  10536. scsi_host_put(shost);
  10537. release_region:
  10538. release_region(ioport, ASC_IOADR_GAP);
  10539. break;
  10540. }
  10541. if (err)
  10542. goto free_data;
  10543. dev_set_drvdata(dev, data);
  10544. return 0;
  10545. free_data:
  10546. kfree(data->host[0]);
  10547. kfree(data->host[1]);
  10548. kfree(data);
  10549. fail:
  10550. return err;
  10551. }
  10552. static int advansys_eisa_remove(struct device *dev)
  10553. {
  10554. int i;
  10555. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  10556. for (i = 0; i < 2; i++) {
  10557. int ioport;
  10558. struct Scsi_Host *shost = data->host[i];
  10559. if (!shost)
  10560. continue;
  10561. ioport = shost->io_port;
  10562. advansys_release(shost);
  10563. release_region(ioport, ASC_IOADR_GAP);
  10564. }
  10565. kfree(data);
  10566. return 0;
  10567. }
  10568. static struct eisa_driver advansys_eisa_driver = {
  10569. .id_table = advansys_eisa_table,
  10570. .driver = {
  10571. .name = DRV_NAME,
  10572. .probe = advansys_eisa_probe,
  10573. .remove = advansys_eisa_remove,
  10574. }
  10575. };
  10576. /* PCI Devices supported by this driver */
  10577. static struct pci_device_id advansys_pci_tbl[] = {
  10578. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  10579. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10580. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  10581. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10582. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  10583. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10584. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  10585. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10586. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  10587. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10588. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  10589. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10590. {}
  10591. };
  10592. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  10593. static void advansys_set_latency(struct pci_dev *pdev)
  10594. {
  10595. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  10596. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  10597. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  10598. } else {
  10599. u8 latency;
  10600. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  10601. if (latency < 0x20)
  10602. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  10603. }
  10604. }
  10605. static int advansys_pci_probe(struct pci_dev *pdev,
  10606. const struct pci_device_id *ent)
  10607. {
  10608. int err, ioport;
  10609. struct Scsi_Host *shost;
  10610. struct asc_board *board;
  10611. err = pci_enable_device(pdev);
  10612. if (err)
  10613. goto fail;
  10614. err = pci_request_regions(pdev, DRV_NAME);
  10615. if (err)
  10616. goto disable_device;
  10617. pci_set_master(pdev);
  10618. advansys_set_latency(pdev);
  10619. err = -ENODEV;
  10620. if (pci_resource_len(pdev, 0) == 0)
  10621. goto release_region;
  10622. ioport = pci_resource_start(pdev, 0);
  10623. err = -ENOMEM;
  10624. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10625. if (!shost)
  10626. goto release_region;
  10627. board = shost_priv(shost);
  10628. board->irq = pdev->irq;
  10629. board->dev = &pdev->dev;
  10630. board->shost = shost;
  10631. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  10632. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  10633. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  10634. board->flags |= ASC_IS_WIDE_BOARD;
  10635. }
  10636. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  10637. if (err)
  10638. goto free_host;
  10639. pci_set_drvdata(pdev, shost);
  10640. return 0;
  10641. free_host:
  10642. scsi_host_put(shost);
  10643. release_region:
  10644. pci_release_regions(pdev);
  10645. disable_device:
  10646. pci_disable_device(pdev);
  10647. fail:
  10648. return err;
  10649. }
  10650. static void advansys_pci_remove(struct pci_dev *pdev)
  10651. {
  10652. advansys_release(pci_get_drvdata(pdev));
  10653. pci_release_regions(pdev);
  10654. pci_disable_device(pdev);
  10655. }
  10656. static struct pci_driver advansys_pci_driver = {
  10657. .name = DRV_NAME,
  10658. .id_table = advansys_pci_tbl,
  10659. .probe = advansys_pci_probe,
  10660. .remove = advansys_pci_remove,
  10661. };
  10662. static int __init advansys_init(void)
  10663. {
  10664. int error;
  10665. error = isa_register_driver(&advansys_isa_driver,
  10666. ASC_IOADR_TABLE_MAX_IX);
  10667. if (error)
  10668. goto fail;
  10669. error = isa_register_driver(&advansys_vlb_driver,
  10670. ASC_IOADR_TABLE_MAX_IX);
  10671. if (error)
  10672. goto unregister_isa;
  10673. error = eisa_driver_register(&advansys_eisa_driver);
  10674. if (error)
  10675. goto unregister_vlb;
  10676. error = pci_register_driver(&advansys_pci_driver);
  10677. if (error)
  10678. goto unregister_eisa;
  10679. return 0;
  10680. unregister_eisa:
  10681. eisa_driver_unregister(&advansys_eisa_driver);
  10682. unregister_vlb:
  10683. isa_unregister_driver(&advansys_vlb_driver);
  10684. unregister_isa:
  10685. isa_unregister_driver(&advansys_isa_driver);
  10686. fail:
  10687. return error;
  10688. }
  10689. static void __exit advansys_exit(void)
  10690. {
  10691. pci_unregister_driver(&advansys_pci_driver);
  10692. eisa_driver_unregister(&advansys_eisa_driver);
  10693. isa_unregister_driver(&advansys_vlb_driver);
  10694. isa_unregister_driver(&advansys_isa_driver);
  10695. }
  10696. module_init(advansys_init);
  10697. module_exit(advansys_exit);
  10698. MODULE_LICENSE("GPL");
  10699. MODULE_FIRMWARE("advansys/mcode.bin");
  10700. MODULE_FIRMWARE("advansys/3550.bin");
  10701. MODULE_FIRMWARE("advansys/38C0800.bin");
  10702. MODULE_FIRMWARE("advansys/38C1600.bin");