tg3.c 337 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <asm/system.h>
  41. #include <asm/io.h>
  42. #include <asm/byteorder.h>
  43. #include <asm/uaccess.h>
  44. #ifdef CONFIG_SPARC64
  45. #include <asm/idprom.h>
  46. #include <asm/oplib.h>
  47. #include <asm/pbm.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #ifdef NETIF_F_TSO
  55. #define TG3_TSO_SUPPORT 1
  56. #else
  57. #define TG3_TSO_SUPPORT 0
  58. #endif
  59. #include "tg3.h"
  60. #define DRV_MODULE_NAME "tg3"
  61. #define PFX DRV_MODULE_NAME ": "
  62. #define DRV_MODULE_VERSION "3.63"
  63. #define DRV_MODULE_RELDATE "July 25, 2006"
  64. #define TG3_DEF_MAC_MODE 0
  65. #define TG3_DEF_RX_MODE 0
  66. #define TG3_DEF_TX_MODE 0
  67. #define TG3_DEF_MSG_ENABLE \
  68. (NETIF_MSG_DRV | \
  69. NETIF_MSG_PROBE | \
  70. NETIF_MSG_LINK | \
  71. NETIF_MSG_TIMER | \
  72. NETIF_MSG_IFDOWN | \
  73. NETIF_MSG_IFUP | \
  74. NETIF_MSG_RX_ERR | \
  75. NETIF_MSG_TX_ERR)
  76. /* length of time before we decide the hardware is borked,
  77. * and dev->tx_timeout() should be called to fix the problem
  78. */
  79. #define TG3_TX_TIMEOUT (5 * HZ)
  80. /* hardware minimum and maximum for a single frame's data payload */
  81. #define TG3_MIN_MTU 60
  82. #define TG3_MAX_MTU(tp) \
  83. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  84. /* These numbers seem to be hard coded in the NIC firmware somehow.
  85. * You can't change the ring sizes, but you can change where you place
  86. * them in the NIC onboard memory.
  87. */
  88. #define TG3_RX_RING_SIZE 512
  89. #define TG3_DEF_RX_RING_PENDING 200
  90. #define TG3_RX_JUMBO_RING_SIZE 256
  91. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  92. /* Do not place this n-ring entries value into the tp struct itself,
  93. * we really want to expose these constants to GCC so that modulo et
  94. * al. operations are done with shifts and masks instead of with
  95. * hw multiply/modulo instructions. Another solution would be to
  96. * replace things like '% foo' with '& (foo - 1)'.
  97. */
  98. #define TG3_RX_RCB_RING_SIZE(tp) \
  99. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  100. #define TG3_TX_RING_SIZE 512
  101. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  102. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RING_SIZE)
  104. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  105. TG3_RX_JUMBO_RING_SIZE)
  106. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  107. TG3_RX_RCB_RING_SIZE(tp))
  108. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  109. TG3_TX_RING_SIZE)
  110. #define TX_BUFFS_AVAIL(TP) \
  111. ((TP)->tx_pending - \
  112. (((TP)->tx_prod - (TP)->tx_cons) & (TG3_TX_RING_SIZE - 1)))
  113. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  114. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  115. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  116. /* minimum number of free TX descriptors required to wake up TX process */
  117. #define TG3_TX_WAKEUP_THRESH (TG3_TX_RING_SIZE / 4)
  118. /* number of ETHTOOL_GSTATS u64's */
  119. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  120. #define TG3_NUM_TEST 6
  121. static char version[] __devinitdata =
  122. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  123. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  124. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  125. MODULE_LICENSE("GPL");
  126. MODULE_VERSION(DRV_MODULE_VERSION);
  127. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  128. module_param(tg3_debug, int, 0);
  129. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  130. static struct pci_device_id tg3_pci_tbl[] = {
  131. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700,
  132. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  133. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701,
  134. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  135. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702,
  136. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  137. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703,
  138. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  139. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704,
  140. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  141. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE,
  142. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  143. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705,
  144. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  145. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2,
  146. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  147. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M,
  148. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  149. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2,
  150. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  151. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X,
  152. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  153. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X,
  154. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  155. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S,
  156. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  157. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3,
  158. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  159. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3,
  160. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  161. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782,
  162. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  163. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788,
  164. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  165. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789,
  166. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  167. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901,
  168. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  169. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2,
  170. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  171. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2,
  172. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  173. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F,
  174. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  175. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720,
  176. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  177. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721,
  178. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  179. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750,
  180. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  181. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751,
  182. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  183. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M,
  184. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  185. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M,
  186. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  187. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F,
  188. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  189. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752,
  190. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  191. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M,
  192. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  193. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753,
  194. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  195. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M,
  196. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  197. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F,
  198. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  199. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754,
  200. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  201. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M,
  202. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  203. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755,
  204. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  205. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M,
  206. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  207. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786,
  208. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  209. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787,
  210. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  211. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M,
  212. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  213. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714,
  214. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  215. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S,
  216. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  217. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715,
  218. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  219. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S,
  220. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  221. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780,
  222. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  223. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S,
  224. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  225. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781,
  226. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  227. { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX,
  228. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  229. { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX,
  230. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  231. { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000,
  232. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  233. { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001,
  234. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  235. { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003,
  236. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  237. { PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100,
  238. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  239. { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3,
  240. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  241. { 0, }
  242. };
  243. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  244. static struct {
  245. const char string[ETH_GSTRING_LEN];
  246. } ethtool_stats_keys[TG3_NUM_STATS] = {
  247. { "rx_octets" },
  248. { "rx_fragments" },
  249. { "rx_ucast_packets" },
  250. { "rx_mcast_packets" },
  251. { "rx_bcast_packets" },
  252. { "rx_fcs_errors" },
  253. { "rx_align_errors" },
  254. { "rx_xon_pause_rcvd" },
  255. { "rx_xoff_pause_rcvd" },
  256. { "rx_mac_ctrl_rcvd" },
  257. { "rx_xoff_entered" },
  258. { "rx_frame_too_long_errors" },
  259. { "rx_jabbers" },
  260. { "rx_undersize_packets" },
  261. { "rx_in_length_errors" },
  262. { "rx_out_length_errors" },
  263. { "rx_64_or_less_octet_packets" },
  264. { "rx_65_to_127_octet_packets" },
  265. { "rx_128_to_255_octet_packets" },
  266. { "rx_256_to_511_octet_packets" },
  267. { "rx_512_to_1023_octet_packets" },
  268. { "rx_1024_to_1522_octet_packets" },
  269. { "rx_1523_to_2047_octet_packets" },
  270. { "rx_2048_to_4095_octet_packets" },
  271. { "rx_4096_to_8191_octet_packets" },
  272. { "rx_8192_to_9022_octet_packets" },
  273. { "tx_octets" },
  274. { "tx_collisions" },
  275. { "tx_xon_sent" },
  276. { "tx_xoff_sent" },
  277. { "tx_flow_control" },
  278. { "tx_mac_errors" },
  279. { "tx_single_collisions" },
  280. { "tx_mult_collisions" },
  281. { "tx_deferred" },
  282. { "tx_excessive_collisions" },
  283. { "tx_late_collisions" },
  284. { "tx_collide_2times" },
  285. { "tx_collide_3times" },
  286. { "tx_collide_4times" },
  287. { "tx_collide_5times" },
  288. { "tx_collide_6times" },
  289. { "tx_collide_7times" },
  290. { "tx_collide_8times" },
  291. { "tx_collide_9times" },
  292. { "tx_collide_10times" },
  293. { "tx_collide_11times" },
  294. { "tx_collide_12times" },
  295. { "tx_collide_13times" },
  296. { "tx_collide_14times" },
  297. { "tx_collide_15times" },
  298. { "tx_ucast_packets" },
  299. { "tx_mcast_packets" },
  300. { "tx_bcast_packets" },
  301. { "tx_carrier_sense_errors" },
  302. { "tx_discards" },
  303. { "tx_errors" },
  304. { "dma_writeq_full" },
  305. { "dma_write_prioq_full" },
  306. { "rxbds_empty" },
  307. { "rx_discards" },
  308. { "rx_errors" },
  309. { "rx_threshold_hit" },
  310. { "dma_readq_full" },
  311. { "dma_read_prioq_full" },
  312. { "tx_comp_queue_full" },
  313. { "ring_set_send_prod_index" },
  314. { "ring_status_update" },
  315. { "nic_irqs" },
  316. { "nic_avoided_irqs" },
  317. { "nic_tx_threshold_hit" }
  318. };
  319. static struct {
  320. const char string[ETH_GSTRING_LEN];
  321. } ethtool_test_keys[TG3_NUM_TEST] = {
  322. { "nvram test (online) " },
  323. { "link test (online) " },
  324. { "register test (offline)" },
  325. { "memory test (offline)" },
  326. { "loopback test (offline)" },
  327. { "interrupt test (offline)" },
  328. };
  329. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  330. {
  331. writel(val, tp->regs + off);
  332. }
  333. static u32 tg3_read32(struct tg3 *tp, u32 off)
  334. {
  335. return (readl(tp->regs + off));
  336. }
  337. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  338. {
  339. unsigned long flags;
  340. spin_lock_irqsave(&tp->indirect_lock, flags);
  341. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  342. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  343. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  344. }
  345. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  346. {
  347. writel(val, tp->regs + off);
  348. readl(tp->regs + off);
  349. }
  350. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  351. {
  352. unsigned long flags;
  353. u32 val;
  354. spin_lock_irqsave(&tp->indirect_lock, flags);
  355. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  356. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  357. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  358. return val;
  359. }
  360. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  361. {
  362. unsigned long flags;
  363. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  364. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  365. TG3_64BIT_REG_LOW, val);
  366. return;
  367. }
  368. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  369. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  370. TG3_64BIT_REG_LOW, val);
  371. return;
  372. }
  373. spin_lock_irqsave(&tp->indirect_lock, flags);
  374. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  375. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  376. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  377. /* In indirect mode when disabling interrupts, we also need
  378. * to clear the interrupt bit in the GRC local ctrl register.
  379. */
  380. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  381. (val == 0x1)) {
  382. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  383. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  384. }
  385. }
  386. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  387. {
  388. unsigned long flags;
  389. u32 val;
  390. spin_lock_irqsave(&tp->indirect_lock, flags);
  391. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  392. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  393. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  394. return val;
  395. }
  396. /* usec_wait specifies the wait time in usec when writing to certain registers
  397. * where it is unsafe to read back the register without some delay.
  398. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  399. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  400. */
  401. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  402. {
  403. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  404. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  405. /* Non-posted methods */
  406. tp->write32(tp, off, val);
  407. else {
  408. /* Posted method */
  409. tg3_write32(tp, off, val);
  410. if (usec_wait)
  411. udelay(usec_wait);
  412. tp->read32(tp, off);
  413. }
  414. /* Wait again after the read for the posted method to guarantee that
  415. * the wait time is met.
  416. */
  417. if (usec_wait)
  418. udelay(usec_wait);
  419. }
  420. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  421. {
  422. tp->write32_mbox(tp, off, val);
  423. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  424. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  425. tp->read32_mbox(tp, off);
  426. }
  427. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  428. {
  429. void __iomem *mbox = tp->regs + off;
  430. writel(val, mbox);
  431. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  432. writel(val, mbox);
  433. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  434. readl(mbox);
  435. }
  436. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  437. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  438. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  439. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  440. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  441. #define tw32(reg,val) tp->write32(tp, reg, val)
  442. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  443. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  444. #define tr32(reg) tp->read32(tp, reg)
  445. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  446. {
  447. unsigned long flags;
  448. spin_lock_irqsave(&tp->indirect_lock, flags);
  449. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  450. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  451. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  452. /* Always leave this as zero. */
  453. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  454. } else {
  455. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  456. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  457. /* Always leave this as zero. */
  458. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  459. }
  460. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  461. }
  462. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  463. {
  464. unsigned long flags;
  465. spin_lock_irqsave(&tp->indirect_lock, flags);
  466. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  467. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  468. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  469. /* Always leave this as zero. */
  470. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  471. } else {
  472. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  473. *val = tr32(TG3PCI_MEM_WIN_DATA);
  474. /* Always leave this as zero. */
  475. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  476. }
  477. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  478. }
  479. static void tg3_disable_ints(struct tg3 *tp)
  480. {
  481. tw32(TG3PCI_MISC_HOST_CTRL,
  482. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  483. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  484. }
  485. static inline void tg3_cond_int(struct tg3 *tp)
  486. {
  487. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  488. (tp->hw_status->status & SD_STATUS_UPDATED))
  489. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  490. }
  491. static void tg3_enable_ints(struct tg3 *tp)
  492. {
  493. tp->irq_sync = 0;
  494. wmb();
  495. tw32(TG3PCI_MISC_HOST_CTRL,
  496. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  497. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  498. (tp->last_tag << 24));
  499. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  500. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  501. (tp->last_tag << 24));
  502. tg3_cond_int(tp);
  503. }
  504. static inline unsigned int tg3_has_work(struct tg3 *tp)
  505. {
  506. struct tg3_hw_status *sblk = tp->hw_status;
  507. unsigned int work_exists = 0;
  508. /* check for phy events */
  509. if (!(tp->tg3_flags &
  510. (TG3_FLAG_USE_LINKCHG_REG |
  511. TG3_FLAG_POLL_SERDES))) {
  512. if (sblk->status & SD_STATUS_LINK_CHG)
  513. work_exists = 1;
  514. }
  515. /* check for RX/TX work to do */
  516. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  517. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  518. work_exists = 1;
  519. return work_exists;
  520. }
  521. /* tg3_restart_ints
  522. * similar to tg3_enable_ints, but it accurately determines whether there
  523. * is new work pending and can return without flushing the PIO write
  524. * which reenables interrupts
  525. */
  526. static void tg3_restart_ints(struct tg3 *tp)
  527. {
  528. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  529. tp->last_tag << 24);
  530. mmiowb();
  531. /* When doing tagged status, this work check is unnecessary.
  532. * The last_tag we write above tells the chip which piece of
  533. * work we've completed.
  534. */
  535. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  536. tg3_has_work(tp))
  537. tw32(HOSTCC_MODE, tp->coalesce_mode |
  538. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  539. }
  540. static inline void tg3_netif_stop(struct tg3 *tp)
  541. {
  542. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  543. netif_poll_disable(tp->dev);
  544. netif_tx_disable(tp->dev);
  545. }
  546. static inline void tg3_netif_start(struct tg3 *tp)
  547. {
  548. netif_wake_queue(tp->dev);
  549. /* NOTE: unconditional netif_wake_queue is only appropriate
  550. * so long as all callers are assured to have free tx slots
  551. * (such as after tg3_init_hw)
  552. */
  553. netif_poll_enable(tp->dev);
  554. tp->hw_status->status |= SD_STATUS_UPDATED;
  555. tg3_enable_ints(tp);
  556. }
  557. static void tg3_switch_clocks(struct tg3 *tp)
  558. {
  559. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  560. u32 orig_clock_ctrl;
  561. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  562. return;
  563. orig_clock_ctrl = clock_ctrl;
  564. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  565. CLOCK_CTRL_CLKRUN_OENABLE |
  566. 0x1f);
  567. tp->pci_clock_ctrl = clock_ctrl;
  568. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  569. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  570. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  571. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  572. }
  573. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  574. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  575. clock_ctrl |
  576. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  577. 40);
  578. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  579. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  580. 40);
  581. }
  582. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  583. }
  584. #define PHY_BUSY_LOOPS 5000
  585. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  586. {
  587. u32 frame_val;
  588. unsigned int loops;
  589. int ret;
  590. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  591. tw32_f(MAC_MI_MODE,
  592. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  593. udelay(80);
  594. }
  595. *val = 0x0;
  596. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  597. MI_COM_PHY_ADDR_MASK);
  598. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  599. MI_COM_REG_ADDR_MASK);
  600. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  601. tw32_f(MAC_MI_COM, frame_val);
  602. loops = PHY_BUSY_LOOPS;
  603. while (loops != 0) {
  604. udelay(10);
  605. frame_val = tr32(MAC_MI_COM);
  606. if ((frame_val & MI_COM_BUSY) == 0) {
  607. udelay(5);
  608. frame_val = tr32(MAC_MI_COM);
  609. break;
  610. }
  611. loops -= 1;
  612. }
  613. ret = -EBUSY;
  614. if (loops != 0) {
  615. *val = frame_val & MI_COM_DATA_MASK;
  616. ret = 0;
  617. }
  618. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  619. tw32_f(MAC_MI_MODE, tp->mi_mode);
  620. udelay(80);
  621. }
  622. return ret;
  623. }
  624. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  625. {
  626. u32 frame_val;
  627. unsigned int loops;
  628. int ret;
  629. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  630. tw32_f(MAC_MI_MODE,
  631. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  632. udelay(80);
  633. }
  634. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  635. MI_COM_PHY_ADDR_MASK);
  636. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  637. MI_COM_REG_ADDR_MASK);
  638. frame_val |= (val & MI_COM_DATA_MASK);
  639. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  640. tw32_f(MAC_MI_COM, frame_val);
  641. loops = PHY_BUSY_LOOPS;
  642. while (loops != 0) {
  643. udelay(10);
  644. frame_val = tr32(MAC_MI_COM);
  645. if ((frame_val & MI_COM_BUSY) == 0) {
  646. udelay(5);
  647. frame_val = tr32(MAC_MI_COM);
  648. break;
  649. }
  650. loops -= 1;
  651. }
  652. ret = -EBUSY;
  653. if (loops != 0)
  654. ret = 0;
  655. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  656. tw32_f(MAC_MI_MODE, tp->mi_mode);
  657. udelay(80);
  658. }
  659. return ret;
  660. }
  661. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  662. {
  663. u32 val;
  664. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  665. return;
  666. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  667. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  668. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  669. (val | (1 << 15) | (1 << 4)));
  670. }
  671. static int tg3_bmcr_reset(struct tg3 *tp)
  672. {
  673. u32 phy_control;
  674. int limit, err;
  675. /* OK, reset it, and poll the BMCR_RESET bit until it
  676. * clears or we time out.
  677. */
  678. phy_control = BMCR_RESET;
  679. err = tg3_writephy(tp, MII_BMCR, phy_control);
  680. if (err != 0)
  681. return -EBUSY;
  682. limit = 5000;
  683. while (limit--) {
  684. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  685. if (err != 0)
  686. return -EBUSY;
  687. if ((phy_control & BMCR_RESET) == 0) {
  688. udelay(40);
  689. break;
  690. }
  691. udelay(10);
  692. }
  693. if (limit <= 0)
  694. return -EBUSY;
  695. return 0;
  696. }
  697. static int tg3_wait_macro_done(struct tg3 *tp)
  698. {
  699. int limit = 100;
  700. while (limit--) {
  701. u32 tmp32;
  702. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  703. if ((tmp32 & 0x1000) == 0)
  704. break;
  705. }
  706. }
  707. if (limit <= 0)
  708. return -EBUSY;
  709. return 0;
  710. }
  711. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  712. {
  713. static const u32 test_pat[4][6] = {
  714. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  715. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  716. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  717. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  718. };
  719. int chan;
  720. for (chan = 0; chan < 4; chan++) {
  721. int i;
  722. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  723. (chan * 0x2000) | 0x0200);
  724. tg3_writephy(tp, 0x16, 0x0002);
  725. for (i = 0; i < 6; i++)
  726. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  727. test_pat[chan][i]);
  728. tg3_writephy(tp, 0x16, 0x0202);
  729. if (tg3_wait_macro_done(tp)) {
  730. *resetp = 1;
  731. return -EBUSY;
  732. }
  733. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  734. (chan * 0x2000) | 0x0200);
  735. tg3_writephy(tp, 0x16, 0x0082);
  736. if (tg3_wait_macro_done(tp)) {
  737. *resetp = 1;
  738. return -EBUSY;
  739. }
  740. tg3_writephy(tp, 0x16, 0x0802);
  741. if (tg3_wait_macro_done(tp)) {
  742. *resetp = 1;
  743. return -EBUSY;
  744. }
  745. for (i = 0; i < 6; i += 2) {
  746. u32 low, high;
  747. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  748. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  749. tg3_wait_macro_done(tp)) {
  750. *resetp = 1;
  751. return -EBUSY;
  752. }
  753. low &= 0x7fff;
  754. high &= 0x000f;
  755. if (low != test_pat[chan][i] ||
  756. high != test_pat[chan][i+1]) {
  757. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  758. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  759. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  760. return -EBUSY;
  761. }
  762. }
  763. }
  764. return 0;
  765. }
  766. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  767. {
  768. int chan;
  769. for (chan = 0; chan < 4; chan++) {
  770. int i;
  771. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  772. (chan * 0x2000) | 0x0200);
  773. tg3_writephy(tp, 0x16, 0x0002);
  774. for (i = 0; i < 6; i++)
  775. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  776. tg3_writephy(tp, 0x16, 0x0202);
  777. if (tg3_wait_macro_done(tp))
  778. return -EBUSY;
  779. }
  780. return 0;
  781. }
  782. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  783. {
  784. u32 reg32, phy9_orig;
  785. int retries, do_phy_reset, err;
  786. retries = 10;
  787. do_phy_reset = 1;
  788. do {
  789. if (do_phy_reset) {
  790. err = tg3_bmcr_reset(tp);
  791. if (err)
  792. return err;
  793. do_phy_reset = 0;
  794. }
  795. /* Disable transmitter and interrupt. */
  796. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  797. continue;
  798. reg32 |= 0x3000;
  799. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  800. /* Set full-duplex, 1000 mbps. */
  801. tg3_writephy(tp, MII_BMCR,
  802. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  803. /* Set to master mode. */
  804. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  805. continue;
  806. tg3_writephy(tp, MII_TG3_CTRL,
  807. (MII_TG3_CTRL_AS_MASTER |
  808. MII_TG3_CTRL_ENABLE_AS_MASTER));
  809. /* Enable SM_DSP_CLOCK and 6dB. */
  810. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  811. /* Block the PHY control access. */
  812. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  813. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  814. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  815. if (!err)
  816. break;
  817. } while (--retries);
  818. err = tg3_phy_reset_chanpat(tp);
  819. if (err)
  820. return err;
  821. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  822. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  823. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  824. tg3_writephy(tp, 0x16, 0x0000);
  825. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  826. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  827. /* Set Extended packet length bit for jumbo frames */
  828. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  829. }
  830. else {
  831. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  832. }
  833. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  834. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  835. reg32 &= ~0x3000;
  836. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  837. } else if (!err)
  838. err = -EBUSY;
  839. return err;
  840. }
  841. static void tg3_link_report(struct tg3 *);
  842. /* This will reset the tigon3 PHY if there is no valid
  843. * link unless the FORCE argument is non-zero.
  844. */
  845. static int tg3_phy_reset(struct tg3 *tp)
  846. {
  847. u32 phy_status;
  848. int err;
  849. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  850. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  851. if (err != 0)
  852. return -EBUSY;
  853. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  854. netif_carrier_off(tp->dev);
  855. tg3_link_report(tp);
  856. }
  857. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  858. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  859. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  860. err = tg3_phy_reset_5703_4_5(tp);
  861. if (err)
  862. return err;
  863. goto out;
  864. }
  865. err = tg3_bmcr_reset(tp);
  866. if (err)
  867. return err;
  868. out:
  869. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  870. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  871. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  872. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  873. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  874. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  875. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  876. }
  877. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  878. tg3_writephy(tp, 0x1c, 0x8d68);
  879. tg3_writephy(tp, 0x1c, 0x8d68);
  880. }
  881. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  882. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  883. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  884. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  885. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  886. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  887. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  888. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  889. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  890. }
  891. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  892. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  893. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  894. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  895. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  896. }
  897. /* Set Extended packet length bit (bit 14) on all chips that */
  898. /* support jumbo frames */
  899. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  900. /* Cannot do read-modify-write on 5401 */
  901. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  902. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  903. u32 phy_reg;
  904. /* Set bit 14 with read-modify-write to preserve other bits */
  905. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  906. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  907. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  908. }
  909. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  910. * jumbo frames transmission.
  911. */
  912. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  913. u32 phy_reg;
  914. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  915. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  916. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  917. }
  918. tg3_phy_set_wirespeed(tp);
  919. return 0;
  920. }
  921. static void tg3_frob_aux_power(struct tg3 *tp)
  922. {
  923. struct tg3 *tp_peer = tp;
  924. if ((tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) != 0)
  925. return;
  926. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  927. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  928. struct net_device *dev_peer;
  929. dev_peer = pci_get_drvdata(tp->pdev_peer);
  930. /* remove_one() may have been run on the peer. */
  931. if (!dev_peer)
  932. tp_peer = tp;
  933. else
  934. tp_peer = netdev_priv(dev_peer);
  935. }
  936. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  937. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  938. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  939. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  940. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  941. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  942. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  943. (GRC_LCLCTRL_GPIO_OE0 |
  944. GRC_LCLCTRL_GPIO_OE1 |
  945. GRC_LCLCTRL_GPIO_OE2 |
  946. GRC_LCLCTRL_GPIO_OUTPUT0 |
  947. GRC_LCLCTRL_GPIO_OUTPUT1),
  948. 100);
  949. } else {
  950. u32 no_gpio2;
  951. u32 grc_local_ctrl = 0;
  952. if (tp_peer != tp &&
  953. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  954. return;
  955. /* Workaround to prevent overdrawing Amps. */
  956. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  957. ASIC_REV_5714) {
  958. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  959. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  960. grc_local_ctrl, 100);
  961. }
  962. /* On 5753 and variants, GPIO2 cannot be used. */
  963. no_gpio2 = tp->nic_sram_data_cfg &
  964. NIC_SRAM_DATA_CFG_NO_GPIO2;
  965. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  966. GRC_LCLCTRL_GPIO_OE1 |
  967. GRC_LCLCTRL_GPIO_OE2 |
  968. GRC_LCLCTRL_GPIO_OUTPUT1 |
  969. GRC_LCLCTRL_GPIO_OUTPUT2;
  970. if (no_gpio2) {
  971. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  972. GRC_LCLCTRL_GPIO_OUTPUT2);
  973. }
  974. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  975. grc_local_ctrl, 100);
  976. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  977. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  978. grc_local_ctrl, 100);
  979. if (!no_gpio2) {
  980. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  981. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  982. grc_local_ctrl, 100);
  983. }
  984. }
  985. } else {
  986. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  987. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  988. if (tp_peer != tp &&
  989. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  990. return;
  991. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  992. (GRC_LCLCTRL_GPIO_OE1 |
  993. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  994. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  995. GRC_LCLCTRL_GPIO_OE1, 100);
  996. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  997. (GRC_LCLCTRL_GPIO_OE1 |
  998. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  999. }
  1000. }
  1001. }
  1002. static int tg3_setup_phy(struct tg3 *, int);
  1003. #define RESET_KIND_SHUTDOWN 0
  1004. #define RESET_KIND_INIT 1
  1005. #define RESET_KIND_SUSPEND 2
  1006. static void tg3_write_sig_post_reset(struct tg3 *, int);
  1007. static int tg3_halt_cpu(struct tg3 *, u32);
  1008. static int tg3_nvram_lock(struct tg3 *);
  1009. static void tg3_nvram_unlock(struct tg3 *);
  1010. static void tg3_power_down_phy(struct tg3 *tp)
  1011. {
  1012. /* The PHY should not be powered down on some chips because
  1013. * of bugs.
  1014. */
  1015. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1016. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1017. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1018. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1019. return;
  1020. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1021. }
  1022. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1023. {
  1024. u32 misc_host_ctrl;
  1025. u16 power_control, power_caps;
  1026. int pm = tp->pm_cap;
  1027. /* Make sure register accesses (indirect or otherwise)
  1028. * will function correctly.
  1029. */
  1030. pci_write_config_dword(tp->pdev,
  1031. TG3PCI_MISC_HOST_CTRL,
  1032. tp->misc_host_ctrl);
  1033. pci_read_config_word(tp->pdev,
  1034. pm + PCI_PM_CTRL,
  1035. &power_control);
  1036. power_control |= PCI_PM_CTRL_PME_STATUS;
  1037. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1038. switch (state) {
  1039. case PCI_D0:
  1040. power_control |= 0;
  1041. pci_write_config_word(tp->pdev,
  1042. pm + PCI_PM_CTRL,
  1043. power_control);
  1044. udelay(100); /* Delay after power state change */
  1045. /* Switch out of Vaux if it is not a LOM */
  1046. if (!(tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  1047. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1048. return 0;
  1049. case PCI_D1:
  1050. power_control |= 1;
  1051. break;
  1052. case PCI_D2:
  1053. power_control |= 2;
  1054. break;
  1055. case PCI_D3hot:
  1056. power_control |= 3;
  1057. break;
  1058. default:
  1059. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1060. "requested.\n",
  1061. tp->dev->name, state);
  1062. return -EINVAL;
  1063. };
  1064. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1065. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1066. tw32(TG3PCI_MISC_HOST_CTRL,
  1067. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1068. if (tp->link_config.phy_is_low_power == 0) {
  1069. tp->link_config.phy_is_low_power = 1;
  1070. tp->link_config.orig_speed = tp->link_config.speed;
  1071. tp->link_config.orig_duplex = tp->link_config.duplex;
  1072. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1073. }
  1074. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1075. tp->link_config.speed = SPEED_10;
  1076. tp->link_config.duplex = DUPLEX_HALF;
  1077. tp->link_config.autoneg = AUTONEG_ENABLE;
  1078. tg3_setup_phy(tp, 0);
  1079. }
  1080. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1081. int i;
  1082. u32 val;
  1083. for (i = 0; i < 200; i++) {
  1084. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1085. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1086. break;
  1087. msleep(1);
  1088. }
  1089. }
  1090. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1091. WOL_DRV_STATE_SHUTDOWN |
  1092. WOL_DRV_WOL | WOL_SET_MAGIC_PKT);
  1093. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1094. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1095. u32 mac_mode;
  1096. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1097. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1098. udelay(40);
  1099. mac_mode = MAC_MODE_PORT_MODE_MII;
  1100. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
  1101. !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
  1102. mac_mode |= MAC_MODE_LINK_POLARITY;
  1103. } else {
  1104. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1105. }
  1106. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1107. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1108. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1109. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1110. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1111. tw32_f(MAC_MODE, mac_mode);
  1112. udelay(100);
  1113. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1114. udelay(10);
  1115. }
  1116. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1117. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1118. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1119. u32 base_val;
  1120. base_val = tp->pci_clock_ctrl;
  1121. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1122. CLOCK_CTRL_TXCLK_DISABLE);
  1123. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1124. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1125. } else if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  1126. /* do nothing */
  1127. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1128. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1129. u32 newbits1, newbits2;
  1130. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1131. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1132. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1133. CLOCK_CTRL_TXCLK_DISABLE |
  1134. CLOCK_CTRL_ALTCLK);
  1135. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1136. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1137. newbits1 = CLOCK_CTRL_625_CORE;
  1138. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1139. } else {
  1140. newbits1 = CLOCK_CTRL_ALTCLK;
  1141. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1142. }
  1143. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1144. 40);
  1145. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1146. 40);
  1147. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1148. u32 newbits3;
  1149. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1150. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1151. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1152. CLOCK_CTRL_TXCLK_DISABLE |
  1153. CLOCK_CTRL_44MHZ_CORE);
  1154. } else {
  1155. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1156. }
  1157. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1158. tp->pci_clock_ctrl | newbits3, 40);
  1159. }
  1160. }
  1161. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1162. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1163. /* Turn off the PHY */
  1164. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1165. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1166. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1167. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1168. tg3_power_down_phy(tp);
  1169. }
  1170. }
  1171. tg3_frob_aux_power(tp);
  1172. /* Workaround for unstable PLL clock */
  1173. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1174. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1175. u32 val = tr32(0x7d00);
  1176. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1177. tw32(0x7d00, val);
  1178. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1179. int err;
  1180. err = tg3_nvram_lock(tp);
  1181. tg3_halt_cpu(tp, RX_CPU_BASE);
  1182. if (!err)
  1183. tg3_nvram_unlock(tp);
  1184. }
  1185. }
  1186. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1187. /* Finally, set the new power state. */
  1188. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1189. udelay(100); /* Delay after power state change */
  1190. return 0;
  1191. }
  1192. static void tg3_link_report(struct tg3 *tp)
  1193. {
  1194. if (!netif_carrier_ok(tp->dev)) {
  1195. printk(KERN_INFO PFX "%s: Link is down.\n", tp->dev->name);
  1196. } else {
  1197. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1198. tp->dev->name,
  1199. (tp->link_config.active_speed == SPEED_1000 ?
  1200. 1000 :
  1201. (tp->link_config.active_speed == SPEED_100 ?
  1202. 100 : 10)),
  1203. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1204. "full" : "half"));
  1205. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1206. "%s for RX.\n",
  1207. tp->dev->name,
  1208. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1209. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1210. }
  1211. }
  1212. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1213. {
  1214. u32 new_tg3_flags = 0;
  1215. u32 old_rx_mode = tp->rx_mode;
  1216. u32 old_tx_mode = tp->tx_mode;
  1217. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1218. /* Convert 1000BaseX flow control bits to 1000BaseT
  1219. * bits before resolving flow control.
  1220. */
  1221. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1222. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1223. ADVERTISE_PAUSE_ASYM);
  1224. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1225. if (local_adv & ADVERTISE_1000XPAUSE)
  1226. local_adv |= ADVERTISE_PAUSE_CAP;
  1227. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1228. local_adv |= ADVERTISE_PAUSE_ASYM;
  1229. if (remote_adv & LPA_1000XPAUSE)
  1230. remote_adv |= LPA_PAUSE_CAP;
  1231. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1232. remote_adv |= LPA_PAUSE_ASYM;
  1233. }
  1234. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1235. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1236. if (remote_adv & LPA_PAUSE_CAP)
  1237. new_tg3_flags |=
  1238. (TG3_FLAG_RX_PAUSE |
  1239. TG3_FLAG_TX_PAUSE);
  1240. else if (remote_adv & LPA_PAUSE_ASYM)
  1241. new_tg3_flags |=
  1242. (TG3_FLAG_RX_PAUSE);
  1243. } else {
  1244. if (remote_adv & LPA_PAUSE_CAP)
  1245. new_tg3_flags |=
  1246. (TG3_FLAG_RX_PAUSE |
  1247. TG3_FLAG_TX_PAUSE);
  1248. }
  1249. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1250. if ((remote_adv & LPA_PAUSE_CAP) &&
  1251. (remote_adv & LPA_PAUSE_ASYM))
  1252. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1253. }
  1254. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1255. tp->tg3_flags |= new_tg3_flags;
  1256. } else {
  1257. new_tg3_flags = tp->tg3_flags;
  1258. }
  1259. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1260. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1261. else
  1262. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1263. if (old_rx_mode != tp->rx_mode) {
  1264. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1265. }
  1266. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1267. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1268. else
  1269. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1270. if (old_tx_mode != tp->tx_mode) {
  1271. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1272. }
  1273. }
  1274. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1275. {
  1276. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1277. case MII_TG3_AUX_STAT_10HALF:
  1278. *speed = SPEED_10;
  1279. *duplex = DUPLEX_HALF;
  1280. break;
  1281. case MII_TG3_AUX_STAT_10FULL:
  1282. *speed = SPEED_10;
  1283. *duplex = DUPLEX_FULL;
  1284. break;
  1285. case MII_TG3_AUX_STAT_100HALF:
  1286. *speed = SPEED_100;
  1287. *duplex = DUPLEX_HALF;
  1288. break;
  1289. case MII_TG3_AUX_STAT_100FULL:
  1290. *speed = SPEED_100;
  1291. *duplex = DUPLEX_FULL;
  1292. break;
  1293. case MII_TG3_AUX_STAT_1000HALF:
  1294. *speed = SPEED_1000;
  1295. *duplex = DUPLEX_HALF;
  1296. break;
  1297. case MII_TG3_AUX_STAT_1000FULL:
  1298. *speed = SPEED_1000;
  1299. *duplex = DUPLEX_FULL;
  1300. break;
  1301. default:
  1302. *speed = SPEED_INVALID;
  1303. *duplex = DUPLEX_INVALID;
  1304. break;
  1305. };
  1306. }
  1307. static void tg3_phy_copper_begin(struct tg3 *tp)
  1308. {
  1309. u32 new_adv;
  1310. int i;
  1311. if (tp->link_config.phy_is_low_power) {
  1312. /* Entering low power mode. Disable gigabit and
  1313. * 100baseT advertisements.
  1314. */
  1315. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1316. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1317. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1318. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1319. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1320. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1321. } else if (tp->link_config.speed == SPEED_INVALID) {
  1322. tp->link_config.advertising =
  1323. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  1324. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  1325. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  1326. ADVERTISED_Autoneg | ADVERTISED_MII);
  1327. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1328. tp->link_config.advertising &=
  1329. ~(ADVERTISED_1000baseT_Half |
  1330. ADVERTISED_1000baseT_Full);
  1331. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1332. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1333. new_adv |= ADVERTISE_10HALF;
  1334. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1335. new_adv |= ADVERTISE_10FULL;
  1336. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1337. new_adv |= ADVERTISE_100HALF;
  1338. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1339. new_adv |= ADVERTISE_100FULL;
  1340. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1341. if (tp->link_config.advertising &
  1342. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1343. new_adv = 0;
  1344. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1345. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1346. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1347. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1348. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1349. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1350. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1351. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1352. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1353. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1354. } else {
  1355. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1356. }
  1357. } else {
  1358. /* Asking for a specific link mode. */
  1359. if (tp->link_config.speed == SPEED_1000) {
  1360. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1361. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1362. if (tp->link_config.duplex == DUPLEX_FULL)
  1363. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1364. else
  1365. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1366. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1367. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1368. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1369. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1370. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1371. } else {
  1372. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1373. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1374. if (tp->link_config.speed == SPEED_100) {
  1375. if (tp->link_config.duplex == DUPLEX_FULL)
  1376. new_adv |= ADVERTISE_100FULL;
  1377. else
  1378. new_adv |= ADVERTISE_100HALF;
  1379. } else {
  1380. if (tp->link_config.duplex == DUPLEX_FULL)
  1381. new_adv |= ADVERTISE_10FULL;
  1382. else
  1383. new_adv |= ADVERTISE_10HALF;
  1384. }
  1385. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1386. }
  1387. }
  1388. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1389. tp->link_config.speed != SPEED_INVALID) {
  1390. u32 bmcr, orig_bmcr;
  1391. tp->link_config.active_speed = tp->link_config.speed;
  1392. tp->link_config.active_duplex = tp->link_config.duplex;
  1393. bmcr = 0;
  1394. switch (tp->link_config.speed) {
  1395. default:
  1396. case SPEED_10:
  1397. break;
  1398. case SPEED_100:
  1399. bmcr |= BMCR_SPEED100;
  1400. break;
  1401. case SPEED_1000:
  1402. bmcr |= TG3_BMCR_SPEED1000;
  1403. break;
  1404. };
  1405. if (tp->link_config.duplex == DUPLEX_FULL)
  1406. bmcr |= BMCR_FULLDPLX;
  1407. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1408. (bmcr != orig_bmcr)) {
  1409. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1410. for (i = 0; i < 1500; i++) {
  1411. u32 tmp;
  1412. udelay(10);
  1413. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1414. tg3_readphy(tp, MII_BMSR, &tmp))
  1415. continue;
  1416. if (!(tmp & BMSR_LSTATUS)) {
  1417. udelay(40);
  1418. break;
  1419. }
  1420. }
  1421. tg3_writephy(tp, MII_BMCR, bmcr);
  1422. udelay(40);
  1423. }
  1424. } else {
  1425. tg3_writephy(tp, MII_BMCR,
  1426. BMCR_ANENABLE | BMCR_ANRESTART);
  1427. }
  1428. }
  1429. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1430. {
  1431. int err;
  1432. /* Turn off tap power management. */
  1433. /* Set Extended packet length bit */
  1434. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1435. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1436. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1437. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1438. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1439. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1440. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1441. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1442. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1443. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1444. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1445. udelay(40);
  1446. return err;
  1447. }
  1448. static int tg3_copper_is_advertising_all(struct tg3 *tp)
  1449. {
  1450. u32 adv_reg, all_mask;
  1451. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1452. return 0;
  1453. all_mask = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1454. ADVERTISE_100HALF | ADVERTISE_100FULL);
  1455. if ((adv_reg & all_mask) != all_mask)
  1456. return 0;
  1457. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1458. u32 tg3_ctrl;
  1459. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1460. return 0;
  1461. all_mask = (MII_TG3_CTRL_ADV_1000_HALF |
  1462. MII_TG3_CTRL_ADV_1000_FULL);
  1463. if ((tg3_ctrl & all_mask) != all_mask)
  1464. return 0;
  1465. }
  1466. return 1;
  1467. }
  1468. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1469. {
  1470. int current_link_up;
  1471. u32 bmsr, dummy;
  1472. u16 current_speed;
  1473. u8 current_duplex;
  1474. int i, err;
  1475. tw32(MAC_EVENT, 0);
  1476. tw32_f(MAC_STATUS,
  1477. (MAC_STATUS_SYNC_CHANGED |
  1478. MAC_STATUS_CFG_CHANGED |
  1479. MAC_STATUS_MI_COMPLETION |
  1480. MAC_STATUS_LNKSTATE_CHANGED));
  1481. udelay(40);
  1482. tp->mi_mode = MAC_MI_MODE_BASE;
  1483. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1484. udelay(80);
  1485. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1486. /* Some third-party PHYs need to be reset on link going
  1487. * down.
  1488. */
  1489. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1490. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1491. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1492. netif_carrier_ok(tp->dev)) {
  1493. tg3_readphy(tp, MII_BMSR, &bmsr);
  1494. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1495. !(bmsr & BMSR_LSTATUS))
  1496. force_reset = 1;
  1497. }
  1498. if (force_reset)
  1499. tg3_phy_reset(tp);
  1500. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1501. tg3_readphy(tp, MII_BMSR, &bmsr);
  1502. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1503. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1504. bmsr = 0;
  1505. if (!(bmsr & BMSR_LSTATUS)) {
  1506. err = tg3_init_5401phy_dsp(tp);
  1507. if (err)
  1508. return err;
  1509. tg3_readphy(tp, MII_BMSR, &bmsr);
  1510. for (i = 0; i < 1000; i++) {
  1511. udelay(10);
  1512. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1513. (bmsr & BMSR_LSTATUS)) {
  1514. udelay(40);
  1515. break;
  1516. }
  1517. }
  1518. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1519. !(bmsr & BMSR_LSTATUS) &&
  1520. tp->link_config.active_speed == SPEED_1000) {
  1521. err = tg3_phy_reset(tp);
  1522. if (!err)
  1523. err = tg3_init_5401phy_dsp(tp);
  1524. if (err)
  1525. return err;
  1526. }
  1527. }
  1528. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1529. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1530. /* 5701 {A0,B0} CRC bug workaround */
  1531. tg3_writephy(tp, 0x15, 0x0a75);
  1532. tg3_writephy(tp, 0x1c, 0x8c68);
  1533. tg3_writephy(tp, 0x1c, 0x8d68);
  1534. tg3_writephy(tp, 0x1c, 0x8c68);
  1535. }
  1536. /* Clear pending interrupts... */
  1537. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1538. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1539. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1540. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1541. else
  1542. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1543. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1544. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1545. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1546. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1547. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1548. else
  1549. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1550. }
  1551. current_link_up = 0;
  1552. current_speed = SPEED_INVALID;
  1553. current_duplex = DUPLEX_INVALID;
  1554. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1555. u32 val;
  1556. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1557. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1558. if (!(val & (1 << 10))) {
  1559. val |= (1 << 10);
  1560. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1561. goto relink;
  1562. }
  1563. }
  1564. bmsr = 0;
  1565. for (i = 0; i < 100; i++) {
  1566. tg3_readphy(tp, MII_BMSR, &bmsr);
  1567. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1568. (bmsr & BMSR_LSTATUS))
  1569. break;
  1570. udelay(40);
  1571. }
  1572. if (bmsr & BMSR_LSTATUS) {
  1573. u32 aux_stat, bmcr;
  1574. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1575. for (i = 0; i < 2000; i++) {
  1576. udelay(10);
  1577. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1578. aux_stat)
  1579. break;
  1580. }
  1581. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1582. &current_speed,
  1583. &current_duplex);
  1584. bmcr = 0;
  1585. for (i = 0; i < 200; i++) {
  1586. tg3_readphy(tp, MII_BMCR, &bmcr);
  1587. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1588. continue;
  1589. if (bmcr && bmcr != 0x7fff)
  1590. break;
  1591. udelay(10);
  1592. }
  1593. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1594. if (bmcr & BMCR_ANENABLE) {
  1595. current_link_up = 1;
  1596. /* Force autoneg restart if we are exiting
  1597. * low power mode.
  1598. */
  1599. if (!tg3_copper_is_advertising_all(tp))
  1600. current_link_up = 0;
  1601. } else {
  1602. current_link_up = 0;
  1603. }
  1604. } else {
  1605. if (!(bmcr & BMCR_ANENABLE) &&
  1606. tp->link_config.speed == current_speed &&
  1607. tp->link_config.duplex == current_duplex) {
  1608. current_link_up = 1;
  1609. } else {
  1610. current_link_up = 0;
  1611. }
  1612. }
  1613. tp->link_config.active_speed = current_speed;
  1614. tp->link_config.active_duplex = current_duplex;
  1615. }
  1616. if (current_link_up == 1 &&
  1617. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1618. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1619. u32 local_adv, remote_adv;
  1620. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1621. local_adv = 0;
  1622. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1623. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1624. remote_adv = 0;
  1625. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1626. /* If we are not advertising full pause capability,
  1627. * something is wrong. Bring the link down and reconfigure.
  1628. */
  1629. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1630. current_link_up = 0;
  1631. } else {
  1632. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1633. }
  1634. }
  1635. relink:
  1636. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1637. u32 tmp;
  1638. tg3_phy_copper_begin(tp);
  1639. tg3_readphy(tp, MII_BMSR, &tmp);
  1640. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1641. (tmp & BMSR_LSTATUS))
  1642. current_link_up = 1;
  1643. }
  1644. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1645. if (current_link_up == 1) {
  1646. if (tp->link_config.active_speed == SPEED_100 ||
  1647. tp->link_config.active_speed == SPEED_10)
  1648. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1649. else
  1650. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1651. } else
  1652. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1653. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1654. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1655. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1656. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1657. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1658. if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
  1659. (current_link_up == 1 &&
  1660. tp->link_config.active_speed == SPEED_10))
  1661. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1662. } else {
  1663. if (current_link_up == 1)
  1664. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1665. }
  1666. /* ??? Without this setting Netgear GA302T PHY does not
  1667. * ??? send/receive packets...
  1668. */
  1669. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1670. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1671. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1672. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1673. udelay(80);
  1674. }
  1675. tw32_f(MAC_MODE, tp->mac_mode);
  1676. udelay(40);
  1677. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1678. /* Polled via timer. */
  1679. tw32_f(MAC_EVENT, 0);
  1680. } else {
  1681. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1682. }
  1683. udelay(40);
  1684. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1685. current_link_up == 1 &&
  1686. tp->link_config.active_speed == SPEED_1000 &&
  1687. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1688. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1689. udelay(120);
  1690. tw32_f(MAC_STATUS,
  1691. (MAC_STATUS_SYNC_CHANGED |
  1692. MAC_STATUS_CFG_CHANGED));
  1693. udelay(40);
  1694. tg3_write_mem(tp,
  1695. NIC_SRAM_FIRMWARE_MBOX,
  1696. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1697. }
  1698. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1699. if (current_link_up)
  1700. netif_carrier_on(tp->dev);
  1701. else
  1702. netif_carrier_off(tp->dev);
  1703. tg3_link_report(tp);
  1704. }
  1705. return 0;
  1706. }
  1707. struct tg3_fiber_aneginfo {
  1708. int state;
  1709. #define ANEG_STATE_UNKNOWN 0
  1710. #define ANEG_STATE_AN_ENABLE 1
  1711. #define ANEG_STATE_RESTART_INIT 2
  1712. #define ANEG_STATE_RESTART 3
  1713. #define ANEG_STATE_DISABLE_LINK_OK 4
  1714. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1715. #define ANEG_STATE_ABILITY_DETECT 6
  1716. #define ANEG_STATE_ACK_DETECT_INIT 7
  1717. #define ANEG_STATE_ACK_DETECT 8
  1718. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1719. #define ANEG_STATE_COMPLETE_ACK 10
  1720. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1721. #define ANEG_STATE_IDLE_DETECT 12
  1722. #define ANEG_STATE_LINK_OK 13
  1723. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1724. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1725. u32 flags;
  1726. #define MR_AN_ENABLE 0x00000001
  1727. #define MR_RESTART_AN 0x00000002
  1728. #define MR_AN_COMPLETE 0x00000004
  1729. #define MR_PAGE_RX 0x00000008
  1730. #define MR_NP_LOADED 0x00000010
  1731. #define MR_TOGGLE_TX 0x00000020
  1732. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1733. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1734. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1735. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1736. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1737. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1738. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1739. #define MR_TOGGLE_RX 0x00002000
  1740. #define MR_NP_RX 0x00004000
  1741. #define MR_LINK_OK 0x80000000
  1742. unsigned long link_time, cur_time;
  1743. u32 ability_match_cfg;
  1744. int ability_match_count;
  1745. char ability_match, idle_match, ack_match;
  1746. u32 txconfig, rxconfig;
  1747. #define ANEG_CFG_NP 0x00000080
  1748. #define ANEG_CFG_ACK 0x00000040
  1749. #define ANEG_CFG_RF2 0x00000020
  1750. #define ANEG_CFG_RF1 0x00000010
  1751. #define ANEG_CFG_PS2 0x00000001
  1752. #define ANEG_CFG_PS1 0x00008000
  1753. #define ANEG_CFG_HD 0x00004000
  1754. #define ANEG_CFG_FD 0x00002000
  1755. #define ANEG_CFG_INVAL 0x00001f06
  1756. };
  1757. #define ANEG_OK 0
  1758. #define ANEG_DONE 1
  1759. #define ANEG_TIMER_ENAB 2
  1760. #define ANEG_FAILED -1
  1761. #define ANEG_STATE_SETTLE_TIME 10000
  1762. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1763. struct tg3_fiber_aneginfo *ap)
  1764. {
  1765. unsigned long delta;
  1766. u32 rx_cfg_reg;
  1767. int ret;
  1768. if (ap->state == ANEG_STATE_UNKNOWN) {
  1769. ap->rxconfig = 0;
  1770. ap->link_time = 0;
  1771. ap->cur_time = 0;
  1772. ap->ability_match_cfg = 0;
  1773. ap->ability_match_count = 0;
  1774. ap->ability_match = 0;
  1775. ap->idle_match = 0;
  1776. ap->ack_match = 0;
  1777. }
  1778. ap->cur_time++;
  1779. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1780. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1781. if (rx_cfg_reg != ap->ability_match_cfg) {
  1782. ap->ability_match_cfg = rx_cfg_reg;
  1783. ap->ability_match = 0;
  1784. ap->ability_match_count = 0;
  1785. } else {
  1786. if (++ap->ability_match_count > 1) {
  1787. ap->ability_match = 1;
  1788. ap->ability_match_cfg = rx_cfg_reg;
  1789. }
  1790. }
  1791. if (rx_cfg_reg & ANEG_CFG_ACK)
  1792. ap->ack_match = 1;
  1793. else
  1794. ap->ack_match = 0;
  1795. ap->idle_match = 0;
  1796. } else {
  1797. ap->idle_match = 1;
  1798. ap->ability_match_cfg = 0;
  1799. ap->ability_match_count = 0;
  1800. ap->ability_match = 0;
  1801. ap->ack_match = 0;
  1802. rx_cfg_reg = 0;
  1803. }
  1804. ap->rxconfig = rx_cfg_reg;
  1805. ret = ANEG_OK;
  1806. switch(ap->state) {
  1807. case ANEG_STATE_UNKNOWN:
  1808. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1809. ap->state = ANEG_STATE_AN_ENABLE;
  1810. /* fallthru */
  1811. case ANEG_STATE_AN_ENABLE:
  1812. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1813. if (ap->flags & MR_AN_ENABLE) {
  1814. ap->link_time = 0;
  1815. ap->cur_time = 0;
  1816. ap->ability_match_cfg = 0;
  1817. ap->ability_match_count = 0;
  1818. ap->ability_match = 0;
  1819. ap->idle_match = 0;
  1820. ap->ack_match = 0;
  1821. ap->state = ANEG_STATE_RESTART_INIT;
  1822. } else {
  1823. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1824. }
  1825. break;
  1826. case ANEG_STATE_RESTART_INIT:
  1827. ap->link_time = ap->cur_time;
  1828. ap->flags &= ~(MR_NP_LOADED);
  1829. ap->txconfig = 0;
  1830. tw32(MAC_TX_AUTO_NEG, 0);
  1831. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1832. tw32_f(MAC_MODE, tp->mac_mode);
  1833. udelay(40);
  1834. ret = ANEG_TIMER_ENAB;
  1835. ap->state = ANEG_STATE_RESTART;
  1836. /* fallthru */
  1837. case ANEG_STATE_RESTART:
  1838. delta = ap->cur_time - ap->link_time;
  1839. if (delta > ANEG_STATE_SETTLE_TIME) {
  1840. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1841. } else {
  1842. ret = ANEG_TIMER_ENAB;
  1843. }
  1844. break;
  1845. case ANEG_STATE_DISABLE_LINK_OK:
  1846. ret = ANEG_DONE;
  1847. break;
  1848. case ANEG_STATE_ABILITY_DETECT_INIT:
  1849. ap->flags &= ~(MR_TOGGLE_TX);
  1850. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1851. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1852. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1853. tw32_f(MAC_MODE, tp->mac_mode);
  1854. udelay(40);
  1855. ap->state = ANEG_STATE_ABILITY_DETECT;
  1856. break;
  1857. case ANEG_STATE_ABILITY_DETECT:
  1858. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1859. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1860. }
  1861. break;
  1862. case ANEG_STATE_ACK_DETECT_INIT:
  1863. ap->txconfig |= ANEG_CFG_ACK;
  1864. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1865. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1866. tw32_f(MAC_MODE, tp->mac_mode);
  1867. udelay(40);
  1868. ap->state = ANEG_STATE_ACK_DETECT;
  1869. /* fallthru */
  1870. case ANEG_STATE_ACK_DETECT:
  1871. if (ap->ack_match != 0) {
  1872. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1873. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1874. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1875. } else {
  1876. ap->state = ANEG_STATE_AN_ENABLE;
  1877. }
  1878. } else if (ap->ability_match != 0 &&
  1879. ap->rxconfig == 0) {
  1880. ap->state = ANEG_STATE_AN_ENABLE;
  1881. }
  1882. break;
  1883. case ANEG_STATE_COMPLETE_ACK_INIT:
  1884. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1885. ret = ANEG_FAILED;
  1886. break;
  1887. }
  1888. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1889. MR_LP_ADV_HALF_DUPLEX |
  1890. MR_LP_ADV_SYM_PAUSE |
  1891. MR_LP_ADV_ASYM_PAUSE |
  1892. MR_LP_ADV_REMOTE_FAULT1 |
  1893. MR_LP_ADV_REMOTE_FAULT2 |
  1894. MR_LP_ADV_NEXT_PAGE |
  1895. MR_TOGGLE_RX |
  1896. MR_NP_RX);
  1897. if (ap->rxconfig & ANEG_CFG_FD)
  1898. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1899. if (ap->rxconfig & ANEG_CFG_HD)
  1900. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1901. if (ap->rxconfig & ANEG_CFG_PS1)
  1902. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1903. if (ap->rxconfig & ANEG_CFG_PS2)
  1904. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1905. if (ap->rxconfig & ANEG_CFG_RF1)
  1906. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1907. if (ap->rxconfig & ANEG_CFG_RF2)
  1908. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1909. if (ap->rxconfig & ANEG_CFG_NP)
  1910. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1911. ap->link_time = ap->cur_time;
  1912. ap->flags ^= (MR_TOGGLE_TX);
  1913. if (ap->rxconfig & 0x0008)
  1914. ap->flags |= MR_TOGGLE_RX;
  1915. if (ap->rxconfig & ANEG_CFG_NP)
  1916. ap->flags |= MR_NP_RX;
  1917. ap->flags |= MR_PAGE_RX;
  1918. ap->state = ANEG_STATE_COMPLETE_ACK;
  1919. ret = ANEG_TIMER_ENAB;
  1920. break;
  1921. case ANEG_STATE_COMPLETE_ACK:
  1922. if (ap->ability_match != 0 &&
  1923. ap->rxconfig == 0) {
  1924. ap->state = ANEG_STATE_AN_ENABLE;
  1925. break;
  1926. }
  1927. delta = ap->cur_time - ap->link_time;
  1928. if (delta > ANEG_STATE_SETTLE_TIME) {
  1929. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  1930. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1931. } else {
  1932. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  1933. !(ap->flags & MR_NP_RX)) {
  1934. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1935. } else {
  1936. ret = ANEG_FAILED;
  1937. }
  1938. }
  1939. }
  1940. break;
  1941. case ANEG_STATE_IDLE_DETECT_INIT:
  1942. ap->link_time = ap->cur_time;
  1943. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1944. tw32_f(MAC_MODE, tp->mac_mode);
  1945. udelay(40);
  1946. ap->state = ANEG_STATE_IDLE_DETECT;
  1947. ret = ANEG_TIMER_ENAB;
  1948. break;
  1949. case ANEG_STATE_IDLE_DETECT:
  1950. if (ap->ability_match != 0 &&
  1951. ap->rxconfig == 0) {
  1952. ap->state = ANEG_STATE_AN_ENABLE;
  1953. break;
  1954. }
  1955. delta = ap->cur_time - ap->link_time;
  1956. if (delta > ANEG_STATE_SETTLE_TIME) {
  1957. /* XXX another gem from the Broadcom driver :( */
  1958. ap->state = ANEG_STATE_LINK_OK;
  1959. }
  1960. break;
  1961. case ANEG_STATE_LINK_OK:
  1962. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1963. ret = ANEG_DONE;
  1964. break;
  1965. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1966. /* ??? unimplemented */
  1967. break;
  1968. case ANEG_STATE_NEXT_PAGE_WAIT:
  1969. /* ??? unimplemented */
  1970. break;
  1971. default:
  1972. ret = ANEG_FAILED;
  1973. break;
  1974. };
  1975. return ret;
  1976. }
  1977. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  1978. {
  1979. int res = 0;
  1980. struct tg3_fiber_aneginfo aninfo;
  1981. int status = ANEG_FAILED;
  1982. unsigned int tick;
  1983. u32 tmp;
  1984. tw32_f(MAC_TX_AUTO_NEG, 0);
  1985. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  1986. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  1987. udelay(40);
  1988. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  1989. udelay(40);
  1990. memset(&aninfo, 0, sizeof(aninfo));
  1991. aninfo.flags |= MR_AN_ENABLE;
  1992. aninfo.state = ANEG_STATE_UNKNOWN;
  1993. aninfo.cur_time = 0;
  1994. tick = 0;
  1995. while (++tick < 195000) {
  1996. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  1997. if (status == ANEG_DONE || status == ANEG_FAILED)
  1998. break;
  1999. udelay(1);
  2000. }
  2001. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2002. tw32_f(MAC_MODE, tp->mac_mode);
  2003. udelay(40);
  2004. *flags = aninfo.flags;
  2005. if (status == ANEG_DONE &&
  2006. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2007. MR_LP_ADV_FULL_DUPLEX)))
  2008. res = 1;
  2009. return res;
  2010. }
  2011. static void tg3_init_bcm8002(struct tg3 *tp)
  2012. {
  2013. u32 mac_status = tr32(MAC_STATUS);
  2014. int i;
  2015. /* Reset when initting first time or we have a link. */
  2016. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2017. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2018. return;
  2019. /* Set PLL lock range. */
  2020. tg3_writephy(tp, 0x16, 0x8007);
  2021. /* SW reset */
  2022. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2023. /* Wait for reset to complete. */
  2024. /* XXX schedule_timeout() ... */
  2025. for (i = 0; i < 500; i++)
  2026. udelay(10);
  2027. /* Config mode; select PMA/Ch 1 regs. */
  2028. tg3_writephy(tp, 0x10, 0x8411);
  2029. /* Enable auto-lock and comdet, select txclk for tx. */
  2030. tg3_writephy(tp, 0x11, 0x0a10);
  2031. tg3_writephy(tp, 0x18, 0x00a0);
  2032. tg3_writephy(tp, 0x16, 0x41ff);
  2033. /* Assert and deassert POR. */
  2034. tg3_writephy(tp, 0x13, 0x0400);
  2035. udelay(40);
  2036. tg3_writephy(tp, 0x13, 0x0000);
  2037. tg3_writephy(tp, 0x11, 0x0a50);
  2038. udelay(40);
  2039. tg3_writephy(tp, 0x11, 0x0a10);
  2040. /* Wait for signal to stabilize */
  2041. /* XXX schedule_timeout() ... */
  2042. for (i = 0; i < 15000; i++)
  2043. udelay(10);
  2044. /* Deselect the channel register so we can read the PHYID
  2045. * later.
  2046. */
  2047. tg3_writephy(tp, 0x10, 0x8011);
  2048. }
  2049. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2050. {
  2051. u32 sg_dig_ctrl, sg_dig_status;
  2052. u32 serdes_cfg, expected_sg_dig_ctrl;
  2053. int workaround, port_a;
  2054. int current_link_up;
  2055. serdes_cfg = 0;
  2056. expected_sg_dig_ctrl = 0;
  2057. workaround = 0;
  2058. port_a = 1;
  2059. current_link_up = 0;
  2060. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2061. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2062. workaround = 1;
  2063. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2064. port_a = 0;
  2065. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2066. /* preserve bits 20-23 for voltage regulator */
  2067. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2068. }
  2069. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2070. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2071. if (sg_dig_ctrl & (1 << 31)) {
  2072. if (workaround) {
  2073. u32 val = serdes_cfg;
  2074. if (port_a)
  2075. val |= 0xc010000;
  2076. else
  2077. val |= 0x4010000;
  2078. tw32_f(MAC_SERDES_CFG, val);
  2079. }
  2080. tw32_f(SG_DIG_CTRL, 0x01388400);
  2081. }
  2082. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2083. tg3_setup_flow_control(tp, 0, 0);
  2084. current_link_up = 1;
  2085. }
  2086. goto out;
  2087. }
  2088. /* Want auto-negotiation. */
  2089. expected_sg_dig_ctrl = 0x81388400;
  2090. /* Pause capability */
  2091. expected_sg_dig_ctrl |= (1 << 11);
  2092. /* Asymettric pause */
  2093. expected_sg_dig_ctrl |= (1 << 12);
  2094. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2095. if (workaround)
  2096. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2097. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2098. udelay(5);
  2099. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2100. tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED;
  2101. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2102. MAC_STATUS_SIGNAL_DET)) {
  2103. int i;
  2104. /* Giver time to negotiate (~200ms) */
  2105. for (i = 0; i < 40000; i++) {
  2106. sg_dig_status = tr32(SG_DIG_STATUS);
  2107. if (sg_dig_status & (0x3))
  2108. break;
  2109. udelay(5);
  2110. }
  2111. mac_status = tr32(MAC_STATUS);
  2112. if ((sg_dig_status & (1 << 1)) &&
  2113. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2114. u32 local_adv, remote_adv;
  2115. local_adv = ADVERTISE_PAUSE_CAP;
  2116. remote_adv = 0;
  2117. if (sg_dig_status & (1 << 19))
  2118. remote_adv |= LPA_PAUSE_CAP;
  2119. if (sg_dig_status & (1 << 20))
  2120. remote_adv |= LPA_PAUSE_ASYM;
  2121. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2122. current_link_up = 1;
  2123. tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
  2124. } else if (!(sg_dig_status & (1 << 1))) {
  2125. if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED)
  2126. tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
  2127. else {
  2128. if (workaround) {
  2129. u32 val = serdes_cfg;
  2130. if (port_a)
  2131. val |= 0xc010000;
  2132. else
  2133. val |= 0x4010000;
  2134. tw32_f(MAC_SERDES_CFG, val);
  2135. }
  2136. tw32_f(SG_DIG_CTRL, 0x01388400);
  2137. udelay(40);
  2138. /* Link parallel detection - link is up */
  2139. /* only if we have PCS_SYNC and not */
  2140. /* receiving config code words */
  2141. mac_status = tr32(MAC_STATUS);
  2142. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2143. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2144. tg3_setup_flow_control(tp, 0, 0);
  2145. current_link_up = 1;
  2146. }
  2147. }
  2148. }
  2149. }
  2150. out:
  2151. return current_link_up;
  2152. }
  2153. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2154. {
  2155. int current_link_up = 0;
  2156. if (!(mac_status & MAC_STATUS_PCS_SYNCED)) {
  2157. tp->tg3_flags &= ~TG3_FLAG_GOT_SERDES_FLOWCTL;
  2158. goto out;
  2159. }
  2160. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2161. u32 flags;
  2162. int i;
  2163. if (fiber_autoneg(tp, &flags)) {
  2164. u32 local_adv, remote_adv;
  2165. local_adv = ADVERTISE_PAUSE_CAP;
  2166. remote_adv = 0;
  2167. if (flags & MR_LP_ADV_SYM_PAUSE)
  2168. remote_adv |= LPA_PAUSE_CAP;
  2169. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2170. remote_adv |= LPA_PAUSE_ASYM;
  2171. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2172. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2173. current_link_up = 1;
  2174. }
  2175. for (i = 0; i < 30; i++) {
  2176. udelay(20);
  2177. tw32_f(MAC_STATUS,
  2178. (MAC_STATUS_SYNC_CHANGED |
  2179. MAC_STATUS_CFG_CHANGED));
  2180. udelay(40);
  2181. if ((tr32(MAC_STATUS) &
  2182. (MAC_STATUS_SYNC_CHANGED |
  2183. MAC_STATUS_CFG_CHANGED)) == 0)
  2184. break;
  2185. }
  2186. mac_status = tr32(MAC_STATUS);
  2187. if (current_link_up == 0 &&
  2188. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2189. !(mac_status & MAC_STATUS_RCVD_CFG))
  2190. current_link_up = 1;
  2191. } else {
  2192. /* Forcing 1000FD link up. */
  2193. current_link_up = 1;
  2194. tp->tg3_flags |= TG3_FLAG_GOT_SERDES_FLOWCTL;
  2195. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2196. udelay(40);
  2197. }
  2198. out:
  2199. return current_link_up;
  2200. }
  2201. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2202. {
  2203. u32 orig_pause_cfg;
  2204. u16 orig_active_speed;
  2205. u8 orig_active_duplex;
  2206. u32 mac_status;
  2207. int current_link_up;
  2208. int i;
  2209. orig_pause_cfg =
  2210. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2211. TG3_FLAG_TX_PAUSE));
  2212. orig_active_speed = tp->link_config.active_speed;
  2213. orig_active_duplex = tp->link_config.active_duplex;
  2214. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2215. netif_carrier_ok(tp->dev) &&
  2216. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2217. mac_status = tr32(MAC_STATUS);
  2218. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2219. MAC_STATUS_SIGNAL_DET |
  2220. MAC_STATUS_CFG_CHANGED |
  2221. MAC_STATUS_RCVD_CFG);
  2222. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2223. MAC_STATUS_SIGNAL_DET)) {
  2224. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2225. MAC_STATUS_CFG_CHANGED));
  2226. return 0;
  2227. }
  2228. }
  2229. tw32_f(MAC_TX_AUTO_NEG, 0);
  2230. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2231. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2232. tw32_f(MAC_MODE, tp->mac_mode);
  2233. udelay(40);
  2234. if (tp->phy_id == PHY_ID_BCM8002)
  2235. tg3_init_bcm8002(tp);
  2236. /* Enable link change event even when serdes polling. */
  2237. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2238. udelay(40);
  2239. current_link_up = 0;
  2240. mac_status = tr32(MAC_STATUS);
  2241. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2242. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2243. else
  2244. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2245. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  2246. tw32_f(MAC_MODE, tp->mac_mode);
  2247. udelay(40);
  2248. tp->hw_status->status =
  2249. (SD_STATUS_UPDATED |
  2250. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2251. for (i = 0; i < 100; i++) {
  2252. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2253. MAC_STATUS_CFG_CHANGED));
  2254. udelay(5);
  2255. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2256. MAC_STATUS_CFG_CHANGED)) == 0)
  2257. break;
  2258. }
  2259. mac_status = tr32(MAC_STATUS);
  2260. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2261. current_link_up = 0;
  2262. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2263. tw32_f(MAC_MODE, (tp->mac_mode |
  2264. MAC_MODE_SEND_CONFIGS));
  2265. udelay(1);
  2266. tw32_f(MAC_MODE, tp->mac_mode);
  2267. }
  2268. }
  2269. if (current_link_up == 1) {
  2270. tp->link_config.active_speed = SPEED_1000;
  2271. tp->link_config.active_duplex = DUPLEX_FULL;
  2272. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2273. LED_CTRL_LNKLED_OVERRIDE |
  2274. LED_CTRL_1000MBPS_ON));
  2275. } else {
  2276. tp->link_config.active_speed = SPEED_INVALID;
  2277. tp->link_config.active_duplex = DUPLEX_INVALID;
  2278. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2279. LED_CTRL_LNKLED_OVERRIDE |
  2280. LED_CTRL_TRAFFIC_OVERRIDE));
  2281. }
  2282. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2283. if (current_link_up)
  2284. netif_carrier_on(tp->dev);
  2285. else
  2286. netif_carrier_off(tp->dev);
  2287. tg3_link_report(tp);
  2288. } else {
  2289. u32 now_pause_cfg =
  2290. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2291. TG3_FLAG_TX_PAUSE);
  2292. if (orig_pause_cfg != now_pause_cfg ||
  2293. orig_active_speed != tp->link_config.active_speed ||
  2294. orig_active_duplex != tp->link_config.active_duplex)
  2295. tg3_link_report(tp);
  2296. }
  2297. return 0;
  2298. }
  2299. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2300. {
  2301. int current_link_up, err = 0;
  2302. u32 bmsr, bmcr;
  2303. u16 current_speed;
  2304. u8 current_duplex;
  2305. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2306. tw32_f(MAC_MODE, tp->mac_mode);
  2307. udelay(40);
  2308. tw32(MAC_EVENT, 0);
  2309. tw32_f(MAC_STATUS,
  2310. (MAC_STATUS_SYNC_CHANGED |
  2311. MAC_STATUS_CFG_CHANGED |
  2312. MAC_STATUS_MI_COMPLETION |
  2313. MAC_STATUS_LNKSTATE_CHANGED));
  2314. udelay(40);
  2315. if (force_reset)
  2316. tg3_phy_reset(tp);
  2317. current_link_up = 0;
  2318. current_speed = SPEED_INVALID;
  2319. current_duplex = DUPLEX_INVALID;
  2320. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2321. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2322. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2323. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2324. bmsr |= BMSR_LSTATUS;
  2325. else
  2326. bmsr &= ~BMSR_LSTATUS;
  2327. }
  2328. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2329. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2330. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2331. /* do nothing, just check for link up at the end */
  2332. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2333. u32 adv, new_adv;
  2334. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2335. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2336. ADVERTISE_1000XPAUSE |
  2337. ADVERTISE_1000XPSE_ASYM |
  2338. ADVERTISE_SLCT);
  2339. /* Always advertise symmetric PAUSE just like copper */
  2340. new_adv |= ADVERTISE_1000XPAUSE;
  2341. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2342. new_adv |= ADVERTISE_1000XHALF;
  2343. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2344. new_adv |= ADVERTISE_1000XFULL;
  2345. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2346. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2347. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2348. tg3_writephy(tp, MII_BMCR, bmcr);
  2349. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2350. tp->tg3_flags2 |= TG3_FLG2_PHY_JUST_INITTED;
  2351. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2352. return err;
  2353. }
  2354. } else {
  2355. u32 new_bmcr;
  2356. bmcr &= ~BMCR_SPEED1000;
  2357. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2358. if (tp->link_config.duplex == DUPLEX_FULL)
  2359. new_bmcr |= BMCR_FULLDPLX;
  2360. if (new_bmcr != bmcr) {
  2361. /* BMCR_SPEED1000 is a reserved bit that needs
  2362. * to be set on write.
  2363. */
  2364. new_bmcr |= BMCR_SPEED1000;
  2365. /* Force a linkdown */
  2366. if (netif_carrier_ok(tp->dev)) {
  2367. u32 adv;
  2368. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2369. adv &= ~(ADVERTISE_1000XFULL |
  2370. ADVERTISE_1000XHALF |
  2371. ADVERTISE_SLCT);
  2372. tg3_writephy(tp, MII_ADVERTISE, adv);
  2373. tg3_writephy(tp, MII_BMCR, bmcr |
  2374. BMCR_ANRESTART |
  2375. BMCR_ANENABLE);
  2376. udelay(10);
  2377. netif_carrier_off(tp->dev);
  2378. }
  2379. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2380. bmcr = new_bmcr;
  2381. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2382. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2383. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2384. ASIC_REV_5714) {
  2385. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2386. bmsr |= BMSR_LSTATUS;
  2387. else
  2388. bmsr &= ~BMSR_LSTATUS;
  2389. }
  2390. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2391. }
  2392. }
  2393. if (bmsr & BMSR_LSTATUS) {
  2394. current_speed = SPEED_1000;
  2395. current_link_up = 1;
  2396. if (bmcr & BMCR_FULLDPLX)
  2397. current_duplex = DUPLEX_FULL;
  2398. else
  2399. current_duplex = DUPLEX_HALF;
  2400. if (bmcr & BMCR_ANENABLE) {
  2401. u32 local_adv, remote_adv, common;
  2402. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2403. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2404. common = local_adv & remote_adv;
  2405. if (common & (ADVERTISE_1000XHALF |
  2406. ADVERTISE_1000XFULL)) {
  2407. if (common & ADVERTISE_1000XFULL)
  2408. current_duplex = DUPLEX_FULL;
  2409. else
  2410. current_duplex = DUPLEX_HALF;
  2411. tg3_setup_flow_control(tp, local_adv,
  2412. remote_adv);
  2413. }
  2414. else
  2415. current_link_up = 0;
  2416. }
  2417. }
  2418. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2419. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2420. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2421. tw32_f(MAC_MODE, tp->mac_mode);
  2422. udelay(40);
  2423. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2424. tp->link_config.active_speed = current_speed;
  2425. tp->link_config.active_duplex = current_duplex;
  2426. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2427. if (current_link_up)
  2428. netif_carrier_on(tp->dev);
  2429. else {
  2430. netif_carrier_off(tp->dev);
  2431. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2432. }
  2433. tg3_link_report(tp);
  2434. }
  2435. return err;
  2436. }
  2437. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2438. {
  2439. if (tp->tg3_flags2 & TG3_FLG2_PHY_JUST_INITTED) {
  2440. /* Give autoneg time to complete. */
  2441. tp->tg3_flags2 &= ~TG3_FLG2_PHY_JUST_INITTED;
  2442. return;
  2443. }
  2444. if (!netif_carrier_ok(tp->dev) &&
  2445. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2446. u32 bmcr;
  2447. tg3_readphy(tp, MII_BMCR, &bmcr);
  2448. if (bmcr & BMCR_ANENABLE) {
  2449. u32 phy1, phy2;
  2450. /* Select shadow register 0x1f */
  2451. tg3_writephy(tp, 0x1c, 0x7c00);
  2452. tg3_readphy(tp, 0x1c, &phy1);
  2453. /* Select expansion interrupt status register */
  2454. tg3_writephy(tp, 0x17, 0x0f01);
  2455. tg3_readphy(tp, 0x15, &phy2);
  2456. tg3_readphy(tp, 0x15, &phy2);
  2457. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2458. /* We have signal detect and not receiving
  2459. * config code words, link is up by parallel
  2460. * detection.
  2461. */
  2462. bmcr &= ~BMCR_ANENABLE;
  2463. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2464. tg3_writephy(tp, MII_BMCR, bmcr);
  2465. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2466. }
  2467. }
  2468. }
  2469. else if (netif_carrier_ok(tp->dev) &&
  2470. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2471. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2472. u32 phy2;
  2473. /* Select expansion interrupt status register */
  2474. tg3_writephy(tp, 0x17, 0x0f01);
  2475. tg3_readphy(tp, 0x15, &phy2);
  2476. if (phy2 & 0x20) {
  2477. u32 bmcr;
  2478. /* Config code words received, turn on autoneg. */
  2479. tg3_readphy(tp, MII_BMCR, &bmcr);
  2480. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2481. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2482. }
  2483. }
  2484. }
  2485. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2486. {
  2487. int err;
  2488. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2489. err = tg3_setup_fiber_phy(tp, force_reset);
  2490. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2491. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2492. } else {
  2493. err = tg3_setup_copper_phy(tp, force_reset);
  2494. }
  2495. if (tp->link_config.active_speed == SPEED_1000 &&
  2496. tp->link_config.active_duplex == DUPLEX_HALF)
  2497. tw32(MAC_TX_LENGTHS,
  2498. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2499. (6 << TX_LENGTHS_IPG_SHIFT) |
  2500. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2501. else
  2502. tw32(MAC_TX_LENGTHS,
  2503. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2504. (6 << TX_LENGTHS_IPG_SHIFT) |
  2505. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2506. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2507. if (netif_carrier_ok(tp->dev)) {
  2508. tw32(HOSTCC_STAT_COAL_TICKS,
  2509. tp->coal.stats_block_coalesce_usecs);
  2510. } else {
  2511. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2512. }
  2513. }
  2514. return err;
  2515. }
  2516. /* This is called whenever we suspect that the system chipset is re-
  2517. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2518. * is bogus tx completions. We try to recover by setting the
  2519. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2520. * in the workqueue.
  2521. */
  2522. static void tg3_tx_recover(struct tg3 *tp)
  2523. {
  2524. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2525. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2526. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2527. "mapped I/O cycles to the network device, attempting to "
  2528. "recover. Please report the problem to the driver maintainer "
  2529. "and include system chipset information.\n", tp->dev->name);
  2530. spin_lock(&tp->lock);
  2531. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2532. spin_unlock(&tp->lock);
  2533. }
  2534. /* Tigon3 never reports partial packet sends. So we do not
  2535. * need special logic to handle SKBs that have not had all
  2536. * of their frags sent yet, like SunGEM does.
  2537. */
  2538. static void tg3_tx(struct tg3 *tp)
  2539. {
  2540. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2541. u32 sw_idx = tp->tx_cons;
  2542. while (sw_idx != hw_idx) {
  2543. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2544. struct sk_buff *skb = ri->skb;
  2545. int i, tx_bug = 0;
  2546. if (unlikely(skb == NULL)) {
  2547. tg3_tx_recover(tp);
  2548. return;
  2549. }
  2550. pci_unmap_single(tp->pdev,
  2551. pci_unmap_addr(ri, mapping),
  2552. skb_headlen(skb),
  2553. PCI_DMA_TODEVICE);
  2554. ri->skb = NULL;
  2555. sw_idx = NEXT_TX(sw_idx);
  2556. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2557. ri = &tp->tx_buffers[sw_idx];
  2558. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2559. tx_bug = 1;
  2560. pci_unmap_page(tp->pdev,
  2561. pci_unmap_addr(ri, mapping),
  2562. skb_shinfo(skb)->frags[i].size,
  2563. PCI_DMA_TODEVICE);
  2564. sw_idx = NEXT_TX(sw_idx);
  2565. }
  2566. dev_kfree_skb(skb);
  2567. if (unlikely(tx_bug)) {
  2568. tg3_tx_recover(tp);
  2569. return;
  2570. }
  2571. }
  2572. tp->tx_cons = sw_idx;
  2573. if (unlikely(netif_queue_stopped(tp->dev))) {
  2574. spin_lock(&tp->tx_lock);
  2575. if (netif_queue_stopped(tp->dev) &&
  2576. (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH))
  2577. netif_wake_queue(tp->dev);
  2578. spin_unlock(&tp->tx_lock);
  2579. }
  2580. }
  2581. /* Returns size of skb allocated or < 0 on error.
  2582. *
  2583. * We only need to fill in the address because the other members
  2584. * of the RX descriptor are invariant, see tg3_init_rings.
  2585. *
  2586. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2587. * posting buffers we only dirty the first cache line of the RX
  2588. * descriptor (containing the address). Whereas for the RX status
  2589. * buffers the cpu only reads the last cacheline of the RX descriptor
  2590. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2591. */
  2592. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2593. int src_idx, u32 dest_idx_unmasked)
  2594. {
  2595. struct tg3_rx_buffer_desc *desc;
  2596. struct ring_info *map, *src_map;
  2597. struct sk_buff *skb;
  2598. dma_addr_t mapping;
  2599. int skb_size, dest_idx;
  2600. src_map = NULL;
  2601. switch (opaque_key) {
  2602. case RXD_OPAQUE_RING_STD:
  2603. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2604. desc = &tp->rx_std[dest_idx];
  2605. map = &tp->rx_std_buffers[dest_idx];
  2606. if (src_idx >= 0)
  2607. src_map = &tp->rx_std_buffers[src_idx];
  2608. skb_size = tp->rx_pkt_buf_sz;
  2609. break;
  2610. case RXD_OPAQUE_RING_JUMBO:
  2611. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2612. desc = &tp->rx_jumbo[dest_idx];
  2613. map = &tp->rx_jumbo_buffers[dest_idx];
  2614. if (src_idx >= 0)
  2615. src_map = &tp->rx_jumbo_buffers[src_idx];
  2616. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2617. break;
  2618. default:
  2619. return -EINVAL;
  2620. };
  2621. /* Do not overwrite any of the map or rp information
  2622. * until we are sure we can commit to a new buffer.
  2623. *
  2624. * Callers depend upon this behavior and assume that
  2625. * we leave everything unchanged if we fail.
  2626. */
  2627. skb = dev_alloc_skb(skb_size);
  2628. if (skb == NULL)
  2629. return -ENOMEM;
  2630. skb->dev = tp->dev;
  2631. skb_reserve(skb, tp->rx_offset);
  2632. mapping = pci_map_single(tp->pdev, skb->data,
  2633. skb_size - tp->rx_offset,
  2634. PCI_DMA_FROMDEVICE);
  2635. map->skb = skb;
  2636. pci_unmap_addr_set(map, mapping, mapping);
  2637. if (src_map != NULL)
  2638. src_map->skb = NULL;
  2639. desc->addr_hi = ((u64)mapping >> 32);
  2640. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2641. return skb_size;
  2642. }
  2643. /* We only need to move over in the address because the other
  2644. * members of the RX descriptor are invariant. See notes above
  2645. * tg3_alloc_rx_skb for full details.
  2646. */
  2647. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2648. int src_idx, u32 dest_idx_unmasked)
  2649. {
  2650. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2651. struct ring_info *src_map, *dest_map;
  2652. int dest_idx;
  2653. switch (opaque_key) {
  2654. case RXD_OPAQUE_RING_STD:
  2655. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2656. dest_desc = &tp->rx_std[dest_idx];
  2657. dest_map = &tp->rx_std_buffers[dest_idx];
  2658. src_desc = &tp->rx_std[src_idx];
  2659. src_map = &tp->rx_std_buffers[src_idx];
  2660. break;
  2661. case RXD_OPAQUE_RING_JUMBO:
  2662. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2663. dest_desc = &tp->rx_jumbo[dest_idx];
  2664. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2665. src_desc = &tp->rx_jumbo[src_idx];
  2666. src_map = &tp->rx_jumbo_buffers[src_idx];
  2667. break;
  2668. default:
  2669. return;
  2670. };
  2671. dest_map->skb = src_map->skb;
  2672. pci_unmap_addr_set(dest_map, mapping,
  2673. pci_unmap_addr(src_map, mapping));
  2674. dest_desc->addr_hi = src_desc->addr_hi;
  2675. dest_desc->addr_lo = src_desc->addr_lo;
  2676. src_map->skb = NULL;
  2677. }
  2678. #if TG3_VLAN_TAG_USED
  2679. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2680. {
  2681. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2682. }
  2683. #endif
  2684. /* The RX ring scheme is composed of multiple rings which post fresh
  2685. * buffers to the chip, and one special ring the chip uses to report
  2686. * status back to the host.
  2687. *
  2688. * The special ring reports the status of received packets to the
  2689. * host. The chip does not write into the original descriptor the
  2690. * RX buffer was obtained from. The chip simply takes the original
  2691. * descriptor as provided by the host, updates the status and length
  2692. * field, then writes this into the next status ring entry.
  2693. *
  2694. * Each ring the host uses to post buffers to the chip is described
  2695. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2696. * it is first placed into the on-chip ram. When the packet's length
  2697. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2698. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2699. * which is within the range of the new packet's length is chosen.
  2700. *
  2701. * The "separate ring for rx status" scheme may sound queer, but it makes
  2702. * sense from a cache coherency perspective. If only the host writes
  2703. * to the buffer post rings, and only the chip writes to the rx status
  2704. * rings, then cache lines never move beyond shared-modified state.
  2705. * If both the host and chip were to write into the same ring, cache line
  2706. * eviction could occur since both entities want it in an exclusive state.
  2707. */
  2708. static int tg3_rx(struct tg3 *tp, int budget)
  2709. {
  2710. u32 work_mask, rx_std_posted = 0;
  2711. u32 sw_idx = tp->rx_rcb_ptr;
  2712. u16 hw_idx;
  2713. int received;
  2714. hw_idx = tp->hw_status->idx[0].rx_producer;
  2715. /*
  2716. * We need to order the read of hw_idx and the read of
  2717. * the opaque cookie.
  2718. */
  2719. rmb();
  2720. work_mask = 0;
  2721. received = 0;
  2722. while (sw_idx != hw_idx && budget > 0) {
  2723. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2724. unsigned int len;
  2725. struct sk_buff *skb;
  2726. dma_addr_t dma_addr;
  2727. u32 opaque_key, desc_idx, *post_ptr;
  2728. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2729. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2730. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2731. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2732. mapping);
  2733. skb = tp->rx_std_buffers[desc_idx].skb;
  2734. post_ptr = &tp->rx_std_ptr;
  2735. rx_std_posted++;
  2736. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2737. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2738. mapping);
  2739. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2740. post_ptr = &tp->rx_jumbo_ptr;
  2741. }
  2742. else {
  2743. goto next_pkt_nopost;
  2744. }
  2745. work_mask |= opaque_key;
  2746. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2747. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2748. drop_it:
  2749. tg3_recycle_rx(tp, opaque_key,
  2750. desc_idx, *post_ptr);
  2751. drop_it_no_recycle:
  2752. /* Other statistics kept track of by card. */
  2753. tp->net_stats.rx_dropped++;
  2754. goto next_pkt;
  2755. }
  2756. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2757. if (len > RX_COPY_THRESHOLD
  2758. && tp->rx_offset == 2
  2759. /* rx_offset != 2 iff this is a 5701 card running
  2760. * in PCI-X mode [see tg3_get_invariants()] */
  2761. ) {
  2762. int skb_size;
  2763. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2764. desc_idx, *post_ptr);
  2765. if (skb_size < 0)
  2766. goto drop_it;
  2767. pci_unmap_single(tp->pdev, dma_addr,
  2768. skb_size - tp->rx_offset,
  2769. PCI_DMA_FROMDEVICE);
  2770. skb_put(skb, len);
  2771. } else {
  2772. struct sk_buff *copy_skb;
  2773. tg3_recycle_rx(tp, opaque_key,
  2774. desc_idx, *post_ptr);
  2775. copy_skb = dev_alloc_skb(len + 2);
  2776. if (copy_skb == NULL)
  2777. goto drop_it_no_recycle;
  2778. copy_skb->dev = tp->dev;
  2779. skb_reserve(copy_skb, 2);
  2780. skb_put(copy_skb, len);
  2781. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2782. memcpy(copy_skb->data, skb->data, len);
  2783. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2784. /* We'll reuse the original ring buffer. */
  2785. skb = copy_skb;
  2786. }
  2787. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2788. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2789. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2790. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2791. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2792. else
  2793. skb->ip_summed = CHECKSUM_NONE;
  2794. skb->protocol = eth_type_trans(skb, tp->dev);
  2795. #if TG3_VLAN_TAG_USED
  2796. if (tp->vlgrp != NULL &&
  2797. desc->type_flags & RXD_FLAG_VLAN) {
  2798. tg3_vlan_rx(tp, skb,
  2799. desc->err_vlan & RXD_VLAN_MASK);
  2800. } else
  2801. #endif
  2802. netif_receive_skb(skb);
  2803. tp->dev->last_rx = jiffies;
  2804. received++;
  2805. budget--;
  2806. next_pkt:
  2807. (*post_ptr)++;
  2808. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2809. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2810. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2811. TG3_64BIT_REG_LOW, idx);
  2812. work_mask &= ~RXD_OPAQUE_RING_STD;
  2813. rx_std_posted = 0;
  2814. }
  2815. next_pkt_nopost:
  2816. sw_idx++;
  2817. sw_idx %= TG3_RX_RCB_RING_SIZE(tp);
  2818. /* Refresh hw_idx to see if there is new work */
  2819. if (sw_idx == hw_idx) {
  2820. hw_idx = tp->hw_status->idx[0].rx_producer;
  2821. rmb();
  2822. }
  2823. }
  2824. /* ACK the status ring. */
  2825. tp->rx_rcb_ptr = sw_idx;
  2826. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2827. /* Refill RX ring(s). */
  2828. if (work_mask & RXD_OPAQUE_RING_STD) {
  2829. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2830. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2831. sw_idx);
  2832. }
  2833. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2834. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2835. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2836. sw_idx);
  2837. }
  2838. mmiowb();
  2839. return received;
  2840. }
  2841. static int tg3_poll(struct net_device *netdev, int *budget)
  2842. {
  2843. struct tg3 *tp = netdev_priv(netdev);
  2844. struct tg3_hw_status *sblk = tp->hw_status;
  2845. int done;
  2846. /* handle link change and other phy events */
  2847. if (!(tp->tg3_flags &
  2848. (TG3_FLAG_USE_LINKCHG_REG |
  2849. TG3_FLAG_POLL_SERDES))) {
  2850. if (sblk->status & SD_STATUS_LINK_CHG) {
  2851. sblk->status = SD_STATUS_UPDATED |
  2852. (sblk->status & ~SD_STATUS_LINK_CHG);
  2853. spin_lock(&tp->lock);
  2854. tg3_setup_phy(tp, 0);
  2855. spin_unlock(&tp->lock);
  2856. }
  2857. }
  2858. /* run TX completion thread */
  2859. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2860. tg3_tx(tp);
  2861. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2862. netif_rx_complete(netdev);
  2863. schedule_work(&tp->reset_task);
  2864. return 0;
  2865. }
  2866. }
  2867. /* run RX thread, within the bounds set by NAPI.
  2868. * All RX "locking" is done by ensuring outside
  2869. * code synchronizes with dev->poll()
  2870. */
  2871. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2872. int orig_budget = *budget;
  2873. int work_done;
  2874. if (orig_budget > netdev->quota)
  2875. orig_budget = netdev->quota;
  2876. work_done = tg3_rx(tp, orig_budget);
  2877. *budget -= work_done;
  2878. netdev->quota -= work_done;
  2879. }
  2880. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2881. tp->last_tag = sblk->status_tag;
  2882. rmb();
  2883. } else
  2884. sblk->status &= ~SD_STATUS_UPDATED;
  2885. /* if no more work, tell net stack and NIC we're done */
  2886. done = !tg3_has_work(tp);
  2887. if (done) {
  2888. netif_rx_complete(netdev);
  2889. tg3_restart_ints(tp);
  2890. }
  2891. return (done ? 0 : 1);
  2892. }
  2893. static void tg3_irq_quiesce(struct tg3 *tp)
  2894. {
  2895. BUG_ON(tp->irq_sync);
  2896. tp->irq_sync = 1;
  2897. smp_mb();
  2898. synchronize_irq(tp->pdev->irq);
  2899. }
  2900. static inline int tg3_irq_sync(struct tg3 *tp)
  2901. {
  2902. return tp->irq_sync;
  2903. }
  2904. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  2905. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  2906. * with as well. Most of the time, this is not necessary except when
  2907. * shutting down the device.
  2908. */
  2909. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  2910. {
  2911. if (irq_sync)
  2912. tg3_irq_quiesce(tp);
  2913. spin_lock_bh(&tp->lock);
  2914. }
  2915. static inline void tg3_full_unlock(struct tg3 *tp)
  2916. {
  2917. spin_unlock_bh(&tp->lock);
  2918. }
  2919. /* One-shot MSI handler - Chip automatically disables interrupt
  2920. * after sending MSI so driver doesn't have to do it.
  2921. */
  2922. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id, struct pt_regs *regs)
  2923. {
  2924. struct net_device *dev = dev_id;
  2925. struct tg3 *tp = netdev_priv(dev);
  2926. prefetch(tp->hw_status);
  2927. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2928. if (likely(!tg3_irq_sync(tp)))
  2929. netif_rx_schedule(dev); /* schedule NAPI poll */
  2930. return IRQ_HANDLED;
  2931. }
  2932. /* MSI ISR - No need to check for interrupt sharing and no need to
  2933. * flush status block and interrupt mailbox. PCI ordering rules
  2934. * guarantee that MSI will arrive after the status block.
  2935. */
  2936. static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs)
  2937. {
  2938. struct net_device *dev = dev_id;
  2939. struct tg3 *tp = netdev_priv(dev);
  2940. prefetch(tp->hw_status);
  2941. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2942. /*
  2943. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2944. * chip-internal interrupt pending events.
  2945. * Writing non-zero to intr-mbox-0 additional tells the
  2946. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2947. * event coalescing.
  2948. */
  2949. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  2950. if (likely(!tg3_irq_sync(tp)))
  2951. netif_rx_schedule(dev); /* schedule NAPI poll */
  2952. return IRQ_RETVAL(1);
  2953. }
  2954. static irqreturn_t tg3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2955. {
  2956. struct net_device *dev = dev_id;
  2957. struct tg3 *tp = netdev_priv(dev);
  2958. struct tg3_hw_status *sblk = tp->hw_status;
  2959. unsigned int handled = 1;
  2960. /* In INTx mode, it is possible for the interrupt to arrive at
  2961. * the CPU before the status block posted prior to the interrupt.
  2962. * Reading the PCI State register will confirm whether the
  2963. * interrupt is ours and will flush the status block.
  2964. */
  2965. if ((sblk->status & SD_STATUS_UPDATED) ||
  2966. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  2967. /*
  2968. * Writing any value to intr-mbox-0 clears PCI INTA# and
  2969. * chip-internal interrupt pending events.
  2970. * Writing non-zero to intr-mbox-0 additional tells the
  2971. * NIC to stop sending us irqs, engaging "in-intr-handler"
  2972. * event coalescing.
  2973. */
  2974. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  2975. 0x00000001);
  2976. if (tg3_irq_sync(tp))
  2977. goto out;
  2978. sblk->status &= ~SD_STATUS_UPDATED;
  2979. if (likely(tg3_has_work(tp))) {
  2980. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2981. netif_rx_schedule(dev); /* schedule NAPI poll */
  2982. } else {
  2983. /* No work, shared interrupt perhaps? re-enable
  2984. * interrupts, and flush that PCI write
  2985. */
  2986. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  2987. 0x00000000);
  2988. }
  2989. } else { /* shared interrupt */
  2990. handled = 0;
  2991. }
  2992. out:
  2993. return IRQ_RETVAL(handled);
  2994. }
  2995. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *regs)
  2996. {
  2997. struct net_device *dev = dev_id;
  2998. struct tg3 *tp = netdev_priv(dev);
  2999. struct tg3_hw_status *sblk = tp->hw_status;
  3000. unsigned int handled = 1;
  3001. /* In INTx mode, it is possible for the interrupt to arrive at
  3002. * the CPU before the status block posted prior to the interrupt.
  3003. * Reading the PCI State register will confirm whether the
  3004. * interrupt is ours and will flush the status block.
  3005. */
  3006. if ((sblk->status_tag != tp->last_tag) ||
  3007. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3008. /*
  3009. * writing any value to intr-mbox-0 clears PCI INTA# and
  3010. * chip-internal interrupt pending events.
  3011. * writing non-zero to intr-mbox-0 additional tells the
  3012. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3013. * event coalescing.
  3014. */
  3015. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3016. 0x00000001);
  3017. if (tg3_irq_sync(tp))
  3018. goto out;
  3019. if (netif_rx_schedule_prep(dev)) {
  3020. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3021. /* Update last_tag to mark that this status has been
  3022. * seen. Because interrupt may be shared, we may be
  3023. * racing with tg3_poll(), so only update last_tag
  3024. * if tg3_poll() is not scheduled.
  3025. */
  3026. tp->last_tag = sblk->status_tag;
  3027. __netif_rx_schedule(dev);
  3028. }
  3029. } else { /* shared interrupt */
  3030. handled = 0;
  3031. }
  3032. out:
  3033. return IRQ_RETVAL(handled);
  3034. }
  3035. /* ISR for interrupt test */
  3036. static irqreturn_t tg3_test_isr(int irq, void *dev_id,
  3037. struct pt_regs *regs)
  3038. {
  3039. struct net_device *dev = dev_id;
  3040. struct tg3 *tp = netdev_priv(dev);
  3041. struct tg3_hw_status *sblk = tp->hw_status;
  3042. if ((sblk->status & SD_STATUS_UPDATED) ||
  3043. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3044. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3045. 0x00000001);
  3046. return IRQ_RETVAL(1);
  3047. }
  3048. return IRQ_RETVAL(0);
  3049. }
  3050. static int tg3_init_hw(struct tg3 *, int);
  3051. static int tg3_halt(struct tg3 *, int, int);
  3052. /* Restart hardware after configuration changes, self-test, etc.
  3053. * Invoked with tp->lock held.
  3054. */
  3055. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3056. {
  3057. int err;
  3058. err = tg3_init_hw(tp, reset_phy);
  3059. if (err) {
  3060. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3061. "aborting.\n", tp->dev->name);
  3062. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3063. tg3_full_unlock(tp);
  3064. del_timer_sync(&tp->timer);
  3065. tp->irq_sync = 0;
  3066. netif_poll_enable(tp->dev);
  3067. dev_close(tp->dev);
  3068. tg3_full_lock(tp, 0);
  3069. }
  3070. return err;
  3071. }
  3072. #ifdef CONFIG_NET_POLL_CONTROLLER
  3073. static void tg3_poll_controller(struct net_device *dev)
  3074. {
  3075. struct tg3 *tp = netdev_priv(dev);
  3076. tg3_interrupt(tp->pdev->irq, dev, NULL);
  3077. }
  3078. #endif
  3079. static void tg3_reset_task(void *_data)
  3080. {
  3081. struct tg3 *tp = _data;
  3082. unsigned int restart_timer;
  3083. tg3_full_lock(tp, 0);
  3084. tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
  3085. if (!netif_running(tp->dev)) {
  3086. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3087. tg3_full_unlock(tp);
  3088. return;
  3089. }
  3090. tg3_full_unlock(tp);
  3091. tg3_netif_stop(tp);
  3092. tg3_full_lock(tp, 1);
  3093. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3094. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3095. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3096. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3097. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3098. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3099. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3100. }
  3101. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3102. if (tg3_init_hw(tp, 1))
  3103. goto out;
  3104. tg3_netif_start(tp);
  3105. if (restart_timer)
  3106. mod_timer(&tp->timer, jiffies + 1);
  3107. out:
  3108. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3109. tg3_full_unlock(tp);
  3110. }
  3111. static void tg3_tx_timeout(struct net_device *dev)
  3112. {
  3113. struct tg3 *tp = netdev_priv(dev);
  3114. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3115. dev->name);
  3116. schedule_work(&tp->reset_task);
  3117. }
  3118. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3119. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3120. {
  3121. u32 base = (u32) mapping & 0xffffffff;
  3122. return ((base > 0xffffdcc0) &&
  3123. (base + len + 8 < base));
  3124. }
  3125. /* Test for DMA addresses > 40-bit */
  3126. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3127. int len)
  3128. {
  3129. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3130. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3131. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3132. return 0;
  3133. #else
  3134. return 0;
  3135. #endif
  3136. }
  3137. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3138. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3139. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3140. u32 last_plus_one, u32 *start,
  3141. u32 base_flags, u32 mss)
  3142. {
  3143. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3144. dma_addr_t new_addr = 0;
  3145. u32 entry = *start;
  3146. int i, ret = 0;
  3147. if (!new_skb) {
  3148. ret = -1;
  3149. } else {
  3150. /* New SKB is guaranteed to be linear. */
  3151. entry = *start;
  3152. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3153. PCI_DMA_TODEVICE);
  3154. /* Make sure new skb does not cross any 4G boundaries.
  3155. * Drop the packet if it does.
  3156. */
  3157. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3158. ret = -1;
  3159. dev_kfree_skb(new_skb);
  3160. new_skb = NULL;
  3161. } else {
  3162. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3163. base_flags, 1 | (mss << 1));
  3164. *start = NEXT_TX(entry);
  3165. }
  3166. }
  3167. /* Now clean up the sw ring entries. */
  3168. i = 0;
  3169. while (entry != last_plus_one) {
  3170. int len;
  3171. if (i == 0)
  3172. len = skb_headlen(skb);
  3173. else
  3174. len = skb_shinfo(skb)->frags[i-1].size;
  3175. pci_unmap_single(tp->pdev,
  3176. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3177. len, PCI_DMA_TODEVICE);
  3178. if (i == 0) {
  3179. tp->tx_buffers[entry].skb = new_skb;
  3180. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3181. } else {
  3182. tp->tx_buffers[entry].skb = NULL;
  3183. }
  3184. entry = NEXT_TX(entry);
  3185. i++;
  3186. }
  3187. dev_kfree_skb(skb);
  3188. return ret;
  3189. }
  3190. static void tg3_set_txd(struct tg3 *tp, int entry,
  3191. dma_addr_t mapping, int len, u32 flags,
  3192. u32 mss_and_is_end)
  3193. {
  3194. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3195. int is_end = (mss_and_is_end & 0x1);
  3196. u32 mss = (mss_and_is_end >> 1);
  3197. u32 vlan_tag = 0;
  3198. if (is_end)
  3199. flags |= TXD_FLAG_END;
  3200. if (flags & TXD_FLAG_VLAN) {
  3201. vlan_tag = flags >> 16;
  3202. flags &= 0xffff;
  3203. }
  3204. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3205. txd->addr_hi = ((u64) mapping >> 32);
  3206. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3207. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3208. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3209. }
  3210. /* hard_start_xmit for devices that don't have any bugs and
  3211. * support TG3_FLG2_HW_TSO_2 only.
  3212. */
  3213. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3214. {
  3215. struct tg3 *tp = netdev_priv(dev);
  3216. dma_addr_t mapping;
  3217. u32 len, entry, base_flags, mss;
  3218. len = skb_headlen(skb);
  3219. /* We are running in BH disabled context with netif_tx_lock
  3220. * and TX reclaim runs via tp->poll inside of a software
  3221. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3222. * no IRQ context deadlocks to worry about either. Rejoice!
  3223. */
  3224. if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3225. if (!netif_queue_stopped(dev)) {
  3226. netif_stop_queue(dev);
  3227. /* This is a hard error, log it. */
  3228. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3229. "queue awake!\n", dev->name);
  3230. }
  3231. return NETDEV_TX_BUSY;
  3232. }
  3233. entry = tp->tx_prod;
  3234. base_flags = 0;
  3235. #if TG3_TSO_SUPPORT != 0
  3236. mss = 0;
  3237. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3238. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3239. int tcp_opt_len, ip_tcp_len;
  3240. if (skb_header_cloned(skb) &&
  3241. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3242. dev_kfree_skb(skb);
  3243. goto out_unlock;
  3244. }
  3245. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3246. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3247. else {
  3248. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3249. ip_tcp_len = (skb->nh.iph->ihl * 4) +
  3250. sizeof(struct tcphdr);
  3251. skb->nh.iph->check = 0;
  3252. skb->nh.iph->tot_len = htons(mss + ip_tcp_len +
  3253. tcp_opt_len);
  3254. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3255. }
  3256. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3257. TXD_FLAG_CPU_POST_DMA);
  3258. skb->h.th->check = 0;
  3259. }
  3260. else if (skb->ip_summed == CHECKSUM_HW)
  3261. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3262. #else
  3263. mss = 0;
  3264. if (skb->ip_summed == CHECKSUM_HW)
  3265. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3266. #endif
  3267. #if TG3_VLAN_TAG_USED
  3268. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3269. base_flags |= (TXD_FLAG_VLAN |
  3270. (vlan_tx_tag_get(skb) << 16));
  3271. #endif
  3272. /* Queue skb data, a.k.a. the main skb fragment. */
  3273. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3274. tp->tx_buffers[entry].skb = skb;
  3275. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3276. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3277. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3278. entry = NEXT_TX(entry);
  3279. /* Now loop through additional data fragments, and queue them. */
  3280. if (skb_shinfo(skb)->nr_frags > 0) {
  3281. unsigned int i, last;
  3282. last = skb_shinfo(skb)->nr_frags - 1;
  3283. for (i = 0; i <= last; i++) {
  3284. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3285. len = frag->size;
  3286. mapping = pci_map_page(tp->pdev,
  3287. frag->page,
  3288. frag->page_offset,
  3289. len, PCI_DMA_TODEVICE);
  3290. tp->tx_buffers[entry].skb = NULL;
  3291. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3292. tg3_set_txd(tp, entry, mapping, len,
  3293. base_flags, (i == last) | (mss << 1));
  3294. entry = NEXT_TX(entry);
  3295. }
  3296. }
  3297. /* Packets are ready, update Tx producer idx local and on card. */
  3298. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3299. tp->tx_prod = entry;
  3300. if (unlikely(TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1))) {
  3301. spin_lock(&tp->tx_lock);
  3302. netif_stop_queue(dev);
  3303. if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)
  3304. netif_wake_queue(tp->dev);
  3305. spin_unlock(&tp->tx_lock);
  3306. }
  3307. out_unlock:
  3308. mmiowb();
  3309. dev->trans_start = jiffies;
  3310. return NETDEV_TX_OK;
  3311. }
  3312. #if TG3_TSO_SUPPORT != 0
  3313. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3314. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3315. * TSO header is greater than 80 bytes.
  3316. */
  3317. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3318. {
  3319. struct sk_buff *segs, *nskb;
  3320. /* Estimate the number of fragments in the worst case */
  3321. if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3322. netif_stop_queue(tp->dev);
  3323. return NETDEV_TX_BUSY;
  3324. }
  3325. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3326. if (unlikely(IS_ERR(segs)))
  3327. goto tg3_tso_bug_end;
  3328. do {
  3329. nskb = segs;
  3330. segs = segs->next;
  3331. nskb->next = NULL;
  3332. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3333. } while (segs);
  3334. tg3_tso_bug_end:
  3335. dev_kfree_skb(skb);
  3336. return NETDEV_TX_OK;
  3337. }
  3338. #endif
  3339. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3340. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3341. */
  3342. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3343. {
  3344. struct tg3 *tp = netdev_priv(dev);
  3345. dma_addr_t mapping;
  3346. u32 len, entry, base_flags, mss;
  3347. int would_hit_hwbug;
  3348. len = skb_headlen(skb);
  3349. /* We are running in BH disabled context with netif_tx_lock
  3350. * and TX reclaim runs via tp->poll inside of a software
  3351. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3352. * no IRQ context deadlocks to worry about either. Rejoice!
  3353. */
  3354. if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3355. if (!netif_queue_stopped(dev)) {
  3356. netif_stop_queue(dev);
  3357. /* This is a hard error, log it. */
  3358. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3359. "queue awake!\n", dev->name);
  3360. }
  3361. return NETDEV_TX_BUSY;
  3362. }
  3363. entry = tp->tx_prod;
  3364. base_flags = 0;
  3365. if (skb->ip_summed == CHECKSUM_HW)
  3366. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3367. #if TG3_TSO_SUPPORT != 0
  3368. mss = 0;
  3369. if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
  3370. (mss = skb_shinfo(skb)->gso_size) != 0) {
  3371. int tcp_opt_len, ip_tcp_len, hdr_len;
  3372. if (skb_header_cloned(skb) &&
  3373. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3374. dev_kfree_skb(skb);
  3375. goto out_unlock;
  3376. }
  3377. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3378. ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
  3379. hdr_len = ip_tcp_len + tcp_opt_len;
  3380. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3381. (tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG))
  3382. return (tg3_tso_bug(tp, skb));
  3383. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3384. TXD_FLAG_CPU_POST_DMA);
  3385. skb->nh.iph->check = 0;
  3386. skb->nh.iph->tot_len = htons(mss + hdr_len);
  3387. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3388. skb->h.th->check = 0;
  3389. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3390. }
  3391. else {
  3392. skb->h.th->check =
  3393. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3394. skb->nh.iph->daddr,
  3395. 0, IPPROTO_TCP, 0);
  3396. }
  3397. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3398. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3399. if (tcp_opt_len || skb->nh.iph->ihl > 5) {
  3400. int tsflags;
  3401. tsflags = ((skb->nh.iph->ihl - 5) +
  3402. (tcp_opt_len >> 2));
  3403. mss |= (tsflags << 11);
  3404. }
  3405. } else {
  3406. if (tcp_opt_len || skb->nh.iph->ihl > 5) {
  3407. int tsflags;
  3408. tsflags = ((skb->nh.iph->ihl - 5) +
  3409. (tcp_opt_len >> 2));
  3410. base_flags |= tsflags << 12;
  3411. }
  3412. }
  3413. }
  3414. #else
  3415. mss = 0;
  3416. #endif
  3417. #if TG3_VLAN_TAG_USED
  3418. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3419. base_flags |= (TXD_FLAG_VLAN |
  3420. (vlan_tx_tag_get(skb) << 16));
  3421. #endif
  3422. /* Queue skb data, a.k.a. the main skb fragment. */
  3423. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3424. tp->tx_buffers[entry].skb = skb;
  3425. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3426. would_hit_hwbug = 0;
  3427. if (tg3_4g_overflow_test(mapping, len))
  3428. would_hit_hwbug = 1;
  3429. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3430. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3431. entry = NEXT_TX(entry);
  3432. /* Now loop through additional data fragments, and queue them. */
  3433. if (skb_shinfo(skb)->nr_frags > 0) {
  3434. unsigned int i, last;
  3435. last = skb_shinfo(skb)->nr_frags - 1;
  3436. for (i = 0; i <= last; i++) {
  3437. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3438. len = frag->size;
  3439. mapping = pci_map_page(tp->pdev,
  3440. frag->page,
  3441. frag->page_offset,
  3442. len, PCI_DMA_TODEVICE);
  3443. tp->tx_buffers[entry].skb = NULL;
  3444. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3445. if (tg3_4g_overflow_test(mapping, len))
  3446. would_hit_hwbug = 1;
  3447. if (tg3_40bit_overflow_test(tp, mapping, len))
  3448. would_hit_hwbug = 1;
  3449. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3450. tg3_set_txd(tp, entry, mapping, len,
  3451. base_flags, (i == last)|(mss << 1));
  3452. else
  3453. tg3_set_txd(tp, entry, mapping, len,
  3454. base_flags, (i == last));
  3455. entry = NEXT_TX(entry);
  3456. }
  3457. }
  3458. if (would_hit_hwbug) {
  3459. u32 last_plus_one = entry;
  3460. u32 start;
  3461. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3462. start &= (TG3_TX_RING_SIZE - 1);
  3463. /* If the workaround fails due to memory/mapping
  3464. * failure, silently drop this packet.
  3465. */
  3466. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3467. &start, base_flags, mss))
  3468. goto out_unlock;
  3469. entry = start;
  3470. }
  3471. /* Packets are ready, update Tx producer idx local and on card. */
  3472. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3473. tp->tx_prod = entry;
  3474. if (unlikely(TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1))) {
  3475. spin_lock(&tp->tx_lock);
  3476. netif_stop_queue(dev);
  3477. if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)
  3478. netif_wake_queue(tp->dev);
  3479. spin_unlock(&tp->tx_lock);
  3480. }
  3481. out_unlock:
  3482. mmiowb();
  3483. dev->trans_start = jiffies;
  3484. return NETDEV_TX_OK;
  3485. }
  3486. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3487. int new_mtu)
  3488. {
  3489. dev->mtu = new_mtu;
  3490. if (new_mtu > ETH_DATA_LEN) {
  3491. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3492. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3493. ethtool_op_set_tso(dev, 0);
  3494. }
  3495. else
  3496. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3497. } else {
  3498. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3499. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3500. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3501. }
  3502. }
  3503. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3504. {
  3505. struct tg3 *tp = netdev_priv(dev);
  3506. int err;
  3507. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3508. return -EINVAL;
  3509. if (!netif_running(dev)) {
  3510. /* We'll just catch it later when the
  3511. * device is up'd.
  3512. */
  3513. tg3_set_mtu(dev, tp, new_mtu);
  3514. return 0;
  3515. }
  3516. tg3_netif_stop(tp);
  3517. tg3_full_lock(tp, 1);
  3518. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3519. tg3_set_mtu(dev, tp, new_mtu);
  3520. err = tg3_restart_hw(tp, 0);
  3521. if (!err)
  3522. tg3_netif_start(tp);
  3523. tg3_full_unlock(tp);
  3524. return err;
  3525. }
  3526. /* Free up pending packets in all rx/tx rings.
  3527. *
  3528. * The chip has been shut down and the driver detached from
  3529. * the networking, so no interrupts or new tx packets will
  3530. * end up in the driver. tp->{tx,}lock is not held and we are not
  3531. * in an interrupt context and thus may sleep.
  3532. */
  3533. static void tg3_free_rings(struct tg3 *tp)
  3534. {
  3535. struct ring_info *rxp;
  3536. int i;
  3537. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3538. rxp = &tp->rx_std_buffers[i];
  3539. if (rxp->skb == NULL)
  3540. continue;
  3541. pci_unmap_single(tp->pdev,
  3542. pci_unmap_addr(rxp, mapping),
  3543. tp->rx_pkt_buf_sz - tp->rx_offset,
  3544. PCI_DMA_FROMDEVICE);
  3545. dev_kfree_skb_any(rxp->skb);
  3546. rxp->skb = NULL;
  3547. }
  3548. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3549. rxp = &tp->rx_jumbo_buffers[i];
  3550. if (rxp->skb == NULL)
  3551. continue;
  3552. pci_unmap_single(tp->pdev,
  3553. pci_unmap_addr(rxp, mapping),
  3554. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3555. PCI_DMA_FROMDEVICE);
  3556. dev_kfree_skb_any(rxp->skb);
  3557. rxp->skb = NULL;
  3558. }
  3559. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3560. struct tx_ring_info *txp;
  3561. struct sk_buff *skb;
  3562. int j;
  3563. txp = &tp->tx_buffers[i];
  3564. skb = txp->skb;
  3565. if (skb == NULL) {
  3566. i++;
  3567. continue;
  3568. }
  3569. pci_unmap_single(tp->pdev,
  3570. pci_unmap_addr(txp, mapping),
  3571. skb_headlen(skb),
  3572. PCI_DMA_TODEVICE);
  3573. txp->skb = NULL;
  3574. i++;
  3575. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3576. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3577. pci_unmap_page(tp->pdev,
  3578. pci_unmap_addr(txp, mapping),
  3579. skb_shinfo(skb)->frags[j].size,
  3580. PCI_DMA_TODEVICE);
  3581. i++;
  3582. }
  3583. dev_kfree_skb_any(skb);
  3584. }
  3585. }
  3586. /* Initialize tx/rx rings for packet processing.
  3587. *
  3588. * The chip has been shut down and the driver detached from
  3589. * the networking, so no interrupts or new tx packets will
  3590. * end up in the driver. tp->{tx,}lock are held and thus
  3591. * we may not sleep.
  3592. */
  3593. static int tg3_init_rings(struct tg3 *tp)
  3594. {
  3595. u32 i;
  3596. /* Free up all the SKBs. */
  3597. tg3_free_rings(tp);
  3598. /* Zero out all descriptors. */
  3599. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3600. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3601. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3602. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3603. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3604. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3605. (tp->dev->mtu > ETH_DATA_LEN))
  3606. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3607. /* Initialize invariants of the rings, we only set this
  3608. * stuff once. This works because the card does not
  3609. * write into the rx buffer posting rings.
  3610. */
  3611. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3612. struct tg3_rx_buffer_desc *rxd;
  3613. rxd = &tp->rx_std[i];
  3614. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3615. << RXD_LEN_SHIFT;
  3616. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3617. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3618. (i << RXD_OPAQUE_INDEX_SHIFT));
  3619. }
  3620. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3621. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3622. struct tg3_rx_buffer_desc *rxd;
  3623. rxd = &tp->rx_jumbo[i];
  3624. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3625. << RXD_LEN_SHIFT;
  3626. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3627. RXD_FLAG_JUMBO;
  3628. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3629. (i << RXD_OPAQUE_INDEX_SHIFT));
  3630. }
  3631. }
  3632. /* Now allocate fresh SKBs for each rx ring. */
  3633. for (i = 0; i < tp->rx_pending; i++) {
  3634. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3635. printk(KERN_WARNING PFX
  3636. "%s: Using a smaller RX standard ring, "
  3637. "only %d out of %d buffers were allocated "
  3638. "successfully.\n",
  3639. tp->dev->name, i, tp->rx_pending);
  3640. if (i == 0)
  3641. return -ENOMEM;
  3642. tp->rx_pending = i;
  3643. break;
  3644. }
  3645. }
  3646. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3647. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3648. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3649. -1, i) < 0) {
  3650. printk(KERN_WARNING PFX
  3651. "%s: Using a smaller RX jumbo ring, "
  3652. "only %d out of %d buffers were "
  3653. "allocated successfully.\n",
  3654. tp->dev->name, i, tp->rx_jumbo_pending);
  3655. if (i == 0) {
  3656. tg3_free_rings(tp);
  3657. return -ENOMEM;
  3658. }
  3659. tp->rx_jumbo_pending = i;
  3660. break;
  3661. }
  3662. }
  3663. }
  3664. return 0;
  3665. }
  3666. /*
  3667. * Must not be invoked with interrupt sources disabled and
  3668. * the hardware shutdown down.
  3669. */
  3670. static void tg3_free_consistent(struct tg3 *tp)
  3671. {
  3672. kfree(tp->rx_std_buffers);
  3673. tp->rx_std_buffers = NULL;
  3674. if (tp->rx_std) {
  3675. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3676. tp->rx_std, tp->rx_std_mapping);
  3677. tp->rx_std = NULL;
  3678. }
  3679. if (tp->rx_jumbo) {
  3680. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3681. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3682. tp->rx_jumbo = NULL;
  3683. }
  3684. if (tp->rx_rcb) {
  3685. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3686. tp->rx_rcb, tp->rx_rcb_mapping);
  3687. tp->rx_rcb = NULL;
  3688. }
  3689. if (tp->tx_ring) {
  3690. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3691. tp->tx_ring, tp->tx_desc_mapping);
  3692. tp->tx_ring = NULL;
  3693. }
  3694. if (tp->hw_status) {
  3695. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3696. tp->hw_status, tp->status_mapping);
  3697. tp->hw_status = NULL;
  3698. }
  3699. if (tp->hw_stats) {
  3700. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3701. tp->hw_stats, tp->stats_mapping);
  3702. tp->hw_stats = NULL;
  3703. }
  3704. }
  3705. /*
  3706. * Must not be invoked with interrupt sources disabled and
  3707. * the hardware shutdown down. Can sleep.
  3708. */
  3709. static int tg3_alloc_consistent(struct tg3 *tp)
  3710. {
  3711. tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) *
  3712. (TG3_RX_RING_SIZE +
  3713. TG3_RX_JUMBO_RING_SIZE)) +
  3714. (sizeof(struct tx_ring_info) *
  3715. TG3_TX_RING_SIZE),
  3716. GFP_KERNEL);
  3717. if (!tp->rx_std_buffers)
  3718. return -ENOMEM;
  3719. memset(tp->rx_std_buffers, 0,
  3720. (sizeof(struct ring_info) *
  3721. (TG3_RX_RING_SIZE +
  3722. TG3_RX_JUMBO_RING_SIZE)) +
  3723. (sizeof(struct tx_ring_info) *
  3724. TG3_TX_RING_SIZE));
  3725. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3726. tp->tx_buffers = (struct tx_ring_info *)
  3727. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3728. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3729. &tp->rx_std_mapping);
  3730. if (!tp->rx_std)
  3731. goto err_out;
  3732. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3733. &tp->rx_jumbo_mapping);
  3734. if (!tp->rx_jumbo)
  3735. goto err_out;
  3736. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3737. &tp->rx_rcb_mapping);
  3738. if (!tp->rx_rcb)
  3739. goto err_out;
  3740. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3741. &tp->tx_desc_mapping);
  3742. if (!tp->tx_ring)
  3743. goto err_out;
  3744. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3745. TG3_HW_STATUS_SIZE,
  3746. &tp->status_mapping);
  3747. if (!tp->hw_status)
  3748. goto err_out;
  3749. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3750. sizeof(struct tg3_hw_stats),
  3751. &tp->stats_mapping);
  3752. if (!tp->hw_stats)
  3753. goto err_out;
  3754. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3755. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3756. return 0;
  3757. err_out:
  3758. tg3_free_consistent(tp);
  3759. return -ENOMEM;
  3760. }
  3761. #define MAX_WAIT_CNT 1000
  3762. /* To stop a block, clear the enable bit and poll till it
  3763. * clears. tp->lock is held.
  3764. */
  3765. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3766. {
  3767. unsigned int i;
  3768. u32 val;
  3769. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3770. switch (ofs) {
  3771. case RCVLSC_MODE:
  3772. case DMAC_MODE:
  3773. case MBFREE_MODE:
  3774. case BUFMGR_MODE:
  3775. case MEMARB_MODE:
  3776. /* We can't enable/disable these bits of the
  3777. * 5705/5750, just say success.
  3778. */
  3779. return 0;
  3780. default:
  3781. break;
  3782. };
  3783. }
  3784. val = tr32(ofs);
  3785. val &= ~enable_bit;
  3786. tw32_f(ofs, val);
  3787. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3788. udelay(100);
  3789. val = tr32(ofs);
  3790. if ((val & enable_bit) == 0)
  3791. break;
  3792. }
  3793. if (i == MAX_WAIT_CNT && !silent) {
  3794. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3795. "ofs=%lx enable_bit=%x\n",
  3796. ofs, enable_bit);
  3797. return -ENODEV;
  3798. }
  3799. return 0;
  3800. }
  3801. /* tp->lock is held. */
  3802. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3803. {
  3804. int i, err;
  3805. tg3_disable_ints(tp);
  3806. tp->rx_mode &= ~RX_MODE_ENABLE;
  3807. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3808. udelay(10);
  3809. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3810. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3811. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3812. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3813. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3814. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3815. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3816. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3817. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3818. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3819. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3820. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3821. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3822. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3823. tw32_f(MAC_MODE, tp->mac_mode);
  3824. udelay(40);
  3825. tp->tx_mode &= ~TX_MODE_ENABLE;
  3826. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3827. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3828. udelay(100);
  3829. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3830. break;
  3831. }
  3832. if (i >= MAX_WAIT_CNT) {
  3833. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3834. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3835. tp->dev->name, tr32(MAC_TX_MODE));
  3836. err |= -ENODEV;
  3837. }
  3838. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3839. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3840. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3841. tw32(FTQ_RESET, 0xffffffff);
  3842. tw32(FTQ_RESET, 0x00000000);
  3843. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3844. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3845. if (tp->hw_status)
  3846. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3847. if (tp->hw_stats)
  3848. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3849. return err;
  3850. }
  3851. /* tp->lock is held. */
  3852. static int tg3_nvram_lock(struct tg3 *tp)
  3853. {
  3854. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3855. int i;
  3856. if (tp->nvram_lock_cnt == 0) {
  3857. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3858. for (i = 0; i < 8000; i++) {
  3859. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3860. break;
  3861. udelay(20);
  3862. }
  3863. if (i == 8000) {
  3864. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3865. return -ENODEV;
  3866. }
  3867. }
  3868. tp->nvram_lock_cnt++;
  3869. }
  3870. return 0;
  3871. }
  3872. /* tp->lock is held. */
  3873. static void tg3_nvram_unlock(struct tg3 *tp)
  3874. {
  3875. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3876. if (tp->nvram_lock_cnt > 0)
  3877. tp->nvram_lock_cnt--;
  3878. if (tp->nvram_lock_cnt == 0)
  3879. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3880. }
  3881. }
  3882. /* tp->lock is held. */
  3883. static void tg3_enable_nvram_access(struct tg3 *tp)
  3884. {
  3885. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3886. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3887. u32 nvaccess = tr32(NVRAM_ACCESS);
  3888. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3889. }
  3890. }
  3891. /* tp->lock is held. */
  3892. static void tg3_disable_nvram_access(struct tg3 *tp)
  3893. {
  3894. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3895. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3896. u32 nvaccess = tr32(NVRAM_ACCESS);
  3897. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3898. }
  3899. }
  3900. /* tp->lock is held. */
  3901. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3902. {
  3903. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3904. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3905. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3906. switch (kind) {
  3907. case RESET_KIND_INIT:
  3908. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3909. DRV_STATE_START);
  3910. break;
  3911. case RESET_KIND_SHUTDOWN:
  3912. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3913. DRV_STATE_UNLOAD);
  3914. break;
  3915. case RESET_KIND_SUSPEND:
  3916. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3917. DRV_STATE_SUSPEND);
  3918. break;
  3919. default:
  3920. break;
  3921. };
  3922. }
  3923. }
  3924. /* tp->lock is held. */
  3925. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  3926. {
  3927. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3928. switch (kind) {
  3929. case RESET_KIND_INIT:
  3930. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3931. DRV_STATE_START_DONE);
  3932. break;
  3933. case RESET_KIND_SHUTDOWN:
  3934. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3935. DRV_STATE_UNLOAD_DONE);
  3936. break;
  3937. default:
  3938. break;
  3939. };
  3940. }
  3941. }
  3942. /* tp->lock is held. */
  3943. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  3944. {
  3945. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  3946. switch (kind) {
  3947. case RESET_KIND_INIT:
  3948. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3949. DRV_STATE_START);
  3950. break;
  3951. case RESET_KIND_SHUTDOWN:
  3952. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3953. DRV_STATE_UNLOAD);
  3954. break;
  3955. case RESET_KIND_SUSPEND:
  3956. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3957. DRV_STATE_SUSPEND);
  3958. break;
  3959. default:
  3960. break;
  3961. };
  3962. }
  3963. }
  3964. static void tg3_stop_fw(struct tg3 *);
  3965. /* tp->lock is held. */
  3966. static int tg3_chip_reset(struct tg3 *tp)
  3967. {
  3968. u32 val;
  3969. void (*write_op)(struct tg3 *, u32, u32);
  3970. int i;
  3971. tg3_nvram_lock(tp);
  3972. /* No matching tg3_nvram_unlock() after this because
  3973. * chip reset below will undo the nvram lock.
  3974. */
  3975. tp->nvram_lock_cnt = 0;
  3976. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  3977. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  3978. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  3979. tw32(GRC_FASTBOOT_PC, 0);
  3980. /*
  3981. * We must avoid the readl() that normally takes place.
  3982. * It locks machines, causes machine checks, and other
  3983. * fun things. So, temporarily disable the 5701
  3984. * hardware workaround, while we do the reset.
  3985. */
  3986. write_op = tp->write32;
  3987. if (write_op == tg3_write_flush_reg32)
  3988. tp->write32 = tg3_write32;
  3989. /* do the reset */
  3990. val = GRC_MISC_CFG_CORECLK_RESET;
  3991. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  3992. if (tr32(0x7e2c) == 0x60) {
  3993. tw32(0x7e2c, 0x20);
  3994. }
  3995. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  3996. tw32(GRC_MISC_CFG, (1 << 29));
  3997. val |= (1 << 29);
  3998. }
  3999. }
  4000. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4001. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4002. tw32(GRC_MISC_CFG, val);
  4003. /* restore 5701 hardware bug workaround write method */
  4004. tp->write32 = write_op;
  4005. /* Unfortunately, we have to delay before the PCI read back.
  4006. * Some 575X chips even will not respond to a PCI cfg access
  4007. * when the reset command is given to the chip.
  4008. *
  4009. * How do these hardware designers expect things to work
  4010. * properly if the PCI write is posted for a long period
  4011. * of time? It is always necessary to have some method by
  4012. * which a register read back can occur to push the write
  4013. * out which does the reset.
  4014. *
  4015. * For most tg3 variants the trick below was working.
  4016. * Ho hum...
  4017. */
  4018. udelay(120);
  4019. /* Flush PCI posted writes. The normal MMIO registers
  4020. * are inaccessible at this time so this is the only
  4021. * way to make this reliably (actually, this is no longer
  4022. * the case, see above). I tried to use indirect
  4023. * register read/write but this upset some 5701 variants.
  4024. */
  4025. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4026. udelay(120);
  4027. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4028. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4029. int i;
  4030. u32 cfg_val;
  4031. /* Wait for link training to complete. */
  4032. for (i = 0; i < 5000; i++)
  4033. udelay(100);
  4034. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4035. pci_write_config_dword(tp->pdev, 0xc4,
  4036. cfg_val | (1 << 15));
  4037. }
  4038. /* Set PCIE max payload size and clear error status. */
  4039. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4040. }
  4041. /* Re-enable indirect register accesses. */
  4042. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4043. tp->misc_host_ctrl);
  4044. /* Set MAX PCI retry to zero. */
  4045. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4046. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4047. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4048. val |= PCISTATE_RETRY_SAME_DMA;
  4049. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4050. pci_restore_state(tp->pdev);
  4051. /* Make sure PCI-X relaxed ordering bit is clear. */
  4052. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4053. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4054. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4055. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4056. u32 val;
  4057. /* Chip reset on 5780 will reset MSI enable bit,
  4058. * so need to restore it.
  4059. */
  4060. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4061. u16 ctrl;
  4062. pci_read_config_word(tp->pdev,
  4063. tp->msi_cap + PCI_MSI_FLAGS,
  4064. &ctrl);
  4065. pci_write_config_word(tp->pdev,
  4066. tp->msi_cap + PCI_MSI_FLAGS,
  4067. ctrl | PCI_MSI_FLAGS_ENABLE);
  4068. val = tr32(MSGINT_MODE);
  4069. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4070. }
  4071. val = tr32(MEMARB_MODE);
  4072. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4073. } else
  4074. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4075. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4076. tg3_stop_fw(tp);
  4077. tw32(0x5000, 0x400);
  4078. }
  4079. tw32(GRC_MODE, tp->grc_mode);
  4080. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4081. u32 val = tr32(0xc4);
  4082. tw32(0xc4, val | (1 << 15));
  4083. }
  4084. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4085. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4086. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4087. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4088. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4089. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4090. }
  4091. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4092. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4093. tw32_f(MAC_MODE, tp->mac_mode);
  4094. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4095. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4096. tw32_f(MAC_MODE, tp->mac_mode);
  4097. } else
  4098. tw32_f(MAC_MODE, 0);
  4099. udelay(40);
  4100. /* Wait for firmware initialization to complete. */
  4101. for (i = 0; i < 100000; i++) {
  4102. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4103. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4104. break;
  4105. udelay(10);
  4106. }
  4107. /* Chip might not be fitted with firmare. Some Sun onboard
  4108. * parts are configured like that. So don't signal the timeout
  4109. * of the above loop as an error, but do report the lack of
  4110. * running firmware once.
  4111. */
  4112. if (i >= 100000 &&
  4113. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4114. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4115. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4116. tp->dev->name);
  4117. }
  4118. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4119. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4120. u32 val = tr32(0x7c00);
  4121. tw32(0x7c00, val | (1 << 25));
  4122. }
  4123. /* Reprobe ASF enable state. */
  4124. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4125. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4126. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4127. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4128. u32 nic_cfg;
  4129. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4130. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4131. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4132. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4133. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4134. }
  4135. }
  4136. return 0;
  4137. }
  4138. /* tp->lock is held. */
  4139. static void tg3_stop_fw(struct tg3 *tp)
  4140. {
  4141. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4142. u32 val;
  4143. int i;
  4144. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4145. val = tr32(GRC_RX_CPU_EVENT);
  4146. val |= (1 << 14);
  4147. tw32(GRC_RX_CPU_EVENT, val);
  4148. /* Wait for RX cpu to ACK the event. */
  4149. for (i = 0; i < 100; i++) {
  4150. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4151. break;
  4152. udelay(1);
  4153. }
  4154. }
  4155. }
  4156. /* tp->lock is held. */
  4157. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4158. {
  4159. int err;
  4160. tg3_stop_fw(tp);
  4161. tg3_write_sig_pre_reset(tp, kind);
  4162. tg3_abort_hw(tp, silent);
  4163. err = tg3_chip_reset(tp);
  4164. tg3_write_sig_legacy(tp, kind);
  4165. tg3_write_sig_post_reset(tp, kind);
  4166. if (err)
  4167. return err;
  4168. return 0;
  4169. }
  4170. #define TG3_FW_RELEASE_MAJOR 0x0
  4171. #define TG3_FW_RELASE_MINOR 0x0
  4172. #define TG3_FW_RELEASE_FIX 0x0
  4173. #define TG3_FW_START_ADDR 0x08000000
  4174. #define TG3_FW_TEXT_ADDR 0x08000000
  4175. #define TG3_FW_TEXT_LEN 0x9c0
  4176. #define TG3_FW_RODATA_ADDR 0x080009c0
  4177. #define TG3_FW_RODATA_LEN 0x60
  4178. #define TG3_FW_DATA_ADDR 0x08000a40
  4179. #define TG3_FW_DATA_LEN 0x20
  4180. #define TG3_FW_SBSS_ADDR 0x08000a60
  4181. #define TG3_FW_SBSS_LEN 0xc
  4182. #define TG3_FW_BSS_ADDR 0x08000a70
  4183. #define TG3_FW_BSS_LEN 0x10
  4184. static u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4185. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4186. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4187. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4188. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4189. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4190. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4191. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4192. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4193. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4194. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4195. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4196. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4197. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4198. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4199. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4200. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4201. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4202. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4203. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4204. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4205. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4206. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4207. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4210. 0, 0, 0, 0, 0, 0,
  4211. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4212. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4213. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4214. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4215. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4216. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4217. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4218. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4219. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4220. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4221. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4225. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4226. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4227. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4228. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4229. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4230. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4231. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4232. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4233. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4234. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4235. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4236. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4237. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4238. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4239. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4240. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4241. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4242. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4243. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4244. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4245. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4246. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4247. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4248. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4249. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4250. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4251. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4252. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4253. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4254. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4255. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4256. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4257. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4258. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4259. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4260. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4261. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4262. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4263. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4264. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4265. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4266. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4267. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4268. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4269. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4270. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4271. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4272. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4273. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4274. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4275. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4276. };
  4277. static u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4278. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4279. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4280. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4281. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4282. 0x00000000
  4283. };
  4284. #if 0 /* All zeros, don't eat up space with it. */
  4285. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4286. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4287. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4288. };
  4289. #endif
  4290. #define RX_CPU_SCRATCH_BASE 0x30000
  4291. #define RX_CPU_SCRATCH_SIZE 0x04000
  4292. #define TX_CPU_SCRATCH_BASE 0x34000
  4293. #define TX_CPU_SCRATCH_SIZE 0x04000
  4294. /* tp->lock is held. */
  4295. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4296. {
  4297. int i;
  4298. BUG_ON(offset == TX_CPU_BASE &&
  4299. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4300. if (offset == RX_CPU_BASE) {
  4301. for (i = 0; i < 10000; i++) {
  4302. tw32(offset + CPU_STATE, 0xffffffff);
  4303. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4304. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4305. break;
  4306. }
  4307. tw32(offset + CPU_STATE, 0xffffffff);
  4308. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4309. udelay(10);
  4310. } else {
  4311. for (i = 0; i < 10000; i++) {
  4312. tw32(offset + CPU_STATE, 0xffffffff);
  4313. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4314. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4315. break;
  4316. }
  4317. }
  4318. if (i >= 10000) {
  4319. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4320. "and %s CPU\n",
  4321. tp->dev->name,
  4322. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4323. return -ENODEV;
  4324. }
  4325. /* Clear firmware's nvram arbitration. */
  4326. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4327. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4328. return 0;
  4329. }
  4330. struct fw_info {
  4331. unsigned int text_base;
  4332. unsigned int text_len;
  4333. u32 *text_data;
  4334. unsigned int rodata_base;
  4335. unsigned int rodata_len;
  4336. u32 *rodata_data;
  4337. unsigned int data_base;
  4338. unsigned int data_len;
  4339. u32 *data_data;
  4340. };
  4341. /* tp->lock is held. */
  4342. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4343. int cpu_scratch_size, struct fw_info *info)
  4344. {
  4345. int err, lock_err, i;
  4346. void (*write_op)(struct tg3 *, u32, u32);
  4347. if (cpu_base == TX_CPU_BASE &&
  4348. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4349. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4350. "TX cpu firmware on %s which is 5705.\n",
  4351. tp->dev->name);
  4352. return -EINVAL;
  4353. }
  4354. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4355. write_op = tg3_write_mem;
  4356. else
  4357. write_op = tg3_write_indirect_reg32;
  4358. /* It is possible that bootcode is still loading at this point.
  4359. * Get the nvram lock first before halting the cpu.
  4360. */
  4361. lock_err = tg3_nvram_lock(tp);
  4362. err = tg3_halt_cpu(tp, cpu_base);
  4363. if (!lock_err)
  4364. tg3_nvram_unlock(tp);
  4365. if (err)
  4366. goto out;
  4367. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4368. write_op(tp, cpu_scratch_base + i, 0);
  4369. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4370. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4371. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4372. write_op(tp, (cpu_scratch_base +
  4373. (info->text_base & 0xffff) +
  4374. (i * sizeof(u32))),
  4375. (info->text_data ?
  4376. info->text_data[i] : 0));
  4377. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4378. write_op(tp, (cpu_scratch_base +
  4379. (info->rodata_base & 0xffff) +
  4380. (i * sizeof(u32))),
  4381. (info->rodata_data ?
  4382. info->rodata_data[i] : 0));
  4383. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4384. write_op(tp, (cpu_scratch_base +
  4385. (info->data_base & 0xffff) +
  4386. (i * sizeof(u32))),
  4387. (info->data_data ?
  4388. info->data_data[i] : 0));
  4389. err = 0;
  4390. out:
  4391. return err;
  4392. }
  4393. /* tp->lock is held. */
  4394. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4395. {
  4396. struct fw_info info;
  4397. int err, i;
  4398. info.text_base = TG3_FW_TEXT_ADDR;
  4399. info.text_len = TG3_FW_TEXT_LEN;
  4400. info.text_data = &tg3FwText[0];
  4401. info.rodata_base = TG3_FW_RODATA_ADDR;
  4402. info.rodata_len = TG3_FW_RODATA_LEN;
  4403. info.rodata_data = &tg3FwRodata[0];
  4404. info.data_base = TG3_FW_DATA_ADDR;
  4405. info.data_len = TG3_FW_DATA_LEN;
  4406. info.data_data = NULL;
  4407. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4408. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4409. &info);
  4410. if (err)
  4411. return err;
  4412. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4413. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4414. &info);
  4415. if (err)
  4416. return err;
  4417. /* Now startup only the RX cpu. */
  4418. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4419. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4420. for (i = 0; i < 5; i++) {
  4421. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4422. break;
  4423. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4424. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4425. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4426. udelay(1000);
  4427. }
  4428. if (i >= 5) {
  4429. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4430. "to set RX CPU PC, is %08x should be %08x\n",
  4431. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4432. TG3_FW_TEXT_ADDR);
  4433. return -ENODEV;
  4434. }
  4435. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4436. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4437. return 0;
  4438. }
  4439. #if TG3_TSO_SUPPORT != 0
  4440. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4441. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4442. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4443. #define TG3_TSO_FW_START_ADDR 0x08000000
  4444. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4445. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4446. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4447. #define TG3_TSO_FW_RODATA_LEN 0x60
  4448. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4449. #define TG3_TSO_FW_DATA_LEN 0x30
  4450. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4451. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4452. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4453. #define TG3_TSO_FW_BSS_LEN 0x894
  4454. static u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4455. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4456. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4457. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4458. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4459. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4460. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4461. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4462. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4463. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4464. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4465. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4466. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4467. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4468. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4469. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4470. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4471. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4472. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4473. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4474. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4475. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4476. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4477. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4478. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4479. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4480. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4481. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4482. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4483. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4484. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4485. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4486. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4487. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4488. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4489. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4490. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4491. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4492. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4493. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4494. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4495. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4496. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4497. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4498. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4499. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4500. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4501. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4502. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4503. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4504. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4505. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4506. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4507. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4508. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4509. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4510. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4511. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4512. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4513. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4514. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4515. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4516. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4517. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4518. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4519. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4520. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4521. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4522. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4523. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4524. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4525. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4526. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4527. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4528. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4529. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4530. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4531. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4532. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4533. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4534. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4535. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4536. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4537. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4538. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4539. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4540. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4541. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4542. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4543. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4544. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4545. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4546. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4547. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4548. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4549. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4550. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4551. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4552. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4553. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4554. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4555. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4556. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4557. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4558. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4559. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4560. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4561. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4562. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4563. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4564. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4565. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4566. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4567. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4568. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4569. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4570. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4571. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4572. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4573. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4574. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4575. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4576. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4577. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4578. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4579. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4580. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4581. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4582. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4583. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4584. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4585. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4586. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4587. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4588. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4589. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4590. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4591. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4592. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4593. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4594. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4595. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4596. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4597. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4598. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4599. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4600. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4601. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4602. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4603. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4604. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4605. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4606. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4607. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4608. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4609. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4610. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4611. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4612. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4613. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4614. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4615. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4616. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4617. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4618. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4619. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4620. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4621. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4622. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4623. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4624. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4625. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4626. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4627. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4628. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4629. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4630. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4631. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4632. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4633. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4634. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4635. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4636. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4637. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4638. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4639. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4640. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4641. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4642. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4643. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4644. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4645. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4646. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4647. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4648. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4649. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4650. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4651. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4652. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4653. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4654. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4655. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4656. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4657. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4658. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4659. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4660. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4661. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4662. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4663. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4664. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4665. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4666. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4667. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4668. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4669. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4670. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4671. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4672. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4673. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4674. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4675. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4676. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4677. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4678. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4679. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4680. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4681. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4682. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4683. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4684. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4685. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4686. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4687. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4688. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4689. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4690. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4691. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4692. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4693. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4694. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4695. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4696. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4697. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4698. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4699. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4700. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4701. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4702. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4703. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4704. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4705. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4706. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4707. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4708. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4709. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4710. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4711. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4712. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4713. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4714. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4715. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4716. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4717. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4718. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4719. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4720. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4721. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4722. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4723. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4724. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4725. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4726. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4727. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4728. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4729. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4730. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4731. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4732. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4733. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4734. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4735. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4736. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4737. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4738. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4739. };
  4740. static u32 tg3TsoFwRodata[] = {
  4741. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4742. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4743. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4744. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4745. 0x00000000,
  4746. };
  4747. static u32 tg3TsoFwData[] = {
  4748. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4749. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4750. 0x00000000,
  4751. };
  4752. /* 5705 needs a special version of the TSO firmware. */
  4753. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4754. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4755. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4756. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4757. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4758. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4759. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4760. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4761. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4762. #define TG3_TSO5_FW_DATA_LEN 0x20
  4763. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4764. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4765. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4766. #define TG3_TSO5_FW_BSS_LEN 0x88
  4767. static u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4768. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4769. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4770. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4771. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4772. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4773. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4774. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4775. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4776. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4777. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4778. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4779. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4780. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4781. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4782. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4783. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4784. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4785. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4786. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4787. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4788. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4789. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4790. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4791. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4792. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4793. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4794. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4795. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4796. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4797. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4798. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4799. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4800. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4801. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4802. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4803. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4804. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4805. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4806. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4807. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4808. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4809. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4810. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4811. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4812. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4813. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4814. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4815. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4816. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4817. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4818. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4819. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4820. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4821. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4822. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4823. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4824. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4825. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4826. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4827. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4828. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4829. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4830. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4831. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4832. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4833. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4834. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4835. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4836. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4837. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4838. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4839. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4840. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4841. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4842. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4843. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4844. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4845. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4846. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4847. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4848. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4849. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4850. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4851. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4852. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4853. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4854. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4855. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4856. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4857. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4858. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4859. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4860. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4861. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4862. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4863. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4864. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4865. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4866. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  4867. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  4868. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  4869. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  4870. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  4871. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  4872. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  4873. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  4874. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4875. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4876. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  4877. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  4878. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  4879. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  4880. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  4881. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  4882. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  4883. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  4884. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  4885. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4886. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4887. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  4888. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  4889. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  4890. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  4891. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4892. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  4893. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  4894. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  4895. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  4896. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  4897. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  4898. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  4899. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  4900. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  4901. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  4902. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  4903. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  4904. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  4905. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  4906. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  4907. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  4908. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  4909. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  4910. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  4911. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  4912. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  4913. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  4914. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  4915. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4916. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  4917. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  4918. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  4919. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4920. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  4921. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  4922. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4923. 0x00000000, 0x00000000, 0x00000000,
  4924. };
  4925. static u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  4926. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4927. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  4928. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4929. 0x00000000, 0x00000000, 0x00000000,
  4930. };
  4931. static u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  4932. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  4933. 0x00000000, 0x00000000, 0x00000000,
  4934. };
  4935. /* tp->lock is held. */
  4936. static int tg3_load_tso_firmware(struct tg3 *tp)
  4937. {
  4938. struct fw_info info;
  4939. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  4940. int err, i;
  4941. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  4942. return 0;
  4943. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4944. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  4945. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  4946. info.text_data = &tg3Tso5FwText[0];
  4947. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  4948. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  4949. info.rodata_data = &tg3Tso5FwRodata[0];
  4950. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  4951. info.data_len = TG3_TSO5_FW_DATA_LEN;
  4952. info.data_data = &tg3Tso5FwData[0];
  4953. cpu_base = RX_CPU_BASE;
  4954. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  4955. cpu_scratch_size = (info.text_len +
  4956. info.rodata_len +
  4957. info.data_len +
  4958. TG3_TSO5_FW_SBSS_LEN +
  4959. TG3_TSO5_FW_BSS_LEN);
  4960. } else {
  4961. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  4962. info.text_len = TG3_TSO_FW_TEXT_LEN;
  4963. info.text_data = &tg3TsoFwText[0];
  4964. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  4965. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  4966. info.rodata_data = &tg3TsoFwRodata[0];
  4967. info.data_base = TG3_TSO_FW_DATA_ADDR;
  4968. info.data_len = TG3_TSO_FW_DATA_LEN;
  4969. info.data_data = &tg3TsoFwData[0];
  4970. cpu_base = TX_CPU_BASE;
  4971. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  4972. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  4973. }
  4974. err = tg3_load_firmware_cpu(tp, cpu_base,
  4975. cpu_scratch_base, cpu_scratch_size,
  4976. &info);
  4977. if (err)
  4978. return err;
  4979. /* Now startup the cpu. */
  4980. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4981. tw32_f(cpu_base + CPU_PC, info.text_base);
  4982. for (i = 0; i < 5; i++) {
  4983. if (tr32(cpu_base + CPU_PC) == info.text_base)
  4984. break;
  4985. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4986. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  4987. tw32_f(cpu_base + CPU_PC, info.text_base);
  4988. udelay(1000);
  4989. }
  4990. if (i >= 5) {
  4991. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  4992. "to set CPU PC, is %08x should be %08x\n",
  4993. tp->dev->name, tr32(cpu_base + CPU_PC),
  4994. info.text_base);
  4995. return -ENODEV;
  4996. }
  4997. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4998. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  4999. return 0;
  5000. }
  5001. #endif /* TG3_TSO_SUPPORT != 0 */
  5002. /* tp->lock is held. */
  5003. static void __tg3_set_mac_addr(struct tg3 *tp)
  5004. {
  5005. u32 addr_high, addr_low;
  5006. int i;
  5007. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5008. tp->dev->dev_addr[1]);
  5009. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5010. (tp->dev->dev_addr[3] << 16) |
  5011. (tp->dev->dev_addr[4] << 8) |
  5012. (tp->dev->dev_addr[5] << 0));
  5013. for (i = 0; i < 4; i++) {
  5014. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5015. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5016. }
  5017. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5018. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5019. for (i = 0; i < 12; i++) {
  5020. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5021. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5022. }
  5023. }
  5024. addr_high = (tp->dev->dev_addr[0] +
  5025. tp->dev->dev_addr[1] +
  5026. tp->dev->dev_addr[2] +
  5027. tp->dev->dev_addr[3] +
  5028. tp->dev->dev_addr[4] +
  5029. tp->dev->dev_addr[5]) &
  5030. TX_BACKOFF_SEED_MASK;
  5031. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5032. }
  5033. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5034. {
  5035. struct tg3 *tp = netdev_priv(dev);
  5036. struct sockaddr *addr = p;
  5037. int err = 0;
  5038. if (!is_valid_ether_addr(addr->sa_data))
  5039. return -EINVAL;
  5040. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5041. if (!netif_running(dev))
  5042. return 0;
  5043. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5044. /* Reset chip so that ASF can re-init any MAC addresses it
  5045. * needs.
  5046. */
  5047. tg3_netif_stop(tp);
  5048. tg3_full_lock(tp, 1);
  5049. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5050. err = tg3_restart_hw(tp, 0);
  5051. if (!err)
  5052. tg3_netif_start(tp);
  5053. tg3_full_unlock(tp);
  5054. } else {
  5055. spin_lock_bh(&tp->lock);
  5056. __tg3_set_mac_addr(tp);
  5057. spin_unlock_bh(&tp->lock);
  5058. }
  5059. return err;
  5060. }
  5061. /* tp->lock is held. */
  5062. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5063. dma_addr_t mapping, u32 maxlen_flags,
  5064. u32 nic_addr)
  5065. {
  5066. tg3_write_mem(tp,
  5067. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5068. ((u64) mapping >> 32));
  5069. tg3_write_mem(tp,
  5070. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5071. ((u64) mapping & 0xffffffff));
  5072. tg3_write_mem(tp,
  5073. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5074. maxlen_flags);
  5075. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5076. tg3_write_mem(tp,
  5077. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5078. nic_addr);
  5079. }
  5080. static void __tg3_set_rx_mode(struct net_device *);
  5081. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5082. {
  5083. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5084. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5085. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5086. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5087. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5088. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5089. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5090. }
  5091. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5092. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5093. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5094. u32 val = ec->stats_block_coalesce_usecs;
  5095. if (!netif_carrier_ok(tp->dev))
  5096. val = 0;
  5097. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5098. }
  5099. }
  5100. /* tp->lock is held. */
  5101. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5102. {
  5103. u32 val, rdmac_mode;
  5104. int i, err, limit;
  5105. tg3_disable_ints(tp);
  5106. tg3_stop_fw(tp);
  5107. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5108. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5109. tg3_abort_hw(tp, 1);
  5110. }
  5111. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) && reset_phy)
  5112. tg3_phy_reset(tp);
  5113. err = tg3_chip_reset(tp);
  5114. if (err)
  5115. return err;
  5116. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5117. /* This works around an issue with Athlon chipsets on
  5118. * B3 tigon3 silicon. This bit has no effect on any
  5119. * other revision. But do not set this on PCI Express
  5120. * chips.
  5121. */
  5122. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5123. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5124. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5125. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5126. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5127. val = tr32(TG3PCI_PCISTATE);
  5128. val |= PCISTATE_RETRY_SAME_DMA;
  5129. tw32(TG3PCI_PCISTATE, val);
  5130. }
  5131. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5132. /* Enable some hw fixes. */
  5133. val = tr32(TG3PCI_MSI_DATA);
  5134. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5135. tw32(TG3PCI_MSI_DATA, val);
  5136. }
  5137. /* Descriptor ring init may make accesses to the
  5138. * NIC SRAM area to setup the TX descriptors, so we
  5139. * can only do this after the hardware has been
  5140. * successfully reset.
  5141. */
  5142. err = tg3_init_rings(tp);
  5143. if (err)
  5144. return err;
  5145. /* This value is determined during the probe time DMA
  5146. * engine test, tg3_test_dma.
  5147. */
  5148. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5149. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5150. GRC_MODE_4X_NIC_SEND_RINGS |
  5151. GRC_MODE_NO_TX_PHDR_CSUM |
  5152. GRC_MODE_NO_RX_PHDR_CSUM);
  5153. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5154. /* Pseudo-header checksum is done by hardware logic and not
  5155. * the offload processers, so make the chip do the pseudo-
  5156. * header checksums on receive. For transmit it is more
  5157. * convenient to do the pseudo-header checksum in software
  5158. * as Linux does that on transmit for us in all cases.
  5159. */
  5160. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5161. tw32(GRC_MODE,
  5162. tp->grc_mode |
  5163. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5164. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5165. val = tr32(GRC_MISC_CFG);
  5166. val &= ~0xff;
  5167. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5168. tw32(GRC_MISC_CFG, val);
  5169. /* Initialize MBUF/DESC pool. */
  5170. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5171. /* Do nothing. */
  5172. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5173. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5174. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5175. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5176. else
  5177. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5178. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5179. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5180. }
  5181. #if TG3_TSO_SUPPORT != 0
  5182. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5183. int fw_len;
  5184. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5185. TG3_TSO5_FW_RODATA_LEN +
  5186. TG3_TSO5_FW_DATA_LEN +
  5187. TG3_TSO5_FW_SBSS_LEN +
  5188. TG3_TSO5_FW_BSS_LEN);
  5189. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5190. tw32(BUFMGR_MB_POOL_ADDR,
  5191. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5192. tw32(BUFMGR_MB_POOL_SIZE,
  5193. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5194. }
  5195. #endif
  5196. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5197. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5198. tp->bufmgr_config.mbuf_read_dma_low_water);
  5199. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5200. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5201. tw32(BUFMGR_MB_HIGH_WATER,
  5202. tp->bufmgr_config.mbuf_high_water);
  5203. } else {
  5204. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5205. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5206. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5207. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5208. tw32(BUFMGR_MB_HIGH_WATER,
  5209. tp->bufmgr_config.mbuf_high_water_jumbo);
  5210. }
  5211. tw32(BUFMGR_DMA_LOW_WATER,
  5212. tp->bufmgr_config.dma_low_water);
  5213. tw32(BUFMGR_DMA_HIGH_WATER,
  5214. tp->bufmgr_config.dma_high_water);
  5215. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5216. for (i = 0; i < 2000; i++) {
  5217. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5218. break;
  5219. udelay(10);
  5220. }
  5221. if (i >= 2000) {
  5222. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5223. tp->dev->name);
  5224. return -ENODEV;
  5225. }
  5226. /* Setup replenish threshold. */
  5227. val = tp->rx_pending / 8;
  5228. if (val == 0)
  5229. val = 1;
  5230. else if (val > tp->rx_std_max_post)
  5231. val = tp->rx_std_max_post;
  5232. tw32(RCVBDI_STD_THRESH, val);
  5233. /* Initialize TG3_BDINFO's at:
  5234. * RCVDBDI_STD_BD: standard eth size rx ring
  5235. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5236. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5237. *
  5238. * like so:
  5239. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5240. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5241. * ring attribute flags
  5242. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5243. *
  5244. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5245. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5246. *
  5247. * The size of each ring is fixed in the firmware, but the location is
  5248. * configurable.
  5249. */
  5250. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5251. ((u64) tp->rx_std_mapping >> 32));
  5252. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5253. ((u64) tp->rx_std_mapping & 0xffffffff));
  5254. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5255. NIC_SRAM_RX_BUFFER_DESC);
  5256. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5257. * configs on 5705.
  5258. */
  5259. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5260. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5261. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5262. } else {
  5263. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5264. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5265. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5266. BDINFO_FLAGS_DISABLED);
  5267. /* Setup replenish threshold. */
  5268. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5269. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5270. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5271. ((u64) tp->rx_jumbo_mapping >> 32));
  5272. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5273. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5274. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5275. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5276. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5277. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5278. } else {
  5279. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5280. BDINFO_FLAGS_DISABLED);
  5281. }
  5282. }
  5283. /* There is only one send ring on 5705/5750, no need to explicitly
  5284. * disable the others.
  5285. */
  5286. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5287. /* Clear out send RCB ring in SRAM. */
  5288. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5289. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5290. BDINFO_FLAGS_DISABLED);
  5291. }
  5292. tp->tx_prod = 0;
  5293. tp->tx_cons = 0;
  5294. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5295. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5296. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5297. tp->tx_desc_mapping,
  5298. (TG3_TX_RING_SIZE <<
  5299. BDINFO_FLAGS_MAXLEN_SHIFT),
  5300. NIC_SRAM_TX_BUFFER_DESC);
  5301. /* There is only one receive return ring on 5705/5750, no need
  5302. * to explicitly disable the others.
  5303. */
  5304. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5305. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5306. i += TG3_BDINFO_SIZE) {
  5307. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5308. BDINFO_FLAGS_DISABLED);
  5309. }
  5310. }
  5311. tp->rx_rcb_ptr = 0;
  5312. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5313. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5314. tp->rx_rcb_mapping,
  5315. (TG3_RX_RCB_RING_SIZE(tp) <<
  5316. BDINFO_FLAGS_MAXLEN_SHIFT),
  5317. 0);
  5318. tp->rx_std_ptr = tp->rx_pending;
  5319. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5320. tp->rx_std_ptr);
  5321. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5322. tp->rx_jumbo_pending : 0;
  5323. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5324. tp->rx_jumbo_ptr);
  5325. /* Initialize MAC address and backoff seed. */
  5326. __tg3_set_mac_addr(tp);
  5327. /* MTU + ethernet header + FCS + optional VLAN tag */
  5328. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5329. /* The slot time is changed by tg3_setup_phy if we
  5330. * run at gigabit with half duplex.
  5331. */
  5332. tw32(MAC_TX_LENGTHS,
  5333. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5334. (6 << TX_LENGTHS_IPG_SHIFT) |
  5335. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5336. /* Receive rules. */
  5337. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5338. tw32(RCVLPC_CONFIG, 0x0181);
  5339. /* Calculate RDMAC_MODE setting early, we need it to determine
  5340. * the RCVLPC_STATE_ENABLE mask.
  5341. */
  5342. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5343. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5344. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5345. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5346. RDMAC_MODE_LNGREAD_ENAB);
  5347. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  5348. rdmac_mode |= RDMAC_MODE_SPLIT_ENABLE;
  5349. /* If statement applies to 5705 and 5750 PCI devices only */
  5350. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5351. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5352. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5353. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5354. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5355. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5356. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5357. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5358. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5359. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5360. }
  5361. }
  5362. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5363. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5364. #if TG3_TSO_SUPPORT != 0
  5365. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5366. rdmac_mode |= (1 << 27);
  5367. #endif
  5368. /* Receive/send statistics. */
  5369. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5370. val = tr32(RCVLPC_STATS_ENABLE);
  5371. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5372. tw32(RCVLPC_STATS_ENABLE, val);
  5373. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5374. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5375. val = tr32(RCVLPC_STATS_ENABLE);
  5376. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5377. tw32(RCVLPC_STATS_ENABLE, val);
  5378. } else {
  5379. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5380. }
  5381. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5382. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5383. tw32(SNDDATAI_STATSCTRL,
  5384. (SNDDATAI_SCTRL_ENABLE |
  5385. SNDDATAI_SCTRL_FASTUPD));
  5386. /* Setup host coalescing engine. */
  5387. tw32(HOSTCC_MODE, 0);
  5388. for (i = 0; i < 2000; i++) {
  5389. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5390. break;
  5391. udelay(10);
  5392. }
  5393. __tg3_set_coalesce(tp, &tp->coal);
  5394. /* set status block DMA address */
  5395. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5396. ((u64) tp->status_mapping >> 32));
  5397. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5398. ((u64) tp->status_mapping & 0xffffffff));
  5399. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5400. /* Status/statistics block address. See tg3_timer,
  5401. * the tg3_periodic_fetch_stats call there, and
  5402. * tg3_get_stats to see how this works for 5705/5750 chips.
  5403. */
  5404. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5405. ((u64) tp->stats_mapping >> 32));
  5406. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5407. ((u64) tp->stats_mapping & 0xffffffff));
  5408. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5409. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5410. }
  5411. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5412. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5413. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5414. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5415. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5416. /* Clear statistics/status block in chip, and status block in ram. */
  5417. for (i = NIC_SRAM_STATS_BLK;
  5418. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5419. i += sizeof(u32)) {
  5420. tg3_write_mem(tp, i, 0);
  5421. udelay(40);
  5422. }
  5423. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5424. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5425. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5426. /* reset to prevent losing 1st rx packet intermittently */
  5427. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5428. udelay(10);
  5429. }
  5430. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5431. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5432. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5433. udelay(40);
  5434. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5435. * If TG3_FLAG_EEPROM_WRITE_PROT is set, we should read the
  5436. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5437. * whether used as inputs or outputs, are set by boot code after
  5438. * reset.
  5439. */
  5440. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  5441. u32 gpio_mask;
  5442. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE2 |
  5443. GRC_LCLCTRL_GPIO_OUTPUT0 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5444. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5445. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5446. GRC_LCLCTRL_GPIO_OUTPUT3;
  5447. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5448. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5449. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5450. /* GPIO1 must be driven high for eeprom write protect */
  5451. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5452. GRC_LCLCTRL_GPIO_OUTPUT1);
  5453. }
  5454. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5455. udelay(100);
  5456. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5457. tp->last_tag = 0;
  5458. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5459. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5460. udelay(40);
  5461. }
  5462. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5463. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5464. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5465. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5466. WDMAC_MODE_LNGREAD_ENAB);
  5467. /* If statement applies to 5705 and 5750 PCI devices only */
  5468. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5469. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5470. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5471. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5472. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5473. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5474. /* nothing */
  5475. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5476. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5477. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5478. val |= WDMAC_MODE_RX_ACCEL;
  5479. }
  5480. }
  5481. /* Enable host coalescing bug fix */
  5482. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5483. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5484. val |= (1 << 29);
  5485. tw32_f(WDMAC_MODE, val);
  5486. udelay(40);
  5487. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5488. val = tr32(TG3PCI_X_CAPS);
  5489. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5490. val &= ~PCIX_CAPS_BURST_MASK;
  5491. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5492. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5493. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5494. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5495. if (tp->tg3_flags & TG3_FLAG_SPLIT_MODE)
  5496. val |= (tp->split_mode_max_reqs <<
  5497. PCIX_CAPS_SPLIT_SHIFT);
  5498. }
  5499. tw32(TG3PCI_X_CAPS, val);
  5500. }
  5501. tw32_f(RDMAC_MODE, rdmac_mode);
  5502. udelay(40);
  5503. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5504. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5505. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5506. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5507. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5508. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5509. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5510. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5511. #if TG3_TSO_SUPPORT != 0
  5512. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5513. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5514. #endif
  5515. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5516. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5517. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5518. err = tg3_load_5701_a0_firmware_fix(tp);
  5519. if (err)
  5520. return err;
  5521. }
  5522. #if TG3_TSO_SUPPORT != 0
  5523. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5524. err = tg3_load_tso_firmware(tp);
  5525. if (err)
  5526. return err;
  5527. }
  5528. #endif
  5529. tp->tx_mode = TX_MODE_ENABLE;
  5530. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5531. udelay(100);
  5532. tp->rx_mode = RX_MODE_ENABLE;
  5533. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5534. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5535. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5536. udelay(10);
  5537. if (tp->link_config.phy_is_low_power) {
  5538. tp->link_config.phy_is_low_power = 0;
  5539. tp->link_config.speed = tp->link_config.orig_speed;
  5540. tp->link_config.duplex = tp->link_config.orig_duplex;
  5541. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5542. }
  5543. tp->mi_mode = MAC_MI_MODE_BASE;
  5544. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5545. udelay(80);
  5546. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5547. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5548. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5549. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5550. udelay(10);
  5551. }
  5552. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5553. udelay(10);
  5554. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5555. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5556. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5557. /* Set drive transmission level to 1.2V */
  5558. /* only if the signal pre-emphasis bit is not set */
  5559. val = tr32(MAC_SERDES_CFG);
  5560. val &= 0xfffff000;
  5561. val |= 0x880;
  5562. tw32(MAC_SERDES_CFG, val);
  5563. }
  5564. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5565. tw32(MAC_SERDES_CFG, 0x616000);
  5566. }
  5567. /* Prevent chip from dropping frames when flow control
  5568. * is enabled.
  5569. */
  5570. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5571. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5572. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5573. /* Use hardware link auto-negotiation */
  5574. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5575. }
  5576. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5577. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5578. u32 tmp;
  5579. tmp = tr32(SERDES_RX_CTRL);
  5580. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5581. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5582. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5583. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5584. }
  5585. err = tg3_setup_phy(tp, reset_phy);
  5586. if (err)
  5587. return err;
  5588. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5589. u32 tmp;
  5590. /* Clear CRC stats. */
  5591. if (!tg3_readphy(tp, 0x1e, &tmp)) {
  5592. tg3_writephy(tp, 0x1e, tmp | 0x8000);
  5593. tg3_readphy(tp, 0x14, &tmp);
  5594. }
  5595. }
  5596. __tg3_set_rx_mode(tp->dev);
  5597. /* Initialize receive rules. */
  5598. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5599. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5600. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5601. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5602. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5603. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5604. limit = 8;
  5605. else
  5606. limit = 16;
  5607. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5608. limit -= 4;
  5609. switch (limit) {
  5610. case 16:
  5611. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5612. case 15:
  5613. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5614. case 14:
  5615. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5616. case 13:
  5617. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5618. case 12:
  5619. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5620. case 11:
  5621. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5622. case 10:
  5623. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5624. case 9:
  5625. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5626. case 8:
  5627. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5628. case 7:
  5629. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5630. case 6:
  5631. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5632. case 5:
  5633. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5634. case 4:
  5635. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5636. case 3:
  5637. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5638. case 2:
  5639. case 1:
  5640. default:
  5641. break;
  5642. };
  5643. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5644. return 0;
  5645. }
  5646. /* Called at device open time to get the chip ready for
  5647. * packet processing. Invoked with tp->lock held.
  5648. */
  5649. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5650. {
  5651. int err;
  5652. /* Force the chip into D0. */
  5653. err = tg3_set_power_state(tp, PCI_D0);
  5654. if (err)
  5655. goto out;
  5656. tg3_switch_clocks(tp);
  5657. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5658. err = tg3_reset_hw(tp, reset_phy);
  5659. out:
  5660. return err;
  5661. }
  5662. #define TG3_STAT_ADD32(PSTAT, REG) \
  5663. do { u32 __val = tr32(REG); \
  5664. (PSTAT)->low += __val; \
  5665. if ((PSTAT)->low < __val) \
  5666. (PSTAT)->high += 1; \
  5667. } while (0)
  5668. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5669. {
  5670. struct tg3_hw_stats *sp = tp->hw_stats;
  5671. if (!netif_carrier_ok(tp->dev))
  5672. return;
  5673. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5674. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5675. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5676. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5677. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5678. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5679. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5680. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5681. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5682. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5683. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5684. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5685. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5686. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5687. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5688. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5689. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5690. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5691. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5692. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5693. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5694. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5695. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5696. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5697. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5698. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5699. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5700. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5701. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5702. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5703. }
  5704. static void tg3_timer(unsigned long __opaque)
  5705. {
  5706. struct tg3 *tp = (struct tg3 *) __opaque;
  5707. if (tp->irq_sync)
  5708. goto restart_timer;
  5709. spin_lock(&tp->lock);
  5710. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5711. /* All of this garbage is because when using non-tagged
  5712. * IRQ status the mailbox/status_block protocol the chip
  5713. * uses with the cpu is race prone.
  5714. */
  5715. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5716. tw32(GRC_LOCAL_CTRL,
  5717. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5718. } else {
  5719. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5720. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5721. }
  5722. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5723. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5724. spin_unlock(&tp->lock);
  5725. schedule_work(&tp->reset_task);
  5726. return;
  5727. }
  5728. }
  5729. /* This part only runs once per second. */
  5730. if (!--tp->timer_counter) {
  5731. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5732. tg3_periodic_fetch_stats(tp);
  5733. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5734. u32 mac_stat;
  5735. int phy_event;
  5736. mac_stat = tr32(MAC_STATUS);
  5737. phy_event = 0;
  5738. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5739. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5740. phy_event = 1;
  5741. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5742. phy_event = 1;
  5743. if (phy_event)
  5744. tg3_setup_phy(tp, 0);
  5745. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5746. u32 mac_stat = tr32(MAC_STATUS);
  5747. int need_setup = 0;
  5748. if (netif_carrier_ok(tp->dev) &&
  5749. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5750. need_setup = 1;
  5751. }
  5752. if (! netif_carrier_ok(tp->dev) &&
  5753. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5754. MAC_STATUS_SIGNAL_DET))) {
  5755. need_setup = 1;
  5756. }
  5757. if (need_setup) {
  5758. tw32_f(MAC_MODE,
  5759. (tp->mac_mode &
  5760. ~MAC_MODE_PORT_MODE_MASK));
  5761. udelay(40);
  5762. tw32_f(MAC_MODE, tp->mac_mode);
  5763. udelay(40);
  5764. tg3_setup_phy(tp, 0);
  5765. }
  5766. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5767. tg3_serdes_parallel_detect(tp);
  5768. tp->timer_counter = tp->timer_multiplier;
  5769. }
  5770. /* Heartbeat is only sent once every 2 seconds. */
  5771. if (!--tp->asf_counter) {
  5772. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5773. u32 val;
  5774. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5775. FWCMD_NICDRV_ALIVE2);
  5776. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5777. /* 5 seconds timeout */
  5778. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5779. val = tr32(GRC_RX_CPU_EVENT);
  5780. val |= (1 << 14);
  5781. tw32(GRC_RX_CPU_EVENT, val);
  5782. }
  5783. tp->asf_counter = tp->asf_multiplier;
  5784. }
  5785. spin_unlock(&tp->lock);
  5786. restart_timer:
  5787. tp->timer.expires = jiffies + tp->timer_offset;
  5788. add_timer(&tp->timer);
  5789. }
  5790. static int tg3_request_irq(struct tg3 *tp)
  5791. {
  5792. irqreturn_t (*fn)(int, void *, struct pt_regs *);
  5793. unsigned long flags;
  5794. struct net_device *dev = tp->dev;
  5795. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5796. fn = tg3_msi;
  5797. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5798. fn = tg3_msi_1shot;
  5799. flags = IRQF_SAMPLE_RANDOM;
  5800. } else {
  5801. fn = tg3_interrupt;
  5802. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5803. fn = tg3_interrupt_tagged;
  5804. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5805. }
  5806. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5807. }
  5808. static int tg3_test_interrupt(struct tg3 *tp)
  5809. {
  5810. struct net_device *dev = tp->dev;
  5811. int err, i;
  5812. u32 int_mbox = 0;
  5813. if (!netif_running(dev))
  5814. return -ENODEV;
  5815. tg3_disable_ints(tp);
  5816. free_irq(tp->pdev->irq, dev);
  5817. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5818. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5819. if (err)
  5820. return err;
  5821. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5822. tg3_enable_ints(tp);
  5823. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5824. HOSTCC_MODE_NOW);
  5825. for (i = 0; i < 5; i++) {
  5826. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5827. TG3_64BIT_REG_LOW);
  5828. if (int_mbox != 0)
  5829. break;
  5830. msleep(10);
  5831. }
  5832. tg3_disable_ints(tp);
  5833. free_irq(tp->pdev->irq, dev);
  5834. err = tg3_request_irq(tp);
  5835. if (err)
  5836. return err;
  5837. if (int_mbox != 0)
  5838. return 0;
  5839. return -EIO;
  5840. }
  5841. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5842. * successfully restored
  5843. */
  5844. static int tg3_test_msi(struct tg3 *tp)
  5845. {
  5846. struct net_device *dev = tp->dev;
  5847. int err;
  5848. u16 pci_cmd;
  5849. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  5850. return 0;
  5851. /* Turn off SERR reporting in case MSI terminates with Master
  5852. * Abort.
  5853. */
  5854. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  5855. pci_write_config_word(tp->pdev, PCI_COMMAND,
  5856. pci_cmd & ~PCI_COMMAND_SERR);
  5857. err = tg3_test_interrupt(tp);
  5858. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  5859. if (!err)
  5860. return 0;
  5861. /* other failures */
  5862. if (err != -EIO)
  5863. return err;
  5864. /* MSI test failed, go back to INTx mode */
  5865. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  5866. "switching to INTx mode. Please report this failure to "
  5867. "the PCI maintainer and include system chipset information.\n",
  5868. tp->dev->name);
  5869. free_irq(tp->pdev->irq, dev);
  5870. pci_disable_msi(tp->pdev);
  5871. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5872. err = tg3_request_irq(tp);
  5873. if (err)
  5874. return err;
  5875. /* Need to reset the chip because the MSI cycle may have terminated
  5876. * with Master Abort.
  5877. */
  5878. tg3_full_lock(tp, 1);
  5879. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5880. err = tg3_init_hw(tp, 1);
  5881. tg3_full_unlock(tp);
  5882. if (err)
  5883. free_irq(tp->pdev->irq, dev);
  5884. return err;
  5885. }
  5886. static int tg3_open(struct net_device *dev)
  5887. {
  5888. struct tg3 *tp = netdev_priv(dev);
  5889. int err;
  5890. tg3_full_lock(tp, 0);
  5891. err = tg3_set_power_state(tp, PCI_D0);
  5892. if (err)
  5893. return err;
  5894. tg3_disable_ints(tp);
  5895. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  5896. tg3_full_unlock(tp);
  5897. /* The placement of this call is tied
  5898. * to the setup and use of Host TX descriptors.
  5899. */
  5900. err = tg3_alloc_consistent(tp);
  5901. if (err)
  5902. return err;
  5903. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  5904. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
  5905. (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
  5906. !((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) &&
  5907. (tp->pdev_peer == tp->pdev))) {
  5908. /* All MSI supporting chips should support tagged
  5909. * status. Assert that this is the case.
  5910. */
  5911. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5912. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  5913. "Not using MSI.\n", tp->dev->name);
  5914. } else if (pci_enable_msi(tp->pdev) == 0) {
  5915. u32 msi_mode;
  5916. msi_mode = tr32(MSGINT_MODE);
  5917. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  5918. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  5919. }
  5920. }
  5921. err = tg3_request_irq(tp);
  5922. if (err) {
  5923. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5924. pci_disable_msi(tp->pdev);
  5925. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5926. }
  5927. tg3_free_consistent(tp);
  5928. return err;
  5929. }
  5930. tg3_full_lock(tp, 0);
  5931. err = tg3_init_hw(tp, 1);
  5932. if (err) {
  5933. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5934. tg3_free_rings(tp);
  5935. } else {
  5936. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5937. tp->timer_offset = HZ;
  5938. else
  5939. tp->timer_offset = HZ / 10;
  5940. BUG_ON(tp->timer_offset > HZ);
  5941. tp->timer_counter = tp->timer_multiplier =
  5942. (HZ / tp->timer_offset);
  5943. tp->asf_counter = tp->asf_multiplier =
  5944. ((HZ / tp->timer_offset) * 2);
  5945. init_timer(&tp->timer);
  5946. tp->timer.expires = jiffies + tp->timer_offset;
  5947. tp->timer.data = (unsigned long) tp;
  5948. tp->timer.function = tg3_timer;
  5949. }
  5950. tg3_full_unlock(tp);
  5951. if (err) {
  5952. free_irq(tp->pdev->irq, dev);
  5953. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5954. pci_disable_msi(tp->pdev);
  5955. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5956. }
  5957. tg3_free_consistent(tp);
  5958. return err;
  5959. }
  5960. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5961. err = tg3_test_msi(tp);
  5962. if (err) {
  5963. tg3_full_lock(tp, 0);
  5964. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5965. pci_disable_msi(tp->pdev);
  5966. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5967. }
  5968. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5969. tg3_free_rings(tp);
  5970. tg3_free_consistent(tp);
  5971. tg3_full_unlock(tp);
  5972. return err;
  5973. }
  5974. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5975. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  5976. u32 val = tr32(0x7c04);
  5977. tw32(0x7c04, val | (1 << 29));
  5978. }
  5979. }
  5980. }
  5981. tg3_full_lock(tp, 0);
  5982. add_timer(&tp->timer);
  5983. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  5984. tg3_enable_ints(tp);
  5985. tg3_full_unlock(tp);
  5986. netif_start_queue(dev);
  5987. return 0;
  5988. }
  5989. #if 0
  5990. /*static*/ void tg3_dump_state(struct tg3 *tp)
  5991. {
  5992. u32 val32, val32_2, val32_3, val32_4, val32_5;
  5993. u16 val16;
  5994. int i;
  5995. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  5996. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  5997. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  5998. val16, val32);
  5999. /* MAC block */
  6000. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6001. tr32(MAC_MODE), tr32(MAC_STATUS));
  6002. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6003. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6004. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6005. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6006. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6007. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6008. /* Send data initiator control block */
  6009. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6010. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6011. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6012. tr32(SNDDATAI_STATSCTRL));
  6013. /* Send data completion control block */
  6014. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6015. /* Send BD ring selector block */
  6016. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6017. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6018. /* Send BD initiator control block */
  6019. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6020. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6021. /* Send BD completion control block */
  6022. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6023. /* Receive list placement control block */
  6024. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6025. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6026. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6027. tr32(RCVLPC_STATSCTRL));
  6028. /* Receive data and receive BD initiator control block */
  6029. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6030. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6031. /* Receive data completion control block */
  6032. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6033. tr32(RCVDCC_MODE));
  6034. /* Receive BD initiator control block */
  6035. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6036. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6037. /* Receive BD completion control block */
  6038. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6039. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6040. /* Receive list selector control block */
  6041. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6042. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6043. /* Mbuf cluster free block */
  6044. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6045. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6046. /* Host coalescing control block */
  6047. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6048. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6049. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6050. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6051. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6052. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6053. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6054. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6055. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6056. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6057. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6058. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6059. /* Memory arbiter control block */
  6060. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6061. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6062. /* Buffer manager control block */
  6063. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6064. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6065. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6066. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6067. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6068. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6069. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6070. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6071. /* Read DMA control block */
  6072. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6073. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6074. /* Write DMA control block */
  6075. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6076. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6077. /* DMA completion block */
  6078. printk("DEBUG: DMAC_MODE[%08x]\n",
  6079. tr32(DMAC_MODE));
  6080. /* GRC block */
  6081. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6082. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6083. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6084. tr32(GRC_LOCAL_CTRL));
  6085. /* TG3_BDINFOs */
  6086. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6087. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6088. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6089. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6090. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6091. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6092. tr32(RCVDBDI_STD_BD + 0x0),
  6093. tr32(RCVDBDI_STD_BD + 0x4),
  6094. tr32(RCVDBDI_STD_BD + 0x8),
  6095. tr32(RCVDBDI_STD_BD + 0xc));
  6096. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6097. tr32(RCVDBDI_MINI_BD + 0x0),
  6098. tr32(RCVDBDI_MINI_BD + 0x4),
  6099. tr32(RCVDBDI_MINI_BD + 0x8),
  6100. tr32(RCVDBDI_MINI_BD + 0xc));
  6101. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6102. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6103. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6104. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6105. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6106. val32, val32_2, val32_3, val32_4);
  6107. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6108. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6109. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6110. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6111. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6112. val32, val32_2, val32_3, val32_4);
  6113. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6114. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6115. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6116. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6117. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6118. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6119. val32, val32_2, val32_3, val32_4, val32_5);
  6120. /* SW status block */
  6121. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6122. tp->hw_status->status,
  6123. tp->hw_status->status_tag,
  6124. tp->hw_status->rx_jumbo_consumer,
  6125. tp->hw_status->rx_consumer,
  6126. tp->hw_status->rx_mini_consumer,
  6127. tp->hw_status->idx[0].rx_producer,
  6128. tp->hw_status->idx[0].tx_consumer);
  6129. /* SW statistics block */
  6130. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6131. ((u32 *)tp->hw_stats)[0],
  6132. ((u32 *)tp->hw_stats)[1],
  6133. ((u32 *)tp->hw_stats)[2],
  6134. ((u32 *)tp->hw_stats)[3]);
  6135. /* Mailboxes */
  6136. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6137. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6138. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6139. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6140. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6141. /* NIC side send descriptors. */
  6142. for (i = 0; i < 6; i++) {
  6143. unsigned long txd;
  6144. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6145. + (i * sizeof(struct tg3_tx_buffer_desc));
  6146. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6147. i,
  6148. readl(txd + 0x0), readl(txd + 0x4),
  6149. readl(txd + 0x8), readl(txd + 0xc));
  6150. }
  6151. /* NIC side RX descriptors. */
  6152. for (i = 0; i < 6; i++) {
  6153. unsigned long rxd;
  6154. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6155. + (i * sizeof(struct tg3_rx_buffer_desc));
  6156. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6157. i,
  6158. readl(rxd + 0x0), readl(rxd + 0x4),
  6159. readl(rxd + 0x8), readl(rxd + 0xc));
  6160. rxd += (4 * sizeof(u32));
  6161. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6162. i,
  6163. readl(rxd + 0x0), readl(rxd + 0x4),
  6164. readl(rxd + 0x8), readl(rxd + 0xc));
  6165. }
  6166. for (i = 0; i < 6; i++) {
  6167. unsigned long rxd;
  6168. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6169. + (i * sizeof(struct tg3_rx_buffer_desc));
  6170. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6171. i,
  6172. readl(rxd + 0x0), readl(rxd + 0x4),
  6173. readl(rxd + 0x8), readl(rxd + 0xc));
  6174. rxd += (4 * sizeof(u32));
  6175. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6176. i,
  6177. readl(rxd + 0x0), readl(rxd + 0x4),
  6178. readl(rxd + 0x8), readl(rxd + 0xc));
  6179. }
  6180. }
  6181. #endif
  6182. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6183. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6184. static int tg3_close(struct net_device *dev)
  6185. {
  6186. struct tg3 *tp = netdev_priv(dev);
  6187. /* Calling flush_scheduled_work() may deadlock because
  6188. * linkwatch_event() may be on the workqueue and it will try to get
  6189. * the rtnl_lock which we are holding.
  6190. */
  6191. while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
  6192. msleep(1);
  6193. netif_stop_queue(dev);
  6194. del_timer_sync(&tp->timer);
  6195. tg3_full_lock(tp, 1);
  6196. #if 0
  6197. tg3_dump_state(tp);
  6198. #endif
  6199. tg3_disable_ints(tp);
  6200. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6201. tg3_free_rings(tp);
  6202. tp->tg3_flags &=
  6203. ~(TG3_FLAG_INIT_COMPLETE |
  6204. TG3_FLAG_GOT_SERDES_FLOWCTL);
  6205. tg3_full_unlock(tp);
  6206. free_irq(tp->pdev->irq, dev);
  6207. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6208. pci_disable_msi(tp->pdev);
  6209. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6210. }
  6211. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6212. sizeof(tp->net_stats_prev));
  6213. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6214. sizeof(tp->estats_prev));
  6215. tg3_free_consistent(tp);
  6216. tg3_set_power_state(tp, PCI_D3hot);
  6217. netif_carrier_off(tp->dev);
  6218. return 0;
  6219. }
  6220. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6221. {
  6222. unsigned long ret;
  6223. #if (BITS_PER_LONG == 32)
  6224. ret = val->low;
  6225. #else
  6226. ret = ((u64)val->high << 32) | ((u64)val->low);
  6227. #endif
  6228. return ret;
  6229. }
  6230. static unsigned long calc_crc_errors(struct tg3 *tp)
  6231. {
  6232. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6233. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6234. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6235. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6236. u32 val;
  6237. spin_lock_bh(&tp->lock);
  6238. if (!tg3_readphy(tp, 0x1e, &val)) {
  6239. tg3_writephy(tp, 0x1e, val | 0x8000);
  6240. tg3_readphy(tp, 0x14, &val);
  6241. } else
  6242. val = 0;
  6243. spin_unlock_bh(&tp->lock);
  6244. tp->phy_crc_errors += val;
  6245. return tp->phy_crc_errors;
  6246. }
  6247. return get_stat64(&hw_stats->rx_fcs_errors);
  6248. }
  6249. #define ESTAT_ADD(member) \
  6250. estats->member = old_estats->member + \
  6251. get_stat64(&hw_stats->member)
  6252. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6253. {
  6254. struct tg3_ethtool_stats *estats = &tp->estats;
  6255. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6256. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6257. if (!hw_stats)
  6258. return old_estats;
  6259. ESTAT_ADD(rx_octets);
  6260. ESTAT_ADD(rx_fragments);
  6261. ESTAT_ADD(rx_ucast_packets);
  6262. ESTAT_ADD(rx_mcast_packets);
  6263. ESTAT_ADD(rx_bcast_packets);
  6264. ESTAT_ADD(rx_fcs_errors);
  6265. ESTAT_ADD(rx_align_errors);
  6266. ESTAT_ADD(rx_xon_pause_rcvd);
  6267. ESTAT_ADD(rx_xoff_pause_rcvd);
  6268. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6269. ESTAT_ADD(rx_xoff_entered);
  6270. ESTAT_ADD(rx_frame_too_long_errors);
  6271. ESTAT_ADD(rx_jabbers);
  6272. ESTAT_ADD(rx_undersize_packets);
  6273. ESTAT_ADD(rx_in_length_errors);
  6274. ESTAT_ADD(rx_out_length_errors);
  6275. ESTAT_ADD(rx_64_or_less_octet_packets);
  6276. ESTAT_ADD(rx_65_to_127_octet_packets);
  6277. ESTAT_ADD(rx_128_to_255_octet_packets);
  6278. ESTAT_ADD(rx_256_to_511_octet_packets);
  6279. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6280. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6281. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6282. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6283. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6284. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6285. ESTAT_ADD(tx_octets);
  6286. ESTAT_ADD(tx_collisions);
  6287. ESTAT_ADD(tx_xon_sent);
  6288. ESTAT_ADD(tx_xoff_sent);
  6289. ESTAT_ADD(tx_flow_control);
  6290. ESTAT_ADD(tx_mac_errors);
  6291. ESTAT_ADD(tx_single_collisions);
  6292. ESTAT_ADD(tx_mult_collisions);
  6293. ESTAT_ADD(tx_deferred);
  6294. ESTAT_ADD(tx_excessive_collisions);
  6295. ESTAT_ADD(tx_late_collisions);
  6296. ESTAT_ADD(tx_collide_2times);
  6297. ESTAT_ADD(tx_collide_3times);
  6298. ESTAT_ADD(tx_collide_4times);
  6299. ESTAT_ADD(tx_collide_5times);
  6300. ESTAT_ADD(tx_collide_6times);
  6301. ESTAT_ADD(tx_collide_7times);
  6302. ESTAT_ADD(tx_collide_8times);
  6303. ESTAT_ADD(tx_collide_9times);
  6304. ESTAT_ADD(tx_collide_10times);
  6305. ESTAT_ADD(tx_collide_11times);
  6306. ESTAT_ADD(tx_collide_12times);
  6307. ESTAT_ADD(tx_collide_13times);
  6308. ESTAT_ADD(tx_collide_14times);
  6309. ESTAT_ADD(tx_collide_15times);
  6310. ESTAT_ADD(tx_ucast_packets);
  6311. ESTAT_ADD(tx_mcast_packets);
  6312. ESTAT_ADD(tx_bcast_packets);
  6313. ESTAT_ADD(tx_carrier_sense_errors);
  6314. ESTAT_ADD(tx_discards);
  6315. ESTAT_ADD(tx_errors);
  6316. ESTAT_ADD(dma_writeq_full);
  6317. ESTAT_ADD(dma_write_prioq_full);
  6318. ESTAT_ADD(rxbds_empty);
  6319. ESTAT_ADD(rx_discards);
  6320. ESTAT_ADD(rx_errors);
  6321. ESTAT_ADD(rx_threshold_hit);
  6322. ESTAT_ADD(dma_readq_full);
  6323. ESTAT_ADD(dma_read_prioq_full);
  6324. ESTAT_ADD(tx_comp_queue_full);
  6325. ESTAT_ADD(ring_set_send_prod_index);
  6326. ESTAT_ADD(ring_status_update);
  6327. ESTAT_ADD(nic_irqs);
  6328. ESTAT_ADD(nic_avoided_irqs);
  6329. ESTAT_ADD(nic_tx_threshold_hit);
  6330. return estats;
  6331. }
  6332. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6333. {
  6334. struct tg3 *tp = netdev_priv(dev);
  6335. struct net_device_stats *stats = &tp->net_stats;
  6336. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6337. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6338. if (!hw_stats)
  6339. return old_stats;
  6340. stats->rx_packets = old_stats->rx_packets +
  6341. get_stat64(&hw_stats->rx_ucast_packets) +
  6342. get_stat64(&hw_stats->rx_mcast_packets) +
  6343. get_stat64(&hw_stats->rx_bcast_packets);
  6344. stats->tx_packets = old_stats->tx_packets +
  6345. get_stat64(&hw_stats->tx_ucast_packets) +
  6346. get_stat64(&hw_stats->tx_mcast_packets) +
  6347. get_stat64(&hw_stats->tx_bcast_packets);
  6348. stats->rx_bytes = old_stats->rx_bytes +
  6349. get_stat64(&hw_stats->rx_octets);
  6350. stats->tx_bytes = old_stats->tx_bytes +
  6351. get_stat64(&hw_stats->tx_octets);
  6352. stats->rx_errors = old_stats->rx_errors +
  6353. get_stat64(&hw_stats->rx_errors);
  6354. stats->tx_errors = old_stats->tx_errors +
  6355. get_stat64(&hw_stats->tx_errors) +
  6356. get_stat64(&hw_stats->tx_mac_errors) +
  6357. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6358. get_stat64(&hw_stats->tx_discards);
  6359. stats->multicast = old_stats->multicast +
  6360. get_stat64(&hw_stats->rx_mcast_packets);
  6361. stats->collisions = old_stats->collisions +
  6362. get_stat64(&hw_stats->tx_collisions);
  6363. stats->rx_length_errors = old_stats->rx_length_errors +
  6364. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6365. get_stat64(&hw_stats->rx_undersize_packets);
  6366. stats->rx_over_errors = old_stats->rx_over_errors +
  6367. get_stat64(&hw_stats->rxbds_empty);
  6368. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6369. get_stat64(&hw_stats->rx_align_errors);
  6370. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6371. get_stat64(&hw_stats->tx_discards);
  6372. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6373. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6374. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6375. calc_crc_errors(tp);
  6376. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6377. get_stat64(&hw_stats->rx_discards);
  6378. return stats;
  6379. }
  6380. static inline u32 calc_crc(unsigned char *buf, int len)
  6381. {
  6382. u32 reg;
  6383. u32 tmp;
  6384. int j, k;
  6385. reg = 0xffffffff;
  6386. for (j = 0; j < len; j++) {
  6387. reg ^= buf[j];
  6388. for (k = 0; k < 8; k++) {
  6389. tmp = reg & 0x01;
  6390. reg >>= 1;
  6391. if (tmp) {
  6392. reg ^= 0xedb88320;
  6393. }
  6394. }
  6395. }
  6396. return ~reg;
  6397. }
  6398. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6399. {
  6400. /* accept or reject all multicast frames */
  6401. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6402. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6403. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6404. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6405. }
  6406. static void __tg3_set_rx_mode(struct net_device *dev)
  6407. {
  6408. struct tg3 *tp = netdev_priv(dev);
  6409. u32 rx_mode;
  6410. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6411. RX_MODE_KEEP_VLAN_TAG);
  6412. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6413. * flag clear.
  6414. */
  6415. #if TG3_VLAN_TAG_USED
  6416. if (!tp->vlgrp &&
  6417. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6418. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6419. #else
  6420. /* By definition, VLAN is disabled always in this
  6421. * case.
  6422. */
  6423. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6424. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6425. #endif
  6426. if (dev->flags & IFF_PROMISC) {
  6427. /* Promiscuous mode. */
  6428. rx_mode |= RX_MODE_PROMISC;
  6429. } else if (dev->flags & IFF_ALLMULTI) {
  6430. /* Accept all multicast. */
  6431. tg3_set_multi (tp, 1);
  6432. } else if (dev->mc_count < 1) {
  6433. /* Reject all multicast. */
  6434. tg3_set_multi (tp, 0);
  6435. } else {
  6436. /* Accept one or more multicast(s). */
  6437. struct dev_mc_list *mclist;
  6438. unsigned int i;
  6439. u32 mc_filter[4] = { 0, };
  6440. u32 regidx;
  6441. u32 bit;
  6442. u32 crc;
  6443. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6444. i++, mclist = mclist->next) {
  6445. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6446. bit = ~crc & 0x7f;
  6447. regidx = (bit & 0x60) >> 5;
  6448. bit &= 0x1f;
  6449. mc_filter[regidx] |= (1 << bit);
  6450. }
  6451. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6452. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6453. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6454. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6455. }
  6456. if (rx_mode != tp->rx_mode) {
  6457. tp->rx_mode = rx_mode;
  6458. tw32_f(MAC_RX_MODE, rx_mode);
  6459. udelay(10);
  6460. }
  6461. }
  6462. static void tg3_set_rx_mode(struct net_device *dev)
  6463. {
  6464. struct tg3 *tp = netdev_priv(dev);
  6465. if (!netif_running(dev))
  6466. return;
  6467. tg3_full_lock(tp, 0);
  6468. __tg3_set_rx_mode(dev);
  6469. tg3_full_unlock(tp);
  6470. }
  6471. #define TG3_REGDUMP_LEN (32 * 1024)
  6472. static int tg3_get_regs_len(struct net_device *dev)
  6473. {
  6474. return TG3_REGDUMP_LEN;
  6475. }
  6476. static void tg3_get_regs(struct net_device *dev,
  6477. struct ethtool_regs *regs, void *_p)
  6478. {
  6479. u32 *p = _p;
  6480. struct tg3 *tp = netdev_priv(dev);
  6481. u8 *orig_p = _p;
  6482. int i;
  6483. regs->version = 0;
  6484. memset(p, 0, TG3_REGDUMP_LEN);
  6485. if (tp->link_config.phy_is_low_power)
  6486. return;
  6487. tg3_full_lock(tp, 0);
  6488. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6489. #define GET_REG32_LOOP(base,len) \
  6490. do { p = (u32 *)(orig_p + (base)); \
  6491. for (i = 0; i < len; i += 4) \
  6492. __GET_REG32((base) + i); \
  6493. } while (0)
  6494. #define GET_REG32_1(reg) \
  6495. do { p = (u32 *)(orig_p + (reg)); \
  6496. __GET_REG32((reg)); \
  6497. } while (0)
  6498. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6499. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6500. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6501. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6502. GET_REG32_1(SNDDATAC_MODE);
  6503. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6504. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6505. GET_REG32_1(SNDBDC_MODE);
  6506. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6507. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6508. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6509. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6510. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6511. GET_REG32_1(RCVDCC_MODE);
  6512. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6513. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6514. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6515. GET_REG32_1(MBFREE_MODE);
  6516. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6517. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6518. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6519. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6520. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6521. GET_REG32_1(RX_CPU_MODE);
  6522. GET_REG32_1(RX_CPU_STATE);
  6523. GET_REG32_1(RX_CPU_PGMCTR);
  6524. GET_REG32_1(RX_CPU_HWBKPT);
  6525. GET_REG32_1(TX_CPU_MODE);
  6526. GET_REG32_1(TX_CPU_STATE);
  6527. GET_REG32_1(TX_CPU_PGMCTR);
  6528. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6529. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6530. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6531. GET_REG32_1(DMAC_MODE);
  6532. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6533. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6534. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6535. #undef __GET_REG32
  6536. #undef GET_REG32_LOOP
  6537. #undef GET_REG32_1
  6538. tg3_full_unlock(tp);
  6539. }
  6540. static int tg3_get_eeprom_len(struct net_device *dev)
  6541. {
  6542. struct tg3 *tp = netdev_priv(dev);
  6543. return tp->nvram_size;
  6544. }
  6545. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6546. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6547. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6548. {
  6549. struct tg3 *tp = netdev_priv(dev);
  6550. int ret;
  6551. u8 *pd;
  6552. u32 i, offset, len, val, b_offset, b_count;
  6553. if (tp->link_config.phy_is_low_power)
  6554. return -EAGAIN;
  6555. offset = eeprom->offset;
  6556. len = eeprom->len;
  6557. eeprom->len = 0;
  6558. eeprom->magic = TG3_EEPROM_MAGIC;
  6559. if (offset & 3) {
  6560. /* adjustments to start on required 4 byte boundary */
  6561. b_offset = offset & 3;
  6562. b_count = 4 - b_offset;
  6563. if (b_count > len) {
  6564. /* i.e. offset=1 len=2 */
  6565. b_count = len;
  6566. }
  6567. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6568. if (ret)
  6569. return ret;
  6570. val = cpu_to_le32(val);
  6571. memcpy(data, ((char*)&val) + b_offset, b_count);
  6572. len -= b_count;
  6573. offset += b_count;
  6574. eeprom->len += b_count;
  6575. }
  6576. /* read bytes upto the last 4 byte boundary */
  6577. pd = &data[eeprom->len];
  6578. for (i = 0; i < (len - (len & 3)); i += 4) {
  6579. ret = tg3_nvram_read(tp, offset + i, &val);
  6580. if (ret) {
  6581. eeprom->len += i;
  6582. return ret;
  6583. }
  6584. val = cpu_to_le32(val);
  6585. memcpy(pd + i, &val, 4);
  6586. }
  6587. eeprom->len += i;
  6588. if (len & 3) {
  6589. /* read last bytes not ending on 4 byte boundary */
  6590. pd = &data[eeprom->len];
  6591. b_count = len & 3;
  6592. b_offset = offset + len - b_count;
  6593. ret = tg3_nvram_read(tp, b_offset, &val);
  6594. if (ret)
  6595. return ret;
  6596. val = cpu_to_le32(val);
  6597. memcpy(pd, ((char*)&val), b_count);
  6598. eeprom->len += b_count;
  6599. }
  6600. return 0;
  6601. }
  6602. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6603. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6604. {
  6605. struct tg3 *tp = netdev_priv(dev);
  6606. int ret;
  6607. u32 offset, len, b_offset, odd_len, start, end;
  6608. u8 *buf;
  6609. if (tp->link_config.phy_is_low_power)
  6610. return -EAGAIN;
  6611. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6612. return -EINVAL;
  6613. offset = eeprom->offset;
  6614. len = eeprom->len;
  6615. if ((b_offset = (offset & 3))) {
  6616. /* adjustments to start on required 4 byte boundary */
  6617. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6618. if (ret)
  6619. return ret;
  6620. start = cpu_to_le32(start);
  6621. len += b_offset;
  6622. offset &= ~3;
  6623. if (len < 4)
  6624. len = 4;
  6625. }
  6626. odd_len = 0;
  6627. if (len & 3) {
  6628. /* adjustments to end on required 4 byte boundary */
  6629. odd_len = 1;
  6630. len = (len + 3) & ~3;
  6631. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6632. if (ret)
  6633. return ret;
  6634. end = cpu_to_le32(end);
  6635. }
  6636. buf = data;
  6637. if (b_offset || odd_len) {
  6638. buf = kmalloc(len, GFP_KERNEL);
  6639. if (buf == 0)
  6640. return -ENOMEM;
  6641. if (b_offset)
  6642. memcpy(buf, &start, 4);
  6643. if (odd_len)
  6644. memcpy(buf+len-4, &end, 4);
  6645. memcpy(buf + b_offset, data, eeprom->len);
  6646. }
  6647. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6648. if (buf != data)
  6649. kfree(buf);
  6650. return ret;
  6651. }
  6652. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6653. {
  6654. struct tg3 *tp = netdev_priv(dev);
  6655. cmd->supported = (SUPPORTED_Autoneg);
  6656. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6657. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6658. SUPPORTED_1000baseT_Full);
  6659. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6660. cmd->supported |= (SUPPORTED_100baseT_Half |
  6661. SUPPORTED_100baseT_Full |
  6662. SUPPORTED_10baseT_Half |
  6663. SUPPORTED_10baseT_Full |
  6664. SUPPORTED_MII);
  6665. cmd->port = PORT_TP;
  6666. } else {
  6667. cmd->supported |= SUPPORTED_FIBRE;
  6668. cmd->port = PORT_FIBRE;
  6669. }
  6670. cmd->advertising = tp->link_config.advertising;
  6671. if (netif_running(dev)) {
  6672. cmd->speed = tp->link_config.active_speed;
  6673. cmd->duplex = tp->link_config.active_duplex;
  6674. }
  6675. cmd->phy_address = PHY_ADDR;
  6676. cmd->transceiver = 0;
  6677. cmd->autoneg = tp->link_config.autoneg;
  6678. cmd->maxtxpkt = 0;
  6679. cmd->maxrxpkt = 0;
  6680. return 0;
  6681. }
  6682. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6683. {
  6684. struct tg3 *tp = netdev_priv(dev);
  6685. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6686. /* These are the only valid advertisement bits allowed. */
  6687. if (cmd->autoneg == AUTONEG_ENABLE &&
  6688. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6689. ADVERTISED_1000baseT_Full |
  6690. ADVERTISED_Autoneg |
  6691. ADVERTISED_FIBRE)))
  6692. return -EINVAL;
  6693. /* Fiber can only do SPEED_1000. */
  6694. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6695. (cmd->speed != SPEED_1000))
  6696. return -EINVAL;
  6697. /* Copper cannot force SPEED_1000. */
  6698. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6699. (cmd->speed == SPEED_1000))
  6700. return -EINVAL;
  6701. else if ((cmd->speed == SPEED_1000) &&
  6702. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6703. return -EINVAL;
  6704. tg3_full_lock(tp, 0);
  6705. tp->link_config.autoneg = cmd->autoneg;
  6706. if (cmd->autoneg == AUTONEG_ENABLE) {
  6707. tp->link_config.advertising = cmd->advertising;
  6708. tp->link_config.speed = SPEED_INVALID;
  6709. tp->link_config.duplex = DUPLEX_INVALID;
  6710. } else {
  6711. tp->link_config.advertising = 0;
  6712. tp->link_config.speed = cmd->speed;
  6713. tp->link_config.duplex = cmd->duplex;
  6714. }
  6715. if (netif_running(dev))
  6716. tg3_setup_phy(tp, 1);
  6717. tg3_full_unlock(tp);
  6718. return 0;
  6719. }
  6720. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6721. {
  6722. struct tg3 *tp = netdev_priv(dev);
  6723. strcpy(info->driver, DRV_MODULE_NAME);
  6724. strcpy(info->version, DRV_MODULE_VERSION);
  6725. strcpy(info->fw_version, tp->fw_ver);
  6726. strcpy(info->bus_info, pci_name(tp->pdev));
  6727. }
  6728. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6729. {
  6730. struct tg3 *tp = netdev_priv(dev);
  6731. wol->supported = WAKE_MAGIC;
  6732. wol->wolopts = 0;
  6733. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6734. wol->wolopts = WAKE_MAGIC;
  6735. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6736. }
  6737. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6738. {
  6739. struct tg3 *tp = netdev_priv(dev);
  6740. if (wol->wolopts & ~WAKE_MAGIC)
  6741. return -EINVAL;
  6742. if ((wol->wolopts & WAKE_MAGIC) &&
  6743. tp->tg3_flags2 & TG3_FLG2_PHY_SERDES &&
  6744. !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
  6745. return -EINVAL;
  6746. spin_lock_bh(&tp->lock);
  6747. if (wol->wolopts & WAKE_MAGIC)
  6748. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6749. else
  6750. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6751. spin_unlock_bh(&tp->lock);
  6752. return 0;
  6753. }
  6754. static u32 tg3_get_msglevel(struct net_device *dev)
  6755. {
  6756. struct tg3 *tp = netdev_priv(dev);
  6757. return tp->msg_enable;
  6758. }
  6759. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6760. {
  6761. struct tg3 *tp = netdev_priv(dev);
  6762. tp->msg_enable = value;
  6763. }
  6764. #if TG3_TSO_SUPPORT != 0
  6765. static int tg3_set_tso(struct net_device *dev, u32 value)
  6766. {
  6767. struct tg3 *tp = netdev_priv(dev);
  6768. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6769. if (value)
  6770. return -EINVAL;
  6771. return 0;
  6772. }
  6773. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) {
  6774. if (value)
  6775. dev->features |= NETIF_F_TSO6;
  6776. else
  6777. dev->features &= ~NETIF_F_TSO6;
  6778. }
  6779. return ethtool_op_set_tso(dev, value);
  6780. }
  6781. #endif
  6782. static int tg3_nway_reset(struct net_device *dev)
  6783. {
  6784. struct tg3 *tp = netdev_priv(dev);
  6785. u32 bmcr;
  6786. int r;
  6787. if (!netif_running(dev))
  6788. return -EAGAIN;
  6789. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6790. return -EINVAL;
  6791. spin_lock_bh(&tp->lock);
  6792. r = -EINVAL;
  6793. tg3_readphy(tp, MII_BMCR, &bmcr);
  6794. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6795. ((bmcr & BMCR_ANENABLE) ||
  6796. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6797. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6798. BMCR_ANENABLE);
  6799. r = 0;
  6800. }
  6801. spin_unlock_bh(&tp->lock);
  6802. return r;
  6803. }
  6804. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6805. {
  6806. struct tg3 *tp = netdev_priv(dev);
  6807. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6808. ering->rx_mini_max_pending = 0;
  6809. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6810. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6811. else
  6812. ering->rx_jumbo_max_pending = 0;
  6813. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6814. ering->rx_pending = tp->rx_pending;
  6815. ering->rx_mini_pending = 0;
  6816. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6817. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6818. else
  6819. ering->rx_jumbo_pending = 0;
  6820. ering->tx_pending = tp->tx_pending;
  6821. }
  6822. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6823. {
  6824. struct tg3 *tp = netdev_priv(dev);
  6825. int irq_sync = 0, err = 0;
  6826. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6827. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6828. (ering->tx_pending > TG3_TX_RING_SIZE - 1))
  6829. return -EINVAL;
  6830. if (netif_running(dev)) {
  6831. tg3_netif_stop(tp);
  6832. irq_sync = 1;
  6833. }
  6834. tg3_full_lock(tp, irq_sync);
  6835. tp->rx_pending = ering->rx_pending;
  6836. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6837. tp->rx_pending > 63)
  6838. tp->rx_pending = 63;
  6839. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6840. tp->tx_pending = ering->tx_pending;
  6841. if (netif_running(dev)) {
  6842. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6843. err = tg3_restart_hw(tp, 1);
  6844. if (!err)
  6845. tg3_netif_start(tp);
  6846. }
  6847. tg3_full_unlock(tp);
  6848. return err;
  6849. }
  6850. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6851. {
  6852. struct tg3 *tp = netdev_priv(dev);
  6853. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  6854. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  6855. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  6856. }
  6857. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6858. {
  6859. struct tg3 *tp = netdev_priv(dev);
  6860. int irq_sync = 0, err = 0;
  6861. if (netif_running(dev)) {
  6862. tg3_netif_stop(tp);
  6863. irq_sync = 1;
  6864. }
  6865. tg3_full_lock(tp, irq_sync);
  6866. if (epause->autoneg)
  6867. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  6868. else
  6869. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  6870. if (epause->rx_pause)
  6871. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  6872. else
  6873. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  6874. if (epause->tx_pause)
  6875. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  6876. else
  6877. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  6878. if (netif_running(dev)) {
  6879. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6880. err = tg3_restart_hw(tp, 1);
  6881. if (!err)
  6882. tg3_netif_start(tp);
  6883. }
  6884. tg3_full_unlock(tp);
  6885. return err;
  6886. }
  6887. static u32 tg3_get_rx_csum(struct net_device *dev)
  6888. {
  6889. struct tg3 *tp = netdev_priv(dev);
  6890. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  6891. }
  6892. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  6893. {
  6894. struct tg3 *tp = netdev_priv(dev);
  6895. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  6896. if (data != 0)
  6897. return -EINVAL;
  6898. return 0;
  6899. }
  6900. spin_lock_bh(&tp->lock);
  6901. if (data)
  6902. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  6903. else
  6904. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  6905. spin_unlock_bh(&tp->lock);
  6906. return 0;
  6907. }
  6908. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  6909. {
  6910. struct tg3 *tp = netdev_priv(dev);
  6911. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  6912. if (data != 0)
  6913. return -EINVAL;
  6914. return 0;
  6915. }
  6916. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  6917. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  6918. ethtool_op_set_tx_hw_csum(dev, data);
  6919. else
  6920. ethtool_op_set_tx_csum(dev, data);
  6921. return 0;
  6922. }
  6923. static int tg3_get_stats_count (struct net_device *dev)
  6924. {
  6925. return TG3_NUM_STATS;
  6926. }
  6927. static int tg3_get_test_count (struct net_device *dev)
  6928. {
  6929. return TG3_NUM_TEST;
  6930. }
  6931. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  6932. {
  6933. switch (stringset) {
  6934. case ETH_SS_STATS:
  6935. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  6936. break;
  6937. case ETH_SS_TEST:
  6938. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  6939. break;
  6940. default:
  6941. WARN_ON(1); /* we need a WARN() */
  6942. break;
  6943. }
  6944. }
  6945. static int tg3_phys_id(struct net_device *dev, u32 data)
  6946. {
  6947. struct tg3 *tp = netdev_priv(dev);
  6948. int i;
  6949. if (!netif_running(tp->dev))
  6950. return -EAGAIN;
  6951. if (data == 0)
  6952. data = 2;
  6953. for (i = 0; i < (data * 2); i++) {
  6954. if ((i % 2) == 0)
  6955. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  6956. LED_CTRL_1000MBPS_ON |
  6957. LED_CTRL_100MBPS_ON |
  6958. LED_CTRL_10MBPS_ON |
  6959. LED_CTRL_TRAFFIC_OVERRIDE |
  6960. LED_CTRL_TRAFFIC_BLINK |
  6961. LED_CTRL_TRAFFIC_LED);
  6962. else
  6963. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  6964. LED_CTRL_TRAFFIC_OVERRIDE);
  6965. if (msleep_interruptible(500))
  6966. break;
  6967. }
  6968. tw32(MAC_LED_CTRL, tp->led_ctrl);
  6969. return 0;
  6970. }
  6971. static void tg3_get_ethtool_stats (struct net_device *dev,
  6972. struct ethtool_stats *estats, u64 *tmp_stats)
  6973. {
  6974. struct tg3 *tp = netdev_priv(dev);
  6975. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  6976. }
  6977. #define NVRAM_TEST_SIZE 0x100
  6978. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  6979. static int tg3_test_nvram(struct tg3 *tp)
  6980. {
  6981. u32 *buf, csum, magic;
  6982. int i, j, err = 0, size;
  6983. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  6984. return -EIO;
  6985. if (magic == TG3_EEPROM_MAGIC)
  6986. size = NVRAM_TEST_SIZE;
  6987. else if ((magic & 0xff000000) == 0xa5000000) {
  6988. if ((magic & 0xe00000) == 0x200000)
  6989. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  6990. else
  6991. return 0;
  6992. } else
  6993. return -EIO;
  6994. buf = kmalloc(size, GFP_KERNEL);
  6995. if (buf == NULL)
  6996. return -ENOMEM;
  6997. err = -EIO;
  6998. for (i = 0, j = 0; i < size; i += 4, j++) {
  6999. u32 val;
  7000. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7001. break;
  7002. buf[j] = cpu_to_le32(val);
  7003. }
  7004. if (i < size)
  7005. goto out;
  7006. /* Selfboot format */
  7007. if (cpu_to_be32(buf[0]) != TG3_EEPROM_MAGIC) {
  7008. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7009. for (i = 0; i < size; i++)
  7010. csum8 += buf8[i];
  7011. if (csum8 == 0) {
  7012. err = 0;
  7013. goto out;
  7014. }
  7015. err = -EIO;
  7016. goto out;
  7017. }
  7018. /* Bootstrap checksum at offset 0x10 */
  7019. csum = calc_crc((unsigned char *) buf, 0x10);
  7020. if(csum != cpu_to_le32(buf[0x10/4]))
  7021. goto out;
  7022. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7023. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7024. if (csum != cpu_to_le32(buf[0xfc/4]))
  7025. goto out;
  7026. err = 0;
  7027. out:
  7028. kfree(buf);
  7029. return err;
  7030. }
  7031. #define TG3_SERDES_TIMEOUT_SEC 2
  7032. #define TG3_COPPER_TIMEOUT_SEC 6
  7033. static int tg3_test_link(struct tg3 *tp)
  7034. {
  7035. int i, max;
  7036. if (!netif_running(tp->dev))
  7037. return -ENODEV;
  7038. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7039. max = TG3_SERDES_TIMEOUT_SEC;
  7040. else
  7041. max = TG3_COPPER_TIMEOUT_SEC;
  7042. for (i = 0; i < max; i++) {
  7043. if (netif_carrier_ok(tp->dev))
  7044. return 0;
  7045. if (msleep_interruptible(1000))
  7046. break;
  7047. }
  7048. return -EIO;
  7049. }
  7050. /* Only test the commonly used registers */
  7051. static int tg3_test_registers(struct tg3 *tp)
  7052. {
  7053. int i, is_5705;
  7054. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7055. static struct {
  7056. u16 offset;
  7057. u16 flags;
  7058. #define TG3_FL_5705 0x1
  7059. #define TG3_FL_NOT_5705 0x2
  7060. #define TG3_FL_NOT_5788 0x4
  7061. u32 read_mask;
  7062. u32 write_mask;
  7063. } reg_tbl[] = {
  7064. /* MAC Control Registers */
  7065. { MAC_MODE, TG3_FL_NOT_5705,
  7066. 0x00000000, 0x00ef6f8c },
  7067. { MAC_MODE, TG3_FL_5705,
  7068. 0x00000000, 0x01ef6b8c },
  7069. { MAC_STATUS, TG3_FL_NOT_5705,
  7070. 0x03800107, 0x00000000 },
  7071. { MAC_STATUS, TG3_FL_5705,
  7072. 0x03800100, 0x00000000 },
  7073. { MAC_ADDR_0_HIGH, 0x0000,
  7074. 0x00000000, 0x0000ffff },
  7075. { MAC_ADDR_0_LOW, 0x0000,
  7076. 0x00000000, 0xffffffff },
  7077. { MAC_RX_MTU_SIZE, 0x0000,
  7078. 0x00000000, 0x0000ffff },
  7079. { MAC_TX_MODE, 0x0000,
  7080. 0x00000000, 0x00000070 },
  7081. { MAC_TX_LENGTHS, 0x0000,
  7082. 0x00000000, 0x00003fff },
  7083. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7084. 0x00000000, 0x000007fc },
  7085. { MAC_RX_MODE, TG3_FL_5705,
  7086. 0x00000000, 0x000007dc },
  7087. { MAC_HASH_REG_0, 0x0000,
  7088. 0x00000000, 0xffffffff },
  7089. { MAC_HASH_REG_1, 0x0000,
  7090. 0x00000000, 0xffffffff },
  7091. { MAC_HASH_REG_2, 0x0000,
  7092. 0x00000000, 0xffffffff },
  7093. { MAC_HASH_REG_3, 0x0000,
  7094. 0x00000000, 0xffffffff },
  7095. /* Receive Data and Receive BD Initiator Control Registers. */
  7096. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7097. 0x00000000, 0xffffffff },
  7098. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7099. 0x00000000, 0xffffffff },
  7100. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7101. 0x00000000, 0x00000003 },
  7102. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7103. 0x00000000, 0xffffffff },
  7104. { RCVDBDI_STD_BD+0, 0x0000,
  7105. 0x00000000, 0xffffffff },
  7106. { RCVDBDI_STD_BD+4, 0x0000,
  7107. 0x00000000, 0xffffffff },
  7108. { RCVDBDI_STD_BD+8, 0x0000,
  7109. 0x00000000, 0xffff0002 },
  7110. { RCVDBDI_STD_BD+0xc, 0x0000,
  7111. 0x00000000, 0xffffffff },
  7112. /* Receive BD Initiator Control Registers. */
  7113. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7114. 0x00000000, 0xffffffff },
  7115. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7116. 0x00000000, 0x000003ff },
  7117. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7118. 0x00000000, 0xffffffff },
  7119. /* Host Coalescing Control Registers. */
  7120. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7121. 0x00000000, 0x00000004 },
  7122. { HOSTCC_MODE, TG3_FL_5705,
  7123. 0x00000000, 0x000000f6 },
  7124. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7125. 0x00000000, 0xffffffff },
  7126. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7127. 0x00000000, 0x000003ff },
  7128. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7129. 0x00000000, 0xffffffff },
  7130. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7131. 0x00000000, 0x000003ff },
  7132. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7133. 0x00000000, 0xffffffff },
  7134. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7135. 0x00000000, 0x000000ff },
  7136. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7137. 0x00000000, 0xffffffff },
  7138. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7139. 0x00000000, 0x000000ff },
  7140. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7141. 0x00000000, 0xffffffff },
  7142. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7143. 0x00000000, 0xffffffff },
  7144. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7145. 0x00000000, 0xffffffff },
  7146. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7147. 0x00000000, 0x000000ff },
  7148. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7149. 0x00000000, 0xffffffff },
  7150. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7151. 0x00000000, 0x000000ff },
  7152. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7153. 0x00000000, 0xffffffff },
  7154. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7155. 0x00000000, 0xffffffff },
  7156. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7157. 0x00000000, 0xffffffff },
  7158. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7159. 0x00000000, 0xffffffff },
  7160. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7161. 0x00000000, 0xffffffff },
  7162. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7163. 0xffffffff, 0x00000000 },
  7164. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7165. 0xffffffff, 0x00000000 },
  7166. /* Buffer Manager Control Registers. */
  7167. { BUFMGR_MB_POOL_ADDR, 0x0000,
  7168. 0x00000000, 0x007fff80 },
  7169. { BUFMGR_MB_POOL_SIZE, 0x0000,
  7170. 0x00000000, 0x007fffff },
  7171. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7172. 0x00000000, 0x0000003f },
  7173. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7174. 0x00000000, 0x000001ff },
  7175. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7176. 0x00000000, 0x000001ff },
  7177. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7178. 0xffffffff, 0x00000000 },
  7179. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7180. 0xffffffff, 0x00000000 },
  7181. /* Mailbox Registers */
  7182. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7183. 0x00000000, 0x000001ff },
  7184. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7185. 0x00000000, 0x000001ff },
  7186. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7187. 0x00000000, 0x000007ff },
  7188. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7189. 0x00000000, 0x000001ff },
  7190. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7191. };
  7192. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  7193. is_5705 = 1;
  7194. else
  7195. is_5705 = 0;
  7196. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7197. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7198. continue;
  7199. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7200. continue;
  7201. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7202. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7203. continue;
  7204. offset = (u32) reg_tbl[i].offset;
  7205. read_mask = reg_tbl[i].read_mask;
  7206. write_mask = reg_tbl[i].write_mask;
  7207. /* Save the original register content */
  7208. save_val = tr32(offset);
  7209. /* Determine the read-only value. */
  7210. read_val = save_val & read_mask;
  7211. /* Write zero to the register, then make sure the read-only bits
  7212. * are not changed and the read/write bits are all zeros.
  7213. */
  7214. tw32(offset, 0);
  7215. val = tr32(offset);
  7216. /* Test the read-only and read/write bits. */
  7217. if (((val & read_mask) != read_val) || (val & write_mask))
  7218. goto out;
  7219. /* Write ones to all the bits defined by RdMask and WrMask, then
  7220. * make sure the read-only bits are not changed and the
  7221. * read/write bits are all ones.
  7222. */
  7223. tw32(offset, read_mask | write_mask);
  7224. val = tr32(offset);
  7225. /* Test the read-only bits. */
  7226. if ((val & read_mask) != read_val)
  7227. goto out;
  7228. /* Test the read/write bits. */
  7229. if ((val & write_mask) != write_mask)
  7230. goto out;
  7231. tw32(offset, save_val);
  7232. }
  7233. return 0;
  7234. out:
  7235. printk(KERN_ERR PFX "Register test failed at offset %x\n", offset);
  7236. tw32(offset, save_val);
  7237. return -EIO;
  7238. }
  7239. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7240. {
  7241. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7242. int i;
  7243. u32 j;
  7244. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7245. for (j = 0; j < len; j += 4) {
  7246. u32 val;
  7247. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7248. tg3_read_mem(tp, offset + j, &val);
  7249. if (val != test_pattern[i])
  7250. return -EIO;
  7251. }
  7252. }
  7253. return 0;
  7254. }
  7255. static int tg3_test_memory(struct tg3 *tp)
  7256. {
  7257. static struct mem_entry {
  7258. u32 offset;
  7259. u32 len;
  7260. } mem_tbl_570x[] = {
  7261. { 0x00000000, 0x00b50},
  7262. { 0x00002000, 0x1c000},
  7263. { 0xffffffff, 0x00000}
  7264. }, mem_tbl_5705[] = {
  7265. { 0x00000100, 0x0000c},
  7266. { 0x00000200, 0x00008},
  7267. { 0x00004000, 0x00800},
  7268. { 0x00006000, 0x01000},
  7269. { 0x00008000, 0x02000},
  7270. { 0x00010000, 0x0e000},
  7271. { 0xffffffff, 0x00000}
  7272. }, mem_tbl_5755[] = {
  7273. { 0x00000200, 0x00008},
  7274. { 0x00004000, 0x00800},
  7275. { 0x00006000, 0x00800},
  7276. { 0x00008000, 0x02000},
  7277. { 0x00010000, 0x0c000},
  7278. { 0xffffffff, 0x00000}
  7279. };
  7280. struct mem_entry *mem_tbl;
  7281. int err = 0;
  7282. int i;
  7283. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7284. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7285. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7286. mem_tbl = mem_tbl_5755;
  7287. else
  7288. mem_tbl = mem_tbl_5705;
  7289. } else
  7290. mem_tbl = mem_tbl_570x;
  7291. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7292. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7293. mem_tbl[i].len)) != 0)
  7294. break;
  7295. }
  7296. return err;
  7297. }
  7298. #define TG3_MAC_LOOPBACK 0
  7299. #define TG3_PHY_LOOPBACK 1
  7300. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7301. {
  7302. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7303. u32 desc_idx;
  7304. struct sk_buff *skb, *rx_skb;
  7305. u8 *tx_data;
  7306. dma_addr_t map;
  7307. int num_pkts, tx_len, rx_len, i, err;
  7308. struct tg3_rx_buffer_desc *desc;
  7309. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7310. /* HW errata - mac loopback fails in some cases on 5780.
  7311. * Normal traffic and PHY loopback are not affected by
  7312. * errata.
  7313. */
  7314. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7315. return 0;
  7316. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7317. MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY |
  7318. MAC_MODE_PORT_MODE_GMII;
  7319. tw32(MAC_MODE, mac_mode);
  7320. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7321. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX |
  7322. BMCR_SPEED1000);
  7323. udelay(40);
  7324. /* reset to prevent losing 1st rx packet intermittently */
  7325. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7326. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7327. udelay(10);
  7328. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7329. }
  7330. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7331. MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII;
  7332. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  7333. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7334. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7335. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7336. }
  7337. tw32(MAC_MODE, mac_mode);
  7338. }
  7339. else
  7340. return -EINVAL;
  7341. err = -EIO;
  7342. tx_len = 1514;
  7343. skb = dev_alloc_skb(tx_len);
  7344. if (!skb)
  7345. return -ENOMEM;
  7346. tx_data = skb_put(skb, tx_len);
  7347. memcpy(tx_data, tp->dev->dev_addr, 6);
  7348. memset(tx_data + 6, 0x0, 8);
  7349. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7350. for (i = 14; i < tx_len; i++)
  7351. tx_data[i] = (u8) (i & 0xff);
  7352. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7353. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7354. HOSTCC_MODE_NOW);
  7355. udelay(10);
  7356. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7357. num_pkts = 0;
  7358. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7359. tp->tx_prod++;
  7360. num_pkts++;
  7361. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7362. tp->tx_prod);
  7363. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7364. udelay(10);
  7365. for (i = 0; i < 10; i++) {
  7366. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7367. HOSTCC_MODE_NOW);
  7368. udelay(10);
  7369. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7370. rx_idx = tp->hw_status->idx[0].rx_producer;
  7371. if ((tx_idx == tp->tx_prod) &&
  7372. (rx_idx == (rx_start_idx + num_pkts)))
  7373. break;
  7374. }
  7375. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7376. dev_kfree_skb(skb);
  7377. if (tx_idx != tp->tx_prod)
  7378. goto out;
  7379. if (rx_idx != rx_start_idx + num_pkts)
  7380. goto out;
  7381. desc = &tp->rx_rcb[rx_start_idx];
  7382. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7383. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7384. if (opaque_key != RXD_OPAQUE_RING_STD)
  7385. goto out;
  7386. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7387. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7388. goto out;
  7389. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7390. if (rx_len != tx_len)
  7391. goto out;
  7392. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7393. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7394. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7395. for (i = 14; i < tx_len; i++) {
  7396. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7397. goto out;
  7398. }
  7399. err = 0;
  7400. /* tg3_free_rings will unmap and free the rx_skb */
  7401. out:
  7402. return err;
  7403. }
  7404. #define TG3_MAC_LOOPBACK_FAILED 1
  7405. #define TG3_PHY_LOOPBACK_FAILED 2
  7406. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7407. TG3_PHY_LOOPBACK_FAILED)
  7408. static int tg3_test_loopback(struct tg3 *tp)
  7409. {
  7410. int err = 0;
  7411. if (!netif_running(tp->dev))
  7412. return TG3_LOOPBACK_FAILED;
  7413. err = tg3_reset_hw(tp, 1);
  7414. if (err)
  7415. return TG3_LOOPBACK_FAILED;
  7416. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7417. err |= TG3_MAC_LOOPBACK_FAILED;
  7418. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7419. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7420. err |= TG3_PHY_LOOPBACK_FAILED;
  7421. }
  7422. return err;
  7423. }
  7424. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7425. u64 *data)
  7426. {
  7427. struct tg3 *tp = netdev_priv(dev);
  7428. if (tp->link_config.phy_is_low_power)
  7429. tg3_set_power_state(tp, PCI_D0);
  7430. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7431. if (tg3_test_nvram(tp) != 0) {
  7432. etest->flags |= ETH_TEST_FL_FAILED;
  7433. data[0] = 1;
  7434. }
  7435. if (tg3_test_link(tp) != 0) {
  7436. etest->flags |= ETH_TEST_FL_FAILED;
  7437. data[1] = 1;
  7438. }
  7439. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7440. int err, irq_sync = 0;
  7441. if (netif_running(dev)) {
  7442. tg3_netif_stop(tp);
  7443. irq_sync = 1;
  7444. }
  7445. tg3_full_lock(tp, irq_sync);
  7446. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7447. err = tg3_nvram_lock(tp);
  7448. tg3_halt_cpu(tp, RX_CPU_BASE);
  7449. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7450. tg3_halt_cpu(tp, TX_CPU_BASE);
  7451. if (!err)
  7452. tg3_nvram_unlock(tp);
  7453. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7454. tg3_phy_reset(tp);
  7455. if (tg3_test_registers(tp) != 0) {
  7456. etest->flags |= ETH_TEST_FL_FAILED;
  7457. data[2] = 1;
  7458. }
  7459. if (tg3_test_memory(tp) != 0) {
  7460. etest->flags |= ETH_TEST_FL_FAILED;
  7461. data[3] = 1;
  7462. }
  7463. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7464. etest->flags |= ETH_TEST_FL_FAILED;
  7465. tg3_full_unlock(tp);
  7466. if (tg3_test_interrupt(tp) != 0) {
  7467. etest->flags |= ETH_TEST_FL_FAILED;
  7468. data[5] = 1;
  7469. }
  7470. tg3_full_lock(tp, 0);
  7471. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7472. if (netif_running(dev)) {
  7473. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7474. if (!tg3_restart_hw(tp, 1))
  7475. tg3_netif_start(tp);
  7476. }
  7477. tg3_full_unlock(tp);
  7478. }
  7479. if (tp->link_config.phy_is_low_power)
  7480. tg3_set_power_state(tp, PCI_D3hot);
  7481. }
  7482. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7483. {
  7484. struct mii_ioctl_data *data = if_mii(ifr);
  7485. struct tg3 *tp = netdev_priv(dev);
  7486. int err;
  7487. switch(cmd) {
  7488. case SIOCGMIIPHY:
  7489. data->phy_id = PHY_ADDR;
  7490. /* fallthru */
  7491. case SIOCGMIIREG: {
  7492. u32 mii_regval;
  7493. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7494. break; /* We have no PHY */
  7495. if (tp->link_config.phy_is_low_power)
  7496. return -EAGAIN;
  7497. spin_lock_bh(&tp->lock);
  7498. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7499. spin_unlock_bh(&tp->lock);
  7500. data->val_out = mii_regval;
  7501. return err;
  7502. }
  7503. case SIOCSMIIREG:
  7504. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7505. break; /* We have no PHY */
  7506. if (!capable(CAP_NET_ADMIN))
  7507. return -EPERM;
  7508. if (tp->link_config.phy_is_low_power)
  7509. return -EAGAIN;
  7510. spin_lock_bh(&tp->lock);
  7511. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7512. spin_unlock_bh(&tp->lock);
  7513. return err;
  7514. default:
  7515. /* do nothing */
  7516. break;
  7517. }
  7518. return -EOPNOTSUPP;
  7519. }
  7520. #if TG3_VLAN_TAG_USED
  7521. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7522. {
  7523. struct tg3 *tp = netdev_priv(dev);
  7524. if (netif_running(dev))
  7525. tg3_netif_stop(tp);
  7526. tg3_full_lock(tp, 0);
  7527. tp->vlgrp = grp;
  7528. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7529. __tg3_set_rx_mode(dev);
  7530. tg3_full_unlock(tp);
  7531. if (netif_running(dev))
  7532. tg3_netif_start(tp);
  7533. }
  7534. static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  7535. {
  7536. struct tg3 *tp = netdev_priv(dev);
  7537. if (netif_running(dev))
  7538. tg3_netif_stop(tp);
  7539. tg3_full_lock(tp, 0);
  7540. if (tp->vlgrp)
  7541. tp->vlgrp->vlan_devices[vid] = NULL;
  7542. tg3_full_unlock(tp);
  7543. if (netif_running(dev))
  7544. tg3_netif_start(tp);
  7545. }
  7546. #endif
  7547. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7548. {
  7549. struct tg3 *tp = netdev_priv(dev);
  7550. memcpy(ec, &tp->coal, sizeof(*ec));
  7551. return 0;
  7552. }
  7553. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7554. {
  7555. struct tg3 *tp = netdev_priv(dev);
  7556. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7557. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7558. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7559. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7560. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7561. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7562. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7563. }
  7564. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7565. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7566. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7567. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7568. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7569. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7570. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7571. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7572. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7573. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7574. return -EINVAL;
  7575. /* No rx interrupts will be generated if both are zero */
  7576. if ((ec->rx_coalesce_usecs == 0) &&
  7577. (ec->rx_max_coalesced_frames == 0))
  7578. return -EINVAL;
  7579. /* No tx interrupts will be generated if both are zero */
  7580. if ((ec->tx_coalesce_usecs == 0) &&
  7581. (ec->tx_max_coalesced_frames == 0))
  7582. return -EINVAL;
  7583. /* Only copy relevant parameters, ignore all others. */
  7584. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7585. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7586. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7587. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7588. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7589. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7590. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7591. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7592. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7593. if (netif_running(dev)) {
  7594. tg3_full_lock(tp, 0);
  7595. __tg3_set_coalesce(tp, &tp->coal);
  7596. tg3_full_unlock(tp);
  7597. }
  7598. return 0;
  7599. }
  7600. static struct ethtool_ops tg3_ethtool_ops = {
  7601. .get_settings = tg3_get_settings,
  7602. .set_settings = tg3_set_settings,
  7603. .get_drvinfo = tg3_get_drvinfo,
  7604. .get_regs_len = tg3_get_regs_len,
  7605. .get_regs = tg3_get_regs,
  7606. .get_wol = tg3_get_wol,
  7607. .set_wol = tg3_set_wol,
  7608. .get_msglevel = tg3_get_msglevel,
  7609. .set_msglevel = tg3_set_msglevel,
  7610. .nway_reset = tg3_nway_reset,
  7611. .get_link = ethtool_op_get_link,
  7612. .get_eeprom_len = tg3_get_eeprom_len,
  7613. .get_eeprom = tg3_get_eeprom,
  7614. .set_eeprom = tg3_set_eeprom,
  7615. .get_ringparam = tg3_get_ringparam,
  7616. .set_ringparam = tg3_set_ringparam,
  7617. .get_pauseparam = tg3_get_pauseparam,
  7618. .set_pauseparam = tg3_set_pauseparam,
  7619. .get_rx_csum = tg3_get_rx_csum,
  7620. .set_rx_csum = tg3_set_rx_csum,
  7621. .get_tx_csum = ethtool_op_get_tx_csum,
  7622. .set_tx_csum = tg3_set_tx_csum,
  7623. .get_sg = ethtool_op_get_sg,
  7624. .set_sg = ethtool_op_set_sg,
  7625. #if TG3_TSO_SUPPORT != 0
  7626. .get_tso = ethtool_op_get_tso,
  7627. .set_tso = tg3_set_tso,
  7628. #endif
  7629. .self_test_count = tg3_get_test_count,
  7630. .self_test = tg3_self_test,
  7631. .get_strings = tg3_get_strings,
  7632. .phys_id = tg3_phys_id,
  7633. .get_stats_count = tg3_get_stats_count,
  7634. .get_ethtool_stats = tg3_get_ethtool_stats,
  7635. .get_coalesce = tg3_get_coalesce,
  7636. .set_coalesce = tg3_set_coalesce,
  7637. .get_perm_addr = ethtool_op_get_perm_addr,
  7638. };
  7639. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7640. {
  7641. u32 cursize, val, magic;
  7642. tp->nvram_size = EEPROM_CHIP_SIZE;
  7643. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7644. return;
  7645. if ((magic != TG3_EEPROM_MAGIC) && ((magic & 0xff000000) != 0xa5000000))
  7646. return;
  7647. /*
  7648. * Size the chip by reading offsets at increasing powers of two.
  7649. * When we encounter our validation signature, we know the addressing
  7650. * has wrapped around, and thus have our chip size.
  7651. */
  7652. cursize = 0x10;
  7653. while (cursize < tp->nvram_size) {
  7654. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7655. return;
  7656. if (val == magic)
  7657. break;
  7658. cursize <<= 1;
  7659. }
  7660. tp->nvram_size = cursize;
  7661. }
  7662. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7663. {
  7664. u32 val;
  7665. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7666. return;
  7667. /* Selfboot format */
  7668. if (val != TG3_EEPROM_MAGIC) {
  7669. tg3_get_eeprom_size(tp);
  7670. return;
  7671. }
  7672. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7673. if (val != 0) {
  7674. tp->nvram_size = (val >> 16) * 1024;
  7675. return;
  7676. }
  7677. }
  7678. tp->nvram_size = 0x20000;
  7679. }
  7680. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7681. {
  7682. u32 nvcfg1;
  7683. nvcfg1 = tr32(NVRAM_CFG1);
  7684. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7685. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7686. }
  7687. else {
  7688. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7689. tw32(NVRAM_CFG1, nvcfg1);
  7690. }
  7691. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7692. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7693. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7694. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7695. tp->nvram_jedecnum = JEDEC_ATMEL;
  7696. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7697. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7698. break;
  7699. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7700. tp->nvram_jedecnum = JEDEC_ATMEL;
  7701. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7702. break;
  7703. case FLASH_VENDOR_ATMEL_EEPROM:
  7704. tp->nvram_jedecnum = JEDEC_ATMEL;
  7705. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7706. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7707. break;
  7708. case FLASH_VENDOR_ST:
  7709. tp->nvram_jedecnum = JEDEC_ST;
  7710. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7711. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7712. break;
  7713. case FLASH_VENDOR_SAIFUN:
  7714. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7715. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7716. break;
  7717. case FLASH_VENDOR_SST_SMALL:
  7718. case FLASH_VENDOR_SST_LARGE:
  7719. tp->nvram_jedecnum = JEDEC_SST;
  7720. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7721. break;
  7722. }
  7723. }
  7724. else {
  7725. tp->nvram_jedecnum = JEDEC_ATMEL;
  7726. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7727. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7728. }
  7729. }
  7730. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7731. {
  7732. u32 nvcfg1;
  7733. nvcfg1 = tr32(NVRAM_CFG1);
  7734. /* NVRAM protection for TPM */
  7735. if (nvcfg1 & (1 << 27))
  7736. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7737. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7738. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7739. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7740. tp->nvram_jedecnum = JEDEC_ATMEL;
  7741. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7742. break;
  7743. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7744. tp->nvram_jedecnum = JEDEC_ATMEL;
  7745. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7746. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7747. break;
  7748. case FLASH_5752VENDOR_ST_M45PE10:
  7749. case FLASH_5752VENDOR_ST_M45PE20:
  7750. case FLASH_5752VENDOR_ST_M45PE40:
  7751. tp->nvram_jedecnum = JEDEC_ST;
  7752. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7753. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7754. break;
  7755. }
  7756. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7757. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7758. case FLASH_5752PAGE_SIZE_256:
  7759. tp->nvram_pagesize = 256;
  7760. break;
  7761. case FLASH_5752PAGE_SIZE_512:
  7762. tp->nvram_pagesize = 512;
  7763. break;
  7764. case FLASH_5752PAGE_SIZE_1K:
  7765. tp->nvram_pagesize = 1024;
  7766. break;
  7767. case FLASH_5752PAGE_SIZE_2K:
  7768. tp->nvram_pagesize = 2048;
  7769. break;
  7770. case FLASH_5752PAGE_SIZE_4K:
  7771. tp->nvram_pagesize = 4096;
  7772. break;
  7773. case FLASH_5752PAGE_SIZE_264:
  7774. tp->nvram_pagesize = 264;
  7775. break;
  7776. }
  7777. }
  7778. else {
  7779. /* For eeprom, set pagesize to maximum eeprom size */
  7780. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7781. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7782. tw32(NVRAM_CFG1, nvcfg1);
  7783. }
  7784. }
  7785. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  7786. {
  7787. u32 nvcfg1;
  7788. nvcfg1 = tr32(NVRAM_CFG1);
  7789. /* NVRAM protection for TPM */
  7790. if (nvcfg1 & (1 << 27))
  7791. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7792. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7793. case FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ:
  7794. case FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ:
  7795. tp->nvram_jedecnum = JEDEC_ATMEL;
  7796. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7797. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7798. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7799. tw32(NVRAM_CFG1, nvcfg1);
  7800. break;
  7801. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7802. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7803. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  7804. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  7805. case FLASH_5755VENDOR_ATMEL_FLASH_4:
  7806. tp->nvram_jedecnum = JEDEC_ATMEL;
  7807. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7808. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7809. tp->nvram_pagesize = 264;
  7810. break;
  7811. case FLASH_5752VENDOR_ST_M45PE10:
  7812. case FLASH_5752VENDOR_ST_M45PE20:
  7813. case FLASH_5752VENDOR_ST_M45PE40:
  7814. tp->nvram_jedecnum = JEDEC_ST;
  7815. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7816. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7817. tp->nvram_pagesize = 256;
  7818. break;
  7819. }
  7820. }
  7821. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  7822. {
  7823. u32 nvcfg1;
  7824. nvcfg1 = tr32(NVRAM_CFG1);
  7825. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7826. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  7827. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  7828. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  7829. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  7830. tp->nvram_jedecnum = JEDEC_ATMEL;
  7831. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7832. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7833. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7834. tw32(NVRAM_CFG1, nvcfg1);
  7835. break;
  7836. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7837. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7838. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  7839. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  7840. tp->nvram_jedecnum = JEDEC_ATMEL;
  7841. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7842. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7843. tp->nvram_pagesize = 264;
  7844. break;
  7845. case FLASH_5752VENDOR_ST_M45PE10:
  7846. case FLASH_5752VENDOR_ST_M45PE20:
  7847. case FLASH_5752VENDOR_ST_M45PE40:
  7848. tp->nvram_jedecnum = JEDEC_ST;
  7849. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7850. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7851. tp->nvram_pagesize = 256;
  7852. break;
  7853. }
  7854. }
  7855. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  7856. static void __devinit tg3_nvram_init(struct tg3 *tp)
  7857. {
  7858. int j;
  7859. tw32_f(GRC_EEPROM_ADDR,
  7860. (EEPROM_ADDR_FSM_RESET |
  7861. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  7862. EEPROM_ADDR_CLKPERD_SHIFT)));
  7863. /* XXX schedule_timeout() ... */
  7864. for (j = 0; j < 100; j++)
  7865. udelay(10);
  7866. /* Enable seeprom accesses. */
  7867. tw32_f(GRC_LOCAL_CTRL,
  7868. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  7869. udelay(100);
  7870. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  7871. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  7872. tp->tg3_flags |= TG3_FLAG_NVRAM;
  7873. if (tg3_nvram_lock(tp)) {
  7874. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  7875. "tg3_nvram_init failed.\n", tp->dev->name);
  7876. return;
  7877. }
  7878. tg3_enable_nvram_access(tp);
  7879. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  7880. tg3_get_5752_nvram_info(tp);
  7881. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  7882. tg3_get_5755_nvram_info(tp);
  7883. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7884. tg3_get_5787_nvram_info(tp);
  7885. else
  7886. tg3_get_nvram_info(tp);
  7887. tg3_get_nvram_size(tp);
  7888. tg3_disable_nvram_access(tp);
  7889. tg3_nvram_unlock(tp);
  7890. } else {
  7891. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  7892. tg3_get_eeprom_size(tp);
  7893. }
  7894. }
  7895. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  7896. u32 offset, u32 *val)
  7897. {
  7898. u32 tmp;
  7899. int i;
  7900. if (offset > EEPROM_ADDR_ADDR_MASK ||
  7901. (offset % 4) != 0)
  7902. return -EINVAL;
  7903. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  7904. EEPROM_ADDR_DEVID_MASK |
  7905. EEPROM_ADDR_READ);
  7906. tw32(GRC_EEPROM_ADDR,
  7907. tmp |
  7908. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  7909. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  7910. EEPROM_ADDR_ADDR_MASK) |
  7911. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  7912. for (i = 0; i < 10000; i++) {
  7913. tmp = tr32(GRC_EEPROM_ADDR);
  7914. if (tmp & EEPROM_ADDR_COMPLETE)
  7915. break;
  7916. udelay(100);
  7917. }
  7918. if (!(tmp & EEPROM_ADDR_COMPLETE))
  7919. return -EBUSY;
  7920. *val = tr32(GRC_EEPROM_DATA);
  7921. return 0;
  7922. }
  7923. #define NVRAM_CMD_TIMEOUT 10000
  7924. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  7925. {
  7926. int i;
  7927. tw32(NVRAM_CMD, nvram_cmd);
  7928. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  7929. udelay(10);
  7930. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  7931. udelay(10);
  7932. break;
  7933. }
  7934. }
  7935. if (i == NVRAM_CMD_TIMEOUT) {
  7936. return -EBUSY;
  7937. }
  7938. return 0;
  7939. }
  7940. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  7941. {
  7942. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  7943. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  7944. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  7945. (tp->nvram_jedecnum == JEDEC_ATMEL))
  7946. addr = ((addr / tp->nvram_pagesize) <<
  7947. ATMEL_AT45DB0X1B_PAGE_POS) +
  7948. (addr % tp->nvram_pagesize);
  7949. return addr;
  7950. }
  7951. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  7952. {
  7953. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  7954. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  7955. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  7956. (tp->nvram_jedecnum == JEDEC_ATMEL))
  7957. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  7958. tp->nvram_pagesize) +
  7959. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  7960. return addr;
  7961. }
  7962. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  7963. {
  7964. int ret;
  7965. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  7966. return tg3_nvram_read_using_eeprom(tp, offset, val);
  7967. offset = tg3_nvram_phys_addr(tp, offset);
  7968. if (offset > NVRAM_ADDR_MSK)
  7969. return -EINVAL;
  7970. ret = tg3_nvram_lock(tp);
  7971. if (ret)
  7972. return ret;
  7973. tg3_enable_nvram_access(tp);
  7974. tw32(NVRAM_ADDR, offset);
  7975. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  7976. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  7977. if (ret == 0)
  7978. *val = swab32(tr32(NVRAM_RDDATA));
  7979. tg3_disable_nvram_access(tp);
  7980. tg3_nvram_unlock(tp);
  7981. return ret;
  7982. }
  7983. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  7984. {
  7985. int err;
  7986. u32 tmp;
  7987. err = tg3_nvram_read(tp, offset, &tmp);
  7988. *val = swab32(tmp);
  7989. return err;
  7990. }
  7991. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  7992. u32 offset, u32 len, u8 *buf)
  7993. {
  7994. int i, j, rc = 0;
  7995. u32 val;
  7996. for (i = 0; i < len; i += 4) {
  7997. u32 addr, data;
  7998. addr = offset + i;
  7999. memcpy(&data, buf + i, 4);
  8000. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8001. val = tr32(GRC_EEPROM_ADDR);
  8002. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8003. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8004. EEPROM_ADDR_READ);
  8005. tw32(GRC_EEPROM_ADDR, val |
  8006. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8007. (addr & EEPROM_ADDR_ADDR_MASK) |
  8008. EEPROM_ADDR_START |
  8009. EEPROM_ADDR_WRITE);
  8010. for (j = 0; j < 10000; j++) {
  8011. val = tr32(GRC_EEPROM_ADDR);
  8012. if (val & EEPROM_ADDR_COMPLETE)
  8013. break;
  8014. udelay(100);
  8015. }
  8016. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8017. rc = -EBUSY;
  8018. break;
  8019. }
  8020. }
  8021. return rc;
  8022. }
  8023. /* offset and length are dword aligned */
  8024. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8025. u8 *buf)
  8026. {
  8027. int ret = 0;
  8028. u32 pagesize = tp->nvram_pagesize;
  8029. u32 pagemask = pagesize - 1;
  8030. u32 nvram_cmd;
  8031. u8 *tmp;
  8032. tmp = kmalloc(pagesize, GFP_KERNEL);
  8033. if (tmp == NULL)
  8034. return -ENOMEM;
  8035. while (len) {
  8036. int j;
  8037. u32 phy_addr, page_off, size;
  8038. phy_addr = offset & ~pagemask;
  8039. for (j = 0; j < pagesize; j += 4) {
  8040. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8041. (u32 *) (tmp + j))))
  8042. break;
  8043. }
  8044. if (ret)
  8045. break;
  8046. page_off = offset & pagemask;
  8047. size = pagesize;
  8048. if (len < size)
  8049. size = len;
  8050. len -= size;
  8051. memcpy(tmp + page_off, buf, size);
  8052. offset = offset + (pagesize - page_off);
  8053. tg3_enable_nvram_access(tp);
  8054. /*
  8055. * Before we can erase the flash page, we need
  8056. * to issue a special "write enable" command.
  8057. */
  8058. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8059. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8060. break;
  8061. /* Erase the target page */
  8062. tw32(NVRAM_ADDR, phy_addr);
  8063. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8064. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8065. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8066. break;
  8067. /* Issue another write enable to start the write. */
  8068. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8069. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8070. break;
  8071. for (j = 0; j < pagesize; j += 4) {
  8072. u32 data;
  8073. data = *((u32 *) (tmp + j));
  8074. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8075. tw32(NVRAM_ADDR, phy_addr + j);
  8076. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8077. NVRAM_CMD_WR;
  8078. if (j == 0)
  8079. nvram_cmd |= NVRAM_CMD_FIRST;
  8080. else if (j == (pagesize - 4))
  8081. nvram_cmd |= NVRAM_CMD_LAST;
  8082. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8083. break;
  8084. }
  8085. if (ret)
  8086. break;
  8087. }
  8088. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8089. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8090. kfree(tmp);
  8091. return ret;
  8092. }
  8093. /* offset and length are dword aligned */
  8094. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8095. u8 *buf)
  8096. {
  8097. int i, ret = 0;
  8098. for (i = 0; i < len; i += 4, offset += 4) {
  8099. u32 data, page_off, phy_addr, nvram_cmd;
  8100. memcpy(&data, buf + i, 4);
  8101. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8102. page_off = offset % tp->nvram_pagesize;
  8103. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8104. tw32(NVRAM_ADDR, phy_addr);
  8105. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8106. if ((page_off == 0) || (i == 0))
  8107. nvram_cmd |= NVRAM_CMD_FIRST;
  8108. if (page_off == (tp->nvram_pagesize - 4))
  8109. nvram_cmd |= NVRAM_CMD_LAST;
  8110. if (i == (len - 4))
  8111. nvram_cmd |= NVRAM_CMD_LAST;
  8112. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8113. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8114. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8115. (tp->nvram_jedecnum == JEDEC_ST) &&
  8116. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8117. if ((ret = tg3_nvram_exec_cmd(tp,
  8118. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8119. NVRAM_CMD_DONE)))
  8120. break;
  8121. }
  8122. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8123. /* We always do complete word writes to eeprom. */
  8124. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8125. }
  8126. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8127. break;
  8128. }
  8129. return ret;
  8130. }
  8131. /* offset and length are dword aligned */
  8132. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8133. {
  8134. int ret;
  8135. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8136. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8137. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8138. udelay(40);
  8139. }
  8140. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8141. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8142. }
  8143. else {
  8144. u32 grc_mode;
  8145. ret = tg3_nvram_lock(tp);
  8146. if (ret)
  8147. return ret;
  8148. tg3_enable_nvram_access(tp);
  8149. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8150. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8151. tw32(NVRAM_WRITE1, 0x406);
  8152. grc_mode = tr32(GRC_MODE);
  8153. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8154. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8155. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8156. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8157. buf);
  8158. }
  8159. else {
  8160. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8161. buf);
  8162. }
  8163. grc_mode = tr32(GRC_MODE);
  8164. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8165. tg3_disable_nvram_access(tp);
  8166. tg3_nvram_unlock(tp);
  8167. }
  8168. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8169. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8170. udelay(40);
  8171. }
  8172. return ret;
  8173. }
  8174. struct subsys_tbl_ent {
  8175. u16 subsys_vendor, subsys_devid;
  8176. u32 phy_id;
  8177. };
  8178. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8179. /* Broadcom boards. */
  8180. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8181. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8182. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8183. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8184. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8185. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8186. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8187. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8188. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8189. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8190. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8191. /* 3com boards. */
  8192. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8193. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8194. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8195. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8196. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8197. /* DELL boards. */
  8198. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8199. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8200. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8201. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8202. /* Compaq boards. */
  8203. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8204. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8205. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8206. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8207. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8208. /* IBM boards. */
  8209. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8210. };
  8211. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8212. {
  8213. int i;
  8214. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8215. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8216. tp->pdev->subsystem_vendor) &&
  8217. (subsys_id_to_phy_id[i].subsys_devid ==
  8218. tp->pdev->subsystem_device))
  8219. return &subsys_id_to_phy_id[i];
  8220. }
  8221. return NULL;
  8222. }
  8223. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8224. {
  8225. u32 val;
  8226. u16 pmcsr;
  8227. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8228. * so need make sure we're in D0.
  8229. */
  8230. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8231. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8232. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8233. msleep(1);
  8234. /* Make sure register accesses (indirect or otherwise)
  8235. * will function correctly.
  8236. */
  8237. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8238. tp->misc_host_ctrl);
  8239. /* The memory arbiter has to be enabled in order for SRAM accesses
  8240. * to succeed. Normally on powerup the tg3 chip firmware will make
  8241. * sure it is enabled, but other entities such as system netboot
  8242. * code might disable it.
  8243. */
  8244. val = tr32(MEMARB_MODE);
  8245. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8246. tp->phy_id = PHY_ID_INVALID;
  8247. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8248. /* Assume an onboard device by default. */
  8249. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8250. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8251. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8252. u32 nic_cfg, led_cfg;
  8253. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8254. int eeprom_phy_serdes = 0;
  8255. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8256. tp->nic_sram_data_cfg = nic_cfg;
  8257. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8258. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8259. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8260. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8261. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8262. (ver > 0) && (ver < 0x100))
  8263. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8264. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8265. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8266. eeprom_phy_serdes = 1;
  8267. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8268. if (nic_phy_id != 0) {
  8269. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8270. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8271. eeprom_phy_id = (id1 >> 16) << 10;
  8272. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8273. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8274. } else
  8275. eeprom_phy_id = 0;
  8276. tp->phy_id = eeprom_phy_id;
  8277. if (eeprom_phy_serdes) {
  8278. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8279. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8280. else
  8281. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8282. }
  8283. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8284. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8285. SHASTA_EXT_LED_MODE_MASK);
  8286. else
  8287. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8288. switch (led_cfg) {
  8289. default:
  8290. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8291. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8292. break;
  8293. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8294. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8295. break;
  8296. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8297. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8298. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8299. * read on some older 5700/5701 bootcode.
  8300. */
  8301. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8302. ASIC_REV_5700 ||
  8303. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8304. ASIC_REV_5701)
  8305. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8306. break;
  8307. case SHASTA_EXT_LED_SHARED:
  8308. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8309. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8310. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8311. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8312. LED_CTRL_MODE_PHY_2);
  8313. break;
  8314. case SHASTA_EXT_LED_MAC:
  8315. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8316. break;
  8317. case SHASTA_EXT_LED_COMBO:
  8318. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8319. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8320. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8321. LED_CTRL_MODE_PHY_2);
  8322. break;
  8323. };
  8324. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8325. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8326. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8327. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8328. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP)
  8329. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8330. else
  8331. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8332. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8333. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8334. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8335. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8336. }
  8337. if (nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)
  8338. tp->tg3_flags |= TG3_FLAG_SERDES_WOL_CAP;
  8339. if (cfg2 & (1 << 17))
  8340. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8341. /* serdes signal pre-emphasis in register 0x590 set by */
  8342. /* bootcode if bit 18 is set */
  8343. if (cfg2 & (1 << 18))
  8344. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8345. }
  8346. }
  8347. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8348. {
  8349. u32 hw_phy_id_1, hw_phy_id_2;
  8350. u32 hw_phy_id, hw_phy_id_masked;
  8351. int err;
  8352. /* Reading the PHY ID register can conflict with ASF
  8353. * firwmare access to the PHY hardware.
  8354. */
  8355. err = 0;
  8356. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8357. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8358. } else {
  8359. /* Now read the physical PHY_ID from the chip and verify
  8360. * that it is sane. If it doesn't look good, we fall back
  8361. * to either the hard-coded table based PHY_ID and failing
  8362. * that the value found in the eeprom area.
  8363. */
  8364. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8365. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8366. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8367. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8368. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8369. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8370. }
  8371. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8372. tp->phy_id = hw_phy_id;
  8373. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8374. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8375. else
  8376. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8377. } else {
  8378. if (tp->phy_id != PHY_ID_INVALID) {
  8379. /* Do nothing, phy ID already set up in
  8380. * tg3_get_eeprom_hw_cfg().
  8381. */
  8382. } else {
  8383. struct subsys_tbl_ent *p;
  8384. /* No eeprom signature? Try the hardcoded
  8385. * subsys device table.
  8386. */
  8387. p = lookup_by_subsys(tp);
  8388. if (!p)
  8389. return -ENODEV;
  8390. tp->phy_id = p->phy_id;
  8391. if (!tp->phy_id ||
  8392. tp->phy_id == PHY_ID_BCM8002)
  8393. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8394. }
  8395. }
  8396. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8397. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8398. u32 bmsr, adv_reg, tg3_ctrl;
  8399. tg3_readphy(tp, MII_BMSR, &bmsr);
  8400. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8401. (bmsr & BMSR_LSTATUS))
  8402. goto skip_phy_reset;
  8403. err = tg3_phy_reset(tp);
  8404. if (err)
  8405. return err;
  8406. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8407. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8408. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8409. tg3_ctrl = 0;
  8410. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8411. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8412. MII_TG3_CTRL_ADV_1000_FULL);
  8413. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8414. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8415. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8416. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8417. }
  8418. if (!tg3_copper_is_advertising_all(tp)) {
  8419. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8420. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8421. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8422. tg3_writephy(tp, MII_BMCR,
  8423. BMCR_ANENABLE | BMCR_ANRESTART);
  8424. }
  8425. tg3_phy_set_wirespeed(tp);
  8426. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8427. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8428. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8429. }
  8430. skip_phy_reset:
  8431. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8432. err = tg3_init_5401phy_dsp(tp);
  8433. if (err)
  8434. return err;
  8435. }
  8436. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8437. err = tg3_init_5401phy_dsp(tp);
  8438. }
  8439. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8440. tp->link_config.advertising =
  8441. (ADVERTISED_1000baseT_Half |
  8442. ADVERTISED_1000baseT_Full |
  8443. ADVERTISED_Autoneg |
  8444. ADVERTISED_FIBRE);
  8445. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8446. tp->link_config.advertising &=
  8447. ~(ADVERTISED_1000baseT_Half |
  8448. ADVERTISED_1000baseT_Full);
  8449. return err;
  8450. }
  8451. static void __devinit tg3_read_partno(struct tg3 *tp)
  8452. {
  8453. unsigned char vpd_data[256];
  8454. int i;
  8455. u32 magic;
  8456. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8457. goto out_not_found;
  8458. if (magic == TG3_EEPROM_MAGIC) {
  8459. for (i = 0; i < 256; i += 4) {
  8460. u32 tmp;
  8461. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8462. goto out_not_found;
  8463. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8464. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8465. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8466. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8467. }
  8468. } else {
  8469. int vpd_cap;
  8470. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8471. for (i = 0; i < 256; i += 4) {
  8472. u32 tmp, j = 0;
  8473. u16 tmp16;
  8474. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8475. i);
  8476. while (j++ < 100) {
  8477. pci_read_config_word(tp->pdev, vpd_cap +
  8478. PCI_VPD_ADDR, &tmp16);
  8479. if (tmp16 & 0x8000)
  8480. break;
  8481. msleep(1);
  8482. }
  8483. if (!(tmp16 & 0x8000))
  8484. goto out_not_found;
  8485. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8486. &tmp);
  8487. tmp = cpu_to_le32(tmp);
  8488. memcpy(&vpd_data[i], &tmp, 4);
  8489. }
  8490. }
  8491. /* Now parse and find the part number. */
  8492. for (i = 0; i < 256; ) {
  8493. unsigned char val = vpd_data[i];
  8494. int block_end;
  8495. if (val == 0x82 || val == 0x91) {
  8496. i = (i + 3 +
  8497. (vpd_data[i + 1] +
  8498. (vpd_data[i + 2] << 8)));
  8499. continue;
  8500. }
  8501. if (val != 0x90)
  8502. goto out_not_found;
  8503. block_end = (i + 3 +
  8504. (vpd_data[i + 1] +
  8505. (vpd_data[i + 2] << 8)));
  8506. i += 3;
  8507. while (i < block_end) {
  8508. if (vpd_data[i + 0] == 'P' &&
  8509. vpd_data[i + 1] == 'N') {
  8510. int partno_len = vpd_data[i + 2];
  8511. if (partno_len > 24)
  8512. goto out_not_found;
  8513. memcpy(tp->board_part_number,
  8514. &vpd_data[i + 3],
  8515. partno_len);
  8516. /* Success. */
  8517. return;
  8518. }
  8519. }
  8520. /* Part number not found. */
  8521. goto out_not_found;
  8522. }
  8523. out_not_found:
  8524. strcpy(tp->board_part_number, "none");
  8525. }
  8526. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8527. {
  8528. u32 val, offset, start;
  8529. if (tg3_nvram_read_swab(tp, 0, &val))
  8530. return;
  8531. if (val != TG3_EEPROM_MAGIC)
  8532. return;
  8533. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8534. tg3_nvram_read_swab(tp, 0x4, &start))
  8535. return;
  8536. offset = tg3_nvram_logical_addr(tp, offset);
  8537. if (tg3_nvram_read_swab(tp, offset, &val))
  8538. return;
  8539. if ((val & 0xfc000000) == 0x0c000000) {
  8540. u32 ver_offset, addr;
  8541. int i;
  8542. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8543. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8544. return;
  8545. if (val != 0)
  8546. return;
  8547. addr = offset + ver_offset - start;
  8548. for (i = 0; i < 16; i += 4) {
  8549. if (tg3_nvram_read(tp, addr + i, &val))
  8550. return;
  8551. val = cpu_to_le32(val);
  8552. memcpy(tp->fw_ver + i, &val, 4);
  8553. }
  8554. }
  8555. }
  8556. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8557. {
  8558. static struct pci_device_id write_reorder_chipsets[] = {
  8559. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8560. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8561. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8562. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8563. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8564. PCI_DEVICE_ID_VIA_8385_0) },
  8565. { },
  8566. };
  8567. u32 misc_ctrl_reg;
  8568. u32 cacheline_sz_reg;
  8569. u32 pci_state_reg, grc_misc_cfg;
  8570. u32 val;
  8571. u16 pci_cmd;
  8572. int err;
  8573. /* Force memory write invalidate off. If we leave it on,
  8574. * then on 5700_BX chips we have to enable a workaround.
  8575. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8576. * to match the cacheline size. The Broadcom driver have this
  8577. * workaround but turns MWI off all the times so never uses
  8578. * it. This seems to suggest that the workaround is insufficient.
  8579. */
  8580. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8581. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8582. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8583. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8584. * has the register indirect write enable bit set before
  8585. * we try to access any of the MMIO registers. It is also
  8586. * critical that the PCI-X hw workaround situation is decided
  8587. * before that as well.
  8588. */
  8589. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8590. &misc_ctrl_reg);
  8591. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8592. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8593. /* Wrong chip ID in 5752 A0. This code can be removed later
  8594. * as A0 is not in production.
  8595. */
  8596. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8597. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8598. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8599. * we need to disable memory and use config. cycles
  8600. * only to access all registers. The 5702/03 chips
  8601. * can mistakenly decode the special cycles from the
  8602. * ICH chipsets as memory write cycles, causing corruption
  8603. * of register and memory space. Only certain ICH bridges
  8604. * will drive special cycles with non-zero data during the
  8605. * address phase which can fall within the 5703's address
  8606. * range. This is not an ICH bug as the PCI spec allows
  8607. * non-zero address during special cycles. However, only
  8608. * these ICH bridges are known to drive non-zero addresses
  8609. * during special cycles.
  8610. *
  8611. * Since special cycles do not cross PCI bridges, we only
  8612. * enable this workaround if the 5703 is on the secondary
  8613. * bus of these ICH bridges.
  8614. */
  8615. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8616. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8617. static struct tg3_dev_id {
  8618. u32 vendor;
  8619. u32 device;
  8620. u32 rev;
  8621. } ich_chipsets[] = {
  8622. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8623. PCI_ANY_ID },
  8624. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8625. PCI_ANY_ID },
  8626. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8627. 0xa },
  8628. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8629. PCI_ANY_ID },
  8630. { },
  8631. };
  8632. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8633. struct pci_dev *bridge = NULL;
  8634. while (pci_id->vendor != 0) {
  8635. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8636. bridge);
  8637. if (!bridge) {
  8638. pci_id++;
  8639. continue;
  8640. }
  8641. if (pci_id->rev != PCI_ANY_ID) {
  8642. u8 rev;
  8643. pci_read_config_byte(bridge, PCI_REVISION_ID,
  8644. &rev);
  8645. if (rev > pci_id->rev)
  8646. continue;
  8647. }
  8648. if (bridge->subordinate &&
  8649. (bridge->subordinate->number ==
  8650. tp->pdev->bus->number)) {
  8651. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8652. pci_dev_put(bridge);
  8653. break;
  8654. }
  8655. }
  8656. }
  8657. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8658. * DMA addresses > 40-bit. This bridge may have other additional
  8659. * 57xx devices behind it in some 4-port NIC designs for example.
  8660. * Any tg3 device found behind the bridge will also need the 40-bit
  8661. * DMA workaround.
  8662. */
  8663. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8664. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8665. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8666. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8667. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8668. }
  8669. else {
  8670. struct pci_dev *bridge = NULL;
  8671. do {
  8672. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8673. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8674. bridge);
  8675. if (bridge && bridge->subordinate &&
  8676. (bridge->subordinate->number <=
  8677. tp->pdev->bus->number) &&
  8678. (bridge->subordinate->subordinate >=
  8679. tp->pdev->bus->number)) {
  8680. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8681. pci_dev_put(bridge);
  8682. break;
  8683. }
  8684. } while (bridge);
  8685. }
  8686. /* Initialize misc host control in PCI block. */
  8687. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8688. MISC_HOST_CTRL_CHIPREV);
  8689. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8690. tp->misc_host_ctrl);
  8691. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8692. &cacheline_sz_reg);
  8693. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8694. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8695. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8696. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8697. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8698. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8699. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8700. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8701. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8702. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8703. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8704. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8705. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8706. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8707. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8708. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  8709. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8710. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8711. } else {
  8712. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 |
  8713. TG3_FLG2_HW_TSO_1_BUG;
  8714. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8715. ASIC_REV_5750 &&
  8716. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  8717. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_1_BUG;
  8718. }
  8719. }
  8720. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  8721. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  8722. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  8723. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  8724. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787)
  8725. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  8726. if (pci_find_capability(tp->pdev, PCI_CAP_ID_EXP) != 0)
  8727. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  8728. /* If we have an AMD 762 or VIA K8T800 chipset, write
  8729. * reordering to the mailbox registers done by the host
  8730. * controller can cause major troubles. We read back from
  8731. * every mailbox register write to force the writes to be
  8732. * posted to the chip in order.
  8733. */
  8734. if (pci_dev_present(write_reorder_chipsets) &&
  8735. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  8736. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  8737. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  8738. tp->pci_lat_timer < 64) {
  8739. tp->pci_lat_timer = 64;
  8740. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  8741. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  8742. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  8743. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  8744. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8745. cacheline_sz_reg);
  8746. }
  8747. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  8748. &pci_state_reg);
  8749. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  8750. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  8751. /* If this is a 5700 BX chipset, and we are in PCI-X
  8752. * mode, enable register write workaround.
  8753. *
  8754. * The workaround is to use indirect register accesses
  8755. * for all chip writes not to mailbox registers.
  8756. */
  8757. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  8758. u32 pm_reg;
  8759. u16 pci_cmd;
  8760. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  8761. /* The chip can have it's power management PCI config
  8762. * space registers clobbered due to this bug.
  8763. * So explicitly force the chip into D0 here.
  8764. */
  8765. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  8766. &pm_reg);
  8767. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  8768. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  8769. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  8770. pm_reg);
  8771. /* Also, force SERR#/PERR# in PCI command. */
  8772. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8773. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  8774. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8775. }
  8776. }
  8777. /* 5700 BX chips need to have their TX producer index mailboxes
  8778. * written twice to workaround a bug.
  8779. */
  8780. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  8781. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  8782. /* Back to back register writes can cause problems on this chip,
  8783. * the workaround is to read back all reg writes except those to
  8784. * mailbox regs. See tg3_write_indirect_reg32().
  8785. *
  8786. * PCI Express 5750_A0 rev chips need this workaround too.
  8787. */
  8788. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  8789. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  8790. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0))
  8791. tp->tg3_flags |= TG3_FLAG_5701_REG_WRITE_BUG;
  8792. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  8793. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  8794. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  8795. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  8796. /* Chip-specific fixup from Broadcom driver */
  8797. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  8798. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  8799. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  8800. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  8801. }
  8802. /* Default fast path register access methods */
  8803. tp->read32 = tg3_read32;
  8804. tp->write32 = tg3_write32;
  8805. tp->read32_mbox = tg3_read32;
  8806. tp->write32_mbox = tg3_write32;
  8807. tp->write32_tx_mbox = tg3_write32;
  8808. tp->write32_rx_mbox = tg3_write32;
  8809. /* Various workaround register access methods */
  8810. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  8811. tp->write32 = tg3_write_indirect_reg32;
  8812. else if (tp->tg3_flags & TG3_FLAG_5701_REG_WRITE_BUG)
  8813. tp->write32 = tg3_write_flush_reg32;
  8814. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  8815. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  8816. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  8817. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  8818. tp->write32_rx_mbox = tg3_write_flush_reg32;
  8819. }
  8820. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  8821. tp->read32 = tg3_read_indirect_reg32;
  8822. tp->write32 = tg3_write_indirect_reg32;
  8823. tp->read32_mbox = tg3_read_indirect_mbox;
  8824. tp->write32_mbox = tg3_write_indirect_mbox;
  8825. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  8826. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  8827. iounmap(tp->regs);
  8828. tp->regs = NULL;
  8829. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8830. pci_cmd &= ~PCI_COMMAND_MEMORY;
  8831. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8832. }
  8833. if (tp->write32 == tg3_write_indirect_reg32 ||
  8834. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  8835. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8836. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  8837. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  8838. /* Get eeprom hw config before calling tg3_set_power_state().
  8839. * In particular, the TG3_FLAG_EEPROM_WRITE_PROT flag must be
  8840. * determined before calling tg3_set_power_state() so that
  8841. * we know whether or not to switch out of Vaux power.
  8842. * When the flag is set, it means that GPIO1 is used for eeprom
  8843. * write protect and also implies that it is a LOM where GPIOs
  8844. * are not used to switch power.
  8845. */
  8846. tg3_get_eeprom_hw_cfg(tp);
  8847. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  8848. * GPIO1 driven high will bring 5700's external PHY out of reset.
  8849. * It is also used as eeprom write protect on LOMs.
  8850. */
  8851. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  8852. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  8853. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  8854. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  8855. GRC_LCLCTRL_GPIO_OUTPUT1);
  8856. /* Unused GPIO3 must be driven as output on 5752 because there
  8857. * are no pull-up resistors on unused GPIO pins.
  8858. */
  8859. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8860. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  8861. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8862. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  8863. /* Force the chip into D0. */
  8864. err = tg3_set_power_state(tp, PCI_D0);
  8865. if (err) {
  8866. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  8867. pci_name(tp->pdev));
  8868. return err;
  8869. }
  8870. /* 5700 B0 chips do not support checksumming correctly due
  8871. * to hardware bugs.
  8872. */
  8873. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  8874. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  8875. /* Derive initial jumbo mode from MTU assigned in
  8876. * ether_setup() via the alloc_etherdev() call
  8877. */
  8878. if (tp->dev->mtu > ETH_DATA_LEN &&
  8879. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8880. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  8881. /* Determine WakeOnLan speed to use. */
  8882. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8883. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8884. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  8885. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  8886. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  8887. } else {
  8888. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  8889. }
  8890. /* A few boards don't want Ethernet@WireSpeed phy feature */
  8891. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  8892. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  8893. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  8894. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  8895. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  8896. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  8897. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  8898. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  8899. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  8900. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  8901. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  8902. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  8903. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8904. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8905. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  8906. else
  8907. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  8908. }
  8909. tp->coalesce_mode = 0;
  8910. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  8911. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  8912. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  8913. /* Initialize MAC MI mode, polling disabled. */
  8914. tw32_f(MAC_MI_MODE, tp->mi_mode);
  8915. udelay(80);
  8916. /* Initialize data/descriptor byte/word swapping. */
  8917. val = tr32(GRC_MODE);
  8918. val &= GRC_MODE_HOST_STACKUP;
  8919. tw32(GRC_MODE, val | tp->grc_mode);
  8920. tg3_switch_clocks(tp);
  8921. /* Clear this out for sanity. */
  8922. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  8923. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  8924. &pci_state_reg);
  8925. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  8926. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  8927. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  8928. if (chiprevid == CHIPREV_ID_5701_A0 ||
  8929. chiprevid == CHIPREV_ID_5701_B0 ||
  8930. chiprevid == CHIPREV_ID_5701_B2 ||
  8931. chiprevid == CHIPREV_ID_5701_B5) {
  8932. void __iomem *sram_base;
  8933. /* Write some dummy words into the SRAM status block
  8934. * area, see if it reads back correctly. If the return
  8935. * value is bad, force enable the PCIX workaround.
  8936. */
  8937. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  8938. writel(0x00000000, sram_base);
  8939. writel(0x00000000, sram_base + 4);
  8940. writel(0xffffffff, sram_base + 4);
  8941. if (readl(sram_base) != 0x00000000)
  8942. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  8943. }
  8944. }
  8945. udelay(50);
  8946. tg3_nvram_init(tp);
  8947. grc_misc_cfg = tr32(GRC_MISC_CFG);
  8948. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  8949. /* Broadcom's driver says that CIOBE multisplit has a bug */
  8950. #if 0
  8951. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  8952. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5704CIOBE) {
  8953. tp->tg3_flags |= TG3_FLAG_SPLIT_MODE;
  8954. tp->split_mode_max_reqs = SPLIT_MODE_5704_MAX_REQ;
  8955. }
  8956. #endif
  8957. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  8958. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  8959. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  8960. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  8961. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  8962. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  8963. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  8964. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  8965. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  8966. HOSTCC_MODE_CLRTICK_TXBD);
  8967. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  8968. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8969. tp->misc_host_ctrl);
  8970. }
  8971. /* these are limited to 10/100 only */
  8972. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  8973. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  8974. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  8975. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  8976. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  8977. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  8978. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  8979. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  8980. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  8981. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F)))
  8982. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  8983. err = tg3_phy_probe(tp);
  8984. if (err) {
  8985. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  8986. pci_name(tp->pdev), err);
  8987. /* ... but do not return immediately ... */
  8988. }
  8989. tg3_read_partno(tp);
  8990. tg3_read_fw_ver(tp);
  8991. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  8992. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  8993. } else {
  8994. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  8995. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  8996. else
  8997. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  8998. }
  8999. /* 5700 {AX,BX} chips have a broken status block link
  9000. * change bit implementation, so we must use the
  9001. * status register in those cases.
  9002. */
  9003. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9004. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9005. else
  9006. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9007. /* The led_ctrl is set during tg3_phy_probe, here we might
  9008. * have to force the link status polling mechanism based
  9009. * upon subsystem IDs.
  9010. */
  9011. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9012. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9013. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9014. TG3_FLAG_USE_LINKCHG_REG);
  9015. }
  9016. /* For all SERDES we poll the MAC status register. */
  9017. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9018. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9019. else
  9020. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9021. /* All chips before 5787 can get confused if TX buffers
  9022. * straddle the 4GB address boundary in some cases.
  9023. */
  9024. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9025. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  9026. tp->dev->hard_start_xmit = tg3_start_xmit;
  9027. else
  9028. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9029. tp->rx_offset = 2;
  9030. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9031. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9032. tp->rx_offset = 0;
  9033. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9034. /* Increment the rx prod index on the rx std ring by at most
  9035. * 8 for these chips to workaround hw errata.
  9036. */
  9037. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9038. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9039. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9040. tp->rx_std_max_post = 8;
  9041. /* By default, disable wake-on-lan. User can change this
  9042. * using ETHTOOL_SWOL.
  9043. */
  9044. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9045. return err;
  9046. }
  9047. #ifdef CONFIG_SPARC64
  9048. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9049. {
  9050. struct net_device *dev = tp->dev;
  9051. struct pci_dev *pdev = tp->pdev;
  9052. struct pcidev_cookie *pcp = pdev->sysdata;
  9053. if (pcp != NULL) {
  9054. unsigned char *addr;
  9055. int len;
  9056. addr = of_get_property(pcp->prom_node, "local-mac-address",
  9057. &len);
  9058. if (addr && len == 6) {
  9059. memcpy(dev->dev_addr, addr, 6);
  9060. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9061. return 0;
  9062. }
  9063. }
  9064. return -ENODEV;
  9065. }
  9066. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9067. {
  9068. struct net_device *dev = tp->dev;
  9069. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9070. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9071. return 0;
  9072. }
  9073. #endif
  9074. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9075. {
  9076. struct net_device *dev = tp->dev;
  9077. u32 hi, lo, mac_offset;
  9078. int addr_ok = 0;
  9079. #ifdef CONFIG_SPARC64
  9080. if (!tg3_get_macaddr_sparc(tp))
  9081. return 0;
  9082. #endif
  9083. mac_offset = 0x7c;
  9084. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9085. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9086. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9087. mac_offset = 0xcc;
  9088. if (tg3_nvram_lock(tp))
  9089. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9090. else
  9091. tg3_nvram_unlock(tp);
  9092. }
  9093. /* First try to get it from MAC address mailbox. */
  9094. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9095. if ((hi >> 16) == 0x484b) {
  9096. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9097. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9098. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9099. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9100. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9101. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9102. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9103. /* Some old bootcode may report a 0 MAC address in SRAM */
  9104. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9105. }
  9106. if (!addr_ok) {
  9107. /* Next, try NVRAM. */
  9108. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9109. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9110. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9111. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9112. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9113. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9114. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9115. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9116. }
  9117. /* Finally just fetch it out of the MAC control regs. */
  9118. else {
  9119. hi = tr32(MAC_ADDR_0_HIGH);
  9120. lo = tr32(MAC_ADDR_0_LOW);
  9121. dev->dev_addr[5] = lo & 0xff;
  9122. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9123. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9124. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9125. dev->dev_addr[1] = hi & 0xff;
  9126. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9127. }
  9128. }
  9129. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9130. #ifdef CONFIG_SPARC64
  9131. if (!tg3_get_default_macaddr_sparc(tp))
  9132. return 0;
  9133. #endif
  9134. return -EINVAL;
  9135. }
  9136. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9137. return 0;
  9138. }
  9139. #define BOUNDARY_SINGLE_CACHELINE 1
  9140. #define BOUNDARY_MULTI_CACHELINE 2
  9141. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9142. {
  9143. int cacheline_size;
  9144. u8 byte;
  9145. int goal;
  9146. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9147. if (byte == 0)
  9148. cacheline_size = 1024;
  9149. else
  9150. cacheline_size = (int) byte * 4;
  9151. /* On 5703 and later chips, the boundary bits have no
  9152. * effect.
  9153. */
  9154. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9155. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9156. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9157. goto out;
  9158. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9159. goal = BOUNDARY_MULTI_CACHELINE;
  9160. #else
  9161. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9162. goal = BOUNDARY_SINGLE_CACHELINE;
  9163. #else
  9164. goal = 0;
  9165. #endif
  9166. #endif
  9167. if (!goal)
  9168. goto out;
  9169. /* PCI controllers on most RISC systems tend to disconnect
  9170. * when a device tries to burst across a cache-line boundary.
  9171. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9172. *
  9173. * Unfortunately, for PCI-E there are only limited
  9174. * write-side controls for this, and thus for reads
  9175. * we will still get the disconnects. We'll also waste
  9176. * these PCI cycles for both read and write for chips
  9177. * other than 5700 and 5701 which do not implement the
  9178. * boundary bits.
  9179. */
  9180. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9181. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9182. switch (cacheline_size) {
  9183. case 16:
  9184. case 32:
  9185. case 64:
  9186. case 128:
  9187. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9188. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9189. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9190. } else {
  9191. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9192. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9193. }
  9194. break;
  9195. case 256:
  9196. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9197. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9198. break;
  9199. default:
  9200. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9201. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9202. break;
  9203. };
  9204. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9205. switch (cacheline_size) {
  9206. case 16:
  9207. case 32:
  9208. case 64:
  9209. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9210. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9211. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9212. break;
  9213. }
  9214. /* fallthrough */
  9215. case 128:
  9216. default:
  9217. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9218. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9219. break;
  9220. };
  9221. } else {
  9222. switch (cacheline_size) {
  9223. case 16:
  9224. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9225. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9226. DMA_RWCTRL_WRITE_BNDRY_16);
  9227. break;
  9228. }
  9229. /* fallthrough */
  9230. case 32:
  9231. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9232. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9233. DMA_RWCTRL_WRITE_BNDRY_32);
  9234. break;
  9235. }
  9236. /* fallthrough */
  9237. case 64:
  9238. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9239. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9240. DMA_RWCTRL_WRITE_BNDRY_64);
  9241. break;
  9242. }
  9243. /* fallthrough */
  9244. case 128:
  9245. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9246. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9247. DMA_RWCTRL_WRITE_BNDRY_128);
  9248. break;
  9249. }
  9250. /* fallthrough */
  9251. case 256:
  9252. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9253. DMA_RWCTRL_WRITE_BNDRY_256);
  9254. break;
  9255. case 512:
  9256. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9257. DMA_RWCTRL_WRITE_BNDRY_512);
  9258. break;
  9259. case 1024:
  9260. default:
  9261. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9262. DMA_RWCTRL_WRITE_BNDRY_1024);
  9263. break;
  9264. };
  9265. }
  9266. out:
  9267. return val;
  9268. }
  9269. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9270. {
  9271. struct tg3_internal_buffer_desc test_desc;
  9272. u32 sram_dma_descs;
  9273. int i, ret;
  9274. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9275. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9276. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9277. tw32(RDMAC_STATUS, 0);
  9278. tw32(WDMAC_STATUS, 0);
  9279. tw32(BUFMGR_MODE, 0);
  9280. tw32(FTQ_RESET, 0);
  9281. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9282. test_desc.addr_lo = buf_dma & 0xffffffff;
  9283. test_desc.nic_mbuf = 0x00002100;
  9284. test_desc.len = size;
  9285. /*
  9286. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9287. * the *second* time the tg3 driver was getting loaded after an
  9288. * initial scan.
  9289. *
  9290. * Broadcom tells me:
  9291. * ...the DMA engine is connected to the GRC block and a DMA
  9292. * reset may affect the GRC block in some unpredictable way...
  9293. * The behavior of resets to individual blocks has not been tested.
  9294. *
  9295. * Broadcom noted the GRC reset will also reset all sub-components.
  9296. */
  9297. if (to_device) {
  9298. test_desc.cqid_sqid = (13 << 8) | 2;
  9299. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9300. udelay(40);
  9301. } else {
  9302. test_desc.cqid_sqid = (16 << 8) | 7;
  9303. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9304. udelay(40);
  9305. }
  9306. test_desc.flags = 0x00000005;
  9307. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9308. u32 val;
  9309. val = *(((u32 *)&test_desc) + i);
  9310. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9311. sram_dma_descs + (i * sizeof(u32)));
  9312. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9313. }
  9314. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9315. if (to_device) {
  9316. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9317. } else {
  9318. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9319. }
  9320. ret = -ENODEV;
  9321. for (i = 0; i < 40; i++) {
  9322. u32 val;
  9323. if (to_device)
  9324. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9325. else
  9326. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9327. if ((val & 0xffff) == sram_dma_descs) {
  9328. ret = 0;
  9329. break;
  9330. }
  9331. udelay(100);
  9332. }
  9333. return ret;
  9334. }
  9335. #define TEST_BUFFER_SIZE 0x2000
  9336. static int __devinit tg3_test_dma(struct tg3 *tp)
  9337. {
  9338. dma_addr_t buf_dma;
  9339. u32 *buf, saved_dma_rwctrl;
  9340. int ret;
  9341. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9342. if (!buf) {
  9343. ret = -ENOMEM;
  9344. goto out_nofree;
  9345. }
  9346. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9347. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9348. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9349. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9350. /* DMA read watermark not used on PCIE */
  9351. tp->dma_rwctrl |= 0x00180000;
  9352. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9353. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9354. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9355. tp->dma_rwctrl |= 0x003f0000;
  9356. else
  9357. tp->dma_rwctrl |= 0x003f000f;
  9358. } else {
  9359. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9360. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9361. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9362. /* If the 5704 is behind the EPB bridge, we can
  9363. * do the less restrictive ONE_DMA workaround for
  9364. * better performance.
  9365. */
  9366. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9367. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9368. tp->dma_rwctrl |= 0x8000;
  9369. else if (ccval == 0x6 || ccval == 0x7)
  9370. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9371. /* Set bit 23 to enable PCIX hw bug fix */
  9372. tp->dma_rwctrl |= 0x009f0000;
  9373. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9374. /* 5780 always in PCIX mode */
  9375. tp->dma_rwctrl |= 0x00144000;
  9376. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9377. /* 5714 always in PCIX mode */
  9378. tp->dma_rwctrl |= 0x00148000;
  9379. } else {
  9380. tp->dma_rwctrl |= 0x001b000f;
  9381. }
  9382. }
  9383. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9384. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9385. tp->dma_rwctrl &= 0xfffffff0;
  9386. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9387. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9388. /* Remove this if it causes problems for some boards. */
  9389. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9390. /* On 5700/5701 chips, we need to set this bit.
  9391. * Otherwise the chip will issue cacheline transactions
  9392. * to streamable DMA memory with not all the byte
  9393. * enables turned on. This is an error on several
  9394. * RISC PCI controllers, in particular sparc64.
  9395. *
  9396. * On 5703/5704 chips, this bit has been reassigned
  9397. * a different meaning. In particular, it is used
  9398. * on those chips to enable a PCI-X workaround.
  9399. */
  9400. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9401. }
  9402. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9403. #if 0
  9404. /* Unneeded, already done by tg3_get_invariants. */
  9405. tg3_switch_clocks(tp);
  9406. #endif
  9407. ret = 0;
  9408. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9409. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9410. goto out;
  9411. /* It is best to perform DMA test with maximum write burst size
  9412. * to expose the 5700/5701 write DMA bug.
  9413. */
  9414. saved_dma_rwctrl = tp->dma_rwctrl;
  9415. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9416. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9417. while (1) {
  9418. u32 *p = buf, i;
  9419. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9420. p[i] = i;
  9421. /* Send the buffer to the chip. */
  9422. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9423. if (ret) {
  9424. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9425. break;
  9426. }
  9427. #if 0
  9428. /* validate data reached card RAM correctly. */
  9429. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9430. u32 val;
  9431. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9432. if (le32_to_cpu(val) != p[i]) {
  9433. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9434. /* ret = -ENODEV here? */
  9435. }
  9436. p[i] = 0;
  9437. }
  9438. #endif
  9439. /* Now read it back. */
  9440. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9441. if (ret) {
  9442. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9443. break;
  9444. }
  9445. /* Verify it. */
  9446. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9447. if (p[i] == i)
  9448. continue;
  9449. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9450. DMA_RWCTRL_WRITE_BNDRY_16) {
  9451. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9452. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9453. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9454. break;
  9455. } else {
  9456. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9457. ret = -ENODEV;
  9458. goto out;
  9459. }
  9460. }
  9461. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9462. /* Success. */
  9463. ret = 0;
  9464. break;
  9465. }
  9466. }
  9467. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9468. DMA_RWCTRL_WRITE_BNDRY_16) {
  9469. static struct pci_device_id dma_wait_state_chipsets[] = {
  9470. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9471. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9472. { },
  9473. };
  9474. /* DMA test passed without adjusting DMA boundary,
  9475. * now look for chipsets that are known to expose the
  9476. * DMA bug without failing the test.
  9477. */
  9478. if (pci_dev_present(dma_wait_state_chipsets)) {
  9479. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9480. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9481. }
  9482. else
  9483. /* Safe to use the calculated DMA boundary. */
  9484. tp->dma_rwctrl = saved_dma_rwctrl;
  9485. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9486. }
  9487. out:
  9488. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9489. out_nofree:
  9490. return ret;
  9491. }
  9492. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9493. {
  9494. tp->link_config.advertising =
  9495. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9496. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9497. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9498. ADVERTISED_Autoneg | ADVERTISED_MII);
  9499. tp->link_config.speed = SPEED_INVALID;
  9500. tp->link_config.duplex = DUPLEX_INVALID;
  9501. tp->link_config.autoneg = AUTONEG_ENABLE;
  9502. tp->link_config.active_speed = SPEED_INVALID;
  9503. tp->link_config.active_duplex = DUPLEX_INVALID;
  9504. tp->link_config.phy_is_low_power = 0;
  9505. tp->link_config.orig_speed = SPEED_INVALID;
  9506. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9507. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9508. }
  9509. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9510. {
  9511. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9512. tp->bufmgr_config.mbuf_read_dma_low_water =
  9513. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9514. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9515. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9516. tp->bufmgr_config.mbuf_high_water =
  9517. DEFAULT_MB_HIGH_WATER_5705;
  9518. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9519. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9520. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9521. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9522. tp->bufmgr_config.mbuf_high_water_jumbo =
  9523. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9524. } else {
  9525. tp->bufmgr_config.mbuf_read_dma_low_water =
  9526. DEFAULT_MB_RDMA_LOW_WATER;
  9527. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9528. DEFAULT_MB_MACRX_LOW_WATER;
  9529. tp->bufmgr_config.mbuf_high_water =
  9530. DEFAULT_MB_HIGH_WATER;
  9531. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9532. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9533. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9534. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9535. tp->bufmgr_config.mbuf_high_water_jumbo =
  9536. DEFAULT_MB_HIGH_WATER_JUMBO;
  9537. }
  9538. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9539. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9540. }
  9541. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9542. {
  9543. switch (tp->phy_id & PHY_ID_MASK) {
  9544. case PHY_ID_BCM5400: return "5400";
  9545. case PHY_ID_BCM5401: return "5401";
  9546. case PHY_ID_BCM5411: return "5411";
  9547. case PHY_ID_BCM5701: return "5701";
  9548. case PHY_ID_BCM5703: return "5703";
  9549. case PHY_ID_BCM5704: return "5704";
  9550. case PHY_ID_BCM5705: return "5705";
  9551. case PHY_ID_BCM5750: return "5750";
  9552. case PHY_ID_BCM5752: return "5752";
  9553. case PHY_ID_BCM5714: return "5714";
  9554. case PHY_ID_BCM5780: return "5780";
  9555. case PHY_ID_BCM5755: return "5755";
  9556. case PHY_ID_BCM5787: return "5787";
  9557. case PHY_ID_BCM8002: return "8002/serdes";
  9558. case 0: return "serdes";
  9559. default: return "unknown";
  9560. };
  9561. }
  9562. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9563. {
  9564. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9565. strcpy(str, "PCI Express");
  9566. return str;
  9567. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9568. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9569. strcpy(str, "PCIX:");
  9570. if ((clock_ctrl == 7) ||
  9571. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9572. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9573. strcat(str, "133MHz");
  9574. else if (clock_ctrl == 0)
  9575. strcat(str, "33MHz");
  9576. else if (clock_ctrl == 2)
  9577. strcat(str, "50MHz");
  9578. else if (clock_ctrl == 4)
  9579. strcat(str, "66MHz");
  9580. else if (clock_ctrl == 6)
  9581. strcat(str, "100MHz");
  9582. } else {
  9583. strcpy(str, "PCI:");
  9584. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9585. strcat(str, "66MHz");
  9586. else
  9587. strcat(str, "33MHz");
  9588. }
  9589. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9590. strcat(str, ":32-bit");
  9591. else
  9592. strcat(str, ":64-bit");
  9593. return str;
  9594. }
  9595. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9596. {
  9597. struct pci_dev *peer;
  9598. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9599. for (func = 0; func < 8; func++) {
  9600. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9601. if (peer && peer != tp->pdev)
  9602. break;
  9603. pci_dev_put(peer);
  9604. }
  9605. /* 5704 can be configured in single-port mode, set peer to
  9606. * tp->pdev in that case.
  9607. */
  9608. if (!peer) {
  9609. peer = tp->pdev;
  9610. return peer;
  9611. }
  9612. /*
  9613. * We don't need to keep the refcount elevated; there's no way
  9614. * to remove one half of this device without removing the other
  9615. */
  9616. pci_dev_put(peer);
  9617. return peer;
  9618. }
  9619. static void __devinit tg3_init_coal(struct tg3 *tp)
  9620. {
  9621. struct ethtool_coalesce *ec = &tp->coal;
  9622. memset(ec, 0, sizeof(*ec));
  9623. ec->cmd = ETHTOOL_GCOALESCE;
  9624. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9625. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9626. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9627. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9628. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9629. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9630. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9631. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9632. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9633. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9634. HOSTCC_MODE_CLRTICK_TXBD)) {
  9635. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9636. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9637. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9638. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9639. }
  9640. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9641. ec->rx_coalesce_usecs_irq = 0;
  9642. ec->tx_coalesce_usecs_irq = 0;
  9643. ec->stats_block_coalesce_usecs = 0;
  9644. }
  9645. }
  9646. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9647. const struct pci_device_id *ent)
  9648. {
  9649. static int tg3_version_printed = 0;
  9650. unsigned long tg3reg_base, tg3reg_len;
  9651. struct net_device *dev;
  9652. struct tg3 *tp;
  9653. int i, err, pm_cap;
  9654. char str[40];
  9655. u64 dma_mask, persist_dma_mask;
  9656. if (tg3_version_printed++ == 0)
  9657. printk(KERN_INFO "%s", version);
  9658. err = pci_enable_device(pdev);
  9659. if (err) {
  9660. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9661. "aborting.\n");
  9662. return err;
  9663. }
  9664. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9665. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9666. "base address, aborting.\n");
  9667. err = -ENODEV;
  9668. goto err_out_disable_pdev;
  9669. }
  9670. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9671. if (err) {
  9672. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9673. "aborting.\n");
  9674. goto err_out_disable_pdev;
  9675. }
  9676. pci_set_master(pdev);
  9677. /* Find power-management capability. */
  9678. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9679. if (pm_cap == 0) {
  9680. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  9681. "aborting.\n");
  9682. err = -EIO;
  9683. goto err_out_free_res;
  9684. }
  9685. tg3reg_base = pci_resource_start(pdev, 0);
  9686. tg3reg_len = pci_resource_len(pdev, 0);
  9687. dev = alloc_etherdev(sizeof(*tp));
  9688. if (!dev) {
  9689. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  9690. err = -ENOMEM;
  9691. goto err_out_free_res;
  9692. }
  9693. SET_MODULE_OWNER(dev);
  9694. SET_NETDEV_DEV(dev, &pdev->dev);
  9695. #if TG3_VLAN_TAG_USED
  9696. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  9697. dev->vlan_rx_register = tg3_vlan_rx_register;
  9698. dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
  9699. #endif
  9700. tp = netdev_priv(dev);
  9701. tp->pdev = pdev;
  9702. tp->dev = dev;
  9703. tp->pm_cap = pm_cap;
  9704. tp->mac_mode = TG3_DEF_MAC_MODE;
  9705. tp->rx_mode = TG3_DEF_RX_MODE;
  9706. tp->tx_mode = TG3_DEF_TX_MODE;
  9707. tp->mi_mode = MAC_MI_MODE_BASE;
  9708. if (tg3_debug > 0)
  9709. tp->msg_enable = tg3_debug;
  9710. else
  9711. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  9712. /* The word/byte swap controls here control register access byte
  9713. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  9714. * setting below.
  9715. */
  9716. tp->misc_host_ctrl =
  9717. MISC_HOST_CTRL_MASK_PCI_INT |
  9718. MISC_HOST_CTRL_WORD_SWAP |
  9719. MISC_HOST_CTRL_INDIR_ACCESS |
  9720. MISC_HOST_CTRL_PCISTATE_RW;
  9721. /* The NONFRM (non-frame) byte/word swap controls take effect
  9722. * on descriptor entries, anything which isn't packet data.
  9723. *
  9724. * The StrongARM chips on the board (one for tx, one for rx)
  9725. * are running in big-endian mode.
  9726. */
  9727. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  9728. GRC_MODE_WSWAP_NONFRM_DATA);
  9729. #ifdef __BIG_ENDIAN
  9730. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  9731. #endif
  9732. spin_lock_init(&tp->lock);
  9733. spin_lock_init(&tp->tx_lock);
  9734. spin_lock_init(&tp->indirect_lock);
  9735. INIT_WORK(&tp->reset_task, tg3_reset_task, tp);
  9736. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  9737. if (tp->regs == 0UL) {
  9738. printk(KERN_ERR PFX "Cannot map device registers, "
  9739. "aborting.\n");
  9740. err = -ENOMEM;
  9741. goto err_out_free_dev;
  9742. }
  9743. tg3_init_link_config(tp);
  9744. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  9745. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  9746. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  9747. dev->open = tg3_open;
  9748. dev->stop = tg3_close;
  9749. dev->get_stats = tg3_get_stats;
  9750. dev->set_multicast_list = tg3_set_rx_mode;
  9751. dev->set_mac_address = tg3_set_mac_addr;
  9752. dev->do_ioctl = tg3_ioctl;
  9753. dev->tx_timeout = tg3_tx_timeout;
  9754. dev->poll = tg3_poll;
  9755. dev->ethtool_ops = &tg3_ethtool_ops;
  9756. dev->weight = 64;
  9757. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  9758. dev->change_mtu = tg3_change_mtu;
  9759. dev->irq = pdev->irq;
  9760. #ifdef CONFIG_NET_POLL_CONTROLLER
  9761. dev->poll_controller = tg3_poll_controller;
  9762. #endif
  9763. err = tg3_get_invariants(tp);
  9764. if (err) {
  9765. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  9766. "aborting.\n");
  9767. goto err_out_iounmap;
  9768. }
  9769. /* The EPB bridge inside 5714, 5715, and 5780 and any
  9770. * device behind the EPB cannot support DMA addresses > 40-bit.
  9771. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  9772. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  9773. * do DMA address check in tg3_start_xmit().
  9774. */
  9775. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  9776. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  9777. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  9778. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  9779. #ifdef CONFIG_HIGHMEM
  9780. dma_mask = DMA_64BIT_MASK;
  9781. #endif
  9782. } else
  9783. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  9784. /* Configure DMA attributes. */
  9785. if (dma_mask > DMA_32BIT_MASK) {
  9786. err = pci_set_dma_mask(pdev, dma_mask);
  9787. if (!err) {
  9788. dev->features |= NETIF_F_HIGHDMA;
  9789. err = pci_set_consistent_dma_mask(pdev,
  9790. persist_dma_mask);
  9791. if (err < 0) {
  9792. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  9793. "DMA for consistent allocations\n");
  9794. goto err_out_iounmap;
  9795. }
  9796. }
  9797. }
  9798. if (err || dma_mask == DMA_32BIT_MASK) {
  9799. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  9800. if (err) {
  9801. printk(KERN_ERR PFX "No usable DMA configuration, "
  9802. "aborting.\n");
  9803. goto err_out_iounmap;
  9804. }
  9805. }
  9806. tg3_init_bufmgr_config(tp);
  9807. #if TG3_TSO_SUPPORT != 0
  9808. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  9809. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  9810. }
  9811. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9812. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9813. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  9814. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  9815. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  9816. } else {
  9817. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  9818. }
  9819. /* TSO is on by default on chips that support hardware TSO.
  9820. * Firmware TSO on older chips gives lower performance, so it
  9821. * is off by default, but can be enabled using ethtool.
  9822. */
  9823. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  9824. dev->features |= NETIF_F_TSO;
  9825. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2)
  9826. dev->features |= NETIF_F_TSO6;
  9827. }
  9828. #endif
  9829. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  9830. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  9831. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  9832. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  9833. tp->rx_pending = 63;
  9834. }
  9835. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9836. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  9837. tp->pdev_peer = tg3_find_peer(tp);
  9838. err = tg3_get_device_address(tp);
  9839. if (err) {
  9840. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  9841. "aborting.\n");
  9842. goto err_out_iounmap;
  9843. }
  9844. /*
  9845. * Reset chip in case UNDI or EFI driver did not shutdown
  9846. * DMA self test will enable WDMAC and we'll see (spurious)
  9847. * pending DMA on the PCI bus at that point.
  9848. */
  9849. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  9850. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  9851. pci_save_state(tp->pdev);
  9852. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  9853. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  9854. }
  9855. err = tg3_test_dma(tp);
  9856. if (err) {
  9857. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  9858. goto err_out_iounmap;
  9859. }
  9860. /* Tigon3 can do ipv4 only... and some chips have buggy
  9861. * checksumming.
  9862. */
  9863. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  9864. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9865. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  9866. dev->features |= NETIF_F_HW_CSUM;
  9867. else
  9868. dev->features |= NETIF_F_IP_CSUM;
  9869. dev->features |= NETIF_F_SG;
  9870. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  9871. } else
  9872. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  9873. /* flow control autonegotiation is default behavior */
  9874. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  9875. tg3_init_coal(tp);
  9876. /* Now that we have fully setup the chip, save away a snapshot
  9877. * of the PCI config space. We need to restore this after
  9878. * GRC_MISC_CFG core clock resets and some resume events.
  9879. */
  9880. pci_save_state(tp->pdev);
  9881. err = register_netdev(dev);
  9882. if (err) {
  9883. printk(KERN_ERR PFX "Cannot register net device, "
  9884. "aborting.\n");
  9885. goto err_out_iounmap;
  9886. }
  9887. pci_set_drvdata(pdev, dev);
  9888. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %sBaseT Ethernet ",
  9889. dev->name,
  9890. tp->board_part_number,
  9891. tp->pci_chip_rev_id,
  9892. tg3_phy_string(tp),
  9893. tg3_bus_string(tp, str),
  9894. (tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100" : "10/100/1000");
  9895. for (i = 0; i < 6; i++)
  9896. printk("%2.2x%c", dev->dev_addr[i],
  9897. i == 5 ? '\n' : ':');
  9898. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  9899. "MIirq[%d] ASF[%d] Split[%d] WireSpeed[%d] "
  9900. "TSOcap[%d] \n",
  9901. dev->name,
  9902. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  9903. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  9904. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  9905. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  9906. (tp->tg3_flags & TG3_FLAG_SPLIT_MODE) != 0,
  9907. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  9908. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  9909. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  9910. dev->name, tp->dma_rwctrl,
  9911. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  9912. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  9913. netif_carrier_off(tp->dev);
  9914. return 0;
  9915. err_out_iounmap:
  9916. if (tp->regs) {
  9917. iounmap(tp->regs);
  9918. tp->regs = NULL;
  9919. }
  9920. err_out_free_dev:
  9921. free_netdev(dev);
  9922. err_out_free_res:
  9923. pci_release_regions(pdev);
  9924. err_out_disable_pdev:
  9925. pci_disable_device(pdev);
  9926. pci_set_drvdata(pdev, NULL);
  9927. return err;
  9928. }
  9929. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  9930. {
  9931. struct net_device *dev = pci_get_drvdata(pdev);
  9932. if (dev) {
  9933. struct tg3 *tp = netdev_priv(dev);
  9934. flush_scheduled_work();
  9935. unregister_netdev(dev);
  9936. if (tp->regs) {
  9937. iounmap(tp->regs);
  9938. tp->regs = NULL;
  9939. }
  9940. free_netdev(dev);
  9941. pci_release_regions(pdev);
  9942. pci_disable_device(pdev);
  9943. pci_set_drvdata(pdev, NULL);
  9944. }
  9945. }
  9946. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  9947. {
  9948. struct net_device *dev = pci_get_drvdata(pdev);
  9949. struct tg3 *tp = netdev_priv(dev);
  9950. int err;
  9951. if (!netif_running(dev))
  9952. return 0;
  9953. flush_scheduled_work();
  9954. tg3_netif_stop(tp);
  9955. del_timer_sync(&tp->timer);
  9956. tg3_full_lock(tp, 1);
  9957. tg3_disable_ints(tp);
  9958. tg3_full_unlock(tp);
  9959. netif_device_detach(dev);
  9960. tg3_full_lock(tp, 0);
  9961. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  9962. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  9963. tg3_full_unlock(tp);
  9964. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  9965. if (err) {
  9966. tg3_full_lock(tp, 0);
  9967. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  9968. if (tg3_restart_hw(tp, 1))
  9969. goto out;
  9970. tp->timer.expires = jiffies + tp->timer_offset;
  9971. add_timer(&tp->timer);
  9972. netif_device_attach(dev);
  9973. tg3_netif_start(tp);
  9974. out:
  9975. tg3_full_unlock(tp);
  9976. }
  9977. return err;
  9978. }
  9979. static int tg3_resume(struct pci_dev *pdev)
  9980. {
  9981. struct net_device *dev = pci_get_drvdata(pdev);
  9982. struct tg3 *tp = netdev_priv(dev);
  9983. int err;
  9984. if (!netif_running(dev))
  9985. return 0;
  9986. pci_restore_state(tp->pdev);
  9987. err = tg3_set_power_state(tp, PCI_D0);
  9988. if (err)
  9989. return err;
  9990. netif_device_attach(dev);
  9991. tg3_full_lock(tp, 0);
  9992. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  9993. err = tg3_restart_hw(tp, 1);
  9994. if (err)
  9995. goto out;
  9996. tp->timer.expires = jiffies + tp->timer_offset;
  9997. add_timer(&tp->timer);
  9998. tg3_netif_start(tp);
  9999. out:
  10000. tg3_full_unlock(tp);
  10001. return err;
  10002. }
  10003. static struct pci_driver tg3_driver = {
  10004. .name = DRV_MODULE_NAME,
  10005. .id_table = tg3_pci_tbl,
  10006. .probe = tg3_init_one,
  10007. .remove = __devexit_p(tg3_remove_one),
  10008. .suspend = tg3_suspend,
  10009. .resume = tg3_resume
  10010. };
  10011. static int __init tg3_init(void)
  10012. {
  10013. return pci_module_init(&tg3_driver);
  10014. }
  10015. static void __exit tg3_cleanup(void)
  10016. {
  10017. pci_unregister_driver(&tg3_driver);
  10018. }
  10019. module_init(tg3_init);
  10020. module_exit(tg3_cleanup);