tg3.c 327 KB

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