tg3.c 346 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <asm/system.h>
  41. #include <asm/io.h>
  42. #include <asm/byteorder.h>
  43. #include <asm/uaccess.h>
  44. #ifdef CONFIG_SPARC64
  45. #include <asm/idprom.h>
  46. #include <asm/oplib.h>
  47. #include <asm/pbm.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #ifdef NETIF_F_TSO
  55. #define TG3_TSO_SUPPORT 1
  56. #else
  57. #define TG3_TSO_SUPPORT 0
  58. #endif
  59. #include "tg3.h"
  60. #define DRV_MODULE_NAME "tg3"
  61. #define PFX DRV_MODULE_NAME ": "
  62. #define DRV_MODULE_VERSION "3.69"
  63. #define DRV_MODULE_RELDATE "November 15, 2006"
  64. #define TG3_DEF_MAC_MODE 0
  65. #define TG3_DEF_RX_MODE 0
  66. #define TG3_DEF_TX_MODE 0
  67. #define TG3_DEF_MSG_ENABLE \
  68. (NETIF_MSG_DRV | \
  69. NETIF_MSG_PROBE | \
  70. NETIF_MSG_LINK | \
  71. NETIF_MSG_TIMER | \
  72. NETIF_MSG_IFDOWN | \
  73. NETIF_MSG_IFUP | \
  74. NETIF_MSG_RX_ERR | \
  75. NETIF_MSG_TX_ERR)
  76. /* length of time before we decide the hardware is borked,
  77. * and dev->tx_timeout() should be called to fix the problem
  78. */
  79. #define TG3_TX_TIMEOUT (5 * HZ)
  80. /* hardware minimum and maximum for a single frame's data payload */
  81. #define TG3_MIN_MTU 60
  82. #define TG3_MAX_MTU(tp) \
  83. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  84. /* These numbers seem to be hard coded in the NIC firmware somehow.
  85. * You can't change the ring sizes, but you can change where you place
  86. * them in the NIC onboard memory.
  87. */
  88. #define TG3_RX_RING_SIZE 512
  89. #define TG3_DEF_RX_RING_PENDING 200
  90. #define TG3_RX_JUMBO_RING_SIZE 256
  91. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  92. /* Do not place this n-ring entries value into the tp struct itself,
  93. * we really want to expose these constants to GCC so that modulo et
  94. * al. operations are done with shifts and masks instead of with
  95. * hw multiply/modulo instructions. Another solution would be to
  96. * replace things like '% foo' with '& (foo - 1)'.
  97. */
  98. #define TG3_RX_RCB_RING_SIZE(tp) \
  99. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  100. #define TG3_TX_RING_SIZE 512
  101. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  102. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RING_SIZE)
  104. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  105. TG3_RX_JUMBO_RING_SIZE)
  106. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  107. TG3_RX_RCB_RING_SIZE(tp))
  108. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  109. TG3_TX_RING_SIZE)
  110. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  111. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  112. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  113. /* minimum number of free TX descriptors required to wake up TX process */
  114. #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
  115. /* number of ETHTOOL_GSTATS u64's */
  116. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  117. #define TG3_NUM_TEST 6
  118. static char version[] __devinitdata =
  119. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  120. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  121. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  122. MODULE_LICENSE("GPL");
  123. MODULE_VERSION(DRV_MODULE_VERSION);
  124. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  125. module_param(tg3_debug, int, 0);
  126. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  127. static struct pci_device_id tg3_pci_tbl[] = {
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  184. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  185. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  186. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  187. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  188. {}
  189. };
  190. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  191. static const struct {
  192. const char string[ETH_GSTRING_LEN];
  193. } ethtool_stats_keys[TG3_NUM_STATS] = {
  194. { "rx_octets" },
  195. { "rx_fragments" },
  196. { "rx_ucast_packets" },
  197. { "rx_mcast_packets" },
  198. { "rx_bcast_packets" },
  199. { "rx_fcs_errors" },
  200. { "rx_align_errors" },
  201. { "rx_xon_pause_rcvd" },
  202. { "rx_xoff_pause_rcvd" },
  203. { "rx_mac_ctrl_rcvd" },
  204. { "rx_xoff_entered" },
  205. { "rx_frame_too_long_errors" },
  206. { "rx_jabbers" },
  207. { "rx_undersize_packets" },
  208. { "rx_in_length_errors" },
  209. { "rx_out_length_errors" },
  210. { "rx_64_or_less_octet_packets" },
  211. { "rx_65_to_127_octet_packets" },
  212. { "rx_128_to_255_octet_packets" },
  213. { "rx_256_to_511_octet_packets" },
  214. { "rx_512_to_1023_octet_packets" },
  215. { "rx_1024_to_1522_octet_packets" },
  216. { "rx_1523_to_2047_octet_packets" },
  217. { "rx_2048_to_4095_octet_packets" },
  218. { "rx_4096_to_8191_octet_packets" },
  219. { "rx_8192_to_9022_octet_packets" },
  220. { "tx_octets" },
  221. { "tx_collisions" },
  222. { "tx_xon_sent" },
  223. { "tx_xoff_sent" },
  224. { "tx_flow_control" },
  225. { "tx_mac_errors" },
  226. { "tx_single_collisions" },
  227. { "tx_mult_collisions" },
  228. { "tx_deferred" },
  229. { "tx_excessive_collisions" },
  230. { "tx_late_collisions" },
  231. { "tx_collide_2times" },
  232. { "tx_collide_3times" },
  233. { "tx_collide_4times" },
  234. { "tx_collide_5times" },
  235. { "tx_collide_6times" },
  236. { "tx_collide_7times" },
  237. { "tx_collide_8times" },
  238. { "tx_collide_9times" },
  239. { "tx_collide_10times" },
  240. { "tx_collide_11times" },
  241. { "tx_collide_12times" },
  242. { "tx_collide_13times" },
  243. { "tx_collide_14times" },
  244. { "tx_collide_15times" },
  245. { "tx_ucast_packets" },
  246. { "tx_mcast_packets" },
  247. { "tx_bcast_packets" },
  248. { "tx_carrier_sense_errors" },
  249. { "tx_discards" },
  250. { "tx_errors" },
  251. { "dma_writeq_full" },
  252. { "dma_write_prioq_full" },
  253. { "rxbds_empty" },
  254. { "rx_discards" },
  255. { "rx_errors" },
  256. { "rx_threshold_hit" },
  257. { "dma_readq_full" },
  258. { "dma_read_prioq_full" },
  259. { "tx_comp_queue_full" },
  260. { "ring_set_send_prod_index" },
  261. { "ring_status_update" },
  262. { "nic_irqs" },
  263. { "nic_avoided_irqs" },
  264. { "nic_tx_threshold_hit" }
  265. };
  266. static const struct {
  267. const char string[ETH_GSTRING_LEN];
  268. } ethtool_test_keys[TG3_NUM_TEST] = {
  269. { "nvram test (online) " },
  270. { "link test (online) " },
  271. { "register test (offline)" },
  272. { "memory test (offline)" },
  273. { "loopback test (offline)" },
  274. { "interrupt test (offline)" },
  275. };
  276. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  277. {
  278. writel(val, tp->regs + off);
  279. }
  280. static u32 tg3_read32(struct tg3 *tp, u32 off)
  281. {
  282. return (readl(tp->regs + off));
  283. }
  284. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  285. {
  286. unsigned long flags;
  287. spin_lock_irqsave(&tp->indirect_lock, flags);
  288. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  289. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  290. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  291. }
  292. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  293. {
  294. writel(val, tp->regs + off);
  295. readl(tp->regs + off);
  296. }
  297. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  298. {
  299. unsigned long flags;
  300. u32 val;
  301. spin_lock_irqsave(&tp->indirect_lock, flags);
  302. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  303. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  304. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  305. return val;
  306. }
  307. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  308. {
  309. unsigned long flags;
  310. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  311. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  312. TG3_64BIT_REG_LOW, val);
  313. return;
  314. }
  315. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  316. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  317. TG3_64BIT_REG_LOW, val);
  318. return;
  319. }
  320. spin_lock_irqsave(&tp->indirect_lock, flags);
  321. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  322. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  323. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  324. /* In indirect mode when disabling interrupts, we also need
  325. * to clear the interrupt bit in the GRC local ctrl register.
  326. */
  327. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  328. (val == 0x1)) {
  329. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  330. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  331. }
  332. }
  333. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  334. {
  335. unsigned long flags;
  336. u32 val;
  337. spin_lock_irqsave(&tp->indirect_lock, flags);
  338. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  339. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  340. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  341. return val;
  342. }
  343. /* usec_wait specifies the wait time in usec when writing to certain registers
  344. * where it is unsafe to read back the register without some delay.
  345. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  346. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  347. */
  348. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  349. {
  350. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  351. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  352. /* Non-posted methods */
  353. tp->write32(tp, off, val);
  354. else {
  355. /* Posted method */
  356. tg3_write32(tp, off, val);
  357. if (usec_wait)
  358. udelay(usec_wait);
  359. tp->read32(tp, off);
  360. }
  361. /* Wait again after the read for the posted method to guarantee that
  362. * the wait time is met.
  363. */
  364. if (usec_wait)
  365. udelay(usec_wait);
  366. }
  367. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  368. {
  369. tp->write32_mbox(tp, off, val);
  370. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  371. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  372. tp->read32_mbox(tp, off);
  373. }
  374. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  375. {
  376. void __iomem *mbox = tp->regs + off;
  377. writel(val, mbox);
  378. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  379. writel(val, mbox);
  380. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  381. readl(mbox);
  382. }
  383. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  384. {
  385. return (readl(tp->regs + off + GRCMBOX_BASE));
  386. }
  387. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  388. {
  389. writel(val, tp->regs + off + GRCMBOX_BASE);
  390. }
  391. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  392. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  393. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  394. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  395. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  396. #define tw32(reg,val) tp->write32(tp, reg, val)
  397. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  398. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  399. #define tr32(reg) tp->read32(tp, reg)
  400. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  401. {
  402. unsigned long flags;
  403. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  404. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  405. return;
  406. spin_lock_irqsave(&tp->indirect_lock, flags);
  407. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  408. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  409. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  410. /* Always leave this as zero. */
  411. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  412. } else {
  413. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  414. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  415. /* Always leave this as zero. */
  416. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  417. }
  418. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  419. }
  420. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  421. {
  422. unsigned long flags;
  423. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  424. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  425. *val = 0;
  426. return;
  427. }
  428. spin_lock_irqsave(&tp->indirect_lock, flags);
  429. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  430. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  431. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  432. /* Always leave this as zero. */
  433. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  434. } else {
  435. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  436. *val = tr32(TG3PCI_MEM_WIN_DATA);
  437. /* Always leave this as zero. */
  438. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  439. }
  440. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  441. }
  442. static void tg3_disable_ints(struct tg3 *tp)
  443. {
  444. tw32(TG3PCI_MISC_HOST_CTRL,
  445. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  446. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  447. }
  448. static inline void tg3_cond_int(struct tg3 *tp)
  449. {
  450. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  451. (tp->hw_status->status & SD_STATUS_UPDATED))
  452. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  453. else
  454. tw32(HOSTCC_MODE, tp->coalesce_mode |
  455. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  456. }
  457. static void tg3_enable_ints(struct tg3 *tp)
  458. {
  459. tp->irq_sync = 0;
  460. wmb();
  461. tw32(TG3PCI_MISC_HOST_CTRL,
  462. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  463. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  464. (tp->last_tag << 24));
  465. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  466. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  467. (tp->last_tag << 24));
  468. tg3_cond_int(tp);
  469. }
  470. static inline unsigned int tg3_has_work(struct tg3 *tp)
  471. {
  472. struct tg3_hw_status *sblk = tp->hw_status;
  473. unsigned int work_exists = 0;
  474. /* check for phy events */
  475. if (!(tp->tg3_flags &
  476. (TG3_FLAG_USE_LINKCHG_REG |
  477. TG3_FLAG_POLL_SERDES))) {
  478. if (sblk->status & SD_STATUS_LINK_CHG)
  479. work_exists = 1;
  480. }
  481. /* check for RX/TX work to do */
  482. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  483. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  484. work_exists = 1;
  485. return work_exists;
  486. }
  487. /* tg3_restart_ints
  488. * similar to tg3_enable_ints, but it accurately determines whether there
  489. * is new work pending and can return without flushing the PIO write
  490. * which reenables interrupts
  491. */
  492. static void tg3_restart_ints(struct tg3 *tp)
  493. {
  494. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  495. tp->last_tag << 24);
  496. mmiowb();
  497. /* When doing tagged status, this work check is unnecessary.
  498. * The last_tag we write above tells the chip which piece of
  499. * work we've completed.
  500. */
  501. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  502. tg3_has_work(tp))
  503. tw32(HOSTCC_MODE, tp->coalesce_mode |
  504. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  505. }
  506. static inline void tg3_netif_stop(struct tg3 *tp)
  507. {
  508. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  509. netif_poll_disable(tp->dev);
  510. netif_tx_disable(tp->dev);
  511. }
  512. static inline void tg3_netif_start(struct tg3 *tp)
  513. {
  514. netif_wake_queue(tp->dev);
  515. /* NOTE: unconditional netif_wake_queue is only appropriate
  516. * so long as all callers are assured to have free tx slots
  517. * (such as after tg3_init_hw)
  518. */
  519. netif_poll_enable(tp->dev);
  520. tp->hw_status->status |= SD_STATUS_UPDATED;
  521. tg3_enable_ints(tp);
  522. }
  523. static void tg3_switch_clocks(struct tg3 *tp)
  524. {
  525. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  526. u32 orig_clock_ctrl;
  527. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  528. return;
  529. orig_clock_ctrl = clock_ctrl;
  530. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  531. CLOCK_CTRL_CLKRUN_OENABLE |
  532. 0x1f);
  533. tp->pci_clock_ctrl = clock_ctrl;
  534. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  535. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  536. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  537. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  538. }
  539. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  540. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  541. clock_ctrl |
  542. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  543. 40);
  544. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  545. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  546. 40);
  547. }
  548. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  549. }
  550. #define PHY_BUSY_LOOPS 5000
  551. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  552. {
  553. u32 frame_val;
  554. unsigned int loops;
  555. int ret;
  556. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  557. tw32_f(MAC_MI_MODE,
  558. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  559. udelay(80);
  560. }
  561. *val = 0x0;
  562. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  563. MI_COM_PHY_ADDR_MASK);
  564. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  565. MI_COM_REG_ADDR_MASK);
  566. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  567. tw32_f(MAC_MI_COM, frame_val);
  568. loops = PHY_BUSY_LOOPS;
  569. while (loops != 0) {
  570. udelay(10);
  571. frame_val = tr32(MAC_MI_COM);
  572. if ((frame_val & MI_COM_BUSY) == 0) {
  573. udelay(5);
  574. frame_val = tr32(MAC_MI_COM);
  575. break;
  576. }
  577. loops -= 1;
  578. }
  579. ret = -EBUSY;
  580. if (loops != 0) {
  581. *val = frame_val & MI_COM_DATA_MASK;
  582. ret = 0;
  583. }
  584. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  585. tw32_f(MAC_MI_MODE, tp->mi_mode);
  586. udelay(80);
  587. }
  588. return ret;
  589. }
  590. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  591. {
  592. u32 frame_val;
  593. unsigned int loops;
  594. int ret;
  595. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  596. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  597. return 0;
  598. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  599. tw32_f(MAC_MI_MODE,
  600. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  601. udelay(80);
  602. }
  603. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  604. MI_COM_PHY_ADDR_MASK);
  605. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  606. MI_COM_REG_ADDR_MASK);
  607. frame_val |= (val & MI_COM_DATA_MASK);
  608. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  609. tw32_f(MAC_MI_COM, frame_val);
  610. loops = PHY_BUSY_LOOPS;
  611. while (loops != 0) {
  612. udelay(10);
  613. frame_val = tr32(MAC_MI_COM);
  614. if ((frame_val & MI_COM_BUSY) == 0) {
  615. udelay(5);
  616. frame_val = tr32(MAC_MI_COM);
  617. break;
  618. }
  619. loops -= 1;
  620. }
  621. ret = -EBUSY;
  622. if (loops != 0)
  623. ret = 0;
  624. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  625. tw32_f(MAC_MI_MODE, tp->mi_mode);
  626. udelay(80);
  627. }
  628. return ret;
  629. }
  630. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  631. {
  632. u32 val;
  633. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  634. return;
  635. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  636. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  637. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  638. (val | (1 << 15) | (1 << 4)));
  639. }
  640. static int tg3_bmcr_reset(struct tg3 *tp)
  641. {
  642. u32 phy_control;
  643. int limit, err;
  644. /* OK, reset it, and poll the BMCR_RESET bit until it
  645. * clears or we time out.
  646. */
  647. phy_control = BMCR_RESET;
  648. err = tg3_writephy(tp, MII_BMCR, phy_control);
  649. if (err != 0)
  650. return -EBUSY;
  651. limit = 5000;
  652. while (limit--) {
  653. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  654. if (err != 0)
  655. return -EBUSY;
  656. if ((phy_control & BMCR_RESET) == 0) {
  657. udelay(40);
  658. break;
  659. }
  660. udelay(10);
  661. }
  662. if (limit <= 0)
  663. return -EBUSY;
  664. return 0;
  665. }
  666. static int tg3_wait_macro_done(struct tg3 *tp)
  667. {
  668. int limit = 100;
  669. while (limit--) {
  670. u32 tmp32;
  671. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  672. if ((tmp32 & 0x1000) == 0)
  673. break;
  674. }
  675. }
  676. if (limit <= 0)
  677. return -EBUSY;
  678. return 0;
  679. }
  680. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  681. {
  682. static const u32 test_pat[4][6] = {
  683. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  684. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  685. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  686. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  687. };
  688. int chan;
  689. for (chan = 0; chan < 4; chan++) {
  690. int i;
  691. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  692. (chan * 0x2000) | 0x0200);
  693. tg3_writephy(tp, 0x16, 0x0002);
  694. for (i = 0; i < 6; i++)
  695. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  696. test_pat[chan][i]);
  697. tg3_writephy(tp, 0x16, 0x0202);
  698. if (tg3_wait_macro_done(tp)) {
  699. *resetp = 1;
  700. return -EBUSY;
  701. }
  702. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  703. (chan * 0x2000) | 0x0200);
  704. tg3_writephy(tp, 0x16, 0x0082);
  705. if (tg3_wait_macro_done(tp)) {
  706. *resetp = 1;
  707. return -EBUSY;
  708. }
  709. tg3_writephy(tp, 0x16, 0x0802);
  710. if (tg3_wait_macro_done(tp)) {
  711. *resetp = 1;
  712. return -EBUSY;
  713. }
  714. for (i = 0; i < 6; i += 2) {
  715. u32 low, high;
  716. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  717. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  718. tg3_wait_macro_done(tp)) {
  719. *resetp = 1;
  720. return -EBUSY;
  721. }
  722. low &= 0x7fff;
  723. high &= 0x000f;
  724. if (low != test_pat[chan][i] ||
  725. high != test_pat[chan][i+1]) {
  726. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  727. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  728. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  729. return -EBUSY;
  730. }
  731. }
  732. }
  733. return 0;
  734. }
  735. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  736. {
  737. int chan;
  738. for (chan = 0; chan < 4; chan++) {
  739. int i;
  740. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  741. (chan * 0x2000) | 0x0200);
  742. tg3_writephy(tp, 0x16, 0x0002);
  743. for (i = 0; i < 6; i++)
  744. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  745. tg3_writephy(tp, 0x16, 0x0202);
  746. if (tg3_wait_macro_done(tp))
  747. return -EBUSY;
  748. }
  749. return 0;
  750. }
  751. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  752. {
  753. u32 reg32, phy9_orig;
  754. int retries, do_phy_reset, err;
  755. retries = 10;
  756. do_phy_reset = 1;
  757. do {
  758. if (do_phy_reset) {
  759. err = tg3_bmcr_reset(tp);
  760. if (err)
  761. return err;
  762. do_phy_reset = 0;
  763. }
  764. /* Disable transmitter and interrupt. */
  765. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  766. continue;
  767. reg32 |= 0x3000;
  768. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  769. /* Set full-duplex, 1000 mbps. */
  770. tg3_writephy(tp, MII_BMCR,
  771. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  772. /* Set to master mode. */
  773. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  774. continue;
  775. tg3_writephy(tp, MII_TG3_CTRL,
  776. (MII_TG3_CTRL_AS_MASTER |
  777. MII_TG3_CTRL_ENABLE_AS_MASTER));
  778. /* Enable SM_DSP_CLOCK and 6dB. */
  779. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  780. /* Block the PHY control access. */
  781. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  782. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  783. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  784. if (!err)
  785. break;
  786. } while (--retries);
  787. err = tg3_phy_reset_chanpat(tp);
  788. if (err)
  789. return err;
  790. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  791. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  792. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  793. tg3_writephy(tp, 0x16, 0x0000);
  794. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  795. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  796. /* Set Extended packet length bit for jumbo frames */
  797. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  798. }
  799. else {
  800. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  801. }
  802. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  803. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  804. reg32 &= ~0x3000;
  805. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  806. } else if (!err)
  807. err = -EBUSY;
  808. return err;
  809. }
  810. static void tg3_link_report(struct tg3 *);
  811. /* This will reset the tigon3 PHY if there is no valid
  812. * link unless the FORCE argument is non-zero.
  813. */
  814. static int tg3_phy_reset(struct tg3 *tp)
  815. {
  816. u32 phy_status;
  817. int err;
  818. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  819. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  820. if (err != 0)
  821. return -EBUSY;
  822. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  823. netif_carrier_off(tp->dev);
  824. tg3_link_report(tp);
  825. }
  826. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  827. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  828. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  829. err = tg3_phy_reset_5703_4_5(tp);
  830. if (err)
  831. return err;
  832. goto out;
  833. }
  834. err = tg3_bmcr_reset(tp);
  835. if (err)
  836. return err;
  837. out:
  838. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  839. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  840. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  841. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  842. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  843. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  844. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  845. }
  846. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  847. tg3_writephy(tp, 0x1c, 0x8d68);
  848. tg3_writephy(tp, 0x1c, 0x8d68);
  849. }
  850. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  851. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  852. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  853. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  854. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  855. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  856. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  857. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  858. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  859. }
  860. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  861. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  862. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  863. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  864. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  865. }
  866. /* Set Extended packet length bit (bit 14) on all chips that */
  867. /* support jumbo frames */
  868. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  869. /* Cannot do read-modify-write on 5401 */
  870. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  871. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  872. u32 phy_reg;
  873. /* Set bit 14 with read-modify-write to preserve other bits */
  874. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  875. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  876. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  877. }
  878. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  879. * jumbo frames transmission.
  880. */
  881. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  882. u32 phy_reg;
  883. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  884. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  885. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  886. }
  887. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  888. u32 phy_reg;
  889. /* adjust output voltage */
  890. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  891. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
  892. u32 phy_reg2;
  893. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  894. phy_reg | MII_TG3_EPHY_SHADOW_EN);
  895. /* Enable auto-MDIX */
  896. if (!tg3_readphy(tp, 0x10, &phy_reg2))
  897. tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
  898. tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
  899. }
  900. }
  901. tg3_phy_set_wirespeed(tp);
  902. return 0;
  903. }
  904. static void tg3_frob_aux_power(struct tg3 *tp)
  905. {
  906. struct tg3 *tp_peer = tp;
  907. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  908. return;
  909. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  910. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  911. struct net_device *dev_peer;
  912. dev_peer = pci_get_drvdata(tp->pdev_peer);
  913. /* remove_one() may have been run on the peer. */
  914. if (!dev_peer)
  915. tp_peer = tp;
  916. else
  917. tp_peer = netdev_priv(dev_peer);
  918. }
  919. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  920. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  921. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  922. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  923. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  924. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  925. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  926. (GRC_LCLCTRL_GPIO_OE0 |
  927. GRC_LCLCTRL_GPIO_OE1 |
  928. GRC_LCLCTRL_GPIO_OE2 |
  929. GRC_LCLCTRL_GPIO_OUTPUT0 |
  930. GRC_LCLCTRL_GPIO_OUTPUT1),
  931. 100);
  932. } else {
  933. u32 no_gpio2;
  934. u32 grc_local_ctrl = 0;
  935. if (tp_peer != tp &&
  936. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  937. return;
  938. /* Workaround to prevent overdrawing Amps. */
  939. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  940. ASIC_REV_5714) {
  941. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  942. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  943. grc_local_ctrl, 100);
  944. }
  945. /* On 5753 and variants, GPIO2 cannot be used. */
  946. no_gpio2 = tp->nic_sram_data_cfg &
  947. NIC_SRAM_DATA_CFG_NO_GPIO2;
  948. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  949. GRC_LCLCTRL_GPIO_OE1 |
  950. GRC_LCLCTRL_GPIO_OE2 |
  951. GRC_LCLCTRL_GPIO_OUTPUT1 |
  952. GRC_LCLCTRL_GPIO_OUTPUT2;
  953. if (no_gpio2) {
  954. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  955. GRC_LCLCTRL_GPIO_OUTPUT2);
  956. }
  957. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  958. grc_local_ctrl, 100);
  959. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  960. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  961. grc_local_ctrl, 100);
  962. if (!no_gpio2) {
  963. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  964. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  965. grc_local_ctrl, 100);
  966. }
  967. }
  968. } else {
  969. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  970. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  971. if (tp_peer != tp &&
  972. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  973. return;
  974. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  975. (GRC_LCLCTRL_GPIO_OE1 |
  976. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  977. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  978. GRC_LCLCTRL_GPIO_OE1, 100);
  979. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  980. (GRC_LCLCTRL_GPIO_OE1 |
  981. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  982. }
  983. }
  984. }
  985. static int tg3_setup_phy(struct tg3 *, int);
  986. #define RESET_KIND_SHUTDOWN 0
  987. #define RESET_KIND_INIT 1
  988. #define RESET_KIND_SUSPEND 2
  989. static void tg3_write_sig_post_reset(struct tg3 *, int);
  990. static int tg3_halt_cpu(struct tg3 *, u32);
  991. static int tg3_nvram_lock(struct tg3 *);
  992. static void tg3_nvram_unlock(struct tg3 *);
  993. static void tg3_power_down_phy(struct tg3 *tp)
  994. {
  995. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  996. return;
  997. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  998. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  999. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1000. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1001. }
  1002. /* The PHY should not be powered down on some chips because
  1003. * of bugs.
  1004. */
  1005. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1006. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1007. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1008. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1009. return;
  1010. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1011. }
  1012. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1013. {
  1014. u32 misc_host_ctrl;
  1015. u16 power_control, power_caps;
  1016. int pm = tp->pm_cap;
  1017. /* Make sure register accesses (indirect or otherwise)
  1018. * will function correctly.
  1019. */
  1020. pci_write_config_dword(tp->pdev,
  1021. TG3PCI_MISC_HOST_CTRL,
  1022. tp->misc_host_ctrl);
  1023. pci_read_config_word(tp->pdev,
  1024. pm + PCI_PM_CTRL,
  1025. &power_control);
  1026. power_control |= PCI_PM_CTRL_PME_STATUS;
  1027. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1028. switch (state) {
  1029. case PCI_D0:
  1030. power_control |= 0;
  1031. pci_write_config_word(tp->pdev,
  1032. pm + PCI_PM_CTRL,
  1033. power_control);
  1034. udelay(100); /* Delay after power state change */
  1035. /* Switch out of Vaux if it is a NIC */
  1036. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1037. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1038. return 0;
  1039. case PCI_D1:
  1040. power_control |= 1;
  1041. break;
  1042. case PCI_D2:
  1043. power_control |= 2;
  1044. break;
  1045. case PCI_D3hot:
  1046. power_control |= 3;
  1047. break;
  1048. default:
  1049. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1050. "requested.\n",
  1051. tp->dev->name, state);
  1052. return -EINVAL;
  1053. };
  1054. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1055. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1056. tw32(TG3PCI_MISC_HOST_CTRL,
  1057. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1058. if (tp->link_config.phy_is_low_power == 0) {
  1059. tp->link_config.phy_is_low_power = 1;
  1060. tp->link_config.orig_speed = tp->link_config.speed;
  1061. tp->link_config.orig_duplex = tp->link_config.duplex;
  1062. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1063. }
  1064. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1065. tp->link_config.speed = SPEED_10;
  1066. tp->link_config.duplex = DUPLEX_HALF;
  1067. tp->link_config.autoneg = AUTONEG_ENABLE;
  1068. tg3_setup_phy(tp, 0);
  1069. }
  1070. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1071. u32 val;
  1072. val = tr32(GRC_VCPU_EXT_CTRL);
  1073. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1074. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1075. int i;
  1076. u32 val;
  1077. for (i = 0; i < 200; i++) {
  1078. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1079. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1080. break;
  1081. msleep(1);
  1082. }
  1083. }
  1084. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1085. WOL_DRV_STATE_SHUTDOWN |
  1086. WOL_DRV_WOL | WOL_SET_MAGIC_PKT);
  1087. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1088. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1089. u32 mac_mode;
  1090. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1091. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1092. udelay(40);
  1093. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1094. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1095. else
  1096. mac_mode = MAC_MODE_PORT_MODE_MII;
  1097. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
  1098. !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
  1099. mac_mode |= MAC_MODE_LINK_POLARITY;
  1100. } else {
  1101. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1102. }
  1103. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1104. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1105. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1106. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1107. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1108. tw32_f(MAC_MODE, mac_mode);
  1109. udelay(100);
  1110. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1111. udelay(10);
  1112. }
  1113. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1114. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1115. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1116. u32 base_val;
  1117. base_val = tp->pci_clock_ctrl;
  1118. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1119. CLOCK_CTRL_TXCLK_DISABLE);
  1120. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1121. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1122. } else if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  1123. /* do nothing */
  1124. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1125. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1126. u32 newbits1, newbits2;
  1127. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1128. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1129. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1130. CLOCK_CTRL_TXCLK_DISABLE |
  1131. CLOCK_CTRL_ALTCLK);
  1132. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1133. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1134. newbits1 = CLOCK_CTRL_625_CORE;
  1135. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1136. } else {
  1137. newbits1 = CLOCK_CTRL_ALTCLK;
  1138. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1139. }
  1140. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1141. 40);
  1142. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1143. 40);
  1144. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1145. u32 newbits3;
  1146. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1147. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1148. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1149. CLOCK_CTRL_TXCLK_DISABLE |
  1150. CLOCK_CTRL_44MHZ_CORE);
  1151. } else {
  1152. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1153. }
  1154. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1155. tp->pci_clock_ctrl | newbits3, 40);
  1156. }
  1157. }
  1158. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1159. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  1160. tg3_power_down_phy(tp);
  1161. tg3_frob_aux_power(tp);
  1162. /* Workaround for unstable PLL clock */
  1163. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1164. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1165. u32 val = tr32(0x7d00);
  1166. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1167. tw32(0x7d00, val);
  1168. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1169. int err;
  1170. err = tg3_nvram_lock(tp);
  1171. tg3_halt_cpu(tp, RX_CPU_BASE);
  1172. if (!err)
  1173. tg3_nvram_unlock(tp);
  1174. }
  1175. }
  1176. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1177. /* Finally, set the new power state. */
  1178. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1179. udelay(100); /* Delay after power state change */
  1180. return 0;
  1181. }
  1182. static void tg3_link_report(struct tg3 *tp)
  1183. {
  1184. if (!netif_carrier_ok(tp->dev)) {
  1185. if (netif_msg_link(tp))
  1186. printk(KERN_INFO PFX "%s: Link is down.\n",
  1187. tp->dev->name);
  1188. } else if (netif_msg_link(tp)) {
  1189. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1190. tp->dev->name,
  1191. (tp->link_config.active_speed == SPEED_1000 ?
  1192. 1000 :
  1193. (tp->link_config.active_speed == SPEED_100 ?
  1194. 100 : 10)),
  1195. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1196. "full" : "half"));
  1197. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1198. "%s for RX.\n",
  1199. tp->dev->name,
  1200. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1201. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1202. }
  1203. }
  1204. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1205. {
  1206. u32 new_tg3_flags = 0;
  1207. u32 old_rx_mode = tp->rx_mode;
  1208. u32 old_tx_mode = tp->tx_mode;
  1209. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1210. /* Convert 1000BaseX flow control bits to 1000BaseT
  1211. * bits before resolving flow control.
  1212. */
  1213. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1214. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1215. ADVERTISE_PAUSE_ASYM);
  1216. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1217. if (local_adv & ADVERTISE_1000XPAUSE)
  1218. local_adv |= ADVERTISE_PAUSE_CAP;
  1219. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1220. local_adv |= ADVERTISE_PAUSE_ASYM;
  1221. if (remote_adv & LPA_1000XPAUSE)
  1222. remote_adv |= LPA_PAUSE_CAP;
  1223. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1224. remote_adv |= LPA_PAUSE_ASYM;
  1225. }
  1226. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1227. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1228. if (remote_adv & LPA_PAUSE_CAP)
  1229. new_tg3_flags |=
  1230. (TG3_FLAG_RX_PAUSE |
  1231. TG3_FLAG_TX_PAUSE);
  1232. else if (remote_adv & LPA_PAUSE_ASYM)
  1233. new_tg3_flags |=
  1234. (TG3_FLAG_RX_PAUSE);
  1235. } else {
  1236. if (remote_adv & LPA_PAUSE_CAP)
  1237. new_tg3_flags |=
  1238. (TG3_FLAG_RX_PAUSE |
  1239. TG3_FLAG_TX_PAUSE);
  1240. }
  1241. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1242. if ((remote_adv & LPA_PAUSE_CAP) &&
  1243. (remote_adv & LPA_PAUSE_ASYM))
  1244. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1245. }
  1246. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1247. tp->tg3_flags |= new_tg3_flags;
  1248. } else {
  1249. new_tg3_flags = tp->tg3_flags;
  1250. }
  1251. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1252. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1253. else
  1254. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1255. if (old_rx_mode != tp->rx_mode) {
  1256. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1257. }
  1258. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1259. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1260. else
  1261. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1262. if (old_tx_mode != tp->tx_mode) {
  1263. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1264. }
  1265. }
  1266. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1267. {
  1268. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1269. case MII_TG3_AUX_STAT_10HALF:
  1270. *speed = SPEED_10;
  1271. *duplex = DUPLEX_HALF;
  1272. break;
  1273. case MII_TG3_AUX_STAT_10FULL:
  1274. *speed = SPEED_10;
  1275. *duplex = DUPLEX_FULL;
  1276. break;
  1277. case MII_TG3_AUX_STAT_100HALF:
  1278. *speed = SPEED_100;
  1279. *duplex = DUPLEX_HALF;
  1280. break;
  1281. case MII_TG3_AUX_STAT_100FULL:
  1282. *speed = SPEED_100;
  1283. *duplex = DUPLEX_FULL;
  1284. break;
  1285. case MII_TG3_AUX_STAT_1000HALF:
  1286. *speed = SPEED_1000;
  1287. *duplex = DUPLEX_HALF;
  1288. break;
  1289. case MII_TG3_AUX_STAT_1000FULL:
  1290. *speed = SPEED_1000;
  1291. *duplex = DUPLEX_FULL;
  1292. break;
  1293. default:
  1294. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1295. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1296. SPEED_10;
  1297. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1298. DUPLEX_HALF;
  1299. break;
  1300. }
  1301. *speed = SPEED_INVALID;
  1302. *duplex = DUPLEX_INVALID;
  1303. break;
  1304. };
  1305. }
  1306. static void tg3_phy_copper_begin(struct tg3 *tp)
  1307. {
  1308. u32 new_adv;
  1309. int i;
  1310. if (tp->link_config.phy_is_low_power) {
  1311. /* Entering low power mode. Disable gigabit and
  1312. * 100baseT advertisements.
  1313. */
  1314. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1315. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1316. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1317. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1318. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1319. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1320. } else if (tp->link_config.speed == SPEED_INVALID) {
  1321. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1322. tp->link_config.advertising &=
  1323. ~(ADVERTISED_1000baseT_Half |
  1324. ADVERTISED_1000baseT_Full);
  1325. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1326. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1327. new_adv |= ADVERTISE_10HALF;
  1328. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1329. new_adv |= ADVERTISE_10FULL;
  1330. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1331. new_adv |= ADVERTISE_100HALF;
  1332. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1333. new_adv |= ADVERTISE_100FULL;
  1334. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1335. if (tp->link_config.advertising &
  1336. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1337. new_adv = 0;
  1338. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1339. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1340. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1341. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1342. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1343. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1344. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1345. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1346. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1347. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1348. } else {
  1349. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1350. }
  1351. } else {
  1352. /* Asking for a specific link mode. */
  1353. if (tp->link_config.speed == SPEED_1000) {
  1354. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1355. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1356. if (tp->link_config.duplex == DUPLEX_FULL)
  1357. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1358. else
  1359. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1360. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1361. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1362. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1363. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1364. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1365. } else {
  1366. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1367. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1368. if (tp->link_config.speed == SPEED_100) {
  1369. if (tp->link_config.duplex == DUPLEX_FULL)
  1370. new_adv |= ADVERTISE_100FULL;
  1371. else
  1372. new_adv |= ADVERTISE_100HALF;
  1373. } else {
  1374. if (tp->link_config.duplex == DUPLEX_FULL)
  1375. new_adv |= ADVERTISE_10FULL;
  1376. else
  1377. new_adv |= ADVERTISE_10HALF;
  1378. }
  1379. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1380. }
  1381. }
  1382. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1383. tp->link_config.speed != SPEED_INVALID) {
  1384. u32 bmcr, orig_bmcr;
  1385. tp->link_config.active_speed = tp->link_config.speed;
  1386. tp->link_config.active_duplex = tp->link_config.duplex;
  1387. bmcr = 0;
  1388. switch (tp->link_config.speed) {
  1389. default:
  1390. case SPEED_10:
  1391. break;
  1392. case SPEED_100:
  1393. bmcr |= BMCR_SPEED100;
  1394. break;
  1395. case SPEED_1000:
  1396. bmcr |= TG3_BMCR_SPEED1000;
  1397. break;
  1398. };
  1399. if (tp->link_config.duplex == DUPLEX_FULL)
  1400. bmcr |= BMCR_FULLDPLX;
  1401. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1402. (bmcr != orig_bmcr)) {
  1403. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1404. for (i = 0; i < 1500; i++) {
  1405. u32 tmp;
  1406. udelay(10);
  1407. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1408. tg3_readphy(tp, MII_BMSR, &tmp))
  1409. continue;
  1410. if (!(tmp & BMSR_LSTATUS)) {
  1411. udelay(40);
  1412. break;
  1413. }
  1414. }
  1415. tg3_writephy(tp, MII_BMCR, bmcr);
  1416. udelay(40);
  1417. }
  1418. } else {
  1419. tg3_writephy(tp, MII_BMCR,
  1420. BMCR_ANENABLE | BMCR_ANRESTART);
  1421. }
  1422. }
  1423. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1424. {
  1425. int err;
  1426. /* Turn off tap power management. */
  1427. /* Set Extended packet length bit */
  1428. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1429. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1430. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1431. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1432. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1433. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1434. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1435. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1436. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1437. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1438. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1439. udelay(40);
  1440. return err;
  1441. }
  1442. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1443. {
  1444. u32 adv_reg, all_mask = 0;
  1445. if (mask & ADVERTISED_10baseT_Half)
  1446. all_mask |= ADVERTISE_10HALF;
  1447. if (mask & ADVERTISED_10baseT_Full)
  1448. all_mask |= ADVERTISE_10FULL;
  1449. if (mask & ADVERTISED_100baseT_Half)
  1450. all_mask |= ADVERTISE_100HALF;
  1451. if (mask & ADVERTISED_100baseT_Full)
  1452. all_mask |= ADVERTISE_100FULL;
  1453. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1454. return 0;
  1455. if ((adv_reg & all_mask) != all_mask)
  1456. return 0;
  1457. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1458. u32 tg3_ctrl;
  1459. all_mask = 0;
  1460. if (mask & ADVERTISED_1000baseT_Half)
  1461. all_mask |= ADVERTISE_1000HALF;
  1462. if (mask & ADVERTISED_1000baseT_Full)
  1463. all_mask |= ADVERTISE_1000FULL;
  1464. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1465. return 0;
  1466. if ((tg3_ctrl & all_mask) != all_mask)
  1467. return 0;
  1468. }
  1469. return 1;
  1470. }
  1471. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1472. {
  1473. int current_link_up;
  1474. u32 bmsr, dummy;
  1475. u16 current_speed;
  1476. u8 current_duplex;
  1477. int i, err;
  1478. tw32(MAC_EVENT, 0);
  1479. tw32_f(MAC_STATUS,
  1480. (MAC_STATUS_SYNC_CHANGED |
  1481. MAC_STATUS_CFG_CHANGED |
  1482. MAC_STATUS_MI_COMPLETION |
  1483. MAC_STATUS_LNKSTATE_CHANGED));
  1484. udelay(40);
  1485. tp->mi_mode = MAC_MI_MODE_BASE;
  1486. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1487. udelay(80);
  1488. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1489. /* Some third-party PHYs need to be reset on link going
  1490. * down.
  1491. */
  1492. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1493. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1494. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1495. netif_carrier_ok(tp->dev)) {
  1496. tg3_readphy(tp, MII_BMSR, &bmsr);
  1497. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1498. !(bmsr & BMSR_LSTATUS))
  1499. force_reset = 1;
  1500. }
  1501. if (force_reset)
  1502. tg3_phy_reset(tp);
  1503. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1504. tg3_readphy(tp, MII_BMSR, &bmsr);
  1505. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1506. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1507. bmsr = 0;
  1508. if (!(bmsr & BMSR_LSTATUS)) {
  1509. err = tg3_init_5401phy_dsp(tp);
  1510. if (err)
  1511. return err;
  1512. tg3_readphy(tp, MII_BMSR, &bmsr);
  1513. for (i = 0; i < 1000; i++) {
  1514. udelay(10);
  1515. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1516. (bmsr & BMSR_LSTATUS)) {
  1517. udelay(40);
  1518. break;
  1519. }
  1520. }
  1521. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1522. !(bmsr & BMSR_LSTATUS) &&
  1523. tp->link_config.active_speed == SPEED_1000) {
  1524. err = tg3_phy_reset(tp);
  1525. if (!err)
  1526. err = tg3_init_5401phy_dsp(tp);
  1527. if (err)
  1528. return err;
  1529. }
  1530. }
  1531. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1532. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1533. /* 5701 {A0,B0} CRC bug workaround */
  1534. tg3_writephy(tp, 0x15, 0x0a75);
  1535. tg3_writephy(tp, 0x1c, 0x8c68);
  1536. tg3_writephy(tp, 0x1c, 0x8d68);
  1537. tg3_writephy(tp, 0x1c, 0x8c68);
  1538. }
  1539. /* Clear pending interrupts... */
  1540. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1541. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1542. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1543. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1544. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1545. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1546. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1547. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1548. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1549. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1550. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1551. else
  1552. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1553. }
  1554. current_link_up = 0;
  1555. current_speed = SPEED_INVALID;
  1556. current_duplex = DUPLEX_INVALID;
  1557. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1558. u32 val;
  1559. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1560. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1561. if (!(val & (1 << 10))) {
  1562. val |= (1 << 10);
  1563. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1564. goto relink;
  1565. }
  1566. }
  1567. bmsr = 0;
  1568. for (i = 0; i < 100; i++) {
  1569. tg3_readphy(tp, MII_BMSR, &bmsr);
  1570. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1571. (bmsr & BMSR_LSTATUS))
  1572. break;
  1573. udelay(40);
  1574. }
  1575. if (bmsr & BMSR_LSTATUS) {
  1576. u32 aux_stat, bmcr;
  1577. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1578. for (i = 0; i < 2000; i++) {
  1579. udelay(10);
  1580. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1581. aux_stat)
  1582. break;
  1583. }
  1584. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1585. &current_speed,
  1586. &current_duplex);
  1587. bmcr = 0;
  1588. for (i = 0; i < 200; i++) {
  1589. tg3_readphy(tp, MII_BMCR, &bmcr);
  1590. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1591. continue;
  1592. if (bmcr && bmcr != 0x7fff)
  1593. break;
  1594. udelay(10);
  1595. }
  1596. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1597. if (bmcr & BMCR_ANENABLE) {
  1598. current_link_up = 1;
  1599. /* Force autoneg restart if we are exiting
  1600. * low power mode.
  1601. */
  1602. if (!tg3_copper_is_advertising_all(tp,
  1603. tp->link_config.advertising))
  1604. current_link_up = 0;
  1605. } else {
  1606. current_link_up = 0;
  1607. }
  1608. } else {
  1609. if (!(bmcr & BMCR_ANENABLE) &&
  1610. tp->link_config.speed == current_speed &&
  1611. tp->link_config.duplex == current_duplex) {
  1612. current_link_up = 1;
  1613. } else {
  1614. current_link_up = 0;
  1615. }
  1616. }
  1617. tp->link_config.active_speed = current_speed;
  1618. tp->link_config.active_duplex = current_duplex;
  1619. }
  1620. if (current_link_up == 1 &&
  1621. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1622. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1623. u32 local_adv, remote_adv;
  1624. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1625. local_adv = 0;
  1626. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1627. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1628. remote_adv = 0;
  1629. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1630. /* If we are not advertising full pause capability,
  1631. * something is wrong. Bring the link down and reconfigure.
  1632. */
  1633. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1634. current_link_up = 0;
  1635. } else {
  1636. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1637. }
  1638. }
  1639. relink:
  1640. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1641. u32 tmp;
  1642. tg3_phy_copper_begin(tp);
  1643. tg3_readphy(tp, MII_BMSR, &tmp);
  1644. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1645. (tmp & BMSR_LSTATUS))
  1646. current_link_up = 1;
  1647. }
  1648. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1649. if (current_link_up == 1) {
  1650. if (tp->link_config.active_speed == SPEED_100 ||
  1651. tp->link_config.active_speed == SPEED_10)
  1652. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1653. else
  1654. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1655. } else
  1656. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1657. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1658. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1659. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1660. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1661. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1662. if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
  1663. (current_link_up == 1 &&
  1664. tp->link_config.active_speed == SPEED_10))
  1665. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1666. } else {
  1667. if (current_link_up == 1)
  1668. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1669. }
  1670. /* ??? Without this setting Netgear GA302T PHY does not
  1671. * ??? send/receive packets...
  1672. */
  1673. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1674. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1675. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1676. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1677. udelay(80);
  1678. }
  1679. tw32_f(MAC_MODE, tp->mac_mode);
  1680. udelay(40);
  1681. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1682. /* Polled via timer. */
  1683. tw32_f(MAC_EVENT, 0);
  1684. } else {
  1685. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1686. }
  1687. udelay(40);
  1688. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1689. current_link_up == 1 &&
  1690. tp->link_config.active_speed == SPEED_1000 &&
  1691. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1692. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1693. udelay(120);
  1694. tw32_f(MAC_STATUS,
  1695. (MAC_STATUS_SYNC_CHANGED |
  1696. MAC_STATUS_CFG_CHANGED));
  1697. udelay(40);
  1698. tg3_write_mem(tp,
  1699. NIC_SRAM_FIRMWARE_MBOX,
  1700. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1701. }
  1702. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1703. if (current_link_up)
  1704. netif_carrier_on(tp->dev);
  1705. else
  1706. netif_carrier_off(tp->dev);
  1707. tg3_link_report(tp);
  1708. }
  1709. return 0;
  1710. }
  1711. struct tg3_fiber_aneginfo {
  1712. int state;
  1713. #define ANEG_STATE_UNKNOWN 0
  1714. #define ANEG_STATE_AN_ENABLE 1
  1715. #define ANEG_STATE_RESTART_INIT 2
  1716. #define ANEG_STATE_RESTART 3
  1717. #define ANEG_STATE_DISABLE_LINK_OK 4
  1718. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1719. #define ANEG_STATE_ABILITY_DETECT 6
  1720. #define ANEG_STATE_ACK_DETECT_INIT 7
  1721. #define ANEG_STATE_ACK_DETECT 8
  1722. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1723. #define ANEG_STATE_COMPLETE_ACK 10
  1724. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1725. #define ANEG_STATE_IDLE_DETECT 12
  1726. #define ANEG_STATE_LINK_OK 13
  1727. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1728. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1729. u32 flags;
  1730. #define MR_AN_ENABLE 0x00000001
  1731. #define MR_RESTART_AN 0x00000002
  1732. #define MR_AN_COMPLETE 0x00000004
  1733. #define MR_PAGE_RX 0x00000008
  1734. #define MR_NP_LOADED 0x00000010
  1735. #define MR_TOGGLE_TX 0x00000020
  1736. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1737. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1738. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1739. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1740. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1741. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1742. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1743. #define MR_TOGGLE_RX 0x00002000
  1744. #define MR_NP_RX 0x00004000
  1745. #define MR_LINK_OK 0x80000000
  1746. unsigned long link_time, cur_time;
  1747. u32 ability_match_cfg;
  1748. int ability_match_count;
  1749. char ability_match, idle_match, ack_match;
  1750. u32 txconfig, rxconfig;
  1751. #define ANEG_CFG_NP 0x00000080
  1752. #define ANEG_CFG_ACK 0x00000040
  1753. #define ANEG_CFG_RF2 0x00000020
  1754. #define ANEG_CFG_RF1 0x00000010
  1755. #define ANEG_CFG_PS2 0x00000001
  1756. #define ANEG_CFG_PS1 0x00008000
  1757. #define ANEG_CFG_HD 0x00004000
  1758. #define ANEG_CFG_FD 0x00002000
  1759. #define ANEG_CFG_INVAL 0x00001f06
  1760. };
  1761. #define ANEG_OK 0
  1762. #define ANEG_DONE 1
  1763. #define ANEG_TIMER_ENAB 2
  1764. #define ANEG_FAILED -1
  1765. #define ANEG_STATE_SETTLE_TIME 10000
  1766. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1767. struct tg3_fiber_aneginfo *ap)
  1768. {
  1769. unsigned long delta;
  1770. u32 rx_cfg_reg;
  1771. int ret;
  1772. if (ap->state == ANEG_STATE_UNKNOWN) {
  1773. ap->rxconfig = 0;
  1774. ap->link_time = 0;
  1775. ap->cur_time = 0;
  1776. ap->ability_match_cfg = 0;
  1777. ap->ability_match_count = 0;
  1778. ap->ability_match = 0;
  1779. ap->idle_match = 0;
  1780. ap->ack_match = 0;
  1781. }
  1782. ap->cur_time++;
  1783. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1784. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1785. if (rx_cfg_reg != ap->ability_match_cfg) {
  1786. ap->ability_match_cfg = rx_cfg_reg;
  1787. ap->ability_match = 0;
  1788. ap->ability_match_count = 0;
  1789. } else {
  1790. if (++ap->ability_match_count > 1) {
  1791. ap->ability_match = 1;
  1792. ap->ability_match_cfg = rx_cfg_reg;
  1793. }
  1794. }
  1795. if (rx_cfg_reg & ANEG_CFG_ACK)
  1796. ap->ack_match = 1;
  1797. else
  1798. ap->ack_match = 0;
  1799. ap->idle_match = 0;
  1800. } else {
  1801. ap->idle_match = 1;
  1802. ap->ability_match_cfg = 0;
  1803. ap->ability_match_count = 0;
  1804. ap->ability_match = 0;
  1805. ap->ack_match = 0;
  1806. rx_cfg_reg = 0;
  1807. }
  1808. ap->rxconfig = rx_cfg_reg;
  1809. ret = ANEG_OK;
  1810. switch(ap->state) {
  1811. case ANEG_STATE_UNKNOWN:
  1812. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1813. ap->state = ANEG_STATE_AN_ENABLE;
  1814. /* fallthru */
  1815. case ANEG_STATE_AN_ENABLE:
  1816. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1817. if (ap->flags & MR_AN_ENABLE) {
  1818. ap->link_time = 0;
  1819. ap->cur_time = 0;
  1820. ap->ability_match_cfg = 0;
  1821. ap->ability_match_count = 0;
  1822. ap->ability_match = 0;
  1823. ap->idle_match = 0;
  1824. ap->ack_match = 0;
  1825. ap->state = ANEG_STATE_RESTART_INIT;
  1826. } else {
  1827. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1828. }
  1829. break;
  1830. case ANEG_STATE_RESTART_INIT:
  1831. ap->link_time = ap->cur_time;
  1832. ap->flags &= ~(MR_NP_LOADED);
  1833. ap->txconfig = 0;
  1834. tw32(MAC_TX_AUTO_NEG, 0);
  1835. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1836. tw32_f(MAC_MODE, tp->mac_mode);
  1837. udelay(40);
  1838. ret = ANEG_TIMER_ENAB;
  1839. ap->state = ANEG_STATE_RESTART;
  1840. /* fallthru */
  1841. case ANEG_STATE_RESTART:
  1842. delta = ap->cur_time - ap->link_time;
  1843. if (delta > ANEG_STATE_SETTLE_TIME) {
  1844. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1845. } else {
  1846. ret = ANEG_TIMER_ENAB;
  1847. }
  1848. break;
  1849. case ANEG_STATE_DISABLE_LINK_OK:
  1850. ret = ANEG_DONE;
  1851. break;
  1852. case ANEG_STATE_ABILITY_DETECT_INIT:
  1853. ap->flags &= ~(MR_TOGGLE_TX);
  1854. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1855. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1856. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1857. tw32_f(MAC_MODE, tp->mac_mode);
  1858. udelay(40);
  1859. ap->state = ANEG_STATE_ABILITY_DETECT;
  1860. break;
  1861. case ANEG_STATE_ABILITY_DETECT:
  1862. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1863. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1864. }
  1865. break;
  1866. case ANEG_STATE_ACK_DETECT_INIT:
  1867. ap->txconfig |= ANEG_CFG_ACK;
  1868. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1869. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1870. tw32_f(MAC_MODE, tp->mac_mode);
  1871. udelay(40);
  1872. ap->state = ANEG_STATE_ACK_DETECT;
  1873. /* fallthru */
  1874. case ANEG_STATE_ACK_DETECT:
  1875. if (ap->ack_match != 0) {
  1876. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1877. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1878. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1879. } else {
  1880. ap->state = ANEG_STATE_AN_ENABLE;
  1881. }
  1882. } else if (ap->ability_match != 0 &&
  1883. ap->rxconfig == 0) {
  1884. ap->state = ANEG_STATE_AN_ENABLE;
  1885. }
  1886. break;
  1887. case ANEG_STATE_COMPLETE_ACK_INIT:
  1888. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1889. ret = ANEG_FAILED;
  1890. break;
  1891. }
  1892. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1893. MR_LP_ADV_HALF_DUPLEX |
  1894. MR_LP_ADV_SYM_PAUSE |
  1895. MR_LP_ADV_ASYM_PAUSE |
  1896. MR_LP_ADV_REMOTE_FAULT1 |
  1897. MR_LP_ADV_REMOTE_FAULT2 |
  1898. MR_LP_ADV_NEXT_PAGE |
  1899. MR_TOGGLE_RX |
  1900. MR_NP_RX);
  1901. if (ap->rxconfig & ANEG_CFG_FD)
  1902. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1903. if (ap->rxconfig & ANEG_CFG_HD)
  1904. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1905. if (ap->rxconfig & ANEG_CFG_PS1)
  1906. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1907. if (ap->rxconfig & ANEG_CFG_PS2)
  1908. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1909. if (ap->rxconfig & ANEG_CFG_RF1)
  1910. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1911. if (ap->rxconfig & ANEG_CFG_RF2)
  1912. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1913. if (ap->rxconfig & ANEG_CFG_NP)
  1914. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1915. ap->link_time = ap->cur_time;
  1916. ap->flags ^= (MR_TOGGLE_TX);
  1917. if (ap->rxconfig & 0x0008)
  1918. ap->flags |= MR_TOGGLE_RX;
  1919. if (ap->rxconfig & ANEG_CFG_NP)
  1920. ap->flags |= MR_NP_RX;
  1921. ap->flags |= MR_PAGE_RX;
  1922. ap->state = ANEG_STATE_COMPLETE_ACK;
  1923. ret = ANEG_TIMER_ENAB;
  1924. break;
  1925. case ANEG_STATE_COMPLETE_ACK:
  1926. if (ap->ability_match != 0 &&
  1927. ap->rxconfig == 0) {
  1928. ap->state = ANEG_STATE_AN_ENABLE;
  1929. break;
  1930. }
  1931. delta = ap->cur_time - ap->link_time;
  1932. if (delta > ANEG_STATE_SETTLE_TIME) {
  1933. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  1934. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1935. } else {
  1936. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  1937. !(ap->flags & MR_NP_RX)) {
  1938. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1939. } else {
  1940. ret = ANEG_FAILED;
  1941. }
  1942. }
  1943. }
  1944. break;
  1945. case ANEG_STATE_IDLE_DETECT_INIT:
  1946. ap->link_time = ap->cur_time;
  1947. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1948. tw32_f(MAC_MODE, tp->mac_mode);
  1949. udelay(40);
  1950. ap->state = ANEG_STATE_IDLE_DETECT;
  1951. ret = ANEG_TIMER_ENAB;
  1952. break;
  1953. case ANEG_STATE_IDLE_DETECT:
  1954. if (ap->ability_match != 0 &&
  1955. ap->rxconfig == 0) {
  1956. ap->state = ANEG_STATE_AN_ENABLE;
  1957. break;
  1958. }
  1959. delta = ap->cur_time - ap->link_time;
  1960. if (delta > ANEG_STATE_SETTLE_TIME) {
  1961. /* XXX another gem from the Broadcom driver :( */
  1962. ap->state = ANEG_STATE_LINK_OK;
  1963. }
  1964. break;
  1965. case ANEG_STATE_LINK_OK:
  1966. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1967. ret = ANEG_DONE;
  1968. break;
  1969. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1970. /* ??? unimplemented */
  1971. break;
  1972. case ANEG_STATE_NEXT_PAGE_WAIT:
  1973. /* ??? unimplemented */
  1974. break;
  1975. default:
  1976. ret = ANEG_FAILED;
  1977. break;
  1978. };
  1979. return ret;
  1980. }
  1981. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  1982. {
  1983. int res = 0;
  1984. struct tg3_fiber_aneginfo aninfo;
  1985. int status = ANEG_FAILED;
  1986. unsigned int tick;
  1987. u32 tmp;
  1988. tw32_f(MAC_TX_AUTO_NEG, 0);
  1989. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  1990. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  1991. udelay(40);
  1992. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  1993. udelay(40);
  1994. memset(&aninfo, 0, sizeof(aninfo));
  1995. aninfo.flags |= MR_AN_ENABLE;
  1996. aninfo.state = ANEG_STATE_UNKNOWN;
  1997. aninfo.cur_time = 0;
  1998. tick = 0;
  1999. while (++tick < 195000) {
  2000. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2001. if (status == ANEG_DONE || status == ANEG_FAILED)
  2002. break;
  2003. udelay(1);
  2004. }
  2005. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2006. tw32_f(MAC_MODE, tp->mac_mode);
  2007. udelay(40);
  2008. *flags = aninfo.flags;
  2009. if (status == ANEG_DONE &&
  2010. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2011. MR_LP_ADV_FULL_DUPLEX)))
  2012. res = 1;
  2013. return res;
  2014. }
  2015. static void tg3_init_bcm8002(struct tg3 *tp)
  2016. {
  2017. u32 mac_status = tr32(MAC_STATUS);
  2018. int i;
  2019. /* Reset when initting first time or we have a link. */
  2020. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2021. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2022. return;
  2023. /* Set PLL lock range. */
  2024. tg3_writephy(tp, 0x16, 0x8007);
  2025. /* SW reset */
  2026. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2027. /* Wait for reset to complete. */
  2028. /* XXX schedule_timeout() ... */
  2029. for (i = 0; i < 500; i++)
  2030. udelay(10);
  2031. /* Config mode; select PMA/Ch 1 regs. */
  2032. tg3_writephy(tp, 0x10, 0x8411);
  2033. /* Enable auto-lock and comdet, select txclk for tx. */
  2034. tg3_writephy(tp, 0x11, 0x0a10);
  2035. tg3_writephy(tp, 0x18, 0x00a0);
  2036. tg3_writephy(tp, 0x16, 0x41ff);
  2037. /* Assert and deassert POR. */
  2038. tg3_writephy(tp, 0x13, 0x0400);
  2039. udelay(40);
  2040. tg3_writephy(tp, 0x13, 0x0000);
  2041. tg3_writephy(tp, 0x11, 0x0a50);
  2042. udelay(40);
  2043. tg3_writephy(tp, 0x11, 0x0a10);
  2044. /* Wait for signal to stabilize */
  2045. /* XXX schedule_timeout() ... */
  2046. for (i = 0; i < 15000; i++)
  2047. udelay(10);
  2048. /* Deselect the channel register so we can read the PHYID
  2049. * later.
  2050. */
  2051. tg3_writephy(tp, 0x10, 0x8011);
  2052. }
  2053. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2054. {
  2055. u32 sg_dig_ctrl, sg_dig_status;
  2056. u32 serdes_cfg, expected_sg_dig_ctrl;
  2057. int workaround, port_a;
  2058. int current_link_up;
  2059. serdes_cfg = 0;
  2060. expected_sg_dig_ctrl = 0;
  2061. workaround = 0;
  2062. port_a = 1;
  2063. current_link_up = 0;
  2064. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2065. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2066. workaround = 1;
  2067. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2068. port_a = 0;
  2069. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2070. /* preserve bits 20-23 for voltage regulator */
  2071. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2072. }
  2073. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2074. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2075. if (sg_dig_ctrl & (1 << 31)) {
  2076. if (workaround) {
  2077. u32 val = serdes_cfg;
  2078. if (port_a)
  2079. val |= 0xc010000;
  2080. else
  2081. val |= 0x4010000;
  2082. tw32_f(MAC_SERDES_CFG, val);
  2083. }
  2084. tw32_f(SG_DIG_CTRL, 0x01388400);
  2085. }
  2086. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2087. tg3_setup_flow_control(tp, 0, 0);
  2088. current_link_up = 1;
  2089. }
  2090. goto out;
  2091. }
  2092. /* Want auto-negotiation. */
  2093. expected_sg_dig_ctrl = 0x81388400;
  2094. /* Pause capability */
  2095. expected_sg_dig_ctrl |= (1 << 11);
  2096. /* Asymettric pause */
  2097. expected_sg_dig_ctrl |= (1 << 12);
  2098. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2099. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2100. tp->serdes_counter &&
  2101. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2102. MAC_STATUS_RCVD_CFG)) ==
  2103. MAC_STATUS_PCS_SYNCED)) {
  2104. tp->serdes_counter--;
  2105. current_link_up = 1;
  2106. goto out;
  2107. }
  2108. restart_autoneg:
  2109. if (workaround)
  2110. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2111. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2112. udelay(5);
  2113. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2114. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2115. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2116. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2117. MAC_STATUS_SIGNAL_DET)) {
  2118. sg_dig_status = tr32(SG_DIG_STATUS);
  2119. mac_status = tr32(MAC_STATUS);
  2120. if ((sg_dig_status & (1 << 1)) &&
  2121. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2122. u32 local_adv, remote_adv;
  2123. local_adv = ADVERTISE_PAUSE_CAP;
  2124. remote_adv = 0;
  2125. if (sg_dig_status & (1 << 19))
  2126. remote_adv |= LPA_PAUSE_CAP;
  2127. if (sg_dig_status & (1 << 20))
  2128. remote_adv |= LPA_PAUSE_ASYM;
  2129. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2130. current_link_up = 1;
  2131. tp->serdes_counter = 0;
  2132. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2133. } else if (!(sg_dig_status & (1 << 1))) {
  2134. if (tp->serdes_counter)
  2135. tp->serdes_counter--;
  2136. else {
  2137. if (workaround) {
  2138. u32 val = serdes_cfg;
  2139. if (port_a)
  2140. val |= 0xc010000;
  2141. else
  2142. val |= 0x4010000;
  2143. tw32_f(MAC_SERDES_CFG, val);
  2144. }
  2145. tw32_f(SG_DIG_CTRL, 0x01388400);
  2146. udelay(40);
  2147. /* Link parallel detection - link is up */
  2148. /* only if we have PCS_SYNC and not */
  2149. /* receiving config code words */
  2150. mac_status = tr32(MAC_STATUS);
  2151. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2152. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2153. tg3_setup_flow_control(tp, 0, 0);
  2154. current_link_up = 1;
  2155. tp->tg3_flags2 |=
  2156. TG3_FLG2_PARALLEL_DETECT;
  2157. tp->serdes_counter =
  2158. SERDES_PARALLEL_DET_TIMEOUT;
  2159. } else
  2160. goto restart_autoneg;
  2161. }
  2162. }
  2163. } else {
  2164. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2165. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2166. }
  2167. out:
  2168. return current_link_up;
  2169. }
  2170. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2171. {
  2172. int current_link_up = 0;
  2173. if (!(mac_status & MAC_STATUS_PCS_SYNCED)) {
  2174. tp->tg3_flags &= ~TG3_FLAG_GOT_SERDES_FLOWCTL;
  2175. goto out;
  2176. }
  2177. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2178. u32 flags;
  2179. int i;
  2180. if (fiber_autoneg(tp, &flags)) {
  2181. u32 local_adv, remote_adv;
  2182. local_adv = ADVERTISE_PAUSE_CAP;
  2183. remote_adv = 0;
  2184. if (flags & MR_LP_ADV_SYM_PAUSE)
  2185. remote_adv |= LPA_PAUSE_CAP;
  2186. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2187. remote_adv |= LPA_PAUSE_ASYM;
  2188. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2189. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2190. current_link_up = 1;
  2191. }
  2192. for (i = 0; i < 30; i++) {
  2193. udelay(20);
  2194. tw32_f(MAC_STATUS,
  2195. (MAC_STATUS_SYNC_CHANGED |
  2196. MAC_STATUS_CFG_CHANGED));
  2197. udelay(40);
  2198. if ((tr32(MAC_STATUS) &
  2199. (MAC_STATUS_SYNC_CHANGED |
  2200. MAC_STATUS_CFG_CHANGED)) == 0)
  2201. break;
  2202. }
  2203. mac_status = tr32(MAC_STATUS);
  2204. if (current_link_up == 0 &&
  2205. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2206. !(mac_status & MAC_STATUS_RCVD_CFG))
  2207. current_link_up = 1;
  2208. } else {
  2209. /* Forcing 1000FD link up. */
  2210. current_link_up = 1;
  2211. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2212. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2213. udelay(40);
  2214. }
  2215. out:
  2216. return current_link_up;
  2217. }
  2218. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2219. {
  2220. u32 orig_pause_cfg;
  2221. u16 orig_active_speed;
  2222. u8 orig_active_duplex;
  2223. u32 mac_status;
  2224. int current_link_up;
  2225. int i;
  2226. orig_pause_cfg =
  2227. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2228. TG3_FLAG_TX_PAUSE));
  2229. orig_active_speed = tp->link_config.active_speed;
  2230. orig_active_duplex = tp->link_config.active_duplex;
  2231. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2232. netif_carrier_ok(tp->dev) &&
  2233. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2234. mac_status = tr32(MAC_STATUS);
  2235. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2236. MAC_STATUS_SIGNAL_DET |
  2237. MAC_STATUS_CFG_CHANGED |
  2238. MAC_STATUS_RCVD_CFG);
  2239. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2240. MAC_STATUS_SIGNAL_DET)) {
  2241. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2242. MAC_STATUS_CFG_CHANGED));
  2243. return 0;
  2244. }
  2245. }
  2246. tw32_f(MAC_TX_AUTO_NEG, 0);
  2247. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2248. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2249. tw32_f(MAC_MODE, tp->mac_mode);
  2250. udelay(40);
  2251. if (tp->phy_id == PHY_ID_BCM8002)
  2252. tg3_init_bcm8002(tp);
  2253. /* Enable link change event even when serdes polling. */
  2254. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2255. udelay(40);
  2256. current_link_up = 0;
  2257. mac_status = tr32(MAC_STATUS);
  2258. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2259. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2260. else
  2261. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2262. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  2263. tw32_f(MAC_MODE, tp->mac_mode);
  2264. udelay(40);
  2265. tp->hw_status->status =
  2266. (SD_STATUS_UPDATED |
  2267. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2268. for (i = 0; i < 100; i++) {
  2269. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2270. MAC_STATUS_CFG_CHANGED));
  2271. udelay(5);
  2272. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2273. MAC_STATUS_CFG_CHANGED |
  2274. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2275. break;
  2276. }
  2277. mac_status = tr32(MAC_STATUS);
  2278. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2279. current_link_up = 0;
  2280. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2281. tp->serdes_counter == 0) {
  2282. tw32_f(MAC_MODE, (tp->mac_mode |
  2283. MAC_MODE_SEND_CONFIGS));
  2284. udelay(1);
  2285. tw32_f(MAC_MODE, tp->mac_mode);
  2286. }
  2287. }
  2288. if (current_link_up == 1) {
  2289. tp->link_config.active_speed = SPEED_1000;
  2290. tp->link_config.active_duplex = DUPLEX_FULL;
  2291. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2292. LED_CTRL_LNKLED_OVERRIDE |
  2293. LED_CTRL_1000MBPS_ON));
  2294. } else {
  2295. tp->link_config.active_speed = SPEED_INVALID;
  2296. tp->link_config.active_duplex = DUPLEX_INVALID;
  2297. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2298. LED_CTRL_LNKLED_OVERRIDE |
  2299. LED_CTRL_TRAFFIC_OVERRIDE));
  2300. }
  2301. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2302. if (current_link_up)
  2303. netif_carrier_on(tp->dev);
  2304. else
  2305. netif_carrier_off(tp->dev);
  2306. tg3_link_report(tp);
  2307. } else {
  2308. u32 now_pause_cfg =
  2309. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2310. TG3_FLAG_TX_PAUSE);
  2311. if (orig_pause_cfg != now_pause_cfg ||
  2312. orig_active_speed != tp->link_config.active_speed ||
  2313. orig_active_duplex != tp->link_config.active_duplex)
  2314. tg3_link_report(tp);
  2315. }
  2316. return 0;
  2317. }
  2318. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2319. {
  2320. int current_link_up, err = 0;
  2321. u32 bmsr, bmcr;
  2322. u16 current_speed;
  2323. u8 current_duplex;
  2324. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2325. tw32_f(MAC_MODE, tp->mac_mode);
  2326. udelay(40);
  2327. tw32(MAC_EVENT, 0);
  2328. tw32_f(MAC_STATUS,
  2329. (MAC_STATUS_SYNC_CHANGED |
  2330. MAC_STATUS_CFG_CHANGED |
  2331. MAC_STATUS_MI_COMPLETION |
  2332. MAC_STATUS_LNKSTATE_CHANGED));
  2333. udelay(40);
  2334. if (force_reset)
  2335. tg3_phy_reset(tp);
  2336. current_link_up = 0;
  2337. current_speed = SPEED_INVALID;
  2338. current_duplex = DUPLEX_INVALID;
  2339. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2340. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2341. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2342. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2343. bmsr |= BMSR_LSTATUS;
  2344. else
  2345. bmsr &= ~BMSR_LSTATUS;
  2346. }
  2347. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2348. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2349. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2350. /* do nothing, just check for link up at the end */
  2351. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2352. u32 adv, new_adv;
  2353. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2354. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2355. ADVERTISE_1000XPAUSE |
  2356. ADVERTISE_1000XPSE_ASYM |
  2357. ADVERTISE_SLCT);
  2358. /* Always advertise symmetric PAUSE just like copper */
  2359. new_adv |= ADVERTISE_1000XPAUSE;
  2360. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2361. new_adv |= ADVERTISE_1000XHALF;
  2362. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2363. new_adv |= ADVERTISE_1000XFULL;
  2364. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2365. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2366. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2367. tg3_writephy(tp, MII_BMCR, bmcr);
  2368. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2369. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2370. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2371. return err;
  2372. }
  2373. } else {
  2374. u32 new_bmcr;
  2375. bmcr &= ~BMCR_SPEED1000;
  2376. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2377. if (tp->link_config.duplex == DUPLEX_FULL)
  2378. new_bmcr |= BMCR_FULLDPLX;
  2379. if (new_bmcr != bmcr) {
  2380. /* BMCR_SPEED1000 is a reserved bit that needs
  2381. * to be set on write.
  2382. */
  2383. new_bmcr |= BMCR_SPEED1000;
  2384. /* Force a linkdown */
  2385. if (netif_carrier_ok(tp->dev)) {
  2386. u32 adv;
  2387. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2388. adv &= ~(ADVERTISE_1000XFULL |
  2389. ADVERTISE_1000XHALF |
  2390. ADVERTISE_SLCT);
  2391. tg3_writephy(tp, MII_ADVERTISE, adv);
  2392. tg3_writephy(tp, MII_BMCR, bmcr |
  2393. BMCR_ANRESTART |
  2394. BMCR_ANENABLE);
  2395. udelay(10);
  2396. netif_carrier_off(tp->dev);
  2397. }
  2398. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2399. bmcr = new_bmcr;
  2400. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2401. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2402. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2403. ASIC_REV_5714) {
  2404. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2405. bmsr |= BMSR_LSTATUS;
  2406. else
  2407. bmsr &= ~BMSR_LSTATUS;
  2408. }
  2409. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2410. }
  2411. }
  2412. if (bmsr & BMSR_LSTATUS) {
  2413. current_speed = SPEED_1000;
  2414. current_link_up = 1;
  2415. if (bmcr & BMCR_FULLDPLX)
  2416. current_duplex = DUPLEX_FULL;
  2417. else
  2418. current_duplex = DUPLEX_HALF;
  2419. if (bmcr & BMCR_ANENABLE) {
  2420. u32 local_adv, remote_adv, common;
  2421. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2422. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2423. common = local_adv & remote_adv;
  2424. if (common & (ADVERTISE_1000XHALF |
  2425. ADVERTISE_1000XFULL)) {
  2426. if (common & ADVERTISE_1000XFULL)
  2427. current_duplex = DUPLEX_FULL;
  2428. else
  2429. current_duplex = DUPLEX_HALF;
  2430. tg3_setup_flow_control(tp, local_adv,
  2431. remote_adv);
  2432. }
  2433. else
  2434. current_link_up = 0;
  2435. }
  2436. }
  2437. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2438. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2439. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2440. tw32_f(MAC_MODE, tp->mac_mode);
  2441. udelay(40);
  2442. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2443. tp->link_config.active_speed = current_speed;
  2444. tp->link_config.active_duplex = current_duplex;
  2445. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2446. if (current_link_up)
  2447. netif_carrier_on(tp->dev);
  2448. else {
  2449. netif_carrier_off(tp->dev);
  2450. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2451. }
  2452. tg3_link_report(tp);
  2453. }
  2454. return err;
  2455. }
  2456. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2457. {
  2458. if (tp->serdes_counter) {
  2459. /* Give autoneg time to complete. */
  2460. tp->serdes_counter--;
  2461. return;
  2462. }
  2463. if (!netif_carrier_ok(tp->dev) &&
  2464. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2465. u32 bmcr;
  2466. tg3_readphy(tp, MII_BMCR, &bmcr);
  2467. if (bmcr & BMCR_ANENABLE) {
  2468. u32 phy1, phy2;
  2469. /* Select shadow register 0x1f */
  2470. tg3_writephy(tp, 0x1c, 0x7c00);
  2471. tg3_readphy(tp, 0x1c, &phy1);
  2472. /* Select expansion interrupt status register */
  2473. tg3_writephy(tp, 0x17, 0x0f01);
  2474. tg3_readphy(tp, 0x15, &phy2);
  2475. tg3_readphy(tp, 0x15, &phy2);
  2476. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2477. /* We have signal detect and not receiving
  2478. * config code words, link is up by parallel
  2479. * detection.
  2480. */
  2481. bmcr &= ~BMCR_ANENABLE;
  2482. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2483. tg3_writephy(tp, MII_BMCR, bmcr);
  2484. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2485. }
  2486. }
  2487. }
  2488. else if (netif_carrier_ok(tp->dev) &&
  2489. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2490. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2491. u32 phy2;
  2492. /* Select expansion interrupt status register */
  2493. tg3_writephy(tp, 0x17, 0x0f01);
  2494. tg3_readphy(tp, 0x15, &phy2);
  2495. if (phy2 & 0x20) {
  2496. u32 bmcr;
  2497. /* Config code words received, turn on autoneg. */
  2498. tg3_readphy(tp, MII_BMCR, &bmcr);
  2499. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2500. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2501. }
  2502. }
  2503. }
  2504. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2505. {
  2506. int err;
  2507. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2508. err = tg3_setup_fiber_phy(tp, force_reset);
  2509. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2510. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2511. } else {
  2512. err = tg3_setup_copper_phy(tp, force_reset);
  2513. }
  2514. if (tp->link_config.active_speed == SPEED_1000 &&
  2515. tp->link_config.active_duplex == DUPLEX_HALF)
  2516. tw32(MAC_TX_LENGTHS,
  2517. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2518. (6 << TX_LENGTHS_IPG_SHIFT) |
  2519. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2520. else
  2521. tw32(MAC_TX_LENGTHS,
  2522. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2523. (6 << TX_LENGTHS_IPG_SHIFT) |
  2524. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2525. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2526. if (netif_carrier_ok(tp->dev)) {
  2527. tw32(HOSTCC_STAT_COAL_TICKS,
  2528. tp->coal.stats_block_coalesce_usecs);
  2529. } else {
  2530. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2531. }
  2532. }
  2533. return err;
  2534. }
  2535. /* This is called whenever we suspect that the system chipset is re-
  2536. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2537. * is bogus tx completions. We try to recover by setting the
  2538. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2539. * in the workqueue.
  2540. */
  2541. static void tg3_tx_recover(struct tg3 *tp)
  2542. {
  2543. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2544. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2545. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2546. "mapped I/O cycles to the network device, attempting to "
  2547. "recover. Please report the problem to the driver maintainer "
  2548. "and include system chipset information.\n", tp->dev->name);
  2549. spin_lock(&tp->lock);
  2550. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2551. spin_unlock(&tp->lock);
  2552. }
  2553. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2554. {
  2555. smp_mb();
  2556. return (tp->tx_pending -
  2557. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2558. }
  2559. /* Tigon3 never reports partial packet sends. So we do not
  2560. * need special logic to handle SKBs that have not had all
  2561. * of their frags sent yet, like SunGEM does.
  2562. */
  2563. static void tg3_tx(struct tg3 *tp)
  2564. {
  2565. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2566. u32 sw_idx = tp->tx_cons;
  2567. while (sw_idx != hw_idx) {
  2568. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2569. struct sk_buff *skb = ri->skb;
  2570. int i, tx_bug = 0;
  2571. if (unlikely(skb == NULL)) {
  2572. tg3_tx_recover(tp);
  2573. return;
  2574. }
  2575. pci_unmap_single(tp->pdev,
  2576. pci_unmap_addr(ri, mapping),
  2577. skb_headlen(skb),
  2578. PCI_DMA_TODEVICE);
  2579. ri->skb = NULL;
  2580. sw_idx = NEXT_TX(sw_idx);
  2581. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2582. ri = &tp->tx_buffers[sw_idx];
  2583. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2584. tx_bug = 1;
  2585. pci_unmap_page(tp->pdev,
  2586. pci_unmap_addr(ri, mapping),
  2587. skb_shinfo(skb)->frags[i].size,
  2588. PCI_DMA_TODEVICE);
  2589. sw_idx = NEXT_TX(sw_idx);
  2590. }
  2591. dev_kfree_skb(skb);
  2592. if (unlikely(tx_bug)) {
  2593. tg3_tx_recover(tp);
  2594. return;
  2595. }
  2596. }
  2597. tp->tx_cons = sw_idx;
  2598. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2599. * before checking for netif_queue_stopped(). Without the
  2600. * memory barrier, there is a small possibility that tg3_start_xmit()
  2601. * will miss it and cause the queue to be stopped forever.
  2602. */
  2603. smp_mb();
  2604. if (unlikely(netif_queue_stopped(tp->dev) &&
  2605. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2606. netif_tx_lock(tp->dev);
  2607. if (netif_queue_stopped(tp->dev) &&
  2608. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2609. netif_wake_queue(tp->dev);
  2610. netif_tx_unlock(tp->dev);
  2611. }
  2612. }
  2613. /* Returns size of skb allocated or < 0 on error.
  2614. *
  2615. * We only need to fill in the address because the other members
  2616. * of the RX descriptor are invariant, see tg3_init_rings.
  2617. *
  2618. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2619. * posting buffers we only dirty the first cache line of the RX
  2620. * descriptor (containing the address). Whereas for the RX status
  2621. * buffers the cpu only reads the last cacheline of the RX descriptor
  2622. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2623. */
  2624. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2625. int src_idx, u32 dest_idx_unmasked)
  2626. {
  2627. struct tg3_rx_buffer_desc *desc;
  2628. struct ring_info *map, *src_map;
  2629. struct sk_buff *skb;
  2630. dma_addr_t mapping;
  2631. int skb_size, dest_idx;
  2632. src_map = NULL;
  2633. switch (opaque_key) {
  2634. case RXD_OPAQUE_RING_STD:
  2635. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2636. desc = &tp->rx_std[dest_idx];
  2637. map = &tp->rx_std_buffers[dest_idx];
  2638. if (src_idx >= 0)
  2639. src_map = &tp->rx_std_buffers[src_idx];
  2640. skb_size = tp->rx_pkt_buf_sz;
  2641. break;
  2642. case RXD_OPAQUE_RING_JUMBO:
  2643. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2644. desc = &tp->rx_jumbo[dest_idx];
  2645. map = &tp->rx_jumbo_buffers[dest_idx];
  2646. if (src_idx >= 0)
  2647. src_map = &tp->rx_jumbo_buffers[src_idx];
  2648. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2649. break;
  2650. default:
  2651. return -EINVAL;
  2652. };
  2653. /* Do not overwrite any of the map or rp information
  2654. * until we are sure we can commit to a new buffer.
  2655. *
  2656. * Callers depend upon this behavior and assume that
  2657. * we leave everything unchanged if we fail.
  2658. */
  2659. skb = netdev_alloc_skb(tp->dev, skb_size);
  2660. if (skb == NULL)
  2661. return -ENOMEM;
  2662. skb_reserve(skb, tp->rx_offset);
  2663. mapping = pci_map_single(tp->pdev, skb->data,
  2664. skb_size - tp->rx_offset,
  2665. PCI_DMA_FROMDEVICE);
  2666. map->skb = skb;
  2667. pci_unmap_addr_set(map, mapping, mapping);
  2668. if (src_map != NULL)
  2669. src_map->skb = NULL;
  2670. desc->addr_hi = ((u64)mapping >> 32);
  2671. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2672. return skb_size;
  2673. }
  2674. /* We only need to move over in the address because the other
  2675. * members of the RX descriptor are invariant. See notes above
  2676. * tg3_alloc_rx_skb for full details.
  2677. */
  2678. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2679. int src_idx, u32 dest_idx_unmasked)
  2680. {
  2681. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2682. struct ring_info *src_map, *dest_map;
  2683. int dest_idx;
  2684. switch (opaque_key) {
  2685. case RXD_OPAQUE_RING_STD:
  2686. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2687. dest_desc = &tp->rx_std[dest_idx];
  2688. dest_map = &tp->rx_std_buffers[dest_idx];
  2689. src_desc = &tp->rx_std[src_idx];
  2690. src_map = &tp->rx_std_buffers[src_idx];
  2691. break;
  2692. case RXD_OPAQUE_RING_JUMBO:
  2693. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2694. dest_desc = &tp->rx_jumbo[dest_idx];
  2695. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2696. src_desc = &tp->rx_jumbo[src_idx];
  2697. src_map = &tp->rx_jumbo_buffers[src_idx];
  2698. break;
  2699. default:
  2700. return;
  2701. };
  2702. dest_map->skb = src_map->skb;
  2703. pci_unmap_addr_set(dest_map, mapping,
  2704. pci_unmap_addr(src_map, mapping));
  2705. dest_desc->addr_hi = src_desc->addr_hi;
  2706. dest_desc->addr_lo = src_desc->addr_lo;
  2707. src_map->skb = NULL;
  2708. }
  2709. #if TG3_VLAN_TAG_USED
  2710. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2711. {
  2712. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2713. }
  2714. #endif
  2715. /* The RX ring scheme is composed of multiple rings which post fresh
  2716. * buffers to the chip, and one special ring the chip uses to report
  2717. * status back to the host.
  2718. *
  2719. * The special ring reports the status of received packets to the
  2720. * host. The chip does not write into the original descriptor the
  2721. * RX buffer was obtained from. The chip simply takes the original
  2722. * descriptor as provided by the host, updates the status and length
  2723. * field, then writes this into the next status ring entry.
  2724. *
  2725. * Each ring the host uses to post buffers to the chip is described
  2726. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2727. * it is first placed into the on-chip ram. When the packet's length
  2728. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2729. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2730. * which is within the range of the new packet's length is chosen.
  2731. *
  2732. * The "separate ring for rx status" scheme may sound queer, but it makes
  2733. * sense from a cache coherency perspective. If only the host writes
  2734. * to the buffer post rings, and only the chip writes to the rx status
  2735. * rings, then cache lines never move beyond shared-modified state.
  2736. * If both the host and chip were to write into the same ring, cache line
  2737. * eviction could occur since both entities want it in an exclusive state.
  2738. */
  2739. static int tg3_rx(struct tg3 *tp, int budget)
  2740. {
  2741. u32 work_mask, rx_std_posted = 0;
  2742. u32 sw_idx = tp->rx_rcb_ptr;
  2743. u16 hw_idx;
  2744. int received;
  2745. hw_idx = tp->hw_status->idx[0].rx_producer;
  2746. /*
  2747. * We need to order the read of hw_idx and the read of
  2748. * the opaque cookie.
  2749. */
  2750. rmb();
  2751. work_mask = 0;
  2752. received = 0;
  2753. while (sw_idx != hw_idx && budget > 0) {
  2754. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2755. unsigned int len;
  2756. struct sk_buff *skb;
  2757. dma_addr_t dma_addr;
  2758. u32 opaque_key, desc_idx, *post_ptr;
  2759. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2760. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2761. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2762. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2763. mapping);
  2764. skb = tp->rx_std_buffers[desc_idx].skb;
  2765. post_ptr = &tp->rx_std_ptr;
  2766. rx_std_posted++;
  2767. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2768. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2769. mapping);
  2770. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2771. post_ptr = &tp->rx_jumbo_ptr;
  2772. }
  2773. else {
  2774. goto next_pkt_nopost;
  2775. }
  2776. work_mask |= opaque_key;
  2777. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2778. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2779. drop_it:
  2780. tg3_recycle_rx(tp, opaque_key,
  2781. desc_idx, *post_ptr);
  2782. drop_it_no_recycle:
  2783. /* Other statistics kept track of by card. */
  2784. tp->net_stats.rx_dropped++;
  2785. goto next_pkt;
  2786. }
  2787. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2788. if (len > RX_COPY_THRESHOLD
  2789. && tp->rx_offset == 2
  2790. /* rx_offset != 2 iff this is a 5701 card running
  2791. * in PCI-X mode [see tg3_get_invariants()] */
  2792. ) {
  2793. int skb_size;
  2794. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2795. desc_idx, *post_ptr);
  2796. if (skb_size < 0)
  2797. goto drop_it;
  2798. pci_unmap_single(tp->pdev, dma_addr,
  2799. skb_size - tp->rx_offset,
  2800. PCI_DMA_FROMDEVICE);
  2801. skb_put(skb, len);
  2802. } else {
  2803. struct sk_buff *copy_skb;
  2804. tg3_recycle_rx(tp, opaque_key,
  2805. desc_idx, *post_ptr);
  2806. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  2807. if (copy_skb == NULL)
  2808. goto drop_it_no_recycle;
  2809. skb_reserve(copy_skb, 2);
  2810. skb_put(copy_skb, len);
  2811. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2812. memcpy(copy_skb->data, skb->data, len);
  2813. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2814. /* We'll reuse the original ring buffer. */
  2815. skb = copy_skb;
  2816. }
  2817. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2818. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2819. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2820. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2821. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2822. else
  2823. skb->ip_summed = CHECKSUM_NONE;
  2824. skb->protocol = eth_type_trans(skb, tp->dev);
  2825. #if TG3_VLAN_TAG_USED
  2826. if (tp->vlgrp != NULL &&
  2827. desc->type_flags & RXD_FLAG_VLAN) {
  2828. tg3_vlan_rx(tp, skb,
  2829. desc->err_vlan & RXD_VLAN_MASK);
  2830. } else
  2831. #endif
  2832. netif_receive_skb(skb);
  2833. tp->dev->last_rx = jiffies;
  2834. received++;
  2835. budget--;
  2836. next_pkt:
  2837. (*post_ptr)++;
  2838. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2839. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2840. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2841. TG3_64BIT_REG_LOW, idx);
  2842. work_mask &= ~RXD_OPAQUE_RING_STD;
  2843. rx_std_posted = 0;
  2844. }
  2845. next_pkt_nopost:
  2846. sw_idx++;
  2847. sw_idx %= TG3_RX_RCB_RING_SIZE(tp);
  2848. /* Refresh hw_idx to see if there is new work */
  2849. if (sw_idx == hw_idx) {
  2850. hw_idx = tp->hw_status->idx[0].rx_producer;
  2851. rmb();
  2852. }
  2853. }
  2854. /* ACK the status ring. */
  2855. tp->rx_rcb_ptr = sw_idx;
  2856. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2857. /* Refill RX ring(s). */
  2858. if (work_mask & RXD_OPAQUE_RING_STD) {
  2859. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2860. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2861. sw_idx);
  2862. }
  2863. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2864. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2865. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2866. sw_idx);
  2867. }
  2868. mmiowb();
  2869. return received;
  2870. }
  2871. static int tg3_poll(struct net_device *netdev, int *budget)
  2872. {
  2873. struct tg3 *tp = netdev_priv(netdev);
  2874. struct tg3_hw_status *sblk = tp->hw_status;
  2875. int done;
  2876. /* handle link change and other phy events */
  2877. if (!(tp->tg3_flags &
  2878. (TG3_FLAG_USE_LINKCHG_REG |
  2879. TG3_FLAG_POLL_SERDES))) {
  2880. if (sblk->status & SD_STATUS_LINK_CHG) {
  2881. sblk->status = SD_STATUS_UPDATED |
  2882. (sblk->status & ~SD_STATUS_LINK_CHG);
  2883. spin_lock(&tp->lock);
  2884. tg3_setup_phy(tp, 0);
  2885. spin_unlock(&tp->lock);
  2886. }
  2887. }
  2888. /* run TX completion thread */
  2889. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2890. tg3_tx(tp);
  2891. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2892. netif_rx_complete(netdev);
  2893. schedule_work(&tp->reset_task);
  2894. return 0;
  2895. }
  2896. }
  2897. /* run RX thread, within the bounds set by NAPI.
  2898. * All RX "locking" is done by ensuring outside
  2899. * code synchronizes with dev->poll()
  2900. */
  2901. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2902. int orig_budget = *budget;
  2903. int work_done;
  2904. if (orig_budget > netdev->quota)
  2905. orig_budget = netdev->quota;
  2906. work_done = tg3_rx(tp, orig_budget);
  2907. *budget -= work_done;
  2908. netdev->quota -= work_done;
  2909. }
  2910. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2911. tp->last_tag = sblk->status_tag;
  2912. rmb();
  2913. } else
  2914. sblk->status &= ~SD_STATUS_UPDATED;
  2915. /* if no more work, tell net stack and NIC we're done */
  2916. done = !tg3_has_work(tp);
  2917. if (done) {
  2918. netif_rx_complete(netdev);
  2919. tg3_restart_ints(tp);
  2920. }
  2921. return (done ? 0 : 1);
  2922. }
  2923. static void tg3_irq_quiesce(struct tg3 *tp)
  2924. {
  2925. BUG_ON(tp->irq_sync);
  2926. tp->irq_sync = 1;
  2927. smp_mb();
  2928. synchronize_irq(tp->pdev->irq);
  2929. }
  2930. static inline int tg3_irq_sync(struct tg3 *tp)
  2931. {
  2932. return tp->irq_sync;
  2933. }
  2934. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  2935. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  2936. * with as well. Most of the time, this is not necessary except when
  2937. * shutting down the device.
  2938. */
  2939. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  2940. {
  2941. if (irq_sync)
  2942. tg3_irq_quiesce(tp);
  2943. spin_lock_bh(&tp->lock);
  2944. }
  2945. static inline void tg3_full_unlock(struct tg3 *tp)
  2946. {
  2947. spin_unlock_bh(&tp->lock);
  2948. }
  2949. /* One-shot MSI handler - Chip automatically disables interrupt
  2950. * after sending MSI so driver doesn't have to do it.
  2951. */
  2952. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  2953. {
  2954. struct net_device *dev = dev_id;
  2955. struct tg3 *tp = netdev_priv(dev);
  2956. prefetch(tp->hw_status);
  2957. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2958. if (likely(!tg3_irq_sync(tp)))
  2959. netif_rx_schedule(dev); /* schedule NAPI poll */
  2960. return IRQ_HANDLED;
  2961. }
  2962. /* MSI ISR - No need to check for interrupt sharing and no need to
  2963. * flush status block and interrupt mailbox. PCI ordering rules
  2964. * guarantee that MSI will arrive after the status block.
  2965. */
  2966. static irqreturn_t tg3_msi(int irq, void *dev_id)
  2967. {
  2968. struct net_device *dev = dev_id;
  2969. struct tg3 *tp = netdev_priv(dev);
  2970. prefetch(tp->hw_status);
  2971. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2972. /*
  2973. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2974. * chip-internal interrupt pending events.
  2975. * Writing non-zero to intr-mbox-0 additional tells the
  2976. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2977. * event coalescing.
  2978. */
  2979. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  2980. if (likely(!tg3_irq_sync(tp)))
  2981. netif_rx_schedule(dev); /* schedule NAPI poll */
  2982. return IRQ_RETVAL(1);
  2983. }
  2984. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  2985. {
  2986. struct net_device *dev = dev_id;
  2987. struct tg3 *tp = netdev_priv(dev);
  2988. struct tg3_hw_status *sblk = tp->hw_status;
  2989. unsigned int handled = 1;
  2990. /* In INTx mode, it is possible for the interrupt to arrive at
  2991. * the CPU before the status block posted prior to the interrupt.
  2992. * Reading the PCI State register will confirm whether the
  2993. * interrupt is ours and will flush the status block.
  2994. */
  2995. if ((sblk->status & SD_STATUS_UPDATED) ||
  2996. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  2997. /*
  2998. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2999. * chip-internal interrupt pending events.
  3000. * Writing non-zero to intr-mbox-0 additional tells the
  3001. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3002. * event coalescing.
  3003. */
  3004. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3005. 0x00000001);
  3006. if (tg3_irq_sync(tp))
  3007. goto out;
  3008. sblk->status &= ~SD_STATUS_UPDATED;
  3009. if (likely(tg3_has_work(tp))) {
  3010. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3011. netif_rx_schedule(dev); /* schedule NAPI poll */
  3012. } else {
  3013. /* No work, shared interrupt perhaps? re-enable
  3014. * interrupts, and flush that PCI write
  3015. */
  3016. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3017. 0x00000000);
  3018. }
  3019. } else { /* shared interrupt */
  3020. handled = 0;
  3021. }
  3022. out:
  3023. return IRQ_RETVAL(handled);
  3024. }
  3025. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3026. {
  3027. struct net_device *dev = dev_id;
  3028. struct tg3 *tp = netdev_priv(dev);
  3029. struct tg3_hw_status *sblk = tp->hw_status;
  3030. unsigned int handled = 1;
  3031. /* In INTx mode, it is possible for the interrupt to arrive at
  3032. * the CPU before the status block posted prior to the interrupt.
  3033. * Reading the PCI State register will confirm whether the
  3034. * interrupt is ours and will flush the status block.
  3035. */
  3036. if ((sblk->status_tag != tp->last_tag) ||
  3037. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3038. /*
  3039. * writing any value to intr-mbox-0 clears PCI INTA# and
  3040. * chip-internal interrupt pending events.
  3041. * writing non-zero to intr-mbox-0 additional tells the
  3042. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3043. * event coalescing.
  3044. */
  3045. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3046. 0x00000001);
  3047. if (tg3_irq_sync(tp))
  3048. goto out;
  3049. if (netif_rx_schedule_prep(dev)) {
  3050. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3051. /* Update last_tag to mark that this status has been
  3052. * seen. Because interrupt may be shared, we may be
  3053. * racing with tg3_poll(), so only update last_tag
  3054. * if tg3_poll() is not scheduled.
  3055. */
  3056. tp->last_tag = sblk->status_tag;
  3057. __netif_rx_schedule(dev);
  3058. }
  3059. } else { /* shared interrupt */
  3060. handled = 0;
  3061. }
  3062. out:
  3063. return IRQ_RETVAL(handled);
  3064. }
  3065. /* ISR for interrupt test */
  3066. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3067. {
  3068. struct net_device *dev = dev_id;
  3069. struct tg3 *tp = netdev_priv(dev);
  3070. struct tg3_hw_status *sblk = tp->hw_status;
  3071. if ((sblk->status & SD_STATUS_UPDATED) ||
  3072. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3073. tg3_disable_ints(tp);
  3074. return IRQ_RETVAL(1);
  3075. }
  3076. return IRQ_RETVAL(0);
  3077. }
  3078. static int tg3_init_hw(struct tg3 *, int);
  3079. static int tg3_halt(struct tg3 *, int, int);
  3080. /* Restart hardware after configuration changes, self-test, etc.
  3081. * Invoked with tp->lock held.
  3082. */
  3083. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3084. {
  3085. int err;
  3086. err = tg3_init_hw(tp, reset_phy);
  3087. if (err) {
  3088. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3089. "aborting.\n", tp->dev->name);
  3090. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3091. tg3_full_unlock(tp);
  3092. del_timer_sync(&tp->timer);
  3093. tp->irq_sync = 0;
  3094. netif_poll_enable(tp->dev);
  3095. dev_close(tp->dev);
  3096. tg3_full_lock(tp, 0);
  3097. }
  3098. return err;
  3099. }
  3100. #ifdef CONFIG_NET_POLL_CONTROLLER
  3101. static void tg3_poll_controller(struct net_device *dev)
  3102. {
  3103. struct tg3 *tp = netdev_priv(dev);
  3104. tg3_interrupt(tp->pdev->irq, dev);
  3105. }
  3106. #endif
  3107. static void tg3_reset_task(struct work_struct *work)
  3108. {
  3109. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3110. unsigned int restart_timer;
  3111. tg3_full_lock(tp, 0);
  3112. tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
  3113. if (!netif_running(tp->dev)) {
  3114. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3115. tg3_full_unlock(tp);
  3116. return;
  3117. }
  3118. tg3_full_unlock(tp);
  3119. tg3_netif_stop(tp);
  3120. tg3_full_lock(tp, 1);
  3121. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3122. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3123. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3124. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3125. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3126. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3127. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3128. }
  3129. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3130. if (tg3_init_hw(tp, 1))
  3131. goto out;
  3132. tg3_netif_start(tp);
  3133. if (restart_timer)
  3134. mod_timer(&tp->timer, jiffies + 1);
  3135. out:
  3136. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3137. tg3_full_unlock(tp);
  3138. }
  3139. static void tg3_tx_timeout(struct net_device *dev)
  3140. {
  3141. struct tg3 *tp = netdev_priv(dev);
  3142. if (netif_msg_tx_err(tp))
  3143. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3144. dev->name);
  3145. schedule_work(&tp->reset_task);
  3146. }
  3147. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3148. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3149. {
  3150. u32 base = (u32) mapping & 0xffffffff;
  3151. return ((base > 0xffffdcc0) &&
  3152. (base + len + 8 < base));
  3153. }
  3154. /* Test for DMA addresses > 40-bit */
  3155. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3156. int len)
  3157. {
  3158. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3159. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3160. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3161. return 0;
  3162. #else
  3163. return 0;
  3164. #endif
  3165. }
  3166. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3167. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3168. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3169. u32 last_plus_one, u32 *start,
  3170. u32 base_flags, u32 mss)
  3171. {
  3172. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3173. dma_addr_t new_addr = 0;
  3174. u32 entry = *start;
  3175. int i, ret = 0;
  3176. if (!new_skb) {
  3177. ret = -1;
  3178. } else {
  3179. /* New SKB is guaranteed to be linear. */
  3180. entry = *start;
  3181. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3182. PCI_DMA_TODEVICE);
  3183. /* Make sure new skb does not cross any 4G boundaries.
  3184. * Drop the packet if it does.
  3185. */
  3186. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3187. ret = -1;
  3188. dev_kfree_skb(new_skb);
  3189. new_skb = NULL;
  3190. } else {
  3191. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3192. base_flags, 1 | (mss << 1));
  3193. *start = NEXT_TX(entry);
  3194. }
  3195. }
  3196. /* Now clean up the sw ring entries. */
  3197. i = 0;
  3198. while (entry != last_plus_one) {
  3199. int len;
  3200. if (i == 0)
  3201. len = skb_headlen(skb);
  3202. else
  3203. len = skb_shinfo(skb)->frags[i-1].size;
  3204. pci_unmap_single(tp->pdev,
  3205. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3206. len, PCI_DMA_TODEVICE);
  3207. if (i == 0) {
  3208. tp->tx_buffers[entry].skb = new_skb;
  3209. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3210. } else {
  3211. tp->tx_buffers[entry].skb = NULL;
  3212. }
  3213. entry = NEXT_TX(entry);
  3214. i++;
  3215. }
  3216. dev_kfree_skb(skb);
  3217. return ret;
  3218. }
  3219. static void tg3_set_txd(struct tg3 *tp, int entry,
  3220. dma_addr_t mapping, int len, u32 flags,
  3221. u32 mss_and_is_end)
  3222. {
  3223. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3224. int is_end = (mss_and_is_end & 0x1);
  3225. u32 mss = (mss_and_is_end >> 1);
  3226. u32 vlan_tag = 0;
  3227. if (is_end)
  3228. flags |= TXD_FLAG_END;
  3229. if (flags & TXD_FLAG_VLAN) {
  3230. vlan_tag = flags >> 16;
  3231. flags &= 0xffff;
  3232. }
  3233. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3234. txd->addr_hi = ((u64) mapping >> 32);
  3235. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3236. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3237. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3238. }
  3239. /* hard_start_xmit for devices that don't have any bugs and
  3240. * support TG3_FLG2_HW_TSO_2 only.
  3241. */
  3242. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3243. {
  3244. struct tg3 *tp = netdev_priv(dev);
  3245. dma_addr_t mapping;
  3246. u32 len, entry, base_flags, mss;
  3247. len = skb_headlen(skb);
  3248. /* We are running in BH disabled context with netif_tx_lock
  3249. * and TX reclaim runs via tp->poll inside of a software
  3250. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3251. * no IRQ context deadlocks to worry about either. Rejoice!
  3252. */
  3253. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3254. if (!netif_queue_stopped(dev)) {
  3255. netif_stop_queue(dev);
  3256. /* This is a hard error, log it. */
  3257. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3258. "queue awake!\n", dev->name);
  3259. }
  3260. return NETDEV_TX_BUSY;
  3261. }
  3262. entry = tp->tx_prod;
  3263. base_flags = 0;
  3264. #if TG3_TSO_SUPPORT != 0
  3265. mss = 0;
  3266. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3267. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3268. int tcp_opt_len, ip_tcp_len;
  3269. if (skb_header_cloned(skb) &&
  3270. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3271. dev_kfree_skb(skb);
  3272. goto out_unlock;
  3273. }
  3274. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3275. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3276. else {
  3277. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3278. ip_tcp_len = (skb->nh.iph->ihl * 4) +
  3279. sizeof(struct tcphdr);
  3280. skb->nh.iph->check = 0;
  3281. skb->nh.iph->tot_len = htons(mss + ip_tcp_len +
  3282. tcp_opt_len);
  3283. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3284. }
  3285. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3286. TXD_FLAG_CPU_POST_DMA);
  3287. skb->h.th->check = 0;
  3288. }
  3289. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3290. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3291. #else
  3292. mss = 0;
  3293. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3294. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3295. #endif
  3296. #if TG3_VLAN_TAG_USED
  3297. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3298. base_flags |= (TXD_FLAG_VLAN |
  3299. (vlan_tx_tag_get(skb) << 16));
  3300. #endif
  3301. /* Queue skb data, a.k.a. the main skb fragment. */
  3302. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3303. tp->tx_buffers[entry].skb = skb;
  3304. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3305. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3306. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3307. entry = NEXT_TX(entry);
  3308. /* Now loop through additional data fragments, and queue them. */
  3309. if (skb_shinfo(skb)->nr_frags > 0) {
  3310. unsigned int i, last;
  3311. last = skb_shinfo(skb)->nr_frags - 1;
  3312. for (i = 0; i <= last; i++) {
  3313. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3314. len = frag->size;
  3315. mapping = pci_map_page(tp->pdev,
  3316. frag->page,
  3317. frag->page_offset,
  3318. len, PCI_DMA_TODEVICE);
  3319. tp->tx_buffers[entry].skb = NULL;
  3320. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3321. tg3_set_txd(tp, entry, mapping, len,
  3322. base_flags, (i == last) | (mss << 1));
  3323. entry = NEXT_TX(entry);
  3324. }
  3325. }
  3326. /* Packets are ready, update Tx producer idx local and on card. */
  3327. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3328. tp->tx_prod = entry;
  3329. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3330. netif_stop_queue(dev);
  3331. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3332. netif_wake_queue(tp->dev);
  3333. }
  3334. out_unlock:
  3335. mmiowb();
  3336. dev->trans_start = jiffies;
  3337. return NETDEV_TX_OK;
  3338. }
  3339. #if TG3_TSO_SUPPORT != 0
  3340. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3341. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3342. * TSO header is greater than 80 bytes.
  3343. */
  3344. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3345. {
  3346. struct sk_buff *segs, *nskb;
  3347. /* Estimate the number of fragments in the worst case */
  3348. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3349. netif_stop_queue(tp->dev);
  3350. return NETDEV_TX_BUSY;
  3351. }
  3352. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3353. if (unlikely(IS_ERR(segs)))
  3354. goto tg3_tso_bug_end;
  3355. do {
  3356. nskb = segs;
  3357. segs = segs->next;
  3358. nskb->next = NULL;
  3359. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3360. } while (segs);
  3361. tg3_tso_bug_end:
  3362. dev_kfree_skb(skb);
  3363. return NETDEV_TX_OK;
  3364. }
  3365. #endif
  3366. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3367. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3368. */
  3369. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3370. {
  3371. struct tg3 *tp = netdev_priv(dev);
  3372. dma_addr_t mapping;
  3373. u32 len, entry, base_flags, mss;
  3374. int would_hit_hwbug;
  3375. len = skb_headlen(skb);
  3376. /* We are running in BH disabled context with netif_tx_lock
  3377. * and TX reclaim runs via tp->poll inside of a software
  3378. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3379. * no IRQ context deadlocks to worry about either. Rejoice!
  3380. */
  3381. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3382. if (!netif_queue_stopped(dev)) {
  3383. netif_stop_queue(dev);
  3384. /* This is a hard error, log it. */
  3385. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3386. "queue awake!\n", dev->name);
  3387. }
  3388. return NETDEV_TX_BUSY;
  3389. }
  3390. entry = tp->tx_prod;
  3391. base_flags = 0;
  3392. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3393. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3394. #if TG3_TSO_SUPPORT != 0
  3395. mss = 0;
  3396. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3397. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3398. int tcp_opt_len, ip_tcp_len, hdr_len;
  3399. if (skb_header_cloned(skb) &&
  3400. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3401. dev_kfree_skb(skb);
  3402. goto out_unlock;
  3403. }
  3404. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3405. ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
  3406. hdr_len = ip_tcp_len + tcp_opt_len;
  3407. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3408. (tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG))
  3409. return (tg3_tso_bug(tp, skb));
  3410. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3411. TXD_FLAG_CPU_POST_DMA);
  3412. skb->nh.iph->check = 0;
  3413. skb->nh.iph->tot_len = htons(mss + hdr_len);
  3414. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3415. skb->h.th->check = 0;
  3416. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3417. }
  3418. else {
  3419. skb->h.th->check =
  3420. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3421. skb->nh.iph->daddr,
  3422. 0, IPPROTO_TCP, 0);
  3423. }
  3424. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3425. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3426. if (tcp_opt_len || skb->nh.iph->ihl > 5) {
  3427. int tsflags;
  3428. tsflags = ((skb->nh.iph->ihl - 5) +
  3429. (tcp_opt_len >> 2));
  3430. mss |= (tsflags << 11);
  3431. }
  3432. } else {
  3433. if (tcp_opt_len || skb->nh.iph->ihl > 5) {
  3434. int tsflags;
  3435. tsflags = ((skb->nh.iph->ihl - 5) +
  3436. (tcp_opt_len >> 2));
  3437. base_flags |= tsflags << 12;
  3438. }
  3439. }
  3440. }
  3441. #else
  3442. mss = 0;
  3443. #endif
  3444. #if TG3_VLAN_TAG_USED
  3445. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3446. base_flags |= (TXD_FLAG_VLAN |
  3447. (vlan_tx_tag_get(skb) << 16));
  3448. #endif
  3449. /* Queue skb data, a.k.a. the main skb fragment. */
  3450. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3451. tp->tx_buffers[entry].skb = skb;
  3452. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3453. would_hit_hwbug = 0;
  3454. if (tg3_4g_overflow_test(mapping, len))
  3455. would_hit_hwbug = 1;
  3456. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3457. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3458. entry = NEXT_TX(entry);
  3459. /* Now loop through additional data fragments, and queue them. */
  3460. if (skb_shinfo(skb)->nr_frags > 0) {
  3461. unsigned int i, last;
  3462. last = skb_shinfo(skb)->nr_frags - 1;
  3463. for (i = 0; i <= last; i++) {
  3464. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3465. len = frag->size;
  3466. mapping = pci_map_page(tp->pdev,
  3467. frag->page,
  3468. frag->page_offset,
  3469. len, PCI_DMA_TODEVICE);
  3470. tp->tx_buffers[entry].skb = NULL;
  3471. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3472. if (tg3_4g_overflow_test(mapping, len))
  3473. would_hit_hwbug = 1;
  3474. if (tg3_40bit_overflow_test(tp, mapping, len))
  3475. would_hit_hwbug = 1;
  3476. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3477. tg3_set_txd(tp, entry, mapping, len,
  3478. base_flags, (i == last)|(mss << 1));
  3479. else
  3480. tg3_set_txd(tp, entry, mapping, len,
  3481. base_flags, (i == last));
  3482. entry = NEXT_TX(entry);
  3483. }
  3484. }
  3485. if (would_hit_hwbug) {
  3486. u32 last_plus_one = entry;
  3487. u32 start;
  3488. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3489. start &= (TG3_TX_RING_SIZE - 1);
  3490. /* If the workaround fails due to memory/mapping
  3491. * failure, silently drop this packet.
  3492. */
  3493. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3494. &start, base_flags, mss))
  3495. goto out_unlock;
  3496. entry = start;
  3497. }
  3498. /* Packets are ready, update Tx producer idx local and on card. */
  3499. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3500. tp->tx_prod = entry;
  3501. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3502. netif_stop_queue(dev);
  3503. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3504. netif_wake_queue(tp->dev);
  3505. }
  3506. out_unlock:
  3507. mmiowb();
  3508. dev->trans_start = jiffies;
  3509. return NETDEV_TX_OK;
  3510. }
  3511. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3512. int new_mtu)
  3513. {
  3514. dev->mtu = new_mtu;
  3515. if (new_mtu > ETH_DATA_LEN) {
  3516. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3517. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3518. ethtool_op_set_tso(dev, 0);
  3519. }
  3520. else
  3521. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3522. } else {
  3523. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3524. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3525. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3526. }
  3527. }
  3528. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3529. {
  3530. struct tg3 *tp = netdev_priv(dev);
  3531. int err;
  3532. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3533. return -EINVAL;
  3534. if (!netif_running(dev)) {
  3535. /* We'll just catch it later when the
  3536. * device is up'd.
  3537. */
  3538. tg3_set_mtu(dev, tp, new_mtu);
  3539. return 0;
  3540. }
  3541. tg3_netif_stop(tp);
  3542. tg3_full_lock(tp, 1);
  3543. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3544. tg3_set_mtu(dev, tp, new_mtu);
  3545. err = tg3_restart_hw(tp, 0);
  3546. if (!err)
  3547. tg3_netif_start(tp);
  3548. tg3_full_unlock(tp);
  3549. return err;
  3550. }
  3551. /* Free up pending packets in all rx/tx rings.
  3552. *
  3553. * The chip has been shut down and the driver detached from
  3554. * the networking, so no interrupts or new tx packets will
  3555. * end up in the driver. tp->{tx,}lock is not held and we are not
  3556. * in an interrupt context and thus may sleep.
  3557. */
  3558. static void tg3_free_rings(struct tg3 *tp)
  3559. {
  3560. struct ring_info *rxp;
  3561. int i;
  3562. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3563. rxp = &tp->rx_std_buffers[i];
  3564. if (rxp->skb == NULL)
  3565. continue;
  3566. pci_unmap_single(tp->pdev,
  3567. pci_unmap_addr(rxp, mapping),
  3568. tp->rx_pkt_buf_sz - tp->rx_offset,
  3569. PCI_DMA_FROMDEVICE);
  3570. dev_kfree_skb_any(rxp->skb);
  3571. rxp->skb = NULL;
  3572. }
  3573. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3574. rxp = &tp->rx_jumbo_buffers[i];
  3575. if (rxp->skb == NULL)
  3576. continue;
  3577. pci_unmap_single(tp->pdev,
  3578. pci_unmap_addr(rxp, mapping),
  3579. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3580. PCI_DMA_FROMDEVICE);
  3581. dev_kfree_skb_any(rxp->skb);
  3582. rxp->skb = NULL;
  3583. }
  3584. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3585. struct tx_ring_info *txp;
  3586. struct sk_buff *skb;
  3587. int j;
  3588. txp = &tp->tx_buffers[i];
  3589. skb = txp->skb;
  3590. if (skb == NULL) {
  3591. i++;
  3592. continue;
  3593. }
  3594. pci_unmap_single(tp->pdev,
  3595. pci_unmap_addr(txp, mapping),
  3596. skb_headlen(skb),
  3597. PCI_DMA_TODEVICE);
  3598. txp->skb = NULL;
  3599. i++;
  3600. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3601. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3602. pci_unmap_page(tp->pdev,
  3603. pci_unmap_addr(txp, mapping),
  3604. skb_shinfo(skb)->frags[j].size,
  3605. PCI_DMA_TODEVICE);
  3606. i++;
  3607. }
  3608. dev_kfree_skb_any(skb);
  3609. }
  3610. }
  3611. /* Initialize tx/rx rings for packet processing.
  3612. *
  3613. * The chip has been shut down and the driver detached from
  3614. * the networking, so no interrupts or new tx packets will
  3615. * end up in the driver. tp->{tx,}lock are held and thus
  3616. * we may not sleep.
  3617. */
  3618. static int tg3_init_rings(struct tg3 *tp)
  3619. {
  3620. u32 i;
  3621. /* Free up all the SKBs. */
  3622. tg3_free_rings(tp);
  3623. /* Zero out all descriptors. */
  3624. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3625. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3626. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3627. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3628. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3629. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3630. (tp->dev->mtu > ETH_DATA_LEN))
  3631. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3632. /* Initialize invariants of the rings, we only set this
  3633. * stuff once. This works because the card does not
  3634. * write into the rx buffer posting rings.
  3635. */
  3636. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3637. struct tg3_rx_buffer_desc *rxd;
  3638. rxd = &tp->rx_std[i];
  3639. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3640. << RXD_LEN_SHIFT;
  3641. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3642. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3643. (i << RXD_OPAQUE_INDEX_SHIFT));
  3644. }
  3645. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3646. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3647. struct tg3_rx_buffer_desc *rxd;
  3648. rxd = &tp->rx_jumbo[i];
  3649. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3650. << RXD_LEN_SHIFT;
  3651. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3652. RXD_FLAG_JUMBO;
  3653. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3654. (i << RXD_OPAQUE_INDEX_SHIFT));
  3655. }
  3656. }
  3657. /* Now allocate fresh SKBs for each rx ring. */
  3658. for (i = 0; i < tp->rx_pending; i++) {
  3659. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3660. printk(KERN_WARNING PFX
  3661. "%s: Using a smaller RX standard ring, "
  3662. "only %d out of %d buffers were allocated "
  3663. "successfully.\n",
  3664. tp->dev->name, i, tp->rx_pending);
  3665. if (i == 0)
  3666. return -ENOMEM;
  3667. tp->rx_pending = i;
  3668. break;
  3669. }
  3670. }
  3671. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3672. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3673. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3674. -1, i) < 0) {
  3675. printk(KERN_WARNING PFX
  3676. "%s: Using a smaller RX jumbo ring, "
  3677. "only %d out of %d buffers were "
  3678. "allocated successfully.\n",
  3679. tp->dev->name, i, tp->rx_jumbo_pending);
  3680. if (i == 0) {
  3681. tg3_free_rings(tp);
  3682. return -ENOMEM;
  3683. }
  3684. tp->rx_jumbo_pending = i;
  3685. break;
  3686. }
  3687. }
  3688. }
  3689. return 0;
  3690. }
  3691. /*
  3692. * Must not be invoked with interrupt sources disabled and
  3693. * the hardware shutdown down.
  3694. */
  3695. static void tg3_free_consistent(struct tg3 *tp)
  3696. {
  3697. kfree(tp->rx_std_buffers);
  3698. tp->rx_std_buffers = NULL;
  3699. if (tp->rx_std) {
  3700. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3701. tp->rx_std, tp->rx_std_mapping);
  3702. tp->rx_std = NULL;
  3703. }
  3704. if (tp->rx_jumbo) {
  3705. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3706. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3707. tp->rx_jumbo = NULL;
  3708. }
  3709. if (tp->rx_rcb) {
  3710. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3711. tp->rx_rcb, tp->rx_rcb_mapping);
  3712. tp->rx_rcb = NULL;
  3713. }
  3714. if (tp->tx_ring) {
  3715. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3716. tp->tx_ring, tp->tx_desc_mapping);
  3717. tp->tx_ring = NULL;
  3718. }
  3719. if (tp->hw_status) {
  3720. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3721. tp->hw_status, tp->status_mapping);
  3722. tp->hw_status = NULL;
  3723. }
  3724. if (tp->hw_stats) {
  3725. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3726. tp->hw_stats, tp->stats_mapping);
  3727. tp->hw_stats = NULL;
  3728. }
  3729. }
  3730. /*
  3731. * Must not be invoked with interrupt sources disabled and
  3732. * the hardware shutdown down. Can sleep.
  3733. */
  3734. static int tg3_alloc_consistent(struct tg3 *tp)
  3735. {
  3736. tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) *
  3737. (TG3_RX_RING_SIZE +
  3738. TG3_RX_JUMBO_RING_SIZE)) +
  3739. (sizeof(struct tx_ring_info) *
  3740. TG3_TX_RING_SIZE),
  3741. GFP_KERNEL);
  3742. if (!tp->rx_std_buffers)
  3743. return -ENOMEM;
  3744. memset(tp->rx_std_buffers, 0,
  3745. (sizeof(struct ring_info) *
  3746. (TG3_RX_RING_SIZE +
  3747. TG3_RX_JUMBO_RING_SIZE)) +
  3748. (sizeof(struct tx_ring_info) *
  3749. TG3_TX_RING_SIZE));
  3750. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3751. tp->tx_buffers = (struct tx_ring_info *)
  3752. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3753. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3754. &tp->rx_std_mapping);
  3755. if (!tp->rx_std)
  3756. goto err_out;
  3757. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3758. &tp->rx_jumbo_mapping);
  3759. if (!tp->rx_jumbo)
  3760. goto err_out;
  3761. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3762. &tp->rx_rcb_mapping);
  3763. if (!tp->rx_rcb)
  3764. goto err_out;
  3765. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3766. &tp->tx_desc_mapping);
  3767. if (!tp->tx_ring)
  3768. goto err_out;
  3769. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3770. TG3_HW_STATUS_SIZE,
  3771. &tp->status_mapping);
  3772. if (!tp->hw_status)
  3773. goto err_out;
  3774. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3775. sizeof(struct tg3_hw_stats),
  3776. &tp->stats_mapping);
  3777. if (!tp->hw_stats)
  3778. goto err_out;
  3779. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3780. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3781. return 0;
  3782. err_out:
  3783. tg3_free_consistent(tp);
  3784. return -ENOMEM;
  3785. }
  3786. #define MAX_WAIT_CNT 1000
  3787. /* To stop a block, clear the enable bit and poll till it
  3788. * clears. tp->lock is held.
  3789. */
  3790. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3791. {
  3792. unsigned int i;
  3793. u32 val;
  3794. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3795. switch (ofs) {
  3796. case RCVLSC_MODE:
  3797. case DMAC_MODE:
  3798. case MBFREE_MODE:
  3799. case BUFMGR_MODE:
  3800. case MEMARB_MODE:
  3801. /* We can't enable/disable these bits of the
  3802. * 5705/5750, just say success.
  3803. */
  3804. return 0;
  3805. default:
  3806. break;
  3807. };
  3808. }
  3809. val = tr32(ofs);
  3810. val &= ~enable_bit;
  3811. tw32_f(ofs, val);
  3812. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3813. udelay(100);
  3814. val = tr32(ofs);
  3815. if ((val & enable_bit) == 0)
  3816. break;
  3817. }
  3818. if (i == MAX_WAIT_CNT && !silent) {
  3819. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3820. "ofs=%lx enable_bit=%x\n",
  3821. ofs, enable_bit);
  3822. return -ENODEV;
  3823. }
  3824. return 0;
  3825. }
  3826. /* tp->lock is held. */
  3827. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3828. {
  3829. int i, err;
  3830. tg3_disable_ints(tp);
  3831. tp->rx_mode &= ~RX_MODE_ENABLE;
  3832. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3833. udelay(10);
  3834. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3835. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3836. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3837. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3838. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3839. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3840. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3841. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3842. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3843. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3844. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3845. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3846. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3847. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3848. tw32_f(MAC_MODE, tp->mac_mode);
  3849. udelay(40);
  3850. tp->tx_mode &= ~TX_MODE_ENABLE;
  3851. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3852. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3853. udelay(100);
  3854. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3855. break;
  3856. }
  3857. if (i >= MAX_WAIT_CNT) {
  3858. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3859. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3860. tp->dev->name, tr32(MAC_TX_MODE));
  3861. err |= -ENODEV;
  3862. }
  3863. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3864. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3865. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3866. tw32(FTQ_RESET, 0xffffffff);
  3867. tw32(FTQ_RESET, 0x00000000);
  3868. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3869. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3870. if (tp->hw_status)
  3871. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3872. if (tp->hw_stats)
  3873. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3874. return err;
  3875. }
  3876. /* tp->lock is held. */
  3877. static int tg3_nvram_lock(struct tg3 *tp)
  3878. {
  3879. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3880. int i;
  3881. if (tp->nvram_lock_cnt == 0) {
  3882. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3883. for (i = 0; i < 8000; i++) {
  3884. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3885. break;
  3886. udelay(20);
  3887. }
  3888. if (i == 8000) {
  3889. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3890. return -ENODEV;
  3891. }
  3892. }
  3893. tp->nvram_lock_cnt++;
  3894. }
  3895. return 0;
  3896. }
  3897. /* tp->lock is held. */
  3898. static void tg3_nvram_unlock(struct tg3 *tp)
  3899. {
  3900. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3901. if (tp->nvram_lock_cnt > 0)
  3902. tp->nvram_lock_cnt--;
  3903. if (tp->nvram_lock_cnt == 0)
  3904. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3905. }
  3906. }
  3907. /* tp->lock is held. */
  3908. static void tg3_enable_nvram_access(struct tg3 *tp)
  3909. {
  3910. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3911. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3912. u32 nvaccess = tr32(NVRAM_ACCESS);
  3913. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3914. }
  3915. }
  3916. /* tp->lock is held. */
  3917. static void tg3_disable_nvram_access(struct tg3 *tp)
  3918. {
  3919. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3920. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3921. u32 nvaccess = tr32(NVRAM_ACCESS);
  3922. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3923. }
  3924. }
  3925. /* tp->lock is held. */
  3926. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3927. {
  3928. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3929. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3930. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3931. switch (kind) {
  3932. case RESET_KIND_INIT:
  3933. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3934. DRV_STATE_START);
  3935. break;
  3936. case RESET_KIND_SHUTDOWN:
  3937. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3938. DRV_STATE_UNLOAD);
  3939. break;
  3940. case RESET_KIND_SUSPEND:
  3941. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3942. DRV_STATE_SUSPEND);
  3943. break;
  3944. default:
  3945. break;
  3946. };
  3947. }
  3948. }
  3949. /* tp->lock is held. */
  3950. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  3951. {
  3952. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3953. switch (kind) {
  3954. case RESET_KIND_INIT:
  3955. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3956. DRV_STATE_START_DONE);
  3957. break;
  3958. case RESET_KIND_SHUTDOWN:
  3959. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3960. DRV_STATE_UNLOAD_DONE);
  3961. break;
  3962. default:
  3963. break;
  3964. };
  3965. }
  3966. }
  3967. /* tp->lock is held. */
  3968. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  3969. {
  3970. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  3971. switch (kind) {
  3972. case RESET_KIND_INIT:
  3973. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3974. DRV_STATE_START);
  3975. break;
  3976. case RESET_KIND_SHUTDOWN:
  3977. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3978. DRV_STATE_UNLOAD);
  3979. break;
  3980. case RESET_KIND_SUSPEND:
  3981. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3982. DRV_STATE_SUSPEND);
  3983. break;
  3984. default:
  3985. break;
  3986. };
  3987. }
  3988. }
  3989. static int tg3_poll_fw(struct tg3 *tp)
  3990. {
  3991. int i;
  3992. u32 val;
  3993. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  3994. /* Wait up to 20ms for init done. */
  3995. for (i = 0; i < 200; i++) {
  3996. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  3997. return 0;
  3998. udelay(100);
  3999. }
  4000. return -ENODEV;
  4001. }
  4002. /* Wait for firmware initialization to complete. */
  4003. for (i = 0; i < 100000; i++) {
  4004. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4005. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4006. break;
  4007. udelay(10);
  4008. }
  4009. /* Chip might not be fitted with firmware. Some Sun onboard
  4010. * parts are configured like that. So don't signal the timeout
  4011. * of the above loop as an error, but do report the lack of
  4012. * running firmware once.
  4013. */
  4014. if (i >= 100000 &&
  4015. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4016. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4017. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4018. tp->dev->name);
  4019. }
  4020. return 0;
  4021. }
  4022. static void tg3_stop_fw(struct tg3 *);
  4023. /* tp->lock is held. */
  4024. static int tg3_chip_reset(struct tg3 *tp)
  4025. {
  4026. u32 val;
  4027. void (*write_op)(struct tg3 *, u32, u32);
  4028. int err;
  4029. tg3_nvram_lock(tp);
  4030. /* No matching tg3_nvram_unlock() after this because
  4031. * chip reset below will undo the nvram lock.
  4032. */
  4033. tp->nvram_lock_cnt = 0;
  4034. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4035. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4036. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  4037. tw32(GRC_FASTBOOT_PC, 0);
  4038. /*
  4039. * We must avoid the readl() that normally takes place.
  4040. * It locks machines, causes machine checks, and other
  4041. * fun things. So, temporarily disable the 5701
  4042. * hardware workaround, while we do the reset.
  4043. */
  4044. write_op = tp->write32;
  4045. if (write_op == tg3_write_flush_reg32)
  4046. tp->write32 = tg3_write32;
  4047. /* do the reset */
  4048. val = GRC_MISC_CFG_CORECLK_RESET;
  4049. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4050. if (tr32(0x7e2c) == 0x60) {
  4051. tw32(0x7e2c, 0x20);
  4052. }
  4053. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4054. tw32(GRC_MISC_CFG, (1 << 29));
  4055. val |= (1 << 29);
  4056. }
  4057. }
  4058. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4059. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4060. tw32(GRC_VCPU_EXT_CTRL,
  4061. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4062. }
  4063. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4064. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4065. tw32(GRC_MISC_CFG, val);
  4066. /* restore 5701 hardware bug workaround write method */
  4067. tp->write32 = write_op;
  4068. /* Unfortunately, we have to delay before the PCI read back.
  4069. * Some 575X chips even will not respond to a PCI cfg access
  4070. * when the reset command is given to the chip.
  4071. *
  4072. * How do these hardware designers expect things to work
  4073. * properly if the PCI write is posted for a long period
  4074. * of time? It is always necessary to have some method by
  4075. * which a register read back can occur to push the write
  4076. * out which does the reset.
  4077. *
  4078. * For most tg3 variants the trick below was working.
  4079. * Ho hum...
  4080. */
  4081. udelay(120);
  4082. /* Flush PCI posted writes. The normal MMIO registers
  4083. * are inaccessible at this time so this is the only
  4084. * way to make this reliably (actually, this is no longer
  4085. * the case, see above). I tried to use indirect
  4086. * register read/write but this upset some 5701 variants.
  4087. */
  4088. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4089. udelay(120);
  4090. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4091. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4092. int i;
  4093. u32 cfg_val;
  4094. /* Wait for link training to complete. */
  4095. for (i = 0; i < 5000; i++)
  4096. udelay(100);
  4097. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4098. pci_write_config_dword(tp->pdev, 0xc4,
  4099. cfg_val | (1 << 15));
  4100. }
  4101. /* Set PCIE max payload size and clear error status. */
  4102. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4103. }
  4104. /* Re-enable indirect register accesses. */
  4105. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4106. tp->misc_host_ctrl);
  4107. /* Set MAX PCI retry to zero. */
  4108. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4109. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4110. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4111. val |= PCISTATE_RETRY_SAME_DMA;
  4112. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4113. pci_restore_state(tp->pdev);
  4114. /* Make sure PCI-X relaxed ordering bit is clear. */
  4115. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4116. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4117. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4118. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4119. u32 val;
  4120. /* Chip reset on 5780 will reset MSI enable bit,
  4121. * so need to restore it.
  4122. */
  4123. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4124. u16 ctrl;
  4125. pci_read_config_word(tp->pdev,
  4126. tp->msi_cap + PCI_MSI_FLAGS,
  4127. &ctrl);
  4128. pci_write_config_word(tp->pdev,
  4129. tp->msi_cap + PCI_MSI_FLAGS,
  4130. ctrl | PCI_MSI_FLAGS_ENABLE);
  4131. val = tr32(MSGINT_MODE);
  4132. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4133. }
  4134. val = tr32(MEMARB_MODE);
  4135. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4136. } else
  4137. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4138. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4139. tg3_stop_fw(tp);
  4140. tw32(0x5000, 0x400);
  4141. }
  4142. tw32(GRC_MODE, tp->grc_mode);
  4143. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4144. u32 val = tr32(0xc4);
  4145. tw32(0xc4, val | (1 << 15));
  4146. }
  4147. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4148. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4149. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4150. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4151. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4152. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4153. }
  4154. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4155. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4156. tw32_f(MAC_MODE, tp->mac_mode);
  4157. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4158. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4159. tw32_f(MAC_MODE, tp->mac_mode);
  4160. } else
  4161. tw32_f(MAC_MODE, 0);
  4162. udelay(40);
  4163. err = tg3_poll_fw(tp);
  4164. if (err)
  4165. return err;
  4166. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4167. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4168. u32 val = tr32(0x7c00);
  4169. tw32(0x7c00, val | (1 << 25));
  4170. }
  4171. /* Reprobe ASF enable state. */
  4172. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4173. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4174. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4175. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4176. u32 nic_cfg;
  4177. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4178. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4179. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4180. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4181. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4182. }
  4183. }
  4184. return 0;
  4185. }
  4186. /* tp->lock is held. */
  4187. static void tg3_stop_fw(struct tg3 *tp)
  4188. {
  4189. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4190. u32 val;
  4191. int i;
  4192. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4193. val = tr32(GRC_RX_CPU_EVENT);
  4194. val |= (1 << 14);
  4195. tw32(GRC_RX_CPU_EVENT, val);
  4196. /* Wait for RX cpu to ACK the event. */
  4197. for (i = 0; i < 100; i++) {
  4198. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4199. break;
  4200. udelay(1);
  4201. }
  4202. }
  4203. }
  4204. /* tp->lock is held. */
  4205. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4206. {
  4207. int err;
  4208. tg3_stop_fw(tp);
  4209. tg3_write_sig_pre_reset(tp, kind);
  4210. tg3_abort_hw(tp, silent);
  4211. err = tg3_chip_reset(tp);
  4212. tg3_write_sig_legacy(tp, kind);
  4213. tg3_write_sig_post_reset(tp, kind);
  4214. if (err)
  4215. return err;
  4216. return 0;
  4217. }
  4218. #define TG3_FW_RELEASE_MAJOR 0x0
  4219. #define TG3_FW_RELASE_MINOR 0x0
  4220. #define TG3_FW_RELEASE_FIX 0x0
  4221. #define TG3_FW_START_ADDR 0x08000000
  4222. #define TG3_FW_TEXT_ADDR 0x08000000
  4223. #define TG3_FW_TEXT_LEN 0x9c0
  4224. #define TG3_FW_RODATA_ADDR 0x080009c0
  4225. #define TG3_FW_RODATA_LEN 0x60
  4226. #define TG3_FW_DATA_ADDR 0x08000a40
  4227. #define TG3_FW_DATA_LEN 0x20
  4228. #define TG3_FW_SBSS_ADDR 0x08000a60
  4229. #define TG3_FW_SBSS_LEN 0xc
  4230. #define TG3_FW_BSS_ADDR 0x08000a70
  4231. #define TG3_FW_BSS_LEN 0x10
  4232. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4233. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4234. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4235. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4236. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4237. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4238. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4239. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4240. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4241. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4242. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4243. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4244. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4245. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4246. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4247. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4248. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4249. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4250. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4251. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4252. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4253. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4254. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4255. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4258. 0, 0, 0, 0, 0, 0,
  4259. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4260. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4261. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4262. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4263. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4264. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4265. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4266. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4267. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4268. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4269. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4273. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4274. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4275. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4276. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4277. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4278. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4279. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4280. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4281. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4282. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4283. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4284. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4285. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4286. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4287. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4288. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4289. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4290. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4291. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4292. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4293. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4294. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4295. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4296. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4297. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4298. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4299. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4300. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4301. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4302. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4303. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4304. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4305. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4306. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4307. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4308. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4309. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4310. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4311. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4312. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4313. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4314. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4315. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4316. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4317. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4318. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4319. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4320. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4321. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4322. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4323. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4324. };
  4325. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4326. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4327. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4328. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4329. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4330. 0x00000000
  4331. };
  4332. #if 0 /* All zeros, don't eat up space with it. */
  4333. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4334. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4335. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4336. };
  4337. #endif
  4338. #define RX_CPU_SCRATCH_BASE 0x30000
  4339. #define RX_CPU_SCRATCH_SIZE 0x04000
  4340. #define TX_CPU_SCRATCH_BASE 0x34000
  4341. #define TX_CPU_SCRATCH_SIZE 0x04000
  4342. /* tp->lock is held. */
  4343. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4344. {
  4345. int i;
  4346. BUG_ON(offset == TX_CPU_BASE &&
  4347. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4348. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4349. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4350. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4351. return 0;
  4352. }
  4353. if (offset == RX_CPU_BASE) {
  4354. for (i = 0; i < 10000; i++) {
  4355. tw32(offset + CPU_STATE, 0xffffffff);
  4356. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4357. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4358. break;
  4359. }
  4360. tw32(offset + CPU_STATE, 0xffffffff);
  4361. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4362. udelay(10);
  4363. } else {
  4364. for (i = 0; i < 10000; i++) {
  4365. tw32(offset + CPU_STATE, 0xffffffff);
  4366. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4367. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4368. break;
  4369. }
  4370. }
  4371. if (i >= 10000) {
  4372. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4373. "and %s CPU\n",
  4374. tp->dev->name,
  4375. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4376. return -ENODEV;
  4377. }
  4378. /* Clear firmware's nvram arbitration. */
  4379. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4380. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4381. return 0;
  4382. }
  4383. struct fw_info {
  4384. unsigned int text_base;
  4385. unsigned int text_len;
  4386. const u32 *text_data;
  4387. unsigned int rodata_base;
  4388. unsigned int rodata_len;
  4389. const u32 *rodata_data;
  4390. unsigned int data_base;
  4391. unsigned int data_len;
  4392. const u32 *data_data;
  4393. };
  4394. /* tp->lock is held. */
  4395. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4396. int cpu_scratch_size, struct fw_info *info)
  4397. {
  4398. int err, lock_err, i;
  4399. void (*write_op)(struct tg3 *, u32, u32);
  4400. if (cpu_base == TX_CPU_BASE &&
  4401. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4402. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4403. "TX cpu firmware on %s which is 5705.\n",
  4404. tp->dev->name);
  4405. return -EINVAL;
  4406. }
  4407. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4408. write_op = tg3_write_mem;
  4409. else
  4410. write_op = tg3_write_indirect_reg32;
  4411. /* It is possible that bootcode is still loading at this point.
  4412. * Get the nvram lock first before halting the cpu.
  4413. */
  4414. lock_err = tg3_nvram_lock(tp);
  4415. err = tg3_halt_cpu(tp, cpu_base);
  4416. if (!lock_err)
  4417. tg3_nvram_unlock(tp);
  4418. if (err)
  4419. goto out;
  4420. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4421. write_op(tp, cpu_scratch_base + i, 0);
  4422. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4423. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4424. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4425. write_op(tp, (cpu_scratch_base +
  4426. (info->text_base & 0xffff) +
  4427. (i * sizeof(u32))),
  4428. (info->text_data ?
  4429. info->text_data[i] : 0));
  4430. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4431. write_op(tp, (cpu_scratch_base +
  4432. (info->rodata_base & 0xffff) +
  4433. (i * sizeof(u32))),
  4434. (info->rodata_data ?
  4435. info->rodata_data[i] : 0));
  4436. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4437. write_op(tp, (cpu_scratch_base +
  4438. (info->data_base & 0xffff) +
  4439. (i * sizeof(u32))),
  4440. (info->data_data ?
  4441. info->data_data[i] : 0));
  4442. err = 0;
  4443. out:
  4444. return err;
  4445. }
  4446. /* tp->lock is held. */
  4447. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4448. {
  4449. struct fw_info info;
  4450. int err, i;
  4451. info.text_base = TG3_FW_TEXT_ADDR;
  4452. info.text_len = TG3_FW_TEXT_LEN;
  4453. info.text_data = &tg3FwText[0];
  4454. info.rodata_base = TG3_FW_RODATA_ADDR;
  4455. info.rodata_len = TG3_FW_RODATA_LEN;
  4456. info.rodata_data = &tg3FwRodata[0];
  4457. info.data_base = TG3_FW_DATA_ADDR;
  4458. info.data_len = TG3_FW_DATA_LEN;
  4459. info.data_data = NULL;
  4460. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4461. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4462. &info);
  4463. if (err)
  4464. return err;
  4465. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4466. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4467. &info);
  4468. if (err)
  4469. return err;
  4470. /* Now startup only the RX cpu. */
  4471. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4472. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4473. for (i = 0; i < 5; i++) {
  4474. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4475. break;
  4476. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4477. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4478. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4479. udelay(1000);
  4480. }
  4481. if (i >= 5) {
  4482. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4483. "to set RX CPU PC, is %08x should be %08x\n",
  4484. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4485. TG3_FW_TEXT_ADDR);
  4486. return -ENODEV;
  4487. }
  4488. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4489. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4490. return 0;
  4491. }
  4492. #if TG3_TSO_SUPPORT != 0
  4493. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4494. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4495. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4496. #define TG3_TSO_FW_START_ADDR 0x08000000
  4497. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4498. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4499. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4500. #define TG3_TSO_FW_RODATA_LEN 0x60
  4501. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4502. #define TG3_TSO_FW_DATA_LEN 0x30
  4503. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4504. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4505. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4506. #define TG3_TSO_FW_BSS_LEN 0x894
  4507. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4508. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4509. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4510. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4511. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4512. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4513. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4514. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4515. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4516. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4517. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4518. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4519. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4520. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4521. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4522. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4523. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4524. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4525. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4526. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4527. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4528. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4529. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4530. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4531. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4532. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4533. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4534. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4535. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4536. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4537. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4538. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4539. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4540. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4541. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4542. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4543. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4544. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4545. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4546. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4547. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4548. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4549. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4550. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4551. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4552. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4553. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4554. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4555. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4556. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4557. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4558. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4559. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4560. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4561. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4562. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4563. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4564. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4565. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4566. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4567. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4568. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4569. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4570. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4571. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4572. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4573. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4574. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4575. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4576. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4577. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4578. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4579. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4580. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4581. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4582. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4583. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4584. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4585. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4586. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4587. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4588. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4589. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4590. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4591. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4592. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4593. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4594. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4595. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4596. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4597. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4598. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4599. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4600. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4601. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4602. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4603. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4604. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4605. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4606. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4607. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4608. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4609. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4610. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4611. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4612. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4613. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4614. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4615. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4616. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4617. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4618. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4619. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4620. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4621. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4622. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4623. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4624. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4625. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4626. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4627. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4628. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4629. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4630. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4631. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4632. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4633. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4634. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4635. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4636. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4637. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4638. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4639. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4640. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4641. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4642. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4643. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4644. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4645. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4646. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4647. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4648. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4649. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4650. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4651. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4652. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4653. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4654. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4655. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4656. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4657. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4658. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4659. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4660. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4661. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4662. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4663. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4664. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4665. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4666. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4667. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4668. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4669. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4670. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4671. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4672. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4673. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4674. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4675. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4676. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4677. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4678. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4679. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4680. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4681. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4682. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4683. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4684. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4685. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4686. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4687. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4688. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4689. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4690. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4691. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4692. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4693. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4694. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4695. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4696. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4697. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4698. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4699. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4700. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4701. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4702. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4703. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4704. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4705. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4706. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4707. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4708. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4709. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4710. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4711. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4712. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4713. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4714. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4715. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4716. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4717. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4718. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4719. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4720. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4721. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4722. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4723. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4724. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4725. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4726. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4727. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4728. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4729. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4730. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4731. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4732. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4733. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4734. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4735. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4736. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4737. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4738. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4739. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4740. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4741. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4742. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4743. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4744. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4745. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4746. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4747. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4748. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4749. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4750. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4751. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4752. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4753. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4754. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4755. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4756. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4757. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4758. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4759. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4760. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4761. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4762. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4763. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4764. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4765. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4766. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4767. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4768. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4769. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4770. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4771. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4772. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4773. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4774. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4775. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4776. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4777. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4778. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4779. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4780. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4781. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4782. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4783. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4784. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4785. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4786. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4787. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4788. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4789. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4790. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4791. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4792. };
  4793. static const u32 tg3TsoFwRodata[] = {
  4794. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4795. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4796. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4797. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4798. 0x00000000,
  4799. };
  4800. static const u32 tg3TsoFwData[] = {
  4801. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4802. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4803. 0x00000000,
  4804. };
  4805. /* 5705 needs a special version of the TSO firmware. */
  4806. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4807. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4808. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4809. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4810. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4811. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4812. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4813. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4814. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4815. #define TG3_TSO5_FW_DATA_LEN 0x20
  4816. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4817. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4818. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4819. #define TG3_TSO5_FW_BSS_LEN 0x88
  4820. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4821. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4822. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4823. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4824. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4825. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4826. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4827. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4828. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4829. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4830. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4831. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4832. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4833. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4834. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4835. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4836. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4837. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4838. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4839. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4840. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4841. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4842. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4843. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4844. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4845. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4846. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4847. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4848. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4849. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4850. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4851. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4852. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4853. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4854. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4855. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4856. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4857. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4858. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4859. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4860. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4861. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4862. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4863. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4864. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4865. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4866. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4867. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4868. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4869. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4870. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4871. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4872. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4873. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4874. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4875. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4876. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4877. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4878. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4879. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4880. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4881. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4882. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4883. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4884. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4885. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4886. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4887. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4888. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4889. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4890. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4891. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4892. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4893. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4894. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4895. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4896. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4897. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4898. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4899. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4900. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4901. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4902. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4903. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4904. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4905. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4906. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4907. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4908. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4909. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4910. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4911. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4912. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4913. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4914. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4915. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4916. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4917. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4918. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4919. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  4920. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  4921. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  4922. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  4923. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  4924. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  4925. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  4926. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  4927. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4928. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4929. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  4930. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  4931. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  4932. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  4933. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  4934. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  4935. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  4936. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  4937. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  4938. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4939. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4940. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  4941. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  4942. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  4943. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  4944. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4945. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  4946. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  4947. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  4948. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  4949. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  4950. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  4951. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  4952. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  4953. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  4954. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  4955. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  4956. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  4957. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  4958. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  4959. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  4960. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  4961. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  4962. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  4963. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  4964. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  4965. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  4966. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  4967. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  4968. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4969. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  4970. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  4971. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  4972. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4973. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  4974. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  4975. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4976. 0x00000000, 0x00000000, 0x00000000,
  4977. };
  4978. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  4979. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4980. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  4981. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4982. 0x00000000, 0x00000000, 0x00000000,
  4983. };
  4984. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  4985. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  4986. 0x00000000, 0x00000000, 0x00000000,
  4987. };
  4988. /* tp->lock is held. */
  4989. static int tg3_load_tso_firmware(struct tg3 *tp)
  4990. {
  4991. struct fw_info info;
  4992. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  4993. int err, i;
  4994. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  4995. return 0;
  4996. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4997. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  4998. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  4999. info.text_data = &tg3Tso5FwText[0];
  5000. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5001. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5002. info.rodata_data = &tg3Tso5FwRodata[0];
  5003. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5004. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5005. info.data_data = &tg3Tso5FwData[0];
  5006. cpu_base = RX_CPU_BASE;
  5007. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5008. cpu_scratch_size = (info.text_len +
  5009. info.rodata_len +
  5010. info.data_len +
  5011. TG3_TSO5_FW_SBSS_LEN +
  5012. TG3_TSO5_FW_BSS_LEN);
  5013. } else {
  5014. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5015. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5016. info.text_data = &tg3TsoFwText[0];
  5017. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5018. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5019. info.rodata_data = &tg3TsoFwRodata[0];
  5020. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5021. info.data_len = TG3_TSO_FW_DATA_LEN;
  5022. info.data_data = &tg3TsoFwData[0];
  5023. cpu_base = TX_CPU_BASE;
  5024. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5025. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5026. }
  5027. err = tg3_load_firmware_cpu(tp, cpu_base,
  5028. cpu_scratch_base, cpu_scratch_size,
  5029. &info);
  5030. if (err)
  5031. return err;
  5032. /* Now startup the cpu. */
  5033. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5034. tw32_f(cpu_base + CPU_PC, info.text_base);
  5035. for (i = 0; i < 5; i++) {
  5036. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5037. break;
  5038. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5039. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5040. tw32_f(cpu_base + CPU_PC, info.text_base);
  5041. udelay(1000);
  5042. }
  5043. if (i >= 5) {
  5044. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5045. "to set CPU PC, is %08x should be %08x\n",
  5046. tp->dev->name, tr32(cpu_base + CPU_PC),
  5047. info.text_base);
  5048. return -ENODEV;
  5049. }
  5050. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5051. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5052. return 0;
  5053. }
  5054. #endif /* TG3_TSO_SUPPORT != 0 */
  5055. /* tp->lock is held. */
  5056. static void __tg3_set_mac_addr(struct tg3 *tp)
  5057. {
  5058. u32 addr_high, addr_low;
  5059. int i;
  5060. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5061. tp->dev->dev_addr[1]);
  5062. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5063. (tp->dev->dev_addr[3] << 16) |
  5064. (tp->dev->dev_addr[4] << 8) |
  5065. (tp->dev->dev_addr[5] << 0));
  5066. for (i = 0; i < 4; i++) {
  5067. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5068. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5069. }
  5070. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5071. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5072. for (i = 0; i < 12; i++) {
  5073. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5074. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5075. }
  5076. }
  5077. addr_high = (tp->dev->dev_addr[0] +
  5078. tp->dev->dev_addr[1] +
  5079. tp->dev->dev_addr[2] +
  5080. tp->dev->dev_addr[3] +
  5081. tp->dev->dev_addr[4] +
  5082. tp->dev->dev_addr[5]) &
  5083. TX_BACKOFF_SEED_MASK;
  5084. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5085. }
  5086. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5087. {
  5088. struct tg3 *tp = netdev_priv(dev);
  5089. struct sockaddr *addr = p;
  5090. int err = 0;
  5091. if (!is_valid_ether_addr(addr->sa_data))
  5092. return -EINVAL;
  5093. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5094. if (!netif_running(dev))
  5095. return 0;
  5096. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5097. /* Reset chip so that ASF can re-init any MAC addresses it
  5098. * needs.
  5099. */
  5100. tg3_netif_stop(tp);
  5101. tg3_full_lock(tp, 1);
  5102. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5103. err = tg3_restart_hw(tp, 0);
  5104. if (!err)
  5105. tg3_netif_start(tp);
  5106. tg3_full_unlock(tp);
  5107. } else {
  5108. spin_lock_bh(&tp->lock);
  5109. __tg3_set_mac_addr(tp);
  5110. spin_unlock_bh(&tp->lock);
  5111. }
  5112. return err;
  5113. }
  5114. /* tp->lock is held. */
  5115. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5116. dma_addr_t mapping, u32 maxlen_flags,
  5117. u32 nic_addr)
  5118. {
  5119. tg3_write_mem(tp,
  5120. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5121. ((u64) mapping >> 32));
  5122. tg3_write_mem(tp,
  5123. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5124. ((u64) mapping & 0xffffffff));
  5125. tg3_write_mem(tp,
  5126. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5127. maxlen_flags);
  5128. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5129. tg3_write_mem(tp,
  5130. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5131. nic_addr);
  5132. }
  5133. static void __tg3_set_rx_mode(struct net_device *);
  5134. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5135. {
  5136. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5137. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5138. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5139. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5140. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5141. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5142. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5143. }
  5144. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5145. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5146. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5147. u32 val = ec->stats_block_coalesce_usecs;
  5148. if (!netif_carrier_ok(tp->dev))
  5149. val = 0;
  5150. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5151. }
  5152. }
  5153. /* tp->lock is held. */
  5154. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5155. {
  5156. u32 val, rdmac_mode;
  5157. int i, err, limit;
  5158. tg3_disable_ints(tp);
  5159. tg3_stop_fw(tp);
  5160. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5161. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5162. tg3_abort_hw(tp, 1);
  5163. }
  5164. if (reset_phy)
  5165. tg3_phy_reset(tp);
  5166. err = tg3_chip_reset(tp);
  5167. if (err)
  5168. return err;
  5169. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5170. /* This works around an issue with Athlon chipsets on
  5171. * B3 tigon3 silicon. This bit has no effect on any
  5172. * other revision. But do not set this on PCI Express
  5173. * chips.
  5174. */
  5175. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5176. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5177. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5178. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5179. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5180. val = tr32(TG3PCI_PCISTATE);
  5181. val |= PCISTATE_RETRY_SAME_DMA;
  5182. tw32(TG3PCI_PCISTATE, val);
  5183. }
  5184. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5185. /* Enable some hw fixes. */
  5186. val = tr32(TG3PCI_MSI_DATA);
  5187. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5188. tw32(TG3PCI_MSI_DATA, val);
  5189. }
  5190. /* Descriptor ring init may make accesses to the
  5191. * NIC SRAM area to setup the TX descriptors, so we
  5192. * can only do this after the hardware has been
  5193. * successfully reset.
  5194. */
  5195. err = tg3_init_rings(tp);
  5196. if (err)
  5197. return err;
  5198. /* This value is determined during the probe time DMA
  5199. * engine test, tg3_test_dma.
  5200. */
  5201. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5202. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5203. GRC_MODE_4X_NIC_SEND_RINGS |
  5204. GRC_MODE_NO_TX_PHDR_CSUM |
  5205. GRC_MODE_NO_RX_PHDR_CSUM);
  5206. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5207. /* Pseudo-header checksum is done by hardware logic and not
  5208. * the offload processers, so make the chip do the pseudo-
  5209. * header checksums on receive. For transmit it is more
  5210. * convenient to do the pseudo-header checksum in software
  5211. * as Linux does that on transmit for us in all cases.
  5212. */
  5213. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5214. tw32(GRC_MODE,
  5215. tp->grc_mode |
  5216. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5217. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5218. val = tr32(GRC_MISC_CFG);
  5219. val &= ~0xff;
  5220. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5221. tw32(GRC_MISC_CFG, val);
  5222. /* Initialize MBUF/DESC pool. */
  5223. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5224. /* Do nothing. */
  5225. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5226. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5227. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5228. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5229. else
  5230. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5231. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5232. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5233. }
  5234. #if TG3_TSO_SUPPORT != 0
  5235. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5236. int fw_len;
  5237. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5238. TG3_TSO5_FW_RODATA_LEN +
  5239. TG3_TSO5_FW_DATA_LEN +
  5240. TG3_TSO5_FW_SBSS_LEN +
  5241. TG3_TSO5_FW_BSS_LEN);
  5242. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5243. tw32(BUFMGR_MB_POOL_ADDR,
  5244. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5245. tw32(BUFMGR_MB_POOL_SIZE,
  5246. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5247. }
  5248. #endif
  5249. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5250. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5251. tp->bufmgr_config.mbuf_read_dma_low_water);
  5252. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5253. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5254. tw32(BUFMGR_MB_HIGH_WATER,
  5255. tp->bufmgr_config.mbuf_high_water);
  5256. } else {
  5257. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5258. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5259. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5260. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5261. tw32(BUFMGR_MB_HIGH_WATER,
  5262. tp->bufmgr_config.mbuf_high_water_jumbo);
  5263. }
  5264. tw32(BUFMGR_DMA_LOW_WATER,
  5265. tp->bufmgr_config.dma_low_water);
  5266. tw32(BUFMGR_DMA_HIGH_WATER,
  5267. tp->bufmgr_config.dma_high_water);
  5268. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5269. for (i = 0; i < 2000; i++) {
  5270. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5271. break;
  5272. udelay(10);
  5273. }
  5274. if (i >= 2000) {
  5275. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5276. tp->dev->name);
  5277. return -ENODEV;
  5278. }
  5279. /* Setup replenish threshold. */
  5280. val = tp->rx_pending / 8;
  5281. if (val == 0)
  5282. val = 1;
  5283. else if (val > tp->rx_std_max_post)
  5284. val = tp->rx_std_max_post;
  5285. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5286. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5287. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5288. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5289. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5290. }
  5291. tw32(RCVBDI_STD_THRESH, val);
  5292. /* Initialize TG3_BDINFO's at:
  5293. * RCVDBDI_STD_BD: standard eth size rx ring
  5294. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5295. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5296. *
  5297. * like so:
  5298. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5299. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5300. * ring attribute flags
  5301. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5302. *
  5303. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5304. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5305. *
  5306. * The size of each ring is fixed in the firmware, but the location is
  5307. * configurable.
  5308. */
  5309. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5310. ((u64) tp->rx_std_mapping >> 32));
  5311. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5312. ((u64) tp->rx_std_mapping & 0xffffffff));
  5313. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5314. NIC_SRAM_RX_BUFFER_DESC);
  5315. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5316. * configs on 5705.
  5317. */
  5318. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5319. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5320. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5321. } else {
  5322. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5323. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5324. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5325. BDINFO_FLAGS_DISABLED);
  5326. /* Setup replenish threshold. */
  5327. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5328. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5329. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5330. ((u64) tp->rx_jumbo_mapping >> 32));
  5331. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5332. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5333. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5334. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5335. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5336. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5337. } else {
  5338. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5339. BDINFO_FLAGS_DISABLED);
  5340. }
  5341. }
  5342. /* There is only one send ring on 5705/5750, no need to explicitly
  5343. * disable the others.
  5344. */
  5345. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5346. /* Clear out send RCB ring in SRAM. */
  5347. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5348. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5349. BDINFO_FLAGS_DISABLED);
  5350. }
  5351. tp->tx_prod = 0;
  5352. tp->tx_cons = 0;
  5353. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5354. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5355. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5356. tp->tx_desc_mapping,
  5357. (TG3_TX_RING_SIZE <<
  5358. BDINFO_FLAGS_MAXLEN_SHIFT),
  5359. NIC_SRAM_TX_BUFFER_DESC);
  5360. /* There is only one receive return ring on 5705/5750, no need
  5361. * to explicitly disable the others.
  5362. */
  5363. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5364. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5365. i += TG3_BDINFO_SIZE) {
  5366. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5367. BDINFO_FLAGS_DISABLED);
  5368. }
  5369. }
  5370. tp->rx_rcb_ptr = 0;
  5371. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5372. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5373. tp->rx_rcb_mapping,
  5374. (TG3_RX_RCB_RING_SIZE(tp) <<
  5375. BDINFO_FLAGS_MAXLEN_SHIFT),
  5376. 0);
  5377. tp->rx_std_ptr = tp->rx_pending;
  5378. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5379. tp->rx_std_ptr);
  5380. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5381. tp->rx_jumbo_pending : 0;
  5382. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5383. tp->rx_jumbo_ptr);
  5384. /* Initialize MAC address and backoff seed. */
  5385. __tg3_set_mac_addr(tp);
  5386. /* MTU + ethernet header + FCS + optional VLAN tag */
  5387. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5388. /* The slot time is changed by tg3_setup_phy if we
  5389. * run at gigabit with half duplex.
  5390. */
  5391. tw32(MAC_TX_LENGTHS,
  5392. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5393. (6 << TX_LENGTHS_IPG_SHIFT) |
  5394. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5395. /* Receive rules. */
  5396. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5397. tw32(RCVLPC_CONFIG, 0x0181);
  5398. /* Calculate RDMAC_MODE setting early, we need it to determine
  5399. * the RCVLPC_STATE_ENABLE mask.
  5400. */
  5401. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5402. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5403. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5404. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5405. RDMAC_MODE_LNGREAD_ENAB);
  5406. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  5407. rdmac_mode |= RDMAC_MODE_SPLIT_ENABLE;
  5408. /* If statement applies to 5705 and 5750 PCI devices only */
  5409. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5410. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5411. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5412. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5413. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5414. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5415. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5416. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5417. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5418. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5419. }
  5420. }
  5421. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5422. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5423. #if TG3_TSO_SUPPORT != 0
  5424. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5425. rdmac_mode |= (1 << 27);
  5426. #endif
  5427. /* Receive/send statistics. */
  5428. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5429. val = tr32(RCVLPC_STATS_ENABLE);
  5430. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5431. tw32(RCVLPC_STATS_ENABLE, val);
  5432. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5433. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5434. val = tr32(RCVLPC_STATS_ENABLE);
  5435. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5436. tw32(RCVLPC_STATS_ENABLE, val);
  5437. } else {
  5438. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5439. }
  5440. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5441. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5442. tw32(SNDDATAI_STATSCTRL,
  5443. (SNDDATAI_SCTRL_ENABLE |
  5444. SNDDATAI_SCTRL_FASTUPD));
  5445. /* Setup host coalescing engine. */
  5446. tw32(HOSTCC_MODE, 0);
  5447. for (i = 0; i < 2000; i++) {
  5448. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5449. break;
  5450. udelay(10);
  5451. }
  5452. __tg3_set_coalesce(tp, &tp->coal);
  5453. /* set status block DMA address */
  5454. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5455. ((u64) tp->status_mapping >> 32));
  5456. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5457. ((u64) tp->status_mapping & 0xffffffff));
  5458. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5459. /* Status/statistics block address. See tg3_timer,
  5460. * the tg3_periodic_fetch_stats call there, and
  5461. * tg3_get_stats to see how this works for 5705/5750 chips.
  5462. */
  5463. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5464. ((u64) tp->stats_mapping >> 32));
  5465. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5466. ((u64) tp->stats_mapping & 0xffffffff));
  5467. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5468. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5469. }
  5470. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5471. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5472. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5473. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5474. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5475. /* Clear statistics/status block in chip, and status block in ram. */
  5476. for (i = NIC_SRAM_STATS_BLK;
  5477. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5478. i += sizeof(u32)) {
  5479. tg3_write_mem(tp, i, 0);
  5480. udelay(40);
  5481. }
  5482. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5483. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5484. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5485. /* reset to prevent losing 1st rx packet intermittently */
  5486. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5487. udelay(10);
  5488. }
  5489. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5490. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5491. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5492. udelay(40);
  5493. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5494. * If TG3_FLG2_IS_NIC is zero, we should read the
  5495. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5496. * whether used as inputs or outputs, are set by boot code after
  5497. * reset.
  5498. */
  5499. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5500. u32 gpio_mask;
  5501. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5502. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5503. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5504. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5505. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5506. GRC_LCLCTRL_GPIO_OUTPUT3;
  5507. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5508. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5509. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5510. /* GPIO1 must be driven high for eeprom write protect */
  5511. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5512. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5513. GRC_LCLCTRL_GPIO_OUTPUT1);
  5514. }
  5515. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5516. udelay(100);
  5517. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5518. tp->last_tag = 0;
  5519. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5520. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5521. udelay(40);
  5522. }
  5523. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5524. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5525. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5526. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5527. WDMAC_MODE_LNGREAD_ENAB);
  5528. /* If statement applies to 5705 and 5750 PCI devices only */
  5529. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5530. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5531. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5532. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5533. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5534. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5535. /* nothing */
  5536. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5537. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5538. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5539. val |= WDMAC_MODE_RX_ACCEL;
  5540. }
  5541. }
  5542. /* Enable host coalescing bug fix */
  5543. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5544. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5545. val |= (1 << 29);
  5546. tw32_f(WDMAC_MODE, val);
  5547. udelay(40);
  5548. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5549. val = tr32(TG3PCI_X_CAPS);
  5550. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5551. val &= ~PCIX_CAPS_BURST_MASK;
  5552. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5553. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5554. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5555. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5556. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  5557. val |= (tp->split_mode_max_reqs <<
  5558. PCIX_CAPS_SPLIT_SHIFT);
  5559. }
  5560. tw32(TG3PCI_X_CAPS, val);
  5561. }
  5562. tw32_f(RDMAC_MODE, rdmac_mode);
  5563. udelay(40);
  5564. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5565. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5566. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5567. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5568. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5569. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5570. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5571. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5572. #if TG3_TSO_SUPPORT != 0
  5573. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5574. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5575. #endif
  5576. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5577. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5578. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5579. err = tg3_load_5701_a0_firmware_fix(tp);
  5580. if (err)
  5581. return err;
  5582. }
  5583. #if TG3_TSO_SUPPORT != 0
  5584. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5585. err = tg3_load_tso_firmware(tp);
  5586. if (err)
  5587. return err;
  5588. }
  5589. #endif
  5590. tp->tx_mode = TX_MODE_ENABLE;
  5591. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5592. udelay(100);
  5593. tp->rx_mode = RX_MODE_ENABLE;
  5594. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5595. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5596. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5597. udelay(10);
  5598. if (tp->link_config.phy_is_low_power) {
  5599. tp->link_config.phy_is_low_power = 0;
  5600. tp->link_config.speed = tp->link_config.orig_speed;
  5601. tp->link_config.duplex = tp->link_config.orig_duplex;
  5602. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5603. }
  5604. tp->mi_mode = MAC_MI_MODE_BASE;
  5605. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5606. udelay(80);
  5607. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5608. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5609. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5610. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5611. udelay(10);
  5612. }
  5613. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5614. udelay(10);
  5615. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5616. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5617. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5618. /* Set drive transmission level to 1.2V */
  5619. /* only if the signal pre-emphasis bit is not set */
  5620. val = tr32(MAC_SERDES_CFG);
  5621. val &= 0xfffff000;
  5622. val |= 0x880;
  5623. tw32(MAC_SERDES_CFG, val);
  5624. }
  5625. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5626. tw32(MAC_SERDES_CFG, 0x616000);
  5627. }
  5628. /* Prevent chip from dropping frames when flow control
  5629. * is enabled.
  5630. */
  5631. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5632. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5633. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5634. /* Use hardware link auto-negotiation */
  5635. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5636. }
  5637. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5638. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5639. u32 tmp;
  5640. tmp = tr32(SERDES_RX_CTRL);
  5641. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5642. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5643. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5644. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5645. }
  5646. err = tg3_setup_phy(tp, 0);
  5647. if (err)
  5648. return err;
  5649. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5650. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  5651. u32 tmp;
  5652. /* Clear CRC stats. */
  5653. if (!tg3_readphy(tp, 0x1e, &tmp)) {
  5654. tg3_writephy(tp, 0x1e, tmp | 0x8000);
  5655. tg3_readphy(tp, 0x14, &tmp);
  5656. }
  5657. }
  5658. __tg3_set_rx_mode(tp->dev);
  5659. /* Initialize receive rules. */
  5660. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5661. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5662. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5663. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5664. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5665. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5666. limit = 8;
  5667. else
  5668. limit = 16;
  5669. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5670. limit -= 4;
  5671. switch (limit) {
  5672. case 16:
  5673. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5674. case 15:
  5675. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5676. case 14:
  5677. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5678. case 13:
  5679. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5680. case 12:
  5681. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5682. case 11:
  5683. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5684. case 10:
  5685. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5686. case 9:
  5687. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5688. case 8:
  5689. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5690. case 7:
  5691. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5692. case 6:
  5693. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5694. case 5:
  5695. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5696. case 4:
  5697. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5698. case 3:
  5699. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5700. case 2:
  5701. case 1:
  5702. default:
  5703. break;
  5704. };
  5705. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5706. return 0;
  5707. }
  5708. /* Called at device open time to get the chip ready for
  5709. * packet processing. Invoked with tp->lock held.
  5710. */
  5711. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5712. {
  5713. int err;
  5714. /* Force the chip into D0. */
  5715. err = tg3_set_power_state(tp, PCI_D0);
  5716. if (err)
  5717. goto out;
  5718. tg3_switch_clocks(tp);
  5719. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5720. err = tg3_reset_hw(tp, reset_phy);
  5721. out:
  5722. return err;
  5723. }
  5724. #define TG3_STAT_ADD32(PSTAT, REG) \
  5725. do { u32 __val = tr32(REG); \
  5726. (PSTAT)->low += __val; \
  5727. if ((PSTAT)->low < __val) \
  5728. (PSTAT)->high += 1; \
  5729. } while (0)
  5730. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5731. {
  5732. struct tg3_hw_stats *sp = tp->hw_stats;
  5733. if (!netif_carrier_ok(tp->dev))
  5734. return;
  5735. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5736. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5737. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5738. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5739. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5740. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5741. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5742. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5743. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5744. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5745. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5746. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5747. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5748. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5749. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5750. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5751. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5752. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5753. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5754. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5755. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5756. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5757. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5758. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5759. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5760. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5761. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5762. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5763. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5764. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5765. }
  5766. static void tg3_timer(unsigned long __opaque)
  5767. {
  5768. struct tg3 *tp = (struct tg3 *) __opaque;
  5769. if (tp->irq_sync)
  5770. goto restart_timer;
  5771. spin_lock(&tp->lock);
  5772. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5773. /* All of this garbage is because when using non-tagged
  5774. * IRQ status the mailbox/status_block protocol the chip
  5775. * uses with the cpu is race prone.
  5776. */
  5777. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5778. tw32(GRC_LOCAL_CTRL,
  5779. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5780. } else {
  5781. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5782. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5783. }
  5784. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5785. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5786. spin_unlock(&tp->lock);
  5787. schedule_work(&tp->reset_task);
  5788. return;
  5789. }
  5790. }
  5791. /* This part only runs once per second. */
  5792. if (!--tp->timer_counter) {
  5793. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5794. tg3_periodic_fetch_stats(tp);
  5795. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5796. u32 mac_stat;
  5797. int phy_event;
  5798. mac_stat = tr32(MAC_STATUS);
  5799. phy_event = 0;
  5800. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5801. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5802. phy_event = 1;
  5803. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5804. phy_event = 1;
  5805. if (phy_event)
  5806. tg3_setup_phy(tp, 0);
  5807. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5808. u32 mac_stat = tr32(MAC_STATUS);
  5809. int need_setup = 0;
  5810. if (netif_carrier_ok(tp->dev) &&
  5811. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5812. need_setup = 1;
  5813. }
  5814. if (! netif_carrier_ok(tp->dev) &&
  5815. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5816. MAC_STATUS_SIGNAL_DET))) {
  5817. need_setup = 1;
  5818. }
  5819. if (need_setup) {
  5820. if (!tp->serdes_counter) {
  5821. tw32_f(MAC_MODE,
  5822. (tp->mac_mode &
  5823. ~MAC_MODE_PORT_MODE_MASK));
  5824. udelay(40);
  5825. tw32_f(MAC_MODE, tp->mac_mode);
  5826. udelay(40);
  5827. }
  5828. tg3_setup_phy(tp, 0);
  5829. }
  5830. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5831. tg3_serdes_parallel_detect(tp);
  5832. tp->timer_counter = tp->timer_multiplier;
  5833. }
  5834. /* Heartbeat is only sent once every 2 seconds.
  5835. *
  5836. * The heartbeat is to tell the ASF firmware that the host
  5837. * driver is still alive. In the event that the OS crashes,
  5838. * ASF needs to reset the hardware to free up the FIFO space
  5839. * that may be filled with rx packets destined for the host.
  5840. * If the FIFO is full, ASF will no longer function properly.
  5841. *
  5842. * Unintended resets have been reported on real time kernels
  5843. * where the timer doesn't run on time. Netpoll will also have
  5844. * same problem.
  5845. *
  5846. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  5847. * to check the ring condition when the heartbeat is expiring
  5848. * before doing the reset. This will prevent most unintended
  5849. * resets.
  5850. */
  5851. if (!--tp->asf_counter) {
  5852. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5853. u32 val;
  5854. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5855. FWCMD_NICDRV_ALIVE3);
  5856. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5857. /* 5 seconds timeout */
  5858. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5859. val = tr32(GRC_RX_CPU_EVENT);
  5860. val |= (1 << 14);
  5861. tw32(GRC_RX_CPU_EVENT, val);
  5862. }
  5863. tp->asf_counter = tp->asf_multiplier;
  5864. }
  5865. spin_unlock(&tp->lock);
  5866. restart_timer:
  5867. tp->timer.expires = jiffies + tp->timer_offset;
  5868. add_timer(&tp->timer);
  5869. }
  5870. static int tg3_request_irq(struct tg3 *tp)
  5871. {
  5872. irq_handler_t fn;
  5873. unsigned long flags;
  5874. struct net_device *dev = tp->dev;
  5875. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5876. fn = tg3_msi;
  5877. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5878. fn = tg3_msi_1shot;
  5879. flags = IRQF_SAMPLE_RANDOM;
  5880. } else {
  5881. fn = tg3_interrupt;
  5882. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5883. fn = tg3_interrupt_tagged;
  5884. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5885. }
  5886. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5887. }
  5888. static int tg3_test_interrupt(struct tg3 *tp)
  5889. {
  5890. struct net_device *dev = tp->dev;
  5891. int err, i, intr_ok = 0;
  5892. if (!netif_running(dev))
  5893. return -ENODEV;
  5894. tg3_disable_ints(tp);
  5895. free_irq(tp->pdev->irq, dev);
  5896. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5897. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5898. if (err)
  5899. return err;
  5900. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5901. tg3_enable_ints(tp);
  5902. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5903. HOSTCC_MODE_NOW);
  5904. for (i = 0; i < 5; i++) {
  5905. u32 int_mbox, misc_host_ctrl;
  5906. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5907. TG3_64BIT_REG_LOW);
  5908. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  5909. if ((int_mbox != 0) ||
  5910. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  5911. intr_ok = 1;
  5912. break;
  5913. }
  5914. msleep(10);
  5915. }
  5916. tg3_disable_ints(tp);
  5917. free_irq(tp->pdev->irq, dev);
  5918. err = tg3_request_irq(tp);
  5919. if (err)
  5920. return err;
  5921. if (intr_ok)
  5922. return 0;
  5923. return -EIO;
  5924. }
  5925. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5926. * successfully restored
  5927. */
  5928. static int tg3_test_msi(struct tg3 *tp)
  5929. {
  5930. struct net_device *dev = tp->dev;
  5931. int err;
  5932. u16 pci_cmd;
  5933. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  5934. return 0;
  5935. /* Turn off SERR reporting in case MSI terminates with Master
  5936. * Abort.
  5937. */
  5938. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  5939. pci_write_config_word(tp->pdev, PCI_COMMAND,
  5940. pci_cmd & ~PCI_COMMAND_SERR);
  5941. err = tg3_test_interrupt(tp);
  5942. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  5943. if (!err)
  5944. return 0;
  5945. /* other failures */
  5946. if (err != -EIO)
  5947. return err;
  5948. /* MSI test failed, go back to INTx mode */
  5949. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  5950. "switching to INTx mode. Please report this failure to "
  5951. "the PCI maintainer and include system chipset information.\n",
  5952. tp->dev->name);
  5953. free_irq(tp->pdev->irq, dev);
  5954. pci_disable_msi(tp->pdev);
  5955. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5956. err = tg3_request_irq(tp);
  5957. if (err)
  5958. return err;
  5959. /* Need to reset the chip because the MSI cycle may have terminated
  5960. * with Master Abort.
  5961. */
  5962. tg3_full_lock(tp, 1);
  5963. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5964. err = tg3_init_hw(tp, 1);
  5965. tg3_full_unlock(tp);
  5966. if (err)
  5967. free_irq(tp->pdev->irq, dev);
  5968. return err;
  5969. }
  5970. static int tg3_open(struct net_device *dev)
  5971. {
  5972. struct tg3 *tp = netdev_priv(dev);
  5973. int err;
  5974. tg3_full_lock(tp, 0);
  5975. err = tg3_set_power_state(tp, PCI_D0);
  5976. if (err) {
  5977. tg3_full_unlock(tp);
  5978. return err;
  5979. }
  5980. tg3_disable_ints(tp);
  5981. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  5982. tg3_full_unlock(tp);
  5983. /* The placement of this call is tied
  5984. * to the setup and use of Host TX descriptors.
  5985. */
  5986. err = tg3_alloc_consistent(tp);
  5987. if (err)
  5988. return err;
  5989. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  5990. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
  5991. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
  5992. !((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) &&
  5993. (tp->pdev_peer == tp->pdev))) {
  5994. /* All MSI supporting chips should support tagged
  5995. * status. Assert that this is the case.
  5996. */
  5997. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5998. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  5999. "Not using MSI.\n", tp->dev->name);
  6000. } else if (pci_enable_msi(tp->pdev) == 0) {
  6001. u32 msi_mode;
  6002. msi_mode = tr32(MSGINT_MODE);
  6003. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6004. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6005. }
  6006. }
  6007. err = tg3_request_irq(tp);
  6008. if (err) {
  6009. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6010. pci_disable_msi(tp->pdev);
  6011. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6012. }
  6013. tg3_free_consistent(tp);
  6014. return err;
  6015. }
  6016. tg3_full_lock(tp, 0);
  6017. err = tg3_init_hw(tp, 1);
  6018. if (err) {
  6019. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6020. tg3_free_rings(tp);
  6021. } else {
  6022. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6023. tp->timer_offset = HZ;
  6024. else
  6025. tp->timer_offset = HZ / 10;
  6026. BUG_ON(tp->timer_offset > HZ);
  6027. tp->timer_counter = tp->timer_multiplier =
  6028. (HZ / tp->timer_offset);
  6029. tp->asf_counter = tp->asf_multiplier =
  6030. ((HZ / tp->timer_offset) * 2);
  6031. init_timer(&tp->timer);
  6032. tp->timer.expires = jiffies + tp->timer_offset;
  6033. tp->timer.data = (unsigned long) tp;
  6034. tp->timer.function = tg3_timer;
  6035. }
  6036. tg3_full_unlock(tp);
  6037. if (err) {
  6038. free_irq(tp->pdev->irq, dev);
  6039. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6040. pci_disable_msi(tp->pdev);
  6041. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6042. }
  6043. tg3_free_consistent(tp);
  6044. return err;
  6045. }
  6046. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6047. err = tg3_test_msi(tp);
  6048. if (err) {
  6049. tg3_full_lock(tp, 0);
  6050. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6051. pci_disable_msi(tp->pdev);
  6052. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6053. }
  6054. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6055. tg3_free_rings(tp);
  6056. tg3_free_consistent(tp);
  6057. tg3_full_unlock(tp);
  6058. return err;
  6059. }
  6060. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6061. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6062. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6063. tw32(PCIE_TRANSACTION_CFG,
  6064. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6065. }
  6066. }
  6067. }
  6068. tg3_full_lock(tp, 0);
  6069. add_timer(&tp->timer);
  6070. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6071. tg3_enable_ints(tp);
  6072. tg3_full_unlock(tp);
  6073. netif_start_queue(dev);
  6074. return 0;
  6075. }
  6076. #if 0
  6077. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6078. {
  6079. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6080. u16 val16;
  6081. int i;
  6082. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6083. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6084. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6085. val16, val32);
  6086. /* MAC block */
  6087. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6088. tr32(MAC_MODE), tr32(MAC_STATUS));
  6089. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6090. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6091. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6092. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6093. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6094. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6095. /* Send data initiator control block */
  6096. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6097. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6098. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6099. tr32(SNDDATAI_STATSCTRL));
  6100. /* Send data completion control block */
  6101. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6102. /* Send BD ring selector block */
  6103. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6104. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6105. /* Send BD initiator control block */
  6106. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6107. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6108. /* Send BD completion control block */
  6109. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6110. /* Receive list placement control block */
  6111. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6112. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6113. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6114. tr32(RCVLPC_STATSCTRL));
  6115. /* Receive data and receive BD initiator control block */
  6116. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6117. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6118. /* Receive data completion control block */
  6119. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6120. tr32(RCVDCC_MODE));
  6121. /* Receive BD initiator control block */
  6122. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6123. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6124. /* Receive BD completion control block */
  6125. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6126. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6127. /* Receive list selector control block */
  6128. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6129. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6130. /* Mbuf cluster free block */
  6131. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6132. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6133. /* Host coalescing control block */
  6134. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6135. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6136. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6137. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6138. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6139. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6140. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6141. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6142. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6143. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6144. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6145. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6146. /* Memory arbiter control block */
  6147. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6148. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6149. /* Buffer manager control block */
  6150. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6151. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6152. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6153. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6154. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6155. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6156. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6157. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6158. /* Read DMA control block */
  6159. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6160. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6161. /* Write DMA control block */
  6162. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6163. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6164. /* DMA completion block */
  6165. printk("DEBUG: DMAC_MODE[%08x]\n",
  6166. tr32(DMAC_MODE));
  6167. /* GRC block */
  6168. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6169. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6170. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6171. tr32(GRC_LOCAL_CTRL));
  6172. /* TG3_BDINFOs */
  6173. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6174. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6175. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6176. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6177. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6178. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6179. tr32(RCVDBDI_STD_BD + 0x0),
  6180. tr32(RCVDBDI_STD_BD + 0x4),
  6181. tr32(RCVDBDI_STD_BD + 0x8),
  6182. tr32(RCVDBDI_STD_BD + 0xc));
  6183. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6184. tr32(RCVDBDI_MINI_BD + 0x0),
  6185. tr32(RCVDBDI_MINI_BD + 0x4),
  6186. tr32(RCVDBDI_MINI_BD + 0x8),
  6187. tr32(RCVDBDI_MINI_BD + 0xc));
  6188. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6189. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6190. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6191. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6192. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6193. val32, val32_2, val32_3, val32_4);
  6194. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6195. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6196. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6197. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6198. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6199. val32, val32_2, val32_3, val32_4);
  6200. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6201. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6202. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6203. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6204. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6205. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6206. val32, val32_2, val32_3, val32_4, val32_5);
  6207. /* SW status block */
  6208. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6209. tp->hw_status->status,
  6210. tp->hw_status->status_tag,
  6211. tp->hw_status->rx_jumbo_consumer,
  6212. tp->hw_status->rx_consumer,
  6213. tp->hw_status->rx_mini_consumer,
  6214. tp->hw_status->idx[0].rx_producer,
  6215. tp->hw_status->idx[0].tx_consumer);
  6216. /* SW statistics block */
  6217. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6218. ((u32 *)tp->hw_stats)[0],
  6219. ((u32 *)tp->hw_stats)[1],
  6220. ((u32 *)tp->hw_stats)[2],
  6221. ((u32 *)tp->hw_stats)[3]);
  6222. /* Mailboxes */
  6223. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6224. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6225. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6226. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6227. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6228. /* NIC side send descriptors. */
  6229. for (i = 0; i < 6; i++) {
  6230. unsigned long txd;
  6231. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6232. + (i * sizeof(struct tg3_tx_buffer_desc));
  6233. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6234. i,
  6235. readl(txd + 0x0), readl(txd + 0x4),
  6236. readl(txd + 0x8), readl(txd + 0xc));
  6237. }
  6238. /* NIC side RX descriptors. */
  6239. for (i = 0; i < 6; i++) {
  6240. unsigned long rxd;
  6241. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6242. + (i * sizeof(struct tg3_rx_buffer_desc));
  6243. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6244. i,
  6245. readl(rxd + 0x0), readl(rxd + 0x4),
  6246. readl(rxd + 0x8), readl(rxd + 0xc));
  6247. rxd += (4 * sizeof(u32));
  6248. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6249. i,
  6250. readl(rxd + 0x0), readl(rxd + 0x4),
  6251. readl(rxd + 0x8), readl(rxd + 0xc));
  6252. }
  6253. for (i = 0; i < 6; i++) {
  6254. unsigned long rxd;
  6255. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6256. + (i * sizeof(struct tg3_rx_buffer_desc));
  6257. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6258. i,
  6259. readl(rxd + 0x0), readl(rxd + 0x4),
  6260. readl(rxd + 0x8), readl(rxd + 0xc));
  6261. rxd += (4 * sizeof(u32));
  6262. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6263. i,
  6264. readl(rxd + 0x0), readl(rxd + 0x4),
  6265. readl(rxd + 0x8), readl(rxd + 0xc));
  6266. }
  6267. }
  6268. #endif
  6269. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6270. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6271. static int tg3_close(struct net_device *dev)
  6272. {
  6273. struct tg3 *tp = netdev_priv(dev);
  6274. /* Calling flush_scheduled_work() may deadlock because
  6275. * linkwatch_event() may be on the workqueue and it will try to get
  6276. * the rtnl_lock which we are holding.
  6277. */
  6278. while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
  6279. msleep(1);
  6280. netif_stop_queue(dev);
  6281. del_timer_sync(&tp->timer);
  6282. tg3_full_lock(tp, 1);
  6283. #if 0
  6284. tg3_dump_state(tp);
  6285. #endif
  6286. tg3_disable_ints(tp);
  6287. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6288. tg3_free_rings(tp);
  6289. tp->tg3_flags &=
  6290. ~(TG3_FLAG_INIT_COMPLETE |
  6291. TG3_FLAG_GOT_SERDES_FLOWCTL);
  6292. tg3_full_unlock(tp);
  6293. free_irq(tp->pdev->irq, dev);
  6294. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6295. pci_disable_msi(tp->pdev);
  6296. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6297. }
  6298. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6299. sizeof(tp->net_stats_prev));
  6300. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6301. sizeof(tp->estats_prev));
  6302. tg3_free_consistent(tp);
  6303. tg3_set_power_state(tp, PCI_D3hot);
  6304. netif_carrier_off(tp->dev);
  6305. return 0;
  6306. }
  6307. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6308. {
  6309. unsigned long ret;
  6310. #if (BITS_PER_LONG == 32)
  6311. ret = val->low;
  6312. #else
  6313. ret = ((u64)val->high << 32) | ((u64)val->low);
  6314. #endif
  6315. return ret;
  6316. }
  6317. static unsigned long calc_crc_errors(struct tg3 *tp)
  6318. {
  6319. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6320. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6321. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6322. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6323. u32 val;
  6324. spin_lock_bh(&tp->lock);
  6325. if (!tg3_readphy(tp, 0x1e, &val)) {
  6326. tg3_writephy(tp, 0x1e, val | 0x8000);
  6327. tg3_readphy(tp, 0x14, &val);
  6328. } else
  6329. val = 0;
  6330. spin_unlock_bh(&tp->lock);
  6331. tp->phy_crc_errors += val;
  6332. return tp->phy_crc_errors;
  6333. }
  6334. return get_stat64(&hw_stats->rx_fcs_errors);
  6335. }
  6336. #define ESTAT_ADD(member) \
  6337. estats->member = old_estats->member + \
  6338. get_stat64(&hw_stats->member)
  6339. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6340. {
  6341. struct tg3_ethtool_stats *estats = &tp->estats;
  6342. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6343. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6344. if (!hw_stats)
  6345. return old_estats;
  6346. ESTAT_ADD(rx_octets);
  6347. ESTAT_ADD(rx_fragments);
  6348. ESTAT_ADD(rx_ucast_packets);
  6349. ESTAT_ADD(rx_mcast_packets);
  6350. ESTAT_ADD(rx_bcast_packets);
  6351. ESTAT_ADD(rx_fcs_errors);
  6352. ESTAT_ADD(rx_align_errors);
  6353. ESTAT_ADD(rx_xon_pause_rcvd);
  6354. ESTAT_ADD(rx_xoff_pause_rcvd);
  6355. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6356. ESTAT_ADD(rx_xoff_entered);
  6357. ESTAT_ADD(rx_frame_too_long_errors);
  6358. ESTAT_ADD(rx_jabbers);
  6359. ESTAT_ADD(rx_undersize_packets);
  6360. ESTAT_ADD(rx_in_length_errors);
  6361. ESTAT_ADD(rx_out_length_errors);
  6362. ESTAT_ADD(rx_64_or_less_octet_packets);
  6363. ESTAT_ADD(rx_65_to_127_octet_packets);
  6364. ESTAT_ADD(rx_128_to_255_octet_packets);
  6365. ESTAT_ADD(rx_256_to_511_octet_packets);
  6366. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6367. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6368. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6369. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6370. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6371. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6372. ESTAT_ADD(tx_octets);
  6373. ESTAT_ADD(tx_collisions);
  6374. ESTAT_ADD(tx_xon_sent);
  6375. ESTAT_ADD(tx_xoff_sent);
  6376. ESTAT_ADD(tx_flow_control);
  6377. ESTAT_ADD(tx_mac_errors);
  6378. ESTAT_ADD(tx_single_collisions);
  6379. ESTAT_ADD(tx_mult_collisions);
  6380. ESTAT_ADD(tx_deferred);
  6381. ESTAT_ADD(tx_excessive_collisions);
  6382. ESTAT_ADD(tx_late_collisions);
  6383. ESTAT_ADD(tx_collide_2times);
  6384. ESTAT_ADD(tx_collide_3times);
  6385. ESTAT_ADD(tx_collide_4times);
  6386. ESTAT_ADD(tx_collide_5times);
  6387. ESTAT_ADD(tx_collide_6times);
  6388. ESTAT_ADD(tx_collide_7times);
  6389. ESTAT_ADD(tx_collide_8times);
  6390. ESTAT_ADD(tx_collide_9times);
  6391. ESTAT_ADD(tx_collide_10times);
  6392. ESTAT_ADD(tx_collide_11times);
  6393. ESTAT_ADD(tx_collide_12times);
  6394. ESTAT_ADD(tx_collide_13times);
  6395. ESTAT_ADD(tx_collide_14times);
  6396. ESTAT_ADD(tx_collide_15times);
  6397. ESTAT_ADD(tx_ucast_packets);
  6398. ESTAT_ADD(tx_mcast_packets);
  6399. ESTAT_ADD(tx_bcast_packets);
  6400. ESTAT_ADD(tx_carrier_sense_errors);
  6401. ESTAT_ADD(tx_discards);
  6402. ESTAT_ADD(tx_errors);
  6403. ESTAT_ADD(dma_writeq_full);
  6404. ESTAT_ADD(dma_write_prioq_full);
  6405. ESTAT_ADD(rxbds_empty);
  6406. ESTAT_ADD(rx_discards);
  6407. ESTAT_ADD(rx_errors);
  6408. ESTAT_ADD(rx_threshold_hit);
  6409. ESTAT_ADD(dma_readq_full);
  6410. ESTAT_ADD(dma_read_prioq_full);
  6411. ESTAT_ADD(tx_comp_queue_full);
  6412. ESTAT_ADD(ring_set_send_prod_index);
  6413. ESTAT_ADD(ring_status_update);
  6414. ESTAT_ADD(nic_irqs);
  6415. ESTAT_ADD(nic_avoided_irqs);
  6416. ESTAT_ADD(nic_tx_threshold_hit);
  6417. return estats;
  6418. }
  6419. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6420. {
  6421. struct tg3 *tp = netdev_priv(dev);
  6422. struct net_device_stats *stats = &tp->net_stats;
  6423. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6424. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6425. if (!hw_stats)
  6426. return old_stats;
  6427. stats->rx_packets = old_stats->rx_packets +
  6428. get_stat64(&hw_stats->rx_ucast_packets) +
  6429. get_stat64(&hw_stats->rx_mcast_packets) +
  6430. get_stat64(&hw_stats->rx_bcast_packets);
  6431. stats->tx_packets = old_stats->tx_packets +
  6432. get_stat64(&hw_stats->tx_ucast_packets) +
  6433. get_stat64(&hw_stats->tx_mcast_packets) +
  6434. get_stat64(&hw_stats->tx_bcast_packets);
  6435. stats->rx_bytes = old_stats->rx_bytes +
  6436. get_stat64(&hw_stats->rx_octets);
  6437. stats->tx_bytes = old_stats->tx_bytes +
  6438. get_stat64(&hw_stats->tx_octets);
  6439. stats->rx_errors = old_stats->rx_errors +
  6440. get_stat64(&hw_stats->rx_errors);
  6441. stats->tx_errors = old_stats->tx_errors +
  6442. get_stat64(&hw_stats->tx_errors) +
  6443. get_stat64(&hw_stats->tx_mac_errors) +
  6444. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6445. get_stat64(&hw_stats->tx_discards);
  6446. stats->multicast = old_stats->multicast +
  6447. get_stat64(&hw_stats->rx_mcast_packets);
  6448. stats->collisions = old_stats->collisions +
  6449. get_stat64(&hw_stats->tx_collisions);
  6450. stats->rx_length_errors = old_stats->rx_length_errors +
  6451. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6452. get_stat64(&hw_stats->rx_undersize_packets);
  6453. stats->rx_over_errors = old_stats->rx_over_errors +
  6454. get_stat64(&hw_stats->rxbds_empty);
  6455. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6456. get_stat64(&hw_stats->rx_align_errors);
  6457. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6458. get_stat64(&hw_stats->tx_discards);
  6459. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6460. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6461. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6462. calc_crc_errors(tp);
  6463. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6464. get_stat64(&hw_stats->rx_discards);
  6465. return stats;
  6466. }
  6467. static inline u32 calc_crc(unsigned char *buf, int len)
  6468. {
  6469. u32 reg;
  6470. u32 tmp;
  6471. int j, k;
  6472. reg = 0xffffffff;
  6473. for (j = 0; j < len; j++) {
  6474. reg ^= buf[j];
  6475. for (k = 0; k < 8; k++) {
  6476. tmp = reg & 0x01;
  6477. reg >>= 1;
  6478. if (tmp) {
  6479. reg ^= 0xedb88320;
  6480. }
  6481. }
  6482. }
  6483. return ~reg;
  6484. }
  6485. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6486. {
  6487. /* accept or reject all multicast frames */
  6488. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6489. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6490. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6491. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6492. }
  6493. static void __tg3_set_rx_mode(struct net_device *dev)
  6494. {
  6495. struct tg3 *tp = netdev_priv(dev);
  6496. u32 rx_mode;
  6497. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6498. RX_MODE_KEEP_VLAN_TAG);
  6499. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6500. * flag clear.
  6501. */
  6502. #if TG3_VLAN_TAG_USED
  6503. if (!tp->vlgrp &&
  6504. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6505. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6506. #else
  6507. /* By definition, VLAN is disabled always in this
  6508. * case.
  6509. */
  6510. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6511. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6512. #endif
  6513. if (dev->flags & IFF_PROMISC) {
  6514. /* Promiscuous mode. */
  6515. rx_mode |= RX_MODE_PROMISC;
  6516. } else if (dev->flags & IFF_ALLMULTI) {
  6517. /* Accept all multicast. */
  6518. tg3_set_multi (tp, 1);
  6519. } else if (dev->mc_count < 1) {
  6520. /* Reject all multicast. */
  6521. tg3_set_multi (tp, 0);
  6522. } else {
  6523. /* Accept one or more multicast(s). */
  6524. struct dev_mc_list *mclist;
  6525. unsigned int i;
  6526. u32 mc_filter[4] = { 0, };
  6527. u32 regidx;
  6528. u32 bit;
  6529. u32 crc;
  6530. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6531. i++, mclist = mclist->next) {
  6532. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6533. bit = ~crc & 0x7f;
  6534. regidx = (bit & 0x60) >> 5;
  6535. bit &= 0x1f;
  6536. mc_filter[regidx] |= (1 << bit);
  6537. }
  6538. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6539. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6540. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6541. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6542. }
  6543. if (rx_mode != tp->rx_mode) {
  6544. tp->rx_mode = rx_mode;
  6545. tw32_f(MAC_RX_MODE, rx_mode);
  6546. udelay(10);
  6547. }
  6548. }
  6549. static void tg3_set_rx_mode(struct net_device *dev)
  6550. {
  6551. struct tg3 *tp = netdev_priv(dev);
  6552. if (!netif_running(dev))
  6553. return;
  6554. tg3_full_lock(tp, 0);
  6555. __tg3_set_rx_mode(dev);
  6556. tg3_full_unlock(tp);
  6557. }
  6558. #define TG3_REGDUMP_LEN (32 * 1024)
  6559. static int tg3_get_regs_len(struct net_device *dev)
  6560. {
  6561. return TG3_REGDUMP_LEN;
  6562. }
  6563. static void tg3_get_regs(struct net_device *dev,
  6564. struct ethtool_regs *regs, void *_p)
  6565. {
  6566. u32 *p = _p;
  6567. struct tg3 *tp = netdev_priv(dev);
  6568. u8 *orig_p = _p;
  6569. int i;
  6570. regs->version = 0;
  6571. memset(p, 0, TG3_REGDUMP_LEN);
  6572. if (tp->link_config.phy_is_low_power)
  6573. return;
  6574. tg3_full_lock(tp, 0);
  6575. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6576. #define GET_REG32_LOOP(base,len) \
  6577. do { p = (u32 *)(orig_p + (base)); \
  6578. for (i = 0; i < len; i += 4) \
  6579. __GET_REG32((base) + i); \
  6580. } while (0)
  6581. #define GET_REG32_1(reg) \
  6582. do { p = (u32 *)(orig_p + (reg)); \
  6583. __GET_REG32((reg)); \
  6584. } while (0)
  6585. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6586. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6587. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6588. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6589. GET_REG32_1(SNDDATAC_MODE);
  6590. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6591. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6592. GET_REG32_1(SNDBDC_MODE);
  6593. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6594. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6595. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6596. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6597. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6598. GET_REG32_1(RCVDCC_MODE);
  6599. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6600. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6601. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6602. GET_REG32_1(MBFREE_MODE);
  6603. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6604. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6605. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6606. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6607. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6608. GET_REG32_1(RX_CPU_MODE);
  6609. GET_REG32_1(RX_CPU_STATE);
  6610. GET_REG32_1(RX_CPU_PGMCTR);
  6611. GET_REG32_1(RX_CPU_HWBKPT);
  6612. GET_REG32_1(TX_CPU_MODE);
  6613. GET_REG32_1(TX_CPU_STATE);
  6614. GET_REG32_1(TX_CPU_PGMCTR);
  6615. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6616. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6617. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6618. GET_REG32_1(DMAC_MODE);
  6619. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6620. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6621. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6622. #undef __GET_REG32
  6623. #undef GET_REG32_LOOP
  6624. #undef GET_REG32_1
  6625. tg3_full_unlock(tp);
  6626. }
  6627. static int tg3_get_eeprom_len(struct net_device *dev)
  6628. {
  6629. struct tg3 *tp = netdev_priv(dev);
  6630. return tp->nvram_size;
  6631. }
  6632. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6633. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6634. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6635. {
  6636. struct tg3 *tp = netdev_priv(dev);
  6637. int ret;
  6638. u8 *pd;
  6639. u32 i, offset, len, val, b_offset, b_count;
  6640. if (tp->link_config.phy_is_low_power)
  6641. return -EAGAIN;
  6642. offset = eeprom->offset;
  6643. len = eeprom->len;
  6644. eeprom->len = 0;
  6645. eeprom->magic = TG3_EEPROM_MAGIC;
  6646. if (offset & 3) {
  6647. /* adjustments to start on required 4 byte boundary */
  6648. b_offset = offset & 3;
  6649. b_count = 4 - b_offset;
  6650. if (b_count > len) {
  6651. /* i.e. offset=1 len=2 */
  6652. b_count = len;
  6653. }
  6654. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6655. if (ret)
  6656. return ret;
  6657. val = cpu_to_le32(val);
  6658. memcpy(data, ((char*)&val) + b_offset, b_count);
  6659. len -= b_count;
  6660. offset += b_count;
  6661. eeprom->len += b_count;
  6662. }
  6663. /* read bytes upto the last 4 byte boundary */
  6664. pd = &data[eeprom->len];
  6665. for (i = 0; i < (len - (len & 3)); i += 4) {
  6666. ret = tg3_nvram_read(tp, offset + i, &val);
  6667. if (ret) {
  6668. eeprom->len += i;
  6669. return ret;
  6670. }
  6671. val = cpu_to_le32(val);
  6672. memcpy(pd + i, &val, 4);
  6673. }
  6674. eeprom->len += i;
  6675. if (len & 3) {
  6676. /* read last bytes not ending on 4 byte boundary */
  6677. pd = &data[eeprom->len];
  6678. b_count = len & 3;
  6679. b_offset = offset + len - b_count;
  6680. ret = tg3_nvram_read(tp, b_offset, &val);
  6681. if (ret)
  6682. return ret;
  6683. val = cpu_to_le32(val);
  6684. memcpy(pd, ((char*)&val), b_count);
  6685. eeprom->len += b_count;
  6686. }
  6687. return 0;
  6688. }
  6689. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6690. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6691. {
  6692. struct tg3 *tp = netdev_priv(dev);
  6693. int ret;
  6694. u32 offset, len, b_offset, odd_len, start, end;
  6695. u8 *buf;
  6696. if (tp->link_config.phy_is_low_power)
  6697. return -EAGAIN;
  6698. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6699. return -EINVAL;
  6700. offset = eeprom->offset;
  6701. len = eeprom->len;
  6702. if ((b_offset = (offset & 3))) {
  6703. /* adjustments to start on required 4 byte boundary */
  6704. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6705. if (ret)
  6706. return ret;
  6707. start = cpu_to_le32(start);
  6708. len += b_offset;
  6709. offset &= ~3;
  6710. if (len < 4)
  6711. len = 4;
  6712. }
  6713. odd_len = 0;
  6714. if (len & 3) {
  6715. /* adjustments to end on required 4 byte boundary */
  6716. odd_len = 1;
  6717. len = (len + 3) & ~3;
  6718. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6719. if (ret)
  6720. return ret;
  6721. end = cpu_to_le32(end);
  6722. }
  6723. buf = data;
  6724. if (b_offset || odd_len) {
  6725. buf = kmalloc(len, GFP_KERNEL);
  6726. if (buf == 0)
  6727. return -ENOMEM;
  6728. if (b_offset)
  6729. memcpy(buf, &start, 4);
  6730. if (odd_len)
  6731. memcpy(buf+len-4, &end, 4);
  6732. memcpy(buf + b_offset, data, eeprom->len);
  6733. }
  6734. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6735. if (buf != data)
  6736. kfree(buf);
  6737. return ret;
  6738. }
  6739. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6740. {
  6741. struct tg3 *tp = netdev_priv(dev);
  6742. cmd->supported = (SUPPORTED_Autoneg);
  6743. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6744. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6745. SUPPORTED_1000baseT_Full);
  6746. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6747. cmd->supported |= (SUPPORTED_100baseT_Half |
  6748. SUPPORTED_100baseT_Full |
  6749. SUPPORTED_10baseT_Half |
  6750. SUPPORTED_10baseT_Full |
  6751. SUPPORTED_MII);
  6752. cmd->port = PORT_TP;
  6753. } else {
  6754. cmd->supported |= SUPPORTED_FIBRE;
  6755. cmd->port = PORT_FIBRE;
  6756. }
  6757. cmd->advertising = tp->link_config.advertising;
  6758. if (netif_running(dev)) {
  6759. cmd->speed = tp->link_config.active_speed;
  6760. cmd->duplex = tp->link_config.active_duplex;
  6761. }
  6762. cmd->phy_address = PHY_ADDR;
  6763. cmd->transceiver = 0;
  6764. cmd->autoneg = tp->link_config.autoneg;
  6765. cmd->maxtxpkt = 0;
  6766. cmd->maxrxpkt = 0;
  6767. return 0;
  6768. }
  6769. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6770. {
  6771. struct tg3 *tp = netdev_priv(dev);
  6772. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6773. /* These are the only valid advertisement bits allowed. */
  6774. if (cmd->autoneg == AUTONEG_ENABLE &&
  6775. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6776. ADVERTISED_1000baseT_Full |
  6777. ADVERTISED_Autoneg |
  6778. ADVERTISED_FIBRE)))
  6779. return -EINVAL;
  6780. /* Fiber can only do SPEED_1000. */
  6781. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6782. (cmd->speed != SPEED_1000))
  6783. return -EINVAL;
  6784. /* Copper cannot force SPEED_1000. */
  6785. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6786. (cmd->speed == SPEED_1000))
  6787. return -EINVAL;
  6788. else if ((cmd->speed == SPEED_1000) &&
  6789. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6790. return -EINVAL;
  6791. tg3_full_lock(tp, 0);
  6792. tp->link_config.autoneg = cmd->autoneg;
  6793. if (cmd->autoneg == AUTONEG_ENABLE) {
  6794. tp->link_config.advertising = cmd->advertising;
  6795. tp->link_config.speed = SPEED_INVALID;
  6796. tp->link_config.duplex = DUPLEX_INVALID;
  6797. } else {
  6798. tp->link_config.advertising = 0;
  6799. tp->link_config.speed = cmd->speed;
  6800. tp->link_config.duplex = cmd->duplex;
  6801. }
  6802. if (netif_running(dev))
  6803. tg3_setup_phy(tp, 1);
  6804. tg3_full_unlock(tp);
  6805. return 0;
  6806. }
  6807. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6808. {
  6809. struct tg3 *tp = netdev_priv(dev);
  6810. strcpy(info->driver, DRV_MODULE_NAME);
  6811. strcpy(info->version, DRV_MODULE_VERSION);
  6812. strcpy(info->fw_version, tp->fw_ver);
  6813. strcpy(info->bus_info, pci_name(tp->pdev));
  6814. }
  6815. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6816. {
  6817. struct tg3 *tp = netdev_priv(dev);
  6818. wol->supported = WAKE_MAGIC;
  6819. wol->wolopts = 0;
  6820. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6821. wol->wolopts = WAKE_MAGIC;
  6822. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6823. }
  6824. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6825. {
  6826. struct tg3 *tp = netdev_priv(dev);
  6827. if (wol->wolopts & ~WAKE_MAGIC)
  6828. return -EINVAL;
  6829. if ((wol->wolopts & WAKE_MAGIC) &&
  6830. tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  6831. !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
  6832. return -EINVAL;
  6833. spin_lock_bh(&tp->lock);
  6834. if (wol->wolopts & WAKE_MAGIC)
  6835. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6836. else
  6837. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6838. spin_unlock_bh(&tp->lock);
  6839. return 0;
  6840. }
  6841. static u32 tg3_get_msglevel(struct net_device *dev)
  6842. {
  6843. struct tg3 *tp = netdev_priv(dev);
  6844. return tp->msg_enable;
  6845. }
  6846. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6847. {
  6848. struct tg3 *tp = netdev_priv(dev);
  6849. tp->msg_enable = value;
  6850. }
  6851. #if TG3_TSO_SUPPORT != 0
  6852. static int tg3_set_tso(struct net_device *dev, u32 value)
  6853. {
  6854. struct tg3 *tp = netdev_priv(dev);
  6855. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6856. if (value)
  6857. return -EINVAL;
  6858. return 0;
  6859. }
  6860. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  6861. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  6862. if (value)
  6863. dev->features |= NETIF_F_TSO6;
  6864. else
  6865. dev->features &= ~NETIF_F_TSO6;
  6866. }
  6867. return ethtool_op_set_tso(dev, value);
  6868. }
  6869. #endif
  6870. static int tg3_nway_reset(struct net_device *dev)
  6871. {
  6872. struct tg3 *tp = netdev_priv(dev);
  6873. u32 bmcr;
  6874. int r;
  6875. if (!netif_running(dev))
  6876. return -EAGAIN;
  6877. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6878. return -EINVAL;
  6879. spin_lock_bh(&tp->lock);
  6880. r = -EINVAL;
  6881. tg3_readphy(tp, MII_BMCR, &bmcr);
  6882. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6883. ((bmcr & BMCR_ANENABLE) ||
  6884. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6885. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6886. BMCR_ANENABLE);
  6887. r = 0;
  6888. }
  6889. spin_unlock_bh(&tp->lock);
  6890. return r;
  6891. }
  6892. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6893. {
  6894. struct tg3 *tp = netdev_priv(dev);
  6895. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6896. ering->rx_mini_max_pending = 0;
  6897. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6898. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6899. else
  6900. ering->rx_jumbo_max_pending = 0;
  6901. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6902. ering->rx_pending = tp->rx_pending;
  6903. ering->rx_mini_pending = 0;
  6904. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6905. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6906. else
  6907. ering->rx_jumbo_pending = 0;
  6908. ering->tx_pending = tp->tx_pending;
  6909. }
  6910. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6911. {
  6912. struct tg3 *tp = netdev_priv(dev);
  6913. int irq_sync = 0, err = 0;
  6914. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6915. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6916. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  6917. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  6918. ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG) &&
  6919. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  6920. return -EINVAL;
  6921. if (netif_running(dev)) {
  6922. tg3_netif_stop(tp);
  6923. irq_sync = 1;
  6924. }
  6925. tg3_full_lock(tp, irq_sync);
  6926. tp->rx_pending = ering->rx_pending;
  6927. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6928. tp->rx_pending > 63)
  6929. tp->rx_pending = 63;
  6930. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6931. tp->tx_pending = ering->tx_pending;
  6932. if (netif_running(dev)) {
  6933. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6934. err = tg3_restart_hw(tp, 1);
  6935. if (!err)
  6936. tg3_netif_start(tp);
  6937. }
  6938. tg3_full_unlock(tp);
  6939. return err;
  6940. }
  6941. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6942. {
  6943. struct tg3 *tp = netdev_priv(dev);
  6944. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  6945. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  6946. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  6947. }
  6948. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6949. {
  6950. struct tg3 *tp = netdev_priv(dev);
  6951. int irq_sync = 0, err = 0;
  6952. if (netif_running(dev)) {
  6953. tg3_netif_stop(tp);
  6954. irq_sync = 1;
  6955. }
  6956. tg3_full_lock(tp, irq_sync);
  6957. if (epause->autoneg)
  6958. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  6959. else
  6960. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  6961. if (epause->rx_pause)
  6962. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  6963. else
  6964. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  6965. if (epause->tx_pause)
  6966. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  6967. else
  6968. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  6969. if (netif_running(dev)) {
  6970. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6971. err = tg3_restart_hw(tp, 1);
  6972. if (!err)
  6973. tg3_netif_start(tp);
  6974. }
  6975. tg3_full_unlock(tp);
  6976. return err;
  6977. }
  6978. static u32 tg3_get_rx_csum(struct net_device *dev)
  6979. {
  6980. struct tg3 *tp = netdev_priv(dev);
  6981. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  6982. }
  6983. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  6984. {
  6985. struct tg3 *tp = netdev_priv(dev);
  6986. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  6987. if (data != 0)
  6988. return -EINVAL;
  6989. return 0;
  6990. }
  6991. spin_lock_bh(&tp->lock);
  6992. if (data)
  6993. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  6994. else
  6995. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  6996. spin_unlock_bh(&tp->lock);
  6997. return 0;
  6998. }
  6999. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7000. {
  7001. struct tg3 *tp = netdev_priv(dev);
  7002. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7003. if (data != 0)
  7004. return -EINVAL;
  7005. return 0;
  7006. }
  7007. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7008. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7009. ethtool_op_set_tx_hw_csum(dev, data);
  7010. else
  7011. ethtool_op_set_tx_csum(dev, data);
  7012. return 0;
  7013. }
  7014. static int tg3_get_stats_count (struct net_device *dev)
  7015. {
  7016. return TG3_NUM_STATS;
  7017. }
  7018. static int tg3_get_test_count (struct net_device *dev)
  7019. {
  7020. return TG3_NUM_TEST;
  7021. }
  7022. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7023. {
  7024. switch (stringset) {
  7025. case ETH_SS_STATS:
  7026. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7027. break;
  7028. case ETH_SS_TEST:
  7029. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7030. break;
  7031. default:
  7032. WARN_ON(1); /* we need a WARN() */
  7033. break;
  7034. }
  7035. }
  7036. static int tg3_phys_id(struct net_device *dev, u32 data)
  7037. {
  7038. struct tg3 *tp = netdev_priv(dev);
  7039. int i;
  7040. if (!netif_running(tp->dev))
  7041. return -EAGAIN;
  7042. if (data == 0)
  7043. data = 2;
  7044. for (i = 0; i < (data * 2); i++) {
  7045. if ((i % 2) == 0)
  7046. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7047. LED_CTRL_1000MBPS_ON |
  7048. LED_CTRL_100MBPS_ON |
  7049. LED_CTRL_10MBPS_ON |
  7050. LED_CTRL_TRAFFIC_OVERRIDE |
  7051. LED_CTRL_TRAFFIC_BLINK |
  7052. LED_CTRL_TRAFFIC_LED);
  7053. else
  7054. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7055. LED_CTRL_TRAFFIC_OVERRIDE);
  7056. if (msleep_interruptible(500))
  7057. break;
  7058. }
  7059. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7060. return 0;
  7061. }
  7062. static void tg3_get_ethtool_stats (struct net_device *dev,
  7063. struct ethtool_stats *estats, u64 *tmp_stats)
  7064. {
  7065. struct tg3 *tp = netdev_priv(dev);
  7066. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7067. }
  7068. #define NVRAM_TEST_SIZE 0x100
  7069. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  7070. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7071. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7072. static int tg3_test_nvram(struct tg3 *tp)
  7073. {
  7074. u32 *buf, csum, magic;
  7075. int i, j, err = 0, size;
  7076. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7077. return -EIO;
  7078. if (magic == TG3_EEPROM_MAGIC)
  7079. size = NVRAM_TEST_SIZE;
  7080. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7081. if ((magic & 0xe00000) == 0x200000)
  7082. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  7083. else
  7084. return 0;
  7085. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7086. size = NVRAM_SELFBOOT_HW_SIZE;
  7087. else
  7088. return -EIO;
  7089. buf = kmalloc(size, GFP_KERNEL);
  7090. if (buf == NULL)
  7091. return -ENOMEM;
  7092. err = -EIO;
  7093. for (i = 0, j = 0; i < size; i += 4, j++) {
  7094. u32 val;
  7095. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7096. break;
  7097. buf[j] = cpu_to_le32(val);
  7098. }
  7099. if (i < size)
  7100. goto out;
  7101. /* Selfboot format */
  7102. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
  7103. TG3_EEPROM_MAGIC_FW) {
  7104. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7105. for (i = 0; i < size; i++)
  7106. csum8 += buf8[i];
  7107. if (csum8 == 0) {
  7108. err = 0;
  7109. goto out;
  7110. }
  7111. err = -EIO;
  7112. goto out;
  7113. }
  7114. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
  7115. TG3_EEPROM_MAGIC_HW) {
  7116. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7117. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7118. u8 *buf8 = (u8 *) buf;
  7119. int j, k;
  7120. /* Separate the parity bits and the data bytes. */
  7121. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7122. if ((i == 0) || (i == 8)) {
  7123. int l;
  7124. u8 msk;
  7125. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7126. parity[k++] = buf8[i] & msk;
  7127. i++;
  7128. }
  7129. else if (i == 16) {
  7130. int l;
  7131. u8 msk;
  7132. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7133. parity[k++] = buf8[i] & msk;
  7134. i++;
  7135. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7136. parity[k++] = buf8[i] & msk;
  7137. i++;
  7138. }
  7139. data[j++] = buf8[i];
  7140. }
  7141. err = -EIO;
  7142. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7143. u8 hw8 = hweight8(data[i]);
  7144. if ((hw8 & 0x1) && parity[i])
  7145. goto out;
  7146. else if (!(hw8 & 0x1) && !parity[i])
  7147. goto out;
  7148. }
  7149. err = 0;
  7150. goto out;
  7151. }
  7152. /* Bootstrap checksum at offset 0x10 */
  7153. csum = calc_crc((unsigned char *) buf, 0x10);
  7154. if(csum != cpu_to_le32(buf[0x10/4]))
  7155. goto out;
  7156. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7157. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7158. if (csum != cpu_to_le32(buf[0xfc/4]))
  7159. goto out;
  7160. err = 0;
  7161. out:
  7162. kfree(buf);
  7163. return err;
  7164. }
  7165. #define TG3_SERDES_TIMEOUT_SEC 2
  7166. #define TG3_COPPER_TIMEOUT_SEC 6
  7167. static int tg3_test_link(struct tg3 *tp)
  7168. {
  7169. int i, max;
  7170. if (!netif_running(tp->dev))
  7171. return -ENODEV;
  7172. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7173. max = TG3_SERDES_TIMEOUT_SEC;
  7174. else
  7175. max = TG3_COPPER_TIMEOUT_SEC;
  7176. for (i = 0; i < max; i++) {
  7177. if (netif_carrier_ok(tp->dev))
  7178. return 0;
  7179. if (msleep_interruptible(1000))
  7180. break;
  7181. }
  7182. return -EIO;
  7183. }
  7184. /* Only test the commonly used registers */
  7185. static int tg3_test_registers(struct tg3 *tp)
  7186. {
  7187. int i, is_5705, is_5750;
  7188. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7189. static struct {
  7190. u16 offset;
  7191. u16 flags;
  7192. #define TG3_FL_5705 0x1
  7193. #define TG3_FL_NOT_5705 0x2
  7194. #define TG3_FL_NOT_5788 0x4
  7195. #define TG3_FL_NOT_5750 0x8
  7196. u32 read_mask;
  7197. u32 write_mask;
  7198. } reg_tbl[] = {
  7199. /* MAC Control Registers */
  7200. { MAC_MODE, TG3_FL_NOT_5705,
  7201. 0x00000000, 0x00ef6f8c },
  7202. { MAC_MODE, TG3_FL_5705,
  7203. 0x00000000, 0x01ef6b8c },
  7204. { MAC_STATUS, TG3_FL_NOT_5705,
  7205. 0x03800107, 0x00000000 },
  7206. { MAC_STATUS, TG3_FL_5705,
  7207. 0x03800100, 0x00000000 },
  7208. { MAC_ADDR_0_HIGH, 0x0000,
  7209. 0x00000000, 0x0000ffff },
  7210. { MAC_ADDR_0_LOW, 0x0000,
  7211. 0x00000000, 0xffffffff },
  7212. { MAC_RX_MTU_SIZE, 0x0000,
  7213. 0x00000000, 0x0000ffff },
  7214. { MAC_TX_MODE, 0x0000,
  7215. 0x00000000, 0x00000070 },
  7216. { MAC_TX_LENGTHS, 0x0000,
  7217. 0x00000000, 0x00003fff },
  7218. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7219. 0x00000000, 0x000007fc },
  7220. { MAC_RX_MODE, TG3_FL_5705,
  7221. 0x00000000, 0x000007dc },
  7222. { MAC_HASH_REG_0, 0x0000,
  7223. 0x00000000, 0xffffffff },
  7224. { MAC_HASH_REG_1, 0x0000,
  7225. 0x00000000, 0xffffffff },
  7226. { MAC_HASH_REG_2, 0x0000,
  7227. 0x00000000, 0xffffffff },
  7228. { MAC_HASH_REG_3, 0x0000,
  7229. 0x00000000, 0xffffffff },
  7230. /* Receive Data and Receive BD Initiator Control Registers. */
  7231. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7232. 0x00000000, 0xffffffff },
  7233. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7234. 0x00000000, 0xffffffff },
  7235. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7236. 0x00000000, 0x00000003 },
  7237. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7238. 0x00000000, 0xffffffff },
  7239. { RCVDBDI_STD_BD+0, 0x0000,
  7240. 0x00000000, 0xffffffff },
  7241. { RCVDBDI_STD_BD+4, 0x0000,
  7242. 0x00000000, 0xffffffff },
  7243. { RCVDBDI_STD_BD+8, 0x0000,
  7244. 0x00000000, 0xffff0002 },
  7245. { RCVDBDI_STD_BD+0xc, 0x0000,
  7246. 0x00000000, 0xffffffff },
  7247. /* Receive BD Initiator Control Registers. */
  7248. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7249. 0x00000000, 0xffffffff },
  7250. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7251. 0x00000000, 0x000003ff },
  7252. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7253. 0x00000000, 0xffffffff },
  7254. /* Host Coalescing Control Registers. */
  7255. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7256. 0x00000000, 0x00000004 },
  7257. { HOSTCC_MODE, TG3_FL_5705,
  7258. 0x00000000, 0x000000f6 },
  7259. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7260. 0x00000000, 0xffffffff },
  7261. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7262. 0x00000000, 0x000003ff },
  7263. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7264. 0x00000000, 0xffffffff },
  7265. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7266. 0x00000000, 0x000003ff },
  7267. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7268. 0x00000000, 0xffffffff },
  7269. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7270. 0x00000000, 0x000000ff },
  7271. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7272. 0x00000000, 0xffffffff },
  7273. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7274. 0x00000000, 0x000000ff },
  7275. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7276. 0x00000000, 0xffffffff },
  7277. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7278. 0x00000000, 0xffffffff },
  7279. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7280. 0x00000000, 0xffffffff },
  7281. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7282. 0x00000000, 0x000000ff },
  7283. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7284. 0x00000000, 0xffffffff },
  7285. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7286. 0x00000000, 0x000000ff },
  7287. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7288. 0x00000000, 0xffffffff },
  7289. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7290. 0x00000000, 0xffffffff },
  7291. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7292. 0x00000000, 0xffffffff },
  7293. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7294. 0x00000000, 0xffffffff },
  7295. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7296. 0x00000000, 0xffffffff },
  7297. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7298. 0xffffffff, 0x00000000 },
  7299. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7300. 0xffffffff, 0x00000000 },
  7301. /* Buffer Manager Control Registers. */
  7302. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7303. 0x00000000, 0x007fff80 },
  7304. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7305. 0x00000000, 0x007fffff },
  7306. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7307. 0x00000000, 0x0000003f },
  7308. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7309. 0x00000000, 0x000001ff },
  7310. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7311. 0x00000000, 0x000001ff },
  7312. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7313. 0xffffffff, 0x00000000 },
  7314. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7315. 0xffffffff, 0x00000000 },
  7316. /* Mailbox Registers */
  7317. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7318. 0x00000000, 0x000001ff },
  7319. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7320. 0x00000000, 0x000001ff },
  7321. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7322. 0x00000000, 0x000007ff },
  7323. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7324. 0x00000000, 0x000001ff },
  7325. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7326. };
  7327. is_5705 = is_5750 = 0;
  7328. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7329. is_5705 = 1;
  7330. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7331. is_5750 = 1;
  7332. }
  7333. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7334. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7335. continue;
  7336. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7337. continue;
  7338. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7339. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7340. continue;
  7341. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7342. continue;
  7343. offset = (u32) reg_tbl[i].offset;
  7344. read_mask = reg_tbl[i].read_mask;
  7345. write_mask = reg_tbl[i].write_mask;
  7346. /* Save the original register content */
  7347. save_val = tr32(offset);
  7348. /* Determine the read-only value. */
  7349. read_val = save_val & read_mask;
  7350. /* Write zero to the register, then make sure the read-only bits
  7351. * are not changed and the read/write bits are all zeros.
  7352. */
  7353. tw32(offset, 0);
  7354. val = tr32(offset);
  7355. /* Test the read-only and read/write bits. */
  7356. if (((val & read_mask) != read_val) || (val & write_mask))
  7357. goto out;
  7358. /* Write ones to all the bits defined by RdMask and WrMask, then
  7359. * make sure the read-only bits are not changed and the
  7360. * read/write bits are all ones.
  7361. */
  7362. tw32(offset, read_mask | write_mask);
  7363. val = tr32(offset);
  7364. /* Test the read-only bits. */
  7365. if ((val & read_mask) != read_val)
  7366. goto out;
  7367. /* Test the read/write bits. */
  7368. if ((val & write_mask) != write_mask)
  7369. goto out;
  7370. tw32(offset, save_val);
  7371. }
  7372. return 0;
  7373. out:
  7374. if (netif_msg_hw(tp))
  7375. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7376. offset);
  7377. tw32(offset, save_val);
  7378. return -EIO;
  7379. }
  7380. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7381. {
  7382. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7383. int i;
  7384. u32 j;
  7385. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7386. for (j = 0; j < len; j += 4) {
  7387. u32 val;
  7388. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7389. tg3_read_mem(tp, offset + j, &val);
  7390. if (val != test_pattern[i])
  7391. return -EIO;
  7392. }
  7393. }
  7394. return 0;
  7395. }
  7396. static int tg3_test_memory(struct tg3 *tp)
  7397. {
  7398. static struct mem_entry {
  7399. u32 offset;
  7400. u32 len;
  7401. } mem_tbl_570x[] = {
  7402. { 0x00000000, 0x00b50},
  7403. { 0x00002000, 0x1c000},
  7404. { 0xffffffff, 0x00000}
  7405. }, mem_tbl_5705[] = {
  7406. { 0x00000100, 0x0000c},
  7407. { 0x00000200, 0x00008},
  7408. { 0x00004000, 0x00800},
  7409. { 0x00006000, 0x01000},
  7410. { 0x00008000, 0x02000},
  7411. { 0x00010000, 0x0e000},
  7412. { 0xffffffff, 0x00000}
  7413. }, mem_tbl_5755[] = {
  7414. { 0x00000200, 0x00008},
  7415. { 0x00004000, 0x00800},
  7416. { 0x00006000, 0x00800},
  7417. { 0x00008000, 0x02000},
  7418. { 0x00010000, 0x0c000},
  7419. { 0xffffffff, 0x00000}
  7420. }, mem_tbl_5906[] = {
  7421. { 0x00000200, 0x00008},
  7422. { 0x00004000, 0x00400},
  7423. { 0x00006000, 0x00400},
  7424. { 0x00008000, 0x01000},
  7425. { 0x00010000, 0x01000},
  7426. { 0xffffffff, 0x00000}
  7427. };
  7428. struct mem_entry *mem_tbl;
  7429. int err = 0;
  7430. int i;
  7431. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7432. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7433. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7434. mem_tbl = mem_tbl_5755;
  7435. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7436. mem_tbl = mem_tbl_5906;
  7437. else
  7438. mem_tbl = mem_tbl_5705;
  7439. } else
  7440. mem_tbl = mem_tbl_570x;
  7441. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7442. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7443. mem_tbl[i].len)) != 0)
  7444. break;
  7445. }
  7446. return err;
  7447. }
  7448. #define TG3_MAC_LOOPBACK 0
  7449. #define TG3_PHY_LOOPBACK 1
  7450. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7451. {
  7452. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7453. u32 desc_idx;
  7454. struct sk_buff *skb, *rx_skb;
  7455. u8 *tx_data;
  7456. dma_addr_t map;
  7457. int num_pkts, tx_len, rx_len, i, err;
  7458. struct tg3_rx_buffer_desc *desc;
  7459. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7460. /* HW errata - mac loopback fails in some cases on 5780.
  7461. * Normal traffic and PHY loopback are not affected by
  7462. * errata.
  7463. */
  7464. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7465. return 0;
  7466. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7467. MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
  7468. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7469. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7470. else
  7471. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7472. tw32(MAC_MODE, mac_mode);
  7473. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7474. u32 val;
  7475. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7476. u32 phytest;
  7477. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7478. u32 phy;
  7479. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7480. phytest | MII_TG3_EPHY_SHADOW_EN);
  7481. if (!tg3_readphy(tp, 0x1b, &phy))
  7482. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7483. if (!tg3_readphy(tp, 0x10, &phy))
  7484. tg3_writephy(tp, 0x10, phy & ~0x4000);
  7485. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7486. }
  7487. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7488. } else
  7489. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7490. tg3_writephy(tp, MII_BMCR, val);
  7491. udelay(40);
  7492. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7493. MAC_MODE_LINK_POLARITY;
  7494. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7495. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7496. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7497. } else
  7498. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7499. /* reset to prevent losing 1st rx packet intermittently */
  7500. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7501. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7502. udelay(10);
  7503. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7504. }
  7505. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  7506. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7507. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7508. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7509. }
  7510. tw32(MAC_MODE, mac_mode);
  7511. }
  7512. else
  7513. return -EINVAL;
  7514. err = -EIO;
  7515. tx_len = 1514;
  7516. skb = netdev_alloc_skb(tp->dev, tx_len);
  7517. if (!skb)
  7518. return -ENOMEM;
  7519. tx_data = skb_put(skb, tx_len);
  7520. memcpy(tx_data, tp->dev->dev_addr, 6);
  7521. memset(tx_data + 6, 0x0, 8);
  7522. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7523. for (i = 14; i < tx_len; i++)
  7524. tx_data[i] = (u8) (i & 0xff);
  7525. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7526. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7527. HOSTCC_MODE_NOW);
  7528. udelay(10);
  7529. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7530. num_pkts = 0;
  7531. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7532. tp->tx_prod++;
  7533. num_pkts++;
  7534. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7535. tp->tx_prod);
  7536. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7537. udelay(10);
  7538. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  7539. for (i = 0; i < 25; i++) {
  7540. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7541. HOSTCC_MODE_NOW);
  7542. udelay(10);
  7543. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7544. rx_idx = tp->hw_status->idx[0].rx_producer;
  7545. if ((tx_idx == tp->tx_prod) &&
  7546. (rx_idx == (rx_start_idx + num_pkts)))
  7547. break;
  7548. }
  7549. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7550. dev_kfree_skb(skb);
  7551. if (tx_idx != tp->tx_prod)
  7552. goto out;
  7553. if (rx_idx != rx_start_idx + num_pkts)
  7554. goto out;
  7555. desc = &tp->rx_rcb[rx_start_idx];
  7556. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7557. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7558. if (opaque_key != RXD_OPAQUE_RING_STD)
  7559. goto out;
  7560. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7561. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7562. goto out;
  7563. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7564. if (rx_len != tx_len)
  7565. goto out;
  7566. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7567. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7568. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7569. for (i = 14; i < tx_len; i++) {
  7570. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7571. goto out;
  7572. }
  7573. err = 0;
  7574. /* tg3_free_rings will unmap and free the rx_skb */
  7575. out:
  7576. return err;
  7577. }
  7578. #define TG3_MAC_LOOPBACK_FAILED 1
  7579. #define TG3_PHY_LOOPBACK_FAILED 2
  7580. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7581. TG3_PHY_LOOPBACK_FAILED)
  7582. static int tg3_test_loopback(struct tg3 *tp)
  7583. {
  7584. int err = 0;
  7585. if (!netif_running(tp->dev))
  7586. return TG3_LOOPBACK_FAILED;
  7587. err = tg3_reset_hw(tp, 1);
  7588. if (err)
  7589. return TG3_LOOPBACK_FAILED;
  7590. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7591. err |= TG3_MAC_LOOPBACK_FAILED;
  7592. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7593. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7594. err |= TG3_PHY_LOOPBACK_FAILED;
  7595. }
  7596. return err;
  7597. }
  7598. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7599. u64 *data)
  7600. {
  7601. struct tg3 *tp = netdev_priv(dev);
  7602. if (tp->link_config.phy_is_low_power)
  7603. tg3_set_power_state(tp, PCI_D0);
  7604. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7605. if (tg3_test_nvram(tp) != 0) {
  7606. etest->flags |= ETH_TEST_FL_FAILED;
  7607. data[0] = 1;
  7608. }
  7609. if (tg3_test_link(tp) != 0) {
  7610. etest->flags |= ETH_TEST_FL_FAILED;
  7611. data[1] = 1;
  7612. }
  7613. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7614. int err, irq_sync = 0;
  7615. if (netif_running(dev)) {
  7616. tg3_netif_stop(tp);
  7617. irq_sync = 1;
  7618. }
  7619. tg3_full_lock(tp, irq_sync);
  7620. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7621. err = tg3_nvram_lock(tp);
  7622. tg3_halt_cpu(tp, RX_CPU_BASE);
  7623. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7624. tg3_halt_cpu(tp, TX_CPU_BASE);
  7625. if (!err)
  7626. tg3_nvram_unlock(tp);
  7627. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7628. tg3_phy_reset(tp);
  7629. if (tg3_test_registers(tp) != 0) {
  7630. etest->flags |= ETH_TEST_FL_FAILED;
  7631. data[2] = 1;
  7632. }
  7633. if (tg3_test_memory(tp) != 0) {
  7634. etest->flags |= ETH_TEST_FL_FAILED;
  7635. data[3] = 1;
  7636. }
  7637. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7638. etest->flags |= ETH_TEST_FL_FAILED;
  7639. tg3_full_unlock(tp);
  7640. if (tg3_test_interrupt(tp) != 0) {
  7641. etest->flags |= ETH_TEST_FL_FAILED;
  7642. data[5] = 1;
  7643. }
  7644. tg3_full_lock(tp, 0);
  7645. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7646. if (netif_running(dev)) {
  7647. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7648. if (!tg3_restart_hw(tp, 1))
  7649. tg3_netif_start(tp);
  7650. }
  7651. tg3_full_unlock(tp);
  7652. }
  7653. if (tp->link_config.phy_is_low_power)
  7654. tg3_set_power_state(tp, PCI_D3hot);
  7655. }
  7656. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7657. {
  7658. struct mii_ioctl_data *data = if_mii(ifr);
  7659. struct tg3 *tp = netdev_priv(dev);
  7660. int err;
  7661. switch(cmd) {
  7662. case SIOCGMIIPHY:
  7663. data->phy_id = PHY_ADDR;
  7664. /* fallthru */
  7665. case SIOCGMIIREG: {
  7666. u32 mii_regval;
  7667. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7668. break; /* We have no PHY */
  7669. if (tp->link_config.phy_is_low_power)
  7670. return -EAGAIN;
  7671. spin_lock_bh(&tp->lock);
  7672. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7673. spin_unlock_bh(&tp->lock);
  7674. data->val_out = mii_regval;
  7675. return err;
  7676. }
  7677. case SIOCSMIIREG:
  7678. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7679. break; /* We have no PHY */
  7680. if (!capable(CAP_NET_ADMIN))
  7681. return -EPERM;
  7682. if (tp->link_config.phy_is_low_power)
  7683. return -EAGAIN;
  7684. spin_lock_bh(&tp->lock);
  7685. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7686. spin_unlock_bh(&tp->lock);
  7687. return err;
  7688. default:
  7689. /* do nothing */
  7690. break;
  7691. }
  7692. return -EOPNOTSUPP;
  7693. }
  7694. #if TG3_VLAN_TAG_USED
  7695. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7696. {
  7697. struct tg3 *tp = netdev_priv(dev);
  7698. if (netif_running(dev))
  7699. tg3_netif_stop(tp);
  7700. tg3_full_lock(tp, 0);
  7701. tp->vlgrp = grp;
  7702. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7703. __tg3_set_rx_mode(dev);
  7704. tg3_full_unlock(tp);
  7705. if (netif_running(dev))
  7706. tg3_netif_start(tp);
  7707. }
  7708. static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  7709. {
  7710. struct tg3 *tp = netdev_priv(dev);
  7711. if (netif_running(dev))
  7712. tg3_netif_stop(tp);
  7713. tg3_full_lock(tp, 0);
  7714. if (tp->vlgrp)
  7715. tp->vlgrp->vlan_devices[vid] = NULL;
  7716. tg3_full_unlock(tp);
  7717. if (netif_running(dev))
  7718. tg3_netif_start(tp);
  7719. }
  7720. #endif
  7721. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7722. {
  7723. struct tg3 *tp = netdev_priv(dev);
  7724. memcpy(ec, &tp->coal, sizeof(*ec));
  7725. return 0;
  7726. }
  7727. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7728. {
  7729. struct tg3 *tp = netdev_priv(dev);
  7730. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7731. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7732. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7733. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7734. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7735. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7736. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7737. }
  7738. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7739. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7740. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7741. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7742. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7743. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7744. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7745. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7746. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7747. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7748. return -EINVAL;
  7749. /* No rx interrupts will be generated if both are zero */
  7750. if ((ec->rx_coalesce_usecs == 0) &&
  7751. (ec->rx_max_coalesced_frames == 0))
  7752. return -EINVAL;
  7753. /* No tx interrupts will be generated if both are zero */
  7754. if ((ec->tx_coalesce_usecs == 0) &&
  7755. (ec->tx_max_coalesced_frames == 0))
  7756. return -EINVAL;
  7757. /* Only copy relevant parameters, ignore all others. */
  7758. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7759. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7760. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7761. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7762. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7763. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7764. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7765. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7766. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7767. if (netif_running(dev)) {
  7768. tg3_full_lock(tp, 0);
  7769. __tg3_set_coalesce(tp, &tp->coal);
  7770. tg3_full_unlock(tp);
  7771. }
  7772. return 0;
  7773. }
  7774. static const struct ethtool_ops tg3_ethtool_ops = {
  7775. .get_settings = tg3_get_settings,
  7776. .set_settings = tg3_set_settings,
  7777. .get_drvinfo = tg3_get_drvinfo,
  7778. .get_regs_len = tg3_get_regs_len,
  7779. .get_regs = tg3_get_regs,
  7780. .get_wol = tg3_get_wol,
  7781. .set_wol = tg3_set_wol,
  7782. .get_msglevel = tg3_get_msglevel,
  7783. .set_msglevel = tg3_set_msglevel,
  7784. .nway_reset = tg3_nway_reset,
  7785. .get_link = ethtool_op_get_link,
  7786. .get_eeprom_len = tg3_get_eeprom_len,
  7787. .get_eeprom = tg3_get_eeprom,
  7788. .set_eeprom = tg3_set_eeprom,
  7789. .get_ringparam = tg3_get_ringparam,
  7790. .set_ringparam = tg3_set_ringparam,
  7791. .get_pauseparam = tg3_get_pauseparam,
  7792. .set_pauseparam = tg3_set_pauseparam,
  7793. .get_rx_csum = tg3_get_rx_csum,
  7794. .set_rx_csum = tg3_set_rx_csum,
  7795. .get_tx_csum = ethtool_op_get_tx_csum,
  7796. .set_tx_csum = tg3_set_tx_csum,
  7797. .get_sg = ethtool_op_get_sg,
  7798. .set_sg = ethtool_op_set_sg,
  7799. #if TG3_TSO_SUPPORT != 0
  7800. .get_tso = ethtool_op_get_tso,
  7801. .set_tso = tg3_set_tso,
  7802. #endif
  7803. .self_test_count = tg3_get_test_count,
  7804. .self_test = tg3_self_test,
  7805. .get_strings = tg3_get_strings,
  7806. .phys_id = tg3_phys_id,
  7807. .get_stats_count = tg3_get_stats_count,
  7808. .get_ethtool_stats = tg3_get_ethtool_stats,
  7809. .get_coalesce = tg3_get_coalesce,
  7810. .set_coalesce = tg3_set_coalesce,
  7811. .get_perm_addr = ethtool_op_get_perm_addr,
  7812. };
  7813. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7814. {
  7815. u32 cursize, val, magic;
  7816. tp->nvram_size = EEPROM_CHIP_SIZE;
  7817. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7818. return;
  7819. if ((magic != TG3_EEPROM_MAGIC) &&
  7820. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  7821. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  7822. return;
  7823. /*
  7824. * Size the chip by reading offsets at increasing powers of two.
  7825. * When we encounter our validation signature, we know the addressing
  7826. * has wrapped around, and thus have our chip size.
  7827. */
  7828. cursize = 0x10;
  7829. while (cursize < tp->nvram_size) {
  7830. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7831. return;
  7832. if (val == magic)
  7833. break;
  7834. cursize <<= 1;
  7835. }
  7836. tp->nvram_size = cursize;
  7837. }
  7838. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7839. {
  7840. u32 val;
  7841. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7842. return;
  7843. /* Selfboot format */
  7844. if (val != TG3_EEPROM_MAGIC) {
  7845. tg3_get_eeprom_size(tp);
  7846. return;
  7847. }
  7848. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7849. if (val != 0) {
  7850. tp->nvram_size = (val >> 16) * 1024;
  7851. return;
  7852. }
  7853. }
  7854. tp->nvram_size = 0x20000;
  7855. }
  7856. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7857. {
  7858. u32 nvcfg1;
  7859. nvcfg1 = tr32(NVRAM_CFG1);
  7860. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7861. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7862. }
  7863. else {
  7864. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7865. tw32(NVRAM_CFG1, nvcfg1);
  7866. }
  7867. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7868. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7869. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7870. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7871. tp->nvram_jedecnum = JEDEC_ATMEL;
  7872. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7873. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7874. break;
  7875. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7876. tp->nvram_jedecnum = JEDEC_ATMEL;
  7877. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7878. break;
  7879. case FLASH_VENDOR_ATMEL_EEPROM:
  7880. tp->nvram_jedecnum = JEDEC_ATMEL;
  7881. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7882. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7883. break;
  7884. case FLASH_VENDOR_ST:
  7885. tp->nvram_jedecnum = JEDEC_ST;
  7886. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7887. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7888. break;
  7889. case FLASH_VENDOR_SAIFUN:
  7890. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7891. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7892. break;
  7893. case FLASH_VENDOR_SST_SMALL:
  7894. case FLASH_VENDOR_SST_LARGE:
  7895. tp->nvram_jedecnum = JEDEC_SST;
  7896. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7897. break;
  7898. }
  7899. }
  7900. else {
  7901. tp->nvram_jedecnum = JEDEC_ATMEL;
  7902. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7903. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7904. }
  7905. }
  7906. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7907. {
  7908. u32 nvcfg1;
  7909. nvcfg1 = tr32(NVRAM_CFG1);
  7910. /* NVRAM protection for TPM */
  7911. if (nvcfg1 & (1 << 27))
  7912. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7913. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7914. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7915. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7916. tp->nvram_jedecnum = JEDEC_ATMEL;
  7917. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7918. break;
  7919. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7920. tp->nvram_jedecnum = JEDEC_ATMEL;
  7921. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7922. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7923. break;
  7924. case FLASH_5752VENDOR_ST_M45PE10:
  7925. case FLASH_5752VENDOR_ST_M45PE20:
  7926. case FLASH_5752VENDOR_ST_M45PE40:
  7927. tp->nvram_jedecnum = JEDEC_ST;
  7928. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7929. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7930. break;
  7931. }
  7932. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7933. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7934. case FLASH_5752PAGE_SIZE_256:
  7935. tp->nvram_pagesize = 256;
  7936. break;
  7937. case FLASH_5752PAGE_SIZE_512:
  7938. tp->nvram_pagesize = 512;
  7939. break;
  7940. case FLASH_5752PAGE_SIZE_1K:
  7941. tp->nvram_pagesize = 1024;
  7942. break;
  7943. case FLASH_5752PAGE_SIZE_2K:
  7944. tp->nvram_pagesize = 2048;
  7945. break;
  7946. case FLASH_5752PAGE_SIZE_4K:
  7947. tp->nvram_pagesize = 4096;
  7948. break;
  7949. case FLASH_5752PAGE_SIZE_264:
  7950. tp->nvram_pagesize = 264;
  7951. break;
  7952. }
  7953. }
  7954. else {
  7955. /* For eeprom, set pagesize to maximum eeprom size */
  7956. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7957. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7958. tw32(NVRAM_CFG1, nvcfg1);
  7959. }
  7960. }
  7961. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  7962. {
  7963. u32 nvcfg1;
  7964. nvcfg1 = tr32(NVRAM_CFG1);
  7965. /* NVRAM protection for TPM */
  7966. if (nvcfg1 & (1 << 27))
  7967. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7968. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7969. case FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ:
  7970. case FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ:
  7971. tp->nvram_jedecnum = JEDEC_ATMEL;
  7972. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7973. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7974. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7975. tw32(NVRAM_CFG1, nvcfg1);
  7976. break;
  7977. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7978. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7979. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  7980. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  7981. case FLASH_5755VENDOR_ATMEL_FLASH_4:
  7982. tp->nvram_jedecnum = JEDEC_ATMEL;
  7983. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7984. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7985. tp->nvram_pagesize = 264;
  7986. break;
  7987. case FLASH_5752VENDOR_ST_M45PE10:
  7988. case FLASH_5752VENDOR_ST_M45PE20:
  7989. case FLASH_5752VENDOR_ST_M45PE40:
  7990. tp->nvram_jedecnum = JEDEC_ST;
  7991. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7992. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7993. tp->nvram_pagesize = 256;
  7994. break;
  7995. }
  7996. }
  7997. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  7998. {
  7999. u32 nvcfg1;
  8000. nvcfg1 = tr32(NVRAM_CFG1);
  8001. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8002. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8003. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8004. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8005. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8006. tp->nvram_jedecnum = JEDEC_ATMEL;
  8007. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8008. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8009. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8010. tw32(NVRAM_CFG1, nvcfg1);
  8011. break;
  8012. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8013. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8014. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8015. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8016. tp->nvram_jedecnum = JEDEC_ATMEL;
  8017. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8018. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8019. tp->nvram_pagesize = 264;
  8020. break;
  8021. case FLASH_5752VENDOR_ST_M45PE10:
  8022. case FLASH_5752VENDOR_ST_M45PE20:
  8023. case FLASH_5752VENDOR_ST_M45PE40:
  8024. tp->nvram_jedecnum = JEDEC_ST;
  8025. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8026. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8027. tp->nvram_pagesize = 256;
  8028. break;
  8029. }
  8030. }
  8031. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8032. {
  8033. tp->nvram_jedecnum = JEDEC_ATMEL;
  8034. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8035. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8036. }
  8037. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8038. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8039. {
  8040. tw32_f(GRC_EEPROM_ADDR,
  8041. (EEPROM_ADDR_FSM_RESET |
  8042. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8043. EEPROM_ADDR_CLKPERD_SHIFT)));
  8044. msleep(1);
  8045. /* Enable seeprom accesses. */
  8046. tw32_f(GRC_LOCAL_CTRL,
  8047. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8048. udelay(100);
  8049. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8050. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8051. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8052. if (tg3_nvram_lock(tp)) {
  8053. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8054. "tg3_nvram_init failed.\n", tp->dev->name);
  8055. return;
  8056. }
  8057. tg3_enable_nvram_access(tp);
  8058. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8059. tg3_get_5752_nvram_info(tp);
  8060. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8061. tg3_get_5755_nvram_info(tp);
  8062. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8063. tg3_get_5787_nvram_info(tp);
  8064. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8065. tg3_get_5906_nvram_info(tp);
  8066. else
  8067. tg3_get_nvram_info(tp);
  8068. tg3_get_nvram_size(tp);
  8069. tg3_disable_nvram_access(tp);
  8070. tg3_nvram_unlock(tp);
  8071. } else {
  8072. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8073. tg3_get_eeprom_size(tp);
  8074. }
  8075. }
  8076. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8077. u32 offset, u32 *val)
  8078. {
  8079. u32 tmp;
  8080. int i;
  8081. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8082. (offset % 4) != 0)
  8083. return -EINVAL;
  8084. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8085. EEPROM_ADDR_DEVID_MASK |
  8086. EEPROM_ADDR_READ);
  8087. tw32(GRC_EEPROM_ADDR,
  8088. tmp |
  8089. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8090. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8091. EEPROM_ADDR_ADDR_MASK) |
  8092. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8093. for (i = 0; i < 1000; i++) {
  8094. tmp = tr32(GRC_EEPROM_ADDR);
  8095. if (tmp & EEPROM_ADDR_COMPLETE)
  8096. break;
  8097. msleep(1);
  8098. }
  8099. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8100. return -EBUSY;
  8101. *val = tr32(GRC_EEPROM_DATA);
  8102. return 0;
  8103. }
  8104. #define NVRAM_CMD_TIMEOUT 10000
  8105. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8106. {
  8107. int i;
  8108. tw32(NVRAM_CMD, nvram_cmd);
  8109. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8110. udelay(10);
  8111. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8112. udelay(10);
  8113. break;
  8114. }
  8115. }
  8116. if (i == NVRAM_CMD_TIMEOUT) {
  8117. return -EBUSY;
  8118. }
  8119. return 0;
  8120. }
  8121. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8122. {
  8123. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8124. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8125. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8126. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8127. addr = ((addr / tp->nvram_pagesize) <<
  8128. ATMEL_AT45DB0X1B_PAGE_POS) +
  8129. (addr % tp->nvram_pagesize);
  8130. return addr;
  8131. }
  8132. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8133. {
  8134. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8135. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8136. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8137. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8138. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8139. tp->nvram_pagesize) +
  8140. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8141. return addr;
  8142. }
  8143. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8144. {
  8145. int ret;
  8146. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8147. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8148. offset = tg3_nvram_phys_addr(tp, offset);
  8149. if (offset > NVRAM_ADDR_MSK)
  8150. return -EINVAL;
  8151. ret = tg3_nvram_lock(tp);
  8152. if (ret)
  8153. return ret;
  8154. tg3_enable_nvram_access(tp);
  8155. tw32(NVRAM_ADDR, offset);
  8156. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8157. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8158. if (ret == 0)
  8159. *val = swab32(tr32(NVRAM_RDDATA));
  8160. tg3_disable_nvram_access(tp);
  8161. tg3_nvram_unlock(tp);
  8162. return ret;
  8163. }
  8164. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8165. {
  8166. int err;
  8167. u32 tmp;
  8168. err = tg3_nvram_read(tp, offset, &tmp);
  8169. *val = swab32(tmp);
  8170. return err;
  8171. }
  8172. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8173. u32 offset, u32 len, u8 *buf)
  8174. {
  8175. int i, j, rc = 0;
  8176. u32 val;
  8177. for (i = 0; i < len; i += 4) {
  8178. u32 addr, data;
  8179. addr = offset + i;
  8180. memcpy(&data, buf + i, 4);
  8181. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8182. val = tr32(GRC_EEPROM_ADDR);
  8183. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8184. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8185. EEPROM_ADDR_READ);
  8186. tw32(GRC_EEPROM_ADDR, val |
  8187. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8188. (addr & EEPROM_ADDR_ADDR_MASK) |
  8189. EEPROM_ADDR_START |
  8190. EEPROM_ADDR_WRITE);
  8191. for (j = 0; j < 1000; j++) {
  8192. val = tr32(GRC_EEPROM_ADDR);
  8193. if (val & EEPROM_ADDR_COMPLETE)
  8194. break;
  8195. msleep(1);
  8196. }
  8197. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8198. rc = -EBUSY;
  8199. break;
  8200. }
  8201. }
  8202. return rc;
  8203. }
  8204. /* offset and length are dword aligned */
  8205. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8206. u8 *buf)
  8207. {
  8208. int ret = 0;
  8209. u32 pagesize = tp->nvram_pagesize;
  8210. u32 pagemask = pagesize - 1;
  8211. u32 nvram_cmd;
  8212. u8 *tmp;
  8213. tmp = kmalloc(pagesize, GFP_KERNEL);
  8214. if (tmp == NULL)
  8215. return -ENOMEM;
  8216. while (len) {
  8217. int j;
  8218. u32 phy_addr, page_off, size;
  8219. phy_addr = offset & ~pagemask;
  8220. for (j = 0; j < pagesize; j += 4) {
  8221. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8222. (u32 *) (tmp + j))))
  8223. break;
  8224. }
  8225. if (ret)
  8226. break;
  8227. page_off = offset & pagemask;
  8228. size = pagesize;
  8229. if (len < size)
  8230. size = len;
  8231. len -= size;
  8232. memcpy(tmp + page_off, buf, size);
  8233. offset = offset + (pagesize - page_off);
  8234. tg3_enable_nvram_access(tp);
  8235. /*
  8236. * Before we can erase the flash page, we need
  8237. * to issue a special "write enable" command.
  8238. */
  8239. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8240. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8241. break;
  8242. /* Erase the target page */
  8243. tw32(NVRAM_ADDR, phy_addr);
  8244. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8245. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8246. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8247. break;
  8248. /* Issue another write enable to start the write. */
  8249. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8250. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8251. break;
  8252. for (j = 0; j < pagesize; j += 4) {
  8253. u32 data;
  8254. data = *((u32 *) (tmp + j));
  8255. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8256. tw32(NVRAM_ADDR, phy_addr + j);
  8257. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8258. NVRAM_CMD_WR;
  8259. if (j == 0)
  8260. nvram_cmd |= NVRAM_CMD_FIRST;
  8261. else if (j == (pagesize - 4))
  8262. nvram_cmd |= NVRAM_CMD_LAST;
  8263. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8264. break;
  8265. }
  8266. if (ret)
  8267. break;
  8268. }
  8269. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8270. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8271. kfree(tmp);
  8272. return ret;
  8273. }
  8274. /* offset and length are dword aligned */
  8275. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8276. u8 *buf)
  8277. {
  8278. int i, ret = 0;
  8279. for (i = 0; i < len; i += 4, offset += 4) {
  8280. u32 data, page_off, phy_addr, nvram_cmd;
  8281. memcpy(&data, buf + i, 4);
  8282. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8283. page_off = offset % tp->nvram_pagesize;
  8284. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8285. tw32(NVRAM_ADDR, phy_addr);
  8286. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8287. if ((page_off == 0) || (i == 0))
  8288. nvram_cmd |= NVRAM_CMD_FIRST;
  8289. if (page_off == (tp->nvram_pagesize - 4))
  8290. nvram_cmd |= NVRAM_CMD_LAST;
  8291. if (i == (len - 4))
  8292. nvram_cmd |= NVRAM_CMD_LAST;
  8293. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8294. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8295. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8296. (tp->nvram_jedecnum == JEDEC_ST) &&
  8297. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8298. if ((ret = tg3_nvram_exec_cmd(tp,
  8299. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8300. NVRAM_CMD_DONE)))
  8301. break;
  8302. }
  8303. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8304. /* We always do complete word writes to eeprom. */
  8305. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8306. }
  8307. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8308. break;
  8309. }
  8310. return ret;
  8311. }
  8312. /* offset and length are dword aligned */
  8313. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8314. {
  8315. int ret;
  8316. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8317. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8318. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8319. udelay(40);
  8320. }
  8321. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8322. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8323. }
  8324. else {
  8325. u32 grc_mode;
  8326. ret = tg3_nvram_lock(tp);
  8327. if (ret)
  8328. return ret;
  8329. tg3_enable_nvram_access(tp);
  8330. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8331. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8332. tw32(NVRAM_WRITE1, 0x406);
  8333. grc_mode = tr32(GRC_MODE);
  8334. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8335. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8336. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8337. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8338. buf);
  8339. }
  8340. else {
  8341. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8342. buf);
  8343. }
  8344. grc_mode = tr32(GRC_MODE);
  8345. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8346. tg3_disable_nvram_access(tp);
  8347. tg3_nvram_unlock(tp);
  8348. }
  8349. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8350. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8351. udelay(40);
  8352. }
  8353. return ret;
  8354. }
  8355. struct subsys_tbl_ent {
  8356. u16 subsys_vendor, subsys_devid;
  8357. u32 phy_id;
  8358. };
  8359. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8360. /* Broadcom boards. */
  8361. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8362. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8363. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8364. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8365. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8366. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8367. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8368. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8369. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8370. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8371. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8372. /* 3com boards. */
  8373. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8374. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8375. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8376. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8377. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8378. /* DELL boards. */
  8379. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8380. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8381. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8382. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8383. /* Compaq boards. */
  8384. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8385. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8386. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8387. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8388. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8389. /* IBM boards. */
  8390. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8391. };
  8392. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8393. {
  8394. int i;
  8395. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8396. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8397. tp->pdev->subsystem_vendor) &&
  8398. (subsys_id_to_phy_id[i].subsys_devid ==
  8399. tp->pdev->subsystem_device))
  8400. return &subsys_id_to_phy_id[i];
  8401. }
  8402. return NULL;
  8403. }
  8404. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8405. {
  8406. u32 val;
  8407. u16 pmcsr;
  8408. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8409. * so need make sure we're in D0.
  8410. */
  8411. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8412. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8413. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8414. msleep(1);
  8415. /* Make sure register accesses (indirect or otherwise)
  8416. * will function correctly.
  8417. */
  8418. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8419. tp->misc_host_ctrl);
  8420. /* The memory arbiter has to be enabled in order for SRAM accesses
  8421. * to succeed. Normally on powerup the tg3 chip firmware will make
  8422. * sure it is enabled, but other entities such as system netboot
  8423. * code might disable it.
  8424. */
  8425. val = tr32(MEMARB_MODE);
  8426. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8427. tp->phy_id = PHY_ID_INVALID;
  8428. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8429. /* Assume an onboard device by default. */
  8430. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8431. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8432. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  8433. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8434. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8435. }
  8436. return;
  8437. }
  8438. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8439. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8440. u32 nic_cfg, led_cfg;
  8441. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8442. int eeprom_phy_serdes = 0;
  8443. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8444. tp->nic_sram_data_cfg = nic_cfg;
  8445. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8446. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8447. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8448. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8449. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8450. (ver > 0) && (ver < 0x100))
  8451. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8452. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8453. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8454. eeprom_phy_serdes = 1;
  8455. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8456. if (nic_phy_id != 0) {
  8457. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8458. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8459. eeprom_phy_id = (id1 >> 16) << 10;
  8460. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8461. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8462. } else
  8463. eeprom_phy_id = 0;
  8464. tp->phy_id = eeprom_phy_id;
  8465. if (eeprom_phy_serdes) {
  8466. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8467. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8468. else
  8469. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8470. }
  8471. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8472. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8473. SHASTA_EXT_LED_MODE_MASK);
  8474. else
  8475. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8476. switch (led_cfg) {
  8477. default:
  8478. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8479. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8480. break;
  8481. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8482. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8483. break;
  8484. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8485. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8486. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8487. * read on some older 5700/5701 bootcode.
  8488. */
  8489. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8490. ASIC_REV_5700 ||
  8491. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8492. ASIC_REV_5701)
  8493. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8494. break;
  8495. case SHASTA_EXT_LED_SHARED:
  8496. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8497. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8498. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8499. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8500. LED_CTRL_MODE_PHY_2);
  8501. break;
  8502. case SHASTA_EXT_LED_MAC:
  8503. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8504. break;
  8505. case SHASTA_EXT_LED_COMBO:
  8506. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8507. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8508. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8509. LED_CTRL_MODE_PHY_2);
  8510. break;
  8511. };
  8512. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8513. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8514. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8515. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8516. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  8517. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8518. if ((tp->pdev->subsystem_vendor ==
  8519. PCI_VENDOR_ID_ARIMA) &&
  8520. (tp->pdev->subsystem_device == 0x205a ||
  8521. tp->pdev->subsystem_device == 0x2063))
  8522. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8523. } else {
  8524. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8525. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8526. }
  8527. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8528. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8529. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8530. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8531. }
  8532. if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
  8533. tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
  8534. if (cfg2 & (1 << 17))
  8535. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8536. /* serdes signal pre-emphasis in register 0x590 set by */
  8537. /* bootcode if bit 18 is set */
  8538. if (cfg2 & (1 << 18))
  8539. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8540. }
  8541. }
  8542. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8543. {
  8544. u32 hw_phy_id_1, hw_phy_id_2;
  8545. u32 hw_phy_id, hw_phy_id_masked;
  8546. int err;
  8547. /* Reading the PHY ID register can conflict with ASF
  8548. * firwmare access to the PHY hardware.
  8549. */
  8550. err = 0;
  8551. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8552. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8553. } else {
  8554. /* Now read the physical PHY_ID from the chip and verify
  8555. * that it is sane. If it doesn't look good, we fall back
  8556. * to either the hard-coded table based PHY_ID and failing
  8557. * that the value found in the eeprom area.
  8558. */
  8559. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8560. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8561. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8562. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8563. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8564. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8565. }
  8566. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8567. tp->phy_id = hw_phy_id;
  8568. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8569. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8570. else
  8571. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8572. } else {
  8573. if (tp->phy_id != PHY_ID_INVALID) {
  8574. /* Do nothing, phy ID already set up in
  8575. * tg3_get_eeprom_hw_cfg().
  8576. */
  8577. } else {
  8578. struct subsys_tbl_ent *p;
  8579. /* No eeprom signature? Try the hardcoded
  8580. * subsys device table.
  8581. */
  8582. p = lookup_by_subsys(tp);
  8583. if (!p)
  8584. return -ENODEV;
  8585. tp->phy_id = p->phy_id;
  8586. if (!tp->phy_id ||
  8587. tp->phy_id == PHY_ID_BCM8002)
  8588. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8589. }
  8590. }
  8591. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8592. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8593. u32 bmsr, adv_reg, tg3_ctrl, mask;
  8594. tg3_readphy(tp, MII_BMSR, &bmsr);
  8595. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8596. (bmsr & BMSR_LSTATUS))
  8597. goto skip_phy_reset;
  8598. err = tg3_phy_reset(tp);
  8599. if (err)
  8600. return err;
  8601. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8602. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8603. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8604. tg3_ctrl = 0;
  8605. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8606. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8607. MII_TG3_CTRL_ADV_1000_FULL);
  8608. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8609. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8610. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8611. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8612. }
  8613. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  8614. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  8615. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  8616. if (!tg3_copper_is_advertising_all(tp, mask)) {
  8617. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8618. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8619. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8620. tg3_writephy(tp, MII_BMCR,
  8621. BMCR_ANENABLE | BMCR_ANRESTART);
  8622. }
  8623. tg3_phy_set_wirespeed(tp);
  8624. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8625. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8626. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8627. }
  8628. skip_phy_reset:
  8629. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8630. err = tg3_init_5401phy_dsp(tp);
  8631. if (err)
  8632. return err;
  8633. }
  8634. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8635. err = tg3_init_5401phy_dsp(tp);
  8636. }
  8637. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8638. tp->link_config.advertising =
  8639. (ADVERTISED_1000baseT_Half |
  8640. ADVERTISED_1000baseT_Full |
  8641. ADVERTISED_Autoneg |
  8642. ADVERTISED_FIBRE);
  8643. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8644. tp->link_config.advertising &=
  8645. ~(ADVERTISED_1000baseT_Half |
  8646. ADVERTISED_1000baseT_Full);
  8647. return err;
  8648. }
  8649. static void __devinit tg3_read_partno(struct tg3 *tp)
  8650. {
  8651. unsigned char vpd_data[256];
  8652. unsigned int i;
  8653. u32 magic;
  8654. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8655. goto out_not_found;
  8656. if (magic == TG3_EEPROM_MAGIC) {
  8657. for (i = 0; i < 256; i += 4) {
  8658. u32 tmp;
  8659. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8660. goto out_not_found;
  8661. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8662. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8663. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8664. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8665. }
  8666. } else {
  8667. int vpd_cap;
  8668. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8669. for (i = 0; i < 256; i += 4) {
  8670. u32 tmp, j = 0;
  8671. u16 tmp16;
  8672. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8673. i);
  8674. while (j++ < 100) {
  8675. pci_read_config_word(tp->pdev, vpd_cap +
  8676. PCI_VPD_ADDR, &tmp16);
  8677. if (tmp16 & 0x8000)
  8678. break;
  8679. msleep(1);
  8680. }
  8681. if (!(tmp16 & 0x8000))
  8682. goto out_not_found;
  8683. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8684. &tmp);
  8685. tmp = cpu_to_le32(tmp);
  8686. memcpy(&vpd_data[i], &tmp, 4);
  8687. }
  8688. }
  8689. /* Now parse and find the part number. */
  8690. for (i = 0; i < 254; ) {
  8691. unsigned char val = vpd_data[i];
  8692. unsigned int block_end;
  8693. if (val == 0x82 || val == 0x91) {
  8694. i = (i + 3 +
  8695. (vpd_data[i + 1] +
  8696. (vpd_data[i + 2] << 8)));
  8697. continue;
  8698. }
  8699. if (val != 0x90)
  8700. goto out_not_found;
  8701. block_end = (i + 3 +
  8702. (vpd_data[i + 1] +
  8703. (vpd_data[i + 2] << 8)));
  8704. i += 3;
  8705. if (block_end > 256)
  8706. goto out_not_found;
  8707. while (i < (block_end - 2)) {
  8708. if (vpd_data[i + 0] == 'P' &&
  8709. vpd_data[i + 1] == 'N') {
  8710. int partno_len = vpd_data[i + 2];
  8711. i += 3;
  8712. if (partno_len > 24 || (partno_len + i) > 256)
  8713. goto out_not_found;
  8714. memcpy(tp->board_part_number,
  8715. &vpd_data[i], partno_len);
  8716. /* Success. */
  8717. return;
  8718. }
  8719. i += 3 + vpd_data[i + 2];
  8720. }
  8721. /* Part number not found. */
  8722. goto out_not_found;
  8723. }
  8724. out_not_found:
  8725. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8726. strcpy(tp->board_part_number, "BCM95906");
  8727. else
  8728. strcpy(tp->board_part_number, "none");
  8729. }
  8730. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8731. {
  8732. u32 val, offset, start;
  8733. if (tg3_nvram_read_swab(tp, 0, &val))
  8734. return;
  8735. if (val != TG3_EEPROM_MAGIC)
  8736. return;
  8737. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8738. tg3_nvram_read_swab(tp, 0x4, &start))
  8739. return;
  8740. offset = tg3_nvram_logical_addr(tp, offset);
  8741. if (tg3_nvram_read_swab(tp, offset, &val))
  8742. return;
  8743. if ((val & 0xfc000000) == 0x0c000000) {
  8744. u32 ver_offset, addr;
  8745. int i;
  8746. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8747. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8748. return;
  8749. if (val != 0)
  8750. return;
  8751. addr = offset + ver_offset - start;
  8752. for (i = 0; i < 16; i += 4) {
  8753. if (tg3_nvram_read(tp, addr + i, &val))
  8754. return;
  8755. val = cpu_to_le32(val);
  8756. memcpy(tp->fw_ver + i, &val, 4);
  8757. }
  8758. }
  8759. }
  8760. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8761. {
  8762. static struct pci_device_id write_reorder_chipsets[] = {
  8763. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8764. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8765. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8766. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8767. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8768. PCI_DEVICE_ID_VIA_8385_0) },
  8769. { },
  8770. };
  8771. u32 misc_ctrl_reg;
  8772. u32 cacheline_sz_reg;
  8773. u32 pci_state_reg, grc_misc_cfg;
  8774. u32 val;
  8775. u16 pci_cmd;
  8776. int err, pcie_cap;
  8777. /* Force memory write invalidate off. If we leave it on,
  8778. * then on 5700_BX chips we have to enable a workaround.
  8779. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8780. * to match the cacheline size. The Broadcom driver have this
  8781. * workaround but turns MWI off all the times so never uses
  8782. * it. This seems to suggest that the workaround is insufficient.
  8783. */
  8784. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8785. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8786. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8787. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8788. * has the register indirect write enable bit set before
  8789. * we try to access any of the MMIO registers. It is also
  8790. * critical that the PCI-X hw workaround situation is decided
  8791. * before that as well.
  8792. */
  8793. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8794. &misc_ctrl_reg);
  8795. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8796. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8797. /* Wrong chip ID in 5752 A0. This code can be removed later
  8798. * as A0 is not in production.
  8799. */
  8800. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8801. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8802. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8803. * we need to disable memory and use config. cycles
  8804. * only to access all registers. The 5702/03 chips
  8805. * can mistakenly decode the special cycles from the
  8806. * ICH chipsets as memory write cycles, causing corruption
  8807. * of register and memory space. Only certain ICH bridges
  8808. * will drive special cycles with non-zero data during the
  8809. * address phase which can fall within the 5703's address
  8810. * range. This is not an ICH bug as the PCI spec allows
  8811. * non-zero address during special cycles. However, only
  8812. * these ICH bridges are known to drive non-zero addresses
  8813. * during special cycles.
  8814. *
  8815. * Since special cycles do not cross PCI bridges, we only
  8816. * enable this workaround if the 5703 is on the secondary
  8817. * bus of these ICH bridges.
  8818. */
  8819. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8820. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8821. static struct tg3_dev_id {
  8822. u32 vendor;
  8823. u32 device;
  8824. u32 rev;
  8825. } ich_chipsets[] = {
  8826. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8827. PCI_ANY_ID },
  8828. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8829. PCI_ANY_ID },
  8830. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8831. 0xa },
  8832. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8833. PCI_ANY_ID },
  8834. { },
  8835. };
  8836. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8837. struct pci_dev *bridge = NULL;
  8838. while (pci_id->vendor != 0) {
  8839. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8840. bridge);
  8841. if (!bridge) {
  8842. pci_id++;
  8843. continue;
  8844. }
  8845. if (pci_id->rev != PCI_ANY_ID) {
  8846. u8 rev;
  8847. pci_read_config_byte(bridge, PCI_REVISION_ID,
  8848. &rev);
  8849. if (rev > pci_id->rev)
  8850. continue;
  8851. }
  8852. if (bridge->subordinate &&
  8853. (bridge->subordinate->number ==
  8854. tp->pdev->bus->number)) {
  8855. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8856. pci_dev_put(bridge);
  8857. break;
  8858. }
  8859. }
  8860. }
  8861. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8862. * DMA addresses > 40-bit. This bridge may have other additional
  8863. * 57xx devices behind it in some 4-port NIC designs for example.
  8864. * Any tg3 device found behind the bridge will also need the 40-bit
  8865. * DMA workaround.
  8866. */
  8867. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8868. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8869. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8870. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8871. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8872. }
  8873. else {
  8874. struct pci_dev *bridge = NULL;
  8875. do {
  8876. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8877. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8878. bridge);
  8879. if (bridge && bridge->subordinate &&
  8880. (bridge->subordinate->number <=
  8881. tp->pdev->bus->number) &&
  8882. (bridge->subordinate->subordinate >=
  8883. tp->pdev->bus->number)) {
  8884. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8885. pci_dev_put(bridge);
  8886. break;
  8887. }
  8888. } while (bridge);
  8889. }
  8890. /* Initialize misc host control in PCI block. */
  8891. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8892. MISC_HOST_CTRL_CHIPREV);
  8893. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8894. tp->misc_host_ctrl);
  8895. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8896. &cacheline_sz_reg);
  8897. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8898. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8899. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8900. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8901. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8902. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8903. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8904. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8905. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  8906. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8907. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8908. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8909. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8910. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8911. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8912. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8913. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8914. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8915. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8916. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8917. } else {
  8918. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 |
  8919. TG3_FLG2_HW_TSO_1_BUG;
  8920. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8921. ASIC_REV_5750 &&
  8922. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  8923. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_1_BUG;
  8924. }
  8925. }
  8926. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  8927. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  8928. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  8929. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  8930. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  8931. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  8932. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  8933. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  8934. if (pcie_cap != 0) {
  8935. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  8936. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8937. u16 lnkctl;
  8938. pci_read_config_word(tp->pdev,
  8939. pcie_cap + PCI_EXP_LNKCTL,
  8940. &lnkctl);
  8941. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  8942. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  8943. }
  8944. }
  8945. /* If we have an AMD 762 or VIA K8T800 chipset, write
  8946. * reordering to the mailbox registers done by the host
  8947. * controller can cause major troubles. We read back from
  8948. * every mailbox register write to force the writes to be
  8949. * posted to the chip in order.
  8950. */
  8951. if (pci_dev_present(write_reorder_chipsets) &&
  8952. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  8953. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  8954. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  8955. tp->pci_lat_timer < 64) {
  8956. tp->pci_lat_timer = 64;
  8957. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  8958. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  8959. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  8960. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  8961. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8962. cacheline_sz_reg);
  8963. }
  8964. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  8965. &pci_state_reg);
  8966. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  8967. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  8968. /* If this is a 5700 BX chipset, and we are in PCI-X
  8969. * mode, enable register write workaround.
  8970. *
  8971. * The workaround is to use indirect register accesses
  8972. * for all chip writes not to mailbox registers.
  8973. */
  8974. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  8975. u32 pm_reg;
  8976. u16 pci_cmd;
  8977. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  8978. /* The chip can have it's power management PCI config
  8979. * space registers clobbered due to this bug.
  8980. * So explicitly force the chip into D0 here.
  8981. */
  8982. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  8983. &pm_reg);
  8984. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  8985. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  8986. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  8987. pm_reg);
  8988. /* Also, force SERR#/PERR# in PCI command. */
  8989. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8990. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  8991. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8992. }
  8993. }
  8994. /* 5700 BX chips need to have their TX producer index mailboxes
  8995. * written twice to workaround a bug.
  8996. */
  8997. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  8998. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  8999. /* Back to back register writes can cause problems on this chip,
  9000. * the workaround is to read back all reg writes except those to
  9001. * mailbox regs. See tg3_write_indirect_reg32().
  9002. *
  9003. * PCI Express 5750_A0 rev chips need this workaround too.
  9004. */
  9005. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9006. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9007. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0))
  9008. tp->tg3_flags |= TG3_FLAG_5701_REG_WRITE_BUG;
  9009. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9010. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9011. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9012. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9013. /* Chip-specific fixup from Broadcom driver */
  9014. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9015. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9016. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9017. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9018. }
  9019. /* Default fast path register access methods */
  9020. tp->read32 = tg3_read32;
  9021. tp->write32 = tg3_write32;
  9022. tp->read32_mbox = tg3_read32;
  9023. tp->write32_mbox = tg3_write32;
  9024. tp->write32_tx_mbox = tg3_write32;
  9025. tp->write32_rx_mbox = tg3_write32;
  9026. /* Various workaround register access methods */
  9027. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9028. tp->write32 = tg3_write_indirect_reg32;
  9029. else if (tp->tg3_flags & TG3_FLAG_5701_REG_WRITE_BUG)
  9030. tp->write32 = tg3_write_flush_reg32;
  9031. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9032. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9033. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9034. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9035. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9036. }
  9037. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9038. tp->read32 = tg3_read_indirect_reg32;
  9039. tp->write32 = tg3_write_indirect_reg32;
  9040. tp->read32_mbox = tg3_read_indirect_mbox;
  9041. tp->write32_mbox = tg3_write_indirect_mbox;
  9042. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9043. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9044. iounmap(tp->regs);
  9045. tp->regs = NULL;
  9046. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9047. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9048. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9049. }
  9050. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9051. tp->read32_mbox = tg3_read32_mbox_5906;
  9052. tp->write32_mbox = tg3_write32_mbox_5906;
  9053. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9054. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9055. }
  9056. if (tp->write32 == tg3_write_indirect_reg32 ||
  9057. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9058. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9059. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9060. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9061. /* Get eeprom hw config before calling tg3_set_power_state().
  9062. * In particular, the TG3_FLG2_IS_NIC flag must be
  9063. * determined before calling tg3_set_power_state() so that
  9064. * we know whether or not to switch out of Vaux power.
  9065. * When the flag is set, it means that GPIO1 is used for eeprom
  9066. * write protect and also implies that it is a LOM where GPIOs
  9067. * are not used to switch power.
  9068. */
  9069. tg3_get_eeprom_hw_cfg(tp);
  9070. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9071. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9072. * It is also used as eeprom write protect on LOMs.
  9073. */
  9074. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9075. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9076. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9077. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9078. GRC_LCLCTRL_GPIO_OUTPUT1);
  9079. /* Unused GPIO3 must be driven as output on 5752 because there
  9080. * are no pull-up resistors on unused GPIO pins.
  9081. */
  9082. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9083. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9084. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9085. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9086. /* Force the chip into D0. */
  9087. err = tg3_set_power_state(tp, PCI_D0);
  9088. if (err) {
  9089. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9090. pci_name(tp->pdev));
  9091. return err;
  9092. }
  9093. /* 5700 B0 chips do not support checksumming correctly due
  9094. * to hardware bugs.
  9095. */
  9096. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9097. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9098. /* Derive initial jumbo mode from MTU assigned in
  9099. * ether_setup() via the alloc_etherdev() call
  9100. */
  9101. if (tp->dev->mtu > ETH_DATA_LEN &&
  9102. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9103. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9104. /* Determine WakeOnLan speed to use. */
  9105. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9106. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9107. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9108. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9109. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9110. } else {
  9111. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9112. }
  9113. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9114. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9115. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9116. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9117. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9118. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9119. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9120. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9121. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9122. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9123. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9124. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9125. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9126. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9127. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9128. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  9129. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9130. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9131. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9132. }
  9133. tp->coalesce_mode = 0;
  9134. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9135. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9136. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9137. /* Initialize MAC MI mode, polling disabled. */
  9138. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9139. udelay(80);
  9140. /* Initialize data/descriptor byte/word swapping. */
  9141. val = tr32(GRC_MODE);
  9142. val &= GRC_MODE_HOST_STACKUP;
  9143. tw32(GRC_MODE, val | tp->grc_mode);
  9144. tg3_switch_clocks(tp);
  9145. /* Clear this out for sanity. */
  9146. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9147. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9148. &pci_state_reg);
  9149. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9150. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9151. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9152. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9153. chiprevid == CHIPREV_ID_5701_B0 ||
  9154. chiprevid == CHIPREV_ID_5701_B2 ||
  9155. chiprevid == CHIPREV_ID_5701_B5) {
  9156. void __iomem *sram_base;
  9157. /* Write some dummy words into the SRAM status block
  9158. * area, see if it reads back correctly. If the return
  9159. * value is bad, force enable the PCIX workaround.
  9160. */
  9161. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9162. writel(0x00000000, sram_base);
  9163. writel(0x00000000, sram_base + 4);
  9164. writel(0xffffffff, sram_base + 4);
  9165. if (readl(sram_base) != 0x00000000)
  9166. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9167. }
  9168. }
  9169. udelay(50);
  9170. tg3_nvram_init(tp);
  9171. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9172. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9173. /* Broadcom's driver says that CIOBE multisplit has a bug */
  9174. #if 0
  9175. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  9176. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5704CIOBE) {
  9177. tp->tg3_flags |= TG3_FLAG_SPLIT_MODE;
  9178. tp->split_mode_max_reqs = SPLIT_MODE_5704_MAX_REQ;
  9179. }
  9180. #endif
  9181. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9182. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9183. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9184. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9185. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9186. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9187. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9188. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9189. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9190. HOSTCC_MODE_CLRTICK_TXBD);
  9191. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9192. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9193. tp->misc_host_ctrl);
  9194. }
  9195. /* these are limited to 10/100 only */
  9196. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9197. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9198. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9199. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9200. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9201. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9202. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9203. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9204. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9205. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9206. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9207. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9208. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9209. err = tg3_phy_probe(tp);
  9210. if (err) {
  9211. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9212. pci_name(tp->pdev), err);
  9213. /* ... but do not return immediately ... */
  9214. }
  9215. tg3_read_partno(tp);
  9216. tg3_read_fw_ver(tp);
  9217. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  9218. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9219. } else {
  9220. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9221. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  9222. else
  9223. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9224. }
  9225. /* 5700 {AX,BX} chips have a broken status block link
  9226. * change bit implementation, so we must use the
  9227. * status register in those cases.
  9228. */
  9229. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9230. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9231. else
  9232. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9233. /* The led_ctrl is set during tg3_phy_probe, here we might
  9234. * have to force the link status polling mechanism based
  9235. * upon subsystem IDs.
  9236. */
  9237. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9238. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9239. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9240. TG3_FLAG_USE_LINKCHG_REG);
  9241. }
  9242. /* For all SERDES we poll the MAC status register. */
  9243. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9244. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9245. else
  9246. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9247. /* All chips before 5787 can get confused if TX buffers
  9248. * straddle the 4GB address boundary in some cases.
  9249. */
  9250. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9251. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9252. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9253. tp->dev->hard_start_xmit = tg3_start_xmit;
  9254. else
  9255. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9256. tp->rx_offset = 2;
  9257. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9258. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9259. tp->rx_offset = 0;
  9260. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9261. /* Increment the rx prod index on the rx std ring by at most
  9262. * 8 for these chips to workaround hw errata.
  9263. */
  9264. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9265. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9266. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9267. tp->rx_std_max_post = 8;
  9268. /* By default, disable wake-on-lan. User can change this
  9269. * using ETHTOOL_SWOL.
  9270. */
  9271. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9272. return err;
  9273. }
  9274. #ifdef CONFIG_SPARC64
  9275. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9276. {
  9277. struct net_device *dev = tp->dev;
  9278. struct pci_dev *pdev = tp->pdev;
  9279. struct pcidev_cookie *pcp = pdev->sysdata;
  9280. if (pcp != NULL) {
  9281. unsigned char *addr;
  9282. int len;
  9283. addr = of_get_property(pcp->prom_node, "local-mac-address",
  9284. &len);
  9285. if (addr && len == 6) {
  9286. memcpy(dev->dev_addr, addr, 6);
  9287. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9288. return 0;
  9289. }
  9290. }
  9291. return -ENODEV;
  9292. }
  9293. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9294. {
  9295. struct net_device *dev = tp->dev;
  9296. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9297. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9298. return 0;
  9299. }
  9300. #endif
  9301. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9302. {
  9303. struct net_device *dev = tp->dev;
  9304. u32 hi, lo, mac_offset;
  9305. int addr_ok = 0;
  9306. #ifdef CONFIG_SPARC64
  9307. if (!tg3_get_macaddr_sparc(tp))
  9308. return 0;
  9309. #endif
  9310. mac_offset = 0x7c;
  9311. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9312. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9313. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9314. mac_offset = 0xcc;
  9315. if (tg3_nvram_lock(tp))
  9316. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9317. else
  9318. tg3_nvram_unlock(tp);
  9319. }
  9320. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9321. mac_offset = 0x10;
  9322. /* First try to get it from MAC address mailbox. */
  9323. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9324. if ((hi >> 16) == 0x484b) {
  9325. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9326. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9327. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9328. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9329. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9330. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9331. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9332. /* Some old bootcode may report a 0 MAC address in SRAM */
  9333. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9334. }
  9335. if (!addr_ok) {
  9336. /* Next, try NVRAM. */
  9337. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9338. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9339. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9340. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9341. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9342. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9343. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9344. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9345. }
  9346. /* Finally just fetch it out of the MAC control regs. */
  9347. else {
  9348. hi = tr32(MAC_ADDR_0_HIGH);
  9349. lo = tr32(MAC_ADDR_0_LOW);
  9350. dev->dev_addr[5] = lo & 0xff;
  9351. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9352. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9353. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9354. dev->dev_addr[1] = hi & 0xff;
  9355. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9356. }
  9357. }
  9358. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9359. #ifdef CONFIG_SPARC64
  9360. if (!tg3_get_default_macaddr_sparc(tp))
  9361. return 0;
  9362. #endif
  9363. return -EINVAL;
  9364. }
  9365. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9366. return 0;
  9367. }
  9368. #define BOUNDARY_SINGLE_CACHELINE 1
  9369. #define BOUNDARY_MULTI_CACHELINE 2
  9370. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9371. {
  9372. int cacheline_size;
  9373. u8 byte;
  9374. int goal;
  9375. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9376. if (byte == 0)
  9377. cacheline_size = 1024;
  9378. else
  9379. cacheline_size = (int) byte * 4;
  9380. /* On 5703 and later chips, the boundary bits have no
  9381. * effect.
  9382. */
  9383. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9384. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9385. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9386. goto out;
  9387. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9388. goal = BOUNDARY_MULTI_CACHELINE;
  9389. #else
  9390. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9391. goal = BOUNDARY_SINGLE_CACHELINE;
  9392. #else
  9393. goal = 0;
  9394. #endif
  9395. #endif
  9396. if (!goal)
  9397. goto out;
  9398. /* PCI controllers on most RISC systems tend to disconnect
  9399. * when a device tries to burst across a cache-line boundary.
  9400. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9401. *
  9402. * Unfortunately, for PCI-E there are only limited
  9403. * write-side controls for this, and thus for reads
  9404. * we will still get the disconnects. We'll also waste
  9405. * these PCI cycles for both read and write for chips
  9406. * other than 5700 and 5701 which do not implement the
  9407. * boundary bits.
  9408. */
  9409. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9410. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9411. switch (cacheline_size) {
  9412. case 16:
  9413. case 32:
  9414. case 64:
  9415. case 128:
  9416. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9417. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9418. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9419. } else {
  9420. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9421. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9422. }
  9423. break;
  9424. case 256:
  9425. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9426. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9427. break;
  9428. default:
  9429. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9430. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9431. break;
  9432. };
  9433. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9434. switch (cacheline_size) {
  9435. case 16:
  9436. case 32:
  9437. case 64:
  9438. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9439. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9440. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9441. break;
  9442. }
  9443. /* fallthrough */
  9444. case 128:
  9445. default:
  9446. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9447. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9448. break;
  9449. };
  9450. } else {
  9451. switch (cacheline_size) {
  9452. case 16:
  9453. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9454. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9455. DMA_RWCTRL_WRITE_BNDRY_16);
  9456. break;
  9457. }
  9458. /* fallthrough */
  9459. case 32:
  9460. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9461. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9462. DMA_RWCTRL_WRITE_BNDRY_32);
  9463. break;
  9464. }
  9465. /* fallthrough */
  9466. case 64:
  9467. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9468. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9469. DMA_RWCTRL_WRITE_BNDRY_64);
  9470. break;
  9471. }
  9472. /* fallthrough */
  9473. case 128:
  9474. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9475. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9476. DMA_RWCTRL_WRITE_BNDRY_128);
  9477. break;
  9478. }
  9479. /* fallthrough */
  9480. case 256:
  9481. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9482. DMA_RWCTRL_WRITE_BNDRY_256);
  9483. break;
  9484. case 512:
  9485. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9486. DMA_RWCTRL_WRITE_BNDRY_512);
  9487. break;
  9488. case 1024:
  9489. default:
  9490. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9491. DMA_RWCTRL_WRITE_BNDRY_1024);
  9492. break;
  9493. };
  9494. }
  9495. out:
  9496. return val;
  9497. }
  9498. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9499. {
  9500. struct tg3_internal_buffer_desc test_desc;
  9501. u32 sram_dma_descs;
  9502. int i, ret;
  9503. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9504. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9505. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9506. tw32(RDMAC_STATUS, 0);
  9507. tw32(WDMAC_STATUS, 0);
  9508. tw32(BUFMGR_MODE, 0);
  9509. tw32(FTQ_RESET, 0);
  9510. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9511. test_desc.addr_lo = buf_dma & 0xffffffff;
  9512. test_desc.nic_mbuf = 0x00002100;
  9513. test_desc.len = size;
  9514. /*
  9515. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9516. * the *second* time the tg3 driver was getting loaded after an
  9517. * initial scan.
  9518. *
  9519. * Broadcom tells me:
  9520. * ...the DMA engine is connected to the GRC block and a DMA
  9521. * reset may affect the GRC block in some unpredictable way...
  9522. * The behavior of resets to individual blocks has not been tested.
  9523. *
  9524. * Broadcom noted the GRC reset will also reset all sub-components.
  9525. */
  9526. if (to_device) {
  9527. test_desc.cqid_sqid = (13 << 8) | 2;
  9528. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9529. udelay(40);
  9530. } else {
  9531. test_desc.cqid_sqid = (16 << 8) | 7;
  9532. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9533. udelay(40);
  9534. }
  9535. test_desc.flags = 0x00000005;
  9536. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9537. u32 val;
  9538. val = *(((u32 *)&test_desc) + i);
  9539. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9540. sram_dma_descs + (i * sizeof(u32)));
  9541. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9542. }
  9543. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9544. if (to_device) {
  9545. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9546. } else {
  9547. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9548. }
  9549. ret = -ENODEV;
  9550. for (i = 0; i < 40; i++) {
  9551. u32 val;
  9552. if (to_device)
  9553. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9554. else
  9555. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9556. if ((val & 0xffff) == sram_dma_descs) {
  9557. ret = 0;
  9558. break;
  9559. }
  9560. udelay(100);
  9561. }
  9562. return ret;
  9563. }
  9564. #define TEST_BUFFER_SIZE 0x2000
  9565. static int __devinit tg3_test_dma(struct tg3 *tp)
  9566. {
  9567. dma_addr_t buf_dma;
  9568. u32 *buf, saved_dma_rwctrl;
  9569. int ret;
  9570. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9571. if (!buf) {
  9572. ret = -ENOMEM;
  9573. goto out_nofree;
  9574. }
  9575. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9576. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9577. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9578. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9579. /* DMA read watermark not used on PCIE */
  9580. tp->dma_rwctrl |= 0x00180000;
  9581. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9582. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9583. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9584. tp->dma_rwctrl |= 0x003f0000;
  9585. else
  9586. tp->dma_rwctrl |= 0x003f000f;
  9587. } else {
  9588. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9589. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9590. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9591. /* If the 5704 is behind the EPB bridge, we can
  9592. * do the less restrictive ONE_DMA workaround for
  9593. * better performance.
  9594. */
  9595. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9596. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9597. tp->dma_rwctrl |= 0x8000;
  9598. else if (ccval == 0x6 || ccval == 0x7)
  9599. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9600. /* Set bit 23 to enable PCIX hw bug fix */
  9601. tp->dma_rwctrl |= 0x009f0000;
  9602. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9603. /* 5780 always in PCIX mode */
  9604. tp->dma_rwctrl |= 0x00144000;
  9605. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9606. /* 5714 always in PCIX mode */
  9607. tp->dma_rwctrl |= 0x00148000;
  9608. } else {
  9609. tp->dma_rwctrl |= 0x001b000f;
  9610. }
  9611. }
  9612. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9613. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9614. tp->dma_rwctrl &= 0xfffffff0;
  9615. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9616. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9617. /* Remove this if it causes problems for some boards. */
  9618. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9619. /* On 5700/5701 chips, we need to set this bit.
  9620. * Otherwise the chip will issue cacheline transactions
  9621. * to streamable DMA memory with not all the byte
  9622. * enables turned on. This is an error on several
  9623. * RISC PCI controllers, in particular sparc64.
  9624. *
  9625. * On 5703/5704 chips, this bit has been reassigned
  9626. * a different meaning. In particular, it is used
  9627. * on those chips to enable a PCI-X workaround.
  9628. */
  9629. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9630. }
  9631. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9632. #if 0
  9633. /* Unneeded, already done by tg3_get_invariants. */
  9634. tg3_switch_clocks(tp);
  9635. #endif
  9636. ret = 0;
  9637. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9638. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9639. goto out;
  9640. /* It is best to perform DMA test with maximum write burst size
  9641. * to expose the 5700/5701 write DMA bug.
  9642. */
  9643. saved_dma_rwctrl = tp->dma_rwctrl;
  9644. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9645. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9646. while (1) {
  9647. u32 *p = buf, i;
  9648. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9649. p[i] = i;
  9650. /* Send the buffer to the chip. */
  9651. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9652. if (ret) {
  9653. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9654. break;
  9655. }
  9656. #if 0
  9657. /* validate data reached card RAM correctly. */
  9658. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9659. u32 val;
  9660. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9661. if (le32_to_cpu(val) != p[i]) {
  9662. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9663. /* ret = -ENODEV here? */
  9664. }
  9665. p[i] = 0;
  9666. }
  9667. #endif
  9668. /* Now read it back. */
  9669. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9670. if (ret) {
  9671. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9672. break;
  9673. }
  9674. /* Verify it. */
  9675. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9676. if (p[i] == i)
  9677. continue;
  9678. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9679. DMA_RWCTRL_WRITE_BNDRY_16) {
  9680. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9681. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9682. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9683. break;
  9684. } else {
  9685. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9686. ret = -ENODEV;
  9687. goto out;
  9688. }
  9689. }
  9690. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9691. /* Success. */
  9692. ret = 0;
  9693. break;
  9694. }
  9695. }
  9696. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9697. DMA_RWCTRL_WRITE_BNDRY_16) {
  9698. static struct pci_device_id dma_wait_state_chipsets[] = {
  9699. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9700. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9701. { },
  9702. };
  9703. /* DMA test passed without adjusting DMA boundary,
  9704. * now look for chipsets that are known to expose the
  9705. * DMA bug without failing the test.
  9706. */
  9707. if (pci_dev_present(dma_wait_state_chipsets)) {
  9708. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9709. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9710. }
  9711. else
  9712. /* Safe to use the calculated DMA boundary. */
  9713. tp->dma_rwctrl = saved_dma_rwctrl;
  9714. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9715. }
  9716. out:
  9717. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9718. out_nofree:
  9719. return ret;
  9720. }
  9721. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9722. {
  9723. tp->link_config.advertising =
  9724. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9725. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9726. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9727. ADVERTISED_Autoneg | ADVERTISED_MII);
  9728. tp->link_config.speed = SPEED_INVALID;
  9729. tp->link_config.duplex = DUPLEX_INVALID;
  9730. tp->link_config.autoneg = AUTONEG_ENABLE;
  9731. tp->link_config.active_speed = SPEED_INVALID;
  9732. tp->link_config.active_duplex = DUPLEX_INVALID;
  9733. tp->link_config.phy_is_low_power = 0;
  9734. tp->link_config.orig_speed = SPEED_INVALID;
  9735. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9736. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9737. }
  9738. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9739. {
  9740. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9741. tp->bufmgr_config.mbuf_read_dma_low_water =
  9742. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9743. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9744. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9745. tp->bufmgr_config.mbuf_high_water =
  9746. DEFAULT_MB_HIGH_WATER_5705;
  9747. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9748. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9749. DEFAULT_MB_MACRX_LOW_WATER_5906;
  9750. tp->bufmgr_config.mbuf_high_water =
  9751. DEFAULT_MB_HIGH_WATER_5906;
  9752. }
  9753. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9754. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9755. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9756. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9757. tp->bufmgr_config.mbuf_high_water_jumbo =
  9758. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9759. } else {
  9760. tp->bufmgr_config.mbuf_read_dma_low_water =
  9761. DEFAULT_MB_RDMA_LOW_WATER;
  9762. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9763. DEFAULT_MB_MACRX_LOW_WATER;
  9764. tp->bufmgr_config.mbuf_high_water =
  9765. DEFAULT_MB_HIGH_WATER;
  9766. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9767. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9768. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9769. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9770. tp->bufmgr_config.mbuf_high_water_jumbo =
  9771. DEFAULT_MB_HIGH_WATER_JUMBO;
  9772. }
  9773. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9774. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9775. }
  9776. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9777. {
  9778. switch (tp->phy_id & PHY_ID_MASK) {
  9779. case PHY_ID_BCM5400: return "5400";
  9780. case PHY_ID_BCM5401: return "5401";
  9781. case PHY_ID_BCM5411: return "5411";
  9782. case PHY_ID_BCM5701: return "5701";
  9783. case PHY_ID_BCM5703: return "5703";
  9784. case PHY_ID_BCM5704: return "5704";
  9785. case PHY_ID_BCM5705: return "5705";
  9786. case PHY_ID_BCM5750: return "5750";
  9787. case PHY_ID_BCM5752: return "5752";
  9788. case PHY_ID_BCM5714: return "5714";
  9789. case PHY_ID_BCM5780: return "5780";
  9790. case PHY_ID_BCM5755: return "5755";
  9791. case PHY_ID_BCM5787: return "5787";
  9792. case PHY_ID_BCM5756: return "5722/5756";
  9793. case PHY_ID_BCM5906: return "5906";
  9794. case PHY_ID_BCM8002: return "8002/serdes";
  9795. case 0: return "serdes";
  9796. default: return "unknown";
  9797. };
  9798. }
  9799. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9800. {
  9801. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9802. strcpy(str, "PCI Express");
  9803. return str;
  9804. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9805. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9806. strcpy(str, "PCIX:");
  9807. if ((clock_ctrl == 7) ||
  9808. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9809. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9810. strcat(str, "133MHz");
  9811. else if (clock_ctrl == 0)
  9812. strcat(str, "33MHz");
  9813. else if (clock_ctrl == 2)
  9814. strcat(str, "50MHz");
  9815. else if (clock_ctrl == 4)
  9816. strcat(str, "66MHz");
  9817. else if (clock_ctrl == 6)
  9818. strcat(str, "100MHz");
  9819. } else {
  9820. strcpy(str, "PCI:");
  9821. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9822. strcat(str, "66MHz");
  9823. else
  9824. strcat(str, "33MHz");
  9825. }
  9826. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9827. strcat(str, ":32-bit");
  9828. else
  9829. strcat(str, ":64-bit");
  9830. return str;
  9831. }
  9832. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9833. {
  9834. struct pci_dev *peer;
  9835. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9836. for (func = 0; func < 8; func++) {
  9837. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9838. if (peer && peer != tp->pdev)
  9839. break;
  9840. pci_dev_put(peer);
  9841. }
  9842. /* 5704 can be configured in single-port mode, set peer to
  9843. * tp->pdev in that case.
  9844. */
  9845. if (!peer) {
  9846. peer = tp->pdev;
  9847. return peer;
  9848. }
  9849. /*
  9850. * We don't need to keep the refcount elevated; there's no way
  9851. * to remove one half of this device without removing the other
  9852. */
  9853. pci_dev_put(peer);
  9854. return peer;
  9855. }
  9856. static void __devinit tg3_init_coal(struct tg3 *tp)
  9857. {
  9858. struct ethtool_coalesce *ec = &tp->coal;
  9859. memset(ec, 0, sizeof(*ec));
  9860. ec->cmd = ETHTOOL_GCOALESCE;
  9861. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9862. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9863. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9864. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9865. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9866. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9867. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9868. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9869. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9870. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9871. HOSTCC_MODE_CLRTICK_TXBD)) {
  9872. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9873. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9874. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9875. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9876. }
  9877. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9878. ec->rx_coalesce_usecs_irq = 0;
  9879. ec->tx_coalesce_usecs_irq = 0;
  9880. ec->stats_block_coalesce_usecs = 0;
  9881. }
  9882. }
  9883. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9884. const struct pci_device_id *ent)
  9885. {
  9886. static int tg3_version_printed = 0;
  9887. unsigned long tg3reg_base, tg3reg_len;
  9888. struct net_device *dev;
  9889. struct tg3 *tp;
  9890. int i, err, pm_cap;
  9891. char str[40];
  9892. u64 dma_mask, persist_dma_mask;
  9893. if (tg3_version_printed++ == 0)
  9894. printk(KERN_INFO "%s", version);
  9895. err = pci_enable_device(pdev);
  9896. if (err) {
  9897. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9898. "aborting.\n");
  9899. return err;
  9900. }
  9901. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9902. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9903. "base address, aborting.\n");
  9904. err = -ENODEV;
  9905. goto err_out_disable_pdev;
  9906. }
  9907. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9908. if (err) {
  9909. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9910. "aborting.\n");
  9911. goto err_out_disable_pdev;
  9912. }
  9913. pci_set_master(pdev);
  9914. /* Find power-management capability. */
  9915. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9916. if (pm_cap == 0) {
  9917. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  9918. "aborting.\n");
  9919. err = -EIO;
  9920. goto err_out_free_res;
  9921. }
  9922. tg3reg_base = pci_resource_start(pdev, 0);
  9923. tg3reg_len = pci_resource_len(pdev, 0);
  9924. dev = alloc_etherdev(sizeof(*tp));
  9925. if (!dev) {
  9926. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  9927. err = -ENOMEM;
  9928. goto err_out_free_res;
  9929. }
  9930. SET_MODULE_OWNER(dev);
  9931. SET_NETDEV_DEV(dev, &pdev->dev);
  9932. #if TG3_VLAN_TAG_USED
  9933. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  9934. dev->vlan_rx_register = tg3_vlan_rx_register;
  9935. dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
  9936. #endif
  9937. tp = netdev_priv(dev);
  9938. tp->pdev = pdev;
  9939. tp->dev = dev;
  9940. tp->pm_cap = pm_cap;
  9941. tp->mac_mode = TG3_DEF_MAC_MODE;
  9942. tp->rx_mode = TG3_DEF_RX_MODE;
  9943. tp->tx_mode = TG3_DEF_TX_MODE;
  9944. tp->mi_mode = MAC_MI_MODE_BASE;
  9945. if (tg3_debug > 0)
  9946. tp->msg_enable = tg3_debug;
  9947. else
  9948. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  9949. /* The word/byte swap controls here control register access byte
  9950. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  9951. * setting below.
  9952. */
  9953. tp->misc_host_ctrl =
  9954. MISC_HOST_CTRL_MASK_PCI_INT |
  9955. MISC_HOST_CTRL_WORD_SWAP |
  9956. MISC_HOST_CTRL_INDIR_ACCESS |
  9957. MISC_HOST_CTRL_PCISTATE_RW;
  9958. /* The NONFRM (non-frame) byte/word swap controls take effect
  9959. * on descriptor entries, anything which isn't packet data.
  9960. *
  9961. * The StrongARM chips on the board (one for tx, one for rx)
  9962. * are running in big-endian mode.
  9963. */
  9964. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  9965. GRC_MODE_WSWAP_NONFRM_DATA);
  9966. #ifdef __BIG_ENDIAN
  9967. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  9968. #endif
  9969. spin_lock_init(&tp->lock);
  9970. spin_lock_init(&tp->indirect_lock);
  9971. INIT_WORK(&tp->reset_task, tg3_reset_task);
  9972. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  9973. if (tp->regs == 0UL) {
  9974. printk(KERN_ERR PFX "Cannot map device registers, "
  9975. "aborting.\n");
  9976. err = -ENOMEM;
  9977. goto err_out_free_dev;
  9978. }
  9979. tg3_init_link_config(tp);
  9980. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  9981. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  9982. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  9983. dev->open = tg3_open;
  9984. dev->stop = tg3_close;
  9985. dev->get_stats = tg3_get_stats;
  9986. dev->set_multicast_list = tg3_set_rx_mode;
  9987. dev->set_mac_address = tg3_set_mac_addr;
  9988. dev->do_ioctl = tg3_ioctl;
  9989. dev->tx_timeout = tg3_tx_timeout;
  9990. dev->poll = tg3_poll;
  9991. dev->ethtool_ops = &tg3_ethtool_ops;
  9992. dev->weight = 64;
  9993. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  9994. dev->change_mtu = tg3_change_mtu;
  9995. dev->irq = pdev->irq;
  9996. #ifdef CONFIG_NET_POLL_CONTROLLER
  9997. dev->poll_controller = tg3_poll_controller;
  9998. #endif
  9999. err = tg3_get_invariants(tp);
  10000. if (err) {
  10001. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10002. "aborting.\n");
  10003. goto err_out_iounmap;
  10004. }
  10005. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10006. * device behind the EPB cannot support DMA addresses > 40-bit.
  10007. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10008. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10009. * do DMA address check in tg3_start_xmit().
  10010. */
  10011. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10012. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10013. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10014. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10015. #ifdef CONFIG_HIGHMEM
  10016. dma_mask = DMA_64BIT_MASK;
  10017. #endif
  10018. } else
  10019. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10020. /* Configure DMA attributes. */
  10021. if (dma_mask > DMA_32BIT_MASK) {
  10022. err = pci_set_dma_mask(pdev, dma_mask);
  10023. if (!err) {
  10024. dev->features |= NETIF_F_HIGHDMA;
  10025. err = pci_set_consistent_dma_mask(pdev,
  10026. persist_dma_mask);
  10027. if (err < 0) {
  10028. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10029. "DMA for consistent allocations\n");
  10030. goto err_out_iounmap;
  10031. }
  10032. }
  10033. }
  10034. if (err || dma_mask == DMA_32BIT_MASK) {
  10035. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10036. if (err) {
  10037. printk(KERN_ERR PFX "No usable DMA configuration, "
  10038. "aborting.\n");
  10039. goto err_out_iounmap;
  10040. }
  10041. }
  10042. tg3_init_bufmgr_config(tp);
  10043. #if TG3_TSO_SUPPORT != 0
  10044. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10045. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10046. }
  10047. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10048. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10049. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10050. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10051. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10052. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10053. } else {
  10054. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10055. }
  10056. /* TSO is on by default on chips that support hardware TSO.
  10057. * Firmware TSO on older chips gives lower performance, so it
  10058. * is off by default, but can be enabled using ethtool.
  10059. */
  10060. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10061. dev->features |= NETIF_F_TSO;
  10062. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10063. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10064. dev->features |= NETIF_F_TSO6;
  10065. }
  10066. #endif
  10067. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10068. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10069. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10070. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10071. tp->rx_pending = 63;
  10072. }
  10073. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  10074. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  10075. tp->pdev_peer = tg3_find_peer(tp);
  10076. err = tg3_get_device_address(tp);
  10077. if (err) {
  10078. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10079. "aborting.\n");
  10080. goto err_out_iounmap;
  10081. }
  10082. /*
  10083. * Reset chip in case UNDI or EFI driver did not shutdown
  10084. * DMA self test will enable WDMAC and we'll see (spurious)
  10085. * pending DMA on the PCI bus at that point.
  10086. */
  10087. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10088. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10089. pci_save_state(tp->pdev);
  10090. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10091. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10092. }
  10093. err = tg3_test_dma(tp);
  10094. if (err) {
  10095. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10096. goto err_out_iounmap;
  10097. }
  10098. /* Tigon3 can do ipv4 only... and some chips have buggy
  10099. * checksumming.
  10100. */
  10101. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10102. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10103. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  10104. dev->features |= NETIF_F_HW_CSUM;
  10105. else
  10106. dev->features |= NETIF_F_IP_CSUM;
  10107. dev->features |= NETIF_F_SG;
  10108. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10109. } else
  10110. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10111. /* flow control autonegotiation is default behavior */
  10112. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10113. tg3_init_coal(tp);
  10114. /* Now that we have fully setup the chip, save away a snapshot
  10115. * of the PCI config space. We need to restore this after
  10116. * GRC_MISC_CFG core clock resets and some resume events.
  10117. */
  10118. pci_save_state(tp->pdev);
  10119. err = register_netdev(dev);
  10120. if (err) {
  10121. printk(KERN_ERR PFX "Cannot register net device, "
  10122. "aborting.\n");
  10123. goto err_out_iounmap;
  10124. }
  10125. pci_set_drvdata(pdev, dev);
  10126. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %sBaseT Ethernet ",
  10127. dev->name,
  10128. tp->board_part_number,
  10129. tp->pci_chip_rev_id,
  10130. tg3_phy_string(tp),
  10131. tg3_bus_string(tp, str),
  10132. (tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100" : "10/100/1000");
  10133. for (i = 0; i < 6; i++)
  10134. printk("%2.2x%c", dev->dev_addr[i],
  10135. i == 5 ? '\n' : ':');
  10136. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10137. "MIirq[%d] ASF[%d] Split[%d] WireSpeed[%d] "
  10138. "TSOcap[%d] \n",
  10139. dev->name,
  10140. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10141. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10142. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10143. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10144. (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0,
  10145. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10146. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10147. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10148. dev->name, tp->dma_rwctrl,
  10149. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10150. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10151. netif_carrier_off(tp->dev);
  10152. return 0;
  10153. err_out_iounmap:
  10154. if (tp->regs) {
  10155. iounmap(tp->regs);
  10156. tp->regs = NULL;
  10157. }
  10158. err_out_free_dev:
  10159. free_netdev(dev);
  10160. err_out_free_res:
  10161. pci_release_regions(pdev);
  10162. err_out_disable_pdev:
  10163. pci_disable_device(pdev);
  10164. pci_set_drvdata(pdev, NULL);
  10165. return err;
  10166. }
  10167. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10168. {
  10169. struct net_device *dev = pci_get_drvdata(pdev);
  10170. if (dev) {
  10171. struct tg3 *tp = netdev_priv(dev);
  10172. flush_scheduled_work();
  10173. unregister_netdev(dev);
  10174. if (tp->regs) {
  10175. iounmap(tp->regs);
  10176. tp->regs = NULL;
  10177. }
  10178. free_netdev(dev);
  10179. pci_release_regions(pdev);
  10180. pci_disable_device(pdev);
  10181. pci_set_drvdata(pdev, NULL);
  10182. }
  10183. }
  10184. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10185. {
  10186. struct net_device *dev = pci_get_drvdata(pdev);
  10187. struct tg3 *tp = netdev_priv(dev);
  10188. int err;
  10189. if (!netif_running(dev))
  10190. return 0;
  10191. flush_scheduled_work();
  10192. tg3_netif_stop(tp);
  10193. del_timer_sync(&tp->timer);
  10194. tg3_full_lock(tp, 1);
  10195. tg3_disable_ints(tp);
  10196. tg3_full_unlock(tp);
  10197. netif_device_detach(dev);
  10198. tg3_full_lock(tp, 0);
  10199. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10200. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  10201. tg3_full_unlock(tp);
  10202. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  10203. if (err) {
  10204. tg3_full_lock(tp, 0);
  10205. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10206. if (tg3_restart_hw(tp, 1))
  10207. goto out;
  10208. tp->timer.expires = jiffies + tp->timer_offset;
  10209. add_timer(&tp->timer);
  10210. netif_device_attach(dev);
  10211. tg3_netif_start(tp);
  10212. out:
  10213. tg3_full_unlock(tp);
  10214. }
  10215. return err;
  10216. }
  10217. static int tg3_resume(struct pci_dev *pdev)
  10218. {
  10219. struct net_device *dev = pci_get_drvdata(pdev);
  10220. struct tg3 *tp = netdev_priv(dev);
  10221. int err;
  10222. if (!netif_running(dev))
  10223. return 0;
  10224. pci_restore_state(tp->pdev);
  10225. err = tg3_set_power_state(tp, PCI_D0);
  10226. if (err)
  10227. return err;
  10228. netif_device_attach(dev);
  10229. tg3_full_lock(tp, 0);
  10230. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10231. err = tg3_restart_hw(tp, 1);
  10232. if (err)
  10233. goto out;
  10234. tp->timer.expires = jiffies + tp->timer_offset;
  10235. add_timer(&tp->timer);
  10236. tg3_netif_start(tp);
  10237. out:
  10238. tg3_full_unlock(tp);
  10239. return err;
  10240. }
  10241. static struct pci_driver tg3_driver = {
  10242. .name = DRV_MODULE_NAME,
  10243. .id_table = tg3_pci_tbl,
  10244. .probe = tg3_init_one,
  10245. .remove = __devexit_p(tg3_remove_one),
  10246. .suspend = tg3_suspend,
  10247. .resume = tg3_resume
  10248. };
  10249. static int __init tg3_init(void)
  10250. {
  10251. return pci_register_driver(&tg3_driver);
  10252. }
  10253. static void __exit tg3_cleanup(void)
  10254. {
  10255. pci_unregister_driver(&tg3_driver);
  10256. }
  10257. module_init(tg3_init);
  10258. module_exit(tg3_cleanup);