tg3.c 333 KB

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