tg3.c 347 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136
  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-2007 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 <net/ip.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/byteorder.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_SPARC64
  46. #include <asm/idprom.h>
  47. #include <asm/oplib.h>
  48. #include <asm/pbm.h>
  49. #endif
  50. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  51. #define TG3_VLAN_TAG_USED 1
  52. #else
  53. #define TG3_VLAN_TAG_USED 0
  54. #endif
  55. #define TG3_TSO_SUPPORT 1
  56. #include "tg3.h"
  57. #define DRV_MODULE_NAME "tg3"
  58. #define PFX DRV_MODULE_NAME ": "
  59. #define DRV_MODULE_VERSION "3.75"
  60. #define DRV_MODULE_RELDATE "March 23, 2007"
  61. #define TG3_DEF_MAC_MODE 0
  62. #define TG3_DEF_RX_MODE 0
  63. #define TG3_DEF_TX_MODE 0
  64. #define TG3_DEF_MSG_ENABLE \
  65. (NETIF_MSG_DRV | \
  66. NETIF_MSG_PROBE | \
  67. NETIF_MSG_LINK | \
  68. NETIF_MSG_TIMER | \
  69. NETIF_MSG_IFDOWN | \
  70. NETIF_MSG_IFUP | \
  71. NETIF_MSG_RX_ERR | \
  72. NETIF_MSG_TX_ERR)
  73. /* length of time before we decide the hardware is borked,
  74. * and dev->tx_timeout() should be called to fix the problem
  75. */
  76. #define TG3_TX_TIMEOUT (5 * HZ)
  77. /* hardware minimum and maximum for a single frame's data payload */
  78. #define TG3_MIN_MTU 60
  79. #define TG3_MAX_MTU(tp) \
  80. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  81. /* These numbers seem to be hard coded in the NIC firmware somehow.
  82. * You can't change the ring sizes, but you can change where you place
  83. * them in the NIC onboard memory.
  84. */
  85. #define TG3_RX_RING_SIZE 512
  86. #define TG3_DEF_RX_RING_PENDING 200
  87. #define TG3_RX_JUMBO_RING_SIZE 256
  88. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  89. /* Do not place this n-ring entries value into the tp struct itself,
  90. * we really want to expose these constants to GCC so that modulo et
  91. * al. operations are done with shifts and masks instead of with
  92. * hw multiply/modulo instructions. Another solution would be to
  93. * replace things like '% foo' with '& (foo - 1)'.
  94. */
  95. #define TG3_RX_RCB_RING_SIZE(tp) \
  96. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  97. #define TG3_TX_RING_SIZE 512
  98. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  99. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  100. TG3_RX_RING_SIZE)
  101. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  102. TG3_RX_JUMBO_RING_SIZE)
  103. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  104. TG3_RX_RCB_RING_SIZE(tp))
  105. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  106. TG3_TX_RING_SIZE)
  107. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  108. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  109. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  110. /* minimum number of free TX descriptors required to wake up TX process */
  111. #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
  112. /* number of ETHTOOL_GSTATS u64's */
  113. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  114. #define TG3_NUM_TEST 6
  115. static char version[] __devinitdata =
  116. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  117. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  118. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  119. MODULE_LICENSE("GPL");
  120. MODULE_VERSION(DRV_MODULE_VERSION);
  121. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  122. module_param(tg3_debug, int, 0);
  123. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  124. static struct pci_device_id tg3_pci_tbl[] = {
  125. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  126. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  127. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  184. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  185. {}
  186. };
  187. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  188. static const struct {
  189. const char string[ETH_GSTRING_LEN];
  190. } ethtool_stats_keys[TG3_NUM_STATS] = {
  191. { "rx_octets" },
  192. { "rx_fragments" },
  193. { "rx_ucast_packets" },
  194. { "rx_mcast_packets" },
  195. { "rx_bcast_packets" },
  196. { "rx_fcs_errors" },
  197. { "rx_align_errors" },
  198. { "rx_xon_pause_rcvd" },
  199. { "rx_xoff_pause_rcvd" },
  200. { "rx_mac_ctrl_rcvd" },
  201. { "rx_xoff_entered" },
  202. { "rx_frame_too_long_errors" },
  203. { "rx_jabbers" },
  204. { "rx_undersize_packets" },
  205. { "rx_in_length_errors" },
  206. { "rx_out_length_errors" },
  207. { "rx_64_or_less_octet_packets" },
  208. { "rx_65_to_127_octet_packets" },
  209. { "rx_128_to_255_octet_packets" },
  210. { "rx_256_to_511_octet_packets" },
  211. { "rx_512_to_1023_octet_packets" },
  212. { "rx_1024_to_1522_octet_packets" },
  213. { "rx_1523_to_2047_octet_packets" },
  214. { "rx_2048_to_4095_octet_packets" },
  215. { "rx_4096_to_8191_octet_packets" },
  216. { "rx_8192_to_9022_octet_packets" },
  217. { "tx_octets" },
  218. { "tx_collisions" },
  219. { "tx_xon_sent" },
  220. { "tx_xoff_sent" },
  221. { "tx_flow_control" },
  222. { "tx_mac_errors" },
  223. { "tx_single_collisions" },
  224. { "tx_mult_collisions" },
  225. { "tx_deferred" },
  226. { "tx_excessive_collisions" },
  227. { "tx_late_collisions" },
  228. { "tx_collide_2times" },
  229. { "tx_collide_3times" },
  230. { "tx_collide_4times" },
  231. { "tx_collide_5times" },
  232. { "tx_collide_6times" },
  233. { "tx_collide_7times" },
  234. { "tx_collide_8times" },
  235. { "tx_collide_9times" },
  236. { "tx_collide_10times" },
  237. { "tx_collide_11times" },
  238. { "tx_collide_12times" },
  239. { "tx_collide_13times" },
  240. { "tx_collide_14times" },
  241. { "tx_collide_15times" },
  242. { "tx_ucast_packets" },
  243. { "tx_mcast_packets" },
  244. { "tx_bcast_packets" },
  245. { "tx_carrier_sense_errors" },
  246. { "tx_discards" },
  247. { "tx_errors" },
  248. { "dma_writeq_full" },
  249. { "dma_write_prioq_full" },
  250. { "rxbds_empty" },
  251. { "rx_discards" },
  252. { "rx_errors" },
  253. { "rx_threshold_hit" },
  254. { "dma_readq_full" },
  255. { "dma_read_prioq_full" },
  256. { "tx_comp_queue_full" },
  257. { "ring_set_send_prod_index" },
  258. { "ring_status_update" },
  259. { "nic_irqs" },
  260. { "nic_avoided_irqs" },
  261. { "nic_tx_threshold_hit" }
  262. };
  263. static const struct {
  264. const char string[ETH_GSTRING_LEN];
  265. } ethtool_test_keys[TG3_NUM_TEST] = {
  266. { "nvram test (online) " },
  267. { "link test (online) " },
  268. { "register test (offline)" },
  269. { "memory test (offline)" },
  270. { "loopback test (offline)" },
  271. { "interrupt test (offline)" },
  272. };
  273. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  274. {
  275. writel(val, tp->regs + off);
  276. }
  277. static u32 tg3_read32(struct tg3 *tp, u32 off)
  278. {
  279. return (readl(tp->regs + off));
  280. }
  281. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  282. {
  283. unsigned long flags;
  284. spin_lock_irqsave(&tp->indirect_lock, flags);
  285. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  286. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  287. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  288. }
  289. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  290. {
  291. writel(val, tp->regs + off);
  292. readl(tp->regs + off);
  293. }
  294. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  295. {
  296. unsigned long flags;
  297. u32 val;
  298. spin_lock_irqsave(&tp->indirect_lock, flags);
  299. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  300. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  301. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  302. return val;
  303. }
  304. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  305. {
  306. unsigned long flags;
  307. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  308. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  309. TG3_64BIT_REG_LOW, val);
  310. return;
  311. }
  312. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  313. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  314. TG3_64BIT_REG_LOW, val);
  315. return;
  316. }
  317. spin_lock_irqsave(&tp->indirect_lock, flags);
  318. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  319. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  320. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  321. /* In indirect mode when disabling interrupts, we also need
  322. * to clear the interrupt bit in the GRC local ctrl register.
  323. */
  324. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  325. (val == 0x1)) {
  326. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  327. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  328. }
  329. }
  330. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  331. {
  332. unsigned long flags;
  333. u32 val;
  334. spin_lock_irqsave(&tp->indirect_lock, flags);
  335. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  336. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  337. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  338. return val;
  339. }
  340. /* usec_wait specifies the wait time in usec when writing to certain registers
  341. * where it is unsafe to read back the register without some delay.
  342. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  343. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  344. */
  345. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  346. {
  347. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  348. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  349. /* Non-posted methods */
  350. tp->write32(tp, off, val);
  351. else {
  352. /* Posted method */
  353. tg3_write32(tp, off, val);
  354. if (usec_wait)
  355. udelay(usec_wait);
  356. tp->read32(tp, off);
  357. }
  358. /* Wait again after the read for the posted method to guarantee that
  359. * the wait time is met.
  360. */
  361. if (usec_wait)
  362. udelay(usec_wait);
  363. }
  364. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  365. {
  366. tp->write32_mbox(tp, off, val);
  367. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  368. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  369. tp->read32_mbox(tp, off);
  370. }
  371. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  372. {
  373. void __iomem *mbox = tp->regs + off;
  374. writel(val, mbox);
  375. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  376. writel(val, mbox);
  377. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  378. readl(mbox);
  379. }
  380. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  381. {
  382. return (readl(tp->regs + off + GRCMBOX_BASE));
  383. }
  384. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  385. {
  386. writel(val, tp->regs + off + GRCMBOX_BASE);
  387. }
  388. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  389. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  390. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  391. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  392. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  393. #define tw32(reg,val) tp->write32(tp, reg, val)
  394. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  395. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  396. #define tr32(reg) tp->read32(tp, reg)
  397. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  398. {
  399. unsigned long flags;
  400. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  401. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  402. return;
  403. spin_lock_irqsave(&tp->indirect_lock, flags);
  404. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  405. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  406. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  407. /* Always leave this as zero. */
  408. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  409. } else {
  410. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  411. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  412. /* Always leave this as zero. */
  413. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  414. }
  415. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  416. }
  417. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  418. {
  419. unsigned long flags;
  420. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  421. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  422. *val = 0;
  423. return;
  424. }
  425. spin_lock_irqsave(&tp->indirect_lock, flags);
  426. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  427. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  428. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  429. /* Always leave this as zero. */
  430. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  431. } else {
  432. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  433. *val = tr32(TG3PCI_MEM_WIN_DATA);
  434. /* Always leave this as zero. */
  435. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  436. }
  437. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  438. }
  439. static void tg3_disable_ints(struct tg3 *tp)
  440. {
  441. tw32(TG3PCI_MISC_HOST_CTRL,
  442. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  443. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  444. }
  445. static inline void tg3_cond_int(struct tg3 *tp)
  446. {
  447. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  448. (tp->hw_status->status & SD_STATUS_UPDATED))
  449. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  450. else
  451. tw32(HOSTCC_MODE, tp->coalesce_mode |
  452. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  453. }
  454. static void tg3_enable_ints(struct tg3 *tp)
  455. {
  456. tp->irq_sync = 0;
  457. wmb();
  458. tw32(TG3PCI_MISC_HOST_CTRL,
  459. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  460. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  461. (tp->last_tag << 24));
  462. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  463. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  464. (tp->last_tag << 24));
  465. tg3_cond_int(tp);
  466. }
  467. static inline unsigned int tg3_has_work(struct tg3 *tp)
  468. {
  469. struct tg3_hw_status *sblk = tp->hw_status;
  470. unsigned int work_exists = 0;
  471. /* check for phy events */
  472. if (!(tp->tg3_flags &
  473. (TG3_FLAG_USE_LINKCHG_REG |
  474. TG3_FLAG_POLL_SERDES))) {
  475. if (sblk->status & SD_STATUS_LINK_CHG)
  476. work_exists = 1;
  477. }
  478. /* check for RX/TX work to do */
  479. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  480. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  481. work_exists = 1;
  482. return work_exists;
  483. }
  484. /* tg3_restart_ints
  485. * similar to tg3_enable_ints, but it accurately determines whether there
  486. * is new work pending and can return without flushing the PIO write
  487. * which reenables interrupts
  488. */
  489. static void tg3_restart_ints(struct tg3 *tp)
  490. {
  491. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  492. tp->last_tag << 24);
  493. mmiowb();
  494. /* When doing tagged status, this work check is unnecessary.
  495. * The last_tag we write above tells the chip which piece of
  496. * work we've completed.
  497. */
  498. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  499. tg3_has_work(tp))
  500. tw32(HOSTCC_MODE, tp->coalesce_mode |
  501. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  502. }
  503. static inline void tg3_netif_stop(struct tg3 *tp)
  504. {
  505. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  506. netif_poll_disable(tp->dev);
  507. netif_tx_disable(tp->dev);
  508. }
  509. static inline void tg3_netif_start(struct tg3 *tp)
  510. {
  511. netif_wake_queue(tp->dev);
  512. /* NOTE: unconditional netif_wake_queue is only appropriate
  513. * so long as all callers are assured to have free tx slots
  514. * (such as after tg3_init_hw)
  515. */
  516. netif_poll_enable(tp->dev);
  517. tp->hw_status->status |= SD_STATUS_UPDATED;
  518. tg3_enable_ints(tp);
  519. }
  520. static void tg3_switch_clocks(struct tg3 *tp)
  521. {
  522. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  523. u32 orig_clock_ctrl;
  524. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  525. return;
  526. orig_clock_ctrl = clock_ctrl;
  527. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  528. CLOCK_CTRL_CLKRUN_OENABLE |
  529. 0x1f);
  530. tp->pci_clock_ctrl = clock_ctrl;
  531. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  532. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  533. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  534. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  535. }
  536. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  537. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  538. clock_ctrl |
  539. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  540. 40);
  541. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  542. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  543. 40);
  544. }
  545. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  546. }
  547. #define PHY_BUSY_LOOPS 5000
  548. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  549. {
  550. u32 frame_val;
  551. unsigned int loops;
  552. int ret;
  553. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  554. tw32_f(MAC_MI_MODE,
  555. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  556. udelay(80);
  557. }
  558. *val = 0x0;
  559. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  560. MI_COM_PHY_ADDR_MASK);
  561. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  562. MI_COM_REG_ADDR_MASK);
  563. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  564. tw32_f(MAC_MI_COM, frame_val);
  565. loops = PHY_BUSY_LOOPS;
  566. while (loops != 0) {
  567. udelay(10);
  568. frame_val = tr32(MAC_MI_COM);
  569. if ((frame_val & MI_COM_BUSY) == 0) {
  570. udelay(5);
  571. frame_val = tr32(MAC_MI_COM);
  572. break;
  573. }
  574. loops -= 1;
  575. }
  576. ret = -EBUSY;
  577. if (loops != 0) {
  578. *val = frame_val & MI_COM_DATA_MASK;
  579. ret = 0;
  580. }
  581. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  582. tw32_f(MAC_MI_MODE, tp->mi_mode);
  583. udelay(80);
  584. }
  585. return ret;
  586. }
  587. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  588. {
  589. u32 frame_val;
  590. unsigned int loops;
  591. int ret;
  592. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  593. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  594. return 0;
  595. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  596. tw32_f(MAC_MI_MODE,
  597. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  598. udelay(80);
  599. }
  600. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  601. MI_COM_PHY_ADDR_MASK);
  602. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  603. MI_COM_REG_ADDR_MASK);
  604. frame_val |= (val & MI_COM_DATA_MASK);
  605. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  606. tw32_f(MAC_MI_COM, frame_val);
  607. loops = PHY_BUSY_LOOPS;
  608. while (loops != 0) {
  609. udelay(10);
  610. frame_val = tr32(MAC_MI_COM);
  611. if ((frame_val & MI_COM_BUSY) == 0) {
  612. udelay(5);
  613. frame_val = tr32(MAC_MI_COM);
  614. break;
  615. }
  616. loops -= 1;
  617. }
  618. ret = -EBUSY;
  619. if (loops != 0)
  620. ret = 0;
  621. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  622. tw32_f(MAC_MI_MODE, tp->mi_mode);
  623. udelay(80);
  624. }
  625. return ret;
  626. }
  627. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  628. {
  629. u32 val;
  630. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  631. return;
  632. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  633. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  634. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  635. (val | (1 << 15) | (1 << 4)));
  636. }
  637. static int tg3_bmcr_reset(struct tg3 *tp)
  638. {
  639. u32 phy_control;
  640. int limit, err;
  641. /* OK, reset it, and poll the BMCR_RESET bit until it
  642. * clears or we time out.
  643. */
  644. phy_control = BMCR_RESET;
  645. err = tg3_writephy(tp, MII_BMCR, phy_control);
  646. if (err != 0)
  647. return -EBUSY;
  648. limit = 5000;
  649. while (limit--) {
  650. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  651. if (err != 0)
  652. return -EBUSY;
  653. if ((phy_control & BMCR_RESET) == 0) {
  654. udelay(40);
  655. break;
  656. }
  657. udelay(10);
  658. }
  659. if (limit <= 0)
  660. return -EBUSY;
  661. return 0;
  662. }
  663. static int tg3_wait_macro_done(struct tg3 *tp)
  664. {
  665. int limit = 100;
  666. while (limit--) {
  667. u32 tmp32;
  668. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  669. if ((tmp32 & 0x1000) == 0)
  670. break;
  671. }
  672. }
  673. if (limit <= 0)
  674. return -EBUSY;
  675. return 0;
  676. }
  677. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  678. {
  679. static const u32 test_pat[4][6] = {
  680. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  681. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  682. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  683. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  684. };
  685. int chan;
  686. for (chan = 0; chan < 4; chan++) {
  687. int i;
  688. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  689. (chan * 0x2000) | 0x0200);
  690. tg3_writephy(tp, 0x16, 0x0002);
  691. for (i = 0; i < 6; i++)
  692. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  693. test_pat[chan][i]);
  694. tg3_writephy(tp, 0x16, 0x0202);
  695. if (tg3_wait_macro_done(tp)) {
  696. *resetp = 1;
  697. return -EBUSY;
  698. }
  699. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  700. (chan * 0x2000) | 0x0200);
  701. tg3_writephy(tp, 0x16, 0x0082);
  702. if (tg3_wait_macro_done(tp)) {
  703. *resetp = 1;
  704. return -EBUSY;
  705. }
  706. tg3_writephy(tp, 0x16, 0x0802);
  707. if (tg3_wait_macro_done(tp)) {
  708. *resetp = 1;
  709. return -EBUSY;
  710. }
  711. for (i = 0; i < 6; i += 2) {
  712. u32 low, high;
  713. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  714. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  715. tg3_wait_macro_done(tp)) {
  716. *resetp = 1;
  717. return -EBUSY;
  718. }
  719. low &= 0x7fff;
  720. high &= 0x000f;
  721. if (low != test_pat[chan][i] ||
  722. high != test_pat[chan][i+1]) {
  723. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  724. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  725. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  726. return -EBUSY;
  727. }
  728. }
  729. }
  730. return 0;
  731. }
  732. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  733. {
  734. int chan;
  735. for (chan = 0; chan < 4; chan++) {
  736. int i;
  737. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  738. (chan * 0x2000) | 0x0200);
  739. tg3_writephy(tp, 0x16, 0x0002);
  740. for (i = 0; i < 6; i++)
  741. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  742. tg3_writephy(tp, 0x16, 0x0202);
  743. if (tg3_wait_macro_done(tp))
  744. return -EBUSY;
  745. }
  746. return 0;
  747. }
  748. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  749. {
  750. u32 reg32, phy9_orig;
  751. int retries, do_phy_reset, err;
  752. retries = 10;
  753. do_phy_reset = 1;
  754. do {
  755. if (do_phy_reset) {
  756. err = tg3_bmcr_reset(tp);
  757. if (err)
  758. return err;
  759. do_phy_reset = 0;
  760. }
  761. /* Disable transmitter and interrupt. */
  762. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  763. continue;
  764. reg32 |= 0x3000;
  765. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  766. /* Set full-duplex, 1000 mbps. */
  767. tg3_writephy(tp, MII_BMCR,
  768. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  769. /* Set to master mode. */
  770. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  771. continue;
  772. tg3_writephy(tp, MII_TG3_CTRL,
  773. (MII_TG3_CTRL_AS_MASTER |
  774. MII_TG3_CTRL_ENABLE_AS_MASTER));
  775. /* Enable SM_DSP_CLOCK and 6dB. */
  776. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  777. /* Block the PHY control access. */
  778. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  779. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  780. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  781. if (!err)
  782. break;
  783. } while (--retries);
  784. err = tg3_phy_reset_chanpat(tp);
  785. if (err)
  786. return err;
  787. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  788. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  789. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  790. tg3_writephy(tp, 0x16, 0x0000);
  791. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  792. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  793. /* Set Extended packet length bit for jumbo frames */
  794. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  795. }
  796. else {
  797. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  798. }
  799. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  800. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  801. reg32 &= ~0x3000;
  802. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  803. } else if (!err)
  804. err = -EBUSY;
  805. return err;
  806. }
  807. static void tg3_link_report(struct tg3 *);
  808. /* This will reset the tigon3 PHY if there is no valid
  809. * link unless the FORCE argument is non-zero.
  810. */
  811. static int tg3_phy_reset(struct tg3 *tp)
  812. {
  813. u32 phy_status;
  814. int err;
  815. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  816. u32 val;
  817. val = tr32(GRC_MISC_CFG);
  818. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  819. udelay(40);
  820. }
  821. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  822. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  823. if (err != 0)
  824. return -EBUSY;
  825. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  826. netif_carrier_off(tp->dev);
  827. tg3_link_report(tp);
  828. }
  829. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  830. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  831. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  832. err = tg3_phy_reset_5703_4_5(tp);
  833. if (err)
  834. return err;
  835. goto out;
  836. }
  837. err = tg3_bmcr_reset(tp);
  838. if (err)
  839. return err;
  840. out:
  841. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  842. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  843. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  844. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  845. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  846. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  847. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  848. }
  849. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  850. tg3_writephy(tp, 0x1c, 0x8d68);
  851. tg3_writephy(tp, 0x1c, 0x8d68);
  852. }
  853. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  854. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  855. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  856. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  857. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  858. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  859. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  860. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  861. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  862. }
  863. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  864. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  865. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  866. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  867. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  868. tg3_writephy(tp, MII_TG3_TEST1,
  869. MII_TG3_TEST1_TRIM_EN | 0x4);
  870. } else
  871. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  872. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  873. }
  874. /* Set Extended packet length bit (bit 14) on all chips that */
  875. /* support jumbo frames */
  876. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  877. /* Cannot do read-modify-write on 5401 */
  878. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  879. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  880. u32 phy_reg;
  881. /* Set bit 14 with read-modify-write to preserve other bits */
  882. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  883. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  884. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  885. }
  886. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  887. * jumbo frames transmission.
  888. */
  889. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  890. u32 phy_reg;
  891. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  892. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  893. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  894. }
  895. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  896. u32 phy_reg;
  897. /* adjust output voltage */
  898. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  899. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
  900. u32 phy_reg2;
  901. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  902. phy_reg | MII_TG3_EPHY_SHADOW_EN);
  903. /* Enable auto-MDIX */
  904. if (!tg3_readphy(tp, 0x10, &phy_reg2))
  905. tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
  906. tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
  907. }
  908. }
  909. tg3_phy_set_wirespeed(tp);
  910. return 0;
  911. }
  912. static void tg3_frob_aux_power(struct tg3 *tp)
  913. {
  914. struct tg3 *tp_peer = tp;
  915. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  916. return;
  917. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  918. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  919. struct net_device *dev_peer;
  920. dev_peer = pci_get_drvdata(tp->pdev_peer);
  921. /* remove_one() may have been run on the peer. */
  922. if (!dev_peer)
  923. tp_peer = tp;
  924. else
  925. tp_peer = netdev_priv(dev_peer);
  926. }
  927. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  928. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  929. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  930. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  931. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  932. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  933. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  934. (GRC_LCLCTRL_GPIO_OE0 |
  935. GRC_LCLCTRL_GPIO_OE1 |
  936. GRC_LCLCTRL_GPIO_OE2 |
  937. GRC_LCLCTRL_GPIO_OUTPUT0 |
  938. GRC_LCLCTRL_GPIO_OUTPUT1),
  939. 100);
  940. } else {
  941. u32 no_gpio2;
  942. u32 grc_local_ctrl = 0;
  943. if (tp_peer != tp &&
  944. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  945. return;
  946. /* Workaround to prevent overdrawing Amps. */
  947. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  948. ASIC_REV_5714) {
  949. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  950. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  951. grc_local_ctrl, 100);
  952. }
  953. /* On 5753 and variants, GPIO2 cannot be used. */
  954. no_gpio2 = tp->nic_sram_data_cfg &
  955. NIC_SRAM_DATA_CFG_NO_GPIO2;
  956. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  957. GRC_LCLCTRL_GPIO_OE1 |
  958. GRC_LCLCTRL_GPIO_OE2 |
  959. GRC_LCLCTRL_GPIO_OUTPUT1 |
  960. GRC_LCLCTRL_GPIO_OUTPUT2;
  961. if (no_gpio2) {
  962. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  963. GRC_LCLCTRL_GPIO_OUTPUT2);
  964. }
  965. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  966. grc_local_ctrl, 100);
  967. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  968. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  969. grc_local_ctrl, 100);
  970. if (!no_gpio2) {
  971. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  972. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  973. grc_local_ctrl, 100);
  974. }
  975. }
  976. } else {
  977. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  978. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  979. if (tp_peer != tp &&
  980. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  981. return;
  982. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  983. (GRC_LCLCTRL_GPIO_OE1 |
  984. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  985. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  986. GRC_LCLCTRL_GPIO_OE1, 100);
  987. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  988. (GRC_LCLCTRL_GPIO_OE1 |
  989. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  990. }
  991. }
  992. }
  993. static int tg3_setup_phy(struct tg3 *, int);
  994. #define RESET_KIND_SHUTDOWN 0
  995. #define RESET_KIND_INIT 1
  996. #define RESET_KIND_SUSPEND 2
  997. static void tg3_write_sig_post_reset(struct tg3 *, int);
  998. static int tg3_halt_cpu(struct tg3 *, u32);
  999. static int tg3_nvram_lock(struct tg3 *);
  1000. static void tg3_nvram_unlock(struct tg3 *);
  1001. static void tg3_power_down_phy(struct tg3 *tp)
  1002. {
  1003. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1004. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1005. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1006. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1007. sg_dig_ctrl |=
  1008. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1009. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1010. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1011. }
  1012. return;
  1013. }
  1014. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1015. u32 val;
  1016. tg3_bmcr_reset(tp);
  1017. val = tr32(GRC_MISC_CFG);
  1018. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1019. udelay(40);
  1020. return;
  1021. } else {
  1022. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1023. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1024. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1025. }
  1026. /* The PHY should not be powered down on some chips because
  1027. * of bugs.
  1028. */
  1029. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1030. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1031. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1032. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1033. return;
  1034. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1035. }
  1036. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1037. {
  1038. u32 misc_host_ctrl;
  1039. u16 power_control, power_caps;
  1040. int pm = tp->pm_cap;
  1041. /* Make sure register accesses (indirect or otherwise)
  1042. * will function correctly.
  1043. */
  1044. pci_write_config_dword(tp->pdev,
  1045. TG3PCI_MISC_HOST_CTRL,
  1046. tp->misc_host_ctrl);
  1047. pci_read_config_word(tp->pdev,
  1048. pm + PCI_PM_CTRL,
  1049. &power_control);
  1050. power_control |= PCI_PM_CTRL_PME_STATUS;
  1051. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1052. switch (state) {
  1053. case PCI_D0:
  1054. power_control |= 0;
  1055. pci_write_config_word(tp->pdev,
  1056. pm + PCI_PM_CTRL,
  1057. power_control);
  1058. udelay(100); /* Delay after power state change */
  1059. /* Switch out of Vaux if it is a NIC */
  1060. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1061. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1062. return 0;
  1063. case PCI_D1:
  1064. power_control |= 1;
  1065. break;
  1066. case PCI_D2:
  1067. power_control |= 2;
  1068. break;
  1069. case PCI_D3hot:
  1070. power_control |= 3;
  1071. break;
  1072. default:
  1073. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1074. "requested.\n",
  1075. tp->dev->name, state);
  1076. return -EINVAL;
  1077. };
  1078. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1079. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1080. tw32(TG3PCI_MISC_HOST_CTRL,
  1081. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1082. if (tp->link_config.phy_is_low_power == 0) {
  1083. tp->link_config.phy_is_low_power = 1;
  1084. tp->link_config.orig_speed = tp->link_config.speed;
  1085. tp->link_config.orig_duplex = tp->link_config.duplex;
  1086. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1087. }
  1088. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1089. tp->link_config.speed = SPEED_10;
  1090. tp->link_config.duplex = DUPLEX_HALF;
  1091. tp->link_config.autoneg = AUTONEG_ENABLE;
  1092. tg3_setup_phy(tp, 0);
  1093. }
  1094. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1095. u32 val;
  1096. val = tr32(GRC_VCPU_EXT_CTRL);
  1097. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1098. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1099. int i;
  1100. u32 val;
  1101. for (i = 0; i < 200; i++) {
  1102. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1103. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1104. break;
  1105. msleep(1);
  1106. }
  1107. }
  1108. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1109. WOL_DRV_STATE_SHUTDOWN |
  1110. WOL_DRV_WOL | WOL_SET_MAGIC_PKT);
  1111. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1112. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1113. u32 mac_mode;
  1114. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1115. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1116. udelay(40);
  1117. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1118. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1119. else
  1120. mac_mode = MAC_MODE_PORT_MODE_MII;
  1121. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
  1122. !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
  1123. mac_mode |= MAC_MODE_LINK_POLARITY;
  1124. } else {
  1125. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1126. }
  1127. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1128. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1129. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1130. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1131. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1132. tw32_f(MAC_MODE, mac_mode);
  1133. udelay(100);
  1134. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1135. udelay(10);
  1136. }
  1137. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1138. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1139. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1140. u32 base_val;
  1141. base_val = tp->pci_clock_ctrl;
  1142. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1143. CLOCK_CTRL_TXCLK_DISABLE);
  1144. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1145. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1146. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1147. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1148. /* do nothing */
  1149. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1150. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1151. u32 newbits1, newbits2;
  1152. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1153. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1154. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1155. CLOCK_CTRL_TXCLK_DISABLE |
  1156. CLOCK_CTRL_ALTCLK);
  1157. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1158. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1159. newbits1 = CLOCK_CTRL_625_CORE;
  1160. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1161. } else {
  1162. newbits1 = CLOCK_CTRL_ALTCLK;
  1163. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1164. }
  1165. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1166. 40);
  1167. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1168. 40);
  1169. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1170. u32 newbits3;
  1171. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1172. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1173. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1174. CLOCK_CTRL_TXCLK_DISABLE |
  1175. CLOCK_CTRL_44MHZ_CORE);
  1176. } else {
  1177. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1178. }
  1179. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1180. tp->pci_clock_ctrl | newbits3, 40);
  1181. }
  1182. }
  1183. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1184. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  1185. tg3_power_down_phy(tp);
  1186. tg3_frob_aux_power(tp);
  1187. /* Workaround for unstable PLL clock */
  1188. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1189. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1190. u32 val = tr32(0x7d00);
  1191. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1192. tw32(0x7d00, val);
  1193. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1194. int err;
  1195. err = tg3_nvram_lock(tp);
  1196. tg3_halt_cpu(tp, RX_CPU_BASE);
  1197. if (!err)
  1198. tg3_nvram_unlock(tp);
  1199. }
  1200. }
  1201. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1202. /* Finally, set the new power state. */
  1203. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1204. udelay(100); /* Delay after power state change */
  1205. return 0;
  1206. }
  1207. static void tg3_link_report(struct tg3 *tp)
  1208. {
  1209. if (!netif_carrier_ok(tp->dev)) {
  1210. if (netif_msg_link(tp))
  1211. printk(KERN_INFO PFX "%s: Link is down.\n",
  1212. tp->dev->name);
  1213. } else if (netif_msg_link(tp)) {
  1214. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1215. tp->dev->name,
  1216. (tp->link_config.active_speed == SPEED_1000 ?
  1217. 1000 :
  1218. (tp->link_config.active_speed == SPEED_100 ?
  1219. 100 : 10)),
  1220. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1221. "full" : "half"));
  1222. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1223. "%s for RX.\n",
  1224. tp->dev->name,
  1225. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1226. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1227. }
  1228. }
  1229. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1230. {
  1231. u32 new_tg3_flags = 0;
  1232. u32 old_rx_mode = tp->rx_mode;
  1233. u32 old_tx_mode = tp->tx_mode;
  1234. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1235. /* Convert 1000BaseX flow control bits to 1000BaseT
  1236. * bits before resolving flow control.
  1237. */
  1238. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1239. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1240. ADVERTISE_PAUSE_ASYM);
  1241. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1242. if (local_adv & ADVERTISE_1000XPAUSE)
  1243. local_adv |= ADVERTISE_PAUSE_CAP;
  1244. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1245. local_adv |= ADVERTISE_PAUSE_ASYM;
  1246. if (remote_adv & LPA_1000XPAUSE)
  1247. remote_adv |= LPA_PAUSE_CAP;
  1248. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1249. remote_adv |= LPA_PAUSE_ASYM;
  1250. }
  1251. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1252. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1253. if (remote_adv & LPA_PAUSE_CAP)
  1254. new_tg3_flags |=
  1255. (TG3_FLAG_RX_PAUSE |
  1256. TG3_FLAG_TX_PAUSE);
  1257. else if (remote_adv & LPA_PAUSE_ASYM)
  1258. new_tg3_flags |=
  1259. (TG3_FLAG_RX_PAUSE);
  1260. } else {
  1261. if (remote_adv & LPA_PAUSE_CAP)
  1262. new_tg3_flags |=
  1263. (TG3_FLAG_RX_PAUSE |
  1264. TG3_FLAG_TX_PAUSE);
  1265. }
  1266. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1267. if ((remote_adv & LPA_PAUSE_CAP) &&
  1268. (remote_adv & LPA_PAUSE_ASYM))
  1269. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1270. }
  1271. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1272. tp->tg3_flags |= new_tg3_flags;
  1273. } else {
  1274. new_tg3_flags = tp->tg3_flags;
  1275. }
  1276. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1277. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1278. else
  1279. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1280. if (old_rx_mode != tp->rx_mode) {
  1281. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1282. }
  1283. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1284. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1285. else
  1286. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1287. if (old_tx_mode != tp->tx_mode) {
  1288. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1289. }
  1290. }
  1291. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1292. {
  1293. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1294. case MII_TG3_AUX_STAT_10HALF:
  1295. *speed = SPEED_10;
  1296. *duplex = DUPLEX_HALF;
  1297. break;
  1298. case MII_TG3_AUX_STAT_10FULL:
  1299. *speed = SPEED_10;
  1300. *duplex = DUPLEX_FULL;
  1301. break;
  1302. case MII_TG3_AUX_STAT_100HALF:
  1303. *speed = SPEED_100;
  1304. *duplex = DUPLEX_HALF;
  1305. break;
  1306. case MII_TG3_AUX_STAT_100FULL:
  1307. *speed = SPEED_100;
  1308. *duplex = DUPLEX_FULL;
  1309. break;
  1310. case MII_TG3_AUX_STAT_1000HALF:
  1311. *speed = SPEED_1000;
  1312. *duplex = DUPLEX_HALF;
  1313. break;
  1314. case MII_TG3_AUX_STAT_1000FULL:
  1315. *speed = SPEED_1000;
  1316. *duplex = DUPLEX_FULL;
  1317. break;
  1318. default:
  1319. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1320. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1321. SPEED_10;
  1322. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1323. DUPLEX_HALF;
  1324. break;
  1325. }
  1326. *speed = SPEED_INVALID;
  1327. *duplex = DUPLEX_INVALID;
  1328. break;
  1329. };
  1330. }
  1331. static void tg3_phy_copper_begin(struct tg3 *tp)
  1332. {
  1333. u32 new_adv;
  1334. int i;
  1335. if (tp->link_config.phy_is_low_power) {
  1336. /* Entering low power mode. Disable gigabit and
  1337. * 100baseT advertisements.
  1338. */
  1339. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1340. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1341. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1342. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1343. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1344. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1345. } else if (tp->link_config.speed == SPEED_INVALID) {
  1346. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1347. tp->link_config.advertising &=
  1348. ~(ADVERTISED_1000baseT_Half |
  1349. ADVERTISED_1000baseT_Full);
  1350. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1351. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1352. new_adv |= ADVERTISE_10HALF;
  1353. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1354. new_adv |= ADVERTISE_10FULL;
  1355. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1356. new_adv |= ADVERTISE_100HALF;
  1357. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1358. new_adv |= ADVERTISE_100FULL;
  1359. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1360. if (tp->link_config.advertising &
  1361. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1362. new_adv = 0;
  1363. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1364. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1365. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1366. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1367. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1368. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1369. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1370. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1371. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1372. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1373. } else {
  1374. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1375. }
  1376. } else {
  1377. /* Asking for a specific link mode. */
  1378. if (tp->link_config.speed == SPEED_1000) {
  1379. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1380. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1381. if (tp->link_config.duplex == DUPLEX_FULL)
  1382. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1383. else
  1384. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1385. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1386. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1387. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1388. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1389. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1390. } else {
  1391. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1392. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1393. if (tp->link_config.speed == SPEED_100) {
  1394. if (tp->link_config.duplex == DUPLEX_FULL)
  1395. new_adv |= ADVERTISE_100FULL;
  1396. else
  1397. new_adv |= ADVERTISE_100HALF;
  1398. } else {
  1399. if (tp->link_config.duplex == DUPLEX_FULL)
  1400. new_adv |= ADVERTISE_10FULL;
  1401. else
  1402. new_adv |= ADVERTISE_10HALF;
  1403. }
  1404. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1405. }
  1406. }
  1407. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1408. tp->link_config.speed != SPEED_INVALID) {
  1409. u32 bmcr, orig_bmcr;
  1410. tp->link_config.active_speed = tp->link_config.speed;
  1411. tp->link_config.active_duplex = tp->link_config.duplex;
  1412. bmcr = 0;
  1413. switch (tp->link_config.speed) {
  1414. default:
  1415. case SPEED_10:
  1416. break;
  1417. case SPEED_100:
  1418. bmcr |= BMCR_SPEED100;
  1419. break;
  1420. case SPEED_1000:
  1421. bmcr |= TG3_BMCR_SPEED1000;
  1422. break;
  1423. };
  1424. if (tp->link_config.duplex == DUPLEX_FULL)
  1425. bmcr |= BMCR_FULLDPLX;
  1426. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1427. (bmcr != orig_bmcr)) {
  1428. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1429. for (i = 0; i < 1500; i++) {
  1430. u32 tmp;
  1431. udelay(10);
  1432. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1433. tg3_readphy(tp, MII_BMSR, &tmp))
  1434. continue;
  1435. if (!(tmp & BMSR_LSTATUS)) {
  1436. udelay(40);
  1437. break;
  1438. }
  1439. }
  1440. tg3_writephy(tp, MII_BMCR, bmcr);
  1441. udelay(40);
  1442. }
  1443. } else {
  1444. tg3_writephy(tp, MII_BMCR,
  1445. BMCR_ANENABLE | BMCR_ANRESTART);
  1446. }
  1447. }
  1448. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1449. {
  1450. int err;
  1451. /* Turn off tap power management. */
  1452. /* Set Extended packet length bit */
  1453. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1454. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1455. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1456. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1457. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1458. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1459. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1460. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1461. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1462. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1463. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1464. udelay(40);
  1465. return err;
  1466. }
  1467. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1468. {
  1469. u32 adv_reg, all_mask = 0;
  1470. if (mask & ADVERTISED_10baseT_Half)
  1471. all_mask |= ADVERTISE_10HALF;
  1472. if (mask & ADVERTISED_10baseT_Full)
  1473. all_mask |= ADVERTISE_10FULL;
  1474. if (mask & ADVERTISED_100baseT_Half)
  1475. all_mask |= ADVERTISE_100HALF;
  1476. if (mask & ADVERTISED_100baseT_Full)
  1477. all_mask |= ADVERTISE_100FULL;
  1478. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1479. return 0;
  1480. if ((adv_reg & all_mask) != all_mask)
  1481. return 0;
  1482. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1483. u32 tg3_ctrl;
  1484. all_mask = 0;
  1485. if (mask & ADVERTISED_1000baseT_Half)
  1486. all_mask |= ADVERTISE_1000HALF;
  1487. if (mask & ADVERTISED_1000baseT_Full)
  1488. all_mask |= ADVERTISE_1000FULL;
  1489. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1490. return 0;
  1491. if ((tg3_ctrl & all_mask) != all_mask)
  1492. return 0;
  1493. }
  1494. return 1;
  1495. }
  1496. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1497. {
  1498. int current_link_up;
  1499. u32 bmsr, dummy;
  1500. u16 current_speed;
  1501. u8 current_duplex;
  1502. int i, err;
  1503. tw32(MAC_EVENT, 0);
  1504. tw32_f(MAC_STATUS,
  1505. (MAC_STATUS_SYNC_CHANGED |
  1506. MAC_STATUS_CFG_CHANGED |
  1507. MAC_STATUS_MI_COMPLETION |
  1508. MAC_STATUS_LNKSTATE_CHANGED));
  1509. udelay(40);
  1510. tp->mi_mode = MAC_MI_MODE_BASE;
  1511. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1512. udelay(80);
  1513. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1514. /* Some third-party PHYs need to be reset on link going
  1515. * down.
  1516. */
  1517. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1518. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1519. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1520. netif_carrier_ok(tp->dev)) {
  1521. tg3_readphy(tp, MII_BMSR, &bmsr);
  1522. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1523. !(bmsr & BMSR_LSTATUS))
  1524. force_reset = 1;
  1525. }
  1526. if (force_reset)
  1527. tg3_phy_reset(tp);
  1528. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1529. tg3_readphy(tp, MII_BMSR, &bmsr);
  1530. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1531. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1532. bmsr = 0;
  1533. if (!(bmsr & BMSR_LSTATUS)) {
  1534. err = tg3_init_5401phy_dsp(tp);
  1535. if (err)
  1536. return err;
  1537. tg3_readphy(tp, MII_BMSR, &bmsr);
  1538. for (i = 0; i < 1000; i++) {
  1539. udelay(10);
  1540. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1541. (bmsr & BMSR_LSTATUS)) {
  1542. udelay(40);
  1543. break;
  1544. }
  1545. }
  1546. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1547. !(bmsr & BMSR_LSTATUS) &&
  1548. tp->link_config.active_speed == SPEED_1000) {
  1549. err = tg3_phy_reset(tp);
  1550. if (!err)
  1551. err = tg3_init_5401phy_dsp(tp);
  1552. if (err)
  1553. return err;
  1554. }
  1555. }
  1556. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1557. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1558. /* 5701 {A0,B0} CRC bug workaround */
  1559. tg3_writephy(tp, 0x15, 0x0a75);
  1560. tg3_writephy(tp, 0x1c, 0x8c68);
  1561. tg3_writephy(tp, 0x1c, 0x8d68);
  1562. tg3_writephy(tp, 0x1c, 0x8c68);
  1563. }
  1564. /* Clear pending interrupts... */
  1565. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1566. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1567. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1568. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1569. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1570. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1571. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1572. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1573. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1574. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1575. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1576. else
  1577. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1578. }
  1579. current_link_up = 0;
  1580. current_speed = SPEED_INVALID;
  1581. current_duplex = DUPLEX_INVALID;
  1582. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1583. u32 val;
  1584. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1585. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1586. if (!(val & (1 << 10))) {
  1587. val |= (1 << 10);
  1588. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1589. goto relink;
  1590. }
  1591. }
  1592. bmsr = 0;
  1593. for (i = 0; i < 100; i++) {
  1594. tg3_readphy(tp, MII_BMSR, &bmsr);
  1595. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1596. (bmsr & BMSR_LSTATUS))
  1597. break;
  1598. udelay(40);
  1599. }
  1600. if (bmsr & BMSR_LSTATUS) {
  1601. u32 aux_stat, bmcr;
  1602. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1603. for (i = 0; i < 2000; i++) {
  1604. udelay(10);
  1605. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1606. aux_stat)
  1607. break;
  1608. }
  1609. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1610. &current_speed,
  1611. &current_duplex);
  1612. bmcr = 0;
  1613. for (i = 0; i < 200; i++) {
  1614. tg3_readphy(tp, MII_BMCR, &bmcr);
  1615. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1616. continue;
  1617. if (bmcr && bmcr != 0x7fff)
  1618. break;
  1619. udelay(10);
  1620. }
  1621. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1622. if (bmcr & BMCR_ANENABLE) {
  1623. current_link_up = 1;
  1624. /* Force autoneg restart if we are exiting
  1625. * low power mode.
  1626. */
  1627. if (!tg3_copper_is_advertising_all(tp,
  1628. tp->link_config.advertising))
  1629. current_link_up = 0;
  1630. } else {
  1631. current_link_up = 0;
  1632. }
  1633. } else {
  1634. if (!(bmcr & BMCR_ANENABLE) &&
  1635. tp->link_config.speed == current_speed &&
  1636. tp->link_config.duplex == current_duplex) {
  1637. current_link_up = 1;
  1638. } else {
  1639. current_link_up = 0;
  1640. }
  1641. }
  1642. tp->link_config.active_speed = current_speed;
  1643. tp->link_config.active_duplex = current_duplex;
  1644. }
  1645. if (current_link_up == 1 &&
  1646. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1647. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1648. u32 local_adv, remote_adv;
  1649. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1650. local_adv = 0;
  1651. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1652. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1653. remote_adv = 0;
  1654. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1655. /* If we are not advertising full pause capability,
  1656. * something is wrong. Bring the link down and reconfigure.
  1657. */
  1658. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1659. current_link_up = 0;
  1660. } else {
  1661. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1662. }
  1663. }
  1664. relink:
  1665. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1666. u32 tmp;
  1667. tg3_phy_copper_begin(tp);
  1668. tg3_readphy(tp, MII_BMSR, &tmp);
  1669. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1670. (tmp & BMSR_LSTATUS))
  1671. current_link_up = 1;
  1672. }
  1673. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1674. if (current_link_up == 1) {
  1675. if (tp->link_config.active_speed == SPEED_100 ||
  1676. tp->link_config.active_speed == SPEED_10)
  1677. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1678. else
  1679. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1680. } else
  1681. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1682. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1683. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1684. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1685. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1686. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1687. if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
  1688. (current_link_up == 1 &&
  1689. tp->link_config.active_speed == SPEED_10))
  1690. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1691. } else {
  1692. if (current_link_up == 1)
  1693. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1694. }
  1695. /* ??? Without this setting Netgear GA302T PHY does not
  1696. * ??? send/receive packets...
  1697. */
  1698. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1699. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1700. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1701. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1702. udelay(80);
  1703. }
  1704. tw32_f(MAC_MODE, tp->mac_mode);
  1705. udelay(40);
  1706. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1707. /* Polled via timer. */
  1708. tw32_f(MAC_EVENT, 0);
  1709. } else {
  1710. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1711. }
  1712. udelay(40);
  1713. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1714. current_link_up == 1 &&
  1715. tp->link_config.active_speed == SPEED_1000 &&
  1716. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1717. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1718. udelay(120);
  1719. tw32_f(MAC_STATUS,
  1720. (MAC_STATUS_SYNC_CHANGED |
  1721. MAC_STATUS_CFG_CHANGED));
  1722. udelay(40);
  1723. tg3_write_mem(tp,
  1724. NIC_SRAM_FIRMWARE_MBOX,
  1725. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1726. }
  1727. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1728. if (current_link_up)
  1729. netif_carrier_on(tp->dev);
  1730. else
  1731. netif_carrier_off(tp->dev);
  1732. tg3_link_report(tp);
  1733. }
  1734. return 0;
  1735. }
  1736. struct tg3_fiber_aneginfo {
  1737. int state;
  1738. #define ANEG_STATE_UNKNOWN 0
  1739. #define ANEG_STATE_AN_ENABLE 1
  1740. #define ANEG_STATE_RESTART_INIT 2
  1741. #define ANEG_STATE_RESTART 3
  1742. #define ANEG_STATE_DISABLE_LINK_OK 4
  1743. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1744. #define ANEG_STATE_ABILITY_DETECT 6
  1745. #define ANEG_STATE_ACK_DETECT_INIT 7
  1746. #define ANEG_STATE_ACK_DETECT 8
  1747. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1748. #define ANEG_STATE_COMPLETE_ACK 10
  1749. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1750. #define ANEG_STATE_IDLE_DETECT 12
  1751. #define ANEG_STATE_LINK_OK 13
  1752. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1753. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1754. u32 flags;
  1755. #define MR_AN_ENABLE 0x00000001
  1756. #define MR_RESTART_AN 0x00000002
  1757. #define MR_AN_COMPLETE 0x00000004
  1758. #define MR_PAGE_RX 0x00000008
  1759. #define MR_NP_LOADED 0x00000010
  1760. #define MR_TOGGLE_TX 0x00000020
  1761. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1762. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1763. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1764. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1765. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1766. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1767. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1768. #define MR_TOGGLE_RX 0x00002000
  1769. #define MR_NP_RX 0x00004000
  1770. #define MR_LINK_OK 0x80000000
  1771. unsigned long link_time, cur_time;
  1772. u32 ability_match_cfg;
  1773. int ability_match_count;
  1774. char ability_match, idle_match, ack_match;
  1775. u32 txconfig, rxconfig;
  1776. #define ANEG_CFG_NP 0x00000080
  1777. #define ANEG_CFG_ACK 0x00000040
  1778. #define ANEG_CFG_RF2 0x00000020
  1779. #define ANEG_CFG_RF1 0x00000010
  1780. #define ANEG_CFG_PS2 0x00000001
  1781. #define ANEG_CFG_PS1 0x00008000
  1782. #define ANEG_CFG_HD 0x00004000
  1783. #define ANEG_CFG_FD 0x00002000
  1784. #define ANEG_CFG_INVAL 0x00001f06
  1785. };
  1786. #define ANEG_OK 0
  1787. #define ANEG_DONE 1
  1788. #define ANEG_TIMER_ENAB 2
  1789. #define ANEG_FAILED -1
  1790. #define ANEG_STATE_SETTLE_TIME 10000
  1791. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1792. struct tg3_fiber_aneginfo *ap)
  1793. {
  1794. unsigned long delta;
  1795. u32 rx_cfg_reg;
  1796. int ret;
  1797. if (ap->state == ANEG_STATE_UNKNOWN) {
  1798. ap->rxconfig = 0;
  1799. ap->link_time = 0;
  1800. ap->cur_time = 0;
  1801. ap->ability_match_cfg = 0;
  1802. ap->ability_match_count = 0;
  1803. ap->ability_match = 0;
  1804. ap->idle_match = 0;
  1805. ap->ack_match = 0;
  1806. }
  1807. ap->cur_time++;
  1808. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1809. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1810. if (rx_cfg_reg != ap->ability_match_cfg) {
  1811. ap->ability_match_cfg = rx_cfg_reg;
  1812. ap->ability_match = 0;
  1813. ap->ability_match_count = 0;
  1814. } else {
  1815. if (++ap->ability_match_count > 1) {
  1816. ap->ability_match = 1;
  1817. ap->ability_match_cfg = rx_cfg_reg;
  1818. }
  1819. }
  1820. if (rx_cfg_reg & ANEG_CFG_ACK)
  1821. ap->ack_match = 1;
  1822. else
  1823. ap->ack_match = 0;
  1824. ap->idle_match = 0;
  1825. } else {
  1826. ap->idle_match = 1;
  1827. ap->ability_match_cfg = 0;
  1828. ap->ability_match_count = 0;
  1829. ap->ability_match = 0;
  1830. ap->ack_match = 0;
  1831. rx_cfg_reg = 0;
  1832. }
  1833. ap->rxconfig = rx_cfg_reg;
  1834. ret = ANEG_OK;
  1835. switch(ap->state) {
  1836. case ANEG_STATE_UNKNOWN:
  1837. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1838. ap->state = ANEG_STATE_AN_ENABLE;
  1839. /* fallthru */
  1840. case ANEG_STATE_AN_ENABLE:
  1841. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1842. if (ap->flags & MR_AN_ENABLE) {
  1843. ap->link_time = 0;
  1844. ap->cur_time = 0;
  1845. ap->ability_match_cfg = 0;
  1846. ap->ability_match_count = 0;
  1847. ap->ability_match = 0;
  1848. ap->idle_match = 0;
  1849. ap->ack_match = 0;
  1850. ap->state = ANEG_STATE_RESTART_INIT;
  1851. } else {
  1852. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1853. }
  1854. break;
  1855. case ANEG_STATE_RESTART_INIT:
  1856. ap->link_time = ap->cur_time;
  1857. ap->flags &= ~(MR_NP_LOADED);
  1858. ap->txconfig = 0;
  1859. tw32(MAC_TX_AUTO_NEG, 0);
  1860. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1861. tw32_f(MAC_MODE, tp->mac_mode);
  1862. udelay(40);
  1863. ret = ANEG_TIMER_ENAB;
  1864. ap->state = ANEG_STATE_RESTART;
  1865. /* fallthru */
  1866. case ANEG_STATE_RESTART:
  1867. delta = ap->cur_time - ap->link_time;
  1868. if (delta > ANEG_STATE_SETTLE_TIME) {
  1869. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1870. } else {
  1871. ret = ANEG_TIMER_ENAB;
  1872. }
  1873. break;
  1874. case ANEG_STATE_DISABLE_LINK_OK:
  1875. ret = ANEG_DONE;
  1876. break;
  1877. case ANEG_STATE_ABILITY_DETECT_INIT:
  1878. ap->flags &= ~(MR_TOGGLE_TX);
  1879. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1880. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1881. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1882. tw32_f(MAC_MODE, tp->mac_mode);
  1883. udelay(40);
  1884. ap->state = ANEG_STATE_ABILITY_DETECT;
  1885. break;
  1886. case ANEG_STATE_ABILITY_DETECT:
  1887. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1888. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1889. }
  1890. break;
  1891. case ANEG_STATE_ACK_DETECT_INIT:
  1892. ap->txconfig |= ANEG_CFG_ACK;
  1893. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1894. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1895. tw32_f(MAC_MODE, tp->mac_mode);
  1896. udelay(40);
  1897. ap->state = ANEG_STATE_ACK_DETECT;
  1898. /* fallthru */
  1899. case ANEG_STATE_ACK_DETECT:
  1900. if (ap->ack_match != 0) {
  1901. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1902. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1903. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1904. } else {
  1905. ap->state = ANEG_STATE_AN_ENABLE;
  1906. }
  1907. } else if (ap->ability_match != 0 &&
  1908. ap->rxconfig == 0) {
  1909. ap->state = ANEG_STATE_AN_ENABLE;
  1910. }
  1911. break;
  1912. case ANEG_STATE_COMPLETE_ACK_INIT:
  1913. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1914. ret = ANEG_FAILED;
  1915. break;
  1916. }
  1917. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1918. MR_LP_ADV_HALF_DUPLEX |
  1919. MR_LP_ADV_SYM_PAUSE |
  1920. MR_LP_ADV_ASYM_PAUSE |
  1921. MR_LP_ADV_REMOTE_FAULT1 |
  1922. MR_LP_ADV_REMOTE_FAULT2 |
  1923. MR_LP_ADV_NEXT_PAGE |
  1924. MR_TOGGLE_RX |
  1925. MR_NP_RX);
  1926. if (ap->rxconfig & ANEG_CFG_FD)
  1927. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1928. if (ap->rxconfig & ANEG_CFG_HD)
  1929. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1930. if (ap->rxconfig & ANEG_CFG_PS1)
  1931. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1932. if (ap->rxconfig & ANEG_CFG_PS2)
  1933. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1934. if (ap->rxconfig & ANEG_CFG_RF1)
  1935. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1936. if (ap->rxconfig & ANEG_CFG_RF2)
  1937. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1938. if (ap->rxconfig & ANEG_CFG_NP)
  1939. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1940. ap->link_time = ap->cur_time;
  1941. ap->flags ^= (MR_TOGGLE_TX);
  1942. if (ap->rxconfig & 0x0008)
  1943. ap->flags |= MR_TOGGLE_RX;
  1944. if (ap->rxconfig & ANEG_CFG_NP)
  1945. ap->flags |= MR_NP_RX;
  1946. ap->flags |= MR_PAGE_RX;
  1947. ap->state = ANEG_STATE_COMPLETE_ACK;
  1948. ret = ANEG_TIMER_ENAB;
  1949. break;
  1950. case ANEG_STATE_COMPLETE_ACK:
  1951. if (ap->ability_match != 0 &&
  1952. ap->rxconfig == 0) {
  1953. ap->state = ANEG_STATE_AN_ENABLE;
  1954. break;
  1955. }
  1956. delta = ap->cur_time - ap->link_time;
  1957. if (delta > ANEG_STATE_SETTLE_TIME) {
  1958. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  1959. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1960. } else {
  1961. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  1962. !(ap->flags & MR_NP_RX)) {
  1963. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1964. } else {
  1965. ret = ANEG_FAILED;
  1966. }
  1967. }
  1968. }
  1969. break;
  1970. case ANEG_STATE_IDLE_DETECT_INIT:
  1971. ap->link_time = ap->cur_time;
  1972. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1973. tw32_f(MAC_MODE, tp->mac_mode);
  1974. udelay(40);
  1975. ap->state = ANEG_STATE_IDLE_DETECT;
  1976. ret = ANEG_TIMER_ENAB;
  1977. break;
  1978. case ANEG_STATE_IDLE_DETECT:
  1979. if (ap->ability_match != 0 &&
  1980. ap->rxconfig == 0) {
  1981. ap->state = ANEG_STATE_AN_ENABLE;
  1982. break;
  1983. }
  1984. delta = ap->cur_time - ap->link_time;
  1985. if (delta > ANEG_STATE_SETTLE_TIME) {
  1986. /* XXX another gem from the Broadcom driver :( */
  1987. ap->state = ANEG_STATE_LINK_OK;
  1988. }
  1989. break;
  1990. case ANEG_STATE_LINK_OK:
  1991. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1992. ret = ANEG_DONE;
  1993. break;
  1994. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1995. /* ??? unimplemented */
  1996. break;
  1997. case ANEG_STATE_NEXT_PAGE_WAIT:
  1998. /* ??? unimplemented */
  1999. break;
  2000. default:
  2001. ret = ANEG_FAILED;
  2002. break;
  2003. };
  2004. return ret;
  2005. }
  2006. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  2007. {
  2008. int res = 0;
  2009. struct tg3_fiber_aneginfo aninfo;
  2010. int status = ANEG_FAILED;
  2011. unsigned int tick;
  2012. u32 tmp;
  2013. tw32_f(MAC_TX_AUTO_NEG, 0);
  2014. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2015. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2016. udelay(40);
  2017. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2018. udelay(40);
  2019. memset(&aninfo, 0, sizeof(aninfo));
  2020. aninfo.flags |= MR_AN_ENABLE;
  2021. aninfo.state = ANEG_STATE_UNKNOWN;
  2022. aninfo.cur_time = 0;
  2023. tick = 0;
  2024. while (++tick < 195000) {
  2025. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2026. if (status == ANEG_DONE || status == ANEG_FAILED)
  2027. break;
  2028. udelay(1);
  2029. }
  2030. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2031. tw32_f(MAC_MODE, tp->mac_mode);
  2032. udelay(40);
  2033. *flags = aninfo.flags;
  2034. if (status == ANEG_DONE &&
  2035. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2036. MR_LP_ADV_FULL_DUPLEX)))
  2037. res = 1;
  2038. return res;
  2039. }
  2040. static void tg3_init_bcm8002(struct tg3 *tp)
  2041. {
  2042. u32 mac_status = tr32(MAC_STATUS);
  2043. int i;
  2044. /* Reset when initting first time or we have a link. */
  2045. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2046. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2047. return;
  2048. /* Set PLL lock range. */
  2049. tg3_writephy(tp, 0x16, 0x8007);
  2050. /* SW reset */
  2051. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2052. /* Wait for reset to complete. */
  2053. /* XXX schedule_timeout() ... */
  2054. for (i = 0; i < 500; i++)
  2055. udelay(10);
  2056. /* Config mode; select PMA/Ch 1 regs. */
  2057. tg3_writephy(tp, 0x10, 0x8411);
  2058. /* Enable auto-lock and comdet, select txclk for tx. */
  2059. tg3_writephy(tp, 0x11, 0x0a10);
  2060. tg3_writephy(tp, 0x18, 0x00a0);
  2061. tg3_writephy(tp, 0x16, 0x41ff);
  2062. /* Assert and deassert POR. */
  2063. tg3_writephy(tp, 0x13, 0x0400);
  2064. udelay(40);
  2065. tg3_writephy(tp, 0x13, 0x0000);
  2066. tg3_writephy(tp, 0x11, 0x0a50);
  2067. udelay(40);
  2068. tg3_writephy(tp, 0x11, 0x0a10);
  2069. /* Wait for signal to stabilize */
  2070. /* XXX schedule_timeout() ... */
  2071. for (i = 0; i < 15000; i++)
  2072. udelay(10);
  2073. /* Deselect the channel register so we can read the PHYID
  2074. * later.
  2075. */
  2076. tg3_writephy(tp, 0x10, 0x8011);
  2077. }
  2078. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2079. {
  2080. u32 sg_dig_ctrl, sg_dig_status;
  2081. u32 serdes_cfg, expected_sg_dig_ctrl;
  2082. int workaround, port_a;
  2083. int current_link_up;
  2084. serdes_cfg = 0;
  2085. expected_sg_dig_ctrl = 0;
  2086. workaround = 0;
  2087. port_a = 1;
  2088. current_link_up = 0;
  2089. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2090. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2091. workaround = 1;
  2092. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2093. port_a = 0;
  2094. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2095. /* preserve bits 20-23 for voltage regulator */
  2096. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2097. }
  2098. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2099. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2100. if (sg_dig_ctrl & (1 << 31)) {
  2101. if (workaround) {
  2102. u32 val = serdes_cfg;
  2103. if (port_a)
  2104. val |= 0xc010000;
  2105. else
  2106. val |= 0x4010000;
  2107. tw32_f(MAC_SERDES_CFG, val);
  2108. }
  2109. tw32_f(SG_DIG_CTRL, 0x01388400);
  2110. }
  2111. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2112. tg3_setup_flow_control(tp, 0, 0);
  2113. current_link_up = 1;
  2114. }
  2115. goto out;
  2116. }
  2117. /* Want auto-negotiation. */
  2118. expected_sg_dig_ctrl = 0x81388400;
  2119. /* Pause capability */
  2120. expected_sg_dig_ctrl |= (1 << 11);
  2121. /* Asymettric pause */
  2122. expected_sg_dig_ctrl |= (1 << 12);
  2123. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2124. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2125. tp->serdes_counter &&
  2126. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2127. MAC_STATUS_RCVD_CFG)) ==
  2128. MAC_STATUS_PCS_SYNCED)) {
  2129. tp->serdes_counter--;
  2130. current_link_up = 1;
  2131. goto out;
  2132. }
  2133. restart_autoneg:
  2134. if (workaround)
  2135. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2136. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2137. udelay(5);
  2138. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2139. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2140. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2141. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2142. MAC_STATUS_SIGNAL_DET)) {
  2143. sg_dig_status = tr32(SG_DIG_STATUS);
  2144. mac_status = tr32(MAC_STATUS);
  2145. if ((sg_dig_status & (1 << 1)) &&
  2146. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2147. u32 local_adv, remote_adv;
  2148. local_adv = ADVERTISE_PAUSE_CAP;
  2149. remote_adv = 0;
  2150. if (sg_dig_status & (1 << 19))
  2151. remote_adv |= LPA_PAUSE_CAP;
  2152. if (sg_dig_status & (1 << 20))
  2153. remote_adv |= LPA_PAUSE_ASYM;
  2154. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2155. current_link_up = 1;
  2156. tp->serdes_counter = 0;
  2157. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2158. } else if (!(sg_dig_status & (1 << 1))) {
  2159. if (tp->serdes_counter)
  2160. tp->serdes_counter--;
  2161. else {
  2162. if (workaround) {
  2163. u32 val = serdes_cfg;
  2164. if (port_a)
  2165. val |= 0xc010000;
  2166. else
  2167. val |= 0x4010000;
  2168. tw32_f(MAC_SERDES_CFG, val);
  2169. }
  2170. tw32_f(SG_DIG_CTRL, 0x01388400);
  2171. udelay(40);
  2172. /* Link parallel detection - link is up */
  2173. /* only if we have PCS_SYNC and not */
  2174. /* receiving config code words */
  2175. mac_status = tr32(MAC_STATUS);
  2176. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2177. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2178. tg3_setup_flow_control(tp, 0, 0);
  2179. current_link_up = 1;
  2180. tp->tg3_flags2 |=
  2181. TG3_FLG2_PARALLEL_DETECT;
  2182. tp->serdes_counter =
  2183. SERDES_PARALLEL_DET_TIMEOUT;
  2184. } else
  2185. goto restart_autoneg;
  2186. }
  2187. }
  2188. } else {
  2189. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2190. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2191. }
  2192. out:
  2193. return current_link_up;
  2194. }
  2195. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2196. {
  2197. int current_link_up = 0;
  2198. if (!(mac_status & MAC_STATUS_PCS_SYNCED)) {
  2199. tp->tg3_flags &= ~TG3_FLAG_GOT_SERDES_FLOWCTL;
  2200. goto out;
  2201. }
  2202. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2203. u32 flags;
  2204. int i;
  2205. if (fiber_autoneg(tp, &flags)) {
  2206. u32 local_adv, remote_adv;
  2207. local_adv = ADVERTISE_PAUSE_CAP;
  2208. remote_adv = 0;
  2209. if (flags & MR_LP_ADV_SYM_PAUSE)
  2210. remote_adv |= LPA_PAUSE_CAP;
  2211. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2212. remote_adv |= LPA_PAUSE_ASYM;
  2213. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2214. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2215. current_link_up = 1;
  2216. }
  2217. for (i = 0; i < 30; i++) {
  2218. udelay(20);
  2219. tw32_f(MAC_STATUS,
  2220. (MAC_STATUS_SYNC_CHANGED |
  2221. MAC_STATUS_CFG_CHANGED));
  2222. udelay(40);
  2223. if ((tr32(MAC_STATUS) &
  2224. (MAC_STATUS_SYNC_CHANGED |
  2225. MAC_STATUS_CFG_CHANGED)) == 0)
  2226. break;
  2227. }
  2228. mac_status = tr32(MAC_STATUS);
  2229. if (current_link_up == 0 &&
  2230. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2231. !(mac_status & MAC_STATUS_RCVD_CFG))
  2232. current_link_up = 1;
  2233. } else {
  2234. /* Forcing 1000FD link up. */
  2235. current_link_up = 1;
  2236. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2237. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2238. udelay(40);
  2239. }
  2240. out:
  2241. return current_link_up;
  2242. }
  2243. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2244. {
  2245. u32 orig_pause_cfg;
  2246. u16 orig_active_speed;
  2247. u8 orig_active_duplex;
  2248. u32 mac_status;
  2249. int current_link_up;
  2250. int i;
  2251. orig_pause_cfg =
  2252. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2253. TG3_FLAG_TX_PAUSE));
  2254. orig_active_speed = tp->link_config.active_speed;
  2255. orig_active_duplex = tp->link_config.active_duplex;
  2256. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2257. netif_carrier_ok(tp->dev) &&
  2258. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2259. mac_status = tr32(MAC_STATUS);
  2260. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2261. MAC_STATUS_SIGNAL_DET |
  2262. MAC_STATUS_CFG_CHANGED |
  2263. MAC_STATUS_RCVD_CFG);
  2264. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2265. MAC_STATUS_SIGNAL_DET)) {
  2266. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2267. MAC_STATUS_CFG_CHANGED));
  2268. return 0;
  2269. }
  2270. }
  2271. tw32_f(MAC_TX_AUTO_NEG, 0);
  2272. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2273. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2274. tw32_f(MAC_MODE, tp->mac_mode);
  2275. udelay(40);
  2276. if (tp->phy_id == PHY_ID_BCM8002)
  2277. tg3_init_bcm8002(tp);
  2278. /* Enable link change event even when serdes polling. */
  2279. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2280. udelay(40);
  2281. current_link_up = 0;
  2282. mac_status = tr32(MAC_STATUS);
  2283. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2284. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2285. else
  2286. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2287. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  2288. tw32_f(MAC_MODE, tp->mac_mode);
  2289. udelay(40);
  2290. tp->hw_status->status =
  2291. (SD_STATUS_UPDATED |
  2292. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2293. for (i = 0; i < 100; i++) {
  2294. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2295. MAC_STATUS_CFG_CHANGED));
  2296. udelay(5);
  2297. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2298. MAC_STATUS_CFG_CHANGED |
  2299. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2300. break;
  2301. }
  2302. mac_status = tr32(MAC_STATUS);
  2303. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2304. current_link_up = 0;
  2305. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2306. tp->serdes_counter == 0) {
  2307. tw32_f(MAC_MODE, (tp->mac_mode |
  2308. MAC_MODE_SEND_CONFIGS));
  2309. udelay(1);
  2310. tw32_f(MAC_MODE, tp->mac_mode);
  2311. }
  2312. }
  2313. if (current_link_up == 1) {
  2314. tp->link_config.active_speed = SPEED_1000;
  2315. tp->link_config.active_duplex = DUPLEX_FULL;
  2316. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2317. LED_CTRL_LNKLED_OVERRIDE |
  2318. LED_CTRL_1000MBPS_ON));
  2319. } else {
  2320. tp->link_config.active_speed = SPEED_INVALID;
  2321. tp->link_config.active_duplex = DUPLEX_INVALID;
  2322. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2323. LED_CTRL_LNKLED_OVERRIDE |
  2324. LED_CTRL_TRAFFIC_OVERRIDE));
  2325. }
  2326. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2327. if (current_link_up)
  2328. netif_carrier_on(tp->dev);
  2329. else
  2330. netif_carrier_off(tp->dev);
  2331. tg3_link_report(tp);
  2332. } else {
  2333. u32 now_pause_cfg =
  2334. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2335. TG3_FLAG_TX_PAUSE);
  2336. if (orig_pause_cfg != now_pause_cfg ||
  2337. orig_active_speed != tp->link_config.active_speed ||
  2338. orig_active_duplex != tp->link_config.active_duplex)
  2339. tg3_link_report(tp);
  2340. }
  2341. return 0;
  2342. }
  2343. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2344. {
  2345. int current_link_up, err = 0;
  2346. u32 bmsr, bmcr;
  2347. u16 current_speed;
  2348. u8 current_duplex;
  2349. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2350. tw32_f(MAC_MODE, tp->mac_mode);
  2351. udelay(40);
  2352. tw32(MAC_EVENT, 0);
  2353. tw32_f(MAC_STATUS,
  2354. (MAC_STATUS_SYNC_CHANGED |
  2355. MAC_STATUS_CFG_CHANGED |
  2356. MAC_STATUS_MI_COMPLETION |
  2357. MAC_STATUS_LNKSTATE_CHANGED));
  2358. udelay(40);
  2359. if (force_reset)
  2360. tg3_phy_reset(tp);
  2361. current_link_up = 0;
  2362. current_speed = SPEED_INVALID;
  2363. current_duplex = DUPLEX_INVALID;
  2364. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2365. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2366. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2367. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2368. bmsr |= BMSR_LSTATUS;
  2369. else
  2370. bmsr &= ~BMSR_LSTATUS;
  2371. }
  2372. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2373. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2374. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2375. /* do nothing, just check for link up at the end */
  2376. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2377. u32 adv, new_adv;
  2378. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2379. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2380. ADVERTISE_1000XPAUSE |
  2381. ADVERTISE_1000XPSE_ASYM |
  2382. ADVERTISE_SLCT);
  2383. /* Always advertise symmetric PAUSE just like copper */
  2384. new_adv |= ADVERTISE_1000XPAUSE;
  2385. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2386. new_adv |= ADVERTISE_1000XHALF;
  2387. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2388. new_adv |= ADVERTISE_1000XFULL;
  2389. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2390. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2391. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2392. tg3_writephy(tp, MII_BMCR, bmcr);
  2393. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2394. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2395. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2396. return err;
  2397. }
  2398. } else {
  2399. u32 new_bmcr;
  2400. bmcr &= ~BMCR_SPEED1000;
  2401. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2402. if (tp->link_config.duplex == DUPLEX_FULL)
  2403. new_bmcr |= BMCR_FULLDPLX;
  2404. if (new_bmcr != bmcr) {
  2405. /* BMCR_SPEED1000 is a reserved bit that needs
  2406. * to be set on write.
  2407. */
  2408. new_bmcr |= BMCR_SPEED1000;
  2409. /* Force a linkdown */
  2410. if (netif_carrier_ok(tp->dev)) {
  2411. u32 adv;
  2412. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2413. adv &= ~(ADVERTISE_1000XFULL |
  2414. ADVERTISE_1000XHALF |
  2415. ADVERTISE_SLCT);
  2416. tg3_writephy(tp, MII_ADVERTISE, adv);
  2417. tg3_writephy(tp, MII_BMCR, bmcr |
  2418. BMCR_ANRESTART |
  2419. BMCR_ANENABLE);
  2420. udelay(10);
  2421. netif_carrier_off(tp->dev);
  2422. }
  2423. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2424. bmcr = new_bmcr;
  2425. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2426. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2427. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2428. ASIC_REV_5714) {
  2429. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2430. bmsr |= BMSR_LSTATUS;
  2431. else
  2432. bmsr &= ~BMSR_LSTATUS;
  2433. }
  2434. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2435. }
  2436. }
  2437. if (bmsr & BMSR_LSTATUS) {
  2438. current_speed = SPEED_1000;
  2439. current_link_up = 1;
  2440. if (bmcr & BMCR_FULLDPLX)
  2441. current_duplex = DUPLEX_FULL;
  2442. else
  2443. current_duplex = DUPLEX_HALF;
  2444. if (bmcr & BMCR_ANENABLE) {
  2445. u32 local_adv, remote_adv, common;
  2446. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2447. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2448. common = local_adv & remote_adv;
  2449. if (common & (ADVERTISE_1000XHALF |
  2450. ADVERTISE_1000XFULL)) {
  2451. if (common & ADVERTISE_1000XFULL)
  2452. current_duplex = DUPLEX_FULL;
  2453. else
  2454. current_duplex = DUPLEX_HALF;
  2455. tg3_setup_flow_control(tp, local_adv,
  2456. remote_adv);
  2457. }
  2458. else
  2459. current_link_up = 0;
  2460. }
  2461. }
  2462. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2463. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2464. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2465. tw32_f(MAC_MODE, tp->mac_mode);
  2466. udelay(40);
  2467. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2468. tp->link_config.active_speed = current_speed;
  2469. tp->link_config.active_duplex = current_duplex;
  2470. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2471. if (current_link_up)
  2472. netif_carrier_on(tp->dev);
  2473. else {
  2474. netif_carrier_off(tp->dev);
  2475. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2476. }
  2477. tg3_link_report(tp);
  2478. }
  2479. return err;
  2480. }
  2481. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2482. {
  2483. if (tp->serdes_counter) {
  2484. /* Give autoneg time to complete. */
  2485. tp->serdes_counter--;
  2486. return;
  2487. }
  2488. if (!netif_carrier_ok(tp->dev) &&
  2489. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2490. u32 bmcr;
  2491. tg3_readphy(tp, MII_BMCR, &bmcr);
  2492. if (bmcr & BMCR_ANENABLE) {
  2493. u32 phy1, phy2;
  2494. /* Select shadow register 0x1f */
  2495. tg3_writephy(tp, 0x1c, 0x7c00);
  2496. tg3_readphy(tp, 0x1c, &phy1);
  2497. /* Select expansion interrupt status register */
  2498. tg3_writephy(tp, 0x17, 0x0f01);
  2499. tg3_readphy(tp, 0x15, &phy2);
  2500. tg3_readphy(tp, 0x15, &phy2);
  2501. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2502. /* We have signal detect and not receiving
  2503. * config code words, link is up by parallel
  2504. * detection.
  2505. */
  2506. bmcr &= ~BMCR_ANENABLE;
  2507. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2508. tg3_writephy(tp, MII_BMCR, bmcr);
  2509. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2510. }
  2511. }
  2512. }
  2513. else if (netif_carrier_ok(tp->dev) &&
  2514. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2515. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2516. u32 phy2;
  2517. /* Select expansion interrupt status register */
  2518. tg3_writephy(tp, 0x17, 0x0f01);
  2519. tg3_readphy(tp, 0x15, &phy2);
  2520. if (phy2 & 0x20) {
  2521. u32 bmcr;
  2522. /* Config code words received, turn on autoneg. */
  2523. tg3_readphy(tp, MII_BMCR, &bmcr);
  2524. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2525. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2526. }
  2527. }
  2528. }
  2529. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2530. {
  2531. int err;
  2532. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2533. err = tg3_setup_fiber_phy(tp, force_reset);
  2534. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2535. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2536. } else {
  2537. err = tg3_setup_copper_phy(tp, force_reset);
  2538. }
  2539. if (tp->link_config.active_speed == SPEED_1000 &&
  2540. tp->link_config.active_duplex == DUPLEX_HALF)
  2541. tw32(MAC_TX_LENGTHS,
  2542. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2543. (6 << TX_LENGTHS_IPG_SHIFT) |
  2544. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2545. else
  2546. tw32(MAC_TX_LENGTHS,
  2547. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2548. (6 << TX_LENGTHS_IPG_SHIFT) |
  2549. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2550. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2551. if (netif_carrier_ok(tp->dev)) {
  2552. tw32(HOSTCC_STAT_COAL_TICKS,
  2553. tp->coal.stats_block_coalesce_usecs);
  2554. } else {
  2555. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2556. }
  2557. }
  2558. return err;
  2559. }
  2560. /* This is called whenever we suspect that the system chipset is re-
  2561. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2562. * is bogus tx completions. We try to recover by setting the
  2563. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2564. * in the workqueue.
  2565. */
  2566. static void tg3_tx_recover(struct tg3 *tp)
  2567. {
  2568. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2569. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2570. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2571. "mapped I/O cycles to the network device, attempting to "
  2572. "recover. Please report the problem to the driver maintainer "
  2573. "and include system chipset information.\n", tp->dev->name);
  2574. spin_lock(&tp->lock);
  2575. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2576. spin_unlock(&tp->lock);
  2577. }
  2578. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2579. {
  2580. smp_mb();
  2581. return (tp->tx_pending -
  2582. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2583. }
  2584. /* Tigon3 never reports partial packet sends. So we do not
  2585. * need special logic to handle SKBs that have not had all
  2586. * of their frags sent yet, like SunGEM does.
  2587. */
  2588. static void tg3_tx(struct tg3 *tp)
  2589. {
  2590. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2591. u32 sw_idx = tp->tx_cons;
  2592. while (sw_idx != hw_idx) {
  2593. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2594. struct sk_buff *skb = ri->skb;
  2595. int i, tx_bug = 0;
  2596. if (unlikely(skb == NULL)) {
  2597. tg3_tx_recover(tp);
  2598. return;
  2599. }
  2600. pci_unmap_single(tp->pdev,
  2601. pci_unmap_addr(ri, mapping),
  2602. skb_headlen(skb),
  2603. PCI_DMA_TODEVICE);
  2604. ri->skb = NULL;
  2605. sw_idx = NEXT_TX(sw_idx);
  2606. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2607. ri = &tp->tx_buffers[sw_idx];
  2608. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2609. tx_bug = 1;
  2610. pci_unmap_page(tp->pdev,
  2611. pci_unmap_addr(ri, mapping),
  2612. skb_shinfo(skb)->frags[i].size,
  2613. PCI_DMA_TODEVICE);
  2614. sw_idx = NEXT_TX(sw_idx);
  2615. }
  2616. dev_kfree_skb(skb);
  2617. if (unlikely(tx_bug)) {
  2618. tg3_tx_recover(tp);
  2619. return;
  2620. }
  2621. }
  2622. tp->tx_cons = sw_idx;
  2623. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2624. * before checking for netif_queue_stopped(). Without the
  2625. * memory barrier, there is a small possibility that tg3_start_xmit()
  2626. * will miss it and cause the queue to be stopped forever.
  2627. */
  2628. smp_mb();
  2629. if (unlikely(netif_queue_stopped(tp->dev) &&
  2630. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2631. netif_tx_lock(tp->dev);
  2632. if (netif_queue_stopped(tp->dev) &&
  2633. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2634. netif_wake_queue(tp->dev);
  2635. netif_tx_unlock(tp->dev);
  2636. }
  2637. }
  2638. /* Returns size of skb allocated or < 0 on error.
  2639. *
  2640. * We only need to fill in the address because the other members
  2641. * of the RX descriptor are invariant, see tg3_init_rings.
  2642. *
  2643. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2644. * posting buffers we only dirty the first cache line of the RX
  2645. * descriptor (containing the address). Whereas for the RX status
  2646. * buffers the cpu only reads the last cacheline of the RX descriptor
  2647. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2648. */
  2649. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2650. int src_idx, u32 dest_idx_unmasked)
  2651. {
  2652. struct tg3_rx_buffer_desc *desc;
  2653. struct ring_info *map, *src_map;
  2654. struct sk_buff *skb;
  2655. dma_addr_t mapping;
  2656. int skb_size, dest_idx;
  2657. src_map = NULL;
  2658. switch (opaque_key) {
  2659. case RXD_OPAQUE_RING_STD:
  2660. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2661. desc = &tp->rx_std[dest_idx];
  2662. map = &tp->rx_std_buffers[dest_idx];
  2663. if (src_idx >= 0)
  2664. src_map = &tp->rx_std_buffers[src_idx];
  2665. skb_size = tp->rx_pkt_buf_sz;
  2666. break;
  2667. case RXD_OPAQUE_RING_JUMBO:
  2668. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2669. desc = &tp->rx_jumbo[dest_idx];
  2670. map = &tp->rx_jumbo_buffers[dest_idx];
  2671. if (src_idx >= 0)
  2672. src_map = &tp->rx_jumbo_buffers[src_idx];
  2673. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2674. break;
  2675. default:
  2676. return -EINVAL;
  2677. };
  2678. /* Do not overwrite any of the map or rp information
  2679. * until we are sure we can commit to a new buffer.
  2680. *
  2681. * Callers depend upon this behavior and assume that
  2682. * we leave everything unchanged if we fail.
  2683. */
  2684. skb = netdev_alloc_skb(tp->dev, skb_size);
  2685. if (skb == NULL)
  2686. return -ENOMEM;
  2687. skb_reserve(skb, tp->rx_offset);
  2688. mapping = pci_map_single(tp->pdev, skb->data,
  2689. skb_size - tp->rx_offset,
  2690. PCI_DMA_FROMDEVICE);
  2691. map->skb = skb;
  2692. pci_unmap_addr_set(map, mapping, mapping);
  2693. if (src_map != NULL)
  2694. src_map->skb = NULL;
  2695. desc->addr_hi = ((u64)mapping >> 32);
  2696. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2697. return skb_size;
  2698. }
  2699. /* We only need to move over in the address because the other
  2700. * members of the RX descriptor are invariant. See notes above
  2701. * tg3_alloc_rx_skb for full details.
  2702. */
  2703. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2704. int src_idx, u32 dest_idx_unmasked)
  2705. {
  2706. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2707. struct ring_info *src_map, *dest_map;
  2708. int dest_idx;
  2709. switch (opaque_key) {
  2710. case RXD_OPAQUE_RING_STD:
  2711. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2712. dest_desc = &tp->rx_std[dest_idx];
  2713. dest_map = &tp->rx_std_buffers[dest_idx];
  2714. src_desc = &tp->rx_std[src_idx];
  2715. src_map = &tp->rx_std_buffers[src_idx];
  2716. break;
  2717. case RXD_OPAQUE_RING_JUMBO:
  2718. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2719. dest_desc = &tp->rx_jumbo[dest_idx];
  2720. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2721. src_desc = &tp->rx_jumbo[src_idx];
  2722. src_map = &tp->rx_jumbo_buffers[src_idx];
  2723. break;
  2724. default:
  2725. return;
  2726. };
  2727. dest_map->skb = src_map->skb;
  2728. pci_unmap_addr_set(dest_map, mapping,
  2729. pci_unmap_addr(src_map, mapping));
  2730. dest_desc->addr_hi = src_desc->addr_hi;
  2731. dest_desc->addr_lo = src_desc->addr_lo;
  2732. src_map->skb = NULL;
  2733. }
  2734. #if TG3_VLAN_TAG_USED
  2735. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2736. {
  2737. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2738. }
  2739. #endif
  2740. /* The RX ring scheme is composed of multiple rings which post fresh
  2741. * buffers to the chip, and one special ring the chip uses to report
  2742. * status back to the host.
  2743. *
  2744. * The special ring reports the status of received packets to the
  2745. * host. The chip does not write into the original descriptor the
  2746. * RX buffer was obtained from. The chip simply takes the original
  2747. * descriptor as provided by the host, updates the status and length
  2748. * field, then writes this into the next status ring entry.
  2749. *
  2750. * Each ring the host uses to post buffers to the chip is described
  2751. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2752. * it is first placed into the on-chip ram. When the packet's length
  2753. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2754. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2755. * which is within the range of the new packet's length is chosen.
  2756. *
  2757. * The "separate ring for rx status" scheme may sound queer, but it makes
  2758. * sense from a cache coherency perspective. If only the host writes
  2759. * to the buffer post rings, and only the chip writes to the rx status
  2760. * rings, then cache lines never move beyond shared-modified state.
  2761. * If both the host and chip were to write into the same ring, cache line
  2762. * eviction could occur since both entities want it in an exclusive state.
  2763. */
  2764. static int tg3_rx(struct tg3 *tp, int budget)
  2765. {
  2766. u32 work_mask, rx_std_posted = 0;
  2767. u32 sw_idx = tp->rx_rcb_ptr;
  2768. u16 hw_idx;
  2769. int received;
  2770. hw_idx = tp->hw_status->idx[0].rx_producer;
  2771. /*
  2772. * We need to order the read of hw_idx and the read of
  2773. * the opaque cookie.
  2774. */
  2775. rmb();
  2776. work_mask = 0;
  2777. received = 0;
  2778. while (sw_idx != hw_idx && budget > 0) {
  2779. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2780. unsigned int len;
  2781. struct sk_buff *skb;
  2782. dma_addr_t dma_addr;
  2783. u32 opaque_key, desc_idx, *post_ptr;
  2784. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2785. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2786. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2787. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2788. mapping);
  2789. skb = tp->rx_std_buffers[desc_idx].skb;
  2790. post_ptr = &tp->rx_std_ptr;
  2791. rx_std_posted++;
  2792. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2793. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2794. mapping);
  2795. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2796. post_ptr = &tp->rx_jumbo_ptr;
  2797. }
  2798. else {
  2799. goto next_pkt_nopost;
  2800. }
  2801. work_mask |= opaque_key;
  2802. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2803. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2804. drop_it:
  2805. tg3_recycle_rx(tp, opaque_key,
  2806. desc_idx, *post_ptr);
  2807. drop_it_no_recycle:
  2808. /* Other statistics kept track of by card. */
  2809. tp->net_stats.rx_dropped++;
  2810. goto next_pkt;
  2811. }
  2812. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2813. if (len > RX_COPY_THRESHOLD
  2814. && tp->rx_offset == 2
  2815. /* rx_offset != 2 iff this is a 5701 card running
  2816. * in PCI-X mode [see tg3_get_invariants()] */
  2817. ) {
  2818. int skb_size;
  2819. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2820. desc_idx, *post_ptr);
  2821. if (skb_size < 0)
  2822. goto drop_it;
  2823. pci_unmap_single(tp->pdev, dma_addr,
  2824. skb_size - tp->rx_offset,
  2825. PCI_DMA_FROMDEVICE);
  2826. skb_put(skb, len);
  2827. } else {
  2828. struct sk_buff *copy_skb;
  2829. tg3_recycle_rx(tp, opaque_key,
  2830. desc_idx, *post_ptr);
  2831. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  2832. if (copy_skb == NULL)
  2833. goto drop_it_no_recycle;
  2834. skb_reserve(copy_skb, 2);
  2835. skb_put(copy_skb, len);
  2836. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2837. memcpy(copy_skb->data, skb->data, len);
  2838. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2839. /* We'll reuse the original ring buffer. */
  2840. skb = copy_skb;
  2841. }
  2842. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2843. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2844. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2845. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2846. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2847. else
  2848. skb->ip_summed = CHECKSUM_NONE;
  2849. skb->protocol = eth_type_trans(skb, tp->dev);
  2850. #if TG3_VLAN_TAG_USED
  2851. if (tp->vlgrp != NULL &&
  2852. desc->type_flags & RXD_FLAG_VLAN) {
  2853. tg3_vlan_rx(tp, skb,
  2854. desc->err_vlan & RXD_VLAN_MASK);
  2855. } else
  2856. #endif
  2857. netif_receive_skb(skb);
  2858. tp->dev->last_rx = jiffies;
  2859. received++;
  2860. budget--;
  2861. next_pkt:
  2862. (*post_ptr)++;
  2863. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2864. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2865. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2866. TG3_64BIT_REG_LOW, idx);
  2867. work_mask &= ~RXD_OPAQUE_RING_STD;
  2868. rx_std_posted = 0;
  2869. }
  2870. next_pkt_nopost:
  2871. sw_idx++;
  2872. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  2873. /* Refresh hw_idx to see if there is new work */
  2874. if (sw_idx == hw_idx) {
  2875. hw_idx = tp->hw_status->idx[0].rx_producer;
  2876. rmb();
  2877. }
  2878. }
  2879. /* ACK the status ring. */
  2880. tp->rx_rcb_ptr = sw_idx;
  2881. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2882. /* Refill RX ring(s). */
  2883. if (work_mask & RXD_OPAQUE_RING_STD) {
  2884. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2885. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2886. sw_idx);
  2887. }
  2888. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2889. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2890. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2891. sw_idx);
  2892. }
  2893. mmiowb();
  2894. return received;
  2895. }
  2896. static int tg3_poll(struct net_device *netdev, int *budget)
  2897. {
  2898. struct tg3 *tp = netdev_priv(netdev);
  2899. struct tg3_hw_status *sblk = tp->hw_status;
  2900. int done;
  2901. /* handle link change and other phy events */
  2902. if (!(tp->tg3_flags &
  2903. (TG3_FLAG_USE_LINKCHG_REG |
  2904. TG3_FLAG_POLL_SERDES))) {
  2905. if (sblk->status & SD_STATUS_LINK_CHG) {
  2906. sblk->status = SD_STATUS_UPDATED |
  2907. (sblk->status & ~SD_STATUS_LINK_CHG);
  2908. spin_lock(&tp->lock);
  2909. tg3_setup_phy(tp, 0);
  2910. spin_unlock(&tp->lock);
  2911. }
  2912. }
  2913. /* run TX completion thread */
  2914. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2915. tg3_tx(tp);
  2916. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2917. netif_rx_complete(netdev);
  2918. schedule_work(&tp->reset_task);
  2919. return 0;
  2920. }
  2921. }
  2922. /* run RX thread, within the bounds set by NAPI.
  2923. * All RX "locking" is done by ensuring outside
  2924. * code synchronizes with dev->poll()
  2925. */
  2926. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2927. int orig_budget = *budget;
  2928. int work_done;
  2929. if (orig_budget > netdev->quota)
  2930. orig_budget = netdev->quota;
  2931. work_done = tg3_rx(tp, orig_budget);
  2932. *budget -= work_done;
  2933. netdev->quota -= work_done;
  2934. }
  2935. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2936. tp->last_tag = sblk->status_tag;
  2937. rmb();
  2938. } else
  2939. sblk->status &= ~SD_STATUS_UPDATED;
  2940. /* if no more work, tell net stack and NIC we're done */
  2941. done = !tg3_has_work(tp);
  2942. if (done) {
  2943. netif_rx_complete(netdev);
  2944. tg3_restart_ints(tp);
  2945. }
  2946. return (done ? 0 : 1);
  2947. }
  2948. static void tg3_irq_quiesce(struct tg3 *tp)
  2949. {
  2950. BUG_ON(tp->irq_sync);
  2951. tp->irq_sync = 1;
  2952. smp_mb();
  2953. synchronize_irq(tp->pdev->irq);
  2954. }
  2955. static inline int tg3_irq_sync(struct tg3 *tp)
  2956. {
  2957. return tp->irq_sync;
  2958. }
  2959. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  2960. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  2961. * with as well. Most of the time, this is not necessary except when
  2962. * shutting down the device.
  2963. */
  2964. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  2965. {
  2966. if (irq_sync)
  2967. tg3_irq_quiesce(tp);
  2968. spin_lock_bh(&tp->lock);
  2969. }
  2970. static inline void tg3_full_unlock(struct tg3 *tp)
  2971. {
  2972. spin_unlock_bh(&tp->lock);
  2973. }
  2974. /* One-shot MSI handler - Chip automatically disables interrupt
  2975. * after sending MSI so driver doesn't have to do it.
  2976. */
  2977. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  2978. {
  2979. struct net_device *dev = dev_id;
  2980. struct tg3 *tp = netdev_priv(dev);
  2981. prefetch(tp->hw_status);
  2982. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2983. if (likely(!tg3_irq_sync(tp)))
  2984. netif_rx_schedule(dev); /* schedule NAPI poll */
  2985. return IRQ_HANDLED;
  2986. }
  2987. /* MSI ISR - No need to check for interrupt sharing and no need to
  2988. * flush status block and interrupt mailbox. PCI ordering rules
  2989. * guarantee that MSI will arrive after the status block.
  2990. */
  2991. static irqreturn_t tg3_msi(int irq, void *dev_id)
  2992. {
  2993. struct net_device *dev = dev_id;
  2994. struct tg3 *tp = netdev_priv(dev);
  2995. prefetch(tp->hw_status);
  2996. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  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, 0x00000001);
  3005. if (likely(!tg3_irq_sync(tp)))
  3006. netif_rx_schedule(dev); /* schedule NAPI poll */
  3007. return IRQ_RETVAL(1);
  3008. }
  3009. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3010. {
  3011. struct net_device *dev = dev_id;
  3012. struct tg3 *tp = netdev_priv(dev);
  3013. struct tg3_hw_status *sblk = tp->hw_status;
  3014. unsigned int handled = 1;
  3015. /* In INTx mode, it is possible for the interrupt to arrive at
  3016. * the CPU before the status block posted prior to the interrupt.
  3017. * Reading the PCI State register will confirm whether the
  3018. * interrupt is ours and will flush the status block.
  3019. */
  3020. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3021. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3022. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3023. handled = 0;
  3024. goto out;
  3025. }
  3026. }
  3027. /*
  3028. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3029. * chip-internal interrupt pending events.
  3030. * Writing non-zero to intr-mbox-0 additional tells the
  3031. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3032. * event coalescing.
  3033. */
  3034. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3035. if (tg3_irq_sync(tp))
  3036. goto out;
  3037. sblk->status &= ~SD_STATUS_UPDATED;
  3038. if (likely(tg3_has_work(tp))) {
  3039. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3040. netif_rx_schedule(dev); /* schedule NAPI poll */
  3041. } else {
  3042. /* No work, shared interrupt perhaps? re-enable
  3043. * interrupts, and flush that PCI write
  3044. */
  3045. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3046. 0x00000000);
  3047. }
  3048. out:
  3049. return IRQ_RETVAL(handled);
  3050. }
  3051. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3052. {
  3053. struct net_device *dev = dev_id;
  3054. struct tg3 *tp = netdev_priv(dev);
  3055. struct tg3_hw_status *sblk = tp->hw_status;
  3056. unsigned int handled = 1;
  3057. /* In INTx mode, it is possible for the interrupt to arrive at
  3058. * the CPU before the status block posted prior to the interrupt.
  3059. * Reading the PCI State register will confirm whether the
  3060. * interrupt is ours and will flush the status block.
  3061. */
  3062. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3063. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3064. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3065. handled = 0;
  3066. goto out;
  3067. }
  3068. }
  3069. /*
  3070. * writing any value to intr-mbox-0 clears PCI INTA# and
  3071. * chip-internal interrupt pending events.
  3072. * writing non-zero to intr-mbox-0 additional tells the
  3073. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3074. * event coalescing.
  3075. */
  3076. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3077. if (tg3_irq_sync(tp))
  3078. goto out;
  3079. if (netif_rx_schedule_prep(dev)) {
  3080. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3081. /* Update last_tag to mark that this status has been
  3082. * seen. Because interrupt may be shared, we may be
  3083. * racing with tg3_poll(), so only update last_tag
  3084. * if tg3_poll() is not scheduled.
  3085. */
  3086. tp->last_tag = sblk->status_tag;
  3087. __netif_rx_schedule(dev);
  3088. }
  3089. out:
  3090. return IRQ_RETVAL(handled);
  3091. }
  3092. /* ISR for interrupt test */
  3093. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3094. {
  3095. struct net_device *dev = dev_id;
  3096. struct tg3 *tp = netdev_priv(dev);
  3097. struct tg3_hw_status *sblk = tp->hw_status;
  3098. if ((sblk->status & SD_STATUS_UPDATED) ||
  3099. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3100. tg3_disable_ints(tp);
  3101. return IRQ_RETVAL(1);
  3102. }
  3103. return IRQ_RETVAL(0);
  3104. }
  3105. static int tg3_init_hw(struct tg3 *, int);
  3106. static int tg3_halt(struct tg3 *, int, int);
  3107. /* Restart hardware after configuration changes, self-test, etc.
  3108. * Invoked with tp->lock held.
  3109. */
  3110. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3111. {
  3112. int err;
  3113. err = tg3_init_hw(tp, reset_phy);
  3114. if (err) {
  3115. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3116. "aborting.\n", tp->dev->name);
  3117. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3118. tg3_full_unlock(tp);
  3119. del_timer_sync(&tp->timer);
  3120. tp->irq_sync = 0;
  3121. netif_poll_enable(tp->dev);
  3122. dev_close(tp->dev);
  3123. tg3_full_lock(tp, 0);
  3124. }
  3125. return err;
  3126. }
  3127. #ifdef CONFIG_NET_POLL_CONTROLLER
  3128. static void tg3_poll_controller(struct net_device *dev)
  3129. {
  3130. struct tg3 *tp = netdev_priv(dev);
  3131. tg3_interrupt(tp->pdev->irq, dev);
  3132. }
  3133. #endif
  3134. static void tg3_reset_task(struct work_struct *work)
  3135. {
  3136. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3137. unsigned int restart_timer;
  3138. tg3_full_lock(tp, 0);
  3139. tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
  3140. if (!netif_running(tp->dev)) {
  3141. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3142. tg3_full_unlock(tp);
  3143. return;
  3144. }
  3145. tg3_full_unlock(tp);
  3146. tg3_netif_stop(tp);
  3147. tg3_full_lock(tp, 1);
  3148. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3149. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3150. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3151. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3152. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3153. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3154. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3155. }
  3156. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3157. if (tg3_init_hw(tp, 1))
  3158. goto out;
  3159. tg3_netif_start(tp);
  3160. if (restart_timer)
  3161. mod_timer(&tp->timer, jiffies + 1);
  3162. out:
  3163. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3164. tg3_full_unlock(tp);
  3165. }
  3166. static void tg3_dump_short_state(struct tg3 *tp)
  3167. {
  3168. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3169. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3170. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3171. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3172. }
  3173. static void tg3_tx_timeout(struct net_device *dev)
  3174. {
  3175. struct tg3 *tp = netdev_priv(dev);
  3176. if (netif_msg_tx_err(tp)) {
  3177. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3178. dev->name);
  3179. tg3_dump_short_state(tp);
  3180. }
  3181. schedule_work(&tp->reset_task);
  3182. }
  3183. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3184. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3185. {
  3186. u32 base = (u32) mapping & 0xffffffff;
  3187. return ((base > 0xffffdcc0) &&
  3188. (base + len + 8 < base));
  3189. }
  3190. /* Test for DMA addresses > 40-bit */
  3191. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3192. int len)
  3193. {
  3194. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3195. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3196. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3197. return 0;
  3198. #else
  3199. return 0;
  3200. #endif
  3201. }
  3202. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3203. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3204. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3205. u32 last_plus_one, u32 *start,
  3206. u32 base_flags, u32 mss)
  3207. {
  3208. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3209. dma_addr_t new_addr = 0;
  3210. u32 entry = *start;
  3211. int i, ret = 0;
  3212. if (!new_skb) {
  3213. ret = -1;
  3214. } else {
  3215. /* New SKB is guaranteed to be linear. */
  3216. entry = *start;
  3217. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3218. PCI_DMA_TODEVICE);
  3219. /* Make sure new skb does not cross any 4G boundaries.
  3220. * Drop the packet if it does.
  3221. */
  3222. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3223. ret = -1;
  3224. dev_kfree_skb(new_skb);
  3225. new_skb = NULL;
  3226. } else {
  3227. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3228. base_flags, 1 | (mss << 1));
  3229. *start = NEXT_TX(entry);
  3230. }
  3231. }
  3232. /* Now clean up the sw ring entries. */
  3233. i = 0;
  3234. while (entry != last_plus_one) {
  3235. int len;
  3236. if (i == 0)
  3237. len = skb_headlen(skb);
  3238. else
  3239. len = skb_shinfo(skb)->frags[i-1].size;
  3240. pci_unmap_single(tp->pdev,
  3241. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3242. len, PCI_DMA_TODEVICE);
  3243. if (i == 0) {
  3244. tp->tx_buffers[entry].skb = new_skb;
  3245. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3246. } else {
  3247. tp->tx_buffers[entry].skb = NULL;
  3248. }
  3249. entry = NEXT_TX(entry);
  3250. i++;
  3251. }
  3252. dev_kfree_skb(skb);
  3253. return ret;
  3254. }
  3255. static void tg3_set_txd(struct tg3 *tp, int entry,
  3256. dma_addr_t mapping, int len, u32 flags,
  3257. u32 mss_and_is_end)
  3258. {
  3259. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3260. int is_end = (mss_and_is_end & 0x1);
  3261. u32 mss = (mss_and_is_end >> 1);
  3262. u32 vlan_tag = 0;
  3263. if (is_end)
  3264. flags |= TXD_FLAG_END;
  3265. if (flags & TXD_FLAG_VLAN) {
  3266. vlan_tag = flags >> 16;
  3267. flags &= 0xffff;
  3268. }
  3269. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3270. txd->addr_hi = ((u64) mapping >> 32);
  3271. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3272. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3273. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3274. }
  3275. /* hard_start_xmit for devices that don't have any bugs and
  3276. * support TG3_FLG2_HW_TSO_2 only.
  3277. */
  3278. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3279. {
  3280. struct tg3 *tp = netdev_priv(dev);
  3281. dma_addr_t mapping;
  3282. u32 len, entry, base_flags, mss;
  3283. len = skb_headlen(skb);
  3284. /* We are running in BH disabled context with netif_tx_lock
  3285. * and TX reclaim runs via tp->poll inside of a software
  3286. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3287. * no IRQ context deadlocks to worry about either. Rejoice!
  3288. */
  3289. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3290. if (!netif_queue_stopped(dev)) {
  3291. netif_stop_queue(dev);
  3292. /* This is a hard error, log it. */
  3293. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3294. "queue awake!\n", dev->name);
  3295. }
  3296. return NETDEV_TX_BUSY;
  3297. }
  3298. entry = tp->tx_prod;
  3299. base_flags = 0;
  3300. mss = 0;
  3301. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3302. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3303. int tcp_opt_len, ip_tcp_len;
  3304. if (skb_header_cloned(skb) &&
  3305. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3306. dev_kfree_skb(skb);
  3307. goto out_unlock;
  3308. }
  3309. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3310. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3311. else {
  3312. struct iphdr *iph = ip_hdr(skb);
  3313. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3314. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3315. iph->check = 0;
  3316. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3317. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3318. }
  3319. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3320. TXD_FLAG_CPU_POST_DMA);
  3321. skb->h.th->check = 0;
  3322. }
  3323. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3324. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3325. #if TG3_VLAN_TAG_USED
  3326. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3327. base_flags |= (TXD_FLAG_VLAN |
  3328. (vlan_tx_tag_get(skb) << 16));
  3329. #endif
  3330. /* Queue skb data, a.k.a. the main skb fragment. */
  3331. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3332. tp->tx_buffers[entry].skb = skb;
  3333. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3334. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3335. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3336. entry = NEXT_TX(entry);
  3337. /* Now loop through additional data fragments, and queue them. */
  3338. if (skb_shinfo(skb)->nr_frags > 0) {
  3339. unsigned int i, last;
  3340. last = skb_shinfo(skb)->nr_frags - 1;
  3341. for (i = 0; i <= last; i++) {
  3342. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3343. len = frag->size;
  3344. mapping = pci_map_page(tp->pdev,
  3345. frag->page,
  3346. frag->page_offset,
  3347. len, PCI_DMA_TODEVICE);
  3348. tp->tx_buffers[entry].skb = NULL;
  3349. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3350. tg3_set_txd(tp, entry, mapping, len,
  3351. base_flags, (i == last) | (mss << 1));
  3352. entry = NEXT_TX(entry);
  3353. }
  3354. }
  3355. /* Packets are ready, update Tx producer idx local and on card. */
  3356. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3357. tp->tx_prod = entry;
  3358. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3359. netif_stop_queue(dev);
  3360. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3361. netif_wake_queue(tp->dev);
  3362. }
  3363. out_unlock:
  3364. mmiowb();
  3365. dev->trans_start = jiffies;
  3366. return NETDEV_TX_OK;
  3367. }
  3368. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3369. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3370. * TSO header is greater than 80 bytes.
  3371. */
  3372. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3373. {
  3374. struct sk_buff *segs, *nskb;
  3375. /* Estimate the number of fragments in the worst case */
  3376. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3377. netif_stop_queue(tp->dev);
  3378. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3379. return NETDEV_TX_BUSY;
  3380. netif_wake_queue(tp->dev);
  3381. }
  3382. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3383. if (unlikely(IS_ERR(segs)))
  3384. goto tg3_tso_bug_end;
  3385. do {
  3386. nskb = segs;
  3387. segs = segs->next;
  3388. nskb->next = NULL;
  3389. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3390. } while (segs);
  3391. tg3_tso_bug_end:
  3392. dev_kfree_skb(skb);
  3393. return NETDEV_TX_OK;
  3394. }
  3395. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3396. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3397. */
  3398. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3399. {
  3400. struct tg3 *tp = netdev_priv(dev);
  3401. dma_addr_t mapping;
  3402. u32 len, entry, base_flags, mss;
  3403. int would_hit_hwbug;
  3404. len = skb_headlen(skb);
  3405. /* We are running in BH disabled context with netif_tx_lock
  3406. * and TX reclaim runs via tp->poll inside of a software
  3407. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3408. * no IRQ context deadlocks to worry about either. Rejoice!
  3409. */
  3410. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3411. if (!netif_queue_stopped(dev)) {
  3412. netif_stop_queue(dev);
  3413. /* This is a hard error, log it. */
  3414. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3415. "queue awake!\n", dev->name);
  3416. }
  3417. return NETDEV_TX_BUSY;
  3418. }
  3419. entry = tp->tx_prod;
  3420. base_flags = 0;
  3421. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3422. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3423. mss = 0;
  3424. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3425. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3426. struct iphdr *iph;
  3427. int tcp_opt_len, ip_tcp_len, hdr_len;
  3428. if (skb_header_cloned(skb) &&
  3429. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3430. dev_kfree_skb(skb);
  3431. goto out_unlock;
  3432. }
  3433. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3434. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3435. hdr_len = ip_tcp_len + tcp_opt_len;
  3436. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3437. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3438. return (tg3_tso_bug(tp, skb));
  3439. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3440. TXD_FLAG_CPU_POST_DMA);
  3441. iph = ip_hdr(skb);
  3442. iph->check = 0;
  3443. iph->tot_len = htons(mss + hdr_len);
  3444. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3445. skb->h.th->check = 0;
  3446. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3447. }
  3448. else {
  3449. skb->h.th->check = ~csum_tcpudp_magic(iph->saddr,
  3450. iph->daddr, 0,
  3451. IPPROTO_TCP, 0);
  3452. }
  3453. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3454. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3455. if (tcp_opt_len || iph->ihl > 5) {
  3456. int tsflags;
  3457. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3458. mss |= (tsflags << 11);
  3459. }
  3460. } else {
  3461. if (tcp_opt_len || iph->ihl > 5) {
  3462. int tsflags;
  3463. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3464. base_flags |= tsflags << 12;
  3465. }
  3466. }
  3467. }
  3468. #if TG3_VLAN_TAG_USED
  3469. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3470. base_flags |= (TXD_FLAG_VLAN |
  3471. (vlan_tx_tag_get(skb) << 16));
  3472. #endif
  3473. /* Queue skb data, a.k.a. the main skb fragment. */
  3474. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3475. tp->tx_buffers[entry].skb = skb;
  3476. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3477. would_hit_hwbug = 0;
  3478. if (tg3_4g_overflow_test(mapping, len))
  3479. would_hit_hwbug = 1;
  3480. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3481. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3482. entry = NEXT_TX(entry);
  3483. /* Now loop through additional data fragments, and queue them. */
  3484. if (skb_shinfo(skb)->nr_frags > 0) {
  3485. unsigned int i, last;
  3486. last = skb_shinfo(skb)->nr_frags - 1;
  3487. for (i = 0; i <= last; i++) {
  3488. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3489. len = frag->size;
  3490. mapping = pci_map_page(tp->pdev,
  3491. frag->page,
  3492. frag->page_offset,
  3493. len, PCI_DMA_TODEVICE);
  3494. tp->tx_buffers[entry].skb = NULL;
  3495. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3496. if (tg3_4g_overflow_test(mapping, len))
  3497. would_hit_hwbug = 1;
  3498. if (tg3_40bit_overflow_test(tp, mapping, len))
  3499. would_hit_hwbug = 1;
  3500. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3501. tg3_set_txd(tp, entry, mapping, len,
  3502. base_flags, (i == last)|(mss << 1));
  3503. else
  3504. tg3_set_txd(tp, entry, mapping, len,
  3505. base_flags, (i == last));
  3506. entry = NEXT_TX(entry);
  3507. }
  3508. }
  3509. if (would_hit_hwbug) {
  3510. u32 last_plus_one = entry;
  3511. u32 start;
  3512. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3513. start &= (TG3_TX_RING_SIZE - 1);
  3514. /* If the workaround fails due to memory/mapping
  3515. * failure, silently drop this packet.
  3516. */
  3517. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3518. &start, base_flags, mss))
  3519. goto out_unlock;
  3520. entry = start;
  3521. }
  3522. /* Packets are ready, update Tx producer idx local and on card. */
  3523. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3524. tp->tx_prod = entry;
  3525. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3526. netif_stop_queue(dev);
  3527. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3528. netif_wake_queue(tp->dev);
  3529. }
  3530. out_unlock:
  3531. mmiowb();
  3532. dev->trans_start = jiffies;
  3533. return NETDEV_TX_OK;
  3534. }
  3535. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3536. int new_mtu)
  3537. {
  3538. dev->mtu = new_mtu;
  3539. if (new_mtu > ETH_DATA_LEN) {
  3540. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3541. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3542. ethtool_op_set_tso(dev, 0);
  3543. }
  3544. else
  3545. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3546. } else {
  3547. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3548. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3549. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3550. }
  3551. }
  3552. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3553. {
  3554. struct tg3 *tp = netdev_priv(dev);
  3555. int err;
  3556. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3557. return -EINVAL;
  3558. if (!netif_running(dev)) {
  3559. /* We'll just catch it later when the
  3560. * device is up'd.
  3561. */
  3562. tg3_set_mtu(dev, tp, new_mtu);
  3563. return 0;
  3564. }
  3565. tg3_netif_stop(tp);
  3566. tg3_full_lock(tp, 1);
  3567. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3568. tg3_set_mtu(dev, tp, new_mtu);
  3569. err = tg3_restart_hw(tp, 0);
  3570. if (!err)
  3571. tg3_netif_start(tp);
  3572. tg3_full_unlock(tp);
  3573. return err;
  3574. }
  3575. /* Free up pending packets in all rx/tx rings.
  3576. *
  3577. * The chip has been shut down and the driver detached from
  3578. * the networking, so no interrupts or new tx packets will
  3579. * end up in the driver. tp->{tx,}lock is not held and we are not
  3580. * in an interrupt context and thus may sleep.
  3581. */
  3582. static void tg3_free_rings(struct tg3 *tp)
  3583. {
  3584. struct ring_info *rxp;
  3585. int i;
  3586. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3587. rxp = &tp->rx_std_buffers[i];
  3588. if (rxp->skb == NULL)
  3589. continue;
  3590. pci_unmap_single(tp->pdev,
  3591. pci_unmap_addr(rxp, mapping),
  3592. tp->rx_pkt_buf_sz - tp->rx_offset,
  3593. PCI_DMA_FROMDEVICE);
  3594. dev_kfree_skb_any(rxp->skb);
  3595. rxp->skb = NULL;
  3596. }
  3597. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3598. rxp = &tp->rx_jumbo_buffers[i];
  3599. if (rxp->skb == NULL)
  3600. continue;
  3601. pci_unmap_single(tp->pdev,
  3602. pci_unmap_addr(rxp, mapping),
  3603. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3604. PCI_DMA_FROMDEVICE);
  3605. dev_kfree_skb_any(rxp->skb);
  3606. rxp->skb = NULL;
  3607. }
  3608. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3609. struct tx_ring_info *txp;
  3610. struct sk_buff *skb;
  3611. int j;
  3612. txp = &tp->tx_buffers[i];
  3613. skb = txp->skb;
  3614. if (skb == NULL) {
  3615. i++;
  3616. continue;
  3617. }
  3618. pci_unmap_single(tp->pdev,
  3619. pci_unmap_addr(txp, mapping),
  3620. skb_headlen(skb),
  3621. PCI_DMA_TODEVICE);
  3622. txp->skb = NULL;
  3623. i++;
  3624. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3625. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3626. pci_unmap_page(tp->pdev,
  3627. pci_unmap_addr(txp, mapping),
  3628. skb_shinfo(skb)->frags[j].size,
  3629. PCI_DMA_TODEVICE);
  3630. i++;
  3631. }
  3632. dev_kfree_skb_any(skb);
  3633. }
  3634. }
  3635. /* Initialize tx/rx rings for packet processing.
  3636. *
  3637. * The chip has been shut down and the driver detached from
  3638. * the networking, so no interrupts or new tx packets will
  3639. * end up in the driver. tp->{tx,}lock are held and thus
  3640. * we may not sleep.
  3641. */
  3642. static int tg3_init_rings(struct tg3 *tp)
  3643. {
  3644. u32 i;
  3645. /* Free up all the SKBs. */
  3646. tg3_free_rings(tp);
  3647. /* Zero out all descriptors. */
  3648. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3649. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3650. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3651. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3652. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3653. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3654. (tp->dev->mtu > ETH_DATA_LEN))
  3655. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3656. /* Initialize invariants of the rings, we only set this
  3657. * stuff once. This works because the card does not
  3658. * write into the rx buffer posting rings.
  3659. */
  3660. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3661. struct tg3_rx_buffer_desc *rxd;
  3662. rxd = &tp->rx_std[i];
  3663. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3664. << RXD_LEN_SHIFT;
  3665. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3666. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3667. (i << RXD_OPAQUE_INDEX_SHIFT));
  3668. }
  3669. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3670. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3671. struct tg3_rx_buffer_desc *rxd;
  3672. rxd = &tp->rx_jumbo[i];
  3673. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3674. << RXD_LEN_SHIFT;
  3675. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3676. RXD_FLAG_JUMBO;
  3677. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3678. (i << RXD_OPAQUE_INDEX_SHIFT));
  3679. }
  3680. }
  3681. /* Now allocate fresh SKBs for each rx ring. */
  3682. for (i = 0; i < tp->rx_pending; i++) {
  3683. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3684. printk(KERN_WARNING PFX
  3685. "%s: Using a smaller RX standard ring, "
  3686. "only %d out of %d buffers were allocated "
  3687. "successfully.\n",
  3688. tp->dev->name, i, tp->rx_pending);
  3689. if (i == 0)
  3690. return -ENOMEM;
  3691. tp->rx_pending = i;
  3692. break;
  3693. }
  3694. }
  3695. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3696. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3697. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3698. -1, i) < 0) {
  3699. printk(KERN_WARNING PFX
  3700. "%s: Using a smaller RX jumbo ring, "
  3701. "only %d out of %d buffers were "
  3702. "allocated successfully.\n",
  3703. tp->dev->name, i, tp->rx_jumbo_pending);
  3704. if (i == 0) {
  3705. tg3_free_rings(tp);
  3706. return -ENOMEM;
  3707. }
  3708. tp->rx_jumbo_pending = i;
  3709. break;
  3710. }
  3711. }
  3712. }
  3713. return 0;
  3714. }
  3715. /*
  3716. * Must not be invoked with interrupt sources disabled and
  3717. * the hardware shutdown down.
  3718. */
  3719. static void tg3_free_consistent(struct tg3 *tp)
  3720. {
  3721. kfree(tp->rx_std_buffers);
  3722. tp->rx_std_buffers = NULL;
  3723. if (tp->rx_std) {
  3724. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3725. tp->rx_std, tp->rx_std_mapping);
  3726. tp->rx_std = NULL;
  3727. }
  3728. if (tp->rx_jumbo) {
  3729. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3730. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3731. tp->rx_jumbo = NULL;
  3732. }
  3733. if (tp->rx_rcb) {
  3734. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3735. tp->rx_rcb, tp->rx_rcb_mapping);
  3736. tp->rx_rcb = NULL;
  3737. }
  3738. if (tp->tx_ring) {
  3739. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3740. tp->tx_ring, tp->tx_desc_mapping);
  3741. tp->tx_ring = NULL;
  3742. }
  3743. if (tp->hw_status) {
  3744. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3745. tp->hw_status, tp->status_mapping);
  3746. tp->hw_status = NULL;
  3747. }
  3748. if (tp->hw_stats) {
  3749. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3750. tp->hw_stats, tp->stats_mapping);
  3751. tp->hw_stats = NULL;
  3752. }
  3753. }
  3754. /*
  3755. * Must not be invoked with interrupt sources disabled and
  3756. * the hardware shutdown down. Can sleep.
  3757. */
  3758. static int tg3_alloc_consistent(struct tg3 *tp)
  3759. {
  3760. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  3761. (TG3_RX_RING_SIZE +
  3762. TG3_RX_JUMBO_RING_SIZE)) +
  3763. (sizeof(struct tx_ring_info) *
  3764. TG3_TX_RING_SIZE),
  3765. GFP_KERNEL);
  3766. if (!tp->rx_std_buffers)
  3767. return -ENOMEM;
  3768. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3769. tp->tx_buffers = (struct tx_ring_info *)
  3770. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3771. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3772. &tp->rx_std_mapping);
  3773. if (!tp->rx_std)
  3774. goto err_out;
  3775. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3776. &tp->rx_jumbo_mapping);
  3777. if (!tp->rx_jumbo)
  3778. goto err_out;
  3779. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3780. &tp->rx_rcb_mapping);
  3781. if (!tp->rx_rcb)
  3782. goto err_out;
  3783. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3784. &tp->tx_desc_mapping);
  3785. if (!tp->tx_ring)
  3786. goto err_out;
  3787. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3788. TG3_HW_STATUS_SIZE,
  3789. &tp->status_mapping);
  3790. if (!tp->hw_status)
  3791. goto err_out;
  3792. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3793. sizeof(struct tg3_hw_stats),
  3794. &tp->stats_mapping);
  3795. if (!tp->hw_stats)
  3796. goto err_out;
  3797. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3798. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3799. return 0;
  3800. err_out:
  3801. tg3_free_consistent(tp);
  3802. return -ENOMEM;
  3803. }
  3804. #define MAX_WAIT_CNT 1000
  3805. /* To stop a block, clear the enable bit and poll till it
  3806. * clears. tp->lock is held.
  3807. */
  3808. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3809. {
  3810. unsigned int i;
  3811. u32 val;
  3812. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3813. switch (ofs) {
  3814. case RCVLSC_MODE:
  3815. case DMAC_MODE:
  3816. case MBFREE_MODE:
  3817. case BUFMGR_MODE:
  3818. case MEMARB_MODE:
  3819. /* We can't enable/disable these bits of the
  3820. * 5705/5750, just say success.
  3821. */
  3822. return 0;
  3823. default:
  3824. break;
  3825. };
  3826. }
  3827. val = tr32(ofs);
  3828. val &= ~enable_bit;
  3829. tw32_f(ofs, val);
  3830. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3831. udelay(100);
  3832. val = tr32(ofs);
  3833. if ((val & enable_bit) == 0)
  3834. break;
  3835. }
  3836. if (i == MAX_WAIT_CNT && !silent) {
  3837. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3838. "ofs=%lx enable_bit=%x\n",
  3839. ofs, enable_bit);
  3840. return -ENODEV;
  3841. }
  3842. return 0;
  3843. }
  3844. /* tp->lock is held. */
  3845. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3846. {
  3847. int i, err;
  3848. tg3_disable_ints(tp);
  3849. tp->rx_mode &= ~RX_MODE_ENABLE;
  3850. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3851. udelay(10);
  3852. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3853. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3854. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3855. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3856. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3857. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3858. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3859. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3860. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3861. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3862. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3863. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3864. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3865. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3866. tw32_f(MAC_MODE, tp->mac_mode);
  3867. udelay(40);
  3868. tp->tx_mode &= ~TX_MODE_ENABLE;
  3869. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3870. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3871. udelay(100);
  3872. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3873. break;
  3874. }
  3875. if (i >= MAX_WAIT_CNT) {
  3876. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3877. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3878. tp->dev->name, tr32(MAC_TX_MODE));
  3879. err |= -ENODEV;
  3880. }
  3881. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3882. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3883. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3884. tw32(FTQ_RESET, 0xffffffff);
  3885. tw32(FTQ_RESET, 0x00000000);
  3886. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3887. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3888. if (tp->hw_status)
  3889. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3890. if (tp->hw_stats)
  3891. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3892. return err;
  3893. }
  3894. /* tp->lock is held. */
  3895. static int tg3_nvram_lock(struct tg3 *tp)
  3896. {
  3897. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3898. int i;
  3899. if (tp->nvram_lock_cnt == 0) {
  3900. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3901. for (i = 0; i < 8000; i++) {
  3902. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3903. break;
  3904. udelay(20);
  3905. }
  3906. if (i == 8000) {
  3907. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3908. return -ENODEV;
  3909. }
  3910. }
  3911. tp->nvram_lock_cnt++;
  3912. }
  3913. return 0;
  3914. }
  3915. /* tp->lock is held. */
  3916. static void tg3_nvram_unlock(struct tg3 *tp)
  3917. {
  3918. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3919. if (tp->nvram_lock_cnt > 0)
  3920. tp->nvram_lock_cnt--;
  3921. if (tp->nvram_lock_cnt == 0)
  3922. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3923. }
  3924. }
  3925. /* tp->lock is held. */
  3926. static void tg3_enable_nvram_access(struct tg3 *tp)
  3927. {
  3928. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3929. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3930. u32 nvaccess = tr32(NVRAM_ACCESS);
  3931. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3932. }
  3933. }
  3934. /* tp->lock is held. */
  3935. static void tg3_disable_nvram_access(struct tg3 *tp)
  3936. {
  3937. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3938. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3939. u32 nvaccess = tr32(NVRAM_ACCESS);
  3940. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3941. }
  3942. }
  3943. /* tp->lock is held. */
  3944. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3945. {
  3946. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3947. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3948. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3949. switch (kind) {
  3950. case RESET_KIND_INIT:
  3951. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3952. DRV_STATE_START);
  3953. break;
  3954. case RESET_KIND_SHUTDOWN:
  3955. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3956. DRV_STATE_UNLOAD);
  3957. break;
  3958. case RESET_KIND_SUSPEND:
  3959. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3960. DRV_STATE_SUSPEND);
  3961. break;
  3962. default:
  3963. break;
  3964. };
  3965. }
  3966. }
  3967. /* tp->lock is held. */
  3968. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  3969. {
  3970. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3971. switch (kind) {
  3972. case RESET_KIND_INIT:
  3973. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3974. DRV_STATE_START_DONE);
  3975. break;
  3976. case RESET_KIND_SHUTDOWN:
  3977. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3978. DRV_STATE_UNLOAD_DONE);
  3979. break;
  3980. default:
  3981. break;
  3982. };
  3983. }
  3984. }
  3985. /* tp->lock is held. */
  3986. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  3987. {
  3988. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  3989. switch (kind) {
  3990. case RESET_KIND_INIT:
  3991. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3992. DRV_STATE_START);
  3993. break;
  3994. case RESET_KIND_SHUTDOWN:
  3995. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3996. DRV_STATE_UNLOAD);
  3997. break;
  3998. case RESET_KIND_SUSPEND:
  3999. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4000. DRV_STATE_SUSPEND);
  4001. break;
  4002. default:
  4003. break;
  4004. };
  4005. }
  4006. }
  4007. static int tg3_poll_fw(struct tg3 *tp)
  4008. {
  4009. int i;
  4010. u32 val;
  4011. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4012. /* Wait up to 20ms for init done. */
  4013. for (i = 0; i < 200; i++) {
  4014. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4015. return 0;
  4016. udelay(100);
  4017. }
  4018. return -ENODEV;
  4019. }
  4020. /* Wait for firmware initialization to complete. */
  4021. for (i = 0; i < 100000; i++) {
  4022. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4023. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4024. break;
  4025. udelay(10);
  4026. }
  4027. /* Chip might not be fitted with firmware. Some Sun onboard
  4028. * parts are configured like that. So don't signal the timeout
  4029. * of the above loop as an error, but do report the lack of
  4030. * running firmware once.
  4031. */
  4032. if (i >= 100000 &&
  4033. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4034. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4035. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4036. tp->dev->name);
  4037. }
  4038. return 0;
  4039. }
  4040. static void tg3_stop_fw(struct tg3 *);
  4041. /* tp->lock is held. */
  4042. static int tg3_chip_reset(struct tg3 *tp)
  4043. {
  4044. u32 val;
  4045. void (*write_op)(struct tg3 *, u32, u32);
  4046. int err;
  4047. tg3_nvram_lock(tp);
  4048. /* No matching tg3_nvram_unlock() after this because
  4049. * chip reset below will undo the nvram lock.
  4050. */
  4051. tp->nvram_lock_cnt = 0;
  4052. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4053. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4054. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  4055. tw32(GRC_FASTBOOT_PC, 0);
  4056. /*
  4057. * We must avoid the readl() that normally takes place.
  4058. * It locks machines, causes machine checks, and other
  4059. * fun things. So, temporarily disable the 5701
  4060. * hardware workaround, while we do the reset.
  4061. */
  4062. write_op = tp->write32;
  4063. if (write_op == tg3_write_flush_reg32)
  4064. tp->write32 = tg3_write32;
  4065. /* Prevent the irq handler from reading or writing PCI registers
  4066. * during chip reset when the memory enable bit in the PCI command
  4067. * register may be cleared. The chip does not generate interrupt
  4068. * at this time, but the irq handler may still be called due to irq
  4069. * sharing or irqpoll.
  4070. */
  4071. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4072. if (tp->hw_status) {
  4073. tp->hw_status->status = 0;
  4074. tp->hw_status->status_tag = 0;
  4075. }
  4076. tp->last_tag = 0;
  4077. smp_mb();
  4078. synchronize_irq(tp->pdev->irq);
  4079. /* do the reset */
  4080. val = GRC_MISC_CFG_CORECLK_RESET;
  4081. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4082. if (tr32(0x7e2c) == 0x60) {
  4083. tw32(0x7e2c, 0x20);
  4084. }
  4085. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4086. tw32(GRC_MISC_CFG, (1 << 29));
  4087. val |= (1 << 29);
  4088. }
  4089. }
  4090. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4091. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4092. tw32(GRC_VCPU_EXT_CTRL,
  4093. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4094. }
  4095. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4096. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4097. tw32(GRC_MISC_CFG, val);
  4098. /* restore 5701 hardware bug workaround write method */
  4099. tp->write32 = write_op;
  4100. /* Unfortunately, we have to delay before the PCI read back.
  4101. * Some 575X chips even will not respond to a PCI cfg access
  4102. * when the reset command is given to the chip.
  4103. *
  4104. * How do these hardware designers expect things to work
  4105. * properly if the PCI write is posted for a long period
  4106. * of time? It is always necessary to have some method by
  4107. * which a register read back can occur to push the write
  4108. * out which does the reset.
  4109. *
  4110. * For most tg3 variants the trick below was working.
  4111. * Ho hum...
  4112. */
  4113. udelay(120);
  4114. /* Flush PCI posted writes. The normal MMIO registers
  4115. * are inaccessible at this time so this is the only
  4116. * way to make this reliably (actually, this is no longer
  4117. * the case, see above). I tried to use indirect
  4118. * register read/write but this upset some 5701 variants.
  4119. */
  4120. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4121. udelay(120);
  4122. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4123. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4124. int i;
  4125. u32 cfg_val;
  4126. /* Wait for link training to complete. */
  4127. for (i = 0; i < 5000; i++)
  4128. udelay(100);
  4129. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4130. pci_write_config_dword(tp->pdev, 0xc4,
  4131. cfg_val | (1 << 15));
  4132. }
  4133. /* Set PCIE max payload size and clear error status. */
  4134. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4135. }
  4136. /* Re-enable indirect register accesses. */
  4137. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4138. tp->misc_host_ctrl);
  4139. /* Set MAX PCI retry to zero. */
  4140. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4141. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4142. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4143. val |= PCISTATE_RETRY_SAME_DMA;
  4144. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4145. pci_restore_state(tp->pdev);
  4146. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4147. /* Make sure PCI-X relaxed ordering bit is clear. */
  4148. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4149. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4150. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4151. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4152. u32 val;
  4153. /* Chip reset on 5780 will reset MSI enable bit,
  4154. * so need to restore it.
  4155. */
  4156. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4157. u16 ctrl;
  4158. pci_read_config_word(tp->pdev,
  4159. tp->msi_cap + PCI_MSI_FLAGS,
  4160. &ctrl);
  4161. pci_write_config_word(tp->pdev,
  4162. tp->msi_cap + PCI_MSI_FLAGS,
  4163. ctrl | PCI_MSI_FLAGS_ENABLE);
  4164. val = tr32(MSGINT_MODE);
  4165. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4166. }
  4167. val = tr32(MEMARB_MODE);
  4168. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4169. } else
  4170. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4171. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4172. tg3_stop_fw(tp);
  4173. tw32(0x5000, 0x400);
  4174. }
  4175. tw32(GRC_MODE, tp->grc_mode);
  4176. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4177. u32 val = tr32(0xc4);
  4178. tw32(0xc4, val | (1 << 15));
  4179. }
  4180. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4181. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4182. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4183. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4184. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4185. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4186. }
  4187. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4188. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4189. tw32_f(MAC_MODE, tp->mac_mode);
  4190. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4191. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4192. tw32_f(MAC_MODE, tp->mac_mode);
  4193. } else
  4194. tw32_f(MAC_MODE, 0);
  4195. udelay(40);
  4196. err = tg3_poll_fw(tp);
  4197. if (err)
  4198. return err;
  4199. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4200. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4201. u32 val = tr32(0x7c00);
  4202. tw32(0x7c00, val | (1 << 25));
  4203. }
  4204. /* Reprobe ASF enable state. */
  4205. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4206. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4207. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4208. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4209. u32 nic_cfg;
  4210. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4211. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4212. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4213. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4214. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4215. }
  4216. }
  4217. return 0;
  4218. }
  4219. /* tp->lock is held. */
  4220. static void tg3_stop_fw(struct tg3 *tp)
  4221. {
  4222. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4223. u32 val;
  4224. int i;
  4225. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4226. val = tr32(GRC_RX_CPU_EVENT);
  4227. val |= (1 << 14);
  4228. tw32(GRC_RX_CPU_EVENT, val);
  4229. /* Wait for RX cpu to ACK the event. */
  4230. for (i = 0; i < 100; i++) {
  4231. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4232. break;
  4233. udelay(1);
  4234. }
  4235. }
  4236. }
  4237. /* tp->lock is held. */
  4238. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4239. {
  4240. int err;
  4241. tg3_stop_fw(tp);
  4242. tg3_write_sig_pre_reset(tp, kind);
  4243. tg3_abort_hw(tp, silent);
  4244. err = tg3_chip_reset(tp);
  4245. tg3_write_sig_legacy(tp, kind);
  4246. tg3_write_sig_post_reset(tp, kind);
  4247. if (err)
  4248. return err;
  4249. return 0;
  4250. }
  4251. #define TG3_FW_RELEASE_MAJOR 0x0
  4252. #define TG3_FW_RELASE_MINOR 0x0
  4253. #define TG3_FW_RELEASE_FIX 0x0
  4254. #define TG3_FW_START_ADDR 0x08000000
  4255. #define TG3_FW_TEXT_ADDR 0x08000000
  4256. #define TG3_FW_TEXT_LEN 0x9c0
  4257. #define TG3_FW_RODATA_ADDR 0x080009c0
  4258. #define TG3_FW_RODATA_LEN 0x60
  4259. #define TG3_FW_DATA_ADDR 0x08000a40
  4260. #define TG3_FW_DATA_LEN 0x20
  4261. #define TG3_FW_SBSS_ADDR 0x08000a60
  4262. #define TG3_FW_SBSS_LEN 0xc
  4263. #define TG3_FW_BSS_ADDR 0x08000a70
  4264. #define TG3_FW_BSS_LEN 0x10
  4265. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4266. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4267. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4268. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4269. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4270. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4271. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4272. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4273. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4274. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4275. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4276. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4277. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4278. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4279. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4280. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4281. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4282. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4283. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4284. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4285. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4286. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4287. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4288. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4291. 0, 0, 0, 0, 0, 0,
  4292. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4293. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4294. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4295. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4296. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4297. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4298. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4299. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4300. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4301. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4302. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4306. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4307. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4308. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4309. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4310. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4311. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4312. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4313. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4314. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4315. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4316. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4317. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4318. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4319. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4320. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4321. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4322. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4323. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4324. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4325. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4326. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4327. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4328. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4329. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4330. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4331. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4332. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4333. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4334. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4335. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4336. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4337. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4338. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4339. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4340. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4341. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4342. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4343. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4344. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4345. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4346. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4347. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4348. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4349. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4350. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4351. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4352. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4353. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4354. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4355. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4356. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4357. };
  4358. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4359. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4360. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4361. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4362. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4363. 0x00000000
  4364. };
  4365. #if 0 /* All zeros, don't eat up space with it. */
  4366. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4367. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4368. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4369. };
  4370. #endif
  4371. #define RX_CPU_SCRATCH_BASE 0x30000
  4372. #define RX_CPU_SCRATCH_SIZE 0x04000
  4373. #define TX_CPU_SCRATCH_BASE 0x34000
  4374. #define TX_CPU_SCRATCH_SIZE 0x04000
  4375. /* tp->lock is held. */
  4376. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4377. {
  4378. int i;
  4379. BUG_ON(offset == TX_CPU_BASE &&
  4380. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4381. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4382. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4383. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4384. return 0;
  4385. }
  4386. if (offset == RX_CPU_BASE) {
  4387. for (i = 0; i < 10000; i++) {
  4388. tw32(offset + CPU_STATE, 0xffffffff);
  4389. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4390. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4391. break;
  4392. }
  4393. tw32(offset + CPU_STATE, 0xffffffff);
  4394. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4395. udelay(10);
  4396. } else {
  4397. for (i = 0; i < 10000; i++) {
  4398. tw32(offset + CPU_STATE, 0xffffffff);
  4399. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4400. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4401. break;
  4402. }
  4403. }
  4404. if (i >= 10000) {
  4405. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4406. "and %s CPU\n",
  4407. tp->dev->name,
  4408. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4409. return -ENODEV;
  4410. }
  4411. /* Clear firmware's nvram arbitration. */
  4412. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4413. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4414. return 0;
  4415. }
  4416. struct fw_info {
  4417. unsigned int text_base;
  4418. unsigned int text_len;
  4419. const u32 *text_data;
  4420. unsigned int rodata_base;
  4421. unsigned int rodata_len;
  4422. const u32 *rodata_data;
  4423. unsigned int data_base;
  4424. unsigned int data_len;
  4425. const u32 *data_data;
  4426. };
  4427. /* tp->lock is held. */
  4428. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4429. int cpu_scratch_size, struct fw_info *info)
  4430. {
  4431. int err, lock_err, i;
  4432. void (*write_op)(struct tg3 *, u32, u32);
  4433. if (cpu_base == TX_CPU_BASE &&
  4434. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4435. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4436. "TX cpu firmware on %s which is 5705.\n",
  4437. tp->dev->name);
  4438. return -EINVAL;
  4439. }
  4440. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4441. write_op = tg3_write_mem;
  4442. else
  4443. write_op = tg3_write_indirect_reg32;
  4444. /* It is possible that bootcode is still loading at this point.
  4445. * Get the nvram lock first before halting the cpu.
  4446. */
  4447. lock_err = tg3_nvram_lock(tp);
  4448. err = tg3_halt_cpu(tp, cpu_base);
  4449. if (!lock_err)
  4450. tg3_nvram_unlock(tp);
  4451. if (err)
  4452. goto out;
  4453. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4454. write_op(tp, cpu_scratch_base + i, 0);
  4455. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4456. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4457. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4458. write_op(tp, (cpu_scratch_base +
  4459. (info->text_base & 0xffff) +
  4460. (i * sizeof(u32))),
  4461. (info->text_data ?
  4462. info->text_data[i] : 0));
  4463. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4464. write_op(tp, (cpu_scratch_base +
  4465. (info->rodata_base & 0xffff) +
  4466. (i * sizeof(u32))),
  4467. (info->rodata_data ?
  4468. info->rodata_data[i] : 0));
  4469. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4470. write_op(tp, (cpu_scratch_base +
  4471. (info->data_base & 0xffff) +
  4472. (i * sizeof(u32))),
  4473. (info->data_data ?
  4474. info->data_data[i] : 0));
  4475. err = 0;
  4476. out:
  4477. return err;
  4478. }
  4479. /* tp->lock is held. */
  4480. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4481. {
  4482. struct fw_info info;
  4483. int err, i;
  4484. info.text_base = TG3_FW_TEXT_ADDR;
  4485. info.text_len = TG3_FW_TEXT_LEN;
  4486. info.text_data = &tg3FwText[0];
  4487. info.rodata_base = TG3_FW_RODATA_ADDR;
  4488. info.rodata_len = TG3_FW_RODATA_LEN;
  4489. info.rodata_data = &tg3FwRodata[0];
  4490. info.data_base = TG3_FW_DATA_ADDR;
  4491. info.data_len = TG3_FW_DATA_LEN;
  4492. info.data_data = NULL;
  4493. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4494. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4495. &info);
  4496. if (err)
  4497. return err;
  4498. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4499. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4500. &info);
  4501. if (err)
  4502. return err;
  4503. /* Now startup only the RX cpu. */
  4504. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4505. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4506. for (i = 0; i < 5; i++) {
  4507. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4508. break;
  4509. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4510. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4511. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4512. udelay(1000);
  4513. }
  4514. if (i >= 5) {
  4515. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4516. "to set RX CPU PC, is %08x should be %08x\n",
  4517. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4518. TG3_FW_TEXT_ADDR);
  4519. return -ENODEV;
  4520. }
  4521. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4522. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4523. return 0;
  4524. }
  4525. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4526. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4527. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4528. #define TG3_TSO_FW_START_ADDR 0x08000000
  4529. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4530. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4531. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4532. #define TG3_TSO_FW_RODATA_LEN 0x60
  4533. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4534. #define TG3_TSO_FW_DATA_LEN 0x30
  4535. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4536. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4537. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4538. #define TG3_TSO_FW_BSS_LEN 0x894
  4539. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4540. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4541. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4542. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4543. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4544. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4545. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4546. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4547. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4548. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4549. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4550. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4551. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4552. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4553. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4554. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4555. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4556. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4557. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4558. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4559. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4560. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4561. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4562. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4563. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4564. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4565. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4566. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4567. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4568. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4569. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4570. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4571. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4572. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4573. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4574. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4575. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4576. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4577. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4578. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4579. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4580. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4581. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4582. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4583. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4584. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4585. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4586. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4587. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4588. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4589. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4590. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4591. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4592. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4593. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4594. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4595. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4596. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4597. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4598. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4599. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4600. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4601. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4602. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4603. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4604. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4605. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4606. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4607. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4608. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4609. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4610. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4611. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4612. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4613. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4614. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4615. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4616. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4617. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4618. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4619. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4620. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4621. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4622. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4623. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4624. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4625. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4626. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4627. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4628. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4629. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4630. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4631. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4632. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4633. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4634. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4635. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4636. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4637. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4638. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4639. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4640. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4641. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4642. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4643. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4644. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4645. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4646. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4647. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4648. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4649. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4650. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4651. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4652. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4653. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4654. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4655. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4656. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4657. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4658. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4659. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4660. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4661. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4662. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4663. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4664. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4665. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4666. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4667. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4668. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4669. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4670. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4671. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4672. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4673. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4674. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4675. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4676. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4677. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4678. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4679. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4680. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4681. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4682. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4683. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4684. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4685. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4686. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4687. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4688. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4689. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4690. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4691. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4692. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4693. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4694. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4695. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4696. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4697. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4698. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4699. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4700. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4701. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4702. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4703. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4704. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4705. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4706. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4707. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4708. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4709. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4710. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4711. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4712. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4713. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4714. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4715. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4716. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4717. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4718. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4719. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4720. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4721. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4722. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4723. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4724. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4725. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4726. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4727. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4728. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4729. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4730. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4731. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4732. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4733. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4734. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4735. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4736. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4737. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4738. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4739. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4740. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4741. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4742. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4743. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4744. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4745. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4746. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4747. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4748. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4749. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4750. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4751. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4752. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4753. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4754. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4755. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4756. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4757. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4758. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4759. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4760. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4761. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4762. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4763. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4764. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4765. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4766. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4767. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4768. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4769. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4770. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4771. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4772. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4773. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4774. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4775. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4776. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4777. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4778. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4779. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4780. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4781. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4782. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4783. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4784. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4785. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4786. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4787. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4788. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4789. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4790. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4791. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4792. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4793. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4794. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4795. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4796. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4797. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4798. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4799. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4800. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4801. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4802. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4803. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4804. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4805. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4806. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4807. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4808. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4809. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4810. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4811. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4812. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4813. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4814. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4815. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4816. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4817. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4818. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4819. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4820. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4821. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4822. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4823. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4824. };
  4825. static const u32 tg3TsoFwRodata[] = {
  4826. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4827. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4828. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4829. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4830. 0x00000000,
  4831. };
  4832. static const u32 tg3TsoFwData[] = {
  4833. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4834. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4835. 0x00000000,
  4836. };
  4837. /* 5705 needs a special version of the TSO firmware. */
  4838. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4839. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4840. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4841. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4842. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4843. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4844. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4845. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4846. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4847. #define TG3_TSO5_FW_DATA_LEN 0x20
  4848. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4849. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4850. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4851. #define TG3_TSO5_FW_BSS_LEN 0x88
  4852. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4853. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4854. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4855. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4856. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4857. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4858. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4859. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4860. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4861. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4862. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4863. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4864. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4865. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4866. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4867. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4868. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4869. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4870. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4871. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4872. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4873. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4874. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4875. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4876. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4877. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4878. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4879. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4880. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4881. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4882. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4883. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4884. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4885. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4886. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4887. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4888. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4889. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4890. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4891. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4892. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4893. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4894. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4895. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4896. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4897. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4898. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4899. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4900. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4901. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4902. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4903. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4904. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4905. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4906. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4907. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4908. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4909. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4910. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4911. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4912. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4913. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4914. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4915. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4916. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4917. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4918. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4919. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4920. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4921. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4922. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4923. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4924. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4925. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4926. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4927. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4928. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4929. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4930. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4931. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4932. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4933. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4934. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4935. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4936. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4937. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4938. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4939. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4940. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4941. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4942. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4943. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4944. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4945. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4946. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4947. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4948. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4949. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4950. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4951. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  4952. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  4953. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  4954. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  4955. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  4956. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  4957. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  4958. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  4959. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4960. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4961. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  4962. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  4963. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  4964. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  4965. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  4966. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  4967. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  4968. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  4969. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  4970. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4971. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4972. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  4973. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  4974. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  4975. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  4976. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4977. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  4978. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  4979. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  4980. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  4981. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  4982. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  4983. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  4984. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  4985. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  4986. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  4987. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  4988. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  4989. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  4990. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  4991. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  4992. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  4993. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  4994. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  4995. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  4996. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  4997. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  4998. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  4999. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  5000. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  5001. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  5002. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  5003. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  5004. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  5005. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5006. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5007. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5008. 0x00000000, 0x00000000, 0x00000000,
  5009. };
  5010. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5011. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5012. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5013. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5014. 0x00000000, 0x00000000, 0x00000000,
  5015. };
  5016. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5017. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5018. 0x00000000, 0x00000000, 0x00000000,
  5019. };
  5020. /* tp->lock is held. */
  5021. static int tg3_load_tso_firmware(struct tg3 *tp)
  5022. {
  5023. struct fw_info info;
  5024. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5025. int err, i;
  5026. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5027. return 0;
  5028. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5029. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5030. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5031. info.text_data = &tg3Tso5FwText[0];
  5032. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5033. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5034. info.rodata_data = &tg3Tso5FwRodata[0];
  5035. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5036. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5037. info.data_data = &tg3Tso5FwData[0];
  5038. cpu_base = RX_CPU_BASE;
  5039. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5040. cpu_scratch_size = (info.text_len +
  5041. info.rodata_len +
  5042. info.data_len +
  5043. TG3_TSO5_FW_SBSS_LEN +
  5044. TG3_TSO5_FW_BSS_LEN);
  5045. } else {
  5046. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5047. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5048. info.text_data = &tg3TsoFwText[0];
  5049. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5050. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5051. info.rodata_data = &tg3TsoFwRodata[0];
  5052. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5053. info.data_len = TG3_TSO_FW_DATA_LEN;
  5054. info.data_data = &tg3TsoFwData[0];
  5055. cpu_base = TX_CPU_BASE;
  5056. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5057. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5058. }
  5059. err = tg3_load_firmware_cpu(tp, cpu_base,
  5060. cpu_scratch_base, cpu_scratch_size,
  5061. &info);
  5062. if (err)
  5063. return err;
  5064. /* Now startup the cpu. */
  5065. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5066. tw32_f(cpu_base + CPU_PC, info.text_base);
  5067. for (i = 0; i < 5; i++) {
  5068. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5069. break;
  5070. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5071. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5072. tw32_f(cpu_base + CPU_PC, info.text_base);
  5073. udelay(1000);
  5074. }
  5075. if (i >= 5) {
  5076. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5077. "to set CPU PC, is %08x should be %08x\n",
  5078. tp->dev->name, tr32(cpu_base + CPU_PC),
  5079. info.text_base);
  5080. return -ENODEV;
  5081. }
  5082. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5083. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5084. return 0;
  5085. }
  5086. /* tp->lock is held. */
  5087. static void __tg3_set_mac_addr(struct tg3 *tp)
  5088. {
  5089. u32 addr_high, addr_low;
  5090. int i;
  5091. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5092. tp->dev->dev_addr[1]);
  5093. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5094. (tp->dev->dev_addr[3] << 16) |
  5095. (tp->dev->dev_addr[4] << 8) |
  5096. (tp->dev->dev_addr[5] << 0));
  5097. for (i = 0; i < 4; i++) {
  5098. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5099. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5100. }
  5101. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5102. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5103. for (i = 0; i < 12; i++) {
  5104. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5105. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5106. }
  5107. }
  5108. addr_high = (tp->dev->dev_addr[0] +
  5109. tp->dev->dev_addr[1] +
  5110. tp->dev->dev_addr[2] +
  5111. tp->dev->dev_addr[3] +
  5112. tp->dev->dev_addr[4] +
  5113. tp->dev->dev_addr[5]) &
  5114. TX_BACKOFF_SEED_MASK;
  5115. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5116. }
  5117. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5118. {
  5119. struct tg3 *tp = netdev_priv(dev);
  5120. struct sockaddr *addr = p;
  5121. int err = 0;
  5122. if (!is_valid_ether_addr(addr->sa_data))
  5123. return -EINVAL;
  5124. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5125. if (!netif_running(dev))
  5126. return 0;
  5127. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5128. /* Reset chip so that ASF can re-init any MAC addresses it
  5129. * needs.
  5130. */
  5131. tg3_netif_stop(tp);
  5132. tg3_full_lock(tp, 1);
  5133. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5134. err = tg3_restart_hw(tp, 0);
  5135. if (!err)
  5136. tg3_netif_start(tp);
  5137. tg3_full_unlock(tp);
  5138. } else {
  5139. spin_lock_bh(&tp->lock);
  5140. __tg3_set_mac_addr(tp);
  5141. spin_unlock_bh(&tp->lock);
  5142. }
  5143. return err;
  5144. }
  5145. /* tp->lock is held. */
  5146. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5147. dma_addr_t mapping, u32 maxlen_flags,
  5148. u32 nic_addr)
  5149. {
  5150. tg3_write_mem(tp,
  5151. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5152. ((u64) mapping >> 32));
  5153. tg3_write_mem(tp,
  5154. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5155. ((u64) mapping & 0xffffffff));
  5156. tg3_write_mem(tp,
  5157. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5158. maxlen_flags);
  5159. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5160. tg3_write_mem(tp,
  5161. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5162. nic_addr);
  5163. }
  5164. static void __tg3_set_rx_mode(struct net_device *);
  5165. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5166. {
  5167. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5168. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5169. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5170. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5171. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5172. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5173. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5174. }
  5175. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5176. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5177. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5178. u32 val = ec->stats_block_coalesce_usecs;
  5179. if (!netif_carrier_ok(tp->dev))
  5180. val = 0;
  5181. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5182. }
  5183. }
  5184. /* tp->lock is held. */
  5185. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5186. {
  5187. u32 val, rdmac_mode;
  5188. int i, err, limit;
  5189. tg3_disable_ints(tp);
  5190. tg3_stop_fw(tp);
  5191. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5192. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5193. tg3_abort_hw(tp, 1);
  5194. }
  5195. if (reset_phy)
  5196. tg3_phy_reset(tp);
  5197. err = tg3_chip_reset(tp);
  5198. if (err)
  5199. return err;
  5200. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5201. /* This works around an issue with Athlon chipsets on
  5202. * B3 tigon3 silicon. This bit has no effect on any
  5203. * other revision. But do not set this on PCI Express
  5204. * chips.
  5205. */
  5206. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5207. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5208. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5209. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5210. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5211. val = tr32(TG3PCI_PCISTATE);
  5212. val |= PCISTATE_RETRY_SAME_DMA;
  5213. tw32(TG3PCI_PCISTATE, val);
  5214. }
  5215. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5216. /* Enable some hw fixes. */
  5217. val = tr32(TG3PCI_MSI_DATA);
  5218. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5219. tw32(TG3PCI_MSI_DATA, val);
  5220. }
  5221. /* Descriptor ring init may make accesses to the
  5222. * NIC SRAM area to setup the TX descriptors, so we
  5223. * can only do this after the hardware has been
  5224. * successfully reset.
  5225. */
  5226. err = tg3_init_rings(tp);
  5227. if (err)
  5228. return err;
  5229. /* This value is determined during the probe time DMA
  5230. * engine test, tg3_test_dma.
  5231. */
  5232. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5233. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5234. GRC_MODE_4X_NIC_SEND_RINGS |
  5235. GRC_MODE_NO_TX_PHDR_CSUM |
  5236. GRC_MODE_NO_RX_PHDR_CSUM);
  5237. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5238. /* Pseudo-header checksum is done by hardware logic and not
  5239. * the offload processers, so make the chip do the pseudo-
  5240. * header checksums on receive. For transmit it is more
  5241. * convenient to do the pseudo-header checksum in software
  5242. * as Linux does that on transmit for us in all cases.
  5243. */
  5244. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5245. tw32(GRC_MODE,
  5246. tp->grc_mode |
  5247. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5248. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5249. val = tr32(GRC_MISC_CFG);
  5250. val &= ~0xff;
  5251. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5252. tw32(GRC_MISC_CFG, val);
  5253. /* Initialize MBUF/DESC pool. */
  5254. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5255. /* Do nothing. */
  5256. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5257. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5258. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5259. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5260. else
  5261. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5262. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5263. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5264. }
  5265. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5266. int fw_len;
  5267. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5268. TG3_TSO5_FW_RODATA_LEN +
  5269. TG3_TSO5_FW_DATA_LEN +
  5270. TG3_TSO5_FW_SBSS_LEN +
  5271. TG3_TSO5_FW_BSS_LEN);
  5272. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5273. tw32(BUFMGR_MB_POOL_ADDR,
  5274. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5275. tw32(BUFMGR_MB_POOL_SIZE,
  5276. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5277. }
  5278. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5279. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5280. tp->bufmgr_config.mbuf_read_dma_low_water);
  5281. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5282. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5283. tw32(BUFMGR_MB_HIGH_WATER,
  5284. tp->bufmgr_config.mbuf_high_water);
  5285. } else {
  5286. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5287. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5288. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5289. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5290. tw32(BUFMGR_MB_HIGH_WATER,
  5291. tp->bufmgr_config.mbuf_high_water_jumbo);
  5292. }
  5293. tw32(BUFMGR_DMA_LOW_WATER,
  5294. tp->bufmgr_config.dma_low_water);
  5295. tw32(BUFMGR_DMA_HIGH_WATER,
  5296. tp->bufmgr_config.dma_high_water);
  5297. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5298. for (i = 0; i < 2000; i++) {
  5299. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5300. break;
  5301. udelay(10);
  5302. }
  5303. if (i >= 2000) {
  5304. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5305. tp->dev->name);
  5306. return -ENODEV;
  5307. }
  5308. /* Setup replenish threshold. */
  5309. val = tp->rx_pending / 8;
  5310. if (val == 0)
  5311. val = 1;
  5312. else if (val > tp->rx_std_max_post)
  5313. val = tp->rx_std_max_post;
  5314. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5315. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5316. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5317. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5318. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5319. }
  5320. tw32(RCVBDI_STD_THRESH, val);
  5321. /* Initialize TG3_BDINFO's at:
  5322. * RCVDBDI_STD_BD: standard eth size rx ring
  5323. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5324. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5325. *
  5326. * like so:
  5327. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5328. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5329. * ring attribute flags
  5330. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5331. *
  5332. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5333. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5334. *
  5335. * The size of each ring is fixed in the firmware, but the location is
  5336. * configurable.
  5337. */
  5338. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5339. ((u64) tp->rx_std_mapping >> 32));
  5340. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5341. ((u64) tp->rx_std_mapping & 0xffffffff));
  5342. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5343. NIC_SRAM_RX_BUFFER_DESC);
  5344. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5345. * configs on 5705.
  5346. */
  5347. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5348. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5349. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5350. } else {
  5351. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5352. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5353. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5354. BDINFO_FLAGS_DISABLED);
  5355. /* Setup replenish threshold. */
  5356. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5357. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5358. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5359. ((u64) tp->rx_jumbo_mapping >> 32));
  5360. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5361. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5362. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5363. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5364. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5365. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5366. } else {
  5367. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5368. BDINFO_FLAGS_DISABLED);
  5369. }
  5370. }
  5371. /* There is only one send ring on 5705/5750, no need to explicitly
  5372. * disable the others.
  5373. */
  5374. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5375. /* Clear out send RCB ring in SRAM. */
  5376. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5377. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5378. BDINFO_FLAGS_DISABLED);
  5379. }
  5380. tp->tx_prod = 0;
  5381. tp->tx_cons = 0;
  5382. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5383. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5384. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5385. tp->tx_desc_mapping,
  5386. (TG3_TX_RING_SIZE <<
  5387. BDINFO_FLAGS_MAXLEN_SHIFT),
  5388. NIC_SRAM_TX_BUFFER_DESC);
  5389. /* There is only one receive return ring on 5705/5750, no need
  5390. * to explicitly disable the others.
  5391. */
  5392. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5393. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5394. i += TG3_BDINFO_SIZE) {
  5395. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5396. BDINFO_FLAGS_DISABLED);
  5397. }
  5398. }
  5399. tp->rx_rcb_ptr = 0;
  5400. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5401. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5402. tp->rx_rcb_mapping,
  5403. (TG3_RX_RCB_RING_SIZE(tp) <<
  5404. BDINFO_FLAGS_MAXLEN_SHIFT),
  5405. 0);
  5406. tp->rx_std_ptr = tp->rx_pending;
  5407. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5408. tp->rx_std_ptr);
  5409. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5410. tp->rx_jumbo_pending : 0;
  5411. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5412. tp->rx_jumbo_ptr);
  5413. /* Initialize MAC address and backoff seed. */
  5414. __tg3_set_mac_addr(tp);
  5415. /* MTU + ethernet header + FCS + optional VLAN tag */
  5416. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5417. /* The slot time is changed by tg3_setup_phy if we
  5418. * run at gigabit with half duplex.
  5419. */
  5420. tw32(MAC_TX_LENGTHS,
  5421. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5422. (6 << TX_LENGTHS_IPG_SHIFT) |
  5423. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5424. /* Receive rules. */
  5425. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5426. tw32(RCVLPC_CONFIG, 0x0181);
  5427. /* Calculate RDMAC_MODE setting early, we need it to determine
  5428. * the RCVLPC_STATE_ENABLE mask.
  5429. */
  5430. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5431. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5432. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5433. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5434. RDMAC_MODE_LNGREAD_ENAB);
  5435. /* If statement applies to 5705 and 5750 PCI devices only */
  5436. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5437. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5438. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5439. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5440. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5441. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5442. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5443. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5444. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5445. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5446. }
  5447. }
  5448. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5449. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5450. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5451. rdmac_mode |= (1 << 27);
  5452. /* Receive/send statistics. */
  5453. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5454. val = tr32(RCVLPC_STATS_ENABLE);
  5455. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5456. tw32(RCVLPC_STATS_ENABLE, val);
  5457. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5458. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5459. val = tr32(RCVLPC_STATS_ENABLE);
  5460. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5461. tw32(RCVLPC_STATS_ENABLE, val);
  5462. } else {
  5463. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5464. }
  5465. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5466. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5467. tw32(SNDDATAI_STATSCTRL,
  5468. (SNDDATAI_SCTRL_ENABLE |
  5469. SNDDATAI_SCTRL_FASTUPD));
  5470. /* Setup host coalescing engine. */
  5471. tw32(HOSTCC_MODE, 0);
  5472. for (i = 0; i < 2000; i++) {
  5473. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5474. break;
  5475. udelay(10);
  5476. }
  5477. __tg3_set_coalesce(tp, &tp->coal);
  5478. /* set status block DMA address */
  5479. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5480. ((u64) tp->status_mapping >> 32));
  5481. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5482. ((u64) tp->status_mapping & 0xffffffff));
  5483. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5484. /* Status/statistics block address. See tg3_timer,
  5485. * the tg3_periodic_fetch_stats call there, and
  5486. * tg3_get_stats to see how this works for 5705/5750 chips.
  5487. */
  5488. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5489. ((u64) tp->stats_mapping >> 32));
  5490. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5491. ((u64) tp->stats_mapping & 0xffffffff));
  5492. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5493. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5494. }
  5495. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5496. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5497. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5498. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5499. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5500. /* Clear statistics/status block in chip, and status block in ram. */
  5501. for (i = NIC_SRAM_STATS_BLK;
  5502. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5503. i += sizeof(u32)) {
  5504. tg3_write_mem(tp, i, 0);
  5505. udelay(40);
  5506. }
  5507. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5508. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5509. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5510. /* reset to prevent losing 1st rx packet intermittently */
  5511. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5512. udelay(10);
  5513. }
  5514. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5515. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5516. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5517. udelay(40);
  5518. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5519. * If TG3_FLG2_IS_NIC is zero, we should read the
  5520. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5521. * whether used as inputs or outputs, are set by boot code after
  5522. * reset.
  5523. */
  5524. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5525. u32 gpio_mask;
  5526. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5527. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5528. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5529. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5530. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5531. GRC_LCLCTRL_GPIO_OUTPUT3;
  5532. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5533. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5534. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5535. /* GPIO1 must be driven high for eeprom write protect */
  5536. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5537. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5538. GRC_LCLCTRL_GPIO_OUTPUT1);
  5539. }
  5540. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5541. udelay(100);
  5542. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5543. tp->last_tag = 0;
  5544. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5545. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5546. udelay(40);
  5547. }
  5548. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5549. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5550. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5551. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5552. WDMAC_MODE_LNGREAD_ENAB);
  5553. /* If statement applies to 5705 and 5750 PCI devices only */
  5554. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5555. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5556. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5557. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5558. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5559. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5560. /* nothing */
  5561. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5562. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5563. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5564. val |= WDMAC_MODE_RX_ACCEL;
  5565. }
  5566. }
  5567. /* Enable host coalescing bug fix */
  5568. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5569. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5570. val |= (1 << 29);
  5571. tw32_f(WDMAC_MODE, val);
  5572. udelay(40);
  5573. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5574. val = tr32(TG3PCI_X_CAPS);
  5575. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5576. val &= ~PCIX_CAPS_BURST_MASK;
  5577. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5578. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5579. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5580. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5581. }
  5582. tw32(TG3PCI_X_CAPS, val);
  5583. }
  5584. tw32_f(RDMAC_MODE, rdmac_mode);
  5585. udelay(40);
  5586. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5587. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5588. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5589. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5590. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5591. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5592. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5593. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5594. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5595. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5596. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5597. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5598. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5599. err = tg3_load_5701_a0_firmware_fix(tp);
  5600. if (err)
  5601. return err;
  5602. }
  5603. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5604. err = tg3_load_tso_firmware(tp);
  5605. if (err)
  5606. return err;
  5607. }
  5608. tp->tx_mode = TX_MODE_ENABLE;
  5609. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5610. udelay(100);
  5611. tp->rx_mode = RX_MODE_ENABLE;
  5612. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5613. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5614. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5615. udelay(10);
  5616. if (tp->link_config.phy_is_low_power) {
  5617. tp->link_config.phy_is_low_power = 0;
  5618. tp->link_config.speed = tp->link_config.orig_speed;
  5619. tp->link_config.duplex = tp->link_config.orig_duplex;
  5620. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5621. }
  5622. tp->mi_mode = MAC_MI_MODE_BASE;
  5623. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5624. udelay(80);
  5625. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5626. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5627. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5628. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5629. udelay(10);
  5630. }
  5631. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5632. udelay(10);
  5633. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5634. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5635. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5636. /* Set drive transmission level to 1.2V */
  5637. /* only if the signal pre-emphasis bit is not set */
  5638. val = tr32(MAC_SERDES_CFG);
  5639. val &= 0xfffff000;
  5640. val |= 0x880;
  5641. tw32(MAC_SERDES_CFG, val);
  5642. }
  5643. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5644. tw32(MAC_SERDES_CFG, 0x616000);
  5645. }
  5646. /* Prevent chip from dropping frames when flow control
  5647. * is enabled.
  5648. */
  5649. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5650. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5651. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5652. /* Use hardware link auto-negotiation */
  5653. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5654. }
  5655. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5656. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5657. u32 tmp;
  5658. tmp = tr32(SERDES_RX_CTRL);
  5659. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5660. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5661. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5662. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5663. }
  5664. err = tg3_setup_phy(tp, 0);
  5665. if (err)
  5666. return err;
  5667. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5668. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  5669. u32 tmp;
  5670. /* Clear CRC stats. */
  5671. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  5672. tg3_writephy(tp, MII_TG3_TEST1,
  5673. tmp | MII_TG3_TEST1_CRC_EN);
  5674. tg3_readphy(tp, 0x14, &tmp);
  5675. }
  5676. }
  5677. __tg3_set_rx_mode(tp->dev);
  5678. /* Initialize receive rules. */
  5679. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5680. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5681. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5682. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5683. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5684. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5685. limit = 8;
  5686. else
  5687. limit = 16;
  5688. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5689. limit -= 4;
  5690. switch (limit) {
  5691. case 16:
  5692. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5693. case 15:
  5694. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5695. case 14:
  5696. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5697. case 13:
  5698. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5699. case 12:
  5700. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5701. case 11:
  5702. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5703. case 10:
  5704. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5705. case 9:
  5706. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5707. case 8:
  5708. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5709. case 7:
  5710. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5711. case 6:
  5712. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5713. case 5:
  5714. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5715. case 4:
  5716. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5717. case 3:
  5718. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5719. case 2:
  5720. case 1:
  5721. default:
  5722. break;
  5723. };
  5724. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5725. return 0;
  5726. }
  5727. /* Called at device open time to get the chip ready for
  5728. * packet processing. Invoked with tp->lock held.
  5729. */
  5730. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5731. {
  5732. int err;
  5733. /* Force the chip into D0. */
  5734. err = tg3_set_power_state(tp, PCI_D0);
  5735. if (err)
  5736. goto out;
  5737. tg3_switch_clocks(tp);
  5738. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5739. err = tg3_reset_hw(tp, reset_phy);
  5740. out:
  5741. return err;
  5742. }
  5743. #define TG3_STAT_ADD32(PSTAT, REG) \
  5744. do { u32 __val = tr32(REG); \
  5745. (PSTAT)->low += __val; \
  5746. if ((PSTAT)->low < __val) \
  5747. (PSTAT)->high += 1; \
  5748. } while (0)
  5749. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5750. {
  5751. struct tg3_hw_stats *sp = tp->hw_stats;
  5752. if (!netif_carrier_ok(tp->dev))
  5753. return;
  5754. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5755. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5756. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5757. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5758. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5759. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5760. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5761. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5762. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5763. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5764. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5765. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5766. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5767. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5768. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5769. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5770. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5771. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5772. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5773. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5774. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5775. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5776. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5777. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5778. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5779. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5780. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5781. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5782. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5783. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5784. }
  5785. static void tg3_timer(unsigned long __opaque)
  5786. {
  5787. struct tg3 *tp = (struct tg3 *) __opaque;
  5788. if (tp->irq_sync)
  5789. goto restart_timer;
  5790. spin_lock(&tp->lock);
  5791. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5792. /* All of this garbage is because when using non-tagged
  5793. * IRQ status the mailbox/status_block protocol the chip
  5794. * uses with the cpu is race prone.
  5795. */
  5796. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5797. tw32(GRC_LOCAL_CTRL,
  5798. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5799. } else {
  5800. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5801. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5802. }
  5803. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5804. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5805. spin_unlock(&tp->lock);
  5806. schedule_work(&tp->reset_task);
  5807. return;
  5808. }
  5809. }
  5810. /* This part only runs once per second. */
  5811. if (!--tp->timer_counter) {
  5812. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5813. tg3_periodic_fetch_stats(tp);
  5814. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5815. u32 mac_stat;
  5816. int phy_event;
  5817. mac_stat = tr32(MAC_STATUS);
  5818. phy_event = 0;
  5819. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5820. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5821. phy_event = 1;
  5822. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5823. phy_event = 1;
  5824. if (phy_event)
  5825. tg3_setup_phy(tp, 0);
  5826. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5827. u32 mac_stat = tr32(MAC_STATUS);
  5828. int need_setup = 0;
  5829. if (netif_carrier_ok(tp->dev) &&
  5830. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5831. need_setup = 1;
  5832. }
  5833. if (! netif_carrier_ok(tp->dev) &&
  5834. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5835. MAC_STATUS_SIGNAL_DET))) {
  5836. need_setup = 1;
  5837. }
  5838. if (need_setup) {
  5839. if (!tp->serdes_counter) {
  5840. tw32_f(MAC_MODE,
  5841. (tp->mac_mode &
  5842. ~MAC_MODE_PORT_MODE_MASK));
  5843. udelay(40);
  5844. tw32_f(MAC_MODE, tp->mac_mode);
  5845. udelay(40);
  5846. }
  5847. tg3_setup_phy(tp, 0);
  5848. }
  5849. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5850. tg3_serdes_parallel_detect(tp);
  5851. tp->timer_counter = tp->timer_multiplier;
  5852. }
  5853. /* Heartbeat is only sent once every 2 seconds.
  5854. *
  5855. * The heartbeat is to tell the ASF firmware that the host
  5856. * driver is still alive. In the event that the OS crashes,
  5857. * ASF needs to reset the hardware to free up the FIFO space
  5858. * that may be filled with rx packets destined for the host.
  5859. * If the FIFO is full, ASF will no longer function properly.
  5860. *
  5861. * Unintended resets have been reported on real time kernels
  5862. * where the timer doesn't run on time. Netpoll will also have
  5863. * same problem.
  5864. *
  5865. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  5866. * to check the ring condition when the heartbeat is expiring
  5867. * before doing the reset. This will prevent most unintended
  5868. * resets.
  5869. */
  5870. if (!--tp->asf_counter) {
  5871. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5872. u32 val;
  5873. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5874. FWCMD_NICDRV_ALIVE3);
  5875. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5876. /* 5 seconds timeout */
  5877. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5878. val = tr32(GRC_RX_CPU_EVENT);
  5879. val |= (1 << 14);
  5880. tw32(GRC_RX_CPU_EVENT, val);
  5881. }
  5882. tp->asf_counter = tp->asf_multiplier;
  5883. }
  5884. spin_unlock(&tp->lock);
  5885. restart_timer:
  5886. tp->timer.expires = jiffies + tp->timer_offset;
  5887. add_timer(&tp->timer);
  5888. }
  5889. static int tg3_request_irq(struct tg3 *tp)
  5890. {
  5891. irq_handler_t fn;
  5892. unsigned long flags;
  5893. struct net_device *dev = tp->dev;
  5894. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5895. fn = tg3_msi;
  5896. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5897. fn = tg3_msi_1shot;
  5898. flags = IRQF_SAMPLE_RANDOM;
  5899. } else {
  5900. fn = tg3_interrupt;
  5901. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5902. fn = tg3_interrupt_tagged;
  5903. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5904. }
  5905. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5906. }
  5907. static int tg3_test_interrupt(struct tg3 *tp)
  5908. {
  5909. struct net_device *dev = tp->dev;
  5910. int err, i, intr_ok = 0;
  5911. if (!netif_running(dev))
  5912. return -ENODEV;
  5913. tg3_disable_ints(tp);
  5914. free_irq(tp->pdev->irq, dev);
  5915. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5916. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5917. if (err)
  5918. return err;
  5919. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5920. tg3_enable_ints(tp);
  5921. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5922. HOSTCC_MODE_NOW);
  5923. for (i = 0; i < 5; i++) {
  5924. u32 int_mbox, misc_host_ctrl;
  5925. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5926. TG3_64BIT_REG_LOW);
  5927. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  5928. if ((int_mbox != 0) ||
  5929. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  5930. intr_ok = 1;
  5931. break;
  5932. }
  5933. msleep(10);
  5934. }
  5935. tg3_disable_ints(tp);
  5936. free_irq(tp->pdev->irq, dev);
  5937. err = tg3_request_irq(tp);
  5938. if (err)
  5939. return err;
  5940. if (intr_ok)
  5941. return 0;
  5942. return -EIO;
  5943. }
  5944. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5945. * successfully restored
  5946. */
  5947. static int tg3_test_msi(struct tg3 *tp)
  5948. {
  5949. struct net_device *dev = tp->dev;
  5950. int err;
  5951. u16 pci_cmd;
  5952. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  5953. return 0;
  5954. /* Turn off SERR reporting in case MSI terminates with Master
  5955. * Abort.
  5956. */
  5957. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  5958. pci_write_config_word(tp->pdev, PCI_COMMAND,
  5959. pci_cmd & ~PCI_COMMAND_SERR);
  5960. err = tg3_test_interrupt(tp);
  5961. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  5962. if (!err)
  5963. return 0;
  5964. /* other failures */
  5965. if (err != -EIO)
  5966. return err;
  5967. /* MSI test failed, go back to INTx mode */
  5968. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  5969. "switching to INTx mode. Please report this failure to "
  5970. "the PCI maintainer and include system chipset information.\n",
  5971. tp->dev->name);
  5972. free_irq(tp->pdev->irq, dev);
  5973. pci_disable_msi(tp->pdev);
  5974. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5975. err = tg3_request_irq(tp);
  5976. if (err)
  5977. return err;
  5978. /* Need to reset the chip because the MSI cycle may have terminated
  5979. * with Master Abort.
  5980. */
  5981. tg3_full_lock(tp, 1);
  5982. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5983. err = tg3_init_hw(tp, 1);
  5984. tg3_full_unlock(tp);
  5985. if (err)
  5986. free_irq(tp->pdev->irq, dev);
  5987. return err;
  5988. }
  5989. static int tg3_open(struct net_device *dev)
  5990. {
  5991. struct tg3 *tp = netdev_priv(dev);
  5992. int err;
  5993. netif_carrier_off(tp->dev);
  5994. tg3_full_lock(tp, 0);
  5995. err = tg3_set_power_state(tp, PCI_D0);
  5996. if (err) {
  5997. tg3_full_unlock(tp);
  5998. return err;
  5999. }
  6000. tg3_disable_ints(tp);
  6001. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6002. tg3_full_unlock(tp);
  6003. /* The placement of this call is tied
  6004. * to the setup and use of Host TX descriptors.
  6005. */
  6006. err = tg3_alloc_consistent(tp);
  6007. if (err)
  6008. return err;
  6009. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  6010. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
  6011. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
  6012. !((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) &&
  6013. (tp->pdev_peer == tp->pdev))) {
  6014. /* All MSI supporting chips should support tagged
  6015. * status. Assert that this is the case.
  6016. */
  6017. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6018. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6019. "Not using MSI.\n", tp->dev->name);
  6020. } else if (pci_enable_msi(tp->pdev) == 0) {
  6021. u32 msi_mode;
  6022. msi_mode = tr32(MSGINT_MODE);
  6023. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6024. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6025. }
  6026. }
  6027. err = tg3_request_irq(tp);
  6028. if (err) {
  6029. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6030. pci_disable_msi(tp->pdev);
  6031. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6032. }
  6033. tg3_free_consistent(tp);
  6034. return err;
  6035. }
  6036. tg3_full_lock(tp, 0);
  6037. err = tg3_init_hw(tp, 1);
  6038. if (err) {
  6039. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6040. tg3_free_rings(tp);
  6041. } else {
  6042. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6043. tp->timer_offset = HZ;
  6044. else
  6045. tp->timer_offset = HZ / 10;
  6046. BUG_ON(tp->timer_offset > HZ);
  6047. tp->timer_counter = tp->timer_multiplier =
  6048. (HZ / tp->timer_offset);
  6049. tp->asf_counter = tp->asf_multiplier =
  6050. ((HZ / tp->timer_offset) * 2);
  6051. init_timer(&tp->timer);
  6052. tp->timer.expires = jiffies + tp->timer_offset;
  6053. tp->timer.data = (unsigned long) tp;
  6054. tp->timer.function = tg3_timer;
  6055. }
  6056. tg3_full_unlock(tp);
  6057. if (err) {
  6058. free_irq(tp->pdev->irq, dev);
  6059. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6060. pci_disable_msi(tp->pdev);
  6061. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6062. }
  6063. tg3_free_consistent(tp);
  6064. return err;
  6065. }
  6066. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6067. err = tg3_test_msi(tp);
  6068. if (err) {
  6069. tg3_full_lock(tp, 0);
  6070. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6071. pci_disable_msi(tp->pdev);
  6072. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6073. }
  6074. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6075. tg3_free_rings(tp);
  6076. tg3_free_consistent(tp);
  6077. tg3_full_unlock(tp);
  6078. return err;
  6079. }
  6080. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6081. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6082. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6083. tw32(PCIE_TRANSACTION_CFG,
  6084. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6085. }
  6086. }
  6087. }
  6088. tg3_full_lock(tp, 0);
  6089. add_timer(&tp->timer);
  6090. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6091. tg3_enable_ints(tp);
  6092. tg3_full_unlock(tp);
  6093. netif_start_queue(dev);
  6094. return 0;
  6095. }
  6096. #if 0
  6097. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6098. {
  6099. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6100. u16 val16;
  6101. int i;
  6102. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6103. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6104. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6105. val16, val32);
  6106. /* MAC block */
  6107. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6108. tr32(MAC_MODE), tr32(MAC_STATUS));
  6109. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6110. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6111. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6112. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6113. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6114. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6115. /* Send data initiator control block */
  6116. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6117. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6118. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6119. tr32(SNDDATAI_STATSCTRL));
  6120. /* Send data completion control block */
  6121. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6122. /* Send BD ring selector block */
  6123. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6124. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6125. /* Send BD initiator control block */
  6126. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6127. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6128. /* Send BD completion control block */
  6129. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6130. /* Receive list placement control block */
  6131. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6132. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6133. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6134. tr32(RCVLPC_STATSCTRL));
  6135. /* Receive data and receive BD initiator control block */
  6136. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6137. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6138. /* Receive data completion control block */
  6139. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6140. tr32(RCVDCC_MODE));
  6141. /* Receive BD initiator control block */
  6142. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6143. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6144. /* Receive BD completion control block */
  6145. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6146. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6147. /* Receive list selector control block */
  6148. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6149. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6150. /* Mbuf cluster free block */
  6151. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6152. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6153. /* Host coalescing control block */
  6154. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6155. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6156. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6157. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6158. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6159. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6160. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6161. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6162. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6163. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6164. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6165. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6166. /* Memory arbiter control block */
  6167. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6168. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6169. /* Buffer manager control block */
  6170. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6171. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6172. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6173. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6174. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6175. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6176. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6177. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6178. /* Read DMA control block */
  6179. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6180. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6181. /* Write DMA control block */
  6182. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6183. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6184. /* DMA completion block */
  6185. printk("DEBUG: DMAC_MODE[%08x]\n",
  6186. tr32(DMAC_MODE));
  6187. /* GRC block */
  6188. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6189. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6190. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6191. tr32(GRC_LOCAL_CTRL));
  6192. /* TG3_BDINFOs */
  6193. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6194. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6195. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6196. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6197. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6198. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6199. tr32(RCVDBDI_STD_BD + 0x0),
  6200. tr32(RCVDBDI_STD_BD + 0x4),
  6201. tr32(RCVDBDI_STD_BD + 0x8),
  6202. tr32(RCVDBDI_STD_BD + 0xc));
  6203. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6204. tr32(RCVDBDI_MINI_BD + 0x0),
  6205. tr32(RCVDBDI_MINI_BD + 0x4),
  6206. tr32(RCVDBDI_MINI_BD + 0x8),
  6207. tr32(RCVDBDI_MINI_BD + 0xc));
  6208. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6209. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6210. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6211. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6212. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6213. val32, val32_2, val32_3, val32_4);
  6214. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6215. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6216. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6217. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6218. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6219. val32, val32_2, val32_3, val32_4);
  6220. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6221. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6222. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6223. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6224. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6225. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6226. val32, val32_2, val32_3, val32_4, val32_5);
  6227. /* SW status block */
  6228. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6229. tp->hw_status->status,
  6230. tp->hw_status->status_tag,
  6231. tp->hw_status->rx_jumbo_consumer,
  6232. tp->hw_status->rx_consumer,
  6233. tp->hw_status->rx_mini_consumer,
  6234. tp->hw_status->idx[0].rx_producer,
  6235. tp->hw_status->idx[0].tx_consumer);
  6236. /* SW statistics block */
  6237. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6238. ((u32 *)tp->hw_stats)[0],
  6239. ((u32 *)tp->hw_stats)[1],
  6240. ((u32 *)tp->hw_stats)[2],
  6241. ((u32 *)tp->hw_stats)[3]);
  6242. /* Mailboxes */
  6243. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6244. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6245. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6246. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6247. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6248. /* NIC side send descriptors. */
  6249. for (i = 0; i < 6; i++) {
  6250. unsigned long txd;
  6251. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6252. + (i * sizeof(struct tg3_tx_buffer_desc));
  6253. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6254. i,
  6255. readl(txd + 0x0), readl(txd + 0x4),
  6256. readl(txd + 0x8), readl(txd + 0xc));
  6257. }
  6258. /* NIC side RX descriptors. */
  6259. for (i = 0; i < 6; i++) {
  6260. unsigned long rxd;
  6261. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6262. + (i * sizeof(struct tg3_rx_buffer_desc));
  6263. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6264. i,
  6265. readl(rxd + 0x0), readl(rxd + 0x4),
  6266. readl(rxd + 0x8), readl(rxd + 0xc));
  6267. rxd += (4 * sizeof(u32));
  6268. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6269. i,
  6270. readl(rxd + 0x0), readl(rxd + 0x4),
  6271. readl(rxd + 0x8), readl(rxd + 0xc));
  6272. }
  6273. for (i = 0; i < 6; i++) {
  6274. unsigned long rxd;
  6275. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6276. + (i * sizeof(struct tg3_rx_buffer_desc));
  6277. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6278. i,
  6279. readl(rxd + 0x0), readl(rxd + 0x4),
  6280. readl(rxd + 0x8), readl(rxd + 0xc));
  6281. rxd += (4 * sizeof(u32));
  6282. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6283. i,
  6284. readl(rxd + 0x0), readl(rxd + 0x4),
  6285. readl(rxd + 0x8), readl(rxd + 0xc));
  6286. }
  6287. }
  6288. #endif
  6289. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6290. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6291. static int tg3_close(struct net_device *dev)
  6292. {
  6293. struct tg3 *tp = netdev_priv(dev);
  6294. /* Calling flush_scheduled_work() may deadlock because
  6295. * linkwatch_event() may be on the workqueue and it will try to get
  6296. * the rtnl_lock which we are holding.
  6297. */
  6298. while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
  6299. msleep(1);
  6300. netif_stop_queue(dev);
  6301. del_timer_sync(&tp->timer);
  6302. tg3_full_lock(tp, 1);
  6303. #if 0
  6304. tg3_dump_state(tp);
  6305. #endif
  6306. tg3_disable_ints(tp);
  6307. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6308. tg3_free_rings(tp);
  6309. tp->tg3_flags &=
  6310. ~(TG3_FLAG_INIT_COMPLETE |
  6311. TG3_FLAG_GOT_SERDES_FLOWCTL);
  6312. tg3_full_unlock(tp);
  6313. free_irq(tp->pdev->irq, dev);
  6314. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6315. pci_disable_msi(tp->pdev);
  6316. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6317. }
  6318. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6319. sizeof(tp->net_stats_prev));
  6320. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6321. sizeof(tp->estats_prev));
  6322. tg3_free_consistent(tp);
  6323. tg3_set_power_state(tp, PCI_D3hot);
  6324. netif_carrier_off(tp->dev);
  6325. return 0;
  6326. }
  6327. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6328. {
  6329. unsigned long ret;
  6330. #if (BITS_PER_LONG == 32)
  6331. ret = val->low;
  6332. #else
  6333. ret = ((u64)val->high << 32) | ((u64)val->low);
  6334. #endif
  6335. return ret;
  6336. }
  6337. static unsigned long calc_crc_errors(struct tg3 *tp)
  6338. {
  6339. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6340. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6341. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6342. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6343. u32 val;
  6344. spin_lock_bh(&tp->lock);
  6345. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6346. tg3_writephy(tp, MII_TG3_TEST1,
  6347. val | MII_TG3_TEST1_CRC_EN);
  6348. tg3_readphy(tp, 0x14, &val);
  6349. } else
  6350. val = 0;
  6351. spin_unlock_bh(&tp->lock);
  6352. tp->phy_crc_errors += val;
  6353. return tp->phy_crc_errors;
  6354. }
  6355. return get_stat64(&hw_stats->rx_fcs_errors);
  6356. }
  6357. #define ESTAT_ADD(member) \
  6358. estats->member = old_estats->member + \
  6359. get_stat64(&hw_stats->member)
  6360. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6361. {
  6362. struct tg3_ethtool_stats *estats = &tp->estats;
  6363. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6364. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6365. if (!hw_stats)
  6366. return old_estats;
  6367. ESTAT_ADD(rx_octets);
  6368. ESTAT_ADD(rx_fragments);
  6369. ESTAT_ADD(rx_ucast_packets);
  6370. ESTAT_ADD(rx_mcast_packets);
  6371. ESTAT_ADD(rx_bcast_packets);
  6372. ESTAT_ADD(rx_fcs_errors);
  6373. ESTAT_ADD(rx_align_errors);
  6374. ESTAT_ADD(rx_xon_pause_rcvd);
  6375. ESTAT_ADD(rx_xoff_pause_rcvd);
  6376. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6377. ESTAT_ADD(rx_xoff_entered);
  6378. ESTAT_ADD(rx_frame_too_long_errors);
  6379. ESTAT_ADD(rx_jabbers);
  6380. ESTAT_ADD(rx_undersize_packets);
  6381. ESTAT_ADD(rx_in_length_errors);
  6382. ESTAT_ADD(rx_out_length_errors);
  6383. ESTAT_ADD(rx_64_or_less_octet_packets);
  6384. ESTAT_ADD(rx_65_to_127_octet_packets);
  6385. ESTAT_ADD(rx_128_to_255_octet_packets);
  6386. ESTAT_ADD(rx_256_to_511_octet_packets);
  6387. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6388. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6389. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6390. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6391. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6392. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6393. ESTAT_ADD(tx_octets);
  6394. ESTAT_ADD(tx_collisions);
  6395. ESTAT_ADD(tx_xon_sent);
  6396. ESTAT_ADD(tx_xoff_sent);
  6397. ESTAT_ADD(tx_flow_control);
  6398. ESTAT_ADD(tx_mac_errors);
  6399. ESTAT_ADD(tx_single_collisions);
  6400. ESTAT_ADD(tx_mult_collisions);
  6401. ESTAT_ADD(tx_deferred);
  6402. ESTAT_ADD(tx_excessive_collisions);
  6403. ESTAT_ADD(tx_late_collisions);
  6404. ESTAT_ADD(tx_collide_2times);
  6405. ESTAT_ADD(tx_collide_3times);
  6406. ESTAT_ADD(tx_collide_4times);
  6407. ESTAT_ADD(tx_collide_5times);
  6408. ESTAT_ADD(tx_collide_6times);
  6409. ESTAT_ADD(tx_collide_7times);
  6410. ESTAT_ADD(tx_collide_8times);
  6411. ESTAT_ADD(tx_collide_9times);
  6412. ESTAT_ADD(tx_collide_10times);
  6413. ESTAT_ADD(tx_collide_11times);
  6414. ESTAT_ADD(tx_collide_12times);
  6415. ESTAT_ADD(tx_collide_13times);
  6416. ESTAT_ADD(tx_collide_14times);
  6417. ESTAT_ADD(tx_collide_15times);
  6418. ESTAT_ADD(tx_ucast_packets);
  6419. ESTAT_ADD(tx_mcast_packets);
  6420. ESTAT_ADD(tx_bcast_packets);
  6421. ESTAT_ADD(tx_carrier_sense_errors);
  6422. ESTAT_ADD(tx_discards);
  6423. ESTAT_ADD(tx_errors);
  6424. ESTAT_ADD(dma_writeq_full);
  6425. ESTAT_ADD(dma_write_prioq_full);
  6426. ESTAT_ADD(rxbds_empty);
  6427. ESTAT_ADD(rx_discards);
  6428. ESTAT_ADD(rx_errors);
  6429. ESTAT_ADD(rx_threshold_hit);
  6430. ESTAT_ADD(dma_readq_full);
  6431. ESTAT_ADD(dma_read_prioq_full);
  6432. ESTAT_ADD(tx_comp_queue_full);
  6433. ESTAT_ADD(ring_set_send_prod_index);
  6434. ESTAT_ADD(ring_status_update);
  6435. ESTAT_ADD(nic_irqs);
  6436. ESTAT_ADD(nic_avoided_irqs);
  6437. ESTAT_ADD(nic_tx_threshold_hit);
  6438. return estats;
  6439. }
  6440. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6441. {
  6442. struct tg3 *tp = netdev_priv(dev);
  6443. struct net_device_stats *stats = &tp->net_stats;
  6444. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6445. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6446. if (!hw_stats)
  6447. return old_stats;
  6448. stats->rx_packets = old_stats->rx_packets +
  6449. get_stat64(&hw_stats->rx_ucast_packets) +
  6450. get_stat64(&hw_stats->rx_mcast_packets) +
  6451. get_stat64(&hw_stats->rx_bcast_packets);
  6452. stats->tx_packets = old_stats->tx_packets +
  6453. get_stat64(&hw_stats->tx_ucast_packets) +
  6454. get_stat64(&hw_stats->tx_mcast_packets) +
  6455. get_stat64(&hw_stats->tx_bcast_packets);
  6456. stats->rx_bytes = old_stats->rx_bytes +
  6457. get_stat64(&hw_stats->rx_octets);
  6458. stats->tx_bytes = old_stats->tx_bytes +
  6459. get_stat64(&hw_stats->tx_octets);
  6460. stats->rx_errors = old_stats->rx_errors +
  6461. get_stat64(&hw_stats->rx_errors);
  6462. stats->tx_errors = old_stats->tx_errors +
  6463. get_stat64(&hw_stats->tx_errors) +
  6464. get_stat64(&hw_stats->tx_mac_errors) +
  6465. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6466. get_stat64(&hw_stats->tx_discards);
  6467. stats->multicast = old_stats->multicast +
  6468. get_stat64(&hw_stats->rx_mcast_packets);
  6469. stats->collisions = old_stats->collisions +
  6470. get_stat64(&hw_stats->tx_collisions);
  6471. stats->rx_length_errors = old_stats->rx_length_errors +
  6472. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6473. get_stat64(&hw_stats->rx_undersize_packets);
  6474. stats->rx_over_errors = old_stats->rx_over_errors +
  6475. get_stat64(&hw_stats->rxbds_empty);
  6476. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6477. get_stat64(&hw_stats->rx_align_errors);
  6478. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6479. get_stat64(&hw_stats->tx_discards);
  6480. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6481. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6482. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6483. calc_crc_errors(tp);
  6484. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6485. get_stat64(&hw_stats->rx_discards);
  6486. return stats;
  6487. }
  6488. static inline u32 calc_crc(unsigned char *buf, int len)
  6489. {
  6490. u32 reg;
  6491. u32 tmp;
  6492. int j, k;
  6493. reg = 0xffffffff;
  6494. for (j = 0; j < len; j++) {
  6495. reg ^= buf[j];
  6496. for (k = 0; k < 8; k++) {
  6497. tmp = reg & 0x01;
  6498. reg >>= 1;
  6499. if (tmp) {
  6500. reg ^= 0xedb88320;
  6501. }
  6502. }
  6503. }
  6504. return ~reg;
  6505. }
  6506. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6507. {
  6508. /* accept or reject all multicast frames */
  6509. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6510. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6511. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6512. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6513. }
  6514. static void __tg3_set_rx_mode(struct net_device *dev)
  6515. {
  6516. struct tg3 *tp = netdev_priv(dev);
  6517. u32 rx_mode;
  6518. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6519. RX_MODE_KEEP_VLAN_TAG);
  6520. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6521. * flag clear.
  6522. */
  6523. #if TG3_VLAN_TAG_USED
  6524. if (!tp->vlgrp &&
  6525. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6526. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6527. #else
  6528. /* By definition, VLAN is disabled always in this
  6529. * case.
  6530. */
  6531. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6532. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6533. #endif
  6534. if (dev->flags & IFF_PROMISC) {
  6535. /* Promiscuous mode. */
  6536. rx_mode |= RX_MODE_PROMISC;
  6537. } else if (dev->flags & IFF_ALLMULTI) {
  6538. /* Accept all multicast. */
  6539. tg3_set_multi (tp, 1);
  6540. } else if (dev->mc_count < 1) {
  6541. /* Reject all multicast. */
  6542. tg3_set_multi (tp, 0);
  6543. } else {
  6544. /* Accept one or more multicast(s). */
  6545. struct dev_mc_list *mclist;
  6546. unsigned int i;
  6547. u32 mc_filter[4] = { 0, };
  6548. u32 regidx;
  6549. u32 bit;
  6550. u32 crc;
  6551. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6552. i++, mclist = mclist->next) {
  6553. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6554. bit = ~crc & 0x7f;
  6555. regidx = (bit & 0x60) >> 5;
  6556. bit &= 0x1f;
  6557. mc_filter[regidx] |= (1 << bit);
  6558. }
  6559. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6560. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6561. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6562. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6563. }
  6564. if (rx_mode != tp->rx_mode) {
  6565. tp->rx_mode = rx_mode;
  6566. tw32_f(MAC_RX_MODE, rx_mode);
  6567. udelay(10);
  6568. }
  6569. }
  6570. static void tg3_set_rx_mode(struct net_device *dev)
  6571. {
  6572. struct tg3 *tp = netdev_priv(dev);
  6573. if (!netif_running(dev))
  6574. return;
  6575. tg3_full_lock(tp, 0);
  6576. __tg3_set_rx_mode(dev);
  6577. tg3_full_unlock(tp);
  6578. }
  6579. #define TG3_REGDUMP_LEN (32 * 1024)
  6580. static int tg3_get_regs_len(struct net_device *dev)
  6581. {
  6582. return TG3_REGDUMP_LEN;
  6583. }
  6584. static void tg3_get_regs(struct net_device *dev,
  6585. struct ethtool_regs *regs, void *_p)
  6586. {
  6587. u32 *p = _p;
  6588. struct tg3 *tp = netdev_priv(dev);
  6589. u8 *orig_p = _p;
  6590. int i;
  6591. regs->version = 0;
  6592. memset(p, 0, TG3_REGDUMP_LEN);
  6593. if (tp->link_config.phy_is_low_power)
  6594. return;
  6595. tg3_full_lock(tp, 0);
  6596. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6597. #define GET_REG32_LOOP(base,len) \
  6598. do { p = (u32 *)(orig_p + (base)); \
  6599. for (i = 0; i < len; i += 4) \
  6600. __GET_REG32((base) + i); \
  6601. } while (0)
  6602. #define GET_REG32_1(reg) \
  6603. do { p = (u32 *)(orig_p + (reg)); \
  6604. __GET_REG32((reg)); \
  6605. } while (0)
  6606. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6607. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6608. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6609. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6610. GET_REG32_1(SNDDATAC_MODE);
  6611. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6612. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6613. GET_REG32_1(SNDBDC_MODE);
  6614. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6615. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6616. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6617. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6618. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6619. GET_REG32_1(RCVDCC_MODE);
  6620. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6621. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6622. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6623. GET_REG32_1(MBFREE_MODE);
  6624. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6625. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6626. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6627. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6628. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6629. GET_REG32_1(RX_CPU_MODE);
  6630. GET_REG32_1(RX_CPU_STATE);
  6631. GET_REG32_1(RX_CPU_PGMCTR);
  6632. GET_REG32_1(RX_CPU_HWBKPT);
  6633. GET_REG32_1(TX_CPU_MODE);
  6634. GET_REG32_1(TX_CPU_STATE);
  6635. GET_REG32_1(TX_CPU_PGMCTR);
  6636. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6637. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6638. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6639. GET_REG32_1(DMAC_MODE);
  6640. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6641. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6642. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6643. #undef __GET_REG32
  6644. #undef GET_REG32_LOOP
  6645. #undef GET_REG32_1
  6646. tg3_full_unlock(tp);
  6647. }
  6648. static int tg3_get_eeprom_len(struct net_device *dev)
  6649. {
  6650. struct tg3 *tp = netdev_priv(dev);
  6651. return tp->nvram_size;
  6652. }
  6653. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6654. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6655. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6656. {
  6657. struct tg3 *tp = netdev_priv(dev);
  6658. int ret;
  6659. u8 *pd;
  6660. u32 i, offset, len, val, b_offset, b_count;
  6661. if (tp->link_config.phy_is_low_power)
  6662. return -EAGAIN;
  6663. offset = eeprom->offset;
  6664. len = eeprom->len;
  6665. eeprom->len = 0;
  6666. eeprom->magic = TG3_EEPROM_MAGIC;
  6667. if (offset & 3) {
  6668. /* adjustments to start on required 4 byte boundary */
  6669. b_offset = offset & 3;
  6670. b_count = 4 - b_offset;
  6671. if (b_count > len) {
  6672. /* i.e. offset=1 len=2 */
  6673. b_count = len;
  6674. }
  6675. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6676. if (ret)
  6677. return ret;
  6678. val = cpu_to_le32(val);
  6679. memcpy(data, ((char*)&val) + b_offset, b_count);
  6680. len -= b_count;
  6681. offset += b_count;
  6682. eeprom->len += b_count;
  6683. }
  6684. /* read bytes upto the last 4 byte boundary */
  6685. pd = &data[eeprom->len];
  6686. for (i = 0; i < (len - (len & 3)); i += 4) {
  6687. ret = tg3_nvram_read(tp, offset + i, &val);
  6688. if (ret) {
  6689. eeprom->len += i;
  6690. return ret;
  6691. }
  6692. val = cpu_to_le32(val);
  6693. memcpy(pd + i, &val, 4);
  6694. }
  6695. eeprom->len += i;
  6696. if (len & 3) {
  6697. /* read last bytes not ending on 4 byte boundary */
  6698. pd = &data[eeprom->len];
  6699. b_count = len & 3;
  6700. b_offset = offset + len - b_count;
  6701. ret = tg3_nvram_read(tp, b_offset, &val);
  6702. if (ret)
  6703. return ret;
  6704. val = cpu_to_le32(val);
  6705. memcpy(pd, ((char*)&val), b_count);
  6706. eeprom->len += b_count;
  6707. }
  6708. return 0;
  6709. }
  6710. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6711. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6712. {
  6713. struct tg3 *tp = netdev_priv(dev);
  6714. int ret;
  6715. u32 offset, len, b_offset, odd_len, start, end;
  6716. u8 *buf;
  6717. if (tp->link_config.phy_is_low_power)
  6718. return -EAGAIN;
  6719. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6720. return -EINVAL;
  6721. offset = eeprom->offset;
  6722. len = eeprom->len;
  6723. if ((b_offset = (offset & 3))) {
  6724. /* adjustments to start on required 4 byte boundary */
  6725. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6726. if (ret)
  6727. return ret;
  6728. start = cpu_to_le32(start);
  6729. len += b_offset;
  6730. offset &= ~3;
  6731. if (len < 4)
  6732. len = 4;
  6733. }
  6734. odd_len = 0;
  6735. if (len & 3) {
  6736. /* adjustments to end on required 4 byte boundary */
  6737. odd_len = 1;
  6738. len = (len + 3) & ~3;
  6739. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6740. if (ret)
  6741. return ret;
  6742. end = cpu_to_le32(end);
  6743. }
  6744. buf = data;
  6745. if (b_offset || odd_len) {
  6746. buf = kmalloc(len, GFP_KERNEL);
  6747. if (buf == 0)
  6748. return -ENOMEM;
  6749. if (b_offset)
  6750. memcpy(buf, &start, 4);
  6751. if (odd_len)
  6752. memcpy(buf+len-4, &end, 4);
  6753. memcpy(buf + b_offset, data, eeprom->len);
  6754. }
  6755. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6756. if (buf != data)
  6757. kfree(buf);
  6758. return ret;
  6759. }
  6760. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6761. {
  6762. struct tg3 *tp = netdev_priv(dev);
  6763. cmd->supported = (SUPPORTED_Autoneg);
  6764. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6765. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6766. SUPPORTED_1000baseT_Full);
  6767. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6768. cmd->supported |= (SUPPORTED_100baseT_Half |
  6769. SUPPORTED_100baseT_Full |
  6770. SUPPORTED_10baseT_Half |
  6771. SUPPORTED_10baseT_Full |
  6772. SUPPORTED_MII);
  6773. cmd->port = PORT_TP;
  6774. } else {
  6775. cmd->supported |= SUPPORTED_FIBRE;
  6776. cmd->port = PORT_FIBRE;
  6777. }
  6778. cmd->advertising = tp->link_config.advertising;
  6779. if (netif_running(dev)) {
  6780. cmd->speed = tp->link_config.active_speed;
  6781. cmd->duplex = tp->link_config.active_duplex;
  6782. }
  6783. cmd->phy_address = PHY_ADDR;
  6784. cmd->transceiver = 0;
  6785. cmd->autoneg = tp->link_config.autoneg;
  6786. cmd->maxtxpkt = 0;
  6787. cmd->maxrxpkt = 0;
  6788. return 0;
  6789. }
  6790. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6791. {
  6792. struct tg3 *tp = netdev_priv(dev);
  6793. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6794. /* These are the only valid advertisement bits allowed. */
  6795. if (cmd->autoneg == AUTONEG_ENABLE &&
  6796. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6797. ADVERTISED_1000baseT_Full |
  6798. ADVERTISED_Autoneg |
  6799. ADVERTISED_FIBRE)))
  6800. return -EINVAL;
  6801. /* Fiber can only do SPEED_1000. */
  6802. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6803. (cmd->speed != SPEED_1000))
  6804. return -EINVAL;
  6805. /* Copper cannot force SPEED_1000. */
  6806. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6807. (cmd->speed == SPEED_1000))
  6808. return -EINVAL;
  6809. else if ((cmd->speed == SPEED_1000) &&
  6810. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6811. return -EINVAL;
  6812. tg3_full_lock(tp, 0);
  6813. tp->link_config.autoneg = cmd->autoneg;
  6814. if (cmd->autoneg == AUTONEG_ENABLE) {
  6815. tp->link_config.advertising = cmd->advertising;
  6816. tp->link_config.speed = SPEED_INVALID;
  6817. tp->link_config.duplex = DUPLEX_INVALID;
  6818. } else {
  6819. tp->link_config.advertising = 0;
  6820. tp->link_config.speed = cmd->speed;
  6821. tp->link_config.duplex = cmd->duplex;
  6822. }
  6823. tp->link_config.orig_speed = tp->link_config.speed;
  6824. tp->link_config.orig_duplex = tp->link_config.duplex;
  6825. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  6826. if (netif_running(dev))
  6827. tg3_setup_phy(tp, 1);
  6828. tg3_full_unlock(tp);
  6829. return 0;
  6830. }
  6831. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6832. {
  6833. struct tg3 *tp = netdev_priv(dev);
  6834. strcpy(info->driver, DRV_MODULE_NAME);
  6835. strcpy(info->version, DRV_MODULE_VERSION);
  6836. strcpy(info->fw_version, tp->fw_ver);
  6837. strcpy(info->bus_info, pci_name(tp->pdev));
  6838. }
  6839. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6840. {
  6841. struct tg3 *tp = netdev_priv(dev);
  6842. wol->supported = WAKE_MAGIC;
  6843. wol->wolopts = 0;
  6844. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6845. wol->wolopts = WAKE_MAGIC;
  6846. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6847. }
  6848. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6849. {
  6850. struct tg3 *tp = netdev_priv(dev);
  6851. if (wol->wolopts & ~WAKE_MAGIC)
  6852. return -EINVAL;
  6853. if ((wol->wolopts & WAKE_MAGIC) &&
  6854. tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  6855. !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
  6856. return -EINVAL;
  6857. spin_lock_bh(&tp->lock);
  6858. if (wol->wolopts & WAKE_MAGIC)
  6859. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6860. else
  6861. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6862. spin_unlock_bh(&tp->lock);
  6863. return 0;
  6864. }
  6865. static u32 tg3_get_msglevel(struct net_device *dev)
  6866. {
  6867. struct tg3 *tp = netdev_priv(dev);
  6868. return tp->msg_enable;
  6869. }
  6870. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6871. {
  6872. struct tg3 *tp = netdev_priv(dev);
  6873. tp->msg_enable = value;
  6874. }
  6875. static int tg3_set_tso(struct net_device *dev, u32 value)
  6876. {
  6877. struct tg3 *tp = netdev_priv(dev);
  6878. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6879. if (value)
  6880. return -EINVAL;
  6881. return 0;
  6882. }
  6883. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  6884. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  6885. if (value)
  6886. dev->features |= NETIF_F_TSO6;
  6887. else
  6888. dev->features &= ~NETIF_F_TSO6;
  6889. }
  6890. return ethtool_op_set_tso(dev, value);
  6891. }
  6892. static int tg3_nway_reset(struct net_device *dev)
  6893. {
  6894. struct tg3 *tp = netdev_priv(dev);
  6895. u32 bmcr;
  6896. int r;
  6897. if (!netif_running(dev))
  6898. return -EAGAIN;
  6899. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6900. return -EINVAL;
  6901. spin_lock_bh(&tp->lock);
  6902. r = -EINVAL;
  6903. tg3_readphy(tp, MII_BMCR, &bmcr);
  6904. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6905. ((bmcr & BMCR_ANENABLE) ||
  6906. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6907. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6908. BMCR_ANENABLE);
  6909. r = 0;
  6910. }
  6911. spin_unlock_bh(&tp->lock);
  6912. return r;
  6913. }
  6914. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6915. {
  6916. struct tg3 *tp = netdev_priv(dev);
  6917. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6918. ering->rx_mini_max_pending = 0;
  6919. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6920. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6921. else
  6922. ering->rx_jumbo_max_pending = 0;
  6923. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6924. ering->rx_pending = tp->rx_pending;
  6925. ering->rx_mini_pending = 0;
  6926. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6927. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6928. else
  6929. ering->rx_jumbo_pending = 0;
  6930. ering->tx_pending = tp->tx_pending;
  6931. }
  6932. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6933. {
  6934. struct tg3 *tp = netdev_priv(dev);
  6935. int irq_sync = 0, err = 0;
  6936. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6937. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6938. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  6939. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  6940. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  6941. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  6942. return -EINVAL;
  6943. if (netif_running(dev)) {
  6944. tg3_netif_stop(tp);
  6945. irq_sync = 1;
  6946. }
  6947. tg3_full_lock(tp, irq_sync);
  6948. tp->rx_pending = ering->rx_pending;
  6949. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6950. tp->rx_pending > 63)
  6951. tp->rx_pending = 63;
  6952. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6953. tp->tx_pending = ering->tx_pending;
  6954. if (netif_running(dev)) {
  6955. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6956. err = tg3_restart_hw(tp, 1);
  6957. if (!err)
  6958. tg3_netif_start(tp);
  6959. }
  6960. tg3_full_unlock(tp);
  6961. return err;
  6962. }
  6963. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6964. {
  6965. struct tg3 *tp = netdev_priv(dev);
  6966. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  6967. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  6968. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  6969. }
  6970. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6971. {
  6972. struct tg3 *tp = netdev_priv(dev);
  6973. int irq_sync = 0, err = 0;
  6974. if (netif_running(dev)) {
  6975. tg3_netif_stop(tp);
  6976. irq_sync = 1;
  6977. }
  6978. tg3_full_lock(tp, irq_sync);
  6979. if (epause->autoneg)
  6980. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  6981. else
  6982. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  6983. if (epause->rx_pause)
  6984. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  6985. else
  6986. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  6987. if (epause->tx_pause)
  6988. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  6989. else
  6990. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  6991. if (netif_running(dev)) {
  6992. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6993. err = tg3_restart_hw(tp, 1);
  6994. if (!err)
  6995. tg3_netif_start(tp);
  6996. }
  6997. tg3_full_unlock(tp);
  6998. return err;
  6999. }
  7000. static u32 tg3_get_rx_csum(struct net_device *dev)
  7001. {
  7002. struct tg3 *tp = netdev_priv(dev);
  7003. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  7004. }
  7005. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  7006. {
  7007. struct tg3 *tp = netdev_priv(dev);
  7008. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7009. if (data != 0)
  7010. return -EINVAL;
  7011. return 0;
  7012. }
  7013. spin_lock_bh(&tp->lock);
  7014. if (data)
  7015. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7016. else
  7017. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7018. spin_unlock_bh(&tp->lock);
  7019. return 0;
  7020. }
  7021. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7022. {
  7023. struct tg3 *tp = netdev_priv(dev);
  7024. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7025. if (data != 0)
  7026. return -EINVAL;
  7027. return 0;
  7028. }
  7029. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7030. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7031. ethtool_op_set_tx_hw_csum(dev, data);
  7032. else
  7033. ethtool_op_set_tx_csum(dev, data);
  7034. return 0;
  7035. }
  7036. static int tg3_get_stats_count (struct net_device *dev)
  7037. {
  7038. return TG3_NUM_STATS;
  7039. }
  7040. static int tg3_get_test_count (struct net_device *dev)
  7041. {
  7042. return TG3_NUM_TEST;
  7043. }
  7044. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7045. {
  7046. switch (stringset) {
  7047. case ETH_SS_STATS:
  7048. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7049. break;
  7050. case ETH_SS_TEST:
  7051. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7052. break;
  7053. default:
  7054. WARN_ON(1); /* we need a WARN() */
  7055. break;
  7056. }
  7057. }
  7058. static int tg3_phys_id(struct net_device *dev, u32 data)
  7059. {
  7060. struct tg3 *tp = netdev_priv(dev);
  7061. int i;
  7062. if (!netif_running(tp->dev))
  7063. return -EAGAIN;
  7064. if (data == 0)
  7065. data = 2;
  7066. for (i = 0; i < (data * 2); i++) {
  7067. if ((i % 2) == 0)
  7068. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7069. LED_CTRL_1000MBPS_ON |
  7070. LED_CTRL_100MBPS_ON |
  7071. LED_CTRL_10MBPS_ON |
  7072. LED_CTRL_TRAFFIC_OVERRIDE |
  7073. LED_CTRL_TRAFFIC_BLINK |
  7074. LED_CTRL_TRAFFIC_LED);
  7075. else
  7076. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7077. LED_CTRL_TRAFFIC_OVERRIDE);
  7078. if (msleep_interruptible(500))
  7079. break;
  7080. }
  7081. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7082. return 0;
  7083. }
  7084. static void tg3_get_ethtool_stats (struct net_device *dev,
  7085. struct ethtool_stats *estats, u64 *tmp_stats)
  7086. {
  7087. struct tg3 *tp = netdev_priv(dev);
  7088. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7089. }
  7090. #define NVRAM_TEST_SIZE 0x100
  7091. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  7092. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7093. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7094. static int tg3_test_nvram(struct tg3 *tp)
  7095. {
  7096. u32 *buf, csum, magic;
  7097. int i, j, err = 0, size;
  7098. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7099. return -EIO;
  7100. if (magic == TG3_EEPROM_MAGIC)
  7101. size = NVRAM_TEST_SIZE;
  7102. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7103. if ((magic & 0xe00000) == 0x200000)
  7104. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  7105. else
  7106. return 0;
  7107. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7108. size = NVRAM_SELFBOOT_HW_SIZE;
  7109. else
  7110. return -EIO;
  7111. buf = kmalloc(size, GFP_KERNEL);
  7112. if (buf == NULL)
  7113. return -ENOMEM;
  7114. err = -EIO;
  7115. for (i = 0, j = 0; i < size; i += 4, j++) {
  7116. u32 val;
  7117. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7118. break;
  7119. buf[j] = cpu_to_le32(val);
  7120. }
  7121. if (i < size)
  7122. goto out;
  7123. /* Selfboot format */
  7124. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
  7125. TG3_EEPROM_MAGIC_FW) {
  7126. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7127. for (i = 0; i < size; i++)
  7128. csum8 += buf8[i];
  7129. if (csum8 == 0) {
  7130. err = 0;
  7131. goto out;
  7132. }
  7133. err = -EIO;
  7134. goto out;
  7135. }
  7136. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
  7137. TG3_EEPROM_MAGIC_HW) {
  7138. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7139. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7140. u8 *buf8 = (u8 *) buf;
  7141. int j, k;
  7142. /* Separate the parity bits and the data bytes. */
  7143. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7144. if ((i == 0) || (i == 8)) {
  7145. int l;
  7146. u8 msk;
  7147. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7148. parity[k++] = buf8[i] & msk;
  7149. i++;
  7150. }
  7151. else if (i == 16) {
  7152. int l;
  7153. u8 msk;
  7154. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7155. parity[k++] = buf8[i] & msk;
  7156. i++;
  7157. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7158. parity[k++] = buf8[i] & msk;
  7159. i++;
  7160. }
  7161. data[j++] = buf8[i];
  7162. }
  7163. err = -EIO;
  7164. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7165. u8 hw8 = hweight8(data[i]);
  7166. if ((hw8 & 0x1) && parity[i])
  7167. goto out;
  7168. else if (!(hw8 & 0x1) && !parity[i])
  7169. goto out;
  7170. }
  7171. err = 0;
  7172. goto out;
  7173. }
  7174. /* Bootstrap checksum at offset 0x10 */
  7175. csum = calc_crc((unsigned char *) buf, 0x10);
  7176. if(csum != cpu_to_le32(buf[0x10/4]))
  7177. goto out;
  7178. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7179. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7180. if (csum != cpu_to_le32(buf[0xfc/4]))
  7181. goto out;
  7182. err = 0;
  7183. out:
  7184. kfree(buf);
  7185. return err;
  7186. }
  7187. #define TG3_SERDES_TIMEOUT_SEC 2
  7188. #define TG3_COPPER_TIMEOUT_SEC 6
  7189. static int tg3_test_link(struct tg3 *tp)
  7190. {
  7191. int i, max;
  7192. if (!netif_running(tp->dev))
  7193. return -ENODEV;
  7194. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7195. max = TG3_SERDES_TIMEOUT_SEC;
  7196. else
  7197. max = TG3_COPPER_TIMEOUT_SEC;
  7198. for (i = 0; i < max; i++) {
  7199. if (netif_carrier_ok(tp->dev))
  7200. return 0;
  7201. if (msleep_interruptible(1000))
  7202. break;
  7203. }
  7204. return -EIO;
  7205. }
  7206. /* Only test the commonly used registers */
  7207. static int tg3_test_registers(struct tg3 *tp)
  7208. {
  7209. int i, is_5705, is_5750;
  7210. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7211. static struct {
  7212. u16 offset;
  7213. u16 flags;
  7214. #define TG3_FL_5705 0x1
  7215. #define TG3_FL_NOT_5705 0x2
  7216. #define TG3_FL_NOT_5788 0x4
  7217. #define TG3_FL_NOT_5750 0x8
  7218. u32 read_mask;
  7219. u32 write_mask;
  7220. } reg_tbl[] = {
  7221. /* MAC Control Registers */
  7222. { MAC_MODE, TG3_FL_NOT_5705,
  7223. 0x00000000, 0x00ef6f8c },
  7224. { MAC_MODE, TG3_FL_5705,
  7225. 0x00000000, 0x01ef6b8c },
  7226. { MAC_STATUS, TG3_FL_NOT_5705,
  7227. 0x03800107, 0x00000000 },
  7228. { MAC_STATUS, TG3_FL_5705,
  7229. 0x03800100, 0x00000000 },
  7230. { MAC_ADDR_0_HIGH, 0x0000,
  7231. 0x00000000, 0x0000ffff },
  7232. { MAC_ADDR_0_LOW, 0x0000,
  7233. 0x00000000, 0xffffffff },
  7234. { MAC_RX_MTU_SIZE, 0x0000,
  7235. 0x00000000, 0x0000ffff },
  7236. { MAC_TX_MODE, 0x0000,
  7237. 0x00000000, 0x00000070 },
  7238. { MAC_TX_LENGTHS, 0x0000,
  7239. 0x00000000, 0x00003fff },
  7240. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7241. 0x00000000, 0x000007fc },
  7242. { MAC_RX_MODE, TG3_FL_5705,
  7243. 0x00000000, 0x000007dc },
  7244. { MAC_HASH_REG_0, 0x0000,
  7245. 0x00000000, 0xffffffff },
  7246. { MAC_HASH_REG_1, 0x0000,
  7247. 0x00000000, 0xffffffff },
  7248. { MAC_HASH_REG_2, 0x0000,
  7249. 0x00000000, 0xffffffff },
  7250. { MAC_HASH_REG_3, 0x0000,
  7251. 0x00000000, 0xffffffff },
  7252. /* Receive Data and Receive BD Initiator Control Registers. */
  7253. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7254. 0x00000000, 0xffffffff },
  7255. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7256. 0x00000000, 0xffffffff },
  7257. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7258. 0x00000000, 0x00000003 },
  7259. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7260. 0x00000000, 0xffffffff },
  7261. { RCVDBDI_STD_BD+0, 0x0000,
  7262. 0x00000000, 0xffffffff },
  7263. { RCVDBDI_STD_BD+4, 0x0000,
  7264. 0x00000000, 0xffffffff },
  7265. { RCVDBDI_STD_BD+8, 0x0000,
  7266. 0x00000000, 0xffff0002 },
  7267. { RCVDBDI_STD_BD+0xc, 0x0000,
  7268. 0x00000000, 0xffffffff },
  7269. /* Receive BD Initiator Control Registers. */
  7270. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7271. 0x00000000, 0xffffffff },
  7272. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7273. 0x00000000, 0x000003ff },
  7274. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7275. 0x00000000, 0xffffffff },
  7276. /* Host Coalescing Control Registers. */
  7277. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7278. 0x00000000, 0x00000004 },
  7279. { HOSTCC_MODE, TG3_FL_5705,
  7280. 0x00000000, 0x000000f6 },
  7281. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7282. 0x00000000, 0xffffffff },
  7283. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7284. 0x00000000, 0x000003ff },
  7285. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7286. 0x00000000, 0xffffffff },
  7287. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7288. 0x00000000, 0x000003ff },
  7289. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7290. 0x00000000, 0xffffffff },
  7291. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7292. 0x00000000, 0x000000ff },
  7293. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7294. 0x00000000, 0xffffffff },
  7295. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7296. 0x00000000, 0x000000ff },
  7297. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7298. 0x00000000, 0xffffffff },
  7299. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7300. 0x00000000, 0xffffffff },
  7301. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7302. 0x00000000, 0xffffffff },
  7303. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7304. 0x00000000, 0x000000ff },
  7305. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7306. 0x00000000, 0xffffffff },
  7307. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7308. 0x00000000, 0x000000ff },
  7309. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7310. 0x00000000, 0xffffffff },
  7311. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7312. 0x00000000, 0xffffffff },
  7313. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7314. 0x00000000, 0xffffffff },
  7315. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7316. 0x00000000, 0xffffffff },
  7317. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7318. 0x00000000, 0xffffffff },
  7319. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7320. 0xffffffff, 0x00000000 },
  7321. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7322. 0xffffffff, 0x00000000 },
  7323. /* Buffer Manager Control Registers. */
  7324. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7325. 0x00000000, 0x007fff80 },
  7326. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7327. 0x00000000, 0x007fffff },
  7328. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7329. 0x00000000, 0x0000003f },
  7330. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7331. 0x00000000, 0x000001ff },
  7332. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7333. 0x00000000, 0x000001ff },
  7334. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7335. 0xffffffff, 0x00000000 },
  7336. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7337. 0xffffffff, 0x00000000 },
  7338. /* Mailbox Registers */
  7339. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7340. 0x00000000, 0x000001ff },
  7341. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7342. 0x00000000, 0x000001ff },
  7343. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7344. 0x00000000, 0x000007ff },
  7345. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7346. 0x00000000, 0x000001ff },
  7347. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7348. };
  7349. is_5705 = is_5750 = 0;
  7350. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7351. is_5705 = 1;
  7352. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7353. is_5750 = 1;
  7354. }
  7355. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7356. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7357. continue;
  7358. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7359. continue;
  7360. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7361. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7362. continue;
  7363. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7364. continue;
  7365. offset = (u32) reg_tbl[i].offset;
  7366. read_mask = reg_tbl[i].read_mask;
  7367. write_mask = reg_tbl[i].write_mask;
  7368. /* Save the original register content */
  7369. save_val = tr32(offset);
  7370. /* Determine the read-only value. */
  7371. read_val = save_val & read_mask;
  7372. /* Write zero to the register, then make sure the read-only bits
  7373. * are not changed and the read/write bits are all zeros.
  7374. */
  7375. tw32(offset, 0);
  7376. val = tr32(offset);
  7377. /* Test the read-only and read/write bits. */
  7378. if (((val & read_mask) != read_val) || (val & write_mask))
  7379. goto out;
  7380. /* Write ones to all the bits defined by RdMask and WrMask, then
  7381. * make sure the read-only bits are not changed and the
  7382. * read/write bits are all ones.
  7383. */
  7384. tw32(offset, read_mask | write_mask);
  7385. val = tr32(offset);
  7386. /* Test the read-only bits. */
  7387. if ((val & read_mask) != read_val)
  7388. goto out;
  7389. /* Test the read/write bits. */
  7390. if ((val & write_mask) != write_mask)
  7391. goto out;
  7392. tw32(offset, save_val);
  7393. }
  7394. return 0;
  7395. out:
  7396. if (netif_msg_hw(tp))
  7397. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7398. offset);
  7399. tw32(offset, save_val);
  7400. return -EIO;
  7401. }
  7402. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7403. {
  7404. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7405. int i;
  7406. u32 j;
  7407. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7408. for (j = 0; j < len; j += 4) {
  7409. u32 val;
  7410. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7411. tg3_read_mem(tp, offset + j, &val);
  7412. if (val != test_pattern[i])
  7413. return -EIO;
  7414. }
  7415. }
  7416. return 0;
  7417. }
  7418. static int tg3_test_memory(struct tg3 *tp)
  7419. {
  7420. static struct mem_entry {
  7421. u32 offset;
  7422. u32 len;
  7423. } mem_tbl_570x[] = {
  7424. { 0x00000000, 0x00b50},
  7425. { 0x00002000, 0x1c000},
  7426. { 0xffffffff, 0x00000}
  7427. }, mem_tbl_5705[] = {
  7428. { 0x00000100, 0x0000c},
  7429. { 0x00000200, 0x00008},
  7430. { 0x00004000, 0x00800},
  7431. { 0x00006000, 0x01000},
  7432. { 0x00008000, 0x02000},
  7433. { 0x00010000, 0x0e000},
  7434. { 0xffffffff, 0x00000}
  7435. }, mem_tbl_5755[] = {
  7436. { 0x00000200, 0x00008},
  7437. { 0x00004000, 0x00800},
  7438. { 0x00006000, 0x00800},
  7439. { 0x00008000, 0x02000},
  7440. { 0x00010000, 0x0c000},
  7441. { 0xffffffff, 0x00000}
  7442. }, mem_tbl_5906[] = {
  7443. { 0x00000200, 0x00008},
  7444. { 0x00004000, 0x00400},
  7445. { 0x00006000, 0x00400},
  7446. { 0x00008000, 0x01000},
  7447. { 0x00010000, 0x01000},
  7448. { 0xffffffff, 0x00000}
  7449. };
  7450. struct mem_entry *mem_tbl;
  7451. int err = 0;
  7452. int i;
  7453. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7454. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7455. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7456. mem_tbl = mem_tbl_5755;
  7457. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7458. mem_tbl = mem_tbl_5906;
  7459. else
  7460. mem_tbl = mem_tbl_5705;
  7461. } else
  7462. mem_tbl = mem_tbl_570x;
  7463. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7464. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7465. mem_tbl[i].len)) != 0)
  7466. break;
  7467. }
  7468. return err;
  7469. }
  7470. #define TG3_MAC_LOOPBACK 0
  7471. #define TG3_PHY_LOOPBACK 1
  7472. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7473. {
  7474. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7475. u32 desc_idx;
  7476. struct sk_buff *skb, *rx_skb;
  7477. u8 *tx_data;
  7478. dma_addr_t map;
  7479. int num_pkts, tx_len, rx_len, i, err;
  7480. struct tg3_rx_buffer_desc *desc;
  7481. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7482. /* HW errata - mac loopback fails in some cases on 5780.
  7483. * Normal traffic and PHY loopback are not affected by
  7484. * errata.
  7485. */
  7486. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7487. return 0;
  7488. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7489. MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
  7490. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7491. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7492. else
  7493. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7494. tw32(MAC_MODE, mac_mode);
  7495. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7496. u32 val;
  7497. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7498. u32 phytest;
  7499. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7500. u32 phy;
  7501. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7502. phytest | MII_TG3_EPHY_SHADOW_EN);
  7503. if (!tg3_readphy(tp, 0x1b, &phy))
  7504. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7505. if (!tg3_readphy(tp, 0x10, &phy))
  7506. tg3_writephy(tp, 0x10, phy & ~0x4000);
  7507. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7508. }
  7509. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7510. } else
  7511. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7512. tg3_writephy(tp, MII_BMCR, val);
  7513. udelay(40);
  7514. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7515. MAC_MODE_LINK_POLARITY;
  7516. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7517. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7518. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7519. } else
  7520. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7521. /* reset to prevent losing 1st rx packet intermittently */
  7522. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7523. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7524. udelay(10);
  7525. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7526. }
  7527. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  7528. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7529. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7530. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7531. }
  7532. tw32(MAC_MODE, mac_mode);
  7533. }
  7534. else
  7535. return -EINVAL;
  7536. err = -EIO;
  7537. tx_len = 1514;
  7538. skb = netdev_alloc_skb(tp->dev, tx_len);
  7539. if (!skb)
  7540. return -ENOMEM;
  7541. tx_data = skb_put(skb, tx_len);
  7542. memcpy(tx_data, tp->dev->dev_addr, 6);
  7543. memset(tx_data + 6, 0x0, 8);
  7544. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7545. for (i = 14; i < tx_len; i++)
  7546. tx_data[i] = (u8) (i & 0xff);
  7547. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7548. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7549. HOSTCC_MODE_NOW);
  7550. udelay(10);
  7551. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7552. num_pkts = 0;
  7553. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7554. tp->tx_prod++;
  7555. num_pkts++;
  7556. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7557. tp->tx_prod);
  7558. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7559. udelay(10);
  7560. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  7561. for (i = 0; i < 25; i++) {
  7562. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7563. HOSTCC_MODE_NOW);
  7564. udelay(10);
  7565. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7566. rx_idx = tp->hw_status->idx[0].rx_producer;
  7567. if ((tx_idx == tp->tx_prod) &&
  7568. (rx_idx == (rx_start_idx + num_pkts)))
  7569. break;
  7570. }
  7571. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7572. dev_kfree_skb(skb);
  7573. if (tx_idx != tp->tx_prod)
  7574. goto out;
  7575. if (rx_idx != rx_start_idx + num_pkts)
  7576. goto out;
  7577. desc = &tp->rx_rcb[rx_start_idx];
  7578. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7579. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7580. if (opaque_key != RXD_OPAQUE_RING_STD)
  7581. goto out;
  7582. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7583. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7584. goto out;
  7585. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7586. if (rx_len != tx_len)
  7587. goto out;
  7588. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7589. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7590. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7591. for (i = 14; i < tx_len; i++) {
  7592. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7593. goto out;
  7594. }
  7595. err = 0;
  7596. /* tg3_free_rings will unmap and free the rx_skb */
  7597. out:
  7598. return err;
  7599. }
  7600. #define TG3_MAC_LOOPBACK_FAILED 1
  7601. #define TG3_PHY_LOOPBACK_FAILED 2
  7602. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7603. TG3_PHY_LOOPBACK_FAILED)
  7604. static int tg3_test_loopback(struct tg3 *tp)
  7605. {
  7606. int err = 0;
  7607. if (!netif_running(tp->dev))
  7608. return TG3_LOOPBACK_FAILED;
  7609. err = tg3_reset_hw(tp, 1);
  7610. if (err)
  7611. return TG3_LOOPBACK_FAILED;
  7612. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7613. err |= TG3_MAC_LOOPBACK_FAILED;
  7614. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7615. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7616. err |= TG3_PHY_LOOPBACK_FAILED;
  7617. }
  7618. return err;
  7619. }
  7620. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7621. u64 *data)
  7622. {
  7623. struct tg3 *tp = netdev_priv(dev);
  7624. if (tp->link_config.phy_is_low_power)
  7625. tg3_set_power_state(tp, PCI_D0);
  7626. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7627. if (tg3_test_nvram(tp) != 0) {
  7628. etest->flags |= ETH_TEST_FL_FAILED;
  7629. data[0] = 1;
  7630. }
  7631. if (tg3_test_link(tp) != 0) {
  7632. etest->flags |= ETH_TEST_FL_FAILED;
  7633. data[1] = 1;
  7634. }
  7635. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7636. int err, irq_sync = 0;
  7637. if (netif_running(dev)) {
  7638. tg3_netif_stop(tp);
  7639. irq_sync = 1;
  7640. }
  7641. tg3_full_lock(tp, irq_sync);
  7642. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7643. err = tg3_nvram_lock(tp);
  7644. tg3_halt_cpu(tp, RX_CPU_BASE);
  7645. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7646. tg3_halt_cpu(tp, TX_CPU_BASE);
  7647. if (!err)
  7648. tg3_nvram_unlock(tp);
  7649. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7650. tg3_phy_reset(tp);
  7651. if (tg3_test_registers(tp) != 0) {
  7652. etest->flags |= ETH_TEST_FL_FAILED;
  7653. data[2] = 1;
  7654. }
  7655. if (tg3_test_memory(tp) != 0) {
  7656. etest->flags |= ETH_TEST_FL_FAILED;
  7657. data[3] = 1;
  7658. }
  7659. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7660. etest->flags |= ETH_TEST_FL_FAILED;
  7661. tg3_full_unlock(tp);
  7662. if (tg3_test_interrupt(tp) != 0) {
  7663. etest->flags |= ETH_TEST_FL_FAILED;
  7664. data[5] = 1;
  7665. }
  7666. tg3_full_lock(tp, 0);
  7667. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7668. if (netif_running(dev)) {
  7669. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7670. if (!tg3_restart_hw(tp, 1))
  7671. tg3_netif_start(tp);
  7672. }
  7673. tg3_full_unlock(tp);
  7674. }
  7675. if (tp->link_config.phy_is_low_power)
  7676. tg3_set_power_state(tp, PCI_D3hot);
  7677. }
  7678. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7679. {
  7680. struct mii_ioctl_data *data = if_mii(ifr);
  7681. struct tg3 *tp = netdev_priv(dev);
  7682. int err;
  7683. switch(cmd) {
  7684. case SIOCGMIIPHY:
  7685. data->phy_id = PHY_ADDR;
  7686. /* fallthru */
  7687. case SIOCGMIIREG: {
  7688. u32 mii_regval;
  7689. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7690. break; /* We have no PHY */
  7691. if (tp->link_config.phy_is_low_power)
  7692. return -EAGAIN;
  7693. spin_lock_bh(&tp->lock);
  7694. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7695. spin_unlock_bh(&tp->lock);
  7696. data->val_out = mii_regval;
  7697. return err;
  7698. }
  7699. case SIOCSMIIREG:
  7700. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7701. break; /* We have no PHY */
  7702. if (!capable(CAP_NET_ADMIN))
  7703. return -EPERM;
  7704. if (tp->link_config.phy_is_low_power)
  7705. return -EAGAIN;
  7706. spin_lock_bh(&tp->lock);
  7707. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7708. spin_unlock_bh(&tp->lock);
  7709. return err;
  7710. default:
  7711. /* do nothing */
  7712. break;
  7713. }
  7714. return -EOPNOTSUPP;
  7715. }
  7716. #if TG3_VLAN_TAG_USED
  7717. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7718. {
  7719. struct tg3 *tp = netdev_priv(dev);
  7720. if (netif_running(dev))
  7721. tg3_netif_stop(tp);
  7722. tg3_full_lock(tp, 0);
  7723. tp->vlgrp = grp;
  7724. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7725. __tg3_set_rx_mode(dev);
  7726. tg3_full_unlock(tp);
  7727. if (netif_running(dev))
  7728. tg3_netif_start(tp);
  7729. }
  7730. static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  7731. {
  7732. struct tg3 *tp = netdev_priv(dev);
  7733. if (netif_running(dev))
  7734. tg3_netif_stop(tp);
  7735. tg3_full_lock(tp, 0);
  7736. vlan_group_set_device(tp->vlgrp, vid, NULL);
  7737. tg3_full_unlock(tp);
  7738. if (netif_running(dev))
  7739. tg3_netif_start(tp);
  7740. }
  7741. #endif
  7742. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7743. {
  7744. struct tg3 *tp = netdev_priv(dev);
  7745. memcpy(ec, &tp->coal, sizeof(*ec));
  7746. return 0;
  7747. }
  7748. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7749. {
  7750. struct tg3 *tp = netdev_priv(dev);
  7751. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7752. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7753. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7754. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7755. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7756. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7757. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7758. }
  7759. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7760. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7761. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7762. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7763. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7764. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7765. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7766. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7767. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7768. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7769. return -EINVAL;
  7770. /* No rx interrupts will be generated if both are zero */
  7771. if ((ec->rx_coalesce_usecs == 0) &&
  7772. (ec->rx_max_coalesced_frames == 0))
  7773. return -EINVAL;
  7774. /* No tx interrupts will be generated if both are zero */
  7775. if ((ec->tx_coalesce_usecs == 0) &&
  7776. (ec->tx_max_coalesced_frames == 0))
  7777. return -EINVAL;
  7778. /* Only copy relevant parameters, ignore all others. */
  7779. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7780. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7781. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7782. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7783. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7784. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7785. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7786. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7787. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7788. if (netif_running(dev)) {
  7789. tg3_full_lock(tp, 0);
  7790. __tg3_set_coalesce(tp, &tp->coal);
  7791. tg3_full_unlock(tp);
  7792. }
  7793. return 0;
  7794. }
  7795. static const struct ethtool_ops tg3_ethtool_ops = {
  7796. .get_settings = tg3_get_settings,
  7797. .set_settings = tg3_set_settings,
  7798. .get_drvinfo = tg3_get_drvinfo,
  7799. .get_regs_len = tg3_get_regs_len,
  7800. .get_regs = tg3_get_regs,
  7801. .get_wol = tg3_get_wol,
  7802. .set_wol = tg3_set_wol,
  7803. .get_msglevel = tg3_get_msglevel,
  7804. .set_msglevel = tg3_set_msglevel,
  7805. .nway_reset = tg3_nway_reset,
  7806. .get_link = ethtool_op_get_link,
  7807. .get_eeprom_len = tg3_get_eeprom_len,
  7808. .get_eeprom = tg3_get_eeprom,
  7809. .set_eeprom = tg3_set_eeprom,
  7810. .get_ringparam = tg3_get_ringparam,
  7811. .set_ringparam = tg3_set_ringparam,
  7812. .get_pauseparam = tg3_get_pauseparam,
  7813. .set_pauseparam = tg3_set_pauseparam,
  7814. .get_rx_csum = tg3_get_rx_csum,
  7815. .set_rx_csum = tg3_set_rx_csum,
  7816. .get_tx_csum = ethtool_op_get_tx_csum,
  7817. .set_tx_csum = tg3_set_tx_csum,
  7818. .get_sg = ethtool_op_get_sg,
  7819. .set_sg = ethtool_op_set_sg,
  7820. .get_tso = ethtool_op_get_tso,
  7821. .set_tso = tg3_set_tso,
  7822. .self_test_count = tg3_get_test_count,
  7823. .self_test = tg3_self_test,
  7824. .get_strings = tg3_get_strings,
  7825. .phys_id = tg3_phys_id,
  7826. .get_stats_count = tg3_get_stats_count,
  7827. .get_ethtool_stats = tg3_get_ethtool_stats,
  7828. .get_coalesce = tg3_get_coalesce,
  7829. .set_coalesce = tg3_set_coalesce,
  7830. .get_perm_addr = ethtool_op_get_perm_addr,
  7831. };
  7832. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7833. {
  7834. u32 cursize, val, magic;
  7835. tp->nvram_size = EEPROM_CHIP_SIZE;
  7836. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7837. return;
  7838. if ((magic != TG3_EEPROM_MAGIC) &&
  7839. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  7840. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  7841. return;
  7842. /*
  7843. * Size the chip by reading offsets at increasing powers of two.
  7844. * When we encounter our validation signature, we know the addressing
  7845. * has wrapped around, and thus have our chip size.
  7846. */
  7847. cursize = 0x10;
  7848. while (cursize < tp->nvram_size) {
  7849. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7850. return;
  7851. if (val == magic)
  7852. break;
  7853. cursize <<= 1;
  7854. }
  7855. tp->nvram_size = cursize;
  7856. }
  7857. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7858. {
  7859. u32 val;
  7860. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7861. return;
  7862. /* Selfboot format */
  7863. if (val != TG3_EEPROM_MAGIC) {
  7864. tg3_get_eeprom_size(tp);
  7865. return;
  7866. }
  7867. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7868. if (val != 0) {
  7869. tp->nvram_size = (val >> 16) * 1024;
  7870. return;
  7871. }
  7872. }
  7873. tp->nvram_size = 0x20000;
  7874. }
  7875. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7876. {
  7877. u32 nvcfg1;
  7878. nvcfg1 = tr32(NVRAM_CFG1);
  7879. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7880. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7881. }
  7882. else {
  7883. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7884. tw32(NVRAM_CFG1, nvcfg1);
  7885. }
  7886. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7887. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7888. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7889. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7890. tp->nvram_jedecnum = JEDEC_ATMEL;
  7891. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7892. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7893. break;
  7894. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7895. tp->nvram_jedecnum = JEDEC_ATMEL;
  7896. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7897. break;
  7898. case FLASH_VENDOR_ATMEL_EEPROM:
  7899. tp->nvram_jedecnum = JEDEC_ATMEL;
  7900. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7901. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7902. break;
  7903. case FLASH_VENDOR_ST:
  7904. tp->nvram_jedecnum = JEDEC_ST;
  7905. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7906. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7907. break;
  7908. case FLASH_VENDOR_SAIFUN:
  7909. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7910. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7911. break;
  7912. case FLASH_VENDOR_SST_SMALL:
  7913. case FLASH_VENDOR_SST_LARGE:
  7914. tp->nvram_jedecnum = JEDEC_SST;
  7915. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7916. break;
  7917. }
  7918. }
  7919. else {
  7920. tp->nvram_jedecnum = JEDEC_ATMEL;
  7921. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7922. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7923. }
  7924. }
  7925. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7926. {
  7927. u32 nvcfg1;
  7928. nvcfg1 = tr32(NVRAM_CFG1);
  7929. /* NVRAM protection for TPM */
  7930. if (nvcfg1 & (1 << 27))
  7931. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7932. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7933. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7934. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7935. tp->nvram_jedecnum = JEDEC_ATMEL;
  7936. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7937. break;
  7938. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7939. tp->nvram_jedecnum = JEDEC_ATMEL;
  7940. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7941. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7942. break;
  7943. case FLASH_5752VENDOR_ST_M45PE10:
  7944. case FLASH_5752VENDOR_ST_M45PE20:
  7945. case FLASH_5752VENDOR_ST_M45PE40:
  7946. tp->nvram_jedecnum = JEDEC_ST;
  7947. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7948. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7949. break;
  7950. }
  7951. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7952. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7953. case FLASH_5752PAGE_SIZE_256:
  7954. tp->nvram_pagesize = 256;
  7955. break;
  7956. case FLASH_5752PAGE_SIZE_512:
  7957. tp->nvram_pagesize = 512;
  7958. break;
  7959. case FLASH_5752PAGE_SIZE_1K:
  7960. tp->nvram_pagesize = 1024;
  7961. break;
  7962. case FLASH_5752PAGE_SIZE_2K:
  7963. tp->nvram_pagesize = 2048;
  7964. break;
  7965. case FLASH_5752PAGE_SIZE_4K:
  7966. tp->nvram_pagesize = 4096;
  7967. break;
  7968. case FLASH_5752PAGE_SIZE_264:
  7969. tp->nvram_pagesize = 264;
  7970. break;
  7971. }
  7972. }
  7973. else {
  7974. /* For eeprom, set pagesize to maximum eeprom size */
  7975. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7976. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7977. tw32(NVRAM_CFG1, nvcfg1);
  7978. }
  7979. }
  7980. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  7981. {
  7982. u32 nvcfg1;
  7983. nvcfg1 = tr32(NVRAM_CFG1);
  7984. /* NVRAM protection for TPM */
  7985. if (nvcfg1 & (1 << 27))
  7986. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7987. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7988. case FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ:
  7989. case FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ:
  7990. tp->nvram_jedecnum = JEDEC_ATMEL;
  7991. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7992. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7993. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7994. tw32(NVRAM_CFG1, nvcfg1);
  7995. break;
  7996. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7997. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7998. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  7999. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8000. case FLASH_5755VENDOR_ATMEL_FLASH_4:
  8001. tp->nvram_jedecnum = JEDEC_ATMEL;
  8002. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8003. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8004. tp->nvram_pagesize = 264;
  8005. break;
  8006. case FLASH_5752VENDOR_ST_M45PE10:
  8007. case FLASH_5752VENDOR_ST_M45PE20:
  8008. case FLASH_5752VENDOR_ST_M45PE40:
  8009. tp->nvram_jedecnum = JEDEC_ST;
  8010. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8011. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8012. tp->nvram_pagesize = 256;
  8013. break;
  8014. }
  8015. }
  8016. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8017. {
  8018. u32 nvcfg1;
  8019. nvcfg1 = tr32(NVRAM_CFG1);
  8020. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8021. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8022. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8023. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8024. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8025. tp->nvram_jedecnum = JEDEC_ATMEL;
  8026. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8027. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8028. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8029. tw32(NVRAM_CFG1, nvcfg1);
  8030. break;
  8031. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8032. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8033. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8034. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8035. tp->nvram_jedecnum = JEDEC_ATMEL;
  8036. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8037. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8038. tp->nvram_pagesize = 264;
  8039. break;
  8040. case FLASH_5752VENDOR_ST_M45PE10:
  8041. case FLASH_5752VENDOR_ST_M45PE20:
  8042. case FLASH_5752VENDOR_ST_M45PE40:
  8043. tp->nvram_jedecnum = JEDEC_ST;
  8044. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8045. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8046. tp->nvram_pagesize = 256;
  8047. break;
  8048. }
  8049. }
  8050. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8051. {
  8052. tp->nvram_jedecnum = JEDEC_ATMEL;
  8053. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8054. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8055. }
  8056. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8057. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8058. {
  8059. tw32_f(GRC_EEPROM_ADDR,
  8060. (EEPROM_ADDR_FSM_RESET |
  8061. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8062. EEPROM_ADDR_CLKPERD_SHIFT)));
  8063. msleep(1);
  8064. /* Enable seeprom accesses. */
  8065. tw32_f(GRC_LOCAL_CTRL,
  8066. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8067. udelay(100);
  8068. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8069. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8070. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8071. if (tg3_nvram_lock(tp)) {
  8072. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8073. "tg3_nvram_init failed.\n", tp->dev->name);
  8074. return;
  8075. }
  8076. tg3_enable_nvram_access(tp);
  8077. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8078. tg3_get_5752_nvram_info(tp);
  8079. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8080. tg3_get_5755_nvram_info(tp);
  8081. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8082. tg3_get_5787_nvram_info(tp);
  8083. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8084. tg3_get_5906_nvram_info(tp);
  8085. else
  8086. tg3_get_nvram_info(tp);
  8087. tg3_get_nvram_size(tp);
  8088. tg3_disable_nvram_access(tp);
  8089. tg3_nvram_unlock(tp);
  8090. } else {
  8091. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8092. tg3_get_eeprom_size(tp);
  8093. }
  8094. }
  8095. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8096. u32 offset, u32 *val)
  8097. {
  8098. u32 tmp;
  8099. int i;
  8100. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8101. (offset % 4) != 0)
  8102. return -EINVAL;
  8103. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8104. EEPROM_ADDR_DEVID_MASK |
  8105. EEPROM_ADDR_READ);
  8106. tw32(GRC_EEPROM_ADDR,
  8107. tmp |
  8108. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8109. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8110. EEPROM_ADDR_ADDR_MASK) |
  8111. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8112. for (i = 0; i < 1000; i++) {
  8113. tmp = tr32(GRC_EEPROM_ADDR);
  8114. if (tmp & EEPROM_ADDR_COMPLETE)
  8115. break;
  8116. msleep(1);
  8117. }
  8118. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8119. return -EBUSY;
  8120. *val = tr32(GRC_EEPROM_DATA);
  8121. return 0;
  8122. }
  8123. #define NVRAM_CMD_TIMEOUT 10000
  8124. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8125. {
  8126. int i;
  8127. tw32(NVRAM_CMD, nvram_cmd);
  8128. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8129. udelay(10);
  8130. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8131. udelay(10);
  8132. break;
  8133. }
  8134. }
  8135. if (i == NVRAM_CMD_TIMEOUT) {
  8136. return -EBUSY;
  8137. }
  8138. return 0;
  8139. }
  8140. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8141. {
  8142. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8143. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8144. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8145. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8146. addr = ((addr / tp->nvram_pagesize) <<
  8147. ATMEL_AT45DB0X1B_PAGE_POS) +
  8148. (addr % tp->nvram_pagesize);
  8149. return addr;
  8150. }
  8151. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8152. {
  8153. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8154. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8155. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8156. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8157. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8158. tp->nvram_pagesize) +
  8159. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8160. return addr;
  8161. }
  8162. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8163. {
  8164. int ret;
  8165. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8166. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8167. offset = tg3_nvram_phys_addr(tp, offset);
  8168. if (offset > NVRAM_ADDR_MSK)
  8169. return -EINVAL;
  8170. ret = tg3_nvram_lock(tp);
  8171. if (ret)
  8172. return ret;
  8173. tg3_enable_nvram_access(tp);
  8174. tw32(NVRAM_ADDR, offset);
  8175. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8176. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8177. if (ret == 0)
  8178. *val = swab32(tr32(NVRAM_RDDATA));
  8179. tg3_disable_nvram_access(tp);
  8180. tg3_nvram_unlock(tp);
  8181. return ret;
  8182. }
  8183. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8184. {
  8185. int err;
  8186. u32 tmp;
  8187. err = tg3_nvram_read(tp, offset, &tmp);
  8188. *val = swab32(tmp);
  8189. return err;
  8190. }
  8191. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8192. u32 offset, u32 len, u8 *buf)
  8193. {
  8194. int i, j, rc = 0;
  8195. u32 val;
  8196. for (i = 0; i < len; i += 4) {
  8197. u32 addr, data;
  8198. addr = offset + i;
  8199. memcpy(&data, buf + i, 4);
  8200. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8201. val = tr32(GRC_EEPROM_ADDR);
  8202. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8203. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8204. EEPROM_ADDR_READ);
  8205. tw32(GRC_EEPROM_ADDR, val |
  8206. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8207. (addr & EEPROM_ADDR_ADDR_MASK) |
  8208. EEPROM_ADDR_START |
  8209. EEPROM_ADDR_WRITE);
  8210. for (j = 0; j < 1000; j++) {
  8211. val = tr32(GRC_EEPROM_ADDR);
  8212. if (val & EEPROM_ADDR_COMPLETE)
  8213. break;
  8214. msleep(1);
  8215. }
  8216. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8217. rc = -EBUSY;
  8218. break;
  8219. }
  8220. }
  8221. return rc;
  8222. }
  8223. /* offset and length are dword aligned */
  8224. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8225. u8 *buf)
  8226. {
  8227. int ret = 0;
  8228. u32 pagesize = tp->nvram_pagesize;
  8229. u32 pagemask = pagesize - 1;
  8230. u32 nvram_cmd;
  8231. u8 *tmp;
  8232. tmp = kmalloc(pagesize, GFP_KERNEL);
  8233. if (tmp == NULL)
  8234. return -ENOMEM;
  8235. while (len) {
  8236. int j;
  8237. u32 phy_addr, page_off, size;
  8238. phy_addr = offset & ~pagemask;
  8239. for (j = 0; j < pagesize; j += 4) {
  8240. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8241. (u32 *) (tmp + j))))
  8242. break;
  8243. }
  8244. if (ret)
  8245. break;
  8246. page_off = offset & pagemask;
  8247. size = pagesize;
  8248. if (len < size)
  8249. size = len;
  8250. len -= size;
  8251. memcpy(tmp + page_off, buf, size);
  8252. offset = offset + (pagesize - page_off);
  8253. tg3_enable_nvram_access(tp);
  8254. /*
  8255. * Before we can erase the flash page, we need
  8256. * to issue a special "write enable" command.
  8257. */
  8258. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8259. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8260. break;
  8261. /* Erase the target page */
  8262. tw32(NVRAM_ADDR, phy_addr);
  8263. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8264. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8265. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8266. break;
  8267. /* Issue another write enable to start the write. */
  8268. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8269. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8270. break;
  8271. for (j = 0; j < pagesize; j += 4) {
  8272. u32 data;
  8273. data = *((u32 *) (tmp + j));
  8274. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8275. tw32(NVRAM_ADDR, phy_addr + j);
  8276. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8277. NVRAM_CMD_WR;
  8278. if (j == 0)
  8279. nvram_cmd |= NVRAM_CMD_FIRST;
  8280. else if (j == (pagesize - 4))
  8281. nvram_cmd |= NVRAM_CMD_LAST;
  8282. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8283. break;
  8284. }
  8285. if (ret)
  8286. break;
  8287. }
  8288. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8289. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8290. kfree(tmp);
  8291. return ret;
  8292. }
  8293. /* offset and length are dword aligned */
  8294. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8295. u8 *buf)
  8296. {
  8297. int i, ret = 0;
  8298. for (i = 0; i < len; i += 4, offset += 4) {
  8299. u32 data, page_off, phy_addr, nvram_cmd;
  8300. memcpy(&data, buf + i, 4);
  8301. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8302. page_off = offset % tp->nvram_pagesize;
  8303. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8304. tw32(NVRAM_ADDR, phy_addr);
  8305. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8306. if ((page_off == 0) || (i == 0))
  8307. nvram_cmd |= NVRAM_CMD_FIRST;
  8308. if (page_off == (tp->nvram_pagesize - 4))
  8309. nvram_cmd |= NVRAM_CMD_LAST;
  8310. if (i == (len - 4))
  8311. nvram_cmd |= NVRAM_CMD_LAST;
  8312. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8313. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8314. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8315. (tp->nvram_jedecnum == JEDEC_ST) &&
  8316. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8317. if ((ret = tg3_nvram_exec_cmd(tp,
  8318. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8319. NVRAM_CMD_DONE)))
  8320. break;
  8321. }
  8322. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8323. /* We always do complete word writes to eeprom. */
  8324. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8325. }
  8326. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8327. break;
  8328. }
  8329. return ret;
  8330. }
  8331. /* offset and length are dword aligned */
  8332. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8333. {
  8334. int ret;
  8335. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8336. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8337. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8338. udelay(40);
  8339. }
  8340. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8341. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8342. }
  8343. else {
  8344. u32 grc_mode;
  8345. ret = tg3_nvram_lock(tp);
  8346. if (ret)
  8347. return ret;
  8348. tg3_enable_nvram_access(tp);
  8349. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8350. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8351. tw32(NVRAM_WRITE1, 0x406);
  8352. grc_mode = tr32(GRC_MODE);
  8353. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8354. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8355. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8356. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8357. buf);
  8358. }
  8359. else {
  8360. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8361. buf);
  8362. }
  8363. grc_mode = tr32(GRC_MODE);
  8364. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8365. tg3_disable_nvram_access(tp);
  8366. tg3_nvram_unlock(tp);
  8367. }
  8368. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8369. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8370. udelay(40);
  8371. }
  8372. return ret;
  8373. }
  8374. struct subsys_tbl_ent {
  8375. u16 subsys_vendor, subsys_devid;
  8376. u32 phy_id;
  8377. };
  8378. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8379. /* Broadcom boards. */
  8380. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8381. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8382. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8383. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8384. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8385. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8386. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8387. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8388. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8389. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8390. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8391. /* 3com boards. */
  8392. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8393. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8394. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8395. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8396. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8397. /* DELL boards. */
  8398. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8399. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8400. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8401. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8402. /* Compaq boards. */
  8403. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8404. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8405. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8406. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8407. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8408. /* IBM boards. */
  8409. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8410. };
  8411. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8412. {
  8413. int i;
  8414. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8415. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8416. tp->pdev->subsystem_vendor) &&
  8417. (subsys_id_to_phy_id[i].subsys_devid ==
  8418. tp->pdev->subsystem_device))
  8419. return &subsys_id_to_phy_id[i];
  8420. }
  8421. return NULL;
  8422. }
  8423. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8424. {
  8425. u32 val;
  8426. u16 pmcsr;
  8427. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8428. * so need make sure we're in D0.
  8429. */
  8430. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8431. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8432. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8433. msleep(1);
  8434. /* Make sure register accesses (indirect or otherwise)
  8435. * will function correctly.
  8436. */
  8437. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8438. tp->misc_host_ctrl);
  8439. /* The memory arbiter has to be enabled in order for SRAM accesses
  8440. * to succeed. Normally on powerup the tg3 chip firmware will make
  8441. * sure it is enabled, but other entities such as system netboot
  8442. * code might disable it.
  8443. */
  8444. val = tr32(MEMARB_MODE);
  8445. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8446. tp->phy_id = PHY_ID_INVALID;
  8447. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8448. /* Assume an onboard device by default. */
  8449. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8450. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8451. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  8452. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8453. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8454. }
  8455. return;
  8456. }
  8457. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8458. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8459. u32 nic_cfg, led_cfg;
  8460. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8461. int eeprom_phy_serdes = 0;
  8462. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8463. tp->nic_sram_data_cfg = nic_cfg;
  8464. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8465. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8466. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8467. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8468. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8469. (ver > 0) && (ver < 0x100))
  8470. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8471. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8472. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8473. eeprom_phy_serdes = 1;
  8474. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8475. if (nic_phy_id != 0) {
  8476. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8477. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8478. eeprom_phy_id = (id1 >> 16) << 10;
  8479. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8480. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8481. } else
  8482. eeprom_phy_id = 0;
  8483. tp->phy_id = eeprom_phy_id;
  8484. if (eeprom_phy_serdes) {
  8485. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8486. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8487. else
  8488. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8489. }
  8490. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8491. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8492. SHASTA_EXT_LED_MODE_MASK);
  8493. else
  8494. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8495. switch (led_cfg) {
  8496. default:
  8497. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8498. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8499. break;
  8500. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8501. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8502. break;
  8503. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8504. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8505. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8506. * read on some older 5700/5701 bootcode.
  8507. */
  8508. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8509. ASIC_REV_5700 ||
  8510. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8511. ASIC_REV_5701)
  8512. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8513. break;
  8514. case SHASTA_EXT_LED_SHARED:
  8515. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8516. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8517. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8518. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8519. LED_CTRL_MODE_PHY_2);
  8520. break;
  8521. case SHASTA_EXT_LED_MAC:
  8522. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8523. break;
  8524. case SHASTA_EXT_LED_COMBO:
  8525. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8526. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8527. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8528. LED_CTRL_MODE_PHY_2);
  8529. break;
  8530. };
  8531. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8532. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8533. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8534. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8535. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  8536. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8537. if ((tp->pdev->subsystem_vendor ==
  8538. PCI_VENDOR_ID_ARIMA) &&
  8539. (tp->pdev->subsystem_device == 0x205a ||
  8540. tp->pdev->subsystem_device == 0x2063))
  8541. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8542. } else {
  8543. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8544. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8545. }
  8546. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8547. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8548. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8549. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8550. }
  8551. if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
  8552. tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
  8553. if (cfg2 & (1 << 17))
  8554. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8555. /* serdes signal pre-emphasis in register 0x590 set by */
  8556. /* bootcode if bit 18 is set */
  8557. if (cfg2 & (1 << 18))
  8558. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8559. }
  8560. }
  8561. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8562. {
  8563. u32 hw_phy_id_1, hw_phy_id_2;
  8564. u32 hw_phy_id, hw_phy_id_masked;
  8565. int err;
  8566. /* Reading the PHY ID register can conflict with ASF
  8567. * firwmare access to the PHY hardware.
  8568. */
  8569. err = 0;
  8570. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8571. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8572. } else {
  8573. /* Now read the physical PHY_ID from the chip and verify
  8574. * that it is sane. If it doesn't look good, we fall back
  8575. * to either the hard-coded table based PHY_ID and failing
  8576. * that the value found in the eeprom area.
  8577. */
  8578. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8579. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8580. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8581. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8582. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8583. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8584. }
  8585. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8586. tp->phy_id = hw_phy_id;
  8587. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8588. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8589. else
  8590. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8591. } else {
  8592. if (tp->phy_id != PHY_ID_INVALID) {
  8593. /* Do nothing, phy ID already set up in
  8594. * tg3_get_eeprom_hw_cfg().
  8595. */
  8596. } else {
  8597. struct subsys_tbl_ent *p;
  8598. /* No eeprom signature? Try the hardcoded
  8599. * subsys device table.
  8600. */
  8601. p = lookup_by_subsys(tp);
  8602. if (!p)
  8603. return -ENODEV;
  8604. tp->phy_id = p->phy_id;
  8605. if (!tp->phy_id ||
  8606. tp->phy_id == PHY_ID_BCM8002)
  8607. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8608. }
  8609. }
  8610. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8611. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8612. u32 bmsr, adv_reg, tg3_ctrl, mask;
  8613. tg3_readphy(tp, MII_BMSR, &bmsr);
  8614. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8615. (bmsr & BMSR_LSTATUS))
  8616. goto skip_phy_reset;
  8617. err = tg3_phy_reset(tp);
  8618. if (err)
  8619. return err;
  8620. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8621. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8622. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8623. tg3_ctrl = 0;
  8624. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8625. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8626. MII_TG3_CTRL_ADV_1000_FULL);
  8627. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8628. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8629. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8630. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8631. }
  8632. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  8633. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  8634. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  8635. if (!tg3_copper_is_advertising_all(tp, mask)) {
  8636. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8637. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8638. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8639. tg3_writephy(tp, MII_BMCR,
  8640. BMCR_ANENABLE | BMCR_ANRESTART);
  8641. }
  8642. tg3_phy_set_wirespeed(tp);
  8643. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8644. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8645. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8646. }
  8647. skip_phy_reset:
  8648. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8649. err = tg3_init_5401phy_dsp(tp);
  8650. if (err)
  8651. return err;
  8652. }
  8653. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8654. err = tg3_init_5401phy_dsp(tp);
  8655. }
  8656. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8657. tp->link_config.advertising =
  8658. (ADVERTISED_1000baseT_Half |
  8659. ADVERTISED_1000baseT_Full |
  8660. ADVERTISED_Autoneg |
  8661. ADVERTISED_FIBRE);
  8662. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8663. tp->link_config.advertising &=
  8664. ~(ADVERTISED_1000baseT_Half |
  8665. ADVERTISED_1000baseT_Full);
  8666. return err;
  8667. }
  8668. static void __devinit tg3_read_partno(struct tg3 *tp)
  8669. {
  8670. unsigned char vpd_data[256];
  8671. unsigned int i;
  8672. u32 magic;
  8673. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8674. goto out_not_found;
  8675. if (magic == TG3_EEPROM_MAGIC) {
  8676. for (i = 0; i < 256; i += 4) {
  8677. u32 tmp;
  8678. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8679. goto out_not_found;
  8680. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8681. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8682. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8683. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8684. }
  8685. } else {
  8686. int vpd_cap;
  8687. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8688. for (i = 0; i < 256; i += 4) {
  8689. u32 tmp, j = 0;
  8690. u16 tmp16;
  8691. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8692. i);
  8693. while (j++ < 100) {
  8694. pci_read_config_word(tp->pdev, vpd_cap +
  8695. PCI_VPD_ADDR, &tmp16);
  8696. if (tmp16 & 0x8000)
  8697. break;
  8698. msleep(1);
  8699. }
  8700. if (!(tmp16 & 0x8000))
  8701. goto out_not_found;
  8702. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8703. &tmp);
  8704. tmp = cpu_to_le32(tmp);
  8705. memcpy(&vpd_data[i], &tmp, 4);
  8706. }
  8707. }
  8708. /* Now parse and find the part number. */
  8709. for (i = 0; i < 254; ) {
  8710. unsigned char val = vpd_data[i];
  8711. unsigned int block_end;
  8712. if (val == 0x82 || val == 0x91) {
  8713. i = (i + 3 +
  8714. (vpd_data[i + 1] +
  8715. (vpd_data[i + 2] << 8)));
  8716. continue;
  8717. }
  8718. if (val != 0x90)
  8719. goto out_not_found;
  8720. block_end = (i + 3 +
  8721. (vpd_data[i + 1] +
  8722. (vpd_data[i + 2] << 8)));
  8723. i += 3;
  8724. if (block_end > 256)
  8725. goto out_not_found;
  8726. while (i < (block_end - 2)) {
  8727. if (vpd_data[i + 0] == 'P' &&
  8728. vpd_data[i + 1] == 'N') {
  8729. int partno_len = vpd_data[i + 2];
  8730. i += 3;
  8731. if (partno_len > 24 || (partno_len + i) > 256)
  8732. goto out_not_found;
  8733. memcpy(tp->board_part_number,
  8734. &vpd_data[i], partno_len);
  8735. /* Success. */
  8736. return;
  8737. }
  8738. i += 3 + vpd_data[i + 2];
  8739. }
  8740. /* Part number not found. */
  8741. goto out_not_found;
  8742. }
  8743. out_not_found:
  8744. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8745. strcpy(tp->board_part_number, "BCM95906");
  8746. else
  8747. strcpy(tp->board_part_number, "none");
  8748. }
  8749. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8750. {
  8751. u32 val, offset, start;
  8752. if (tg3_nvram_read_swab(tp, 0, &val))
  8753. return;
  8754. if (val != TG3_EEPROM_MAGIC)
  8755. return;
  8756. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8757. tg3_nvram_read_swab(tp, 0x4, &start))
  8758. return;
  8759. offset = tg3_nvram_logical_addr(tp, offset);
  8760. if (tg3_nvram_read_swab(tp, offset, &val))
  8761. return;
  8762. if ((val & 0xfc000000) == 0x0c000000) {
  8763. u32 ver_offset, addr;
  8764. int i;
  8765. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8766. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8767. return;
  8768. if (val != 0)
  8769. return;
  8770. addr = offset + ver_offset - start;
  8771. for (i = 0; i < 16; i += 4) {
  8772. if (tg3_nvram_read(tp, addr + i, &val))
  8773. return;
  8774. val = cpu_to_le32(val);
  8775. memcpy(tp->fw_ver + i, &val, 4);
  8776. }
  8777. }
  8778. }
  8779. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8780. {
  8781. static struct pci_device_id write_reorder_chipsets[] = {
  8782. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8783. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8784. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8785. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8786. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8787. PCI_DEVICE_ID_VIA_8385_0) },
  8788. { },
  8789. };
  8790. u32 misc_ctrl_reg;
  8791. u32 cacheline_sz_reg;
  8792. u32 pci_state_reg, grc_misc_cfg;
  8793. u32 val;
  8794. u16 pci_cmd;
  8795. int err, pcie_cap;
  8796. /* Force memory write invalidate off. If we leave it on,
  8797. * then on 5700_BX chips we have to enable a workaround.
  8798. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8799. * to match the cacheline size. The Broadcom driver have this
  8800. * workaround but turns MWI off all the times so never uses
  8801. * it. This seems to suggest that the workaround is insufficient.
  8802. */
  8803. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8804. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8805. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8806. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8807. * has the register indirect write enable bit set before
  8808. * we try to access any of the MMIO registers. It is also
  8809. * critical that the PCI-X hw workaround situation is decided
  8810. * before that as well.
  8811. */
  8812. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8813. &misc_ctrl_reg);
  8814. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8815. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8816. /* Wrong chip ID in 5752 A0. This code can be removed later
  8817. * as A0 is not in production.
  8818. */
  8819. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8820. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8821. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8822. * we need to disable memory and use config. cycles
  8823. * only to access all registers. The 5702/03 chips
  8824. * can mistakenly decode the special cycles from the
  8825. * ICH chipsets as memory write cycles, causing corruption
  8826. * of register and memory space. Only certain ICH bridges
  8827. * will drive special cycles with non-zero data during the
  8828. * address phase which can fall within the 5703's address
  8829. * range. This is not an ICH bug as the PCI spec allows
  8830. * non-zero address during special cycles. However, only
  8831. * these ICH bridges are known to drive non-zero addresses
  8832. * during special cycles.
  8833. *
  8834. * Since special cycles do not cross PCI bridges, we only
  8835. * enable this workaround if the 5703 is on the secondary
  8836. * bus of these ICH bridges.
  8837. */
  8838. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8839. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8840. static struct tg3_dev_id {
  8841. u32 vendor;
  8842. u32 device;
  8843. u32 rev;
  8844. } ich_chipsets[] = {
  8845. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8846. PCI_ANY_ID },
  8847. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8848. PCI_ANY_ID },
  8849. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8850. 0xa },
  8851. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8852. PCI_ANY_ID },
  8853. { },
  8854. };
  8855. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8856. struct pci_dev *bridge = NULL;
  8857. while (pci_id->vendor != 0) {
  8858. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8859. bridge);
  8860. if (!bridge) {
  8861. pci_id++;
  8862. continue;
  8863. }
  8864. if (pci_id->rev != PCI_ANY_ID) {
  8865. u8 rev;
  8866. pci_read_config_byte(bridge, PCI_REVISION_ID,
  8867. &rev);
  8868. if (rev > pci_id->rev)
  8869. continue;
  8870. }
  8871. if (bridge->subordinate &&
  8872. (bridge->subordinate->number ==
  8873. tp->pdev->bus->number)) {
  8874. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8875. pci_dev_put(bridge);
  8876. break;
  8877. }
  8878. }
  8879. }
  8880. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8881. * DMA addresses > 40-bit. This bridge may have other additional
  8882. * 57xx devices behind it in some 4-port NIC designs for example.
  8883. * Any tg3 device found behind the bridge will also need the 40-bit
  8884. * DMA workaround.
  8885. */
  8886. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8887. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8888. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8889. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8890. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8891. }
  8892. else {
  8893. struct pci_dev *bridge = NULL;
  8894. do {
  8895. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8896. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8897. bridge);
  8898. if (bridge && bridge->subordinate &&
  8899. (bridge->subordinate->number <=
  8900. tp->pdev->bus->number) &&
  8901. (bridge->subordinate->subordinate >=
  8902. tp->pdev->bus->number)) {
  8903. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8904. pci_dev_put(bridge);
  8905. break;
  8906. }
  8907. } while (bridge);
  8908. }
  8909. /* Initialize misc host control in PCI block. */
  8910. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8911. MISC_HOST_CTRL_CHIPREV);
  8912. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8913. tp->misc_host_ctrl);
  8914. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8915. &cacheline_sz_reg);
  8916. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8917. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8918. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8919. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8920. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8921. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8922. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8923. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8924. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  8925. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8926. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8927. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8928. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8929. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8930. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8931. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8932. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8933. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8934. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8935. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8936. } else {
  8937. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  8938. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8939. ASIC_REV_5750 &&
  8940. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  8941. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  8942. }
  8943. }
  8944. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  8945. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  8946. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  8947. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  8948. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  8949. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  8950. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  8951. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  8952. if (pcie_cap != 0) {
  8953. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  8954. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8955. u16 lnkctl;
  8956. pci_read_config_word(tp->pdev,
  8957. pcie_cap + PCI_EXP_LNKCTL,
  8958. &lnkctl);
  8959. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  8960. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  8961. }
  8962. }
  8963. /* If we have an AMD 762 or VIA K8T800 chipset, write
  8964. * reordering to the mailbox registers done by the host
  8965. * controller can cause major troubles. We read back from
  8966. * every mailbox register write to force the writes to be
  8967. * posted to the chip in order.
  8968. */
  8969. if (pci_dev_present(write_reorder_chipsets) &&
  8970. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  8971. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  8972. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  8973. tp->pci_lat_timer < 64) {
  8974. tp->pci_lat_timer = 64;
  8975. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  8976. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  8977. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  8978. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  8979. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8980. cacheline_sz_reg);
  8981. }
  8982. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  8983. &pci_state_reg);
  8984. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  8985. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  8986. /* If this is a 5700 BX chipset, and we are in PCI-X
  8987. * mode, enable register write workaround.
  8988. *
  8989. * The workaround is to use indirect register accesses
  8990. * for all chip writes not to mailbox registers.
  8991. */
  8992. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  8993. u32 pm_reg;
  8994. u16 pci_cmd;
  8995. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  8996. /* The chip can have it's power management PCI config
  8997. * space registers clobbered due to this bug.
  8998. * So explicitly force the chip into D0 here.
  8999. */
  9000. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9001. &pm_reg);
  9002. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9003. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9004. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9005. pm_reg);
  9006. /* Also, force SERR#/PERR# in PCI command. */
  9007. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9008. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9009. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9010. }
  9011. }
  9012. /* 5700 BX chips need to have their TX producer index mailboxes
  9013. * written twice to workaround a bug.
  9014. */
  9015. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9016. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9017. /* Back to back register writes can cause problems on this chip,
  9018. * the workaround is to read back all reg writes except those to
  9019. * mailbox regs. See tg3_write_indirect_reg32().
  9020. *
  9021. * PCI Express 5750_A0 rev chips need this workaround too.
  9022. */
  9023. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9024. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9025. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0))
  9026. tp->tg3_flags |= TG3_FLAG_5701_REG_WRITE_BUG;
  9027. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9028. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9029. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9030. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9031. /* Chip-specific fixup from Broadcom driver */
  9032. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9033. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9034. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9035. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9036. }
  9037. /* Default fast path register access methods */
  9038. tp->read32 = tg3_read32;
  9039. tp->write32 = tg3_write32;
  9040. tp->read32_mbox = tg3_read32;
  9041. tp->write32_mbox = tg3_write32;
  9042. tp->write32_tx_mbox = tg3_write32;
  9043. tp->write32_rx_mbox = tg3_write32;
  9044. /* Various workaround register access methods */
  9045. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9046. tp->write32 = tg3_write_indirect_reg32;
  9047. else if (tp->tg3_flags & TG3_FLAG_5701_REG_WRITE_BUG)
  9048. tp->write32 = tg3_write_flush_reg32;
  9049. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9050. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9051. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9052. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9053. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9054. }
  9055. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9056. tp->read32 = tg3_read_indirect_reg32;
  9057. tp->write32 = tg3_write_indirect_reg32;
  9058. tp->read32_mbox = tg3_read_indirect_mbox;
  9059. tp->write32_mbox = tg3_write_indirect_mbox;
  9060. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9061. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9062. iounmap(tp->regs);
  9063. tp->regs = NULL;
  9064. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9065. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9066. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9067. }
  9068. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9069. tp->read32_mbox = tg3_read32_mbox_5906;
  9070. tp->write32_mbox = tg3_write32_mbox_5906;
  9071. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9072. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9073. }
  9074. if (tp->write32 == tg3_write_indirect_reg32 ||
  9075. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9076. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9077. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9078. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9079. /* Get eeprom hw config before calling tg3_set_power_state().
  9080. * In particular, the TG3_FLG2_IS_NIC flag must be
  9081. * determined before calling tg3_set_power_state() so that
  9082. * we know whether or not to switch out of Vaux power.
  9083. * When the flag is set, it means that GPIO1 is used for eeprom
  9084. * write protect and also implies that it is a LOM where GPIOs
  9085. * are not used to switch power.
  9086. */
  9087. tg3_get_eeprom_hw_cfg(tp);
  9088. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9089. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9090. * It is also used as eeprom write protect on LOMs.
  9091. */
  9092. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9093. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9094. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9095. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9096. GRC_LCLCTRL_GPIO_OUTPUT1);
  9097. /* Unused GPIO3 must be driven as output on 5752 because there
  9098. * are no pull-up resistors on unused GPIO pins.
  9099. */
  9100. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9101. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9102. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9103. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9104. /* Force the chip into D0. */
  9105. err = tg3_set_power_state(tp, PCI_D0);
  9106. if (err) {
  9107. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9108. pci_name(tp->pdev));
  9109. return err;
  9110. }
  9111. /* 5700 B0 chips do not support checksumming correctly due
  9112. * to hardware bugs.
  9113. */
  9114. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9115. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9116. /* Derive initial jumbo mode from MTU assigned in
  9117. * ether_setup() via the alloc_etherdev() call
  9118. */
  9119. if (tp->dev->mtu > ETH_DATA_LEN &&
  9120. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9121. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9122. /* Determine WakeOnLan speed to use. */
  9123. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9124. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9125. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9126. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9127. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9128. } else {
  9129. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9130. }
  9131. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9132. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9133. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9134. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9135. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9136. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9137. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9138. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9139. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9140. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9141. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9142. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9143. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9144. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9145. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9146. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  9147. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9148. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9149. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9150. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9151. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9152. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9153. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9154. }
  9155. tp->coalesce_mode = 0;
  9156. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9157. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9158. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9159. /* Initialize MAC MI mode, polling disabled. */
  9160. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9161. udelay(80);
  9162. /* Initialize data/descriptor byte/word swapping. */
  9163. val = tr32(GRC_MODE);
  9164. val &= GRC_MODE_HOST_STACKUP;
  9165. tw32(GRC_MODE, val | tp->grc_mode);
  9166. tg3_switch_clocks(tp);
  9167. /* Clear this out for sanity. */
  9168. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9169. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9170. &pci_state_reg);
  9171. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9172. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9173. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9174. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9175. chiprevid == CHIPREV_ID_5701_B0 ||
  9176. chiprevid == CHIPREV_ID_5701_B2 ||
  9177. chiprevid == CHIPREV_ID_5701_B5) {
  9178. void __iomem *sram_base;
  9179. /* Write some dummy words into the SRAM status block
  9180. * area, see if it reads back correctly. If the return
  9181. * value is bad, force enable the PCIX workaround.
  9182. */
  9183. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9184. writel(0x00000000, sram_base);
  9185. writel(0x00000000, sram_base + 4);
  9186. writel(0xffffffff, sram_base + 4);
  9187. if (readl(sram_base) != 0x00000000)
  9188. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9189. }
  9190. }
  9191. udelay(50);
  9192. tg3_nvram_init(tp);
  9193. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9194. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9195. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9196. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9197. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9198. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9199. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9200. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9201. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9202. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9203. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9204. HOSTCC_MODE_CLRTICK_TXBD);
  9205. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9206. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9207. tp->misc_host_ctrl);
  9208. }
  9209. /* these are limited to 10/100 only */
  9210. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9211. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9212. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9213. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9214. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9215. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9216. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9217. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9218. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9219. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9220. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9221. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9222. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9223. err = tg3_phy_probe(tp);
  9224. if (err) {
  9225. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9226. pci_name(tp->pdev), err);
  9227. /* ... but do not return immediately ... */
  9228. }
  9229. tg3_read_partno(tp);
  9230. tg3_read_fw_ver(tp);
  9231. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  9232. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9233. } else {
  9234. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9235. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  9236. else
  9237. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9238. }
  9239. /* 5700 {AX,BX} chips have a broken status block link
  9240. * change bit implementation, so we must use the
  9241. * status register in those cases.
  9242. */
  9243. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9244. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9245. else
  9246. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9247. /* The led_ctrl is set during tg3_phy_probe, here we might
  9248. * have to force the link status polling mechanism based
  9249. * upon subsystem IDs.
  9250. */
  9251. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9252. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9253. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9254. TG3_FLAG_USE_LINKCHG_REG);
  9255. }
  9256. /* For all SERDES we poll the MAC status register. */
  9257. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9258. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9259. else
  9260. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9261. /* All chips before 5787 can get confused if TX buffers
  9262. * straddle the 4GB address boundary in some cases.
  9263. */
  9264. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9265. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9266. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9267. tp->dev->hard_start_xmit = tg3_start_xmit;
  9268. else
  9269. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9270. tp->rx_offset = 2;
  9271. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9272. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9273. tp->rx_offset = 0;
  9274. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9275. /* Increment the rx prod index on the rx std ring by at most
  9276. * 8 for these chips to workaround hw errata.
  9277. */
  9278. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9279. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9280. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9281. tp->rx_std_max_post = 8;
  9282. /* By default, disable wake-on-lan. User can change this
  9283. * using ETHTOOL_SWOL.
  9284. */
  9285. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9286. return err;
  9287. }
  9288. #ifdef CONFIG_SPARC64
  9289. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9290. {
  9291. struct net_device *dev = tp->dev;
  9292. struct pci_dev *pdev = tp->pdev;
  9293. struct pcidev_cookie *pcp = pdev->sysdata;
  9294. if (pcp != NULL) {
  9295. unsigned char *addr;
  9296. int len;
  9297. addr = of_get_property(pcp->prom_node, "local-mac-address",
  9298. &len);
  9299. if (addr && len == 6) {
  9300. memcpy(dev->dev_addr, addr, 6);
  9301. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9302. return 0;
  9303. }
  9304. }
  9305. return -ENODEV;
  9306. }
  9307. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9308. {
  9309. struct net_device *dev = tp->dev;
  9310. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9311. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9312. return 0;
  9313. }
  9314. #endif
  9315. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9316. {
  9317. struct net_device *dev = tp->dev;
  9318. u32 hi, lo, mac_offset;
  9319. int addr_ok = 0;
  9320. #ifdef CONFIG_SPARC64
  9321. if (!tg3_get_macaddr_sparc(tp))
  9322. return 0;
  9323. #endif
  9324. mac_offset = 0x7c;
  9325. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9326. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9327. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9328. mac_offset = 0xcc;
  9329. if (tg3_nvram_lock(tp))
  9330. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9331. else
  9332. tg3_nvram_unlock(tp);
  9333. }
  9334. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9335. mac_offset = 0x10;
  9336. /* First try to get it from MAC address mailbox. */
  9337. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9338. if ((hi >> 16) == 0x484b) {
  9339. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9340. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9341. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9342. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9343. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9344. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9345. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9346. /* Some old bootcode may report a 0 MAC address in SRAM */
  9347. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9348. }
  9349. if (!addr_ok) {
  9350. /* Next, try NVRAM. */
  9351. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9352. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9353. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9354. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9355. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9356. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9357. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9358. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9359. }
  9360. /* Finally just fetch it out of the MAC control regs. */
  9361. else {
  9362. hi = tr32(MAC_ADDR_0_HIGH);
  9363. lo = tr32(MAC_ADDR_0_LOW);
  9364. dev->dev_addr[5] = lo & 0xff;
  9365. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9366. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9367. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9368. dev->dev_addr[1] = hi & 0xff;
  9369. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9370. }
  9371. }
  9372. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9373. #ifdef CONFIG_SPARC64
  9374. if (!tg3_get_default_macaddr_sparc(tp))
  9375. return 0;
  9376. #endif
  9377. return -EINVAL;
  9378. }
  9379. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9380. return 0;
  9381. }
  9382. #define BOUNDARY_SINGLE_CACHELINE 1
  9383. #define BOUNDARY_MULTI_CACHELINE 2
  9384. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9385. {
  9386. int cacheline_size;
  9387. u8 byte;
  9388. int goal;
  9389. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9390. if (byte == 0)
  9391. cacheline_size = 1024;
  9392. else
  9393. cacheline_size = (int) byte * 4;
  9394. /* On 5703 and later chips, the boundary bits have no
  9395. * effect.
  9396. */
  9397. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9398. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9399. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9400. goto out;
  9401. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9402. goal = BOUNDARY_MULTI_CACHELINE;
  9403. #else
  9404. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9405. goal = BOUNDARY_SINGLE_CACHELINE;
  9406. #else
  9407. goal = 0;
  9408. #endif
  9409. #endif
  9410. if (!goal)
  9411. goto out;
  9412. /* PCI controllers on most RISC systems tend to disconnect
  9413. * when a device tries to burst across a cache-line boundary.
  9414. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9415. *
  9416. * Unfortunately, for PCI-E there are only limited
  9417. * write-side controls for this, and thus for reads
  9418. * we will still get the disconnects. We'll also waste
  9419. * these PCI cycles for both read and write for chips
  9420. * other than 5700 and 5701 which do not implement the
  9421. * boundary bits.
  9422. */
  9423. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9424. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9425. switch (cacheline_size) {
  9426. case 16:
  9427. case 32:
  9428. case 64:
  9429. case 128:
  9430. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9431. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9432. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9433. } else {
  9434. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9435. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9436. }
  9437. break;
  9438. case 256:
  9439. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9440. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9441. break;
  9442. default:
  9443. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9444. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9445. break;
  9446. };
  9447. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9448. switch (cacheline_size) {
  9449. case 16:
  9450. case 32:
  9451. case 64:
  9452. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9453. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9454. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9455. break;
  9456. }
  9457. /* fallthrough */
  9458. case 128:
  9459. default:
  9460. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9461. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9462. break;
  9463. };
  9464. } else {
  9465. switch (cacheline_size) {
  9466. case 16:
  9467. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9468. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9469. DMA_RWCTRL_WRITE_BNDRY_16);
  9470. break;
  9471. }
  9472. /* fallthrough */
  9473. case 32:
  9474. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9475. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9476. DMA_RWCTRL_WRITE_BNDRY_32);
  9477. break;
  9478. }
  9479. /* fallthrough */
  9480. case 64:
  9481. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9482. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9483. DMA_RWCTRL_WRITE_BNDRY_64);
  9484. break;
  9485. }
  9486. /* fallthrough */
  9487. case 128:
  9488. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9489. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9490. DMA_RWCTRL_WRITE_BNDRY_128);
  9491. break;
  9492. }
  9493. /* fallthrough */
  9494. case 256:
  9495. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9496. DMA_RWCTRL_WRITE_BNDRY_256);
  9497. break;
  9498. case 512:
  9499. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9500. DMA_RWCTRL_WRITE_BNDRY_512);
  9501. break;
  9502. case 1024:
  9503. default:
  9504. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9505. DMA_RWCTRL_WRITE_BNDRY_1024);
  9506. break;
  9507. };
  9508. }
  9509. out:
  9510. return val;
  9511. }
  9512. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9513. {
  9514. struct tg3_internal_buffer_desc test_desc;
  9515. u32 sram_dma_descs;
  9516. int i, ret;
  9517. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9518. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9519. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9520. tw32(RDMAC_STATUS, 0);
  9521. tw32(WDMAC_STATUS, 0);
  9522. tw32(BUFMGR_MODE, 0);
  9523. tw32(FTQ_RESET, 0);
  9524. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9525. test_desc.addr_lo = buf_dma & 0xffffffff;
  9526. test_desc.nic_mbuf = 0x00002100;
  9527. test_desc.len = size;
  9528. /*
  9529. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9530. * the *second* time the tg3 driver was getting loaded after an
  9531. * initial scan.
  9532. *
  9533. * Broadcom tells me:
  9534. * ...the DMA engine is connected to the GRC block and a DMA
  9535. * reset may affect the GRC block in some unpredictable way...
  9536. * The behavior of resets to individual blocks has not been tested.
  9537. *
  9538. * Broadcom noted the GRC reset will also reset all sub-components.
  9539. */
  9540. if (to_device) {
  9541. test_desc.cqid_sqid = (13 << 8) | 2;
  9542. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9543. udelay(40);
  9544. } else {
  9545. test_desc.cqid_sqid = (16 << 8) | 7;
  9546. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9547. udelay(40);
  9548. }
  9549. test_desc.flags = 0x00000005;
  9550. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9551. u32 val;
  9552. val = *(((u32 *)&test_desc) + i);
  9553. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9554. sram_dma_descs + (i * sizeof(u32)));
  9555. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9556. }
  9557. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9558. if (to_device) {
  9559. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9560. } else {
  9561. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9562. }
  9563. ret = -ENODEV;
  9564. for (i = 0; i < 40; i++) {
  9565. u32 val;
  9566. if (to_device)
  9567. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9568. else
  9569. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9570. if ((val & 0xffff) == sram_dma_descs) {
  9571. ret = 0;
  9572. break;
  9573. }
  9574. udelay(100);
  9575. }
  9576. return ret;
  9577. }
  9578. #define TEST_BUFFER_SIZE 0x2000
  9579. static int __devinit tg3_test_dma(struct tg3 *tp)
  9580. {
  9581. dma_addr_t buf_dma;
  9582. u32 *buf, saved_dma_rwctrl;
  9583. int ret;
  9584. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9585. if (!buf) {
  9586. ret = -ENOMEM;
  9587. goto out_nofree;
  9588. }
  9589. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9590. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9591. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9592. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9593. /* DMA read watermark not used on PCIE */
  9594. tp->dma_rwctrl |= 0x00180000;
  9595. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9596. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9597. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9598. tp->dma_rwctrl |= 0x003f0000;
  9599. else
  9600. tp->dma_rwctrl |= 0x003f000f;
  9601. } else {
  9602. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9603. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9604. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9605. u32 read_water = 0x7;
  9606. /* If the 5704 is behind the EPB bridge, we can
  9607. * do the less restrictive ONE_DMA workaround for
  9608. * better performance.
  9609. */
  9610. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9611. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9612. tp->dma_rwctrl |= 0x8000;
  9613. else if (ccval == 0x6 || ccval == 0x7)
  9614. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9615. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  9616. read_water = 4;
  9617. /* Set bit 23 to enable PCIX hw bug fix */
  9618. tp->dma_rwctrl |=
  9619. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  9620. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  9621. (1 << 23);
  9622. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9623. /* 5780 always in PCIX mode */
  9624. tp->dma_rwctrl |= 0x00144000;
  9625. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9626. /* 5714 always in PCIX mode */
  9627. tp->dma_rwctrl |= 0x00148000;
  9628. } else {
  9629. tp->dma_rwctrl |= 0x001b000f;
  9630. }
  9631. }
  9632. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9633. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9634. tp->dma_rwctrl &= 0xfffffff0;
  9635. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9636. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9637. /* Remove this if it causes problems for some boards. */
  9638. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9639. /* On 5700/5701 chips, we need to set this bit.
  9640. * Otherwise the chip will issue cacheline transactions
  9641. * to streamable DMA memory with not all the byte
  9642. * enables turned on. This is an error on several
  9643. * RISC PCI controllers, in particular sparc64.
  9644. *
  9645. * On 5703/5704 chips, this bit has been reassigned
  9646. * a different meaning. In particular, it is used
  9647. * on those chips to enable a PCI-X workaround.
  9648. */
  9649. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9650. }
  9651. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9652. #if 0
  9653. /* Unneeded, already done by tg3_get_invariants. */
  9654. tg3_switch_clocks(tp);
  9655. #endif
  9656. ret = 0;
  9657. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9658. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9659. goto out;
  9660. /* It is best to perform DMA test with maximum write burst size
  9661. * to expose the 5700/5701 write DMA bug.
  9662. */
  9663. saved_dma_rwctrl = tp->dma_rwctrl;
  9664. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9665. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9666. while (1) {
  9667. u32 *p = buf, i;
  9668. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9669. p[i] = i;
  9670. /* Send the buffer to the chip. */
  9671. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9672. if (ret) {
  9673. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9674. break;
  9675. }
  9676. #if 0
  9677. /* validate data reached card RAM correctly. */
  9678. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9679. u32 val;
  9680. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9681. if (le32_to_cpu(val) != p[i]) {
  9682. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9683. /* ret = -ENODEV here? */
  9684. }
  9685. p[i] = 0;
  9686. }
  9687. #endif
  9688. /* Now read it back. */
  9689. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9690. if (ret) {
  9691. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9692. break;
  9693. }
  9694. /* Verify it. */
  9695. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9696. if (p[i] == i)
  9697. continue;
  9698. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9699. DMA_RWCTRL_WRITE_BNDRY_16) {
  9700. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9701. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9702. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9703. break;
  9704. } else {
  9705. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9706. ret = -ENODEV;
  9707. goto out;
  9708. }
  9709. }
  9710. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9711. /* Success. */
  9712. ret = 0;
  9713. break;
  9714. }
  9715. }
  9716. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9717. DMA_RWCTRL_WRITE_BNDRY_16) {
  9718. static struct pci_device_id dma_wait_state_chipsets[] = {
  9719. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9720. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9721. { },
  9722. };
  9723. /* DMA test passed without adjusting DMA boundary,
  9724. * now look for chipsets that are known to expose the
  9725. * DMA bug without failing the test.
  9726. */
  9727. if (pci_dev_present(dma_wait_state_chipsets)) {
  9728. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9729. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9730. }
  9731. else
  9732. /* Safe to use the calculated DMA boundary. */
  9733. tp->dma_rwctrl = saved_dma_rwctrl;
  9734. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9735. }
  9736. out:
  9737. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9738. out_nofree:
  9739. return ret;
  9740. }
  9741. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9742. {
  9743. tp->link_config.advertising =
  9744. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9745. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9746. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9747. ADVERTISED_Autoneg | ADVERTISED_MII);
  9748. tp->link_config.speed = SPEED_INVALID;
  9749. tp->link_config.duplex = DUPLEX_INVALID;
  9750. tp->link_config.autoneg = AUTONEG_ENABLE;
  9751. tp->link_config.active_speed = SPEED_INVALID;
  9752. tp->link_config.active_duplex = DUPLEX_INVALID;
  9753. tp->link_config.phy_is_low_power = 0;
  9754. tp->link_config.orig_speed = SPEED_INVALID;
  9755. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9756. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9757. }
  9758. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9759. {
  9760. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9761. tp->bufmgr_config.mbuf_read_dma_low_water =
  9762. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9763. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9764. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9765. tp->bufmgr_config.mbuf_high_water =
  9766. DEFAULT_MB_HIGH_WATER_5705;
  9767. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9768. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9769. DEFAULT_MB_MACRX_LOW_WATER_5906;
  9770. tp->bufmgr_config.mbuf_high_water =
  9771. DEFAULT_MB_HIGH_WATER_5906;
  9772. }
  9773. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9774. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9775. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9776. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9777. tp->bufmgr_config.mbuf_high_water_jumbo =
  9778. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9779. } else {
  9780. tp->bufmgr_config.mbuf_read_dma_low_water =
  9781. DEFAULT_MB_RDMA_LOW_WATER;
  9782. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9783. DEFAULT_MB_MACRX_LOW_WATER;
  9784. tp->bufmgr_config.mbuf_high_water =
  9785. DEFAULT_MB_HIGH_WATER;
  9786. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9787. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9788. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9789. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9790. tp->bufmgr_config.mbuf_high_water_jumbo =
  9791. DEFAULT_MB_HIGH_WATER_JUMBO;
  9792. }
  9793. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9794. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9795. }
  9796. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9797. {
  9798. switch (tp->phy_id & PHY_ID_MASK) {
  9799. case PHY_ID_BCM5400: return "5400";
  9800. case PHY_ID_BCM5401: return "5401";
  9801. case PHY_ID_BCM5411: return "5411";
  9802. case PHY_ID_BCM5701: return "5701";
  9803. case PHY_ID_BCM5703: return "5703";
  9804. case PHY_ID_BCM5704: return "5704";
  9805. case PHY_ID_BCM5705: return "5705";
  9806. case PHY_ID_BCM5750: return "5750";
  9807. case PHY_ID_BCM5752: return "5752";
  9808. case PHY_ID_BCM5714: return "5714";
  9809. case PHY_ID_BCM5780: return "5780";
  9810. case PHY_ID_BCM5755: return "5755";
  9811. case PHY_ID_BCM5787: return "5787";
  9812. case PHY_ID_BCM5756: return "5722/5756";
  9813. case PHY_ID_BCM5906: return "5906";
  9814. case PHY_ID_BCM8002: return "8002/serdes";
  9815. case 0: return "serdes";
  9816. default: return "unknown";
  9817. };
  9818. }
  9819. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9820. {
  9821. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9822. strcpy(str, "PCI Express");
  9823. return str;
  9824. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9825. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9826. strcpy(str, "PCIX:");
  9827. if ((clock_ctrl == 7) ||
  9828. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9829. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9830. strcat(str, "133MHz");
  9831. else if (clock_ctrl == 0)
  9832. strcat(str, "33MHz");
  9833. else if (clock_ctrl == 2)
  9834. strcat(str, "50MHz");
  9835. else if (clock_ctrl == 4)
  9836. strcat(str, "66MHz");
  9837. else if (clock_ctrl == 6)
  9838. strcat(str, "100MHz");
  9839. } else {
  9840. strcpy(str, "PCI:");
  9841. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9842. strcat(str, "66MHz");
  9843. else
  9844. strcat(str, "33MHz");
  9845. }
  9846. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9847. strcat(str, ":32-bit");
  9848. else
  9849. strcat(str, ":64-bit");
  9850. return str;
  9851. }
  9852. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9853. {
  9854. struct pci_dev *peer;
  9855. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9856. for (func = 0; func < 8; func++) {
  9857. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9858. if (peer && peer != tp->pdev)
  9859. break;
  9860. pci_dev_put(peer);
  9861. }
  9862. /* 5704 can be configured in single-port mode, set peer to
  9863. * tp->pdev in that case.
  9864. */
  9865. if (!peer) {
  9866. peer = tp->pdev;
  9867. return peer;
  9868. }
  9869. /*
  9870. * We don't need to keep the refcount elevated; there's no way
  9871. * to remove one half of this device without removing the other
  9872. */
  9873. pci_dev_put(peer);
  9874. return peer;
  9875. }
  9876. static void __devinit tg3_init_coal(struct tg3 *tp)
  9877. {
  9878. struct ethtool_coalesce *ec = &tp->coal;
  9879. memset(ec, 0, sizeof(*ec));
  9880. ec->cmd = ETHTOOL_GCOALESCE;
  9881. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9882. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9883. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9884. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9885. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9886. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9887. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9888. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9889. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9890. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9891. HOSTCC_MODE_CLRTICK_TXBD)) {
  9892. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9893. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9894. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9895. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9896. }
  9897. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9898. ec->rx_coalesce_usecs_irq = 0;
  9899. ec->tx_coalesce_usecs_irq = 0;
  9900. ec->stats_block_coalesce_usecs = 0;
  9901. }
  9902. }
  9903. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9904. const struct pci_device_id *ent)
  9905. {
  9906. static int tg3_version_printed = 0;
  9907. unsigned long tg3reg_base, tg3reg_len;
  9908. struct net_device *dev;
  9909. struct tg3 *tp;
  9910. int i, err, pm_cap;
  9911. char str[40];
  9912. u64 dma_mask, persist_dma_mask;
  9913. if (tg3_version_printed++ == 0)
  9914. printk(KERN_INFO "%s", version);
  9915. err = pci_enable_device(pdev);
  9916. if (err) {
  9917. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9918. "aborting.\n");
  9919. return err;
  9920. }
  9921. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9922. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9923. "base address, aborting.\n");
  9924. err = -ENODEV;
  9925. goto err_out_disable_pdev;
  9926. }
  9927. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9928. if (err) {
  9929. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9930. "aborting.\n");
  9931. goto err_out_disable_pdev;
  9932. }
  9933. pci_set_master(pdev);
  9934. /* Find power-management capability. */
  9935. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9936. if (pm_cap == 0) {
  9937. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  9938. "aborting.\n");
  9939. err = -EIO;
  9940. goto err_out_free_res;
  9941. }
  9942. tg3reg_base = pci_resource_start(pdev, 0);
  9943. tg3reg_len = pci_resource_len(pdev, 0);
  9944. dev = alloc_etherdev(sizeof(*tp));
  9945. if (!dev) {
  9946. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  9947. err = -ENOMEM;
  9948. goto err_out_free_res;
  9949. }
  9950. SET_MODULE_OWNER(dev);
  9951. SET_NETDEV_DEV(dev, &pdev->dev);
  9952. #if TG3_VLAN_TAG_USED
  9953. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  9954. dev->vlan_rx_register = tg3_vlan_rx_register;
  9955. dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
  9956. #endif
  9957. tp = netdev_priv(dev);
  9958. tp->pdev = pdev;
  9959. tp->dev = dev;
  9960. tp->pm_cap = pm_cap;
  9961. tp->mac_mode = TG3_DEF_MAC_MODE;
  9962. tp->rx_mode = TG3_DEF_RX_MODE;
  9963. tp->tx_mode = TG3_DEF_TX_MODE;
  9964. tp->mi_mode = MAC_MI_MODE_BASE;
  9965. if (tg3_debug > 0)
  9966. tp->msg_enable = tg3_debug;
  9967. else
  9968. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  9969. /* The word/byte swap controls here control register access byte
  9970. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  9971. * setting below.
  9972. */
  9973. tp->misc_host_ctrl =
  9974. MISC_HOST_CTRL_MASK_PCI_INT |
  9975. MISC_HOST_CTRL_WORD_SWAP |
  9976. MISC_HOST_CTRL_INDIR_ACCESS |
  9977. MISC_HOST_CTRL_PCISTATE_RW;
  9978. /* The NONFRM (non-frame) byte/word swap controls take effect
  9979. * on descriptor entries, anything which isn't packet data.
  9980. *
  9981. * The StrongARM chips on the board (one for tx, one for rx)
  9982. * are running in big-endian mode.
  9983. */
  9984. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  9985. GRC_MODE_WSWAP_NONFRM_DATA);
  9986. #ifdef __BIG_ENDIAN
  9987. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  9988. #endif
  9989. spin_lock_init(&tp->lock);
  9990. spin_lock_init(&tp->indirect_lock);
  9991. INIT_WORK(&tp->reset_task, tg3_reset_task);
  9992. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  9993. if (tp->regs == 0UL) {
  9994. printk(KERN_ERR PFX "Cannot map device registers, "
  9995. "aborting.\n");
  9996. err = -ENOMEM;
  9997. goto err_out_free_dev;
  9998. }
  9999. tg3_init_link_config(tp);
  10000. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10001. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10002. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10003. dev->open = tg3_open;
  10004. dev->stop = tg3_close;
  10005. dev->get_stats = tg3_get_stats;
  10006. dev->set_multicast_list = tg3_set_rx_mode;
  10007. dev->set_mac_address = tg3_set_mac_addr;
  10008. dev->do_ioctl = tg3_ioctl;
  10009. dev->tx_timeout = tg3_tx_timeout;
  10010. dev->poll = tg3_poll;
  10011. dev->ethtool_ops = &tg3_ethtool_ops;
  10012. dev->weight = 64;
  10013. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10014. dev->change_mtu = tg3_change_mtu;
  10015. dev->irq = pdev->irq;
  10016. #ifdef CONFIG_NET_POLL_CONTROLLER
  10017. dev->poll_controller = tg3_poll_controller;
  10018. #endif
  10019. err = tg3_get_invariants(tp);
  10020. if (err) {
  10021. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10022. "aborting.\n");
  10023. goto err_out_iounmap;
  10024. }
  10025. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10026. * device behind the EPB cannot support DMA addresses > 40-bit.
  10027. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10028. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10029. * do DMA address check in tg3_start_xmit().
  10030. */
  10031. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10032. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10033. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10034. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10035. #ifdef CONFIG_HIGHMEM
  10036. dma_mask = DMA_64BIT_MASK;
  10037. #endif
  10038. } else
  10039. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10040. /* Configure DMA attributes. */
  10041. if (dma_mask > DMA_32BIT_MASK) {
  10042. err = pci_set_dma_mask(pdev, dma_mask);
  10043. if (!err) {
  10044. dev->features |= NETIF_F_HIGHDMA;
  10045. err = pci_set_consistent_dma_mask(pdev,
  10046. persist_dma_mask);
  10047. if (err < 0) {
  10048. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10049. "DMA for consistent allocations\n");
  10050. goto err_out_iounmap;
  10051. }
  10052. }
  10053. }
  10054. if (err || dma_mask == DMA_32BIT_MASK) {
  10055. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10056. if (err) {
  10057. printk(KERN_ERR PFX "No usable DMA configuration, "
  10058. "aborting.\n");
  10059. goto err_out_iounmap;
  10060. }
  10061. }
  10062. tg3_init_bufmgr_config(tp);
  10063. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10064. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10065. }
  10066. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10067. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10068. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10069. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10070. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10071. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10072. } else {
  10073. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10074. }
  10075. /* TSO is on by default on chips that support hardware TSO.
  10076. * Firmware TSO on older chips gives lower performance, so it
  10077. * is off by default, but can be enabled using ethtool.
  10078. */
  10079. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10080. dev->features |= NETIF_F_TSO;
  10081. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10082. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10083. dev->features |= NETIF_F_TSO6;
  10084. }
  10085. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10086. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10087. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10088. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10089. tp->rx_pending = 63;
  10090. }
  10091. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  10092. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  10093. tp->pdev_peer = tg3_find_peer(tp);
  10094. err = tg3_get_device_address(tp);
  10095. if (err) {
  10096. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10097. "aborting.\n");
  10098. goto err_out_iounmap;
  10099. }
  10100. /*
  10101. * Reset chip in case UNDI or EFI driver did not shutdown
  10102. * DMA self test will enable WDMAC and we'll see (spurious)
  10103. * pending DMA on the PCI bus at that point.
  10104. */
  10105. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10106. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10107. pci_save_state(tp->pdev);
  10108. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10109. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10110. }
  10111. err = tg3_test_dma(tp);
  10112. if (err) {
  10113. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10114. goto err_out_iounmap;
  10115. }
  10116. /* Tigon3 can do ipv4 only... and some chips have buggy
  10117. * checksumming.
  10118. */
  10119. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10120. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10121. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  10122. dev->features |= NETIF_F_HW_CSUM;
  10123. else
  10124. dev->features |= NETIF_F_IP_CSUM;
  10125. dev->features |= NETIF_F_SG;
  10126. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10127. } else
  10128. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10129. /* flow control autonegotiation is default behavior */
  10130. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10131. tg3_init_coal(tp);
  10132. /* Now that we have fully setup the chip, save away a snapshot
  10133. * of the PCI config space. We need to restore this after
  10134. * GRC_MISC_CFG core clock resets and some resume events.
  10135. */
  10136. pci_save_state(tp->pdev);
  10137. pci_set_drvdata(pdev, dev);
  10138. err = register_netdev(dev);
  10139. if (err) {
  10140. printk(KERN_ERR PFX "Cannot register net device, "
  10141. "aborting.\n");
  10142. goto err_out_iounmap;
  10143. }
  10144. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ",
  10145. dev->name,
  10146. tp->board_part_number,
  10147. tp->pci_chip_rev_id,
  10148. tg3_phy_string(tp),
  10149. tg3_bus_string(tp, str),
  10150. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10151. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10152. "10/100/1000Base-T")));
  10153. for (i = 0; i < 6; i++)
  10154. printk("%2.2x%c", dev->dev_addr[i],
  10155. i == 5 ? '\n' : ':');
  10156. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10157. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10158. dev->name,
  10159. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10160. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10161. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10162. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10163. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10164. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10165. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10166. dev->name, tp->dma_rwctrl,
  10167. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10168. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10169. return 0;
  10170. err_out_iounmap:
  10171. if (tp->regs) {
  10172. iounmap(tp->regs);
  10173. tp->regs = NULL;
  10174. }
  10175. err_out_free_dev:
  10176. free_netdev(dev);
  10177. err_out_free_res:
  10178. pci_release_regions(pdev);
  10179. err_out_disable_pdev:
  10180. pci_disable_device(pdev);
  10181. pci_set_drvdata(pdev, NULL);
  10182. return err;
  10183. }
  10184. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10185. {
  10186. struct net_device *dev = pci_get_drvdata(pdev);
  10187. if (dev) {
  10188. struct tg3 *tp = netdev_priv(dev);
  10189. flush_scheduled_work();
  10190. unregister_netdev(dev);
  10191. if (tp->regs) {
  10192. iounmap(tp->regs);
  10193. tp->regs = NULL;
  10194. }
  10195. free_netdev(dev);
  10196. pci_release_regions(pdev);
  10197. pci_disable_device(pdev);
  10198. pci_set_drvdata(pdev, NULL);
  10199. }
  10200. }
  10201. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10202. {
  10203. struct net_device *dev = pci_get_drvdata(pdev);
  10204. struct tg3 *tp = netdev_priv(dev);
  10205. int err;
  10206. if (!netif_running(dev))
  10207. return 0;
  10208. flush_scheduled_work();
  10209. tg3_netif_stop(tp);
  10210. del_timer_sync(&tp->timer);
  10211. tg3_full_lock(tp, 1);
  10212. tg3_disable_ints(tp);
  10213. tg3_full_unlock(tp);
  10214. netif_device_detach(dev);
  10215. tg3_full_lock(tp, 0);
  10216. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10217. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  10218. tg3_full_unlock(tp);
  10219. /* Save MSI address and data for resume. */
  10220. pci_save_state(pdev);
  10221. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  10222. if (err) {
  10223. tg3_full_lock(tp, 0);
  10224. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10225. if (tg3_restart_hw(tp, 1))
  10226. goto out;
  10227. tp->timer.expires = jiffies + tp->timer_offset;
  10228. add_timer(&tp->timer);
  10229. netif_device_attach(dev);
  10230. tg3_netif_start(tp);
  10231. out:
  10232. tg3_full_unlock(tp);
  10233. }
  10234. return err;
  10235. }
  10236. static int tg3_resume(struct pci_dev *pdev)
  10237. {
  10238. struct net_device *dev = pci_get_drvdata(pdev);
  10239. struct tg3 *tp = netdev_priv(dev);
  10240. int err;
  10241. if (!netif_running(dev))
  10242. return 0;
  10243. pci_restore_state(tp->pdev);
  10244. err = tg3_set_power_state(tp, PCI_D0);
  10245. if (err)
  10246. return err;
  10247. netif_device_attach(dev);
  10248. tg3_full_lock(tp, 0);
  10249. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10250. err = tg3_restart_hw(tp, 1);
  10251. if (err)
  10252. goto out;
  10253. tp->timer.expires = jiffies + tp->timer_offset;
  10254. add_timer(&tp->timer);
  10255. tg3_netif_start(tp);
  10256. out:
  10257. tg3_full_unlock(tp);
  10258. return err;
  10259. }
  10260. static struct pci_driver tg3_driver = {
  10261. .name = DRV_MODULE_NAME,
  10262. .id_table = tg3_pci_tbl,
  10263. .probe = tg3_init_one,
  10264. .remove = __devexit_p(tg3_remove_one),
  10265. .suspend = tg3_suspend,
  10266. .resume = tg3_resume
  10267. };
  10268. static int __init tg3_init(void)
  10269. {
  10270. return pci_register_driver(&tg3_driver);
  10271. }
  10272. static void __exit tg3_cleanup(void)
  10273. {
  10274. pci_unregister_driver(&tg3_driver);
  10275. }
  10276. module_init(tg3_init);
  10277. module_exit(tg3_cleanup);