tg3.c 332 KB

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