advansys.c 374 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826
  1. #define DRV_NAME "advansys"
  2. #define ASC_VERSION "3.4" /* AdvanSys Driver Version */
  3. /*
  4. * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
  5. *
  6. * Copyright (c) 1995-2000 Advanced System Products, Inc.
  7. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
  8. * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
  9. * All Rights Reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. /*
  17. * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
  18. * changed its name to ConnectCom Solutions, Inc.
  19. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
  20. */
  21. #include <linux/module.h>
  22. #include <linux/string.h>
  23. #include <linux/kernel.h>
  24. #include <linux/types.h>
  25. #include <linux/ioport.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/mm.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/init.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/isa.h>
  34. #include <linux/eisa.h>
  35. #include <linux/pci.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/firmware.h>
  39. #include <asm/io.h>
  40. #include <asm/system.h>
  41. #include <asm/dma.h>
  42. #include <scsi/scsi_cmnd.h>
  43. #include <scsi/scsi_device.h>
  44. #include <scsi/scsi_tcq.h>
  45. #include <scsi/scsi.h>
  46. #include <scsi/scsi_host.h>
  47. /* FIXME:
  48. *
  49. * 1. Although all of the necessary command mapping places have the
  50. * appropriate dma_map.. APIs, the driver still processes its internal
  51. * queue using bus_to_virt() and virt_to_bus() which are illegal under
  52. * the API. The entire queue processing structure will need to be
  53. * altered to fix this.
  54. * 2. Need to add memory mapping workaround. Test the memory mapping.
  55. * If it doesn't work revert to I/O port access. Can a test be done
  56. * safely?
  57. * 3. Handle an interrupt not working. Keep an interrupt counter in
  58. * the interrupt handler. In the timeout function if the interrupt
  59. * has not occurred then print a message and run in polled mode.
  60. * 4. Need to add support for target mode commands, cf. CAM XPT.
  61. * 5. check DMA mapping functions for failure
  62. * 6. Use scsi_transport_spi
  63. * 7. advansys_info is not safe against multiple simultaneous callers
  64. * 8. Add module_param to override ISA/VLB ioport array
  65. */
  66. #warning this driver is still not properly converted to the DMA API
  67. /* Enable driver /proc statistics. */
  68. #define ADVANSYS_STATS
  69. /* Enable driver tracing. */
  70. #undef ADVANSYS_DEBUG
  71. /*
  72. * Portable Data Types
  73. *
  74. * Any instance where a 32-bit long or pointer type is assumed
  75. * for precision or HW defined structures, the following define
  76. * types must be used. In Linux the char, short, and int types
  77. * are all consistent at 8, 16, and 32 bits respectively. Pointers
  78. * and long types are 64 bits on Alpha and UltraSPARC.
  79. */
  80. #define ASC_PADDR __u32 /* Physical/Bus address data type. */
  81. #define ASC_VADDR __u32 /* Virtual address data type. */
  82. #define ASC_DCNT __u32 /* Unsigned Data count type. */
  83. #define ASC_SDCNT __s32 /* Signed Data count type. */
  84. typedef unsigned char uchar;
  85. #ifndef TRUE
  86. #define TRUE (1)
  87. #endif
  88. #ifndef FALSE
  89. #define FALSE (0)
  90. #endif
  91. #define ERR (-1)
  92. #define UW_ERR (uint)(0xFFFF)
  93. #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
  94. #define PCI_VENDOR_ID_ASP 0x10cd
  95. #define PCI_DEVICE_ID_ASP_1200A 0x1100
  96. #define PCI_DEVICE_ID_ASP_ABP940 0x1200
  97. #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
  98. #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
  99. #define PCI_DEVICE_ID_38C0800_REV1 0x2500
  100. #define PCI_DEVICE_ID_38C1600_REV1 0x2700
  101. /*
  102. * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
  103. * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
  104. * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
  105. * SRB structure.
  106. */
  107. #define CC_VERY_LONG_SG_LIST 0
  108. #define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr)
  109. #define PortAddr unsigned int /* port address size */
  110. #define inp(port) inb(port)
  111. #define outp(port, byte) outb((byte), (port))
  112. #define inpw(port) inw(port)
  113. #define outpw(port, word) outw((word), (port))
  114. #define ASC_MAX_SG_QUEUE 7
  115. #define ASC_MAX_SG_LIST 255
  116. #define ASC_CS_TYPE unsigned short
  117. #define ASC_IS_ISA (0x0001)
  118. #define ASC_IS_ISAPNP (0x0081)
  119. #define ASC_IS_EISA (0x0002)
  120. #define ASC_IS_PCI (0x0004)
  121. #define ASC_IS_PCI_ULTRA (0x0104)
  122. #define ASC_IS_PCMCIA (0x0008)
  123. #define ASC_IS_MCA (0x0020)
  124. #define ASC_IS_VL (0x0040)
  125. #define ASC_IS_WIDESCSI_16 (0x0100)
  126. #define ASC_IS_WIDESCSI_32 (0x0200)
  127. #define ASC_IS_BIG_ENDIAN (0x8000)
  128. #define ASC_CHIP_MIN_VER_VL (0x01)
  129. #define ASC_CHIP_MAX_VER_VL (0x07)
  130. #define ASC_CHIP_MIN_VER_PCI (0x09)
  131. #define ASC_CHIP_MAX_VER_PCI (0x0F)
  132. #define ASC_CHIP_VER_PCI_BIT (0x08)
  133. #define ASC_CHIP_MIN_VER_ISA (0x11)
  134. #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
  135. #define ASC_CHIP_MAX_VER_ISA (0x27)
  136. #define ASC_CHIP_VER_ISA_BIT (0x30)
  137. #define ASC_CHIP_VER_ISAPNP_BIT (0x20)
  138. #define ASC_CHIP_VER_ASYN_BUG (0x21)
  139. #define ASC_CHIP_VER_PCI 0x08
  140. #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
  141. #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
  142. #define ASC_CHIP_MIN_VER_EISA (0x41)
  143. #define ASC_CHIP_MAX_VER_EISA (0x47)
  144. #define ASC_CHIP_VER_EISA_BIT (0x40)
  145. #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
  146. #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
  147. #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
  148. #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
  149. #define ASC_SCSI_ID_BITS 3
  150. #define ASC_SCSI_TIX_TYPE uchar
  151. #define ASC_ALL_DEVICE_BIT_SET 0xFF
  152. #define ASC_SCSI_BIT_ID_TYPE uchar
  153. #define ASC_MAX_TID 7
  154. #define ASC_MAX_LUN 7
  155. #define ASC_SCSI_WIDTH_BIT_SET 0xFF
  156. #define ASC_MAX_SENSE_LEN 32
  157. #define ASC_MIN_SENSE_LEN 14
  158. #define ASC_SCSI_RESET_HOLD_TIME_US 60
  159. /*
  160. * Narrow boards only support 12-byte commands, while wide boards
  161. * extend to 16-byte commands.
  162. */
  163. #define ASC_MAX_CDB_LEN 12
  164. #define ADV_MAX_CDB_LEN 16
  165. #define MS_SDTR_LEN 0x03
  166. #define MS_WDTR_LEN 0x02
  167. #define ASC_SG_LIST_PER_Q 7
  168. #define QS_FREE 0x00
  169. #define QS_READY 0x01
  170. #define QS_DISC1 0x02
  171. #define QS_DISC2 0x04
  172. #define QS_BUSY 0x08
  173. #define QS_ABORTED 0x40
  174. #define QS_DONE 0x80
  175. #define QC_NO_CALLBACK 0x01
  176. #define QC_SG_SWAP_QUEUE 0x02
  177. #define QC_SG_HEAD 0x04
  178. #define QC_DATA_IN 0x08
  179. #define QC_DATA_OUT 0x10
  180. #define QC_URGENT 0x20
  181. #define QC_MSG_OUT 0x40
  182. #define QC_REQ_SENSE 0x80
  183. #define QCSG_SG_XFER_LIST 0x02
  184. #define QCSG_SG_XFER_MORE 0x04
  185. #define QCSG_SG_XFER_END 0x08
  186. #define QD_IN_PROGRESS 0x00
  187. #define QD_NO_ERROR 0x01
  188. #define QD_ABORTED_BY_HOST 0x02
  189. #define QD_WITH_ERROR 0x04
  190. #define QD_INVALID_REQUEST 0x80
  191. #define QD_INVALID_HOST_NUM 0x81
  192. #define QD_INVALID_DEVICE 0x82
  193. #define QD_ERR_INTERNAL 0xFF
  194. #define QHSTA_NO_ERROR 0x00
  195. #define QHSTA_M_SEL_TIMEOUT 0x11
  196. #define QHSTA_M_DATA_OVER_RUN 0x12
  197. #define QHSTA_M_DATA_UNDER_RUN 0x12
  198. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  199. #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
  200. #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
  201. #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
  202. #define QHSTA_D_HOST_ABORT_FAILED 0x23
  203. #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
  204. #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
  205. #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
  206. #define QHSTA_M_WTM_TIMEOUT 0x41
  207. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  208. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  209. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  210. #define QHSTA_M_TARGET_STATUS_BUSY 0x45
  211. #define QHSTA_M_BAD_TAG_CODE 0x46
  212. #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
  213. #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
  214. #define QHSTA_D_LRAM_CMP_ERROR 0x81
  215. #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
  216. #define ASC_FLAG_SCSIQ_REQ 0x01
  217. #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
  218. #define ASC_FLAG_BIOS_ASYNC_IO 0x04
  219. #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
  220. #define ASC_FLAG_WIN16 0x10
  221. #define ASC_FLAG_WIN32 0x20
  222. #define ASC_FLAG_ISA_OVER_16MB 0x40
  223. #define ASC_FLAG_DOS_VM_CALLBACK 0x80
  224. #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
  225. #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
  226. #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
  227. #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
  228. #define ASC_SCSIQ_CPY_BEG 4
  229. #define ASC_SCSIQ_SGHD_CPY_BEG 2
  230. #define ASC_SCSIQ_B_FWD 0
  231. #define ASC_SCSIQ_B_BWD 1
  232. #define ASC_SCSIQ_B_STATUS 2
  233. #define ASC_SCSIQ_B_QNO 3
  234. #define ASC_SCSIQ_B_CNTL 4
  235. #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
  236. #define ASC_SCSIQ_D_DATA_ADDR 8
  237. #define ASC_SCSIQ_D_DATA_CNT 12
  238. #define ASC_SCSIQ_B_SENSE_LEN 20
  239. #define ASC_SCSIQ_DONE_INFO_BEG 22
  240. #define ASC_SCSIQ_D_SRBPTR 22
  241. #define ASC_SCSIQ_B_TARGET_IX 26
  242. #define ASC_SCSIQ_B_CDB_LEN 28
  243. #define ASC_SCSIQ_B_TAG_CODE 29
  244. #define ASC_SCSIQ_W_VM_ID 30
  245. #define ASC_SCSIQ_DONE_STATUS 32
  246. #define ASC_SCSIQ_HOST_STATUS 33
  247. #define ASC_SCSIQ_SCSI_STATUS 34
  248. #define ASC_SCSIQ_CDB_BEG 36
  249. #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
  250. #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
  251. #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
  252. #define ASC_SCSIQ_B_SG_WK_QP 49
  253. #define ASC_SCSIQ_B_SG_WK_IX 50
  254. #define ASC_SCSIQ_W_ALT_DC1 52
  255. #define ASC_SCSIQ_B_LIST_CNT 6
  256. #define ASC_SCSIQ_B_CUR_LIST_CNT 7
  257. #define ASC_SGQ_B_SG_CNTL 4
  258. #define ASC_SGQ_B_SG_HEAD_QP 5
  259. #define ASC_SGQ_B_SG_LIST_CNT 6
  260. #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
  261. #define ASC_SGQ_LIST_BEG 8
  262. #define ASC_DEF_SCSI1_QNG 4
  263. #define ASC_MAX_SCSI1_QNG 4
  264. #define ASC_DEF_SCSI2_QNG 16
  265. #define ASC_MAX_SCSI2_QNG 32
  266. #define ASC_TAG_CODE_MASK 0x23
  267. #define ASC_STOP_REQ_RISC_STOP 0x01
  268. #define ASC_STOP_ACK_RISC_STOP 0x03
  269. #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
  270. #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
  271. #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
  272. #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
  273. #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
  274. #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
  275. #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
  276. #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
  277. #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
  278. #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
  279. typedef struct asc_scsiq_1 {
  280. uchar status;
  281. uchar q_no;
  282. uchar cntl;
  283. uchar sg_queue_cnt;
  284. uchar target_id;
  285. uchar target_lun;
  286. ASC_PADDR data_addr;
  287. ASC_DCNT data_cnt;
  288. ASC_PADDR sense_addr;
  289. uchar sense_len;
  290. uchar extra_bytes;
  291. } ASC_SCSIQ_1;
  292. typedef struct asc_scsiq_2 {
  293. ASC_VADDR srb_ptr;
  294. uchar target_ix;
  295. uchar flag;
  296. uchar cdb_len;
  297. uchar tag_code;
  298. ushort vm_id;
  299. } ASC_SCSIQ_2;
  300. typedef struct asc_scsiq_3 {
  301. uchar done_stat;
  302. uchar host_stat;
  303. uchar scsi_stat;
  304. uchar scsi_msg;
  305. } ASC_SCSIQ_3;
  306. typedef struct asc_scsiq_4 {
  307. uchar cdb[ASC_MAX_CDB_LEN];
  308. uchar y_first_sg_list_qp;
  309. uchar y_working_sg_qp;
  310. uchar y_working_sg_ix;
  311. uchar y_res;
  312. ushort x_req_count;
  313. ushort x_reconnect_rtn;
  314. ASC_PADDR x_saved_data_addr;
  315. ASC_DCNT x_saved_data_cnt;
  316. } ASC_SCSIQ_4;
  317. typedef struct asc_q_done_info {
  318. ASC_SCSIQ_2 d2;
  319. ASC_SCSIQ_3 d3;
  320. uchar q_status;
  321. uchar q_no;
  322. uchar cntl;
  323. uchar sense_len;
  324. uchar extra_bytes;
  325. uchar res;
  326. ASC_DCNT remain_bytes;
  327. } ASC_QDONE_INFO;
  328. typedef struct asc_sg_list {
  329. ASC_PADDR addr;
  330. ASC_DCNT bytes;
  331. } ASC_SG_LIST;
  332. typedef struct asc_sg_head {
  333. ushort entry_cnt;
  334. ushort queue_cnt;
  335. ushort entry_to_copy;
  336. ushort res;
  337. ASC_SG_LIST sg_list[0];
  338. } ASC_SG_HEAD;
  339. typedef struct asc_scsi_q {
  340. ASC_SCSIQ_1 q1;
  341. ASC_SCSIQ_2 q2;
  342. uchar *cdbptr;
  343. ASC_SG_HEAD *sg_head;
  344. ushort remain_sg_entry_cnt;
  345. ushort next_sg_index;
  346. } ASC_SCSI_Q;
  347. typedef struct asc_scsi_req_q {
  348. ASC_SCSIQ_1 r1;
  349. ASC_SCSIQ_2 r2;
  350. uchar *cdbptr;
  351. ASC_SG_HEAD *sg_head;
  352. uchar *sense_ptr;
  353. ASC_SCSIQ_3 r3;
  354. uchar cdb[ASC_MAX_CDB_LEN];
  355. uchar sense[ASC_MIN_SENSE_LEN];
  356. } ASC_SCSI_REQ_Q;
  357. typedef struct asc_scsi_bios_req_q {
  358. ASC_SCSIQ_1 r1;
  359. ASC_SCSIQ_2 r2;
  360. uchar *cdbptr;
  361. ASC_SG_HEAD *sg_head;
  362. uchar *sense_ptr;
  363. ASC_SCSIQ_3 r3;
  364. uchar cdb[ASC_MAX_CDB_LEN];
  365. uchar sense[ASC_MIN_SENSE_LEN];
  366. } ASC_SCSI_BIOS_REQ_Q;
  367. typedef struct asc_risc_q {
  368. uchar fwd;
  369. uchar bwd;
  370. ASC_SCSIQ_1 i1;
  371. ASC_SCSIQ_2 i2;
  372. ASC_SCSIQ_3 i3;
  373. ASC_SCSIQ_4 i4;
  374. } ASC_RISC_Q;
  375. typedef struct asc_sg_list_q {
  376. uchar seq_no;
  377. uchar q_no;
  378. uchar cntl;
  379. uchar sg_head_qp;
  380. uchar sg_list_cnt;
  381. uchar sg_cur_list_cnt;
  382. } ASC_SG_LIST_Q;
  383. typedef struct asc_risc_sg_list_q {
  384. uchar fwd;
  385. uchar bwd;
  386. ASC_SG_LIST_Q sg;
  387. ASC_SG_LIST sg_list[7];
  388. } ASC_RISC_SG_LIST_Q;
  389. #define ASCQ_ERR_Q_STATUS 0x0D
  390. #define ASCQ_ERR_CUR_QNG 0x17
  391. #define ASCQ_ERR_SG_Q_LINKS 0x18
  392. #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
  393. #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
  394. #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
  395. /*
  396. * Warning code values are set in ASC_DVC_VAR 'warn_code'.
  397. */
  398. #define ASC_WARN_NO_ERROR 0x0000
  399. #define ASC_WARN_IO_PORT_ROTATE 0x0001
  400. #define ASC_WARN_EEPROM_CHKSUM 0x0002
  401. #define ASC_WARN_IRQ_MODIFIED 0x0004
  402. #define ASC_WARN_AUTO_CONFIG 0x0008
  403. #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
  404. #define ASC_WARN_EEPROM_RECOVER 0x0020
  405. #define ASC_WARN_CFG_MSW_RECOVER 0x0040
  406. /*
  407. * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
  408. */
  409. #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
  410. #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
  411. #define ASC_IERR_SET_PC_ADDR 0x0004
  412. #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
  413. #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
  414. #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
  415. #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
  416. #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
  417. #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
  418. #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
  419. #define ASC_IERR_NO_BUS_TYPE 0x0400
  420. #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
  421. #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
  422. #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
  423. #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
  424. #define ASC_MIN_TAG_Q_PER_DVC (0x04)
  425. #define ASC_MIN_FREE_Q (0x02)
  426. #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
  427. #define ASC_MAX_TOTAL_QNG 240
  428. #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
  429. #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
  430. #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
  431. #define ASC_MAX_INRAM_TAG_QNG 16
  432. #define ASC_IOADR_GAP 0x10
  433. #define ASC_SYN_MAX_OFFSET 0x0F
  434. #define ASC_DEF_SDTR_OFFSET 0x0F
  435. #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
  436. #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
  437. /* The narrow chip only supports a limited selection of transfer rates.
  438. * These are encoded in the range 0..7 or 0..15 depending whether the chip
  439. * is Ultra-capable or not. These tables let us convert from one to the other.
  440. */
  441. static const unsigned char asc_syn_xfer_period[8] = {
  442. 25, 30, 35, 40, 50, 60, 70, 85
  443. };
  444. static const unsigned char asc_syn_ultra_xfer_period[16] = {
  445. 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
  446. };
  447. typedef struct ext_msg {
  448. uchar msg_type;
  449. uchar msg_len;
  450. uchar msg_req;
  451. union {
  452. struct {
  453. uchar sdtr_xfer_period;
  454. uchar sdtr_req_ack_offset;
  455. } sdtr;
  456. struct {
  457. uchar wdtr_width;
  458. } wdtr;
  459. struct {
  460. uchar mdp_b3;
  461. uchar mdp_b2;
  462. uchar mdp_b1;
  463. uchar mdp_b0;
  464. } mdp;
  465. } u_ext_msg;
  466. uchar res;
  467. } EXT_MSG;
  468. #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
  469. #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
  470. #define wdtr_width u_ext_msg.wdtr.wdtr_width
  471. #define mdp_b3 u_ext_msg.mdp_b3
  472. #define mdp_b2 u_ext_msg.mdp_b2
  473. #define mdp_b1 u_ext_msg.mdp_b1
  474. #define mdp_b0 u_ext_msg.mdp_b0
  475. typedef struct asc_dvc_cfg {
  476. ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
  477. ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
  478. ASC_SCSI_BIT_ID_TYPE disc_enable;
  479. ASC_SCSI_BIT_ID_TYPE sdtr_enable;
  480. uchar chip_scsi_id;
  481. uchar isa_dma_speed;
  482. uchar isa_dma_channel;
  483. uchar chip_version;
  484. ushort mcode_date;
  485. ushort mcode_version;
  486. uchar max_tag_qng[ASC_MAX_TID + 1];
  487. uchar sdtr_period_offset[ASC_MAX_TID + 1];
  488. uchar adapter_info[6];
  489. } ASC_DVC_CFG;
  490. #define ASC_DEF_DVC_CNTL 0xFFFF
  491. #define ASC_DEF_CHIP_SCSI_ID 7
  492. #define ASC_DEF_ISA_DMA_SPEED 4
  493. #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
  494. #define ASC_INIT_STATE_END_GET_CFG 0x0002
  495. #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
  496. #define ASC_INIT_STATE_END_SET_CFG 0x0008
  497. #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
  498. #define ASC_INIT_STATE_END_LOAD_MC 0x0020
  499. #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
  500. #define ASC_INIT_STATE_END_INQUIRY 0x0080
  501. #define ASC_INIT_RESET_SCSI_DONE 0x0100
  502. #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
  503. #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
  504. #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
  505. #define ASC_MIN_TAGGED_CMD 7
  506. #define ASC_MAX_SCSI_RESET_WAIT 30
  507. #define ASC_OVERRUN_BSIZE 64
  508. struct asc_dvc_var; /* Forward Declaration. */
  509. typedef struct asc_dvc_var {
  510. PortAddr iop_base;
  511. ushort err_code;
  512. ushort dvc_cntl;
  513. ushort bug_fix_cntl;
  514. ushort bus_type;
  515. ASC_SCSI_BIT_ID_TYPE init_sdtr;
  516. ASC_SCSI_BIT_ID_TYPE sdtr_done;
  517. ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
  518. ASC_SCSI_BIT_ID_TYPE unit_not_ready;
  519. ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
  520. ASC_SCSI_BIT_ID_TYPE start_motor;
  521. uchar *overrun_buf;
  522. dma_addr_t overrun_dma;
  523. uchar scsi_reset_wait;
  524. uchar chip_no;
  525. char is_in_int;
  526. uchar max_total_qng;
  527. uchar cur_total_qng;
  528. uchar in_critical_cnt;
  529. uchar last_q_shortage;
  530. ushort init_state;
  531. uchar cur_dvc_qng[ASC_MAX_TID + 1];
  532. uchar max_dvc_qng[ASC_MAX_TID + 1];
  533. ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
  534. ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
  535. const uchar *sdtr_period_tbl;
  536. ASC_DVC_CFG *cfg;
  537. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
  538. char redo_scam;
  539. ushort res2;
  540. uchar dos_int13_table[ASC_MAX_TID + 1];
  541. ASC_DCNT max_dma_count;
  542. ASC_SCSI_BIT_ID_TYPE no_scam;
  543. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
  544. uchar min_sdtr_index;
  545. uchar max_sdtr_index;
  546. struct asc_board *drv_ptr;
  547. int ptr_map_count;
  548. void **ptr_map;
  549. ASC_DCNT uc_break;
  550. } ASC_DVC_VAR;
  551. typedef struct asc_dvc_inq_info {
  552. uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  553. } ASC_DVC_INQ_INFO;
  554. typedef struct asc_cap_info {
  555. ASC_DCNT lba;
  556. ASC_DCNT blk_size;
  557. } ASC_CAP_INFO;
  558. typedef struct asc_cap_info_array {
  559. ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  560. } ASC_CAP_INFO_ARRAY;
  561. #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
  562. #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
  563. #define ASC_CNTL_INITIATOR (ushort)0x0001
  564. #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
  565. #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
  566. #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
  567. #define ASC_CNTL_NO_SCAM (ushort)0x0010
  568. #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
  569. #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
  570. #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
  571. #define ASC_CNTL_RESET_SCSI (ushort)0x0200
  572. #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
  573. #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
  574. #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
  575. #define ASC_CNTL_BURST_MODE (ushort)0x2000
  576. #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
  577. #define ASC_EEP_DVC_CFG_BEG_VL 2
  578. #define ASC_EEP_MAX_DVC_ADDR_VL 15
  579. #define ASC_EEP_DVC_CFG_BEG 32
  580. #define ASC_EEP_MAX_DVC_ADDR 45
  581. #define ASC_EEP_MAX_RETRY 20
  582. /*
  583. * These macros keep the chip SCSI id and ISA DMA speed
  584. * bitfields in board order. C bitfields aren't portable
  585. * between big and little-endian platforms so they are
  586. * not used.
  587. */
  588. #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
  589. #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
  590. #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
  591. ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
  592. #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
  593. ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
  594. typedef struct asceep_config {
  595. ushort cfg_lsw;
  596. ushort cfg_msw;
  597. uchar init_sdtr;
  598. uchar disc_enable;
  599. uchar use_cmd_qng;
  600. uchar start_motor;
  601. uchar max_total_qng;
  602. uchar max_tag_qng;
  603. uchar bios_scan;
  604. uchar power_up_wait;
  605. uchar no_scam;
  606. uchar id_speed; /* low order 4 bits is chip scsi id */
  607. /* high order 4 bits is isa dma speed */
  608. uchar dos_int13_table[ASC_MAX_TID + 1];
  609. uchar adapter_info[6];
  610. ushort cntl;
  611. ushort chksum;
  612. } ASCEEP_CONFIG;
  613. #define ASC_EEP_CMD_READ 0x80
  614. #define ASC_EEP_CMD_WRITE 0x40
  615. #define ASC_EEP_CMD_WRITE_ABLE 0x30
  616. #define ASC_EEP_CMD_WRITE_DISABLE 0x00
  617. #define ASCV_MSGOUT_BEG 0x0000
  618. #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
  619. #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
  620. #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
  621. #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
  622. #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
  623. #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
  624. #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
  625. #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
  626. #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
  627. #define ASCV_BREAK_ADDR (ushort)0x0028
  628. #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
  629. #define ASCV_BREAK_CONTROL (ushort)0x002C
  630. #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
  631. #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
  632. #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
  633. #define ASCV_MCODE_SIZE_W (ushort)0x0034
  634. #define ASCV_STOP_CODE_B (ushort)0x0036
  635. #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
  636. #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
  637. #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
  638. #define ASCV_HALTCODE_W (ushort)0x0040
  639. #define ASCV_CHKSUM_W (ushort)0x0042
  640. #define ASCV_MC_DATE_W (ushort)0x0044
  641. #define ASCV_MC_VER_W (ushort)0x0046
  642. #define ASCV_NEXTRDY_B (ushort)0x0048
  643. #define ASCV_DONENEXT_B (ushort)0x0049
  644. #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
  645. #define ASCV_SCSIBUSY_B (ushort)0x004B
  646. #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
  647. #define ASCV_CURCDB_B (ushort)0x004D
  648. #define ASCV_RCLUN_B (ushort)0x004E
  649. #define ASCV_BUSY_QHEAD_B (ushort)0x004F
  650. #define ASCV_DISC1_QHEAD_B (ushort)0x0050
  651. #define ASCV_DISC_ENABLE_B (ushort)0x0052
  652. #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
  653. #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
  654. #define ASCV_MCODE_CNTL_B (ushort)0x0056
  655. #define ASCV_NULL_TARGET_B (ushort)0x0057
  656. #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
  657. #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
  658. #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
  659. #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
  660. #define ASCV_HOST_FLAG_B (ushort)0x005D
  661. #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
  662. #define ASCV_VER_SERIAL_B (ushort)0x0065
  663. #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
  664. #define ASCV_WTM_FLAG_B (ushort)0x0068
  665. #define ASCV_RISC_FLAG_B (ushort)0x006A
  666. #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
  667. #define ASC_HOST_FLAG_IN_ISR 0x01
  668. #define ASC_HOST_FLAG_ACK_INT 0x02
  669. #define ASC_RISC_FLAG_GEN_INT 0x01
  670. #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
  671. #define IOP_CTRL (0x0F)
  672. #define IOP_STATUS (0x0E)
  673. #define IOP_INT_ACK IOP_STATUS
  674. #define IOP_REG_IFC (0x0D)
  675. #define IOP_SYN_OFFSET (0x0B)
  676. #define IOP_EXTRA_CONTROL (0x0D)
  677. #define IOP_REG_PC (0x0C)
  678. #define IOP_RAM_ADDR (0x0A)
  679. #define IOP_RAM_DATA (0x08)
  680. #define IOP_EEP_DATA (0x06)
  681. #define IOP_EEP_CMD (0x07)
  682. #define IOP_VERSION (0x03)
  683. #define IOP_CONFIG_HIGH (0x04)
  684. #define IOP_CONFIG_LOW (0x02)
  685. #define IOP_SIG_BYTE (0x01)
  686. #define IOP_SIG_WORD (0x00)
  687. #define IOP_REG_DC1 (0x0E)
  688. #define IOP_REG_DC0 (0x0C)
  689. #define IOP_REG_SB (0x0B)
  690. #define IOP_REG_DA1 (0x0A)
  691. #define IOP_REG_DA0 (0x08)
  692. #define IOP_REG_SC (0x09)
  693. #define IOP_DMA_SPEED (0x07)
  694. #define IOP_REG_FLAG (0x07)
  695. #define IOP_FIFO_H (0x06)
  696. #define IOP_FIFO_L (0x04)
  697. #define IOP_REG_ID (0x05)
  698. #define IOP_REG_QP (0x03)
  699. #define IOP_REG_IH (0x02)
  700. #define IOP_REG_IX (0x01)
  701. #define IOP_REG_AX (0x00)
  702. #define IFC_REG_LOCK (0x00)
  703. #define IFC_REG_UNLOCK (0x09)
  704. #define IFC_WR_EN_FILTER (0x10)
  705. #define IFC_RD_NO_EEPROM (0x10)
  706. #define IFC_SLEW_RATE (0x20)
  707. #define IFC_ACT_NEG (0x40)
  708. #define IFC_INP_FILTER (0x80)
  709. #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
  710. #define SC_SEL (uchar)(0x80)
  711. #define SC_BSY (uchar)(0x40)
  712. #define SC_ACK (uchar)(0x20)
  713. #define SC_REQ (uchar)(0x10)
  714. #define SC_ATN (uchar)(0x08)
  715. #define SC_IO (uchar)(0x04)
  716. #define SC_CD (uchar)(0x02)
  717. #define SC_MSG (uchar)(0x01)
  718. #define SEC_SCSI_CTL (uchar)(0x80)
  719. #define SEC_ACTIVE_NEGATE (uchar)(0x40)
  720. #define SEC_SLEW_RATE (uchar)(0x20)
  721. #define SEC_ENABLE_FILTER (uchar)(0x10)
  722. #define ASC_HALT_EXTMSG_IN (ushort)0x8000
  723. #define ASC_HALT_CHK_CONDITION (ushort)0x8100
  724. #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
  725. #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
  726. #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
  727. #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
  728. #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
  729. #define ASC_MAX_QNO 0xF8
  730. #define ASC_DATA_SEC_BEG (ushort)0x0080
  731. #define ASC_DATA_SEC_END (ushort)0x0080
  732. #define ASC_CODE_SEC_BEG (ushort)0x0080
  733. #define ASC_CODE_SEC_END (ushort)0x0080
  734. #define ASC_QADR_BEG (0x4000)
  735. #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
  736. #define ASC_QADR_END (ushort)0x7FFF
  737. #define ASC_QLAST_ADR (ushort)0x7FC0
  738. #define ASC_QBLK_SIZE 0x40
  739. #define ASC_BIOS_DATA_QBEG 0xF8
  740. #define ASC_MIN_ACTIVE_QNO 0x01
  741. #define ASC_QLINK_END 0xFF
  742. #define ASC_EEPROM_WORDS 0x10
  743. #define ASC_MAX_MGS_LEN 0x10
  744. #define ASC_BIOS_ADDR_DEF 0xDC00
  745. #define ASC_BIOS_SIZE 0x3800
  746. #define ASC_BIOS_RAM_OFF 0x3800
  747. #define ASC_BIOS_RAM_SIZE 0x800
  748. #define ASC_BIOS_MIN_ADDR 0xC000
  749. #define ASC_BIOS_MAX_ADDR 0xEC00
  750. #define ASC_BIOS_BANK_SIZE 0x0400
  751. #define ASC_MCODE_START_ADDR 0x0080
  752. #define ASC_CFG0_HOST_INT_ON 0x0020
  753. #define ASC_CFG0_BIOS_ON 0x0040
  754. #define ASC_CFG0_VERA_BURST_ON 0x0080
  755. #define ASC_CFG0_SCSI_PARITY_ON 0x0800
  756. #define ASC_CFG1_SCSI_TARGET_ON 0x0080
  757. #define ASC_CFG1_LRAM_8BITS_ON 0x0800
  758. #define ASC_CFG_MSW_CLR_MASK 0x3080
  759. #define CSW_TEST1 (ASC_CS_TYPE)0x8000
  760. #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
  761. #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
  762. #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
  763. #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
  764. #define CSW_TEST2 (ASC_CS_TYPE)0x0400
  765. #define CSW_TEST3 (ASC_CS_TYPE)0x0200
  766. #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
  767. #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
  768. #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
  769. #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
  770. #define CSW_HALTED (ASC_CS_TYPE)0x0010
  771. #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
  772. #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
  773. #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
  774. #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
  775. #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
  776. #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
  777. #define CIW_TEST1 (ASC_CS_TYPE)0x0200
  778. #define CIW_TEST2 (ASC_CS_TYPE)0x0400
  779. #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
  780. #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
  781. #define CC_CHIP_RESET (uchar)0x80
  782. #define CC_SCSI_RESET (uchar)0x40
  783. #define CC_HALT (uchar)0x20
  784. #define CC_SINGLE_STEP (uchar)0x10
  785. #define CC_DMA_ABLE (uchar)0x08
  786. #define CC_TEST (uchar)0x04
  787. #define CC_BANK_ONE (uchar)0x02
  788. #define CC_DIAG (uchar)0x01
  789. #define ASC_1000_ID0W 0x04C1
  790. #define ASC_1000_ID0W_FIX 0x00C1
  791. #define ASC_1000_ID1B 0x25
  792. #define ASC_EISA_REV_IOP_MASK (0x0C83)
  793. #define ASC_EISA_CFG_IOP_MASK (0x0C86)
  794. #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
  795. #define INS_HALTINT (ushort)0x6281
  796. #define INS_HALT (ushort)0x6280
  797. #define INS_SINT (ushort)0x6200
  798. #define INS_RFLAG_WTM (ushort)0x7380
  799. #define ASC_MC_SAVE_CODE_WSIZE 0x500
  800. #define ASC_MC_SAVE_DATA_WSIZE 0x40
  801. typedef struct asc_mc_saved {
  802. ushort data[ASC_MC_SAVE_DATA_WSIZE];
  803. ushort code[ASC_MC_SAVE_CODE_WSIZE];
  804. } ASC_MC_SAVED;
  805. #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
  806. #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
  807. #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
  808. #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
  809. #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
  810. #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
  811. #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
  812. #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
  813. #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
  814. #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
  815. #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
  816. #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
  817. #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
  818. #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
  819. #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
  820. #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
  821. #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
  822. #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
  823. #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
  824. #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
  825. #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
  826. #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
  827. #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
  828. #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
  829. #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
  830. #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
  831. #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
  832. #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
  833. #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
  834. #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
  835. #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
  836. #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
  837. #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
  838. #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
  839. #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
  840. #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
  841. #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
  842. #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
  843. #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
  844. #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
  845. #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
  846. #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
  847. #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
  848. #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
  849. #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
  850. #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
  851. #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
  852. #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
  853. #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
  854. #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
  855. #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
  856. #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
  857. #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
  858. #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
  859. #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
  860. #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
  861. #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
  862. #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
  863. #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
  864. #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
  865. #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
  866. #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
  867. #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
  868. #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
  869. #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
  870. #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
  871. #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
  872. /*
  873. * Portable Data Types
  874. *
  875. * Any instance where a 32-bit long or pointer type is assumed
  876. * for precision or HW defined structures, the following define
  877. * types must be used. In Linux the char, short, and int types
  878. * are all consistent at 8, 16, and 32 bits respectively. Pointers
  879. * and long types are 64 bits on Alpha and UltraSPARC.
  880. */
  881. #define ADV_PADDR __u32 /* Physical address data type. */
  882. #define ADV_VADDR __u32 /* Virtual address data type. */
  883. #define ADV_DCNT __u32 /* Unsigned Data count type. */
  884. #define ADV_SDCNT __s32 /* Signed Data count type. */
  885. /*
  886. * These macros are used to convert a virtual address to a
  887. * 32-bit value. This currently can be used on Linux Alpha
  888. * which uses 64-bit virtual address but a 32-bit bus address.
  889. * This is likely to break in the future, but doing this now
  890. * will give us time to change the HW and FW to handle 64-bit
  891. * addresses.
  892. */
  893. #define ADV_VADDR_TO_U32 virt_to_bus
  894. #define ADV_U32_TO_VADDR bus_to_virt
  895. #define AdvPortAddr void __iomem * /* Virtual memory address size */
  896. /*
  897. * Define Adv Library required memory access macros.
  898. */
  899. #define ADV_MEM_READB(addr) readb(addr)
  900. #define ADV_MEM_READW(addr) readw(addr)
  901. #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
  902. #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
  903. #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
  904. #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
  905. /*
  906. * Define total number of simultaneous maximum element scatter-gather
  907. * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
  908. * maximum number of outstanding commands per wide host adapter. Each
  909. * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
  910. * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
  911. * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
  912. * structures or 255 scatter-gather elements.
  913. */
  914. #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
  915. /*
  916. * Define maximum number of scatter-gather elements per request.
  917. */
  918. #define ADV_MAX_SG_LIST 255
  919. #define NO_OF_SG_PER_BLOCK 15
  920. #define ADV_EEP_DVC_CFG_BEGIN (0x00)
  921. #define ADV_EEP_DVC_CFG_END (0x15)
  922. #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
  923. #define ADV_EEP_MAX_WORD_ADDR (0x1E)
  924. #define ADV_EEP_DELAY_MS 100
  925. #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
  926. #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
  927. /*
  928. * For the ASC3550 Bit 13 is Termination Polarity control bit.
  929. * For later ICs Bit 13 controls whether the CIS (Card Information
  930. * Service Section) is loaded from EEPROM.
  931. */
  932. #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
  933. #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
  934. /*
  935. * ASC38C1600 Bit 11
  936. *
  937. * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
  938. * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
  939. * Function 0 will specify INT B.
  940. *
  941. * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
  942. * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
  943. * Function 1 will specify INT A.
  944. */
  945. #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
  946. typedef struct adveep_3550_config {
  947. /* Word Offset, Description */
  948. ushort cfg_lsw; /* 00 power up initialization */
  949. /* bit 13 set - Term Polarity Control */
  950. /* bit 14 set - BIOS Enable */
  951. /* bit 15 set - Big Endian Mode */
  952. ushort cfg_msw; /* 01 unused */
  953. ushort disc_enable; /* 02 disconnect enable */
  954. ushort wdtr_able; /* 03 Wide DTR able */
  955. ushort sdtr_able; /* 04 Synchronous DTR able */
  956. ushort start_motor; /* 05 send start up motor */
  957. ushort tagqng_able; /* 06 tag queuing able */
  958. ushort bios_scan; /* 07 BIOS device control */
  959. ushort scam_tolerant; /* 08 no scam */
  960. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  961. uchar bios_boot_delay; /* power up wait */
  962. uchar scsi_reset_delay; /* 10 reset delay */
  963. uchar bios_id_lun; /* first boot device scsi id & lun */
  964. /* high nibble is lun */
  965. /* low nibble is scsi id */
  966. uchar termination; /* 11 0 - automatic */
  967. /* 1 - low off / high off */
  968. /* 2 - low off / high on */
  969. /* 3 - low on / high on */
  970. /* There is no low on / high off */
  971. uchar reserved1; /* reserved byte (not used) */
  972. ushort bios_ctrl; /* 12 BIOS control bits */
  973. /* bit 0 BIOS don't act as initiator. */
  974. /* bit 1 BIOS > 1 GB support */
  975. /* bit 2 BIOS > 2 Disk Support */
  976. /* bit 3 BIOS don't support removables */
  977. /* bit 4 BIOS support bootable CD */
  978. /* bit 5 BIOS scan enabled */
  979. /* bit 6 BIOS support multiple LUNs */
  980. /* bit 7 BIOS display of message */
  981. /* bit 8 SCAM disabled */
  982. /* bit 9 Reset SCSI bus during init. */
  983. /* bit 10 */
  984. /* bit 11 No verbose initialization. */
  985. /* bit 12 SCSI parity enabled */
  986. /* bit 13 */
  987. /* bit 14 */
  988. /* bit 15 */
  989. ushort ultra_able; /* 13 ULTRA speed able */
  990. ushort reserved2; /* 14 reserved */
  991. uchar max_host_qng; /* 15 maximum host queuing */
  992. uchar max_dvc_qng; /* maximum per device queuing */
  993. ushort dvc_cntl; /* 16 control bit for driver */
  994. ushort bug_fix; /* 17 control bit for bug fix */
  995. ushort serial_number_word1; /* 18 Board serial number word 1 */
  996. ushort serial_number_word2; /* 19 Board serial number word 2 */
  997. ushort serial_number_word3; /* 20 Board serial number word 3 */
  998. ushort check_sum; /* 21 EEP check sum */
  999. uchar oem_name[16]; /* 22 OEM name */
  1000. ushort dvc_err_code; /* 30 last device driver error code */
  1001. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1002. ushort adv_err_addr; /* 32 last uc error address */
  1003. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1004. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1005. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1006. ushort num_of_err; /* 36 number of error */
  1007. } ADVEEP_3550_CONFIG;
  1008. typedef struct adveep_38C0800_config {
  1009. /* Word Offset, Description */
  1010. ushort cfg_lsw; /* 00 power up initialization */
  1011. /* bit 13 set - Load CIS */
  1012. /* bit 14 set - BIOS Enable */
  1013. /* bit 15 set - Big Endian Mode */
  1014. ushort cfg_msw; /* 01 unused */
  1015. ushort disc_enable; /* 02 disconnect enable */
  1016. ushort wdtr_able; /* 03 Wide DTR able */
  1017. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1018. ushort start_motor; /* 05 send start up motor */
  1019. ushort tagqng_able; /* 06 tag queuing able */
  1020. ushort bios_scan; /* 07 BIOS device control */
  1021. ushort scam_tolerant; /* 08 no scam */
  1022. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1023. uchar bios_boot_delay; /* power up wait */
  1024. uchar scsi_reset_delay; /* 10 reset delay */
  1025. uchar bios_id_lun; /* first boot device scsi id & lun */
  1026. /* high nibble is lun */
  1027. /* low nibble is scsi id */
  1028. uchar termination_se; /* 11 0 - automatic */
  1029. /* 1 - low off / high off */
  1030. /* 2 - low off / high on */
  1031. /* 3 - low on / high on */
  1032. /* There is no low on / high off */
  1033. uchar termination_lvd; /* 11 0 - automatic */
  1034. /* 1 - low off / high off */
  1035. /* 2 - low off / high on */
  1036. /* 3 - low on / high on */
  1037. /* There is no low on / high off */
  1038. ushort bios_ctrl; /* 12 BIOS control bits */
  1039. /* bit 0 BIOS don't act as initiator. */
  1040. /* bit 1 BIOS > 1 GB support */
  1041. /* bit 2 BIOS > 2 Disk Support */
  1042. /* bit 3 BIOS don't support removables */
  1043. /* bit 4 BIOS support bootable CD */
  1044. /* bit 5 BIOS scan enabled */
  1045. /* bit 6 BIOS support multiple LUNs */
  1046. /* bit 7 BIOS display of message */
  1047. /* bit 8 SCAM disabled */
  1048. /* bit 9 Reset SCSI bus during init. */
  1049. /* bit 10 */
  1050. /* bit 11 No verbose initialization. */
  1051. /* bit 12 SCSI parity enabled */
  1052. /* bit 13 */
  1053. /* bit 14 */
  1054. /* bit 15 */
  1055. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1056. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1057. uchar max_host_qng; /* 15 maximum host queueing */
  1058. uchar max_dvc_qng; /* maximum per device queuing */
  1059. ushort dvc_cntl; /* 16 control bit for driver */
  1060. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1061. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1062. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1063. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1064. ushort check_sum; /* 21 EEP check sum */
  1065. uchar oem_name[16]; /* 22 OEM name */
  1066. ushort dvc_err_code; /* 30 last device driver error code */
  1067. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1068. ushort adv_err_addr; /* 32 last uc error address */
  1069. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1070. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1071. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1072. ushort reserved36; /* 36 reserved */
  1073. ushort reserved37; /* 37 reserved */
  1074. ushort reserved38; /* 38 reserved */
  1075. ushort reserved39; /* 39 reserved */
  1076. ushort reserved40; /* 40 reserved */
  1077. ushort reserved41; /* 41 reserved */
  1078. ushort reserved42; /* 42 reserved */
  1079. ushort reserved43; /* 43 reserved */
  1080. ushort reserved44; /* 44 reserved */
  1081. ushort reserved45; /* 45 reserved */
  1082. ushort reserved46; /* 46 reserved */
  1083. ushort reserved47; /* 47 reserved */
  1084. ushort reserved48; /* 48 reserved */
  1085. ushort reserved49; /* 49 reserved */
  1086. ushort reserved50; /* 50 reserved */
  1087. ushort reserved51; /* 51 reserved */
  1088. ushort reserved52; /* 52 reserved */
  1089. ushort reserved53; /* 53 reserved */
  1090. ushort reserved54; /* 54 reserved */
  1091. ushort reserved55; /* 55 reserved */
  1092. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1093. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1094. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1095. ushort subsysid; /* 59 SubSystem ID */
  1096. ushort reserved60; /* 60 reserved */
  1097. ushort reserved61; /* 61 reserved */
  1098. ushort reserved62; /* 62 reserved */
  1099. ushort reserved63; /* 63 reserved */
  1100. } ADVEEP_38C0800_CONFIG;
  1101. typedef struct adveep_38C1600_config {
  1102. /* Word Offset, Description */
  1103. ushort cfg_lsw; /* 00 power up initialization */
  1104. /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
  1105. /* clear - Func. 0 INTA, Func. 1 INTB */
  1106. /* bit 13 set - Load CIS */
  1107. /* bit 14 set - BIOS Enable */
  1108. /* bit 15 set - Big Endian Mode */
  1109. ushort cfg_msw; /* 01 unused */
  1110. ushort disc_enable; /* 02 disconnect enable */
  1111. ushort wdtr_able; /* 03 Wide DTR able */
  1112. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1113. ushort start_motor; /* 05 send start up motor */
  1114. ushort tagqng_able; /* 06 tag queuing able */
  1115. ushort bios_scan; /* 07 BIOS device control */
  1116. ushort scam_tolerant; /* 08 no scam */
  1117. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1118. uchar bios_boot_delay; /* power up wait */
  1119. uchar scsi_reset_delay; /* 10 reset delay */
  1120. uchar bios_id_lun; /* first boot device scsi id & lun */
  1121. /* high nibble is lun */
  1122. /* low nibble is scsi id */
  1123. uchar termination_se; /* 11 0 - automatic */
  1124. /* 1 - low off / high off */
  1125. /* 2 - low off / high on */
  1126. /* 3 - low on / high on */
  1127. /* There is no low on / high off */
  1128. uchar termination_lvd; /* 11 0 - automatic */
  1129. /* 1 - low off / high off */
  1130. /* 2 - low off / high on */
  1131. /* 3 - low on / high on */
  1132. /* There is no low on / high off */
  1133. ushort bios_ctrl; /* 12 BIOS control bits */
  1134. /* bit 0 BIOS don't act as initiator. */
  1135. /* bit 1 BIOS > 1 GB support */
  1136. /* bit 2 BIOS > 2 Disk Support */
  1137. /* bit 3 BIOS don't support removables */
  1138. /* bit 4 BIOS support bootable CD */
  1139. /* bit 5 BIOS scan enabled */
  1140. /* bit 6 BIOS support multiple LUNs */
  1141. /* bit 7 BIOS display of message */
  1142. /* bit 8 SCAM disabled */
  1143. /* bit 9 Reset SCSI bus during init. */
  1144. /* bit 10 Basic Integrity Checking disabled */
  1145. /* bit 11 No verbose initialization. */
  1146. /* bit 12 SCSI parity enabled */
  1147. /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
  1148. /* bit 14 */
  1149. /* bit 15 */
  1150. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1151. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1152. uchar max_host_qng; /* 15 maximum host queueing */
  1153. uchar max_dvc_qng; /* maximum per device queuing */
  1154. ushort dvc_cntl; /* 16 control bit for driver */
  1155. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1156. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1157. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1158. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1159. ushort check_sum; /* 21 EEP check sum */
  1160. uchar oem_name[16]; /* 22 OEM name */
  1161. ushort dvc_err_code; /* 30 last device driver error code */
  1162. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1163. ushort adv_err_addr; /* 32 last uc error address */
  1164. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1165. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1166. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1167. ushort reserved36; /* 36 reserved */
  1168. ushort reserved37; /* 37 reserved */
  1169. ushort reserved38; /* 38 reserved */
  1170. ushort reserved39; /* 39 reserved */
  1171. ushort reserved40; /* 40 reserved */
  1172. ushort reserved41; /* 41 reserved */
  1173. ushort reserved42; /* 42 reserved */
  1174. ushort reserved43; /* 43 reserved */
  1175. ushort reserved44; /* 44 reserved */
  1176. ushort reserved45; /* 45 reserved */
  1177. ushort reserved46; /* 46 reserved */
  1178. ushort reserved47; /* 47 reserved */
  1179. ushort reserved48; /* 48 reserved */
  1180. ushort reserved49; /* 49 reserved */
  1181. ushort reserved50; /* 50 reserved */
  1182. ushort reserved51; /* 51 reserved */
  1183. ushort reserved52; /* 52 reserved */
  1184. ushort reserved53; /* 53 reserved */
  1185. ushort reserved54; /* 54 reserved */
  1186. ushort reserved55; /* 55 reserved */
  1187. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1188. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1189. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1190. ushort subsysid; /* 59 SubSystem ID */
  1191. ushort reserved60; /* 60 reserved */
  1192. ushort reserved61; /* 61 reserved */
  1193. ushort reserved62; /* 62 reserved */
  1194. ushort reserved63; /* 63 reserved */
  1195. } ADVEEP_38C1600_CONFIG;
  1196. /*
  1197. * EEPROM Commands
  1198. */
  1199. #define ASC_EEP_CMD_DONE 0x0200
  1200. /* bios_ctrl */
  1201. #define BIOS_CTRL_BIOS 0x0001
  1202. #define BIOS_CTRL_EXTENDED_XLAT 0x0002
  1203. #define BIOS_CTRL_GT_2_DISK 0x0004
  1204. #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
  1205. #define BIOS_CTRL_BOOTABLE_CD 0x0010
  1206. #define BIOS_CTRL_MULTIPLE_LUN 0x0040
  1207. #define BIOS_CTRL_DISPLAY_MSG 0x0080
  1208. #define BIOS_CTRL_NO_SCAM 0x0100
  1209. #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
  1210. #define BIOS_CTRL_INIT_VERBOSE 0x0800
  1211. #define BIOS_CTRL_SCSI_PARITY 0x1000
  1212. #define BIOS_CTRL_AIPP_DIS 0x2000
  1213. #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
  1214. #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1215. /*
  1216. * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
  1217. * a special 16K Adv Library and Microcode version. After the issue is
  1218. * resolved, should restore 32K support.
  1219. *
  1220. * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
  1221. */
  1222. #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1223. /*
  1224. * Byte I/O register address from base of 'iop_base'.
  1225. */
  1226. #define IOPB_INTR_STATUS_REG 0x00
  1227. #define IOPB_CHIP_ID_1 0x01
  1228. #define IOPB_INTR_ENABLES 0x02
  1229. #define IOPB_CHIP_TYPE_REV 0x03
  1230. #define IOPB_RES_ADDR_4 0x04
  1231. #define IOPB_RES_ADDR_5 0x05
  1232. #define IOPB_RAM_DATA 0x06
  1233. #define IOPB_RES_ADDR_7 0x07
  1234. #define IOPB_FLAG_REG 0x08
  1235. #define IOPB_RES_ADDR_9 0x09
  1236. #define IOPB_RISC_CSR 0x0A
  1237. #define IOPB_RES_ADDR_B 0x0B
  1238. #define IOPB_RES_ADDR_C 0x0C
  1239. #define IOPB_RES_ADDR_D 0x0D
  1240. #define IOPB_SOFT_OVER_WR 0x0E
  1241. #define IOPB_RES_ADDR_F 0x0F
  1242. #define IOPB_MEM_CFG 0x10
  1243. #define IOPB_RES_ADDR_11 0x11
  1244. #define IOPB_GPIO_DATA 0x12
  1245. #define IOPB_RES_ADDR_13 0x13
  1246. #define IOPB_FLASH_PAGE 0x14
  1247. #define IOPB_RES_ADDR_15 0x15
  1248. #define IOPB_GPIO_CNTL 0x16
  1249. #define IOPB_RES_ADDR_17 0x17
  1250. #define IOPB_FLASH_DATA 0x18
  1251. #define IOPB_RES_ADDR_19 0x19
  1252. #define IOPB_RES_ADDR_1A 0x1A
  1253. #define IOPB_RES_ADDR_1B 0x1B
  1254. #define IOPB_RES_ADDR_1C 0x1C
  1255. #define IOPB_RES_ADDR_1D 0x1D
  1256. #define IOPB_RES_ADDR_1E 0x1E
  1257. #define IOPB_RES_ADDR_1F 0x1F
  1258. #define IOPB_DMA_CFG0 0x20
  1259. #define IOPB_DMA_CFG1 0x21
  1260. #define IOPB_TICKLE 0x22
  1261. #define IOPB_DMA_REG_WR 0x23
  1262. #define IOPB_SDMA_STATUS 0x24
  1263. #define IOPB_SCSI_BYTE_CNT 0x25
  1264. #define IOPB_HOST_BYTE_CNT 0x26
  1265. #define IOPB_BYTE_LEFT_TO_XFER 0x27
  1266. #define IOPB_BYTE_TO_XFER_0 0x28
  1267. #define IOPB_BYTE_TO_XFER_1 0x29
  1268. #define IOPB_BYTE_TO_XFER_2 0x2A
  1269. #define IOPB_BYTE_TO_XFER_3 0x2B
  1270. #define IOPB_ACC_GRP 0x2C
  1271. #define IOPB_RES_ADDR_2D 0x2D
  1272. #define IOPB_DEV_ID 0x2E
  1273. #define IOPB_RES_ADDR_2F 0x2F
  1274. #define IOPB_SCSI_DATA 0x30
  1275. #define IOPB_RES_ADDR_31 0x31
  1276. #define IOPB_RES_ADDR_32 0x32
  1277. #define IOPB_SCSI_DATA_HSHK 0x33
  1278. #define IOPB_SCSI_CTRL 0x34
  1279. #define IOPB_RES_ADDR_35 0x35
  1280. #define IOPB_RES_ADDR_36 0x36
  1281. #define IOPB_RES_ADDR_37 0x37
  1282. #define IOPB_RAM_BIST 0x38
  1283. #define IOPB_PLL_TEST 0x39
  1284. #define IOPB_PCI_INT_CFG 0x3A
  1285. #define IOPB_RES_ADDR_3B 0x3B
  1286. #define IOPB_RFIFO_CNT 0x3C
  1287. #define IOPB_RES_ADDR_3D 0x3D
  1288. #define IOPB_RES_ADDR_3E 0x3E
  1289. #define IOPB_RES_ADDR_3F 0x3F
  1290. /*
  1291. * Word I/O register address from base of 'iop_base'.
  1292. */
  1293. #define IOPW_CHIP_ID_0 0x00 /* CID0 */
  1294. #define IOPW_CTRL_REG 0x02 /* CC */
  1295. #define IOPW_RAM_ADDR 0x04 /* LA */
  1296. #define IOPW_RAM_DATA 0x06 /* LD */
  1297. #define IOPW_RES_ADDR_08 0x08
  1298. #define IOPW_RISC_CSR 0x0A /* CSR */
  1299. #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
  1300. #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
  1301. #define IOPW_RES_ADDR_10 0x10
  1302. #define IOPW_SEL_MASK 0x12 /* SM */
  1303. #define IOPW_RES_ADDR_14 0x14
  1304. #define IOPW_FLASH_ADDR 0x16 /* FA */
  1305. #define IOPW_RES_ADDR_18 0x18
  1306. #define IOPW_EE_CMD 0x1A /* EC */
  1307. #define IOPW_EE_DATA 0x1C /* ED */
  1308. #define IOPW_SFIFO_CNT 0x1E /* SFC */
  1309. #define IOPW_RES_ADDR_20 0x20
  1310. #define IOPW_Q_BASE 0x22 /* QB */
  1311. #define IOPW_QP 0x24 /* QP */
  1312. #define IOPW_IX 0x26 /* IX */
  1313. #define IOPW_SP 0x28 /* SP */
  1314. #define IOPW_PC 0x2A /* PC */
  1315. #define IOPW_RES_ADDR_2C 0x2C
  1316. #define IOPW_RES_ADDR_2E 0x2E
  1317. #define IOPW_SCSI_DATA 0x30 /* SD */
  1318. #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
  1319. #define IOPW_SCSI_CTRL 0x34 /* SC */
  1320. #define IOPW_HSHK_CFG 0x36 /* HCFG */
  1321. #define IOPW_SXFR_STATUS 0x36 /* SXS */
  1322. #define IOPW_SXFR_CNTL 0x38 /* SXL */
  1323. #define IOPW_SXFR_CNTH 0x3A /* SXH */
  1324. #define IOPW_RES_ADDR_3C 0x3C
  1325. #define IOPW_RFIFO_DATA 0x3E /* RFD */
  1326. /*
  1327. * Doubleword I/O register address from base of 'iop_base'.
  1328. */
  1329. #define IOPDW_RES_ADDR_0 0x00
  1330. #define IOPDW_RAM_DATA 0x04
  1331. #define IOPDW_RES_ADDR_8 0x08
  1332. #define IOPDW_RES_ADDR_C 0x0C
  1333. #define IOPDW_RES_ADDR_10 0x10
  1334. #define IOPDW_COMMA 0x14
  1335. #define IOPDW_COMMB 0x18
  1336. #define IOPDW_RES_ADDR_1C 0x1C
  1337. #define IOPDW_SDMA_ADDR0 0x20
  1338. #define IOPDW_SDMA_ADDR1 0x24
  1339. #define IOPDW_SDMA_COUNT 0x28
  1340. #define IOPDW_SDMA_ERROR 0x2C
  1341. #define IOPDW_RDMA_ADDR0 0x30
  1342. #define IOPDW_RDMA_ADDR1 0x34
  1343. #define IOPDW_RDMA_COUNT 0x38
  1344. #define IOPDW_RDMA_ERROR 0x3C
  1345. #define ADV_CHIP_ID_BYTE 0x25
  1346. #define ADV_CHIP_ID_WORD 0x04C1
  1347. #define ADV_INTR_ENABLE_HOST_INTR 0x01
  1348. #define ADV_INTR_ENABLE_SEL_INTR 0x02
  1349. #define ADV_INTR_ENABLE_DPR_INTR 0x04
  1350. #define ADV_INTR_ENABLE_RTA_INTR 0x08
  1351. #define ADV_INTR_ENABLE_RMA_INTR 0x10
  1352. #define ADV_INTR_ENABLE_RST_INTR 0x20
  1353. #define ADV_INTR_ENABLE_DPE_INTR 0x40
  1354. #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
  1355. #define ADV_INTR_STATUS_INTRA 0x01
  1356. #define ADV_INTR_STATUS_INTRB 0x02
  1357. #define ADV_INTR_STATUS_INTRC 0x04
  1358. #define ADV_RISC_CSR_STOP (0x0000)
  1359. #define ADV_RISC_TEST_COND (0x2000)
  1360. #define ADV_RISC_CSR_RUN (0x4000)
  1361. #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
  1362. #define ADV_CTRL_REG_HOST_INTR 0x0100
  1363. #define ADV_CTRL_REG_SEL_INTR 0x0200
  1364. #define ADV_CTRL_REG_DPR_INTR 0x0400
  1365. #define ADV_CTRL_REG_RTA_INTR 0x0800
  1366. #define ADV_CTRL_REG_RMA_INTR 0x1000
  1367. #define ADV_CTRL_REG_RES_BIT14 0x2000
  1368. #define ADV_CTRL_REG_DPE_INTR 0x4000
  1369. #define ADV_CTRL_REG_POWER_DONE 0x8000
  1370. #define ADV_CTRL_REG_ANY_INTR 0xFF00
  1371. #define ADV_CTRL_REG_CMD_RESET 0x00C6
  1372. #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
  1373. #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
  1374. #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
  1375. #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
  1376. #define ADV_TICKLE_NOP 0x00
  1377. #define ADV_TICKLE_A 0x01
  1378. #define ADV_TICKLE_B 0x02
  1379. #define ADV_TICKLE_C 0x03
  1380. #define AdvIsIntPending(port) \
  1381. (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
  1382. /*
  1383. * SCSI_CFG0 Register bit definitions
  1384. */
  1385. #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
  1386. #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
  1387. #define EVEN_PARITY 0x1000 /* Select Even Parity */
  1388. #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
  1389. #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
  1390. #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
  1391. #define SCAM_EN 0x0080 /* Enable SCAM selection */
  1392. #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
  1393. #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
  1394. #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
  1395. #define OUR_ID 0x000F /* SCSI ID */
  1396. /*
  1397. * SCSI_CFG1 Register bit definitions
  1398. */
  1399. #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
  1400. #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
  1401. #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
  1402. #define FILTER_SEL 0x0C00 /* Filter Period Selection */
  1403. #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
  1404. #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
  1405. #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
  1406. #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
  1407. #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
  1408. #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
  1409. #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
  1410. #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
  1411. #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
  1412. #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
  1413. #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
  1414. /*
  1415. * Addendum for ASC-38C0800 Chip
  1416. *
  1417. * The ASC-38C1600 Chip uses the same definitions except that the
  1418. * bus mode override bits [12:10] have been moved to byte register
  1419. * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
  1420. * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
  1421. * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
  1422. * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
  1423. * and [1:0]. Bits [14], [7:6], [3:2] are unused.
  1424. */
  1425. #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
  1426. #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
  1427. #define HVD 0x1000 /* HVD Device Detect */
  1428. #define LVD 0x0800 /* LVD Device Detect */
  1429. #define SE 0x0400 /* SE Device Detect */
  1430. #define TERM_LVD 0x00C0 /* LVD Termination Bits */
  1431. #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
  1432. #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
  1433. #define TERM_SE 0x0030 /* SE Termination Bits */
  1434. #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
  1435. #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
  1436. #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
  1437. #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
  1438. #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
  1439. #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
  1440. #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
  1441. #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
  1442. #define CABLE_ILLEGAL_A 0x7
  1443. /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
  1444. #define CABLE_ILLEGAL_B 0xB
  1445. /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
  1446. /*
  1447. * MEM_CFG Register bit definitions
  1448. */
  1449. #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
  1450. #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
  1451. #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
  1452. #define RAM_SZ_2KB 0x00 /* 2 KB */
  1453. #define RAM_SZ_4KB 0x04 /* 4 KB */
  1454. #define RAM_SZ_8KB 0x08 /* 8 KB */
  1455. #define RAM_SZ_16KB 0x0C /* 16 KB */
  1456. #define RAM_SZ_32KB 0x10 /* 32 KB */
  1457. #define RAM_SZ_64KB 0x14 /* 64 KB */
  1458. /*
  1459. * DMA_CFG0 Register bit definitions
  1460. *
  1461. * This register is only accessible to the host.
  1462. */
  1463. #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
  1464. #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
  1465. #define FIFO_THRESH_16B 0x00 /* 16 bytes */
  1466. #define FIFO_THRESH_32B 0x20 /* 32 bytes */
  1467. #define FIFO_THRESH_48B 0x30 /* 48 bytes */
  1468. #define FIFO_THRESH_64B 0x40 /* 64 bytes */
  1469. #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
  1470. #define FIFO_THRESH_96B 0x60 /* 96 bytes */
  1471. #define FIFO_THRESH_112B 0x70 /* 112 bytes */
  1472. #define START_CTL 0x0C /* DMA start conditions */
  1473. #define START_CTL_TH 0x00 /* Wait threshold level (default) */
  1474. #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
  1475. #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
  1476. #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
  1477. #define READ_CMD 0x03 /* Memory Read Method */
  1478. #define READ_CMD_MR 0x00 /* Memory Read */
  1479. #define READ_CMD_MRL 0x02 /* Memory Read Long */
  1480. #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
  1481. /*
  1482. * ASC-38C0800 RAM BIST Register bit definitions
  1483. */
  1484. #define RAM_TEST_MODE 0x80
  1485. #define PRE_TEST_MODE 0x40
  1486. #define NORMAL_MODE 0x00
  1487. #define RAM_TEST_DONE 0x10
  1488. #define RAM_TEST_STATUS 0x0F
  1489. #define RAM_TEST_HOST_ERROR 0x08
  1490. #define RAM_TEST_INTRAM_ERROR 0x04
  1491. #define RAM_TEST_RISC_ERROR 0x02
  1492. #define RAM_TEST_SCSI_ERROR 0x01
  1493. #define RAM_TEST_SUCCESS 0x00
  1494. #define PRE_TEST_VALUE 0x05
  1495. #define NORMAL_VALUE 0x00
  1496. /*
  1497. * ASC38C1600 Definitions
  1498. *
  1499. * IOPB_PCI_INT_CFG Bit Field Definitions
  1500. */
  1501. #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
  1502. /*
  1503. * Bit 1 can be set to change the interrupt for the Function to operate in
  1504. * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
  1505. * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
  1506. * mode, otherwise the operating mode is undefined.
  1507. */
  1508. #define TOTEMPOLE 0x02
  1509. /*
  1510. * Bit 0 can be used to change the Int Pin for the Function. The value is
  1511. * 0 by default for both Functions with Function 0 using INT A and Function
  1512. * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
  1513. * INT A is used.
  1514. *
  1515. * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
  1516. * value specified in the PCI Configuration Space.
  1517. */
  1518. #define INTAB 0x01
  1519. /*
  1520. * Adv Library Status Definitions
  1521. */
  1522. #define ADV_TRUE 1
  1523. #define ADV_FALSE 0
  1524. #define ADV_SUCCESS 1
  1525. #define ADV_BUSY 0
  1526. #define ADV_ERROR (-1)
  1527. /*
  1528. * ADV_DVC_VAR 'warn_code' values
  1529. */
  1530. #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
  1531. #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
  1532. #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
  1533. #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
  1534. #define ADV_MAX_TID 15 /* max. target identifier */
  1535. #define ADV_MAX_LUN 7 /* max. logical unit number */
  1536. /*
  1537. * Fixed locations of microcode operating variables.
  1538. */
  1539. #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
  1540. #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
  1541. #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
  1542. #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
  1543. #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
  1544. #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
  1545. #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
  1546. #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
  1547. #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
  1548. #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
  1549. #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
  1550. #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
  1551. #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
  1552. #define ASC_MC_CHIP_TYPE 0x009A
  1553. #define ASC_MC_INTRB_CODE 0x009B
  1554. #define ASC_MC_WDTR_ABLE 0x009C
  1555. #define ASC_MC_SDTR_ABLE 0x009E
  1556. #define ASC_MC_TAGQNG_ABLE 0x00A0
  1557. #define ASC_MC_DISC_ENABLE 0x00A2
  1558. #define ASC_MC_IDLE_CMD_STATUS 0x00A4
  1559. #define ASC_MC_IDLE_CMD 0x00A6
  1560. #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
  1561. #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
  1562. #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
  1563. #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
  1564. #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
  1565. #define ASC_MC_SDTR_DONE 0x00B6
  1566. #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
  1567. #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
  1568. #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
  1569. #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
  1570. #define ASC_MC_WDTR_DONE 0x0124
  1571. #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
  1572. #define ASC_MC_ICQ 0x0160
  1573. #define ASC_MC_IRQ 0x0164
  1574. #define ASC_MC_PPR_ABLE 0x017A
  1575. /*
  1576. * BIOS LRAM variable absolute offsets.
  1577. */
  1578. #define BIOS_CODESEG 0x54
  1579. #define BIOS_CODELEN 0x56
  1580. #define BIOS_SIGNATURE 0x58
  1581. #define BIOS_VERSION 0x5A
  1582. /*
  1583. * Microcode Control Flags
  1584. *
  1585. * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
  1586. * and handled by the microcode.
  1587. */
  1588. #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
  1589. #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
  1590. /*
  1591. * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
  1592. */
  1593. #define HSHK_CFG_WIDE_XFR 0x8000
  1594. #define HSHK_CFG_RATE 0x0F00
  1595. #define HSHK_CFG_OFFSET 0x001F
  1596. #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
  1597. #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
  1598. #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
  1599. #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
  1600. #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
  1601. #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
  1602. #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
  1603. #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
  1604. #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
  1605. #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
  1606. #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
  1607. #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
  1608. #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
  1609. #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
  1610. /*
  1611. * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
  1612. * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
  1613. */
  1614. #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
  1615. #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
  1616. /*
  1617. * All fields here are accessed by the board microcode and need to be
  1618. * little-endian.
  1619. */
  1620. typedef struct adv_carr_t {
  1621. ADV_VADDR carr_va; /* Carrier Virtual Address */
  1622. ADV_PADDR carr_pa; /* Carrier Physical Address */
  1623. ADV_VADDR areq_vpa; /* ASC_SCSI_REQ_Q Virtual or Physical Address */
  1624. /*
  1625. * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
  1626. *
  1627. * next_vpa [3:1] Reserved Bits
  1628. * next_vpa [0] Done Flag set in Response Queue.
  1629. */
  1630. ADV_VADDR next_vpa;
  1631. } ADV_CARR_T;
  1632. /*
  1633. * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
  1634. */
  1635. #define ASC_NEXT_VPA_MASK 0xFFFFFFF0
  1636. #define ASC_RQ_DONE 0x00000001
  1637. #define ASC_RQ_GOOD 0x00000002
  1638. #define ASC_CQ_STOPPER 0x00000000
  1639. #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
  1640. #define ADV_CARRIER_NUM_PAGE_CROSSING \
  1641. (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + (PAGE_SIZE - 1))/PAGE_SIZE)
  1642. #define ADV_CARRIER_BUFSIZE \
  1643. ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
  1644. /*
  1645. * ASC_SCSI_REQ_Q 'a_flag' definitions
  1646. *
  1647. * The Adv Library should limit use to the lower nibble (4 bits) of
  1648. * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
  1649. */
  1650. #define ADV_POLL_REQUEST 0x01 /* poll for request completion */
  1651. #define ADV_SCSIQ_DONE 0x02 /* request done */
  1652. #define ADV_DONT_RETRY 0x08 /* don't do retry */
  1653. #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
  1654. #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
  1655. #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
  1656. /*
  1657. * Adapter temporary configuration structure
  1658. *
  1659. * This structure can be discarded after initialization. Don't add
  1660. * fields here needed after initialization.
  1661. *
  1662. * Field naming convention:
  1663. *
  1664. * *_enable indicates the field enables or disables a feature. The
  1665. * value of the field is never reset.
  1666. */
  1667. typedef struct adv_dvc_cfg {
  1668. ushort disc_enable; /* enable disconnection */
  1669. uchar chip_version; /* chip version */
  1670. uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
  1671. ushort control_flag; /* Microcode Control Flag */
  1672. ushort mcode_date; /* Microcode date */
  1673. ushort mcode_version; /* Microcode version */
  1674. ushort serial1; /* EEPROM serial number word 1 */
  1675. ushort serial2; /* EEPROM serial number word 2 */
  1676. ushort serial3; /* EEPROM serial number word 3 */
  1677. } ADV_DVC_CFG;
  1678. struct adv_dvc_var;
  1679. struct adv_scsi_req_q;
  1680. typedef struct asc_sg_block {
  1681. uchar reserved1;
  1682. uchar reserved2;
  1683. uchar reserved3;
  1684. uchar sg_cnt; /* Valid entries in block. */
  1685. ADV_PADDR sg_ptr; /* Pointer to next sg block. */
  1686. struct {
  1687. ADV_PADDR sg_addr; /* SG element address. */
  1688. ADV_DCNT sg_count; /* SG element count. */
  1689. } sg_list[NO_OF_SG_PER_BLOCK];
  1690. } ADV_SG_BLOCK;
  1691. /*
  1692. * ADV_SCSI_REQ_Q - microcode request structure
  1693. *
  1694. * All fields in this structure up to byte 60 are used by the microcode.
  1695. * The microcode makes assumptions about the size and ordering of fields
  1696. * in this structure. Do not change the structure definition here without
  1697. * coordinating the change with the microcode.
  1698. *
  1699. * All fields accessed by microcode must be maintained in little_endian
  1700. * order.
  1701. */
  1702. typedef struct adv_scsi_req_q {
  1703. uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
  1704. uchar target_cmd;
  1705. uchar target_id; /* Device target identifier. */
  1706. uchar target_lun; /* Device target logical unit number. */
  1707. ADV_PADDR data_addr; /* Data buffer physical address. */
  1708. ADV_DCNT data_cnt; /* Data count. Ucode sets to residual. */
  1709. ADV_PADDR sense_addr;
  1710. ADV_PADDR carr_pa;
  1711. uchar mflag;
  1712. uchar sense_len;
  1713. uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
  1714. uchar scsi_cntl;
  1715. uchar done_status; /* Completion status. */
  1716. uchar scsi_status; /* SCSI status byte. */
  1717. uchar host_status; /* Ucode host status. */
  1718. uchar sg_working_ix;
  1719. uchar cdb[12]; /* SCSI CDB bytes 0-11. */
  1720. ADV_PADDR sg_real_addr; /* SG list physical address. */
  1721. ADV_PADDR scsiq_rptr;
  1722. uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
  1723. ADV_VADDR scsiq_ptr;
  1724. ADV_VADDR carr_va;
  1725. /*
  1726. * End of microcode structure - 60 bytes. The rest of the structure
  1727. * is used by the Adv Library and ignored by the microcode.
  1728. */
  1729. ADV_VADDR srb_ptr;
  1730. ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
  1731. char *vdata_addr; /* Data buffer virtual address. */
  1732. uchar a_flag;
  1733. uchar pad[2]; /* Pad out to a word boundary. */
  1734. } ADV_SCSI_REQ_Q;
  1735. /*
  1736. * The following two structures are used to process Wide Board requests.
  1737. *
  1738. * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
  1739. * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
  1740. * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
  1741. * Mid-Level SCSI request structure.
  1742. *
  1743. * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
  1744. * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
  1745. * up to 255 scatter-gather elements may be used per request or
  1746. * ADV_SCSI_REQ_Q.
  1747. *
  1748. * Both structures must be 32 byte aligned.
  1749. */
  1750. typedef struct adv_sgblk {
  1751. ADV_SG_BLOCK sg_block; /* Sgblock structure. */
  1752. uchar align[32]; /* Sgblock structure padding. */
  1753. struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
  1754. } adv_sgblk_t;
  1755. typedef struct adv_req {
  1756. ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
  1757. uchar align[32]; /* Request structure padding. */
  1758. struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
  1759. adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
  1760. struct adv_req *next_reqp; /* Next Request Structure. */
  1761. } adv_req_t;
  1762. /*
  1763. * Adapter operation variable structure.
  1764. *
  1765. * One structure is required per host adapter.
  1766. *
  1767. * Field naming convention:
  1768. *
  1769. * *_able indicates both whether a feature should be enabled or disabled
  1770. * and whether a device isi capable of the feature. At initialization
  1771. * this field may be set, but later if a device is found to be incapable
  1772. * of the feature, the field is cleared.
  1773. */
  1774. typedef struct adv_dvc_var {
  1775. AdvPortAddr iop_base; /* I/O port address */
  1776. ushort err_code; /* fatal error code */
  1777. ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
  1778. ushort wdtr_able; /* try WDTR for a device */
  1779. ushort sdtr_able; /* try SDTR for a device */
  1780. ushort ultra_able; /* try SDTR Ultra speed for a device */
  1781. ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
  1782. ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
  1783. ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
  1784. ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
  1785. ushort tagqng_able; /* try tagged queuing with a device */
  1786. ushort ppr_able; /* PPR message capable per TID bitmask. */
  1787. uchar max_dvc_qng; /* maximum number of tagged commands per device */
  1788. ushort start_motor; /* start motor command allowed */
  1789. uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
  1790. uchar chip_no; /* should be assigned by caller */
  1791. uchar max_host_qng; /* maximum number of Q'ed command allowed */
  1792. ushort no_scam; /* scam_tolerant of EEPROM */
  1793. struct asc_board *drv_ptr; /* driver pointer to private structure */
  1794. uchar chip_scsi_id; /* chip SCSI target ID */
  1795. uchar chip_type;
  1796. uchar bist_err_code;
  1797. ADV_CARR_T *carrier_buf;
  1798. ADV_CARR_T *carr_freelist; /* Carrier free list. */
  1799. ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
  1800. ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
  1801. ushort carr_pending_cnt; /* Count of pending carriers. */
  1802. struct adv_req *orig_reqp; /* adv_req_t memory block. */
  1803. /*
  1804. * Note: The following fields will not be used after initialization. The
  1805. * driver may discard the buffer after initialization is done.
  1806. */
  1807. ADV_DVC_CFG *cfg; /* temporary configuration structure */
  1808. } ADV_DVC_VAR;
  1809. /*
  1810. * Microcode idle loop commands
  1811. */
  1812. #define IDLE_CMD_COMPLETED 0
  1813. #define IDLE_CMD_STOP_CHIP 0x0001
  1814. #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
  1815. #define IDLE_CMD_SEND_INT 0x0004
  1816. #define IDLE_CMD_ABORT 0x0008
  1817. #define IDLE_CMD_DEVICE_RESET 0x0010
  1818. #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
  1819. #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
  1820. #define IDLE_CMD_SCSIREQ 0x0080
  1821. #define IDLE_CMD_STATUS_SUCCESS 0x0001
  1822. #define IDLE_CMD_STATUS_FAILURE 0x0002
  1823. /*
  1824. * AdvSendIdleCmd() flag definitions.
  1825. */
  1826. #define ADV_NOWAIT 0x01
  1827. /*
  1828. * Wait loop time out values.
  1829. */
  1830. #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
  1831. #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
  1832. #define SCSI_MAX_RETRY 10 /* retry count */
  1833. #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
  1834. #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
  1835. #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
  1836. #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
  1837. #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
  1838. /* Read byte from a register. */
  1839. #define AdvReadByteRegister(iop_base, reg_off) \
  1840. (ADV_MEM_READB((iop_base) + (reg_off)))
  1841. /* Write byte to a register. */
  1842. #define AdvWriteByteRegister(iop_base, reg_off, byte) \
  1843. (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
  1844. /* Read word (2 bytes) from a register. */
  1845. #define AdvReadWordRegister(iop_base, reg_off) \
  1846. (ADV_MEM_READW((iop_base) + (reg_off)))
  1847. /* Write word (2 bytes) to a register. */
  1848. #define AdvWriteWordRegister(iop_base, reg_off, word) \
  1849. (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
  1850. /* Write dword (4 bytes) to a register. */
  1851. #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
  1852. (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
  1853. /* Read byte from LRAM. */
  1854. #define AdvReadByteLram(iop_base, addr, byte) \
  1855. do { \
  1856. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1857. (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
  1858. } while (0)
  1859. /* Write byte to LRAM. */
  1860. #define AdvWriteByteLram(iop_base, addr, byte) \
  1861. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1862. ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
  1863. /* Read word (2 bytes) from LRAM. */
  1864. #define AdvReadWordLram(iop_base, addr, word) \
  1865. do { \
  1866. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1867. (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
  1868. } while (0)
  1869. /* Write word (2 bytes) to LRAM. */
  1870. #define AdvWriteWordLram(iop_base, addr, word) \
  1871. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1872. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1873. /* Write little-endian double word (4 bytes) to LRAM */
  1874. /* Because of unspecified C language ordering don't use auto-increment. */
  1875. #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
  1876. ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1877. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1878. cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
  1879. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
  1880. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1881. cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
  1882. /* Read word (2 bytes) from LRAM assuming that the address is already set. */
  1883. #define AdvReadWordAutoIncLram(iop_base) \
  1884. (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
  1885. /* Write word (2 bytes) to LRAM assuming that the address is already set. */
  1886. #define AdvWriteWordAutoIncLram(iop_base, word) \
  1887. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1888. /*
  1889. * Define macro to check for Condor signature.
  1890. *
  1891. * Evaluate to ADV_TRUE if a Condor chip is found the specified port
  1892. * address 'iop_base'. Otherwise evalue to ADV_FALSE.
  1893. */
  1894. #define AdvFindSignature(iop_base) \
  1895. (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
  1896. ADV_CHIP_ID_BYTE) && \
  1897. (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
  1898. ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
  1899. /*
  1900. * Define macro to Return the version number of the chip at 'iop_base'.
  1901. *
  1902. * The second parameter 'bus_type' is currently unused.
  1903. */
  1904. #define AdvGetChipVersion(iop_base, bus_type) \
  1905. AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
  1906. /*
  1907. * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
  1908. * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
  1909. *
  1910. * If the request has not yet been sent to the device it will simply be
  1911. * aborted from RISC memory. If the request is disconnected it will be
  1912. * aborted on reselection by sending an Abort Message to the target ID.
  1913. *
  1914. * Return value:
  1915. * ADV_TRUE(1) - Queue was successfully aborted.
  1916. * ADV_FALSE(0) - Queue was not found on the active queue list.
  1917. */
  1918. #define AdvAbortQueue(asc_dvc, scsiq) \
  1919. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
  1920. (ADV_DCNT) (scsiq))
  1921. /*
  1922. * Send a Bus Device Reset Message to the specified target ID.
  1923. *
  1924. * All outstanding commands will be purged if sending the
  1925. * Bus Device Reset Message is successful.
  1926. *
  1927. * Return Value:
  1928. * ADV_TRUE(1) - All requests on the target are purged.
  1929. * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
  1930. * are not purged.
  1931. */
  1932. #define AdvResetDevice(asc_dvc, target_id) \
  1933. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
  1934. (ADV_DCNT) (target_id))
  1935. /*
  1936. * SCSI Wide Type definition.
  1937. */
  1938. #define ADV_SCSI_BIT_ID_TYPE ushort
  1939. /*
  1940. * AdvInitScsiTarget() 'cntl_flag' options.
  1941. */
  1942. #define ADV_SCAN_LUN 0x01
  1943. #define ADV_CAPINFO_NOLUN 0x02
  1944. /*
  1945. * Convert target id to target id bit mask.
  1946. */
  1947. #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
  1948. /*
  1949. * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
  1950. */
  1951. #define QD_NO_STATUS 0x00 /* Request not completed yet. */
  1952. #define QD_NO_ERROR 0x01
  1953. #define QD_ABORTED_BY_HOST 0x02
  1954. #define QD_WITH_ERROR 0x04
  1955. #define QHSTA_NO_ERROR 0x00
  1956. #define QHSTA_M_SEL_TIMEOUT 0x11
  1957. #define QHSTA_M_DATA_OVER_RUN 0x12
  1958. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  1959. #define QHSTA_M_QUEUE_ABORTED 0x15
  1960. #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
  1961. #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
  1962. #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
  1963. #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
  1964. #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
  1965. #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
  1966. #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
  1967. /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
  1968. #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
  1969. #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
  1970. #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
  1971. #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
  1972. #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
  1973. #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
  1974. #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
  1975. #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
  1976. #define QHSTA_M_WTM_TIMEOUT 0x41
  1977. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  1978. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  1979. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  1980. #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
  1981. #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
  1982. #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
  1983. /* Return the address that is aligned at the next doubleword >= to 'addr'. */
  1984. #define ADV_8BALIGN(addr) (((ulong) (addr) + 0x7) & ~0x7)
  1985. #define ADV_16BALIGN(addr) (((ulong) (addr) + 0xF) & ~0xF)
  1986. #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
  1987. /*
  1988. * Total contiguous memory needed for driver SG blocks.
  1989. *
  1990. * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
  1991. * number of scatter-gather elements the driver supports in a
  1992. * single request.
  1993. */
  1994. #define ADV_SG_LIST_MAX_BYTE_SIZE \
  1995. (sizeof(ADV_SG_BLOCK) * \
  1996. ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
  1997. /* struct asc_board flags */
  1998. #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
  1999. #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
  2000. #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
  2001. #define ASC_INFO_SIZE 128 /* advansys_info() line size */
  2002. #ifdef CONFIG_PROC_FS
  2003. /* /proc/scsi/advansys/[0...] related definitions */
  2004. #define ASC_PRTBUF_SIZE 2048
  2005. #define ASC_PRTLINE_SIZE 160
  2006. #define ASC_PRT_NEXT() \
  2007. if (cp) { \
  2008. totlen += len; \
  2009. leftlen -= len; \
  2010. if (leftlen == 0) { \
  2011. return totlen; \
  2012. } \
  2013. cp += len; \
  2014. }
  2015. #endif /* CONFIG_PROC_FS */
  2016. /* Asc Library return codes */
  2017. #define ASC_TRUE 1
  2018. #define ASC_FALSE 0
  2019. #define ASC_NOERROR 1
  2020. #define ASC_BUSY 0
  2021. #define ASC_ERROR (-1)
  2022. /* struct scsi_cmnd function return codes */
  2023. #define STATUS_BYTE(byte) (byte)
  2024. #define MSG_BYTE(byte) ((byte) << 8)
  2025. #define HOST_BYTE(byte) ((byte) << 16)
  2026. #define DRIVER_BYTE(byte) ((byte) << 24)
  2027. #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
  2028. #ifndef ADVANSYS_STATS
  2029. #define ASC_STATS_ADD(shost, counter, count)
  2030. #else /* ADVANSYS_STATS */
  2031. #define ASC_STATS_ADD(shost, counter, count) \
  2032. (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
  2033. #endif /* ADVANSYS_STATS */
  2034. /* If the result wraps when calculating tenths, return 0. */
  2035. #define ASC_TENTHS(num, den) \
  2036. (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
  2037. 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
  2038. /*
  2039. * Display a message to the console.
  2040. */
  2041. #define ASC_PRINT(s) \
  2042. { \
  2043. printk("advansys: "); \
  2044. printk(s); \
  2045. }
  2046. #define ASC_PRINT1(s, a1) \
  2047. { \
  2048. printk("advansys: "); \
  2049. printk((s), (a1)); \
  2050. }
  2051. #define ASC_PRINT2(s, a1, a2) \
  2052. { \
  2053. printk("advansys: "); \
  2054. printk((s), (a1), (a2)); \
  2055. }
  2056. #define ASC_PRINT3(s, a1, a2, a3) \
  2057. { \
  2058. printk("advansys: "); \
  2059. printk((s), (a1), (a2), (a3)); \
  2060. }
  2061. #define ASC_PRINT4(s, a1, a2, a3, a4) \
  2062. { \
  2063. printk("advansys: "); \
  2064. printk((s), (a1), (a2), (a3), (a4)); \
  2065. }
  2066. #ifndef ADVANSYS_DEBUG
  2067. #define ASC_DBG(lvl, s...)
  2068. #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
  2069. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
  2070. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  2071. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
  2072. #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  2073. #define ASC_DBG_PRT_HEX(lvl, name, start, length)
  2074. #define ASC_DBG_PRT_CDB(lvl, cdb, len)
  2075. #define ASC_DBG_PRT_SENSE(lvl, sense, len)
  2076. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
  2077. #else /* ADVANSYS_DEBUG */
  2078. /*
  2079. * Debugging Message Levels:
  2080. * 0: Errors Only
  2081. * 1: High-Level Tracing
  2082. * 2-N: Verbose Tracing
  2083. */
  2084. #define ASC_DBG(lvl, format, arg...) { \
  2085. if (asc_dbglvl >= (lvl)) \
  2086. printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
  2087. __func__ , ## arg); \
  2088. }
  2089. #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
  2090. { \
  2091. if (asc_dbglvl >= (lvl)) { \
  2092. asc_prt_scsi_host(s); \
  2093. } \
  2094. }
  2095. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
  2096. { \
  2097. if (asc_dbglvl >= (lvl)) { \
  2098. asc_prt_asc_scsi_q(scsiqp); \
  2099. } \
  2100. }
  2101. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
  2102. { \
  2103. if (asc_dbglvl >= (lvl)) { \
  2104. asc_prt_asc_qdone_info(qdone); \
  2105. } \
  2106. }
  2107. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
  2108. { \
  2109. if (asc_dbglvl >= (lvl)) { \
  2110. asc_prt_adv_scsi_req_q(scsiqp); \
  2111. } \
  2112. }
  2113. #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
  2114. { \
  2115. if (asc_dbglvl >= (lvl)) { \
  2116. asc_prt_hex((name), (start), (length)); \
  2117. } \
  2118. }
  2119. #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
  2120. ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
  2121. #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
  2122. ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
  2123. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
  2124. ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
  2125. #endif /* ADVANSYS_DEBUG */
  2126. #ifdef ADVANSYS_STATS
  2127. /* Per board statistics structure */
  2128. struct asc_stats {
  2129. /* Driver Entrypoint Statistics */
  2130. ADV_DCNT queuecommand; /* # calls to advansys_queuecommand() */
  2131. ADV_DCNT reset; /* # calls to advansys_eh_bus_reset() */
  2132. ADV_DCNT biosparam; /* # calls to advansys_biosparam() */
  2133. ADV_DCNT interrupt; /* # advansys_interrupt() calls */
  2134. ADV_DCNT callback; /* # calls to asc/adv_isr_callback() */
  2135. ADV_DCNT done; /* # calls to request's scsi_done function */
  2136. ADV_DCNT build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
  2137. ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
  2138. ADV_DCNT adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
  2139. /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
  2140. ADV_DCNT exe_noerror; /* # ASC_NOERROR returns. */
  2141. ADV_DCNT exe_busy; /* # ASC_BUSY returns. */
  2142. ADV_DCNT exe_error; /* # ASC_ERROR returns. */
  2143. ADV_DCNT exe_unknown; /* # unknown returns. */
  2144. /* Data Transfer Statistics */
  2145. ADV_DCNT xfer_cnt; /* # I/O requests received */
  2146. ADV_DCNT xfer_elem; /* # scatter-gather elements */
  2147. ADV_DCNT xfer_sect; /* # 512-byte blocks */
  2148. };
  2149. #endif /* ADVANSYS_STATS */
  2150. /*
  2151. * Structure allocated for each board.
  2152. *
  2153. * This structure is allocated by scsi_host_alloc() at the end
  2154. * of the 'Scsi_Host' structure starting at the 'hostdata'
  2155. * field. It is guaranteed to be allocated from DMA-able memory.
  2156. */
  2157. struct asc_board {
  2158. struct device *dev;
  2159. uint flags; /* Board flags */
  2160. unsigned int irq;
  2161. union {
  2162. ASC_DVC_VAR asc_dvc_var; /* Narrow board */
  2163. ADV_DVC_VAR adv_dvc_var; /* Wide board */
  2164. } dvc_var;
  2165. union {
  2166. ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
  2167. ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
  2168. } dvc_cfg;
  2169. ushort asc_n_io_port; /* Number I/O ports. */
  2170. ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
  2171. ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
  2172. ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
  2173. ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
  2174. union {
  2175. ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
  2176. ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
  2177. ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
  2178. ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
  2179. } eep_config;
  2180. ulong last_reset; /* Saved last reset time */
  2181. /* /proc/scsi/advansys/[0...] */
  2182. char *prtbuf; /* /proc print buffer */
  2183. #ifdef ADVANSYS_STATS
  2184. struct asc_stats asc_stats; /* Board statistics */
  2185. #endif /* ADVANSYS_STATS */
  2186. /*
  2187. * The following fields are used only for Narrow Boards.
  2188. */
  2189. uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
  2190. /*
  2191. * The following fields are used only for Wide Boards.
  2192. */
  2193. void __iomem *ioremap_addr; /* I/O Memory remap address. */
  2194. ushort ioport; /* I/O Port address. */
  2195. adv_req_t *adv_reqp; /* Request structures. */
  2196. adv_sgblk_t *adv_sgblkp; /* Scatter-gather structures. */
  2197. ushort bios_signature; /* BIOS Signature. */
  2198. ushort bios_version; /* BIOS Version. */
  2199. ushort bios_codeseg; /* BIOS Code Segment. */
  2200. ushort bios_codelen; /* BIOS Code Segment Length. */
  2201. };
  2202. #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
  2203. dvc_var.asc_dvc_var)
  2204. #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
  2205. dvc_var.adv_dvc_var)
  2206. #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
  2207. #ifdef ADVANSYS_DEBUG
  2208. static int asc_dbglvl = 3;
  2209. /*
  2210. * asc_prt_asc_dvc_var()
  2211. */
  2212. static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
  2213. {
  2214. printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2215. printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
  2216. "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
  2217. printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
  2218. (unsigned)h->init_sdtr);
  2219. printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
  2220. "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
  2221. (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
  2222. (unsigned)h->chip_no);
  2223. printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
  2224. "%u,\n", (unsigned)h->queue_full_or_busy,
  2225. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2226. printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
  2227. "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
  2228. (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
  2229. (unsigned)h->in_critical_cnt);
  2230. printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
  2231. "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
  2232. (unsigned)h->init_state, (unsigned)h->no_scam,
  2233. (unsigned)h->pci_fix_asyn_xfer);
  2234. printk(" cfg 0x%lx\n", (ulong)h->cfg);
  2235. }
  2236. /*
  2237. * asc_prt_asc_dvc_cfg()
  2238. */
  2239. static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
  2240. {
  2241. printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2242. printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
  2243. h->can_tagged_qng, h->cmd_qng_enabled);
  2244. printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
  2245. h->disc_enable, h->sdtr_enable);
  2246. printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
  2247. "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
  2248. h->isa_dma_channel, h->chip_version);
  2249. printk(" mcode_date 0x%x, mcode_version %d\n",
  2250. h->mcode_date, h->mcode_version);
  2251. }
  2252. /*
  2253. * asc_prt_adv_dvc_var()
  2254. *
  2255. * Display an ADV_DVC_VAR structure.
  2256. */
  2257. static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
  2258. {
  2259. printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2260. printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
  2261. (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
  2262. printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
  2263. (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
  2264. printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
  2265. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2266. printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
  2267. (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
  2268. (ulong)h->carr_freelist);
  2269. printk(" icq_sp 0x%lx, irq_sp 0x%lx\n",
  2270. (ulong)h->icq_sp, (ulong)h->irq_sp);
  2271. printk(" no_scam 0x%x, tagqng_able 0x%x\n",
  2272. (unsigned)h->no_scam, (unsigned)h->tagqng_able);
  2273. printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
  2274. (unsigned)h->chip_scsi_id, (ulong)h->cfg);
  2275. }
  2276. /*
  2277. * asc_prt_adv_dvc_cfg()
  2278. *
  2279. * Display an ADV_DVC_CFG structure.
  2280. */
  2281. static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
  2282. {
  2283. printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2284. printk(" disc_enable 0x%x, termination 0x%x\n",
  2285. h->disc_enable, h->termination);
  2286. printk(" chip_version 0x%x, mcode_date 0x%x\n",
  2287. h->chip_version, h->mcode_date);
  2288. printk(" mcode_version 0x%x, control_flag 0x%x\n",
  2289. h->mcode_version, h->control_flag);
  2290. }
  2291. /*
  2292. * asc_prt_scsi_host()
  2293. */
  2294. static void asc_prt_scsi_host(struct Scsi_Host *s)
  2295. {
  2296. struct asc_board *boardp = shost_priv(s);
  2297. printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
  2298. printk(" host_busy %u, host_no %d, last_reset %d,\n",
  2299. s->host_busy, s->host_no, (unsigned)s->last_reset);
  2300. printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
  2301. (ulong)s->base, (ulong)s->io_port, boardp->irq);
  2302. printk(" dma_channel %d, this_id %d, can_queue %d,\n",
  2303. s->dma_channel, s->this_id, s->can_queue);
  2304. printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
  2305. s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
  2306. if (ASC_NARROW_BOARD(boardp)) {
  2307. asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
  2308. asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
  2309. } else {
  2310. asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
  2311. asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
  2312. }
  2313. }
  2314. /*
  2315. * asc_prt_hex()
  2316. *
  2317. * Print hexadecimal output in 4 byte groupings 32 bytes
  2318. * or 8 double-words per line.
  2319. */
  2320. static void asc_prt_hex(char *f, uchar *s, int l)
  2321. {
  2322. int i;
  2323. int j;
  2324. int k;
  2325. int m;
  2326. printk("%s: (%d bytes)\n", f, l);
  2327. for (i = 0; i < l; i += 32) {
  2328. /* Display a maximum of 8 double-words per line. */
  2329. if ((k = (l - i) / 4) >= 8) {
  2330. k = 8;
  2331. m = 0;
  2332. } else {
  2333. m = (l - i) % 4;
  2334. }
  2335. for (j = 0; j < k; j++) {
  2336. printk(" %2.2X%2.2X%2.2X%2.2X",
  2337. (unsigned)s[i + (j * 4)],
  2338. (unsigned)s[i + (j * 4) + 1],
  2339. (unsigned)s[i + (j * 4) + 2],
  2340. (unsigned)s[i + (j * 4) + 3]);
  2341. }
  2342. switch (m) {
  2343. case 0:
  2344. default:
  2345. break;
  2346. case 1:
  2347. printk(" %2.2X", (unsigned)s[i + (j * 4)]);
  2348. break;
  2349. case 2:
  2350. printk(" %2.2X%2.2X",
  2351. (unsigned)s[i + (j * 4)],
  2352. (unsigned)s[i + (j * 4) + 1]);
  2353. break;
  2354. case 3:
  2355. printk(" %2.2X%2.2X%2.2X",
  2356. (unsigned)s[i + (j * 4) + 1],
  2357. (unsigned)s[i + (j * 4) + 2],
  2358. (unsigned)s[i + (j * 4) + 3]);
  2359. break;
  2360. }
  2361. printk("\n");
  2362. }
  2363. }
  2364. /*
  2365. * asc_prt_asc_scsi_q()
  2366. */
  2367. static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
  2368. {
  2369. ASC_SG_HEAD *sgp;
  2370. int i;
  2371. printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
  2372. printk
  2373. (" target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
  2374. q->q2.target_ix, q->q1.target_lun, (ulong)q->q2.srb_ptr,
  2375. q->q2.tag_code);
  2376. printk
  2377. (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2378. (ulong)le32_to_cpu(q->q1.data_addr),
  2379. (ulong)le32_to_cpu(q->q1.data_cnt),
  2380. (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
  2381. printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
  2382. (ulong)q->cdbptr, q->q2.cdb_len,
  2383. (ulong)q->sg_head, q->q1.sg_queue_cnt);
  2384. if (q->sg_head) {
  2385. sgp = q->sg_head;
  2386. printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
  2387. printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
  2388. sgp->queue_cnt);
  2389. for (i = 0; i < sgp->entry_cnt; i++) {
  2390. printk(" [%u]: addr 0x%lx, bytes %lu\n",
  2391. i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
  2392. (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
  2393. }
  2394. }
  2395. }
  2396. /*
  2397. * asc_prt_asc_qdone_info()
  2398. */
  2399. static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
  2400. {
  2401. printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
  2402. printk(" srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
  2403. (ulong)q->d2.srb_ptr, q->d2.target_ix, q->d2.cdb_len,
  2404. q->d2.tag_code);
  2405. printk
  2406. (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
  2407. q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
  2408. }
  2409. /*
  2410. * asc_prt_adv_sgblock()
  2411. *
  2412. * Display an ADV_SG_BLOCK structure.
  2413. */
  2414. static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
  2415. {
  2416. int i;
  2417. printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
  2418. (ulong)b, sgblockno);
  2419. printk(" sg_cnt %u, sg_ptr 0x%lx\n",
  2420. b->sg_cnt, (ulong)le32_to_cpu(b->sg_ptr));
  2421. BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
  2422. if (b->sg_ptr != 0)
  2423. BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
  2424. for (i = 0; i < b->sg_cnt; i++) {
  2425. printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
  2426. i, (ulong)b->sg_list[i].sg_addr,
  2427. (ulong)b->sg_list[i].sg_count);
  2428. }
  2429. }
  2430. /*
  2431. * asc_prt_adv_scsi_req_q()
  2432. *
  2433. * Display an ADV_SCSI_REQ_Q structure.
  2434. */
  2435. static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
  2436. {
  2437. int sg_blk_cnt;
  2438. struct asc_sg_block *sg_ptr;
  2439. printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
  2440. printk(" target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
  2441. q->target_id, q->target_lun, (ulong)q->srb_ptr, q->a_flag);
  2442. printk(" cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
  2443. q->cntl, (ulong)le32_to_cpu(q->data_addr), (ulong)q->vdata_addr);
  2444. printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2445. (ulong)le32_to_cpu(q->data_cnt),
  2446. (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
  2447. printk
  2448. (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
  2449. q->cdb_len, q->done_status, q->host_status, q->scsi_status);
  2450. printk(" sg_working_ix 0x%x, target_cmd %u\n",
  2451. q->sg_working_ix, q->target_cmd);
  2452. printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
  2453. (ulong)le32_to_cpu(q->scsiq_rptr),
  2454. (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
  2455. /* Display the request's ADV_SG_BLOCK structures. */
  2456. if (q->sg_list_ptr != NULL) {
  2457. sg_blk_cnt = 0;
  2458. while (1) {
  2459. /*
  2460. * 'sg_ptr' is a physical address. Convert it to a virtual
  2461. * address by indexing 'sg_blk_cnt' into the virtual address
  2462. * array 'sg_list_ptr'.
  2463. *
  2464. * XXX - Assumes all SG physical blocks are virtually contiguous.
  2465. */
  2466. sg_ptr =
  2467. &(((ADV_SG_BLOCK *)(q->sg_list_ptr))[sg_blk_cnt]);
  2468. asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
  2469. if (sg_ptr->sg_ptr == 0) {
  2470. break;
  2471. }
  2472. sg_blk_cnt++;
  2473. }
  2474. }
  2475. }
  2476. #endif /* ADVANSYS_DEBUG */
  2477. /*
  2478. * The advansys chip/microcode contains a 32-bit identifier for each command
  2479. * known as the 'srb'. I don't know what it stands for. The driver used
  2480. * to encode the scsi_cmnd pointer by calling virt_to_bus and retrieve it
  2481. * with bus_to_virt. Now the driver keeps a per-host map of integers to
  2482. * pointers. It auto-expands when full, unless it can't allocate memory.
  2483. * Note that an srb of 0 is treated specially by the chip/firmware, hence
  2484. * the return of i+1 in this routine, and the corresponding subtraction in
  2485. * the inverse routine.
  2486. */
  2487. #define BAD_SRB 0
  2488. static u32 advansys_ptr_to_srb(struct asc_dvc_var *asc_dvc, void *ptr)
  2489. {
  2490. int i;
  2491. void **new_ptr;
  2492. for (i = 0; i < asc_dvc->ptr_map_count; i++) {
  2493. if (!asc_dvc->ptr_map[i])
  2494. goto out;
  2495. }
  2496. if (asc_dvc->ptr_map_count == 0)
  2497. asc_dvc->ptr_map_count = 1;
  2498. else
  2499. asc_dvc->ptr_map_count *= 2;
  2500. new_ptr = krealloc(asc_dvc->ptr_map,
  2501. asc_dvc->ptr_map_count * sizeof(void *), GFP_ATOMIC);
  2502. if (!new_ptr)
  2503. return BAD_SRB;
  2504. asc_dvc->ptr_map = new_ptr;
  2505. out:
  2506. ASC_DBG(3, "Putting ptr %p into array offset %d\n", ptr, i);
  2507. asc_dvc->ptr_map[i] = ptr;
  2508. return i + 1;
  2509. }
  2510. static void * advansys_srb_to_ptr(struct asc_dvc_var *asc_dvc, u32 srb)
  2511. {
  2512. void *ptr;
  2513. srb--;
  2514. if (srb >= asc_dvc->ptr_map_count) {
  2515. printk("advansys: bad SRB %u, max %u\n", srb,
  2516. asc_dvc->ptr_map_count);
  2517. return NULL;
  2518. }
  2519. ptr = asc_dvc->ptr_map[srb];
  2520. asc_dvc->ptr_map[srb] = NULL;
  2521. ASC_DBG(3, "Returning ptr %p from array offset %d\n", ptr, srb);
  2522. return ptr;
  2523. }
  2524. /*
  2525. * advansys_info()
  2526. *
  2527. * Return suitable for printing on the console with the argument
  2528. * adapter's configuration information.
  2529. *
  2530. * Note: The information line should not exceed ASC_INFO_SIZE bytes,
  2531. * otherwise the static 'info' array will be overrun.
  2532. */
  2533. static const char *advansys_info(struct Scsi_Host *shost)
  2534. {
  2535. static char info[ASC_INFO_SIZE];
  2536. struct asc_board *boardp = shost_priv(shost);
  2537. ASC_DVC_VAR *asc_dvc_varp;
  2538. ADV_DVC_VAR *adv_dvc_varp;
  2539. char *busname;
  2540. char *widename = NULL;
  2541. if (ASC_NARROW_BOARD(boardp)) {
  2542. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2543. ASC_DBG(1, "begin\n");
  2544. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2545. if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
  2546. ASC_IS_ISAPNP) {
  2547. busname = "ISA PnP";
  2548. } else {
  2549. busname = "ISA";
  2550. }
  2551. sprintf(info,
  2552. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
  2553. ASC_VERSION, busname,
  2554. (ulong)shost->io_port,
  2555. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2556. boardp->irq, shost->dma_channel);
  2557. } else {
  2558. if (asc_dvc_varp->bus_type & ASC_IS_VL) {
  2559. busname = "VL";
  2560. } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
  2561. busname = "EISA";
  2562. } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
  2563. if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
  2564. == ASC_IS_PCI_ULTRA) {
  2565. busname = "PCI Ultra";
  2566. } else {
  2567. busname = "PCI";
  2568. }
  2569. } else {
  2570. busname = "?";
  2571. shost_printk(KERN_ERR, shost, "unknown bus "
  2572. "type %d\n", asc_dvc_varp->bus_type);
  2573. }
  2574. sprintf(info,
  2575. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
  2576. ASC_VERSION, busname, (ulong)shost->io_port,
  2577. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2578. boardp->irq);
  2579. }
  2580. } else {
  2581. /*
  2582. * Wide Adapter Information
  2583. *
  2584. * Memory-mapped I/O is used instead of I/O space to access
  2585. * the adapter, but display the I/O Port range. The Memory
  2586. * I/O address is displayed through the driver /proc file.
  2587. */
  2588. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2589. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2590. widename = "Ultra-Wide";
  2591. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2592. widename = "Ultra2-Wide";
  2593. } else {
  2594. widename = "Ultra3-Wide";
  2595. }
  2596. sprintf(info,
  2597. "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
  2598. ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
  2599. (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
  2600. }
  2601. BUG_ON(strlen(info) >= ASC_INFO_SIZE);
  2602. ASC_DBG(1, "end\n");
  2603. return info;
  2604. }
  2605. #ifdef CONFIG_PROC_FS
  2606. /*
  2607. * asc_prt_line()
  2608. *
  2609. * If 'cp' is NULL print to the console, otherwise print to a buffer.
  2610. *
  2611. * Return 0 if printing to the console, otherwise return the number of
  2612. * bytes written to the buffer.
  2613. *
  2614. * Note: If any single line is greater than ASC_PRTLINE_SIZE bytes the stack
  2615. * will be corrupted. 's[]' is defined to be ASC_PRTLINE_SIZE bytes.
  2616. */
  2617. static int asc_prt_line(char *buf, int buflen, char *fmt, ...)
  2618. {
  2619. va_list args;
  2620. int ret;
  2621. char s[ASC_PRTLINE_SIZE];
  2622. va_start(args, fmt);
  2623. ret = vsprintf(s, fmt, args);
  2624. BUG_ON(ret >= ASC_PRTLINE_SIZE);
  2625. if (buf == NULL) {
  2626. (void)printk(s);
  2627. ret = 0;
  2628. } else {
  2629. ret = min(buflen, ret);
  2630. memcpy(buf, s, ret);
  2631. }
  2632. va_end(args);
  2633. return ret;
  2634. }
  2635. /*
  2636. * asc_prt_board_devices()
  2637. *
  2638. * Print driver information for devices attached to the board.
  2639. *
  2640. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  2641. * cf. asc_prt_line().
  2642. *
  2643. * Return the number of characters copied into 'cp'. No more than
  2644. * 'cplen' characters will be copied to 'cp'.
  2645. */
  2646. static int asc_prt_board_devices(struct Scsi_Host *shost, char *cp, int cplen)
  2647. {
  2648. struct asc_board *boardp = shost_priv(shost);
  2649. int leftlen;
  2650. int totlen;
  2651. int len;
  2652. int chip_scsi_id;
  2653. int i;
  2654. leftlen = cplen;
  2655. totlen = len = 0;
  2656. len = asc_prt_line(cp, leftlen,
  2657. "\nDevice Information for AdvanSys SCSI Host %d:\n",
  2658. shost->host_no);
  2659. ASC_PRT_NEXT();
  2660. if (ASC_NARROW_BOARD(boardp)) {
  2661. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2662. } else {
  2663. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2664. }
  2665. len = asc_prt_line(cp, leftlen, "Target IDs Detected:");
  2666. ASC_PRT_NEXT();
  2667. for (i = 0; i <= ADV_MAX_TID; i++) {
  2668. if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) {
  2669. len = asc_prt_line(cp, leftlen, " %X,", i);
  2670. ASC_PRT_NEXT();
  2671. }
  2672. }
  2673. len = asc_prt_line(cp, leftlen, " (%X=Host Adapter)\n", chip_scsi_id);
  2674. ASC_PRT_NEXT();
  2675. return totlen;
  2676. }
  2677. /*
  2678. * Display Wide Board BIOS Information.
  2679. */
  2680. static int asc_prt_adv_bios(struct Scsi_Host *shost, char *cp, int cplen)
  2681. {
  2682. struct asc_board *boardp = shost_priv(shost);
  2683. int leftlen;
  2684. int totlen;
  2685. int len;
  2686. ushort major, minor, letter;
  2687. leftlen = cplen;
  2688. totlen = len = 0;
  2689. len = asc_prt_line(cp, leftlen, "\nROM BIOS Version: ");
  2690. ASC_PRT_NEXT();
  2691. /*
  2692. * If the BIOS saved a valid signature, then fill in
  2693. * the BIOS code segment base address.
  2694. */
  2695. if (boardp->bios_signature != 0x55AA) {
  2696. len = asc_prt_line(cp, leftlen, "Disabled or Pre-3.1\n");
  2697. ASC_PRT_NEXT();
  2698. len = asc_prt_line(cp, leftlen,
  2699. "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
  2700. ASC_PRT_NEXT();
  2701. len = asc_prt_line(cp, leftlen,
  2702. "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
  2703. ASC_PRT_NEXT();
  2704. } else {
  2705. major = (boardp->bios_version >> 12) & 0xF;
  2706. minor = (boardp->bios_version >> 8) & 0xF;
  2707. letter = (boardp->bios_version & 0xFF);
  2708. len = asc_prt_line(cp, leftlen, "%d.%d%c\n",
  2709. major, minor,
  2710. letter >= 26 ? '?' : letter + 'A');
  2711. ASC_PRT_NEXT();
  2712. /*
  2713. * Current available ROM BIOS release is 3.1I for UW
  2714. * and 3.2I for U2W. This code doesn't differentiate
  2715. * UW and U2W boards.
  2716. */
  2717. if (major < 3 || (major <= 3 && minor < 1) ||
  2718. (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
  2719. len = asc_prt_line(cp, leftlen,
  2720. "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
  2721. ASC_PRT_NEXT();
  2722. len = asc_prt_line(cp, leftlen,
  2723. "ftp://ftp.connectcom.net/pub\n");
  2724. ASC_PRT_NEXT();
  2725. }
  2726. }
  2727. return totlen;
  2728. }
  2729. /*
  2730. * Add serial number to information bar if signature AAh
  2731. * is found in at bit 15-9 (7 bits) of word 1.
  2732. *
  2733. * Serial Number consists fo 12 alpha-numeric digits.
  2734. *
  2735. * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
  2736. * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
  2737. * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
  2738. * 5 - Product revision (A-J) Word0: " "
  2739. *
  2740. * Signature Word1: 15-9 (7 bits)
  2741. * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
  2742. * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
  2743. *
  2744. * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
  2745. *
  2746. * Note 1: Only production cards will have a serial number.
  2747. *
  2748. * Note 2: Signature is most significant 7 bits (0xFE).
  2749. *
  2750. * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
  2751. */
  2752. static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
  2753. {
  2754. ushort w, num;
  2755. if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
  2756. return ASC_FALSE;
  2757. } else {
  2758. /*
  2759. * First word - 6 digits.
  2760. */
  2761. w = serialnum[0];
  2762. /* Product type - 1st digit. */
  2763. if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
  2764. /* Product type is P=Prototype */
  2765. *cp += 0x8;
  2766. }
  2767. cp++;
  2768. /* Manufacturing location - 2nd digit. */
  2769. *cp++ = 'A' + ((w & 0x1C00) >> 10);
  2770. /* Product ID - 3rd, 4th digits. */
  2771. num = w & 0x3FF;
  2772. *cp++ = '0' + (num / 100);
  2773. num %= 100;
  2774. *cp++ = '0' + (num / 10);
  2775. /* Product revision - 5th digit. */
  2776. *cp++ = 'A' + (num % 10);
  2777. /*
  2778. * Second word
  2779. */
  2780. w = serialnum[1];
  2781. /*
  2782. * Year - 6th digit.
  2783. *
  2784. * If bit 15 of third word is set, then the
  2785. * last digit of the year is greater than 7.
  2786. */
  2787. if (serialnum[2] & 0x8000) {
  2788. *cp++ = '8' + ((w & 0x1C0) >> 6);
  2789. } else {
  2790. *cp++ = '0' + ((w & 0x1C0) >> 6);
  2791. }
  2792. /* Week of year - 7th, 8th digits. */
  2793. num = w & 0x003F;
  2794. *cp++ = '0' + num / 10;
  2795. num %= 10;
  2796. *cp++ = '0' + num;
  2797. /*
  2798. * Third word
  2799. */
  2800. w = serialnum[2] & 0x7FFF;
  2801. /* Serial number - 9th digit. */
  2802. *cp++ = 'A' + (w / 1000);
  2803. /* 10th, 11th, 12th digits. */
  2804. num = w % 1000;
  2805. *cp++ = '0' + num / 100;
  2806. num %= 100;
  2807. *cp++ = '0' + num / 10;
  2808. num %= 10;
  2809. *cp++ = '0' + num;
  2810. *cp = '\0'; /* Null Terminate the string. */
  2811. return ASC_TRUE;
  2812. }
  2813. }
  2814. /*
  2815. * asc_prt_asc_board_eeprom()
  2816. *
  2817. * Print board EEPROM configuration.
  2818. *
  2819. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  2820. * cf. asc_prt_line().
  2821. *
  2822. * Return the number of characters copied into 'cp'. No more than
  2823. * 'cplen' characters will be copied to 'cp'.
  2824. */
  2825. static int asc_prt_asc_board_eeprom(struct Scsi_Host *shost, char *cp, int cplen)
  2826. {
  2827. struct asc_board *boardp = shost_priv(shost);
  2828. ASC_DVC_VAR *asc_dvc_varp;
  2829. int leftlen;
  2830. int totlen;
  2831. int len;
  2832. ASCEEP_CONFIG *ep;
  2833. int i;
  2834. #ifdef CONFIG_ISA
  2835. int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
  2836. #endif /* CONFIG_ISA */
  2837. uchar serialstr[13];
  2838. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2839. ep = &boardp->eep_config.asc_eep;
  2840. leftlen = cplen;
  2841. totlen = len = 0;
  2842. len = asc_prt_line(cp, leftlen,
  2843. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2844. shost->host_no);
  2845. ASC_PRT_NEXT();
  2846. if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
  2847. == ASC_TRUE) {
  2848. len =
  2849. asc_prt_line(cp, leftlen, " Serial Number: %s\n",
  2850. serialstr);
  2851. ASC_PRT_NEXT();
  2852. } else {
  2853. if (ep->adapter_info[5] == 0xBB) {
  2854. len = asc_prt_line(cp, leftlen,
  2855. " Default Settings Used for EEPROM-less Adapter.\n");
  2856. ASC_PRT_NEXT();
  2857. } else {
  2858. len = asc_prt_line(cp, leftlen,
  2859. " Serial Number Signature Not Present.\n");
  2860. ASC_PRT_NEXT();
  2861. }
  2862. }
  2863. len = asc_prt_line(cp, leftlen,
  2864. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2865. ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
  2866. ep->max_tag_qng);
  2867. ASC_PRT_NEXT();
  2868. len = asc_prt_line(cp, leftlen,
  2869. " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
  2870. ASC_PRT_NEXT();
  2871. len = asc_prt_line(cp, leftlen, " Target ID: ");
  2872. ASC_PRT_NEXT();
  2873. for (i = 0; i <= ASC_MAX_TID; i++) {
  2874. len = asc_prt_line(cp, leftlen, " %d", i);
  2875. ASC_PRT_NEXT();
  2876. }
  2877. len = asc_prt_line(cp, leftlen, "\n");
  2878. ASC_PRT_NEXT();
  2879. len = asc_prt_line(cp, leftlen, " Disconnects: ");
  2880. ASC_PRT_NEXT();
  2881. for (i = 0; i <= ASC_MAX_TID; i++) {
  2882. len = asc_prt_line(cp, leftlen, " %c",
  2883. (ep->
  2884. disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2885. 'N');
  2886. ASC_PRT_NEXT();
  2887. }
  2888. len = asc_prt_line(cp, leftlen, "\n");
  2889. ASC_PRT_NEXT();
  2890. len = asc_prt_line(cp, leftlen, " Command Queuing: ");
  2891. ASC_PRT_NEXT();
  2892. for (i = 0; i <= ASC_MAX_TID; i++) {
  2893. len = asc_prt_line(cp, leftlen, " %c",
  2894. (ep->
  2895. use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2896. 'N');
  2897. ASC_PRT_NEXT();
  2898. }
  2899. len = asc_prt_line(cp, leftlen, "\n");
  2900. ASC_PRT_NEXT();
  2901. len = asc_prt_line(cp, leftlen, " Start Motor: ");
  2902. ASC_PRT_NEXT();
  2903. for (i = 0; i <= ASC_MAX_TID; i++) {
  2904. len = asc_prt_line(cp, leftlen, " %c",
  2905. (ep->
  2906. start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2907. 'N');
  2908. ASC_PRT_NEXT();
  2909. }
  2910. len = asc_prt_line(cp, leftlen, "\n");
  2911. ASC_PRT_NEXT();
  2912. len = asc_prt_line(cp, leftlen, " Synchronous Transfer:");
  2913. ASC_PRT_NEXT();
  2914. for (i = 0; i <= ASC_MAX_TID; i++) {
  2915. len = asc_prt_line(cp, leftlen, " %c",
  2916. (ep->
  2917. init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2918. 'N');
  2919. ASC_PRT_NEXT();
  2920. }
  2921. len = asc_prt_line(cp, leftlen, "\n");
  2922. ASC_PRT_NEXT();
  2923. #ifdef CONFIG_ISA
  2924. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2925. len = asc_prt_line(cp, leftlen,
  2926. " Host ISA DMA speed: %d MB/S\n",
  2927. isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
  2928. ASC_PRT_NEXT();
  2929. }
  2930. #endif /* CONFIG_ISA */
  2931. return totlen;
  2932. }
  2933. /*
  2934. * asc_prt_adv_board_eeprom()
  2935. *
  2936. * Print board EEPROM configuration.
  2937. *
  2938. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  2939. * cf. asc_prt_line().
  2940. *
  2941. * Return the number of characters copied into 'cp'. No more than
  2942. * 'cplen' characters will be copied to 'cp'.
  2943. */
  2944. static int asc_prt_adv_board_eeprom(struct Scsi_Host *shost, char *cp, int cplen)
  2945. {
  2946. struct asc_board *boardp = shost_priv(shost);
  2947. ADV_DVC_VAR *adv_dvc_varp;
  2948. int leftlen;
  2949. int totlen;
  2950. int len;
  2951. int i;
  2952. char *termstr;
  2953. uchar serialstr[13];
  2954. ADVEEP_3550_CONFIG *ep_3550 = NULL;
  2955. ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
  2956. ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
  2957. ushort word;
  2958. ushort *wordp;
  2959. ushort sdtr_speed = 0;
  2960. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2961. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2962. ep_3550 = &boardp->eep_config.adv_3550_eep;
  2963. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2964. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  2965. } else {
  2966. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  2967. }
  2968. leftlen = cplen;
  2969. totlen = len = 0;
  2970. len = asc_prt_line(cp, leftlen,
  2971. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2972. shost->host_no);
  2973. ASC_PRT_NEXT();
  2974. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2975. wordp = &ep_3550->serial_number_word1;
  2976. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2977. wordp = &ep_38C0800->serial_number_word1;
  2978. } else {
  2979. wordp = &ep_38C1600->serial_number_word1;
  2980. }
  2981. if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE) {
  2982. len =
  2983. asc_prt_line(cp, leftlen, " Serial Number: %s\n",
  2984. serialstr);
  2985. ASC_PRT_NEXT();
  2986. } else {
  2987. len = asc_prt_line(cp, leftlen,
  2988. " Serial Number Signature Not Present.\n");
  2989. ASC_PRT_NEXT();
  2990. }
  2991. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2992. len = asc_prt_line(cp, leftlen,
  2993. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2994. ep_3550->adapter_scsi_id,
  2995. ep_3550->max_host_qng, ep_3550->max_dvc_qng);
  2996. ASC_PRT_NEXT();
  2997. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2998. len = asc_prt_line(cp, leftlen,
  2999. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  3000. ep_38C0800->adapter_scsi_id,
  3001. ep_38C0800->max_host_qng,
  3002. ep_38C0800->max_dvc_qng);
  3003. ASC_PRT_NEXT();
  3004. } else {
  3005. len = asc_prt_line(cp, leftlen,
  3006. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  3007. ep_38C1600->adapter_scsi_id,
  3008. ep_38C1600->max_host_qng,
  3009. ep_38C1600->max_dvc_qng);
  3010. ASC_PRT_NEXT();
  3011. }
  3012. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3013. word = ep_3550->termination;
  3014. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3015. word = ep_38C0800->termination_lvd;
  3016. } else {
  3017. word = ep_38C1600->termination_lvd;
  3018. }
  3019. switch (word) {
  3020. case 1:
  3021. termstr = "Low Off/High Off";
  3022. break;
  3023. case 2:
  3024. termstr = "Low Off/High On";
  3025. break;
  3026. case 3:
  3027. termstr = "Low On/High On";
  3028. break;
  3029. default:
  3030. case 0:
  3031. termstr = "Automatic";
  3032. break;
  3033. }
  3034. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3035. len = asc_prt_line(cp, leftlen,
  3036. " termination: %u (%s), bios_ctrl: 0x%x\n",
  3037. ep_3550->termination, termstr,
  3038. ep_3550->bios_ctrl);
  3039. ASC_PRT_NEXT();
  3040. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3041. len = asc_prt_line(cp, leftlen,
  3042. " termination: %u (%s), bios_ctrl: 0x%x\n",
  3043. ep_38C0800->termination_lvd, termstr,
  3044. ep_38C0800->bios_ctrl);
  3045. ASC_PRT_NEXT();
  3046. } else {
  3047. len = asc_prt_line(cp, leftlen,
  3048. " termination: %u (%s), bios_ctrl: 0x%x\n",
  3049. ep_38C1600->termination_lvd, termstr,
  3050. ep_38C1600->bios_ctrl);
  3051. ASC_PRT_NEXT();
  3052. }
  3053. len = asc_prt_line(cp, leftlen, " Target ID: ");
  3054. ASC_PRT_NEXT();
  3055. for (i = 0; i <= ADV_MAX_TID; i++) {
  3056. len = asc_prt_line(cp, leftlen, " %X", i);
  3057. ASC_PRT_NEXT();
  3058. }
  3059. len = asc_prt_line(cp, leftlen, "\n");
  3060. ASC_PRT_NEXT();
  3061. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3062. word = ep_3550->disc_enable;
  3063. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3064. word = ep_38C0800->disc_enable;
  3065. } else {
  3066. word = ep_38C1600->disc_enable;
  3067. }
  3068. len = asc_prt_line(cp, leftlen, " Disconnects: ");
  3069. ASC_PRT_NEXT();
  3070. for (i = 0; i <= ADV_MAX_TID; i++) {
  3071. len = asc_prt_line(cp, leftlen, " %c",
  3072. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3073. ASC_PRT_NEXT();
  3074. }
  3075. len = asc_prt_line(cp, leftlen, "\n");
  3076. ASC_PRT_NEXT();
  3077. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3078. word = ep_3550->tagqng_able;
  3079. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3080. word = ep_38C0800->tagqng_able;
  3081. } else {
  3082. word = ep_38C1600->tagqng_able;
  3083. }
  3084. len = asc_prt_line(cp, leftlen, " Command Queuing: ");
  3085. ASC_PRT_NEXT();
  3086. for (i = 0; i <= ADV_MAX_TID; i++) {
  3087. len = asc_prt_line(cp, leftlen, " %c",
  3088. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3089. ASC_PRT_NEXT();
  3090. }
  3091. len = asc_prt_line(cp, leftlen, "\n");
  3092. ASC_PRT_NEXT();
  3093. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3094. word = ep_3550->start_motor;
  3095. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3096. word = ep_38C0800->start_motor;
  3097. } else {
  3098. word = ep_38C1600->start_motor;
  3099. }
  3100. len = asc_prt_line(cp, leftlen, " Start Motor: ");
  3101. ASC_PRT_NEXT();
  3102. for (i = 0; i <= ADV_MAX_TID; i++) {
  3103. len = asc_prt_line(cp, leftlen, " %c",
  3104. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3105. ASC_PRT_NEXT();
  3106. }
  3107. len = asc_prt_line(cp, leftlen, "\n");
  3108. ASC_PRT_NEXT();
  3109. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3110. len = asc_prt_line(cp, leftlen, " Synchronous Transfer:");
  3111. ASC_PRT_NEXT();
  3112. for (i = 0; i <= ADV_MAX_TID; i++) {
  3113. len = asc_prt_line(cp, leftlen, " %c",
  3114. (ep_3550->
  3115. sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
  3116. 'Y' : 'N');
  3117. ASC_PRT_NEXT();
  3118. }
  3119. len = asc_prt_line(cp, leftlen, "\n");
  3120. ASC_PRT_NEXT();
  3121. }
  3122. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3123. len = asc_prt_line(cp, leftlen, " Ultra Transfer: ");
  3124. ASC_PRT_NEXT();
  3125. for (i = 0; i <= ADV_MAX_TID; i++) {
  3126. len = asc_prt_line(cp, leftlen, " %c",
  3127. (ep_3550->
  3128. ultra_able & ADV_TID_TO_TIDMASK(i))
  3129. ? 'Y' : 'N');
  3130. ASC_PRT_NEXT();
  3131. }
  3132. len = asc_prt_line(cp, leftlen, "\n");
  3133. ASC_PRT_NEXT();
  3134. }
  3135. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3136. word = ep_3550->wdtr_able;
  3137. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3138. word = ep_38C0800->wdtr_able;
  3139. } else {
  3140. word = ep_38C1600->wdtr_able;
  3141. }
  3142. len = asc_prt_line(cp, leftlen, " Wide Transfer: ");
  3143. ASC_PRT_NEXT();
  3144. for (i = 0; i <= ADV_MAX_TID; i++) {
  3145. len = asc_prt_line(cp, leftlen, " %c",
  3146. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3147. ASC_PRT_NEXT();
  3148. }
  3149. len = asc_prt_line(cp, leftlen, "\n");
  3150. ASC_PRT_NEXT();
  3151. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
  3152. adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
  3153. len = asc_prt_line(cp, leftlen,
  3154. " Synchronous Transfer Speed (Mhz):\n ");
  3155. ASC_PRT_NEXT();
  3156. for (i = 0; i <= ADV_MAX_TID; i++) {
  3157. char *speed_str;
  3158. if (i == 0) {
  3159. sdtr_speed = adv_dvc_varp->sdtr_speed1;
  3160. } else if (i == 4) {
  3161. sdtr_speed = adv_dvc_varp->sdtr_speed2;
  3162. } else if (i == 8) {
  3163. sdtr_speed = adv_dvc_varp->sdtr_speed3;
  3164. } else if (i == 12) {
  3165. sdtr_speed = adv_dvc_varp->sdtr_speed4;
  3166. }
  3167. switch (sdtr_speed & ADV_MAX_TID) {
  3168. case 0:
  3169. speed_str = "Off";
  3170. break;
  3171. case 1:
  3172. speed_str = " 5";
  3173. break;
  3174. case 2:
  3175. speed_str = " 10";
  3176. break;
  3177. case 3:
  3178. speed_str = " 20";
  3179. break;
  3180. case 4:
  3181. speed_str = " 40";
  3182. break;
  3183. case 5:
  3184. speed_str = " 80";
  3185. break;
  3186. default:
  3187. speed_str = "Unk";
  3188. break;
  3189. }
  3190. len = asc_prt_line(cp, leftlen, "%X:%s ", i, speed_str);
  3191. ASC_PRT_NEXT();
  3192. if (i == 7) {
  3193. len = asc_prt_line(cp, leftlen, "\n ");
  3194. ASC_PRT_NEXT();
  3195. }
  3196. sdtr_speed >>= 4;
  3197. }
  3198. len = asc_prt_line(cp, leftlen, "\n");
  3199. ASC_PRT_NEXT();
  3200. }
  3201. return totlen;
  3202. }
  3203. /*
  3204. * asc_prt_driver_conf()
  3205. *
  3206. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3207. * cf. asc_prt_line().
  3208. *
  3209. * Return the number of characters copied into 'cp'. No more than
  3210. * 'cplen' characters will be copied to 'cp'.
  3211. */
  3212. static int asc_prt_driver_conf(struct Scsi_Host *shost, char *cp, int cplen)
  3213. {
  3214. struct asc_board *boardp = shost_priv(shost);
  3215. int leftlen;
  3216. int totlen;
  3217. int len;
  3218. int chip_scsi_id;
  3219. leftlen = cplen;
  3220. totlen = len = 0;
  3221. len = asc_prt_line(cp, leftlen,
  3222. "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
  3223. shost->host_no);
  3224. ASC_PRT_NEXT();
  3225. len = asc_prt_line(cp, leftlen,
  3226. " host_busy %u, last_reset %u, max_id %u, max_lun %u, max_channel %u\n",
  3227. shost->host_busy, shost->last_reset, shost->max_id,
  3228. shost->max_lun, shost->max_channel);
  3229. ASC_PRT_NEXT();
  3230. len = asc_prt_line(cp, leftlen,
  3231. " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
  3232. shost->unique_id, shost->can_queue, shost->this_id,
  3233. shost->sg_tablesize, shost->cmd_per_lun);
  3234. ASC_PRT_NEXT();
  3235. len = asc_prt_line(cp, leftlen,
  3236. " unchecked_isa_dma %d, use_clustering %d\n",
  3237. shost->unchecked_isa_dma, shost->use_clustering);
  3238. ASC_PRT_NEXT();
  3239. len = asc_prt_line(cp, leftlen,
  3240. " flags 0x%x, last_reset 0x%x, jiffies 0x%x, asc_n_io_port 0x%x\n",
  3241. boardp->flags, boardp->last_reset, jiffies,
  3242. boardp->asc_n_io_port);
  3243. ASC_PRT_NEXT();
  3244. len = asc_prt_line(cp, leftlen, " io_port 0x%x\n", shost->io_port);
  3245. ASC_PRT_NEXT();
  3246. if (ASC_NARROW_BOARD(boardp)) {
  3247. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  3248. } else {
  3249. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  3250. }
  3251. return totlen;
  3252. }
  3253. /*
  3254. * asc_prt_asc_board_info()
  3255. *
  3256. * Print dynamic board configuration information.
  3257. *
  3258. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3259. * cf. asc_prt_line().
  3260. *
  3261. * Return the number of characters copied into 'cp'. No more than
  3262. * 'cplen' characters will be copied to 'cp'.
  3263. */
  3264. static int asc_prt_asc_board_info(struct Scsi_Host *shost, char *cp, int cplen)
  3265. {
  3266. struct asc_board *boardp = shost_priv(shost);
  3267. int chip_scsi_id;
  3268. int leftlen;
  3269. int totlen;
  3270. int len;
  3271. ASC_DVC_VAR *v;
  3272. ASC_DVC_CFG *c;
  3273. int i;
  3274. int renegotiate = 0;
  3275. v = &boardp->dvc_var.asc_dvc_var;
  3276. c = &boardp->dvc_cfg.asc_dvc_cfg;
  3277. chip_scsi_id = c->chip_scsi_id;
  3278. leftlen = cplen;
  3279. totlen = len = 0;
  3280. len = asc_prt_line(cp, leftlen,
  3281. "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3282. shost->host_no);
  3283. ASC_PRT_NEXT();
  3284. len = asc_prt_line(cp, leftlen, " chip_version %u, mcode_date 0x%x, "
  3285. "mcode_version 0x%x, err_code %u\n",
  3286. c->chip_version, c->mcode_date, c->mcode_version,
  3287. v->err_code);
  3288. ASC_PRT_NEXT();
  3289. /* Current number of commands waiting for the host. */
  3290. len = asc_prt_line(cp, leftlen,
  3291. " Total Command Pending: %d\n", v->cur_total_qng);
  3292. ASC_PRT_NEXT();
  3293. len = asc_prt_line(cp, leftlen, " Command Queuing:");
  3294. ASC_PRT_NEXT();
  3295. for (i = 0; i <= ASC_MAX_TID; i++) {
  3296. if ((chip_scsi_id == i) ||
  3297. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3298. continue;
  3299. }
  3300. len = asc_prt_line(cp, leftlen, " %X:%c",
  3301. i,
  3302. (v->
  3303. use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ?
  3304. 'Y' : 'N');
  3305. ASC_PRT_NEXT();
  3306. }
  3307. len = asc_prt_line(cp, leftlen, "\n");
  3308. ASC_PRT_NEXT();
  3309. /* Current number of commands waiting for a device. */
  3310. len = asc_prt_line(cp, leftlen, " Command Queue Pending:");
  3311. ASC_PRT_NEXT();
  3312. for (i = 0; i <= ASC_MAX_TID; i++) {
  3313. if ((chip_scsi_id == i) ||
  3314. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3315. continue;
  3316. }
  3317. len = asc_prt_line(cp, leftlen, " %X:%u", i, v->cur_dvc_qng[i]);
  3318. ASC_PRT_NEXT();
  3319. }
  3320. len = asc_prt_line(cp, leftlen, "\n");
  3321. ASC_PRT_NEXT();
  3322. /* Current limit on number of commands that can be sent to a device. */
  3323. len = asc_prt_line(cp, leftlen, " Command Queue Limit:");
  3324. ASC_PRT_NEXT();
  3325. for (i = 0; i <= ASC_MAX_TID; i++) {
  3326. if ((chip_scsi_id == i) ||
  3327. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3328. continue;
  3329. }
  3330. len = asc_prt_line(cp, leftlen, " %X:%u", i, v->max_dvc_qng[i]);
  3331. ASC_PRT_NEXT();
  3332. }
  3333. len = asc_prt_line(cp, leftlen, "\n");
  3334. ASC_PRT_NEXT();
  3335. /* Indicate whether the device has returned queue full status. */
  3336. len = asc_prt_line(cp, leftlen, " Command Queue Full:");
  3337. ASC_PRT_NEXT();
  3338. for (i = 0; i <= ASC_MAX_TID; i++) {
  3339. if ((chip_scsi_id == i) ||
  3340. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3341. continue;
  3342. }
  3343. if (boardp->queue_full & ADV_TID_TO_TIDMASK(i)) {
  3344. len = asc_prt_line(cp, leftlen, " %X:Y-%d",
  3345. i, boardp->queue_full_cnt[i]);
  3346. } else {
  3347. len = asc_prt_line(cp, leftlen, " %X:N", i);
  3348. }
  3349. ASC_PRT_NEXT();
  3350. }
  3351. len = asc_prt_line(cp, leftlen, "\n");
  3352. ASC_PRT_NEXT();
  3353. len = asc_prt_line(cp, leftlen, " Synchronous Transfer:");
  3354. ASC_PRT_NEXT();
  3355. for (i = 0; i <= ASC_MAX_TID; i++) {
  3356. if ((chip_scsi_id == i) ||
  3357. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3358. continue;
  3359. }
  3360. len = asc_prt_line(cp, leftlen, " %X:%c",
  3361. i,
  3362. (v->
  3363. sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3364. 'N');
  3365. ASC_PRT_NEXT();
  3366. }
  3367. len = asc_prt_line(cp, leftlen, "\n");
  3368. ASC_PRT_NEXT();
  3369. for (i = 0; i <= ASC_MAX_TID; i++) {
  3370. uchar syn_period_ix;
  3371. if ((chip_scsi_id == i) ||
  3372. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3373. ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3374. continue;
  3375. }
  3376. len = asc_prt_line(cp, leftlen, " %X:", i);
  3377. ASC_PRT_NEXT();
  3378. if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
  3379. len = asc_prt_line(cp, leftlen, " Asynchronous");
  3380. ASC_PRT_NEXT();
  3381. } else {
  3382. syn_period_ix =
  3383. (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
  3384. 1);
  3385. len = asc_prt_line(cp, leftlen,
  3386. " Transfer Period Factor: %d (%d.%d Mhz),",
  3387. v->sdtr_period_tbl[syn_period_ix],
  3388. 250 /
  3389. v->sdtr_period_tbl[syn_period_ix],
  3390. ASC_TENTHS(250,
  3391. v->
  3392. sdtr_period_tbl
  3393. [syn_period_ix]));
  3394. ASC_PRT_NEXT();
  3395. len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
  3396. boardp->
  3397. sdtr_data[i] & ASC_SYN_MAX_OFFSET);
  3398. ASC_PRT_NEXT();
  3399. }
  3400. if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3401. len = asc_prt_line(cp, leftlen, "*\n");
  3402. renegotiate = 1;
  3403. } else {
  3404. len = asc_prt_line(cp, leftlen, "\n");
  3405. }
  3406. ASC_PRT_NEXT();
  3407. }
  3408. if (renegotiate) {
  3409. len = asc_prt_line(cp, leftlen,
  3410. " * = Re-negotiation pending before next command.\n");
  3411. ASC_PRT_NEXT();
  3412. }
  3413. return totlen;
  3414. }
  3415. /*
  3416. * asc_prt_adv_board_info()
  3417. *
  3418. * Print dynamic board configuration information.
  3419. *
  3420. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3421. * cf. asc_prt_line().
  3422. *
  3423. * Return the number of characters copied into 'cp'. No more than
  3424. * 'cplen' characters will be copied to 'cp'.
  3425. */
  3426. static int asc_prt_adv_board_info(struct Scsi_Host *shost, char *cp, int cplen)
  3427. {
  3428. struct asc_board *boardp = shost_priv(shost);
  3429. int leftlen;
  3430. int totlen;
  3431. int len;
  3432. int i;
  3433. ADV_DVC_VAR *v;
  3434. ADV_DVC_CFG *c;
  3435. AdvPortAddr iop_base;
  3436. ushort chip_scsi_id;
  3437. ushort lramword;
  3438. uchar lrambyte;
  3439. ushort tagqng_able;
  3440. ushort sdtr_able, wdtr_able;
  3441. ushort wdtr_done, sdtr_done;
  3442. ushort period = 0;
  3443. int renegotiate = 0;
  3444. v = &boardp->dvc_var.adv_dvc_var;
  3445. c = &boardp->dvc_cfg.adv_dvc_cfg;
  3446. iop_base = v->iop_base;
  3447. chip_scsi_id = v->chip_scsi_id;
  3448. leftlen = cplen;
  3449. totlen = len = 0;
  3450. len = asc_prt_line(cp, leftlen,
  3451. "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3452. shost->host_no);
  3453. ASC_PRT_NEXT();
  3454. len = asc_prt_line(cp, leftlen,
  3455. " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
  3456. v->iop_base,
  3457. AdvReadWordRegister(iop_base,
  3458. IOPW_SCSI_CFG1) & CABLE_DETECT,
  3459. v->err_code);
  3460. ASC_PRT_NEXT();
  3461. len = asc_prt_line(cp, leftlen, " chip_version %u, mcode_date 0x%x, "
  3462. "mcode_version 0x%x\n", c->chip_version,
  3463. c->mcode_date, c->mcode_version);
  3464. ASC_PRT_NEXT();
  3465. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3466. len = asc_prt_line(cp, leftlen, " Queuing Enabled:");
  3467. ASC_PRT_NEXT();
  3468. for (i = 0; i <= ADV_MAX_TID; i++) {
  3469. if ((chip_scsi_id == i) ||
  3470. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3471. continue;
  3472. }
  3473. len = asc_prt_line(cp, leftlen, " %X:%c",
  3474. i,
  3475. (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3476. 'N');
  3477. ASC_PRT_NEXT();
  3478. }
  3479. len = asc_prt_line(cp, leftlen, "\n");
  3480. ASC_PRT_NEXT();
  3481. len = asc_prt_line(cp, leftlen, " Queue Limit:");
  3482. ASC_PRT_NEXT();
  3483. for (i = 0; i <= ADV_MAX_TID; i++) {
  3484. if ((chip_scsi_id == i) ||
  3485. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3486. continue;
  3487. }
  3488. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
  3489. lrambyte);
  3490. len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
  3491. ASC_PRT_NEXT();
  3492. }
  3493. len = asc_prt_line(cp, leftlen, "\n");
  3494. ASC_PRT_NEXT();
  3495. len = asc_prt_line(cp, leftlen, " Command Pending:");
  3496. ASC_PRT_NEXT();
  3497. for (i = 0; i <= ADV_MAX_TID; i++) {
  3498. if ((chip_scsi_id == i) ||
  3499. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3500. continue;
  3501. }
  3502. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
  3503. lrambyte);
  3504. len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
  3505. ASC_PRT_NEXT();
  3506. }
  3507. len = asc_prt_line(cp, leftlen, "\n");
  3508. ASC_PRT_NEXT();
  3509. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3510. len = asc_prt_line(cp, leftlen, " Wide Enabled:");
  3511. ASC_PRT_NEXT();
  3512. for (i = 0; i <= ADV_MAX_TID; i++) {
  3513. if ((chip_scsi_id == i) ||
  3514. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3515. continue;
  3516. }
  3517. len = asc_prt_line(cp, leftlen, " %X:%c",
  3518. i,
  3519. (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3520. 'N');
  3521. ASC_PRT_NEXT();
  3522. }
  3523. len = asc_prt_line(cp, leftlen, "\n");
  3524. ASC_PRT_NEXT();
  3525. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
  3526. len = asc_prt_line(cp, leftlen, " Transfer Bit Width:");
  3527. ASC_PRT_NEXT();
  3528. for (i = 0; i <= ADV_MAX_TID; i++) {
  3529. if ((chip_scsi_id == i) ||
  3530. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3531. continue;
  3532. }
  3533. AdvReadWordLram(iop_base,
  3534. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3535. lramword);
  3536. len = asc_prt_line(cp, leftlen, " %X:%d",
  3537. i, (lramword & 0x8000) ? 16 : 8);
  3538. ASC_PRT_NEXT();
  3539. if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
  3540. (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3541. len = asc_prt_line(cp, leftlen, "*");
  3542. ASC_PRT_NEXT();
  3543. renegotiate = 1;
  3544. }
  3545. }
  3546. len = asc_prt_line(cp, leftlen, "\n");
  3547. ASC_PRT_NEXT();
  3548. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3549. len = asc_prt_line(cp, leftlen, " Synchronous Enabled:");
  3550. ASC_PRT_NEXT();
  3551. for (i = 0; i <= ADV_MAX_TID; i++) {
  3552. if ((chip_scsi_id == i) ||
  3553. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3554. continue;
  3555. }
  3556. len = asc_prt_line(cp, leftlen, " %X:%c",
  3557. i,
  3558. (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3559. 'N');
  3560. ASC_PRT_NEXT();
  3561. }
  3562. len = asc_prt_line(cp, leftlen, "\n");
  3563. ASC_PRT_NEXT();
  3564. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
  3565. for (i = 0; i <= ADV_MAX_TID; i++) {
  3566. AdvReadWordLram(iop_base,
  3567. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3568. lramword);
  3569. lramword &= ~0x8000;
  3570. if ((chip_scsi_id == i) ||
  3571. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3572. ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3573. continue;
  3574. }
  3575. len = asc_prt_line(cp, leftlen, " %X:", i);
  3576. ASC_PRT_NEXT();
  3577. if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
  3578. len = asc_prt_line(cp, leftlen, " Asynchronous");
  3579. ASC_PRT_NEXT();
  3580. } else {
  3581. len =
  3582. asc_prt_line(cp, leftlen,
  3583. " Transfer Period Factor: ");
  3584. ASC_PRT_NEXT();
  3585. if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
  3586. len =
  3587. asc_prt_line(cp, leftlen, "9 (80.0 Mhz),");
  3588. ASC_PRT_NEXT();
  3589. } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
  3590. len =
  3591. asc_prt_line(cp, leftlen, "10 (40.0 Mhz),");
  3592. ASC_PRT_NEXT();
  3593. } else { /* 20 Mhz or below. */
  3594. period = (((lramword >> 8) * 25) + 50) / 4;
  3595. if (period == 0) { /* Should never happen. */
  3596. len =
  3597. asc_prt_line(cp, leftlen,
  3598. "%d (? Mhz), ");
  3599. ASC_PRT_NEXT();
  3600. } else {
  3601. len = asc_prt_line(cp, leftlen,
  3602. "%d (%d.%d Mhz),",
  3603. period, 250 / period,
  3604. ASC_TENTHS(250,
  3605. period));
  3606. ASC_PRT_NEXT();
  3607. }
  3608. }
  3609. len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
  3610. lramword & 0x1F);
  3611. ASC_PRT_NEXT();
  3612. }
  3613. if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3614. len = asc_prt_line(cp, leftlen, "*\n");
  3615. renegotiate = 1;
  3616. } else {
  3617. len = asc_prt_line(cp, leftlen, "\n");
  3618. }
  3619. ASC_PRT_NEXT();
  3620. }
  3621. if (renegotiate) {
  3622. len = asc_prt_line(cp, leftlen,
  3623. " * = Re-negotiation pending before next command.\n");
  3624. ASC_PRT_NEXT();
  3625. }
  3626. return totlen;
  3627. }
  3628. /*
  3629. * asc_proc_copy()
  3630. *
  3631. * Copy proc information to a read buffer taking into account the current
  3632. * read offset in the file and the remaining space in the read buffer.
  3633. */
  3634. static int
  3635. asc_proc_copy(off_t advoffset, off_t offset, char *curbuf, int leftlen,
  3636. char *cp, int cplen)
  3637. {
  3638. int cnt = 0;
  3639. ASC_DBG(2, "offset %d, advoffset %d, cplen %d\n",
  3640. (unsigned)offset, (unsigned)advoffset, cplen);
  3641. if (offset <= advoffset) {
  3642. /* Read offset below current offset, copy everything. */
  3643. cnt = min(cplen, leftlen);
  3644. ASC_DBG(2, "curbuf 0x%lx, cp 0x%lx, cnt %d\n",
  3645. (ulong)curbuf, (ulong)cp, cnt);
  3646. memcpy(curbuf, cp, cnt);
  3647. } else if (offset < advoffset + cplen) {
  3648. /* Read offset within current range, partial copy. */
  3649. cnt = (advoffset + cplen) - offset;
  3650. cp = (cp + cplen) - cnt;
  3651. cnt = min(cnt, leftlen);
  3652. ASC_DBG(2, "curbuf 0x%lx, cp 0x%lx, cnt %d\n",
  3653. (ulong)curbuf, (ulong)cp, cnt);
  3654. memcpy(curbuf, cp, cnt);
  3655. }
  3656. return cnt;
  3657. }
  3658. #ifdef ADVANSYS_STATS
  3659. /*
  3660. * asc_prt_board_stats()
  3661. *
  3662. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3663. * cf. asc_prt_line().
  3664. *
  3665. * Return the number of characters copied into 'cp'. No more than
  3666. * 'cplen' characters will be copied to 'cp'.
  3667. */
  3668. static int asc_prt_board_stats(struct Scsi_Host *shost, char *cp, int cplen)
  3669. {
  3670. struct asc_board *boardp = shost_priv(shost);
  3671. struct asc_stats *s = &boardp->asc_stats;
  3672. int leftlen = cplen;
  3673. int len, totlen = 0;
  3674. len = asc_prt_line(cp, leftlen,
  3675. "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
  3676. shost->host_no);
  3677. ASC_PRT_NEXT();
  3678. len = asc_prt_line(cp, leftlen,
  3679. " queuecommand %lu, reset %lu, biosparam %lu, interrupt %lu\n",
  3680. s->queuecommand, s->reset, s->biosparam,
  3681. s->interrupt);
  3682. ASC_PRT_NEXT();
  3683. len = asc_prt_line(cp, leftlen,
  3684. " callback %lu, done %lu, build_error %lu, build_noreq %lu, build_nosg %lu\n",
  3685. s->callback, s->done, s->build_error,
  3686. s->adv_build_noreq, s->adv_build_nosg);
  3687. ASC_PRT_NEXT();
  3688. len = asc_prt_line(cp, leftlen,
  3689. " exe_noerror %lu, exe_busy %lu, exe_error %lu, exe_unknown %lu\n",
  3690. s->exe_noerror, s->exe_busy, s->exe_error,
  3691. s->exe_unknown);
  3692. ASC_PRT_NEXT();
  3693. /*
  3694. * Display data transfer statistics.
  3695. */
  3696. if (s->xfer_cnt > 0) {
  3697. len = asc_prt_line(cp, leftlen, " xfer_cnt %lu, xfer_elem %lu, ",
  3698. s->xfer_cnt, s->xfer_elem);
  3699. ASC_PRT_NEXT();
  3700. len = asc_prt_line(cp, leftlen, "xfer_bytes %lu.%01lu kb\n",
  3701. s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
  3702. ASC_PRT_NEXT();
  3703. /* Scatter gather transfer statistics */
  3704. len = asc_prt_line(cp, leftlen, " avg_num_elem %lu.%01lu, ",
  3705. s->xfer_elem / s->xfer_cnt,
  3706. ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
  3707. ASC_PRT_NEXT();
  3708. len = asc_prt_line(cp, leftlen, "avg_elem_size %lu.%01lu kb, ",
  3709. (s->xfer_sect / 2) / s->xfer_elem,
  3710. ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
  3711. ASC_PRT_NEXT();
  3712. len = asc_prt_line(cp, leftlen, "avg_xfer_size %lu.%01lu kb\n",
  3713. (s->xfer_sect / 2) / s->xfer_cnt,
  3714. ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
  3715. ASC_PRT_NEXT();
  3716. }
  3717. return totlen;
  3718. }
  3719. #endif /* ADVANSYS_STATS */
  3720. /*
  3721. * advansys_proc_info() - /proc/scsi/advansys/{0,1,2,3,...}
  3722. *
  3723. * *buffer: I/O buffer
  3724. * **start: if inout == FALSE pointer into buffer where user read should start
  3725. * offset: current offset into a /proc/scsi/advansys/[0...] file
  3726. * length: length of buffer
  3727. * hostno: Scsi_Host host_no
  3728. * inout: TRUE - user is writing; FALSE - user is reading
  3729. *
  3730. * Return the number of bytes read from or written to a
  3731. * /proc/scsi/advansys/[0...] file.
  3732. *
  3733. * Note: This function uses the per board buffer 'prtbuf' which is
  3734. * allocated when the board is initialized in advansys_detect(). The
  3735. * buffer is ASC_PRTBUF_SIZE bytes. The function asc_proc_copy() is
  3736. * used to write to the buffer. The way asc_proc_copy() is written
  3737. * if 'prtbuf' is too small it will not be overwritten. Instead the
  3738. * user just won't get all the available statistics.
  3739. */
  3740. static int
  3741. advansys_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  3742. off_t offset, int length, int inout)
  3743. {
  3744. struct asc_board *boardp = shost_priv(shost);
  3745. char *cp;
  3746. int cplen;
  3747. int cnt;
  3748. int totcnt;
  3749. int leftlen;
  3750. char *curbuf;
  3751. off_t advoffset;
  3752. ASC_DBG(1, "begin\n");
  3753. /*
  3754. * User write not supported.
  3755. */
  3756. if (inout == TRUE)
  3757. return -ENOSYS;
  3758. /*
  3759. * User read of /proc/scsi/advansys/[0...] file.
  3760. */
  3761. /* Copy read data starting at the beginning of the buffer. */
  3762. *start = buffer;
  3763. curbuf = buffer;
  3764. advoffset = 0;
  3765. totcnt = 0;
  3766. leftlen = length;
  3767. /*
  3768. * Get board configuration information.
  3769. *
  3770. * advansys_info() returns the board string from its own static buffer.
  3771. */
  3772. cp = (char *)advansys_info(shost);
  3773. strcat(cp, "\n");
  3774. cplen = strlen(cp);
  3775. /* Copy board information. */
  3776. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3777. totcnt += cnt;
  3778. leftlen -= cnt;
  3779. if (leftlen == 0) {
  3780. ASC_DBG(1, "totcnt %d\n", totcnt);
  3781. return totcnt;
  3782. }
  3783. advoffset += cplen;
  3784. curbuf += cnt;
  3785. /*
  3786. * Display Wide Board BIOS Information.
  3787. */
  3788. if (!ASC_NARROW_BOARD(boardp)) {
  3789. cp = boardp->prtbuf;
  3790. cplen = asc_prt_adv_bios(shost, cp, ASC_PRTBUF_SIZE);
  3791. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3792. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp,
  3793. cplen);
  3794. totcnt += cnt;
  3795. leftlen -= cnt;
  3796. if (leftlen == 0) {
  3797. ASC_DBG(1, "totcnt %d\n", totcnt);
  3798. return totcnt;
  3799. }
  3800. advoffset += cplen;
  3801. curbuf += cnt;
  3802. }
  3803. /*
  3804. * Display driver information for each device attached to the board.
  3805. */
  3806. cp = boardp->prtbuf;
  3807. cplen = asc_prt_board_devices(shost, cp, ASC_PRTBUF_SIZE);
  3808. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3809. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3810. totcnt += cnt;
  3811. leftlen -= cnt;
  3812. if (leftlen == 0) {
  3813. ASC_DBG(1, "totcnt %d\n", totcnt);
  3814. return totcnt;
  3815. }
  3816. advoffset += cplen;
  3817. curbuf += cnt;
  3818. /*
  3819. * Display EEPROM configuration for the board.
  3820. */
  3821. cp = boardp->prtbuf;
  3822. if (ASC_NARROW_BOARD(boardp)) {
  3823. cplen = asc_prt_asc_board_eeprom(shost, cp, ASC_PRTBUF_SIZE);
  3824. } else {
  3825. cplen = asc_prt_adv_board_eeprom(shost, cp, ASC_PRTBUF_SIZE);
  3826. }
  3827. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3828. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3829. totcnt += cnt;
  3830. leftlen -= cnt;
  3831. if (leftlen == 0) {
  3832. ASC_DBG(1, "totcnt %d\n", totcnt);
  3833. return totcnt;
  3834. }
  3835. advoffset += cplen;
  3836. curbuf += cnt;
  3837. /*
  3838. * Display driver configuration and information for the board.
  3839. */
  3840. cp = boardp->prtbuf;
  3841. cplen = asc_prt_driver_conf(shost, cp, ASC_PRTBUF_SIZE);
  3842. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3843. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3844. totcnt += cnt;
  3845. leftlen -= cnt;
  3846. if (leftlen == 0) {
  3847. ASC_DBG(1, "totcnt %d\n", totcnt);
  3848. return totcnt;
  3849. }
  3850. advoffset += cplen;
  3851. curbuf += cnt;
  3852. #ifdef ADVANSYS_STATS
  3853. /*
  3854. * Display driver statistics for the board.
  3855. */
  3856. cp = boardp->prtbuf;
  3857. cplen = asc_prt_board_stats(shost, cp, ASC_PRTBUF_SIZE);
  3858. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3859. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3860. totcnt += cnt;
  3861. leftlen -= cnt;
  3862. if (leftlen == 0) {
  3863. ASC_DBG(1, "totcnt %d\n", totcnt);
  3864. return totcnt;
  3865. }
  3866. advoffset += cplen;
  3867. curbuf += cnt;
  3868. #endif /* ADVANSYS_STATS */
  3869. /*
  3870. * Display Asc Library dynamic configuration information
  3871. * for the board.
  3872. */
  3873. cp = boardp->prtbuf;
  3874. if (ASC_NARROW_BOARD(boardp)) {
  3875. cplen = asc_prt_asc_board_info(shost, cp, ASC_PRTBUF_SIZE);
  3876. } else {
  3877. cplen = asc_prt_adv_board_info(shost, cp, ASC_PRTBUF_SIZE);
  3878. }
  3879. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3880. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3881. totcnt += cnt;
  3882. leftlen -= cnt;
  3883. if (leftlen == 0) {
  3884. ASC_DBG(1, "totcnt %d\n", totcnt);
  3885. return totcnt;
  3886. }
  3887. advoffset += cplen;
  3888. curbuf += cnt;
  3889. ASC_DBG(1, "totcnt %d\n", totcnt);
  3890. return totcnt;
  3891. }
  3892. #endif /* CONFIG_PROC_FS */
  3893. static void asc_scsi_done(struct scsi_cmnd *scp)
  3894. {
  3895. scsi_dma_unmap(scp);
  3896. ASC_STATS(scp->device->host, done);
  3897. scp->scsi_done(scp);
  3898. }
  3899. static void AscSetBank(PortAddr iop_base, uchar bank)
  3900. {
  3901. uchar val;
  3902. val = AscGetChipControl(iop_base) &
  3903. (~
  3904. (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
  3905. CC_CHIP_RESET));
  3906. if (bank == 1) {
  3907. val |= CC_BANK_ONE;
  3908. } else if (bank == 2) {
  3909. val |= CC_DIAG | CC_BANK_ONE;
  3910. } else {
  3911. val &= ~CC_BANK_ONE;
  3912. }
  3913. AscSetChipControl(iop_base, val);
  3914. }
  3915. static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
  3916. {
  3917. AscSetBank(iop_base, 1);
  3918. AscWriteChipIH(iop_base, ins_code);
  3919. AscSetBank(iop_base, 0);
  3920. }
  3921. static int AscStartChip(PortAddr iop_base)
  3922. {
  3923. AscSetChipControl(iop_base, 0);
  3924. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3925. return (0);
  3926. }
  3927. return (1);
  3928. }
  3929. static int AscStopChip(PortAddr iop_base)
  3930. {
  3931. uchar cc_val;
  3932. cc_val =
  3933. AscGetChipControl(iop_base) &
  3934. (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
  3935. AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
  3936. AscSetChipIH(iop_base, INS_HALT);
  3937. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3938. if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
  3939. return (0);
  3940. }
  3941. return (1);
  3942. }
  3943. static int AscIsChipHalted(PortAddr iop_base)
  3944. {
  3945. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3946. if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
  3947. return (1);
  3948. }
  3949. }
  3950. return (0);
  3951. }
  3952. static int AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
  3953. {
  3954. PortAddr iop_base;
  3955. int i = 10;
  3956. iop_base = asc_dvc->iop_base;
  3957. while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
  3958. && (i-- > 0)) {
  3959. mdelay(100);
  3960. }
  3961. AscStopChip(iop_base);
  3962. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
  3963. udelay(60);
  3964. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3965. AscSetChipIH(iop_base, INS_HALT);
  3966. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
  3967. AscSetChipControl(iop_base, CC_HALT);
  3968. mdelay(200);
  3969. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  3970. AscSetChipStatus(iop_base, 0);
  3971. return (AscIsChipHalted(iop_base));
  3972. }
  3973. static int AscFindSignature(PortAddr iop_base)
  3974. {
  3975. ushort sig_word;
  3976. ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
  3977. iop_base, AscGetChipSignatureByte(iop_base));
  3978. if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
  3979. ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
  3980. iop_base, AscGetChipSignatureWord(iop_base));
  3981. sig_word = AscGetChipSignatureWord(iop_base);
  3982. if ((sig_word == (ushort)ASC_1000_ID0W) ||
  3983. (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
  3984. return (1);
  3985. }
  3986. }
  3987. return (0);
  3988. }
  3989. static void AscEnableInterrupt(PortAddr iop_base)
  3990. {
  3991. ushort cfg;
  3992. cfg = AscGetChipCfgLsw(iop_base);
  3993. AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
  3994. }
  3995. static void AscDisableInterrupt(PortAddr iop_base)
  3996. {
  3997. ushort cfg;
  3998. cfg = AscGetChipCfgLsw(iop_base);
  3999. AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
  4000. }
  4001. static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
  4002. {
  4003. unsigned char byte_data;
  4004. unsigned short word_data;
  4005. if (isodd_word(addr)) {
  4006. AscSetChipLramAddr(iop_base, addr - 1);
  4007. word_data = AscGetChipLramData(iop_base);
  4008. byte_data = (word_data >> 8) & 0xFF;
  4009. } else {
  4010. AscSetChipLramAddr(iop_base, addr);
  4011. word_data = AscGetChipLramData(iop_base);
  4012. byte_data = word_data & 0xFF;
  4013. }
  4014. return byte_data;
  4015. }
  4016. static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
  4017. {
  4018. ushort word_data;
  4019. AscSetChipLramAddr(iop_base, addr);
  4020. word_data = AscGetChipLramData(iop_base);
  4021. return (word_data);
  4022. }
  4023. #if CC_VERY_LONG_SG_LIST
  4024. static ASC_DCNT AscReadLramDWord(PortAddr iop_base, ushort addr)
  4025. {
  4026. ushort val_low, val_high;
  4027. ASC_DCNT dword_data;
  4028. AscSetChipLramAddr(iop_base, addr);
  4029. val_low = AscGetChipLramData(iop_base);
  4030. val_high = AscGetChipLramData(iop_base);
  4031. dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low;
  4032. return (dword_data);
  4033. }
  4034. #endif /* CC_VERY_LONG_SG_LIST */
  4035. static void
  4036. AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
  4037. {
  4038. int i;
  4039. AscSetChipLramAddr(iop_base, s_addr);
  4040. for (i = 0; i < words; i++) {
  4041. AscSetChipLramData(iop_base, set_wval);
  4042. }
  4043. }
  4044. static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
  4045. {
  4046. AscSetChipLramAddr(iop_base, addr);
  4047. AscSetChipLramData(iop_base, word_val);
  4048. }
  4049. static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
  4050. {
  4051. ushort word_data;
  4052. if (isodd_word(addr)) {
  4053. addr--;
  4054. word_data = AscReadLramWord(iop_base, addr);
  4055. word_data &= 0x00FF;
  4056. word_data |= (((ushort)byte_val << 8) & 0xFF00);
  4057. } else {
  4058. word_data = AscReadLramWord(iop_base, addr);
  4059. word_data &= 0xFF00;
  4060. word_data |= ((ushort)byte_val & 0x00FF);
  4061. }
  4062. AscWriteLramWord(iop_base, addr, word_data);
  4063. }
  4064. /*
  4065. * Copy 2 bytes to LRAM.
  4066. *
  4067. * The source data is assumed to be in little-endian order in memory
  4068. * and is maintained in little-endian order when written to LRAM.
  4069. */
  4070. static void
  4071. AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
  4072. const uchar *s_buffer, int words)
  4073. {
  4074. int i;
  4075. AscSetChipLramAddr(iop_base, s_addr);
  4076. for (i = 0; i < 2 * words; i += 2) {
  4077. /*
  4078. * On a little-endian system the second argument below
  4079. * produces a little-endian ushort which is written to
  4080. * LRAM in little-endian order. On a big-endian system
  4081. * the second argument produces a big-endian ushort which
  4082. * is "transparently" byte-swapped by outpw() and written
  4083. * in little-endian order to LRAM.
  4084. */
  4085. outpw(iop_base + IOP_RAM_DATA,
  4086. ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
  4087. }
  4088. }
  4089. /*
  4090. * Copy 4 bytes to LRAM.
  4091. *
  4092. * The source data is assumed to be in little-endian order in memory
  4093. * and is maintained in little-endian order when writen to LRAM.
  4094. */
  4095. static void
  4096. AscMemDWordCopyPtrToLram(PortAddr iop_base,
  4097. ushort s_addr, uchar *s_buffer, int dwords)
  4098. {
  4099. int i;
  4100. AscSetChipLramAddr(iop_base, s_addr);
  4101. for (i = 0; i < 4 * dwords; i += 4) {
  4102. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
  4103. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
  4104. }
  4105. }
  4106. /*
  4107. * Copy 2 bytes from LRAM.
  4108. *
  4109. * The source data is assumed to be in little-endian order in LRAM
  4110. * and is maintained in little-endian order when written to memory.
  4111. */
  4112. static void
  4113. AscMemWordCopyPtrFromLram(PortAddr iop_base,
  4114. ushort s_addr, uchar *d_buffer, int words)
  4115. {
  4116. int i;
  4117. ushort word;
  4118. AscSetChipLramAddr(iop_base, s_addr);
  4119. for (i = 0; i < 2 * words; i += 2) {
  4120. word = inpw(iop_base + IOP_RAM_DATA);
  4121. d_buffer[i] = word & 0xff;
  4122. d_buffer[i + 1] = (word >> 8) & 0xff;
  4123. }
  4124. }
  4125. static ASC_DCNT AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
  4126. {
  4127. ASC_DCNT sum;
  4128. int i;
  4129. sum = 0L;
  4130. for (i = 0; i < words; i++, s_addr += 2) {
  4131. sum += AscReadLramWord(iop_base, s_addr);
  4132. }
  4133. return (sum);
  4134. }
  4135. static ushort AscInitLram(ASC_DVC_VAR *asc_dvc)
  4136. {
  4137. uchar i;
  4138. ushort s_addr;
  4139. PortAddr iop_base;
  4140. ushort warn_code;
  4141. iop_base = asc_dvc->iop_base;
  4142. warn_code = 0;
  4143. AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
  4144. (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
  4145. 64) >> 1));
  4146. i = ASC_MIN_ACTIVE_QNO;
  4147. s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
  4148. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  4149. (uchar)(i + 1));
  4150. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  4151. (uchar)(asc_dvc->max_total_qng));
  4152. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  4153. (uchar)i);
  4154. i++;
  4155. s_addr += ASC_QBLK_SIZE;
  4156. for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
  4157. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  4158. (uchar)(i + 1));
  4159. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  4160. (uchar)(i - 1));
  4161. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  4162. (uchar)i);
  4163. }
  4164. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  4165. (uchar)ASC_QLINK_END);
  4166. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  4167. (uchar)(asc_dvc->max_total_qng - 1));
  4168. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  4169. (uchar)asc_dvc->max_total_qng);
  4170. i++;
  4171. s_addr += ASC_QBLK_SIZE;
  4172. for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
  4173. i++, s_addr += ASC_QBLK_SIZE) {
  4174. AscWriteLramByte(iop_base,
  4175. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
  4176. AscWriteLramByte(iop_base,
  4177. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
  4178. AscWriteLramByte(iop_base,
  4179. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
  4180. }
  4181. return warn_code;
  4182. }
  4183. static ASC_DCNT
  4184. AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
  4185. const uchar *mcode_buf, ushort mcode_size)
  4186. {
  4187. ASC_DCNT chksum;
  4188. ushort mcode_word_size;
  4189. ushort mcode_chksum;
  4190. /* Write the microcode buffer starting at LRAM address 0. */
  4191. mcode_word_size = (ushort)(mcode_size >> 1);
  4192. AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
  4193. AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
  4194. chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
  4195. ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
  4196. mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
  4197. (ushort)ASC_CODE_SEC_BEG,
  4198. (ushort)((mcode_size -
  4199. s_addr - (ushort)
  4200. ASC_CODE_SEC_BEG) /
  4201. 2));
  4202. ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
  4203. AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
  4204. AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
  4205. return chksum;
  4206. }
  4207. static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
  4208. {
  4209. PortAddr iop_base;
  4210. int i;
  4211. ushort lram_addr;
  4212. iop_base = asc_dvc->iop_base;
  4213. AscPutRiscVarFreeQHead(iop_base, 1);
  4214. AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  4215. AscPutVarFreeQHead(iop_base, 1);
  4216. AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  4217. AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
  4218. (uchar)((int)asc_dvc->max_total_qng + 1));
  4219. AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
  4220. (uchar)((int)asc_dvc->max_total_qng + 2));
  4221. AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
  4222. asc_dvc->max_total_qng);
  4223. AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
  4224. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  4225. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
  4226. AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
  4227. AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
  4228. AscPutQDoneInProgress(iop_base, 0);
  4229. lram_addr = ASC_QADR_BEG;
  4230. for (i = 0; i < 32; i++, lram_addr += 2) {
  4231. AscWriteLramWord(iop_base, lram_addr, 0);
  4232. }
  4233. }
  4234. static ushort AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
  4235. {
  4236. int i;
  4237. ushort warn_code;
  4238. PortAddr iop_base;
  4239. ASC_PADDR phy_addr;
  4240. ASC_DCNT phy_size;
  4241. struct asc_board *board = asc_dvc_to_board(asc_dvc);
  4242. iop_base = asc_dvc->iop_base;
  4243. warn_code = 0;
  4244. for (i = 0; i <= ASC_MAX_TID; i++) {
  4245. AscPutMCodeInitSDTRAtID(iop_base, i,
  4246. asc_dvc->cfg->sdtr_period_offset[i]);
  4247. }
  4248. AscInitQLinkVar(asc_dvc);
  4249. AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
  4250. asc_dvc->cfg->disc_enable);
  4251. AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
  4252. ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
  4253. /* Ensure overrun buffer is aligned on an 8 byte boundary. */
  4254. BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
  4255. asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
  4256. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  4257. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  4258. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  4259. (uchar *)&phy_addr, 1);
  4260. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  4261. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  4262. (uchar *)&phy_size, 1);
  4263. asc_dvc->cfg->mcode_date =
  4264. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  4265. asc_dvc->cfg->mcode_version =
  4266. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  4267. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  4268. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  4269. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  4270. return warn_code;
  4271. }
  4272. if (AscStartChip(iop_base) != 1) {
  4273. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  4274. return warn_code;
  4275. }
  4276. return warn_code;
  4277. }
  4278. static ushort AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  4279. {
  4280. const struct firmware *fw;
  4281. const char fwname[] = "advansys/mcode.bin";
  4282. int err;
  4283. unsigned long chksum;
  4284. ushort warn_code;
  4285. PortAddr iop_base;
  4286. iop_base = asc_dvc->iop_base;
  4287. warn_code = 0;
  4288. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  4289. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  4290. AscResetChipAndScsiBus(asc_dvc);
  4291. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4292. }
  4293. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  4294. if (asc_dvc->err_code != 0)
  4295. return UW_ERR;
  4296. if (!AscFindSignature(asc_dvc->iop_base)) {
  4297. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  4298. return warn_code;
  4299. }
  4300. AscDisableInterrupt(iop_base);
  4301. warn_code |= AscInitLram(asc_dvc);
  4302. if (asc_dvc->err_code != 0)
  4303. return UW_ERR;
  4304. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4305. if (err) {
  4306. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4307. fwname, err);
  4308. return err;
  4309. }
  4310. if (fw->size < 4) {
  4311. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4312. fw->size, fwname);
  4313. release_firmware(fw);
  4314. return -EINVAL;
  4315. }
  4316. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4317. (fw->data[1] << 8) | fw->data[0];
  4318. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  4319. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  4320. fw->size - 4) != chksum) {
  4321. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4322. release_firmware(fw);
  4323. return warn_code;
  4324. }
  4325. release_firmware(fw);
  4326. warn_code |= AscInitMicroCodeVar(asc_dvc);
  4327. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  4328. AscEnableInterrupt(iop_base);
  4329. return warn_code;
  4330. }
  4331. /*
  4332. * Load the Microcode
  4333. *
  4334. * Write the microcode image to RISC memory starting at address 0.
  4335. *
  4336. * The microcode is stored compressed in the following format:
  4337. *
  4338. * 254 word (508 byte) table indexed by byte code followed
  4339. * by the following byte codes:
  4340. *
  4341. * 1-Byte Code:
  4342. * 00: Emit word 0 in table.
  4343. * 01: Emit word 1 in table.
  4344. * .
  4345. * FD: Emit word 253 in table.
  4346. *
  4347. * Multi-Byte Code:
  4348. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  4349. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  4350. *
  4351. * Returns 0 or an error if the checksum doesn't match
  4352. */
  4353. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  4354. int size, int memsize, int chksum)
  4355. {
  4356. int i, j, end, len = 0;
  4357. ADV_DCNT sum;
  4358. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  4359. for (i = 253 * 2; i < size; i++) {
  4360. if (buf[i] == 0xff) {
  4361. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  4362. for (j = 0; j < buf[i + 1]; j++) {
  4363. AdvWriteWordAutoIncLram(iop_base, word);
  4364. len += 2;
  4365. }
  4366. i += 3;
  4367. } else if (buf[i] == 0xfe) {
  4368. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  4369. AdvWriteWordAutoIncLram(iop_base, word);
  4370. i += 2;
  4371. len += 2;
  4372. } else {
  4373. unsigned int off = buf[i] * 2;
  4374. unsigned short word = (buf[off + 1] << 8) | buf[off];
  4375. AdvWriteWordAutoIncLram(iop_base, word);
  4376. len += 2;
  4377. }
  4378. }
  4379. end = len;
  4380. while (len < memsize) {
  4381. AdvWriteWordAutoIncLram(iop_base, 0);
  4382. len += 2;
  4383. }
  4384. /* Verify the microcode checksum. */
  4385. sum = 0;
  4386. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  4387. for (len = 0; len < end; len += 2) {
  4388. sum += AdvReadWordAutoIncLram(iop_base);
  4389. }
  4390. if (sum != chksum)
  4391. return ASC_IERR_MCODE_CHKSUM;
  4392. return 0;
  4393. }
  4394. static void AdvBuildCarrierFreelist(struct adv_dvc_var *asc_dvc)
  4395. {
  4396. ADV_CARR_T *carrp;
  4397. ADV_SDCNT buf_size;
  4398. ADV_PADDR carr_paddr;
  4399. carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
  4400. asc_dvc->carr_freelist = NULL;
  4401. if (carrp == asc_dvc->carrier_buf) {
  4402. buf_size = ADV_CARRIER_BUFSIZE;
  4403. } else {
  4404. buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
  4405. }
  4406. do {
  4407. /* Get physical address of the carrier 'carrp'. */
  4408. carr_paddr = cpu_to_le32(virt_to_bus(carrp));
  4409. buf_size -= sizeof(ADV_CARR_T);
  4410. carrp->carr_pa = carr_paddr;
  4411. carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
  4412. /*
  4413. * Insert the carrier at the beginning of the freelist.
  4414. */
  4415. carrp->next_vpa =
  4416. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  4417. asc_dvc->carr_freelist = carrp;
  4418. carrp++;
  4419. } while (buf_size > 0);
  4420. }
  4421. /*
  4422. * Send an idle command to the chip and wait for completion.
  4423. *
  4424. * Command completion is polled for once per microsecond.
  4425. *
  4426. * The function can be called from anywhere including an interrupt handler.
  4427. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  4428. * functions to prevent reentrancy.
  4429. *
  4430. * Return Values:
  4431. * ADV_TRUE - command completed successfully
  4432. * ADV_FALSE - command failed
  4433. * ADV_ERROR - command timed out
  4434. */
  4435. static int
  4436. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  4437. ushort idle_cmd, ADV_DCNT idle_cmd_parameter)
  4438. {
  4439. int result;
  4440. ADV_DCNT i, j;
  4441. AdvPortAddr iop_base;
  4442. iop_base = asc_dvc->iop_base;
  4443. /*
  4444. * Clear the idle command status which is set by the microcode
  4445. * to a non-zero value to indicate when the command is completed.
  4446. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  4447. */
  4448. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  4449. /*
  4450. * Write the idle command value after the idle command parameter
  4451. * has been written to avoid a race condition. If the order is not
  4452. * followed, the microcode may process the idle command before the
  4453. * parameters have been written to LRAM.
  4454. */
  4455. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  4456. cpu_to_le32(idle_cmd_parameter));
  4457. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  4458. /*
  4459. * Tickle the RISC to tell it to process the idle command.
  4460. */
  4461. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  4462. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  4463. /*
  4464. * Clear the tickle value. In the ASC-3550 the RISC flag
  4465. * command 'clr_tickle_b' does not work unless the host
  4466. * value is cleared.
  4467. */
  4468. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  4469. }
  4470. /* Wait for up to 100 millisecond for the idle command to timeout. */
  4471. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  4472. /* Poll once each microsecond for command completion. */
  4473. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  4474. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  4475. result);
  4476. if (result != 0)
  4477. return result;
  4478. udelay(1);
  4479. }
  4480. }
  4481. BUG(); /* The idle command should never timeout. */
  4482. return ADV_ERROR;
  4483. }
  4484. /*
  4485. * Reset SCSI Bus and purge all outstanding requests.
  4486. *
  4487. * Return Value:
  4488. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  4489. * ADV_FALSE(0) - Microcode command failed.
  4490. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  4491. * may be hung which requires driver recovery.
  4492. */
  4493. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  4494. {
  4495. int status;
  4496. /*
  4497. * Send the SCSI Bus Reset idle start idle command which asserts
  4498. * the SCSI Bus Reset signal.
  4499. */
  4500. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  4501. if (status != ADV_TRUE) {
  4502. return status;
  4503. }
  4504. /*
  4505. * Delay for the specified SCSI Bus Reset hold time.
  4506. *
  4507. * The hold time delay is done on the host because the RISC has no
  4508. * microsecond accurate timer.
  4509. */
  4510. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  4511. /*
  4512. * Send the SCSI Bus Reset end idle command which de-asserts
  4513. * the SCSI Bus Reset signal and purges any pending requests.
  4514. */
  4515. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  4516. if (status != ADV_TRUE) {
  4517. return status;
  4518. }
  4519. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4520. return status;
  4521. }
  4522. /*
  4523. * Initialize the ASC-3550.
  4524. *
  4525. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4526. *
  4527. * For a non-fatal error return a warning code. If there are no warnings
  4528. * then 0 is returned.
  4529. *
  4530. * Needed after initialization for error recovery.
  4531. */
  4532. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  4533. {
  4534. const struct firmware *fw;
  4535. const char fwname[] = "advansys/3550.bin";
  4536. AdvPortAddr iop_base;
  4537. ushort warn_code;
  4538. int begin_addr;
  4539. int end_addr;
  4540. ushort code_sum;
  4541. int word;
  4542. int i;
  4543. int err;
  4544. unsigned long chksum;
  4545. ushort scsi_cfg1;
  4546. uchar tid;
  4547. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4548. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  4549. uchar max_cmd[ADV_MAX_TID + 1];
  4550. /* If there is already an error, don't continue. */
  4551. if (asc_dvc->err_code != 0)
  4552. return ADV_ERROR;
  4553. /*
  4554. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  4555. */
  4556. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  4557. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4558. return ADV_ERROR;
  4559. }
  4560. warn_code = 0;
  4561. iop_base = asc_dvc->iop_base;
  4562. /*
  4563. * Save the RISC memory BIOS region before writing the microcode.
  4564. * The BIOS may already be loaded and using its RISC LRAM region
  4565. * so its region must be saved and restored.
  4566. *
  4567. * Note: This code makes the assumption, which is currently true,
  4568. * that a chip reset does not clear RISC LRAM.
  4569. */
  4570. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4571. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4572. bios_mem[i]);
  4573. }
  4574. /*
  4575. * Save current per TID negotiated values.
  4576. */
  4577. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  4578. ushort bios_version, major, minor;
  4579. bios_version =
  4580. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  4581. major = (bios_version >> 12) & 0xF;
  4582. minor = (bios_version >> 8) & 0xF;
  4583. if (major < 3 || (major == 3 && minor == 1)) {
  4584. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  4585. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  4586. } else {
  4587. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4588. }
  4589. }
  4590. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4591. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4592. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4593. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4594. max_cmd[tid]);
  4595. }
  4596. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4597. if (err) {
  4598. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4599. fwname, err);
  4600. return err;
  4601. }
  4602. if (fw->size < 4) {
  4603. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4604. fw->size, fwname);
  4605. release_firmware(fw);
  4606. return -EINVAL;
  4607. }
  4608. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4609. (fw->data[1] << 8) | fw->data[0];
  4610. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4611. fw->size - 4, ADV_3550_MEMSIZE,
  4612. chksum);
  4613. release_firmware(fw);
  4614. if (asc_dvc->err_code)
  4615. return ADV_ERROR;
  4616. /*
  4617. * Restore the RISC memory BIOS region.
  4618. */
  4619. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4620. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4621. bios_mem[i]);
  4622. }
  4623. /*
  4624. * Calculate and write the microcode code checksum to the microcode
  4625. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4626. */
  4627. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4628. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4629. code_sum = 0;
  4630. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4631. for (word = begin_addr; word < end_addr; word += 2) {
  4632. code_sum += AdvReadWordAutoIncLram(iop_base);
  4633. }
  4634. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4635. /*
  4636. * Read and save microcode version and date.
  4637. */
  4638. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4639. asc_dvc->cfg->mcode_date);
  4640. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4641. asc_dvc->cfg->mcode_version);
  4642. /*
  4643. * Set the chip type to indicate the ASC3550.
  4644. */
  4645. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  4646. /*
  4647. * If the PCI Configuration Command Register "Parity Error Response
  4648. * Control" Bit was clear (0), then set the microcode variable
  4649. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4650. * to ignore DMA parity errors.
  4651. */
  4652. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4653. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4654. word |= CONTROL_FLAG_IGNORE_PERR;
  4655. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4656. }
  4657. /*
  4658. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4659. * threshold of 128 bytes. This register is only accessible to the host.
  4660. */
  4661. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4662. START_CTL_EMFU | READ_CMD_MRM);
  4663. /*
  4664. * Microcode operating variables for WDTR, SDTR, and command tag
  4665. * queuing will be set in slave_configure() based on what a
  4666. * device reports it is capable of in Inquiry byte 7.
  4667. *
  4668. * If SCSI Bus Resets have been disabled, then directly set
  4669. * SDTR and WDTR from the EEPROM configuration. This will allow
  4670. * the BIOS and warm boot to work without a SCSI bus hang on
  4671. * the Inquiry caused by host and target mismatched DTR values.
  4672. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4673. * be assumed to be in Asynchronous, Narrow mode.
  4674. */
  4675. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4676. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4677. asc_dvc->wdtr_able);
  4678. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4679. asc_dvc->sdtr_able);
  4680. }
  4681. /*
  4682. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4683. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4684. * bitmask. These values determine the maximum SDTR speed negotiated
  4685. * with a device.
  4686. *
  4687. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4688. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4689. * without determining here whether the device supports SDTR.
  4690. *
  4691. * 4-bit speed SDTR speed name
  4692. * =========== ===============
  4693. * 0000b (0x0) SDTR disabled
  4694. * 0001b (0x1) 5 Mhz
  4695. * 0010b (0x2) 10 Mhz
  4696. * 0011b (0x3) 20 Mhz (Ultra)
  4697. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4698. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4699. * 0110b (0x6) Undefined
  4700. * .
  4701. * 1111b (0xF) Undefined
  4702. */
  4703. word = 0;
  4704. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4705. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4706. /* Set Ultra speed for TID 'tid'. */
  4707. word |= (0x3 << (4 * (tid % 4)));
  4708. } else {
  4709. /* Set Fast speed for TID 'tid'. */
  4710. word |= (0x2 << (4 * (tid % 4)));
  4711. }
  4712. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4713. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4714. word = 0;
  4715. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4716. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4717. word = 0;
  4718. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4719. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4720. word = 0;
  4721. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4722. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4723. /* End of loop. */
  4724. }
  4725. }
  4726. /*
  4727. * Set microcode operating variable for the disconnect per TID bitmask.
  4728. */
  4729. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4730. asc_dvc->cfg->disc_enable);
  4731. /*
  4732. * Set SCSI_CFG0 Microcode Default Value.
  4733. *
  4734. * The microcode will set the SCSI_CFG0 register using this value
  4735. * after it is started below.
  4736. */
  4737. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4738. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4739. asc_dvc->chip_scsi_id);
  4740. /*
  4741. * Determine SCSI_CFG1 Microcode Default Value.
  4742. *
  4743. * The microcode will set the SCSI_CFG1 register using this value
  4744. * after it is started below.
  4745. */
  4746. /* Read current SCSI_CFG1 Register value. */
  4747. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4748. /*
  4749. * If all three connectors are in use, return an error.
  4750. */
  4751. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4752. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4753. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4754. return ADV_ERROR;
  4755. }
  4756. /*
  4757. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4758. * register signals will be set. Check for and return an error if
  4759. * this condition is found.
  4760. */
  4761. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4762. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4763. return ADV_ERROR;
  4764. }
  4765. /*
  4766. * If this is a differential board and a single-ended device
  4767. * is attached to one of the connectors, return an error.
  4768. */
  4769. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4770. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4771. return ADV_ERROR;
  4772. }
  4773. /*
  4774. * If automatic termination control is enabled, then set the
  4775. * termination value based on a table listed in a_condor.h.
  4776. *
  4777. * If manual termination was specified with an EEPROM setting
  4778. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4779. * is ready to be 'ored' into SCSI_CFG1.
  4780. */
  4781. if (asc_dvc->cfg->termination == 0) {
  4782. /*
  4783. * The software always controls termination by setting TERM_CTL_SEL.
  4784. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4785. */
  4786. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4787. switch (scsi_cfg1 & CABLE_DETECT) {
  4788. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4789. case 0x3:
  4790. case 0x7:
  4791. case 0xB:
  4792. case 0xD:
  4793. case 0xE:
  4794. case 0xF:
  4795. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4796. break;
  4797. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4798. case 0x1:
  4799. case 0x5:
  4800. case 0x9:
  4801. case 0xA:
  4802. case 0xC:
  4803. asc_dvc->cfg->termination |= TERM_CTL_H;
  4804. break;
  4805. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4806. case 0x2:
  4807. case 0x6:
  4808. break;
  4809. }
  4810. }
  4811. /*
  4812. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4813. */
  4814. scsi_cfg1 &= ~TERM_CTL;
  4815. /*
  4816. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4817. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4818. * referenced, because the hardware internally inverts
  4819. * the Termination High and Low bits if TERM_POL is set.
  4820. */
  4821. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4822. /*
  4823. * Set SCSI_CFG1 Microcode Default Value
  4824. *
  4825. * Set filter value and possibly modified termination control
  4826. * bits in the Microcode SCSI_CFG1 Register Value.
  4827. *
  4828. * The microcode will set the SCSI_CFG1 register using this value
  4829. * after it is started below.
  4830. */
  4831. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4832. FLTR_DISABLE | scsi_cfg1);
  4833. /*
  4834. * Set MEM_CFG Microcode Default Value
  4835. *
  4836. * The microcode will set the MEM_CFG register using this value
  4837. * after it is started below.
  4838. *
  4839. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4840. * are defined.
  4841. *
  4842. * ASC-3550 has 8KB internal memory.
  4843. */
  4844. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4845. BIOS_EN | RAM_SZ_8KB);
  4846. /*
  4847. * Set SEL_MASK Microcode Default Value
  4848. *
  4849. * The microcode will set the SEL_MASK register using this value
  4850. * after it is started below.
  4851. */
  4852. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4853. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4854. AdvBuildCarrierFreelist(asc_dvc);
  4855. /*
  4856. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4857. */
  4858. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  4859. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4860. return ADV_ERROR;
  4861. }
  4862. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4863. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  4864. /*
  4865. * The first command issued will be placed in the stopper carrier.
  4866. */
  4867. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4868. /*
  4869. * Set RISC ICQ physical address start value.
  4870. */
  4871. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4872. /*
  4873. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4874. */
  4875. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  4876. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4877. return ADV_ERROR;
  4878. }
  4879. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4880. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  4881. /*
  4882. * The first command completed by the RISC will be placed in
  4883. * the stopper.
  4884. *
  4885. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  4886. * completed the RISC will set the ASC_RQ_STOPPER bit.
  4887. */
  4888. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4889. /*
  4890. * Set RISC IRQ physical address start value.
  4891. */
  4892. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4893. asc_dvc->carr_pending_cnt = 0;
  4894. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4895. (ADV_INTR_ENABLE_HOST_INTR |
  4896. ADV_INTR_ENABLE_GLOBAL_INTR));
  4897. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4898. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4899. /* finally, finally, gentlemen, start your engine */
  4900. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4901. /*
  4902. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4903. * Resets should be performed. The RISC has to be running
  4904. * to issue a SCSI Bus Reset.
  4905. */
  4906. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4907. /*
  4908. * If the BIOS Signature is present in memory, restore the
  4909. * BIOS Handshake Configuration Table and do not perform
  4910. * a SCSI Bus Reset.
  4911. */
  4912. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4913. 0x55AA) {
  4914. /*
  4915. * Restore per TID negotiated values.
  4916. */
  4917. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4918. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4919. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4920. tagqng_able);
  4921. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4922. AdvWriteByteLram(iop_base,
  4923. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4924. max_cmd[tid]);
  4925. }
  4926. } else {
  4927. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4928. warn_code = ASC_WARN_BUSRESET_ERROR;
  4929. }
  4930. }
  4931. }
  4932. return warn_code;
  4933. }
  4934. /*
  4935. * Initialize the ASC-38C0800.
  4936. *
  4937. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4938. *
  4939. * For a non-fatal error return a warning code. If there are no warnings
  4940. * then 0 is returned.
  4941. *
  4942. * Needed after initialization for error recovery.
  4943. */
  4944. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4945. {
  4946. const struct firmware *fw;
  4947. const char fwname[] = "advansys/38C0800.bin";
  4948. AdvPortAddr iop_base;
  4949. ushort warn_code;
  4950. int begin_addr;
  4951. int end_addr;
  4952. ushort code_sum;
  4953. int word;
  4954. int i;
  4955. int err;
  4956. unsigned long chksum;
  4957. ushort scsi_cfg1;
  4958. uchar byte;
  4959. uchar tid;
  4960. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4961. ushort wdtr_able, sdtr_able, tagqng_able;
  4962. uchar max_cmd[ADV_MAX_TID + 1];
  4963. /* If there is already an error, don't continue. */
  4964. if (asc_dvc->err_code != 0)
  4965. return ADV_ERROR;
  4966. /*
  4967. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4968. */
  4969. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4970. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4971. return ADV_ERROR;
  4972. }
  4973. warn_code = 0;
  4974. iop_base = asc_dvc->iop_base;
  4975. /*
  4976. * Save the RISC memory BIOS region before writing the microcode.
  4977. * The BIOS may already be loaded and using its RISC LRAM region
  4978. * so its region must be saved and restored.
  4979. *
  4980. * Note: This code makes the assumption, which is currently true,
  4981. * that a chip reset does not clear RISC LRAM.
  4982. */
  4983. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4984. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4985. bios_mem[i]);
  4986. }
  4987. /*
  4988. * Save current per TID negotiated values.
  4989. */
  4990. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4991. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4992. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4993. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4994. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4995. max_cmd[tid]);
  4996. }
  4997. /*
  4998. * RAM BIST (RAM Built-In Self Test)
  4999. *
  5000. * Address : I/O base + offset 0x38h register (byte).
  5001. * Function: Bit 7-6(RW) : RAM mode
  5002. * Normal Mode : 0x00
  5003. * Pre-test Mode : 0x40
  5004. * RAM Test Mode : 0x80
  5005. * Bit 5 : unused
  5006. * Bit 4(RO) : Done bit
  5007. * Bit 3-0(RO) : Status
  5008. * Host Error : 0x08
  5009. * Int_RAM Error : 0x04
  5010. * RISC Error : 0x02
  5011. * SCSI Error : 0x01
  5012. * No Error : 0x00
  5013. *
  5014. * Note: RAM BIST code should be put right here, before loading the
  5015. * microcode and after saving the RISC memory BIOS region.
  5016. */
  5017. /*
  5018. * LRAM Pre-test
  5019. *
  5020. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5021. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5022. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5023. * to NORMAL_MODE, return an error too.
  5024. */
  5025. for (i = 0; i < 2; i++) {
  5026. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5027. mdelay(10); /* Wait for 10ms before reading back. */
  5028. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5029. if ((byte & RAM_TEST_DONE) == 0
  5030. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5031. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5032. return ADV_ERROR;
  5033. }
  5034. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5035. mdelay(10); /* Wait for 10ms before reading back. */
  5036. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5037. != NORMAL_VALUE) {
  5038. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5039. return ADV_ERROR;
  5040. }
  5041. }
  5042. /*
  5043. * LRAM Test - It takes about 1.5 ms to run through the test.
  5044. *
  5045. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5046. * If Done bit not set or Status not 0, save register byte, set the
  5047. * err_code, and return an error.
  5048. */
  5049. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5050. mdelay(10); /* Wait for 10ms before checking status. */
  5051. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5052. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5053. /* Get here if Done bit not set or Status not 0. */
  5054. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5055. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5056. return ADV_ERROR;
  5057. }
  5058. /* We need to reset back to normal mode after LRAM test passes. */
  5059. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5060. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5061. if (err) {
  5062. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5063. fwname, err);
  5064. return err;
  5065. }
  5066. if (fw->size < 4) {
  5067. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5068. fw->size, fwname);
  5069. release_firmware(fw);
  5070. return -EINVAL;
  5071. }
  5072. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5073. (fw->data[1] << 8) | fw->data[0];
  5074. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5075. fw->size - 4, ADV_38C0800_MEMSIZE,
  5076. chksum);
  5077. release_firmware(fw);
  5078. if (asc_dvc->err_code)
  5079. return ADV_ERROR;
  5080. /*
  5081. * Restore the RISC memory BIOS region.
  5082. */
  5083. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5084. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5085. bios_mem[i]);
  5086. }
  5087. /*
  5088. * Calculate and write the microcode code checksum to the microcode
  5089. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5090. */
  5091. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5092. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5093. code_sum = 0;
  5094. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5095. for (word = begin_addr; word < end_addr; word += 2) {
  5096. code_sum += AdvReadWordAutoIncLram(iop_base);
  5097. }
  5098. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5099. /*
  5100. * Read microcode version and date.
  5101. */
  5102. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5103. asc_dvc->cfg->mcode_date);
  5104. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5105. asc_dvc->cfg->mcode_version);
  5106. /*
  5107. * Set the chip type to indicate the ASC38C0800.
  5108. */
  5109. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  5110. /*
  5111. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5112. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5113. * cable detection and then we are able to read C_DET[3:0].
  5114. *
  5115. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5116. * Microcode Default Value' section below.
  5117. */
  5118. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5119. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5120. scsi_cfg1 | DIS_TERM_DRV);
  5121. /*
  5122. * If the PCI Configuration Command Register "Parity Error Response
  5123. * Control" Bit was clear (0), then set the microcode variable
  5124. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5125. * to ignore DMA parity errors.
  5126. */
  5127. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5128. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5129. word |= CONTROL_FLAG_IGNORE_PERR;
  5130. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5131. }
  5132. /*
  5133. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  5134. * bits for the default FIFO threshold.
  5135. *
  5136. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  5137. *
  5138. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  5139. */
  5140. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5141. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  5142. READ_CMD_MRM);
  5143. /*
  5144. * Microcode operating variables for WDTR, SDTR, and command tag
  5145. * queuing will be set in slave_configure() based on what a
  5146. * device reports it is capable of in Inquiry byte 7.
  5147. *
  5148. * If SCSI Bus Resets have been disabled, then directly set
  5149. * SDTR and WDTR from the EEPROM configuration. This will allow
  5150. * the BIOS and warm boot to work without a SCSI bus hang on
  5151. * the Inquiry caused by host and target mismatched DTR values.
  5152. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5153. * be assumed to be in Asynchronous, Narrow mode.
  5154. */
  5155. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5156. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5157. asc_dvc->wdtr_able);
  5158. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5159. asc_dvc->sdtr_able);
  5160. }
  5161. /*
  5162. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5163. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5164. * configuration values.
  5165. *
  5166. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5167. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5168. * without determining here whether the device supports SDTR.
  5169. */
  5170. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5171. asc_dvc->cfg->disc_enable);
  5172. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5173. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5174. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5175. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5176. /*
  5177. * Set SCSI_CFG0 Microcode Default Value.
  5178. *
  5179. * The microcode will set the SCSI_CFG0 register using this value
  5180. * after it is started below.
  5181. */
  5182. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5183. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5184. asc_dvc->chip_scsi_id);
  5185. /*
  5186. * Determine SCSI_CFG1 Microcode Default Value.
  5187. *
  5188. * The microcode will set the SCSI_CFG1 register using this value
  5189. * after it is started below.
  5190. */
  5191. /* Read current SCSI_CFG1 Register value. */
  5192. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5193. /*
  5194. * If the internal narrow cable is reversed all of the SCSI_CTRL
  5195. * register signals will be set. Check for and return an error if
  5196. * this condition is found.
  5197. */
  5198. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5199. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5200. return ADV_ERROR;
  5201. }
  5202. /*
  5203. * All kind of combinations of devices attached to one of four
  5204. * connectors are acceptable except HVD device attached. For example,
  5205. * LVD device can be attached to SE connector while SE device attached
  5206. * to LVD connector. If LVD device attached to SE connector, it only
  5207. * runs up to Ultra speed.
  5208. *
  5209. * If an HVD device is attached to one of LVD connectors, return an
  5210. * error. However, there is no way to detect HVD device attached to
  5211. * SE connectors.
  5212. */
  5213. if (scsi_cfg1 & HVD) {
  5214. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  5215. return ADV_ERROR;
  5216. }
  5217. /*
  5218. * If either SE or LVD automatic termination control is enabled, then
  5219. * set the termination value based on a table listed in a_condor.h.
  5220. *
  5221. * If manual termination was specified with an EEPROM setting then
  5222. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  5223. * to be 'ored' into SCSI_CFG1.
  5224. */
  5225. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5226. /* SE automatic termination control is enabled. */
  5227. switch (scsi_cfg1 & C_DET_SE) {
  5228. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5229. case 0x1:
  5230. case 0x2:
  5231. case 0x3:
  5232. asc_dvc->cfg->termination |= TERM_SE;
  5233. break;
  5234. /* TERM_SE_HI: on, TERM_SE_LO: off */
  5235. case 0x0:
  5236. asc_dvc->cfg->termination |= TERM_SE_HI;
  5237. break;
  5238. }
  5239. }
  5240. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  5241. /* LVD automatic termination control is enabled. */
  5242. switch (scsi_cfg1 & C_DET_LVD) {
  5243. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  5244. case 0x4:
  5245. case 0x8:
  5246. case 0xC:
  5247. asc_dvc->cfg->termination |= TERM_LVD;
  5248. break;
  5249. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  5250. case 0x0:
  5251. break;
  5252. }
  5253. }
  5254. /*
  5255. * Clear any set TERM_SE and TERM_LVD bits.
  5256. */
  5257. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  5258. /*
  5259. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  5260. */
  5261. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  5262. /*
  5263. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  5264. * bits and set possibly modified termination control bits in the
  5265. * Microcode SCSI_CFG1 Register Value.
  5266. */
  5267. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  5268. /*
  5269. * Set SCSI_CFG1 Microcode Default Value
  5270. *
  5271. * Set possibly modified termination control and reset DIS_TERM_DRV
  5272. * bits in the Microcode SCSI_CFG1 Register Value.
  5273. *
  5274. * The microcode will set the SCSI_CFG1 register using this value
  5275. * after it is started below.
  5276. */
  5277. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5278. /*
  5279. * Set MEM_CFG Microcode Default Value
  5280. *
  5281. * The microcode will set the MEM_CFG register using this value
  5282. * after it is started below.
  5283. *
  5284. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5285. * are defined.
  5286. *
  5287. * ASC-38C0800 has 16KB internal memory.
  5288. */
  5289. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5290. BIOS_EN | RAM_SZ_16KB);
  5291. /*
  5292. * Set SEL_MASK Microcode Default Value
  5293. *
  5294. * The microcode will set the SEL_MASK register using this value
  5295. * after it is started below.
  5296. */
  5297. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5298. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5299. AdvBuildCarrierFreelist(asc_dvc);
  5300. /*
  5301. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5302. */
  5303. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5304. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5305. return ADV_ERROR;
  5306. }
  5307. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5308. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5309. /*
  5310. * The first command issued will be placed in the stopper carrier.
  5311. */
  5312. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5313. /*
  5314. * Set RISC ICQ physical address start value.
  5315. * carr_pa is LE, must be native before write
  5316. */
  5317. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5318. /*
  5319. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5320. */
  5321. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5322. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5323. return ADV_ERROR;
  5324. }
  5325. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5326. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5327. /*
  5328. * The first command completed by the RISC will be placed in
  5329. * the stopper.
  5330. *
  5331. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5332. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5333. */
  5334. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5335. /*
  5336. * Set RISC IRQ physical address start value.
  5337. *
  5338. * carr_pa is LE, must be native before write *
  5339. */
  5340. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5341. asc_dvc->carr_pending_cnt = 0;
  5342. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5343. (ADV_INTR_ENABLE_HOST_INTR |
  5344. ADV_INTR_ENABLE_GLOBAL_INTR));
  5345. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5346. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5347. /* finally, finally, gentlemen, start your engine */
  5348. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5349. /*
  5350. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5351. * Resets should be performed. The RISC has to be running
  5352. * to issue a SCSI Bus Reset.
  5353. */
  5354. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5355. /*
  5356. * If the BIOS Signature is present in memory, restore the
  5357. * BIOS Handshake Configuration Table and do not perform
  5358. * a SCSI Bus Reset.
  5359. */
  5360. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5361. 0x55AA) {
  5362. /*
  5363. * Restore per TID negotiated values.
  5364. */
  5365. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5366. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5367. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5368. tagqng_able);
  5369. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5370. AdvWriteByteLram(iop_base,
  5371. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5372. max_cmd[tid]);
  5373. }
  5374. } else {
  5375. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5376. warn_code = ASC_WARN_BUSRESET_ERROR;
  5377. }
  5378. }
  5379. }
  5380. return warn_code;
  5381. }
  5382. /*
  5383. * Initialize the ASC-38C1600.
  5384. *
  5385. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  5386. *
  5387. * For a non-fatal error return a warning code. If there are no warnings
  5388. * then 0 is returned.
  5389. *
  5390. * Needed after initialization for error recovery.
  5391. */
  5392. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  5393. {
  5394. const struct firmware *fw;
  5395. const char fwname[] = "advansys/38C1600.bin";
  5396. AdvPortAddr iop_base;
  5397. ushort warn_code;
  5398. int begin_addr;
  5399. int end_addr;
  5400. ushort code_sum;
  5401. long word;
  5402. int i;
  5403. int err;
  5404. unsigned long chksum;
  5405. ushort scsi_cfg1;
  5406. uchar byte;
  5407. uchar tid;
  5408. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  5409. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  5410. uchar max_cmd[ASC_MAX_TID + 1];
  5411. /* If there is already an error, don't continue. */
  5412. if (asc_dvc->err_code != 0) {
  5413. return ADV_ERROR;
  5414. }
  5415. /*
  5416. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  5417. */
  5418. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  5419. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  5420. return ADV_ERROR;
  5421. }
  5422. warn_code = 0;
  5423. iop_base = asc_dvc->iop_base;
  5424. /*
  5425. * Save the RISC memory BIOS region before writing the microcode.
  5426. * The BIOS may already be loaded and using its RISC LRAM region
  5427. * so its region must be saved and restored.
  5428. *
  5429. * Note: This code makes the assumption, which is currently true,
  5430. * that a chip reset does not clear RISC LRAM.
  5431. */
  5432. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5433. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5434. bios_mem[i]);
  5435. }
  5436. /*
  5437. * Save current per TID negotiated values.
  5438. */
  5439. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5440. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5441. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5442. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5443. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5444. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5445. max_cmd[tid]);
  5446. }
  5447. /*
  5448. * RAM BIST (Built-In Self Test)
  5449. *
  5450. * Address : I/O base + offset 0x38h register (byte).
  5451. * Function: Bit 7-6(RW) : RAM mode
  5452. * Normal Mode : 0x00
  5453. * Pre-test Mode : 0x40
  5454. * RAM Test Mode : 0x80
  5455. * Bit 5 : unused
  5456. * Bit 4(RO) : Done bit
  5457. * Bit 3-0(RO) : Status
  5458. * Host Error : 0x08
  5459. * Int_RAM Error : 0x04
  5460. * RISC Error : 0x02
  5461. * SCSI Error : 0x01
  5462. * No Error : 0x00
  5463. *
  5464. * Note: RAM BIST code should be put right here, before loading the
  5465. * microcode and after saving the RISC memory BIOS region.
  5466. */
  5467. /*
  5468. * LRAM Pre-test
  5469. *
  5470. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5471. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5472. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5473. * to NORMAL_MODE, return an error too.
  5474. */
  5475. for (i = 0; i < 2; i++) {
  5476. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5477. mdelay(10); /* Wait for 10ms before reading back. */
  5478. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5479. if ((byte & RAM_TEST_DONE) == 0
  5480. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5481. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5482. return ADV_ERROR;
  5483. }
  5484. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5485. mdelay(10); /* Wait for 10ms before reading back. */
  5486. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5487. != NORMAL_VALUE) {
  5488. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5489. return ADV_ERROR;
  5490. }
  5491. }
  5492. /*
  5493. * LRAM Test - It takes about 1.5 ms to run through the test.
  5494. *
  5495. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5496. * If Done bit not set or Status not 0, save register byte, set the
  5497. * err_code, and return an error.
  5498. */
  5499. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5500. mdelay(10); /* Wait for 10ms before checking status. */
  5501. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5502. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5503. /* Get here if Done bit not set or Status not 0. */
  5504. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5505. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5506. return ADV_ERROR;
  5507. }
  5508. /* We need to reset back to normal mode after LRAM test passes. */
  5509. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5510. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5511. if (err) {
  5512. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5513. fwname, err);
  5514. return err;
  5515. }
  5516. if (fw->size < 4) {
  5517. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5518. fw->size, fwname);
  5519. release_firmware(fw);
  5520. return -EINVAL;
  5521. }
  5522. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5523. (fw->data[1] << 8) | fw->data[0];
  5524. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5525. fw->size - 4, ADV_38C1600_MEMSIZE,
  5526. chksum);
  5527. release_firmware(fw);
  5528. if (asc_dvc->err_code)
  5529. return ADV_ERROR;
  5530. /*
  5531. * Restore the RISC memory BIOS region.
  5532. */
  5533. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5534. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5535. bios_mem[i]);
  5536. }
  5537. /*
  5538. * Calculate and write the microcode code checksum to the microcode
  5539. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5540. */
  5541. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5542. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5543. code_sum = 0;
  5544. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5545. for (word = begin_addr; word < end_addr; word += 2) {
  5546. code_sum += AdvReadWordAutoIncLram(iop_base);
  5547. }
  5548. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5549. /*
  5550. * Read microcode version and date.
  5551. */
  5552. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5553. asc_dvc->cfg->mcode_date);
  5554. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5555. asc_dvc->cfg->mcode_version);
  5556. /*
  5557. * Set the chip type to indicate the ASC38C1600.
  5558. */
  5559. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  5560. /*
  5561. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5562. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5563. * cable detection and then we are able to read C_DET[3:0].
  5564. *
  5565. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5566. * Microcode Default Value' section below.
  5567. */
  5568. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5569. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5570. scsi_cfg1 | DIS_TERM_DRV);
  5571. /*
  5572. * If the PCI Configuration Command Register "Parity Error Response
  5573. * Control" Bit was clear (0), then set the microcode variable
  5574. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5575. * to ignore DMA parity errors.
  5576. */
  5577. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5578. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5579. word |= CONTROL_FLAG_IGNORE_PERR;
  5580. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5581. }
  5582. /*
  5583. * If the BIOS control flag AIPP (Asynchronous Information
  5584. * Phase Protection) disable bit is not set, then set the firmware
  5585. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  5586. * AIPP checking and encoding.
  5587. */
  5588. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  5589. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5590. word |= CONTROL_FLAG_ENABLE_AIPP;
  5591. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5592. }
  5593. /*
  5594. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  5595. * and START_CTL_TH [3:2].
  5596. */
  5597. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5598. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  5599. /*
  5600. * Microcode operating variables for WDTR, SDTR, and command tag
  5601. * queuing will be set in slave_configure() based on what a
  5602. * device reports it is capable of in Inquiry byte 7.
  5603. *
  5604. * If SCSI Bus Resets have been disabled, then directly set
  5605. * SDTR and WDTR from the EEPROM configuration. This will allow
  5606. * the BIOS and warm boot to work without a SCSI bus hang on
  5607. * the Inquiry caused by host and target mismatched DTR values.
  5608. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5609. * be assumed to be in Asynchronous, Narrow mode.
  5610. */
  5611. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5612. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5613. asc_dvc->wdtr_able);
  5614. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5615. asc_dvc->sdtr_able);
  5616. }
  5617. /*
  5618. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5619. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5620. * configuration values.
  5621. *
  5622. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5623. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5624. * without determining here whether the device supports SDTR.
  5625. */
  5626. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5627. asc_dvc->cfg->disc_enable);
  5628. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5629. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5630. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5631. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5632. /*
  5633. * Set SCSI_CFG0 Microcode Default Value.
  5634. *
  5635. * The microcode will set the SCSI_CFG0 register using this value
  5636. * after it is started below.
  5637. */
  5638. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5639. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5640. asc_dvc->chip_scsi_id);
  5641. /*
  5642. * Calculate SCSI_CFG1 Microcode Default Value.
  5643. *
  5644. * The microcode will set the SCSI_CFG1 register using this value
  5645. * after it is started below.
  5646. *
  5647. * Each ASC-38C1600 function has only two cable detect bits.
  5648. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  5649. */
  5650. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5651. /*
  5652. * If the cable is reversed all of the SCSI_CTRL register signals
  5653. * will be set. Check for and return an error if this condition is
  5654. * found.
  5655. */
  5656. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5657. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5658. return ADV_ERROR;
  5659. }
  5660. /*
  5661. * Each ASC-38C1600 function has two connectors. Only an HVD device
  5662. * can not be connected to either connector. An LVD device or SE device
  5663. * may be connected to either connecor. If an SE device is connected,
  5664. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  5665. *
  5666. * If an HVD device is attached, return an error.
  5667. */
  5668. if (scsi_cfg1 & HVD) {
  5669. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5670. return ADV_ERROR;
  5671. }
  5672. /*
  5673. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5674. * termination because there are two connectors for each function. Each
  5675. * function may use either LVD or SE mode. Corresponding the SE automatic
  5676. * termination control EEPROM bits are used for each function. Each
  5677. * function has its own EEPROM. If SE automatic control is enabled for
  5678. * the function, then set the termination value based on a table listed
  5679. * in a_condor.h.
  5680. *
  5681. * If manual termination is specified in the EEPROM for the function,
  5682. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5683. * ready to be 'ored' into SCSI_CFG1.
  5684. */
  5685. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5686. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5687. /* SE automatic termination control is enabled. */
  5688. switch (scsi_cfg1 & C_DET_SE) {
  5689. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5690. case 0x1:
  5691. case 0x2:
  5692. case 0x3:
  5693. asc_dvc->cfg->termination |= TERM_SE;
  5694. break;
  5695. case 0x0:
  5696. if (PCI_FUNC(pdev->devfn) == 0) {
  5697. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5698. } else {
  5699. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5700. asc_dvc->cfg->termination |= TERM_SE_HI;
  5701. }
  5702. break;
  5703. }
  5704. }
  5705. /*
  5706. * Clear any set TERM_SE bits.
  5707. */
  5708. scsi_cfg1 &= ~TERM_SE;
  5709. /*
  5710. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5711. */
  5712. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5713. /*
  5714. * Clear Big Endian and Terminator Polarity bits and set possibly
  5715. * modified termination control bits in the Microcode SCSI_CFG1
  5716. * Register Value.
  5717. *
  5718. * Big Endian bit is not used even on big endian machines.
  5719. */
  5720. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5721. /*
  5722. * Set SCSI_CFG1 Microcode Default Value
  5723. *
  5724. * Set possibly modified termination control bits in the Microcode
  5725. * SCSI_CFG1 Register Value.
  5726. *
  5727. * The microcode will set the SCSI_CFG1 register using this value
  5728. * after it is started below.
  5729. */
  5730. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5731. /*
  5732. * Set MEM_CFG Microcode Default Value
  5733. *
  5734. * The microcode will set the MEM_CFG register using this value
  5735. * after it is started below.
  5736. *
  5737. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5738. * are defined.
  5739. *
  5740. * ASC-38C1600 has 32KB internal memory.
  5741. *
  5742. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5743. * out a special 16K Adv Library and Microcode version. After the issue
  5744. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5745. * mcode.sas files also need to be updated.
  5746. *
  5747. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5748. * BIOS_EN | RAM_SZ_32KB);
  5749. */
  5750. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5751. BIOS_EN | RAM_SZ_16KB);
  5752. /*
  5753. * Set SEL_MASK Microcode Default Value
  5754. *
  5755. * The microcode will set the SEL_MASK register using this value
  5756. * after it is started below.
  5757. */
  5758. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5759. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5760. AdvBuildCarrierFreelist(asc_dvc);
  5761. /*
  5762. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5763. */
  5764. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5765. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5766. return ADV_ERROR;
  5767. }
  5768. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5769. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5770. /*
  5771. * The first command issued will be placed in the stopper carrier.
  5772. */
  5773. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5774. /*
  5775. * Set RISC ICQ physical address start value. Initialize the
  5776. * COMMA register to the same value otherwise the RISC will
  5777. * prematurely detect a command is available.
  5778. */
  5779. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5780. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5781. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5782. /*
  5783. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5784. */
  5785. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5786. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5787. return ADV_ERROR;
  5788. }
  5789. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5790. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5791. /*
  5792. * The first command completed by the RISC will be placed in
  5793. * the stopper.
  5794. *
  5795. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5796. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5797. */
  5798. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5799. /*
  5800. * Set RISC IRQ physical address start value.
  5801. */
  5802. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5803. asc_dvc->carr_pending_cnt = 0;
  5804. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5805. (ADV_INTR_ENABLE_HOST_INTR |
  5806. ADV_INTR_ENABLE_GLOBAL_INTR));
  5807. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5808. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5809. /* finally, finally, gentlemen, start your engine */
  5810. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5811. /*
  5812. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5813. * Resets should be performed. The RISC has to be running
  5814. * to issue a SCSI Bus Reset.
  5815. */
  5816. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5817. /*
  5818. * If the BIOS Signature is present in memory, restore the
  5819. * per TID microcode operating variables.
  5820. */
  5821. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5822. 0x55AA) {
  5823. /*
  5824. * Restore per TID negotiated values.
  5825. */
  5826. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5827. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5828. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5829. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5830. tagqng_able);
  5831. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5832. AdvWriteByteLram(iop_base,
  5833. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5834. max_cmd[tid]);
  5835. }
  5836. } else {
  5837. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5838. warn_code = ASC_WARN_BUSRESET_ERROR;
  5839. }
  5840. }
  5841. }
  5842. return warn_code;
  5843. }
  5844. /*
  5845. * Reset chip and SCSI Bus.
  5846. *
  5847. * Return Value:
  5848. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5849. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5850. */
  5851. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5852. {
  5853. int status;
  5854. ushort wdtr_able, sdtr_able, tagqng_able;
  5855. ushort ppr_able = 0;
  5856. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5857. AdvPortAddr iop_base;
  5858. ushort bios_sig;
  5859. iop_base = asc_dvc->iop_base;
  5860. /*
  5861. * Save current per TID negotiated values.
  5862. */
  5863. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5864. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5865. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5866. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5867. }
  5868. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5869. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5870. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5871. max_cmd[tid]);
  5872. }
  5873. /*
  5874. * Force the AdvInitAsc3550/38C0800Driver() function to
  5875. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5876. * The initialization functions assumes a SCSI Bus Reset is not
  5877. * needed if the BIOS signature word is present.
  5878. */
  5879. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5880. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5881. /*
  5882. * Stop chip and reset it.
  5883. */
  5884. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5885. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5886. mdelay(100);
  5887. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5888. ADV_CTRL_REG_CMD_WR_IO_REG);
  5889. /*
  5890. * Reset Adv Library error code, if any, and try
  5891. * re-initializing the chip.
  5892. */
  5893. asc_dvc->err_code = 0;
  5894. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5895. status = AdvInitAsc38C1600Driver(asc_dvc);
  5896. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5897. status = AdvInitAsc38C0800Driver(asc_dvc);
  5898. } else {
  5899. status = AdvInitAsc3550Driver(asc_dvc);
  5900. }
  5901. /* Translate initialization return value to status value. */
  5902. if (status == 0) {
  5903. status = ADV_TRUE;
  5904. } else {
  5905. status = ADV_FALSE;
  5906. }
  5907. /*
  5908. * Restore the BIOS signature word.
  5909. */
  5910. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5911. /*
  5912. * Restore per TID negotiated values.
  5913. */
  5914. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5915. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5916. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5917. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5918. }
  5919. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5920. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5921. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5922. max_cmd[tid]);
  5923. }
  5924. return status;
  5925. }
  5926. /*
  5927. * adv_async_callback() - Adv Library asynchronous event callback function.
  5928. */
  5929. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5930. {
  5931. switch (code) {
  5932. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5933. /*
  5934. * The firmware detected a SCSI Bus reset.
  5935. */
  5936. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5937. break;
  5938. case ADV_ASYNC_RDMA_FAILURE:
  5939. /*
  5940. * Handle RDMA failure by resetting the SCSI Bus and
  5941. * possibly the chip if it is unresponsive. Log the error
  5942. * with a unique code.
  5943. */
  5944. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5945. AdvResetChipAndSB(adv_dvc_varp);
  5946. break;
  5947. case ADV_HOST_SCSI_BUS_RESET:
  5948. /*
  5949. * Host generated SCSI bus reset occurred.
  5950. */
  5951. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5952. break;
  5953. default:
  5954. ASC_DBG(0, "unknown code 0x%x\n", code);
  5955. break;
  5956. }
  5957. }
  5958. /*
  5959. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5960. *
  5961. * Callback function for the Wide SCSI Adv Library.
  5962. */
  5963. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5964. {
  5965. struct asc_board *boardp;
  5966. adv_req_t *reqp;
  5967. adv_sgblk_t *sgblkp;
  5968. struct scsi_cmnd *scp;
  5969. struct Scsi_Host *shost;
  5970. ADV_DCNT resid_cnt;
  5971. ASC_DBG(1, "adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
  5972. (ulong)adv_dvc_varp, (ulong)scsiqp);
  5973. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5974. /*
  5975. * Get the adv_req_t structure for the command that has been
  5976. * completed. The adv_req_t structure actually contains the
  5977. * completed ADV_SCSI_REQ_Q structure.
  5978. */
  5979. reqp = (adv_req_t *)ADV_U32_TO_VADDR(scsiqp->srb_ptr);
  5980. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  5981. if (reqp == NULL) {
  5982. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  5983. return;
  5984. }
  5985. /*
  5986. * Get the struct scsi_cmnd structure and Scsi_Host structure for the
  5987. * command that has been completed.
  5988. *
  5989. * Note: The adv_req_t request structure and adv_sgblk_t structure,
  5990. * if any, are dropped, because a board structure pointer can not be
  5991. * determined.
  5992. */
  5993. scp = reqp->cmndp;
  5994. ASC_DBG(1, "scp 0x%p\n", scp);
  5995. if (scp == NULL) {
  5996. ASC_PRINT
  5997. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  5998. return;
  5999. }
  6000. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6001. shost = scp->device->host;
  6002. ASC_STATS(shost, callback);
  6003. ASC_DBG(1, "shost 0x%p\n", shost);
  6004. boardp = shost_priv(shost);
  6005. BUG_ON(adv_dvc_varp != &boardp->dvc_var.adv_dvc_var);
  6006. /*
  6007. * 'done_status' contains the command's ending status.
  6008. */
  6009. switch (scsiqp->done_status) {
  6010. case QD_NO_ERROR:
  6011. ASC_DBG(2, "QD_NO_ERROR\n");
  6012. scp->result = 0;
  6013. /*
  6014. * Check for an underrun condition.
  6015. *
  6016. * If there was no error and an underrun condition, then
  6017. * then return the number of underrun bytes.
  6018. */
  6019. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  6020. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  6021. resid_cnt <= scsi_bufflen(scp)) {
  6022. ASC_DBG(1, "underrun condition %lu bytes\n",
  6023. (ulong)resid_cnt);
  6024. scsi_set_resid(scp, resid_cnt);
  6025. }
  6026. break;
  6027. case QD_WITH_ERROR:
  6028. ASC_DBG(2, "QD_WITH_ERROR\n");
  6029. switch (scsiqp->host_status) {
  6030. case QHSTA_NO_ERROR:
  6031. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  6032. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6033. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6034. SCSI_SENSE_BUFFERSIZE);
  6035. /*
  6036. * Note: The 'status_byte()' macro used by
  6037. * target drivers defined in scsi.h shifts the
  6038. * status byte returned by host drivers right
  6039. * by 1 bit. This is why target drivers also
  6040. * use right shifted status byte definitions.
  6041. * For instance target drivers use
  6042. * CHECK_CONDITION, defined to 0x1, instead of
  6043. * the SCSI defined check condition value of
  6044. * 0x2. Host drivers are supposed to return
  6045. * the status byte as it is defined by SCSI.
  6046. */
  6047. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6048. STATUS_BYTE(scsiqp->scsi_status);
  6049. } else {
  6050. scp->result = STATUS_BYTE(scsiqp->scsi_status);
  6051. }
  6052. break;
  6053. default:
  6054. /* Some other QHSTA error occurred. */
  6055. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  6056. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6057. break;
  6058. }
  6059. break;
  6060. case QD_ABORTED_BY_HOST:
  6061. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6062. scp->result =
  6063. HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
  6064. break;
  6065. default:
  6066. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  6067. scp->result =
  6068. HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
  6069. break;
  6070. }
  6071. /*
  6072. * If the 'init_tidmask' bit isn't already set for the target and the
  6073. * current request finished normally, then set the bit for the target
  6074. * to indicate that a device is present.
  6075. */
  6076. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6077. scsiqp->done_status == QD_NO_ERROR &&
  6078. scsiqp->host_status == QHSTA_NO_ERROR) {
  6079. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6080. }
  6081. asc_scsi_done(scp);
  6082. /*
  6083. * Free all 'adv_sgblk_t' structures allocated for the request.
  6084. */
  6085. while ((sgblkp = reqp->sgblkp) != NULL) {
  6086. /* Remove 'sgblkp' from the request list. */
  6087. reqp->sgblkp = sgblkp->next_sgblkp;
  6088. /* Add 'sgblkp' to the board free list. */
  6089. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  6090. boardp->adv_sgblkp = sgblkp;
  6091. }
  6092. /*
  6093. * Free the adv_req_t structure used with the command by adding
  6094. * it back to the board free list.
  6095. */
  6096. reqp->next_reqp = boardp->adv_reqp;
  6097. boardp->adv_reqp = reqp;
  6098. ASC_DBG(1, "done\n");
  6099. }
  6100. /*
  6101. * Adv Library Interrupt Service Routine
  6102. *
  6103. * This function is called by a driver's interrupt service routine.
  6104. * The function disables and re-enables interrupts.
  6105. *
  6106. * When a microcode idle command is completed, the ADV_DVC_VAR
  6107. * 'idle_cmd_done' field is set to ADV_TRUE.
  6108. *
  6109. * Note: AdvISR() can be called when interrupts are disabled or even
  6110. * when there is no hardware interrupt condition present. It will
  6111. * always check for completed idle commands and microcode requests.
  6112. * This is an important feature that shouldn't be changed because it
  6113. * allows commands to be completed from polling mode loops.
  6114. *
  6115. * Return:
  6116. * ADV_TRUE(1) - interrupt was pending
  6117. * ADV_FALSE(0) - no interrupt was pending
  6118. */
  6119. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  6120. {
  6121. AdvPortAddr iop_base;
  6122. uchar int_stat;
  6123. ushort target_bit;
  6124. ADV_CARR_T *free_carrp;
  6125. ADV_VADDR irq_next_vpa;
  6126. ADV_SCSI_REQ_Q *scsiq;
  6127. iop_base = asc_dvc->iop_base;
  6128. /* Reading the register clears the interrupt. */
  6129. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  6130. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  6131. ADV_INTR_STATUS_INTRC)) == 0) {
  6132. return ADV_FALSE;
  6133. }
  6134. /*
  6135. * Notify the driver of an asynchronous microcode condition by
  6136. * calling the adv_async_callback function. The function
  6137. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  6138. */
  6139. if (int_stat & ADV_INTR_STATUS_INTRB) {
  6140. uchar intrb_code;
  6141. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  6142. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  6143. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  6144. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  6145. asc_dvc->carr_pending_cnt != 0) {
  6146. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  6147. ADV_TICKLE_A);
  6148. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  6149. AdvWriteByteRegister(iop_base,
  6150. IOPB_TICKLE,
  6151. ADV_TICKLE_NOP);
  6152. }
  6153. }
  6154. }
  6155. adv_async_callback(asc_dvc, intrb_code);
  6156. }
  6157. /*
  6158. * Check if the IRQ stopper carrier contains a completed request.
  6159. */
  6160. while (((irq_next_vpa =
  6161. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) {
  6162. /*
  6163. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  6164. * The RISC will have set 'areq_vpa' to a virtual address.
  6165. *
  6166. * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
  6167. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  6168. * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
  6169. * in AdvExeScsiQueue().
  6170. */
  6171. scsiq = (ADV_SCSI_REQ_Q *)
  6172. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
  6173. /*
  6174. * Request finished with good status and the queue was not
  6175. * DMAed to host memory by the firmware. Set all status fields
  6176. * to indicate good status.
  6177. */
  6178. if ((irq_next_vpa & ASC_RQ_GOOD) != 0) {
  6179. scsiq->done_status = QD_NO_ERROR;
  6180. scsiq->host_status = scsiq->scsi_status = 0;
  6181. scsiq->data_cnt = 0L;
  6182. }
  6183. /*
  6184. * Advance the stopper pointer to the next carrier
  6185. * ignoring the lower four bits. Free the previous
  6186. * stopper carrier.
  6187. */
  6188. free_carrp = asc_dvc->irq_sp;
  6189. asc_dvc->irq_sp = (ADV_CARR_T *)
  6190. ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
  6191. free_carrp->next_vpa =
  6192. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  6193. asc_dvc->carr_freelist = free_carrp;
  6194. asc_dvc->carr_pending_cnt--;
  6195. target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
  6196. /*
  6197. * Clear request microcode control flag.
  6198. */
  6199. scsiq->cntl = 0;
  6200. /*
  6201. * Notify the driver of the completed request by passing
  6202. * the ADV_SCSI_REQ_Q pointer to its callback function.
  6203. */
  6204. scsiq->a_flag |= ADV_SCSIQ_DONE;
  6205. adv_isr_callback(asc_dvc, scsiq);
  6206. /*
  6207. * Note: After the driver callback function is called, 'scsiq'
  6208. * can no longer be referenced.
  6209. *
  6210. * Fall through and continue processing other completed
  6211. * requests...
  6212. */
  6213. }
  6214. return ADV_TRUE;
  6215. }
  6216. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  6217. {
  6218. if (asc_dvc->err_code == 0) {
  6219. asc_dvc->err_code = err_code;
  6220. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  6221. err_code);
  6222. }
  6223. return err_code;
  6224. }
  6225. static void AscAckInterrupt(PortAddr iop_base)
  6226. {
  6227. uchar host_flag;
  6228. uchar risc_flag;
  6229. ushort loop;
  6230. loop = 0;
  6231. do {
  6232. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  6233. if (loop++ > 0x7FFF) {
  6234. break;
  6235. }
  6236. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  6237. host_flag =
  6238. AscReadLramByte(iop_base,
  6239. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  6240. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6241. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  6242. AscSetChipStatus(iop_base, CIW_INT_ACK);
  6243. loop = 0;
  6244. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  6245. AscSetChipStatus(iop_base, CIW_INT_ACK);
  6246. if (loop++ > 3) {
  6247. break;
  6248. }
  6249. }
  6250. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6251. }
  6252. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  6253. {
  6254. const uchar *period_table;
  6255. int max_index;
  6256. int min_index;
  6257. int i;
  6258. period_table = asc_dvc->sdtr_period_tbl;
  6259. max_index = (int)asc_dvc->max_sdtr_index;
  6260. min_index = (int)asc_dvc->min_sdtr_index;
  6261. if ((syn_time <= period_table[max_index])) {
  6262. for (i = min_index; i < (max_index - 1); i++) {
  6263. if (syn_time <= period_table[i]) {
  6264. return (uchar)i;
  6265. }
  6266. }
  6267. return (uchar)max_index;
  6268. } else {
  6269. return (uchar)(max_index + 1);
  6270. }
  6271. }
  6272. static uchar
  6273. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  6274. {
  6275. EXT_MSG sdtr_buf;
  6276. uchar sdtr_period_index;
  6277. PortAddr iop_base;
  6278. iop_base = asc_dvc->iop_base;
  6279. sdtr_buf.msg_type = EXTENDED_MESSAGE;
  6280. sdtr_buf.msg_len = MS_SDTR_LEN;
  6281. sdtr_buf.msg_req = EXTENDED_SDTR;
  6282. sdtr_buf.xfer_period = sdtr_period;
  6283. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  6284. sdtr_buf.req_ack_offset = sdtr_offset;
  6285. sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  6286. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  6287. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  6288. (uchar *)&sdtr_buf,
  6289. sizeof(EXT_MSG) >> 1);
  6290. return ((sdtr_period_index << 4) | sdtr_offset);
  6291. } else {
  6292. sdtr_buf.req_ack_offset = 0;
  6293. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  6294. (uchar *)&sdtr_buf,
  6295. sizeof(EXT_MSG) >> 1);
  6296. return 0;
  6297. }
  6298. }
  6299. static uchar
  6300. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  6301. {
  6302. uchar byte;
  6303. uchar sdtr_period_ix;
  6304. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  6305. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  6306. return 0xFF;
  6307. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  6308. return byte;
  6309. }
  6310. static int AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  6311. {
  6312. ASC_SCSI_BIT_ID_TYPE org_id;
  6313. int i;
  6314. int sta = TRUE;
  6315. AscSetBank(iop_base, 1);
  6316. org_id = AscReadChipDvcID(iop_base);
  6317. for (i = 0; i <= ASC_MAX_TID; i++) {
  6318. if (org_id == (0x01 << i))
  6319. break;
  6320. }
  6321. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  6322. AscWriteChipDvcID(iop_base, id);
  6323. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  6324. AscSetBank(iop_base, 0);
  6325. AscSetChipSyn(iop_base, sdtr_data);
  6326. if (AscGetChipSyn(iop_base) != sdtr_data) {
  6327. sta = FALSE;
  6328. }
  6329. } else {
  6330. sta = FALSE;
  6331. }
  6332. AscSetBank(iop_base, 1);
  6333. AscWriteChipDvcID(iop_base, org_id);
  6334. AscSetBank(iop_base, 0);
  6335. return (sta);
  6336. }
  6337. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  6338. {
  6339. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6340. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  6341. }
  6342. static int AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  6343. {
  6344. EXT_MSG ext_msg;
  6345. EXT_MSG out_msg;
  6346. ushort halt_q_addr;
  6347. int sdtr_accept;
  6348. ushort int_halt_code;
  6349. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6350. ASC_SCSI_BIT_ID_TYPE target_id;
  6351. PortAddr iop_base;
  6352. uchar tag_code;
  6353. uchar q_status;
  6354. uchar halt_qp;
  6355. uchar sdtr_data;
  6356. uchar target_ix;
  6357. uchar q_cntl, tid_no;
  6358. uchar cur_dvc_qng;
  6359. uchar asyn_sdtr;
  6360. uchar scsi_status;
  6361. struct asc_board *boardp;
  6362. BUG_ON(!asc_dvc->drv_ptr);
  6363. boardp = asc_dvc->drv_ptr;
  6364. iop_base = asc_dvc->iop_base;
  6365. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  6366. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  6367. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  6368. target_ix = AscReadLramByte(iop_base,
  6369. (ushort)(halt_q_addr +
  6370. (ushort)ASC_SCSIQ_B_TARGET_IX));
  6371. q_cntl = AscReadLramByte(iop_base,
  6372. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6373. tid_no = ASC_TIX_TO_TID(target_ix);
  6374. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  6375. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6376. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  6377. } else {
  6378. asyn_sdtr = 0;
  6379. }
  6380. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  6381. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6382. AscSetChipSDTR(iop_base, 0, tid_no);
  6383. boardp->sdtr_data[tid_no] = 0;
  6384. }
  6385. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6386. return (0);
  6387. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  6388. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6389. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6390. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6391. }
  6392. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6393. return (0);
  6394. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  6395. AscMemWordCopyPtrFromLram(iop_base,
  6396. ASCV_MSGIN_BEG,
  6397. (uchar *)&ext_msg,
  6398. sizeof(EXT_MSG) >> 1);
  6399. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6400. ext_msg.msg_req == EXTENDED_SDTR &&
  6401. ext_msg.msg_len == MS_SDTR_LEN) {
  6402. sdtr_accept = TRUE;
  6403. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  6404. sdtr_accept = FALSE;
  6405. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  6406. }
  6407. if ((ext_msg.xfer_period <
  6408. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  6409. || (ext_msg.xfer_period >
  6410. asc_dvc->sdtr_period_tbl[asc_dvc->
  6411. max_sdtr_index])) {
  6412. sdtr_accept = FALSE;
  6413. ext_msg.xfer_period =
  6414. asc_dvc->sdtr_period_tbl[asc_dvc->
  6415. min_sdtr_index];
  6416. }
  6417. if (sdtr_accept) {
  6418. sdtr_data =
  6419. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  6420. ext_msg.req_ack_offset);
  6421. if ((sdtr_data == 0xFF)) {
  6422. q_cntl |= QC_MSG_OUT;
  6423. asc_dvc->init_sdtr &= ~target_id;
  6424. asc_dvc->sdtr_done &= ~target_id;
  6425. AscSetChipSDTR(iop_base, asyn_sdtr,
  6426. tid_no);
  6427. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6428. }
  6429. }
  6430. if (ext_msg.req_ack_offset == 0) {
  6431. q_cntl &= ~QC_MSG_OUT;
  6432. asc_dvc->init_sdtr &= ~target_id;
  6433. asc_dvc->sdtr_done &= ~target_id;
  6434. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6435. } else {
  6436. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  6437. q_cntl &= ~QC_MSG_OUT;
  6438. asc_dvc->sdtr_done |= target_id;
  6439. asc_dvc->init_sdtr |= target_id;
  6440. asc_dvc->pci_fix_asyn_xfer &=
  6441. ~target_id;
  6442. sdtr_data =
  6443. AscCalSDTRData(asc_dvc,
  6444. ext_msg.xfer_period,
  6445. ext_msg.
  6446. req_ack_offset);
  6447. AscSetChipSDTR(iop_base, sdtr_data,
  6448. tid_no);
  6449. boardp->sdtr_data[tid_no] = sdtr_data;
  6450. } else {
  6451. q_cntl |= QC_MSG_OUT;
  6452. AscMsgOutSDTR(asc_dvc,
  6453. ext_msg.xfer_period,
  6454. ext_msg.req_ack_offset);
  6455. asc_dvc->pci_fix_asyn_xfer &=
  6456. ~target_id;
  6457. sdtr_data =
  6458. AscCalSDTRData(asc_dvc,
  6459. ext_msg.xfer_period,
  6460. ext_msg.
  6461. req_ack_offset);
  6462. AscSetChipSDTR(iop_base, sdtr_data,
  6463. tid_no);
  6464. boardp->sdtr_data[tid_no] = sdtr_data;
  6465. asc_dvc->sdtr_done |= target_id;
  6466. asc_dvc->init_sdtr |= target_id;
  6467. }
  6468. }
  6469. AscWriteLramByte(iop_base,
  6470. (ushort)(halt_q_addr +
  6471. (ushort)ASC_SCSIQ_B_CNTL),
  6472. q_cntl);
  6473. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6474. return (0);
  6475. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6476. ext_msg.msg_req == EXTENDED_WDTR &&
  6477. ext_msg.msg_len == MS_WDTR_LEN) {
  6478. ext_msg.wdtr_width = 0;
  6479. AscMemWordCopyPtrToLram(iop_base,
  6480. ASCV_MSGOUT_BEG,
  6481. (uchar *)&ext_msg,
  6482. sizeof(EXT_MSG) >> 1);
  6483. q_cntl |= QC_MSG_OUT;
  6484. AscWriteLramByte(iop_base,
  6485. (ushort)(halt_q_addr +
  6486. (ushort)ASC_SCSIQ_B_CNTL),
  6487. q_cntl);
  6488. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6489. return (0);
  6490. } else {
  6491. ext_msg.msg_type = MESSAGE_REJECT;
  6492. AscMemWordCopyPtrToLram(iop_base,
  6493. ASCV_MSGOUT_BEG,
  6494. (uchar *)&ext_msg,
  6495. sizeof(EXT_MSG) >> 1);
  6496. q_cntl |= QC_MSG_OUT;
  6497. AscWriteLramByte(iop_base,
  6498. (ushort)(halt_q_addr +
  6499. (ushort)ASC_SCSIQ_B_CNTL),
  6500. q_cntl);
  6501. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6502. return (0);
  6503. }
  6504. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  6505. q_cntl |= QC_REQ_SENSE;
  6506. if ((asc_dvc->init_sdtr & target_id) != 0) {
  6507. asc_dvc->sdtr_done &= ~target_id;
  6508. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  6509. q_cntl |= QC_MSG_OUT;
  6510. AscMsgOutSDTR(asc_dvc,
  6511. asc_dvc->
  6512. sdtr_period_tbl[(sdtr_data >> 4) &
  6513. (uchar)(asc_dvc->
  6514. max_sdtr_index -
  6515. 1)],
  6516. (uchar)(sdtr_data & (uchar)
  6517. ASC_SYN_MAX_OFFSET));
  6518. }
  6519. AscWriteLramByte(iop_base,
  6520. (ushort)(halt_q_addr +
  6521. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6522. tag_code = AscReadLramByte(iop_base,
  6523. (ushort)(halt_q_addr + (ushort)
  6524. ASC_SCSIQ_B_TAG_CODE));
  6525. tag_code &= 0xDC;
  6526. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  6527. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  6528. ) {
  6529. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  6530. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  6531. }
  6532. AscWriteLramByte(iop_base,
  6533. (ushort)(halt_q_addr +
  6534. (ushort)ASC_SCSIQ_B_TAG_CODE),
  6535. tag_code);
  6536. q_status = AscReadLramByte(iop_base,
  6537. (ushort)(halt_q_addr + (ushort)
  6538. ASC_SCSIQ_B_STATUS));
  6539. q_status |= (QS_READY | QS_BUSY);
  6540. AscWriteLramByte(iop_base,
  6541. (ushort)(halt_q_addr +
  6542. (ushort)ASC_SCSIQ_B_STATUS),
  6543. q_status);
  6544. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  6545. scsi_busy &= ~target_id;
  6546. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6547. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6548. return (0);
  6549. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  6550. AscMemWordCopyPtrFromLram(iop_base,
  6551. ASCV_MSGOUT_BEG,
  6552. (uchar *)&out_msg,
  6553. sizeof(EXT_MSG) >> 1);
  6554. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  6555. (out_msg.msg_len == MS_SDTR_LEN) &&
  6556. (out_msg.msg_req == EXTENDED_SDTR)) {
  6557. asc_dvc->init_sdtr &= ~target_id;
  6558. asc_dvc->sdtr_done &= ~target_id;
  6559. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6560. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6561. }
  6562. q_cntl &= ~QC_MSG_OUT;
  6563. AscWriteLramByte(iop_base,
  6564. (ushort)(halt_q_addr +
  6565. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6566. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6567. return (0);
  6568. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  6569. scsi_status = AscReadLramByte(iop_base,
  6570. (ushort)((ushort)halt_q_addr +
  6571. (ushort)
  6572. ASC_SCSIQ_SCSI_STATUS));
  6573. cur_dvc_qng =
  6574. AscReadLramByte(iop_base,
  6575. (ushort)((ushort)ASC_QADR_BEG +
  6576. (ushort)target_ix));
  6577. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  6578. scsi_busy = AscReadLramByte(iop_base,
  6579. (ushort)ASCV_SCSIBUSY_B);
  6580. scsi_busy |= target_id;
  6581. AscWriteLramByte(iop_base,
  6582. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6583. asc_dvc->queue_full_or_busy |= target_id;
  6584. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  6585. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  6586. cur_dvc_qng -= 1;
  6587. asc_dvc->max_dvc_qng[tid_no] =
  6588. cur_dvc_qng;
  6589. AscWriteLramByte(iop_base,
  6590. (ushort)((ushort)
  6591. ASCV_MAX_DVC_QNG_BEG
  6592. + (ushort)
  6593. tid_no),
  6594. cur_dvc_qng);
  6595. /*
  6596. * Set the device queue depth to the
  6597. * number of active requests when the
  6598. * QUEUE FULL condition was encountered.
  6599. */
  6600. boardp->queue_full |= target_id;
  6601. boardp->queue_full_cnt[tid_no] =
  6602. cur_dvc_qng;
  6603. }
  6604. }
  6605. }
  6606. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6607. return (0);
  6608. }
  6609. #if CC_VERY_LONG_SG_LIST
  6610. else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) {
  6611. uchar q_no;
  6612. ushort q_addr;
  6613. uchar sg_wk_q_no;
  6614. uchar first_sg_wk_q_no;
  6615. ASC_SCSI_Q *scsiq; /* Ptr to driver request. */
  6616. ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */
  6617. ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */
  6618. ushort sg_list_dwords;
  6619. ushort sg_entry_cnt;
  6620. uchar next_qp;
  6621. int i;
  6622. q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP);
  6623. if (q_no == ASC_QLINK_END)
  6624. return 0;
  6625. q_addr = ASC_QNO_TO_QADDR(q_no);
  6626. /*
  6627. * Convert the request's SRB pointer to a host ASC_SCSI_REQ
  6628. * structure pointer using a macro provided by the driver.
  6629. * The ASC_SCSI_REQ pointer provides a pointer to the
  6630. * host ASC_SG_HEAD structure.
  6631. */
  6632. /* Read request's SRB pointer. */
  6633. scsiq = (ASC_SCSI_Q *)
  6634. ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
  6635. (ushort)
  6636. (q_addr +
  6637. ASC_SCSIQ_D_SRBPTR))));
  6638. /*
  6639. * Get request's first and working SG queue.
  6640. */
  6641. sg_wk_q_no = AscReadLramByte(iop_base,
  6642. (ushort)(q_addr +
  6643. ASC_SCSIQ_B_SG_WK_QP));
  6644. first_sg_wk_q_no = AscReadLramByte(iop_base,
  6645. (ushort)(q_addr +
  6646. ASC_SCSIQ_B_FIRST_SG_WK_QP));
  6647. /*
  6648. * Reset request's working SG queue back to the
  6649. * first SG queue.
  6650. */
  6651. AscWriteLramByte(iop_base,
  6652. (ushort)(q_addr +
  6653. (ushort)ASC_SCSIQ_B_SG_WK_QP),
  6654. first_sg_wk_q_no);
  6655. sg_head = scsiq->sg_head;
  6656. /*
  6657. * Set sg_entry_cnt to the number of SG elements
  6658. * that will be completed on this interrupt.
  6659. *
  6660. * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
  6661. * SG elements. The data_cnt and data_addr fields which
  6662. * add 1 to the SG element capacity are not used when
  6663. * restarting SG handling after a halt.
  6664. */
  6665. if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) {
  6666. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  6667. /*
  6668. * Keep track of remaining number of SG elements that
  6669. * will need to be handled on the next interrupt.
  6670. */
  6671. scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
  6672. } else {
  6673. sg_entry_cnt = scsiq->remain_sg_entry_cnt;
  6674. scsiq->remain_sg_entry_cnt = 0;
  6675. }
  6676. /*
  6677. * Copy SG elements into the list of allocated SG queues.
  6678. *
  6679. * Last index completed is saved in scsiq->next_sg_index.
  6680. */
  6681. next_qp = first_sg_wk_q_no;
  6682. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6683. scsi_sg_q.sg_head_qp = q_no;
  6684. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  6685. for (i = 0; i < sg_head->queue_cnt; i++) {
  6686. scsi_sg_q.seq_no = i + 1;
  6687. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  6688. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  6689. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  6690. /*
  6691. * After very first SG queue RISC FW uses next
  6692. * SG queue first element then checks sg_list_cnt
  6693. * against zero and then decrements, so set
  6694. * sg_list_cnt 1 less than number of SG elements
  6695. * in each SG queue.
  6696. */
  6697. scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
  6698. scsi_sg_q.sg_cur_list_cnt =
  6699. ASC_SG_LIST_PER_Q - 1;
  6700. } else {
  6701. /*
  6702. * This is the last SG queue in the list of
  6703. * allocated SG queues. If there are more
  6704. * SG elements than will fit in the allocated
  6705. * queues, then set the QCSG_SG_XFER_MORE flag.
  6706. */
  6707. if (scsiq->remain_sg_entry_cnt != 0) {
  6708. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  6709. } else {
  6710. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  6711. }
  6712. /* equals sg_entry_cnt * 2 */
  6713. sg_list_dwords = sg_entry_cnt << 1;
  6714. scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
  6715. scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
  6716. sg_entry_cnt = 0;
  6717. }
  6718. scsi_sg_q.q_no = next_qp;
  6719. AscMemWordCopyPtrToLram(iop_base,
  6720. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  6721. (uchar *)&scsi_sg_q,
  6722. sizeof(ASC_SG_LIST_Q) >> 1);
  6723. AscMemDWordCopyPtrToLram(iop_base,
  6724. q_addr + ASC_SGQ_LIST_BEG,
  6725. (uchar *)&sg_head->
  6726. sg_list[scsiq->next_sg_index],
  6727. sg_list_dwords);
  6728. scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
  6729. /*
  6730. * If the just completed SG queue contained the
  6731. * last SG element, then no more SG queues need
  6732. * to be written.
  6733. */
  6734. if (scsi_sg_q.cntl & QCSG_SG_XFER_END) {
  6735. break;
  6736. }
  6737. next_qp = AscReadLramByte(iop_base,
  6738. (ushort)(q_addr +
  6739. ASC_SCSIQ_B_FWD));
  6740. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6741. }
  6742. /*
  6743. * Clear the halt condition so the RISC will be restarted
  6744. * after the return.
  6745. */
  6746. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6747. return (0);
  6748. }
  6749. #endif /* CC_VERY_LONG_SG_LIST */
  6750. return (0);
  6751. }
  6752. /*
  6753. * void
  6754. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6755. *
  6756. * Calling/Exit State:
  6757. * none
  6758. *
  6759. * Description:
  6760. * Input an ASC_QDONE_INFO structure from the chip
  6761. */
  6762. static void
  6763. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6764. {
  6765. int i;
  6766. ushort word;
  6767. AscSetChipLramAddr(iop_base, s_addr);
  6768. for (i = 0; i < 2 * words; i += 2) {
  6769. if (i == 10) {
  6770. continue;
  6771. }
  6772. word = inpw(iop_base + IOP_RAM_DATA);
  6773. inbuf[i] = word & 0xff;
  6774. inbuf[i + 1] = (word >> 8) & 0xff;
  6775. }
  6776. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  6777. }
  6778. static uchar
  6779. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  6780. ushort q_addr,
  6781. ASC_QDONE_INFO *scsiq, ASC_DCNT max_dma_count)
  6782. {
  6783. ushort _val;
  6784. uchar sg_queue_cnt;
  6785. DvcGetQinfo(iop_base,
  6786. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  6787. (uchar *)scsiq,
  6788. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  6789. _val = AscReadLramWord(iop_base,
  6790. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  6791. scsiq->q_status = (uchar)_val;
  6792. scsiq->q_no = (uchar)(_val >> 8);
  6793. _val = AscReadLramWord(iop_base,
  6794. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6795. scsiq->cntl = (uchar)_val;
  6796. sg_queue_cnt = (uchar)(_val >> 8);
  6797. _val = AscReadLramWord(iop_base,
  6798. (ushort)(q_addr +
  6799. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  6800. scsiq->sense_len = (uchar)_val;
  6801. scsiq->extra_bytes = (uchar)(_val >> 8);
  6802. /*
  6803. * Read high word of remain bytes from alternate location.
  6804. */
  6805. scsiq->remain_bytes = (((ADV_DCNT)AscReadLramWord(iop_base,
  6806. (ushort)(q_addr +
  6807. (ushort)
  6808. ASC_SCSIQ_W_ALT_DC1)))
  6809. << 16);
  6810. /*
  6811. * Read low word of remain bytes from original location.
  6812. */
  6813. scsiq->remain_bytes += AscReadLramWord(iop_base,
  6814. (ushort)(q_addr + (ushort)
  6815. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  6816. scsiq->remain_bytes &= max_dma_count;
  6817. return sg_queue_cnt;
  6818. }
  6819. /*
  6820. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  6821. *
  6822. * Interrupt callback function for the Narrow SCSI Asc Library.
  6823. */
  6824. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  6825. {
  6826. struct asc_board *boardp;
  6827. struct scsi_cmnd *scp;
  6828. struct Scsi_Host *shost;
  6829. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  6830. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  6831. scp = advansys_srb_to_ptr(asc_dvc_varp, qdonep->d2.srb_ptr);
  6832. if (!scp)
  6833. return;
  6834. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6835. shost = scp->device->host;
  6836. ASC_STATS(shost, callback);
  6837. ASC_DBG(1, "shost 0x%p\n", shost);
  6838. boardp = shost_priv(shost);
  6839. BUG_ON(asc_dvc_varp != &boardp->dvc_var.asc_dvc_var);
  6840. dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
  6841. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6842. /*
  6843. * 'qdonep' contains the command's ending status.
  6844. */
  6845. switch (qdonep->d3.done_stat) {
  6846. case QD_NO_ERROR:
  6847. ASC_DBG(2, "QD_NO_ERROR\n");
  6848. scp->result = 0;
  6849. /*
  6850. * Check for an underrun condition.
  6851. *
  6852. * If there was no error and an underrun condition, then
  6853. * return the number of underrun bytes.
  6854. */
  6855. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6856. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6857. ASC_DBG(1, "underrun condition %u bytes\n",
  6858. (unsigned)qdonep->remain_bytes);
  6859. scsi_set_resid(scp, qdonep->remain_bytes);
  6860. }
  6861. break;
  6862. case QD_WITH_ERROR:
  6863. ASC_DBG(2, "QD_WITH_ERROR\n");
  6864. switch (qdonep->d3.host_stat) {
  6865. case QHSTA_NO_ERROR:
  6866. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6867. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6868. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6869. SCSI_SENSE_BUFFERSIZE);
  6870. /*
  6871. * Note: The 'status_byte()' macro used by
  6872. * target drivers defined in scsi.h shifts the
  6873. * status byte returned by host drivers right
  6874. * by 1 bit. This is why target drivers also
  6875. * use right shifted status byte definitions.
  6876. * For instance target drivers use
  6877. * CHECK_CONDITION, defined to 0x1, instead of
  6878. * the SCSI defined check condition value of
  6879. * 0x2. Host drivers are supposed to return
  6880. * the status byte as it is defined by SCSI.
  6881. */
  6882. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6883. STATUS_BYTE(qdonep->d3.scsi_stat);
  6884. } else {
  6885. scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
  6886. }
  6887. break;
  6888. default:
  6889. /* QHSTA error occurred */
  6890. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6891. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6892. break;
  6893. }
  6894. break;
  6895. case QD_ABORTED_BY_HOST:
  6896. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6897. scp->result =
  6898. HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
  6899. scsi_msg) |
  6900. STATUS_BYTE(qdonep->d3.scsi_stat);
  6901. break;
  6902. default:
  6903. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6904. scp->result =
  6905. HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
  6906. scsi_msg) |
  6907. STATUS_BYTE(qdonep->d3.scsi_stat);
  6908. break;
  6909. }
  6910. /*
  6911. * If the 'init_tidmask' bit isn't already set for the target and the
  6912. * current request finished normally, then set the bit for the target
  6913. * to indicate that a device is present.
  6914. */
  6915. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6916. qdonep->d3.done_stat == QD_NO_ERROR &&
  6917. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6918. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6919. }
  6920. asc_scsi_done(scp);
  6921. }
  6922. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6923. {
  6924. uchar next_qp;
  6925. uchar n_q_used;
  6926. uchar sg_list_qp;
  6927. uchar sg_queue_cnt;
  6928. uchar q_cnt;
  6929. uchar done_q_tail;
  6930. uchar tid_no;
  6931. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6932. ASC_SCSI_BIT_ID_TYPE target_id;
  6933. PortAddr iop_base;
  6934. ushort q_addr;
  6935. ushort sg_q_addr;
  6936. uchar cur_target_qng;
  6937. ASC_QDONE_INFO scsiq_buf;
  6938. ASC_QDONE_INFO *scsiq;
  6939. int false_overrun;
  6940. iop_base = asc_dvc->iop_base;
  6941. n_q_used = 1;
  6942. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6943. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6944. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6945. next_qp = AscReadLramByte(iop_base,
  6946. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6947. if (next_qp != ASC_QLINK_END) {
  6948. AscPutVarDoneQTail(iop_base, next_qp);
  6949. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6950. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6951. asc_dvc->max_dma_count);
  6952. AscWriteLramByte(iop_base,
  6953. (ushort)(q_addr +
  6954. (ushort)ASC_SCSIQ_B_STATUS),
  6955. (uchar)(scsiq->
  6956. q_status & (uchar)~(QS_READY |
  6957. QS_ABORTED)));
  6958. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6959. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6960. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6961. sg_q_addr = q_addr;
  6962. sg_list_qp = next_qp;
  6963. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6964. sg_list_qp = AscReadLramByte(iop_base,
  6965. (ushort)(sg_q_addr
  6966. + (ushort)
  6967. ASC_SCSIQ_B_FWD));
  6968. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6969. if (sg_list_qp == ASC_QLINK_END) {
  6970. AscSetLibErrorCode(asc_dvc,
  6971. ASCQ_ERR_SG_Q_LINKS);
  6972. scsiq->d3.done_stat = QD_WITH_ERROR;
  6973. scsiq->d3.host_stat =
  6974. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6975. goto FATAL_ERR_QDONE;
  6976. }
  6977. AscWriteLramByte(iop_base,
  6978. (ushort)(sg_q_addr + (ushort)
  6979. ASC_SCSIQ_B_STATUS),
  6980. QS_FREE);
  6981. }
  6982. n_q_used = sg_queue_cnt + 1;
  6983. AscPutVarDoneQTail(iop_base, sg_list_qp);
  6984. }
  6985. if (asc_dvc->queue_full_or_busy & target_id) {
  6986. cur_target_qng = AscReadLramByte(iop_base,
  6987. (ushort)((ushort)
  6988. ASC_QADR_BEG
  6989. + (ushort)
  6990. scsiq->d2.
  6991. target_ix));
  6992. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  6993. scsi_busy = AscReadLramByte(iop_base, (ushort)
  6994. ASCV_SCSIBUSY_B);
  6995. scsi_busy &= ~target_id;
  6996. AscWriteLramByte(iop_base,
  6997. (ushort)ASCV_SCSIBUSY_B,
  6998. scsi_busy);
  6999. asc_dvc->queue_full_or_busy &= ~target_id;
  7000. }
  7001. }
  7002. if (asc_dvc->cur_total_qng >= n_q_used) {
  7003. asc_dvc->cur_total_qng -= n_q_used;
  7004. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  7005. asc_dvc->cur_dvc_qng[tid_no]--;
  7006. }
  7007. } else {
  7008. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  7009. scsiq->d3.done_stat = QD_WITH_ERROR;
  7010. goto FATAL_ERR_QDONE;
  7011. }
  7012. if ((scsiq->d2.srb_ptr == 0UL) ||
  7013. ((scsiq->q_status & QS_ABORTED) != 0)) {
  7014. return (0x11);
  7015. } else if (scsiq->q_status == QS_DONE) {
  7016. false_overrun = FALSE;
  7017. if (scsiq->extra_bytes != 0) {
  7018. scsiq->remain_bytes +=
  7019. (ADV_DCNT)scsiq->extra_bytes;
  7020. }
  7021. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  7022. if (scsiq->d3.host_stat ==
  7023. QHSTA_M_DATA_OVER_RUN) {
  7024. if ((scsiq->
  7025. cntl & (QC_DATA_IN | QC_DATA_OUT))
  7026. == 0) {
  7027. scsiq->d3.done_stat =
  7028. QD_NO_ERROR;
  7029. scsiq->d3.host_stat =
  7030. QHSTA_NO_ERROR;
  7031. } else if (false_overrun) {
  7032. scsiq->d3.done_stat =
  7033. QD_NO_ERROR;
  7034. scsiq->d3.host_stat =
  7035. QHSTA_NO_ERROR;
  7036. }
  7037. } else if (scsiq->d3.host_stat ==
  7038. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  7039. AscStopChip(iop_base);
  7040. AscSetChipControl(iop_base,
  7041. (uchar)(CC_SCSI_RESET
  7042. | CC_HALT));
  7043. udelay(60);
  7044. AscSetChipControl(iop_base, CC_HALT);
  7045. AscSetChipStatus(iop_base,
  7046. CIW_CLR_SCSI_RESET_INT);
  7047. AscSetChipStatus(iop_base, 0);
  7048. AscSetChipControl(iop_base, 0);
  7049. }
  7050. }
  7051. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  7052. asc_isr_callback(asc_dvc, scsiq);
  7053. } else {
  7054. if ((AscReadLramByte(iop_base,
  7055. (ushort)(q_addr + (ushort)
  7056. ASC_SCSIQ_CDB_BEG))
  7057. == START_STOP)) {
  7058. asc_dvc->unit_not_ready &= ~target_id;
  7059. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  7060. asc_dvc->start_motor &=
  7061. ~target_id;
  7062. }
  7063. }
  7064. }
  7065. return (1);
  7066. } else {
  7067. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  7068. FATAL_ERR_QDONE:
  7069. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  7070. asc_isr_callback(asc_dvc, scsiq);
  7071. }
  7072. return (0x80);
  7073. }
  7074. }
  7075. return (0);
  7076. }
  7077. static int AscISR(ASC_DVC_VAR *asc_dvc)
  7078. {
  7079. ASC_CS_TYPE chipstat;
  7080. PortAddr iop_base;
  7081. ushort saved_ram_addr;
  7082. uchar ctrl_reg;
  7083. uchar saved_ctrl_reg;
  7084. int int_pending;
  7085. int status;
  7086. uchar host_flag;
  7087. iop_base = asc_dvc->iop_base;
  7088. int_pending = FALSE;
  7089. if (AscIsIntPending(iop_base) == 0)
  7090. return int_pending;
  7091. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  7092. return ERR;
  7093. }
  7094. if (asc_dvc->in_critical_cnt != 0) {
  7095. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  7096. return ERR;
  7097. }
  7098. if (asc_dvc->is_in_int) {
  7099. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  7100. return ERR;
  7101. }
  7102. asc_dvc->is_in_int = TRUE;
  7103. ctrl_reg = AscGetChipControl(iop_base);
  7104. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  7105. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  7106. chipstat = AscGetChipStatus(iop_base);
  7107. if (chipstat & CSW_SCSI_RESET_LATCH) {
  7108. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  7109. int i = 10;
  7110. int_pending = TRUE;
  7111. asc_dvc->sdtr_done = 0;
  7112. saved_ctrl_reg &= (uchar)(~CC_HALT);
  7113. while ((AscGetChipStatus(iop_base) &
  7114. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  7115. mdelay(100);
  7116. }
  7117. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  7118. AscSetChipControl(iop_base, CC_HALT);
  7119. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  7120. AscSetChipStatus(iop_base, 0);
  7121. chipstat = AscGetChipStatus(iop_base);
  7122. }
  7123. }
  7124. saved_ram_addr = AscGetChipLramAddr(iop_base);
  7125. host_flag = AscReadLramByte(iop_base,
  7126. ASCV_HOST_FLAG_B) &
  7127. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  7128. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  7129. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  7130. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  7131. AscAckInterrupt(iop_base);
  7132. int_pending = TRUE;
  7133. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  7134. if (AscIsrChipHalted(asc_dvc) == ERR) {
  7135. goto ISR_REPORT_QDONE_FATAL_ERROR;
  7136. } else {
  7137. saved_ctrl_reg &= (uchar)(~CC_HALT);
  7138. }
  7139. } else {
  7140. ISR_REPORT_QDONE_FATAL_ERROR:
  7141. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  7142. while (((status =
  7143. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  7144. }
  7145. } else {
  7146. do {
  7147. if ((status =
  7148. AscIsrQDone(asc_dvc)) == 1) {
  7149. break;
  7150. }
  7151. } while (status == 0x11);
  7152. }
  7153. if ((status & 0x80) != 0)
  7154. int_pending = ERR;
  7155. }
  7156. }
  7157. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  7158. AscSetChipLramAddr(iop_base, saved_ram_addr);
  7159. AscSetChipControl(iop_base, saved_ctrl_reg);
  7160. asc_dvc->is_in_int = FALSE;
  7161. return int_pending;
  7162. }
  7163. /*
  7164. * advansys_reset()
  7165. *
  7166. * Reset the bus associated with the command 'scp'.
  7167. *
  7168. * This function runs its own thread. Interrupts must be blocked but
  7169. * sleeping is allowed and no locking other than for host structures is
  7170. * required. Returns SUCCESS or FAILED.
  7171. */
  7172. static int advansys_reset(struct scsi_cmnd *scp)
  7173. {
  7174. struct Scsi_Host *shost = scp->device->host;
  7175. struct asc_board *boardp = shost_priv(shost);
  7176. unsigned long flags;
  7177. int status;
  7178. int ret = SUCCESS;
  7179. ASC_DBG(1, "0x%p\n", scp);
  7180. ASC_STATS(shost, reset);
  7181. scmd_printk(KERN_INFO, scp, "SCSI bus reset started...\n");
  7182. if (ASC_NARROW_BOARD(boardp)) {
  7183. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7184. /* Reset the chip and SCSI bus. */
  7185. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  7186. status = AscInitAsc1000Driver(asc_dvc);
  7187. /* Refer to ASC_IERR_* defintions for meaning of 'err_code'. */
  7188. if (asc_dvc->err_code) {
  7189. scmd_printk(KERN_INFO, scp, "SCSI bus reset error: "
  7190. "0x%x\n", asc_dvc->err_code);
  7191. ret = FAILED;
  7192. } else if (status) {
  7193. scmd_printk(KERN_INFO, scp, "SCSI bus reset warning: "
  7194. "0x%x\n", status);
  7195. } else {
  7196. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  7197. "successful\n");
  7198. }
  7199. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  7200. spin_lock_irqsave(shost->host_lock, flags);
  7201. } else {
  7202. /*
  7203. * If the suggest reset bus flags are set, then reset the bus.
  7204. * Otherwise only reset the device.
  7205. */
  7206. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  7207. /*
  7208. * Reset the target's SCSI bus.
  7209. */
  7210. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  7211. switch (AdvResetChipAndSB(adv_dvc)) {
  7212. case ASC_TRUE:
  7213. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  7214. "successful\n");
  7215. break;
  7216. case ASC_FALSE:
  7217. default:
  7218. scmd_printk(KERN_INFO, scp, "SCSI bus reset error\n");
  7219. ret = FAILED;
  7220. break;
  7221. }
  7222. spin_lock_irqsave(shost->host_lock, flags);
  7223. AdvISR(adv_dvc);
  7224. }
  7225. /* Save the time of the most recently completed reset. */
  7226. boardp->last_reset = jiffies;
  7227. spin_unlock_irqrestore(shost->host_lock, flags);
  7228. ASC_DBG(1, "ret %d\n", ret);
  7229. return ret;
  7230. }
  7231. /*
  7232. * advansys_biosparam()
  7233. *
  7234. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  7235. * support is enabled for a drive.
  7236. *
  7237. * ip (information pointer) is an int array with the following definition:
  7238. * ip[0]: heads
  7239. * ip[1]: sectors
  7240. * ip[2]: cylinders
  7241. */
  7242. static int
  7243. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  7244. sector_t capacity, int ip[])
  7245. {
  7246. struct asc_board *boardp = shost_priv(sdev->host);
  7247. ASC_DBG(1, "begin\n");
  7248. ASC_STATS(sdev->host, biosparam);
  7249. if (ASC_NARROW_BOARD(boardp)) {
  7250. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  7251. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  7252. ip[0] = 255;
  7253. ip[1] = 63;
  7254. } else {
  7255. ip[0] = 64;
  7256. ip[1] = 32;
  7257. }
  7258. } else {
  7259. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  7260. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  7261. ip[0] = 255;
  7262. ip[1] = 63;
  7263. } else {
  7264. ip[0] = 64;
  7265. ip[1] = 32;
  7266. }
  7267. }
  7268. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  7269. ASC_DBG(1, "end\n");
  7270. return 0;
  7271. }
  7272. /*
  7273. * First-level interrupt handler.
  7274. *
  7275. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  7276. */
  7277. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  7278. {
  7279. struct Scsi_Host *shost = dev_id;
  7280. struct asc_board *boardp = shost_priv(shost);
  7281. irqreturn_t result = IRQ_NONE;
  7282. ASC_DBG(2, "boardp 0x%p\n", boardp);
  7283. spin_lock(shost->host_lock);
  7284. if (ASC_NARROW_BOARD(boardp)) {
  7285. if (AscIsIntPending(shost->io_port)) {
  7286. result = IRQ_HANDLED;
  7287. ASC_STATS(shost, interrupt);
  7288. ASC_DBG(1, "before AscISR()\n");
  7289. AscISR(&boardp->dvc_var.asc_dvc_var);
  7290. }
  7291. } else {
  7292. ASC_DBG(1, "before AdvISR()\n");
  7293. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  7294. result = IRQ_HANDLED;
  7295. ASC_STATS(shost, interrupt);
  7296. }
  7297. }
  7298. spin_unlock(shost->host_lock);
  7299. ASC_DBG(1, "end\n");
  7300. return result;
  7301. }
  7302. static int AscHostReqRiscHalt(PortAddr iop_base)
  7303. {
  7304. int count = 0;
  7305. int sta = 0;
  7306. uchar saved_stop_code;
  7307. if (AscIsChipHalted(iop_base))
  7308. return (1);
  7309. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  7310. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  7311. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  7312. do {
  7313. if (AscIsChipHalted(iop_base)) {
  7314. sta = 1;
  7315. break;
  7316. }
  7317. mdelay(100);
  7318. } while (count++ < 20);
  7319. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  7320. return (sta);
  7321. }
  7322. static int
  7323. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  7324. {
  7325. int sta = FALSE;
  7326. if (AscHostReqRiscHalt(iop_base)) {
  7327. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  7328. AscStartChip(iop_base);
  7329. }
  7330. return sta;
  7331. }
  7332. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  7333. {
  7334. char type = sdev->type;
  7335. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  7336. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  7337. return;
  7338. if (asc_dvc->init_sdtr & tid_bits)
  7339. return;
  7340. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  7341. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  7342. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  7343. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  7344. (type == TYPE_ROM) || (type == TYPE_TAPE))
  7345. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  7346. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  7347. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  7348. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  7349. }
  7350. static void
  7351. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  7352. {
  7353. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  7354. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  7355. if (sdev->lun == 0) {
  7356. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  7357. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  7358. asc_dvc->init_sdtr |= tid_bit;
  7359. } else {
  7360. asc_dvc->init_sdtr &= ~tid_bit;
  7361. }
  7362. if (orig_init_sdtr != asc_dvc->init_sdtr)
  7363. AscAsyncFix(asc_dvc, sdev);
  7364. }
  7365. if (sdev->tagged_supported) {
  7366. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  7367. if (sdev->lun == 0) {
  7368. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  7369. asc_dvc->use_tagged_qng |= tid_bit;
  7370. }
  7371. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7372. asc_dvc->max_dvc_qng[sdev->id]);
  7373. }
  7374. } else {
  7375. if (sdev->lun == 0) {
  7376. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  7377. asc_dvc->use_tagged_qng &= ~tid_bit;
  7378. }
  7379. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7380. }
  7381. if ((sdev->lun == 0) &&
  7382. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  7383. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  7384. asc_dvc->cfg->disc_enable);
  7385. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  7386. asc_dvc->use_tagged_qng);
  7387. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  7388. asc_dvc->cfg->can_tagged_qng);
  7389. asc_dvc->max_dvc_qng[sdev->id] =
  7390. asc_dvc->cfg->max_tag_qng[sdev->id];
  7391. AscWriteLramByte(asc_dvc->iop_base,
  7392. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  7393. asc_dvc->max_dvc_qng[sdev->id]);
  7394. }
  7395. }
  7396. /*
  7397. * Wide Transfers
  7398. *
  7399. * If the EEPROM enabled WDTR for the device and the device supports wide
  7400. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  7401. * write the new value to the microcode.
  7402. */
  7403. static void
  7404. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  7405. {
  7406. unsigned short cfg_word;
  7407. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  7408. if ((cfg_word & tidmask) != 0)
  7409. return;
  7410. cfg_word |= tidmask;
  7411. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  7412. /*
  7413. * Clear the microcode SDTR and WDTR negotiation done indicators for
  7414. * the target to cause it to negotiate with the new setting set above.
  7415. * WDTR when accepted causes the target to enter asynchronous mode, so
  7416. * SDTR must be negotiated.
  7417. */
  7418. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7419. cfg_word &= ~tidmask;
  7420. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7421. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  7422. cfg_word &= ~tidmask;
  7423. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  7424. }
  7425. /*
  7426. * Synchronous Transfers
  7427. *
  7428. * If the EEPROM enabled SDTR for the device and the device
  7429. * supports synchronous transfers, then turn on the device's
  7430. * 'sdtr_able' bit. Write the new value to the microcode.
  7431. */
  7432. static void
  7433. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  7434. {
  7435. unsigned short cfg_word;
  7436. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  7437. if ((cfg_word & tidmask) != 0)
  7438. return;
  7439. cfg_word |= tidmask;
  7440. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  7441. /*
  7442. * Clear the microcode "SDTR negotiation" done indicator for the
  7443. * target to cause it to negotiate with the new setting set above.
  7444. */
  7445. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7446. cfg_word &= ~tidmask;
  7447. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7448. }
  7449. /*
  7450. * PPR (Parallel Protocol Request) Capable
  7451. *
  7452. * If the device supports DT mode, then it must be PPR capable.
  7453. * The PPR message will be used in place of the SDTR and WDTR
  7454. * messages to negotiate synchronous speed and offset, transfer
  7455. * width, and protocol options.
  7456. */
  7457. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  7458. AdvPortAddr iop_base, unsigned short tidmask)
  7459. {
  7460. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7461. adv_dvc->ppr_able |= tidmask;
  7462. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7463. }
  7464. static void
  7465. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  7466. {
  7467. AdvPortAddr iop_base = adv_dvc->iop_base;
  7468. unsigned short tidmask = 1 << sdev->id;
  7469. if (sdev->lun == 0) {
  7470. /*
  7471. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  7472. * is enabled in the EEPROM and the device supports the
  7473. * feature, then enable it in the microcode.
  7474. */
  7475. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  7476. advansys_wide_enable_wdtr(iop_base, tidmask);
  7477. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  7478. advansys_wide_enable_sdtr(iop_base, tidmask);
  7479. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  7480. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  7481. /*
  7482. * Tag Queuing is disabled for the BIOS which runs in polled
  7483. * mode and would see no benefit from Tag Queuing. Also by
  7484. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  7485. * bugs will at least work with the BIOS.
  7486. */
  7487. if ((adv_dvc->tagqng_able & tidmask) &&
  7488. sdev->tagged_supported) {
  7489. unsigned short cfg_word;
  7490. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  7491. cfg_word |= tidmask;
  7492. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  7493. cfg_word);
  7494. AdvWriteByteLram(iop_base,
  7495. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  7496. adv_dvc->max_dvc_qng);
  7497. }
  7498. }
  7499. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) {
  7500. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7501. adv_dvc->max_dvc_qng);
  7502. } else {
  7503. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7504. }
  7505. }
  7506. /*
  7507. * Set the number of commands to queue per device for the
  7508. * specified host adapter.
  7509. */
  7510. static int advansys_slave_configure(struct scsi_device *sdev)
  7511. {
  7512. struct asc_board *boardp = shost_priv(sdev->host);
  7513. if (ASC_NARROW_BOARD(boardp))
  7514. advansys_narrow_slave_configure(sdev,
  7515. &boardp->dvc_var.asc_dvc_var);
  7516. else
  7517. advansys_wide_slave_configure(sdev,
  7518. &boardp->dvc_var.adv_dvc_var);
  7519. return 0;
  7520. }
  7521. static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
  7522. {
  7523. struct asc_board *board = shost_priv(scp->device->host);
  7524. scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  7525. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7526. dma_cache_sync(board->dev, scp->sense_buffer,
  7527. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7528. return cpu_to_le32(scp->SCp.dma_handle);
  7529. }
  7530. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7531. struct asc_scsi_q *asc_scsi_q)
  7532. {
  7533. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7534. int use_sg;
  7535. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  7536. /*
  7537. * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
  7538. */
  7539. asc_scsi_q->q2.srb_ptr = advansys_ptr_to_srb(asc_dvc, scp);
  7540. if (asc_scsi_q->q2.srb_ptr == BAD_SRB) {
  7541. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7542. return ASC_ERROR;
  7543. }
  7544. /*
  7545. * Build the ASC_SCSI_Q request.
  7546. */
  7547. asc_scsi_q->cdbptr = &scp->cmnd[0];
  7548. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  7549. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  7550. asc_scsi_q->q1.target_lun = scp->device->lun;
  7551. asc_scsi_q->q2.target_ix =
  7552. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  7553. asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
  7554. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  7555. /*
  7556. * If there are any outstanding requests for the current target,
  7557. * then every 255th request send an ORDERED request. This heuristic
  7558. * tries to retain the benefit of request sorting while preventing
  7559. * request starvation. 255 is the max number of tags or pending commands
  7560. * a device may have outstanding.
  7561. *
  7562. * The request count is incremented below for every successfully
  7563. * started request.
  7564. *
  7565. */
  7566. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  7567. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  7568. asc_scsi_q->q2.tag_code = MSG_ORDERED_TAG;
  7569. } else {
  7570. asc_scsi_q->q2.tag_code = MSG_SIMPLE_TAG;
  7571. }
  7572. /* Build ASC_SCSI_Q */
  7573. use_sg = scsi_dma_map(scp);
  7574. if (use_sg != 0) {
  7575. int sgcnt;
  7576. struct scatterlist *slp;
  7577. struct asc_sg_head *asc_sg_head;
  7578. if (use_sg > scp->device->host->sg_tablesize) {
  7579. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7580. "sg_tablesize %d\n", use_sg,
  7581. scp->device->host->sg_tablesize);
  7582. scsi_dma_unmap(scp);
  7583. scp->result = HOST_BYTE(DID_ERROR);
  7584. return ASC_ERROR;
  7585. }
  7586. asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
  7587. use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
  7588. if (!asc_sg_head) {
  7589. scsi_dma_unmap(scp);
  7590. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7591. return ASC_ERROR;
  7592. }
  7593. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  7594. asc_scsi_q->sg_head = asc_sg_head;
  7595. asc_scsi_q->q1.data_cnt = 0;
  7596. asc_scsi_q->q1.data_addr = 0;
  7597. /* This is a byte value, otherwise it would need to be swapped. */
  7598. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  7599. ASC_STATS_ADD(scp->device->host, xfer_elem,
  7600. asc_sg_head->entry_cnt);
  7601. /*
  7602. * Convert scatter-gather list into ASC_SG_HEAD list.
  7603. */
  7604. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  7605. asc_sg_head->sg_list[sgcnt].addr =
  7606. cpu_to_le32(sg_dma_address(slp));
  7607. asc_sg_head->sg_list[sgcnt].bytes =
  7608. cpu_to_le32(sg_dma_len(slp));
  7609. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7610. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7611. }
  7612. }
  7613. ASC_STATS(scp->device->host, xfer_cnt);
  7614. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  7615. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7616. return ASC_NOERROR;
  7617. }
  7618. /*
  7619. * Build scatter-gather list for Adv Library (Wide Board).
  7620. *
  7621. * Additional ADV_SG_BLOCK structures will need to be allocated
  7622. * if the total number of scatter-gather elements exceeds
  7623. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  7624. * assumed to be physically contiguous.
  7625. *
  7626. * Return:
  7627. * ADV_SUCCESS(1) - SG List successfully created
  7628. * ADV_ERROR(-1) - SG List creation failed
  7629. */
  7630. static int
  7631. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp, struct scsi_cmnd *scp,
  7632. int use_sg)
  7633. {
  7634. adv_sgblk_t *sgblkp;
  7635. ADV_SCSI_REQ_Q *scsiqp;
  7636. struct scatterlist *slp;
  7637. int sg_elem_cnt;
  7638. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  7639. ADV_PADDR sg_block_paddr;
  7640. int i;
  7641. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7642. slp = scsi_sglist(scp);
  7643. sg_elem_cnt = use_sg;
  7644. prev_sg_block = NULL;
  7645. reqp->sgblkp = NULL;
  7646. for (;;) {
  7647. /*
  7648. * Allocate a 'adv_sgblk_t' structure from the board free
  7649. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  7650. * (15) scatter-gather elements.
  7651. */
  7652. if ((sgblkp = boardp->adv_sgblkp) == NULL) {
  7653. ASC_DBG(1, "no free adv_sgblk_t\n");
  7654. ASC_STATS(scp->device->host, adv_build_nosg);
  7655. /*
  7656. * Allocation failed. Free 'adv_sgblk_t' structures
  7657. * already allocated for the request.
  7658. */
  7659. while ((sgblkp = reqp->sgblkp) != NULL) {
  7660. /* Remove 'sgblkp' from the request list. */
  7661. reqp->sgblkp = sgblkp->next_sgblkp;
  7662. /* Add 'sgblkp' to the board free list. */
  7663. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  7664. boardp->adv_sgblkp = sgblkp;
  7665. }
  7666. return ASC_BUSY;
  7667. }
  7668. /* Complete 'adv_sgblk_t' board allocation. */
  7669. boardp->adv_sgblkp = sgblkp->next_sgblkp;
  7670. sgblkp->next_sgblkp = NULL;
  7671. /*
  7672. * Get 8 byte aligned virtual and physical addresses
  7673. * for the allocated ADV_SG_BLOCK structure.
  7674. */
  7675. sg_block = (ADV_SG_BLOCK *)ADV_8BALIGN(&sgblkp->sg_block);
  7676. sg_block_paddr = virt_to_bus(sg_block);
  7677. /*
  7678. * Check if this is the first 'adv_sgblk_t' for the
  7679. * request.
  7680. */
  7681. if (reqp->sgblkp == NULL) {
  7682. /* Request's first scatter-gather block. */
  7683. reqp->sgblkp = sgblkp;
  7684. /*
  7685. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  7686. * address pointers.
  7687. */
  7688. scsiqp->sg_list_ptr = sg_block;
  7689. scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
  7690. } else {
  7691. /* Request's second or later scatter-gather block. */
  7692. sgblkp->next_sgblkp = reqp->sgblkp;
  7693. reqp->sgblkp = sgblkp;
  7694. /*
  7695. * Point the previous ADV_SG_BLOCK structure to
  7696. * the newly allocated ADV_SG_BLOCK structure.
  7697. */
  7698. prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
  7699. }
  7700. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  7701. sg_block->sg_list[i].sg_addr =
  7702. cpu_to_le32(sg_dma_address(slp));
  7703. sg_block->sg_list[i].sg_count =
  7704. cpu_to_le32(sg_dma_len(slp));
  7705. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7706. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7707. if (--sg_elem_cnt == 0) { /* Last ADV_SG_BLOCK and scatter-gather entry. */
  7708. sg_block->sg_cnt = i + 1;
  7709. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  7710. return ADV_SUCCESS;
  7711. }
  7712. slp++;
  7713. }
  7714. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  7715. prev_sg_block = sg_block;
  7716. }
  7717. }
  7718. /*
  7719. * Build a request structure for the Adv Library (Wide Board).
  7720. *
  7721. * If an adv_req_t can not be allocated to issue the request,
  7722. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  7723. *
  7724. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
  7725. * microcode for DMA addresses or math operations are byte swapped
  7726. * to little-endian order.
  7727. */
  7728. static int
  7729. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7730. ADV_SCSI_REQ_Q **adv_scsiqpp)
  7731. {
  7732. adv_req_t *reqp;
  7733. ADV_SCSI_REQ_Q *scsiqp;
  7734. int i;
  7735. int ret;
  7736. int use_sg;
  7737. /*
  7738. * Allocate an adv_req_t structure from the board to execute
  7739. * the command.
  7740. */
  7741. if (boardp->adv_reqp == NULL) {
  7742. ASC_DBG(1, "no free adv_req_t\n");
  7743. ASC_STATS(scp->device->host, adv_build_noreq);
  7744. return ASC_BUSY;
  7745. } else {
  7746. reqp = boardp->adv_reqp;
  7747. boardp->adv_reqp = reqp->next_reqp;
  7748. reqp->next_reqp = NULL;
  7749. }
  7750. /*
  7751. * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
  7752. */
  7753. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7754. /*
  7755. * Initialize the structure.
  7756. */
  7757. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  7758. /*
  7759. * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
  7760. */
  7761. scsiqp->srb_ptr = ADV_VADDR_TO_U32(reqp);
  7762. /*
  7763. * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
  7764. */
  7765. reqp->cmndp = scp;
  7766. /*
  7767. * Build the ADV_SCSI_REQ_Q request.
  7768. */
  7769. /* Set CDB length and copy it to the request structure. */
  7770. scsiqp->cdb_len = scp->cmd_len;
  7771. /* Copy first 12 CDB bytes to cdb[]. */
  7772. for (i = 0; i < scp->cmd_len && i < 12; i++) {
  7773. scsiqp->cdb[i] = scp->cmnd[i];
  7774. }
  7775. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  7776. for (; i < scp->cmd_len; i++) {
  7777. scsiqp->cdb16[i - 12] = scp->cmnd[i];
  7778. }
  7779. scsiqp->target_id = scp->device->id;
  7780. scsiqp->target_lun = scp->device->lun;
  7781. scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
  7782. scsiqp->sense_len = SCSI_SENSE_BUFFERSIZE;
  7783. /* Build ADV_SCSI_REQ_Q */
  7784. use_sg = scsi_dma_map(scp);
  7785. if (use_sg == 0) {
  7786. /* Zero-length transfer */
  7787. reqp->sgblkp = NULL;
  7788. scsiqp->data_cnt = 0;
  7789. scsiqp->vdata_addr = NULL;
  7790. scsiqp->data_addr = 0;
  7791. scsiqp->sg_list_ptr = NULL;
  7792. scsiqp->sg_real_addr = 0;
  7793. } else {
  7794. if (use_sg > ADV_MAX_SG_LIST) {
  7795. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7796. "ADV_MAX_SG_LIST %d\n", use_sg,
  7797. scp->device->host->sg_tablesize);
  7798. scsi_dma_unmap(scp);
  7799. scp->result = HOST_BYTE(DID_ERROR);
  7800. /*
  7801. * Free the 'adv_req_t' structure by adding it back
  7802. * to the board free list.
  7803. */
  7804. reqp->next_reqp = boardp->adv_reqp;
  7805. boardp->adv_reqp = reqp;
  7806. return ASC_ERROR;
  7807. }
  7808. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  7809. ret = adv_get_sglist(boardp, reqp, scp, use_sg);
  7810. if (ret != ADV_SUCCESS) {
  7811. /*
  7812. * Free the adv_req_t structure by adding it back to
  7813. * the board free list.
  7814. */
  7815. reqp->next_reqp = boardp->adv_reqp;
  7816. boardp->adv_reqp = reqp;
  7817. return ret;
  7818. }
  7819. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  7820. }
  7821. ASC_STATS(scp->device->host, xfer_cnt);
  7822. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  7823. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7824. *adv_scsiqpp = scsiqp;
  7825. return ASC_NOERROR;
  7826. }
  7827. static int AscSgListToQueue(int sg_list)
  7828. {
  7829. int n_sg_list_qs;
  7830. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  7831. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  7832. n_sg_list_qs++;
  7833. return n_sg_list_qs + 1;
  7834. }
  7835. static uint
  7836. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  7837. {
  7838. uint cur_used_qs;
  7839. uint cur_free_qs;
  7840. ASC_SCSI_BIT_ID_TYPE target_id;
  7841. uchar tid_no;
  7842. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  7843. tid_no = ASC_TIX_TO_TID(target_ix);
  7844. if ((asc_dvc->unit_not_ready & target_id) ||
  7845. (asc_dvc->queue_full_or_busy & target_id)) {
  7846. return 0;
  7847. }
  7848. if (n_qs == 1) {
  7849. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7850. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  7851. } else {
  7852. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7853. (uint) ASC_MIN_FREE_Q;
  7854. }
  7855. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  7856. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  7857. if (asc_dvc->cur_dvc_qng[tid_no] >=
  7858. asc_dvc->max_dvc_qng[tid_no]) {
  7859. return 0;
  7860. }
  7861. return cur_free_qs;
  7862. }
  7863. if (n_qs > 1) {
  7864. if ((n_qs > asc_dvc->last_q_shortage)
  7865. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  7866. asc_dvc->last_q_shortage = n_qs;
  7867. }
  7868. }
  7869. return 0;
  7870. }
  7871. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7872. {
  7873. ushort q_addr;
  7874. uchar next_qp;
  7875. uchar q_status;
  7876. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7877. q_status = (uchar)AscReadLramByte(iop_base,
  7878. (ushort)(q_addr +
  7879. ASC_SCSIQ_B_STATUS));
  7880. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7881. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7882. return next_qp;
  7883. return ASC_QLINK_END;
  7884. }
  7885. static uchar
  7886. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7887. {
  7888. uchar i;
  7889. for (i = 0; i < n_free_q; i++) {
  7890. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7891. if (free_q_head == ASC_QLINK_END)
  7892. break;
  7893. }
  7894. return free_q_head;
  7895. }
  7896. /*
  7897. * void
  7898. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7899. *
  7900. * Calling/Exit State:
  7901. * none
  7902. *
  7903. * Description:
  7904. * Output an ASC_SCSI_Q structure to the chip
  7905. */
  7906. static void
  7907. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7908. {
  7909. int i;
  7910. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7911. AscSetChipLramAddr(iop_base, s_addr);
  7912. for (i = 0; i < 2 * words; i += 2) {
  7913. if (i == 4 || i == 20) {
  7914. continue;
  7915. }
  7916. outpw(iop_base + IOP_RAM_DATA,
  7917. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7918. }
  7919. }
  7920. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7921. {
  7922. ushort q_addr;
  7923. uchar tid_no;
  7924. uchar sdtr_data;
  7925. uchar syn_period_ix;
  7926. uchar syn_offset;
  7927. PortAddr iop_base;
  7928. iop_base = asc_dvc->iop_base;
  7929. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7930. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7931. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7932. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7933. syn_period_ix =
  7934. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7935. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7936. AscMsgOutSDTR(asc_dvc,
  7937. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7938. syn_offset);
  7939. scsiq->q1.cntl |= QC_MSG_OUT;
  7940. }
  7941. q_addr = ASC_QNO_TO_QADDR(q_no);
  7942. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7943. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  7944. }
  7945. scsiq->q1.status = QS_FREE;
  7946. AscMemWordCopyPtrToLram(iop_base,
  7947. q_addr + ASC_SCSIQ_CDB_BEG,
  7948. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7949. DvcPutScsiQ(iop_base,
  7950. q_addr + ASC_SCSIQ_CPY_BEG,
  7951. (uchar *)&scsiq->q1.cntl,
  7952. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7953. AscWriteLramWord(iop_base,
  7954. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7955. (ushort)(((ushort)scsiq->q1.
  7956. q_no << 8) | (ushort)QS_READY));
  7957. return 1;
  7958. }
  7959. static int
  7960. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7961. {
  7962. int sta;
  7963. int i;
  7964. ASC_SG_HEAD *sg_head;
  7965. ASC_SG_LIST_Q scsi_sg_q;
  7966. ASC_DCNT saved_data_addr;
  7967. ASC_DCNT saved_data_cnt;
  7968. PortAddr iop_base;
  7969. ushort sg_list_dwords;
  7970. ushort sg_index;
  7971. ushort sg_entry_cnt;
  7972. ushort q_addr;
  7973. uchar next_qp;
  7974. iop_base = asc_dvc->iop_base;
  7975. sg_head = scsiq->sg_head;
  7976. saved_data_addr = scsiq->q1.data_addr;
  7977. saved_data_cnt = scsiq->q1.data_cnt;
  7978. scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
  7979. scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
  7980. #if CC_VERY_LONG_SG_LIST
  7981. /*
  7982. * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
  7983. * then not all SG elements will fit in the allocated queues.
  7984. * The rest of the SG elements will be copied when the RISC
  7985. * completes the SG elements that fit and halts.
  7986. */
  7987. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  7988. /*
  7989. * Set sg_entry_cnt to be the number of SG elements that
  7990. * will fit in the allocated SG queues. It is minus 1, because
  7991. * the first SG element is handled above. ASC_MAX_SG_LIST is
  7992. * already inflated by 1 to account for this. For example it
  7993. * may be 50 which is 1 + 7 queues * 7 SG elements.
  7994. */
  7995. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  7996. /*
  7997. * Keep track of remaining number of SG elements that will
  7998. * need to be handled from a_isr.c.
  7999. */
  8000. scsiq->remain_sg_entry_cnt =
  8001. sg_head->entry_cnt - ASC_MAX_SG_LIST;
  8002. } else {
  8003. #endif /* CC_VERY_LONG_SG_LIST */
  8004. /*
  8005. * Set sg_entry_cnt to be the number of SG elements that
  8006. * will fit in the allocated SG queues. It is minus 1, because
  8007. * the first SG element is handled above.
  8008. */
  8009. sg_entry_cnt = sg_head->entry_cnt - 1;
  8010. #if CC_VERY_LONG_SG_LIST
  8011. }
  8012. #endif /* CC_VERY_LONG_SG_LIST */
  8013. if (sg_entry_cnt != 0) {
  8014. scsiq->q1.cntl |= QC_SG_HEAD;
  8015. q_addr = ASC_QNO_TO_QADDR(q_no);
  8016. sg_index = 1;
  8017. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  8018. scsi_sg_q.sg_head_qp = q_no;
  8019. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  8020. for (i = 0; i < sg_head->queue_cnt; i++) {
  8021. scsi_sg_q.seq_no = i + 1;
  8022. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  8023. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  8024. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  8025. if (i == 0) {
  8026. scsi_sg_q.sg_list_cnt =
  8027. ASC_SG_LIST_PER_Q;
  8028. scsi_sg_q.sg_cur_list_cnt =
  8029. ASC_SG_LIST_PER_Q;
  8030. } else {
  8031. scsi_sg_q.sg_list_cnt =
  8032. ASC_SG_LIST_PER_Q - 1;
  8033. scsi_sg_q.sg_cur_list_cnt =
  8034. ASC_SG_LIST_PER_Q - 1;
  8035. }
  8036. } else {
  8037. #if CC_VERY_LONG_SG_LIST
  8038. /*
  8039. * This is the last SG queue in the list of
  8040. * allocated SG queues. If there are more
  8041. * SG elements than will fit in the allocated
  8042. * queues, then set the QCSG_SG_XFER_MORE flag.
  8043. */
  8044. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  8045. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  8046. } else {
  8047. #endif /* CC_VERY_LONG_SG_LIST */
  8048. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  8049. #if CC_VERY_LONG_SG_LIST
  8050. }
  8051. #endif /* CC_VERY_LONG_SG_LIST */
  8052. sg_list_dwords = sg_entry_cnt << 1;
  8053. if (i == 0) {
  8054. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  8055. scsi_sg_q.sg_cur_list_cnt =
  8056. sg_entry_cnt;
  8057. } else {
  8058. scsi_sg_q.sg_list_cnt =
  8059. sg_entry_cnt - 1;
  8060. scsi_sg_q.sg_cur_list_cnt =
  8061. sg_entry_cnt - 1;
  8062. }
  8063. sg_entry_cnt = 0;
  8064. }
  8065. next_qp = AscReadLramByte(iop_base,
  8066. (ushort)(q_addr +
  8067. ASC_SCSIQ_B_FWD));
  8068. scsi_sg_q.q_no = next_qp;
  8069. q_addr = ASC_QNO_TO_QADDR(next_qp);
  8070. AscMemWordCopyPtrToLram(iop_base,
  8071. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  8072. (uchar *)&scsi_sg_q,
  8073. sizeof(ASC_SG_LIST_Q) >> 1);
  8074. AscMemDWordCopyPtrToLram(iop_base,
  8075. q_addr + ASC_SGQ_LIST_BEG,
  8076. (uchar *)&sg_head->
  8077. sg_list[sg_index],
  8078. sg_list_dwords);
  8079. sg_index += ASC_SG_LIST_PER_Q;
  8080. scsiq->next_sg_index = sg_index;
  8081. }
  8082. } else {
  8083. scsiq->q1.cntl &= ~QC_SG_HEAD;
  8084. }
  8085. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  8086. scsiq->q1.data_addr = saved_data_addr;
  8087. scsiq->q1.data_cnt = saved_data_cnt;
  8088. return (sta);
  8089. }
  8090. static int
  8091. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  8092. {
  8093. PortAddr iop_base;
  8094. uchar free_q_head;
  8095. uchar next_qp;
  8096. uchar tid_no;
  8097. uchar target_ix;
  8098. int sta;
  8099. iop_base = asc_dvc->iop_base;
  8100. target_ix = scsiq->q2.target_ix;
  8101. tid_no = ASC_TIX_TO_TID(target_ix);
  8102. sta = 0;
  8103. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  8104. if (n_q_required > 1) {
  8105. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  8106. (uchar)n_q_required);
  8107. if (next_qp != ASC_QLINK_END) {
  8108. asc_dvc->last_q_shortage = 0;
  8109. scsiq->sg_head->queue_cnt = n_q_required - 1;
  8110. scsiq->q1.q_no = free_q_head;
  8111. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  8112. free_q_head);
  8113. }
  8114. } else if (n_q_required == 1) {
  8115. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  8116. if (next_qp != ASC_QLINK_END) {
  8117. scsiq->q1.q_no = free_q_head;
  8118. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  8119. }
  8120. }
  8121. if (sta == 1) {
  8122. AscPutVarFreeQHead(iop_base, next_qp);
  8123. asc_dvc->cur_total_qng += n_q_required;
  8124. asc_dvc->cur_dvc_qng[tid_no]++;
  8125. }
  8126. return sta;
  8127. }
  8128. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  8129. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  8130. INQUIRY,
  8131. REQUEST_SENSE,
  8132. READ_CAPACITY,
  8133. READ_TOC,
  8134. MODE_SELECT,
  8135. MODE_SENSE,
  8136. MODE_SELECT_10,
  8137. MODE_SENSE_10,
  8138. 0xFF,
  8139. 0xFF,
  8140. 0xFF,
  8141. 0xFF,
  8142. 0xFF,
  8143. 0xFF,
  8144. 0xFF,
  8145. 0xFF
  8146. };
  8147. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  8148. {
  8149. PortAddr iop_base;
  8150. int sta;
  8151. int n_q_required;
  8152. int disable_syn_offset_one_fix;
  8153. int i;
  8154. ASC_PADDR addr;
  8155. ushort sg_entry_cnt = 0;
  8156. ushort sg_entry_cnt_minus_one = 0;
  8157. uchar target_ix;
  8158. uchar tid_no;
  8159. uchar sdtr_data;
  8160. uchar extra_bytes;
  8161. uchar scsi_cmd;
  8162. uchar disable_cmd;
  8163. ASC_SG_HEAD *sg_head;
  8164. ASC_DCNT data_cnt;
  8165. iop_base = asc_dvc->iop_base;
  8166. sg_head = scsiq->sg_head;
  8167. if (asc_dvc->err_code != 0)
  8168. return (ERR);
  8169. scsiq->q1.q_no = 0;
  8170. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  8171. scsiq->q1.extra_bytes = 0;
  8172. }
  8173. sta = 0;
  8174. target_ix = scsiq->q2.target_ix;
  8175. tid_no = ASC_TIX_TO_TID(target_ix);
  8176. n_q_required = 1;
  8177. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  8178. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  8179. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  8180. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  8181. AscMsgOutSDTR(asc_dvc,
  8182. asc_dvc->
  8183. sdtr_period_tbl[(sdtr_data >> 4) &
  8184. (uchar)(asc_dvc->
  8185. max_sdtr_index -
  8186. 1)],
  8187. (uchar)(sdtr_data & (uchar)
  8188. ASC_SYN_MAX_OFFSET));
  8189. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  8190. }
  8191. }
  8192. if (asc_dvc->in_critical_cnt != 0) {
  8193. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  8194. return (ERR);
  8195. }
  8196. asc_dvc->in_critical_cnt++;
  8197. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  8198. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  8199. asc_dvc->in_critical_cnt--;
  8200. return (ERR);
  8201. }
  8202. #if !CC_VERY_LONG_SG_LIST
  8203. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  8204. asc_dvc->in_critical_cnt--;
  8205. return (ERR);
  8206. }
  8207. #endif /* !CC_VERY_LONG_SG_LIST */
  8208. if (sg_entry_cnt == 1) {
  8209. scsiq->q1.data_addr =
  8210. (ADV_PADDR)sg_head->sg_list[0].addr;
  8211. scsiq->q1.data_cnt =
  8212. (ADV_DCNT)sg_head->sg_list[0].bytes;
  8213. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  8214. }
  8215. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  8216. }
  8217. scsi_cmd = scsiq->cdbptr[0];
  8218. disable_syn_offset_one_fix = FALSE;
  8219. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  8220. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  8221. if (scsiq->q1.cntl & QC_SG_HEAD) {
  8222. data_cnt = 0;
  8223. for (i = 0; i < sg_entry_cnt; i++) {
  8224. data_cnt +=
  8225. (ADV_DCNT)le32_to_cpu(sg_head->sg_list[i].
  8226. bytes);
  8227. }
  8228. } else {
  8229. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  8230. }
  8231. if (data_cnt != 0UL) {
  8232. if (data_cnt < 512UL) {
  8233. disable_syn_offset_one_fix = TRUE;
  8234. } else {
  8235. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  8236. i++) {
  8237. disable_cmd =
  8238. _syn_offset_one_disable_cmd[i];
  8239. if (disable_cmd == 0xFF) {
  8240. break;
  8241. }
  8242. if (scsi_cmd == disable_cmd) {
  8243. disable_syn_offset_one_fix =
  8244. TRUE;
  8245. break;
  8246. }
  8247. }
  8248. }
  8249. }
  8250. }
  8251. if (disable_syn_offset_one_fix) {
  8252. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  8253. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  8254. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  8255. } else {
  8256. scsiq->q2.tag_code &= 0x27;
  8257. }
  8258. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  8259. if (asc_dvc->bug_fix_cntl) {
  8260. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  8261. if ((scsi_cmd == READ_6) ||
  8262. (scsi_cmd == READ_10)) {
  8263. addr =
  8264. (ADV_PADDR)le32_to_cpu(sg_head->
  8265. sg_list
  8266. [sg_entry_cnt_minus_one].
  8267. addr) +
  8268. (ADV_DCNT)le32_to_cpu(sg_head->
  8269. sg_list
  8270. [sg_entry_cnt_minus_one].
  8271. bytes);
  8272. extra_bytes =
  8273. (uchar)((ushort)addr & 0x0003);
  8274. if ((extra_bytes != 0)
  8275. &&
  8276. ((scsiq->q2.
  8277. tag_code &
  8278. ASC_TAG_FLAG_EXTRA_BYTES)
  8279. == 0)) {
  8280. scsiq->q2.tag_code |=
  8281. ASC_TAG_FLAG_EXTRA_BYTES;
  8282. scsiq->q1.extra_bytes =
  8283. extra_bytes;
  8284. data_cnt =
  8285. le32_to_cpu(sg_head->
  8286. sg_list
  8287. [sg_entry_cnt_minus_one].
  8288. bytes);
  8289. data_cnt -=
  8290. (ASC_DCNT) extra_bytes;
  8291. sg_head->
  8292. sg_list
  8293. [sg_entry_cnt_minus_one].
  8294. bytes =
  8295. cpu_to_le32(data_cnt);
  8296. }
  8297. }
  8298. }
  8299. }
  8300. sg_head->entry_to_copy = sg_head->entry_cnt;
  8301. #if CC_VERY_LONG_SG_LIST
  8302. /*
  8303. * Set the sg_entry_cnt to the maximum possible. The rest of
  8304. * the SG elements will be copied when the RISC completes the
  8305. * SG elements that fit and halts.
  8306. */
  8307. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  8308. sg_entry_cnt = ASC_MAX_SG_LIST;
  8309. }
  8310. #endif /* CC_VERY_LONG_SG_LIST */
  8311. n_q_required = AscSgListToQueue(sg_entry_cnt);
  8312. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  8313. (uint) n_q_required)
  8314. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  8315. if ((sta =
  8316. AscSendScsiQueue(asc_dvc, scsiq,
  8317. n_q_required)) == 1) {
  8318. asc_dvc->in_critical_cnt--;
  8319. return (sta);
  8320. }
  8321. }
  8322. } else {
  8323. if (asc_dvc->bug_fix_cntl) {
  8324. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  8325. if ((scsi_cmd == READ_6) ||
  8326. (scsi_cmd == READ_10)) {
  8327. addr =
  8328. le32_to_cpu(scsiq->q1.data_addr) +
  8329. le32_to_cpu(scsiq->q1.data_cnt);
  8330. extra_bytes =
  8331. (uchar)((ushort)addr & 0x0003);
  8332. if ((extra_bytes != 0)
  8333. &&
  8334. ((scsiq->q2.
  8335. tag_code &
  8336. ASC_TAG_FLAG_EXTRA_BYTES)
  8337. == 0)) {
  8338. data_cnt =
  8339. le32_to_cpu(scsiq->q1.
  8340. data_cnt);
  8341. if (((ushort)data_cnt & 0x01FF)
  8342. == 0) {
  8343. scsiq->q2.tag_code |=
  8344. ASC_TAG_FLAG_EXTRA_BYTES;
  8345. data_cnt -= (ASC_DCNT)
  8346. extra_bytes;
  8347. scsiq->q1.data_cnt =
  8348. cpu_to_le32
  8349. (data_cnt);
  8350. scsiq->q1.extra_bytes =
  8351. extra_bytes;
  8352. }
  8353. }
  8354. }
  8355. }
  8356. }
  8357. n_q_required = 1;
  8358. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  8359. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  8360. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  8361. n_q_required)) == 1) {
  8362. asc_dvc->in_critical_cnt--;
  8363. return (sta);
  8364. }
  8365. }
  8366. }
  8367. asc_dvc->in_critical_cnt--;
  8368. return (sta);
  8369. }
  8370. /*
  8371. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  8372. *
  8373. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  8374. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  8375. * RISC to notify it a new command is ready to be executed.
  8376. *
  8377. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  8378. * set to SCSI_MAX_RETRY.
  8379. *
  8380. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
  8381. * for DMA addresses or math operations are byte swapped to little-endian
  8382. * order.
  8383. *
  8384. * Return:
  8385. * ADV_SUCCESS(1) - The request was successfully queued.
  8386. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  8387. * request completes.
  8388. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  8389. * host IC error.
  8390. */
  8391. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq)
  8392. {
  8393. AdvPortAddr iop_base;
  8394. ADV_PADDR req_paddr;
  8395. ADV_CARR_T *new_carrp;
  8396. /*
  8397. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  8398. */
  8399. if (scsiq->target_id > ADV_MAX_TID) {
  8400. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  8401. scsiq->done_status = QD_WITH_ERROR;
  8402. return ADV_ERROR;
  8403. }
  8404. iop_base = asc_dvc->iop_base;
  8405. /*
  8406. * Allocate a carrier ensuring at least one carrier always
  8407. * remains on the freelist and initialize fields.
  8408. */
  8409. if ((new_carrp = asc_dvc->carr_freelist) == NULL) {
  8410. return ADV_BUSY;
  8411. }
  8412. asc_dvc->carr_freelist = (ADV_CARR_T *)
  8413. ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
  8414. asc_dvc->carr_pending_cnt++;
  8415. /*
  8416. * Set the carrier to be a stopper by setting 'next_vpa'
  8417. * to the stopper value. The current stopper will be changed
  8418. * below to point to the new stopper.
  8419. */
  8420. new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  8421. /*
  8422. * Clear the ADV_SCSI_REQ_Q done flag.
  8423. */
  8424. scsiq->a_flag &= ~ADV_SCSIQ_DONE;
  8425. req_paddr = virt_to_bus(scsiq);
  8426. BUG_ON(req_paddr & 31);
  8427. /* Wait for assertion before making little-endian */
  8428. req_paddr = cpu_to_le32(req_paddr);
  8429. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  8430. scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
  8431. scsiq->scsiq_rptr = req_paddr;
  8432. scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
  8433. /*
  8434. * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
  8435. * order during initialization.
  8436. */
  8437. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  8438. /*
  8439. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  8440. * the microcode. The newly allocated stopper will become the new
  8441. * stopper.
  8442. */
  8443. asc_dvc->icq_sp->areq_vpa = req_paddr;
  8444. /*
  8445. * Set the 'next_vpa' pointer for the old stopper to be the
  8446. * physical address of the new stopper. The RISC can only
  8447. * follow physical addresses.
  8448. */
  8449. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  8450. /*
  8451. * Set the host adapter stopper pointer to point to the new carrier.
  8452. */
  8453. asc_dvc->icq_sp = new_carrp;
  8454. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  8455. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  8456. /*
  8457. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  8458. */
  8459. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  8460. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  8461. /*
  8462. * Clear the tickle value. In the ASC-3550 the RISC flag
  8463. * command 'clr_tickle_a' does not work unless the host
  8464. * value is cleared.
  8465. */
  8466. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  8467. ADV_TICKLE_NOP);
  8468. }
  8469. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  8470. /*
  8471. * Notify the RISC a carrier is ready by writing the physical
  8472. * address of the new carrier stopper to the COMMA register.
  8473. */
  8474. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  8475. le32_to_cpu(new_carrp->carr_pa));
  8476. }
  8477. return ADV_SUCCESS;
  8478. }
  8479. /*
  8480. * Execute a single 'Scsi_Cmnd'.
  8481. */
  8482. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  8483. {
  8484. int ret, err_code;
  8485. struct asc_board *boardp = shost_priv(scp->device->host);
  8486. ASC_DBG(1, "scp 0x%p\n", scp);
  8487. if (ASC_NARROW_BOARD(boardp)) {
  8488. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  8489. struct asc_scsi_q asc_scsi_q;
  8490. /* asc_build_req() can not return ASC_BUSY. */
  8491. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  8492. if (ret == ASC_ERROR) {
  8493. ASC_STATS(scp->device->host, build_error);
  8494. return ASC_ERROR;
  8495. }
  8496. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  8497. kfree(asc_scsi_q.sg_head);
  8498. err_code = asc_dvc->err_code;
  8499. } else {
  8500. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  8501. ADV_SCSI_REQ_Q *adv_scsiqp;
  8502. switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
  8503. case ASC_NOERROR:
  8504. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  8505. break;
  8506. case ASC_BUSY:
  8507. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  8508. /*
  8509. * The asc_stats fields 'adv_build_noreq' and
  8510. * 'adv_build_nosg' count wide board busy conditions.
  8511. * They are updated in adv_build_req and
  8512. * adv_get_sglist, respectively.
  8513. */
  8514. return ASC_BUSY;
  8515. case ASC_ERROR:
  8516. default:
  8517. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  8518. ASC_STATS(scp->device->host, build_error);
  8519. return ASC_ERROR;
  8520. }
  8521. ret = AdvExeScsiQueue(adv_dvc, adv_scsiqp);
  8522. err_code = adv_dvc->err_code;
  8523. }
  8524. switch (ret) {
  8525. case ASC_NOERROR:
  8526. ASC_STATS(scp->device->host, exe_noerror);
  8527. /*
  8528. * Increment monotonically increasing per device
  8529. * successful request counter. Wrapping doesn't matter.
  8530. */
  8531. boardp->reqcnt[scp->device->id]++;
  8532. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  8533. break;
  8534. case ASC_BUSY:
  8535. ASC_STATS(scp->device->host, exe_busy);
  8536. break;
  8537. case ASC_ERROR:
  8538. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  8539. "err_code 0x%x\n", err_code);
  8540. ASC_STATS(scp->device->host, exe_error);
  8541. scp->result = HOST_BYTE(DID_ERROR);
  8542. break;
  8543. default:
  8544. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  8545. "err_code 0x%x\n", err_code);
  8546. ASC_STATS(scp->device->host, exe_unknown);
  8547. scp->result = HOST_BYTE(DID_ERROR);
  8548. break;
  8549. }
  8550. ASC_DBG(1, "end\n");
  8551. return ret;
  8552. }
  8553. /*
  8554. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  8555. *
  8556. * This function always returns 0. Command return status is saved
  8557. * in the 'scp' result field.
  8558. */
  8559. static int
  8560. advansys_queuecommand(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
  8561. {
  8562. struct Scsi_Host *shost = scp->device->host;
  8563. int asc_res, result = 0;
  8564. ASC_STATS(shost, queuecommand);
  8565. scp->scsi_done = done;
  8566. asc_res = asc_execute_scsi_cmnd(scp);
  8567. switch (asc_res) {
  8568. case ASC_NOERROR:
  8569. break;
  8570. case ASC_BUSY:
  8571. result = SCSI_MLQUEUE_HOST_BUSY;
  8572. break;
  8573. case ASC_ERROR:
  8574. default:
  8575. asc_scsi_done(scp);
  8576. break;
  8577. }
  8578. return result;
  8579. }
  8580. static ushort __devinit AscGetEisaChipCfg(PortAddr iop_base)
  8581. {
  8582. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8583. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  8584. return inpw(eisa_cfg_iop);
  8585. }
  8586. /*
  8587. * Return the BIOS address of the adapter at the specified
  8588. * I/O port and with the specified bus type.
  8589. */
  8590. static unsigned short __devinit
  8591. AscGetChipBiosAddress(PortAddr iop_base, unsigned short bus_type)
  8592. {
  8593. unsigned short cfg_lsw;
  8594. unsigned short bios_addr;
  8595. /*
  8596. * The PCI BIOS is re-located by the motherboard BIOS. Because
  8597. * of this the driver can not determine where a PCI BIOS is
  8598. * loaded and executes.
  8599. */
  8600. if (bus_type & ASC_IS_PCI)
  8601. return 0;
  8602. if ((bus_type & ASC_IS_EISA) != 0) {
  8603. cfg_lsw = AscGetEisaChipCfg(iop_base);
  8604. cfg_lsw &= 0x000F;
  8605. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  8606. return bios_addr;
  8607. }
  8608. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8609. /*
  8610. * ISA PnP uses the top bit as the 32K BIOS flag
  8611. */
  8612. if (bus_type == ASC_IS_ISAPNP)
  8613. cfg_lsw &= 0x7FFF;
  8614. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  8615. return bios_addr;
  8616. }
  8617. static uchar __devinit AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  8618. {
  8619. ushort cfg_lsw;
  8620. if (AscGetChipScsiID(iop_base) == new_host_id) {
  8621. return (new_host_id);
  8622. }
  8623. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8624. cfg_lsw &= 0xF8FF;
  8625. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  8626. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8627. return (AscGetChipScsiID(iop_base));
  8628. }
  8629. static unsigned char __devinit AscGetChipScsiCtrl(PortAddr iop_base)
  8630. {
  8631. unsigned char sc;
  8632. AscSetBank(iop_base, 1);
  8633. sc = inp(iop_base + IOP_REG_SC);
  8634. AscSetBank(iop_base, 0);
  8635. return sc;
  8636. }
  8637. static unsigned char __devinit
  8638. AscGetChipVersion(PortAddr iop_base, unsigned short bus_type)
  8639. {
  8640. if (bus_type & ASC_IS_EISA) {
  8641. PortAddr eisa_iop;
  8642. unsigned char revision;
  8643. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8644. (PortAddr) ASC_EISA_REV_IOP_MASK;
  8645. revision = inp(eisa_iop);
  8646. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  8647. }
  8648. return AscGetChipVerNo(iop_base);
  8649. }
  8650. #ifdef CONFIG_ISA
  8651. static void __devinit AscEnableIsaDma(uchar dma_channel)
  8652. {
  8653. if (dma_channel < 4) {
  8654. outp(0x000B, (ushort)(0xC0 | dma_channel));
  8655. outp(0x000A, dma_channel);
  8656. } else if (dma_channel < 8) {
  8657. outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
  8658. outp(0x00D4, (ushort)(dma_channel - 4));
  8659. }
  8660. }
  8661. #endif /* CONFIG_ISA */
  8662. static int AscStopQueueExe(PortAddr iop_base)
  8663. {
  8664. int count = 0;
  8665. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  8666. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  8667. ASC_STOP_REQ_RISC_STOP);
  8668. do {
  8669. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  8670. ASC_STOP_ACK_RISC_STOP) {
  8671. return (1);
  8672. }
  8673. mdelay(100);
  8674. } while (count++ < 20);
  8675. }
  8676. return (0);
  8677. }
  8678. static ASC_DCNT __devinit AscGetMaxDmaCount(ushort bus_type)
  8679. {
  8680. if (bus_type & ASC_IS_ISA)
  8681. return ASC_MAX_ISA_DMA_COUNT;
  8682. else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  8683. return ASC_MAX_VL_DMA_COUNT;
  8684. return ASC_MAX_PCI_DMA_COUNT;
  8685. }
  8686. #ifdef CONFIG_ISA
  8687. static ushort __devinit AscGetIsaDmaChannel(PortAddr iop_base)
  8688. {
  8689. ushort channel;
  8690. channel = AscGetChipCfgLsw(iop_base) & 0x0003;
  8691. if (channel == 0x03)
  8692. return (0);
  8693. else if (channel == 0x00)
  8694. return (7);
  8695. return (channel + 4);
  8696. }
  8697. static ushort __devinit AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
  8698. {
  8699. ushort cfg_lsw;
  8700. uchar value;
  8701. if ((dma_channel >= 5) && (dma_channel <= 7)) {
  8702. if (dma_channel == 7)
  8703. value = 0x00;
  8704. else
  8705. value = dma_channel - 4;
  8706. cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
  8707. cfg_lsw |= value;
  8708. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8709. return (AscGetIsaDmaChannel(iop_base));
  8710. }
  8711. return 0;
  8712. }
  8713. static uchar __devinit AscGetIsaDmaSpeed(PortAddr iop_base)
  8714. {
  8715. uchar speed_value;
  8716. AscSetBank(iop_base, 1);
  8717. speed_value = AscReadChipDmaSpeed(iop_base);
  8718. speed_value &= 0x07;
  8719. AscSetBank(iop_base, 0);
  8720. return speed_value;
  8721. }
  8722. static uchar __devinit AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
  8723. {
  8724. speed_value &= 0x07;
  8725. AscSetBank(iop_base, 1);
  8726. AscWriteChipDmaSpeed(iop_base, speed_value);
  8727. AscSetBank(iop_base, 0);
  8728. return AscGetIsaDmaSpeed(iop_base);
  8729. }
  8730. #endif /* CONFIG_ISA */
  8731. static ushort __devinit AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  8732. {
  8733. int i;
  8734. PortAddr iop_base;
  8735. ushort warn_code;
  8736. uchar chip_version;
  8737. iop_base = asc_dvc->iop_base;
  8738. warn_code = 0;
  8739. asc_dvc->err_code = 0;
  8740. if ((asc_dvc->bus_type &
  8741. (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  8742. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  8743. }
  8744. AscSetChipControl(iop_base, CC_HALT);
  8745. AscSetChipStatus(iop_base, 0);
  8746. asc_dvc->bug_fix_cntl = 0;
  8747. asc_dvc->pci_fix_asyn_xfer = 0;
  8748. asc_dvc->pci_fix_asyn_xfer_always = 0;
  8749. /* asc_dvc->init_state initalized in AscInitGetConfig(). */
  8750. asc_dvc->sdtr_done = 0;
  8751. asc_dvc->cur_total_qng = 0;
  8752. asc_dvc->is_in_int = 0;
  8753. asc_dvc->in_critical_cnt = 0;
  8754. asc_dvc->last_q_shortage = 0;
  8755. asc_dvc->use_tagged_qng = 0;
  8756. asc_dvc->no_scam = 0;
  8757. asc_dvc->unit_not_ready = 0;
  8758. asc_dvc->queue_full_or_busy = 0;
  8759. asc_dvc->redo_scam = 0;
  8760. asc_dvc->res2 = 0;
  8761. asc_dvc->min_sdtr_index = 0;
  8762. asc_dvc->cfg->can_tagged_qng = 0;
  8763. asc_dvc->cfg->cmd_qng_enabled = 0;
  8764. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  8765. asc_dvc->init_sdtr = 0;
  8766. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  8767. asc_dvc->scsi_reset_wait = 3;
  8768. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  8769. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  8770. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  8771. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  8772. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  8773. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  8774. asc_dvc->cfg->chip_version = chip_version;
  8775. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  8776. asc_dvc->max_sdtr_index = 7;
  8777. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  8778. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  8779. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  8780. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  8781. asc_dvc->max_sdtr_index = 15;
  8782. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  8783. AscSetExtraControl(iop_base,
  8784. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8785. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  8786. AscSetExtraControl(iop_base,
  8787. (SEC_ACTIVE_NEGATE |
  8788. SEC_ENABLE_FILTER));
  8789. }
  8790. }
  8791. if (asc_dvc->bus_type == ASC_IS_PCI) {
  8792. AscSetExtraControl(iop_base,
  8793. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8794. }
  8795. asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
  8796. #ifdef CONFIG_ISA
  8797. if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
  8798. if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
  8799. AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
  8800. asc_dvc->bus_type = ASC_IS_ISAPNP;
  8801. }
  8802. asc_dvc->cfg->isa_dma_channel =
  8803. (uchar)AscGetIsaDmaChannel(iop_base);
  8804. }
  8805. #endif /* CONFIG_ISA */
  8806. for (i = 0; i <= ASC_MAX_TID; i++) {
  8807. asc_dvc->cur_dvc_qng[i] = 0;
  8808. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  8809. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  8810. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  8811. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  8812. }
  8813. return warn_code;
  8814. }
  8815. static int __devinit AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  8816. {
  8817. int retry;
  8818. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  8819. unsigned char read_back;
  8820. AscSetChipEEPCmd(iop_base, cmd_reg);
  8821. mdelay(1);
  8822. read_back = AscGetChipEEPCmd(iop_base);
  8823. if (read_back == cmd_reg)
  8824. return 1;
  8825. }
  8826. return 0;
  8827. }
  8828. static void __devinit AscWaitEEPRead(void)
  8829. {
  8830. mdelay(1);
  8831. }
  8832. static ushort __devinit AscReadEEPWord(PortAddr iop_base, uchar addr)
  8833. {
  8834. ushort read_wval;
  8835. uchar cmd_reg;
  8836. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8837. AscWaitEEPRead();
  8838. cmd_reg = addr | ASC_EEP_CMD_READ;
  8839. AscWriteEEPCmdReg(iop_base, cmd_reg);
  8840. AscWaitEEPRead();
  8841. read_wval = AscGetChipEEPData(iop_base);
  8842. AscWaitEEPRead();
  8843. return read_wval;
  8844. }
  8845. static ushort __devinit
  8846. AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  8847. {
  8848. ushort wval;
  8849. ushort sum;
  8850. ushort *wbuf;
  8851. int cfg_beg;
  8852. int cfg_end;
  8853. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8854. int s_addr;
  8855. wbuf = (ushort *)cfg_buf;
  8856. sum = 0;
  8857. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  8858. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8859. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8860. sum += *wbuf;
  8861. }
  8862. if (bus_type & ASC_IS_VL) {
  8863. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8864. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8865. } else {
  8866. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8867. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8868. }
  8869. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8870. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  8871. if (s_addr <= uchar_end_in_config) {
  8872. /*
  8873. * Swap all char fields - must unswap bytes already swapped
  8874. * by AscReadEEPWord().
  8875. */
  8876. *wbuf = le16_to_cpu(wval);
  8877. } else {
  8878. /* Don't swap word field at the end - cntl field. */
  8879. *wbuf = wval;
  8880. }
  8881. sum += wval; /* Checksum treats all EEPROM data as words. */
  8882. }
  8883. /*
  8884. * Read the checksum word which will be compared against 'sum'
  8885. * by the caller. Word field already swapped.
  8886. */
  8887. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8888. return sum;
  8889. }
  8890. static int __devinit AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  8891. {
  8892. PortAddr iop_base;
  8893. ushort q_addr;
  8894. ushort saved_word;
  8895. int sta;
  8896. iop_base = asc_dvc->iop_base;
  8897. sta = 0;
  8898. q_addr = ASC_QNO_TO_QADDR(241);
  8899. saved_word = AscReadLramWord(iop_base, q_addr);
  8900. AscSetChipLramAddr(iop_base, q_addr);
  8901. AscSetChipLramData(iop_base, 0x55AA);
  8902. mdelay(10);
  8903. AscSetChipLramAddr(iop_base, q_addr);
  8904. if (AscGetChipLramData(iop_base) == 0x55AA) {
  8905. sta = 1;
  8906. AscWriteLramWord(iop_base, q_addr, saved_word);
  8907. }
  8908. return (sta);
  8909. }
  8910. static void __devinit AscWaitEEPWrite(void)
  8911. {
  8912. mdelay(20);
  8913. }
  8914. static int __devinit AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  8915. {
  8916. ushort read_back;
  8917. int retry;
  8918. retry = 0;
  8919. while (TRUE) {
  8920. AscSetChipEEPData(iop_base, data_reg);
  8921. mdelay(1);
  8922. read_back = AscGetChipEEPData(iop_base);
  8923. if (read_back == data_reg) {
  8924. return (1);
  8925. }
  8926. if (retry++ > ASC_EEP_MAX_RETRY) {
  8927. return (0);
  8928. }
  8929. }
  8930. }
  8931. static ushort __devinit
  8932. AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  8933. {
  8934. ushort read_wval;
  8935. read_wval = AscReadEEPWord(iop_base, addr);
  8936. if (read_wval != word_val) {
  8937. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  8938. AscWaitEEPRead();
  8939. AscWriteEEPDataReg(iop_base, word_val);
  8940. AscWaitEEPRead();
  8941. AscWriteEEPCmdReg(iop_base,
  8942. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  8943. AscWaitEEPWrite();
  8944. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8945. AscWaitEEPRead();
  8946. return (AscReadEEPWord(iop_base, addr));
  8947. }
  8948. return (read_wval);
  8949. }
  8950. static int __devinit
  8951. AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  8952. {
  8953. int n_error;
  8954. ushort *wbuf;
  8955. ushort word;
  8956. ushort sum;
  8957. int s_addr;
  8958. int cfg_beg;
  8959. int cfg_end;
  8960. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8961. wbuf = (ushort *)cfg_buf;
  8962. n_error = 0;
  8963. sum = 0;
  8964. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  8965. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8966. sum += *wbuf;
  8967. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8968. n_error++;
  8969. }
  8970. }
  8971. if (bus_type & ASC_IS_VL) {
  8972. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8973. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8974. } else {
  8975. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8976. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8977. }
  8978. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8979. if (s_addr <= uchar_end_in_config) {
  8980. /*
  8981. * This is a char field. Swap char fields before they are
  8982. * swapped again by AscWriteEEPWord().
  8983. */
  8984. word = cpu_to_le16(*wbuf);
  8985. if (word !=
  8986. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  8987. n_error++;
  8988. }
  8989. } else {
  8990. /* Don't swap word field at the end - cntl field. */
  8991. if (*wbuf !=
  8992. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8993. n_error++;
  8994. }
  8995. }
  8996. sum += *wbuf; /* Checksum calculated from word values. */
  8997. }
  8998. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  8999. *wbuf = sum;
  9000. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  9001. n_error++;
  9002. }
  9003. /* Read EEPROM back again. */
  9004. wbuf = (ushort *)cfg_buf;
  9005. /*
  9006. * Read two config words; Byte-swapping done by AscReadEEPWord().
  9007. */
  9008. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  9009. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  9010. n_error++;
  9011. }
  9012. }
  9013. if (bus_type & ASC_IS_VL) {
  9014. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  9015. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  9016. } else {
  9017. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  9018. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  9019. }
  9020. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  9021. if (s_addr <= uchar_end_in_config) {
  9022. /*
  9023. * Swap all char fields. Must unswap bytes already swapped
  9024. * by AscReadEEPWord().
  9025. */
  9026. word =
  9027. le16_to_cpu(AscReadEEPWord
  9028. (iop_base, (uchar)s_addr));
  9029. } else {
  9030. /* Don't swap word field at the end - cntl field. */
  9031. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  9032. }
  9033. if (*wbuf != word) {
  9034. n_error++;
  9035. }
  9036. }
  9037. /* Read checksum; Byte swapping not needed. */
  9038. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  9039. n_error++;
  9040. }
  9041. return n_error;
  9042. }
  9043. static int __devinit
  9044. AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  9045. {
  9046. int retry;
  9047. int n_error;
  9048. retry = 0;
  9049. while (TRUE) {
  9050. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  9051. bus_type)) == 0) {
  9052. break;
  9053. }
  9054. if (++retry > ASC_EEP_MAX_RETRY) {
  9055. break;
  9056. }
  9057. }
  9058. return n_error;
  9059. }
  9060. static ushort __devinit AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  9061. {
  9062. ASCEEP_CONFIG eep_config_buf;
  9063. ASCEEP_CONFIG *eep_config;
  9064. PortAddr iop_base;
  9065. ushort chksum;
  9066. ushort warn_code;
  9067. ushort cfg_msw, cfg_lsw;
  9068. int i;
  9069. int write_eep = 0;
  9070. iop_base = asc_dvc->iop_base;
  9071. warn_code = 0;
  9072. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  9073. AscStopQueueExe(iop_base);
  9074. if ((AscStopChip(iop_base) == FALSE) ||
  9075. (AscGetChipScsiCtrl(iop_base) != 0)) {
  9076. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  9077. AscResetChipAndScsiBus(asc_dvc);
  9078. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  9079. }
  9080. if (AscIsChipHalted(iop_base) == FALSE) {
  9081. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  9082. return (warn_code);
  9083. }
  9084. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  9085. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  9086. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  9087. return (warn_code);
  9088. }
  9089. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  9090. cfg_msw = AscGetChipCfgMsw(iop_base);
  9091. cfg_lsw = AscGetChipCfgLsw(iop_base);
  9092. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  9093. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9094. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  9095. AscSetChipCfgMsw(iop_base, cfg_msw);
  9096. }
  9097. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  9098. ASC_DBG(1, "chksum 0x%x\n", chksum);
  9099. if (chksum == 0) {
  9100. chksum = 0xaa55;
  9101. }
  9102. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  9103. warn_code |= ASC_WARN_AUTO_CONFIG;
  9104. if (asc_dvc->cfg->chip_version == 3) {
  9105. if (eep_config->cfg_lsw != cfg_lsw) {
  9106. warn_code |= ASC_WARN_EEPROM_RECOVER;
  9107. eep_config->cfg_lsw =
  9108. AscGetChipCfgLsw(iop_base);
  9109. }
  9110. if (eep_config->cfg_msw != cfg_msw) {
  9111. warn_code |= ASC_WARN_EEPROM_RECOVER;
  9112. eep_config->cfg_msw =
  9113. AscGetChipCfgMsw(iop_base);
  9114. }
  9115. }
  9116. }
  9117. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9118. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  9119. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  9120. if (chksum != eep_config->chksum) {
  9121. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  9122. ASC_CHIP_VER_PCI_ULTRA_3050) {
  9123. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  9124. eep_config->init_sdtr = 0xFF;
  9125. eep_config->disc_enable = 0xFF;
  9126. eep_config->start_motor = 0xFF;
  9127. eep_config->use_cmd_qng = 0;
  9128. eep_config->max_total_qng = 0xF0;
  9129. eep_config->max_tag_qng = 0x20;
  9130. eep_config->cntl = 0xBFFF;
  9131. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  9132. eep_config->no_scam = 0;
  9133. eep_config->adapter_info[0] = 0;
  9134. eep_config->adapter_info[1] = 0;
  9135. eep_config->adapter_info[2] = 0;
  9136. eep_config->adapter_info[3] = 0;
  9137. eep_config->adapter_info[4] = 0;
  9138. /* Indicate EEPROM-less board. */
  9139. eep_config->adapter_info[5] = 0xBB;
  9140. } else {
  9141. ASC_PRINT
  9142. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  9143. write_eep = 1;
  9144. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9145. }
  9146. }
  9147. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  9148. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  9149. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  9150. asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
  9151. asc_dvc->start_motor = eep_config->start_motor;
  9152. asc_dvc->dvc_cntl = eep_config->cntl;
  9153. asc_dvc->no_scam = eep_config->no_scam;
  9154. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  9155. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  9156. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  9157. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  9158. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  9159. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  9160. if (!AscTestExternalLram(asc_dvc)) {
  9161. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  9162. ASC_IS_PCI_ULTRA)) {
  9163. eep_config->max_total_qng =
  9164. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  9165. eep_config->max_tag_qng =
  9166. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  9167. } else {
  9168. eep_config->cfg_msw |= 0x0800;
  9169. cfg_msw |= 0x0800;
  9170. AscSetChipCfgMsw(iop_base, cfg_msw);
  9171. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  9172. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  9173. }
  9174. } else {
  9175. }
  9176. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  9177. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  9178. }
  9179. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  9180. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  9181. }
  9182. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  9183. eep_config->max_tag_qng = eep_config->max_total_qng;
  9184. }
  9185. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  9186. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  9187. }
  9188. asc_dvc->max_total_qng = eep_config->max_total_qng;
  9189. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  9190. eep_config->use_cmd_qng) {
  9191. eep_config->disc_enable = eep_config->use_cmd_qng;
  9192. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  9193. }
  9194. ASC_EEP_SET_CHIP_ID(eep_config,
  9195. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  9196. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  9197. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  9198. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  9199. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  9200. }
  9201. for (i = 0; i <= ASC_MAX_TID; i++) {
  9202. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  9203. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  9204. asc_dvc->cfg->sdtr_period_offset[i] =
  9205. (uchar)(ASC_DEF_SDTR_OFFSET |
  9206. (asc_dvc->min_sdtr_index << 4));
  9207. }
  9208. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  9209. if (write_eep) {
  9210. if ((i = AscSetEEPConfig(iop_base, eep_config,
  9211. asc_dvc->bus_type)) != 0) {
  9212. ASC_PRINT1
  9213. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  9214. i);
  9215. } else {
  9216. ASC_PRINT
  9217. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  9218. }
  9219. }
  9220. return (warn_code);
  9221. }
  9222. static int __devinit AscInitGetConfig(struct Scsi_Host *shost)
  9223. {
  9224. struct asc_board *board = shost_priv(shost);
  9225. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  9226. unsigned short warn_code = 0;
  9227. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  9228. if (asc_dvc->err_code != 0)
  9229. return asc_dvc->err_code;
  9230. if (AscFindSignature(asc_dvc->iop_base)) {
  9231. warn_code |= AscInitAscDvcVar(asc_dvc);
  9232. warn_code |= AscInitFromEEP(asc_dvc);
  9233. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  9234. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  9235. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  9236. } else {
  9237. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9238. }
  9239. switch (warn_code) {
  9240. case 0: /* No error */
  9241. break;
  9242. case ASC_WARN_IO_PORT_ROTATE:
  9243. shost_printk(KERN_WARNING, shost, "I/O port address "
  9244. "modified\n");
  9245. break;
  9246. case ASC_WARN_AUTO_CONFIG:
  9247. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  9248. "enabled\n");
  9249. break;
  9250. case ASC_WARN_EEPROM_CHKSUM:
  9251. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  9252. break;
  9253. case ASC_WARN_IRQ_MODIFIED:
  9254. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  9255. break;
  9256. case ASC_WARN_CMD_QNG_CONFLICT:
  9257. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  9258. "disconnects\n");
  9259. break;
  9260. default:
  9261. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  9262. warn_code);
  9263. break;
  9264. }
  9265. if (asc_dvc->err_code != 0)
  9266. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  9267. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  9268. return asc_dvc->err_code;
  9269. }
  9270. static int __devinit AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  9271. {
  9272. struct asc_board *board = shost_priv(shost);
  9273. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  9274. PortAddr iop_base = asc_dvc->iop_base;
  9275. unsigned short cfg_msw;
  9276. unsigned short warn_code = 0;
  9277. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  9278. if (asc_dvc->err_code != 0)
  9279. return asc_dvc->err_code;
  9280. if (!AscFindSignature(asc_dvc->iop_base)) {
  9281. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9282. return asc_dvc->err_code;
  9283. }
  9284. cfg_msw = AscGetChipCfgMsw(iop_base);
  9285. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  9286. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9287. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  9288. AscSetChipCfgMsw(iop_base, cfg_msw);
  9289. }
  9290. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  9291. asc_dvc->cfg->cmd_qng_enabled) {
  9292. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  9293. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  9294. }
  9295. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  9296. warn_code |= ASC_WARN_AUTO_CONFIG;
  9297. }
  9298. #ifdef CONFIG_PCI
  9299. if (asc_dvc->bus_type & ASC_IS_PCI) {
  9300. cfg_msw &= 0xFFC0;
  9301. AscSetChipCfgMsw(iop_base, cfg_msw);
  9302. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  9303. } else {
  9304. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  9305. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  9306. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  9307. asc_dvc->bug_fix_cntl |=
  9308. ASC_BUG_FIX_ASYN_USE_SYN;
  9309. }
  9310. }
  9311. } else
  9312. #endif /* CONFIG_PCI */
  9313. if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
  9314. if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
  9315. == ASC_CHIP_VER_ASYN_BUG) {
  9316. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
  9317. }
  9318. }
  9319. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  9320. asc_dvc->cfg->chip_scsi_id) {
  9321. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  9322. }
  9323. #ifdef CONFIG_ISA
  9324. if (asc_dvc->bus_type & ASC_IS_ISA) {
  9325. AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
  9326. AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
  9327. }
  9328. #endif /* CONFIG_ISA */
  9329. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  9330. switch (warn_code) {
  9331. case 0: /* No error. */
  9332. break;
  9333. case ASC_WARN_IO_PORT_ROTATE:
  9334. shost_printk(KERN_WARNING, shost, "I/O port address "
  9335. "modified\n");
  9336. break;
  9337. case ASC_WARN_AUTO_CONFIG:
  9338. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  9339. "enabled\n");
  9340. break;
  9341. case ASC_WARN_EEPROM_CHKSUM:
  9342. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  9343. break;
  9344. case ASC_WARN_IRQ_MODIFIED:
  9345. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  9346. break;
  9347. case ASC_WARN_CMD_QNG_CONFLICT:
  9348. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  9349. "disconnects\n");
  9350. break;
  9351. default:
  9352. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  9353. warn_code);
  9354. break;
  9355. }
  9356. if (asc_dvc->err_code != 0)
  9357. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  9358. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  9359. return asc_dvc->err_code;
  9360. }
  9361. /*
  9362. * EEPROM Configuration.
  9363. *
  9364. * All drivers should use this structure to set the default EEPROM
  9365. * configuration. The BIOS now uses this structure when it is built.
  9366. * Additional structure information can be found in a_condor.h where
  9367. * the structure is defined.
  9368. *
  9369. * The *_Field_IsChar structs are needed to correct for endianness.
  9370. * These values are read from the board 16 bits at a time directly
  9371. * into the structs. Because some fields are char, the values will be
  9372. * in the wrong order. The *_Field_IsChar tells when to flip the
  9373. * bytes. Data read and written to PCI memory is automatically swapped
  9374. * on big-endian platforms so char fields read as words are actually being
  9375. * unswapped on big-endian platforms.
  9376. */
  9377. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config __devinitdata = {
  9378. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  9379. 0x0000, /* cfg_msw */
  9380. 0xFFFF, /* disc_enable */
  9381. 0xFFFF, /* wdtr_able */
  9382. 0xFFFF, /* sdtr_able */
  9383. 0xFFFF, /* start_motor */
  9384. 0xFFFF, /* tagqng_able */
  9385. 0xFFFF, /* bios_scan */
  9386. 0, /* scam_tolerant */
  9387. 7, /* adapter_scsi_id */
  9388. 0, /* bios_boot_delay */
  9389. 3, /* scsi_reset_delay */
  9390. 0, /* bios_id_lun */
  9391. 0, /* termination */
  9392. 0, /* reserved1 */
  9393. 0xFFE7, /* bios_ctrl */
  9394. 0xFFFF, /* ultra_able */
  9395. 0, /* reserved2 */
  9396. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  9397. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9398. 0, /* dvc_cntl */
  9399. 0, /* bug_fix */
  9400. 0, /* serial_number_word1 */
  9401. 0, /* serial_number_word2 */
  9402. 0, /* serial_number_word3 */
  9403. 0, /* check_sum */
  9404. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9405. , /* oem_name[16] */
  9406. 0, /* dvc_err_code */
  9407. 0, /* adv_err_code */
  9408. 0, /* adv_err_addr */
  9409. 0, /* saved_dvc_err_code */
  9410. 0, /* saved_adv_err_code */
  9411. 0, /* saved_adv_err_addr */
  9412. 0 /* num_of_err */
  9413. };
  9414. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar __devinitdata = {
  9415. 0, /* cfg_lsw */
  9416. 0, /* cfg_msw */
  9417. 0, /* -disc_enable */
  9418. 0, /* wdtr_able */
  9419. 0, /* sdtr_able */
  9420. 0, /* start_motor */
  9421. 0, /* tagqng_able */
  9422. 0, /* bios_scan */
  9423. 0, /* scam_tolerant */
  9424. 1, /* adapter_scsi_id */
  9425. 1, /* bios_boot_delay */
  9426. 1, /* scsi_reset_delay */
  9427. 1, /* bios_id_lun */
  9428. 1, /* termination */
  9429. 1, /* reserved1 */
  9430. 0, /* bios_ctrl */
  9431. 0, /* ultra_able */
  9432. 0, /* reserved2 */
  9433. 1, /* max_host_qng */
  9434. 1, /* max_dvc_qng */
  9435. 0, /* dvc_cntl */
  9436. 0, /* bug_fix */
  9437. 0, /* serial_number_word1 */
  9438. 0, /* serial_number_word2 */
  9439. 0, /* serial_number_word3 */
  9440. 0, /* check_sum */
  9441. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9442. , /* oem_name[16] */
  9443. 0, /* dvc_err_code */
  9444. 0, /* adv_err_code */
  9445. 0, /* adv_err_addr */
  9446. 0, /* saved_dvc_err_code */
  9447. 0, /* saved_adv_err_code */
  9448. 0, /* saved_adv_err_addr */
  9449. 0 /* num_of_err */
  9450. };
  9451. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config __devinitdata = {
  9452. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9453. 0x0000, /* 01 cfg_msw */
  9454. 0xFFFF, /* 02 disc_enable */
  9455. 0xFFFF, /* 03 wdtr_able */
  9456. 0x4444, /* 04 sdtr_speed1 */
  9457. 0xFFFF, /* 05 start_motor */
  9458. 0xFFFF, /* 06 tagqng_able */
  9459. 0xFFFF, /* 07 bios_scan */
  9460. 0, /* 08 scam_tolerant */
  9461. 7, /* 09 adapter_scsi_id */
  9462. 0, /* bios_boot_delay */
  9463. 3, /* 10 scsi_reset_delay */
  9464. 0, /* bios_id_lun */
  9465. 0, /* 11 termination_se */
  9466. 0, /* termination_lvd */
  9467. 0xFFE7, /* 12 bios_ctrl */
  9468. 0x4444, /* 13 sdtr_speed2 */
  9469. 0x4444, /* 14 sdtr_speed3 */
  9470. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9471. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9472. 0, /* 16 dvc_cntl */
  9473. 0x4444, /* 17 sdtr_speed4 */
  9474. 0, /* 18 serial_number_word1 */
  9475. 0, /* 19 serial_number_word2 */
  9476. 0, /* 20 serial_number_word3 */
  9477. 0, /* 21 check_sum */
  9478. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9479. , /* 22-29 oem_name[16] */
  9480. 0, /* 30 dvc_err_code */
  9481. 0, /* 31 adv_err_code */
  9482. 0, /* 32 adv_err_addr */
  9483. 0, /* 33 saved_dvc_err_code */
  9484. 0, /* 34 saved_adv_err_code */
  9485. 0, /* 35 saved_adv_err_addr */
  9486. 0, /* 36 reserved */
  9487. 0, /* 37 reserved */
  9488. 0, /* 38 reserved */
  9489. 0, /* 39 reserved */
  9490. 0, /* 40 reserved */
  9491. 0, /* 41 reserved */
  9492. 0, /* 42 reserved */
  9493. 0, /* 43 reserved */
  9494. 0, /* 44 reserved */
  9495. 0, /* 45 reserved */
  9496. 0, /* 46 reserved */
  9497. 0, /* 47 reserved */
  9498. 0, /* 48 reserved */
  9499. 0, /* 49 reserved */
  9500. 0, /* 50 reserved */
  9501. 0, /* 51 reserved */
  9502. 0, /* 52 reserved */
  9503. 0, /* 53 reserved */
  9504. 0, /* 54 reserved */
  9505. 0, /* 55 reserved */
  9506. 0, /* 56 cisptr_lsw */
  9507. 0, /* 57 cisprt_msw */
  9508. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9509. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  9510. 0, /* 60 reserved */
  9511. 0, /* 61 reserved */
  9512. 0, /* 62 reserved */
  9513. 0 /* 63 reserved */
  9514. };
  9515. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar __devinitdata = {
  9516. 0, /* 00 cfg_lsw */
  9517. 0, /* 01 cfg_msw */
  9518. 0, /* 02 disc_enable */
  9519. 0, /* 03 wdtr_able */
  9520. 0, /* 04 sdtr_speed1 */
  9521. 0, /* 05 start_motor */
  9522. 0, /* 06 tagqng_able */
  9523. 0, /* 07 bios_scan */
  9524. 0, /* 08 scam_tolerant */
  9525. 1, /* 09 adapter_scsi_id */
  9526. 1, /* bios_boot_delay */
  9527. 1, /* 10 scsi_reset_delay */
  9528. 1, /* bios_id_lun */
  9529. 1, /* 11 termination_se */
  9530. 1, /* termination_lvd */
  9531. 0, /* 12 bios_ctrl */
  9532. 0, /* 13 sdtr_speed2 */
  9533. 0, /* 14 sdtr_speed3 */
  9534. 1, /* 15 max_host_qng */
  9535. 1, /* max_dvc_qng */
  9536. 0, /* 16 dvc_cntl */
  9537. 0, /* 17 sdtr_speed4 */
  9538. 0, /* 18 serial_number_word1 */
  9539. 0, /* 19 serial_number_word2 */
  9540. 0, /* 20 serial_number_word3 */
  9541. 0, /* 21 check_sum */
  9542. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9543. , /* 22-29 oem_name[16] */
  9544. 0, /* 30 dvc_err_code */
  9545. 0, /* 31 adv_err_code */
  9546. 0, /* 32 adv_err_addr */
  9547. 0, /* 33 saved_dvc_err_code */
  9548. 0, /* 34 saved_adv_err_code */
  9549. 0, /* 35 saved_adv_err_addr */
  9550. 0, /* 36 reserved */
  9551. 0, /* 37 reserved */
  9552. 0, /* 38 reserved */
  9553. 0, /* 39 reserved */
  9554. 0, /* 40 reserved */
  9555. 0, /* 41 reserved */
  9556. 0, /* 42 reserved */
  9557. 0, /* 43 reserved */
  9558. 0, /* 44 reserved */
  9559. 0, /* 45 reserved */
  9560. 0, /* 46 reserved */
  9561. 0, /* 47 reserved */
  9562. 0, /* 48 reserved */
  9563. 0, /* 49 reserved */
  9564. 0, /* 50 reserved */
  9565. 0, /* 51 reserved */
  9566. 0, /* 52 reserved */
  9567. 0, /* 53 reserved */
  9568. 0, /* 54 reserved */
  9569. 0, /* 55 reserved */
  9570. 0, /* 56 cisptr_lsw */
  9571. 0, /* 57 cisprt_msw */
  9572. 0, /* 58 subsysvid */
  9573. 0, /* 59 subsysid */
  9574. 0, /* 60 reserved */
  9575. 0, /* 61 reserved */
  9576. 0, /* 62 reserved */
  9577. 0 /* 63 reserved */
  9578. };
  9579. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config __devinitdata = {
  9580. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9581. 0x0000, /* 01 cfg_msw */
  9582. 0xFFFF, /* 02 disc_enable */
  9583. 0xFFFF, /* 03 wdtr_able */
  9584. 0x5555, /* 04 sdtr_speed1 */
  9585. 0xFFFF, /* 05 start_motor */
  9586. 0xFFFF, /* 06 tagqng_able */
  9587. 0xFFFF, /* 07 bios_scan */
  9588. 0, /* 08 scam_tolerant */
  9589. 7, /* 09 adapter_scsi_id */
  9590. 0, /* bios_boot_delay */
  9591. 3, /* 10 scsi_reset_delay */
  9592. 0, /* bios_id_lun */
  9593. 0, /* 11 termination_se */
  9594. 0, /* termination_lvd */
  9595. 0xFFE7, /* 12 bios_ctrl */
  9596. 0x5555, /* 13 sdtr_speed2 */
  9597. 0x5555, /* 14 sdtr_speed3 */
  9598. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9599. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9600. 0, /* 16 dvc_cntl */
  9601. 0x5555, /* 17 sdtr_speed4 */
  9602. 0, /* 18 serial_number_word1 */
  9603. 0, /* 19 serial_number_word2 */
  9604. 0, /* 20 serial_number_word3 */
  9605. 0, /* 21 check_sum */
  9606. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9607. , /* 22-29 oem_name[16] */
  9608. 0, /* 30 dvc_err_code */
  9609. 0, /* 31 adv_err_code */
  9610. 0, /* 32 adv_err_addr */
  9611. 0, /* 33 saved_dvc_err_code */
  9612. 0, /* 34 saved_adv_err_code */
  9613. 0, /* 35 saved_adv_err_addr */
  9614. 0, /* 36 reserved */
  9615. 0, /* 37 reserved */
  9616. 0, /* 38 reserved */
  9617. 0, /* 39 reserved */
  9618. 0, /* 40 reserved */
  9619. 0, /* 41 reserved */
  9620. 0, /* 42 reserved */
  9621. 0, /* 43 reserved */
  9622. 0, /* 44 reserved */
  9623. 0, /* 45 reserved */
  9624. 0, /* 46 reserved */
  9625. 0, /* 47 reserved */
  9626. 0, /* 48 reserved */
  9627. 0, /* 49 reserved */
  9628. 0, /* 50 reserved */
  9629. 0, /* 51 reserved */
  9630. 0, /* 52 reserved */
  9631. 0, /* 53 reserved */
  9632. 0, /* 54 reserved */
  9633. 0, /* 55 reserved */
  9634. 0, /* 56 cisptr_lsw */
  9635. 0, /* 57 cisprt_msw */
  9636. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9637. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  9638. 0, /* 60 reserved */
  9639. 0, /* 61 reserved */
  9640. 0, /* 62 reserved */
  9641. 0 /* 63 reserved */
  9642. };
  9643. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar __devinitdata = {
  9644. 0, /* 00 cfg_lsw */
  9645. 0, /* 01 cfg_msw */
  9646. 0, /* 02 disc_enable */
  9647. 0, /* 03 wdtr_able */
  9648. 0, /* 04 sdtr_speed1 */
  9649. 0, /* 05 start_motor */
  9650. 0, /* 06 tagqng_able */
  9651. 0, /* 07 bios_scan */
  9652. 0, /* 08 scam_tolerant */
  9653. 1, /* 09 adapter_scsi_id */
  9654. 1, /* bios_boot_delay */
  9655. 1, /* 10 scsi_reset_delay */
  9656. 1, /* bios_id_lun */
  9657. 1, /* 11 termination_se */
  9658. 1, /* termination_lvd */
  9659. 0, /* 12 bios_ctrl */
  9660. 0, /* 13 sdtr_speed2 */
  9661. 0, /* 14 sdtr_speed3 */
  9662. 1, /* 15 max_host_qng */
  9663. 1, /* max_dvc_qng */
  9664. 0, /* 16 dvc_cntl */
  9665. 0, /* 17 sdtr_speed4 */
  9666. 0, /* 18 serial_number_word1 */
  9667. 0, /* 19 serial_number_word2 */
  9668. 0, /* 20 serial_number_word3 */
  9669. 0, /* 21 check_sum */
  9670. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9671. , /* 22-29 oem_name[16] */
  9672. 0, /* 30 dvc_err_code */
  9673. 0, /* 31 adv_err_code */
  9674. 0, /* 32 adv_err_addr */
  9675. 0, /* 33 saved_dvc_err_code */
  9676. 0, /* 34 saved_adv_err_code */
  9677. 0, /* 35 saved_adv_err_addr */
  9678. 0, /* 36 reserved */
  9679. 0, /* 37 reserved */
  9680. 0, /* 38 reserved */
  9681. 0, /* 39 reserved */
  9682. 0, /* 40 reserved */
  9683. 0, /* 41 reserved */
  9684. 0, /* 42 reserved */
  9685. 0, /* 43 reserved */
  9686. 0, /* 44 reserved */
  9687. 0, /* 45 reserved */
  9688. 0, /* 46 reserved */
  9689. 0, /* 47 reserved */
  9690. 0, /* 48 reserved */
  9691. 0, /* 49 reserved */
  9692. 0, /* 50 reserved */
  9693. 0, /* 51 reserved */
  9694. 0, /* 52 reserved */
  9695. 0, /* 53 reserved */
  9696. 0, /* 54 reserved */
  9697. 0, /* 55 reserved */
  9698. 0, /* 56 cisptr_lsw */
  9699. 0, /* 57 cisprt_msw */
  9700. 0, /* 58 subsysvid */
  9701. 0, /* 59 subsysid */
  9702. 0, /* 60 reserved */
  9703. 0, /* 61 reserved */
  9704. 0, /* 62 reserved */
  9705. 0 /* 63 reserved */
  9706. };
  9707. #ifdef CONFIG_PCI
  9708. /*
  9709. * Wait for EEPROM command to complete
  9710. */
  9711. static void __devinit AdvWaitEEPCmd(AdvPortAddr iop_base)
  9712. {
  9713. int eep_delay_ms;
  9714. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  9715. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  9716. ASC_EEP_CMD_DONE) {
  9717. break;
  9718. }
  9719. mdelay(1);
  9720. }
  9721. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  9722. 0)
  9723. BUG();
  9724. }
  9725. /*
  9726. * Read the EEPROM from specified location
  9727. */
  9728. static ushort __devinit AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  9729. {
  9730. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9731. ASC_EEP_CMD_READ | eep_word_addr);
  9732. AdvWaitEEPCmd(iop_base);
  9733. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  9734. }
  9735. /*
  9736. * Write the EEPROM from 'cfg_buf'.
  9737. */
  9738. static void __devinit
  9739. AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
  9740. {
  9741. ushort *wbuf;
  9742. ushort addr, chksum;
  9743. ushort *charfields;
  9744. wbuf = (ushort *)cfg_buf;
  9745. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9746. chksum = 0;
  9747. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9748. AdvWaitEEPCmd(iop_base);
  9749. /*
  9750. * Write EEPROM from word 0 to word 20.
  9751. */
  9752. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9753. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9754. ushort word;
  9755. if (*charfields++) {
  9756. word = cpu_to_le16(*wbuf);
  9757. } else {
  9758. word = *wbuf;
  9759. }
  9760. chksum += *wbuf; /* Checksum is calculated from word values. */
  9761. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9762. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9763. ASC_EEP_CMD_WRITE | addr);
  9764. AdvWaitEEPCmd(iop_base);
  9765. mdelay(ADV_EEP_DELAY_MS);
  9766. }
  9767. /*
  9768. * Write EEPROM checksum at word 21.
  9769. */
  9770. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9771. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9772. AdvWaitEEPCmd(iop_base);
  9773. wbuf++;
  9774. charfields++;
  9775. /*
  9776. * Write EEPROM OEM name at words 22 to 29.
  9777. */
  9778. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9779. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9780. ushort word;
  9781. if (*charfields++) {
  9782. word = cpu_to_le16(*wbuf);
  9783. } else {
  9784. word = *wbuf;
  9785. }
  9786. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9787. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9788. ASC_EEP_CMD_WRITE | addr);
  9789. AdvWaitEEPCmd(iop_base);
  9790. }
  9791. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9792. AdvWaitEEPCmd(iop_base);
  9793. }
  9794. /*
  9795. * Write the EEPROM from 'cfg_buf'.
  9796. */
  9797. static void __devinit
  9798. AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
  9799. {
  9800. ushort *wbuf;
  9801. ushort *charfields;
  9802. ushort addr, chksum;
  9803. wbuf = (ushort *)cfg_buf;
  9804. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9805. chksum = 0;
  9806. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9807. AdvWaitEEPCmd(iop_base);
  9808. /*
  9809. * Write EEPROM from word 0 to word 20.
  9810. */
  9811. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9812. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9813. ushort word;
  9814. if (*charfields++) {
  9815. word = cpu_to_le16(*wbuf);
  9816. } else {
  9817. word = *wbuf;
  9818. }
  9819. chksum += *wbuf; /* Checksum is calculated from word values. */
  9820. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9821. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9822. ASC_EEP_CMD_WRITE | addr);
  9823. AdvWaitEEPCmd(iop_base);
  9824. mdelay(ADV_EEP_DELAY_MS);
  9825. }
  9826. /*
  9827. * Write EEPROM checksum at word 21.
  9828. */
  9829. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9830. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9831. AdvWaitEEPCmd(iop_base);
  9832. wbuf++;
  9833. charfields++;
  9834. /*
  9835. * Write EEPROM OEM name at words 22 to 29.
  9836. */
  9837. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9838. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9839. ushort word;
  9840. if (*charfields++) {
  9841. word = cpu_to_le16(*wbuf);
  9842. } else {
  9843. word = *wbuf;
  9844. }
  9845. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9846. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9847. ASC_EEP_CMD_WRITE | addr);
  9848. AdvWaitEEPCmd(iop_base);
  9849. }
  9850. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9851. AdvWaitEEPCmd(iop_base);
  9852. }
  9853. /*
  9854. * Write the EEPROM from 'cfg_buf'.
  9855. */
  9856. static void __devinit
  9857. AdvSet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
  9858. {
  9859. ushort *wbuf;
  9860. ushort *charfields;
  9861. ushort addr, chksum;
  9862. wbuf = (ushort *)cfg_buf;
  9863. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9864. chksum = 0;
  9865. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9866. AdvWaitEEPCmd(iop_base);
  9867. /*
  9868. * Write EEPROM from word 0 to word 20.
  9869. */
  9870. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9871. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9872. ushort word;
  9873. if (*charfields++) {
  9874. word = cpu_to_le16(*wbuf);
  9875. } else {
  9876. word = *wbuf;
  9877. }
  9878. chksum += *wbuf; /* Checksum is calculated from word values. */
  9879. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9880. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9881. ASC_EEP_CMD_WRITE | addr);
  9882. AdvWaitEEPCmd(iop_base);
  9883. mdelay(ADV_EEP_DELAY_MS);
  9884. }
  9885. /*
  9886. * Write EEPROM checksum at word 21.
  9887. */
  9888. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9889. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9890. AdvWaitEEPCmd(iop_base);
  9891. wbuf++;
  9892. charfields++;
  9893. /*
  9894. * Write EEPROM OEM name at words 22 to 29.
  9895. */
  9896. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9897. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9898. ushort word;
  9899. if (*charfields++) {
  9900. word = cpu_to_le16(*wbuf);
  9901. } else {
  9902. word = *wbuf;
  9903. }
  9904. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9905. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9906. ASC_EEP_CMD_WRITE | addr);
  9907. AdvWaitEEPCmd(iop_base);
  9908. }
  9909. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9910. AdvWaitEEPCmd(iop_base);
  9911. }
  9912. /*
  9913. * Read EEPROM configuration into the specified buffer.
  9914. *
  9915. * Return a checksum based on the EEPROM configuration read.
  9916. */
  9917. static ushort __devinit
  9918. AdvGet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
  9919. {
  9920. ushort wval, chksum;
  9921. ushort *wbuf;
  9922. int eep_addr;
  9923. ushort *charfields;
  9924. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9925. wbuf = (ushort *)cfg_buf;
  9926. chksum = 0;
  9927. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9928. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9929. wval = AdvReadEEPWord(iop_base, eep_addr);
  9930. chksum += wval; /* Checksum is calculated from word values. */
  9931. if (*charfields++) {
  9932. *wbuf = le16_to_cpu(wval);
  9933. } else {
  9934. *wbuf = wval;
  9935. }
  9936. }
  9937. /* Read checksum word. */
  9938. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9939. wbuf++;
  9940. charfields++;
  9941. /* Read rest of EEPROM not covered by the checksum. */
  9942. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9943. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9944. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9945. if (*charfields++) {
  9946. *wbuf = le16_to_cpu(*wbuf);
  9947. }
  9948. }
  9949. return chksum;
  9950. }
  9951. /*
  9952. * Read EEPROM configuration into the specified buffer.
  9953. *
  9954. * Return a checksum based on the EEPROM configuration read.
  9955. */
  9956. static ushort __devinit
  9957. AdvGet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
  9958. {
  9959. ushort wval, chksum;
  9960. ushort *wbuf;
  9961. int eep_addr;
  9962. ushort *charfields;
  9963. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9964. wbuf = (ushort *)cfg_buf;
  9965. chksum = 0;
  9966. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9967. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9968. wval = AdvReadEEPWord(iop_base, eep_addr);
  9969. chksum += wval; /* Checksum is calculated from word values. */
  9970. if (*charfields++) {
  9971. *wbuf = le16_to_cpu(wval);
  9972. } else {
  9973. *wbuf = wval;
  9974. }
  9975. }
  9976. /* Read checksum word. */
  9977. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9978. wbuf++;
  9979. charfields++;
  9980. /* Read rest of EEPROM not covered by the checksum. */
  9981. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9982. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9983. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9984. if (*charfields++) {
  9985. *wbuf = le16_to_cpu(*wbuf);
  9986. }
  9987. }
  9988. return chksum;
  9989. }
  9990. /*
  9991. * Read EEPROM configuration into the specified buffer.
  9992. *
  9993. * Return a checksum based on the EEPROM configuration read.
  9994. */
  9995. static ushort __devinit
  9996. AdvGet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
  9997. {
  9998. ushort wval, chksum;
  9999. ushort *wbuf;
  10000. int eep_addr;
  10001. ushort *charfields;
  10002. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  10003. wbuf = (ushort *)cfg_buf;
  10004. chksum = 0;
  10005. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  10006. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  10007. wval = AdvReadEEPWord(iop_base, eep_addr);
  10008. chksum += wval; /* Checksum is calculated from word values. */
  10009. if (*charfields++) {
  10010. *wbuf = le16_to_cpu(wval);
  10011. } else {
  10012. *wbuf = wval;
  10013. }
  10014. }
  10015. /* Read checksum word. */
  10016. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10017. wbuf++;
  10018. charfields++;
  10019. /* Read rest of EEPROM not covered by the checksum. */
  10020. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  10021. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  10022. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10023. if (*charfields++) {
  10024. *wbuf = le16_to_cpu(*wbuf);
  10025. }
  10026. }
  10027. return chksum;
  10028. }
  10029. /*
  10030. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  10031. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10032. * all of this is done.
  10033. *
  10034. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10035. *
  10036. * For a non-fatal error return a warning code. If there are no warnings
  10037. * then 0 is returned.
  10038. *
  10039. * Note: Chip is stopped on entry.
  10040. */
  10041. static int __devinit AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  10042. {
  10043. AdvPortAddr iop_base;
  10044. ushort warn_code;
  10045. ADVEEP_3550_CONFIG eep_config;
  10046. iop_base = asc_dvc->iop_base;
  10047. warn_code = 0;
  10048. /*
  10049. * Read the board's EEPROM configuration.
  10050. *
  10051. * Set default values if a bad checksum is found.
  10052. */
  10053. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  10054. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10055. /*
  10056. * Set EEPROM default values.
  10057. */
  10058. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  10059. sizeof(ADVEEP_3550_CONFIG));
  10060. /*
  10061. * Assume the 6 byte board serial number that was read from
  10062. * EEPROM is correct even if the EEPROM checksum failed.
  10063. */
  10064. eep_config.serial_number_word3 =
  10065. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10066. eep_config.serial_number_word2 =
  10067. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10068. eep_config.serial_number_word1 =
  10069. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10070. AdvSet3550EEPConfig(iop_base, &eep_config);
  10071. }
  10072. /*
  10073. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  10074. * EEPROM configuration that was read.
  10075. *
  10076. * This is the mapping of EEPROM fields to Adv Library fields.
  10077. */
  10078. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10079. asc_dvc->sdtr_able = eep_config.sdtr_able;
  10080. asc_dvc->ultra_able = eep_config.ultra_able;
  10081. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10082. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10083. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10084. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10085. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  10086. asc_dvc->start_motor = eep_config.start_motor;
  10087. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10088. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10089. asc_dvc->no_scam = eep_config.scam_tolerant;
  10090. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  10091. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  10092. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  10093. /*
  10094. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10095. * maximum queuing (max. 63, min. 4).
  10096. */
  10097. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10098. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10099. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10100. /* If the value is zero, assume it is uninitialized. */
  10101. if (eep_config.max_host_qng == 0) {
  10102. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10103. } else {
  10104. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10105. }
  10106. }
  10107. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10108. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10109. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10110. /* If the value is zero, assume it is uninitialized. */
  10111. if (eep_config.max_dvc_qng == 0) {
  10112. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10113. } else {
  10114. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10115. }
  10116. }
  10117. /*
  10118. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10119. * set 'max_dvc_qng' to 'max_host_qng'.
  10120. */
  10121. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10122. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10123. }
  10124. /*
  10125. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  10126. * values based on possibly adjusted EEPROM values.
  10127. */
  10128. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10129. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10130. /*
  10131. * If the EEPROM 'termination' field is set to automatic (0), then set
  10132. * the ADV_DVC_CFG 'termination' field to automatic also.
  10133. *
  10134. * If the termination is specified with a non-zero 'termination'
  10135. * value check that a legal value is set and set the ADV_DVC_CFG
  10136. * 'termination' field appropriately.
  10137. */
  10138. if (eep_config.termination == 0) {
  10139. asc_dvc->cfg->termination = 0; /* auto termination */
  10140. } else {
  10141. /* Enable manual control with low off / high off. */
  10142. if (eep_config.termination == 1) {
  10143. asc_dvc->cfg->termination = TERM_CTL_SEL;
  10144. /* Enable manual control with low off / high on. */
  10145. } else if (eep_config.termination == 2) {
  10146. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  10147. /* Enable manual control with low on / high on. */
  10148. } else if (eep_config.termination == 3) {
  10149. asc_dvc->cfg->termination =
  10150. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  10151. } else {
  10152. /*
  10153. * The EEPROM 'termination' field contains a bad value. Use
  10154. * automatic termination instead.
  10155. */
  10156. asc_dvc->cfg->termination = 0;
  10157. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10158. }
  10159. }
  10160. return warn_code;
  10161. }
  10162. /*
  10163. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  10164. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10165. * all of this is done.
  10166. *
  10167. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10168. *
  10169. * For a non-fatal error return a warning code. If there are no warnings
  10170. * then 0 is returned.
  10171. *
  10172. * Note: Chip is stopped on entry.
  10173. */
  10174. static int __devinit AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  10175. {
  10176. AdvPortAddr iop_base;
  10177. ushort warn_code;
  10178. ADVEEP_38C0800_CONFIG eep_config;
  10179. uchar tid, termination;
  10180. ushort sdtr_speed = 0;
  10181. iop_base = asc_dvc->iop_base;
  10182. warn_code = 0;
  10183. /*
  10184. * Read the board's EEPROM configuration.
  10185. *
  10186. * Set default values if a bad checksum is found.
  10187. */
  10188. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  10189. eep_config.check_sum) {
  10190. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10191. /*
  10192. * Set EEPROM default values.
  10193. */
  10194. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  10195. sizeof(ADVEEP_38C0800_CONFIG));
  10196. /*
  10197. * Assume the 6 byte board serial number that was read from
  10198. * EEPROM is correct even if the EEPROM checksum failed.
  10199. */
  10200. eep_config.serial_number_word3 =
  10201. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10202. eep_config.serial_number_word2 =
  10203. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10204. eep_config.serial_number_word1 =
  10205. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10206. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  10207. }
  10208. /*
  10209. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  10210. * EEPROM configuration that was read.
  10211. *
  10212. * This is the mapping of EEPROM fields to Adv Library fields.
  10213. */
  10214. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10215. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  10216. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  10217. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  10218. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  10219. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10220. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10221. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10222. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10223. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  10224. asc_dvc->start_motor = eep_config.start_motor;
  10225. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10226. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10227. asc_dvc->no_scam = eep_config.scam_tolerant;
  10228. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  10229. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  10230. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  10231. /*
  10232. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  10233. * are set, then set an 'sdtr_able' bit for it.
  10234. */
  10235. asc_dvc->sdtr_able = 0;
  10236. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  10237. if (tid == 0) {
  10238. sdtr_speed = asc_dvc->sdtr_speed1;
  10239. } else if (tid == 4) {
  10240. sdtr_speed = asc_dvc->sdtr_speed2;
  10241. } else if (tid == 8) {
  10242. sdtr_speed = asc_dvc->sdtr_speed3;
  10243. } else if (tid == 12) {
  10244. sdtr_speed = asc_dvc->sdtr_speed4;
  10245. }
  10246. if (sdtr_speed & ADV_MAX_TID) {
  10247. asc_dvc->sdtr_able |= (1 << tid);
  10248. }
  10249. sdtr_speed >>= 4;
  10250. }
  10251. /*
  10252. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10253. * maximum queuing (max. 63, min. 4).
  10254. */
  10255. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10256. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10257. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10258. /* If the value is zero, assume it is uninitialized. */
  10259. if (eep_config.max_host_qng == 0) {
  10260. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10261. } else {
  10262. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10263. }
  10264. }
  10265. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10266. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10267. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10268. /* If the value is zero, assume it is uninitialized. */
  10269. if (eep_config.max_dvc_qng == 0) {
  10270. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10271. } else {
  10272. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10273. }
  10274. }
  10275. /*
  10276. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10277. * set 'max_dvc_qng' to 'max_host_qng'.
  10278. */
  10279. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10280. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10281. }
  10282. /*
  10283. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  10284. * values based on possibly adjusted EEPROM values.
  10285. */
  10286. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10287. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10288. /*
  10289. * If the EEPROM 'termination' field is set to automatic (0), then set
  10290. * the ADV_DVC_CFG 'termination' field to automatic also.
  10291. *
  10292. * If the termination is specified with a non-zero 'termination'
  10293. * value check that a legal value is set and set the ADV_DVC_CFG
  10294. * 'termination' field appropriately.
  10295. */
  10296. if (eep_config.termination_se == 0) {
  10297. termination = 0; /* auto termination for SE */
  10298. } else {
  10299. /* Enable manual control with low off / high off. */
  10300. if (eep_config.termination_se == 1) {
  10301. termination = 0;
  10302. /* Enable manual control with low off / high on. */
  10303. } else if (eep_config.termination_se == 2) {
  10304. termination = TERM_SE_HI;
  10305. /* Enable manual control with low on / high on. */
  10306. } else if (eep_config.termination_se == 3) {
  10307. termination = TERM_SE;
  10308. } else {
  10309. /*
  10310. * The EEPROM 'termination_se' field contains a bad value.
  10311. * Use automatic termination instead.
  10312. */
  10313. termination = 0;
  10314. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10315. }
  10316. }
  10317. if (eep_config.termination_lvd == 0) {
  10318. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10319. } else {
  10320. /* Enable manual control with low off / high off. */
  10321. if (eep_config.termination_lvd == 1) {
  10322. asc_dvc->cfg->termination = termination;
  10323. /* Enable manual control with low off / high on. */
  10324. } else if (eep_config.termination_lvd == 2) {
  10325. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10326. /* Enable manual control with low on / high on. */
  10327. } else if (eep_config.termination_lvd == 3) {
  10328. asc_dvc->cfg->termination = termination | TERM_LVD;
  10329. } else {
  10330. /*
  10331. * The EEPROM 'termination_lvd' field contains a bad value.
  10332. * Use automatic termination instead.
  10333. */
  10334. asc_dvc->cfg->termination = termination;
  10335. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10336. }
  10337. }
  10338. return warn_code;
  10339. }
  10340. /*
  10341. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  10342. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10343. * all of this is done.
  10344. *
  10345. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  10346. *
  10347. * For a non-fatal error return a warning code. If there are no warnings
  10348. * then 0 is returned.
  10349. *
  10350. * Note: Chip is stopped on entry.
  10351. */
  10352. static int __devinit AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  10353. {
  10354. AdvPortAddr iop_base;
  10355. ushort warn_code;
  10356. ADVEEP_38C1600_CONFIG eep_config;
  10357. uchar tid, termination;
  10358. ushort sdtr_speed = 0;
  10359. iop_base = asc_dvc->iop_base;
  10360. warn_code = 0;
  10361. /*
  10362. * Read the board's EEPROM configuration.
  10363. *
  10364. * Set default values if a bad checksum is found.
  10365. */
  10366. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  10367. eep_config.check_sum) {
  10368. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  10369. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10370. /*
  10371. * Set EEPROM default values.
  10372. */
  10373. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  10374. sizeof(ADVEEP_38C1600_CONFIG));
  10375. if (PCI_FUNC(pdev->devfn) != 0) {
  10376. u8 ints;
  10377. /*
  10378. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  10379. * and old Mac system booting problem. The Expansion
  10380. * ROM must be disabled in Function 1 for these systems
  10381. */
  10382. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  10383. /*
  10384. * Clear the INTAB (bit 11) if the GPIO 0 input
  10385. * indicates the Function 1 interrupt line is wired
  10386. * to INTB.
  10387. *
  10388. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  10389. * 1 - Function 1 interrupt line wired to INT A.
  10390. * 0 - Function 1 interrupt line wired to INT B.
  10391. *
  10392. * Note: Function 0 is always wired to INTA.
  10393. * Put all 5 GPIO bits in input mode and then read
  10394. * their input values.
  10395. */
  10396. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  10397. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  10398. if ((ints & 0x01) == 0)
  10399. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  10400. }
  10401. /*
  10402. * Assume the 6 byte board serial number that was read from
  10403. * EEPROM is correct even if the EEPROM checksum failed.
  10404. */
  10405. eep_config.serial_number_word3 =
  10406. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10407. eep_config.serial_number_word2 =
  10408. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10409. eep_config.serial_number_word1 =
  10410. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10411. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  10412. }
  10413. /*
  10414. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  10415. * EEPROM configuration that was read.
  10416. *
  10417. * This is the mapping of EEPROM fields to Adv Library fields.
  10418. */
  10419. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10420. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  10421. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  10422. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  10423. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  10424. asc_dvc->ppr_able = 0;
  10425. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10426. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10427. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10428. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10429. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  10430. asc_dvc->start_motor = eep_config.start_motor;
  10431. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10432. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10433. asc_dvc->no_scam = eep_config.scam_tolerant;
  10434. /*
  10435. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  10436. * are set, then set an 'sdtr_able' bit for it.
  10437. */
  10438. asc_dvc->sdtr_able = 0;
  10439. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  10440. if (tid == 0) {
  10441. sdtr_speed = asc_dvc->sdtr_speed1;
  10442. } else if (tid == 4) {
  10443. sdtr_speed = asc_dvc->sdtr_speed2;
  10444. } else if (tid == 8) {
  10445. sdtr_speed = asc_dvc->sdtr_speed3;
  10446. } else if (tid == 12) {
  10447. sdtr_speed = asc_dvc->sdtr_speed4;
  10448. }
  10449. if (sdtr_speed & ASC_MAX_TID) {
  10450. asc_dvc->sdtr_able |= (1 << tid);
  10451. }
  10452. sdtr_speed >>= 4;
  10453. }
  10454. /*
  10455. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10456. * maximum queuing (max. 63, min. 4).
  10457. */
  10458. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10459. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10460. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10461. /* If the value is zero, assume it is uninitialized. */
  10462. if (eep_config.max_host_qng == 0) {
  10463. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10464. } else {
  10465. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10466. }
  10467. }
  10468. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10469. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10470. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10471. /* If the value is zero, assume it is uninitialized. */
  10472. if (eep_config.max_dvc_qng == 0) {
  10473. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10474. } else {
  10475. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10476. }
  10477. }
  10478. /*
  10479. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10480. * set 'max_dvc_qng' to 'max_host_qng'.
  10481. */
  10482. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10483. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10484. }
  10485. /*
  10486. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  10487. * values based on possibly adjusted EEPROM values.
  10488. */
  10489. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10490. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10491. /*
  10492. * If the EEPROM 'termination' field is set to automatic (0), then set
  10493. * the ASC_DVC_CFG 'termination' field to automatic also.
  10494. *
  10495. * If the termination is specified with a non-zero 'termination'
  10496. * value check that a legal value is set and set the ASC_DVC_CFG
  10497. * 'termination' field appropriately.
  10498. */
  10499. if (eep_config.termination_se == 0) {
  10500. termination = 0; /* auto termination for SE */
  10501. } else {
  10502. /* Enable manual control with low off / high off. */
  10503. if (eep_config.termination_se == 1) {
  10504. termination = 0;
  10505. /* Enable manual control with low off / high on. */
  10506. } else if (eep_config.termination_se == 2) {
  10507. termination = TERM_SE_HI;
  10508. /* Enable manual control with low on / high on. */
  10509. } else if (eep_config.termination_se == 3) {
  10510. termination = TERM_SE;
  10511. } else {
  10512. /*
  10513. * The EEPROM 'termination_se' field contains a bad value.
  10514. * Use automatic termination instead.
  10515. */
  10516. termination = 0;
  10517. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10518. }
  10519. }
  10520. if (eep_config.termination_lvd == 0) {
  10521. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10522. } else {
  10523. /* Enable manual control with low off / high off. */
  10524. if (eep_config.termination_lvd == 1) {
  10525. asc_dvc->cfg->termination = termination;
  10526. /* Enable manual control with low off / high on. */
  10527. } else if (eep_config.termination_lvd == 2) {
  10528. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10529. /* Enable manual control with low on / high on. */
  10530. } else if (eep_config.termination_lvd == 3) {
  10531. asc_dvc->cfg->termination = termination | TERM_LVD;
  10532. } else {
  10533. /*
  10534. * The EEPROM 'termination_lvd' field contains a bad value.
  10535. * Use automatic termination instead.
  10536. */
  10537. asc_dvc->cfg->termination = termination;
  10538. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10539. }
  10540. }
  10541. return warn_code;
  10542. }
  10543. /*
  10544. * Initialize the ADV_DVC_VAR structure.
  10545. *
  10546. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10547. *
  10548. * For a non-fatal error return a warning code. If there are no warnings
  10549. * then 0 is returned.
  10550. */
  10551. static int __devinit
  10552. AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  10553. {
  10554. struct asc_board *board = shost_priv(shost);
  10555. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  10556. unsigned short warn_code = 0;
  10557. AdvPortAddr iop_base = asc_dvc->iop_base;
  10558. u16 cmd;
  10559. int status;
  10560. asc_dvc->err_code = 0;
  10561. /*
  10562. * Save the state of the PCI Configuration Command Register
  10563. * "Parity Error Response Control" Bit. If the bit is clear (0),
  10564. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  10565. * DMA parity errors.
  10566. */
  10567. asc_dvc->cfg->control_flag = 0;
  10568. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  10569. if ((cmd & PCI_COMMAND_PARITY) == 0)
  10570. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  10571. asc_dvc->cfg->chip_version =
  10572. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  10573. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  10574. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  10575. (ushort)ADV_CHIP_ID_BYTE);
  10576. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  10577. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  10578. (ushort)ADV_CHIP_ID_WORD);
  10579. /*
  10580. * Reset the chip to start and allow register writes.
  10581. */
  10582. if (AdvFindSignature(iop_base) == 0) {
  10583. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  10584. return ADV_ERROR;
  10585. } else {
  10586. /*
  10587. * The caller must set 'chip_type' to a valid setting.
  10588. */
  10589. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  10590. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  10591. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  10592. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  10593. return ADV_ERROR;
  10594. }
  10595. /*
  10596. * Reset Chip.
  10597. */
  10598. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10599. ADV_CTRL_REG_CMD_RESET);
  10600. mdelay(100);
  10601. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10602. ADV_CTRL_REG_CMD_WR_IO_REG);
  10603. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  10604. status = AdvInitFrom38C1600EEP(asc_dvc);
  10605. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10606. status = AdvInitFrom38C0800EEP(asc_dvc);
  10607. } else {
  10608. status = AdvInitFrom3550EEP(asc_dvc);
  10609. }
  10610. warn_code |= status;
  10611. }
  10612. if (warn_code != 0)
  10613. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  10614. if (asc_dvc->err_code)
  10615. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  10616. asc_dvc->err_code);
  10617. return asc_dvc->err_code;
  10618. }
  10619. #endif
  10620. static struct scsi_host_template advansys_template = {
  10621. .proc_name = DRV_NAME,
  10622. #ifdef CONFIG_PROC_FS
  10623. .proc_info = advansys_proc_info,
  10624. #endif
  10625. .name = DRV_NAME,
  10626. .info = advansys_info,
  10627. .queuecommand = advansys_queuecommand,
  10628. .eh_bus_reset_handler = advansys_reset,
  10629. .bios_param = advansys_biosparam,
  10630. .slave_configure = advansys_slave_configure,
  10631. /*
  10632. * Because the driver may control an ISA adapter 'unchecked_isa_dma'
  10633. * must be set. The flag will be cleared in advansys_board_found
  10634. * for non-ISA adapters.
  10635. */
  10636. .unchecked_isa_dma = 1,
  10637. /*
  10638. * All adapters controlled by this driver are capable of large
  10639. * scatter-gather lists. According to the mid-level SCSI documentation
  10640. * this obviates any performance gain provided by setting
  10641. * 'use_clustering'. But empirically while CPU utilization is increased
  10642. * by enabling clustering, I/O throughput increases as well.
  10643. */
  10644. .use_clustering = ENABLE_CLUSTERING,
  10645. };
  10646. static int __devinit advansys_wide_init_chip(struct Scsi_Host *shost)
  10647. {
  10648. struct asc_board *board = shost_priv(shost);
  10649. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10650. int req_cnt = 0;
  10651. adv_req_t *reqp = NULL;
  10652. int sg_cnt = 0;
  10653. adv_sgblk_t *sgp;
  10654. int warn_code, err_code;
  10655. /*
  10656. * Allocate buffer carrier structures. The total size
  10657. * is about 4 KB, so allocate all at once.
  10658. */
  10659. adv_dvc->carrier_buf = kmalloc(ADV_CARRIER_BUFSIZE, GFP_KERNEL);
  10660. ASC_DBG(1, "carrier_buf 0x%p\n", adv_dvc->carrier_buf);
  10661. if (!adv_dvc->carrier_buf)
  10662. goto kmalloc_failed;
  10663. /*
  10664. * Allocate up to 'max_host_qng' request structures for the Wide
  10665. * board. The total size is about 16 KB, so allocate all at once.
  10666. * If the allocation fails decrement and try again.
  10667. */
  10668. for (req_cnt = adv_dvc->max_host_qng; req_cnt > 0; req_cnt--) {
  10669. reqp = kmalloc(sizeof(adv_req_t) * req_cnt, GFP_KERNEL);
  10670. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", reqp, req_cnt,
  10671. (ulong)sizeof(adv_req_t) * req_cnt);
  10672. if (reqp)
  10673. break;
  10674. }
  10675. if (!reqp)
  10676. goto kmalloc_failed;
  10677. adv_dvc->orig_reqp = reqp;
  10678. /*
  10679. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  10680. * the Wide board. Each structure is about 136 bytes.
  10681. */
  10682. board->adv_sgblkp = NULL;
  10683. for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
  10684. sgp = kmalloc(sizeof(adv_sgblk_t), GFP_KERNEL);
  10685. if (!sgp)
  10686. break;
  10687. sgp->next_sgblkp = board->adv_sgblkp;
  10688. board->adv_sgblkp = sgp;
  10689. }
  10690. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", sg_cnt, sizeof(adv_sgblk_t),
  10691. sizeof(adv_sgblk_t) * sg_cnt);
  10692. if (!board->adv_sgblkp)
  10693. goto kmalloc_failed;
  10694. /*
  10695. * Point 'adv_reqp' to the request structures and
  10696. * link them together.
  10697. */
  10698. req_cnt--;
  10699. reqp[req_cnt].next_reqp = NULL;
  10700. for (; req_cnt > 0; req_cnt--) {
  10701. reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
  10702. }
  10703. board->adv_reqp = &reqp[0];
  10704. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  10705. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  10706. warn_code = AdvInitAsc3550Driver(adv_dvc);
  10707. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10708. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  10709. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  10710. } else {
  10711. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  10712. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  10713. }
  10714. err_code = adv_dvc->err_code;
  10715. if (warn_code || err_code) {
  10716. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  10717. "0x%x\n", warn_code, err_code);
  10718. }
  10719. goto exit;
  10720. kmalloc_failed:
  10721. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  10722. err_code = ADV_ERROR;
  10723. exit:
  10724. return err_code;
  10725. }
  10726. static void advansys_wide_free_mem(struct asc_board *board)
  10727. {
  10728. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10729. kfree(adv_dvc->carrier_buf);
  10730. adv_dvc->carrier_buf = NULL;
  10731. kfree(adv_dvc->orig_reqp);
  10732. adv_dvc->orig_reqp = board->adv_reqp = NULL;
  10733. while (board->adv_sgblkp) {
  10734. adv_sgblk_t *sgp = board->adv_sgblkp;
  10735. board->adv_sgblkp = sgp->next_sgblkp;
  10736. kfree(sgp);
  10737. }
  10738. }
  10739. static int __devinit advansys_board_found(struct Scsi_Host *shost,
  10740. unsigned int iop, int bus_type)
  10741. {
  10742. struct pci_dev *pdev;
  10743. struct asc_board *boardp = shost_priv(shost);
  10744. ASC_DVC_VAR *asc_dvc_varp = NULL;
  10745. ADV_DVC_VAR *adv_dvc_varp = NULL;
  10746. int share_irq, warn_code, ret;
  10747. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  10748. if (ASC_NARROW_BOARD(boardp)) {
  10749. ASC_DBG(1, "narrow board\n");
  10750. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  10751. asc_dvc_varp->bus_type = bus_type;
  10752. asc_dvc_varp->drv_ptr = boardp;
  10753. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  10754. asc_dvc_varp->iop_base = iop;
  10755. } else {
  10756. #ifdef CONFIG_PCI
  10757. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  10758. adv_dvc_varp->drv_ptr = boardp;
  10759. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  10760. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  10761. ASC_DBG(1, "wide board ASC-3550\n");
  10762. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  10763. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  10764. ASC_DBG(1, "wide board ASC-38C0800\n");
  10765. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  10766. } else {
  10767. ASC_DBG(1, "wide board ASC-38C1600\n");
  10768. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  10769. }
  10770. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  10771. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  10772. if (!boardp->ioremap_addr) {
  10773. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  10774. "returned NULL\n",
  10775. (long)pci_resource_start(pdev, 1),
  10776. boardp->asc_n_io_port);
  10777. ret = -ENODEV;
  10778. goto err_shost;
  10779. }
  10780. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  10781. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  10782. /*
  10783. * Even though it isn't used to access wide boards, other
  10784. * than for the debug line below, save I/O Port address so
  10785. * that it can be reported.
  10786. */
  10787. boardp->ioport = iop;
  10788. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  10789. (ushort)inp(iop + 1), (ushort)inpw(iop));
  10790. #endif /* CONFIG_PCI */
  10791. }
  10792. #ifdef CONFIG_PROC_FS
  10793. /*
  10794. * Allocate buffer for printing information from
  10795. * /proc/scsi/advansys/[0...].
  10796. */
  10797. boardp->prtbuf = kmalloc(ASC_PRTBUF_SIZE, GFP_KERNEL);
  10798. if (!boardp->prtbuf) {
  10799. shost_printk(KERN_ERR, shost, "kmalloc(%d) returned NULL\n",
  10800. ASC_PRTBUF_SIZE);
  10801. ret = -ENOMEM;
  10802. goto err_unmap;
  10803. }
  10804. #endif /* CONFIG_PROC_FS */
  10805. if (ASC_NARROW_BOARD(boardp)) {
  10806. /*
  10807. * Set the board bus type and PCI IRQ before
  10808. * calling AscInitGetConfig().
  10809. */
  10810. switch (asc_dvc_varp->bus_type) {
  10811. #ifdef CONFIG_ISA
  10812. case ASC_IS_ISA:
  10813. shost->unchecked_isa_dma = TRUE;
  10814. share_irq = 0;
  10815. break;
  10816. case ASC_IS_VL:
  10817. shost->unchecked_isa_dma = FALSE;
  10818. share_irq = 0;
  10819. break;
  10820. case ASC_IS_EISA:
  10821. shost->unchecked_isa_dma = FALSE;
  10822. share_irq = IRQF_SHARED;
  10823. break;
  10824. #endif /* CONFIG_ISA */
  10825. #ifdef CONFIG_PCI
  10826. case ASC_IS_PCI:
  10827. shost->unchecked_isa_dma = FALSE;
  10828. share_irq = IRQF_SHARED;
  10829. break;
  10830. #endif /* CONFIG_PCI */
  10831. default:
  10832. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  10833. "%d\n", asc_dvc_varp->bus_type);
  10834. shost->unchecked_isa_dma = TRUE;
  10835. share_irq = 0;
  10836. break;
  10837. }
  10838. /*
  10839. * NOTE: AscInitGetConfig() may change the board's
  10840. * bus_type value. The bus_type value should no
  10841. * longer be used. If the bus_type field must be
  10842. * referenced only use the bit-wise AND operator "&".
  10843. */
  10844. ASC_DBG(2, "AscInitGetConfig()\n");
  10845. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  10846. } else {
  10847. #ifdef CONFIG_PCI
  10848. /*
  10849. * For Wide boards set PCI information before calling
  10850. * AdvInitGetConfig().
  10851. */
  10852. shost->unchecked_isa_dma = FALSE;
  10853. share_irq = IRQF_SHARED;
  10854. ASC_DBG(2, "AdvInitGetConfig()\n");
  10855. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  10856. #endif /* CONFIG_PCI */
  10857. }
  10858. if (ret)
  10859. goto err_free_proc;
  10860. /*
  10861. * Save the EEPROM configuration so that it can be displayed
  10862. * from /proc/scsi/advansys/[0...].
  10863. */
  10864. if (ASC_NARROW_BOARD(boardp)) {
  10865. ASCEEP_CONFIG *ep;
  10866. /*
  10867. * Set the adapter's target id bit in the 'init_tidmask' field.
  10868. */
  10869. boardp->init_tidmask |=
  10870. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  10871. /*
  10872. * Save EEPROM settings for the board.
  10873. */
  10874. ep = &boardp->eep_config.asc_eep;
  10875. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  10876. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  10877. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  10878. ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
  10879. ep->start_motor = asc_dvc_varp->start_motor;
  10880. ep->cntl = asc_dvc_varp->dvc_cntl;
  10881. ep->no_scam = asc_dvc_varp->no_scam;
  10882. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  10883. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  10884. /* 'max_tag_qng' is set to the same value for every device. */
  10885. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  10886. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  10887. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  10888. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  10889. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  10890. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  10891. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  10892. /*
  10893. * Modify board configuration.
  10894. */
  10895. ASC_DBG(2, "AscInitSetConfig()\n");
  10896. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  10897. if (ret)
  10898. goto err_free_proc;
  10899. } else {
  10900. ADVEEP_3550_CONFIG *ep_3550;
  10901. ADVEEP_38C0800_CONFIG *ep_38C0800;
  10902. ADVEEP_38C1600_CONFIG *ep_38C1600;
  10903. /*
  10904. * Save Wide EEP Configuration Information.
  10905. */
  10906. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  10907. ep_3550 = &boardp->eep_config.adv_3550_eep;
  10908. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  10909. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  10910. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10911. ep_3550->termination = adv_dvc_varp->cfg->termination;
  10912. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  10913. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10914. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  10915. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  10916. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  10917. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  10918. ep_3550->start_motor = adv_dvc_varp->start_motor;
  10919. ep_3550->scsi_reset_delay =
  10920. adv_dvc_varp->scsi_reset_wait;
  10921. ep_3550->serial_number_word1 =
  10922. adv_dvc_varp->cfg->serial1;
  10923. ep_3550->serial_number_word2 =
  10924. adv_dvc_varp->cfg->serial2;
  10925. ep_3550->serial_number_word3 =
  10926. adv_dvc_varp->cfg->serial3;
  10927. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  10928. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  10929. ep_38C0800->adapter_scsi_id =
  10930. adv_dvc_varp->chip_scsi_id;
  10931. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  10932. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10933. ep_38C0800->termination_lvd =
  10934. adv_dvc_varp->cfg->termination;
  10935. ep_38C0800->disc_enable =
  10936. adv_dvc_varp->cfg->disc_enable;
  10937. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10938. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  10939. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10940. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10941. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10942. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10943. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10944. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10945. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  10946. ep_38C0800->scsi_reset_delay =
  10947. adv_dvc_varp->scsi_reset_wait;
  10948. ep_38C0800->serial_number_word1 =
  10949. adv_dvc_varp->cfg->serial1;
  10950. ep_38C0800->serial_number_word2 =
  10951. adv_dvc_varp->cfg->serial2;
  10952. ep_38C0800->serial_number_word3 =
  10953. adv_dvc_varp->cfg->serial3;
  10954. } else {
  10955. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  10956. ep_38C1600->adapter_scsi_id =
  10957. adv_dvc_varp->chip_scsi_id;
  10958. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  10959. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10960. ep_38C1600->termination_lvd =
  10961. adv_dvc_varp->cfg->termination;
  10962. ep_38C1600->disc_enable =
  10963. adv_dvc_varp->cfg->disc_enable;
  10964. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10965. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  10966. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10967. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10968. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10969. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10970. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10971. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10972. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  10973. ep_38C1600->scsi_reset_delay =
  10974. adv_dvc_varp->scsi_reset_wait;
  10975. ep_38C1600->serial_number_word1 =
  10976. adv_dvc_varp->cfg->serial1;
  10977. ep_38C1600->serial_number_word2 =
  10978. adv_dvc_varp->cfg->serial2;
  10979. ep_38C1600->serial_number_word3 =
  10980. adv_dvc_varp->cfg->serial3;
  10981. }
  10982. /*
  10983. * Set the adapter's target id bit in the 'init_tidmask' field.
  10984. */
  10985. boardp->init_tidmask |=
  10986. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  10987. }
  10988. /*
  10989. * Channels are numbered beginning with 0. For AdvanSys one host
  10990. * structure supports one channel. Multi-channel boards have a
  10991. * separate host structure for each channel.
  10992. */
  10993. shost->max_channel = 0;
  10994. if (ASC_NARROW_BOARD(boardp)) {
  10995. shost->max_id = ASC_MAX_TID + 1;
  10996. shost->max_lun = ASC_MAX_LUN + 1;
  10997. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  10998. shost->io_port = asc_dvc_varp->iop_base;
  10999. boardp->asc_n_io_port = ASC_IOADR_GAP;
  11000. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  11001. /* Set maximum number of queues the adapter can handle. */
  11002. shost->can_queue = asc_dvc_varp->max_total_qng;
  11003. } else {
  11004. shost->max_id = ADV_MAX_TID + 1;
  11005. shost->max_lun = ADV_MAX_LUN + 1;
  11006. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  11007. /*
  11008. * Save the I/O Port address and length even though
  11009. * I/O ports are not used to access Wide boards.
  11010. * Instead the Wide boards are accessed with
  11011. * PCI Memory Mapped I/O.
  11012. */
  11013. shost->io_port = iop;
  11014. shost->this_id = adv_dvc_varp->chip_scsi_id;
  11015. /* Set maximum number of queues the adapter can handle. */
  11016. shost->can_queue = adv_dvc_varp->max_host_qng;
  11017. }
  11018. /*
  11019. * Following v1.3.89, 'cmd_per_lun' is no longer needed
  11020. * and should be set to zero.
  11021. *
  11022. * But because of a bug introduced in v1.3.89 if the driver is
  11023. * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
  11024. * SCSI function 'allocate_device' will panic. To allow the driver
  11025. * to work as a module in these kernels set 'cmd_per_lun' to 1.
  11026. *
  11027. * Note: This is wrong. cmd_per_lun should be set to the depth
  11028. * you want on untagged devices always.
  11029. #ifdef MODULE
  11030. */
  11031. shost->cmd_per_lun = 1;
  11032. /* #else
  11033. shost->cmd_per_lun = 0;
  11034. #endif */
  11035. /*
  11036. * Set the maximum number of scatter-gather elements the
  11037. * adapter can handle.
  11038. */
  11039. if (ASC_NARROW_BOARD(boardp)) {
  11040. /*
  11041. * Allow two commands with 'sg_tablesize' scatter-gather
  11042. * elements to be executed simultaneously. This value is
  11043. * the theoretical hardware limit. It may be decreased
  11044. * below.
  11045. */
  11046. shost->sg_tablesize =
  11047. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  11048. ASC_SG_LIST_PER_Q) + 1;
  11049. } else {
  11050. shost->sg_tablesize = ADV_MAX_SG_LIST;
  11051. }
  11052. /*
  11053. * The value of 'sg_tablesize' can not exceed the SCSI
  11054. * mid-level driver definition of SG_ALL. SG_ALL also
  11055. * must not be exceeded, because it is used to define the
  11056. * size of the scatter-gather table in 'struct asc_sg_head'.
  11057. */
  11058. if (shost->sg_tablesize > SG_ALL) {
  11059. shost->sg_tablesize = SG_ALL;
  11060. }
  11061. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  11062. /* BIOS start address. */
  11063. if (ASC_NARROW_BOARD(boardp)) {
  11064. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  11065. asc_dvc_varp->bus_type);
  11066. } else {
  11067. /*
  11068. * Fill-in BIOS board variables. The Wide BIOS saves
  11069. * information in LRAM that is used by the driver.
  11070. */
  11071. AdvReadWordLram(adv_dvc_varp->iop_base,
  11072. BIOS_SIGNATURE, boardp->bios_signature);
  11073. AdvReadWordLram(adv_dvc_varp->iop_base,
  11074. BIOS_VERSION, boardp->bios_version);
  11075. AdvReadWordLram(adv_dvc_varp->iop_base,
  11076. BIOS_CODESEG, boardp->bios_codeseg);
  11077. AdvReadWordLram(adv_dvc_varp->iop_base,
  11078. BIOS_CODELEN, boardp->bios_codelen);
  11079. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  11080. boardp->bios_signature, boardp->bios_version);
  11081. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  11082. boardp->bios_codeseg, boardp->bios_codelen);
  11083. /*
  11084. * If the BIOS saved a valid signature, then fill in
  11085. * the BIOS code segment base address.
  11086. */
  11087. if (boardp->bios_signature == 0x55AA) {
  11088. /*
  11089. * Convert x86 realmode code segment to a linear
  11090. * address by shifting left 4.
  11091. */
  11092. shost->base = ((ulong)boardp->bios_codeseg << 4);
  11093. } else {
  11094. shost->base = 0;
  11095. }
  11096. }
  11097. /*
  11098. * Register Board Resources - I/O Port, DMA, IRQ
  11099. */
  11100. /* Register DMA Channel for Narrow boards. */
  11101. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  11102. #ifdef CONFIG_ISA
  11103. if (ASC_NARROW_BOARD(boardp)) {
  11104. /* Register DMA channel for ISA bus. */
  11105. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  11106. shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
  11107. ret = request_dma(shost->dma_channel, DRV_NAME);
  11108. if (ret) {
  11109. shost_printk(KERN_ERR, shost, "request_dma() "
  11110. "%d failed %d\n",
  11111. shost->dma_channel, ret);
  11112. goto err_free_proc;
  11113. }
  11114. AscEnableIsaDma(shost->dma_channel);
  11115. }
  11116. }
  11117. #endif /* CONFIG_ISA */
  11118. /* Register IRQ Number. */
  11119. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  11120. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  11121. DRV_NAME, shost);
  11122. if (ret) {
  11123. if (ret == -EBUSY) {
  11124. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11125. "already in use\n", boardp->irq);
  11126. } else if (ret == -EINVAL) {
  11127. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11128. "not valid\n", boardp->irq);
  11129. } else {
  11130. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11131. "failed with %d\n", boardp->irq, ret);
  11132. }
  11133. goto err_free_dma;
  11134. }
  11135. /*
  11136. * Initialize board RISC chip and enable interrupts.
  11137. */
  11138. if (ASC_NARROW_BOARD(boardp)) {
  11139. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  11140. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  11141. if (!asc_dvc_varp->overrun_buf) {
  11142. ret = -ENOMEM;
  11143. goto err_free_wide_mem;
  11144. }
  11145. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  11146. if (warn_code || asc_dvc_varp->err_code) {
  11147. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  11148. "warn 0x%x, error 0x%x\n",
  11149. asc_dvc_varp->init_state, warn_code,
  11150. asc_dvc_varp->err_code);
  11151. if (asc_dvc_varp->err_code) {
  11152. ret = -ENODEV;
  11153. kfree(asc_dvc_varp->overrun_buf);
  11154. }
  11155. }
  11156. } else {
  11157. if (advansys_wide_init_chip(shost))
  11158. ret = -ENODEV;
  11159. }
  11160. if (ret)
  11161. goto err_free_wide_mem;
  11162. ASC_DBG_PRT_SCSI_HOST(2, shost);
  11163. ret = scsi_add_host(shost, boardp->dev);
  11164. if (ret)
  11165. goto err_free_wide_mem;
  11166. scsi_scan_host(shost);
  11167. return 0;
  11168. err_free_wide_mem:
  11169. advansys_wide_free_mem(boardp);
  11170. free_irq(boardp->irq, shost);
  11171. err_free_dma:
  11172. #ifdef CONFIG_ISA
  11173. if (shost->dma_channel != NO_ISA_DMA)
  11174. free_dma(shost->dma_channel);
  11175. #endif
  11176. err_free_proc:
  11177. kfree(boardp->prtbuf);
  11178. err_unmap:
  11179. if (boardp->ioremap_addr)
  11180. iounmap(boardp->ioremap_addr);
  11181. err_shost:
  11182. return ret;
  11183. }
  11184. /*
  11185. * advansys_release()
  11186. *
  11187. * Release resources allocated for a single AdvanSys adapter.
  11188. */
  11189. static int advansys_release(struct Scsi_Host *shost)
  11190. {
  11191. struct asc_board *board = shost_priv(shost);
  11192. ASC_DBG(1, "begin\n");
  11193. scsi_remove_host(shost);
  11194. free_irq(board->irq, shost);
  11195. #ifdef CONFIG_ISA
  11196. if (shost->dma_channel != NO_ISA_DMA) {
  11197. ASC_DBG(1, "free_dma()\n");
  11198. free_dma(shost->dma_channel);
  11199. }
  11200. #endif
  11201. if (ASC_NARROW_BOARD(board)) {
  11202. dma_unmap_single(board->dev,
  11203. board->dvc_var.asc_dvc_var.overrun_dma,
  11204. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  11205. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  11206. } else {
  11207. iounmap(board->ioremap_addr);
  11208. advansys_wide_free_mem(board);
  11209. }
  11210. kfree(board->prtbuf);
  11211. scsi_host_put(shost);
  11212. ASC_DBG(1, "end\n");
  11213. return 0;
  11214. }
  11215. #define ASC_IOADR_TABLE_MAX_IX 11
  11216. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  11217. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  11218. 0x0210, 0x0230, 0x0250, 0x0330
  11219. };
  11220. /*
  11221. * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
  11222. * 00: 10
  11223. * 01: 11
  11224. * 10: 12
  11225. * 11: 15
  11226. */
  11227. static unsigned int __devinit advansys_isa_irq_no(PortAddr iop_base)
  11228. {
  11229. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  11230. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
  11231. if (chip_irq == 13)
  11232. chip_irq = 15;
  11233. return chip_irq;
  11234. }
  11235. static int __devinit advansys_isa_probe(struct device *dev, unsigned int id)
  11236. {
  11237. int err = -ENODEV;
  11238. PortAddr iop_base = _asc_def_iop_base[id];
  11239. struct Scsi_Host *shost;
  11240. struct asc_board *board;
  11241. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  11242. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  11243. return -ENODEV;
  11244. }
  11245. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  11246. if (!AscFindSignature(iop_base))
  11247. goto release_region;
  11248. if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
  11249. goto release_region;
  11250. err = -ENOMEM;
  11251. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11252. if (!shost)
  11253. goto release_region;
  11254. board = shost_priv(shost);
  11255. board->irq = advansys_isa_irq_no(iop_base);
  11256. board->dev = dev;
  11257. err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
  11258. if (err)
  11259. goto free_host;
  11260. dev_set_drvdata(dev, shost);
  11261. return 0;
  11262. free_host:
  11263. scsi_host_put(shost);
  11264. release_region:
  11265. release_region(iop_base, ASC_IOADR_GAP);
  11266. return err;
  11267. }
  11268. static int __devexit advansys_isa_remove(struct device *dev, unsigned int id)
  11269. {
  11270. int ioport = _asc_def_iop_base[id];
  11271. advansys_release(dev_get_drvdata(dev));
  11272. release_region(ioport, ASC_IOADR_GAP);
  11273. return 0;
  11274. }
  11275. static struct isa_driver advansys_isa_driver = {
  11276. .probe = advansys_isa_probe,
  11277. .remove = __devexit_p(advansys_isa_remove),
  11278. .driver = {
  11279. .owner = THIS_MODULE,
  11280. .name = DRV_NAME,
  11281. },
  11282. };
  11283. /*
  11284. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  11285. * 000: invalid
  11286. * 001: 10
  11287. * 010: 11
  11288. * 011: 12
  11289. * 100: invalid
  11290. * 101: 14
  11291. * 110: 15
  11292. * 111: invalid
  11293. */
  11294. static unsigned int __devinit advansys_vlb_irq_no(PortAddr iop_base)
  11295. {
  11296. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  11297. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  11298. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  11299. return 0;
  11300. return chip_irq;
  11301. }
  11302. static int __devinit advansys_vlb_probe(struct device *dev, unsigned int id)
  11303. {
  11304. int err = -ENODEV;
  11305. PortAddr iop_base = _asc_def_iop_base[id];
  11306. struct Scsi_Host *shost;
  11307. struct asc_board *board;
  11308. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  11309. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  11310. return -ENODEV;
  11311. }
  11312. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  11313. if (!AscFindSignature(iop_base))
  11314. goto release_region;
  11315. /*
  11316. * I don't think this condition can actually happen, but the old
  11317. * driver did it, and the chances of finding a VLB setup in 2007
  11318. * to do testing with is slight to none.
  11319. */
  11320. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  11321. goto release_region;
  11322. err = -ENOMEM;
  11323. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11324. if (!shost)
  11325. goto release_region;
  11326. board = shost_priv(shost);
  11327. board->irq = advansys_vlb_irq_no(iop_base);
  11328. board->dev = dev;
  11329. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  11330. if (err)
  11331. goto free_host;
  11332. dev_set_drvdata(dev, shost);
  11333. return 0;
  11334. free_host:
  11335. scsi_host_put(shost);
  11336. release_region:
  11337. release_region(iop_base, ASC_IOADR_GAP);
  11338. return -ENODEV;
  11339. }
  11340. static struct isa_driver advansys_vlb_driver = {
  11341. .probe = advansys_vlb_probe,
  11342. .remove = __devexit_p(advansys_isa_remove),
  11343. .driver = {
  11344. .owner = THIS_MODULE,
  11345. .name = "advansys_vlb",
  11346. },
  11347. };
  11348. static struct eisa_device_id advansys_eisa_table[] __devinitdata = {
  11349. { "ABP7401" },
  11350. { "ABP7501" },
  11351. { "" }
  11352. };
  11353. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  11354. /*
  11355. * EISA is a little more tricky than PCI; each EISA device may have two
  11356. * channels, and this driver is written to make each channel its own Scsi_Host
  11357. */
  11358. struct eisa_scsi_data {
  11359. struct Scsi_Host *host[2];
  11360. };
  11361. /*
  11362. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  11363. * 000: 10
  11364. * 001: 11
  11365. * 010: 12
  11366. * 011: invalid
  11367. * 100: 14
  11368. * 101: 15
  11369. * 110: invalid
  11370. * 111: invalid
  11371. */
  11372. static unsigned int __devinit advansys_eisa_irq_no(struct eisa_device *edev)
  11373. {
  11374. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  11375. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  11376. if ((chip_irq == 13) || (chip_irq > 15))
  11377. return 0;
  11378. return chip_irq;
  11379. }
  11380. static int __devinit advansys_eisa_probe(struct device *dev)
  11381. {
  11382. int i, ioport, irq = 0;
  11383. int err;
  11384. struct eisa_device *edev = to_eisa_device(dev);
  11385. struct eisa_scsi_data *data;
  11386. err = -ENOMEM;
  11387. data = kzalloc(sizeof(*data), GFP_KERNEL);
  11388. if (!data)
  11389. goto fail;
  11390. ioport = edev->base_addr + 0xc30;
  11391. err = -ENODEV;
  11392. for (i = 0; i < 2; i++, ioport += 0x20) {
  11393. struct asc_board *board;
  11394. struct Scsi_Host *shost;
  11395. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  11396. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  11397. ioport + ASC_IOADR_GAP - 1);
  11398. continue;
  11399. }
  11400. if (!AscFindSignature(ioport)) {
  11401. release_region(ioport, ASC_IOADR_GAP);
  11402. continue;
  11403. }
  11404. /*
  11405. * I don't know why we need to do this for EISA chips, but
  11406. * not for any others. It looks to be equivalent to
  11407. * AscGetChipCfgMsw, but I may have overlooked something,
  11408. * so I'm not converting it until I get an EISA board to
  11409. * test with.
  11410. */
  11411. inw(ioport + 4);
  11412. if (!irq)
  11413. irq = advansys_eisa_irq_no(edev);
  11414. err = -ENOMEM;
  11415. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11416. if (!shost)
  11417. goto release_region;
  11418. board = shost_priv(shost);
  11419. board->irq = irq;
  11420. board->dev = dev;
  11421. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  11422. if (!err) {
  11423. data->host[i] = shost;
  11424. continue;
  11425. }
  11426. scsi_host_put(shost);
  11427. release_region:
  11428. release_region(ioport, ASC_IOADR_GAP);
  11429. break;
  11430. }
  11431. if (err)
  11432. goto free_data;
  11433. dev_set_drvdata(dev, data);
  11434. return 0;
  11435. free_data:
  11436. kfree(data->host[0]);
  11437. kfree(data->host[1]);
  11438. kfree(data);
  11439. fail:
  11440. return err;
  11441. }
  11442. static __devexit int advansys_eisa_remove(struct device *dev)
  11443. {
  11444. int i;
  11445. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  11446. for (i = 0; i < 2; i++) {
  11447. int ioport;
  11448. struct Scsi_Host *shost = data->host[i];
  11449. if (!shost)
  11450. continue;
  11451. ioport = shost->io_port;
  11452. advansys_release(shost);
  11453. release_region(ioport, ASC_IOADR_GAP);
  11454. }
  11455. kfree(data);
  11456. return 0;
  11457. }
  11458. static struct eisa_driver advansys_eisa_driver = {
  11459. .id_table = advansys_eisa_table,
  11460. .driver = {
  11461. .name = DRV_NAME,
  11462. .probe = advansys_eisa_probe,
  11463. .remove = __devexit_p(advansys_eisa_remove),
  11464. }
  11465. };
  11466. /* PCI Devices supported by this driver */
  11467. static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
  11468. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  11469. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11470. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  11471. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11472. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  11473. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11474. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  11475. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11476. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  11477. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11478. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  11479. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11480. {}
  11481. };
  11482. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  11483. static void __devinit advansys_set_latency(struct pci_dev *pdev)
  11484. {
  11485. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  11486. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  11487. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  11488. } else {
  11489. u8 latency;
  11490. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  11491. if (latency < 0x20)
  11492. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  11493. }
  11494. }
  11495. static int __devinit
  11496. advansys_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11497. {
  11498. int err, ioport;
  11499. struct Scsi_Host *shost;
  11500. struct asc_board *board;
  11501. err = pci_enable_device(pdev);
  11502. if (err)
  11503. goto fail;
  11504. err = pci_request_regions(pdev, DRV_NAME);
  11505. if (err)
  11506. goto disable_device;
  11507. pci_set_master(pdev);
  11508. advansys_set_latency(pdev);
  11509. err = -ENODEV;
  11510. if (pci_resource_len(pdev, 0) == 0)
  11511. goto release_region;
  11512. ioport = pci_resource_start(pdev, 0);
  11513. err = -ENOMEM;
  11514. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11515. if (!shost)
  11516. goto release_region;
  11517. board = shost_priv(shost);
  11518. board->irq = pdev->irq;
  11519. board->dev = &pdev->dev;
  11520. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  11521. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  11522. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  11523. board->flags |= ASC_IS_WIDE_BOARD;
  11524. }
  11525. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  11526. if (err)
  11527. goto free_host;
  11528. pci_set_drvdata(pdev, shost);
  11529. return 0;
  11530. free_host:
  11531. scsi_host_put(shost);
  11532. release_region:
  11533. pci_release_regions(pdev);
  11534. disable_device:
  11535. pci_disable_device(pdev);
  11536. fail:
  11537. return err;
  11538. }
  11539. static void __devexit advansys_pci_remove(struct pci_dev *pdev)
  11540. {
  11541. advansys_release(pci_get_drvdata(pdev));
  11542. pci_release_regions(pdev);
  11543. pci_disable_device(pdev);
  11544. }
  11545. static struct pci_driver advansys_pci_driver = {
  11546. .name = DRV_NAME,
  11547. .id_table = advansys_pci_tbl,
  11548. .probe = advansys_pci_probe,
  11549. .remove = __devexit_p(advansys_pci_remove),
  11550. };
  11551. static int __init advansys_init(void)
  11552. {
  11553. int error;
  11554. error = isa_register_driver(&advansys_isa_driver,
  11555. ASC_IOADR_TABLE_MAX_IX);
  11556. if (error)
  11557. goto fail;
  11558. error = isa_register_driver(&advansys_vlb_driver,
  11559. ASC_IOADR_TABLE_MAX_IX);
  11560. if (error)
  11561. goto unregister_isa;
  11562. error = eisa_driver_register(&advansys_eisa_driver);
  11563. if (error)
  11564. goto unregister_vlb;
  11565. error = pci_register_driver(&advansys_pci_driver);
  11566. if (error)
  11567. goto unregister_eisa;
  11568. return 0;
  11569. unregister_eisa:
  11570. eisa_driver_unregister(&advansys_eisa_driver);
  11571. unregister_vlb:
  11572. isa_unregister_driver(&advansys_vlb_driver);
  11573. unregister_isa:
  11574. isa_unregister_driver(&advansys_isa_driver);
  11575. fail:
  11576. return error;
  11577. }
  11578. static void __exit advansys_exit(void)
  11579. {
  11580. pci_unregister_driver(&advansys_pci_driver);
  11581. eisa_driver_unregister(&advansys_eisa_driver);
  11582. isa_unregister_driver(&advansys_vlb_driver);
  11583. isa_unregister_driver(&advansys_isa_driver);
  11584. }
  11585. module_init(advansys_init);
  11586. module_exit(advansys_exit);
  11587. MODULE_LICENSE("GPL");
  11588. MODULE_FIRMWARE("advansys/mcode.bin");
  11589. MODULE_FIRMWARE("advansys/3550.bin");
  11590. MODULE_FIRMWARE("advansys/38C0800.bin");
  11591. MODULE_FIRMWARE("advansys/38C1600.bin");