tg3.c 349 KB

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