tg3.c 347 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005-2007 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <net/ip.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/byteorder.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_SPARC
  46. #include <asm/idprom.h>
  47. #include <asm/prom.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. #define TG3_TSO_SUPPORT 1
  55. #include "tg3.h"
  56. #define DRV_MODULE_NAME "tg3"
  57. #define PFX DRV_MODULE_NAME ": "
  58. #define DRV_MODULE_VERSION "3.75"
  59. #define DRV_MODULE_RELDATE "March 23, 2007"
  60. #define TG3_DEF_MAC_MODE 0
  61. #define TG3_DEF_RX_MODE 0
  62. #define TG3_DEF_TX_MODE 0
  63. #define TG3_DEF_MSG_ENABLE \
  64. (NETIF_MSG_DRV | \
  65. NETIF_MSG_PROBE | \
  66. NETIF_MSG_LINK | \
  67. NETIF_MSG_TIMER | \
  68. NETIF_MSG_IFDOWN | \
  69. NETIF_MSG_IFUP | \
  70. NETIF_MSG_RX_ERR | \
  71. NETIF_MSG_TX_ERR)
  72. /* length of time before we decide the hardware is borked,
  73. * and dev->tx_timeout() should be called to fix the problem
  74. */
  75. #define TG3_TX_TIMEOUT (5 * HZ)
  76. /* hardware minimum and maximum for a single frame's data payload */
  77. #define TG3_MIN_MTU 60
  78. #define TG3_MAX_MTU(tp) \
  79. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  80. /* These numbers seem to be hard coded in the NIC firmware somehow.
  81. * You can't change the ring sizes, but you can change where you place
  82. * them in the NIC onboard memory.
  83. */
  84. #define TG3_RX_RING_SIZE 512
  85. #define TG3_DEF_RX_RING_PENDING 200
  86. #define TG3_RX_JUMBO_RING_SIZE 256
  87. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  88. /* Do not place this n-ring entries value into the tp struct itself,
  89. * we really want to expose these constants to GCC so that modulo et
  90. * al. operations are done with shifts and masks instead of with
  91. * hw multiply/modulo instructions. Another solution would be to
  92. * replace things like '% foo' with '& (foo - 1)'.
  93. */
  94. #define TG3_RX_RCB_RING_SIZE(tp) \
  95. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  96. #define TG3_TX_RING_SIZE 512
  97. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  98. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  99. TG3_RX_RING_SIZE)
  100. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  101. TG3_RX_JUMBO_RING_SIZE)
  102. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RCB_RING_SIZE(tp))
  104. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  105. TG3_TX_RING_SIZE)
  106. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  107. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  108. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  109. /* minimum number of free TX descriptors required to wake up TX process */
  110. #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
  111. /* number of ETHTOOL_GSTATS u64's */
  112. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  113. #define TG3_NUM_TEST 6
  114. static char version[] __devinitdata =
  115. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  116. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  117. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  118. MODULE_LICENSE("GPL");
  119. MODULE_VERSION(DRV_MODULE_VERSION);
  120. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  121. module_param(tg3_debug, int, 0);
  122. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  123. static struct pci_device_id tg3_pci_tbl[] = {
  124. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  125. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  126. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  127. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  184. {}
  185. };
  186. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  187. static const struct {
  188. const char string[ETH_GSTRING_LEN];
  189. } ethtool_stats_keys[TG3_NUM_STATS] = {
  190. { "rx_octets" },
  191. { "rx_fragments" },
  192. { "rx_ucast_packets" },
  193. { "rx_mcast_packets" },
  194. { "rx_bcast_packets" },
  195. { "rx_fcs_errors" },
  196. { "rx_align_errors" },
  197. { "rx_xon_pause_rcvd" },
  198. { "rx_xoff_pause_rcvd" },
  199. { "rx_mac_ctrl_rcvd" },
  200. { "rx_xoff_entered" },
  201. { "rx_frame_too_long_errors" },
  202. { "rx_jabbers" },
  203. { "rx_undersize_packets" },
  204. { "rx_in_length_errors" },
  205. { "rx_out_length_errors" },
  206. { "rx_64_or_less_octet_packets" },
  207. { "rx_65_to_127_octet_packets" },
  208. { "rx_128_to_255_octet_packets" },
  209. { "rx_256_to_511_octet_packets" },
  210. { "rx_512_to_1023_octet_packets" },
  211. { "rx_1024_to_1522_octet_packets" },
  212. { "rx_1523_to_2047_octet_packets" },
  213. { "rx_2048_to_4095_octet_packets" },
  214. { "rx_4096_to_8191_octet_packets" },
  215. { "rx_8192_to_9022_octet_packets" },
  216. { "tx_octets" },
  217. { "tx_collisions" },
  218. { "tx_xon_sent" },
  219. { "tx_xoff_sent" },
  220. { "tx_flow_control" },
  221. { "tx_mac_errors" },
  222. { "tx_single_collisions" },
  223. { "tx_mult_collisions" },
  224. { "tx_deferred" },
  225. { "tx_excessive_collisions" },
  226. { "tx_late_collisions" },
  227. { "tx_collide_2times" },
  228. { "tx_collide_3times" },
  229. { "tx_collide_4times" },
  230. { "tx_collide_5times" },
  231. { "tx_collide_6times" },
  232. { "tx_collide_7times" },
  233. { "tx_collide_8times" },
  234. { "tx_collide_9times" },
  235. { "tx_collide_10times" },
  236. { "tx_collide_11times" },
  237. { "tx_collide_12times" },
  238. { "tx_collide_13times" },
  239. { "tx_collide_14times" },
  240. { "tx_collide_15times" },
  241. { "tx_ucast_packets" },
  242. { "tx_mcast_packets" },
  243. { "tx_bcast_packets" },
  244. { "tx_carrier_sense_errors" },
  245. { "tx_discards" },
  246. { "tx_errors" },
  247. { "dma_writeq_full" },
  248. { "dma_write_prioq_full" },
  249. { "rxbds_empty" },
  250. { "rx_discards" },
  251. { "rx_errors" },
  252. { "rx_threshold_hit" },
  253. { "dma_readq_full" },
  254. { "dma_read_prioq_full" },
  255. { "tx_comp_queue_full" },
  256. { "ring_set_send_prod_index" },
  257. { "ring_status_update" },
  258. { "nic_irqs" },
  259. { "nic_avoided_irqs" },
  260. { "nic_tx_threshold_hit" }
  261. };
  262. static const struct {
  263. const char string[ETH_GSTRING_LEN];
  264. } ethtool_test_keys[TG3_NUM_TEST] = {
  265. { "nvram test (online) " },
  266. { "link test (online) " },
  267. { "register test (offline)" },
  268. { "memory test (offline)" },
  269. { "loopback test (offline)" },
  270. { "interrupt test (offline)" },
  271. };
  272. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  273. {
  274. writel(val, tp->regs + off);
  275. }
  276. static u32 tg3_read32(struct tg3 *tp, u32 off)
  277. {
  278. return (readl(tp->regs + off));
  279. }
  280. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  281. {
  282. unsigned long flags;
  283. spin_lock_irqsave(&tp->indirect_lock, flags);
  284. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  285. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  286. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  287. }
  288. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  289. {
  290. writel(val, tp->regs + off);
  291. readl(tp->regs + off);
  292. }
  293. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  294. {
  295. unsigned long flags;
  296. u32 val;
  297. spin_lock_irqsave(&tp->indirect_lock, flags);
  298. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  299. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  300. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  301. return val;
  302. }
  303. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  304. {
  305. unsigned long flags;
  306. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  307. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  308. TG3_64BIT_REG_LOW, val);
  309. return;
  310. }
  311. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  312. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  313. TG3_64BIT_REG_LOW, val);
  314. return;
  315. }
  316. spin_lock_irqsave(&tp->indirect_lock, flags);
  317. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  318. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  319. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  320. /* In indirect mode when disabling interrupts, we also need
  321. * to clear the interrupt bit in the GRC local ctrl register.
  322. */
  323. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  324. (val == 0x1)) {
  325. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  326. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  327. }
  328. }
  329. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  330. {
  331. unsigned long flags;
  332. u32 val;
  333. spin_lock_irqsave(&tp->indirect_lock, flags);
  334. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  335. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  336. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  337. return val;
  338. }
  339. /* usec_wait specifies the wait time in usec when writing to certain registers
  340. * where it is unsafe to read back the register without some delay.
  341. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  342. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  343. */
  344. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  345. {
  346. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  347. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  348. /* Non-posted methods */
  349. tp->write32(tp, off, val);
  350. else {
  351. /* Posted method */
  352. tg3_write32(tp, off, val);
  353. if (usec_wait)
  354. udelay(usec_wait);
  355. tp->read32(tp, off);
  356. }
  357. /* Wait again after the read for the posted method to guarantee that
  358. * the wait time is met.
  359. */
  360. if (usec_wait)
  361. udelay(usec_wait);
  362. }
  363. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  364. {
  365. tp->write32_mbox(tp, off, val);
  366. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  367. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  368. tp->read32_mbox(tp, off);
  369. }
  370. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  371. {
  372. void __iomem *mbox = tp->regs + off;
  373. writel(val, mbox);
  374. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  375. writel(val, mbox);
  376. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  377. readl(mbox);
  378. }
  379. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  380. {
  381. return (readl(tp->regs + off + GRCMBOX_BASE));
  382. }
  383. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  384. {
  385. writel(val, tp->regs + off + GRCMBOX_BASE);
  386. }
  387. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  388. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  389. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  390. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  391. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  392. #define tw32(reg,val) tp->write32(tp, reg, val)
  393. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  394. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  395. #define tr32(reg) tp->read32(tp, reg)
  396. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  397. {
  398. unsigned long flags;
  399. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  400. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  401. return;
  402. spin_lock_irqsave(&tp->indirect_lock, flags);
  403. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  404. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  405. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  406. /* Always leave this as zero. */
  407. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  408. } else {
  409. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  410. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  411. /* Always leave this as zero. */
  412. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  413. }
  414. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  415. }
  416. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  417. {
  418. unsigned long flags;
  419. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  420. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  421. *val = 0;
  422. return;
  423. }
  424. spin_lock_irqsave(&tp->indirect_lock, flags);
  425. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  426. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  427. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  428. /* Always leave this as zero. */
  429. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  430. } else {
  431. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  432. *val = tr32(TG3PCI_MEM_WIN_DATA);
  433. /* Always leave this as zero. */
  434. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  435. }
  436. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  437. }
  438. static void tg3_disable_ints(struct tg3 *tp)
  439. {
  440. tw32(TG3PCI_MISC_HOST_CTRL,
  441. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  442. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  443. }
  444. static inline void tg3_cond_int(struct tg3 *tp)
  445. {
  446. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  447. (tp->hw_status->status & SD_STATUS_UPDATED))
  448. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  449. else
  450. tw32(HOSTCC_MODE, tp->coalesce_mode |
  451. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  452. }
  453. static void tg3_enable_ints(struct tg3 *tp)
  454. {
  455. tp->irq_sync = 0;
  456. wmb();
  457. tw32(TG3PCI_MISC_HOST_CTRL,
  458. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  459. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  460. (tp->last_tag << 24));
  461. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  462. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  463. (tp->last_tag << 24));
  464. tg3_cond_int(tp);
  465. }
  466. static inline unsigned int tg3_has_work(struct tg3 *tp)
  467. {
  468. struct tg3_hw_status *sblk = tp->hw_status;
  469. unsigned int work_exists = 0;
  470. /* check for phy events */
  471. if (!(tp->tg3_flags &
  472. (TG3_FLAG_USE_LINKCHG_REG |
  473. TG3_FLAG_POLL_SERDES))) {
  474. if (sblk->status & SD_STATUS_LINK_CHG)
  475. work_exists = 1;
  476. }
  477. /* check for RX/TX work to do */
  478. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  479. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  480. work_exists = 1;
  481. return work_exists;
  482. }
  483. /* tg3_restart_ints
  484. * similar to tg3_enable_ints, but it accurately determines whether there
  485. * is new work pending and can return without flushing the PIO write
  486. * which reenables interrupts
  487. */
  488. static void tg3_restart_ints(struct tg3 *tp)
  489. {
  490. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  491. tp->last_tag << 24);
  492. mmiowb();
  493. /* When doing tagged status, this work check is unnecessary.
  494. * The last_tag we write above tells the chip which piece of
  495. * work we've completed.
  496. */
  497. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  498. tg3_has_work(tp))
  499. tw32(HOSTCC_MODE, tp->coalesce_mode |
  500. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  501. }
  502. static inline void tg3_netif_stop(struct tg3 *tp)
  503. {
  504. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  505. netif_poll_disable(tp->dev);
  506. netif_tx_disable(tp->dev);
  507. }
  508. static inline void tg3_netif_start(struct tg3 *tp)
  509. {
  510. netif_wake_queue(tp->dev);
  511. /* NOTE: unconditional netif_wake_queue is only appropriate
  512. * so long as all callers are assured to have free tx slots
  513. * (such as after tg3_init_hw)
  514. */
  515. netif_poll_enable(tp->dev);
  516. tp->hw_status->status |= SD_STATUS_UPDATED;
  517. tg3_enable_ints(tp);
  518. }
  519. static void tg3_switch_clocks(struct tg3 *tp)
  520. {
  521. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  522. u32 orig_clock_ctrl;
  523. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  524. return;
  525. orig_clock_ctrl = clock_ctrl;
  526. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  527. CLOCK_CTRL_CLKRUN_OENABLE |
  528. 0x1f);
  529. tp->pci_clock_ctrl = clock_ctrl;
  530. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  531. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  532. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  533. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  534. }
  535. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  536. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  537. clock_ctrl |
  538. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  539. 40);
  540. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  541. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  542. 40);
  543. }
  544. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  545. }
  546. #define PHY_BUSY_LOOPS 5000
  547. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  548. {
  549. u32 frame_val;
  550. unsigned int loops;
  551. int ret;
  552. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  553. tw32_f(MAC_MI_MODE,
  554. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  555. udelay(80);
  556. }
  557. *val = 0x0;
  558. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  559. MI_COM_PHY_ADDR_MASK);
  560. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  561. MI_COM_REG_ADDR_MASK);
  562. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  563. tw32_f(MAC_MI_COM, frame_val);
  564. loops = PHY_BUSY_LOOPS;
  565. while (loops != 0) {
  566. udelay(10);
  567. frame_val = tr32(MAC_MI_COM);
  568. if ((frame_val & MI_COM_BUSY) == 0) {
  569. udelay(5);
  570. frame_val = tr32(MAC_MI_COM);
  571. break;
  572. }
  573. loops -= 1;
  574. }
  575. ret = -EBUSY;
  576. if (loops != 0) {
  577. *val = frame_val & MI_COM_DATA_MASK;
  578. ret = 0;
  579. }
  580. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  581. tw32_f(MAC_MI_MODE, tp->mi_mode);
  582. udelay(80);
  583. }
  584. return ret;
  585. }
  586. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  587. {
  588. u32 frame_val;
  589. unsigned int loops;
  590. int ret;
  591. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  592. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  593. return 0;
  594. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  595. tw32_f(MAC_MI_MODE,
  596. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  597. udelay(80);
  598. }
  599. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  600. MI_COM_PHY_ADDR_MASK);
  601. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  602. MI_COM_REG_ADDR_MASK);
  603. frame_val |= (val & MI_COM_DATA_MASK);
  604. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  605. tw32_f(MAC_MI_COM, frame_val);
  606. loops = PHY_BUSY_LOOPS;
  607. while (loops != 0) {
  608. udelay(10);
  609. frame_val = tr32(MAC_MI_COM);
  610. if ((frame_val & MI_COM_BUSY) == 0) {
  611. udelay(5);
  612. frame_val = tr32(MAC_MI_COM);
  613. break;
  614. }
  615. loops -= 1;
  616. }
  617. ret = -EBUSY;
  618. if (loops != 0)
  619. ret = 0;
  620. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  621. tw32_f(MAC_MI_MODE, tp->mi_mode);
  622. udelay(80);
  623. }
  624. return ret;
  625. }
  626. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  627. {
  628. u32 val;
  629. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  630. return;
  631. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  632. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  633. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  634. (val | (1 << 15) | (1 << 4)));
  635. }
  636. static int tg3_bmcr_reset(struct tg3 *tp)
  637. {
  638. u32 phy_control;
  639. int limit, err;
  640. /* OK, reset it, and poll the BMCR_RESET bit until it
  641. * clears or we time out.
  642. */
  643. phy_control = BMCR_RESET;
  644. err = tg3_writephy(tp, MII_BMCR, phy_control);
  645. if (err != 0)
  646. return -EBUSY;
  647. limit = 5000;
  648. while (limit--) {
  649. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  650. if (err != 0)
  651. return -EBUSY;
  652. if ((phy_control & BMCR_RESET) == 0) {
  653. udelay(40);
  654. break;
  655. }
  656. udelay(10);
  657. }
  658. if (limit <= 0)
  659. return -EBUSY;
  660. return 0;
  661. }
  662. static int tg3_wait_macro_done(struct tg3 *tp)
  663. {
  664. int limit = 100;
  665. while (limit--) {
  666. u32 tmp32;
  667. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  668. if ((tmp32 & 0x1000) == 0)
  669. break;
  670. }
  671. }
  672. if (limit <= 0)
  673. return -EBUSY;
  674. return 0;
  675. }
  676. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  677. {
  678. static const u32 test_pat[4][6] = {
  679. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  680. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  681. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  682. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  683. };
  684. int chan;
  685. for (chan = 0; chan < 4; chan++) {
  686. int i;
  687. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  688. (chan * 0x2000) | 0x0200);
  689. tg3_writephy(tp, 0x16, 0x0002);
  690. for (i = 0; i < 6; i++)
  691. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  692. test_pat[chan][i]);
  693. tg3_writephy(tp, 0x16, 0x0202);
  694. if (tg3_wait_macro_done(tp)) {
  695. *resetp = 1;
  696. return -EBUSY;
  697. }
  698. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  699. (chan * 0x2000) | 0x0200);
  700. tg3_writephy(tp, 0x16, 0x0082);
  701. if (tg3_wait_macro_done(tp)) {
  702. *resetp = 1;
  703. return -EBUSY;
  704. }
  705. tg3_writephy(tp, 0x16, 0x0802);
  706. if (tg3_wait_macro_done(tp)) {
  707. *resetp = 1;
  708. return -EBUSY;
  709. }
  710. for (i = 0; i < 6; i += 2) {
  711. u32 low, high;
  712. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  713. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  714. tg3_wait_macro_done(tp)) {
  715. *resetp = 1;
  716. return -EBUSY;
  717. }
  718. low &= 0x7fff;
  719. high &= 0x000f;
  720. if (low != test_pat[chan][i] ||
  721. high != test_pat[chan][i+1]) {
  722. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  723. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  724. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  725. return -EBUSY;
  726. }
  727. }
  728. }
  729. return 0;
  730. }
  731. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  732. {
  733. int chan;
  734. for (chan = 0; chan < 4; chan++) {
  735. int i;
  736. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  737. (chan * 0x2000) | 0x0200);
  738. tg3_writephy(tp, 0x16, 0x0002);
  739. for (i = 0; i < 6; i++)
  740. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  741. tg3_writephy(tp, 0x16, 0x0202);
  742. if (tg3_wait_macro_done(tp))
  743. return -EBUSY;
  744. }
  745. return 0;
  746. }
  747. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  748. {
  749. u32 reg32, phy9_orig;
  750. int retries, do_phy_reset, err;
  751. retries = 10;
  752. do_phy_reset = 1;
  753. do {
  754. if (do_phy_reset) {
  755. err = tg3_bmcr_reset(tp);
  756. if (err)
  757. return err;
  758. do_phy_reset = 0;
  759. }
  760. /* Disable transmitter and interrupt. */
  761. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  762. continue;
  763. reg32 |= 0x3000;
  764. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  765. /* Set full-duplex, 1000 mbps. */
  766. tg3_writephy(tp, MII_BMCR,
  767. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  768. /* Set to master mode. */
  769. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  770. continue;
  771. tg3_writephy(tp, MII_TG3_CTRL,
  772. (MII_TG3_CTRL_AS_MASTER |
  773. MII_TG3_CTRL_ENABLE_AS_MASTER));
  774. /* Enable SM_DSP_CLOCK and 6dB. */
  775. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  776. /* Block the PHY control access. */
  777. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  778. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  779. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  780. if (!err)
  781. break;
  782. } while (--retries);
  783. err = tg3_phy_reset_chanpat(tp);
  784. if (err)
  785. return err;
  786. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  787. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  788. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  789. tg3_writephy(tp, 0x16, 0x0000);
  790. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  791. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  792. /* Set Extended packet length bit for jumbo frames */
  793. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  794. }
  795. else {
  796. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  797. }
  798. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  799. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  800. reg32 &= ~0x3000;
  801. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  802. } else if (!err)
  803. err = -EBUSY;
  804. return err;
  805. }
  806. static void tg3_link_report(struct tg3 *);
  807. /* This will reset the tigon3 PHY if there is no valid
  808. * link unless the FORCE argument is non-zero.
  809. */
  810. static int tg3_phy_reset(struct tg3 *tp)
  811. {
  812. u32 phy_status;
  813. int err;
  814. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  815. u32 val;
  816. val = tr32(GRC_MISC_CFG);
  817. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  818. udelay(40);
  819. }
  820. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  821. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  822. if (err != 0)
  823. return -EBUSY;
  824. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  825. netif_carrier_off(tp->dev);
  826. tg3_link_report(tp);
  827. }
  828. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  829. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  830. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  831. err = tg3_phy_reset_5703_4_5(tp);
  832. if (err)
  833. return err;
  834. goto out;
  835. }
  836. err = tg3_bmcr_reset(tp);
  837. if (err)
  838. return err;
  839. out:
  840. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  841. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  842. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  843. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  844. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  845. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  846. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  847. }
  848. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  849. tg3_writephy(tp, 0x1c, 0x8d68);
  850. tg3_writephy(tp, 0x1c, 0x8d68);
  851. }
  852. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  853. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  854. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  855. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  856. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  857. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  858. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  859. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  860. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  861. }
  862. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  863. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  864. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  865. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  866. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  867. tg3_writephy(tp, MII_TG3_TEST1,
  868. MII_TG3_TEST1_TRIM_EN | 0x4);
  869. } else
  870. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  871. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  872. }
  873. /* Set Extended packet length bit (bit 14) on all chips that */
  874. /* support jumbo frames */
  875. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  876. /* Cannot do read-modify-write on 5401 */
  877. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  878. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  879. u32 phy_reg;
  880. /* Set bit 14 with read-modify-write to preserve other bits */
  881. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  882. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  883. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  884. }
  885. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  886. * jumbo frames transmission.
  887. */
  888. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  889. u32 phy_reg;
  890. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  891. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  892. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  893. }
  894. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  895. u32 phy_reg;
  896. /* adjust output voltage */
  897. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  898. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
  899. u32 phy_reg2;
  900. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  901. phy_reg | MII_TG3_EPHY_SHADOW_EN);
  902. /* Enable auto-MDIX */
  903. if (!tg3_readphy(tp, 0x10, &phy_reg2))
  904. tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
  905. tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
  906. }
  907. }
  908. tg3_phy_set_wirespeed(tp);
  909. return 0;
  910. }
  911. static void tg3_frob_aux_power(struct tg3 *tp)
  912. {
  913. struct tg3 *tp_peer = tp;
  914. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  915. return;
  916. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  917. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  918. struct net_device *dev_peer;
  919. dev_peer = pci_get_drvdata(tp->pdev_peer);
  920. /* remove_one() may have been run on the peer. */
  921. if (!dev_peer)
  922. tp_peer = tp;
  923. else
  924. tp_peer = netdev_priv(dev_peer);
  925. }
  926. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  927. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  928. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  929. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  930. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  931. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  932. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  933. (GRC_LCLCTRL_GPIO_OE0 |
  934. GRC_LCLCTRL_GPIO_OE1 |
  935. GRC_LCLCTRL_GPIO_OE2 |
  936. GRC_LCLCTRL_GPIO_OUTPUT0 |
  937. GRC_LCLCTRL_GPIO_OUTPUT1),
  938. 100);
  939. } else {
  940. u32 no_gpio2;
  941. u32 grc_local_ctrl = 0;
  942. if (tp_peer != tp &&
  943. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  944. return;
  945. /* Workaround to prevent overdrawing Amps. */
  946. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  947. ASIC_REV_5714) {
  948. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  949. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  950. grc_local_ctrl, 100);
  951. }
  952. /* On 5753 and variants, GPIO2 cannot be used. */
  953. no_gpio2 = tp->nic_sram_data_cfg &
  954. NIC_SRAM_DATA_CFG_NO_GPIO2;
  955. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  956. GRC_LCLCTRL_GPIO_OE1 |
  957. GRC_LCLCTRL_GPIO_OE2 |
  958. GRC_LCLCTRL_GPIO_OUTPUT1 |
  959. GRC_LCLCTRL_GPIO_OUTPUT2;
  960. if (no_gpio2) {
  961. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  962. GRC_LCLCTRL_GPIO_OUTPUT2);
  963. }
  964. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  965. grc_local_ctrl, 100);
  966. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  967. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  968. grc_local_ctrl, 100);
  969. if (!no_gpio2) {
  970. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  971. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  972. grc_local_ctrl, 100);
  973. }
  974. }
  975. } else {
  976. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  977. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  978. if (tp_peer != tp &&
  979. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  980. return;
  981. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  982. (GRC_LCLCTRL_GPIO_OE1 |
  983. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  984. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  985. GRC_LCLCTRL_GPIO_OE1, 100);
  986. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  987. (GRC_LCLCTRL_GPIO_OE1 |
  988. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  989. }
  990. }
  991. }
  992. static int tg3_setup_phy(struct tg3 *, int);
  993. #define RESET_KIND_SHUTDOWN 0
  994. #define RESET_KIND_INIT 1
  995. #define RESET_KIND_SUSPEND 2
  996. static void tg3_write_sig_post_reset(struct tg3 *, int);
  997. static int tg3_halt_cpu(struct tg3 *, u32);
  998. static int tg3_nvram_lock(struct tg3 *);
  999. static void tg3_nvram_unlock(struct tg3 *);
  1000. static void tg3_power_down_phy(struct tg3 *tp)
  1001. {
  1002. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1003. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1004. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1005. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1006. sg_dig_ctrl |=
  1007. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1008. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1009. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1010. }
  1011. return;
  1012. }
  1013. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1014. u32 val;
  1015. tg3_bmcr_reset(tp);
  1016. val = tr32(GRC_MISC_CFG);
  1017. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1018. udelay(40);
  1019. return;
  1020. } else {
  1021. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1022. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1023. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1024. }
  1025. /* The PHY should not be powered down on some chips because
  1026. * of bugs.
  1027. */
  1028. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1029. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1030. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1031. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1032. return;
  1033. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1034. }
  1035. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1036. {
  1037. u32 misc_host_ctrl;
  1038. u16 power_control, power_caps;
  1039. int pm = tp->pm_cap;
  1040. /* Make sure register accesses (indirect or otherwise)
  1041. * will function correctly.
  1042. */
  1043. pci_write_config_dword(tp->pdev,
  1044. TG3PCI_MISC_HOST_CTRL,
  1045. tp->misc_host_ctrl);
  1046. pci_read_config_word(tp->pdev,
  1047. pm + PCI_PM_CTRL,
  1048. &power_control);
  1049. power_control |= PCI_PM_CTRL_PME_STATUS;
  1050. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1051. switch (state) {
  1052. case PCI_D0:
  1053. power_control |= 0;
  1054. pci_write_config_word(tp->pdev,
  1055. pm + PCI_PM_CTRL,
  1056. power_control);
  1057. udelay(100); /* Delay after power state change */
  1058. /* Switch out of Vaux if it is a NIC */
  1059. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1060. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1061. return 0;
  1062. case PCI_D1:
  1063. power_control |= 1;
  1064. break;
  1065. case PCI_D2:
  1066. power_control |= 2;
  1067. break;
  1068. case PCI_D3hot:
  1069. power_control |= 3;
  1070. break;
  1071. default:
  1072. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1073. "requested.\n",
  1074. tp->dev->name, state);
  1075. return -EINVAL;
  1076. };
  1077. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1078. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1079. tw32(TG3PCI_MISC_HOST_CTRL,
  1080. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1081. if (tp->link_config.phy_is_low_power == 0) {
  1082. tp->link_config.phy_is_low_power = 1;
  1083. tp->link_config.orig_speed = tp->link_config.speed;
  1084. tp->link_config.orig_duplex = tp->link_config.duplex;
  1085. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1086. }
  1087. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1088. tp->link_config.speed = SPEED_10;
  1089. tp->link_config.duplex = DUPLEX_HALF;
  1090. tp->link_config.autoneg = AUTONEG_ENABLE;
  1091. tg3_setup_phy(tp, 0);
  1092. }
  1093. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1094. u32 val;
  1095. val = tr32(GRC_VCPU_EXT_CTRL);
  1096. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1097. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1098. int i;
  1099. u32 val;
  1100. for (i = 0; i < 200; i++) {
  1101. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1102. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1103. break;
  1104. msleep(1);
  1105. }
  1106. }
  1107. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  1108. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1109. WOL_DRV_STATE_SHUTDOWN |
  1110. WOL_DRV_WOL |
  1111. WOL_SET_MAGIC_PKT);
  1112. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1113. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1114. u32 mac_mode;
  1115. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1116. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1117. udelay(40);
  1118. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1119. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1120. else
  1121. mac_mode = MAC_MODE_PORT_MODE_MII;
  1122. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
  1123. !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
  1124. mac_mode |= MAC_MODE_LINK_POLARITY;
  1125. } else {
  1126. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1127. }
  1128. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1129. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1130. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1131. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1132. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1133. tw32_f(MAC_MODE, mac_mode);
  1134. udelay(100);
  1135. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1136. udelay(10);
  1137. }
  1138. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1139. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1140. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1141. u32 base_val;
  1142. base_val = tp->pci_clock_ctrl;
  1143. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1144. CLOCK_CTRL_TXCLK_DISABLE);
  1145. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1146. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1147. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1148. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1149. /* do nothing */
  1150. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1151. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1152. u32 newbits1, newbits2;
  1153. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1154. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1155. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1156. CLOCK_CTRL_TXCLK_DISABLE |
  1157. CLOCK_CTRL_ALTCLK);
  1158. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1159. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1160. newbits1 = CLOCK_CTRL_625_CORE;
  1161. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1162. } else {
  1163. newbits1 = CLOCK_CTRL_ALTCLK;
  1164. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1165. }
  1166. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1167. 40);
  1168. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1169. 40);
  1170. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1171. u32 newbits3;
  1172. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1173. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1174. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1175. CLOCK_CTRL_TXCLK_DISABLE |
  1176. CLOCK_CTRL_44MHZ_CORE);
  1177. } else {
  1178. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1179. }
  1180. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1181. tp->pci_clock_ctrl | newbits3, 40);
  1182. }
  1183. }
  1184. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1185. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  1186. tg3_power_down_phy(tp);
  1187. tg3_frob_aux_power(tp);
  1188. /* Workaround for unstable PLL clock */
  1189. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1190. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1191. u32 val = tr32(0x7d00);
  1192. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1193. tw32(0x7d00, val);
  1194. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1195. int err;
  1196. err = tg3_nvram_lock(tp);
  1197. tg3_halt_cpu(tp, RX_CPU_BASE);
  1198. if (!err)
  1199. tg3_nvram_unlock(tp);
  1200. }
  1201. }
  1202. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1203. /* Finally, set the new power state. */
  1204. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1205. udelay(100); /* Delay after power state change */
  1206. return 0;
  1207. }
  1208. static void tg3_link_report(struct tg3 *tp)
  1209. {
  1210. if (!netif_carrier_ok(tp->dev)) {
  1211. if (netif_msg_link(tp))
  1212. printk(KERN_INFO PFX "%s: Link is down.\n",
  1213. tp->dev->name);
  1214. } else if (netif_msg_link(tp)) {
  1215. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1216. tp->dev->name,
  1217. (tp->link_config.active_speed == SPEED_1000 ?
  1218. 1000 :
  1219. (tp->link_config.active_speed == SPEED_100 ?
  1220. 100 : 10)),
  1221. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1222. "full" : "half"));
  1223. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1224. "%s for RX.\n",
  1225. tp->dev->name,
  1226. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1227. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1228. }
  1229. }
  1230. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1231. {
  1232. u32 new_tg3_flags = 0;
  1233. u32 old_rx_mode = tp->rx_mode;
  1234. u32 old_tx_mode = tp->tx_mode;
  1235. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1236. /* Convert 1000BaseX flow control bits to 1000BaseT
  1237. * bits before resolving flow control.
  1238. */
  1239. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1240. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1241. ADVERTISE_PAUSE_ASYM);
  1242. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1243. if (local_adv & ADVERTISE_1000XPAUSE)
  1244. local_adv |= ADVERTISE_PAUSE_CAP;
  1245. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1246. local_adv |= ADVERTISE_PAUSE_ASYM;
  1247. if (remote_adv & LPA_1000XPAUSE)
  1248. remote_adv |= LPA_PAUSE_CAP;
  1249. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1250. remote_adv |= LPA_PAUSE_ASYM;
  1251. }
  1252. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1253. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1254. if (remote_adv & LPA_PAUSE_CAP)
  1255. new_tg3_flags |=
  1256. (TG3_FLAG_RX_PAUSE |
  1257. TG3_FLAG_TX_PAUSE);
  1258. else if (remote_adv & LPA_PAUSE_ASYM)
  1259. new_tg3_flags |=
  1260. (TG3_FLAG_RX_PAUSE);
  1261. } else {
  1262. if (remote_adv & LPA_PAUSE_CAP)
  1263. new_tg3_flags |=
  1264. (TG3_FLAG_RX_PAUSE |
  1265. TG3_FLAG_TX_PAUSE);
  1266. }
  1267. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1268. if ((remote_adv & LPA_PAUSE_CAP) &&
  1269. (remote_adv & LPA_PAUSE_ASYM))
  1270. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1271. }
  1272. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1273. tp->tg3_flags |= new_tg3_flags;
  1274. } else {
  1275. new_tg3_flags = tp->tg3_flags;
  1276. }
  1277. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1278. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1279. else
  1280. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1281. if (old_rx_mode != tp->rx_mode) {
  1282. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1283. }
  1284. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1285. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1286. else
  1287. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1288. if (old_tx_mode != tp->tx_mode) {
  1289. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1290. }
  1291. }
  1292. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1293. {
  1294. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1295. case MII_TG3_AUX_STAT_10HALF:
  1296. *speed = SPEED_10;
  1297. *duplex = DUPLEX_HALF;
  1298. break;
  1299. case MII_TG3_AUX_STAT_10FULL:
  1300. *speed = SPEED_10;
  1301. *duplex = DUPLEX_FULL;
  1302. break;
  1303. case MII_TG3_AUX_STAT_100HALF:
  1304. *speed = SPEED_100;
  1305. *duplex = DUPLEX_HALF;
  1306. break;
  1307. case MII_TG3_AUX_STAT_100FULL:
  1308. *speed = SPEED_100;
  1309. *duplex = DUPLEX_FULL;
  1310. break;
  1311. case MII_TG3_AUX_STAT_1000HALF:
  1312. *speed = SPEED_1000;
  1313. *duplex = DUPLEX_HALF;
  1314. break;
  1315. case MII_TG3_AUX_STAT_1000FULL:
  1316. *speed = SPEED_1000;
  1317. *duplex = DUPLEX_FULL;
  1318. break;
  1319. default:
  1320. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1321. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1322. SPEED_10;
  1323. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1324. DUPLEX_HALF;
  1325. break;
  1326. }
  1327. *speed = SPEED_INVALID;
  1328. *duplex = DUPLEX_INVALID;
  1329. break;
  1330. };
  1331. }
  1332. static void tg3_phy_copper_begin(struct tg3 *tp)
  1333. {
  1334. u32 new_adv;
  1335. int i;
  1336. if (tp->link_config.phy_is_low_power) {
  1337. /* Entering low power mode. Disable gigabit and
  1338. * 100baseT advertisements.
  1339. */
  1340. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1341. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1342. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1343. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1344. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1345. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1346. } else if (tp->link_config.speed == SPEED_INVALID) {
  1347. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1348. tp->link_config.advertising &=
  1349. ~(ADVERTISED_1000baseT_Half |
  1350. ADVERTISED_1000baseT_Full);
  1351. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1352. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1353. new_adv |= ADVERTISE_10HALF;
  1354. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1355. new_adv |= ADVERTISE_10FULL;
  1356. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1357. new_adv |= ADVERTISE_100HALF;
  1358. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1359. new_adv |= ADVERTISE_100FULL;
  1360. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1361. if (tp->link_config.advertising &
  1362. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1363. new_adv = 0;
  1364. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1365. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1366. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1367. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1368. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1369. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1370. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1371. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1372. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1373. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1374. } else {
  1375. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1376. }
  1377. } else {
  1378. /* Asking for a specific link mode. */
  1379. if (tp->link_config.speed == SPEED_1000) {
  1380. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1381. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1382. if (tp->link_config.duplex == DUPLEX_FULL)
  1383. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1384. else
  1385. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1386. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1387. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1388. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1389. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1390. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1391. } else {
  1392. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1393. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1394. if (tp->link_config.speed == SPEED_100) {
  1395. if (tp->link_config.duplex == DUPLEX_FULL)
  1396. new_adv |= ADVERTISE_100FULL;
  1397. else
  1398. new_adv |= ADVERTISE_100HALF;
  1399. } else {
  1400. if (tp->link_config.duplex == DUPLEX_FULL)
  1401. new_adv |= ADVERTISE_10FULL;
  1402. else
  1403. new_adv |= ADVERTISE_10HALF;
  1404. }
  1405. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1406. }
  1407. }
  1408. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1409. tp->link_config.speed != SPEED_INVALID) {
  1410. u32 bmcr, orig_bmcr;
  1411. tp->link_config.active_speed = tp->link_config.speed;
  1412. tp->link_config.active_duplex = tp->link_config.duplex;
  1413. bmcr = 0;
  1414. switch (tp->link_config.speed) {
  1415. default:
  1416. case SPEED_10:
  1417. break;
  1418. case SPEED_100:
  1419. bmcr |= BMCR_SPEED100;
  1420. break;
  1421. case SPEED_1000:
  1422. bmcr |= TG3_BMCR_SPEED1000;
  1423. break;
  1424. };
  1425. if (tp->link_config.duplex == DUPLEX_FULL)
  1426. bmcr |= BMCR_FULLDPLX;
  1427. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1428. (bmcr != orig_bmcr)) {
  1429. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1430. for (i = 0; i < 1500; i++) {
  1431. u32 tmp;
  1432. udelay(10);
  1433. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1434. tg3_readphy(tp, MII_BMSR, &tmp))
  1435. continue;
  1436. if (!(tmp & BMSR_LSTATUS)) {
  1437. udelay(40);
  1438. break;
  1439. }
  1440. }
  1441. tg3_writephy(tp, MII_BMCR, bmcr);
  1442. udelay(40);
  1443. }
  1444. } else {
  1445. tg3_writephy(tp, MII_BMCR,
  1446. BMCR_ANENABLE | BMCR_ANRESTART);
  1447. }
  1448. }
  1449. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1450. {
  1451. int err;
  1452. /* Turn off tap power management. */
  1453. /* Set Extended packet length bit */
  1454. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1455. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1456. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1457. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1458. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1459. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1460. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1461. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1462. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1463. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1464. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1465. udelay(40);
  1466. return err;
  1467. }
  1468. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1469. {
  1470. u32 adv_reg, all_mask = 0;
  1471. if (mask & ADVERTISED_10baseT_Half)
  1472. all_mask |= ADVERTISE_10HALF;
  1473. if (mask & ADVERTISED_10baseT_Full)
  1474. all_mask |= ADVERTISE_10FULL;
  1475. if (mask & ADVERTISED_100baseT_Half)
  1476. all_mask |= ADVERTISE_100HALF;
  1477. if (mask & ADVERTISED_100baseT_Full)
  1478. all_mask |= ADVERTISE_100FULL;
  1479. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1480. return 0;
  1481. if ((adv_reg & all_mask) != all_mask)
  1482. return 0;
  1483. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1484. u32 tg3_ctrl;
  1485. all_mask = 0;
  1486. if (mask & ADVERTISED_1000baseT_Half)
  1487. all_mask |= ADVERTISE_1000HALF;
  1488. if (mask & ADVERTISED_1000baseT_Full)
  1489. all_mask |= ADVERTISE_1000FULL;
  1490. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1491. return 0;
  1492. if ((tg3_ctrl & all_mask) != all_mask)
  1493. return 0;
  1494. }
  1495. return 1;
  1496. }
  1497. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1498. {
  1499. int current_link_up;
  1500. u32 bmsr, dummy;
  1501. u16 current_speed;
  1502. u8 current_duplex;
  1503. int i, err;
  1504. tw32(MAC_EVENT, 0);
  1505. tw32_f(MAC_STATUS,
  1506. (MAC_STATUS_SYNC_CHANGED |
  1507. MAC_STATUS_CFG_CHANGED |
  1508. MAC_STATUS_MI_COMPLETION |
  1509. MAC_STATUS_LNKSTATE_CHANGED));
  1510. udelay(40);
  1511. tp->mi_mode = MAC_MI_MODE_BASE;
  1512. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1513. udelay(80);
  1514. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1515. /* Some third-party PHYs need to be reset on link going
  1516. * down.
  1517. */
  1518. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1519. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1520. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1521. netif_carrier_ok(tp->dev)) {
  1522. tg3_readphy(tp, MII_BMSR, &bmsr);
  1523. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1524. !(bmsr & BMSR_LSTATUS))
  1525. force_reset = 1;
  1526. }
  1527. if (force_reset)
  1528. tg3_phy_reset(tp);
  1529. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1530. tg3_readphy(tp, MII_BMSR, &bmsr);
  1531. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1532. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1533. bmsr = 0;
  1534. if (!(bmsr & BMSR_LSTATUS)) {
  1535. err = tg3_init_5401phy_dsp(tp);
  1536. if (err)
  1537. return err;
  1538. tg3_readphy(tp, MII_BMSR, &bmsr);
  1539. for (i = 0; i < 1000; i++) {
  1540. udelay(10);
  1541. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1542. (bmsr & BMSR_LSTATUS)) {
  1543. udelay(40);
  1544. break;
  1545. }
  1546. }
  1547. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1548. !(bmsr & BMSR_LSTATUS) &&
  1549. tp->link_config.active_speed == SPEED_1000) {
  1550. err = tg3_phy_reset(tp);
  1551. if (!err)
  1552. err = tg3_init_5401phy_dsp(tp);
  1553. if (err)
  1554. return err;
  1555. }
  1556. }
  1557. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1558. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1559. /* 5701 {A0,B0} CRC bug workaround */
  1560. tg3_writephy(tp, 0x15, 0x0a75);
  1561. tg3_writephy(tp, 0x1c, 0x8c68);
  1562. tg3_writephy(tp, 0x1c, 0x8d68);
  1563. tg3_writephy(tp, 0x1c, 0x8c68);
  1564. }
  1565. /* Clear pending interrupts... */
  1566. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1567. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1568. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1569. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1570. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1571. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1572. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1573. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1574. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1575. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1576. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1577. else
  1578. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1579. }
  1580. current_link_up = 0;
  1581. current_speed = SPEED_INVALID;
  1582. current_duplex = DUPLEX_INVALID;
  1583. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1584. u32 val;
  1585. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1586. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1587. if (!(val & (1 << 10))) {
  1588. val |= (1 << 10);
  1589. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1590. goto relink;
  1591. }
  1592. }
  1593. bmsr = 0;
  1594. for (i = 0; i < 100; i++) {
  1595. tg3_readphy(tp, MII_BMSR, &bmsr);
  1596. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1597. (bmsr & BMSR_LSTATUS))
  1598. break;
  1599. udelay(40);
  1600. }
  1601. if (bmsr & BMSR_LSTATUS) {
  1602. u32 aux_stat, bmcr;
  1603. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1604. for (i = 0; i < 2000; i++) {
  1605. udelay(10);
  1606. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1607. aux_stat)
  1608. break;
  1609. }
  1610. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1611. &current_speed,
  1612. &current_duplex);
  1613. bmcr = 0;
  1614. for (i = 0; i < 200; i++) {
  1615. tg3_readphy(tp, MII_BMCR, &bmcr);
  1616. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1617. continue;
  1618. if (bmcr && bmcr != 0x7fff)
  1619. break;
  1620. udelay(10);
  1621. }
  1622. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1623. if (bmcr & BMCR_ANENABLE) {
  1624. current_link_up = 1;
  1625. /* Force autoneg restart if we are exiting
  1626. * low power mode.
  1627. */
  1628. if (!tg3_copper_is_advertising_all(tp,
  1629. tp->link_config.advertising))
  1630. current_link_up = 0;
  1631. } else {
  1632. current_link_up = 0;
  1633. }
  1634. } else {
  1635. if (!(bmcr & BMCR_ANENABLE) &&
  1636. tp->link_config.speed == current_speed &&
  1637. tp->link_config.duplex == current_duplex) {
  1638. current_link_up = 1;
  1639. } else {
  1640. current_link_up = 0;
  1641. }
  1642. }
  1643. tp->link_config.active_speed = current_speed;
  1644. tp->link_config.active_duplex = current_duplex;
  1645. }
  1646. if (current_link_up == 1 &&
  1647. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1648. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1649. u32 local_adv, remote_adv;
  1650. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1651. local_adv = 0;
  1652. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1653. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1654. remote_adv = 0;
  1655. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1656. /* If we are not advertising full pause capability,
  1657. * something is wrong. Bring the link down and reconfigure.
  1658. */
  1659. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1660. current_link_up = 0;
  1661. } else {
  1662. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1663. }
  1664. }
  1665. relink:
  1666. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1667. u32 tmp;
  1668. tg3_phy_copper_begin(tp);
  1669. tg3_readphy(tp, MII_BMSR, &tmp);
  1670. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1671. (tmp & BMSR_LSTATUS))
  1672. current_link_up = 1;
  1673. }
  1674. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1675. if (current_link_up == 1) {
  1676. if (tp->link_config.active_speed == SPEED_100 ||
  1677. tp->link_config.active_speed == SPEED_10)
  1678. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1679. else
  1680. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1681. } else
  1682. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1683. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1684. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1685. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1686. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1687. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1688. if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
  1689. (current_link_up == 1 &&
  1690. tp->link_config.active_speed == SPEED_10))
  1691. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1692. } else {
  1693. if (current_link_up == 1)
  1694. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1695. }
  1696. /* ??? Without this setting Netgear GA302T PHY does not
  1697. * ??? send/receive packets...
  1698. */
  1699. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1700. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1701. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1702. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1703. udelay(80);
  1704. }
  1705. tw32_f(MAC_MODE, tp->mac_mode);
  1706. udelay(40);
  1707. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1708. /* Polled via timer. */
  1709. tw32_f(MAC_EVENT, 0);
  1710. } else {
  1711. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1712. }
  1713. udelay(40);
  1714. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1715. current_link_up == 1 &&
  1716. tp->link_config.active_speed == SPEED_1000 &&
  1717. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1718. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1719. udelay(120);
  1720. tw32_f(MAC_STATUS,
  1721. (MAC_STATUS_SYNC_CHANGED |
  1722. MAC_STATUS_CFG_CHANGED));
  1723. udelay(40);
  1724. tg3_write_mem(tp,
  1725. NIC_SRAM_FIRMWARE_MBOX,
  1726. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1727. }
  1728. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1729. if (current_link_up)
  1730. netif_carrier_on(tp->dev);
  1731. else
  1732. netif_carrier_off(tp->dev);
  1733. tg3_link_report(tp);
  1734. }
  1735. return 0;
  1736. }
  1737. struct tg3_fiber_aneginfo {
  1738. int state;
  1739. #define ANEG_STATE_UNKNOWN 0
  1740. #define ANEG_STATE_AN_ENABLE 1
  1741. #define ANEG_STATE_RESTART_INIT 2
  1742. #define ANEG_STATE_RESTART 3
  1743. #define ANEG_STATE_DISABLE_LINK_OK 4
  1744. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1745. #define ANEG_STATE_ABILITY_DETECT 6
  1746. #define ANEG_STATE_ACK_DETECT_INIT 7
  1747. #define ANEG_STATE_ACK_DETECT 8
  1748. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1749. #define ANEG_STATE_COMPLETE_ACK 10
  1750. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1751. #define ANEG_STATE_IDLE_DETECT 12
  1752. #define ANEG_STATE_LINK_OK 13
  1753. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1754. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1755. u32 flags;
  1756. #define MR_AN_ENABLE 0x00000001
  1757. #define MR_RESTART_AN 0x00000002
  1758. #define MR_AN_COMPLETE 0x00000004
  1759. #define MR_PAGE_RX 0x00000008
  1760. #define MR_NP_LOADED 0x00000010
  1761. #define MR_TOGGLE_TX 0x00000020
  1762. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1763. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1764. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1765. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1766. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1767. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1768. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1769. #define MR_TOGGLE_RX 0x00002000
  1770. #define MR_NP_RX 0x00004000
  1771. #define MR_LINK_OK 0x80000000
  1772. unsigned long link_time, cur_time;
  1773. u32 ability_match_cfg;
  1774. int ability_match_count;
  1775. char ability_match, idle_match, ack_match;
  1776. u32 txconfig, rxconfig;
  1777. #define ANEG_CFG_NP 0x00000080
  1778. #define ANEG_CFG_ACK 0x00000040
  1779. #define ANEG_CFG_RF2 0x00000020
  1780. #define ANEG_CFG_RF1 0x00000010
  1781. #define ANEG_CFG_PS2 0x00000001
  1782. #define ANEG_CFG_PS1 0x00008000
  1783. #define ANEG_CFG_HD 0x00004000
  1784. #define ANEG_CFG_FD 0x00002000
  1785. #define ANEG_CFG_INVAL 0x00001f06
  1786. };
  1787. #define ANEG_OK 0
  1788. #define ANEG_DONE 1
  1789. #define ANEG_TIMER_ENAB 2
  1790. #define ANEG_FAILED -1
  1791. #define ANEG_STATE_SETTLE_TIME 10000
  1792. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1793. struct tg3_fiber_aneginfo *ap)
  1794. {
  1795. unsigned long delta;
  1796. u32 rx_cfg_reg;
  1797. int ret;
  1798. if (ap->state == ANEG_STATE_UNKNOWN) {
  1799. ap->rxconfig = 0;
  1800. ap->link_time = 0;
  1801. ap->cur_time = 0;
  1802. ap->ability_match_cfg = 0;
  1803. ap->ability_match_count = 0;
  1804. ap->ability_match = 0;
  1805. ap->idle_match = 0;
  1806. ap->ack_match = 0;
  1807. }
  1808. ap->cur_time++;
  1809. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1810. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1811. if (rx_cfg_reg != ap->ability_match_cfg) {
  1812. ap->ability_match_cfg = rx_cfg_reg;
  1813. ap->ability_match = 0;
  1814. ap->ability_match_count = 0;
  1815. } else {
  1816. if (++ap->ability_match_count > 1) {
  1817. ap->ability_match = 1;
  1818. ap->ability_match_cfg = rx_cfg_reg;
  1819. }
  1820. }
  1821. if (rx_cfg_reg & ANEG_CFG_ACK)
  1822. ap->ack_match = 1;
  1823. else
  1824. ap->ack_match = 0;
  1825. ap->idle_match = 0;
  1826. } else {
  1827. ap->idle_match = 1;
  1828. ap->ability_match_cfg = 0;
  1829. ap->ability_match_count = 0;
  1830. ap->ability_match = 0;
  1831. ap->ack_match = 0;
  1832. rx_cfg_reg = 0;
  1833. }
  1834. ap->rxconfig = rx_cfg_reg;
  1835. ret = ANEG_OK;
  1836. switch(ap->state) {
  1837. case ANEG_STATE_UNKNOWN:
  1838. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1839. ap->state = ANEG_STATE_AN_ENABLE;
  1840. /* fallthru */
  1841. case ANEG_STATE_AN_ENABLE:
  1842. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1843. if (ap->flags & MR_AN_ENABLE) {
  1844. ap->link_time = 0;
  1845. ap->cur_time = 0;
  1846. ap->ability_match_cfg = 0;
  1847. ap->ability_match_count = 0;
  1848. ap->ability_match = 0;
  1849. ap->idle_match = 0;
  1850. ap->ack_match = 0;
  1851. ap->state = ANEG_STATE_RESTART_INIT;
  1852. } else {
  1853. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1854. }
  1855. break;
  1856. case ANEG_STATE_RESTART_INIT:
  1857. ap->link_time = ap->cur_time;
  1858. ap->flags &= ~(MR_NP_LOADED);
  1859. ap->txconfig = 0;
  1860. tw32(MAC_TX_AUTO_NEG, 0);
  1861. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1862. tw32_f(MAC_MODE, tp->mac_mode);
  1863. udelay(40);
  1864. ret = ANEG_TIMER_ENAB;
  1865. ap->state = ANEG_STATE_RESTART;
  1866. /* fallthru */
  1867. case ANEG_STATE_RESTART:
  1868. delta = ap->cur_time - ap->link_time;
  1869. if (delta > ANEG_STATE_SETTLE_TIME) {
  1870. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1871. } else {
  1872. ret = ANEG_TIMER_ENAB;
  1873. }
  1874. break;
  1875. case ANEG_STATE_DISABLE_LINK_OK:
  1876. ret = ANEG_DONE;
  1877. break;
  1878. case ANEG_STATE_ABILITY_DETECT_INIT:
  1879. ap->flags &= ~(MR_TOGGLE_TX);
  1880. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1881. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1882. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1883. tw32_f(MAC_MODE, tp->mac_mode);
  1884. udelay(40);
  1885. ap->state = ANEG_STATE_ABILITY_DETECT;
  1886. break;
  1887. case ANEG_STATE_ABILITY_DETECT:
  1888. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1889. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1890. }
  1891. break;
  1892. case ANEG_STATE_ACK_DETECT_INIT:
  1893. ap->txconfig |= ANEG_CFG_ACK;
  1894. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1895. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1896. tw32_f(MAC_MODE, tp->mac_mode);
  1897. udelay(40);
  1898. ap->state = ANEG_STATE_ACK_DETECT;
  1899. /* fallthru */
  1900. case ANEG_STATE_ACK_DETECT:
  1901. if (ap->ack_match != 0) {
  1902. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1903. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1904. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1905. } else {
  1906. ap->state = ANEG_STATE_AN_ENABLE;
  1907. }
  1908. } else if (ap->ability_match != 0 &&
  1909. ap->rxconfig == 0) {
  1910. ap->state = ANEG_STATE_AN_ENABLE;
  1911. }
  1912. break;
  1913. case ANEG_STATE_COMPLETE_ACK_INIT:
  1914. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1915. ret = ANEG_FAILED;
  1916. break;
  1917. }
  1918. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1919. MR_LP_ADV_HALF_DUPLEX |
  1920. MR_LP_ADV_SYM_PAUSE |
  1921. MR_LP_ADV_ASYM_PAUSE |
  1922. MR_LP_ADV_REMOTE_FAULT1 |
  1923. MR_LP_ADV_REMOTE_FAULT2 |
  1924. MR_LP_ADV_NEXT_PAGE |
  1925. MR_TOGGLE_RX |
  1926. MR_NP_RX);
  1927. if (ap->rxconfig & ANEG_CFG_FD)
  1928. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1929. if (ap->rxconfig & ANEG_CFG_HD)
  1930. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1931. if (ap->rxconfig & ANEG_CFG_PS1)
  1932. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1933. if (ap->rxconfig & ANEG_CFG_PS2)
  1934. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1935. if (ap->rxconfig & ANEG_CFG_RF1)
  1936. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1937. if (ap->rxconfig & ANEG_CFG_RF2)
  1938. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1939. if (ap->rxconfig & ANEG_CFG_NP)
  1940. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1941. ap->link_time = ap->cur_time;
  1942. ap->flags ^= (MR_TOGGLE_TX);
  1943. if (ap->rxconfig & 0x0008)
  1944. ap->flags |= MR_TOGGLE_RX;
  1945. if (ap->rxconfig & ANEG_CFG_NP)
  1946. ap->flags |= MR_NP_RX;
  1947. ap->flags |= MR_PAGE_RX;
  1948. ap->state = ANEG_STATE_COMPLETE_ACK;
  1949. ret = ANEG_TIMER_ENAB;
  1950. break;
  1951. case ANEG_STATE_COMPLETE_ACK:
  1952. if (ap->ability_match != 0 &&
  1953. ap->rxconfig == 0) {
  1954. ap->state = ANEG_STATE_AN_ENABLE;
  1955. break;
  1956. }
  1957. delta = ap->cur_time - ap->link_time;
  1958. if (delta > ANEG_STATE_SETTLE_TIME) {
  1959. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  1960. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1961. } else {
  1962. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  1963. !(ap->flags & MR_NP_RX)) {
  1964. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1965. } else {
  1966. ret = ANEG_FAILED;
  1967. }
  1968. }
  1969. }
  1970. break;
  1971. case ANEG_STATE_IDLE_DETECT_INIT:
  1972. ap->link_time = ap->cur_time;
  1973. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1974. tw32_f(MAC_MODE, tp->mac_mode);
  1975. udelay(40);
  1976. ap->state = ANEG_STATE_IDLE_DETECT;
  1977. ret = ANEG_TIMER_ENAB;
  1978. break;
  1979. case ANEG_STATE_IDLE_DETECT:
  1980. if (ap->ability_match != 0 &&
  1981. ap->rxconfig == 0) {
  1982. ap->state = ANEG_STATE_AN_ENABLE;
  1983. break;
  1984. }
  1985. delta = ap->cur_time - ap->link_time;
  1986. if (delta > ANEG_STATE_SETTLE_TIME) {
  1987. /* XXX another gem from the Broadcom driver :( */
  1988. ap->state = ANEG_STATE_LINK_OK;
  1989. }
  1990. break;
  1991. case ANEG_STATE_LINK_OK:
  1992. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1993. ret = ANEG_DONE;
  1994. break;
  1995. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1996. /* ??? unimplemented */
  1997. break;
  1998. case ANEG_STATE_NEXT_PAGE_WAIT:
  1999. /* ??? unimplemented */
  2000. break;
  2001. default:
  2002. ret = ANEG_FAILED;
  2003. break;
  2004. };
  2005. return ret;
  2006. }
  2007. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  2008. {
  2009. int res = 0;
  2010. struct tg3_fiber_aneginfo aninfo;
  2011. int status = ANEG_FAILED;
  2012. unsigned int tick;
  2013. u32 tmp;
  2014. tw32_f(MAC_TX_AUTO_NEG, 0);
  2015. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2016. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2017. udelay(40);
  2018. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2019. udelay(40);
  2020. memset(&aninfo, 0, sizeof(aninfo));
  2021. aninfo.flags |= MR_AN_ENABLE;
  2022. aninfo.state = ANEG_STATE_UNKNOWN;
  2023. aninfo.cur_time = 0;
  2024. tick = 0;
  2025. while (++tick < 195000) {
  2026. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2027. if (status == ANEG_DONE || status == ANEG_FAILED)
  2028. break;
  2029. udelay(1);
  2030. }
  2031. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2032. tw32_f(MAC_MODE, tp->mac_mode);
  2033. udelay(40);
  2034. *flags = aninfo.flags;
  2035. if (status == ANEG_DONE &&
  2036. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2037. MR_LP_ADV_FULL_DUPLEX)))
  2038. res = 1;
  2039. return res;
  2040. }
  2041. static void tg3_init_bcm8002(struct tg3 *tp)
  2042. {
  2043. u32 mac_status = tr32(MAC_STATUS);
  2044. int i;
  2045. /* Reset when initting first time or we have a link. */
  2046. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2047. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2048. return;
  2049. /* Set PLL lock range. */
  2050. tg3_writephy(tp, 0x16, 0x8007);
  2051. /* SW reset */
  2052. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2053. /* Wait for reset to complete. */
  2054. /* XXX schedule_timeout() ... */
  2055. for (i = 0; i < 500; i++)
  2056. udelay(10);
  2057. /* Config mode; select PMA/Ch 1 regs. */
  2058. tg3_writephy(tp, 0x10, 0x8411);
  2059. /* Enable auto-lock and comdet, select txclk for tx. */
  2060. tg3_writephy(tp, 0x11, 0x0a10);
  2061. tg3_writephy(tp, 0x18, 0x00a0);
  2062. tg3_writephy(tp, 0x16, 0x41ff);
  2063. /* Assert and deassert POR. */
  2064. tg3_writephy(tp, 0x13, 0x0400);
  2065. udelay(40);
  2066. tg3_writephy(tp, 0x13, 0x0000);
  2067. tg3_writephy(tp, 0x11, 0x0a50);
  2068. udelay(40);
  2069. tg3_writephy(tp, 0x11, 0x0a10);
  2070. /* Wait for signal to stabilize */
  2071. /* XXX schedule_timeout() ... */
  2072. for (i = 0; i < 15000; i++)
  2073. udelay(10);
  2074. /* Deselect the channel register so we can read the PHYID
  2075. * later.
  2076. */
  2077. tg3_writephy(tp, 0x10, 0x8011);
  2078. }
  2079. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2080. {
  2081. u32 sg_dig_ctrl, sg_dig_status;
  2082. u32 serdes_cfg, expected_sg_dig_ctrl;
  2083. int workaround, port_a;
  2084. int current_link_up;
  2085. serdes_cfg = 0;
  2086. expected_sg_dig_ctrl = 0;
  2087. workaround = 0;
  2088. port_a = 1;
  2089. current_link_up = 0;
  2090. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2091. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2092. workaround = 1;
  2093. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2094. port_a = 0;
  2095. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2096. /* preserve bits 20-23 for voltage regulator */
  2097. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2098. }
  2099. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2100. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2101. if (sg_dig_ctrl & (1 << 31)) {
  2102. if (workaround) {
  2103. u32 val = serdes_cfg;
  2104. if (port_a)
  2105. val |= 0xc010000;
  2106. else
  2107. val |= 0x4010000;
  2108. tw32_f(MAC_SERDES_CFG, val);
  2109. }
  2110. tw32_f(SG_DIG_CTRL, 0x01388400);
  2111. }
  2112. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2113. tg3_setup_flow_control(tp, 0, 0);
  2114. current_link_up = 1;
  2115. }
  2116. goto out;
  2117. }
  2118. /* Want auto-negotiation. */
  2119. expected_sg_dig_ctrl = 0x81388400;
  2120. /* Pause capability */
  2121. expected_sg_dig_ctrl |= (1 << 11);
  2122. /* Asymettric pause */
  2123. expected_sg_dig_ctrl |= (1 << 12);
  2124. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2125. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2126. tp->serdes_counter &&
  2127. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2128. MAC_STATUS_RCVD_CFG)) ==
  2129. MAC_STATUS_PCS_SYNCED)) {
  2130. tp->serdes_counter--;
  2131. current_link_up = 1;
  2132. goto out;
  2133. }
  2134. restart_autoneg:
  2135. if (workaround)
  2136. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2137. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2138. udelay(5);
  2139. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2140. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2141. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2142. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2143. MAC_STATUS_SIGNAL_DET)) {
  2144. sg_dig_status = tr32(SG_DIG_STATUS);
  2145. mac_status = tr32(MAC_STATUS);
  2146. if ((sg_dig_status & (1 << 1)) &&
  2147. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2148. u32 local_adv, remote_adv;
  2149. local_adv = ADVERTISE_PAUSE_CAP;
  2150. remote_adv = 0;
  2151. if (sg_dig_status & (1 << 19))
  2152. remote_adv |= LPA_PAUSE_CAP;
  2153. if (sg_dig_status & (1 << 20))
  2154. remote_adv |= LPA_PAUSE_ASYM;
  2155. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2156. current_link_up = 1;
  2157. tp->serdes_counter = 0;
  2158. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2159. } else if (!(sg_dig_status & (1 << 1))) {
  2160. if (tp->serdes_counter)
  2161. tp->serdes_counter--;
  2162. else {
  2163. if (workaround) {
  2164. u32 val = serdes_cfg;
  2165. if (port_a)
  2166. val |= 0xc010000;
  2167. else
  2168. val |= 0x4010000;
  2169. tw32_f(MAC_SERDES_CFG, val);
  2170. }
  2171. tw32_f(SG_DIG_CTRL, 0x01388400);
  2172. udelay(40);
  2173. /* Link parallel detection - link is up */
  2174. /* only if we have PCS_SYNC and not */
  2175. /* receiving config code words */
  2176. mac_status = tr32(MAC_STATUS);
  2177. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2178. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2179. tg3_setup_flow_control(tp, 0, 0);
  2180. current_link_up = 1;
  2181. tp->tg3_flags2 |=
  2182. TG3_FLG2_PARALLEL_DETECT;
  2183. tp->serdes_counter =
  2184. SERDES_PARALLEL_DET_TIMEOUT;
  2185. } else
  2186. goto restart_autoneg;
  2187. }
  2188. }
  2189. } else {
  2190. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2191. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2192. }
  2193. out:
  2194. return current_link_up;
  2195. }
  2196. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2197. {
  2198. int current_link_up = 0;
  2199. if (!(mac_status & MAC_STATUS_PCS_SYNCED))
  2200. goto out;
  2201. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2202. u32 flags;
  2203. int i;
  2204. if (fiber_autoneg(tp, &flags)) {
  2205. u32 local_adv, remote_adv;
  2206. local_adv = ADVERTISE_PAUSE_CAP;
  2207. remote_adv = 0;
  2208. if (flags & MR_LP_ADV_SYM_PAUSE)
  2209. remote_adv |= LPA_PAUSE_CAP;
  2210. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2211. remote_adv |= LPA_PAUSE_ASYM;
  2212. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2213. current_link_up = 1;
  2214. }
  2215. for (i = 0; i < 30; i++) {
  2216. udelay(20);
  2217. tw32_f(MAC_STATUS,
  2218. (MAC_STATUS_SYNC_CHANGED |
  2219. MAC_STATUS_CFG_CHANGED));
  2220. udelay(40);
  2221. if ((tr32(MAC_STATUS) &
  2222. (MAC_STATUS_SYNC_CHANGED |
  2223. MAC_STATUS_CFG_CHANGED)) == 0)
  2224. break;
  2225. }
  2226. mac_status = tr32(MAC_STATUS);
  2227. if (current_link_up == 0 &&
  2228. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2229. !(mac_status & MAC_STATUS_RCVD_CFG))
  2230. current_link_up = 1;
  2231. } else {
  2232. /* Forcing 1000FD link up. */
  2233. current_link_up = 1;
  2234. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2235. udelay(40);
  2236. }
  2237. out:
  2238. return current_link_up;
  2239. }
  2240. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2241. {
  2242. u32 orig_pause_cfg;
  2243. u16 orig_active_speed;
  2244. u8 orig_active_duplex;
  2245. u32 mac_status;
  2246. int current_link_up;
  2247. int i;
  2248. orig_pause_cfg =
  2249. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2250. TG3_FLAG_TX_PAUSE));
  2251. orig_active_speed = tp->link_config.active_speed;
  2252. orig_active_duplex = tp->link_config.active_duplex;
  2253. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2254. netif_carrier_ok(tp->dev) &&
  2255. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2256. mac_status = tr32(MAC_STATUS);
  2257. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2258. MAC_STATUS_SIGNAL_DET |
  2259. MAC_STATUS_CFG_CHANGED |
  2260. MAC_STATUS_RCVD_CFG);
  2261. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2262. MAC_STATUS_SIGNAL_DET)) {
  2263. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2264. MAC_STATUS_CFG_CHANGED));
  2265. return 0;
  2266. }
  2267. }
  2268. tw32_f(MAC_TX_AUTO_NEG, 0);
  2269. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2270. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2271. tw32_f(MAC_MODE, tp->mac_mode);
  2272. udelay(40);
  2273. if (tp->phy_id == PHY_ID_BCM8002)
  2274. tg3_init_bcm8002(tp);
  2275. /* Enable link change event even when serdes polling. */
  2276. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2277. udelay(40);
  2278. current_link_up = 0;
  2279. mac_status = tr32(MAC_STATUS);
  2280. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2281. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2282. else
  2283. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2284. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  2285. tw32_f(MAC_MODE, tp->mac_mode);
  2286. udelay(40);
  2287. tp->hw_status->status =
  2288. (SD_STATUS_UPDATED |
  2289. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2290. for (i = 0; i < 100; i++) {
  2291. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2292. MAC_STATUS_CFG_CHANGED));
  2293. udelay(5);
  2294. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2295. MAC_STATUS_CFG_CHANGED |
  2296. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2297. break;
  2298. }
  2299. mac_status = tr32(MAC_STATUS);
  2300. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2301. current_link_up = 0;
  2302. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2303. tp->serdes_counter == 0) {
  2304. tw32_f(MAC_MODE, (tp->mac_mode |
  2305. MAC_MODE_SEND_CONFIGS));
  2306. udelay(1);
  2307. tw32_f(MAC_MODE, tp->mac_mode);
  2308. }
  2309. }
  2310. if (current_link_up == 1) {
  2311. tp->link_config.active_speed = SPEED_1000;
  2312. tp->link_config.active_duplex = DUPLEX_FULL;
  2313. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2314. LED_CTRL_LNKLED_OVERRIDE |
  2315. LED_CTRL_1000MBPS_ON));
  2316. } else {
  2317. tp->link_config.active_speed = SPEED_INVALID;
  2318. tp->link_config.active_duplex = DUPLEX_INVALID;
  2319. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2320. LED_CTRL_LNKLED_OVERRIDE |
  2321. LED_CTRL_TRAFFIC_OVERRIDE));
  2322. }
  2323. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2324. if (current_link_up)
  2325. netif_carrier_on(tp->dev);
  2326. else
  2327. netif_carrier_off(tp->dev);
  2328. tg3_link_report(tp);
  2329. } else {
  2330. u32 now_pause_cfg =
  2331. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2332. TG3_FLAG_TX_PAUSE);
  2333. if (orig_pause_cfg != now_pause_cfg ||
  2334. orig_active_speed != tp->link_config.active_speed ||
  2335. orig_active_duplex != tp->link_config.active_duplex)
  2336. tg3_link_report(tp);
  2337. }
  2338. return 0;
  2339. }
  2340. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2341. {
  2342. int current_link_up, err = 0;
  2343. u32 bmsr, bmcr;
  2344. u16 current_speed;
  2345. u8 current_duplex;
  2346. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2347. tw32_f(MAC_MODE, tp->mac_mode);
  2348. udelay(40);
  2349. tw32(MAC_EVENT, 0);
  2350. tw32_f(MAC_STATUS,
  2351. (MAC_STATUS_SYNC_CHANGED |
  2352. MAC_STATUS_CFG_CHANGED |
  2353. MAC_STATUS_MI_COMPLETION |
  2354. MAC_STATUS_LNKSTATE_CHANGED));
  2355. udelay(40);
  2356. if (force_reset)
  2357. tg3_phy_reset(tp);
  2358. current_link_up = 0;
  2359. current_speed = SPEED_INVALID;
  2360. current_duplex = DUPLEX_INVALID;
  2361. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2362. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2363. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2364. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2365. bmsr |= BMSR_LSTATUS;
  2366. else
  2367. bmsr &= ~BMSR_LSTATUS;
  2368. }
  2369. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2370. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2371. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2372. /* do nothing, just check for link up at the end */
  2373. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2374. u32 adv, new_adv;
  2375. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2376. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2377. ADVERTISE_1000XPAUSE |
  2378. ADVERTISE_1000XPSE_ASYM |
  2379. ADVERTISE_SLCT);
  2380. /* Always advertise symmetric PAUSE just like copper */
  2381. new_adv |= ADVERTISE_1000XPAUSE;
  2382. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2383. new_adv |= ADVERTISE_1000XHALF;
  2384. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2385. new_adv |= ADVERTISE_1000XFULL;
  2386. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2387. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2388. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2389. tg3_writephy(tp, MII_BMCR, bmcr);
  2390. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2391. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2392. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2393. return err;
  2394. }
  2395. } else {
  2396. u32 new_bmcr;
  2397. bmcr &= ~BMCR_SPEED1000;
  2398. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2399. if (tp->link_config.duplex == DUPLEX_FULL)
  2400. new_bmcr |= BMCR_FULLDPLX;
  2401. if (new_bmcr != bmcr) {
  2402. /* BMCR_SPEED1000 is a reserved bit that needs
  2403. * to be set on write.
  2404. */
  2405. new_bmcr |= BMCR_SPEED1000;
  2406. /* Force a linkdown */
  2407. if (netif_carrier_ok(tp->dev)) {
  2408. u32 adv;
  2409. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2410. adv &= ~(ADVERTISE_1000XFULL |
  2411. ADVERTISE_1000XHALF |
  2412. ADVERTISE_SLCT);
  2413. tg3_writephy(tp, MII_ADVERTISE, adv);
  2414. tg3_writephy(tp, MII_BMCR, bmcr |
  2415. BMCR_ANRESTART |
  2416. BMCR_ANENABLE);
  2417. udelay(10);
  2418. netif_carrier_off(tp->dev);
  2419. }
  2420. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2421. bmcr = new_bmcr;
  2422. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2423. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2424. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2425. ASIC_REV_5714) {
  2426. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2427. bmsr |= BMSR_LSTATUS;
  2428. else
  2429. bmsr &= ~BMSR_LSTATUS;
  2430. }
  2431. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2432. }
  2433. }
  2434. if (bmsr & BMSR_LSTATUS) {
  2435. current_speed = SPEED_1000;
  2436. current_link_up = 1;
  2437. if (bmcr & BMCR_FULLDPLX)
  2438. current_duplex = DUPLEX_FULL;
  2439. else
  2440. current_duplex = DUPLEX_HALF;
  2441. if (bmcr & BMCR_ANENABLE) {
  2442. u32 local_adv, remote_adv, common;
  2443. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2444. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2445. common = local_adv & remote_adv;
  2446. if (common & (ADVERTISE_1000XHALF |
  2447. ADVERTISE_1000XFULL)) {
  2448. if (common & ADVERTISE_1000XFULL)
  2449. current_duplex = DUPLEX_FULL;
  2450. else
  2451. current_duplex = DUPLEX_HALF;
  2452. tg3_setup_flow_control(tp, local_adv,
  2453. remote_adv);
  2454. }
  2455. else
  2456. current_link_up = 0;
  2457. }
  2458. }
  2459. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2460. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2461. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2462. tw32_f(MAC_MODE, tp->mac_mode);
  2463. udelay(40);
  2464. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2465. tp->link_config.active_speed = current_speed;
  2466. tp->link_config.active_duplex = current_duplex;
  2467. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2468. if (current_link_up)
  2469. netif_carrier_on(tp->dev);
  2470. else {
  2471. netif_carrier_off(tp->dev);
  2472. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2473. }
  2474. tg3_link_report(tp);
  2475. }
  2476. return err;
  2477. }
  2478. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2479. {
  2480. if (tp->serdes_counter) {
  2481. /* Give autoneg time to complete. */
  2482. tp->serdes_counter--;
  2483. return;
  2484. }
  2485. if (!netif_carrier_ok(tp->dev) &&
  2486. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2487. u32 bmcr;
  2488. tg3_readphy(tp, MII_BMCR, &bmcr);
  2489. if (bmcr & BMCR_ANENABLE) {
  2490. u32 phy1, phy2;
  2491. /* Select shadow register 0x1f */
  2492. tg3_writephy(tp, 0x1c, 0x7c00);
  2493. tg3_readphy(tp, 0x1c, &phy1);
  2494. /* Select expansion interrupt status register */
  2495. tg3_writephy(tp, 0x17, 0x0f01);
  2496. tg3_readphy(tp, 0x15, &phy2);
  2497. tg3_readphy(tp, 0x15, &phy2);
  2498. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2499. /* We have signal detect and not receiving
  2500. * config code words, link is up by parallel
  2501. * detection.
  2502. */
  2503. bmcr &= ~BMCR_ANENABLE;
  2504. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2505. tg3_writephy(tp, MII_BMCR, bmcr);
  2506. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2507. }
  2508. }
  2509. }
  2510. else if (netif_carrier_ok(tp->dev) &&
  2511. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2512. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2513. u32 phy2;
  2514. /* Select expansion interrupt status register */
  2515. tg3_writephy(tp, 0x17, 0x0f01);
  2516. tg3_readphy(tp, 0x15, &phy2);
  2517. if (phy2 & 0x20) {
  2518. u32 bmcr;
  2519. /* Config code words received, turn on autoneg. */
  2520. tg3_readphy(tp, MII_BMCR, &bmcr);
  2521. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2522. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2523. }
  2524. }
  2525. }
  2526. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2527. {
  2528. int err;
  2529. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2530. err = tg3_setup_fiber_phy(tp, force_reset);
  2531. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2532. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2533. } else {
  2534. err = tg3_setup_copper_phy(tp, force_reset);
  2535. }
  2536. if (tp->link_config.active_speed == SPEED_1000 &&
  2537. tp->link_config.active_duplex == DUPLEX_HALF)
  2538. tw32(MAC_TX_LENGTHS,
  2539. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2540. (6 << TX_LENGTHS_IPG_SHIFT) |
  2541. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2542. else
  2543. tw32(MAC_TX_LENGTHS,
  2544. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2545. (6 << TX_LENGTHS_IPG_SHIFT) |
  2546. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2547. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2548. if (netif_carrier_ok(tp->dev)) {
  2549. tw32(HOSTCC_STAT_COAL_TICKS,
  2550. tp->coal.stats_block_coalesce_usecs);
  2551. } else {
  2552. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2553. }
  2554. }
  2555. return err;
  2556. }
  2557. /* This is called whenever we suspect that the system chipset is re-
  2558. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2559. * is bogus tx completions. We try to recover by setting the
  2560. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2561. * in the workqueue.
  2562. */
  2563. static void tg3_tx_recover(struct tg3 *tp)
  2564. {
  2565. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2566. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2567. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2568. "mapped I/O cycles to the network device, attempting to "
  2569. "recover. Please report the problem to the driver maintainer "
  2570. "and include system chipset information.\n", tp->dev->name);
  2571. spin_lock(&tp->lock);
  2572. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2573. spin_unlock(&tp->lock);
  2574. }
  2575. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2576. {
  2577. smp_mb();
  2578. return (tp->tx_pending -
  2579. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2580. }
  2581. /* Tigon3 never reports partial packet sends. So we do not
  2582. * need special logic to handle SKBs that have not had all
  2583. * of their frags sent yet, like SunGEM does.
  2584. */
  2585. static void tg3_tx(struct tg3 *tp)
  2586. {
  2587. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2588. u32 sw_idx = tp->tx_cons;
  2589. while (sw_idx != hw_idx) {
  2590. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2591. struct sk_buff *skb = ri->skb;
  2592. int i, tx_bug = 0;
  2593. if (unlikely(skb == NULL)) {
  2594. tg3_tx_recover(tp);
  2595. return;
  2596. }
  2597. pci_unmap_single(tp->pdev,
  2598. pci_unmap_addr(ri, mapping),
  2599. skb_headlen(skb),
  2600. PCI_DMA_TODEVICE);
  2601. ri->skb = NULL;
  2602. sw_idx = NEXT_TX(sw_idx);
  2603. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2604. ri = &tp->tx_buffers[sw_idx];
  2605. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2606. tx_bug = 1;
  2607. pci_unmap_page(tp->pdev,
  2608. pci_unmap_addr(ri, mapping),
  2609. skb_shinfo(skb)->frags[i].size,
  2610. PCI_DMA_TODEVICE);
  2611. sw_idx = NEXT_TX(sw_idx);
  2612. }
  2613. dev_kfree_skb(skb);
  2614. if (unlikely(tx_bug)) {
  2615. tg3_tx_recover(tp);
  2616. return;
  2617. }
  2618. }
  2619. tp->tx_cons = sw_idx;
  2620. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2621. * before checking for netif_queue_stopped(). Without the
  2622. * memory barrier, there is a small possibility that tg3_start_xmit()
  2623. * will miss it and cause the queue to be stopped forever.
  2624. */
  2625. smp_mb();
  2626. if (unlikely(netif_queue_stopped(tp->dev) &&
  2627. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2628. netif_tx_lock(tp->dev);
  2629. if (netif_queue_stopped(tp->dev) &&
  2630. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2631. netif_wake_queue(tp->dev);
  2632. netif_tx_unlock(tp->dev);
  2633. }
  2634. }
  2635. /* Returns size of skb allocated or < 0 on error.
  2636. *
  2637. * We only need to fill in the address because the other members
  2638. * of the RX descriptor are invariant, see tg3_init_rings.
  2639. *
  2640. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2641. * posting buffers we only dirty the first cache line of the RX
  2642. * descriptor (containing the address). Whereas for the RX status
  2643. * buffers the cpu only reads the last cacheline of the RX descriptor
  2644. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2645. */
  2646. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2647. int src_idx, u32 dest_idx_unmasked)
  2648. {
  2649. struct tg3_rx_buffer_desc *desc;
  2650. struct ring_info *map, *src_map;
  2651. struct sk_buff *skb;
  2652. dma_addr_t mapping;
  2653. int skb_size, dest_idx;
  2654. src_map = NULL;
  2655. switch (opaque_key) {
  2656. case RXD_OPAQUE_RING_STD:
  2657. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2658. desc = &tp->rx_std[dest_idx];
  2659. map = &tp->rx_std_buffers[dest_idx];
  2660. if (src_idx >= 0)
  2661. src_map = &tp->rx_std_buffers[src_idx];
  2662. skb_size = tp->rx_pkt_buf_sz;
  2663. break;
  2664. case RXD_OPAQUE_RING_JUMBO:
  2665. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2666. desc = &tp->rx_jumbo[dest_idx];
  2667. map = &tp->rx_jumbo_buffers[dest_idx];
  2668. if (src_idx >= 0)
  2669. src_map = &tp->rx_jumbo_buffers[src_idx];
  2670. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2671. break;
  2672. default:
  2673. return -EINVAL;
  2674. };
  2675. /* Do not overwrite any of the map or rp information
  2676. * until we are sure we can commit to a new buffer.
  2677. *
  2678. * Callers depend upon this behavior and assume that
  2679. * we leave everything unchanged if we fail.
  2680. */
  2681. skb = netdev_alloc_skb(tp->dev, skb_size);
  2682. if (skb == NULL)
  2683. return -ENOMEM;
  2684. skb_reserve(skb, tp->rx_offset);
  2685. mapping = pci_map_single(tp->pdev, skb->data,
  2686. skb_size - tp->rx_offset,
  2687. PCI_DMA_FROMDEVICE);
  2688. map->skb = skb;
  2689. pci_unmap_addr_set(map, mapping, mapping);
  2690. if (src_map != NULL)
  2691. src_map->skb = NULL;
  2692. desc->addr_hi = ((u64)mapping >> 32);
  2693. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2694. return skb_size;
  2695. }
  2696. /* We only need to move over in the address because the other
  2697. * members of the RX descriptor are invariant. See notes above
  2698. * tg3_alloc_rx_skb for full details.
  2699. */
  2700. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2701. int src_idx, u32 dest_idx_unmasked)
  2702. {
  2703. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2704. struct ring_info *src_map, *dest_map;
  2705. int dest_idx;
  2706. switch (opaque_key) {
  2707. case RXD_OPAQUE_RING_STD:
  2708. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2709. dest_desc = &tp->rx_std[dest_idx];
  2710. dest_map = &tp->rx_std_buffers[dest_idx];
  2711. src_desc = &tp->rx_std[src_idx];
  2712. src_map = &tp->rx_std_buffers[src_idx];
  2713. break;
  2714. case RXD_OPAQUE_RING_JUMBO:
  2715. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2716. dest_desc = &tp->rx_jumbo[dest_idx];
  2717. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2718. src_desc = &tp->rx_jumbo[src_idx];
  2719. src_map = &tp->rx_jumbo_buffers[src_idx];
  2720. break;
  2721. default:
  2722. return;
  2723. };
  2724. dest_map->skb = src_map->skb;
  2725. pci_unmap_addr_set(dest_map, mapping,
  2726. pci_unmap_addr(src_map, mapping));
  2727. dest_desc->addr_hi = src_desc->addr_hi;
  2728. dest_desc->addr_lo = src_desc->addr_lo;
  2729. src_map->skb = NULL;
  2730. }
  2731. #if TG3_VLAN_TAG_USED
  2732. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2733. {
  2734. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2735. }
  2736. #endif
  2737. /* The RX ring scheme is composed of multiple rings which post fresh
  2738. * buffers to the chip, and one special ring the chip uses to report
  2739. * status back to the host.
  2740. *
  2741. * The special ring reports the status of received packets to the
  2742. * host. The chip does not write into the original descriptor the
  2743. * RX buffer was obtained from. The chip simply takes the original
  2744. * descriptor as provided by the host, updates the status and length
  2745. * field, then writes this into the next status ring entry.
  2746. *
  2747. * Each ring the host uses to post buffers to the chip is described
  2748. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2749. * it is first placed into the on-chip ram. When the packet's length
  2750. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2751. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2752. * which is within the range of the new packet's length is chosen.
  2753. *
  2754. * The "separate ring for rx status" scheme may sound queer, but it makes
  2755. * sense from a cache coherency perspective. If only the host writes
  2756. * to the buffer post rings, and only the chip writes to the rx status
  2757. * rings, then cache lines never move beyond shared-modified state.
  2758. * If both the host and chip were to write into the same ring, cache line
  2759. * eviction could occur since both entities want it in an exclusive state.
  2760. */
  2761. static int tg3_rx(struct tg3 *tp, int budget)
  2762. {
  2763. u32 work_mask, rx_std_posted = 0;
  2764. u32 sw_idx = tp->rx_rcb_ptr;
  2765. u16 hw_idx;
  2766. int received;
  2767. hw_idx = tp->hw_status->idx[0].rx_producer;
  2768. /*
  2769. * We need to order the read of hw_idx and the read of
  2770. * the opaque cookie.
  2771. */
  2772. rmb();
  2773. work_mask = 0;
  2774. received = 0;
  2775. while (sw_idx != hw_idx && budget > 0) {
  2776. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2777. unsigned int len;
  2778. struct sk_buff *skb;
  2779. dma_addr_t dma_addr;
  2780. u32 opaque_key, desc_idx, *post_ptr;
  2781. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2782. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2783. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2784. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2785. mapping);
  2786. skb = tp->rx_std_buffers[desc_idx].skb;
  2787. post_ptr = &tp->rx_std_ptr;
  2788. rx_std_posted++;
  2789. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2790. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2791. mapping);
  2792. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2793. post_ptr = &tp->rx_jumbo_ptr;
  2794. }
  2795. else {
  2796. goto next_pkt_nopost;
  2797. }
  2798. work_mask |= opaque_key;
  2799. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2800. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2801. drop_it:
  2802. tg3_recycle_rx(tp, opaque_key,
  2803. desc_idx, *post_ptr);
  2804. drop_it_no_recycle:
  2805. /* Other statistics kept track of by card. */
  2806. tp->net_stats.rx_dropped++;
  2807. goto next_pkt;
  2808. }
  2809. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2810. if (len > RX_COPY_THRESHOLD
  2811. && tp->rx_offset == 2
  2812. /* rx_offset != 2 iff this is a 5701 card running
  2813. * in PCI-X mode [see tg3_get_invariants()] */
  2814. ) {
  2815. int skb_size;
  2816. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2817. desc_idx, *post_ptr);
  2818. if (skb_size < 0)
  2819. goto drop_it;
  2820. pci_unmap_single(tp->pdev, dma_addr,
  2821. skb_size - tp->rx_offset,
  2822. PCI_DMA_FROMDEVICE);
  2823. skb_put(skb, len);
  2824. } else {
  2825. struct sk_buff *copy_skb;
  2826. tg3_recycle_rx(tp, opaque_key,
  2827. desc_idx, *post_ptr);
  2828. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  2829. if (copy_skb == NULL)
  2830. goto drop_it_no_recycle;
  2831. skb_reserve(copy_skb, 2);
  2832. skb_put(copy_skb, len);
  2833. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2834. skb_copy_from_linear_data(skb, copy_skb->data, len);
  2835. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2836. /* We'll reuse the original ring buffer. */
  2837. skb = copy_skb;
  2838. }
  2839. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2840. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2841. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2842. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2843. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2844. else
  2845. skb->ip_summed = CHECKSUM_NONE;
  2846. skb->protocol = eth_type_trans(skb, tp->dev);
  2847. #if TG3_VLAN_TAG_USED
  2848. if (tp->vlgrp != NULL &&
  2849. desc->type_flags & RXD_FLAG_VLAN) {
  2850. tg3_vlan_rx(tp, skb,
  2851. desc->err_vlan & RXD_VLAN_MASK);
  2852. } else
  2853. #endif
  2854. netif_receive_skb(skb);
  2855. tp->dev->last_rx = jiffies;
  2856. received++;
  2857. budget--;
  2858. next_pkt:
  2859. (*post_ptr)++;
  2860. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2861. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2862. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2863. TG3_64BIT_REG_LOW, idx);
  2864. work_mask &= ~RXD_OPAQUE_RING_STD;
  2865. rx_std_posted = 0;
  2866. }
  2867. next_pkt_nopost:
  2868. sw_idx++;
  2869. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  2870. /* Refresh hw_idx to see if there is new work */
  2871. if (sw_idx == hw_idx) {
  2872. hw_idx = tp->hw_status->idx[0].rx_producer;
  2873. rmb();
  2874. }
  2875. }
  2876. /* ACK the status ring. */
  2877. tp->rx_rcb_ptr = sw_idx;
  2878. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2879. /* Refill RX ring(s). */
  2880. if (work_mask & RXD_OPAQUE_RING_STD) {
  2881. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2882. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2883. sw_idx);
  2884. }
  2885. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2886. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2887. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2888. sw_idx);
  2889. }
  2890. mmiowb();
  2891. return received;
  2892. }
  2893. static int tg3_poll(struct net_device *netdev, int *budget)
  2894. {
  2895. struct tg3 *tp = netdev_priv(netdev);
  2896. struct tg3_hw_status *sblk = tp->hw_status;
  2897. int done;
  2898. /* handle link change and other phy events */
  2899. if (!(tp->tg3_flags &
  2900. (TG3_FLAG_USE_LINKCHG_REG |
  2901. TG3_FLAG_POLL_SERDES))) {
  2902. if (sblk->status & SD_STATUS_LINK_CHG) {
  2903. sblk->status = SD_STATUS_UPDATED |
  2904. (sblk->status & ~SD_STATUS_LINK_CHG);
  2905. spin_lock(&tp->lock);
  2906. tg3_setup_phy(tp, 0);
  2907. spin_unlock(&tp->lock);
  2908. }
  2909. }
  2910. /* run TX completion thread */
  2911. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2912. tg3_tx(tp);
  2913. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2914. netif_rx_complete(netdev);
  2915. schedule_work(&tp->reset_task);
  2916. return 0;
  2917. }
  2918. }
  2919. /* run RX thread, within the bounds set by NAPI.
  2920. * All RX "locking" is done by ensuring outside
  2921. * code synchronizes with dev->poll()
  2922. */
  2923. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2924. int orig_budget = *budget;
  2925. int work_done;
  2926. if (orig_budget > netdev->quota)
  2927. orig_budget = netdev->quota;
  2928. work_done = tg3_rx(tp, orig_budget);
  2929. *budget -= work_done;
  2930. netdev->quota -= work_done;
  2931. }
  2932. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2933. tp->last_tag = sblk->status_tag;
  2934. rmb();
  2935. } else
  2936. sblk->status &= ~SD_STATUS_UPDATED;
  2937. /* if no more work, tell net stack and NIC we're done */
  2938. done = !tg3_has_work(tp);
  2939. if (done) {
  2940. netif_rx_complete(netdev);
  2941. tg3_restart_ints(tp);
  2942. }
  2943. return (done ? 0 : 1);
  2944. }
  2945. static void tg3_irq_quiesce(struct tg3 *tp)
  2946. {
  2947. BUG_ON(tp->irq_sync);
  2948. tp->irq_sync = 1;
  2949. smp_mb();
  2950. synchronize_irq(tp->pdev->irq);
  2951. }
  2952. static inline int tg3_irq_sync(struct tg3 *tp)
  2953. {
  2954. return tp->irq_sync;
  2955. }
  2956. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  2957. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  2958. * with as well. Most of the time, this is not necessary except when
  2959. * shutting down the device.
  2960. */
  2961. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  2962. {
  2963. if (irq_sync)
  2964. tg3_irq_quiesce(tp);
  2965. spin_lock_bh(&tp->lock);
  2966. }
  2967. static inline void tg3_full_unlock(struct tg3 *tp)
  2968. {
  2969. spin_unlock_bh(&tp->lock);
  2970. }
  2971. /* One-shot MSI handler - Chip automatically disables interrupt
  2972. * after sending MSI so driver doesn't have to do it.
  2973. */
  2974. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  2975. {
  2976. struct net_device *dev = dev_id;
  2977. struct tg3 *tp = netdev_priv(dev);
  2978. prefetch(tp->hw_status);
  2979. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2980. if (likely(!tg3_irq_sync(tp)))
  2981. netif_rx_schedule(dev); /* schedule NAPI poll */
  2982. return IRQ_HANDLED;
  2983. }
  2984. /* MSI ISR - No need to check for interrupt sharing and no need to
  2985. * flush status block and interrupt mailbox. PCI ordering rules
  2986. * guarantee that MSI will arrive after the status block.
  2987. */
  2988. static irqreturn_t tg3_msi(int irq, void *dev_id)
  2989. {
  2990. struct net_device *dev = dev_id;
  2991. struct tg3 *tp = netdev_priv(dev);
  2992. prefetch(tp->hw_status);
  2993. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2994. /*
  2995. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2996. * chip-internal interrupt pending events.
  2997. * Writing non-zero to intr-mbox-0 additional tells the
  2998. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2999. * event coalescing.
  3000. */
  3001. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3002. if (likely(!tg3_irq_sync(tp)))
  3003. netif_rx_schedule(dev); /* schedule NAPI poll */
  3004. return IRQ_RETVAL(1);
  3005. }
  3006. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3007. {
  3008. struct net_device *dev = dev_id;
  3009. struct tg3 *tp = netdev_priv(dev);
  3010. struct tg3_hw_status *sblk = tp->hw_status;
  3011. unsigned int handled = 1;
  3012. /* In INTx mode, it is possible for the interrupt to arrive at
  3013. * the CPU before the status block posted prior to the interrupt.
  3014. * Reading the PCI State register will confirm whether the
  3015. * interrupt is ours and will flush the status block.
  3016. */
  3017. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3018. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3019. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3020. handled = 0;
  3021. goto out;
  3022. }
  3023. }
  3024. /*
  3025. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3026. * chip-internal interrupt pending events.
  3027. * Writing non-zero to intr-mbox-0 additional tells the
  3028. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3029. * event coalescing.
  3030. */
  3031. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3032. if (tg3_irq_sync(tp))
  3033. goto out;
  3034. sblk->status &= ~SD_STATUS_UPDATED;
  3035. if (likely(tg3_has_work(tp))) {
  3036. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3037. netif_rx_schedule(dev); /* schedule NAPI poll */
  3038. } else {
  3039. /* No work, shared interrupt perhaps? re-enable
  3040. * interrupts, and flush that PCI write
  3041. */
  3042. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3043. 0x00000000);
  3044. }
  3045. out:
  3046. return IRQ_RETVAL(handled);
  3047. }
  3048. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3049. {
  3050. struct net_device *dev = dev_id;
  3051. struct tg3 *tp = netdev_priv(dev);
  3052. struct tg3_hw_status *sblk = tp->hw_status;
  3053. unsigned int handled = 1;
  3054. /* In INTx mode, it is possible for the interrupt to arrive at
  3055. * the CPU before the status block posted prior to the interrupt.
  3056. * Reading the PCI State register will confirm whether the
  3057. * interrupt is ours and will flush the status block.
  3058. */
  3059. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3060. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3061. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3062. handled = 0;
  3063. goto out;
  3064. }
  3065. }
  3066. /*
  3067. * writing any value to intr-mbox-0 clears PCI INTA# and
  3068. * chip-internal interrupt pending events.
  3069. * writing non-zero to intr-mbox-0 additional tells the
  3070. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3071. * event coalescing.
  3072. */
  3073. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3074. if (tg3_irq_sync(tp))
  3075. goto out;
  3076. if (netif_rx_schedule_prep(dev)) {
  3077. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3078. /* Update last_tag to mark that this status has been
  3079. * seen. Because interrupt may be shared, we may be
  3080. * racing with tg3_poll(), so only update last_tag
  3081. * if tg3_poll() is not scheduled.
  3082. */
  3083. tp->last_tag = sblk->status_tag;
  3084. __netif_rx_schedule(dev);
  3085. }
  3086. out:
  3087. return IRQ_RETVAL(handled);
  3088. }
  3089. /* ISR for interrupt test */
  3090. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3091. {
  3092. struct net_device *dev = dev_id;
  3093. struct tg3 *tp = netdev_priv(dev);
  3094. struct tg3_hw_status *sblk = tp->hw_status;
  3095. if ((sblk->status & SD_STATUS_UPDATED) ||
  3096. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3097. tg3_disable_ints(tp);
  3098. return IRQ_RETVAL(1);
  3099. }
  3100. return IRQ_RETVAL(0);
  3101. }
  3102. static int tg3_init_hw(struct tg3 *, int);
  3103. static int tg3_halt(struct tg3 *, int, int);
  3104. /* Restart hardware after configuration changes, self-test, etc.
  3105. * Invoked with tp->lock held.
  3106. */
  3107. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3108. {
  3109. int err;
  3110. err = tg3_init_hw(tp, reset_phy);
  3111. if (err) {
  3112. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3113. "aborting.\n", tp->dev->name);
  3114. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3115. tg3_full_unlock(tp);
  3116. del_timer_sync(&tp->timer);
  3117. tp->irq_sync = 0;
  3118. netif_poll_enable(tp->dev);
  3119. dev_close(tp->dev);
  3120. tg3_full_lock(tp, 0);
  3121. }
  3122. return err;
  3123. }
  3124. #ifdef CONFIG_NET_POLL_CONTROLLER
  3125. static void tg3_poll_controller(struct net_device *dev)
  3126. {
  3127. struct tg3 *tp = netdev_priv(dev);
  3128. tg3_interrupt(tp->pdev->irq, dev);
  3129. }
  3130. #endif
  3131. static void tg3_reset_task(struct work_struct *work)
  3132. {
  3133. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3134. unsigned int restart_timer;
  3135. tg3_full_lock(tp, 0);
  3136. tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
  3137. if (!netif_running(tp->dev)) {
  3138. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3139. tg3_full_unlock(tp);
  3140. return;
  3141. }
  3142. tg3_full_unlock(tp);
  3143. tg3_netif_stop(tp);
  3144. tg3_full_lock(tp, 1);
  3145. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3146. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3147. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3148. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3149. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3150. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3151. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3152. }
  3153. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3154. if (tg3_init_hw(tp, 1))
  3155. goto out;
  3156. tg3_netif_start(tp);
  3157. if (restart_timer)
  3158. mod_timer(&tp->timer, jiffies + 1);
  3159. out:
  3160. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3161. tg3_full_unlock(tp);
  3162. }
  3163. static void tg3_dump_short_state(struct tg3 *tp)
  3164. {
  3165. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3166. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3167. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3168. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3169. }
  3170. static void tg3_tx_timeout(struct net_device *dev)
  3171. {
  3172. struct tg3 *tp = netdev_priv(dev);
  3173. if (netif_msg_tx_err(tp)) {
  3174. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3175. dev->name);
  3176. tg3_dump_short_state(tp);
  3177. }
  3178. schedule_work(&tp->reset_task);
  3179. }
  3180. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3181. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3182. {
  3183. u32 base = (u32) mapping & 0xffffffff;
  3184. return ((base > 0xffffdcc0) &&
  3185. (base + len + 8 < base));
  3186. }
  3187. /* Test for DMA addresses > 40-bit */
  3188. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3189. int len)
  3190. {
  3191. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3192. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3193. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3194. return 0;
  3195. #else
  3196. return 0;
  3197. #endif
  3198. }
  3199. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3200. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3201. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3202. u32 last_plus_one, u32 *start,
  3203. u32 base_flags, u32 mss)
  3204. {
  3205. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3206. dma_addr_t new_addr = 0;
  3207. u32 entry = *start;
  3208. int i, ret = 0;
  3209. if (!new_skb) {
  3210. ret = -1;
  3211. } else {
  3212. /* New SKB is guaranteed to be linear. */
  3213. entry = *start;
  3214. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3215. PCI_DMA_TODEVICE);
  3216. /* Make sure new skb does not cross any 4G boundaries.
  3217. * Drop the packet if it does.
  3218. */
  3219. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3220. ret = -1;
  3221. dev_kfree_skb(new_skb);
  3222. new_skb = NULL;
  3223. } else {
  3224. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3225. base_flags, 1 | (mss << 1));
  3226. *start = NEXT_TX(entry);
  3227. }
  3228. }
  3229. /* Now clean up the sw ring entries. */
  3230. i = 0;
  3231. while (entry != last_plus_one) {
  3232. int len;
  3233. if (i == 0)
  3234. len = skb_headlen(skb);
  3235. else
  3236. len = skb_shinfo(skb)->frags[i-1].size;
  3237. pci_unmap_single(tp->pdev,
  3238. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3239. len, PCI_DMA_TODEVICE);
  3240. if (i == 0) {
  3241. tp->tx_buffers[entry].skb = new_skb;
  3242. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3243. } else {
  3244. tp->tx_buffers[entry].skb = NULL;
  3245. }
  3246. entry = NEXT_TX(entry);
  3247. i++;
  3248. }
  3249. dev_kfree_skb(skb);
  3250. return ret;
  3251. }
  3252. static void tg3_set_txd(struct tg3 *tp, int entry,
  3253. dma_addr_t mapping, int len, u32 flags,
  3254. u32 mss_and_is_end)
  3255. {
  3256. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3257. int is_end = (mss_and_is_end & 0x1);
  3258. u32 mss = (mss_and_is_end >> 1);
  3259. u32 vlan_tag = 0;
  3260. if (is_end)
  3261. flags |= TXD_FLAG_END;
  3262. if (flags & TXD_FLAG_VLAN) {
  3263. vlan_tag = flags >> 16;
  3264. flags &= 0xffff;
  3265. }
  3266. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3267. txd->addr_hi = ((u64) mapping >> 32);
  3268. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3269. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3270. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3271. }
  3272. /* hard_start_xmit for devices that don't have any bugs and
  3273. * support TG3_FLG2_HW_TSO_2 only.
  3274. */
  3275. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3276. {
  3277. struct tg3 *tp = netdev_priv(dev);
  3278. dma_addr_t mapping;
  3279. u32 len, entry, base_flags, mss;
  3280. len = skb_headlen(skb);
  3281. /* We are running in BH disabled context with netif_tx_lock
  3282. * and TX reclaim runs via tp->poll inside of a software
  3283. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3284. * no IRQ context deadlocks to worry about either. Rejoice!
  3285. */
  3286. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3287. if (!netif_queue_stopped(dev)) {
  3288. netif_stop_queue(dev);
  3289. /* This is a hard error, log it. */
  3290. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3291. "queue awake!\n", dev->name);
  3292. }
  3293. return NETDEV_TX_BUSY;
  3294. }
  3295. entry = tp->tx_prod;
  3296. base_flags = 0;
  3297. mss = 0;
  3298. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3299. int tcp_opt_len, ip_tcp_len;
  3300. if (skb_header_cloned(skb) &&
  3301. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3302. dev_kfree_skb(skb);
  3303. goto out_unlock;
  3304. }
  3305. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3306. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3307. else {
  3308. struct iphdr *iph = ip_hdr(skb);
  3309. tcp_opt_len = tcp_optlen(skb);
  3310. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3311. iph->check = 0;
  3312. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3313. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3314. }
  3315. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3316. TXD_FLAG_CPU_POST_DMA);
  3317. tcp_hdr(skb)->check = 0;
  3318. }
  3319. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3320. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3321. #if TG3_VLAN_TAG_USED
  3322. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3323. base_flags |= (TXD_FLAG_VLAN |
  3324. (vlan_tx_tag_get(skb) << 16));
  3325. #endif
  3326. /* Queue skb data, a.k.a. the main skb fragment. */
  3327. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3328. tp->tx_buffers[entry].skb = skb;
  3329. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3330. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3331. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3332. entry = NEXT_TX(entry);
  3333. /* Now loop through additional data fragments, and queue them. */
  3334. if (skb_shinfo(skb)->nr_frags > 0) {
  3335. unsigned int i, last;
  3336. last = skb_shinfo(skb)->nr_frags - 1;
  3337. for (i = 0; i <= last; i++) {
  3338. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3339. len = frag->size;
  3340. mapping = pci_map_page(tp->pdev,
  3341. frag->page,
  3342. frag->page_offset,
  3343. len, PCI_DMA_TODEVICE);
  3344. tp->tx_buffers[entry].skb = NULL;
  3345. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3346. tg3_set_txd(tp, entry, mapping, len,
  3347. base_flags, (i == last) | (mss << 1));
  3348. entry = NEXT_TX(entry);
  3349. }
  3350. }
  3351. /* Packets are ready, update Tx producer idx local and on card. */
  3352. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3353. tp->tx_prod = entry;
  3354. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3355. netif_stop_queue(dev);
  3356. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3357. netif_wake_queue(tp->dev);
  3358. }
  3359. out_unlock:
  3360. mmiowb();
  3361. dev->trans_start = jiffies;
  3362. return NETDEV_TX_OK;
  3363. }
  3364. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3365. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3366. * TSO header is greater than 80 bytes.
  3367. */
  3368. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3369. {
  3370. struct sk_buff *segs, *nskb;
  3371. /* Estimate the number of fragments in the worst case */
  3372. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3373. netif_stop_queue(tp->dev);
  3374. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3375. return NETDEV_TX_BUSY;
  3376. netif_wake_queue(tp->dev);
  3377. }
  3378. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3379. if (unlikely(IS_ERR(segs)))
  3380. goto tg3_tso_bug_end;
  3381. do {
  3382. nskb = segs;
  3383. segs = segs->next;
  3384. nskb->next = NULL;
  3385. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3386. } while (segs);
  3387. tg3_tso_bug_end:
  3388. dev_kfree_skb(skb);
  3389. return NETDEV_TX_OK;
  3390. }
  3391. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3392. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3393. */
  3394. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3395. {
  3396. struct tg3 *tp = netdev_priv(dev);
  3397. dma_addr_t mapping;
  3398. u32 len, entry, base_flags, mss;
  3399. int would_hit_hwbug;
  3400. len = skb_headlen(skb);
  3401. /* We are running in BH disabled context with netif_tx_lock
  3402. * and TX reclaim runs via tp->poll inside of a software
  3403. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3404. * no IRQ context deadlocks to worry about either. Rejoice!
  3405. */
  3406. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3407. if (!netif_queue_stopped(dev)) {
  3408. netif_stop_queue(dev);
  3409. /* This is a hard error, log it. */
  3410. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3411. "queue awake!\n", dev->name);
  3412. }
  3413. return NETDEV_TX_BUSY;
  3414. }
  3415. entry = tp->tx_prod;
  3416. base_flags = 0;
  3417. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3418. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3419. mss = 0;
  3420. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3421. struct iphdr *iph;
  3422. int tcp_opt_len, ip_tcp_len, hdr_len;
  3423. if (skb_header_cloned(skb) &&
  3424. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3425. dev_kfree_skb(skb);
  3426. goto out_unlock;
  3427. }
  3428. tcp_opt_len = tcp_optlen(skb);
  3429. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3430. hdr_len = ip_tcp_len + tcp_opt_len;
  3431. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3432. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3433. return (tg3_tso_bug(tp, skb));
  3434. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3435. TXD_FLAG_CPU_POST_DMA);
  3436. iph = ip_hdr(skb);
  3437. iph->check = 0;
  3438. iph->tot_len = htons(mss + hdr_len);
  3439. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3440. tcp_hdr(skb)->check = 0;
  3441. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3442. } else
  3443. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3444. iph->daddr, 0,
  3445. IPPROTO_TCP,
  3446. 0);
  3447. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3448. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3449. if (tcp_opt_len || iph->ihl > 5) {
  3450. int tsflags;
  3451. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3452. mss |= (tsflags << 11);
  3453. }
  3454. } else {
  3455. if (tcp_opt_len || iph->ihl > 5) {
  3456. int tsflags;
  3457. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3458. base_flags |= tsflags << 12;
  3459. }
  3460. }
  3461. }
  3462. #if TG3_VLAN_TAG_USED
  3463. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3464. base_flags |= (TXD_FLAG_VLAN |
  3465. (vlan_tx_tag_get(skb) << 16));
  3466. #endif
  3467. /* Queue skb data, a.k.a. the main skb fragment. */
  3468. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3469. tp->tx_buffers[entry].skb = skb;
  3470. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3471. would_hit_hwbug = 0;
  3472. if (tg3_4g_overflow_test(mapping, len))
  3473. would_hit_hwbug = 1;
  3474. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3475. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3476. entry = NEXT_TX(entry);
  3477. /* Now loop through additional data fragments, and queue them. */
  3478. if (skb_shinfo(skb)->nr_frags > 0) {
  3479. unsigned int i, last;
  3480. last = skb_shinfo(skb)->nr_frags - 1;
  3481. for (i = 0; i <= last; i++) {
  3482. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3483. len = frag->size;
  3484. mapping = pci_map_page(tp->pdev,
  3485. frag->page,
  3486. frag->page_offset,
  3487. len, PCI_DMA_TODEVICE);
  3488. tp->tx_buffers[entry].skb = NULL;
  3489. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3490. if (tg3_4g_overflow_test(mapping, len))
  3491. would_hit_hwbug = 1;
  3492. if (tg3_40bit_overflow_test(tp, mapping, len))
  3493. would_hit_hwbug = 1;
  3494. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3495. tg3_set_txd(tp, entry, mapping, len,
  3496. base_flags, (i == last)|(mss << 1));
  3497. else
  3498. tg3_set_txd(tp, entry, mapping, len,
  3499. base_flags, (i == last));
  3500. entry = NEXT_TX(entry);
  3501. }
  3502. }
  3503. if (would_hit_hwbug) {
  3504. u32 last_plus_one = entry;
  3505. u32 start;
  3506. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3507. start &= (TG3_TX_RING_SIZE - 1);
  3508. /* If the workaround fails due to memory/mapping
  3509. * failure, silently drop this packet.
  3510. */
  3511. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3512. &start, base_flags, mss))
  3513. goto out_unlock;
  3514. entry = start;
  3515. }
  3516. /* Packets are ready, update Tx producer idx local and on card. */
  3517. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3518. tp->tx_prod = entry;
  3519. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3520. netif_stop_queue(dev);
  3521. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3522. netif_wake_queue(tp->dev);
  3523. }
  3524. out_unlock:
  3525. mmiowb();
  3526. dev->trans_start = jiffies;
  3527. return NETDEV_TX_OK;
  3528. }
  3529. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3530. int new_mtu)
  3531. {
  3532. dev->mtu = new_mtu;
  3533. if (new_mtu > ETH_DATA_LEN) {
  3534. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3535. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3536. ethtool_op_set_tso(dev, 0);
  3537. }
  3538. else
  3539. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3540. } else {
  3541. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3542. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3543. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3544. }
  3545. }
  3546. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3547. {
  3548. struct tg3 *tp = netdev_priv(dev);
  3549. int err;
  3550. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3551. return -EINVAL;
  3552. if (!netif_running(dev)) {
  3553. /* We'll just catch it later when the
  3554. * device is up'd.
  3555. */
  3556. tg3_set_mtu(dev, tp, new_mtu);
  3557. return 0;
  3558. }
  3559. tg3_netif_stop(tp);
  3560. tg3_full_lock(tp, 1);
  3561. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3562. tg3_set_mtu(dev, tp, new_mtu);
  3563. err = tg3_restart_hw(tp, 0);
  3564. if (!err)
  3565. tg3_netif_start(tp);
  3566. tg3_full_unlock(tp);
  3567. return err;
  3568. }
  3569. /* Free up pending packets in all rx/tx rings.
  3570. *
  3571. * The chip has been shut down and the driver detached from
  3572. * the networking, so no interrupts or new tx packets will
  3573. * end up in the driver. tp->{tx,}lock is not held and we are not
  3574. * in an interrupt context and thus may sleep.
  3575. */
  3576. static void tg3_free_rings(struct tg3 *tp)
  3577. {
  3578. struct ring_info *rxp;
  3579. int i;
  3580. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3581. rxp = &tp->rx_std_buffers[i];
  3582. if (rxp->skb == NULL)
  3583. continue;
  3584. pci_unmap_single(tp->pdev,
  3585. pci_unmap_addr(rxp, mapping),
  3586. tp->rx_pkt_buf_sz - tp->rx_offset,
  3587. PCI_DMA_FROMDEVICE);
  3588. dev_kfree_skb_any(rxp->skb);
  3589. rxp->skb = NULL;
  3590. }
  3591. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3592. rxp = &tp->rx_jumbo_buffers[i];
  3593. if (rxp->skb == NULL)
  3594. continue;
  3595. pci_unmap_single(tp->pdev,
  3596. pci_unmap_addr(rxp, mapping),
  3597. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3598. PCI_DMA_FROMDEVICE);
  3599. dev_kfree_skb_any(rxp->skb);
  3600. rxp->skb = NULL;
  3601. }
  3602. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3603. struct tx_ring_info *txp;
  3604. struct sk_buff *skb;
  3605. int j;
  3606. txp = &tp->tx_buffers[i];
  3607. skb = txp->skb;
  3608. if (skb == NULL) {
  3609. i++;
  3610. continue;
  3611. }
  3612. pci_unmap_single(tp->pdev,
  3613. pci_unmap_addr(txp, mapping),
  3614. skb_headlen(skb),
  3615. PCI_DMA_TODEVICE);
  3616. txp->skb = NULL;
  3617. i++;
  3618. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3619. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3620. pci_unmap_page(tp->pdev,
  3621. pci_unmap_addr(txp, mapping),
  3622. skb_shinfo(skb)->frags[j].size,
  3623. PCI_DMA_TODEVICE);
  3624. i++;
  3625. }
  3626. dev_kfree_skb_any(skb);
  3627. }
  3628. }
  3629. /* Initialize tx/rx rings for packet processing.
  3630. *
  3631. * The chip has been shut down and the driver detached from
  3632. * the networking, so no interrupts or new tx packets will
  3633. * end up in the driver. tp->{tx,}lock are held and thus
  3634. * we may not sleep.
  3635. */
  3636. static int tg3_init_rings(struct tg3 *tp)
  3637. {
  3638. u32 i;
  3639. /* Free up all the SKBs. */
  3640. tg3_free_rings(tp);
  3641. /* Zero out all descriptors. */
  3642. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3643. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3644. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3645. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3646. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3647. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3648. (tp->dev->mtu > ETH_DATA_LEN))
  3649. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3650. /* Initialize invariants of the rings, we only set this
  3651. * stuff once. This works because the card does not
  3652. * write into the rx buffer posting rings.
  3653. */
  3654. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3655. struct tg3_rx_buffer_desc *rxd;
  3656. rxd = &tp->rx_std[i];
  3657. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3658. << RXD_LEN_SHIFT;
  3659. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3660. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3661. (i << RXD_OPAQUE_INDEX_SHIFT));
  3662. }
  3663. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3664. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3665. struct tg3_rx_buffer_desc *rxd;
  3666. rxd = &tp->rx_jumbo[i];
  3667. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3668. << RXD_LEN_SHIFT;
  3669. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3670. RXD_FLAG_JUMBO;
  3671. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3672. (i << RXD_OPAQUE_INDEX_SHIFT));
  3673. }
  3674. }
  3675. /* Now allocate fresh SKBs for each rx ring. */
  3676. for (i = 0; i < tp->rx_pending; i++) {
  3677. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3678. printk(KERN_WARNING PFX
  3679. "%s: Using a smaller RX standard ring, "
  3680. "only %d out of %d buffers were allocated "
  3681. "successfully.\n",
  3682. tp->dev->name, i, tp->rx_pending);
  3683. if (i == 0)
  3684. return -ENOMEM;
  3685. tp->rx_pending = i;
  3686. break;
  3687. }
  3688. }
  3689. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3690. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3691. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3692. -1, i) < 0) {
  3693. printk(KERN_WARNING PFX
  3694. "%s: Using a smaller RX jumbo ring, "
  3695. "only %d out of %d buffers were "
  3696. "allocated successfully.\n",
  3697. tp->dev->name, i, tp->rx_jumbo_pending);
  3698. if (i == 0) {
  3699. tg3_free_rings(tp);
  3700. return -ENOMEM;
  3701. }
  3702. tp->rx_jumbo_pending = i;
  3703. break;
  3704. }
  3705. }
  3706. }
  3707. return 0;
  3708. }
  3709. /*
  3710. * Must not be invoked with interrupt sources disabled and
  3711. * the hardware shutdown down.
  3712. */
  3713. static void tg3_free_consistent(struct tg3 *tp)
  3714. {
  3715. kfree(tp->rx_std_buffers);
  3716. tp->rx_std_buffers = NULL;
  3717. if (tp->rx_std) {
  3718. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3719. tp->rx_std, tp->rx_std_mapping);
  3720. tp->rx_std = NULL;
  3721. }
  3722. if (tp->rx_jumbo) {
  3723. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3724. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3725. tp->rx_jumbo = NULL;
  3726. }
  3727. if (tp->rx_rcb) {
  3728. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3729. tp->rx_rcb, tp->rx_rcb_mapping);
  3730. tp->rx_rcb = NULL;
  3731. }
  3732. if (tp->tx_ring) {
  3733. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3734. tp->tx_ring, tp->tx_desc_mapping);
  3735. tp->tx_ring = NULL;
  3736. }
  3737. if (tp->hw_status) {
  3738. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3739. tp->hw_status, tp->status_mapping);
  3740. tp->hw_status = NULL;
  3741. }
  3742. if (tp->hw_stats) {
  3743. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3744. tp->hw_stats, tp->stats_mapping);
  3745. tp->hw_stats = NULL;
  3746. }
  3747. }
  3748. /*
  3749. * Must not be invoked with interrupt sources disabled and
  3750. * the hardware shutdown down. Can sleep.
  3751. */
  3752. static int tg3_alloc_consistent(struct tg3 *tp)
  3753. {
  3754. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  3755. (TG3_RX_RING_SIZE +
  3756. TG3_RX_JUMBO_RING_SIZE)) +
  3757. (sizeof(struct tx_ring_info) *
  3758. TG3_TX_RING_SIZE),
  3759. GFP_KERNEL);
  3760. if (!tp->rx_std_buffers)
  3761. return -ENOMEM;
  3762. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3763. tp->tx_buffers = (struct tx_ring_info *)
  3764. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3765. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3766. &tp->rx_std_mapping);
  3767. if (!tp->rx_std)
  3768. goto err_out;
  3769. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3770. &tp->rx_jumbo_mapping);
  3771. if (!tp->rx_jumbo)
  3772. goto err_out;
  3773. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3774. &tp->rx_rcb_mapping);
  3775. if (!tp->rx_rcb)
  3776. goto err_out;
  3777. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3778. &tp->tx_desc_mapping);
  3779. if (!tp->tx_ring)
  3780. goto err_out;
  3781. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3782. TG3_HW_STATUS_SIZE,
  3783. &tp->status_mapping);
  3784. if (!tp->hw_status)
  3785. goto err_out;
  3786. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3787. sizeof(struct tg3_hw_stats),
  3788. &tp->stats_mapping);
  3789. if (!tp->hw_stats)
  3790. goto err_out;
  3791. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3792. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3793. return 0;
  3794. err_out:
  3795. tg3_free_consistent(tp);
  3796. return -ENOMEM;
  3797. }
  3798. #define MAX_WAIT_CNT 1000
  3799. /* To stop a block, clear the enable bit and poll till it
  3800. * clears. tp->lock is held.
  3801. */
  3802. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3803. {
  3804. unsigned int i;
  3805. u32 val;
  3806. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3807. switch (ofs) {
  3808. case RCVLSC_MODE:
  3809. case DMAC_MODE:
  3810. case MBFREE_MODE:
  3811. case BUFMGR_MODE:
  3812. case MEMARB_MODE:
  3813. /* We can't enable/disable these bits of the
  3814. * 5705/5750, just say success.
  3815. */
  3816. return 0;
  3817. default:
  3818. break;
  3819. };
  3820. }
  3821. val = tr32(ofs);
  3822. val &= ~enable_bit;
  3823. tw32_f(ofs, val);
  3824. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3825. udelay(100);
  3826. val = tr32(ofs);
  3827. if ((val & enable_bit) == 0)
  3828. break;
  3829. }
  3830. if (i == MAX_WAIT_CNT && !silent) {
  3831. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3832. "ofs=%lx enable_bit=%x\n",
  3833. ofs, enable_bit);
  3834. return -ENODEV;
  3835. }
  3836. return 0;
  3837. }
  3838. /* tp->lock is held. */
  3839. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3840. {
  3841. int i, err;
  3842. tg3_disable_ints(tp);
  3843. tp->rx_mode &= ~RX_MODE_ENABLE;
  3844. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3845. udelay(10);
  3846. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3847. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3848. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3849. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3850. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3851. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3852. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3853. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3854. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3855. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3856. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3857. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3858. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3859. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3860. tw32_f(MAC_MODE, tp->mac_mode);
  3861. udelay(40);
  3862. tp->tx_mode &= ~TX_MODE_ENABLE;
  3863. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3864. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3865. udelay(100);
  3866. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3867. break;
  3868. }
  3869. if (i >= MAX_WAIT_CNT) {
  3870. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3871. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3872. tp->dev->name, tr32(MAC_TX_MODE));
  3873. err |= -ENODEV;
  3874. }
  3875. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3876. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3877. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3878. tw32(FTQ_RESET, 0xffffffff);
  3879. tw32(FTQ_RESET, 0x00000000);
  3880. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3881. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3882. if (tp->hw_status)
  3883. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3884. if (tp->hw_stats)
  3885. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3886. return err;
  3887. }
  3888. /* tp->lock is held. */
  3889. static int tg3_nvram_lock(struct tg3 *tp)
  3890. {
  3891. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3892. int i;
  3893. if (tp->nvram_lock_cnt == 0) {
  3894. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3895. for (i = 0; i < 8000; i++) {
  3896. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3897. break;
  3898. udelay(20);
  3899. }
  3900. if (i == 8000) {
  3901. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3902. return -ENODEV;
  3903. }
  3904. }
  3905. tp->nvram_lock_cnt++;
  3906. }
  3907. return 0;
  3908. }
  3909. /* tp->lock is held. */
  3910. static void tg3_nvram_unlock(struct tg3 *tp)
  3911. {
  3912. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3913. if (tp->nvram_lock_cnt > 0)
  3914. tp->nvram_lock_cnt--;
  3915. if (tp->nvram_lock_cnt == 0)
  3916. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3917. }
  3918. }
  3919. /* tp->lock is held. */
  3920. static void tg3_enable_nvram_access(struct tg3 *tp)
  3921. {
  3922. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3923. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3924. u32 nvaccess = tr32(NVRAM_ACCESS);
  3925. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3926. }
  3927. }
  3928. /* tp->lock is held. */
  3929. static void tg3_disable_nvram_access(struct tg3 *tp)
  3930. {
  3931. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3932. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3933. u32 nvaccess = tr32(NVRAM_ACCESS);
  3934. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3935. }
  3936. }
  3937. /* tp->lock is held. */
  3938. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3939. {
  3940. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3941. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3942. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3943. switch (kind) {
  3944. case RESET_KIND_INIT:
  3945. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3946. DRV_STATE_START);
  3947. break;
  3948. case RESET_KIND_SHUTDOWN:
  3949. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3950. DRV_STATE_UNLOAD);
  3951. break;
  3952. case RESET_KIND_SUSPEND:
  3953. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3954. DRV_STATE_SUSPEND);
  3955. break;
  3956. default:
  3957. break;
  3958. };
  3959. }
  3960. }
  3961. /* tp->lock is held. */
  3962. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  3963. {
  3964. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3965. switch (kind) {
  3966. case RESET_KIND_INIT:
  3967. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3968. DRV_STATE_START_DONE);
  3969. break;
  3970. case RESET_KIND_SHUTDOWN:
  3971. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3972. DRV_STATE_UNLOAD_DONE);
  3973. break;
  3974. default:
  3975. break;
  3976. };
  3977. }
  3978. }
  3979. /* tp->lock is held. */
  3980. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  3981. {
  3982. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  3983. switch (kind) {
  3984. case RESET_KIND_INIT:
  3985. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3986. DRV_STATE_START);
  3987. break;
  3988. case RESET_KIND_SHUTDOWN:
  3989. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3990. DRV_STATE_UNLOAD);
  3991. break;
  3992. case RESET_KIND_SUSPEND:
  3993. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3994. DRV_STATE_SUSPEND);
  3995. break;
  3996. default:
  3997. break;
  3998. };
  3999. }
  4000. }
  4001. static int tg3_poll_fw(struct tg3 *tp)
  4002. {
  4003. int i;
  4004. u32 val;
  4005. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4006. /* Wait up to 20ms for init done. */
  4007. for (i = 0; i < 200; i++) {
  4008. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4009. return 0;
  4010. udelay(100);
  4011. }
  4012. return -ENODEV;
  4013. }
  4014. /* Wait for firmware initialization to complete. */
  4015. for (i = 0; i < 100000; i++) {
  4016. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4017. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4018. break;
  4019. udelay(10);
  4020. }
  4021. /* Chip might not be fitted with firmware. Some Sun onboard
  4022. * parts are configured like that. So don't signal the timeout
  4023. * of the above loop as an error, but do report the lack of
  4024. * running firmware once.
  4025. */
  4026. if (i >= 100000 &&
  4027. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4028. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4029. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4030. tp->dev->name);
  4031. }
  4032. return 0;
  4033. }
  4034. static void tg3_stop_fw(struct tg3 *);
  4035. /* tp->lock is held. */
  4036. static int tg3_chip_reset(struct tg3 *tp)
  4037. {
  4038. u32 val;
  4039. void (*write_op)(struct tg3 *, u32, u32);
  4040. int err;
  4041. tg3_nvram_lock(tp);
  4042. /* No matching tg3_nvram_unlock() after this because
  4043. * chip reset below will undo the nvram lock.
  4044. */
  4045. tp->nvram_lock_cnt = 0;
  4046. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4047. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4048. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  4049. tw32(GRC_FASTBOOT_PC, 0);
  4050. /*
  4051. * We must avoid the readl() that normally takes place.
  4052. * It locks machines, causes machine checks, and other
  4053. * fun things. So, temporarily disable the 5701
  4054. * hardware workaround, while we do the reset.
  4055. */
  4056. write_op = tp->write32;
  4057. if (write_op == tg3_write_flush_reg32)
  4058. tp->write32 = tg3_write32;
  4059. /* Prevent the irq handler from reading or writing PCI registers
  4060. * during chip reset when the memory enable bit in the PCI command
  4061. * register may be cleared. The chip does not generate interrupt
  4062. * at this time, but the irq handler may still be called due to irq
  4063. * sharing or irqpoll.
  4064. */
  4065. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4066. if (tp->hw_status) {
  4067. tp->hw_status->status = 0;
  4068. tp->hw_status->status_tag = 0;
  4069. }
  4070. tp->last_tag = 0;
  4071. smp_mb();
  4072. synchronize_irq(tp->pdev->irq);
  4073. /* do the reset */
  4074. val = GRC_MISC_CFG_CORECLK_RESET;
  4075. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4076. if (tr32(0x7e2c) == 0x60) {
  4077. tw32(0x7e2c, 0x20);
  4078. }
  4079. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4080. tw32(GRC_MISC_CFG, (1 << 29));
  4081. val |= (1 << 29);
  4082. }
  4083. }
  4084. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4085. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4086. tw32(GRC_VCPU_EXT_CTRL,
  4087. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4088. }
  4089. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4090. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4091. tw32(GRC_MISC_CFG, val);
  4092. /* restore 5701 hardware bug workaround write method */
  4093. tp->write32 = write_op;
  4094. /* Unfortunately, we have to delay before the PCI read back.
  4095. * Some 575X chips even will not respond to a PCI cfg access
  4096. * when the reset command is given to the chip.
  4097. *
  4098. * How do these hardware designers expect things to work
  4099. * properly if the PCI write is posted for a long period
  4100. * of time? It is always necessary to have some method by
  4101. * which a register read back can occur to push the write
  4102. * out which does the reset.
  4103. *
  4104. * For most tg3 variants the trick below was working.
  4105. * Ho hum...
  4106. */
  4107. udelay(120);
  4108. /* Flush PCI posted writes. The normal MMIO registers
  4109. * are inaccessible at this time so this is the only
  4110. * way to make this reliably (actually, this is no longer
  4111. * the case, see above). I tried to use indirect
  4112. * register read/write but this upset some 5701 variants.
  4113. */
  4114. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4115. udelay(120);
  4116. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4117. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4118. int i;
  4119. u32 cfg_val;
  4120. /* Wait for link training to complete. */
  4121. for (i = 0; i < 5000; i++)
  4122. udelay(100);
  4123. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4124. pci_write_config_dword(tp->pdev, 0xc4,
  4125. cfg_val | (1 << 15));
  4126. }
  4127. /* Set PCIE max payload size and clear error status. */
  4128. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4129. }
  4130. /* Re-enable indirect register accesses. */
  4131. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4132. tp->misc_host_ctrl);
  4133. /* Set MAX PCI retry to zero. */
  4134. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4135. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4136. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4137. val |= PCISTATE_RETRY_SAME_DMA;
  4138. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4139. pci_restore_state(tp->pdev);
  4140. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4141. /* Make sure PCI-X relaxed ordering bit is clear. */
  4142. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4143. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4144. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4145. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4146. u32 val;
  4147. /* Chip reset on 5780 will reset MSI enable bit,
  4148. * so need to restore it.
  4149. */
  4150. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4151. u16 ctrl;
  4152. pci_read_config_word(tp->pdev,
  4153. tp->msi_cap + PCI_MSI_FLAGS,
  4154. &ctrl);
  4155. pci_write_config_word(tp->pdev,
  4156. tp->msi_cap + PCI_MSI_FLAGS,
  4157. ctrl | PCI_MSI_FLAGS_ENABLE);
  4158. val = tr32(MSGINT_MODE);
  4159. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4160. }
  4161. val = tr32(MEMARB_MODE);
  4162. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4163. } else
  4164. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4165. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4166. tg3_stop_fw(tp);
  4167. tw32(0x5000, 0x400);
  4168. }
  4169. tw32(GRC_MODE, tp->grc_mode);
  4170. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4171. u32 val = tr32(0xc4);
  4172. tw32(0xc4, val | (1 << 15));
  4173. }
  4174. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4175. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4176. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4177. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4178. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4179. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4180. }
  4181. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4182. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4183. tw32_f(MAC_MODE, tp->mac_mode);
  4184. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4185. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4186. tw32_f(MAC_MODE, tp->mac_mode);
  4187. } else
  4188. tw32_f(MAC_MODE, 0);
  4189. udelay(40);
  4190. err = tg3_poll_fw(tp);
  4191. if (err)
  4192. return err;
  4193. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4194. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4195. u32 val = tr32(0x7c00);
  4196. tw32(0x7c00, val | (1 << 25));
  4197. }
  4198. /* Reprobe ASF enable state. */
  4199. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4200. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4201. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4202. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4203. u32 nic_cfg;
  4204. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4205. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4206. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4207. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4208. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4209. }
  4210. }
  4211. return 0;
  4212. }
  4213. /* tp->lock is held. */
  4214. static void tg3_stop_fw(struct tg3 *tp)
  4215. {
  4216. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4217. u32 val;
  4218. int i;
  4219. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4220. val = tr32(GRC_RX_CPU_EVENT);
  4221. val |= (1 << 14);
  4222. tw32(GRC_RX_CPU_EVENT, val);
  4223. /* Wait for RX cpu to ACK the event. */
  4224. for (i = 0; i < 100; i++) {
  4225. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4226. break;
  4227. udelay(1);
  4228. }
  4229. }
  4230. }
  4231. /* tp->lock is held. */
  4232. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4233. {
  4234. int err;
  4235. tg3_stop_fw(tp);
  4236. tg3_write_sig_pre_reset(tp, kind);
  4237. tg3_abort_hw(tp, silent);
  4238. err = tg3_chip_reset(tp);
  4239. tg3_write_sig_legacy(tp, kind);
  4240. tg3_write_sig_post_reset(tp, kind);
  4241. if (err)
  4242. return err;
  4243. return 0;
  4244. }
  4245. #define TG3_FW_RELEASE_MAJOR 0x0
  4246. #define TG3_FW_RELASE_MINOR 0x0
  4247. #define TG3_FW_RELEASE_FIX 0x0
  4248. #define TG3_FW_START_ADDR 0x08000000
  4249. #define TG3_FW_TEXT_ADDR 0x08000000
  4250. #define TG3_FW_TEXT_LEN 0x9c0
  4251. #define TG3_FW_RODATA_ADDR 0x080009c0
  4252. #define TG3_FW_RODATA_LEN 0x60
  4253. #define TG3_FW_DATA_ADDR 0x08000a40
  4254. #define TG3_FW_DATA_LEN 0x20
  4255. #define TG3_FW_SBSS_ADDR 0x08000a60
  4256. #define TG3_FW_SBSS_LEN 0xc
  4257. #define TG3_FW_BSS_ADDR 0x08000a70
  4258. #define TG3_FW_BSS_LEN 0x10
  4259. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4260. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4261. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4262. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4263. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4264. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4265. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4266. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4267. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4268. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4269. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4270. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4271. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4272. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4273. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4274. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4275. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4276. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4277. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4278. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4279. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4280. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4281. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4282. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4285. 0, 0, 0, 0, 0, 0,
  4286. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4287. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4288. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4289. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4290. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4291. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4292. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4293. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4294. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4295. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4296. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4300. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4301. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4302. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4303. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4304. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4305. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4306. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4307. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4308. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4309. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4310. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4311. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4312. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4313. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4314. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4315. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4316. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4317. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4318. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4319. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4320. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4321. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4322. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4323. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4324. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4325. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4326. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4327. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4328. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4329. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4330. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4331. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4332. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4333. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4334. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4335. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4336. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4337. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4338. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4339. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4340. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4341. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4342. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4343. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4344. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4345. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4346. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4347. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4348. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4349. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4350. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4351. };
  4352. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4353. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4354. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4355. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4356. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4357. 0x00000000
  4358. };
  4359. #if 0 /* All zeros, don't eat up space with it. */
  4360. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4361. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4362. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4363. };
  4364. #endif
  4365. #define RX_CPU_SCRATCH_BASE 0x30000
  4366. #define RX_CPU_SCRATCH_SIZE 0x04000
  4367. #define TX_CPU_SCRATCH_BASE 0x34000
  4368. #define TX_CPU_SCRATCH_SIZE 0x04000
  4369. /* tp->lock is held. */
  4370. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4371. {
  4372. int i;
  4373. BUG_ON(offset == TX_CPU_BASE &&
  4374. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4375. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4376. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4377. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4378. return 0;
  4379. }
  4380. if (offset == RX_CPU_BASE) {
  4381. for (i = 0; i < 10000; i++) {
  4382. tw32(offset + CPU_STATE, 0xffffffff);
  4383. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4384. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4385. break;
  4386. }
  4387. tw32(offset + CPU_STATE, 0xffffffff);
  4388. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4389. udelay(10);
  4390. } else {
  4391. for (i = 0; i < 10000; i++) {
  4392. tw32(offset + CPU_STATE, 0xffffffff);
  4393. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4394. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4395. break;
  4396. }
  4397. }
  4398. if (i >= 10000) {
  4399. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4400. "and %s CPU\n",
  4401. tp->dev->name,
  4402. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4403. return -ENODEV;
  4404. }
  4405. /* Clear firmware's nvram arbitration. */
  4406. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4407. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4408. return 0;
  4409. }
  4410. struct fw_info {
  4411. unsigned int text_base;
  4412. unsigned int text_len;
  4413. const u32 *text_data;
  4414. unsigned int rodata_base;
  4415. unsigned int rodata_len;
  4416. const u32 *rodata_data;
  4417. unsigned int data_base;
  4418. unsigned int data_len;
  4419. const u32 *data_data;
  4420. };
  4421. /* tp->lock is held. */
  4422. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4423. int cpu_scratch_size, struct fw_info *info)
  4424. {
  4425. int err, lock_err, i;
  4426. void (*write_op)(struct tg3 *, u32, u32);
  4427. if (cpu_base == TX_CPU_BASE &&
  4428. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4429. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4430. "TX cpu firmware on %s which is 5705.\n",
  4431. tp->dev->name);
  4432. return -EINVAL;
  4433. }
  4434. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4435. write_op = tg3_write_mem;
  4436. else
  4437. write_op = tg3_write_indirect_reg32;
  4438. /* It is possible that bootcode is still loading at this point.
  4439. * Get the nvram lock first before halting the cpu.
  4440. */
  4441. lock_err = tg3_nvram_lock(tp);
  4442. err = tg3_halt_cpu(tp, cpu_base);
  4443. if (!lock_err)
  4444. tg3_nvram_unlock(tp);
  4445. if (err)
  4446. goto out;
  4447. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4448. write_op(tp, cpu_scratch_base + i, 0);
  4449. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4450. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4451. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4452. write_op(tp, (cpu_scratch_base +
  4453. (info->text_base & 0xffff) +
  4454. (i * sizeof(u32))),
  4455. (info->text_data ?
  4456. info->text_data[i] : 0));
  4457. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4458. write_op(tp, (cpu_scratch_base +
  4459. (info->rodata_base & 0xffff) +
  4460. (i * sizeof(u32))),
  4461. (info->rodata_data ?
  4462. info->rodata_data[i] : 0));
  4463. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4464. write_op(tp, (cpu_scratch_base +
  4465. (info->data_base & 0xffff) +
  4466. (i * sizeof(u32))),
  4467. (info->data_data ?
  4468. info->data_data[i] : 0));
  4469. err = 0;
  4470. out:
  4471. return err;
  4472. }
  4473. /* tp->lock is held. */
  4474. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4475. {
  4476. struct fw_info info;
  4477. int err, i;
  4478. info.text_base = TG3_FW_TEXT_ADDR;
  4479. info.text_len = TG3_FW_TEXT_LEN;
  4480. info.text_data = &tg3FwText[0];
  4481. info.rodata_base = TG3_FW_RODATA_ADDR;
  4482. info.rodata_len = TG3_FW_RODATA_LEN;
  4483. info.rodata_data = &tg3FwRodata[0];
  4484. info.data_base = TG3_FW_DATA_ADDR;
  4485. info.data_len = TG3_FW_DATA_LEN;
  4486. info.data_data = NULL;
  4487. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4488. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4489. &info);
  4490. if (err)
  4491. return err;
  4492. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4493. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4494. &info);
  4495. if (err)
  4496. return err;
  4497. /* Now startup only the RX cpu. */
  4498. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4499. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4500. for (i = 0; i < 5; i++) {
  4501. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4502. break;
  4503. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4504. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4505. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4506. udelay(1000);
  4507. }
  4508. if (i >= 5) {
  4509. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4510. "to set RX CPU PC, is %08x should be %08x\n",
  4511. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4512. TG3_FW_TEXT_ADDR);
  4513. return -ENODEV;
  4514. }
  4515. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4516. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4517. return 0;
  4518. }
  4519. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4520. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4521. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4522. #define TG3_TSO_FW_START_ADDR 0x08000000
  4523. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4524. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4525. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4526. #define TG3_TSO_FW_RODATA_LEN 0x60
  4527. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4528. #define TG3_TSO_FW_DATA_LEN 0x30
  4529. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4530. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4531. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4532. #define TG3_TSO_FW_BSS_LEN 0x894
  4533. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4534. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4535. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4536. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4537. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4538. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4539. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4540. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4541. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4542. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4543. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4544. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4545. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4546. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4547. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4548. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4549. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4550. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4551. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4552. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4553. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4554. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4555. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4556. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4557. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4558. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4559. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4560. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4561. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4562. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4563. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4564. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4565. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4566. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4567. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4568. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4569. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4570. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4571. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4572. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4573. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4574. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4575. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4576. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4577. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4578. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4579. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4580. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4581. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4582. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4583. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4584. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4585. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4586. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4587. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4588. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4589. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4590. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4591. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4592. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4593. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4594. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4595. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4596. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4597. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4598. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4599. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4600. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4601. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4602. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4603. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4604. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4605. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4606. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4607. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4608. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4609. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4610. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4611. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4612. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4613. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4614. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4615. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4616. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4617. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4618. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4619. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4620. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4621. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4622. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4623. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4624. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4625. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4626. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4627. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4628. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4629. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4630. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4631. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4632. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4633. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4634. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4635. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4636. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4637. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4638. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4639. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4640. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4641. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4642. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4643. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4644. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4645. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4646. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4647. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4648. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4649. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4650. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4651. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4652. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4653. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4654. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4655. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4656. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4657. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4658. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4659. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4660. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4661. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4662. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4663. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4664. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4665. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4666. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4667. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4668. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4669. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4670. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4671. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4672. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4673. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4674. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4675. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4676. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4677. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4678. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4679. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4680. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4681. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4682. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4683. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4684. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4685. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4686. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4687. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4688. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4689. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4690. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4691. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4692. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4693. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4694. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4695. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4696. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4697. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4698. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4699. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4700. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4701. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4702. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4703. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4704. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4705. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4706. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4707. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4708. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4709. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4710. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4711. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4712. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4713. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4714. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4715. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4716. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4717. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4718. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4719. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4720. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4721. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4722. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4723. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4724. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4725. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4726. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4727. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4728. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4729. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4730. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4731. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4732. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4733. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4734. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4735. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4736. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4737. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4738. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4739. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4740. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4741. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4742. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4743. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4744. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4745. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4746. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4747. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4748. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4749. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4750. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4751. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4752. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4753. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4754. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4755. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4756. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4757. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4758. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4759. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4760. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4761. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4762. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4763. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4764. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4765. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4766. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4767. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4768. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4769. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4770. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4771. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4772. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4773. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4774. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4775. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4776. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4777. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4778. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4779. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4780. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4781. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4782. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4783. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4784. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4785. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4786. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4787. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4788. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4789. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4790. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4791. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4792. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4793. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4794. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4795. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4796. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4797. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4798. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4799. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4800. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4801. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4802. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4803. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4804. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4805. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4806. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4807. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4808. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4809. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4810. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4811. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4812. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4813. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4814. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4815. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4816. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4817. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4818. };
  4819. static const u32 tg3TsoFwRodata[] = {
  4820. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4821. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4822. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4823. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4824. 0x00000000,
  4825. };
  4826. static const u32 tg3TsoFwData[] = {
  4827. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4828. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4829. 0x00000000,
  4830. };
  4831. /* 5705 needs a special version of the TSO firmware. */
  4832. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4833. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4834. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4835. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4836. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4837. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4838. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4839. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4840. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4841. #define TG3_TSO5_FW_DATA_LEN 0x20
  4842. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4843. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4844. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4845. #define TG3_TSO5_FW_BSS_LEN 0x88
  4846. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4847. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4848. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4849. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4850. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4851. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4852. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4853. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4854. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4855. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4856. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4857. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4858. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4859. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4860. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4861. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4862. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4863. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4864. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4865. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4866. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4867. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4868. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4869. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4870. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4871. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4872. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4873. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4874. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4875. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4876. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4877. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4878. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4879. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4880. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4881. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4882. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4883. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4884. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4885. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4886. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4887. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4888. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4889. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4890. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4891. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4892. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4893. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4894. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4895. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4896. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4897. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4898. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4899. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4900. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4901. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4902. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4903. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4904. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4905. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4906. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4907. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4908. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4909. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4910. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4911. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4912. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4913. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4914. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4915. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4916. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4917. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4918. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4919. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4920. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4921. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4922. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4923. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4924. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4925. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4926. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4927. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4928. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4929. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4930. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4931. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4932. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4933. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4934. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4935. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4936. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4937. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4938. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4939. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4940. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4941. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4942. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4943. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4944. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4945. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  4946. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  4947. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  4948. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  4949. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  4950. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  4951. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  4952. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  4953. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4954. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4955. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  4956. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  4957. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  4958. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  4959. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  4960. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  4961. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  4962. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  4963. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  4964. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4965. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4966. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  4967. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  4968. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  4969. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  4970. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4971. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  4972. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  4973. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  4974. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  4975. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  4976. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  4977. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  4978. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  4979. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  4980. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  4981. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  4982. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  4983. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  4984. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  4985. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  4986. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  4987. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  4988. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  4989. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  4990. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  4991. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  4992. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  4993. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  4994. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4995. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  4996. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  4997. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  4998. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4999. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5000. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5001. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5002. 0x00000000, 0x00000000, 0x00000000,
  5003. };
  5004. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5005. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5006. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5007. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5008. 0x00000000, 0x00000000, 0x00000000,
  5009. };
  5010. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5011. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5012. 0x00000000, 0x00000000, 0x00000000,
  5013. };
  5014. /* tp->lock is held. */
  5015. static int tg3_load_tso_firmware(struct tg3 *tp)
  5016. {
  5017. struct fw_info info;
  5018. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5019. int err, i;
  5020. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5021. return 0;
  5022. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5023. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5024. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5025. info.text_data = &tg3Tso5FwText[0];
  5026. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5027. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5028. info.rodata_data = &tg3Tso5FwRodata[0];
  5029. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5030. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5031. info.data_data = &tg3Tso5FwData[0];
  5032. cpu_base = RX_CPU_BASE;
  5033. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5034. cpu_scratch_size = (info.text_len +
  5035. info.rodata_len +
  5036. info.data_len +
  5037. TG3_TSO5_FW_SBSS_LEN +
  5038. TG3_TSO5_FW_BSS_LEN);
  5039. } else {
  5040. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5041. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5042. info.text_data = &tg3TsoFwText[0];
  5043. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5044. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5045. info.rodata_data = &tg3TsoFwRodata[0];
  5046. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5047. info.data_len = TG3_TSO_FW_DATA_LEN;
  5048. info.data_data = &tg3TsoFwData[0];
  5049. cpu_base = TX_CPU_BASE;
  5050. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5051. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5052. }
  5053. err = tg3_load_firmware_cpu(tp, cpu_base,
  5054. cpu_scratch_base, cpu_scratch_size,
  5055. &info);
  5056. if (err)
  5057. return err;
  5058. /* Now startup the cpu. */
  5059. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5060. tw32_f(cpu_base + CPU_PC, info.text_base);
  5061. for (i = 0; i < 5; i++) {
  5062. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5063. break;
  5064. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5065. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5066. tw32_f(cpu_base + CPU_PC, info.text_base);
  5067. udelay(1000);
  5068. }
  5069. if (i >= 5) {
  5070. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5071. "to set CPU PC, is %08x should be %08x\n",
  5072. tp->dev->name, tr32(cpu_base + CPU_PC),
  5073. info.text_base);
  5074. return -ENODEV;
  5075. }
  5076. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5077. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5078. return 0;
  5079. }
  5080. /* tp->lock is held. */
  5081. static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
  5082. {
  5083. u32 addr_high, addr_low;
  5084. int i;
  5085. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5086. tp->dev->dev_addr[1]);
  5087. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5088. (tp->dev->dev_addr[3] << 16) |
  5089. (tp->dev->dev_addr[4] << 8) |
  5090. (tp->dev->dev_addr[5] << 0));
  5091. for (i = 0; i < 4; i++) {
  5092. if (i == 1 && skip_mac_1)
  5093. continue;
  5094. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5095. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5096. }
  5097. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5098. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5099. for (i = 0; i < 12; i++) {
  5100. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5101. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5102. }
  5103. }
  5104. addr_high = (tp->dev->dev_addr[0] +
  5105. tp->dev->dev_addr[1] +
  5106. tp->dev->dev_addr[2] +
  5107. tp->dev->dev_addr[3] +
  5108. tp->dev->dev_addr[4] +
  5109. tp->dev->dev_addr[5]) &
  5110. TX_BACKOFF_SEED_MASK;
  5111. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5112. }
  5113. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5114. {
  5115. struct tg3 *tp = netdev_priv(dev);
  5116. struct sockaddr *addr = p;
  5117. int err = 0, skip_mac_1 = 0;
  5118. if (!is_valid_ether_addr(addr->sa_data))
  5119. return -EINVAL;
  5120. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5121. if (!netif_running(dev))
  5122. return 0;
  5123. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5124. u32 addr0_high, addr0_low, addr1_high, addr1_low;
  5125. addr0_high = tr32(MAC_ADDR_0_HIGH);
  5126. addr0_low = tr32(MAC_ADDR_0_LOW);
  5127. addr1_high = tr32(MAC_ADDR_1_HIGH);
  5128. addr1_low = tr32(MAC_ADDR_1_LOW);
  5129. /* Skip MAC addr 1 if ASF is using it. */
  5130. if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
  5131. !(addr1_high == 0 && addr1_low == 0))
  5132. skip_mac_1 = 1;
  5133. }
  5134. spin_lock_bh(&tp->lock);
  5135. __tg3_set_mac_addr(tp, skip_mac_1);
  5136. spin_unlock_bh(&tp->lock);
  5137. return err;
  5138. }
  5139. /* tp->lock is held. */
  5140. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5141. dma_addr_t mapping, u32 maxlen_flags,
  5142. u32 nic_addr)
  5143. {
  5144. tg3_write_mem(tp,
  5145. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5146. ((u64) mapping >> 32));
  5147. tg3_write_mem(tp,
  5148. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5149. ((u64) mapping & 0xffffffff));
  5150. tg3_write_mem(tp,
  5151. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5152. maxlen_flags);
  5153. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5154. tg3_write_mem(tp,
  5155. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5156. nic_addr);
  5157. }
  5158. static void __tg3_set_rx_mode(struct net_device *);
  5159. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5160. {
  5161. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5162. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5163. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5164. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5165. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5166. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5167. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5168. }
  5169. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5170. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5171. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5172. u32 val = ec->stats_block_coalesce_usecs;
  5173. if (!netif_carrier_ok(tp->dev))
  5174. val = 0;
  5175. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5176. }
  5177. }
  5178. /* tp->lock is held. */
  5179. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5180. {
  5181. u32 val, rdmac_mode;
  5182. int i, err, limit;
  5183. tg3_disable_ints(tp);
  5184. tg3_stop_fw(tp);
  5185. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5186. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5187. tg3_abort_hw(tp, 1);
  5188. }
  5189. if (reset_phy)
  5190. tg3_phy_reset(tp);
  5191. err = tg3_chip_reset(tp);
  5192. if (err)
  5193. return err;
  5194. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5195. /* This works around an issue with Athlon chipsets on
  5196. * B3 tigon3 silicon. This bit has no effect on any
  5197. * other revision. But do not set this on PCI Express
  5198. * chips.
  5199. */
  5200. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5201. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5202. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5203. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5204. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5205. val = tr32(TG3PCI_PCISTATE);
  5206. val |= PCISTATE_RETRY_SAME_DMA;
  5207. tw32(TG3PCI_PCISTATE, val);
  5208. }
  5209. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5210. /* Enable some hw fixes. */
  5211. val = tr32(TG3PCI_MSI_DATA);
  5212. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5213. tw32(TG3PCI_MSI_DATA, val);
  5214. }
  5215. /* Descriptor ring init may make accesses to the
  5216. * NIC SRAM area to setup the TX descriptors, so we
  5217. * can only do this after the hardware has been
  5218. * successfully reset.
  5219. */
  5220. err = tg3_init_rings(tp);
  5221. if (err)
  5222. return err;
  5223. /* This value is determined during the probe time DMA
  5224. * engine test, tg3_test_dma.
  5225. */
  5226. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5227. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5228. GRC_MODE_4X_NIC_SEND_RINGS |
  5229. GRC_MODE_NO_TX_PHDR_CSUM |
  5230. GRC_MODE_NO_RX_PHDR_CSUM);
  5231. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5232. /* Pseudo-header checksum is done by hardware logic and not
  5233. * the offload processers, so make the chip do the pseudo-
  5234. * header checksums on receive. For transmit it is more
  5235. * convenient to do the pseudo-header checksum in software
  5236. * as Linux does that on transmit for us in all cases.
  5237. */
  5238. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5239. tw32(GRC_MODE,
  5240. tp->grc_mode |
  5241. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5242. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5243. val = tr32(GRC_MISC_CFG);
  5244. val &= ~0xff;
  5245. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5246. tw32(GRC_MISC_CFG, val);
  5247. /* Initialize MBUF/DESC pool. */
  5248. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5249. /* Do nothing. */
  5250. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5251. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5252. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5253. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5254. else
  5255. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5256. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5257. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5258. }
  5259. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5260. int fw_len;
  5261. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5262. TG3_TSO5_FW_RODATA_LEN +
  5263. TG3_TSO5_FW_DATA_LEN +
  5264. TG3_TSO5_FW_SBSS_LEN +
  5265. TG3_TSO5_FW_BSS_LEN);
  5266. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5267. tw32(BUFMGR_MB_POOL_ADDR,
  5268. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5269. tw32(BUFMGR_MB_POOL_SIZE,
  5270. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5271. }
  5272. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5273. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5274. tp->bufmgr_config.mbuf_read_dma_low_water);
  5275. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5276. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5277. tw32(BUFMGR_MB_HIGH_WATER,
  5278. tp->bufmgr_config.mbuf_high_water);
  5279. } else {
  5280. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5281. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5282. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5283. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5284. tw32(BUFMGR_MB_HIGH_WATER,
  5285. tp->bufmgr_config.mbuf_high_water_jumbo);
  5286. }
  5287. tw32(BUFMGR_DMA_LOW_WATER,
  5288. tp->bufmgr_config.dma_low_water);
  5289. tw32(BUFMGR_DMA_HIGH_WATER,
  5290. tp->bufmgr_config.dma_high_water);
  5291. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5292. for (i = 0; i < 2000; i++) {
  5293. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5294. break;
  5295. udelay(10);
  5296. }
  5297. if (i >= 2000) {
  5298. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5299. tp->dev->name);
  5300. return -ENODEV;
  5301. }
  5302. /* Setup replenish threshold. */
  5303. val = tp->rx_pending / 8;
  5304. if (val == 0)
  5305. val = 1;
  5306. else if (val > tp->rx_std_max_post)
  5307. val = tp->rx_std_max_post;
  5308. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5309. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5310. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5311. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5312. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5313. }
  5314. tw32(RCVBDI_STD_THRESH, val);
  5315. /* Initialize TG3_BDINFO's at:
  5316. * RCVDBDI_STD_BD: standard eth size rx ring
  5317. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5318. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5319. *
  5320. * like so:
  5321. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5322. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5323. * ring attribute flags
  5324. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5325. *
  5326. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5327. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5328. *
  5329. * The size of each ring is fixed in the firmware, but the location is
  5330. * configurable.
  5331. */
  5332. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5333. ((u64) tp->rx_std_mapping >> 32));
  5334. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5335. ((u64) tp->rx_std_mapping & 0xffffffff));
  5336. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5337. NIC_SRAM_RX_BUFFER_DESC);
  5338. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5339. * configs on 5705.
  5340. */
  5341. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5342. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5343. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5344. } else {
  5345. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5346. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5347. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5348. BDINFO_FLAGS_DISABLED);
  5349. /* Setup replenish threshold. */
  5350. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5351. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5352. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5353. ((u64) tp->rx_jumbo_mapping >> 32));
  5354. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5355. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5356. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5357. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5358. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5359. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5360. } else {
  5361. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5362. BDINFO_FLAGS_DISABLED);
  5363. }
  5364. }
  5365. /* There is only one send ring on 5705/5750, no need to explicitly
  5366. * disable the others.
  5367. */
  5368. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5369. /* Clear out send RCB ring in SRAM. */
  5370. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5371. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5372. BDINFO_FLAGS_DISABLED);
  5373. }
  5374. tp->tx_prod = 0;
  5375. tp->tx_cons = 0;
  5376. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5377. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5378. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5379. tp->tx_desc_mapping,
  5380. (TG3_TX_RING_SIZE <<
  5381. BDINFO_FLAGS_MAXLEN_SHIFT),
  5382. NIC_SRAM_TX_BUFFER_DESC);
  5383. /* There is only one receive return ring on 5705/5750, no need
  5384. * to explicitly disable the others.
  5385. */
  5386. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5387. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5388. i += TG3_BDINFO_SIZE) {
  5389. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5390. BDINFO_FLAGS_DISABLED);
  5391. }
  5392. }
  5393. tp->rx_rcb_ptr = 0;
  5394. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5395. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5396. tp->rx_rcb_mapping,
  5397. (TG3_RX_RCB_RING_SIZE(tp) <<
  5398. BDINFO_FLAGS_MAXLEN_SHIFT),
  5399. 0);
  5400. tp->rx_std_ptr = tp->rx_pending;
  5401. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5402. tp->rx_std_ptr);
  5403. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5404. tp->rx_jumbo_pending : 0;
  5405. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5406. tp->rx_jumbo_ptr);
  5407. /* Initialize MAC address and backoff seed. */
  5408. __tg3_set_mac_addr(tp, 0);
  5409. /* MTU + ethernet header + FCS + optional VLAN tag */
  5410. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5411. /* The slot time is changed by tg3_setup_phy if we
  5412. * run at gigabit with half duplex.
  5413. */
  5414. tw32(MAC_TX_LENGTHS,
  5415. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5416. (6 << TX_LENGTHS_IPG_SHIFT) |
  5417. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5418. /* Receive rules. */
  5419. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5420. tw32(RCVLPC_CONFIG, 0x0181);
  5421. /* Calculate RDMAC_MODE setting early, we need it to determine
  5422. * the RCVLPC_STATE_ENABLE mask.
  5423. */
  5424. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5425. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5426. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5427. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5428. RDMAC_MODE_LNGREAD_ENAB);
  5429. /* If statement applies to 5705 and 5750 PCI devices only */
  5430. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5431. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5432. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5433. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5434. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5435. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5436. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5437. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5438. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5439. }
  5440. }
  5441. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5442. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5443. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5444. rdmac_mode |= (1 << 27);
  5445. /* Receive/send statistics. */
  5446. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5447. val = tr32(RCVLPC_STATS_ENABLE);
  5448. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5449. tw32(RCVLPC_STATS_ENABLE, val);
  5450. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5451. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5452. val = tr32(RCVLPC_STATS_ENABLE);
  5453. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5454. tw32(RCVLPC_STATS_ENABLE, val);
  5455. } else {
  5456. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5457. }
  5458. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5459. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5460. tw32(SNDDATAI_STATSCTRL,
  5461. (SNDDATAI_SCTRL_ENABLE |
  5462. SNDDATAI_SCTRL_FASTUPD));
  5463. /* Setup host coalescing engine. */
  5464. tw32(HOSTCC_MODE, 0);
  5465. for (i = 0; i < 2000; i++) {
  5466. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5467. break;
  5468. udelay(10);
  5469. }
  5470. __tg3_set_coalesce(tp, &tp->coal);
  5471. /* set status block DMA address */
  5472. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5473. ((u64) tp->status_mapping >> 32));
  5474. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5475. ((u64) tp->status_mapping & 0xffffffff));
  5476. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5477. /* Status/statistics block address. See tg3_timer,
  5478. * the tg3_periodic_fetch_stats call there, and
  5479. * tg3_get_stats to see how this works for 5705/5750 chips.
  5480. */
  5481. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5482. ((u64) tp->stats_mapping >> 32));
  5483. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5484. ((u64) tp->stats_mapping & 0xffffffff));
  5485. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5486. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5487. }
  5488. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5489. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5490. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5491. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5492. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5493. /* Clear statistics/status block in chip, and status block in ram. */
  5494. for (i = NIC_SRAM_STATS_BLK;
  5495. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5496. i += sizeof(u32)) {
  5497. tg3_write_mem(tp, i, 0);
  5498. udelay(40);
  5499. }
  5500. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5501. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5502. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5503. /* reset to prevent losing 1st rx packet intermittently */
  5504. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5505. udelay(10);
  5506. }
  5507. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5508. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5509. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5510. udelay(40);
  5511. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5512. * If TG3_FLG2_IS_NIC is zero, we should read the
  5513. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5514. * whether used as inputs or outputs, are set by boot code after
  5515. * reset.
  5516. */
  5517. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5518. u32 gpio_mask;
  5519. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5520. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5521. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5522. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5523. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5524. GRC_LCLCTRL_GPIO_OUTPUT3;
  5525. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5526. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5527. tp->grc_local_ctrl &= ~gpio_mask;
  5528. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5529. /* GPIO1 must be driven high for eeprom write protect */
  5530. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5531. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5532. GRC_LCLCTRL_GPIO_OUTPUT1);
  5533. }
  5534. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5535. udelay(100);
  5536. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5537. tp->last_tag = 0;
  5538. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5539. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5540. udelay(40);
  5541. }
  5542. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5543. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5544. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5545. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5546. WDMAC_MODE_LNGREAD_ENAB);
  5547. /* If statement applies to 5705 and 5750 PCI devices only */
  5548. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5549. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5550. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5551. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5552. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5553. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5554. /* nothing */
  5555. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5556. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5557. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5558. val |= WDMAC_MODE_RX_ACCEL;
  5559. }
  5560. }
  5561. /* Enable host coalescing bug fix */
  5562. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5563. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5564. val |= (1 << 29);
  5565. tw32_f(WDMAC_MODE, val);
  5566. udelay(40);
  5567. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5568. val = tr32(TG3PCI_X_CAPS);
  5569. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5570. val &= ~PCIX_CAPS_BURST_MASK;
  5571. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5572. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5573. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5574. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5575. }
  5576. tw32(TG3PCI_X_CAPS, val);
  5577. }
  5578. tw32_f(RDMAC_MODE, rdmac_mode);
  5579. udelay(40);
  5580. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5581. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5582. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5583. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5584. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5585. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5586. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5587. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5588. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5589. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5590. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5591. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5592. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5593. err = tg3_load_5701_a0_firmware_fix(tp);
  5594. if (err)
  5595. return err;
  5596. }
  5597. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5598. err = tg3_load_tso_firmware(tp);
  5599. if (err)
  5600. return err;
  5601. }
  5602. tp->tx_mode = TX_MODE_ENABLE;
  5603. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5604. udelay(100);
  5605. tp->rx_mode = RX_MODE_ENABLE;
  5606. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5607. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5608. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5609. udelay(10);
  5610. if (tp->link_config.phy_is_low_power) {
  5611. tp->link_config.phy_is_low_power = 0;
  5612. tp->link_config.speed = tp->link_config.orig_speed;
  5613. tp->link_config.duplex = tp->link_config.orig_duplex;
  5614. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5615. }
  5616. tp->mi_mode = MAC_MI_MODE_BASE;
  5617. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5618. udelay(80);
  5619. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5620. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5621. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5622. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5623. udelay(10);
  5624. }
  5625. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5626. udelay(10);
  5627. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5628. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5629. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5630. /* Set drive transmission level to 1.2V */
  5631. /* only if the signal pre-emphasis bit is not set */
  5632. val = tr32(MAC_SERDES_CFG);
  5633. val &= 0xfffff000;
  5634. val |= 0x880;
  5635. tw32(MAC_SERDES_CFG, val);
  5636. }
  5637. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5638. tw32(MAC_SERDES_CFG, 0x616000);
  5639. }
  5640. /* Prevent chip from dropping frames when flow control
  5641. * is enabled.
  5642. */
  5643. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5644. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5645. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5646. /* Use hardware link auto-negotiation */
  5647. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5648. }
  5649. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5650. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5651. u32 tmp;
  5652. tmp = tr32(SERDES_RX_CTRL);
  5653. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5654. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5655. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5656. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5657. }
  5658. err = tg3_setup_phy(tp, 0);
  5659. if (err)
  5660. return err;
  5661. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5662. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  5663. u32 tmp;
  5664. /* Clear CRC stats. */
  5665. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  5666. tg3_writephy(tp, MII_TG3_TEST1,
  5667. tmp | MII_TG3_TEST1_CRC_EN);
  5668. tg3_readphy(tp, 0x14, &tmp);
  5669. }
  5670. }
  5671. __tg3_set_rx_mode(tp->dev);
  5672. /* Initialize receive rules. */
  5673. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5674. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5675. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5676. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5677. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5678. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5679. limit = 8;
  5680. else
  5681. limit = 16;
  5682. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5683. limit -= 4;
  5684. switch (limit) {
  5685. case 16:
  5686. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5687. case 15:
  5688. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5689. case 14:
  5690. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5691. case 13:
  5692. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5693. case 12:
  5694. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5695. case 11:
  5696. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5697. case 10:
  5698. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5699. case 9:
  5700. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5701. case 8:
  5702. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5703. case 7:
  5704. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5705. case 6:
  5706. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5707. case 5:
  5708. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5709. case 4:
  5710. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5711. case 3:
  5712. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5713. case 2:
  5714. case 1:
  5715. default:
  5716. break;
  5717. };
  5718. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5719. return 0;
  5720. }
  5721. /* Called at device open time to get the chip ready for
  5722. * packet processing. Invoked with tp->lock held.
  5723. */
  5724. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5725. {
  5726. int err;
  5727. /* Force the chip into D0. */
  5728. err = tg3_set_power_state(tp, PCI_D0);
  5729. if (err)
  5730. goto out;
  5731. tg3_switch_clocks(tp);
  5732. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5733. err = tg3_reset_hw(tp, reset_phy);
  5734. out:
  5735. return err;
  5736. }
  5737. #define TG3_STAT_ADD32(PSTAT, REG) \
  5738. do { u32 __val = tr32(REG); \
  5739. (PSTAT)->low += __val; \
  5740. if ((PSTAT)->low < __val) \
  5741. (PSTAT)->high += 1; \
  5742. } while (0)
  5743. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5744. {
  5745. struct tg3_hw_stats *sp = tp->hw_stats;
  5746. if (!netif_carrier_ok(tp->dev))
  5747. return;
  5748. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5749. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5750. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5751. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5752. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5753. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5754. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5755. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5756. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5757. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5758. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5759. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5760. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5761. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5762. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5763. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5764. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5765. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5766. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5767. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5768. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5769. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5770. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5771. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5772. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5773. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5774. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5775. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5776. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5777. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5778. }
  5779. static void tg3_timer(unsigned long __opaque)
  5780. {
  5781. struct tg3 *tp = (struct tg3 *) __opaque;
  5782. if (tp->irq_sync)
  5783. goto restart_timer;
  5784. spin_lock(&tp->lock);
  5785. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5786. /* All of this garbage is because when using non-tagged
  5787. * IRQ status the mailbox/status_block protocol the chip
  5788. * uses with the cpu is race prone.
  5789. */
  5790. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5791. tw32(GRC_LOCAL_CTRL,
  5792. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5793. } else {
  5794. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5795. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5796. }
  5797. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5798. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5799. spin_unlock(&tp->lock);
  5800. schedule_work(&tp->reset_task);
  5801. return;
  5802. }
  5803. }
  5804. /* This part only runs once per second. */
  5805. if (!--tp->timer_counter) {
  5806. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5807. tg3_periodic_fetch_stats(tp);
  5808. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5809. u32 mac_stat;
  5810. int phy_event;
  5811. mac_stat = tr32(MAC_STATUS);
  5812. phy_event = 0;
  5813. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5814. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5815. phy_event = 1;
  5816. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5817. phy_event = 1;
  5818. if (phy_event)
  5819. tg3_setup_phy(tp, 0);
  5820. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5821. u32 mac_stat = tr32(MAC_STATUS);
  5822. int need_setup = 0;
  5823. if (netif_carrier_ok(tp->dev) &&
  5824. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5825. need_setup = 1;
  5826. }
  5827. if (! netif_carrier_ok(tp->dev) &&
  5828. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5829. MAC_STATUS_SIGNAL_DET))) {
  5830. need_setup = 1;
  5831. }
  5832. if (need_setup) {
  5833. if (!tp->serdes_counter) {
  5834. tw32_f(MAC_MODE,
  5835. (tp->mac_mode &
  5836. ~MAC_MODE_PORT_MODE_MASK));
  5837. udelay(40);
  5838. tw32_f(MAC_MODE, tp->mac_mode);
  5839. udelay(40);
  5840. }
  5841. tg3_setup_phy(tp, 0);
  5842. }
  5843. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5844. tg3_serdes_parallel_detect(tp);
  5845. tp->timer_counter = tp->timer_multiplier;
  5846. }
  5847. /* Heartbeat is only sent once every 2 seconds.
  5848. *
  5849. * The heartbeat is to tell the ASF firmware that the host
  5850. * driver is still alive. In the event that the OS crashes,
  5851. * ASF needs to reset the hardware to free up the FIFO space
  5852. * that may be filled with rx packets destined for the host.
  5853. * If the FIFO is full, ASF will no longer function properly.
  5854. *
  5855. * Unintended resets have been reported on real time kernels
  5856. * where the timer doesn't run on time. Netpoll will also have
  5857. * same problem.
  5858. *
  5859. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  5860. * to check the ring condition when the heartbeat is expiring
  5861. * before doing the reset. This will prevent most unintended
  5862. * resets.
  5863. */
  5864. if (!--tp->asf_counter) {
  5865. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5866. u32 val;
  5867. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5868. FWCMD_NICDRV_ALIVE3);
  5869. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5870. /* 5 seconds timeout */
  5871. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5872. val = tr32(GRC_RX_CPU_EVENT);
  5873. val |= (1 << 14);
  5874. tw32(GRC_RX_CPU_EVENT, val);
  5875. }
  5876. tp->asf_counter = tp->asf_multiplier;
  5877. }
  5878. spin_unlock(&tp->lock);
  5879. restart_timer:
  5880. tp->timer.expires = jiffies + tp->timer_offset;
  5881. add_timer(&tp->timer);
  5882. }
  5883. static int tg3_request_irq(struct tg3 *tp)
  5884. {
  5885. irq_handler_t fn;
  5886. unsigned long flags;
  5887. struct net_device *dev = tp->dev;
  5888. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5889. fn = tg3_msi;
  5890. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5891. fn = tg3_msi_1shot;
  5892. flags = IRQF_SAMPLE_RANDOM;
  5893. } else {
  5894. fn = tg3_interrupt;
  5895. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5896. fn = tg3_interrupt_tagged;
  5897. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5898. }
  5899. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5900. }
  5901. static int tg3_test_interrupt(struct tg3 *tp)
  5902. {
  5903. struct net_device *dev = tp->dev;
  5904. int err, i, intr_ok = 0;
  5905. if (!netif_running(dev))
  5906. return -ENODEV;
  5907. tg3_disable_ints(tp);
  5908. free_irq(tp->pdev->irq, dev);
  5909. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5910. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5911. if (err)
  5912. return err;
  5913. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5914. tg3_enable_ints(tp);
  5915. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5916. HOSTCC_MODE_NOW);
  5917. for (i = 0; i < 5; i++) {
  5918. u32 int_mbox, misc_host_ctrl;
  5919. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5920. TG3_64BIT_REG_LOW);
  5921. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  5922. if ((int_mbox != 0) ||
  5923. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  5924. intr_ok = 1;
  5925. break;
  5926. }
  5927. msleep(10);
  5928. }
  5929. tg3_disable_ints(tp);
  5930. free_irq(tp->pdev->irq, dev);
  5931. err = tg3_request_irq(tp);
  5932. if (err)
  5933. return err;
  5934. if (intr_ok)
  5935. return 0;
  5936. return -EIO;
  5937. }
  5938. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5939. * successfully restored
  5940. */
  5941. static int tg3_test_msi(struct tg3 *tp)
  5942. {
  5943. struct net_device *dev = tp->dev;
  5944. int err;
  5945. u16 pci_cmd;
  5946. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  5947. return 0;
  5948. /* Turn off SERR reporting in case MSI terminates with Master
  5949. * Abort.
  5950. */
  5951. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  5952. pci_write_config_word(tp->pdev, PCI_COMMAND,
  5953. pci_cmd & ~PCI_COMMAND_SERR);
  5954. err = tg3_test_interrupt(tp);
  5955. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  5956. if (!err)
  5957. return 0;
  5958. /* other failures */
  5959. if (err != -EIO)
  5960. return err;
  5961. /* MSI test failed, go back to INTx mode */
  5962. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  5963. "switching to INTx mode. Please report this failure to "
  5964. "the PCI maintainer and include system chipset information.\n",
  5965. tp->dev->name);
  5966. free_irq(tp->pdev->irq, dev);
  5967. pci_disable_msi(tp->pdev);
  5968. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5969. err = tg3_request_irq(tp);
  5970. if (err)
  5971. return err;
  5972. /* Need to reset the chip because the MSI cycle may have terminated
  5973. * with Master Abort.
  5974. */
  5975. tg3_full_lock(tp, 1);
  5976. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5977. err = tg3_init_hw(tp, 1);
  5978. tg3_full_unlock(tp);
  5979. if (err)
  5980. free_irq(tp->pdev->irq, dev);
  5981. return err;
  5982. }
  5983. static int tg3_open(struct net_device *dev)
  5984. {
  5985. struct tg3 *tp = netdev_priv(dev);
  5986. int err;
  5987. netif_carrier_off(tp->dev);
  5988. tg3_full_lock(tp, 0);
  5989. err = tg3_set_power_state(tp, PCI_D0);
  5990. if (err) {
  5991. tg3_full_unlock(tp);
  5992. return err;
  5993. }
  5994. tg3_disable_ints(tp);
  5995. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  5996. tg3_full_unlock(tp);
  5997. /* The placement of this call is tied
  5998. * to the setup and use of Host TX descriptors.
  5999. */
  6000. err = tg3_alloc_consistent(tp);
  6001. if (err)
  6002. return err;
  6003. if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) {
  6004. /* All MSI supporting chips should support tagged
  6005. * status. Assert that this is the case.
  6006. */
  6007. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6008. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6009. "Not using MSI.\n", tp->dev->name);
  6010. } else if (pci_enable_msi(tp->pdev) == 0) {
  6011. u32 msi_mode;
  6012. msi_mode = tr32(MSGINT_MODE);
  6013. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6014. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6015. }
  6016. }
  6017. err = tg3_request_irq(tp);
  6018. if (err) {
  6019. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6020. pci_disable_msi(tp->pdev);
  6021. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6022. }
  6023. tg3_free_consistent(tp);
  6024. return err;
  6025. }
  6026. tg3_full_lock(tp, 0);
  6027. err = tg3_init_hw(tp, 1);
  6028. if (err) {
  6029. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6030. tg3_free_rings(tp);
  6031. } else {
  6032. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6033. tp->timer_offset = HZ;
  6034. else
  6035. tp->timer_offset = HZ / 10;
  6036. BUG_ON(tp->timer_offset > HZ);
  6037. tp->timer_counter = tp->timer_multiplier =
  6038. (HZ / tp->timer_offset);
  6039. tp->asf_counter = tp->asf_multiplier =
  6040. ((HZ / tp->timer_offset) * 2);
  6041. init_timer(&tp->timer);
  6042. tp->timer.expires = jiffies + tp->timer_offset;
  6043. tp->timer.data = (unsigned long) tp;
  6044. tp->timer.function = tg3_timer;
  6045. }
  6046. tg3_full_unlock(tp);
  6047. if (err) {
  6048. free_irq(tp->pdev->irq, dev);
  6049. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6050. pci_disable_msi(tp->pdev);
  6051. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6052. }
  6053. tg3_free_consistent(tp);
  6054. return err;
  6055. }
  6056. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6057. err = tg3_test_msi(tp);
  6058. if (err) {
  6059. tg3_full_lock(tp, 0);
  6060. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6061. pci_disable_msi(tp->pdev);
  6062. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6063. }
  6064. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6065. tg3_free_rings(tp);
  6066. tg3_free_consistent(tp);
  6067. tg3_full_unlock(tp);
  6068. return err;
  6069. }
  6070. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6071. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6072. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6073. tw32(PCIE_TRANSACTION_CFG,
  6074. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6075. }
  6076. }
  6077. }
  6078. tg3_full_lock(tp, 0);
  6079. add_timer(&tp->timer);
  6080. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6081. tg3_enable_ints(tp);
  6082. tg3_full_unlock(tp);
  6083. netif_start_queue(dev);
  6084. return 0;
  6085. }
  6086. #if 0
  6087. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6088. {
  6089. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6090. u16 val16;
  6091. int i;
  6092. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6093. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6094. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6095. val16, val32);
  6096. /* MAC block */
  6097. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6098. tr32(MAC_MODE), tr32(MAC_STATUS));
  6099. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6100. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6101. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6102. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6103. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6104. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6105. /* Send data initiator control block */
  6106. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6107. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6108. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6109. tr32(SNDDATAI_STATSCTRL));
  6110. /* Send data completion control block */
  6111. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6112. /* Send BD ring selector block */
  6113. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6114. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6115. /* Send BD initiator control block */
  6116. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6117. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6118. /* Send BD completion control block */
  6119. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6120. /* Receive list placement control block */
  6121. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6122. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6123. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6124. tr32(RCVLPC_STATSCTRL));
  6125. /* Receive data and receive BD initiator control block */
  6126. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6127. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6128. /* Receive data completion control block */
  6129. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6130. tr32(RCVDCC_MODE));
  6131. /* Receive BD initiator control block */
  6132. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6133. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6134. /* Receive BD completion control block */
  6135. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6136. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6137. /* Receive list selector control block */
  6138. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6139. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6140. /* Mbuf cluster free block */
  6141. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6142. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6143. /* Host coalescing control block */
  6144. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6145. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6146. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6147. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6148. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6149. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6150. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6151. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6152. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6153. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6154. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6155. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6156. /* Memory arbiter control block */
  6157. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6158. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6159. /* Buffer manager control block */
  6160. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6161. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6162. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6163. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6164. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6165. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6166. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6167. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6168. /* Read DMA control block */
  6169. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6170. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6171. /* Write DMA control block */
  6172. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6173. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6174. /* DMA completion block */
  6175. printk("DEBUG: DMAC_MODE[%08x]\n",
  6176. tr32(DMAC_MODE));
  6177. /* GRC block */
  6178. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6179. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6180. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6181. tr32(GRC_LOCAL_CTRL));
  6182. /* TG3_BDINFOs */
  6183. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6184. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6185. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6186. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6187. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6188. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6189. tr32(RCVDBDI_STD_BD + 0x0),
  6190. tr32(RCVDBDI_STD_BD + 0x4),
  6191. tr32(RCVDBDI_STD_BD + 0x8),
  6192. tr32(RCVDBDI_STD_BD + 0xc));
  6193. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6194. tr32(RCVDBDI_MINI_BD + 0x0),
  6195. tr32(RCVDBDI_MINI_BD + 0x4),
  6196. tr32(RCVDBDI_MINI_BD + 0x8),
  6197. tr32(RCVDBDI_MINI_BD + 0xc));
  6198. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6199. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6200. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6201. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6202. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6203. val32, val32_2, val32_3, val32_4);
  6204. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6205. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6206. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6207. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6208. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6209. val32, val32_2, val32_3, val32_4);
  6210. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6211. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6212. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6213. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6214. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6215. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6216. val32, val32_2, val32_3, val32_4, val32_5);
  6217. /* SW status block */
  6218. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6219. tp->hw_status->status,
  6220. tp->hw_status->status_tag,
  6221. tp->hw_status->rx_jumbo_consumer,
  6222. tp->hw_status->rx_consumer,
  6223. tp->hw_status->rx_mini_consumer,
  6224. tp->hw_status->idx[0].rx_producer,
  6225. tp->hw_status->idx[0].tx_consumer);
  6226. /* SW statistics block */
  6227. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6228. ((u32 *)tp->hw_stats)[0],
  6229. ((u32 *)tp->hw_stats)[1],
  6230. ((u32 *)tp->hw_stats)[2],
  6231. ((u32 *)tp->hw_stats)[3]);
  6232. /* Mailboxes */
  6233. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6234. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6235. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6236. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6237. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6238. /* NIC side send descriptors. */
  6239. for (i = 0; i < 6; i++) {
  6240. unsigned long txd;
  6241. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6242. + (i * sizeof(struct tg3_tx_buffer_desc));
  6243. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6244. i,
  6245. readl(txd + 0x0), readl(txd + 0x4),
  6246. readl(txd + 0x8), readl(txd + 0xc));
  6247. }
  6248. /* NIC side RX descriptors. */
  6249. for (i = 0; i < 6; i++) {
  6250. unsigned long rxd;
  6251. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6252. + (i * sizeof(struct tg3_rx_buffer_desc));
  6253. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6254. i,
  6255. readl(rxd + 0x0), readl(rxd + 0x4),
  6256. readl(rxd + 0x8), readl(rxd + 0xc));
  6257. rxd += (4 * sizeof(u32));
  6258. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6259. i,
  6260. readl(rxd + 0x0), readl(rxd + 0x4),
  6261. readl(rxd + 0x8), readl(rxd + 0xc));
  6262. }
  6263. for (i = 0; i < 6; i++) {
  6264. unsigned long rxd;
  6265. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6266. + (i * sizeof(struct tg3_rx_buffer_desc));
  6267. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6268. i,
  6269. readl(rxd + 0x0), readl(rxd + 0x4),
  6270. readl(rxd + 0x8), readl(rxd + 0xc));
  6271. rxd += (4 * sizeof(u32));
  6272. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6273. i,
  6274. readl(rxd + 0x0), readl(rxd + 0x4),
  6275. readl(rxd + 0x8), readl(rxd + 0xc));
  6276. }
  6277. }
  6278. #endif
  6279. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6280. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6281. static int tg3_close(struct net_device *dev)
  6282. {
  6283. struct tg3 *tp = netdev_priv(dev);
  6284. /* Calling flush_scheduled_work() may deadlock because
  6285. * linkwatch_event() may be on the workqueue and it will try to get
  6286. * the rtnl_lock which we are holding.
  6287. */
  6288. while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
  6289. msleep(1);
  6290. netif_stop_queue(dev);
  6291. del_timer_sync(&tp->timer);
  6292. tg3_full_lock(tp, 1);
  6293. #if 0
  6294. tg3_dump_state(tp);
  6295. #endif
  6296. tg3_disable_ints(tp);
  6297. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6298. tg3_free_rings(tp);
  6299. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6300. tg3_full_unlock(tp);
  6301. free_irq(tp->pdev->irq, dev);
  6302. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6303. pci_disable_msi(tp->pdev);
  6304. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6305. }
  6306. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6307. sizeof(tp->net_stats_prev));
  6308. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6309. sizeof(tp->estats_prev));
  6310. tg3_free_consistent(tp);
  6311. tg3_set_power_state(tp, PCI_D3hot);
  6312. netif_carrier_off(tp->dev);
  6313. return 0;
  6314. }
  6315. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6316. {
  6317. unsigned long ret;
  6318. #if (BITS_PER_LONG == 32)
  6319. ret = val->low;
  6320. #else
  6321. ret = ((u64)val->high << 32) | ((u64)val->low);
  6322. #endif
  6323. return ret;
  6324. }
  6325. static unsigned long calc_crc_errors(struct tg3 *tp)
  6326. {
  6327. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6328. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6329. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6330. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6331. u32 val;
  6332. spin_lock_bh(&tp->lock);
  6333. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6334. tg3_writephy(tp, MII_TG3_TEST1,
  6335. val | MII_TG3_TEST1_CRC_EN);
  6336. tg3_readphy(tp, 0x14, &val);
  6337. } else
  6338. val = 0;
  6339. spin_unlock_bh(&tp->lock);
  6340. tp->phy_crc_errors += val;
  6341. return tp->phy_crc_errors;
  6342. }
  6343. return get_stat64(&hw_stats->rx_fcs_errors);
  6344. }
  6345. #define ESTAT_ADD(member) \
  6346. estats->member = old_estats->member + \
  6347. get_stat64(&hw_stats->member)
  6348. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6349. {
  6350. struct tg3_ethtool_stats *estats = &tp->estats;
  6351. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6352. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6353. if (!hw_stats)
  6354. return old_estats;
  6355. ESTAT_ADD(rx_octets);
  6356. ESTAT_ADD(rx_fragments);
  6357. ESTAT_ADD(rx_ucast_packets);
  6358. ESTAT_ADD(rx_mcast_packets);
  6359. ESTAT_ADD(rx_bcast_packets);
  6360. ESTAT_ADD(rx_fcs_errors);
  6361. ESTAT_ADD(rx_align_errors);
  6362. ESTAT_ADD(rx_xon_pause_rcvd);
  6363. ESTAT_ADD(rx_xoff_pause_rcvd);
  6364. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6365. ESTAT_ADD(rx_xoff_entered);
  6366. ESTAT_ADD(rx_frame_too_long_errors);
  6367. ESTAT_ADD(rx_jabbers);
  6368. ESTAT_ADD(rx_undersize_packets);
  6369. ESTAT_ADD(rx_in_length_errors);
  6370. ESTAT_ADD(rx_out_length_errors);
  6371. ESTAT_ADD(rx_64_or_less_octet_packets);
  6372. ESTAT_ADD(rx_65_to_127_octet_packets);
  6373. ESTAT_ADD(rx_128_to_255_octet_packets);
  6374. ESTAT_ADD(rx_256_to_511_octet_packets);
  6375. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6376. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6377. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6378. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6379. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6380. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6381. ESTAT_ADD(tx_octets);
  6382. ESTAT_ADD(tx_collisions);
  6383. ESTAT_ADD(tx_xon_sent);
  6384. ESTAT_ADD(tx_xoff_sent);
  6385. ESTAT_ADD(tx_flow_control);
  6386. ESTAT_ADD(tx_mac_errors);
  6387. ESTAT_ADD(tx_single_collisions);
  6388. ESTAT_ADD(tx_mult_collisions);
  6389. ESTAT_ADD(tx_deferred);
  6390. ESTAT_ADD(tx_excessive_collisions);
  6391. ESTAT_ADD(tx_late_collisions);
  6392. ESTAT_ADD(tx_collide_2times);
  6393. ESTAT_ADD(tx_collide_3times);
  6394. ESTAT_ADD(tx_collide_4times);
  6395. ESTAT_ADD(tx_collide_5times);
  6396. ESTAT_ADD(tx_collide_6times);
  6397. ESTAT_ADD(tx_collide_7times);
  6398. ESTAT_ADD(tx_collide_8times);
  6399. ESTAT_ADD(tx_collide_9times);
  6400. ESTAT_ADD(tx_collide_10times);
  6401. ESTAT_ADD(tx_collide_11times);
  6402. ESTAT_ADD(tx_collide_12times);
  6403. ESTAT_ADD(tx_collide_13times);
  6404. ESTAT_ADD(tx_collide_14times);
  6405. ESTAT_ADD(tx_collide_15times);
  6406. ESTAT_ADD(tx_ucast_packets);
  6407. ESTAT_ADD(tx_mcast_packets);
  6408. ESTAT_ADD(tx_bcast_packets);
  6409. ESTAT_ADD(tx_carrier_sense_errors);
  6410. ESTAT_ADD(tx_discards);
  6411. ESTAT_ADD(tx_errors);
  6412. ESTAT_ADD(dma_writeq_full);
  6413. ESTAT_ADD(dma_write_prioq_full);
  6414. ESTAT_ADD(rxbds_empty);
  6415. ESTAT_ADD(rx_discards);
  6416. ESTAT_ADD(rx_errors);
  6417. ESTAT_ADD(rx_threshold_hit);
  6418. ESTAT_ADD(dma_readq_full);
  6419. ESTAT_ADD(dma_read_prioq_full);
  6420. ESTAT_ADD(tx_comp_queue_full);
  6421. ESTAT_ADD(ring_set_send_prod_index);
  6422. ESTAT_ADD(ring_status_update);
  6423. ESTAT_ADD(nic_irqs);
  6424. ESTAT_ADD(nic_avoided_irqs);
  6425. ESTAT_ADD(nic_tx_threshold_hit);
  6426. return estats;
  6427. }
  6428. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6429. {
  6430. struct tg3 *tp = netdev_priv(dev);
  6431. struct net_device_stats *stats = &tp->net_stats;
  6432. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6433. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6434. if (!hw_stats)
  6435. return old_stats;
  6436. stats->rx_packets = old_stats->rx_packets +
  6437. get_stat64(&hw_stats->rx_ucast_packets) +
  6438. get_stat64(&hw_stats->rx_mcast_packets) +
  6439. get_stat64(&hw_stats->rx_bcast_packets);
  6440. stats->tx_packets = old_stats->tx_packets +
  6441. get_stat64(&hw_stats->tx_ucast_packets) +
  6442. get_stat64(&hw_stats->tx_mcast_packets) +
  6443. get_stat64(&hw_stats->tx_bcast_packets);
  6444. stats->rx_bytes = old_stats->rx_bytes +
  6445. get_stat64(&hw_stats->rx_octets);
  6446. stats->tx_bytes = old_stats->tx_bytes +
  6447. get_stat64(&hw_stats->tx_octets);
  6448. stats->rx_errors = old_stats->rx_errors +
  6449. get_stat64(&hw_stats->rx_errors);
  6450. stats->tx_errors = old_stats->tx_errors +
  6451. get_stat64(&hw_stats->tx_errors) +
  6452. get_stat64(&hw_stats->tx_mac_errors) +
  6453. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6454. get_stat64(&hw_stats->tx_discards);
  6455. stats->multicast = old_stats->multicast +
  6456. get_stat64(&hw_stats->rx_mcast_packets);
  6457. stats->collisions = old_stats->collisions +
  6458. get_stat64(&hw_stats->tx_collisions);
  6459. stats->rx_length_errors = old_stats->rx_length_errors +
  6460. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6461. get_stat64(&hw_stats->rx_undersize_packets);
  6462. stats->rx_over_errors = old_stats->rx_over_errors +
  6463. get_stat64(&hw_stats->rxbds_empty);
  6464. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6465. get_stat64(&hw_stats->rx_align_errors);
  6466. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6467. get_stat64(&hw_stats->tx_discards);
  6468. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6469. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6470. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6471. calc_crc_errors(tp);
  6472. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6473. get_stat64(&hw_stats->rx_discards);
  6474. return stats;
  6475. }
  6476. static inline u32 calc_crc(unsigned char *buf, int len)
  6477. {
  6478. u32 reg;
  6479. u32 tmp;
  6480. int j, k;
  6481. reg = 0xffffffff;
  6482. for (j = 0; j < len; j++) {
  6483. reg ^= buf[j];
  6484. for (k = 0; k < 8; k++) {
  6485. tmp = reg & 0x01;
  6486. reg >>= 1;
  6487. if (tmp) {
  6488. reg ^= 0xedb88320;
  6489. }
  6490. }
  6491. }
  6492. return ~reg;
  6493. }
  6494. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6495. {
  6496. /* accept or reject all multicast frames */
  6497. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6498. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6499. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6500. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6501. }
  6502. static void __tg3_set_rx_mode(struct net_device *dev)
  6503. {
  6504. struct tg3 *tp = netdev_priv(dev);
  6505. u32 rx_mode;
  6506. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6507. RX_MODE_KEEP_VLAN_TAG);
  6508. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6509. * flag clear.
  6510. */
  6511. #if TG3_VLAN_TAG_USED
  6512. if (!tp->vlgrp &&
  6513. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6514. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6515. #else
  6516. /* By definition, VLAN is disabled always in this
  6517. * case.
  6518. */
  6519. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6520. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6521. #endif
  6522. if (dev->flags & IFF_PROMISC) {
  6523. /* Promiscuous mode. */
  6524. rx_mode |= RX_MODE_PROMISC;
  6525. } else if (dev->flags & IFF_ALLMULTI) {
  6526. /* Accept all multicast. */
  6527. tg3_set_multi (tp, 1);
  6528. } else if (dev->mc_count < 1) {
  6529. /* Reject all multicast. */
  6530. tg3_set_multi (tp, 0);
  6531. } else {
  6532. /* Accept one or more multicast(s). */
  6533. struct dev_mc_list *mclist;
  6534. unsigned int i;
  6535. u32 mc_filter[4] = { 0, };
  6536. u32 regidx;
  6537. u32 bit;
  6538. u32 crc;
  6539. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6540. i++, mclist = mclist->next) {
  6541. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6542. bit = ~crc & 0x7f;
  6543. regidx = (bit & 0x60) >> 5;
  6544. bit &= 0x1f;
  6545. mc_filter[regidx] |= (1 << bit);
  6546. }
  6547. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6548. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6549. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6550. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6551. }
  6552. if (rx_mode != tp->rx_mode) {
  6553. tp->rx_mode = rx_mode;
  6554. tw32_f(MAC_RX_MODE, rx_mode);
  6555. udelay(10);
  6556. }
  6557. }
  6558. static void tg3_set_rx_mode(struct net_device *dev)
  6559. {
  6560. struct tg3 *tp = netdev_priv(dev);
  6561. if (!netif_running(dev))
  6562. return;
  6563. tg3_full_lock(tp, 0);
  6564. __tg3_set_rx_mode(dev);
  6565. tg3_full_unlock(tp);
  6566. }
  6567. #define TG3_REGDUMP_LEN (32 * 1024)
  6568. static int tg3_get_regs_len(struct net_device *dev)
  6569. {
  6570. return TG3_REGDUMP_LEN;
  6571. }
  6572. static void tg3_get_regs(struct net_device *dev,
  6573. struct ethtool_regs *regs, void *_p)
  6574. {
  6575. u32 *p = _p;
  6576. struct tg3 *tp = netdev_priv(dev);
  6577. u8 *orig_p = _p;
  6578. int i;
  6579. regs->version = 0;
  6580. memset(p, 0, TG3_REGDUMP_LEN);
  6581. if (tp->link_config.phy_is_low_power)
  6582. return;
  6583. tg3_full_lock(tp, 0);
  6584. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6585. #define GET_REG32_LOOP(base,len) \
  6586. do { p = (u32 *)(orig_p + (base)); \
  6587. for (i = 0; i < len; i += 4) \
  6588. __GET_REG32((base) + i); \
  6589. } while (0)
  6590. #define GET_REG32_1(reg) \
  6591. do { p = (u32 *)(orig_p + (reg)); \
  6592. __GET_REG32((reg)); \
  6593. } while (0)
  6594. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6595. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6596. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6597. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6598. GET_REG32_1(SNDDATAC_MODE);
  6599. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6600. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6601. GET_REG32_1(SNDBDC_MODE);
  6602. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6603. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6604. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6605. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6606. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6607. GET_REG32_1(RCVDCC_MODE);
  6608. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6609. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6610. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6611. GET_REG32_1(MBFREE_MODE);
  6612. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6613. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6614. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6615. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6616. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6617. GET_REG32_1(RX_CPU_MODE);
  6618. GET_REG32_1(RX_CPU_STATE);
  6619. GET_REG32_1(RX_CPU_PGMCTR);
  6620. GET_REG32_1(RX_CPU_HWBKPT);
  6621. GET_REG32_1(TX_CPU_MODE);
  6622. GET_REG32_1(TX_CPU_STATE);
  6623. GET_REG32_1(TX_CPU_PGMCTR);
  6624. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6625. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6626. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6627. GET_REG32_1(DMAC_MODE);
  6628. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6629. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6630. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6631. #undef __GET_REG32
  6632. #undef GET_REG32_LOOP
  6633. #undef GET_REG32_1
  6634. tg3_full_unlock(tp);
  6635. }
  6636. static int tg3_get_eeprom_len(struct net_device *dev)
  6637. {
  6638. struct tg3 *tp = netdev_priv(dev);
  6639. return tp->nvram_size;
  6640. }
  6641. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6642. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6643. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6644. {
  6645. struct tg3 *tp = netdev_priv(dev);
  6646. int ret;
  6647. u8 *pd;
  6648. u32 i, offset, len, val, b_offset, b_count;
  6649. if (tp->link_config.phy_is_low_power)
  6650. return -EAGAIN;
  6651. offset = eeprom->offset;
  6652. len = eeprom->len;
  6653. eeprom->len = 0;
  6654. eeprom->magic = TG3_EEPROM_MAGIC;
  6655. if (offset & 3) {
  6656. /* adjustments to start on required 4 byte boundary */
  6657. b_offset = offset & 3;
  6658. b_count = 4 - b_offset;
  6659. if (b_count > len) {
  6660. /* i.e. offset=1 len=2 */
  6661. b_count = len;
  6662. }
  6663. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6664. if (ret)
  6665. return ret;
  6666. val = cpu_to_le32(val);
  6667. memcpy(data, ((char*)&val) + b_offset, b_count);
  6668. len -= b_count;
  6669. offset += b_count;
  6670. eeprom->len += b_count;
  6671. }
  6672. /* read bytes upto the last 4 byte boundary */
  6673. pd = &data[eeprom->len];
  6674. for (i = 0; i < (len - (len & 3)); i += 4) {
  6675. ret = tg3_nvram_read(tp, offset + i, &val);
  6676. if (ret) {
  6677. eeprom->len += i;
  6678. return ret;
  6679. }
  6680. val = cpu_to_le32(val);
  6681. memcpy(pd + i, &val, 4);
  6682. }
  6683. eeprom->len += i;
  6684. if (len & 3) {
  6685. /* read last bytes not ending on 4 byte boundary */
  6686. pd = &data[eeprom->len];
  6687. b_count = len & 3;
  6688. b_offset = offset + len - b_count;
  6689. ret = tg3_nvram_read(tp, b_offset, &val);
  6690. if (ret)
  6691. return ret;
  6692. val = cpu_to_le32(val);
  6693. memcpy(pd, ((char*)&val), b_count);
  6694. eeprom->len += b_count;
  6695. }
  6696. return 0;
  6697. }
  6698. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6699. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6700. {
  6701. struct tg3 *tp = netdev_priv(dev);
  6702. int ret;
  6703. u32 offset, len, b_offset, odd_len, start, end;
  6704. u8 *buf;
  6705. if (tp->link_config.phy_is_low_power)
  6706. return -EAGAIN;
  6707. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6708. return -EINVAL;
  6709. offset = eeprom->offset;
  6710. len = eeprom->len;
  6711. if ((b_offset = (offset & 3))) {
  6712. /* adjustments to start on required 4 byte boundary */
  6713. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6714. if (ret)
  6715. return ret;
  6716. start = cpu_to_le32(start);
  6717. len += b_offset;
  6718. offset &= ~3;
  6719. if (len < 4)
  6720. len = 4;
  6721. }
  6722. odd_len = 0;
  6723. if (len & 3) {
  6724. /* adjustments to end on required 4 byte boundary */
  6725. odd_len = 1;
  6726. len = (len + 3) & ~3;
  6727. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6728. if (ret)
  6729. return ret;
  6730. end = cpu_to_le32(end);
  6731. }
  6732. buf = data;
  6733. if (b_offset || odd_len) {
  6734. buf = kmalloc(len, GFP_KERNEL);
  6735. if (buf == 0)
  6736. return -ENOMEM;
  6737. if (b_offset)
  6738. memcpy(buf, &start, 4);
  6739. if (odd_len)
  6740. memcpy(buf+len-4, &end, 4);
  6741. memcpy(buf + b_offset, data, eeprom->len);
  6742. }
  6743. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6744. if (buf != data)
  6745. kfree(buf);
  6746. return ret;
  6747. }
  6748. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6749. {
  6750. struct tg3 *tp = netdev_priv(dev);
  6751. cmd->supported = (SUPPORTED_Autoneg);
  6752. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6753. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6754. SUPPORTED_1000baseT_Full);
  6755. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6756. cmd->supported |= (SUPPORTED_100baseT_Half |
  6757. SUPPORTED_100baseT_Full |
  6758. SUPPORTED_10baseT_Half |
  6759. SUPPORTED_10baseT_Full |
  6760. SUPPORTED_MII);
  6761. cmd->port = PORT_TP;
  6762. } else {
  6763. cmd->supported |= SUPPORTED_FIBRE;
  6764. cmd->port = PORT_FIBRE;
  6765. }
  6766. cmd->advertising = tp->link_config.advertising;
  6767. if (netif_running(dev)) {
  6768. cmd->speed = tp->link_config.active_speed;
  6769. cmd->duplex = tp->link_config.active_duplex;
  6770. }
  6771. cmd->phy_address = PHY_ADDR;
  6772. cmd->transceiver = 0;
  6773. cmd->autoneg = tp->link_config.autoneg;
  6774. cmd->maxtxpkt = 0;
  6775. cmd->maxrxpkt = 0;
  6776. return 0;
  6777. }
  6778. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6779. {
  6780. struct tg3 *tp = netdev_priv(dev);
  6781. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6782. /* These are the only valid advertisement bits allowed. */
  6783. if (cmd->autoneg == AUTONEG_ENABLE &&
  6784. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6785. ADVERTISED_1000baseT_Full |
  6786. ADVERTISED_Autoneg |
  6787. ADVERTISED_FIBRE)))
  6788. return -EINVAL;
  6789. /* Fiber can only do SPEED_1000. */
  6790. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6791. (cmd->speed != SPEED_1000))
  6792. return -EINVAL;
  6793. /* Copper cannot force SPEED_1000. */
  6794. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6795. (cmd->speed == SPEED_1000))
  6796. return -EINVAL;
  6797. else if ((cmd->speed == SPEED_1000) &&
  6798. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6799. return -EINVAL;
  6800. tg3_full_lock(tp, 0);
  6801. tp->link_config.autoneg = cmd->autoneg;
  6802. if (cmd->autoneg == AUTONEG_ENABLE) {
  6803. tp->link_config.advertising = cmd->advertising;
  6804. tp->link_config.speed = SPEED_INVALID;
  6805. tp->link_config.duplex = DUPLEX_INVALID;
  6806. } else {
  6807. tp->link_config.advertising = 0;
  6808. tp->link_config.speed = cmd->speed;
  6809. tp->link_config.duplex = cmd->duplex;
  6810. }
  6811. tp->link_config.orig_speed = tp->link_config.speed;
  6812. tp->link_config.orig_duplex = tp->link_config.duplex;
  6813. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  6814. if (netif_running(dev))
  6815. tg3_setup_phy(tp, 1);
  6816. tg3_full_unlock(tp);
  6817. return 0;
  6818. }
  6819. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6820. {
  6821. struct tg3 *tp = netdev_priv(dev);
  6822. strcpy(info->driver, DRV_MODULE_NAME);
  6823. strcpy(info->version, DRV_MODULE_VERSION);
  6824. strcpy(info->fw_version, tp->fw_ver);
  6825. strcpy(info->bus_info, pci_name(tp->pdev));
  6826. }
  6827. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6828. {
  6829. struct tg3 *tp = netdev_priv(dev);
  6830. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  6831. wol->supported = WAKE_MAGIC;
  6832. else
  6833. wol->supported = 0;
  6834. wol->wolopts = 0;
  6835. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6836. wol->wolopts = WAKE_MAGIC;
  6837. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6838. }
  6839. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6840. {
  6841. struct tg3 *tp = netdev_priv(dev);
  6842. if (wol->wolopts & ~WAKE_MAGIC)
  6843. return -EINVAL;
  6844. if ((wol->wolopts & WAKE_MAGIC) &&
  6845. !(tp->tg3_flags & TG3_FLAG_WOL_CAP))
  6846. return -EINVAL;
  6847. spin_lock_bh(&tp->lock);
  6848. if (wol->wolopts & WAKE_MAGIC)
  6849. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6850. else
  6851. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6852. spin_unlock_bh(&tp->lock);
  6853. return 0;
  6854. }
  6855. static u32 tg3_get_msglevel(struct net_device *dev)
  6856. {
  6857. struct tg3 *tp = netdev_priv(dev);
  6858. return tp->msg_enable;
  6859. }
  6860. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6861. {
  6862. struct tg3 *tp = netdev_priv(dev);
  6863. tp->msg_enable = value;
  6864. }
  6865. static int tg3_set_tso(struct net_device *dev, u32 value)
  6866. {
  6867. struct tg3 *tp = netdev_priv(dev);
  6868. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6869. if (value)
  6870. return -EINVAL;
  6871. return 0;
  6872. }
  6873. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  6874. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  6875. if (value)
  6876. dev->features |= NETIF_F_TSO6;
  6877. else
  6878. dev->features &= ~NETIF_F_TSO6;
  6879. }
  6880. return ethtool_op_set_tso(dev, value);
  6881. }
  6882. static int tg3_nway_reset(struct net_device *dev)
  6883. {
  6884. struct tg3 *tp = netdev_priv(dev);
  6885. u32 bmcr;
  6886. int r;
  6887. if (!netif_running(dev))
  6888. return -EAGAIN;
  6889. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6890. return -EINVAL;
  6891. spin_lock_bh(&tp->lock);
  6892. r = -EINVAL;
  6893. tg3_readphy(tp, MII_BMCR, &bmcr);
  6894. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6895. ((bmcr & BMCR_ANENABLE) ||
  6896. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6897. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6898. BMCR_ANENABLE);
  6899. r = 0;
  6900. }
  6901. spin_unlock_bh(&tp->lock);
  6902. return r;
  6903. }
  6904. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6905. {
  6906. struct tg3 *tp = netdev_priv(dev);
  6907. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6908. ering->rx_mini_max_pending = 0;
  6909. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6910. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6911. else
  6912. ering->rx_jumbo_max_pending = 0;
  6913. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6914. ering->rx_pending = tp->rx_pending;
  6915. ering->rx_mini_pending = 0;
  6916. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6917. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6918. else
  6919. ering->rx_jumbo_pending = 0;
  6920. ering->tx_pending = tp->tx_pending;
  6921. }
  6922. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6923. {
  6924. struct tg3 *tp = netdev_priv(dev);
  6925. int irq_sync = 0, err = 0;
  6926. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6927. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6928. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  6929. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  6930. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  6931. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  6932. return -EINVAL;
  6933. if (netif_running(dev)) {
  6934. tg3_netif_stop(tp);
  6935. irq_sync = 1;
  6936. }
  6937. tg3_full_lock(tp, irq_sync);
  6938. tp->rx_pending = ering->rx_pending;
  6939. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6940. tp->rx_pending > 63)
  6941. tp->rx_pending = 63;
  6942. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6943. tp->tx_pending = ering->tx_pending;
  6944. if (netif_running(dev)) {
  6945. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6946. err = tg3_restart_hw(tp, 1);
  6947. if (!err)
  6948. tg3_netif_start(tp);
  6949. }
  6950. tg3_full_unlock(tp);
  6951. return err;
  6952. }
  6953. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6954. {
  6955. struct tg3 *tp = netdev_priv(dev);
  6956. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  6957. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  6958. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  6959. }
  6960. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6961. {
  6962. struct tg3 *tp = netdev_priv(dev);
  6963. int irq_sync = 0, err = 0;
  6964. if (netif_running(dev)) {
  6965. tg3_netif_stop(tp);
  6966. irq_sync = 1;
  6967. }
  6968. tg3_full_lock(tp, irq_sync);
  6969. if (epause->autoneg)
  6970. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  6971. else
  6972. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  6973. if (epause->rx_pause)
  6974. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  6975. else
  6976. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  6977. if (epause->tx_pause)
  6978. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  6979. else
  6980. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  6981. if (netif_running(dev)) {
  6982. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6983. err = tg3_restart_hw(tp, 1);
  6984. if (!err)
  6985. tg3_netif_start(tp);
  6986. }
  6987. tg3_full_unlock(tp);
  6988. return err;
  6989. }
  6990. static u32 tg3_get_rx_csum(struct net_device *dev)
  6991. {
  6992. struct tg3 *tp = netdev_priv(dev);
  6993. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  6994. }
  6995. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  6996. {
  6997. struct tg3 *tp = netdev_priv(dev);
  6998. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  6999. if (data != 0)
  7000. return -EINVAL;
  7001. return 0;
  7002. }
  7003. spin_lock_bh(&tp->lock);
  7004. if (data)
  7005. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7006. else
  7007. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7008. spin_unlock_bh(&tp->lock);
  7009. return 0;
  7010. }
  7011. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7012. {
  7013. struct tg3 *tp = netdev_priv(dev);
  7014. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7015. if (data != 0)
  7016. return -EINVAL;
  7017. return 0;
  7018. }
  7019. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7020. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7021. ethtool_op_set_tx_hw_csum(dev, data);
  7022. else
  7023. ethtool_op_set_tx_csum(dev, data);
  7024. return 0;
  7025. }
  7026. static int tg3_get_stats_count (struct net_device *dev)
  7027. {
  7028. return TG3_NUM_STATS;
  7029. }
  7030. static int tg3_get_test_count (struct net_device *dev)
  7031. {
  7032. return TG3_NUM_TEST;
  7033. }
  7034. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7035. {
  7036. switch (stringset) {
  7037. case ETH_SS_STATS:
  7038. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7039. break;
  7040. case ETH_SS_TEST:
  7041. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7042. break;
  7043. default:
  7044. WARN_ON(1); /* we need a WARN() */
  7045. break;
  7046. }
  7047. }
  7048. static int tg3_phys_id(struct net_device *dev, u32 data)
  7049. {
  7050. struct tg3 *tp = netdev_priv(dev);
  7051. int i;
  7052. if (!netif_running(tp->dev))
  7053. return -EAGAIN;
  7054. if (data == 0)
  7055. data = 2;
  7056. for (i = 0; i < (data * 2); i++) {
  7057. if ((i % 2) == 0)
  7058. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7059. LED_CTRL_1000MBPS_ON |
  7060. LED_CTRL_100MBPS_ON |
  7061. LED_CTRL_10MBPS_ON |
  7062. LED_CTRL_TRAFFIC_OVERRIDE |
  7063. LED_CTRL_TRAFFIC_BLINK |
  7064. LED_CTRL_TRAFFIC_LED);
  7065. else
  7066. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7067. LED_CTRL_TRAFFIC_OVERRIDE);
  7068. if (msleep_interruptible(500))
  7069. break;
  7070. }
  7071. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7072. return 0;
  7073. }
  7074. static void tg3_get_ethtool_stats (struct net_device *dev,
  7075. struct ethtool_stats *estats, u64 *tmp_stats)
  7076. {
  7077. struct tg3 *tp = netdev_priv(dev);
  7078. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7079. }
  7080. #define NVRAM_TEST_SIZE 0x100
  7081. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  7082. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7083. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7084. static int tg3_test_nvram(struct tg3 *tp)
  7085. {
  7086. u32 *buf, csum, magic;
  7087. int i, j, err = 0, size;
  7088. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7089. return -EIO;
  7090. if (magic == TG3_EEPROM_MAGIC)
  7091. size = NVRAM_TEST_SIZE;
  7092. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7093. if ((magic & 0xe00000) == 0x200000)
  7094. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  7095. else
  7096. return 0;
  7097. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7098. size = NVRAM_SELFBOOT_HW_SIZE;
  7099. else
  7100. return -EIO;
  7101. buf = kmalloc(size, GFP_KERNEL);
  7102. if (buf == NULL)
  7103. return -ENOMEM;
  7104. err = -EIO;
  7105. for (i = 0, j = 0; i < size; i += 4, j++) {
  7106. u32 val;
  7107. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7108. break;
  7109. buf[j] = cpu_to_le32(val);
  7110. }
  7111. if (i < size)
  7112. goto out;
  7113. /* Selfboot format */
  7114. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
  7115. TG3_EEPROM_MAGIC_FW) {
  7116. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7117. for (i = 0; i < size; i++)
  7118. csum8 += buf8[i];
  7119. if (csum8 == 0) {
  7120. err = 0;
  7121. goto out;
  7122. }
  7123. err = -EIO;
  7124. goto out;
  7125. }
  7126. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
  7127. TG3_EEPROM_MAGIC_HW) {
  7128. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7129. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7130. u8 *buf8 = (u8 *) buf;
  7131. int j, k;
  7132. /* Separate the parity bits and the data bytes. */
  7133. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7134. if ((i == 0) || (i == 8)) {
  7135. int l;
  7136. u8 msk;
  7137. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7138. parity[k++] = buf8[i] & msk;
  7139. i++;
  7140. }
  7141. else if (i == 16) {
  7142. int l;
  7143. u8 msk;
  7144. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7145. parity[k++] = buf8[i] & msk;
  7146. i++;
  7147. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7148. parity[k++] = buf8[i] & msk;
  7149. i++;
  7150. }
  7151. data[j++] = buf8[i];
  7152. }
  7153. err = -EIO;
  7154. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7155. u8 hw8 = hweight8(data[i]);
  7156. if ((hw8 & 0x1) && parity[i])
  7157. goto out;
  7158. else if (!(hw8 & 0x1) && !parity[i])
  7159. goto out;
  7160. }
  7161. err = 0;
  7162. goto out;
  7163. }
  7164. /* Bootstrap checksum at offset 0x10 */
  7165. csum = calc_crc((unsigned char *) buf, 0x10);
  7166. if(csum != cpu_to_le32(buf[0x10/4]))
  7167. goto out;
  7168. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7169. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7170. if (csum != cpu_to_le32(buf[0xfc/4]))
  7171. goto out;
  7172. err = 0;
  7173. out:
  7174. kfree(buf);
  7175. return err;
  7176. }
  7177. #define TG3_SERDES_TIMEOUT_SEC 2
  7178. #define TG3_COPPER_TIMEOUT_SEC 6
  7179. static int tg3_test_link(struct tg3 *tp)
  7180. {
  7181. int i, max;
  7182. if (!netif_running(tp->dev))
  7183. return -ENODEV;
  7184. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7185. max = TG3_SERDES_TIMEOUT_SEC;
  7186. else
  7187. max = TG3_COPPER_TIMEOUT_SEC;
  7188. for (i = 0; i < max; i++) {
  7189. if (netif_carrier_ok(tp->dev))
  7190. return 0;
  7191. if (msleep_interruptible(1000))
  7192. break;
  7193. }
  7194. return -EIO;
  7195. }
  7196. /* Only test the commonly used registers */
  7197. static int tg3_test_registers(struct tg3 *tp)
  7198. {
  7199. int i, is_5705, is_5750;
  7200. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7201. static struct {
  7202. u16 offset;
  7203. u16 flags;
  7204. #define TG3_FL_5705 0x1
  7205. #define TG3_FL_NOT_5705 0x2
  7206. #define TG3_FL_NOT_5788 0x4
  7207. #define TG3_FL_NOT_5750 0x8
  7208. u32 read_mask;
  7209. u32 write_mask;
  7210. } reg_tbl[] = {
  7211. /* MAC Control Registers */
  7212. { MAC_MODE, TG3_FL_NOT_5705,
  7213. 0x00000000, 0x00ef6f8c },
  7214. { MAC_MODE, TG3_FL_5705,
  7215. 0x00000000, 0x01ef6b8c },
  7216. { MAC_STATUS, TG3_FL_NOT_5705,
  7217. 0x03800107, 0x00000000 },
  7218. { MAC_STATUS, TG3_FL_5705,
  7219. 0x03800100, 0x00000000 },
  7220. { MAC_ADDR_0_HIGH, 0x0000,
  7221. 0x00000000, 0x0000ffff },
  7222. { MAC_ADDR_0_LOW, 0x0000,
  7223. 0x00000000, 0xffffffff },
  7224. { MAC_RX_MTU_SIZE, 0x0000,
  7225. 0x00000000, 0x0000ffff },
  7226. { MAC_TX_MODE, 0x0000,
  7227. 0x00000000, 0x00000070 },
  7228. { MAC_TX_LENGTHS, 0x0000,
  7229. 0x00000000, 0x00003fff },
  7230. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7231. 0x00000000, 0x000007fc },
  7232. { MAC_RX_MODE, TG3_FL_5705,
  7233. 0x00000000, 0x000007dc },
  7234. { MAC_HASH_REG_0, 0x0000,
  7235. 0x00000000, 0xffffffff },
  7236. { MAC_HASH_REG_1, 0x0000,
  7237. 0x00000000, 0xffffffff },
  7238. { MAC_HASH_REG_2, 0x0000,
  7239. 0x00000000, 0xffffffff },
  7240. { MAC_HASH_REG_3, 0x0000,
  7241. 0x00000000, 0xffffffff },
  7242. /* Receive Data and Receive BD Initiator Control Registers. */
  7243. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7244. 0x00000000, 0xffffffff },
  7245. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7246. 0x00000000, 0xffffffff },
  7247. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7248. 0x00000000, 0x00000003 },
  7249. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7250. 0x00000000, 0xffffffff },
  7251. { RCVDBDI_STD_BD+0, 0x0000,
  7252. 0x00000000, 0xffffffff },
  7253. { RCVDBDI_STD_BD+4, 0x0000,
  7254. 0x00000000, 0xffffffff },
  7255. { RCVDBDI_STD_BD+8, 0x0000,
  7256. 0x00000000, 0xffff0002 },
  7257. { RCVDBDI_STD_BD+0xc, 0x0000,
  7258. 0x00000000, 0xffffffff },
  7259. /* Receive BD Initiator Control Registers. */
  7260. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7261. 0x00000000, 0xffffffff },
  7262. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7263. 0x00000000, 0x000003ff },
  7264. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7265. 0x00000000, 0xffffffff },
  7266. /* Host Coalescing Control Registers. */
  7267. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7268. 0x00000000, 0x00000004 },
  7269. { HOSTCC_MODE, TG3_FL_5705,
  7270. 0x00000000, 0x000000f6 },
  7271. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7272. 0x00000000, 0xffffffff },
  7273. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7274. 0x00000000, 0x000003ff },
  7275. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7276. 0x00000000, 0xffffffff },
  7277. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7278. 0x00000000, 0x000003ff },
  7279. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7280. 0x00000000, 0xffffffff },
  7281. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7282. 0x00000000, 0x000000ff },
  7283. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7284. 0x00000000, 0xffffffff },
  7285. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7286. 0x00000000, 0x000000ff },
  7287. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7288. 0x00000000, 0xffffffff },
  7289. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7290. 0x00000000, 0xffffffff },
  7291. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7292. 0x00000000, 0xffffffff },
  7293. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7294. 0x00000000, 0x000000ff },
  7295. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7296. 0x00000000, 0xffffffff },
  7297. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7298. 0x00000000, 0x000000ff },
  7299. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7300. 0x00000000, 0xffffffff },
  7301. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7302. 0x00000000, 0xffffffff },
  7303. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7304. 0x00000000, 0xffffffff },
  7305. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7306. 0x00000000, 0xffffffff },
  7307. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7308. 0x00000000, 0xffffffff },
  7309. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7310. 0xffffffff, 0x00000000 },
  7311. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7312. 0xffffffff, 0x00000000 },
  7313. /* Buffer Manager Control Registers. */
  7314. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7315. 0x00000000, 0x007fff80 },
  7316. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7317. 0x00000000, 0x007fffff },
  7318. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7319. 0x00000000, 0x0000003f },
  7320. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7321. 0x00000000, 0x000001ff },
  7322. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7323. 0x00000000, 0x000001ff },
  7324. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7325. 0xffffffff, 0x00000000 },
  7326. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7327. 0xffffffff, 0x00000000 },
  7328. /* Mailbox Registers */
  7329. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7330. 0x00000000, 0x000001ff },
  7331. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7332. 0x00000000, 0x000001ff },
  7333. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7334. 0x00000000, 0x000007ff },
  7335. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7336. 0x00000000, 0x000001ff },
  7337. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7338. };
  7339. is_5705 = is_5750 = 0;
  7340. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7341. is_5705 = 1;
  7342. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7343. is_5750 = 1;
  7344. }
  7345. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7346. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7347. continue;
  7348. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7349. continue;
  7350. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7351. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7352. continue;
  7353. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7354. continue;
  7355. offset = (u32) reg_tbl[i].offset;
  7356. read_mask = reg_tbl[i].read_mask;
  7357. write_mask = reg_tbl[i].write_mask;
  7358. /* Save the original register content */
  7359. save_val = tr32(offset);
  7360. /* Determine the read-only value. */
  7361. read_val = save_val & read_mask;
  7362. /* Write zero to the register, then make sure the read-only bits
  7363. * are not changed and the read/write bits are all zeros.
  7364. */
  7365. tw32(offset, 0);
  7366. val = tr32(offset);
  7367. /* Test the read-only and read/write bits. */
  7368. if (((val & read_mask) != read_val) || (val & write_mask))
  7369. goto out;
  7370. /* Write ones to all the bits defined by RdMask and WrMask, then
  7371. * make sure the read-only bits are not changed and the
  7372. * read/write bits are all ones.
  7373. */
  7374. tw32(offset, read_mask | write_mask);
  7375. val = tr32(offset);
  7376. /* Test the read-only bits. */
  7377. if ((val & read_mask) != read_val)
  7378. goto out;
  7379. /* Test the read/write bits. */
  7380. if ((val & write_mask) != write_mask)
  7381. goto out;
  7382. tw32(offset, save_val);
  7383. }
  7384. return 0;
  7385. out:
  7386. if (netif_msg_hw(tp))
  7387. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7388. offset);
  7389. tw32(offset, save_val);
  7390. return -EIO;
  7391. }
  7392. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7393. {
  7394. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7395. int i;
  7396. u32 j;
  7397. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7398. for (j = 0; j < len; j += 4) {
  7399. u32 val;
  7400. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7401. tg3_read_mem(tp, offset + j, &val);
  7402. if (val != test_pattern[i])
  7403. return -EIO;
  7404. }
  7405. }
  7406. return 0;
  7407. }
  7408. static int tg3_test_memory(struct tg3 *tp)
  7409. {
  7410. static struct mem_entry {
  7411. u32 offset;
  7412. u32 len;
  7413. } mem_tbl_570x[] = {
  7414. { 0x00000000, 0x00b50},
  7415. { 0x00002000, 0x1c000},
  7416. { 0xffffffff, 0x00000}
  7417. }, mem_tbl_5705[] = {
  7418. { 0x00000100, 0x0000c},
  7419. { 0x00000200, 0x00008},
  7420. { 0x00004000, 0x00800},
  7421. { 0x00006000, 0x01000},
  7422. { 0x00008000, 0x02000},
  7423. { 0x00010000, 0x0e000},
  7424. { 0xffffffff, 0x00000}
  7425. }, mem_tbl_5755[] = {
  7426. { 0x00000200, 0x00008},
  7427. { 0x00004000, 0x00800},
  7428. { 0x00006000, 0x00800},
  7429. { 0x00008000, 0x02000},
  7430. { 0x00010000, 0x0c000},
  7431. { 0xffffffff, 0x00000}
  7432. }, mem_tbl_5906[] = {
  7433. { 0x00000200, 0x00008},
  7434. { 0x00004000, 0x00400},
  7435. { 0x00006000, 0x00400},
  7436. { 0x00008000, 0x01000},
  7437. { 0x00010000, 0x01000},
  7438. { 0xffffffff, 0x00000}
  7439. };
  7440. struct mem_entry *mem_tbl;
  7441. int err = 0;
  7442. int i;
  7443. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7444. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7445. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7446. mem_tbl = mem_tbl_5755;
  7447. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7448. mem_tbl = mem_tbl_5906;
  7449. else
  7450. mem_tbl = mem_tbl_5705;
  7451. } else
  7452. mem_tbl = mem_tbl_570x;
  7453. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7454. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7455. mem_tbl[i].len)) != 0)
  7456. break;
  7457. }
  7458. return err;
  7459. }
  7460. #define TG3_MAC_LOOPBACK 0
  7461. #define TG3_PHY_LOOPBACK 1
  7462. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7463. {
  7464. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7465. u32 desc_idx;
  7466. struct sk_buff *skb, *rx_skb;
  7467. u8 *tx_data;
  7468. dma_addr_t map;
  7469. int num_pkts, tx_len, rx_len, i, err;
  7470. struct tg3_rx_buffer_desc *desc;
  7471. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7472. /* HW errata - mac loopback fails in some cases on 5780.
  7473. * Normal traffic and PHY loopback are not affected by
  7474. * errata.
  7475. */
  7476. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7477. return 0;
  7478. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7479. MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
  7480. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7481. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7482. else
  7483. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7484. tw32(MAC_MODE, mac_mode);
  7485. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7486. u32 val;
  7487. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7488. u32 phytest;
  7489. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7490. u32 phy;
  7491. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7492. phytest | MII_TG3_EPHY_SHADOW_EN);
  7493. if (!tg3_readphy(tp, 0x1b, &phy))
  7494. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7495. if (!tg3_readphy(tp, 0x10, &phy))
  7496. tg3_writephy(tp, 0x10, phy & ~0x4000);
  7497. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7498. }
  7499. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7500. } else
  7501. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7502. tg3_writephy(tp, MII_BMCR, val);
  7503. udelay(40);
  7504. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7505. MAC_MODE_LINK_POLARITY;
  7506. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7507. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7508. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7509. } else
  7510. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7511. /* reset to prevent losing 1st rx packet intermittently */
  7512. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7513. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7514. udelay(10);
  7515. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7516. }
  7517. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  7518. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7519. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7520. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7521. }
  7522. tw32(MAC_MODE, mac_mode);
  7523. }
  7524. else
  7525. return -EINVAL;
  7526. err = -EIO;
  7527. tx_len = 1514;
  7528. skb = netdev_alloc_skb(tp->dev, tx_len);
  7529. if (!skb)
  7530. return -ENOMEM;
  7531. tx_data = skb_put(skb, tx_len);
  7532. memcpy(tx_data, tp->dev->dev_addr, 6);
  7533. memset(tx_data + 6, 0x0, 8);
  7534. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7535. for (i = 14; i < tx_len; i++)
  7536. tx_data[i] = (u8) (i & 0xff);
  7537. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7538. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7539. HOSTCC_MODE_NOW);
  7540. udelay(10);
  7541. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7542. num_pkts = 0;
  7543. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7544. tp->tx_prod++;
  7545. num_pkts++;
  7546. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7547. tp->tx_prod);
  7548. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7549. udelay(10);
  7550. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  7551. for (i = 0; i < 25; i++) {
  7552. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7553. HOSTCC_MODE_NOW);
  7554. udelay(10);
  7555. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7556. rx_idx = tp->hw_status->idx[0].rx_producer;
  7557. if ((tx_idx == tp->tx_prod) &&
  7558. (rx_idx == (rx_start_idx + num_pkts)))
  7559. break;
  7560. }
  7561. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7562. dev_kfree_skb(skb);
  7563. if (tx_idx != tp->tx_prod)
  7564. goto out;
  7565. if (rx_idx != rx_start_idx + num_pkts)
  7566. goto out;
  7567. desc = &tp->rx_rcb[rx_start_idx];
  7568. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7569. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7570. if (opaque_key != RXD_OPAQUE_RING_STD)
  7571. goto out;
  7572. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7573. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7574. goto out;
  7575. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7576. if (rx_len != tx_len)
  7577. goto out;
  7578. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7579. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7580. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7581. for (i = 14; i < tx_len; i++) {
  7582. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7583. goto out;
  7584. }
  7585. err = 0;
  7586. /* tg3_free_rings will unmap and free the rx_skb */
  7587. out:
  7588. return err;
  7589. }
  7590. #define TG3_MAC_LOOPBACK_FAILED 1
  7591. #define TG3_PHY_LOOPBACK_FAILED 2
  7592. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7593. TG3_PHY_LOOPBACK_FAILED)
  7594. static int tg3_test_loopback(struct tg3 *tp)
  7595. {
  7596. int err = 0;
  7597. if (!netif_running(tp->dev))
  7598. return TG3_LOOPBACK_FAILED;
  7599. err = tg3_reset_hw(tp, 1);
  7600. if (err)
  7601. return TG3_LOOPBACK_FAILED;
  7602. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7603. err |= TG3_MAC_LOOPBACK_FAILED;
  7604. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7605. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7606. err |= TG3_PHY_LOOPBACK_FAILED;
  7607. }
  7608. return err;
  7609. }
  7610. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7611. u64 *data)
  7612. {
  7613. struct tg3 *tp = netdev_priv(dev);
  7614. if (tp->link_config.phy_is_low_power)
  7615. tg3_set_power_state(tp, PCI_D0);
  7616. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7617. if (tg3_test_nvram(tp) != 0) {
  7618. etest->flags |= ETH_TEST_FL_FAILED;
  7619. data[0] = 1;
  7620. }
  7621. if (tg3_test_link(tp) != 0) {
  7622. etest->flags |= ETH_TEST_FL_FAILED;
  7623. data[1] = 1;
  7624. }
  7625. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7626. int err, irq_sync = 0;
  7627. if (netif_running(dev)) {
  7628. tg3_netif_stop(tp);
  7629. irq_sync = 1;
  7630. }
  7631. tg3_full_lock(tp, irq_sync);
  7632. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7633. err = tg3_nvram_lock(tp);
  7634. tg3_halt_cpu(tp, RX_CPU_BASE);
  7635. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7636. tg3_halt_cpu(tp, TX_CPU_BASE);
  7637. if (!err)
  7638. tg3_nvram_unlock(tp);
  7639. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7640. tg3_phy_reset(tp);
  7641. if (tg3_test_registers(tp) != 0) {
  7642. etest->flags |= ETH_TEST_FL_FAILED;
  7643. data[2] = 1;
  7644. }
  7645. if (tg3_test_memory(tp) != 0) {
  7646. etest->flags |= ETH_TEST_FL_FAILED;
  7647. data[3] = 1;
  7648. }
  7649. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7650. etest->flags |= ETH_TEST_FL_FAILED;
  7651. tg3_full_unlock(tp);
  7652. if (tg3_test_interrupt(tp) != 0) {
  7653. etest->flags |= ETH_TEST_FL_FAILED;
  7654. data[5] = 1;
  7655. }
  7656. tg3_full_lock(tp, 0);
  7657. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7658. if (netif_running(dev)) {
  7659. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7660. if (!tg3_restart_hw(tp, 1))
  7661. tg3_netif_start(tp);
  7662. }
  7663. tg3_full_unlock(tp);
  7664. }
  7665. if (tp->link_config.phy_is_low_power)
  7666. tg3_set_power_state(tp, PCI_D3hot);
  7667. }
  7668. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7669. {
  7670. struct mii_ioctl_data *data = if_mii(ifr);
  7671. struct tg3 *tp = netdev_priv(dev);
  7672. int err;
  7673. switch(cmd) {
  7674. case SIOCGMIIPHY:
  7675. data->phy_id = PHY_ADDR;
  7676. /* fallthru */
  7677. case SIOCGMIIREG: {
  7678. u32 mii_regval;
  7679. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7680. break; /* We have no PHY */
  7681. if (tp->link_config.phy_is_low_power)
  7682. return -EAGAIN;
  7683. spin_lock_bh(&tp->lock);
  7684. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7685. spin_unlock_bh(&tp->lock);
  7686. data->val_out = mii_regval;
  7687. return err;
  7688. }
  7689. case SIOCSMIIREG:
  7690. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7691. break; /* We have no PHY */
  7692. if (!capable(CAP_NET_ADMIN))
  7693. return -EPERM;
  7694. if (tp->link_config.phy_is_low_power)
  7695. return -EAGAIN;
  7696. spin_lock_bh(&tp->lock);
  7697. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7698. spin_unlock_bh(&tp->lock);
  7699. return err;
  7700. default:
  7701. /* do nothing */
  7702. break;
  7703. }
  7704. return -EOPNOTSUPP;
  7705. }
  7706. #if TG3_VLAN_TAG_USED
  7707. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7708. {
  7709. struct tg3 *tp = netdev_priv(dev);
  7710. if (netif_running(dev))
  7711. tg3_netif_stop(tp);
  7712. tg3_full_lock(tp, 0);
  7713. tp->vlgrp = grp;
  7714. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7715. __tg3_set_rx_mode(dev);
  7716. tg3_full_unlock(tp);
  7717. if (netif_running(dev))
  7718. tg3_netif_start(tp);
  7719. }
  7720. static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  7721. {
  7722. struct tg3 *tp = netdev_priv(dev);
  7723. if (netif_running(dev))
  7724. tg3_netif_stop(tp);
  7725. tg3_full_lock(tp, 0);
  7726. vlan_group_set_device(tp->vlgrp, vid, NULL);
  7727. tg3_full_unlock(tp);
  7728. if (netif_running(dev))
  7729. tg3_netif_start(tp);
  7730. }
  7731. #endif
  7732. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7733. {
  7734. struct tg3 *tp = netdev_priv(dev);
  7735. memcpy(ec, &tp->coal, sizeof(*ec));
  7736. return 0;
  7737. }
  7738. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7739. {
  7740. struct tg3 *tp = netdev_priv(dev);
  7741. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7742. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7743. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7744. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7745. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7746. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7747. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7748. }
  7749. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7750. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7751. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7752. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7753. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7754. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7755. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7756. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7757. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7758. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7759. return -EINVAL;
  7760. /* No rx interrupts will be generated if both are zero */
  7761. if ((ec->rx_coalesce_usecs == 0) &&
  7762. (ec->rx_max_coalesced_frames == 0))
  7763. return -EINVAL;
  7764. /* No tx interrupts will be generated if both are zero */
  7765. if ((ec->tx_coalesce_usecs == 0) &&
  7766. (ec->tx_max_coalesced_frames == 0))
  7767. return -EINVAL;
  7768. /* Only copy relevant parameters, ignore all others. */
  7769. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7770. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7771. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7772. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7773. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7774. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7775. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7776. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7777. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7778. if (netif_running(dev)) {
  7779. tg3_full_lock(tp, 0);
  7780. __tg3_set_coalesce(tp, &tp->coal);
  7781. tg3_full_unlock(tp);
  7782. }
  7783. return 0;
  7784. }
  7785. static const struct ethtool_ops tg3_ethtool_ops = {
  7786. .get_settings = tg3_get_settings,
  7787. .set_settings = tg3_set_settings,
  7788. .get_drvinfo = tg3_get_drvinfo,
  7789. .get_regs_len = tg3_get_regs_len,
  7790. .get_regs = tg3_get_regs,
  7791. .get_wol = tg3_get_wol,
  7792. .set_wol = tg3_set_wol,
  7793. .get_msglevel = tg3_get_msglevel,
  7794. .set_msglevel = tg3_set_msglevel,
  7795. .nway_reset = tg3_nway_reset,
  7796. .get_link = ethtool_op_get_link,
  7797. .get_eeprom_len = tg3_get_eeprom_len,
  7798. .get_eeprom = tg3_get_eeprom,
  7799. .set_eeprom = tg3_set_eeprom,
  7800. .get_ringparam = tg3_get_ringparam,
  7801. .set_ringparam = tg3_set_ringparam,
  7802. .get_pauseparam = tg3_get_pauseparam,
  7803. .set_pauseparam = tg3_set_pauseparam,
  7804. .get_rx_csum = tg3_get_rx_csum,
  7805. .set_rx_csum = tg3_set_rx_csum,
  7806. .get_tx_csum = ethtool_op_get_tx_csum,
  7807. .set_tx_csum = tg3_set_tx_csum,
  7808. .get_sg = ethtool_op_get_sg,
  7809. .set_sg = ethtool_op_set_sg,
  7810. .get_tso = ethtool_op_get_tso,
  7811. .set_tso = tg3_set_tso,
  7812. .self_test_count = tg3_get_test_count,
  7813. .self_test = tg3_self_test,
  7814. .get_strings = tg3_get_strings,
  7815. .phys_id = tg3_phys_id,
  7816. .get_stats_count = tg3_get_stats_count,
  7817. .get_ethtool_stats = tg3_get_ethtool_stats,
  7818. .get_coalesce = tg3_get_coalesce,
  7819. .set_coalesce = tg3_set_coalesce,
  7820. .get_perm_addr = ethtool_op_get_perm_addr,
  7821. };
  7822. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7823. {
  7824. u32 cursize, val, magic;
  7825. tp->nvram_size = EEPROM_CHIP_SIZE;
  7826. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7827. return;
  7828. if ((magic != TG3_EEPROM_MAGIC) &&
  7829. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  7830. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  7831. return;
  7832. /*
  7833. * Size the chip by reading offsets at increasing powers of two.
  7834. * When we encounter our validation signature, we know the addressing
  7835. * has wrapped around, and thus have our chip size.
  7836. */
  7837. cursize = 0x10;
  7838. while (cursize < tp->nvram_size) {
  7839. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7840. return;
  7841. if (val == magic)
  7842. break;
  7843. cursize <<= 1;
  7844. }
  7845. tp->nvram_size = cursize;
  7846. }
  7847. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7848. {
  7849. u32 val;
  7850. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7851. return;
  7852. /* Selfboot format */
  7853. if (val != TG3_EEPROM_MAGIC) {
  7854. tg3_get_eeprom_size(tp);
  7855. return;
  7856. }
  7857. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7858. if (val != 0) {
  7859. tp->nvram_size = (val >> 16) * 1024;
  7860. return;
  7861. }
  7862. }
  7863. tp->nvram_size = 0x80000;
  7864. }
  7865. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7866. {
  7867. u32 nvcfg1;
  7868. nvcfg1 = tr32(NVRAM_CFG1);
  7869. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7870. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7871. }
  7872. else {
  7873. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7874. tw32(NVRAM_CFG1, nvcfg1);
  7875. }
  7876. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7877. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7878. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7879. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7880. tp->nvram_jedecnum = JEDEC_ATMEL;
  7881. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7882. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7883. break;
  7884. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7885. tp->nvram_jedecnum = JEDEC_ATMEL;
  7886. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7887. break;
  7888. case FLASH_VENDOR_ATMEL_EEPROM:
  7889. tp->nvram_jedecnum = JEDEC_ATMEL;
  7890. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7891. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7892. break;
  7893. case FLASH_VENDOR_ST:
  7894. tp->nvram_jedecnum = JEDEC_ST;
  7895. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7896. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7897. break;
  7898. case FLASH_VENDOR_SAIFUN:
  7899. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7900. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7901. break;
  7902. case FLASH_VENDOR_SST_SMALL:
  7903. case FLASH_VENDOR_SST_LARGE:
  7904. tp->nvram_jedecnum = JEDEC_SST;
  7905. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7906. break;
  7907. }
  7908. }
  7909. else {
  7910. tp->nvram_jedecnum = JEDEC_ATMEL;
  7911. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7912. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7913. }
  7914. }
  7915. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7916. {
  7917. u32 nvcfg1;
  7918. nvcfg1 = tr32(NVRAM_CFG1);
  7919. /* NVRAM protection for TPM */
  7920. if (nvcfg1 & (1 << 27))
  7921. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7922. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7923. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7924. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7925. tp->nvram_jedecnum = JEDEC_ATMEL;
  7926. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7927. break;
  7928. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7929. tp->nvram_jedecnum = JEDEC_ATMEL;
  7930. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7931. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7932. break;
  7933. case FLASH_5752VENDOR_ST_M45PE10:
  7934. case FLASH_5752VENDOR_ST_M45PE20:
  7935. case FLASH_5752VENDOR_ST_M45PE40:
  7936. tp->nvram_jedecnum = JEDEC_ST;
  7937. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7938. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7939. break;
  7940. }
  7941. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7942. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7943. case FLASH_5752PAGE_SIZE_256:
  7944. tp->nvram_pagesize = 256;
  7945. break;
  7946. case FLASH_5752PAGE_SIZE_512:
  7947. tp->nvram_pagesize = 512;
  7948. break;
  7949. case FLASH_5752PAGE_SIZE_1K:
  7950. tp->nvram_pagesize = 1024;
  7951. break;
  7952. case FLASH_5752PAGE_SIZE_2K:
  7953. tp->nvram_pagesize = 2048;
  7954. break;
  7955. case FLASH_5752PAGE_SIZE_4K:
  7956. tp->nvram_pagesize = 4096;
  7957. break;
  7958. case FLASH_5752PAGE_SIZE_264:
  7959. tp->nvram_pagesize = 264;
  7960. break;
  7961. }
  7962. }
  7963. else {
  7964. /* For eeprom, set pagesize to maximum eeprom size */
  7965. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7966. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7967. tw32(NVRAM_CFG1, nvcfg1);
  7968. }
  7969. }
  7970. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  7971. {
  7972. u32 nvcfg1, protect = 0;
  7973. nvcfg1 = tr32(NVRAM_CFG1);
  7974. /* NVRAM protection for TPM */
  7975. if (nvcfg1 & (1 << 27)) {
  7976. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7977. protect = 1;
  7978. }
  7979. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  7980. switch (nvcfg1) {
  7981. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7982. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  7983. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  7984. tp->nvram_jedecnum = JEDEC_ATMEL;
  7985. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7986. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7987. tp->nvram_pagesize = 264;
  7988. if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1)
  7989. tp->nvram_size = (protect ? 0x3e200 : 0x80000);
  7990. else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
  7991. tp->nvram_size = (protect ? 0x1f200 : 0x40000);
  7992. else
  7993. tp->nvram_size = (protect ? 0x1f200 : 0x20000);
  7994. break;
  7995. case FLASH_5752VENDOR_ST_M45PE10:
  7996. case FLASH_5752VENDOR_ST_M45PE20:
  7997. case FLASH_5752VENDOR_ST_M45PE40:
  7998. tp->nvram_jedecnum = JEDEC_ST;
  7999. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8000. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8001. tp->nvram_pagesize = 256;
  8002. if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
  8003. tp->nvram_size = (protect ? 0x10000 : 0x20000);
  8004. else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
  8005. tp->nvram_size = (protect ? 0x10000 : 0x40000);
  8006. else
  8007. tp->nvram_size = (protect ? 0x20000 : 0x80000);
  8008. break;
  8009. }
  8010. }
  8011. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8012. {
  8013. u32 nvcfg1;
  8014. nvcfg1 = tr32(NVRAM_CFG1);
  8015. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8016. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8017. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8018. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8019. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8020. tp->nvram_jedecnum = JEDEC_ATMEL;
  8021. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8022. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8023. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8024. tw32(NVRAM_CFG1, nvcfg1);
  8025. break;
  8026. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8027. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8028. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8029. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8030. tp->nvram_jedecnum = JEDEC_ATMEL;
  8031. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8032. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8033. tp->nvram_pagesize = 264;
  8034. break;
  8035. case FLASH_5752VENDOR_ST_M45PE10:
  8036. case FLASH_5752VENDOR_ST_M45PE20:
  8037. case FLASH_5752VENDOR_ST_M45PE40:
  8038. tp->nvram_jedecnum = JEDEC_ST;
  8039. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8040. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8041. tp->nvram_pagesize = 256;
  8042. break;
  8043. }
  8044. }
  8045. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8046. {
  8047. tp->nvram_jedecnum = JEDEC_ATMEL;
  8048. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8049. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8050. }
  8051. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8052. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8053. {
  8054. tw32_f(GRC_EEPROM_ADDR,
  8055. (EEPROM_ADDR_FSM_RESET |
  8056. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8057. EEPROM_ADDR_CLKPERD_SHIFT)));
  8058. msleep(1);
  8059. /* Enable seeprom accesses. */
  8060. tw32_f(GRC_LOCAL_CTRL,
  8061. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8062. udelay(100);
  8063. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8064. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8065. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8066. if (tg3_nvram_lock(tp)) {
  8067. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8068. "tg3_nvram_init failed.\n", tp->dev->name);
  8069. return;
  8070. }
  8071. tg3_enable_nvram_access(tp);
  8072. tp->nvram_size = 0;
  8073. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8074. tg3_get_5752_nvram_info(tp);
  8075. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8076. tg3_get_5755_nvram_info(tp);
  8077. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8078. tg3_get_5787_nvram_info(tp);
  8079. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8080. tg3_get_5906_nvram_info(tp);
  8081. else
  8082. tg3_get_nvram_info(tp);
  8083. if (tp->nvram_size == 0)
  8084. tg3_get_nvram_size(tp);
  8085. tg3_disable_nvram_access(tp);
  8086. tg3_nvram_unlock(tp);
  8087. } else {
  8088. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8089. tg3_get_eeprom_size(tp);
  8090. }
  8091. }
  8092. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8093. u32 offset, u32 *val)
  8094. {
  8095. u32 tmp;
  8096. int i;
  8097. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8098. (offset % 4) != 0)
  8099. return -EINVAL;
  8100. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8101. EEPROM_ADDR_DEVID_MASK |
  8102. EEPROM_ADDR_READ);
  8103. tw32(GRC_EEPROM_ADDR,
  8104. tmp |
  8105. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8106. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8107. EEPROM_ADDR_ADDR_MASK) |
  8108. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8109. for (i = 0; i < 1000; i++) {
  8110. tmp = tr32(GRC_EEPROM_ADDR);
  8111. if (tmp & EEPROM_ADDR_COMPLETE)
  8112. break;
  8113. msleep(1);
  8114. }
  8115. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8116. return -EBUSY;
  8117. *val = tr32(GRC_EEPROM_DATA);
  8118. return 0;
  8119. }
  8120. #define NVRAM_CMD_TIMEOUT 10000
  8121. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8122. {
  8123. int i;
  8124. tw32(NVRAM_CMD, nvram_cmd);
  8125. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8126. udelay(10);
  8127. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8128. udelay(10);
  8129. break;
  8130. }
  8131. }
  8132. if (i == NVRAM_CMD_TIMEOUT) {
  8133. return -EBUSY;
  8134. }
  8135. return 0;
  8136. }
  8137. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8138. {
  8139. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8140. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8141. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8142. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8143. addr = ((addr / tp->nvram_pagesize) <<
  8144. ATMEL_AT45DB0X1B_PAGE_POS) +
  8145. (addr % tp->nvram_pagesize);
  8146. return addr;
  8147. }
  8148. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8149. {
  8150. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8151. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8152. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8153. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8154. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8155. tp->nvram_pagesize) +
  8156. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8157. return addr;
  8158. }
  8159. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8160. {
  8161. int ret;
  8162. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8163. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8164. offset = tg3_nvram_phys_addr(tp, offset);
  8165. if (offset > NVRAM_ADDR_MSK)
  8166. return -EINVAL;
  8167. ret = tg3_nvram_lock(tp);
  8168. if (ret)
  8169. return ret;
  8170. tg3_enable_nvram_access(tp);
  8171. tw32(NVRAM_ADDR, offset);
  8172. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8173. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8174. if (ret == 0)
  8175. *val = swab32(tr32(NVRAM_RDDATA));
  8176. tg3_disable_nvram_access(tp);
  8177. tg3_nvram_unlock(tp);
  8178. return ret;
  8179. }
  8180. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8181. {
  8182. int err;
  8183. u32 tmp;
  8184. err = tg3_nvram_read(tp, offset, &tmp);
  8185. *val = swab32(tmp);
  8186. return err;
  8187. }
  8188. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8189. u32 offset, u32 len, u8 *buf)
  8190. {
  8191. int i, j, rc = 0;
  8192. u32 val;
  8193. for (i = 0; i < len; i += 4) {
  8194. u32 addr, data;
  8195. addr = offset + i;
  8196. memcpy(&data, buf + i, 4);
  8197. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8198. val = tr32(GRC_EEPROM_ADDR);
  8199. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8200. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8201. EEPROM_ADDR_READ);
  8202. tw32(GRC_EEPROM_ADDR, val |
  8203. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8204. (addr & EEPROM_ADDR_ADDR_MASK) |
  8205. EEPROM_ADDR_START |
  8206. EEPROM_ADDR_WRITE);
  8207. for (j = 0; j < 1000; j++) {
  8208. val = tr32(GRC_EEPROM_ADDR);
  8209. if (val & EEPROM_ADDR_COMPLETE)
  8210. break;
  8211. msleep(1);
  8212. }
  8213. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8214. rc = -EBUSY;
  8215. break;
  8216. }
  8217. }
  8218. return rc;
  8219. }
  8220. /* offset and length are dword aligned */
  8221. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8222. u8 *buf)
  8223. {
  8224. int ret = 0;
  8225. u32 pagesize = tp->nvram_pagesize;
  8226. u32 pagemask = pagesize - 1;
  8227. u32 nvram_cmd;
  8228. u8 *tmp;
  8229. tmp = kmalloc(pagesize, GFP_KERNEL);
  8230. if (tmp == NULL)
  8231. return -ENOMEM;
  8232. while (len) {
  8233. int j;
  8234. u32 phy_addr, page_off, size;
  8235. phy_addr = offset & ~pagemask;
  8236. for (j = 0; j < pagesize; j += 4) {
  8237. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8238. (u32 *) (tmp + j))))
  8239. break;
  8240. }
  8241. if (ret)
  8242. break;
  8243. page_off = offset & pagemask;
  8244. size = pagesize;
  8245. if (len < size)
  8246. size = len;
  8247. len -= size;
  8248. memcpy(tmp + page_off, buf, size);
  8249. offset = offset + (pagesize - page_off);
  8250. tg3_enable_nvram_access(tp);
  8251. /*
  8252. * Before we can erase the flash page, we need
  8253. * to issue a special "write enable" command.
  8254. */
  8255. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8256. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8257. break;
  8258. /* Erase the target page */
  8259. tw32(NVRAM_ADDR, phy_addr);
  8260. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8261. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8262. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8263. break;
  8264. /* Issue another write enable to start the write. */
  8265. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8266. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8267. break;
  8268. for (j = 0; j < pagesize; j += 4) {
  8269. u32 data;
  8270. data = *((u32 *) (tmp + j));
  8271. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8272. tw32(NVRAM_ADDR, phy_addr + j);
  8273. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8274. NVRAM_CMD_WR;
  8275. if (j == 0)
  8276. nvram_cmd |= NVRAM_CMD_FIRST;
  8277. else if (j == (pagesize - 4))
  8278. nvram_cmd |= NVRAM_CMD_LAST;
  8279. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8280. break;
  8281. }
  8282. if (ret)
  8283. break;
  8284. }
  8285. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8286. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8287. kfree(tmp);
  8288. return ret;
  8289. }
  8290. /* offset and length are dword aligned */
  8291. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8292. u8 *buf)
  8293. {
  8294. int i, ret = 0;
  8295. for (i = 0; i < len; i += 4, offset += 4) {
  8296. u32 data, page_off, phy_addr, nvram_cmd;
  8297. memcpy(&data, buf + i, 4);
  8298. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8299. page_off = offset % tp->nvram_pagesize;
  8300. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8301. tw32(NVRAM_ADDR, phy_addr);
  8302. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8303. if ((page_off == 0) || (i == 0))
  8304. nvram_cmd |= NVRAM_CMD_FIRST;
  8305. if (page_off == (tp->nvram_pagesize - 4))
  8306. nvram_cmd |= NVRAM_CMD_LAST;
  8307. if (i == (len - 4))
  8308. nvram_cmd |= NVRAM_CMD_LAST;
  8309. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8310. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8311. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8312. (tp->nvram_jedecnum == JEDEC_ST) &&
  8313. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8314. if ((ret = tg3_nvram_exec_cmd(tp,
  8315. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8316. NVRAM_CMD_DONE)))
  8317. break;
  8318. }
  8319. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8320. /* We always do complete word writes to eeprom. */
  8321. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8322. }
  8323. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8324. break;
  8325. }
  8326. return ret;
  8327. }
  8328. /* offset and length are dword aligned */
  8329. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8330. {
  8331. int ret;
  8332. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8333. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8334. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8335. udelay(40);
  8336. }
  8337. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8338. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8339. }
  8340. else {
  8341. u32 grc_mode;
  8342. ret = tg3_nvram_lock(tp);
  8343. if (ret)
  8344. return ret;
  8345. tg3_enable_nvram_access(tp);
  8346. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8347. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8348. tw32(NVRAM_WRITE1, 0x406);
  8349. grc_mode = tr32(GRC_MODE);
  8350. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8351. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8352. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8353. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8354. buf);
  8355. }
  8356. else {
  8357. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8358. buf);
  8359. }
  8360. grc_mode = tr32(GRC_MODE);
  8361. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8362. tg3_disable_nvram_access(tp);
  8363. tg3_nvram_unlock(tp);
  8364. }
  8365. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8366. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8367. udelay(40);
  8368. }
  8369. return ret;
  8370. }
  8371. struct subsys_tbl_ent {
  8372. u16 subsys_vendor, subsys_devid;
  8373. u32 phy_id;
  8374. };
  8375. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8376. /* Broadcom boards. */
  8377. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8378. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8379. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8380. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8381. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8382. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8383. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8384. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8385. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8386. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8387. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8388. /* 3com boards. */
  8389. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8390. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8391. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8392. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8393. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8394. /* DELL boards. */
  8395. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8396. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8397. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8398. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8399. /* Compaq boards. */
  8400. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8401. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8402. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8403. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8404. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8405. /* IBM boards. */
  8406. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8407. };
  8408. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8409. {
  8410. int i;
  8411. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8412. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8413. tp->pdev->subsystem_vendor) &&
  8414. (subsys_id_to_phy_id[i].subsys_devid ==
  8415. tp->pdev->subsystem_device))
  8416. return &subsys_id_to_phy_id[i];
  8417. }
  8418. return NULL;
  8419. }
  8420. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8421. {
  8422. u32 val;
  8423. u16 pmcsr;
  8424. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8425. * so need make sure we're in D0.
  8426. */
  8427. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8428. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8429. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8430. msleep(1);
  8431. /* Make sure register accesses (indirect or otherwise)
  8432. * will function correctly.
  8433. */
  8434. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8435. tp->misc_host_ctrl);
  8436. /* The memory arbiter has to be enabled in order for SRAM accesses
  8437. * to succeed. Normally on powerup the tg3 chip firmware will make
  8438. * sure it is enabled, but other entities such as system netboot
  8439. * code might disable it.
  8440. */
  8441. val = tr32(MEMARB_MODE);
  8442. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8443. tp->phy_id = PHY_ID_INVALID;
  8444. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8445. /* Assume an onboard device and WOL capable by default. */
  8446. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
  8447. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8448. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  8449. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8450. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8451. }
  8452. return;
  8453. }
  8454. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8455. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8456. u32 nic_cfg, led_cfg;
  8457. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8458. int eeprom_phy_serdes = 0;
  8459. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8460. tp->nic_sram_data_cfg = nic_cfg;
  8461. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8462. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8463. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8464. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8465. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8466. (ver > 0) && (ver < 0x100))
  8467. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8468. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8469. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8470. eeprom_phy_serdes = 1;
  8471. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8472. if (nic_phy_id != 0) {
  8473. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8474. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8475. eeprom_phy_id = (id1 >> 16) << 10;
  8476. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8477. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8478. } else
  8479. eeprom_phy_id = 0;
  8480. tp->phy_id = eeprom_phy_id;
  8481. if (eeprom_phy_serdes) {
  8482. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8483. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8484. else
  8485. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8486. }
  8487. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8488. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8489. SHASTA_EXT_LED_MODE_MASK);
  8490. else
  8491. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8492. switch (led_cfg) {
  8493. default:
  8494. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8495. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8496. break;
  8497. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8498. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8499. break;
  8500. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8501. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8502. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8503. * read on some older 5700/5701 bootcode.
  8504. */
  8505. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8506. ASIC_REV_5700 ||
  8507. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8508. ASIC_REV_5701)
  8509. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8510. break;
  8511. case SHASTA_EXT_LED_SHARED:
  8512. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8513. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8514. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8515. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8516. LED_CTRL_MODE_PHY_2);
  8517. break;
  8518. case SHASTA_EXT_LED_MAC:
  8519. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8520. break;
  8521. case SHASTA_EXT_LED_COMBO:
  8522. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8523. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8524. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8525. LED_CTRL_MODE_PHY_2);
  8526. break;
  8527. };
  8528. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8529. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8530. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8531. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8532. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  8533. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8534. if ((tp->pdev->subsystem_vendor ==
  8535. PCI_VENDOR_ID_ARIMA) &&
  8536. (tp->pdev->subsystem_device == 0x205a ||
  8537. tp->pdev->subsystem_device == 0x2063))
  8538. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8539. } else {
  8540. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8541. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8542. }
  8543. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8544. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8545. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8546. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8547. }
  8548. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  8549. !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
  8550. tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
  8551. if (cfg2 & (1 << 17))
  8552. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8553. /* serdes signal pre-emphasis in register 0x590 set by */
  8554. /* bootcode if bit 18 is set */
  8555. if (cfg2 & (1 << 18))
  8556. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8557. }
  8558. }
  8559. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8560. {
  8561. u32 hw_phy_id_1, hw_phy_id_2;
  8562. u32 hw_phy_id, hw_phy_id_masked;
  8563. int err;
  8564. /* Reading the PHY ID register can conflict with ASF
  8565. * firwmare access to the PHY hardware.
  8566. */
  8567. err = 0;
  8568. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8569. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8570. } else {
  8571. /* Now read the physical PHY_ID from the chip and verify
  8572. * that it is sane. If it doesn't look good, we fall back
  8573. * to either the hard-coded table based PHY_ID and failing
  8574. * that the value found in the eeprom area.
  8575. */
  8576. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8577. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8578. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8579. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8580. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8581. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8582. }
  8583. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8584. tp->phy_id = hw_phy_id;
  8585. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8586. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8587. else
  8588. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8589. } else {
  8590. if (tp->phy_id != PHY_ID_INVALID) {
  8591. /* Do nothing, phy ID already set up in
  8592. * tg3_get_eeprom_hw_cfg().
  8593. */
  8594. } else {
  8595. struct subsys_tbl_ent *p;
  8596. /* No eeprom signature? Try the hardcoded
  8597. * subsys device table.
  8598. */
  8599. p = lookup_by_subsys(tp);
  8600. if (!p)
  8601. return -ENODEV;
  8602. tp->phy_id = p->phy_id;
  8603. if (!tp->phy_id ||
  8604. tp->phy_id == PHY_ID_BCM8002)
  8605. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8606. }
  8607. }
  8608. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8609. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8610. u32 bmsr, adv_reg, tg3_ctrl, mask;
  8611. tg3_readphy(tp, MII_BMSR, &bmsr);
  8612. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8613. (bmsr & BMSR_LSTATUS))
  8614. goto skip_phy_reset;
  8615. err = tg3_phy_reset(tp);
  8616. if (err)
  8617. return err;
  8618. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8619. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8620. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8621. tg3_ctrl = 0;
  8622. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8623. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8624. MII_TG3_CTRL_ADV_1000_FULL);
  8625. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8626. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8627. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8628. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8629. }
  8630. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  8631. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  8632. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  8633. if (!tg3_copper_is_advertising_all(tp, mask)) {
  8634. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8635. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8636. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8637. tg3_writephy(tp, MII_BMCR,
  8638. BMCR_ANENABLE | BMCR_ANRESTART);
  8639. }
  8640. tg3_phy_set_wirespeed(tp);
  8641. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8642. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8643. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8644. }
  8645. skip_phy_reset:
  8646. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8647. err = tg3_init_5401phy_dsp(tp);
  8648. if (err)
  8649. return err;
  8650. }
  8651. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8652. err = tg3_init_5401phy_dsp(tp);
  8653. }
  8654. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8655. tp->link_config.advertising =
  8656. (ADVERTISED_1000baseT_Half |
  8657. ADVERTISED_1000baseT_Full |
  8658. ADVERTISED_Autoneg |
  8659. ADVERTISED_FIBRE);
  8660. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8661. tp->link_config.advertising &=
  8662. ~(ADVERTISED_1000baseT_Half |
  8663. ADVERTISED_1000baseT_Full);
  8664. return err;
  8665. }
  8666. static void __devinit tg3_read_partno(struct tg3 *tp)
  8667. {
  8668. unsigned char vpd_data[256];
  8669. unsigned int i;
  8670. u32 magic;
  8671. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8672. goto out_not_found;
  8673. if (magic == TG3_EEPROM_MAGIC) {
  8674. for (i = 0; i < 256; i += 4) {
  8675. u32 tmp;
  8676. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8677. goto out_not_found;
  8678. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8679. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8680. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8681. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8682. }
  8683. } else {
  8684. int vpd_cap;
  8685. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8686. for (i = 0; i < 256; i += 4) {
  8687. u32 tmp, j = 0;
  8688. u16 tmp16;
  8689. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8690. i);
  8691. while (j++ < 100) {
  8692. pci_read_config_word(tp->pdev, vpd_cap +
  8693. PCI_VPD_ADDR, &tmp16);
  8694. if (tmp16 & 0x8000)
  8695. break;
  8696. msleep(1);
  8697. }
  8698. if (!(tmp16 & 0x8000))
  8699. goto out_not_found;
  8700. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8701. &tmp);
  8702. tmp = cpu_to_le32(tmp);
  8703. memcpy(&vpd_data[i], &tmp, 4);
  8704. }
  8705. }
  8706. /* Now parse and find the part number. */
  8707. for (i = 0; i < 254; ) {
  8708. unsigned char val = vpd_data[i];
  8709. unsigned int block_end;
  8710. if (val == 0x82 || val == 0x91) {
  8711. i = (i + 3 +
  8712. (vpd_data[i + 1] +
  8713. (vpd_data[i + 2] << 8)));
  8714. continue;
  8715. }
  8716. if (val != 0x90)
  8717. goto out_not_found;
  8718. block_end = (i + 3 +
  8719. (vpd_data[i + 1] +
  8720. (vpd_data[i + 2] << 8)));
  8721. i += 3;
  8722. if (block_end > 256)
  8723. goto out_not_found;
  8724. while (i < (block_end - 2)) {
  8725. if (vpd_data[i + 0] == 'P' &&
  8726. vpd_data[i + 1] == 'N') {
  8727. int partno_len = vpd_data[i + 2];
  8728. i += 3;
  8729. if (partno_len > 24 || (partno_len + i) > 256)
  8730. goto out_not_found;
  8731. memcpy(tp->board_part_number,
  8732. &vpd_data[i], partno_len);
  8733. /* Success. */
  8734. return;
  8735. }
  8736. i += 3 + vpd_data[i + 2];
  8737. }
  8738. /* Part number not found. */
  8739. goto out_not_found;
  8740. }
  8741. out_not_found:
  8742. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8743. strcpy(tp->board_part_number, "BCM95906");
  8744. else
  8745. strcpy(tp->board_part_number, "none");
  8746. }
  8747. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8748. {
  8749. u32 val, offset, start;
  8750. if (tg3_nvram_read_swab(tp, 0, &val))
  8751. return;
  8752. if (val != TG3_EEPROM_MAGIC)
  8753. return;
  8754. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8755. tg3_nvram_read_swab(tp, 0x4, &start))
  8756. return;
  8757. offset = tg3_nvram_logical_addr(tp, offset);
  8758. if (tg3_nvram_read_swab(tp, offset, &val))
  8759. return;
  8760. if ((val & 0xfc000000) == 0x0c000000) {
  8761. u32 ver_offset, addr;
  8762. int i;
  8763. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8764. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8765. return;
  8766. if (val != 0)
  8767. return;
  8768. addr = offset + ver_offset - start;
  8769. for (i = 0; i < 16; i += 4) {
  8770. if (tg3_nvram_read(tp, addr + i, &val))
  8771. return;
  8772. val = cpu_to_le32(val);
  8773. memcpy(tp->fw_ver + i, &val, 4);
  8774. }
  8775. }
  8776. }
  8777. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
  8778. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8779. {
  8780. static struct pci_device_id write_reorder_chipsets[] = {
  8781. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8782. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8783. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8784. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8785. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8786. PCI_DEVICE_ID_VIA_8385_0) },
  8787. { },
  8788. };
  8789. u32 misc_ctrl_reg;
  8790. u32 cacheline_sz_reg;
  8791. u32 pci_state_reg, grc_misc_cfg;
  8792. u32 val;
  8793. u16 pci_cmd;
  8794. int err, pcie_cap;
  8795. /* Force memory write invalidate off. If we leave it on,
  8796. * then on 5700_BX chips we have to enable a workaround.
  8797. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8798. * to match the cacheline size. The Broadcom driver have this
  8799. * workaround but turns MWI off all the times so never uses
  8800. * it. This seems to suggest that the workaround is insufficient.
  8801. */
  8802. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8803. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8804. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8805. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8806. * has the register indirect write enable bit set before
  8807. * we try to access any of the MMIO registers. It is also
  8808. * critical that the PCI-X hw workaround situation is decided
  8809. * before that as well.
  8810. */
  8811. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8812. &misc_ctrl_reg);
  8813. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8814. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8815. /* Wrong chip ID in 5752 A0. This code can be removed later
  8816. * as A0 is not in production.
  8817. */
  8818. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8819. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8820. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8821. * we need to disable memory and use config. cycles
  8822. * only to access all registers. The 5702/03 chips
  8823. * can mistakenly decode the special cycles from the
  8824. * ICH chipsets as memory write cycles, causing corruption
  8825. * of register and memory space. Only certain ICH bridges
  8826. * will drive special cycles with non-zero data during the
  8827. * address phase which can fall within the 5703's address
  8828. * range. This is not an ICH bug as the PCI spec allows
  8829. * non-zero address during special cycles. However, only
  8830. * these ICH bridges are known to drive non-zero addresses
  8831. * during special cycles.
  8832. *
  8833. * Since special cycles do not cross PCI bridges, we only
  8834. * enable this workaround if the 5703 is on the secondary
  8835. * bus of these ICH bridges.
  8836. */
  8837. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8838. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8839. static struct tg3_dev_id {
  8840. u32 vendor;
  8841. u32 device;
  8842. u32 rev;
  8843. } ich_chipsets[] = {
  8844. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8845. PCI_ANY_ID },
  8846. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8847. PCI_ANY_ID },
  8848. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8849. 0xa },
  8850. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8851. PCI_ANY_ID },
  8852. { },
  8853. };
  8854. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8855. struct pci_dev *bridge = NULL;
  8856. while (pci_id->vendor != 0) {
  8857. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8858. bridge);
  8859. if (!bridge) {
  8860. pci_id++;
  8861. continue;
  8862. }
  8863. if (pci_id->rev != PCI_ANY_ID) {
  8864. u8 rev;
  8865. pci_read_config_byte(bridge, PCI_REVISION_ID,
  8866. &rev);
  8867. if (rev > pci_id->rev)
  8868. continue;
  8869. }
  8870. if (bridge->subordinate &&
  8871. (bridge->subordinate->number ==
  8872. tp->pdev->bus->number)) {
  8873. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8874. pci_dev_put(bridge);
  8875. break;
  8876. }
  8877. }
  8878. }
  8879. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8880. * DMA addresses > 40-bit. This bridge may have other additional
  8881. * 57xx devices behind it in some 4-port NIC designs for example.
  8882. * Any tg3 device found behind the bridge will also need the 40-bit
  8883. * DMA workaround.
  8884. */
  8885. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8886. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8887. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8888. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8889. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8890. }
  8891. else {
  8892. struct pci_dev *bridge = NULL;
  8893. do {
  8894. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8895. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8896. bridge);
  8897. if (bridge && bridge->subordinate &&
  8898. (bridge->subordinate->number <=
  8899. tp->pdev->bus->number) &&
  8900. (bridge->subordinate->subordinate >=
  8901. tp->pdev->bus->number)) {
  8902. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8903. pci_dev_put(bridge);
  8904. break;
  8905. }
  8906. } while (bridge);
  8907. }
  8908. /* Initialize misc host control in PCI block. */
  8909. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8910. MISC_HOST_CTRL_CHIPREV);
  8911. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8912. tp->misc_host_ctrl);
  8913. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8914. &cacheline_sz_reg);
  8915. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8916. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8917. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8918. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8919. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  8920. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  8921. tp->pdev_peer = tg3_find_peer(tp);
  8922. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8923. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8924. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8925. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8926. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  8927. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8928. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8929. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8930. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8931. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8932. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8933. tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
  8934. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
  8935. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
  8936. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
  8937. tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
  8938. tp->pdev_peer == tp->pdev))
  8939. tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
  8940. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8941. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8942. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8943. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8944. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8945. } else {
  8946. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  8947. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8948. ASIC_REV_5750 &&
  8949. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  8950. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  8951. }
  8952. }
  8953. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  8954. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  8955. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  8956. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  8957. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  8958. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  8959. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  8960. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  8961. if (pcie_cap != 0) {
  8962. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  8963. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8964. u16 lnkctl;
  8965. pci_read_config_word(tp->pdev,
  8966. pcie_cap + PCI_EXP_LNKCTL,
  8967. &lnkctl);
  8968. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  8969. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  8970. }
  8971. }
  8972. /* If we have an AMD 762 or VIA K8T800 chipset, write
  8973. * reordering to the mailbox registers done by the host
  8974. * controller can cause major troubles. We read back from
  8975. * every mailbox register write to force the writes to be
  8976. * posted to the chip in order.
  8977. */
  8978. if (pci_dev_present(write_reorder_chipsets) &&
  8979. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  8980. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  8981. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  8982. tp->pci_lat_timer < 64) {
  8983. tp->pci_lat_timer = 64;
  8984. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  8985. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  8986. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  8987. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  8988. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8989. cacheline_sz_reg);
  8990. }
  8991. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  8992. &pci_state_reg);
  8993. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  8994. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  8995. /* If this is a 5700 BX chipset, and we are in PCI-X
  8996. * mode, enable register write workaround.
  8997. *
  8998. * The workaround is to use indirect register accesses
  8999. * for all chip writes not to mailbox registers.
  9000. */
  9001. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  9002. u32 pm_reg;
  9003. u16 pci_cmd;
  9004. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9005. /* The chip can have it's power management PCI config
  9006. * space registers clobbered due to this bug.
  9007. * So explicitly force the chip into D0 here.
  9008. */
  9009. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9010. &pm_reg);
  9011. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9012. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9013. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9014. pm_reg);
  9015. /* Also, force SERR#/PERR# in PCI command. */
  9016. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9017. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9018. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9019. }
  9020. }
  9021. /* 5700 BX chips need to have their TX producer index mailboxes
  9022. * written twice to workaround a bug.
  9023. */
  9024. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9025. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9026. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9027. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9028. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9029. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9030. /* Chip-specific fixup from Broadcom driver */
  9031. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9032. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9033. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9034. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9035. }
  9036. /* Default fast path register access methods */
  9037. tp->read32 = tg3_read32;
  9038. tp->write32 = tg3_write32;
  9039. tp->read32_mbox = tg3_read32;
  9040. tp->write32_mbox = tg3_write32;
  9041. tp->write32_tx_mbox = tg3_write32;
  9042. tp->write32_rx_mbox = tg3_write32;
  9043. /* Various workaround register access methods */
  9044. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9045. tp->write32 = tg3_write_indirect_reg32;
  9046. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9047. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9048. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
  9049. /*
  9050. * Back to back register writes can cause problems on these
  9051. * chips, the workaround is to read back all reg writes
  9052. * except those to mailbox regs.
  9053. *
  9054. * See tg3_write_indirect_reg32().
  9055. */
  9056. tp->write32 = tg3_write_flush_reg32;
  9057. }
  9058. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9059. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9060. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9061. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9062. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9063. }
  9064. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9065. tp->read32 = tg3_read_indirect_reg32;
  9066. tp->write32 = tg3_write_indirect_reg32;
  9067. tp->read32_mbox = tg3_read_indirect_mbox;
  9068. tp->write32_mbox = tg3_write_indirect_mbox;
  9069. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9070. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9071. iounmap(tp->regs);
  9072. tp->regs = NULL;
  9073. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9074. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9075. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9076. }
  9077. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9078. tp->read32_mbox = tg3_read32_mbox_5906;
  9079. tp->write32_mbox = tg3_write32_mbox_5906;
  9080. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9081. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9082. }
  9083. if (tp->write32 == tg3_write_indirect_reg32 ||
  9084. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9085. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9086. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9087. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9088. /* Get eeprom hw config before calling tg3_set_power_state().
  9089. * In particular, the TG3_FLG2_IS_NIC flag must be
  9090. * determined before calling tg3_set_power_state() so that
  9091. * we know whether or not to switch out of Vaux power.
  9092. * When the flag is set, it means that GPIO1 is used for eeprom
  9093. * write protect and also implies that it is a LOM where GPIOs
  9094. * are not used to switch power.
  9095. */
  9096. tg3_get_eeprom_hw_cfg(tp);
  9097. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9098. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9099. * It is also used as eeprom write protect on LOMs.
  9100. */
  9101. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9102. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9103. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9104. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9105. GRC_LCLCTRL_GPIO_OUTPUT1);
  9106. /* Unused GPIO3 must be driven as output on 5752 because there
  9107. * are no pull-up resistors on unused GPIO pins.
  9108. */
  9109. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9110. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9111. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9112. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9113. /* Force the chip into D0. */
  9114. err = tg3_set_power_state(tp, PCI_D0);
  9115. if (err) {
  9116. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9117. pci_name(tp->pdev));
  9118. return err;
  9119. }
  9120. /* 5700 B0 chips do not support checksumming correctly due
  9121. * to hardware bugs.
  9122. */
  9123. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9124. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9125. /* Derive initial jumbo mode from MTU assigned in
  9126. * ether_setup() via the alloc_etherdev() call
  9127. */
  9128. if (tp->dev->mtu > ETH_DATA_LEN &&
  9129. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9130. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9131. /* Determine WakeOnLan speed to use. */
  9132. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9133. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9134. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9135. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9136. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9137. } else {
  9138. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9139. }
  9140. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9141. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9142. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9143. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9144. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9145. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9146. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9147. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9148. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9149. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9150. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9151. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9152. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9153. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9154. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9155. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  9156. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9157. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9158. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9159. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9160. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9161. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9162. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9163. }
  9164. tp->coalesce_mode = 0;
  9165. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9166. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9167. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9168. /* Initialize MAC MI mode, polling disabled. */
  9169. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9170. udelay(80);
  9171. /* Initialize data/descriptor byte/word swapping. */
  9172. val = tr32(GRC_MODE);
  9173. val &= GRC_MODE_HOST_STACKUP;
  9174. tw32(GRC_MODE, val | tp->grc_mode);
  9175. tg3_switch_clocks(tp);
  9176. /* Clear this out for sanity. */
  9177. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9178. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9179. &pci_state_reg);
  9180. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9181. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9182. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9183. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9184. chiprevid == CHIPREV_ID_5701_B0 ||
  9185. chiprevid == CHIPREV_ID_5701_B2 ||
  9186. chiprevid == CHIPREV_ID_5701_B5) {
  9187. void __iomem *sram_base;
  9188. /* Write some dummy words into the SRAM status block
  9189. * area, see if it reads back correctly. If the return
  9190. * value is bad, force enable the PCIX workaround.
  9191. */
  9192. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9193. writel(0x00000000, sram_base);
  9194. writel(0x00000000, sram_base + 4);
  9195. writel(0xffffffff, sram_base + 4);
  9196. if (readl(sram_base) != 0x00000000)
  9197. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9198. }
  9199. }
  9200. udelay(50);
  9201. tg3_nvram_init(tp);
  9202. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9203. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9204. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9205. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9206. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9207. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9208. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9209. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9210. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9211. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9212. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9213. HOSTCC_MODE_CLRTICK_TXBD);
  9214. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9215. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9216. tp->misc_host_ctrl);
  9217. }
  9218. /* these are limited to 10/100 only */
  9219. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9220. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9221. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9222. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9223. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9224. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9225. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9226. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9227. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9228. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9229. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9230. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9231. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9232. err = tg3_phy_probe(tp);
  9233. if (err) {
  9234. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9235. pci_name(tp->pdev), err);
  9236. /* ... but do not return immediately ... */
  9237. }
  9238. tg3_read_partno(tp);
  9239. tg3_read_fw_ver(tp);
  9240. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  9241. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9242. } else {
  9243. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9244. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  9245. else
  9246. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9247. }
  9248. /* 5700 {AX,BX} chips have a broken status block link
  9249. * change bit implementation, so we must use the
  9250. * status register in those cases.
  9251. */
  9252. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9253. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9254. else
  9255. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9256. /* The led_ctrl is set during tg3_phy_probe, here we might
  9257. * have to force the link status polling mechanism based
  9258. * upon subsystem IDs.
  9259. */
  9260. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9261. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9262. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9263. TG3_FLAG_USE_LINKCHG_REG);
  9264. }
  9265. /* For all SERDES we poll the MAC status register. */
  9266. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9267. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9268. else
  9269. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9270. /* All chips before 5787 can get confused if TX buffers
  9271. * straddle the 4GB address boundary in some cases.
  9272. */
  9273. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9274. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9275. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9276. tp->dev->hard_start_xmit = tg3_start_xmit;
  9277. else
  9278. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9279. tp->rx_offset = 2;
  9280. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9281. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9282. tp->rx_offset = 0;
  9283. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9284. /* Increment the rx prod index on the rx std ring by at most
  9285. * 8 for these chips to workaround hw errata.
  9286. */
  9287. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9288. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9289. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9290. tp->rx_std_max_post = 8;
  9291. /* By default, disable wake-on-lan. User can change this
  9292. * using ETHTOOL_SWOL.
  9293. */
  9294. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9295. return err;
  9296. }
  9297. #ifdef CONFIG_SPARC
  9298. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9299. {
  9300. struct net_device *dev = tp->dev;
  9301. struct pci_dev *pdev = tp->pdev;
  9302. struct device_node *dp = pci_device_to_OF_node(pdev);
  9303. const unsigned char *addr;
  9304. int len;
  9305. addr = of_get_property(dp, "local-mac-address", &len);
  9306. if (addr && len == 6) {
  9307. memcpy(dev->dev_addr, addr, 6);
  9308. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9309. return 0;
  9310. }
  9311. return -ENODEV;
  9312. }
  9313. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9314. {
  9315. struct net_device *dev = tp->dev;
  9316. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9317. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9318. return 0;
  9319. }
  9320. #endif
  9321. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9322. {
  9323. struct net_device *dev = tp->dev;
  9324. u32 hi, lo, mac_offset;
  9325. int addr_ok = 0;
  9326. #ifdef CONFIG_SPARC
  9327. if (!tg3_get_macaddr_sparc(tp))
  9328. return 0;
  9329. #endif
  9330. mac_offset = 0x7c;
  9331. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9332. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9333. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9334. mac_offset = 0xcc;
  9335. if (tg3_nvram_lock(tp))
  9336. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9337. else
  9338. tg3_nvram_unlock(tp);
  9339. }
  9340. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9341. mac_offset = 0x10;
  9342. /* First try to get it from MAC address mailbox. */
  9343. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9344. if ((hi >> 16) == 0x484b) {
  9345. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9346. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9347. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9348. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9349. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9350. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9351. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9352. /* Some old bootcode may report a 0 MAC address in SRAM */
  9353. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9354. }
  9355. if (!addr_ok) {
  9356. /* Next, try NVRAM. */
  9357. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9358. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9359. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9360. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9361. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9362. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9363. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9364. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9365. }
  9366. /* Finally just fetch it out of the MAC control regs. */
  9367. else {
  9368. hi = tr32(MAC_ADDR_0_HIGH);
  9369. lo = tr32(MAC_ADDR_0_LOW);
  9370. dev->dev_addr[5] = lo & 0xff;
  9371. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9372. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9373. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9374. dev->dev_addr[1] = hi & 0xff;
  9375. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9376. }
  9377. }
  9378. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9379. #ifdef CONFIG_SPARC64
  9380. if (!tg3_get_default_macaddr_sparc(tp))
  9381. return 0;
  9382. #endif
  9383. return -EINVAL;
  9384. }
  9385. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9386. return 0;
  9387. }
  9388. #define BOUNDARY_SINGLE_CACHELINE 1
  9389. #define BOUNDARY_MULTI_CACHELINE 2
  9390. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9391. {
  9392. int cacheline_size;
  9393. u8 byte;
  9394. int goal;
  9395. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9396. if (byte == 0)
  9397. cacheline_size = 1024;
  9398. else
  9399. cacheline_size = (int) byte * 4;
  9400. /* On 5703 and later chips, the boundary bits have no
  9401. * effect.
  9402. */
  9403. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9404. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9405. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9406. goto out;
  9407. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9408. goal = BOUNDARY_MULTI_CACHELINE;
  9409. #else
  9410. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9411. goal = BOUNDARY_SINGLE_CACHELINE;
  9412. #else
  9413. goal = 0;
  9414. #endif
  9415. #endif
  9416. if (!goal)
  9417. goto out;
  9418. /* PCI controllers on most RISC systems tend to disconnect
  9419. * when a device tries to burst across a cache-line boundary.
  9420. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9421. *
  9422. * Unfortunately, for PCI-E there are only limited
  9423. * write-side controls for this, and thus for reads
  9424. * we will still get the disconnects. We'll also waste
  9425. * these PCI cycles for both read and write for chips
  9426. * other than 5700 and 5701 which do not implement the
  9427. * boundary bits.
  9428. */
  9429. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9430. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9431. switch (cacheline_size) {
  9432. case 16:
  9433. case 32:
  9434. case 64:
  9435. case 128:
  9436. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9437. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9438. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9439. } else {
  9440. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9441. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9442. }
  9443. break;
  9444. case 256:
  9445. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9446. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9447. break;
  9448. default:
  9449. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9450. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9451. break;
  9452. };
  9453. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9454. switch (cacheline_size) {
  9455. case 16:
  9456. case 32:
  9457. case 64:
  9458. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9459. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9460. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9461. break;
  9462. }
  9463. /* fallthrough */
  9464. case 128:
  9465. default:
  9466. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9467. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9468. break;
  9469. };
  9470. } else {
  9471. switch (cacheline_size) {
  9472. case 16:
  9473. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9474. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9475. DMA_RWCTRL_WRITE_BNDRY_16);
  9476. break;
  9477. }
  9478. /* fallthrough */
  9479. case 32:
  9480. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9481. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9482. DMA_RWCTRL_WRITE_BNDRY_32);
  9483. break;
  9484. }
  9485. /* fallthrough */
  9486. case 64:
  9487. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9488. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9489. DMA_RWCTRL_WRITE_BNDRY_64);
  9490. break;
  9491. }
  9492. /* fallthrough */
  9493. case 128:
  9494. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9495. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9496. DMA_RWCTRL_WRITE_BNDRY_128);
  9497. break;
  9498. }
  9499. /* fallthrough */
  9500. case 256:
  9501. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9502. DMA_RWCTRL_WRITE_BNDRY_256);
  9503. break;
  9504. case 512:
  9505. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9506. DMA_RWCTRL_WRITE_BNDRY_512);
  9507. break;
  9508. case 1024:
  9509. default:
  9510. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9511. DMA_RWCTRL_WRITE_BNDRY_1024);
  9512. break;
  9513. };
  9514. }
  9515. out:
  9516. return val;
  9517. }
  9518. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9519. {
  9520. struct tg3_internal_buffer_desc test_desc;
  9521. u32 sram_dma_descs;
  9522. int i, ret;
  9523. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9524. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9525. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9526. tw32(RDMAC_STATUS, 0);
  9527. tw32(WDMAC_STATUS, 0);
  9528. tw32(BUFMGR_MODE, 0);
  9529. tw32(FTQ_RESET, 0);
  9530. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9531. test_desc.addr_lo = buf_dma & 0xffffffff;
  9532. test_desc.nic_mbuf = 0x00002100;
  9533. test_desc.len = size;
  9534. /*
  9535. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9536. * the *second* time the tg3 driver was getting loaded after an
  9537. * initial scan.
  9538. *
  9539. * Broadcom tells me:
  9540. * ...the DMA engine is connected to the GRC block and a DMA
  9541. * reset may affect the GRC block in some unpredictable way...
  9542. * The behavior of resets to individual blocks has not been tested.
  9543. *
  9544. * Broadcom noted the GRC reset will also reset all sub-components.
  9545. */
  9546. if (to_device) {
  9547. test_desc.cqid_sqid = (13 << 8) | 2;
  9548. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9549. udelay(40);
  9550. } else {
  9551. test_desc.cqid_sqid = (16 << 8) | 7;
  9552. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9553. udelay(40);
  9554. }
  9555. test_desc.flags = 0x00000005;
  9556. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9557. u32 val;
  9558. val = *(((u32 *)&test_desc) + i);
  9559. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9560. sram_dma_descs + (i * sizeof(u32)));
  9561. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9562. }
  9563. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9564. if (to_device) {
  9565. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9566. } else {
  9567. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9568. }
  9569. ret = -ENODEV;
  9570. for (i = 0; i < 40; i++) {
  9571. u32 val;
  9572. if (to_device)
  9573. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9574. else
  9575. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9576. if ((val & 0xffff) == sram_dma_descs) {
  9577. ret = 0;
  9578. break;
  9579. }
  9580. udelay(100);
  9581. }
  9582. return ret;
  9583. }
  9584. #define TEST_BUFFER_SIZE 0x2000
  9585. static int __devinit tg3_test_dma(struct tg3 *tp)
  9586. {
  9587. dma_addr_t buf_dma;
  9588. u32 *buf, saved_dma_rwctrl;
  9589. int ret;
  9590. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9591. if (!buf) {
  9592. ret = -ENOMEM;
  9593. goto out_nofree;
  9594. }
  9595. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9596. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9597. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9598. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9599. /* DMA read watermark not used on PCIE */
  9600. tp->dma_rwctrl |= 0x00180000;
  9601. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9602. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9603. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9604. tp->dma_rwctrl |= 0x003f0000;
  9605. else
  9606. tp->dma_rwctrl |= 0x003f000f;
  9607. } else {
  9608. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9609. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9610. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9611. u32 read_water = 0x7;
  9612. /* If the 5704 is behind the EPB bridge, we can
  9613. * do the less restrictive ONE_DMA workaround for
  9614. * better performance.
  9615. */
  9616. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9617. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9618. tp->dma_rwctrl |= 0x8000;
  9619. else if (ccval == 0x6 || ccval == 0x7)
  9620. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9621. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  9622. read_water = 4;
  9623. /* Set bit 23 to enable PCIX hw bug fix */
  9624. tp->dma_rwctrl |=
  9625. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  9626. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  9627. (1 << 23);
  9628. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9629. /* 5780 always in PCIX mode */
  9630. tp->dma_rwctrl |= 0x00144000;
  9631. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9632. /* 5714 always in PCIX mode */
  9633. tp->dma_rwctrl |= 0x00148000;
  9634. } else {
  9635. tp->dma_rwctrl |= 0x001b000f;
  9636. }
  9637. }
  9638. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9639. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9640. tp->dma_rwctrl &= 0xfffffff0;
  9641. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9642. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9643. /* Remove this if it causes problems for some boards. */
  9644. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9645. /* On 5700/5701 chips, we need to set this bit.
  9646. * Otherwise the chip will issue cacheline transactions
  9647. * to streamable DMA memory with not all the byte
  9648. * enables turned on. This is an error on several
  9649. * RISC PCI controllers, in particular sparc64.
  9650. *
  9651. * On 5703/5704 chips, this bit has been reassigned
  9652. * a different meaning. In particular, it is used
  9653. * on those chips to enable a PCI-X workaround.
  9654. */
  9655. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9656. }
  9657. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9658. #if 0
  9659. /* Unneeded, already done by tg3_get_invariants. */
  9660. tg3_switch_clocks(tp);
  9661. #endif
  9662. ret = 0;
  9663. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9664. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9665. goto out;
  9666. /* It is best to perform DMA test with maximum write burst size
  9667. * to expose the 5700/5701 write DMA bug.
  9668. */
  9669. saved_dma_rwctrl = tp->dma_rwctrl;
  9670. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9671. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9672. while (1) {
  9673. u32 *p = buf, i;
  9674. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9675. p[i] = i;
  9676. /* Send the buffer to the chip. */
  9677. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9678. if (ret) {
  9679. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9680. break;
  9681. }
  9682. #if 0
  9683. /* validate data reached card RAM correctly. */
  9684. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9685. u32 val;
  9686. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9687. if (le32_to_cpu(val) != p[i]) {
  9688. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9689. /* ret = -ENODEV here? */
  9690. }
  9691. p[i] = 0;
  9692. }
  9693. #endif
  9694. /* Now read it back. */
  9695. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9696. if (ret) {
  9697. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9698. break;
  9699. }
  9700. /* Verify it. */
  9701. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9702. if (p[i] == i)
  9703. continue;
  9704. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9705. DMA_RWCTRL_WRITE_BNDRY_16) {
  9706. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9707. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9708. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9709. break;
  9710. } else {
  9711. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9712. ret = -ENODEV;
  9713. goto out;
  9714. }
  9715. }
  9716. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9717. /* Success. */
  9718. ret = 0;
  9719. break;
  9720. }
  9721. }
  9722. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9723. DMA_RWCTRL_WRITE_BNDRY_16) {
  9724. static struct pci_device_id dma_wait_state_chipsets[] = {
  9725. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9726. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9727. { },
  9728. };
  9729. /* DMA test passed without adjusting DMA boundary,
  9730. * now look for chipsets that are known to expose the
  9731. * DMA bug without failing the test.
  9732. */
  9733. if (pci_dev_present(dma_wait_state_chipsets)) {
  9734. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9735. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9736. }
  9737. else
  9738. /* Safe to use the calculated DMA boundary. */
  9739. tp->dma_rwctrl = saved_dma_rwctrl;
  9740. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9741. }
  9742. out:
  9743. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9744. out_nofree:
  9745. return ret;
  9746. }
  9747. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9748. {
  9749. tp->link_config.advertising =
  9750. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9751. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9752. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9753. ADVERTISED_Autoneg | ADVERTISED_MII);
  9754. tp->link_config.speed = SPEED_INVALID;
  9755. tp->link_config.duplex = DUPLEX_INVALID;
  9756. tp->link_config.autoneg = AUTONEG_ENABLE;
  9757. tp->link_config.active_speed = SPEED_INVALID;
  9758. tp->link_config.active_duplex = DUPLEX_INVALID;
  9759. tp->link_config.phy_is_low_power = 0;
  9760. tp->link_config.orig_speed = SPEED_INVALID;
  9761. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9762. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9763. }
  9764. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9765. {
  9766. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9767. tp->bufmgr_config.mbuf_read_dma_low_water =
  9768. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9769. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9770. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9771. tp->bufmgr_config.mbuf_high_water =
  9772. DEFAULT_MB_HIGH_WATER_5705;
  9773. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9774. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9775. DEFAULT_MB_MACRX_LOW_WATER_5906;
  9776. tp->bufmgr_config.mbuf_high_water =
  9777. DEFAULT_MB_HIGH_WATER_5906;
  9778. }
  9779. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9780. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9781. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9782. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9783. tp->bufmgr_config.mbuf_high_water_jumbo =
  9784. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9785. } else {
  9786. tp->bufmgr_config.mbuf_read_dma_low_water =
  9787. DEFAULT_MB_RDMA_LOW_WATER;
  9788. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9789. DEFAULT_MB_MACRX_LOW_WATER;
  9790. tp->bufmgr_config.mbuf_high_water =
  9791. DEFAULT_MB_HIGH_WATER;
  9792. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9793. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9794. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9795. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9796. tp->bufmgr_config.mbuf_high_water_jumbo =
  9797. DEFAULT_MB_HIGH_WATER_JUMBO;
  9798. }
  9799. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9800. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9801. }
  9802. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9803. {
  9804. switch (tp->phy_id & PHY_ID_MASK) {
  9805. case PHY_ID_BCM5400: return "5400";
  9806. case PHY_ID_BCM5401: return "5401";
  9807. case PHY_ID_BCM5411: return "5411";
  9808. case PHY_ID_BCM5701: return "5701";
  9809. case PHY_ID_BCM5703: return "5703";
  9810. case PHY_ID_BCM5704: return "5704";
  9811. case PHY_ID_BCM5705: return "5705";
  9812. case PHY_ID_BCM5750: return "5750";
  9813. case PHY_ID_BCM5752: return "5752";
  9814. case PHY_ID_BCM5714: return "5714";
  9815. case PHY_ID_BCM5780: return "5780";
  9816. case PHY_ID_BCM5755: return "5755";
  9817. case PHY_ID_BCM5787: return "5787";
  9818. case PHY_ID_BCM5756: return "5722/5756";
  9819. case PHY_ID_BCM5906: return "5906";
  9820. case PHY_ID_BCM8002: return "8002/serdes";
  9821. case 0: return "serdes";
  9822. default: return "unknown";
  9823. };
  9824. }
  9825. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9826. {
  9827. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9828. strcpy(str, "PCI Express");
  9829. return str;
  9830. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9831. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9832. strcpy(str, "PCIX:");
  9833. if ((clock_ctrl == 7) ||
  9834. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9835. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9836. strcat(str, "133MHz");
  9837. else if (clock_ctrl == 0)
  9838. strcat(str, "33MHz");
  9839. else if (clock_ctrl == 2)
  9840. strcat(str, "50MHz");
  9841. else if (clock_ctrl == 4)
  9842. strcat(str, "66MHz");
  9843. else if (clock_ctrl == 6)
  9844. strcat(str, "100MHz");
  9845. } else {
  9846. strcpy(str, "PCI:");
  9847. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9848. strcat(str, "66MHz");
  9849. else
  9850. strcat(str, "33MHz");
  9851. }
  9852. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9853. strcat(str, ":32-bit");
  9854. else
  9855. strcat(str, ":64-bit");
  9856. return str;
  9857. }
  9858. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9859. {
  9860. struct pci_dev *peer;
  9861. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9862. for (func = 0; func < 8; func++) {
  9863. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9864. if (peer && peer != tp->pdev)
  9865. break;
  9866. pci_dev_put(peer);
  9867. }
  9868. /* 5704 can be configured in single-port mode, set peer to
  9869. * tp->pdev in that case.
  9870. */
  9871. if (!peer) {
  9872. peer = tp->pdev;
  9873. return peer;
  9874. }
  9875. /*
  9876. * We don't need to keep the refcount elevated; there's no way
  9877. * to remove one half of this device without removing the other
  9878. */
  9879. pci_dev_put(peer);
  9880. return peer;
  9881. }
  9882. static void __devinit tg3_init_coal(struct tg3 *tp)
  9883. {
  9884. struct ethtool_coalesce *ec = &tp->coal;
  9885. memset(ec, 0, sizeof(*ec));
  9886. ec->cmd = ETHTOOL_GCOALESCE;
  9887. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9888. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9889. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9890. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9891. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9892. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9893. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9894. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9895. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9896. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9897. HOSTCC_MODE_CLRTICK_TXBD)) {
  9898. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9899. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9900. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9901. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9902. }
  9903. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9904. ec->rx_coalesce_usecs_irq = 0;
  9905. ec->tx_coalesce_usecs_irq = 0;
  9906. ec->stats_block_coalesce_usecs = 0;
  9907. }
  9908. }
  9909. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9910. const struct pci_device_id *ent)
  9911. {
  9912. static int tg3_version_printed = 0;
  9913. unsigned long tg3reg_base, tg3reg_len;
  9914. struct net_device *dev;
  9915. struct tg3 *tp;
  9916. int i, err, pm_cap;
  9917. char str[40];
  9918. u64 dma_mask, persist_dma_mask;
  9919. if (tg3_version_printed++ == 0)
  9920. printk(KERN_INFO "%s", version);
  9921. err = pci_enable_device(pdev);
  9922. if (err) {
  9923. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9924. "aborting.\n");
  9925. return err;
  9926. }
  9927. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9928. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9929. "base address, aborting.\n");
  9930. err = -ENODEV;
  9931. goto err_out_disable_pdev;
  9932. }
  9933. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9934. if (err) {
  9935. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9936. "aborting.\n");
  9937. goto err_out_disable_pdev;
  9938. }
  9939. pci_set_master(pdev);
  9940. /* Find power-management capability. */
  9941. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9942. if (pm_cap == 0) {
  9943. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  9944. "aborting.\n");
  9945. err = -EIO;
  9946. goto err_out_free_res;
  9947. }
  9948. tg3reg_base = pci_resource_start(pdev, 0);
  9949. tg3reg_len = pci_resource_len(pdev, 0);
  9950. dev = alloc_etherdev(sizeof(*tp));
  9951. if (!dev) {
  9952. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  9953. err = -ENOMEM;
  9954. goto err_out_free_res;
  9955. }
  9956. SET_MODULE_OWNER(dev);
  9957. SET_NETDEV_DEV(dev, &pdev->dev);
  9958. #if TG3_VLAN_TAG_USED
  9959. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  9960. dev->vlan_rx_register = tg3_vlan_rx_register;
  9961. dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
  9962. #endif
  9963. tp = netdev_priv(dev);
  9964. tp->pdev = pdev;
  9965. tp->dev = dev;
  9966. tp->pm_cap = pm_cap;
  9967. tp->mac_mode = TG3_DEF_MAC_MODE;
  9968. tp->rx_mode = TG3_DEF_RX_MODE;
  9969. tp->tx_mode = TG3_DEF_TX_MODE;
  9970. tp->mi_mode = MAC_MI_MODE_BASE;
  9971. if (tg3_debug > 0)
  9972. tp->msg_enable = tg3_debug;
  9973. else
  9974. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  9975. /* The word/byte swap controls here control register access byte
  9976. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  9977. * setting below.
  9978. */
  9979. tp->misc_host_ctrl =
  9980. MISC_HOST_CTRL_MASK_PCI_INT |
  9981. MISC_HOST_CTRL_WORD_SWAP |
  9982. MISC_HOST_CTRL_INDIR_ACCESS |
  9983. MISC_HOST_CTRL_PCISTATE_RW;
  9984. /* The NONFRM (non-frame) byte/word swap controls take effect
  9985. * on descriptor entries, anything which isn't packet data.
  9986. *
  9987. * The StrongARM chips on the board (one for tx, one for rx)
  9988. * are running in big-endian mode.
  9989. */
  9990. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  9991. GRC_MODE_WSWAP_NONFRM_DATA);
  9992. #ifdef __BIG_ENDIAN
  9993. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  9994. #endif
  9995. spin_lock_init(&tp->lock);
  9996. spin_lock_init(&tp->indirect_lock);
  9997. INIT_WORK(&tp->reset_task, tg3_reset_task);
  9998. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  9999. if (tp->regs == 0UL) {
  10000. printk(KERN_ERR PFX "Cannot map device registers, "
  10001. "aborting.\n");
  10002. err = -ENOMEM;
  10003. goto err_out_free_dev;
  10004. }
  10005. tg3_init_link_config(tp);
  10006. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10007. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10008. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10009. dev->open = tg3_open;
  10010. dev->stop = tg3_close;
  10011. dev->get_stats = tg3_get_stats;
  10012. dev->set_multicast_list = tg3_set_rx_mode;
  10013. dev->set_mac_address = tg3_set_mac_addr;
  10014. dev->do_ioctl = tg3_ioctl;
  10015. dev->tx_timeout = tg3_tx_timeout;
  10016. dev->poll = tg3_poll;
  10017. dev->ethtool_ops = &tg3_ethtool_ops;
  10018. dev->weight = 64;
  10019. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10020. dev->change_mtu = tg3_change_mtu;
  10021. dev->irq = pdev->irq;
  10022. #ifdef CONFIG_NET_POLL_CONTROLLER
  10023. dev->poll_controller = tg3_poll_controller;
  10024. #endif
  10025. err = tg3_get_invariants(tp);
  10026. if (err) {
  10027. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10028. "aborting.\n");
  10029. goto err_out_iounmap;
  10030. }
  10031. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10032. * device behind the EPB cannot support DMA addresses > 40-bit.
  10033. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10034. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10035. * do DMA address check in tg3_start_xmit().
  10036. */
  10037. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10038. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10039. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10040. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10041. #ifdef CONFIG_HIGHMEM
  10042. dma_mask = DMA_64BIT_MASK;
  10043. #endif
  10044. } else
  10045. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10046. /* Configure DMA attributes. */
  10047. if (dma_mask > DMA_32BIT_MASK) {
  10048. err = pci_set_dma_mask(pdev, dma_mask);
  10049. if (!err) {
  10050. dev->features |= NETIF_F_HIGHDMA;
  10051. err = pci_set_consistent_dma_mask(pdev,
  10052. persist_dma_mask);
  10053. if (err < 0) {
  10054. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10055. "DMA for consistent allocations\n");
  10056. goto err_out_iounmap;
  10057. }
  10058. }
  10059. }
  10060. if (err || dma_mask == DMA_32BIT_MASK) {
  10061. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10062. if (err) {
  10063. printk(KERN_ERR PFX "No usable DMA configuration, "
  10064. "aborting.\n");
  10065. goto err_out_iounmap;
  10066. }
  10067. }
  10068. tg3_init_bufmgr_config(tp);
  10069. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10070. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10071. }
  10072. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10073. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10074. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10075. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10076. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10077. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10078. } else {
  10079. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10080. }
  10081. /* TSO is on by default on chips that support hardware TSO.
  10082. * Firmware TSO on older chips gives lower performance, so it
  10083. * is off by default, but can be enabled using ethtool.
  10084. */
  10085. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10086. dev->features |= NETIF_F_TSO;
  10087. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10088. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10089. dev->features |= NETIF_F_TSO6;
  10090. }
  10091. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10092. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10093. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10094. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10095. tp->rx_pending = 63;
  10096. }
  10097. err = tg3_get_device_address(tp);
  10098. if (err) {
  10099. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10100. "aborting.\n");
  10101. goto err_out_iounmap;
  10102. }
  10103. /*
  10104. * Reset chip in case UNDI or EFI driver did not shutdown
  10105. * DMA self test will enable WDMAC and we'll see (spurious)
  10106. * pending DMA on the PCI bus at that point.
  10107. */
  10108. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10109. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10110. pci_save_state(tp->pdev);
  10111. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10112. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10113. }
  10114. err = tg3_test_dma(tp);
  10115. if (err) {
  10116. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10117. goto err_out_iounmap;
  10118. }
  10119. /* Tigon3 can do ipv4 only... and some chips have buggy
  10120. * checksumming.
  10121. */
  10122. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10123. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10124. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  10125. dev->features |= NETIF_F_HW_CSUM;
  10126. else
  10127. dev->features |= NETIF_F_IP_CSUM;
  10128. dev->features |= NETIF_F_SG;
  10129. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10130. } else
  10131. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10132. /* flow control autonegotiation is default behavior */
  10133. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10134. tg3_init_coal(tp);
  10135. /* Now that we have fully setup the chip, save away a snapshot
  10136. * of the PCI config space. We need to restore this after
  10137. * GRC_MISC_CFG core clock resets and some resume events.
  10138. */
  10139. pci_save_state(tp->pdev);
  10140. pci_set_drvdata(pdev, dev);
  10141. err = register_netdev(dev);
  10142. if (err) {
  10143. printk(KERN_ERR PFX "Cannot register net device, "
  10144. "aborting.\n");
  10145. goto err_out_iounmap;
  10146. }
  10147. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ",
  10148. dev->name,
  10149. tp->board_part_number,
  10150. tp->pci_chip_rev_id,
  10151. tg3_phy_string(tp),
  10152. tg3_bus_string(tp, str),
  10153. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10154. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10155. "10/100/1000Base-T")));
  10156. for (i = 0; i < 6; i++)
  10157. printk("%2.2x%c", dev->dev_addr[i],
  10158. i == 5 ? '\n' : ':');
  10159. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10160. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10161. dev->name,
  10162. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10163. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10164. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10165. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10166. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10167. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10168. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10169. dev->name, tp->dma_rwctrl,
  10170. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10171. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10172. return 0;
  10173. err_out_iounmap:
  10174. if (tp->regs) {
  10175. iounmap(tp->regs);
  10176. tp->regs = NULL;
  10177. }
  10178. err_out_free_dev:
  10179. free_netdev(dev);
  10180. err_out_free_res:
  10181. pci_release_regions(pdev);
  10182. err_out_disable_pdev:
  10183. pci_disable_device(pdev);
  10184. pci_set_drvdata(pdev, NULL);
  10185. return err;
  10186. }
  10187. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10188. {
  10189. struct net_device *dev = pci_get_drvdata(pdev);
  10190. if (dev) {
  10191. struct tg3 *tp = netdev_priv(dev);
  10192. flush_scheduled_work();
  10193. unregister_netdev(dev);
  10194. if (tp->regs) {
  10195. iounmap(tp->regs);
  10196. tp->regs = NULL;
  10197. }
  10198. free_netdev(dev);
  10199. pci_release_regions(pdev);
  10200. pci_disable_device(pdev);
  10201. pci_set_drvdata(pdev, NULL);
  10202. }
  10203. }
  10204. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10205. {
  10206. struct net_device *dev = pci_get_drvdata(pdev);
  10207. struct tg3 *tp = netdev_priv(dev);
  10208. int err;
  10209. if (!netif_running(dev))
  10210. return 0;
  10211. flush_scheduled_work();
  10212. tg3_netif_stop(tp);
  10213. del_timer_sync(&tp->timer);
  10214. tg3_full_lock(tp, 1);
  10215. tg3_disable_ints(tp);
  10216. tg3_full_unlock(tp);
  10217. netif_device_detach(dev);
  10218. tg3_full_lock(tp, 0);
  10219. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10220. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  10221. tg3_full_unlock(tp);
  10222. /* Save MSI address and data for resume. */
  10223. pci_save_state(pdev);
  10224. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  10225. if (err) {
  10226. tg3_full_lock(tp, 0);
  10227. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10228. if (tg3_restart_hw(tp, 1))
  10229. goto out;
  10230. tp->timer.expires = jiffies + tp->timer_offset;
  10231. add_timer(&tp->timer);
  10232. netif_device_attach(dev);
  10233. tg3_netif_start(tp);
  10234. out:
  10235. tg3_full_unlock(tp);
  10236. }
  10237. return err;
  10238. }
  10239. static int tg3_resume(struct pci_dev *pdev)
  10240. {
  10241. struct net_device *dev = pci_get_drvdata(pdev);
  10242. struct tg3 *tp = netdev_priv(dev);
  10243. int err;
  10244. if (!netif_running(dev))
  10245. return 0;
  10246. pci_restore_state(tp->pdev);
  10247. err = tg3_set_power_state(tp, PCI_D0);
  10248. if (err)
  10249. return err;
  10250. netif_device_attach(dev);
  10251. tg3_full_lock(tp, 0);
  10252. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10253. err = tg3_restart_hw(tp, 1);
  10254. if (err)
  10255. goto out;
  10256. tp->timer.expires = jiffies + tp->timer_offset;
  10257. add_timer(&tp->timer);
  10258. tg3_netif_start(tp);
  10259. out:
  10260. tg3_full_unlock(tp);
  10261. return err;
  10262. }
  10263. static struct pci_driver tg3_driver = {
  10264. .name = DRV_MODULE_NAME,
  10265. .id_table = tg3_pci_tbl,
  10266. .probe = tg3_init_one,
  10267. .remove = __devexit_p(tg3_remove_one),
  10268. .suspend = tg3_suspend,
  10269. .resume = tg3_resume
  10270. };
  10271. static int __init tg3_init(void)
  10272. {
  10273. return pci_register_driver(&tg3_driver);
  10274. }
  10275. static void __exit tg3_cleanup(void)
  10276. {
  10277. pci_unregister_driver(&tg3_driver);
  10278. }
  10279. module_init(tg3_init);
  10280. module_exit(tg3_cleanup);