tg3.c 344 KB

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