tg3.c 310 KB

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