tg3.c 373 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095
  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.91"
  59. #define DRV_MODULE_RELDATE "April 18, 2008"
  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_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  184. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  185. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  186. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  187. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  188. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  189. {}
  190. };
  191. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  192. static const struct {
  193. const char string[ETH_GSTRING_LEN];
  194. } ethtool_stats_keys[TG3_NUM_STATS] = {
  195. { "rx_octets" },
  196. { "rx_fragments" },
  197. { "rx_ucast_packets" },
  198. { "rx_mcast_packets" },
  199. { "rx_bcast_packets" },
  200. { "rx_fcs_errors" },
  201. { "rx_align_errors" },
  202. { "rx_xon_pause_rcvd" },
  203. { "rx_xoff_pause_rcvd" },
  204. { "rx_mac_ctrl_rcvd" },
  205. { "rx_xoff_entered" },
  206. { "rx_frame_too_long_errors" },
  207. { "rx_jabbers" },
  208. { "rx_undersize_packets" },
  209. { "rx_in_length_errors" },
  210. { "rx_out_length_errors" },
  211. { "rx_64_or_less_octet_packets" },
  212. { "rx_65_to_127_octet_packets" },
  213. { "rx_128_to_255_octet_packets" },
  214. { "rx_256_to_511_octet_packets" },
  215. { "rx_512_to_1023_octet_packets" },
  216. { "rx_1024_to_1522_octet_packets" },
  217. { "rx_1523_to_2047_octet_packets" },
  218. { "rx_2048_to_4095_octet_packets" },
  219. { "rx_4096_to_8191_octet_packets" },
  220. { "rx_8192_to_9022_octet_packets" },
  221. { "tx_octets" },
  222. { "tx_collisions" },
  223. { "tx_xon_sent" },
  224. { "tx_xoff_sent" },
  225. { "tx_flow_control" },
  226. { "tx_mac_errors" },
  227. { "tx_single_collisions" },
  228. { "tx_mult_collisions" },
  229. { "tx_deferred" },
  230. { "tx_excessive_collisions" },
  231. { "tx_late_collisions" },
  232. { "tx_collide_2times" },
  233. { "tx_collide_3times" },
  234. { "tx_collide_4times" },
  235. { "tx_collide_5times" },
  236. { "tx_collide_6times" },
  237. { "tx_collide_7times" },
  238. { "tx_collide_8times" },
  239. { "tx_collide_9times" },
  240. { "tx_collide_10times" },
  241. { "tx_collide_11times" },
  242. { "tx_collide_12times" },
  243. { "tx_collide_13times" },
  244. { "tx_collide_14times" },
  245. { "tx_collide_15times" },
  246. { "tx_ucast_packets" },
  247. { "tx_mcast_packets" },
  248. { "tx_bcast_packets" },
  249. { "tx_carrier_sense_errors" },
  250. { "tx_discards" },
  251. { "tx_errors" },
  252. { "dma_writeq_full" },
  253. { "dma_write_prioq_full" },
  254. { "rxbds_empty" },
  255. { "rx_discards" },
  256. { "rx_errors" },
  257. { "rx_threshold_hit" },
  258. { "dma_readq_full" },
  259. { "dma_read_prioq_full" },
  260. { "tx_comp_queue_full" },
  261. { "ring_set_send_prod_index" },
  262. { "ring_status_update" },
  263. { "nic_irqs" },
  264. { "nic_avoided_irqs" },
  265. { "nic_tx_threshold_hit" }
  266. };
  267. static const struct {
  268. const char string[ETH_GSTRING_LEN];
  269. } ethtool_test_keys[TG3_NUM_TEST] = {
  270. { "nvram test (online) " },
  271. { "link test (online) " },
  272. { "register test (offline)" },
  273. { "memory test (offline)" },
  274. { "loopback test (offline)" },
  275. { "interrupt test (offline)" },
  276. };
  277. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  278. {
  279. writel(val, tp->regs + off);
  280. }
  281. static u32 tg3_read32(struct tg3 *tp, u32 off)
  282. {
  283. return (readl(tp->regs + off));
  284. }
  285. static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val)
  286. {
  287. writel(val, tp->aperegs + off);
  288. }
  289. static u32 tg3_ape_read32(struct tg3 *tp, u32 off)
  290. {
  291. return (readl(tp->aperegs + off));
  292. }
  293. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  294. {
  295. unsigned long flags;
  296. spin_lock_irqsave(&tp->indirect_lock, flags);
  297. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  298. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  299. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  300. }
  301. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  302. {
  303. writel(val, tp->regs + off);
  304. readl(tp->regs + off);
  305. }
  306. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  307. {
  308. unsigned long flags;
  309. u32 val;
  310. spin_lock_irqsave(&tp->indirect_lock, flags);
  311. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  312. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  313. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  314. return val;
  315. }
  316. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  317. {
  318. unsigned long flags;
  319. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  320. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  321. TG3_64BIT_REG_LOW, val);
  322. return;
  323. }
  324. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  325. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  326. TG3_64BIT_REG_LOW, val);
  327. return;
  328. }
  329. spin_lock_irqsave(&tp->indirect_lock, flags);
  330. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  331. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  332. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  333. /* In indirect mode when disabling interrupts, we also need
  334. * to clear the interrupt bit in the GRC local ctrl register.
  335. */
  336. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  337. (val == 0x1)) {
  338. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  339. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  340. }
  341. }
  342. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  343. {
  344. unsigned long flags;
  345. u32 val;
  346. spin_lock_irqsave(&tp->indirect_lock, flags);
  347. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  348. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  349. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  350. return val;
  351. }
  352. /* usec_wait specifies the wait time in usec when writing to certain registers
  353. * where it is unsafe to read back the register without some delay.
  354. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  355. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  356. */
  357. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  358. {
  359. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  360. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  361. /* Non-posted methods */
  362. tp->write32(tp, off, val);
  363. else {
  364. /* Posted method */
  365. tg3_write32(tp, off, val);
  366. if (usec_wait)
  367. udelay(usec_wait);
  368. tp->read32(tp, off);
  369. }
  370. /* Wait again after the read for the posted method to guarantee that
  371. * the wait time is met.
  372. */
  373. if (usec_wait)
  374. udelay(usec_wait);
  375. }
  376. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  377. {
  378. tp->write32_mbox(tp, off, val);
  379. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  380. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  381. tp->read32_mbox(tp, off);
  382. }
  383. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  384. {
  385. void __iomem *mbox = tp->regs + off;
  386. writel(val, mbox);
  387. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  388. writel(val, mbox);
  389. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  390. readl(mbox);
  391. }
  392. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  393. {
  394. return (readl(tp->regs + off + GRCMBOX_BASE));
  395. }
  396. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  397. {
  398. writel(val, tp->regs + off + GRCMBOX_BASE);
  399. }
  400. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  401. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  402. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  403. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  404. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  405. #define tw32(reg,val) tp->write32(tp, reg, val)
  406. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  407. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  408. #define tr32(reg) tp->read32(tp, reg)
  409. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  410. {
  411. unsigned long flags;
  412. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  413. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  414. return;
  415. spin_lock_irqsave(&tp->indirect_lock, flags);
  416. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  417. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  418. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  419. /* Always leave this as zero. */
  420. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  421. } else {
  422. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  423. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  424. /* Always leave this as zero. */
  425. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  426. }
  427. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  428. }
  429. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  430. {
  431. unsigned long flags;
  432. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  433. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  434. *val = 0;
  435. return;
  436. }
  437. spin_lock_irqsave(&tp->indirect_lock, flags);
  438. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  439. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  440. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  441. /* Always leave this as zero. */
  442. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  443. } else {
  444. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  445. *val = tr32(TG3PCI_MEM_WIN_DATA);
  446. /* Always leave this as zero. */
  447. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  448. }
  449. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  450. }
  451. static void tg3_ape_lock_init(struct tg3 *tp)
  452. {
  453. int i;
  454. /* Make sure the driver hasn't any stale locks. */
  455. for (i = 0; i < 8; i++)
  456. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + 4 * i,
  457. APE_LOCK_GRANT_DRIVER);
  458. }
  459. static int tg3_ape_lock(struct tg3 *tp, int locknum)
  460. {
  461. int i, off;
  462. int ret = 0;
  463. u32 status;
  464. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  465. return 0;
  466. switch (locknum) {
  467. case TG3_APE_LOCK_MEM:
  468. break;
  469. default:
  470. return -EINVAL;
  471. }
  472. off = 4 * locknum;
  473. tg3_ape_write32(tp, TG3_APE_LOCK_REQ + off, APE_LOCK_REQ_DRIVER);
  474. /* Wait for up to 1 millisecond to acquire lock. */
  475. for (i = 0; i < 100; i++) {
  476. status = tg3_ape_read32(tp, TG3_APE_LOCK_GRANT + off);
  477. if (status == APE_LOCK_GRANT_DRIVER)
  478. break;
  479. udelay(10);
  480. }
  481. if (status != APE_LOCK_GRANT_DRIVER) {
  482. /* Revoke the lock request. */
  483. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off,
  484. APE_LOCK_GRANT_DRIVER);
  485. ret = -EBUSY;
  486. }
  487. return ret;
  488. }
  489. static void tg3_ape_unlock(struct tg3 *tp, int locknum)
  490. {
  491. int off;
  492. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  493. return;
  494. switch (locknum) {
  495. case TG3_APE_LOCK_MEM:
  496. break;
  497. default:
  498. return;
  499. }
  500. off = 4 * locknum;
  501. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off, APE_LOCK_GRANT_DRIVER);
  502. }
  503. static void tg3_disable_ints(struct tg3 *tp)
  504. {
  505. tw32(TG3PCI_MISC_HOST_CTRL,
  506. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  507. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  508. }
  509. static inline void tg3_cond_int(struct tg3 *tp)
  510. {
  511. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  512. (tp->hw_status->status & SD_STATUS_UPDATED))
  513. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  514. else
  515. tw32(HOSTCC_MODE, tp->coalesce_mode |
  516. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  517. }
  518. static void tg3_enable_ints(struct tg3 *tp)
  519. {
  520. tp->irq_sync = 0;
  521. wmb();
  522. tw32(TG3PCI_MISC_HOST_CTRL,
  523. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  524. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  525. (tp->last_tag << 24));
  526. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  527. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  528. (tp->last_tag << 24));
  529. tg3_cond_int(tp);
  530. }
  531. static inline unsigned int tg3_has_work(struct tg3 *tp)
  532. {
  533. struct tg3_hw_status *sblk = tp->hw_status;
  534. unsigned int work_exists = 0;
  535. /* check for phy events */
  536. if (!(tp->tg3_flags &
  537. (TG3_FLAG_USE_LINKCHG_REG |
  538. TG3_FLAG_POLL_SERDES))) {
  539. if (sblk->status & SD_STATUS_LINK_CHG)
  540. work_exists = 1;
  541. }
  542. /* check for RX/TX work to do */
  543. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  544. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  545. work_exists = 1;
  546. return work_exists;
  547. }
  548. /* tg3_restart_ints
  549. * similar to tg3_enable_ints, but it accurately determines whether there
  550. * is new work pending and can return without flushing the PIO write
  551. * which reenables interrupts
  552. */
  553. static void tg3_restart_ints(struct tg3 *tp)
  554. {
  555. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  556. tp->last_tag << 24);
  557. mmiowb();
  558. /* When doing tagged status, this work check is unnecessary.
  559. * The last_tag we write above tells the chip which piece of
  560. * work we've completed.
  561. */
  562. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  563. tg3_has_work(tp))
  564. tw32(HOSTCC_MODE, tp->coalesce_mode |
  565. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  566. }
  567. static inline void tg3_netif_stop(struct tg3 *tp)
  568. {
  569. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  570. napi_disable(&tp->napi);
  571. netif_tx_disable(tp->dev);
  572. }
  573. static inline void tg3_netif_start(struct tg3 *tp)
  574. {
  575. netif_wake_queue(tp->dev);
  576. /* NOTE: unconditional netif_wake_queue is only appropriate
  577. * so long as all callers are assured to have free tx slots
  578. * (such as after tg3_init_hw)
  579. */
  580. napi_enable(&tp->napi);
  581. tp->hw_status->status |= SD_STATUS_UPDATED;
  582. tg3_enable_ints(tp);
  583. }
  584. static void tg3_switch_clocks(struct tg3 *tp)
  585. {
  586. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  587. u32 orig_clock_ctrl;
  588. if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
  589. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  590. return;
  591. orig_clock_ctrl = clock_ctrl;
  592. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  593. CLOCK_CTRL_CLKRUN_OENABLE |
  594. 0x1f);
  595. tp->pci_clock_ctrl = clock_ctrl;
  596. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  597. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  598. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  599. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  600. }
  601. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  602. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  603. clock_ctrl |
  604. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  605. 40);
  606. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  607. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  608. 40);
  609. }
  610. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  611. }
  612. #define PHY_BUSY_LOOPS 5000
  613. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  614. {
  615. u32 frame_val;
  616. unsigned int loops;
  617. int ret;
  618. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  619. tw32_f(MAC_MI_MODE,
  620. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  621. udelay(80);
  622. }
  623. *val = 0x0;
  624. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  625. MI_COM_PHY_ADDR_MASK);
  626. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  627. MI_COM_REG_ADDR_MASK);
  628. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  629. tw32_f(MAC_MI_COM, frame_val);
  630. loops = PHY_BUSY_LOOPS;
  631. while (loops != 0) {
  632. udelay(10);
  633. frame_val = tr32(MAC_MI_COM);
  634. if ((frame_val & MI_COM_BUSY) == 0) {
  635. udelay(5);
  636. frame_val = tr32(MAC_MI_COM);
  637. break;
  638. }
  639. loops -= 1;
  640. }
  641. ret = -EBUSY;
  642. if (loops != 0) {
  643. *val = frame_val & MI_COM_DATA_MASK;
  644. ret = 0;
  645. }
  646. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  647. tw32_f(MAC_MI_MODE, tp->mi_mode);
  648. udelay(80);
  649. }
  650. return ret;
  651. }
  652. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  653. {
  654. u32 frame_val;
  655. unsigned int loops;
  656. int ret;
  657. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  658. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  659. return 0;
  660. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  661. tw32_f(MAC_MI_MODE,
  662. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  663. udelay(80);
  664. }
  665. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  666. MI_COM_PHY_ADDR_MASK);
  667. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  668. MI_COM_REG_ADDR_MASK);
  669. frame_val |= (val & MI_COM_DATA_MASK);
  670. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  671. tw32_f(MAC_MI_COM, frame_val);
  672. loops = PHY_BUSY_LOOPS;
  673. while (loops != 0) {
  674. udelay(10);
  675. frame_val = tr32(MAC_MI_COM);
  676. if ((frame_val & MI_COM_BUSY) == 0) {
  677. udelay(5);
  678. frame_val = tr32(MAC_MI_COM);
  679. break;
  680. }
  681. loops -= 1;
  682. }
  683. ret = -EBUSY;
  684. if (loops != 0)
  685. ret = 0;
  686. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  687. tw32_f(MAC_MI_MODE, tp->mi_mode);
  688. udelay(80);
  689. }
  690. return ret;
  691. }
  692. static void tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val)
  693. {
  694. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg);
  695. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val);
  696. }
  697. static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
  698. {
  699. u32 phy;
  700. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  701. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  702. return;
  703. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  704. u32 ephy;
  705. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &ephy)) {
  706. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  707. ephy | MII_TG3_EPHY_SHADOW_EN);
  708. if (!tg3_readphy(tp, MII_TG3_EPHYTST_MISCCTRL, &phy)) {
  709. if (enable)
  710. phy |= MII_TG3_EPHYTST_MISCCTRL_MDIX;
  711. else
  712. phy &= ~MII_TG3_EPHYTST_MISCCTRL_MDIX;
  713. tg3_writephy(tp, MII_TG3_EPHYTST_MISCCTRL, phy);
  714. }
  715. tg3_writephy(tp, MII_TG3_EPHY_TEST, ephy);
  716. }
  717. } else {
  718. phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
  719. MII_TG3_AUXCTL_SHDWSEL_MISC;
  720. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
  721. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
  722. if (enable)
  723. phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  724. else
  725. phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  726. phy |= MII_TG3_AUXCTL_MISC_WREN;
  727. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  728. }
  729. }
  730. }
  731. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  732. {
  733. u32 val;
  734. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  735. return;
  736. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  737. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  738. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  739. (val | (1 << 15) | (1 << 4)));
  740. }
  741. static int tg3_bmcr_reset(struct tg3 *tp)
  742. {
  743. u32 phy_control;
  744. int limit, err;
  745. /* OK, reset it, and poll the BMCR_RESET bit until it
  746. * clears or we time out.
  747. */
  748. phy_control = BMCR_RESET;
  749. err = tg3_writephy(tp, MII_BMCR, phy_control);
  750. if (err != 0)
  751. return -EBUSY;
  752. limit = 5000;
  753. while (limit--) {
  754. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  755. if (err != 0)
  756. return -EBUSY;
  757. if ((phy_control & BMCR_RESET) == 0) {
  758. udelay(40);
  759. break;
  760. }
  761. udelay(10);
  762. }
  763. if (limit <= 0)
  764. return -EBUSY;
  765. return 0;
  766. }
  767. static void tg3_phy_apply_otp(struct tg3 *tp)
  768. {
  769. u32 otp, phy;
  770. if (!tp->phy_otp)
  771. return;
  772. otp = tp->phy_otp;
  773. /* Enable SM_DSP clock and tx 6dB coding. */
  774. phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
  775. MII_TG3_AUXCTL_ACTL_SMDSP_ENA |
  776. MII_TG3_AUXCTL_ACTL_TX_6DB;
  777. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  778. phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT);
  779. phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT;
  780. tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy);
  781. phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) |
  782. ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT);
  783. tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy);
  784. phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT);
  785. phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ;
  786. tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy);
  787. phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT);
  788. tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy);
  789. phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT);
  790. tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy);
  791. phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) |
  792. ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT);
  793. tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy);
  794. /* Turn off SM_DSP clock. */
  795. phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
  796. MII_TG3_AUXCTL_ACTL_TX_6DB;
  797. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  798. }
  799. static int tg3_wait_macro_done(struct tg3 *tp)
  800. {
  801. int limit = 100;
  802. while (limit--) {
  803. u32 tmp32;
  804. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  805. if ((tmp32 & 0x1000) == 0)
  806. break;
  807. }
  808. }
  809. if (limit <= 0)
  810. return -EBUSY;
  811. return 0;
  812. }
  813. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  814. {
  815. static const u32 test_pat[4][6] = {
  816. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  817. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  818. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  819. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  820. };
  821. int chan;
  822. for (chan = 0; chan < 4; chan++) {
  823. int i;
  824. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  825. (chan * 0x2000) | 0x0200);
  826. tg3_writephy(tp, 0x16, 0x0002);
  827. for (i = 0; i < 6; i++)
  828. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  829. test_pat[chan][i]);
  830. tg3_writephy(tp, 0x16, 0x0202);
  831. if (tg3_wait_macro_done(tp)) {
  832. *resetp = 1;
  833. return -EBUSY;
  834. }
  835. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  836. (chan * 0x2000) | 0x0200);
  837. tg3_writephy(tp, 0x16, 0x0082);
  838. if (tg3_wait_macro_done(tp)) {
  839. *resetp = 1;
  840. return -EBUSY;
  841. }
  842. tg3_writephy(tp, 0x16, 0x0802);
  843. if (tg3_wait_macro_done(tp)) {
  844. *resetp = 1;
  845. return -EBUSY;
  846. }
  847. for (i = 0; i < 6; i += 2) {
  848. u32 low, high;
  849. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  850. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  851. tg3_wait_macro_done(tp)) {
  852. *resetp = 1;
  853. return -EBUSY;
  854. }
  855. low &= 0x7fff;
  856. high &= 0x000f;
  857. if (low != test_pat[chan][i] ||
  858. high != test_pat[chan][i+1]) {
  859. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  860. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  861. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  862. return -EBUSY;
  863. }
  864. }
  865. }
  866. return 0;
  867. }
  868. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  869. {
  870. int chan;
  871. for (chan = 0; chan < 4; chan++) {
  872. int i;
  873. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  874. (chan * 0x2000) | 0x0200);
  875. tg3_writephy(tp, 0x16, 0x0002);
  876. for (i = 0; i < 6; i++)
  877. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  878. tg3_writephy(tp, 0x16, 0x0202);
  879. if (tg3_wait_macro_done(tp))
  880. return -EBUSY;
  881. }
  882. return 0;
  883. }
  884. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  885. {
  886. u32 reg32, phy9_orig;
  887. int retries, do_phy_reset, err;
  888. retries = 10;
  889. do_phy_reset = 1;
  890. do {
  891. if (do_phy_reset) {
  892. err = tg3_bmcr_reset(tp);
  893. if (err)
  894. return err;
  895. do_phy_reset = 0;
  896. }
  897. /* Disable transmitter and interrupt. */
  898. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  899. continue;
  900. reg32 |= 0x3000;
  901. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  902. /* Set full-duplex, 1000 mbps. */
  903. tg3_writephy(tp, MII_BMCR,
  904. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  905. /* Set to master mode. */
  906. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  907. continue;
  908. tg3_writephy(tp, MII_TG3_CTRL,
  909. (MII_TG3_CTRL_AS_MASTER |
  910. MII_TG3_CTRL_ENABLE_AS_MASTER));
  911. /* Enable SM_DSP_CLOCK and 6dB. */
  912. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  913. /* Block the PHY control access. */
  914. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  915. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  916. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  917. if (!err)
  918. break;
  919. } while (--retries);
  920. err = tg3_phy_reset_chanpat(tp);
  921. if (err)
  922. return err;
  923. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  924. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  925. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  926. tg3_writephy(tp, 0x16, 0x0000);
  927. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  928. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  929. /* Set Extended packet length bit for jumbo frames */
  930. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  931. }
  932. else {
  933. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  934. }
  935. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  936. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  937. reg32 &= ~0x3000;
  938. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  939. } else if (!err)
  940. err = -EBUSY;
  941. return err;
  942. }
  943. static void tg3_link_report(struct tg3 *);
  944. /* This will reset the tigon3 PHY if there is no valid
  945. * link unless the FORCE argument is non-zero.
  946. */
  947. static int tg3_phy_reset(struct tg3 *tp)
  948. {
  949. u32 cpmuctrl;
  950. u32 phy_status;
  951. int err;
  952. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  953. u32 val;
  954. val = tr32(GRC_MISC_CFG);
  955. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  956. udelay(40);
  957. }
  958. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  959. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  960. if (err != 0)
  961. return -EBUSY;
  962. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  963. netif_carrier_off(tp->dev);
  964. tg3_link_report(tp);
  965. }
  966. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  967. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  968. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  969. err = tg3_phy_reset_5703_4_5(tp);
  970. if (err)
  971. return err;
  972. goto out;
  973. }
  974. cpmuctrl = 0;
  975. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
  976. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
  977. cpmuctrl = tr32(TG3_CPMU_CTRL);
  978. if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY)
  979. tw32(TG3_CPMU_CTRL,
  980. cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY);
  981. }
  982. err = tg3_bmcr_reset(tp);
  983. if (err)
  984. return err;
  985. if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) {
  986. u32 phy;
  987. phy = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz;
  988. tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, phy);
  989. tw32(TG3_CPMU_CTRL, cpmuctrl);
  990. }
  991. if (tp->tg3_flags3 & TG3_FLG3_5761_5784_AX_FIXES) {
  992. u32 val;
  993. val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
  994. if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) ==
  995. CPMU_LSPD_1000MB_MACCLK_12_5) {
  996. val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
  997. udelay(40);
  998. tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
  999. }
  1000. /* Disable GPHY autopowerdown. */
  1001. tg3_writephy(tp, MII_TG3_MISC_SHDW,
  1002. MII_TG3_MISC_SHDW_WREN |
  1003. MII_TG3_MISC_SHDW_APD_SEL |
  1004. MII_TG3_MISC_SHDW_APD_WKTM_84MS);
  1005. }
  1006. tg3_phy_apply_otp(tp);
  1007. out:
  1008. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  1009. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1010. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1011. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  1012. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1013. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  1014. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1015. }
  1016. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  1017. tg3_writephy(tp, 0x1c, 0x8d68);
  1018. tg3_writephy(tp, 0x1c, 0x8d68);
  1019. }
  1020. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  1021. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1022. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1023. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  1024. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1025. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  1026. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  1027. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  1028. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1029. }
  1030. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  1031. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1032. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1033. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  1034. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  1035. tg3_writephy(tp, MII_TG3_TEST1,
  1036. MII_TG3_TEST1_TRIM_EN | 0x4);
  1037. } else
  1038. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  1039. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1040. }
  1041. /* Set Extended packet length bit (bit 14) on all chips that */
  1042. /* support jumbo frames */
  1043. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1044. /* Cannot do read-modify-write on 5401 */
  1045. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1046. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  1047. u32 phy_reg;
  1048. /* Set bit 14 with read-modify-write to preserve other bits */
  1049. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  1050. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  1051. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  1052. }
  1053. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  1054. * jumbo frames transmission.
  1055. */
  1056. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  1057. u32 phy_reg;
  1058. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  1059. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1060. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  1061. }
  1062. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1063. /* adjust output voltage */
  1064. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  1065. }
  1066. tg3_phy_toggle_automdix(tp, 1);
  1067. tg3_phy_set_wirespeed(tp);
  1068. return 0;
  1069. }
  1070. static void tg3_frob_aux_power(struct tg3 *tp)
  1071. {
  1072. struct tg3 *tp_peer = tp;
  1073. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  1074. return;
  1075. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  1076. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  1077. struct net_device *dev_peer;
  1078. dev_peer = pci_get_drvdata(tp->pdev_peer);
  1079. /* remove_one() may have been run on the peer. */
  1080. if (!dev_peer)
  1081. tp_peer = tp;
  1082. else
  1083. tp_peer = netdev_priv(dev_peer);
  1084. }
  1085. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  1086. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  1087. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  1088. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  1089. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1090. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1091. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1092. (GRC_LCLCTRL_GPIO_OE0 |
  1093. GRC_LCLCTRL_GPIO_OE1 |
  1094. GRC_LCLCTRL_GPIO_OE2 |
  1095. GRC_LCLCTRL_GPIO_OUTPUT0 |
  1096. GRC_LCLCTRL_GPIO_OUTPUT1),
  1097. 100);
  1098. } else {
  1099. u32 no_gpio2;
  1100. u32 grc_local_ctrl = 0;
  1101. if (tp_peer != tp &&
  1102. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1103. return;
  1104. /* Workaround to prevent overdrawing Amps. */
  1105. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1106. ASIC_REV_5714) {
  1107. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  1108. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1109. grc_local_ctrl, 100);
  1110. }
  1111. /* On 5753 and variants, GPIO2 cannot be used. */
  1112. no_gpio2 = tp->nic_sram_data_cfg &
  1113. NIC_SRAM_DATA_CFG_NO_GPIO2;
  1114. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  1115. GRC_LCLCTRL_GPIO_OE1 |
  1116. GRC_LCLCTRL_GPIO_OE2 |
  1117. GRC_LCLCTRL_GPIO_OUTPUT1 |
  1118. GRC_LCLCTRL_GPIO_OUTPUT2;
  1119. if (no_gpio2) {
  1120. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  1121. GRC_LCLCTRL_GPIO_OUTPUT2);
  1122. }
  1123. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1124. grc_local_ctrl, 100);
  1125. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  1126. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1127. grc_local_ctrl, 100);
  1128. if (!no_gpio2) {
  1129. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  1130. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1131. grc_local_ctrl, 100);
  1132. }
  1133. }
  1134. } else {
  1135. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  1136. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  1137. if (tp_peer != tp &&
  1138. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1139. return;
  1140. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1141. (GRC_LCLCTRL_GPIO_OE1 |
  1142. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1143. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1144. GRC_LCLCTRL_GPIO_OE1, 100);
  1145. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1146. (GRC_LCLCTRL_GPIO_OE1 |
  1147. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1148. }
  1149. }
  1150. }
  1151. static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
  1152. {
  1153. if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
  1154. return 1;
  1155. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411) {
  1156. if (speed != SPEED_10)
  1157. return 1;
  1158. } else if (speed == SPEED_10)
  1159. return 1;
  1160. return 0;
  1161. }
  1162. static int tg3_setup_phy(struct tg3 *, int);
  1163. #define RESET_KIND_SHUTDOWN 0
  1164. #define RESET_KIND_INIT 1
  1165. #define RESET_KIND_SUSPEND 2
  1166. static void tg3_write_sig_post_reset(struct tg3 *, int);
  1167. static int tg3_halt_cpu(struct tg3 *, u32);
  1168. static int tg3_nvram_lock(struct tg3 *);
  1169. static void tg3_nvram_unlock(struct tg3 *);
  1170. static void tg3_power_down_phy(struct tg3 *tp)
  1171. {
  1172. u32 val;
  1173. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1174. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1175. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1176. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1177. sg_dig_ctrl |=
  1178. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1179. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1180. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1181. }
  1182. return;
  1183. }
  1184. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1185. tg3_bmcr_reset(tp);
  1186. val = tr32(GRC_MISC_CFG);
  1187. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1188. udelay(40);
  1189. return;
  1190. } else {
  1191. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1192. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1193. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1194. }
  1195. /* The PHY should not be powered down on some chips because
  1196. * of bugs.
  1197. */
  1198. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1199. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1200. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1201. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1202. return;
  1203. if (tp->tg3_flags3 & TG3_FLG3_5761_5784_AX_FIXES) {
  1204. val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
  1205. val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
  1206. val |= CPMU_LSPD_1000MB_MACCLK_12_5;
  1207. tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
  1208. }
  1209. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1210. }
  1211. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1212. {
  1213. u32 misc_host_ctrl;
  1214. u16 power_control, power_caps;
  1215. int pm = tp->pm_cap;
  1216. /* Make sure register accesses (indirect or otherwise)
  1217. * will function correctly.
  1218. */
  1219. pci_write_config_dword(tp->pdev,
  1220. TG3PCI_MISC_HOST_CTRL,
  1221. tp->misc_host_ctrl);
  1222. pci_read_config_word(tp->pdev,
  1223. pm + PCI_PM_CTRL,
  1224. &power_control);
  1225. power_control |= PCI_PM_CTRL_PME_STATUS;
  1226. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1227. switch (state) {
  1228. case PCI_D0:
  1229. power_control |= 0;
  1230. pci_write_config_word(tp->pdev,
  1231. pm + PCI_PM_CTRL,
  1232. power_control);
  1233. udelay(100); /* Delay after power state change */
  1234. /* Switch out of Vaux if it is a NIC */
  1235. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1236. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1237. return 0;
  1238. case PCI_D1:
  1239. power_control |= 1;
  1240. break;
  1241. case PCI_D2:
  1242. power_control |= 2;
  1243. break;
  1244. case PCI_D3hot:
  1245. power_control |= 3;
  1246. break;
  1247. default:
  1248. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1249. "requested.\n",
  1250. tp->dev->name, state);
  1251. return -EINVAL;
  1252. };
  1253. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1254. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1255. tw32(TG3PCI_MISC_HOST_CTRL,
  1256. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1257. if (tp->link_config.phy_is_low_power == 0) {
  1258. tp->link_config.phy_is_low_power = 1;
  1259. tp->link_config.orig_speed = tp->link_config.speed;
  1260. tp->link_config.orig_duplex = tp->link_config.duplex;
  1261. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1262. }
  1263. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1264. tp->link_config.speed = SPEED_10;
  1265. tp->link_config.duplex = DUPLEX_HALF;
  1266. tp->link_config.autoneg = AUTONEG_ENABLE;
  1267. tg3_setup_phy(tp, 0);
  1268. }
  1269. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1270. u32 val;
  1271. val = tr32(GRC_VCPU_EXT_CTRL);
  1272. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1273. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1274. int i;
  1275. u32 val;
  1276. for (i = 0; i < 200; i++) {
  1277. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1278. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1279. break;
  1280. msleep(1);
  1281. }
  1282. }
  1283. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  1284. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1285. WOL_DRV_STATE_SHUTDOWN |
  1286. WOL_DRV_WOL |
  1287. WOL_SET_MAGIC_PKT);
  1288. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1289. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1290. u32 mac_mode;
  1291. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1292. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1293. udelay(40);
  1294. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1295. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1296. else
  1297. mac_mode = MAC_MODE_PORT_MODE_MII;
  1298. mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
  1299. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1300. ASIC_REV_5700) {
  1301. u32 speed = (tp->tg3_flags &
  1302. TG3_FLAG_WOL_SPEED_100MB) ?
  1303. SPEED_100 : SPEED_10;
  1304. if (tg3_5700_link_polarity(tp, speed))
  1305. mac_mode |= MAC_MODE_LINK_POLARITY;
  1306. else
  1307. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1308. }
  1309. } else {
  1310. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1311. }
  1312. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1313. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1314. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1315. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1316. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1317. tw32_f(MAC_MODE, mac_mode);
  1318. udelay(100);
  1319. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1320. udelay(10);
  1321. }
  1322. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1323. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1324. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1325. u32 base_val;
  1326. base_val = tp->pci_clock_ctrl;
  1327. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1328. CLOCK_CTRL_TXCLK_DISABLE);
  1329. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1330. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1331. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1332. (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
  1333. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1334. /* do nothing */
  1335. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1336. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1337. u32 newbits1, newbits2;
  1338. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1339. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1340. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1341. CLOCK_CTRL_TXCLK_DISABLE |
  1342. CLOCK_CTRL_ALTCLK);
  1343. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1344. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1345. newbits1 = CLOCK_CTRL_625_CORE;
  1346. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1347. } else {
  1348. newbits1 = CLOCK_CTRL_ALTCLK;
  1349. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1350. }
  1351. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1352. 40);
  1353. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1354. 40);
  1355. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1356. u32 newbits3;
  1357. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1358. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1359. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1360. CLOCK_CTRL_TXCLK_DISABLE |
  1361. CLOCK_CTRL_44MHZ_CORE);
  1362. } else {
  1363. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1364. }
  1365. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1366. tp->pci_clock_ctrl | newbits3, 40);
  1367. }
  1368. }
  1369. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1370. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
  1371. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  1372. tg3_power_down_phy(tp);
  1373. tg3_frob_aux_power(tp);
  1374. /* Workaround for unstable PLL clock */
  1375. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1376. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1377. u32 val = tr32(0x7d00);
  1378. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1379. tw32(0x7d00, val);
  1380. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1381. int err;
  1382. err = tg3_nvram_lock(tp);
  1383. tg3_halt_cpu(tp, RX_CPU_BASE);
  1384. if (!err)
  1385. tg3_nvram_unlock(tp);
  1386. }
  1387. }
  1388. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1389. /* Finally, set the new power state. */
  1390. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1391. udelay(100); /* Delay after power state change */
  1392. return 0;
  1393. }
  1394. static void tg3_link_report(struct tg3 *tp)
  1395. {
  1396. if (!netif_carrier_ok(tp->dev)) {
  1397. if (netif_msg_link(tp))
  1398. printk(KERN_INFO PFX "%s: Link is down.\n",
  1399. tp->dev->name);
  1400. } else if (netif_msg_link(tp)) {
  1401. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1402. tp->dev->name,
  1403. (tp->link_config.active_speed == SPEED_1000 ?
  1404. 1000 :
  1405. (tp->link_config.active_speed == SPEED_100 ?
  1406. 100 : 10)),
  1407. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1408. "full" : "half"));
  1409. printk(KERN_INFO PFX
  1410. "%s: Flow control is %s for TX and %s for RX.\n",
  1411. tp->dev->name,
  1412. (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_TX) ?
  1413. "on" : "off",
  1414. (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX) ?
  1415. "on" : "off");
  1416. }
  1417. }
  1418. static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl)
  1419. {
  1420. u16 miireg;
  1421. if ((flow_ctrl & TG3_FLOW_CTRL_TX) && (flow_ctrl & TG3_FLOW_CTRL_RX))
  1422. miireg = ADVERTISE_PAUSE_CAP;
  1423. else if (flow_ctrl & TG3_FLOW_CTRL_TX)
  1424. miireg = ADVERTISE_PAUSE_ASYM;
  1425. else if (flow_ctrl & TG3_FLOW_CTRL_RX)
  1426. miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  1427. else
  1428. miireg = 0;
  1429. return miireg;
  1430. }
  1431. static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl)
  1432. {
  1433. u16 miireg;
  1434. if ((flow_ctrl & TG3_FLOW_CTRL_TX) && (flow_ctrl & TG3_FLOW_CTRL_RX))
  1435. miireg = ADVERTISE_1000XPAUSE;
  1436. else if (flow_ctrl & TG3_FLOW_CTRL_TX)
  1437. miireg = ADVERTISE_1000XPSE_ASYM;
  1438. else if (flow_ctrl & TG3_FLOW_CTRL_RX)
  1439. miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  1440. else
  1441. miireg = 0;
  1442. return miireg;
  1443. }
  1444. static u8 tg3_resolve_flowctrl_1000T(u16 lcladv, u16 rmtadv)
  1445. {
  1446. u8 cap = 0;
  1447. if (lcladv & ADVERTISE_PAUSE_CAP) {
  1448. if (lcladv & ADVERTISE_PAUSE_ASYM) {
  1449. if (rmtadv & LPA_PAUSE_CAP)
  1450. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1451. else if (rmtadv & LPA_PAUSE_ASYM)
  1452. cap = TG3_FLOW_CTRL_RX;
  1453. } else {
  1454. if (rmtadv & LPA_PAUSE_CAP)
  1455. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1456. }
  1457. } else if (lcladv & ADVERTISE_PAUSE_ASYM) {
  1458. if ((rmtadv & LPA_PAUSE_CAP) && (rmtadv & LPA_PAUSE_ASYM))
  1459. cap = TG3_FLOW_CTRL_TX;
  1460. }
  1461. return cap;
  1462. }
  1463. static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv)
  1464. {
  1465. u8 cap = 0;
  1466. if (lcladv & ADVERTISE_1000XPAUSE) {
  1467. if (lcladv & ADVERTISE_1000XPSE_ASYM) {
  1468. if (rmtadv & LPA_1000XPAUSE)
  1469. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1470. else if (rmtadv & LPA_1000XPAUSE_ASYM)
  1471. cap = TG3_FLOW_CTRL_RX;
  1472. } else {
  1473. if (rmtadv & LPA_1000XPAUSE)
  1474. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1475. }
  1476. } else if (lcladv & ADVERTISE_1000XPSE_ASYM) {
  1477. if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM))
  1478. cap = TG3_FLOW_CTRL_TX;
  1479. }
  1480. return cap;
  1481. }
  1482. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1483. {
  1484. u8 new_tg3_flags = 0;
  1485. u32 old_rx_mode = tp->rx_mode;
  1486. u32 old_tx_mode = tp->tx_mode;
  1487. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  1488. (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) {
  1489. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  1490. new_tg3_flags = tg3_resolve_flowctrl_1000X(local_adv,
  1491. remote_adv);
  1492. else
  1493. new_tg3_flags = tg3_resolve_flowctrl_1000T(local_adv,
  1494. remote_adv);
  1495. } else {
  1496. new_tg3_flags = tp->link_config.flowctrl;
  1497. }
  1498. tp->link_config.active_flowctrl = new_tg3_flags;
  1499. if (new_tg3_flags & TG3_FLOW_CTRL_RX)
  1500. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1501. else
  1502. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1503. if (old_rx_mode != tp->rx_mode) {
  1504. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1505. }
  1506. if (new_tg3_flags & TG3_FLOW_CTRL_TX)
  1507. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1508. else
  1509. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1510. if (old_tx_mode != tp->tx_mode) {
  1511. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1512. }
  1513. }
  1514. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1515. {
  1516. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1517. case MII_TG3_AUX_STAT_10HALF:
  1518. *speed = SPEED_10;
  1519. *duplex = DUPLEX_HALF;
  1520. break;
  1521. case MII_TG3_AUX_STAT_10FULL:
  1522. *speed = SPEED_10;
  1523. *duplex = DUPLEX_FULL;
  1524. break;
  1525. case MII_TG3_AUX_STAT_100HALF:
  1526. *speed = SPEED_100;
  1527. *duplex = DUPLEX_HALF;
  1528. break;
  1529. case MII_TG3_AUX_STAT_100FULL:
  1530. *speed = SPEED_100;
  1531. *duplex = DUPLEX_FULL;
  1532. break;
  1533. case MII_TG3_AUX_STAT_1000HALF:
  1534. *speed = SPEED_1000;
  1535. *duplex = DUPLEX_HALF;
  1536. break;
  1537. case MII_TG3_AUX_STAT_1000FULL:
  1538. *speed = SPEED_1000;
  1539. *duplex = DUPLEX_FULL;
  1540. break;
  1541. default:
  1542. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1543. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1544. SPEED_10;
  1545. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1546. DUPLEX_HALF;
  1547. break;
  1548. }
  1549. *speed = SPEED_INVALID;
  1550. *duplex = DUPLEX_INVALID;
  1551. break;
  1552. };
  1553. }
  1554. static void tg3_phy_copper_begin(struct tg3 *tp)
  1555. {
  1556. u32 new_adv;
  1557. int i;
  1558. if (tp->link_config.phy_is_low_power) {
  1559. /* Entering low power mode. Disable gigabit and
  1560. * 100baseT advertisements.
  1561. */
  1562. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1563. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1564. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1565. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1566. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1567. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1568. } else if (tp->link_config.speed == SPEED_INVALID) {
  1569. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1570. tp->link_config.advertising &=
  1571. ~(ADVERTISED_1000baseT_Half |
  1572. ADVERTISED_1000baseT_Full);
  1573. new_adv = ADVERTISE_CSMA;
  1574. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1575. new_adv |= ADVERTISE_10HALF;
  1576. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1577. new_adv |= ADVERTISE_10FULL;
  1578. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1579. new_adv |= ADVERTISE_100HALF;
  1580. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1581. new_adv |= ADVERTISE_100FULL;
  1582. new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1583. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1584. if (tp->link_config.advertising &
  1585. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1586. new_adv = 0;
  1587. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1588. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1589. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1590. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1591. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1592. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1593. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1594. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1595. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1596. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1597. } else {
  1598. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1599. }
  1600. } else {
  1601. new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1602. new_adv |= ADVERTISE_CSMA;
  1603. /* Asking for a specific link mode. */
  1604. if (tp->link_config.speed == SPEED_1000) {
  1605. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1606. if (tp->link_config.duplex == DUPLEX_FULL)
  1607. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1608. else
  1609. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1610. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1611. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1612. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1613. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1614. } else {
  1615. if (tp->link_config.speed == SPEED_100) {
  1616. if (tp->link_config.duplex == DUPLEX_FULL)
  1617. new_adv |= ADVERTISE_100FULL;
  1618. else
  1619. new_adv |= ADVERTISE_100HALF;
  1620. } else {
  1621. if (tp->link_config.duplex == DUPLEX_FULL)
  1622. new_adv |= ADVERTISE_10FULL;
  1623. else
  1624. new_adv |= ADVERTISE_10HALF;
  1625. }
  1626. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1627. new_adv = 0;
  1628. }
  1629. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1630. }
  1631. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1632. tp->link_config.speed != SPEED_INVALID) {
  1633. u32 bmcr, orig_bmcr;
  1634. tp->link_config.active_speed = tp->link_config.speed;
  1635. tp->link_config.active_duplex = tp->link_config.duplex;
  1636. bmcr = 0;
  1637. switch (tp->link_config.speed) {
  1638. default:
  1639. case SPEED_10:
  1640. break;
  1641. case SPEED_100:
  1642. bmcr |= BMCR_SPEED100;
  1643. break;
  1644. case SPEED_1000:
  1645. bmcr |= TG3_BMCR_SPEED1000;
  1646. break;
  1647. };
  1648. if (tp->link_config.duplex == DUPLEX_FULL)
  1649. bmcr |= BMCR_FULLDPLX;
  1650. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1651. (bmcr != orig_bmcr)) {
  1652. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1653. for (i = 0; i < 1500; i++) {
  1654. u32 tmp;
  1655. udelay(10);
  1656. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1657. tg3_readphy(tp, MII_BMSR, &tmp))
  1658. continue;
  1659. if (!(tmp & BMSR_LSTATUS)) {
  1660. udelay(40);
  1661. break;
  1662. }
  1663. }
  1664. tg3_writephy(tp, MII_BMCR, bmcr);
  1665. udelay(40);
  1666. }
  1667. } else {
  1668. tg3_writephy(tp, MII_BMCR,
  1669. BMCR_ANENABLE | BMCR_ANRESTART);
  1670. }
  1671. }
  1672. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1673. {
  1674. int err;
  1675. /* Turn off tap power management. */
  1676. /* Set Extended packet length bit */
  1677. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1678. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1679. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1680. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1681. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1682. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1683. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1684. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1685. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1686. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1687. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1688. udelay(40);
  1689. return err;
  1690. }
  1691. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1692. {
  1693. u32 adv_reg, all_mask = 0;
  1694. if (mask & ADVERTISED_10baseT_Half)
  1695. all_mask |= ADVERTISE_10HALF;
  1696. if (mask & ADVERTISED_10baseT_Full)
  1697. all_mask |= ADVERTISE_10FULL;
  1698. if (mask & ADVERTISED_100baseT_Half)
  1699. all_mask |= ADVERTISE_100HALF;
  1700. if (mask & ADVERTISED_100baseT_Full)
  1701. all_mask |= ADVERTISE_100FULL;
  1702. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1703. return 0;
  1704. if ((adv_reg & all_mask) != all_mask)
  1705. return 0;
  1706. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1707. u32 tg3_ctrl;
  1708. all_mask = 0;
  1709. if (mask & ADVERTISED_1000baseT_Half)
  1710. all_mask |= ADVERTISE_1000HALF;
  1711. if (mask & ADVERTISED_1000baseT_Full)
  1712. all_mask |= ADVERTISE_1000FULL;
  1713. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1714. return 0;
  1715. if ((tg3_ctrl & all_mask) != all_mask)
  1716. return 0;
  1717. }
  1718. return 1;
  1719. }
  1720. static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv)
  1721. {
  1722. u32 curadv, reqadv;
  1723. if (tg3_readphy(tp, MII_ADVERTISE, lcladv))
  1724. return 1;
  1725. curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1726. reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1727. if (tp->link_config.active_duplex == DUPLEX_FULL) {
  1728. if (curadv != reqadv)
  1729. return 0;
  1730. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)
  1731. tg3_readphy(tp, MII_LPA, rmtadv);
  1732. } else {
  1733. /* Reprogram the advertisement register, even if it
  1734. * does not affect the current link. If the link
  1735. * gets renegotiated in the future, we can save an
  1736. * additional renegotiation cycle by advertising
  1737. * it correctly in the first place.
  1738. */
  1739. if (curadv != reqadv) {
  1740. *lcladv &= ~(ADVERTISE_PAUSE_CAP |
  1741. ADVERTISE_PAUSE_ASYM);
  1742. tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv);
  1743. }
  1744. }
  1745. return 1;
  1746. }
  1747. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1748. {
  1749. int current_link_up;
  1750. u32 bmsr, dummy;
  1751. u32 lcl_adv, rmt_adv;
  1752. u16 current_speed;
  1753. u8 current_duplex;
  1754. int i, err;
  1755. tw32(MAC_EVENT, 0);
  1756. tw32_f(MAC_STATUS,
  1757. (MAC_STATUS_SYNC_CHANGED |
  1758. MAC_STATUS_CFG_CHANGED |
  1759. MAC_STATUS_MI_COMPLETION |
  1760. MAC_STATUS_LNKSTATE_CHANGED));
  1761. udelay(40);
  1762. tp->mi_mode = MAC_MI_MODE_BASE;
  1763. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1764. udelay(80);
  1765. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1766. /* Some third-party PHYs need to be reset on link going
  1767. * down.
  1768. */
  1769. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1770. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1771. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1772. netif_carrier_ok(tp->dev)) {
  1773. tg3_readphy(tp, MII_BMSR, &bmsr);
  1774. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1775. !(bmsr & BMSR_LSTATUS))
  1776. force_reset = 1;
  1777. }
  1778. if (force_reset)
  1779. tg3_phy_reset(tp);
  1780. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1781. tg3_readphy(tp, MII_BMSR, &bmsr);
  1782. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1783. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1784. bmsr = 0;
  1785. if (!(bmsr & BMSR_LSTATUS)) {
  1786. err = tg3_init_5401phy_dsp(tp);
  1787. if (err)
  1788. return err;
  1789. tg3_readphy(tp, MII_BMSR, &bmsr);
  1790. for (i = 0; i < 1000; i++) {
  1791. udelay(10);
  1792. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1793. (bmsr & BMSR_LSTATUS)) {
  1794. udelay(40);
  1795. break;
  1796. }
  1797. }
  1798. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1799. !(bmsr & BMSR_LSTATUS) &&
  1800. tp->link_config.active_speed == SPEED_1000) {
  1801. err = tg3_phy_reset(tp);
  1802. if (!err)
  1803. err = tg3_init_5401phy_dsp(tp);
  1804. if (err)
  1805. return err;
  1806. }
  1807. }
  1808. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1809. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1810. /* 5701 {A0,B0} CRC bug workaround */
  1811. tg3_writephy(tp, 0x15, 0x0a75);
  1812. tg3_writephy(tp, 0x1c, 0x8c68);
  1813. tg3_writephy(tp, 0x1c, 0x8d68);
  1814. tg3_writephy(tp, 0x1c, 0x8c68);
  1815. }
  1816. /* Clear pending interrupts... */
  1817. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1818. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1819. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1820. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1821. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1822. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1823. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1824. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1825. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1826. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1827. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1828. else
  1829. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1830. }
  1831. current_link_up = 0;
  1832. current_speed = SPEED_INVALID;
  1833. current_duplex = DUPLEX_INVALID;
  1834. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1835. u32 val;
  1836. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1837. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1838. if (!(val & (1 << 10))) {
  1839. val |= (1 << 10);
  1840. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1841. goto relink;
  1842. }
  1843. }
  1844. bmsr = 0;
  1845. for (i = 0; i < 100; i++) {
  1846. tg3_readphy(tp, MII_BMSR, &bmsr);
  1847. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1848. (bmsr & BMSR_LSTATUS))
  1849. break;
  1850. udelay(40);
  1851. }
  1852. if (bmsr & BMSR_LSTATUS) {
  1853. u32 aux_stat, bmcr;
  1854. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1855. for (i = 0; i < 2000; i++) {
  1856. udelay(10);
  1857. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1858. aux_stat)
  1859. break;
  1860. }
  1861. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1862. &current_speed,
  1863. &current_duplex);
  1864. bmcr = 0;
  1865. for (i = 0; i < 200; i++) {
  1866. tg3_readphy(tp, MII_BMCR, &bmcr);
  1867. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1868. continue;
  1869. if (bmcr && bmcr != 0x7fff)
  1870. break;
  1871. udelay(10);
  1872. }
  1873. lcl_adv = 0;
  1874. rmt_adv = 0;
  1875. tp->link_config.active_speed = current_speed;
  1876. tp->link_config.active_duplex = current_duplex;
  1877. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1878. if ((bmcr & BMCR_ANENABLE) &&
  1879. tg3_copper_is_advertising_all(tp,
  1880. tp->link_config.advertising)) {
  1881. if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv,
  1882. &rmt_adv))
  1883. current_link_up = 1;
  1884. }
  1885. } else {
  1886. if (!(bmcr & BMCR_ANENABLE) &&
  1887. tp->link_config.speed == current_speed &&
  1888. tp->link_config.duplex == current_duplex &&
  1889. tp->link_config.flowctrl ==
  1890. tp->link_config.active_flowctrl) {
  1891. current_link_up = 1;
  1892. }
  1893. }
  1894. if (current_link_up == 1 &&
  1895. tp->link_config.active_duplex == DUPLEX_FULL)
  1896. tg3_setup_flow_control(tp, lcl_adv, rmt_adv);
  1897. }
  1898. relink:
  1899. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1900. u32 tmp;
  1901. tg3_phy_copper_begin(tp);
  1902. tg3_readphy(tp, MII_BMSR, &tmp);
  1903. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1904. (tmp & BMSR_LSTATUS))
  1905. current_link_up = 1;
  1906. }
  1907. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1908. if (current_link_up == 1) {
  1909. if (tp->link_config.active_speed == SPEED_100 ||
  1910. tp->link_config.active_speed == SPEED_10)
  1911. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1912. else
  1913. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1914. } else
  1915. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1916. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1917. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1918. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1919. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1920. if (current_link_up == 1 &&
  1921. tg3_5700_link_polarity(tp, tp->link_config.active_speed))
  1922. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1923. else
  1924. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1925. }
  1926. /* ??? Without this setting Netgear GA302T PHY does not
  1927. * ??? send/receive packets...
  1928. */
  1929. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1930. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1931. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1932. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1933. udelay(80);
  1934. }
  1935. tw32_f(MAC_MODE, tp->mac_mode);
  1936. udelay(40);
  1937. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1938. /* Polled via timer. */
  1939. tw32_f(MAC_EVENT, 0);
  1940. } else {
  1941. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1942. }
  1943. udelay(40);
  1944. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1945. current_link_up == 1 &&
  1946. tp->link_config.active_speed == SPEED_1000 &&
  1947. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1948. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1949. udelay(120);
  1950. tw32_f(MAC_STATUS,
  1951. (MAC_STATUS_SYNC_CHANGED |
  1952. MAC_STATUS_CFG_CHANGED));
  1953. udelay(40);
  1954. tg3_write_mem(tp,
  1955. NIC_SRAM_FIRMWARE_MBOX,
  1956. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1957. }
  1958. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1959. if (current_link_up)
  1960. netif_carrier_on(tp->dev);
  1961. else
  1962. netif_carrier_off(tp->dev);
  1963. tg3_link_report(tp);
  1964. }
  1965. return 0;
  1966. }
  1967. struct tg3_fiber_aneginfo {
  1968. int state;
  1969. #define ANEG_STATE_UNKNOWN 0
  1970. #define ANEG_STATE_AN_ENABLE 1
  1971. #define ANEG_STATE_RESTART_INIT 2
  1972. #define ANEG_STATE_RESTART 3
  1973. #define ANEG_STATE_DISABLE_LINK_OK 4
  1974. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1975. #define ANEG_STATE_ABILITY_DETECT 6
  1976. #define ANEG_STATE_ACK_DETECT_INIT 7
  1977. #define ANEG_STATE_ACK_DETECT 8
  1978. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1979. #define ANEG_STATE_COMPLETE_ACK 10
  1980. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1981. #define ANEG_STATE_IDLE_DETECT 12
  1982. #define ANEG_STATE_LINK_OK 13
  1983. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1984. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1985. u32 flags;
  1986. #define MR_AN_ENABLE 0x00000001
  1987. #define MR_RESTART_AN 0x00000002
  1988. #define MR_AN_COMPLETE 0x00000004
  1989. #define MR_PAGE_RX 0x00000008
  1990. #define MR_NP_LOADED 0x00000010
  1991. #define MR_TOGGLE_TX 0x00000020
  1992. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1993. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1994. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1995. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1996. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1997. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1998. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1999. #define MR_TOGGLE_RX 0x00002000
  2000. #define MR_NP_RX 0x00004000
  2001. #define MR_LINK_OK 0x80000000
  2002. unsigned long link_time, cur_time;
  2003. u32 ability_match_cfg;
  2004. int ability_match_count;
  2005. char ability_match, idle_match, ack_match;
  2006. u32 txconfig, rxconfig;
  2007. #define ANEG_CFG_NP 0x00000080
  2008. #define ANEG_CFG_ACK 0x00000040
  2009. #define ANEG_CFG_RF2 0x00000020
  2010. #define ANEG_CFG_RF1 0x00000010
  2011. #define ANEG_CFG_PS2 0x00000001
  2012. #define ANEG_CFG_PS1 0x00008000
  2013. #define ANEG_CFG_HD 0x00004000
  2014. #define ANEG_CFG_FD 0x00002000
  2015. #define ANEG_CFG_INVAL 0x00001f06
  2016. };
  2017. #define ANEG_OK 0
  2018. #define ANEG_DONE 1
  2019. #define ANEG_TIMER_ENAB 2
  2020. #define ANEG_FAILED -1
  2021. #define ANEG_STATE_SETTLE_TIME 10000
  2022. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  2023. struct tg3_fiber_aneginfo *ap)
  2024. {
  2025. u16 flowctrl;
  2026. unsigned long delta;
  2027. u32 rx_cfg_reg;
  2028. int ret;
  2029. if (ap->state == ANEG_STATE_UNKNOWN) {
  2030. ap->rxconfig = 0;
  2031. ap->link_time = 0;
  2032. ap->cur_time = 0;
  2033. ap->ability_match_cfg = 0;
  2034. ap->ability_match_count = 0;
  2035. ap->ability_match = 0;
  2036. ap->idle_match = 0;
  2037. ap->ack_match = 0;
  2038. }
  2039. ap->cur_time++;
  2040. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  2041. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  2042. if (rx_cfg_reg != ap->ability_match_cfg) {
  2043. ap->ability_match_cfg = rx_cfg_reg;
  2044. ap->ability_match = 0;
  2045. ap->ability_match_count = 0;
  2046. } else {
  2047. if (++ap->ability_match_count > 1) {
  2048. ap->ability_match = 1;
  2049. ap->ability_match_cfg = rx_cfg_reg;
  2050. }
  2051. }
  2052. if (rx_cfg_reg & ANEG_CFG_ACK)
  2053. ap->ack_match = 1;
  2054. else
  2055. ap->ack_match = 0;
  2056. ap->idle_match = 0;
  2057. } else {
  2058. ap->idle_match = 1;
  2059. ap->ability_match_cfg = 0;
  2060. ap->ability_match_count = 0;
  2061. ap->ability_match = 0;
  2062. ap->ack_match = 0;
  2063. rx_cfg_reg = 0;
  2064. }
  2065. ap->rxconfig = rx_cfg_reg;
  2066. ret = ANEG_OK;
  2067. switch(ap->state) {
  2068. case ANEG_STATE_UNKNOWN:
  2069. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  2070. ap->state = ANEG_STATE_AN_ENABLE;
  2071. /* fallthru */
  2072. case ANEG_STATE_AN_ENABLE:
  2073. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  2074. if (ap->flags & MR_AN_ENABLE) {
  2075. ap->link_time = 0;
  2076. ap->cur_time = 0;
  2077. ap->ability_match_cfg = 0;
  2078. ap->ability_match_count = 0;
  2079. ap->ability_match = 0;
  2080. ap->idle_match = 0;
  2081. ap->ack_match = 0;
  2082. ap->state = ANEG_STATE_RESTART_INIT;
  2083. } else {
  2084. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  2085. }
  2086. break;
  2087. case ANEG_STATE_RESTART_INIT:
  2088. ap->link_time = ap->cur_time;
  2089. ap->flags &= ~(MR_NP_LOADED);
  2090. ap->txconfig = 0;
  2091. tw32(MAC_TX_AUTO_NEG, 0);
  2092. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2093. tw32_f(MAC_MODE, tp->mac_mode);
  2094. udelay(40);
  2095. ret = ANEG_TIMER_ENAB;
  2096. ap->state = ANEG_STATE_RESTART;
  2097. /* fallthru */
  2098. case ANEG_STATE_RESTART:
  2099. delta = ap->cur_time - ap->link_time;
  2100. if (delta > ANEG_STATE_SETTLE_TIME) {
  2101. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  2102. } else {
  2103. ret = ANEG_TIMER_ENAB;
  2104. }
  2105. break;
  2106. case ANEG_STATE_DISABLE_LINK_OK:
  2107. ret = ANEG_DONE;
  2108. break;
  2109. case ANEG_STATE_ABILITY_DETECT_INIT:
  2110. ap->flags &= ~(MR_TOGGLE_TX);
  2111. ap->txconfig = ANEG_CFG_FD;
  2112. flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2113. if (flowctrl & ADVERTISE_1000XPAUSE)
  2114. ap->txconfig |= ANEG_CFG_PS1;
  2115. if (flowctrl & ADVERTISE_1000XPSE_ASYM)
  2116. ap->txconfig |= ANEG_CFG_PS2;
  2117. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  2118. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2119. tw32_f(MAC_MODE, tp->mac_mode);
  2120. udelay(40);
  2121. ap->state = ANEG_STATE_ABILITY_DETECT;
  2122. break;
  2123. case ANEG_STATE_ABILITY_DETECT:
  2124. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  2125. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  2126. }
  2127. break;
  2128. case ANEG_STATE_ACK_DETECT_INIT:
  2129. ap->txconfig |= ANEG_CFG_ACK;
  2130. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  2131. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2132. tw32_f(MAC_MODE, tp->mac_mode);
  2133. udelay(40);
  2134. ap->state = ANEG_STATE_ACK_DETECT;
  2135. /* fallthru */
  2136. case ANEG_STATE_ACK_DETECT:
  2137. if (ap->ack_match != 0) {
  2138. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  2139. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  2140. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  2141. } else {
  2142. ap->state = ANEG_STATE_AN_ENABLE;
  2143. }
  2144. } else if (ap->ability_match != 0 &&
  2145. ap->rxconfig == 0) {
  2146. ap->state = ANEG_STATE_AN_ENABLE;
  2147. }
  2148. break;
  2149. case ANEG_STATE_COMPLETE_ACK_INIT:
  2150. if (ap->rxconfig & ANEG_CFG_INVAL) {
  2151. ret = ANEG_FAILED;
  2152. break;
  2153. }
  2154. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  2155. MR_LP_ADV_HALF_DUPLEX |
  2156. MR_LP_ADV_SYM_PAUSE |
  2157. MR_LP_ADV_ASYM_PAUSE |
  2158. MR_LP_ADV_REMOTE_FAULT1 |
  2159. MR_LP_ADV_REMOTE_FAULT2 |
  2160. MR_LP_ADV_NEXT_PAGE |
  2161. MR_TOGGLE_RX |
  2162. MR_NP_RX);
  2163. if (ap->rxconfig & ANEG_CFG_FD)
  2164. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  2165. if (ap->rxconfig & ANEG_CFG_HD)
  2166. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  2167. if (ap->rxconfig & ANEG_CFG_PS1)
  2168. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  2169. if (ap->rxconfig & ANEG_CFG_PS2)
  2170. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  2171. if (ap->rxconfig & ANEG_CFG_RF1)
  2172. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  2173. if (ap->rxconfig & ANEG_CFG_RF2)
  2174. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  2175. if (ap->rxconfig & ANEG_CFG_NP)
  2176. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  2177. ap->link_time = ap->cur_time;
  2178. ap->flags ^= (MR_TOGGLE_TX);
  2179. if (ap->rxconfig & 0x0008)
  2180. ap->flags |= MR_TOGGLE_RX;
  2181. if (ap->rxconfig & ANEG_CFG_NP)
  2182. ap->flags |= MR_NP_RX;
  2183. ap->flags |= MR_PAGE_RX;
  2184. ap->state = ANEG_STATE_COMPLETE_ACK;
  2185. ret = ANEG_TIMER_ENAB;
  2186. break;
  2187. case ANEG_STATE_COMPLETE_ACK:
  2188. if (ap->ability_match != 0 &&
  2189. ap->rxconfig == 0) {
  2190. ap->state = ANEG_STATE_AN_ENABLE;
  2191. break;
  2192. }
  2193. delta = ap->cur_time - ap->link_time;
  2194. if (delta > ANEG_STATE_SETTLE_TIME) {
  2195. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  2196. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2197. } else {
  2198. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  2199. !(ap->flags & MR_NP_RX)) {
  2200. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2201. } else {
  2202. ret = ANEG_FAILED;
  2203. }
  2204. }
  2205. }
  2206. break;
  2207. case ANEG_STATE_IDLE_DETECT_INIT:
  2208. ap->link_time = ap->cur_time;
  2209. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2210. tw32_f(MAC_MODE, tp->mac_mode);
  2211. udelay(40);
  2212. ap->state = ANEG_STATE_IDLE_DETECT;
  2213. ret = ANEG_TIMER_ENAB;
  2214. break;
  2215. case ANEG_STATE_IDLE_DETECT:
  2216. if (ap->ability_match != 0 &&
  2217. ap->rxconfig == 0) {
  2218. ap->state = ANEG_STATE_AN_ENABLE;
  2219. break;
  2220. }
  2221. delta = ap->cur_time - ap->link_time;
  2222. if (delta > ANEG_STATE_SETTLE_TIME) {
  2223. /* XXX another gem from the Broadcom driver :( */
  2224. ap->state = ANEG_STATE_LINK_OK;
  2225. }
  2226. break;
  2227. case ANEG_STATE_LINK_OK:
  2228. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  2229. ret = ANEG_DONE;
  2230. break;
  2231. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  2232. /* ??? unimplemented */
  2233. break;
  2234. case ANEG_STATE_NEXT_PAGE_WAIT:
  2235. /* ??? unimplemented */
  2236. break;
  2237. default:
  2238. ret = ANEG_FAILED;
  2239. break;
  2240. };
  2241. return ret;
  2242. }
  2243. static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags)
  2244. {
  2245. int res = 0;
  2246. struct tg3_fiber_aneginfo aninfo;
  2247. int status = ANEG_FAILED;
  2248. unsigned int tick;
  2249. u32 tmp;
  2250. tw32_f(MAC_TX_AUTO_NEG, 0);
  2251. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2252. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2253. udelay(40);
  2254. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2255. udelay(40);
  2256. memset(&aninfo, 0, sizeof(aninfo));
  2257. aninfo.flags |= MR_AN_ENABLE;
  2258. aninfo.state = ANEG_STATE_UNKNOWN;
  2259. aninfo.cur_time = 0;
  2260. tick = 0;
  2261. while (++tick < 195000) {
  2262. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2263. if (status == ANEG_DONE || status == ANEG_FAILED)
  2264. break;
  2265. udelay(1);
  2266. }
  2267. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2268. tw32_f(MAC_MODE, tp->mac_mode);
  2269. udelay(40);
  2270. *txflags = aninfo.txconfig;
  2271. *rxflags = aninfo.flags;
  2272. if (status == ANEG_DONE &&
  2273. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2274. MR_LP_ADV_FULL_DUPLEX)))
  2275. res = 1;
  2276. return res;
  2277. }
  2278. static void tg3_init_bcm8002(struct tg3 *tp)
  2279. {
  2280. u32 mac_status = tr32(MAC_STATUS);
  2281. int i;
  2282. /* Reset when initting first time or we have a link. */
  2283. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2284. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2285. return;
  2286. /* Set PLL lock range. */
  2287. tg3_writephy(tp, 0x16, 0x8007);
  2288. /* SW reset */
  2289. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2290. /* Wait for reset to complete. */
  2291. /* XXX schedule_timeout() ... */
  2292. for (i = 0; i < 500; i++)
  2293. udelay(10);
  2294. /* Config mode; select PMA/Ch 1 regs. */
  2295. tg3_writephy(tp, 0x10, 0x8411);
  2296. /* Enable auto-lock and comdet, select txclk for tx. */
  2297. tg3_writephy(tp, 0x11, 0x0a10);
  2298. tg3_writephy(tp, 0x18, 0x00a0);
  2299. tg3_writephy(tp, 0x16, 0x41ff);
  2300. /* Assert and deassert POR. */
  2301. tg3_writephy(tp, 0x13, 0x0400);
  2302. udelay(40);
  2303. tg3_writephy(tp, 0x13, 0x0000);
  2304. tg3_writephy(tp, 0x11, 0x0a50);
  2305. udelay(40);
  2306. tg3_writephy(tp, 0x11, 0x0a10);
  2307. /* Wait for signal to stabilize */
  2308. /* XXX schedule_timeout() ... */
  2309. for (i = 0; i < 15000; i++)
  2310. udelay(10);
  2311. /* Deselect the channel register so we can read the PHYID
  2312. * later.
  2313. */
  2314. tg3_writephy(tp, 0x10, 0x8011);
  2315. }
  2316. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2317. {
  2318. u16 flowctrl;
  2319. u32 sg_dig_ctrl, sg_dig_status;
  2320. u32 serdes_cfg, expected_sg_dig_ctrl;
  2321. int workaround, port_a;
  2322. int current_link_up;
  2323. serdes_cfg = 0;
  2324. expected_sg_dig_ctrl = 0;
  2325. workaround = 0;
  2326. port_a = 1;
  2327. current_link_up = 0;
  2328. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2329. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2330. workaround = 1;
  2331. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2332. port_a = 0;
  2333. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2334. /* preserve bits 20-23 for voltage regulator */
  2335. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2336. }
  2337. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2338. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2339. if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) {
  2340. if (workaround) {
  2341. u32 val = serdes_cfg;
  2342. if (port_a)
  2343. val |= 0xc010000;
  2344. else
  2345. val |= 0x4010000;
  2346. tw32_f(MAC_SERDES_CFG, val);
  2347. }
  2348. tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
  2349. }
  2350. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2351. tg3_setup_flow_control(tp, 0, 0);
  2352. current_link_up = 1;
  2353. }
  2354. goto out;
  2355. }
  2356. /* Want auto-negotiation. */
  2357. expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP;
  2358. flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2359. if (flowctrl & ADVERTISE_1000XPAUSE)
  2360. expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP;
  2361. if (flowctrl & ADVERTISE_1000XPSE_ASYM)
  2362. expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE;
  2363. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2364. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2365. tp->serdes_counter &&
  2366. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2367. MAC_STATUS_RCVD_CFG)) ==
  2368. MAC_STATUS_PCS_SYNCED)) {
  2369. tp->serdes_counter--;
  2370. current_link_up = 1;
  2371. goto out;
  2372. }
  2373. restart_autoneg:
  2374. if (workaround)
  2375. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2376. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET);
  2377. udelay(5);
  2378. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2379. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2380. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2381. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2382. MAC_STATUS_SIGNAL_DET)) {
  2383. sg_dig_status = tr32(SG_DIG_STATUS);
  2384. mac_status = tr32(MAC_STATUS);
  2385. if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) &&
  2386. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2387. u32 local_adv = 0, remote_adv = 0;
  2388. if (sg_dig_ctrl & SG_DIG_PAUSE_CAP)
  2389. local_adv |= ADVERTISE_1000XPAUSE;
  2390. if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE)
  2391. local_adv |= ADVERTISE_1000XPSE_ASYM;
  2392. if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE)
  2393. remote_adv |= LPA_1000XPAUSE;
  2394. if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE)
  2395. remote_adv |= LPA_1000XPAUSE_ASYM;
  2396. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2397. current_link_up = 1;
  2398. tp->serdes_counter = 0;
  2399. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2400. } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) {
  2401. if (tp->serdes_counter)
  2402. tp->serdes_counter--;
  2403. else {
  2404. if (workaround) {
  2405. u32 val = serdes_cfg;
  2406. if (port_a)
  2407. val |= 0xc010000;
  2408. else
  2409. val |= 0x4010000;
  2410. tw32_f(MAC_SERDES_CFG, val);
  2411. }
  2412. tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
  2413. udelay(40);
  2414. /* Link parallel detection - link is up */
  2415. /* only if we have PCS_SYNC and not */
  2416. /* receiving config code words */
  2417. mac_status = tr32(MAC_STATUS);
  2418. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2419. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2420. tg3_setup_flow_control(tp, 0, 0);
  2421. current_link_up = 1;
  2422. tp->tg3_flags2 |=
  2423. TG3_FLG2_PARALLEL_DETECT;
  2424. tp->serdes_counter =
  2425. SERDES_PARALLEL_DET_TIMEOUT;
  2426. } else
  2427. goto restart_autoneg;
  2428. }
  2429. }
  2430. } else {
  2431. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2432. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2433. }
  2434. out:
  2435. return current_link_up;
  2436. }
  2437. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2438. {
  2439. int current_link_up = 0;
  2440. if (!(mac_status & MAC_STATUS_PCS_SYNCED))
  2441. goto out;
  2442. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2443. u32 txflags, rxflags;
  2444. int i;
  2445. if (fiber_autoneg(tp, &txflags, &rxflags)) {
  2446. u32 local_adv = 0, remote_adv = 0;
  2447. if (txflags & ANEG_CFG_PS1)
  2448. local_adv |= ADVERTISE_1000XPAUSE;
  2449. if (txflags & ANEG_CFG_PS2)
  2450. local_adv |= ADVERTISE_1000XPSE_ASYM;
  2451. if (rxflags & MR_LP_ADV_SYM_PAUSE)
  2452. remote_adv |= LPA_1000XPAUSE;
  2453. if (rxflags & MR_LP_ADV_ASYM_PAUSE)
  2454. remote_adv |= LPA_1000XPAUSE_ASYM;
  2455. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2456. current_link_up = 1;
  2457. }
  2458. for (i = 0; i < 30; i++) {
  2459. udelay(20);
  2460. tw32_f(MAC_STATUS,
  2461. (MAC_STATUS_SYNC_CHANGED |
  2462. MAC_STATUS_CFG_CHANGED));
  2463. udelay(40);
  2464. if ((tr32(MAC_STATUS) &
  2465. (MAC_STATUS_SYNC_CHANGED |
  2466. MAC_STATUS_CFG_CHANGED)) == 0)
  2467. break;
  2468. }
  2469. mac_status = tr32(MAC_STATUS);
  2470. if (current_link_up == 0 &&
  2471. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2472. !(mac_status & MAC_STATUS_RCVD_CFG))
  2473. current_link_up = 1;
  2474. } else {
  2475. tg3_setup_flow_control(tp, 0, 0);
  2476. /* Forcing 1000FD link up. */
  2477. current_link_up = 1;
  2478. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2479. udelay(40);
  2480. tw32_f(MAC_MODE, tp->mac_mode);
  2481. udelay(40);
  2482. }
  2483. out:
  2484. return current_link_up;
  2485. }
  2486. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2487. {
  2488. u32 orig_pause_cfg;
  2489. u16 orig_active_speed;
  2490. u8 orig_active_duplex;
  2491. u32 mac_status;
  2492. int current_link_up;
  2493. int i;
  2494. orig_pause_cfg = tp->link_config.active_flowctrl;
  2495. orig_active_speed = tp->link_config.active_speed;
  2496. orig_active_duplex = tp->link_config.active_duplex;
  2497. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2498. netif_carrier_ok(tp->dev) &&
  2499. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2500. mac_status = tr32(MAC_STATUS);
  2501. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2502. MAC_STATUS_SIGNAL_DET |
  2503. MAC_STATUS_CFG_CHANGED |
  2504. MAC_STATUS_RCVD_CFG);
  2505. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2506. MAC_STATUS_SIGNAL_DET)) {
  2507. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2508. MAC_STATUS_CFG_CHANGED));
  2509. return 0;
  2510. }
  2511. }
  2512. tw32_f(MAC_TX_AUTO_NEG, 0);
  2513. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2514. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2515. tw32_f(MAC_MODE, tp->mac_mode);
  2516. udelay(40);
  2517. if (tp->phy_id == PHY_ID_BCM8002)
  2518. tg3_init_bcm8002(tp);
  2519. /* Enable link change event even when serdes polling. */
  2520. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2521. udelay(40);
  2522. current_link_up = 0;
  2523. mac_status = tr32(MAC_STATUS);
  2524. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2525. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2526. else
  2527. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2528. tp->hw_status->status =
  2529. (SD_STATUS_UPDATED |
  2530. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2531. for (i = 0; i < 100; i++) {
  2532. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2533. MAC_STATUS_CFG_CHANGED));
  2534. udelay(5);
  2535. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2536. MAC_STATUS_CFG_CHANGED |
  2537. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2538. break;
  2539. }
  2540. mac_status = tr32(MAC_STATUS);
  2541. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2542. current_link_up = 0;
  2543. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2544. tp->serdes_counter == 0) {
  2545. tw32_f(MAC_MODE, (tp->mac_mode |
  2546. MAC_MODE_SEND_CONFIGS));
  2547. udelay(1);
  2548. tw32_f(MAC_MODE, tp->mac_mode);
  2549. }
  2550. }
  2551. if (current_link_up == 1) {
  2552. tp->link_config.active_speed = SPEED_1000;
  2553. tp->link_config.active_duplex = DUPLEX_FULL;
  2554. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2555. LED_CTRL_LNKLED_OVERRIDE |
  2556. LED_CTRL_1000MBPS_ON));
  2557. } else {
  2558. tp->link_config.active_speed = SPEED_INVALID;
  2559. tp->link_config.active_duplex = DUPLEX_INVALID;
  2560. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2561. LED_CTRL_LNKLED_OVERRIDE |
  2562. LED_CTRL_TRAFFIC_OVERRIDE));
  2563. }
  2564. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2565. if (current_link_up)
  2566. netif_carrier_on(tp->dev);
  2567. else
  2568. netif_carrier_off(tp->dev);
  2569. tg3_link_report(tp);
  2570. } else {
  2571. u32 now_pause_cfg = tp->link_config.active_flowctrl;
  2572. if (orig_pause_cfg != now_pause_cfg ||
  2573. orig_active_speed != tp->link_config.active_speed ||
  2574. orig_active_duplex != tp->link_config.active_duplex)
  2575. tg3_link_report(tp);
  2576. }
  2577. return 0;
  2578. }
  2579. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2580. {
  2581. int current_link_up, err = 0;
  2582. u32 bmsr, bmcr;
  2583. u16 current_speed;
  2584. u8 current_duplex;
  2585. u32 local_adv, remote_adv;
  2586. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2587. tw32_f(MAC_MODE, tp->mac_mode);
  2588. udelay(40);
  2589. tw32(MAC_EVENT, 0);
  2590. tw32_f(MAC_STATUS,
  2591. (MAC_STATUS_SYNC_CHANGED |
  2592. MAC_STATUS_CFG_CHANGED |
  2593. MAC_STATUS_MI_COMPLETION |
  2594. MAC_STATUS_LNKSTATE_CHANGED));
  2595. udelay(40);
  2596. if (force_reset)
  2597. tg3_phy_reset(tp);
  2598. current_link_up = 0;
  2599. current_speed = SPEED_INVALID;
  2600. current_duplex = DUPLEX_INVALID;
  2601. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2602. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2603. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2604. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2605. bmsr |= BMSR_LSTATUS;
  2606. else
  2607. bmsr &= ~BMSR_LSTATUS;
  2608. }
  2609. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2610. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2611. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2612. tp->link_config.flowctrl == tp->link_config.active_flowctrl) {
  2613. /* do nothing, just check for link up at the end */
  2614. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2615. u32 adv, new_adv;
  2616. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2617. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2618. ADVERTISE_1000XPAUSE |
  2619. ADVERTISE_1000XPSE_ASYM |
  2620. ADVERTISE_SLCT);
  2621. new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2622. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2623. new_adv |= ADVERTISE_1000XHALF;
  2624. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2625. new_adv |= ADVERTISE_1000XFULL;
  2626. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2627. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2628. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2629. tg3_writephy(tp, MII_BMCR, bmcr);
  2630. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2631. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2632. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2633. return err;
  2634. }
  2635. } else {
  2636. u32 new_bmcr;
  2637. bmcr &= ~BMCR_SPEED1000;
  2638. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2639. if (tp->link_config.duplex == DUPLEX_FULL)
  2640. new_bmcr |= BMCR_FULLDPLX;
  2641. if (new_bmcr != bmcr) {
  2642. /* BMCR_SPEED1000 is a reserved bit that needs
  2643. * to be set on write.
  2644. */
  2645. new_bmcr |= BMCR_SPEED1000;
  2646. /* Force a linkdown */
  2647. if (netif_carrier_ok(tp->dev)) {
  2648. u32 adv;
  2649. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2650. adv &= ~(ADVERTISE_1000XFULL |
  2651. ADVERTISE_1000XHALF |
  2652. ADVERTISE_SLCT);
  2653. tg3_writephy(tp, MII_ADVERTISE, adv);
  2654. tg3_writephy(tp, MII_BMCR, bmcr |
  2655. BMCR_ANRESTART |
  2656. BMCR_ANENABLE);
  2657. udelay(10);
  2658. netif_carrier_off(tp->dev);
  2659. }
  2660. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2661. bmcr = new_bmcr;
  2662. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2663. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2664. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2665. ASIC_REV_5714) {
  2666. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2667. bmsr |= BMSR_LSTATUS;
  2668. else
  2669. bmsr &= ~BMSR_LSTATUS;
  2670. }
  2671. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2672. }
  2673. }
  2674. if (bmsr & BMSR_LSTATUS) {
  2675. current_speed = SPEED_1000;
  2676. current_link_up = 1;
  2677. if (bmcr & BMCR_FULLDPLX)
  2678. current_duplex = DUPLEX_FULL;
  2679. else
  2680. current_duplex = DUPLEX_HALF;
  2681. local_adv = 0;
  2682. remote_adv = 0;
  2683. if (bmcr & BMCR_ANENABLE) {
  2684. u32 common;
  2685. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2686. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2687. common = local_adv & remote_adv;
  2688. if (common & (ADVERTISE_1000XHALF |
  2689. ADVERTISE_1000XFULL)) {
  2690. if (common & ADVERTISE_1000XFULL)
  2691. current_duplex = DUPLEX_FULL;
  2692. else
  2693. current_duplex = DUPLEX_HALF;
  2694. }
  2695. else
  2696. current_link_up = 0;
  2697. }
  2698. }
  2699. if (current_link_up == 1 && current_duplex == DUPLEX_FULL)
  2700. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2701. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2702. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2703. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2704. tw32_f(MAC_MODE, tp->mac_mode);
  2705. udelay(40);
  2706. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2707. tp->link_config.active_speed = current_speed;
  2708. tp->link_config.active_duplex = current_duplex;
  2709. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2710. if (current_link_up)
  2711. netif_carrier_on(tp->dev);
  2712. else {
  2713. netif_carrier_off(tp->dev);
  2714. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2715. }
  2716. tg3_link_report(tp);
  2717. }
  2718. return err;
  2719. }
  2720. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2721. {
  2722. if (tp->serdes_counter) {
  2723. /* Give autoneg time to complete. */
  2724. tp->serdes_counter--;
  2725. return;
  2726. }
  2727. if (!netif_carrier_ok(tp->dev) &&
  2728. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2729. u32 bmcr;
  2730. tg3_readphy(tp, MII_BMCR, &bmcr);
  2731. if (bmcr & BMCR_ANENABLE) {
  2732. u32 phy1, phy2;
  2733. /* Select shadow register 0x1f */
  2734. tg3_writephy(tp, 0x1c, 0x7c00);
  2735. tg3_readphy(tp, 0x1c, &phy1);
  2736. /* Select expansion interrupt status register */
  2737. tg3_writephy(tp, 0x17, 0x0f01);
  2738. tg3_readphy(tp, 0x15, &phy2);
  2739. tg3_readphy(tp, 0x15, &phy2);
  2740. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2741. /* We have signal detect and not receiving
  2742. * config code words, link is up by parallel
  2743. * detection.
  2744. */
  2745. bmcr &= ~BMCR_ANENABLE;
  2746. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2747. tg3_writephy(tp, MII_BMCR, bmcr);
  2748. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2749. }
  2750. }
  2751. }
  2752. else if (netif_carrier_ok(tp->dev) &&
  2753. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2754. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2755. u32 phy2;
  2756. /* Select expansion interrupt status register */
  2757. tg3_writephy(tp, 0x17, 0x0f01);
  2758. tg3_readphy(tp, 0x15, &phy2);
  2759. if (phy2 & 0x20) {
  2760. u32 bmcr;
  2761. /* Config code words received, turn on autoneg. */
  2762. tg3_readphy(tp, MII_BMCR, &bmcr);
  2763. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2764. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2765. }
  2766. }
  2767. }
  2768. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2769. {
  2770. int err;
  2771. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2772. err = tg3_setup_fiber_phy(tp, force_reset);
  2773. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2774. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2775. } else {
  2776. err = tg3_setup_copper_phy(tp, force_reset);
  2777. }
  2778. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  2779. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1) {
  2780. u32 val, scale;
  2781. val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK;
  2782. if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5)
  2783. scale = 65;
  2784. else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25)
  2785. scale = 6;
  2786. else
  2787. scale = 12;
  2788. val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK;
  2789. val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT);
  2790. tw32(GRC_MISC_CFG, val);
  2791. }
  2792. if (tp->link_config.active_speed == SPEED_1000 &&
  2793. tp->link_config.active_duplex == DUPLEX_HALF)
  2794. tw32(MAC_TX_LENGTHS,
  2795. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2796. (6 << TX_LENGTHS_IPG_SHIFT) |
  2797. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2798. else
  2799. tw32(MAC_TX_LENGTHS,
  2800. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2801. (6 << TX_LENGTHS_IPG_SHIFT) |
  2802. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2803. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2804. if (netif_carrier_ok(tp->dev)) {
  2805. tw32(HOSTCC_STAT_COAL_TICKS,
  2806. tp->coal.stats_block_coalesce_usecs);
  2807. } else {
  2808. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2809. }
  2810. }
  2811. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) {
  2812. u32 val = tr32(PCIE_PWR_MGMT_THRESH);
  2813. if (!netif_carrier_ok(tp->dev))
  2814. val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) |
  2815. tp->pwrmgmt_thresh;
  2816. else
  2817. val |= PCIE_PWR_MGMT_L1_THRESH_MSK;
  2818. tw32(PCIE_PWR_MGMT_THRESH, val);
  2819. }
  2820. return err;
  2821. }
  2822. /* This is called whenever we suspect that the system chipset is re-
  2823. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2824. * is bogus tx completions. We try to recover by setting the
  2825. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2826. * in the workqueue.
  2827. */
  2828. static void tg3_tx_recover(struct tg3 *tp)
  2829. {
  2830. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2831. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2832. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2833. "mapped I/O cycles to the network device, attempting to "
  2834. "recover. Please report the problem to the driver maintainer "
  2835. "and include system chipset information.\n", tp->dev->name);
  2836. spin_lock(&tp->lock);
  2837. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2838. spin_unlock(&tp->lock);
  2839. }
  2840. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2841. {
  2842. smp_mb();
  2843. return (tp->tx_pending -
  2844. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2845. }
  2846. /* Tigon3 never reports partial packet sends. So we do not
  2847. * need special logic to handle SKBs that have not had all
  2848. * of their frags sent yet, like SunGEM does.
  2849. */
  2850. static void tg3_tx(struct tg3 *tp)
  2851. {
  2852. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2853. u32 sw_idx = tp->tx_cons;
  2854. while (sw_idx != hw_idx) {
  2855. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2856. struct sk_buff *skb = ri->skb;
  2857. int i, tx_bug = 0;
  2858. if (unlikely(skb == NULL)) {
  2859. tg3_tx_recover(tp);
  2860. return;
  2861. }
  2862. pci_unmap_single(tp->pdev,
  2863. pci_unmap_addr(ri, mapping),
  2864. skb_headlen(skb),
  2865. PCI_DMA_TODEVICE);
  2866. ri->skb = NULL;
  2867. sw_idx = NEXT_TX(sw_idx);
  2868. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2869. ri = &tp->tx_buffers[sw_idx];
  2870. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2871. tx_bug = 1;
  2872. pci_unmap_page(tp->pdev,
  2873. pci_unmap_addr(ri, mapping),
  2874. skb_shinfo(skb)->frags[i].size,
  2875. PCI_DMA_TODEVICE);
  2876. sw_idx = NEXT_TX(sw_idx);
  2877. }
  2878. dev_kfree_skb(skb);
  2879. if (unlikely(tx_bug)) {
  2880. tg3_tx_recover(tp);
  2881. return;
  2882. }
  2883. }
  2884. tp->tx_cons = sw_idx;
  2885. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2886. * before checking for netif_queue_stopped(). Without the
  2887. * memory barrier, there is a small possibility that tg3_start_xmit()
  2888. * will miss it and cause the queue to be stopped forever.
  2889. */
  2890. smp_mb();
  2891. if (unlikely(netif_queue_stopped(tp->dev) &&
  2892. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2893. netif_tx_lock(tp->dev);
  2894. if (netif_queue_stopped(tp->dev) &&
  2895. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2896. netif_wake_queue(tp->dev);
  2897. netif_tx_unlock(tp->dev);
  2898. }
  2899. }
  2900. /* Returns size of skb allocated or < 0 on error.
  2901. *
  2902. * We only need to fill in the address because the other members
  2903. * of the RX descriptor are invariant, see tg3_init_rings.
  2904. *
  2905. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2906. * posting buffers we only dirty the first cache line of the RX
  2907. * descriptor (containing the address). Whereas for the RX status
  2908. * buffers the cpu only reads the last cacheline of the RX descriptor
  2909. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2910. */
  2911. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2912. int src_idx, u32 dest_idx_unmasked)
  2913. {
  2914. struct tg3_rx_buffer_desc *desc;
  2915. struct ring_info *map, *src_map;
  2916. struct sk_buff *skb;
  2917. dma_addr_t mapping;
  2918. int skb_size, dest_idx;
  2919. src_map = NULL;
  2920. switch (opaque_key) {
  2921. case RXD_OPAQUE_RING_STD:
  2922. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2923. desc = &tp->rx_std[dest_idx];
  2924. map = &tp->rx_std_buffers[dest_idx];
  2925. if (src_idx >= 0)
  2926. src_map = &tp->rx_std_buffers[src_idx];
  2927. skb_size = tp->rx_pkt_buf_sz;
  2928. break;
  2929. case RXD_OPAQUE_RING_JUMBO:
  2930. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2931. desc = &tp->rx_jumbo[dest_idx];
  2932. map = &tp->rx_jumbo_buffers[dest_idx];
  2933. if (src_idx >= 0)
  2934. src_map = &tp->rx_jumbo_buffers[src_idx];
  2935. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2936. break;
  2937. default:
  2938. return -EINVAL;
  2939. };
  2940. /* Do not overwrite any of the map or rp information
  2941. * until we are sure we can commit to a new buffer.
  2942. *
  2943. * Callers depend upon this behavior and assume that
  2944. * we leave everything unchanged if we fail.
  2945. */
  2946. skb = netdev_alloc_skb(tp->dev, skb_size);
  2947. if (skb == NULL)
  2948. return -ENOMEM;
  2949. skb_reserve(skb, tp->rx_offset);
  2950. mapping = pci_map_single(tp->pdev, skb->data,
  2951. skb_size - tp->rx_offset,
  2952. PCI_DMA_FROMDEVICE);
  2953. map->skb = skb;
  2954. pci_unmap_addr_set(map, mapping, mapping);
  2955. if (src_map != NULL)
  2956. src_map->skb = NULL;
  2957. desc->addr_hi = ((u64)mapping >> 32);
  2958. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2959. return skb_size;
  2960. }
  2961. /* We only need to move over in the address because the other
  2962. * members of the RX descriptor are invariant. See notes above
  2963. * tg3_alloc_rx_skb for full details.
  2964. */
  2965. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2966. int src_idx, u32 dest_idx_unmasked)
  2967. {
  2968. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2969. struct ring_info *src_map, *dest_map;
  2970. int dest_idx;
  2971. switch (opaque_key) {
  2972. case RXD_OPAQUE_RING_STD:
  2973. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2974. dest_desc = &tp->rx_std[dest_idx];
  2975. dest_map = &tp->rx_std_buffers[dest_idx];
  2976. src_desc = &tp->rx_std[src_idx];
  2977. src_map = &tp->rx_std_buffers[src_idx];
  2978. break;
  2979. case RXD_OPAQUE_RING_JUMBO:
  2980. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2981. dest_desc = &tp->rx_jumbo[dest_idx];
  2982. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2983. src_desc = &tp->rx_jumbo[src_idx];
  2984. src_map = &tp->rx_jumbo_buffers[src_idx];
  2985. break;
  2986. default:
  2987. return;
  2988. };
  2989. dest_map->skb = src_map->skb;
  2990. pci_unmap_addr_set(dest_map, mapping,
  2991. pci_unmap_addr(src_map, mapping));
  2992. dest_desc->addr_hi = src_desc->addr_hi;
  2993. dest_desc->addr_lo = src_desc->addr_lo;
  2994. src_map->skb = NULL;
  2995. }
  2996. #if TG3_VLAN_TAG_USED
  2997. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2998. {
  2999. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  3000. }
  3001. #endif
  3002. /* The RX ring scheme is composed of multiple rings which post fresh
  3003. * buffers to the chip, and one special ring the chip uses to report
  3004. * status back to the host.
  3005. *
  3006. * The special ring reports the status of received packets to the
  3007. * host. The chip does not write into the original descriptor the
  3008. * RX buffer was obtained from. The chip simply takes the original
  3009. * descriptor as provided by the host, updates the status and length
  3010. * field, then writes this into the next status ring entry.
  3011. *
  3012. * Each ring the host uses to post buffers to the chip is described
  3013. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  3014. * it is first placed into the on-chip ram. When the packet's length
  3015. * is known, it walks down the TG3_BDINFO entries to select the ring.
  3016. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  3017. * which is within the range of the new packet's length is chosen.
  3018. *
  3019. * The "separate ring for rx status" scheme may sound queer, but it makes
  3020. * sense from a cache coherency perspective. If only the host writes
  3021. * to the buffer post rings, and only the chip writes to the rx status
  3022. * rings, then cache lines never move beyond shared-modified state.
  3023. * If both the host and chip were to write into the same ring, cache line
  3024. * eviction could occur since both entities want it in an exclusive state.
  3025. */
  3026. static int tg3_rx(struct tg3 *tp, int budget)
  3027. {
  3028. u32 work_mask, rx_std_posted = 0;
  3029. u32 sw_idx = tp->rx_rcb_ptr;
  3030. u16 hw_idx;
  3031. int received;
  3032. hw_idx = tp->hw_status->idx[0].rx_producer;
  3033. /*
  3034. * We need to order the read of hw_idx and the read of
  3035. * the opaque cookie.
  3036. */
  3037. rmb();
  3038. work_mask = 0;
  3039. received = 0;
  3040. while (sw_idx != hw_idx && budget > 0) {
  3041. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  3042. unsigned int len;
  3043. struct sk_buff *skb;
  3044. dma_addr_t dma_addr;
  3045. u32 opaque_key, desc_idx, *post_ptr;
  3046. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  3047. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  3048. if (opaque_key == RXD_OPAQUE_RING_STD) {
  3049. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  3050. mapping);
  3051. skb = tp->rx_std_buffers[desc_idx].skb;
  3052. post_ptr = &tp->rx_std_ptr;
  3053. rx_std_posted++;
  3054. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  3055. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  3056. mapping);
  3057. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  3058. post_ptr = &tp->rx_jumbo_ptr;
  3059. }
  3060. else {
  3061. goto next_pkt_nopost;
  3062. }
  3063. work_mask |= opaque_key;
  3064. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  3065. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  3066. drop_it:
  3067. tg3_recycle_rx(tp, opaque_key,
  3068. desc_idx, *post_ptr);
  3069. drop_it_no_recycle:
  3070. /* Other statistics kept track of by card. */
  3071. tp->net_stats.rx_dropped++;
  3072. goto next_pkt;
  3073. }
  3074. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  3075. if (len > RX_COPY_THRESHOLD
  3076. && tp->rx_offset == 2
  3077. /* rx_offset != 2 iff this is a 5701 card running
  3078. * in PCI-X mode [see tg3_get_invariants()] */
  3079. ) {
  3080. int skb_size;
  3081. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  3082. desc_idx, *post_ptr);
  3083. if (skb_size < 0)
  3084. goto drop_it;
  3085. pci_unmap_single(tp->pdev, dma_addr,
  3086. skb_size - tp->rx_offset,
  3087. PCI_DMA_FROMDEVICE);
  3088. skb_put(skb, len);
  3089. } else {
  3090. struct sk_buff *copy_skb;
  3091. tg3_recycle_rx(tp, opaque_key,
  3092. desc_idx, *post_ptr);
  3093. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  3094. if (copy_skb == NULL)
  3095. goto drop_it_no_recycle;
  3096. skb_reserve(copy_skb, 2);
  3097. skb_put(copy_skb, len);
  3098. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  3099. skb_copy_from_linear_data(skb, copy_skb->data, len);
  3100. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  3101. /* We'll reuse the original ring buffer. */
  3102. skb = copy_skb;
  3103. }
  3104. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  3105. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  3106. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  3107. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  3108. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3109. else
  3110. skb->ip_summed = CHECKSUM_NONE;
  3111. skb->protocol = eth_type_trans(skb, tp->dev);
  3112. #if TG3_VLAN_TAG_USED
  3113. if (tp->vlgrp != NULL &&
  3114. desc->type_flags & RXD_FLAG_VLAN) {
  3115. tg3_vlan_rx(tp, skb,
  3116. desc->err_vlan & RXD_VLAN_MASK);
  3117. } else
  3118. #endif
  3119. netif_receive_skb(skb);
  3120. tp->dev->last_rx = jiffies;
  3121. received++;
  3122. budget--;
  3123. next_pkt:
  3124. (*post_ptr)++;
  3125. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  3126. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  3127. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  3128. TG3_64BIT_REG_LOW, idx);
  3129. work_mask &= ~RXD_OPAQUE_RING_STD;
  3130. rx_std_posted = 0;
  3131. }
  3132. next_pkt_nopost:
  3133. sw_idx++;
  3134. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  3135. /* Refresh hw_idx to see if there is new work */
  3136. if (sw_idx == hw_idx) {
  3137. hw_idx = tp->hw_status->idx[0].rx_producer;
  3138. rmb();
  3139. }
  3140. }
  3141. /* ACK the status ring. */
  3142. tp->rx_rcb_ptr = sw_idx;
  3143. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  3144. /* Refill RX ring(s). */
  3145. if (work_mask & RXD_OPAQUE_RING_STD) {
  3146. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  3147. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  3148. sw_idx);
  3149. }
  3150. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  3151. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  3152. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  3153. sw_idx);
  3154. }
  3155. mmiowb();
  3156. return received;
  3157. }
  3158. static int tg3_poll_work(struct tg3 *tp, int work_done, int budget)
  3159. {
  3160. struct tg3_hw_status *sblk = tp->hw_status;
  3161. /* handle link change and other phy events */
  3162. if (!(tp->tg3_flags &
  3163. (TG3_FLAG_USE_LINKCHG_REG |
  3164. TG3_FLAG_POLL_SERDES))) {
  3165. if (sblk->status & SD_STATUS_LINK_CHG) {
  3166. sblk->status = SD_STATUS_UPDATED |
  3167. (sblk->status & ~SD_STATUS_LINK_CHG);
  3168. spin_lock(&tp->lock);
  3169. tg3_setup_phy(tp, 0);
  3170. spin_unlock(&tp->lock);
  3171. }
  3172. }
  3173. /* run TX completion thread */
  3174. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  3175. tg3_tx(tp);
  3176. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
  3177. return work_done;
  3178. }
  3179. /* run RX thread, within the bounds set by NAPI.
  3180. * All RX "locking" is done by ensuring outside
  3181. * code synchronizes with tg3->napi.poll()
  3182. */
  3183. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  3184. work_done += tg3_rx(tp, budget - work_done);
  3185. return work_done;
  3186. }
  3187. static int tg3_poll(struct napi_struct *napi, int budget)
  3188. {
  3189. struct tg3 *tp = container_of(napi, struct tg3, napi);
  3190. int work_done = 0;
  3191. struct tg3_hw_status *sblk = tp->hw_status;
  3192. while (1) {
  3193. work_done = tg3_poll_work(tp, work_done, budget);
  3194. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
  3195. goto tx_recovery;
  3196. if (unlikely(work_done >= budget))
  3197. break;
  3198. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  3199. /* tp->last_tag is used in tg3_restart_ints() below
  3200. * to tell the hw how much work has been processed,
  3201. * so we must read it before checking for more work.
  3202. */
  3203. tp->last_tag = sblk->status_tag;
  3204. rmb();
  3205. } else
  3206. sblk->status &= ~SD_STATUS_UPDATED;
  3207. if (likely(!tg3_has_work(tp))) {
  3208. netif_rx_complete(tp->dev, napi);
  3209. tg3_restart_ints(tp);
  3210. break;
  3211. }
  3212. }
  3213. return work_done;
  3214. tx_recovery:
  3215. /* work_done is guaranteed to be less than budget. */
  3216. netif_rx_complete(tp->dev, napi);
  3217. schedule_work(&tp->reset_task);
  3218. return work_done;
  3219. }
  3220. static void tg3_irq_quiesce(struct tg3 *tp)
  3221. {
  3222. BUG_ON(tp->irq_sync);
  3223. tp->irq_sync = 1;
  3224. smp_mb();
  3225. synchronize_irq(tp->pdev->irq);
  3226. }
  3227. static inline int tg3_irq_sync(struct tg3 *tp)
  3228. {
  3229. return tp->irq_sync;
  3230. }
  3231. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  3232. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  3233. * with as well. Most of the time, this is not necessary except when
  3234. * shutting down the device.
  3235. */
  3236. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  3237. {
  3238. spin_lock_bh(&tp->lock);
  3239. if (irq_sync)
  3240. tg3_irq_quiesce(tp);
  3241. }
  3242. static inline void tg3_full_unlock(struct tg3 *tp)
  3243. {
  3244. spin_unlock_bh(&tp->lock);
  3245. }
  3246. /* One-shot MSI handler - Chip automatically disables interrupt
  3247. * after sending MSI so driver doesn't have to do it.
  3248. */
  3249. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  3250. {
  3251. struct net_device *dev = dev_id;
  3252. struct tg3 *tp = netdev_priv(dev);
  3253. prefetch(tp->hw_status);
  3254. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3255. if (likely(!tg3_irq_sync(tp)))
  3256. netif_rx_schedule(dev, &tp->napi);
  3257. return IRQ_HANDLED;
  3258. }
  3259. /* MSI ISR - No need to check for interrupt sharing and no need to
  3260. * flush status block and interrupt mailbox. PCI ordering rules
  3261. * guarantee that MSI will arrive after the status block.
  3262. */
  3263. static irqreturn_t tg3_msi(int irq, void *dev_id)
  3264. {
  3265. struct net_device *dev = dev_id;
  3266. struct tg3 *tp = netdev_priv(dev);
  3267. prefetch(tp->hw_status);
  3268. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3269. /*
  3270. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3271. * chip-internal interrupt pending events.
  3272. * Writing non-zero to intr-mbox-0 additional tells the
  3273. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3274. * event coalescing.
  3275. */
  3276. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3277. if (likely(!tg3_irq_sync(tp)))
  3278. netif_rx_schedule(dev, &tp->napi);
  3279. return IRQ_RETVAL(1);
  3280. }
  3281. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3282. {
  3283. struct net_device *dev = dev_id;
  3284. struct tg3 *tp = netdev_priv(dev);
  3285. struct tg3_hw_status *sblk = tp->hw_status;
  3286. unsigned int handled = 1;
  3287. /* In INTx mode, it is possible for the interrupt to arrive at
  3288. * the CPU before the status block posted prior to the interrupt.
  3289. * Reading the PCI State register will confirm whether the
  3290. * interrupt is ours and will flush the status block.
  3291. */
  3292. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3293. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3294. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3295. handled = 0;
  3296. goto out;
  3297. }
  3298. }
  3299. /*
  3300. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3301. * chip-internal interrupt pending events.
  3302. * Writing non-zero to intr-mbox-0 additional tells the
  3303. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3304. * event coalescing.
  3305. *
  3306. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3307. * spurious interrupts. The flush impacts performance but
  3308. * excessive spurious interrupts can be worse in some cases.
  3309. */
  3310. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3311. if (tg3_irq_sync(tp))
  3312. goto out;
  3313. sblk->status &= ~SD_STATUS_UPDATED;
  3314. if (likely(tg3_has_work(tp))) {
  3315. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3316. netif_rx_schedule(dev, &tp->napi);
  3317. } else {
  3318. /* No work, shared interrupt perhaps? re-enable
  3319. * interrupts, and flush that PCI write
  3320. */
  3321. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3322. 0x00000000);
  3323. }
  3324. out:
  3325. return IRQ_RETVAL(handled);
  3326. }
  3327. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3328. {
  3329. struct net_device *dev = dev_id;
  3330. struct tg3 *tp = netdev_priv(dev);
  3331. struct tg3_hw_status *sblk = tp->hw_status;
  3332. unsigned int handled = 1;
  3333. /* In INTx mode, it is possible for the interrupt to arrive at
  3334. * the CPU before the status block posted prior to the interrupt.
  3335. * Reading the PCI State register will confirm whether the
  3336. * interrupt is ours and will flush the status block.
  3337. */
  3338. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3339. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3340. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3341. handled = 0;
  3342. goto out;
  3343. }
  3344. }
  3345. /*
  3346. * writing any value to intr-mbox-0 clears PCI INTA# and
  3347. * chip-internal interrupt pending events.
  3348. * writing non-zero to intr-mbox-0 additional tells the
  3349. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3350. * event coalescing.
  3351. *
  3352. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3353. * spurious interrupts. The flush impacts performance but
  3354. * excessive spurious interrupts can be worse in some cases.
  3355. */
  3356. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3357. if (tg3_irq_sync(tp))
  3358. goto out;
  3359. if (netif_rx_schedule_prep(dev, &tp->napi)) {
  3360. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3361. /* Update last_tag to mark that this status has been
  3362. * seen. Because interrupt may be shared, we may be
  3363. * racing with tg3_poll(), so only update last_tag
  3364. * if tg3_poll() is not scheduled.
  3365. */
  3366. tp->last_tag = sblk->status_tag;
  3367. __netif_rx_schedule(dev, &tp->napi);
  3368. }
  3369. out:
  3370. return IRQ_RETVAL(handled);
  3371. }
  3372. /* ISR for interrupt test */
  3373. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3374. {
  3375. struct net_device *dev = dev_id;
  3376. struct tg3 *tp = netdev_priv(dev);
  3377. struct tg3_hw_status *sblk = tp->hw_status;
  3378. if ((sblk->status & SD_STATUS_UPDATED) ||
  3379. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3380. tg3_disable_ints(tp);
  3381. return IRQ_RETVAL(1);
  3382. }
  3383. return IRQ_RETVAL(0);
  3384. }
  3385. static int tg3_init_hw(struct tg3 *, int);
  3386. static int tg3_halt(struct tg3 *, int, int);
  3387. /* Restart hardware after configuration changes, self-test, etc.
  3388. * Invoked with tp->lock held.
  3389. */
  3390. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3391. {
  3392. int err;
  3393. err = tg3_init_hw(tp, reset_phy);
  3394. if (err) {
  3395. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3396. "aborting.\n", tp->dev->name);
  3397. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3398. tg3_full_unlock(tp);
  3399. del_timer_sync(&tp->timer);
  3400. tp->irq_sync = 0;
  3401. napi_enable(&tp->napi);
  3402. dev_close(tp->dev);
  3403. tg3_full_lock(tp, 0);
  3404. }
  3405. return err;
  3406. }
  3407. #ifdef CONFIG_NET_POLL_CONTROLLER
  3408. static void tg3_poll_controller(struct net_device *dev)
  3409. {
  3410. struct tg3 *tp = netdev_priv(dev);
  3411. tg3_interrupt(tp->pdev->irq, dev);
  3412. }
  3413. #endif
  3414. static void tg3_reset_task(struct work_struct *work)
  3415. {
  3416. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3417. unsigned int restart_timer;
  3418. tg3_full_lock(tp, 0);
  3419. if (!netif_running(tp->dev)) {
  3420. tg3_full_unlock(tp);
  3421. return;
  3422. }
  3423. tg3_full_unlock(tp);
  3424. tg3_netif_stop(tp);
  3425. tg3_full_lock(tp, 1);
  3426. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3427. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3428. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3429. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3430. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3431. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3432. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3433. }
  3434. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3435. if (tg3_init_hw(tp, 1))
  3436. goto out;
  3437. tg3_netif_start(tp);
  3438. if (restart_timer)
  3439. mod_timer(&tp->timer, jiffies + 1);
  3440. out:
  3441. tg3_full_unlock(tp);
  3442. }
  3443. static void tg3_dump_short_state(struct tg3 *tp)
  3444. {
  3445. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3446. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3447. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3448. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3449. }
  3450. static void tg3_tx_timeout(struct net_device *dev)
  3451. {
  3452. struct tg3 *tp = netdev_priv(dev);
  3453. if (netif_msg_tx_err(tp)) {
  3454. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3455. dev->name);
  3456. tg3_dump_short_state(tp);
  3457. }
  3458. schedule_work(&tp->reset_task);
  3459. }
  3460. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3461. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3462. {
  3463. u32 base = (u32) mapping & 0xffffffff;
  3464. return ((base > 0xffffdcc0) &&
  3465. (base + len + 8 < base));
  3466. }
  3467. /* Test for DMA addresses > 40-bit */
  3468. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3469. int len)
  3470. {
  3471. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3472. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3473. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3474. return 0;
  3475. #else
  3476. return 0;
  3477. #endif
  3478. }
  3479. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3480. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3481. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3482. u32 last_plus_one, u32 *start,
  3483. u32 base_flags, u32 mss)
  3484. {
  3485. struct sk_buff *new_skb;
  3486. dma_addr_t new_addr = 0;
  3487. u32 entry = *start;
  3488. int i, ret = 0;
  3489. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  3490. new_skb = skb_copy(skb, GFP_ATOMIC);
  3491. else {
  3492. int more_headroom = 4 - ((unsigned long)skb->data & 3);
  3493. new_skb = skb_copy_expand(skb,
  3494. skb_headroom(skb) + more_headroom,
  3495. skb_tailroom(skb), GFP_ATOMIC);
  3496. }
  3497. if (!new_skb) {
  3498. ret = -1;
  3499. } else {
  3500. /* New SKB is guaranteed to be linear. */
  3501. entry = *start;
  3502. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3503. PCI_DMA_TODEVICE);
  3504. /* Make sure new skb does not cross any 4G boundaries.
  3505. * Drop the packet if it does.
  3506. */
  3507. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3508. ret = -1;
  3509. dev_kfree_skb(new_skb);
  3510. new_skb = NULL;
  3511. } else {
  3512. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3513. base_flags, 1 | (mss << 1));
  3514. *start = NEXT_TX(entry);
  3515. }
  3516. }
  3517. /* Now clean up the sw ring entries. */
  3518. i = 0;
  3519. while (entry != last_plus_one) {
  3520. int len;
  3521. if (i == 0)
  3522. len = skb_headlen(skb);
  3523. else
  3524. len = skb_shinfo(skb)->frags[i-1].size;
  3525. pci_unmap_single(tp->pdev,
  3526. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3527. len, PCI_DMA_TODEVICE);
  3528. if (i == 0) {
  3529. tp->tx_buffers[entry].skb = new_skb;
  3530. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3531. } else {
  3532. tp->tx_buffers[entry].skb = NULL;
  3533. }
  3534. entry = NEXT_TX(entry);
  3535. i++;
  3536. }
  3537. dev_kfree_skb(skb);
  3538. return ret;
  3539. }
  3540. static void tg3_set_txd(struct tg3 *tp, int entry,
  3541. dma_addr_t mapping, int len, u32 flags,
  3542. u32 mss_and_is_end)
  3543. {
  3544. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3545. int is_end = (mss_and_is_end & 0x1);
  3546. u32 mss = (mss_and_is_end >> 1);
  3547. u32 vlan_tag = 0;
  3548. if (is_end)
  3549. flags |= TXD_FLAG_END;
  3550. if (flags & TXD_FLAG_VLAN) {
  3551. vlan_tag = flags >> 16;
  3552. flags &= 0xffff;
  3553. }
  3554. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3555. txd->addr_hi = ((u64) mapping >> 32);
  3556. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3557. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3558. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3559. }
  3560. /* hard_start_xmit for devices that don't have any bugs and
  3561. * support TG3_FLG2_HW_TSO_2 only.
  3562. */
  3563. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3564. {
  3565. struct tg3 *tp = netdev_priv(dev);
  3566. dma_addr_t mapping;
  3567. u32 len, entry, base_flags, mss;
  3568. len = skb_headlen(skb);
  3569. /* We are running in BH disabled context with netif_tx_lock
  3570. * and TX reclaim runs via tp->napi.poll inside of a software
  3571. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3572. * no IRQ context deadlocks to worry about either. Rejoice!
  3573. */
  3574. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3575. if (!netif_queue_stopped(dev)) {
  3576. netif_stop_queue(dev);
  3577. /* This is a hard error, log it. */
  3578. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3579. "queue awake!\n", dev->name);
  3580. }
  3581. return NETDEV_TX_BUSY;
  3582. }
  3583. entry = tp->tx_prod;
  3584. base_flags = 0;
  3585. mss = 0;
  3586. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3587. int tcp_opt_len, ip_tcp_len;
  3588. if (skb_header_cloned(skb) &&
  3589. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3590. dev_kfree_skb(skb);
  3591. goto out_unlock;
  3592. }
  3593. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3594. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3595. else {
  3596. struct iphdr *iph = ip_hdr(skb);
  3597. tcp_opt_len = tcp_optlen(skb);
  3598. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3599. iph->check = 0;
  3600. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3601. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3602. }
  3603. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3604. TXD_FLAG_CPU_POST_DMA);
  3605. tcp_hdr(skb)->check = 0;
  3606. }
  3607. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3608. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3609. #if TG3_VLAN_TAG_USED
  3610. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3611. base_flags |= (TXD_FLAG_VLAN |
  3612. (vlan_tx_tag_get(skb) << 16));
  3613. #endif
  3614. /* Queue skb data, a.k.a. the main skb fragment. */
  3615. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3616. tp->tx_buffers[entry].skb = skb;
  3617. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3618. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3619. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3620. entry = NEXT_TX(entry);
  3621. /* Now loop through additional data fragments, and queue them. */
  3622. if (skb_shinfo(skb)->nr_frags > 0) {
  3623. unsigned int i, last;
  3624. last = skb_shinfo(skb)->nr_frags - 1;
  3625. for (i = 0; i <= last; i++) {
  3626. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3627. len = frag->size;
  3628. mapping = pci_map_page(tp->pdev,
  3629. frag->page,
  3630. frag->page_offset,
  3631. len, PCI_DMA_TODEVICE);
  3632. tp->tx_buffers[entry].skb = NULL;
  3633. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3634. tg3_set_txd(tp, entry, mapping, len,
  3635. base_flags, (i == last) | (mss << 1));
  3636. entry = NEXT_TX(entry);
  3637. }
  3638. }
  3639. /* Packets are ready, update Tx producer idx local and on card. */
  3640. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3641. tp->tx_prod = entry;
  3642. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3643. netif_stop_queue(dev);
  3644. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3645. netif_wake_queue(tp->dev);
  3646. }
  3647. out_unlock:
  3648. mmiowb();
  3649. dev->trans_start = jiffies;
  3650. return NETDEV_TX_OK;
  3651. }
  3652. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3653. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3654. * TSO header is greater than 80 bytes.
  3655. */
  3656. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3657. {
  3658. struct sk_buff *segs, *nskb;
  3659. /* Estimate the number of fragments in the worst case */
  3660. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3661. netif_stop_queue(tp->dev);
  3662. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3663. return NETDEV_TX_BUSY;
  3664. netif_wake_queue(tp->dev);
  3665. }
  3666. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3667. if (unlikely(IS_ERR(segs)))
  3668. goto tg3_tso_bug_end;
  3669. do {
  3670. nskb = segs;
  3671. segs = segs->next;
  3672. nskb->next = NULL;
  3673. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3674. } while (segs);
  3675. tg3_tso_bug_end:
  3676. dev_kfree_skb(skb);
  3677. return NETDEV_TX_OK;
  3678. }
  3679. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3680. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3681. */
  3682. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3683. {
  3684. struct tg3 *tp = netdev_priv(dev);
  3685. dma_addr_t mapping;
  3686. u32 len, entry, base_flags, mss;
  3687. int would_hit_hwbug;
  3688. len = skb_headlen(skb);
  3689. /* We are running in BH disabled context with netif_tx_lock
  3690. * and TX reclaim runs via tp->napi.poll inside of a software
  3691. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3692. * no IRQ context deadlocks to worry about either. Rejoice!
  3693. */
  3694. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3695. if (!netif_queue_stopped(dev)) {
  3696. netif_stop_queue(dev);
  3697. /* This is a hard error, log it. */
  3698. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3699. "queue awake!\n", dev->name);
  3700. }
  3701. return NETDEV_TX_BUSY;
  3702. }
  3703. entry = tp->tx_prod;
  3704. base_flags = 0;
  3705. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3706. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3707. mss = 0;
  3708. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3709. struct iphdr *iph;
  3710. int tcp_opt_len, ip_tcp_len, hdr_len;
  3711. if (skb_header_cloned(skb) &&
  3712. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3713. dev_kfree_skb(skb);
  3714. goto out_unlock;
  3715. }
  3716. tcp_opt_len = tcp_optlen(skb);
  3717. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3718. hdr_len = ip_tcp_len + tcp_opt_len;
  3719. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3720. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3721. return (tg3_tso_bug(tp, skb));
  3722. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3723. TXD_FLAG_CPU_POST_DMA);
  3724. iph = ip_hdr(skb);
  3725. iph->check = 0;
  3726. iph->tot_len = htons(mss + hdr_len);
  3727. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3728. tcp_hdr(skb)->check = 0;
  3729. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3730. } else
  3731. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3732. iph->daddr, 0,
  3733. IPPROTO_TCP,
  3734. 0);
  3735. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3736. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3737. if (tcp_opt_len || iph->ihl > 5) {
  3738. int tsflags;
  3739. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3740. mss |= (tsflags << 11);
  3741. }
  3742. } else {
  3743. if (tcp_opt_len || iph->ihl > 5) {
  3744. int tsflags;
  3745. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3746. base_flags |= tsflags << 12;
  3747. }
  3748. }
  3749. }
  3750. #if TG3_VLAN_TAG_USED
  3751. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3752. base_flags |= (TXD_FLAG_VLAN |
  3753. (vlan_tx_tag_get(skb) << 16));
  3754. #endif
  3755. /* Queue skb data, a.k.a. the main skb fragment. */
  3756. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3757. tp->tx_buffers[entry].skb = skb;
  3758. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3759. would_hit_hwbug = 0;
  3760. if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG)
  3761. would_hit_hwbug = 1;
  3762. else if (tg3_4g_overflow_test(mapping, len))
  3763. would_hit_hwbug = 1;
  3764. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3765. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3766. entry = NEXT_TX(entry);
  3767. /* Now loop through additional data fragments, and queue them. */
  3768. if (skb_shinfo(skb)->nr_frags > 0) {
  3769. unsigned int i, last;
  3770. last = skb_shinfo(skb)->nr_frags - 1;
  3771. for (i = 0; i <= last; i++) {
  3772. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3773. len = frag->size;
  3774. mapping = pci_map_page(tp->pdev,
  3775. frag->page,
  3776. frag->page_offset,
  3777. len, PCI_DMA_TODEVICE);
  3778. tp->tx_buffers[entry].skb = NULL;
  3779. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3780. if (tg3_4g_overflow_test(mapping, len))
  3781. would_hit_hwbug = 1;
  3782. if (tg3_40bit_overflow_test(tp, mapping, len))
  3783. would_hit_hwbug = 1;
  3784. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3785. tg3_set_txd(tp, entry, mapping, len,
  3786. base_flags, (i == last)|(mss << 1));
  3787. else
  3788. tg3_set_txd(tp, entry, mapping, len,
  3789. base_flags, (i == last));
  3790. entry = NEXT_TX(entry);
  3791. }
  3792. }
  3793. if (would_hit_hwbug) {
  3794. u32 last_plus_one = entry;
  3795. u32 start;
  3796. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3797. start &= (TG3_TX_RING_SIZE - 1);
  3798. /* If the workaround fails due to memory/mapping
  3799. * failure, silently drop this packet.
  3800. */
  3801. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3802. &start, base_flags, mss))
  3803. goto out_unlock;
  3804. entry = start;
  3805. }
  3806. /* Packets are ready, update Tx producer idx local and on card. */
  3807. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3808. tp->tx_prod = entry;
  3809. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3810. netif_stop_queue(dev);
  3811. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3812. netif_wake_queue(tp->dev);
  3813. }
  3814. out_unlock:
  3815. mmiowb();
  3816. dev->trans_start = jiffies;
  3817. return NETDEV_TX_OK;
  3818. }
  3819. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3820. int new_mtu)
  3821. {
  3822. dev->mtu = new_mtu;
  3823. if (new_mtu > ETH_DATA_LEN) {
  3824. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3825. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3826. ethtool_op_set_tso(dev, 0);
  3827. }
  3828. else
  3829. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3830. } else {
  3831. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3832. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3833. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3834. }
  3835. }
  3836. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3837. {
  3838. struct tg3 *tp = netdev_priv(dev);
  3839. int err;
  3840. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3841. return -EINVAL;
  3842. if (!netif_running(dev)) {
  3843. /* We'll just catch it later when the
  3844. * device is up'd.
  3845. */
  3846. tg3_set_mtu(dev, tp, new_mtu);
  3847. return 0;
  3848. }
  3849. tg3_netif_stop(tp);
  3850. tg3_full_lock(tp, 1);
  3851. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3852. tg3_set_mtu(dev, tp, new_mtu);
  3853. err = tg3_restart_hw(tp, 0);
  3854. if (!err)
  3855. tg3_netif_start(tp);
  3856. tg3_full_unlock(tp);
  3857. return err;
  3858. }
  3859. /* Free up pending packets in all rx/tx rings.
  3860. *
  3861. * The chip has been shut down and the driver detached from
  3862. * the networking, so no interrupts or new tx packets will
  3863. * end up in the driver. tp->{tx,}lock is not held and we are not
  3864. * in an interrupt context and thus may sleep.
  3865. */
  3866. static void tg3_free_rings(struct tg3 *tp)
  3867. {
  3868. struct ring_info *rxp;
  3869. int i;
  3870. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3871. rxp = &tp->rx_std_buffers[i];
  3872. if (rxp->skb == NULL)
  3873. continue;
  3874. pci_unmap_single(tp->pdev,
  3875. pci_unmap_addr(rxp, mapping),
  3876. tp->rx_pkt_buf_sz - tp->rx_offset,
  3877. PCI_DMA_FROMDEVICE);
  3878. dev_kfree_skb_any(rxp->skb);
  3879. rxp->skb = NULL;
  3880. }
  3881. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3882. rxp = &tp->rx_jumbo_buffers[i];
  3883. if (rxp->skb == NULL)
  3884. continue;
  3885. pci_unmap_single(tp->pdev,
  3886. pci_unmap_addr(rxp, mapping),
  3887. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3888. PCI_DMA_FROMDEVICE);
  3889. dev_kfree_skb_any(rxp->skb);
  3890. rxp->skb = NULL;
  3891. }
  3892. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3893. struct tx_ring_info *txp;
  3894. struct sk_buff *skb;
  3895. int j;
  3896. txp = &tp->tx_buffers[i];
  3897. skb = txp->skb;
  3898. if (skb == NULL) {
  3899. i++;
  3900. continue;
  3901. }
  3902. pci_unmap_single(tp->pdev,
  3903. pci_unmap_addr(txp, mapping),
  3904. skb_headlen(skb),
  3905. PCI_DMA_TODEVICE);
  3906. txp->skb = NULL;
  3907. i++;
  3908. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3909. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3910. pci_unmap_page(tp->pdev,
  3911. pci_unmap_addr(txp, mapping),
  3912. skb_shinfo(skb)->frags[j].size,
  3913. PCI_DMA_TODEVICE);
  3914. i++;
  3915. }
  3916. dev_kfree_skb_any(skb);
  3917. }
  3918. }
  3919. /* Initialize tx/rx rings for packet processing.
  3920. *
  3921. * The chip has been shut down and the driver detached from
  3922. * the networking, so no interrupts or new tx packets will
  3923. * end up in the driver. tp->{tx,}lock are held and thus
  3924. * we may not sleep.
  3925. */
  3926. static int tg3_init_rings(struct tg3 *tp)
  3927. {
  3928. u32 i;
  3929. /* Free up all the SKBs. */
  3930. tg3_free_rings(tp);
  3931. /* Zero out all descriptors. */
  3932. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3933. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3934. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3935. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3936. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3937. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3938. (tp->dev->mtu > ETH_DATA_LEN))
  3939. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3940. /* Initialize invariants of the rings, we only set this
  3941. * stuff once. This works because the card does not
  3942. * write into the rx buffer posting rings.
  3943. */
  3944. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3945. struct tg3_rx_buffer_desc *rxd;
  3946. rxd = &tp->rx_std[i];
  3947. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3948. << RXD_LEN_SHIFT;
  3949. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3950. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3951. (i << RXD_OPAQUE_INDEX_SHIFT));
  3952. }
  3953. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3954. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3955. struct tg3_rx_buffer_desc *rxd;
  3956. rxd = &tp->rx_jumbo[i];
  3957. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3958. << RXD_LEN_SHIFT;
  3959. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3960. RXD_FLAG_JUMBO;
  3961. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3962. (i << RXD_OPAQUE_INDEX_SHIFT));
  3963. }
  3964. }
  3965. /* Now allocate fresh SKBs for each rx ring. */
  3966. for (i = 0; i < tp->rx_pending; i++) {
  3967. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3968. printk(KERN_WARNING PFX
  3969. "%s: Using a smaller RX standard ring, "
  3970. "only %d out of %d buffers were allocated "
  3971. "successfully.\n",
  3972. tp->dev->name, i, tp->rx_pending);
  3973. if (i == 0)
  3974. return -ENOMEM;
  3975. tp->rx_pending = i;
  3976. break;
  3977. }
  3978. }
  3979. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3980. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3981. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3982. -1, i) < 0) {
  3983. printk(KERN_WARNING PFX
  3984. "%s: Using a smaller RX jumbo ring, "
  3985. "only %d out of %d buffers were "
  3986. "allocated successfully.\n",
  3987. tp->dev->name, i, tp->rx_jumbo_pending);
  3988. if (i == 0) {
  3989. tg3_free_rings(tp);
  3990. return -ENOMEM;
  3991. }
  3992. tp->rx_jumbo_pending = i;
  3993. break;
  3994. }
  3995. }
  3996. }
  3997. return 0;
  3998. }
  3999. /*
  4000. * Must not be invoked with interrupt sources disabled and
  4001. * the hardware shutdown down.
  4002. */
  4003. static void tg3_free_consistent(struct tg3 *tp)
  4004. {
  4005. kfree(tp->rx_std_buffers);
  4006. tp->rx_std_buffers = NULL;
  4007. if (tp->rx_std) {
  4008. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  4009. tp->rx_std, tp->rx_std_mapping);
  4010. tp->rx_std = NULL;
  4011. }
  4012. if (tp->rx_jumbo) {
  4013. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  4014. tp->rx_jumbo, tp->rx_jumbo_mapping);
  4015. tp->rx_jumbo = NULL;
  4016. }
  4017. if (tp->rx_rcb) {
  4018. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  4019. tp->rx_rcb, tp->rx_rcb_mapping);
  4020. tp->rx_rcb = NULL;
  4021. }
  4022. if (tp->tx_ring) {
  4023. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  4024. tp->tx_ring, tp->tx_desc_mapping);
  4025. tp->tx_ring = NULL;
  4026. }
  4027. if (tp->hw_status) {
  4028. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  4029. tp->hw_status, tp->status_mapping);
  4030. tp->hw_status = NULL;
  4031. }
  4032. if (tp->hw_stats) {
  4033. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  4034. tp->hw_stats, tp->stats_mapping);
  4035. tp->hw_stats = NULL;
  4036. }
  4037. }
  4038. /*
  4039. * Must not be invoked with interrupt sources disabled and
  4040. * the hardware shutdown down. Can sleep.
  4041. */
  4042. static int tg3_alloc_consistent(struct tg3 *tp)
  4043. {
  4044. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  4045. (TG3_RX_RING_SIZE +
  4046. TG3_RX_JUMBO_RING_SIZE)) +
  4047. (sizeof(struct tx_ring_info) *
  4048. TG3_TX_RING_SIZE),
  4049. GFP_KERNEL);
  4050. if (!tp->rx_std_buffers)
  4051. return -ENOMEM;
  4052. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  4053. tp->tx_buffers = (struct tx_ring_info *)
  4054. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  4055. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  4056. &tp->rx_std_mapping);
  4057. if (!tp->rx_std)
  4058. goto err_out;
  4059. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  4060. &tp->rx_jumbo_mapping);
  4061. if (!tp->rx_jumbo)
  4062. goto err_out;
  4063. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  4064. &tp->rx_rcb_mapping);
  4065. if (!tp->rx_rcb)
  4066. goto err_out;
  4067. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  4068. &tp->tx_desc_mapping);
  4069. if (!tp->tx_ring)
  4070. goto err_out;
  4071. tp->hw_status = pci_alloc_consistent(tp->pdev,
  4072. TG3_HW_STATUS_SIZE,
  4073. &tp->status_mapping);
  4074. if (!tp->hw_status)
  4075. goto err_out;
  4076. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  4077. sizeof(struct tg3_hw_stats),
  4078. &tp->stats_mapping);
  4079. if (!tp->hw_stats)
  4080. goto err_out;
  4081. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  4082. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  4083. return 0;
  4084. err_out:
  4085. tg3_free_consistent(tp);
  4086. return -ENOMEM;
  4087. }
  4088. #define MAX_WAIT_CNT 1000
  4089. /* To stop a block, clear the enable bit and poll till it
  4090. * clears. tp->lock is held.
  4091. */
  4092. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  4093. {
  4094. unsigned int i;
  4095. u32 val;
  4096. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  4097. switch (ofs) {
  4098. case RCVLSC_MODE:
  4099. case DMAC_MODE:
  4100. case MBFREE_MODE:
  4101. case BUFMGR_MODE:
  4102. case MEMARB_MODE:
  4103. /* We can't enable/disable these bits of the
  4104. * 5705/5750, just say success.
  4105. */
  4106. return 0;
  4107. default:
  4108. break;
  4109. };
  4110. }
  4111. val = tr32(ofs);
  4112. val &= ~enable_bit;
  4113. tw32_f(ofs, val);
  4114. for (i = 0; i < MAX_WAIT_CNT; i++) {
  4115. udelay(100);
  4116. val = tr32(ofs);
  4117. if ((val & enable_bit) == 0)
  4118. break;
  4119. }
  4120. if (i == MAX_WAIT_CNT && !silent) {
  4121. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  4122. "ofs=%lx enable_bit=%x\n",
  4123. ofs, enable_bit);
  4124. return -ENODEV;
  4125. }
  4126. return 0;
  4127. }
  4128. /* tp->lock is held. */
  4129. static int tg3_abort_hw(struct tg3 *tp, int silent)
  4130. {
  4131. int i, err;
  4132. tg3_disable_ints(tp);
  4133. tp->rx_mode &= ~RX_MODE_ENABLE;
  4134. tw32_f(MAC_RX_MODE, tp->rx_mode);
  4135. udelay(10);
  4136. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  4137. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  4138. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  4139. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  4140. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  4141. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  4142. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  4143. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  4144. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  4145. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  4146. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  4147. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  4148. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  4149. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  4150. tw32_f(MAC_MODE, tp->mac_mode);
  4151. udelay(40);
  4152. tp->tx_mode &= ~TX_MODE_ENABLE;
  4153. tw32_f(MAC_TX_MODE, tp->tx_mode);
  4154. for (i = 0; i < MAX_WAIT_CNT; i++) {
  4155. udelay(100);
  4156. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  4157. break;
  4158. }
  4159. if (i >= MAX_WAIT_CNT) {
  4160. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  4161. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  4162. tp->dev->name, tr32(MAC_TX_MODE));
  4163. err |= -ENODEV;
  4164. }
  4165. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  4166. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  4167. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  4168. tw32(FTQ_RESET, 0xffffffff);
  4169. tw32(FTQ_RESET, 0x00000000);
  4170. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  4171. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  4172. if (tp->hw_status)
  4173. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  4174. if (tp->hw_stats)
  4175. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  4176. return err;
  4177. }
  4178. /* tp->lock is held. */
  4179. static int tg3_nvram_lock(struct tg3 *tp)
  4180. {
  4181. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  4182. int i;
  4183. if (tp->nvram_lock_cnt == 0) {
  4184. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  4185. for (i = 0; i < 8000; i++) {
  4186. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  4187. break;
  4188. udelay(20);
  4189. }
  4190. if (i == 8000) {
  4191. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  4192. return -ENODEV;
  4193. }
  4194. }
  4195. tp->nvram_lock_cnt++;
  4196. }
  4197. return 0;
  4198. }
  4199. /* tp->lock is held. */
  4200. static void tg3_nvram_unlock(struct tg3 *tp)
  4201. {
  4202. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  4203. if (tp->nvram_lock_cnt > 0)
  4204. tp->nvram_lock_cnt--;
  4205. if (tp->nvram_lock_cnt == 0)
  4206. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  4207. }
  4208. }
  4209. /* tp->lock is held. */
  4210. static void tg3_enable_nvram_access(struct tg3 *tp)
  4211. {
  4212. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  4213. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  4214. u32 nvaccess = tr32(NVRAM_ACCESS);
  4215. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  4216. }
  4217. }
  4218. /* tp->lock is held. */
  4219. static void tg3_disable_nvram_access(struct tg3 *tp)
  4220. {
  4221. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  4222. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  4223. u32 nvaccess = tr32(NVRAM_ACCESS);
  4224. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  4225. }
  4226. }
  4227. static void tg3_ape_send_event(struct tg3 *tp, u32 event)
  4228. {
  4229. int i;
  4230. u32 apedata;
  4231. apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
  4232. if (apedata != APE_SEG_SIG_MAGIC)
  4233. return;
  4234. apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
  4235. if (apedata != APE_FW_STATUS_READY)
  4236. return;
  4237. /* Wait for up to 1 millisecond for APE to service previous event. */
  4238. for (i = 0; i < 10; i++) {
  4239. if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
  4240. return;
  4241. apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
  4242. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4243. tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
  4244. event | APE_EVENT_STATUS_EVENT_PENDING);
  4245. tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
  4246. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4247. break;
  4248. udelay(100);
  4249. }
  4250. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4251. tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
  4252. }
  4253. static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
  4254. {
  4255. u32 event;
  4256. u32 apedata;
  4257. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  4258. return;
  4259. switch (kind) {
  4260. case RESET_KIND_INIT:
  4261. tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG,
  4262. APE_HOST_SEG_SIG_MAGIC);
  4263. tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN,
  4264. APE_HOST_SEG_LEN_MAGIC);
  4265. apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT);
  4266. tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata);
  4267. tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID,
  4268. APE_HOST_DRIVER_ID_MAGIC);
  4269. tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR,
  4270. APE_HOST_BEHAV_NO_PHYLOCK);
  4271. event = APE_EVENT_STATUS_STATE_START;
  4272. break;
  4273. case RESET_KIND_SHUTDOWN:
  4274. event = APE_EVENT_STATUS_STATE_UNLOAD;
  4275. break;
  4276. case RESET_KIND_SUSPEND:
  4277. event = APE_EVENT_STATUS_STATE_SUSPEND;
  4278. break;
  4279. default:
  4280. return;
  4281. }
  4282. event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE;
  4283. tg3_ape_send_event(tp, event);
  4284. }
  4285. /* tp->lock is held. */
  4286. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  4287. {
  4288. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  4289. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  4290. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4291. switch (kind) {
  4292. case RESET_KIND_INIT:
  4293. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4294. DRV_STATE_START);
  4295. break;
  4296. case RESET_KIND_SHUTDOWN:
  4297. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4298. DRV_STATE_UNLOAD);
  4299. break;
  4300. case RESET_KIND_SUSPEND:
  4301. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4302. DRV_STATE_SUSPEND);
  4303. break;
  4304. default:
  4305. break;
  4306. };
  4307. }
  4308. if (kind == RESET_KIND_INIT ||
  4309. kind == RESET_KIND_SUSPEND)
  4310. tg3_ape_driver_state_change(tp, kind);
  4311. }
  4312. /* tp->lock is held. */
  4313. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  4314. {
  4315. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4316. switch (kind) {
  4317. case RESET_KIND_INIT:
  4318. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4319. DRV_STATE_START_DONE);
  4320. break;
  4321. case RESET_KIND_SHUTDOWN:
  4322. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4323. DRV_STATE_UNLOAD_DONE);
  4324. break;
  4325. default:
  4326. break;
  4327. };
  4328. }
  4329. if (kind == RESET_KIND_SHUTDOWN)
  4330. tg3_ape_driver_state_change(tp, kind);
  4331. }
  4332. /* tp->lock is held. */
  4333. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  4334. {
  4335. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4336. switch (kind) {
  4337. case RESET_KIND_INIT:
  4338. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4339. DRV_STATE_START);
  4340. break;
  4341. case RESET_KIND_SHUTDOWN:
  4342. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4343. DRV_STATE_UNLOAD);
  4344. break;
  4345. case RESET_KIND_SUSPEND:
  4346. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4347. DRV_STATE_SUSPEND);
  4348. break;
  4349. default:
  4350. break;
  4351. };
  4352. }
  4353. }
  4354. static int tg3_poll_fw(struct tg3 *tp)
  4355. {
  4356. int i;
  4357. u32 val;
  4358. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4359. /* Wait up to 20ms for init done. */
  4360. for (i = 0; i < 200; i++) {
  4361. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4362. return 0;
  4363. udelay(100);
  4364. }
  4365. return -ENODEV;
  4366. }
  4367. /* Wait for firmware initialization to complete. */
  4368. for (i = 0; i < 100000; i++) {
  4369. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4370. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4371. break;
  4372. udelay(10);
  4373. }
  4374. /* Chip might not be fitted with firmware. Some Sun onboard
  4375. * parts are configured like that. So don't signal the timeout
  4376. * of the above loop as an error, but do report the lack of
  4377. * running firmware once.
  4378. */
  4379. if (i >= 100000 &&
  4380. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4381. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4382. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4383. tp->dev->name);
  4384. }
  4385. return 0;
  4386. }
  4387. /* Save PCI command register before chip reset */
  4388. static void tg3_save_pci_state(struct tg3 *tp)
  4389. {
  4390. pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd);
  4391. }
  4392. /* Restore PCI state after chip reset */
  4393. static void tg3_restore_pci_state(struct tg3 *tp)
  4394. {
  4395. u32 val;
  4396. /* Re-enable indirect register accesses. */
  4397. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4398. tp->misc_host_ctrl);
  4399. /* Set MAX PCI retry to zero. */
  4400. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4401. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4402. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4403. val |= PCISTATE_RETRY_SAME_DMA;
  4404. /* Allow reads and writes to the APE register and memory space. */
  4405. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
  4406. val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  4407. PCISTATE_ALLOW_APE_SHMEM_WR;
  4408. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4409. pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd);
  4410. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  4411. pcie_set_readrq(tp->pdev, 4096);
  4412. else {
  4413. pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE,
  4414. tp->pci_cacheline_sz);
  4415. pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER,
  4416. tp->pci_lat_timer);
  4417. }
  4418. /* Make sure PCI-X relaxed ordering bit is clear. */
  4419. if (tp->pcix_cap) {
  4420. u16 pcix_cmd;
  4421. pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  4422. &pcix_cmd);
  4423. pcix_cmd &= ~PCI_X_CMD_ERO;
  4424. pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  4425. pcix_cmd);
  4426. }
  4427. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4428. /* Chip reset on 5780 will reset MSI enable bit,
  4429. * so need to restore it.
  4430. */
  4431. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4432. u16 ctrl;
  4433. pci_read_config_word(tp->pdev,
  4434. tp->msi_cap + PCI_MSI_FLAGS,
  4435. &ctrl);
  4436. pci_write_config_word(tp->pdev,
  4437. tp->msi_cap + PCI_MSI_FLAGS,
  4438. ctrl | PCI_MSI_FLAGS_ENABLE);
  4439. val = tr32(MSGINT_MODE);
  4440. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4441. }
  4442. }
  4443. }
  4444. static void tg3_stop_fw(struct tg3 *);
  4445. /* tp->lock is held. */
  4446. static int tg3_chip_reset(struct tg3 *tp)
  4447. {
  4448. u32 val;
  4449. void (*write_op)(struct tg3 *, u32, u32);
  4450. int err;
  4451. tg3_nvram_lock(tp);
  4452. /* No matching tg3_nvram_unlock() after this because
  4453. * chip reset below will undo the nvram lock.
  4454. */
  4455. tp->nvram_lock_cnt = 0;
  4456. /* GRC_MISC_CFG core clock reset will clear the memory
  4457. * enable bit in PCI register 4 and the MSI enable bit
  4458. * on some chips, so we save relevant registers here.
  4459. */
  4460. tg3_save_pci_state(tp);
  4461. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4462. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4463. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  4464. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  4465. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  4466. tw32(GRC_FASTBOOT_PC, 0);
  4467. /*
  4468. * We must avoid the readl() that normally takes place.
  4469. * It locks machines, causes machine checks, and other
  4470. * fun things. So, temporarily disable the 5701
  4471. * hardware workaround, while we do the reset.
  4472. */
  4473. write_op = tp->write32;
  4474. if (write_op == tg3_write_flush_reg32)
  4475. tp->write32 = tg3_write32;
  4476. /* Prevent the irq handler from reading or writing PCI registers
  4477. * during chip reset when the memory enable bit in the PCI command
  4478. * register may be cleared. The chip does not generate interrupt
  4479. * at this time, but the irq handler may still be called due to irq
  4480. * sharing or irqpoll.
  4481. */
  4482. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4483. if (tp->hw_status) {
  4484. tp->hw_status->status = 0;
  4485. tp->hw_status->status_tag = 0;
  4486. }
  4487. tp->last_tag = 0;
  4488. smp_mb();
  4489. synchronize_irq(tp->pdev->irq);
  4490. /* do the reset */
  4491. val = GRC_MISC_CFG_CORECLK_RESET;
  4492. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4493. if (tr32(0x7e2c) == 0x60) {
  4494. tw32(0x7e2c, 0x20);
  4495. }
  4496. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4497. tw32(GRC_MISC_CFG, (1 << 29));
  4498. val |= (1 << 29);
  4499. }
  4500. }
  4501. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4502. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4503. tw32(GRC_VCPU_EXT_CTRL,
  4504. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4505. }
  4506. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4507. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4508. tw32(GRC_MISC_CFG, val);
  4509. /* restore 5701 hardware bug workaround write method */
  4510. tp->write32 = write_op;
  4511. /* Unfortunately, we have to delay before the PCI read back.
  4512. * Some 575X chips even will not respond to a PCI cfg access
  4513. * when the reset command is given to the chip.
  4514. *
  4515. * How do these hardware designers expect things to work
  4516. * properly if the PCI write is posted for a long period
  4517. * of time? It is always necessary to have some method by
  4518. * which a register read back can occur to push the write
  4519. * out which does the reset.
  4520. *
  4521. * For most tg3 variants the trick below was working.
  4522. * Ho hum...
  4523. */
  4524. udelay(120);
  4525. /* Flush PCI posted writes. The normal MMIO registers
  4526. * are inaccessible at this time so this is the only
  4527. * way to make this reliably (actually, this is no longer
  4528. * the case, see above). I tried to use indirect
  4529. * register read/write but this upset some 5701 variants.
  4530. */
  4531. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4532. udelay(120);
  4533. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4534. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4535. int i;
  4536. u32 cfg_val;
  4537. /* Wait for link training to complete. */
  4538. for (i = 0; i < 5000; i++)
  4539. udelay(100);
  4540. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4541. pci_write_config_dword(tp->pdev, 0xc4,
  4542. cfg_val | (1 << 15));
  4543. }
  4544. /* Set PCIE max payload size and clear error status. */
  4545. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4546. }
  4547. tg3_restore_pci_state(tp);
  4548. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4549. val = 0;
  4550. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  4551. val = tr32(MEMARB_MODE);
  4552. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4553. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4554. tg3_stop_fw(tp);
  4555. tw32(0x5000, 0x400);
  4556. }
  4557. tw32(GRC_MODE, tp->grc_mode);
  4558. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4559. val = tr32(0xc4);
  4560. tw32(0xc4, val | (1 << 15));
  4561. }
  4562. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4563. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4564. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4565. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4566. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4567. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4568. }
  4569. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4570. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4571. tw32_f(MAC_MODE, tp->mac_mode);
  4572. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4573. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4574. tw32_f(MAC_MODE, tp->mac_mode);
  4575. } else
  4576. tw32_f(MAC_MODE, 0);
  4577. udelay(40);
  4578. err = tg3_poll_fw(tp);
  4579. if (err)
  4580. return err;
  4581. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4582. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4583. val = tr32(0x7c00);
  4584. tw32(0x7c00, val | (1 << 25));
  4585. }
  4586. /* Reprobe ASF enable state. */
  4587. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4588. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4589. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4590. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4591. u32 nic_cfg;
  4592. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4593. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4594. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4595. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4596. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4597. }
  4598. }
  4599. return 0;
  4600. }
  4601. /* tp->lock is held. */
  4602. static void tg3_stop_fw(struct tg3 *tp)
  4603. {
  4604. if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
  4605. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
  4606. u32 val;
  4607. int i;
  4608. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4609. val = tr32(GRC_RX_CPU_EVENT);
  4610. val |= (1 << 14);
  4611. tw32(GRC_RX_CPU_EVENT, val);
  4612. /* Wait for RX cpu to ACK the event. */
  4613. for (i = 0; i < 100; i++) {
  4614. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4615. break;
  4616. udelay(1);
  4617. }
  4618. }
  4619. }
  4620. /* tp->lock is held. */
  4621. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4622. {
  4623. int err;
  4624. tg3_stop_fw(tp);
  4625. tg3_write_sig_pre_reset(tp, kind);
  4626. tg3_abort_hw(tp, silent);
  4627. err = tg3_chip_reset(tp);
  4628. tg3_write_sig_legacy(tp, kind);
  4629. tg3_write_sig_post_reset(tp, kind);
  4630. if (err)
  4631. return err;
  4632. return 0;
  4633. }
  4634. #define TG3_FW_RELEASE_MAJOR 0x0
  4635. #define TG3_FW_RELASE_MINOR 0x0
  4636. #define TG3_FW_RELEASE_FIX 0x0
  4637. #define TG3_FW_START_ADDR 0x08000000
  4638. #define TG3_FW_TEXT_ADDR 0x08000000
  4639. #define TG3_FW_TEXT_LEN 0x9c0
  4640. #define TG3_FW_RODATA_ADDR 0x080009c0
  4641. #define TG3_FW_RODATA_LEN 0x60
  4642. #define TG3_FW_DATA_ADDR 0x08000a40
  4643. #define TG3_FW_DATA_LEN 0x20
  4644. #define TG3_FW_SBSS_ADDR 0x08000a60
  4645. #define TG3_FW_SBSS_LEN 0xc
  4646. #define TG3_FW_BSS_ADDR 0x08000a70
  4647. #define TG3_FW_BSS_LEN 0x10
  4648. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4649. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4650. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4651. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4652. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4653. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4654. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4655. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4656. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4657. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4658. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4659. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4660. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4661. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4662. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4663. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4664. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4665. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4666. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4667. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4668. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4669. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4670. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4671. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4674. 0, 0, 0, 0, 0, 0,
  4675. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4676. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4677. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4678. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4679. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4680. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4681. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4682. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4683. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4684. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4685. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4689. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4690. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4691. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4692. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4693. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4694. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4695. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4696. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4697. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4698. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4699. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4700. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4701. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4702. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4703. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4704. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4705. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4706. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4707. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4708. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4709. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4710. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4711. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4712. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4713. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4714. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4715. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4716. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4717. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4718. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4719. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4720. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4721. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4722. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4723. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4724. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4725. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4726. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4727. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4728. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4729. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4730. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4731. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4732. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4733. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4734. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4735. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4736. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4737. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4738. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4739. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4740. };
  4741. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4742. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4743. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4744. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4745. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4746. 0x00000000
  4747. };
  4748. #if 0 /* All zeros, don't eat up space with it. */
  4749. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4750. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4751. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4752. };
  4753. #endif
  4754. #define RX_CPU_SCRATCH_BASE 0x30000
  4755. #define RX_CPU_SCRATCH_SIZE 0x04000
  4756. #define TX_CPU_SCRATCH_BASE 0x34000
  4757. #define TX_CPU_SCRATCH_SIZE 0x04000
  4758. /* tp->lock is held. */
  4759. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4760. {
  4761. int i;
  4762. BUG_ON(offset == TX_CPU_BASE &&
  4763. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4764. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4765. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4766. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4767. return 0;
  4768. }
  4769. if (offset == RX_CPU_BASE) {
  4770. for (i = 0; i < 10000; i++) {
  4771. tw32(offset + CPU_STATE, 0xffffffff);
  4772. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4773. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4774. break;
  4775. }
  4776. tw32(offset + CPU_STATE, 0xffffffff);
  4777. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4778. udelay(10);
  4779. } else {
  4780. for (i = 0; i < 10000; i++) {
  4781. tw32(offset + CPU_STATE, 0xffffffff);
  4782. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4783. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4784. break;
  4785. }
  4786. }
  4787. if (i >= 10000) {
  4788. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4789. "and %s CPU\n",
  4790. tp->dev->name,
  4791. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4792. return -ENODEV;
  4793. }
  4794. /* Clear firmware's nvram arbitration. */
  4795. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4796. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4797. return 0;
  4798. }
  4799. struct fw_info {
  4800. unsigned int text_base;
  4801. unsigned int text_len;
  4802. const u32 *text_data;
  4803. unsigned int rodata_base;
  4804. unsigned int rodata_len;
  4805. const u32 *rodata_data;
  4806. unsigned int data_base;
  4807. unsigned int data_len;
  4808. const u32 *data_data;
  4809. };
  4810. /* tp->lock is held. */
  4811. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4812. int cpu_scratch_size, struct fw_info *info)
  4813. {
  4814. int err, lock_err, i;
  4815. void (*write_op)(struct tg3 *, u32, u32);
  4816. if (cpu_base == TX_CPU_BASE &&
  4817. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4818. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4819. "TX cpu firmware on %s which is 5705.\n",
  4820. tp->dev->name);
  4821. return -EINVAL;
  4822. }
  4823. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4824. write_op = tg3_write_mem;
  4825. else
  4826. write_op = tg3_write_indirect_reg32;
  4827. /* It is possible that bootcode is still loading at this point.
  4828. * Get the nvram lock first before halting the cpu.
  4829. */
  4830. lock_err = tg3_nvram_lock(tp);
  4831. err = tg3_halt_cpu(tp, cpu_base);
  4832. if (!lock_err)
  4833. tg3_nvram_unlock(tp);
  4834. if (err)
  4835. goto out;
  4836. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4837. write_op(tp, cpu_scratch_base + i, 0);
  4838. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4839. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4840. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4841. write_op(tp, (cpu_scratch_base +
  4842. (info->text_base & 0xffff) +
  4843. (i * sizeof(u32))),
  4844. (info->text_data ?
  4845. info->text_data[i] : 0));
  4846. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4847. write_op(tp, (cpu_scratch_base +
  4848. (info->rodata_base & 0xffff) +
  4849. (i * sizeof(u32))),
  4850. (info->rodata_data ?
  4851. info->rodata_data[i] : 0));
  4852. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4853. write_op(tp, (cpu_scratch_base +
  4854. (info->data_base & 0xffff) +
  4855. (i * sizeof(u32))),
  4856. (info->data_data ?
  4857. info->data_data[i] : 0));
  4858. err = 0;
  4859. out:
  4860. return err;
  4861. }
  4862. /* tp->lock is held. */
  4863. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4864. {
  4865. struct fw_info info;
  4866. int err, i;
  4867. info.text_base = TG3_FW_TEXT_ADDR;
  4868. info.text_len = TG3_FW_TEXT_LEN;
  4869. info.text_data = &tg3FwText[0];
  4870. info.rodata_base = TG3_FW_RODATA_ADDR;
  4871. info.rodata_len = TG3_FW_RODATA_LEN;
  4872. info.rodata_data = &tg3FwRodata[0];
  4873. info.data_base = TG3_FW_DATA_ADDR;
  4874. info.data_len = TG3_FW_DATA_LEN;
  4875. info.data_data = NULL;
  4876. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4877. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4878. &info);
  4879. if (err)
  4880. return err;
  4881. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4882. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4883. &info);
  4884. if (err)
  4885. return err;
  4886. /* Now startup only the RX cpu. */
  4887. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4888. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4889. for (i = 0; i < 5; i++) {
  4890. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4891. break;
  4892. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4893. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4894. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4895. udelay(1000);
  4896. }
  4897. if (i >= 5) {
  4898. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4899. "to set RX CPU PC, is %08x should be %08x\n",
  4900. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4901. TG3_FW_TEXT_ADDR);
  4902. return -ENODEV;
  4903. }
  4904. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4905. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4906. return 0;
  4907. }
  4908. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4909. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4910. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4911. #define TG3_TSO_FW_START_ADDR 0x08000000
  4912. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4913. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4914. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4915. #define TG3_TSO_FW_RODATA_LEN 0x60
  4916. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4917. #define TG3_TSO_FW_DATA_LEN 0x30
  4918. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4919. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4920. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4921. #define TG3_TSO_FW_BSS_LEN 0x894
  4922. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4923. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4924. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4925. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4926. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4927. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4928. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4929. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4930. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4931. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4932. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4933. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4934. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4935. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4936. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4937. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4938. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4939. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4940. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4941. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4942. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4943. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4944. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4945. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4946. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4947. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4948. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4949. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4950. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4951. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4952. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4953. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4954. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4955. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4956. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4957. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4958. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4959. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4960. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4961. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4962. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4963. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4964. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4965. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4966. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4967. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4968. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4969. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4970. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4971. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4972. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4973. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4974. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4975. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4976. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4977. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4978. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4979. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4980. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4981. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4982. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4983. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4984. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4985. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4986. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4987. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4988. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4989. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4990. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4991. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4992. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4993. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4994. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4995. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4996. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4997. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4998. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4999. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  5000. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  5001. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  5002. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  5003. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  5004. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  5005. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  5006. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  5007. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  5008. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  5009. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  5010. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  5011. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  5012. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  5013. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  5014. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  5015. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  5016. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  5017. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  5018. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  5019. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  5020. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  5021. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  5022. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  5023. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  5024. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  5025. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  5026. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  5027. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  5028. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  5029. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  5030. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  5031. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  5032. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  5033. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  5034. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  5035. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  5036. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  5037. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  5038. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  5039. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  5040. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  5041. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  5042. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  5043. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  5044. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  5045. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  5046. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  5047. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  5048. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  5049. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  5050. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  5051. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  5052. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  5053. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  5054. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  5055. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  5056. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  5057. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  5058. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  5059. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  5060. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  5061. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  5062. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  5063. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  5064. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  5065. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  5066. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  5067. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  5068. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  5069. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  5070. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  5071. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  5072. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  5073. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  5074. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  5075. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  5076. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  5077. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  5078. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  5079. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  5080. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  5081. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  5082. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  5083. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  5084. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  5085. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  5086. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  5087. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  5088. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  5089. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  5090. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  5091. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  5092. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  5093. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  5094. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  5095. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  5096. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  5097. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  5098. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  5099. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  5100. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  5101. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  5102. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  5103. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  5104. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  5105. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  5106. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  5107. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  5108. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  5109. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  5110. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  5111. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  5112. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  5113. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  5114. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  5115. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  5116. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  5117. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  5118. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  5119. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  5120. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  5121. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  5122. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  5123. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  5124. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  5125. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  5126. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  5127. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  5128. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  5129. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  5130. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  5131. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  5132. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  5133. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  5134. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  5135. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  5136. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  5137. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  5138. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  5139. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  5140. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  5141. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  5142. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  5143. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  5144. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  5145. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  5146. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  5147. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  5148. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  5149. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  5150. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  5151. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  5152. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  5153. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  5154. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  5155. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  5156. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  5157. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  5158. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  5159. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  5160. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  5161. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  5162. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  5163. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  5164. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  5165. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  5166. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  5167. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  5168. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  5169. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  5170. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  5171. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  5172. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  5173. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  5174. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  5175. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  5176. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  5177. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  5178. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  5179. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  5180. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  5181. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  5182. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  5183. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  5184. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  5185. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  5186. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  5187. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  5188. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  5189. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  5190. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  5191. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  5192. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  5193. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  5194. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  5195. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  5196. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  5197. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  5198. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  5199. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  5200. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  5201. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  5202. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  5203. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  5204. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  5205. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  5206. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  5207. };
  5208. static const u32 tg3TsoFwRodata[] = {
  5209. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5210. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  5211. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  5212. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  5213. 0x00000000,
  5214. };
  5215. static const u32 tg3TsoFwData[] = {
  5216. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  5217. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  5218. 0x00000000,
  5219. };
  5220. /* 5705 needs a special version of the TSO firmware. */
  5221. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  5222. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  5223. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  5224. #define TG3_TSO5_FW_START_ADDR 0x00010000
  5225. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  5226. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  5227. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  5228. #define TG3_TSO5_FW_RODATA_LEN 0x50
  5229. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  5230. #define TG3_TSO5_FW_DATA_LEN 0x20
  5231. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  5232. #define TG3_TSO5_FW_SBSS_LEN 0x28
  5233. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  5234. #define TG3_TSO5_FW_BSS_LEN 0x88
  5235. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  5236. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  5237. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  5238. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  5239. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  5240. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  5241. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  5242. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5243. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  5244. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  5245. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  5246. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  5247. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  5248. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  5249. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  5250. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  5251. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  5252. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  5253. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  5254. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  5255. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  5256. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  5257. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  5258. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  5259. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  5260. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  5261. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  5262. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  5263. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  5264. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  5265. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  5266. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  5267. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  5268. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  5269. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  5270. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  5271. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  5272. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  5273. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  5274. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  5275. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  5276. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  5277. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  5278. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  5279. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  5280. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  5281. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  5282. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  5283. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  5284. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  5285. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  5286. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  5287. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  5288. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  5289. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  5290. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  5291. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  5292. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  5293. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  5294. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  5295. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  5296. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  5297. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  5298. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  5299. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  5300. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  5301. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  5302. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  5303. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  5304. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  5305. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  5306. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  5307. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  5308. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  5309. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  5310. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  5311. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  5312. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  5313. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  5314. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  5315. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  5316. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  5317. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  5318. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  5319. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  5320. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  5321. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  5322. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  5323. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  5324. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  5325. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  5326. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  5327. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  5328. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  5329. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  5330. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  5331. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  5332. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  5333. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  5334. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  5335. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  5336. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  5337. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  5338. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  5339. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  5340. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  5341. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  5342. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5343. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5344. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  5345. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  5346. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  5347. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  5348. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  5349. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  5350. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  5351. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  5352. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  5353. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5354. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5355. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  5356. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  5357. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  5358. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  5359. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5360. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  5361. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  5362. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  5363. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  5364. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  5365. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  5366. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  5367. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  5368. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  5369. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  5370. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  5371. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  5372. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  5373. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  5374. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  5375. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  5376. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  5377. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  5378. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  5379. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  5380. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  5381. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  5382. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  5383. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  5384. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  5385. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  5386. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  5387. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  5388. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5389. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5390. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5391. 0x00000000, 0x00000000, 0x00000000,
  5392. };
  5393. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5394. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5395. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5396. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5397. 0x00000000, 0x00000000, 0x00000000,
  5398. };
  5399. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5400. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5401. 0x00000000, 0x00000000, 0x00000000,
  5402. };
  5403. /* tp->lock is held. */
  5404. static int tg3_load_tso_firmware(struct tg3 *tp)
  5405. {
  5406. struct fw_info info;
  5407. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5408. int err, i;
  5409. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5410. return 0;
  5411. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5412. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5413. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5414. info.text_data = &tg3Tso5FwText[0];
  5415. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5416. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5417. info.rodata_data = &tg3Tso5FwRodata[0];
  5418. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5419. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5420. info.data_data = &tg3Tso5FwData[0];
  5421. cpu_base = RX_CPU_BASE;
  5422. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5423. cpu_scratch_size = (info.text_len +
  5424. info.rodata_len +
  5425. info.data_len +
  5426. TG3_TSO5_FW_SBSS_LEN +
  5427. TG3_TSO5_FW_BSS_LEN);
  5428. } else {
  5429. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5430. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5431. info.text_data = &tg3TsoFwText[0];
  5432. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5433. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5434. info.rodata_data = &tg3TsoFwRodata[0];
  5435. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5436. info.data_len = TG3_TSO_FW_DATA_LEN;
  5437. info.data_data = &tg3TsoFwData[0];
  5438. cpu_base = TX_CPU_BASE;
  5439. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5440. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5441. }
  5442. err = tg3_load_firmware_cpu(tp, cpu_base,
  5443. cpu_scratch_base, cpu_scratch_size,
  5444. &info);
  5445. if (err)
  5446. return err;
  5447. /* Now startup the cpu. */
  5448. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5449. tw32_f(cpu_base + CPU_PC, info.text_base);
  5450. for (i = 0; i < 5; i++) {
  5451. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5452. break;
  5453. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5454. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5455. tw32_f(cpu_base + CPU_PC, info.text_base);
  5456. udelay(1000);
  5457. }
  5458. if (i >= 5) {
  5459. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5460. "to set CPU PC, is %08x should be %08x\n",
  5461. tp->dev->name, tr32(cpu_base + CPU_PC),
  5462. info.text_base);
  5463. return -ENODEV;
  5464. }
  5465. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5466. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5467. return 0;
  5468. }
  5469. /* tp->lock is held. */
  5470. static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
  5471. {
  5472. u32 addr_high, addr_low;
  5473. int i;
  5474. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5475. tp->dev->dev_addr[1]);
  5476. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5477. (tp->dev->dev_addr[3] << 16) |
  5478. (tp->dev->dev_addr[4] << 8) |
  5479. (tp->dev->dev_addr[5] << 0));
  5480. for (i = 0; i < 4; i++) {
  5481. if (i == 1 && skip_mac_1)
  5482. continue;
  5483. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5484. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5485. }
  5486. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5487. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5488. for (i = 0; i < 12; i++) {
  5489. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5490. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5491. }
  5492. }
  5493. addr_high = (tp->dev->dev_addr[0] +
  5494. tp->dev->dev_addr[1] +
  5495. tp->dev->dev_addr[2] +
  5496. tp->dev->dev_addr[3] +
  5497. tp->dev->dev_addr[4] +
  5498. tp->dev->dev_addr[5]) &
  5499. TX_BACKOFF_SEED_MASK;
  5500. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5501. }
  5502. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5503. {
  5504. struct tg3 *tp = netdev_priv(dev);
  5505. struct sockaddr *addr = p;
  5506. int err = 0, skip_mac_1 = 0;
  5507. if (!is_valid_ether_addr(addr->sa_data))
  5508. return -EINVAL;
  5509. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5510. if (!netif_running(dev))
  5511. return 0;
  5512. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5513. u32 addr0_high, addr0_low, addr1_high, addr1_low;
  5514. addr0_high = tr32(MAC_ADDR_0_HIGH);
  5515. addr0_low = tr32(MAC_ADDR_0_LOW);
  5516. addr1_high = tr32(MAC_ADDR_1_HIGH);
  5517. addr1_low = tr32(MAC_ADDR_1_LOW);
  5518. /* Skip MAC addr 1 if ASF is using it. */
  5519. if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
  5520. !(addr1_high == 0 && addr1_low == 0))
  5521. skip_mac_1 = 1;
  5522. }
  5523. spin_lock_bh(&tp->lock);
  5524. __tg3_set_mac_addr(tp, skip_mac_1);
  5525. spin_unlock_bh(&tp->lock);
  5526. return err;
  5527. }
  5528. /* tp->lock is held. */
  5529. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5530. dma_addr_t mapping, u32 maxlen_flags,
  5531. u32 nic_addr)
  5532. {
  5533. tg3_write_mem(tp,
  5534. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5535. ((u64) mapping >> 32));
  5536. tg3_write_mem(tp,
  5537. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5538. ((u64) mapping & 0xffffffff));
  5539. tg3_write_mem(tp,
  5540. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5541. maxlen_flags);
  5542. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5543. tg3_write_mem(tp,
  5544. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5545. nic_addr);
  5546. }
  5547. static void __tg3_set_rx_mode(struct net_device *);
  5548. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5549. {
  5550. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5551. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5552. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5553. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5554. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5555. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5556. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5557. }
  5558. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5559. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5560. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5561. u32 val = ec->stats_block_coalesce_usecs;
  5562. if (!netif_carrier_ok(tp->dev))
  5563. val = 0;
  5564. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5565. }
  5566. }
  5567. /* tp->lock is held. */
  5568. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5569. {
  5570. u32 val, rdmac_mode;
  5571. int i, err, limit;
  5572. tg3_disable_ints(tp);
  5573. tg3_stop_fw(tp);
  5574. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5575. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5576. tg3_abort_hw(tp, 1);
  5577. }
  5578. if (reset_phy)
  5579. tg3_phy_reset(tp);
  5580. err = tg3_chip_reset(tp);
  5581. if (err)
  5582. return err;
  5583. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5584. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  5585. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1) {
  5586. val = tr32(TG3_CPMU_CTRL);
  5587. val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE);
  5588. tw32(TG3_CPMU_CTRL, val);
  5589. val = tr32(TG3_CPMU_LSPD_10MB_CLK);
  5590. val &= ~CPMU_LSPD_10MB_MACCLK_MASK;
  5591. val |= CPMU_LSPD_10MB_MACCLK_6_25;
  5592. tw32(TG3_CPMU_LSPD_10MB_CLK, val);
  5593. val = tr32(TG3_CPMU_LNK_AWARE_PWRMD);
  5594. val &= ~CPMU_LNK_AWARE_MACCLK_MASK;
  5595. val |= CPMU_LNK_AWARE_MACCLK_6_25;
  5596. tw32(TG3_CPMU_LNK_AWARE_PWRMD, val);
  5597. val = tr32(TG3_CPMU_HST_ACC);
  5598. val &= ~CPMU_HST_ACC_MACCLK_MASK;
  5599. val |= CPMU_HST_ACC_MACCLK_6_25;
  5600. tw32(TG3_CPMU_HST_ACC, val);
  5601. }
  5602. /* This works around an issue with Athlon chipsets on
  5603. * B3 tigon3 silicon. This bit has no effect on any
  5604. * other revision. But do not set this on PCI Express
  5605. * chips and don't even touch the clocks if the CPMU is present.
  5606. */
  5607. if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) {
  5608. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5609. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5610. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5611. }
  5612. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5613. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5614. val = tr32(TG3PCI_PCISTATE);
  5615. val |= PCISTATE_RETRY_SAME_DMA;
  5616. tw32(TG3PCI_PCISTATE, val);
  5617. }
  5618. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  5619. /* Allow reads and writes to the
  5620. * APE register and memory space.
  5621. */
  5622. val = tr32(TG3PCI_PCISTATE);
  5623. val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  5624. PCISTATE_ALLOW_APE_SHMEM_WR;
  5625. tw32(TG3PCI_PCISTATE, val);
  5626. }
  5627. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5628. /* Enable some hw fixes. */
  5629. val = tr32(TG3PCI_MSI_DATA);
  5630. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5631. tw32(TG3PCI_MSI_DATA, val);
  5632. }
  5633. /* Descriptor ring init may make accesses to the
  5634. * NIC SRAM area to setup the TX descriptors, so we
  5635. * can only do this after the hardware has been
  5636. * successfully reset.
  5637. */
  5638. err = tg3_init_rings(tp);
  5639. if (err)
  5640. return err;
  5641. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 &&
  5642. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) {
  5643. /* This value is determined during the probe time DMA
  5644. * engine test, tg3_test_dma.
  5645. */
  5646. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5647. }
  5648. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5649. GRC_MODE_4X_NIC_SEND_RINGS |
  5650. GRC_MODE_NO_TX_PHDR_CSUM |
  5651. GRC_MODE_NO_RX_PHDR_CSUM);
  5652. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5653. /* Pseudo-header checksum is done by hardware logic and not
  5654. * the offload processers, so make the chip do the pseudo-
  5655. * header checksums on receive. For transmit it is more
  5656. * convenient to do the pseudo-header checksum in software
  5657. * as Linux does that on transmit for us in all cases.
  5658. */
  5659. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5660. tw32(GRC_MODE,
  5661. tp->grc_mode |
  5662. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5663. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5664. val = tr32(GRC_MISC_CFG);
  5665. val &= ~0xff;
  5666. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5667. tw32(GRC_MISC_CFG, val);
  5668. /* Initialize MBUF/DESC pool. */
  5669. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5670. /* Do nothing. */
  5671. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5672. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5673. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5674. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5675. else
  5676. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5677. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5678. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5679. }
  5680. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5681. int fw_len;
  5682. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5683. TG3_TSO5_FW_RODATA_LEN +
  5684. TG3_TSO5_FW_DATA_LEN +
  5685. TG3_TSO5_FW_SBSS_LEN +
  5686. TG3_TSO5_FW_BSS_LEN);
  5687. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5688. tw32(BUFMGR_MB_POOL_ADDR,
  5689. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5690. tw32(BUFMGR_MB_POOL_SIZE,
  5691. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5692. }
  5693. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5694. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5695. tp->bufmgr_config.mbuf_read_dma_low_water);
  5696. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5697. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5698. tw32(BUFMGR_MB_HIGH_WATER,
  5699. tp->bufmgr_config.mbuf_high_water);
  5700. } else {
  5701. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5702. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5703. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5704. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5705. tw32(BUFMGR_MB_HIGH_WATER,
  5706. tp->bufmgr_config.mbuf_high_water_jumbo);
  5707. }
  5708. tw32(BUFMGR_DMA_LOW_WATER,
  5709. tp->bufmgr_config.dma_low_water);
  5710. tw32(BUFMGR_DMA_HIGH_WATER,
  5711. tp->bufmgr_config.dma_high_water);
  5712. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5713. for (i = 0; i < 2000; i++) {
  5714. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5715. break;
  5716. udelay(10);
  5717. }
  5718. if (i >= 2000) {
  5719. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5720. tp->dev->name);
  5721. return -ENODEV;
  5722. }
  5723. /* Setup replenish threshold. */
  5724. val = tp->rx_pending / 8;
  5725. if (val == 0)
  5726. val = 1;
  5727. else if (val > tp->rx_std_max_post)
  5728. val = tp->rx_std_max_post;
  5729. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5730. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5731. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5732. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5733. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5734. }
  5735. tw32(RCVBDI_STD_THRESH, val);
  5736. /* Initialize TG3_BDINFO's at:
  5737. * RCVDBDI_STD_BD: standard eth size rx ring
  5738. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5739. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5740. *
  5741. * like so:
  5742. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5743. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5744. * ring attribute flags
  5745. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5746. *
  5747. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5748. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5749. *
  5750. * The size of each ring is fixed in the firmware, but the location is
  5751. * configurable.
  5752. */
  5753. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5754. ((u64) tp->rx_std_mapping >> 32));
  5755. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5756. ((u64) tp->rx_std_mapping & 0xffffffff));
  5757. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5758. NIC_SRAM_RX_BUFFER_DESC);
  5759. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5760. * configs on 5705.
  5761. */
  5762. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5763. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5764. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5765. } else {
  5766. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5767. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5768. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5769. BDINFO_FLAGS_DISABLED);
  5770. /* Setup replenish threshold. */
  5771. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5772. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5773. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5774. ((u64) tp->rx_jumbo_mapping >> 32));
  5775. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5776. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5777. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5778. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5779. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5780. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5781. } else {
  5782. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5783. BDINFO_FLAGS_DISABLED);
  5784. }
  5785. }
  5786. /* There is only one send ring on 5705/5750, no need to explicitly
  5787. * disable the others.
  5788. */
  5789. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5790. /* Clear out send RCB ring in SRAM. */
  5791. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5792. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5793. BDINFO_FLAGS_DISABLED);
  5794. }
  5795. tp->tx_prod = 0;
  5796. tp->tx_cons = 0;
  5797. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5798. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5799. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5800. tp->tx_desc_mapping,
  5801. (TG3_TX_RING_SIZE <<
  5802. BDINFO_FLAGS_MAXLEN_SHIFT),
  5803. NIC_SRAM_TX_BUFFER_DESC);
  5804. /* There is only one receive return ring on 5705/5750, no need
  5805. * to explicitly disable the others.
  5806. */
  5807. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5808. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5809. i += TG3_BDINFO_SIZE) {
  5810. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5811. BDINFO_FLAGS_DISABLED);
  5812. }
  5813. }
  5814. tp->rx_rcb_ptr = 0;
  5815. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5816. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5817. tp->rx_rcb_mapping,
  5818. (TG3_RX_RCB_RING_SIZE(tp) <<
  5819. BDINFO_FLAGS_MAXLEN_SHIFT),
  5820. 0);
  5821. tp->rx_std_ptr = tp->rx_pending;
  5822. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5823. tp->rx_std_ptr);
  5824. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5825. tp->rx_jumbo_pending : 0;
  5826. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5827. tp->rx_jumbo_ptr);
  5828. /* Initialize MAC address and backoff seed. */
  5829. __tg3_set_mac_addr(tp, 0);
  5830. /* MTU + ethernet header + FCS + optional VLAN tag */
  5831. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5832. /* The slot time is changed by tg3_setup_phy if we
  5833. * run at gigabit with half duplex.
  5834. */
  5835. tw32(MAC_TX_LENGTHS,
  5836. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5837. (6 << TX_LENGTHS_IPG_SHIFT) |
  5838. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5839. /* Receive rules. */
  5840. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5841. tw32(RCVLPC_CONFIG, 0x0181);
  5842. /* Calculate RDMAC_MODE setting early, we need it to determine
  5843. * the RCVLPC_STATE_ENABLE mask.
  5844. */
  5845. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5846. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5847. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5848. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5849. RDMAC_MODE_LNGREAD_ENAB);
  5850. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)
  5851. rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB |
  5852. RDMAC_MODE_MBUF_RBD_CRPT_ENAB |
  5853. RDMAC_MODE_MBUF_SBD_CRPT_ENAB;
  5854. /* If statement applies to 5705 and 5750 PCI devices only */
  5855. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5856. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5857. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5858. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5859. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5860. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5861. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5862. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5863. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5864. }
  5865. }
  5866. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5867. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5868. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5869. rdmac_mode |= (1 << 27);
  5870. /* Receive/send statistics. */
  5871. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5872. val = tr32(RCVLPC_STATS_ENABLE);
  5873. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5874. tw32(RCVLPC_STATS_ENABLE, val);
  5875. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5876. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5877. val = tr32(RCVLPC_STATS_ENABLE);
  5878. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5879. tw32(RCVLPC_STATS_ENABLE, val);
  5880. } else {
  5881. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5882. }
  5883. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5884. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5885. tw32(SNDDATAI_STATSCTRL,
  5886. (SNDDATAI_SCTRL_ENABLE |
  5887. SNDDATAI_SCTRL_FASTUPD));
  5888. /* Setup host coalescing engine. */
  5889. tw32(HOSTCC_MODE, 0);
  5890. for (i = 0; i < 2000; i++) {
  5891. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5892. break;
  5893. udelay(10);
  5894. }
  5895. __tg3_set_coalesce(tp, &tp->coal);
  5896. /* set status block DMA address */
  5897. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5898. ((u64) tp->status_mapping >> 32));
  5899. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5900. ((u64) tp->status_mapping & 0xffffffff));
  5901. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5902. /* Status/statistics block address. See tg3_timer,
  5903. * the tg3_periodic_fetch_stats call there, and
  5904. * tg3_get_stats to see how this works for 5705/5750 chips.
  5905. */
  5906. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5907. ((u64) tp->stats_mapping >> 32));
  5908. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5909. ((u64) tp->stats_mapping & 0xffffffff));
  5910. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5911. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5912. }
  5913. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5914. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5915. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5916. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5917. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5918. /* Clear statistics/status block in chip, and status block in ram. */
  5919. for (i = NIC_SRAM_STATS_BLK;
  5920. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5921. i += sizeof(u32)) {
  5922. tg3_write_mem(tp, i, 0);
  5923. udelay(40);
  5924. }
  5925. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5926. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5927. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5928. /* reset to prevent losing 1st rx packet intermittently */
  5929. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5930. udelay(10);
  5931. }
  5932. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5933. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5934. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5935. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5936. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
  5937. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  5938. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5939. udelay(40);
  5940. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5941. * If TG3_FLG2_IS_NIC is zero, we should read the
  5942. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5943. * whether used as inputs or outputs, are set by boot code after
  5944. * reset.
  5945. */
  5946. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5947. u32 gpio_mask;
  5948. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5949. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5950. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5951. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5952. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5953. GRC_LCLCTRL_GPIO_OUTPUT3;
  5954. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5955. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5956. tp->grc_local_ctrl &= ~gpio_mask;
  5957. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5958. /* GPIO1 must be driven high for eeprom write protect */
  5959. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5960. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5961. GRC_LCLCTRL_GPIO_OUTPUT1);
  5962. }
  5963. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5964. udelay(100);
  5965. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5966. tp->last_tag = 0;
  5967. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5968. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5969. udelay(40);
  5970. }
  5971. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5972. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5973. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5974. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5975. WDMAC_MODE_LNGREAD_ENAB);
  5976. /* If statement applies to 5705 and 5750 PCI devices only */
  5977. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5978. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5979. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5980. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5981. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5982. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5983. /* nothing */
  5984. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5985. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5986. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5987. val |= WDMAC_MODE_RX_ACCEL;
  5988. }
  5989. }
  5990. /* Enable host coalescing bug fix */
  5991. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5992. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) ||
  5993. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784) ||
  5994. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761))
  5995. val |= (1 << 29);
  5996. tw32_f(WDMAC_MODE, val);
  5997. udelay(40);
  5998. if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  5999. u16 pcix_cmd;
  6000. pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  6001. &pcix_cmd);
  6002. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  6003. pcix_cmd &= ~PCI_X_CMD_MAX_READ;
  6004. pcix_cmd |= PCI_X_CMD_READ_2K;
  6005. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  6006. pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ);
  6007. pcix_cmd |= PCI_X_CMD_READ_2K;
  6008. }
  6009. pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  6010. pcix_cmd);
  6011. }
  6012. tw32_f(RDMAC_MODE, rdmac_mode);
  6013. udelay(40);
  6014. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  6015. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  6016. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  6017. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  6018. tw32(SNDDATAC_MODE,
  6019. SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY);
  6020. else
  6021. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  6022. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  6023. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  6024. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  6025. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  6026. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  6027. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  6028. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  6029. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  6030. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  6031. err = tg3_load_5701_a0_firmware_fix(tp);
  6032. if (err)
  6033. return err;
  6034. }
  6035. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  6036. err = tg3_load_tso_firmware(tp);
  6037. if (err)
  6038. return err;
  6039. }
  6040. tp->tx_mode = TX_MODE_ENABLE;
  6041. tw32_f(MAC_TX_MODE, tp->tx_mode);
  6042. udelay(100);
  6043. tp->rx_mode = RX_MODE_ENABLE;
  6044. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  6045. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  6046. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  6047. tw32_f(MAC_RX_MODE, tp->rx_mode);
  6048. udelay(10);
  6049. if (tp->link_config.phy_is_low_power) {
  6050. tp->link_config.phy_is_low_power = 0;
  6051. tp->link_config.speed = tp->link_config.orig_speed;
  6052. tp->link_config.duplex = tp->link_config.orig_duplex;
  6053. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  6054. }
  6055. tp->mi_mode = MAC_MI_MODE_BASE;
  6056. tw32_f(MAC_MI_MODE, tp->mi_mode);
  6057. udelay(80);
  6058. tw32(MAC_LED_CTRL, tp->led_ctrl);
  6059. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  6060. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  6061. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  6062. udelay(10);
  6063. }
  6064. tw32_f(MAC_RX_MODE, tp->rx_mode);
  6065. udelay(10);
  6066. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  6067. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  6068. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  6069. /* Set drive transmission level to 1.2V */
  6070. /* only if the signal pre-emphasis bit is not set */
  6071. val = tr32(MAC_SERDES_CFG);
  6072. val &= 0xfffff000;
  6073. val |= 0x880;
  6074. tw32(MAC_SERDES_CFG, val);
  6075. }
  6076. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  6077. tw32(MAC_SERDES_CFG, 0x616000);
  6078. }
  6079. /* Prevent chip from dropping frames when flow control
  6080. * is enabled.
  6081. */
  6082. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  6083. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  6084. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  6085. /* Use hardware link auto-negotiation */
  6086. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  6087. }
  6088. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  6089. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  6090. u32 tmp;
  6091. tmp = tr32(SERDES_RX_CTRL);
  6092. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  6093. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  6094. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  6095. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  6096. }
  6097. err = tg3_setup_phy(tp, 0);
  6098. if (err)
  6099. return err;
  6100. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6101. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  6102. u32 tmp;
  6103. /* Clear CRC stats. */
  6104. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  6105. tg3_writephy(tp, MII_TG3_TEST1,
  6106. tmp | MII_TG3_TEST1_CRC_EN);
  6107. tg3_readphy(tp, 0x14, &tmp);
  6108. }
  6109. }
  6110. __tg3_set_rx_mode(tp->dev);
  6111. /* Initialize receive rules. */
  6112. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  6113. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  6114. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  6115. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  6116. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  6117. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  6118. limit = 8;
  6119. else
  6120. limit = 16;
  6121. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  6122. limit -= 4;
  6123. switch (limit) {
  6124. case 16:
  6125. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  6126. case 15:
  6127. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  6128. case 14:
  6129. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  6130. case 13:
  6131. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  6132. case 12:
  6133. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  6134. case 11:
  6135. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  6136. case 10:
  6137. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  6138. case 9:
  6139. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  6140. case 8:
  6141. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  6142. case 7:
  6143. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  6144. case 6:
  6145. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  6146. case 5:
  6147. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  6148. case 4:
  6149. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  6150. case 3:
  6151. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  6152. case 2:
  6153. case 1:
  6154. default:
  6155. break;
  6156. };
  6157. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
  6158. /* Write our heartbeat update interval to APE. */
  6159. tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS,
  6160. APE_HOST_HEARTBEAT_INT_DISABLE);
  6161. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  6162. return 0;
  6163. }
  6164. /* Called at device open time to get the chip ready for
  6165. * packet processing. Invoked with tp->lock held.
  6166. */
  6167. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  6168. {
  6169. int err;
  6170. /* Force the chip into D0. */
  6171. err = tg3_set_power_state(tp, PCI_D0);
  6172. if (err)
  6173. goto out;
  6174. tg3_switch_clocks(tp);
  6175. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  6176. err = tg3_reset_hw(tp, reset_phy);
  6177. out:
  6178. return err;
  6179. }
  6180. #define TG3_STAT_ADD32(PSTAT, REG) \
  6181. do { u32 __val = tr32(REG); \
  6182. (PSTAT)->low += __val; \
  6183. if ((PSTAT)->low < __val) \
  6184. (PSTAT)->high += 1; \
  6185. } while (0)
  6186. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  6187. {
  6188. struct tg3_hw_stats *sp = tp->hw_stats;
  6189. if (!netif_carrier_ok(tp->dev))
  6190. return;
  6191. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  6192. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  6193. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  6194. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  6195. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  6196. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  6197. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  6198. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  6199. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  6200. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  6201. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  6202. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  6203. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  6204. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  6205. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  6206. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  6207. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  6208. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  6209. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  6210. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  6211. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  6212. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  6213. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  6214. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  6215. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  6216. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  6217. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  6218. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  6219. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  6220. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  6221. }
  6222. static void tg3_timer(unsigned long __opaque)
  6223. {
  6224. struct tg3 *tp = (struct tg3 *) __opaque;
  6225. if (tp->irq_sync)
  6226. goto restart_timer;
  6227. spin_lock(&tp->lock);
  6228. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6229. /* All of this garbage is because when using non-tagged
  6230. * IRQ status the mailbox/status_block protocol the chip
  6231. * uses with the cpu is race prone.
  6232. */
  6233. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  6234. tw32(GRC_LOCAL_CTRL,
  6235. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  6236. } else {
  6237. tw32(HOSTCC_MODE, tp->coalesce_mode |
  6238. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  6239. }
  6240. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  6241. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  6242. spin_unlock(&tp->lock);
  6243. schedule_work(&tp->reset_task);
  6244. return;
  6245. }
  6246. }
  6247. /* This part only runs once per second. */
  6248. if (!--tp->timer_counter) {
  6249. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  6250. tg3_periodic_fetch_stats(tp);
  6251. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  6252. u32 mac_stat;
  6253. int phy_event;
  6254. mac_stat = tr32(MAC_STATUS);
  6255. phy_event = 0;
  6256. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  6257. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  6258. phy_event = 1;
  6259. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  6260. phy_event = 1;
  6261. if (phy_event)
  6262. tg3_setup_phy(tp, 0);
  6263. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  6264. u32 mac_stat = tr32(MAC_STATUS);
  6265. int need_setup = 0;
  6266. if (netif_carrier_ok(tp->dev) &&
  6267. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  6268. need_setup = 1;
  6269. }
  6270. if (! netif_carrier_ok(tp->dev) &&
  6271. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  6272. MAC_STATUS_SIGNAL_DET))) {
  6273. need_setup = 1;
  6274. }
  6275. if (need_setup) {
  6276. if (!tp->serdes_counter) {
  6277. tw32_f(MAC_MODE,
  6278. (tp->mac_mode &
  6279. ~MAC_MODE_PORT_MODE_MASK));
  6280. udelay(40);
  6281. tw32_f(MAC_MODE, tp->mac_mode);
  6282. udelay(40);
  6283. }
  6284. tg3_setup_phy(tp, 0);
  6285. }
  6286. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  6287. tg3_serdes_parallel_detect(tp);
  6288. tp->timer_counter = tp->timer_multiplier;
  6289. }
  6290. /* Heartbeat is only sent once every 2 seconds.
  6291. *
  6292. * The heartbeat is to tell the ASF firmware that the host
  6293. * driver is still alive. In the event that the OS crashes,
  6294. * ASF needs to reset the hardware to free up the FIFO space
  6295. * that may be filled with rx packets destined for the host.
  6296. * If the FIFO is full, ASF will no longer function properly.
  6297. *
  6298. * Unintended resets have been reported on real time kernels
  6299. * where the timer doesn't run on time. Netpoll will also have
  6300. * same problem.
  6301. *
  6302. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  6303. * to check the ring condition when the heartbeat is expiring
  6304. * before doing the reset. This will prevent most unintended
  6305. * resets.
  6306. */
  6307. if (!--tp->asf_counter) {
  6308. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  6309. u32 val;
  6310. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  6311. FWCMD_NICDRV_ALIVE3);
  6312. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  6313. /* 5 seconds timeout */
  6314. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  6315. val = tr32(GRC_RX_CPU_EVENT);
  6316. val |= (1 << 14);
  6317. tw32(GRC_RX_CPU_EVENT, val);
  6318. }
  6319. tp->asf_counter = tp->asf_multiplier;
  6320. }
  6321. spin_unlock(&tp->lock);
  6322. restart_timer:
  6323. tp->timer.expires = jiffies + tp->timer_offset;
  6324. add_timer(&tp->timer);
  6325. }
  6326. static int tg3_request_irq(struct tg3 *tp)
  6327. {
  6328. irq_handler_t fn;
  6329. unsigned long flags;
  6330. struct net_device *dev = tp->dev;
  6331. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6332. fn = tg3_msi;
  6333. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  6334. fn = tg3_msi_1shot;
  6335. flags = IRQF_SAMPLE_RANDOM;
  6336. } else {
  6337. fn = tg3_interrupt;
  6338. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6339. fn = tg3_interrupt_tagged;
  6340. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  6341. }
  6342. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  6343. }
  6344. static int tg3_test_interrupt(struct tg3 *tp)
  6345. {
  6346. struct net_device *dev = tp->dev;
  6347. int err, i, intr_ok = 0;
  6348. if (!netif_running(dev))
  6349. return -ENODEV;
  6350. tg3_disable_ints(tp);
  6351. free_irq(tp->pdev->irq, dev);
  6352. err = request_irq(tp->pdev->irq, tg3_test_isr,
  6353. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  6354. if (err)
  6355. return err;
  6356. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  6357. tg3_enable_ints(tp);
  6358. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  6359. HOSTCC_MODE_NOW);
  6360. for (i = 0; i < 5; i++) {
  6361. u32 int_mbox, misc_host_ctrl;
  6362. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  6363. TG3_64BIT_REG_LOW);
  6364. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  6365. if ((int_mbox != 0) ||
  6366. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  6367. intr_ok = 1;
  6368. break;
  6369. }
  6370. msleep(10);
  6371. }
  6372. tg3_disable_ints(tp);
  6373. free_irq(tp->pdev->irq, dev);
  6374. err = tg3_request_irq(tp);
  6375. if (err)
  6376. return err;
  6377. if (intr_ok)
  6378. return 0;
  6379. return -EIO;
  6380. }
  6381. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  6382. * successfully restored
  6383. */
  6384. static int tg3_test_msi(struct tg3 *tp)
  6385. {
  6386. struct net_device *dev = tp->dev;
  6387. int err;
  6388. u16 pci_cmd;
  6389. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  6390. return 0;
  6391. /* Turn off SERR reporting in case MSI terminates with Master
  6392. * Abort.
  6393. */
  6394. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  6395. pci_write_config_word(tp->pdev, PCI_COMMAND,
  6396. pci_cmd & ~PCI_COMMAND_SERR);
  6397. err = tg3_test_interrupt(tp);
  6398. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  6399. if (!err)
  6400. return 0;
  6401. /* other failures */
  6402. if (err != -EIO)
  6403. return err;
  6404. /* MSI test failed, go back to INTx mode */
  6405. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  6406. "switching to INTx mode. Please report this failure to "
  6407. "the PCI maintainer and include system chipset information.\n",
  6408. tp->dev->name);
  6409. free_irq(tp->pdev->irq, dev);
  6410. pci_disable_msi(tp->pdev);
  6411. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6412. err = tg3_request_irq(tp);
  6413. if (err)
  6414. return err;
  6415. /* Need to reset the chip because the MSI cycle may have terminated
  6416. * with Master Abort.
  6417. */
  6418. tg3_full_lock(tp, 1);
  6419. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6420. err = tg3_init_hw(tp, 1);
  6421. tg3_full_unlock(tp);
  6422. if (err)
  6423. free_irq(tp->pdev->irq, dev);
  6424. return err;
  6425. }
  6426. static int tg3_open(struct net_device *dev)
  6427. {
  6428. struct tg3 *tp = netdev_priv(dev);
  6429. int err;
  6430. netif_carrier_off(tp->dev);
  6431. tg3_full_lock(tp, 0);
  6432. err = tg3_set_power_state(tp, PCI_D0);
  6433. if (err) {
  6434. tg3_full_unlock(tp);
  6435. return err;
  6436. }
  6437. tg3_disable_ints(tp);
  6438. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6439. tg3_full_unlock(tp);
  6440. /* The placement of this call is tied
  6441. * to the setup and use of Host TX descriptors.
  6442. */
  6443. err = tg3_alloc_consistent(tp);
  6444. if (err)
  6445. return err;
  6446. if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) {
  6447. /* All MSI supporting chips should support tagged
  6448. * status. Assert that this is the case.
  6449. */
  6450. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6451. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6452. "Not using MSI.\n", tp->dev->name);
  6453. } else if (pci_enable_msi(tp->pdev) == 0) {
  6454. u32 msi_mode;
  6455. msi_mode = tr32(MSGINT_MODE);
  6456. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6457. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6458. }
  6459. }
  6460. err = tg3_request_irq(tp);
  6461. if (err) {
  6462. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6463. pci_disable_msi(tp->pdev);
  6464. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6465. }
  6466. tg3_free_consistent(tp);
  6467. return err;
  6468. }
  6469. napi_enable(&tp->napi);
  6470. tg3_full_lock(tp, 0);
  6471. err = tg3_init_hw(tp, 1);
  6472. if (err) {
  6473. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6474. tg3_free_rings(tp);
  6475. } else {
  6476. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6477. tp->timer_offset = HZ;
  6478. else
  6479. tp->timer_offset = HZ / 10;
  6480. BUG_ON(tp->timer_offset > HZ);
  6481. tp->timer_counter = tp->timer_multiplier =
  6482. (HZ / tp->timer_offset);
  6483. tp->asf_counter = tp->asf_multiplier =
  6484. ((HZ / tp->timer_offset) * 2);
  6485. init_timer(&tp->timer);
  6486. tp->timer.expires = jiffies + tp->timer_offset;
  6487. tp->timer.data = (unsigned long) tp;
  6488. tp->timer.function = tg3_timer;
  6489. }
  6490. tg3_full_unlock(tp);
  6491. if (err) {
  6492. napi_disable(&tp->napi);
  6493. free_irq(tp->pdev->irq, dev);
  6494. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6495. pci_disable_msi(tp->pdev);
  6496. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6497. }
  6498. tg3_free_consistent(tp);
  6499. return err;
  6500. }
  6501. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6502. err = tg3_test_msi(tp);
  6503. if (err) {
  6504. tg3_full_lock(tp, 0);
  6505. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6506. pci_disable_msi(tp->pdev);
  6507. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6508. }
  6509. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6510. tg3_free_rings(tp);
  6511. tg3_free_consistent(tp);
  6512. tg3_full_unlock(tp);
  6513. napi_disable(&tp->napi);
  6514. return err;
  6515. }
  6516. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6517. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6518. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6519. tw32(PCIE_TRANSACTION_CFG,
  6520. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6521. }
  6522. }
  6523. }
  6524. tg3_full_lock(tp, 0);
  6525. add_timer(&tp->timer);
  6526. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6527. tg3_enable_ints(tp);
  6528. tg3_full_unlock(tp);
  6529. netif_start_queue(dev);
  6530. return 0;
  6531. }
  6532. #if 0
  6533. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6534. {
  6535. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6536. u16 val16;
  6537. int i;
  6538. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6539. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6540. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6541. val16, val32);
  6542. /* MAC block */
  6543. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6544. tr32(MAC_MODE), tr32(MAC_STATUS));
  6545. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6546. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6547. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6548. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6549. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6550. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6551. /* Send data initiator control block */
  6552. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6553. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6554. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6555. tr32(SNDDATAI_STATSCTRL));
  6556. /* Send data completion control block */
  6557. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6558. /* Send BD ring selector block */
  6559. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6560. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6561. /* Send BD initiator control block */
  6562. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6563. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6564. /* Send BD completion control block */
  6565. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6566. /* Receive list placement control block */
  6567. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6568. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6569. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6570. tr32(RCVLPC_STATSCTRL));
  6571. /* Receive data and receive BD initiator control block */
  6572. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6573. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6574. /* Receive data completion control block */
  6575. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6576. tr32(RCVDCC_MODE));
  6577. /* Receive BD initiator control block */
  6578. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6579. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6580. /* Receive BD completion control block */
  6581. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6582. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6583. /* Receive list selector control block */
  6584. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6585. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6586. /* Mbuf cluster free block */
  6587. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6588. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6589. /* Host coalescing control block */
  6590. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6591. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6592. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6593. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6594. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6595. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6596. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6597. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6598. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6599. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6600. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6601. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6602. /* Memory arbiter control block */
  6603. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6604. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6605. /* Buffer manager control block */
  6606. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6607. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6608. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6609. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6610. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6611. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6612. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6613. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6614. /* Read DMA control block */
  6615. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6616. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6617. /* Write DMA control block */
  6618. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6619. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6620. /* DMA completion block */
  6621. printk("DEBUG: DMAC_MODE[%08x]\n",
  6622. tr32(DMAC_MODE));
  6623. /* GRC block */
  6624. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6625. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6626. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6627. tr32(GRC_LOCAL_CTRL));
  6628. /* TG3_BDINFOs */
  6629. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6630. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6631. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6632. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6633. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6634. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6635. tr32(RCVDBDI_STD_BD + 0x0),
  6636. tr32(RCVDBDI_STD_BD + 0x4),
  6637. tr32(RCVDBDI_STD_BD + 0x8),
  6638. tr32(RCVDBDI_STD_BD + 0xc));
  6639. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6640. tr32(RCVDBDI_MINI_BD + 0x0),
  6641. tr32(RCVDBDI_MINI_BD + 0x4),
  6642. tr32(RCVDBDI_MINI_BD + 0x8),
  6643. tr32(RCVDBDI_MINI_BD + 0xc));
  6644. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6645. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6646. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6647. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6648. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6649. val32, val32_2, val32_3, val32_4);
  6650. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6651. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6652. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6653. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6654. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6655. val32, val32_2, val32_3, val32_4);
  6656. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6657. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6658. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6659. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6660. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6661. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6662. val32, val32_2, val32_3, val32_4, val32_5);
  6663. /* SW status block */
  6664. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6665. tp->hw_status->status,
  6666. tp->hw_status->status_tag,
  6667. tp->hw_status->rx_jumbo_consumer,
  6668. tp->hw_status->rx_consumer,
  6669. tp->hw_status->rx_mini_consumer,
  6670. tp->hw_status->idx[0].rx_producer,
  6671. tp->hw_status->idx[0].tx_consumer);
  6672. /* SW statistics block */
  6673. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6674. ((u32 *)tp->hw_stats)[0],
  6675. ((u32 *)tp->hw_stats)[1],
  6676. ((u32 *)tp->hw_stats)[2],
  6677. ((u32 *)tp->hw_stats)[3]);
  6678. /* Mailboxes */
  6679. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6680. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6681. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6682. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6683. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6684. /* NIC side send descriptors. */
  6685. for (i = 0; i < 6; i++) {
  6686. unsigned long txd;
  6687. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6688. + (i * sizeof(struct tg3_tx_buffer_desc));
  6689. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6690. i,
  6691. readl(txd + 0x0), readl(txd + 0x4),
  6692. readl(txd + 0x8), readl(txd + 0xc));
  6693. }
  6694. /* NIC side RX descriptors. */
  6695. for (i = 0; i < 6; i++) {
  6696. unsigned long rxd;
  6697. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6698. + (i * sizeof(struct tg3_rx_buffer_desc));
  6699. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6700. i,
  6701. readl(rxd + 0x0), readl(rxd + 0x4),
  6702. readl(rxd + 0x8), readl(rxd + 0xc));
  6703. rxd += (4 * sizeof(u32));
  6704. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6705. i,
  6706. readl(rxd + 0x0), readl(rxd + 0x4),
  6707. readl(rxd + 0x8), readl(rxd + 0xc));
  6708. }
  6709. for (i = 0; i < 6; i++) {
  6710. unsigned long rxd;
  6711. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6712. + (i * sizeof(struct tg3_rx_buffer_desc));
  6713. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6714. i,
  6715. readl(rxd + 0x0), readl(rxd + 0x4),
  6716. readl(rxd + 0x8), readl(rxd + 0xc));
  6717. rxd += (4 * sizeof(u32));
  6718. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6719. i,
  6720. readl(rxd + 0x0), readl(rxd + 0x4),
  6721. readl(rxd + 0x8), readl(rxd + 0xc));
  6722. }
  6723. }
  6724. #endif
  6725. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6726. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6727. static int tg3_close(struct net_device *dev)
  6728. {
  6729. struct tg3 *tp = netdev_priv(dev);
  6730. napi_disable(&tp->napi);
  6731. cancel_work_sync(&tp->reset_task);
  6732. netif_stop_queue(dev);
  6733. del_timer_sync(&tp->timer);
  6734. tg3_full_lock(tp, 1);
  6735. #if 0
  6736. tg3_dump_state(tp);
  6737. #endif
  6738. tg3_disable_ints(tp);
  6739. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6740. tg3_free_rings(tp);
  6741. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6742. tg3_full_unlock(tp);
  6743. free_irq(tp->pdev->irq, dev);
  6744. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6745. pci_disable_msi(tp->pdev);
  6746. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6747. }
  6748. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6749. sizeof(tp->net_stats_prev));
  6750. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6751. sizeof(tp->estats_prev));
  6752. tg3_free_consistent(tp);
  6753. tg3_set_power_state(tp, PCI_D3hot);
  6754. netif_carrier_off(tp->dev);
  6755. return 0;
  6756. }
  6757. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6758. {
  6759. unsigned long ret;
  6760. #if (BITS_PER_LONG == 32)
  6761. ret = val->low;
  6762. #else
  6763. ret = ((u64)val->high << 32) | ((u64)val->low);
  6764. #endif
  6765. return ret;
  6766. }
  6767. static unsigned long calc_crc_errors(struct tg3 *tp)
  6768. {
  6769. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6770. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6771. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6772. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6773. u32 val;
  6774. spin_lock_bh(&tp->lock);
  6775. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6776. tg3_writephy(tp, MII_TG3_TEST1,
  6777. val | MII_TG3_TEST1_CRC_EN);
  6778. tg3_readphy(tp, 0x14, &val);
  6779. } else
  6780. val = 0;
  6781. spin_unlock_bh(&tp->lock);
  6782. tp->phy_crc_errors += val;
  6783. return tp->phy_crc_errors;
  6784. }
  6785. return get_stat64(&hw_stats->rx_fcs_errors);
  6786. }
  6787. #define ESTAT_ADD(member) \
  6788. estats->member = old_estats->member + \
  6789. get_stat64(&hw_stats->member)
  6790. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6791. {
  6792. struct tg3_ethtool_stats *estats = &tp->estats;
  6793. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6794. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6795. if (!hw_stats)
  6796. return old_estats;
  6797. ESTAT_ADD(rx_octets);
  6798. ESTAT_ADD(rx_fragments);
  6799. ESTAT_ADD(rx_ucast_packets);
  6800. ESTAT_ADD(rx_mcast_packets);
  6801. ESTAT_ADD(rx_bcast_packets);
  6802. ESTAT_ADD(rx_fcs_errors);
  6803. ESTAT_ADD(rx_align_errors);
  6804. ESTAT_ADD(rx_xon_pause_rcvd);
  6805. ESTAT_ADD(rx_xoff_pause_rcvd);
  6806. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6807. ESTAT_ADD(rx_xoff_entered);
  6808. ESTAT_ADD(rx_frame_too_long_errors);
  6809. ESTAT_ADD(rx_jabbers);
  6810. ESTAT_ADD(rx_undersize_packets);
  6811. ESTAT_ADD(rx_in_length_errors);
  6812. ESTAT_ADD(rx_out_length_errors);
  6813. ESTAT_ADD(rx_64_or_less_octet_packets);
  6814. ESTAT_ADD(rx_65_to_127_octet_packets);
  6815. ESTAT_ADD(rx_128_to_255_octet_packets);
  6816. ESTAT_ADD(rx_256_to_511_octet_packets);
  6817. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6818. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6819. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6820. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6821. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6822. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6823. ESTAT_ADD(tx_octets);
  6824. ESTAT_ADD(tx_collisions);
  6825. ESTAT_ADD(tx_xon_sent);
  6826. ESTAT_ADD(tx_xoff_sent);
  6827. ESTAT_ADD(tx_flow_control);
  6828. ESTAT_ADD(tx_mac_errors);
  6829. ESTAT_ADD(tx_single_collisions);
  6830. ESTAT_ADD(tx_mult_collisions);
  6831. ESTAT_ADD(tx_deferred);
  6832. ESTAT_ADD(tx_excessive_collisions);
  6833. ESTAT_ADD(tx_late_collisions);
  6834. ESTAT_ADD(tx_collide_2times);
  6835. ESTAT_ADD(tx_collide_3times);
  6836. ESTAT_ADD(tx_collide_4times);
  6837. ESTAT_ADD(tx_collide_5times);
  6838. ESTAT_ADD(tx_collide_6times);
  6839. ESTAT_ADD(tx_collide_7times);
  6840. ESTAT_ADD(tx_collide_8times);
  6841. ESTAT_ADD(tx_collide_9times);
  6842. ESTAT_ADD(tx_collide_10times);
  6843. ESTAT_ADD(tx_collide_11times);
  6844. ESTAT_ADD(tx_collide_12times);
  6845. ESTAT_ADD(tx_collide_13times);
  6846. ESTAT_ADD(tx_collide_14times);
  6847. ESTAT_ADD(tx_collide_15times);
  6848. ESTAT_ADD(tx_ucast_packets);
  6849. ESTAT_ADD(tx_mcast_packets);
  6850. ESTAT_ADD(tx_bcast_packets);
  6851. ESTAT_ADD(tx_carrier_sense_errors);
  6852. ESTAT_ADD(tx_discards);
  6853. ESTAT_ADD(tx_errors);
  6854. ESTAT_ADD(dma_writeq_full);
  6855. ESTAT_ADD(dma_write_prioq_full);
  6856. ESTAT_ADD(rxbds_empty);
  6857. ESTAT_ADD(rx_discards);
  6858. ESTAT_ADD(rx_errors);
  6859. ESTAT_ADD(rx_threshold_hit);
  6860. ESTAT_ADD(dma_readq_full);
  6861. ESTAT_ADD(dma_read_prioq_full);
  6862. ESTAT_ADD(tx_comp_queue_full);
  6863. ESTAT_ADD(ring_set_send_prod_index);
  6864. ESTAT_ADD(ring_status_update);
  6865. ESTAT_ADD(nic_irqs);
  6866. ESTAT_ADD(nic_avoided_irqs);
  6867. ESTAT_ADD(nic_tx_threshold_hit);
  6868. return estats;
  6869. }
  6870. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6871. {
  6872. struct tg3 *tp = netdev_priv(dev);
  6873. struct net_device_stats *stats = &tp->net_stats;
  6874. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6875. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6876. if (!hw_stats)
  6877. return old_stats;
  6878. stats->rx_packets = old_stats->rx_packets +
  6879. get_stat64(&hw_stats->rx_ucast_packets) +
  6880. get_stat64(&hw_stats->rx_mcast_packets) +
  6881. get_stat64(&hw_stats->rx_bcast_packets);
  6882. stats->tx_packets = old_stats->tx_packets +
  6883. get_stat64(&hw_stats->tx_ucast_packets) +
  6884. get_stat64(&hw_stats->tx_mcast_packets) +
  6885. get_stat64(&hw_stats->tx_bcast_packets);
  6886. stats->rx_bytes = old_stats->rx_bytes +
  6887. get_stat64(&hw_stats->rx_octets);
  6888. stats->tx_bytes = old_stats->tx_bytes +
  6889. get_stat64(&hw_stats->tx_octets);
  6890. stats->rx_errors = old_stats->rx_errors +
  6891. get_stat64(&hw_stats->rx_errors);
  6892. stats->tx_errors = old_stats->tx_errors +
  6893. get_stat64(&hw_stats->tx_errors) +
  6894. get_stat64(&hw_stats->tx_mac_errors) +
  6895. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6896. get_stat64(&hw_stats->tx_discards);
  6897. stats->multicast = old_stats->multicast +
  6898. get_stat64(&hw_stats->rx_mcast_packets);
  6899. stats->collisions = old_stats->collisions +
  6900. get_stat64(&hw_stats->tx_collisions);
  6901. stats->rx_length_errors = old_stats->rx_length_errors +
  6902. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6903. get_stat64(&hw_stats->rx_undersize_packets);
  6904. stats->rx_over_errors = old_stats->rx_over_errors +
  6905. get_stat64(&hw_stats->rxbds_empty);
  6906. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6907. get_stat64(&hw_stats->rx_align_errors);
  6908. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6909. get_stat64(&hw_stats->tx_discards);
  6910. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6911. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6912. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6913. calc_crc_errors(tp);
  6914. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6915. get_stat64(&hw_stats->rx_discards);
  6916. return stats;
  6917. }
  6918. static inline u32 calc_crc(unsigned char *buf, int len)
  6919. {
  6920. u32 reg;
  6921. u32 tmp;
  6922. int j, k;
  6923. reg = 0xffffffff;
  6924. for (j = 0; j < len; j++) {
  6925. reg ^= buf[j];
  6926. for (k = 0; k < 8; k++) {
  6927. tmp = reg & 0x01;
  6928. reg >>= 1;
  6929. if (tmp) {
  6930. reg ^= 0xedb88320;
  6931. }
  6932. }
  6933. }
  6934. return ~reg;
  6935. }
  6936. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6937. {
  6938. /* accept or reject all multicast frames */
  6939. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6940. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6941. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6942. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6943. }
  6944. static void __tg3_set_rx_mode(struct net_device *dev)
  6945. {
  6946. struct tg3 *tp = netdev_priv(dev);
  6947. u32 rx_mode;
  6948. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6949. RX_MODE_KEEP_VLAN_TAG);
  6950. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6951. * flag clear.
  6952. */
  6953. #if TG3_VLAN_TAG_USED
  6954. if (!tp->vlgrp &&
  6955. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6956. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6957. #else
  6958. /* By definition, VLAN is disabled always in this
  6959. * case.
  6960. */
  6961. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6962. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6963. #endif
  6964. if (dev->flags & IFF_PROMISC) {
  6965. /* Promiscuous mode. */
  6966. rx_mode |= RX_MODE_PROMISC;
  6967. } else if (dev->flags & IFF_ALLMULTI) {
  6968. /* Accept all multicast. */
  6969. tg3_set_multi (tp, 1);
  6970. } else if (dev->mc_count < 1) {
  6971. /* Reject all multicast. */
  6972. tg3_set_multi (tp, 0);
  6973. } else {
  6974. /* Accept one or more multicast(s). */
  6975. struct dev_mc_list *mclist;
  6976. unsigned int i;
  6977. u32 mc_filter[4] = { 0, };
  6978. u32 regidx;
  6979. u32 bit;
  6980. u32 crc;
  6981. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6982. i++, mclist = mclist->next) {
  6983. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6984. bit = ~crc & 0x7f;
  6985. regidx = (bit & 0x60) >> 5;
  6986. bit &= 0x1f;
  6987. mc_filter[regidx] |= (1 << bit);
  6988. }
  6989. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6990. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6991. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6992. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6993. }
  6994. if (rx_mode != tp->rx_mode) {
  6995. tp->rx_mode = rx_mode;
  6996. tw32_f(MAC_RX_MODE, rx_mode);
  6997. udelay(10);
  6998. }
  6999. }
  7000. static void tg3_set_rx_mode(struct net_device *dev)
  7001. {
  7002. struct tg3 *tp = netdev_priv(dev);
  7003. if (!netif_running(dev))
  7004. return;
  7005. tg3_full_lock(tp, 0);
  7006. __tg3_set_rx_mode(dev);
  7007. tg3_full_unlock(tp);
  7008. }
  7009. #define TG3_REGDUMP_LEN (32 * 1024)
  7010. static int tg3_get_regs_len(struct net_device *dev)
  7011. {
  7012. return TG3_REGDUMP_LEN;
  7013. }
  7014. static void tg3_get_regs(struct net_device *dev,
  7015. struct ethtool_regs *regs, void *_p)
  7016. {
  7017. u32 *p = _p;
  7018. struct tg3 *tp = netdev_priv(dev);
  7019. u8 *orig_p = _p;
  7020. int i;
  7021. regs->version = 0;
  7022. memset(p, 0, TG3_REGDUMP_LEN);
  7023. if (tp->link_config.phy_is_low_power)
  7024. return;
  7025. tg3_full_lock(tp, 0);
  7026. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  7027. #define GET_REG32_LOOP(base,len) \
  7028. do { p = (u32 *)(orig_p + (base)); \
  7029. for (i = 0; i < len; i += 4) \
  7030. __GET_REG32((base) + i); \
  7031. } while (0)
  7032. #define GET_REG32_1(reg) \
  7033. do { p = (u32 *)(orig_p + (reg)); \
  7034. __GET_REG32((reg)); \
  7035. } while (0)
  7036. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  7037. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  7038. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  7039. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  7040. GET_REG32_1(SNDDATAC_MODE);
  7041. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  7042. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  7043. GET_REG32_1(SNDBDC_MODE);
  7044. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  7045. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  7046. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  7047. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  7048. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  7049. GET_REG32_1(RCVDCC_MODE);
  7050. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  7051. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  7052. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  7053. GET_REG32_1(MBFREE_MODE);
  7054. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  7055. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  7056. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  7057. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  7058. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  7059. GET_REG32_1(RX_CPU_MODE);
  7060. GET_REG32_1(RX_CPU_STATE);
  7061. GET_REG32_1(RX_CPU_PGMCTR);
  7062. GET_REG32_1(RX_CPU_HWBKPT);
  7063. GET_REG32_1(TX_CPU_MODE);
  7064. GET_REG32_1(TX_CPU_STATE);
  7065. GET_REG32_1(TX_CPU_PGMCTR);
  7066. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  7067. GET_REG32_LOOP(FTQ_RESET, 0x120);
  7068. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  7069. GET_REG32_1(DMAC_MODE);
  7070. GET_REG32_LOOP(GRC_MODE, 0x4c);
  7071. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  7072. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  7073. #undef __GET_REG32
  7074. #undef GET_REG32_LOOP
  7075. #undef GET_REG32_1
  7076. tg3_full_unlock(tp);
  7077. }
  7078. static int tg3_get_eeprom_len(struct net_device *dev)
  7079. {
  7080. struct tg3 *tp = netdev_priv(dev);
  7081. return tp->nvram_size;
  7082. }
  7083. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  7084. static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val);
  7085. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  7086. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  7087. {
  7088. struct tg3 *tp = netdev_priv(dev);
  7089. int ret;
  7090. u8 *pd;
  7091. u32 i, offset, len, b_offset, b_count;
  7092. __le32 val;
  7093. if (tp->link_config.phy_is_low_power)
  7094. return -EAGAIN;
  7095. offset = eeprom->offset;
  7096. len = eeprom->len;
  7097. eeprom->len = 0;
  7098. eeprom->magic = TG3_EEPROM_MAGIC;
  7099. if (offset & 3) {
  7100. /* adjustments to start on required 4 byte boundary */
  7101. b_offset = offset & 3;
  7102. b_count = 4 - b_offset;
  7103. if (b_count > len) {
  7104. /* i.e. offset=1 len=2 */
  7105. b_count = len;
  7106. }
  7107. ret = tg3_nvram_read_le(tp, offset-b_offset, &val);
  7108. if (ret)
  7109. return ret;
  7110. memcpy(data, ((char*)&val) + b_offset, b_count);
  7111. len -= b_count;
  7112. offset += b_count;
  7113. eeprom->len += b_count;
  7114. }
  7115. /* read bytes upto the last 4 byte boundary */
  7116. pd = &data[eeprom->len];
  7117. for (i = 0; i < (len - (len & 3)); i += 4) {
  7118. ret = tg3_nvram_read_le(tp, offset + i, &val);
  7119. if (ret) {
  7120. eeprom->len += i;
  7121. return ret;
  7122. }
  7123. memcpy(pd + i, &val, 4);
  7124. }
  7125. eeprom->len += i;
  7126. if (len & 3) {
  7127. /* read last bytes not ending on 4 byte boundary */
  7128. pd = &data[eeprom->len];
  7129. b_count = len & 3;
  7130. b_offset = offset + len - b_count;
  7131. ret = tg3_nvram_read_le(tp, b_offset, &val);
  7132. if (ret)
  7133. return ret;
  7134. memcpy(pd, &val, b_count);
  7135. eeprom->len += b_count;
  7136. }
  7137. return 0;
  7138. }
  7139. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  7140. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  7141. {
  7142. struct tg3 *tp = netdev_priv(dev);
  7143. int ret;
  7144. u32 offset, len, b_offset, odd_len;
  7145. u8 *buf;
  7146. __le32 start, end;
  7147. if (tp->link_config.phy_is_low_power)
  7148. return -EAGAIN;
  7149. if (eeprom->magic != TG3_EEPROM_MAGIC)
  7150. return -EINVAL;
  7151. offset = eeprom->offset;
  7152. len = eeprom->len;
  7153. if ((b_offset = (offset & 3))) {
  7154. /* adjustments to start on required 4 byte boundary */
  7155. ret = tg3_nvram_read_le(tp, offset-b_offset, &start);
  7156. if (ret)
  7157. return ret;
  7158. len += b_offset;
  7159. offset &= ~3;
  7160. if (len < 4)
  7161. len = 4;
  7162. }
  7163. odd_len = 0;
  7164. if (len & 3) {
  7165. /* adjustments to end on required 4 byte boundary */
  7166. odd_len = 1;
  7167. len = (len + 3) & ~3;
  7168. ret = tg3_nvram_read_le(tp, offset+len-4, &end);
  7169. if (ret)
  7170. return ret;
  7171. }
  7172. buf = data;
  7173. if (b_offset || odd_len) {
  7174. buf = kmalloc(len, GFP_KERNEL);
  7175. if (!buf)
  7176. return -ENOMEM;
  7177. if (b_offset)
  7178. memcpy(buf, &start, 4);
  7179. if (odd_len)
  7180. memcpy(buf+len-4, &end, 4);
  7181. memcpy(buf + b_offset, data, eeprom->len);
  7182. }
  7183. ret = tg3_nvram_write_block(tp, offset, len, buf);
  7184. if (buf != data)
  7185. kfree(buf);
  7186. return ret;
  7187. }
  7188. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7189. {
  7190. struct tg3 *tp = netdev_priv(dev);
  7191. cmd->supported = (SUPPORTED_Autoneg);
  7192. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  7193. cmd->supported |= (SUPPORTED_1000baseT_Half |
  7194. SUPPORTED_1000baseT_Full);
  7195. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  7196. cmd->supported |= (SUPPORTED_100baseT_Half |
  7197. SUPPORTED_100baseT_Full |
  7198. SUPPORTED_10baseT_Half |
  7199. SUPPORTED_10baseT_Full |
  7200. SUPPORTED_TP);
  7201. cmd->port = PORT_TP;
  7202. } else {
  7203. cmd->supported |= SUPPORTED_FIBRE;
  7204. cmd->port = PORT_FIBRE;
  7205. }
  7206. cmd->advertising = tp->link_config.advertising;
  7207. if (netif_running(dev)) {
  7208. cmd->speed = tp->link_config.active_speed;
  7209. cmd->duplex = tp->link_config.active_duplex;
  7210. }
  7211. cmd->phy_address = PHY_ADDR;
  7212. cmd->transceiver = 0;
  7213. cmd->autoneg = tp->link_config.autoneg;
  7214. cmd->maxtxpkt = 0;
  7215. cmd->maxrxpkt = 0;
  7216. return 0;
  7217. }
  7218. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7219. {
  7220. struct tg3 *tp = netdev_priv(dev);
  7221. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  7222. /* These are the only valid advertisement bits allowed. */
  7223. if (cmd->autoneg == AUTONEG_ENABLE &&
  7224. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  7225. ADVERTISED_1000baseT_Full |
  7226. ADVERTISED_Autoneg |
  7227. ADVERTISED_FIBRE)))
  7228. return -EINVAL;
  7229. /* Fiber can only do SPEED_1000. */
  7230. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  7231. (cmd->speed != SPEED_1000))
  7232. return -EINVAL;
  7233. /* Copper cannot force SPEED_1000. */
  7234. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  7235. (cmd->speed == SPEED_1000))
  7236. return -EINVAL;
  7237. else if ((cmd->speed == SPEED_1000) &&
  7238. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  7239. return -EINVAL;
  7240. tg3_full_lock(tp, 0);
  7241. tp->link_config.autoneg = cmd->autoneg;
  7242. if (cmd->autoneg == AUTONEG_ENABLE) {
  7243. tp->link_config.advertising = (cmd->advertising |
  7244. ADVERTISED_Autoneg);
  7245. tp->link_config.speed = SPEED_INVALID;
  7246. tp->link_config.duplex = DUPLEX_INVALID;
  7247. } else {
  7248. tp->link_config.advertising = 0;
  7249. tp->link_config.speed = cmd->speed;
  7250. tp->link_config.duplex = cmd->duplex;
  7251. }
  7252. tp->link_config.orig_speed = tp->link_config.speed;
  7253. tp->link_config.orig_duplex = tp->link_config.duplex;
  7254. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  7255. if (netif_running(dev))
  7256. tg3_setup_phy(tp, 1);
  7257. tg3_full_unlock(tp);
  7258. return 0;
  7259. }
  7260. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  7261. {
  7262. struct tg3 *tp = netdev_priv(dev);
  7263. strcpy(info->driver, DRV_MODULE_NAME);
  7264. strcpy(info->version, DRV_MODULE_VERSION);
  7265. strcpy(info->fw_version, tp->fw_ver);
  7266. strcpy(info->bus_info, pci_name(tp->pdev));
  7267. }
  7268. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7269. {
  7270. struct tg3 *tp = netdev_priv(dev);
  7271. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  7272. wol->supported = WAKE_MAGIC;
  7273. else
  7274. wol->supported = 0;
  7275. wol->wolopts = 0;
  7276. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  7277. wol->wolopts = WAKE_MAGIC;
  7278. memset(&wol->sopass, 0, sizeof(wol->sopass));
  7279. }
  7280. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7281. {
  7282. struct tg3 *tp = netdev_priv(dev);
  7283. if (wol->wolopts & ~WAKE_MAGIC)
  7284. return -EINVAL;
  7285. if ((wol->wolopts & WAKE_MAGIC) &&
  7286. !(tp->tg3_flags & TG3_FLAG_WOL_CAP))
  7287. return -EINVAL;
  7288. spin_lock_bh(&tp->lock);
  7289. if (wol->wolopts & WAKE_MAGIC)
  7290. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  7291. else
  7292. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  7293. spin_unlock_bh(&tp->lock);
  7294. return 0;
  7295. }
  7296. static u32 tg3_get_msglevel(struct net_device *dev)
  7297. {
  7298. struct tg3 *tp = netdev_priv(dev);
  7299. return tp->msg_enable;
  7300. }
  7301. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  7302. {
  7303. struct tg3 *tp = netdev_priv(dev);
  7304. tp->msg_enable = value;
  7305. }
  7306. static int tg3_set_tso(struct net_device *dev, u32 value)
  7307. {
  7308. struct tg3 *tp = netdev_priv(dev);
  7309. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  7310. if (value)
  7311. return -EINVAL;
  7312. return 0;
  7313. }
  7314. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  7315. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  7316. if (value) {
  7317. dev->features |= NETIF_F_TSO6;
  7318. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7319. dev->features |= NETIF_F_TSO_ECN;
  7320. } else
  7321. dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN);
  7322. }
  7323. return ethtool_op_set_tso(dev, value);
  7324. }
  7325. static int tg3_nway_reset(struct net_device *dev)
  7326. {
  7327. struct tg3 *tp = netdev_priv(dev);
  7328. u32 bmcr;
  7329. int r;
  7330. if (!netif_running(dev))
  7331. return -EAGAIN;
  7332. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7333. return -EINVAL;
  7334. spin_lock_bh(&tp->lock);
  7335. r = -EINVAL;
  7336. tg3_readphy(tp, MII_BMCR, &bmcr);
  7337. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  7338. ((bmcr & BMCR_ANENABLE) ||
  7339. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  7340. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  7341. BMCR_ANENABLE);
  7342. r = 0;
  7343. }
  7344. spin_unlock_bh(&tp->lock);
  7345. return r;
  7346. }
  7347. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  7348. {
  7349. struct tg3 *tp = netdev_priv(dev);
  7350. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  7351. ering->rx_mini_max_pending = 0;
  7352. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  7353. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  7354. else
  7355. ering->rx_jumbo_max_pending = 0;
  7356. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  7357. ering->rx_pending = tp->rx_pending;
  7358. ering->rx_mini_pending = 0;
  7359. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  7360. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  7361. else
  7362. ering->rx_jumbo_pending = 0;
  7363. ering->tx_pending = tp->tx_pending;
  7364. }
  7365. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  7366. {
  7367. struct tg3 *tp = netdev_priv(dev);
  7368. int irq_sync = 0, err = 0;
  7369. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  7370. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  7371. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  7372. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  7373. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  7374. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  7375. return -EINVAL;
  7376. if (netif_running(dev)) {
  7377. tg3_netif_stop(tp);
  7378. irq_sync = 1;
  7379. }
  7380. tg3_full_lock(tp, irq_sync);
  7381. tp->rx_pending = ering->rx_pending;
  7382. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  7383. tp->rx_pending > 63)
  7384. tp->rx_pending = 63;
  7385. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  7386. tp->tx_pending = ering->tx_pending;
  7387. if (netif_running(dev)) {
  7388. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7389. err = tg3_restart_hw(tp, 1);
  7390. if (!err)
  7391. tg3_netif_start(tp);
  7392. }
  7393. tg3_full_unlock(tp);
  7394. return err;
  7395. }
  7396. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7397. {
  7398. struct tg3 *tp = netdev_priv(dev);
  7399. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  7400. if (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX)
  7401. epause->rx_pause = 1;
  7402. else
  7403. epause->rx_pause = 0;
  7404. if (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_TX)
  7405. epause->tx_pause = 1;
  7406. else
  7407. epause->tx_pause = 0;
  7408. }
  7409. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7410. {
  7411. struct tg3 *tp = netdev_priv(dev);
  7412. int irq_sync = 0, err = 0;
  7413. if (netif_running(dev)) {
  7414. tg3_netif_stop(tp);
  7415. irq_sync = 1;
  7416. }
  7417. tg3_full_lock(tp, irq_sync);
  7418. if (epause->autoneg)
  7419. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  7420. else
  7421. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  7422. if (epause->rx_pause)
  7423. tp->link_config.flowctrl |= TG3_FLOW_CTRL_RX;
  7424. else
  7425. tp->link_config.flowctrl &= ~TG3_FLOW_CTRL_RX;
  7426. if (epause->tx_pause)
  7427. tp->link_config.flowctrl |= TG3_FLOW_CTRL_TX;
  7428. else
  7429. tp->link_config.flowctrl &= ~TG3_FLOW_CTRL_TX;
  7430. if (netif_running(dev)) {
  7431. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7432. err = tg3_restart_hw(tp, 1);
  7433. if (!err)
  7434. tg3_netif_start(tp);
  7435. }
  7436. tg3_full_unlock(tp);
  7437. return err;
  7438. }
  7439. static u32 tg3_get_rx_csum(struct net_device *dev)
  7440. {
  7441. struct tg3 *tp = netdev_priv(dev);
  7442. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  7443. }
  7444. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  7445. {
  7446. struct tg3 *tp = netdev_priv(dev);
  7447. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7448. if (data != 0)
  7449. return -EINVAL;
  7450. return 0;
  7451. }
  7452. spin_lock_bh(&tp->lock);
  7453. if (data)
  7454. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7455. else
  7456. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7457. spin_unlock_bh(&tp->lock);
  7458. return 0;
  7459. }
  7460. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7461. {
  7462. struct tg3 *tp = netdev_priv(dev);
  7463. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7464. if (data != 0)
  7465. return -EINVAL;
  7466. return 0;
  7467. }
  7468. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7469. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  7470. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  7471. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7472. ethtool_op_set_tx_ipv6_csum(dev, data);
  7473. else
  7474. ethtool_op_set_tx_csum(dev, data);
  7475. return 0;
  7476. }
  7477. static int tg3_get_sset_count (struct net_device *dev, int sset)
  7478. {
  7479. switch (sset) {
  7480. case ETH_SS_TEST:
  7481. return TG3_NUM_TEST;
  7482. case ETH_SS_STATS:
  7483. return TG3_NUM_STATS;
  7484. default:
  7485. return -EOPNOTSUPP;
  7486. }
  7487. }
  7488. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7489. {
  7490. switch (stringset) {
  7491. case ETH_SS_STATS:
  7492. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7493. break;
  7494. case ETH_SS_TEST:
  7495. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7496. break;
  7497. default:
  7498. WARN_ON(1); /* we need a WARN() */
  7499. break;
  7500. }
  7501. }
  7502. static int tg3_phys_id(struct net_device *dev, u32 data)
  7503. {
  7504. struct tg3 *tp = netdev_priv(dev);
  7505. int i;
  7506. if (!netif_running(tp->dev))
  7507. return -EAGAIN;
  7508. if (data == 0)
  7509. data = UINT_MAX / 2;
  7510. for (i = 0; i < (data * 2); i++) {
  7511. if ((i % 2) == 0)
  7512. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7513. LED_CTRL_1000MBPS_ON |
  7514. LED_CTRL_100MBPS_ON |
  7515. LED_CTRL_10MBPS_ON |
  7516. LED_CTRL_TRAFFIC_OVERRIDE |
  7517. LED_CTRL_TRAFFIC_BLINK |
  7518. LED_CTRL_TRAFFIC_LED);
  7519. else
  7520. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7521. LED_CTRL_TRAFFIC_OVERRIDE);
  7522. if (msleep_interruptible(500))
  7523. break;
  7524. }
  7525. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7526. return 0;
  7527. }
  7528. static void tg3_get_ethtool_stats (struct net_device *dev,
  7529. struct ethtool_stats *estats, u64 *tmp_stats)
  7530. {
  7531. struct tg3 *tp = netdev_priv(dev);
  7532. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7533. }
  7534. #define NVRAM_TEST_SIZE 0x100
  7535. #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14
  7536. #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18
  7537. #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c
  7538. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7539. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7540. static int tg3_test_nvram(struct tg3 *tp)
  7541. {
  7542. u32 csum, magic;
  7543. __le32 *buf;
  7544. int i, j, k, err = 0, size;
  7545. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7546. return -EIO;
  7547. if (magic == TG3_EEPROM_MAGIC)
  7548. size = NVRAM_TEST_SIZE;
  7549. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7550. if ((magic & TG3_EEPROM_SB_FORMAT_MASK) ==
  7551. TG3_EEPROM_SB_FORMAT_1) {
  7552. switch (magic & TG3_EEPROM_SB_REVISION_MASK) {
  7553. case TG3_EEPROM_SB_REVISION_0:
  7554. size = NVRAM_SELFBOOT_FORMAT1_0_SIZE;
  7555. break;
  7556. case TG3_EEPROM_SB_REVISION_2:
  7557. size = NVRAM_SELFBOOT_FORMAT1_2_SIZE;
  7558. break;
  7559. case TG3_EEPROM_SB_REVISION_3:
  7560. size = NVRAM_SELFBOOT_FORMAT1_3_SIZE;
  7561. break;
  7562. default:
  7563. return 0;
  7564. }
  7565. } else
  7566. return 0;
  7567. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7568. size = NVRAM_SELFBOOT_HW_SIZE;
  7569. else
  7570. return -EIO;
  7571. buf = kmalloc(size, GFP_KERNEL);
  7572. if (buf == NULL)
  7573. return -ENOMEM;
  7574. err = -EIO;
  7575. for (i = 0, j = 0; i < size; i += 4, j++) {
  7576. if ((err = tg3_nvram_read_le(tp, i, &buf[j])) != 0)
  7577. break;
  7578. }
  7579. if (i < size)
  7580. goto out;
  7581. /* Selfboot format */
  7582. magic = swab32(le32_to_cpu(buf[0]));
  7583. if ((magic & TG3_EEPROM_MAGIC_FW_MSK) ==
  7584. TG3_EEPROM_MAGIC_FW) {
  7585. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7586. if ((magic & TG3_EEPROM_SB_REVISION_MASK) ==
  7587. TG3_EEPROM_SB_REVISION_2) {
  7588. /* For rev 2, the csum doesn't include the MBA. */
  7589. for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++)
  7590. csum8 += buf8[i];
  7591. for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++)
  7592. csum8 += buf8[i];
  7593. } else {
  7594. for (i = 0; i < size; i++)
  7595. csum8 += buf8[i];
  7596. }
  7597. if (csum8 == 0) {
  7598. err = 0;
  7599. goto out;
  7600. }
  7601. err = -EIO;
  7602. goto out;
  7603. }
  7604. if ((magic & TG3_EEPROM_MAGIC_HW_MSK) ==
  7605. TG3_EEPROM_MAGIC_HW) {
  7606. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7607. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7608. u8 *buf8 = (u8 *) buf;
  7609. /* Separate the parity bits and the data bytes. */
  7610. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7611. if ((i == 0) || (i == 8)) {
  7612. int l;
  7613. u8 msk;
  7614. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7615. parity[k++] = buf8[i] & msk;
  7616. i++;
  7617. }
  7618. else if (i == 16) {
  7619. int l;
  7620. u8 msk;
  7621. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7622. parity[k++] = buf8[i] & msk;
  7623. i++;
  7624. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7625. parity[k++] = buf8[i] & msk;
  7626. i++;
  7627. }
  7628. data[j++] = buf8[i];
  7629. }
  7630. err = -EIO;
  7631. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7632. u8 hw8 = hweight8(data[i]);
  7633. if ((hw8 & 0x1) && parity[i])
  7634. goto out;
  7635. else if (!(hw8 & 0x1) && !parity[i])
  7636. goto out;
  7637. }
  7638. err = 0;
  7639. goto out;
  7640. }
  7641. /* Bootstrap checksum at offset 0x10 */
  7642. csum = calc_crc((unsigned char *) buf, 0x10);
  7643. if(csum != le32_to_cpu(buf[0x10/4]))
  7644. goto out;
  7645. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7646. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7647. if (csum != le32_to_cpu(buf[0xfc/4]))
  7648. goto out;
  7649. err = 0;
  7650. out:
  7651. kfree(buf);
  7652. return err;
  7653. }
  7654. #define TG3_SERDES_TIMEOUT_SEC 2
  7655. #define TG3_COPPER_TIMEOUT_SEC 6
  7656. static int tg3_test_link(struct tg3 *tp)
  7657. {
  7658. int i, max;
  7659. if (!netif_running(tp->dev))
  7660. return -ENODEV;
  7661. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7662. max = TG3_SERDES_TIMEOUT_SEC;
  7663. else
  7664. max = TG3_COPPER_TIMEOUT_SEC;
  7665. for (i = 0; i < max; i++) {
  7666. if (netif_carrier_ok(tp->dev))
  7667. return 0;
  7668. if (msleep_interruptible(1000))
  7669. break;
  7670. }
  7671. return -EIO;
  7672. }
  7673. /* Only test the commonly used registers */
  7674. static int tg3_test_registers(struct tg3 *tp)
  7675. {
  7676. int i, is_5705, is_5750;
  7677. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7678. static struct {
  7679. u16 offset;
  7680. u16 flags;
  7681. #define TG3_FL_5705 0x1
  7682. #define TG3_FL_NOT_5705 0x2
  7683. #define TG3_FL_NOT_5788 0x4
  7684. #define TG3_FL_NOT_5750 0x8
  7685. u32 read_mask;
  7686. u32 write_mask;
  7687. } reg_tbl[] = {
  7688. /* MAC Control Registers */
  7689. { MAC_MODE, TG3_FL_NOT_5705,
  7690. 0x00000000, 0x00ef6f8c },
  7691. { MAC_MODE, TG3_FL_5705,
  7692. 0x00000000, 0x01ef6b8c },
  7693. { MAC_STATUS, TG3_FL_NOT_5705,
  7694. 0x03800107, 0x00000000 },
  7695. { MAC_STATUS, TG3_FL_5705,
  7696. 0x03800100, 0x00000000 },
  7697. { MAC_ADDR_0_HIGH, 0x0000,
  7698. 0x00000000, 0x0000ffff },
  7699. { MAC_ADDR_0_LOW, 0x0000,
  7700. 0x00000000, 0xffffffff },
  7701. { MAC_RX_MTU_SIZE, 0x0000,
  7702. 0x00000000, 0x0000ffff },
  7703. { MAC_TX_MODE, 0x0000,
  7704. 0x00000000, 0x00000070 },
  7705. { MAC_TX_LENGTHS, 0x0000,
  7706. 0x00000000, 0x00003fff },
  7707. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7708. 0x00000000, 0x000007fc },
  7709. { MAC_RX_MODE, TG3_FL_5705,
  7710. 0x00000000, 0x000007dc },
  7711. { MAC_HASH_REG_0, 0x0000,
  7712. 0x00000000, 0xffffffff },
  7713. { MAC_HASH_REG_1, 0x0000,
  7714. 0x00000000, 0xffffffff },
  7715. { MAC_HASH_REG_2, 0x0000,
  7716. 0x00000000, 0xffffffff },
  7717. { MAC_HASH_REG_3, 0x0000,
  7718. 0x00000000, 0xffffffff },
  7719. /* Receive Data and Receive BD Initiator Control Registers. */
  7720. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7721. 0x00000000, 0xffffffff },
  7722. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7723. 0x00000000, 0xffffffff },
  7724. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7725. 0x00000000, 0x00000003 },
  7726. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7727. 0x00000000, 0xffffffff },
  7728. { RCVDBDI_STD_BD+0, 0x0000,
  7729. 0x00000000, 0xffffffff },
  7730. { RCVDBDI_STD_BD+4, 0x0000,
  7731. 0x00000000, 0xffffffff },
  7732. { RCVDBDI_STD_BD+8, 0x0000,
  7733. 0x00000000, 0xffff0002 },
  7734. { RCVDBDI_STD_BD+0xc, 0x0000,
  7735. 0x00000000, 0xffffffff },
  7736. /* Receive BD Initiator Control Registers. */
  7737. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7738. 0x00000000, 0xffffffff },
  7739. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7740. 0x00000000, 0x000003ff },
  7741. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7742. 0x00000000, 0xffffffff },
  7743. /* Host Coalescing Control Registers. */
  7744. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7745. 0x00000000, 0x00000004 },
  7746. { HOSTCC_MODE, TG3_FL_5705,
  7747. 0x00000000, 0x000000f6 },
  7748. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7749. 0x00000000, 0xffffffff },
  7750. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7751. 0x00000000, 0x000003ff },
  7752. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7753. 0x00000000, 0xffffffff },
  7754. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7755. 0x00000000, 0x000003ff },
  7756. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7757. 0x00000000, 0xffffffff },
  7758. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7759. 0x00000000, 0x000000ff },
  7760. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7761. 0x00000000, 0xffffffff },
  7762. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7763. 0x00000000, 0x000000ff },
  7764. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7765. 0x00000000, 0xffffffff },
  7766. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7767. 0x00000000, 0xffffffff },
  7768. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7769. 0x00000000, 0xffffffff },
  7770. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7771. 0x00000000, 0x000000ff },
  7772. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7773. 0x00000000, 0xffffffff },
  7774. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7775. 0x00000000, 0x000000ff },
  7776. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7777. 0x00000000, 0xffffffff },
  7778. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7779. 0x00000000, 0xffffffff },
  7780. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7781. 0x00000000, 0xffffffff },
  7782. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7783. 0x00000000, 0xffffffff },
  7784. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7785. 0x00000000, 0xffffffff },
  7786. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7787. 0xffffffff, 0x00000000 },
  7788. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7789. 0xffffffff, 0x00000000 },
  7790. /* Buffer Manager Control Registers. */
  7791. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7792. 0x00000000, 0x007fff80 },
  7793. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7794. 0x00000000, 0x007fffff },
  7795. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7796. 0x00000000, 0x0000003f },
  7797. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7798. 0x00000000, 0x000001ff },
  7799. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7800. 0x00000000, 0x000001ff },
  7801. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7802. 0xffffffff, 0x00000000 },
  7803. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7804. 0xffffffff, 0x00000000 },
  7805. /* Mailbox Registers */
  7806. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7807. 0x00000000, 0x000001ff },
  7808. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7809. 0x00000000, 0x000001ff },
  7810. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7811. 0x00000000, 0x000007ff },
  7812. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7813. 0x00000000, 0x000001ff },
  7814. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7815. };
  7816. is_5705 = is_5750 = 0;
  7817. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7818. is_5705 = 1;
  7819. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7820. is_5750 = 1;
  7821. }
  7822. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7823. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7824. continue;
  7825. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7826. continue;
  7827. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7828. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7829. continue;
  7830. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7831. continue;
  7832. offset = (u32) reg_tbl[i].offset;
  7833. read_mask = reg_tbl[i].read_mask;
  7834. write_mask = reg_tbl[i].write_mask;
  7835. /* Save the original register content */
  7836. save_val = tr32(offset);
  7837. /* Determine the read-only value. */
  7838. read_val = save_val & read_mask;
  7839. /* Write zero to the register, then make sure the read-only bits
  7840. * are not changed and the read/write bits are all zeros.
  7841. */
  7842. tw32(offset, 0);
  7843. val = tr32(offset);
  7844. /* Test the read-only and read/write bits. */
  7845. if (((val & read_mask) != read_val) || (val & write_mask))
  7846. goto out;
  7847. /* Write ones to all the bits defined by RdMask and WrMask, then
  7848. * make sure the read-only bits are not changed and the
  7849. * read/write bits are all ones.
  7850. */
  7851. tw32(offset, read_mask | write_mask);
  7852. val = tr32(offset);
  7853. /* Test the read-only bits. */
  7854. if ((val & read_mask) != read_val)
  7855. goto out;
  7856. /* Test the read/write bits. */
  7857. if ((val & write_mask) != write_mask)
  7858. goto out;
  7859. tw32(offset, save_val);
  7860. }
  7861. return 0;
  7862. out:
  7863. if (netif_msg_hw(tp))
  7864. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7865. offset);
  7866. tw32(offset, save_val);
  7867. return -EIO;
  7868. }
  7869. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7870. {
  7871. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7872. int i;
  7873. u32 j;
  7874. for (i = 0; i < ARRAY_SIZE(test_pattern); i++) {
  7875. for (j = 0; j < len; j += 4) {
  7876. u32 val;
  7877. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7878. tg3_read_mem(tp, offset + j, &val);
  7879. if (val != test_pattern[i])
  7880. return -EIO;
  7881. }
  7882. }
  7883. return 0;
  7884. }
  7885. static int tg3_test_memory(struct tg3 *tp)
  7886. {
  7887. static struct mem_entry {
  7888. u32 offset;
  7889. u32 len;
  7890. } mem_tbl_570x[] = {
  7891. { 0x00000000, 0x00b50},
  7892. { 0x00002000, 0x1c000},
  7893. { 0xffffffff, 0x00000}
  7894. }, mem_tbl_5705[] = {
  7895. { 0x00000100, 0x0000c},
  7896. { 0x00000200, 0x00008},
  7897. { 0x00004000, 0x00800},
  7898. { 0x00006000, 0x01000},
  7899. { 0x00008000, 0x02000},
  7900. { 0x00010000, 0x0e000},
  7901. { 0xffffffff, 0x00000}
  7902. }, mem_tbl_5755[] = {
  7903. { 0x00000200, 0x00008},
  7904. { 0x00004000, 0x00800},
  7905. { 0x00006000, 0x00800},
  7906. { 0x00008000, 0x02000},
  7907. { 0x00010000, 0x0c000},
  7908. { 0xffffffff, 0x00000}
  7909. }, mem_tbl_5906[] = {
  7910. { 0x00000200, 0x00008},
  7911. { 0x00004000, 0x00400},
  7912. { 0x00006000, 0x00400},
  7913. { 0x00008000, 0x01000},
  7914. { 0x00010000, 0x01000},
  7915. { 0xffffffff, 0x00000}
  7916. };
  7917. struct mem_entry *mem_tbl;
  7918. int err = 0;
  7919. int i;
  7920. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7921. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7922. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  7923. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  7924. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7925. mem_tbl = mem_tbl_5755;
  7926. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7927. mem_tbl = mem_tbl_5906;
  7928. else
  7929. mem_tbl = mem_tbl_5705;
  7930. } else
  7931. mem_tbl = mem_tbl_570x;
  7932. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7933. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7934. mem_tbl[i].len)) != 0)
  7935. break;
  7936. }
  7937. return err;
  7938. }
  7939. #define TG3_MAC_LOOPBACK 0
  7940. #define TG3_PHY_LOOPBACK 1
  7941. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7942. {
  7943. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7944. u32 desc_idx;
  7945. struct sk_buff *skb, *rx_skb;
  7946. u8 *tx_data;
  7947. dma_addr_t map;
  7948. int num_pkts, tx_len, rx_len, i, err;
  7949. struct tg3_rx_buffer_desc *desc;
  7950. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7951. /* HW errata - mac loopback fails in some cases on 5780.
  7952. * Normal traffic and PHY loopback are not affected by
  7953. * errata.
  7954. */
  7955. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7956. return 0;
  7957. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7958. MAC_MODE_PORT_INT_LPBACK;
  7959. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7960. mac_mode |= MAC_MODE_LINK_POLARITY;
  7961. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7962. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7963. else
  7964. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7965. tw32(MAC_MODE, mac_mode);
  7966. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7967. u32 val;
  7968. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7969. u32 phytest;
  7970. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7971. u32 phy;
  7972. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7973. phytest | MII_TG3_EPHY_SHADOW_EN);
  7974. if (!tg3_readphy(tp, 0x1b, &phy))
  7975. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7976. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7977. }
  7978. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7979. } else
  7980. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7981. tg3_phy_toggle_automdix(tp, 0);
  7982. tg3_writephy(tp, MII_BMCR, val);
  7983. udelay(40);
  7984. mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  7985. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7986. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7987. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7988. } else
  7989. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7990. /* reset to prevent losing 1st rx packet intermittently */
  7991. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7992. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7993. udelay(10);
  7994. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7995. }
  7996. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  7997. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
  7998. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7999. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411)
  8000. mac_mode |= MAC_MODE_LINK_POLARITY;
  8001. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  8002. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  8003. }
  8004. tw32(MAC_MODE, mac_mode);
  8005. }
  8006. else
  8007. return -EINVAL;
  8008. err = -EIO;
  8009. tx_len = 1514;
  8010. skb = netdev_alloc_skb(tp->dev, tx_len);
  8011. if (!skb)
  8012. return -ENOMEM;
  8013. tx_data = skb_put(skb, tx_len);
  8014. memcpy(tx_data, tp->dev->dev_addr, 6);
  8015. memset(tx_data + 6, 0x0, 8);
  8016. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  8017. for (i = 14; i < tx_len; i++)
  8018. tx_data[i] = (u8) (i & 0xff);
  8019. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  8020. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  8021. HOSTCC_MODE_NOW);
  8022. udelay(10);
  8023. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  8024. num_pkts = 0;
  8025. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  8026. tp->tx_prod++;
  8027. num_pkts++;
  8028. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  8029. tp->tx_prod);
  8030. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  8031. udelay(10);
  8032. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  8033. for (i = 0; i < 25; i++) {
  8034. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  8035. HOSTCC_MODE_NOW);
  8036. udelay(10);
  8037. tx_idx = tp->hw_status->idx[0].tx_consumer;
  8038. rx_idx = tp->hw_status->idx[0].rx_producer;
  8039. if ((tx_idx == tp->tx_prod) &&
  8040. (rx_idx == (rx_start_idx + num_pkts)))
  8041. break;
  8042. }
  8043. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  8044. dev_kfree_skb(skb);
  8045. if (tx_idx != tp->tx_prod)
  8046. goto out;
  8047. if (rx_idx != rx_start_idx + num_pkts)
  8048. goto out;
  8049. desc = &tp->rx_rcb[rx_start_idx];
  8050. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  8051. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  8052. if (opaque_key != RXD_OPAQUE_RING_STD)
  8053. goto out;
  8054. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  8055. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  8056. goto out;
  8057. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  8058. if (rx_len != tx_len)
  8059. goto out;
  8060. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  8061. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  8062. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  8063. for (i = 14; i < tx_len; i++) {
  8064. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  8065. goto out;
  8066. }
  8067. err = 0;
  8068. /* tg3_free_rings will unmap and free the rx_skb */
  8069. out:
  8070. return err;
  8071. }
  8072. #define TG3_MAC_LOOPBACK_FAILED 1
  8073. #define TG3_PHY_LOOPBACK_FAILED 2
  8074. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  8075. TG3_PHY_LOOPBACK_FAILED)
  8076. static int tg3_test_loopback(struct tg3 *tp)
  8077. {
  8078. int err = 0;
  8079. u32 cpmuctrl = 0;
  8080. if (!netif_running(tp->dev))
  8081. return TG3_LOOPBACK_FAILED;
  8082. err = tg3_reset_hw(tp, 1);
  8083. if (err)
  8084. return TG3_LOOPBACK_FAILED;
  8085. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8086. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  8087. int i;
  8088. u32 status;
  8089. tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER);
  8090. /* Wait for up to 40 microseconds to acquire lock. */
  8091. for (i = 0; i < 4; i++) {
  8092. status = tr32(TG3_CPMU_MUTEX_GNT);
  8093. if (status == CPMU_MUTEX_GNT_DRIVER)
  8094. break;
  8095. udelay(10);
  8096. }
  8097. if (status != CPMU_MUTEX_GNT_DRIVER)
  8098. return TG3_LOOPBACK_FAILED;
  8099. /* Turn off link-based power management. */
  8100. cpmuctrl = tr32(TG3_CPMU_CTRL);
  8101. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8102. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX)
  8103. tw32(TG3_CPMU_CTRL,
  8104. cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE |
  8105. CPMU_CTRL_LINK_AWARE_MODE));
  8106. else
  8107. tw32(TG3_CPMU_CTRL,
  8108. cpmuctrl & ~CPMU_CTRL_LINK_AWARE_MODE);
  8109. }
  8110. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  8111. err |= TG3_MAC_LOOPBACK_FAILED;
  8112. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8113. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  8114. tw32(TG3_CPMU_CTRL, cpmuctrl);
  8115. /* Release the mutex */
  8116. tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER);
  8117. }
  8118. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  8119. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  8120. err |= TG3_PHY_LOOPBACK_FAILED;
  8121. }
  8122. return err;
  8123. }
  8124. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  8125. u64 *data)
  8126. {
  8127. struct tg3 *tp = netdev_priv(dev);
  8128. if (tp->link_config.phy_is_low_power)
  8129. tg3_set_power_state(tp, PCI_D0);
  8130. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  8131. if (tg3_test_nvram(tp) != 0) {
  8132. etest->flags |= ETH_TEST_FL_FAILED;
  8133. data[0] = 1;
  8134. }
  8135. if (tg3_test_link(tp) != 0) {
  8136. etest->flags |= ETH_TEST_FL_FAILED;
  8137. data[1] = 1;
  8138. }
  8139. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  8140. int err, irq_sync = 0;
  8141. if (netif_running(dev)) {
  8142. tg3_netif_stop(tp);
  8143. irq_sync = 1;
  8144. }
  8145. tg3_full_lock(tp, irq_sync);
  8146. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  8147. err = tg3_nvram_lock(tp);
  8148. tg3_halt_cpu(tp, RX_CPU_BASE);
  8149. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  8150. tg3_halt_cpu(tp, TX_CPU_BASE);
  8151. if (!err)
  8152. tg3_nvram_unlock(tp);
  8153. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  8154. tg3_phy_reset(tp);
  8155. if (tg3_test_registers(tp) != 0) {
  8156. etest->flags |= ETH_TEST_FL_FAILED;
  8157. data[2] = 1;
  8158. }
  8159. if (tg3_test_memory(tp) != 0) {
  8160. etest->flags |= ETH_TEST_FL_FAILED;
  8161. data[3] = 1;
  8162. }
  8163. if ((data[4] = tg3_test_loopback(tp)) != 0)
  8164. etest->flags |= ETH_TEST_FL_FAILED;
  8165. tg3_full_unlock(tp);
  8166. if (tg3_test_interrupt(tp) != 0) {
  8167. etest->flags |= ETH_TEST_FL_FAILED;
  8168. data[5] = 1;
  8169. }
  8170. tg3_full_lock(tp, 0);
  8171. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  8172. if (netif_running(dev)) {
  8173. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  8174. if (!tg3_restart_hw(tp, 1))
  8175. tg3_netif_start(tp);
  8176. }
  8177. tg3_full_unlock(tp);
  8178. }
  8179. if (tp->link_config.phy_is_low_power)
  8180. tg3_set_power_state(tp, PCI_D3hot);
  8181. }
  8182. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8183. {
  8184. struct mii_ioctl_data *data = if_mii(ifr);
  8185. struct tg3 *tp = netdev_priv(dev);
  8186. int err;
  8187. switch(cmd) {
  8188. case SIOCGMIIPHY:
  8189. data->phy_id = PHY_ADDR;
  8190. /* fallthru */
  8191. case SIOCGMIIREG: {
  8192. u32 mii_regval;
  8193. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  8194. break; /* We have no PHY */
  8195. if (tp->link_config.phy_is_low_power)
  8196. return -EAGAIN;
  8197. spin_lock_bh(&tp->lock);
  8198. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  8199. spin_unlock_bh(&tp->lock);
  8200. data->val_out = mii_regval;
  8201. return err;
  8202. }
  8203. case SIOCSMIIREG:
  8204. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  8205. break; /* We have no PHY */
  8206. if (!capable(CAP_NET_ADMIN))
  8207. return -EPERM;
  8208. if (tp->link_config.phy_is_low_power)
  8209. return -EAGAIN;
  8210. spin_lock_bh(&tp->lock);
  8211. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  8212. spin_unlock_bh(&tp->lock);
  8213. return err;
  8214. default:
  8215. /* do nothing */
  8216. break;
  8217. }
  8218. return -EOPNOTSUPP;
  8219. }
  8220. #if TG3_VLAN_TAG_USED
  8221. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  8222. {
  8223. struct tg3 *tp = netdev_priv(dev);
  8224. if (netif_running(dev))
  8225. tg3_netif_stop(tp);
  8226. tg3_full_lock(tp, 0);
  8227. tp->vlgrp = grp;
  8228. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  8229. __tg3_set_rx_mode(dev);
  8230. if (netif_running(dev))
  8231. tg3_netif_start(tp);
  8232. tg3_full_unlock(tp);
  8233. }
  8234. #endif
  8235. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  8236. {
  8237. struct tg3 *tp = netdev_priv(dev);
  8238. memcpy(ec, &tp->coal, sizeof(*ec));
  8239. return 0;
  8240. }
  8241. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  8242. {
  8243. struct tg3 *tp = netdev_priv(dev);
  8244. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  8245. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  8246. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  8247. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  8248. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  8249. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  8250. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  8251. }
  8252. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  8253. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  8254. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  8255. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  8256. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  8257. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  8258. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  8259. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  8260. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  8261. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  8262. return -EINVAL;
  8263. /* No rx interrupts will be generated if both are zero */
  8264. if ((ec->rx_coalesce_usecs == 0) &&
  8265. (ec->rx_max_coalesced_frames == 0))
  8266. return -EINVAL;
  8267. /* No tx interrupts will be generated if both are zero */
  8268. if ((ec->tx_coalesce_usecs == 0) &&
  8269. (ec->tx_max_coalesced_frames == 0))
  8270. return -EINVAL;
  8271. /* Only copy relevant parameters, ignore all others. */
  8272. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  8273. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  8274. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  8275. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  8276. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  8277. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  8278. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  8279. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  8280. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  8281. if (netif_running(dev)) {
  8282. tg3_full_lock(tp, 0);
  8283. __tg3_set_coalesce(tp, &tp->coal);
  8284. tg3_full_unlock(tp);
  8285. }
  8286. return 0;
  8287. }
  8288. static const struct ethtool_ops tg3_ethtool_ops = {
  8289. .get_settings = tg3_get_settings,
  8290. .set_settings = tg3_set_settings,
  8291. .get_drvinfo = tg3_get_drvinfo,
  8292. .get_regs_len = tg3_get_regs_len,
  8293. .get_regs = tg3_get_regs,
  8294. .get_wol = tg3_get_wol,
  8295. .set_wol = tg3_set_wol,
  8296. .get_msglevel = tg3_get_msglevel,
  8297. .set_msglevel = tg3_set_msglevel,
  8298. .nway_reset = tg3_nway_reset,
  8299. .get_link = ethtool_op_get_link,
  8300. .get_eeprom_len = tg3_get_eeprom_len,
  8301. .get_eeprom = tg3_get_eeprom,
  8302. .set_eeprom = tg3_set_eeprom,
  8303. .get_ringparam = tg3_get_ringparam,
  8304. .set_ringparam = tg3_set_ringparam,
  8305. .get_pauseparam = tg3_get_pauseparam,
  8306. .set_pauseparam = tg3_set_pauseparam,
  8307. .get_rx_csum = tg3_get_rx_csum,
  8308. .set_rx_csum = tg3_set_rx_csum,
  8309. .set_tx_csum = tg3_set_tx_csum,
  8310. .set_sg = ethtool_op_set_sg,
  8311. .set_tso = tg3_set_tso,
  8312. .self_test = tg3_self_test,
  8313. .get_strings = tg3_get_strings,
  8314. .phys_id = tg3_phys_id,
  8315. .get_ethtool_stats = tg3_get_ethtool_stats,
  8316. .get_coalesce = tg3_get_coalesce,
  8317. .set_coalesce = tg3_set_coalesce,
  8318. .get_sset_count = tg3_get_sset_count,
  8319. };
  8320. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  8321. {
  8322. u32 cursize, val, magic;
  8323. tp->nvram_size = EEPROM_CHIP_SIZE;
  8324. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  8325. return;
  8326. if ((magic != TG3_EEPROM_MAGIC) &&
  8327. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  8328. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  8329. return;
  8330. /*
  8331. * Size the chip by reading offsets at increasing powers of two.
  8332. * When we encounter our validation signature, we know the addressing
  8333. * has wrapped around, and thus have our chip size.
  8334. */
  8335. cursize = 0x10;
  8336. while (cursize < tp->nvram_size) {
  8337. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  8338. return;
  8339. if (val == magic)
  8340. break;
  8341. cursize <<= 1;
  8342. }
  8343. tp->nvram_size = cursize;
  8344. }
  8345. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  8346. {
  8347. u32 val;
  8348. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  8349. return;
  8350. /* Selfboot format */
  8351. if (val != TG3_EEPROM_MAGIC) {
  8352. tg3_get_eeprom_size(tp);
  8353. return;
  8354. }
  8355. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  8356. if (val != 0) {
  8357. tp->nvram_size = (val >> 16) * 1024;
  8358. return;
  8359. }
  8360. }
  8361. tp->nvram_size = 0x80000;
  8362. }
  8363. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  8364. {
  8365. u32 nvcfg1;
  8366. nvcfg1 = tr32(NVRAM_CFG1);
  8367. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  8368. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8369. }
  8370. else {
  8371. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8372. tw32(NVRAM_CFG1, nvcfg1);
  8373. }
  8374. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  8375. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  8376. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  8377. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  8378. tp->nvram_jedecnum = JEDEC_ATMEL;
  8379. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  8380. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8381. break;
  8382. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  8383. tp->nvram_jedecnum = JEDEC_ATMEL;
  8384. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  8385. break;
  8386. case FLASH_VENDOR_ATMEL_EEPROM:
  8387. tp->nvram_jedecnum = JEDEC_ATMEL;
  8388. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8389. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8390. break;
  8391. case FLASH_VENDOR_ST:
  8392. tp->nvram_jedecnum = JEDEC_ST;
  8393. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  8394. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8395. break;
  8396. case FLASH_VENDOR_SAIFUN:
  8397. tp->nvram_jedecnum = JEDEC_SAIFUN;
  8398. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  8399. break;
  8400. case FLASH_VENDOR_SST_SMALL:
  8401. case FLASH_VENDOR_SST_LARGE:
  8402. tp->nvram_jedecnum = JEDEC_SST;
  8403. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  8404. break;
  8405. }
  8406. }
  8407. else {
  8408. tp->nvram_jedecnum = JEDEC_ATMEL;
  8409. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  8410. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8411. }
  8412. }
  8413. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  8414. {
  8415. u32 nvcfg1;
  8416. nvcfg1 = tr32(NVRAM_CFG1);
  8417. /* NVRAM protection for TPM */
  8418. if (nvcfg1 & (1 << 27))
  8419. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8420. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8421. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  8422. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  8423. tp->nvram_jedecnum = JEDEC_ATMEL;
  8424. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8425. break;
  8426. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8427. tp->nvram_jedecnum = JEDEC_ATMEL;
  8428. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8429. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8430. break;
  8431. case FLASH_5752VENDOR_ST_M45PE10:
  8432. case FLASH_5752VENDOR_ST_M45PE20:
  8433. case FLASH_5752VENDOR_ST_M45PE40:
  8434. tp->nvram_jedecnum = JEDEC_ST;
  8435. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8436. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8437. break;
  8438. }
  8439. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  8440. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  8441. case FLASH_5752PAGE_SIZE_256:
  8442. tp->nvram_pagesize = 256;
  8443. break;
  8444. case FLASH_5752PAGE_SIZE_512:
  8445. tp->nvram_pagesize = 512;
  8446. break;
  8447. case FLASH_5752PAGE_SIZE_1K:
  8448. tp->nvram_pagesize = 1024;
  8449. break;
  8450. case FLASH_5752PAGE_SIZE_2K:
  8451. tp->nvram_pagesize = 2048;
  8452. break;
  8453. case FLASH_5752PAGE_SIZE_4K:
  8454. tp->nvram_pagesize = 4096;
  8455. break;
  8456. case FLASH_5752PAGE_SIZE_264:
  8457. tp->nvram_pagesize = 264;
  8458. break;
  8459. }
  8460. }
  8461. else {
  8462. /* For eeprom, set pagesize to maximum eeprom size */
  8463. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8464. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8465. tw32(NVRAM_CFG1, nvcfg1);
  8466. }
  8467. }
  8468. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  8469. {
  8470. u32 nvcfg1, protect = 0;
  8471. nvcfg1 = tr32(NVRAM_CFG1);
  8472. /* NVRAM protection for TPM */
  8473. if (nvcfg1 & (1 << 27)) {
  8474. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8475. protect = 1;
  8476. }
  8477. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8478. switch (nvcfg1) {
  8479. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8480. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8481. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8482. case FLASH_5755VENDOR_ATMEL_FLASH_5:
  8483. tp->nvram_jedecnum = JEDEC_ATMEL;
  8484. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8485. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8486. tp->nvram_pagesize = 264;
  8487. if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
  8488. nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
  8489. tp->nvram_size = (protect ? 0x3e200 : 0x80000);
  8490. else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
  8491. tp->nvram_size = (protect ? 0x1f200 : 0x40000);
  8492. else
  8493. tp->nvram_size = (protect ? 0x1f200 : 0x20000);
  8494. break;
  8495. case FLASH_5752VENDOR_ST_M45PE10:
  8496. case FLASH_5752VENDOR_ST_M45PE20:
  8497. case FLASH_5752VENDOR_ST_M45PE40:
  8498. tp->nvram_jedecnum = JEDEC_ST;
  8499. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8500. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8501. tp->nvram_pagesize = 256;
  8502. if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
  8503. tp->nvram_size = (protect ? 0x10000 : 0x20000);
  8504. else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
  8505. tp->nvram_size = (protect ? 0x10000 : 0x40000);
  8506. else
  8507. tp->nvram_size = (protect ? 0x20000 : 0x80000);
  8508. break;
  8509. }
  8510. }
  8511. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8512. {
  8513. u32 nvcfg1;
  8514. nvcfg1 = tr32(NVRAM_CFG1);
  8515. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8516. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8517. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8518. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8519. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8520. tp->nvram_jedecnum = JEDEC_ATMEL;
  8521. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8522. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8523. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8524. tw32(NVRAM_CFG1, nvcfg1);
  8525. break;
  8526. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8527. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8528. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8529. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8530. tp->nvram_jedecnum = JEDEC_ATMEL;
  8531. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8532. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8533. tp->nvram_pagesize = 264;
  8534. break;
  8535. case FLASH_5752VENDOR_ST_M45PE10:
  8536. case FLASH_5752VENDOR_ST_M45PE20:
  8537. case FLASH_5752VENDOR_ST_M45PE40:
  8538. tp->nvram_jedecnum = JEDEC_ST;
  8539. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8540. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8541. tp->nvram_pagesize = 256;
  8542. break;
  8543. }
  8544. }
  8545. static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp)
  8546. {
  8547. u32 nvcfg1, protect = 0;
  8548. nvcfg1 = tr32(NVRAM_CFG1);
  8549. /* NVRAM protection for TPM */
  8550. if (nvcfg1 & (1 << 27)) {
  8551. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8552. protect = 1;
  8553. }
  8554. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8555. switch (nvcfg1) {
  8556. case FLASH_5761VENDOR_ATMEL_ADB021D:
  8557. case FLASH_5761VENDOR_ATMEL_ADB041D:
  8558. case FLASH_5761VENDOR_ATMEL_ADB081D:
  8559. case FLASH_5761VENDOR_ATMEL_ADB161D:
  8560. case FLASH_5761VENDOR_ATMEL_MDB021D:
  8561. case FLASH_5761VENDOR_ATMEL_MDB041D:
  8562. case FLASH_5761VENDOR_ATMEL_MDB081D:
  8563. case FLASH_5761VENDOR_ATMEL_MDB161D:
  8564. tp->nvram_jedecnum = JEDEC_ATMEL;
  8565. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8566. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8567. tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS;
  8568. tp->nvram_pagesize = 256;
  8569. break;
  8570. case FLASH_5761VENDOR_ST_A_M45PE20:
  8571. case FLASH_5761VENDOR_ST_A_M45PE40:
  8572. case FLASH_5761VENDOR_ST_A_M45PE80:
  8573. case FLASH_5761VENDOR_ST_A_M45PE16:
  8574. case FLASH_5761VENDOR_ST_M_M45PE20:
  8575. case FLASH_5761VENDOR_ST_M_M45PE40:
  8576. case FLASH_5761VENDOR_ST_M_M45PE80:
  8577. case FLASH_5761VENDOR_ST_M_M45PE16:
  8578. tp->nvram_jedecnum = JEDEC_ST;
  8579. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8580. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8581. tp->nvram_pagesize = 256;
  8582. break;
  8583. }
  8584. if (protect) {
  8585. tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT);
  8586. } else {
  8587. switch (nvcfg1) {
  8588. case FLASH_5761VENDOR_ATMEL_ADB161D:
  8589. case FLASH_5761VENDOR_ATMEL_MDB161D:
  8590. case FLASH_5761VENDOR_ST_A_M45PE16:
  8591. case FLASH_5761VENDOR_ST_M_M45PE16:
  8592. tp->nvram_size = 0x100000;
  8593. break;
  8594. case FLASH_5761VENDOR_ATMEL_ADB081D:
  8595. case FLASH_5761VENDOR_ATMEL_MDB081D:
  8596. case FLASH_5761VENDOR_ST_A_M45PE80:
  8597. case FLASH_5761VENDOR_ST_M_M45PE80:
  8598. tp->nvram_size = 0x80000;
  8599. break;
  8600. case FLASH_5761VENDOR_ATMEL_ADB041D:
  8601. case FLASH_5761VENDOR_ATMEL_MDB041D:
  8602. case FLASH_5761VENDOR_ST_A_M45PE40:
  8603. case FLASH_5761VENDOR_ST_M_M45PE40:
  8604. tp->nvram_size = 0x40000;
  8605. break;
  8606. case FLASH_5761VENDOR_ATMEL_ADB021D:
  8607. case FLASH_5761VENDOR_ATMEL_MDB021D:
  8608. case FLASH_5761VENDOR_ST_A_M45PE20:
  8609. case FLASH_5761VENDOR_ST_M_M45PE20:
  8610. tp->nvram_size = 0x20000;
  8611. break;
  8612. }
  8613. }
  8614. }
  8615. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8616. {
  8617. tp->nvram_jedecnum = JEDEC_ATMEL;
  8618. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8619. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8620. }
  8621. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8622. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8623. {
  8624. tw32_f(GRC_EEPROM_ADDR,
  8625. (EEPROM_ADDR_FSM_RESET |
  8626. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8627. EEPROM_ADDR_CLKPERD_SHIFT)));
  8628. msleep(1);
  8629. /* Enable seeprom accesses. */
  8630. tw32_f(GRC_LOCAL_CTRL,
  8631. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8632. udelay(100);
  8633. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8634. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8635. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8636. if (tg3_nvram_lock(tp)) {
  8637. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8638. "tg3_nvram_init failed.\n", tp->dev->name);
  8639. return;
  8640. }
  8641. tg3_enable_nvram_access(tp);
  8642. tp->nvram_size = 0;
  8643. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8644. tg3_get_5752_nvram_info(tp);
  8645. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8646. tg3_get_5755_nvram_info(tp);
  8647. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8648. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)
  8649. tg3_get_5787_nvram_info(tp);
  8650. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  8651. tg3_get_5761_nvram_info(tp);
  8652. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8653. tg3_get_5906_nvram_info(tp);
  8654. else
  8655. tg3_get_nvram_info(tp);
  8656. if (tp->nvram_size == 0)
  8657. tg3_get_nvram_size(tp);
  8658. tg3_disable_nvram_access(tp);
  8659. tg3_nvram_unlock(tp);
  8660. } else {
  8661. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8662. tg3_get_eeprom_size(tp);
  8663. }
  8664. }
  8665. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8666. u32 offset, u32 *val)
  8667. {
  8668. u32 tmp;
  8669. int i;
  8670. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8671. (offset % 4) != 0)
  8672. return -EINVAL;
  8673. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8674. EEPROM_ADDR_DEVID_MASK |
  8675. EEPROM_ADDR_READ);
  8676. tw32(GRC_EEPROM_ADDR,
  8677. tmp |
  8678. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8679. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8680. EEPROM_ADDR_ADDR_MASK) |
  8681. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8682. for (i = 0; i < 1000; i++) {
  8683. tmp = tr32(GRC_EEPROM_ADDR);
  8684. if (tmp & EEPROM_ADDR_COMPLETE)
  8685. break;
  8686. msleep(1);
  8687. }
  8688. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8689. return -EBUSY;
  8690. *val = tr32(GRC_EEPROM_DATA);
  8691. return 0;
  8692. }
  8693. #define NVRAM_CMD_TIMEOUT 10000
  8694. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8695. {
  8696. int i;
  8697. tw32(NVRAM_CMD, nvram_cmd);
  8698. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8699. udelay(10);
  8700. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8701. udelay(10);
  8702. break;
  8703. }
  8704. }
  8705. if (i == NVRAM_CMD_TIMEOUT) {
  8706. return -EBUSY;
  8707. }
  8708. return 0;
  8709. }
  8710. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8711. {
  8712. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8713. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8714. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8715. !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
  8716. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8717. addr = ((addr / tp->nvram_pagesize) <<
  8718. ATMEL_AT45DB0X1B_PAGE_POS) +
  8719. (addr % tp->nvram_pagesize);
  8720. return addr;
  8721. }
  8722. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8723. {
  8724. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8725. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8726. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8727. !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
  8728. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8729. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8730. tp->nvram_pagesize) +
  8731. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8732. return addr;
  8733. }
  8734. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8735. {
  8736. int ret;
  8737. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8738. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8739. offset = tg3_nvram_phys_addr(tp, offset);
  8740. if (offset > NVRAM_ADDR_MSK)
  8741. return -EINVAL;
  8742. ret = tg3_nvram_lock(tp);
  8743. if (ret)
  8744. return ret;
  8745. tg3_enable_nvram_access(tp);
  8746. tw32(NVRAM_ADDR, offset);
  8747. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8748. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8749. if (ret == 0)
  8750. *val = swab32(tr32(NVRAM_RDDATA));
  8751. tg3_disable_nvram_access(tp);
  8752. tg3_nvram_unlock(tp);
  8753. return ret;
  8754. }
  8755. static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val)
  8756. {
  8757. u32 v;
  8758. int res = tg3_nvram_read(tp, offset, &v);
  8759. if (!res)
  8760. *val = cpu_to_le32(v);
  8761. return res;
  8762. }
  8763. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8764. {
  8765. int err;
  8766. u32 tmp;
  8767. err = tg3_nvram_read(tp, offset, &tmp);
  8768. *val = swab32(tmp);
  8769. return err;
  8770. }
  8771. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8772. u32 offset, u32 len, u8 *buf)
  8773. {
  8774. int i, j, rc = 0;
  8775. u32 val;
  8776. for (i = 0; i < len; i += 4) {
  8777. u32 addr;
  8778. __le32 data;
  8779. addr = offset + i;
  8780. memcpy(&data, buf + i, 4);
  8781. tw32(GRC_EEPROM_DATA, le32_to_cpu(data));
  8782. val = tr32(GRC_EEPROM_ADDR);
  8783. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8784. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8785. EEPROM_ADDR_READ);
  8786. tw32(GRC_EEPROM_ADDR, val |
  8787. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8788. (addr & EEPROM_ADDR_ADDR_MASK) |
  8789. EEPROM_ADDR_START |
  8790. EEPROM_ADDR_WRITE);
  8791. for (j = 0; j < 1000; j++) {
  8792. val = tr32(GRC_EEPROM_ADDR);
  8793. if (val & EEPROM_ADDR_COMPLETE)
  8794. break;
  8795. msleep(1);
  8796. }
  8797. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8798. rc = -EBUSY;
  8799. break;
  8800. }
  8801. }
  8802. return rc;
  8803. }
  8804. /* offset and length are dword aligned */
  8805. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8806. u8 *buf)
  8807. {
  8808. int ret = 0;
  8809. u32 pagesize = tp->nvram_pagesize;
  8810. u32 pagemask = pagesize - 1;
  8811. u32 nvram_cmd;
  8812. u8 *tmp;
  8813. tmp = kmalloc(pagesize, GFP_KERNEL);
  8814. if (tmp == NULL)
  8815. return -ENOMEM;
  8816. while (len) {
  8817. int j;
  8818. u32 phy_addr, page_off, size;
  8819. phy_addr = offset & ~pagemask;
  8820. for (j = 0; j < pagesize; j += 4) {
  8821. if ((ret = tg3_nvram_read_le(tp, phy_addr + j,
  8822. (__le32 *) (tmp + j))))
  8823. break;
  8824. }
  8825. if (ret)
  8826. break;
  8827. page_off = offset & pagemask;
  8828. size = pagesize;
  8829. if (len < size)
  8830. size = len;
  8831. len -= size;
  8832. memcpy(tmp + page_off, buf, size);
  8833. offset = offset + (pagesize - page_off);
  8834. tg3_enable_nvram_access(tp);
  8835. /*
  8836. * Before we can erase the flash page, we need
  8837. * to issue a special "write enable" command.
  8838. */
  8839. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8840. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8841. break;
  8842. /* Erase the target page */
  8843. tw32(NVRAM_ADDR, phy_addr);
  8844. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8845. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8846. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8847. break;
  8848. /* Issue another write enable to start the write. */
  8849. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8850. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8851. break;
  8852. for (j = 0; j < pagesize; j += 4) {
  8853. __be32 data;
  8854. data = *((__be32 *) (tmp + j));
  8855. /* swab32(le32_to_cpu(data)), actually */
  8856. tw32(NVRAM_WRDATA, be32_to_cpu(data));
  8857. tw32(NVRAM_ADDR, phy_addr + j);
  8858. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8859. NVRAM_CMD_WR;
  8860. if (j == 0)
  8861. nvram_cmd |= NVRAM_CMD_FIRST;
  8862. else if (j == (pagesize - 4))
  8863. nvram_cmd |= NVRAM_CMD_LAST;
  8864. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8865. break;
  8866. }
  8867. if (ret)
  8868. break;
  8869. }
  8870. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8871. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8872. kfree(tmp);
  8873. return ret;
  8874. }
  8875. /* offset and length are dword aligned */
  8876. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8877. u8 *buf)
  8878. {
  8879. int i, ret = 0;
  8880. for (i = 0; i < len; i += 4, offset += 4) {
  8881. u32 page_off, phy_addr, nvram_cmd;
  8882. __be32 data;
  8883. memcpy(&data, buf + i, 4);
  8884. tw32(NVRAM_WRDATA, be32_to_cpu(data));
  8885. page_off = offset % tp->nvram_pagesize;
  8886. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8887. tw32(NVRAM_ADDR, phy_addr);
  8888. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8889. if ((page_off == 0) || (i == 0))
  8890. nvram_cmd |= NVRAM_CMD_FIRST;
  8891. if (page_off == (tp->nvram_pagesize - 4))
  8892. nvram_cmd |= NVRAM_CMD_LAST;
  8893. if (i == (len - 4))
  8894. nvram_cmd |= NVRAM_CMD_LAST;
  8895. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8896. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8897. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8898. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784) &&
  8899. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) &&
  8900. (tp->nvram_jedecnum == JEDEC_ST) &&
  8901. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8902. if ((ret = tg3_nvram_exec_cmd(tp,
  8903. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8904. NVRAM_CMD_DONE)))
  8905. break;
  8906. }
  8907. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8908. /* We always do complete word writes to eeprom. */
  8909. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8910. }
  8911. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8912. break;
  8913. }
  8914. return ret;
  8915. }
  8916. /* offset and length are dword aligned */
  8917. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8918. {
  8919. int ret;
  8920. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8921. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8922. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8923. udelay(40);
  8924. }
  8925. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8926. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8927. }
  8928. else {
  8929. u32 grc_mode;
  8930. ret = tg3_nvram_lock(tp);
  8931. if (ret)
  8932. return ret;
  8933. tg3_enable_nvram_access(tp);
  8934. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8935. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8936. tw32(NVRAM_WRITE1, 0x406);
  8937. grc_mode = tr32(GRC_MODE);
  8938. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8939. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8940. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8941. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8942. buf);
  8943. }
  8944. else {
  8945. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8946. buf);
  8947. }
  8948. grc_mode = tr32(GRC_MODE);
  8949. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8950. tg3_disable_nvram_access(tp);
  8951. tg3_nvram_unlock(tp);
  8952. }
  8953. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8954. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8955. udelay(40);
  8956. }
  8957. return ret;
  8958. }
  8959. struct subsys_tbl_ent {
  8960. u16 subsys_vendor, subsys_devid;
  8961. u32 phy_id;
  8962. };
  8963. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8964. /* Broadcom boards. */
  8965. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8966. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8967. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8968. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8969. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8970. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8971. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8972. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8973. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8974. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8975. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8976. /* 3com boards. */
  8977. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8978. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8979. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8980. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8981. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8982. /* DELL boards. */
  8983. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8984. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8985. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8986. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8987. /* Compaq boards. */
  8988. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8989. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8990. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8991. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8992. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8993. /* IBM boards. */
  8994. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8995. };
  8996. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8997. {
  8998. int i;
  8999. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  9000. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  9001. tp->pdev->subsystem_vendor) &&
  9002. (subsys_id_to_phy_id[i].subsys_devid ==
  9003. tp->pdev->subsystem_device))
  9004. return &subsys_id_to_phy_id[i];
  9005. }
  9006. return NULL;
  9007. }
  9008. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  9009. {
  9010. u32 val;
  9011. u16 pmcsr;
  9012. /* On some early chips the SRAM cannot be accessed in D3hot state,
  9013. * so need make sure we're in D0.
  9014. */
  9015. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  9016. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  9017. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  9018. msleep(1);
  9019. /* Make sure register accesses (indirect or otherwise)
  9020. * will function correctly.
  9021. */
  9022. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9023. tp->misc_host_ctrl);
  9024. /* The memory arbiter has to be enabled in order for SRAM accesses
  9025. * to succeed. Normally on powerup the tg3 chip firmware will make
  9026. * sure it is enabled, but other entities such as system netboot
  9027. * code might disable it.
  9028. */
  9029. val = tr32(MEMARB_MODE);
  9030. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  9031. tp->phy_id = PHY_ID_INVALID;
  9032. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9033. /* Assume an onboard device and WOL capable by default. */
  9034. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
  9035. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9036. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  9037. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9038. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  9039. }
  9040. val = tr32(VCPU_CFGSHDW);
  9041. if (val & VCPU_CFGSHDW_ASPM_DBNC)
  9042. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  9043. if ((val & VCPU_CFGSHDW_WOL_ENABLE) &&
  9044. (val & VCPU_CFGSHDW_WOL_MAGPKT))
  9045. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  9046. return;
  9047. }
  9048. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  9049. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  9050. u32 nic_cfg, led_cfg;
  9051. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  9052. int eeprom_phy_serdes = 0;
  9053. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  9054. tp->nic_sram_data_cfg = nic_cfg;
  9055. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  9056. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  9057. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  9058. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  9059. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  9060. (ver > 0) && (ver < 0x100))
  9061. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  9062. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  9063. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  9064. eeprom_phy_serdes = 1;
  9065. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  9066. if (nic_phy_id != 0) {
  9067. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  9068. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  9069. eeprom_phy_id = (id1 >> 16) << 10;
  9070. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  9071. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  9072. } else
  9073. eeprom_phy_id = 0;
  9074. tp->phy_id = eeprom_phy_id;
  9075. if (eeprom_phy_serdes) {
  9076. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  9077. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  9078. else
  9079. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9080. }
  9081. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  9082. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  9083. SHASTA_EXT_LED_MODE_MASK);
  9084. else
  9085. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  9086. switch (led_cfg) {
  9087. default:
  9088. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  9089. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9090. break;
  9091. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  9092. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  9093. break;
  9094. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  9095. tp->led_ctrl = LED_CTRL_MODE_MAC;
  9096. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  9097. * read on some older 5700/5701 bootcode.
  9098. */
  9099. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9100. ASIC_REV_5700 ||
  9101. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9102. ASIC_REV_5701)
  9103. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9104. break;
  9105. case SHASTA_EXT_LED_SHARED:
  9106. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  9107. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  9108. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  9109. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  9110. LED_CTRL_MODE_PHY_2);
  9111. break;
  9112. case SHASTA_EXT_LED_MAC:
  9113. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  9114. break;
  9115. case SHASTA_EXT_LED_COMBO:
  9116. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  9117. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  9118. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  9119. LED_CTRL_MODE_PHY_2);
  9120. break;
  9121. };
  9122. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9123. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  9124. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  9125. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  9126. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX)
  9127. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9128. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  9129. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  9130. if ((tp->pdev->subsystem_vendor ==
  9131. PCI_VENDOR_ID_ARIMA) &&
  9132. (tp->pdev->subsystem_device == 0x205a ||
  9133. tp->pdev->subsystem_device == 0x2063))
  9134. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9135. } else {
  9136. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9137. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  9138. }
  9139. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  9140. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  9141. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  9142. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  9143. }
  9144. if (nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE)
  9145. tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE;
  9146. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  9147. !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
  9148. tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
  9149. if (tp->tg3_flags & TG3_FLAG_WOL_CAP &&
  9150. nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)
  9151. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  9152. if (cfg2 & (1 << 17))
  9153. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  9154. /* serdes signal pre-emphasis in register 0x590 set by */
  9155. /* bootcode if bit 18 is set */
  9156. if (cfg2 & (1 << 18))
  9157. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  9158. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9159. u32 cfg3;
  9160. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3);
  9161. if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)
  9162. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  9163. }
  9164. }
  9165. }
  9166. static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd)
  9167. {
  9168. int i;
  9169. u32 val;
  9170. tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START);
  9171. tw32(OTP_CTRL, cmd);
  9172. /* Wait for up to 1 ms for command to execute. */
  9173. for (i = 0; i < 100; i++) {
  9174. val = tr32(OTP_STATUS);
  9175. if (val & OTP_STATUS_CMD_DONE)
  9176. break;
  9177. udelay(10);
  9178. }
  9179. return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY;
  9180. }
  9181. /* Read the gphy configuration from the OTP region of the chip. The gphy
  9182. * configuration is a 32-bit value that straddles the alignment boundary.
  9183. * We do two 32-bit reads and then shift and merge the results.
  9184. */
  9185. static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp)
  9186. {
  9187. u32 bhalf_otp, thalf_otp;
  9188. tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC);
  9189. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT))
  9190. return 0;
  9191. tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1);
  9192. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
  9193. return 0;
  9194. thalf_otp = tr32(OTP_READ_DATA);
  9195. tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2);
  9196. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
  9197. return 0;
  9198. bhalf_otp = tr32(OTP_READ_DATA);
  9199. return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16);
  9200. }
  9201. static int __devinit tg3_phy_probe(struct tg3 *tp)
  9202. {
  9203. u32 hw_phy_id_1, hw_phy_id_2;
  9204. u32 hw_phy_id, hw_phy_id_masked;
  9205. int err;
  9206. /* Reading the PHY ID register can conflict with ASF
  9207. * firwmare access to the PHY hardware.
  9208. */
  9209. err = 0;
  9210. if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
  9211. (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
  9212. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  9213. } else {
  9214. /* Now read the physical PHY_ID from the chip and verify
  9215. * that it is sane. If it doesn't look good, we fall back
  9216. * to either the hard-coded table based PHY_ID and failing
  9217. * that the value found in the eeprom area.
  9218. */
  9219. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  9220. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  9221. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  9222. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  9223. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  9224. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  9225. }
  9226. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  9227. tp->phy_id = hw_phy_id;
  9228. if (hw_phy_id_masked == PHY_ID_BCM8002)
  9229. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9230. else
  9231. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  9232. } else {
  9233. if (tp->phy_id != PHY_ID_INVALID) {
  9234. /* Do nothing, phy ID already set up in
  9235. * tg3_get_eeprom_hw_cfg().
  9236. */
  9237. } else {
  9238. struct subsys_tbl_ent *p;
  9239. /* No eeprom signature? Try the hardcoded
  9240. * subsys device table.
  9241. */
  9242. p = lookup_by_subsys(tp);
  9243. if (!p)
  9244. return -ENODEV;
  9245. tp->phy_id = p->phy_id;
  9246. if (!tp->phy_id ||
  9247. tp->phy_id == PHY_ID_BCM8002)
  9248. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9249. }
  9250. }
  9251. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  9252. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) &&
  9253. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  9254. u32 bmsr, adv_reg, tg3_ctrl, mask;
  9255. tg3_readphy(tp, MII_BMSR, &bmsr);
  9256. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  9257. (bmsr & BMSR_LSTATUS))
  9258. goto skip_phy_reset;
  9259. err = tg3_phy_reset(tp);
  9260. if (err)
  9261. return err;
  9262. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  9263. ADVERTISE_100HALF | ADVERTISE_100FULL |
  9264. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  9265. tg3_ctrl = 0;
  9266. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  9267. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  9268. MII_TG3_CTRL_ADV_1000_FULL);
  9269. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9270. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  9271. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  9272. MII_TG3_CTRL_ENABLE_AS_MASTER);
  9273. }
  9274. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9275. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9276. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  9277. if (!tg3_copper_is_advertising_all(tp, mask)) {
  9278. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  9279. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  9280. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  9281. tg3_writephy(tp, MII_BMCR,
  9282. BMCR_ANENABLE | BMCR_ANRESTART);
  9283. }
  9284. tg3_phy_set_wirespeed(tp);
  9285. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  9286. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  9287. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  9288. }
  9289. skip_phy_reset:
  9290. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  9291. err = tg3_init_5401phy_dsp(tp);
  9292. if (err)
  9293. return err;
  9294. }
  9295. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  9296. err = tg3_init_5401phy_dsp(tp);
  9297. }
  9298. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  9299. tp->link_config.advertising =
  9300. (ADVERTISED_1000baseT_Half |
  9301. ADVERTISED_1000baseT_Full |
  9302. ADVERTISED_Autoneg |
  9303. ADVERTISED_FIBRE);
  9304. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  9305. tp->link_config.advertising &=
  9306. ~(ADVERTISED_1000baseT_Half |
  9307. ADVERTISED_1000baseT_Full);
  9308. return err;
  9309. }
  9310. static void __devinit tg3_read_partno(struct tg3 *tp)
  9311. {
  9312. unsigned char vpd_data[256];
  9313. unsigned int i;
  9314. u32 magic;
  9315. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  9316. goto out_not_found;
  9317. if (magic == TG3_EEPROM_MAGIC) {
  9318. for (i = 0; i < 256; i += 4) {
  9319. u32 tmp;
  9320. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  9321. goto out_not_found;
  9322. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  9323. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  9324. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  9325. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  9326. }
  9327. } else {
  9328. int vpd_cap;
  9329. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  9330. for (i = 0; i < 256; i += 4) {
  9331. u32 tmp, j = 0;
  9332. __le32 v;
  9333. u16 tmp16;
  9334. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  9335. i);
  9336. while (j++ < 100) {
  9337. pci_read_config_word(tp->pdev, vpd_cap +
  9338. PCI_VPD_ADDR, &tmp16);
  9339. if (tmp16 & 0x8000)
  9340. break;
  9341. msleep(1);
  9342. }
  9343. if (!(tmp16 & 0x8000))
  9344. goto out_not_found;
  9345. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  9346. &tmp);
  9347. v = cpu_to_le32(tmp);
  9348. memcpy(&vpd_data[i], &v, 4);
  9349. }
  9350. }
  9351. /* Now parse and find the part number. */
  9352. for (i = 0; i < 254; ) {
  9353. unsigned char val = vpd_data[i];
  9354. unsigned int block_end;
  9355. if (val == 0x82 || val == 0x91) {
  9356. i = (i + 3 +
  9357. (vpd_data[i + 1] +
  9358. (vpd_data[i + 2] << 8)));
  9359. continue;
  9360. }
  9361. if (val != 0x90)
  9362. goto out_not_found;
  9363. block_end = (i + 3 +
  9364. (vpd_data[i + 1] +
  9365. (vpd_data[i + 2] << 8)));
  9366. i += 3;
  9367. if (block_end > 256)
  9368. goto out_not_found;
  9369. while (i < (block_end - 2)) {
  9370. if (vpd_data[i + 0] == 'P' &&
  9371. vpd_data[i + 1] == 'N') {
  9372. int partno_len = vpd_data[i + 2];
  9373. i += 3;
  9374. if (partno_len > 24 || (partno_len + i) > 256)
  9375. goto out_not_found;
  9376. memcpy(tp->board_part_number,
  9377. &vpd_data[i], partno_len);
  9378. /* Success. */
  9379. return;
  9380. }
  9381. i += 3 + vpd_data[i + 2];
  9382. }
  9383. /* Part number not found. */
  9384. goto out_not_found;
  9385. }
  9386. out_not_found:
  9387. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9388. strcpy(tp->board_part_number, "BCM95906");
  9389. else
  9390. strcpy(tp->board_part_number, "none");
  9391. }
  9392. static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset)
  9393. {
  9394. u32 val;
  9395. if (tg3_nvram_read_swab(tp, offset, &val) ||
  9396. (val & 0xfc000000) != 0x0c000000 ||
  9397. tg3_nvram_read_swab(tp, offset + 4, &val) ||
  9398. val != 0)
  9399. return 0;
  9400. return 1;
  9401. }
  9402. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  9403. {
  9404. u32 val, offset, start;
  9405. u32 ver_offset;
  9406. int i, bcnt;
  9407. if (tg3_nvram_read_swab(tp, 0, &val))
  9408. return;
  9409. if (val != TG3_EEPROM_MAGIC)
  9410. return;
  9411. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  9412. tg3_nvram_read_swab(tp, 0x4, &start))
  9413. return;
  9414. offset = tg3_nvram_logical_addr(tp, offset);
  9415. if (!tg3_fw_img_is_valid(tp, offset) ||
  9416. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  9417. return;
  9418. offset = offset + ver_offset - start;
  9419. for (i = 0; i < 16; i += 4) {
  9420. __le32 v;
  9421. if (tg3_nvram_read_le(tp, offset + i, &v))
  9422. return;
  9423. memcpy(tp->fw_ver + i, &v, 4);
  9424. }
  9425. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
  9426. (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  9427. return;
  9428. for (offset = TG3_NVM_DIR_START;
  9429. offset < TG3_NVM_DIR_END;
  9430. offset += TG3_NVM_DIRENT_SIZE) {
  9431. if (tg3_nvram_read_swab(tp, offset, &val))
  9432. return;
  9433. if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI)
  9434. break;
  9435. }
  9436. if (offset == TG3_NVM_DIR_END)
  9437. return;
  9438. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  9439. start = 0x08000000;
  9440. else if (tg3_nvram_read_swab(tp, offset - 4, &start))
  9441. return;
  9442. if (tg3_nvram_read_swab(tp, offset + 4, &offset) ||
  9443. !tg3_fw_img_is_valid(tp, offset) ||
  9444. tg3_nvram_read_swab(tp, offset + 8, &val))
  9445. return;
  9446. offset += val - start;
  9447. bcnt = strlen(tp->fw_ver);
  9448. tp->fw_ver[bcnt++] = ',';
  9449. tp->fw_ver[bcnt++] = ' ';
  9450. for (i = 0; i < 4; i++) {
  9451. __le32 v;
  9452. if (tg3_nvram_read_le(tp, offset, &v))
  9453. return;
  9454. offset += sizeof(v);
  9455. if (bcnt > TG3_VER_SIZE - sizeof(v)) {
  9456. memcpy(&tp->fw_ver[bcnt], &v, TG3_VER_SIZE - bcnt);
  9457. break;
  9458. }
  9459. memcpy(&tp->fw_ver[bcnt], &v, sizeof(v));
  9460. bcnt += sizeof(v);
  9461. }
  9462. tp->fw_ver[TG3_VER_SIZE - 1] = 0;
  9463. }
  9464. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
  9465. static int __devinit tg3_get_invariants(struct tg3 *tp)
  9466. {
  9467. static struct pci_device_id write_reorder_chipsets[] = {
  9468. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  9469. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  9470. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  9471. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  9472. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  9473. PCI_DEVICE_ID_VIA_8385_0) },
  9474. { },
  9475. };
  9476. u32 misc_ctrl_reg;
  9477. u32 cacheline_sz_reg;
  9478. u32 pci_state_reg, grc_misc_cfg;
  9479. u32 val;
  9480. u16 pci_cmd;
  9481. int err, pcie_cap;
  9482. /* Force memory write invalidate off. If we leave it on,
  9483. * then on 5700_BX chips we have to enable a workaround.
  9484. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  9485. * to match the cacheline size. The Broadcom driver have this
  9486. * workaround but turns MWI off all the times so never uses
  9487. * it. This seems to suggest that the workaround is insufficient.
  9488. */
  9489. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9490. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  9491. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9492. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  9493. * has the register indirect write enable bit set before
  9494. * we try to access any of the MMIO registers. It is also
  9495. * critical that the PCI-X hw workaround situation is decided
  9496. * before that as well.
  9497. */
  9498. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9499. &misc_ctrl_reg);
  9500. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  9501. MISC_HOST_CTRL_CHIPREV_SHIFT);
  9502. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) {
  9503. u32 prod_id_asic_rev;
  9504. pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV,
  9505. &prod_id_asic_rev);
  9506. tp->pci_chip_rev_id = prod_id_asic_rev & PROD_ID_ASIC_REV_MASK;
  9507. }
  9508. /* Wrong chip ID in 5752 A0. This code can be removed later
  9509. * as A0 is not in production.
  9510. */
  9511. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  9512. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  9513. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  9514. * we need to disable memory and use config. cycles
  9515. * only to access all registers. The 5702/03 chips
  9516. * can mistakenly decode the special cycles from the
  9517. * ICH chipsets as memory write cycles, causing corruption
  9518. * of register and memory space. Only certain ICH bridges
  9519. * will drive special cycles with non-zero data during the
  9520. * address phase which can fall within the 5703's address
  9521. * range. This is not an ICH bug as the PCI spec allows
  9522. * non-zero address during special cycles. However, only
  9523. * these ICH bridges are known to drive non-zero addresses
  9524. * during special cycles.
  9525. *
  9526. * Since special cycles do not cross PCI bridges, we only
  9527. * enable this workaround if the 5703 is on the secondary
  9528. * bus of these ICH bridges.
  9529. */
  9530. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  9531. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  9532. static struct tg3_dev_id {
  9533. u32 vendor;
  9534. u32 device;
  9535. u32 rev;
  9536. } ich_chipsets[] = {
  9537. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  9538. PCI_ANY_ID },
  9539. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  9540. PCI_ANY_ID },
  9541. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  9542. 0xa },
  9543. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  9544. PCI_ANY_ID },
  9545. { },
  9546. };
  9547. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  9548. struct pci_dev *bridge = NULL;
  9549. while (pci_id->vendor != 0) {
  9550. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  9551. bridge);
  9552. if (!bridge) {
  9553. pci_id++;
  9554. continue;
  9555. }
  9556. if (pci_id->rev != PCI_ANY_ID) {
  9557. if (bridge->revision > pci_id->rev)
  9558. continue;
  9559. }
  9560. if (bridge->subordinate &&
  9561. (bridge->subordinate->number ==
  9562. tp->pdev->bus->number)) {
  9563. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  9564. pci_dev_put(bridge);
  9565. break;
  9566. }
  9567. }
  9568. }
  9569. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  9570. static struct tg3_dev_id {
  9571. u32 vendor;
  9572. u32 device;
  9573. } bridge_chipsets[] = {
  9574. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 },
  9575. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 },
  9576. { },
  9577. };
  9578. struct tg3_dev_id *pci_id = &bridge_chipsets[0];
  9579. struct pci_dev *bridge = NULL;
  9580. while (pci_id->vendor != 0) {
  9581. bridge = pci_get_device(pci_id->vendor,
  9582. pci_id->device,
  9583. bridge);
  9584. if (!bridge) {
  9585. pci_id++;
  9586. continue;
  9587. }
  9588. if (bridge->subordinate &&
  9589. (bridge->subordinate->number <=
  9590. tp->pdev->bus->number) &&
  9591. (bridge->subordinate->subordinate >=
  9592. tp->pdev->bus->number)) {
  9593. tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG;
  9594. pci_dev_put(bridge);
  9595. break;
  9596. }
  9597. }
  9598. }
  9599. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  9600. * DMA addresses > 40-bit. This bridge may have other additional
  9601. * 57xx devices behind it in some 4-port NIC designs for example.
  9602. * Any tg3 device found behind the bridge will also need the 40-bit
  9603. * DMA workaround.
  9604. */
  9605. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  9606. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9607. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  9608. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  9609. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  9610. }
  9611. else {
  9612. struct pci_dev *bridge = NULL;
  9613. do {
  9614. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  9615. PCI_DEVICE_ID_SERVERWORKS_EPB,
  9616. bridge);
  9617. if (bridge && bridge->subordinate &&
  9618. (bridge->subordinate->number <=
  9619. tp->pdev->bus->number) &&
  9620. (bridge->subordinate->subordinate >=
  9621. tp->pdev->bus->number)) {
  9622. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  9623. pci_dev_put(bridge);
  9624. break;
  9625. }
  9626. } while (bridge);
  9627. }
  9628. /* Initialize misc host control in PCI block. */
  9629. tp->misc_host_ctrl |= (misc_ctrl_reg &
  9630. MISC_HOST_CTRL_CHIPREV);
  9631. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9632. tp->misc_host_ctrl);
  9633. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9634. &cacheline_sz_reg);
  9635. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  9636. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  9637. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  9638. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  9639. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9640. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  9641. tp->pdev_peer = tg3_find_peer(tp);
  9642. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9643. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9644. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9645. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9646. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9647. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  9648. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  9649. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9650. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  9651. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  9652. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  9653. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  9654. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  9655. tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
  9656. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
  9657. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
  9658. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
  9659. tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
  9660. tp->pdev_peer == tp->pdev))
  9661. tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
  9662. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9663. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9664. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9665. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  9666. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9667. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  9668. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  9669. } else {
  9670. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  9671. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9672. ASIC_REV_5750 &&
  9673. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  9674. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  9675. }
  9676. }
  9677. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  9678. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  9679. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  9680. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  9681. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  9682. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 &&
  9683. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761 &&
  9684. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9685. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  9686. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  9687. if (pcie_cap != 0) {
  9688. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  9689. pcie_set_readrq(tp->pdev, 4096);
  9690. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9691. u16 lnkctl;
  9692. pci_read_config_word(tp->pdev,
  9693. pcie_cap + PCI_EXP_LNKCTL,
  9694. &lnkctl);
  9695. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  9696. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  9697. }
  9698. }
  9699. /* If we have an AMD 762 or VIA K8T800 chipset, write
  9700. * reordering to the mailbox registers done by the host
  9701. * controller can cause major troubles. We read back from
  9702. * every mailbox register write to force the writes to be
  9703. * posted to the chip in order.
  9704. */
  9705. if (pci_dev_present(write_reorder_chipsets) &&
  9706. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9707. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  9708. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9709. tp->pci_lat_timer < 64) {
  9710. tp->pci_lat_timer = 64;
  9711. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  9712. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  9713. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  9714. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  9715. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9716. cacheline_sz_reg);
  9717. }
  9718. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  9719. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9720. tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX);
  9721. if (!tp->pcix_cap) {
  9722. printk(KERN_ERR PFX "Cannot find PCI-X "
  9723. "capability, aborting.\n");
  9724. return -EIO;
  9725. }
  9726. }
  9727. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9728. &pci_state_reg);
  9729. if (tp->pcix_cap && (pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  9730. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  9731. /* If this is a 5700 BX chipset, and we are in PCI-X
  9732. * mode, enable register write workaround.
  9733. *
  9734. * The workaround is to use indirect register accesses
  9735. * for all chip writes not to mailbox registers.
  9736. */
  9737. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  9738. u32 pm_reg;
  9739. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9740. /* The chip can have it's power management PCI config
  9741. * space registers clobbered due to this bug.
  9742. * So explicitly force the chip into D0 here.
  9743. */
  9744. pci_read_config_dword(tp->pdev,
  9745. tp->pm_cap + PCI_PM_CTRL,
  9746. &pm_reg);
  9747. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9748. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9749. pci_write_config_dword(tp->pdev,
  9750. tp->pm_cap + PCI_PM_CTRL,
  9751. pm_reg);
  9752. /* Also, force SERR#/PERR# in PCI command. */
  9753. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9754. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9755. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9756. }
  9757. }
  9758. /* 5700 BX chips need to have their TX producer index mailboxes
  9759. * written twice to workaround a bug.
  9760. */
  9761. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9762. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9763. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9764. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9765. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9766. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9767. /* Chip-specific fixup from Broadcom driver */
  9768. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9769. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9770. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9771. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9772. }
  9773. /* Default fast path register access methods */
  9774. tp->read32 = tg3_read32;
  9775. tp->write32 = tg3_write32;
  9776. tp->read32_mbox = tg3_read32;
  9777. tp->write32_mbox = tg3_write32;
  9778. tp->write32_tx_mbox = tg3_write32;
  9779. tp->write32_rx_mbox = tg3_write32;
  9780. /* Various workaround register access methods */
  9781. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9782. tp->write32 = tg3_write_indirect_reg32;
  9783. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9784. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9785. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
  9786. /*
  9787. * Back to back register writes can cause problems on these
  9788. * chips, the workaround is to read back all reg writes
  9789. * except those to mailbox regs.
  9790. *
  9791. * See tg3_write_indirect_reg32().
  9792. */
  9793. tp->write32 = tg3_write_flush_reg32;
  9794. }
  9795. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9796. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9797. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9798. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9799. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9800. }
  9801. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9802. tp->read32 = tg3_read_indirect_reg32;
  9803. tp->write32 = tg3_write_indirect_reg32;
  9804. tp->read32_mbox = tg3_read_indirect_mbox;
  9805. tp->write32_mbox = tg3_write_indirect_mbox;
  9806. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9807. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9808. iounmap(tp->regs);
  9809. tp->regs = NULL;
  9810. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9811. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9812. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9813. }
  9814. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9815. tp->read32_mbox = tg3_read32_mbox_5906;
  9816. tp->write32_mbox = tg3_write32_mbox_5906;
  9817. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9818. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9819. }
  9820. if (tp->write32 == tg3_write_indirect_reg32 ||
  9821. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9822. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9823. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9824. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9825. /* Get eeprom hw config before calling tg3_set_power_state().
  9826. * In particular, the TG3_FLG2_IS_NIC flag must be
  9827. * determined before calling tg3_set_power_state() so that
  9828. * we know whether or not to switch out of Vaux power.
  9829. * When the flag is set, it means that GPIO1 is used for eeprom
  9830. * write protect and also implies that it is a LOM where GPIOs
  9831. * are not used to switch power.
  9832. */
  9833. tg3_get_eeprom_hw_cfg(tp);
  9834. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  9835. /* Allow reads and writes to the
  9836. * APE register and memory space.
  9837. */
  9838. pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  9839. PCISTATE_ALLOW_APE_SHMEM_WR;
  9840. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9841. pci_state_reg);
  9842. }
  9843. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9844. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  9845. tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT;
  9846. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  9847. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1 ||
  9848. tp->pci_chip_rev_id == CHIPREV_ID_5761_A0 ||
  9849. tp->pci_chip_rev_id == CHIPREV_ID_5761_A1)
  9850. tp->tg3_flags3 |= TG3_FLG3_5761_5784_AX_FIXES;
  9851. }
  9852. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9853. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9854. * It is also used as eeprom write protect on LOMs.
  9855. */
  9856. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9857. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9858. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9859. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9860. GRC_LCLCTRL_GPIO_OUTPUT1);
  9861. /* Unused GPIO3 must be driven as output on 5752 because there
  9862. * are no pull-up resistors on unused GPIO pins.
  9863. */
  9864. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9865. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9866. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9867. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9868. /* Force the chip into D0. */
  9869. err = tg3_set_power_state(tp, PCI_D0);
  9870. if (err) {
  9871. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9872. pci_name(tp->pdev));
  9873. return err;
  9874. }
  9875. /* 5700 B0 chips do not support checksumming correctly due
  9876. * to hardware bugs.
  9877. */
  9878. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9879. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9880. /* Derive initial jumbo mode from MTU assigned in
  9881. * ether_setup() via the alloc_etherdev() call
  9882. */
  9883. if (tp->dev->mtu > ETH_DATA_LEN &&
  9884. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9885. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9886. /* Determine WakeOnLan speed to use. */
  9887. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9888. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9889. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9890. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9891. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9892. } else {
  9893. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9894. }
  9895. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9896. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9897. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9898. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9899. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9900. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9901. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9902. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9903. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9904. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9905. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9906. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9907. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9908. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9909. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9910. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9911. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9912. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  9913. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9914. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9915. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9916. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9917. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9918. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9919. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9920. }
  9921. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
  9922. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
  9923. tp->phy_otp = tg3_read_otp_phycfg(tp);
  9924. if (tp->phy_otp == 0)
  9925. tp->phy_otp = TG3_OTP_DEFAULT;
  9926. }
  9927. tp->coalesce_mode = 0;
  9928. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9929. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9930. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9931. /* Initialize MAC MI mode, polling disabled. */
  9932. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9933. udelay(80);
  9934. /* Initialize data/descriptor byte/word swapping. */
  9935. val = tr32(GRC_MODE);
  9936. val &= GRC_MODE_HOST_STACKUP;
  9937. tw32(GRC_MODE, val | tp->grc_mode);
  9938. tg3_switch_clocks(tp);
  9939. /* Clear this out for sanity. */
  9940. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9941. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9942. &pci_state_reg);
  9943. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9944. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9945. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9946. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9947. chiprevid == CHIPREV_ID_5701_B0 ||
  9948. chiprevid == CHIPREV_ID_5701_B2 ||
  9949. chiprevid == CHIPREV_ID_5701_B5) {
  9950. void __iomem *sram_base;
  9951. /* Write some dummy words into the SRAM status block
  9952. * area, see if it reads back correctly. If the return
  9953. * value is bad, force enable the PCIX workaround.
  9954. */
  9955. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9956. writel(0x00000000, sram_base);
  9957. writel(0x00000000, sram_base + 4);
  9958. writel(0xffffffff, sram_base + 4);
  9959. if (readl(sram_base) != 0x00000000)
  9960. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9961. }
  9962. }
  9963. udelay(50);
  9964. tg3_nvram_init(tp);
  9965. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9966. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9967. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9968. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9969. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9970. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9971. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9972. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9973. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9974. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9975. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9976. HOSTCC_MODE_CLRTICK_TXBD);
  9977. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9978. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9979. tp->misc_host_ctrl);
  9980. }
  9981. /* these are limited to 10/100 only */
  9982. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9983. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9984. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9985. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9986. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9987. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9988. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9989. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9990. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9991. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9992. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9993. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9994. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9995. err = tg3_phy_probe(tp);
  9996. if (err) {
  9997. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9998. pci_name(tp->pdev), err);
  9999. /* ... but do not return immediately ... */
  10000. }
  10001. tg3_read_partno(tp);
  10002. tg3_read_fw_ver(tp);
  10003. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  10004. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  10005. } else {
  10006. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  10007. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  10008. else
  10009. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  10010. }
  10011. /* 5700 {AX,BX} chips have a broken status block link
  10012. * change bit implementation, so we must use the
  10013. * status register in those cases.
  10014. */
  10015. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  10016. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  10017. else
  10018. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  10019. /* The led_ctrl is set during tg3_phy_probe, here we might
  10020. * have to force the link status polling mechanism based
  10021. * upon subsystem IDs.
  10022. */
  10023. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  10024. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  10025. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  10026. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  10027. TG3_FLAG_USE_LINKCHG_REG);
  10028. }
  10029. /* For all SERDES we poll the MAC status register. */
  10030. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  10031. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  10032. else
  10033. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  10034. /* All chips before 5787 can get confused if TX buffers
  10035. * straddle the 4GB address boundary in some cases.
  10036. */
  10037. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10038. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  10039. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  10040. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  10041. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10042. tp->dev->hard_start_xmit = tg3_start_xmit;
  10043. else
  10044. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  10045. tp->rx_offset = 2;
  10046. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  10047. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  10048. tp->rx_offset = 0;
  10049. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  10050. /* Increment the rx prod index on the rx std ring by at most
  10051. * 8 for these chips to workaround hw errata.
  10052. */
  10053. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  10054. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  10055. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  10056. tp->rx_std_max_post = 8;
  10057. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND)
  10058. tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) &
  10059. PCIE_PWR_MGMT_L1_THRESH_MSK;
  10060. return err;
  10061. }
  10062. #ifdef CONFIG_SPARC
  10063. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  10064. {
  10065. struct net_device *dev = tp->dev;
  10066. struct pci_dev *pdev = tp->pdev;
  10067. struct device_node *dp = pci_device_to_OF_node(pdev);
  10068. const unsigned char *addr;
  10069. int len;
  10070. addr = of_get_property(dp, "local-mac-address", &len);
  10071. if (addr && len == 6) {
  10072. memcpy(dev->dev_addr, addr, 6);
  10073. memcpy(dev->perm_addr, dev->dev_addr, 6);
  10074. return 0;
  10075. }
  10076. return -ENODEV;
  10077. }
  10078. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  10079. {
  10080. struct net_device *dev = tp->dev;
  10081. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  10082. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  10083. return 0;
  10084. }
  10085. #endif
  10086. static int __devinit tg3_get_device_address(struct tg3 *tp)
  10087. {
  10088. struct net_device *dev = tp->dev;
  10089. u32 hi, lo, mac_offset;
  10090. int addr_ok = 0;
  10091. #ifdef CONFIG_SPARC
  10092. if (!tg3_get_macaddr_sparc(tp))
  10093. return 0;
  10094. #endif
  10095. mac_offset = 0x7c;
  10096. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  10097. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  10098. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  10099. mac_offset = 0xcc;
  10100. if (tg3_nvram_lock(tp))
  10101. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  10102. else
  10103. tg3_nvram_unlock(tp);
  10104. }
  10105. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10106. mac_offset = 0x10;
  10107. /* First try to get it from MAC address mailbox. */
  10108. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  10109. if ((hi >> 16) == 0x484b) {
  10110. dev->dev_addr[0] = (hi >> 8) & 0xff;
  10111. dev->dev_addr[1] = (hi >> 0) & 0xff;
  10112. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  10113. dev->dev_addr[2] = (lo >> 24) & 0xff;
  10114. dev->dev_addr[3] = (lo >> 16) & 0xff;
  10115. dev->dev_addr[4] = (lo >> 8) & 0xff;
  10116. dev->dev_addr[5] = (lo >> 0) & 0xff;
  10117. /* Some old bootcode may report a 0 MAC address in SRAM */
  10118. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  10119. }
  10120. if (!addr_ok) {
  10121. /* Next, try NVRAM. */
  10122. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  10123. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  10124. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  10125. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  10126. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  10127. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  10128. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  10129. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  10130. }
  10131. /* Finally just fetch it out of the MAC control regs. */
  10132. else {
  10133. hi = tr32(MAC_ADDR_0_HIGH);
  10134. lo = tr32(MAC_ADDR_0_LOW);
  10135. dev->dev_addr[5] = lo & 0xff;
  10136. dev->dev_addr[4] = (lo >> 8) & 0xff;
  10137. dev->dev_addr[3] = (lo >> 16) & 0xff;
  10138. dev->dev_addr[2] = (lo >> 24) & 0xff;
  10139. dev->dev_addr[1] = hi & 0xff;
  10140. dev->dev_addr[0] = (hi >> 8) & 0xff;
  10141. }
  10142. }
  10143. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  10144. #ifdef CONFIG_SPARC
  10145. if (!tg3_get_default_macaddr_sparc(tp))
  10146. return 0;
  10147. #endif
  10148. return -EINVAL;
  10149. }
  10150. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  10151. return 0;
  10152. }
  10153. #define BOUNDARY_SINGLE_CACHELINE 1
  10154. #define BOUNDARY_MULTI_CACHELINE 2
  10155. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  10156. {
  10157. int cacheline_size;
  10158. u8 byte;
  10159. int goal;
  10160. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  10161. if (byte == 0)
  10162. cacheline_size = 1024;
  10163. else
  10164. cacheline_size = (int) byte * 4;
  10165. /* On 5703 and later chips, the boundary bits have no
  10166. * effect.
  10167. */
  10168. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  10169. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  10170. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  10171. goto out;
  10172. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  10173. goal = BOUNDARY_MULTI_CACHELINE;
  10174. #else
  10175. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  10176. goal = BOUNDARY_SINGLE_CACHELINE;
  10177. #else
  10178. goal = 0;
  10179. #endif
  10180. #endif
  10181. if (!goal)
  10182. goto out;
  10183. /* PCI controllers on most RISC systems tend to disconnect
  10184. * when a device tries to burst across a cache-line boundary.
  10185. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  10186. *
  10187. * Unfortunately, for PCI-E there are only limited
  10188. * write-side controls for this, and thus for reads
  10189. * we will still get the disconnects. We'll also waste
  10190. * these PCI cycles for both read and write for chips
  10191. * other than 5700 and 5701 which do not implement the
  10192. * boundary bits.
  10193. */
  10194. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  10195. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  10196. switch (cacheline_size) {
  10197. case 16:
  10198. case 32:
  10199. case 64:
  10200. case 128:
  10201. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10202. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  10203. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  10204. } else {
  10205. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  10206. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  10207. }
  10208. break;
  10209. case 256:
  10210. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  10211. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  10212. break;
  10213. default:
  10214. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  10215. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  10216. break;
  10217. };
  10218. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10219. switch (cacheline_size) {
  10220. case 16:
  10221. case 32:
  10222. case 64:
  10223. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10224. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  10225. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  10226. break;
  10227. }
  10228. /* fallthrough */
  10229. case 128:
  10230. default:
  10231. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  10232. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  10233. break;
  10234. };
  10235. } else {
  10236. switch (cacheline_size) {
  10237. case 16:
  10238. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10239. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  10240. DMA_RWCTRL_WRITE_BNDRY_16);
  10241. break;
  10242. }
  10243. /* fallthrough */
  10244. case 32:
  10245. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10246. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  10247. DMA_RWCTRL_WRITE_BNDRY_32);
  10248. break;
  10249. }
  10250. /* fallthrough */
  10251. case 64:
  10252. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10253. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  10254. DMA_RWCTRL_WRITE_BNDRY_64);
  10255. break;
  10256. }
  10257. /* fallthrough */
  10258. case 128:
  10259. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10260. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  10261. DMA_RWCTRL_WRITE_BNDRY_128);
  10262. break;
  10263. }
  10264. /* fallthrough */
  10265. case 256:
  10266. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  10267. DMA_RWCTRL_WRITE_BNDRY_256);
  10268. break;
  10269. case 512:
  10270. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  10271. DMA_RWCTRL_WRITE_BNDRY_512);
  10272. break;
  10273. case 1024:
  10274. default:
  10275. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  10276. DMA_RWCTRL_WRITE_BNDRY_1024);
  10277. break;
  10278. };
  10279. }
  10280. out:
  10281. return val;
  10282. }
  10283. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  10284. {
  10285. struct tg3_internal_buffer_desc test_desc;
  10286. u32 sram_dma_descs;
  10287. int i, ret;
  10288. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  10289. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  10290. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  10291. tw32(RDMAC_STATUS, 0);
  10292. tw32(WDMAC_STATUS, 0);
  10293. tw32(BUFMGR_MODE, 0);
  10294. tw32(FTQ_RESET, 0);
  10295. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  10296. test_desc.addr_lo = buf_dma & 0xffffffff;
  10297. test_desc.nic_mbuf = 0x00002100;
  10298. test_desc.len = size;
  10299. /*
  10300. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  10301. * the *second* time the tg3 driver was getting loaded after an
  10302. * initial scan.
  10303. *
  10304. * Broadcom tells me:
  10305. * ...the DMA engine is connected to the GRC block and a DMA
  10306. * reset may affect the GRC block in some unpredictable way...
  10307. * The behavior of resets to individual blocks has not been tested.
  10308. *
  10309. * Broadcom noted the GRC reset will also reset all sub-components.
  10310. */
  10311. if (to_device) {
  10312. test_desc.cqid_sqid = (13 << 8) | 2;
  10313. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  10314. udelay(40);
  10315. } else {
  10316. test_desc.cqid_sqid = (16 << 8) | 7;
  10317. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  10318. udelay(40);
  10319. }
  10320. test_desc.flags = 0x00000005;
  10321. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  10322. u32 val;
  10323. val = *(((u32 *)&test_desc) + i);
  10324. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  10325. sram_dma_descs + (i * sizeof(u32)));
  10326. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  10327. }
  10328. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  10329. if (to_device) {
  10330. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  10331. } else {
  10332. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  10333. }
  10334. ret = -ENODEV;
  10335. for (i = 0; i < 40; i++) {
  10336. u32 val;
  10337. if (to_device)
  10338. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  10339. else
  10340. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  10341. if ((val & 0xffff) == sram_dma_descs) {
  10342. ret = 0;
  10343. break;
  10344. }
  10345. udelay(100);
  10346. }
  10347. return ret;
  10348. }
  10349. #define TEST_BUFFER_SIZE 0x2000
  10350. static int __devinit tg3_test_dma(struct tg3 *tp)
  10351. {
  10352. dma_addr_t buf_dma;
  10353. u32 *buf, saved_dma_rwctrl;
  10354. int ret;
  10355. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  10356. if (!buf) {
  10357. ret = -ENOMEM;
  10358. goto out_nofree;
  10359. }
  10360. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  10361. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  10362. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  10363. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10364. /* DMA read watermark not used on PCIE */
  10365. tp->dma_rwctrl |= 0x00180000;
  10366. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  10367. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  10368. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  10369. tp->dma_rwctrl |= 0x003f0000;
  10370. else
  10371. tp->dma_rwctrl |= 0x003f000f;
  10372. } else {
  10373. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  10374. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  10375. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  10376. u32 read_water = 0x7;
  10377. /* If the 5704 is behind the EPB bridge, we can
  10378. * do the less restrictive ONE_DMA workaround for
  10379. * better performance.
  10380. */
  10381. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  10382. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  10383. tp->dma_rwctrl |= 0x8000;
  10384. else if (ccval == 0x6 || ccval == 0x7)
  10385. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  10386. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  10387. read_water = 4;
  10388. /* Set bit 23 to enable PCIX hw bug fix */
  10389. tp->dma_rwctrl |=
  10390. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  10391. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  10392. (1 << 23);
  10393. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  10394. /* 5780 always in PCIX mode */
  10395. tp->dma_rwctrl |= 0x00144000;
  10396. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  10397. /* 5714 always in PCIX mode */
  10398. tp->dma_rwctrl |= 0x00148000;
  10399. } else {
  10400. tp->dma_rwctrl |= 0x001b000f;
  10401. }
  10402. }
  10403. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  10404. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  10405. tp->dma_rwctrl &= 0xfffffff0;
  10406. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10407. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  10408. /* Remove this if it causes problems for some boards. */
  10409. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  10410. /* On 5700/5701 chips, we need to set this bit.
  10411. * Otherwise the chip will issue cacheline transactions
  10412. * to streamable DMA memory with not all the byte
  10413. * enables turned on. This is an error on several
  10414. * RISC PCI controllers, in particular sparc64.
  10415. *
  10416. * On 5703/5704 chips, this bit has been reassigned
  10417. * a different meaning. In particular, it is used
  10418. * on those chips to enable a PCI-X workaround.
  10419. */
  10420. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  10421. }
  10422. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10423. #if 0
  10424. /* Unneeded, already done by tg3_get_invariants. */
  10425. tg3_switch_clocks(tp);
  10426. #endif
  10427. ret = 0;
  10428. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  10429. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  10430. goto out;
  10431. /* It is best to perform DMA test with maximum write burst size
  10432. * to expose the 5700/5701 write DMA bug.
  10433. */
  10434. saved_dma_rwctrl = tp->dma_rwctrl;
  10435. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10436. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10437. while (1) {
  10438. u32 *p = buf, i;
  10439. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  10440. p[i] = i;
  10441. /* Send the buffer to the chip. */
  10442. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  10443. if (ret) {
  10444. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  10445. break;
  10446. }
  10447. #if 0
  10448. /* validate data reached card RAM correctly. */
  10449. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  10450. u32 val;
  10451. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  10452. if (le32_to_cpu(val) != p[i]) {
  10453. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  10454. /* ret = -ENODEV here? */
  10455. }
  10456. p[i] = 0;
  10457. }
  10458. #endif
  10459. /* Now read it back. */
  10460. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  10461. if (ret) {
  10462. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  10463. break;
  10464. }
  10465. /* Verify it. */
  10466. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  10467. if (p[i] == i)
  10468. continue;
  10469. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  10470. DMA_RWCTRL_WRITE_BNDRY_16) {
  10471. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10472. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  10473. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10474. break;
  10475. } else {
  10476. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  10477. ret = -ENODEV;
  10478. goto out;
  10479. }
  10480. }
  10481. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  10482. /* Success. */
  10483. ret = 0;
  10484. break;
  10485. }
  10486. }
  10487. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  10488. DMA_RWCTRL_WRITE_BNDRY_16) {
  10489. static struct pci_device_id dma_wait_state_chipsets[] = {
  10490. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  10491. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  10492. { },
  10493. };
  10494. /* DMA test passed without adjusting DMA boundary,
  10495. * now look for chipsets that are known to expose the
  10496. * DMA bug without failing the test.
  10497. */
  10498. if (pci_dev_present(dma_wait_state_chipsets)) {
  10499. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10500. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  10501. }
  10502. else
  10503. /* Safe to use the calculated DMA boundary. */
  10504. tp->dma_rwctrl = saved_dma_rwctrl;
  10505. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10506. }
  10507. out:
  10508. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  10509. out_nofree:
  10510. return ret;
  10511. }
  10512. static void __devinit tg3_init_link_config(struct tg3 *tp)
  10513. {
  10514. tp->link_config.advertising =
  10515. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  10516. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  10517. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  10518. ADVERTISED_Autoneg | ADVERTISED_MII);
  10519. tp->link_config.speed = SPEED_INVALID;
  10520. tp->link_config.duplex = DUPLEX_INVALID;
  10521. tp->link_config.autoneg = AUTONEG_ENABLE;
  10522. tp->link_config.active_speed = SPEED_INVALID;
  10523. tp->link_config.active_duplex = DUPLEX_INVALID;
  10524. tp->link_config.phy_is_low_power = 0;
  10525. tp->link_config.orig_speed = SPEED_INVALID;
  10526. tp->link_config.orig_duplex = DUPLEX_INVALID;
  10527. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  10528. }
  10529. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  10530. {
  10531. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  10532. tp->bufmgr_config.mbuf_read_dma_low_water =
  10533. DEFAULT_MB_RDMA_LOW_WATER_5705;
  10534. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10535. DEFAULT_MB_MACRX_LOW_WATER_5705;
  10536. tp->bufmgr_config.mbuf_high_water =
  10537. DEFAULT_MB_HIGH_WATER_5705;
  10538. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  10539. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10540. DEFAULT_MB_MACRX_LOW_WATER_5906;
  10541. tp->bufmgr_config.mbuf_high_water =
  10542. DEFAULT_MB_HIGH_WATER_5906;
  10543. }
  10544. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  10545. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  10546. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  10547. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  10548. tp->bufmgr_config.mbuf_high_water_jumbo =
  10549. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  10550. } else {
  10551. tp->bufmgr_config.mbuf_read_dma_low_water =
  10552. DEFAULT_MB_RDMA_LOW_WATER;
  10553. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10554. DEFAULT_MB_MACRX_LOW_WATER;
  10555. tp->bufmgr_config.mbuf_high_water =
  10556. DEFAULT_MB_HIGH_WATER;
  10557. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  10558. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  10559. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  10560. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  10561. tp->bufmgr_config.mbuf_high_water_jumbo =
  10562. DEFAULT_MB_HIGH_WATER_JUMBO;
  10563. }
  10564. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  10565. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  10566. }
  10567. static char * __devinit tg3_phy_string(struct tg3 *tp)
  10568. {
  10569. switch (tp->phy_id & PHY_ID_MASK) {
  10570. case PHY_ID_BCM5400: return "5400";
  10571. case PHY_ID_BCM5401: return "5401";
  10572. case PHY_ID_BCM5411: return "5411";
  10573. case PHY_ID_BCM5701: return "5701";
  10574. case PHY_ID_BCM5703: return "5703";
  10575. case PHY_ID_BCM5704: return "5704";
  10576. case PHY_ID_BCM5705: return "5705";
  10577. case PHY_ID_BCM5750: return "5750";
  10578. case PHY_ID_BCM5752: return "5752";
  10579. case PHY_ID_BCM5714: return "5714";
  10580. case PHY_ID_BCM5780: return "5780";
  10581. case PHY_ID_BCM5755: return "5755";
  10582. case PHY_ID_BCM5787: return "5787";
  10583. case PHY_ID_BCM5784: return "5784";
  10584. case PHY_ID_BCM5756: return "5722/5756";
  10585. case PHY_ID_BCM5906: return "5906";
  10586. case PHY_ID_BCM5761: return "5761";
  10587. case PHY_ID_BCM8002: return "8002/serdes";
  10588. case 0: return "serdes";
  10589. default: return "unknown";
  10590. };
  10591. }
  10592. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  10593. {
  10594. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10595. strcpy(str, "PCI Express");
  10596. return str;
  10597. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  10598. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  10599. strcpy(str, "PCIX:");
  10600. if ((clock_ctrl == 7) ||
  10601. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  10602. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  10603. strcat(str, "133MHz");
  10604. else if (clock_ctrl == 0)
  10605. strcat(str, "33MHz");
  10606. else if (clock_ctrl == 2)
  10607. strcat(str, "50MHz");
  10608. else if (clock_ctrl == 4)
  10609. strcat(str, "66MHz");
  10610. else if (clock_ctrl == 6)
  10611. strcat(str, "100MHz");
  10612. } else {
  10613. strcpy(str, "PCI:");
  10614. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  10615. strcat(str, "66MHz");
  10616. else
  10617. strcat(str, "33MHz");
  10618. }
  10619. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  10620. strcat(str, ":32-bit");
  10621. else
  10622. strcat(str, ":64-bit");
  10623. return str;
  10624. }
  10625. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  10626. {
  10627. struct pci_dev *peer;
  10628. unsigned int func, devnr = tp->pdev->devfn & ~7;
  10629. for (func = 0; func < 8; func++) {
  10630. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  10631. if (peer && peer != tp->pdev)
  10632. break;
  10633. pci_dev_put(peer);
  10634. }
  10635. /* 5704 can be configured in single-port mode, set peer to
  10636. * tp->pdev in that case.
  10637. */
  10638. if (!peer) {
  10639. peer = tp->pdev;
  10640. return peer;
  10641. }
  10642. /*
  10643. * We don't need to keep the refcount elevated; there's no way
  10644. * to remove one half of this device without removing the other
  10645. */
  10646. pci_dev_put(peer);
  10647. return peer;
  10648. }
  10649. static void __devinit tg3_init_coal(struct tg3 *tp)
  10650. {
  10651. struct ethtool_coalesce *ec = &tp->coal;
  10652. memset(ec, 0, sizeof(*ec));
  10653. ec->cmd = ETHTOOL_GCOALESCE;
  10654. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  10655. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  10656. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  10657. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  10658. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  10659. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  10660. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  10661. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  10662. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  10663. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  10664. HOSTCC_MODE_CLRTICK_TXBD)) {
  10665. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  10666. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  10667. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  10668. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  10669. }
  10670. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  10671. ec->rx_coalesce_usecs_irq = 0;
  10672. ec->tx_coalesce_usecs_irq = 0;
  10673. ec->stats_block_coalesce_usecs = 0;
  10674. }
  10675. }
  10676. static int __devinit tg3_init_one(struct pci_dev *pdev,
  10677. const struct pci_device_id *ent)
  10678. {
  10679. static int tg3_version_printed = 0;
  10680. resource_size_t tg3reg_base;
  10681. unsigned long tg3reg_len;
  10682. struct net_device *dev;
  10683. struct tg3 *tp;
  10684. int err, pm_cap;
  10685. char str[40];
  10686. u64 dma_mask, persist_dma_mask;
  10687. DECLARE_MAC_BUF(mac);
  10688. if (tg3_version_printed++ == 0)
  10689. printk(KERN_INFO "%s", version);
  10690. err = pci_enable_device(pdev);
  10691. if (err) {
  10692. printk(KERN_ERR PFX "Cannot enable PCI device, "
  10693. "aborting.\n");
  10694. return err;
  10695. }
  10696. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10697. printk(KERN_ERR PFX "Cannot find proper PCI device "
  10698. "base address, aborting.\n");
  10699. err = -ENODEV;
  10700. goto err_out_disable_pdev;
  10701. }
  10702. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  10703. if (err) {
  10704. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  10705. "aborting.\n");
  10706. goto err_out_disable_pdev;
  10707. }
  10708. pci_set_master(pdev);
  10709. /* Find power-management capability. */
  10710. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  10711. if (pm_cap == 0) {
  10712. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  10713. "aborting.\n");
  10714. err = -EIO;
  10715. goto err_out_free_res;
  10716. }
  10717. tg3reg_base = pci_resource_start(pdev, 0);
  10718. tg3reg_len = pci_resource_len(pdev, 0);
  10719. dev = alloc_etherdev(sizeof(*tp));
  10720. if (!dev) {
  10721. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  10722. err = -ENOMEM;
  10723. goto err_out_free_res;
  10724. }
  10725. SET_NETDEV_DEV(dev, &pdev->dev);
  10726. #if TG3_VLAN_TAG_USED
  10727. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  10728. dev->vlan_rx_register = tg3_vlan_rx_register;
  10729. #endif
  10730. tp = netdev_priv(dev);
  10731. tp->pdev = pdev;
  10732. tp->dev = dev;
  10733. tp->pm_cap = pm_cap;
  10734. tp->mac_mode = TG3_DEF_MAC_MODE;
  10735. tp->rx_mode = TG3_DEF_RX_MODE;
  10736. tp->tx_mode = TG3_DEF_TX_MODE;
  10737. tp->mi_mode = MAC_MI_MODE_BASE;
  10738. if (tg3_debug > 0)
  10739. tp->msg_enable = tg3_debug;
  10740. else
  10741. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  10742. /* The word/byte swap controls here control register access byte
  10743. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  10744. * setting below.
  10745. */
  10746. tp->misc_host_ctrl =
  10747. MISC_HOST_CTRL_MASK_PCI_INT |
  10748. MISC_HOST_CTRL_WORD_SWAP |
  10749. MISC_HOST_CTRL_INDIR_ACCESS |
  10750. MISC_HOST_CTRL_PCISTATE_RW;
  10751. /* The NONFRM (non-frame) byte/word swap controls take effect
  10752. * on descriptor entries, anything which isn't packet data.
  10753. *
  10754. * The StrongARM chips on the board (one for tx, one for rx)
  10755. * are running in big-endian mode.
  10756. */
  10757. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  10758. GRC_MODE_WSWAP_NONFRM_DATA);
  10759. #ifdef __BIG_ENDIAN
  10760. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  10761. #endif
  10762. spin_lock_init(&tp->lock);
  10763. spin_lock_init(&tp->indirect_lock);
  10764. INIT_WORK(&tp->reset_task, tg3_reset_task);
  10765. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10766. if (!tp->regs) {
  10767. printk(KERN_ERR PFX "Cannot map device registers, "
  10768. "aborting.\n");
  10769. err = -ENOMEM;
  10770. goto err_out_free_dev;
  10771. }
  10772. tg3_init_link_config(tp);
  10773. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10774. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10775. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10776. dev->open = tg3_open;
  10777. dev->stop = tg3_close;
  10778. dev->get_stats = tg3_get_stats;
  10779. dev->set_multicast_list = tg3_set_rx_mode;
  10780. dev->set_mac_address = tg3_set_mac_addr;
  10781. dev->do_ioctl = tg3_ioctl;
  10782. dev->tx_timeout = tg3_tx_timeout;
  10783. netif_napi_add(dev, &tp->napi, tg3_poll, 64);
  10784. dev->ethtool_ops = &tg3_ethtool_ops;
  10785. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10786. dev->change_mtu = tg3_change_mtu;
  10787. dev->irq = pdev->irq;
  10788. #ifdef CONFIG_NET_POLL_CONTROLLER
  10789. dev->poll_controller = tg3_poll_controller;
  10790. #endif
  10791. err = tg3_get_invariants(tp);
  10792. if (err) {
  10793. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10794. "aborting.\n");
  10795. goto err_out_iounmap;
  10796. }
  10797. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10798. * device behind the EPB cannot support DMA addresses > 40-bit.
  10799. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10800. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10801. * do DMA address check in tg3_start_xmit().
  10802. */
  10803. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10804. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10805. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10806. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10807. #ifdef CONFIG_HIGHMEM
  10808. dma_mask = DMA_64BIT_MASK;
  10809. #endif
  10810. } else
  10811. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10812. /* Configure DMA attributes. */
  10813. if (dma_mask > DMA_32BIT_MASK) {
  10814. err = pci_set_dma_mask(pdev, dma_mask);
  10815. if (!err) {
  10816. dev->features |= NETIF_F_HIGHDMA;
  10817. err = pci_set_consistent_dma_mask(pdev,
  10818. persist_dma_mask);
  10819. if (err < 0) {
  10820. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10821. "DMA for consistent allocations\n");
  10822. goto err_out_iounmap;
  10823. }
  10824. }
  10825. }
  10826. if (err || dma_mask == DMA_32BIT_MASK) {
  10827. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10828. if (err) {
  10829. printk(KERN_ERR PFX "No usable DMA configuration, "
  10830. "aborting.\n");
  10831. goto err_out_iounmap;
  10832. }
  10833. }
  10834. tg3_init_bufmgr_config(tp);
  10835. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10836. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10837. }
  10838. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10839. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10840. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10841. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10842. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10843. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10844. } else {
  10845. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10846. }
  10847. /* TSO is on by default on chips that support hardware TSO.
  10848. * Firmware TSO on older chips gives lower performance, so it
  10849. * is off by default, but can be enabled using ethtool.
  10850. */
  10851. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10852. dev->features |= NETIF_F_TSO;
  10853. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10854. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10855. dev->features |= NETIF_F_TSO6;
  10856. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  10857. dev->features |= NETIF_F_TSO_ECN;
  10858. }
  10859. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10860. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10861. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10862. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10863. tp->rx_pending = 63;
  10864. }
  10865. err = tg3_get_device_address(tp);
  10866. if (err) {
  10867. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10868. "aborting.\n");
  10869. goto err_out_iounmap;
  10870. }
  10871. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  10872. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10873. printk(KERN_ERR PFX "Cannot find proper PCI device "
  10874. "base address for APE, aborting.\n");
  10875. err = -ENODEV;
  10876. goto err_out_iounmap;
  10877. }
  10878. tg3reg_base = pci_resource_start(pdev, 2);
  10879. tg3reg_len = pci_resource_len(pdev, 2);
  10880. tp->aperegs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10881. if (!tp->aperegs) {
  10882. printk(KERN_ERR PFX "Cannot map APE registers, "
  10883. "aborting.\n");
  10884. err = -ENOMEM;
  10885. goto err_out_iounmap;
  10886. }
  10887. tg3_ape_lock_init(tp);
  10888. }
  10889. /*
  10890. * Reset chip in case UNDI or EFI driver did not shutdown
  10891. * DMA self test will enable WDMAC and we'll see (spurious)
  10892. * pending DMA on the PCI bus at that point.
  10893. */
  10894. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10895. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10896. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10897. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10898. }
  10899. err = tg3_test_dma(tp);
  10900. if (err) {
  10901. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10902. goto err_out_apeunmap;
  10903. }
  10904. /* Tigon3 can do ipv4 only... and some chips have buggy
  10905. * checksumming.
  10906. */
  10907. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10908. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  10909. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10910. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  10911. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  10912. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  10913. dev->features |= NETIF_F_IPV6_CSUM;
  10914. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10915. } else
  10916. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10917. /* flow control autonegotiation is default behavior */
  10918. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10919. tp->link_config.flowctrl = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  10920. tg3_init_coal(tp);
  10921. pci_set_drvdata(pdev, dev);
  10922. err = register_netdev(dev);
  10923. if (err) {
  10924. printk(KERN_ERR PFX "Cannot register net device, "
  10925. "aborting.\n");
  10926. goto err_out_apeunmap;
  10927. }
  10928. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] "
  10929. "(%s) %s Ethernet %s\n",
  10930. dev->name,
  10931. tp->board_part_number,
  10932. tp->pci_chip_rev_id,
  10933. tg3_phy_string(tp),
  10934. tg3_bus_string(tp, str),
  10935. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10936. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10937. "10/100/1000Base-T")),
  10938. print_mac(mac, dev->dev_addr));
  10939. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10940. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10941. dev->name,
  10942. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10943. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10944. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10945. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10946. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10947. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10948. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10949. dev->name, tp->dma_rwctrl,
  10950. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10951. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10952. return 0;
  10953. err_out_apeunmap:
  10954. if (tp->aperegs) {
  10955. iounmap(tp->aperegs);
  10956. tp->aperegs = NULL;
  10957. }
  10958. err_out_iounmap:
  10959. if (tp->regs) {
  10960. iounmap(tp->regs);
  10961. tp->regs = NULL;
  10962. }
  10963. err_out_free_dev:
  10964. free_netdev(dev);
  10965. err_out_free_res:
  10966. pci_release_regions(pdev);
  10967. err_out_disable_pdev:
  10968. pci_disable_device(pdev);
  10969. pci_set_drvdata(pdev, NULL);
  10970. return err;
  10971. }
  10972. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10973. {
  10974. struct net_device *dev = pci_get_drvdata(pdev);
  10975. if (dev) {
  10976. struct tg3 *tp = netdev_priv(dev);
  10977. flush_scheduled_work();
  10978. unregister_netdev(dev);
  10979. if (tp->aperegs) {
  10980. iounmap(tp->aperegs);
  10981. tp->aperegs = NULL;
  10982. }
  10983. if (tp->regs) {
  10984. iounmap(tp->regs);
  10985. tp->regs = NULL;
  10986. }
  10987. free_netdev(dev);
  10988. pci_release_regions(pdev);
  10989. pci_disable_device(pdev);
  10990. pci_set_drvdata(pdev, NULL);
  10991. }
  10992. }
  10993. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10994. {
  10995. struct net_device *dev = pci_get_drvdata(pdev);
  10996. struct tg3 *tp = netdev_priv(dev);
  10997. int err;
  10998. /* PCI register 4 needs to be saved whether netif_running() or not.
  10999. * MSI address and data need to be saved if using MSI and
  11000. * netif_running().
  11001. */
  11002. pci_save_state(pdev);
  11003. if (!netif_running(dev))
  11004. return 0;
  11005. flush_scheduled_work();
  11006. tg3_netif_stop(tp);
  11007. del_timer_sync(&tp->timer);
  11008. tg3_full_lock(tp, 1);
  11009. tg3_disable_ints(tp);
  11010. tg3_full_unlock(tp);
  11011. netif_device_detach(dev);
  11012. tg3_full_lock(tp, 0);
  11013. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  11014. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  11015. tg3_full_unlock(tp);
  11016. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  11017. if (err) {
  11018. tg3_full_lock(tp, 0);
  11019. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  11020. if (tg3_restart_hw(tp, 1))
  11021. goto out;
  11022. tp->timer.expires = jiffies + tp->timer_offset;
  11023. add_timer(&tp->timer);
  11024. netif_device_attach(dev);
  11025. tg3_netif_start(tp);
  11026. out:
  11027. tg3_full_unlock(tp);
  11028. }
  11029. return err;
  11030. }
  11031. static int tg3_resume(struct pci_dev *pdev)
  11032. {
  11033. struct net_device *dev = pci_get_drvdata(pdev);
  11034. struct tg3 *tp = netdev_priv(dev);
  11035. int err;
  11036. pci_restore_state(tp->pdev);
  11037. if (!netif_running(dev))
  11038. return 0;
  11039. err = tg3_set_power_state(tp, PCI_D0);
  11040. if (err)
  11041. return err;
  11042. netif_device_attach(dev);
  11043. tg3_full_lock(tp, 0);
  11044. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  11045. err = tg3_restart_hw(tp, 1);
  11046. if (err)
  11047. goto out;
  11048. tp->timer.expires = jiffies + tp->timer_offset;
  11049. add_timer(&tp->timer);
  11050. tg3_netif_start(tp);
  11051. out:
  11052. tg3_full_unlock(tp);
  11053. return err;
  11054. }
  11055. static struct pci_driver tg3_driver = {
  11056. .name = DRV_MODULE_NAME,
  11057. .id_table = tg3_pci_tbl,
  11058. .probe = tg3_init_one,
  11059. .remove = __devexit_p(tg3_remove_one),
  11060. .suspend = tg3_suspend,
  11061. .resume = tg3_resume
  11062. };
  11063. static int __init tg3_init(void)
  11064. {
  11065. return pci_register_driver(&tg3_driver);
  11066. }
  11067. static void __exit tg3_cleanup(void)
  11068. {
  11069. pci_unregister_driver(&tg3_driver);
  11070. }
  11071. module_init(tg3_init);
  11072. module_exit(tg3_cleanup);