tg3.c 332 KB

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