tg3.c 334 KB

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