tg3.c 344 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <asm/system.h>
  41. #include <asm/io.h>
  42. #include <asm/byteorder.h>
  43. #include <asm/uaccess.h>
  44. #ifdef CONFIG_SPARC64
  45. #include <asm/idprom.h>
  46. #include <asm/oplib.h>
  47. #include <asm/pbm.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #ifdef NETIF_F_TSO
  55. #define TG3_TSO_SUPPORT 1
  56. #else
  57. #define TG3_TSO_SUPPORT 0
  58. #endif
  59. #include "tg3.h"
  60. #define DRV_MODULE_NAME "tg3"
  61. #define PFX DRV_MODULE_NAME ": "
  62. #define DRV_MODULE_VERSION "3.66"
  63. #define DRV_MODULE_RELDATE "September 23, 2006"
  64. #define TG3_DEF_MAC_MODE 0
  65. #define TG3_DEF_RX_MODE 0
  66. #define TG3_DEF_TX_MODE 0
  67. #define TG3_DEF_MSG_ENABLE \
  68. (NETIF_MSG_DRV | \
  69. NETIF_MSG_PROBE | \
  70. NETIF_MSG_LINK | \
  71. NETIF_MSG_TIMER | \
  72. NETIF_MSG_IFDOWN | \
  73. NETIF_MSG_IFUP | \
  74. NETIF_MSG_RX_ERR | \
  75. NETIF_MSG_TX_ERR)
  76. /* length of time before we decide the hardware is borked,
  77. * and dev->tx_timeout() should be called to fix the problem
  78. */
  79. #define TG3_TX_TIMEOUT (5 * HZ)
  80. /* hardware minimum and maximum for a single frame's data payload */
  81. #define TG3_MIN_MTU 60
  82. #define TG3_MAX_MTU(tp) \
  83. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  84. /* These numbers seem to be hard coded in the NIC firmware somehow.
  85. * You can't change the ring sizes, but you can change where you place
  86. * them in the NIC onboard memory.
  87. */
  88. #define TG3_RX_RING_SIZE 512
  89. #define TG3_DEF_RX_RING_PENDING 200
  90. #define TG3_RX_JUMBO_RING_SIZE 256
  91. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  92. /* Do not place this n-ring entries value into the tp struct itself,
  93. * we really want to expose these constants to GCC so that modulo et
  94. * al. operations are done with shifts and masks instead of with
  95. * hw multiply/modulo instructions. Another solution would be to
  96. * replace things like '% foo' with '& (foo - 1)'.
  97. */
  98. #define TG3_RX_RCB_RING_SIZE(tp) \
  99. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  100. #define TG3_TX_RING_SIZE 512
  101. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  102. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RING_SIZE)
  104. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  105. TG3_RX_JUMBO_RING_SIZE)
  106. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  107. TG3_RX_RCB_RING_SIZE(tp))
  108. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  109. TG3_TX_RING_SIZE)
  110. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  111. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  112. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  113. /* minimum number of free TX descriptors required to wake up TX process */
  114. #define TG3_TX_WAKEUP_THRESH (TG3_TX_RING_SIZE / 4)
  115. /* number of ETHTOOL_GSTATS u64's */
  116. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  117. #define TG3_NUM_TEST 6
  118. static char version[] __devinitdata =
  119. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  120. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  121. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  122. MODULE_LICENSE("GPL");
  123. MODULE_VERSION(DRV_MODULE_VERSION);
  124. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  125. module_param(tg3_debug, int, 0);
  126. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  127. static struct pci_device_id tg3_pci_tbl[] = {
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  184. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  185. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  186. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  187. {}
  188. };
  189. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  190. static const struct {
  191. const char string[ETH_GSTRING_LEN];
  192. } ethtool_stats_keys[TG3_NUM_STATS] = {
  193. { "rx_octets" },
  194. { "rx_fragments" },
  195. { "rx_ucast_packets" },
  196. { "rx_mcast_packets" },
  197. { "rx_bcast_packets" },
  198. { "rx_fcs_errors" },
  199. { "rx_align_errors" },
  200. { "rx_xon_pause_rcvd" },
  201. { "rx_xoff_pause_rcvd" },
  202. { "rx_mac_ctrl_rcvd" },
  203. { "rx_xoff_entered" },
  204. { "rx_frame_too_long_errors" },
  205. { "rx_jabbers" },
  206. { "rx_undersize_packets" },
  207. { "rx_in_length_errors" },
  208. { "rx_out_length_errors" },
  209. { "rx_64_or_less_octet_packets" },
  210. { "rx_65_to_127_octet_packets" },
  211. { "rx_128_to_255_octet_packets" },
  212. { "rx_256_to_511_octet_packets" },
  213. { "rx_512_to_1023_octet_packets" },
  214. { "rx_1024_to_1522_octet_packets" },
  215. { "rx_1523_to_2047_octet_packets" },
  216. { "rx_2048_to_4095_octet_packets" },
  217. { "rx_4096_to_8191_octet_packets" },
  218. { "rx_8192_to_9022_octet_packets" },
  219. { "tx_octets" },
  220. { "tx_collisions" },
  221. { "tx_xon_sent" },
  222. { "tx_xoff_sent" },
  223. { "tx_flow_control" },
  224. { "tx_mac_errors" },
  225. { "tx_single_collisions" },
  226. { "tx_mult_collisions" },
  227. { "tx_deferred" },
  228. { "tx_excessive_collisions" },
  229. { "tx_late_collisions" },
  230. { "tx_collide_2times" },
  231. { "tx_collide_3times" },
  232. { "tx_collide_4times" },
  233. { "tx_collide_5times" },
  234. { "tx_collide_6times" },
  235. { "tx_collide_7times" },
  236. { "tx_collide_8times" },
  237. { "tx_collide_9times" },
  238. { "tx_collide_10times" },
  239. { "tx_collide_11times" },
  240. { "tx_collide_12times" },
  241. { "tx_collide_13times" },
  242. { "tx_collide_14times" },
  243. { "tx_collide_15times" },
  244. { "tx_ucast_packets" },
  245. { "tx_mcast_packets" },
  246. { "tx_bcast_packets" },
  247. { "tx_carrier_sense_errors" },
  248. { "tx_discards" },
  249. { "tx_errors" },
  250. { "dma_writeq_full" },
  251. { "dma_write_prioq_full" },
  252. { "rxbds_empty" },
  253. { "rx_discards" },
  254. { "rx_errors" },
  255. { "rx_threshold_hit" },
  256. { "dma_readq_full" },
  257. { "dma_read_prioq_full" },
  258. { "tx_comp_queue_full" },
  259. { "ring_set_send_prod_index" },
  260. { "ring_status_update" },
  261. { "nic_irqs" },
  262. { "nic_avoided_irqs" },
  263. { "nic_tx_threshold_hit" }
  264. };
  265. static const struct {
  266. const char string[ETH_GSTRING_LEN];
  267. } ethtool_test_keys[TG3_NUM_TEST] = {
  268. { "nvram test (online) " },
  269. { "link test (online) " },
  270. { "register test (offline)" },
  271. { "memory test (offline)" },
  272. { "loopback test (offline)" },
  273. { "interrupt test (offline)" },
  274. };
  275. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  276. {
  277. writel(val, tp->regs + off);
  278. }
  279. static u32 tg3_read32(struct tg3 *tp, u32 off)
  280. {
  281. return (readl(tp->regs + off));
  282. }
  283. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  284. {
  285. unsigned long flags;
  286. spin_lock_irqsave(&tp->indirect_lock, flags);
  287. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  288. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  289. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  290. }
  291. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  292. {
  293. writel(val, tp->regs + off);
  294. readl(tp->regs + off);
  295. }
  296. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  297. {
  298. unsigned long flags;
  299. u32 val;
  300. spin_lock_irqsave(&tp->indirect_lock, flags);
  301. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  302. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  303. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  304. return val;
  305. }
  306. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  307. {
  308. unsigned long flags;
  309. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  310. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  311. TG3_64BIT_REG_LOW, val);
  312. return;
  313. }
  314. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  315. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  316. TG3_64BIT_REG_LOW, val);
  317. return;
  318. }
  319. spin_lock_irqsave(&tp->indirect_lock, flags);
  320. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  321. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  322. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  323. /* In indirect mode when disabling interrupts, we also need
  324. * to clear the interrupt bit in the GRC local ctrl register.
  325. */
  326. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  327. (val == 0x1)) {
  328. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  329. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  330. }
  331. }
  332. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  333. {
  334. unsigned long flags;
  335. u32 val;
  336. spin_lock_irqsave(&tp->indirect_lock, flags);
  337. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  338. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  339. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  340. return val;
  341. }
  342. /* usec_wait specifies the wait time in usec when writing to certain registers
  343. * where it is unsafe to read back the register without some delay.
  344. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  345. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  346. */
  347. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  348. {
  349. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  350. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  351. /* Non-posted methods */
  352. tp->write32(tp, off, val);
  353. else {
  354. /* Posted method */
  355. tg3_write32(tp, off, val);
  356. if (usec_wait)
  357. udelay(usec_wait);
  358. tp->read32(tp, off);
  359. }
  360. /* Wait again after the read for the posted method to guarantee that
  361. * the wait time is met.
  362. */
  363. if (usec_wait)
  364. udelay(usec_wait);
  365. }
  366. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  367. {
  368. tp->write32_mbox(tp, off, val);
  369. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  370. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  371. tp->read32_mbox(tp, off);
  372. }
  373. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  374. {
  375. void __iomem *mbox = tp->regs + off;
  376. writel(val, mbox);
  377. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  378. writel(val, mbox);
  379. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  380. readl(mbox);
  381. }
  382. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  383. {
  384. return (readl(tp->regs + off + GRCMBOX_BASE));
  385. }
  386. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  387. {
  388. writel(val, tp->regs + off + GRCMBOX_BASE);
  389. }
  390. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  391. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  392. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  393. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  394. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  395. #define tw32(reg,val) tp->write32(tp, reg, val)
  396. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  397. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  398. #define tr32(reg) tp->read32(tp, reg)
  399. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  400. {
  401. unsigned long flags;
  402. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  403. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  404. return;
  405. spin_lock_irqsave(&tp->indirect_lock, flags);
  406. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  407. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  408. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  409. /* Always leave this as zero. */
  410. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  411. } else {
  412. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  413. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  414. /* Always leave this as zero. */
  415. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  416. }
  417. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  418. }
  419. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  420. {
  421. unsigned long flags;
  422. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  423. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  424. *val = 0;
  425. return;
  426. }
  427. spin_lock_irqsave(&tp->indirect_lock, flags);
  428. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  429. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  430. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  431. /* Always leave this as zero. */
  432. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  433. } else {
  434. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  435. *val = tr32(TG3PCI_MEM_WIN_DATA);
  436. /* Always leave this as zero. */
  437. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  438. }
  439. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  440. }
  441. static void tg3_disable_ints(struct tg3 *tp)
  442. {
  443. tw32(TG3PCI_MISC_HOST_CTRL,
  444. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  445. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  446. }
  447. static inline void tg3_cond_int(struct tg3 *tp)
  448. {
  449. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  450. (tp->hw_status->status & SD_STATUS_UPDATED))
  451. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  452. else
  453. tw32(HOSTCC_MODE, tp->coalesce_mode |
  454. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  455. }
  456. static void tg3_enable_ints(struct tg3 *tp)
  457. {
  458. tp->irq_sync = 0;
  459. wmb();
  460. tw32(TG3PCI_MISC_HOST_CTRL,
  461. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  462. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  463. (tp->last_tag << 24));
  464. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  465. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  466. (tp->last_tag << 24));
  467. tg3_cond_int(tp);
  468. }
  469. static inline unsigned int tg3_has_work(struct tg3 *tp)
  470. {
  471. struct tg3_hw_status *sblk = tp->hw_status;
  472. unsigned int work_exists = 0;
  473. /* check for phy events */
  474. if (!(tp->tg3_flags &
  475. (TG3_FLAG_USE_LINKCHG_REG |
  476. TG3_FLAG_POLL_SERDES))) {
  477. if (sblk->status & SD_STATUS_LINK_CHG)
  478. work_exists = 1;
  479. }
  480. /* check for RX/TX work to do */
  481. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  482. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  483. work_exists = 1;
  484. return work_exists;
  485. }
  486. /* tg3_restart_ints
  487. * similar to tg3_enable_ints, but it accurately determines whether there
  488. * is new work pending and can return without flushing the PIO write
  489. * which reenables interrupts
  490. */
  491. static void tg3_restart_ints(struct tg3 *tp)
  492. {
  493. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  494. tp->last_tag << 24);
  495. mmiowb();
  496. /* When doing tagged status, this work check is unnecessary.
  497. * The last_tag we write above tells the chip which piece of
  498. * work we've completed.
  499. */
  500. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  501. tg3_has_work(tp))
  502. tw32(HOSTCC_MODE, tp->coalesce_mode |
  503. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  504. }
  505. static inline void tg3_netif_stop(struct tg3 *tp)
  506. {
  507. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  508. netif_poll_disable(tp->dev);
  509. netif_tx_disable(tp->dev);
  510. }
  511. static inline void tg3_netif_start(struct tg3 *tp)
  512. {
  513. netif_wake_queue(tp->dev);
  514. /* NOTE: unconditional netif_wake_queue is only appropriate
  515. * so long as all callers are assured to have free tx slots
  516. * (such as after tg3_init_hw)
  517. */
  518. netif_poll_enable(tp->dev);
  519. tp->hw_status->status |= SD_STATUS_UPDATED;
  520. tg3_enable_ints(tp);
  521. }
  522. static void tg3_switch_clocks(struct tg3 *tp)
  523. {
  524. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  525. u32 orig_clock_ctrl;
  526. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  527. return;
  528. orig_clock_ctrl = clock_ctrl;
  529. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  530. CLOCK_CTRL_CLKRUN_OENABLE |
  531. 0x1f);
  532. tp->pci_clock_ctrl = clock_ctrl;
  533. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  534. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  535. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  536. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  537. }
  538. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  539. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  540. clock_ctrl |
  541. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  542. 40);
  543. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  544. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  545. 40);
  546. }
  547. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  548. }
  549. #define PHY_BUSY_LOOPS 5000
  550. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  551. {
  552. u32 frame_val;
  553. unsigned int loops;
  554. int ret;
  555. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  556. tw32_f(MAC_MI_MODE,
  557. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  558. udelay(80);
  559. }
  560. *val = 0x0;
  561. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  562. MI_COM_PHY_ADDR_MASK);
  563. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  564. MI_COM_REG_ADDR_MASK);
  565. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  566. tw32_f(MAC_MI_COM, frame_val);
  567. loops = PHY_BUSY_LOOPS;
  568. while (loops != 0) {
  569. udelay(10);
  570. frame_val = tr32(MAC_MI_COM);
  571. if ((frame_val & MI_COM_BUSY) == 0) {
  572. udelay(5);
  573. frame_val = tr32(MAC_MI_COM);
  574. break;
  575. }
  576. loops -= 1;
  577. }
  578. ret = -EBUSY;
  579. if (loops != 0) {
  580. *val = frame_val & MI_COM_DATA_MASK;
  581. ret = 0;
  582. }
  583. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  584. tw32_f(MAC_MI_MODE, tp->mi_mode);
  585. udelay(80);
  586. }
  587. return ret;
  588. }
  589. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  590. {
  591. u32 frame_val;
  592. unsigned int loops;
  593. int ret;
  594. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  595. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  596. return 0;
  597. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  598. tw32_f(MAC_MI_MODE,
  599. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  600. udelay(80);
  601. }
  602. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  603. MI_COM_PHY_ADDR_MASK);
  604. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  605. MI_COM_REG_ADDR_MASK);
  606. frame_val |= (val & MI_COM_DATA_MASK);
  607. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  608. tw32_f(MAC_MI_COM, frame_val);
  609. loops = PHY_BUSY_LOOPS;
  610. while (loops != 0) {
  611. udelay(10);
  612. frame_val = tr32(MAC_MI_COM);
  613. if ((frame_val & MI_COM_BUSY) == 0) {
  614. udelay(5);
  615. frame_val = tr32(MAC_MI_COM);
  616. break;
  617. }
  618. loops -= 1;
  619. }
  620. ret = -EBUSY;
  621. if (loops != 0)
  622. ret = 0;
  623. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  624. tw32_f(MAC_MI_MODE, tp->mi_mode);
  625. udelay(80);
  626. }
  627. return ret;
  628. }
  629. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  630. {
  631. u32 val;
  632. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  633. return;
  634. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  635. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  636. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  637. (val | (1 << 15) | (1 << 4)));
  638. }
  639. static int tg3_bmcr_reset(struct tg3 *tp)
  640. {
  641. u32 phy_control;
  642. int limit, err;
  643. /* OK, reset it, and poll the BMCR_RESET bit until it
  644. * clears or we time out.
  645. */
  646. phy_control = BMCR_RESET;
  647. err = tg3_writephy(tp, MII_BMCR, phy_control);
  648. if (err != 0)
  649. return -EBUSY;
  650. limit = 5000;
  651. while (limit--) {
  652. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  653. if (err != 0)
  654. return -EBUSY;
  655. if ((phy_control & BMCR_RESET) == 0) {
  656. udelay(40);
  657. break;
  658. }
  659. udelay(10);
  660. }
  661. if (limit <= 0)
  662. return -EBUSY;
  663. return 0;
  664. }
  665. static int tg3_wait_macro_done(struct tg3 *tp)
  666. {
  667. int limit = 100;
  668. while (limit--) {
  669. u32 tmp32;
  670. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  671. if ((tmp32 & 0x1000) == 0)
  672. break;
  673. }
  674. }
  675. if (limit <= 0)
  676. return -EBUSY;
  677. return 0;
  678. }
  679. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  680. {
  681. static const u32 test_pat[4][6] = {
  682. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  683. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  684. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  685. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  686. };
  687. int chan;
  688. for (chan = 0; chan < 4; chan++) {
  689. int i;
  690. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  691. (chan * 0x2000) | 0x0200);
  692. tg3_writephy(tp, 0x16, 0x0002);
  693. for (i = 0; i < 6; i++)
  694. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  695. test_pat[chan][i]);
  696. tg3_writephy(tp, 0x16, 0x0202);
  697. if (tg3_wait_macro_done(tp)) {
  698. *resetp = 1;
  699. return -EBUSY;
  700. }
  701. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  702. (chan * 0x2000) | 0x0200);
  703. tg3_writephy(tp, 0x16, 0x0082);
  704. if (tg3_wait_macro_done(tp)) {
  705. *resetp = 1;
  706. return -EBUSY;
  707. }
  708. tg3_writephy(tp, 0x16, 0x0802);
  709. if (tg3_wait_macro_done(tp)) {
  710. *resetp = 1;
  711. return -EBUSY;
  712. }
  713. for (i = 0; i < 6; i += 2) {
  714. u32 low, high;
  715. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  716. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  717. tg3_wait_macro_done(tp)) {
  718. *resetp = 1;
  719. return -EBUSY;
  720. }
  721. low &= 0x7fff;
  722. high &= 0x000f;
  723. if (low != test_pat[chan][i] ||
  724. high != test_pat[chan][i+1]) {
  725. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  726. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  727. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  728. return -EBUSY;
  729. }
  730. }
  731. }
  732. return 0;
  733. }
  734. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  735. {
  736. int chan;
  737. for (chan = 0; chan < 4; chan++) {
  738. int i;
  739. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  740. (chan * 0x2000) | 0x0200);
  741. tg3_writephy(tp, 0x16, 0x0002);
  742. for (i = 0; i < 6; i++)
  743. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  744. tg3_writephy(tp, 0x16, 0x0202);
  745. if (tg3_wait_macro_done(tp))
  746. return -EBUSY;
  747. }
  748. return 0;
  749. }
  750. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  751. {
  752. u32 reg32, phy9_orig;
  753. int retries, do_phy_reset, err;
  754. retries = 10;
  755. do_phy_reset = 1;
  756. do {
  757. if (do_phy_reset) {
  758. err = tg3_bmcr_reset(tp);
  759. if (err)
  760. return err;
  761. do_phy_reset = 0;
  762. }
  763. /* Disable transmitter and interrupt. */
  764. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  765. continue;
  766. reg32 |= 0x3000;
  767. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  768. /* Set full-duplex, 1000 mbps. */
  769. tg3_writephy(tp, MII_BMCR,
  770. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  771. /* Set to master mode. */
  772. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  773. continue;
  774. tg3_writephy(tp, MII_TG3_CTRL,
  775. (MII_TG3_CTRL_AS_MASTER |
  776. MII_TG3_CTRL_ENABLE_AS_MASTER));
  777. /* Enable SM_DSP_CLOCK and 6dB. */
  778. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  779. /* Block the PHY control access. */
  780. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  781. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  782. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  783. if (!err)
  784. break;
  785. } while (--retries);
  786. err = tg3_phy_reset_chanpat(tp);
  787. if (err)
  788. return err;
  789. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  790. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  791. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  792. tg3_writephy(tp, 0x16, 0x0000);
  793. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  794. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  795. /* Set Extended packet length bit for jumbo frames */
  796. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  797. }
  798. else {
  799. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  800. }
  801. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  802. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  803. reg32 &= ~0x3000;
  804. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  805. } else if (!err)
  806. err = -EBUSY;
  807. return err;
  808. }
  809. static void tg3_link_report(struct tg3 *);
  810. /* This will reset the tigon3 PHY if there is no valid
  811. * link unless the FORCE argument is non-zero.
  812. */
  813. static int tg3_phy_reset(struct tg3 *tp)
  814. {
  815. u32 phy_status;
  816. int err;
  817. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  818. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  819. if (err != 0)
  820. return -EBUSY;
  821. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  822. netif_carrier_off(tp->dev);
  823. tg3_link_report(tp);
  824. }
  825. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  826. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  827. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  828. err = tg3_phy_reset_5703_4_5(tp);
  829. if (err)
  830. return err;
  831. goto out;
  832. }
  833. err = tg3_bmcr_reset(tp);
  834. if (err)
  835. return err;
  836. out:
  837. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  838. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  839. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  840. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  841. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  842. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  843. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  844. }
  845. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  846. tg3_writephy(tp, 0x1c, 0x8d68);
  847. tg3_writephy(tp, 0x1c, 0x8d68);
  848. }
  849. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  850. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  851. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  852. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  853. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  854. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  855. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  856. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  857. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  858. }
  859. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  860. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  861. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  862. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  863. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  864. }
  865. /* Set Extended packet length bit (bit 14) on all chips that */
  866. /* support jumbo frames */
  867. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  868. /* Cannot do read-modify-write on 5401 */
  869. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  870. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  871. u32 phy_reg;
  872. /* Set bit 14 with read-modify-write to preserve other bits */
  873. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  874. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  875. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  876. }
  877. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  878. * jumbo frames transmission.
  879. */
  880. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  881. u32 phy_reg;
  882. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  883. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  884. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  885. }
  886. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  887. u32 phy_reg;
  888. /* adjust output voltage */
  889. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  890. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
  891. u32 phy_reg2;
  892. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  893. phy_reg | MII_TG3_EPHY_SHADOW_EN);
  894. /* Enable auto-MDIX */
  895. if (!tg3_readphy(tp, 0x10, &phy_reg2))
  896. tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
  897. tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
  898. }
  899. }
  900. tg3_phy_set_wirespeed(tp);
  901. return 0;
  902. }
  903. static void tg3_frob_aux_power(struct tg3 *tp)
  904. {
  905. struct tg3 *tp_peer = tp;
  906. if ((tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) != 0)
  907. return;
  908. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  909. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  910. struct net_device *dev_peer;
  911. dev_peer = pci_get_drvdata(tp->pdev_peer);
  912. /* remove_one() may have been run on the peer. */
  913. if (!dev_peer)
  914. tp_peer = tp;
  915. else
  916. tp_peer = netdev_priv(dev_peer);
  917. }
  918. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  919. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  920. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  921. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  922. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  923. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  924. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  925. (GRC_LCLCTRL_GPIO_OE0 |
  926. GRC_LCLCTRL_GPIO_OE1 |
  927. GRC_LCLCTRL_GPIO_OE2 |
  928. GRC_LCLCTRL_GPIO_OUTPUT0 |
  929. GRC_LCLCTRL_GPIO_OUTPUT1),
  930. 100);
  931. } else {
  932. u32 no_gpio2;
  933. u32 grc_local_ctrl = 0;
  934. if (tp_peer != tp &&
  935. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  936. return;
  937. /* Workaround to prevent overdrawing Amps. */
  938. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  939. ASIC_REV_5714) {
  940. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  941. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  942. grc_local_ctrl, 100);
  943. }
  944. /* On 5753 and variants, GPIO2 cannot be used. */
  945. no_gpio2 = tp->nic_sram_data_cfg &
  946. NIC_SRAM_DATA_CFG_NO_GPIO2;
  947. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  948. GRC_LCLCTRL_GPIO_OE1 |
  949. GRC_LCLCTRL_GPIO_OE2 |
  950. GRC_LCLCTRL_GPIO_OUTPUT1 |
  951. GRC_LCLCTRL_GPIO_OUTPUT2;
  952. if (no_gpio2) {
  953. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  954. GRC_LCLCTRL_GPIO_OUTPUT2);
  955. }
  956. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  957. grc_local_ctrl, 100);
  958. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  959. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  960. grc_local_ctrl, 100);
  961. if (!no_gpio2) {
  962. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  963. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  964. grc_local_ctrl, 100);
  965. }
  966. }
  967. } else {
  968. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  969. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  970. if (tp_peer != tp &&
  971. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  972. return;
  973. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  974. (GRC_LCLCTRL_GPIO_OE1 |
  975. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  976. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  977. GRC_LCLCTRL_GPIO_OE1, 100);
  978. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  979. (GRC_LCLCTRL_GPIO_OE1 |
  980. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  981. }
  982. }
  983. }
  984. static int tg3_setup_phy(struct tg3 *, int);
  985. #define RESET_KIND_SHUTDOWN 0
  986. #define RESET_KIND_INIT 1
  987. #define RESET_KIND_SUSPEND 2
  988. static void tg3_write_sig_post_reset(struct tg3 *, int);
  989. static int tg3_halt_cpu(struct tg3 *, u32);
  990. static int tg3_nvram_lock(struct tg3 *);
  991. static void tg3_nvram_unlock(struct tg3 *);
  992. static void tg3_power_down_phy(struct tg3 *tp)
  993. {
  994. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  995. return;
  996. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  997. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  998. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  999. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1000. }
  1001. /* The PHY should not be powered down on some chips because
  1002. * of bugs.
  1003. */
  1004. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1005. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1006. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1007. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1008. return;
  1009. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1010. }
  1011. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1012. {
  1013. u32 misc_host_ctrl;
  1014. u16 power_control, power_caps;
  1015. int pm = tp->pm_cap;
  1016. /* Make sure register accesses (indirect or otherwise)
  1017. * will function correctly.
  1018. */
  1019. pci_write_config_dword(tp->pdev,
  1020. TG3PCI_MISC_HOST_CTRL,
  1021. tp->misc_host_ctrl);
  1022. pci_read_config_word(tp->pdev,
  1023. pm + PCI_PM_CTRL,
  1024. &power_control);
  1025. power_control |= PCI_PM_CTRL_PME_STATUS;
  1026. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1027. switch (state) {
  1028. case PCI_D0:
  1029. power_control |= 0;
  1030. pci_write_config_word(tp->pdev,
  1031. pm + PCI_PM_CTRL,
  1032. power_control);
  1033. udelay(100); /* Delay after power state change */
  1034. /* Switch out of Vaux if it is not a LOM */
  1035. if (!(tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  1036. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1037. return 0;
  1038. case PCI_D1:
  1039. power_control |= 1;
  1040. break;
  1041. case PCI_D2:
  1042. power_control |= 2;
  1043. break;
  1044. case PCI_D3hot:
  1045. power_control |= 3;
  1046. break;
  1047. default:
  1048. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1049. "requested.\n",
  1050. tp->dev->name, state);
  1051. return -EINVAL;
  1052. };
  1053. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1054. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1055. tw32(TG3PCI_MISC_HOST_CTRL,
  1056. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1057. if (tp->link_config.phy_is_low_power == 0) {
  1058. tp->link_config.phy_is_low_power = 1;
  1059. tp->link_config.orig_speed = tp->link_config.speed;
  1060. tp->link_config.orig_duplex = tp->link_config.duplex;
  1061. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1062. }
  1063. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1064. tp->link_config.speed = SPEED_10;
  1065. tp->link_config.duplex = DUPLEX_HALF;
  1066. tp->link_config.autoneg = AUTONEG_ENABLE;
  1067. tg3_setup_phy(tp, 0);
  1068. }
  1069. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1070. u32 val;
  1071. val = tr32(GRC_VCPU_EXT_CTRL);
  1072. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1073. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1074. int i;
  1075. u32 val;
  1076. for (i = 0; i < 200; i++) {
  1077. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1078. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1079. break;
  1080. msleep(1);
  1081. }
  1082. }
  1083. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1084. WOL_DRV_STATE_SHUTDOWN |
  1085. WOL_DRV_WOL | WOL_SET_MAGIC_PKT);
  1086. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1087. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1088. u32 mac_mode;
  1089. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1090. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1091. udelay(40);
  1092. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1093. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1094. else
  1095. mac_mode = MAC_MODE_PORT_MODE_MII;
  1096. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
  1097. !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
  1098. mac_mode |= MAC_MODE_LINK_POLARITY;
  1099. } else {
  1100. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1101. }
  1102. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1103. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1104. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1105. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1106. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1107. tw32_f(MAC_MODE, mac_mode);
  1108. udelay(100);
  1109. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1110. udelay(10);
  1111. }
  1112. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1113. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1114. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1115. u32 base_val;
  1116. base_val = tp->pci_clock_ctrl;
  1117. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1118. CLOCK_CTRL_TXCLK_DISABLE);
  1119. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1120. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1121. } else if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  1122. /* do nothing */
  1123. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1124. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1125. u32 newbits1, newbits2;
  1126. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1127. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1128. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1129. CLOCK_CTRL_TXCLK_DISABLE |
  1130. CLOCK_CTRL_ALTCLK);
  1131. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1132. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1133. newbits1 = CLOCK_CTRL_625_CORE;
  1134. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1135. } else {
  1136. newbits1 = CLOCK_CTRL_ALTCLK;
  1137. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1138. }
  1139. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1140. 40);
  1141. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1142. 40);
  1143. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1144. u32 newbits3;
  1145. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1146. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1147. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1148. CLOCK_CTRL_TXCLK_DISABLE |
  1149. CLOCK_CTRL_44MHZ_CORE);
  1150. } else {
  1151. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1152. }
  1153. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1154. tp->pci_clock_ctrl | newbits3, 40);
  1155. }
  1156. }
  1157. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1158. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  1159. tg3_power_down_phy(tp);
  1160. tg3_frob_aux_power(tp);
  1161. /* Workaround for unstable PLL clock */
  1162. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1163. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1164. u32 val = tr32(0x7d00);
  1165. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1166. tw32(0x7d00, val);
  1167. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1168. int err;
  1169. err = tg3_nvram_lock(tp);
  1170. tg3_halt_cpu(tp, RX_CPU_BASE);
  1171. if (!err)
  1172. tg3_nvram_unlock(tp);
  1173. }
  1174. }
  1175. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1176. /* Finally, set the new power state. */
  1177. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1178. udelay(100); /* Delay after power state change */
  1179. return 0;
  1180. }
  1181. static void tg3_link_report(struct tg3 *tp)
  1182. {
  1183. if (!netif_carrier_ok(tp->dev)) {
  1184. printk(KERN_INFO PFX "%s: Link is down.\n", tp->dev->name);
  1185. } else {
  1186. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1187. tp->dev->name,
  1188. (tp->link_config.active_speed == SPEED_1000 ?
  1189. 1000 :
  1190. (tp->link_config.active_speed == SPEED_100 ?
  1191. 100 : 10)),
  1192. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1193. "full" : "half"));
  1194. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1195. "%s for RX.\n",
  1196. tp->dev->name,
  1197. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1198. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1199. }
  1200. }
  1201. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1202. {
  1203. u32 new_tg3_flags = 0;
  1204. u32 old_rx_mode = tp->rx_mode;
  1205. u32 old_tx_mode = tp->tx_mode;
  1206. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1207. /* Convert 1000BaseX flow control bits to 1000BaseT
  1208. * bits before resolving flow control.
  1209. */
  1210. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1211. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1212. ADVERTISE_PAUSE_ASYM);
  1213. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1214. if (local_adv & ADVERTISE_1000XPAUSE)
  1215. local_adv |= ADVERTISE_PAUSE_CAP;
  1216. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1217. local_adv |= ADVERTISE_PAUSE_ASYM;
  1218. if (remote_adv & LPA_1000XPAUSE)
  1219. remote_adv |= LPA_PAUSE_CAP;
  1220. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1221. remote_adv |= LPA_PAUSE_ASYM;
  1222. }
  1223. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1224. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1225. if (remote_adv & LPA_PAUSE_CAP)
  1226. new_tg3_flags |=
  1227. (TG3_FLAG_RX_PAUSE |
  1228. TG3_FLAG_TX_PAUSE);
  1229. else if (remote_adv & LPA_PAUSE_ASYM)
  1230. new_tg3_flags |=
  1231. (TG3_FLAG_RX_PAUSE);
  1232. } else {
  1233. if (remote_adv & LPA_PAUSE_CAP)
  1234. new_tg3_flags |=
  1235. (TG3_FLAG_RX_PAUSE |
  1236. TG3_FLAG_TX_PAUSE);
  1237. }
  1238. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1239. if ((remote_adv & LPA_PAUSE_CAP) &&
  1240. (remote_adv & LPA_PAUSE_ASYM))
  1241. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1242. }
  1243. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1244. tp->tg3_flags |= new_tg3_flags;
  1245. } else {
  1246. new_tg3_flags = tp->tg3_flags;
  1247. }
  1248. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1249. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1250. else
  1251. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1252. if (old_rx_mode != tp->rx_mode) {
  1253. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1254. }
  1255. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1256. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1257. else
  1258. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1259. if (old_tx_mode != tp->tx_mode) {
  1260. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1261. }
  1262. }
  1263. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1264. {
  1265. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1266. case MII_TG3_AUX_STAT_10HALF:
  1267. *speed = SPEED_10;
  1268. *duplex = DUPLEX_HALF;
  1269. break;
  1270. case MII_TG3_AUX_STAT_10FULL:
  1271. *speed = SPEED_10;
  1272. *duplex = DUPLEX_FULL;
  1273. break;
  1274. case MII_TG3_AUX_STAT_100HALF:
  1275. *speed = SPEED_100;
  1276. *duplex = DUPLEX_HALF;
  1277. break;
  1278. case MII_TG3_AUX_STAT_100FULL:
  1279. *speed = SPEED_100;
  1280. *duplex = DUPLEX_FULL;
  1281. break;
  1282. case MII_TG3_AUX_STAT_1000HALF:
  1283. *speed = SPEED_1000;
  1284. *duplex = DUPLEX_HALF;
  1285. break;
  1286. case MII_TG3_AUX_STAT_1000FULL:
  1287. *speed = SPEED_1000;
  1288. *duplex = DUPLEX_FULL;
  1289. break;
  1290. default:
  1291. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1292. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1293. SPEED_10;
  1294. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1295. DUPLEX_HALF;
  1296. break;
  1297. }
  1298. *speed = SPEED_INVALID;
  1299. *duplex = DUPLEX_INVALID;
  1300. break;
  1301. };
  1302. }
  1303. static void tg3_phy_copper_begin(struct tg3 *tp)
  1304. {
  1305. u32 new_adv;
  1306. int i;
  1307. if (tp->link_config.phy_is_low_power) {
  1308. /* Entering low power mode. Disable gigabit and
  1309. * 100baseT advertisements.
  1310. */
  1311. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1312. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1313. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1314. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1315. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1316. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1317. } else if (tp->link_config.speed == SPEED_INVALID) {
  1318. tp->link_config.advertising =
  1319. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  1320. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  1321. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  1322. ADVERTISED_Autoneg | ADVERTISED_MII);
  1323. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1324. tp->link_config.advertising &=
  1325. ~(ADVERTISED_1000baseT_Half |
  1326. ADVERTISED_1000baseT_Full);
  1327. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1328. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1329. new_adv |= ADVERTISE_10HALF;
  1330. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1331. new_adv |= ADVERTISE_10FULL;
  1332. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1333. new_adv |= ADVERTISE_100HALF;
  1334. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1335. new_adv |= ADVERTISE_100FULL;
  1336. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1337. if (tp->link_config.advertising &
  1338. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1339. new_adv = 0;
  1340. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1341. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1342. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1343. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1344. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1345. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1346. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1347. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1348. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1349. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1350. } else {
  1351. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1352. }
  1353. } else {
  1354. /* Asking for a specific link mode. */
  1355. if (tp->link_config.speed == SPEED_1000) {
  1356. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1357. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1358. if (tp->link_config.duplex == DUPLEX_FULL)
  1359. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1360. else
  1361. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1362. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1363. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1364. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1365. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1366. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1367. } else {
  1368. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1369. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1370. if (tp->link_config.speed == SPEED_100) {
  1371. if (tp->link_config.duplex == DUPLEX_FULL)
  1372. new_adv |= ADVERTISE_100FULL;
  1373. else
  1374. new_adv |= ADVERTISE_100HALF;
  1375. } else {
  1376. if (tp->link_config.duplex == DUPLEX_FULL)
  1377. new_adv |= ADVERTISE_10FULL;
  1378. else
  1379. new_adv |= ADVERTISE_10HALF;
  1380. }
  1381. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1382. }
  1383. }
  1384. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1385. tp->link_config.speed != SPEED_INVALID) {
  1386. u32 bmcr, orig_bmcr;
  1387. tp->link_config.active_speed = tp->link_config.speed;
  1388. tp->link_config.active_duplex = tp->link_config.duplex;
  1389. bmcr = 0;
  1390. switch (tp->link_config.speed) {
  1391. default:
  1392. case SPEED_10:
  1393. break;
  1394. case SPEED_100:
  1395. bmcr |= BMCR_SPEED100;
  1396. break;
  1397. case SPEED_1000:
  1398. bmcr |= TG3_BMCR_SPEED1000;
  1399. break;
  1400. };
  1401. if (tp->link_config.duplex == DUPLEX_FULL)
  1402. bmcr |= BMCR_FULLDPLX;
  1403. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1404. (bmcr != orig_bmcr)) {
  1405. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1406. for (i = 0; i < 1500; i++) {
  1407. u32 tmp;
  1408. udelay(10);
  1409. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1410. tg3_readphy(tp, MII_BMSR, &tmp))
  1411. continue;
  1412. if (!(tmp & BMSR_LSTATUS)) {
  1413. udelay(40);
  1414. break;
  1415. }
  1416. }
  1417. tg3_writephy(tp, MII_BMCR, bmcr);
  1418. udelay(40);
  1419. }
  1420. } else {
  1421. tg3_writephy(tp, MII_BMCR,
  1422. BMCR_ANENABLE | BMCR_ANRESTART);
  1423. }
  1424. }
  1425. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1426. {
  1427. int err;
  1428. /* Turn off tap power management. */
  1429. /* Set Extended packet length bit */
  1430. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1431. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1432. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1433. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1434. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1435. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1436. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1437. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1438. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1439. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1440. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1441. udelay(40);
  1442. return err;
  1443. }
  1444. static int tg3_copper_is_advertising_all(struct tg3 *tp)
  1445. {
  1446. u32 adv_reg, all_mask;
  1447. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1448. return 0;
  1449. all_mask = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1450. ADVERTISE_100HALF | ADVERTISE_100FULL);
  1451. if ((adv_reg & all_mask) != all_mask)
  1452. return 0;
  1453. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1454. u32 tg3_ctrl;
  1455. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1456. return 0;
  1457. all_mask = (MII_TG3_CTRL_ADV_1000_HALF |
  1458. MII_TG3_CTRL_ADV_1000_FULL);
  1459. if ((tg3_ctrl & all_mask) != all_mask)
  1460. return 0;
  1461. }
  1462. return 1;
  1463. }
  1464. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1465. {
  1466. int current_link_up;
  1467. u32 bmsr, dummy;
  1468. u16 current_speed;
  1469. u8 current_duplex;
  1470. int i, err;
  1471. tw32(MAC_EVENT, 0);
  1472. tw32_f(MAC_STATUS,
  1473. (MAC_STATUS_SYNC_CHANGED |
  1474. MAC_STATUS_CFG_CHANGED |
  1475. MAC_STATUS_MI_COMPLETION |
  1476. MAC_STATUS_LNKSTATE_CHANGED));
  1477. udelay(40);
  1478. tp->mi_mode = MAC_MI_MODE_BASE;
  1479. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1480. udelay(80);
  1481. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1482. /* Some third-party PHYs need to be reset on link going
  1483. * down.
  1484. */
  1485. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1486. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1487. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1488. netif_carrier_ok(tp->dev)) {
  1489. tg3_readphy(tp, MII_BMSR, &bmsr);
  1490. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1491. !(bmsr & BMSR_LSTATUS))
  1492. force_reset = 1;
  1493. }
  1494. if (force_reset)
  1495. tg3_phy_reset(tp);
  1496. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1497. tg3_readphy(tp, MII_BMSR, &bmsr);
  1498. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1499. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1500. bmsr = 0;
  1501. if (!(bmsr & BMSR_LSTATUS)) {
  1502. err = tg3_init_5401phy_dsp(tp);
  1503. if (err)
  1504. return err;
  1505. tg3_readphy(tp, MII_BMSR, &bmsr);
  1506. for (i = 0; i < 1000; i++) {
  1507. udelay(10);
  1508. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1509. (bmsr & BMSR_LSTATUS)) {
  1510. udelay(40);
  1511. break;
  1512. }
  1513. }
  1514. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1515. !(bmsr & BMSR_LSTATUS) &&
  1516. tp->link_config.active_speed == SPEED_1000) {
  1517. err = tg3_phy_reset(tp);
  1518. if (!err)
  1519. err = tg3_init_5401phy_dsp(tp);
  1520. if (err)
  1521. return err;
  1522. }
  1523. }
  1524. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1525. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1526. /* 5701 {A0,B0} CRC bug workaround */
  1527. tg3_writephy(tp, 0x15, 0x0a75);
  1528. tg3_writephy(tp, 0x1c, 0x8c68);
  1529. tg3_writephy(tp, 0x1c, 0x8d68);
  1530. tg3_writephy(tp, 0x1c, 0x8c68);
  1531. }
  1532. /* Clear pending interrupts... */
  1533. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1534. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1535. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1536. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1537. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1538. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1539. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1540. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1541. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1542. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1543. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1544. else
  1545. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1546. }
  1547. current_link_up = 0;
  1548. current_speed = SPEED_INVALID;
  1549. current_duplex = DUPLEX_INVALID;
  1550. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1551. u32 val;
  1552. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1553. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1554. if (!(val & (1 << 10))) {
  1555. val |= (1 << 10);
  1556. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1557. goto relink;
  1558. }
  1559. }
  1560. bmsr = 0;
  1561. for (i = 0; i < 100; i++) {
  1562. tg3_readphy(tp, MII_BMSR, &bmsr);
  1563. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1564. (bmsr & BMSR_LSTATUS))
  1565. break;
  1566. udelay(40);
  1567. }
  1568. if (bmsr & BMSR_LSTATUS) {
  1569. u32 aux_stat, bmcr;
  1570. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1571. for (i = 0; i < 2000; i++) {
  1572. udelay(10);
  1573. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1574. aux_stat)
  1575. break;
  1576. }
  1577. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1578. &current_speed,
  1579. &current_duplex);
  1580. bmcr = 0;
  1581. for (i = 0; i < 200; i++) {
  1582. tg3_readphy(tp, MII_BMCR, &bmcr);
  1583. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1584. continue;
  1585. if (bmcr && bmcr != 0x7fff)
  1586. break;
  1587. udelay(10);
  1588. }
  1589. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1590. if (bmcr & BMCR_ANENABLE) {
  1591. current_link_up = 1;
  1592. /* Force autoneg restart if we are exiting
  1593. * low power mode.
  1594. */
  1595. if (!tg3_copper_is_advertising_all(tp))
  1596. current_link_up = 0;
  1597. } else {
  1598. current_link_up = 0;
  1599. }
  1600. } else {
  1601. if (!(bmcr & BMCR_ANENABLE) &&
  1602. tp->link_config.speed == current_speed &&
  1603. tp->link_config.duplex == current_duplex) {
  1604. current_link_up = 1;
  1605. } else {
  1606. current_link_up = 0;
  1607. }
  1608. }
  1609. tp->link_config.active_speed = current_speed;
  1610. tp->link_config.active_duplex = current_duplex;
  1611. }
  1612. if (current_link_up == 1 &&
  1613. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1614. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1615. u32 local_adv, remote_adv;
  1616. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1617. local_adv = 0;
  1618. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1619. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1620. remote_adv = 0;
  1621. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1622. /* If we are not advertising full pause capability,
  1623. * something is wrong. Bring the link down and reconfigure.
  1624. */
  1625. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1626. current_link_up = 0;
  1627. } else {
  1628. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1629. }
  1630. }
  1631. relink:
  1632. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1633. u32 tmp;
  1634. tg3_phy_copper_begin(tp);
  1635. tg3_readphy(tp, MII_BMSR, &tmp);
  1636. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1637. (tmp & BMSR_LSTATUS))
  1638. current_link_up = 1;
  1639. }
  1640. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1641. if (current_link_up == 1) {
  1642. if (tp->link_config.active_speed == SPEED_100 ||
  1643. tp->link_config.active_speed == SPEED_10)
  1644. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1645. else
  1646. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1647. } else
  1648. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1649. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1650. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1651. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1652. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1653. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1654. if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
  1655. (current_link_up == 1 &&
  1656. tp->link_config.active_speed == SPEED_10))
  1657. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1658. } else {
  1659. if (current_link_up == 1)
  1660. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1661. }
  1662. /* ??? Without this setting Netgear GA302T PHY does not
  1663. * ??? send/receive packets...
  1664. */
  1665. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1666. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1667. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1668. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1669. udelay(80);
  1670. }
  1671. tw32_f(MAC_MODE, tp->mac_mode);
  1672. udelay(40);
  1673. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1674. /* Polled via timer. */
  1675. tw32_f(MAC_EVENT, 0);
  1676. } else {
  1677. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1678. }
  1679. udelay(40);
  1680. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1681. current_link_up == 1 &&
  1682. tp->link_config.active_speed == SPEED_1000 &&
  1683. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1684. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1685. udelay(120);
  1686. tw32_f(MAC_STATUS,
  1687. (MAC_STATUS_SYNC_CHANGED |
  1688. MAC_STATUS_CFG_CHANGED));
  1689. udelay(40);
  1690. tg3_write_mem(tp,
  1691. NIC_SRAM_FIRMWARE_MBOX,
  1692. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1693. }
  1694. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1695. if (current_link_up)
  1696. netif_carrier_on(tp->dev);
  1697. else
  1698. netif_carrier_off(tp->dev);
  1699. tg3_link_report(tp);
  1700. }
  1701. return 0;
  1702. }
  1703. struct tg3_fiber_aneginfo {
  1704. int state;
  1705. #define ANEG_STATE_UNKNOWN 0
  1706. #define ANEG_STATE_AN_ENABLE 1
  1707. #define ANEG_STATE_RESTART_INIT 2
  1708. #define ANEG_STATE_RESTART 3
  1709. #define ANEG_STATE_DISABLE_LINK_OK 4
  1710. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1711. #define ANEG_STATE_ABILITY_DETECT 6
  1712. #define ANEG_STATE_ACK_DETECT_INIT 7
  1713. #define ANEG_STATE_ACK_DETECT 8
  1714. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1715. #define ANEG_STATE_COMPLETE_ACK 10
  1716. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1717. #define ANEG_STATE_IDLE_DETECT 12
  1718. #define ANEG_STATE_LINK_OK 13
  1719. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1720. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1721. u32 flags;
  1722. #define MR_AN_ENABLE 0x00000001
  1723. #define MR_RESTART_AN 0x00000002
  1724. #define MR_AN_COMPLETE 0x00000004
  1725. #define MR_PAGE_RX 0x00000008
  1726. #define MR_NP_LOADED 0x00000010
  1727. #define MR_TOGGLE_TX 0x00000020
  1728. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1729. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1730. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1731. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1732. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1733. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1734. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1735. #define MR_TOGGLE_RX 0x00002000
  1736. #define MR_NP_RX 0x00004000
  1737. #define MR_LINK_OK 0x80000000
  1738. unsigned long link_time, cur_time;
  1739. u32 ability_match_cfg;
  1740. int ability_match_count;
  1741. char ability_match, idle_match, ack_match;
  1742. u32 txconfig, rxconfig;
  1743. #define ANEG_CFG_NP 0x00000080
  1744. #define ANEG_CFG_ACK 0x00000040
  1745. #define ANEG_CFG_RF2 0x00000020
  1746. #define ANEG_CFG_RF1 0x00000010
  1747. #define ANEG_CFG_PS2 0x00000001
  1748. #define ANEG_CFG_PS1 0x00008000
  1749. #define ANEG_CFG_HD 0x00004000
  1750. #define ANEG_CFG_FD 0x00002000
  1751. #define ANEG_CFG_INVAL 0x00001f06
  1752. };
  1753. #define ANEG_OK 0
  1754. #define ANEG_DONE 1
  1755. #define ANEG_TIMER_ENAB 2
  1756. #define ANEG_FAILED -1
  1757. #define ANEG_STATE_SETTLE_TIME 10000
  1758. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1759. struct tg3_fiber_aneginfo *ap)
  1760. {
  1761. unsigned long delta;
  1762. u32 rx_cfg_reg;
  1763. int ret;
  1764. if (ap->state == ANEG_STATE_UNKNOWN) {
  1765. ap->rxconfig = 0;
  1766. ap->link_time = 0;
  1767. ap->cur_time = 0;
  1768. ap->ability_match_cfg = 0;
  1769. ap->ability_match_count = 0;
  1770. ap->ability_match = 0;
  1771. ap->idle_match = 0;
  1772. ap->ack_match = 0;
  1773. }
  1774. ap->cur_time++;
  1775. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1776. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1777. if (rx_cfg_reg != ap->ability_match_cfg) {
  1778. ap->ability_match_cfg = rx_cfg_reg;
  1779. ap->ability_match = 0;
  1780. ap->ability_match_count = 0;
  1781. } else {
  1782. if (++ap->ability_match_count > 1) {
  1783. ap->ability_match = 1;
  1784. ap->ability_match_cfg = rx_cfg_reg;
  1785. }
  1786. }
  1787. if (rx_cfg_reg & ANEG_CFG_ACK)
  1788. ap->ack_match = 1;
  1789. else
  1790. ap->ack_match = 0;
  1791. ap->idle_match = 0;
  1792. } else {
  1793. ap->idle_match = 1;
  1794. ap->ability_match_cfg = 0;
  1795. ap->ability_match_count = 0;
  1796. ap->ability_match = 0;
  1797. ap->ack_match = 0;
  1798. rx_cfg_reg = 0;
  1799. }
  1800. ap->rxconfig = rx_cfg_reg;
  1801. ret = ANEG_OK;
  1802. switch(ap->state) {
  1803. case ANEG_STATE_UNKNOWN:
  1804. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1805. ap->state = ANEG_STATE_AN_ENABLE;
  1806. /* fallthru */
  1807. case ANEG_STATE_AN_ENABLE:
  1808. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1809. if (ap->flags & MR_AN_ENABLE) {
  1810. ap->link_time = 0;
  1811. ap->cur_time = 0;
  1812. ap->ability_match_cfg = 0;
  1813. ap->ability_match_count = 0;
  1814. ap->ability_match = 0;
  1815. ap->idle_match = 0;
  1816. ap->ack_match = 0;
  1817. ap->state = ANEG_STATE_RESTART_INIT;
  1818. } else {
  1819. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1820. }
  1821. break;
  1822. case ANEG_STATE_RESTART_INIT:
  1823. ap->link_time = ap->cur_time;
  1824. ap->flags &= ~(MR_NP_LOADED);
  1825. ap->txconfig = 0;
  1826. tw32(MAC_TX_AUTO_NEG, 0);
  1827. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1828. tw32_f(MAC_MODE, tp->mac_mode);
  1829. udelay(40);
  1830. ret = ANEG_TIMER_ENAB;
  1831. ap->state = ANEG_STATE_RESTART;
  1832. /* fallthru */
  1833. case ANEG_STATE_RESTART:
  1834. delta = ap->cur_time - ap->link_time;
  1835. if (delta > ANEG_STATE_SETTLE_TIME) {
  1836. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1837. } else {
  1838. ret = ANEG_TIMER_ENAB;
  1839. }
  1840. break;
  1841. case ANEG_STATE_DISABLE_LINK_OK:
  1842. ret = ANEG_DONE;
  1843. break;
  1844. case ANEG_STATE_ABILITY_DETECT_INIT:
  1845. ap->flags &= ~(MR_TOGGLE_TX);
  1846. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1847. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1848. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1849. tw32_f(MAC_MODE, tp->mac_mode);
  1850. udelay(40);
  1851. ap->state = ANEG_STATE_ABILITY_DETECT;
  1852. break;
  1853. case ANEG_STATE_ABILITY_DETECT:
  1854. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1855. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1856. }
  1857. break;
  1858. case ANEG_STATE_ACK_DETECT_INIT:
  1859. ap->txconfig |= ANEG_CFG_ACK;
  1860. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1861. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1862. tw32_f(MAC_MODE, tp->mac_mode);
  1863. udelay(40);
  1864. ap->state = ANEG_STATE_ACK_DETECT;
  1865. /* fallthru */
  1866. case ANEG_STATE_ACK_DETECT:
  1867. if (ap->ack_match != 0) {
  1868. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1869. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1870. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1871. } else {
  1872. ap->state = ANEG_STATE_AN_ENABLE;
  1873. }
  1874. } else if (ap->ability_match != 0 &&
  1875. ap->rxconfig == 0) {
  1876. ap->state = ANEG_STATE_AN_ENABLE;
  1877. }
  1878. break;
  1879. case ANEG_STATE_COMPLETE_ACK_INIT:
  1880. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1881. ret = ANEG_FAILED;
  1882. break;
  1883. }
  1884. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1885. MR_LP_ADV_HALF_DUPLEX |
  1886. MR_LP_ADV_SYM_PAUSE |
  1887. MR_LP_ADV_ASYM_PAUSE |
  1888. MR_LP_ADV_REMOTE_FAULT1 |
  1889. MR_LP_ADV_REMOTE_FAULT2 |
  1890. MR_LP_ADV_NEXT_PAGE |
  1891. MR_TOGGLE_RX |
  1892. MR_NP_RX);
  1893. if (ap->rxconfig & ANEG_CFG_FD)
  1894. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1895. if (ap->rxconfig & ANEG_CFG_HD)
  1896. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1897. if (ap->rxconfig & ANEG_CFG_PS1)
  1898. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1899. if (ap->rxconfig & ANEG_CFG_PS2)
  1900. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1901. if (ap->rxconfig & ANEG_CFG_RF1)
  1902. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1903. if (ap->rxconfig & ANEG_CFG_RF2)
  1904. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1905. if (ap->rxconfig & ANEG_CFG_NP)
  1906. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1907. ap->link_time = ap->cur_time;
  1908. ap->flags ^= (MR_TOGGLE_TX);
  1909. if (ap->rxconfig & 0x0008)
  1910. ap->flags |= MR_TOGGLE_RX;
  1911. if (ap->rxconfig & ANEG_CFG_NP)
  1912. ap->flags |= MR_NP_RX;
  1913. ap->flags |= MR_PAGE_RX;
  1914. ap->state = ANEG_STATE_COMPLETE_ACK;
  1915. ret = ANEG_TIMER_ENAB;
  1916. break;
  1917. case ANEG_STATE_COMPLETE_ACK:
  1918. if (ap->ability_match != 0 &&
  1919. ap->rxconfig == 0) {
  1920. ap->state = ANEG_STATE_AN_ENABLE;
  1921. break;
  1922. }
  1923. delta = ap->cur_time - ap->link_time;
  1924. if (delta > ANEG_STATE_SETTLE_TIME) {
  1925. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  1926. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1927. } else {
  1928. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  1929. !(ap->flags & MR_NP_RX)) {
  1930. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1931. } else {
  1932. ret = ANEG_FAILED;
  1933. }
  1934. }
  1935. }
  1936. break;
  1937. case ANEG_STATE_IDLE_DETECT_INIT:
  1938. ap->link_time = ap->cur_time;
  1939. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1940. tw32_f(MAC_MODE, tp->mac_mode);
  1941. udelay(40);
  1942. ap->state = ANEG_STATE_IDLE_DETECT;
  1943. ret = ANEG_TIMER_ENAB;
  1944. break;
  1945. case ANEG_STATE_IDLE_DETECT:
  1946. if (ap->ability_match != 0 &&
  1947. ap->rxconfig == 0) {
  1948. ap->state = ANEG_STATE_AN_ENABLE;
  1949. break;
  1950. }
  1951. delta = ap->cur_time - ap->link_time;
  1952. if (delta > ANEG_STATE_SETTLE_TIME) {
  1953. /* XXX another gem from the Broadcom driver :( */
  1954. ap->state = ANEG_STATE_LINK_OK;
  1955. }
  1956. break;
  1957. case ANEG_STATE_LINK_OK:
  1958. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1959. ret = ANEG_DONE;
  1960. break;
  1961. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1962. /* ??? unimplemented */
  1963. break;
  1964. case ANEG_STATE_NEXT_PAGE_WAIT:
  1965. /* ??? unimplemented */
  1966. break;
  1967. default:
  1968. ret = ANEG_FAILED;
  1969. break;
  1970. };
  1971. return ret;
  1972. }
  1973. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  1974. {
  1975. int res = 0;
  1976. struct tg3_fiber_aneginfo aninfo;
  1977. int status = ANEG_FAILED;
  1978. unsigned int tick;
  1979. u32 tmp;
  1980. tw32_f(MAC_TX_AUTO_NEG, 0);
  1981. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  1982. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  1983. udelay(40);
  1984. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  1985. udelay(40);
  1986. memset(&aninfo, 0, sizeof(aninfo));
  1987. aninfo.flags |= MR_AN_ENABLE;
  1988. aninfo.state = ANEG_STATE_UNKNOWN;
  1989. aninfo.cur_time = 0;
  1990. tick = 0;
  1991. while (++tick < 195000) {
  1992. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  1993. if (status == ANEG_DONE || status == ANEG_FAILED)
  1994. break;
  1995. udelay(1);
  1996. }
  1997. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1998. tw32_f(MAC_MODE, tp->mac_mode);
  1999. udelay(40);
  2000. *flags = aninfo.flags;
  2001. if (status == ANEG_DONE &&
  2002. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2003. MR_LP_ADV_FULL_DUPLEX)))
  2004. res = 1;
  2005. return res;
  2006. }
  2007. static void tg3_init_bcm8002(struct tg3 *tp)
  2008. {
  2009. u32 mac_status = tr32(MAC_STATUS);
  2010. int i;
  2011. /* Reset when initting first time or we have a link. */
  2012. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2013. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2014. return;
  2015. /* Set PLL lock range. */
  2016. tg3_writephy(tp, 0x16, 0x8007);
  2017. /* SW reset */
  2018. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2019. /* Wait for reset to complete. */
  2020. /* XXX schedule_timeout() ... */
  2021. for (i = 0; i < 500; i++)
  2022. udelay(10);
  2023. /* Config mode; select PMA/Ch 1 regs. */
  2024. tg3_writephy(tp, 0x10, 0x8411);
  2025. /* Enable auto-lock and comdet, select txclk for tx. */
  2026. tg3_writephy(tp, 0x11, 0x0a10);
  2027. tg3_writephy(tp, 0x18, 0x00a0);
  2028. tg3_writephy(tp, 0x16, 0x41ff);
  2029. /* Assert and deassert POR. */
  2030. tg3_writephy(tp, 0x13, 0x0400);
  2031. udelay(40);
  2032. tg3_writephy(tp, 0x13, 0x0000);
  2033. tg3_writephy(tp, 0x11, 0x0a50);
  2034. udelay(40);
  2035. tg3_writephy(tp, 0x11, 0x0a10);
  2036. /* Wait for signal to stabilize */
  2037. /* XXX schedule_timeout() ... */
  2038. for (i = 0; i < 15000; i++)
  2039. udelay(10);
  2040. /* Deselect the channel register so we can read the PHYID
  2041. * later.
  2042. */
  2043. tg3_writephy(tp, 0x10, 0x8011);
  2044. }
  2045. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2046. {
  2047. u32 sg_dig_ctrl, sg_dig_status;
  2048. u32 serdes_cfg, expected_sg_dig_ctrl;
  2049. int workaround, port_a;
  2050. int current_link_up;
  2051. serdes_cfg = 0;
  2052. expected_sg_dig_ctrl = 0;
  2053. workaround = 0;
  2054. port_a = 1;
  2055. current_link_up = 0;
  2056. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2057. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2058. workaround = 1;
  2059. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2060. port_a = 0;
  2061. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2062. /* preserve bits 20-23 for voltage regulator */
  2063. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2064. }
  2065. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2066. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2067. if (sg_dig_ctrl & (1 << 31)) {
  2068. if (workaround) {
  2069. u32 val = serdes_cfg;
  2070. if (port_a)
  2071. val |= 0xc010000;
  2072. else
  2073. val |= 0x4010000;
  2074. tw32_f(MAC_SERDES_CFG, val);
  2075. }
  2076. tw32_f(SG_DIG_CTRL, 0x01388400);
  2077. }
  2078. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2079. tg3_setup_flow_control(tp, 0, 0);
  2080. current_link_up = 1;
  2081. }
  2082. goto out;
  2083. }
  2084. /* Want auto-negotiation. */
  2085. expected_sg_dig_ctrl = 0x81388400;
  2086. /* Pause capability */
  2087. expected_sg_dig_ctrl |= (1 << 11);
  2088. /* Asymettric pause */
  2089. expected_sg_dig_ctrl |= (1 << 12);
  2090. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2091. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2092. tp->serdes_counter &&
  2093. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2094. MAC_STATUS_RCVD_CFG)) ==
  2095. MAC_STATUS_PCS_SYNCED)) {
  2096. tp->serdes_counter--;
  2097. current_link_up = 1;
  2098. goto out;
  2099. }
  2100. restart_autoneg:
  2101. if (workaround)
  2102. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2103. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2104. udelay(5);
  2105. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2106. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2107. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2108. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2109. MAC_STATUS_SIGNAL_DET)) {
  2110. sg_dig_status = tr32(SG_DIG_STATUS);
  2111. mac_status = tr32(MAC_STATUS);
  2112. if ((sg_dig_status & (1 << 1)) &&
  2113. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2114. u32 local_adv, remote_adv;
  2115. local_adv = ADVERTISE_PAUSE_CAP;
  2116. remote_adv = 0;
  2117. if (sg_dig_status & (1 << 19))
  2118. remote_adv |= LPA_PAUSE_CAP;
  2119. if (sg_dig_status & (1 << 20))
  2120. remote_adv |= LPA_PAUSE_ASYM;
  2121. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2122. current_link_up = 1;
  2123. tp->serdes_counter = 0;
  2124. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2125. } else if (!(sg_dig_status & (1 << 1))) {
  2126. if (tp->serdes_counter)
  2127. tp->serdes_counter--;
  2128. else {
  2129. if (workaround) {
  2130. u32 val = serdes_cfg;
  2131. if (port_a)
  2132. val |= 0xc010000;
  2133. else
  2134. val |= 0x4010000;
  2135. tw32_f(MAC_SERDES_CFG, val);
  2136. }
  2137. tw32_f(SG_DIG_CTRL, 0x01388400);
  2138. udelay(40);
  2139. /* Link parallel detection - link is up */
  2140. /* only if we have PCS_SYNC and not */
  2141. /* receiving config code words */
  2142. mac_status = tr32(MAC_STATUS);
  2143. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2144. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2145. tg3_setup_flow_control(tp, 0, 0);
  2146. current_link_up = 1;
  2147. tp->tg3_flags2 |=
  2148. TG3_FLG2_PARALLEL_DETECT;
  2149. tp->serdes_counter =
  2150. SERDES_PARALLEL_DET_TIMEOUT;
  2151. } else
  2152. goto restart_autoneg;
  2153. }
  2154. }
  2155. } else {
  2156. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2157. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2158. }
  2159. out:
  2160. return current_link_up;
  2161. }
  2162. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2163. {
  2164. int current_link_up = 0;
  2165. if (!(mac_status & MAC_STATUS_PCS_SYNCED)) {
  2166. tp->tg3_flags &= ~TG3_FLAG_GOT_SERDES_FLOWCTL;
  2167. goto out;
  2168. }
  2169. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2170. u32 flags;
  2171. int i;
  2172. if (fiber_autoneg(tp, &flags)) {
  2173. u32 local_adv, remote_adv;
  2174. local_adv = ADVERTISE_PAUSE_CAP;
  2175. remote_adv = 0;
  2176. if (flags & MR_LP_ADV_SYM_PAUSE)
  2177. remote_adv |= LPA_PAUSE_CAP;
  2178. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2179. remote_adv |= LPA_PAUSE_ASYM;
  2180. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2181. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2182. current_link_up = 1;
  2183. }
  2184. for (i = 0; i < 30; i++) {
  2185. udelay(20);
  2186. tw32_f(MAC_STATUS,
  2187. (MAC_STATUS_SYNC_CHANGED |
  2188. MAC_STATUS_CFG_CHANGED));
  2189. udelay(40);
  2190. if ((tr32(MAC_STATUS) &
  2191. (MAC_STATUS_SYNC_CHANGED |
  2192. MAC_STATUS_CFG_CHANGED)) == 0)
  2193. break;
  2194. }
  2195. mac_status = tr32(MAC_STATUS);
  2196. if (current_link_up == 0 &&
  2197. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2198. !(mac_status & MAC_STATUS_RCVD_CFG))
  2199. current_link_up = 1;
  2200. } else {
  2201. /* Forcing 1000FD link up. */
  2202. current_link_up = 1;
  2203. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2204. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2205. udelay(40);
  2206. }
  2207. out:
  2208. return current_link_up;
  2209. }
  2210. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2211. {
  2212. u32 orig_pause_cfg;
  2213. u16 orig_active_speed;
  2214. u8 orig_active_duplex;
  2215. u32 mac_status;
  2216. int current_link_up;
  2217. int i;
  2218. orig_pause_cfg =
  2219. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2220. TG3_FLAG_TX_PAUSE));
  2221. orig_active_speed = tp->link_config.active_speed;
  2222. orig_active_duplex = tp->link_config.active_duplex;
  2223. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2224. netif_carrier_ok(tp->dev) &&
  2225. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2226. mac_status = tr32(MAC_STATUS);
  2227. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2228. MAC_STATUS_SIGNAL_DET |
  2229. MAC_STATUS_CFG_CHANGED |
  2230. MAC_STATUS_RCVD_CFG);
  2231. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2232. MAC_STATUS_SIGNAL_DET)) {
  2233. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2234. MAC_STATUS_CFG_CHANGED));
  2235. return 0;
  2236. }
  2237. }
  2238. tw32_f(MAC_TX_AUTO_NEG, 0);
  2239. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2240. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2241. tw32_f(MAC_MODE, tp->mac_mode);
  2242. udelay(40);
  2243. if (tp->phy_id == PHY_ID_BCM8002)
  2244. tg3_init_bcm8002(tp);
  2245. /* Enable link change event even when serdes polling. */
  2246. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2247. udelay(40);
  2248. current_link_up = 0;
  2249. mac_status = tr32(MAC_STATUS);
  2250. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2251. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2252. else
  2253. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2254. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  2255. tw32_f(MAC_MODE, tp->mac_mode);
  2256. udelay(40);
  2257. tp->hw_status->status =
  2258. (SD_STATUS_UPDATED |
  2259. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2260. for (i = 0; i < 100; i++) {
  2261. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2262. MAC_STATUS_CFG_CHANGED));
  2263. udelay(5);
  2264. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2265. MAC_STATUS_CFG_CHANGED |
  2266. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2267. break;
  2268. }
  2269. mac_status = tr32(MAC_STATUS);
  2270. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2271. current_link_up = 0;
  2272. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2273. tp->serdes_counter == 0) {
  2274. tw32_f(MAC_MODE, (tp->mac_mode |
  2275. MAC_MODE_SEND_CONFIGS));
  2276. udelay(1);
  2277. tw32_f(MAC_MODE, tp->mac_mode);
  2278. }
  2279. }
  2280. if (current_link_up == 1) {
  2281. tp->link_config.active_speed = SPEED_1000;
  2282. tp->link_config.active_duplex = DUPLEX_FULL;
  2283. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2284. LED_CTRL_LNKLED_OVERRIDE |
  2285. LED_CTRL_1000MBPS_ON));
  2286. } else {
  2287. tp->link_config.active_speed = SPEED_INVALID;
  2288. tp->link_config.active_duplex = DUPLEX_INVALID;
  2289. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2290. LED_CTRL_LNKLED_OVERRIDE |
  2291. LED_CTRL_TRAFFIC_OVERRIDE));
  2292. }
  2293. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2294. if (current_link_up)
  2295. netif_carrier_on(tp->dev);
  2296. else
  2297. netif_carrier_off(tp->dev);
  2298. tg3_link_report(tp);
  2299. } else {
  2300. u32 now_pause_cfg =
  2301. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2302. TG3_FLAG_TX_PAUSE);
  2303. if (orig_pause_cfg != now_pause_cfg ||
  2304. orig_active_speed != tp->link_config.active_speed ||
  2305. orig_active_duplex != tp->link_config.active_duplex)
  2306. tg3_link_report(tp);
  2307. }
  2308. return 0;
  2309. }
  2310. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2311. {
  2312. int current_link_up, err = 0;
  2313. u32 bmsr, bmcr;
  2314. u16 current_speed;
  2315. u8 current_duplex;
  2316. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2317. tw32_f(MAC_MODE, tp->mac_mode);
  2318. udelay(40);
  2319. tw32(MAC_EVENT, 0);
  2320. tw32_f(MAC_STATUS,
  2321. (MAC_STATUS_SYNC_CHANGED |
  2322. MAC_STATUS_CFG_CHANGED |
  2323. MAC_STATUS_MI_COMPLETION |
  2324. MAC_STATUS_LNKSTATE_CHANGED));
  2325. udelay(40);
  2326. if (force_reset)
  2327. tg3_phy_reset(tp);
  2328. current_link_up = 0;
  2329. current_speed = SPEED_INVALID;
  2330. current_duplex = DUPLEX_INVALID;
  2331. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2332. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2333. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2334. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2335. bmsr |= BMSR_LSTATUS;
  2336. else
  2337. bmsr &= ~BMSR_LSTATUS;
  2338. }
  2339. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2340. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2341. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2342. /* do nothing, just check for link up at the end */
  2343. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2344. u32 adv, new_adv;
  2345. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2346. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2347. ADVERTISE_1000XPAUSE |
  2348. ADVERTISE_1000XPSE_ASYM |
  2349. ADVERTISE_SLCT);
  2350. /* Always advertise symmetric PAUSE just like copper */
  2351. new_adv |= ADVERTISE_1000XPAUSE;
  2352. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2353. new_adv |= ADVERTISE_1000XHALF;
  2354. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2355. new_adv |= ADVERTISE_1000XFULL;
  2356. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2357. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2358. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2359. tg3_writephy(tp, MII_BMCR, bmcr);
  2360. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2361. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2362. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2363. return err;
  2364. }
  2365. } else {
  2366. u32 new_bmcr;
  2367. bmcr &= ~BMCR_SPEED1000;
  2368. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2369. if (tp->link_config.duplex == DUPLEX_FULL)
  2370. new_bmcr |= BMCR_FULLDPLX;
  2371. if (new_bmcr != bmcr) {
  2372. /* BMCR_SPEED1000 is a reserved bit that needs
  2373. * to be set on write.
  2374. */
  2375. new_bmcr |= BMCR_SPEED1000;
  2376. /* Force a linkdown */
  2377. if (netif_carrier_ok(tp->dev)) {
  2378. u32 adv;
  2379. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2380. adv &= ~(ADVERTISE_1000XFULL |
  2381. ADVERTISE_1000XHALF |
  2382. ADVERTISE_SLCT);
  2383. tg3_writephy(tp, MII_ADVERTISE, adv);
  2384. tg3_writephy(tp, MII_BMCR, bmcr |
  2385. BMCR_ANRESTART |
  2386. BMCR_ANENABLE);
  2387. udelay(10);
  2388. netif_carrier_off(tp->dev);
  2389. }
  2390. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2391. bmcr = new_bmcr;
  2392. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2393. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2394. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2395. ASIC_REV_5714) {
  2396. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2397. bmsr |= BMSR_LSTATUS;
  2398. else
  2399. bmsr &= ~BMSR_LSTATUS;
  2400. }
  2401. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2402. }
  2403. }
  2404. if (bmsr & BMSR_LSTATUS) {
  2405. current_speed = SPEED_1000;
  2406. current_link_up = 1;
  2407. if (bmcr & BMCR_FULLDPLX)
  2408. current_duplex = DUPLEX_FULL;
  2409. else
  2410. current_duplex = DUPLEX_HALF;
  2411. if (bmcr & BMCR_ANENABLE) {
  2412. u32 local_adv, remote_adv, common;
  2413. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2414. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2415. common = local_adv & remote_adv;
  2416. if (common & (ADVERTISE_1000XHALF |
  2417. ADVERTISE_1000XFULL)) {
  2418. if (common & ADVERTISE_1000XFULL)
  2419. current_duplex = DUPLEX_FULL;
  2420. else
  2421. current_duplex = DUPLEX_HALF;
  2422. tg3_setup_flow_control(tp, local_adv,
  2423. remote_adv);
  2424. }
  2425. else
  2426. current_link_up = 0;
  2427. }
  2428. }
  2429. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2430. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2431. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2432. tw32_f(MAC_MODE, tp->mac_mode);
  2433. udelay(40);
  2434. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2435. tp->link_config.active_speed = current_speed;
  2436. tp->link_config.active_duplex = current_duplex;
  2437. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2438. if (current_link_up)
  2439. netif_carrier_on(tp->dev);
  2440. else {
  2441. netif_carrier_off(tp->dev);
  2442. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2443. }
  2444. tg3_link_report(tp);
  2445. }
  2446. return err;
  2447. }
  2448. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2449. {
  2450. if (tp->serdes_counter) {
  2451. /* Give autoneg time to complete. */
  2452. tp->serdes_counter--;
  2453. return;
  2454. }
  2455. if (!netif_carrier_ok(tp->dev) &&
  2456. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2457. u32 bmcr;
  2458. tg3_readphy(tp, MII_BMCR, &bmcr);
  2459. if (bmcr & BMCR_ANENABLE) {
  2460. u32 phy1, phy2;
  2461. /* Select shadow register 0x1f */
  2462. tg3_writephy(tp, 0x1c, 0x7c00);
  2463. tg3_readphy(tp, 0x1c, &phy1);
  2464. /* Select expansion interrupt status register */
  2465. tg3_writephy(tp, 0x17, 0x0f01);
  2466. tg3_readphy(tp, 0x15, &phy2);
  2467. tg3_readphy(tp, 0x15, &phy2);
  2468. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2469. /* We have signal detect and not receiving
  2470. * config code words, link is up by parallel
  2471. * detection.
  2472. */
  2473. bmcr &= ~BMCR_ANENABLE;
  2474. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2475. tg3_writephy(tp, MII_BMCR, bmcr);
  2476. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2477. }
  2478. }
  2479. }
  2480. else if (netif_carrier_ok(tp->dev) &&
  2481. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2482. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2483. u32 phy2;
  2484. /* Select expansion interrupt status register */
  2485. tg3_writephy(tp, 0x17, 0x0f01);
  2486. tg3_readphy(tp, 0x15, &phy2);
  2487. if (phy2 & 0x20) {
  2488. u32 bmcr;
  2489. /* Config code words received, turn on autoneg. */
  2490. tg3_readphy(tp, MII_BMCR, &bmcr);
  2491. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2492. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2493. }
  2494. }
  2495. }
  2496. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2497. {
  2498. int err;
  2499. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2500. err = tg3_setup_fiber_phy(tp, force_reset);
  2501. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2502. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2503. } else {
  2504. err = tg3_setup_copper_phy(tp, force_reset);
  2505. }
  2506. if (tp->link_config.active_speed == SPEED_1000 &&
  2507. tp->link_config.active_duplex == DUPLEX_HALF)
  2508. tw32(MAC_TX_LENGTHS,
  2509. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2510. (6 << TX_LENGTHS_IPG_SHIFT) |
  2511. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2512. else
  2513. tw32(MAC_TX_LENGTHS,
  2514. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2515. (6 << TX_LENGTHS_IPG_SHIFT) |
  2516. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2517. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2518. if (netif_carrier_ok(tp->dev)) {
  2519. tw32(HOSTCC_STAT_COAL_TICKS,
  2520. tp->coal.stats_block_coalesce_usecs);
  2521. } else {
  2522. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2523. }
  2524. }
  2525. return err;
  2526. }
  2527. /* This is called whenever we suspect that the system chipset is re-
  2528. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2529. * is bogus tx completions. We try to recover by setting the
  2530. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2531. * in the workqueue.
  2532. */
  2533. static void tg3_tx_recover(struct tg3 *tp)
  2534. {
  2535. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2536. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2537. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2538. "mapped I/O cycles to the network device, attempting to "
  2539. "recover. Please report the problem to the driver maintainer "
  2540. "and include system chipset information.\n", tp->dev->name);
  2541. spin_lock(&tp->lock);
  2542. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2543. spin_unlock(&tp->lock);
  2544. }
  2545. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2546. {
  2547. smp_mb();
  2548. return (tp->tx_pending -
  2549. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2550. }
  2551. /* Tigon3 never reports partial packet sends. So we do not
  2552. * need special logic to handle SKBs that have not had all
  2553. * of their frags sent yet, like SunGEM does.
  2554. */
  2555. static void tg3_tx(struct tg3 *tp)
  2556. {
  2557. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2558. u32 sw_idx = tp->tx_cons;
  2559. while (sw_idx != hw_idx) {
  2560. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2561. struct sk_buff *skb = ri->skb;
  2562. int i, tx_bug = 0;
  2563. if (unlikely(skb == NULL)) {
  2564. tg3_tx_recover(tp);
  2565. return;
  2566. }
  2567. pci_unmap_single(tp->pdev,
  2568. pci_unmap_addr(ri, mapping),
  2569. skb_headlen(skb),
  2570. PCI_DMA_TODEVICE);
  2571. ri->skb = NULL;
  2572. sw_idx = NEXT_TX(sw_idx);
  2573. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2574. ri = &tp->tx_buffers[sw_idx];
  2575. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2576. tx_bug = 1;
  2577. pci_unmap_page(tp->pdev,
  2578. pci_unmap_addr(ri, mapping),
  2579. skb_shinfo(skb)->frags[i].size,
  2580. PCI_DMA_TODEVICE);
  2581. sw_idx = NEXT_TX(sw_idx);
  2582. }
  2583. dev_kfree_skb(skb);
  2584. if (unlikely(tx_bug)) {
  2585. tg3_tx_recover(tp);
  2586. return;
  2587. }
  2588. }
  2589. tp->tx_cons = sw_idx;
  2590. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2591. * before checking for netif_queue_stopped(). Without the
  2592. * memory barrier, there is a small possibility that tg3_start_xmit()
  2593. * will miss it and cause the queue to be stopped forever.
  2594. */
  2595. smp_mb();
  2596. if (unlikely(netif_queue_stopped(tp->dev) &&
  2597. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH))) {
  2598. netif_tx_lock(tp->dev);
  2599. if (netif_queue_stopped(tp->dev) &&
  2600. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH))
  2601. netif_wake_queue(tp->dev);
  2602. netif_tx_unlock(tp->dev);
  2603. }
  2604. }
  2605. /* Returns size of skb allocated or < 0 on error.
  2606. *
  2607. * We only need to fill in the address because the other members
  2608. * of the RX descriptor are invariant, see tg3_init_rings.
  2609. *
  2610. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2611. * posting buffers we only dirty the first cache line of the RX
  2612. * descriptor (containing the address). Whereas for the RX status
  2613. * buffers the cpu only reads the last cacheline of the RX descriptor
  2614. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2615. */
  2616. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2617. int src_idx, u32 dest_idx_unmasked)
  2618. {
  2619. struct tg3_rx_buffer_desc *desc;
  2620. struct ring_info *map, *src_map;
  2621. struct sk_buff *skb;
  2622. dma_addr_t mapping;
  2623. int skb_size, dest_idx;
  2624. src_map = NULL;
  2625. switch (opaque_key) {
  2626. case RXD_OPAQUE_RING_STD:
  2627. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2628. desc = &tp->rx_std[dest_idx];
  2629. map = &tp->rx_std_buffers[dest_idx];
  2630. if (src_idx >= 0)
  2631. src_map = &tp->rx_std_buffers[src_idx];
  2632. skb_size = tp->rx_pkt_buf_sz;
  2633. break;
  2634. case RXD_OPAQUE_RING_JUMBO:
  2635. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2636. desc = &tp->rx_jumbo[dest_idx];
  2637. map = &tp->rx_jumbo_buffers[dest_idx];
  2638. if (src_idx >= 0)
  2639. src_map = &tp->rx_jumbo_buffers[src_idx];
  2640. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2641. break;
  2642. default:
  2643. return -EINVAL;
  2644. };
  2645. /* Do not overwrite any of the map or rp information
  2646. * until we are sure we can commit to a new buffer.
  2647. *
  2648. * Callers depend upon this behavior and assume that
  2649. * we leave everything unchanged if we fail.
  2650. */
  2651. skb = netdev_alloc_skb(tp->dev, skb_size);
  2652. if (skb == NULL)
  2653. return -ENOMEM;
  2654. skb_reserve(skb, tp->rx_offset);
  2655. mapping = pci_map_single(tp->pdev, skb->data,
  2656. skb_size - tp->rx_offset,
  2657. PCI_DMA_FROMDEVICE);
  2658. map->skb = skb;
  2659. pci_unmap_addr_set(map, mapping, mapping);
  2660. if (src_map != NULL)
  2661. src_map->skb = NULL;
  2662. desc->addr_hi = ((u64)mapping >> 32);
  2663. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2664. return skb_size;
  2665. }
  2666. /* We only need to move over in the address because the other
  2667. * members of the RX descriptor are invariant. See notes above
  2668. * tg3_alloc_rx_skb for full details.
  2669. */
  2670. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2671. int src_idx, u32 dest_idx_unmasked)
  2672. {
  2673. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2674. struct ring_info *src_map, *dest_map;
  2675. int dest_idx;
  2676. switch (opaque_key) {
  2677. case RXD_OPAQUE_RING_STD:
  2678. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2679. dest_desc = &tp->rx_std[dest_idx];
  2680. dest_map = &tp->rx_std_buffers[dest_idx];
  2681. src_desc = &tp->rx_std[src_idx];
  2682. src_map = &tp->rx_std_buffers[src_idx];
  2683. break;
  2684. case RXD_OPAQUE_RING_JUMBO:
  2685. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2686. dest_desc = &tp->rx_jumbo[dest_idx];
  2687. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2688. src_desc = &tp->rx_jumbo[src_idx];
  2689. src_map = &tp->rx_jumbo_buffers[src_idx];
  2690. break;
  2691. default:
  2692. return;
  2693. };
  2694. dest_map->skb = src_map->skb;
  2695. pci_unmap_addr_set(dest_map, mapping,
  2696. pci_unmap_addr(src_map, mapping));
  2697. dest_desc->addr_hi = src_desc->addr_hi;
  2698. dest_desc->addr_lo = src_desc->addr_lo;
  2699. src_map->skb = NULL;
  2700. }
  2701. #if TG3_VLAN_TAG_USED
  2702. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2703. {
  2704. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2705. }
  2706. #endif
  2707. /* The RX ring scheme is composed of multiple rings which post fresh
  2708. * buffers to the chip, and one special ring the chip uses to report
  2709. * status back to the host.
  2710. *
  2711. * The special ring reports the status of received packets to the
  2712. * host. The chip does not write into the original descriptor the
  2713. * RX buffer was obtained from. The chip simply takes the original
  2714. * descriptor as provided by the host, updates the status and length
  2715. * field, then writes this into the next status ring entry.
  2716. *
  2717. * Each ring the host uses to post buffers to the chip is described
  2718. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2719. * it is first placed into the on-chip ram. When the packet's length
  2720. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2721. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2722. * which is within the range of the new packet's length is chosen.
  2723. *
  2724. * The "separate ring for rx status" scheme may sound queer, but it makes
  2725. * sense from a cache coherency perspective. If only the host writes
  2726. * to the buffer post rings, and only the chip writes to the rx status
  2727. * rings, then cache lines never move beyond shared-modified state.
  2728. * If both the host and chip were to write into the same ring, cache line
  2729. * eviction could occur since both entities want it in an exclusive state.
  2730. */
  2731. static int tg3_rx(struct tg3 *tp, int budget)
  2732. {
  2733. u32 work_mask, rx_std_posted = 0;
  2734. u32 sw_idx = tp->rx_rcb_ptr;
  2735. u16 hw_idx;
  2736. int received;
  2737. hw_idx = tp->hw_status->idx[0].rx_producer;
  2738. /*
  2739. * We need to order the read of hw_idx and the read of
  2740. * the opaque cookie.
  2741. */
  2742. rmb();
  2743. work_mask = 0;
  2744. received = 0;
  2745. while (sw_idx != hw_idx && budget > 0) {
  2746. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2747. unsigned int len;
  2748. struct sk_buff *skb;
  2749. dma_addr_t dma_addr;
  2750. u32 opaque_key, desc_idx, *post_ptr;
  2751. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2752. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2753. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2754. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2755. mapping);
  2756. skb = tp->rx_std_buffers[desc_idx].skb;
  2757. post_ptr = &tp->rx_std_ptr;
  2758. rx_std_posted++;
  2759. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2760. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2761. mapping);
  2762. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2763. post_ptr = &tp->rx_jumbo_ptr;
  2764. }
  2765. else {
  2766. goto next_pkt_nopost;
  2767. }
  2768. work_mask |= opaque_key;
  2769. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2770. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2771. drop_it:
  2772. tg3_recycle_rx(tp, opaque_key,
  2773. desc_idx, *post_ptr);
  2774. drop_it_no_recycle:
  2775. /* Other statistics kept track of by card. */
  2776. tp->net_stats.rx_dropped++;
  2777. goto next_pkt;
  2778. }
  2779. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2780. if (len > RX_COPY_THRESHOLD
  2781. && tp->rx_offset == 2
  2782. /* rx_offset != 2 iff this is a 5701 card running
  2783. * in PCI-X mode [see tg3_get_invariants()] */
  2784. ) {
  2785. int skb_size;
  2786. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2787. desc_idx, *post_ptr);
  2788. if (skb_size < 0)
  2789. goto drop_it;
  2790. pci_unmap_single(tp->pdev, dma_addr,
  2791. skb_size - tp->rx_offset,
  2792. PCI_DMA_FROMDEVICE);
  2793. skb_put(skb, len);
  2794. } else {
  2795. struct sk_buff *copy_skb;
  2796. tg3_recycle_rx(tp, opaque_key,
  2797. desc_idx, *post_ptr);
  2798. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  2799. if (copy_skb == NULL)
  2800. goto drop_it_no_recycle;
  2801. skb_reserve(copy_skb, 2);
  2802. skb_put(copy_skb, len);
  2803. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2804. memcpy(copy_skb->data, skb->data, len);
  2805. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2806. /* We'll reuse the original ring buffer. */
  2807. skb = copy_skb;
  2808. }
  2809. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2810. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2811. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2812. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2813. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2814. else
  2815. skb->ip_summed = CHECKSUM_NONE;
  2816. skb->protocol = eth_type_trans(skb, tp->dev);
  2817. #if TG3_VLAN_TAG_USED
  2818. if (tp->vlgrp != NULL &&
  2819. desc->type_flags & RXD_FLAG_VLAN) {
  2820. tg3_vlan_rx(tp, skb,
  2821. desc->err_vlan & RXD_VLAN_MASK);
  2822. } else
  2823. #endif
  2824. netif_receive_skb(skb);
  2825. tp->dev->last_rx = jiffies;
  2826. received++;
  2827. budget--;
  2828. next_pkt:
  2829. (*post_ptr)++;
  2830. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2831. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2832. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2833. TG3_64BIT_REG_LOW, idx);
  2834. work_mask &= ~RXD_OPAQUE_RING_STD;
  2835. rx_std_posted = 0;
  2836. }
  2837. next_pkt_nopost:
  2838. sw_idx++;
  2839. sw_idx %= TG3_RX_RCB_RING_SIZE(tp);
  2840. /* Refresh hw_idx to see if there is new work */
  2841. if (sw_idx == hw_idx) {
  2842. hw_idx = tp->hw_status->idx[0].rx_producer;
  2843. rmb();
  2844. }
  2845. }
  2846. /* ACK the status ring. */
  2847. tp->rx_rcb_ptr = sw_idx;
  2848. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2849. /* Refill RX ring(s). */
  2850. if (work_mask & RXD_OPAQUE_RING_STD) {
  2851. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2852. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2853. sw_idx);
  2854. }
  2855. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2856. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2857. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2858. sw_idx);
  2859. }
  2860. mmiowb();
  2861. return received;
  2862. }
  2863. static int tg3_poll(struct net_device *netdev, int *budget)
  2864. {
  2865. struct tg3 *tp = netdev_priv(netdev);
  2866. struct tg3_hw_status *sblk = tp->hw_status;
  2867. int done;
  2868. /* handle link change and other phy events */
  2869. if (!(tp->tg3_flags &
  2870. (TG3_FLAG_USE_LINKCHG_REG |
  2871. TG3_FLAG_POLL_SERDES))) {
  2872. if (sblk->status & SD_STATUS_LINK_CHG) {
  2873. sblk->status = SD_STATUS_UPDATED |
  2874. (sblk->status & ~SD_STATUS_LINK_CHG);
  2875. spin_lock(&tp->lock);
  2876. tg3_setup_phy(tp, 0);
  2877. spin_unlock(&tp->lock);
  2878. }
  2879. }
  2880. /* run TX completion thread */
  2881. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2882. tg3_tx(tp);
  2883. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2884. netif_rx_complete(netdev);
  2885. schedule_work(&tp->reset_task);
  2886. return 0;
  2887. }
  2888. }
  2889. /* run RX thread, within the bounds set by NAPI.
  2890. * All RX "locking" is done by ensuring outside
  2891. * code synchronizes with dev->poll()
  2892. */
  2893. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2894. int orig_budget = *budget;
  2895. int work_done;
  2896. if (orig_budget > netdev->quota)
  2897. orig_budget = netdev->quota;
  2898. work_done = tg3_rx(tp, orig_budget);
  2899. *budget -= work_done;
  2900. netdev->quota -= work_done;
  2901. }
  2902. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2903. tp->last_tag = sblk->status_tag;
  2904. rmb();
  2905. } else
  2906. sblk->status &= ~SD_STATUS_UPDATED;
  2907. /* if no more work, tell net stack and NIC we're done */
  2908. done = !tg3_has_work(tp);
  2909. if (done) {
  2910. netif_rx_complete(netdev);
  2911. tg3_restart_ints(tp);
  2912. }
  2913. return (done ? 0 : 1);
  2914. }
  2915. static void tg3_irq_quiesce(struct tg3 *tp)
  2916. {
  2917. BUG_ON(tp->irq_sync);
  2918. tp->irq_sync = 1;
  2919. smp_mb();
  2920. synchronize_irq(tp->pdev->irq);
  2921. }
  2922. static inline int tg3_irq_sync(struct tg3 *tp)
  2923. {
  2924. return tp->irq_sync;
  2925. }
  2926. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  2927. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  2928. * with as well. Most of the time, this is not necessary except when
  2929. * shutting down the device.
  2930. */
  2931. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  2932. {
  2933. if (irq_sync)
  2934. tg3_irq_quiesce(tp);
  2935. spin_lock_bh(&tp->lock);
  2936. }
  2937. static inline void tg3_full_unlock(struct tg3 *tp)
  2938. {
  2939. spin_unlock_bh(&tp->lock);
  2940. }
  2941. /* One-shot MSI handler - Chip automatically disables interrupt
  2942. * after sending MSI so driver doesn't have to do it.
  2943. */
  2944. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id, struct pt_regs *regs)
  2945. {
  2946. struct net_device *dev = dev_id;
  2947. struct tg3 *tp = netdev_priv(dev);
  2948. prefetch(tp->hw_status);
  2949. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2950. if (likely(!tg3_irq_sync(tp)))
  2951. netif_rx_schedule(dev); /* schedule NAPI poll */
  2952. return IRQ_HANDLED;
  2953. }
  2954. /* MSI ISR - No need to check for interrupt sharing and no need to
  2955. * flush status block and interrupt mailbox. PCI ordering rules
  2956. * guarantee that MSI will arrive after the status block.
  2957. */
  2958. static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs)
  2959. {
  2960. struct net_device *dev = dev_id;
  2961. struct tg3 *tp = netdev_priv(dev);
  2962. prefetch(tp->hw_status);
  2963. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2964. /*
  2965. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2966. * chip-internal interrupt pending events.
  2967. * Writing non-zero to intr-mbox-0 additional tells the
  2968. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2969. * event coalescing.
  2970. */
  2971. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  2972. if (likely(!tg3_irq_sync(tp)))
  2973. netif_rx_schedule(dev); /* schedule NAPI poll */
  2974. return IRQ_RETVAL(1);
  2975. }
  2976. static irqreturn_t tg3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2977. {
  2978. struct net_device *dev = dev_id;
  2979. struct tg3 *tp = netdev_priv(dev);
  2980. struct tg3_hw_status *sblk = tp->hw_status;
  2981. unsigned int handled = 1;
  2982. /* In INTx mode, it is possible for the interrupt to arrive at
  2983. * the CPU before the status block posted prior to the interrupt.
  2984. * Reading the PCI State register will confirm whether the
  2985. * interrupt is ours and will flush the status block.
  2986. */
  2987. if ((sblk->status & SD_STATUS_UPDATED) ||
  2988. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  2989. /*
  2990. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2991. * chip-internal interrupt pending events.
  2992. * Writing non-zero to intr-mbox-0 additional tells the
  2993. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2994. * event coalescing.
  2995. */
  2996. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  2997. 0x00000001);
  2998. if (tg3_irq_sync(tp))
  2999. goto out;
  3000. sblk->status &= ~SD_STATUS_UPDATED;
  3001. if (likely(tg3_has_work(tp))) {
  3002. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3003. netif_rx_schedule(dev); /* schedule NAPI poll */
  3004. } else {
  3005. /* No work, shared interrupt perhaps? re-enable
  3006. * interrupts, and flush that PCI write
  3007. */
  3008. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3009. 0x00000000);
  3010. }
  3011. } else { /* shared interrupt */
  3012. handled = 0;
  3013. }
  3014. out:
  3015. return IRQ_RETVAL(handled);
  3016. }
  3017. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *regs)
  3018. {
  3019. struct net_device *dev = dev_id;
  3020. struct tg3 *tp = netdev_priv(dev);
  3021. struct tg3_hw_status *sblk = tp->hw_status;
  3022. unsigned int handled = 1;
  3023. /* In INTx mode, it is possible for the interrupt to arrive at
  3024. * the CPU before the status block posted prior to the interrupt.
  3025. * Reading the PCI State register will confirm whether the
  3026. * interrupt is ours and will flush the status block.
  3027. */
  3028. if ((sblk->status_tag != tp->last_tag) ||
  3029. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3030. /*
  3031. * writing any value to intr-mbox-0 clears PCI INTA# and
  3032. * chip-internal interrupt pending events.
  3033. * writing non-zero to intr-mbox-0 additional tells the
  3034. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3035. * event coalescing.
  3036. */
  3037. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3038. 0x00000001);
  3039. if (tg3_irq_sync(tp))
  3040. goto out;
  3041. if (netif_rx_schedule_prep(dev)) {
  3042. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3043. /* Update last_tag to mark that this status has been
  3044. * seen. Because interrupt may be shared, we may be
  3045. * racing with tg3_poll(), so only update last_tag
  3046. * if tg3_poll() is not scheduled.
  3047. */
  3048. tp->last_tag = sblk->status_tag;
  3049. __netif_rx_schedule(dev);
  3050. }
  3051. } else { /* shared interrupt */
  3052. handled = 0;
  3053. }
  3054. out:
  3055. return IRQ_RETVAL(handled);
  3056. }
  3057. /* ISR for interrupt test */
  3058. static irqreturn_t tg3_test_isr(int irq, void *dev_id,
  3059. struct pt_regs *regs)
  3060. {
  3061. struct net_device *dev = dev_id;
  3062. struct tg3 *tp = netdev_priv(dev);
  3063. struct tg3_hw_status *sblk = tp->hw_status;
  3064. if ((sblk->status & SD_STATUS_UPDATED) ||
  3065. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3066. tg3_disable_ints(tp);
  3067. return IRQ_RETVAL(1);
  3068. }
  3069. return IRQ_RETVAL(0);
  3070. }
  3071. static int tg3_init_hw(struct tg3 *, int);
  3072. static int tg3_halt(struct tg3 *, int, int);
  3073. /* Restart hardware after configuration changes, self-test, etc.
  3074. * Invoked with tp->lock held.
  3075. */
  3076. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3077. {
  3078. int err;
  3079. err = tg3_init_hw(tp, reset_phy);
  3080. if (err) {
  3081. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3082. "aborting.\n", tp->dev->name);
  3083. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3084. tg3_full_unlock(tp);
  3085. del_timer_sync(&tp->timer);
  3086. tp->irq_sync = 0;
  3087. netif_poll_enable(tp->dev);
  3088. dev_close(tp->dev);
  3089. tg3_full_lock(tp, 0);
  3090. }
  3091. return err;
  3092. }
  3093. #ifdef CONFIG_NET_POLL_CONTROLLER
  3094. static void tg3_poll_controller(struct net_device *dev)
  3095. {
  3096. struct tg3 *tp = netdev_priv(dev);
  3097. tg3_interrupt(tp->pdev->irq, dev, NULL);
  3098. }
  3099. #endif
  3100. static void tg3_reset_task(void *_data)
  3101. {
  3102. struct tg3 *tp = _data;
  3103. unsigned int restart_timer;
  3104. tg3_full_lock(tp, 0);
  3105. tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
  3106. if (!netif_running(tp->dev)) {
  3107. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3108. tg3_full_unlock(tp);
  3109. return;
  3110. }
  3111. tg3_full_unlock(tp);
  3112. tg3_netif_stop(tp);
  3113. tg3_full_lock(tp, 1);
  3114. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3115. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3116. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3117. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3118. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3119. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3120. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3121. }
  3122. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3123. if (tg3_init_hw(tp, 1))
  3124. goto out;
  3125. tg3_netif_start(tp);
  3126. if (restart_timer)
  3127. mod_timer(&tp->timer, jiffies + 1);
  3128. out:
  3129. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3130. tg3_full_unlock(tp);
  3131. }
  3132. static void tg3_tx_timeout(struct net_device *dev)
  3133. {
  3134. struct tg3 *tp = netdev_priv(dev);
  3135. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3136. dev->name);
  3137. schedule_work(&tp->reset_task);
  3138. }
  3139. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3140. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3141. {
  3142. u32 base = (u32) mapping & 0xffffffff;
  3143. return ((base > 0xffffdcc0) &&
  3144. (base + len + 8 < base));
  3145. }
  3146. /* Test for DMA addresses > 40-bit */
  3147. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3148. int len)
  3149. {
  3150. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3151. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3152. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3153. return 0;
  3154. #else
  3155. return 0;
  3156. #endif
  3157. }
  3158. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3159. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3160. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3161. u32 last_plus_one, u32 *start,
  3162. u32 base_flags, u32 mss)
  3163. {
  3164. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3165. dma_addr_t new_addr = 0;
  3166. u32 entry = *start;
  3167. int i, ret = 0;
  3168. if (!new_skb) {
  3169. ret = -1;
  3170. } else {
  3171. /* New SKB is guaranteed to be linear. */
  3172. entry = *start;
  3173. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3174. PCI_DMA_TODEVICE);
  3175. /* Make sure new skb does not cross any 4G boundaries.
  3176. * Drop the packet if it does.
  3177. */
  3178. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3179. ret = -1;
  3180. dev_kfree_skb(new_skb);
  3181. new_skb = NULL;
  3182. } else {
  3183. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3184. base_flags, 1 | (mss << 1));
  3185. *start = NEXT_TX(entry);
  3186. }
  3187. }
  3188. /* Now clean up the sw ring entries. */
  3189. i = 0;
  3190. while (entry != last_plus_one) {
  3191. int len;
  3192. if (i == 0)
  3193. len = skb_headlen(skb);
  3194. else
  3195. len = skb_shinfo(skb)->frags[i-1].size;
  3196. pci_unmap_single(tp->pdev,
  3197. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3198. len, PCI_DMA_TODEVICE);
  3199. if (i == 0) {
  3200. tp->tx_buffers[entry].skb = new_skb;
  3201. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3202. } else {
  3203. tp->tx_buffers[entry].skb = NULL;
  3204. }
  3205. entry = NEXT_TX(entry);
  3206. i++;
  3207. }
  3208. dev_kfree_skb(skb);
  3209. return ret;
  3210. }
  3211. static void tg3_set_txd(struct tg3 *tp, int entry,
  3212. dma_addr_t mapping, int len, u32 flags,
  3213. u32 mss_and_is_end)
  3214. {
  3215. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3216. int is_end = (mss_and_is_end & 0x1);
  3217. u32 mss = (mss_and_is_end >> 1);
  3218. u32 vlan_tag = 0;
  3219. if (is_end)
  3220. flags |= TXD_FLAG_END;
  3221. if (flags & TXD_FLAG_VLAN) {
  3222. vlan_tag = flags >> 16;
  3223. flags &= 0xffff;
  3224. }
  3225. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3226. txd->addr_hi = ((u64) mapping >> 32);
  3227. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3228. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3229. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3230. }
  3231. /* hard_start_xmit for devices that don't have any bugs and
  3232. * support TG3_FLG2_HW_TSO_2 only.
  3233. */
  3234. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3235. {
  3236. struct tg3 *tp = netdev_priv(dev);
  3237. dma_addr_t mapping;
  3238. u32 len, entry, base_flags, mss;
  3239. len = skb_headlen(skb);
  3240. /* We are running in BH disabled context with netif_tx_lock
  3241. * and TX reclaim runs via tp->poll inside of a software
  3242. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3243. * no IRQ context deadlocks to worry about either. Rejoice!
  3244. */
  3245. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3246. if (!netif_queue_stopped(dev)) {
  3247. netif_stop_queue(dev);
  3248. /* This is a hard error, log it. */
  3249. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3250. "queue awake!\n", dev->name);
  3251. }
  3252. return NETDEV_TX_BUSY;
  3253. }
  3254. entry = tp->tx_prod;
  3255. base_flags = 0;
  3256. #if TG3_TSO_SUPPORT != 0
  3257. mss = 0;
  3258. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3259. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3260. int tcp_opt_len, ip_tcp_len;
  3261. if (skb_header_cloned(skb) &&
  3262. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3263. dev_kfree_skb(skb);
  3264. goto out_unlock;
  3265. }
  3266. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3267. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3268. else {
  3269. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3270. ip_tcp_len = (skb->nh.iph->ihl * 4) +
  3271. sizeof(struct tcphdr);
  3272. skb->nh.iph->check = 0;
  3273. skb->nh.iph->tot_len = htons(mss + ip_tcp_len +
  3274. tcp_opt_len);
  3275. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3276. }
  3277. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3278. TXD_FLAG_CPU_POST_DMA);
  3279. skb->h.th->check = 0;
  3280. }
  3281. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3282. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3283. #else
  3284. mss = 0;
  3285. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3286. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3287. #endif
  3288. #if TG3_VLAN_TAG_USED
  3289. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3290. base_flags |= (TXD_FLAG_VLAN |
  3291. (vlan_tx_tag_get(skb) << 16));
  3292. #endif
  3293. /* Queue skb data, a.k.a. the main skb fragment. */
  3294. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3295. tp->tx_buffers[entry].skb = skb;
  3296. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3297. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3298. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3299. entry = NEXT_TX(entry);
  3300. /* Now loop through additional data fragments, and queue them. */
  3301. if (skb_shinfo(skb)->nr_frags > 0) {
  3302. unsigned int i, last;
  3303. last = skb_shinfo(skb)->nr_frags - 1;
  3304. for (i = 0; i <= last; i++) {
  3305. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3306. len = frag->size;
  3307. mapping = pci_map_page(tp->pdev,
  3308. frag->page,
  3309. frag->page_offset,
  3310. len, PCI_DMA_TODEVICE);
  3311. tp->tx_buffers[entry].skb = NULL;
  3312. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3313. tg3_set_txd(tp, entry, mapping, len,
  3314. base_flags, (i == last) | (mss << 1));
  3315. entry = NEXT_TX(entry);
  3316. }
  3317. }
  3318. /* Packets are ready, update Tx producer idx local and on card. */
  3319. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3320. tp->tx_prod = entry;
  3321. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3322. netif_stop_queue(dev);
  3323. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH)
  3324. netif_wake_queue(tp->dev);
  3325. }
  3326. out_unlock:
  3327. mmiowb();
  3328. dev->trans_start = jiffies;
  3329. return NETDEV_TX_OK;
  3330. }
  3331. #if TG3_TSO_SUPPORT != 0
  3332. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3333. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3334. * TSO header is greater than 80 bytes.
  3335. */
  3336. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3337. {
  3338. struct sk_buff *segs, *nskb;
  3339. /* Estimate the number of fragments in the worst case */
  3340. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3341. netif_stop_queue(tp->dev);
  3342. return NETDEV_TX_BUSY;
  3343. }
  3344. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3345. if (unlikely(IS_ERR(segs)))
  3346. goto tg3_tso_bug_end;
  3347. do {
  3348. nskb = segs;
  3349. segs = segs->next;
  3350. nskb->next = NULL;
  3351. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3352. } while (segs);
  3353. tg3_tso_bug_end:
  3354. dev_kfree_skb(skb);
  3355. return NETDEV_TX_OK;
  3356. }
  3357. #endif
  3358. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3359. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3360. */
  3361. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3362. {
  3363. struct tg3 *tp = netdev_priv(dev);
  3364. dma_addr_t mapping;
  3365. u32 len, entry, base_flags, mss;
  3366. int would_hit_hwbug;
  3367. len = skb_headlen(skb);
  3368. /* We are running in BH disabled context with netif_tx_lock
  3369. * and TX reclaim runs via tp->poll inside of a software
  3370. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3371. * no IRQ context deadlocks to worry about either. Rejoice!
  3372. */
  3373. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3374. if (!netif_queue_stopped(dev)) {
  3375. netif_stop_queue(dev);
  3376. /* This is a hard error, log it. */
  3377. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3378. "queue awake!\n", dev->name);
  3379. }
  3380. return NETDEV_TX_BUSY;
  3381. }
  3382. entry = tp->tx_prod;
  3383. base_flags = 0;
  3384. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3385. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3386. #if TG3_TSO_SUPPORT != 0
  3387. mss = 0;
  3388. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3389. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3390. int tcp_opt_len, ip_tcp_len, hdr_len;
  3391. if (skb_header_cloned(skb) &&
  3392. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3393. dev_kfree_skb(skb);
  3394. goto out_unlock;
  3395. }
  3396. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3397. ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
  3398. hdr_len = ip_tcp_len + tcp_opt_len;
  3399. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3400. (tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG))
  3401. return (tg3_tso_bug(tp, skb));
  3402. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3403. TXD_FLAG_CPU_POST_DMA);
  3404. skb->nh.iph->check = 0;
  3405. skb->nh.iph->tot_len = htons(mss + hdr_len);
  3406. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3407. skb->h.th->check = 0;
  3408. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3409. }
  3410. else {
  3411. skb->h.th->check =
  3412. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3413. skb->nh.iph->daddr,
  3414. 0, IPPROTO_TCP, 0);
  3415. }
  3416. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3417. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3418. if (tcp_opt_len || skb->nh.iph->ihl > 5) {
  3419. int tsflags;
  3420. tsflags = ((skb->nh.iph->ihl - 5) +
  3421. (tcp_opt_len >> 2));
  3422. mss |= (tsflags << 11);
  3423. }
  3424. } else {
  3425. if (tcp_opt_len || skb->nh.iph->ihl > 5) {
  3426. int tsflags;
  3427. tsflags = ((skb->nh.iph->ihl - 5) +
  3428. (tcp_opt_len >> 2));
  3429. base_flags |= tsflags << 12;
  3430. }
  3431. }
  3432. }
  3433. #else
  3434. mss = 0;
  3435. #endif
  3436. #if TG3_VLAN_TAG_USED
  3437. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3438. base_flags |= (TXD_FLAG_VLAN |
  3439. (vlan_tx_tag_get(skb) << 16));
  3440. #endif
  3441. /* Queue skb data, a.k.a. the main skb fragment. */
  3442. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3443. tp->tx_buffers[entry].skb = skb;
  3444. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3445. would_hit_hwbug = 0;
  3446. if (tg3_4g_overflow_test(mapping, len))
  3447. would_hit_hwbug = 1;
  3448. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3449. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3450. entry = NEXT_TX(entry);
  3451. /* Now loop through additional data fragments, and queue them. */
  3452. if (skb_shinfo(skb)->nr_frags > 0) {
  3453. unsigned int i, last;
  3454. last = skb_shinfo(skb)->nr_frags - 1;
  3455. for (i = 0; i <= last; i++) {
  3456. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3457. len = frag->size;
  3458. mapping = pci_map_page(tp->pdev,
  3459. frag->page,
  3460. frag->page_offset,
  3461. len, PCI_DMA_TODEVICE);
  3462. tp->tx_buffers[entry].skb = NULL;
  3463. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3464. if (tg3_4g_overflow_test(mapping, len))
  3465. would_hit_hwbug = 1;
  3466. if (tg3_40bit_overflow_test(tp, mapping, len))
  3467. would_hit_hwbug = 1;
  3468. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3469. tg3_set_txd(tp, entry, mapping, len,
  3470. base_flags, (i == last)|(mss << 1));
  3471. else
  3472. tg3_set_txd(tp, entry, mapping, len,
  3473. base_flags, (i == last));
  3474. entry = NEXT_TX(entry);
  3475. }
  3476. }
  3477. if (would_hit_hwbug) {
  3478. u32 last_plus_one = entry;
  3479. u32 start;
  3480. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3481. start &= (TG3_TX_RING_SIZE - 1);
  3482. /* If the workaround fails due to memory/mapping
  3483. * failure, silently drop this packet.
  3484. */
  3485. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3486. &start, base_flags, mss))
  3487. goto out_unlock;
  3488. entry = start;
  3489. }
  3490. /* Packets are ready, update Tx producer idx local and on card. */
  3491. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3492. tp->tx_prod = entry;
  3493. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3494. netif_stop_queue(dev);
  3495. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH)
  3496. netif_wake_queue(tp->dev);
  3497. }
  3498. out_unlock:
  3499. mmiowb();
  3500. dev->trans_start = jiffies;
  3501. return NETDEV_TX_OK;
  3502. }
  3503. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3504. int new_mtu)
  3505. {
  3506. dev->mtu = new_mtu;
  3507. if (new_mtu > ETH_DATA_LEN) {
  3508. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3509. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3510. ethtool_op_set_tso(dev, 0);
  3511. }
  3512. else
  3513. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3514. } else {
  3515. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3516. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3517. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3518. }
  3519. }
  3520. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3521. {
  3522. struct tg3 *tp = netdev_priv(dev);
  3523. int err;
  3524. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3525. return -EINVAL;
  3526. if (!netif_running(dev)) {
  3527. /* We'll just catch it later when the
  3528. * device is up'd.
  3529. */
  3530. tg3_set_mtu(dev, tp, new_mtu);
  3531. return 0;
  3532. }
  3533. tg3_netif_stop(tp);
  3534. tg3_full_lock(tp, 1);
  3535. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3536. tg3_set_mtu(dev, tp, new_mtu);
  3537. err = tg3_restart_hw(tp, 0);
  3538. if (!err)
  3539. tg3_netif_start(tp);
  3540. tg3_full_unlock(tp);
  3541. return err;
  3542. }
  3543. /* Free up pending packets in all rx/tx rings.
  3544. *
  3545. * The chip has been shut down and the driver detached from
  3546. * the networking, so no interrupts or new tx packets will
  3547. * end up in the driver. tp->{tx,}lock is not held and we are not
  3548. * in an interrupt context and thus may sleep.
  3549. */
  3550. static void tg3_free_rings(struct tg3 *tp)
  3551. {
  3552. struct ring_info *rxp;
  3553. int i;
  3554. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3555. rxp = &tp->rx_std_buffers[i];
  3556. if (rxp->skb == NULL)
  3557. continue;
  3558. pci_unmap_single(tp->pdev,
  3559. pci_unmap_addr(rxp, mapping),
  3560. tp->rx_pkt_buf_sz - tp->rx_offset,
  3561. PCI_DMA_FROMDEVICE);
  3562. dev_kfree_skb_any(rxp->skb);
  3563. rxp->skb = NULL;
  3564. }
  3565. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3566. rxp = &tp->rx_jumbo_buffers[i];
  3567. if (rxp->skb == NULL)
  3568. continue;
  3569. pci_unmap_single(tp->pdev,
  3570. pci_unmap_addr(rxp, mapping),
  3571. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3572. PCI_DMA_FROMDEVICE);
  3573. dev_kfree_skb_any(rxp->skb);
  3574. rxp->skb = NULL;
  3575. }
  3576. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3577. struct tx_ring_info *txp;
  3578. struct sk_buff *skb;
  3579. int j;
  3580. txp = &tp->tx_buffers[i];
  3581. skb = txp->skb;
  3582. if (skb == NULL) {
  3583. i++;
  3584. continue;
  3585. }
  3586. pci_unmap_single(tp->pdev,
  3587. pci_unmap_addr(txp, mapping),
  3588. skb_headlen(skb),
  3589. PCI_DMA_TODEVICE);
  3590. txp->skb = NULL;
  3591. i++;
  3592. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3593. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3594. pci_unmap_page(tp->pdev,
  3595. pci_unmap_addr(txp, mapping),
  3596. skb_shinfo(skb)->frags[j].size,
  3597. PCI_DMA_TODEVICE);
  3598. i++;
  3599. }
  3600. dev_kfree_skb_any(skb);
  3601. }
  3602. }
  3603. /* Initialize tx/rx rings for packet processing.
  3604. *
  3605. * The chip has been shut down and the driver detached from
  3606. * the networking, so no interrupts or new tx packets will
  3607. * end up in the driver. tp->{tx,}lock are held and thus
  3608. * we may not sleep.
  3609. */
  3610. static int tg3_init_rings(struct tg3 *tp)
  3611. {
  3612. u32 i;
  3613. /* Free up all the SKBs. */
  3614. tg3_free_rings(tp);
  3615. /* Zero out all descriptors. */
  3616. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3617. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3618. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3619. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3620. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3621. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3622. (tp->dev->mtu > ETH_DATA_LEN))
  3623. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3624. /* Initialize invariants of the rings, we only set this
  3625. * stuff once. This works because the card does not
  3626. * write into the rx buffer posting rings.
  3627. */
  3628. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3629. struct tg3_rx_buffer_desc *rxd;
  3630. rxd = &tp->rx_std[i];
  3631. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3632. << RXD_LEN_SHIFT;
  3633. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3634. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3635. (i << RXD_OPAQUE_INDEX_SHIFT));
  3636. }
  3637. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3638. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3639. struct tg3_rx_buffer_desc *rxd;
  3640. rxd = &tp->rx_jumbo[i];
  3641. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3642. << RXD_LEN_SHIFT;
  3643. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3644. RXD_FLAG_JUMBO;
  3645. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3646. (i << RXD_OPAQUE_INDEX_SHIFT));
  3647. }
  3648. }
  3649. /* Now allocate fresh SKBs for each rx ring. */
  3650. for (i = 0; i < tp->rx_pending; i++) {
  3651. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3652. printk(KERN_WARNING PFX
  3653. "%s: Using a smaller RX standard ring, "
  3654. "only %d out of %d buffers were allocated "
  3655. "successfully.\n",
  3656. tp->dev->name, i, tp->rx_pending);
  3657. if (i == 0)
  3658. return -ENOMEM;
  3659. tp->rx_pending = i;
  3660. break;
  3661. }
  3662. }
  3663. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3664. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3665. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3666. -1, i) < 0) {
  3667. printk(KERN_WARNING PFX
  3668. "%s: Using a smaller RX jumbo ring, "
  3669. "only %d out of %d buffers were "
  3670. "allocated successfully.\n",
  3671. tp->dev->name, i, tp->rx_jumbo_pending);
  3672. if (i == 0) {
  3673. tg3_free_rings(tp);
  3674. return -ENOMEM;
  3675. }
  3676. tp->rx_jumbo_pending = i;
  3677. break;
  3678. }
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. /*
  3684. * Must not be invoked with interrupt sources disabled and
  3685. * the hardware shutdown down.
  3686. */
  3687. static void tg3_free_consistent(struct tg3 *tp)
  3688. {
  3689. kfree(tp->rx_std_buffers);
  3690. tp->rx_std_buffers = NULL;
  3691. if (tp->rx_std) {
  3692. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3693. tp->rx_std, tp->rx_std_mapping);
  3694. tp->rx_std = NULL;
  3695. }
  3696. if (tp->rx_jumbo) {
  3697. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3698. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3699. tp->rx_jumbo = NULL;
  3700. }
  3701. if (tp->rx_rcb) {
  3702. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3703. tp->rx_rcb, tp->rx_rcb_mapping);
  3704. tp->rx_rcb = NULL;
  3705. }
  3706. if (tp->tx_ring) {
  3707. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3708. tp->tx_ring, tp->tx_desc_mapping);
  3709. tp->tx_ring = NULL;
  3710. }
  3711. if (tp->hw_status) {
  3712. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3713. tp->hw_status, tp->status_mapping);
  3714. tp->hw_status = NULL;
  3715. }
  3716. if (tp->hw_stats) {
  3717. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3718. tp->hw_stats, tp->stats_mapping);
  3719. tp->hw_stats = NULL;
  3720. }
  3721. }
  3722. /*
  3723. * Must not be invoked with interrupt sources disabled and
  3724. * the hardware shutdown down. Can sleep.
  3725. */
  3726. static int tg3_alloc_consistent(struct tg3 *tp)
  3727. {
  3728. tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) *
  3729. (TG3_RX_RING_SIZE +
  3730. TG3_RX_JUMBO_RING_SIZE)) +
  3731. (sizeof(struct tx_ring_info) *
  3732. TG3_TX_RING_SIZE),
  3733. GFP_KERNEL);
  3734. if (!tp->rx_std_buffers)
  3735. return -ENOMEM;
  3736. memset(tp->rx_std_buffers, 0,
  3737. (sizeof(struct ring_info) *
  3738. (TG3_RX_RING_SIZE +
  3739. TG3_RX_JUMBO_RING_SIZE)) +
  3740. (sizeof(struct tx_ring_info) *
  3741. TG3_TX_RING_SIZE));
  3742. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3743. tp->tx_buffers = (struct tx_ring_info *)
  3744. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3745. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3746. &tp->rx_std_mapping);
  3747. if (!tp->rx_std)
  3748. goto err_out;
  3749. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3750. &tp->rx_jumbo_mapping);
  3751. if (!tp->rx_jumbo)
  3752. goto err_out;
  3753. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3754. &tp->rx_rcb_mapping);
  3755. if (!tp->rx_rcb)
  3756. goto err_out;
  3757. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3758. &tp->tx_desc_mapping);
  3759. if (!tp->tx_ring)
  3760. goto err_out;
  3761. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3762. TG3_HW_STATUS_SIZE,
  3763. &tp->status_mapping);
  3764. if (!tp->hw_status)
  3765. goto err_out;
  3766. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3767. sizeof(struct tg3_hw_stats),
  3768. &tp->stats_mapping);
  3769. if (!tp->hw_stats)
  3770. goto err_out;
  3771. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3772. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3773. return 0;
  3774. err_out:
  3775. tg3_free_consistent(tp);
  3776. return -ENOMEM;
  3777. }
  3778. #define MAX_WAIT_CNT 1000
  3779. /* To stop a block, clear the enable bit and poll till it
  3780. * clears. tp->lock is held.
  3781. */
  3782. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3783. {
  3784. unsigned int i;
  3785. u32 val;
  3786. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3787. switch (ofs) {
  3788. case RCVLSC_MODE:
  3789. case DMAC_MODE:
  3790. case MBFREE_MODE:
  3791. case BUFMGR_MODE:
  3792. case MEMARB_MODE:
  3793. /* We can't enable/disable these bits of the
  3794. * 5705/5750, just say success.
  3795. */
  3796. return 0;
  3797. default:
  3798. break;
  3799. };
  3800. }
  3801. val = tr32(ofs);
  3802. val &= ~enable_bit;
  3803. tw32_f(ofs, val);
  3804. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3805. udelay(100);
  3806. val = tr32(ofs);
  3807. if ((val & enable_bit) == 0)
  3808. break;
  3809. }
  3810. if (i == MAX_WAIT_CNT && !silent) {
  3811. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3812. "ofs=%lx enable_bit=%x\n",
  3813. ofs, enable_bit);
  3814. return -ENODEV;
  3815. }
  3816. return 0;
  3817. }
  3818. /* tp->lock is held. */
  3819. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3820. {
  3821. int i, err;
  3822. tg3_disable_ints(tp);
  3823. tp->rx_mode &= ~RX_MODE_ENABLE;
  3824. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3825. udelay(10);
  3826. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3827. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3828. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3829. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3830. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3831. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3832. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3833. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3834. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3835. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3836. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3837. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3838. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3839. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3840. tw32_f(MAC_MODE, tp->mac_mode);
  3841. udelay(40);
  3842. tp->tx_mode &= ~TX_MODE_ENABLE;
  3843. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3844. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3845. udelay(100);
  3846. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3847. break;
  3848. }
  3849. if (i >= MAX_WAIT_CNT) {
  3850. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3851. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3852. tp->dev->name, tr32(MAC_TX_MODE));
  3853. err |= -ENODEV;
  3854. }
  3855. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3856. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3857. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3858. tw32(FTQ_RESET, 0xffffffff);
  3859. tw32(FTQ_RESET, 0x00000000);
  3860. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3861. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3862. if (tp->hw_status)
  3863. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3864. if (tp->hw_stats)
  3865. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3866. return err;
  3867. }
  3868. /* tp->lock is held. */
  3869. static int tg3_nvram_lock(struct tg3 *tp)
  3870. {
  3871. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3872. int i;
  3873. if (tp->nvram_lock_cnt == 0) {
  3874. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3875. for (i = 0; i < 8000; i++) {
  3876. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3877. break;
  3878. udelay(20);
  3879. }
  3880. if (i == 8000) {
  3881. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3882. return -ENODEV;
  3883. }
  3884. }
  3885. tp->nvram_lock_cnt++;
  3886. }
  3887. return 0;
  3888. }
  3889. /* tp->lock is held. */
  3890. static void tg3_nvram_unlock(struct tg3 *tp)
  3891. {
  3892. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3893. if (tp->nvram_lock_cnt > 0)
  3894. tp->nvram_lock_cnt--;
  3895. if (tp->nvram_lock_cnt == 0)
  3896. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3897. }
  3898. }
  3899. /* tp->lock is held. */
  3900. static void tg3_enable_nvram_access(struct tg3 *tp)
  3901. {
  3902. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3903. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3904. u32 nvaccess = tr32(NVRAM_ACCESS);
  3905. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3906. }
  3907. }
  3908. /* tp->lock is held. */
  3909. static void tg3_disable_nvram_access(struct tg3 *tp)
  3910. {
  3911. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3912. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3913. u32 nvaccess = tr32(NVRAM_ACCESS);
  3914. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3915. }
  3916. }
  3917. /* tp->lock is held. */
  3918. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3919. {
  3920. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3921. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3922. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3923. switch (kind) {
  3924. case RESET_KIND_INIT:
  3925. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3926. DRV_STATE_START);
  3927. break;
  3928. case RESET_KIND_SHUTDOWN:
  3929. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3930. DRV_STATE_UNLOAD);
  3931. break;
  3932. case RESET_KIND_SUSPEND:
  3933. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3934. DRV_STATE_SUSPEND);
  3935. break;
  3936. default:
  3937. break;
  3938. };
  3939. }
  3940. }
  3941. /* tp->lock is held. */
  3942. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  3943. {
  3944. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3945. switch (kind) {
  3946. case RESET_KIND_INIT:
  3947. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3948. DRV_STATE_START_DONE);
  3949. break;
  3950. case RESET_KIND_SHUTDOWN:
  3951. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3952. DRV_STATE_UNLOAD_DONE);
  3953. break;
  3954. default:
  3955. break;
  3956. };
  3957. }
  3958. }
  3959. /* tp->lock is held. */
  3960. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  3961. {
  3962. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  3963. switch (kind) {
  3964. case RESET_KIND_INIT:
  3965. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3966. DRV_STATE_START);
  3967. break;
  3968. case RESET_KIND_SHUTDOWN:
  3969. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3970. DRV_STATE_UNLOAD);
  3971. break;
  3972. case RESET_KIND_SUSPEND:
  3973. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3974. DRV_STATE_SUSPEND);
  3975. break;
  3976. default:
  3977. break;
  3978. };
  3979. }
  3980. }
  3981. static int tg3_poll_fw(struct tg3 *tp)
  3982. {
  3983. int i;
  3984. u32 val;
  3985. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  3986. for (i = 0; i < 400; i++) {
  3987. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  3988. return 0;
  3989. udelay(10);
  3990. }
  3991. return -ENODEV;
  3992. }
  3993. /* Wait for firmware initialization to complete. */
  3994. for (i = 0; i < 100000; i++) {
  3995. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  3996. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  3997. break;
  3998. udelay(10);
  3999. }
  4000. /* Chip might not be fitted with firmware. Some Sun onboard
  4001. * parts are configured like that. So don't signal the timeout
  4002. * of the above loop as an error, but do report the lack of
  4003. * running firmware once.
  4004. */
  4005. if (i >= 100000 &&
  4006. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4007. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4008. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4009. tp->dev->name);
  4010. }
  4011. return 0;
  4012. }
  4013. static void tg3_stop_fw(struct tg3 *);
  4014. /* tp->lock is held. */
  4015. static int tg3_chip_reset(struct tg3 *tp)
  4016. {
  4017. u32 val;
  4018. void (*write_op)(struct tg3 *, u32, u32);
  4019. int err;
  4020. tg3_nvram_lock(tp);
  4021. /* No matching tg3_nvram_unlock() after this because
  4022. * chip reset below will undo the nvram lock.
  4023. */
  4024. tp->nvram_lock_cnt = 0;
  4025. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4026. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4027. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  4028. tw32(GRC_FASTBOOT_PC, 0);
  4029. /*
  4030. * We must avoid the readl() that normally takes place.
  4031. * It locks machines, causes machine checks, and other
  4032. * fun things. So, temporarily disable the 5701
  4033. * hardware workaround, while we do the reset.
  4034. */
  4035. write_op = tp->write32;
  4036. if (write_op == tg3_write_flush_reg32)
  4037. tp->write32 = tg3_write32;
  4038. /* do the reset */
  4039. val = GRC_MISC_CFG_CORECLK_RESET;
  4040. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4041. if (tr32(0x7e2c) == 0x60) {
  4042. tw32(0x7e2c, 0x20);
  4043. }
  4044. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4045. tw32(GRC_MISC_CFG, (1 << 29));
  4046. val |= (1 << 29);
  4047. }
  4048. }
  4049. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4050. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4051. tw32(GRC_VCPU_EXT_CTRL,
  4052. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4053. }
  4054. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4055. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4056. tw32(GRC_MISC_CFG, val);
  4057. /* restore 5701 hardware bug workaround write method */
  4058. tp->write32 = write_op;
  4059. /* Unfortunately, we have to delay before the PCI read back.
  4060. * Some 575X chips even will not respond to a PCI cfg access
  4061. * when the reset command is given to the chip.
  4062. *
  4063. * How do these hardware designers expect things to work
  4064. * properly if the PCI write is posted for a long period
  4065. * of time? It is always necessary to have some method by
  4066. * which a register read back can occur to push the write
  4067. * out which does the reset.
  4068. *
  4069. * For most tg3 variants the trick below was working.
  4070. * Ho hum...
  4071. */
  4072. udelay(120);
  4073. /* Flush PCI posted writes. The normal MMIO registers
  4074. * are inaccessible at this time so this is the only
  4075. * way to make this reliably (actually, this is no longer
  4076. * the case, see above). I tried to use indirect
  4077. * register read/write but this upset some 5701 variants.
  4078. */
  4079. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4080. udelay(120);
  4081. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4082. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4083. int i;
  4084. u32 cfg_val;
  4085. /* Wait for link training to complete. */
  4086. for (i = 0; i < 5000; i++)
  4087. udelay(100);
  4088. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4089. pci_write_config_dword(tp->pdev, 0xc4,
  4090. cfg_val | (1 << 15));
  4091. }
  4092. /* Set PCIE max payload size and clear error status. */
  4093. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4094. }
  4095. /* Re-enable indirect register accesses. */
  4096. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4097. tp->misc_host_ctrl);
  4098. /* Set MAX PCI retry to zero. */
  4099. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4100. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4101. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4102. val |= PCISTATE_RETRY_SAME_DMA;
  4103. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4104. pci_restore_state(tp->pdev);
  4105. /* Make sure PCI-X relaxed ordering bit is clear. */
  4106. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4107. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4108. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4109. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4110. u32 val;
  4111. /* Chip reset on 5780 will reset MSI enable bit,
  4112. * so need to restore it.
  4113. */
  4114. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4115. u16 ctrl;
  4116. pci_read_config_word(tp->pdev,
  4117. tp->msi_cap + PCI_MSI_FLAGS,
  4118. &ctrl);
  4119. pci_write_config_word(tp->pdev,
  4120. tp->msi_cap + PCI_MSI_FLAGS,
  4121. ctrl | PCI_MSI_FLAGS_ENABLE);
  4122. val = tr32(MSGINT_MODE);
  4123. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4124. }
  4125. val = tr32(MEMARB_MODE);
  4126. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4127. } else
  4128. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4129. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4130. tg3_stop_fw(tp);
  4131. tw32(0x5000, 0x400);
  4132. }
  4133. tw32(GRC_MODE, tp->grc_mode);
  4134. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4135. u32 val = tr32(0xc4);
  4136. tw32(0xc4, val | (1 << 15));
  4137. }
  4138. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4139. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4140. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4141. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4142. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4143. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4144. }
  4145. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4146. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4147. tw32_f(MAC_MODE, tp->mac_mode);
  4148. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4149. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4150. tw32_f(MAC_MODE, tp->mac_mode);
  4151. } else
  4152. tw32_f(MAC_MODE, 0);
  4153. udelay(40);
  4154. err = tg3_poll_fw(tp);
  4155. if (err)
  4156. return err;
  4157. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4158. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4159. u32 val = tr32(0x7c00);
  4160. tw32(0x7c00, val | (1 << 25));
  4161. }
  4162. /* Reprobe ASF enable state. */
  4163. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4164. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4165. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4166. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4167. u32 nic_cfg;
  4168. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4169. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4170. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4171. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4172. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4173. }
  4174. }
  4175. return 0;
  4176. }
  4177. /* tp->lock is held. */
  4178. static void tg3_stop_fw(struct tg3 *tp)
  4179. {
  4180. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4181. u32 val;
  4182. int i;
  4183. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4184. val = tr32(GRC_RX_CPU_EVENT);
  4185. val |= (1 << 14);
  4186. tw32(GRC_RX_CPU_EVENT, val);
  4187. /* Wait for RX cpu to ACK the event. */
  4188. for (i = 0; i < 100; i++) {
  4189. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4190. break;
  4191. udelay(1);
  4192. }
  4193. }
  4194. }
  4195. /* tp->lock is held. */
  4196. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4197. {
  4198. int err;
  4199. tg3_stop_fw(tp);
  4200. tg3_write_sig_pre_reset(tp, kind);
  4201. tg3_abort_hw(tp, silent);
  4202. err = tg3_chip_reset(tp);
  4203. tg3_write_sig_legacy(tp, kind);
  4204. tg3_write_sig_post_reset(tp, kind);
  4205. if (err)
  4206. return err;
  4207. return 0;
  4208. }
  4209. #define TG3_FW_RELEASE_MAJOR 0x0
  4210. #define TG3_FW_RELASE_MINOR 0x0
  4211. #define TG3_FW_RELEASE_FIX 0x0
  4212. #define TG3_FW_START_ADDR 0x08000000
  4213. #define TG3_FW_TEXT_ADDR 0x08000000
  4214. #define TG3_FW_TEXT_LEN 0x9c0
  4215. #define TG3_FW_RODATA_ADDR 0x080009c0
  4216. #define TG3_FW_RODATA_LEN 0x60
  4217. #define TG3_FW_DATA_ADDR 0x08000a40
  4218. #define TG3_FW_DATA_LEN 0x20
  4219. #define TG3_FW_SBSS_ADDR 0x08000a60
  4220. #define TG3_FW_SBSS_LEN 0xc
  4221. #define TG3_FW_BSS_ADDR 0x08000a70
  4222. #define TG3_FW_BSS_LEN 0x10
  4223. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4224. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4225. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4226. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4227. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4228. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4229. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4230. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4231. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4232. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4233. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4234. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4235. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4236. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4237. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4238. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4239. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4240. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4241. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4242. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4243. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4244. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4245. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4246. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4249. 0, 0, 0, 0, 0, 0,
  4250. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4251. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4252. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4253. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4254. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4255. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4256. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4257. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4258. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4259. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4260. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4264. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4265. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4266. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4267. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4268. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4269. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4270. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4271. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4272. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4273. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4274. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4275. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4276. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4277. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4278. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4279. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4280. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4281. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4282. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4283. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4284. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4285. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4286. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4287. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4288. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4289. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4290. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4291. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4292. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4293. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4294. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4295. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4296. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4297. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4298. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4299. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4300. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4301. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4302. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4303. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4304. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4305. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4306. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4307. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4308. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4309. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4310. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4311. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4312. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4313. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4314. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4315. };
  4316. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4317. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4318. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4319. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4320. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4321. 0x00000000
  4322. };
  4323. #if 0 /* All zeros, don't eat up space with it. */
  4324. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4325. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4326. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4327. };
  4328. #endif
  4329. #define RX_CPU_SCRATCH_BASE 0x30000
  4330. #define RX_CPU_SCRATCH_SIZE 0x04000
  4331. #define TX_CPU_SCRATCH_BASE 0x34000
  4332. #define TX_CPU_SCRATCH_SIZE 0x04000
  4333. /* tp->lock is held. */
  4334. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4335. {
  4336. int i;
  4337. BUG_ON(offset == TX_CPU_BASE &&
  4338. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4339. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4340. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4341. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4342. return 0;
  4343. }
  4344. if (offset == RX_CPU_BASE) {
  4345. for (i = 0; i < 10000; i++) {
  4346. tw32(offset + CPU_STATE, 0xffffffff);
  4347. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4348. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4349. break;
  4350. }
  4351. tw32(offset + CPU_STATE, 0xffffffff);
  4352. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4353. udelay(10);
  4354. } else {
  4355. for (i = 0; i < 10000; i++) {
  4356. tw32(offset + CPU_STATE, 0xffffffff);
  4357. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4358. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4359. break;
  4360. }
  4361. }
  4362. if (i >= 10000) {
  4363. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4364. "and %s CPU\n",
  4365. tp->dev->name,
  4366. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4367. return -ENODEV;
  4368. }
  4369. /* Clear firmware's nvram arbitration. */
  4370. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4371. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4372. return 0;
  4373. }
  4374. struct fw_info {
  4375. unsigned int text_base;
  4376. unsigned int text_len;
  4377. const u32 *text_data;
  4378. unsigned int rodata_base;
  4379. unsigned int rodata_len;
  4380. const u32 *rodata_data;
  4381. unsigned int data_base;
  4382. unsigned int data_len;
  4383. const u32 *data_data;
  4384. };
  4385. /* tp->lock is held. */
  4386. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4387. int cpu_scratch_size, struct fw_info *info)
  4388. {
  4389. int err, lock_err, i;
  4390. void (*write_op)(struct tg3 *, u32, u32);
  4391. if (cpu_base == TX_CPU_BASE &&
  4392. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4393. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4394. "TX cpu firmware on %s which is 5705.\n",
  4395. tp->dev->name);
  4396. return -EINVAL;
  4397. }
  4398. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4399. write_op = tg3_write_mem;
  4400. else
  4401. write_op = tg3_write_indirect_reg32;
  4402. /* It is possible that bootcode is still loading at this point.
  4403. * Get the nvram lock first before halting the cpu.
  4404. */
  4405. lock_err = tg3_nvram_lock(tp);
  4406. err = tg3_halt_cpu(tp, cpu_base);
  4407. if (!lock_err)
  4408. tg3_nvram_unlock(tp);
  4409. if (err)
  4410. goto out;
  4411. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4412. write_op(tp, cpu_scratch_base + i, 0);
  4413. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4414. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4415. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4416. write_op(tp, (cpu_scratch_base +
  4417. (info->text_base & 0xffff) +
  4418. (i * sizeof(u32))),
  4419. (info->text_data ?
  4420. info->text_data[i] : 0));
  4421. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4422. write_op(tp, (cpu_scratch_base +
  4423. (info->rodata_base & 0xffff) +
  4424. (i * sizeof(u32))),
  4425. (info->rodata_data ?
  4426. info->rodata_data[i] : 0));
  4427. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4428. write_op(tp, (cpu_scratch_base +
  4429. (info->data_base & 0xffff) +
  4430. (i * sizeof(u32))),
  4431. (info->data_data ?
  4432. info->data_data[i] : 0));
  4433. err = 0;
  4434. out:
  4435. return err;
  4436. }
  4437. /* tp->lock is held. */
  4438. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4439. {
  4440. struct fw_info info;
  4441. int err, i;
  4442. info.text_base = TG3_FW_TEXT_ADDR;
  4443. info.text_len = TG3_FW_TEXT_LEN;
  4444. info.text_data = &tg3FwText[0];
  4445. info.rodata_base = TG3_FW_RODATA_ADDR;
  4446. info.rodata_len = TG3_FW_RODATA_LEN;
  4447. info.rodata_data = &tg3FwRodata[0];
  4448. info.data_base = TG3_FW_DATA_ADDR;
  4449. info.data_len = TG3_FW_DATA_LEN;
  4450. info.data_data = NULL;
  4451. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4452. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4453. &info);
  4454. if (err)
  4455. return err;
  4456. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4457. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4458. &info);
  4459. if (err)
  4460. return err;
  4461. /* Now startup only the RX cpu. */
  4462. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4463. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4464. for (i = 0; i < 5; i++) {
  4465. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4466. break;
  4467. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4468. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4469. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4470. udelay(1000);
  4471. }
  4472. if (i >= 5) {
  4473. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4474. "to set RX CPU PC, is %08x should be %08x\n",
  4475. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4476. TG3_FW_TEXT_ADDR);
  4477. return -ENODEV;
  4478. }
  4479. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4480. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4481. return 0;
  4482. }
  4483. #if TG3_TSO_SUPPORT != 0
  4484. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4485. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4486. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4487. #define TG3_TSO_FW_START_ADDR 0x08000000
  4488. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4489. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4490. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4491. #define TG3_TSO_FW_RODATA_LEN 0x60
  4492. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4493. #define TG3_TSO_FW_DATA_LEN 0x30
  4494. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4495. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4496. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4497. #define TG3_TSO_FW_BSS_LEN 0x894
  4498. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4499. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4500. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4501. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4502. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4503. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4504. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4505. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4506. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4507. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4508. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4509. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4510. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4511. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4512. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4513. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4514. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4515. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4516. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4517. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4518. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4519. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4520. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4521. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4522. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4523. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4524. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4525. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4526. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4527. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4528. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4529. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4530. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4531. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4532. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4533. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4534. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4535. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4536. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4537. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4538. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4539. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4540. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4541. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4542. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4543. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4544. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4545. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4546. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4547. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4548. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4549. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4550. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4551. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4552. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4553. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4554. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4555. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4556. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4557. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4558. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4559. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4560. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4561. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4562. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4563. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4564. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4565. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4566. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4567. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4568. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4569. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4570. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4571. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4572. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4573. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4574. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4575. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4576. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4577. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4578. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4579. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4580. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4581. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4582. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4583. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4584. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4585. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4586. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4587. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4588. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4589. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4590. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4591. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4592. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4593. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4594. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4595. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4596. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4597. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4598. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4599. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4600. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4601. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4602. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4603. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4604. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4605. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4606. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4607. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4608. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4609. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4610. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4611. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4612. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4613. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4614. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4615. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4616. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4617. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4618. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4619. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4620. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4621. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4622. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4623. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4624. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4625. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4626. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4627. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4628. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4629. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4630. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4631. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4632. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4633. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4634. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4635. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4636. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4637. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4638. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4639. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4640. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4641. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4642. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4643. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4644. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4645. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4646. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4647. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4648. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4649. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4650. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4651. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4652. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4653. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4654. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4655. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4656. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4657. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4658. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4659. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4660. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4661. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4662. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4663. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4664. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4665. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4666. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4667. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4668. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4669. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4670. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4671. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4672. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4673. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4674. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4675. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4676. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4677. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4678. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4679. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4680. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4681. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4682. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4683. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4684. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4685. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4686. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4687. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4688. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4689. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4690. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4691. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4692. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4693. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4694. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4695. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4696. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4697. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4698. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4699. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4700. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4701. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4702. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4703. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4704. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4705. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4706. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4707. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4708. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4709. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4710. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4711. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4712. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4713. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4714. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4715. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4716. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4717. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4718. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4719. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4720. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4721. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4722. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4723. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4724. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4725. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4726. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4727. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4728. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4729. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4730. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4731. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4732. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4733. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4734. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4735. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4736. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4737. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4738. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4739. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4740. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4741. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4742. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4743. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4744. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4745. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4746. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4747. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4748. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4749. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4750. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4751. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4752. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4753. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4754. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4755. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4756. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4757. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4758. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4759. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4760. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4761. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4762. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4763. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4764. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4765. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4766. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4767. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4768. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4769. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4770. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4771. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4772. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4773. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4774. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4775. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4776. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4777. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4778. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4779. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4780. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4781. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4782. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4783. };
  4784. static const u32 tg3TsoFwRodata[] = {
  4785. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4786. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4787. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4788. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4789. 0x00000000,
  4790. };
  4791. static const u32 tg3TsoFwData[] = {
  4792. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4793. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4794. 0x00000000,
  4795. };
  4796. /* 5705 needs a special version of the TSO firmware. */
  4797. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4798. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4799. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4800. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4801. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4802. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4803. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4804. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4805. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4806. #define TG3_TSO5_FW_DATA_LEN 0x20
  4807. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4808. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4809. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4810. #define TG3_TSO5_FW_BSS_LEN 0x88
  4811. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4812. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4813. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4814. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4815. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4816. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4817. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4818. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4819. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4820. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4821. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4822. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4823. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4824. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4825. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4826. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4827. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4828. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4829. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4830. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4831. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4832. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4833. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4834. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4835. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4836. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4837. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4838. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4839. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4840. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4841. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4842. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4843. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4844. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4845. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4846. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4847. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4848. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4849. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4850. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4851. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4852. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4853. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4854. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4855. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4856. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4857. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4858. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4859. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4860. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4861. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4862. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4863. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4864. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4865. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4866. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4867. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4868. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4869. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4870. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4871. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4872. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4873. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4874. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4875. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4876. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4877. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4878. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4879. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4880. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4881. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4882. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4883. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4884. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4885. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4886. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4887. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4888. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4889. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4890. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4891. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4892. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4893. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4894. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4895. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4896. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4897. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4898. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4899. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4900. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4901. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4902. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4903. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4904. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4905. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4906. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4907. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4908. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4909. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4910. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  4911. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  4912. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  4913. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  4914. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  4915. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  4916. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  4917. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  4918. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4919. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4920. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  4921. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  4922. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  4923. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  4924. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  4925. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  4926. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  4927. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  4928. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  4929. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4930. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4931. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  4932. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  4933. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  4934. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  4935. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4936. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  4937. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  4938. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  4939. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  4940. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  4941. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  4942. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  4943. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  4944. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  4945. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  4946. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  4947. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  4948. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  4949. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  4950. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  4951. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  4952. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  4953. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  4954. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  4955. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  4956. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  4957. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  4958. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  4959. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4960. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  4961. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  4962. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  4963. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4964. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  4965. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  4966. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4967. 0x00000000, 0x00000000, 0x00000000,
  4968. };
  4969. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  4970. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4971. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  4972. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4973. 0x00000000, 0x00000000, 0x00000000,
  4974. };
  4975. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  4976. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  4977. 0x00000000, 0x00000000, 0x00000000,
  4978. };
  4979. /* tp->lock is held. */
  4980. static int tg3_load_tso_firmware(struct tg3 *tp)
  4981. {
  4982. struct fw_info info;
  4983. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  4984. int err, i;
  4985. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  4986. return 0;
  4987. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4988. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  4989. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  4990. info.text_data = &tg3Tso5FwText[0];
  4991. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  4992. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  4993. info.rodata_data = &tg3Tso5FwRodata[0];
  4994. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  4995. info.data_len = TG3_TSO5_FW_DATA_LEN;
  4996. info.data_data = &tg3Tso5FwData[0];
  4997. cpu_base = RX_CPU_BASE;
  4998. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  4999. cpu_scratch_size = (info.text_len +
  5000. info.rodata_len +
  5001. info.data_len +
  5002. TG3_TSO5_FW_SBSS_LEN +
  5003. TG3_TSO5_FW_BSS_LEN);
  5004. } else {
  5005. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5006. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5007. info.text_data = &tg3TsoFwText[0];
  5008. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5009. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5010. info.rodata_data = &tg3TsoFwRodata[0];
  5011. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5012. info.data_len = TG3_TSO_FW_DATA_LEN;
  5013. info.data_data = &tg3TsoFwData[0];
  5014. cpu_base = TX_CPU_BASE;
  5015. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5016. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5017. }
  5018. err = tg3_load_firmware_cpu(tp, cpu_base,
  5019. cpu_scratch_base, cpu_scratch_size,
  5020. &info);
  5021. if (err)
  5022. return err;
  5023. /* Now startup the cpu. */
  5024. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5025. tw32_f(cpu_base + CPU_PC, info.text_base);
  5026. for (i = 0; i < 5; i++) {
  5027. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5028. break;
  5029. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5030. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5031. tw32_f(cpu_base + CPU_PC, info.text_base);
  5032. udelay(1000);
  5033. }
  5034. if (i >= 5) {
  5035. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5036. "to set CPU PC, is %08x should be %08x\n",
  5037. tp->dev->name, tr32(cpu_base + CPU_PC),
  5038. info.text_base);
  5039. return -ENODEV;
  5040. }
  5041. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5042. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5043. return 0;
  5044. }
  5045. #endif /* TG3_TSO_SUPPORT != 0 */
  5046. /* tp->lock is held. */
  5047. static void __tg3_set_mac_addr(struct tg3 *tp)
  5048. {
  5049. u32 addr_high, addr_low;
  5050. int i;
  5051. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5052. tp->dev->dev_addr[1]);
  5053. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5054. (tp->dev->dev_addr[3] << 16) |
  5055. (tp->dev->dev_addr[4] << 8) |
  5056. (tp->dev->dev_addr[5] << 0));
  5057. for (i = 0; i < 4; i++) {
  5058. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5059. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5060. }
  5061. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5062. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5063. for (i = 0; i < 12; i++) {
  5064. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5065. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5066. }
  5067. }
  5068. addr_high = (tp->dev->dev_addr[0] +
  5069. tp->dev->dev_addr[1] +
  5070. tp->dev->dev_addr[2] +
  5071. tp->dev->dev_addr[3] +
  5072. tp->dev->dev_addr[4] +
  5073. tp->dev->dev_addr[5]) &
  5074. TX_BACKOFF_SEED_MASK;
  5075. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5076. }
  5077. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5078. {
  5079. struct tg3 *tp = netdev_priv(dev);
  5080. struct sockaddr *addr = p;
  5081. int err = 0;
  5082. if (!is_valid_ether_addr(addr->sa_data))
  5083. return -EINVAL;
  5084. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5085. if (!netif_running(dev))
  5086. return 0;
  5087. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5088. /* Reset chip so that ASF can re-init any MAC addresses it
  5089. * needs.
  5090. */
  5091. tg3_netif_stop(tp);
  5092. tg3_full_lock(tp, 1);
  5093. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5094. err = tg3_restart_hw(tp, 0);
  5095. if (!err)
  5096. tg3_netif_start(tp);
  5097. tg3_full_unlock(tp);
  5098. } else {
  5099. spin_lock_bh(&tp->lock);
  5100. __tg3_set_mac_addr(tp);
  5101. spin_unlock_bh(&tp->lock);
  5102. }
  5103. return err;
  5104. }
  5105. /* tp->lock is held. */
  5106. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5107. dma_addr_t mapping, u32 maxlen_flags,
  5108. u32 nic_addr)
  5109. {
  5110. tg3_write_mem(tp,
  5111. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5112. ((u64) mapping >> 32));
  5113. tg3_write_mem(tp,
  5114. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5115. ((u64) mapping & 0xffffffff));
  5116. tg3_write_mem(tp,
  5117. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5118. maxlen_flags);
  5119. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5120. tg3_write_mem(tp,
  5121. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5122. nic_addr);
  5123. }
  5124. static void __tg3_set_rx_mode(struct net_device *);
  5125. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5126. {
  5127. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5128. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5129. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5130. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5131. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5132. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5133. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5134. }
  5135. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5136. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5137. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5138. u32 val = ec->stats_block_coalesce_usecs;
  5139. if (!netif_carrier_ok(tp->dev))
  5140. val = 0;
  5141. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5142. }
  5143. }
  5144. /* tp->lock is held. */
  5145. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5146. {
  5147. u32 val, rdmac_mode;
  5148. int i, err, limit;
  5149. tg3_disable_ints(tp);
  5150. tg3_stop_fw(tp);
  5151. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5152. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5153. tg3_abort_hw(tp, 1);
  5154. }
  5155. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) && reset_phy)
  5156. tg3_phy_reset(tp);
  5157. err = tg3_chip_reset(tp);
  5158. if (err)
  5159. return err;
  5160. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5161. /* This works around an issue with Athlon chipsets on
  5162. * B3 tigon3 silicon. This bit has no effect on any
  5163. * other revision. But do not set this on PCI Express
  5164. * chips.
  5165. */
  5166. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5167. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5168. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5169. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5170. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5171. val = tr32(TG3PCI_PCISTATE);
  5172. val |= PCISTATE_RETRY_SAME_DMA;
  5173. tw32(TG3PCI_PCISTATE, val);
  5174. }
  5175. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5176. /* Enable some hw fixes. */
  5177. val = tr32(TG3PCI_MSI_DATA);
  5178. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5179. tw32(TG3PCI_MSI_DATA, val);
  5180. }
  5181. /* Descriptor ring init may make accesses to the
  5182. * NIC SRAM area to setup the TX descriptors, so we
  5183. * can only do this after the hardware has been
  5184. * successfully reset.
  5185. */
  5186. err = tg3_init_rings(tp);
  5187. if (err)
  5188. return err;
  5189. /* This value is determined during the probe time DMA
  5190. * engine test, tg3_test_dma.
  5191. */
  5192. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5193. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5194. GRC_MODE_4X_NIC_SEND_RINGS |
  5195. GRC_MODE_NO_TX_PHDR_CSUM |
  5196. GRC_MODE_NO_RX_PHDR_CSUM);
  5197. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5198. /* Pseudo-header checksum is done by hardware logic and not
  5199. * the offload processers, so make the chip do the pseudo-
  5200. * header checksums on receive. For transmit it is more
  5201. * convenient to do the pseudo-header checksum in software
  5202. * as Linux does that on transmit for us in all cases.
  5203. */
  5204. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5205. tw32(GRC_MODE,
  5206. tp->grc_mode |
  5207. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5208. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5209. val = tr32(GRC_MISC_CFG);
  5210. val &= ~0xff;
  5211. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5212. tw32(GRC_MISC_CFG, val);
  5213. /* Initialize MBUF/DESC pool. */
  5214. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5215. /* Do nothing. */
  5216. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5217. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5218. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5219. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5220. else
  5221. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5222. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5223. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5224. }
  5225. #if TG3_TSO_SUPPORT != 0
  5226. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5227. int fw_len;
  5228. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5229. TG3_TSO5_FW_RODATA_LEN +
  5230. TG3_TSO5_FW_DATA_LEN +
  5231. TG3_TSO5_FW_SBSS_LEN +
  5232. TG3_TSO5_FW_BSS_LEN);
  5233. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5234. tw32(BUFMGR_MB_POOL_ADDR,
  5235. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5236. tw32(BUFMGR_MB_POOL_SIZE,
  5237. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5238. }
  5239. #endif
  5240. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5241. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5242. tp->bufmgr_config.mbuf_read_dma_low_water);
  5243. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5244. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5245. tw32(BUFMGR_MB_HIGH_WATER,
  5246. tp->bufmgr_config.mbuf_high_water);
  5247. } else {
  5248. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5249. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5250. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5251. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5252. tw32(BUFMGR_MB_HIGH_WATER,
  5253. tp->bufmgr_config.mbuf_high_water_jumbo);
  5254. }
  5255. tw32(BUFMGR_DMA_LOW_WATER,
  5256. tp->bufmgr_config.dma_low_water);
  5257. tw32(BUFMGR_DMA_HIGH_WATER,
  5258. tp->bufmgr_config.dma_high_water);
  5259. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5260. for (i = 0; i < 2000; i++) {
  5261. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5262. break;
  5263. udelay(10);
  5264. }
  5265. if (i >= 2000) {
  5266. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5267. tp->dev->name);
  5268. return -ENODEV;
  5269. }
  5270. /* Setup replenish threshold. */
  5271. val = tp->rx_pending / 8;
  5272. if (val == 0)
  5273. val = 1;
  5274. else if (val > tp->rx_std_max_post)
  5275. val = tp->rx_std_max_post;
  5276. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5277. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5278. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5279. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5280. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5281. }
  5282. tw32(RCVBDI_STD_THRESH, val);
  5283. /* Initialize TG3_BDINFO's at:
  5284. * RCVDBDI_STD_BD: standard eth size rx ring
  5285. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5286. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5287. *
  5288. * like so:
  5289. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5290. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5291. * ring attribute flags
  5292. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5293. *
  5294. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5295. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5296. *
  5297. * The size of each ring is fixed in the firmware, but the location is
  5298. * configurable.
  5299. */
  5300. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5301. ((u64) tp->rx_std_mapping >> 32));
  5302. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5303. ((u64) tp->rx_std_mapping & 0xffffffff));
  5304. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5305. NIC_SRAM_RX_BUFFER_DESC);
  5306. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5307. * configs on 5705.
  5308. */
  5309. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5310. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5311. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5312. } else {
  5313. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5314. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5315. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5316. BDINFO_FLAGS_DISABLED);
  5317. /* Setup replenish threshold. */
  5318. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5319. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5320. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5321. ((u64) tp->rx_jumbo_mapping >> 32));
  5322. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5323. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5324. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5325. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5326. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5327. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5328. } else {
  5329. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5330. BDINFO_FLAGS_DISABLED);
  5331. }
  5332. }
  5333. /* There is only one send ring on 5705/5750, no need to explicitly
  5334. * disable the others.
  5335. */
  5336. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5337. /* Clear out send RCB ring in SRAM. */
  5338. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5339. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5340. BDINFO_FLAGS_DISABLED);
  5341. }
  5342. tp->tx_prod = 0;
  5343. tp->tx_cons = 0;
  5344. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5345. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5346. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5347. tp->tx_desc_mapping,
  5348. (TG3_TX_RING_SIZE <<
  5349. BDINFO_FLAGS_MAXLEN_SHIFT),
  5350. NIC_SRAM_TX_BUFFER_DESC);
  5351. /* There is only one receive return ring on 5705/5750, no need
  5352. * to explicitly disable the others.
  5353. */
  5354. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5355. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5356. i += TG3_BDINFO_SIZE) {
  5357. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5358. BDINFO_FLAGS_DISABLED);
  5359. }
  5360. }
  5361. tp->rx_rcb_ptr = 0;
  5362. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5363. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5364. tp->rx_rcb_mapping,
  5365. (TG3_RX_RCB_RING_SIZE(tp) <<
  5366. BDINFO_FLAGS_MAXLEN_SHIFT),
  5367. 0);
  5368. tp->rx_std_ptr = tp->rx_pending;
  5369. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5370. tp->rx_std_ptr);
  5371. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5372. tp->rx_jumbo_pending : 0;
  5373. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5374. tp->rx_jumbo_ptr);
  5375. /* Initialize MAC address and backoff seed. */
  5376. __tg3_set_mac_addr(tp);
  5377. /* MTU + ethernet header + FCS + optional VLAN tag */
  5378. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5379. /* The slot time is changed by tg3_setup_phy if we
  5380. * run at gigabit with half duplex.
  5381. */
  5382. tw32(MAC_TX_LENGTHS,
  5383. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5384. (6 << TX_LENGTHS_IPG_SHIFT) |
  5385. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5386. /* Receive rules. */
  5387. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5388. tw32(RCVLPC_CONFIG, 0x0181);
  5389. /* Calculate RDMAC_MODE setting early, we need it to determine
  5390. * the RCVLPC_STATE_ENABLE mask.
  5391. */
  5392. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5393. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5394. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5395. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5396. RDMAC_MODE_LNGREAD_ENAB);
  5397. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  5398. rdmac_mode |= RDMAC_MODE_SPLIT_ENABLE;
  5399. /* If statement applies to 5705 and 5750 PCI devices only */
  5400. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5401. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5402. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5403. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5404. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5405. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5406. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5407. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5408. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5409. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5410. }
  5411. }
  5412. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5413. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5414. #if TG3_TSO_SUPPORT != 0
  5415. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5416. rdmac_mode |= (1 << 27);
  5417. #endif
  5418. /* Receive/send statistics. */
  5419. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5420. val = tr32(RCVLPC_STATS_ENABLE);
  5421. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5422. tw32(RCVLPC_STATS_ENABLE, val);
  5423. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5424. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5425. val = tr32(RCVLPC_STATS_ENABLE);
  5426. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5427. tw32(RCVLPC_STATS_ENABLE, val);
  5428. } else {
  5429. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5430. }
  5431. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5432. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5433. tw32(SNDDATAI_STATSCTRL,
  5434. (SNDDATAI_SCTRL_ENABLE |
  5435. SNDDATAI_SCTRL_FASTUPD));
  5436. /* Setup host coalescing engine. */
  5437. tw32(HOSTCC_MODE, 0);
  5438. for (i = 0; i < 2000; i++) {
  5439. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5440. break;
  5441. udelay(10);
  5442. }
  5443. __tg3_set_coalesce(tp, &tp->coal);
  5444. /* set status block DMA address */
  5445. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5446. ((u64) tp->status_mapping >> 32));
  5447. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5448. ((u64) tp->status_mapping & 0xffffffff));
  5449. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5450. /* Status/statistics block address. See tg3_timer,
  5451. * the tg3_periodic_fetch_stats call there, and
  5452. * tg3_get_stats to see how this works for 5705/5750 chips.
  5453. */
  5454. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5455. ((u64) tp->stats_mapping >> 32));
  5456. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5457. ((u64) tp->stats_mapping & 0xffffffff));
  5458. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5459. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5460. }
  5461. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5462. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5463. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5464. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5465. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5466. /* Clear statistics/status block in chip, and status block in ram. */
  5467. for (i = NIC_SRAM_STATS_BLK;
  5468. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5469. i += sizeof(u32)) {
  5470. tg3_write_mem(tp, i, 0);
  5471. udelay(40);
  5472. }
  5473. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5474. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5475. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5476. /* reset to prevent losing 1st rx packet intermittently */
  5477. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5478. udelay(10);
  5479. }
  5480. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5481. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5482. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5483. udelay(40);
  5484. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5485. * If TG3_FLAG_EEPROM_WRITE_PROT is set, we should read the
  5486. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5487. * whether used as inputs or outputs, are set by boot code after
  5488. * reset.
  5489. */
  5490. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  5491. u32 gpio_mask;
  5492. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE2 |
  5493. GRC_LCLCTRL_GPIO_OUTPUT0 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5494. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5495. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5496. GRC_LCLCTRL_GPIO_OUTPUT3;
  5497. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5498. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5499. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5500. /* GPIO1 must be driven high for eeprom write protect */
  5501. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5502. GRC_LCLCTRL_GPIO_OUTPUT1);
  5503. }
  5504. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5505. udelay(100);
  5506. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5507. tp->last_tag = 0;
  5508. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5509. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5510. udelay(40);
  5511. }
  5512. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5513. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5514. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5515. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5516. WDMAC_MODE_LNGREAD_ENAB);
  5517. /* If statement applies to 5705 and 5750 PCI devices only */
  5518. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5519. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5520. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5521. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5522. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5523. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5524. /* nothing */
  5525. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5526. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5527. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5528. val |= WDMAC_MODE_RX_ACCEL;
  5529. }
  5530. }
  5531. /* Enable host coalescing bug fix */
  5532. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5533. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5534. val |= (1 << 29);
  5535. tw32_f(WDMAC_MODE, val);
  5536. udelay(40);
  5537. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5538. val = tr32(TG3PCI_X_CAPS);
  5539. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5540. val &= ~PCIX_CAPS_BURST_MASK;
  5541. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5542. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5543. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5544. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5545. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  5546. val |= (tp->split_mode_max_reqs <<
  5547. PCIX_CAPS_SPLIT_SHIFT);
  5548. }
  5549. tw32(TG3PCI_X_CAPS, val);
  5550. }
  5551. tw32_f(RDMAC_MODE, rdmac_mode);
  5552. udelay(40);
  5553. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5554. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5555. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5556. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5557. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5558. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5559. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5560. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5561. #if TG3_TSO_SUPPORT != 0
  5562. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5563. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5564. #endif
  5565. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5566. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5567. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5568. err = tg3_load_5701_a0_firmware_fix(tp);
  5569. if (err)
  5570. return err;
  5571. }
  5572. #if TG3_TSO_SUPPORT != 0
  5573. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5574. err = tg3_load_tso_firmware(tp);
  5575. if (err)
  5576. return err;
  5577. }
  5578. #endif
  5579. tp->tx_mode = TX_MODE_ENABLE;
  5580. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5581. udelay(100);
  5582. tp->rx_mode = RX_MODE_ENABLE;
  5583. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5584. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5585. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5586. udelay(10);
  5587. if (tp->link_config.phy_is_low_power) {
  5588. tp->link_config.phy_is_low_power = 0;
  5589. tp->link_config.speed = tp->link_config.orig_speed;
  5590. tp->link_config.duplex = tp->link_config.orig_duplex;
  5591. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5592. }
  5593. tp->mi_mode = MAC_MI_MODE_BASE;
  5594. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5595. udelay(80);
  5596. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5597. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5598. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5599. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5600. udelay(10);
  5601. }
  5602. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5603. udelay(10);
  5604. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5605. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5606. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5607. /* Set drive transmission level to 1.2V */
  5608. /* only if the signal pre-emphasis bit is not set */
  5609. val = tr32(MAC_SERDES_CFG);
  5610. val &= 0xfffff000;
  5611. val |= 0x880;
  5612. tw32(MAC_SERDES_CFG, val);
  5613. }
  5614. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5615. tw32(MAC_SERDES_CFG, 0x616000);
  5616. }
  5617. /* Prevent chip from dropping frames when flow control
  5618. * is enabled.
  5619. */
  5620. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5621. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5622. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5623. /* Use hardware link auto-negotiation */
  5624. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5625. }
  5626. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5627. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5628. u32 tmp;
  5629. tmp = tr32(SERDES_RX_CTRL);
  5630. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5631. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5632. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5633. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5634. }
  5635. err = tg3_setup_phy(tp, reset_phy);
  5636. if (err)
  5637. return err;
  5638. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5639. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  5640. u32 tmp;
  5641. /* Clear CRC stats. */
  5642. if (!tg3_readphy(tp, 0x1e, &tmp)) {
  5643. tg3_writephy(tp, 0x1e, tmp | 0x8000);
  5644. tg3_readphy(tp, 0x14, &tmp);
  5645. }
  5646. }
  5647. __tg3_set_rx_mode(tp->dev);
  5648. /* Initialize receive rules. */
  5649. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5650. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5651. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5652. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5653. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5654. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5655. limit = 8;
  5656. else
  5657. limit = 16;
  5658. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5659. limit -= 4;
  5660. switch (limit) {
  5661. case 16:
  5662. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5663. case 15:
  5664. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5665. case 14:
  5666. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5667. case 13:
  5668. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5669. case 12:
  5670. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5671. case 11:
  5672. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5673. case 10:
  5674. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5675. case 9:
  5676. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5677. case 8:
  5678. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5679. case 7:
  5680. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5681. case 6:
  5682. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5683. case 5:
  5684. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5685. case 4:
  5686. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5687. case 3:
  5688. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5689. case 2:
  5690. case 1:
  5691. default:
  5692. break;
  5693. };
  5694. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5695. return 0;
  5696. }
  5697. /* Called at device open time to get the chip ready for
  5698. * packet processing. Invoked with tp->lock held.
  5699. */
  5700. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5701. {
  5702. int err;
  5703. /* Force the chip into D0. */
  5704. err = tg3_set_power_state(tp, PCI_D0);
  5705. if (err)
  5706. goto out;
  5707. tg3_switch_clocks(tp);
  5708. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5709. err = tg3_reset_hw(tp, reset_phy);
  5710. out:
  5711. return err;
  5712. }
  5713. #define TG3_STAT_ADD32(PSTAT, REG) \
  5714. do { u32 __val = tr32(REG); \
  5715. (PSTAT)->low += __val; \
  5716. if ((PSTAT)->low < __val) \
  5717. (PSTAT)->high += 1; \
  5718. } while (0)
  5719. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5720. {
  5721. struct tg3_hw_stats *sp = tp->hw_stats;
  5722. if (!netif_carrier_ok(tp->dev))
  5723. return;
  5724. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5725. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5726. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5727. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5728. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5729. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5730. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5731. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5732. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5733. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5734. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5735. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5736. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5737. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5738. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5739. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5740. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5741. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5742. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5743. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5744. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5745. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5746. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5747. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5748. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5749. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5750. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5751. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5752. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5753. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5754. }
  5755. static void tg3_timer(unsigned long __opaque)
  5756. {
  5757. struct tg3 *tp = (struct tg3 *) __opaque;
  5758. if (tp->irq_sync)
  5759. goto restart_timer;
  5760. spin_lock(&tp->lock);
  5761. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5762. /* All of this garbage is because when using non-tagged
  5763. * IRQ status the mailbox/status_block protocol the chip
  5764. * uses with the cpu is race prone.
  5765. */
  5766. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5767. tw32(GRC_LOCAL_CTRL,
  5768. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5769. } else {
  5770. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5771. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5772. }
  5773. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5774. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5775. spin_unlock(&tp->lock);
  5776. schedule_work(&tp->reset_task);
  5777. return;
  5778. }
  5779. }
  5780. /* This part only runs once per second. */
  5781. if (!--tp->timer_counter) {
  5782. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5783. tg3_periodic_fetch_stats(tp);
  5784. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5785. u32 mac_stat;
  5786. int phy_event;
  5787. mac_stat = tr32(MAC_STATUS);
  5788. phy_event = 0;
  5789. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5790. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5791. phy_event = 1;
  5792. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5793. phy_event = 1;
  5794. if (phy_event)
  5795. tg3_setup_phy(tp, 0);
  5796. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5797. u32 mac_stat = tr32(MAC_STATUS);
  5798. int need_setup = 0;
  5799. if (netif_carrier_ok(tp->dev) &&
  5800. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5801. need_setup = 1;
  5802. }
  5803. if (! netif_carrier_ok(tp->dev) &&
  5804. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5805. MAC_STATUS_SIGNAL_DET))) {
  5806. need_setup = 1;
  5807. }
  5808. if (need_setup) {
  5809. if (!tp->serdes_counter) {
  5810. tw32_f(MAC_MODE,
  5811. (tp->mac_mode &
  5812. ~MAC_MODE_PORT_MODE_MASK));
  5813. udelay(40);
  5814. tw32_f(MAC_MODE, tp->mac_mode);
  5815. udelay(40);
  5816. }
  5817. tg3_setup_phy(tp, 0);
  5818. }
  5819. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5820. tg3_serdes_parallel_detect(tp);
  5821. tp->timer_counter = tp->timer_multiplier;
  5822. }
  5823. /* Heartbeat is only sent once every 2 seconds.
  5824. *
  5825. * The heartbeat is to tell the ASF firmware that the host
  5826. * driver is still alive. In the event that the OS crashes,
  5827. * ASF needs to reset the hardware to free up the FIFO space
  5828. * that may be filled with rx packets destined for the host.
  5829. * If the FIFO is full, ASF will no longer function properly.
  5830. *
  5831. * Unintended resets have been reported on real time kernels
  5832. * where the timer doesn't run on time. Netpoll will also have
  5833. * same problem.
  5834. *
  5835. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  5836. * to check the ring condition when the heartbeat is expiring
  5837. * before doing the reset. This will prevent most unintended
  5838. * resets.
  5839. */
  5840. if (!--tp->asf_counter) {
  5841. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5842. u32 val;
  5843. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5844. FWCMD_NICDRV_ALIVE3);
  5845. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5846. /* 5 seconds timeout */
  5847. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5848. val = tr32(GRC_RX_CPU_EVENT);
  5849. val |= (1 << 14);
  5850. tw32(GRC_RX_CPU_EVENT, val);
  5851. }
  5852. tp->asf_counter = tp->asf_multiplier;
  5853. }
  5854. spin_unlock(&tp->lock);
  5855. restart_timer:
  5856. tp->timer.expires = jiffies + tp->timer_offset;
  5857. add_timer(&tp->timer);
  5858. }
  5859. static int tg3_request_irq(struct tg3 *tp)
  5860. {
  5861. irqreturn_t (*fn)(int, void *, struct pt_regs *);
  5862. unsigned long flags;
  5863. struct net_device *dev = tp->dev;
  5864. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5865. fn = tg3_msi;
  5866. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5867. fn = tg3_msi_1shot;
  5868. flags = IRQF_SAMPLE_RANDOM;
  5869. } else {
  5870. fn = tg3_interrupt;
  5871. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5872. fn = tg3_interrupt_tagged;
  5873. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5874. }
  5875. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5876. }
  5877. static int tg3_test_interrupt(struct tg3 *tp)
  5878. {
  5879. struct net_device *dev = tp->dev;
  5880. int err, i, intr_ok = 0;
  5881. if (!netif_running(dev))
  5882. return -ENODEV;
  5883. tg3_disable_ints(tp);
  5884. free_irq(tp->pdev->irq, dev);
  5885. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5886. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5887. if (err)
  5888. return err;
  5889. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5890. tg3_enable_ints(tp);
  5891. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5892. HOSTCC_MODE_NOW);
  5893. for (i = 0; i < 5; i++) {
  5894. u32 int_mbox, misc_host_ctrl;
  5895. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5896. TG3_64BIT_REG_LOW);
  5897. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  5898. if ((int_mbox != 0) ||
  5899. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  5900. intr_ok = 1;
  5901. break;
  5902. }
  5903. msleep(10);
  5904. }
  5905. tg3_disable_ints(tp);
  5906. free_irq(tp->pdev->irq, dev);
  5907. err = tg3_request_irq(tp);
  5908. if (err)
  5909. return err;
  5910. if (intr_ok)
  5911. return 0;
  5912. return -EIO;
  5913. }
  5914. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5915. * successfully restored
  5916. */
  5917. static int tg3_test_msi(struct tg3 *tp)
  5918. {
  5919. struct net_device *dev = tp->dev;
  5920. int err;
  5921. u16 pci_cmd;
  5922. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  5923. return 0;
  5924. /* Turn off SERR reporting in case MSI terminates with Master
  5925. * Abort.
  5926. */
  5927. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  5928. pci_write_config_word(tp->pdev, PCI_COMMAND,
  5929. pci_cmd & ~PCI_COMMAND_SERR);
  5930. err = tg3_test_interrupt(tp);
  5931. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  5932. if (!err)
  5933. return 0;
  5934. /* other failures */
  5935. if (err != -EIO)
  5936. return err;
  5937. /* MSI test failed, go back to INTx mode */
  5938. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  5939. "switching to INTx mode. Please report this failure to "
  5940. "the PCI maintainer and include system chipset information.\n",
  5941. tp->dev->name);
  5942. free_irq(tp->pdev->irq, dev);
  5943. pci_disable_msi(tp->pdev);
  5944. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5945. err = tg3_request_irq(tp);
  5946. if (err)
  5947. return err;
  5948. /* Need to reset the chip because the MSI cycle may have terminated
  5949. * with Master Abort.
  5950. */
  5951. tg3_full_lock(tp, 1);
  5952. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5953. err = tg3_init_hw(tp, 1);
  5954. tg3_full_unlock(tp);
  5955. if (err)
  5956. free_irq(tp->pdev->irq, dev);
  5957. return err;
  5958. }
  5959. static int tg3_open(struct net_device *dev)
  5960. {
  5961. struct tg3 *tp = netdev_priv(dev);
  5962. int err;
  5963. tg3_full_lock(tp, 0);
  5964. err = tg3_set_power_state(tp, PCI_D0);
  5965. if (err)
  5966. return err;
  5967. tg3_disable_ints(tp);
  5968. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  5969. tg3_full_unlock(tp);
  5970. /* The placement of this call is tied
  5971. * to the setup and use of Host TX descriptors.
  5972. */
  5973. err = tg3_alloc_consistent(tp);
  5974. if (err)
  5975. return err;
  5976. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  5977. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
  5978. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
  5979. !((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) &&
  5980. (tp->pdev_peer == tp->pdev))) {
  5981. /* All MSI supporting chips should support tagged
  5982. * status. Assert that this is the case.
  5983. */
  5984. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5985. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  5986. "Not using MSI.\n", tp->dev->name);
  5987. } else if (pci_enable_msi(tp->pdev) == 0) {
  5988. u32 msi_mode;
  5989. msi_mode = tr32(MSGINT_MODE);
  5990. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  5991. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  5992. }
  5993. }
  5994. err = tg3_request_irq(tp);
  5995. if (err) {
  5996. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5997. pci_disable_msi(tp->pdev);
  5998. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5999. }
  6000. tg3_free_consistent(tp);
  6001. return err;
  6002. }
  6003. tg3_full_lock(tp, 0);
  6004. err = tg3_init_hw(tp, 1);
  6005. if (err) {
  6006. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6007. tg3_free_rings(tp);
  6008. } else {
  6009. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6010. tp->timer_offset = HZ;
  6011. else
  6012. tp->timer_offset = HZ / 10;
  6013. BUG_ON(tp->timer_offset > HZ);
  6014. tp->timer_counter = tp->timer_multiplier =
  6015. (HZ / tp->timer_offset);
  6016. tp->asf_counter = tp->asf_multiplier =
  6017. ((HZ / tp->timer_offset) * 2);
  6018. init_timer(&tp->timer);
  6019. tp->timer.expires = jiffies + tp->timer_offset;
  6020. tp->timer.data = (unsigned long) tp;
  6021. tp->timer.function = tg3_timer;
  6022. }
  6023. tg3_full_unlock(tp);
  6024. if (err) {
  6025. free_irq(tp->pdev->irq, dev);
  6026. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6027. pci_disable_msi(tp->pdev);
  6028. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6029. }
  6030. tg3_free_consistent(tp);
  6031. return err;
  6032. }
  6033. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6034. err = tg3_test_msi(tp);
  6035. if (err) {
  6036. tg3_full_lock(tp, 0);
  6037. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6038. pci_disable_msi(tp->pdev);
  6039. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6040. }
  6041. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6042. tg3_free_rings(tp);
  6043. tg3_free_consistent(tp);
  6044. tg3_full_unlock(tp);
  6045. return err;
  6046. }
  6047. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6048. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6049. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6050. tw32(PCIE_TRANSACTION_CFG,
  6051. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6052. }
  6053. }
  6054. }
  6055. tg3_full_lock(tp, 0);
  6056. add_timer(&tp->timer);
  6057. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6058. tg3_enable_ints(tp);
  6059. tg3_full_unlock(tp);
  6060. netif_start_queue(dev);
  6061. return 0;
  6062. }
  6063. #if 0
  6064. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6065. {
  6066. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6067. u16 val16;
  6068. int i;
  6069. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6070. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6071. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6072. val16, val32);
  6073. /* MAC block */
  6074. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6075. tr32(MAC_MODE), tr32(MAC_STATUS));
  6076. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6077. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6078. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6079. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6080. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6081. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6082. /* Send data initiator control block */
  6083. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6084. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6085. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6086. tr32(SNDDATAI_STATSCTRL));
  6087. /* Send data completion control block */
  6088. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6089. /* Send BD ring selector block */
  6090. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6091. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6092. /* Send BD initiator control block */
  6093. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6094. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6095. /* Send BD completion control block */
  6096. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6097. /* Receive list placement control block */
  6098. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6099. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6100. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6101. tr32(RCVLPC_STATSCTRL));
  6102. /* Receive data and receive BD initiator control block */
  6103. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6104. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6105. /* Receive data completion control block */
  6106. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6107. tr32(RCVDCC_MODE));
  6108. /* Receive BD initiator control block */
  6109. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6110. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6111. /* Receive BD completion control block */
  6112. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6113. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6114. /* Receive list selector control block */
  6115. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6116. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6117. /* Mbuf cluster free block */
  6118. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6119. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6120. /* Host coalescing control block */
  6121. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6122. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6123. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6124. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6125. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6126. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6127. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6128. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6129. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6130. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6131. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6132. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6133. /* Memory arbiter control block */
  6134. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6135. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6136. /* Buffer manager control block */
  6137. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6138. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6139. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6140. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6141. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6142. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6143. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6144. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6145. /* Read DMA control block */
  6146. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6147. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6148. /* Write DMA control block */
  6149. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6150. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6151. /* DMA completion block */
  6152. printk("DEBUG: DMAC_MODE[%08x]\n",
  6153. tr32(DMAC_MODE));
  6154. /* GRC block */
  6155. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6156. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6157. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6158. tr32(GRC_LOCAL_CTRL));
  6159. /* TG3_BDINFOs */
  6160. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6161. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6162. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6163. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6164. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6165. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6166. tr32(RCVDBDI_STD_BD + 0x0),
  6167. tr32(RCVDBDI_STD_BD + 0x4),
  6168. tr32(RCVDBDI_STD_BD + 0x8),
  6169. tr32(RCVDBDI_STD_BD + 0xc));
  6170. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6171. tr32(RCVDBDI_MINI_BD + 0x0),
  6172. tr32(RCVDBDI_MINI_BD + 0x4),
  6173. tr32(RCVDBDI_MINI_BD + 0x8),
  6174. tr32(RCVDBDI_MINI_BD + 0xc));
  6175. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6176. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6177. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6178. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6179. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6180. val32, val32_2, val32_3, val32_4);
  6181. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6182. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6183. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6184. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6185. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6186. val32, val32_2, val32_3, val32_4);
  6187. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6188. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6189. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6190. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6191. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6192. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6193. val32, val32_2, val32_3, val32_4, val32_5);
  6194. /* SW status block */
  6195. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6196. tp->hw_status->status,
  6197. tp->hw_status->status_tag,
  6198. tp->hw_status->rx_jumbo_consumer,
  6199. tp->hw_status->rx_consumer,
  6200. tp->hw_status->rx_mini_consumer,
  6201. tp->hw_status->idx[0].rx_producer,
  6202. tp->hw_status->idx[0].tx_consumer);
  6203. /* SW statistics block */
  6204. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6205. ((u32 *)tp->hw_stats)[0],
  6206. ((u32 *)tp->hw_stats)[1],
  6207. ((u32 *)tp->hw_stats)[2],
  6208. ((u32 *)tp->hw_stats)[3]);
  6209. /* Mailboxes */
  6210. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6211. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6212. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6213. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6214. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6215. /* NIC side send descriptors. */
  6216. for (i = 0; i < 6; i++) {
  6217. unsigned long txd;
  6218. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6219. + (i * sizeof(struct tg3_tx_buffer_desc));
  6220. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6221. i,
  6222. readl(txd + 0x0), readl(txd + 0x4),
  6223. readl(txd + 0x8), readl(txd + 0xc));
  6224. }
  6225. /* NIC side RX descriptors. */
  6226. for (i = 0; i < 6; i++) {
  6227. unsigned long rxd;
  6228. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6229. + (i * sizeof(struct tg3_rx_buffer_desc));
  6230. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6231. i,
  6232. readl(rxd + 0x0), readl(rxd + 0x4),
  6233. readl(rxd + 0x8), readl(rxd + 0xc));
  6234. rxd += (4 * sizeof(u32));
  6235. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6236. i,
  6237. readl(rxd + 0x0), readl(rxd + 0x4),
  6238. readl(rxd + 0x8), readl(rxd + 0xc));
  6239. }
  6240. for (i = 0; i < 6; i++) {
  6241. unsigned long rxd;
  6242. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6243. + (i * sizeof(struct tg3_rx_buffer_desc));
  6244. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6245. i,
  6246. readl(rxd + 0x0), readl(rxd + 0x4),
  6247. readl(rxd + 0x8), readl(rxd + 0xc));
  6248. rxd += (4 * sizeof(u32));
  6249. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6250. i,
  6251. readl(rxd + 0x0), readl(rxd + 0x4),
  6252. readl(rxd + 0x8), readl(rxd + 0xc));
  6253. }
  6254. }
  6255. #endif
  6256. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6257. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6258. static int tg3_close(struct net_device *dev)
  6259. {
  6260. struct tg3 *tp = netdev_priv(dev);
  6261. /* Calling flush_scheduled_work() may deadlock because
  6262. * linkwatch_event() may be on the workqueue and it will try to get
  6263. * the rtnl_lock which we are holding.
  6264. */
  6265. while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
  6266. msleep(1);
  6267. netif_stop_queue(dev);
  6268. del_timer_sync(&tp->timer);
  6269. tg3_full_lock(tp, 1);
  6270. #if 0
  6271. tg3_dump_state(tp);
  6272. #endif
  6273. tg3_disable_ints(tp);
  6274. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6275. tg3_free_rings(tp);
  6276. tp->tg3_flags &=
  6277. ~(TG3_FLAG_INIT_COMPLETE |
  6278. TG3_FLAG_GOT_SERDES_FLOWCTL);
  6279. tg3_full_unlock(tp);
  6280. free_irq(tp->pdev->irq, dev);
  6281. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6282. pci_disable_msi(tp->pdev);
  6283. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6284. }
  6285. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6286. sizeof(tp->net_stats_prev));
  6287. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6288. sizeof(tp->estats_prev));
  6289. tg3_free_consistent(tp);
  6290. tg3_set_power_state(tp, PCI_D3hot);
  6291. netif_carrier_off(tp->dev);
  6292. return 0;
  6293. }
  6294. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6295. {
  6296. unsigned long ret;
  6297. #if (BITS_PER_LONG == 32)
  6298. ret = val->low;
  6299. #else
  6300. ret = ((u64)val->high << 32) | ((u64)val->low);
  6301. #endif
  6302. return ret;
  6303. }
  6304. static unsigned long calc_crc_errors(struct tg3 *tp)
  6305. {
  6306. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6307. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6308. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6309. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6310. u32 val;
  6311. spin_lock_bh(&tp->lock);
  6312. if (!tg3_readphy(tp, 0x1e, &val)) {
  6313. tg3_writephy(tp, 0x1e, val | 0x8000);
  6314. tg3_readphy(tp, 0x14, &val);
  6315. } else
  6316. val = 0;
  6317. spin_unlock_bh(&tp->lock);
  6318. tp->phy_crc_errors += val;
  6319. return tp->phy_crc_errors;
  6320. }
  6321. return get_stat64(&hw_stats->rx_fcs_errors);
  6322. }
  6323. #define ESTAT_ADD(member) \
  6324. estats->member = old_estats->member + \
  6325. get_stat64(&hw_stats->member)
  6326. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6327. {
  6328. struct tg3_ethtool_stats *estats = &tp->estats;
  6329. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6330. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6331. if (!hw_stats)
  6332. return old_estats;
  6333. ESTAT_ADD(rx_octets);
  6334. ESTAT_ADD(rx_fragments);
  6335. ESTAT_ADD(rx_ucast_packets);
  6336. ESTAT_ADD(rx_mcast_packets);
  6337. ESTAT_ADD(rx_bcast_packets);
  6338. ESTAT_ADD(rx_fcs_errors);
  6339. ESTAT_ADD(rx_align_errors);
  6340. ESTAT_ADD(rx_xon_pause_rcvd);
  6341. ESTAT_ADD(rx_xoff_pause_rcvd);
  6342. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6343. ESTAT_ADD(rx_xoff_entered);
  6344. ESTAT_ADD(rx_frame_too_long_errors);
  6345. ESTAT_ADD(rx_jabbers);
  6346. ESTAT_ADD(rx_undersize_packets);
  6347. ESTAT_ADD(rx_in_length_errors);
  6348. ESTAT_ADD(rx_out_length_errors);
  6349. ESTAT_ADD(rx_64_or_less_octet_packets);
  6350. ESTAT_ADD(rx_65_to_127_octet_packets);
  6351. ESTAT_ADD(rx_128_to_255_octet_packets);
  6352. ESTAT_ADD(rx_256_to_511_octet_packets);
  6353. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6354. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6355. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6356. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6357. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6358. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6359. ESTAT_ADD(tx_octets);
  6360. ESTAT_ADD(tx_collisions);
  6361. ESTAT_ADD(tx_xon_sent);
  6362. ESTAT_ADD(tx_xoff_sent);
  6363. ESTAT_ADD(tx_flow_control);
  6364. ESTAT_ADD(tx_mac_errors);
  6365. ESTAT_ADD(tx_single_collisions);
  6366. ESTAT_ADD(tx_mult_collisions);
  6367. ESTAT_ADD(tx_deferred);
  6368. ESTAT_ADD(tx_excessive_collisions);
  6369. ESTAT_ADD(tx_late_collisions);
  6370. ESTAT_ADD(tx_collide_2times);
  6371. ESTAT_ADD(tx_collide_3times);
  6372. ESTAT_ADD(tx_collide_4times);
  6373. ESTAT_ADD(tx_collide_5times);
  6374. ESTAT_ADD(tx_collide_6times);
  6375. ESTAT_ADD(tx_collide_7times);
  6376. ESTAT_ADD(tx_collide_8times);
  6377. ESTAT_ADD(tx_collide_9times);
  6378. ESTAT_ADD(tx_collide_10times);
  6379. ESTAT_ADD(tx_collide_11times);
  6380. ESTAT_ADD(tx_collide_12times);
  6381. ESTAT_ADD(tx_collide_13times);
  6382. ESTAT_ADD(tx_collide_14times);
  6383. ESTAT_ADD(tx_collide_15times);
  6384. ESTAT_ADD(tx_ucast_packets);
  6385. ESTAT_ADD(tx_mcast_packets);
  6386. ESTAT_ADD(tx_bcast_packets);
  6387. ESTAT_ADD(tx_carrier_sense_errors);
  6388. ESTAT_ADD(tx_discards);
  6389. ESTAT_ADD(tx_errors);
  6390. ESTAT_ADD(dma_writeq_full);
  6391. ESTAT_ADD(dma_write_prioq_full);
  6392. ESTAT_ADD(rxbds_empty);
  6393. ESTAT_ADD(rx_discards);
  6394. ESTAT_ADD(rx_errors);
  6395. ESTAT_ADD(rx_threshold_hit);
  6396. ESTAT_ADD(dma_readq_full);
  6397. ESTAT_ADD(dma_read_prioq_full);
  6398. ESTAT_ADD(tx_comp_queue_full);
  6399. ESTAT_ADD(ring_set_send_prod_index);
  6400. ESTAT_ADD(ring_status_update);
  6401. ESTAT_ADD(nic_irqs);
  6402. ESTAT_ADD(nic_avoided_irqs);
  6403. ESTAT_ADD(nic_tx_threshold_hit);
  6404. return estats;
  6405. }
  6406. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6407. {
  6408. struct tg3 *tp = netdev_priv(dev);
  6409. struct net_device_stats *stats = &tp->net_stats;
  6410. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6411. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6412. if (!hw_stats)
  6413. return old_stats;
  6414. stats->rx_packets = old_stats->rx_packets +
  6415. get_stat64(&hw_stats->rx_ucast_packets) +
  6416. get_stat64(&hw_stats->rx_mcast_packets) +
  6417. get_stat64(&hw_stats->rx_bcast_packets);
  6418. stats->tx_packets = old_stats->tx_packets +
  6419. get_stat64(&hw_stats->tx_ucast_packets) +
  6420. get_stat64(&hw_stats->tx_mcast_packets) +
  6421. get_stat64(&hw_stats->tx_bcast_packets);
  6422. stats->rx_bytes = old_stats->rx_bytes +
  6423. get_stat64(&hw_stats->rx_octets);
  6424. stats->tx_bytes = old_stats->tx_bytes +
  6425. get_stat64(&hw_stats->tx_octets);
  6426. stats->rx_errors = old_stats->rx_errors +
  6427. get_stat64(&hw_stats->rx_errors);
  6428. stats->tx_errors = old_stats->tx_errors +
  6429. get_stat64(&hw_stats->tx_errors) +
  6430. get_stat64(&hw_stats->tx_mac_errors) +
  6431. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6432. get_stat64(&hw_stats->tx_discards);
  6433. stats->multicast = old_stats->multicast +
  6434. get_stat64(&hw_stats->rx_mcast_packets);
  6435. stats->collisions = old_stats->collisions +
  6436. get_stat64(&hw_stats->tx_collisions);
  6437. stats->rx_length_errors = old_stats->rx_length_errors +
  6438. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6439. get_stat64(&hw_stats->rx_undersize_packets);
  6440. stats->rx_over_errors = old_stats->rx_over_errors +
  6441. get_stat64(&hw_stats->rxbds_empty);
  6442. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6443. get_stat64(&hw_stats->rx_align_errors);
  6444. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6445. get_stat64(&hw_stats->tx_discards);
  6446. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6447. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6448. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6449. calc_crc_errors(tp);
  6450. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6451. get_stat64(&hw_stats->rx_discards);
  6452. return stats;
  6453. }
  6454. static inline u32 calc_crc(unsigned char *buf, int len)
  6455. {
  6456. u32 reg;
  6457. u32 tmp;
  6458. int j, k;
  6459. reg = 0xffffffff;
  6460. for (j = 0; j < len; j++) {
  6461. reg ^= buf[j];
  6462. for (k = 0; k < 8; k++) {
  6463. tmp = reg & 0x01;
  6464. reg >>= 1;
  6465. if (tmp) {
  6466. reg ^= 0xedb88320;
  6467. }
  6468. }
  6469. }
  6470. return ~reg;
  6471. }
  6472. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6473. {
  6474. /* accept or reject all multicast frames */
  6475. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6476. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6477. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6478. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6479. }
  6480. static void __tg3_set_rx_mode(struct net_device *dev)
  6481. {
  6482. struct tg3 *tp = netdev_priv(dev);
  6483. u32 rx_mode;
  6484. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6485. RX_MODE_KEEP_VLAN_TAG);
  6486. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6487. * flag clear.
  6488. */
  6489. #if TG3_VLAN_TAG_USED
  6490. if (!tp->vlgrp &&
  6491. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6492. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6493. #else
  6494. /* By definition, VLAN is disabled always in this
  6495. * case.
  6496. */
  6497. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6498. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6499. #endif
  6500. if (dev->flags & IFF_PROMISC) {
  6501. /* Promiscuous mode. */
  6502. rx_mode |= RX_MODE_PROMISC;
  6503. } else if (dev->flags & IFF_ALLMULTI) {
  6504. /* Accept all multicast. */
  6505. tg3_set_multi (tp, 1);
  6506. } else if (dev->mc_count < 1) {
  6507. /* Reject all multicast. */
  6508. tg3_set_multi (tp, 0);
  6509. } else {
  6510. /* Accept one or more multicast(s). */
  6511. struct dev_mc_list *mclist;
  6512. unsigned int i;
  6513. u32 mc_filter[4] = { 0, };
  6514. u32 regidx;
  6515. u32 bit;
  6516. u32 crc;
  6517. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6518. i++, mclist = mclist->next) {
  6519. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6520. bit = ~crc & 0x7f;
  6521. regidx = (bit & 0x60) >> 5;
  6522. bit &= 0x1f;
  6523. mc_filter[regidx] |= (1 << bit);
  6524. }
  6525. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6526. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6527. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6528. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6529. }
  6530. if (rx_mode != tp->rx_mode) {
  6531. tp->rx_mode = rx_mode;
  6532. tw32_f(MAC_RX_MODE, rx_mode);
  6533. udelay(10);
  6534. }
  6535. }
  6536. static void tg3_set_rx_mode(struct net_device *dev)
  6537. {
  6538. struct tg3 *tp = netdev_priv(dev);
  6539. if (!netif_running(dev))
  6540. return;
  6541. tg3_full_lock(tp, 0);
  6542. __tg3_set_rx_mode(dev);
  6543. tg3_full_unlock(tp);
  6544. }
  6545. #define TG3_REGDUMP_LEN (32 * 1024)
  6546. static int tg3_get_regs_len(struct net_device *dev)
  6547. {
  6548. return TG3_REGDUMP_LEN;
  6549. }
  6550. static void tg3_get_regs(struct net_device *dev,
  6551. struct ethtool_regs *regs, void *_p)
  6552. {
  6553. u32 *p = _p;
  6554. struct tg3 *tp = netdev_priv(dev);
  6555. u8 *orig_p = _p;
  6556. int i;
  6557. regs->version = 0;
  6558. memset(p, 0, TG3_REGDUMP_LEN);
  6559. if (tp->link_config.phy_is_low_power)
  6560. return;
  6561. tg3_full_lock(tp, 0);
  6562. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6563. #define GET_REG32_LOOP(base,len) \
  6564. do { p = (u32 *)(orig_p + (base)); \
  6565. for (i = 0; i < len; i += 4) \
  6566. __GET_REG32((base) + i); \
  6567. } while (0)
  6568. #define GET_REG32_1(reg) \
  6569. do { p = (u32 *)(orig_p + (reg)); \
  6570. __GET_REG32((reg)); \
  6571. } while (0)
  6572. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6573. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6574. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6575. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6576. GET_REG32_1(SNDDATAC_MODE);
  6577. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6578. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6579. GET_REG32_1(SNDBDC_MODE);
  6580. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6581. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6582. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6583. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6584. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6585. GET_REG32_1(RCVDCC_MODE);
  6586. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6587. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6588. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6589. GET_REG32_1(MBFREE_MODE);
  6590. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6591. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6592. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6593. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6594. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6595. GET_REG32_1(RX_CPU_MODE);
  6596. GET_REG32_1(RX_CPU_STATE);
  6597. GET_REG32_1(RX_CPU_PGMCTR);
  6598. GET_REG32_1(RX_CPU_HWBKPT);
  6599. GET_REG32_1(TX_CPU_MODE);
  6600. GET_REG32_1(TX_CPU_STATE);
  6601. GET_REG32_1(TX_CPU_PGMCTR);
  6602. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6603. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6604. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6605. GET_REG32_1(DMAC_MODE);
  6606. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6607. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6608. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6609. #undef __GET_REG32
  6610. #undef GET_REG32_LOOP
  6611. #undef GET_REG32_1
  6612. tg3_full_unlock(tp);
  6613. }
  6614. static int tg3_get_eeprom_len(struct net_device *dev)
  6615. {
  6616. struct tg3 *tp = netdev_priv(dev);
  6617. return tp->nvram_size;
  6618. }
  6619. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6620. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6621. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6622. {
  6623. struct tg3 *tp = netdev_priv(dev);
  6624. int ret;
  6625. u8 *pd;
  6626. u32 i, offset, len, val, b_offset, b_count;
  6627. if (tp->link_config.phy_is_low_power)
  6628. return -EAGAIN;
  6629. offset = eeprom->offset;
  6630. len = eeprom->len;
  6631. eeprom->len = 0;
  6632. eeprom->magic = TG3_EEPROM_MAGIC;
  6633. if (offset & 3) {
  6634. /* adjustments to start on required 4 byte boundary */
  6635. b_offset = offset & 3;
  6636. b_count = 4 - b_offset;
  6637. if (b_count > len) {
  6638. /* i.e. offset=1 len=2 */
  6639. b_count = len;
  6640. }
  6641. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6642. if (ret)
  6643. return ret;
  6644. val = cpu_to_le32(val);
  6645. memcpy(data, ((char*)&val) + b_offset, b_count);
  6646. len -= b_count;
  6647. offset += b_count;
  6648. eeprom->len += b_count;
  6649. }
  6650. /* read bytes upto the last 4 byte boundary */
  6651. pd = &data[eeprom->len];
  6652. for (i = 0; i < (len - (len & 3)); i += 4) {
  6653. ret = tg3_nvram_read(tp, offset + i, &val);
  6654. if (ret) {
  6655. eeprom->len += i;
  6656. return ret;
  6657. }
  6658. val = cpu_to_le32(val);
  6659. memcpy(pd + i, &val, 4);
  6660. }
  6661. eeprom->len += i;
  6662. if (len & 3) {
  6663. /* read last bytes not ending on 4 byte boundary */
  6664. pd = &data[eeprom->len];
  6665. b_count = len & 3;
  6666. b_offset = offset + len - b_count;
  6667. ret = tg3_nvram_read(tp, b_offset, &val);
  6668. if (ret)
  6669. return ret;
  6670. val = cpu_to_le32(val);
  6671. memcpy(pd, ((char*)&val), b_count);
  6672. eeprom->len += b_count;
  6673. }
  6674. return 0;
  6675. }
  6676. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6677. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6678. {
  6679. struct tg3 *tp = netdev_priv(dev);
  6680. int ret;
  6681. u32 offset, len, b_offset, odd_len, start, end;
  6682. u8 *buf;
  6683. if (tp->link_config.phy_is_low_power)
  6684. return -EAGAIN;
  6685. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6686. return -EINVAL;
  6687. offset = eeprom->offset;
  6688. len = eeprom->len;
  6689. if ((b_offset = (offset & 3))) {
  6690. /* adjustments to start on required 4 byte boundary */
  6691. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6692. if (ret)
  6693. return ret;
  6694. start = cpu_to_le32(start);
  6695. len += b_offset;
  6696. offset &= ~3;
  6697. if (len < 4)
  6698. len = 4;
  6699. }
  6700. odd_len = 0;
  6701. if (len & 3) {
  6702. /* adjustments to end on required 4 byte boundary */
  6703. odd_len = 1;
  6704. len = (len + 3) & ~3;
  6705. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6706. if (ret)
  6707. return ret;
  6708. end = cpu_to_le32(end);
  6709. }
  6710. buf = data;
  6711. if (b_offset || odd_len) {
  6712. buf = kmalloc(len, GFP_KERNEL);
  6713. if (buf == 0)
  6714. return -ENOMEM;
  6715. if (b_offset)
  6716. memcpy(buf, &start, 4);
  6717. if (odd_len)
  6718. memcpy(buf+len-4, &end, 4);
  6719. memcpy(buf + b_offset, data, eeprom->len);
  6720. }
  6721. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6722. if (buf != data)
  6723. kfree(buf);
  6724. return ret;
  6725. }
  6726. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6727. {
  6728. struct tg3 *tp = netdev_priv(dev);
  6729. cmd->supported = (SUPPORTED_Autoneg);
  6730. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6731. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6732. SUPPORTED_1000baseT_Full);
  6733. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6734. cmd->supported |= (SUPPORTED_100baseT_Half |
  6735. SUPPORTED_100baseT_Full |
  6736. SUPPORTED_10baseT_Half |
  6737. SUPPORTED_10baseT_Full |
  6738. SUPPORTED_MII);
  6739. cmd->port = PORT_TP;
  6740. } else {
  6741. cmd->supported |= SUPPORTED_FIBRE;
  6742. cmd->port = PORT_FIBRE;
  6743. }
  6744. cmd->advertising = tp->link_config.advertising;
  6745. if (netif_running(dev)) {
  6746. cmd->speed = tp->link_config.active_speed;
  6747. cmd->duplex = tp->link_config.active_duplex;
  6748. }
  6749. cmd->phy_address = PHY_ADDR;
  6750. cmd->transceiver = 0;
  6751. cmd->autoneg = tp->link_config.autoneg;
  6752. cmd->maxtxpkt = 0;
  6753. cmd->maxrxpkt = 0;
  6754. return 0;
  6755. }
  6756. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6757. {
  6758. struct tg3 *tp = netdev_priv(dev);
  6759. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6760. /* These are the only valid advertisement bits allowed. */
  6761. if (cmd->autoneg == AUTONEG_ENABLE &&
  6762. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6763. ADVERTISED_1000baseT_Full |
  6764. ADVERTISED_Autoneg |
  6765. ADVERTISED_FIBRE)))
  6766. return -EINVAL;
  6767. /* Fiber can only do SPEED_1000. */
  6768. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6769. (cmd->speed != SPEED_1000))
  6770. return -EINVAL;
  6771. /* Copper cannot force SPEED_1000. */
  6772. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6773. (cmd->speed == SPEED_1000))
  6774. return -EINVAL;
  6775. else if ((cmd->speed == SPEED_1000) &&
  6776. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6777. return -EINVAL;
  6778. tg3_full_lock(tp, 0);
  6779. tp->link_config.autoneg = cmd->autoneg;
  6780. if (cmd->autoneg == AUTONEG_ENABLE) {
  6781. tp->link_config.advertising = cmd->advertising;
  6782. tp->link_config.speed = SPEED_INVALID;
  6783. tp->link_config.duplex = DUPLEX_INVALID;
  6784. } else {
  6785. tp->link_config.advertising = 0;
  6786. tp->link_config.speed = cmd->speed;
  6787. tp->link_config.duplex = cmd->duplex;
  6788. }
  6789. if (netif_running(dev))
  6790. tg3_setup_phy(tp, 1);
  6791. tg3_full_unlock(tp);
  6792. return 0;
  6793. }
  6794. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6795. {
  6796. struct tg3 *tp = netdev_priv(dev);
  6797. strcpy(info->driver, DRV_MODULE_NAME);
  6798. strcpy(info->version, DRV_MODULE_VERSION);
  6799. strcpy(info->fw_version, tp->fw_ver);
  6800. strcpy(info->bus_info, pci_name(tp->pdev));
  6801. }
  6802. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6803. {
  6804. struct tg3 *tp = netdev_priv(dev);
  6805. wol->supported = WAKE_MAGIC;
  6806. wol->wolopts = 0;
  6807. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6808. wol->wolopts = WAKE_MAGIC;
  6809. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6810. }
  6811. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6812. {
  6813. struct tg3 *tp = netdev_priv(dev);
  6814. if (wol->wolopts & ~WAKE_MAGIC)
  6815. return -EINVAL;
  6816. if ((wol->wolopts & WAKE_MAGIC) &&
  6817. tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  6818. !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
  6819. return -EINVAL;
  6820. spin_lock_bh(&tp->lock);
  6821. if (wol->wolopts & WAKE_MAGIC)
  6822. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6823. else
  6824. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6825. spin_unlock_bh(&tp->lock);
  6826. return 0;
  6827. }
  6828. static u32 tg3_get_msglevel(struct net_device *dev)
  6829. {
  6830. struct tg3 *tp = netdev_priv(dev);
  6831. return tp->msg_enable;
  6832. }
  6833. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6834. {
  6835. struct tg3 *tp = netdev_priv(dev);
  6836. tp->msg_enable = value;
  6837. }
  6838. #if TG3_TSO_SUPPORT != 0
  6839. static int tg3_set_tso(struct net_device *dev, u32 value)
  6840. {
  6841. struct tg3 *tp = netdev_priv(dev);
  6842. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6843. if (value)
  6844. return -EINVAL;
  6845. return 0;
  6846. }
  6847. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  6848. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  6849. if (value)
  6850. dev->features |= NETIF_F_TSO6;
  6851. else
  6852. dev->features &= ~NETIF_F_TSO6;
  6853. }
  6854. return ethtool_op_set_tso(dev, value);
  6855. }
  6856. #endif
  6857. static int tg3_nway_reset(struct net_device *dev)
  6858. {
  6859. struct tg3 *tp = netdev_priv(dev);
  6860. u32 bmcr;
  6861. int r;
  6862. if (!netif_running(dev))
  6863. return -EAGAIN;
  6864. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6865. return -EINVAL;
  6866. spin_lock_bh(&tp->lock);
  6867. r = -EINVAL;
  6868. tg3_readphy(tp, MII_BMCR, &bmcr);
  6869. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6870. ((bmcr & BMCR_ANENABLE) ||
  6871. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6872. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6873. BMCR_ANENABLE);
  6874. r = 0;
  6875. }
  6876. spin_unlock_bh(&tp->lock);
  6877. return r;
  6878. }
  6879. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6880. {
  6881. struct tg3 *tp = netdev_priv(dev);
  6882. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6883. ering->rx_mini_max_pending = 0;
  6884. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6885. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6886. else
  6887. ering->rx_jumbo_max_pending = 0;
  6888. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6889. ering->rx_pending = tp->rx_pending;
  6890. ering->rx_mini_pending = 0;
  6891. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6892. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6893. else
  6894. ering->rx_jumbo_pending = 0;
  6895. ering->tx_pending = tp->tx_pending;
  6896. }
  6897. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6898. {
  6899. struct tg3 *tp = netdev_priv(dev);
  6900. int irq_sync = 0, err = 0;
  6901. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6902. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6903. (ering->tx_pending > TG3_TX_RING_SIZE - 1))
  6904. return -EINVAL;
  6905. if (netif_running(dev)) {
  6906. tg3_netif_stop(tp);
  6907. irq_sync = 1;
  6908. }
  6909. tg3_full_lock(tp, irq_sync);
  6910. tp->rx_pending = ering->rx_pending;
  6911. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6912. tp->rx_pending > 63)
  6913. tp->rx_pending = 63;
  6914. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6915. tp->tx_pending = ering->tx_pending;
  6916. if (netif_running(dev)) {
  6917. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6918. err = tg3_restart_hw(tp, 1);
  6919. if (!err)
  6920. tg3_netif_start(tp);
  6921. }
  6922. tg3_full_unlock(tp);
  6923. return err;
  6924. }
  6925. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6926. {
  6927. struct tg3 *tp = netdev_priv(dev);
  6928. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  6929. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  6930. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  6931. }
  6932. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6933. {
  6934. struct tg3 *tp = netdev_priv(dev);
  6935. int irq_sync = 0, err = 0;
  6936. if (netif_running(dev)) {
  6937. tg3_netif_stop(tp);
  6938. irq_sync = 1;
  6939. }
  6940. tg3_full_lock(tp, irq_sync);
  6941. if (epause->autoneg)
  6942. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  6943. else
  6944. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  6945. if (epause->rx_pause)
  6946. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  6947. else
  6948. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  6949. if (epause->tx_pause)
  6950. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  6951. else
  6952. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  6953. if (netif_running(dev)) {
  6954. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6955. err = tg3_restart_hw(tp, 1);
  6956. if (!err)
  6957. tg3_netif_start(tp);
  6958. }
  6959. tg3_full_unlock(tp);
  6960. return err;
  6961. }
  6962. static u32 tg3_get_rx_csum(struct net_device *dev)
  6963. {
  6964. struct tg3 *tp = netdev_priv(dev);
  6965. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  6966. }
  6967. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  6968. {
  6969. struct tg3 *tp = netdev_priv(dev);
  6970. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  6971. if (data != 0)
  6972. return -EINVAL;
  6973. return 0;
  6974. }
  6975. spin_lock_bh(&tp->lock);
  6976. if (data)
  6977. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  6978. else
  6979. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  6980. spin_unlock_bh(&tp->lock);
  6981. return 0;
  6982. }
  6983. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  6984. {
  6985. struct tg3 *tp = netdev_priv(dev);
  6986. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  6987. if (data != 0)
  6988. return -EINVAL;
  6989. return 0;
  6990. }
  6991. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  6992. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  6993. ethtool_op_set_tx_hw_csum(dev, data);
  6994. else
  6995. ethtool_op_set_tx_csum(dev, data);
  6996. return 0;
  6997. }
  6998. static int tg3_get_stats_count (struct net_device *dev)
  6999. {
  7000. return TG3_NUM_STATS;
  7001. }
  7002. static int tg3_get_test_count (struct net_device *dev)
  7003. {
  7004. return TG3_NUM_TEST;
  7005. }
  7006. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7007. {
  7008. switch (stringset) {
  7009. case ETH_SS_STATS:
  7010. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7011. break;
  7012. case ETH_SS_TEST:
  7013. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7014. break;
  7015. default:
  7016. WARN_ON(1); /* we need a WARN() */
  7017. break;
  7018. }
  7019. }
  7020. static int tg3_phys_id(struct net_device *dev, u32 data)
  7021. {
  7022. struct tg3 *tp = netdev_priv(dev);
  7023. int i;
  7024. if (!netif_running(tp->dev))
  7025. return -EAGAIN;
  7026. if (data == 0)
  7027. data = 2;
  7028. for (i = 0; i < (data * 2); i++) {
  7029. if ((i % 2) == 0)
  7030. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7031. LED_CTRL_1000MBPS_ON |
  7032. LED_CTRL_100MBPS_ON |
  7033. LED_CTRL_10MBPS_ON |
  7034. LED_CTRL_TRAFFIC_OVERRIDE |
  7035. LED_CTRL_TRAFFIC_BLINK |
  7036. LED_CTRL_TRAFFIC_LED);
  7037. else
  7038. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7039. LED_CTRL_TRAFFIC_OVERRIDE);
  7040. if (msleep_interruptible(500))
  7041. break;
  7042. }
  7043. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7044. return 0;
  7045. }
  7046. static void tg3_get_ethtool_stats (struct net_device *dev,
  7047. struct ethtool_stats *estats, u64 *tmp_stats)
  7048. {
  7049. struct tg3 *tp = netdev_priv(dev);
  7050. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7051. }
  7052. #define NVRAM_TEST_SIZE 0x100
  7053. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  7054. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7055. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7056. static int tg3_test_nvram(struct tg3 *tp)
  7057. {
  7058. u32 *buf, csum, magic;
  7059. int i, j, err = 0, size;
  7060. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7061. return -EIO;
  7062. if (magic == TG3_EEPROM_MAGIC)
  7063. size = NVRAM_TEST_SIZE;
  7064. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7065. if ((magic & 0xe00000) == 0x200000)
  7066. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  7067. else
  7068. return 0;
  7069. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7070. size = NVRAM_SELFBOOT_HW_SIZE;
  7071. else
  7072. return -EIO;
  7073. buf = kmalloc(size, GFP_KERNEL);
  7074. if (buf == NULL)
  7075. return -ENOMEM;
  7076. err = -EIO;
  7077. for (i = 0, j = 0; i < size; i += 4, j++) {
  7078. u32 val;
  7079. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7080. break;
  7081. buf[j] = cpu_to_le32(val);
  7082. }
  7083. if (i < size)
  7084. goto out;
  7085. /* Selfboot format */
  7086. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
  7087. TG3_EEPROM_MAGIC_FW) {
  7088. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7089. for (i = 0; i < size; i++)
  7090. csum8 += buf8[i];
  7091. if (csum8 == 0) {
  7092. err = 0;
  7093. goto out;
  7094. }
  7095. err = -EIO;
  7096. goto out;
  7097. }
  7098. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
  7099. TG3_EEPROM_MAGIC_HW) {
  7100. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7101. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7102. u8 *buf8 = (u8 *) buf;
  7103. int j, k;
  7104. /* Separate the parity bits and the data bytes. */
  7105. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7106. if ((i == 0) || (i == 8)) {
  7107. int l;
  7108. u8 msk;
  7109. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7110. parity[k++] = buf8[i] & msk;
  7111. i++;
  7112. }
  7113. else if (i == 16) {
  7114. int l;
  7115. u8 msk;
  7116. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7117. parity[k++] = buf8[i] & msk;
  7118. i++;
  7119. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7120. parity[k++] = buf8[i] & msk;
  7121. i++;
  7122. }
  7123. data[j++] = buf8[i];
  7124. }
  7125. err = -EIO;
  7126. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7127. u8 hw8 = hweight8(data[i]);
  7128. if ((hw8 & 0x1) && parity[i])
  7129. goto out;
  7130. else if (!(hw8 & 0x1) && !parity[i])
  7131. goto out;
  7132. }
  7133. err = 0;
  7134. goto out;
  7135. }
  7136. /* Bootstrap checksum at offset 0x10 */
  7137. csum = calc_crc((unsigned char *) buf, 0x10);
  7138. if(csum != cpu_to_le32(buf[0x10/4]))
  7139. goto out;
  7140. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7141. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7142. if (csum != cpu_to_le32(buf[0xfc/4]))
  7143. goto out;
  7144. err = 0;
  7145. out:
  7146. kfree(buf);
  7147. return err;
  7148. }
  7149. #define TG3_SERDES_TIMEOUT_SEC 2
  7150. #define TG3_COPPER_TIMEOUT_SEC 6
  7151. static int tg3_test_link(struct tg3 *tp)
  7152. {
  7153. int i, max;
  7154. if (!netif_running(tp->dev))
  7155. return -ENODEV;
  7156. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7157. max = TG3_SERDES_TIMEOUT_SEC;
  7158. else
  7159. max = TG3_COPPER_TIMEOUT_SEC;
  7160. for (i = 0; i < max; i++) {
  7161. if (netif_carrier_ok(tp->dev))
  7162. return 0;
  7163. if (msleep_interruptible(1000))
  7164. break;
  7165. }
  7166. return -EIO;
  7167. }
  7168. /* Only test the commonly used registers */
  7169. static int tg3_test_registers(struct tg3 *tp)
  7170. {
  7171. int i, is_5705, is_5750;
  7172. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7173. static struct {
  7174. u16 offset;
  7175. u16 flags;
  7176. #define TG3_FL_5705 0x1
  7177. #define TG3_FL_NOT_5705 0x2
  7178. #define TG3_FL_NOT_5788 0x4
  7179. #define TG3_FL_NOT_5750 0x8
  7180. u32 read_mask;
  7181. u32 write_mask;
  7182. } reg_tbl[] = {
  7183. /* MAC Control Registers */
  7184. { MAC_MODE, TG3_FL_NOT_5705,
  7185. 0x00000000, 0x00ef6f8c },
  7186. { MAC_MODE, TG3_FL_5705,
  7187. 0x00000000, 0x01ef6b8c },
  7188. { MAC_STATUS, TG3_FL_NOT_5705,
  7189. 0x03800107, 0x00000000 },
  7190. { MAC_STATUS, TG3_FL_5705,
  7191. 0x03800100, 0x00000000 },
  7192. { MAC_ADDR_0_HIGH, 0x0000,
  7193. 0x00000000, 0x0000ffff },
  7194. { MAC_ADDR_0_LOW, 0x0000,
  7195. 0x00000000, 0xffffffff },
  7196. { MAC_RX_MTU_SIZE, 0x0000,
  7197. 0x00000000, 0x0000ffff },
  7198. { MAC_TX_MODE, 0x0000,
  7199. 0x00000000, 0x00000070 },
  7200. { MAC_TX_LENGTHS, 0x0000,
  7201. 0x00000000, 0x00003fff },
  7202. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7203. 0x00000000, 0x000007fc },
  7204. { MAC_RX_MODE, TG3_FL_5705,
  7205. 0x00000000, 0x000007dc },
  7206. { MAC_HASH_REG_0, 0x0000,
  7207. 0x00000000, 0xffffffff },
  7208. { MAC_HASH_REG_1, 0x0000,
  7209. 0x00000000, 0xffffffff },
  7210. { MAC_HASH_REG_2, 0x0000,
  7211. 0x00000000, 0xffffffff },
  7212. { MAC_HASH_REG_3, 0x0000,
  7213. 0x00000000, 0xffffffff },
  7214. /* Receive Data and Receive BD Initiator Control Registers. */
  7215. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7216. 0x00000000, 0xffffffff },
  7217. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7218. 0x00000000, 0xffffffff },
  7219. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7220. 0x00000000, 0x00000003 },
  7221. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7222. 0x00000000, 0xffffffff },
  7223. { RCVDBDI_STD_BD+0, 0x0000,
  7224. 0x00000000, 0xffffffff },
  7225. { RCVDBDI_STD_BD+4, 0x0000,
  7226. 0x00000000, 0xffffffff },
  7227. { RCVDBDI_STD_BD+8, 0x0000,
  7228. 0x00000000, 0xffff0002 },
  7229. { RCVDBDI_STD_BD+0xc, 0x0000,
  7230. 0x00000000, 0xffffffff },
  7231. /* Receive BD Initiator Control Registers. */
  7232. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7233. 0x00000000, 0xffffffff },
  7234. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7235. 0x00000000, 0x000003ff },
  7236. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7237. 0x00000000, 0xffffffff },
  7238. /* Host Coalescing Control Registers. */
  7239. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7240. 0x00000000, 0x00000004 },
  7241. { HOSTCC_MODE, TG3_FL_5705,
  7242. 0x00000000, 0x000000f6 },
  7243. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7244. 0x00000000, 0xffffffff },
  7245. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7246. 0x00000000, 0x000003ff },
  7247. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7248. 0x00000000, 0xffffffff },
  7249. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7250. 0x00000000, 0x000003ff },
  7251. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7252. 0x00000000, 0xffffffff },
  7253. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7254. 0x00000000, 0x000000ff },
  7255. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7256. 0x00000000, 0xffffffff },
  7257. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7258. 0x00000000, 0x000000ff },
  7259. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7260. 0x00000000, 0xffffffff },
  7261. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7262. 0x00000000, 0xffffffff },
  7263. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7264. 0x00000000, 0xffffffff },
  7265. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7266. 0x00000000, 0x000000ff },
  7267. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7268. 0x00000000, 0xffffffff },
  7269. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7270. 0x00000000, 0x000000ff },
  7271. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7272. 0x00000000, 0xffffffff },
  7273. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7274. 0x00000000, 0xffffffff },
  7275. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7276. 0x00000000, 0xffffffff },
  7277. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7278. 0x00000000, 0xffffffff },
  7279. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7280. 0x00000000, 0xffffffff },
  7281. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7282. 0xffffffff, 0x00000000 },
  7283. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7284. 0xffffffff, 0x00000000 },
  7285. /* Buffer Manager Control Registers. */
  7286. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7287. 0x00000000, 0x007fff80 },
  7288. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7289. 0x00000000, 0x007fffff },
  7290. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7291. 0x00000000, 0x0000003f },
  7292. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7293. 0x00000000, 0x000001ff },
  7294. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7295. 0x00000000, 0x000001ff },
  7296. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7297. 0xffffffff, 0x00000000 },
  7298. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7299. 0xffffffff, 0x00000000 },
  7300. /* Mailbox Registers */
  7301. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7302. 0x00000000, 0x000001ff },
  7303. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7304. 0x00000000, 0x000001ff },
  7305. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7306. 0x00000000, 0x000007ff },
  7307. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7308. 0x00000000, 0x000001ff },
  7309. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7310. };
  7311. is_5705 = is_5750 = 0;
  7312. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7313. is_5705 = 1;
  7314. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7315. is_5750 = 1;
  7316. }
  7317. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7318. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7319. continue;
  7320. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7321. continue;
  7322. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7323. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7324. continue;
  7325. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7326. continue;
  7327. offset = (u32) reg_tbl[i].offset;
  7328. read_mask = reg_tbl[i].read_mask;
  7329. write_mask = reg_tbl[i].write_mask;
  7330. /* Save the original register content */
  7331. save_val = tr32(offset);
  7332. /* Determine the read-only value. */
  7333. read_val = save_val & read_mask;
  7334. /* Write zero to the register, then make sure the read-only bits
  7335. * are not changed and the read/write bits are all zeros.
  7336. */
  7337. tw32(offset, 0);
  7338. val = tr32(offset);
  7339. /* Test the read-only and read/write bits. */
  7340. if (((val & read_mask) != read_val) || (val & write_mask))
  7341. goto out;
  7342. /* Write ones to all the bits defined by RdMask and WrMask, then
  7343. * make sure the read-only bits are not changed and the
  7344. * read/write bits are all ones.
  7345. */
  7346. tw32(offset, read_mask | write_mask);
  7347. val = tr32(offset);
  7348. /* Test the read-only bits. */
  7349. if ((val & read_mask) != read_val)
  7350. goto out;
  7351. /* Test the read/write bits. */
  7352. if ((val & write_mask) != write_mask)
  7353. goto out;
  7354. tw32(offset, save_val);
  7355. }
  7356. return 0;
  7357. out:
  7358. printk(KERN_ERR PFX "Register test failed at offset %x\n", offset);
  7359. tw32(offset, save_val);
  7360. return -EIO;
  7361. }
  7362. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7363. {
  7364. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7365. int i;
  7366. u32 j;
  7367. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7368. for (j = 0; j < len; j += 4) {
  7369. u32 val;
  7370. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7371. tg3_read_mem(tp, offset + j, &val);
  7372. if (val != test_pattern[i])
  7373. return -EIO;
  7374. }
  7375. }
  7376. return 0;
  7377. }
  7378. static int tg3_test_memory(struct tg3 *tp)
  7379. {
  7380. static struct mem_entry {
  7381. u32 offset;
  7382. u32 len;
  7383. } mem_tbl_570x[] = {
  7384. { 0x00000000, 0x00b50},
  7385. { 0x00002000, 0x1c000},
  7386. { 0xffffffff, 0x00000}
  7387. }, mem_tbl_5705[] = {
  7388. { 0x00000100, 0x0000c},
  7389. { 0x00000200, 0x00008},
  7390. { 0x00004000, 0x00800},
  7391. { 0x00006000, 0x01000},
  7392. { 0x00008000, 0x02000},
  7393. { 0x00010000, 0x0e000},
  7394. { 0xffffffff, 0x00000}
  7395. }, mem_tbl_5755[] = {
  7396. { 0x00000200, 0x00008},
  7397. { 0x00004000, 0x00800},
  7398. { 0x00006000, 0x00800},
  7399. { 0x00008000, 0x02000},
  7400. { 0x00010000, 0x0c000},
  7401. { 0xffffffff, 0x00000}
  7402. }, mem_tbl_5906[] = {
  7403. { 0x00000200, 0x00008},
  7404. { 0x00004000, 0x00400},
  7405. { 0x00006000, 0x00400},
  7406. { 0x00008000, 0x01000},
  7407. { 0x00010000, 0x01000},
  7408. { 0xffffffff, 0x00000}
  7409. };
  7410. struct mem_entry *mem_tbl;
  7411. int err = 0;
  7412. int i;
  7413. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7414. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7415. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7416. mem_tbl = mem_tbl_5755;
  7417. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7418. mem_tbl = mem_tbl_5906;
  7419. else
  7420. mem_tbl = mem_tbl_5705;
  7421. } else
  7422. mem_tbl = mem_tbl_570x;
  7423. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7424. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7425. mem_tbl[i].len)) != 0)
  7426. break;
  7427. }
  7428. return err;
  7429. }
  7430. #define TG3_MAC_LOOPBACK 0
  7431. #define TG3_PHY_LOOPBACK 1
  7432. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7433. {
  7434. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7435. u32 desc_idx;
  7436. struct sk_buff *skb, *rx_skb;
  7437. u8 *tx_data;
  7438. dma_addr_t map;
  7439. int num_pkts, tx_len, rx_len, i, err;
  7440. struct tg3_rx_buffer_desc *desc;
  7441. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7442. /* HW errata - mac loopback fails in some cases on 5780.
  7443. * Normal traffic and PHY loopback are not affected by
  7444. * errata.
  7445. */
  7446. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7447. return 0;
  7448. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7449. MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
  7450. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7451. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7452. else
  7453. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7454. tw32(MAC_MODE, mac_mode);
  7455. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7456. u32 val;
  7457. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7458. u32 phytest;
  7459. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7460. u32 phy;
  7461. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7462. phytest | MII_TG3_EPHY_SHADOW_EN);
  7463. if (!tg3_readphy(tp, 0x1b, &phy))
  7464. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7465. if (!tg3_readphy(tp, 0x10, &phy))
  7466. tg3_writephy(tp, 0x10, phy & ~0x4000);
  7467. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7468. }
  7469. }
  7470. val = BMCR_LOOPBACK | BMCR_FULLDPLX;
  7471. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7472. val |= BMCR_SPEED100;
  7473. else
  7474. val |= BMCR_SPEED1000;
  7475. tg3_writephy(tp, MII_BMCR, val);
  7476. udelay(40);
  7477. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7478. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7479. /* reset to prevent losing 1st rx packet intermittently */
  7480. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7481. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7482. udelay(10);
  7483. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7484. }
  7485. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7486. MAC_MODE_LINK_POLARITY;
  7487. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7488. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7489. else
  7490. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7491. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  7492. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7493. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7494. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7495. }
  7496. tw32(MAC_MODE, mac_mode);
  7497. }
  7498. else
  7499. return -EINVAL;
  7500. err = -EIO;
  7501. tx_len = 1514;
  7502. skb = netdev_alloc_skb(tp->dev, tx_len);
  7503. if (!skb)
  7504. return -ENOMEM;
  7505. tx_data = skb_put(skb, tx_len);
  7506. memcpy(tx_data, tp->dev->dev_addr, 6);
  7507. memset(tx_data + 6, 0x0, 8);
  7508. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7509. for (i = 14; i < tx_len; i++)
  7510. tx_data[i] = (u8) (i & 0xff);
  7511. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7512. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7513. HOSTCC_MODE_NOW);
  7514. udelay(10);
  7515. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7516. num_pkts = 0;
  7517. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7518. tp->tx_prod++;
  7519. num_pkts++;
  7520. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7521. tp->tx_prod);
  7522. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7523. udelay(10);
  7524. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  7525. for (i = 0; i < 25; i++) {
  7526. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7527. HOSTCC_MODE_NOW);
  7528. udelay(10);
  7529. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7530. rx_idx = tp->hw_status->idx[0].rx_producer;
  7531. if ((tx_idx == tp->tx_prod) &&
  7532. (rx_idx == (rx_start_idx + num_pkts)))
  7533. break;
  7534. }
  7535. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7536. dev_kfree_skb(skb);
  7537. if (tx_idx != tp->tx_prod)
  7538. goto out;
  7539. if (rx_idx != rx_start_idx + num_pkts)
  7540. goto out;
  7541. desc = &tp->rx_rcb[rx_start_idx];
  7542. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7543. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7544. if (opaque_key != RXD_OPAQUE_RING_STD)
  7545. goto out;
  7546. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7547. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7548. goto out;
  7549. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7550. if (rx_len != tx_len)
  7551. goto out;
  7552. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7553. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7554. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7555. for (i = 14; i < tx_len; i++) {
  7556. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7557. goto out;
  7558. }
  7559. err = 0;
  7560. /* tg3_free_rings will unmap and free the rx_skb */
  7561. out:
  7562. return err;
  7563. }
  7564. #define TG3_MAC_LOOPBACK_FAILED 1
  7565. #define TG3_PHY_LOOPBACK_FAILED 2
  7566. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7567. TG3_PHY_LOOPBACK_FAILED)
  7568. static int tg3_test_loopback(struct tg3 *tp)
  7569. {
  7570. int err = 0;
  7571. if (!netif_running(tp->dev))
  7572. return TG3_LOOPBACK_FAILED;
  7573. err = tg3_reset_hw(tp, 1);
  7574. if (err)
  7575. return TG3_LOOPBACK_FAILED;
  7576. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7577. err |= TG3_MAC_LOOPBACK_FAILED;
  7578. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7579. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7580. err |= TG3_PHY_LOOPBACK_FAILED;
  7581. }
  7582. return err;
  7583. }
  7584. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7585. u64 *data)
  7586. {
  7587. struct tg3 *tp = netdev_priv(dev);
  7588. if (tp->link_config.phy_is_low_power)
  7589. tg3_set_power_state(tp, PCI_D0);
  7590. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7591. if (tg3_test_nvram(tp) != 0) {
  7592. etest->flags |= ETH_TEST_FL_FAILED;
  7593. data[0] = 1;
  7594. }
  7595. if (tg3_test_link(tp) != 0) {
  7596. etest->flags |= ETH_TEST_FL_FAILED;
  7597. data[1] = 1;
  7598. }
  7599. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7600. int err, irq_sync = 0;
  7601. if (netif_running(dev)) {
  7602. tg3_netif_stop(tp);
  7603. irq_sync = 1;
  7604. }
  7605. tg3_full_lock(tp, irq_sync);
  7606. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7607. err = tg3_nvram_lock(tp);
  7608. tg3_halt_cpu(tp, RX_CPU_BASE);
  7609. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7610. tg3_halt_cpu(tp, TX_CPU_BASE);
  7611. if (!err)
  7612. tg3_nvram_unlock(tp);
  7613. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7614. tg3_phy_reset(tp);
  7615. if (tg3_test_registers(tp) != 0) {
  7616. etest->flags |= ETH_TEST_FL_FAILED;
  7617. data[2] = 1;
  7618. }
  7619. if (tg3_test_memory(tp) != 0) {
  7620. etest->flags |= ETH_TEST_FL_FAILED;
  7621. data[3] = 1;
  7622. }
  7623. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7624. etest->flags |= ETH_TEST_FL_FAILED;
  7625. tg3_full_unlock(tp);
  7626. if (tg3_test_interrupt(tp) != 0) {
  7627. etest->flags |= ETH_TEST_FL_FAILED;
  7628. data[5] = 1;
  7629. }
  7630. tg3_full_lock(tp, 0);
  7631. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7632. if (netif_running(dev)) {
  7633. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7634. if (!tg3_restart_hw(tp, 1))
  7635. tg3_netif_start(tp);
  7636. }
  7637. tg3_full_unlock(tp);
  7638. }
  7639. if (tp->link_config.phy_is_low_power)
  7640. tg3_set_power_state(tp, PCI_D3hot);
  7641. }
  7642. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7643. {
  7644. struct mii_ioctl_data *data = if_mii(ifr);
  7645. struct tg3 *tp = netdev_priv(dev);
  7646. int err;
  7647. switch(cmd) {
  7648. case SIOCGMIIPHY:
  7649. data->phy_id = PHY_ADDR;
  7650. /* fallthru */
  7651. case SIOCGMIIREG: {
  7652. u32 mii_regval;
  7653. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7654. break; /* We have no PHY */
  7655. if (tp->link_config.phy_is_low_power)
  7656. return -EAGAIN;
  7657. spin_lock_bh(&tp->lock);
  7658. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7659. spin_unlock_bh(&tp->lock);
  7660. data->val_out = mii_regval;
  7661. return err;
  7662. }
  7663. case SIOCSMIIREG:
  7664. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7665. break; /* We have no PHY */
  7666. if (!capable(CAP_NET_ADMIN))
  7667. return -EPERM;
  7668. if (tp->link_config.phy_is_low_power)
  7669. return -EAGAIN;
  7670. spin_lock_bh(&tp->lock);
  7671. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7672. spin_unlock_bh(&tp->lock);
  7673. return err;
  7674. default:
  7675. /* do nothing */
  7676. break;
  7677. }
  7678. return -EOPNOTSUPP;
  7679. }
  7680. #if TG3_VLAN_TAG_USED
  7681. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7682. {
  7683. struct tg3 *tp = netdev_priv(dev);
  7684. if (netif_running(dev))
  7685. tg3_netif_stop(tp);
  7686. tg3_full_lock(tp, 0);
  7687. tp->vlgrp = grp;
  7688. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7689. __tg3_set_rx_mode(dev);
  7690. tg3_full_unlock(tp);
  7691. if (netif_running(dev))
  7692. tg3_netif_start(tp);
  7693. }
  7694. static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  7695. {
  7696. struct tg3 *tp = netdev_priv(dev);
  7697. if (netif_running(dev))
  7698. tg3_netif_stop(tp);
  7699. tg3_full_lock(tp, 0);
  7700. if (tp->vlgrp)
  7701. tp->vlgrp->vlan_devices[vid] = NULL;
  7702. tg3_full_unlock(tp);
  7703. if (netif_running(dev))
  7704. tg3_netif_start(tp);
  7705. }
  7706. #endif
  7707. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7708. {
  7709. struct tg3 *tp = netdev_priv(dev);
  7710. memcpy(ec, &tp->coal, sizeof(*ec));
  7711. return 0;
  7712. }
  7713. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7714. {
  7715. struct tg3 *tp = netdev_priv(dev);
  7716. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7717. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7718. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7719. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7720. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7721. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7722. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7723. }
  7724. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7725. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7726. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7727. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7728. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7729. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7730. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7731. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7732. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7733. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7734. return -EINVAL;
  7735. /* No rx interrupts will be generated if both are zero */
  7736. if ((ec->rx_coalesce_usecs == 0) &&
  7737. (ec->rx_max_coalesced_frames == 0))
  7738. return -EINVAL;
  7739. /* No tx interrupts will be generated if both are zero */
  7740. if ((ec->tx_coalesce_usecs == 0) &&
  7741. (ec->tx_max_coalesced_frames == 0))
  7742. return -EINVAL;
  7743. /* Only copy relevant parameters, ignore all others. */
  7744. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7745. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7746. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7747. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7748. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7749. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7750. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7751. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7752. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7753. if (netif_running(dev)) {
  7754. tg3_full_lock(tp, 0);
  7755. __tg3_set_coalesce(tp, &tp->coal);
  7756. tg3_full_unlock(tp);
  7757. }
  7758. return 0;
  7759. }
  7760. static const struct ethtool_ops tg3_ethtool_ops = {
  7761. .get_settings = tg3_get_settings,
  7762. .set_settings = tg3_set_settings,
  7763. .get_drvinfo = tg3_get_drvinfo,
  7764. .get_regs_len = tg3_get_regs_len,
  7765. .get_regs = tg3_get_regs,
  7766. .get_wol = tg3_get_wol,
  7767. .set_wol = tg3_set_wol,
  7768. .get_msglevel = tg3_get_msglevel,
  7769. .set_msglevel = tg3_set_msglevel,
  7770. .nway_reset = tg3_nway_reset,
  7771. .get_link = ethtool_op_get_link,
  7772. .get_eeprom_len = tg3_get_eeprom_len,
  7773. .get_eeprom = tg3_get_eeprom,
  7774. .set_eeprom = tg3_set_eeprom,
  7775. .get_ringparam = tg3_get_ringparam,
  7776. .set_ringparam = tg3_set_ringparam,
  7777. .get_pauseparam = tg3_get_pauseparam,
  7778. .set_pauseparam = tg3_set_pauseparam,
  7779. .get_rx_csum = tg3_get_rx_csum,
  7780. .set_rx_csum = tg3_set_rx_csum,
  7781. .get_tx_csum = ethtool_op_get_tx_csum,
  7782. .set_tx_csum = tg3_set_tx_csum,
  7783. .get_sg = ethtool_op_get_sg,
  7784. .set_sg = ethtool_op_set_sg,
  7785. #if TG3_TSO_SUPPORT != 0
  7786. .get_tso = ethtool_op_get_tso,
  7787. .set_tso = tg3_set_tso,
  7788. #endif
  7789. .self_test_count = tg3_get_test_count,
  7790. .self_test = tg3_self_test,
  7791. .get_strings = tg3_get_strings,
  7792. .phys_id = tg3_phys_id,
  7793. .get_stats_count = tg3_get_stats_count,
  7794. .get_ethtool_stats = tg3_get_ethtool_stats,
  7795. .get_coalesce = tg3_get_coalesce,
  7796. .set_coalesce = tg3_set_coalesce,
  7797. .get_perm_addr = ethtool_op_get_perm_addr,
  7798. };
  7799. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7800. {
  7801. u32 cursize, val, magic;
  7802. tp->nvram_size = EEPROM_CHIP_SIZE;
  7803. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7804. return;
  7805. if ((magic != TG3_EEPROM_MAGIC) &&
  7806. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  7807. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  7808. return;
  7809. /*
  7810. * Size the chip by reading offsets at increasing powers of two.
  7811. * When we encounter our validation signature, we know the addressing
  7812. * has wrapped around, and thus have our chip size.
  7813. */
  7814. cursize = 0x10;
  7815. while (cursize < tp->nvram_size) {
  7816. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7817. return;
  7818. if (val == magic)
  7819. break;
  7820. cursize <<= 1;
  7821. }
  7822. tp->nvram_size = cursize;
  7823. }
  7824. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7825. {
  7826. u32 val;
  7827. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7828. return;
  7829. /* Selfboot format */
  7830. if (val != TG3_EEPROM_MAGIC) {
  7831. tg3_get_eeprom_size(tp);
  7832. return;
  7833. }
  7834. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7835. if (val != 0) {
  7836. tp->nvram_size = (val >> 16) * 1024;
  7837. return;
  7838. }
  7839. }
  7840. tp->nvram_size = 0x20000;
  7841. }
  7842. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7843. {
  7844. u32 nvcfg1;
  7845. nvcfg1 = tr32(NVRAM_CFG1);
  7846. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7847. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7848. }
  7849. else {
  7850. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7851. tw32(NVRAM_CFG1, nvcfg1);
  7852. }
  7853. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7854. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7855. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7856. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7857. tp->nvram_jedecnum = JEDEC_ATMEL;
  7858. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7859. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7860. break;
  7861. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7862. tp->nvram_jedecnum = JEDEC_ATMEL;
  7863. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7864. break;
  7865. case FLASH_VENDOR_ATMEL_EEPROM:
  7866. tp->nvram_jedecnum = JEDEC_ATMEL;
  7867. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7868. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7869. break;
  7870. case FLASH_VENDOR_ST:
  7871. tp->nvram_jedecnum = JEDEC_ST;
  7872. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7873. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7874. break;
  7875. case FLASH_VENDOR_SAIFUN:
  7876. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7877. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7878. break;
  7879. case FLASH_VENDOR_SST_SMALL:
  7880. case FLASH_VENDOR_SST_LARGE:
  7881. tp->nvram_jedecnum = JEDEC_SST;
  7882. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7883. break;
  7884. }
  7885. }
  7886. else {
  7887. tp->nvram_jedecnum = JEDEC_ATMEL;
  7888. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7889. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7890. }
  7891. }
  7892. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7893. {
  7894. u32 nvcfg1;
  7895. nvcfg1 = tr32(NVRAM_CFG1);
  7896. /* NVRAM protection for TPM */
  7897. if (nvcfg1 & (1 << 27))
  7898. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7899. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7900. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7901. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7902. tp->nvram_jedecnum = JEDEC_ATMEL;
  7903. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7904. break;
  7905. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7906. tp->nvram_jedecnum = JEDEC_ATMEL;
  7907. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7908. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7909. break;
  7910. case FLASH_5752VENDOR_ST_M45PE10:
  7911. case FLASH_5752VENDOR_ST_M45PE20:
  7912. case FLASH_5752VENDOR_ST_M45PE40:
  7913. tp->nvram_jedecnum = JEDEC_ST;
  7914. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7915. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7916. break;
  7917. }
  7918. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7919. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7920. case FLASH_5752PAGE_SIZE_256:
  7921. tp->nvram_pagesize = 256;
  7922. break;
  7923. case FLASH_5752PAGE_SIZE_512:
  7924. tp->nvram_pagesize = 512;
  7925. break;
  7926. case FLASH_5752PAGE_SIZE_1K:
  7927. tp->nvram_pagesize = 1024;
  7928. break;
  7929. case FLASH_5752PAGE_SIZE_2K:
  7930. tp->nvram_pagesize = 2048;
  7931. break;
  7932. case FLASH_5752PAGE_SIZE_4K:
  7933. tp->nvram_pagesize = 4096;
  7934. break;
  7935. case FLASH_5752PAGE_SIZE_264:
  7936. tp->nvram_pagesize = 264;
  7937. break;
  7938. }
  7939. }
  7940. else {
  7941. /* For eeprom, set pagesize to maximum eeprom size */
  7942. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7943. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7944. tw32(NVRAM_CFG1, nvcfg1);
  7945. }
  7946. }
  7947. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  7948. {
  7949. u32 nvcfg1;
  7950. nvcfg1 = tr32(NVRAM_CFG1);
  7951. /* NVRAM protection for TPM */
  7952. if (nvcfg1 & (1 << 27))
  7953. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7954. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7955. case FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ:
  7956. case FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ:
  7957. tp->nvram_jedecnum = JEDEC_ATMEL;
  7958. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7959. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7960. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7961. tw32(NVRAM_CFG1, nvcfg1);
  7962. break;
  7963. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7964. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7965. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  7966. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  7967. case FLASH_5755VENDOR_ATMEL_FLASH_4:
  7968. tp->nvram_jedecnum = JEDEC_ATMEL;
  7969. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7970. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7971. tp->nvram_pagesize = 264;
  7972. break;
  7973. case FLASH_5752VENDOR_ST_M45PE10:
  7974. case FLASH_5752VENDOR_ST_M45PE20:
  7975. case FLASH_5752VENDOR_ST_M45PE40:
  7976. tp->nvram_jedecnum = JEDEC_ST;
  7977. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7978. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7979. tp->nvram_pagesize = 256;
  7980. break;
  7981. }
  7982. }
  7983. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  7984. {
  7985. u32 nvcfg1;
  7986. nvcfg1 = tr32(NVRAM_CFG1);
  7987. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7988. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  7989. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  7990. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  7991. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  7992. tp->nvram_jedecnum = JEDEC_ATMEL;
  7993. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7994. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7995. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7996. tw32(NVRAM_CFG1, nvcfg1);
  7997. break;
  7998. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7999. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8000. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8001. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8002. tp->nvram_jedecnum = JEDEC_ATMEL;
  8003. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8004. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8005. tp->nvram_pagesize = 264;
  8006. break;
  8007. case FLASH_5752VENDOR_ST_M45PE10:
  8008. case FLASH_5752VENDOR_ST_M45PE20:
  8009. case FLASH_5752VENDOR_ST_M45PE40:
  8010. tp->nvram_jedecnum = JEDEC_ST;
  8011. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8012. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8013. tp->nvram_pagesize = 256;
  8014. break;
  8015. }
  8016. }
  8017. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8018. {
  8019. tp->nvram_jedecnum = JEDEC_ATMEL;
  8020. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8021. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8022. }
  8023. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8024. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8025. {
  8026. int j;
  8027. tw32_f(GRC_EEPROM_ADDR,
  8028. (EEPROM_ADDR_FSM_RESET |
  8029. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8030. EEPROM_ADDR_CLKPERD_SHIFT)));
  8031. /* XXX schedule_timeout() ... */
  8032. for (j = 0; j < 100; j++)
  8033. udelay(10);
  8034. /* Enable seeprom accesses. */
  8035. tw32_f(GRC_LOCAL_CTRL,
  8036. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8037. udelay(100);
  8038. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8039. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8040. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8041. if (tg3_nvram_lock(tp)) {
  8042. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8043. "tg3_nvram_init failed.\n", tp->dev->name);
  8044. return;
  8045. }
  8046. tg3_enable_nvram_access(tp);
  8047. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8048. tg3_get_5752_nvram_info(tp);
  8049. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8050. tg3_get_5755_nvram_info(tp);
  8051. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8052. tg3_get_5787_nvram_info(tp);
  8053. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8054. tg3_get_5906_nvram_info(tp);
  8055. else
  8056. tg3_get_nvram_info(tp);
  8057. tg3_get_nvram_size(tp);
  8058. tg3_disable_nvram_access(tp);
  8059. tg3_nvram_unlock(tp);
  8060. } else {
  8061. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8062. tg3_get_eeprom_size(tp);
  8063. }
  8064. }
  8065. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8066. u32 offset, u32 *val)
  8067. {
  8068. u32 tmp;
  8069. int i;
  8070. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8071. (offset % 4) != 0)
  8072. return -EINVAL;
  8073. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8074. EEPROM_ADDR_DEVID_MASK |
  8075. EEPROM_ADDR_READ);
  8076. tw32(GRC_EEPROM_ADDR,
  8077. tmp |
  8078. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8079. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8080. EEPROM_ADDR_ADDR_MASK) |
  8081. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8082. for (i = 0; i < 10000; i++) {
  8083. tmp = tr32(GRC_EEPROM_ADDR);
  8084. if (tmp & EEPROM_ADDR_COMPLETE)
  8085. break;
  8086. udelay(100);
  8087. }
  8088. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8089. return -EBUSY;
  8090. *val = tr32(GRC_EEPROM_DATA);
  8091. return 0;
  8092. }
  8093. #define NVRAM_CMD_TIMEOUT 10000
  8094. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8095. {
  8096. int i;
  8097. tw32(NVRAM_CMD, nvram_cmd);
  8098. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8099. udelay(10);
  8100. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8101. udelay(10);
  8102. break;
  8103. }
  8104. }
  8105. if (i == NVRAM_CMD_TIMEOUT) {
  8106. return -EBUSY;
  8107. }
  8108. return 0;
  8109. }
  8110. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8111. {
  8112. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8113. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8114. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8115. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8116. addr = ((addr / tp->nvram_pagesize) <<
  8117. ATMEL_AT45DB0X1B_PAGE_POS) +
  8118. (addr % tp->nvram_pagesize);
  8119. return addr;
  8120. }
  8121. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8122. {
  8123. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8124. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8125. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8126. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8127. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8128. tp->nvram_pagesize) +
  8129. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8130. return addr;
  8131. }
  8132. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8133. {
  8134. int ret;
  8135. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8136. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8137. offset = tg3_nvram_phys_addr(tp, offset);
  8138. if (offset > NVRAM_ADDR_MSK)
  8139. return -EINVAL;
  8140. ret = tg3_nvram_lock(tp);
  8141. if (ret)
  8142. return ret;
  8143. tg3_enable_nvram_access(tp);
  8144. tw32(NVRAM_ADDR, offset);
  8145. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8146. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8147. if (ret == 0)
  8148. *val = swab32(tr32(NVRAM_RDDATA));
  8149. tg3_disable_nvram_access(tp);
  8150. tg3_nvram_unlock(tp);
  8151. return ret;
  8152. }
  8153. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8154. {
  8155. int err;
  8156. u32 tmp;
  8157. err = tg3_nvram_read(tp, offset, &tmp);
  8158. *val = swab32(tmp);
  8159. return err;
  8160. }
  8161. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8162. u32 offset, u32 len, u8 *buf)
  8163. {
  8164. int i, j, rc = 0;
  8165. u32 val;
  8166. for (i = 0; i < len; i += 4) {
  8167. u32 addr, data;
  8168. addr = offset + i;
  8169. memcpy(&data, buf + i, 4);
  8170. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8171. val = tr32(GRC_EEPROM_ADDR);
  8172. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8173. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8174. EEPROM_ADDR_READ);
  8175. tw32(GRC_EEPROM_ADDR, val |
  8176. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8177. (addr & EEPROM_ADDR_ADDR_MASK) |
  8178. EEPROM_ADDR_START |
  8179. EEPROM_ADDR_WRITE);
  8180. for (j = 0; j < 10000; j++) {
  8181. val = tr32(GRC_EEPROM_ADDR);
  8182. if (val & EEPROM_ADDR_COMPLETE)
  8183. break;
  8184. udelay(100);
  8185. }
  8186. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8187. rc = -EBUSY;
  8188. break;
  8189. }
  8190. }
  8191. return rc;
  8192. }
  8193. /* offset and length are dword aligned */
  8194. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8195. u8 *buf)
  8196. {
  8197. int ret = 0;
  8198. u32 pagesize = tp->nvram_pagesize;
  8199. u32 pagemask = pagesize - 1;
  8200. u32 nvram_cmd;
  8201. u8 *tmp;
  8202. tmp = kmalloc(pagesize, GFP_KERNEL);
  8203. if (tmp == NULL)
  8204. return -ENOMEM;
  8205. while (len) {
  8206. int j;
  8207. u32 phy_addr, page_off, size;
  8208. phy_addr = offset & ~pagemask;
  8209. for (j = 0; j < pagesize; j += 4) {
  8210. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8211. (u32 *) (tmp + j))))
  8212. break;
  8213. }
  8214. if (ret)
  8215. break;
  8216. page_off = offset & pagemask;
  8217. size = pagesize;
  8218. if (len < size)
  8219. size = len;
  8220. len -= size;
  8221. memcpy(tmp + page_off, buf, size);
  8222. offset = offset + (pagesize - page_off);
  8223. tg3_enable_nvram_access(tp);
  8224. /*
  8225. * Before we can erase the flash page, we need
  8226. * to issue a special "write enable" command.
  8227. */
  8228. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8229. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8230. break;
  8231. /* Erase the target page */
  8232. tw32(NVRAM_ADDR, phy_addr);
  8233. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8234. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8235. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8236. break;
  8237. /* Issue another write enable to start the write. */
  8238. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8239. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8240. break;
  8241. for (j = 0; j < pagesize; j += 4) {
  8242. u32 data;
  8243. data = *((u32 *) (tmp + j));
  8244. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8245. tw32(NVRAM_ADDR, phy_addr + j);
  8246. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8247. NVRAM_CMD_WR;
  8248. if (j == 0)
  8249. nvram_cmd |= NVRAM_CMD_FIRST;
  8250. else if (j == (pagesize - 4))
  8251. nvram_cmd |= NVRAM_CMD_LAST;
  8252. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8253. break;
  8254. }
  8255. if (ret)
  8256. break;
  8257. }
  8258. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8259. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8260. kfree(tmp);
  8261. return ret;
  8262. }
  8263. /* offset and length are dword aligned */
  8264. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8265. u8 *buf)
  8266. {
  8267. int i, ret = 0;
  8268. for (i = 0; i < len; i += 4, offset += 4) {
  8269. u32 data, page_off, phy_addr, nvram_cmd;
  8270. memcpy(&data, buf + i, 4);
  8271. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8272. page_off = offset % tp->nvram_pagesize;
  8273. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8274. tw32(NVRAM_ADDR, phy_addr);
  8275. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8276. if ((page_off == 0) || (i == 0))
  8277. nvram_cmd |= NVRAM_CMD_FIRST;
  8278. if (page_off == (tp->nvram_pagesize - 4))
  8279. nvram_cmd |= NVRAM_CMD_LAST;
  8280. if (i == (len - 4))
  8281. nvram_cmd |= NVRAM_CMD_LAST;
  8282. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8283. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8284. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8285. (tp->nvram_jedecnum == JEDEC_ST) &&
  8286. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8287. if ((ret = tg3_nvram_exec_cmd(tp,
  8288. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8289. NVRAM_CMD_DONE)))
  8290. break;
  8291. }
  8292. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8293. /* We always do complete word writes to eeprom. */
  8294. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8295. }
  8296. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8297. break;
  8298. }
  8299. return ret;
  8300. }
  8301. /* offset and length are dword aligned */
  8302. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8303. {
  8304. int ret;
  8305. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8306. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8307. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8308. udelay(40);
  8309. }
  8310. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8311. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8312. }
  8313. else {
  8314. u32 grc_mode;
  8315. ret = tg3_nvram_lock(tp);
  8316. if (ret)
  8317. return ret;
  8318. tg3_enable_nvram_access(tp);
  8319. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8320. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8321. tw32(NVRAM_WRITE1, 0x406);
  8322. grc_mode = tr32(GRC_MODE);
  8323. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8324. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8325. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8326. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8327. buf);
  8328. }
  8329. else {
  8330. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8331. buf);
  8332. }
  8333. grc_mode = tr32(GRC_MODE);
  8334. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8335. tg3_disable_nvram_access(tp);
  8336. tg3_nvram_unlock(tp);
  8337. }
  8338. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8339. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8340. udelay(40);
  8341. }
  8342. return ret;
  8343. }
  8344. struct subsys_tbl_ent {
  8345. u16 subsys_vendor, subsys_devid;
  8346. u32 phy_id;
  8347. };
  8348. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8349. /* Broadcom boards. */
  8350. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8351. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8352. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8353. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8354. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8355. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8356. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8357. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8358. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8359. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8360. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8361. /* 3com boards. */
  8362. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8363. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8364. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8365. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8366. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8367. /* DELL boards. */
  8368. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8369. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8370. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8371. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8372. /* Compaq boards. */
  8373. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8374. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8375. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8376. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8377. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8378. /* IBM boards. */
  8379. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8380. };
  8381. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8382. {
  8383. int i;
  8384. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8385. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8386. tp->pdev->subsystem_vendor) &&
  8387. (subsys_id_to_phy_id[i].subsys_devid ==
  8388. tp->pdev->subsystem_device))
  8389. return &subsys_id_to_phy_id[i];
  8390. }
  8391. return NULL;
  8392. }
  8393. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8394. {
  8395. u32 val;
  8396. u16 pmcsr;
  8397. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8398. * so need make sure we're in D0.
  8399. */
  8400. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8401. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8402. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8403. msleep(1);
  8404. /* Make sure register accesses (indirect or otherwise)
  8405. * will function correctly.
  8406. */
  8407. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8408. tp->misc_host_ctrl);
  8409. /* The memory arbiter has to be enabled in order for SRAM accesses
  8410. * to succeed. Normally on powerup the tg3 chip firmware will make
  8411. * sure it is enabled, but other entities such as system netboot
  8412. * code might disable it.
  8413. */
  8414. val = tr32(MEMARB_MODE);
  8415. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8416. tp->phy_id = PHY_ID_INVALID;
  8417. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8418. /* Assume an onboard device by default. */
  8419. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8420. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8421. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM))
  8422. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8423. return;
  8424. }
  8425. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8426. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8427. u32 nic_cfg, led_cfg;
  8428. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8429. int eeprom_phy_serdes = 0;
  8430. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8431. tp->nic_sram_data_cfg = nic_cfg;
  8432. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8433. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8434. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8435. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8436. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8437. (ver > 0) && (ver < 0x100))
  8438. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8439. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8440. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8441. eeprom_phy_serdes = 1;
  8442. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8443. if (nic_phy_id != 0) {
  8444. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8445. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8446. eeprom_phy_id = (id1 >> 16) << 10;
  8447. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8448. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8449. } else
  8450. eeprom_phy_id = 0;
  8451. tp->phy_id = eeprom_phy_id;
  8452. if (eeprom_phy_serdes) {
  8453. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8454. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8455. else
  8456. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8457. }
  8458. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8459. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8460. SHASTA_EXT_LED_MODE_MASK);
  8461. else
  8462. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8463. switch (led_cfg) {
  8464. default:
  8465. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8466. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8467. break;
  8468. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8469. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8470. break;
  8471. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8472. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8473. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8474. * read on some older 5700/5701 bootcode.
  8475. */
  8476. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8477. ASIC_REV_5700 ||
  8478. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8479. ASIC_REV_5701)
  8480. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8481. break;
  8482. case SHASTA_EXT_LED_SHARED:
  8483. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8484. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8485. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8486. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8487. LED_CTRL_MODE_PHY_2);
  8488. break;
  8489. case SHASTA_EXT_LED_MAC:
  8490. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8491. break;
  8492. case SHASTA_EXT_LED_COMBO:
  8493. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8494. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8495. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8496. LED_CTRL_MODE_PHY_2);
  8497. break;
  8498. };
  8499. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8500. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8501. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8502. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8503. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP)
  8504. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8505. else
  8506. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8507. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8508. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8509. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8510. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8511. }
  8512. if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
  8513. tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
  8514. if (cfg2 & (1 << 17))
  8515. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8516. /* serdes signal pre-emphasis in register 0x590 set by */
  8517. /* bootcode if bit 18 is set */
  8518. if (cfg2 & (1 << 18))
  8519. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8520. }
  8521. }
  8522. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8523. {
  8524. u32 hw_phy_id_1, hw_phy_id_2;
  8525. u32 hw_phy_id, hw_phy_id_masked;
  8526. int err;
  8527. /* Reading the PHY ID register can conflict with ASF
  8528. * firwmare access to the PHY hardware.
  8529. */
  8530. err = 0;
  8531. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8532. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8533. } else {
  8534. /* Now read the physical PHY_ID from the chip and verify
  8535. * that it is sane. If it doesn't look good, we fall back
  8536. * to either the hard-coded table based PHY_ID and failing
  8537. * that the value found in the eeprom area.
  8538. */
  8539. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8540. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8541. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8542. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8543. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8544. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8545. }
  8546. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8547. tp->phy_id = hw_phy_id;
  8548. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8549. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8550. else
  8551. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8552. } else {
  8553. if (tp->phy_id != PHY_ID_INVALID) {
  8554. /* Do nothing, phy ID already set up in
  8555. * tg3_get_eeprom_hw_cfg().
  8556. */
  8557. } else {
  8558. struct subsys_tbl_ent *p;
  8559. /* No eeprom signature? Try the hardcoded
  8560. * subsys device table.
  8561. */
  8562. p = lookup_by_subsys(tp);
  8563. if (!p)
  8564. return -ENODEV;
  8565. tp->phy_id = p->phy_id;
  8566. if (!tp->phy_id ||
  8567. tp->phy_id == PHY_ID_BCM8002)
  8568. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8569. }
  8570. }
  8571. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8572. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8573. u32 bmsr, adv_reg, tg3_ctrl;
  8574. tg3_readphy(tp, MII_BMSR, &bmsr);
  8575. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8576. (bmsr & BMSR_LSTATUS))
  8577. goto skip_phy_reset;
  8578. err = tg3_phy_reset(tp);
  8579. if (err)
  8580. return err;
  8581. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8582. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8583. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8584. tg3_ctrl = 0;
  8585. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8586. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8587. MII_TG3_CTRL_ADV_1000_FULL);
  8588. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8589. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8590. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8591. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8592. }
  8593. if (!tg3_copper_is_advertising_all(tp)) {
  8594. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8595. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8596. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8597. tg3_writephy(tp, MII_BMCR,
  8598. BMCR_ANENABLE | BMCR_ANRESTART);
  8599. }
  8600. tg3_phy_set_wirespeed(tp);
  8601. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8602. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8603. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8604. }
  8605. skip_phy_reset:
  8606. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8607. err = tg3_init_5401phy_dsp(tp);
  8608. if (err)
  8609. return err;
  8610. }
  8611. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8612. err = tg3_init_5401phy_dsp(tp);
  8613. }
  8614. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8615. tp->link_config.advertising =
  8616. (ADVERTISED_1000baseT_Half |
  8617. ADVERTISED_1000baseT_Full |
  8618. ADVERTISED_Autoneg |
  8619. ADVERTISED_FIBRE);
  8620. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8621. tp->link_config.advertising &=
  8622. ~(ADVERTISED_1000baseT_Half |
  8623. ADVERTISED_1000baseT_Full);
  8624. return err;
  8625. }
  8626. static void __devinit tg3_read_partno(struct tg3 *tp)
  8627. {
  8628. unsigned char vpd_data[256];
  8629. int i;
  8630. u32 magic;
  8631. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8632. goto out_not_found;
  8633. if (magic == TG3_EEPROM_MAGIC) {
  8634. for (i = 0; i < 256; i += 4) {
  8635. u32 tmp;
  8636. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8637. goto out_not_found;
  8638. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8639. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8640. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8641. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8642. }
  8643. } else {
  8644. int vpd_cap;
  8645. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8646. for (i = 0; i < 256; i += 4) {
  8647. u32 tmp, j = 0;
  8648. u16 tmp16;
  8649. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8650. i);
  8651. while (j++ < 100) {
  8652. pci_read_config_word(tp->pdev, vpd_cap +
  8653. PCI_VPD_ADDR, &tmp16);
  8654. if (tmp16 & 0x8000)
  8655. break;
  8656. msleep(1);
  8657. }
  8658. if (!(tmp16 & 0x8000))
  8659. goto out_not_found;
  8660. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8661. &tmp);
  8662. tmp = cpu_to_le32(tmp);
  8663. memcpy(&vpd_data[i], &tmp, 4);
  8664. }
  8665. }
  8666. /* Now parse and find the part number. */
  8667. for (i = 0; i < 256; ) {
  8668. unsigned char val = vpd_data[i];
  8669. int block_end;
  8670. if (val == 0x82 || val == 0x91) {
  8671. i = (i + 3 +
  8672. (vpd_data[i + 1] +
  8673. (vpd_data[i + 2] << 8)));
  8674. continue;
  8675. }
  8676. if (val != 0x90)
  8677. goto out_not_found;
  8678. block_end = (i + 3 +
  8679. (vpd_data[i + 1] +
  8680. (vpd_data[i + 2] << 8)));
  8681. i += 3;
  8682. while (i < block_end) {
  8683. if (vpd_data[i + 0] == 'P' &&
  8684. vpd_data[i + 1] == 'N') {
  8685. int partno_len = vpd_data[i + 2];
  8686. if (partno_len > 24)
  8687. goto out_not_found;
  8688. memcpy(tp->board_part_number,
  8689. &vpd_data[i + 3],
  8690. partno_len);
  8691. /* Success. */
  8692. return;
  8693. }
  8694. }
  8695. /* Part number not found. */
  8696. goto out_not_found;
  8697. }
  8698. out_not_found:
  8699. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8700. strcpy(tp->board_part_number, "BCM95906");
  8701. else
  8702. strcpy(tp->board_part_number, "none");
  8703. }
  8704. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8705. {
  8706. u32 val, offset, start;
  8707. if (tg3_nvram_read_swab(tp, 0, &val))
  8708. return;
  8709. if (val != TG3_EEPROM_MAGIC)
  8710. return;
  8711. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8712. tg3_nvram_read_swab(tp, 0x4, &start))
  8713. return;
  8714. offset = tg3_nvram_logical_addr(tp, offset);
  8715. if (tg3_nvram_read_swab(tp, offset, &val))
  8716. return;
  8717. if ((val & 0xfc000000) == 0x0c000000) {
  8718. u32 ver_offset, addr;
  8719. int i;
  8720. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8721. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8722. return;
  8723. if (val != 0)
  8724. return;
  8725. addr = offset + ver_offset - start;
  8726. for (i = 0; i < 16; i += 4) {
  8727. if (tg3_nvram_read(tp, addr + i, &val))
  8728. return;
  8729. val = cpu_to_le32(val);
  8730. memcpy(tp->fw_ver + i, &val, 4);
  8731. }
  8732. }
  8733. }
  8734. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8735. {
  8736. static struct pci_device_id write_reorder_chipsets[] = {
  8737. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8738. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8739. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8740. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8741. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8742. PCI_DEVICE_ID_VIA_8385_0) },
  8743. { },
  8744. };
  8745. u32 misc_ctrl_reg;
  8746. u32 cacheline_sz_reg;
  8747. u32 pci_state_reg, grc_misc_cfg;
  8748. u32 val;
  8749. u16 pci_cmd;
  8750. int err;
  8751. /* Force memory write invalidate off. If we leave it on,
  8752. * then on 5700_BX chips we have to enable a workaround.
  8753. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8754. * to match the cacheline size. The Broadcom driver have this
  8755. * workaround but turns MWI off all the times so never uses
  8756. * it. This seems to suggest that the workaround is insufficient.
  8757. */
  8758. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8759. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8760. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8761. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8762. * has the register indirect write enable bit set before
  8763. * we try to access any of the MMIO registers. It is also
  8764. * critical that the PCI-X hw workaround situation is decided
  8765. * before that as well.
  8766. */
  8767. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8768. &misc_ctrl_reg);
  8769. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8770. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8771. /* Wrong chip ID in 5752 A0. This code can be removed later
  8772. * as A0 is not in production.
  8773. */
  8774. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8775. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8776. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8777. * we need to disable memory and use config. cycles
  8778. * only to access all registers. The 5702/03 chips
  8779. * can mistakenly decode the special cycles from the
  8780. * ICH chipsets as memory write cycles, causing corruption
  8781. * of register and memory space. Only certain ICH bridges
  8782. * will drive special cycles with non-zero data during the
  8783. * address phase which can fall within the 5703's address
  8784. * range. This is not an ICH bug as the PCI spec allows
  8785. * non-zero address during special cycles. However, only
  8786. * these ICH bridges are known to drive non-zero addresses
  8787. * during special cycles.
  8788. *
  8789. * Since special cycles do not cross PCI bridges, we only
  8790. * enable this workaround if the 5703 is on the secondary
  8791. * bus of these ICH bridges.
  8792. */
  8793. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8794. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8795. static struct tg3_dev_id {
  8796. u32 vendor;
  8797. u32 device;
  8798. u32 rev;
  8799. } ich_chipsets[] = {
  8800. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8801. PCI_ANY_ID },
  8802. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8803. PCI_ANY_ID },
  8804. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8805. 0xa },
  8806. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8807. PCI_ANY_ID },
  8808. { },
  8809. };
  8810. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8811. struct pci_dev *bridge = NULL;
  8812. while (pci_id->vendor != 0) {
  8813. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8814. bridge);
  8815. if (!bridge) {
  8816. pci_id++;
  8817. continue;
  8818. }
  8819. if (pci_id->rev != PCI_ANY_ID) {
  8820. u8 rev;
  8821. pci_read_config_byte(bridge, PCI_REVISION_ID,
  8822. &rev);
  8823. if (rev > pci_id->rev)
  8824. continue;
  8825. }
  8826. if (bridge->subordinate &&
  8827. (bridge->subordinate->number ==
  8828. tp->pdev->bus->number)) {
  8829. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8830. pci_dev_put(bridge);
  8831. break;
  8832. }
  8833. }
  8834. }
  8835. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8836. * DMA addresses > 40-bit. This bridge may have other additional
  8837. * 57xx devices behind it in some 4-port NIC designs for example.
  8838. * Any tg3 device found behind the bridge will also need the 40-bit
  8839. * DMA workaround.
  8840. */
  8841. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8842. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8843. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8844. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8845. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8846. }
  8847. else {
  8848. struct pci_dev *bridge = NULL;
  8849. do {
  8850. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8851. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8852. bridge);
  8853. if (bridge && bridge->subordinate &&
  8854. (bridge->subordinate->number <=
  8855. tp->pdev->bus->number) &&
  8856. (bridge->subordinate->subordinate >=
  8857. tp->pdev->bus->number)) {
  8858. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8859. pci_dev_put(bridge);
  8860. break;
  8861. }
  8862. } while (bridge);
  8863. }
  8864. /* Initialize misc host control in PCI block. */
  8865. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8866. MISC_HOST_CTRL_CHIPREV);
  8867. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8868. tp->misc_host_ctrl);
  8869. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8870. &cacheline_sz_reg);
  8871. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8872. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8873. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8874. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8875. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8876. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8877. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8878. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8879. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  8880. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8881. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8882. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8883. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8884. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8885. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8886. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8887. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8888. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8889. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8890. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8891. } else {
  8892. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 |
  8893. TG3_FLG2_HW_TSO_1_BUG;
  8894. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8895. ASIC_REV_5750 &&
  8896. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  8897. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_1_BUG;
  8898. }
  8899. }
  8900. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  8901. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  8902. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  8903. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  8904. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  8905. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  8906. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  8907. if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0)
  8908. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  8909. /* If we have an AMD 762 or VIA K8T800 chipset, write
  8910. * reordering to the mailbox registers done by the host
  8911. * controller can cause major troubles. We read back from
  8912. * every mailbox register write to force the writes to be
  8913. * posted to the chip in order.
  8914. */
  8915. if (pci_dev_present(write_reorder_chipsets) &&
  8916. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  8917. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  8918. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  8919. tp->pci_lat_timer < 64) {
  8920. tp->pci_lat_timer = 64;
  8921. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  8922. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  8923. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  8924. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  8925. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8926. cacheline_sz_reg);
  8927. }
  8928. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  8929. &pci_state_reg);
  8930. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  8931. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  8932. /* If this is a 5700 BX chipset, and we are in PCI-X
  8933. * mode, enable register write workaround.
  8934. *
  8935. * The workaround is to use indirect register accesses
  8936. * for all chip writes not to mailbox registers.
  8937. */
  8938. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  8939. u32 pm_reg;
  8940. u16 pci_cmd;
  8941. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  8942. /* The chip can have it's power management PCI config
  8943. * space registers clobbered due to this bug.
  8944. * So explicitly force the chip into D0 here.
  8945. */
  8946. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  8947. &pm_reg);
  8948. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  8949. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  8950. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  8951. pm_reg);
  8952. /* Also, force SERR#/PERR# in PCI command. */
  8953. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8954. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  8955. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8956. }
  8957. }
  8958. /* 5700 BX chips need to have their TX producer index mailboxes
  8959. * written twice to workaround a bug.
  8960. */
  8961. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  8962. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  8963. /* Back to back register writes can cause problems on this chip,
  8964. * the workaround is to read back all reg writes except those to
  8965. * mailbox regs. See tg3_write_indirect_reg32().
  8966. *
  8967. * PCI Express 5750_A0 rev chips need this workaround too.
  8968. */
  8969. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  8970. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  8971. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0))
  8972. tp->tg3_flags |= TG3_FLAG_5701_REG_WRITE_BUG;
  8973. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  8974. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  8975. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  8976. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  8977. /* Chip-specific fixup from Broadcom driver */
  8978. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  8979. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  8980. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  8981. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  8982. }
  8983. /* Default fast path register access methods */
  8984. tp->read32 = tg3_read32;
  8985. tp->write32 = tg3_write32;
  8986. tp->read32_mbox = tg3_read32;
  8987. tp->write32_mbox = tg3_write32;
  8988. tp->write32_tx_mbox = tg3_write32;
  8989. tp->write32_rx_mbox = tg3_write32;
  8990. /* Various workaround register access methods */
  8991. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  8992. tp->write32 = tg3_write_indirect_reg32;
  8993. else if (tp->tg3_flags & TG3_FLAG_5701_REG_WRITE_BUG)
  8994. tp->write32 = tg3_write_flush_reg32;
  8995. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  8996. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  8997. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  8998. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  8999. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9000. }
  9001. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9002. tp->read32 = tg3_read_indirect_reg32;
  9003. tp->write32 = tg3_write_indirect_reg32;
  9004. tp->read32_mbox = tg3_read_indirect_mbox;
  9005. tp->write32_mbox = tg3_write_indirect_mbox;
  9006. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9007. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9008. iounmap(tp->regs);
  9009. tp->regs = NULL;
  9010. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9011. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9012. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9013. }
  9014. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9015. tp->read32_mbox = tg3_read32_mbox_5906;
  9016. tp->write32_mbox = tg3_write32_mbox_5906;
  9017. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9018. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9019. }
  9020. if (tp->write32 == tg3_write_indirect_reg32 ||
  9021. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9022. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9023. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9024. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9025. /* Get eeprom hw config before calling tg3_set_power_state().
  9026. * In particular, the TG3_FLAG_EEPROM_WRITE_PROT flag must be
  9027. * determined before calling tg3_set_power_state() so that
  9028. * we know whether or not to switch out of Vaux power.
  9029. * When the flag is set, it means that GPIO1 is used for eeprom
  9030. * write protect and also implies that it is a LOM where GPIOs
  9031. * are not used to switch power.
  9032. */
  9033. tg3_get_eeprom_hw_cfg(tp);
  9034. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9035. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9036. * It is also used as eeprom write protect on LOMs.
  9037. */
  9038. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9039. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9040. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9041. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9042. GRC_LCLCTRL_GPIO_OUTPUT1);
  9043. /* Unused GPIO3 must be driven as output on 5752 because there
  9044. * are no pull-up resistors on unused GPIO pins.
  9045. */
  9046. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9047. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9048. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9049. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9050. /* Force the chip into D0. */
  9051. err = tg3_set_power_state(tp, PCI_D0);
  9052. if (err) {
  9053. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9054. pci_name(tp->pdev));
  9055. return err;
  9056. }
  9057. /* 5700 B0 chips do not support checksumming correctly due
  9058. * to hardware bugs.
  9059. */
  9060. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9061. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9062. /* Derive initial jumbo mode from MTU assigned in
  9063. * ether_setup() via the alloc_etherdev() call
  9064. */
  9065. if (tp->dev->mtu > ETH_DATA_LEN &&
  9066. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9067. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9068. /* Determine WakeOnLan speed to use. */
  9069. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9070. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9071. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9072. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9073. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9074. } else {
  9075. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9076. }
  9077. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9078. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9079. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9080. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9081. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9082. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9083. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9084. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9085. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9086. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9087. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9088. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9089. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9090. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9091. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9092. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  9093. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9094. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9095. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9096. }
  9097. tp->coalesce_mode = 0;
  9098. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9099. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9100. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9101. /* Initialize MAC MI mode, polling disabled. */
  9102. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9103. udelay(80);
  9104. /* Initialize data/descriptor byte/word swapping. */
  9105. val = tr32(GRC_MODE);
  9106. val &= GRC_MODE_HOST_STACKUP;
  9107. tw32(GRC_MODE, val | tp->grc_mode);
  9108. tg3_switch_clocks(tp);
  9109. /* Clear this out for sanity. */
  9110. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9111. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9112. &pci_state_reg);
  9113. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9114. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9115. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9116. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9117. chiprevid == CHIPREV_ID_5701_B0 ||
  9118. chiprevid == CHIPREV_ID_5701_B2 ||
  9119. chiprevid == CHIPREV_ID_5701_B5) {
  9120. void __iomem *sram_base;
  9121. /* Write some dummy words into the SRAM status block
  9122. * area, see if it reads back correctly. If the return
  9123. * value is bad, force enable the PCIX workaround.
  9124. */
  9125. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9126. writel(0x00000000, sram_base);
  9127. writel(0x00000000, sram_base + 4);
  9128. writel(0xffffffff, sram_base + 4);
  9129. if (readl(sram_base) != 0x00000000)
  9130. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9131. }
  9132. }
  9133. udelay(50);
  9134. tg3_nvram_init(tp);
  9135. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9136. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9137. /* Broadcom's driver says that CIOBE multisplit has a bug */
  9138. #if 0
  9139. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  9140. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5704CIOBE) {
  9141. tp->tg3_flags |= TG3_FLAG_SPLIT_MODE;
  9142. tp->split_mode_max_reqs = SPLIT_MODE_5704_MAX_REQ;
  9143. }
  9144. #endif
  9145. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9146. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9147. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9148. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9149. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9150. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9151. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9152. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9153. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9154. HOSTCC_MODE_CLRTICK_TXBD);
  9155. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9156. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9157. tp->misc_host_ctrl);
  9158. }
  9159. /* these are limited to 10/100 only */
  9160. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9161. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9162. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9163. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9164. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9165. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9166. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9167. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9168. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9169. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F)) ||
  9170. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9171. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9172. err = tg3_phy_probe(tp);
  9173. if (err) {
  9174. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9175. pci_name(tp->pdev), err);
  9176. /* ... but do not return immediately ... */
  9177. }
  9178. tg3_read_partno(tp);
  9179. tg3_read_fw_ver(tp);
  9180. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  9181. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9182. } else {
  9183. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9184. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  9185. else
  9186. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9187. }
  9188. /* 5700 {AX,BX} chips have a broken status block link
  9189. * change bit implementation, so we must use the
  9190. * status register in those cases.
  9191. */
  9192. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9193. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9194. else
  9195. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9196. /* The led_ctrl is set during tg3_phy_probe, here we might
  9197. * have to force the link status polling mechanism based
  9198. * upon subsystem IDs.
  9199. */
  9200. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9201. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9202. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9203. TG3_FLAG_USE_LINKCHG_REG);
  9204. }
  9205. /* For all SERDES we poll the MAC status register. */
  9206. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9207. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9208. else
  9209. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9210. /* All chips before 5787 can get confused if TX buffers
  9211. * straddle the 4GB address boundary in some cases.
  9212. */
  9213. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9214. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9215. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9216. tp->dev->hard_start_xmit = tg3_start_xmit;
  9217. else
  9218. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9219. tp->rx_offset = 2;
  9220. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9221. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9222. tp->rx_offset = 0;
  9223. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9224. /* Increment the rx prod index on the rx std ring by at most
  9225. * 8 for these chips to workaround hw errata.
  9226. */
  9227. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9228. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9229. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9230. tp->rx_std_max_post = 8;
  9231. /* By default, disable wake-on-lan. User can change this
  9232. * using ETHTOOL_SWOL.
  9233. */
  9234. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9235. return err;
  9236. }
  9237. #ifdef CONFIG_SPARC64
  9238. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9239. {
  9240. struct net_device *dev = tp->dev;
  9241. struct pci_dev *pdev = tp->pdev;
  9242. struct pcidev_cookie *pcp = pdev->sysdata;
  9243. if (pcp != NULL) {
  9244. unsigned char *addr;
  9245. int len;
  9246. addr = of_get_property(pcp->prom_node, "local-mac-address",
  9247. &len);
  9248. if (addr && len == 6) {
  9249. memcpy(dev->dev_addr, addr, 6);
  9250. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9251. return 0;
  9252. }
  9253. }
  9254. return -ENODEV;
  9255. }
  9256. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9257. {
  9258. struct net_device *dev = tp->dev;
  9259. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9260. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9261. return 0;
  9262. }
  9263. #endif
  9264. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9265. {
  9266. struct net_device *dev = tp->dev;
  9267. u32 hi, lo, mac_offset;
  9268. int addr_ok = 0;
  9269. #ifdef CONFIG_SPARC64
  9270. if (!tg3_get_macaddr_sparc(tp))
  9271. return 0;
  9272. #endif
  9273. mac_offset = 0x7c;
  9274. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9275. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9276. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9277. mac_offset = 0xcc;
  9278. if (tg3_nvram_lock(tp))
  9279. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9280. else
  9281. tg3_nvram_unlock(tp);
  9282. }
  9283. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9284. mac_offset = 0x10;
  9285. /* First try to get it from MAC address mailbox. */
  9286. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9287. if ((hi >> 16) == 0x484b) {
  9288. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9289. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9290. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9291. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9292. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9293. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9294. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9295. /* Some old bootcode may report a 0 MAC address in SRAM */
  9296. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9297. }
  9298. if (!addr_ok) {
  9299. /* Next, try NVRAM. */
  9300. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9301. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9302. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9303. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9304. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9305. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9306. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9307. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9308. }
  9309. /* Finally just fetch it out of the MAC control regs. */
  9310. else {
  9311. hi = tr32(MAC_ADDR_0_HIGH);
  9312. lo = tr32(MAC_ADDR_0_LOW);
  9313. dev->dev_addr[5] = lo & 0xff;
  9314. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9315. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9316. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9317. dev->dev_addr[1] = hi & 0xff;
  9318. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9319. }
  9320. }
  9321. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9322. #ifdef CONFIG_SPARC64
  9323. if (!tg3_get_default_macaddr_sparc(tp))
  9324. return 0;
  9325. #endif
  9326. return -EINVAL;
  9327. }
  9328. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9329. return 0;
  9330. }
  9331. #define BOUNDARY_SINGLE_CACHELINE 1
  9332. #define BOUNDARY_MULTI_CACHELINE 2
  9333. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9334. {
  9335. int cacheline_size;
  9336. u8 byte;
  9337. int goal;
  9338. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9339. if (byte == 0)
  9340. cacheline_size = 1024;
  9341. else
  9342. cacheline_size = (int) byte * 4;
  9343. /* On 5703 and later chips, the boundary bits have no
  9344. * effect.
  9345. */
  9346. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9347. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9348. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9349. goto out;
  9350. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9351. goal = BOUNDARY_MULTI_CACHELINE;
  9352. #else
  9353. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9354. goal = BOUNDARY_SINGLE_CACHELINE;
  9355. #else
  9356. goal = 0;
  9357. #endif
  9358. #endif
  9359. if (!goal)
  9360. goto out;
  9361. /* PCI controllers on most RISC systems tend to disconnect
  9362. * when a device tries to burst across a cache-line boundary.
  9363. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9364. *
  9365. * Unfortunately, for PCI-E there are only limited
  9366. * write-side controls for this, and thus for reads
  9367. * we will still get the disconnects. We'll also waste
  9368. * these PCI cycles for both read and write for chips
  9369. * other than 5700 and 5701 which do not implement the
  9370. * boundary bits.
  9371. */
  9372. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9373. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9374. switch (cacheline_size) {
  9375. case 16:
  9376. case 32:
  9377. case 64:
  9378. case 128:
  9379. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9380. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9381. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9382. } else {
  9383. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9384. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9385. }
  9386. break;
  9387. case 256:
  9388. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9389. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9390. break;
  9391. default:
  9392. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9393. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9394. break;
  9395. };
  9396. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9397. switch (cacheline_size) {
  9398. case 16:
  9399. case 32:
  9400. case 64:
  9401. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9402. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9403. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9404. break;
  9405. }
  9406. /* fallthrough */
  9407. case 128:
  9408. default:
  9409. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9410. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9411. break;
  9412. };
  9413. } else {
  9414. switch (cacheline_size) {
  9415. case 16:
  9416. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9417. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9418. DMA_RWCTRL_WRITE_BNDRY_16);
  9419. break;
  9420. }
  9421. /* fallthrough */
  9422. case 32:
  9423. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9424. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9425. DMA_RWCTRL_WRITE_BNDRY_32);
  9426. break;
  9427. }
  9428. /* fallthrough */
  9429. case 64:
  9430. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9431. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9432. DMA_RWCTRL_WRITE_BNDRY_64);
  9433. break;
  9434. }
  9435. /* fallthrough */
  9436. case 128:
  9437. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9438. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9439. DMA_RWCTRL_WRITE_BNDRY_128);
  9440. break;
  9441. }
  9442. /* fallthrough */
  9443. case 256:
  9444. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9445. DMA_RWCTRL_WRITE_BNDRY_256);
  9446. break;
  9447. case 512:
  9448. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9449. DMA_RWCTRL_WRITE_BNDRY_512);
  9450. break;
  9451. case 1024:
  9452. default:
  9453. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9454. DMA_RWCTRL_WRITE_BNDRY_1024);
  9455. break;
  9456. };
  9457. }
  9458. out:
  9459. return val;
  9460. }
  9461. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9462. {
  9463. struct tg3_internal_buffer_desc test_desc;
  9464. u32 sram_dma_descs;
  9465. int i, ret;
  9466. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9467. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9468. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9469. tw32(RDMAC_STATUS, 0);
  9470. tw32(WDMAC_STATUS, 0);
  9471. tw32(BUFMGR_MODE, 0);
  9472. tw32(FTQ_RESET, 0);
  9473. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9474. test_desc.addr_lo = buf_dma & 0xffffffff;
  9475. test_desc.nic_mbuf = 0x00002100;
  9476. test_desc.len = size;
  9477. /*
  9478. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9479. * the *second* time the tg3 driver was getting loaded after an
  9480. * initial scan.
  9481. *
  9482. * Broadcom tells me:
  9483. * ...the DMA engine is connected to the GRC block and a DMA
  9484. * reset may affect the GRC block in some unpredictable way...
  9485. * The behavior of resets to individual blocks has not been tested.
  9486. *
  9487. * Broadcom noted the GRC reset will also reset all sub-components.
  9488. */
  9489. if (to_device) {
  9490. test_desc.cqid_sqid = (13 << 8) | 2;
  9491. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9492. udelay(40);
  9493. } else {
  9494. test_desc.cqid_sqid = (16 << 8) | 7;
  9495. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9496. udelay(40);
  9497. }
  9498. test_desc.flags = 0x00000005;
  9499. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9500. u32 val;
  9501. val = *(((u32 *)&test_desc) + i);
  9502. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9503. sram_dma_descs + (i * sizeof(u32)));
  9504. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9505. }
  9506. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9507. if (to_device) {
  9508. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9509. } else {
  9510. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9511. }
  9512. ret = -ENODEV;
  9513. for (i = 0; i < 40; i++) {
  9514. u32 val;
  9515. if (to_device)
  9516. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9517. else
  9518. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9519. if ((val & 0xffff) == sram_dma_descs) {
  9520. ret = 0;
  9521. break;
  9522. }
  9523. udelay(100);
  9524. }
  9525. return ret;
  9526. }
  9527. #define TEST_BUFFER_SIZE 0x2000
  9528. static int __devinit tg3_test_dma(struct tg3 *tp)
  9529. {
  9530. dma_addr_t buf_dma;
  9531. u32 *buf, saved_dma_rwctrl;
  9532. int ret;
  9533. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9534. if (!buf) {
  9535. ret = -ENOMEM;
  9536. goto out_nofree;
  9537. }
  9538. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9539. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9540. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9541. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9542. /* DMA read watermark not used on PCIE */
  9543. tp->dma_rwctrl |= 0x00180000;
  9544. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9545. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9546. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9547. tp->dma_rwctrl |= 0x003f0000;
  9548. else
  9549. tp->dma_rwctrl |= 0x003f000f;
  9550. } else {
  9551. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9552. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9553. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9554. /* If the 5704 is behind the EPB bridge, we can
  9555. * do the less restrictive ONE_DMA workaround for
  9556. * better performance.
  9557. */
  9558. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9559. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9560. tp->dma_rwctrl |= 0x8000;
  9561. else if (ccval == 0x6 || ccval == 0x7)
  9562. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9563. /* Set bit 23 to enable PCIX hw bug fix */
  9564. tp->dma_rwctrl |= 0x009f0000;
  9565. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9566. /* 5780 always in PCIX mode */
  9567. tp->dma_rwctrl |= 0x00144000;
  9568. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9569. /* 5714 always in PCIX mode */
  9570. tp->dma_rwctrl |= 0x00148000;
  9571. } else {
  9572. tp->dma_rwctrl |= 0x001b000f;
  9573. }
  9574. }
  9575. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9576. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9577. tp->dma_rwctrl &= 0xfffffff0;
  9578. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9579. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9580. /* Remove this if it causes problems for some boards. */
  9581. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9582. /* On 5700/5701 chips, we need to set this bit.
  9583. * Otherwise the chip will issue cacheline transactions
  9584. * to streamable DMA memory with not all the byte
  9585. * enables turned on. This is an error on several
  9586. * RISC PCI controllers, in particular sparc64.
  9587. *
  9588. * On 5703/5704 chips, this bit has been reassigned
  9589. * a different meaning. In particular, it is used
  9590. * on those chips to enable a PCI-X workaround.
  9591. */
  9592. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9593. }
  9594. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9595. #if 0
  9596. /* Unneeded, already done by tg3_get_invariants. */
  9597. tg3_switch_clocks(tp);
  9598. #endif
  9599. ret = 0;
  9600. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9601. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9602. goto out;
  9603. /* It is best to perform DMA test with maximum write burst size
  9604. * to expose the 5700/5701 write DMA bug.
  9605. */
  9606. saved_dma_rwctrl = tp->dma_rwctrl;
  9607. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9608. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9609. while (1) {
  9610. u32 *p = buf, i;
  9611. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9612. p[i] = i;
  9613. /* Send the buffer to the chip. */
  9614. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9615. if (ret) {
  9616. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9617. break;
  9618. }
  9619. #if 0
  9620. /* validate data reached card RAM correctly. */
  9621. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9622. u32 val;
  9623. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9624. if (le32_to_cpu(val) != p[i]) {
  9625. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9626. /* ret = -ENODEV here? */
  9627. }
  9628. p[i] = 0;
  9629. }
  9630. #endif
  9631. /* Now read it back. */
  9632. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9633. if (ret) {
  9634. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9635. break;
  9636. }
  9637. /* Verify it. */
  9638. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9639. if (p[i] == i)
  9640. continue;
  9641. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9642. DMA_RWCTRL_WRITE_BNDRY_16) {
  9643. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9644. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9645. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9646. break;
  9647. } else {
  9648. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9649. ret = -ENODEV;
  9650. goto out;
  9651. }
  9652. }
  9653. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9654. /* Success. */
  9655. ret = 0;
  9656. break;
  9657. }
  9658. }
  9659. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9660. DMA_RWCTRL_WRITE_BNDRY_16) {
  9661. static struct pci_device_id dma_wait_state_chipsets[] = {
  9662. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9663. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9664. { },
  9665. };
  9666. /* DMA test passed without adjusting DMA boundary,
  9667. * now look for chipsets that are known to expose the
  9668. * DMA bug without failing the test.
  9669. */
  9670. if (pci_dev_present(dma_wait_state_chipsets)) {
  9671. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9672. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9673. }
  9674. else
  9675. /* Safe to use the calculated DMA boundary. */
  9676. tp->dma_rwctrl = saved_dma_rwctrl;
  9677. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9678. }
  9679. out:
  9680. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9681. out_nofree:
  9682. return ret;
  9683. }
  9684. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9685. {
  9686. tp->link_config.advertising =
  9687. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9688. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9689. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9690. ADVERTISED_Autoneg | ADVERTISED_MII);
  9691. tp->link_config.speed = SPEED_INVALID;
  9692. tp->link_config.duplex = DUPLEX_INVALID;
  9693. tp->link_config.autoneg = AUTONEG_ENABLE;
  9694. tp->link_config.active_speed = SPEED_INVALID;
  9695. tp->link_config.active_duplex = DUPLEX_INVALID;
  9696. tp->link_config.phy_is_low_power = 0;
  9697. tp->link_config.orig_speed = SPEED_INVALID;
  9698. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9699. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9700. }
  9701. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9702. {
  9703. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9704. tp->bufmgr_config.mbuf_read_dma_low_water =
  9705. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9706. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9707. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9708. tp->bufmgr_config.mbuf_high_water =
  9709. DEFAULT_MB_HIGH_WATER_5705;
  9710. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9711. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9712. DEFAULT_MB_MACRX_LOW_WATER_5906;
  9713. tp->bufmgr_config.mbuf_high_water =
  9714. DEFAULT_MB_HIGH_WATER_5906;
  9715. }
  9716. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9717. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9718. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9719. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9720. tp->bufmgr_config.mbuf_high_water_jumbo =
  9721. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9722. } else {
  9723. tp->bufmgr_config.mbuf_read_dma_low_water =
  9724. DEFAULT_MB_RDMA_LOW_WATER;
  9725. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9726. DEFAULT_MB_MACRX_LOW_WATER;
  9727. tp->bufmgr_config.mbuf_high_water =
  9728. DEFAULT_MB_HIGH_WATER;
  9729. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9730. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9731. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9732. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9733. tp->bufmgr_config.mbuf_high_water_jumbo =
  9734. DEFAULT_MB_HIGH_WATER_JUMBO;
  9735. }
  9736. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9737. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9738. }
  9739. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9740. {
  9741. switch (tp->phy_id & PHY_ID_MASK) {
  9742. case PHY_ID_BCM5400: return "5400";
  9743. case PHY_ID_BCM5401: return "5401";
  9744. case PHY_ID_BCM5411: return "5411";
  9745. case PHY_ID_BCM5701: return "5701";
  9746. case PHY_ID_BCM5703: return "5703";
  9747. case PHY_ID_BCM5704: return "5704";
  9748. case PHY_ID_BCM5705: return "5705";
  9749. case PHY_ID_BCM5750: return "5750";
  9750. case PHY_ID_BCM5752: return "5752";
  9751. case PHY_ID_BCM5714: return "5714";
  9752. case PHY_ID_BCM5780: return "5780";
  9753. case PHY_ID_BCM5755: return "5755";
  9754. case PHY_ID_BCM5787: return "5787";
  9755. case PHY_ID_BCM5756: return "5722/5756";
  9756. case PHY_ID_BCM5906: return "5906";
  9757. case PHY_ID_BCM8002: return "8002/serdes";
  9758. case 0: return "serdes";
  9759. default: return "unknown";
  9760. };
  9761. }
  9762. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9763. {
  9764. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9765. strcpy(str, "PCI Express");
  9766. return str;
  9767. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9768. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9769. strcpy(str, "PCIX:");
  9770. if ((clock_ctrl == 7) ||
  9771. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9772. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9773. strcat(str, "133MHz");
  9774. else if (clock_ctrl == 0)
  9775. strcat(str, "33MHz");
  9776. else if (clock_ctrl == 2)
  9777. strcat(str, "50MHz");
  9778. else if (clock_ctrl == 4)
  9779. strcat(str, "66MHz");
  9780. else if (clock_ctrl == 6)
  9781. strcat(str, "100MHz");
  9782. } else {
  9783. strcpy(str, "PCI:");
  9784. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9785. strcat(str, "66MHz");
  9786. else
  9787. strcat(str, "33MHz");
  9788. }
  9789. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9790. strcat(str, ":32-bit");
  9791. else
  9792. strcat(str, ":64-bit");
  9793. return str;
  9794. }
  9795. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9796. {
  9797. struct pci_dev *peer;
  9798. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9799. for (func = 0; func < 8; func++) {
  9800. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9801. if (peer && peer != tp->pdev)
  9802. break;
  9803. pci_dev_put(peer);
  9804. }
  9805. /* 5704 can be configured in single-port mode, set peer to
  9806. * tp->pdev in that case.
  9807. */
  9808. if (!peer) {
  9809. peer = tp->pdev;
  9810. return peer;
  9811. }
  9812. /*
  9813. * We don't need to keep the refcount elevated; there's no way
  9814. * to remove one half of this device without removing the other
  9815. */
  9816. pci_dev_put(peer);
  9817. return peer;
  9818. }
  9819. static void __devinit tg3_init_coal(struct tg3 *tp)
  9820. {
  9821. struct ethtool_coalesce *ec = &tp->coal;
  9822. memset(ec, 0, sizeof(*ec));
  9823. ec->cmd = ETHTOOL_GCOALESCE;
  9824. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9825. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9826. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9827. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9828. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9829. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9830. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9831. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9832. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9833. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9834. HOSTCC_MODE_CLRTICK_TXBD)) {
  9835. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9836. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9837. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9838. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9839. }
  9840. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9841. ec->rx_coalesce_usecs_irq = 0;
  9842. ec->tx_coalesce_usecs_irq = 0;
  9843. ec->stats_block_coalesce_usecs = 0;
  9844. }
  9845. }
  9846. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9847. const struct pci_device_id *ent)
  9848. {
  9849. static int tg3_version_printed = 0;
  9850. unsigned long tg3reg_base, tg3reg_len;
  9851. struct net_device *dev;
  9852. struct tg3 *tp;
  9853. int i, err, pm_cap;
  9854. char str[40];
  9855. u64 dma_mask, persist_dma_mask;
  9856. if (tg3_version_printed++ == 0)
  9857. printk(KERN_INFO "%s", version);
  9858. err = pci_enable_device(pdev);
  9859. if (err) {
  9860. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9861. "aborting.\n");
  9862. return err;
  9863. }
  9864. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9865. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9866. "base address, aborting.\n");
  9867. err = -ENODEV;
  9868. goto err_out_disable_pdev;
  9869. }
  9870. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9871. if (err) {
  9872. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9873. "aborting.\n");
  9874. goto err_out_disable_pdev;
  9875. }
  9876. pci_set_master(pdev);
  9877. /* Find power-management capability. */
  9878. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9879. if (pm_cap == 0) {
  9880. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  9881. "aborting.\n");
  9882. err = -EIO;
  9883. goto err_out_free_res;
  9884. }
  9885. tg3reg_base = pci_resource_start(pdev, 0);
  9886. tg3reg_len = pci_resource_len(pdev, 0);
  9887. dev = alloc_etherdev(sizeof(*tp));
  9888. if (!dev) {
  9889. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  9890. err = -ENOMEM;
  9891. goto err_out_free_res;
  9892. }
  9893. SET_MODULE_OWNER(dev);
  9894. SET_NETDEV_DEV(dev, &pdev->dev);
  9895. #if TG3_VLAN_TAG_USED
  9896. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  9897. dev->vlan_rx_register = tg3_vlan_rx_register;
  9898. dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
  9899. #endif
  9900. tp = netdev_priv(dev);
  9901. tp->pdev = pdev;
  9902. tp->dev = dev;
  9903. tp->pm_cap = pm_cap;
  9904. tp->mac_mode = TG3_DEF_MAC_MODE;
  9905. tp->rx_mode = TG3_DEF_RX_MODE;
  9906. tp->tx_mode = TG3_DEF_TX_MODE;
  9907. tp->mi_mode = MAC_MI_MODE_BASE;
  9908. if (tg3_debug > 0)
  9909. tp->msg_enable = tg3_debug;
  9910. else
  9911. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  9912. /* The word/byte swap controls here control register access byte
  9913. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  9914. * setting below.
  9915. */
  9916. tp->misc_host_ctrl =
  9917. MISC_HOST_CTRL_MASK_PCI_INT |
  9918. MISC_HOST_CTRL_WORD_SWAP |
  9919. MISC_HOST_CTRL_INDIR_ACCESS |
  9920. MISC_HOST_CTRL_PCISTATE_RW;
  9921. /* The NONFRM (non-frame) byte/word swap controls take effect
  9922. * on descriptor entries, anything which isn't packet data.
  9923. *
  9924. * The StrongARM chips on the board (one for tx, one for rx)
  9925. * are running in big-endian mode.
  9926. */
  9927. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  9928. GRC_MODE_WSWAP_NONFRM_DATA);
  9929. #ifdef __BIG_ENDIAN
  9930. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  9931. #endif
  9932. spin_lock_init(&tp->lock);
  9933. spin_lock_init(&tp->indirect_lock);
  9934. INIT_WORK(&tp->reset_task, tg3_reset_task, tp);
  9935. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  9936. if (tp->regs == 0UL) {
  9937. printk(KERN_ERR PFX "Cannot map device registers, "
  9938. "aborting.\n");
  9939. err = -ENOMEM;
  9940. goto err_out_free_dev;
  9941. }
  9942. tg3_init_link_config(tp);
  9943. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  9944. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  9945. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  9946. dev->open = tg3_open;
  9947. dev->stop = tg3_close;
  9948. dev->get_stats = tg3_get_stats;
  9949. dev->set_multicast_list = tg3_set_rx_mode;
  9950. dev->set_mac_address = tg3_set_mac_addr;
  9951. dev->do_ioctl = tg3_ioctl;
  9952. dev->tx_timeout = tg3_tx_timeout;
  9953. dev->poll = tg3_poll;
  9954. dev->ethtool_ops = &tg3_ethtool_ops;
  9955. dev->weight = 64;
  9956. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  9957. dev->change_mtu = tg3_change_mtu;
  9958. dev->irq = pdev->irq;
  9959. #ifdef CONFIG_NET_POLL_CONTROLLER
  9960. dev->poll_controller = tg3_poll_controller;
  9961. #endif
  9962. err = tg3_get_invariants(tp);
  9963. if (err) {
  9964. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  9965. "aborting.\n");
  9966. goto err_out_iounmap;
  9967. }
  9968. /* The EPB bridge inside 5714, 5715, and 5780 and any
  9969. * device behind the EPB cannot support DMA addresses > 40-bit.
  9970. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  9971. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  9972. * do DMA address check in tg3_start_xmit().
  9973. */
  9974. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  9975. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  9976. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  9977. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  9978. #ifdef CONFIG_HIGHMEM
  9979. dma_mask = DMA_64BIT_MASK;
  9980. #endif
  9981. } else
  9982. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  9983. /* Configure DMA attributes. */
  9984. if (dma_mask > DMA_32BIT_MASK) {
  9985. err = pci_set_dma_mask(pdev, dma_mask);
  9986. if (!err) {
  9987. dev->features |= NETIF_F_HIGHDMA;
  9988. err = pci_set_consistent_dma_mask(pdev,
  9989. persist_dma_mask);
  9990. if (err < 0) {
  9991. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  9992. "DMA for consistent allocations\n");
  9993. goto err_out_iounmap;
  9994. }
  9995. }
  9996. }
  9997. if (err || dma_mask == DMA_32BIT_MASK) {
  9998. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  9999. if (err) {
  10000. printk(KERN_ERR PFX "No usable DMA configuration, "
  10001. "aborting.\n");
  10002. goto err_out_iounmap;
  10003. }
  10004. }
  10005. tg3_init_bufmgr_config(tp);
  10006. #if TG3_TSO_SUPPORT != 0
  10007. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10008. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10009. }
  10010. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10011. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10012. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10013. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10014. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10015. } else {
  10016. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10017. }
  10018. /* TSO is on by default on chips that support hardware TSO.
  10019. * Firmware TSO on older chips gives lower performance, so it
  10020. * is off by default, but can be enabled using ethtool.
  10021. */
  10022. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10023. dev->features |= NETIF_F_TSO;
  10024. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10025. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10026. dev->features |= NETIF_F_TSO6;
  10027. }
  10028. #endif
  10029. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10030. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10031. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10032. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10033. tp->rx_pending = 63;
  10034. }
  10035. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  10036. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  10037. tp->pdev_peer = tg3_find_peer(tp);
  10038. err = tg3_get_device_address(tp);
  10039. if (err) {
  10040. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10041. "aborting.\n");
  10042. goto err_out_iounmap;
  10043. }
  10044. /*
  10045. * Reset chip in case UNDI or EFI driver did not shutdown
  10046. * DMA self test will enable WDMAC and we'll see (spurious)
  10047. * pending DMA on the PCI bus at that point.
  10048. */
  10049. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10050. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10051. pci_save_state(tp->pdev);
  10052. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10053. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10054. }
  10055. err = tg3_test_dma(tp);
  10056. if (err) {
  10057. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10058. goto err_out_iounmap;
  10059. }
  10060. /* Tigon3 can do ipv4 only... and some chips have buggy
  10061. * checksumming.
  10062. */
  10063. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10064. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10065. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  10066. dev->features |= NETIF_F_HW_CSUM;
  10067. else
  10068. dev->features |= NETIF_F_IP_CSUM;
  10069. dev->features |= NETIF_F_SG;
  10070. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10071. } else
  10072. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10073. /* flow control autonegotiation is default behavior */
  10074. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10075. tg3_init_coal(tp);
  10076. /* Now that we have fully setup the chip, save away a snapshot
  10077. * of the PCI config space. We need to restore this after
  10078. * GRC_MISC_CFG core clock resets and some resume events.
  10079. */
  10080. pci_save_state(tp->pdev);
  10081. err = register_netdev(dev);
  10082. if (err) {
  10083. printk(KERN_ERR PFX "Cannot register net device, "
  10084. "aborting.\n");
  10085. goto err_out_iounmap;
  10086. }
  10087. pci_set_drvdata(pdev, dev);
  10088. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %sBaseT Ethernet ",
  10089. dev->name,
  10090. tp->board_part_number,
  10091. tp->pci_chip_rev_id,
  10092. tg3_phy_string(tp),
  10093. tg3_bus_string(tp, str),
  10094. (tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100" : "10/100/1000");
  10095. for (i = 0; i < 6; i++)
  10096. printk("%2.2x%c", dev->dev_addr[i],
  10097. i == 5 ? '\n' : ':');
  10098. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10099. "MIirq[%d] ASF[%d] Split[%d] WireSpeed[%d] "
  10100. "TSOcap[%d] \n",
  10101. dev->name,
  10102. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10103. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10104. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10105. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10106. (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0,
  10107. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10108. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10109. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10110. dev->name, tp->dma_rwctrl,
  10111. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10112. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10113. netif_carrier_off(tp->dev);
  10114. return 0;
  10115. err_out_iounmap:
  10116. if (tp->regs) {
  10117. iounmap(tp->regs);
  10118. tp->regs = NULL;
  10119. }
  10120. err_out_free_dev:
  10121. free_netdev(dev);
  10122. err_out_free_res:
  10123. pci_release_regions(pdev);
  10124. err_out_disable_pdev:
  10125. pci_disable_device(pdev);
  10126. pci_set_drvdata(pdev, NULL);
  10127. return err;
  10128. }
  10129. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10130. {
  10131. struct net_device *dev = pci_get_drvdata(pdev);
  10132. if (dev) {
  10133. struct tg3 *tp = netdev_priv(dev);
  10134. flush_scheduled_work();
  10135. unregister_netdev(dev);
  10136. if (tp->regs) {
  10137. iounmap(tp->regs);
  10138. tp->regs = NULL;
  10139. }
  10140. free_netdev(dev);
  10141. pci_release_regions(pdev);
  10142. pci_disable_device(pdev);
  10143. pci_set_drvdata(pdev, NULL);
  10144. }
  10145. }
  10146. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10147. {
  10148. struct net_device *dev = pci_get_drvdata(pdev);
  10149. struct tg3 *tp = netdev_priv(dev);
  10150. int err;
  10151. if (!netif_running(dev))
  10152. return 0;
  10153. flush_scheduled_work();
  10154. tg3_netif_stop(tp);
  10155. del_timer_sync(&tp->timer);
  10156. tg3_full_lock(tp, 1);
  10157. tg3_disable_ints(tp);
  10158. tg3_full_unlock(tp);
  10159. netif_device_detach(dev);
  10160. tg3_full_lock(tp, 0);
  10161. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10162. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  10163. tg3_full_unlock(tp);
  10164. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  10165. if (err) {
  10166. tg3_full_lock(tp, 0);
  10167. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10168. if (tg3_restart_hw(tp, 1))
  10169. goto out;
  10170. tp->timer.expires = jiffies + tp->timer_offset;
  10171. add_timer(&tp->timer);
  10172. netif_device_attach(dev);
  10173. tg3_netif_start(tp);
  10174. out:
  10175. tg3_full_unlock(tp);
  10176. }
  10177. return err;
  10178. }
  10179. static int tg3_resume(struct pci_dev *pdev)
  10180. {
  10181. struct net_device *dev = pci_get_drvdata(pdev);
  10182. struct tg3 *tp = netdev_priv(dev);
  10183. int err;
  10184. if (!netif_running(dev))
  10185. return 0;
  10186. pci_restore_state(tp->pdev);
  10187. err = tg3_set_power_state(tp, PCI_D0);
  10188. if (err)
  10189. return err;
  10190. netif_device_attach(dev);
  10191. tg3_full_lock(tp, 0);
  10192. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10193. err = tg3_restart_hw(tp, 1);
  10194. if (err)
  10195. goto out;
  10196. tp->timer.expires = jiffies + tp->timer_offset;
  10197. add_timer(&tp->timer);
  10198. tg3_netif_start(tp);
  10199. out:
  10200. tg3_full_unlock(tp);
  10201. return err;
  10202. }
  10203. static struct pci_driver tg3_driver = {
  10204. .name = DRV_MODULE_NAME,
  10205. .id_table = tg3_pci_tbl,
  10206. .probe = tg3_init_one,
  10207. .remove = __devexit_p(tg3_remove_one),
  10208. .suspend = tg3_suspend,
  10209. .resume = tg3_resume
  10210. };
  10211. static int __init tg3_init(void)
  10212. {
  10213. return pci_register_driver(&tg3_driver);
  10214. }
  10215. static void __exit tg3_cleanup(void)
  10216. {
  10217. pci_unregister_driver(&tg3_driver);
  10218. }
  10219. module_init(tg3_init);
  10220. module_exit(tg3_cleanup);