tg3.c 348 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005-2007 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <net/ip.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/byteorder.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_SPARC
  46. #include <asm/idprom.h>
  47. #include <asm/prom.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #define TG3_TSO_SUPPORT 1
  55. #include "tg3.h"
  56. #define DRV_MODULE_NAME "tg3"
  57. #define PFX DRV_MODULE_NAME ": "
  58. #define DRV_MODULE_VERSION "3.76"
  59. #define DRV_MODULE_RELDATE "May 5, 2007"
  60. #define TG3_DEF_MAC_MODE 0
  61. #define TG3_DEF_RX_MODE 0
  62. #define TG3_DEF_TX_MODE 0
  63. #define TG3_DEF_MSG_ENABLE \
  64. (NETIF_MSG_DRV | \
  65. NETIF_MSG_PROBE | \
  66. NETIF_MSG_LINK | \
  67. NETIF_MSG_TIMER | \
  68. NETIF_MSG_IFDOWN | \
  69. NETIF_MSG_IFUP | \
  70. NETIF_MSG_RX_ERR | \
  71. NETIF_MSG_TX_ERR)
  72. /* length of time before we decide the hardware is borked,
  73. * and dev->tx_timeout() should be called to fix the problem
  74. */
  75. #define TG3_TX_TIMEOUT (5 * HZ)
  76. /* hardware minimum and maximum for a single frame's data payload */
  77. #define TG3_MIN_MTU 60
  78. #define TG3_MAX_MTU(tp) \
  79. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  80. /* These numbers seem to be hard coded in the NIC firmware somehow.
  81. * You can't change the ring sizes, but you can change where you place
  82. * them in the NIC onboard memory.
  83. */
  84. #define TG3_RX_RING_SIZE 512
  85. #define TG3_DEF_RX_RING_PENDING 200
  86. #define TG3_RX_JUMBO_RING_SIZE 256
  87. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  88. /* Do not place this n-ring entries value into the tp struct itself,
  89. * we really want to expose these constants to GCC so that modulo et
  90. * al. operations are done with shifts and masks instead of with
  91. * hw multiply/modulo instructions. Another solution would be to
  92. * replace things like '% foo' with '& (foo - 1)'.
  93. */
  94. #define TG3_RX_RCB_RING_SIZE(tp) \
  95. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  96. #define TG3_TX_RING_SIZE 512
  97. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  98. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  99. TG3_RX_RING_SIZE)
  100. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  101. TG3_RX_JUMBO_RING_SIZE)
  102. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RCB_RING_SIZE(tp))
  104. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  105. TG3_TX_RING_SIZE)
  106. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  107. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  108. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  109. /* minimum number of free TX descriptors required to wake up TX process */
  110. #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
  111. /* number of ETHTOOL_GSTATS u64's */
  112. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  113. #define TG3_NUM_TEST 6
  114. static char version[] __devinitdata =
  115. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  116. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  117. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  118. MODULE_LICENSE("GPL");
  119. MODULE_VERSION(DRV_MODULE_VERSION);
  120. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  121. module_param(tg3_debug, int, 0);
  122. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  123. static struct pci_device_id tg3_pci_tbl[] = {
  124. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  125. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  126. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  127. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  184. {}
  185. };
  186. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  187. static const struct {
  188. const char string[ETH_GSTRING_LEN];
  189. } ethtool_stats_keys[TG3_NUM_STATS] = {
  190. { "rx_octets" },
  191. { "rx_fragments" },
  192. { "rx_ucast_packets" },
  193. { "rx_mcast_packets" },
  194. { "rx_bcast_packets" },
  195. { "rx_fcs_errors" },
  196. { "rx_align_errors" },
  197. { "rx_xon_pause_rcvd" },
  198. { "rx_xoff_pause_rcvd" },
  199. { "rx_mac_ctrl_rcvd" },
  200. { "rx_xoff_entered" },
  201. { "rx_frame_too_long_errors" },
  202. { "rx_jabbers" },
  203. { "rx_undersize_packets" },
  204. { "rx_in_length_errors" },
  205. { "rx_out_length_errors" },
  206. { "rx_64_or_less_octet_packets" },
  207. { "rx_65_to_127_octet_packets" },
  208. { "rx_128_to_255_octet_packets" },
  209. { "rx_256_to_511_octet_packets" },
  210. { "rx_512_to_1023_octet_packets" },
  211. { "rx_1024_to_1522_octet_packets" },
  212. { "rx_1523_to_2047_octet_packets" },
  213. { "rx_2048_to_4095_octet_packets" },
  214. { "rx_4096_to_8191_octet_packets" },
  215. { "rx_8192_to_9022_octet_packets" },
  216. { "tx_octets" },
  217. { "tx_collisions" },
  218. { "tx_xon_sent" },
  219. { "tx_xoff_sent" },
  220. { "tx_flow_control" },
  221. { "tx_mac_errors" },
  222. { "tx_single_collisions" },
  223. { "tx_mult_collisions" },
  224. { "tx_deferred" },
  225. { "tx_excessive_collisions" },
  226. { "tx_late_collisions" },
  227. { "tx_collide_2times" },
  228. { "tx_collide_3times" },
  229. { "tx_collide_4times" },
  230. { "tx_collide_5times" },
  231. { "tx_collide_6times" },
  232. { "tx_collide_7times" },
  233. { "tx_collide_8times" },
  234. { "tx_collide_9times" },
  235. { "tx_collide_10times" },
  236. { "tx_collide_11times" },
  237. { "tx_collide_12times" },
  238. { "tx_collide_13times" },
  239. { "tx_collide_14times" },
  240. { "tx_collide_15times" },
  241. { "tx_ucast_packets" },
  242. { "tx_mcast_packets" },
  243. { "tx_bcast_packets" },
  244. { "tx_carrier_sense_errors" },
  245. { "tx_discards" },
  246. { "tx_errors" },
  247. { "dma_writeq_full" },
  248. { "dma_write_prioq_full" },
  249. { "rxbds_empty" },
  250. { "rx_discards" },
  251. { "rx_errors" },
  252. { "rx_threshold_hit" },
  253. { "dma_readq_full" },
  254. { "dma_read_prioq_full" },
  255. { "tx_comp_queue_full" },
  256. { "ring_set_send_prod_index" },
  257. { "ring_status_update" },
  258. { "nic_irqs" },
  259. { "nic_avoided_irqs" },
  260. { "nic_tx_threshold_hit" }
  261. };
  262. static const struct {
  263. const char string[ETH_GSTRING_LEN];
  264. } ethtool_test_keys[TG3_NUM_TEST] = {
  265. { "nvram test (online) " },
  266. { "link test (online) " },
  267. { "register test (offline)" },
  268. { "memory test (offline)" },
  269. { "loopback test (offline)" },
  270. { "interrupt test (offline)" },
  271. };
  272. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  273. {
  274. writel(val, tp->regs + off);
  275. }
  276. static u32 tg3_read32(struct tg3 *tp, u32 off)
  277. {
  278. return (readl(tp->regs + off));
  279. }
  280. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  281. {
  282. unsigned long flags;
  283. spin_lock_irqsave(&tp->indirect_lock, flags);
  284. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  285. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  286. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  287. }
  288. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  289. {
  290. writel(val, tp->regs + off);
  291. readl(tp->regs + off);
  292. }
  293. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  294. {
  295. unsigned long flags;
  296. u32 val;
  297. spin_lock_irqsave(&tp->indirect_lock, flags);
  298. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  299. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  300. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  301. return val;
  302. }
  303. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  304. {
  305. unsigned long flags;
  306. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  307. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  308. TG3_64BIT_REG_LOW, val);
  309. return;
  310. }
  311. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  312. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  313. TG3_64BIT_REG_LOW, val);
  314. return;
  315. }
  316. spin_lock_irqsave(&tp->indirect_lock, flags);
  317. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  318. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  319. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  320. /* In indirect mode when disabling interrupts, we also need
  321. * to clear the interrupt bit in the GRC local ctrl register.
  322. */
  323. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  324. (val == 0x1)) {
  325. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  326. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  327. }
  328. }
  329. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  330. {
  331. unsigned long flags;
  332. u32 val;
  333. spin_lock_irqsave(&tp->indirect_lock, flags);
  334. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  335. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  336. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  337. return val;
  338. }
  339. /* usec_wait specifies the wait time in usec when writing to certain registers
  340. * where it is unsafe to read back the register without some delay.
  341. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  342. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  343. */
  344. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  345. {
  346. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  347. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  348. /* Non-posted methods */
  349. tp->write32(tp, off, val);
  350. else {
  351. /* Posted method */
  352. tg3_write32(tp, off, val);
  353. if (usec_wait)
  354. udelay(usec_wait);
  355. tp->read32(tp, off);
  356. }
  357. /* Wait again after the read for the posted method to guarantee that
  358. * the wait time is met.
  359. */
  360. if (usec_wait)
  361. udelay(usec_wait);
  362. }
  363. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  364. {
  365. tp->write32_mbox(tp, off, val);
  366. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  367. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  368. tp->read32_mbox(tp, off);
  369. }
  370. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  371. {
  372. void __iomem *mbox = tp->regs + off;
  373. writel(val, mbox);
  374. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  375. writel(val, mbox);
  376. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  377. readl(mbox);
  378. }
  379. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  380. {
  381. return (readl(tp->regs + off + GRCMBOX_BASE));
  382. }
  383. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  384. {
  385. writel(val, tp->regs + off + GRCMBOX_BASE);
  386. }
  387. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  388. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  389. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  390. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  391. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  392. #define tw32(reg,val) tp->write32(tp, reg, val)
  393. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  394. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  395. #define tr32(reg) tp->read32(tp, reg)
  396. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  397. {
  398. unsigned long flags;
  399. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  400. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  401. return;
  402. spin_lock_irqsave(&tp->indirect_lock, flags);
  403. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  404. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  405. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  406. /* Always leave this as zero. */
  407. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  408. } else {
  409. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  410. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  411. /* Always leave this as zero. */
  412. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  413. }
  414. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  415. }
  416. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  417. {
  418. unsigned long flags;
  419. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  420. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  421. *val = 0;
  422. return;
  423. }
  424. spin_lock_irqsave(&tp->indirect_lock, flags);
  425. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  426. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  427. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  428. /* Always leave this as zero. */
  429. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  430. } else {
  431. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  432. *val = tr32(TG3PCI_MEM_WIN_DATA);
  433. /* Always leave this as zero. */
  434. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  435. }
  436. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  437. }
  438. static void tg3_disable_ints(struct tg3 *tp)
  439. {
  440. tw32(TG3PCI_MISC_HOST_CTRL,
  441. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  442. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  443. }
  444. static inline void tg3_cond_int(struct tg3 *tp)
  445. {
  446. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  447. (tp->hw_status->status & SD_STATUS_UPDATED))
  448. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  449. else
  450. tw32(HOSTCC_MODE, tp->coalesce_mode |
  451. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  452. }
  453. static void tg3_enable_ints(struct tg3 *tp)
  454. {
  455. tp->irq_sync = 0;
  456. wmb();
  457. tw32(TG3PCI_MISC_HOST_CTRL,
  458. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  459. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  460. (tp->last_tag << 24));
  461. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  462. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  463. (tp->last_tag << 24));
  464. tg3_cond_int(tp);
  465. }
  466. static inline unsigned int tg3_has_work(struct tg3 *tp)
  467. {
  468. struct tg3_hw_status *sblk = tp->hw_status;
  469. unsigned int work_exists = 0;
  470. /* check for phy events */
  471. if (!(tp->tg3_flags &
  472. (TG3_FLAG_USE_LINKCHG_REG |
  473. TG3_FLAG_POLL_SERDES))) {
  474. if (sblk->status & SD_STATUS_LINK_CHG)
  475. work_exists = 1;
  476. }
  477. /* check for RX/TX work to do */
  478. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  479. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  480. work_exists = 1;
  481. return work_exists;
  482. }
  483. /* tg3_restart_ints
  484. * similar to tg3_enable_ints, but it accurately determines whether there
  485. * is new work pending and can return without flushing the PIO write
  486. * which reenables interrupts
  487. */
  488. static void tg3_restart_ints(struct tg3 *tp)
  489. {
  490. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  491. tp->last_tag << 24);
  492. mmiowb();
  493. /* When doing tagged status, this work check is unnecessary.
  494. * The last_tag we write above tells the chip which piece of
  495. * work we've completed.
  496. */
  497. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  498. tg3_has_work(tp))
  499. tw32(HOSTCC_MODE, tp->coalesce_mode |
  500. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  501. }
  502. static inline void tg3_netif_stop(struct tg3 *tp)
  503. {
  504. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  505. netif_poll_disable(tp->dev);
  506. netif_tx_disable(tp->dev);
  507. }
  508. static inline void tg3_netif_start(struct tg3 *tp)
  509. {
  510. netif_wake_queue(tp->dev);
  511. /* NOTE: unconditional netif_wake_queue is only appropriate
  512. * so long as all callers are assured to have free tx slots
  513. * (such as after tg3_init_hw)
  514. */
  515. netif_poll_enable(tp->dev);
  516. tp->hw_status->status |= SD_STATUS_UPDATED;
  517. tg3_enable_ints(tp);
  518. }
  519. static void tg3_switch_clocks(struct tg3 *tp)
  520. {
  521. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  522. u32 orig_clock_ctrl;
  523. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  524. return;
  525. orig_clock_ctrl = clock_ctrl;
  526. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  527. CLOCK_CTRL_CLKRUN_OENABLE |
  528. 0x1f);
  529. tp->pci_clock_ctrl = clock_ctrl;
  530. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  531. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  532. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  533. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  534. }
  535. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  536. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  537. clock_ctrl |
  538. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  539. 40);
  540. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  541. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  542. 40);
  543. }
  544. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  545. }
  546. #define PHY_BUSY_LOOPS 5000
  547. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  548. {
  549. u32 frame_val;
  550. unsigned int loops;
  551. int ret;
  552. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  553. tw32_f(MAC_MI_MODE,
  554. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  555. udelay(80);
  556. }
  557. *val = 0x0;
  558. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  559. MI_COM_PHY_ADDR_MASK);
  560. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  561. MI_COM_REG_ADDR_MASK);
  562. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  563. tw32_f(MAC_MI_COM, frame_val);
  564. loops = PHY_BUSY_LOOPS;
  565. while (loops != 0) {
  566. udelay(10);
  567. frame_val = tr32(MAC_MI_COM);
  568. if ((frame_val & MI_COM_BUSY) == 0) {
  569. udelay(5);
  570. frame_val = tr32(MAC_MI_COM);
  571. break;
  572. }
  573. loops -= 1;
  574. }
  575. ret = -EBUSY;
  576. if (loops != 0) {
  577. *val = frame_val & MI_COM_DATA_MASK;
  578. ret = 0;
  579. }
  580. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  581. tw32_f(MAC_MI_MODE, tp->mi_mode);
  582. udelay(80);
  583. }
  584. return ret;
  585. }
  586. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  587. {
  588. u32 frame_val;
  589. unsigned int loops;
  590. int ret;
  591. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  592. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  593. return 0;
  594. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  595. tw32_f(MAC_MI_MODE,
  596. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  597. udelay(80);
  598. }
  599. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  600. MI_COM_PHY_ADDR_MASK);
  601. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  602. MI_COM_REG_ADDR_MASK);
  603. frame_val |= (val & MI_COM_DATA_MASK);
  604. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  605. tw32_f(MAC_MI_COM, frame_val);
  606. loops = PHY_BUSY_LOOPS;
  607. while (loops != 0) {
  608. udelay(10);
  609. frame_val = tr32(MAC_MI_COM);
  610. if ((frame_val & MI_COM_BUSY) == 0) {
  611. udelay(5);
  612. frame_val = tr32(MAC_MI_COM);
  613. break;
  614. }
  615. loops -= 1;
  616. }
  617. ret = -EBUSY;
  618. if (loops != 0)
  619. ret = 0;
  620. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  621. tw32_f(MAC_MI_MODE, tp->mi_mode);
  622. udelay(80);
  623. }
  624. return ret;
  625. }
  626. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  627. {
  628. u32 val;
  629. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  630. return;
  631. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  632. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  633. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  634. (val | (1 << 15) | (1 << 4)));
  635. }
  636. static int tg3_bmcr_reset(struct tg3 *tp)
  637. {
  638. u32 phy_control;
  639. int limit, err;
  640. /* OK, reset it, and poll the BMCR_RESET bit until it
  641. * clears or we time out.
  642. */
  643. phy_control = BMCR_RESET;
  644. err = tg3_writephy(tp, MII_BMCR, phy_control);
  645. if (err != 0)
  646. return -EBUSY;
  647. limit = 5000;
  648. while (limit--) {
  649. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  650. if (err != 0)
  651. return -EBUSY;
  652. if ((phy_control & BMCR_RESET) == 0) {
  653. udelay(40);
  654. break;
  655. }
  656. udelay(10);
  657. }
  658. if (limit <= 0)
  659. return -EBUSY;
  660. return 0;
  661. }
  662. static int tg3_wait_macro_done(struct tg3 *tp)
  663. {
  664. int limit = 100;
  665. while (limit--) {
  666. u32 tmp32;
  667. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  668. if ((tmp32 & 0x1000) == 0)
  669. break;
  670. }
  671. }
  672. if (limit <= 0)
  673. return -EBUSY;
  674. return 0;
  675. }
  676. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  677. {
  678. static const u32 test_pat[4][6] = {
  679. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  680. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  681. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  682. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  683. };
  684. int chan;
  685. for (chan = 0; chan < 4; chan++) {
  686. int i;
  687. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  688. (chan * 0x2000) | 0x0200);
  689. tg3_writephy(tp, 0x16, 0x0002);
  690. for (i = 0; i < 6; i++)
  691. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  692. test_pat[chan][i]);
  693. tg3_writephy(tp, 0x16, 0x0202);
  694. if (tg3_wait_macro_done(tp)) {
  695. *resetp = 1;
  696. return -EBUSY;
  697. }
  698. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  699. (chan * 0x2000) | 0x0200);
  700. tg3_writephy(tp, 0x16, 0x0082);
  701. if (tg3_wait_macro_done(tp)) {
  702. *resetp = 1;
  703. return -EBUSY;
  704. }
  705. tg3_writephy(tp, 0x16, 0x0802);
  706. if (tg3_wait_macro_done(tp)) {
  707. *resetp = 1;
  708. return -EBUSY;
  709. }
  710. for (i = 0; i < 6; i += 2) {
  711. u32 low, high;
  712. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  713. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  714. tg3_wait_macro_done(tp)) {
  715. *resetp = 1;
  716. return -EBUSY;
  717. }
  718. low &= 0x7fff;
  719. high &= 0x000f;
  720. if (low != test_pat[chan][i] ||
  721. high != test_pat[chan][i+1]) {
  722. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  723. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  724. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  725. return -EBUSY;
  726. }
  727. }
  728. }
  729. return 0;
  730. }
  731. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  732. {
  733. int chan;
  734. for (chan = 0; chan < 4; chan++) {
  735. int i;
  736. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  737. (chan * 0x2000) | 0x0200);
  738. tg3_writephy(tp, 0x16, 0x0002);
  739. for (i = 0; i < 6; i++)
  740. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  741. tg3_writephy(tp, 0x16, 0x0202);
  742. if (tg3_wait_macro_done(tp))
  743. return -EBUSY;
  744. }
  745. return 0;
  746. }
  747. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  748. {
  749. u32 reg32, phy9_orig;
  750. int retries, do_phy_reset, err;
  751. retries = 10;
  752. do_phy_reset = 1;
  753. do {
  754. if (do_phy_reset) {
  755. err = tg3_bmcr_reset(tp);
  756. if (err)
  757. return err;
  758. do_phy_reset = 0;
  759. }
  760. /* Disable transmitter and interrupt. */
  761. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  762. continue;
  763. reg32 |= 0x3000;
  764. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  765. /* Set full-duplex, 1000 mbps. */
  766. tg3_writephy(tp, MII_BMCR,
  767. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  768. /* Set to master mode. */
  769. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  770. continue;
  771. tg3_writephy(tp, MII_TG3_CTRL,
  772. (MII_TG3_CTRL_AS_MASTER |
  773. MII_TG3_CTRL_ENABLE_AS_MASTER));
  774. /* Enable SM_DSP_CLOCK and 6dB. */
  775. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  776. /* Block the PHY control access. */
  777. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  778. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  779. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  780. if (!err)
  781. break;
  782. } while (--retries);
  783. err = tg3_phy_reset_chanpat(tp);
  784. if (err)
  785. return err;
  786. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  787. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  788. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  789. tg3_writephy(tp, 0x16, 0x0000);
  790. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  791. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  792. /* Set Extended packet length bit for jumbo frames */
  793. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  794. }
  795. else {
  796. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  797. }
  798. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  799. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  800. reg32 &= ~0x3000;
  801. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  802. } else if (!err)
  803. err = -EBUSY;
  804. return err;
  805. }
  806. static void tg3_link_report(struct tg3 *);
  807. /* This will reset the tigon3 PHY if there is no valid
  808. * link unless the FORCE argument is non-zero.
  809. */
  810. static int tg3_phy_reset(struct tg3 *tp)
  811. {
  812. u32 phy_status;
  813. int err;
  814. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  815. u32 val;
  816. val = tr32(GRC_MISC_CFG);
  817. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  818. udelay(40);
  819. }
  820. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  821. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  822. if (err != 0)
  823. return -EBUSY;
  824. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  825. netif_carrier_off(tp->dev);
  826. tg3_link_report(tp);
  827. }
  828. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  829. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  830. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  831. err = tg3_phy_reset_5703_4_5(tp);
  832. if (err)
  833. return err;
  834. goto out;
  835. }
  836. err = tg3_bmcr_reset(tp);
  837. if (err)
  838. return err;
  839. out:
  840. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  841. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  842. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  843. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  844. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  845. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  846. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  847. }
  848. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  849. tg3_writephy(tp, 0x1c, 0x8d68);
  850. tg3_writephy(tp, 0x1c, 0x8d68);
  851. }
  852. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  853. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  854. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  855. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  856. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  857. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  858. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  859. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  860. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  861. }
  862. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  863. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  864. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  865. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  866. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  867. tg3_writephy(tp, MII_TG3_TEST1,
  868. MII_TG3_TEST1_TRIM_EN | 0x4);
  869. } else
  870. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  871. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  872. }
  873. /* Set Extended packet length bit (bit 14) on all chips that */
  874. /* support jumbo frames */
  875. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  876. /* Cannot do read-modify-write on 5401 */
  877. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  878. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  879. u32 phy_reg;
  880. /* Set bit 14 with read-modify-write to preserve other bits */
  881. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  882. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  883. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  884. }
  885. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  886. * jumbo frames transmission.
  887. */
  888. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  889. u32 phy_reg;
  890. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  891. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  892. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  893. }
  894. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  895. u32 phy_reg;
  896. /* adjust output voltage */
  897. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  898. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
  899. u32 phy_reg2;
  900. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  901. phy_reg | MII_TG3_EPHY_SHADOW_EN);
  902. /* Enable auto-MDIX */
  903. if (!tg3_readphy(tp, 0x10, &phy_reg2))
  904. tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
  905. tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
  906. }
  907. }
  908. tg3_phy_set_wirespeed(tp);
  909. return 0;
  910. }
  911. static void tg3_frob_aux_power(struct tg3 *tp)
  912. {
  913. struct tg3 *tp_peer = tp;
  914. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  915. return;
  916. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  917. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  918. struct net_device *dev_peer;
  919. dev_peer = pci_get_drvdata(tp->pdev_peer);
  920. /* remove_one() may have been run on the peer. */
  921. if (!dev_peer)
  922. tp_peer = tp;
  923. else
  924. tp_peer = netdev_priv(dev_peer);
  925. }
  926. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  927. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  928. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  929. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  930. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  931. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  932. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  933. (GRC_LCLCTRL_GPIO_OE0 |
  934. GRC_LCLCTRL_GPIO_OE1 |
  935. GRC_LCLCTRL_GPIO_OE2 |
  936. GRC_LCLCTRL_GPIO_OUTPUT0 |
  937. GRC_LCLCTRL_GPIO_OUTPUT1),
  938. 100);
  939. } else {
  940. u32 no_gpio2;
  941. u32 grc_local_ctrl = 0;
  942. if (tp_peer != tp &&
  943. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  944. return;
  945. /* Workaround to prevent overdrawing Amps. */
  946. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  947. ASIC_REV_5714) {
  948. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  949. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  950. grc_local_ctrl, 100);
  951. }
  952. /* On 5753 and variants, GPIO2 cannot be used. */
  953. no_gpio2 = tp->nic_sram_data_cfg &
  954. NIC_SRAM_DATA_CFG_NO_GPIO2;
  955. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  956. GRC_LCLCTRL_GPIO_OE1 |
  957. GRC_LCLCTRL_GPIO_OE2 |
  958. GRC_LCLCTRL_GPIO_OUTPUT1 |
  959. GRC_LCLCTRL_GPIO_OUTPUT2;
  960. if (no_gpio2) {
  961. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  962. GRC_LCLCTRL_GPIO_OUTPUT2);
  963. }
  964. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  965. grc_local_ctrl, 100);
  966. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  967. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  968. grc_local_ctrl, 100);
  969. if (!no_gpio2) {
  970. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  971. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  972. grc_local_ctrl, 100);
  973. }
  974. }
  975. } else {
  976. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  977. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  978. if (tp_peer != tp &&
  979. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  980. return;
  981. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  982. (GRC_LCLCTRL_GPIO_OE1 |
  983. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  984. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  985. GRC_LCLCTRL_GPIO_OE1, 100);
  986. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  987. (GRC_LCLCTRL_GPIO_OE1 |
  988. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  989. }
  990. }
  991. }
  992. static int tg3_setup_phy(struct tg3 *, int);
  993. #define RESET_KIND_SHUTDOWN 0
  994. #define RESET_KIND_INIT 1
  995. #define RESET_KIND_SUSPEND 2
  996. static void tg3_write_sig_post_reset(struct tg3 *, int);
  997. static int tg3_halt_cpu(struct tg3 *, u32);
  998. static int tg3_nvram_lock(struct tg3 *);
  999. static void tg3_nvram_unlock(struct tg3 *);
  1000. static void tg3_power_down_phy(struct tg3 *tp)
  1001. {
  1002. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1003. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1004. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1005. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1006. sg_dig_ctrl |=
  1007. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1008. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1009. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1010. }
  1011. return;
  1012. }
  1013. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1014. u32 val;
  1015. tg3_bmcr_reset(tp);
  1016. val = tr32(GRC_MISC_CFG);
  1017. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1018. udelay(40);
  1019. return;
  1020. } else {
  1021. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1022. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1023. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1024. }
  1025. /* The PHY should not be powered down on some chips because
  1026. * of bugs.
  1027. */
  1028. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1029. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1030. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1031. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1032. return;
  1033. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1034. }
  1035. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1036. {
  1037. u32 misc_host_ctrl;
  1038. u16 power_control, power_caps;
  1039. int pm = tp->pm_cap;
  1040. /* Make sure register accesses (indirect or otherwise)
  1041. * will function correctly.
  1042. */
  1043. pci_write_config_dword(tp->pdev,
  1044. TG3PCI_MISC_HOST_CTRL,
  1045. tp->misc_host_ctrl);
  1046. pci_read_config_word(tp->pdev,
  1047. pm + PCI_PM_CTRL,
  1048. &power_control);
  1049. power_control |= PCI_PM_CTRL_PME_STATUS;
  1050. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1051. switch (state) {
  1052. case PCI_D0:
  1053. power_control |= 0;
  1054. pci_write_config_word(tp->pdev,
  1055. pm + PCI_PM_CTRL,
  1056. power_control);
  1057. udelay(100); /* Delay after power state change */
  1058. /* Switch out of Vaux if it is a NIC */
  1059. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1060. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1061. return 0;
  1062. case PCI_D1:
  1063. power_control |= 1;
  1064. break;
  1065. case PCI_D2:
  1066. power_control |= 2;
  1067. break;
  1068. case PCI_D3hot:
  1069. power_control |= 3;
  1070. break;
  1071. default:
  1072. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1073. "requested.\n",
  1074. tp->dev->name, state);
  1075. return -EINVAL;
  1076. };
  1077. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1078. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1079. tw32(TG3PCI_MISC_HOST_CTRL,
  1080. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1081. if (tp->link_config.phy_is_low_power == 0) {
  1082. tp->link_config.phy_is_low_power = 1;
  1083. tp->link_config.orig_speed = tp->link_config.speed;
  1084. tp->link_config.orig_duplex = tp->link_config.duplex;
  1085. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1086. }
  1087. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1088. tp->link_config.speed = SPEED_10;
  1089. tp->link_config.duplex = DUPLEX_HALF;
  1090. tp->link_config.autoneg = AUTONEG_ENABLE;
  1091. tg3_setup_phy(tp, 0);
  1092. }
  1093. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1094. u32 val;
  1095. val = tr32(GRC_VCPU_EXT_CTRL);
  1096. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1097. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1098. int i;
  1099. u32 val;
  1100. for (i = 0; i < 200; i++) {
  1101. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1102. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1103. break;
  1104. msleep(1);
  1105. }
  1106. }
  1107. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  1108. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1109. WOL_DRV_STATE_SHUTDOWN |
  1110. WOL_DRV_WOL |
  1111. WOL_SET_MAGIC_PKT);
  1112. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1113. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1114. u32 mac_mode;
  1115. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1116. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1117. udelay(40);
  1118. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1119. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1120. else
  1121. mac_mode = MAC_MODE_PORT_MODE_MII;
  1122. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
  1123. !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
  1124. mac_mode |= MAC_MODE_LINK_POLARITY;
  1125. } else {
  1126. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1127. }
  1128. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1129. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1130. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1131. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1132. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1133. tw32_f(MAC_MODE, mac_mode);
  1134. udelay(100);
  1135. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1136. udelay(10);
  1137. }
  1138. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1139. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1140. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1141. u32 base_val;
  1142. base_val = tp->pci_clock_ctrl;
  1143. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1144. CLOCK_CTRL_TXCLK_DISABLE);
  1145. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1146. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1147. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1148. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1149. /* do nothing */
  1150. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1151. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1152. u32 newbits1, newbits2;
  1153. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1154. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1155. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1156. CLOCK_CTRL_TXCLK_DISABLE |
  1157. CLOCK_CTRL_ALTCLK);
  1158. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1159. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1160. newbits1 = CLOCK_CTRL_625_CORE;
  1161. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1162. } else {
  1163. newbits1 = CLOCK_CTRL_ALTCLK;
  1164. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1165. }
  1166. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1167. 40);
  1168. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1169. 40);
  1170. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1171. u32 newbits3;
  1172. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1173. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1174. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1175. CLOCK_CTRL_TXCLK_DISABLE |
  1176. CLOCK_CTRL_44MHZ_CORE);
  1177. } else {
  1178. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1179. }
  1180. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1181. tp->pci_clock_ctrl | newbits3, 40);
  1182. }
  1183. }
  1184. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1185. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  1186. tg3_power_down_phy(tp);
  1187. tg3_frob_aux_power(tp);
  1188. /* Workaround for unstable PLL clock */
  1189. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1190. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1191. u32 val = tr32(0x7d00);
  1192. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1193. tw32(0x7d00, val);
  1194. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1195. int err;
  1196. err = tg3_nvram_lock(tp);
  1197. tg3_halt_cpu(tp, RX_CPU_BASE);
  1198. if (!err)
  1199. tg3_nvram_unlock(tp);
  1200. }
  1201. }
  1202. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1203. /* Finally, set the new power state. */
  1204. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1205. udelay(100); /* Delay after power state change */
  1206. return 0;
  1207. }
  1208. static void tg3_link_report(struct tg3 *tp)
  1209. {
  1210. if (!netif_carrier_ok(tp->dev)) {
  1211. if (netif_msg_link(tp))
  1212. printk(KERN_INFO PFX "%s: Link is down.\n",
  1213. tp->dev->name);
  1214. } else if (netif_msg_link(tp)) {
  1215. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1216. tp->dev->name,
  1217. (tp->link_config.active_speed == SPEED_1000 ?
  1218. 1000 :
  1219. (tp->link_config.active_speed == SPEED_100 ?
  1220. 100 : 10)),
  1221. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1222. "full" : "half"));
  1223. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1224. "%s for RX.\n",
  1225. tp->dev->name,
  1226. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1227. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1228. }
  1229. }
  1230. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1231. {
  1232. u32 new_tg3_flags = 0;
  1233. u32 old_rx_mode = tp->rx_mode;
  1234. u32 old_tx_mode = tp->tx_mode;
  1235. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1236. /* Convert 1000BaseX flow control bits to 1000BaseT
  1237. * bits before resolving flow control.
  1238. */
  1239. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1240. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1241. ADVERTISE_PAUSE_ASYM);
  1242. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1243. if (local_adv & ADVERTISE_1000XPAUSE)
  1244. local_adv |= ADVERTISE_PAUSE_CAP;
  1245. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1246. local_adv |= ADVERTISE_PAUSE_ASYM;
  1247. if (remote_adv & LPA_1000XPAUSE)
  1248. remote_adv |= LPA_PAUSE_CAP;
  1249. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1250. remote_adv |= LPA_PAUSE_ASYM;
  1251. }
  1252. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1253. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1254. if (remote_adv & LPA_PAUSE_CAP)
  1255. new_tg3_flags |=
  1256. (TG3_FLAG_RX_PAUSE |
  1257. TG3_FLAG_TX_PAUSE);
  1258. else if (remote_adv & LPA_PAUSE_ASYM)
  1259. new_tg3_flags |=
  1260. (TG3_FLAG_RX_PAUSE);
  1261. } else {
  1262. if (remote_adv & LPA_PAUSE_CAP)
  1263. new_tg3_flags |=
  1264. (TG3_FLAG_RX_PAUSE |
  1265. TG3_FLAG_TX_PAUSE);
  1266. }
  1267. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1268. if ((remote_adv & LPA_PAUSE_CAP) &&
  1269. (remote_adv & LPA_PAUSE_ASYM))
  1270. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1271. }
  1272. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1273. tp->tg3_flags |= new_tg3_flags;
  1274. } else {
  1275. new_tg3_flags = tp->tg3_flags;
  1276. }
  1277. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1278. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1279. else
  1280. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1281. if (old_rx_mode != tp->rx_mode) {
  1282. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1283. }
  1284. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1285. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1286. else
  1287. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1288. if (old_tx_mode != tp->tx_mode) {
  1289. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1290. }
  1291. }
  1292. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1293. {
  1294. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1295. case MII_TG3_AUX_STAT_10HALF:
  1296. *speed = SPEED_10;
  1297. *duplex = DUPLEX_HALF;
  1298. break;
  1299. case MII_TG3_AUX_STAT_10FULL:
  1300. *speed = SPEED_10;
  1301. *duplex = DUPLEX_FULL;
  1302. break;
  1303. case MII_TG3_AUX_STAT_100HALF:
  1304. *speed = SPEED_100;
  1305. *duplex = DUPLEX_HALF;
  1306. break;
  1307. case MII_TG3_AUX_STAT_100FULL:
  1308. *speed = SPEED_100;
  1309. *duplex = DUPLEX_FULL;
  1310. break;
  1311. case MII_TG3_AUX_STAT_1000HALF:
  1312. *speed = SPEED_1000;
  1313. *duplex = DUPLEX_HALF;
  1314. break;
  1315. case MII_TG3_AUX_STAT_1000FULL:
  1316. *speed = SPEED_1000;
  1317. *duplex = DUPLEX_FULL;
  1318. break;
  1319. default:
  1320. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1321. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1322. SPEED_10;
  1323. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1324. DUPLEX_HALF;
  1325. break;
  1326. }
  1327. *speed = SPEED_INVALID;
  1328. *duplex = DUPLEX_INVALID;
  1329. break;
  1330. };
  1331. }
  1332. static void tg3_phy_copper_begin(struct tg3 *tp)
  1333. {
  1334. u32 new_adv;
  1335. int i;
  1336. if (tp->link_config.phy_is_low_power) {
  1337. /* Entering low power mode. Disable gigabit and
  1338. * 100baseT advertisements.
  1339. */
  1340. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1341. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1342. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1343. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1344. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1345. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1346. } else if (tp->link_config.speed == SPEED_INVALID) {
  1347. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1348. tp->link_config.advertising &=
  1349. ~(ADVERTISED_1000baseT_Half |
  1350. ADVERTISED_1000baseT_Full);
  1351. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1352. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1353. new_adv |= ADVERTISE_10HALF;
  1354. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1355. new_adv |= ADVERTISE_10FULL;
  1356. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1357. new_adv |= ADVERTISE_100HALF;
  1358. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1359. new_adv |= ADVERTISE_100FULL;
  1360. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1361. if (tp->link_config.advertising &
  1362. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1363. new_adv = 0;
  1364. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1365. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1366. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1367. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1368. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1369. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1370. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1371. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1372. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1373. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1374. } else {
  1375. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1376. }
  1377. } else {
  1378. /* Asking for a specific link mode. */
  1379. if (tp->link_config.speed == SPEED_1000) {
  1380. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1381. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1382. if (tp->link_config.duplex == DUPLEX_FULL)
  1383. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1384. else
  1385. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1386. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1387. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1388. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1389. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1390. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1391. } else {
  1392. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1393. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1394. if (tp->link_config.speed == SPEED_100) {
  1395. if (tp->link_config.duplex == DUPLEX_FULL)
  1396. new_adv |= ADVERTISE_100FULL;
  1397. else
  1398. new_adv |= ADVERTISE_100HALF;
  1399. } else {
  1400. if (tp->link_config.duplex == DUPLEX_FULL)
  1401. new_adv |= ADVERTISE_10FULL;
  1402. else
  1403. new_adv |= ADVERTISE_10HALF;
  1404. }
  1405. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1406. }
  1407. }
  1408. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1409. tp->link_config.speed != SPEED_INVALID) {
  1410. u32 bmcr, orig_bmcr;
  1411. tp->link_config.active_speed = tp->link_config.speed;
  1412. tp->link_config.active_duplex = tp->link_config.duplex;
  1413. bmcr = 0;
  1414. switch (tp->link_config.speed) {
  1415. default:
  1416. case SPEED_10:
  1417. break;
  1418. case SPEED_100:
  1419. bmcr |= BMCR_SPEED100;
  1420. break;
  1421. case SPEED_1000:
  1422. bmcr |= TG3_BMCR_SPEED1000;
  1423. break;
  1424. };
  1425. if (tp->link_config.duplex == DUPLEX_FULL)
  1426. bmcr |= BMCR_FULLDPLX;
  1427. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1428. (bmcr != orig_bmcr)) {
  1429. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1430. for (i = 0; i < 1500; i++) {
  1431. u32 tmp;
  1432. udelay(10);
  1433. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1434. tg3_readphy(tp, MII_BMSR, &tmp))
  1435. continue;
  1436. if (!(tmp & BMSR_LSTATUS)) {
  1437. udelay(40);
  1438. break;
  1439. }
  1440. }
  1441. tg3_writephy(tp, MII_BMCR, bmcr);
  1442. udelay(40);
  1443. }
  1444. } else {
  1445. tg3_writephy(tp, MII_BMCR,
  1446. BMCR_ANENABLE | BMCR_ANRESTART);
  1447. }
  1448. }
  1449. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1450. {
  1451. int err;
  1452. /* Turn off tap power management. */
  1453. /* Set Extended packet length bit */
  1454. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1455. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1456. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1457. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1458. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1459. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1460. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1461. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1462. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1463. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1464. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1465. udelay(40);
  1466. return err;
  1467. }
  1468. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1469. {
  1470. u32 adv_reg, all_mask = 0;
  1471. if (mask & ADVERTISED_10baseT_Half)
  1472. all_mask |= ADVERTISE_10HALF;
  1473. if (mask & ADVERTISED_10baseT_Full)
  1474. all_mask |= ADVERTISE_10FULL;
  1475. if (mask & ADVERTISED_100baseT_Half)
  1476. all_mask |= ADVERTISE_100HALF;
  1477. if (mask & ADVERTISED_100baseT_Full)
  1478. all_mask |= ADVERTISE_100FULL;
  1479. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1480. return 0;
  1481. if ((adv_reg & all_mask) != all_mask)
  1482. return 0;
  1483. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1484. u32 tg3_ctrl;
  1485. all_mask = 0;
  1486. if (mask & ADVERTISED_1000baseT_Half)
  1487. all_mask |= ADVERTISE_1000HALF;
  1488. if (mask & ADVERTISED_1000baseT_Full)
  1489. all_mask |= ADVERTISE_1000FULL;
  1490. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1491. return 0;
  1492. if ((tg3_ctrl & all_mask) != all_mask)
  1493. return 0;
  1494. }
  1495. return 1;
  1496. }
  1497. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1498. {
  1499. int current_link_up;
  1500. u32 bmsr, dummy;
  1501. u16 current_speed;
  1502. u8 current_duplex;
  1503. int i, err;
  1504. tw32(MAC_EVENT, 0);
  1505. tw32_f(MAC_STATUS,
  1506. (MAC_STATUS_SYNC_CHANGED |
  1507. MAC_STATUS_CFG_CHANGED |
  1508. MAC_STATUS_MI_COMPLETION |
  1509. MAC_STATUS_LNKSTATE_CHANGED));
  1510. udelay(40);
  1511. tp->mi_mode = MAC_MI_MODE_BASE;
  1512. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1513. udelay(80);
  1514. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1515. /* Some third-party PHYs need to be reset on link going
  1516. * down.
  1517. */
  1518. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1519. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1520. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1521. netif_carrier_ok(tp->dev)) {
  1522. tg3_readphy(tp, MII_BMSR, &bmsr);
  1523. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1524. !(bmsr & BMSR_LSTATUS))
  1525. force_reset = 1;
  1526. }
  1527. if (force_reset)
  1528. tg3_phy_reset(tp);
  1529. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1530. tg3_readphy(tp, MII_BMSR, &bmsr);
  1531. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1532. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1533. bmsr = 0;
  1534. if (!(bmsr & BMSR_LSTATUS)) {
  1535. err = tg3_init_5401phy_dsp(tp);
  1536. if (err)
  1537. return err;
  1538. tg3_readphy(tp, MII_BMSR, &bmsr);
  1539. for (i = 0; i < 1000; i++) {
  1540. udelay(10);
  1541. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1542. (bmsr & BMSR_LSTATUS)) {
  1543. udelay(40);
  1544. break;
  1545. }
  1546. }
  1547. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1548. !(bmsr & BMSR_LSTATUS) &&
  1549. tp->link_config.active_speed == SPEED_1000) {
  1550. err = tg3_phy_reset(tp);
  1551. if (!err)
  1552. err = tg3_init_5401phy_dsp(tp);
  1553. if (err)
  1554. return err;
  1555. }
  1556. }
  1557. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1558. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1559. /* 5701 {A0,B0} CRC bug workaround */
  1560. tg3_writephy(tp, 0x15, 0x0a75);
  1561. tg3_writephy(tp, 0x1c, 0x8c68);
  1562. tg3_writephy(tp, 0x1c, 0x8d68);
  1563. tg3_writephy(tp, 0x1c, 0x8c68);
  1564. }
  1565. /* Clear pending interrupts... */
  1566. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1567. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1568. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1569. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1570. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1571. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1572. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1573. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1574. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1575. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1576. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1577. else
  1578. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1579. }
  1580. current_link_up = 0;
  1581. current_speed = SPEED_INVALID;
  1582. current_duplex = DUPLEX_INVALID;
  1583. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1584. u32 val;
  1585. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1586. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1587. if (!(val & (1 << 10))) {
  1588. val |= (1 << 10);
  1589. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1590. goto relink;
  1591. }
  1592. }
  1593. bmsr = 0;
  1594. for (i = 0; i < 100; i++) {
  1595. tg3_readphy(tp, MII_BMSR, &bmsr);
  1596. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1597. (bmsr & BMSR_LSTATUS))
  1598. break;
  1599. udelay(40);
  1600. }
  1601. if (bmsr & BMSR_LSTATUS) {
  1602. u32 aux_stat, bmcr;
  1603. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1604. for (i = 0; i < 2000; i++) {
  1605. udelay(10);
  1606. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1607. aux_stat)
  1608. break;
  1609. }
  1610. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1611. &current_speed,
  1612. &current_duplex);
  1613. bmcr = 0;
  1614. for (i = 0; i < 200; i++) {
  1615. tg3_readphy(tp, MII_BMCR, &bmcr);
  1616. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1617. continue;
  1618. if (bmcr && bmcr != 0x7fff)
  1619. break;
  1620. udelay(10);
  1621. }
  1622. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1623. if (bmcr & BMCR_ANENABLE) {
  1624. current_link_up = 1;
  1625. /* Force autoneg restart if we are exiting
  1626. * low power mode.
  1627. */
  1628. if (!tg3_copper_is_advertising_all(tp,
  1629. tp->link_config.advertising))
  1630. current_link_up = 0;
  1631. } else {
  1632. current_link_up = 0;
  1633. }
  1634. } else {
  1635. if (!(bmcr & BMCR_ANENABLE) &&
  1636. tp->link_config.speed == current_speed &&
  1637. tp->link_config.duplex == current_duplex) {
  1638. current_link_up = 1;
  1639. } else {
  1640. current_link_up = 0;
  1641. }
  1642. }
  1643. tp->link_config.active_speed = current_speed;
  1644. tp->link_config.active_duplex = current_duplex;
  1645. }
  1646. if (current_link_up == 1 &&
  1647. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1648. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1649. u32 local_adv, remote_adv;
  1650. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1651. local_adv = 0;
  1652. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1653. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1654. remote_adv = 0;
  1655. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1656. /* If we are not advertising full pause capability,
  1657. * something is wrong. Bring the link down and reconfigure.
  1658. */
  1659. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1660. current_link_up = 0;
  1661. } else {
  1662. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1663. }
  1664. }
  1665. relink:
  1666. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1667. u32 tmp;
  1668. tg3_phy_copper_begin(tp);
  1669. tg3_readphy(tp, MII_BMSR, &tmp);
  1670. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1671. (tmp & BMSR_LSTATUS))
  1672. current_link_up = 1;
  1673. }
  1674. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1675. if (current_link_up == 1) {
  1676. if (tp->link_config.active_speed == SPEED_100 ||
  1677. tp->link_config.active_speed == SPEED_10)
  1678. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1679. else
  1680. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1681. } else
  1682. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1683. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1684. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1685. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1686. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1687. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1688. if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) ||
  1689. (current_link_up == 1 &&
  1690. tp->link_config.active_speed == SPEED_10))
  1691. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1692. } else {
  1693. if (current_link_up == 1)
  1694. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1695. }
  1696. /* ??? Without this setting Netgear GA302T PHY does not
  1697. * ??? send/receive packets...
  1698. */
  1699. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1700. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1701. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1702. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1703. udelay(80);
  1704. }
  1705. tw32_f(MAC_MODE, tp->mac_mode);
  1706. udelay(40);
  1707. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1708. /* Polled via timer. */
  1709. tw32_f(MAC_EVENT, 0);
  1710. } else {
  1711. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1712. }
  1713. udelay(40);
  1714. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1715. current_link_up == 1 &&
  1716. tp->link_config.active_speed == SPEED_1000 &&
  1717. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1718. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1719. udelay(120);
  1720. tw32_f(MAC_STATUS,
  1721. (MAC_STATUS_SYNC_CHANGED |
  1722. MAC_STATUS_CFG_CHANGED));
  1723. udelay(40);
  1724. tg3_write_mem(tp,
  1725. NIC_SRAM_FIRMWARE_MBOX,
  1726. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1727. }
  1728. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1729. if (current_link_up)
  1730. netif_carrier_on(tp->dev);
  1731. else
  1732. netif_carrier_off(tp->dev);
  1733. tg3_link_report(tp);
  1734. }
  1735. return 0;
  1736. }
  1737. struct tg3_fiber_aneginfo {
  1738. int state;
  1739. #define ANEG_STATE_UNKNOWN 0
  1740. #define ANEG_STATE_AN_ENABLE 1
  1741. #define ANEG_STATE_RESTART_INIT 2
  1742. #define ANEG_STATE_RESTART 3
  1743. #define ANEG_STATE_DISABLE_LINK_OK 4
  1744. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1745. #define ANEG_STATE_ABILITY_DETECT 6
  1746. #define ANEG_STATE_ACK_DETECT_INIT 7
  1747. #define ANEG_STATE_ACK_DETECT 8
  1748. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1749. #define ANEG_STATE_COMPLETE_ACK 10
  1750. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1751. #define ANEG_STATE_IDLE_DETECT 12
  1752. #define ANEG_STATE_LINK_OK 13
  1753. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1754. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1755. u32 flags;
  1756. #define MR_AN_ENABLE 0x00000001
  1757. #define MR_RESTART_AN 0x00000002
  1758. #define MR_AN_COMPLETE 0x00000004
  1759. #define MR_PAGE_RX 0x00000008
  1760. #define MR_NP_LOADED 0x00000010
  1761. #define MR_TOGGLE_TX 0x00000020
  1762. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1763. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1764. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1765. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1766. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1767. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1768. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1769. #define MR_TOGGLE_RX 0x00002000
  1770. #define MR_NP_RX 0x00004000
  1771. #define MR_LINK_OK 0x80000000
  1772. unsigned long link_time, cur_time;
  1773. u32 ability_match_cfg;
  1774. int ability_match_count;
  1775. char ability_match, idle_match, ack_match;
  1776. u32 txconfig, rxconfig;
  1777. #define ANEG_CFG_NP 0x00000080
  1778. #define ANEG_CFG_ACK 0x00000040
  1779. #define ANEG_CFG_RF2 0x00000020
  1780. #define ANEG_CFG_RF1 0x00000010
  1781. #define ANEG_CFG_PS2 0x00000001
  1782. #define ANEG_CFG_PS1 0x00008000
  1783. #define ANEG_CFG_HD 0x00004000
  1784. #define ANEG_CFG_FD 0x00002000
  1785. #define ANEG_CFG_INVAL 0x00001f06
  1786. };
  1787. #define ANEG_OK 0
  1788. #define ANEG_DONE 1
  1789. #define ANEG_TIMER_ENAB 2
  1790. #define ANEG_FAILED -1
  1791. #define ANEG_STATE_SETTLE_TIME 10000
  1792. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1793. struct tg3_fiber_aneginfo *ap)
  1794. {
  1795. unsigned long delta;
  1796. u32 rx_cfg_reg;
  1797. int ret;
  1798. if (ap->state == ANEG_STATE_UNKNOWN) {
  1799. ap->rxconfig = 0;
  1800. ap->link_time = 0;
  1801. ap->cur_time = 0;
  1802. ap->ability_match_cfg = 0;
  1803. ap->ability_match_count = 0;
  1804. ap->ability_match = 0;
  1805. ap->idle_match = 0;
  1806. ap->ack_match = 0;
  1807. }
  1808. ap->cur_time++;
  1809. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1810. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1811. if (rx_cfg_reg != ap->ability_match_cfg) {
  1812. ap->ability_match_cfg = rx_cfg_reg;
  1813. ap->ability_match = 0;
  1814. ap->ability_match_count = 0;
  1815. } else {
  1816. if (++ap->ability_match_count > 1) {
  1817. ap->ability_match = 1;
  1818. ap->ability_match_cfg = rx_cfg_reg;
  1819. }
  1820. }
  1821. if (rx_cfg_reg & ANEG_CFG_ACK)
  1822. ap->ack_match = 1;
  1823. else
  1824. ap->ack_match = 0;
  1825. ap->idle_match = 0;
  1826. } else {
  1827. ap->idle_match = 1;
  1828. ap->ability_match_cfg = 0;
  1829. ap->ability_match_count = 0;
  1830. ap->ability_match = 0;
  1831. ap->ack_match = 0;
  1832. rx_cfg_reg = 0;
  1833. }
  1834. ap->rxconfig = rx_cfg_reg;
  1835. ret = ANEG_OK;
  1836. switch(ap->state) {
  1837. case ANEG_STATE_UNKNOWN:
  1838. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1839. ap->state = ANEG_STATE_AN_ENABLE;
  1840. /* fallthru */
  1841. case ANEG_STATE_AN_ENABLE:
  1842. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1843. if (ap->flags & MR_AN_ENABLE) {
  1844. ap->link_time = 0;
  1845. ap->cur_time = 0;
  1846. ap->ability_match_cfg = 0;
  1847. ap->ability_match_count = 0;
  1848. ap->ability_match = 0;
  1849. ap->idle_match = 0;
  1850. ap->ack_match = 0;
  1851. ap->state = ANEG_STATE_RESTART_INIT;
  1852. } else {
  1853. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1854. }
  1855. break;
  1856. case ANEG_STATE_RESTART_INIT:
  1857. ap->link_time = ap->cur_time;
  1858. ap->flags &= ~(MR_NP_LOADED);
  1859. ap->txconfig = 0;
  1860. tw32(MAC_TX_AUTO_NEG, 0);
  1861. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1862. tw32_f(MAC_MODE, tp->mac_mode);
  1863. udelay(40);
  1864. ret = ANEG_TIMER_ENAB;
  1865. ap->state = ANEG_STATE_RESTART;
  1866. /* fallthru */
  1867. case ANEG_STATE_RESTART:
  1868. delta = ap->cur_time - ap->link_time;
  1869. if (delta > ANEG_STATE_SETTLE_TIME) {
  1870. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1871. } else {
  1872. ret = ANEG_TIMER_ENAB;
  1873. }
  1874. break;
  1875. case ANEG_STATE_DISABLE_LINK_OK:
  1876. ret = ANEG_DONE;
  1877. break;
  1878. case ANEG_STATE_ABILITY_DETECT_INIT:
  1879. ap->flags &= ~(MR_TOGGLE_TX);
  1880. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1881. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1882. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1883. tw32_f(MAC_MODE, tp->mac_mode);
  1884. udelay(40);
  1885. ap->state = ANEG_STATE_ABILITY_DETECT;
  1886. break;
  1887. case ANEG_STATE_ABILITY_DETECT:
  1888. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1889. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1890. }
  1891. break;
  1892. case ANEG_STATE_ACK_DETECT_INIT:
  1893. ap->txconfig |= ANEG_CFG_ACK;
  1894. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1895. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1896. tw32_f(MAC_MODE, tp->mac_mode);
  1897. udelay(40);
  1898. ap->state = ANEG_STATE_ACK_DETECT;
  1899. /* fallthru */
  1900. case ANEG_STATE_ACK_DETECT:
  1901. if (ap->ack_match != 0) {
  1902. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1903. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1904. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1905. } else {
  1906. ap->state = ANEG_STATE_AN_ENABLE;
  1907. }
  1908. } else if (ap->ability_match != 0 &&
  1909. ap->rxconfig == 0) {
  1910. ap->state = ANEG_STATE_AN_ENABLE;
  1911. }
  1912. break;
  1913. case ANEG_STATE_COMPLETE_ACK_INIT:
  1914. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1915. ret = ANEG_FAILED;
  1916. break;
  1917. }
  1918. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1919. MR_LP_ADV_HALF_DUPLEX |
  1920. MR_LP_ADV_SYM_PAUSE |
  1921. MR_LP_ADV_ASYM_PAUSE |
  1922. MR_LP_ADV_REMOTE_FAULT1 |
  1923. MR_LP_ADV_REMOTE_FAULT2 |
  1924. MR_LP_ADV_NEXT_PAGE |
  1925. MR_TOGGLE_RX |
  1926. MR_NP_RX);
  1927. if (ap->rxconfig & ANEG_CFG_FD)
  1928. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1929. if (ap->rxconfig & ANEG_CFG_HD)
  1930. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1931. if (ap->rxconfig & ANEG_CFG_PS1)
  1932. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1933. if (ap->rxconfig & ANEG_CFG_PS2)
  1934. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1935. if (ap->rxconfig & ANEG_CFG_RF1)
  1936. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1937. if (ap->rxconfig & ANEG_CFG_RF2)
  1938. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1939. if (ap->rxconfig & ANEG_CFG_NP)
  1940. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1941. ap->link_time = ap->cur_time;
  1942. ap->flags ^= (MR_TOGGLE_TX);
  1943. if (ap->rxconfig & 0x0008)
  1944. ap->flags |= MR_TOGGLE_RX;
  1945. if (ap->rxconfig & ANEG_CFG_NP)
  1946. ap->flags |= MR_NP_RX;
  1947. ap->flags |= MR_PAGE_RX;
  1948. ap->state = ANEG_STATE_COMPLETE_ACK;
  1949. ret = ANEG_TIMER_ENAB;
  1950. break;
  1951. case ANEG_STATE_COMPLETE_ACK:
  1952. if (ap->ability_match != 0 &&
  1953. ap->rxconfig == 0) {
  1954. ap->state = ANEG_STATE_AN_ENABLE;
  1955. break;
  1956. }
  1957. delta = ap->cur_time - ap->link_time;
  1958. if (delta > ANEG_STATE_SETTLE_TIME) {
  1959. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  1960. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1961. } else {
  1962. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  1963. !(ap->flags & MR_NP_RX)) {
  1964. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  1965. } else {
  1966. ret = ANEG_FAILED;
  1967. }
  1968. }
  1969. }
  1970. break;
  1971. case ANEG_STATE_IDLE_DETECT_INIT:
  1972. ap->link_time = ap->cur_time;
  1973. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  1974. tw32_f(MAC_MODE, tp->mac_mode);
  1975. udelay(40);
  1976. ap->state = ANEG_STATE_IDLE_DETECT;
  1977. ret = ANEG_TIMER_ENAB;
  1978. break;
  1979. case ANEG_STATE_IDLE_DETECT:
  1980. if (ap->ability_match != 0 &&
  1981. ap->rxconfig == 0) {
  1982. ap->state = ANEG_STATE_AN_ENABLE;
  1983. break;
  1984. }
  1985. delta = ap->cur_time - ap->link_time;
  1986. if (delta > ANEG_STATE_SETTLE_TIME) {
  1987. /* XXX another gem from the Broadcom driver :( */
  1988. ap->state = ANEG_STATE_LINK_OK;
  1989. }
  1990. break;
  1991. case ANEG_STATE_LINK_OK:
  1992. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  1993. ret = ANEG_DONE;
  1994. break;
  1995. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  1996. /* ??? unimplemented */
  1997. break;
  1998. case ANEG_STATE_NEXT_PAGE_WAIT:
  1999. /* ??? unimplemented */
  2000. break;
  2001. default:
  2002. ret = ANEG_FAILED;
  2003. break;
  2004. };
  2005. return ret;
  2006. }
  2007. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  2008. {
  2009. int res = 0;
  2010. struct tg3_fiber_aneginfo aninfo;
  2011. int status = ANEG_FAILED;
  2012. unsigned int tick;
  2013. u32 tmp;
  2014. tw32_f(MAC_TX_AUTO_NEG, 0);
  2015. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2016. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2017. udelay(40);
  2018. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2019. udelay(40);
  2020. memset(&aninfo, 0, sizeof(aninfo));
  2021. aninfo.flags |= MR_AN_ENABLE;
  2022. aninfo.state = ANEG_STATE_UNKNOWN;
  2023. aninfo.cur_time = 0;
  2024. tick = 0;
  2025. while (++tick < 195000) {
  2026. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2027. if (status == ANEG_DONE || status == ANEG_FAILED)
  2028. break;
  2029. udelay(1);
  2030. }
  2031. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2032. tw32_f(MAC_MODE, tp->mac_mode);
  2033. udelay(40);
  2034. *flags = aninfo.flags;
  2035. if (status == ANEG_DONE &&
  2036. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2037. MR_LP_ADV_FULL_DUPLEX)))
  2038. res = 1;
  2039. return res;
  2040. }
  2041. static void tg3_init_bcm8002(struct tg3 *tp)
  2042. {
  2043. u32 mac_status = tr32(MAC_STATUS);
  2044. int i;
  2045. /* Reset when initting first time or we have a link. */
  2046. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2047. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2048. return;
  2049. /* Set PLL lock range. */
  2050. tg3_writephy(tp, 0x16, 0x8007);
  2051. /* SW reset */
  2052. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2053. /* Wait for reset to complete. */
  2054. /* XXX schedule_timeout() ... */
  2055. for (i = 0; i < 500; i++)
  2056. udelay(10);
  2057. /* Config mode; select PMA/Ch 1 regs. */
  2058. tg3_writephy(tp, 0x10, 0x8411);
  2059. /* Enable auto-lock and comdet, select txclk for tx. */
  2060. tg3_writephy(tp, 0x11, 0x0a10);
  2061. tg3_writephy(tp, 0x18, 0x00a0);
  2062. tg3_writephy(tp, 0x16, 0x41ff);
  2063. /* Assert and deassert POR. */
  2064. tg3_writephy(tp, 0x13, 0x0400);
  2065. udelay(40);
  2066. tg3_writephy(tp, 0x13, 0x0000);
  2067. tg3_writephy(tp, 0x11, 0x0a50);
  2068. udelay(40);
  2069. tg3_writephy(tp, 0x11, 0x0a10);
  2070. /* Wait for signal to stabilize */
  2071. /* XXX schedule_timeout() ... */
  2072. for (i = 0; i < 15000; i++)
  2073. udelay(10);
  2074. /* Deselect the channel register so we can read the PHYID
  2075. * later.
  2076. */
  2077. tg3_writephy(tp, 0x10, 0x8011);
  2078. }
  2079. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2080. {
  2081. u32 sg_dig_ctrl, sg_dig_status;
  2082. u32 serdes_cfg, expected_sg_dig_ctrl;
  2083. int workaround, port_a;
  2084. int current_link_up;
  2085. serdes_cfg = 0;
  2086. expected_sg_dig_ctrl = 0;
  2087. workaround = 0;
  2088. port_a = 1;
  2089. current_link_up = 0;
  2090. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2091. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2092. workaround = 1;
  2093. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2094. port_a = 0;
  2095. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2096. /* preserve bits 20-23 for voltage regulator */
  2097. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2098. }
  2099. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2100. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2101. if (sg_dig_ctrl & (1 << 31)) {
  2102. if (workaround) {
  2103. u32 val = serdes_cfg;
  2104. if (port_a)
  2105. val |= 0xc010000;
  2106. else
  2107. val |= 0x4010000;
  2108. tw32_f(MAC_SERDES_CFG, val);
  2109. }
  2110. tw32_f(SG_DIG_CTRL, 0x01388400);
  2111. }
  2112. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2113. tg3_setup_flow_control(tp, 0, 0);
  2114. current_link_up = 1;
  2115. }
  2116. goto out;
  2117. }
  2118. /* Want auto-negotiation. */
  2119. expected_sg_dig_ctrl = 0x81388400;
  2120. /* Pause capability */
  2121. expected_sg_dig_ctrl |= (1 << 11);
  2122. /* Asymettric pause */
  2123. expected_sg_dig_ctrl |= (1 << 12);
  2124. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2125. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2126. tp->serdes_counter &&
  2127. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2128. MAC_STATUS_RCVD_CFG)) ==
  2129. MAC_STATUS_PCS_SYNCED)) {
  2130. tp->serdes_counter--;
  2131. current_link_up = 1;
  2132. goto out;
  2133. }
  2134. restart_autoneg:
  2135. if (workaround)
  2136. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2137. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2138. udelay(5);
  2139. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2140. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2141. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2142. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2143. MAC_STATUS_SIGNAL_DET)) {
  2144. sg_dig_status = tr32(SG_DIG_STATUS);
  2145. mac_status = tr32(MAC_STATUS);
  2146. if ((sg_dig_status & (1 << 1)) &&
  2147. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2148. u32 local_adv, remote_adv;
  2149. local_adv = ADVERTISE_PAUSE_CAP;
  2150. remote_adv = 0;
  2151. if (sg_dig_status & (1 << 19))
  2152. remote_adv |= LPA_PAUSE_CAP;
  2153. if (sg_dig_status & (1 << 20))
  2154. remote_adv |= LPA_PAUSE_ASYM;
  2155. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2156. current_link_up = 1;
  2157. tp->serdes_counter = 0;
  2158. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2159. } else if (!(sg_dig_status & (1 << 1))) {
  2160. if (tp->serdes_counter)
  2161. tp->serdes_counter--;
  2162. else {
  2163. if (workaround) {
  2164. u32 val = serdes_cfg;
  2165. if (port_a)
  2166. val |= 0xc010000;
  2167. else
  2168. val |= 0x4010000;
  2169. tw32_f(MAC_SERDES_CFG, val);
  2170. }
  2171. tw32_f(SG_DIG_CTRL, 0x01388400);
  2172. udelay(40);
  2173. /* Link parallel detection - link is up */
  2174. /* only if we have PCS_SYNC and not */
  2175. /* receiving config code words */
  2176. mac_status = tr32(MAC_STATUS);
  2177. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2178. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2179. tg3_setup_flow_control(tp, 0, 0);
  2180. current_link_up = 1;
  2181. tp->tg3_flags2 |=
  2182. TG3_FLG2_PARALLEL_DETECT;
  2183. tp->serdes_counter =
  2184. SERDES_PARALLEL_DET_TIMEOUT;
  2185. } else
  2186. goto restart_autoneg;
  2187. }
  2188. }
  2189. } else {
  2190. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2191. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2192. }
  2193. out:
  2194. return current_link_up;
  2195. }
  2196. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2197. {
  2198. int current_link_up = 0;
  2199. if (!(mac_status & MAC_STATUS_PCS_SYNCED))
  2200. goto out;
  2201. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2202. u32 flags;
  2203. int i;
  2204. if (fiber_autoneg(tp, &flags)) {
  2205. u32 local_adv, remote_adv;
  2206. local_adv = ADVERTISE_PAUSE_CAP;
  2207. remote_adv = 0;
  2208. if (flags & MR_LP_ADV_SYM_PAUSE)
  2209. remote_adv |= LPA_PAUSE_CAP;
  2210. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2211. remote_adv |= LPA_PAUSE_ASYM;
  2212. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2213. current_link_up = 1;
  2214. }
  2215. for (i = 0; i < 30; i++) {
  2216. udelay(20);
  2217. tw32_f(MAC_STATUS,
  2218. (MAC_STATUS_SYNC_CHANGED |
  2219. MAC_STATUS_CFG_CHANGED));
  2220. udelay(40);
  2221. if ((tr32(MAC_STATUS) &
  2222. (MAC_STATUS_SYNC_CHANGED |
  2223. MAC_STATUS_CFG_CHANGED)) == 0)
  2224. break;
  2225. }
  2226. mac_status = tr32(MAC_STATUS);
  2227. if (current_link_up == 0 &&
  2228. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2229. !(mac_status & MAC_STATUS_RCVD_CFG))
  2230. current_link_up = 1;
  2231. } else {
  2232. /* Forcing 1000FD link up. */
  2233. current_link_up = 1;
  2234. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2235. udelay(40);
  2236. }
  2237. out:
  2238. return current_link_up;
  2239. }
  2240. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2241. {
  2242. u32 orig_pause_cfg;
  2243. u16 orig_active_speed;
  2244. u8 orig_active_duplex;
  2245. u32 mac_status;
  2246. int current_link_up;
  2247. int i;
  2248. orig_pause_cfg =
  2249. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2250. TG3_FLAG_TX_PAUSE));
  2251. orig_active_speed = tp->link_config.active_speed;
  2252. orig_active_duplex = tp->link_config.active_duplex;
  2253. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2254. netif_carrier_ok(tp->dev) &&
  2255. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2256. mac_status = tr32(MAC_STATUS);
  2257. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2258. MAC_STATUS_SIGNAL_DET |
  2259. MAC_STATUS_CFG_CHANGED |
  2260. MAC_STATUS_RCVD_CFG);
  2261. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2262. MAC_STATUS_SIGNAL_DET)) {
  2263. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2264. MAC_STATUS_CFG_CHANGED));
  2265. return 0;
  2266. }
  2267. }
  2268. tw32_f(MAC_TX_AUTO_NEG, 0);
  2269. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2270. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2271. tw32_f(MAC_MODE, tp->mac_mode);
  2272. udelay(40);
  2273. if (tp->phy_id == PHY_ID_BCM8002)
  2274. tg3_init_bcm8002(tp);
  2275. /* Enable link change event even when serdes polling. */
  2276. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2277. udelay(40);
  2278. current_link_up = 0;
  2279. mac_status = tr32(MAC_STATUS);
  2280. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2281. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2282. else
  2283. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2284. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  2285. tw32_f(MAC_MODE, tp->mac_mode);
  2286. udelay(40);
  2287. tp->hw_status->status =
  2288. (SD_STATUS_UPDATED |
  2289. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2290. for (i = 0; i < 100; i++) {
  2291. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2292. MAC_STATUS_CFG_CHANGED));
  2293. udelay(5);
  2294. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2295. MAC_STATUS_CFG_CHANGED |
  2296. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2297. break;
  2298. }
  2299. mac_status = tr32(MAC_STATUS);
  2300. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2301. current_link_up = 0;
  2302. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2303. tp->serdes_counter == 0) {
  2304. tw32_f(MAC_MODE, (tp->mac_mode |
  2305. MAC_MODE_SEND_CONFIGS));
  2306. udelay(1);
  2307. tw32_f(MAC_MODE, tp->mac_mode);
  2308. }
  2309. }
  2310. if (current_link_up == 1) {
  2311. tp->link_config.active_speed = SPEED_1000;
  2312. tp->link_config.active_duplex = DUPLEX_FULL;
  2313. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2314. LED_CTRL_LNKLED_OVERRIDE |
  2315. LED_CTRL_1000MBPS_ON));
  2316. } else {
  2317. tp->link_config.active_speed = SPEED_INVALID;
  2318. tp->link_config.active_duplex = DUPLEX_INVALID;
  2319. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2320. LED_CTRL_LNKLED_OVERRIDE |
  2321. LED_CTRL_TRAFFIC_OVERRIDE));
  2322. }
  2323. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2324. if (current_link_up)
  2325. netif_carrier_on(tp->dev);
  2326. else
  2327. netif_carrier_off(tp->dev);
  2328. tg3_link_report(tp);
  2329. } else {
  2330. u32 now_pause_cfg =
  2331. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2332. TG3_FLAG_TX_PAUSE);
  2333. if (orig_pause_cfg != now_pause_cfg ||
  2334. orig_active_speed != tp->link_config.active_speed ||
  2335. orig_active_duplex != tp->link_config.active_duplex)
  2336. tg3_link_report(tp);
  2337. }
  2338. return 0;
  2339. }
  2340. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2341. {
  2342. int current_link_up, err = 0;
  2343. u32 bmsr, bmcr;
  2344. u16 current_speed;
  2345. u8 current_duplex;
  2346. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2347. tw32_f(MAC_MODE, tp->mac_mode);
  2348. udelay(40);
  2349. tw32(MAC_EVENT, 0);
  2350. tw32_f(MAC_STATUS,
  2351. (MAC_STATUS_SYNC_CHANGED |
  2352. MAC_STATUS_CFG_CHANGED |
  2353. MAC_STATUS_MI_COMPLETION |
  2354. MAC_STATUS_LNKSTATE_CHANGED));
  2355. udelay(40);
  2356. if (force_reset)
  2357. tg3_phy_reset(tp);
  2358. current_link_up = 0;
  2359. current_speed = SPEED_INVALID;
  2360. current_duplex = DUPLEX_INVALID;
  2361. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2362. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2363. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2364. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2365. bmsr |= BMSR_LSTATUS;
  2366. else
  2367. bmsr &= ~BMSR_LSTATUS;
  2368. }
  2369. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2370. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2371. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2372. /* do nothing, just check for link up at the end */
  2373. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2374. u32 adv, new_adv;
  2375. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2376. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2377. ADVERTISE_1000XPAUSE |
  2378. ADVERTISE_1000XPSE_ASYM |
  2379. ADVERTISE_SLCT);
  2380. /* Always advertise symmetric PAUSE just like copper */
  2381. new_adv |= ADVERTISE_1000XPAUSE;
  2382. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2383. new_adv |= ADVERTISE_1000XHALF;
  2384. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2385. new_adv |= ADVERTISE_1000XFULL;
  2386. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2387. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2388. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2389. tg3_writephy(tp, MII_BMCR, bmcr);
  2390. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2391. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2392. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2393. return err;
  2394. }
  2395. } else {
  2396. u32 new_bmcr;
  2397. bmcr &= ~BMCR_SPEED1000;
  2398. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2399. if (tp->link_config.duplex == DUPLEX_FULL)
  2400. new_bmcr |= BMCR_FULLDPLX;
  2401. if (new_bmcr != bmcr) {
  2402. /* BMCR_SPEED1000 is a reserved bit that needs
  2403. * to be set on write.
  2404. */
  2405. new_bmcr |= BMCR_SPEED1000;
  2406. /* Force a linkdown */
  2407. if (netif_carrier_ok(tp->dev)) {
  2408. u32 adv;
  2409. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2410. adv &= ~(ADVERTISE_1000XFULL |
  2411. ADVERTISE_1000XHALF |
  2412. ADVERTISE_SLCT);
  2413. tg3_writephy(tp, MII_ADVERTISE, adv);
  2414. tg3_writephy(tp, MII_BMCR, bmcr |
  2415. BMCR_ANRESTART |
  2416. BMCR_ANENABLE);
  2417. udelay(10);
  2418. netif_carrier_off(tp->dev);
  2419. }
  2420. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2421. bmcr = new_bmcr;
  2422. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2423. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2424. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2425. ASIC_REV_5714) {
  2426. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2427. bmsr |= BMSR_LSTATUS;
  2428. else
  2429. bmsr &= ~BMSR_LSTATUS;
  2430. }
  2431. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2432. }
  2433. }
  2434. if (bmsr & BMSR_LSTATUS) {
  2435. current_speed = SPEED_1000;
  2436. current_link_up = 1;
  2437. if (bmcr & BMCR_FULLDPLX)
  2438. current_duplex = DUPLEX_FULL;
  2439. else
  2440. current_duplex = DUPLEX_HALF;
  2441. if (bmcr & BMCR_ANENABLE) {
  2442. u32 local_adv, remote_adv, common;
  2443. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2444. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2445. common = local_adv & remote_adv;
  2446. if (common & (ADVERTISE_1000XHALF |
  2447. ADVERTISE_1000XFULL)) {
  2448. if (common & ADVERTISE_1000XFULL)
  2449. current_duplex = DUPLEX_FULL;
  2450. else
  2451. current_duplex = DUPLEX_HALF;
  2452. tg3_setup_flow_control(tp, local_adv,
  2453. remote_adv);
  2454. }
  2455. else
  2456. current_link_up = 0;
  2457. }
  2458. }
  2459. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2460. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2461. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2462. tw32_f(MAC_MODE, tp->mac_mode);
  2463. udelay(40);
  2464. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2465. tp->link_config.active_speed = current_speed;
  2466. tp->link_config.active_duplex = current_duplex;
  2467. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2468. if (current_link_up)
  2469. netif_carrier_on(tp->dev);
  2470. else {
  2471. netif_carrier_off(tp->dev);
  2472. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2473. }
  2474. tg3_link_report(tp);
  2475. }
  2476. return err;
  2477. }
  2478. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2479. {
  2480. if (tp->serdes_counter) {
  2481. /* Give autoneg time to complete. */
  2482. tp->serdes_counter--;
  2483. return;
  2484. }
  2485. if (!netif_carrier_ok(tp->dev) &&
  2486. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2487. u32 bmcr;
  2488. tg3_readphy(tp, MII_BMCR, &bmcr);
  2489. if (bmcr & BMCR_ANENABLE) {
  2490. u32 phy1, phy2;
  2491. /* Select shadow register 0x1f */
  2492. tg3_writephy(tp, 0x1c, 0x7c00);
  2493. tg3_readphy(tp, 0x1c, &phy1);
  2494. /* Select expansion interrupt status register */
  2495. tg3_writephy(tp, 0x17, 0x0f01);
  2496. tg3_readphy(tp, 0x15, &phy2);
  2497. tg3_readphy(tp, 0x15, &phy2);
  2498. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2499. /* We have signal detect and not receiving
  2500. * config code words, link is up by parallel
  2501. * detection.
  2502. */
  2503. bmcr &= ~BMCR_ANENABLE;
  2504. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2505. tg3_writephy(tp, MII_BMCR, bmcr);
  2506. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2507. }
  2508. }
  2509. }
  2510. else if (netif_carrier_ok(tp->dev) &&
  2511. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2512. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2513. u32 phy2;
  2514. /* Select expansion interrupt status register */
  2515. tg3_writephy(tp, 0x17, 0x0f01);
  2516. tg3_readphy(tp, 0x15, &phy2);
  2517. if (phy2 & 0x20) {
  2518. u32 bmcr;
  2519. /* Config code words received, turn on autoneg. */
  2520. tg3_readphy(tp, MII_BMCR, &bmcr);
  2521. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2522. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2523. }
  2524. }
  2525. }
  2526. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2527. {
  2528. int err;
  2529. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2530. err = tg3_setup_fiber_phy(tp, force_reset);
  2531. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2532. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2533. } else {
  2534. err = tg3_setup_copper_phy(tp, force_reset);
  2535. }
  2536. if (tp->link_config.active_speed == SPEED_1000 &&
  2537. tp->link_config.active_duplex == DUPLEX_HALF)
  2538. tw32(MAC_TX_LENGTHS,
  2539. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2540. (6 << TX_LENGTHS_IPG_SHIFT) |
  2541. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2542. else
  2543. tw32(MAC_TX_LENGTHS,
  2544. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2545. (6 << TX_LENGTHS_IPG_SHIFT) |
  2546. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2547. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2548. if (netif_carrier_ok(tp->dev)) {
  2549. tw32(HOSTCC_STAT_COAL_TICKS,
  2550. tp->coal.stats_block_coalesce_usecs);
  2551. } else {
  2552. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2553. }
  2554. }
  2555. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) {
  2556. u32 val = tr32(PCIE_PWR_MGMT_THRESH);
  2557. if (!netif_carrier_ok(tp->dev))
  2558. val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) |
  2559. tp->pwrmgmt_thresh;
  2560. else
  2561. val |= PCIE_PWR_MGMT_L1_THRESH_MSK;
  2562. tw32(PCIE_PWR_MGMT_THRESH, val);
  2563. }
  2564. return err;
  2565. }
  2566. /* This is called whenever we suspect that the system chipset is re-
  2567. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2568. * is bogus tx completions. We try to recover by setting the
  2569. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2570. * in the workqueue.
  2571. */
  2572. static void tg3_tx_recover(struct tg3 *tp)
  2573. {
  2574. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2575. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2576. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2577. "mapped I/O cycles to the network device, attempting to "
  2578. "recover. Please report the problem to the driver maintainer "
  2579. "and include system chipset information.\n", tp->dev->name);
  2580. spin_lock(&tp->lock);
  2581. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2582. spin_unlock(&tp->lock);
  2583. }
  2584. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2585. {
  2586. smp_mb();
  2587. return (tp->tx_pending -
  2588. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2589. }
  2590. /* Tigon3 never reports partial packet sends. So we do not
  2591. * need special logic to handle SKBs that have not had all
  2592. * of their frags sent yet, like SunGEM does.
  2593. */
  2594. static void tg3_tx(struct tg3 *tp)
  2595. {
  2596. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2597. u32 sw_idx = tp->tx_cons;
  2598. while (sw_idx != hw_idx) {
  2599. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2600. struct sk_buff *skb = ri->skb;
  2601. int i, tx_bug = 0;
  2602. if (unlikely(skb == NULL)) {
  2603. tg3_tx_recover(tp);
  2604. return;
  2605. }
  2606. pci_unmap_single(tp->pdev,
  2607. pci_unmap_addr(ri, mapping),
  2608. skb_headlen(skb),
  2609. PCI_DMA_TODEVICE);
  2610. ri->skb = NULL;
  2611. sw_idx = NEXT_TX(sw_idx);
  2612. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2613. ri = &tp->tx_buffers[sw_idx];
  2614. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2615. tx_bug = 1;
  2616. pci_unmap_page(tp->pdev,
  2617. pci_unmap_addr(ri, mapping),
  2618. skb_shinfo(skb)->frags[i].size,
  2619. PCI_DMA_TODEVICE);
  2620. sw_idx = NEXT_TX(sw_idx);
  2621. }
  2622. dev_kfree_skb(skb);
  2623. if (unlikely(tx_bug)) {
  2624. tg3_tx_recover(tp);
  2625. return;
  2626. }
  2627. }
  2628. tp->tx_cons = sw_idx;
  2629. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2630. * before checking for netif_queue_stopped(). Without the
  2631. * memory barrier, there is a small possibility that tg3_start_xmit()
  2632. * will miss it and cause the queue to be stopped forever.
  2633. */
  2634. smp_mb();
  2635. if (unlikely(netif_queue_stopped(tp->dev) &&
  2636. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2637. netif_tx_lock(tp->dev);
  2638. if (netif_queue_stopped(tp->dev) &&
  2639. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2640. netif_wake_queue(tp->dev);
  2641. netif_tx_unlock(tp->dev);
  2642. }
  2643. }
  2644. /* Returns size of skb allocated or < 0 on error.
  2645. *
  2646. * We only need to fill in the address because the other members
  2647. * of the RX descriptor are invariant, see tg3_init_rings.
  2648. *
  2649. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2650. * posting buffers we only dirty the first cache line of the RX
  2651. * descriptor (containing the address). Whereas for the RX status
  2652. * buffers the cpu only reads the last cacheline of the RX descriptor
  2653. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2654. */
  2655. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2656. int src_idx, u32 dest_idx_unmasked)
  2657. {
  2658. struct tg3_rx_buffer_desc *desc;
  2659. struct ring_info *map, *src_map;
  2660. struct sk_buff *skb;
  2661. dma_addr_t mapping;
  2662. int skb_size, dest_idx;
  2663. src_map = NULL;
  2664. switch (opaque_key) {
  2665. case RXD_OPAQUE_RING_STD:
  2666. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2667. desc = &tp->rx_std[dest_idx];
  2668. map = &tp->rx_std_buffers[dest_idx];
  2669. if (src_idx >= 0)
  2670. src_map = &tp->rx_std_buffers[src_idx];
  2671. skb_size = tp->rx_pkt_buf_sz;
  2672. break;
  2673. case RXD_OPAQUE_RING_JUMBO:
  2674. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2675. desc = &tp->rx_jumbo[dest_idx];
  2676. map = &tp->rx_jumbo_buffers[dest_idx];
  2677. if (src_idx >= 0)
  2678. src_map = &tp->rx_jumbo_buffers[src_idx];
  2679. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2680. break;
  2681. default:
  2682. return -EINVAL;
  2683. };
  2684. /* Do not overwrite any of the map or rp information
  2685. * until we are sure we can commit to a new buffer.
  2686. *
  2687. * Callers depend upon this behavior and assume that
  2688. * we leave everything unchanged if we fail.
  2689. */
  2690. skb = netdev_alloc_skb(tp->dev, skb_size);
  2691. if (skb == NULL)
  2692. return -ENOMEM;
  2693. skb_reserve(skb, tp->rx_offset);
  2694. mapping = pci_map_single(tp->pdev, skb->data,
  2695. skb_size - tp->rx_offset,
  2696. PCI_DMA_FROMDEVICE);
  2697. map->skb = skb;
  2698. pci_unmap_addr_set(map, mapping, mapping);
  2699. if (src_map != NULL)
  2700. src_map->skb = NULL;
  2701. desc->addr_hi = ((u64)mapping >> 32);
  2702. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2703. return skb_size;
  2704. }
  2705. /* We only need to move over in the address because the other
  2706. * members of the RX descriptor are invariant. See notes above
  2707. * tg3_alloc_rx_skb for full details.
  2708. */
  2709. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2710. int src_idx, u32 dest_idx_unmasked)
  2711. {
  2712. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2713. struct ring_info *src_map, *dest_map;
  2714. int dest_idx;
  2715. switch (opaque_key) {
  2716. case RXD_OPAQUE_RING_STD:
  2717. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2718. dest_desc = &tp->rx_std[dest_idx];
  2719. dest_map = &tp->rx_std_buffers[dest_idx];
  2720. src_desc = &tp->rx_std[src_idx];
  2721. src_map = &tp->rx_std_buffers[src_idx];
  2722. break;
  2723. case RXD_OPAQUE_RING_JUMBO:
  2724. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2725. dest_desc = &tp->rx_jumbo[dest_idx];
  2726. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2727. src_desc = &tp->rx_jumbo[src_idx];
  2728. src_map = &tp->rx_jumbo_buffers[src_idx];
  2729. break;
  2730. default:
  2731. return;
  2732. };
  2733. dest_map->skb = src_map->skb;
  2734. pci_unmap_addr_set(dest_map, mapping,
  2735. pci_unmap_addr(src_map, mapping));
  2736. dest_desc->addr_hi = src_desc->addr_hi;
  2737. dest_desc->addr_lo = src_desc->addr_lo;
  2738. src_map->skb = NULL;
  2739. }
  2740. #if TG3_VLAN_TAG_USED
  2741. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2742. {
  2743. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2744. }
  2745. #endif
  2746. /* The RX ring scheme is composed of multiple rings which post fresh
  2747. * buffers to the chip, and one special ring the chip uses to report
  2748. * status back to the host.
  2749. *
  2750. * The special ring reports the status of received packets to the
  2751. * host. The chip does not write into the original descriptor the
  2752. * RX buffer was obtained from. The chip simply takes the original
  2753. * descriptor as provided by the host, updates the status and length
  2754. * field, then writes this into the next status ring entry.
  2755. *
  2756. * Each ring the host uses to post buffers to the chip is described
  2757. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2758. * it is first placed into the on-chip ram. When the packet's length
  2759. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2760. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2761. * which is within the range of the new packet's length is chosen.
  2762. *
  2763. * The "separate ring for rx status" scheme may sound queer, but it makes
  2764. * sense from a cache coherency perspective. If only the host writes
  2765. * to the buffer post rings, and only the chip writes to the rx status
  2766. * rings, then cache lines never move beyond shared-modified state.
  2767. * If both the host and chip were to write into the same ring, cache line
  2768. * eviction could occur since both entities want it in an exclusive state.
  2769. */
  2770. static int tg3_rx(struct tg3 *tp, int budget)
  2771. {
  2772. u32 work_mask, rx_std_posted = 0;
  2773. u32 sw_idx = tp->rx_rcb_ptr;
  2774. u16 hw_idx;
  2775. int received;
  2776. hw_idx = tp->hw_status->idx[0].rx_producer;
  2777. /*
  2778. * We need to order the read of hw_idx and the read of
  2779. * the opaque cookie.
  2780. */
  2781. rmb();
  2782. work_mask = 0;
  2783. received = 0;
  2784. while (sw_idx != hw_idx && budget > 0) {
  2785. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2786. unsigned int len;
  2787. struct sk_buff *skb;
  2788. dma_addr_t dma_addr;
  2789. u32 opaque_key, desc_idx, *post_ptr;
  2790. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2791. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2792. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2793. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2794. mapping);
  2795. skb = tp->rx_std_buffers[desc_idx].skb;
  2796. post_ptr = &tp->rx_std_ptr;
  2797. rx_std_posted++;
  2798. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2799. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2800. mapping);
  2801. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2802. post_ptr = &tp->rx_jumbo_ptr;
  2803. }
  2804. else {
  2805. goto next_pkt_nopost;
  2806. }
  2807. work_mask |= opaque_key;
  2808. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2809. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2810. drop_it:
  2811. tg3_recycle_rx(tp, opaque_key,
  2812. desc_idx, *post_ptr);
  2813. drop_it_no_recycle:
  2814. /* Other statistics kept track of by card. */
  2815. tp->net_stats.rx_dropped++;
  2816. goto next_pkt;
  2817. }
  2818. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2819. if (len > RX_COPY_THRESHOLD
  2820. && tp->rx_offset == 2
  2821. /* rx_offset != 2 iff this is a 5701 card running
  2822. * in PCI-X mode [see tg3_get_invariants()] */
  2823. ) {
  2824. int skb_size;
  2825. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2826. desc_idx, *post_ptr);
  2827. if (skb_size < 0)
  2828. goto drop_it;
  2829. pci_unmap_single(tp->pdev, dma_addr,
  2830. skb_size - tp->rx_offset,
  2831. PCI_DMA_FROMDEVICE);
  2832. skb_put(skb, len);
  2833. } else {
  2834. struct sk_buff *copy_skb;
  2835. tg3_recycle_rx(tp, opaque_key,
  2836. desc_idx, *post_ptr);
  2837. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  2838. if (copy_skb == NULL)
  2839. goto drop_it_no_recycle;
  2840. skb_reserve(copy_skb, 2);
  2841. skb_put(copy_skb, len);
  2842. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2843. skb_copy_from_linear_data(skb, copy_skb->data, len);
  2844. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2845. /* We'll reuse the original ring buffer. */
  2846. skb = copy_skb;
  2847. }
  2848. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2849. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2850. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2851. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2852. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2853. else
  2854. skb->ip_summed = CHECKSUM_NONE;
  2855. skb->protocol = eth_type_trans(skb, tp->dev);
  2856. #if TG3_VLAN_TAG_USED
  2857. if (tp->vlgrp != NULL &&
  2858. desc->type_flags & RXD_FLAG_VLAN) {
  2859. tg3_vlan_rx(tp, skb,
  2860. desc->err_vlan & RXD_VLAN_MASK);
  2861. } else
  2862. #endif
  2863. netif_receive_skb(skb);
  2864. tp->dev->last_rx = jiffies;
  2865. received++;
  2866. budget--;
  2867. next_pkt:
  2868. (*post_ptr)++;
  2869. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2870. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2871. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2872. TG3_64BIT_REG_LOW, idx);
  2873. work_mask &= ~RXD_OPAQUE_RING_STD;
  2874. rx_std_posted = 0;
  2875. }
  2876. next_pkt_nopost:
  2877. sw_idx++;
  2878. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  2879. /* Refresh hw_idx to see if there is new work */
  2880. if (sw_idx == hw_idx) {
  2881. hw_idx = tp->hw_status->idx[0].rx_producer;
  2882. rmb();
  2883. }
  2884. }
  2885. /* ACK the status ring. */
  2886. tp->rx_rcb_ptr = sw_idx;
  2887. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2888. /* Refill RX ring(s). */
  2889. if (work_mask & RXD_OPAQUE_RING_STD) {
  2890. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2891. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2892. sw_idx);
  2893. }
  2894. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2895. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2896. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2897. sw_idx);
  2898. }
  2899. mmiowb();
  2900. return received;
  2901. }
  2902. static int tg3_poll(struct net_device *netdev, int *budget)
  2903. {
  2904. struct tg3 *tp = netdev_priv(netdev);
  2905. struct tg3_hw_status *sblk = tp->hw_status;
  2906. int done;
  2907. /* handle link change and other phy events */
  2908. if (!(tp->tg3_flags &
  2909. (TG3_FLAG_USE_LINKCHG_REG |
  2910. TG3_FLAG_POLL_SERDES))) {
  2911. if (sblk->status & SD_STATUS_LINK_CHG) {
  2912. sblk->status = SD_STATUS_UPDATED |
  2913. (sblk->status & ~SD_STATUS_LINK_CHG);
  2914. spin_lock(&tp->lock);
  2915. tg3_setup_phy(tp, 0);
  2916. spin_unlock(&tp->lock);
  2917. }
  2918. }
  2919. /* run TX completion thread */
  2920. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2921. tg3_tx(tp);
  2922. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2923. netif_rx_complete(netdev);
  2924. schedule_work(&tp->reset_task);
  2925. return 0;
  2926. }
  2927. }
  2928. /* run RX thread, within the bounds set by NAPI.
  2929. * All RX "locking" is done by ensuring outside
  2930. * code synchronizes with dev->poll()
  2931. */
  2932. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2933. int orig_budget = *budget;
  2934. int work_done;
  2935. if (orig_budget > netdev->quota)
  2936. orig_budget = netdev->quota;
  2937. work_done = tg3_rx(tp, orig_budget);
  2938. *budget -= work_done;
  2939. netdev->quota -= work_done;
  2940. }
  2941. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2942. tp->last_tag = sblk->status_tag;
  2943. rmb();
  2944. } else
  2945. sblk->status &= ~SD_STATUS_UPDATED;
  2946. /* if no more work, tell net stack and NIC we're done */
  2947. done = !tg3_has_work(tp);
  2948. if (done) {
  2949. netif_rx_complete(netdev);
  2950. tg3_restart_ints(tp);
  2951. }
  2952. return (done ? 0 : 1);
  2953. }
  2954. static void tg3_irq_quiesce(struct tg3 *tp)
  2955. {
  2956. BUG_ON(tp->irq_sync);
  2957. tp->irq_sync = 1;
  2958. smp_mb();
  2959. synchronize_irq(tp->pdev->irq);
  2960. }
  2961. static inline int tg3_irq_sync(struct tg3 *tp)
  2962. {
  2963. return tp->irq_sync;
  2964. }
  2965. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  2966. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  2967. * with as well. Most of the time, this is not necessary except when
  2968. * shutting down the device.
  2969. */
  2970. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  2971. {
  2972. if (irq_sync)
  2973. tg3_irq_quiesce(tp);
  2974. spin_lock_bh(&tp->lock);
  2975. }
  2976. static inline void tg3_full_unlock(struct tg3 *tp)
  2977. {
  2978. spin_unlock_bh(&tp->lock);
  2979. }
  2980. /* One-shot MSI handler - Chip automatically disables interrupt
  2981. * after sending MSI so driver doesn't have to do it.
  2982. */
  2983. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  2984. {
  2985. struct net_device *dev = dev_id;
  2986. struct tg3 *tp = netdev_priv(dev);
  2987. prefetch(tp->hw_status);
  2988. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  2989. if (likely(!tg3_irq_sync(tp)))
  2990. netif_rx_schedule(dev); /* schedule NAPI poll */
  2991. return IRQ_HANDLED;
  2992. }
  2993. /* MSI ISR - No need to check for interrupt sharing and no need to
  2994. * flush status block and interrupt mailbox. PCI ordering rules
  2995. * guarantee that MSI will arrive after the status block.
  2996. */
  2997. static irqreturn_t tg3_msi(int irq, void *dev_id)
  2998. {
  2999. struct net_device *dev = dev_id;
  3000. struct tg3 *tp = netdev_priv(dev);
  3001. prefetch(tp->hw_status);
  3002. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3003. /*
  3004. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3005. * chip-internal interrupt pending events.
  3006. * Writing non-zero to intr-mbox-0 additional tells the
  3007. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3008. * event coalescing.
  3009. */
  3010. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3011. if (likely(!tg3_irq_sync(tp)))
  3012. netif_rx_schedule(dev); /* schedule NAPI poll */
  3013. return IRQ_RETVAL(1);
  3014. }
  3015. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3016. {
  3017. struct net_device *dev = dev_id;
  3018. struct tg3 *tp = netdev_priv(dev);
  3019. struct tg3_hw_status *sblk = tp->hw_status;
  3020. unsigned int handled = 1;
  3021. /* In INTx mode, it is possible for the interrupt to arrive at
  3022. * the CPU before the status block posted prior to the interrupt.
  3023. * Reading the PCI State register will confirm whether the
  3024. * interrupt is ours and will flush the status block.
  3025. */
  3026. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3027. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3028. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3029. handled = 0;
  3030. goto out;
  3031. }
  3032. }
  3033. /*
  3034. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3035. * chip-internal interrupt pending events.
  3036. * Writing non-zero to intr-mbox-0 additional tells the
  3037. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3038. * event coalescing.
  3039. *
  3040. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3041. * spurious interrupts. The flush impacts performance but
  3042. * excessive spurious interrupts can be worse in some cases.
  3043. */
  3044. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3045. if (tg3_irq_sync(tp))
  3046. goto out;
  3047. sblk->status &= ~SD_STATUS_UPDATED;
  3048. if (likely(tg3_has_work(tp))) {
  3049. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3050. netif_rx_schedule(dev); /* schedule NAPI poll */
  3051. } else {
  3052. /* No work, shared interrupt perhaps? re-enable
  3053. * interrupts, and flush that PCI write
  3054. */
  3055. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3056. 0x00000000);
  3057. }
  3058. out:
  3059. return IRQ_RETVAL(handled);
  3060. }
  3061. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3062. {
  3063. struct net_device *dev = dev_id;
  3064. struct tg3 *tp = netdev_priv(dev);
  3065. struct tg3_hw_status *sblk = tp->hw_status;
  3066. unsigned int handled = 1;
  3067. /* In INTx mode, it is possible for the interrupt to arrive at
  3068. * the CPU before the status block posted prior to the interrupt.
  3069. * Reading the PCI State register will confirm whether the
  3070. * interrupt is ours and will flush the status block.
  3071. */
  3072. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3073. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3074. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3075. handled = 0;
  3076. goto out;
  3077. }
  3078. }
  3079. /*
  3080. * writing any value to intr-mbox-0 clears PCI INTA# and
  3081. * chip-internal interrupt pending events.
  3082. * writing non-zero to intr-mbox-0 additional tells the
  3083. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3084. * event coalescing.
  3085. *
  3086. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3087. * spurious interrupts. The flush impacts performance but
  3088. * excessive spurious interrupts can be worse in some cases.
  3089. */
  3090. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3091. if (tg3_irq_sync(tp))
  3092. goto out;
  3093. if (netif_rx_schedule_prep(dev)) {
  3094. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3095. /* Update last_tag to mark that this status has been
  3096. * seen. Because interrupt may be shared, we may be
  3097. * racing with tg3_poll(), so only update last_tag
  3098. * if tg3_poll() is not scheduled.
  3099. */
  3100. tp->last_tag = sblk->status_tag;
  3101. __netif_rx_schedule(dev);
  3102. }
  3103. out:
  3104. return IRQ_RETVAL(handled);
  3105. }
  3106. /* ISR for interrupt test */
  3107. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3108. {
  3109. struct net_device *dev = dev_id;
  3110. struct tg3 *tp = netdev_priv(dev);
  3111. struct tg3_hw_status *sblk = tp->hw_status;
  3112. if ((sblk->status & SD_STATUS_UPDATED) ||
  3113. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3114. tg3_disable_ints(tp);
  3115. return IRQ_RETVAL(1);
  3116. }
  3117. return IRQ_RETVAL(0);
  3118. }
  3119. static int tg3_init_hw(struct tg3 *, int);
  3120. static int tg3_halt(struct tg3 *, int, int);
  3121. /* Restart hardware after configuration changes, self-test, etc.
  3122. * Invoked with tp->lock held.
  3123. */
  3124. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3125. {
  3126. int err;
  3127. err = tg3_init_hw(tp, reset_phy);
  3128. if (err) {
  3129. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3130. "aborting.\n", tp->dev->name);
  3131. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3132. tg3_full_unlock(tp);
  3133. del_timer_sync(&tp->timer);
  3134. tp->irq_sync = 0;
  3135. netif_poll_enable(tp->dev);
  3136. dev_close(tp->dev);
  3137. tg3_full_lock(tp, 0);
  3138. }
  3139. return err;
  3140. }
  3141. #ifdef CONFIG_NET_POLL_CONTROLLER
  3142. static void tg3_poll_controller(struct net_device *dev)
  3143. {
  3144. struct tg3 *tp = netdev_priv(dev);
  3145. tg3_interrupt(tp->pdev->irq, dev);
  3146. }
  3147. #endif
  3148. static void tg3_reset_task(struct work_struct *work)
  3149. {
  3150. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3151. unsigned int restart_timer;
  3152. tg3_full_lock(tp, 0);
  3153. tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
  3154. if (!netif_running(tp->dev)) {
  3155. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3156. tg3_full_unlock(tp);
  3157. return;
  3158. }
  3159. tg3_full_unlock(tp);
  3160. tg3_netif_stop(tp);
  3161. tg3_full_lock(tp, 1);
  3162. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3163. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3164. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3165. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3166. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3167. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3168. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3169. }
  3170. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3171. if (tg3_init_hw(tp, 1))
  3172. goto out;
  3173. tg3_netif_start(tp);
  3174. if (restart_timer)
  3175. mod_timer(&tp->timer, jiffies + 1);
  3176. out:
  3177. tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
  3178. tg3_full_unlock(tp);
  3179. }
  3180. static void tg3_dump_short_state(struct tg3 *tp)
  3181. {
  3182. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3183. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3184. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3185. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3186. }
  3187. static void tg3_tx_timeout(struct net_device *dev)
  3188. {
  3189. struct tg3 *tp = netdev_priv(dev);
  3190. if (netif_msg_tx_err(tp)) {
  3191. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3192. dev->name);
  3193. tg3_dump_short_state(tp);
  3194. }
  3195. schedule_work(&tp->reset_task);
  3196. }
  3197. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3198. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3199. {
  3200. u32 base = (u32) mapping & 0xffffffff;
  3201. return ((base > 0xffffdcc0) &&
  3202. (base + len + 8 < base));
  3203. }
  3204. /* Test for DMA addresses > 40-bit */
  3205. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3206. int len)
  3207. {
  3208. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3209. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3210. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3211. return 0;
  3212. #else
  3213. return 0;
  3214. #endif
  3215. }
  3216. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3217. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3218. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3219. u32 last_plus_one, u32 *start,
  3220. u32 base_flags, u32 mss)
  3221. {
  3222. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3223. dma_addr_t new_addr = 0;
  3224. u32 entry = *start;
  3225. int i, ret = 0;
  3226. if (!new_skb) {
  3227. ret = -1;
  3228. } else {
  3229. /* New SKB is guaranteed to be linear. */
  3230. entry = *start;
  3231. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3232. PCI_DMA_TODEVICE);
  3233. /* Make sure new skb does not cross any 4G boundaries.
  3234. * Drop the packet if it does.
  3235. */
  3236. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3237. ret = -1;
  3238. dev_kfree_skb(new_skb);
  3239. new_skb = NULL;
  3240. } else {
  3241. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3242. base_flags, 1 | (mss << 1));
  3243. *start = NEXT_TX(entry);
  3244. }
  3245. }
  3246. /* Now clean up the sw ring entries. */
  3247. i = 0;
  3248. while (entry != last_plus_one) {
  3249. int len;
  3250. if (i == 0)
  3251. len = skb_headlen(skb);
  3252. else
  3253. len = skb_shinfo(skb)->frags[i-1].size;
  3254. pci_unmap_single(tp->pdev,
  3255. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3256. len, PCI_DMA_TODEVICE);
  3257. if (i == 0) {
  3258. tp->tx_buffers[entry].skb = new_skb;
  3259. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3260. } else {
  3261. tp->tx_buffers[entry].skb = NULL;
  3262. }
  3263. entry = NEXT_TX(entry);
  3264. i++;
  3265. }
  3266. dev_kfree_skb(skb);
  3267. return ret;
  3268. }
  3269. static void tg3_set_txd(struct tg3 *tp, int entry,
  3270. dma_addr_t mapping, int len, u32 flags,
  3271. u32 mss_and_is_end)
  3272. {
  3273. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3274. int is_end = (mss_and_is_end & 0x1);
  3275. u32 mss = (mss_and_is_end >> 1);
  3276. u32 vlan_tag = 0;
  3277. if (is_end)
  3278. flags |= TXD_FLAG_END;
  3279. if (flags & TXD_FLAG_VLAN) {
  3280. vlan_tag = flags >> 16;
  3281. flags &= 0xffff;
  3282. }
  3283. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3284. txd->addr_hi = ((u64) mapping >> 32);
  3285. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3286. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3287. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3288. }
  3289. /* hard_start_xmit for devices that don't have any bugs and
  3290. * support TG3_FLG2_HW_TSO_2 only.
  3291. */
  3292. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3293. {
  3294. struct tg3 *tp = netdev_priv(dev);
  3295. dma_addr_t mapping;
  3296. u32 len, entry, base_flags, mss;
  3297. len = skb_headlen(skb);
  3298. /* We are running in BH disabled context with netif_tx_lock
  3299. * and TX reclaim runs via tp->poll inside of a software
  3300. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3301. * no IRQ context deadlocks to worry about either. Rejoice!
  3302. */
  3303. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3304. if (!netif_queue_stopped(dev)) {
  3305. netif_stop_queue(dev);
  3306. /* This is a hard error, log it. */
  3307. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3308. "queue awake!\n", dev->name);
  3309. }
  3310. return NETDEV_TX_BUSY;
  3311. }
  3312. entry = tp->tx_prod;
  3313. base_flags = 0;
  3314. mss = 0;
  3315. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3316. int tcp_opt_len, ip_tcp_len;
  3317. if (skb_header_cloned(skb) &&
  3318. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3319. dev_kfree_skb(skb);
  3320. goto out_unlock;
  3321. }
  3322. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3323. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3324. else {
  3325. struct iphdr *iph = ip_hdr(skb);
  3326. tcp_opt_len = tcp_optlen(skb);
  3327. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3328. iph->check = 0;
  3329. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3330. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3331. }
  3332. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3333. TXD_FLAG_CPU_POST_DMA);
  3334. tcp_hdr(skb)->check = 0;
  3335. }
  3336. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3337. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3338. #if TG3_VLAN_TAG_USED
  3339. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3340. base_flags |= (TXD_FLAG_VLAN |
  3341. (vlan_tx_tag_get(skb) << 16));
  3342. #endif
  3343. /* Queue skb data, a.k.a. the main skb fragment. */
  3344. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3345. tp->tx_buffers[entry].skb = skb;
  3346. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3347. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3348. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3349. entry = NEXT_TX(entry);
  3350. /* Now loop through additional data fragments, and queue them. */
  3351. if (skb_shinfo(skb)->nr_frags > 0) {
  3352. unsigned int i, last;
  3353. last = skb_shinfo(skb)->nr_frags - 1;
  3354. for (i = 0; i <= last; i++) {
  3355. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3356. len = frag->size;
  3357. mapping = pci_map_page(tp->pdev,
  3358. frag->page,
  3359. frag->page_offset,
  3360. len, PCI_DMA_TODEVICE);
  3361. tp->tx_buffers[entry].skb = NULL;
  3362. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3363. tg3_set_txd(tp, entry, mapping, len,
  3364. base_flags, (i == last) | (mss << 1));
  3365. entry = NEXT_TX(entry);
  3366. }
  3367. }
  3368. /* Packets are ready, update Tx producer idx local and on card. */
  3369. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3370. tp->tx_prod = entry;
  3371. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3372. netif_stop_queue(dev);
  3373. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3374. netif_wake_queue(tp->dev);
  3375. }
  3376. out_unlock:
  3377. mmiowb();
  3378. dev->trans_start = jiffies;
  3379. return NETDEV_TX_OK;
  3380. }
  3381. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3382. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3383. * TSO header is greater than 80 bytes.
  3384. */
  3385. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3386. {
  3387. struct sk_buff *segs, *nskb;
  3388. /* Estimate the number of fragments in the worst case */
  3389. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3390. netif_stop_queue(tp->dev);
  3391. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3392. return NETDEV_TX_BUSY;
  3393. netif_wake_queue(tp->dev);
  3394. }
  3395. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3396. if (unlikely(IS_ERR(segs)))
  3397. goto tg3_tso_bug_end;
  3398. do {
  3399. nskb = segs;
  3400. segs = segs->next;
  3401. nskb->next = NULL;
  3402. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3403. } while (segs);
  3404. tg3_tso_bug_end:
  3405. dev_kfree_skb(skb);
  3406. return NETDEV_TX_OK;
  3407. }
  3408. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3409. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3410. */
  3411. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3412. {
  3413. struct tg3 *tp = netdev_priv(dev);
  3414. dma_addr_t mapping;
  3415. u32 len, entry, base_flags, mss;
  3416. int would_hit_hwbug;
  3417. len = skb_headlen(skb);
  3418. /* We are running in BH disabled context with netif_tx_lock
  3419. * and TX reclaim runs via tp->poll inside of a software
  3420. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3421. * no IRQ context deadlocks to worry about either. Rejoice!
  3422. */
  3423. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3424. if (!netif_queue_stopped(dev)) {
  3425. netif_stop_queue(dev);
  3426. /* This is a hard error, log it. */
  3427. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3428. "queue awake!\n", dev->name);
  3429. }
  3430. return NETDEV_TX_BUSY;
  3431. }
  3432. entry = tp->tx_prod;
  3433. base_flags = 0;
  3434. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3435. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3436. mss = 0;
  3437. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3438. struct iphdr *iph;
  3439. int tcp_opt_len, ip_tcp_len, hdr_len;
  3440. if (skb_header_cloned(skb) &&
  3441. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3442. dev_kfree_skb(skb);
  3443. goto out_unlock;
  3444. }
  3445. tcp_opt_len = tcp_optlen(skb);
  3446. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3447. hdr_len = ip_tcp_len + tcp_opt_len;
  3448. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3449. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3450. return (tg3_tso_bug(tp, skb));
  3451. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3452. TXD_FLAG_CPU_POST_DMA);
  3453. iph = ip_hdr(skb);
  3454. iph->check = 0;
  3455. iph->tot_len = htons(mss + hdr_len);
  3456. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3457. tcp_hdr(skb)->check = 0;
  3458. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3459. } else
  3460. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3461. iph->daddr, 0,
  3462. IPPROTO_TCP,
  3463. 0);
  3464. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3465. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3466. if (tcp_opt_len || iph->ihl > 5) {
  3467. int tsflags;
  3468. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3469. mss |= (tsflags << 11);
  3470. }
  3471. } else {
  3472. if (tcp_opt_len || iph->ihl > 5) {
  3473. int tsflags;
  3474. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3475. base_flags |= tsflags << 12;
  3476. }
  3477. }
  3478. }
  3479. #if TG3_VLAN_TAG_USED
  3480. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3481. base_flags |= (TXD_FLAG_VLAN |
  3482. (vlan_tx_tag_get(skb) << 16));
  3483. #endif
  3484. /* Queue skb data, a.k.a. the main skb fragment. */
  3485. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3486. tp->tx_buffers[entry].skb = skb;
  3487. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3488. would_hit_hwbug = 0;
  3489. if (tg3_4g_overflow_test(mapping, len))
  3490. would_hit_hwbug = 1;
  3491. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3492. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3493. entry = NEXT_TX(entry);
  3494. /* Now loop through additional data fragments, and queue them. */
  3495. if (skb_shinfo(skb)->nr_frags > 0) {
  3496. unsigned int i, last;
  3497. last = skb_shinfo(skb)->nr_frags - 1;
  3498. for (i = 0; i <= last; i++) {
  3499. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3500. len = frag->size;
  3501. mapping = pci_map_page(tp->pdev,
  3502. frag->page,
  3503. frag->page_offset,
  3504. len, PCI_DMA_TODEVICE);
  3505. tp->tx_buffers[entry].skb = NULL;
  3506. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3507. if (tg3_4g_overflow_test(mapping, len))
  3508. would_hit_hwbug = 1;
  3509. if (tg3_40bit_overflow_test(tp, mapping, len))
  3510. would_hit_hwbug = 1;
  3511. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3512. tg3_set_txd(tp, entry, mapping, len,
  3513. base_flags, (i == last)|(mss << 1));
  3514. else
  3515. tg3_set_txd(tp, entry, mapping, len,
  3516. base_flags, (i == last));
  3517. entry = NEXT_TX(entry);
  3518. }
  3519. }
  3520. if (would_hit_hwbug) {
  3521. u32 last_plus_one = entry;
  3522. u32 start;
  3523. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3524. start &= (TG3_TX_RING_SIZE - 1);
  3525. /* If the workaround fails due to memory/mapping
  3526. * failure, silently drop this packet.
  3527. */
  3528. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3529. &start, base_flags, mss))
  3530. goto out_unlock;
  3531. entry = start;
  3532. }
  3533. /* Packets are ready, update Tx producer idx local and on card. */
  3534. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3535. tp->tx_prod = entry;
  3536. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3537. netif_stop_queue(dev);
  3538. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3539. netif_wake_queue(tp->dev);
  3540. }
  3541. out_unlock:
  3542. mmiowb();
  3543. dev->trans_start = jiffies;
  3544. return NETDEV_TX_OK;
  3545. }
  3546. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3547. int new_mtu)
  3548. {
  3549. dev->mtu = new_mtu;
  3550. if (new_mtu > ETH_DATA_LEN) {
  3551. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3552. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3553. ethtool_op_set_tso(dev, 0);
  3554. }
  3555. else
  3556. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3557. } else {
  3558. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3559. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3560. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3561. }
  3562. }
  3563. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3564. {
  3565. struct tg3 *tp = netdev_priv(dev);
  3566. int err;
  3567. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3568. return -EINVAL;
  3569. if (!netif_running(dev)) {
  3570. /* We'll just catch it later when the
  3571. * device is up'd.
  3572. */
  3573. tg3_set_mtu(dev, tp, new_mtu);
  3574. return 0;
  3575. }
  3576. tg3_netif_stop(tp);
  3577. tg3_full_lock(tp, 1);
  3578. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3579. tg3_set_mtu(dev, tp, new_mtu);
  3580. err = tg3_restart_hw(tp, 0);
  3581. if (!err)
  3582. tg3_netif_start(tp);
  3583. tg3_full_unlock(tp);
  3584. return err;
  3585. }
  3586. /* Free up pending packets in all rx/tx rings.
  3587. *
  3588. * The chip has been shut down and the driver detached from
  3589. * the networking, so no interrupts or new tx packets will
  3590. * end up in the driver. tp->{tx,}lock is not held and we are not
  3591. * in an interrupt context and thus may sleep.
  3592. */
  3593. static void tg3_free_rings(struct tg3 *tp)
  3594. {
  3595. struct ring_info *rxp;
  3596. int i;
  3597. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3598. rxp = &tp->rx_std_buffers[i];
  3599. if (rxp->skb == NULL)
  3600. continue;
  3601. pci_unmap_single(tp->pdev,
  3602. pci_unmap_addr(rxp, mapping),
  3603. tp->rx_pkt_buf_sz - tp->rx_offset,
  3604. PCI_DMA_FROMDEVICE);
  3605. dev_kfree_skb_any(rxp->skb);
  3606. rxp->skb = NULL;
  3607. }
  3608. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3609. rxp = &tp->rx_jumbo_buffers[i];
  3610. if (rxp->skb == NULL)
  3611. continue;
  3612. pci_unmap_single(tp->pdev,
  3613. pci_unmap_addr(rxp, mapping),
  3614. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3615. PCI_DMA_FROMDEVICE);
  3616. dev_kfree_skb_any(rxp->skb);
  3617. rxp->skb = NULL;
  3618. }
  3619. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3620. struct tx_ring_info *txp;
  3621. struct sk_buff *skb;
  3622. int j;
  3623. txp = &tp->tx_buffers[i];
  3624. skb = txp->skb;
  3625. if (skb == NULL) {
  3626. i++;
  3627. continue;
  3628. }
  3629. pci_unmap_single(tp->pdev,
  3630. pci_unmap_addr(txp, mapping),
  3631. skb_headlen(skb),
  3632. PCI_DMA_TODEVICE);
  3633. txp->skb = NULL;
  3634. i++;
  3635. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3636. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3637. pci_unmap_page(tp->pdev,
  3638. pci_unmap_addr(txp, mapping),
  3639. skb_shinfo(skb)->frags[j].size,
  3640. PCI_DMA_TODEVICE);
  3641. i++;
  3642. }
  3643. dev_kfree_skb_any(skb);
  3644. }
  3645. }
  3646. /* Initialize tx/rx rings for packet processing.
  3647. *
  3648. * The chip has been shut down and the driver detached from
  3649. * the networking, so no interrupts or new tx packets will
  3650. * end up in the driver. tp->{tx,}lock are held and thus
  3651. * we may not sleep.
  3652. */
  3653. static int tg3_init_rings(struct tg3 *tp)
  3654. {
  3655. u32 i;
  3656. /* Free up all the SKBs. */
  3657. tg3_free_rings(tp);
  3658. /* Zero out all descriptors. */
  3659. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3660. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3661. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3662. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3663. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3664. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3665. (tp->dev->mtu > ETH_DATA_LEN))
  3666. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3667. /* Initialize invariants of the rings, we only set this
  3668. * stuff once. This works because the card does not
  3669. * write into the rx buffer posting rings.
  3670. */
  3671. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3672. struct tg3_rx_buffer_desc *rxd;
  3673. rxd = &tp->rx_std[i];
  3674. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3675. << RXD_LEN_SHIFT;
  3676. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3677. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3678. (i << RXD_OPAQUE_INDEX_SHIFT));
  3679. }
  3680. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3681. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3682. struct tg3_rx_buffer_desc *rxd;
  3683. rxd = &tp->rx_jumbo[i];
  3684. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3685. << RXD_LEN_SHIFT;
  3686. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3687. RXD_FLAG_JUMBO;
  3688. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3689. (i << RXD_OPAQUE_INDEX_SHIFT));
  3690. }
  3691. }
  3692. /* Now allocate fresh SKBs for each rx ring. */
  3693. for (i = 0; i < tp->rx_pending; i++) {
  3694. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3695. printk(KERN_WARNING PFX
  3696. "%s: Using a smaller RX standard ring, "
  3697. "only %d out of %d buffers were allocated "
  3698. "successfully.\n",
  3699. tp->dev->name, i, tp->rx_pending);
  3700. if (i == 0)
  3701. return -ENOMEM;
  3702. tp->rx_pending = i;
  3703. break;
  3704. }
  3705. }
  3706. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3707. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3708. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3709. -1, i) < 0) {
  3710. printk(KERN_WARNING PFX
  3711. "%s: Using a smaller RX jumbo ring, "
  3712. "only %d out of %d buffers were "
  3713. "allocated successfully.\n",
  3714. tp->dev->name, i, tp->rx_jumbo_pending);
  3715. if (i == 0) {
  3716. tg3_free_rings(tp);
  3717. return -ENOMEM;
  3718. }
  3719. tp->rx_jumbo_pending = i;
  3720. break;
  3721. }
  3722. }
  3723. }
  3724. return 0;
  3725. }
  3726. /*
  3727. * Must not be invoked with interrupt sources disabled and
  3728. * the hardware shutdown down.
  3729. */
  3730. static void tg3_free_consistent(struct tg3 *tp)
  3731. {
  3732. kfree(tp->rx_std_buffers);
  3733. tp->rx_std_buffers = NULL;
  3734. if (tp->rx_std) {
  3735. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3736. tp->rx_std, tp->rx_std_mapping);
  3737. tp->rx_std = NULL;
  3738. }
  3739. if (tp->rx_jumbo) {
  3740. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3741. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3742. tp->rx_jumbo = NULL;
  3743. }
  3744. if (tp->rx_rcb) {
  3745. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3746. tp->rx_rcb, tp->rx_rcb_mapping);
  3747. tp->rx_rcb = NULL;
  3748. }
  3749. if (tp->tx_ring) {
  3750. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3751. tp->tx_ring, tp->tx_desc_mapping);
  3752. tp->tx_ring = NULL;
  3753. }
  3754. if (tp->hw_status) {
  3755. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3756. tp->hw_status, tp->status_mapping);
  3757. tp->hw_status = NULL;
  3758. }
  3759. if (tp->hw_stats) {
  3760. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3761. tp->hw_stats, tp->stats_mapping);
  3762. tp->hw_stats = NULL;
  3763. }
  3764. }
  3765. /*
  3766. * Must not be invoked with interrupt sources disabled and
  3767. * the hardware shutdown down. Can sleep.
  3768. */
  3769. static int tg3_alloc_consistent(struct tg3 *tp)
  3770. {
  3771. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  3772. (TG3_RX_RING_SIZE +
  3773. TG3_RX_JUMBO_RING_SIZE)) +
  3774. (sizeof(struct tx_ring_info) *
  3775. TG3_TX_RING_SIZE),
  3776. GFP_KERNEL);
  3777. if (!tp->rx_std_buffers)
  3778. return -ENOMEM;
  3779. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3780. tp->tx_buffers = (struct tx_ring_info *)
  3781. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3782. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3783. &tp->rx_std_mapping);
  3784. if (!tp->rx_std)
  3785. goto err_out;
  3786. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3787. &tp->rx_jumbo_mapping);
  3788. if (!tp->rx_jumbo)
  3789. goto err_out;
  3790. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3791. &tp->rx_rcb_mapping);
  3792. if (!tp->rx_rcb)
  3793. goto err_out;
  3794. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3795. &tp->tx_desc_mapping);
  3796. if (!tp->tx_ring)
  3797. goto err_out;
  3798. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3799. TG3_HW_STATUS_SIZE,
  3800. &tp->status_mapping);
  3801. if (!tp->hw_status)
  3802. goto err_out;
  3803. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3804. sizeof(struct tg3_hw_stats),
  3805. &tp->stats_mapping);
  3806. if (!tp->hw_stats)
  3807. goto err_out;
  3808. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3809. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3810. return 0;
  3811. err_out:
  3812. tg3_free_consistent(tp);
  3813. return -ENOMEM;
  3814. }
  3815. #define MAX_WAIT_CNT 1000
  3816. /* To stop a block, clear the enable bit and poll till it
  3817. * clears. tp->lock is held.
  3818. */
  3819. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3820. {
  3821. unsigned int i;
  3822. u32 val;
  3823. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3824. switch (ofs) {
  3825. case RCVLSC_MODE:
  3826. case DMAC_MODE:
  3827. case MBFREE_MODE:
  3828. case BUFMGR_MODE:
  3829. case MEMARB_MODE:
  3830. /* We can't enable/disable these bits of the
  3831. * 5705/5750, just say success.
  3832. */
  3833. return 0;
  3834. default:
  3835. break;
  3836. };
  3837. }
  3838. val = tr32(ofs);
  3839. val &= ~enable_bit;
  3840. tw32_f(ofs, val);
  3841. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3842. udelay(100);
  3843. val = tr32(ofs);
  3844. if ((val & enable_bit) == 0)
  3845. break;
  3846. }
  3847. if (i == MAX_WAIT_CNT && !silent) {
  3848. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3849. "ofs=%lx enable_bit=%x\n",
  3850. ofs, enable_bit);
  3851. return -ENODEV;
  3852. }
  3853. return 0;
  3854. }
  3855. /* tp->lock is held. */
  3856. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3857. {
  3858. int i, err;
  3859. tg3_disable_ints(tp);
  3860. tp->rx_mode &= ~RX_MODE_ENABLE;
  3861. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3862. udelay(10);
  3863. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3864. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3865. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3866. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3867. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3868. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3869. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3870. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3871. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3872. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3873. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3874. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3875. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3876. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3877. tw32_f(MAC_MODE, tp->mac_mode);
  3878. udelay(40);
  3879. tp->tx_mode &= ~TX_MODE_ENABLE;
  3880. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3881. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3882. udelay(100);
  3883. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3884. break;
  3885. }
  3886. if (i >= MAX_WAIT_CNT) {
  3887. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3888. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3889. tp->dev->name, tr32(MAC_TX_MODE));
  3890. err |= -ENODEV;
  3891. }
  3892. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3893. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3894. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3895. tw32(FTQ_RESET, 0xffffffff);
  3896. tw32(FTQ_RESET, 0x00000000);
  3897. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3898. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3899. if (tp->hw_status)
  3900. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3901. if (tp->hw_stats)
  3902. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3903. return err;
  3904. }
  3905. /* tp->lock is held. */
  3906. static int tg3_nvram_lock(struct tg3 *tp)
  3907. {
  3908. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3909. int i;
  3910. if (tp->nvram_lock_cnt == 0) {
  3911. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3912. for (i = 0; i < 8000; i++) {
  3913. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3914. break;
  3915. udelay(20);
  3916. }
  3917. if (i == 8000) {
  3918. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3919. return -ENODEV;
  3920. }
  3921. }
  3922. tp->nvram_lock_cnt++;
  3923. }
  3924. return 0;
  3925. }
  3926. /* tp->lock is held. */
  3927. static void tg3_nvram_unlock(struct tg3 *tp)
  3928. {
  3929. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3930. if (tp->nvram_lock_cnt > 0)
  3931. tp->nvram_lock_cnt--;
  3932. if (tp->nvram_lock_cnt == 0)
  3933. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3934. }
  3935. }
  3936. /* tp->lock is held. */
  3937. static void tg3_enable_nvram_access(struct tg3 *tp)
  3938. {
  3939. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3940. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3941. u32 nvaccess = tr32(NVRAM_ACCESS);
  3942. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3943. }
  3944. }
  3945. /* tp->lock is held. */
  3946. static void tg3_disable_nvram_access(struct tg3 *tp)
  3947. {
  3948. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3949. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3950. u32 nvaccess = tr32(NVRAM_ACCESS);
  3951. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3952. }
  3953. }
  3954. /* tp->lock is held. */
  3955. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3956. {
  3957. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3958. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3959. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3960. switch (kind) {
  3961. case RESET_KIND_INIT:
  3962. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3963. DRV_STATE_START);
  3964. break;
  3965. case RESET_KIND_SHUTDOWN:
  3966. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3967. DRV_STATE_UNLOAD);
  3968. break;
  3969. case RESET_KIND_SUSPEND:
  3970. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3971. DRV_STATE_SUSPEND);
  3972. break;
  3973. default:
  3974. break;
  3975. };
  3976. }
  3977. }
  3978. /* tp->lock is held. */
  3979. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  3980. {
  3981. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3982. switch (kind) {
  3983. case RESET_KIND_INIT:
  3984. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3985. DRV_STATE_START_DONE);
  3986. break;
  3987. case RESET_KIND_SHUTDOWN:
  3988. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  3989. DRV_STATE_UNLOAD_DONE);
  3990. break;
  3991. default:
  3992. break;
  3993. };
  3994. }
  3995. }
  3996. /* tp->lock is held. */
  3997. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  3998. {
  3999. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4000. switch (kind) {
  4001. case RESET_KIND_INIT:
  4002. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4003. DRV_STATE_START);
  4004. break;
  4005. case RESET_KIND_SHUTDOWN:
  4006. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4007. DRV_STATE_UNLOAD);
  4008. break;
  4009. case RESET_KIND_SUSPEND:
  4010. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4011. DRV_STATE_SUSPEND);
  4012. break;
  4013. default:
  4014. break;
  4015. };
  4016. }
  4017. }
  4018. static int tg3_poll_fw(struct tg3 *tp)
  4019. {
  4020. int i;
  4021. u32 val;
  4022. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4023. /* Wait up to 20ms for init done. */
  4024. for (i = 0; i < 200; i++) {
  4025. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4026. return 0;
  4027. udelay(100);
  4028. }
  4029. return -ENODEV;
  4030. }
  4031. /* Wait for firmware initialization to complete. */
  4032. for (i = 0; i < 100000; i++) {
  4033. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4034. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4035. break;
  4036. udelay(10);
  4037. }
  4038. /* Chip might not be fitted with firmware. Some Sun onboard
  4039. * parts are configured like that. So don't signal the timeout
  4040. * of the above loop as an error, but do report the lack of
  4041. * running firmware once.
  4042. */
  4043. if (i >= 100000 &&
  4044. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4045. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4046. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4047. tp->dev->name);
  4048. }
  4049. return 0;
  4050. }
  4051. static void tg3_stop_fw(struct tg3 *);
  4052. /* tp->lock is held. */
  4053. static int tg3_chip_reset(struct tg3 *tp)
  4054. {
  4055. u32 val;
  4056. void (*write_op)(struct tg3 *, u32, u32);
  4057. int err;
  4058. tg3_nvram_lock(tp);
  4059. /* No matching tg3_nvram_unlock() after this because
  4060. * chip reset below will undo the nvram lock.
  4061. */
  4062. tp->nvram_lock_cnt = 0;
  4063. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4064. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4065. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  4066. tw32(GRC_FASTBOOT_PC, 0);
  4067. /*
  4068. * We must avoid the readl() that normally takes place.
  4069. * It locks machines, causes machine checks, and other
  4070. * fun things. So, temporarily disable the 5701
  4071. * hardware workaround, while we do the reset.
  4072. */
  4073. write_op = tp->write32;
  4074. if (write_op == tg3_write_flush_reg32)
  4075. tp->write32 = tg3_write32;
  4076. /* Prevent the irq handler from reading or writing PCI registers
  4077. * during chip reset when the memory enable bit in the PCI command
  4078. * register may be cleared. The chip does not generate interrupt
  4079. * at this time, but the irq handler may still be called due to irq
  4080. * sharing or irqpoll.
  4081. */
  4082. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4083. if (tp->hw_status) {
  4084. tp->hw_status->status = 0;
  4085. tp->hw_status->status_tag = 0;
  4086. }
  4087. tp->last_tag = 0;
  4088. smp_mb();
  4089. synchronize_irq(tp->pdev->irq);
  4090. /* do the reset */
  4091. val = GRC_MISC_CFG_CORECLK_RESET;
  4092. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4093. if (tr32(0x7e2c) == 0x60) {
  4094. tw32(0x7e2c, 0x20);
  4095. }
  4096. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4097. tw32(GRC_MISC_CFG, (1 << 29));
  4098. val |= (1 << 29);
  4099. }
  4100. }
  4101. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4102. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4103. tw32(GRC_VCPU_EXT_CTRL,
  4104. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4105. }
  4106. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4107. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4108. tw32(GRC_MISC_CFG, val);
  4109. /* restore 5701 hardware bug workaround write method */
  4110. tp->write32 = write_op;
  4111. /* Unfortunately, we have to delay before the PCI read back.
  4112. * Some 575X chips even will not respond to a PCI cfg access
  4113. * when the reset command is given to the chip.
  4114. *
  4115. * How do these hardware designers expect things to work
  4116. * properly if the PCI write is posted for a long period
  4117. * of time? It is always necessary to have some method by
  4118. * which a register read back can occur to push the write
  4119. * out which does the reset.
  4120. *
  4121. * For most tg3 variants the trick below was working.
  4122. * Ho hum...
  4123. */
  4124. udelay(120);
  4125. /* Flush PCI posted writes. The normal MMIO registers
  4126. * are inaccessible at this time so this is the only
  4127. * way to make this reliably (actually, this is no longer
  4128. * the case, see above). I tried to use indirect
  4129. * register read/write but this upset some 5701 variants.
  4130. */
  4131. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4132. udelay(120);
  4133. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4134. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4135. int i;
  4136. u32 cfg_val;
  4137. /* Wait for link training to complete. */
  4138. for (i = 0; i < 5000; i++)
  4139. udelay(100);
  4140. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4141. pci_write_config_dword(tp->pdev, 0xc4,
  4142. cfg_val | (1 << 15));
  4143. }
  4144. /* Set PCIE max payload size and clear error status. */
  4145. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4146. }
  4147. /* Re-enable indirect register accesses. */
  4148. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4149. tp->misc_host_ctrl);
  4150. /* Set MAX PCI retry to zero. */
  4151. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4152. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4153. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4154. val |= PCISTATE_RETRY_SAME_DMA;
  4155. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4156. pci_restore_state(tp->pdev);
  4157. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4158. /* Make sure PCI-X relaxed ordering bit is clear. */
  4159. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4160. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4161. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4162. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4163. u32 val;
  4164. /* Chip reset on 5780 will reset MSI enable bit,
  4165. * so need to restore it.
  4166. */
  4167. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4168. u16 ctrl;
  4169. pci_read_config_word(tp->pdev,
  4170. tp->msi_cap + PCI_MSI_FLAGS,
  4171. &ctrl);
  4172. pci_write_config_word(tp->pdev,
  4173. tp->msi_cap + PCI_MSI_FLAGS,
  4174. ctrl | PCI_MSI_FLAGS_ENABLE);
  4175. val = tr32(MSGINT_MODE);
  4176. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4177. }
  4178. val = tr32(MEMARB_MODE);
  4179. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4180. } else
  4181. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4182. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4183. tg3_stop_fw(tp);
  4184. tw32(0x5000, 0x400);
  4185. }
  4186. tw32(GRC_MODE, tp->grc_mode);
  4187. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4188. u32 val = tr32(0xc4);
  4189. tw32(0xc4, val | (1 << 15));
  4190. }
  4191. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4192. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4193. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4194. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4195. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4196. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4197. }
  4198. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4199. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4200. tw32_f(MAC_MODE, tp->mac_mode);
  4201. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4202. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4203. tw32_f(MAC_MODE, tp->mac_mode);
  4204. } else
  4205. tw32_f(MAC_MODE, 0);
  4206. udelay(40);
  4207. err = tg3_poll_fw(tp);
  4208. if (err)
  4209. return err;
  4210. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4211. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4212. u32 val = tr32(0x7c00);
  4213. tw32(0x7c00, val | (1 << 25));
  4214. }
  4215. /* Reprobe ASF enable state. */
  4216. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4217. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4218. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4219. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4220. u32 nic_cfg;
  4221. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4222. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4223. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4224. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4225. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4226. }
  4227. }
  4228. return 0;
  4229. }
  4230. /* tp->lock is held. */
  4231. static void tg3_stop_fw(struct tg3 *tp)
  4232. {
  4233. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4234. u32 val;
  4235. int i;
  4236. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4237. val = tr32(GRC_RX_CPU_EVENT);
  4238. val |= (1 << 14);
  4239. tw32(GRC_RX_CPU_EVENT, val);
  4240. /* Wait for RX cpu to ACK the event. */
  4241. for (i = 0; i < 100; i++) {
  4242. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4243. break;
  4244. udelay(1);
  4245. }
  4246. }
  4247. }
  4248. /* tp->lock is held. */
  4249. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4250. {
  4251. int err;
  4252. tg3_stop_fw(tp);
  4253. tg3_write_sig_pre_reset(tp, kind);
  4254. tg3_abort_hw(tp, silent);
  4255. err = tg3_chip_reset(tp);
  4256. tg3_write_sig_legacy(tp, kind);
  4257. tg3_write_sig_post_reset(tp, kind);
  4258. if (err)
  4259. return err;
  4260. return 0;
  4261. }
  4262. #define TG3_FW_RELEASE_MAJOR 0x0
  4263. #define TG3_FW_RELASE_MINOR 0x0
  4264. #define TG3_FW_RELEASE_FIX 0x0
  4265. #define TG3_FW_START_ADDR 0x08000000
  4266. #define TG3_FW_TEXT_ADDR 0x08000000
  4267. #define TG3_FW_TEXT_LEN 0x9c0
  4268. #define TG3_FW_RODATA_ADDR 0x080009c0
  4269. #define TG3_FW_RODATA_LEN 0x60
  4270. #define TG3_FW_DATA_ADDR 0x08000a40
  4271. #define TG3_FW_DATA_LEN 0x20
  4272. #define TG3_FW_SBSS_ADDR 0x08000a60
  4273. #define TG3_FW_SBSS_LEN 0xc
  4274. #define TG3_FW_BSS_ADDR 0x08000a70
  4275. #define TG3_FW_BSS_LEN 0x10
  4276. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4277. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4278. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4279. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4280. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4281. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4282. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4283. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4284. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4285. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4286. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4287. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4288. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4289. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4290. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4291. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4292. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4293. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4294. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4295. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4296. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4297. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4298. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4299. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4302. 0, 0, 0, 0, 0, 0,
  4303. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4304. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4305. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4306. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4307. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4308. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4309. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4310. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4311. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4312. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4313. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4317. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4318. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4319. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4320. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4321. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4322. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4323. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4324. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4325. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4326. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4327. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4328. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4329. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4330. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4331. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4332. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4333. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4334. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4335. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4336. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4337. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4338. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4339. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4340. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4341. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4342. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4343. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4344. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4345. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4346. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4347. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4348. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4349. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4350. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4351. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4352. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4353. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4354. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4355. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4356. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4357. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4358. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4359. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4360. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4361. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4362. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4363. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4364. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4365. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4366. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4367. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4368. };
  4369. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4370. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4371. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4372. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4373. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4374. 0x00000000
  4375. };
  4376. #if 0 /* All zeros, don't eat up space with it. */
  4377. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4378. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4379. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4380. };
  4381. #endif
  4382. #define RX_CPU_SCRATCH_BASE 0x30000
  4383. #define RX_CPU_SCRATCH_SIZE 0x04000
  4384. #define TX_CPU_SCRATCH_BASE 0x34000
  4385. #define TX_CPU_SCRATCH_SIZE 0x04000
  4386. /* tp->lock is held. */
  4387. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4388. {
  4389. int i;
  4390. BUG_ON(offset == TX_CPU_BASE &&
  4391. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4392. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4393. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4394. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4395. return 0;
  4396. }
  4397. if (offset == RX_CPU_BASE) {
  4398. for (i = 0; i < 10000; i++) {
  4399. tw32(offset + CPU_STATE, 0xffffffff);
  4400. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4401. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4402. break;
  4403. }
  4404. tw32(offset + CPU_STATE, 0xffffffff);
  4405. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4406. udelay(10);
  4407. } else {
  4408. for (i = 0; i < 10000; i++) {
  4409. tw32(offset + CPU_STATE, 0xffffffff);
  4410. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4411. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4412. break;
  4413. }
  4414. }
  4415. if (i >= 10000) {
  4416. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4417. "and %s CPU\n",
  4418. tp->dev->name,
  4419. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4420. return -ENODEV;
  4421. }
  4422. /* Clear firmware's nvram arbitration. */
  4423. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4424. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4425. return 0;
  4426. }
  4427. struct fw_info {
  4428. unsigned int text_base;
  4429. unsigned int text_len;
  4430. const u32 *text_data;
  4431. unsigned int rodata_base;
  4432. unsigned int rodata_len;
  4433. const u32 *rodata_data;
  4434. unsigned int data_base;
  4435. unsigned int data_len;
  4436. const u32 *data_data;
  4437. };
  4438. /* tp->lock is held. */
  4439. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4440. int cpu_scratch_size, struct fw_info *info)
  4441. {
  4442. int err, lock_err, i;
  4443. void (*write_op)(struct tg3 *, u32, u32);
  4444. if (cpu_base == TX_CPU_BASE &&
  4445. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4446. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4447. "TX cpu firmware on %s which is 5705.\n",
  4448. tp->dev->name);
  4449. return -EINVAL;
  4450. }
  4451. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4452. write_op = tg3_write_mem;
  4453. else
  4454. write_op = tg3_write_indirect_reg32;
  4455. /* It is possible that bootcode is still loading at this point.
  4456. * Get the nvram lock first before halting the cpu.
  4457. */
  4458. lock_err = tg3_nvram_lock(tp);
  4459. err = tg3_halt_cpu(tp, cpu_base);
  4460. if (!lock_err)
  4461. tg3_nvram_unlock(tp);
  4462. if (err)
  4463. goto out;
  4464. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4465. write_op(tp, cpu_scratch_base + i, 0);
  4466. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4467. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4468. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4469. write_op(tp, (cpu_scratch_base +
  4470. (info->text_base & 0xffff) +
  4471. (i * sizeof(u32))),
  4472. (info->text_data ?
  4473. info->text_data[i] : 0));
  4474. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4475. write_op(tp, (cpu_scratch_base +
  4476. (info->rodata_base & 0xffff) +
  4477. (i * sizeof(u32))),
  4478. (info->rodata_data ?
  4479. info->rodata_data[i] : 0));
  4480. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4481. write_op(tp, (cpu_scratch_base +
  4482. (info->data_base & 0xffff) +
  4483. (i * sizeof(u32))),
  4484. (info->data_data ?
  4485. info->data_data[i] : 0));
  4486. err = 0;
  4487. out:
  4488. return err;
  4489. }
  4490. /* tp->lock is held. */
  4491. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4492. {
  4493. struct fw_info info;
  4494. int err, i;
  4495. info.text_base = TG3_FW_TEXT_ADDR;
  4496. info.text_len = TG3_FW_TEXT_LEN;
  4497. info.text_data = &tg3FwText[0];
  4498. info.rodata_base = TG3_FW_RODATA_ADDR;
  4499. info.rodata_len = TG3_FW_RODATA_LEN;
  4500. info.rodata_data = &tg3FwRodata[0];
  4501. info.data_base = TG3_FW_DATA_ADDR;
  4502. info.data_len = TG3_FW_DATA_LEN;
  4503. info.data_data = NULL;
  4504. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4505. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4506. &info);
  4507. if (err)
  4508. return err;
  4509. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4510. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4511. &info);
  4512. if (err)
  4513. return err;
  4514. /* Now startup only the RX cpu. */
  4515. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4516. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4517. for (i = 0; i < 5; i++) {
  4518. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4519. break;
  4520. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4521. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4522. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4523. udelay(1000);
  4524. }
  4525. if (i >= 5) {
  4526. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4527. "to set RX CPU PC, is %08x should be %08x\n",
  4528. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4529. TG3_FW_TEXT_ADDR);
  4530. return -ENODEV;
  4531. }
  4532. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4533. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4534. return 0;
  4535. }
  4536. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4537. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4538. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4539. #define TG3_TSO_FW_START_ADDR 0x08000000
  4540. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4541. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4542. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4543. #define TG3_TSO_FW_RODATA_LEN 0x60
  4544. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4545. #define TG3_TSO_FW_DATA_LEN 0x30
  4546. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4547. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4548. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4549. #define TG3_TSO_FW_BSS_LEN 0x894
  4550. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4551. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4552. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4553. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4554. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4555. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4556. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4557. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4558. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4559. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4560. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4561. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4562. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4563. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4564. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4565. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4566. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4567. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4568. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4569. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4570. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4571. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4572. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4573. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4574. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4575. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4576. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4577. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4578. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4579. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4580. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4581. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4582. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4583. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4584. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4585. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4586. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4587. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4588. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4589. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4590. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4591. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4592. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4593. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4594. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4595. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4596. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4597. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4598. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4599. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4600. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4601. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4602. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4603. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4604. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4605. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4606. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4607. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4608. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4609. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4610. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4611. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4612. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4613. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4614. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4615. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4616. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4617. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4618. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4619. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4620. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4621. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4622. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4623. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4624. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4625. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4626. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4627. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4628. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4629. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4630. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4631. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4632. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4633. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4634. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4635. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4636. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4637. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4638. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4639. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4640. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4641. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4642. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4643. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4644. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4645. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4646. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4647. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4648. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4649. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4650. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4651. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4652. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4653. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4654. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4655. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4656. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4657. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4658. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4659. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4660. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4661. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4662. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4663. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4664. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4665. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4666. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4667. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4668. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4669. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4670. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4671. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4672. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4673. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4674. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4675. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4676. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4677. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4678. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4679. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4680. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4681. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4682. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4683. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4684. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4685. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4686. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4687. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4688. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4689. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4690. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4691. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4692. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4693. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4694. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4695. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4696. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4697. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4698. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4699. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4700. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4701. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4702. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4703. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4704. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4705. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4706. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4707. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4708. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4709. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4710. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4711. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4712. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4713. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4714. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4715. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4716. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4717. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4718. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4719. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4720. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4721. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4722. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4723. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4724. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4725. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4726. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4727. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4728. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4729. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4730. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4731. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4732. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4733. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4734. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4735. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4736. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4737. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4738. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4739. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4740. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4741. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4742. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4743. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4744. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4745. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4746. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4747. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4748. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4749. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4750. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4751. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4752. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4753. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4754. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4755. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4756. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4757. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4758. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4759. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4760. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4761. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4762. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4763. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4764. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4765. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4766. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4767. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4768. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4769. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4770. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4771. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4772. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4773. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4774. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4775. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4776. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4777. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4778. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4779. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4780. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4781. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4782. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4783. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4784. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4785. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4786. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4787. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4788. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4789. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4790. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4791. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4792. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4793. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4794. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4795. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4796. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4797. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4798. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4799. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4800. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4801. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4802. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4803. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4804. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4805. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4806. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4807. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4808. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4809. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4810. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4811. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4812. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4813. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4814. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4815. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4816. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4817. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4818. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4819. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4820. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4821. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4822. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4823. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4824. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4825. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4826. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4827. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4828. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4829. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4830. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4831. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4832. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4833. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4834. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4835. };
  4836. static const u32 tg3TsoFwRodata[] = {
  4837. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4838. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4839. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4840. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4841. 0x00000000,
  4842. };
  4843. static const u32 tg3TsoFwData[] = {
  4844. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4845. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4846. 0x00000000,
  4847. };
  4848. /* 5705 needs a special version of the TSO firmware. */
  4849. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4850. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4851. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4852. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4853. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4854. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4855. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4856. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4857. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4858. #define TG3_TSO5_FW_DATA_LEN 0x20
  4859. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4860. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4861. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4862. #define TG3_TSO5_FW_BSS_LEN 0x88
  4863. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4864. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4865. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4866. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4867. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4868. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4869. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4870. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4871. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4872. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4873. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4874. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4875. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4876. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4877. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4878. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4879. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4880. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4881. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4882. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4883. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4884. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4885. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4886. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4887. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4888. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4889. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4890. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4891. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4892. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4893. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4894. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4895. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4896. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4897. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4898. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4899. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4900. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4901. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4902. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4903. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4904. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4905. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4906. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4907. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4908. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4909. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4910. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4911. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4912. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4913. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4914. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4915. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4916. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4917. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4918. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4919. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4920. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4921. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4922. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4923. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4924. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4925. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4926. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4927. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4928. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4929. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4930. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4931. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4932. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4933. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4934. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4935. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4936. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4937. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4938. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4939. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4940. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4941. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4942. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4943. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4944. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4945. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4946. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4947. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4948. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4949. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4950. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4951. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4952. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4953. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4954. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4955. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4956. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4957. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4958. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4959. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4960. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4961. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4962. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  4963. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  4964. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  4965. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  4966. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  4967. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  4968. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  4969. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  4970. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4971. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4972. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  4973. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  4974. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  4975. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  4976. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  4977. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  4978. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  4979. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  4980. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  4981. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  4982. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  4983. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  4984. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  4985. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  4986. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  4987. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4988. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  4989. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  4990. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  4991. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  4992. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  4993. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  4994. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  4995. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  4996. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  4997. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  4998. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  4999. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  5000. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  5001. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  5002. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  5003. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  5004. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  5005. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  5006. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  5007. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  5008. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  5009. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  5010. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  5011. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  5012. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  5013. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  5014. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  5015. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  5016. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5017. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5018. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5019. 0x00000000, 0x00000000, 0x00000000,
  5020. };
  5021. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5022. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5023. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5024. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5025. 0x00000000, 0x00000000, 0x00000000,
  5026. };
  5027. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5028. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5029. 0x00000000, 0x00000000, 0x00000000,
  5030. };
  5031. /* tp->lock is held. */
  5032. static int tg3_load_tso_firmware(struct tg3 *tp)
  5033. {
  5034. struct fw_info info;
  5035. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5036. int err, i;
  5037. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5038. return 0;
  5039. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5040. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5041. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5042. info.text_data = &tg3Tso5FwText[0];
  5043. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5044. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5045. info.rodata_data = &tg3Tso5FwRodata[0];
  5046. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5047. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5048. info.data_data = &tg3Tso5FwData[0];
  5049. cpu_base = RX_CPU_BASE;
  5050. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5051. cpu_scratch_size = (info.text_len +
  5052. info.rodata_len +
  5053. info.data_len +
  5054. TG3_TSO5_FW_SBSS_LEN +
  5055. TG3_TSO5_FW_BSS_LEN);
  5056. } else {
  5057. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5058. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5059. info.text_data = &tg3TsoFwText[0];
  5060. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5061. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5062. info.rodata_data = &tg3TsoFwRodata[0];
  5063. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5064. info.data_len = TG3_TSO_FW_DATA_LEN;
  5065. info.data_data = &tg3TsoFwData[0];
  5066. cpu_base = TX_CPU_BASE;
  5067. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5068. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5069. }
  5070. err = tg3_load_firmware_cpu(tp, cpu_base,
  5071. cpu_scratch_base, cpu_scratch_size,
  5072. &info);
  5073. if (err)
  5074. return err;
  5075. /* Now startup the cpu. */
  5076. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5077. tw32_f(cpu_base + CPU_PC, info.text_base);
  5078. for (i = 0; i < 5; i++) {
  5079. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5080. break;
  5081. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5082. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5083. tw32_f(cpu_base + CPU_PC, info.text_base);
  5084. udelay(1000);
  5085. }
  5086. if (i >= 5) {
  5087. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5088. "to set CPU PC, is %08x should be %08x\n",
  5089. tp->dev->name, tr32(cpu_base + CPU_PC),
  5090. info.text_base);
  5091. return -ENODEV;
  5092. }
  5093. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5094. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5095. return 0;
  5096. }
  5097. /* tp->lock is held. */
  5098. static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
  5099. {
  5100. u32 addr_high, addr_low;
  5101. int i;
  5102. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5103. tp->dev->dev_addr[1]);
  5104. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5105. (tp->dev->dev_addr[3] << 16) |
  5106. (tp->dev->dev_addr[4] << 8) |
  5107. (tp->dev->dev_addr[5] << 0));
  5108. for (i = 0; i < 4; i++) {
  5109. if (i == 1 && skip_mac_1)
  5110. continue;
  5111. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5112. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5113. }
  5114. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5115. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5116. for (i = 0; i < 12; i++) {
  5117. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5118. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5119. }
  5120. }
  5121. addr_high = (tp->dev->dev_addr[0] +
  5122. tp->dev->dev_addr[1] +
  5123. tp->dev->dev_addr[2] +
  5124. tp->dev->dev_addr[3] +
  5125. tp->dev->dev_addr[4] +
  5126. tp->dev->dev_addr[5]) &
  5127. TX_BACKOFF_SEED_MASK;
  5128. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5129. }
  5130. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5131. {
  5132. struct tg3 *tp = netdev_priv(dev);
  5133. struct sockaddr *addr = p;
  5134. int err = 0, skip_mac_1 = 0;
  5135. if (!is_valid_ether_addr(addr->sa_data))
  5136. return -EINVAL;
  5137. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5138. if (!netif_running(dev))
  5139. return 0;
  5140. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5141. u32 addr0_high, addr0_low, addr1_high, addr1_low;
  5142. addr0_high = tr32(MAC_ADDR_0_HIGH);
  5143. addr0_low = tr32(MAC_ADDR_0_LOW);
  5144. addr1_high = tr32(MAC_ADDR_1_HIGH);
  5145. addr1_low = tr32(MAC_ADDR_1_LOW);
  5146. /* Skip MAC addr 1 if ASF is using it. */
  5147. if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
  5148. !(addr1_high == 0 && addr1_low == 0))
  5149. skip_mac_1 = 1;
  5150. }
  5151. spin_lock_bh(&tp->lock);
  5152. __tg3_set_mac_addr(tp, skip_mac_1);
  5153. spin_unlock_bh(&tp->lock);
  5154. return err;
  5155. }
  5156. /* tp->lock is held. */
  5157. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5158. dma_addr_t mapping, u32 maxlen_flags,
  5159. u32 nic_addr)
  5160. {
  5161. tg3_write_mem(tp,
  5162. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5163. ((u64) mapping >> 32));
  5164. tg3_write_mem(tp,
  5165. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5166. ((u64) mapping & 0xffffffff));
  5167. tg3_write_mem(tp,
  5168. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5169. maxlen_flags);
  5170. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5171. tg3_write_mem(tp,
  5172. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5173. nic_addr);
  5174. }
  5175. static void __tg3_set_rx_mode(struct net_device *);
  5176. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5177. {
  5178. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5179. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5180. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5181. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5182. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5183. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5184. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5185. }
  5186. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5187. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5188. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5189. u32 val = ec->stats_block_coalesce_usecs;
  5190. if (!netif_carrier_ok(tp->dev))
  5191. val = 0;
  5192. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5193. }
  5194. }
  5195. /* tp->lock is held. */
  5196. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5197. {
  5198. u32 val, rdmac_mode;
  5199. int i, err, limit;
  5200. tg3_disable_ints(tp);
  5201. tg3_stop_fw(tp);
  5202. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5203. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5204. tg3_abort_hw(tp, 1);
  5205. }
  5206. if (reset_phy)
  5207. tg3_phy_reset(tp);
  5208. err = tg3_chip_reset(tp);
  5209. if (err)
  5210. return err;
  5211. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5212. /* This works around an issue with Athlon chipsets on
  5213. * B3 tigon3 silicon. This bit has no effect on any
  5214. * other revision. But do not set this on PCI Express
  5215. * chips.
  5216. */
  5217. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5218. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5219. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5220. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5221. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5222. val = tr32(TG3PCI_PCISTATE);
  5223. val |= PCISTATE_RETRY_SAME_DMA;
  5224. tw32(TG3PCI_PCISTATE, val);
  5225. }
  5226. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5227. /* Enable some hw fixes. */
  5228. val = tr32(TG3PCI_MSI_DATA);
  5229. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5230. tw32(TG3PCI_MSI_DATA, val);
  5231. }
  5232. /* Descriptor ring init may make accesses to the
  5233. * NIC SRAM area to setup the TX descriptors, so we
  5234. * can only do this after the hardware has been
  5235. * successfully reset.
  5236. */
  5237. err = tg3_init_rings(tp);
  5238. if (err)
  5239. return err;
  5240. /* This value is determined during the probe time DMA
  5241. * engine test, tg3_test_dma.
  5242. */
  5243. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5244. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5245. GRC_MODE_4X_NIC_SEND_RINGS |
  5246. GRC_MODE_NO_TX_PHDR_CSUM |
  5247. GRC_MODE_NO_RX_PHDR_CSUM);
  5248. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5249. /* Pseudo-header checksum is done by hardware logic and not
  5250. * the offload processers, so make the chip do the pseudo-
  5251. * header checksums on receive. For transmit it is more
  5252. * convenient to do the pseudo-header checksum in software
  5253. * as Linux does that on transmit for us in all cases.
  5254. */
  5255. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5256. tw32(GRC_MODE,
  5257. tp->grc_mode |
  5258. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5259. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5260. val = tr32(GRC_MISC_CFG);
  5261. val &= ~0xff;
  5262. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5263. tw32(GRC_MISC_CFG, val);
  5264. /* Initialize MBUF/DESC pool. */
  5265. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5266. /* Do nothing. */
  5267. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5268. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5269. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5270. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5271. else
  5272. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5273. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5274. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5275. }
  5276. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5277. int fw_len;
  5278. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5279. TG3_TSO5_FW_RODATA_LEN +
  5280. TG3_TSO5_FW_DATA_LEN +
  5281. TG3_TSO5_FW_SBSS_LEN +
  5282. TG3_TSO5_FW_BSS_LEN);
  5283. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5284. tw32(BUFMGR_MB_POOL_ADDR,
  5285. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5286. tw32(BUFMGR_MB_POOL_SIZE,
  5287. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5288. }
  5289. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5290. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5291. tp->bufmgr_config.mbuf_read_dma_low_water);
  5292. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5293. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5294. tw32(BUFMGR_MB_HIGH_WATER,
  5295. tp->bufmgr_config.mbuf_high_water);
  5296. } else {
  5297. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5298. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5299. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5300. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5301. tw32(BUFMGR_MB_HIGH_WATER,
  5302. tp->bufmgr_config.mbuf_high_water_jumbo);
  5303. }
  5304. tw32(BUFMGR_DMA_LOW_WATER,
  5305. tp->bufmgr_config.dma_low_water);
  5306. tw32(BUFMGR_DMA_HIGH_WATER,
  5307. tp->bufmgr_config.dma_high_water);
  5308. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5309. for (i = 0; i < 2000; i++) {
  5310. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5311. break;
  5312. udelay(10);
  5313. }
  5314. if (i >= 2000) {
  5315. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5316. tp->dev->name);
  5317. return -ENODEV;
  5318. }
  5319. /* Setup replenish threshold. */
  5320. val = tp->rx_pending / 8;
  5321. if (val == 0)
  5322. val = 1;
  5323. else if (val > tp->rx_std_max_post)
  5324. val = tp->rx_std_max_post;
  5325. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5326. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5327. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5328. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5329. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5330. }
  5331. tw32(RCVBDI_STD_THRESH, val);
  5332. /* Initialize TG3_BDINFO's at:
  5333. * RCVDBDI_STD_BD: standard eth size rx ring
  5334. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5335. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5336. *
  5337. * like so:
  5338. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5339. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5340. * ring attribute flags
  5341. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5342. *
  5343. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5344. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5345. *
  5346. * The size of each ring is fixed in the firmware, but the location is
  5347. * configurable.
  5348. */
  5349. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5350. ((u64) tp->rx_std_mapping >> 32));
  5351. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5352. ((u64) tp->rx_std_mapping & 0xffffffff));
  5353. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5354. NIC_SRAM_RX_BUFFER_DESC);
  5355. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5356. * configs on 5705.
  5357. */
  5358. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5359. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5360. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5361. } else {
  5362. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5363. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5364. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5365. BDINFO_FLAGS_DISABLED);
  5366. /* Setup replenish threshold. */
  5367. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5368. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5369. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5370. ((u64) tp->rx_jumbo_mapping >> 32));
  5371. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5372. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5373. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5374. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5375. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5376. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5377. } else {
  5378. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5379. BDINFO_FLAGS_DISABLED);
  5380. }
  5381. }
  5382. /* There is only one send ring on 5705/5750, no need to explicitly
  5383. * disable the others.
  5384. */
  5385. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5386. /* Clear out send RCB ring in SRAM. */
  5387. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5388. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5389. BDINFO_FLAGS_DISABLED);
  5390. }
  5391. tp->tx_prod = 0;
  5392. tp->tx_cons = 0;
  5393. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5394. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5395. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5396. tp->tx_desc_mapping,
  5397. (TG3_TX_RING_SIZE <<
  5398. BDINFO_FLAGS_MAXLEN_SHIFT),
  5399. NIC_SRAM_TX_BUFFER_DESC);
  5400. /* There is only one receive return ring on 5705/5750, no need
  5401. * to explicitly disable the others.
  5402. */
  5403. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5404. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5405. i += TG3_BDINFO_SIZE) {
  5406. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5407. BDINFO_FLAGS_DISABLED);
  5408. }
  5409. }
  5410. tp->rx_rcb_ptr = 0;
  5411. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5412. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5413. tp->rx_rcb_mapping,
  5414. (TG3_RX_RCB_RING_SIZE(tp) <<
  5415. BDINFO_FLAGS_MAXLEN_SHIFT),
  5416. 0);
  5417. tp->rx_std_ptr = tp->rx_pending;
  5418. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5419. tp->rx_std_ptr);
  5420. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5421. tp->rx_jumbo_pending : 0;
  5422. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5423. tp->rx_jumbo_ptr);
  5424. /* Initialize MAC address and backoff seed. */
  5425. __tg3_set_mac_addr(tp, 0);
  5426. /* MTU + ethernet header + FCS + optional VLAN tag */
  5427. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5428. /* The slot time is changed by tg3_setup_phy if we
  5429. * run at gigabit with half duplex.
  5430. */
  5431. tw32(MAC_TX_LENGTHS,
  5432. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5433. (6 << TX_LENGTHS_IPG_SHIFT) |
  5434. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5435. /* Receive rules. */
  5436. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5437. tw32(RCVLPC_CONFIG, 0x0181);
  5438. /* Calculate RDMAC_MODE setting early, we need it to determine
  5439. * the RCVLPC_STATE_ENABLE mask.
  5440. */
  5441. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5442. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5443. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5444. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5445. RDMAC_MODE_LNGREAD_ENAB);
  5446. /* If statement applies to 5705 and 5750 PCI devices only */
  5447. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5448. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5449. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5450. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5451. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5452. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5453. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5454. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5455. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5456. }
  5457. }
  5458. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5459. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5460. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5461. rdmac_mode |= (1 << 27);
  5462. /* Receive/send statistics. */
  5463. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5464. val = tr32(RCVLPC_STATS_ENABLE);
  5465. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5466. tw32(RCVLPC_STATS_ENABLE, val);
  5467. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5468. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5469. val = tr32(RCVLPC_STATS_ENABLE);
  5470. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5471. tw32(RCVLPC_STATS_ENABLE, val);
  5472. } else {
  5473. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5474. }
  5475. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5476. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5477. tw32(SNDDATAI_STATSCTRL,
  5478. (SNDDATAI_SCTRL_ENABLE |
  5479. SNDDATAI_SCTRL_FASTUPD));
  5480. /* Setup host coalescing engine. */
  5481. tw32(HOSTCC_MODE, 0);
  5482. for (i = 0; i < 2000; i++) {
  5483. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5484. break;
  5485. udelay(10);
  5486. }
  5487. __tg3_set_coalesce(tp, &tp->coal);
  5488. /* set status block DMA address */
  5489. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5490. ((u64) tp->status_mapping >> 32));
  5491. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5492. ((u64) tp->status_mapping & 0xffffffff));
  5493. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5494. /* Status/statistics block address. See tg3_timer,
  5495. * the tg3_periodic_fetch_stats call there, and
  5496. * tg3_get_stats to see how this works for 5705/5750 chips.
  5497. */
  5498. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5499. ((u64) tp->stats_mapping >> 32));
  5500. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5501. ((u64) tp->stats_mapping & 0xffffffff));
  5502. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5503. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5504. }
  5505. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5506. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5507. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5508. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5509. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5510. /* Clear statistics/status block in chip, and status block in ram. */
  5511. for (i = NIC_SRAM_STATS_BLK;
  5512. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5513. i += sizeof(u32)) {
  5514. tg3_write_mem(tp, i, 0);
  5515. udelay(40);
  5516. }
  5517. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5518. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5519. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5520. /* reset to prevent losing 1st rx packet intermittently */
  5521. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5522. udelay(10);
  5523. }
  5524. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5525. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5526. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5527. udelay(40);
  5528. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5529. * If TG3_FLG2_IS_NIC is zero, we should read the
  5530. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5531. * whether used as inputs or outputs, are set by boot code after
  5532. * reset.
  5533. */
  5534. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5535. u32 gpio_mask;
  5536. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5537. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5538. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5539. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5540. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5541. GRC_LCLCTRL_GPIO_OUTPUT3;
  5542. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5543. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5544. tp->grc_local_ctrl &= ~gpio_mask;
  5545. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5546. /* GPIO1 must be driven high for eeprom write protect */
  5547. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5548. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5549. GRC_LCLCTRL_GPIO_OUTPUT1);
  5550. }
  5551. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5552. udelay(100);
  5553. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5554. tp->last_tag = 0;
  5555. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5556. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5557. udelay(40);
  5558. }
  5559. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5560. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5561. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5562. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5563. WDMAC_MODE_LNGREAD_ENAB);
  5564. /* If statement applies to 5705 and 5750 PCI devices only */
  5565. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5566. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5567. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5568. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5569. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5570. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5571. /* nothing */
  5572. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5573. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5574. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5575. val |= WDMAC_MODE_RX_ACCEL;
  5576. }
  5577. }
  5578. /* Enable host coalescing bug fix */
  5579. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5580. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5581. val |= (1 << 29);
  5582. tw32_f(WDMAC_MODE, val);
  5583. udelay(40);
  5584. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5585. val = tr32(TG3PCI_X_CAPS);
  5586. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5587. val &= ~PCIX_CAPS_BURST_MASK;
  5588. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5589. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5590. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5591. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5592. }
  5593. tw32(TG3PCI_X_CAPS, val);
  5594. }
  5595. tw32_f(RDMAC_MODE, rdmac_mode);
  5596. udelay(40);
  5597. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5598. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5599. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5600. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5601. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5602. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5603. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5604. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5605. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5606. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5607. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5608. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5609. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5610. err = tg3_load_5701_a0_firmware_fix(tp);
  5611. if (err)
  5612. return err;
  5613. }
  5614. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5615. err = tg3_load_tso_firmware(tp);
  5616. if (err)
  5617. return err;
  5618. }
  5619. tp->tx_mode = TX_MODE_ENABLE;
  5620. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5621. udelay(100);
  5622. tp->rx_mode = RX_MODE_ENABLE;
  5623. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5624. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5625. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5626. udelay(10);
  5627. if (tp->link_config.phy_is_low_power) {
  5628. tp->link_config.phy_is_low_power = 0;
  5629. tp->link_config.speed = tp->link_config.orig_speed;
  5630. tp->link_config.duplex = tp->link_config.orig_duplex;
  5631. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5632. }
  5633. tp->mi_mode = MAC_MI_MODE_BASE;
  5634. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5635. udelay(80);
  5636. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5637. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5638. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5639. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5640. udelay(10);
  5641. }
  5642. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5643. udelay(10);
  5644. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5645. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5646. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5647. /* Set drive transmission level to 1.2V */
  5648. /* only if the signal pre-emphasis bit is not set */
  5649. val = tr32(MAC_SERDES_CFG);
  5650. val &= 0xfffff000;
  5651. val |= 0x880;
  5652. tw32(MAC_SERDES_CFG, val);
  5653. }
  5654. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5655. tw32(MAC_SERDES_CFG, 0x616000);
  5656. }
  5657. /* Prevent chip from dropping frames when flow control
  5658. * is enabled.
  5659. */
  5660. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5661. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5662. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5663. /* Use hardware link auto-negotiation */
  5664. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5665. }
  5666. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5667. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5668. u32 tmp;
  5669. tmp = tr32(SERDES_RX_CTRL);
  5670. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5671. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5672. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5673. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5674. }
  5675. err = tg3_setup_phy(tp, 0);
  5676. if (err)
  5677. return err;
  5678. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5679. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  5680. u32 tmp;
  5681. /* Clear CRC stats. */
  5682. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  5683. tg3_writephy(tp, MII_TG3_TEST1,
  5684. tmp | MII_TG3_TEST1_CRC_EN);
  5685. tg3_readphy(tp, 0x14, &tmp);
  5686. }
  5687. }
  5688. __tg3_set_rx_mode(tp->dev);
  5689. /* Initialize receive rules. */
  5690. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5691. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5692. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5693. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5694. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5695. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5696. limit = 8;
  5697. else
  5698. limit = 16;
  5699. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5700. limit -= 4;
  5701. switch (limit) {
  5702. case 16:
  5703. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5704. case 15:
  5705. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5706. case 14:
  5707. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5708. case 13:
  5709. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5710. case 12:
  5711. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5712. case 11:
  5713. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5714. case 10:
  5715. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5716. case 9:
  5717. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5718. case 8:
  5719. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5720. case 7:
  5721. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5722. case 6:
  5723. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5724. case 5:
  5725. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5726. case 4:
  5727. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5728. case 3:
  5729. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5730. case 2:
  5731. case 1:
  5732. default:
  5733. break;
  5734. };
  5735. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5736. return 0;
  5737. }
  5738. /* Called at device open time to get the chip ready for
  5739. * packet processing. Invoked with tp->lock held.
  5740. */
  5741. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5742. {
  5743. int err;
  5744. /* Force the chip into D0. */
  5745. err = tg3_set_power_state(tp, PCI_D0);
  5746. if (err)
  5747. goto out;
  5748. tg3_switch_clocks(tp);
  5749. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5750. err = tg3_reset_hw(tp, reset_phy);
  5751. out:
  5752. return err;
  5753. }
  5754. #define TG3_STAT_ADD32(PSTAT, REG) \
  5755. do { u32 __val = tr32(REG); \
  5756. (PSTAT)->low += __val; \
  5757. if ((PSTAT)->low < __val) \
  5758. (PSTAT)->high += 1; \
  5759. } while (0)
  5760. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5761. {
  5762. struct tg3_hw_stats *sp = tp->hw_stats;
  5763. if (!netif_carrier_ok(tp->dev))
  5764. return;
  5765. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5766. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5767. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5768. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5769. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5770. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5771. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5772. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5773. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5774. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5775. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5776. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5777. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5778. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5779. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5780. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5781. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5782. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5783. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5784. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5785. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5786. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5787. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5788. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5789. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5790. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5791. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5792. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5793. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5794. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5795. }
  5796. static void tg3_timer(unsigned long __opaque)
  5797. {
  5798. struct tg3 *tp = (struct tg3 *) __opaque;
  5799. if (tp->irq_sync)
  5800. goto restart_timer;
  5801. spin_lock(&tp->lock);
  5802. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5803. /* All of this garbage is because when using non-tagged
  5804. * IRQ status the mailbox/status_block protocol the chip
  5805. * uses with the cpu is race prone.
  5806. */
  5807. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5808. tw32(GRC_LOCAL_CTRL,
  5809. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5810. } else {
  5811. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5812. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5813. }
  5814. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5815. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5816. spin_unlock(&tp->lock);
  5817. schedule_work(&tp->reset_task);
  5818. return;
  5819. }
  5820. }
  5821. /* This part only runs once per second. */
  5822. if (!--tp->timer_counter) {
  5823. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5824. tg3_periodic_fetch_stats(tp);
  5825. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5826. u32 mac_stat;
  5827. int phy_event;
  5828. mac_stat = tr32(MAC_STATUS);
  5829. phy_event = 0;
  5830. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5831. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5832. phy_event = 1;
  5833. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5834. phy_event = 1;
  5835. if (phy_event)
  5836. tg3_setup_phy(tp, 0);
  5837. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5838. u32 mac_stat = tr32(MAC_STATUS);
  5839. int need_setup = 0;
  5840. if (netif_carrier_ok(tp->dev) &&
  5841. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5842. need_setup = 1;
  5843. }
  5844. if (! netif_carrier_ok(tp->dev) &&
  5845. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5846. MAC_STATUS_SIGNAL_DET))) {
  5847. need_setup = 1;
  5848. }
  5849. if (need_setup) {
  5850. if (!tp->serdes_counter) {
  5851. tw32_f(MAC_MODE,
  5852. (tp->mac_mode &
  5853. ~MAC_MODE_PORT_MODE_MASK));
  5854. udelay(40);
  5855. tw32_f(MAC_MODE, tp->mac_mode);
  5856. udelay(40);
  5857. }
  5858. tg3_setup_phy(tp, 0);
  5859. }
  5860. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5861. tg3_serdes_parallel_detect(tp);
  5862. tp->timer_counter = tp->timer_multiplier;
  5863. }
  5864. /* Heartbeat is only sent once every 2 seconds.
  5865. *
  5866. * The heartbeat is to tell the ASF firmware that the host
  5867. * driver is still alive. In the event that the OS crashes,
  5868. * ASF needs to reset the hardware to free up the FIFO space
  5869. * that may be filled with rx packets destined for the host.
  5870. * If the FIFO is full, ASF will no longer function properly.
  5871. *
  5872. * Unintended resets have been reported on real time kernels
  5873. * where the timer doesn't run on time. Netpoll will also have
  5874. * same problem.
  5875. *
  5876. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  5877. * to check the ring condition when the heartbeat is expiring
  5878. * before doing the reset. This will prevent most unintended
  5879. * resets.
  5880. */
  5881. if (!--tp->asf_counter) {
  5882. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5883. u32 val;
  5884. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5885. FWCMD_NICDRV_ALIVE3);
  5886. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5887. /* 5 seconds timeout */
  5888. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5889. val = tr32(GRC_RX_CPU_EVENT);
  5890. val |= (1 << 14);
  5891. tw32(GRC_RX_CPU_EVENT, val);
  5892. }
  5893. tp->asf_counter = tp->asf_multiplier;
  5894. }
  5895. spin_unlock(&tp->lock);
  5896. restart_timer:
  5897. tp->timer.expires = jiffies + tp->timer_offset;
  5898. add_timer(&tp->timer);
  5899. }
  5900. static int tg3_request_irq(struct tg3 *tp)
  5901. {
  5902. irq_handler_t fn;
  5903. unsigned long flags;
  5904. struct net_device *dev = tp->dev;
  5905. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5906. fn = tg3_msi;
  5907. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5908. fn = tg3_msi_1shot;
  5909. flags = IRQF_SAMPLE_RANDOM;
  5910. } else {
  5911. fn = tg3_interrupt;
  5912. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5913. fn = tg3_interrupt_tagged;
  5914. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5915. }
  5916. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5917. }
  5918. static int tg3_test_interrupt(struct tg3 *tp)
  5919. {
  5920. struct net_device *dev = tp->dev;
  5921. int err, i, intr_ok = 0;
  5922. if (!netif_running(dev))
  5923. return -ENODEV;
  5924. tg3_disable_ints(tp);
  5925. free_irq(tp->pdev->irq, dev);
  5926. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5927. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5928. if (err)
  5929. return err;
  5930. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5931. tg3_enable_ints(tp);
  5932. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5933. HOSTCC_MODE_NOW);
  5934. for (i = 0; i < 5; i++) {
  5935. u32 int_mbox, misc_host_ctrl;
  5936. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5937. TG3_64BIT_REG_LOW);
  5938. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  5939. if ((int_mbox != 0) ||
  5940. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  5941. intr_ok = 1;
  5942. break;
  5943. }
  5944. msleep(10);
  5945. }
  5946. tg3_disable_ints(tp);
  5947. free_irq(tp->pdev->irq, dev);
  5948. err = tg3_request_irq(tp);
  5949. if (err)
  5950. return err;
  5951. if (intr_ok)
  5952. return 0;
  5953. return -EIO;
  5954. }
  5955. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5956. * successfully restored
  5957. */
  5958. static int tg3_test_msi(struct tg3 *tp)
  5959. {
  5960. struct net_device *dev = tp->dev;
  5961. int err;
  5962. u16 pci_cmd;
  5963. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  5964. return 0;
  5965. /* Turn off SERR reporting in case MSI terminates with Master
  5966. * Abort.
  5967. */
  5968. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  5969. pci_write_config_word(tp->pdev, PCI_COMMAND,
  5970. pci_cmd & ~PCI_COMMAND_SERR);
  5971. err = tg3_test_interrupt(tp);
  5972. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  5973. if (!err)
  5974. return 0;
  5975. /* other failures */
  5976. if (err != -EIO)
  5977. return err;
  5978. /* MSI test failed, go back to INTx mode */
  5979. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  5980. "switching to INTx mode. Please report this failure to "
  5981. "the PCI maintainer and include system chipset information.\n",
  5982. tp->dev->name);
  5983. free_irq(tp->pdev->irq, dev);
  5984. pci_disable_msi(tp->pdev);
  5985. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  5986. err = tg3_request_irq(tp);
  5987. if (err)
  5988. return err;
  5989. /* Need to reset the chip because the MSI cycle may have terminated
  5990. * with Master Abort.
  5991. */
  5992. tg3_full_lock(tp, 1);
  5993. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  5994. err = tg3_init_hw(tp, 1);
  5995. tg3_full_unlock(tp);
  5996. if (err)
  5997. free_irq(tp->pdev->irq, dev);
  5998. return err;
  5999. }
  6000. static int tg3_open(struct net_device *dev)
  6001. {
  6002. struct tg3 *tp = netdev_priv(dev);
  6003. int err;
  6004. netif_carrier_off(tp->dev);
  6005. tg3_full_lock(tp, 0);
  6006. err = tg3_set_power_state(tp, PCI_D0);
  6007. if (err) {
  6008. tg3_full_unlock(tp);
  6009. return err;
  6010. }
  6011. tg3_disable_ints(tp);
  6012. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6013. tg3_full_unlock(tp);
  6014. /* The placement of this call is tied
  6015. * to the setup and use of Host TX descriptors.
  6016. */
  6017. err = tg3_alloc_consistent(tp);
  6018. if (err)
  6019. return err;
  6020. if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) {
  6021. /* All MSI supporting chips should support tagged
  6022. * status. Assert that this is the case.
  6023. */
  6024. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6025. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6026. "Not using MSI.\n", tp->dev->name);
  6027. } else if (pci_enable_msi(tp->pdev) == 0) {
  6028. u32 msi_mode;
  6029. msi_mode = tr32(MSGINT_MODE);
  6030. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6031. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6032. }
  6033. }
  6034. err = tg3_request_irq(tp);
  6035. if (err) {
  6036. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6037. pci_disable_msi(tp->pdev);
  6038. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6039. }
  6040. tg3_free_consistent(tp);
  6041. return err;
  6042. }
  6043. tg3_full_lock(tp, 0);
  6044. err = tg3_init_hw(tp, 1);
  6045. if (err) {
  6046. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6047. tg3_free_rings(tp);
  6048. } else {
  6049. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6050. tp->timer_offset = HZ;
  6051. else
  6052. tp->timer_offset = HZ / 10;
  6053. BUG_ON(tp->timer_offset > HZ);
  6054. tp->timer_counter = tp->timer_multiplier =
  6055. (HZ / tp->timer_offset);
  6056. tp->asf_counter = tp->asf_multiplier =
  6057. ((HZ / tp->timer_offset) * 2);
  6058. init_timer(&tp->timer);
  6059. tp->timer.expires = jiffies + tp->timer_offset;
  6060. tp->timer.data = (unsigned long) tp;
  6061. tp->timer.function = tg3_timer;
  6062. }
  6063. tg3_full_unlock(tp);
  6064. if (err) {
  6065. free_irq(tp->pdev->irq, dev);
  6066. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6067. pci_disable_msi(tp->pdev);
  6068. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6069. }
  6070. tg3_free_consistent(tp);
  6071. return err;
  6072. }
  6073. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6074. err = tg3_test_msi(tp);
  6075. if (err) {
  6076. tg3_full_lock(tp, 0);
  6077. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6078. pci_disable_msi(tp->pdev);
  6079. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6080. }
  6081. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6082. tg3_free_rings(tp);
  6083. tg3_free_consistent(tp);
  6084. tg3_full_unlock(tp);
  6085. return err;
  6086. }
  6087. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6088. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6089. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6090. tw32(PCIE_TRANSACTION_CFG,
  6091. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6092. }
  6093. }
  6094. }
  6095. tg3_full_lock(tp, 0);
  6096. add_timer(&tp->timer);
  6097. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6098. tg3_enable_ints(tp);
  6099. tg3_full_unlock(tp);
  6100. netif_start_queue(dev);
  6101. return 0;
  6102. }
  6103. #if 0
  6104. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6105. {
  6106. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6107. u16 val16;
  6108. int i;
  6109. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6110. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6111. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6112. val16, val32);
  6113. /* MAC block */
  6114. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6115. tr32(MAC_MODE), tr32(MAC_STATUS));
  6116. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6117. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6118. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6119. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6120. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6121. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6122. /* Send data initiator control block */
  6123. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6124. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6125. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6126. tr32(SNDDATAI_STATSCTRL));
  6127. /* Send data completion control block */
  6128. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6129. /* Send BD ring selector block */
  6130. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6131. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6132. /* Send BD initiator control block */
  6133. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6134. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6135. /* Send BD completion control block */
  6136. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6137. /* Receive list placement control block */
  6138. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6139. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6140. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6141. tr32(RCVLPC_STATSCTRL));
  6142. /* Receive data and receive BD initiator control block */
  6143. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6144. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6145. /* Receive data completion control block */
  6146. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6147. tr32(RCVDCC_MODE));
  6148. /* Receive BD initiator control block */
  6149. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6150. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6151. /* Receive BD completion control block */
  6152. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6153. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6154. /* Receive list selector control block */
  6155. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6156. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6157. /* Mbuf cluster free block */
  6158. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6159. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6160. /* Host coalescing control block */
  6161. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6162. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6163. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6164. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6165. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6166. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6167. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6168. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6169. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6170. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6171. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6172. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6173. /* Memory arbiter control block */
  6174. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6175. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6176. /* Buffer manager control block */
  6177. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6178. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6179. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6180. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6181. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6182. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6183. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6184. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6185. /* Read DMA control block */
  6186. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6187. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6188. /* Write DMA control block */
  6189. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6190. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6191. /* DMA completion block */
  6192. printk("DEBUG: DMAC_MODE[%08x]\n",
  6193. tr32(DMAC_MODE));
  6194. /* GRC block */
  6195. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6196. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6197. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6198. tr32(GRC_LOCAL_CTRL));
  6199. /* TG3_BDINFOs */
  6200. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6201. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6202. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6203. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6204. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6205. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6206. tr32(RCVDBDI_STD_BD + 0x0),
  6207. tr32(RCVDBDI_STD_BD + 0x4),
  6208. tr32(RCVDBDI_STD_BD + 0x8),
  6209. tr32(RCVDBDI_STD_BD + 0xc));
  6210. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6211. tr32(RCVDBDI_MINI_BD + 0x0),
  6212. tr32(RCVDBDI_MINI_BD + 0x4),
  6213. tr32(RCVDBDI_MINI_BD + 0x8),
  6214. tr32(RCVDBDI_MINI_BD + 0xc));
  6215. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6216. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6217. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6218. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6219. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6220. val32, val32_2, val32_3, val32_4);
  6221. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6222. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6223. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6224. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6225. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6226. val32, val32_2, val32_3, val32_4);
  6227. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6228. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6229. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6230. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6231. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6232. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6233. val32, val32_2, val32_3, val32_4, val32_5);
  6234. /* SW status block */
  6235. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6236. tp->hw_status->status,
  6237. tp->hw_status->status_tag,
  6238. tp->hw_status->rx_jumbo_consumer,
  6239. tp->hw_status->rx_consumer,
  6240. tp->hw_status->rx_mini_consumer,
  6241. tp->hw_status->idx[0].rx_producer,
  6242. tp->hw_status->idx[0].tx_consumer);
  6243. /* SW statistics block */
  6244. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6245. ((u32 *)tp->hw_stats)[0],
  6246. ((u32 *)tp->hw_stats)[1],
  6247. ((u32 *)tp->hw_stats)[2],
  6248. ((u32 *)tp->hw_stats)[3]);
  6249. /* Mailboxes */
  6250. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6251. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6252. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6253. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6254. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6255. /* NIC side send descriptors. */
  6256. for (i = 0; i < 6; i++) {
  6257. unsigned long txd;
  6258. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6259. + (i * sizeof(struct tg3_tx_buffer_desc));
  6260. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6261. i,
  6262. readl(txd + 0x0), readl(txd + 0x4),
  6263. readl(txd + 0x8), readl(txd + 0xc));
  6264. }
  6265. /* NIC side RX descriptors. */
  6266. for (i = 0; i < 6; i++) {
  6267. unsigned long rxd;
  6268. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6269. + (i * sizeof(struct tg3_rx_buffer_desc));
  6270. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6271. i,
  6272. readl(rxd + 0x0), readl(rxd + 0x4),
  6273. readl(rxd + 0x8), readl(rxd + 0xc));
  6274. rxd += (4 * sizeof(u32));
  6275. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6276. i,
  6277. readl(rxd + 0x0), readl(rxd + 0x4),
  6278. readl(rxd + 0x8), readl(rxd + 0xc));
  6279. }
  6280. for (i = 0; i < 6; i++) {
  6281. unsigned long rxd;
  6282. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6283. + (i * sizeof(struct tg3_rx_buffer_desc));
  6284. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6285. i,
  6286. readl(rxd + 0x0), readl(rxd + 0x4),
  6287. readl(rxd + 0x8), readl(rxd + 0xc));
  6288. rxd += (4 * sizeof(u32));
  6289. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6290. i,
  6291. readl(rxd + 0x0), readl(rxd + 0x4),
  6292. readl(rxd + 0x8), readl(rxd + 0xc));
  6293. }
  6294. }
  6295. #endif
  6296. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6297. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6298. static int tg3_close(struct net_device *dev)
  6299. {
  6300. struct tg3 *tp = netdev_priv(dev);
  6301. /* Calling flush_scheduled_work() may deadlock because
  6302. * linkwatch_event() may be on the workqueue and it will try to get
  6303. * the rtnl_lock which we are holding.
  6304. */
  6305. while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
  6306. msleep(1);
  6307. netif_stop_queue(dev);
  6308. del_timer_sync(&tp->timer);
  6309. tg3_full_lock(tp, 1);
  6310. #if 0
  6311. tg3_dump_state(tp);
  6312. #endif
  6313. tg3_disable_ints(tp);
  6314. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6315. tg3_free_rings(tp);
  6316. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6317. tg3_full_unlock(tp);
  6318. free_irq(tp->pdev->irq, dev);
  6319. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6320. pci_disable_msi(tp->pdev);
  6321. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6322. }
  6323. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6324. sizeof(tp->net_stats_prev));
  6325. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6326. sizeof(tp->estats_prev));
  6327. tg3_free_consistent(tp);
  6328. tg3_set_power_state(tp, PCI_D3hot);
  6329. netif_carrier_off(tp->dev);
  6330. return 0;
  6331. }
  6332. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6333. {
  6334. unsigned long ret;
  6335. #if (BITS_PER_LONG == 32)
  6336. ret = val->low;
  6337. #else
  6338. ret = ((u64)val->high << 32) | ((u64)val->low);
  6339. #endif
  6340. return ret;
  6341. }
  6342. static unsigned long calc_crc_errors(struct tg3 *tp)
  6343. {
  6344. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6345. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6346. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6347. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6348. u32 val;
  6349. spin_lock_bh(&tp->lock);
  6350. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6351. tg3_writephy(tp, MII_TG3_TEST1,
  6352. val | MII_TG3_TEST1_CRC_EN);
  6353. tg3_readphy(tp, 0x14, &val);
  6354. } else
  6355. val = 0;
  6356. spin_unlock_bh(&tp->lock);
  6357. tp->phy_crc_errors += val;
  6358. return tp->phy_crc_errors;
  6359. }
  6360. return get_stat64(&hw_stats->rx_fcs_errors);
  6361. }
  6362. #define ESTAT_ADD(member) \
  6363. estats->member = old_estats->member + \
  6364. get_stat64(&hw_stats->member)
  6365. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6366. {
  6367. struct tg3_ethtool_stats *estats = &tp->estats;
  6368. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6369. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6370. if (!hw_stats)
  6371. return old_estats;
  6372. ESTAT_ADD(rx_octets);
  6373. ESTAT_ADD(rx_fragments);
  6374. ESTAT_ADD(rx_ucast_packets);
  6375. ESTAT_ADD(rx_mcast_packets);
  6376. ESTAT_ADD(rx_bcast_packets);
  6377. ESTAT_ADD(rx_fcs_errors);
  6378. ESTAT_ADD(rx_align_errors);
  6379. ESTAT_ADD(rx_xon_pause_rcvd);
  6380. ESTAT_ADD(rx_xoff_pause_rcvd);
  6381. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6382. ESTAT_ADD(rx_xoff_entered);
  6383. ESTAT_ADD(rx_frame_too_long_errors);
  6384. ESTAT_ADD(rx_jabbers);
  6385. ESTAT_ADD(rx_undersize_packets);
  6386. ESTAT_ADD(rx_in_length_errors);
  6387. ESTAT_ADD(rx_out_length_errors);
  6388. ESTAT_ADD(rx_64_or_less_octet_packets);
  6389. ESTAT_ADD(rx_65_to_127_octet_packets);
  6390. ESTAT_ADD(rx_128_to_255_octet_packets);
  6391. ESTAT_ADD(rx_256_to_511_octet_packets);
  6392. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6393. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6394. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6395. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6396. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6397. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6398. ESTAT_ADD(tx_octets);
  6399. ESTAT_ADD(tx_collisions);
  6400. ESTAT_ADD(tx_xon_sent);
  6401. ESTAT_ADD(tx_xoff_sent);
  6402. ESTAT_ADD(tx_flow_control);
  6403. ESTAT_ADD(tx_mac_errors);
  6404. ESTAT_ADD(tx_single_collisions);
  6405. ESTAT_ADD(tx_mult_collisions);
  6406. ESTAT_ADD(tx_deferred);
  6407. ESTAT_ADD(tx_excessive_collisions);
  6408. ESTAT_ADD(tx_late_collisions);
  6409. ESTAT_ADD(tx_collide_2times);
  6410. ESTAT_ADD(tx_collide_3times);
  6411. ESTAT_ADD(tx_collide_4times);
  6412. ESTAT_ADD(tx_collide_5times);
  6413. ESTAT_ADD(tx_collide_6times);
  6414. ESTAT_ADD(tx_collide_7times);
  6415. ESTAT_ADD(tx_collide_8times);
  6416. ESTAT_ADD(tx_collide_9times);
  6417. ESTAT_ADD(tx_collide_10times);
  6418. ESTAT_ADD(tx_collide_11times);
  6419. ESTAT_ADD(tx_collide_12times);
  6420. ESTAT_ADD(tx_collide_13times);
  6421. ESTAT_ADD(tx_collide_14times);
  6422. ESTAT_ADD(tx_collide_15times);
  6423. ESTAT_ADD(tx_ucast_packets);
  6424. ESTAT_ADD(tx_mcast_packets);
  6425. ESTAT_ADD(tx_bcast_packets);
  6426. ESTAT_ADD(tx_carrier_sense_errors);
  6427. ESTAT_ADD(tx_discards);
  6428. ESTAT_ADD(tx_errors);
  6429. ESTAT_ADD(dma_writeq_full);
  6430. ESTAT_ADD(dma_write_prioq_full);
  6431. ESTAT_ADD(rxbds_empty);
  6432. ESTAT_ADD(rx_discards);
  6433. ESTAT_ADD(rx_errors);
  6434. ESTAT_ADD(rx_threshold_hit);
  6435. ESTAT_ADD(dma_readq_full);
  6436. ESTAT_ADD(dma_read_prioq_full);
  6437. ESTAT_ADD(tx_comp_queue_full);
  6438. ESTAT_ADD(ring_set_send_prod_index);
  6439. ESTAT_ADD(ring_status_update);
  6440. ESTAT_ADD(nic_irqs);
  6441. ESTAT_ADD(nic_avoided_irqs);
  6442. ESTAT_ADD(nic_tx_threshold_hit);
  6443. return estats;
  6444. }
  6445. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6446. {
  6447. struct tg3 *tp = netdev_priv(dev);
  6448. struct net_device_stats *stats = &tp->net_stats;
  6449. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6450. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6451. if (!hw_stats)
  6452. return old_stats;
  6453. stats->rx_packets = old_stats->rx_packets +
  6454. get_stat64(&hw_stats->rx_ucast_packets) +
  6455. get_stat64(&hw_stats->rx_mcast_packets) +
  6456. get_stat64(&hw_stats->rx_bcast_packets);
  6457. stats->tx_packets = old_stats->tx_packets +
  6458. get_stat64(&hw_stats->tx_ucast_packets) +
  6459. get_stat64(&hw_stats->tx_mcast_packets) +
  6460. get_stat64(&hw_stats->tx_bcast_packets);
  6461. stats->rx_bytes = old_stats->rx_bytes +
  6462. get_stat64(&hw_stats->rx_octets);
  6463. stats->tx_bytes = old_stats->tx_bytes +
  6464. get_stat64(&hw_stats->tx_octets);
  6465. stats->rx_errors = old_stats->rx_errors +
  6466. get_stat64(&hw_stats->rx_errors);
  6467. stats->tx_errors = old_stats->tx_errors +
  6468. get_stat64(&hw_stats->tx_errors) +
  6469. get_stat64(&hw_stats->tx_mac_errors) +
  6470. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6471. get_stat64(&hw_stats->tx_discards);
  6472. stats->multicast = old_stats->multicast +
  6473. get_stat64(&hw_stats->rx_mcast_packets);
  6474. stats->collisions = old_stats->collisions +
  6475. get_stat64(&hw_stats->tx_collisions);
  6476. stats->rx_length_errors = old_stats->rx_length_errors +
  6477. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6478. get_stat64(&hw_stats->rx_undersize_packets);
  6479. stats->rx_over_errors = old_stats->rx_over_errors +
  6480. get_stat64(&hw_stats->rxbds_empty);
  6481. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6482. get_stat64(&hw_stats->rx_align_errors);
  6483. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6484. get_stat64(&hw_stats->tx_discards);
  6485. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6486. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6487. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6488. calc_crc_errors(tp);
  6489. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6490. get_stat64(&hw_stats->rx_discards);
  6491. return stats;
  6492. }
  6493. static inline u32 calc_crc(unsigned char *buf, int len)
  6494. {
  6495. u32 reg;
  6496. u32 tmp;
  6497. int j, k;
  6498. reg = 0xffffffff;
  6499. for (j = 0; j < len; j++) {
  6500. reg ^= buf[j];
  6501. for (k = 0; k < 8; k++) {
  6502. tmp = reg & 0x01;
  6503. reg >>= 1;
  6504. if (tmp) {
  6505. reg ^= 0xedb88320;
  6506. }
  6507. }
  6508. }
  6509. return ~reg;
  6510. }
  6511. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6512. {
  6513. /* accept or reject all multicast frames */
  6514. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6515. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6516. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6517. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6518. }
  6519. static void __tg3_set_rx_mode(struct net_device *dev)
  6520. {
  6521. struct tg3 *tp = netdev_priv(dev);
  6522. u32 rx_mode;
  6523. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6524. RX_MODE_KEEP_VLAN_TAG);
  6525. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6526. * flag clear.
  6527. */
  6528. #if TG3_VLAN_TAG_USED
  6529. if (!tp->vlgrp &&
  6530. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6531. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6532. #else
  6533. /* By definition, VLAN is disabled always in this
  6534. * case.
  6535. */
  6536. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6537. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6538. #endif
  6539. if (dev->flags & IFF_PROMISC) {
  6540. /* Promiscuous mode. */
  6541. rx_mode |= RX_MODE_PROMISC;
  6542. } else if (dev->flags & IFF_ALLMULTI) {
  6543. /* Accept all multicast. */
  6544. tg3_set_multi (tp, 1);
  6545. } else if (dev->mc_count < 1) {
  6546. /* Reject all multicast. */
  6547. tg3_set_multi (tp, 0);
  6548. } else {
  6549. /* Accept one or more multicast(s). */
  6550. struct dev_mc_list *mclist;
  6551. unsigned int i;
  6552. u32 mc_filter[4] = { 0, };
  6553. u32 regidx;
  6554. u32 bit;
  6555. u32 crc;
  6556. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6557. i++, mclist = mclist->next) {
  6558. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6559. bit = ~crc & 0x7f;
  6560. regidx = (bit & 0x60) >> 5;
  6561. bit &= 0x1f;
  6562. mc_filter[regidx] |= (1 << bit);
  6563. }
  6564. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6565. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6566. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6567. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6568. }
  6569. if (rx_mode != tp->rx_mode) {
  6570. tp->rx_mode = rx_mode;
  6571. tw32_f(MAC_RX_MODE, rx_mode);
  6572. udelay(10);
  6573. }
  6574. }
  6575. static void tg3_set_rx_mode(struct net_device *dev)
  6576. {
  6577. struct tg3 *tp = netdev_priv(dev);
  6578. if (!netif_running(dev))
  6579. return;
  6580. tg3_full_lock(tp, 0);
  6581. __tg3_set_rx_mode(dev);
  6582. tg3_full_unlock(tp);
  6583. }
  6584. #define TG3_REGDUMP_LEN (32 * 1024)
  6585. static int tg3_get_regs_len(struct net_device *dev)
  6586. {
  6587. return TG3_REGDUMP_LEN;
  6588. }
  6589. static void tg3_get_regs(struct net_device *dev,
  6590. struct ethtool_regs *regs, void *_p)
  6591. {
  6592. u32 *p = _p;
  6593. struct tg3 *tp = netdev_priv(dev);
  6594. u8 *orig_p = _p;
  6595. int i;
  6596. regs->version = 0;
  6597. memset(p, 0, TG3_REGDUMP_LEN);
  6598. if (tp->link_config.phy_is_low_power)
  6599. return;
  6600. tg3_full_lock(tp, 0);
  6601. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6602. #define GET_REG32_LOOP(base,len) \
  6603. do { p = (u32 *)(orig_p + (base)); \
  6604. for (i = 0; i < len; i += 4) \
  6605. __GET_REG32((base) + i); \
  6606. } while (0)
  6607. #define GET_REG32_1(reg) \
  6608. do { p = (u32 *)(orig_p + (reg)); \
  6609. __GET_REG32((reg)); \
  6610. } while (0)
  6611. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6612. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6613. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6614. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6615. GET_REG32_1(SNDDATAC_MODE);
  6616. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6617. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6618. GET_REG32_1(SNDBDC_MODE);
  6619. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6620. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6621. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6622. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6623. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6624. GET_REG32_1(RCVDCC_MODE);
  6625. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6626. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6627. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6628. GET_REG32_1(MBFREE_MODE);
  6629. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6630. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6631. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6632. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6633. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6634. GET_REG32_1(RX_CPU_MODE);
  6635. GET_REG32_1(RX_CPU_STATE);
  6636. GET_REG32_1(RX_CPU_PGMCTR);
  6637. GET_REG32_1(RX_CPU_HWBKPT);
  6638. GET_REG32_1(TX_CPU_MODE);
  6639. GET_REG32_1(TX_CPU_STATE);
  6640. GET_REG32_1(TX_CPU_PGMCTR);
  6641. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6642. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6643. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6644. GET_REG32_1(DMAC_MODE);
  6645. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6646. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6647. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6648. #undef __GET_REG32
  6649. #undef GET_REG32_LOOP
  6650. #undef GET_REG32_1
  6651. tg3_full_unlock(tp);
  6652. }
  6653. static int tg3_get_eeprom_len(struct net_device *dev)
  6654. {
  6655. struct tg3 *tp = netdev_priv(dev);
  6656. return tp->nvram_size;
  6657. }
  6658. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6659. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6660. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6661. {
  6662. struct tg3 *tp = netdev_priv(dev);
  6663. int ret;
  6664. u8 *pd;
  6665. u32 i, offset, len, val, b_offset, b_count;
  6666. if (tp->link_config.phy_is_low_power)
  6667. return -EAGAIN;
  6668. offset = eeprom->offset;
  6669. len = eeprom->len;
  6670. eeprom->len = 0;
  6671. eeprom->magic = TG3_EEPROM_MAGIC;
  6672. if (offset & 3) {
  6673. /* adjustments to start on required 4 byte boundary */
  6674. b_offset = offset & 3;
  6675. b_count = 4 - b_offset;
  6676. if (b_count > len) {
  6677. /* i.e. offset=1 len=2 */
  6678. b_count = len;
  6679. }
  6680. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6681. if (ret)
  6682. return ret;
  6683. val = cpu_to_le32(val);
  6684. memcpy(data, ((char*)&val) + b_offset, b_count);
  6685. len -= b_count;
  6686. offset += b_count;
  6687. eeprom->len += b_count;
  6688. }
  6689. /* read bytes upto the last 4 byte boundary */
  6690. pd = &data[eeprom->len];
  6691. for (i = 0; i < (len - (len & 3)); i += 4) {
  6692. ret = tg3_nvram_read(tp, offset + i, &val);
  6693. if (ret) {
  6694. eeprom->len += i;
  6695. return ret;
  6696. }
  6697. val = cpu_to_le32(val);
  6698. memcpy(pd + i, &val, 4);
  6699. }
  6700. eeprom->len += i;
  6701. if (len & 3) {
  6702. /* read last bytes not ending on 4 byte boundary */
  6703. pd = &data[eeprom->len];
  6704. b_count = len & 3;
  6705. b_offset = offset + len - b_count;
  6706. ret = tg3_nvram_read(tp, b_offset, &val);
  6707. if (ret)
  6708. return ret;
  6709. val = cpu_to_le32(val);
  6710. memcpy(pd, ((char*)&val), b_count);
  6711. eeprom->len += b_count;
  6712. }
  6713. return 0;
  6714. }
  6715. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6716. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6717. {
  6718. struct tg3 *tp = netdev_priv(dev);
  6719. int ret;
  6720. u32 offset, len, b_offset, odd_len, start, end;
  6721. u8 *buf;
  6722. if (tp->link_config.phy_is_low_power)
  6723. return -EAGAIN;
  6724. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6725. return -EINVAL;
  6726. offset = eeprom->offset;
  6727. len = eeprom->len;
  6728. if ((b_offset = (offset & 3))) {
  6729. /* adjustments to start on required 4 byte boundary */
  6730. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6731. if (ret)
  6732. return ret;
  6733. start = cpu_to_le32(start);
  6734. len += b_offset;
  6735. offset &= ~3;
  6736. if (len < 4)
  6737. len = 4;
  6738. }
  6739. odd_len = 0;
  6740. if (len & 3) {
  6741. /* adjustments to end on required 4 byte boundary */
  6742. odd_len = 1;
  6743. len = (len + 3) & ~3;
  6744. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6745. if (ret)
  6746. return ret;
  6747. end = cpu_to_le32(end);
  6748. }
  6749. buf = data;
  6750. if (b_offset || odd_len) {
  6751. buf = kmalloc(len, GFP_KERNEL);
  6752. if (buf == 0)
  6753. return -ENOMEM;
  6754. if (b_offset)
  6755. memcpy(buf, &start, 4);
  6756. if (odd_len)
  6757. memcpy(buf+len-4, &end, 4);
  6758. memcpy(buf + b_offset, data, eeprom->len);
  6759. }
  6760. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6761. if (buf != data)
  6762. kfree(buf);
  6763. return ret;
  6764. }
  6765. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6766. {
  6767. struct tg3 *tp = netdev_priv(dev);
  6768. cmd->supported = (SUPPORTED_Autoneg);
  6769. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6770. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6771. SUPPORTED_1000baseT_Full);
  6772. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6773. cmd->supported |= (SUPPORTED_100baseT_Half |
  6774. SUPPORTED_100baseT_Full |
  6775. SUPPORTED_10baseT_Half |
  6776. SUPPORTED_10baseT_Full |
  6777. SUPPORTED_MII);
  6778. cmd->port = PORT_TP;
  6779. } else {
  6780. cmd->supported |= SUPPORTED_FIBRE;
  6781. cmd->port = PORT_FIBRE;
  6782. }
  6783. cmd->advertising = tp->link_config.advertising;
  6784. if (netif_running(dev)) {
  6785. cmd->speed = tp->link_config.active_speed;
  6786. cmd->duplex = tp->link_config.active_duplex;
  6787. }
  6788. cmd->phy_address = PHY_ADDR;
  6789. cmd->transceiver = 0;
  6790. cmd->autoneg = tp->link_config.autoneg;
  6791. cmd->maxtxpkt = 0;
  6792. cmd->maxrxpkt = 0;
  6793. return 0;
  6794. }
  6795. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6796. {
  6797. struct tg3 *tp = netdev_priv(dev);
  6798. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6799. /* These are the only valid advertisement bits allowed. */
  6800. if (cmd->autoneg == AUTONEG_ENABLE &&
  6801. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6802. ADVERTISED_1000baseT_Full |
  6803. ADVERTISED_Autoneg |
  6804. ADVERTISED_FIBRE)))
  6805. return -EINVAL;
  6806. /* Fiber can only do SPEED_1000. */
  6807. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6808. (cmd->speed != SPEED_1000))
  6809. return -EINVAL;
  6810. /* Copper cannot force SPEED_1000. */
  6811. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6812. (cmd->speed == SPEED_1000))
  6813. return -EINVAL;
  6814. else if ((cmd->speed == SPEED_1000) &&
  6815. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6816. return -EINVAL;
  6817. tg3_full_lock(tp, 0);
  6818. tp->link_config.autoneg = cmd->autoneg;
  6819. if (cmd->autoneg == AUTONEG_ENABLE) {
  6820. tp->link_config.advertising = cmd->advertising;
  6821. tp->link_config.speed = SPEED_INVALID;
  6822. tp->link_config.duplex = DUPLEX_INVALID;
  6823. } else {
  6824. tp->link_config.advertising = 0;
  6825. tp->link_config.speed = cmd->speed;
  6826. tp->link_config.duplex = cmd->duplex;
  6827. }
  6828. tp->link_config.orig_speed = tp->link_config.speed;
  6829. tp->link_config.orig_duplex = tp->link_config.duplex;
  6830. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  6831. if (netif_running(dev))
  6832. tg3_setup_phy(tp, 1);
  6833. tg3_full_unlock(tp);
  6834. return 0;
  6835. }
  6836. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6837. {
  6838. struct tg3 *tp = netdev_priv(dev);
  6839. strcpy(info->driver, DRV_MODULE_NAME);
  6840. strcpy(info->version, DRV_MODULE_VERSION);
  6841. strcpy(info->fw_version, tp->fw_ver);
  6842. strcpy(info->bus_info, pci_name(tp->pdev));
  6843. }
  6844. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6845. {
  6846. struct tg3 *tp = netdev_priv(dev);
  6847. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  6848. wol->supported = WAKE_MAGIC;
  6849. else
  6850. wol->supported = 0;
  6851. wol->wolopts = 0;
  6852. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6853. wol->wolopts = WAKE_MAGIC;
  6854. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6855. }
  6856. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6857. {
  6858. struct tg3 *tp = netdev_priv(dev);
  6859. if (wol->wolopts & ~WAKE_MAGIC)
  6860. return -EINVAL;
  6861. if ((wol->wolopts & WAKE_MAGIC) &&
  6862. !(tp->tg3_flags & TG3_FLAG_WOL_CAP))
  6863. return -EINVAL;
  6864. spin_lock_bh(&tp->lock);
  6865. if (wol->wolopts & WAKE_MAGIC)
  6866. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6867. else
  6868. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6869. spin_unlock_bh(&tp->lock);
  6870. return 0;
  6871. }
  6872. static u32 tg3_get_msglevel(struct net_device *dev)
  6873. {
  6874. struct tg3 *tp = netdev_priv(dev);
  6875. return tp->msg_enable;
  6876. }
  6877. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6878. {
  6879. struct tg3 *tp = netdev_priv(dev);
  6880. tp->msg_enable = value;
  6881. }
  6882. static int tg3_set_tso(struct net_device *dev, u32 value)
  6883. {
  6884. struct tg3 *tp = netdev_priv(dev);
  6885. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6886. if (value)
  6887. return -EINVAL;
  6888. return 0;
  6889. }
  6890. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  6891. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  6892. if (value)
  6893. dev->features |= NETIF_F_TSO6;
  6894. else
  6895. dev->features &= ~NETIF_F_TSO6;
  6896. }
  6897. return ethtool_op_set_tso(dev, value);
  6898. }
  6899. static int tg3_nway_reset(struct net_device *dev)
  6900. {
  6901. struct tg3 *tp = netdev_priv(dev);
  6902. u32 bmcr;
  6903. int r;
  6904. if (!netif_running(dev))
  6905. return -EAGAIN;
  6906. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6907. return -EINVAL;
  6908. spin_lock_bh(&tp->lock);
  6909. r = -EINVAL;
  6910. tg3_readphy(tp, MII_BMCR, &bmcr);
  6911. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6912. ((bmcr & BMCR_ANENABLE) ||
  6913. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6914. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6915. BMCR_ANENABLE);
  6916. r = 0;
  6917. }
  6918. spin_unlock_bh(&tp->lock);
  6919. return r;
  6920. }
  6921. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6922. {
  6923. struct tg3 *tp = netdev_priv(dev);
  6924. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6925. ering->rx_mini_max_pending = 0;
  6926. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6927. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6928. else
  6929. ering->rx_jumbo_max_pending = 0;
  6930. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6931. ering->rx_pending = tp->rx_pending;
  6932. ering->rx_mini_pending = 0;
  6933. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6934. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6935. else
  6936. ering->rx_jumbo_pending = 0;
  6937. ering->tx_pending = tp->tx_pending;
  6938. }
  6939. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6940. {
  6941. struct tg3 *tp = netdev_priv(dev);
  6942. int irq_sync = 0, err = 0;
  6943. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6944. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6945. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  6946. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  6947. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  6948. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  6949. return -EINVAL;
  6950. if (netif_running(dev)) {
  6951. tg3_netif_stop(tp);
  6952. irq_sync = 1;
  6953. }
  6954. tg3_full_lock(tp, irq_sync);
  6955. tp->rx_pending = ering->rx_pending;
  6956. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6957. tp->rx_pending > 63)
  6958. tp->rx_pending = 63;
  6959. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6960. tp->tx_pending = ering->tx_pending;
  6961. if (netif_running(dev)) {
  6962. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6963. err = tg3_restart_hw(tp, 1);
  6964. if (!err)
  6965. tg3_netif_start(tp);
  6966. }
  6967. tg3_full_unlock(tp);
  6968. return err;
  6969. }
  6970. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6971. {
  6972. struct tg3 *tp = netdev_priv(dev);
  6973. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  6974. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  6975. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  6976. }
  6977. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  6978. {
  6979. struct tg3 *tp = netdev_priv(dev);
  6980. int irq_sync = 0, err = 0;
  6981. if (netif_running(dev)) {
  6982. tg3_netif_stop(tp);
  6983. irq_sync = 1;
  6984. }
  6985. tg3_full_lock(tp, irq_sync);
  6986. if (epause->autoneg)
  6987. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  6988. else
  6989. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  6990. if (epause->rx_pause)
  6991. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  6992. else
  6993. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  6994. if (epause->tx_pause)
  6995. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  6996. else
  6997. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  6998. if (netif_running(dev)) {
  6999. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7000. err = tg3_restart_hw(tp, 1);
  7001. if (!err)
  7002. tg3_netif_start(tp);
  7003. }
  7004. tg3_full_unlock(tp);
  7005. return err;
  7006. }
  7007. static u32 tg3_get_rx_csum(struct net_device *dev)
  7008. {
  7009. struct tg3 *tp = netdev_priv(dev);
  7010. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  7011. }
  7012. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  7013. {
  7014. struct tg3 *tp = netdev_priv(dev);
  7015. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7016. if (data != 0)
  7017. return -EINVAL;
  7018. return 0;
  7019. }
  7020. spin_lock_bh(&tp->lock);
  7021. if (data)
  7022. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7023. else
  7024. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7025. spin_unlock_bh(&tp->lock);
  7026. return 0;
  7027. }
  7028. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7029. {
  7030. struct tg3 *tp = netdev_priv(dev);
  7031. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7032. if (data != 0)
  7033. return -EINVAL;
  7034. return 0;
  7035. }
  7036. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7037. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7038. ethtool_op_set_tx_hw_csum(dev, data);
  7039. else
  7040. ethtool_op_set_tx_csum(dev, data);
  7041. return 0;
  7042. }
  7043. static int tg3_get_stats_count (struct net_device *dev)
  7044. {
  7045. return TG3_NUM_STATS;
  7046. }
  7047. static int tg3_get_test_count (struct net_device *dev)
  7048. {
  7049. return TG3_NUM_TEST;
  7050. }
  7051. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7052. {
  7053. switch (stringset) {
  7054. case ETH_SS_STATS:
  7055. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7056. break;
  7057. case ETH_SS_TEST:
  7058. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7059. break;
  7060. default:
  7061. WARN_ON(1); /* we need a WARN() */
  7062. break;
  7063. }
  7064. }
  7065. static int tg3_phys_id(struct net_device *dev, u32 data)
  7066. {
  7067. struct tg3 *tp = netdev_priv(dev);
  7068. int i;
  7069. if (!netif_running(tp->dev))
  7070. return -EAGAIN;
  7071. if (data == 0)
  7072. data = 2;
  7073. for (i = 0; i < (data * 2); i++) {
  7074. if ((i % 2) == 0)
  7075. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7076. LED_CTRL_1000MBPS_ON |
  7077. LED_CTRL_100MBPS_ON |
  7078. LED_CTRL_10MBPS_ON |
  7079. LED_CTRL_TRAFFIC_OVERRIDE |
  7080. LED_CTRL_TRAFFIC_BLINK |
  7081. LED_CTRL_TRAFFIC_LED);
  7082. else
  7083. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7084. LED_CTRL_TRAFFIC_OVERRIDE);
  7085. if (msleep_interruptible(500))
  7086. break;
  7087. }
  7088. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7089. return 0;
  7090. }
  7091. static void tg3_get_ethtool_stats (struct net_device *dev,
  7092. struct ethtool_stats *estats, u64 *tmp_stats)
  7093. {
  7094. struct tg3 *tp = netdev_priv(dev);
  7095. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7096. }
  7097. #define NVRAM_TEST_SIZE 0x100
  7098. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  7099. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7100. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7101. static int tg3_test_nvram(struct tg3 *tp)
  7102. {
  7103. u32 *buf, csum, magic;
  7104. int i, j, err = 0, size;
  7105. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7106. return -EIO;
  7107. if (magic == TG3_EEPROM_MAGIC)
  7108. size = NVRAM_TEST_SIZE;
  7109. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7110. if ((magic & 0xe00000) == 0x200000)
  7111. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  7112. else
  7113. return 0;
  7114. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7115. size = NVRAM_SELFBOOT_HW_SIZE;
  7116. else
  7117. return -EIO;
  7118. buf = kmalloc(size, GFP_KERNEL);
  7119. if (buf == NULL)
  7120. return -ENOMEM;
  7121. err = -EIO;
  7122. for (i = 0, j = 0; i < size; i += 4, j++) {
  7123. u32 val;
  7124. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7125. break;
  7126. buf[j] = cpu_to_le32(val);
  7127. }
  7128. if (i < size)
  7129. goto out;
  7130. /* Selfboot format */
  7131. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
  7132. TG3_EEPROM_MAGIC_FW) {
  7133. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7134. for (i = 0; i < size; i++)
  7135. csum8 += buf8[i];
  7136. if (csum8 == 0) {
  7137. err = 0;
  7138. goto out;
  7139. }
  7140. err = -EIO;
  7141. goto out;
  7142. }
  7143. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
  7144. TG3_EEPROM_MAGIC_HW) {
  7145. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7146. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7147. u8 *buf8 = (u8 *) buf;
  7148. int j, k;
  7149. /* Separate the parity bits and the data bytes. */
  7150. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7151. if ((i == 0) || (i == 8)) {
  7152. int l;
  7153. u8 msk;
  7154. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7155. parity[k++] = buf8[i] & msk;
  7156. i++;
  7157. }
  7158. else if (i == 16) {
  7159. int l;
  7160. u8 msk;
  7161. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7162. parity[k++] = buf8[i] & msk;
  7163. i++;
  7164. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7165. parity[k++] = buf8[i] & msk;
  7166. i++;
  7167. }
  7168. data[j++] = buf8[i];
  7169. }
  7170. err = -EIO;
  7171. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7172. u8 hw8 = hweight8(data[i]);
  7173. if ((hw8 & 0x1) && parity[i])
  7174. goto out;
  7175. else if (!(hw8 & 0x1) && !parity[i])
  7176. goto out;
  7177. }
  7178. err = 0;
  7179. goto out;
  7180. }
  7181. /* Bootstrap checksum at offset 0x10 */
  7182. csum = calc_crc((unsigned char *) buf, 0x10);
  7183. if(csum != cpu_to_le32(buf[0x10/4]))
  7184. goto out;
  7185. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7186. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7187. if (csum != cpu_to_le32(buf[0xfc/4]))
  7188. goto out;
  7189. err = 0;
  7190. out:
  7191. kfree(buf);
  7192. return err;
  7193. }
  7194. #define TG3_SERDES_TIMEOUT_SEC 2
  7195. #define TG3_COPPER_TIMEOUT_SEC 6
  7196. static int tg3_test_link(struct tg3 *tp)
  7197. {
  7198. int i, max;
  7199. if (!netif_running(tp->dev))
  7200. return -ENODEV;
  7201. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7202. max = TG3_SERDES_TIMEOUT_SEC;
  7203. else
  7204. max = TG3_COPPER_TIMEOUT_SEC;
  7205. for (i = 0; i < max; i++) {
  7206. if (netif_carrier_ok(tp->dev))
  7207. return 0;
  7208. if (msleep_interruptible(1000))
  7209. break;
  7210. }
  7211. return -EIO;
  7212. }
  7213. /* Only test the commonly used registers */
  7214. static int tg3_test_registers(struct tg3 *tp)
  7215. {
  7216. int i, is_5705, is_5750;
  7217. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7218. static struct {
  7219. u16 offset;
  7220. u16 flags;
  7221. #define TG3_FL_5705 0x1
  7222. #define TG3_FL_NOT_5705 0x2
  7223. #define TG3_FL_NOT_5788 0x4
  7224. #define TG3_FL_NOT_5750 0x8
  7225. u32 read_mask;
  7226. u32 write_mask;
  7227. } reg_tbl[] = {
  7228. /* MAC Control Registers */
  7229. { MAC_MODE, TG3_FL_NOT_5705,
  7230. 0x00000000, 0x00ef6f8c },
  7231. { MAC_MODE, TG3_FL_5705,
  7232. 0x00000000, 0x01ef6b8c },
  7233. { MAC_STATUS, TG3_FL_NOT_5705,
  7234. 0x03800107, 0x00000000 },
  7235. { MAC_STATUS, TG3_FL_5705,
  7236. 0x03800100, 0x00000000 },
  7237. { MAC_ADDR_0_HIGH, 0x0000,
  7238. 0x00000000, 0x0000ffff },
  7239. { MAC_ADDR_0_LOW, 0x0000,
  7240. 0x00000000, 0xffffffff },
  7241. { MAC_RX_MTU_SIZE, 0x0000,
  7242. 0x00000000, 0x0000ffff },
  7243. { MAC_TX_MODE, 0x0000,
  7244. 0x00000000, 0x00000070 },
  7245. { MAC_TX_LENGTHS, 0x0000,
  7246. 0x00000000, 0x00003fff },
  7247. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7248. 0x00000000, 0x000007fc },
  7249. { MAC_RX_MODE, TG3_FL_5705,
  7250. 0x00000000, 0x000007dc },
  7251. { MAC_HASH_REG_0, 0x0000,
  7252. 0x00000000, 0xffffffff },
  7253. { MAC_HASH_REG_1, 0x0000,
  7254. 0x00000000, 0xffffffff },
  7255. { MAC_HASH_REG_2, 0x0000,
  7256. 0x00000000, 0xffffffff },
  7257. { MAC_HASH_REG_3, 0x0000,
  7258. 0x00000000, 0xffffffff },
  7259. /* Receive Data and Receive BD Initiator Control Registers. */
  7260. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7261. 0x00000000, 0xffffffff },
  7262. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7263. 0x00000000, 0xffffffff },
  7264. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7265. 0x00000000, 0x00000003 },
  7266. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7267. 0x00000000, 0xffffffff },
  7268. { RCVDBDI_STD_BD+0, 0x0000,
  7269. 0x00000000, 0xffffffff },
  7270. { RCVDBDI_STD_BD+4, 0x0000,
  7271. 0x00000000, 0xffffffff },
  7272. { RCVDBDI_STD_BD+8, 0x0000,
  7273. 0x00000000, 0xffff0002 },
  7274. { RCVDBDI_STD_BD+0xc, 0x0000,
  7275. 0x00000000, 0xffffffff },
  7276. /* Receive BD Initiator Control Registers. */
  7277. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7278. 0x00000000, 0xffffffff },
  7279. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7280. 0x00000000, 0x000003ff },
  7281. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7282. 0x00000000, 0xffffffff },
  7283. /* Host Coalescing Control Registers. */
  7284. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7285. 0x00000000, 0x00000004 },
  7286. { HOSTCC_MODE, TG3_FL_5705,
  7287. 0x00000000, 0x000000f6 },
  7288. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7289. 0x00000000, 0xffffffff },
  7290. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7291. 0x00000000, 0x000003ff },
  7292. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7293. 0x00000000, 0xffffffff },
  7294. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7295. 0x00000000, 0x000003ff },
  7296. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7297. 0x00000000, 0xffffffff },
  7298. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7299. 0x00000000, 0x000000ff },
  7300. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7301. 0x00000000, 0xffffffff },
  7302. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7303. 0x00000000, 0x000000ff },
  7304. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7305. 0x00000000, 0xffffffff },
  7306. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7307. 0x00000000, 0xffffffff },
  7308. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7309. 0x00000000, 0xffffffff },
  7310. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7311. 0x00000000, 0x000000ff },
  7312. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7313. 0x00000000, 0xffffffff },
  7314. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7315. 0x00000000, 0x000000ff },
  7316. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7317. 0x00000000, 0xffffffff },
  7318. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7319. 0x00000000, 0xffffffff },
  7320. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7321. 0x00000000, 0xffffffff },
  7322. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7323. 0x00000000, 0xffffffff },
  7324. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7325. 0x00000000, 0xffffffff },
  7326. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7327. 0xffffffff, 0x00000000 },
  7328. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7329. 0xffffffff, 0x00000000 },
  7330. /* Buffer Manager Control Registers. */
  7331. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7332. 0x00000000, 0x007fff80 },
  7333. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7334. 0x00000000, 0x007fffff },
  7335. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7336. 0x00000000, 0x0000003f },
  7337. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7338. 0x00000000, 0x000001ff },
  7339. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7340. 0x00000000, 0x000001ff },
  7341. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7342. 0xffffffff, 0x00000000 },
  7343. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7344. 0xffffffff, 0x00000000 },
  7345. /* Mailbox Registers */
  7346. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7347. 0x00000000, 0x000001ff },
  7348. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7349. 0x00000000, 0x000001ff },
  7350. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7351. 0x00000000, 0x000007ff },
  7352. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7353. 0x00000000, 0x000001ff },
  7354. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7355. };
  7356. is_5705 = is_5750 = 0;
  7357. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7358. is_5705 = 1;
  7359. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7360. is_5750 = 1;
  7361. }
  7362. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7363. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7364. continue;
  7365. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7366. continue;
  7367. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7368. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7369. continue;
  7370. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7371. continue;
  7372. offset = (u32) reg_tbl[i].offset;
  7373. read_mask = reg_tbl[i].read_mask;
  7374. write_mask = reg_tbl[i].write_mask;
  7375. /* Save the original register content */
  7376. save_val = tr32(offset);
  7377. /* Determine the read-only value. */
  7378. read_val = save_val & read_mask;
  7379. /* Write zero to the register, then make sure the read-only bits
  7380. * are not changed and the read/write bits are all zeros.
  7381. */
  7382. tw32(offset, 0);
  7383. val = tr32(offset);
  7384. /* Test the read-only and read/write bits. */
  7385. if (((val & read_mask) != read_val) || (val & write_mask))
  7386. goto out;
  7387. /* Write ones to all the bits defined by RdMask and WrMask, then
  7388. * make sure the read-only bits are not changed and the
  7389. * read/write bits are all ones.
  7390. */
  7391. tw32(offset, read_mask | write_mask);
  7392. val = tr32(offset);
  7393. /* Test the read-only bits. */
  7394. if ((val & read_mask) != read_val)
  7395. goto out;
  7396. /* Test the read/write bits. */
  7397. if ((val & write_mask) != write_mask)
  7398. goto out;
  7399. tw32(offset, save_val);
  7400. }
  7401. return 0;
  7402. out:
  7403. if (netif_msg_hw(tp))
  7404. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7405. offset);
  7406. tw32(offset, save_val);
  7407. return -EIO;
  7408. }
  7409. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7410. {
  7411. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7412. int i;
  7413. u32 j;
  7414. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7415. for (j = 0; j < len; j += 4) {
  7416. u32 val;
  7417. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7418. tg3_read_mem(tp, offset + j, &val);
  7419. if (val != test_pattern[i])
  7420. return -EIO;
  7421. }
  7422. }
  7423. return 0;
  7424. }
  7425. static int tg3_test_memory(struct tg3 *tp)
  7426. {
  7427. static struct mem_entry {
  7428. u32 offset;
  7429. u32 len;
  7430. } mem_tbl_570x[] = {
  7431. { 0x00000000, 0x00b50},
  7432. { 0x00002000, 0x1c000},
  7433. { 0xffffffff, 0x00000}
  7434. }, mem_tbl_5705[] = {
  7435. { 0x00000100, 0x0000c},
  7436. { 0x00000200, 0x00008},
  7437. { 0x00004000, 0x00800},
  7438. { 0x00006000, 0x01000},
  7439. { 0x00008000, 0x02000},
  7440. { 0x00010000, 0x0e000},
  7441. { 0xffffffff, 0x00000}
  7442. }, mem_tbl_5755[] = {
  7443. { 0x00000200, 0x00008},
  7444. { 0x00004000, 0x00800},
  7445. { 0x00006000, 0x00800},
  7446. { 0x00008000, 0x02000},
  7447. { 0x00010000, 0x0c000},
  7448. { 0xffffffff, 0x00000}
  7449. }, mem_tbl_5906[] = {
  7450. { 0x00000200, 0x00008},
  7451. { 0x00004000, 0x00400},
  7452. { 0x00006000, 0x00400},
  7453. { 0x00008000, 0x01000},
  7454. { 0x00010000, 0x01000},
  7455. { 0xffffffff, 0x00000}
  7456. };
  7457. struct mem_entry *mem_tbl;
  7458. int err = 0;
  7459. int i;
  7460. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7461. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7462. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7463. mem_tbl = mem_tbl_5755;
  7464. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7465. mem_tbl = mem_tbl_5906;
  7466. else
  7467. mem_tbl = mem_tbl_5705;
  7468. } else
  7469. mem_tbl = mem_tbl_570x;
  7470. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7471. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7472. mem_tbl[i].len)) != 0)
  7473. break;
  7474. }
  7475. return err;
  7476. }
  7477. #define TG3_MAC_LOOPBACK 0
  7478. #define TG3_PHY_LOOPBACK 1
  7479. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7480. {
  7481. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7482. u32 desc_idx;
  7483. struct sk_buff *skb, *rx_skb;
  7484. u8 *tx_data;
  7485. dma_addr_t map;
  7486. int num_pkts, tx_len, rx_len, i, err;
  7487. struct tg3_rx_buffer_desc *desc;
  7488. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7489. /* HW errata - mac loopback fails in some cases on 5780.
  7490. * Normal traffic and PHY loopback are not affected by
  7491. * errata.
  7492. */
  7493. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7494. return 0;
  7495. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7496. MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
  7497. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7498. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7499. else
  7500. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7501. tw32(MAC_MODE, mac_mode);
  7502. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7503. u32 val;
  7504. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7505. u32 phytest;
  7506. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7507. u32 phy;
  7508. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7509. phytest | MII_TG3_EPHY_SHADOW_EN);
  7510. if (!tg3_readphy(tp, 0x1b, &phy))
  7511. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7512. if (!tg3_readphy(tp, 0x10, &phy))
  7513. tg3_writephy(tp, 0x10, phy & ~0x4000);
  7514. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7515. }
  7516. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7517. } else
  7518. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7519. tg3_writephy(tp, MII_BMCR, val);
  7520. udelay(40);
  7521. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7522. MAC_MODE_LINK_POLARITY;
  7523. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7524. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7525. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7526. } else
  7527. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7528. /* reset to prevent losing 1st rx packet intermittently */
  7529. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7530. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7531. udelay(10);
  7532. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7533. }
  7534. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  7535. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7536. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7537. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7538. }
  7539. tw32(MAC_MODE, mac_mode);
  7540. }
  7541. else
  7542. return -EINVAL;
  7543. err = -EIO;
  7544. tx_len = 1514;
  7545. skb = netdev_alloc_skb(tp->dev, tx_len);
  7546. if (!skb)
  7547. return -ENOMEM;
  7548. tx_data = skb_put(skb, tx_len);
  7549. memcpy(tx_data, tp->dev->dev_addr, 6);
  7550. memset(tx_data + 6, 0x0, 8);
  7551. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7552. for (i = 14; i < tx_len; i++)
  7553. tx_data[i] = (u8) (i & 0xff);
  7554. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7555. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7556. HOSTCC_MODE_NOW);
  7557. udelay(10);
  7558. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7559. num_pkts = 0;
  7560. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7561. tp->tx_prod++;
  7562. num_pkts++;
  7563. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7564. tp->tx_prod);
  7565. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7566. udelay(10);
  7567. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  7568. for (i = 0; i < 25; i++) {
  7569. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7570. HOSTCC_MODE_NOW);
  7571. udelay(10);
  7572. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7573. rx_idx = tp->hw_status->idx[0].rx_producer;
  7574. if ((tx_idx == tp->tx_prod) &&
  7575. (rx_idx == (rx_start_idx + num_pkts)))
  7576. break;
  7577. }
  7578. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7579. dev_kfree_skb(skb);
  7580. if (tx_idx != tp->tx_prod)
  7581. goto out;
  7582. if (rx_idx != rx_start_idx + num_pkts)
  7583. goto out;
  7584. desc = &tp->rx_rcb[rx_start_idx];
  7585. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7586. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7587. if (opaque_key != RXD_OPAQUE_RING_STD)
  7588. goto out;
  7589. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7590. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7591. goto out;
  7592. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7593. if (rx_len != tx_len)
  7594. goto out;
  7595. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7596. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7597. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7598. for (i = 14; i < tx_len; i++) {
  7599. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7600. goto out;
  7601. }
  7602. err = 0;
  7603. /* tg3_free_rings will unmap and free the rx_skb */
  7604. out:
  7605. return err;
  7606. }
  7607. #define TG3_MAC_LOOPBACK_FAILED 1
  7608. #define TG3_PHY_LOOPBACK_FAILED 2
  7609. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7610. TG3_PHY_LOOPBACK_FAILED)
  7611. static int tg3_test_loopback(struct tg3 *tp)
  7612. {
  7613. int err = 0;
  7614. if (!netif_running(tp->dev))
  7615. return TG3_LOOPBACK_FAILED;
  7616. err = tg3_reset_hw(tp, 1);
  7617. if (err)
  7618. return TG3_LOOPBACK_FAILED;
  7619. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7620. err |= TG3_MAC_LOOPBACK_FAILED;
  7621. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7622. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7623. err |= TG3_PHY_LOOPBACK_FAILED;
  7624. }
  7625. return err;
  7626. }
  7627. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7628. u64 *data)
  7629. {
  7630. struct tg3 *tp = netdev_priv(dev);
  7631. if (tp->link_config.phy_is_low_power)
  7632. tg3_set_power_state(tp, PCI_D0);
  7633. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7634. if (tg3_test_nvram(tp) != 0) {
  7635. etest->flags |= ETH_TEST_FL_FAILED;
  7636. data[0] = 1;
  7637. }
  7638. if (tg3_test_link(tp) != 0) {
  7639. etest->flags |= ETH_TEST_FL_FAILED;
  7640. data[1] = 1;
  7641. }
  7642. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7643. int err, irq_sync = 0;
  7644. if (netif_running(dev)) {
  7645. tg3_netif_stop(tp);
  7646. irq_sync = 1;
  7647. }
  7648. tg3_full_lock(tp, irq_sync);
  7649. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7650. err = tg3_nvram_lock(tp);
  7651. tg3_halt_cpu(tp, RX_CPU_BASE);
  7652. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7653. tg3_halt_cpu(tp, TX_CPU_BASE);
  7654. if (!err)
  7655. tg3_nvram_unlock(tp);
  7656. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7657. tg3_phy_reset(tp);
  7658. if (tg3_test_registers(tp) != 0) {
  7659. etest->flags |= ETH_TEST_FL_FAILED;
  7660. data[2] = 1;
  7661. }
  7662. if (tg3_test_memory(tp) != 0) {
  7663. etest->flags |= ETH_TEST_FL_FAILED;
  7664. data[3] = 1;
  7665. }
  7666. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7667. etest->flags |= ETH_TEST_FL_FAILED;
  7668. tg3_full_unlock(tp);
  7669. if (tg3_test_interrupt(tp) != 0) {
  7670. etest->flags |= ETH_TEST_FL_FAILED;
  7671. data[5] = 1;
  7672. }
  7673. tg3_full_lock(tp, 0);
  7674. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7675. if (netif_running(dev)) {
  7676. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7677. if (!tg3_restart_hw(tp, 1))
  7678. tg3_netif_start(tp);
  7679. }
  7680. tg3_full_unlock(tp);
  7681. }
  7682. if (tp->link_config.phy_is_low_power)
  7683. tg3_set_power_state(tp, PCI_D3hot);
  7684. }
  7685. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7686. {
  7687. struct mii_ioctl_data *data = if_mii(ifr);
  7688. struct tg3 *tp = netdev_priv(dev);
  7689. int err;
  7690. switch(cmd) {
  7691. case SIOCGMIIPHY:
  7692. data->phy_id = PHY_ADDR;
  7693. /* fallthru */
  7694. case SIOCGMIIREG: {
  7695. u32 mii_regval;
  7696. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7697. break; /* We have no PHY */
  7698. if (tp->link_config.phy_is_low_power)
  7699. return -EAGAIN;
  7700. spin_lock_bh(&tp->lock);
  7701. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7702. spin_unlock_bh(&tp->lock);
  7703. data->val_out = mii_regval;
  7704. return err;
  7705. }
  7706. case SIOCSMIIREG:
  7707. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7708. break; /* We have no PHY */
  7709. if (!capable(CAP_NET_ADMIN))
  7710. return -EPERM;
  7711. if (tp->link_config.phy_is_low_power)
  7712. return -EAGAIN;
  7713. spin_lock_bh(&tp->lock);
  7714. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7715. spin_unlock_bh(&tp->lock);
  7716. return err;
  7717. default:
  7718. /* do nothing */
  7719. break;
  7720. }
  7721. return -EOPNOTSUPP;
  7722. }
  7723. #if TG3_VLAN_TAG_USED
  7724. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7725. {
  7726. struct tg3 *tp = netdev_priv(dev);
  7727. if (netif_running(dev))
  7728. tg3_netif_stop(tp);
  7729. tg3_full_lock(tp, 0);
  7730. tp->vlgrp = grp;
  7731. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7732. __tg3_set_rx_mode(dev);
  7733. tg3_full_unlock(tp);
  7734. if (netif_running(dev))
  7735. tg3_netif_start(tp);
  7736. }
  7737. static void tg3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  7738. {
  7739. struct tg3 *tp = netdev_priv(dev);
  7740. if (netif_running(dev))
  7741. tg3_netif_stop(tp);
  7742. tg3_full_lock(tp, 0);
  7743. vlan_group_set_device(tp->vlgrp, vid, NULL);
  7744. tg3_full_unlock(tp);
  7745. if (netif_running(dev))
  7746. tg3_netif_start(tp);
  7747. }
  7748. #endif
  7749. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7750. {
  7751. struct tg3 *tp = netdev_priv(dev);
  7752. memcpy(ec, &tp->coal, sizeof(*ec));
  7753. return 0;
  7754. }
  7755. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7756. {
  7757. struct tg3 *tp = netdev_priv(dev);
  7758. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7759. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7760. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7761. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7762. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7763. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7764. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7765. }
  7766. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7767. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7768. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7769. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7770. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7771. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7772. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7773. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7774. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7775. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7776. return -EINVAL;
  7777. /* No rx interrupts will be generated if both are zero */
  7778. if ((ec->rx_coalesce_usecs == 0) &&
  7779. (ec->rx_max_coalesced_frames == 0))
  7780. return -EINVAL;
  7781. /* No tx interrupts will be generated if both are zero */
  7782. if ((ec->tx_coalesce_usecs == 0) &&
  7783. (ec->tx_max_coalesced_frames == 0))
  7784. return -EINVAL;
  7785. /* Only copy relevant parameters, ignore all others. */
  7786. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7787. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7788. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7789. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7790. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7791. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7792. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7793. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7794. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7795. if (netif_running(dev)) {
  7796. tg3_full_lock(tp, 0);
  7797. __tg3_set_coalesce(tp, &tp->coal);
  7798. tg3_full_unlock(tp);
  7799. }
  7800. return 0;
  7801. }
  7802. static const struct ethtool_ops tg3_ethtool_ops = {
  7803. .get_settings = tg3_get_settings,
  7804. .set_settings = tg3_set_settings,
  7805. .get_drvinfo = tg3_get_drvinfo,
  7806. .get_regs_len = tg3_get_regs_len,
  7807. .get_regs = tg3_get_regs,
  7808. .get_wol = tg3_get_wol,
  7809. .set_wol = tg3_set_wol,
  7810. .get_msglevel = tg3_get_msglevel,
  7811. .set_msglevel = tg3_set_msglevel,
  7812. .nway_reset = tg3_nway_reset,
  7813. .get_link = ethtool_op_get_link,
  7814. .get_eeprom_len = tg3_get_eeprom_len,
  7815. .get_eeprom = tg3_get_eeprom,
  7816. .set_eeprom = tg3_set_eeprom,
  7817. .get_ringparam = tg3_get_ringparam,
  7818. .set_ringparam = tg3_set_ringparam,
  7819. .get_pauseparam = tg3_get_pauseparam,
  7820. .set_pauseparam = tg3_set_pauseparam,
  7821. .get_rx_csum = tg3_get_rx_csum,
  7822. .set_rx_csum = tg3_set_rx_csum,
  7823. .get_tx_csum = ethtool_op_get_tx_csum,
  7824. .set_tx_csum = tg3_set_tx_csum,
  7825. .get_sg = ethtool_op_get_sg,
  7826. .set_sg = ethtool_op_set_sg,
  7827. .get_tso = ethtool_op_get_tso,
  7828. .set_tso = tg3_set_tso,
  7829. .self_test_count = tg3_get_test_count,
  7830. .self_test = tg3_self_test,
  7831. .get_strings = tg3_get_strings,
  7832. .phys_id = tg3_phys_id,
  7833. .get_stats_count = tg3_get_stats_count,
  7834. .get_ethtool_stats = tg3_get_ethtool_stats,
  7835. .get_coalesce = tg3_get_coalesce,
  7836. .set_coalesce = tg3_set_coalesce,
  7837. .get_perm_addr = ethtool_op_get_perm_addr,
  7838. };
  7839. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7840. {
  7841. u32 cursize, val, magic;
  7842. tp->nvram_size = EEPROM_CHIP_SIZE;
  7843. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7844. return;
  7845. if ((magic != TG3_EEPROM_MAGIC) &&
  7846. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  7847. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  7848. return;
  7849. /*
  7850. * Size the chip by reading offsets at increasing powers of two.
  7851. * When we encounter our validation signature, we know the addressing
  7852. * has wrapped around, and thus have our chip size.
  7853. */
  7854. cursize = 0x10;
  7855. while (cursize < tp->nvram_size) {
  7856. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7857. return;
  7858. if (val == magic)
  7859. break;
  7860. cursize <<= 1;
  7861. }
  7862. tp->nvram_size = cursize;
  7863. }
  7864. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7865. {
  7866. u32 val;
  7867. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7868. return;
  7869. /* Selfboot format */
  7870. if (val != TG3_EEPROM_MAGIC) {
  7871. tg3_get_eeprom_size(tp);
  7872. return;
  7873. }
  7874. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7875. if (val != 0) {
  7876. tp->nvram_size = (val >> 16) * 1024;
  7877. return;
  7878. }
  7879. }
  7880. tp->nvram_size = 0x80000;
  7881. }
  7882. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7883. {
  7884. u32 nvcfg1;
  7885. nvcfg1 = tr32(NVRAM_CFG1);
  7886. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7887. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7888. }
  7889. else {
  7890. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7891. tw32(NVRAM_CFG1, nvcfg1);
  7892. }
  7893. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7894. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7895. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7896. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7897. tp->nvram_jedecnum = JEDEC_ATMEL;
  7898. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7899. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7900. break;
  7901. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7902. tp->nvram_jedecnum = JEDEC_ATMEL;
  7903. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7904. break;
  7905. case FLASH_VENDOR_ATMEL_EEPROM:
  7906. tp->nvram_jedecnum = JEDEC_ATMEL;
  7907. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7908. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7909. break;
  7910. case FLASH_VENDOR_ST:
  7911. tp->nvram_jedecnum = JEDEC_ST;
  7912. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7913. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7914. break;
  7915. case FLASH_VENDOR_SAIFUN:
  7916. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7917. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7918. break;
  7919. case FLASH_VENDOR_SST_SMALL:
  7920. case FLASH_VENDOR_SST_LARGE:
  7921. tp->nvram_jedecnum = JEDEC_SST;
  7922. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7923. break;
  7924. }
  7925. }
  7926. else {
  7927. tp->nvram_jedecnum = JEDEC_ATMEL;
  7928. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7929. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7930. }
  7931. }
  7932. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7933. {
  7934. u32 nvcfg1;
  7935. nvcfg1 = tr32(NVRAM_CFG1);
  7936. /* NVRAM protection for TPM */
  7937. if (nvcfg1 & (1 << 27))
  7938. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7939. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7940. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7941. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7942. tp->nvram_jedecnum = JEDEC_ATMEL;
  7943. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7944. break;
  7945. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7946. tp->nvram_jedecnum = JEDEC_ATMEL;
  7947. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7948. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7949. break;
  7950. case FLASH_5752VENDOR_ST_M45PE10:
  7951. case FLASH_5752VENDOR_ST_M45PE20:
  7952. case FLASH_5752VENDOR_ST_M45PE40:
  7953. tp->nvram_jedecnum = JEDEC_ST;
  7954. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7955. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7956. break;
  7957. }
  7958. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7959. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7960. case FLASH_5752PAGE_SIZE_256:
  7961. tp->nvram_pagesize = 256;
  7962. break;
  7963. case FLASH_5752PAGE_SIZE_512:
  7964. tp->nvram_pagesize = 512;
  7965. break;
  7966. case FLASH_5752PAGE_SIZE_1K:
  7967. tp->nvram_pagesize = 1024;
  7968. break;
  7969. case FLASH_5752PAGE_SIZE_2K:
  7970. tp->nvram_pagesize = 2048;
  7971. break;
  7972. case FLASH_5752PAGE_SIZE_4K:
  7973. tp->nvram_pagesize = 4096;
  7974. break;
  7975. case FLASH_5752PAGE_SIZE_264:
  7976. tp->nvram_pagesize = 264;
  7977. break;
  7978. }
  7979. }
  7980. else {
  7981. /* For eeprom, set pagesize to maximum eeprom size */
  7982. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7983. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7984. tw32(NVRAM_CFG1, nvcfg1);
  7985. }
  7986. }
  7987. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  7988. {
  7989. u32 nvcfg1, protect = 0;
  7990. nvcfg1 = tr32(NVRAM_CFG1);
  7991. /* NVRAM protection for TPM */
  7992. if (nvcfg1 & (1 << 27)) {
  7993. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7994. protect = 1;
  7995. }
  7996. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  7997. switch (nvcfg1) {
  7998. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  7999. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8000. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8001. tp->nvram_jedecnum = JEDEC_ATMEL;
  8002. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8003. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8004. tp->nvram_pagesize = 264;
  8005. if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1)
  8006. tp->nvram_size = (protect ? 0x3e200 : 0x80000);
  8007. else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
  8008. tp->nvram_size = (protect ? 0x1f200 : 0x40000);
  8009. else
  8010. tp->nvram_size = (protect ? 0x1f200 : 0x20000);
  8011. break;
  8012. case FLASH_5752VENDOR_ST_M45PE10:
  8013. case FLASH_5752VENDOR_ST_M45PE20:
  8014. case FLASH_5752VENDOR_ST_M45PE40:
  8015. tp->nvram_jedecnum = JEDEC_ST;
  8016. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8017. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8018. tp->nvram_pagesize = 256;
  8019. if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
  8020. tp->nvram_size = (protect ? 0x10000 : 0x20000);
  8021. else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
  8022. tp->nvram_size = (protect ? 0x10000 : 0x40000);
  8023. else
  8024. tp->nvram_size = (protect ? 0x20000 : 0x80000);
  8025. break;
  8026. }
  8027. }
  8028. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8029. {
  8030. u32 nvcfg1;
  8031. nvcfg1 = tr32(NVRAM_CFG1);
  8032. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8033. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8034. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8035. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8036. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8037. tp->nvram_jedecnum = JEDEC_ATMEL;
  8038. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8039. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8040. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8041. tw32(NVRAM_CFG1, nvcfg1);
  8042. break;
  8043. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8044. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8045. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8046. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8047. tp->nvram_jedecnum = JEDEC_ATMEL;
  8048. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8049. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8050. tp->nvram_pagesize = 264;
  8051. break;
  8052. case FLASH_5752VENDOR_ST_M45PE10:
  8053. case FLASH_5752VENDOR_ST_M45PE20:
  8054. case FLASH_5752VENDOR_ST_M45PE40:
  8055. tp->nvram_jedecnum = JEDEC_ST;
  8056. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8057. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8058. tp->nvram_pagesize = 256;
  8059. break;
  8060. }
  8061. }
  8062. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8063. {
  8064. tp->nvram_jedecnum = JEDEC_ATMEL;
  8065. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8066. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8067. }
  8068. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8069. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8070. {
  8071. tw32_f(GRC_EEPROM_ADDR,
  8072. (EEPROM_ADDR_FSM_RESET |
  8073. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8074. EEPROM_ADDR_CLKPERD_SHIFT)));
  8075. msleep(1);
  8076. /* Enable seeprom accesses. */
  8077. tw32_f(GRC_LOCAL_CTRL,
  8078. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8079. udelay(100);
  8080. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8081. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8082. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8083. if (tg3_nvram_lock(tp)) {
  8084. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8085. "tg3_nvram_init failed.\n", tp->dev->name);
  8086. return;
  8087. }
  8088. tg3_enable_nvram_access(tp);
  8089. tp->nvram_size = 0;
  8090. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8091. tg3_get_5752_nvram_info(tp);
  8092. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8093. tg3_get_5755_nvram_info(tp);
  8094. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8095. tg3_get_5787_nvram_info(tp);
  8096. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8097. tg3_get_5906_nvram_info(tp);
  8098. else
  8099. tg3_get_nvram_info(tp);
  8100. if (tp->nvram_size == 0)
  8101. tg3_get_nvram_size(tp);
  8102. tg3_disable_nvram_access(tp);
  8103. tg3_nvram_unlock(tp);
  8104. } else {
  8105. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8106. tg3_get_eeprom_size(tp);
  8107. }
  8108. }
  8109. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8110. u32 offset, u32 *val)
  8111. {
  8112. u32 tmp;
  8113. int i;
  8114. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8115. (offset % 4) != 0)
  8116. return -EINVAL;
  8117. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8118. EEPROM_ADDR_DEVID_MASK |
  8119. EEPROM_ADDR_READ);
  8120. tw32(GRC_EEPROM_ADDR,
  8121. tmp |
  8122. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8123. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8124. EEPROM_ADDR_ADDR_MASK) |
  8125. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8126. for (i = 0; i < 1000; i++) {
  8127. tmp = tr32(GRC_EEPROM_ADDR);
  8128. if (tmp & EEPROM_ADDR_COMPLETE)
  8129. break;
  8130. msleep(1);
  8131. }
  8132. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8133. return -EBUSY;
  8134. *val = tr32(GRC_EEPROM_DATA);
  8135. return 0;
  8136. }
  8137. #define NVRAM_CMD_TIMEOUT 10000
  8138. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8139. {
  8140. int i;
  8141. tw32(NVRAM_CMD, nvram_cmd);
  8142. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8143. udelay(10);
  8144. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8145. udelay(10);
  8146. break;
  8147. }
  8148. }
  8149. if (i == NVRAM_CMD_TIMEOUT) {
  8150. return -EBUSY;
  8151. }
  8152. return 0;
  8153. }
  8154. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8155. {
  8156. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8157. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8158. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8159. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8160. addr = ((addr / tp->nvram_pagesize) <<
  8161. ATMEL_AT45DB0X1B_PAGE_POS) +
  8162. (addr % tp->nvram_pagesize);
  8163. return addr;
  8164. }
  8165. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8166. {
  8167. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8168. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8169. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8170. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8171. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8172. tp->nvram_pagesize) +
  8173. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8174. return addr;
  8175. }
  8176. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8177. {
  8178. int ret;
  8179. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8180. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8181. offset = tg3_nvram_phys_addr(tp, offset);
  8182. if (offset > NVRAM_ADDR_MSK)
  8183. return -EINVAL;
  8184. ret = tg3_nvram_lock(tp);
  8185. if (ret)
  8186. return ret;
  8187. tg3_enable_nvram_access(tp);
  8188. tw32(NVRAM_ADDR, offset);
  8189. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8190. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8191. if (ret == 0)
  8192. *val = swab32(tr32(NVRAM_RDDATA));
  8193. tg3_disable_nvram_access(tp);
  8194. tg3_nvram_unlock(tp);
  8195. return ret;
  8196. }
  8197. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8198. {
  8199. int err;
  8200. u32 tmp;
  8201. err = tg3_nvram_read(tp, offset, &tmp);
  8202. *val = swab32(tmp);
  8203. return err;
  8204. }
  8205. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8206. u32 offset, u32 len, u8 *buf)
  8207. {
  8208. int i, j, rc = 0;
  8209. u32 val;
  8210. for (i = 0; i < len; i += 4) {
  8211. u32 addr, data;
  8212. addr = offset + i;
  8213. memcpy(&data, buf + i, 4);
  8214. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8215. val = tr32(GRC_EEPROM_ADDR);
  8216. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8217. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8218. EEPROM_ADDR_READ);
  8219. tw32(GRC_EEPROM_ADDR, val |
  8220. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8221. (addr & EEPROM_ADDR_ADDR_MASK) |
  8222. EEPROM_ADDR_START |
  8223. EEPROM_ADDR_WRITE);
  8224. for (j = 0; j < 1000; j++) {
  8225. val = tr32(GRC_EEPROM_ADDR);
  8226. if (val & EEPROM_ADDR_COMPLETE)
  8227. break;
  8228. msleep(1);
  8229. }
  8230. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8231. rc = -EBUSY;
  8232. break;
  8233. }
  8234. }
  8235. return rc;
  8236. }
  8237. /* offset and length are dword aligned */
  8238. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8239. u8 *buf)
  8240. {
  8241. int ret = 0;
  8242. u32 pagesize = tp->nvram_pagesize;
  8243. u32 pagemask = pagesize - 1;
  8244. u32 nvram_cmd;
  8245. u8 *tmp;
  8246. tmp = kmalloc(pagesize, GFP_KERNEL);
  8247. if (tmp == NULL)
  8248. return -ENOMEM;
  8249. while (len) {
  8250. int j;
  8251. u32 phy_addr, page_off, size;
  8252. phy_addr = offset & ~pagemask;
  8253. for (j = 0; j < pagesize; j += 4) {
  8254. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8255. (u32 *) (tmp + j))))
  8256. break;
  8257. }
  8258. if (ret)
  8259. break;
  8260. page_off = offset & pagemask;
  8261. size = pagesize;
  8262. if (len < size)
  8263. size = len;
  8264. len -= size;
  8265. memcpy(tmp + page_off, buf, size);
  8266. offset = offset + (pagesize - page_off);
  8267. tg3_enable_nvram_access(tp);
  8268. /*
  8269. * Before we can erase the flash page, we need
  8270. * to issue a special "write enable" command.
  8271. */
  8272. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8273. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8274. break;
  8275. /* Erase the target page */
  8276. tw32(NVRAM_ADDR, phy_addr);
  8277. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8278. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8279. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8280. break;
  8281. /* Issue another write enable to start the write. */
  8282. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8283. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8284. break;
  8285. for (j = 0; j < pagesize; j += 4) {
  8286. u32 data;
  8287. data = *((u32 *) (tmp + j));
  8288. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8289. tw32(NVRAM_ADDR, phy_addr + j);
  8290. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8291. NVRAM_CMD_WR;
  8292. if (j == 0)
  8293. nvram_cmd |= NVRAM_CMD_FIRST;
  8294. else if (j == (pagesize - 4))
  8295. nvram_cmd |= NVRAM_CMD_LAST;
  8296. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8297. break;
  8298. }
  8299. if (ret)
  8300. break;
  8301. }
  8302. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8303. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8304. kfree(tmp);
  8305. return ret;
  8306. }
  8307. /* offset and length are dword aligned */
  8308. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8309. u8 *buf)
  8310. {
  8311. int i, ret = 0;
  8312. for (i = 0; i < len; i += 4, offset += 4) {
  8313. u32 data, page_off, phy_addr, nvram_cmd;
  8314. memcpy(&data, buf + i, 4);
  8315. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8316. page_off = offset % tp->nvram_pagesize;
  8317. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8318. tw32(NVRAM_ADDR, phy_addr);
  8319. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8320. if ((page_off == 0) || (i == 0))
  8321. nvram_cmd |= NVRAM_CMD_FIRST;
  8322. if (page_off == (tp->nvram_pagesize - 4))
  8323. nvram_cmd |= NVRAM_CMD_LAST;
  8324. if (i == (len - 4))
  8325. nvram_cmd |= NVRAM_CMD_LAST;
  8326. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8327. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8328. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8329. (tp->nvram_jedecnum == JEDEC_ST) &&
  8330. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8331. if ((ret = tg3_nvram_exec_cmd(tp,
  8332. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8333. NVRAM_CMD_DONE)))
  8334. break;
  8335. }
  8336. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8337. /* We always do complete word writes to eeprom. */
  8338. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8339. }
  8340. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8341. break;
  8342. }
  8343. return ret;
  8344. }
  8345. /* offset and length are dword aligned */
  8346. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8347. {
  8348. int ret;
  8349. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8350. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8351. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8352. udelay(40);
  8353. }
  8354. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8355. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8356. }
  8357. else {
  8358. u32 grc_mode;
  8359. ret = tg3_nvram_lock(tp);
  8360. if (ret)
  8361. return ret;
  8362. tg3_enable_nvram_access(tp);
  8363. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8364. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8365. tw32(NVRAM_WRITE1, 0x406);
  8366. grc_mode = tr32(GRC_MODE);
  8367. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8368. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8369. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8370. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8371. buf);
  8372. }
  8373. else {
  8374. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8375. buf);
  8376. }
  8377. grc_mode = tr32(GRC_MODE);
  8378. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8379. tg3_disable_nvram_access(tp);
  8380. tg3_nvram_unlock(tp);
  8381. }
  8382. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8383. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8384. udelay(40);
  8385. }
  8386. return ret;
  8387. }
  8388. struct subsys_tbl_ent {
  8389. u16 subsys_vendor, subsys_devid;
  8390. u32 phy_id;
  8391. };
  8392. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8393. /* Broadcom boards. */
  8394. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8395. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8396. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8397. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8398. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8399. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8400. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8401. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8402. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8403. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8404. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8405. /* 3com boards. */
  8406. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8407. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8408. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8409. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8410. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8411. /* DELL boards. */
  8412. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8413. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8414. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8415. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8416. /* Compaq boards. */
  8417. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8418. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8419. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8420. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8421. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8422. /* IBM boards. */
  8423. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8424. };
  8425. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8426. {
  8427. int i;
  8428. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8429. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8430. tp->pdev->subsystem_vendor) &&
  8431. (subsys_id_to_phy_id[i].subsys_devid ==
  8432. tp->pdev->subsystem_device))
  8433. return &subsys_id_to_phy_id[i];
  8434. }
  8435. return NULL;
  8436. }
  8437. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8438. {
  8439. u32 val;
  8440. u16 pmcsr;
  8441. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8442. * so need make sure we're in D0.
  8443. */
  8444. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8445. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8446. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8447. msleep(1);
  8448. /* Make sure register accesses (indirect or otherwise)
  8449. * will function correctly.
  8450. */
  8451. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8452. tp->misc_host_ctrl);
  8453. /* The memory arbiter has to be enabled in order for SRAM accesses
  8454. * to succeed. Normally on powerup the tg3 chip firmware will make
  8455. * sure it is enabled, but other entities such as system netboot
  8456. * code might disable it.
  8457. */
  8458. val = tr32(MEMARB_MODE);
  8459. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8460. tp->phy_id = PHY_ID_INVALID;
  8461. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8462. /* Assume an onboard device and WOL capable by default. */
  8463. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
  8464. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8465. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  8466. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8467. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8468. }
  8469. if (tr32(VCPU_CFGSHDW) & VCPU_CFGSHDW_ASPM_DBNC)
  8470. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  8471. return;
  8472. }
  8473. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8474. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8475. u32 nic_cfg, led_cfg;
  8476. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8477. int eeprom_phy_serdes = 0;
  8478. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8479. tp->nic_sram_data_cfg = nic_cfg;
  8480. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8481. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8482. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8483. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8484. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8485. (ver > 0) && (ver < 0x100))
  8486. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8487. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8488. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8489. eeprom_phy_serdes = 1;
  8490. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8491. if (nic_phy_id != 0) {
  8492. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8493. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8494. eeprom_phy_id = (id1 >> 16) << 10;
  8495. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8496. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8497. } else
  8498. eeprom_phy_id = 0;
  8499. tp->phy_id = eeprom_phy_id;
  8500. if (eeprom_phy_serdes) {
  8501. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8502. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8503. else
  8504. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8505. }
  8506. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8507. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8508. SHASTA_EXT_LED_MODE_MASK);
  8509. else
  8510. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8511. switch (led_cfg) {
  8512. default:
  8513. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8514. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8515. break;
  8516. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8517. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8518. break;
  8519. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8520. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8521. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8522. * read on some older 5700/5701 bootcode.
  8523. */
  8524. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8525. ASIC_REV_5700 ||
  8526. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8527. ASIC_REV_5701)
  8528. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8529. break;
  8530. case SHASTA_EXT_LED_SHARED:
  8531. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8532. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8533. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8534. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8535. LED_CTRL_MODE_PHY_2);
  8536. break;
  8537. case SHASTA_EXT_LED_MAC:
  8538. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8539. break;
  8540. case SHASTA_EXT_LED_COMBO:
  8541. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8542. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8543. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8544. LED_CTRL_MODE_PHY_2);
  8545. break;
  8546. };
  8547. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8548. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8549. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8550. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8551. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  8552. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8553. if ((tp->pdev->subsystem_vendor ==
  8554. PCI_VENDOR_ID_ARIMA) &&
  8555. (tp->pdev->subsystem_device == 0x205a ||
  8556. tp->pdev->subsystem_device == 0x2063))
  8557. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8558. } else {
  8559. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8560. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8561. }
  8562. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8563. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8564. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8565. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8566. }
  8567. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  8568. !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
  8569. tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
  8570. if (cfg2 & (1 << 17))
  8571. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8572. /* serdes signal pre-emphasis in register 0x590 set by */
  8573. /* bootcode if bit 18 is set */
  8574. if (cfg2 & (1 << 18))
  8575. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8576. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  8577. u32 cfg3;
  8578. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3);
  8579. if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)
  8580. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  8581. }
  8582. }
  8583. }
  8584. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8585. {
  8586. u32 hw_phy_id_1, hw_phy_id_2;
  8587. u32 hw_phy_id, hw_phy_id_masked;
  8588. int err;
  8589. /* Reading the PHY ID register can conflict with ASF
  8590. * firwmare access to the PHY hardware.
  8591. */
  8592. err = 0;
  8593. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8594. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8595. } else {
  8596. /* Now read the physical PHY_ID from the chip and verify
  8597. * that it is sane. If it doesn't look good, we fall back
  8598. * to either the hard-coded table based PHY_ID and failing
  8599. * that the value found in the eeprom area.
  8600. */
  8601. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8602. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8603. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8604. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8605. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8606. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8607. }
  8608. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8609. tp->phy_id = hw_phy_id;
  8610. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8611. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8612. else
  8613. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8614. } else {
  8615. if (tp->phy_id != PHY_ID_INVALID) {
  8616. /* Do nothing, phy ID already set up in
  8617. * tg3_get_eeprom_hw_cfg().
  8618. */
  8619. } else {
  8620. struct subsys_tbl_ent *p;
  8621. /* No eeprom signature? Try the hardcoded
  8622. * subsys device table.
  8623. */
  8624. p = lookup_by_subsys(tp);
  8625. if (!p)
  8626. return -ENODEV;
  8627. tp->phy_id = p->phy_id;
  8628. if (!tp->phy_id ||
  8629. tp->phy_id == PHY_ID_BCM8002)
  8630. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8631. }
  8632. }
  8633. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8634. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8635. u32 bmsr, adv_reg, tg3_ctrl, mask;
  8636. tg3_readphy(tp, MII_BMSR, &bmsr);
  8637. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8638. (bmsr & BMSR_LSTATUS))
  8639. goto skip_phy_reset;
  8640. err = tg3_phy_reset(tp);
  8641. if (err)
  8642. return err;
  8643. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8644. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8645. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8646. tg3_ctrl = 0;
  8647. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8648. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8649. MII_TG3_CTRL_ADV_1000_FULL);
  8650. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8651. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8652. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8653. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8654. }
  8655. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  8656. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  8657. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  8658. if (!tg3_copper_is_advertising_all(tp, mask)) {
  8659. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8660. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8661. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8662. tg3_writephy(tp, MII_BMCR,
  8663. BMCR_ANENABLE | BMCR_ANRESTART);
  8664. }
  8665. tg3_phy_set_wirespeed(tp);
  8666. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8667. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8668. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8669. }
  8670. skip_phy_reset:
  8671. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8672. err = tg3_init_5401phy_dsp(tp);
  8673. if (err)
  8674. return err;
  8675. }
  8676. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8677. err = tg3_init_5401phy_dsp(tp);
  8678. }
  8679. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8680. tp->link_config.advertising =
  8681. (ADVERTISED_1000baseT_Half |
  8682. ADVERTISED_1000baseT_Full |
  8683. ADVERTISED_Autoneg |
  8684. ADVERTISED_FIBRE);
  8685. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8686. tp->link_config.advertising &=
  8687. ~(ADVERTISED_1000baseT_Half |
  8688. ADVERTISED_1000baseT_Full);
  8689. return err;
  8690. }
  8691. static void __devinit tg3_read_partno(struct tg3 *tp)
  8692. {
  8693. unsigned char vpd_data[256];
  8694. unsigned int i;
  8695. u32 magic;
  8696. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8697. goto out_not_found;
  8698. if (magic == TG3_EEPROM_MAGIC) {
  8699. for (i = 0; i < 256; i += 4) {
  8700. u32 tmp;
  8701. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8702. goto out_not_found;
  8703. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8704. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8705. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8706. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8707. }
  8708. } else {
  8709. int vpd_cap;
  8710. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8711. for (i = 0; i < 256; i += 4) {
  8712. u32 tmp, j = 0;
  8713. u16 tmp16;
  8714. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8715. i);
  8716. while (j++ < 100) {
  8717. pci_read_config_word(tp->pdev, vpd_cap +
  8718. PCI_VPD_ADDR, &tmp16);
  8719. if (tmp16 & 0x8000)
  8720. break;
  8721. msleep(1);
  8722. }
  8723. if (!(tmp16 & 0x8000))
  8724. goto out_not_found;
  8725. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8726. &tmp);
  8727. tmp = cpu_to_le32(tmp);
  8728. memcpy(&vpd_data[i], &tmp, 4);
  8729. }
  8730. }
  8731. /* Now parse and find the part number. */
  8732. for (i = 0; i < 254; ) {
  8733. unsigned char val = vpd_data[i];
  8734. unsigned int block_end;
  8735. if (val == 0x82 || val == 0x91) {
  8736. i = (i + 3 +
  8737. (vpd_data[i + 1] +
  8738. (vpd_data[i + 2] << 8)));
  8739. continue;
  8740. }
  8741. if (val != 0x90)
  8742. goto out_not_found;
  8743. block_end = (i + 3 +
  8744. (vpd_data[i + 1] +
  8745. (vpd_data[i + 2] << 8)));
  8746. i += 3;
  8747. if (block_end > 256)
  8748. goto out_not_found;
  8749. while (i < (block_end - 2)) {
  8750. if (vpd_data[i + 0] == 'P' &&
  8751. vpd_data[i + 1] == 'N') {
  8752. int partno_len = vpd_data[i + 2];
  8753. i += 3;
  8754. if (partno_len > 24 || (partno_len + i) > 256)
  8755. goto out_not_found;
  8756. memcpy(tp->board_part_number,
  8757. &vpd_data[i], partno_len);
  8758. /* Success. */
  8759. return;
  8760. }
  8761. i += 3 + vpd_data[i + 2];
  8762. }
  8763. /* Part number not found. */
  8764. goto out_not_found;
  8765. }
  8766. out_not_found:
  8767. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8768. strcpy(tp->board_part_number, "BCM95906");
  8769. else
  8770. strcpy(tp->board_part_number, "none");
  8771. }
  8772. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8773. {
  8774. u32 val, offset, start;
  8775. if (tg3_nvram_read_swab(tp, 0, &val))
  8776. return;
  8777. if (val != TG3_EEPROM_MAGIC)
  8778. return;
  8779. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8780. tg3_nvram_read_swab(tp, 0x4, &start))
  8781. return;
  8782. offset = tg3_nvram_logical_addr(tp, offset);
  8783. if (tg3_nvram_read_swab(tp, offset, &val))
  8784. return;
  8785. if ((val & 0xfc000000) == 0x0c000000) {
  8786. u32 ver_offset, addr;
  8787. int i;
  8788. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8789. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8790. return;
  8791. if (val != 0)
  8792. return;
  8793. addr = offset + ver_offset - start;
  8794. for (i = 0; i < 16; i += 4) {
  8795. if (tg3_nvram_read(tp, addr + i, &val))
  8796. return;
  8797. val = cpu_to_le32(val);
  8798. memcpy(tp->fw_ver + i, &val, 4);
  8799. }
  8800. }
  8801. }
  8802. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
  8803. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8804. {
  8805. static struct pci_device_id write_reorder_chipsets[] = {
  8806. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8807. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8808. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8809. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8810. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8811. PCI_DEVICE_ID_VIA_8385_0) },
  8812. { },
  8813. };
  8814. u32 misc_ctrl_reg;
  8815. u32 cacheline_sz_reg;
  8816. u32 pci_state_reg, grc_misc_cfg;
  8817. u32 val;
  8818. u16 pci_cmd;
  8819. int err, pcie_cap;
  8820. /* Force memory write invalidate off. If we leave it on,
  8821. * then on 5700_BX chips we have to enable a workaround.
  8822. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8823. * to match the cacheline size. The Broadcom driver have this
  8824. * workaround but turns MWI off all the times so never uses
  8825. * it. This seems to suggest that the workaround is insufficient.
  8826. */
  8827. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8828. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8829. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8830. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8831. * has the register indirect write enable bit set before
  8832. * we try to access any of the MMIO registers. It is also
  8833. * critical that the PCI-X hw workaround situation is decided
  8834. * before that as well.
  8835. */
  8836. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8837. &misc_ctrl_reg);
  8838. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8839. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8840. /* Wrong chip ID in 5752 A0. This code can be removed later
  8841. * as A0 is not in production.
  8842. */
  8843. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8844. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8845. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8846. * we need to disable memory and use config. cycles
  8847. * only to access all registers. The 5702/03 chips
  8848. * can mistakenly decode the special cycles from the
  8849. * ICH chipsets as memory write cycles, causing corruption
  8850. * of register and memory space. Only certain ICH bridges
  8851. * will drive special cycles with non-zero data during the
  8852. * address phase which can fall within the 5703's address
  8853. * range. This is not an ICH bug as the PCI spec allows
  8854. * non-zero address during special cycles. However, only
  8855. * these ICH bridges are known to drive non-zero addresses
  8856. * during special cycles.
  8857. *
  8858. * Since special cycles do not cross PCI bridges, we only
  8859. * enable this workaround if the 5703 is on the secondary
  8860. * bus of these ICH bridges.
  8861. */
  8862. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8863. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8864. static struct tg3_dev_id {
  8865. u32 vendor;
  8866. u32 device;
  8867. u32 rev;
  8868. } ich_chipsets[] = {
  8869. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8870. PCI_ANY_ID },
  8871. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8872. PCI_ANY_ID },
  8873. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8874. 0xa },
  8875. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8876. PCI_ANY_ID },
  8877. { },
  8878. };
  8879. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8880. struct pci_dev *bridge = NULL;
  8881. while (pci_id->vendor != 0) {
  8882. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8883. bridge);
  8884. if (!bridge) {
  8885. pci_id++;
  8886. continue;
  8887. }
  8888. if (pci_id->rev != PCI_ANY_ID) {
  8889. u8 rev;
  8890. pci_read_config_byte(bridge, PCI_REVISION_ID,
  8891. &rev);
  8892. if (rev > pci_id->rev)
  8893. continue;
  8894. }
  8895. if (bridge->subordinate &&
  8896. (bridge->subordinate->number ==
  8897. tp->pdev->bus->number)) {
  8898. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8899. pci_dev_put(bridge);
  8900. break;
  8901. }
  8902. }
  8903. }
  8904. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8905. * DMA addresses > 40-bit. This bridge may have other additional
  8906. * 57xx devices behind it in some 4-port NIC designs for example.
  8907. * Any tg3 device found behind the bridge will also need the 40-bit
  8908. * DMA workaround.
  8909. */
  8910. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8911. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8912. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8913. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8914. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8915. }
  8916. else {
  8917. struct pci_dev *bridge = NULL;
  8918. do {
  8919. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8920. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8921. bridge);
  8922. if (bridge && bridge->subordinate &&
  8923. (bridge->subordinate->number <=
  8924. tp->pdev->bus->number) &&
  8925. (bridge->subordinate->subordinate >=
  8926. tp->pdev->bus->number)) {
  8927. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8928. pci_dev_put(bridge);
  8929. break;
  8930. }
  8931. } while (bridge);
  8932. }
  8933. /* Initialize misc host control in PCI block. */
  8934. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8935. MISC_HOST_CTRL_CHIPREV);
  8936. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8937. tp->misc_host_ctrl);
  8938. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8939. &cacheline_sz_reg);
  8940. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8941. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8942. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8943. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8944. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  8945. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  8946. tp->pdev_peer = tg3_find_peer(tp);
  8947. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8948. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8949. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8950. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8951. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  8952. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8953. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8954. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8955. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8956. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8957. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8958. tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
  8959. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
  8960. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
  8961. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
  8962. tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
  8963. tp->pdev_peer == tp->pdev))
  8964. tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
  8965. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8966. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8967. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8968. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8969. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8970. } else {
  8971. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  8972. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8973. ASIC_REV_5750 &&
  8974. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  8975. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  8976. }
  8977. }
  8978. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  8979. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  8980. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  8981. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  8982. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  8983. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  8984. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  8985. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  8986. if (pcie_cap != 0) {
  8987. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  8988. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8989. u16 lnkctl;
  8990. pci_read_config_word(tp->pdev,
  8991. pcie_cap + PCI_EXP_LNKCTL,
  8992. &lnkctl);
  8993. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  8994. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  8995. }
  8996. }
  8997. /* If we have an AMD 762 or VIA K8T800 chipset, write
  8998. * reordering to the mailbox registers done by the host
  8999. * controller can cause major troubles. We read back from
  9000. * every mailbox register write to force the writes to be
  9001. * posted to the chip in order.
  9002. */
  9003. if (pci_dev_present(write_reorder_chipsets) &&
  9004. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9005. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  9006. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9007. tp->pci_lat_timer < 64) {
  9008. tp->pci_lat_timer = 64;
  9009. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  9010. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  9011. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  9012. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  9013. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9014. cacheline_sz_reg);
  9015. }
  9016. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9017. &pci_state_reg);
  9018. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  9019. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  9020. /* If this is a 5700 BX chipset, and we are in PCI-X
  9021. * mode, enable register write workaround.
  9022. *
  9023. * The workaround is to use indirect register accesses
  9024. * for all chip writes not to mailbox registers.
  9025. */
  9026. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  9027. u32 pm_reg;
  9028. u16 pci_cmd;
  9029. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9030. /* The chip can have it's power management PCI config
  9031. * space registers clobbered due to this bug.
  9032. * So explicitly force the chip into D0 here.
  9033. */
  9034. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9035. &pm_reg);
  9036. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9037. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9038. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9039. pm_reg);
  9040. /* Also, force SERR#/PERR# in PCI command. */
  9041. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9042. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9043. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9044. }
  9045. }
  9046. /* 5700 BX chips need to have their TX producer index mailboxes
  9047. * written twice to workaround a bug.
  9048. */
  9049. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9050. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9051. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9052. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9053. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9054. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9055. /* Chip-specific fixup from Broadcom driver */
  9056. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9057. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9058. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9059. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9060. }
  9061. /* Default fast path register access methods */
  9062. tp->read32 = tg3_read32;
  9063. tp->write32 = tg3_write32;
  9064. tp->read32_mbox = tg3_read32;
  9065. tp->write32_mbox = tg3_write32;
  9066. tp->write32_tx_mbox = tg3_write32;
  9067. tp->write32_rx_mbox = tg3_write32;
  9068. /* Various workaround register access methods */
  9069. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9070. tp->write32 = tg3_write_indirect_reg32;
  9071. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9072. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9073. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
  9074. /*
  9075. * Back to back register writes can cause problems on these
  9076. * chips, the workaround is to read back all reg writes
  9077. * except those to mailbox regs.
  9078. *
  9079. * See tg3_write_indirect_reg32().
  9080. */
  9081. tp->write32 = tg3_write_flush_reg32;
  9082. }
  9083. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9084. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9085. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9086. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9087. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9088. }
  9089. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9090. tp->read32 = tg3_read_indirect_reg32;
  9091. tp->write32 = tg3_write_indirect_reg32;
  9092. tp->read32_mbox = tg3_read_indirect_mbox;
  9093. tp->write32_mbox = tg3_write_indirect_mbox;
  9094. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9095. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9096. iounmap(tp->regs);
  9097. tp->regs = NULL;
  9098. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9099. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9100. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9101. }
  9102. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9103. tp->read32_mbox = tg3_read32_mbox_5906;
  9104. tp->write32_mbox = tg3_write32_mbox_5906;
  9105. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9106. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9107. }
  9108. if (tp->write32 == tg3_write_indirect_reg32 ||
  9109. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9110. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9111. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9112. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9113. /* Get eeprom hw config before calling tg3_set_power_state().
  9114. * In particular, the TG3_FLG2_IS_NIC flag must be
  9115. * determined before calling tg3_set_power_state() so that
  9116. * we know whether or not to switch out of Vaux power.
  9117. * When the flag is set, it means that GPIO1 is used for eeprom
  9118. * write protect and also implies that it is a LOM where GPIOs
  9119. * are not used to switch power.
  9120. */
  9121. tg3_get_eeprom_hw_cfg(tp);
  9122. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9123. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9124. * It is also used as eeprom write protect on LOMs.
  9125. */
  9126. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9127. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9128. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9129. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9130. GRC_LCLCTRL_GPIO_OUTPUT1);
  9131. /* Unused GPIO3 must be driven as output on 5752 because there
  9132. * are no pull-up resistors on unused GPIO pins.
  9133. */
  9134. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9135. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9136. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9137. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9138. /* Force the chip into D0. */
  9139. err = tg3_set_power_state(tp, PCI_D0);
  9140. if (err) {
  9141. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9142. pci_name(tp->pdev));
  9143. return err;
  9144. }
  9145. /* 5700 B0 chips do not support checksumming correctly due
  9146. * to hardware bugs.
  9147. */
  9148. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9149. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9150. /* Derive initial jumbo mode from MTU assigned in
  9151. * ether_setup() via the alloc_etherdev() call
  9152. */
  9153. if (tp->dev->mtu > ETH_DATA_LEN &&
  9154. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9155. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9156. /* Determine WakeOnLan speed to use. */
  9157. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9158. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9159. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9160. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9161. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9162. } else {
  9163. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9164. }
  9165. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9166. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9167. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9168. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9169. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9170. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9171. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9172. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9173. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9174. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9175. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9176. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9177. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9178. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9179. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9180. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  9181. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9182. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9183. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9184. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9185. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9186. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9187. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9188. }
  9189. tp->coalesce_mode = 0;
  9190. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9191. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9192. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9193. /* Initialize MAC MI mode, polling disabled. */
  9194. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9195. udelay(80);
  9196. /* Initialize data/descriptor byte/word swapping. */
  9197. val = tr32(GRC_MODE);
  9198. val &= GRC_MODE_HOST_STACKUP;
  9199. tw32(GRC_MODE, val | tp->grc_mode);
  9200. tg3_switch_clocks(tp);
  9201. /* Clear this out for sanity. */
  9202. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9203. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9204. &pci_state_reg);
  9205. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9206. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9207. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9208. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9209. chiprevid == CHIPREV_ID_5701_B0 ||
  9210. chiprevid == CHIPREV_ID_5701_B2 ||
  9211. chiprevid == CHIPREV_ID_5701_B5) {
  9212. void __iomem *sram_base;
  9213. /* Write some dummy words into the SRAM status block
  9214. * area, see if it reads back correctly. If the return
  9215. * value is bad, force enable the PCIX workaround.
  9216. */
  9217. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9218. writel(0x00000000, sram_base);
  9219. writel(0x00000000, sram_base + 4);
  9220. writel(0xffffffff, sram_base + 4);
  9221. if (readl(sram_base) != 0x00000000)
  9222. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9223. }
  9224. }
  9225. udelay(50);
  9226. tg3_nvram_init(tp);
  9227. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9228. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9229. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9230. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9231. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9232. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9233. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9234. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9235. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9236. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9237. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9238. HOSTCC_MODE_CLRTICK_TXBD);
  9239. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9240. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9241. tp->misc_host_ctrl);
  9242. }
  9243. /* these are limited to 10/100 only */
  9244. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9245. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9246. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9247. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9248. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9249. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9250. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9251. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9252. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9253. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9254. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9255. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9256. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9257. err = tg3_phy_probe(tp);
  9258. if (err) {
  9259. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9260. pci_name(tp->pdev), err);
  9261. /* ... but do not return immediately ... */
  9262. }
  9263. tg3_read_partno(tp);
  9264. tg3_read_fw_ver(tp);
  9265. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  9266. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9267. } else {
  9268. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9269. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  9270. else
  9271. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9272. }
  9273. /* 5700 {AX,BX} chips have a broken status block link
  9274. * change bit implementation, so we must use the
  9275. * status register in those cases.
  9276. */
  9277. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9278. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9279. else
  9280. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9281. /* The led_ctrl is set during tg3_phy_probe, here we might
  9282. * have to force the link status polling mechanism based
  9283. * upon subsystem IDs.
  9284. */
  9285. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9286. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9287. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9288. TG3_FLAG_USE_LINKCHG_REG);
  9289. }
  9290. /* For all SERDES we poll the MAC status register. */
  9291. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9292. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9293. else
  9294. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9295. /* All chips before 5787 can get confused if TX buffers
  9296. * straddle the 4GB address boundary in some cases.
  9297. */
  9298. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9299. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9300. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9301. tp->dev->hard_start_xmit = tg3_start_xmit;
  9302. else
  9303. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9304. tp->rx_offset = 2;
  9305. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9306. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9307. tp->rx_offset = 0;
  9308. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9309. /* Increment the rx prod index on the rx std ring by at most
  9310. * 8 for these chips to workaround hw errata.
  9311. */
  9312. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9313. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9314. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9315. tp->rx_std_max_post = 8;
  9316. /* By default, disable wake-on-lan. User can change this
  9317. * using ETHTOOL_SWOL.
  9318. */
  9319. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9320. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND)
  9321. tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) &
  9322. PCIE_PWR_MGMT_L1_THRESH_MSK;
  9323. return err;
  9324. }
  9325. #ifdef CONFIG_SPARC
  9326. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9327. {
  9328. struct net_device *dev = tp->dev;
  9329. struct pci_dev *pdev = tp->pdev;
  9330. struct device_node *dp = pci_device_to_OF_node(pdev);
  9331. const unsigned char *addr;
  9332. int len;
  9333. addr = of_get_property(dp, "local-mac-address", &len);
  9334. if (addr && len == 6) {
  9335. memcpy(dev->dev_addr, addr, 6);
  9336. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9337. return 0;
  9338. }
  9339. return -ENODEV;
  9340. }
  9341. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9342. {
  9343. struct net_device *dev = tp->dev;
  9344. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9345. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9346. return 0;
  9347. }
  9348. #endif
  9349. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9350. {
  9351. struct net_device *dev = tp->dev;
  9352. u32 hi, lo, mac_offset;
  9353. int addr_ok = 0;
  9354. #ifdef CONFIG_SPARC
  9355. if (!tg3_get_macaddr_sparc(tp))
  9356. return 0;
  9357. #endif
  9358. mac_offset = 0x7c;
  9359. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9360. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9361. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9362. mac_offset = 0xcc;
  9363. if (tg3_nvram_lock(tp))
  9364. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9365. else
  9366. tg3_nvram_unlock(tp);
  9367. }
  9368. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9369. mac_offset = 0x10;
  9370. /* First try to get it from MAC address mailbox. */
  9371. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9372. if ((hi >> 16) == 0x484b) {
  9373. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9374. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9375. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9376. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9377. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9378. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9379. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9380. /* Some old bootcode may report a 0 MAC address in SRAM */
  9381. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9382. }
  9383. if (!addr_ok) {
  9384. /* Next, try NVRAM. */
  9385. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9386. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9387. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9388. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9389. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9390. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9391. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9392. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9393. }
  9394. /* Finally just fetch it out of the MAC control regs. */
  9395. else {
  9396. hi = tr32(MAC_ADDR_0_HIGH);
  9397. lo = tr32(MAC_ADDR_0_LOW);
  9398. dev->dev_addr[5] = lo & 0xff;
  9399. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9400. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9401. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9402. dev->dev_addr[1] = hi & 0xff;
  9403. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9404. }
  9405. }
  9406. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9407. #ifdef CONFIG_SPARC64
  9408. if (!tg3_get_default_macaddr_sparc(tp))
  9409. return 0;
  9410. #endif
  9411. return -EINVAL;
  9412. }
  9413. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9414. return 0;
  9415. }
  9416. #define BOUNDARY_SINGLE_CACHELINE 1
  9417. #define BOUNDARY_MULTI_CACHELINE 2
  9418. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9419. {
  9420. int cacheline_size;
  9421. u8 byte;
  9422. int goal;
  9423. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9424. if (byte == 0)
  9425. cacheline_size = 1024;
  9426. else
  9427. cacheline_size = (int) byte * 4;
  9428. /* On 5703 and later chips, the boundary bits have no
  9429. * effect.
  9430. */
  9431. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9432. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9433. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9434. goto out;
  9435. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9436. goal = BOUNDARY_MULTI_CACHELINE;
  9437. #else
  9438. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9439. goal = BOUNDARY_SINGLE_CACHELINE;
  9440. #else
  9441. goal = 0;
  9442. #endif
  9443. #endif
  9444. if (!goal)
  9445. goto out;
  9446. /* PCI controllers on most RISC systems tend to disconnect
  9447. * when a device tries to burst across a cache-line boundary.
  9448. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9449. *
  9450. * Unfortunately, for PCI-E there are only limited
  9451. * write-side controls for this, and thus for reads
  9452. * we will still get the disconnects. We'll also waste
  9453. * these PCI cycles for both read and write for chips
  9454. * other than 5700 and 5701 which do not implement the
  9455. * boundary bits.
  9456. */
  9457. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9458. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9459. switch (cacheline_size) {
  9460. case 16:
  9461. case 32:
  9462. case 64:
  9463. case 128:
  9464. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9465. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9466. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9467. } else {
  9468. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9469. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9470. }
  9471. break;
  9472. case 256:
  9473. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9474. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9475. break;
  9476. default:
  9477. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9478. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9479. break;
  9480. };
  9481. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9482. switch (cacheline_size) {
  9483. case 16:
  9484. case 32:
  9485. case 64:
  9486. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9487. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9488. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9489. break;
  9490. }
  9491. /* fallthrough */
  9492. case 128:
  9493. default:
  9494. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9495. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9496. break;
  9497. };
  9498. } else {
  9499. switch (cacheline_size) {
  9500. case 16:
  9501. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9502. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9503. DMA_RWCTRL_WRITE_BNDRY_16);
  9504. break;
  9505. }
  9506. /* fallthrough */
  9507. case 32:
  9508. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9509. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9510. DMA_RWCTRL_WRITE_BNDRY_32);
  9511. break;
  9512. }
  9513. /* fallthrough */
  9514. case 64:
  9515. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9516. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9517. DMA_RWCTRL_WRITE_BNDRY_64);
  9518. break;
  9519. }
  9520. /* fallthrough */
  9521. case 128:
  9522. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9523. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9524. DMA_RWCTRL_WRITE_BNDRY_128);
  9525. break;
  9526. }
  9527. /* fallthrough */
  9528. case 256:
  9529. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9530. DMA_RWCTRL_WRITE_BNDRY_256);
  9531. break;
  9532. case 512:
  9533. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9534. DMA_RWCTRL_WRITE_BNDRY_512);
  9535. break;
  9536. case 1024:
  9537. default:
  9538. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9539. DMA_RWCTRL_WRITE_BNDRY_1024);
  9540. break;
  9541. };
  9542. }
  9543. out:
  9544. return val;
  9545. }
  9546. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9547. {
  9548. struct tg3_internal_buffer_desc test_desc;
  9549. u32 sram_dma_descs;
  9550. int i, ret;
  9551. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9552. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9553. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9554. tw32(RDMAC_STATUS, 0);
  9555. tw32(WDMAC_STATUS, 0);
  9556. tw32(BUFMGR_MODE, 0);
  9557. tw32(FTQ_RESET, 0);
  9558. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9559. test_desc.addr_lo = buf_dma & 0xffffffff;
  9560. test_desc.nic_mbuf = 0x00002100;
  9561. test_desc.len = size;
  9562. /*
  9563. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9564. * the *second* time the tg3 driver was getting loaded after an
  9565. * initial scan.
  9566. *
  9567. * Broadcom tells me:
  9568. * ...the DMA engine is connected to the GRC block and a DMA
  9569. * reset may affect the GRC block in some unpredictable way...
  9570. * The behavior of resets to individual blocks has not been tested.
  9571. *
  9572. * Broadcom noted the GRC reset will also reset all sub-components.
  9573. */
  9574. if (to_device) {
  9575. test_desc.cqid_sqid = (13 << 8) | 2;
  9576. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9577. udelay(40);
  9578. } else {
  9579. test_desc.cqid_sqid = (16 << 8) | 7;
  9580. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9581. udelay(40);
  9582. }
  9583. test_desc.flags = 0x00000005;
  9584. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9585. u32 val;
  9586. val = *(((u32 *)&test_desc) + i);
  9587. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9588. sram_dma_descs + (i * sizeof(u32)));
  9589. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9590. }
  9591. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9592. if (to_device) {
  9593. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9594. } else {
  9595. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9596. }
  9597. ret = -ENODEV;
  9598. for (i = 0; i < 40; i++) {
  9599. u32 val;
  9600. if (to_device)
  9601. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9602. else
  9603. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9604. if ((val & 0xffff) == sram_dma_descs) {
  9605. ret = 0;
  9606. break;
  9607. }
  9608. udelay(100);
  9609. }
  9610. return ret;
  9611. }
  9612. #define TEST_BUFFER_SIZE 0x2000
  9613. static int __devinit tg3_test_dma(struct tg3 *tp)
  9614. {
  9615. dma_addr_t buf_dma;
  9616. u32 *buf, saved_dma_rwctrl;
  9617. int ret;
  9618. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9619. if (!buf) {
  9620. ret = -ENOMEM;
  9621. goto out_nofree;
  9622. }
  9623. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9624. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9625. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9626. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9627. /* DMA read watermark not used on PCIE */
  9628. tp->dma_rwctrl |= 0x00180000;
  9629. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9630. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9631. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9632. tp->dma_rwctrl |= 0x003f0000;
  9633. else
  9634. tp->dma_rwctrl |= 0x003f000f;
  9635. } else {
  9636. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9637. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9638. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9639. u32 read_water = 0x7;
  9640. /* If the 5704 is behind the EPB bridge, we can
  9641. * do the less restrictive ONE_DMA workaround for
  9642. * better performance.
  9643. */
  9644. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9645. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9646. tp->dma_rwctrl |= 0x8000;
  9647. else if (ccval == 0x6 || ccval == 0x7)
  9648. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9649. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  9650. read_water = 4;
  9651. /* Set bit 23 to enable PCIX hw bug fix */
  9652. tp->dma_rwctrl |=
  9653. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  9654. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  9655. (1 << 23);
  9656. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9657. /* 5780 always in PCIX mode */
  9658. tp->dma_rwctrl |= 0x00144000;
  9659. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9660. /* 5714 always in PCIX mode */
  9661. tp->dma_rwctrl |= 0x00148000;
  9662. } else {
  9663. tp->dma_rwctrl |= 0x001b000f;
  9664. }
  9665. }
  9666. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9667. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9668. tp->dma_rwctrl &= 0xfffffff0;
  9669. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9670. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9671. /* Remove this if it causes problems for some boards. */
  9672. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9673. /* On 5700/5701 chips, we need to set this bit.
  9674. * Otherwise the chip will issue cacheline transactions
  9675. * to streamable DMA memory with not all the byte
  9676. * enables turned on. This is an error on several
  9677. * RISC PCI controllers, in particular sparc64.
  9678. *
  9679. * On 5703/5704 chips, this bit has been reassigned
  9680. * a different meaning. In particular, it is used
  9681. * on those chips to enable a PCI-X workaround.
  9682. */
  9683. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9684. }
  9685. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9686. #if 0
  9687. /* Unneeded, already done by tg3_get_invariants. */
  9688. tg3_switch_clocks(tp);
  9689. #endif
  9690. ret = 0;
  9691. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9692. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9693. goto out;
  9694. /* It is best to perform DMA test with maximum write burst size
  9695. * to expose the 5700/5701 write DMA bug.
  9696. */
  9697. saved_dma_rwctrl = tp->dma_rwctrl;
  9698. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9699. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9700. while (1) {
  9701. u32 *p = buf, i;
  9702. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9703. p[i] = i;
  9704. /* Send the buffer to the chip. */
  9705. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9706. if (ret) {
  9707. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9708. break;
  9709. }
  9710. #if 0
  9711. /* validate data reached card RAM correctly. */
  9712. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9713. u32 val;
  9714. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9715. if (le32_to_cpu(val) != p[i]) {
  9716. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9717. /* ret = -ENODEV here? */
  9718. }
  9719. p[i] = 0;
  9720. }
  9721. #endif
  9722. /* Now read it back. */
  9723. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9724. if (ret) {
  9725. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9726. break;
  9727. }
  9728. /* Verify it. */
  9729. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9730. if (p[i] == i)
  9731. continue;
  9732. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9733. DMA_RWCTRL_WRITE_BNDRY_16) {
  9734. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9735. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9736. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9737. break;
  9738. } else {
  9739. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9740. ret = -ENODEV;
  9741. goto out;
  9742. }
  9743. }
  9744. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9745. /* Success. */
  9746. ret = 0;
  9747. break;
  9748. }
  9749. }
  9750. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9751. DMA_RWCTRL_WRITE_BNDRY_16) {
  9752. static struct pci_device_id dma_wait_state_chipsets[] = {
  9753. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9754. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9755. { },
  9756. };
  9757. /* DMA test passed without adjusting DMA boundary,
  9758. * now look for chipsets that are known to expose the
  9759. * DMA bug without failing the test.
  9760. */
  9761. if (pci_dev_present(dma_wait_state_chipsets)) {
  9762. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9763. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9764. }
  9765. else
  9766. /* Safe to use the calculated DMA boundary. */
  9767. tp->dma_rwctrl = saved_dma_rwctrl;
  9768. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9769. }
  9770. out:
  9771. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9772. out_nofree:
  9773. return ret;
  9774. }
  9775. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9776. {
  9777. tp->link_config.advertising =
  9778. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9779. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9780. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9781. ADVERTISED_Autoneg | ADVERTISED_MII);
  9782. tp->link_config.speed = SPEED_INVALID;
  9783. tp->link_config.duplex = DUPLEX_INVALID;
  9784. tp->link_config.autoneg = AUTONEG_ENABLE;
  9785. tp->link_config.active_speed = SPEED_INVALID;
  9786. tp->link_config.active_duplex = DUPLEX_INVALID;
  9787. tp->link_config.phy_is_low_power = 0;
  9788. tp->link_config.orig_speed = SPEED_INVALID;
  9789. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9790. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9791. }
  9792. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9793. {
  9794. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9795. tp->bufmgr_config.mbuf_read_dma_low_water =
  9796. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9797. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9798. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9799. tp->bufmgr_config.mbuf_high_water =
  9800. DEFAULT_MB_HIGH_WATER_5705;
  9801. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9802. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9803. DEFAULT_MB_MACRX_LOW_WATER_5906;
  9804. tp->bufmgr_config.mbuf_high_water =
  9805. DEFAULT_MB_HIGH_WATER_5906;
  9806. }
  9807. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9808. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9809. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9810. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9811. tp->bufmgr_config.mbuf_high_water_jumbo =
  9812. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9813. } else {
  9814. tp->bufmgr_config.mbuf_read_dma_low_water =
  9815. DEFAULT_MB_RDMA_LOW_WATER;
  9816. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9817. DEFAULT_MB_MACRX_LOW_WATER;
  9818. tp->bufmgr_config.mbuf_high_water =
  9819. DEFAULT_MB_HIGH_WATER;
  9820. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9821. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9822. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9823. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9824. tp->bufmgr_config.mbuf_high_water_jumbo =
  9825. DEFAULT_MB_HIGH_WATER_JUMBO;
  9826. }
  9827. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9828. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9829. }
  9830. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9831. {
  9832. switch (tp->phy_id & PHY_ID_MASK) {
  9833. case PHY_ID_BCM5400: return "5400";
  9834. case PHY_ID_BCM5401: return "5401";
  9835. case PHY_ID_BCM5411: return "5411";
  9836. case PHY_ID_BCM5701: return "5701";
  9837. case PHY_ID_BCM5703: return "5703";
  9838. case PHY_ID_BCM5704: return "5704";
  9839. case PHY_ID_BCM5705: return "5705";
  9840. case PHY_ID_BCM5750: return "5750";
  9841. case PHY_ID_BCM5752: return "5752";
  9842. case PHY_ID_BCM5714: return "5714";
  9843. case PHY_ID_BCM5780: return "5780";
  9844. case PHY_ID_BCM5755: return "5755";
  9845. case PHY_ID_BCM5787: return "5787";
  9846. case PHY_ID_BCM5756: return "5722/5756";
  9847. case PHY_ID_BCM5906: return "5906";
  9848. case PHY_ID_BCM8002: return "8002/serdes";
  9849. case 0: return "serdes";
  9850. default: return "unknown";
  9851. };
  9852. }
  9853. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9854. {
  9855. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9856. strcpy(str, "PCI Express");
  9857. return str;
  9858. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9859. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9860. strcpy(str, "PCIX:");
  9861. if ((clock_ctrl == 7) ||
  9862. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9863. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9864. strcat(str, "133MHz");
  9865. else if (clock_ctrl == 0)
  9866. strcat(str, "33MHz");
  9867. else if (clock_ctrl == 2)
  9868. strcat(str, "50MHz");
  9869. else if (clock_ctrl == 4)
  9870. strcat(str, "66MHz");
  9871. else if (clock_ctrl == 6)
  9872. strcat(str, "100MHz");
  9873. } else {
  9874. strcpy(str, "PCI:");
  9875. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9876. strcat(str, "66MHz");
  9877. else
  9878. strcat(str, "33MHz");
  9879. }
  9880. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9881. strcat(str, ":32-bit");
  9882. else
  9883. strcat(str, ":64-bit");
  9884. return str;
  9885. }
  9886. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9887. {
  9888. struct pci_dev *peer;
  9889. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9890. for (func = 0; func < 8; func++) {
  9891. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9892. if (peer && peer != tp->pdev)
  9893. break;
  9894. pci_dev_put(peer);
  9895. }
  9896. /* 5704 can be configured in single-port mode, set peer to
  9897. * tp->pdev in that case.
  9898. */
  9899. if (!peer) {
  9900. peer = tp->pdev;
  9901. return peer;
  9902. }
  9903. /*
  9904. * We don't need to keep the refcount elevated; there's no way
  9905. * to remove one half of this device without removing the other
  9906. */
  9907. pci_dev_put(peer);
  9908. return peer;
  9909. }
  9910. static void __devinit tg3_init_coal(struct tg3 *tp)
  9911. {
  9912. struct ethtool_coalesce *ec = &tp->coal;
  9913. memset(ec, 0, sizeof(*ec));
  9914. ec->cmd = ETHTOOL_GCOALESCE;
  9915. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9916. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9917. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9918. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9919. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9920. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9921. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9922. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9923. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9924. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9925. HOSTCC_MODE_CLRTICK_TXBD)) {
  9926. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9927. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9928. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9929. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9930. }
  9931. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9932. ec->rx_coalesce_usecs_irq = 0;
  9933. ec->tx_coalesce_usecs_irq = 0;
  9934. ec->stats_block_coalesce_usecs = 0;
  9935. }
  9936. }
  9937. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9938. const struct pci_device_id *ent)
  9939. {
  9940. static int tg3_version_printed = 0;
  9941. unsigned long tg3reg_base, tg3reg_len;
  9942. struct net_device *dev;
  9943. struct tg3 *tp;
  9944. int i, err, pm_cap;
  9945. char str[40];
  9946. u64 dma_mask, persist_dma_mask;
  9947. if (tg3_version_printed++ == 0)
  9948. printk(KERN_INFO "%s", version);
  9949. err = pci_enable_device(pdev);
  9950. if (err) {
  9951. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9952. "aborting.\n");
  9953. return err;
  9954. }
  9955. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9956. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9957. "base address, aborting.\n");
  9958. err = -ENODEV;
  9959. goto err_out_disable_pdev;
  9960. }
  9961. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9962. if (err) {
  9963. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9964. "aborting.\n");
  9965. goto err_out_disable_pdev;
  9966. }
  9967. pci_set_master(pdev);
  9968. /* Find power-management capability. */
  9969. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9970. if (pm_cap == 0) {
  9971. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  9972. "aborting.\n");
  9973. err = -EIO;
  9974. goto err_out_free_res;
  9975. }
  9976. tg3reg_base = pci_resource_start(pdev, 0);
  9977. tg3reg_len = pci_resource_len(pdev, 0);
  9978. dev = alloc_etherdev(sizeof(*tp));
  9979. if (!dev) {
  9980. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  9981. err = -ENOMEM;
  9982. goto err_out_free_res;
  9983. }
  9984. SET_MODULE_OWNER(dev);
  9985. SET_NETDEV_DEV(dev, &pdev->dev);
  9986. #if TG3_VLAN_TAG_USED
  9987. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  9988. dev->vlan_rx_register = tg3_vlan_rx_register;
  9989. dev->vlan_rx_kill_vid = tg3_vlan_rx_kill_vid;
  9990. #endif
  9991. tp = netdev_priv(dev);
  9992. tp->pdev = pdev;
  9993. tp->dev = dev;
  9994. tp->pm_cap = pm_cap;
  9995. tp->mac_mode = TG3_DEF_MAC_MODE;
  9996. tp->rx_mode = TG3_DEF_RX_MODE;
  9997. tp->tx_mode = TG3_DEF_TX_MODE;
  9998. tp->mi_mode = MAC_MI_MODE_BASE;
  9999. if (tg3_debug > 0)
  10000. tp->msg_enable = tg3_debug;
  10001. else
  10002. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  10003. /* The word/byte swap controls here control register access byte
  10004. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  10005. * setting below.
  10006. */
  10007. tp->misc_host_ctrl =
  10008. MISC_HOST_CTRL_MASK_PCI_INT |
  10009. MISC_HOST_CTRL_WORD_SWAP |
  10010. MISC_HOST_CTRL_INDIR_ACCESS |
  10011. MISC_HOST_CTRL_PCISTATE_RW;
  10012. /* The NONFRM (non-frame) byte/word swap controls take effect
  10013. * on descriptor entries, anything which isn't packet data.
  10014. *
  10015. * The StrongARM chips on the board (one for tx, one for rx)
  10016. * are running in big-endian mode.
  10017. */
  10018. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  10019. GRC_MODE_WSWAP_NONFRM_DATA);
  10020. #ifdef __BIG_ENDIAN
  10021. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  10022. #endif
  10023. spin_lock_init(&tp->lock);
  10024. spin_lock_init(&tp->indirect_lock);
  10025. INIT_WORK(&tp->reset_task, tg3_reset_task);
  10026. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10027. if (tp->regs == 0UL) {
  10028. printk(KERN_ERR PFX "Cannot map device registers, "
  10029. "aborting.\n");
  10030. err = -ENOMEM;
  10031. goto err_out_free_dev;
  10032. }
  10033. tg3_init_link_config(tp);
  10034. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10035. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10036. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10037. dev->open = tg3_open;
  10038. dev->stop = tg3_close;
  10039. dev->get_stats = tg3_get_stats;
  10040. dev->set_multicast_list = tg3_set_rx_mode;
  10041. dev->set_mac_address = tg3_set_mac_addr;
  10042. dev->do_ioctl = tg3_ioctl;
  10043. dev->tx_timeout = tg3_tx_timeout;
  10044. dev->poll = tg3_poll;
  10045. dev->ethtool_ops = &tg3_ethtool_ops;
  10046. dev->weight = 64;
  10047. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10048. dev->change_mtu = tg3_change_mtu;
  10049. dev->irq = pdev->irq;
  10050. #ifdef CONFIG_NET_POLL_CONTROLLER
  10051. dev->poll_controller = tg3_poll_controller;
  10052. #endif
  10053. err = tg3_get_invariants(tp);
  10054. if (err) {
  10055. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10056. "aborting.\n");
  10057. goto err_out_iounmap;
  10058. }
  10059. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10060. * device behind the EPB cannot support DMA addresses > 40-bit.
  10061. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10062. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10063. * do DMA address check in tg3_start_xmit().
  10064. */
  10065. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10066. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10067. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10068. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10069. #ifdef CONFIG_HIGHMEM
  10070. dma_mask = DMA_64BIT_MASK;
  10071. #endif
  10072. } else
  10073. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10074. /* Configure DMA attributes. */
  10075. if (dma_mask > DMA_32BIT_MASK) {
  10076. err = pci_set_dma_mask(pdev, dma_mask);
  10077. if (!err) {
  10078. dev->features |= NETIF_F_HIGHDMA;
  10079. err = pci_set_consistent_dma_mask(pdev,
  10080. persist_dma_mask);
  10081. if (err < 0) {
  10082. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10083. "DMA for consistent allocations\n");
  10084. goto err_out_iounmap;
  10085. }
  10086. }
  10087. }
  10088. if (err || dma_mask == DMA_32BIT_MASK) {
  10089. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10090. if (err) {
  10091. printk(KERN_ERR PFX "No usable DMA configuration, "
  10092. "aborting.\n");
  10093. goto err_out_iounmap;
  10094. }
  10095. }
  10096. tg3_init_bufmgr_config(tp);
  10097. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10098. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10099. }
  10100. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10101. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10102. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10103. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10104. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10105. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10106. } else {
  10107. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10108. }
  10109. /* TSO is on by default on chips that support hardware TSO.
  10110. * Firmware TSO on older chips gives lower performance, so it
  10111. * is off by default, but can be enabled using ethtool.
  10112. */
  10113. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10114. dev->features |= NETIF_F_TSO;
  10115. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10116. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10117. dev->features |= NETIF_F_TSO6;
  10118. }
  10119. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10120. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10121. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10122. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10123. tp->rx_pending = 63;
  10124. }
  10125. err = tg3_get_device_address(tp);
  10126. if (err) {
  10127. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10128. "aborting.\n");
  10129. goto err_out_iounmap;
  10130. }
  10131. /*
  10132. * Reset chip in case UNDI or EFI driver did not shutdown
  10133. * DMA self test will enable WDMAC and we'll see (spurious)
  10134. * pending DMA on the PCI bus at that point.
  10135. */
  10136. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10137. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10138. pci_save_state(tp->pdev);
  10139. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10140. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10141. }
  10142. err = tg3_test_dma(tp);
  10143. if (err) {
  10144. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10145. goto err_out_iounmap;
  10146. }
  10147. /* Tigon3 can do ipv4 only... and some chips have buggy
  10148. * checksumming.
  10149. */
  10150. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10151. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10152. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  10153. dev->features |= NETIF_F_HW_CSUM;
  10154. else
  10155. dev->features |= NETIF_F_IP_CSUM;
  10156. dev->features |= NETIF_F_SG;
  10157. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10158. } else
  10159. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10160. /* flow control autonegotiation is default behavior */
  10161. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10162. tg3_init_coal(tp);
  10163. /* Now that we have fully setup the chip, save away a snapshot
  10164. * of the PCI config space. We need to restore this after
  10165. * GRC_MISC_CFG core clock resets and some resume events.
  10166. */
  10167. pci_save_state(tp->pdev);
  10168. pci_set_drvdata(pdev, dev);
  10169. err = register_netdev(dev);
  10170. if (err) {
  10171. printk(KERN_ERR PFX "Cannot register net device, "
  10172. "aborting.\n");
  10173. goto err_out_iounmap;
  10174. }
  10175. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ",
  10176. dev->name,
  10177. tp->board_part_number,
  10178. tp->pci_chip_rev_id,
  10179. tg3_phy_string(tp),
  10180. tg3_bus_string(tp, str),
  10181. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10182. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10183. "10/100/1000Base-T")));
  10184. for (i = 0; i < 6; i++)
  10185. printk("%2.2x%c", dev->dev_addr[i],
  10186. i == 5 ? '\n' : ':');
  10187. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10188. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10189. dev->name,
  10190. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10191. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10192. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10193. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10194. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10195. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10196. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10197. dev->name, tp->dma_rwctrl,
  10198. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10199. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10200. return 0;
  10201. err_out_iounmap:
  10202. if (tp->regs) {
  10203. iounmap(tp->regs);
  10204. tp->regs = NULL;
  10205. }
  10206. err_out_free_dev:
  10207. free_netdev(dev);
  10208. err_out_free_res:
  10209. pci_release_regions(pdev);
  10210. err_out_disable_pdev:
  10211. pci_disable_device(pdev);
  10212. pci_set_drvdata(pdev, NULL);
  10213. return err;
  10214. }
  10215. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10216. {
  10217. struct net_device *dev = pci_get_drvdata(pdev);
  10218. if (dev) {
  10219. struct tg3 *tp = netdev_priv(dev);
  10220. flush_scheduled_work();
  10221. unregister_netdev(dev);
  10222. if (tp->regs) {
  10223. iounmap(tp->regs);
  10224. tp->regs = NULL;
  10225. }
  10226. free_netdev(dev);
  10227. pci_release_regions(pdev);
  10228. pci_disable_device(pdev);
  10229. pci_set_drvdata(pdev, NULL);
  10230. }
  10231. }
  10232. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10233. {
  10234. struct net_device *dev = pci_get_drvdata(pdev);
  10235. struct tg3 *tp = netdev_priv(dev);
  10236. int err;
  10237. if (!netif_running(dev))
  10238. return 0;
  10239. flush_scheduled_work();
  10240. tg3_netif_stop(tp);
  10241. del_timer_sync(&tp->timer);
  10242. tg3_full_lock(tp, 1);
  10243. tg3_disable_ints(tp);
  10244. tg3_full_unlock(tp);
  10245. netif_device_detach(dev);
  10246. tg3_full_lock(tp, 0);
  10247. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10248. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  10249. tg3_full_unlock(tp);
  10250. /* Save MSI address and data for resume. */
  10251. pci_save_state(pdev);
  10252. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  10253. if (err) {
  10254. tg3_full_lock(tp, 0);
  10255. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10256. if (tg3_restart_hw(tp, 1))
  10257. goto out;
  10258. tp->timer.expires = jiffies + tp->timer_offset;
  10259. add_timer(&tp->timer);
  10260. netif_device_attach(dev);
  10261. tg3_netif_start(tp);
  10262. out:
  10263. tg3_full_unlock(tp);
  10264. }
  10265. return err;
  10266. }
  10267. static int tg3_resume(struct pci_dev *pdev)
  10268. {
  10269. struct net_device *dev = pci_get_drvdata(pdev);
  10270. struct tg3 *tp = netdev_priv(dev);
  10271. int err;
  10272. if (!netif_running(dev))
  10273. return 0;
  10274. pci_restore_state(tp->pdev);
  10275. err = tg3_set_power_state(tp, PCI_D0);
  10276. if (err)
  10277. return err;
  10278. netif_device_attach(dev);
  10279. tg3_full_lock(tp, 0);
  10280. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10281. err = tg3_restart_hw(tp, 1);
  10282. if (err)
  10283. goto out;
  10284. tp->timer.expires = jiffies + tp->timer_offset;
  10285. add_timer(&tp->timer);
  10286. tg3_netif_start(tp);
  10287. out:
  10288. tg3_full_unlock(tp);
  10289. return err;
  10290. }
  10291. static struct pci_driver tg3_driver = {
  10292. .name = DRV_MODULE_NAME,
  10293. .id_table = tg3_pci_tbl,
  10294. .probe = tg3_init_one,
  10295. .remove = __devexit_p(tg3_remove_one),
  10296. .suspend = tg3_suspend,
  10297. .resume = tg3_resume
  10298. };
  10299. static int __init tg3_init(void)
  10300. {
  10301. return pci_register_driver(&tg3_driver);
  10302. }
  10303. static void __exit tg3_cleanup(void)
  10304. {
  10305. pci_unregister_driver(&tg3_driver);
  10306. }
  10307. module_init(tg3_init);
  10308. module_exit(tg3_cleanup);