tg3.c 347 KB

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