tg3.c 336 KB

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