advansys.c 375 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859
  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 written 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. if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
  4258. warn_code = -ENOMEM;
  4259. goto err_dma_map;
  4260. }
  4261. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  4262. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  4263. (uchar *)&phy_addr, 1);
  4264. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  4265. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  4266. (uchar *)&phy_size, 1);
  4267. asc_dvc->cfg->mcode_date =
  4268. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  4269. asc_dvc->cfg->mcode_version =
  4270. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  4271. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  4272. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  4273. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  4274. warn_code = UW_ERR;
  4275. goto err_mcode_start;
  4276. }
  4277. if (AscStartChip(iop_base) != 1) {
  4278. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  4279. warn_code = UW_ERR;
  4280. goto err_mcode_start;
  4281. }
  4282. return warn_code;
  4283. err_mcode_start:
  4284. dma_unmap_single(board->dev, asc_dvc->overrun_dma,
  4285. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  4286. err_dma_map:
  4287. asc_dvc->overrun_dma = 0;
  4288. return warn_code;
  4289. }
  4290. static ushort AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  4291. {
  4292. const struct firmware *fw;
  4293. const char fwname[] = "advansys/mcode.bin";
  4294. int err;
  4295. unsigned long chksum;
  4296. ushort warn_code;
  4297. PortAddr iop_base;
  4298. iop_base = asc_dvc->iop_base;
  4299. warn_code = 0;
  4300. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  4301. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  4302. AscResetChipAndScsiBus(asc_dvc);
  4303. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4304. }
  4305. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  4306. if (asc_dvc->err_code != 0)
  4307. return UW_ERR;
  4308. if (!AscFindSignature(asc_dvc->iop_base)) {
  4309. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  4310. return warn_code;
  4311. }
  4312. AscDisableInterrupt(iop_base);
  4313. warn_code |= AscInitLram(asc_dvc);
  4314. if (asc_dvc->err_code != 0)
  4315. return UW_ERR;
  4316. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4317. if (err) {
  4318. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4319. fwname, err);
  4320. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4321. return err;
  4322. }
  4323. if (fw->size < 4) {
  4324. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4325. fw->size, fwname);
  4326. release_firmware(fw);
  4327. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4328. return -EINVAL;
  4329. }
  4330. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4331. (fw->data[1] << 8) | fw->data[0];
  4332. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  4333. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  4334. fw->size - 4) != chksum) {
  4335. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4336. release_firmware(fw);
  4337. return warn_code;
  4338. }
  4339. release_firmware(fw);
  4340. warn_code |= AscInitMicroCodeVar(asc_dvc);
  4341. if (!asc_dvc->overrun_dma)
  4342. return warn_code;
  4343. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  4344. AscEnableInterrupt(iop_base);
  4345. return warn_code;
  4346. }
  4347. /*
  4348. * Load the Microcode
  4349. *
  4350. * Write the microcode image to RISC memory starting at address 0.
  4351. *
  4352. * The microcode is stored compressed in the following format:
  4353. *
  4354. * 254 word (508 byte) table indexed by byte code followed
  4355. * by the following byte codes:
  4356. *
  4357. * 1-Byte Code:
  4358. * 00: Emit word 0 in table.
  4359. * 01: Emit word 1 in table.
  4360. * .
  4361. * FD: Emit word 253 in table.
  4362. *
  4363. * Multi-Byte Code:
  4364. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  4365. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  4366. *
  4367. * Returns 0 or an error if the checksum doesn't match
  4368. */
  4369. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  4370. int size, int memsize, int chksum)
  4371. {
  4372. int i, j, end, len = 0;
  4373. ADV_DCNT sum;
  4374. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  4375. for (i = 253 * 2; i < size; i++) {
  4376. if (buf[i] == 0xff) {
  4377. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  4378. for (j = 0; j < buf[i + 1]; j++) {
  4379. AdvWriteWordAutoIncLram(iop_base, word);
  4380. len += 2;
  4381. }
  4382. i += 3;
  4383. } else if (buf[i] == 0xfe) {
  4384. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  4385. AdvWriteWordAutoIncLram(iop_base, word);
  4386. i += 2;
  4387. len += 2;
  4388. } else {
  4389. unsigned int off = buf[i] * 2;
  4390. unsigned short word = (buf[off + 1] << 8) | buf[off];
  4391. AdvWriteWordAutoIncLram(iop_base, word);
  4392. len += 2;
  4393. }
  4394. }
  4395. end = len;
  4396. while (len < memsize) {
  4397. AdvWriteWordAutoIncLram(iop_base, 0);
  4398. len += 2;
  4399. }
  4400. /* Verify the microcode checksum. */
  4401. sum = 0;
  4402. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  4403. for (len = 0; len < end; len += 2) {
  4404. sum += AdvReadWordAutoIncLram(iop_base);
  4405. }
  4406. if (sum != chksum)
  4407. return ASC_IERR_MCODE_CHKSUM;
  4408. return 0;
  4409. }
  4410. static void AdvBuildCarrierFreelist(struct adv_dvc_var *asc_dvc)
  4411. {
  4412. ADV_CARR_T *carrp;
  4413. ADV_SDCNT buf_size;
  4414. ADV_PADDR carr_paddr;
  4415. carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
  4416. asc_dvc->carr_freelist = NULL;
  4417. if (carrp == asc_dvc->carrier_buf) {
  4418. buf_size = ADV_CARRIER_BUFSIZE;
  4419. } else {
  4420. buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
  4421. }
  4422. do {
  4423. /* Get physical address of the carrier 'carrp'. */
  4424. carr_paddr = cpu_to_le32(virt_to_bus(carrp));
  4425. buf_size -= sizeof(ADV_CARR_T);
  4426. carrp->carr_pa = carr_paddr;
  4427. carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
  4428. /*
  4429. * Insert the carrier at the beginning of the freelist.
  4430. */
  4431. carrp->next_vpa =
  4432. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  4433. asc_dvc->carr_freelist = carrp;
  4434. carrp++;
  4435. } while (buf_size > 0);
  4436. }
  4437. /*
  4438. * Send an idle command to the chip and wait for completion.
  4439. *
  4440. * Command completion is polled for once per microsecond.
  4441. *
  4442. * The function can be called from anywhere including an interrupt handler.
  4443. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  4444. * functions to prevent reentrancy.
  4445. *
  4446. * Return Values:
  4447. * ADV_TRUE - command completed successfully
  4448. * ADV_FALSE - command failed
  4449. * ADV_ERROR - command timed out
  4450. */
  4451. static int
  4452. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  4453. ushort idle_cmd, ADV_DCNT idle_cmd_parameter)
  4454. {
  4455. int result;
  4456. ADV_DCNT i, j;
  4457. AdvPortAddr iop_base;
  4458. iop_base = asc_dvc->iop_base;
  4459. /*
  4460. * Clear the idle command status which is set by the microcode
  4461. * to a non-zero value to indicate when the command is completed.
  4462. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  4463. */
  4464. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  4465. /*
  4466. * Write the idle command value after the idle command parameter
  4467. * has been written to avoid a race condition. If the order is not
  4468. * followed, the microcode may process the idle command before the
  4469. * parameters have been written to LRAM.
  4470. */
  4471. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  4472. cpu_to_le32(idle_cmd_parameter));
  4473. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  4474. /*
  4475. * Tickle the RISC to tell it to process the idle command.
  4476. */
  4477. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  4478. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  4479. /*
  4480. * Clear the tickle value. In the ASC-3550 the RISC flag
  4481. * command 'clr_tickle_b' does not work unless the host
  4482. * value is cleared.
  4483. */
  4484. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  4485. }
  4486. /* Wait for up to 100 millisecond for the idle command to timeout. */
  4487. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  4488. /* Poll once each microsecond for command completion. */
  4489. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  4490. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  4491. result);
  4492. if (result != 0)
  4493. return result;
  4494. udelay(1);
  4495. }
  4496. }
  4497. BUG(); /* The idle command should never timeout. */
  4498. return ADV_ERROR;
  4499. }
  4500. /*
  4501. * Reset SCSI Bus and purge all outstanding requests.
  4502. *
  4503. * Return Value:
  4504. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  4505. * ADV_FALSE(0) - Microcode command failed.
  4506. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  4507. * may be hung which requires driver recovery.
  4508. */
  4509. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  4510. {
  4511. int status;
  4512. /*
  4513. * Send the SCSI Bus Reset idle start idle command which asserts
  4514. * the SCSI Bus Reset signal.
  4515. */
  4516. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  4517. if (status != ADV_TRUE) {
  4518. return status;
  4519. }
  4520. /*
  4521. * Delay for the specified SCSI Bus Reset hold time.
  4522. *
  4523. * The hold time delay is done on the host because the RISC has no
  4524. * microsecond accurate timer.
  4525. */
  4526. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  4527. /*
  4528. * Send the SCSI Bus Reset end idle command which de-asserts
  4529. * the SCSI Bus Reset signal and purges any pending requests.
  4530. */
  4531. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  4532. if (status != ADV_TRUE) {
  4533. return status;
  4534. }
  4535. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4536. return status;
  4537. }
  4538. /*
  4539. * Initialize the ASC-3550.
  4540. *
  4541. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4542. *
  4543. * For a non-fatal error return a warning code. If there are no warnings
  4544. * then 0 is returned.
  4545. *
  4546. * Needed after initialization for error recovery.
  4547. */
  4548. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  4549. {
  4550. const struct firmware *fw;
  4551. const char fwname[] = "advansys/3550.bin";
  4552. AdvPortAddr iop_base;
  4553. ushort warn_code;
  4554. int begin_addr;
  4555. int end_addr;
  4556. ushort code_sum;
  4557. int word;
  4558. int i;
  4559. int err;
  4560. unsigned long chksum;
  4561. ushort scsi_cfg1;
  4562. uchar tid;
  4563. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4564. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  4565. uchar max_cmd[ADV_MAX_TID + 1];
  4566. /* If there is already an error, don't continue. */
  4567. if (asc_dvc->err_code != 0)
  4568. return ADV_ERROR;
  4569. /*
  4570. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  4571. */
  4572. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  4573. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4574. return ADV_ERROR;
  4575. }
  4576. warn_code = 0;
  4577. iop_base = asc_dvc->iop_base;
  4578. /*
  4579. * Save the RISC memory BIOS region before writing the microcode.
  4580. * The BIOS may already be loaded and using its RISC LRAM region
  4581. * so its region must be saved and restored.
  4582. *
  4583. * Note: This code makes the assumption, which is currently true,
  4584. * that a chip reset does not clear RISC LRAM.
  4585. */
  4586. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4587. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4588. bios_mem[i]);
  4589. }
  4590. /*
  4591. * Save current per TID negotiated values.
  4592. */
  4593. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  4594. ushort bios_version, major, minor;
  4595. bios_version =
  4596. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  4597. major = (bios_version >> 12) & 0xF;
  4598. minor = (bios_version >> 8) & 0xF;
  4599. if (major < 3 || (major == 3 && minor == 1)) {
  4600. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  4601. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  4602. } else {
  4603. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4604. }
  4605. }
  4606. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4607. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4608. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4609. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4610. max_cmd[tid]);
  4611. }
  4612. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4613. if (err) {
  4614. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4615. fwname, err);
  4616. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4617. return err;
  4618. }
  4619. if (fw->size < 4) {
  4620. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4621. fw->size, fwname);
  4622. release_firmware(fw);
  4623. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4624. return -EINVAL;
  4625. }
  4626. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4627. (fw->data[1] << 8) | fw->data[0];
  4628. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4629. fw->size - 4, ADV_3550_MEMSIZE,
  4630. chksum);
  4631. release_firmware(fw);
  4632. if (asc_dvc->err_code)
  4633. return ADV_ERROR;
  4634. /*
  4635. * Restore the RISC memory BIOS region.
  4636. */
  4637. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4638. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4639. bios_mem[i]);
  4640. }
  4641. /*
  4642. * Calculate and write the microcode code checksum to the microcode
  4643. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4644. */
  4645. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4646. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4647. code_sum = 0;
  4648. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4649. for (word = begin_addr; word < end_addr; word += 2) {
  4650. code_sum += AdvReadWordAutoIncLram(iop_base);
  4651. }
  4652. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4653. /*
  4654. * Read and save microcode version and date.
  4655. */
  4656. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4657. asc_dvc->cfg->mcode_date);
  4658. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4659. asc_dvc->cfg->mcode_version);
  4660. /*
  4661. * Set the chip type to indicate the ASC3550.
  4662. */
  4663. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  4664. /*
  4665. * If the PCI Configuration Command Register "Parity Error Response
  4666. * Control" Bit was clear (0), then set the microcode variable
  4667. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4668. * to ignore DMA parity errors.
  4669. */
  4670. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4671. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4672. word |= CONTROL_FLAG_IGNORE_PERR;
  4673. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4674. }
  4675. /*
  4676. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4677. * threshold of 128 bytes. This register is only accessible to the host.
  4678. */
  4679. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4680. START_CTL_EMFU | READ_CMD_MRM);
  4681. /*
  4682. * Microcode operating variables for WDTR, SDTR, and command tag
  4683. * queuing will be set in slave_configure() based on what a
  4684. * device reports it is capable of in Inquiry byte 7.
  4685. *
  4686. * If SCSI Bus Resets have been disabled, then directly set
  4687. * SDTR and WDTR from the EEPROM configuration. This will allow
  4688. * the BIOS and warm boot to work without a SCSI bus hang on
  4689. * the Inquiry caused by host and target mismatched DTR values.
  4690. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4691. * be assumed to be in Asynchronous, Narrow mode.
  4692. */
  4693. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4694. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4695. asc_dvc->wdtr_able);
  4696. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4697. asc_dvc->sdtr_able);
  4698. }
  4699. /*
  4700. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4701. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4702. * bitmask. These values determine the maximum SDTR speed negotiated
  4703. * with a device.
  4704. *
  4705. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4706. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4707. * without determining here whether the device supports SDTR.
  4708. *
  4709. * 4-bit speed SDTR speed name
  4710. * =========== ===============
  4711. * 0000b (0x0) SDTR disabled
  4712. * 0001b (0x1) 5 Mhz
  4713. * 0010b (0x2) 10 Mhz
  4714. * 0011b (0x3) 20 Mhz (Ultra)
  4715. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4716. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4717. * 0110b (0x6) Undefined
  4718. * .
  4719. * 1111b (0xF) Undefined
  4720. */
  4721. word = 0;
  4722. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4723. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4724. /* Set Ultra speed for TID 'tid'. */
  4725. word |= (0x3 << (4 * (tid % 4)));
  4726. } else {
  4727. /* Set Fast speed for TID 'tid'. */
  4728. word |= (0x2 << (4 * (tid % 4)));
  4729. }
  4730. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4731. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4732. word = 0;
  4733. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4734. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4735. word = 0;
  4736. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4737. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4738. word = 0;
  4739. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4740. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4741. /* End of loop. */
  4742. }
  4743. }
  4744. /*
  4745. * Set microcode operating variable for the disconnect per TID bitmask.
  4746. */
  4747. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4748. asc_dvc->cfg->disc_enable);
  4749. /*
  4750. * Set SCSI_CFG0 Microcode Default Value.
  4751. *
  4752. * The microcode will set the SCSI_CFG0 register using this value
  4753. * after it is started below.
  4754. */
  4755. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4756. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4757. asc_dvc->chip_scsi_id);
  4758. /*
  4759. * Determine SCSI_CFG1 Microcode Default Value.
  4760. *
  4761. * The microcode will set the SCSI_CFG1 register using this value
  4762. * after it is started below.
  4763. */
  4764. /* Read current SCSI_CFG1 Register value. */
  4765. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4766. /*
  4767. * If all three connectors are in use, return an error.
  4768. */
  4769. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4770. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4771. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4772. return ADV_ERROR;
  4773. }
  4774. /*
  4775. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4776. * register signals will be set. Check for and return an error if
  4777. * this condition is found.
  4778. */
  4779. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4780. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4781. return ADV_ERROR;
  4782. }
  4783. /*
  4784. * If this is a differential board and a single-ended device
  4785. * is attached to one of the connectors, return an error.
  4786. */
  4787. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4788. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4789. return ADV_ERROR;
  4790. }
  4791. /*
  4792. * If automatic termination control is enabled, then set the
  4793. * termination value based on a table listed in a_condor.h.
  4794. *
  4795. * If manual termination was specified with an EEPROM setting
  4796. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4797. * is ready to be 'ored' into SCSI_CFG1.
  4798. */
  4799. if (asc_dvc->cfg->termination == 0) {
  4800. /*
  4801. * The software always controls termination by setting TERM_CTL_SEL.
  4802. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4803. */
  4804. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4805. switch (scsi_cfg1 & CABLE_DETECT) {
  4806. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4807. case 0x3:
  4808. case 0x7:
  4809. case 0xB:
  4810. case 0xD:
  4811. case 0xE:
  4812. case 0xF:
  4813. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4814. break;
  4815. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4816. case 0x1:
  4817. case 0x5:
  4818. case 0x9:
  4819. case 0xA:
  4820. case 0xC:
  4821. asc_dvc->cfg->termination |= TERM_CTL_H;
  4822. break;
  4823. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4824. case 0x2:
  4825. case 0x6:
  4826. break;
  4827. }
  4828. }
  4829. /*
  4830. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4831. */
  4832. scsi_cfg1 &= ~TERM_CTL;
  4833. /*
  4834. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4835. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4836. * referenced, because the hardware internally inverts
  4837. * the Termination High and Low bits if TERM_POL is set.
  4838. */
  4839. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4840. /*
  4841. * Set SCSI_CFG1 Microcode Default Value
  4842. *
  4843. * Set filter value and possibly modified termination control
  4844. * bits in the Microcode SCSI_CFG1 Register Value.
  4845. *
  4846. * The microcode will set the SCSI_CFG1 register using this value
  4847. * after it is started below.
  4848. */
  4849. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4850. FLTR_DISABLE | scsi_cfg1);
  4851. /*
  4852. * Set MEM_CFG Microcode Default Value
  4853. *
  4854. * The microcode will set the MEM_CFG register using this value
  4855. * after it is started below.
  4856. *
  4857. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4858. * are defined.
  4859. *
  4860. * ASC-3550 has 8KB internal memory.
  4861. */
  4862. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4863. BIOS_EN | RAM_SZ_8KB);
  4864. /*
  4865. * Set SEL_MASK Microcode Default Value
  4866. *
  4867. * The microcode will set the SEL_MASK register using this value
  4868. * after it is started below.
  4869. */
  4870. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4871. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4872. AdvBuildCarrierFreelist(asc_dvc);
  4873. /*
  4874. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4875. */
  4876. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  4877. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4878. return ADV_ERROR;
  4879. }
  4880. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4881. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  4882. /*
  4883. * The first command issued will be placed in the stopper carrier.
  4884. */
  4885. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4886. /*
  4887. * Set RISC ICQ physical address start value.
  4888. */
  4889. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4890. /*
  4891. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4892. */
  4893. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  4894. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4895. return ADV_ERROR;
  4896. }
  4897. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4898. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  4899. /*
  4900. * The first command completed by the RISC will be placed in
  4901. * the stopper.
  4902. *
  4903. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  4904. * completed the RISC will set the ASC_RQ_STOPPER bit.
  4905. */
  4906. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4907. /*
  4908. * Set RISC IRQ physical address start value.
  4909. */
  4910. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4911. asc_dvc->carr_pending_cnt = 0;
  4912. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4913. (ADV_INTR_ENABLE_HOST_INTR |
  4914. ADV_INTR_ENABLE_GLOBAL_INTR));
  4915. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4916. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4917. /* finally, finally, gentlemen, start your engine */
  4918. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4919. /*
  4920. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4921. * Resets should be performed. The RISC has to be running
  4922. * to issue a SCSI Bus Reset.
  4923. */
  4924. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4925. /*
  4926. * If the BIOS Signature is present in memory, restore the
  4927. * BIOS Handshake Configuration Table and do not perform
  4928. * a SCSI Bus Reset.
  4929. */
  4930. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4931. 0x55AA) {
  4932. /*
  4933. * Restore per TID negotiated values.
  4934. */
  4935. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4936. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4937. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4938. tagqng_able);
  4939. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4940. AdvWriteByteLram(iop_base,
  4941. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4942. max_cmd[tid]);
  4943. }
  4944. } else {
  4945. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4946. warn_code = ASC_WARN_BUSRESET_ERROR;
  4947. }
  4948. }
  4949. }
  4950. return warn_code;
  4951. }
  4952. /*
  4953. * Initialize the ASC-38C0800.
  4954. *
  4955. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4956. *
  4957. * For a non-fatal error return a warning code. If there are no warnings
  4958. * then 0 is returned.
  4959. *
  4960. * Needed after initialization for error recovery.
  4961. */
  4962. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4963. {
  4964. const struct firmware *fw;
  4965. const char fwname[] = "advansys/38C0800.bin";
  4966. AdvPortAddr iop_base;
  4967. ushort warn_code;
  4968. int begin_addr;
  4969. int end_addr;
  4970. ushort code_sum;
  4971. int word;
  4972. int i;
  4973. int err;
  4974. unsigned long chksum;
  4975. ushort scsi_cfg1;
  4976. uchar byte;
  4977. uchar tid;
  4978. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4979. ushort wdtr_able, sdtr_able, tagqng_able;
  4980. uchar max_cmd[ADV_MAX_TID + 1];
  4981. /* If there is already an error, don't continue. */
  4982. if (asc_dvc->err_code != 0)
  4983. return ADV_ERROR;
  4984. /*
  4985. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4986. */
  4987. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4988. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4989. return ADV_ERROR;
  4990. }
  4991. warn_code = 0;
  4992. iop_base = asc_dvc->iop_base;
  4993. /*
  4994. * Save the RISC memory BIOS region before writing the microcode.
  4995. * The BIOS may already be loaded and using its RISC LRAM region
  4996. * so its region must be saved and restored.
  4997. *
  4998. * Note: This code makes the assumption, which is currently true,
  4999. * that a chip reset does not clear RISC LRAM.
  5000. */
  5001. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5002. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5003. bios_mem[i]);
  5004. }
  5005. /*
  5006. * Save current per TID negotiated values.
  5007. */
  5008. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5009. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5010. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5011. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5012. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5013. max_cmd[tid]);
  5014. }
  5015. /*
  5016. * RAM BIST (RAM Built-In Self Test)
  5017. *
  5018. * Address : I/O base + offset 0x38h register (byte).
  5019. * Function: Bit 7-6(RW) : RAM mode
  5020. * Normal Mode : 0x00
  5021. * Pre-test Mode : 0x40
  5022. * RAM Test Mode : 0x80
  5023. * Bit 5 : unused
  5024. * Bit 4(RO) : Done bit
  5025. * Bit 3-0(RO) : Status
  5026. * Host Error : 0x08
  5027. * Int_RAM Error : 0x04
  5028. * RISC Error : 0x02
  5029. * SCSI Error : 0x01
  5030. * No Error : 0x00
  5031. *
  5032. * Note: RAM BIST code should be put right here, before loading the
  5033. * microcode and after saving the RISC memory BIOS region.
  5034. */
  5035. /*
  5036. * LRAM Pre-test
  5037. *
  5038. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5039. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5040. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5041. * to NORMAL_MODE, return an error too.
  5042. */
  5043. for (i = 0; i < 2; i++) {
  5044. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5045. mdelay(10); /* Wait for 10ms before reading back. */
  5046. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5047. if ((byte & RAM_TEST_DONE) == 0
  5048. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5049. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5050. return ADV_ERROR;
  5051. }
  5052. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5053. mdelay(10); /* Wait for 10ms before reading back. */
  5054. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5055. != NORMAL_VALUE) {
  5056. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5057. return ADV_ERROR;
  5058. }
  5059. }
  5060. /*
  5061. * LRAM Test - It takes about 1.5 ms to run through the test.
  5062. *
  5063. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5064. * If Done bit not set or Status not 0, save register byte, set the
  5065. * err_code, and return an error.
  5066. */
  5067. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5068. mdelay(10); /* Wait for 10ms before checking status. */
  5069. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5070. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5071. /* Get here if Done bit not set or Status not 0. */
  5072. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5073. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5074. return ADV_ERROR;
  5075. }
  5076. /* We need to reset back to normal mode after LRAM test passes. */
  5077. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5078. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5079. if (err) {
  5080. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5081. fwname, err);
  5082. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5083. return err;
  5084. }
  5085. if (fw->size < 4) {
  5086. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5087. fw->size, fwname);
  5088. release_firmware(fw);
  5089. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5090. return -EINVAL;
  5091. }
  5092. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5093. (fw->data[1] << 8) | fw->data[0];
  5094. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5095. fw->size - 4, ADV_38C0800_MEMSIZE,
  5096. chksum);
  5097. release_firmware(fw);
  5098. if (asc_dvc->err_code)
  5099. return ADV_ERROR;
  5100. /*
  5101. * Restore the RISC memory BIOS region.
  5102. */
  5103. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5104. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5105. bios_mem[i]);
  5106. }
  5107. /*
  5108. * Calculate and write the microcode code checksum to the microcode
  5109. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5110. */
  5111. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5112. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5113. code_sum = 0;
  5114. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5115. for (word = begin_addr; word < end_addr; word += 2) {
  5116. code_sum += AdvReadWordAutoIncLram(iop_base);
  5117. }
  5118. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5119. /*
  5120. * Read microcode version and date.
  5121. */
  5122. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5123. asc_dvc->cfg->mcode_date);
  5124. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5125. asc_dvc->cfg->mcode_version);
  5126. /*
  5127. * Set the chip type to indicate the ASC38C0800.
  5128. */
  5129. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  5130. /*
  5131. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5132. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5133. * cable detection and then we are able to read C_DET[3:0].
  5134. *
  5135. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5136. * Microcode Default Value' section below.
  5137. */
  5138. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5139. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5140. scsi_cfg1 | DIS_TERM_DRV);
  5141. /*
  5142. * If the PCI Configuration Command Register "Parity Error Response
  5143. * Control" Bit was clear (0), then set the microcode variable
  5144. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5145. * to ignore DMA parity errors.
  5146. */
  5147. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5148. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5149. word |= CONTROL_FLAG_IGNORE_PERR;
  5150. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5151. }
  5152. /*
  5153. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  5154. * bits for the default FIFO threshold.
  5155. *
  5156. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  5157. *
  5158. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  5159. */
  5160. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5161. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  5162. READ_CMD_MRM);
  5163. /*
  5164. * Microcode operating variables for WDTR, SDTR, and command tag
  5165. * queuing will be set in slave_configure() based on what a
  5166. * device reports it is capable of in Inquiry byte 7.
  5167. *
  5168. * If SCSI Bus Resets have been disabled, then directly set
  5169. * SDTR and WDTR from the EEPROM configuration. This will allow
  5170. * the BIOS and warm boot to work without a SCSI bus hang on
  5171. * the Inquiry caused by host and target mismatched DTR values.
  5172. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5173. * be assumed to be in Asynchronous, Narrow mode.
  5174. */
  5175. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5176. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5177. asc_dvc->wdtr_able);
  5178. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5179. asc_dvc->sdtr_able);
  5180. }
  5181. /*
  5182. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5183. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5184. * configuration values.
  5185. *
  5186. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5187. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5188. * without determining here whether the device supports SDTR.
  5189. */
  5190. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5191. asc_dvc->cfg->disc_enable);
  5192. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5193. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5194. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5195. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5196. /*
  5197. * Set SCSI_CFG0 Microcode Default Value.
  5198. *
  5199. * The microcode will set the SCSI_CFG0 register using this value
  5200. * after it is started below.
  5201. */
  5202. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5203. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5204. asc_dvc->chip_scsi_id);
  5205. /*
  5206. * Determine SCSI_CFG1 Microcode Default Value.
  5207. *
  5208. * The microcode will set the SCSI_CFG1 register using this value
  5209. * after it is started below.
  5210. */
  5211. /* Read current SCSI_CFG1 Register value. */
  5212. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5213. /*
  5214. * If the internal narrow cable is reversed all of the SCSI_CTRL
  5215. * register signals will be set. Check for and return an error if
  5216. * this condition is found.
  5217. */
  5218. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5219. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5220. return ADV_ERROR;
  5221. }
  5222. /*
  5223. * All kind of combinations of devices attached to one of four
  5224. * connectors are acceptable except HVD device attached. For example,
  5225. * LVD device can be attached to SE connector while SE device attached
  5226. * to LVD connector. If LVD device attached to SE connector, it only
  5227. * runs up to Ultra speed.
  5228. *
  5229. * If an HVD device is attached to one of LVD connectors, return an
  5230. * error. However, there is no way to detect HVD device attached to
  5231. * SE connectors.
  5232. */
  5233. if (scsi_cfg1 & HVD) {
  5234. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  5235. return ADV_ERROR;
  5236. }
  5237. /*
  5238. * If either SE or LVD automatic termination control is enabled, then
  5239. * set the termination value based on a table listed in a_condor.h.
  5240. *
  5241. * If manual termination was specified with an EEPROM setting then
  5242. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  5243. * to be 'ored' into SCSI_CFG1.
  5244. */
  5245. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5246. /* SE automatic termination control is enabled. */
  5247. switch (scsi_cfg1 & C_DET_SE) {
  5248. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5249. case 0x1:
  5250. case 0x2:
  5251. case 0x3:
  5252. asc_dvc->cfg->termination |= TERM_SE;
  5253. break;
  5254. /* TERM_SE_HI: on, TERM_SE_LO: off */
  5255. case 0x0:
  5256. asc_dvc->cfg->termination |= TERM_SE_HI;
  5257. break;
  5258. }
  5259. }
  5260. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  5261. /* LVD automatic termination control is enabled. */
  5262. switch (scsi_cfg1 & C_DET_LVD) {
  5263. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  5264. case 0x4:
  5265. case 0x8:
  5266. case 0xC:
  5267. asc_dvc->cfg->termination |= TERM_LVD;
  5268. break;
  5269. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  5270. case 0x0:
  5271. break;
  5272. }
  5273. }
  5274. /*
  5275. * Clear any set TERM_SE and TERM_LVD bits.
  5276. */
  5277. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  5278. /*
  5279. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  5280. */
  5281. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  5282. /*
  5283. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  5284. * bits and set possibly modified termination control bits in the
  5285. * Microcode SCSI_CFG1 Register Value.
  5286. */
  5287. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  5288. /*
  5289. * Set SCSI_CFG1 Microcode Default Value
  5290. *
  5291. * Set possibly modified termination control and reset DIS_TERM_DRV
  5292. * bits in the Microcode SCSI_CFG1 Register Value.
  5293. *
  5294. * The microcode will set the SCSI_CFG1 register using this value
  5295. * after it is started below.
  5296. */
  5297. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5298. /*
  5299. * Set MEM_CFG Microcode Default Value
  5300. *
  5301. * The microcode will set the MEM_CFG register using this value
  5302. * after it is started below.
  5303. *
  5304. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5305. * are defined.
  5306. *
  5307. * ASC-38C0800 has 16KB internal memory.
  5308. */
  5309. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5310. BIOS_EN | RAM_SZ_16KB);
  5311. /*
  5312. * Set SEL_MASK Microcode Default Value
  5313. *
  5314. * The microcode will set the SEL_MASK register using this value
  5315. * after it is started below.
  5316. */
  5317. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5318. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5319. AdvBuildCarrierFreelist(asc_dvc);
  5320. /*
  5321. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5322. */
  5323. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5324. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5325. return ADV_ERROR;
  5326. }
  5327. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5328. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5329. /*
  5330. * The first command issued will be placed in the stopper carrier.
  5331. */
  5332. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5333. /*
  5334. * Set RISC ICQ physical address start value.
  5335. * carr_pa is LE, must be native before write
  5336. */
  5337. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5338. /*
  5339. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5340. */
  5341. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5342. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5343. return ADV_ERROR;
  5344. }
  5345. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5346. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5347. /*
  5348. * The first command completed by the RISC will be placed in
  5349. * the stopper.
  5350. *
  5351. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5352. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5353. */
  5354. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5355. /*
  5356. * Set RISC IRQ physical address start value.
  5357. *
  5358. * carr_pa is LE, must be native before write *
  5359. */
  5360. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5361. asc_dvc->carr_pending_cnt = 0;
  5362. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5363. (ADV_INTR_ENABLE_HOST_INTR |
  5364. ADV_INTR_ENABLE_GLOBAL_INTR));
  5365. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5366. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5367. /* finally, finally, gentlemen, start your engine */
  5368. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5369. /*
  5370. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5371. * Resets should be performed. The RISC has to be running
  5372. * to issue a SCSI Bus Reset.
  5373. */
  5374. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5375. /*
  5376. * If the BIOS Signature is present in memory, restore the
  5377. * BIOS Handshake Configuration Table and do not perform
  5378. * a SCSI Bus Reset.
  5379. */
  5380. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5381. 0x55AA) {
  5382. /*
  5383. * Restore per TID negotiated values.
  5384. */
  5385. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5386. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5387. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5388. tagqng_able);
  5389. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5390. AdvWriteByteLram(iop_base,
  5391. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5392. max_cmd[tid]);
  5393. }
  5394. } else {
  5395. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5396. warn_code = ASC_WARN_BUSRESET_ERROR;
  5397. }
  5398. }
  5399. }
  5400. return warn_code;
  5401. }
  5402. /*
  5403. * Initialize the ASC-38C1600.
  5404. *
  5405. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  5406. *
  5407. * For a non-fatal error return a warning code. If there are no warnings
  5408. * then 0 is returned.
  5409. *
  5410. * Needed after initialization for error recovery.
  5411. */
  5412. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  5413. {
  5414. const struct firmware *fw;
  5415. const char fwname[] = "advansys/38C1600.bin";
  5416. AdvPortAddr iop_base;
  5417. ushort warn_code;
  5418. int begin_addr;
  5419. int end_addr;
  5420. ushort code_sum;
  5421. long word;
  5422. int i;
  5423. int err;
  5424. unsigned long chksum;
  5425. ushort scsi_cfg1;
  5426. uchar byte;
  5427. uchar tid;
  5428. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  5429. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  5430. uchar max_cmd[ASC_MAX_TID + 1];
  5431. /* If there is already an error, don't continue. */
  5432. if (asc_dvc->err_code != 0) {
  5433. return ADV_ERROR;
  5434. }
  5435. /*
  5436. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  5437. */
  5438. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  5439. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  5440. return ADV_ERROR;
  5441. }
  5442. warn_code = 0;
  5443. iop_base = asc_dvc->iop_base;
  5444. /*
  5445. * Save the RISC memory BIOS region before writing the microcode.
  5446. * The BIOS may already be loaded and using its RISC LRAM region
  5447. * so its region must be saved and restored.
  5448. *
  5449. * Note: This code makes the assumption, which is currently true,
  5450. * that a chip reset does not clear RISC LRAM.
  5451. */
  5452. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5453. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5454. bios_mem[i]);
  5455. }
  5456. /*
  5457. * Save current per TID negotiated values.
  5458. */
  5459. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5460. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5461. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5462. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5463. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5464. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5465. max_cmd[tid]);
  5466. }
  5467. /*
  5468. * RAM BIST (Built-In Self Test)
  5469. *
  5470. * Address : I/O base + offset 0x38h register (byte).
  5471. * Function: Bit 7-6(RW) : RAM mode
  5472. * Normal Mode : 0x00
  5473. * Pre-test Mode : 0x40
  5474. * RAM Test Mode : 0x80
  5475. * Bit 5 : unused
  5476. * Bit 4(RO) : Done bit
  5477. * Bit 3-0(RO) : Status
  5478. * Host Error : 0x08
  5479. * Int_RAM Error : 0x04
  5480. * RISC Error : 0x02
  5481. * SCSI Error : 0x01
  5482. * No Error : 0x00
  5483. *
  5484. * Note: RAM BIST code should be put right here, before loading the
  5485. * microcode and after saving the RISC memory BIOS region.
  5486. */
  5487. /*
  5488. * LRAM Pre-test
  5489. *
  5490. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5491. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5492. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5493. * to NORMAL_MODE, return an error too.
  5494. */
  5495. for (i = 0; i < 2; i++) {
  5496. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5497. mdelay(10); /* Wait for 10ms before reading back. */
  5498. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5499. if ((byte & RAM_TEST_DONE) == 0
  5500. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5501. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5502. return ADV_ERROR;
  5503. }
  5504. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5505. mdelay(10); /* Wait for 10ms before reading back. */
  5506. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5507. != NORMAL_VALUE) {
  5508. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5509. return ADV_ERROR;
  5510. }
  5511. }
  5512. /*
  5513. * LRAM Test - It takes about 1.5 ms to run through the test.
  5514. *
  5515. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5516. * If Done bit not set or Status not 0, save register byte, set the
  5517. * err_code, and return an error.
  5518. */
  5519. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5520. mdelay(10); /* Wait for 10ms before checking status. */
  5521. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5522. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5523. /* Get here if Done bit not set or Status not 0. */
  5524. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5525. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5526. return ADV_ERROR;
  5527. }
  5528. /* We need to reset back to normal mode after LRAM test passes. */
  5529. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5530. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5531. if (err) {
  5532. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5533. fwname, err);
  5534. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5535. return err;
  5536. }
  5537. if (fw->size < 4) {
  5538. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5539. fw->size, fwname);
  5540. release_firmware(fw);
  5541. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5542. return -EINVAL;
  5543. }
  5544. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5545. (fw->data[1] << 8) | fw->data[0];
  5546. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5547. fw->size - 4, ADV_38C1600_MEMSIZE,
  5548. chksum);
  5549. release_firmware(fw);
  5550. if (asc_dvc->err_code)
  5551. return ADV_ERROR;
  5552. /*
  5553. * Restore the RISC memory BIOS region.
  5554. */
  5555. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5556. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5557. bios_mem[i]);
  5558. }
  5559. /*
  5560. * Calculate and write the microcode code checksum to the microcode
  5561. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5562. */
  5563. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5564. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5565. code_sum = 0;
  5566. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5567. for (word = begin_addr; word < end_addr; word += 2) {
  5568. code_sum += AdvReadWordAutoIncLram(iop_base);
  5569. }
  5570. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5571. /*
  5572. * Read microcode version and date.
  5573. */
  5574. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5575. asc_dvc->cfg->mcode_date);
  5576. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5577. asc_dvc->cfg->mcode_version);
  5578. /*
  5579. * Set the chip type to indicate the ASC38C1600.
  5580. */
  5581. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  5582. /*
  5583. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5584. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5585. * cable detection and then we are able to read C_DET[3:0].
  5586. *
  5587. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5588. * Microcode Default Value' section below.
  5589. */
  5590. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5591. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5592. scsi_cfg1 | DIS_TERM_DRV);
  5593. /*
  5594. * If the PCI Configuration Command Register "Parity Error Response
  5595. * Control" Bit was clear (0), then set the microcode variable
  5596. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5597. * to ignore DMA parity errors.
  5598. */
  5599. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5600. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5601. word |= CONTROL_FLAG_IGNORE_PERR;
  5602. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5603. }
  5604. /*
  5605. * If the BIOS control flag AIPP (Asynchronous Information
  5606. * Phase Protection) disable bit is not set, then set the firmware
  5607. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  5608. * AIPP checking and encoding.
  5609. */
  5610. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  5611. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5612. word |= CONTROL_FLAG_ENABLE_AIPP;
  5613. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5614. }
  5615. /*
  5616. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  5617. * and START_CTL_TH [3:2].
  5618. */
  5619. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5620. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  5621. /*
  5622. * Microcode operating variables for WDTR, SDTR, and command tag
  5623. * queuing will be set in slave_configure() based on what a
  5624. * device reports it is capable of in Inquiry byte 7.
  5625. *
  5626. * If SCSI Bus Resets have been disabled, then directly set
  5627. * SDTR and WDTR from the EEPROM configuration. This will allow
  5628. * the BIOS and warm boot to work without a SCSI bus hang on
  5629. * the Inquiry caused by host and target mismatched DTR values.
  5630. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5631. * be assumed to be in Asynchronous, Narrow mode.
  5632. */
  5633. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5634. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5635. asc_dvc->wdtr_able);
  5636. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5637. asc_dvc->sdtr_able);
  5638. }
  5639. /*
  5640. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5641. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5642. * configuration values.
  5643. *
  5644. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5645. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5646. * without determining here whether the device supports SDTR.
  5647. */
  5648. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5649. asc_dvc->cfg->disc_enable);
  5650. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5651. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5652. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5653. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5654. /*
  5655. * Set SCSI_CFG0 Microcode Default Value.
  5656. *
  5657. * The microcode will set the SCSI_CFG0 register using this value
  5658. * after it is started below.
  5659. */
  5660. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5661. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5662. asc_dvc->chip_scsi_id);
  5663. /*
  5664. * Calculate SCSI_CFG1 Microcode Default Value.
  5665. *
  5666. * The microcode will set the SCSI_CFG1 register using this value
  5667. * after it is started below.
  5668. *
  5669. * Each ASC-38C1600 function has only two cable detect bits.
  5670. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  5671. */
  5672. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5673. /*
  5674. * If the cable is reversed all of the SCSI_CTRL register signals
  5675. * will be set. Check for and return an error if this condition is
  5676. * found.
  5677. */
  5678. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5679. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5680. return ADV_ERROR;
  5681. }
  5682. /*
  5683. * Each ASC-38C1600 function has two connectors. Only an HVD device
  5684. * can not be connected to either connector. An LVD device or SE device
  5685. * may be connected to either connecor. If an SE device is connected,
  5686. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  5687. *
  5688. * If an HVD device is attached, return an error.
  5689. */
  5690. if (scsi_cfg1 & HVD) {
  5691. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5692. return ADV_ERROR;
  5693. }
  5694. /*
  5695. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5696. * termination because there are two connectors for each function. Each
  5697. * function may use either LVD or SE mode. Corresponding the SE automatic
  5698. * termination control EEPROM bits are used for each function. Each
  5699. * function has its own EEPROM. If SE automatic control is enabled for
  5700. * the function, then set the termination value based on a table listed
  5701. * in a_condor.h.
  5702. *
  5703. * If manual termination is specified in the EEPROM for the function,
  5704. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5705. * ready to be 'ored' into SCSI_CFG1.
  5706. */
  5707. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5708. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5709. /* SE automatic termination control is enabled. */
  5710. switch (scsi_cfg1 & C_DET_SE) {
  5711. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5712. case 0x1:
  5713. case 0x2:
  5714. case 0x3:
  5715. asc_dvc->cfg->termination |= TERM_SE;
  5716. break;
  5717. case 0x0:
  5718. if (PCI_FUNC(pdev->devfn) == 0) {
  5719. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5720. } else {
  5721. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5722. asc_dvc->cfg->termination |= TERM_SE_HI;
  5723. }
  5724. break;
  5725. }
  5726. }
  5727. /*
  5728. * Clear any set TERM_SE bits.
  5729. */
  5730. scsi_cfg1 &= ~TERM_SE;
  5731. /*
  5732. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5733. */
  5734. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5735. /*
  5736. * Clear Big Endian and Terminator Polarity bits and set possibly
  5737. * modified termination control bits in the Microcode SCSI_CFG1
  5738. * Register Value.
  5739. *
  5740. * Big Endian bit is not used even on big endian machines.
  5741. */
  5742. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5743. /*
  5744. * Set SCSI_CFG1 Microcode Default Value
  5745. *
  5746. * Set possibly modified termination control bits in the Microcode
  5747. * SCSI_CFG1 Register Value.
  5748. *
  5749. * The microcode will set the SCSI_CFG1 register using this value
  5750. * after it is started below.
  5751. */
  5752. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5753. /*
  5754. * Set MEM_CFG Microcode Default Value
  5755. *
  5756. * The microcode will set the MEM_CFG register using this value
  5757. * after it is started below.
  5758. *
  5759. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5760. * are defined.
  5761. *
  5762. * ASC-38C1600 has 32KB internal memory.
  5763. *
  5764. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5765. * out a special 16K Adv Library and Microcode version. After the issue
  5766. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5767. * mcode.sas files also need to be updated.
  5768. *
  5769. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5770. * BIOS_EN | RAM_SZ_32KB);
  5771. */
  5772. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5773. BIOS_EN | RAM_SZ_16KB);
  5774. /*
  5775. * Set SEL_MASK Microcode Default Value
  5776. *
  5777. * The microcode will set the SEL_MASK register using this value
  5778. * after it is started below.
  5779. */
  5780. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5781. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5782. AdvBuildCarrierFreelist(asc_dvc);
  5783. /*
  5784. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5785. */
  5786. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5787. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5788. return ADV_ERROR;
  5789. }
  5790. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5791. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5792. /*
  5793. * The first command issued will be placed in the stopper carrier.
  5794. */
  5795. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5796. /*
  5797. * Set RISC ICQ physical address start value. Initialize the
  5798. * COMMA register to the same value otherwise the RISC will
  5799. * prematurely detect a command is available.
  5800. */
  5801. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5802. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5803. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5804. /*
  5805. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5806. */
  5807. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5808. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5809. return ADV_ERROR;
  5810. }
  5811. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5812. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5813. /*
  5814. * The first command completed by the RISC will be placed in
  5815. * the stopper.
  5816. *
  5817. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5818. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5819. */
  5820. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5821. /*
  5822. * Set RISC IRQ physical address start value.
  5823. */
  5824. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5825. asc_dvc->carr_pending_cnt = 0;
  5826. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5827. (ADV_INTR_ENABLE_HOST_INTR |
  5828. ADV_INTR_ENABLE_GLOBAL_INTR));
  5829. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5830. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5831. /* finally, finally, gentlemen, start your engine */
  5832. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5833. /*
  5834. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5835. * Resets should be performed. The RISC has to be running
  5836. * to issue a SCSI Bus Reset.
  5837. */
  5838. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5839. /*
  5840. * If the BIOS Signature is present in memory, restore the
  5841. * per TID microcode operating variables.
  5842. */
  5843. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5844. 0x55AA) {
  5845. /*
  5846. * Restore per TID negotiated values.
  5847. */
  5848. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5849. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5850. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5851. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5852. tagqng_able);
  5853. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5854. AdvWriteByteLram(iop_base,
  5855. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5856. max_cmd[tid]);
  5857. }
  5858. } else {
  5859. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5860. warn_code = ASC_WARN_BUSRESET_ERROR;
  5861. }
  5862. }
  5863. }
  5864. return warn_code;
  5865. }
  5866. /*
  5867. * Reset chip and SCSI Bus.
  5868. *
  5869. * Return Value:
  5870. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5871. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5872. */
  5873. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5874. {
  5875. int status;
  5876. ushort wdtr_able, sdtr_able, tagqng_able;
  5877. ushort ppr_able = 0;
  5878. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5879. AdvPortAddr iop_base;
  5880. ushort bios_sig;
  5881. iop_base = asc_dvc->iop_base;
  5882. /*
  5883. * Save current per TID negotiated values.
  5884. */
  5885. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5886. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5887. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5888. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5889. }
  5890. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5891. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5892. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5893. max_cmd[tid]);
  5894. }
  5895. /*
  5896. * Force the AdvInitAsc3550/38C0800Driver() function to
  5897. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5898. * The initialization functions assumes a SCSI Bus Reset is not
  5899. * needed if the BIOS signature word is present.
  5900. */
  5901. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5902. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5903. /*
  5904. * Stop chip and reset it.
  5905. */
  5906. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5907. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5908. mdelay(100);
  5909. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5910. ADV_CTRL_REG_CMD_WR_IO_REG);
  5911. /*
  5912. * Reset Adv Library error code, if any, and try
  5913. * re-initializing the chip.
  5914. */
  5915. asc_dvc->err_code = 0;
  5916. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5917. status = AdvInitAsc38C1600Driver(asc_dvc);
  5918. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5919. status = AdvInitAsc38C0800Driver(asc_dvc);
  5920. } else {
  5921. status = AdvInitAsc3550Driver(asc_dvc);
  5922. }
  5923. /* Translate initialization return value to status value. */
  5924. if (status == 0) {
  5925. status = ADV_TRUE;
  5926. } else {
  5927. status = ADV_FALSE;
  5928. }
  5929. /*
  5930. * Restore the BIOS signature word.
  5931. */
  5932. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5933. /*
  5934. * Restore per TID negotiated values.
  5935. */
  5936. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5937. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5938. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5939. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5940. }
  5941. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5942. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5943. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5944. max_cmd[tid]);
  5945. }
  5946. return status;
  5947. }
  5948. /*
  5949. * adv_async_callback() - Adv Library asynchronous event callback function.
  5950. */
  5951. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5952. {
  5953. switch (code) {
  5954. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5955. /*
  5956. * The firmware detected a SCSI Bus reset.
  5957. */
  5958. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5959. break;
  5960. case ADV_ASYNC_RDMA_FAILURE:
  5961. /*
  5962. * Handle RDMA failure by resetting the SCSI Bus and
  5963. * possibly the chip if it is unresponsive. Log the error
  5964. * with a unique code.
  5965. */
  5966. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5967. AdvResetChipAndSB(adv_dvc_varp);
  5968. break;
  5969. case ADV_HOST_SCSI_BUS_RESET:
  5970. /*
  5971. * Host generated SCSI bus reset occurred.
  5972. */
  5973. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5974. break;
  5975. default:
  5976. ASC_DBG(0, "unknown code 0x%x\n", code);
  5977. break;
  5978. }
  5979. }
  5980. /*
  5981. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5982. *
  5983. * Callback function for the Wide SCSI Adv Library.
  5984. */
  5985. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5986. {
  5987. struct asc_board *boardp;
  5988. adv_req_t *reqp;
  5989. adv_sgblk_t *sgblkp;
  5990. struct scsi_cmnd *scp;
  5991. struct Scsi_Host *shost;
  5992. ADV_DCNT resid_cnt;
  5993. ASC_DBG(1, "adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
  5994. (ulong)adv_dvc_varp, (ulong)scsiqp);
  5995. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5996. /*
  5997. * Get the adv_req_t structure for the command that has been
  5998. * completed. The adv_req_t structure actually contains the
  5999. * completed ADV_SCSI_REQ_Q structure.
  6000. */
  6001. reqp = (adv_req_t *)ADV_U32_TO_VADDR(scsiqp->srb_ptr);
  6002. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  6003. if (reqp == NULL) {
  6004. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  6005. return;
  6006. }
  6007. /*
  6008. * Get the struct scsi_cmnd structure and Scsi_Host structure for the
  6009. * command that has been completed.
  6010. *
  6011. * Note: The adv_req_t request structure and adv_sgblk_t structure,
  6012. * if any, are dropped, because a board structure pointer can not be
  6013. * determined.
  6014. */
  6015. scp = reqp->cmndp;
  6016. ASC_DBG(1, "scp 0x%p\n", scp);
  6017. if (scp == NULL) {
  6018. ASC_PRINT
  6019. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  6020. return;
  6021. }
  6022. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6023. shost = scp->device->host;
  6024. ASC_STATS(shost, callback);
  6025. ASC_DBG(1, "shost 0x%p\n", shost);
  6026. boardp = shost_priv(shost);
  6027. BUG_ON(adv_dvc_varp != &boardp->dvc_var.adv_dvc_var);
  6028. /*
  6029. * 'done_status' contains the command's ending status.
  6030. */
  6031. switch (scsiqp->done_status) {
  6032. case QD_NO_ERROR:
  6033. ASC_DBG(2, "QD_NO_ERROR\n");
  6034. scp->result = 0;
  6035. /*
  6036. * Check for an underrun condition.
  6037. *
  6038. * If there was no error and an underrun condition, then
  6039. * then return the number of underrun bytes.
  6040. */
  6041. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  6042. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  6043. resid_cnt <= scsi_bufflen(scp)) {
  6044. ASC_DBG(1, "underrun condition %lu bytes\n",
  6045. (ulong)resid_cnt);
  6046. scsi_set_resid(scp, resid_cnt);
  6047. }
  6048. break;
  6049. case QD_WITH_ERROR:
  6050. ASC_DBG(2, "QD_WITH_ERROR\n");
  6051. switch (scsiqp->host_status) {
  6052. case QHSTA_NO_ERROR:
  6053. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  6054. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6055. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6056. SCSI_SENSE_BUFFERSIZE);
  6057. /*
  6058. * Note: The 'status_byte()' macro used by
  6059. * target drivers defined in scsi.h shifts the
  6060. * status byte returned by host drivers right
  6061. * by 1 bit. This is why target drivers also
  6062. * use right shifted status byte definitions.
  6063. * For instance target drivers use
  6064. * CHECK_CONDITION, defined to 0x1, instead of
  6065. * the SCSI defined check condition value of
  6066. * 0x2. Host drivers are supposed to return
  6067. * the status byte as it is defined by SCSI.
  6068. */
  6069. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6070. STATUS_BYTE(scsiqp->scsi_status);
  6071. } else {
  6072. scp->result = STATUS_BYTE(scsiqp->scsi_status);
  6073. }
  6074. break;
  6075. default:
  6076. /* Some other QHSTA error occurred. */
  6077. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  6078. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6079. break;
  6080. }
  6081. break;
  6082. case QD_ABORTED_BY_HOST:
  6083. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6084. scp->result =
  6085. HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
  6086. break;
  6087. default:
  6088. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  6089. scp->result =
  6090. HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
  6091. break;
  6092. }
  6093. /*
  6094. * If the 'init_tidmask' bit isn't already set for the target and the
  6095. * current request finished normally, then set the bit for the target
  6096. * to indicate that a device is present.
  6097. */
  6098. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6099. scsiqp->done_status == QD_NO_ERROR &&
  6100. scsiqp->host_status == QHSTA_NO_ERROR) {
  6101. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6102. }
  6103. asc_scsi_done(scp);
  6104. /*
  6105. * Free all 'adv_sgblk_t' structures allocated for the request.
  6106. */
  6107. while ((sgblkp = reqp->sgblkp) != NULL) {
  6108. /* Remove 'sgblkp' from the request list. */
  6109. reqp->sgblkp = sgblkp->next_sgblkp;
  6110. /* Add 'sgblkp' to the board free list. */
  6111. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  6112. boardp->adv_sgblkp = sgblkp;
  6113. }
  6114. /*
  6115. * Free the adv_req_t structure used with the command by adding
  6116. * it back to the board free list.
  6117. */
  6118. reqp->next_reqp = boardp->adv_reqp;
  6119. boardp->adv_reqp = reqp;
  6120. ASC_DBG(1, "done\n");
  6121. }
  6122. /*
  6123. * Adv Library Interrupt Service Routine
  6124. *
  6125. * This function is called by a driver's interrupt service routine.
  6126. * The function disables and re-enables interrupts.
  6127. *
  6128. * When a microcode idle command is completed, the ADV_DVC_VAR
  6129. * 'idle_cmd_done' field is set to ADV_TRUE.
  6130. *
  6131. * Note: AdvISR() can be called when interrupts are disabled or even
  6132. * when there is no hardware interrupt condition present. It will
  6133. * always check for completed idle commands and microcode requests.
  6134. * This is an important feature that shouldn't be changed because it
  6135. * allows commands to be completed from polling mode loops.
  6136. *
  6137. * Return:
  6138. * ADV_TRUE(1) - interrupt was pending
  6139. * ADV_FALSE(0) - no interrupt was pending
  6140. */
  6141. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  6142. {
  6143. AdvPortAddr iop_base;
  6144. uchar int_stat;
  6145. ushort target_bit;
  6146. ADV_CARR_T *free_carrp;
  6147. ADV_VADDR irq_next_vpa;
  6148. ADV_SCSI_REQ_Q *scsiq;
  6149. iop_base = asc_dvc->iop_base;
  6150. /* Reading the register clears the interrupt. */
  6151. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  6152. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  6153. ADV_INTR_STATUS_INTRC)) == 0) {
  6154. return ADV_FALSE;
  6155. }
  6156. /*
  6157. * Notify the driver of an asynchronous microcode condition by
  6158. * calling the adv_async_callback function. The function
  6159. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  6160. */
  6161. if (int_stat & ADV_INTR_STATUS_INTRB) {
  6162. uchar intrb_code;
  6163. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  6164. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  6165. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  6166. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  6167. asc_dvc->carr_pending_cnt != 0) {
  6168. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  6169. ADV_TICKLE_A);
  6170. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  6171. AdvWriteByteRegister(iop_base,
  6172. IOPB_TICKLE,
  6173. ADV_TICKLE_NOP);
  6174. }
  6175. }
  6176. }
  6177. adv_async_callback(asc_dvc, intrb_code);
  6178. }
  6179. /*
  6180. * Check if the IRQ stopper carrier contains a completed request.
  6181. */
  6182. while (((irq_next_vpa =
  6183. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) {
  6184. /*
  6185. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  6186. * The RISC will have set 'areq_vpa' to a virtual address.
  6187. *
  6188. * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
  6189. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  6190. * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
  6191. * in AdvExeScsiQueue().
  6192. */
  6193. scsiq = (ADV_SCSI_REQ_Q *)
  6194. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
  6195. /*
  6196. * Request finished with good status and the queue was not
  6197. * DMAed to host memory by the firmware. Set all status fields
  6198. * to indicate good status.
  6199. */
  6200. if ((irq_next_vpa & ASC_RQ_GOOD) != 0) {
  6201. scsiq->done_status = QD_NO_ERROR;
  6202. scsiq->host_status = scsiq->scsi_status = 0;
  6203. scsiq->data_cnt = 0L;
  6204. }
  6205. /*
  6206. * Advance the stopper pointer to the next carrier
  6207. * ignoring the lower four bits. Free the previous
  6208. * stopper carrier.
  6209. */
  6210. free_carrp = asc_dvc->irq_sp;
  6211. asc_dvc->irq_sp = (ADV_CARR_T *)
  6212. ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
  6213. free_carrp->next_vpa =
  6214. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  6215. asc_dvc->carr_freelist = free_carrp;
  6216. asc_dvc->carr_pending_cnt--;
  6217. target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
  6218. /*
  6219. * Clear request microcode control flag.
  6220. */
  6221. scsiq->cntl = 0;
  6222. /*
  6223. * Notify the driver of the completed request by passing
  6224. * the ADV_SCSI_REQ_Q pointer to its callback function.
  6225. */
  6226. scsiq->a_flag |= ADV_SCSIQ_DONE;
  6227. adv_isr_callback(asc_dvc, scsiq);
  6228. /*
  6229. * Note: After the driver callback function is called, 'scsiq'
  6230. * can no longer be referenced.
  6231. *
  6232. * Fall through and continue processing other completed
  6233. * requests...
  6234. */
  6235. }
  6236. return ADV_TRUE;
  6237. }
  6238. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  6239. {
  6240. if (asc_dvc->err_code == 0) {
  6241. asc_dvc->err_code = err_code;
  6242. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  6243. err_code);
  6244. }
  6245. return err_code;
  6246. }
  6247. static void AscAckInterrupt(PortAddr iop_base)
  6248. {
  6249. uchar host_flag;
  6250. uchar risc_flag;
  6251. ushort loop;
  6252. loop = 0;
  6253. do {
  6254. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  6255. if (loop++ > 0x7FFF) {
  6256. break;
  6257. }
  6258. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  6259. host_flag =
  6260. AscReadLramByte(iop_base,
  6261. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  6262. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6263. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  6264. AscSetChipStatus(iop_base, CIW_INT_ACK);
  6265. loop = 0;
  6266. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  6267. AscSetChipStatus(iop_base, CIW_INT_ACK);
  6268. if (loop++ > 3) {
  6269. break;
  6270. }
  6271. }
  6272. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6273. }
  6274. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  6275. {
  6276. const uchar *period_table;
  6277. int max_index;
  6278. int min_index;
  6279. int i;
  6280. period_table = asc_dvc->sdtr_period_tbl;
  6281. max_index = (int)asc_dvc->max_sdtr_index;
  6282. min_index = (int)asc_dvc->min_sdtr_index;
  6283. if ((syn_time <= period_table[max_index])) {
  6284. for (i = min_index; i < (max_index - 1); i++) {
  6285. if (syn_time <= period_table[i]) {
  6286. return (uchar)i;
  6287. }
  6288. }
  6289. return (uchar)max_index;
  6290. } else {
  6291. return (uchar)(max_index + 1);
  6292. }
  6293. }
  6294. static uchar
  6295. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  6296. {
  6297. EXT_MSG sdtr_buf;
  6298. uchar sdtr_period_index;
  6299. PortAddr iop_base;
  6300. iop_base = asc_dvc->iop_base;
  6301. sdtr_buf.msg_type = EXTENDED_MESSAGE;
  6302. sdtr_buf.msg_len = MS_SDTR_LEN;
  6303. sdtr_buf.msg_req = EXTENDED_SDTR;
  6304. sdtr_buf.xfer_period = sdtr_period;
  6305. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  6306. sdtr_buf.req_ack_offset = sdtr_offset;
  6307. sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  6308. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  6309. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  6310. (uchar *)&sdtr_buf,
  6311. sizeof(EXT_MSG) >> 1);
  6312. return ((sdtr_period_index << 4) | sdtr_offset);
  6313. } else {
  6314. sdtr_buf.req_ack_offset = 0;
  6315. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  6316. (uchar *)&sdtr_buf,
  6317. sizeof(EXT_MSG) >> 1);
  6318. return 0;
  6319. }
  6320. }
  6321. static uchar
  6322. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  6323. {
  6324. uchar byte;
  6325. uchar sdtr_period_ix;
  6326. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  6327. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  6328. return 0xFF;
  6329. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  6330. return byte;
  6331. }
  6332. static int AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  6333. {
  6334. ASC_SCSI_BIT_ID_TYPE org_id;
  6335. int i;
  6336. int sta = TRUE;
  6337. AscSetBank(iop_base, 1);
  6338. org_id = AscReadChipDvcID(iop_base);
  6339. for (i = 0; i <= ASC_MAX_TID; i++) {
  6340. if (org_id == (0x01 << i))
  6341. break;
  6342. }
  6343. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  6344. AscWriteChipDvcID(iop_base, id);
  6345. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  6346. AscSetBank(iop_base, 0);
  6347. AscSetChipSyn(iop_base, sdtr_data);
  6348. if (AscGetChipSyn(iop_base) != sdtr_data) {
  6349. sta = FALSE;
  6350. }
  6351. } else {
  6352. sta = FALSE;
  6353. }
  6354. AscSetBank(iop_base, 1);
  6355. AscWriteChipDvcID(iop_base, org_id);
  6356. AscSetBank(iop_base, 0);
  6357. return (sta);
  6358. }
  6359. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  6360. {
  6361. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6362. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  6363. }
  6364. static int AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  6365. {
  6366. EXT_MSG ext_msg;
  6367. EXT_MSG out_msg;
  6368. ushort halt_q_addr;
  6369. int sdtr_accept;
  6370. ushort int_halt_code;
  6371. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6372. ASC_SCSI_BIT_ID_TYPE target_id;
  6373. PortAddr iop_base;
  6374. uchar tag_code;
  6375. uchar q_status;
  6376. uchar halt_qp;
  6377. uchar sdtr_data;
  6378. uchar target_ix;
  6379. uchar q_cntl, tid_no;
  6380. uchar cur_dvc_qng;
  6381. uchar asyn_sdtr;
  6382. uchar scsi_status;
  6383. struct asc_board *boardp;
  6384. BUG_ON(!asc_dvc->drv_ptr);
  6385. boardp = asc_dvc->drv_ptr;
  6386. iop_base = asc_dvc->iop_base;
  6387. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  6388. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  6389. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  6390. target_ix = AscReadLramByte(iop_base,
  6391. (ushort)(halt_q_addr +
  6392. (ushort)ASC_SCSIQ_B_TARGET_IX));
  6393. q_cntl = AscReadLramByte(iop_base,
  6394. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6395. tid_no = ASC_TIX_TO_TID(target_ix);
  6396. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  6397. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6398. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  6399. } else {
  6400. asyn_sdtr = 0;
  6401. }
  6402. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  6403. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6404. AscSetChipSDTR(iop_base, 0, tid_no);
  6405. boardp->sdtr_data[tid_no] = 0;
  6406. }
  6407. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6408. return (0);
  6409. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  6410. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6411. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6412. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6413. }
  6414. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6415. return (0);
  6416. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  6417. AscMemWordCopyPtrFromLram(iop_base,
  6418. ASCV_MSGIN_BEG,
  6419. (uchar *)&ext_msg,
  6420. sizeof(EXT_MSG) >> 1);
  6421. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6422. ext_msg.msg_req == EXTENDED_SDTR &&
  6423. ext_msg.msg_len == MS_SDTR_LEN) {
  6424. sdtr_accept = TRUE;
  6425. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  6426. sdtr_accept = FALSE;
  6427. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  6428. }
  6429. if ((ext_msg.xfer_period <
  6430. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  6431. || (ext_msg.xfer_period >
  6432. asc_dvc->sdtr_period_tbl[asc_dvc->
  6433. max_sdtr_index])) {
  6434. sdtr_accept = FALSE;
  6435. ext_msg.xfer_period =
  6436. asc_dvc->sdtr_period_tbl[asc_dvc->
  6437. min_sdtr_index];
  6438. }
  6439. if (sdtr_accept) {
  6440. sdtr_data =
  6441. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  6442. ext_msg.req_ack_offset);
  6443. if ((sdtr_data == 0xFF)) {
  6444. q_cntl |= QC_MSG_OUT;
  6445. asc_dvc->init_sdtr &= ~target_id;
  6446. asc_dvc->sdtr_done &= ~target_id;
  6447. AscSetChipSDTR(iop_base, asyn_sdtr,
  6448. tid_no);
  6449. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6450. }
  6451. }
  6452. if (ext_msg.req_ack_offset == 0) {
  6453. q_cntl &= ~QC_MSG_OUT;
  6454. asc_dvc->init_sdtr &= ~target_id;
  6455. asc_dvc->sdtr_done &= ~target_id;
  6456. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6457. } else {
  6458. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  6459. q_cntl &= ~QC_MSG_OUT;
  6460. asc_dvc->sdtr_done |= target_id;
  6461. asc_dvc->init_sdtr |= target_id;
  6462. asc_dvc->pci_fix_asyn_xfer &=
  6463. ~target_id;
  6464. sdtr_data =
  6465. AscCalSDTRData(asc_dvc,
  6466. ext_msg.xfer_period,
  6467. ext_msg.
  6468. req_ack_offset);
  6469. AscSetChipSDTR(iop_base, sdtr_data,
  6470. tid_no);
  6471. boardp->sdtr_data[tid_no] = sdtr_data;
  6472. } else {
  6473. q_cntl |= QC_MSG_OUT;
  6474. AscMsgOutSDTR(asc_dvc,
  6475. ext_msg.xfer_period,
  6476. ext_msg.req_ack_offset);
  6477. asc_dvc->pci_fix_asyn_xfer &=
  6478. ~target_id;
  6479. sdtr_data =
  6480. AscCalSDTRData(asc_dvc,
  6481. ext_msg.xfer_period,
  6482. ext_msg.
  6483. req_ack_offset);
  6484. AscSetChipSDTR(iop_base, sdtr_data,
  6485. tid_no);
  6486. boardp->sdtr_data[tid_no] = sdtr_data;
  6487. asc_dvc->sdtr_done |= target_id;
  6488. asc_dvc->init_sdtr |= target_id;
  6489. }
  6490. }
  6491. AscWriteLramByte(iop_base,
  6492. (ushort)(halt_q_addr +
  6493. (ushort)ASC_SCSIQ_B_CNTL),
  6494. q_cntl);
  6495. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6496. return (0);
  6497. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6498. ext_msg.msg_req == EXTENDED_WDTR &&
  6499. ext_msg.msg_len == MS_WDTR_LEN) {
  6500. ext_msg.wdtr_width = 0;
  6501. AscMemWordCopyPtrToLram(iop_base,
  6502. ASCV_MSGOUT_BEG,
  6503. (uchar *)&ext_msg,
  6504. sizeof(EXT_MSG) >> 1);
  6505. q_cntl |= QC_MSG_OUT;
  6506. AscWriteLramByte(iop_base,
  6507. (ushort)(halt_q_addr +
  6508. (ushort)ASC_SCSIQ_B_CNTL),
  6509. q_cntl);
  6510. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6511. return (0);
  6512. } else {
  6513. ext_msg.msg_type = MESSAGE_REJECT;
  6514. AscMemWordCopyPtrToLram(iop_base,
  6515. ASCV_MSGOUT_BEG,
  6516. (uchar *)&ext_msg,
  6517. sizeof(EXT_MSG) >> 1);
  6518. q_cntl |= QC_MSG_OUT;
  6519. AscWriteLramByte(iop_base,
  6520. (ushort)(halt_q_addr +
  6521. (ushort)ASC_SCSIQ_B_CNTL),
  6522. q_cntl);
  6523. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6524. return (0);
  6525. }
  6526. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  6527. q_cntl |= QC_REQ_SENSE;
  6528. if ((asc_dvc->init_sdtr & target_id) != 0) {
  6529. asc_dvc->sdtr_done &= ~target_id;
  6530. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  6531. q_cntl |= QC_MSG_OUT;
  6532. AscMsgOutSDTR(asc_dvc,
  6533. asc_dvc->
  6534. sdtr_period_tbl[(sdtr_data >> 4) &
  6535. (uchar)(asc_dvc->
  6536. max_sdtr_index -
  6537. 1)],
  6538. (uchar)(sdtr_data & (uchar)
  6539. ASC_SYN_MAX_OFFSET));
  6540. }
  6541. AscWriteLramByte(iop_base,
  6542. (ushort)(halt_q_addr +
  6543. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6544. tag_code = AscReadLramByte(iop_base,
  6545. (ushort)(halt_q_addr + (ushort)
  6546. ASC_SCSIQ_B_TAG_CODE));
  6547. tag_code &= 0xDC;
  6548. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  6549. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  6550. ) {
  6551. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  6552. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  6553. }
  6554. AscWriteLramByte(iop_base,
  6555. (ushort)(halt_q_addr +
  6556. (ushort)ASC_SCSIQ_B_TAG_CODE),
  6557. tag_code);
  6558. q_status = AscReadLramByte(iop_base,
  6559. (ushort)(halt_q_addr + (ushort)
  6560. ASC_SCSIQ_B_STATUS));
  6561. q_status |= (QS_READY | QS_BUSY);
  6562. AscWriteLramByte(iop_base,
  6563. (ushort)(halt_q_addr +
  6564. (ushort)ASC_SCSIQ_B_STATUS),
  6565. q_status);
  6566. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  6567. scsi_busy &= ~target_id;
  6568. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6569. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6570. return (0);
  6571. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  6572. AscMemWordCopyPtrFromLram(iop_base,
  6573. ASCV_MSGOUT_BEG,
  6574. (uchar *)&out_msg,
  6575. sizeof(EXT_MSG) >> 1);
  6576. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  6577. (out_msg.msg_len == MS_SDTR_LEN) &&
  6578. (out_msg.msg_req == EXTENDED_SDTR)) {
  6579. asc_dvc->init_sdtr &= ~target_id;
  6580. asc_dvc->sdtr_done &= ~target_id;
  6581. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6582. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6583. }
  6584. q_cntl &= ~QC_MSG_OUT;
  6585. AscWriteLramByte(iop_base,
  6586. (ushort)(halt_q_addr +
  6587. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6588. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6589. return (0);
  6590. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  6591. scsi_status = AscReadLramByte(iop_base,
  6592. (ushort)((ushort)halt_q_addr +
  6593. (ushort)
  6594. ASC_SCSIQ_SCSI_STATUS));
  6595. cur_dvc_qng =
  6596. AscReadLramByte(iop_base,
  6597. (ushort)((ushort)ASC_QADR_BEG +
  6598. (ushort)target_ix));
  6599. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  6600. scsi_busy = AscReadLramByte(iop_base,
  6601. (ushort)ASCV_SCSIBUSY_B);
  6602. scsi_busy |= target_id;
  6603. AscWriteLramByte(iop_base,
  6604. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6605. asc_dvc->queue_full_or_busy |= target_id;
  6606. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  6607. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  6608. cur_dvc_qng -= 1;
  6609. asc_dvc->max_dvc_qng[tid_no] =
  6610. cur_dvc_qng;
  6611. AscWriteLramByte(iop_base,
  6612. (ushort)((ushort)
  6613. ASCV_MAX_DVC_QNG_BEG
  6614. + (ushort)
  6615. tid_no),
  6616. cur_dvc_qng);
  6617. /*
  6618. * Set the device queue depth to the
  6619. * number of active requests when the
  6620. * QUEUE FULL condition was encountered.
  6621. */
  6622. boardp->queue_full |= target_id;
  6623. boardp->queue_full_cnt[tid_no] =
  6624. cur_dvc_qng;
  6625. }
  6626. }
  6627. }
  6628. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6629. return (0);
  6630. }
  6631. #if CC_VERY_LONG_SG_LIST
  6632. else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) {
  6633. uchar q_no;
  6634. ushort q_addr;
  6635. uchar sg_wk_q_no;
  6636. uchar first_sg_wk_q_no;
  6637. ASC_SCSI_Q *scsiq; /* Ptr to driver request. */
  6638. ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */
  6639. ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */
  6640. ushort sg_list_dwords;
  6641. ushort sg_entry_cnt;
  6642. uchar next_qp;
  6643. int i;
  6644. q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP);
  6645. if (q_no == ASC_QLINK_END)
  6646. return 0;
  6647. q_addr = ASC_QNO_TO_QADDR(q_no);
  6648. /*
  6649. * Convert the request's SRB pointer to a host ASC_SCSI_REQ
  6650. * structure pointer using a macro provided by the driver.
  6651. * The ASC_SCSI_REQ pointer provides a pointer to the
  6652. * host ASC_SG_HEAD structure.
  6653. */
  6654. /* Read request's SRB pointer. */
  6655. scsiq = (ASC_SCSI_Q *)
  6656. ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
  6657. (ushort)
  6658. (q_addr +
  6659. ASC_SCSIQ_D_SRBPTR))));
  6660. /*
  6661. * Get request's first and working SG queue.
  6662. */
  6663. sg_wk_q_no = AscReadLramByte(iop_base,
  6664. (ushort)(q_addr +
  6665. ASC_SCSIQ_B_SG_WK_QP));
  6666. first_sg_wk_q_no = AscReadLramByte(iop_base,
  6667. (ushort)(q_addr +
  6668. ASC_SCSIQ_B_FIRST_SG_WK_QP));
  6669. /*
  6670. * Reset request's working SG queue back to the
  6671. * first SG queue.
  6672. */
  6673. AscWriteLramByte(iop_base,
  6674. (ushort)(q_addr +
  6675. (ushort)ASC_SCSIQ_B_SG_WK_QP),
  6676. first_sg_wk_q_no);
  6677. sg_head = scsiq->sg_head;
  6678. /*
  6679. * Set sg_entry_cnt to the number of SG elements
  6680. * that will be completed on this interrupt.
  6681. *
  6682. * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
  6683. * SG elements. The data_cnt and data_addr fields which
  6684. * add 1 to the SG element capacity are not used when
  6685. * restarting SG handling after a halt.
  6686. */
  6687. if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) {
  6688. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  6689. /*
  6690. * Keep track of remaining number of SG elements that
  6691. * will need to be handled on the next interrupt.
  6692. */
  6693. scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
  6694. } else {
  6695. sg_entry_cnt = scsiq->remain_sg_entry_cnt;
  6696. scsiq->remain_sg_entry_cnt = 0;
  6697. }
  6698. /*
  6699. * Copy SG elements into the list of allocated SG queues.
  6700. *
  6701. * Last index completed is saved in scsiq->next_sg_index.
  6702. */
  6703. next_qp = first_sg_wk_q_no;
  6704. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6705. scsi_sg_q.sg_head_qp = q_no;
  6706. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  6707. for (i = 0; i < sg_head->queue_cnt; i++) {
  6708. scsi_sg_q.seq_no = i + 1;
  6709. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  6710. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  6711. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  6712. /*
  6713. * After very first SG queue RISC FW uses next
  6714. * SG queue first element then checks sg_list_cnt
  6715. * against zero and then decrements, so set
  6716. * sg_list_cnt 1 less than number of SG elements
  6717. * in each SG queue.
  6718. */
  6719. scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
  6720. scsi_sg_q.sg_cur_list_cnt =
  6721. ASC_SG_LIST_PER_Q - 1;
  6722. } else {
  6723. /*
  6724. * This is the last SG queue in the list of
  6725. * allocated SG queues. If there are more
  6726. * SG elements than will fit in the allocated
  6727. * queues, then set the QCSG_SG_XFER_MORE flag.
  6728. */
  6729. if (scsiq->remain_sg_entry_cnt != 0) {
  6730. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  6731. } else {
  6732. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  6733. }
  6734. /* equals sg_entry_cnt * 2 */
  6735. sg_list_dwords = sg_entry_cnt << 1;
  6736. scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
  6737. scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
  6738. sg_entry_cnt = 0;
  6739. }
  6740. scsi_sg_q.q_no = next_qp;
  6741. AscMemWordCopyPtrToLram(iop_base,
  6742. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  6743. (uchar *)&scsi_sg_q,
  6744. sizeof(ASC_SG_LIST_Q) >> 1);
  6745. AscMemDWordCopyPtrToLram(iop_base,
  6746. q_addr + ASC_SGQ_LIST_BEG,
  6747. (uchar *)&sg_head->
  6748. sg_list[scsiq->next_sg_index],
  6749. sg_list_dwords);
  6750. scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
  6751. /*
  6752. * If the just completed SG queue contained the
  6753. * last SG element, then no more SG queues need
  6754. * to be written.
  6755. */
  6756. if (scsi_sg_q.cntl & QCSG_SG_XFER_END) {
  6757. break;
  6758. }
  6759. next_qp = AscReadLramByte(iop_base,
  6760. (ushort)(q_addr +
  6761. ASC_SCSIQ_B_FWD));
  6762. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6763. }
  6764. /*
  6765. * Clear the halt condition so the RISC will be restarted
  6766. * after the return.
  6767. */
  6768. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6769. return (0);
  6770. }
  6771. #endif /* CC_VERY_LONG_SG_LIST */
  6772. return (0);
  6773. }
  6774. /*
  6775. * void
  6776. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6777. *
  6778. * Calling/Exit State:
  6779. * none
  6780. *
  6781. * Description:
  6782. * Input an ASC_QDONE_INFO structure from the chip
  6783. */
  6784. static void
  6785. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6786. {
  6787. int i;
  6788. ushort word;
  6789. AscSetChipLramAddr(iop_base, s_addr);
  6790. for (i = 0; i < 2 * words; i += 2) {
  6791. if (i == 10) {
  6792. continue;
  6793. }
  6794. word = inpw(iop_base + IOP_RAM_DATA);
  6795. inbuf[i] = word & 0xff;
  6796. inbuf[i + 1] = (word >> 8) & 0xff;
  6797. }
  6798. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  6799. }
  6800. static uchar
  6801. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  6802. ushort q_addr,
  6803. ASC_QDONE_INFO *scsiq, ASC_DCNT max_dma_count)
  6804. {
  6805. ushort _val;
  6806. uchar sg_queue_cnt;
  6807. DvcGetQinfo(iop_base,
  6808. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  6809. (uchar *)scsiq,
  6810. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  6811. _val = AscReadLramWord(iop_base,
  6812. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  6813. scsiq->q_status = (uchar)_val;
  6814. scsiq->q_no = (uchar)(_val >> 8);
  6815. _val = AscReadLramWord(iop_base,
  6816. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6817. scsiq->cntl = (uchar)_val;
  6818. sg_queue_cnt = (uchar)(_val >> 8);
  6819. _val = AscReadLramWord(iop_base,
  6820. (ushort)(q_addr +
  6821. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  6822. scsiq->sense_len = (uchar)_val;
  6823. scsiq->extra_bytes = (uchar)(_val >> 8);
  6824. /*
  6825. * Read high word of remain bytes from alternate location.
  6826. */
  6827. scsiq->remain_bytes = (((ADV_DCNT)AscReadLramWord(iop_base,
  6828. (ushort)(q_addr +
  6829. (ushort)
  6830. ASC_SCSIQ_W_ALT_DC1)))
  6831. << 16);
  6832. /*
  6833. * Read low word of remain bytes from original location.
  6834. */
  6835. scsiq->remain_bytes += AscReadLramWord(iop_base,
  6836. (ushort)(q_addr + (ushort)
  6837. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  6838. scsiq->remain_bytes &= max_dma_count;
  6839. return sg_queue_cnt;
  6840. }
  6841. /*
  6842. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  6843. *
  6844. * Interrupt callback function for the Narrow SCSI Asc Library.
  6845. */
  6846. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  6847. {
  6848. struct asc_board *boardp;
  6849. struct scsi_cmnd *scp;
  6850. struct Scsi_Host *shost;
  6851. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  6852. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  6853. scp = advansys_srb_to_ptr(asc_dvc_varp, qdonep->d2.srb_ptr);
  6854. if (!scp)
  6855. return;
  6856. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6857. shost = scp->device->host;
  6858. ASC_STATS(shost, callback);
  6859. ASC_DBG(1, "shost 0x%p\n", shost);
  6860. boardp = shost_priv(shost);
  6861. BUG_ON(asc_dvc_varp != &boardp->dvc_var.asc_dvc_var);
  6862. dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
  6863. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6864. /*
  6865. * 'qdonep' contains the command's ending status.
  6866. */
  6867. switch (qdonep->d3.done_stat) {
  6868. case QD_NO_ERROR:
  6869. ASC_DBG(2, "QD_NO_ERROR\n");
  6870. scp->result = 0;
  6871. /*
  6872. * Check for an underrun condition.
  6873. *
  6874. * If there was no error and an underrun condition, then
  6875. * return the number of underrun bytes.
  6876. */
  6877. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6878. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6879. ASC_DBG(1, "underrun condition %u bytes\n",
  6880. (unsigned)qdonep->remain_bytes);
  6881. scsi_set_resid(scp, qdonep->remain_bytes);
  6882. }
  6883. break;
  6884. case QD_WITH_ERROR:
  6885. ASC_DBG(2, "QD_WITH_ERROR\n");
  6886. switch (qdonep->d3.host_stat) {
  6887. case QHSTA_NO_ERROR:
  6888. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6889. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6890. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6891. SCSI_SENSE_BUFFERSIZE);
  6892. /*
  6893. * Note: The 'status_byte()' macro used by
  6894. * target drivers defined in scsi.h shifts the
  6895. * status byte returned by host drivers right
  6896. * by 1 bit. This is why target drivers also
  6897. * use right shifted status byte definitions.
  6898. * For instance target drivers use
  6899. * CHECK_CONDITION, defined to 0x1, instead of
  6900. * the SCSI defined check condition value of
  6901. * 0x2. Host drivers are supposed to return
  6902. * the status byte as it is defined by SCSI.
  6903. */
  6904. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6905. STATUS_BYTE(qdonep->d3.scsi_stat);
  6906. } else {
  6907. scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
  6908. }
  6909. break;
  6910. default:
  6911. /* QHSTA error occurred */
  6912. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6913. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6914. break;
  6915. }
  6916. break;
  6917. case QD_ABORTED_BY_HOST:
  6918. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6919. scp->result =
  6920. HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
  6921. scsi_msg) |
  6922. STATUS_BYTE(qdonep->d3.scsi_stat);
  6923. break;
  6924. default:
  6925. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6926. scp->result =
  6927. HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
  6928. scsi_msg) |
  6929. STATUS_BYTE(qdonep->d3.scsi_stat);
  6930. break;
  6931. }
  6932. /*
  6933. * If the 'init_tidmask' bit isn't already set for the target and the
  6934. * current request finished normally, then set the bit for the target
  6935. * to indicate that a device is present.
  6936. */
  6937. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6938. qdonep->d3.done_stat == QD_NO_ERROR &&
  6939. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6940. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6941. }
  6942. asc_scsi_done(scp);
  6943. }
  6944. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6945. {
  6946. uchar next_qp;
  6947. uchar n_q_used;
  6948. uchar sg_list_qp;
  6949. uchar sg_queue_cnt;
  6950. uchar q_cnt;
  6951. uchar done_q_tail;
  6952. uchar tid_no;
  6953. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6954. ASC_SCSI_BIT_ID_TYPE target_id;
  6955. PortAddr iop_base;
  6956. ushort q_addr;
  6957. ushort sg_q_addr;
  6958. uchar cur_target_qng;
  6959. ASC_QDONE_INFO scsiq_buf;
  6960. ASC_QDONE_INFO *scsiq;
  6961. int false_overrun;
  6962. iop_base = asc_dvc->iop_base;
  6963. n_q_used = 1;
  6964. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6965. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6966. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6967. next_qp = AscReadLramByte(iop_base,
  6968. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6969. if (next_qp != ASC_QLINK_END) {
  6970. AscPutVarDoneQTail(iop_base, next_qp);
  6971. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6972. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6973. asc_dvc->max_dma_count);
  6974. AscWriteLramByte(iop_base,
  6975. (ushort)(q_addr +
  6976. (ushort)ASC_SCSIQ_B_STATUS),
  6977. (uchar)(scsiq->
  6978. q_status & (uchar)~(QS_READY |
  6979. QS_ABORTED)));
  6980. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6981. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6982. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6983. sg_q_addr = q_addr;
  6984. sg_list_qp = next_qp;
  6985. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6986. sg_list_qp = AscReadLramByte(iop_base,
  6987. (ushort)(sg_q_addr
  6988. + (ushort)
  6989. ASC_SCSIQ_B_FWD));
  6990. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6991. if (sg_list_qp == ASC_QLINK_END) {
  6992. AscSetLibErrorCode(asc_dvc,
  6993. ASCQ_ERR_SG_Q_LINKS);
  6994. scsiq->d3.done_stat = QD_WITH_ERROR;
  6995. scsiq->d3.host_stat =
  6996. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6997. goto FATAL_ERR_QDONE;
  6998. }
  6999. AscWriteLramByte(iop_base,
  7000. (ushort)(sg_q_addr + (ushort)
  7001. ASC_SCSIQ_B_STATUS),
  7002. QS_FREE);
  7003. }
  7004. n_q_used = sg_queue_cnt + 1;
  7005. AscPutVarDoneQTail(iop_base, sg_list_qp);
  7006. }
  7007. if (asc_dvc->queue_full_or_busy & target_id) {
  7008. cur_target_qng = AscReadLramByte(iop_base,
  7009. (ushort)((ushort)
  7010. ASC_QADR_BEG
  7011. + (ushort)
  7012. scsiq->d2.
  7013. target_ix));
  7014. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  7015. scsi_busy = AscReadLramByte(iop_base, (ushort)
  7016. ASCV_SCSIBUSY_B);
  7017. scsi_busy &= ~target_id;
  7018. AscWriteLramByte(iop_base,
  7019. (ushort)ASCV_SCSIBUSY_B,
  7020. scsi_busy);
  7021. asc_dvc->queue_full_or_busy &= ~target_id;
  7022. }
  7023. }
  7024. if (asc_dvc->cur_total_qng >= n_q_used) {
  7025. asc_dvc->cur_total_qng -= n_q_used;
  7026. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  7027. asc_dvc->cur_dvc_qng[tid_no]--;
  7028. }
  7029. } else {
  7030. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  7031. scsiq->d3.done_stat = QD_WITH_ERROR;
  7032. goto FATAL_ERR_QDONE;
  7033. }
  7034. if ((scsiq->d2.srb_ptr == 0UL) ||
  7035. ((scsiq->q_status & QS_ABORTED) != 0)) {
  7036. return (0x11);
  7037. } else if (scsiq->q_status == QS_DONE) {
  7038. false_overrun = FALSE;
  7039. if (scsiq->extra_bytes != 0) {
  7040. scsiq->remain_bytes +=
  7041. (ADV_DCNT)scsiq->extra_bytes;
  7042. }
  7043. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  7044. if (scsiq->d3.host_stat ==
  7045. QHSTA_M_DATA_OVER_RUN) {
  7046. if ((scsiq->
  7047. cntl & (QC_DATA_IN | QC_DATA_OUT))
  7048. == 0) {
  7049. scsiq->d3.done_stat =
  7050. QD_NO_ERROR;
  7051. scsiq->d3.host_stat =
  7052. QHSTA_NO_ERROR;
  7053. } else if (false_overrun) {
  7054. scsiq->d3.done_stat =
  7055. QD_NO_ERROR;
  7056. scsiq->d3.host_stat =
  7057. QHSTA_NO_ERROR;
  7058. }
  7059. } else if (scsiq->d3.host_stat ==
  7060. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  7061. AscStopChip(iop_base);
  7062. AscSetChipControl(iop_base,
  7063. (uchar)(CC_SCSI_RESET
  7064. | CC_HALT));
  7065. udelay(60);
  7066. AscSetChipControl(iop_base, CC_HALT);
  7067. AscSetChipStatus(iop_base,
  7068. CIW_CLR_SCSI_RESET_INT);
  7069. AscSetChipStatus(iop_base, 0);
  7070. AscSetChipControl(iop_base, 0);
  7071. }
  7072. }
  7073. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  7074. asc_isr_callback(asc_dvc, scsiq);
  7075. } else {
  7076. if ((AscReadLramByte(iop_base,
  7077. (ushort)(q_addr + (ushort)
  7078. ASC_SCSIQ_CDB_BEG))
  7079. == START_STOP)) {
  7080. asc_dvc->unit_not_ready &= ~target_id;
  7081. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  7082. asc_dvc->start_motor &=
  7083. ~target_id;
  7084. }
  7085. }
  7086. }
  7087. return (1);
  7088. } else {
  7089. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  7090. FATAL_ERR_QDONE:
  7091. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  7092. asc_isr_callback(asc_dvc, scsiq);
  7093. }
  7094. return (0x80);
  7095. }
  7096. }
  7097. return (0);
  7098. }
  7099. static int AscISR(ASC_DVC_VAR *asc_dvc)
  7100. {
  7101. ASC_CS_TYPE chipstat;
  7102. PortAddr iop_base;
  7103. ushort saved_ram_addr;
  7104. uchar ctrl_reg;
  7105. uchar saved_ctrl_reg;
  7106. int int_pending;
  7107. int status;
  7108. uchar host_flag;
  7109. iop_base = asc_dvc->iop_base;
  7110. int_pending = FALSE;
  7111. if (AscIsIntPending(iop_base) == 0)
  7112. return int_pending;
  7113. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  7114. return ERR;
  7115. }
  7116. if (asc_dvc->in_critical_cnt != 0) {
  7117. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  7118. return ERR;
  7119. }
  7120. if (asc_dvc->is_in_int) {
  7121. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  7122. return ERR;
  7123. }
  7124. asc_dvc->is_in_int = TRUE;
  7125. ctrl_reg = AscGetChipControl(iop_base);
  7126. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  7127. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  7128. chipstat = AscGetChipStatus(iop_base);
  7129. if (chipstat & CSW_SCSI_RESET_LATCH) {
  7130. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  7131. int i = 10;
  7132. int_pending = TRUE;
  7133. asc_dvc->sdtr_done = 0;
  7134. saved_ctrl_reg &= (uchar)(~CC_HALT);
  7135. while ((AscGetChipStatus(iop_base) &
  7136. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  7137. mdelay(100);
  7138. }
  7139. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  7140. AscSetChipControl(iop_base, CC_HALT);
  7141. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  7142. AscSetChipStatus(iop_base, 0);
  7143. chipstat = AscGetChipStatus(iop_base);
  7144. }
  7145. }
  7146. saved_ram_addr = AscGetChipLramAddr(iop_base);
  7147. host_flag = AscReadLramByte(iop_base,
  7148. ASCV_HOST_FLAG_B) &
  7149. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  7150. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  7151. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  7152. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  7153. AscAckInterrupt(iop_base);
  7154. int_pending = TRUE;
  7155. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  7156. if (AscIsrChipHalted(asc_dvc) == ERR) {
  7157. goto ISR_REPORT_QDONE_FATAL_ERROR;
  7158. } else {
  7159. saved_ctrl_reg &= (uchar)(~CC_HALT);
  7160. }
  7161. } else {
  7162. ISR_REPORT_QDONE_FATAL_ERROR:
  7163. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  7164. while (((status =
  7165. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  7166. }
  7167. } else {
  7168. do {
  7169. if ((status =
  7170. AscIsrQDone(asc_dvc)) == 1) {
  7171. break;
  7172. }
  7173. } while (status == 0x11);
  7174. }
  7175. if ((status & 0x80) != 0)
  7176. int_pending = ERR;
  7177. }
  7178. }
  7179. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  7180. AscSetChipLramAddr(iop_base, saved_ram_addr);
  7181. AscSetChipControl(iop_base, saved_ctrl_reg);
  7182. asc_dvc->is_in_int = FALSE;
  7183. return int_pending;
  7184. }
  7185. /*
  7186. * advansys_reset()
  7187. *
  7188. * Reset the bus associated with the command 'scp'.
  7189. *
  7190. * This function runs its own thread. Interrupts must be blocked but
  7191. * sleeping is allowed and no locking other than for host structures is
  7192. * required. Returns SUCCESS or FAILED.
  7193. */
  7194. static int advansys_reset(struct scsi_cmnd *scp)
  7195. {
  7196. struct Scsi_Host *shost = scp->device->host;
  7197. struct asc_board *boardp = shost_priv(shost);
  7198. unsigned long flags;
  7199. int status;
  7200. int ret = SUCCESS;
  7201. ASC_DBG(1, "0x%p\n", scp);
  7202. ASC_STATS(shost, reset);
  7203. scmd_printk(KERN_INFO, scp, "SCSI bus reset started...\n");
  7204. if (ASC_NARROW_BOARD(boardp)) {
  7205. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7206. /* Reset the chip and SCSI bus. */
  7207. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  7208. status = AscInitAsc1000Driver(asc_dvc);
  7209. /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
  7210. if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
  7211. scmd_printk(KERN_INFO, scp, "SCSI bus reset error: "
  7212. "0x%x, status: 0x%x\n", asc_dvc->err_code,
  7213. status);
  7214. ret = FAILED;
  7215. } else if (status) {
  7216. scmd_printk(KERN_INFO, scp, "SCSI bus reset warning: "
  7217. "0x%x\n", status);
  7218. } else {
  7219. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  7220. "successful\n");
  7221. }
  7222. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  7223. spin_lock_irqsave(shost->host_lock, flags);
  7224. } else {
  7225. /*
  7226. * If the suggest reset bus flags are set, then reset the bus.
  7227. * Otherwise only reset the device.
  7228. */
  7229. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  7230. /*
  7231. * Reset the target's SCSI bus.
  7232. */
  7233. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  7234. switch (AdvResetChipAndSB(adv_dvc)) {
  7235. case ASC_TRUE:
  7236. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  7237. "successful\n");
  7238. break;
  7239. case ASC_FALSE:
  7240. default:
  7241. scmd_printk(KERN_INFO, scp, "SCSI bus reset error\n");
  7242. ret = FAILED;
  7243. break;
  7244. }
  7245. spin_lock_irqsave(shost->host_lock, flags);
  7246. AdvISR(adv_dvc);
  7247. }
  7248. /* Save the time of the most recently completed reset. */
  7249. boardp->last_reset = jiffies;
  7250. spin_unlock_irqrestore(shost->host_lock, flags);
  7251. ASC_DBG(1, "ret %d\n", ret);
  7252. return ret;
  7253. }
  7254. /*
  7255. * advansys_biosparam()
  7256. *
  7257. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  7258. * support is enabled for a drive.
  7259. *
  7260. * ip (information pointer) is an int array with the following definition:
  7261. * ip[0]: heads
  7262. * ip[1]: sectors
  7263. * ip[2]: cylinders
  7264. */
  7265. static int
  7266. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  7267. sector_t capacity, int ip[])
  7268. {
  7269. struct asc_board *boardp = shost_priv(sdev->host);
  7270. ASC_DBG(1, "begin\n");
  7271. ASC_STATS(sdev->host, biosparam);
  7272. if (ASC_NARROW_BOARD(boardp)) {
  7273. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  7274. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  7275. ip[0] = 255;
  7276. ip[1] = 63;
  7277. } else {
  7278. ip[0] = 64;
  7279. ip[1] = 32;
  7280. }
  7281. } else {
  7282. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  7283. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  7284. ip[0] = 255;
  7285. ip[1] = 63;
  7286. } else {
  7287. ip[0] = 64;
  7288. ip[1] = 32;
  7289. }
  7290. }
  7291. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  7292. ASC_DBG(1, "end\n");
  7293. return 0;
  7294. }
  7295. /*
  7296. * First-level interrupt handler.
  7297. *
  7298. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  7299. */
  7300. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  7301. {
  7302. struct Scsi_Host *shost = dev_id;
  7303. struct asc_board *boardp = shost_priv(shost);
  7304. irqreturn_t result = IRQ_NONE;
  7305. ASC_DBG(2, "boardp 0x%p\n", boardp);
  7306. spin_lock(shost->host_lock);
  7307. if (ASC_NARROW_BOARD(boardp)) {
  7308. if (AscIsIntPending(shost->io_port)) {
  7309. result = IRQ_HANDLED;
  7310. ASC_STATS(shost, interrupt);
  7311. ASC_DBG(1, "before AscISR()\n");
  7312. AscISR(&boardp->dvc_var.asc_dvc_var);
  7313. }
  7314. } else {
  7315. ASC_DBG(1, "before AdvISR()\n");
  7316. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  7317. result = IRQ_HANDLED;
  7318. ASC_STATS(shost, interrupt);
  7319. }
  7320. }
  7321. spin_unlock(shost->host_lock);
  7322. ASC_DBG(1, "end\n");
  7323. return result;
  7324. }
  7325. static int AscHostReqRiscHalt(PortAddr iop_base)
  7326. {
  7327. int count = 0;
  7328. int sta = 0;
  7329. uchar saved_stop_code;
  7330. if (AscIsChipHalted(iop_base))
  7331. return (1);
  7332. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  7333. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  7334. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  7335. do {
  7336. if (AscIsChipHalted(iop_base)) {
  7337. sta = 1;
  7338. break;
  7339. }
  7340. mdelay(100);
  7341. } while (count++ < 20);
  7342. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  7343. return (sta);
  7344. }
  7345. static int
  7346. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  7347. {
  7348. int sta = FALSE;
  7349. if (AscHostReqRiscHalt(iop_base)) {
  7350. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  7351. AscStartChip(iop_base);
  7352. }
  7353. return sta;
  7354. }
  7355. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  7356. {
  7357. char type = sdev->type;
  7358. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  7359. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  7360. return;
  7361. if (asc_dvc->init_sdtr & tid_bits)
  7362. return;
  7363. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  7364. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  7365. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  7366. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  7367. (type == TYPE_ROM) || (type == TYPE_TAPE))
  7368. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  7369. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  7370. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  7371. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  7372. }
  7373. static void
  7374. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  7375. {
  7376. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  7377. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  7378. if (sdev->lun == 0) {
  7379. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  7380. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  7381. asc_dvc->init_sdtr |= tid_bit;
  7382. } else {
  7383. asc_dvc->init_sdtr &= ~tid_bit;
  7384. }
  7385. if (orig_init_sdtr != asc_dvc->init_sdtr)
  7386. AscAsyncFix(asc_dvc, sdev);
  7387. }
  7388. if (sdev->tagged_supported) {
  7389. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  7390. if (sdev->lun == 0) {
  7391. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  7392. asc_dvc->use_tagged_qng |= tid_bit;
  7393. }
  7394. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7395. asc_dvc->max_dvc_qng[sdev->id]);
  7396. }
  7397. } else {
  7398. if (sdev->lun == 0) {
  7399. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  7400. asc_dvc->use_tagged_qng &= ~tid_bit;
  7401. }
  7402. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7403. }
  7404. if ((sdev->lun == 0) &&
  7405. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  7406. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  7407. asc_dvc->cfg->disc_enable);
  7408. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  7409. asc_dvc->use_tagged_qng);
  7410. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  7411. asc_dvc->cfg->can_tagged_qng);
  7412. asc_dvc->max_dvc_qng[sdev->id] =
  7413. asc_dvc->cfg->max_tag_qng[sdev->id];
  7414. AscWriteLramByte(asc_dvc->iop_base,
  7415. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  7416. asc_dvc->max_dvc_qng[sdev->id]);
  7417. }
  7418. }
  7419. /*
  7420. * Wide Transfers
  7421. *
  7422. * If the EEPROM enabled WDTR for the device and the device supports wide
  7423. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  7424. * write the new value to the microcode.
  7425. */
  7426. static void
  7427. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  7428. {
  7429. unsigned short cfg_word;
  7430. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  7431. if ((cfg_word & tidmask) != 0)
  7432. return;
  7433. cfg_word |= tidmask;
  7434. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  7435. /*
  7436. * Clear the microcode SDTR and WDTR negotiation done indicators for
  7437. * the target to cause it to negotiate with the new setting set above.
  7438. * WDTR when accepted causes the target to enter asynchronous mode, so
  7439. * SDTR must be negotiated.
  7440. */
  7441. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7442. cfg_word &= ~tidmask;
  7443. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7444. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  7445. cfg_word &= ~tidmask;
  7446. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  7447. }
  7448. /*
  7449. * Synchronous Transfers
  7450. *
  7451. * If the EEPROM enabled SDTR for the device and the device
  7452. * supports synchronous transfers, then turn on the device's
  7453. * 'sdtr_able' bit. Write the new value to the microcode.
  7454. */
  7455. static void
  7456. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  7457. {
  7458. unsigned short cfg_word;
  7459. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  7460. if ((cfg_word & tidmask) != 0)
  7461. return;
  7462. cfg_word |= tidmask;
  7463. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  7464. /*
  7465. * Clear the microcode "SDTR negotiation" done indicator for the
  7466. * target to cause it to negotiate with the new setting set above.
  7467. */
  7468. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7469. cfg_word &= ~tidmask;
  7470. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7471. }
  7472. /*
  7473. * PPR (Parallel Protocol Request) Capable
  7474. *
  7475. * If the device supports DT mode, then it must be PPR capable.
  7476. * The PPR message will be used in place of the SDTR and WDTR
  7477. * messages to negotiate synchronous speed and offset, transfer
  7478. * width, and protocol options.
  7479. */
  7480. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  7481. AdvPortAddr iop_base, unsigned short tidmask)
  7482. {
  7483. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7484. adv_dvc->ppr_able |= tidmask;
  7485. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7486. }
  7487. static void
  7488. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  7489. {
  7490. AdvPortAddr iop_base = adv_dvc->iop_base;
  7491. unsigned short tidmask = 1 << sdev->id;
  7492. if (sdev->lun == 0) {
  7493. /*
  7494. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  7495. * is enabled in the EEPROM and the device supports the
  7496. * feature, then enable it in the microcode.
  7497. */
  7498. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  7499. advansys_wide_enable_wdtr(iop_base, tidmask);
  7500. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  7501. advansys_wide_enable_sdtr(iop_base, tidmask);
  7502. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  7503. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  7504. /*
  7505. * Tag Queuing is disabled for the BIOS which runs in polled
  7506. * mode and would see no benefit from Tag Queuing. Also by
  7507. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  7508. * bugs will at least work with the BIOS.
  7509. */
  7510. if ((adv_dvc->tagqng_able & tidmask) &&
  7511. sdev->tagged_supported) {
  7512. unsigned short cfg_word;
  7513. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  7514. cfg_word |= tidmask;
  7515. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  7516. cfg_word);
  7517. AdvWriteByteLram(iop_base,
  7518. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  7519. adv_dvc->max_dvc_qng);
  7520. }
  7521. }
  7522. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) {
  7523. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7524. adv_dvc->max_dvc_qng);
  7525. } else {
  7526. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7527. }
  7528. }
  7529. /*
  7530. * Set the number of commands to queue per device for the
  7531. * specified host adapter.
  7532. */
  7533. static int advansys_slave_configure(struct scsi_device *sdev)
  7534. {
  7535. struct asc_board *boardp = shost_priv(sdev->host);
  7536. if (ASC_NARROW_BOARD(boardp))
  7537. advansys_narrow_slave_configure(sdev,
  7538. &boardp->dvc_var.asc_dvc_var);
  7539. else
  7540. advansys_wide_slave_configure(sdev,
  7541. &boardp->dvc_var.adv_dvc_var);
  7542. return 0;
  7543. }
  7544. static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
  7545. {
  7546. struct asc_board *board = shost_priv(scp->device->host);
  7547. scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  7548. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7549. dma_cache_sync(board->dev, scp->sense_buffer,
  7550. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7551. return cpu_to_le32(scp->SCp.dma_handle);
  7552. }
  7553. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7554. struct asc_scsi_q *asc_scsi_q)
  7555. {
  7556. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7557. int use_sg;
  7558. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  7559. /*
  7560. * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
  7561. */
  7562. asc_scsi_q->q2.srb_ptr = advansys_ptr_to_srb(asc_dvc, scp);
  7563. if (asc_scsi_q->q2.srb_ptr == BAD_SRB) {
  7564. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7565. return ASC_ERROR;
  7566. }
  7567. /*
  7568. * Build the ASC_SCSI_Q request.
  7569. */
  7570. asc_scsi_q->cdbptr = &scp->cmnd[0];
  7571. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  7572. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  7573. asc_scsi_q->q1.target_lun = scp->device->lun;
  7574. asc_scsi_q->q2.target_ix =
  7575. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  7576. asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
  7577. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  7578. /*
  7579. * If there are any outstanding requests for the current target,
  7580. * then every 255th request send an ORDERED request. This heuristic
  7581. * tries to retain the benefit of request sorting while preventing
  7582. * request starvation. 255 is the max number of tags or pending commands
  7583. * a device may have outstanding.
  7584. *
  7585. * The request count is incremented below for every successfully
  7586. * started request.
  7587. *
  7588. */
  7589. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  7590. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  7591. asc_scsi_q->q2.tag_code = MSG_ORDERED_TAG;
  7592. } else {
  7593. asc_scsi_q->q2.tag_code = MSG_SIMPLE_TAG;
  7594. }
  7595. /* Build ASC_SCSI_Q */
  7596. use_sg = scsi_dma_map(scp);
  7597. if (use_sg != 0) {
  7598. int sgcnt;
  7599. struct scatterlist *slp;
  7600. struct asc_sg_head *asc_sg_head;
  7601. if (use_sg > scp->device->host->sg_tablesize) {
  7602. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7603. "sg_tablesize %d\n", use_sg,
  7604. scp->device->host->sg_tablesize);
  7605. scsi_dma_unmap(scp);
  7606. scp->result = HOST_BYTE(DID_ERROR);
  7607. return ASC_ERROR;
  7608. }
  7609. asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
  7610. use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
  7611. if (!asc_sg_head) {
  7612. scsi_dma_unmap(scp);
  7613. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7614. return ASC_ERROR;
  7615. }
  7616. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  7617. asc_scsi_q->sg_head = asc_sg_head;
  7618. asc_scsi_q->q1.data_cnt = 0;
  7619. asc_scsi_q->q1.data_addr = 0;
  7620. /* This is a byte value, otherwise it would need to be swapped. */
  7621. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  7622. ASC_STATS_ADD(scp->device->host, xfer_elem,
  7623. asc_sg_head->entry_cnt);
  7624. /*
  7625. * Convert scatter-gather list into ASC_SG_HEAD list.
  7626. */
  7627. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  7628. asc_sg_head->sg_list[sgcnt].addr =
  7629. cpu_to_le32(sg_dma_address(slp));
  7630. asc_sg_head->sg_list[sgcnt].bytes =
  7631. cpu_to_le32(sg_dma_len(slp));
  7632. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7633. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7634. }
  7635. }
  7636. ASC_STATS(scp->device->host, xfer_cnt);
  7637. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  7638. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7639. return ASC_NOERROR;
  7640. }
  7641. /*
  7642. * Build scatter-gather list for Adv Library (Wide Board).
  7643. *
  7644. * Additional ADV_SG_BLOCK structures will need to be allocated
  7645. * if the total number of scatter-gather elements exceeds
  7646. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  7647. * assumed to be physically contiguous.
  7648. *
  7649. * Return:
  7650. * ADV_SUCCESS(1) - SG List successfully created
  7651. * ADV_ERROR(-1) - SG List creation failed
  7652. */
  7653. static int
  7654. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp, struct scsi_cmnd *scp,
  7655. int use_sg)
  7656. {
  7657. adv_sgblk_t *sgblkp;
  7658. ADV_SCSI_REQ_Q *scsiqp;
  7659. struct scatterlist *slp;
  7660. int sg_elem_cnt;
  7661. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  7662. ADV_PADDR sg_block_paddr;
  7663. int i;
  7664. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7665. slp = scsi_sglist(scp);
  7666. sg_elem_cnt = use_sg;
  7667. prev_sg_block = NULL;
  7668. reqp->sgblkp = NULL;
  7669. for (;;) {
  7670. /*
  7671. * Allocate a 'adv_sgblk_t' structure from the board free
  7672. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  7673. * (15) scatter-gather elements.
  7674. */
  7675. if ((sgblkp = boardp->adv_sgblkp) == NULL) {
  7676. ASC_DBG(1, "no free adv_sgblk_t\n");
  7677. ASC_STATS(scp->device->host, adv_build_nosg);
  7678. /*
  7679. * Allocation failed. Free 'adv_sgblk_t' structures
  7680. * already allocated for the request.
  7681. */
  7682. while ((sgblkp = reqp->sgblkp) != NULL) {
  7683. /* Remove 'sgblkp' from the request list. */
  7684. reqp->sgblkp = sgblkp->next_sgblkp;
  7685. /* Add 'sgblkp' to the board free list. */
  7686. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  7687. boardp->adv_sgblkp = sgblkp;
  7688. }
  7689. return ASC_BUSY;
  7690. }
  7691. /* Complete 'adv_sgblk_t' board allocation. */
  7692. boardp->adv_sgblkp = sgblkp->next_sgblkp;
  7693. sgblkp->next_sgblkp = NULL;
  7694. /*
  7695. * Get 8 byte aligned virtual and physical addresses
  7696. * for the allocated ADV_SG_BLOCK structure.
  7697. */
  7698. sg_block = (ADV_SG_BLOCK *)ADV_8BALIGN(&sgblkp->sg_block);
  7699. sg_block_paddr = virt_to_bus(sg_block);
  7700. /*
  7701. * Check if this is the first 'adv_sgblk_t' for the
  7702. * request.
  7703. */
  7704. if (reqp->sgblkp == NULL) {
  7705. /* Request's first scatter-gather block. */
  7706. reqp->sgblkp = sgblkp;
  7707. /*
  7708. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  7709. * address pointers.
  7710. */
  7711. scsiqp->sg_list_ptr = sg_block;
  7712. scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
  7713. } else {
  7714. /* Request's second or later scatter-gather block. */
  7715. sgblkp->next_sgblkp = reqp->sgblkp;
  7716. reqp->sgblkp = sgblkp;
  7717. /*
  7718. * Point the previous ADV_SG_BLOCK structure to
  7719. * the newly allocated ADV_SG_BLOCK structure.
  7720. */
  7721. prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
  7722. }
  7723. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  7724. sg_block->sg_list[i].sg_addr =
  7725. cpu_to_le32(sg_dma_address(slp));
  7726. sg_block->sg_list[i].sg_count =
  7727. cpu_to_le32(sg_dma_len(slp));
  7728. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7729. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7730. if (--sg_elem_cnt == 0) { /* Last ADV_SG_BLOCK and scatter-gather entry. */
  7731. sg_block->sg_cnt = i + 1;
  7732. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  7733. return ADV_SUCCESS;
  7734. }
  7735. slp++;
  7736. }
  7737. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  7738. prev_sg_block = sg_block;
  7739. }
  7740. }
  7741. /*
  7742. * Build a request structure for the Adv Library (Wide Board).
  7743. *
  7744. * If an adv_req_t can not be allocated to issue the request,
  7745. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  7746. *
  7747. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
  7748. * microcode for DMA addresses or math operations are byte swapped
  7749. * to little-endian order.
  7750. */
  7751. static int
  7752. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7753. ADV_SCSI_REQ_Q **adv_scsiqpp)
  7754. {
  7755. adv_req_t *reqp;
  7756. ADV_SCSI_REQ_Q *scsiqp;
  7757. int i;
  7758. int ret;
  7759. int use_sg;
  7760. /*
  7761. * Allocate an adv_req_t structure from the board to execute
  7762. * the command.
  7763. */
  7764. if (boardp->adv_reqp == NULL) {
  7765. ASC_DBG(1, "no free adv_req_t\n");
  7766. ASC_STATS(scp->device->host, adv_build_noreq);
  7767. return ASC_BUSY;
  7768. } else {
  7769. reqp = boardp->adv_reqp;
  7770. boardp->adv_reqp = reqp->next_reqp;
  7771. reqp->next_reqp = NULL;
  7772. }
  7773. /*
  7774. * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
  7775. */
  7776. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7777. /*
  7778. * Initialize the structure.
  7779. */
  7780. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  7781. /*
  7782. * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
  7783. */
  7784. scsiqp->srb_ptr = ADV_VADDR_TO_U32(reqp);
  7785. /*
  7786. * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
  7787. */
  7788. reqp->cmndp = scp;
  7789. /*
  7790. * Build the ADV_SCSI_REQ_Q request.
  7791. */
  7792. /* Set CDB length and copy it to the request structure. */
  7793. scsiqp->cdb_len = scp->cmd_len;
  7794. /* Copy first 12 CDB bytes to cdb[]. */
  7795. for (i = 0; i < scp->cmd_len && i < 12; i++) {
  7796. scsiqp->cdb[i] = scp->cmnd[i];
  7797. }
  7798. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  7799. for (; i < scp->cmd_len; i++) {
  7800. scsiqp->cdb16[i - 12] = scp->cmnd[i];
  7801. }
  7802. scsiqp->target_id = scp->device->id;
  7803. scsiqp->target_lun = scp->device->lun;
  7804. scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
  7805. scsiqp->sense_len = SCSI_SENSE_BUFFERSIZE;
  7806. /* Build ADV_SCSI_REQ_Q */
  7807. use_sg = scsi_dma_map(scp);
  7808. if (use_sg == 0) {
  7809. /* Zero-length transfer */
  7810. reqp->sgblkp = NULL;
  7811. scsiqp->data_cnt = 0;
  7812. scsiqp->vdata_addr = NULL;
  7813. scsiqp->data_addr = 0;
  7814. scsiqp->sg_list_ptr = NULL;
  7815. scsiqp->sg_real_addr = 0;
  7816. } else {
  7817. if (use_sg > ADV_MAX_SG_LIST) {
  7818. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7819. "ADV_MAX_SG_LIST %d\n", use_sg,
  7820. scp->device->host->sg_tablesize);
  7821. scsi_dma_unmap(scp);
  7822. scp->result = HOST_BYTE(DID_ERROR);
  7823. /*
  7824. * Free the 'adv_req_t' structure by adding it back
  7825. * to the board free list.
  7826. */
  7827. reqp->next_reqp = boardp->adv_reqp;
  7828. boardp->adv_reqp = reqp;
  7829. return ASC_ERROR;
  7830. }
  7831. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  7832. ret = adv_get_sglist(boardp, reqp, scp, use_sg);
  7833. if (ret != ADV_SUCCESS) {
  7834. /*
  7835. * Free the adv_req_t structure by adding it back to
  7836. * the board free list.
  7837. */
  7838. reqp->next_reqp = boardp->adv_reqp;
  7839. boardp->adv_reqp = reqp;
  7840. return ret;
  7841. }
  7842. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  7843. }
  7844. ASC_STATS(scp->device->host, xfer_cnt);
  7845. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  7846. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7847. *adv_scsiqpp = scsiqp;
  7848. return ASC_NOERROR;
  7849. }
  7850. static int AscSgListToQueue(int sg_list)
  7851. {
  7852. int n_sg_list_qs;
  7853. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  7854. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  7855. n_sg_list_qs++;
  7856. return n_sg_list_qs + 1;
  7857. }
  7858. static uint
  7859. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  7860. {
  7861. uint cur_used_qs;
  7862. uint cur_free_qs;
  7863. ASC_SCSI_BIT_ID_TYPE target_id;
  7864. uchar tid_no;
  7865. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  7866. tid_no = ASC_TIX_TO_TID(target_ix);
  7867. if ((asc_dvc->unit_not_ready & target_id) ||
  7868. (asc_dvc->queue_full_or_busy & target_id)) {
  7869. return 0;
  7870. }
  7871. if (n_qs == 1) {
  7872. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7873. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  7874. } else {
  7875. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7876. (uint) ASC_MIN_FREE_Q;
  7877. }
  7878. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  7879. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  7880. if (asc_dvc->cur_dvc_qng[tid_no] >=
  7881. asc_dvc->max_dvc_qng[tid_no]) {
  7882. return 0;
  7883. }
  7884. return cur_free_qs;
  7885. }
  7886. if (n_qs > 1) {
  7887. if ((n_qs > asc_dvc->last_q_shortage)
  7888. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  7889. asc_dvc->last_q_shortage = n_qs;
  7890. }
  7891. }
  7892. return 0;
  7893. }
  7894. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7895. {
  7896. ushort q_addr;
  7897. uchar next_qp;
  7898. uchar q_status;
  7899. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7900. q_status = (uchar)AscReadLramByte(iop_base,
  7901. (ushort)(q_addr +
  7902. ASC_SCSIQ_B_STATUS));
  7903. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7904. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7905. return next_qp;
  7906. return ASC_QLINK_END;
  7907. }
  7908. static uchar
  7909. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7910. {
  7911. uchar i;
  7912. for (i = 0; i < n_free_q; i++) {
  7913. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7914. if (free_q_head == ASC_QLINK_END)
  7915. break;
  7916. }
  7917. return free_q_head;
  7918. }
  7919. /*
  7920. * void
  7921. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7922. *
  7923. * Calling/Exit State:
  7924. * none
  7925. *
  7926. * Description:
  7927. * Output an ASC_SCSI_Q structure to the chip
  7928. */
  7929. static void
  7930. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7931. {
  7932. int i;
  7933. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7934. AscSetChipLramAddr(iop_base, s_addr);
  7935. for (i = 0; i < 2 * words; i += 2) {
  7936. if (i == 4 || i == 20) {
  7937. continue;
  7938. }
  7939. outpw(iop_base + IOP_RAM_DATA,
  7940. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7941. }
  7942. }
  7943. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7944. {
  7945. ushort q_addr;
  7946. uchar tid_no;
  7947. uchar sdtr_data;
  7948. uchar syn_period_ix;
  7949. uchar syn_offset;
  7950. PortAddr iop_base;
  7951. iop_base = asc_dvc->iop_base;
  7952. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7953. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7954. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7955. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7956. syn_period_ix =
  7957. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7958. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7959. AscMsgOutSDTR(asc_dvc,
  7960. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7961. syn_offset);
  7962. scsiq->q1.cntl |= QC_MSG_OUT;
  7963. }
  7964. q_addr = ASC_QNO_TO_QADDR(q_no);
  7965. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7966. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  7967. }
  7968. scsiq->q1.status = QS_FREE;
  7969. AscMemWordCopyPtrToLram(iop_base,
  7970. q_addr + ASC_SCSIQ_CDB_BEG,
  7971. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7972. DvcPutScsiQ(iop_base,
  7973. q_addr + ASC_SCSIQ_CPY_BEG,
  7974. (uchar *)&scsiq->q1.cntl,
  7975. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7976. AscWriteLramWord(iop_base,
  7977. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7978. (ushort)(((ushort)scsiq->q1.
  7979. q_no << 8) | (ushort)QS_READY));
  7980. return 1;
  7981. }
  7982. static int
  7983. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7984. {
  7985. int sta;
  7986. int i;
  7987. ASC_SG_HEAD *sg_head;
  7988. ASC_SG_LIST_Q scsi_sg_q;
  7989. ASC_DCNT saved_data_addr;
  7990. ASC_DCNT saved_data_cnt;
  7991. PortAddr iop_base;
  7992. ushort sg_list_dwords;
  7993. ushort sg_index;
  7994. ushort sg_entry_cnt;
  7995. ushort q_addr;
  7996. uchar next_qp;
  7997. iop_base = asc_dvc->iop_base;
  7998. sg_head = scsiq->sg_head;
  7999. saved_data_addr = scsiq->q1.data_addr;
  8000. saved_data_cnt = scsiq->q1.data_cnt;
  8001. scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
  8002. scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
  8003. #if CC_VERY_LONG_SG_LIST
  8004. /*
  8005. * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
  8006. * then not all SG elements will fit in the allocated queues.
  8007. * The rest of the SG elements will be copied when the RISC
  8008. * completes the SG elements that fit and halts.
  8009. */
  8010. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  8011. /*
  8012. * Set sg_entry_cnt to be the number of SG elements that
  8013. * will fit in the allocated SG queues. It is minus 1, because
  8014. * the first SG element is handled above. ASC_MAX_SG_LIST is
  8015. * already inflated by 1 to account for this. For example it
  8016. * may be 50 which is 1 + 7 queues * 7 SG elements.
  8017. */
  8018. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  8019. /*
  8020. * Keep track of remaining number of SG elements that will
  8021. * need to be handled from a_isr.c.
  8022. */
  8023. scsiq->remain_sg_entry_cnt =
  8024. sg_head->entry_cnt - ASC_MAX_SG_LIST;
  8025. } else {
  8026. #endif /* CC_VERY_LONG_SG_LIST */
  8027. /*
  8028. * Set sg_entry_cnt to be the number of SG elements that
  8029. * will fit in the allocated SG queues. It is minus 1, because
  8030. * the first SG element is handled above.
  8031. */
  8032. sg_entry_cnt = sg_head->entry_cnt - 1;
  8033. #if CC_VERY_LONG_SG_LIST
  8034. }
  8035. #endif /* CC_VERY_LONG_SG_LIST */
  8036. if (sg_entry_cnt != 0) {
  8037. scsiq->q1.cntl |= QC_SG_HEAD;
  8038. q_addr = ASC_QNO_TO_QADDR(q_no);
  8039. sg_index = 1;
  8040. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  8041. scsi_sg_q.sg_head_qp = q_no;
  8042. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  8043. for (i = 0; i < sg_head->queue_cnt; i++) {
  8044. scsi_sg_q.seq_no = i + 1;
  8045. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  8046. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  8047. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  8048. if (i == 0) {
  8049. scsi_sg_q.sg_list_cnt =
  8050. ASC_SG_LIST_PER_Q;
  8051. scsi_sg_q.sg_cur_list_cnt =
  8052. ASC_SG_LIST_PER_Q;
  8053. } else {
  8054. scsi_sg_q.sg_list_cnt =
  8055. ASC_SG_LIST_PER_Q - 1;
  8056. scsi_sg_q.sg_cur_list_cnt =
  8057. ASC_SG_LIST_PER_Q - 1;
  8058. }
  8059. } else {
  8060. #if CC_VERY_LONG_SG_LIST
  8061. /*
  8062. * This is the last SG queue in the list of
  8063. * allocated SG queues. If there are more
  8064. * SG elements than will fit in the allocated
  8065. * queues, then set the QCSG_SG_XFER_MORE flag.
  8066. */
  8067. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  8068. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  8069. } else {
  8070. #endif /* CC_VERY_LONG_SG_LIST */
  8071. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  8072. #if CC_VERY_LONG_SG_LIST
  8073. }
  8074. #endif /* CC_VERY_LONG_SG_LIST */
  8075. sg_list_dwords = sg_entry_cnt << 1;
  8076. if (i == 0) {
  8077. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  8078. scsi_sg_q.sg_cur_list_cnt =
  8079. sg_entry_cnt;
  8080. } else {
  8081. scsi_sg_q.sg_list_cnt =
  8082. sg_entry_cnt - 1;
  8083. scsi_sg_q.sg_cur_list_cnt =
  8084. sg_entry_cnt - 1;
  8085. }
  8086. sg_entry_cnt = 0;
  8087. }
  8088. next_qp = AscReadLramByte(iop_base,
  8089. (ushort)(q_addr +
  8090. ASC_SCSIQ_B_FWD));
  8091. scsi_sg_q.q_no = next_qp;
  8092. q_addr = ASC_QNO_TO_QADDR(next_qp);
  8093. AscMemWordCopyPtrToLram(iop_base,
  8094. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  8095. (uchar *)&scsi_sg_q,
  8096. sizeof(ASC_SG_LIST_Q) >> 1);
  8097. AscMemDWordCopyPtrToLram(iop_base,
  8098. q_addr + ASC_SGQ_LIST_BEG,
  8099. (uchar *)&sg_head->
  8100. sg_list[sg_index],
  8101. sg_list_dwords);
  8102. sg_index += ASC_SG_LIST_PER_Q;
  8103. scsiq->next_sg_index = sg_index;
  8104. }
  8105. } else {
  8106. scsiq->q1.cntl &= ~QC_SG_HEAD;
  8107. }
  8108. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  8109. scsiq->q1.data_addr = saved_data_addr;
  8110. scsiq->q1.data_cnt = saved_data_cnt;
  8111. return (sta);
  8112. }
  8113. static int
  8114. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  8115. {
  8116. PortAddr iop_base;
  8117. uchar free_q_head;
  8118. uchar next_qp;
  8119. uchar tid_no;
  8120. uchar target_ix;
  8121. int sta;
  8122. iop_base = asc_dvc->iop_base;
  8123. target_ix = scsiq->q2.target_ix;
  8124. tid_no = ASC_TIX_TO_TID(target_ix);
  8125. sta = 0;
  8126. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  8127. if (n_q_required > 1) {
  8128. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  8129. (uchar)n_q_required);
  8130. if (next_qp != ASC_QLINK_END) {
  8131. asc_dvc->last_q_shortage = 0;
  8132. scsiq->sg_head->queue_cnt = n_q_required - 1;
  8133. scsiq->q1.q_no = free_q_head;
  8134. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  8135. free_q_head);
  8136. }
  8137. } else if (n_q_required == 1) {
  8138. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  8139. if (next_qp != ASC_QLINK_END) {
  8140. scsiq->q1.q_no = free_q_head;
  8141. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  8142. }
  8143. }
  8144. if (sta == 1) {
  8145. AscPutVarFreeQHead(iop_base, next_qp);
  8146. asc_dvc->cur_total_qng += n_q_required;
  8147. asc_dvc->cur_dvc_qng[tid_no]++;
  8148. }
  8149. return sta;
  8150. }
  8151. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  8152. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  8153. INQUIRY,
  8154. REQUEST_SENSE,
  8155. READ_CAPACITY,
  8156. READ_TOC,
  8157. MODE_SELECT,
  8158. MODE_SENSE,
  8159. MODE_SELECT_10,
  8160. MODE_SENSE_10,
  8161. 0xFF,
  8162. 0xFF,
  8163. 0xFF,
  8164. 0xFF,
  8165. 0xFF,
  8166. 0xFF,
  8167. 0xFF,
  8168. 0xFF
  8169. };
  8170. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  8171. {
  8172. PortAddr iop_base;
  8173. int sta;
  8174. int n_q_required;
  8175. int disable_syn_offset_one_fix;
  8176. int i;
  8177. ASC_PADDR addr;
  8178. ushort sg_entry_cnt = 0;
  8179. ushort sg_entry_cnt_minus_one = 0;
  8180. uchar target_ix;
  8181. uchar tid_no;
  8182. uchar sdtr_data;
  8183. uchar extra_bytes;
  8184. uchar scsi_cmd;
  8185. uchar disable_cmd;
  8186. ASC_SG_HEAD *sg_head;
  8187. ASC_DCNT data_cnt;
  8188. iop_base = asc_dvc->iop_base;
  8189. sg_head = scsiq->sg_head;
  8190. if (asc_dvc->err_code != 0)
  8191. return (ERR);
  8192. scsiq->q1.q_no = 0;
  8193. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  8194. scsiq->q1.extra_bytes = 0;
  8195. }
  8196. sta = 0;
  8197. target_ix = scsiq->q2.target_ix;
  8198. tid_no = ASC_TIX_TO_TID(target_ix);
  8199. n_q_required = 1;
  8200. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  8201. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  8202. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  8203. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  8204. AscMsgOutSDTR(asc_dvc,
  8205. asc_dvc->
  8206. sdtr_period_tbl[(sdtr_data >> 4) &
  8207. (uchar)(asc_dvc->
  8208. max_sdtr_index -
  8209. 1)],
  8210. (uchar)(sdtr_data & (uchar)
  8211. ASC_SYN_MAX_OFFSET));
  8212. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  8213. }
  8214. }
  8215. if (asc_dvc->in_critical_cnt != 0) {
  8216. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  8217. return (ERR);
  8218. }
  8219. asc_dvc->in_critical_cnt++;
  8220. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  8221. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  8222. asc_dvc->in_critical_cnt--;
  8223. return (ERR);
  8224. }
  8225. #if !CC_VERY_LONG_SG_LIST
  8226. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  8227. asc_dvc->in_critical_cnt--;
  8228. return (ERR);
  8229. }
  8230. #endif /* !CC_VERY_LONG_SG_LIST */
  8231. if (sg_entry_cnt == 1) {
  8232. scsiq->q1.data_addr =
  8233. (ADV_PADDR)sg_head->sg_list[0].addr;
  8234. scsiq->q1.data_cnt =
  8235. (ADV_DCNT)sg_head->sg_list[0].bytes;
  8236. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  8237. }
  8238. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  8239. }
  8240. scsi_cmd = scsiq->cdbptr[0];
  8241. disable_syn_offset_one_fix = FALSE;
  8242. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  8243. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  8244. if (scsiq->q1.cntl & QC_SG_HEAD) {
  8245. data_cnt = 0;
  8246. for (i = 0; i < sg_entry_cnt; i++) {
  8247. data_cnt +=
  8248. (ADV_DCNT)le32_to_cpu(sg_head->sg_list[i].
  8249. bytes);
  8250. }
  8251. } else {
  8252. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  8253. }
  8254. if (data_cnt != 0UL) {
  8255. if (data_cnt < 512UL) {
  8256. disable_syn_offset_one_fix = TRUE;
  8257. } else {
  8258. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  8259. i++) {
  8260. disable_cmd =
  8261. _syn_offset_one_disable_cmd[i];
  8262. if (disable_cmd == 0xFF) {
  8263. break;
  8264. }
  8265. if (scsi_cmd == disable_cmd) {
  8266. disable_syn_offset_one_fix =
  8267. TRUE;
  8268. break;
  8269. }
  8270. }
  8271. }
  8272. }
  8273. }
  8274. if (disable_syn_offset_one_fix) {
  8275. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  8276. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  8277. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  8278. } else {
  8279. scsiq->q2.tag_code &= 0x27;
  8280. }
  8281. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  8282. if (asc_dvc->bug_fix_cntl) {
  8283. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  8284. if ((scsi_cmd == READ_6) ||
  8285. (scsi_cmd == READ_10)) {
  8286. addr =
  8287. (ADV_PADDR)le32_to_cpu(sg_head->
  8288. sg_list
  8289. [sg_entry_cnt_minus_one].
  8290. addr) +
  8291. (ADV_DCNT)le32_to_cpu(sg_head->
  8292. sg_list
  8293. [sg_entry_cnt_minus_one].
  8294. bytes);
  8295. extra_bytes =
  8296. (uchar)((ushort)addr & 0x0003);
  8297. if ((extra_bytes != 0)
  8298. &&
  8299. ((scsiq->q2.
  8300. tag_code &
  8301. ASC_TAG_FLAG_EXTRA_BYTES)
  8302. == 0)) {
  8303. scsiq->q2.tag_code |=
  8304. ASC_TAG_FLAG_EXTRA_BYTES;
  8305. scsiq->q1.extra_bytes =
  8306. extra_bytes;
  8307. data_cnt =
  8308. le32_to_cpu(sg_head->
  8309. sg_list
  8310. [sg_entry_cnt_minus_one].
  8311. bytes);
  8312. data_cnt -=
  8313. (ASC_DCNT) extra_bytes;
  8314. sg_head->
  8315. sg_list
  8316. [sg_entry_cnt_minus_one].
  8317. bytes =
  8318. cpu_to_le32(data_cnt);
  8319. }
  8320. }
  8321. }
  8322. }
  8323. sg_head->entry_to_copy = sg_head->entry_cnt;
  8324. #if CC_VERY_LONG_SG_LIST
  8325. /*
  8326. * Set the sg_entry_cnt to the maximum possible. The rest of
  8327. * the SG elements will be copied when the RISC completes the
  8328. * SG elements that fit and halts.
  8329. */
  8330. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  8331. sg_entry_cnt = ASC_MAX_SG_LIST;
  8332. }
  8333. #endif /* CC_VERY_LONG_SG_LIST */
  8334. n_q_required = AscSgListToQueue(sg_entry_cnt);
  8335. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  8336. (uint) n_q_required)
  8337. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  8338. if ((sta =
  8339. AscSendScsiQueue(asc_dvc, scsiq,
  8340. n_q_required)) == 1) {
  8341. asc_dvc->in_critical_cnt--;
  8342. return (sta);
  8343. }
  8344. }
  8345. } else {
  8346. if (asc_dvc->bug_fix_cntl) {
  8347. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  8348. if ((scsi_cmd == READ_6) ||
  8349. (scsi_cmd == READ_10)) {
  8350. addr =
  8351. le32_to_cpu(scsiq->q1.data_addr) +
  8352. le32_to_cpu(scsiq->q1.data_cnt);
  8353. extra_bytes =
  8354. (uchar)((ushort)addr & 0x0003);
  8355. if ((extra_bytes != 0)
  8356. &&
  8357. ((scsiq->q2.
  8358. tag_code &
  8359. ASC_TAG_FLAG_EXTRA_BYTES)
  8360. == 0)) {
  8361. data_cnt =
  8362. le32_to_cpu(scsiq->q1.
  8363. data_cnt);
  8364. if (((ushort)data_cnt & 0x01FF)
  8365. == 0) {
  8366. scsiq->q2.tag_code |=
  8367. ASC_TAG_FLAG_EXTRA_BYTES;
  8368. data_cnt -= (ASC_DCNT)
  8369. extra_bytes;
  8370. scsiq->q1.data_cnt =
  8371. cpu_to_le32
  8372. (data_cnt);
  8373. scsiq->q1.extra_bytes =
  8374. extra_bytes;
  8375. }
  8376. }
  8377. }
  8378. }
  8379. }
  8380. n_q_required = 1;
  8381. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  8382. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  8383. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  8384. n_q_required)) == 1) {
  8385. asc_dvc->in_critical_cnt--;
  8386. return (sta);
  8387. }
  8388. }
  8389. }
  8390. asc_dvc->in_critical_cnt--;
  8391. return (sta);
  8392. }
  8393. /*
  8394. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  8395. *
  8396. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  8397. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  8398. * RISC to notify it a new command is ready to be executed.
  8399. *
  8400. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  8401. * set to SCSI_MAX_RETRY.
  8402. *
  8403. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
  8404. * for DMA addresses or math operations are byte swapped to little-endian
  8405. * order.
  8406. *
  8407. * Return:
  8408. * ADV_SUCCESS(1) - The request was successfully queued.
  8409. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  8410. * request completes.
  8411. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  8412. * host IC error.
  8413. */
  8414. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq)
  8415. {
  8416. AdvPortAddr iop_base;
  8417. ADV_PADDR req_paddr;
  8418. ADV_CARR_T *new_carrp;
  8419. /*
  8420. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  8421. */
  8422. if (scsiq->target_id > ADV_MAX_TID) {
  8423. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  8424. scsiq->done_status = QD_WITH_ERROR;
  8425. return ADV_ERROR;
  8426. }
  8427. iop_base = asc_dvc->iop_base;
  8428. /*
  8429. * Allocate a carrier ensuring at least one carrier always
  8430. * remains on the freelist and initialize fields.
  8431. */
  8432. if ((new_carrp = asc_dvc->carr_freelist) == NULL) {
  8433. return ADV_BUSY;
  8434. }
  8435. asc_dvc->carr_freelist = (ADV_CARR_T *)
  8436. ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
  8437. asc_dvc->carr_pending_cnt++;
  8438. /*
  8439. * Set the carrier to be a stopper by setting 'next_vpa'
  8440. * to the stopper value. The current stopper will be changed
  8441. * below to point to the new stopper.
  8442. */
  8443. new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  8444. /*
  8445. * Clear the ADV_SCSI_REQ_Q done flag.
  8446. */
  8447. scsiq->a_flag &= ~ADV_SCSIQ_DONE;
  8448. req_paddr = virt_to_bus(scsiq);
  8449. BUG_ON(req_paddr & 31);
  8450. /* Wait for assertion before making little-endian */
  8451. req_paddr = cpu_to_le32(req_paddr);
  8452. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  8453. scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
  8454. scsiq->scsiq_rptr = req_paddr;
  8455. scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
  8456. /*
  8457. * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
  8458. * order during initialization.
  8459. */
  8460. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  8461. /*
  8462. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  8463. * the microcode. The newly allocated stopper will become the new
  8464. * stopper.
  8465. */
  8466. asc_dvc->icq_sp->areq_vpa = req_paddr;
  8467. /*
  8468. * Set the 'next_vpa' pointer for the old stopper to be the
  8469. * physical address of the new stopper. The RISC can only
  8470. * follow physical addresses.
  8471. */
  8472. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  8473. /*
  8474. * Set the host adapter stopper pointer to point to the new carrier.
  8475. */
  8476. asc_dvc->icq_sp = new_carrp;
  8477. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  8478. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  8479. /*
  8480. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  8481. */
  8482. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  8483. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  8484. /*
  8485. * Clear the tickle value. In the ASC-3550 the RISC flag
  8486. * command 'clr_tickle_a' does not work unless the host
  8487. * value is cleared.
  8488. */
  8489. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  8490. ADV_TICKLE_NOP);
  8491. }
  8492. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  8493. /*
  8494. * Notify the RISC a carrier is ready by writing the physical
  8495. * address of the new carrier stopper to the COMMA register.
  8496. */
  8497. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  8498. le32_to_cpu(new_carrp->carr_pa));
  8499. }
  8500. return ADV_SUCCESS;
  8501. }
  8502. /*
  8503. * Execute a single 'Scsi_Cmnd'.
  8504. */
  8505. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  8506. {
  8507. int ret, err_code;
  8508. struct asc_board *boardp = shost_priv(scp->device->host);
  8509. ASC_DBG(1, "scp 0x%p\n", scp);
  8510. if (ASC_NARROW_BOARD(boardp)) {
  8511. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  8512. struct asc_scsi_q asc_scsi_q;
  8513. /* asc_build_req() can not return ASC_BUSY. */
  8514. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  8515. if (ret == ASC_ERROR) {
  8516. ASC_STATS(scp->device->host, build_error);
  8517. return ASC_ERROR;
  8518. }
  8519. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  8520. kfree(asc_scsi_q.sg_head);
  8521. err_code = asc_dvc->err_code;
  8522. } else {
  8523. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  8524. ADV_SCSI_REQ_Q *adv_scsiqp;
  8525. switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
  8526. case ASC_NOERROR:
  8527. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  8528. break;
  8529. case ASC_BUSY:
  8530. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  8531. /*
  8532. * The asc_stats fields 'adv_build_noreq' and
  8533. * 'adv_build_nosg' count wide board busy conditions.
  8534. * They are updated in adv_build_req and
  8535. * adv_get_sglist, respectively.
  8536. */
  8537. return ASC_BUSY;
  8538. case ASC_ERROR:
  8539. default:
  8540. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  8541. ASC_STATS(scp->device->host, build_error);
  8542. return ASC_ERROR;
  8543. }
  8544. ret = AdvExeScsiQueue(adv_dvc, adv_scsiqp);
  8545. err_code = adv_dvc->err_code;
  8546. }
  8547. switch (ret) {
  8548. case ASC_NOERROR:
  8549. ASC_STATS(scp->device->host, exe_noerror);
  8550. /*
  8551. * Increment monotonically increasing per device
  8552. * successful request counter. Wrapping doesn't matter.
  8553. */
  8554. boardp->reqcnt[scp->device->id]++;
  8555. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  8556. break;
  8557. case ASC_BUSY:
  8558. ASC_STATS(scp->device->host, exe_busy);
  8559. break;
  8560. case ASC_ERROR:
  8561. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  8562. "err_code 0x%x\n", err_code);
  8563. ASC_STATS(scp->device->host, exe_error);
  8564. scp->result = HOST_BYTE(DID_ERROR);
  8565. break;
  8566. default:
  8567. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  8568. "err_code 0x%x\n", err_code);
  8569. ASC_STATS(scp->device->host, exe_unknown);
  8570. scp->result = HOST_BYTE(DID_ERROR);
  8571. break;
  8572. }
  8573. ASC_DBG(1, "end\n");
  8574. return ret;
  8575. }
  8576. /*
  8577. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  8578. *
  8579. * This function always returns 0. Command return status is saved
  8580. * in the 'scp' result field.
  8581. */
  8582. static int
  8583. advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
  8584. {
  8585. struct Scsi_Host *shost = scp->device->host;
  8586. int asc_res, result = 0;
  8587. ASC_STATS(shost, queuecommand);
  8588. scp->scsi_done = done;
  8589. asc_res = asc_execute_scsi_cmnd(scp);
  8590. switch (asc_res) {
  8591. case ASC_NOERROR:
  8592. break;
  8593. case ASC_BUSY:
  8594. result = SCSI_MLQUEUE_HOST_BUSY;
  8595. break;
  8596. case ASC_ERROR:
  8597. default:
  8598. asc_scsi_done(scp);
  8599. break;
  8600. }
  8601. return result;
  8602. }
  8603. static DEF_SCSI_QCMD(advansys_queuecommand)
  8604. static ushort __devinit AscGetEisaChipCfg(PortAddr iop_base)
  8605. {
  8606. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8607. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  8608. return inpw(eisa_cfg_iop);
  8609. }
  8610. /*
  8611. * Return the BIOS address of the adapter at the specified
  8612. * I/O port and with the specified bus type.
  8613. */
  8614. static unsigned short __devinit
  8615. AscGetChipBiosAddress(PortAddr iop_base, unsigned short bus_type)
  8616. {
  8617. unsigned short cfg_lsw;
  8618. unsigned short bios_addr;
  8619. /*
  8620. * The PCI BIOS is re-located by the motherboard BIOS. Because
  8621. * of this the driver can not determine where a PCI BIOS is
  8622. * loaded and executes.
  8623. */
  8624. if (bus_type & ASC_IS_PCI)
  8625. return 0;
  8626. if ((bus_type & ASC_IS_EISA) != 0) {
  8627. cfg_lsw = AscGetEisaChipCfg(iop_base);
  8628. cfg_lsw &= 0x000F;
  8629. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  8630. return bios_addr;
  8631. }
  8632. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8633. /*
  8634. * ISA PnP uses the top bit as the 32K BIOS flag
  8635. */
  8636. if (bus_type == ASC_IS_ISAPNP)
  8637. cfg_lsw &= 0x7FFF;
  8638. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  8639. return bios_addr;
  8640. }
  8641. static uchar __devinit AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  8642. {
  8643. ushort cfg_lsw;
  8644. if (AscGetChipScsiID(iop_base) == new_host_id) {
  8645. return (new_host_id);
  8646. }
  8647. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8648. cfg_lsw &= 0xF8FF;
  8649. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  8650. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8651. return (AscGetChipScsiID(iop_base));
  8652. }
  8653. static unsigned char __devinit AscGetChipScsiCtrl(PortAddr iop_base)
  8654. {
  8655. unsigned char sc;
  8656. AscSetBank(iop_base, 1);
  8657. sc = inp(iop_base + IOP_REG_SC);
  8658. AscSetBank(iop_base, 0);
  8659. return sc;
  8660. }
  8661. static unsigned char __devinit
  8662. AscGetChipVersion(PortAddr iop_base, unsigned short bus_type)
  8663. {
  8664. if (bus_type & ASC_IS_EISA) {
  8665. PortAddr eisa_iop;
  8666. unsigned char revision;
  8667. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8668. (PortAddr) ASC_EISA_REV_IOP_MASK;
  8669. revision = inp(eisa_iop);
  8670. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  8671. }
  8672. return AscGetChipVerNo(iop_base);
  8673. }
  8674. #ifdef CONFIG_ISA
  8675. static void __devinit AscEnableIsaDma(uchar dma_channel)
  8676. {
  8677. if (dma_channel < 4) {
  8678. outp(0x000B, (ushort)(0xC0 | dma_channel));
  8679. outp(0x000A, dma_channel);
  8680. } else if (dma_channel < 8) {
  8681. outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
  8682. outp(0x00D4, (ushort)(dma_channel - 4));
  8683. }
  8684. }
  8685. #endif /* CONFIG_ISA */
  8686. static int AscStopQueueExe(PortAddr iop_base)
  8687. {
  8688. int count = 0;
  8689. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  8690. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  8691. ASC_STOP_REQ_RISC_STOP);
  8692. do {
  8693. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  8694. ASC_STOP_ACK_RISC_STOP) {
  8695. return (1);
  8696. }
  8697. mdelay(100);
  8698. } while (count++ < 20);
  8699. }
  8700. return (0);
  8701. }
  8702. static ASC_DCNT __devinit AscGetMaxDmaCount(ushort bus_type)
  8703. {
  8704. if (bus_type & ASC_IS_ISA)
  8705. return ASC_MAX_ISA_DMA_COUNT;
  8706. else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  8707. return ASC_MAX_VL_DMA_COUNT;
  8708. return ASC_MAX_PCI_DMA_COUNT;
  8709. }
  8710. #ifdef CONFIG_ISA
  8711. static ushort __devinit AscGetIsaDmaChannel(PortAddr iop_base)
  8712. {
  8713. ushort channel;
  8714. channel = AscGetChipCfgLsw(iop_base) & 0x0003;
  8715. if (channel == 0x03)
  8716. return (0);
  8717. else if (channel == 0x00)
  8718. return (7);
  8719. return (channel + 4);
  8720. }
  8721. static ushort __devinit AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
  8722. {
  8723. ushort cfg_lsw;
  8724. uchar value;
  8725. if ((dma_channel >= 5) && (dma_channel <= 7)) {
  8726. if (dma_channel == 7)
  8727. value = 0x00;
  8728. else
  8729. value = dma_channel - 4;
  8730. cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
  8731. cfg_lsw |= value;
  8732. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8733. return (AscGetIsaDmaChannel(iop_base));
  8734. }
  8735. return 0;
  8736. }
  8737. static uchar __devinit AscGetIsaDmaSpeed(PortAddr iop_base)
  8738. {
  8739. uchar speed_value;
  8740. AscSetBank(iop_base, 1);
  8741. speed_value = AscReadChipDmaSpeed(iop_base);
  8742. speed_value &= 0x07;
  8743. AscSetBank(iop_base, 0);
  8744. return speed_value;
  8745. }
  8746. static uchar __devinit AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
  8747. {
  8748. speed_value &= 0x07;
  8749. AscSetBank(iop_base, 1);
  8750. AscWriteChipDmaSpeed(iop_base, speed_value);
  8751. AscSetBank(iop_base, 0);
  8752. return AscGetIsaDmaSpeed(iop_base);
  8753. }
  8754. #endif /* CONFIG_ISA */
  8755. static ushort __devinit AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  8756. {
  8757. int i;
  8758. PortAddr iop_base;
  8759. ushort warn_code;
  8760. uchar chip_version;
  8761. iop_base = asc_dvc->iop_base;
  8762. warn_code = 0;
  8763. asc_dvc->err_code = 0;
  8764. if ((asc_dvc->bus_type &
  8765. (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  8766. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  8767. }
  8768. AscSetChipControl(iop_base, CC_HALT);
  8769. AscSetChipStatus(iop_base, 0);
  8770. asc_dvc->bug_fix_cntl = 0;
  8771. asc_dvc->pci_fix_asyn_xfer = 0;
  8772. asc_dvc->pci_fix_asyn_xfer_always = 0;
  8773. /* asc_dvc->init_state initialized in AscInitGetConfig(). */
  8774. asc_dvc->sdtr_done = 0;
  8775. asc_dvc->cur_total_qng = 0;
  8776. asc_dvc->is_in_int = 0;
  8777. asc_dvc->in_critical_cnt = 0;
  8778. asc_dvc->last_q_shortage = 0;
  8779. asc_dvc->use_tagged_qng = 0;
  8780. asc_dvc->no_scam = 0;
  8781. asc_dvc->unit_not_ready = 0;
  8782. asc_dvc->queue_full_or_busy = 0;
  8783. asc_dvc->redo_scam = 0;
  8784. asc_dvc->res2 = 0;
  8785. asc_dvc->min_sdtr_index = 0;
  8786. asc_dvc->cfg->can_tagged_qng = 0;
  8787. asc_dvc->cfg->cmd_qng_enabled = 0;
  8788. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  8789. asc_dvc->init_sdtr = 0;
  8790. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  8791. asc_dvc->scsi_reset_wait = 3;
  8792. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  8793. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  8794. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  8795. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  8796. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  8797. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  8798. asc_dvc->cfg->chip_version = chip_version;
  8799. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  8800. asc_dvc->max_sdtr_index = 7;
  8801. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  8802. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  8803. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  8804. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  8805. asc_dvc->max_sdtr_index = 15;
  8806. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  8807. AscSetExtraControl(iop_base,
  8808. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8809. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  8810. AscSetExtraControl(iop_base,
  8811. (SEC_ACTIVE_NEGATE |
  8812. SEC_ENABLE_FILTER));
  8813. }
  8814. }
  8815. if (asc_dvc->bus_type == ASC_IS_PCI) {
  8816. AscSetExtraControl(iop_base,
  8817. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8818. }
  8819. asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
  8820. #ifdef CONFIG_ISA
  8821. if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
  8822. if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
  8823. AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
  8824. asc_dvc->bus_type = ASC_IS_ISAPNP;
  8825. }
  8826. asc_dvc->cfg->isa_dma_channel =
  8827. (uchar)AscGetIsaDmaChannel(iop_base);
  8828. }
  8829. #endif /* CONFIG_ISA */
  8830. for (i = 0; i <= ASC_MAX_TID; i++) {
  8831. asc_dvc->cur_dvc_qng[i] = 0;
  8832. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  8833. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  8834. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  8835. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  8836. }
  8837. return warn_code;
  8838. }
  8839. static int __devinit AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  8840. {
  8841. int retry;
  8842. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  8843. unsigned char read_back;
  8844. AscSetChipEEPCmd(iop_base, cmd_reg);
  8845. mdelay(1);
  8846. read_back = AscGetChipEEPCmd(iop_base);
  8847. if (read_back == cmd_reg)
  8848. return 1;
  8849. }
  8850. return 0;
  8851. }
  8852. static void __devinit AscWaitEEPRead(void)
  8853. {
  8854. mdelay(1);
  8855. }
  8856. static ushort __devinit AscReadEEPWord(PortAddr iop_base, uchar addr)
  8857. {
  8858. ushort read_wval;
  8859. uchar cmd_reg;
  8860. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8861. AscWaitEEPRead();
  8862. cmd_reg = addr | ASC_EEP_CMD_READ;
  8863. AscWriteEEPCmdReg(iop_base, cmd_reg);
  8864. AscWaitEEPRead();
  8865. read_wval = AscGetChipEEPData(iop_base);
  8866. AscWaitEEPRead();
  8867. return read_wval;
  8868. }
  8869. static ushort __devinit
  8870. AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  8871. {
  8872. ushort wval;
  8873. ushort sum;
  8874. ushort *wbuf;
  8875. int cfg_beg;
  8876. int cfg_end;
  8877. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8878. int s_addr;
  8879. wbuf = (ushort *)cfg_buf;
  8880. sum = 0;
  8881. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  8882. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8883. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8884. sum += *wbuf;
  8885. }
  8886. if (bus_type & ASC_IS_VL) {
  8887. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8888. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8889. } else {
  8890. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8891. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8892. }
  8893. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8894. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  8895. if (s_addr <= uchar_end_in_config) {
  8896. /*
  8897. * Swap all char fields - must unswap bytes already swapped
  8898. * by AscReadEEPWord().
  8899. */
  8900. *wbuf = le16_to_cpu(wval);
  8901. } else {
  8902. /* Don't swap word field at the end - cntl field. */
  8903. *wbuf = wval;
  8904. }
  8905. sum += wval; /* Checksum treats all EEPROM data as words. */
  8906. }
  8907. /*
  8908. * Read the checksum word which will be compared against 'sum'
  8909. * by the caller. Word field already swapped.
  8910. */
  8911. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8912. return sum;
  8913. }
  8914. static int __devinit AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  8915. {
  8916. PortAddr iop_base;
  8917. ushort q_addr;
  8918. ushort saved_word;
  8919. int sta;
  8920. iop_base = asc_dvc->iop_base;
  8921. sta = 0;
  8922. q_addr = ASC_QNO_TO_QADDR(241);
  8923. saved_word = AscReadLramWord(iop_base, q_addr);
  8924. AscSetChipLramAddr(iop_base, q_addr);
  8925. AscSetChipLramData(iop_base, 0x55AA);
  8926. mdelay(10);
  8927. AscSetChipLramAddr(iop_base, q_addr);
  8928. if (AscGetChipLramData(iop_base) == 0x55AA) {
  8929. sta = 1;
  8930. AscWriteLramWord(iop_base, q_addr, saved_word);
  8931. }
  8932. return (sta);
  8933. }
  8934. static void __devinit AscWaitEEPWrite(void)
  8935. {
  8936. mdelay(20);
  8937. }
  8938. static int __devinit AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  8939. {
  8940. ushort read_back;
  8941. int retry;
  8942. retry = 0;
  8943. while (TRUE) {
  8944. AscSetChipEEPData(iop_base, data_reg);
  8945. mdelay(1);
  8946. read_back = AscGetChipEEPData(iop_base);
  8947. if (read_back == data_reg) {
  8948. return (1);
  8949. }
  8950. if (retry++ > ASC_EEP_MAX_RETRY) {
  8951. return (0);
  8952. }
  8953. }
  8954. }
  8955. static ushort __devinit
  8956. AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  8957. {
  8958. ushort read_wval;
  8959. read_wval = AscReadEEPWord(iop_base, addr);
  8960. if (read_wval != word_val) {
  8961. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  8962. AscWaitEEPRead();
  8963. AscWriteEEPDataReg(iop_base, word_val);
  8964. AscWaitEEPRead();
  8965. AscWriteEEPCmdReg(iop_base,
  8966. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  8967. AscWaitEEPWrite();
  8968. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8969. AscWaitEEPRead();
  8970. return (AscReadEEPWord(iop_base, addr));
  8971. }
  8972. return (read_wval);
  8973. }
  8974. static int __devinit
  8975. AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  8976. {
  8977. int n_error;
  8978. ushort *wbuf;
  8979. ushort word;
  8980. ushort sum;
  8981. int s_addr;
  8982. int cfg_beg;
  8983. int cfg_end;
  8984. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8985. wbuf = (ushort *)cfg_buf;
  8986. n_error = 0;
  8987. sum = 0;
  8988. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  8989. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8990. sum += *wbuf;
  8991. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8992. n_error++;
  8993. }
  8994. }
  8995. if (bus_type & ASC_IS_VL) {
  8996. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8997. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8998. } else {
  8999. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  9000. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  9001. }
  9002. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  9003. if (s_addr <= uchar_end_in_config) {
  9004. /*
  9005. * This is a char field. Swap char fields before they are
  9006. * swapped again by AscWriteEEPWord().
  9007. */
  9008. word = cpu_to_le16(*wbuf);
  9009. if (word !=
  9010. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  9011. n_error++;
  9012. }
  9013. } else {
  9014. /* Don't swap word field at the end - cntl field. */
  9015. if (*wbuf !=
  9016. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  9017. n_error++;
  9018. }
  9019. }
  9020. sum += *wbuf; /* Checksum calculated from word values. */
  9021. }
  9022. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  9023. *wbuf = sum;
  9024. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  9025. n_error++;
  9026. }
  9027. /* Read EEPROM back again. */
  9028. wbuf = (ushort *)cfg_buf;
  9029. /*
  9030. * Read two config words; Byte-swapping done by AscReadEEPWord().
  9031. */
  9032. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  9033. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  9034. n_error++;
  9035. }
  9036. }
  9037. if (bus_type & ASC_IS_VL) {
  9038. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  9039. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  9040. } else {
  9041. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  9042. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  9043. }
  9044. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  9045. if (s_addr <= uchar_end_in_config) {
  9046. /*
  9047. * Swap all char fields. Must unswap bytes already swapped
  9048. * by AscReadEEPWord().
  9049. */
  9050. word =
  9051. le16_to_cpu(AscReadEEPWord
  9052. (iop_base, (uchar)s_addr));
  9053. } else {
  9054. /* Don't swap word field at the end - cntl field. */
  9055. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  9056. }
  9057. if (*wbuf != word) {
  9058. n_error++;
  9059. }
  9060. }
  9061. /* Read checksum; Byte swapping not needed. */
  9062. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  9063. n_error++;
  9064. }
  9065. return n_error;
  9066. }
  9067. static int __devinit
  9068. AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  9069. {
  9070. int retry;
  9071. int n_error;
  9072. retry = 0;
  9073. while (TRUE) {
  9074. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  9075. bus_type)) == 0) {
  9076. break;
  9077. }
  9078. if (++retry > ASC_EEP_MAX_RETRY) {
  9079. break;
  9080. }
  9081. }
  9082. return n_error;
  9083. }
  9084. static ushort __devinit AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  9085. {
  9086. ASCEEP_CONFIG eep_config_buf;
  9087. ASCEEP_CONFIG *eep_config;
  9088. PortAddr iop_base;
  9089. ushort chksum;
  9090. ushort warn_code;
  9091. ushort cfg_msw, cfg_lsw;
  9092. int i;
  9093. int write_eep = 0;
  9094. iop_base = asc_dvc->iop_base;
  9095. warn_code = 0;
  9096. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  9097. AscStopQueueExe(iop_base);
  9098. if ((AscStopChip(iop_base) == FALSE) ||
  9099. (AscGetChipScsiCtrl(iop_base) != 0)) {
  9100. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  9101. AscResetChipAndScsiBus(asc_dvc);
  9102. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  9103. }
  9104. if (AscIsChipHalted(iop_base) == FALSE) {
  9105. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  9106. return (warn_code);
  9107. }
  9108. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  9109. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  9110. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  9111. return (warn_code);
  9112. }
  9113. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  9114. cfg_msw = AscGetChipCfgMsw(iop_base);
  9115. cfg_lsw = AscGetChipCfgLsw(iop_base);
  9116. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  9117. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9118. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  9119. AscSetChipCfgMsw(iop_base, cfg_msw);
  9120. }
  9121. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  9122. ASC_DBG(1, "chksum 0x%x\n", chksum);
  9123. if (chksum == 0) {
  9124. chksum = 0xaa55;
  9125. }
  9126. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  9127. warn_code |= ASC_WARN_AUTO_CONFIG;
  9128. if (asc_dvc->cfg->chip_version == 3) {
  9129. if (eep_config->cfg_lsw != cfg_lsw) {
  9130. warn_code |= ASC_WARN_EEPROM_RECOVER;
  9131. eep_config->cfg_lsw =
  9132. AscGetChipCfgLsw(iop_base);
  9133. }
  9134. if (eep_config->cfg_msw != cfg_msw) {
  9135. warn_code |= ASC_WARN_EEPROM_RECOVER;
  9136. eep_config->cfg_msw =
  9137. AscGetChipCfgMsw(iop_base);
  9138. }
  9139. }
  9140. }
  9141. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9142. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  9143. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  9144. if (chksum != eep_config->chksum) {
  9145. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  9146. ASC_CHIP_VER_PCI_ULTRA_3050) {
  9147. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  9148. eep_config->init_sdtr = 0xFF;
  9149. eep_config->disc_enable = 0xFF;
  9150. eep_config->start_motor = 0xFF;
  9151. eep_config->use_cmd_qng = 0;
  9152. eep_config->max_total_qng = 0xF0;
  9153. eep_config->max_tag_qng = 0x20;
  9154. eep_config->cntl = 0xBFFF;
  9155. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  9156. eep_config->no_scam = 0;
  9157. eep_config->adapter_info[0] = 0;
  9158. eep_config->adapter_info[1] = 0;
  9159. eep_config->adapter_info[2] = 0;
  9160. eep_config->adapter_info[3] = 0;
  9161. eep_config->adapter_info[4] = 0;
  9162. /* Indicate EEPROM-less board. */
  9163. eep_config->adapter_info[5] = 0xBB;
  9164. } else {
  9165. ASC_PRINT
  9166. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  9167. write_eep = 1;
  9168. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9169. }
  9170. }
  9171. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  9172. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  9173. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  9174. asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
  9175. asc_dvc->start_motor = eep_config->start_motor;
  9176. asc_dvc->dvc_cntl = eep_config->cntl;
  9177. asc_dvc->no_scam = eep_config->no_scam;
  9178. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  9179. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  9180. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  9181. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  9182. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  9183. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  9184. if (!AscTestExternalLram(asc_dvc)) {
  9185. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  9186. ASC_IS_PCI_ULTRA)) {
  9187. eep_config->max_total_qng =
  9188. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  9189. eep_config->max_tag_qng =
  9190. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  9191. } else {
  9192. eep_config->cfg_msw |= 0x0800;
  9193. cfg_msw |= 0x0800;
  9194. AscSetChipCfgMsw(iop_base, cfg_msw);
  9195. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  9196. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  9197. }
  9198. } else {
  9199. }
  9200. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  9201. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  9202. }
  9203. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  9204. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  9205. }
  9206. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  9207. eep_config->max_tag_qng = eep_config->max_total_qng;
  9208. }
  9209. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  9210. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  9211. }
  9212. asc_dvc->max_total_qng = eep_config->max_total_qng;
  9213. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  9214. eep_config->use_cmd_qng) {
  9215. eep_config->disc_enable = eep_config->use_cmd_qng;
  9216. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  9217. }
  9218. ASC_EEP_SET_CHIP_ID(eep_config,
  9219. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  9220. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  9221. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  9222. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  9223. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  9224. }
  9225. for (i = 0; i <= ASC_MAX_TID; i++) {
  9226. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  9227. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  9228. asc_dvc->cfg->sdtr_period_offset[i] =
  9229. (uchar)(ASC_DEF_SDTR_OFFSET |
  9230. (asc_dvc->min_sdtr_index << 4));
  9231. }
  9232. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  9233. if (write_eep) {
  9234. if ((i = AscSetEEPConfig(iop_base, eep_config,
  9235. asc_dvc->bus_type)) != 0) {
  9236. ASC_PRINT1
  9237. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  9238. i);
  9239. } else {
  9240. ASC_PRINT
  9241. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  9242. }
  9243. }
  9244. return (warn_code);
  9245. }
  9246. static int __devinit AscInitGetConfig(struct Scsi_Host *shost)
  9247. {
  9248. struct asc_board *board = shost_priv(shost);
  9249. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  9250. unsigned short warn_code = 0;
  9251. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  9252. if (asc_dvc->err_code != 0)
  9253. return asc_dvc->err_code;
  9254. if (AscFindSignature(asc_dvc->iop_base)) {
  9255. warn_code |= AscInitAscDvcVar(asc_dvc);
  9256. warn_code |= AscInitFromEEP(asc_dvc);
  9257. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  9258. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  9259. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  9260. } else {
  9261. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9262. }
  9263. switch (warn_code) {
  9264. case 0: /* No error */
  9265. break;
  9266. case ASC_WARN_IO_PORT_ROTATE:
  9267. shost_printk(KERN_WARNING, shost, "I/O port address "
  9268. "modified\n");
  9269. break;
  9270. case ASC_WARN_AUTO_CONFIG:
  9271. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  9272. "enabled\n");
  9273. break;
  9274. case ASC_WARN_EEPROM_CHKSUM:
  9275. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  9276. break;
  9277. case ASC_WARN_IRQ_MODIFIED:
  9278. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  9279. break;
  9280. case ASC_WARN_CMD_QNG_CONFLICT:
  9281. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  9282. "disconnects\n");
  9283. break;
  9284. default:
  9285. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  9286. warn_code);
  9287. break;
  9288. }
  9289. if (asc_dvc->err_code != 0)
  9290. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  9291. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  9292. return asc_dvc->err_code;
  9293. }
  9294. static int __devinit AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  9295. {
  9296. struct asc_board *board = shost_priv(shost);
  9297. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  9298. PortAddr iop_base = asc_dvc->iop_base;
  9299. unsigned short cfg_msw;
  9300. unsigned short warn_code = 0;
  9301. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  9302. if (asc_dvc->err_code != 0)
  9303. return asc_dvc->err_code;
  9304. if (!AscFindSignature(asc_dvc->iop_base)) {
  9305. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9306. return asc_dvc->err_code;
  9307. }
  9308. cfg_msw = AscGetChipCfgMsw(iop_base);
  9309. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  9310. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9311. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  9312. AscSetChipCfgMsw(iop_base, cfg_msw);
  9313. }
  9314. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  9315. asc_dvc->cfg->cmd_qng_enabled) {
  9316. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  9317. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  9318. }
  9319. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  9320. warn_code |= ASC_WARN_AUTO_CONFIG;
  9321. }
  9322. #ifdef CONFIG_PCI
  9323. if (asc_dvc->bus_type & ASC_IS_PCI) {
  9324. cfg_msw &= 0xFFC0;
  9325. AscSetChipCfgMsw(iop_base, cfg_msw);
  9326. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  9327. } else {
  9328. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  9329. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  9330. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  9331. asc_dvc->bug_fix_cntl |=
  9332. ASC_BUG_FIX_ASYN_USE_SYN;
  9333. }
  9334. }
  9335. } else
  9336. #endif /* CONFIG_PCI */
  9337. if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
  9338. if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
  9339. == ASC_CHIP_VER_ASYN_BUG) {
  9340. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
  9341. }
  9342. }
  9343. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  9344. asc_dvc->cfg->chip_scsi_id) {
  9345. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  9346. }
  9347. #ifdef CONFIG_ISA
  9348. if (asc_dvc->bus_type & ASC_IS_ISA) {
  9349. AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
  9350. AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
  9351. }
  9352. #endif /* CONFIG_ISA */
  9353. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  9354. switch (warn_code) {
  9355. case 0: /* No error. */
  9356. break;
  9357. case ASC_WARN_IO_PORT_ROTATE:
  9358. shost_printk(KERN_WARNING, shost, "I/O port address "
  9359. "modified\n");
  9360. break;
  9361. case ASC_WARN_AUTO_CONFIG:
  9362. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  9363. "enabled\n");
  9364. break;
  9365. case ASC_WARN_EEPROM_CHKSUM:
  9366. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  9367. break;
  9368. case ASC_WARN_IRQ_MODIFIED:
  9369. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  9370. break;
  9371. case ASC_WARN_CMD_QNG_CONFLICT:
  9372. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  9373. "disconnects\n");
  9374. break;
  9375. default:
  9376. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  9377. warn_code);
  9378. break;
  9379. }
  9380. if (asc_dvc->err_code != 0)
  9381. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  9382. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  9383. return asc_dvc->err_code;
  9384. }
  9385. /*
  9386. * EEPROM Configuration.
  9387. *
  9388. * All drivers should use this structure to set the default EEPROM
  9389. * configuration. The BIOS now uses this structure when it is built.
  9390. * Additional structure information can be found in a_condor.h where
  9391. * the structure is defined.
  9392. *
  9393. * The *_Field_IsChar structs are needed to correct for endianness.
  9394. * These values are read from the board 16 bits at a time directly
  9395. * into the structs. Because some fields are char, the values will be
  9396. * in the wrong order. The *_Field_IsChar tells when to flip the
  9397. * bytes. Data read and written to PCI memory is automatically swapped
  9398. * on big-endian platforms so char fields read as words are actually being
  9399. * unswapped on big-endian platforms.
  9400. */
  9401. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config __devinitdata = {
  9402. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  9403. 0x0000, /* cfg_msw */
  9404. 0xFFFF, /* disc_enable */
  9405. 0xFFFF, /* wdtr_able */
  9406. 0xFFFF, /* sdtr_able */
  9407. 0xFFFF, /* start_motor */
  9408. 0xFFFF, /* tagqng_able */
  9409. 0xFFFF, /* bios_scan */
  9410. 0, /* scam_tolerant */
  9411. 7, /* adapter_scsi_id */
  9412. 0, /* bios_boot_delay */
  9413. 3, /* scsi_reset_delay */
  9414. 0, /* bios_id_lun */
  9415. 0, /* termination */
  9416. 0, /* reserved1 */
  9417. 0xFFE7, /* bios_ctrl */
  9418. 0xFFFF, /* ultra_able */
  9419. 0, /* reserved2 */
  9420. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  9421. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9422. 0, /* dvc_cntl */
  9423. 0, /* bug_fix */
  9424. 0, /* serial_number_word1 */
  9425. 0, /* serial_number_word2 */
  9426. 0, /* serial_number_word3 */
  9427. 0, /* check_sum */
  9428. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9429. , /* oem_name[16] */
  9430. 0, /* dvc_err_code */
  9431. 0, /* adv_err_code */
  9432. 0, /* adv_err_addr */
  9433. 0, /* saved_dvc_err_code */
  9434. 0, /* saved_adv_err_code */
  9435. 0, /* saved_adv_err_addr */
  9436. 0 /* num_of_err */
  9437. };
  9438. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar __devinitdata = {
  9439. 0, /* cfg_lsw */
  9440. 0, /* cfg_msw */
  9441. 0, /* -disc_enable */
  9442. 0, /* wdtr_able */
  9443. 0, /* sdtr_able */
  9444. 0, /* start_motor */
  9445. 0, /* tagqng_able */
  9446. 0, /* bios_scan */
  9447. 0, /* scam_tolerant */
  9448. 1, /* adapter_scsi_id */
  9449. 1, /* bios_boot_delay */
  9450. 1, /* scsi_reset_delay */
  9451. 1, /* bios_id_lun */
  9452. 1, /* termination */
  9453. 1, /* reserved1 */
  9454. 0, /* bios_ctrl */
  9455. 0, /* ultra_able */
  9456. 0, /* reserved2 */
  9457. 1, /* max_host_qng */
  9458. 1, /* max_dvc_qng */
  9459. 0, /* dvc_cntl */
  9460. 0, /* bug_fix */
  9461. 0, /* serial_number_word1 */
  9462. 0, /* serial_number_word2 */
  9463. 0, /* serial_number_word3 */
  9464. 0, /* check_sum */
  9465. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9466. , /* oem_name[16] */
  9467. 0, /* dvc_err_code */
  9468. 0, /* adv_err_code */
  9469. 0, /* adv_err_addr */
  9470. 0, /* saved_dvc_err_code */
  9471. 0, /* saved_adv_err_code */
  9472. 0, /* saved_adv_err_addr */
  9473. 0 /* num_of_err */
  9474. };
  9475. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config __devinitdata = {
  9476. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9477. 0x0000, /* 01 cfg_msw */
  9478. 0xFFFF, /* 02 disc_enable */
  9479. 0xFFFF, /* 03 wdtr_able */
  9480. 0x4444, /* 04 sdtr_speed1 */
  9481. 0xFFFF, /* 05 start_motor */
  9482. 0xFFFF, /* 06 tagqng_able */
  9483. 0xFFFF, /* 07 bios_scan */
  9484. 0, /* 08 scam_tolerant */
  9485. 7, /* 09 adapter_scsi_id */
  9486. 0, /* bios_boot_delay */
  9487. 3, /* 10 scsi_reset_delay */
  9488. 0, /* bios_id_lun */
  9489. 0, /* 11 termination_se */
  9490. 0, /* termination_lvd */
  9491. 0xFFE7, /* 12 bios_ctrl */
  9492. 0x4444, /* 13 sdtr_speed2 */
  9493. 0x4444, /* 14 sdtr_speed3 */
  9494. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9495. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9496. 0, /* 16 dvc_cntl */
  9497. 0x4444, /* 17 sdtr_speed4 */
  9498. 0, /* 18 serial_number_word1 */
  9499. 0, /* 19 serial_number_word2 */
  9500. 0, /* 20 serial_number_word3 */
  9501. 0, /* 21 check_sum */
  9502. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9503. , /* 22-29 oem_name[16] */
  9504. 0, /* 30 dvc_err_code */
  9505. 0, /* 31 adv_err_code */
  9506. 0, /* 32 adv_err_addr */
  9507. 0, /* 33 saved_dvc_err_code */
  9508. 0, /* 34 saved_adv_err_code */
  9509. 0, /* 35 saved_adv_err_addr */
  9510. 0, /* 36 reserved */
  9511. 0, /* 37 reserved */
  9512. 0, /* 38 reserved */
  9513. 0, /* 39 reserved */
  9514. 0, /* 40 reserved */
  9515. 0, /* 41 reserved */
  9516. 0, /* 42 reserved */
  9517. 0, /* 43 reserved */
  9518. 0, /* 44 reserved */
  9519. 0, /* 45 reserved */
  9520. 0, /* 46 reserved */
  9521. 0, /* 47 reserved */
  9522. 0, /* 48 reserved */
  9523. 0, /* 49 reserved */
  9524. 0, /* 50 reserved */
  9525. 0, /* 51 reserved */
  9526. 0, /* 52 reserved */
  9527. 0, /* 53 reserved */
  9528. 0, /* 54 reserved */
  9529. 0, /* 55 reserved */
  9530. 0, /* 56 cisptr_lsw */
  9531. 0, /* 57 cisprt_msw */
  9532. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9533. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  9534. 0, /* 60 reserved */
  9535. 0, /* 61 reserved */
  9536. 0, /* 62 reserved */
  9537. 0 /* 63 reserved */
  9538. };
  9539. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar __devinitdata = {
  9540. 0, /* 00 cfg_lsw */
  9541. 0, /* 01 cfg_msw */
  9542. 0, /* 02 disc_enable */
  9543. 0, /* 03 wdtr_able */
  9544. 0, /* 04 sdtr_speed1 */
  9545. 0, /* 05 start_motor */
  9546. 0, /* 06 tagqng_able */
  9547. 0, /* 07 bios_scan */
  9548. 0, /* 08 scam_tolerant */
  9549. 1, /* 09 adapter_scsi_id */
  9550. 1, /* bios_boot_delay */
  9551. 1, /* 10 scsi_reset_delay */
  9552. 1, /* bios_id_lun */
  9553. 1, /* 11 termination_se */
  9554. 1, /* termination_lvd */
  9555. 0, /* 12 bios_ctrl */
  9556. 0, /* 13 sdtr_speed2 */
  9557. 0, /* 14 sdtr_speed3 */
  9558. 1, /* 15 max_host_qng */
  9559. 1, /* max_dvc_qng */
  9560. 0, /* 16 dvc_cntl */
  9561. 0, /* 17 sdtr_speed4 */
  9562. 0, /* 18 serial_number_word1 */
  9563. 0, /* 19 serial_number_word2 */
  9564. 0, /* 20 serial_number_word3 */
  9565. 0, /* 21 check_sum */
  9566. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9567. , /* 22-29 oem_name[16] */
  9568. 0, /* 30 dvc_err_code */
  9569. 0, /* 31 adv_err_code */
  9570. 0, /* 32 adv_err_addr */
  9571. 0, /* 33 saved_dvc_err_code */
  9572. 0, /* 34 saved_adv_err_code */
  9573. 0, /* 35 saved_adv_err_addr */
  9574. 0, /* 36 reserved */
  9575. 0, /* 37 reserved */
  9576. 0, /* 38 reserved */
  9577. 0, /* 39 reserved */
  9578. 0, /* 40 reserved */
  9579. 0, /* 41 reserved */
  9580. 0, /* 42 reserved */
  9581. 0, /* 43 reserved */
  9582. 0, /* 44 reserved */
  9583. 0, /* 45 reserved */
  9584. 0, /* 46 reserved */
  9585. 0, /* 47 reserved */
  9586. 0, /* 48 reserved */
  9587. 0, /* 49 reserved */
  9588. 0, /* 50 reserved */
  9589. 0, /* 51 reserved */
  9590. 0, /* 52 reserved */
  9591. 0, /* 53 reserved */
  9592. 0, /* 54 reserved */
  9593. 0, /* 55 reserved */
  9594. 0, /* 56 cisptr_lsw */
  9595. 0, /* 57 cisprt_msw */
  9596. 0, /* 58 subsysvid */
  9597. 0, /* 59 subsysid */
  9598. 0, /* 60 reserved */
  9599. 0, /* 61 reserved */
  9600. 0, /* 62 reserved */
  9601. 0 /* 63 reserved */
  9602. };
  9603. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config __devinitdata = {
  9604. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9605. 0x0000, /* 01 cfg_msw */
  9606. 0xFFFF, /* 02 disc_enable */
  9607. 0xFFFF, /* 03 wdtr_able */
  9608. 0x5555, /* 04 sdtr_speed1 */
  9609. 0xFFFF, /* 05 start_motor */
  9610. 0xFFFF, /* 06 tagqng_able */
  9611. 0xFFFF, /* 07 bios_scan */
  9612. 0, /* 08 scam_tolerant */
  9613. 7, /* 09 adapter_scsi_id */
  9614. 0, /* bios_boot_delay */
  9615. 3, /* 10 scsi_reset_delay */
  9616. 0, /* bios_id_lun */
  9617. 0, /* 11 termination_se */
  9618. 0, /* termination_lvd */
  9619. 0xFFE7, /* 12 bios_ctrl */
  9620. 0x5555, /* 13 sdtr_speed2 */
  9621. 0x5555, /* 14 sdtr_speed3 */
  9622. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9623. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9624. 0, /* 16 dvc_cntl */
  9625. 0x5555, /* 17 sdtr_speed4 */
  9626. 0, /* 18 serial_number_word1 */
  9627. 0, /* 19 serial_number_word2 */
  9628. 0, /* 20 serial_number_word3 */
  9629. 0, /* 21 check_sum */
  9630. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9631. , /* 22-29 oem_name[16] */
  9632. 0, /* 30 dvc_err_code */
  9633. 0, /* 31 adv_err_code */
  9634. 0, /* 32 adv_err_addr */
  9635. 0, /* 33 saved_dvc_err_code */
  9636. 0, /* 34 saved_adv_err_code */
  9637. 0, /* 35 saved_adv_err_addr */
  9638. 0, /* 36 reserved */
  9639. 0, /* 37 reserved */
  9640. 0, /* 38 reserved */
  9641. 0, /* 39 reserved */
  9642. 0, /* 40 reserved */
  9643. 0, /* 41 reserved */
  9644. 0, /* 42 reserved */
  9645. 0, /* 43 reserved */
  9646. 0, /* 44 reserved */
  9647. 0, /* 45 reserved */
  9648. 0, /* 46 reserved */
  9649. 0, /* 47 reserved */
  9650. 0, /* 48 reserved */
  9651. 0, /* 49 reserved */
  9652. 0, /* 50 reserved */
  9653. 0, /* 51 reserved */
  9654. 0, /* 52 reserved */
  9655. 0, /* 53 reserved */
  9656. 0, /* 54 reserved */
  9657. 0, /* 55 reserved */
  9658. 0, /* 56 cisptr_lsw */
  9659. 0, /* 57 cisprt_msw */
  9660. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9661. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  9662. 0, /* 60 reserved */
  9663. 0, /* 61 reserved */
  9664. 0, /* 62 reserved */
  9665. 0 /* 63 reserved */
  9666. };
  9667. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar __devinitdata = {
  9668. 0, /* 00 cfg_lsw */
  9669. 0, /* 01 cfg_msw */
  9670. 0, /* 02 disc_enable */
  9671. 0, /* 03 wdtr_able */
  9672. 0, /* 04 sdtr_speed1 */
  9673. 0, /* 05 start_motor */
  9674. 0, /* 06 tagqng_able */
  9675. 0, /* 07 bios_scan */
  9676. 0, /* 08 scam_tolerant */
  9677. 1, /* 09 adapter_scsi_id */
  9678. 1, /* bios_boot_delay */
  9679. 1, /* 10 scsi_reset_delay */
  9680. 1, /* bios_id_lun */
  9681. 1, /* 11 termination_se */
  9682. 1, /* termination_lvd */
  9683. 0, /* 12 bios_ctrl */
  9684. 0, /* 13 sdtr_speed2 */
  9685. 0, /* 14 sdtr_speed3 */
  9686. 1, /* 15 max_host_qng */
  9687. 1, /* max_dvc_qng */
  9688. 0, /* 16 dvc_cntl */
  9689. 0, /* 17 sdtr_speed4 */
  9690. 0, /* 18 serial_number_word1 */
  9691. 0, /* 19 serial_number_word2 */
  9692. 0, /* 20 serial_number_word3 */
  9693. 0, /* 21 check_sum */
  9694. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9695. , /* 22-29 oem_name[16] */
  9696. 0, /* 30 dvc_err_code */
  9697. 0, /* 31 adv_err_code */
  9698. 0, /* 32 adv_err_addr */
  9699. 0, /* 33 saved_dvc_err_code */
  9700. 0, /* 34 saved_adv_err_code */
  9701. 0, /* 35 saved_adv_err_addr */
  9702. 0, /* 36 reserved */
  9703. 0, /* 37 reserved */
  9704. 0, /* 38 reserved */
  9705. 0, /* 39 reserved */
  9706. 0, /* 40 reserved */
  9707. 0, /* 41 reserved */
  9708. 0, /* 42 reserved */
  9709. 0, /* 43 reserved */
  9710. 0, /* 44 reserved */
  9711. 0, /* 45 reserved */
  9712. 0, /* 46 reserved */
  9713. 0, /* 47 reserved */
  9714. 0, /* 48 reserved */
  9715. 0, /* 49 reserved */
  9716. 0, /* 50 reserved */
  9717. 0, /* 51 reserved */
  9718. 0, /* 52 reserved */
  9719. 0, /* 53 reserved */
  9720. 0, /* 54 reserved */
  9721. 0, /* 55 reserved */
  9722. 0, /* 56 cisptr_lsw */
  9723. 0, /* 57 cisprt_msw */
  9724. 0, /* 58 subsysvid */
  9725. 0, /* 59 subsysid */
  9726. 0, /* 60 reserved */
  9727. 0, /* 61 reserved */
  9728. 0, /* 62 reserved */
  9729. 0 /* 63 reserved */
  9730. };
  9731. #ifdef CONFIG_PCI
  9732. /*
  9733. * Wait for EEPROM command to complete
  9734. */
  9735. static void __devinit AdvWaitEEPCmd(AdvPortAddr iop_base)
  9736. {
  9737. int eep_delay_ms;
  9738. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  9739. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  9740. ASC_EEP_CMD_DONE) {
  9741. break;
  9742. }
  9743. mdelay(1);
  9744. }
  9745. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  9746. 0)
  9747. BUG();
  9748. }
  9749. /*
  9750. * Read the EEPROM from specified location
  9751. */
  9752. static ushort __devinit AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  9753. {
  9754. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9755. ASC_EEP_CMD_READ | eep_word_addr);
  9756. AdvWaitEEPCmd(iop_base);
  9757. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  9758. }
  9759. /*
  9760. * Write the EEPROM from 'cfg_buf'.
  9761. */
  9762. static void __devinit
  9763. AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
  9764. {
  9765. ushort *wbuf;
  9766. ushort addr, chksum;
  9767. ushort *charfields;
  9768. wbuf = (ushort *)cfg_buf;
  9769. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9770. chksum = 0;
  9771. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9772. AdvWaitEEPCmd(iop_base);
  9773. /*
  9774. * Write EEPROM from word 0 to word 20.
  9775. */
  9776. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9777. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9778. ushort word;
  9779. if (*charfields++) {
  9780. word = cpu_to_le16(*wbuf);
  9781. } else {
  9782. word = *wbuf;
  9783. }
  9784. chksum += *wbuf; /* Checksum is calculated from word values. */
  9785. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9786. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9787. ASC_EEP_CMD_WRITE | addr);
  9788. AdvWaitEEPCmd(iop_base);
  9789. mdelay(ADV_EEP_DELAY_MS);
  9790. }
  9791. /*
  9792. * Write EEPROM checksum at word 21.
  9793. */
  9794. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9795. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9796. AdvWaitEEPCmd(iop_base);
  9797. wbuf++;
  9798. charfields++;
  9799. /*
  9800. * Write EEPROM OEM name at words 22 to 29.
  9801. */
  9802. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9803. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9804. ushort word;
  9805. if (*charfields++) {
  9806. word = cpu_to_le16(*wbuf);
  9807. } else {
  9808. word = *wbuf;
  9809. }
  9810. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9811. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9812. ASC_EEP_CMD_WRITE | addr);
  9813. AdvWaitEEPCmd(iop_base);
  9814. }
  9815. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9816. AdvWaitEEPCmd(iop_base);
  9817. }
  9818. /*
  9819. * Write the EEPROM from 'cfg_buf'.
  9820. */
  9821. static void __devinit
  9822. AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
  9823. {
  9824. ushort *wbuf;
  9825. ushort *charfields;
  9826. ushort addr, chksum;
  9827. wbuf = (ushort *)cfg_buf;
  9828. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9829. chksum = 0;
  9830. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9831. AdvWaitEEPCmd(iop_base);
  9832. /*
  9833. * Write EEPROM from word 0 to word 20.
  9834. */
  9835. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9836. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9837. ushort word;
  9838. if (*charfields++) {
  9839. word = cpu_to_le16(*wbuf);
  9840. } else {
  9841. word = *wbuf;
  9842. }
  9843. chksum += *wbuf; /* Checksum is calculated from word values. */
  9844. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9845. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9846. ASC_EEP_CMD_WRITE | addr);
  9847. AdvWaitEEPCmd(iop_base);
  9848. mdelay(ADV_EEP_DELAY_MS);
  9849. }
  9850. /*
  9851. * Write EEPROM checksum at word 21.
  9852. */
  9853. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9854. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9855. AdvWaitEEPCmd(iop_base);
  9856. wbuf++;
  9857. charfields++;
  9858. /*
  9859. * Write EEPROM OEM name at words 22 to 29.
  9860. */
  9861. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9862. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9863. ushort word;
  9864. if (*charfields++) {
  9865. word = cpu_to_le16(*wbuf);
  9866. } else {
  9867. word = *wbuf;
  9868. }
  9869. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9870. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9871. ASC_EEP_CMD_WRITE | addr);
  9872. AdvWaitEEPCmd(iop_base);
  9873. }
  9874. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9875. AdvWaitEEPCmd(iop_base);
  9876. }
  9877. /*
  9878. * Write the EEPROM from 'cfg_buf'.
  9879. */
  9880. static void __devinit
  9881. AdvSet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
  9882. {
  9883. ushort *wbuf;
  9884. ushort *charfields;
  9885. ushort addr, chksum;
  9886. wbuf = (ushort *)cfg_buf;
  9887. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9888. chksum = 0;
  9889. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9890. AdvWaitEEPCmd(iop_base);
  9891. /*
  9892. * Write EEPROM from word 0 to word 20.
  9893. */
  9894. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9895. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9896. ushort word;
  9897. if (*charfields++) {
  9898. word = cpu_to_le16(*wbuf);
  9899. } else {
  9900. word = *wbuf;
  9901. }
  9902. chksum += *wbuf; /* Checksum is calculated from word values. */
  9903. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9904. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9905. ASC_EEP_CMD_WRITE | addr);
  9906. AdvWaitEEPCmd(iop_base);
  9907. mdelay(ADV_EEP_DELAY_MS);
  9908. }
  9909. /*
  9910. * Write EEPROM checksum at word 21.
  9911. */
  9912. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9913. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9914. AdvWaitEEPCmd(iop_base);
  9915. wbuf++;
  9916. charfields++;
  9917. /*
  9918. * Write EEPROM OEM name at words 22 to 29.
  9919. */
  9920. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9921. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9922. ushort word;
  9923. if (*charfields++) {
  9924. word = cpu_to_le16(*wbuf);
  9925. } else {
  9926. word = *wbuf;
  9927. }
  9928. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9929. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9930. ASC_EEP_CMD_WRITE | addr);
  9931. AdvWaitEEPCmd(iop_base);
  9932. }
  9933. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9934. AdvWaitEEPCmd(iop_base);
  9935. }
  9936. /*
  9937. * Read EEPROM configuration into the specified buffer.
  9938. *
  9939. * Return a checksum based on the EEPROM configuration read.
  9940. */
  9941. static ushort __devinit
  9942. AdvGet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
  9943. {
  9944. ushort wval, chksum;
  9945. ushort *wbuf;
  9946. int eep_addr;
  9947. ushort *charfields;
  9948. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9949. wbuf = (ushort *)cfg_buf;
  9950. chksum = 0;
  9951. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9952. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9953. wval = AdvReadEEPWord(iop_base, eep_addr);
  9954. chksum += wval; /* Checksum is calculated from word values. */
  9955. if (*charfields++) {
  9956. *wbuf = le16_to_cpu(wval);
  9957. } else {
  9958. *wbuf = wval;
  9959. }
  9960. }
  9961. /* Read checksum word. */
  9962. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9963. wbuf++;
  9964. charfields++;
  9965. /* Read rest of EEPROM not covered by the checksum. */
  9966. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9967. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9968. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9969. if (*charfields++) {
  9970. *wbuf = le16_to_cpu(*wbuf);
  9971. }
  9972. }
  9973. return chksum;
  9974. }
  9975. /*
  9976. * Read EEPROM configuration into the specified buffer.
  9977. *
  9978. * Return a checksum based on the EEPROM configuration read.
  9979. */
  9980. static ushort __devinit
  9981. AdvGet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
  9982. {
  9983. ushort wval, chksum;
  9984. ushort *wbuf;
  9985. int eep_addr;
  9986. ushort *charfields;
  9987. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9988. wbuf = (ushort *)cfg_buf;
  9989. chksum = 0;
  9990. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9991. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9992. wval = AdvReadEEPWord(iop_base, eep_addr);
  9993. chksum += wval; /* Checksum is calculated from word values. */
  9994. if (*charfields++) {
  9995. *wbuf = le16_to_cpu(wval);
  9996. } else {
  9997. *wbuf = wval;
  9998. }
  9999. }
  10000. /* Read checksum word. */
  10001. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10002. wbuf++;
  10003. charfields++;
  10004. /* Read rest of EEPROM not covered by the checksum. */
  10005. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  10006. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  10007. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10008. if (*charfields++) {
  10009. *wbuf = le16_to_cpu(*wbuf);
  10010. }
  10011. }
  10012. return chksum;
  10013. }
  10014. /*
  10015. * Read EEPROM configuration into the specified buffer.
  10016. *
  10017. * Return a checksum based on the EEPROM configuration read.
  10018. */
  10019. static ushort __devinit
  10020. AdvGet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
  10021. {
  10022. ushort wval, chksum;
  10023. ushort *wbuf;
  10024. int eep_addr;
  10025. ushort *charfields;
  10026. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  10027. wbuf = (ushort *)cfg_buf;
  10028. chksum = 0;
  10029. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  10030. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  10031. wval = AdvReadEEPWord(iop_base, eep_addr);
  10032. chksum += wval; /* Checksum is calculated from word values. */
  10033. if (*charfields++) {
  10034. *wbuf = le16_to_cpu(wval);
  10035. } else {
  10036. *wbuf = wval;
  10037. }
  10038. }
  10039. /* Read checksum word. */
  10040. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10041. wbuf++;
  10042. charfields++;
  10043. /* Read rest of EEPROM not covered by the checksum. */
  10044. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  10045. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  10046. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10047. if (*charfields++) {
  10048. *wbuf = le16_to_cpu(*wbuf);
  10049. }
  10050. }
  10051. return chksum;
  10052. }
  10053. /*
  10054. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  10055. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10056. * all of this is done.
  10057. *
  10058. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10059. *
  10060. * For a non-fatal error return a warning code. If there are no warnings
  10061. * then 0 is returned.
  10062. *
  10063. * Note: Chip is stopped on entry.
  10064. */
  10065. static int __devinit AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  10066. {
  10067. AdvPortAddr iop_base;
  10068. ushort warn_code;
  10069. ADVEEP_3550_CONFIG eep_config;
  10070. iop_base = asc_dvc->iop_base;
  10071. warn_code = 0;
  10072. /*
  10073. * Read the board's EEPROM configuration.
  10074. *
  10075. * Set default values if a bad checksum is found.
  10076. */
  10077. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  10078. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10079. /*
  10080. * Set EEPROM default values.
  10081. */
  10082. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  10083. sizeof(ADVEEP_3550_CONFIG));
  10084. /*
  10085. * Assume the 6 byte board serial number that was read from
  10086. * EEPROM is correct even if the EEPROM checksum failed.
  10087. */
  10088. eep_config.serial_number_word3 =
  10089. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10090. eep_config.serial_number_word2 =
  10091. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10092. eep_config.serial_number_word1 =
  10093. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10094. AdvSet3550EEPConfig(iop_base, &eep_config);
  10095. }
  10096. /*
  10097. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  10098. * EEPROM configuration that was read.
  10099. *
  10100. * This is the mapping of EEPROM fields to Adv Library fields.
  10101. */
  10102. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10103. asc_dvc->sdtr_able = eep_config.sdtr_able;
  10104. asc_dvc->ultra_able = eep_config.ultra_able;
  10105. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10106. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10107. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10108. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10109. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  10110. asc_dvc->start_motor = eep_config.start_motor;
  10111. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10112. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10113. asc_dvc->no_scam = eep_config.scam_tolerant;
  10114. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  10115. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  10116. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  10117. /*
  10118. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10119. * maximum queuing (max. 63, min. 4).
  10120. */
  10121. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10122. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10123. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10124. /* If the value is zero, assume it is uninitialized. */
  10125. if (eep_config.max_host_qng == 0) {
  10126. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10127. } else {
  10128. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10129. }
  10130. }
  10131. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10132. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10133. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10134. /* If the value is zero, assume it is uninitialized. */
  10135. if (eep_config.max_dvc_qng == 0) {
  10136. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10137. } else {
  10138. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10139. }
  10140. }
  10141. /*
  10142. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10143. * set 'max_dvc_qng' to 'max_host_qng'.
  10144. */
  10145. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10146. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10147. }
  10148. /*
  10149. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  10150. * values based on possibly adjusted EEPROM values.
  10151. */
  10152. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10153. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10154. /*
  10155. * If the EEPROM 'termination' field is set to automatic (0), then set
  10156. * the ADV_DVC_CFG 'termination' field to automatic also.
  10157. *
  10158. * If the termination is specified with a non-zero 'termination'
  10159. * value check that a legal value is set and set the ADV_DVC_CFG
  10160. * 'termination' field appropriately.
  10161. */
  10162. if (eep_config.termination == 0) {
  10163. asc_dvc->cfg->termination = 0; /* auto termination */
  10164. } else {
  10165. /* Enable manual control with low off / high off. */
  10166. if (eep_config.termination == 1) {
  10167. asc_dvc->cfg->termination = TERM_CTL_SEL;
  10168. /* Enable manual control with low off / high on. */
  10169. } else if (eep_config.termination == 2) {
  10170. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  10171. /* Enable manual control with low on / high on. */
  10172. } else if (eep_config.termination == 3) {
  10173. asc_dvc->cfg->termination =
  10174. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  10175. } else {
  10176. /*
  10177. * The EEPROM 'termination' field contains a bad value. Use
  10178. * automatic termination instead.
  10179. */
  10180. asc_dvc->cfg->termination = 0;
  10181. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10182. }
  10183. }
  10184. return warn_code;
  10185. }
  10186. /*
  10187. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  10188. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10189. * all of this is done.
  10190. *
  10191. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10192. *
  10193. * For a non-fatal error return a warning code. If there are no warnings
  10194. * then 0 is returned.
  10195. *
  10196. * Note: Chip is stopped on entry.
  10197. */
  10198. static int __devinit AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  10199. {
  10200. AdvPortAddr iop_base;
  10201. ushort warn_code;
  10202. ADVEEP_38C0800_CONFIG eep_config;
  10203. uchar tid, termination;
  10204. ushort sdtr_speed = 0;
  10205. iop_base = asc_dvc->iop_base;
  10206. warn_code = 0;
  10207. /*
  10208. * Read the board's EEPROM configuration.
  10209. *
  10210. * Set default values if a bad checksum is found.
  10211. */
  10212. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  10213. eep_config.check_sum) {
  10214. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10215. /*
  10216. * Set EEPROM default values.
  10217. */
  10218. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  10219. sizeof(ADVEEP_38C0800_CONFIG));
  10220. /*
  10221. * Assume the 6 byte board serial number that was read from
  10222. * EEPROM is correct even if the EEPROM checksum failed.
  10223. */
  10224. eep_config.serial_number_word3 =
  10225. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10226. eep_config.serial_number_word2 =
  10227. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10228. eep_config.serial_number_word1 =
  10229. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10230. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  10231. }
  10232. /*
  10233. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  10234. * EEPROM configuration that was read.
  10235. *
  10236. * This is the mapping of EEPROM fields to Adv Library fields.
  10237. */
  10238. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10239. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  10240. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  10241. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  10242. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  10243. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10244. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10245. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10246. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10247. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  10248. asc_dvc->start_motor = eep_config.start_motor;
  10249. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10250. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10251. asc_dvc->no_scam = eep_config.scam_tolerant;
  10252. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  10253. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  10254. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  10255. /*
  10256. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  10257. * are set, then set an 'sdtr_able' bit for it.
  10258. */
  10259. asc_dvc->sdtr_able = 0;
  10260. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  10261. if (tid == 0) {
  10262. sdtr_speed = asc_dvc->sdtr_speed1;
  10263. } else if (tid == 4) {
  10264. sdtr_speed = asc_dvc->sdtr_speed2;
  10265. } else if (tid == 8) {
  10266. sdtr_speed = asc_dvc->sdtr_speed3;
  10267. } else if (tid == 12) {
  10268. sdtr_speed = asc_dvc->sdtr_speed4;
  10269. }
  10270. if (sdtr_speed & ADV_MAX_TID) {
  10271. asc_dvc->sdtr_able |= (1 << tid);
  10272. }
  10273. sdtr_speed >>= 4;
  10274. }
  10275. /*
  10276. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10277. * maximum queuing (max. 63, min. 4).
  10278. */
  10279. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10280. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10281. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10282. /* If the value is zero, assume it is uninitialized. */
  10283. if (eep_config.max_host_qng == 0) {
  10284. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10285. } else {
  10286. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10287. }
  10288. }
  10289. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10290. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10291. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10292. /* If the value is zero, assume it is uninitialized. */
  10293. if (eep_config.max_dvc_qng == 0) {
  10294. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10295. } else {
  10296. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10297. }
  10298. }
  10299. /*
  10300. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10301. * set 'max_dvc_qng' to 'max_host_qng'.
  10302. */
  10303. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10304. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10305. }
  10306. /*
  10307. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  10308. * values based on possibly adjusted EEPROM values.
  10309. */
  10310. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10311. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10312. /*
  10313. * If the EEPROM 'termination' field is set to automatic (0), then set
  10314. * the ADV_DVC_CFG 'termination' field to automatic also.
  10315. *
  10316. * If the termination is specified with a non-zero 'termination'
  10317. * value check that a legal value is set and set the ADV_DVC_CFG
  10318. * 'termination' field appropriately.
  10319. */
  10320. if (eep_config.termination_se == 0) {
  10321. termination = 0; /* auto termination for SE */
  10322. } else {
  10323. /* Enable manual control with low off / high off. */
  10324. if (eep_config.termination_se == 1) {
  10325. termination = 0;
  10326. /* Enable manual control with low off / high on. */
  10327. } else if (eep_config.termination_se == 2) {
  10328. termination = TERM_SE_HI;
  10329. /* Enable manual control with low on / high on. */
  10330. } else if (eep_config.termination_se == 3) {
  10331. termination = TERM_SE;
  10332. } else {
  10333. /*
  10334. * The EEPROM 'termination_se' field contains a bad value.
  10335. * Use automatic termination instead.
  10336. */
  10337. termination = 0;
  10338. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10339. }
  10340. }
  10341. if (eep_config.termination_lvd == 0) {
  10342. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10343. } else {
  10344. /* Enable manual control with low off / high off. */
  10345. if (eep_config.termination_lvd == 1) {
  10346. asc_dvc->cfg->termination = termination;
  10347. /* Enable manual control with low off / high on. */
  10348. } else if (eep_config.termination_lvd == 2) {
  10349. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10350. /* Enable manual control with low on / high on. */
  10351. } else if (eep_config.termination_lvd == 3) {
  10352. asc_dvc->cfg->termination = termination | TERM_LVD;
  10353. } else {
  10354. /*
  10355. * The EEPROM 'termination_lvd' field contains a bad value.
  10356. * Use automatic termination instead.
  10357. */
  10358. asc_dvc->cfg->termination = termination;
  10359. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10360. }
  10361. }
  10362. return warn_code;
  10363. }
  10364. /*
  10365. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  10366. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10367. * all of this is done.
  10368. *
  10369. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  10370. *
  10371. * For a non-fatal error return a warning code. If there are no warnings
  10372. * then 0 is returned.
  10373. *
  10374. * Note: Chip is stopped on entry.
  10375. */
  10376. static int __devinit AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  10377. {
  10378. AdvPortAddr iop_base;
  10379. ushort warn_code;
  10380. ADVEEP_38C1600_CONFIG eep_config;
  10381. uchar tid, termination;
  10382. ushort sdtr_speed = 0;
  10383. iop_base = asc_dvc->iop_base;
  10384. warn_code = 0;
  10385. /*
  10386. * Read the board's EEPROM configuration.
  10387. *
  10388. * Set default values if a bad checksum is found.
  10389. */
  10390. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  10391. eep_config.check_sum) {
  10392. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  10393. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10394. /*
  10395. * Set EEPROM default values.
  10396. */
  10397. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  10398. sizeof(ADVEEP_38C1600_CONFIG));
  10399. if (PCI_FUNC(pdev->devfn) != 0) {
  10400. u8 ints;
  10401. /*
  10402. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  10403. * and old Mac system booting problem. The Expansion
  10404. * ROM must be disabled in Function 1 for these systems
  10405. */
  10406. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  10407. /*
  10408. * Clear the INTAB (bit 11) if the GPIO 0 input
  10409. * indicates the Function 1 interrupt line is wired
  10410. * to INTB.
  10411. *
  10412. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  10413. * 1 - Function 1 interrupt line wired to INT A.
  10414. * 0 - Function 1 interrupt line wired to INT B.
  10415. *
  10416. * Note: Function 0 is always wired to INTA.
  10417. * Put all 5 GPIO bits in input mode and then read
  10418. * their input values.
  10419. */
  10420. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  10421. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  10422. if ((ints & 0x01) == 0)
  10423. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  10424. }
  10425. /*
  10426. * Assume the 6 byte board serial number that was read from
  10427. * EEPROM is correct even if the EEPROM checksum failed.
  10428. */
  10429. eep_config.serial_number_word3 =
  10430. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10431. eep_config.serial_number_word2 =
  10432. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10433. eep_config.serial_number_word1 =
  10434. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10435. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  10436. }
  10437. /*
  10438. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  10439. * EEPROM configuration that was read.
  10440. *
  10441. * This is the mapping of EEPROM fields to Adv Library fields.
  10442. */
  10443. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10444. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  10445. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  10446. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  10447. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  10448. asc_dvc->ppr_able = 0;
  10449. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10450. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10451. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10452. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10453. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  10454. asc_dvc->start_motor = eep_config.start_motor;
  10455. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10456. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10457. asc_dvc->no_scam = eep_config.scam_tolerant;
  10458. /*
  10459. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  10460. * are set, then set an 'sdtr_able' bit for it.
  10461. */
  10462. asc_dvc->sdtr_able = 0;
  10463. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  10464. if (tid == 0) {
  10465. sdtr_speed = asc_dvc->sdtr_speed1;
  10466. } else if (tid == 4) {
  10467. sdtr_speed = asc_dvc->sdtr_speed2;
  10468. } else if (tid == 8) {
  10469. sdtr_speed = asc_dvc->sdtr_speed3;
  10470. } else if (tid == 12) {
  10471. sdtr_speed = asc_dvc->sdtr_speed4;
  10472. }
  10473. if (sdtr_speed & ASC_MAX_TID) {
  10474. asc_dvc->sdtr_able |= (1 << tid);
  10475. }
  10476. sdtr_speed >>= 4;
  10477. }
  10478. /*
  10479. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10480. * maximum queuing (max. 63, min. 4).
  10481. */
  10482. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10483. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10484. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10485. /* If the value is zero, assume it is uninitialized. */
  10486. if (eep_config.max_host_qng == 0) {
  10487. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10488. } else {
  10489. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10490. }
  10491. }
  10492. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10493. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10494. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10495. /* If the value is zero, assume it is uninitialized. */
  10496. if (eep_config.max_dvc_qng == 0) {
  10497. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10498. } else {
  10499. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10500. }
  10501. }
  10502. /*
  10503. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10504. * set 'max_dvc_qng' to 'max_host_qng'.
  10505. */
  10506. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10507. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10508. }
  10509. /*
  10510. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  10511. * values based on possibly adjusted EEPROM values.
  10512. */
  10513. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10514. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10515. /*
  10516. * If the EEPROM 'termination' field is set to automatic (0), then set
  10517. * the ASC_DVC_CFG 'termination' field to automatic also.
  10518. *
  10519. * If the termination is specified with a non-zero 'termination'
  10520. * value check that a legal value is set and set the ASC_DVC_CFG
  10521. * 'termination' field appropriately.
  10522. */
  10523. if (eep_config.termination_se == 0) {
  10524. termination = 0; /* auto termination for SE */
  10525. } else {
  10526. /* Enable manual control with low off / high off. */
  10527. if (eep_config.termination_se == 1) {
  10528. termination = 0;
  10529. /* Enable manual control with low off / high on. */
  10530. } else if (eep_config.termination_se == 2) {
  10531. termination = TERM_SE_HI;
  10532. /* Enable manual control with low on / high on. */
  10533. } else if (eep_config.termination_se == 3) {
  10534. termination = TERM_SE;
  10535. } else {
  10536. /*
  10537. * The EEPROM 'termination_se' field contains a bad value.
  10538. * Use automatic termination instead.
  10539. */
  10540. termination = 0;
  10541. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10542. }
  10543. }
  10544. if (eep_config.termination_lvd == 0) {
  10545. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10546. } else {
  10547. /* Enable manual control with low off / high off. */
  10548. if (eep_config.termination_lvd == 1) {
  10549. asc_dvc->cfg->termination = termination;
  10550. /* Enable manual control with low off / high on. */
  10551. } else if (eep_config.termination_lvd == 2) {
  10552. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10553. /* Enable manual control with low on / high on. */
  10554. } else if (eep_config.termination_lvd == 3) {
  10555. asc_dvc->cfg->termination = termination | TERM_LVD;
  10556. } else {
  10557. /*
  10558. * The EEPROM 'termination_lvd' field contains a bad value.
  10559. * Use automatic termination instead.
  10560. */
  10561. asc_dvc->cfg->termination = termination;
  10562. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10563. }
  10564. }
  10565. return warn_code;
  10566. }
  10567. /*
  10568. * Initialize the ADV_DVC_VAR structure.
  10569. *
  10570. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10571. *
  10572. * For a non-fatal error return a warning code. If there are no warnings
  10573. * then 0 is returned.
  10574. */
  10575. static int __devinit
  10576. AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  10577. {
  10578. struct asc_board *board = shost_priv(shost);
  10579. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  10580. unsigned short warn_code = 0;
  10581. AdvPortAddr iop_base = asc_dvc->iop_base;
  10582. u16 cmd;
  10583. int status;
  10584. asc_dvc->err_code = 0;
  10585. /*
  10586. * Save the state of the PCI Configuration Command Register
  10587. * "Parity Error Response Control" Bit. If the bit is clear (0),
  10588. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  10589. * DMA parity errors.
  10590. */
  10591. asc_dvc->cfg->control_flag = 0;
  10592. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  10593. if ((cmd & PCI_COMMAND_PARITY) == 0)
  10594. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  10595. asc_dvc->cfg->chip_version =
  10596. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  10597. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  10598. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  10599. (ushort)ADV_CHIP_ID_BYTE);
  10600. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  10601. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  10602. (ushort)ADV_CHIP_ID_WORD);
  10603. /*
  10604. * Reset the chip to start and allow register writes.
  10605. */
  10606. if (AdvFindSignature(iop_base) == 0) {
  10607. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  10608. return ADV_ERROR;
  10609. } else {
  10610. /*
  10611. * The caller must set 'chip_type' to a valid setting.
  10612. */
  10613. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  10614. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  10615. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  10616. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  10617. return ADV_ERROR;
  10618. }
  10619. /*
  10620. * Reset Chip.
  10621. */
  10622. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10623. ADV_CTRL_REG_CMD_RESET);
  10624. mdelay(100);
  10625. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10626. ADV_CTRL_REG_CMD_WR_IO_REG);
  10627. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  10628. status = AdvInitFrom38C1600EEP(asc_dvc);
  10629. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10630. status = AdvInitFrom38C0800EEP(asc_dvc);
  10631. } else {
  10632. status = AdvInitFrom3550EEP(asc_dvc);
  10633. }
  10634. warn_code |= status;
  10635. }
  10636. if (warn_code != 0)
  10637. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  10638. if (asc_dvc->err_code)
  10639. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  10640. asc_dvc->err_code);
  10641. return asc_dvc->err_code;
  10642. }
  10643. #endif
  10644. static struct scsi_host_template advansys_template = {
  10645. .proc_name = DRV_NAME,
  10646. #ifdef CONFIG_PROC_FS
  10647. .proc_info = advansys_proc_info,
  10648. #endif
  10649. .name = DRV_NAME,
  10650. .info = advansys_info,
  10651. .queuecommand = advansys_queuecommand,
  10652. .eh_bus_reset_handler = advansys_reset,
  10653. .bios_param = advansys_biosparam,
  10654. .slave_configure = advansys_slave_configure,
  10655. /*
  10656. * Because the driver may control an ISA adapter 'unchecked_isa_dma'
  10657. * must be set. The flag will be cleared in advansys_board_found
  10658. * for non-ISA adapters.
  10659. */
  10660. .unchecked_isa_dma = 1,
  10661. /*
  10662. * All adapters controlled by this driver are capable of large
  10663. * scatter-gather lists. According to the mid-level SCSI documentation
  10664. * this obviates any performance gain provided by setting
  10665. * 'use_clustering'. But empirically while CPU utilization is increased
  10666. * by enabling clustering, I/O throughput increases as well.
  10667. */
  10668. .use_clustering = ENABLE_CLUSTERING,
  10669. };
  10670. static int __devinit advansys_wide_init_chip(struct Scsi_Host *shost)
  10671. {
  10672. struct asc_board *board = shost_priv(shost);
  10673. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10674. int req_cnt = 0;
  10675. adv_req_t *reqp = NULL;
  10676. int sg_cnt = 0;
  10677. adv_sgblk_t *sgp;
  10678. int warn_code, err_code;
  10679. /*
  10680. * Allocate buffer carrier structures. The total size
  10681. * is about 4 KB, so allocate all at once.
  10682. */
  10683. adv_dvc->carrier_buf = kmalloc(ADV_CARRIER_BUFSIZE, GFP_KERNEL);
  10684. ASC_DBG(1, "carrier_buf 0x%p\n", adv_dvc->carrier_buf);
  10685. if (!adv_dvc->carrier_buf)
  10686. goto kmalloc_failed;
  10687. /*
  10688. * Allocate up to 'max_host_qng' request structures for the Wide
  10689. * board. The total size is about 16 KB, so allocate all at once.
  10690. * If the allocation fails decrement and try again.
  10691. */
  10692. for (req_cnt = adv_dvc->max_host_qng; req_cnt > 0; req_cnt--) {
  10693. reqp = kmalloc(sizeof(adv_req_t) * req_cnt, GFP_KERNEL);
  10694. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", reqp, req_cnt,
  10695. (ulong)sizeof(adv_req_t) * req_cnt);
  10696. if (reqp)
  10697. break;
  10698. }
  10699. if (!reqp)
  10700. goto kmalloc_failed;
  10701. adv_dvc->orig_reqp = reqp;
  10702. /*
  10703. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  10704. * the Wide board. Each structure is about 136 bytes.
  10705. */
  10706. board->adv_sgblkp = NULL;
  10707. for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
  10708. sgp = kmalloc(sizeof(adv_sgblk_t), GFP_KERNEL);
  10709. if (!sgp)
  10710. break;
  10711. sgp->next_sgblkp = board->adv_sgblkp;
  10712. board->adv_sgblkp = sgp;
  10713. }
  10714. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", sg_cnt, sizeof(adv_sgblk_t),
  10715. sizeof(adv_sgblk_t) * sg_cnt);
  10716. if (!board->adv_sgblkp)
  10717. goto kmalloc_failed;
  10718. /*
  10719. * Point 'adv_reqp' to the request structures and
  10720. * link them together.
  10721. */
  10722. req_cnt--;
  10723. reqp[req_cnt].next_reqp = NULL;
  10724. for (; req_cnt > 0; req_cnt--) {
  10725. reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
  10726. }
  10727. board->adv_reqp = &reqp[0];
  10728. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  10729. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  10730. warn_code = AdvInitAsc3550Driver(adv_dvc);
  10731. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10732. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  10733. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  10734. } else {
  10735. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  10736. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  10737. }
  10738. err_code = adv_dvc->err_code;
  10739. if (warn_code || err_code) {
  10740. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  10741. "0x%x\n", warn_code, err_code);
  10742. }
  10743. goto exit;
  10744. kmalloc_failed:
  10745. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  10746. err_code = ADV_ERROR;
  10747. exit:
  10748. return err_code;
  10749. }
  10750. static void advansys_wide_free_mem(struct asc_board *board)
  10751. {
  10752. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10753. kfree(adv_dvc->carrier_buf);
  10754. adv_dvc->carrier_buf = NULL;
  10755. kfree(adv_dvc->orig_reqp);
  10756. adv_dvc->orig_reqp = board->adv_reqp = NULL;
  10757. while (board->adv_sgblkp) {
  10758. adv_sgblk_t *sgp = board->adv_sgblkp;
  10759. board->adv_sgblkp = sgp->next_sgblkp;
  10760. kfree(sgp);
  10761. }
  10762. }
  10763. static int __devinit advansys_board_found(struct Scsi_Host *shost,
  10764. unsigned int iop, int bus_type)
  10765. {
  10766. struct pci_dev *pdev;
  10767. struct asc_board *boardp = shost_priv(shost);
  10768. ASC_DVC_VAR *asc_dvc_varp = NULL;
  10769. ADV_DVC_VAR *adv_dvc_varp = NULL;
  10770. int share_irq, warn_code, ret;
  10771. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  10772. if (ASC_NARROW_BOARD(boardp)) {
  10773. ASC_DBG(1, "narrow board\n");
  10774. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  10775. asc_dvc_varp->bus_type = bus_type;
  10776. asc_dvc_varp->drv_ptr = boardp;
  10777. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  10778. asc_dvc_varp->iop_base = iop;
  10779. } else {
  10780. #ifdef CONFIG_PCI
  10781. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  10782. adv_dvc_varp->drv_ptr = boardp;
  10783. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  10784. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  10785. ASC_DBG(1, "wide board ASC-3550\n");
  10786. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  10787. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  10788. ASC_DBG(1, "wide board ASC-38C0800\n");
  10789. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  10790. } else {
  10791. ASC_DBG(1, "wide board ASC-38C1600\n");
  10792. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  10793. }
  10794. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  10795. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  10796. if (!boardp->ioremap_addr) {
  10797. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  10798. "returned NULL\n",
  10799. (long)pci_resource_start(pdev, 1),
  10800. boardp->asc_n_io_port);
  10801. ret = -ENODEV;
  10802. goto err_shost;
  10803. }
  10804. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  10805. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  10806. /*
  10807. * Even though it isn't used to access wide boards, other
  10808. * than for the debug line below, save I/O Port address so
  10809. * that it can be reported.
  10810. */
  10811. boardp->ioport = iop;
  10812. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  10813. (ushort)inp(iop + 1), (ushort)inpw(iop));
  10814. #endif /* CONFIG_PCI */
  10815. }
  10816. #ifdef CONFIG_PROC_FS
  10817. /*
  10818. * Allocate buffer for printing information from
  10819. * /proc/scsi/advansys/[0...].
  10820. */
  10821. boardp->prtbuf = kmalloc(ASC_PRTBUF_SIZE, GFP_KERNEL);
  10822. if (!boardp->prtbuf) {
  10823. shost_printk(KERN_ERR, shost, "kmalloc(%d) returned NULL\n",
  10824. ASC_PRTBUF_SIZE);
  10825. ret = -ENOMEM;
  10826. goto err_unmap;
  10827. }
  10828. #endif /* CONFIG_PROC_FS */
  10829. if (ASC_NARROW_BOARD(boardp)) {
  10830. /*
  10831. * Set the board bus type and PCI IRQ before
  10832. * calling AscInitGetConfig().
  10833. */
  10834. switch (asc_dvc_varp->bus_type) {
  10835. #ifdef CONFIG_ISA
  10836. case ASC_IS_ISA:
  10837. shost->unchecked_isa_dma = TRUE;
  10838. share_irq = 0;
  10839. break;
  10840. case ASC_IS_VL:
  10841. shost->unchecked_isa_dma = FALSE;
  10842. share_irq = 0;
  10843. break;
  10844. case ASC_IS_EISA:
  10845. shost->unchecked_isa_dma = FALSE;
  10846. share_irq = IRQF_SHARED;
  10847. break;
  10848. #endif /* CONFIG_ISA */
  10849. #ifdef CONFIG_PCI
  10850. case ASC_IS_PCI:
  10851. shost->unchecked_isa_dma = FALSE;
  10852. share_irq = IRQF_SHARED;
  10853. break;
  10854. #endif /* CONFIG_PCI */
  10855. default:
  10856. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  10857. "%d\n", asc_dvc_varp->bus_type);
  10858. shost->unchecked_isa_dma = TRUE;
  10859. share_irq = 0;
  10860. break;
  10861. }
  10862. /*
  10863. * NOTE: AscInitGetConfig() may change the board's
  10864. * bus_type value. The bus_type value should no
  10865. * longer be used. If the bus_type field must be
  10866. * referenced only use the bit-wise AND operator "&".
  10867. */
  10868. ASC_DBG(2, "AscInitGetConfig()\n");
  10869. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  10870. } else {
  10871. #ifdef CONFIG_PCI
  10872. /*
  10873. * For Wide boards set PCI information before calling
  10874. * AdvInitGetConfig().
  10875. */
  10876. shost->unchecked_isa_dma = FALSE;
  10877. share_irq = IRQF_SHARED;
  10878. ASC_DBG(2, "AdvInitGetConfig()\n");
  10879. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  10880. #endif /* CONFIG_PCI */
  10881. }
  10882. if (ret)
  10883. goto err_free_proc;
  10884. /*
  10885. * Save the EEPROM configuration so that it can be displayed
  10886. * from /proc/scsi/advansys/[0...].
  10887. */
  10888. if (ASC_NARROW_BOARD(boardp)) {
  10889. ASCEEP_CONFIG *ep;
  10890. /*
  10891. * Set the adapter's target id bit in the 'init_tidmask' field.
  10892. */
  10893. boardp->init_tidmask |=
  10894. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  10895. /*
  10896. * Save EEPROM settings for the board.
  10897. */
  10898. ep = &boardp->eep_config.asc_eep;
  10899. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  10900. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  10901. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  10902. ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
  10903. ep->start_motor = asc_dvc_varp->start_motor;
  10904. ep->cntl = asc_dvc_varp->dvc_cntl;
  10905. ep->no_scam = asc_dvc_varp->no_scam;
  10906. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  10907. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  10908. /* 'max_tag_qng' is set to the same value for every device. */
  10909. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  10910. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  10911. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  10912. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  10913. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  10914. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  10915. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  10916. /*
  10917. * Modify board configuration.
  10918. */
  10919. ASC_DBG(2, "AscInitSetConfig()\n");
  10920. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  10921. if (ret)
  10922. goto err_free_proc;
  10923. } else {
  10924. ADVEEP_3550_CONFIG *ep_3550;
  10925. ADVEEP_38C0800_CONFIG *ep_38C0800;
  10926. ADVEEP_38C1600_CONFIG *ep_38C1600;
  10927. /*
  10928. * Save Wide EEP Configuration Information.
  10929. */
  10930. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  10931. ep_3550 = &boardp->eep_config.adv_3550_eep;
  10932. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  10933. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  10934. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10935. ep_3550->termination = adv_dvc_varp->cfg->termination;
  10936. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  10937. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10938. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  10939. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  10940. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  10941. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  10942. ep_3550->start_motor = adv_dvc_varp->start_motor;
  10943. ep_3550->scsi_reset_delay =
  10944. adv_dvc_varp->scsi_reset_wait;
  10945. ep_3550->serial_number_word1 =
  10946. adv_dvc_varp->cfg->serial1;
  10947. ep_3550->serial_number_word2 =
  10948. adv_dvc_varp->cfg->serial2;
  10949. ep_3550->serial_number_word3 =
  10950. adv_dvc_varp->cfg->serial3;
  10951. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  10952. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  10953. ep_38C0800->adapter_scsi_id =
  10954. adv_dvc_varp->chip_scsi_id;
  10955. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  10956. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10957. ep_38C0800->termination_lvd =
  10958. adv_dvc_varp->cfg->termination;
  10959. ep_38C0800->disc_enable =
  10960. adv_dvc_varp->cfg->disc_enable;
  10961. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10962. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  10963. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10964. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10965. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10966. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10967. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10968. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10969. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  10970. ep_38C0800->scsi_reset_delay =
  10971. adv_dvc_varp->scsi_reset_wait;
  10972. ep_38C0800->serial_number_word1 =
  10973. adv_dvc_varp->cfg->serial1;
  10974. ep_38C0800->serial_number_word2 =
  10975. adv_dvc_varp->cfg->serial2;
  10976. ep_38C0800->serial_number_word3 =
  10977. adv_dvc_varp->cfg->serial3;
  10978. } else {
  10979. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  10980. ep_38C1600->adapter_scsi_id =
  10981. adv_dvc_varp->chip_scsi_id;
  10982. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  10983. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10984. ep_38C1600->termination_lvd =
  10985. adv_dvc_varp->cfg->termination;
  10986. ep_38C1600->disc_enable =
  10987. adv_dvc_varp->cfg->disc_enable;
  10988. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10989. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  10990. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10991. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10992. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10993. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10994. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10995. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10996. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  10997. ep_38C1600->scsi_reset_delay =
  10998. adv_dvc_varp->scsi_reset_wait;
  10999. ep_38C1600->serial_number_word1 =
  11000. adv_dvc_varp->cfg->serial1;
  11001. ep_38C1600->serial_number_word2 =
  11002. adv_dvc_varp->cfg->serial2;
  11003. ep_38C1600->serial_number_word3 =
  11004. adv_dvc_varp->cfg->serial3;
  11005. }
  11006. /*
  11007. * Set the adapter's target id bit in the 'init_tidmask' field.
  11008. */
  11009. boardp->init_tidmask |=
  11010. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  11011. }
  11012. /*
  11013. * Channels are numbered beginning with 0. For AdvanSys one host
  11014. * structure supports one channel. Multi-channel boards have a
  11015. * separate host structure for each channel.
  11016. */
  11017. shost->max_channel = 0;
  11018. if (ASC_NARROW_BOARD(boardp)) {
  11019. shost->max_id = ASC_MAX_TID + 1;
  11020. shost->max_lun = ASC_MAX_LUN + 1;
  11021. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  11022. shost->io_port = asc_dvc_varp->iop_base;
  11023. boardp->asc_n_io_port = ASC_IOADR_GAP;
  11024. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  11025. /* Set maximum number of queues the adapter can handle. */
  11026. shost->can_queue = asc_dvc_varp->max_total_qng;
  11027. } else {
  11028. shost->max_id = ADV_MAX_TID + 1;
  11029. shost->max_lun = ADV_MAX_LUN + 1;
  11030. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  11031. /*
  11032. * Save the I/O Port address and length even though
  11033. * I/O ports are not used to access Wide boards.
  11034. * Instead the Wide boards are accessed with
  11035. * PCI Memory Mapped I/O.
  11036. */
  11037. shost->io_port = iop;
  11038. shost->this_id = adv_dvc_varp->chip_scsi_id;
  11039. /* Set maximum number of queues the adapter can handle. */
  11040. shost->can_queue = adv_dvc_varp->max_host_qng;
  11041. }
  11042. /*
  11043. * Following v1.3.89, 'cmd_per_lun' is no longer needed
  11044. * and should be set to zero.
  11045. *
  11046. * But because of a bug introduced in v1.3.89 if the driver is
  11047. * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
  11048. * SCSI function 'allocate_device' will panic. To allow the driver
  11049. * to work as a module in these kernels set 'cmd_per_lun' to 1.
  11050. *
  11051. * Note: This is wrong. cmd_per_lun should be set to the depth
  11052. * you want on untagged devices always.
  11053. #ifdef MODULE
  11054. */
  11055. shost->cmd_per_lun = 1;
  11056. /* #else
  11057. shost->cmd_per_lun = 0;
  11058. #endif */
  11059. /*
  11060. * Set the maximum number of scatter-gather elements the
  11061. * adapter can handle.
  11062. */
  11063. if (ASC_NARROW_BOARD(boardp)) {
  11064. /*
  11065. * Allow two commands with 'sg_tablesize' scatter-gather
  11066. * elements to be executed simultaneously. This value is
  11067. * the theoretical hardware limit. It may be decreased
  11068. * below.
  11069. */
  11070. shost->sg_tablesize =
  11071. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  11072. ASC_SG_LIST_PER_Q) + 1;
  11073. } else {
  11074. shost->sg_tablesize = ADV_MAX_SG_LIST;
  11075. }
  11076. /*
  11077. * The value of 'sg_tablesize' can not exceed the SCSI
  11078. * mid-level driver definition of SG_ALL. SG_ALL also
  11079. * must not be exceeded, because it is used to define the
  11080. * size of the scatter-gather table in 'struct asc_sg_head'.
  11081. */
  11082. if (shost->sg_tablesize > SG_ALL) {
  11083. shost->sg_tablesize = SG_ALL;
  11084. }
  11085. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  11086. /* BIOS start address. */
  11087. if (ASC_NARROW_BOARD(boardp)) {
  11088. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  11089. asc_dvc_varp->bus_type);
  11090. } else {
  11091. /*
  11092. * Fill-in BIOS board variables. The Wide BIOS saves
  11093. * information in LRAM that is used by the driver.
  11094. */
  11095. AdvReadWordLram(adv_dvc_varp->iop_base,
  11096. BIOS_SIGNATURE, boardp->bios_signature);
  11097. AdvReadWordLram(adv_dvc_varp->iop_base,
  11098. BIOS_VERSION, boardp->bios_version);
  11099. AdvReadWordLram(adv_dvc_varp->iop_base,
  11100. BIOS_CODESEG, boardp->bios_codeseg);
  11101. AdvReadWordLram(adv_dvc_varp->iop_base,
  11102. BIOS_CODELEN, boardp->bios_codelen);
  11103. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  11104. boardp->bios_signature, boardp->bios_version);
  11105. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  11106. boardp->bios_codeseg, boardp->bios_codelen);
  11107. /*
  11108. * If the BIOS saved a valid signature, then fill in
  11109. * the BIOS code segment base address.
  11110. */
  11111. if (boardp->bios_signature == 0x55AA) {
  11112. /*
  11113. * Convert x86 realmode code segment to a linear
  11114. * address by shifting left 4.
  11115. */
  11116. shost->base = ((ulong)boardp->bios_codeseg << 4);
  11117. } else {
  11118. shost->base = 0;
  11119. }
  11120. }
  11121. /*
  11122. * Register Board Resources - I/O Port, DMA, IRQ
  11123. */
  11124. /* Register DMA Channel for Narrow boards. */
  11125. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  11126. #ifdef CONFIG_ISA
  11127. if (ASC_NARROW_BOARD(boardp)) {
  11128. /* Register DMA channel for ISA bus. */
  11129. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  11130. shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
  11131. ret = request_dma(shost->dma_channel, DRV_NAME);
  11132. if (ret) {
  11133. shost_printk(KERN_ERR, shost, "request_dma() "
  11134. "%d failed %d\n",
  11135. shost->dma_channel, ret);
  11136. goto err_free_proc;
  11137. }
  11138. AscEnableIsaDma(shost->dma_channel);
  11139. }
  11140. }
  11141. #endif /* CONFIG_ISA */
  11142. /* Register IRQ Number. */
  11143. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  11144. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  11145. DRV_NAME, shost);
  11146. if (ret) {
  11147. if (ret == -EBUSY) {
  11148. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11149. "already in use\n", boardp->irq);
  11150. } else if (ret == -EINVAL) {
  11151. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11152. "not valid\n", boardp->irq);
  11153. } else {
  11154. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11155. "failed with %d\n", boardp->irq, ret);
  11156. }
  11157. goto err_free_dma;
  11158. }
  11159. /*
  11160. * Initialize board RISC chip and enable interrupts.
  11161. */
  11162. if (ASC_NARROW_BOARD(boardp)) {
  11163. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  11164. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  11165. if (!asc_dvc_varp->overrun_buf) {
  11166. ret = -ENOMEM;
  11167. goto err_free_irq;
  11168. }
  11169. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  11170. if (warn_code || asc_dvc_varp->err_code) {
  11171. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  11172. "warn 0x%x, error 0x%x\n",
  11173. asc_dvc_varp->init_state, warn_code,
  11174. asc_dvc_varp->err_code);
  11175. if (!asc_dvc_varp->overrun_dma) {
  11176. ret = -ENODEV;
  11177. goto err_free_mem;
  11178. }
  11179. }
  11180. } else {
  11181. if (advansys_wide_init_chip(shost)) {
  11182. ret = -ENODEV;
  11183. goto err_free_mem;
  11184. }
  11185. }
  11186. ASC_DBG_PRT_SCSI_HOST(2, shost);
  11187. ret = scsi_add_host(shost, boardp->dev);
  11188. if (ret)
  11189. goto err_free_mem;
  11190. scsi_scan_host(shost);
  11191. return 0;
  11192. err_free_mem:
  11193. if (ASC_NARROW_BOARD(boardp)) {
  11194. if (asc_dvc_varp->overrun_dma)
  11195. dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
  11196. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  11197. kfree(asc_dvc_varp->overrun_buf);
  11198. } else
  11199. advansys_wide_free_mem(boardp);
  11200. err_free_irq:
  11201. free_irq(boardp->irq, shost);
  11202. err_free_dma:
  11203. #ifdef CONFIG_ISA
  11204. if (shost->dma_channel != NO_ISA_DMA)
  11205. free_dma(shost->dma_channel);
  11206. #endif
  11207. err_free_proc:
  11208. kfree(boardp->prtbuf);
  11209. err_unmap:
  11210. if (boardp->ioremap_addr)
  11211. iounmap(boardp->ioremap_addr);
  11212. err_shost:
  11213. return ret;
  11214. }
  11215. /*
  11216. * advansys_release()
  11217. *
  11218. * Release resources allocated for a single AdvanSys adapter.
  11219. */
  11220. static int advansys_release(struct Scsi_Host *shost)
  11221. {
  11222. struct asc_board *board = shost_priv(shost);
  11223. ASC_DBG(1, "begin\n");
  11224. scsi_remove_host(shost);
  11225. free_irq(board->irq, shost);
  11226. #ifdef CONFIG_ISA
  11227. if (shost->dma_channel != NO_ISA_DMA) {
  11228. ASC_DBG(1, "free_dma()\n");
  11229. free_dma(shost->dma_channel);
  11230. }
  11231. #endif
  11232. if (ASC_NARROW_BOARD(board)) {
  11233. dma_unmap_single(board->dev,
  11234. board->dvc_var.asc_dvc_var.overrun_dma,
  11235. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  11236. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  11237. } else {
  11238. iounmap(board->ioremap_addr);
  11239. advansys_wide_free_mem(board);
  11240. }
  11241. kfree(board->prtbuf);
  11242. scsi_host_put(shost);
  11243. ASC_DBG(1, "end\n");
  11244. return 0;
  11245. }
  11246. #define ASC_IOADR_TABLE_MAX_IX 11
  11247. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  11248. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  11249. 0x0210, 0x0230, 0x0250, 0x0330
  11250. };
  11251. /*
  11252. * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
  11253. * 00: 10
  11254. * 01: 11
  11255. * 10: 12
  11256. * 11: 15
  11257. */
  11258. static unsigned int __devinit advansys_isa_irq_no(PortAddr iop_base)
  11259. {
  11260. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  11261. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
  11262. if (chip_irq == 13)
  11263. chip_irq = 15;
  11264. return chip_irq;
  11265. }
  11266. static int __devinit advansys_isa_probe(struct device *dev, unsigned int id)
  11267. {
  11268. int err = -ENODEV;
  11269. PortAddr iop_base = _asc_def_iop_base[id];
  11270. struct Scsi_Host *shost;
  11271. struct asc_board *board;
  11272. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  11273. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  11274. return -ENODEV;
  11275. }
  11276. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  11277. if (!AscFindSignature(iop_base))
  11278. goto release_region;
  11279. if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
  11280. goto release_region;
  11281. err = -ENOMEM;
  11282. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11283. if (!shost)
  11284. goto release_region;
  11285. board = shost_priv(shost);
  11286. board->irq = advansys_isa_irq_no(iop_base);
  11287. board->dev = dev;
  11288. err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
  11289. if (err)
  11290. goto free_host;
  11291. dev_set_drvdata(dev, shost);
  11292. return 0;
  11293. free_host:
  11294. scsi_host_put(shost);
  11295. release_region:
  11296. release_region(iop_base, ASC_IOADR_GAP);
  11297. return err;
  11298. }
  11299. static int __devexit advansys_isa_remove(struct device *dev, unsigned int id)
  11300. {
  11301. int ioport = _asc_def_iop_base[id];
  11302. advansys_release(dev_get_drvdata(dev));
  11303. release_region(ioport, ASC_IOADR_GAP);
  11304. return 0;
  11305. }
  11306. static struct isa_driver advansys_isa_driver = {
  11307. .probe = advansys_isa_probe,
  11308. .remove = __devexit_p(advansys_isa_remove),
  11309. .driver = {
  11310. .owner = THIS_MODULE,
  11311. .name = DRV_NAME,
  11312. },
  11313. };
  11314. /*
  11315. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  11316. * 000: invalid
  11317. * 001: 10
  11318. * 010: 11
  11319. * 011: 12
  11320. * 100: invalid
  11321. * 101: 14
  11322. * 110: 15
  11323. * 111: invalid
  11324. */
  11325. static unsigned int __devinit advansys_vlb_irq_no(PortAddr iop_base)
  11326. {
  11327. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  11328. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  11329. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  11330. return 0;
  11331. return chip_irq;
  11332. }
  11333. static int __devinit advansys_vlb_probe(struct device *dev, unsigned int id)
  11334. {
  11335. int err = -ENODEV;
  11336. PortAddr iop_base = _asc_def_iop_base[id];
  11337. struct Scsi_Host *shost;
  11338. struct asc_board *board;
  11339. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  11340. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  11341. return -ENODEV;
  11342. }
  11343. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  11344. if (!AscFindSignature(iop_base))
  11345. goto release_region;
  11346. /*
  11347. * I don't think this condition can actually happen, but the old
  11348. * driver did it, and the chances of finding a VLB setup in 2007
  11349. * to do testing with is slight to none.
  11350. */
  11351. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  11352. goto release_region;
  11353. err = -ENOMEM;
  11354. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11355. if (!shost)
  11356. goto release_region;
  11357. board = shost_priv(shost);
  11358. board->irq = advansys_vlb_irq_no(iop_base);
  11359. board->dev = dev;
  11360. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  11361. if (err)
  11362. goto free_host;
  11363. dev_set_drvdata(dev, shost);
  11364. return 0;
  11365. free_host:
  11366. scsi_host_put(shost);
  11367. release_region:
  11368. release_region(iop_base, ASC_IOADR_GAP);
  11369. return -ENODEV;
  11370. }
  11371. static struct isa_driver advansys_vlb_driver = {
  11372. .probe = advansys_vlb_probe,
  11373. .remove = __devexit_p(advansys_isa_remove),
  11374. .driver = {
  11375. .owner = THIS_MODULE,
  11376. .name = "advansys_vlb",
  11377. },
  11378. };
  11379. static struct eisa_device_id advansys_eisa_table[] __devinitdata = {
  11380. { "ABP7401" },
  11381. { "ABP7501" },
  11382. { "" }
  11383. };
  11384. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  11385. /*
  11386. * EISA is a little more tricky than PCI; each EISA device may have two
  11387. * channels, and this driver is written to make each channel its own Scsi_Host
  11388. */
  11389. struct eisa_scsi_data {
  11390. struct Scsi_Host *host[2];
  11391. };
  11392. /*
  11393. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  11394. * 000: 10
  11395. * 001: 11
  11396. * 010: 12
  11397. * 011: invalid
  11398. * 100: 14
  11399. * 101: 15
  11400. * 110: invalid
  11401. * 111: invalid
  11402. */
  11403. static unsigned int __devinit advansys_eisa_irq_no(struct eisa_device *edev)
  11404. {
  11405. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  11406. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  11407. if ((chip_irq == 13) || (chip_irq > 15))
  11408. return 0;
  11409. return chip_irq;
  11410. }
  11411. static int __devinit advansys_eisa_probe(struct device *dev)
  11412. {
  11413. int i, ioport, irq = 0;
  11414. int err;
  11415. struct eisa_device *edev = to_eisa_device(dev);
  11416. struct eisa_scsi_data *data;
  11417. err = -ENOMEM;
  11418. data = kzalloc(sizeof(*data), GFP_KERNEL);
  11419. if (!data)
  11420. goto fail;
  11421. ioport = edev->base_addr + 0xc30;
  11422. err = -ENODEV;
  11423. for (i = 0; i < 2; i++, ioport += 0x20) {
  11424. struct asc_board *board;
  11425. struct Scsi_Host *shost;
  11426. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  11427. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  11428. ioport + ASC_IOADR_GAP - 1);
  11429. continue;
  11430. }
  11431. if (!AscFindSignature(ioport)) {
  11432. release_region(ioport, ASC_IOADR_GAP);
  11433. continue;
  11434. }
  11435. /*
  11436. * I don't know why we need to do this for EISA chips, but
  11437. * not for any others. It looks to be equivalent to
  11438. * AscGetChipCfgMsw, but I may have overlooked something,
  11439. * so I'm not converting it until I get an EISA board to
  11440. * test with.
  11441. */
  11442. inw(ioport + 4);
  11443. if (!irq)
  11444. irq = advansys_eisa_irq_no(edev);
  11445. err = -ENOMEM;
  11446. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11447. if (!shost)
  11448. goto release_region;
  11449. board = shost_priv(shost);
  11450. board->irq = irq;
  11451. board->dev = dev;
  11452. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  11453. if (!err) {
  11454. data->host[i] = shost;
  11455. continue;
  11456. }
  11457. scsi_host_put(shost);
  11458. release_region:
  11459. release_region(ioport, ASC_IOADR_GAP);
  11460. break;
  11461. }
  11462. if (err)
  11463. goto free_data;
  11464. dev_set_drvdata(dev, data);
  11465. return 0;
  11466. free_data:
  11467. kfree(data->host[0]);
  11468. kfree(data->host[1]);
  11469. kfree(data);
  11470. fail:
  11471. return err;
  11472. }
  11473. static __devexit int advansys_eisa_remove(struct device *dev)
  11474. {
  11475. int i;
  11476. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  11477. for (i = 0; i < 2; i++) {
  11478. int ioport;
  11479. struct Scsi_Host *shost = data->host[i];
  11480. if (!shost)
  11481. continue;
  11482. ioport = shost->io_port;
  11483. advansys_release(shost);
  11484. release_region(ioport, ASC_IOADR_GAP);
  11485. }
  11486. kfree(data);
  11487. return 0;
  11488. }
  11489. static struct eisa_driver advansys_eisa_driver = {
  11490. .id_table = advansys_eisa_table,
  11491. .driver = {
  11492. .name = DRV_NAME,
  11493. .probe = advansys_eisa_probe,
  11494. .remove = __devexit_p(advansys_eisa_remove),
  11495. }
  11496. };
  11497. /* PCI Devices supported by this driver */
  11498. static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
  11499. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  11500. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11501. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  11502. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11503. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  11504. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11505. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  11506. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11507. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  11508. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11509. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  11510. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11511. {}
  11512. };
  11513. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  11514. static void __devinit advansys_set_latency(struct pci_dev *pdev)
  11515. {
  11516. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  11517. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  11518. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  11519. } else {
  11520. u8 latency;
  11521. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  11522. if (latency < 0x20)
  11523. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  11524. }
  11525. }
  11526. static int __devinit
  11527. advansys_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11528. {
  11529. int err, ioport;
  11530. struct Scsi_Host *shost;
  11531. struct asc_board *board;
  11532. err = pci_enable_device(pdev);
  11533. if (err)
  11534. goto fail;
  11535. err = pci_request_regions(pdev, DRV_NAME);
  11536. if (err)
  11537. goto disable_device;
  11538. pci_set_master(pdev);
  11539. advansys_set_latency(pdev);
  11540. err = -ENODEV;
  11541. if (pci_resource_len(pdev, 0) == 0)
  11542. goto release_region;
  11543. ioport = pci_resource_start(pdev, 0);
  11544. err = -ENOMEM;
  11545. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11546. if (!shost)
  11547. goto release_region;
  11548. board = shost_priv(shost);
  11549. board->irq = pdev->irq;
  11550. board->dev = &pdev->dev;
  11551. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  11552. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  11553. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  11554. board->flags |= ASC_IS_WIDE_BOARD;
  11555. }
  11556. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  11557. if (err)
  11558. goto free_host;
  11559. pci_set_drvdata(pdev, shost);
  11560. return 0;
  11561. free_host:
  11562. scsi_host_put(shost);
  11563. release_region:
  11564. pci_release_regions(pdev);
  11565. disable_device:
  11566. pci_disable_device(pdev);
  11567. fail:
  11568. return err;
  11569. }
  11570. static void __devexit advansys_pci_remove(struct pci_dev *pdev)
  11571. {
  11572. advansys_release(pci_get_drvdata(pdev));
  11573. pci_release_regions(pdev);
  11574. pci_disable_device(pdev);
  11575. }
  11576. static struct pci_driver advansys_pci_driver = {
  11577. .name = DRV_NAME,
  11578. .id_table = advansys_pci_tbl,
  11579. .probe = advansys_pci_probe,
  11580. .remove = __devexit_p(advansys_pci_remove),
  11581. };
  11582. static int __init advansys_init(void)
  11583. {
  11584. int error;
  11585. error = isa_register_driver(&advansys_isa_driver,
  11586. ASC_IOADR_TABLE_MAX_IX);
  11587. if (error)
  11588. goto fail;
  11589. error = isa_register_driver(&advansys_vlb_driver,
  11590. ASC_IOADR_TABLE_MAX_IX);
  11591. if (error)
  11592. goto unregister_isa;
  11593. error = eisa_driver_register(&advansys_eisa_driver);
  11594. if (error)
  11595. goto unregister_vlb;
  11596. error = pci_register_driver(&advansys_pci_driver);
  11597. if (error)
  11598. goto unregister_eisa;
  11599. return 0;
  11600. unregister_eisa:
  11601. eisa_driver_unregister(&advansys_eisa_driver);
  11602. unregister_vlb:
  11603. isa_unregister_driver(&advansys_vlb_driver);
  11604. unregister_isa:
  11605. isa_unregister_driver(&advansys_isa_driver);
  11606. fail:
  11607. return error;
  11608. }
  11609. static void __exit advansys_exit(void)
  11610. {
  11611. pci_unregister_driver(&advansys_pci_driver);
  11612. eisa_driver_unregister(&advansys_eisa_driver);
  11613. isa_unregister_driver(&advansys_vlb_driver);
  11614. isa_unregister_driver(&advansys_isa_driver);
  11615. }
  11616. module_init(advansys_init);
  11617. module_exit(advansys_exit);
  11618. MODULE_LICENSE("GPL");
  11619. MODULE_FIRMWARE("advansys/mcode.bin");
  11620. MODULE_FIRMWARE("advansys/3550.bin");
  11621. MODULE_FIRMWARE("advansys/38C0800.bin");
  11622. MODULE_FIRMWARE("advansys/38C1600.bin");