tg3.c 373 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005-2007 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <net/ip.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/byteorder.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_SPARC
  46. #include <asm/idprom.h>
  47. #include <asm/prom.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #define TG3_TSO_SUPPORT 1
  55. #include "tg3.h"
  56. #define DRV_MODULE_NAME "tg3"
  57. #define PFX DRV_MODULE_NAME ": "
  58. #define DRV_MODULE_VERSION "3.91"
  59. #define DRV_MODULE_RELDATE "April 18, 2008"
  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_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  184. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  185. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  186. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  187. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  188. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  189. {}
  190. };
  191. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  192. static const struct {
  193. const char string[ETH_GSTRING_LEN];
  194. } ethtool_stats_keys[TG3_NUM_STATS] = {
  195. { "rx_octets" },
  196. { "rx_fragments" },
  197. { "rx_ucast_packets" },
  198. { "rx_mcast_packets" },
  199. { "rx_bcast_packets" },
  200. { "rx_fcs_errors" },
  201. { "rx_align_errors" },
  202. { "rx_xon_pause_rcvd" },
  203. { "rx_xoff_pause_rcvd" },
  204. { "rx_mac_ctrl_rcvd" },
  205. { "rx_xoff_entered" },
  206. { "rx_frame_too_long_errors" },
  207. { "rx_jabbers" },
  208. { "rx_undersize_packets" },
  209. { "rx_in_length_errors" },
  210. { "rx_out_length_errors" },
  211. { "rx_64_or_less_octet_packets" },
  212. { "rx_65_to_127_octet_packets" },
  213. { "rx_128_to_255_octet_packets" },
  214. { "rx_256_to_511_octet_packets" },
  215. { "rx_512_to_1023_octet_packets" },
  216. { "rx_1024_to_1522_octet_packets" },
  217. { "rx_1523_to_2047_octet_packets" },
  218. { "rx_2048_to_4095_octet_packets" },
  219. { "rx_4096_to_8191_octet_packets" },
  220. { "rx_8192_to_9022_octet_packets" },
  221. { "tx_octets" },
  222. { "tx_collisions" },
  223. { "tx_xon_sent" },
  224. { "tx_xoff_sent" },
  225. { "tx_flow_control" },
  226. { "tx_mac_errors" },
  227. { "tx_single_collisions" },
  228. { "tx_mult_collisions" },
  229. { "tx_deferred" },
  230. { "tx_excessive_collisions" },
  231. { "tx_late_collisions" },
  232. { "tx_collide_2times" },
  233. { "tx_collide_3times" },
  234. { "tx_collide_4times" },
  235. { "tx_collide_5times" },
  236. { "tx_collide_6times" },
  237. { "tx_collide_7times" },
  238. { "tx_collide_8times" },
  239. { "tx_collide_9times" },
  240. { "tx_collide_10times" },
  241. { "tx_collide_11times" },
  242. { "tx_collide_12times" },
  243. { "tx_collide_13times" },
  244. { "tx_collide_14times" },
  245. { "tx_collide_15times" },
  246. { "tx_ucast_packets" },
  247. { "tx_mcast_packets" },
  248. { "tx_bcast_packets" },
  249. { "tx_carrier_sense_errors" },
  250. { "tx_discards" },
  251. { "tx_errors" },
  252. { "dma_writeq_full" },
  253. { "dma_write_prioq_full" },
  254. { "rxbds_empty" },
  255. { "rx_discards" },
  256. { "rx_errors" },
  257. { "rx_threshold_hit" },
  258. { "dma_readq_full" },
  259. { "dma_read_prioq_full" },
  260. { "tx_comp_queue_full" },
  261. { "ring_set_send_prod_index" },
  262. { "ring_status_update" },
  263. { "nic_irqs" },
  264. { "nic_avoided_irqs" },
  265. { "nic_tx_threshold_hit" }
  266. };
  267. static const struct {
  268. const char string[ETH_GSTRING_LEN];
  269. } ethtool_test_keys[TG3_NUM_TEST] = {
  270. { "nvram test (online) " },
  271. { "link test (online) " },
  272. { "register test (offline)" },
  273. { "memory test (offline)" },
  274. { "loopback test (offline)" },
  275. { "interrupt test (offline)" },
  276. };
  277. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  278. {
  279. writel(val, tp->regs + off);
  280. }
  281. static u32 tg3_read32(struct tg3 *tp, u32 off)
  282. {
  283. return (readl(tp->regs + off));
  284. }
  285. static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val)
  286. {
  287. writel(val, tp->aperegs + off);
  288. }
  289. static u32 tg3_ape_read32(struct tg3 *tp, u32 off)
  290. {
  291. return (readl(tp->aperegs + off));
  292. }
  293. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  294. {
  295. unsigned long flags;
  296. spin_lock_irqsave(&tp->indirect_lock, flags);
  297. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  298. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  299. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  300. }
  301. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  302. {
  303. writel(val, tp->regs + off);
  304. readl(tp->regs + off);
  305. }
  306. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  307. {
  308. unsigned long flags;
  309. u32 val;
  310. spin_lock_irqsave(&tp->indirect_lock, flags);
  311. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  312. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  313. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  314. return val;
  315. }
  316. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  317. {
  318. unsigned long flags;
  319. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  320. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  321. TG3_64BIT_REG_LOW, val);
  322. return;
  323. }
  324. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  325. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  326. TG3_64BIT_REG_LOW, val);
  327. return;
  328. }
  329. spin_lock_irqsave(&tp->indirect_lock, flags);
  330. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  331. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  332. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  333. /* In indirect mode when disabling interrupts, we also need
  334. * to clear the interrupt bit in the GRC local ctrl register.
  335. */
  336. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  337. (val == 0x1)) {
  338. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  339. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  340. }
  341. }
  342. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  343. {
  344. unsigned long flags;
  345. u32 val;
  346. spin_lock_irqsave(&tp->indirect_lock, flags);
  347. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  348. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  349. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  350. return val;
  351. }
  352. /* usec_wait specifies the wait time in usec when writing to certain registers
  353. * where it is unsafe to read back the register without some delay.
  354. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  355. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  356. */
  357. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  358. {
  359. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  360. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  361. /* Non-posted methods */
  362. tp->write32(tp, off, val);
  363. else {
  364. /* Posted method */
  365. tg3_write32(tp, off, val);
  366. if (usec_wait)
  367. udelay(usec_wait);
  368. tp->read32(tp, off);
  369. }
  370. /* Wait again after the read for the posted method to guarantee that
  371. * the wait time is met.
  372. */
  373. if (usec_wait)
  374. udelay(usec_wait);
  375. }
  376. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  377. {
  378. tp->write32_mbox(tp, off, val);
  379. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  380. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  381. tp->read32_mbox(tp, off);
  382. }
  383. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  384. {
  385. void __iomem *mbox = tp->regs + off;
  386. writel(val, mbox);
  387. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  388. writel(val, mbox);
  389. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  390. readl(mbox);
  391. }
  392. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  393. {
  394. return (readl(tp->regs + off + GRCMBOX_BASE));
  395. }
  396. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  397. {
  398. writel(val, tp->regs + off + GRCMBOX_BASE);
  399. }
  400. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  401. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  402. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  403. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  404. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  405. #define tw32(reg,val) tp->write32(tp, reg, val)
  406. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  407. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  408. #define tr32(reg) tp->read32(tp, reg)
  409. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  410. {
  411. unsigned long flags;
  412. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  413. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  414. return;
  415. spin_lock_irqsave(&tp->indirect_lock, flags);
  416. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  417. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  418. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  419. /* Always leave this as zero. */
  420. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  421. } else {
  422. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  423. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  424. /* Always leave this as zero. */
  425. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  426. }
  427. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  428. }
  429. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  430. {
  431. unsigned long flags;
  432. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  433. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  434. *val = 0;
  435. return;
  436. }
  437. spin_lock_irqsave(&tp->indirect_lock, flags);
  438. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  439. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  440. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  441. /* Always leave this as zero. */
  442. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  443. } else {
  444. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  445. *val = tr32(TG3PCI_MEM_WIN_DATA);
  446. /* Always leave this as zero. */
  447. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  448. }
  449. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  450. }
  451. static void tg3_ape_lock_init(struct tg3 *tp)
  452. {
  453. int i;
  454. /* Make sure the driver hasn't any stale locks. */
  455. for (i = 0; i < 8; i++)
  456. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + 4 * i,
  457. APE_LOCK_GRANT_DRIVER);
  458. }
  459. static int tg3_ape_lock(struct tg3 *tp, int locknum)
  460. {
  461. int i, off;
  462. int ret = 0;
  463. u32 status;
  464. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  465. return 0;
  466. switch (locknum) {
  467. case TG3_APE_LOCK_MEM:
  468. break;
  469. default:
  470. return -EINVAL;
  471. }
  472. off = 4 * locknum;
  473. tg3_ape_write32(tp, TG3_APE_LOCK_REQ + off, APE_LOCK_REQ_DRIVER);
  474. /* Wait for up to 1 millisecond to acquire lock. */
  475. for (i = 0; i < 100; i++) {
  476. status = tg3_ape_read32(tp, TG3_APE_LOCK_GRANT + off);
  477. if (status == APE_LOCK_GRANT_DRIVER)
  478. break;
  479. udelay(10);
  480. }
  481. if (status != APE_LOCK_GRANT_DRIVER) {
  482. /* Revoke the lock request. */
  483. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off,
  484. APE_LOCK_GRANT_DRIVER);
  485. ret = -EBUSY;
  486. }
  487. return ret;
  488. }
  489. static void tg3_ape_unlock(struct tg3 *tp, int locknum)
  490. {
  491. int off;
  492. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  493. return;
  494. switch (locknum) {
  495. case TG3_APE_LOCK_MEM:
  496. break;
  497. default:
  498. return;
  499. }
  500. off = 4 * locknum;
  501. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off, APE_LOCK_GRANT_DRIVER);
  502. }
  503. static void tg3_disable_ints(struct tg3 *tp)
  504. {
  505. tw32(TG3PCI_MISC_HOST_CTRL,
  506. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  507. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  508. }
  509. static inline void tg3_cond_int(struct tg3 *tp)
  510. {
  511. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  512. (tp->hw_status->status & SD_STATUS_UPDATED))
  513. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  514. else
  515. tw32(HOSTCC_MODE, tp->coalesce_mode |
  516. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  517. }
  518. static void tg3_enable_ints(struct tg3 *tp)
  519. {
  520. tp->irq_sync = 0;
  521. wmb();
  522. tw32(TG3PCI_MISC_HOST_CTRL,
  523. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  524. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  525. (tp->last_tag << 24));
  526. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  527. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  528. (tp->last_tag << 24));
  529. tg3_cond_int(tp);
  530. }
  531. static inline unsigned int tg3_has_work(struct tg3 *tp)
  532. {
  533. struct tg3_hw_status *sblk = tp->hw_status;
  534. unsigned int work_exists = 0;
  535. /* check for phy events */
  536. if (!(tp->tg3_flags &
  537. (TG3_FLAG_USE_LINKCHG_REG |
  538. TG3_FLAG_POLL_SERDES))) {
  539. if (sblk->status & SD_STATUS_LINK_CHG)
  540. work_exists = 1;
  541. }
  542. /* check for RX/TX work to do */
  543. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  544. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  545. work_exists = 1;
  546. return work_exists;
  547. }
  548. /* tg3_restart_ints
  549. * similar to tg3_enable_ints, but it accurately determines whether there
  550. * is new work pending and can return without flushing the PIO write
  551. * which reenables interrupts
  552. */
  553. static void tg3_restart_ints(struct tg3 *tp)
  554. {
  555. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  556. tp->last_tag << 24);
  557. mmiowb();
  558. /* When doing tagged status, this work check is unnecessary.
  559. * The last_tag we write above tells the chip which piece of
  560. * work we've completed.
  561. */
  562. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  563. tg3_has_work(tp))
  564. tw32(HOSTCC_MODE, tp->coalesce_mode |
  565. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  566. }
  567. static inline void tg3_netif_stop(struct tg3 *tp)
  568. {
  569. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  570. napi_disable(&tp->napi);
  571. netif_tx_disable(tp->dev);
  572. }
  573. static inline void tg3_netif_start(struct tg3 *tp)
  574. {
  575. netif_wake_queue(tp->dev);
  576. /* NOTE: unconditional netif_wake_queue is only appropriate
  577. * so long as all callers are assured to have free tx slots
  578. * (such as after tg3_init_hw)
  579. */
  580. napi_enable(&tp->napi);
  581. tp->hw_status->status |= SD_STATUS_UPDATED;
  582. tg3_enable_ints(tp);
  583. }
  584. static void tg3_switch_clocks(struct tg3 *tp)
  585. {
  586. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  587. u32 orig_clock_ctrl;
  588. if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
  589. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  590. return;
  591. orig_clock_ctrl = clock_ctrl;
  592. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  593. CLOCK_CTRL_CLKRUN_OENABLE |
  594. 0x1f);
  595. tp->pci_clock_ctrl = clock_ctrl;
  596. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  597. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  598. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  599. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  600. }
  601. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  602. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  603. clock_ctrl |
  604. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  605. 40);
  606. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  607. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  608. 40);
  609. }
  610. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  611. }
  612. #define PHY_BUSY_LOOPS 5000
  613. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  614. {
  615. u32 frame_val;
  616. unsigned int loops;
  617. int ret;
  618. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  619. tw32_f(MAC_MI_MODE,
  620. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  621. udelay(80);
  622. }
  623. *val = 0x0;
  624. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  625. MI_COM_PHY_ADDR_MASK);
  626. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  627. MI_COM_REG_ADDR_MASK);
  628. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  629. tw32_f(MAC_MI_COM, frame_val);
  630. loops = PHY_BUSY_LOOPS;
  631. while (loops != 0) {
  632. udelay(10);
  633. frame_val = tr32(MAC_MI_COM);
  634. if ((frame_val & MI_COM_BUSY) == 0) {
  635. udelay(5);
  636. frame_val = tr32(MAC_MI_COM);
  637. break;
  638. }
  639. loops -= 1;
  640. }
  641. ret = -EBUSY;
  642. if (loops != 0) {
  643. *val = frame_val & MI_COM_DATA_MASK;
  644. ret = 0;
  645. }
  646. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  647. tw32_f(MAC_MI_MODE, tp->mi_mode);
  648. udelay(80);
  649. }
  650. return ret;
  651. }
  652. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  653. {
  654. u32 frame_val;
  655. unsigned int loops;
  656. int ret;
  657. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  658. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  659. return 0;
  660. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  661. tw32_f(MAC_MI_MODE,
  662. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  663. udelay(80);
  664. }
  665. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  666. MI_COM_PHY_ADDR_MASK);
  667. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  668. MI_COM_REG_ADDR_MASK);
  669. frame_val |= (val & MI_COM_DATA_MASK);
  670. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  671. tw32_f(MAC_MI_COM, frame_val);
  672. loops = PHY_BUSY_LOOPS;
  673. while (loops != 0) {
  674. udelay(10);
  675. frame_val = tr32(MAC_MI_COM);
  676. if ((frame_val & MI_COM_BUSY) == 0) {
  677. udelay(5);
  678. frame_val = tr32(MAC_MI_COM);
  679. break;
  680. }
  681. loops -= 1;
  682. }
  683. ret = -EBUSY;
  684. if (loops != 0)
  685. ret = 0;
  686. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  687. tw32_f(MAC_MI_MODE, tp->mi_mode);
  688. udelay(80);
  689. }
  690. return ret;
  691. }
  692. static void tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val)
  693. {
  694. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg);
  695. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val);
  696. }
  697. static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
  698. {
  699. u32 phy;
  700. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  701. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  702. return;
  703. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  704. u32 ephy;
  705. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &ephy)) {
  706. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  707. ephy | MII_TG3_EPHY_SHADOW_EN);
  708. if (!tg3_readphy(tp, MII_TG3_EPHYTST_MISCCTRL, &phy)) {
  709. if (enable)
  710. phy |= MII_TG3_EPHYTST_MISCCTRL_MDIX;
  711. else
  712. phy &= ~MII_TG3_EPHYTST_MISCCTRL_MDIX;
  713. tg3_writephy(tp, MII_TG3_EPHYTST_MISCCTRL, phy);
  714. }
  715. tg3_writephy(tp, MII_TG3_EPHY_TEST, ephy);
  716. }
  717. } else {
  718. phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
  719. MII_TG3_AUXCTL_SHDWSEL_MISC;
  720. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
  721. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
  722. if (enable)
  723. phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  724. else
  725. phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  726. phy |= MII_TG3_AUXCTL_MISC_WREN;
  727. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  728. }
  729. }
  730. }
  731. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  732. {
  733. u32 val;
  734. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  735. return;
  736. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  737. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  738. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  739. (val | (1 << 15) | (1 << 4)));
  740. }
  741. static int tg3_bmcr_reset(struct tg3 *tp)
  742. {
  743. u32 phy_control;
  744. int limit, err;
  745. /* OK, reset it, and poll the BMCR_RESET bit until it
  746. * clears or we time out.
  747. */
  748. phy_control = BMCR_RESET;
  749. err = tg3_writephy(tp, MII_BMCR, phy_control);
  750. if (err != 0)
  751. return -EBUSY;
  752. limit = 5000;
  753. while (limit--) {
  754. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  755. if (err != 0)
  756. return -EBUSY;
  757. if ((phy_control & BMCR_RESET) == 0) {
  758. udelay(40);
  759. break;
  760. }
  761. udelay(10);
  762. }
  763. if (limit <= 0)
  764. return -EBUSY;
  765. return 0;
  766. }
  767. static void tg3_phy_apply_otp(struct tg3 *tp)
  768. {
  769. u32 otp, phy;
  770. if (!tp->phy_otp)
  771. return;
  772. otp = tp->phy_otp;
  773. /* Enable SM_DSP clock and tx 6dB coding. */
  774. phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
  775. MII_TG3_AUXCTL_ACTL_SMDSP_ENA |
  776. MII_TG3_AUXCTL_ACTL_TX_6DB;
  777. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  778. phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT);
  779. phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT;
  780. tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy);
  781. phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) |
  782. ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT);
  783. tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy);
  784. phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT);
  785. phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ;
  786. tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy);
  787. phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT);
  788. tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy);
  789. phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT);
  790. tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy);
  791. phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) |
  792. ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT);
  793. tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy);
  794. /* Turn off SM_DSP clock. */
  795. phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
  796. MII_TG3_AUXCTL_ACTL_TX_6DB;
  797. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  798. }
  799. static int tg3_wait_macro_done(struct tg3 *tp)
  800. {
  801. int limit = 100;
  802. while (limit--) {
  803. u32 tmp32;
  804. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  805. if ((tmp32 & 0x1000) == 0)
  806. break;
  807. }
  808. }
  809. if (limit <= 0)
  810. return -EBUSY;
  811. return 0;
  812. }
  813. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  814. {
  815. static const u32 test_pat[4][6] = {
  816. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  817. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  818. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  819. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  820. };
  821. int chan;
  822. for (chan = 0; chan < 4; chan++) {
  823. int i;
  824. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  825. (chan * 0x2000) | 0x0200);
  826. tg3_writephy(tp, 0x16, 0x0002);
  827. for (i = 0; i < 6; i++)
  828. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  829. test_pat[chan][i]);
  830. tg3_writephy(tp, 0x16, 0x0202);
  831. if (tg3_wait_macro_done(tp)) {
  832. *resetp = 1;
  833. return -EBUSY;
  834. }
  835. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  836. (chan * 0x2000) | 0x0200);
  837. tg3_writephy(tp, 0x16, 0x0082);
  838. if (tg3_wait_macro_done(tp)) {
  839. *resetp = 1;
  840. return -EBUSY;
  841. }
  842. tg3_writephy(tp, 0x16, 0x0802);
  843. if (tg3_wait_macro_done(tp)) {
  844. *resetp = 1;
  845. return -EBUSY;
  846. }
  847. for (i = 0; i < 6; i += 2) {
  848. u32 low, high;
  849. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  850. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  851. tg3_wait_macro_done(tp)) {
  852. *resetp = 1;
  853. return -EBUSY;
  854. }
  855. low &= 0x7fff;
  856. high &= 0x000f;
  857. if (low != test_pat[chan][i] ||
  858. high != test_pat[chan][i+1]) {
  859. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  860. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  861. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  862. return -EBUSY;
  863. }
  864. }
  865. }
  866. return 0;
  867. }
  868. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  869. {
  870. int chan;
  871. for (chan = 0; chan < 4; chan++) {
  872. int i;
  873. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  874. (chan * 0x2000) | 0x0200);
  875. tg3_writephy(tp, 0x16, 0x0002);
  876. for (i = 0; i < 6; i++)
  877. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  878. tg3_writephy(tp, 0x16, 0x0202);
  879. if (tg3_wait_macro_done(tp))
  880. return -EBUSY;
  881. }
  882. return 0;
  883. }
  884. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  885. {
  886. u32 reg32, phy9_orig;
  887. int retries, do_phy_reset, err;
  888. retries = 10;
  889. do_phy_reset = 1;
  890. do {
  891. if (do_phy_reset) {
  892. err = tg3_bmcr_reset(tp);
  893. if (err)
  894. return err;
  895. do_phy_reset = 0;
  896. }
  897. /* Disable transmitter and interrupt. */
  898. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  899. continue;
  900. reg32 |= 0x3000;
  901. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  902. /* Set full-duplex, 1000 mbps. */
  903. tg3_writephy(tp, MII_BMCR,
  904. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  905. /* Set to master mode. */
  906. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  907. continue;
  908. tg3_writephy(tp, MII_TG3_CTRL,
  909. (MII_TG3_CTRL_AS_MASTER |
  910. MII_TG3_CTRL_ENABLE_AS_MASTER));
  911. /* Enable SM_DSP_CLOCK and 6dB. */
  912. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  913. /* Block the PHY control access. */
  914. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  915. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  916. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  917. if (!err)
  918. break;
  919. } while (--retries);
  920. err = tg3_phy_reset_chanpat(tp);
  921. if (err)
  922. return err;
  923. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  924. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  925. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  926. tg3_writephy(tp, 0x16, 0x0000);
  927. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  928. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  929. /* Set Extended packet length bit for jumbo frames */
  930. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  931. }
  932. else {
  933. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  934. }
  935. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  936. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  937. reg32 &= ~0x3000;
  938. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  939. } else if (!err)
  940. err = -EBUSY;
  941. return err;
  942. }
  943. static void tg3_link_report(struct tg3 *);
  944. /* This will reset the tigon3 PHY if there is no valid
  945. * link unless the FORCE argument is non-zero.
  946. */
  947. static int tg3_phy_reset(struct tg3 *tp)
  948. {
  949. u32 cpmuctrl;
  950. u32 phy_status;
  951. int err;
  952. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  953. u32 val;
  954. val = tr32(GRC_MISC_CFG);
  955. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  956. udelay(40);
  957. }
  958. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  959. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  960. if (err != 0)
  961. return -EBUSY;
  962. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  963. netif_carrier_off(tp->dev);
  964. tg3_link_report(tp);
  965. }
  966. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  967. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  968. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  969. err = tg3_phy_reset_5703_4_5(tp);
  970. if (err)
  971. return err;
  972. goto out;
  973. }
  974. cpmuctrl = 0;
  975. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
  976. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
  977. cpmuctrl = tr32(TG3_CPMU_CTRL);
  978. if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY)
  979. tw32(TG3_CPMU_CTRL,
  980. cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY);
  981. }
  982. err = tg3_bmcr_reset(tp);
  983. if (err)
  984. return err;
  985. if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) {
  986. u32 phy;
  987. phy = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz;
  988. tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, phy);
  989. tw32(TG3_CPMU_CTRL, cpmuctrl);
  990. }
  991. if (tp->tg3_flags3 & TG3_FLG3_5761_5784_AX_FIXES) {
  992. u32 val;
  993. val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
  994. if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) ==
  995. CPMU_LSPD_1000MB_MACCLK_12_5) {
  996. val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
  997. udelay(40);
  998. tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
  999. }
  1000. /* Disable GPHY autopowerdown. */
  1001. tg3_writephy(tp, MII_TG3_MISC_SHDW,
  1002. MII_TG3_MISC_SHDW_WREN |
  1003. MII_TG3_MISC_SHDW_APD_SEL |
  1004. MII_TG3_MISC_SHDW_APD_WKTM_84MS);
  1005. }
  1006. tg3_phy_apply_otp(tp);
  1007. out:
  1008. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  1009. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1010. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1011. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  1012. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1013. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  1014. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1015. }
  1016. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  1017. tg3_writephy(tp, 0x1c, 0x8d68);
  1018. tg3_writephy(tp, 0x1c, 0x8d68);
  1019. }
  1020. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  1021. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1022. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1023. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  1024. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1025. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  1026. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  1027. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  1028. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1029. }
  1030. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  1031. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1032. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1033. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  1034. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  1035. tg3_writephy(tp, MII_TG3_TEST1,
  1036. MII_TG3_TEST1_TRIM_EN | 0x4);
  1037. } else
  1038. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  1039. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1040. }
  1041. /* Set Extended packet length bit (bit 14) on all chips that */
  1042. /* support jumbo frames */
  1043. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1044. /* Cannot do read-modify-write on 5401 */
  1045. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1046. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  1047. u32 phy_reg;
  1048. /* Set bit 14 with read-modify-write to preserve other bits */
  1049. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  1050. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  1051. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  1052. }
  1053. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  1054. * jumbo frames transmission.
  1055. */
  1056. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  1057. u32 phy_reg;
  1058. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  1059. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1060. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  1061. }
  1062. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1063. /* adjust output voltage */
  1064. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  1065. }
  1066. tg3_phy_toggle_automdix(tp, 1);
  1067. tg3_phy_set_wirespeed(tp);
  1068. return 0;
  1069. }
  1070. static void tg3_frob_aux_power(struct tg3 *tp)
  1071. {
  1072. struct tg3 *tp_peer = tp;
  1073. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  1074. return;
  1075. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  1076. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  1077. struct net_device *dev_peer;
  1078. dev_peer = pci_get_drvdata(tp->pdev_peer);
  1079. /* remove_one() may have been run on the peer. */
  1080. if (!dev_peer)
  1081. tp_peer = tp;
  1082. else
  1083. tp_peer = netdev_priv(dev_peer);
  1084. }
  1085. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  1086. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  1087. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  1088. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  1089. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1090. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1091. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1092. (GRC_LCLCTRL_GPIO_OE0 |
  1093. GRC_LCLCTRL_GPIO_OE1 |
  1094. GRC_LCLCTRL_GPIO_OE2 |
  1095. GRC_LCLCTRL_GPIO_OUTPUT0 |
  1096. GRC_LCLCTRL_GPIO_OUTPUT1),
  1097. 100);
  1098. } else {
  1099. u32 no_gpio2;
  1100. u32 grc_local_ctrl = 0;
  1101. if (tp_peer != tp &&
  1102. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1103. return;
  1104. /* Workaround to prevent overdrawing Amps. */
  1105. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1106. ASIC_REV_5714) {
  1107. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  1108. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1109. grc_local_ctrl, 100);
  1110. }
  1111. /* On 5753 and variants, GPIO2 cannot be used. */
  1112. no_gpio2 = tp->nic_sram_data_cfg &
  1113. NIC_SRAM_DATA_CFG_NO_GPIO2;
  1114. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  1115. GRC_LCLCTRL_GPIO_OE1 |
  1116. GRC_LCLCTRL_GPIO_OE2 |
  1117. GRC_LCLCTRL_GPIO_OUTPUT1 |
  1118. GRC_LCLCTRL_GPIO_OUTPUT2;
  1119. if (no_gpio2) {
  1120. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  1121. GRC_LCLCTRL_GPIO_OUTPUT2);
  1122. }
  1123. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1124. grc_local_ctrl, 100);
  1125. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  1126. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1127. grc_local_ctrl, 100);
  1128. if (!no_gpio2) {
  1129. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  1130. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1131. grc_local_ctrl, 100);
  1132. }
  1133. }
  1134. } else {
  1135. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  1136. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  1137. if (tp_peer != tp &&
  1138. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1139. return;
  1140. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1141. (GRC_LCLCTRL_GPIO_OE1 |
  1142. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1143. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1144. GRC_LCLCTRL_GPIO_OE1, 100);
  1145. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1146. (GRC_LCLCTRL_GPIO_OE1 |
  1147. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1148. }
  1149. }
  1150. }
  1151. static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
  1152. {
  1153. if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
  1154. return 1;
  1155. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411) {
  1156. if (speed != SPEED_10)
  1157. return 1;
  1158. } else if (speed == SPEED_10)
  1159. return 1;
  1160. return 0;
  1161. }
  1162. static int tg3_setup_phy(struct tg3 *, int);
  1163. #define RESET_KIND_SHUTDOWN 0
  1164. #define RESET_KIND_INIT 1
  1165. #define RESET_KIND_SUSPEND 2
  1166. static void tg3_write_sig_post_reset(struct tg3 *, int);
  1167. static int tg3_halt_cpu(struct tg3 *, u32);
  1168. static int tg3_nvram_lock(struct tg3 *);
  1169. static void tg3_nvram_unlock(struct tg3 *);
  1170. static void tg3_power_down_phy(struct tg3 *tp)
  1171. {
  1172. u32 val;
  1173. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1174. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1175. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1176. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1177. sg_dig_ctrl |=
  1178. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1179. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1180. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1181. }
  1182. return;
  1183. }
  1184. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1185. tg3_bmcr_reset(tp);
  1186. val = tr32(GRC_MISC_CFG);
  1187. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1188. udelay(40);
  1189. return;
  1190. } else {
  1191. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1192. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1193. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1194. }
  1195. /* The PHY should not be powered down on some chips because
  1196. * of bugs.
  1197. */
  1198. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1199. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1200. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1201. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1202. return;
  1203. if (tp->tg3_flags3 & TG3_FLG3_5761_5784_AX_FIXES) {
  1204. val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
  1205. val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
  1206. val |= CPMU_LSPD_1000MB_MACCLK_12_5;
  1207. tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
  1208. }
  1209. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1210. }
  1211. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1212. {
  1213. u32 misc_host_ctrl;
  1214. u16 power_control, power_caps;
  1215. int pm = tp->pm_cap;
  1216. /* Make sure register accesses (indirect or otherwise)
  1217. * will function correctly.
  1218. */
  1219. pci_write_config_dword(tp->pdev,
  1220. TG3PCI_MISC_HOST_CTRL,
  1221. tp->misc_host_ctrl);
  1222. pci_read_config_word(tp->pdev,
  1223. pm + PCI_PM_CTRL,
  1224. &power_control);
  1225. power_control |= PCI_PM_CTRL_PME_STATUS;
  1226. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1227. switch (state) {
  1228. case PCI_D0:
  1229. power_control |= 0;
  1230. pci_write_config_word(tp->pdev,
  1231. pm + PCI_PM_CTRL,
  1232. power_control);
  1233. udelay(100); /* Delay after power state change */
  1234. /* Switch out of Vaux if it is a NIC */
  1235. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1236. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1237. return 0;
  1238. case PCI_D1:
  1239. power_control |= 1;
  1240. break;
  1241. case PCI_D2:
  1242. power_control |= 2;
  1243. break;
  1244. case PCI_D3hot:
  1245. power_control |= 3;
  1246. break;
  1247. default:
  1248. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1249. "requested.\n",
  1250. tp->dev->name, state);
  1251. return -EINVAL;
  1252. };
  1253. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1254. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1255. tw32(TG3PCI_MISC_HOST_CTRL,
  1256. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1257. if (tp->link_config.phy_is_low_power == 0) {
  1258. tp->link_config.phy_is_low_power = 1;
  1259. tp->link_config.orig_speed = tp->link_config.speed;
  1260. tp->link_config.orig_duplex = tp->link_config.duplex;
  1261. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1262. }
  1263. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1264. tp->link_config.speed = SPEED_10;
  1265. tp->link_config.duplex = DUPLEX_HALF;
  1266. tp->link_config.autoneg = AUTONEG_ENABLE;
  1267. tg3_setup_phy(tp, 0);
  1268. }
  1269. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1270. u32 val;
  1271. val = tr32(GRC_VCPU_EXT_CTRL);
  1272. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1273. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1274. int i;
  1275. u32 val;
  1276. for (i = 0; i < 200; i++) {
  1277. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1278. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1279. break;
  1280. msleep(1);
  1281. }
  1282. }
  1283. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  1284. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1285. WOL_DRV_STATE_SHUTDOWN |
  1286. WOL_DRV_WOL |
  1287. WOL_SET_MAGIC_PKT);
  1288. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1289. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1290. u32 mac_mode;
  1291. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1292. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1293. udelay(40);
  1294. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1295. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1296. else
  1297. mac_mode = MAC_MODE_PORT_MODE_MII;
  1298. mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
  1299. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1300. ASIC_REV_5700) {
  1301. u32 speed = (tp->tg3_flags &
  1302. TG3_FLAG_WOL_SPEED_100MB) ?
  1303. SPEED_100 : SPEED_10;
  1304. if (tg3_5700_link_polarity(tp, speed))
  1305. mac_mode |= MAC_MODE_LINK_POLARITY;
  1306. else
  1307. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1308. }
  1309. } else {
  1310. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1311. }
  1312. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1313. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1314. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1315. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1316. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1317. tw32_f(MAC_MODE, mac_mode);
  1318. udelay(100);
  1319. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1320. udelay(10);
  1321. }
  1322. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1323. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1324. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1325. u32 base_val;
  1326. base_val = tp->pci_clock_ctrl;
  1327. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1328. CLOCK_CTRL_TXCLK_DISABLE);
  1329. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1330. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1331. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1332. (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
  1333. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1334. /* do nothing */
  1335. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1336. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1337. u32 newbits1, newbits2;
  1338. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1339. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1340. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1341. CLOCK_CTRL_TXCLK_DISABLE |
  1342. CLOCK_CTRL_ALTCLK);
  1343. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1344. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1345. newbits1 = CLOCK_CTRL_625_CORE;
  1346. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1347. } else {
  1348. newbits1 = CLOCK_CTRL_ALTCLK;
  1349. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1350. }
  1351. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1352. 40);
  1353. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1354. 40);
  1355. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1356. u32 newbits3;
  1357. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1358. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1359. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1360. CLOCK_CTRL_TXCLK_DISABLE |
  1361. CLOCK_CTRL_44MHZ_CORE);
  1362. } else {
  1363. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1364. }
  1365. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1366. tp->pci_clock_ctrl | newbits3, 40);
  1367. }
  1368. }
  1369. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1370. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
  1371. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  1372. tg3_power_down_phy(tp);
  1373. tg3_frob_aux_power(tp);
  1374. /* Workaround for unstable PLL clock */
  1375. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1376. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1377. u32 val = tr32(0x7d00);
  1378. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1379. tw32(0x7d00, val);
  1380. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1381. int err;
  1382. err = tg3_nvram_lock(tp);
  1383. tg3_halt_cpu(tp, RX_CPU_BASE);
  1384. if (!err)
  1385. tg3_nvram_unlock(tp);
  1386. }
  1387. }
  1388. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1389. /* Finally, set the new power state. */
  1390. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1391. udelay(100); /* Delay after power state change */
  1392. return 0;
  1393. }
  1394. static void tg3_link_report(struct tg3 *tp)
  1395. {
  1396. if (!netif_carrier_ok(tp->dev)) {
  1397. if (netif_msg_link(tp))
  1398. printk(KERN_INFO PFX "%s: Link is down.\n",
  1399. tp->dev->name);
  1400. } else if (netif_msg_link(tp)) {
  1401. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1402. tp->dev->name,
  1403. (tp->link_config.active_speed == SPEED_1000 ?
  1404. 1000 :
  1405. (tp->link_config.active_speed == SPEED_100 ?
  1406. 100 : 10)),
  1407. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1408. "full" : "half"));
  1409. printk(KERN_INFO PFX
  1410. "%s: Flow control is %s for TX and %s for RX.\n",
  1411. tp->dev->name,
  1412. (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_TX) ?
  1413. "on" : "off",
  1414. (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX) ?
  1415. "on" : "off");
  1416. }
  1417. }
  1418. static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl)
  1419. {
  1420. u16 miireg;
  1421. if ((flow_ctrl & TG3_FLOW_CTRL_TX) && (flow_ctrl & TG3_FLOW_CTRL_RX))
  1422. miireg = ADVERTISE_PAUSE_CAP;
  1423. else if (flow_ctrl & TG3_FLOW_CTRL_TX)
  1424. miireg = ADVERTISE_PAUSE_ASYM;
  1425. else if (flow_ctrl & TG3_FLOW_CTRL_RX)
  1426. miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  1427. else
  1428. miireg = 0;
  1429. return miireg;
  1430. }
  1431. static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl)
  1432. {
  1433. u16 miireg;
  1434. if ((flow_ctrl & TG3_FLOW_CTRL_TX) && (flow_ctrl & TG3_FLOW_CTRL_RX))
  1435. miireg = ADVERTISE_1000XPAUSE;
  1436. else if (flow_ctrl & TG3_FLOW_CTRL_TX)
  1437. miireg = ADVERTISE_1000XPSE_ASYM;
  1438. else if (flow_ctrl & TG3_FLOW_CTRL_RX)
  1439. miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  1440. else
  1441. miireg = 0;
  1442. return miireg;
  1443. }
  1444. static u8 tg3_resolve_flowctrl_1000T(u16 lcladv, u16 rmtadv)
  1445. {
  1446. u8 cap = 0;
  1447. if (lcladv & ADVERTISE_PAUSE_CAP) {
  1448. if (lcladv & ADVERTISE_PAUSE_ASYM) {
  1449. if (rmtadv & LPA_PAUSE_CAP)
  1450. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1451. else if (rmtadv & LPA_PAUSE_ASYM)
  1452. cap = TG3_FLOW_CTRL_RX;
  1453. } else {
  1454. if (rmtadv & LPA_PAUSE_CAP)
  1455. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1456. }
  1457. } else if (lcladv & ADVERTISE_PAUSE_ASYM) {
  1458. if ((rmtadv & LPA_PAUSE_CAP) && (rmtadv & LPA_PAUSE_ASYM))
  1459. cap = TG3_FLOW_CTRL_TX;
  1460. }
  1461. return cap;
  1462. }
  1463. static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv)
  1464. {
  1465. u8 cap = 0;
  1466. if (lcladv & ADVERTISE_1000XPAUSE) {
  1467. if (lcladv & ADVERTISE_1000XPSE_ASYM) {
  1468. if (rmtadv & LPA_1000XPAUSE)
  1469. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1470. else if (rmtadv & LPA_1000XPAUSE_ASYM)
  1471. cap = TG3_FLOW_CTRL_RX;
  1472. } else {
  1473. if (rmtadv & LPA_1000XPAUSE)
  1474. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  1475. }
  1476. } else if (lcladv & ADVERTISE_1000XPSE_ASYM) {
  1477. if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM))
  1478. cap = TG3_FLOW_CTRL_TX;
  1479. }
  1480. return cap;
  1481. }
  1482. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1483. {
  1484. u8 new_tg3_flags = 0;
  1485. u32 old_rx_mode = tp->rx_mode;
  1486. u32 old_tx_mode = tp->tx_mode;
  1487. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  1488. (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) {
  1489. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  1490. new_tg3_flags = tg3_resolve_flowctrl_1000X(local_adv,
  1491. remote_adv);
  1492. else
  1493. new_tg3_flags = tg3_resolve_flowctrl_1000T(local_adv,
  1494. remote_adv);
  1495. } else {
  1496. new_tg3_flags = tp->link_config.flowctrl;
  1497. }
  1498. tp->link_config.active_flowctrl = new_tg3_flags;
  1499. if (new_tg3_flags & TG3_FLOW_CTRL_RX)
  1500. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1501. else
  1502. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1503. if (old_rx_mode != tp->rx_mode) {
  1504. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1505. }
  1506. if (new_tg3_flags & TG3_FLOW_CTRL_TX)
  1507. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1508. else
  1509. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1510. if (old_tx_mode != tp->tx_mode) {
  1511. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1512. }
  1513. }
  1514. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1515. {
  1516. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1517. case MII_TG3_AUX_STAT_10HALF:
  1518. *speed = SPEED_10;
  1519. *duplex = DUPLEX_HALF;
  1520. break;
  1521. case MII_TG3_AUX_STAT_10FULL:
  1522. *speed = SPEED_10;
  1523. *duplex = DUPLEX_FULL;
  1524. break;
  1525. case MII_TG3_AUX_STAT_100HALF:
  1526. *speed = SPEED_100;
  1527. *duplex = DUPLEX_HALF;
  1528. break;
  1529. case MII_TG3_AUX_STAT_100FULL:
  1530. *speed = SPEED_100;
  1531. *duplex = DUPLEX_FULL;
  1532. break;
  1533. case MII_TG3_AUX_STAT_1000HALF:
  1534. *speed = SPEED_1000;
  1535. *duplex = DUPLEX_HALF;
  1536. break;
  1537. case MII_TG3_AUX_STAT_1000FULL:
  1538. *speed = SPEED_1000;
  1539. *duplex = DUPLEX_FULL;
  1540. break;
  1541. default:
  1542. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1543. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1544. SPEED_10;
  1545. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1546. DUPLEX_HALF;
  1547. break;
  1548. }
  1549. *speed = SPEED_INVALID;
  1550. *duplex = DUPLEX_INVALID;
  1551. break;
  1552. };
  1553. }
  1554. static void tg3_phy_copper_begin(struct tg3 *tp)
  1555. {
  1556. u32 new_adv;
  1557. int i;
  1558. if (tp->link_config.phy_is_low_power) {
  1559. /* Entering low power mode. Disable gigabit and
  1560. * 100baseT advertisements.
  1561. */
  1562. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1563. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1564. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1565. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1566. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1567. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1568. } else if (tp->link_config.speed == SPEED_INVALID) {
  1569. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1570. tp->link_config.advertising &=
  1571. ~(ADVERTISED_1000baseT_Half |
  1572. ADVERTISED_1000baseT_Full);
  1573. new_adv = ADVERTISE_CSMA;
  1574. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1575. new_adv |= ADVERTISE_10HALF;
  1576. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1577. new_adv |= ADVERTISE_10FULL;
  1578. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1579. new_adv |= ADVERTISE_100HALF;
  1580. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1581. new_adv |= ADVERTISE_100FULL;
  1582. new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1583. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1584. if (tp->link_config.advertising &
  1585. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1586. new_adv = 0;
  1587. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1588. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1589. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1590. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1591. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1592. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1593. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1594. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1595. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1596. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1597. } else {
  1598. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1599. }
  1600. } else {
  1601. new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1602. new_adv |= ADVERTISE_CSMA;
  1603. /* Asking for a specific link mode. */
  1604. if (tp->link_config.speed == SPEED_1000) {
  1605. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1606. if (tp->link_config.duplex == DUPLEX_FULL)
  1607. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1608. else
  1609. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1610. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1611. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1612. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1613. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1614. } else {
  1615. if (tp->link_config.speed == SPEED_100) {
  1616. if (tp->link_config.duplex == DUPLEX_FULL)
  1617. new_adv |= ADVERTISE_100FULL;
  1618. else
  1619. new_adv |= ADVERTISE_100HALF;
  1620. } else {
  1621. if (tp->link_config.duplex == DUPLEX_FULL)
  1622. new_adv |= ADVERTISE_10FULL;
  1623. else
  1624. new_adv |= ADVERTISE_10HALF;
  1625. }
  1626. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1627. new_adv = 0;
  1628. }
  1629. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1630. }
  1631. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1632. tp->link_config.speed != SPEED_INVALID) {
  1633. u32 bmcr, orig_bmcr;
  1634. tp->link_config.active_speed = tp->link_config.speed;
  1635. tp->link_config.active_duplex = tp->link_config.duplex;
  1636. bmcr = 0;
  1637. switch (tp->link_config.speed) {
  1638. default:
  1639. case SPEED_10:
  1640. break;
  1641. case SPEED_100:
  1642. bmcr |= BMCR_SPEED100;
  1643. break;
  1644. case SPEED_1000:
  1645. bmcr |= TG3_BMCR_SPEED1000;
  1646. break;
  1647. };
  1648. if (tp->link_config.duplex == DUPLEX_FULL)
  1649. bmcr |= BMCR_FULLDPLX;
  1650. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1651. (bmcr != orig_bmcr)) {
  1652. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1653. for (i = 0; i < 1500; i++) {
  1654. u32 tmp;
  1655. udelay(10);
  1656. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1657. tg3_readphy(tp, MII_BMSR, &tmp))
  1658. continue;
  1659. if (!(tmp & BMSR_LSTATUS)) {
  1660. udelay(40);
  1661. break;
  1662. }
  1663. }
  1664. tg3_writephy(tp, MII_BMCR, bmcr);
  1665. udelay(40);
  1666. }
  1667. } else {
  1668. tg3_writephy(tp, MII_BMCR,
  1669. BMCR_ANENABLE | BMCR_ANRESTART);
  1670. }
  1671. }
  1672. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1673. {
  1674. int err;
  1675. /* Turn off tap power management. */
  1676. /* Set Extended packet length bit */
  1677. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1678. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1679. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1680. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1681. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1682. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1683. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1684. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1685. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1686. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1687. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1688. udelay(40);
  1689. return err;
  1690. }
  1691. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1692. {
  1693. u32 adv_reg, all_mask = 0;
  1694. if (mask & ADVERTISED_10baseT_Half)
  1695. all_mask |= ADVERTISE_10HALF;
  1696. if (mask & ADVERTISED_10baseT_Full)
  1697. all_mask |= ADVERTISE_10FULL;
  1698. if (mask & ADVERTISED_100baseT_Half)
  1699. all_mask |= ADVERTISE_100HALF;
  1700. if (mask & ADVERTISED_100baseT_Full)
  1701. all_mask |= ADVERTISE_100FULL;
  1702. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1703. return 0;
  1704. if ((adv_reg & all_mask) != all_mask)
  1705. return 0;
  1706. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1707. u32 tg3_ctrl;
  1708. all_mask = 0;
  1709. if (mask & ADVERTISED_1000baseT_Half)
  1710. all_mask |= ADVERTISE_1000HALF;
  1711. if (mask & ADVERTISED_1000baseT_Full)
  1712. all_mask |= ADVERTISE_1000FULL;
  1713. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1714. return 0;
  1715. if ((tg3_ctrl & all_mask) != all_mask)
  1716. return 0;
  1717. }
  1718. return 1;
  1719. }
  1720. static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv)
  1721. {
  1722. u32 curadv, reqadv;
  1723. if (tg3_readphy(tp, MII_ADVERTISE, lcladv))
  1724. return 1;
  1725. curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1726. reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1727. if (tp->link_config.active_duplex == DUPLEX_FULL) {
  1728. if (curadv != reqadv)
  1729. return 0;
  1730. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)
  1731. tg3_readphy(tp, MII_LPA, rmtadv);
  1732. } else {
  1733. /* Reprogram the advertisement register, even if it
  1734. * does not affect the current link. If the link
  1735. * gets renegotiated in the future, we can save an
  1736. * additional renegotiation cycle by advertising
  1737. * it correctly in the first place.
  1738. */
  1739. if (curadv != reqadv) {
  1740. *lcladv &= ~(ADVERTISE_PAUSE_CAP |
  1741. ADVERTISE_PAUSE_ASYM);
  1742. tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv);
  1743. }
  1744. }
  1745. return 1;
  1746. }
  1747. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1748. {
  1749. int current_link_up;
  1750. u32 bmsr, dummy;
  1751. u32 lcl_adv, rmt_adv;
  1752. u16 current_speed;
  1753. u8 current_duplex;
  1754. int i, err;
  1755. tw32(MAC_EVENT, 0);
  1756. tw32_f(MAC_STATUS,
  1757. (MAC_STATUS_SYNC_CHANGED |
  1758. MAC_STATUS_CFG_CHANGED |
  1759. MAC_STATUS_MI_COMPLETION |
  1760. MAC_STATUS_LNKSTATE_CHANGED));
  1761. udelay(40);
  1762. tp->mi_mode = MAC_MI_MODE_BASE;
  1763. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1764. udelay(80);
  1765. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1766. /* Some third-party PHYs need to be reset on link going
  1767. * down.
  1768. */
  1769. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1770. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1771. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1772. netif_carrier_ok(tp->dev)) {
  1773. tg3_readphy(tp, MII_BMSR, &bmsr);
  1774. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1775. !(bmsr & BMSR_LSTATUS))
  1776. force_reset = 1;
  1777. }
  1778. if (force_reset)
  1779. tg3_phy_reset(tp);
  1780. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1781. tg3_readphy(tp, MII_BMSR, &bmsr);
  1782. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1783. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1784. bmsr = 0;
  1785. if (!(bmsr & BMSR_LSTATUS)) {
  1786. err = tg3_init_5401phy_dsp(tp);
  1787. if (err)
  1788. return err;
  1789. tg3_readphy(tp, MII_BMSR, &bmsr);
  1790. for (i = 0; i < 1000; i++) {
  1791. udelay(10);
  1792. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1793. (bmsr & BMSR_LSTATUS)) {
  1794. udelay(40);
  1795. break;
  1796. }
  1797. }
  1798. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1799. !(bmsr & BMSR_LSTATUS) &&
  1800. tp->link_config.active_speed == SPEED_1000) {
  1801. err = tg3_phy_reset(tp);
  1802. if (!err)
  1803. err = tg3_init_5401phy_dsp(tp);
  1804. if (err)
  1805. return err;
  1806. }
  1807. }
  1808. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1809. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1810. /* 5701 {A0,B0} CRC bug workaround */
  1811. tg3_writephy(tp, 0x15, 0x0a75);
  1812. tg3_writephy(tp, 0x1c, 0x8c68);
  1813. tg3_writephy(tp, 0x1c, 0x8d68);
  1814. tg3_writephy(tp, 0x1c, 0x8c68);
  1815. }
  1816. /* Clear pending interrupts... */
  1817. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1818. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1819. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1820. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1821. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1822. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1823. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1824. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1825. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1826. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1827. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1828. else
  1829. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1830. }
  1831. current_link_up = 0;
  1832. current_speed = SPEED_INVALID;
  1833. current_duplex = DUPLEX_INVALID;
  1834. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1835. u32 val;
  1836. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1837. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1838. if (!(val & (1 << 10))) {
  1839. val |= (1 << 10);
  1840. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1841. goto relink;
  1842. }
  1843. }
  1844. bmsr = 0;
  1845. for (i = 0; i < 100; i++) {
  1846. tg3_readphy(tp, MII_BMSR, &bmsr);
  1847. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1848. (bmsr & BMSR_LSTATUS))
  1849. break;
  1850. udelay(40);
  1851. }
  1852. if (bmsr & BMSR_LSTATUS) {
  1853. u32 aux_stat, bmcr;
  1854. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1855. for (i = 0; i < 2000; i++) {
  1856. udelay(10);
  1857. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1858. aux_stat)
  1859. break;
  1860. }
  1861. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1862. &current_speed,
  1863. &current_duplex);
  1864. bmcr = 0;
  1865. for (i = 0; i < 200; i++) {
  1866. tg3_readphy(tp, MII_BMCR, &bmcr);
  1867. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1868. continue;
  1869. if (bmcr && bmcr != 0x7fff)
  1870. break;
  1871. udelay(10);
  1872. }
  1873. lcl_adv = 0;
  1874. rmt_adv = 0;
  1875. tp->link_config.active_speed = current_speed;
  1876. tp->link_config.active_duplex = current_duplex;
  1877. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1878. if ((bmcr & BMCR_ANENABLE) &&
  1879. tg3_copper_is_advertising_all(tp,
  1880. tp->link_config.advertising)) {
  1881. if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv,
  1882. &rmt_adv))
  1883. current_link_up = 1;
  1884. }
  1885. } else {
  1886. if (!(bmcr & BMCR_ANENABLE) &&
  1887. tp->link_config.speed == current_speed &&
  1888. tp->link_config.duplex == current_duplex &&
  1889. tp->link_config.flowctrl ==
  1890. tp->link_config.active_flowctrl) {
  1891. current_link_up = 1;
  1892. }
  1893. }
  1894. if (current_link_up == 1 &&
  1895. tp->link_config.active_duplex == DUPLEX_FULL)
  1896. tg3_setup_flow_control(tp, lcl_adv, rmt_adv);
  1897. }
  1898. relink:
  1899. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1900. u32 tmp;
  1901. tg3_phy_copper_begin(tp);
  1902. tg3_readphy(tp, MII_BMSR, &tmp);
  1903. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1904. (tmp & BMSR_LSTATUS))
  1905. current_link_up = 1;
  1906. }
  1907. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1908. if (current_link_up == 1) {
  1909. if (tp->link_config.active_speed == SPEED_100 ||
  1910. tp->link_config.active_speed == SPEED_10)
  1911. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1912. else
  1913. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1914. } else
  1915. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1916. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1917. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1918. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1919. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1920. if (current_link_up == 1 &&
  1921. tg3_5700_link_polarity(tp, tp->link_config.active_speed))
  1922. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1923. else
  1924. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1925. }
  1926. /* ??? Without this setting Netgear GA302T PHY does not
  1927. * ??? send/receive packets...
  1928. */
  1929. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1930. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1931. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1932. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1933. udelay(80);
  1934. }
  1935. tw32_f(MAC_MODE, tp->mac_mode);
  1936. udelay(40);
  1937. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1938. /* Polled via timer. */
  1939. tw32_f(MAC_EVENT, 0);
  1940. } else {
  1941. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1942. }
  1943. udelay(40);
  1944. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1945. current_link_up == 1 &&
  1946. tp->link_config.active_speed == SPEED_1000 &&
  1947. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1948. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1949. udelay(120);
  1950. tw32_f(MAC_STATUS,
  1951. (MAC_STATUS_SYNC_CHANGED |
  1952. MAC_STATUS_CFG_CHANGED));
  1953. udelay(40);
  1954. tg3_write_mem(tp,
  1955. NIC_SRAM_FIRMWARE_MBOX,
  1956. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1957. }
  1958. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1959. if (current_link_up)
  1960. netif_carrier_on(tp->dev);
  1961. else
  1962. netif_carrier_off(tp->dev);
  1963. tg3_link_report(tp);
  1964. }
  1965. return 0;
  1966. }
  1967. struct tg3_fiber_aneginfo {
  1968. int state;
  1969. #define ANEG_STATE_UNKNOWN 0
  1970. #define ANEG_STATE_AN_ENABLE 1
  1971. #define ANEG_STATE_RESTART_INIT 2
  1972. #define ANEG_STATE_RESTART 3
  1973. #define ANEG_STATE_DISABLE_LINK_OK 4
  1974. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1975. #define ANEG_STATE_ABILITY_DETECT 6
  1976. #define ANEG_STATE_ACK_DETECT_INIT 7
  1977. #define ANEG_STATE_ACK_DETECT 8
  1978. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1979. #define ANEG_STATE_COMPLETE_ACK 10
  1980. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1981. #define ANEG_STATE_IDLE_DETECT 12
  1982. #define ANEG_STATE_LINK_OK 13
  1983. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1984. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1985. u32 flags;
  1986. #define MR_AN_ENABLE 0x00000001
  1987. #define MR_RESTART_AN 0x00000002
  1988. #define MR_AN_COMPLETE 0x00000004
  1989. #define MR_PAGE_RX 0x00000008
  1990. #define MR_NP_LOADED 0x00000010
  1991. #define MR_TOGGLE_TX 0x00000020
  1992. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1993. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1994. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1995. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1996. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1997. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1998. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1999. #define MR_TOGGLE_RX 0x00002000
  2000. #define MR_NP_RX 0x00004000
  2001. #define MR_LINK_OK 0x80000000
  2002. unsigned long link_time, cur_time;
  2003. u32 ability_match_cfg;
  2004. int ability_match_count;
  2005. char ability_match, idle_match, ack_match;
  2006. u32 txconfig, rxconfig;
  2007. #define ANEG_CFG_NP 0x00000080
  2008. #define ANEG_CFG_ACK 0x00000040
  2009. #define ANEG_CFG_RF2 0x00000020
  2010. #define ANEG_CFG_RF1 0x00000010
  2011. #define ANEG_CFG_PS2 0x00000001
  2012. #define ANEG_CFG_PS1 0x00008000
  2013. #define ANEG_CFG_HD 0x00004000
  2014. #define ANEG_CFG_FD 0x00002000
  2015. #define ANEG_CFG_INVAL 0x00001f06
  2016. };
  2017. #define ANEG_OK 0
  2018. #define ANEG_DONE 1
  2019. #define ANEG_TIMER_ENAB 2
  2020. #define ANEG_FAILED -1
  2021. #define ANEG_STATE_SETTLE_TIME 10000
  2022. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  2023. struct tg3_fiber_aneginfo *ap)
  2024. {
  2025. u16 flowctrl;
  2026. unsigned long delta;
  2027. u32 rx_cfg_reg;
  2028. int ret;
  2029. if (ap->state == ANEG_STATE_UNKNOWN) {
  2030. ap->rxconfig = 0;
  2031. ap->link_time = 0;
  2032. ap->cur_time = 0;
  2033. ap->ability_match_cfg = 0;
  2034. ap->ability_match_count = 0;
  2035. ap->ability_match = 0;
  2036. ap->idle_match = 0;
  2037. ap->ack_match = 0;
  2038. }
  2039. ap->cur_time++;
  2040. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  2041. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  2042. if (rx_cfg_reg != ap->ability_match_cfg) {
  2043. ap->ability_match_cfg = rx_cfg_reg;
  2044. ap->ability_match = 0;
  2045. ap->ability_match_count = 0;
  2046. } else {
  2047. if (++ap->ability_match_count > 1) {
  2048. ap->ability_match = 1;
  2049. ap->ability_match_cfg = rx_cfg_reg;
  2050. }
  2051. }
  2052. if (rx_cfg_reg & ANEG_CFG_ACK)
  2053. ap->ack_match = 1;
  2054. else
  2055. ap->ack_match = 0;
  2056. ap->idle_match = 0;
  2057. } else {
  2058. ap->idle_match = 1;
  2059. ap->ability_match_cfg = 0;
  2060. ap->ability_match_count = 0;
  2061. ap->ability_match = 0;
  2062. ap->ack_match = 0;
  2063. rx_cfg_reg = 0;
  2064. }
  2065. ap->rxconfig = rx_cfg_reg;
  2066. ret = ANEG_OK;
  2067. switch(ap->state) {
  2068. case ANEG_STATE_UNKNOWN:
  2069. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  2070. ap->state = ANEG_STATE_AN_ENABLE;
  2071. /* fallthru */
  2072. case ANEG_STATE_AN_ENABLE:
  2073. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  2074. if (ap->flags & MR_AN_ENABLE) {
  2075. ap->link_time = 0;
  2076. ap->cur_time = 0;
  2077. ap->ability_match_cfg = 0;
  2078. ap->ability_match_count = 0;
  2079. ap->ability_match = 0;
  2080. ap->idle_match = 0;
  2081. ap->ack_match = 0;
  2082. ap->state = ANEG_STATE_RESTART_INIT;
  2083. } else {
  2084. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  2085. }
  2086. break;
  2087. case ANEG_STATE_RESTART_INIT:
  2088. ap->link_time = ap->cur_time;
  2089. ap->flags &= ~(MR_NP_LOADED);
  2090. ap->txconfig = 0;
  2091. tw32(MAC_TX_AUTO_NEG, 0);
  2092. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2093. tw32_f(MAC_MODE, tp->mac_mode);
  2094. udelay(40);
  2095. ret = ANEG_TIMER_ENAB;
  2096. ap->state = ANEG_STATE_RESTART;
  2097. /* fallthru */
  2098. case ANEG_STATE_RESTART:
  2099. delta = ap->cur_time - ap->link_time;
  2100. if (delta > ANEG_STATE_SETTLE_TIME) {
  2101. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  2102. } else {
  2103. ret = ANEG_TIMER_ENAB;
  2104. }
  2105. break;
  2106. case ANEG_STATE_DISABLE_LINK_OK:
  2107. ret = ANEG_DONE;
  2108. break;
  2109. case ANEG_STATE_ABILITY_DETECT_INIT:
  2110. ap->flags &= ~(MR_TOGGLE_TX);
  2111. ap->txconfig = ANEG_CFG_FD;
  2112. flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2113. if (flowctrl & ADVERTISE_1000XPAUSE)
  2114. ap->txconfig |= ANEG_CFG_PS1;
  2115. if (flowctrl & ADVERTISE_1000XPSE_ASYM)
  2116. ap->txconfig |= ANEG_CFG_PS2;
  2117. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  2118. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2119. tw32_f(MAC_MODE, tp->mac_mode);
  2120. udelay(40);
  2121. ap->state = ANEG_STATE_ABILITY_DETECT;
  2122. break;
  2123. case ANEG_STATE_ABILITY_DETECT:
  2124. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  2125. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  2126. }
  2127. break;
  2128. case ANEG_STATE_ACK_DETECT_INIT:
  2129. ap->txconfig |= ANEG_CFG_ACK;
  2130. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  2131. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2132. tw32_f(MAC_MODE, tp->mac_mode);
  2133. udelay(40);
  2134. ap->state = ANEG_STATE_ACK_DETECT;
  2135. /* fallthru */
  2136. case ANEG_STATE_ACK_DETECT:
  2137. if (ap->ack_match != 0) {
  2138. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  2139. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  2140. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  2141. } else {
  2142. ap->state = ANEG_STATE_AN_ENABLE;
  2143. }
  2144. } else if (ap->ability_match != 0 &&
  2145. ap->rxconfig == 0) {
  2146. ap->state = ANEG_STATE_AN_ENABLE;
  2147. }
  2148. break;
  2149. case ANEG_STATE_COMPLETE_ACK_INIT:
  2150. if (ap->rxconfig & ANEG_CFG_INVAL) {
  2151. ret = ANEG_FAILED;
  2152. break;
  2153. }
  2154. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  2155. MR_LP_ADV_HALF_DUPLEX |
  2156. MR_LP_ADV_SYM_PAUSE |
  2157. MR_LP_ADV_ASYM_PAUSE |
  2158. MR_LP_ADV_REMOTE_FAULT1 |
  2159. MR_LP_ADV_REMOTE_FAULT2 |
  2160. MR_LP_ADV_NEXT_PAGE |
  2161. MR_TOGGLE_RX |
  2162. MR_NP_RX);
  2163. if (ap->rxconfig & ANEG_CFG_FD)
  2164. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  2165. if (ap->rxconfig & ANEG_CFG_HD)
  2166. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  2167. if (ap->rxconfig & ANEG_CFG_PS1)
  2168. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  2169. if (ap->rxconfig & ANEG_CFG_PS2)
  2170. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  2171. if (ap->rxconfig & ANEG_CFG_RF1)
  2172. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  2173. if (ap->rxconfig & ANEG_CFG_RF2)
  2174. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  2175. if (ap->rxconfig & ANEG_CFG_NP)
  2176. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  2177. ap->link_time = ap->cur_time;
  2178. ap->flags ^= (MR_TOGGLE_TX);
  2179. if (ap->rxconfig & 0x0008)
  2180. ap->flags |= MR_TOGGLE_RX;
  2181. if (ap->rxconfig & ANEG_CFG_NP)
  2182. ap->flags |= MR_NP_RX;
  2183. ap->flags |= MR_PAGE_RX;
  2184. ap->state = ANEG_STATE_COMPLETE_ACK;
  2185. ret = ANEG_TIMER_ENAB;
  2186. break;
  2187. case ANEG_STATE_COMPLETE_ACK:
  2188. if (ap->ability_match != 0 &&
  2189. ap->rxconfig == 0) {
  2190. ap->state = ANEG_STATE_AN_ENABLE;
  2191. break;
  2192. }
  2193. delta = ap->cur_time - ap->link_time;
  2194. if (delta > ANEG_STATE_SETTLE_TIME) {
  2195. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  2196. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2197. } else {
  2198. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  2199. !(ap->flags & MR_NP_RX)) {
  2200. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2201. } else {
  2202. ret = ANEG_FAILED;
  2203. }
  2204. }
  2205. }
  2206. break;
  2207. case ANEG_STATE_IDLE_DETECT_INIT:
  2208. ap->link_time = ap->cur_time;
  2209. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2210. tw32_f(MAC_MODE, tp->mac_mode);
  2211. udelay(40);
  2212. ap->state = ANEG_STATE_IDLE_DETECT;
  2213. ret = ANEG_TIMER_ENAB;
  2214. break;
  2215. case ANEG_STATE_IDLE_DETECT:
  2216. if (ap->ability_match != 0 &&
  2217. ap->rxconfig == 0) {
  2218. ap->state = ANEG_STATE_AN_ENABLE;
  2219. break;
  2220. }
  2221. delta = ap->cur_time - ap->link_time;
  2222. if (delta > ANEG_STATE_SETTLE_TIME) {
  2223. /* XXX another gem from the Broadcom driver :( */
  2224. ap->state = ANEG_STATE_LINK_OK;
  2225. }
  2226. break;
  2227. case ANEG_STATE_LINK_OK:
  2228. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  2229. ret = ANEG_DONE;
  2230. break;
  2231. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  2232. /* ??? unimplemented */
  2233. break;
  2234. case ANEG_STATE_NEXT_PAGE_WAIT:
  2235. /* ??? unimplemented */
  2236. break;
  2237. default:
  2238. ret = ANEG_FAILED;
  2239. break;
  2240. };
  2241. return ret;
  2242. }
  2243. static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags)
  2244. {
  2245. int res = 0;
  2246. struct tg3_fiber_aneginfo aninfo;
  2247. int status = ANEG_FAILED;
  2248. unsigned int tick;
  2249. u32 tmp;
  2250. tw32_f(MAC_TX_AUTO_NEG, 0);
  2251. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2252. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2253. udelay(40);
  2254. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2255. udelay(40);
  2256. memset(&aninfo, 0, sizeof(aninfo));
  2257. aninfo.flags |= MR_AN_ENABLE;
  2258. aninfo.state = ANEG_STATE_UNKNOWN;
  2259. aninfo.cur_time = 0;
  2260. tick = 0;
  2261. while (++tick < 195000) {
  2262. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2263. if (status == ANEG_DONE || status == ANEG_FAILED)
  2264. break;
  2265. udelay(1);
  2266. }
  2267. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2268. tw32_f(MAC_MODE, tp->mac_mode);
  2269. udelay(40);
  2270. *txflags = aninfo.txconfig;
  2271. *rxflags = aninfo.flags;
  2272. if (status == ANEG_DONE &&
  2273. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2274. MR_LP_ADV_FULL_DUPLEX)))
  2275. res = 1;
  2276. return res;
  2277. }
  2278. static void tg3_init_bcm8002(struct tg3 *tp)
  2279. {
  2280. u32 mac_status = tr32(MAC_STATUS);
  2281. int i;
  2282. /* Reset when initting first time or we have a link. */
  2283. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2284. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2285. return;
  2286. /* Set PLL lock range. */
  2287. tg3_writephy(tp, 0x16, 0x8007);
  2288. /* SW reset */
  2289. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2290. /* Wait for reset to complete. */
  2291. /* XXX schedule_timeout() ... */
  2292. for (i = 0; i < 500; i++)
  2293. udelay(10);
  2294. /* Config mode; select PMA/Ch 1 regs. */
  2295. tg3_writephy(tp, 0x10, 0x8411);
  2296. /* Enable auto-lock and comdet, select txclk for tx. */
  2297. tg3_writephy(tp, 0x11, 0x0a10);
  2298. tg3_writephy(tp, 0x18, 0x00a0);
  2299. tg3_writephy(tp, 0x16, 0x41ff);
  2300. /* Assert and deassert POR. */
  2301. tg3_writephy(tp, 0x13, 0x0400);
  2302. udelay(40);
  2303. tg3_writephy(tp, 0x13, 0x0000);
  2304. tg3_writephy(tp, 0x11, 0x0a50);
  2305. udelay(40);
  2306. tg3_writephy(tp, 0x11, 0x0a10);
  2307. /* Wait for signal to stabilize */
  2308. /* XXX schedule_timeout() ... */
  2309. for (i = 0; i < 15000; i++)
  2310. udelay(10);
  2311. /* Deselect the channel register so we can read the PHYID
  2312. * later.
  2313. */
  2314. tg3_writephy(tp, 0x10, 0x8011);
  2315. }
  2316. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2317. {
  2318. u16 flowctrl;
  2319. u32 sg_dig_ctrl, sg_dig_status;
  2320. u32 serdes_cfg, expected_sg_dig_ctrl;
  2321. int workaround, port_a;
  2322. int current_link_up;
  2323. serdes_cfg = 0;
  2324. expected_sg_dig_ctrl = 0;
  2325. workaround = 0;
  2326. port_a = 1;
  2327. current_link_up = 0;
  2328. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2329. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2330. workaround = 1;
  2331. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2332. port_a = 0;
  2333. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2334. /* preserve bits 20-23 for voltage regulator */
  2335. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2336. }
  2337. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2338. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2339. if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) {
  2340. if (workaround) {
  2341. u32 val = serdes_cfg;
  2342. if (port_a)
  2343. val |= 0xc010000;
  2344. else
  2345. val |= 0x4010000;
  2346. tw32_f(MAC_SERDES_CFG, val);
  2347. }
  2348. tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
  2349. }
  2350. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2351. tg3_setup_flow_control(tp, 0, 0);
  2352. current_link_up = 1;
  2353. }
  2354. goto out;
  2355. }
  2356. /* Want auto-negotiation. */
  2357. expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP;
  2358. flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2359. if (flowctrl & ADVERTISE_1000XPAUSE)
  2360. expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP;
  2361. if (flowctrl & ADVERTISE_1000XPSE_ASYM)
  2362. expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE;
  2363. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2364. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2365. tp->serdes_counter &&
  2366. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2367. MAC_STATUS_RCVD_CFG)) ==
  2368. MAC_STATUS_PCS_SYNCED)) {
  2369. tp->serdes_counter--;
  2370. current_link_up = 1;
  2371. goto out;
  2372. }
  2373. restart_autoneg:
  2374. if (workaround)
  2375. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2376. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET);
  2377. udelay(5);
  2378. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2379. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2380. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2381. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2382. MAC_STATUS_SIGNAL_DET)) {
  2383. sg_dig_status = tr32(SG_DIG_STATUS);
  2384. mac_status = tr32(MAC_STATUS);
  2385. if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) &&
  2386. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2387. u32 local_adv = 0, remote_adv = 0;
  2388. if (sg_dig_ctrl & SG_DIG_PAUSE_CAP)
  2389. local_adv |= ADVERTISE_1000XPAUSE;
  2390. if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE)
  2391. local_adv |= ADVERTISE_1000XPSE_ASYM;
  2392. if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE)
  2393. remote_adv |= LPA_1000XPAUSE;
  2394. if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE)
  2395. remote_adv |= LPA_1000XPAUSE_ASYM;
  2396. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2397. current_link_up = 1;
  2398. tp->serdes_counter = 0;
  2399. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2400. } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) {
  2401. if (tp->serdes_counter)
  2402. tp->serdes_counter--;
  2403. else {
  2404. if (workaround) {
  2405. u32 val = serdes_cfg;
  2406. if (port_a)
  2407. val |= 0xc010000;
  2408. else
  2409. val |= 0x4010000;
  2410. tw32_f(MAC_SERDES_CFG, val);
  2411. }
  2412. tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
  2413. udelay(40);
  2414. /* Link parallel detection - link is up */
  2415. /* only if we have PCS_SYNC and not */
  2416. /* receiving config code words */
  2417. mac_status = tr32(MAC_STATUS);
  2418. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2419. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2420. tg3_setup_flow_control(tp, 0, 0);
  2421. current_link_up = 1;
  2422. tp->tg3_flags2 |=
  2423. TG3_FLG2_PARALLEL_DETECT;
  2424. tp->serdes_counter =
  2425. SERDES_PARALLEL_DET_TIMEOUT;
  2426. } else
  2427. goto restart_autoneg;
  2428. }
  2429. }
  2430. } else {
  2431. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2432. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2433. }
  2434. out:
  2435. return current_link_up;
  2436. }
  2437. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2438. {
  2439. int current_link_up = 0;
  2440. if (!(mac_status & MAC_STATUS_PCS_SYNCED))
  2441. goto out;
  2442. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2443. u32 txflags, rxflags;
  2444. int i;
  2445. if (fiber_autoneg(tp, &txflags, &rxflags)) {
  2446. u32 local_adv = 0, remote_adv = 0;
  2447. if (txflags & ANEG_CFG_PS1)
  2448. local_adv |= ADVERTISE_1000XPAUSE;
  2449. if (txflags & ANEG_CFG_PS2)
  2450. local_adv |= ADVERTISE_1000XPSE_ASYM;
  2451. if (rxflags & MR_LP_ADV_SYM_PAUSE)
  2452. remote_adv |= LPA_1000XPAUSE;
  2453. if (rxflags & MR_LP_ADV_ASYM_PAUSE)
  2454. remote_adv |= LPA_1000XPAUSE_ASYM;
  2455. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2456. current_link_up = 1;
  2457. }
  2458. for (i = 0; i < 30; i++) {
  2459. udelay(20);
  2460. tw32_f(MAC_STATUS,
  2461. (MAC_STATUS_SYNC_CHANGED |
  2462. MAC_STATUS_CFG_CHANGED));
  2463. udelay(40);
  2464. if ((tr32(MAC_STATUS) &
  2465. (MAC_STATUS_SYNC_CHANGED |
  2466. MAC_STATUS_CFG_CHANGED)) == 0)
  2467. break;
  2468. }
  2469. mac_status = tr32(MAC_STATUS);
  2470. if (current_link_up == 0 &&
  2471. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2472. !(mac_status & MAC_STATUS_RCVD_CFG))
  2473. current_link_up = 1;
  2474. } else {
  2475. tg3_setup_flow_control(tp, 0, 0);
  2476. /* Forcing 1000FD link up. */
  2477. current_link_up = 1;
  2478. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2479. udelay(40);
  2480. tw32_f(MAC_MODE, tp->mac_mode);
  2481. udelay(40);
  2482. }
  2483. out:
  2484. return current_link_up;
  2485. }
  2486. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2487. {
  2488. u32 orig_pause_cfg;
  2489. u16 orig_active_speed;
  2490. u8 orig_active_duplex;
  2491. u32 mac_status;
  2492. int current_link_up;
  2493. int i;
  2494. orig_pause_cfg = tp->link_config.active_flowctrl;
  2495. orig_active_speed = tp->link_config.active_speed;
  2496. orig_active_duplex = tp->link_config.active_duplex;
  2497. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2498. netif_carrier_ok(tp->dev) &&
  2499. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2500. mac_status = tr32(MAC_STATUS);
  2501. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2502. MAC_STATUS_SIGNAL_DET |
  2503. MAC_STATUS_CFG_CHANGED |
  2504. MAC_STATUS_RCVD_CFG);
  2505. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2506. MAC_STATUS_SIGNAL_DET)) {
  2507. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2508. MAC_STATUS_CFG_CHANGED));
  2509. return 0;
  2510. }
  2511. }
  2512. tw32_f(MAC_TX_AUTO_NEG, 0);
  2513. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2514. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2515. tw32_f(MAC_MODE, tp->mac_mode);
  2516. udelay(40);
  2517. if (tp->phy_id == PHY_ID_BCM8002)
  2518. tg3_init_bcm8002(tp);
  2519. /* Enable link change event even when serdes polling. */
  2520. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2521. udelay(40);
  2522. current_link_up = 0;
  2523. mac_status = tr32(MAC_STATUS);
  2524. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2525. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2526. else
  2527. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2528. tp->hw_status->status =
  2529. (SD_STATUS_UPDATED |
  2530. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2531. for (i = 0; i < 100; i++) {
  2532. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2533. MAC_STATUS_CFG_CHANGED));
  2534. udelay(5);
  2535. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2536. MAC_STATUS_CFG_CHANGED |
  2537. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2538. break;
  2539. }
  2540. mac_status = tr32(MAC_STATUS);
  2541. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2542. current_link_up = 0;
  2543. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2544. tp->serdes_counter == 0) {
  2545. tw32_f(MAC_MODE, (tp->mac_mode |
  2546. MAC_MODE_SEND_CONFIGS));
  2547. udelay(1);
  2548. tw32_f(MAC_MODE, tp->mac_mode);
  2549. }
  2550. }
  2551. if (current_link_up == 1) {
  2552. tp->link_config.active_speed = SPEED_1000;
  2553. tp->link_config.active_duplex = DUPLEX_FULL;
  2554. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2555. LED_CTRL_LNKLED_OVERRIDE |
  2556. LED_CTRL_1000MBPS_ON));
  2557. } else {
  2558. tp->link_config.active_speed = SPEED_INVALID;
  2559. tp->link_config.active_duplex = DUPLEX_INVALID;
  2560. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2561. LED_CTRL_LNKLED_OVERRIDE |
  2562. LED_CTRL_TRAFFIC_OVERRIDE));
  2563. }
  2564. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2565. if (current_link_up)
  2566. netif_carrier_on(tp->dev);
  2567. else
  2568. netif_carrier_off(tp->dev);
  2569. tg3_link_report(tp);
  2570. } else {
  2571. u32 now_pause_cfg = tp->link_config.active_flowctrl;
  2572. if (orig_pause_cfg != now_pause_cfg ||
  2573. orig_active_speed != tp->link_config.active_speed ||
  2574. orig_active_duplex != tp->link_config.active_duplex)
  2575. tg3_link_report(tp);
  2576. }
  2577. return 0;
  2578. }
  2579. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2580. {
  2581. int current_link_up, err = 0;
  2582. u32 bmsr, bmcr;
  2583. u16 current_speed;
  2584. u8 current_duplex;
  2585. u32 local_adv, remote_adv;
  2586. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2587. tw32_f(MAC_MODE, tp->mac_mode);
  2588. udelay(40);
  2589. tw32(MAC_EVENT, 0);
  2590. tw32_f(MAC_STATUS,
  2591. (MAC_STATUS_SYNC_CHANGED |
  2592. MAC_STATUS_CFG_CHANGED |
  2593. MAC_STATUS_MI_COMPLETION |
  2594. MAC_STATUS_LNKSTATE_CHANGED));
  2595. udelay(40);
  2596. if (force_reset)
  2597. tg3_phy_reset(tp);
  2598. current_link_up = 0;
  2599. current_speed = SPEED_INVALID;
  2600. current_duplex = DUPLEX_INVALID;
  2601. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2602. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2603. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2604. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2605. bmsr |= BMSR_LSTATUS;
  2606. else
  2607. bmsr &= ~BMSR_LSTATUS;
  2608. }
  2609. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2610. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2611. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2612. tp->link_config.flowctrl == tp->link_config.active_flowctrl) {
  2613. /* do nothing, just check for link up at the end */
  2614. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2615. u32 adv, new_adv;
  2616. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2617. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2618. ADVERTISE_1000XPAUSE |
  2619. ADVERTISE_1000XPSE_ASYM |
  2620. ADVERTISE_SLCT);
  2621. new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2622. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2623. new_adv |= ADVERTISE_1000XHALF;
  2624. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2625. new_adv |= ADVERTISE_1000XFULL;
  2626. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2627. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2628. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2629. tg3_writephy(tp, MII_BMCR, bmcr);
  2630. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2631. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2632. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2633. return err;
  2634. }
  2635. } else {
  2636. u32 new_bmcr;
  2637. bmcr &= ~BMCR_SPEED1000;
  2638. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2639. if (tp->link_config.duplex == DUPLEX_FULL)
  2640. new_bmcr |= BMCR_FULLDPLX;
  2641. if (new_bmcr != bmcr) {
  2642. /* BMCR_SPEED1000 is a reserved bit that needs
  2643. * to be set on write.
  2644. */
  2645. new_bmcr |= BMCR_SPEED1000;
  2646. /* Force a linkdown */
  2647. if (netif_carrier_ok(tp->dev)) {
  2648. u32 adv;
  2649. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2650. adv &= ~(ADVERTISE_1000XFULL |
  2651. ADVERTISE_1000XHALF |
  2652. ADVERTISE_SLCT);
  2653. tg3_writephy(tp, MII_ADVERTISE, adv);
  2654. tg3_writephy(tp, MII_BMCR, bmcr |
  2655. BMCR_ANRESTART |
  2656. BMCR_ANENABLE);
  2657. udelay(10);
  2658. netif_carrier_off(tp->dev);
  2659. }
  2660. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2661. bmcr = new_bmcr;
  2662. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2663. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2664. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2665. ASIC_REV_5714) {
  2666. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2667. bmsr |= BMSR_LSTATUS;
  2668. else
  2669. bmsr &= ~BMSR_LSTATUS;
  2670. }
  2671. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2672. }
  2673. }
  2674. if (bmsr & BMSR_LSTATUS) {
  2675. current_speed = SPEED_1000;
  2676. current_link_up = 1;
  2677. if (bmcr & BMCR_FULLDPLX)
  2678. current_duplex = DUPLEX_FULL;
  2679. else
  2680. current_duplex = DUPLEX_HALF;
  2681. local_adv = 0;
  2682. remote_adv = 0;
  2683. if (bmcr & BMCR_ANENABLE) {
  2684. u32 common;
  2685. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2686. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2687. common = local_adv & remote_adv;
  2688. if (common & (ADVERTISE_1000XHALF |
  2689. ADVERTISE_1000XFULL)) {
  2690. if (common & ADVERTISE_1000XFULL)
  2691. current_duplex = DUPLEX_FULL;
  2692. else
  2693. current_duplex = DUPLEX_HALF;
  2694. }
  2695. else
  2696. current_link_up = 0;
  2697. }
  2698. }
  2699. if (current_link_up == 1 && current_duplex == DUPLEX_FULL)
  2700. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2701. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2702. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2703. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2704. tw32_f(MAC_MODE, tp->mac_mode);
  2705. udelay(40);
  2706. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2707. tp->link_config.active_speed = current_speed;
  2708. tp->link_config.active_duplex = current_duplex;
  2709. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2710. if (current_link_up)
  2711. netif_carrier_on(tp->dev);
  2712. else {
  2713. netif_carrier_off(tp->dev);
  2714. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2715. }
  2716. tg3_link_report(tp);
  2717. }
  2718. return err;
  2719. }
  2720. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2721. {
  2722. if (tp->serdes_counter) {
  2723. /* Give autoneg time to complete. */
  2724. tp->serdes_counter--;
  2725. return;
  2726. }
  2727. if (!netif_carrier_ok(tp->dev) &&
  2728. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2729. u32 bmcr;
  2730. tg3_readphy(tp, MII_BMCR, &bmcr);
  2731. if (bmcr & BMCR_ANENABLE) {
  2732. u32 phy1, phy2;
  2733. /* Select shadow register 0x1f */
  2734. tg3_writephy(tp, 0x1c, 0x7c00);
  2735. tg3_readphy(tp, 0x1c, &phy1);
  2736. /* Select expansion interrupt status register */
  2737. tg3_writephy(tp, 0x17, 0x0f01);
  2738. tg3_readphy(tp, 0x15, &phy2);
  2739. tg3_readphy(tp, 0x15, &phy2);
  2740. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2741. /* We have signal detect and not receiving
  2742. * config code words, link is up by parallel
  2743. * detection.
  2744. */
  2745. bmcr &= ~BMCR_ANENABLE;
  2746. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2747. tg3_writephy(tp, MII_BMCR, bmcr);
  2748. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2749. }
  2750. }
  2751. }
  2752. else if (netif_carrier_ok(tp->dev) &&
  2753. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2754. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2755. u32 phy2;
  2756. /* Select expansion interrupt status register */
  2757. tg3_writephy(tp, 0x17, 0x0f01);
  2758. tg3_readphy(tp, 0x15, &phy2);
  2759. if (phy2 & 0x20) {
  2760. u32 bmcr;
  2761. /* Config code words received, turn on autoneg. */
  2762. tg3_readphy(tp, MII_BMCR, &bmcr);
  2763. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2764. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2765. }
  2766. }
  2767. }
  2768. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2769. {
  2770. int err;
  2771. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2772. err = tg3_setup_fiber_phy(tp, force_reset);
  2773. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2774. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2775. } else {
  2776. err = tg3_setup_copper_phy(tp, force_reset);
  2777. }
  2778. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  2779. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1) {
  2780. u32 val, scale;
  2781. val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK;
  2782. if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5)
  2783. scale = 65;
  2784. else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25)
  2785. scale = 6;
  2786. else
  2787. scale = 12;
  2788. val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK;
  2789. val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT);
  2790. tw32(GRC_MISC_CFG, val);
  2791. }
  2792. if (tp->link_config.active_speed == SPEED_1000 &&
  2793. tp->link_config.active_duplex == DUPLEX_HALF)
  2794. tw32(MAC_TX_LENGTHS,
  2795. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2796. (6 << TX_LENGTHS_IPG_SHIFT) |
  2797. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2798. else
  2799. tw32(MAC_TX_LENGTHS,
  2800. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2801. (6 << TX_LENGTHS_IPG_SHIFT) |
  2802. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2803. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2804. if (netif_carrier_ok(tp->dev)) {
  2805. tw32(HOSTCC_STAT_COAL_TICKS,
  2806. tp->coal.stats_block_coalesce_usecs);
  2807. } else {
  2808. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2809. }
  2810. }
  2811. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) {
  2812. u32 val = tr32(PCIE_PWR_MGMT_THRESH);
  2813. if (!netif_carrier_ok(tp->dev))
  2814. val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) |
  2815. tp->pwrmgmt_thresh;
  2816. else
  2817. val |= PCIE_PWR_MGMT_L1_THRESH_MSK;
  2818. tw32(PCIE_PWR_MGMT_THRESH, val);
  2819. }
  2820. return err;
  2821. }
  2822. /* This is called whenever we suspect that the system chipset is re-
  2823. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2824. * is bogus tx completions. We try to recover by setting the
  2825. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2826. * in the workqueue.
  2827. */
  2828. static void tg3_tx_recover(struct tg3 *tp)
  2829. {
  2830. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2831. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2832. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2833. "mapped I/O cycles to the network device, attempting to "
  2834. "recover. Please report the problem to the driver maintainer "
  2835. "and include system chipset information.\n", tp->dev->name);
  2836. spin_lock(&tp->lock);
  2837. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2838. spin_unlock(&tp->lock);
  2839. }
  2840. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2841. {
  2842. smp_mb();
  2843. return (tp->tx_pending -
  2844. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2845. }
  2846. /* Tigon3 never reports partial packet sends. So we do not
  2847. * need special logic to handle SKBs that have not had all
  2848. * of their frags sent yet, like SunGEM does.
  2849. */
  2850. static void tg3_tx(struct tg3 *tp)
  2851. {
  2852. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2853. u32 sw_idx = tp->tx_cons;
  2854. while (sw_idx != hw_idx) {
  2855. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2856. struct sk_buff *skb = ri->skb;
  2857. int i, tx_bug = 0;
  2858. if (unlikely(skb == NULL)) {
  2859. tg3_tx_recover(tp);
  2860. return;
  2861. }
  2862. pci_unmap_single(tp->pdev,
  2863. pci_unmap_addr(ri, mapping),
  2864. skb_headlen(skb),
  2865. PCI_DMA_TODEVICE);
  2866. ri->skb = NULL;
  2867. sw_idx = NEXT_TX(sw_idx);
  2868. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2869. ri = &tp->tx_buffers[sw_idx];
  2870. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2871. tx_bug = 1;
  2872. pci_unmap_page(tp->pdev,
  2873. pci_unmap_addr(ri, mapping),
  2874. skb_shinfo(skb)->frags[i].size,
  2875. PCI_DMA_TODEVICE);
  2876. sw_idx = NEXT_TX(sw_idx);
  2877. }
  2878. dev_kfree_skb(skb);
  2879. if (unlikely(tx_bug)) {
  2880. tg3_tx_recover(tp);
  2881. return;
  2882. }
  2883. }
  2884. tp->tx_cons = sw_idx;
  2885. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2886. * before checking for netif_queue_stopped(). Without the
  2887. * memory barrier, there is a small possibility that tg3_start_xmit()
  2888. * will miss it and cause the queue to be stopped forever.
  2889. */
  2890. smp_mb();
  2891. if (unlikely(netif_queue_stopped(tp->dev) &&
  2892. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2893. netif_tx_lock(tp->dev);
  2894. if (netif_queue_stopped(tp->dev) &&
  2895. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2896. netif_wake_queue(tp->dev);
  2897. netif_tx_unlock(tp->dev);
  2898. }
  2899. }
  2900. /* Returns size of skb allocated or < 0 on error.
  2901. *
  2902. * We only need to fill in the address because the other members
  2903. * of the RX descriptor are invariant, see tg3_init_rings.
  2904. *
  2905. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2906. * posting buffers we only dirty the first cache line of the RX
  2907. * descriptor (containing the address). Whereas for the RX status
  2908. * buffers the cpu only reads the last cacheline of the RX descriptor
  2909. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2910. */
  2911. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2912. int src_idx, u32 dest_idx_unmasked)
  2913. {
  2914. struct tg3_rx_buffer_desc *desc;
  2915. struct ring_info *map, *src_map;
  2916. struct sk_buff *skb;
  2917. dma_addr_t mapping;
  2918. int skb_size, dest_idx;
  2919. src_map = NULL;
  2920. switch (opaque_key) {
  2921. case RXD_OPAQUE_RING_STD:
  2922. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2923. desc = &tp->rx_std[dest_idx];
  2924. map = &tp->rx_std_buffers[dest_idx];
  2925. if (src_idx >= 0)
  2926. src_map = &tp->rx_std_buffers[src_idx];
  2927. skb_size = tp->rx_pkt_buf_sz;
  2928. break;
  2929. case RXD_OPAQUE_RING_JUMBO:
  2930. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2931. desc = &tp->rx_jumbo[dest_idx];
  2932. map = &tp->rx_jumbo_buffers[dest_idx];
  2933. if (src_idx >= 0)
  2934. src_map = &tp->rx_jumbo_buffers[src_idx];
  2935. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2936. break;
  2937. default:
  2938. return -EINVAL;
  2939. };
  2940. /* Do not overwrite any of the map or rp information
  2941. * until we are sure we can commit to a new buffer.
  2942. *
  2943. * Callers depend upon this behavior and assume that
  2944. * we leave everything unchanged if we fail.
  2945. */
  2946. skb = netdev_alloc_skb(tp->dev, skb_size);
  2947. if (skb == NULL)
  2948. return -ENOMEM;
  2949. skb_reserve(skb, tp->rx_offset);
  2950. mapping = pci_map_single(tp->pdev, skb->data,
  2951. skb_size - tp->rx_offset,
  2952. PCI_DMA_FROMDEVICE);
  2953. map->skb = skb;
  2954. pci_unmap_addr_set(map, mapping, mapping);
  2955. if (src_map != NULL)
  2956. src_map->skb = NULL;
  2957. desc->addr_hi = ((u64)mapping >> 32);
  2958. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2959. return skb_size;
  2960. }
  2961. /* We only need to move over in the address because the other
  2962. * members of the RX descriptor are invariant. See notes above
  2963. * tg3_alloc_rx_skb for full details.
  2964. */
  2965. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2966. int src_idx, u32 dest_idx_unmasked)
  2967. {
  2968. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2969. struct ring_info *src_map, *dest_map;
  2970. int dest_idx;
  2971. switch (opaque_key) {
  2972. case RXD_OPAQUE_RING_STD:
  2973. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2974. dest_desc = &tp->rx_std[dest_idx];
  2975. dest_map = &tp->rx_std_buffers[dest_idx];
  2976. src_desc = &tp->rx_std[src_idx];
  2977. src_map = &tp->rx_std_buffers[src_idx];
  2978. break;
  2979. case RXD_OPAQUE_RING_JUMBO:
  2980. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2981. dest_desc = &tp->rx_jumbo[dest_idx];
  2982. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2983. src_desc = &tp->rx_jumbo[src_idx];
  2984. src_map = &tp->rx_jumbo_buffers[src_idx];
  2985. break;
  2986. default:
  2987. return;
  2988. };
  2989. dest_map->skb = src_map->skb;
  2990. pci_unmap_addr_set(dest_map, mapping,
  2991. pci_unmap_addr(src_map, mapping));
  2992. dest_desc->addr_hi = src_desc->addr_hi;
  2993. dest_desc->addr_lo = src_desc->addr_lo;
  2994. src_map->skb = NULL;
  2995. }
  2996. #if TG3_VLAN_TAG_USED
  2997. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2998. {
  2999. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  3000. }
  3001. #endif
  3002. /* The RX ring scheme is composed of multiple rings which post fresh
  3003. * buffers to the chip, and one special ring the chip uses to report
  3004. * status back to the host.
  3005. *
  3006. * The special ring reports the status of received packets to the
  3007. * host. The chip does not write into the original descriptor the
  3008. * RX buffer was obtained from. The chip simply takes the original
  3009. * descriptor as provided by the host, updates the status and length
  3010. * field, then writes this into the next status ring entry.
  3011. *
  3012. * Each ring the host uses to post buffers to the chip is described
  3013. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  3014. * it is first placed into the on-chip ram. When the packet's length
  3015. * is known, it walks down the TG3_BDINFO entries to select the ring.
  3016. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  3017. * which is within the range of the new packet's length is chosen.
  3018. *
  3019. * The "separate ring for rx status" scheme may sound queer, but it makes
  3020. * sense from a cache coherency perspective. If only the host writes
  3021. * to the buffer post rings, and only the chip writes to the rx status
  3022. * rings, then cache lines never move beyond shared-modified state.
  3023. * If both the host and chip were to write into the same ring, cache line
  3024. * eviction could occur since both entities want it in an exclusive state.
  3025. */
  3026. static int tg3_rx(struct tg3 *tp, int budget)
  3027. {
  3028. u32 work_mask, rx_std_posted = 0;
  3029. u32 sw_idx = tp->rx_rcb_ptr;
  3030. u16 hw_idx;
  3031. int received;
  3032. hw_idx = tp->hw_status->idx[0].rx_producer;
  3033. /*
  3034. * We need to order the read of hw_idx and the read of
  3035. * the opaque cookie.
  3036. */
  3037. rmb();
  3038. work_mask = 0;
  3039. received = 0;
  3040. while (sw_idx != hw_idx && budget > 0) {
  3041. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  3042. unsigned int len;
  3043. struct sk_buff *skb;
  3044. dma_addr_t dma_addr;
  3045. u32 opaque_key, desc_idx, *post_ptr;
  3046. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  3047. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  3048. if (opaque_key == RXD_OPAQUE_RING_STD) {
  3049. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  3050. mapping);
  3051. skb = tp->rx_std_buffers[desc_idx].skb;
  3052. post_ptr = &tp->rx_std_ptr;
  3053. rx_std_posted++;
  3054. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  3055. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  3056. mapping);
  3057. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  3058. post_ptr = &tp->rx_jumbo_ptr;
  3059. }
  3060. else {
  3061. goto next_pkt_nopost;
  3062. }
  3063. work_mask |= opaque_key;
  3064. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  3065. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  3066. drop_it:
  3067. tg3_recycle_rx(tp, opaque_key,
  3068. desc_idx, *post_ptr);
  3069. drop_it_no_recycle:
  3070. /* Other statistics kept track of by card. */
  3071. tp->net_stats.rx_dropped++;
  3072. goto next_pkt;
  3073. }
  3074. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  3075. if (len > RX_COPY_THRESHOLD
  3076. && tp->rx_offset == 2
  3077. /* rx_offset != 2 iff this is a 5701 card running
  3078. * in PCI-X mode [see tg3_get_invariants()] */
  3079. ) {
  3080. int skb_size;
  3081. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  3082. desc_idx, *post_ptr);
  3083. if (skb_size < 0)
  3084. goto drop_it;
  3085. pci_unmap_single(tp->pdev, dma_addr,
  3086. skb_size - tp->rx_offset,
  3087. PCI_DMA_FROMDEVICE);
  3088. skb_put(skb, len);
  3089. } else {
  3090. struct sk_buff *copy_skb;
  3091. tg3_recycle_rx(tp, opaque_key,
  3092. desc_idx, *post_ptr);
  3093. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  3094. if (copy_skb == NULL)
  3095. goto drop_it_no_recycle;
  3096. skb_reserve(copy_skb, 2);
  3097. skb_put(copy_skb, len);
  3098. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  3099. skb_copy_from_linear_data(skb, copy_skb->data, len);
  3100. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  3101. /* We'll reuse the original ring buffer. */
  3102. skb = copy_skb;
  3103. }
  3104. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  3105. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  3106. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  3107. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  3108. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3109. else
  3110. skb->ip_summed = CHECKSUM_NONE;
  3111. skb->protocol = eth_type_trans(skb, tp->dev);
  3112. #if TG3_VLAN_TAG_USED
  3113. if (tp->vlgrp != NULL &&
  3114. desc->type_flags & RXD_FLAG_VLAN) {
  3115. tg3_vlan_rx(tp, skb,
  3116. desc->err_vlan & RXD_VLAN_MASK);
  3117. } else
  3118. #endif
  3119. netif_receive_skb(skb);
  3120. tp->dev->last_rx = jiffies;
  3121. received++;
  3122. budget--;
  3123. next_pkt:
  3124. (*post_ptr)++;
  3125. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  3126. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  3127. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  3128. TG3_64BIT_REG_LOW, idx);
  3129. work_mask &= ~RXD_OPAQUE_RING_STD;
  3130. rx_std_posted = 0;
  3131. }
  3132. next_pkt_nopost:
  3133. sw_idx++;
  3134. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  3135. /* Refresh hw_idx to see if there is new work */
  3136. if (sw_idx == hw_idx) {
  3137. hw_idx = tp->hw_status->idx[0].rx_producer;
  3138. rmb();
  3139. }
  3140. }
  3141. /* ACK the status ring. */
  3142. tp->rx_rcb_ptr = sw_idx;
  3143. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  3144. /* Refill RX ring(s). */
  3145. if (work_mask & RXD_OPAQUE_RING_STD) {
  3146. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  3147. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  3148. sw_idx);
  3149. }
  3150. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  3151. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  3152. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  3153. sw_idx);
  3154. }
  3155. mmiowb();
  3156. return received;
  3157. }
  3158. static int tg3_poll_work(struct tg3 *tp, int work_done, int budget)
  3159. {
  3160. struct tg3_hw_status *sblk = tp->hw_status;
  3161. /* handle link change and other phy events */
  3162. if (!(tp->tg3_flags &
  3163. (TG3_FLAG_USE_LINKCHG_REG |
  3164. TG3_FLAG_POLL_SERDES))) {
  3165. if (sblk->status & SD_STATUS_LINK_CHG) {
  3166. sblk->status = SD_STATUS_UPDATED |
  3167. (sblk->status & ~SD_STATUS_LINK_CHG);
  3168. spin_lock(&tp->lock);
  3169. tg3_setup_phy(tp, 0);
  3170. spin_unlock(&tp->lock);
  3171. }
  3172. }
  3173. /* run TX completion thread */
  3174. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  3175. tg3_tx(tp);
  3176. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
  3177. return work_done;
  3178. }
  3179. /* run RX thread, within the bounds set by NAPI.
  3180. * All RX "locking" is done by ensuring outside
  3181. * code synchronizes with tg3->napi.poll()
  3182. */
  3183. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  3184. work_done += tg3_rx(tp, budget - work_done);
  3185. return work_done;
  3186. }
  3187. static int tg3_poll(struct napi_struct *napi, int budget)
  3188. {
  3189. struct tg3 *tp = container_of(napi, struct tg3, napi);
  3190. int work_done = 0;
  3191. struct tg3_hw_status *sblk = tp->hw_status;
  3192. while (1) {
  3193. work_done = tg3_poll_work(tp, work_done, budget);
  3194. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
  3195. goto tx_recovery;
  3196. if (unlikely(work_done >= budget))
  3197. break;
  3198. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  3199. /* tp->last_tag is used in tg3_restart_ints() below
  3200. * to tell the hw how much work has been processed,
  3201. * so we must read it before checking for more work.
  3202. */
  3203. tp->last_tag = sblk->status_tag;
  3204. rmb();
  3205. } else
  3206. sblk->status &= ~SD_STATUS_UPDATED;
  3207. if (likely(!tg3_has_work(tp))) {
  3208. netif_rx_complete(tp->dev, napi);
  3209. tg3_restart_ints(tp);
  3210. break;
  3211. }
  3212. }
  3213. return work_done;
  3214. tx_recovery:
  3215. /* work_done is guaranteed to be less than budget. */
  3216. netif_rx_complete(tp->dev, napi);
  3217. schedule_work(&tp->reset_task);
  3218. return work_done;
  3219. }
  3220. static void tg3_irq_quiesce(struct tg3 *tp)
  3221. {
  3222. BUG_ON(tp->irq_sync);
  3223. tp->irq_sync = 1;
  3224. smp_mb();
  3225. synchronize_irq(tp->pdev->irq);
  3226. }
  3227. static inline int tg3_irq_sync(struct tg3 *tp)
  3228. {
  3229. return tp->irq_sync;
  3230. }
  3231. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  3232. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  3233. * with as well. Most of the time, this is not necessary except when
  3234. * shutting down the device.
  3235. */
  3236. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  3237. {
  3238. spin_lock_bh(&tp->lock);
  3239. if (irq_sync)
  3240. tg3_irq_quiesce(tp);
  3241. }
  3242. static inline void tg3_full_unlock(struct tg3 *tp)
  3243. {
  3244. spin_unlock_bh(&tp->lock);
  3245. }
  3246. /* One-shot MSI handler - Chip automatically disables interrupt
  3247. * after sending MSI so driver doesn't have to do it.
  3248. */
  3249. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  3250. {
  3251. struct net_device *dev = dev_id;
  3252. struct tg3 *tp = netdev_priv(dev);
  3253. prefetch(tp->hw_status);
  3254. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3255. if (likely(!tg3_irq_sync(tp)))
  3256. netif_rx_schedule(dev, &tp->napi);
  3257. return IRQ_HANDLED;
  3258. }
  3259. /* MSI ISR - No need to check for interrupt sharing and no need to
  3260. * flush status block and interrupt mailbox. PCI ordering rules
  3261. * guarantee that MSI will arrive after the status block.
  3262. */
  3263. static irqreturn_t tg3_msi(int irq, void *dev_id)
  3264. {
  3265. struct net_device *dev = dev_id;
  3266. struct tg3 *tp = netdev_priv(dev);
  3267. prefetch(tp->hw_status);
  3268. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3269. /*
  3270. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3271. * chip-internal interrupt pending events.
  3272. * Writing non-zero to intr-mbox-0 additional tells the
  3273. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3274. * event coalescing.
  3275. */
  3276. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3277. if (likely(!tg3_irq_sync(tp)))
  3278. netif_rx_schedule(dev, &tp->napi);
  3279. return IRQ_RETVAL(1);
  3280. }
  3281. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3282. {
  3283. struct net_device *dev = dev_id;
  3284. struct tg3 *tp = netdev_priv(dev);
  3285. struct tg3_hw_status *sblk = tp->hw_status;
  3286. unsigned int handled = 1;
  3287. /* In INTx mode, it is possible for the interrupt to arrive at
  3288. * the CPU before the status block posted prior to the interrupt.
  3289. * Reading the PCI State register will confirm whether the
  3290. * interrupt is ours and will flush the status block.
  3291. */
  3292. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3293. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3294. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3295. handled = 0;
  3296. goto out;
  3297. }
  3298. }
  3299. /*
  3300. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3301. * chip-internal interrupt pending events.
  3302. * Writing non-zero to intr-mbox-0 additional tells the
  3303. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3304. * event coalescing.
  3305. *
  3306. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3307. * spurious interrupts. The flush impacts performance but
  3308. * excessive spurious interrupts can be worse in some cases.
  3309. */
  3310. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3311. if (tg3_irq_sync(tp))
  3312. goto out;
  3313. sblk->status &= ~SD_STATUS_UPDATED;
  3314. if (likely(tg3_has_work(tp))) {
  3315. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3316. netif_rx_schedule(dev, &tp->napi);
  3317. } else {
  3318. /* No work, shared interrupt perhaps? re-enable
  3319. * interrupts, and flush that PCI write
  3320. */
  3321. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3322. 0x00000000);
  3323. }
  3324. out:
  3325. return IRQ_RETVAL(handled);
  3326. }
  3327. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3328. {
  3329. struct net_device *dev = dev_id;
  3330. struct tg3 *tp = netdev_priv(dev);
  3331. struct tg3_hw_status *sblk = tp->hw_status;
  3332. unsigned int handled = 1;
  3333. /* In INTx mode, it is possible for the interrupt to arrive at
  3334. * the CPU before the status block posted prior to the interrupt.
  3335. * Reading the PCI State register will confirm whether the
  3336. * interrupt is ours and will flush the status block.
  3337. */
  3338. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3339. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3340. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3341. handled = 0;
  3342. goto out;
  3343. }
  3344. }
  3345. /*
  3346. * writing any value to intr-mbox-0 clears PCI INTA# and
  3347. * chip-internal interrupt pending events.
  3348. * writing non-zero to intr-mbox-0 additional tells the
  3349. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3350. * event coalescing.
  3351. *
  3352. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3353. * spurious interrupts. The flush impacts performance but
  3354. * excessive spurious interrupts can be worse in some cases.
  3355. */
  3356. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3357. if (tg3_irq_sync(tp))
  3358. goto out;
  3359. if (netif_rx_schedule_prep(dev, &tp->napi)) {
  3360. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3361. /* Update last_tag to mark that this status has been
  3362. * seen. Because interrupt may be shared, we may be
  3363. * racing with tg3_poll(), so only update last_tag
  3364. * if tg3_poll() is not scheduled.
  3365. */
  3366. tp->last_tag = sblk->status_tag;
  3367. __netif_rx_schedule(dev, &tp->napi);
  3368. }
  3369. out:
  3370. return IRQ_RETVAL(handled);
  3371. }
  3372. /* ISR for interrupt test */
  3373. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3374. {
  3375. struct net_device *dev = dev_id;
  3376. struct tg3 *tp = netdev_priv(dev);
  3377. struct tg3_hw_status *sblk = tp->hw_status;
  3378. if ((sblk->status & SD_STATUS_UPDATED) ||
  3379. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3380. tg3_disable_ints(tp);
  3381. return IRQ_RETVAL(1);
  3382. }
  3383. return IRQ_RETVAL(0);
  3384. }
  3385. static int tg3_init_hw(struct tg3 *, int);
  3386. static int tg3_halt(struct tg3 *, int, int);
  3387. /* Restart hardware after configuration changes, self-test, etc.
  3388. * Invoked with tp->lock held.
  3389. */
  3390. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3391. __releases(tp->lock)
  3392. __acquires(tp->lock)
  3393. {
  3394. int err;
  3395. err = tg3_init_hw(tp, reset_phy);
  3396. if (err) {
  3397. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3398. "aborting.\n", tp->dev->name);
  3399. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3400. tg3_full_unlock(tp);
  3401. del_timer_sync(&tp->timer);
  3402. tp->irq_sync = 0;
  3403. napi_enable(&tp->napi);
  3404. dev_close(tp->dev);
  3405. tg3_full_lock(tp, 0);
  3406. }
  3407. return err;
  3408. }
  3409. #ifdef CONFIG_NET_POLL_CONTROLLER
  3410. static void tg3_poll_controller(struct net_device *dev)
  3411. {
  3412. struct tg3 *tp = netdev_priv(dev);
  3413. tg3_interrupt(tp->pdev->irq, dev);
  3414. }
  3415. #endif
  3416. static void tg3_reset_task(struct work_struct *work)
  3417. {
  3418. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3419. unsigned int restart_timer;
  3420. tg3_full_lock(tp, 0);
  3421. if (!netif_running(tp->dev)) {
  3422. tg3_full_unlock(tp);
  3423. return;
  3424. }
  3425. tg3_full_unlock(tp);
  3426. tg3_netif_stop(tp);
  3427. tg3_full_lock(tp, 1);
  3428. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3429. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3430. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3431. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3432. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3433. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3434. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3435. }
  3436. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3437. if (tg3_init_hw(tp, 1))
  3438. goto out;
  3439. tg3_netif_start(tp);
  3440. if (restart_timer)
  3441. mod_timer(&tp->timer, jiffies + 1);
  3442. out:
  3443. tg3_full_unlock(tp);
  3444. }
  3445. static void tg3_dump_short_state(struct tg3 *tp)
  3446. {
  3447. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3448. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3449. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3450. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3451. }
  3452. static void tg3_tx_timeout(struct net_device *dev)
  3453. {
  3454. struct tg3 *tp = netdev_priv(dev);
  3455. if (netif_msg_tx_err(tp)) {
  3456. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3457. dev->name);
  3458. tg3_dump_short_state(tp);
  3459. }
  3460. schedule_work(&tp->reset_task);
  3461. }
  3462. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3463. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3464. {
  3465. u32 base = (u32) mapping & 0xffffffff;
  3466. return ((base > 0xffffdcc0) &&
  3467. (base + len + 8 < base));
  3468. }
  3469. /* Test for DMA addresses > 40-bit */
  3470. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3471. int len)
  3472. {
  3473. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3474. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3475. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3476. return 0;
  3477. #else
  3478. return 0;
  3479. #endif
  3480. }
  3481. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3482. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3483. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3484. u32 last_plus_one, u32 *start,
  3485. u32 base_flags, u32 mss)
  3486. {
  3487. struct sk_buff *new_skb;
  3488. dma_addr_t new_addr = 0;
  3489. u32 entry = *start;
  3490. int i, ret = 0;
  3491. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  3492. new_skb = skb_copy(skb, GFP_ATOMIC);
  3493. else {
  3494. int more_headroom = 4 - ((unsigned long)skb->data & 3);
  3495. new_skb = skb_copy_expand(skb,
  3496. skb_headroom(skb) + more_headroom,
  3497. skb_tailroom(skb), GFP_ATOMIC);
  3498. }
  3499. if (!new_skb) {
  3500. ret = -1;
  3501. } else {
  3502. /* New SKB is guaranteed to be linear. */
  3503. entry = *start;
  3504. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3505. PCI_DMA_TODEVICE);
  3506. /* Make sure new skb does not cross any 4G boundaries.
  3507. * Drop the packet if it does.
  3508. */
  3509. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3510. ret = -1;
  3511. dev_kfree_skb(new_skb);
  3512. new_skb = NULL;
  3513. } else {
  3514. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3515. base_flags, 1 | (mss << 1));
  3516. *start = NEXT_TX(entry);
  3517. }
  3518. }
  3519. /* Now clean up the sw ring entries. */
  3520. i = 0;
  3521. while (entry != last_plus_one) {
  3522. int len;
  3523. if (i == 0)
  3524. len = skb_headlen(skb);
  3525. else
  3526. len = skb_shinfo(skb)->frags[i-1].size;
  3527. pci_unmap_single(tp->pdev,
  3528. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3529. len, PCI_DMA_TODEVICE);
  3530. if (i == 0) {
  3531. tp->tx_buffers[entry].skb = new_skb;
  3532. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3533. } else {
  3534. tp->tx_buffers[entry].skb = NULL;
  3535. }
  3536. entry = NEXT_TX(entry);
  3537. i++;
  3538. }
  3539. dev_kfree_skb(skb);
  3540. return ret;
  3541. }
  3542. static void tg3_set_txd(struct tg3 *tp, int entry,
  3543. dma_addr_t mapping, int len, u32 flags,
  3544. u32 mss_and_is_end)
  3545. {
  3546. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3547. int is_end = (mss_and_is_end & 0x1);
  3548. u32 mss = (mss_and_is_end >> 1);
  3549. u32 vlan_tag = 0;
  3550. if (is_end)
  3551. flags |= TXD_FLAG_END;
  3552. if (flags & TXD_FLAG_VLAN) {
  3553. vlan_tag = flags >> 16;
  3554. flags &= 0xffff;
  3555. }
  3556. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3557. txd->addr_hi = ((u64) mapping >> 32);
  3558. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3559. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3560. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3561. }
  3562. /* hard_start_xmit for devices that don't have any bugs and
  3563. * support TG3_FLG2_HW_TSO_2 only.
  3564. */
  3565. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3566. {
  3567. struct tg3 *tp = netdev_priv(dev);
  3568. dma_addr_t mapping;
  3569. u32 len, entry, base_flags, mss;
  3570. len = skb_headlen(skb);
  3571. /* We are running in BH disabled context with netif_tx_lock
  3572. * and TX reclaim runs via tp->napi.poll inside of a software
  3573. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3574. * no IRQ context deadlocks to worry about either. Rejoice!
  3575. */
  3576. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3577. if (!netif_queue_stopped(dev)) {
  3578. netif_stop_queue(dev);
  3579. /* This is a hard error, log it. */
  3580. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3581. "queue awake!\n", dev->name);
  3582. }
  3583. return NETDEV_TX_BUSY;
  3584. }
  3585. entry = tp->tx_prod;
  3586. base_flags = 0;
  3587. mss = 0;
  3588. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3589. int tcp_opt_len, ip_tcp_len;
  3590. if (skb_header_cloned(skb) &&
  3591. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3592. dev_kfree_skb(skb);
  3593. goto out_unlock;
  3594. }
  3595. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3596. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3597. else {
  3598. struct iphdr *iph = ip_hdr(skb);
  3599. tcp_opt_len = tcp_optlen(skb);
  3600. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3601. iph->check = 0;
  3602. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3603. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3604. }
  3605. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3606. TXD_FLAG_CPU_POST_DMA);
  3607. tcp_hdr(skb)->check = 0;
  3608. }
  3609. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3610. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3611. #if TG3_VLAN_TAG_USED
  3612. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3613. base_flags |= (TXD_FLAG_VLAN |
  3614. (vlan_tx_tag_get(skb) << 16));
  3615. #endif
  3616. /* Queue skb data, a.k.a. the main skb fragment. */
  3617. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3618. tp->tx_buffers[entry].skb = skb;
  3619. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3620. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3621. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3622. entry = NEXT_TX(entry);
  3623. /* Now loop through additional data fragments, and queue them. */
  3624. if (skb_shinfo(skb)->nr_frags > 0) {
  3625. unsigned int i, last;
  3626. last = skb_shinfo(skb)->nr_frags - 1;
  3627. for (i = 0; i <= last; i++) {
  3628. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3629. len = frag->size;
  3630. mapping = pci_map_page(tp->pdev,
  3631. frag->page,
  3632. frag->page_offset,
  3633. len, PCI_DMA_TODEVICE);
  3634. tp->tx_buffers[entry].skb = NULL;
  3635. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3636. tg3_set_txd(tp, entry, mapping, len,
  3637. base_flags, (i == last) | (mss << 1));
  3638. entry = NEXT_TX(entry);
  3639. }
  3640. }
  3641. /* Packets are ready, update Tx producer idx local and on card. */
  3642. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3643. tp->tx_prod = entry;
  3644. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3645. netif_stop_queue(dev);
  3646. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3647. netif_wake_queue(tp->dev);
  3648. }
  3649. out_unlock:
  3650. mmiowb();
  3651. dev->trans_start = jiffies;
  3652. return NETDEV_TX_OK;
  3653. }
  3654. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3655. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3656. * TSO header is greater than 80 bytes.
  3657. */
  3658. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3659. {
  3660. struct sk_buff *segs, *nskb;
  3661. /* Estimate the number of fragments in the worst case */
  3662. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3663. netif_stop_queue(tp->dev);
  3664. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3665. return NETDEV_TX_BUSY;
  3666. netif_wake_queue(tp->dev);
  3667. }
  3668. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3669. if (IS_ERR(segs))
  3670. goto tg3_tso_bug_end;
  3671. do {
  3672. nskb = segs;
  3673. segs = segs->next;
  3674. nskb->next = NULL;
  3675. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3676. } while (segs);
  3677. tg3_tso_bug_end:
  3678. dev_kfree_skb(skb);
  3679. return NETDEV_TX_OK;
  3680. }
  3681. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3682. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3683. */
  3684. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3685. {
  3686. struct tg3 *tp = netdev_priv(dev);
  3687. dma_addr_t mapping;
  3688. u32 len, entry, base_flags, mss;
  3689. int would_hit_hwbug;
  3690. len = skb_headlen(skb);
  3691. /* We are running in BH disabled context with netif_tx_lock
  3692. * and TX reclaim runs via tp->napi.poll inside of a software
  3693. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3694. * no IRQ context deadlocks to worry about either. Rejoice!
  3695. */
  3696. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3697. if (!netif_queue_stopped(dev)) {
  3698. netif_stop_queue(dev);
  3699. /* This is a hard error, log it. */
  3700. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3701. "queue awake!\n", dev->name);
  3702. }
  3703. return NETDEV_TX_BUSY;
  3704. }
  3705. entry = tp->tx_prod;
  3706. base_flags = 0;
  3707. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3708. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3709. mss = 0;
  3710. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3711. struct iphdr *iph;
  3712. int tcp_opt_len, ip_tcp_len, hdr_len;
  3713. if (skb_header_cloned(skb) &&
  3714. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3715. dev_kfree_skb(skb);
  3716. goto out_unlock;
  3717. }
  3718. tcp_opt_len = tcp_optlen(skb);
  3719. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3720. hdr_len = ip_tcp_len + tcp_opt_len;
  3721. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3722. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3723. return (tg3_tso_bug(tp, skb));
  3724. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3725. TXD_FLAG_CPU_POST_DMA);
  3726. iph = ip_hdr(skb);
  3727. iph->check = 0;
  3728. iph->tot_len = htons(mss + hdr_len);
  3729. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3730. tcp_hdr(skb)->check = 0;
  3731. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3732. } else
  3733. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3734. iph->daddr, 0,
  3735. IPPROTO_TCP,
  3736. 0);
  3737. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3738. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3739. if (tcp_opt_len || iph->ihl > 5) {
  3740. int tsflags;
  3741. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3742. mss |= (tsflags << 11);
  3743. }
  3744. } else {
  3745. if (tcp_opt_len || iph->ihl > 5) {
  3746. int tsflags;
  3747. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3748. base_flags |= tsflags << 12;
  3749. }
  3750. }
  3751. }
  3752. #if TG3_VLAN_TAG_USED
  3753. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3754. base_flags |= (TXD_FLAG_VLAN |
  3755. (vlan_tx_tag_get(skb) << 16));
  3756. #endif
  3757. /* Queue skb data, a.k.a. the main skb fragment. */
  3758. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3759. tp->tx_buffers[entry].skb = skb;
  3760. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3761. would_hit_hwbug = 0;
  3762. if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG)
  3763. would_hit_hwbug = 1;
  3764. else if (tg3_4g_overflow_test(mapping, len))
  3765. would_hit_hwbug = 1;
  3766. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3767. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3768. entry = NEXT_TX(entry);
  3769. /* Now loop through additional data fragments, and queue them. */
  3770. if (skb_shinfo(skb)->nr_frags > 0) {
  3771. unsigned int i, last;
  3772. last = skb_shinfo(skb)->nr_frags - 1;
  3773. for (i = 0; i <= last; i++) {
  3774. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3775. len = frag->size;
  3776. mapping = pci_map_page(tp->pdev,
  3777. frag->page,
  3778. frag->page_offset,
  3779. len, PCI_DMA_TODEVICE);
  3780. tp->tx_buffers[entry].skb = NULL;
  3781. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3782. if (tg3_4g_overflow_test(mapping, len))
  3783. would_hit_hwbug = 1;
  3784. if (tg3_40bit_overflow_test(tp, mapping, len))
  3785. would_hit_hwbug = 1;
  3786. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3787. tg3_set_txd(tp, entry, mapping, len,
  3788. base_flags, (i == last)|(mss << 1));
  3789. else
  3790. tg3_set_txd(tp, entry, mapping, len,
  3791. base_flags, (i == last));
  3792. entry = NEXT_TX(entry);
  3793. }
  3794. }
  3795. if (would_hit_hwbug) {
  3796. u32 last_plus_one = entry;
  3797. u32 start;
  3798. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3799. start &= (TG3_TX_RING_SIZE - 1);
  3800. /* If the workaround fails due to memory/mapping
  3801. * failure, silently drop this packet.
  3802. */
  3803. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3804. &start, base_flags, mss))
  3805. goto out_unlock;
  3806. entry = start;
  3807. }
  3808. /* Packets are ready, update Tx producer idx local and on card. */
  3809. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3810. tp->tx_prod = entry;
  3811. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3812. netif_stop_queue(dev);
  3813. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3814. netif_wake_queue(tp->dev);
  3815. }
  3816. out_unlock:
  3817. mmiowb();
  3818. dev->trans_start = jiffies;
  3819. return NETDEV_TX_OK;
  3820. }
  3821. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3822. int new_mtu)
  3823. {
  3824. dev->mtu = new_mtu;
  3825. if (new_mtu > ETH_DATA_LEN) {
  3826. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3827. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3828. ethtool_op_set_tso(dev, 0);
  3829. }
  3830. else
  3831. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3832. } else {
  3833. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3834. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3835. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3836. }
  3837. }
  3838. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3839. {
  3840. struct tg3 *tp = netdev_priv(dev);
  3841. int err;
  3842. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3843. return -EINVAL;
  3844. if (!netif_running(dev)) {
  3845. /* We'll just catch it later when the
  3846. * device is up'd.
  3847. */
  3848. tg3_set_mtu(dev, tp, new_mtu);
  3849. return 0;
  3850. }
  3851. tg3_netif_stop(tp);
  3852. tg3_full_lock(tp, 1);
  3853. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3854. tg3_set_mtu(dev, tp, new_mtu);
  3855. err = tg3_restart_hw(tp, 0);
  3856. if (!err)
  3857. tg3_netif_start(tp);
  3858. tg3_full_unlock(tp);
  3859. return err;
  3860. }
  3861. /* Free up pending packets in all rx/tx rings.
  3862. *
  3863. * The chip has been shut down and the driver detached from
  3864. * the networking, so no interrupts or new tx packets will
  3865. * end up in the driver. tp->{tx,}lock is not held and we are not
  3866. * in an interrupt context and thus may sleep.
  3867. */
  3868. static void tg3_free_rings(struct tg3 *tp)
  3869. {
  3870. struct ring_info *rxp;
  3871. int i;
  3872. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3873. rxp = &tp->rx_std_buffers[i];
  3874. if (rxp->skb == NULL)
  3875. continue;
  3876. pci_unmap_single(tp->pdev,
  3877. pci_unmap_addr(rxp, mapping),
  3878. tp->rx_pkt_buf_sz - tp->rx_offset,
  3879. PCI_DMA_FROMDEVICE);
  3880. dev_kfree_skb_any(rxp->skb);
  3881. rxp->skb = NULL;
  3882. }
  3883. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3884. rxp = &tp->rx_jumbo_buffers[i];
  3885. if (rxp->skb == NULL)
  3886. continue;
  3887. pci_unmap_single(tp->pdev,
  3888. pci_unmap_addr(rxp, mapping),
  3889. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3890. PCI_DMA_FROMDEVICE);
  3891. dev_kfree_skb_any(rxp->skb);
  3892. rxp->skb = NULL;
  3893. }
  3894. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3895. struct tx_ring_info *txp;
  3896. struct sk_buff *skb;
  3897. int j;
  3898. txp = &tp->tx_buffers[i];
  3899. skb = txp->skb;
  3900. if (skb == NULL) {
  3901. i++;
  3902. continue;
  3903. }
  3904. pci_unmap_single(tp->pdev,
  3905. pci_unmap_addr(txp, mapping),
  3906. skb_headlen(skb),
  3907. PCI_DMA_TODEVICE);
  3908. txp->skb = NULL;
  3909. i++;
  3910. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3911. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3912. pci_unmap_page(tp->pdev,
  3913. pci_unmap_addr(txp, mapping),
  3914. skb_shinfo(skb)->frags[j].size,
  3915. PCI_DMA_TODEVICE);
  3916. i++;
  3917. }
  3918. dev_kfree_skb_any(skb);
  3919. }
  3920. }
  3921. /* Initialize tx/rx rings for packet processing.
  3922. *
  3923. * The chip has been shut down and the driver detached from
  3924. * the networking, so no interrupts or new tx packets will
  3925. * end up in the driver. tp->{tx,}lock are held and thus
  3926. * we may not sleep.
  3927. */
  3928. static int tg3_init_rings(struct tg3 *tp)
  3929. {
  3930. u32 i;
  3931. /* Free up all the SKBs. */
  3932. tg3_free_rings(tp);
  3933. /* Zero out all descriptors. */
  3934. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3935. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3936. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3937. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3938. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3939. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3940. (tp->dev->mtu > ETH_DATA_LEN))
  3941. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3942. /* Initialize invariants of the rings, we only set this
  3943. * stuff once. This works because the card does not
  3944. * write into the rx buffer posting rings.
  3945. */
  3946. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3947. struct tg3_rx_buffer_desc *rxd;
  3948. rxd = &tp->rx_std[i];
  3949. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3950. << RXD_LEN_SHIFT;
  3951. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3952. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3953. (i << RXD_OPAQUE_INDEX_SHIFT));
  3954. }
  3955. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3956. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3957. struct tg3_rx_buffer_desc *rxd;
  3958. rxd = &tp->rx_jumbo[i];
  3959. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3960. << RXD_LEN_SHIFT;
  3961. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3962. RXD_FLAG_JUMBO;
  3963. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3964. (i << RXD_OPAQUE_INDEX_SHIFT));
  3965. }
  3966. }
  3967. /* Now allocate fresh SKBs for each rx ring. */
  3968. for (i = 0; i < tp->rx_pending; i++) {
  3969. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3970. printk(KERN_WARNING PFX
  3971. "%s: Using a smaller RX standard ring, "
  3972. "only %d out of %d buffers were allocated "
  3973. "successfully.\n",
  3974. tp->dev->name, i, tp->rx_pending);
  3975. if (i == 0)
  3976. return -ENOMEM;
  3977. tp->rx_pending = i;
  3978. break;
  3979. }
  3980. }
  3981. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3982. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3983. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3984. -1, i) < 0) {
  3985. printk(KERN_WARNING PFX
  3986. "%s: Using a smaller RX jumbo ring, "
  3987. "only %d out of %d buffers were "
  3988. "allocated successfully.\n",
  3989. tp->dev->name, i, tp->rx_jumbo_pending);
  3990. if (i == 0) {
  3991. tg3_free_rings(tp);
  3992. return -ENOMEM;
  3993. }
  3994. tp->rx_jumbo_pending = i;
  3995. break;
  3996. }
  3997. }
  3998. }
  3999. return 0;
  4000. }
  4001. /*
  4002. * Must not be invoked with interrupt sources disabled and
  4003. * the hardware shutdown down.
  4004. */
  4005. static void tg3_free_consistent(struct tg3 *tp)
  4006. {
  4007. kfree(tp->rx_std_buffers);
  4008. tp->rx_std_buffers = NULL;
  4009. if (tp->rx_std) {
  4010. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  4011. tp->rx_std, tp->rx_std_mapping);
  4012. tp->rx_std = NULL;
  4013. }
  4014. if (tp->rx_jumbo) {
  4015. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  4016. tp->rx_jumbo, tp->rx_jumbo_mapping);
  4017. tp->rx_jumbo = NULL;
  4018. }
  4019. if (tp->rx_rcb) {
  4020. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  4021. tp->rx_rcb, tp->rx_rcb_mapping);
  4022. tp->rx_rcb = NULL;
  4023. }
  4024. if (tp->tx_ring) {
  4025. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  4026. tp->tx_ring, tp->tx_desc_mapping);
  4027. tp->tx_ring = NULL;
  4028. }
  4029. if (tp->hw_status) {
  4030. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  4031. tp->hw_status, tp->status_mapping);
  4032. tp->hw_status = NULL;
  4033. }
  4034. if (tp->hw_stats) {
  4035. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  4036. tp->hw_stats, tp->stats_mapping);
  4037. tp->hw_stats = NULL;
  4038. }
  4039. }
  4040. /*
  4041. * Must not be invoked with interrupt sources disabled and
  4042. * the hardware shutdown down. Can sleep.
  4043. */
  4044. static int tg3_alloc_consistent(struct tg3 *tp)
  4045. {
  4046. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  4047. (TG3_RX_RING_SIZE +
  4048. TG3_RX_JUMBO_RING_SIZE)) +
  4049. (sizeof(struct tx_ring_info) *
  4050. TG3_TX_RING_SIZE),
  4051. GFP_KERNEL);
  4052. if (!tp->rx_std_buffers)
  4053. return -ENOMEM;
  4054. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  4055. tp->tx_buffers = (struct tx_ring_info *)
  4056. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  4057. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  4058. &tp->rx_std_mapping);
  4059. if (!tp->rx_std)
  4060. goto err_out;
  4061. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  4062. &tp->rx_jumbo_mapping);
  4063. if (!tp->rx_jumbo)
  4064. goto err_out;
  4065. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  4066. &tp->rx_rcb_mapping);
  4067. if (!tp->rx_rcb)
  4068. goto err_out;
  4069. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  4070. &tp->tx_desc_mapping);
  4071. if (!tp->tx_ring)
  4072. goto err_out;
  4073. tp->hw_status = pci_alloc_consistent(tp->pdev,
  4074. TG3_HW_STATUS_SIZE,
  4075. &tp->status_mapping);
  4076. if (!tp->hw_status)
  4077. goto err_out;
  4078. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  4079. sizeof(struct tg3_hw_stats),
  4080. &tp->stats_mapping);
  4081. if (!tp->hw_stats)
  4082. goto err_out;
  4083. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  4084. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  4085. return 0;
  4086. err_out:
  4087. tg3_free_consistent(tp);
  4088. return -ENOMEM;
  4089. }
  4090. #define MAX_WAIT_CNT 1000
  4091. /* To stop a block, clear the enable bit and poll till it
  4092. * clears. tp->lock is held.
  4093. */
  4094. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  4095. {
  4096. unsigned int i;
  4097. u32 val;
  4098. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  4099. switch (ofs) {
  4100. case RCVLSC_MODE:
  4101. case DMAC_MODE:
  4102. case MBFREE_MODE:
  4103. case BUFMGR_MODE:
  4104. case MEMARB_MODE:
  4105. /* We can't enable/disable these bits of the
  4106. * 5705/5750, just say success.
  4107. */
  4108. return 0;
  4109. default:
  4110. break;
  4111. };
  4112. }
  4113. val = tr32(ofs);
  4114. val &= ~enable_bit;
  4115. tw32_f(ofs, val);
  4116. for (i = 0; i < MAX_WAIT_CNT; i++) {
  4117. udelay(100);
  4118. val = tr32(ofs);
  4119. if ((val & enable_bit) == 0)
  4120. break;
  4121. }
  4122. if (i == MAX_WAIT_CNT && !silent) {
  4123. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  4124. "ofs=%lx enable_bit=%x\n",
  4125. ofs, enable_bit);
  4126. return -ENODEV;
  4127. }
  4128. return 0;
  4129. }
  4130. /* tp->lock is held. */
  4131. static int tg3_abort_hw(struct tg3 *tp, int silent)
  4132. {
  4133. int i, err;
  4134. tg3_disable_ints(tp);
  4135. tp->rx_mode &= ~RX_MODE_ENABLE;
  4136. tw32_f(MAC_RX_MODE, tp->rx_mode);
  4137. udelay(10);
  4138. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  4139. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  4140. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  4141. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  4142. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  4143. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  4144. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  4145. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  4146. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  4147. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  4148. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  4149. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  4150. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  4151. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  4152. tw32_f(MAC_MODE, tp->mac_mode);
  4153. udelay(40);
  4154. tp->tx_mode &= ~TX_MODE_ENABLE;
  4155. tw32_f(MAC_TX_MODE, tp->tx_mode);
  4156. for (i = 0; i < MAX_WAIT_CNT; i++) {
  4157. udelay(100);
  4158. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  4159. break;
  4160. }
  4161. if (i >= MAX_WAIT_CNT) {
  4162. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  4163. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  4164. tp->dev->name, tr32(MAC_TX_MODE));
  4165. err |= -ENODEV;
  4166. }
  4167. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  4168. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  4169. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  4170. tw32(FTQ_RESET, 0xffffffff);
  4171. tw32(FTQ_RESET, 0x00000000);
  4172. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  4173. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  4174. if (tp->hw_status)
  4175. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  4176. if (tp->hw_stats)
  4177. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  4178. return err;
  4179. }
  4180. /* tp->lock is held. */
  4181. static int tg3_nvram_lock(struct tg3 *tp)
  4182. {
  4183. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  4184. int i;
  4185. if (tp->nvram_lock_cnt == 0) {
  4186. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  4187. for (i = 0; i < 8000; i++) {
  4188. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  4189. break;
  4190. udelay(20);
  4191. }
  4192. if (i == 8000) {
  4193. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  4194. return -ENODEV;
  4195. }
  4196. }
  4197. tp->nvram_lock_cnt++;
  4198. }
  4199. return 0;
  4200. }
  4201. /* tp->lock is held. */
  4202. static void tg3_nvram_unlock(struct tg3 *tp)
  4203. {
  4204. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  4205. if (tp->nvram_lock_cnt > 0)
  4206. tp->nvram_lock_cnt--;
  4207. if (tp->nvram_lock_cnt == 0)
  4208. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  4209. }
  4210. }
  4211. /* tp->lock is held. */
  4212. static void tg3_enable_nvram_access(struct tg3 *tp)
  4213. {
  4214. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  4215. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  4216. u32 nvaccess = tr32(NVRAM_ACCESS);
  4217. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  4218. }
  4219. }
  4220. /* tp->lock is held. */
  4221. static void tg3_disable_nvram_access(struct tg3 *tp)
  4222. {
  4223. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  4224. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  4225. u32 nvaccess = tr32(NVRAM_ACCESS);
  4226. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  4227. }
  4228. }
  4229. static void tg3_ape_send_event(struct tg3 *tp, u32 event)
  4230. {
  4231. int i;
  4232. u32 apedata;
  4233. apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
  4234. if (apedata != APE_SEG_SIG_MAGIC)
  4235. return;
  4236. apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
  4237. if (apedata != APE_FW_STATUS_READY)
  4238. return;
  4239. /* Wait for up to 1 millisecond for APE to service previous event. */
  4240. for (i = 0; i < 10; i++) {
  4241. if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
  4242. return;
  4243. apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
  4244. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4245. tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
  4246. event | APE_EVENT_STATUS_EVENT_PENDING);
  4247. tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
  4248. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4249. break;
  4250. udelay(100);
  4251. }
  4252. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4253. tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
  4254. }
  4255. static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
  4256. {
  4257. u32 event;
  4258. u32 apedata;
  4259. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  4260. return;
  4261. switch (kind) {
  4262. case RESET_KIND_INIT:
  4263. tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG,
  4264. APE_HOST_SEG_SIG_MAGIC);
  4265. tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN,
  4266. APE_HOST_SEG_LEN_MAGIC);
  4267. apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT);
  4268. tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata);
  4269. tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID,
  4270. APE_HOST_DRIVER_ID_MAGIC);
  4271. tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR,
  4272. APE_HOST_BEHAV_NO_PHYLOCK);
  4273. event = APE_EVENT_STATUS_STATE_START;
  4274. break;
  4275. case RESET_KIND_SHUTDOWN:
  4276. event = APE_EVENT_STATUS_STATE_UNLOAD;
  4277. break;
  4278. case RESET_KIND_SUSPEND:
  4279. event = APE_EVENT_STATUS_STATE_SUSPEND;
  4280. break;
  4281. default:
  4282. return;
  4283. }
  4284. event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE;
  4285. tg3_ape_send_event(tp, event);
  4286. }
  4287. /* tp->lock is held. */
  4288. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  4289. {
  4290. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  4291. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  4292. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4293. switch (kind) {
  4294. case RESET_KIND_INIT:
  4295. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4296. DRV_STATE_START);
  4297. break;
  4298. case RESET_KIND_SHUTDOWN:
  4299. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4300. DRV_STATE_UNLOAD);
  4301. break;
  4302. case RESET_KIND_SUSPEND:
  4303. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4304. DRV_STATE_SUSPEND);
  4305. break;
  4306. default:
  4307. break;
  4308. };
  4309. }
  4310. if (kind == RESET_KIND_INIT ||
  4311. kind == RESET_KIND_SUSPEND)
  4312. tg3_ape_driver_state_change(tp, kind);
  4313. }
  4314. /* tp->lock is held. */
  4315. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  4316. {
  4317. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4318. switch (kind) {
  4319. case RESET_KIND_INIT:
  4320. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4321. DRV_STATE_START_DONE);
  4322. break;
  4323. case RESET_KIND_SHUTDOWN:
  4324. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4325. DRV_STATE_UNLOAD_DONE);
  4326. break;
  4327. default:
  4328. break;
  4329. };
  4330. }
  4331. if (kind == RESET_KIND_SHUTDOWN)
  4332. tg3_ape_driver_state_change(tp, kind);
  4333. }
  4334. /* tp->lock is held. */
  4335. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  4336. {
  4337. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4338. switch (kind) {
  4339. case RESET_KIND_INIT:
  4340. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4341. DRV_STATE_START);
  4342. break;
  4343. case RESET_KIND_SHUTDOWN:
  4344. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4345. DRV_STATE_UNLOAD);
  4346. break;
  4347. case RESET_KIND_SUSPEND:
  4348. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4349. DRV_STATE_SUSPEND);
  4350. break;
  4351. default:
  4352. break;
  4353. };
  4354. }
  4355. }
  4356. static int tg3_poll_fw(struct tg3 *tp)
  4357. {
  4358. int i;
  4359. u32 val;
  4360. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4361. /* Wait up to 20ms for init done. */
  4362. for (i = 0; i < 200; i++) {
  4363. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4364. return 0;
  4365. udelay(100);
  4366. }
  4367. return -ENODEV;
  4368. }
  4369. /* Wait for firmware initialization to complete. */
  4370. for (i = 0; i < 100000; i++) {
  4371. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4372. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4373. break;
  4374. udelay(10);
  4375. }
  4376. /* Chip might not be fitted with firmware. Some Sun onboard
  4377. * parts are configured like that. So don't signal the timeout
  4378. * of the above loop as an error, but do report the lack of
  4379. * running firmware once.
  4380. */
  4381. if (i >= 100000 &&
  4382. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4383. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4384. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4385. tp->dev->name);
  4386. }
  4387. return 0;
  4388. }
  4389. /* Save PCI command register before chip reset */
  4390. static void tg3_save_pci_state(struct tg3 *tp)
  4391. {
  4392. pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd);
  4393. }
  4394. /* Restore PCI state after chip reset */
  4395. static void tg3_restore_pci_state(struct tg3 *tp)
  4396. {
  4397. u32 val;
  4398. /* Re-enable indirect register accesses. */
  4399. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4400. tp->misc_host_ctrl);
  4401. /* Set MAX PCI retry to zero. */
  4402. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4403. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4404. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4405. val |= PCISTATE_RETRY_SAME_DMA;
  4406. /* Allow reads and writes to the APE register and memory space. */
  4407. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
  4408. val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  4409. PCISTATE_ALLOW_APE_SHMEM_WR;
  4410. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4411. pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd);
  4412. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  4413. pcie_set_readrq(tp->pdev, 4096);
  4414. else {
  4415. pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE,
  4416. tp->pci_cacheline_sz);
  4417. pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER,
  4418. tp->pci_lat_timer);
  4419. }
  4420. /* Make sure PCI-X relaxed ordering bit is clear. */
  4421. if (tp->pcix_cap) {
  4422. u16 pcix_cmd;
  4423. pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  4424. &pcix_cmd);
  4425. pcix_cmd &= ~PCI_X_CMD_ERO;
  4426. pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  4427. pcix_cmd);
  4428. }
  4429. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4430. /* Chip reset on 5780 will reset MSI enable bit,
  4431. * so need to restore it.
  4432. */
  4433. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4434. u16 ctrl;
  4435. pci_read_config_word(tp->pdev,
  4436. tp->msi_cap + PCI_MSI_FLAGS,
  4437. &ctrl);
  4438. pci_write_config_word(tp->pdev,
  4439. tp->msi_cap + PCI_MSI_FLAGS,
  4440. ctrl | PCI_MSI_FLAGS_ENABLE);
  4441. val = tr32(MSGINT_MODE);
  4442. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4443. }
  4444. }
  4445. }
  4446. static void tg3_stop_fw(struct tg3 *);
  4447. /* tp->lock is held. */
  4448. static int tg3_chip_reset(struct tg3 *tp)
  4449. {
  4450. u32 val;
  4451. void (*write_op)(struct tg3 *, u32, u32);
  4452. int err;
  4453. tg3_nvram_lock(tp);
  4454. /* No matching tg3_nvram_unlock() after this because
  4455. * chip reset below will undo the nvram lock.
  4456. */
  4457. tp->nvram_lock_cnt = 0;
  4458. /* GRC_MISC_CFG core clock reset will clear the memory
  4459. * enable bit in PCI register 4 and the MSI enable bit
  4460. * on some chips, so we save relevant registers here.
  4461. */
  4462. tg3_save_pci_state(tp);
  4463. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4464. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4465. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  4466. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  4467. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  4468. tw32(GRC_FASTBOOT_PC, 0);
  4469. /*
  4470. * We must avoid the readl() that normally takes place.
  4471. * It locks machines, causes machine checks, and other
  4472. * fun things. So, temporarily disable the 5701
  4473. * hardware workaround, while we do the reset.
  4474. */
  4475. write_op = tp->write32;
  4476. if (write_op == tg3_write_flush_reg32)
  4477. tp->write32 = tg3_write32;
  4478. /* Prevent the irq handler from reading or writing PCI registers
  4479. * during chip reset when the memory enable bit in the PCI command
  4480. * register may be cleared. The chip does not generate interrupt
  4481. * at this time, but the irq handler may still be called due to irq
  4482. * sharing or irqpoll.
  4483. */
  4484. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4485. if (tp->hw_status) {
  4486. tp->hw_status->status = 0;
  4487. tp->hw_status->status_tag = 0;
  4488. }
  4489. tp->last_tag = 0;
  4490. smp_mb();
  4491. synchronize_irq(tp->pdev->irq);
  4492. /* do the reset */
  4493. val = GRC_MISC_CFG_CORECLK_RESET;
  4494. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4495. if (tr32(0x7e2c) == 0x60) {
  4496. tw32(0x7e2c, 0x20);
  4497. }
  4498. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4499. tw32(GRC_MISC_CFG, (1 << 29));
  4500. val |= (1 << 29);
  4501. }
  4502. }
  4503. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4504. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4505. tw32(GRC_VCPU_EXT_CTRL,
  4506. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4507. }
  4508. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4509. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4510. tw32(GRC_MISC_CFG, val);
  4511. /* restore 5701 hardware bug workaround write method */
  4512. tp->write32 = write_op;
  4513. /* Unfortunately, we have to delay before the PCI read back.
  4514. * Some 575X chips even will not respond to a PCI cfg access
  4515. * when the reset command is given to the chip.
  4516. *
  4517. * How do these hardware designers expect things to work
  4518. * properly if the PCI write is posted for a long period
  4519. * of time? It is always necessary to have some method by
  4520. * which a register read back can occur to push the write
  4521. * out which does the reset.
  4522. *
  4523. * For most tg3 variants the trick below was working.
  4524. * Ho hum...
  4525. */
  4526. udelay(120);
  4527. /* Flush PCI posted writes. The normal MMIO registers
  4528. * are inaccessible at this time so this is the only
  4529. * way to make this reliably (actually, this is no longer
  4530. * the case, see above). I tried to use indirect
  4531. * register read/write but this upset some 5701 variants.
  4532. */
  4533. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4534. udelay(120);
  4535. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4536. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4537. int i;
  4538. u32 cfg_val;
  4539. /* Wait for link training to complete. */
  4540. for (i = 0; i < 5000; i++)
  4541. udelay(100);
  4542. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4543. pci_write_config_dword(tp->pdev, 0xc4,
  4544. cfg_val | (1 << 15));
  4545. }
  4546. /* Set PCIE max payload size and clear error status. */
  4547. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4548. }
  4549. tg3_restore_pci_state(tp);
  4550. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4551. val = 0;
  4552. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  4553. val = tr32(MEMARB_MODE);
  4554. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4555. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4556. tg3_stop_fw(tp);
  4557. tw32(0x5000, 0x400);
  4558. }
  4559. tw32(GRC_MODE, tp->grc_mode);
  4560. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4561. val = tr32(0xc4);
  4562. tw32(0xc4, val | (1 << 15));
  4563. }
  4564. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4565. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4566. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4567. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4568. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4569. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4570. }
  4571. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4572. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4573. tw32_f(MAC_MODE, tp->mac_mode);
  4574. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4575. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4576. tw32_f(MAC_MODE, tp->mac_mode);
  4577. } else
  4578. tw32_f(MAC_MODE, 0);
  4579. udelay(40);
  4580. err = tg3_poll_fw(tp);
  4581. if (err)
  4582. return err;
  4583. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4584. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4585. val = tr32(0x7c00);
  4586. tw32(0x7c00, val | (1 << 25));
  4587. }
  4588. /* Reprobe ASF enable state. */
  4589. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4590. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4591. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4592. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4593. u32 nic_cfg;
  4594. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4595. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4596. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4597. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4598. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4599. }
  4600. }
  4601. return 0;
  4602. }
  4603. /* tp->lock is held. */
  4604. static void tg3_stop_fw(struct tg3 *tp)
  4605. {
  4606. if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
  4607. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
  4608. u32 val;
  4609. int i;
  4610. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4611. val = tr32(GRC_RX_CPU_EVENT);
  4612. val |= (1 << 14);
  4613. tw32(GRC_RX_CPU_EVENT, val);
  4614. /* Wait for RX cpu to ACK the event. */
  4615. for (i = 0; i < 100; i++) {
  4616. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4617. break;
  4618. udelay(1);
  4619. }
  4620. }
  4621. }
  4622. /* tp->lock is held. */
  4623. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4624. {
  4625. int err;
  4626. tg3_stop_fw(tp);
  4627. tg3_write_sig_pre_reset(tp, kind);
  4628. tg3_abort_hw(tp, silent);
  4629. err = tg3_chip_reset(tp);
  4630. tg3_write_sig_legacy(tp, kind);
  4631. tg3_write_sig_post_reset(tp, kind);
  4632. if (err)
  4633. return err;
  4634. return 0;
  4635. }
  4636. #define TG3_FW_RELEASE_MAJOR 0x0
  4637. #define TG3_FW_RELASE_MINOR 0x0
  4638. #define TG3_FW_RELEASE_FIX 0x0
  4639. #define TG3_FW_START_ADDR 0x08000000
  4640. #define TG3_FW_TEXT_ADDR 0x08000000
  4641. #define TG3_FW_TEXT_LEN 0x9c0
  4642. #define TG3_FW_RODATA_ADDR 0x080009c0
  4643. #define TG3_FW_RODATA_LEN 0x60
  4644. #define TG3_FW_DATA_ADDR 0x08000a40
  4645. #define TG3_FW_DATA_LEN 0x20
  4646. #define TG3_FW_SBSS_ADDR 0x08000a60
  4647. #define TG3_FW_SBSS_LEN 0xc
  4648. #define TG3_FW_BSS_ADDR 0x08000a70
  4649. #define TG3_FW_BSS_LEN 0x10
  4650. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4651. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4652. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4653. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4654. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4655. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4656. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4657. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4658. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4659. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4660. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4661. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4662. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4663. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4664. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4665. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4666. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4667. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4668. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4669. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4670. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4671. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4672. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4673. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4676. 0, 0, 0, 0, 0, 0,
  4677. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4678. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4679. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4680. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4681. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4682. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4683. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4684. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4685. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4686. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4687. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4691. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4692. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4693. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4694. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4695. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4696. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4697. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4698. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4699. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4700. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4701. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4702. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4703. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4704. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4705. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4706. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4707. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4708. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4709. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4710. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4711. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4712. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4713. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4714. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4715. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4716. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4717. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4718. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4719. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4720. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4721. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4722. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4723. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4724. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4725. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4726. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4727. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4728. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4729. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4730. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4731. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4732. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4733. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4734. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4735. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4736. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4737. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4738. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4739. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4740. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4741. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4742. };
  4743. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4744. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4745. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4746. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4747. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4748. 0x00000000
  4749. };
  4750. #if 0 /* All zeros, don't eat up space with it. */
  4751. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4752. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4753. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4754. };
  4755. #endif
  4756. #define RX_CPU_SCRATCH_BASE 0x30000
  4757. #define RX_CPU_SCRATCH_SIZE 0x04000
  4758. #define TX_CPU_SCRATCH_BASE 0x34000
  4759. #define TX_CPU_SCRATCH_SIZE 0x04000
  4760. /* tp->lock is held. */
  4761. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4762. {
  4763. int i;
  4764. BUG_ON(offset == TX_CPU_BASE &&
  4765. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4766. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4767. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4768. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4769. return 0;
  4770. }
  4771. if (offset == RX_CPU_BASE) {
  4772. for (i = 0; i < 10000; i++) {
  4773. tw32(offset + CPU_STATE, 0xffffffff);
  4774. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4775. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4776. break;
  4777. }
  4778. tw32(offset + CPU_STATE, 0xffffffff);
  4779. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4780. udelay(10);
  4781. } else {
  4782. for (i = 0; i < 10000; i++) {
  4783. tw32(offset + CPU_STATE, 0xffffffff);
  4784. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4785. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4786. break;
  4787. }
  4788. }
  4789. if (i >= 10000) {
  4790. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4791. "and %s CPU\n",
  4792. tp->dev->name,
  4793. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4794. return -ENODEV;
  4795. }
  4796. /* Clear firmware's nvram arbitration. */
  4797. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4798. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4799. return 0;
  4800. }
  4801. struct fw_info {
  4802. unsigned int text_base;
  4803. unsigned int text_len;
  4804. const u32 *text_data;
  4805. unsigned int rodata_base;
  4806. unsigned int rodata_len;
  4807. const u32 *rodata_data;
  4808. unsigned int data_base;
  4809. unsigned int data_len;
  4810. const u32 *data_data;
  4811. };
  4812. /* tp->lock is held. */
  4813. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4814. int cpu_scratch_size, struct fw_info *info)
  4815. {
  4816. int err, lock_err, i;
  4817. void (*write_op)(struct tg3 *, u32, u32);
  4818. if (cpu_base == TX_CPU_BASE &&
  4819. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4820. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4821. "TX cpu firmware on %s which is 5705.\n",
  4822. tp->dev->name);
  4823. return -EINVAL;
  4824. }
  4825. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4826. write_op = tg3_write_mem;
  4827. else
  4828. write_op = tg3_write_indirect_reg32;
  4829. /* It is possible that bootcode is still loading at this point.
  4830. * Get the nvram lock first before halting the cpu.
  4831. */
  4832. lock_err = tg3_nvram_lock(tp);
  4833. err = tg3_halt_cpu(tp, cpu_base);
  4834. if (!lock_err)
  4835. tg3_nvram_unlock(tp);
  4836. if (err)
  4837. goto out;
  4838. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4839. write_op(tp, cpu_scratch_base + i, 0);
  4840. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4841. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4842. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4843. write_op(tp, (cpu_scratch_base +
  4844. (info->text_base & 0xffff) +
  4845. (i * sizeof(u32))),
  4846. (info->text_data ?
  4847. info->text_data[i] : 0));
  4848. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4849. write_op(tp, (cpu_scratch_base +
  4850. (info->rodata_base & 0xffff) +
  4851. (i * sizeof(u32))),
  4852. (info->rodata_data ?
  4853. info->rodata_data[i] : 0));
  4854. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4855. write_op(tp, (cpu_scratch_base +
  4856. (info->data_base & 0xffff) +
  4857. (i * sizeof(u32))),
  4858. (info->data_data ?
  4859. info->data_data[i] : 0));
  4860. err = 0;
  4861. out:
  4862. return err;
  4863. }
  4864. /* tp->lock is held. */
  4865. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4866. {
  4867. struct fw_info info;
  4868. int err, i;
  4869. info.text_base = TG3_FW_TEXT_ADDR;
  4870. info.text_len = TG3_FW_TEXT_LEN;
  4871. info.text_data = &tg3FwText[0];
  4872. info.rodata_base = TG3_FW_RODATA_ADDR;
  4873. info.rodata_len = TG3_FW_RODATA_LEN;
  4874. info.rodata_data = &tg3FwRodata[0];
  4875. info.data_base = TG3_FW_DATA_ADDR;
  4876. info.data_len = TG3_FW_DATA_LEN;
  4877. info.data_data = NULL;
  4878. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4879. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4880. &info);
  4881. if (err)
  4882. return err;
  4883. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4884. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4885. &info);
  4886. if (err)
  4887. return err;
  4888. /* Now startup only the RX cpu. */
  4889. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4890. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4891. for (i = 0; i < 5; i++) {
  4892. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4893. break;
  4894. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4895. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4896. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4897. udelay(1000);
  4898. }
  4899. if (i >= 5) {
  4900. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4901. "to set RX CPU PC, is %08x should be %08x\n",
  4902. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4903. TG3_FW_TEXT_ADDR);
  4904. return -ENODEV;
  4905. }
  4906. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4907. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4908. return 0;
  4909. }
  4910. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4911. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4912. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4913. #define TG3_TSO_FW_START_ADDR 0x08000000
  4914. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4915. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4916. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4917. #define TG3_TSO_FW_RODATA_LEN 0x60
  4918. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4919. #define TG3_TSO_FW_DATA_LEN 0x30
  4920. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4921. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4922. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4923. #define TG3_TSO_FW_BSS_LEN 0x894
  4924. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4925. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4926. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4927. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4928. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4929. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4930. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4931. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4932. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4933. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4934. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4935. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4936. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4937. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4938. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4939. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4940. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4941. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4942. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4943. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4944. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4945. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4946. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4947. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4948. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4949. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4950. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4951. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4952. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4953. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4954. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4955. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4956. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4957. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4958. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4959. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4960. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4961. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4962. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4963. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4964. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4965. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4966. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4967. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4968. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4969. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4970. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4971. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4972. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4973. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4974. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4975. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4976. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4977. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4978. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4979. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4980. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4981. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4982. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4983. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4984. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4985. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4986. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4987. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4988. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4989. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4990. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4991. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4992. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4993. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4994. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4995. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4996. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4997. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4998. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4999. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  5000. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  5001. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  5002. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  5003. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  5004. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  5005. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  5006. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  5007. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  5008. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  5009. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  5010. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  5011. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  5012. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  5013. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  5014. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  5015. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  5016. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  5017. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  5018. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  5019. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  5020. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  5021. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  5022. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  5023. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  5024. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  5025. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  5026. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  5027. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  5028. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  5029. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  5030. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  5031. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  5032. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  5033. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  5034. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  5035. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  5036. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  5037. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  5038. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  5039. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  5040. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  5041. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  5042. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  5043. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  5044. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  5045. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  5046. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  5047. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  5048. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  5049. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  5050. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  5051. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  5052. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  5053. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  5054. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  5055. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  5056. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  5057. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  5058. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  5059. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  5060. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  5061. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  5062. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  5063. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  5064. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  5065. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  5066. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  5067. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  5068. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  5069. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  5070. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  5071. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  5072. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  5073. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  5074. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  5075. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  5076. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  5077. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  5078. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  5079. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  5080. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  5081. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  5082. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  5083. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  5084. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  5085. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  5086. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  5087. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  5088. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  5089. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  5090. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  5091. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  5092. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  5093. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  5094. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  5095. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  5096. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  5097. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  5098. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  5099. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  5100. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  5101. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  5102. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  5103. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  5104. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  5105. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  5106. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  5107. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  5108. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  5109. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  5110. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  5111. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  5112. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  5113. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  5114. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  5115. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  5116. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  5117. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  5118. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  5119. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  5120. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  5121. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  5122. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  5123. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  5124. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  5125. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  5126. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  5127. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  5128. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  5129. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  5130. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  5131. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  5132. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  5133. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  5134. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  5135. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  5136. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  5137. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  5138. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  5139. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  5140. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  5141. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  5142. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  5143. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  5144. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  5145. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  5146. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  5147. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  5148. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  5149. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  5150. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  5151. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  5152. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  5153. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  5154. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  5155. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  5156. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  5157. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  5158. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  5159. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  5160. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  5161. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  5162. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  5163. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  5164. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  5165. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  5166. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  5167. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  5168. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  5169. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  5170. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  5171. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  5172. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  5173. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  5174. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  5175. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  5176. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  5177. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  5178. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  5179. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  5180. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  5181. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  5182. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  5183. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  5184. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  5185. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  5186. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  5187. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  5188. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  5189. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  5190. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  5191. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  5192. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  5193. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  5194. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  5195. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  5196. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  5197. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  5198. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  5199. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  5200. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  5201. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  5202. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  5203. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  5204. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  5205. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  5206. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  5207. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  5208. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  5209. };
  5210. static const u32 tg3TsoFwRodata[] = {
  5211. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5212. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  5213. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  5214. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  5215. 0x00000000,
  5216. };
  5217. static const u32 tg3TsoFwData[] = {
  5218. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  5219. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  5220. 0x00000000,
  5221. };
  5222. /* 5705 needs a special version of the TSO firmware. */
  5223. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  5224. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  5225. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  5226. #define TG3_TSO5_FW_START_ADDR 0x00010000
  5227. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  5228. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  5229. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  5230. #define TG3_TSO5_FW_RODATA_LEN 0x50
  5231. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  5232. #define TG3_TSO5_FW_DATA_LEN 0x20
  5233. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  5234. #define TG3_TSO5_FW_SBSS_LEN 0x28
  5235. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  5236. #define TG3_TSO5_FW_BSS_LEN 0x88
  5237. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  5238. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  5239. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  5240. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  5241. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  5242. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  5243. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  5244. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5245. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  5246. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  5247. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  5248. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  5249. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  5250. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  5251. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  5252. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  5253. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  5254. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  5255. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  5256. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  5257. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  5258. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  5259. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  5260. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  5261. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  5262. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  5263. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  5264. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  5265. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  5266. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  5267. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  5268. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  5269. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  5270. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  5271. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  5272. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  5273. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  5274. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  5275. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  5276. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  5277. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  5278. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  5279. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  5280. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  5281. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  5282. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  5283. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  5284. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  5285. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  5286. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  5287. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  5288. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  5289. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  5290. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  5291. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  5292. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  5293. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  5294. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  5295. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  5296. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  5297. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  5298. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  5299. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  5300. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  5301. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  5302. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  5303. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  5304. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  5305. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  5306. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  5307. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  5308. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  5309. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  5310. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  5311. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  5312. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  5313. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  5314. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  5315. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  5316. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  5317. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  5318. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  5319. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  5320. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  5321. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  5322. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  5323. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  5324. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  5325. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  5326. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  5327. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  5328. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  5329. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  5330. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  5331. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  5332. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  5333. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  5334. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  5335. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  5336. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  5337. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  5338. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  5339. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  5340. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  5341. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  5342. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  5343. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  5344. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5345. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5346. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  5347. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  5348. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  5349. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  5350. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  5351. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  5352. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  5353. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  5354. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  5355. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5356. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5357. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  5358. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  5359. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  5360. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  5361. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5362. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  5363. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  5364. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  5365. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  5366. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  5367. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  5368. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  5369. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  5370. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  5371. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  5372. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  5373. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  5374. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  5375. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  5376. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  5377. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  5378. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  5379. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  5380. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  5381. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  5382. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  5383. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  5384. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  5385. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  5386. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  5387. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  5388. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  5389. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  5390. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5391. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5392. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5393. 0x00000000, 0x00000000, 0x00000000,
  5394. };
  5395. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5396. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5397. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5398. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5399. 0x00000000, 0x00000000, 0x00000000,
  5400. };
  5401. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5402. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5403. 0x00000000, 0x00000000, 0x00000000,
  5404. };
  5405. /* tp->lock is held. */
  5406. static int tg3_load_tso_firmware(struct tg3 *tp)
  5407. {
  5408. struct fw_info info;
  5409. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5410. int err, i;
  5411. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5412. return 0;
  5413. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5414. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5415. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5416. info.text_data = &tg3Tso5FwText[0];
  5417. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5418. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5419. info.rodata_data = &tg3Tso5FwRodata[0];
  5420. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5421. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5422. info.data_data = &tg3Tso5FwData[0];
  5423. cpu_base = RX_CPU_BASE;
  5424. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5425. cpu_scratch_size = (info.text_len +
  5426. info.rodata_len +
  5427. info.data_len +
  5428. TG3_TSO5_FW_SBSS_LEN +
  5429. TG3_TSO5_FW_BSS_LEN);
  5430. } else {
  5431. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5432. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5433. info.text_data = &tg3TsoFwText[0];
  5434. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5435. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5436. info.rodata_data = &tg3TsoFwRodata[0];
  5437. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5438. info.data_len = TG3_TSO_FW_DATA_LEN;
  5439. info.data_data = &tg3TsoFwData[0];
  5440. cpu_base = TX_CPU_BASE;
  5441. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5442. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5443. }
  5444. err = tg3_load_firmware_cpu(tp, cpu_base,
  5445. cpu_scratch_base, cpu_scratch_size,
  5446. &info);
  5447. if (err)
  5448. return err;
  5449. /* Now startup the cpu. */
  5450. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5451. tw32_f(cpu_base + CPU_PC, info.text_base);
  5452. for (i = 0; i < 5; i++) {
  5453. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5454. break;
  5455. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5456. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5457. tw32_f(cpu_base + CPU_PC, info.text_base);
  5458. udelay(1000);
  5459. }
  5460. if (i >= 5) {
  5461. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5462. "to set CPU PC, is %08x should be %08x\n",
  5463. tp->dev->name, tr32(cpu_base + CPU_PC),
  5464. info.text_base);
  5465. return -ENODEV;
  5466. }
  5467. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5468. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5469. return 0;
  5470. }
  5471. /* tp->lock is held. */
  5472. static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
  5473. {
  5474. u32 addr_high, addr_low;
  5475. int i;
  5476. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5477. tp->dev->dev_addr[1]);
  5478. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5479. (tp->dev->dev_addr[3] << 16) |
  5480. (tp->dev->dev_addr[4] << 8) |
  5481. (tp->dev->dev_addr[5] << 0));
  5482. for (i = 0; i < 4; i++) {
  5483. if (i == 1 && skip_mac_1)
  5484. continue;
  5485. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5486. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5487. }
  5488. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5489. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5490. for (i = 0; i < 12; i++) {
  5491. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5492. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5493. }
  5494. }
  5495. addr_high = (tp->dev->dev_addr[0] +
  5496. tp->dev->dev_addr[1] +
  5497. tp->dev->dev_addr[2] +
  5498. tp->dev->dev_addr[3] +
  5499. tp->dev->dev_addr[4] +
  5500. tp->dev->dev_addr[5]) &
  5501. TX_BACKOFF_SEED_MASK;
  5502. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5503. }
  5504. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5505. {
  5506. struct tg3 *tp = netdev_priv(dev);
  5507. struct sockaddr *addr = p;
  5508. int err = 0, skip_mac_1 = 0;
  5509. if (!is_valid_ether_addr(addr->sa_data))
  5510. return -EINVAL;
  5511. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5512. if (!netif_running(dev))
  5513. return 0;
  5514. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5515. u32 addr0_high, addr0_low, addr1_high, addr1_low;
  5516. addr0_high = tr32(MAC_ADDR_0_HIGH);
  5517. addr0_low = tr32(MAC_ADDR_0_LOW);
  5518. addr1_high = tr32(MAC_ADDR_1_HIGH);
  5519. addr1_low = tr32(MAC_ADDR_1_LOW);
  5520. /* Skip MAC addr 1 if ASF is using it. */
  5521. if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
  5522. !(addr1_high == 0 && addr1_low == 0))
  5523. skip_mac_1 = 1;
  5524. }
  5525. spin_lock_bh(&tp->lock);
  5526. __tg3_set_mac_addr(tp, skip_mac_1);
  5527. spin_unlock_bh(&tp->lock);
  5528. return err;
  5529. }
  5530. /* tp->lock is held. */
  5531. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5532. dma_addr_t mapping, u32 maxlen_flags,
  5533. u32 nic_addr)
  5534. {
  5535. tg3_write_mem(tp,
  5536. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5537. ((u64) mapping >> 32));
  5538. tg3_write_mem(tp,
  5539. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5540. ((u64) mapping & 0xffffffff));
  5541. tg3_write_mem(tp,
  5542. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5543. maxlen_flags);
  5544. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5545. tg3_write_mem(tp,
  5546. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5547. nic_addr);
  5548. }
  5549. static void __tg3_set_rx_mode(struct net_device *);
  5550. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5551. {
  5552. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5553. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5554. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5555. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5556. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5557. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5558. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5559. }
  5560. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5561. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5562. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5563. u32 val = ec->stats_block_coalesce_usecs;
  5564. if (!netif_carrier_ok(tp->dev))
  5565. val = 0;
  5566. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5567. }
  5568. }
  5569. /* tp->lock is held. */
  5570. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5571. {
  5572. u32 val, rdmac_mode;
  5573. int i, err, limit;
  5574. tg3_disable_ints(tp);
  5575. tg3_stop_fw(tp);
  5576. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5577. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5578. tg3_abort_hw(tp, 1);
  5579. }
  5580. if (reset_phy)
  5581. tg3_phy_reset(tp);
  5582. err = tg3_chip_reset(tp);
  5583. if (err)
  5584. return err;
  5585. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5586. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  5587. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1) {
  5588. val = tr32(TG3_CPMU_CTRL);
  5589. val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE);
  5590. tw32(TG3_CPMU_CTRL, val);
  5591. val = tr32(TG3_CPMU_LSPD_10MB_CLK);
  5592. val &= ~CPMU_LSPD_10MB_MACCLK_MASK;
  5593. val |= CPMU_LSPD_10MB_MACCLK_6_25;
  5594. tw32(TG3_CPMU_LSPD_10MB_CLK, val);
  5595. val = tr32(TG3_CPMU_LNK_AWARE_PWRMD);
  5596. val &= ~CPMU_LNK_AWARE_MACCLK_MASK;
  5597. val |= CPMU_LNK_AWARE_MACCLK_6_25;
  5598. tw32(TG3_CPMU_LNK_AWARE_PWRMD, val);
  5599. val = tr32(TG3_CPMU_HST_ACC);
  5600. val &= ~CPMU_HST_ACC_MACCLK_MASK;
  5601. val |= CPMU_HST_ACC_MACCLK_6_25;
  5602. tw32(TG3_CPMU_HST_ACC, val);
  5603. }
  5604. /* This works around an issue with Athlon chipsets on
  5605. * B3 tigon3 silicon. This bit has no effect on any
  5606. * other revision. But do not set this on PCI Express
  5607. * chips and don't even touch the clocks if the CPMU is present.
  5608. */
  5609. if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) {
  5610. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5611. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5612. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5613. }
  5614. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5615. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5616. val = tr32(TG3PCI_PCISTATE);
  5617. val |= PCISTATE_RETRY_SAME_DMA;
  5618. tw32(TG3PCI_PCISTATE, val);
  5619. }
  5620. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  5621. /* Allow reads and writes to the
  5622. * APE register and memory space.
  5623. */
  5624. val = tr32(TG3PCI_PCISTATE);
  5625. val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  5626. PCISTATE_ALLOW_APE_SHMEM_WR;
  5627. tw32(TG3PCI_PCISTATE, val);
  5628. }
  5629. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5630. /* Enable some hw fixes. */
  5631. val = tr32(TG3PCI_MSI_DATA);
  5632. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5633. tw32(TG3PCI_MSI_DATA, val);
  5634. }
  5635. /* Descriptor ring init may make accesses to the
  5636. * NIC SRAM area to setup the TX descriptors, so we
  5637. * can only do this after the hardware has been
  5638. * successfully reset.
  5639. */
  5640. err = tg3_init_rings(tp);
  5641. if (err)
  5642. return err;
  5643. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 &&
  5644. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) {
  5645. /* This value is determined during the probe time DMA
  5646. * engine test, tg3_test_dma.
  5647. */
  5648. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5649. }
  5650. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5651. GRC_MODE_4X_NIC_SEND_RINGS |
  5652. GRC_MODE_NO_TX_PHDR_CSUM |
  5653. GRC_MODE_NO_RX_PHDR_CSUM);
  5654. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5655. /* Pseudo-header checksum is done by hardware logic and not
  5656. * the offload processers, so make the chip do the pseudo-
  5657. * header checksums on receive. For transmit it is more
  5658. * convenient to do the pseudo-header checksum in software
  5659. * as Linux does that on transmit for us in all cases.
  5660. */
  5661. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5662. tw32(GRC_MODE,
  5663. tp->grc_mode |
  5664. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5665. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5666. val = tr32(GRC_MISC_CFG);
  5667. val &= ~0xff;
  5668. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5669. tw32(GRC_MISC_CFG, val);
  5670. /* Initialize MBUF/DESC pool. */
  5671. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5672. /* Do nothing. */
  5673. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5674. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5675. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5676. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5677. else
  5678. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5679. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5680. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5681. }
  5682. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5683. int fw_len;
  5684. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5685. TG3_TSO5_FW_RODATA_LEN +
  5686. TG3_TSO5_FW_DATA_LEN +
  5687. TG3_TSO5_FW_SBSS_LEN +
  5688. TG3_TSO5_FW_BSS_LEN);
  5689. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5690. tw32(BUFMGR_MB_POOL_ADDR,
  5691. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5692. tw32(BUFMGR_MB_POOL_SIZE,
  5693. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5694. }
  5695. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5696. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5697. tp->bufmgr_config.mbuf_read_dma_low_water);
  5698. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5699. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5700. tw32(BUFMGR_MB_HIGH_WATER,
  5701. tp->bufmgr_config.mbuf_high_water);
  5702. } else {
  5703. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5704. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5705. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5706. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5707. tw32(BUFMGR_MB_HIGH_WATER,
  5708. tp->bufmgr_config.mbuf_high_water_jumbo);
  5709. }
  5710. tw32(BUFMGR_DMA_LOW_WATER,
  5711. tp->bufmgr_config.dma_low_water);
  5712. tw32(BUFMGR_DMA_HIGH_WATER,
  5713. tp->bufmgr_config.dma_high_water);
  5714. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5715. for (i = 0; i < 2000; i++) {
  5716. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5717. break;
  5718. udelay(10);
  5719. }
  5720. if (i >= 2000) {
  5721. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5722. tp->dev->name);
  5723. return -ENODEV;
  5724. }
  5725. /* Setup replenish threshold. */
  5726. val = tp->rx_pending / 8;
  5727. if (val == 0)
  5728. val = 1;
  5729. else if (val > tp->rx_std_max_post)
  5730. val = tp->rx_std_max_post;
  5731. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5732. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5733. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5734. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5735. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5736. }
  5737. tw32(RCVBDI_STD_THRESH, val);
  5738. /* Initialize TG3_BDINFO's at:
  5739. * RCVDBDI_STD_BD: standard eth size rx ring
  5740. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5741. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5742. *
  5743. * like so:
  5744. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5745. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5746. * ring attribute flags
  5747. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5748. *
  5749. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5750. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5751. *
  5752. * The size of each ring is fixed in the firmware, but the location is
  5753. * configurable.
  5754. */
  5755. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5756. ((u64) tp->rx_std_mapping >> 32));
  5757. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5758. ((u64) tp->rx_std_mapping & 0xffffffff));
  5759. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5760. NIC_SRAM_RX_BUFFER_DESC);
  5761. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5762. * configs on 5705.
  5763. */
  5764. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5765. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5766. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5767. } else {
  5768. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5769. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5770. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5771. BDINFO_FLAGS_DISABLED);
  5772. /* Setup replenish threshold. */
  5773. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5774. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5775. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5776. ((u64) tp->rx_jumbo_mapping >> 32));
  5777. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5778. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5779. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5780. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5781. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5782. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5783. } else {
  5784. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5785. BDINFO_FLAGS_DISABLED);
  5786. }
  5787. }
  5788. /* There is only one send ring on 5705/5750, no need to explicitly
  5789. * disable the others.
  5790. */
  5791. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5792. /* Clear out send RCB ring in SRAM. */
  5793. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5794. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5795. BDINFO_FLAGS_DISABLED);
  5796. }
  5797. tp->tx_prod = 0;
  5798. tp->tx_cons = 0;
  5799. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5800. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5801. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5802. tp->tx_desc_mapping,
  5803. (TG3_TX_RING_SIZE <<
  5804. BDINFO_FLAGS_MAXLEN_SHIFT),
  5805. NIC_SRAM_TX_BUFFER_DESC);
  5806. /* There is only one receive return ring on 5705/5750, no need
  5807. * to explicitly disable the others.
  5808. */
  5809. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5810. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5811. i += TG3_BDINFO_SIZE) {
  5812. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5813. BDINFO_FLAGS_DISABLED);
  5814. }
  5815. }
  5816. tp->rx_rcb_ptr = 0;
  5817. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5818. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5819. tp->rx_rcb_mapping,
  5820. (TG3_RX_RCB_RING_SIZE(tp) <<
  5821. BDINFO_FLAGS_MAXLEN_SHIFT),
  5822. 0);
  5823. tp->rx_std_ptr = tp->rx_pending;
  5824. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5825. tp->rx_std_ptr);
  5826. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5827. tp->rx_jumbo_pending : 0;
  5828. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5829. tp->rx_jumbo_ptr);
  5830. /* Initialize MAC address and backoff seed. */
  5831. __tg3_set_mac_addr(tp, 0);
  5832. /* MTU + ethernet header + FCS + optional VLAN tag */
  5833. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5834. /* The slot time is changed by tg3_setup_phy if we
  5835. * run at gigabit with half duplex.
  5836. */
  5837. tw32(MAC_TX_LENGTHS,
  5838. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5839. (6 << TX_LENGTHS_IPG_SHIFT) |
  5840. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5841. /* Receive rules. */
  5842. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5843. tw32(RCVLPC_CONFIG, 0x0181);
  5844. /* Calculate RDMAC_MODE setting early, we need it to determine
  5845. * the RCVLPC_STATE_ENABLE mask.
  5846. */
  5847. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5848. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5849. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5850. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5851. RDMAC_MODE_LNGREAD_ENAB);
  5852. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)
  5853. rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB |
  5854. RDMAC_MODE_MBUF_RBD_CRPT_ENAB |
  5855. RDMAC_MODE_MBUF_SBD_CRPT_ENAB;
  5856. /* If statement applies to 5705 and 5750 PCI devices only */
  5857. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5858. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5859. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5860. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5861. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5862. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5863. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5864. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5865. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5866. }
  5867. }
  5868. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5869. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5870. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5871. rdmac_mode |= (1 << 27);
  5872. /* Receive/send statistics. */
  5873. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5874. val = tr32(RCVLPC_STATS_ENABLE);
  5875. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5876. tw32(RCVLPC_STATS_ENABLE, val);
  5877. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5878. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5879. val = tr32(RCVLPC_STATS_ENABLE);
  5880. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5881. tw32(RCVLPC_STATS_ENABLE, val);
  5882. } else {
  5883. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5884. }
  5885. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5886. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5887. tw32(SNDDATAI_STATSCTRL,
  5888. (SNDDATAI_SCTRL_ENABLE |
  5889. SNDDATAI_SCTRL_FASTUPD));
  5890. /* Setup host coalescing engine. */
  5891. tw32(HOSTCC_MODE, 0);
  5892. for (i = 0; i < 2000; i++) {
  5893. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5894. break;
  5895. udelay(10);
  5896. }
  5897. __tg3_set_coalesce(tp, &tp->coal);
  5898. /* set status block DMA address */
  5899. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5900. ((u64) tp->status_mapping >> 32));
  5901. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5902. ((u64) tp->status_mapping & 0xffffffff));
  5903. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5904. /* Status/statistics block address. See tg3_timer,
  5905. * the tg3_periodic_fetch_stats call there, and
  5906. * tg3_get_stats to see how this works for 5705/5750 chips.
  5907. */
  5908. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5909. ((u64) tp->stats_mapping >> 32));
  5910. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5911. ((u64) tp->stats_mapping & 0xffffffff));
  5912. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5913. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5914. }
  5915. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5916. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5917. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5918. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5919. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5920. /* Clear statistics/status block in chip, and status block in ram. */
  5921. for (i = NIC_SRAM_STATS_BLK;
  5922. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5923. i += sizeof(u32)) {
  5924. tg3_write_mem(tp, i, 0);
  5925. udelay(40);
  5926. }
  5927. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5928. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5929. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5930. /* reset to prevent losing 1st rx packet intermittently */
  5931. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5932. udelay(10);
  5933. }
  5934. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5935. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5936. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5937. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5938. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
  5939. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  5940. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5941. udelay(40);
  5942. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5943. * If TG3_FLG2_IS_NIC is zero, we should read the
  5944. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5945. * whether used as inputs or outputs, are set by boot code after
  5946. * reset.
  5947. */
  5948. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5949. u32 gpio_mask;
  5950. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5951. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5952. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5953. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5954. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5955. GRC_LCLCTRL_GPIO_OUTPUT3;
  5956. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5957. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5958. tp->grc_local_ctrl &= ~gpio_mask;
  5959. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5960. /* GPIO1 must be driven high for eeprom write protect */
  5961. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5962. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5963. GRC_LCLCTRL_GPIO_OUTPUT1);
  5964. }
  5965. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5966. udelay(100);
  5967. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5968. tp->last_tag = 0;
  5969. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5970. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5971. udelay(40);
  5972. }
  5973. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5974. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5975. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5976. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5977. WDMAC_MODE_LNGREAD_ENAB);
  5978. /* If statement applies to 5705 and 5750 PCI devices only */
  5979. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5980. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5981. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5982. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5983. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5984. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5985. /* nothing */
  5986. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5987. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5988. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5989. val |= WDMAC_MODE_RX_ACCEL;
  5990. }
  5991. }
  5992. /* Enable host coalescing bug fix */
  5993. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5994. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) ||
  5995. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784) ||
  5996. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761))
  5997. val |= (1 << 29);
  5998. tw32_f(WDMAC_MODE, val);
  5999. udelay(40);
  6000. if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  6001. u16 pcix_cmd;
  6002. pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  6003. &pcix_cmd);
  6004. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  6005. pcix_cmd &= ~PCI_X_CMD_MAX_READ;
  6006. pcix_cmd |= PCI_X_CMD_READ_2K;
  6007. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  6008. pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ);
  6009. pcix_cmd |= PCI_X_CMD_READ_2K;
  6010. }
  6011. pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  6012. pcix_cmd);
  6013. }
  6014. tw32_f(RDMAC_MODE, rdmac_mode);
  6015. udelay(40);
  6016. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  6017. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  6018. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  6019. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  6020. tw32(SNDDATAC_MODE,
  6021. SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY);
  6022. else
  6023. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  6024. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  6025. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  6026. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  6027. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  6028. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  6029. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  6030. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  6031. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  6032. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  6033. err = tg3_load_5701_a0_firmware_fix(tp);
  6034. if (err)
  6035. return err;
  6036. }
  6037. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  6038. err = tg3_load_tso_firmware(tp);
  6039. if (err)
  6040. return err;
  6041. }
  6042. tp->tx_mode = TX_MODE_ENABLE;
  6043. tw32_f(MAC_TX_MODE, tp->tx_mode);
  6044. udelay(100);
  6045. tp->rx_mode = RX_MODE_ENABLE;
  6046. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  6047. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  6048. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  6049. tw32_f(MAC_RX_MODE, tp->rx_mode);
  6050. udelay(10);
  6051. if (tp->link_config.phy_is_low_power) {
  6052. tp->link_config.phy_is_low_power = 0;
  6053. tp->link_config.speed = tp->link_config.orig_speed;
  6054. tp->link_config.duplex = tp->link_config.orig_duplex;
  6055. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  6056. }
  6057. tp->mi_mode = MAC_MI_MODE_BASE;
  6058. tw32_f(MAC_MI_MODE, tp->mi_mode);
  6059. udelay(80);
  6060. tw32(MAC_LED_CTRL, tp->led_ctrl);
  6061. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  6062. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  6063. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  6064. udelay(10);
  6065. }
  6066. tw32_f(MAC_RX_MODE, tp->rx_mode);
  6067. udelay(10);
  6068. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  6069. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  6070. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  6071. /* Set drive transmission level to 1.2V */
  6072. /* only if the signal pre-emphasis bit is not set */
  6073. val = tr32(MAC_SERDES_CFG);
  6074. val &= 0xfffff000;
  6075. val |= 0x880;
  6076. tw32(MAC_SERDES_CFG, val);
  6077. }
  6078. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  6079. tw32(MAC_SERDES_CFG, 0x616000);
  6080. }
  6081. /* Prevent chip from dropping frames when flow control
  6082. * is enabled.
  6083. */
  6084. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  6085. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  6086. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  6087. /* Use hardware link auto-negotiation */
  6088. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  6089. }
  6090. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  6091. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  6092. u32 tmp;
  6093. tmp = tr32(SERDES_RX_CTRL);
  6094. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  6095. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  6096. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  6097. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  6098. }
  6099. err = tg3_setup_phy(tp, 0);
  6100. if (err)
  6101. return err;
  6102. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6103. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  6104. u32 tmp;
  6105. /* Clear CRC stats. */
  6106. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  6107. tg3_writephy(tp, MII_TG3_TEST1,
  6108. tmp | MII_TG3_TEST1_CRC_EN);
  6109. tg3_readphy(tp, 0x14, &tmp);
  6110. }
  6111. }
  6112. __tg3_set_rx_mode(tp->dev);
  6113. /* Initialize receive rules. */
  6114. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  6115. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  6116. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  6117. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  6118. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  6119. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  6120. limit = 8;
  6121. else
  6122. limit = 16;
  6123. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  6124. limit -= 4;
  6125. switch (limit) {
  6126. case 16:
  6127. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  6128. case 15:
  6129. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  6130. case 14:
  6131. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  6132. case 13:
  6133. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  6134. case 12:
  6135. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  6136. case 11:
  6137. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  6138. case 10:
  6139. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  6140. case 9:
  6141. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  6142. case 8:
  6143. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  6144. case 7:
  6145. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  6146. case 6:
  6147. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  6148. case 5:
  6149. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  6150. case 4:
  6151. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  6152. case 3:
  6153. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  6154. case 2:
  6155. case 1:
  6156. default:
  6157. break;
  6158. };
  6159. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
  6160. /* Write our heartbeat update interval to APE. */
  6161. tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS,
  6162. APE_HOST_HEARTBEAT_INT_DISABLE);
  6163. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  6164. return 0;
  6165. }
  6166. /* Called at device open time to get the chip ready for
  6167. * packet processing. Invoked with tp->lock held.
  6168. */
  6169. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  6170. {
  6171. int err;
  6172. /* Force the chip into D0. */
  6173. err = tg3_set_power_state(tp, PCI_D0);
  6174. if (err)
  6175. goto out;
  6176. tg3_switch_clocks(tp);
  6177. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  6178. err = tg3_reset_hw(tp, reset_phy);
  6179. out:
  6180. return err;
  6181. }
  6182. #define TG3_STAT_ADD32(PSTAT, REG) \
  6183. do { u32 __val = tr32(REG); \
  6184. (PSTAT)->low += __val; \
  6185. if ((PSTAT)->low < __val) \
  6186. (PSTAT)->high += 1; \
  6187. } while (0)
  6188. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  6189. {
  6190. struct tg3_hw_stats *sp = tp->hw_stats;
  6191. if (!netif_carrier_ok(tp->dev))
  6192. return;
  6193. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  6194. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  6195. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  6196. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  6197. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  6198. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  6199. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  6200. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  6201. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  6202. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  6203. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  6204. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  6205. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  6206. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  6207. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  6208. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  6209. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  6210. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  6211. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  6212. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  6213. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  6214. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  6215. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  6216. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  6217. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  6218. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  6219. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  6220. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  6221. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  6222. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  6223. }
  6224. static void tg3_timer(unsigned long __opaque)
  6225. {
  6226. struct tg3 *tp = (struct tg3 *) __opaque;
  6227. if (tp->irq_sync)
  6228. goto restart_timer;
  6229. spin_lock(&tp->lock);
  6230. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6231. /* All of this garbage is because when using non-tagged
  6232. * IRQ status the mailbox/status_block protocol the chip
  6233. * uses with the cpu is race prone.
  6234. */
  6235. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  6236. tw32(GRC_LOCAL_CTRL,
  6237. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  6238. } else {
  6239. tw32(HOSTCC_MODE, tp->coalesce_mode |
  6240. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  6241. }
  6242. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  6243. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  6244. spin_unlock(&tp->lock);
  6245. schedule_work(&tp->reset_task);
  6246. return;
  6247. }
  6248. }
  6249. /* This part only runs once per second. */
  6250. if (!--tp->timer_counter) {
  6251. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  6252. tg3_periodic_fetch_stats(tp);
  6253. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  6254. u32 mac_stat;
  6255. int phy_event;
  6256. mac_stat = tr32(MAC_STATUS);
  6257. phy_event = 0;
  6258. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  6259. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  6260. phy_event = 1;
  6261. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  6262. phy_event = 1;
  6263. if (phy_event)
  6264. tg3_setup_phy(tp, 0);
  6265. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  6266. u32 mac_stat = tr32(MAC_STATUS);
  6267. int need_setup = 0;
  6268. if (netif_carrier_ok(tp->dev) &&
  6269. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  6270. need_setup = 1;
  6271. }
  6272. if (! netif_carrier_ok(tp->dev) &&
  6273. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  6274. MAC_STATUS_SIGNAL_DET))) {
  6275. need_setup = 1;
  6276. }
  6277. if (need_setup) {
  6278. if (!tp->serdes_counter) {
  6279. tw32_f(MAC_MODE,
  6280. (tp->mac_mode &
  6281. ~MAC_MODE_PORT_MODE_MASK));
  6282. udelay(40);
  6283. tw32_f(MAC_MODE, tp->mac_mode);
  6284. udelay(40);
  6285. }
  6286. tg3_setup_phy(tp, 0);
  6287. }
  6288. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  6289. tg3_serdes_parallel_detect(tp);
  6290. tp->timer_counter = tp->timer_multiplier;
  6291. }
  6292. /* Heartbeat is only sent once every 2 seconds.
  6293. *
  6294. * The heartbeat is to tell the ASF firmware that the host
  6295. * driver is still alive. In the event that the OS crashes,
  6296. * ASF needs to reset the hardware to free up the FIFO space
  6297. * that may be filled with rx packets destined for the host.
  6298. * If the FIFO is full, ASF will no longer function properly.
  6299. *
  6300. * Unintended resets have been reported on real time kernels
  6301. * where the timer doesn't run on time. Netpoll will also have
  6302. * same problem.
  6303. *
  6304. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  6305. * to check the ring condition when the heartbeat is expiring
  6306. * before doing the reset. This will prevent most unintended
  6307. * resets.
  6308. */
  6309. if (!--tp->asf_counter) {
  6310. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  6311. u32 val;
  6312. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  6313. FWCMD_NICDRV_ALIVE3);
  6314. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  6315. /* 5 seconds timeout */
  6316. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  6317. val = tr32(GRC_RX_CPU_EVENT);
  6318. val |= (1 << 14);
  6319. tw32(GRC_RX_CPU_EVENT, val);
  6320. }
  6321. tp->asf_counter = tp->asf_multiplier;
  6322. }
  6323. spin_unlock(&tp->lock);
  6324. restart_timer:
  6325. tp->timer.expires = jiffies + tp->timer_offset;
  6326. add_timer(&tp->timer);
  6327. }
  6328. static int tg3_request_irq(struct tg3 *tp)
  6329. {
  6330. irq_handler_t fn;
  6331. unsigned long flags;
  6332. struct net_device *dev = tp->dev;
  6333. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6334. fn = tg3_msi;
  6335. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  6336. fn = tg3_msi_1shot;
  6337. flags = IRQF_SAMPLE_RANDOM;
  6338. } else {
  6339. fn = tg3_interrupt;
  6340. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6341. fn = tg3_interrupt_tagged;
  6342. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  6343. }
  6344. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  6345. }
  6346. static int tg3_test_interrupt(struct tg3 *tp)
  6347. {
  6348. struct net_device *dev = tp->dev;
  6349. int err, i, intr_ok = 0;
  6350. if (!netif_running(dev))
  6351. return -ENODEV;
  6352. tg3_disable_ints(tp);
  6353. free_irq(tp->pdev->irq, dev);
  6354. err = request_irq(tp->pdev->irq, tg3_test_isr,
  6355. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  6356. if (err)
  6357. return err;
  6358. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  6359. tg3_enable_ints(tp);
  6360. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  6361. HOSTCC_MODE_NOW);
  6362. for (i = 0; i < 5; i++) {
  6363. u32 int_mbox, misc_host_ctrl;
  6364. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  6365. TG3_64BIT_REG_LOW);
  6366. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  6367. if ((int_mbox != 0) ||
  6368. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  6369. intr_ok = 1;
  6370. break;
  6371. }
  6372. msleep(10);
  6373. }
  6374. tg3_disable_ints(tp);
  6375. free_irq(tp->pdev->irq, dev);
  6376. err = tg3_request_irq(tp);
  6377. if (err)
  6378. return err;
  6379. if (intr_ok)
  6380. return 0;
  6381. return -EIO;
  6382. }
  6383. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  6384. * successfully restored
  6385. */
  6386. static int tg3_test_msi(struct tg3 *tp)
  6387. {
  6388. struct net_device *dev = tp->dev;
  6389. int err;
  6390. u16 pci_cmd;
  6391. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  6392. return 0;
  6393. /* Turn off SERR reporting in case MSI terminates with Master
  6394. * Abort.
  6395. */
  6396. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  6397. pci_write_config_word(tp->pdev, PCI_COMMAND,
  6398. pci_cmd & ~PCI_COMMAND_SERR);
  6399. err = tg3_test_interrupt(tp);
  6400. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  6401. if (!err)
  6402. return 0;
  6403. /* other failures */
  6404. if (err != -EIO)
  6405. return err;
  6406. /* MSI test failed, go back to INTx mode */
  6407. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  6408. "switching to INTx mode. Please report this failure to "
  6409. "the PCI maintainer and include system chipset information.\n",
  6410. tp->dev->name);
  6411. free_irq(tp->pdev->irq, dev);
  6412. pci_disable_msi(tp->pdev);
  6413. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6414. err = tg3_request_irq(tp);
  6415. if (err)
  6416. return err;
  6417. /* Need to reset the chip because the MSI cycle may have terminated
  6418. * with Master Abort.
  6419. */
  6420. tg3_full_lock(tp, 1);
  6421. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6422. err = tg3_init_hw(tp, 1);
  6423. tg3_full_unlock(tp);
  6424. if (err)
  6425. free_irq(tp->pdev->irq, dev);
  6426. return err;
  6427. }
  6428. static int tg3_open(struct net_device *dev)
  6429. {
  6430. struct tg3 *tp = netdev_priv(dev);
  6431. int err;
  6432. netif_carrier_off(tp->dev);
  6433. tg3_full_lock(tp, 0);
  6434. err = tg3_set_power_state(tp, PCI_D0);
  6435. if (err) {
  6436. tg3_full_unlock(tp);
  6437. return err;
  6438. }
  6439. tg3_disable_ints(tp);
  6440. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6441. tg3_full_unlock(tp);
  6442. /* The placement of this call is tied
  6443. * to the setup and use of Host TX descriptors.
  6444. */
  6445. err = tg3_alloc_consistent(tp);
  6446. if (err)
  6447. return err;
  6448. if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) {
  6449. /* All MSI supporting chips should support tagged
  6450. * status. Assert that this is the case.
  6451. */
  6452. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6453. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6454. "Not using MSI.\n", tp->dev->name);
  6455. } else if (pci_enable_msi(tp->pdev) == 0) {
  6456. u32 msi_mode;
  6457. msi_mode = tr32(MSGINT_MODE);
  6458. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6459. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6460. }
  6461. }
  6462. err = tg3_request_irq(tp);
  6463. if (err) {
  6464. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6465. pci_disable_msi(tp->pdev);
  6466. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6467. }
  6468. tg3_free_consistent(tp);
  6469. return err;
  6470. }
  6471. napi_enable(&tp->napi);
  6472. tg3_full_lock(tp, 0);
  6473. err = tg3_init_hw(tp, 1);
  6474. if (err) {
  6475. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6476. tg3_free_rings(tp);
  6477. } else {
  6478. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6479. tp->timer_offset = HZ;
  6480. else
  6481. tp->timer_offset = HZ / 10;
  6482. BUG_ON(tp->timer_offset > HZ);
  6483. tp->timer_counter = tp->timer_multiplier =
  6484. (HZ / tp->timer_offset);
  6485. tp->asf_counter = tp->asf_multiplier =
  6486. ((HZ / tp->timer_offset) * 2);
  6487. init_timer(&tp->timer);
  6488. tp->timer.expires = jiffies + tp->timer_offset;
  6489. tp->timer.data = (unsigned long) tp;
  6490. tp->timer.function = tg3_timer;
  6491. }
  6492. tg3_full_unlock(tp);
  6493. if (err) {
  6494. napi_disable(&tp->napi);
  6495. free_irq(tp->pdev->irq, dev);
  6496. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6497. pci_disable_msi(tp->pdev);
  6498. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6499. }
  6500. tg3_free_consistent(tp);
  6501. return err;
  6502. }
  6503. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6504. err = tg3_test_msi(tp);
  6505. if (err) {
  6506. tg3_full_lock(tp, 0);
  6507. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6508. pci_disable_msi(tp->pdev);
  6509. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6510. }
  6511. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6512. tg3_free_rings(tp);
  6513. tg3_free_consistent(tp);
  6514. tg3_full_unlock(tp);
  6515. napi_disable(&tp->napi);
  6516. return err;
  6517. }
  6518. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6519. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6520. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6521. tw32(PCIE_TRANSACTION_CFG,
  6522. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6523. }
  6524. }
  6525. }
  6526. tg3_full_lock(tp, 0);
  6527. add_timer(&tp->timer);
  6528. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6529. tg3_enable_ints(tp);
  6530. tg3_full_unlock(tp);
  6531. netif_start_queue(dev);
  6532. return 0;
  6533. }
  6534. #if 0
  6535. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6536. {
  6537. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6538. u16 val16;
  6539. int i;
  6540. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6541. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6542. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6543. val16, val32);
  6544. /* MAC block */
  6545. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6546. tr32(MAC_MODE), tr32(MAC_STATUS));
  6547. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6548. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6549. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6550. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6551. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6552. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6553. /* Send data initiator control block */
  6554. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6555. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6556. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6557. tr32(SNDDATAI_STATSCTRL));
  6558. /* Send data completion control block */
  6559. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6560. /* Send BD ring selector block */
  6561. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6562. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6563. /* Send BD initiator control block */
  6564. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6565. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6566. /* Send BD completion control block */
  6567. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6568. /* Receive list placement control block */
  6569. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6570. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6571. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6572. tr32(RCVLPC_STATSCTRL));
  6573. /* Receive data and receive BD initiator control block */
  6574. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6575. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6576. /* Receive data completion control block */
  6577. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6578. tr32(RCVDCC_MODE));
  6579. /* Receive BD initiator control block */
  6580. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6581. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6582. /* Receive BD completion control block */
  6583. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6584. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6585. /* Receive list selector control block */
  6586. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6587. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6588. /* Mbuf cluster free block */
  6589. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6590. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6591. /* Host coalescing control block */
  6592. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6593. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6594. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6595. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6596. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6597. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6598. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6599. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6600. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6601. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6602. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6603. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6604. /* Memory arbiter control block */
  6605. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6606. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6607. /* Buffer manager control block */
  6608. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6609. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6610. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6611. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6612. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6613. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6614. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6615. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6616. /* Read DMA control block */
  6617. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6618. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6619. /* Write DMA control block */
  6620. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6621. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6622. /* DMA completion block */
  6623. printk("DEBUG: DMAC_MODE[%08x]\n",
  6624. tr32(DMAC_MODE));
  6625. /* GRC block */
  6626. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6627. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6628. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6629. tr32(GRC_LOCAL_CTRL));
  6630. /* TG3_BDINFOs */
  6631. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6632. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6633. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6634. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6635. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6636. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6637. tr32(RCVDBDI_STD_BD + 0x0),
  6638. tr32(RCVDBDI_STD_BD + 0x4),
  6639. tr32(RCVDBDI_STD_BD + 0x8),
  6640. tr32(RCVDBDI_STD_BD + 0xc));
  6641. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6642. tr32(RCVDBDI_MINI_BD + 0x0),
  6643. tr32(RCVDBDI_MINI_BD + 0x4),
  6644. tr32(RCVDBDI_MINI_BD + 0x8),
  6645. tr32(RCVDBDI_MINI_BD + 0xc));
  6646. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6647. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6648. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6649. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6650. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6651. val32, val32_2, val32_3, val32_4);
  6652. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6653. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6654. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6655. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6656. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6657. val32, val32_2, val32_3, val32_4);
  6658. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6659. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6660. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6661. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6662. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6663. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6664. val32, val32_2, val32_3, val32_4, val32_5);
  6665. /* SW status block */
  6666. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6667. tp->hw_status->status,
  6668. tp->hw_status->status_tag,
  6669. tp->hw_status->rx_jumbo_consumer,
  6670. tp->hw_status->rx_consumer,
  6671. tp->hw_status->rx_mini_consumer,
  6672. tp->hw_status->idx[0].rx_producer,
  6673. tp->hw_status->idx[0].tx_consumer);
  6674. /* SW statistics block */
  6675. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6676. ((u32 *)tp->hw_stats)[0],
  6677. ((u32 *)tp->hw_stats)[1],
  6678. ((u32 *)tp->hw_stats)[2],
  6679. ((u32 *)tp->hw_stats)[3]);
  6680. /* Mailboxes */
  6681. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6682. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6683. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6684. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6685. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6686. /* NIC side send descriptors. */
  6687. for (i = 0; i < 6; i++) {
  6688. unsigned long txd;
  6689. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6690. + (i * sizeof(struct tg3_tx_buffer_desc));
  6691. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6692. i,
  6693. readl(txd + 0x0), readl(txd + 0x4),
  6694. readl(txd + 0x8), readl(txd + 0xc));
  6695. }
  6696. /* NIC side RX descriptors. */
  6697. for (i = 0; i < 6; i++) {
  6698. unsigned long rxd;
  6699. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6700. + (i * sizeof(struct tg3_rx_buffer_desc));
  6701. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6702. i,
  6703. readl(rxd + 0x0), readl(rxd + 0x4),
  6704. readl(rxd + 0x8), readl(rxd + 0xc));
  6705. rxd += (4 * sizeof(u32));
  6706. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6707. i,
  6708. readl(rxd + 0x0), readl(rxd + 0x4),
  6709. readl(rxd + 0x8), readl(rxd + 0xc));
  6710. }
  6711. for (i = 0; i < 6; i++) {
  6712. unsigned long rxd;
  6713. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6714. + (i * sizeof(struct tg3_rx_buffer_desc));
  6715. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6716. i,
  6717. readl(rxd + 0x0), readl(rxd + 0x4),
  6718. readl(rxd + 0x8), readl(rxd + 0xc));
  6719. rxd += (4 * sizeof(u32));
  6720. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6721. i,
  6722. readl(rxd + 0x0), readl(rxd + 0x4),
  6723. readl(rxd + 0x8), readl(rxd + 0xc));
  6724. }
  6725. }
  6726. #endif
  6727. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6728. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6729. static int tg3_close(struct net_device *dev)
  6730. {
  6731. struct tg3 *tp = netdev_priv(dev);
  6732. napi_disable(&tp->napi);
  6733. cancel_work_sync(&tp->reset_task);
  6734. netif_stop_queue(dev);
  6735. del_timer_sync(&tp->timer);
  6736. tg3_full_lock(tp, 1);
  6737. #if 0
  6738. tg3_dump_state(tp);
  6739. #endif
  6740. tg3_disable_ints(tp);
  6741. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6742. tg3_free_rings(tp);
  6743. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6744. tg3_full_unlock(tp);
  6745. free_irq(tp->pdev->irq, dev);
  6746. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6747. pci_disable_msi(tp->pdev);
  6748. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6749. }
  6750. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6751. sizeof(tp->net_stats_prev));
  6752. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6753. sizeof(tp->estats_prev));
  6754. tg3_free_consistent(tp);
  6755. tg3_set_power_state(tp, PCI_D3hot);
  6756. netif_carrier_off(tp->dev);
  6757. return 0;
  6758. }
  6759. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6760. {
  6761. unsigned long ret;
  6762. #if (BITS_PER_LONG == 32)
  6763. ret = val->low;
  6764. #else
  6765. ret = ((u64)val->high << 32) | ((u64)val->low);
  6766. #endif
  6767. return ret;
  6768. }
  6769. static unsigned long calc_crc_errors(struct tg3 *tp)
  6770. {
  6771. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6772. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6773. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6774. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6775. u32 val;
  6776. spin_lock_bh(&tp->lock);
  6777. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6778. tg3_writephy(tp, MII_TG3_TEST1,
  6779. val | MII_TG3_TEST1_CRC_EN);
  6780. tg3_readphy(tp, 0x14, &val);
  6781. } else
  6782. val = 0;
  6783. spin_unlock_bh(&tp->lock);
  6784. tp->phy_crc_errors += val;
  6785. return tp->phy_crc_errors;
  6786. }
  6787. return get_stat64(&hw_stats->rx_fcs_errors);
  6788. }
  6789. #define ESTAT_ADD(member) \
  6790. estats->member = old_estats->member + \
  6791. get_stat64(&hw_stats->member)
  6792. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6793. {
  6794. struct tg3_ethtool_stats *estats = &tp->estats;
  6795. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6796. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6797. if (!hw_stats)
  6798. return old_estats;
  6799. ESTAT_ADD(rx_octets);
  6800. ESTAT_ADD(rx_fragments);
  6801. ESTAT_ADD(rx_ucast_packets);
  6802. ESTAT_ADD(rx_mcast_packets);
  6803. ESTAT_ADD(rx_bcast_packets);
  6804. ESTAT_ADD(rx_fcs_errors);
  6805. ESTAT_ADD(rx_align_errors);
  6806. ESTAT_ADD(rx_xon_pause_rcvd);
  6807. ESTAT_ADD(rx_xoff_pause_rcvd);
  6808. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6809. ESTAT_ADD(rx_xoff_entered);
  6810. ESTAT_ADD(rx_frame_too_long_errors);
  6811. ESTAT_ADD(rx_jabbers);
  6812. ESTAT_ADD(rx_undersize_packets);
  6813. ESTAT_ADD(rx_in_length_errors);
  6814. ESTAT_ADD(rx_out_length_errors);
  6815. ESTAT_ADD(rx_64_or_less_octet_packets);
  6816. ESTAT_ADD(rx_65_to_127_octet_packets);
  6817. ESTAT_ADD(rx_128_to_255_octet_packets);
  6818. ESTAT_ADD(rx_256_to_511_octet_packets);
  6819. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6820. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6821. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6822. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6823. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6824. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6825. ESTAT_ADD(tx_octets);
  6826. ESTAT_ADD(tx_collisions);
  6827. ESTAT_ADD(tx_xon_sent);
  6828. ESTAT_ADD(tx_xoff_sent);
  6829. ESTAT_ADD(tx_flow_control);
  6830. ESTAT_ADD(tx_mac_errors);
  6831. ESTAT_ADD(tx_single_collisions);
  6832. ESTAT_ADD(tx_mult_collisions);
  6833. ESTAT_ADD(tx_deferred);
  6834. ESTAT_ADD(tx_excessive_collisions);
  6835. ESTAT_ADD(tx_late_collisions);
  6836. ESTAT_ADD(tx_collide_2times);
  6837. ESTAT_ADD(tx_collide_3times);
  6838. ESTAT_ADD(tx_collide_4times);
  6839. ESTAT_ADD(tx_collide_5times);
  6840. ESTAT_ADD(tx_collide_6times);
  6841. ESTAT_ADD(tx_collide_7times);
  6842. ESTAT_ADD(tx_collide_8times);
  6843. ESTAT_ADD(tx_collide_9times);
  6844. ESTAT_ADD(tx_collide_10times);
  6845. ESTAT_ADD(tx_collide_11times);
  6846. ESTAT_ADD(tx_collide_12times);
  6847. ESTAT_ADD(tx_collide_13times);
  6848. ESTAT_ADD(tx_collide_14times);
  6849. ESTAT_ADD(tx_collide_15times);
  6850. ESTAT_ADD(tx_ucast_packets);
  6851. ESTAT_ADD(tx_mcast_packets);
  6852. ESTAT_ADD(tx_bcast_packets);
  6853. ESTAT_ADD(tx_carrier_sense_errors);
  6854. ESTAT_ADD(tx_discards);
  6855. ESTAT_ADD(tx_errors);
  6856. ESTAT_ADD(dma_writeq_full);
  6857. ESTAT_ADD(dma_write_prioq_full);
  6858. ESTAT_ADD(rxbds_empty);
  6859. ESTAT_ADD(rx_discards);
  6860. ESTAT_ADD(rx_errors);
  6861. ESTAT_ADD(rx_threshold_hit);
  6862. ESTAT_ADD(dma_readq_full);
  6863. ESTAT_ADD(dma_read_prioq_full);
  6864. ESTAT_ADD(tx_comp_queue_full);
  6865. ESTAT_ADD(ring_set_send_prod_index);
  6866. ESTAT_ADD(ring_status_update);
  6867. ESTAT_ADD(nic_irqs);
  6868. ESTAT_ADD(nic_avoided_irqs);
  6869. ESTAT_ADD(nic_tx_threshold_hit);
  6870. return estats;
  6871. }
  6872. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6873. {
  6874. struct tg3 *tp = netdev_priv(dev);
  6875. struct net_device_stats *stats = &tp->net_stats;
  6876. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6877. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6878. if (!hw_stats)
  6879. return old_stats;
  6880. stats->rx_packets = old_stats->rx_packets +
  6881. get_stat64(&hw_stats->rx_ucast_packets) +
  6882. get_stat64(&hw_stats->rx_mcast_packets) +
  6883. get_stat64(&hw_stats->rx_bcast_packets);
  6884. stats->tx_packets = old_stats->tx_packets +
  6885. get_stat64(&hw_stats->tx_ucast_packets) +
  6886. get_stat64(&hw_stats->tx_mcast_packets) +
  6887. get_stat64(&hw_stats->tx_bcast_packets);
  6888. stats->rx_bytes = old_stats->rx_bytes +
  6889. get_stat64(&hw_stats->rx_octets);
  6890. stats->tx_bytes = old_stats->tx_bytes +
  6891. get_stat64(&hw_stats->tx_octets);
  6892. stats->rx_errors = old_stats->rx_errors +
  6893. get_stat64(&hw_stats->rx_errors);
  6894. stats->tx_errors = old_stats->tx_errors +
  6895. get_stat64(&hw_stats->tx_errors) +
  6896. get_stat64(&hw_stats->tx_mac_errors) +
  6897. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6898. get_stat64(&hw_stats->tx_discards);
  6899. stats->multicast = old_stats->multicast +
  6900. get_stat64(&hw_stats->rx_mcast_packets);
  6901. stats->collisions = old_stats->collisions +
  6902. get_stat64(&hw_stats->tx_collisions);
  6903. stats->rx_length_errors = old_stats->rx_length_errors +
  6904. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6905. get_stat64(&hw_stats->rx_undersize_packets);
  6906. stats->rx_over_errors = old_stats->rx_over_errors +
  6907. get_stat64(&hw_stats->rxbds_empty);
  6908. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6909. get_stat64(&hw_stats->rx_align_errors);
  6910. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6911. get_stat64(&hw_stats->tx_discards);
  6912. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6913. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6914. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6915. calc_crc_errors(tp);
  6916. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6917. get_stat64(&hw_stats->rx_discards);
  6918. return stats;
  6919. }
  6920. static inline u32 calc_crc(unsigned char *buf, int len)
  6921. {
  6922. u32 reg;
  6923. u32 tmp;
  6924. int j, k;
  6925. reg = 0xffffffff;
  6926. for (j = 0; j < len; j++) {
  6927. reg ^= buf[j];
  6928. for (k = 0; k < 8; k++) {
  6929. tmp = reg & 0x01;
  6930. reg >>= 1;
  6931. if (tmp) {
  6932. reg ^= 0xedb88320;
  6933. }
  6934. }
  6935. }
  6936. return ~reg;
  6937. }
  6938. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6939. {
  6940. /* accept or reject all multicast frames */
  6941. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6942. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6943. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6944. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6945. }
  6946. static void __tg3_set_rx_mode(struct net_device *dev)
  6947. {
  6948. struct tg3 *tp = netdev_priv(dev);
  6949. u32 rx_mode;
  6950. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6951. RX_MODE_KEEP_VLAN_TAG);
  6952. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6953. * flag clear.
  6954. */
  6955. #if TG3_VLAN_TAG_USED
  6956. if (!tp->vlgrp &&
  6957. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6958. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6959. #else
  6960. /* By definition, VLAN is disabled always in this
  6961. * case.
  6962. */
  6963. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6964. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6965. #endif
  6966. if (dev->flags & IFF_PROMISC) {
  6967. /* Promiscuous mode. */
  6968. rx_mode |= RX_MODE_PROMISC;
  6969. } else if (dev->flags & IFF_ALLMULTI) {
  6970. /* Accept all multicast. */
  6971. tg3_set_multi (tp, 1);
  6972. } else if (dev->mc_count < 1) {
  6973. /* Reject all multicast. */
  6974. tg3_set_multi (tp, 0);
  6975. } else {
  6976. /* Accept one or more multicast(s). */
  6977. struct dev_mc_list *mclist;
  6978. unsigned int i;
  6979. u32 mc_filter[4] = { 0, };
  6980. u32 regidx;
  6981. u32 bit;
  6982. u32 crc;
  6983. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6984. i++, mclist = mclist->next) {
  6985. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6986. bit = ~crc & 0x7f;
  6987. regidx = (bit & 0x60) >> 5;
  6988. bit &= 0x1f;
  6989. mc_filter[regidx] |= (1 << bit);
  6990. }
  6991. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6992. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6993. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6994. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6995. }
  6996. if (rx_mode != tp->rx_mode) {
  6997. tp->rx_mode = rx_mode;
  6998. tw32_f(MAC_RX_MODE, rx_mode);
  6999. udelay(10);
  7000. }
  7001. }
  7002. static void tg3_set_rx_mode(struct net_device *dev)
  7003. {
  7004. struct tg3 *tp = netdev_priv(dev);
  7005. if (!netif_running(dev))
  7006. return;
  7007. tg3_full_lock(tp, 0);
  7008. __tg3_set_rx_mode(dev);
  7009. tg3_full_unlock(tp);
  7010. }
  7011. #define TG3_REGDUMP_LEN (32 * 1024)
  7012. static int tg3_get_regs_len(struct net_device *dev)
  7013. {
  7014. return TG3_REGDUMP_LEN;
  7015. }
  7016. static void tg3_get_regs(struct net_device *dev,
  7017. struct ethtool_regs *regs, void *_p)
  7018. {
  7019. u32 *p = _p;
  7020. struct tg3 *tp = netdev_priv(dev);
  7021. u8 *orig_p = _p;
  7022. int i;
  7023. regs->version = 0;
  7024. memset(p, 0, TG3_REGDUMP_LEN);
  7025. if (tp->link_config.phy_is_low_power)
  7026. return;
  7027. tg3_full_lock(tp, 0);
  7028. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  7029. #define GET_REG32_LOOP(base,len) \
  7030. do { p = (u32 *)(orig_p + (base)); \
  7031. for (i = 0; i < len; i += 4) \
  7032. __GET_REG32((base) + i); \
  7033. } while (0)
  7034. #define GET_REG32_1(reg) \
  7035. do { p = (u32 *)(orig_p + (reg)); \
  7036. __GET_REG32((reg)); \
  7037. } while (0)
  7038. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  7039. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  7040. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  7041. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  7042. GET_REG32_1(SNDDATAC_MODE);
  7043. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  7044. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  7045. GET_REG32_1(SNDBDC_MODE);
  7046. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  7047. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  7048. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  7049. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  7050. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  7051. GET_REG32_1(RCVDCC_MODE);
  7052. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  7053. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  7054. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  7055. GET_REG32_1(MBFREE_MODE);
  7056. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  7057. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  7058. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  7059. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  7060. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  7061. GET_REG32_1(RX_CPU_MODE);
  7062. GET_REG32_1(RX_CPU_STATE);
  7063. GET_REG32_1(RX_CPU_PGMCTR);
  7064. GET_REG32_1(RX_CPU_HWBKPT);
  7065. GET_REG32_1(TX_CPU_MODE);
  7066. GET_REG32_1(TX_CPU_STATE);
  7067. GET_REG32_1(TX_CPU_PGMCTR);
  7068. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  7069. GET_REG32_LOOP(FTQ_RESET, 0x120);
  7070. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  7071. GET_REG32_1(DMAC_MODE);
  7072. GET_REG32_LOOP(GRC_MODE, 0x4c);
  7073. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  7074. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  7075. #undef __GET_REG32
  7076. #undef GET_REG32_LOOP
  7077. #undef GET_REG32_1
  7078. tg3_full_unlock(tp);
  7079. }
  7080. static int tg3_get_eeprom_len(struct net_device *dev)
  7081. {
  7082. struct tg3 *tp = netdev_priv(dev);
  7083. return tp->nvram_size;
  7084. }
  7085. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  7086. static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val);
  7087. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  7088. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  7089. {
  7090. struct tg3 *tp = netdev_priv(dev);
  7091. int ret;
  7092. u8 *pd;
  7093. u32 i, offset, len, b_offset, b_count;
  7094. __le32 val;
  7095. if (tp->link_config.phy_is_low_power)
  7096. return -EAGAIN;
  7097. offset = eeprom->offset;
  7098. len = eeprom->len;
  7099. eeprom->len = 0;
  7100. eeprom->magic = TG3_EEPROM_MAGIC;
  7101. if (offset & 3) {
  7102. /* adjustments to start on required 4 byte boundary */
  7103. b_offset = offset & 3;
  7104. b_count = 4 - b_offset;
  7105. if (b_count > len) {
  7106. /* i.e. offset=1 len=2 */
  7107. b_count = len;
  7108. }
  7109. ret = tg3_nvram_read_le(tp, offset-b_offset, &val);
  7110. if (ret)
  7111. return ret;
  7112. memcpy(data, ((char*)&val) + b_offset, b_count);
  7113. len -= b_count;
  7114. offset += b_count;
  7115. eeprom->len += b_count;
  7116. }
  7117. /* read bytes upto the last 4 byte boundary */
  7118. pd = &data[eeprom->len];
  7119. for (i = 0; i < (len - (len & 3)); i += 4) {
  7120. ret = tg3_nvram_read_le(tp, offset + i, &val);
  7121. if (ret) {
  7122. eeprom->len += i;
  7123. return ret;
  7124. }
  7125. memcpy(pd + i, &val, 4);
  7126. }
  7127. eeprom->len += i;
  7128. if (len & 3) {
  7129. /* read last bytes not ending on 4 byte boundary */
  7130. pd = &data[eeprom->len];
  7131. b_count = len & 3;
  7132. b_offset = offset + len - b_count;
  7133. ret = tg3_nvram_read_le(tp, b_offset, &val);
  7134. if (ret)
  7135. return ret;
  7136. memcpy(pd, &val, b_count);
  7137. eeprom->len += b_count;
  7138. }
  7139. return 0;
  7140. }
  7141. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  7142. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  7143. {
  7144. struct tg3 *tp = netdev_priv(dev);
  7145. int ret;
  7146. u32 offset, len, b_offset, odd_len;
  7147. u8 *buf;
  7148. __le32 start, end;
  7149. if (tp->link_config.phy_is_low_power)
  7150. return -EAGAIN;
  7151. if (eeprom->magic != TG3_EEPROM_MAGIC)
  7152. return -EINVAL;
  7153. offset = eeprom->offset;
  7154. len = eeprom->len;
  7155. if ((b_offset = (offset & 3))) {
  7156. /* adjustments to start on required 4 byte boundary */
  7157. ret = tg3_nvram_read_le(tp, offset-b_offset, &start);
  7158. if (ret)
  7159. return ret;
  7160. len += b_offset;
  7161. offset &= ~3;
  7162. if (len < 4)
  7163. len = 4;
  7164. }
  7165. odd_len = 0;
  7166. if (len & 3) {
  7167. /* adjustments to end on required 4 byte boundary */
  7168. odd_len = 1;
  7169. len = (len + 3) & ~3;
  7170. ret = tg3_nvram_read_le(tp, offset+len-4, &end);
  7171. if (ret)
  7172. return ret;
  7173. }
  7174. buf = data;
  7175. if (b_offset || odd_len) {
  7176. buf = kmalloc(len, GFP_KERNEL);
  7177. if (!buf)
  7178. return -ENOMEM;
  7179. if (b_offset)
  7180. memcpy(buf, &start, 4);
  7181. if (odd_len)
  7182. memcpy(buf+len-4, &end, 4);
  7183. memcpy(buf + b_offset, data, eeprom->len);
  7184. }
  7185. ret = tg3_nvram_write_block(tp, offset, len, buf);
  7186. if (buf != data)
  7187. kfree(buf);
  7188. return ret;
  7189. }
  7190. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7191. {
  7192. struct tg3 *tp = netdev_priv(dev);
  7193. cmd->supported = (SUPPORTED_Autoneg);
  7194. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  7195. cmd->supported |= (SUPPORTED_1000baseT_Half |
  7196. SUPPORTED_1000baseT_Full);
  7197. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  7198. cmd->supported |= (SUPPORTED_100baseT_Half |
  7199. SUPPORTED_100baseT_Full |
  7200. SUPPORTED_10baseT_Half |
  7201. SUPPORTED_10baseT_Full |
  7202. SUPPORTED_TP);
  7203. cmd->port = PORT_TP;
  7204. } else {
  7205. cmd->supported |= SUPPORTED_FIBRE;
  7206. cmd->port = PORT_FIBRE;
  7207. }
  7208. cmd->advertising = tp->link_config.advertising;
  7209. if (netif_running(dev)) {
  7210. cmd->speed = tp->link_config.active_speed;
  7211. cmd->duplex = tp->link_config.active_duplex;
  7212. }
  7213. cmd->phy_address = PHY_ADDR;
  7214. cmd->transceiver = 0;
  7215. cmd->autoneg = tp->link_config.autoneg;
  7216. cmd->maxtxpkt = 0;
  7217. cmd->maxrxpkt = 0;
  7218. return 0;
  7219. }
  7220. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7221. {
  7222. struct tg3 *tp = netdev_priv(dev);
  7223. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  7224. /* These are the only valid advertisement bits allowed. */
  7225. if (cmd->autoneg == AUTONEG_ENABLE &&
  7226. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  7227. ADVERTISED_1000baseT_Full |
  7228. ADVERTISED_Autoneg |
  7229. ADVERTISED_FIBRE)))
  7230. return -EINVAL;
  7231. /* Fiber can only do SPEED_1000. */
  7232. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  7233. (cmd->speed != SPEED_1000))
  7234. return -EINVAL;
  7235. /* Copper cannot force SPEED_1000. */
  7236. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  7237. (cmd->speed == SPEED_1000))
  7238. return -EINVAL;
  7239. else if ((cmd->speed == SPEED_1000) &&
  7240. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  7241. return -EINVAL;
  7242. tg3_full_lock(tp, 0);
  7243. tp->link_config.autoneg = cmd->autoneg;
  7244. if (cmd->autoneg == AUTONEG_ENABLE) {
  7245. tp->link_config.advertising = (cmd->advertising |
  7246. ADVERTISED_Autoneg);
  7247. tp->link_config.speed = SPEED_INVALID;
  7248. tp->link_config.duplex = DUPLEX_INVALID;
  7249. } else {
  7250. tp->link_config.advertising = 0;
  7251. tp->link_config.speed = cmd->speed;
  7252. tp->link_config.duplex = cmd->duplex;
  7253. }
  7254. tp->link_config.orig_speed = tp->link_config.speed;
  7255. tp->link_config.orig_duplex = tp->link_config.duplex;
  7256. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  7257. if (netif_running(dev))
  7258. tg3_setup_phy(tp, 1);
  7259. tg3_full_unlock(tp);
  7260. return 0;
  7261. }
  7262. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  7263. {
  7264. struct tg3 *tp = netdev_priv(dev);
  7265. strcpy(info->driver, DRV_MODULE_NAME);
  7266. strcpy(info->version, DRV_MODULE_VERSION);
  7267. strcpy(info->fw_version, tp->fw_ver);
  7268. strcpy(info->bus_info, pci_name(tp->pdev));
  7269. }
  7270. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7271. {
  7272. struct tg3 *tp = netdev_priv(dev);
  7273. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  7274. wol->supported = WAKE_MAGIC;
  7275. else
  7276. wol->supported = 0;
  7277. wol->wolopts = 0;
  7278. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  7279. wol->wolopts = WAKE_MAGIC;
  7280. memset(&wol->sopass, 0, sizeof(wol->sopass));
  7281. }
  7282. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7283. {
  7284. struct tg3 *tp = netdev_priv(dev);
  7285. if (wol->wolopts & ~WAKE_MAGIC)
  7286. return -EINVAL;
  7287. if ((wol->wolopts & WAKE_MAGIC) &&
  7288. !(tp->tg3_flags & TG3_FLAG_WOL_CAP))
  7289. return -EINVAL;
  7290. spin_lock_bh(&tp->lock);
  7291. if (wol->wolopts & WAKE_MAGIC)
  7292. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  7293. else
  7294. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  7295. spin_unlock_bh(&tp->lock);
  7296. return 0;
  7297. }
  7298. static u32 tg3_get_msglevel(struct net_device *dev)
  7299. {
  7300. struct tg3 *tp = netdev_priv(dev);
  7301. return tp->msg_enable;
  7302. }
  7303. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  7304. {
  7305. struct tg3 *tp = netdev_priv(dev);
  7306. tp->msg_enable = value;
  7307. }
  7308. static int tg3_set_tso(struct net_device *dev, u32 value)
  7309. {
  7310. struct tg3 *tp = netdev_priv(dev);
  7311. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  7312. if (value)
  7313. return -EINVAL;
  7314. return 0;
  7315. }
  7316. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  7317. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  7318. if (value) {
  7319. dev->features |= NETIF_F_TSO6;
  7320. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7321. dev->features |= NETIF_F_TSO_ECN;
  7322. } else
  7323. dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN);
  7324. }
  7325. return ethtool_op_set_tso(dev, value);
  7326. }
  7327. static int tg3_nway_reset(struct net_device *dev)
  7328. {
  7329. struct tg3 *tp = netdev_priv(dev);
  7330. u32 bmcr;
  7331. int r;
  7332. if (!netif_running(dev))
  7333. return -EAGAIN;
  7334. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7335. return -EINVAL;
  7336. spin_lock_bh(&tp->lock);
  7337. r = -EINVAL;
  7338. tg3_readphy(tp, MII_BMCR, &bmcr);
  7339. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  7340. ((bmcr & BMCR_ANENABLE) ||
  7341. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  7342. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  7343. BMCR_ANENABLE);
  7344. r = 0;
  7345. }
  7346. spin_unlock_bh(&tp->lock);
  7347. return r;
  7348. }
  7349. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  7350. {
  7351. struct tg3 *tp = netdev_priv(dev);
  7352. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  7353. ering->rx_mini_max_pending = 0;
  7354. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  7355. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  7356. else
  7357. ering->rx_jumbo_max_pending = 0;
  7358. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  7359. ering->rx_pending = tp->rx_pending;
  7360. ering->rx_mini_pending = 0;
  7361. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  7362. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  7363. else
  7364. ering->rx_jumbo_pending = 0;
  7365. ering->tx_pending = tp->tx_pending;
  7366. }
  7367. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  7368. {
  7369. struct tg3 *tp = netdev_priv(dev);
  7370. int irq_sync = 0, err = 0;
  7371. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  7372. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  7373. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  7374. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  7375. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  7376. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  7377. return -EINVAL;
  7378. if (netif_running(dev)) {
  7379. tg3_netif_stop(tp);
  7380. irq_sync = 1;
  7381. }
  7382. tg3_full_lock(tp, irq_sync);
  7383. tp->rx_pending = ering->rx_pending;
  7384. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  7385. tp->rx_pending > 63)
  7386. tp->rx_pending = 63;
  7387. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  7388. tp->tx_pending = ering->tx_pending;
  7389. if (netif_running(dev)) {
  7390. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7391. err = tg3_restart_hw(tp, 1);
  7392. if (!err)
  7393. tg3_netif_start(tp);
  7394. }
  7395. tg3_full_unlock(tp);
  7396. return err;
  7397. }
  7398. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7399. {
  7400. struct tg3 *tp = netdev_priv(dev);
  7401. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  7402. if (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX)
  7403. epause->rx_pause = 1;
  7404. else
  7405. epause->rx_pause = 0;
  7406. if (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_TX)
  7407. epause->tx_pause = 1;
  7408. else
  7409. epause->tx_pause = 0;
  7410. }
  7411. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7412. {
  7413. struct tg3 *tp = netdev_priv(dev);
  7414. int irq_sync = 0, err = 0;
  7415. if (netif_running(dev)) {
  7416. tg3_netif_stop(tp);
  7417. irq_sync = 1;
  7418. }
  7419. tg3_full_lock(tp, irq_sync);
  7420. if (epause->autoneg)
  7421. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  7422. else
  7423. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  7424. if (epause->rx_pause)
  7425. tp->link_config.flowctrl |= TG3_FLOW_CTRL_RX;
  7426. else
  7427. tp->link_config.flowctrl &= ~TG3_FLOW_CTRL_RX;
  7428. if (epause->tx_pause)
  7429. tp->link_config.flowctrl |= TG3_FLOW_CTRL_TX;
  7430. else
  7431. tp->link_config.flowctrl &= ~TG3_FLOW_CTRL_TX;
  7432. if (netif_running(dev)) {
  7433. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7434. err = tg3_restart_hw(tp, 1);
  7435. if (!err)
  7436. tg3_netif_start(tp);
  7437. }
  7438. tg3_full_unlock(tp);
  7439. return err;
  7440. }
  7441. static u32 tg3_get_rx_csum(struct net_device *dev)
  7442. {
  7443. struct tg3 *tp = netdev_priv(dev);
  7444. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  7445. }
  7446. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  7447. {
  7448. struct tg3 *tp = netdev_priv(dev);
  7449. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7450. if (data != 0)
  7451. return -EINVAL;
  7452. return 0;
  7453. }
  7454. spin_lock_bh(&tp->lock);
  7455. if (data)
  7456. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7457. else
  7458. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7459. spin_unlock_bh(&tp->lock);
  7460. return 0;
  7461. }
  7462. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7463. {
  7464. struct tg3 *tp = netdev_priv(dev);
  7465. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7466. if (data != 0)
  7467. return -EINVAL;
  7468. return 0;
  7469. }
  7470. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7471. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  7472. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  7473. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7474. ethtool_op_set_tx_ipv6_csum(dev, data);
  7475. else
  7476. ethtool_op_set_tx_csum(dev, data);
  7477. return 0;
  7478. }
  7479. static int tg3_get_sset_count (struct net_device *dev, int sset)
  7480. {
  7481. switch (sset) {
  7482. case ETH_SS_TEST:
  7483. return TG3_NUM_TEST;
  7484. case ETH_SS_STATS:
  7485. return TG3_NUM_STATS;
  7486. default:
  7487. return -EOPNOTSUPP;
  7488. }
  7489. }
  7490. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7491. {
  7492. switch (stringset) {
  7493. case ETH_SS_STATS:
  7494. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7495. break;
  7496. case ETH_SS_TEST:
  7497. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7498. break;
  7499. default:
  7500. WARN_ON(1); /* we need a WARN() */
  7501. break;
  7502. }
  7503. }
  7504. static int tg3_phys_id(struct net_device *dev, u32 data)
  7505. {
  7506. struct tg3 *tp = netdev_priv(dev);
  7507. int i;
  7508. if (!netif_running(tp->dev))
  7509. return -EAGAIN;
  7510. if (data == 0)
  7511. data = UINT_MAX / 2;
  7512. for (i = 0; i < (data * 2); i++) {
  7513. if ((i % 2) == 0)
  7514. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7515. LED_CTRL_1000MBPS_ON |
  7516. LED_CTRL_100MBPS_ON |
  7517. LED_CTRL_10MBPS_ON |
  7518. LED_CTRL_TRAFFIC_OVERRIDE |
  7519. LED_CTRL_TRAFFIC_BLINK |
  7520. LED_CTRL_TRAFFIC_LED);
  7521. else
  7522. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7523. LED_CTRL_TRAFFIC_OVERRIDE);
  7524. if (msleep_interruptible(500))
  7525. break;
  7526. }
  7527. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7528. return 0;
  7529. }
  7530. static void tg3_get_ethtool_stats (struct net_device *dev,
  7531. struct ethtool_stats *estats, u64 *tmp_stats)
  7532. {
  7533. struct tg3 *tp = netdev_priv(dev);
  7534. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7535. }
  7536. #define NVRAM_TEST_SIZE 0x100
  7537. #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14
  7538. #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18
  7539. #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c
  7540. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7541. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7542. static int tg3_test_nvram(struct tg3 *tp)
  7543. {
  7544. u32 csum, magic;
  7545. __le32 *buf;
  7546. int i, j, k, err = 0, size;
  7547. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7548. return -EIO;
  7549. if (magic == TG3_EEPROM_MAGIC)
  7550. size = NVRAM_TEST_SIZE;
  7551. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7552. if ((magic & TG3_EEPROM_SB_FORMAT_MASK) ==
  7553. TG3_EEPROM_SB_FORMAT_1) {
  7554. switch (magic & TG3_EEPROM_SB_REVISION_MASK) {
  7555. case TG3_EEPROM_SB_REVISION_0:
  7556. size = NVRAM_SELFBOOT_FORMAT1_0_SIZE;
  7557. break;
  7558. case TG3_EEPROM_SB_REVISION_2:
  7559. size = NVRAM_SELFBOOT_FORMAT1_2_SIZE;
  7560. break;
  7561. case TG3_EEPROM_SB_REVISION_3:
  7562. size = NVRAM_SELFBOOT_FORMAT1_3_SIZE;
  7563. break;
  7564. default:
  7565. return 0;
  7566. }
  7567. } else
  7568. return 0;
  7569. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7570. size = NVRAM_SELFBOOT_HW_SIZE;
  7571. else
  7572. return -EIO;
  7573. buf = kmalloc(size, GFP_KERNEL);
  7574. if (buf == NULL)
  7575. return -ENOMEM;
  7576. err = -EIO;
  7577. for (i = 0, j = 0; i < size; i += 4, j++) {
  7578. if ((err = tg3_nvram_read_le(tp, i, &buf[j])) != 0)
  7579. break;
  7580. }
  7581. if (i < size)
  7582. goto out;
  7583. /* Selfboot format */
  7584. magic = swab32(le32_to_cpu(buf[0]));
  7585. if ((magic & TG3_EEPROM_MAGIC_FW_MSK) ==
  7586. TG3_EEPROM_MAGIC_FW) {
  7587. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7588. if ((magic & TG3_EEPROM_SB_REVISION_MASK) ==
  7589. TG3_EEPROM_SB_REVISION_2) {
  7590. /* For rev 2, the csum doesn't include the MBA. */
  7591. for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++)
  7592. csum8 += buf8[i];
  7593. for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++)
  7594. csum8 += buf8[i];
  7595. } else {
  7596. for (i = 0; i < size; i++)
  7597. csum8 += buf8[i];
  7598. }
  7599. if (csum8 == 0) {
  7600. err = 0;
  7601. goto out;
  7602. }
  7603. err = -EIO;
  7604. goto out;
  7605. }
  7606. if ((magic & TG3_EEPROM_MAGIC_HW_MSK) ==
  7607. TG3_EEPROM_MAGIC_HW) {
  7608. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7609. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7610. u8 *buf8 = (u8 *) buf;
  7611. /* Separate the parity bits and the data bytes. */
  7612. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7613. if ((i == 0) || (i == 8)) {
  7614. int l;
  7615. u8 msk;
  7616. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7617. parity[k++] = buf8[i] & msk;
  7618. i++;
  7619. }
  7620. else if (i == 16) {
  7621. int l;
  7622. u8 msk;
  7623. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7624. parity[k++] = buf8[i] & msk;
  7625. i++;
  7626. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7627. parity[k++] = buf8[i] & msk;
  7628. i++;
  7629. }
  7630. data[j++] = buf8[i];
  7631. }
  7632. err = -EIO;
  7633. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7634. u8 hw8 = hweight8(data[i]);
  7635. if ((hw8 & 0x1) && parity[i])
  7636. goto out;
  7637. else if (!(hw8 & 0x1) && !parity[i])
  7638. goto out;
  7639. }
  7640. err = 0;
  7641. goto out;
  7642. }
  7643. /* Bootstrap checksum at offset 0x10 */
  7644. csum = calc_crc((unsigned char *) buf, 0x10);
  7645. if(csum != le32_to_cpu(buf[0x10/4]))
  7646. goto out;
  7647. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7648. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7649. if (csum != le32_to_cpu(buf[0xfc/4]))
  7650. goto out;
  7651. err = 0;
  7652. out:
  7653. kfree(buf);
  7654. return err;
  7655. }
  7656. #define TG3_SERDES_TIMEOUT_SEC 2
  7657. #define TG3_COPPER_TIMEOUT_SEC 6
  7658. static int tg3_test_link(struct tg3 *tp)
  7659. {
  7660. int i, max;
  7661. if (!netif_running(tp->dev))
  7662. return -ENODEV;
  7663. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7664. max = TG3_SERDES_TIMEOUT_SEC;
  7665. else
  7666. max = TG3_COPPER_TIMEOUT_SEC;
  7667. for (i = 0; i < max; i++) {
  7668. if (netif_carrier_ok(tp->dev))
  7669. return 0;
  7670. if (msleep_interruptible(1000))
  7671. break;
  7672. }
  7673. return -EIO;
  7674. }
  7675. /* Only test the commonly used registers */
  7676. static int tg3_test_registers(struct tg3 *tp)
  7677. {
  7678. int i, is_5705, is_5750;
  7679. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7680. static struct {
  7681. u16 offset;
  7682. u16 flags;
  7683. #define TG3_FL_5705 0x1
  7684. #define TG3_FL_NOT_5705 0x2
  7685. #define TG3_FL_NOT_5788 0x4
  7686. #define TG3_FL_NOT_5750 0x8
  7687. u32 read_mask;
  7688. u32 write_mask;
  7689. } reg_tbl[] = {
  7690. /* MAC Control Registers */
  7691. { MAC_MODE, TG3_FL_NOT_5705,
  7692. 0x00000000, 0x00ef6f8c },
  7693. { MAC_MODE, TG3_FL_5705,
  7694. 0x00000000, 0x01ef6b8c },
  7695. { MAC_STATUS, TG3_FL_NOT_5705,
  7696. 0x03800107, 0x00000000 },
  7697. { MAC_STATUS, TG3_FL_5705,
  7698. 0x03800100, 0x00000000 },
  7699. { MAC_ADDR_0_HIGH, 0x0000,
  7700. 0x00000000, 0x0000ffff },
  7701. { MAC_ADDR_0_LOW, 0x0000,
  7702. 0x00000000, 0xffffffff },
  7703. { MAC_RX_MTU_SIZE, 0x0000,
  7704. 0x00000000, 0x0000ffff },
  7705. { MAC_TX_MODE, 0x0000,
  7706. 0x00000000, 0x00000070 },
  7707. { MAC_TX_LENGTHS, 0x0000,
  7708. 0x00000000, 0x00003fff },
  7709. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7710. 0x00000000, 0x000007fc },
  7711. { MAC_RX_MODE, TG3_FL_5705,
  7712. 0x00000000, 0x000007dc },
  7713. { MAC_HASH_REG_0, 0x0000,
  7714. 0x00000000, 0xffffffff },
  7715. { MAC_HASH_REG_1, 0x0000,
  7716. 0x00000000, 0xffffffff },
  7717. { MAC_HASH_REG_2, 0x0000,
  7718. 0x00000000, 0xffffffff },
  7719. { MAC_HASH_REG_3, 0x0000,
  7720. 0x00000000, 0xffffffff },
  7721. /* Receive Data and Receive BD Initiator Control Registers. */
  7722. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7723. 0x00000000, 0xffffffff },
  7724. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7725. 0x00000000, 0xffffffff },
  7726. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7727. 0x00000000, 0x00000003 },
  7728. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7729. 0x00000000, 0xffffffff },
  7730. { RCVDBDI_STD_BD+0, 0x0000,
  7731. 0x00000000, 0xffffffff },
  7732. { RCVDBDI_STD_BD+4, 0x0000,
  7733. 0x00000000, 0xffffffff },
  7734. { RCVDBDI_STD_BD+8, 0x0000,
  7735. 0x00000000, 0xffff0002 },
  7736. { RCVDBDI_STD_BD+0xc, 0x0000,
  7737. 0x00000000, 0xffffffff },
  7738. /* Receive BD Initiator Control Registers. */
  7739. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7740. 0x00000000, 0xffffffff },
  7741. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7742. 0x00000000, 0x000003ff },
  7743. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7744. 0x00000000, 0xffffffff },
  7745. /* Host Coalescing Control Registers. */
  7746. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7747. 0x00000000, 0x00000004 },
  7748. { HOSTCC_MODE, TG3_FL_5705,
  7749. 0x00000000, 0x000000f6 },
  7750. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7751. 0x00000000, 0xffffffff },
  7752. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7753. 0x00000000, 0x000003ff },
  7754. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7755. 0x00000000, 0xffffffff },
  7756. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7757. 0x00000000, 0x000003ff },
  7758. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7759. 0x00000000, 0xffffffff },
  7760. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7761. 0x00000000, 0x000000ff },
  7762. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7763. 0x00000000, 0xffffffff },
  7764. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7765. 0x00000000, 0x000000ff },
  7766. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7767. 0x00000000, 0xffffffff },
  7768. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7769. 0x00000000, 0xffffffff },
  7770. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7771. 0x00000000, 0xffffffff },
  7772. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7773. 0x00000000, 0x000000ff },
  7774. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7775. 0x00000000, 0xffffffff },
  7776. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7777. 0x00000000, 0x000000ff },
  7778. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7779. 0x00000000, 0xffffffff },
  7780. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7781. 0x00000000, 0xffffffff },
  7782. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7783. 0x00000000, 0xffffffff },
  7784. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7785. 0x00000000, 0xffffffff },
  7786. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7787. 0x00000000, 0xffffffff },
  7788. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7789. 0xffffffff, 0x00000000 },
  7790. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7791. 0xffffffff, 0x00000000 },
  7792. /* Buffer Manager Control Registers. */
  7793. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7794. 0x00000000, 0x007fff80 },
  7795. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7796. 0x00000000, 0x007fffff },
  7797. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7798. 0x00000000, 0x0000003f },
  7799. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7800. 0x00000000, 0x000001ff },
  7801. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7802. 0x00000000, 0x000001ff },
  7803. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7804. 0xffffffff, 0x00000000 },
  7805. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7806. 0xffffffff, 0x00000000 },
  7807. /* Mailbox Registers */
  7808. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7809. 0x00000000, 0x000001ff },
  7810. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7811. 0x00000000, 0x000001ff },
  7812. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7813. 0x00000000, 0x000007ff },
  7814. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7815. 0x00000000, 0x000001ff },
  7816. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7817. };
  7818. is_5705 = is_5750 = 0;
  7819. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7820. is_5705 = 1;
  7821. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7822. is_5750 = 1;
  7823. }
  7824. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7825. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7826. continue;
  7827. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7828. continue;
  7829. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7830. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7831. continue;
  7832. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7833. continue;
  7834. offset = (u32) reg_tbl[i].offset;
  7835. read_mask = reg_tbl[i].read_mask;
  7836. write_mask = reg_tbl[i].write_mask;
  7837. /* Save the original register content */
  7838. save_val = tr32(offset);
  7839. /* Determine the read-only value. */
  7840. read_val = save_val & read_mask;
  7841. /* Write zero to the register, then make sure the read-only bits
  7842. * are not changed and the read/write bits are all zeros.
  7843. */
  7844. tw32(offset, 0);
  7845. val = tr32(offset);
  7846. /* Test the read-only and read/write bits. */
  7847. if (((val & read_mask) != read_val) || (val & write_mask))
  7848. goto out;
  7849. /* Write ones to all the bits defined by RdMask and WrMask, then
  7850. * make sure the read-only bits are not changed and the
  7851. * read/write bits are all ones.
  7852. */
  7853. tw32(offset, read_mask | write_mask);
  7854. val = tr32(offset);
  7855. /* Test the read-only bits. */
  7856. if ((val & read_mask) != read_val)
  7857. goto out;
  7858. /* Test the read/write bits. */
  7859. if ((val & write_mask) != write_mask)
  7860. goto out;
  7861. tw32(offset, save_val);
  7862. }
  7863. return 0;
  7864. out:
  7865. if (netif_msg_hw(tp))
  7866. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7867. offset);
  7868. tw32(offset, save_val);
  7869. return -EIO;
  7870. }
  7871. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7872. {
  7873. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7874. int i;
  7875. u32 j;
  7876. for (i = 0; i < ARRAY_SIZE(test_pattern); i++) {
  7877. for (j = 0; j < len; j += 4) {
  7878. u32 val;
  7879. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7880. tg3_read_mem(tp, offset + j, &val);
  7881. if (val != test_pattern[i])
  7882. return -EIO;
  7883. }
  7884. }
  7885. return 0;
  7886. }
  7887. static int tg3_test_memory(struct tg3 *tp)
  7888. {
  7889. static struct mem_entry {
  7890. u32 offset;
  7891. u32 len;
  7892. } mem_tbl_570x[] = {
  7893. { 0x00000000, 0x00b50},
  7894. { 0x00002000, 0x1c000},
  7895. { 0xffffffff, 0x00000}
  7896. }, mem_tbl_5705[] = {
  7897. { 0x00000100, 0x0000c},
  7898. { 0x00000200, 0x00008},
  7899. { 0x00004000, 0x00800},
  7900. { 0x00006000, 0x01000},
  7901. { 0x00008000, 0x02000},
  7902. { 0x00010000, 0x0e000},
  7903. { 0xffffffff, 0x00000}
  7904. }, mem_tbl_5755[] = {
  7905. { 0x00000200, 0x00008},
  7906. { 0x00004000, 0x00800},
  7907. { 0x00006000, 0x00800},
  7908. { 0x00008000, 0x02000},
  7909. { 0x00010000, 0x0c000},
  7910. { 0xffffffff, 0x00000}
  7911. }, mem_tbl_5906[] = {
  7912. { 0x00000200, 0x00008},
  7913. { 0x00004000, 0x00400},
  7914. { 0x00006000, 0x00400},
  7915. { 0x00008000, 0x01000},
  7916. { 0x00010000, 0x01000},
  7917. { 0xffffffff, 0x00000}
  7918. };
  7919. struct mem_entry *mem_tbl;
  7920. int err = 0;
  7921. int i;
  7922. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7923. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7924. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  7925. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  7926. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7927. mem_tbl = mem_tbl_5755;
  7928. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7929. mem_tbl = mem_tbl_5906;
  7930. else
  7931. mem_tbl = mem_tbl_5705;
  7932. } else
  7933. mem_tbl = mem_tbl_570x;
  7934. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7935. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7936. mem_tbl[i].len)) != 0)
  7937. break;
  7938. }
  7939. return err;
  7940. }
  7941. #define TG3_MAC_LOOPBACK 0
  7942. #define TG3_PHY_LOOPBACK 1
  7943. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7944. {
  7945. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7946. u32 desc_idx;
  7947. struct sk_buff *skb, *rx_skb;
  7948. u8 *tx_data;
  7949. dma_addr_t map;
  7950. int num_pkts, tx_len, rx_len, i, err;
  7951. struct tg3_rx_buffer_desc *desc;
  7952. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7953. /* HW errata - mac loopback fails in some cases on 5780.
  7954. * Normal traffic and PHY loopback are not affected by
  7955. * errata.
  7956. */
  7957. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7958. return 0;
  7959. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7960. MAC_MODE_PORT_INT_LPBACK;
  7961. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7962. mac_mode |= MAC_MODE_LINK_POLARITY;
  7963. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7964. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7965. else
  7966. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7967. tw32(MAC_MODE, mac_mode);
  7968. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7969. u32 val;
  7970. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7971. u32 phytest;
  7972. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7973. u32 phy;
  7974. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7975. phytest | MII_TG3_EPHY_SHADOW_EN);
  7976. if (!tg3_readphy(tp, 0x1b, &phy))
  7977. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7978. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7979. }
  7980. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7981. } else
  7982. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7983. tg3_phy_toggle_automdix(tp, 0);
  7984. tg3_writephy(tp, MII_BMCR, val);
  7985. udelay(40);
  7986. mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  7987. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7988. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7989. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7990. } else
  7991. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7992. /* reset to prevent losing 1st rx packet intermittently */
  7993. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7994. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7995. udelay(10);
  7996. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7997. }
  7998. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  7999. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
  8000. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  8001. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411)
  8002. mac_mode |= MAC_MODE_LINK_POLARITY;
  8003. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  8004. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  8005. }
  8006. tw32(MAC_MODE, mac_mode);
  8007. }
  8008. else
  8009. return -EINVAL;
  8010. err = -EIO;
  8011. tx_len = 1514;
  8012. skb = netdev_alloc_skb(tp->dev, tx_len);
  8013. if (!skb)
  8014. return -ENOMEM;
  8015. tx_data = skb_put(skb, tx_len);
  8016. memcpy(tx_data, tp->dev->dev_addr, 6);
  8017. memset(tx_data + 6, 0x0, 8);
  8018. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  8019. for (i = 14; i < tx_len; i++)
  8020. tx_data[i] = (u8) (i & 0xff);
  8021. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  8022. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  8023. HOSTCC_MODE_NOW);
  8024. udelay(10);
  8025. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  8026. num_pkts = 0;
  8027. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  8028. tp->tx_prod++;
  8029. num_pkts++;
  8030. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  8031. tp->tx_prod);
  8032. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  8033. udelay(10);
  8034. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  8035. for (i = 0; i < 25; i++) {
  8036. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  8037. HOSTCC_MODE_NOW);
  8038. udelay(10);
  8039. tx_idx = tp->hw_status->idx[0].tx_consumer;
  8040. rx_idx = tp->hw_status->idx[0].rx_producer;
  8041. if ((tx_idx == tp->tx_prod) &&
  8042. (rx_idx == (rx_start_idx + num_pkts)))
  8043. break;
  8044. }
  8045. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  8046. dev_kfree_skb(skb);
  8047. if (tx_idx != tp->tx_prod)
  8048. goto out;
  8049. if (rx_idx != rx_start_idx + num_pkts)
  8050. goto out;
  8051. desc = &tp->rx_rcb[rx_start_idx];
  8052. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  8053. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  8054. if (opaque_key != RXD_OPAQUE_RING_STD)
  8055. goto out;
  8056. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  8057. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  8058. goto out;
  8059. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  8060. if (rx_len != tx_len)
  8061. goto out;
  8062. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  8063. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  8064. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  8065. for (i = 14; i < tx_len; i++) {
  8066. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  8067. goto out;
  8068. }
  8069. err = 0;
  8070. /* tg3_free_rings will unmap and free the rx_skb */
  8071. out:
  8072. return err;
  8073. }
  8074. #define TG3_MAC_LOOPBACK_FAILED 1
  8075. #define TG3_PHY_LOOPBACK_FAILED 2
  8076. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  8077. TG3_PHY_LOOPBACK_FAILED)
  8078. static int tg3_test_loopback(struct tg3 *tp)
  8079. {
  8080. int err = 0;
  8081. u32 cpmuctrl = 0;
  8082. if (!netif_running(tp->dev))
  8083. return TG3_LOOPBACK_FAILED;
  8084. err = tg3_reset_hw(tp, 1);
  8085. if (err)
  8086. return TG3_LOOPBACK_FAILED;
  8087. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8088. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  8089. int i;
  8090. u32 status;
  8091. tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER);
  8092. /* Wait for up to 40 microseconds to acquire lock. */
  8093. for (i = 0; i < 4; i++) {
  8094. status = tr32(TG3_CPMU_MUTEX_GNT);
  8095. if (status == CPMU_MUTEX_GNT_DRIVER)
  8096. break;
  8097. udelay(10);
  8098. }
  8099. if (status != CPMU_MUTEX_GNT_DRIVER)
  8100. return TG3_LOOPBACK_FAILED;
  8101. /* Turn off link-based power management. */
  8102. cpmuctrl = tr32(TG3_CPMU_CTRL);
  8103. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8104. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX)
  8105. tw32(TG3_CPMU_CTRL,
  8106. cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE |
  8107. CPMU_CTRL_LINK_AWARE_MODE));
  8108. else
  8109. tw32(TG3_CPMU_CTRL,
  8110. cpmuctrl & ~CPMU_CTRL_LINK_AWARE_MODE);
  8111. }
  8112. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  8113. err |= TG3_MAC_LOOPBACK_FAILED;
  8114. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8115. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  8116. tw32(TG3_CPMU_CTRL, cpmuctrl);
  8117. /* Release the mutex */
  8118. tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER);
  8119. }
  8120. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  8121. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  8122. err |= TG3_PHY_LOOPBACK_FAILED;
  8123. }
  8124. return err;
  8125. }
  8126. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  8127. u64 *data)
  8128. {
  8129. struct tg3 *tp = netdev_priv(dev);
  8130. if (tp->link_config.phy_is_low_power)
  8131. tg3_set_power_state(tp, PCI_D0);
  8132. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  8133. if (tg3_test_nvram(tp) != 0) {
  8134. etest->flags |= ETH_TEST_FL_FAILED;
  8135. data[0] = 1;
  8136. }
  8137. if (tg3_test_link(tp) != 0) {
  8138. etest->flags |= ETH_TEST_FL_FAILED;
  8139. data[1] = 1;
  8140. }
  8141. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  8142. int err, irq_sync = 0;
  8143. if (netif_running(dev)) {
  8144. tg3_netif_stop(tp);
  8145. irq_sync = 1;
  8146. }
  8147. tg3_full_lock(tp, irq_sync);
  8148. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  8149. err = tg3_nvram_lock(tp);
  8150. tg3_halt_cpu(tp, RX_CPU_BASE);
  8151. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  8152. tg3_halt_cpu(tp, TX_CPU_BASE);
  8153. if (!err)
  8154. tg3_nvram_unlock(tp);
  8155. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  8156. tg3_phy_reset(tp);
  8157. if (tg3_test_registers(tp) != 0) {
  8158. etest->flags |= ETH_TEST_FL_FAILED;
  8159. data[2] = 1;
  8160. }
  8161. if (tg3_test_memory(tp) != 0) {
  8162. etest->flags |= ETH_TEST_FL_FAILED;
  8163. data[3] = 1;
  8164. }
  8165. if ((data[4] = tg3_test_loopback(tp)) != 0)
  8166. etest->flags |= ETH_TEST_FL_FAILED;
  8167. tg3_full_unlock(tp);
  8168. if (tg3_test_interrupt(tp) != 0) {
  8169. etest->flags |= ETH_TEST_FL_FAILED;
  8170. data[5] = 1;
  8171. }
  8172. tg3_full_lock(tp, 0);
  8173. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  8174. if (netif_running(dev)) {
  8175. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  8176. if (!tg3_restart_hw(tp, 1))
  8177. tg3_netif_start(tp);
  8178. }
  8179. tg3_full_unlock(tp);
  8180. }
  8181. if (tp->link_config.phy_is_low_power)
  8182. tg3_set_power_state(tp, PCI_D3hot);
  8183. }
  8184. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8185. {
  8186. struct mii_ioctl_data *data = if_mii(ifr);
  8187. struct tg3 *tp = netdev_priv(dev);
  8188. int err;
  8189. switch(cmd) {
  8190. case SIOCGMIIPHY:
  8191. data->phy_id = PHY_ADDR;
  8192. /* fallthru */
  8193. case SIOCGMIIREG: {
  8194. u32 mii_regval;
  8195. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  8196. break; /* We have no PHY */
  8197. if (tp->link_config.phy_is_low_power)
  8198. return -EAGAIN;
  8199. spin_lock_bh(&tp->lock);
  8200. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  8201. spin_unlock_bh(&tp->lock);
  8202. data->val_out = mii_regval;
  8203. return err;
  8204. }
  8205. case SIOCSMIIREG:
  8206. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  8207. break; /* We have no PHY */
  8208. if (!capable(CAP_NET_ADMIN))
  8209. return -EPERM;
  8210. if (tp->link_config.phy_is_low_power)
  8211. return -EAGAIN;
  8212. spin_lock_bh(&tp->lock);
  8213. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  8214. spin_unlock_bh(&tp->lock);
  8215. return err;
  8216. default:
  8217. /* do nothing */
  8218. break;
  8219. }
  8220. return -EOPNOTSUPP;
  8221. }
  8222. #if TG3_VLAN_TAG_USED
  8223. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  8224. {
  8225. struct tg3 *tp = netdev_priv(dev);
  8226. if (netif_running(dev))
  8227. tg3_netif_stop(tp);
  8228. tg3_full_lock(tp, 0);
  8229. tp->vlgrp = grp;
  8230. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  8231. __tg3_set_rx_mode(dev);
  8232. if (netif_running(dev))
  8233. tg3_netif_start(tp);
  8234. tg3_full_unlock(tp);
  8235. }
  8236. #endif
  8237. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  8238. {
  8239. struct tg3 *tp = netdev_priv(dev);
  8240. memcpy(ec, &tp->coal, sizeof(*ec));
  8241. return 0;
  8242. }
  8243. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  8244. {
  8245. struct tg3 *tp = netdev_priv(dev);
  8246. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  8247. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  8248. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  8249. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  8250. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  8251. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  8252. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  8253. }
  8254. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  8255. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  8256. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  8257. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  8258. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  8259. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  8260. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  8261. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  8262. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  8263. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  8264. return -EINVAL;
  8265. /* No rx interrupts will be generated if both are zero */
  8266. if ((ec->rx_coalesce_usecs == 0) &&
  8267. (ec->rx_max_coalesced_frames == 0))
  8268. return -EINVAL;
  8269. /* No tx interrupts will be generated if both are zero */
  8270. if ((ec->tx_coalesce_usecs == 0) &&
  8271. (ec->tx_max_coalesced_frames == 0))
  8272. return -EINVAL;
  8273. /* Only copy relevant parameters, ignore all others. */
  8274. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  8275. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  8276. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  8277. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  8278. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  8279. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  8280. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  8281. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  8282. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  8283. if (netif_running(dev)) {
  8284. tg3_full_lock(tp, 0);
  8285. __tg3_set_coalesce(tp, &tp->coal);
  8286. tg3_full_unlock(tp);
  8287. }
  8288. return 0;
  8289. }
  8290. static const struct ethtool_ops tg3_ethtool_ops = {
  8291. .get_settings = tg3_get_settings,
  8292. .set_settings = tg3_set_settings,
  8293. .get_drvinfo = tg3_get_drvinfo,
  8294. .get_regs_len = tg3_get_regs_len,
  8295. .get_regs = tg3_get_regs,
  8296. .get_wol = tg3_get_wol,
  8297. .set_wol = tg3_set_wol,
  8298. .get_msglevel = tg3_get_msglevel,
  8299. .set_msglevel = tg3_set_msglevel,
  8300. .nway_reset = tg3_nway_reset,
  8301. .get_link = ethtool_op_get_link,
  8302. .get_eeprom_len = tg3_get_eeprom_len,
  8303. .get_eeprom = tg3_get_eeprom,
  8304. .set_eeprom = tg3_set_eeprom,
  8305. .get_ringparam = tg3_get_ringparam,
  8306. .set_ringparam = tg3_set_ringparam,
  8307. .get_pauseparam = tg3_get_pauseparam,
  8308. .set_pauseparam = tg3_set_pauseparam,
  8309. .get_rx_csum = tg3_get_rx_csum,
  8310. .set_rx_csum = tg3_set_rx_csum,
  8311. .set_tx_csum = tg3_set_tx_csum,
  8312. .set_sg = ethtool_op_set_sg,
  8313. .set_tso = tg3_set_tso,
  8314. .self_test = tg3_self_test,
  8315. .get_strings = tg3_get_strings,
  8316. .phys_id = tg3_phys_id,
  8317. .get_ethtool_stats = tg3_get_ethtool_stats,
  8318. .get_coalesce = tg3_get_coalesce,
  8319. .set_coalesce = tg3_set_coalesce,
  8320. .get_sset_count = tg3_get_sset_count,
  8321. };
  8322. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  8323. {
  8324. u32 cursize, val, magic;
  8325. tp->nvram_size = EEPROM_CHIP_SIZE;
  8326. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  8327. return;
  8328. if ((magic != TG3_EEPROM_MAGIC) &&
  8329. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  8330. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  8331. return;
  8332. /*
  8333. * Size the chip by reading offsets at increasing powers of two.
  8334. * When we encounter our validation signature, we know the addressing
  8335. * has wrapped around, and thus have our chip size.
  8336. */
  8337. cursize = 0x10;
  8338. while (cursize < tp->nvram_size) {
  8339. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  8340. return;
  8341. if (val == magic)
  8342. break;
  8343. cursize <<= 1;
  8344. }
  8345. tp->nvram_size = cursize;
  8346. }
  8347. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  8348. {
  8349. u32 val;
  8350. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  8351. return;
  8352. /* Selfboot format */
  8353. if (val != TG3_EEPROM_MAGIC) {
  8354. tg3_get_eeprom_size(tp);
  8355. return;
  8356. }
  8357. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  8358. if (val != 0) {
  8359. tp->nvram_size = (val >> 16) * 1024;
  8360. return;
  8361. }
  8362. }
  8363. tp->nvram_size = 0x80000;
  8364. }
  8365. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  8366. {
  8367. u32 nvcfg1;
  8368. nvcfg1 = tr32(NVRAM_CFG1);
  8369. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  8370. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8371. }
  8372. else {
  8373. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8374. tw32(NVRAM_CFG1, nvcfg1);
  8375. }
  8376. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  8377. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  8378. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  8379. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  8380. tp->nvram_jedecnum = JEDEC_ATMEL;
  8381. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  8382. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8383. break;
  8384. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  8385. tp->nvram_jedecnum = JEDEC_ATMEL;
  8386. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  8387. break;
  8388. case FLASH_VENDOR_ATMEL_EEPROM:
  8389. tp->nvram_jedecnum = JEDEC_ATMEL;
  8390. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8391. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8392. break;
  8393. case FLASH_VENDOR_ST:
  8394. tp->nvram_jedecnum = JEDEC_ST;
  8395. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  8396. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8397. break;
  8398. case FLASH_VENDOR_SAIFUN:
  8399. tp->nvram_jedecnum = JEDEC_SAIFUN;
  8400. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  8401. break;
  8402. case FLASH_VENDOR_SST_SMALL:
  8403. case FLASH_VENDOR_SST_LARGE:
  8404. tp->nvram_jedecnum = JEDEC_SST;
  8405. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  8406. break;
  8407. }
  8408. }
  8409. else {
  8410. tp->nvram_jedecnum = JEDEC_ATMEL;
  8411. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  8412. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8413. }
  8414. }
  8415. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  8416. {
  8417. u32 nvcfg1;
  8418. nvcfg1 = tr32(NVRAM_CFG1);
  8419. /* NVRAM protection for TPM */
  8420. if (nvcfg1 & (1 << 27))
  8421. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8422. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8423. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  8424. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  8425. tp->nvram_jedecnum = JEDEC_ATMEL;
  8426. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8427. break;
  8428. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8429. tp->nvram_jedecnum = JEDEC_ATMEL;
  8430. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8431. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8432. break;
  8433. case FLASH_5752VENDOR_ST_M45PE10:
  8434. case FLASH_5752VENDOR_ST_M45PE20:
  8435. case FLASH_5752VENDOR_ST_M45PE40:
  8436. tp->nvram_jedecnum = JEDEC_ST;
  8437. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8438. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8439. break;
  8440. }
  8441. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  8442. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  8443. case FLASH_5752PAGE_SIZE_256:
  8444. tp->nvram_pagesize = 256;
  8445. break;
  8446. case FLASH_5752PAGE_SIZE_512:
  8447. tp->nvram_pagesize = 512;
  8448. break;
  8449. case FLASH_5752PAGE_SIZE_1K:
  8450. tp->nvram_pagesize = 1024;
  8451. break;
  8452. case FLASH_5752PAGE_SIZE_2K:
  8453. tp->nvram_pagesize = 2048;
  8454. break;
  8455. case FLASH_5752PAGE_SIZE_4K:
  8456. tp->nvram_pagesize = 4096;
  8457. break;
  8458. case FLASH_5752PAGE_SIZE_264:
  8459. tp->nvram_pagesize = 264;
  8460. break;
  8461. }
  8462. }
  8463. else {
  8464. /* For eeprom, set pagesize to maximum eeprom size */
  8465. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8466. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8467. tw32(NVRAM_CFG1, nvcfg1);
  8468. }
  8469. }
  8470. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  8471. {
  8472. u32 nvcfg1, protect = 0;
  8473. nvcfg1 = tr32(NVRAM_CFG1);
  8474. /* NVRAM protection for TPM */
  8475. if (nvcfg1 & (1 << 27)) {
  8476. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8477. protect = 1;
  8478. }
  8479. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8480. switch (nvcfg1) {
  8481. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8482. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8483. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8484. case FLASH_5755VENDOR_ATMEL_FLASH_5:
  8485. tp->nvram_jedecnum = JEDEC_ATMEL;
  8486. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8487. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8488. tp->nvram_pagesize = 264;
  8489. if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
  8490. nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
  8491. tp->nvram_size = (protect ? 0x3e200 : 0x80000);
  8492. else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
  8493. tp->nvram_size = (protect ? 0x1f200 : 0x40000);
  8494. else
  8495. tp->nvram_size = (protect ? 0x1f200 : 0x20000);
  8496. break;
  8497. case FLASH_5752VENDOR_ST_M45PE10:
  8498. case FLASH_5752VENDOR_ST_M45PE20:
  8499. case FLASH_5752VENDOR_ST_M45PE40:
  8500. tp->nvram_jedecnum = JEDEC_ST;
  8501. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8502. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8503. tp->nvram_pagesize = 256;
  8504. if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
  8505. tp->nvram_size = (protect ? 0x10000 : 0x20000);
  8506. else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
  8507. tp->nvram_size = (protect ? 0x10000 : 0x40000);
  8508. else
  8509. tp->nvram_size = (protect ? 0x20000 : 0x80000);
  8510. break;
  8511. }
  8512. }
  8513. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8514. {
  8515. u32 nvcfg1;
  8516. nvcfg1 = tr32(NVRAM_CFG1);
  8517. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8518. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8519. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8520. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8521. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8522. tp->nvram_jedecnum = JEDEC_ATMEL;
  8523. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8524. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8525. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8526. tw32(NVRAM_CFG1, nvcfg1);
  8527. break;
  8528. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8529. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8530. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8531. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8532. tp->nvram_jedecnum = JEDEC_ATMEL;
  8533. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8534. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8535. tp->nvram_pagesize = 264;
  8536. break;
  8537. case FLASH_5752VENDOR_ST_M45PE10:
  8538. case FLASH_5752VENDOR_ST_M45PE20:
  8539. case FLASH_5752VENDOR_ST_M45PE40:
  8540. tp->nvram_jedecnum = JEDEC_ST;
  8541. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8542. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8543. tp->nvram_pagesize = 256;
  8544. break;
  8545. }
  8546. }
  8547. static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp)
  8548. {
  8549. u32 nvcfg1, protect = 0;
  8550. nvcfg1 = tr32(NVRAM_CFG1);
  8551. /* NVRAM protection for TPM */
  8552. if (nvcfg1 & (1 << 27)) {
  8553. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8554. protect = 1;
  8555. }
  8556. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8557. switch (nvcfg1) {
  8558. case FLASH_5761VENDOR_ATMEL_ADB021D:
  8559. case FLASH_5761VENDOR_ATMEL_ADB041D:
  8560. case FLASH_5761VENDOR_ATMEL_ADB081D:
  8561. case FLASH_5761VENDOR_ATMEL_ADB161D:
  8562. case FLASH_5761VENDOR_ATMEL_MDB021D:
  8563. case FLASH_5761VENDOR_ATMEL_MDB041D:
  8564. case FLASH_5761VENDOR_ATMEL_MDB081D:
  8565. case FLASH_5761VENDOR_ATMEL_MDB161D:
  8566. tp->nvram_jedecnum = JEDEC_ATMEL;
  8567. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8568. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8569. tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS;
  8570. tp->nvram_pagesize = 256;
  8571. break;
  8572. case FLASH_5761VENDOR_ST_A_M45PE20:
  8573. case FLASH_5761VENDOR_ST_A_M45PE40:
  8574. case FLASH_5761VENDOR_ST_A_M45PE80:
  8575. case FLASH_5761VENDOR_ST_A_M45PE16:
  8576. case FLASH_5761VENDOR_ST_M_M45PE20:
  8577. case FLASH_5761VENDOR_ST_M_M45PE40:
  8578. case FLASH_5761VENDOR_ST_M_M45PE80:
  8579. case FLASH_5761VENDOR_ST_M_M45PE16:
  8580. tp->nvram_jedecnum = JEDEC_ST;
  8581. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8582. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8583. tp->nvram_pagesize = 256;
  8584. break;
  8585. }
  8586. if (protect) {
  8587. tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT);
  8588. } else {
  8589. switch (nvcfg1) {
  8590. case FLASH_5761VENDOR_ATMEL_ADB161D:
  8591. case FLASH_5761VENDOR_ATMEL_MDB161D:
  8592. case FLASH_5761VENDOR_ST_A_M45PE16:
  8593. case FLASH_5761VENDOR_ST_M_M45PE16:
  8594. tp->nvram_size = 0x100000;
  8595. break;
  8596. case FLASH_5761VENDOR_ATMEL_ADB081D:
  8597. case FLASH_5761VENDOR_ATMEL_MDB081D:
  8598. case FLASH_5761VENDOR_ST_A_M45PE80:
  8599. case FLASH_5761VENDOR_ST_M_M45PE80:
  8600. tp->nvram_size = 0x80000;
  8601. break;
  8602. case FLASH_5761VENDOR_ATMEL_ADB041D:
  8603. case FLASH_5761VENDOR_ATMEL_MDB041D:
  8604. case FLASH_5761VENDOR_ST_A_M45PE40:
  8605. case FLASH_5761VENDOR_ST_M_M45PE40:
  8606. tp->nvram_size = 0x40000;
  8607. break;
  8608. case FLASH_5761VENDOR_ATMEL_ADB021D:
  8609. case FLASH_5761VENDOR_ATMEL_MDB021D:
  8610. case FLASH_5761VENDOR_ST_A_M45PE20:
  8611. case FLASH_5761VENDOR_ST_M_M45PE20:
  8612. tp->nvram_size = 0x20000;
  8613. break;
  8614. }
  8615. }
  8616. }
  8617. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8618. {
  8619. tp->nvram_jedecnum = JEDEC_ATMEL;
  8620. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8621. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8622. }
  8623. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8624. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8625. {
  8626. tw32_f(GRC_EEPROM_ADDR,
  8627. (EEPROM_ADDR_FSM_RESET |
  8628. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8629. EEPROM_ADDR_CLKPERD_SHIFT)));
  8630. msleep(1);
  8631. /* Enable seeprom accesses. */
  8632. tw32_f(GRC_LOCAL_CTRL,
  8633. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8634. udelay(100);
  8635. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8636. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8637. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8638. if (tg3_nvram_lock(tp)) {
  8639. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8640. "tg3_nvram_init failed.\n", tp->dev->name);
  8641. return;
  8642. }
  8643. tg3_enable_nvram_access(tp);
  8644. tp->nvram_size = 0;
  8645. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8646. tg3_get_5752_nvram_info(tp);
  8647. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8648. tg3_get_5755_nvram_info(tp);
  8649. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8650. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)
  8651. tg3_get_5787_nvram_info(tp);
  8652. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  8653. tg3_get_5761_nvram_info(tp);
  8654. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8655. tg3_get_5906_nvram_info(tp);
  8656. else
  8657. tg3_get_nvram_info(tp);
  8658. if (tp->nvram_size == 0)
  8659. tg3_get_nvram_size(tp);
  8660. tg3_disable_nvram_access(tp);
  8661. tg3_nvram_unlock(tp);
  8662. } else {
  8663. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8664. tg3_get_eeprom_size(tp);
  8665. }
  8666. }
  8667. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8668. u32 offset, u32 *val)
  8669. {
  8670. u32 tmp;
  8671. int i;
  8672. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8673. (offset % 4) != 0)
  8674. return -EINVAL;
  8675. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8676. EEPROM_ADDR_DEVID_MASK |
  8677. EEPROM_ADDR_READ);
  8678. tw32(GRC_EEPROM_ADDR,
  8679. tmp |
  8680. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8681. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8682. EEPROM_ADDR_ADDR_MASK) |
  8683. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8684. for (i = 0; i < 1000; i++) {
  8685. tmp = tr32(GRC_EEPROM_ADDR);
  8686. if (tmp & EEPROM_ADDR_COMPLETE)
  8687. break;
  8688. msleep(1);
  8689. }
  8690. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8691. return -EBUSY;
  8692. *val = tr32(GRC_EEPROM_DATA);
  8693. return 0;
  8694. }
  8695. #define NVRAM_CMD_TIMEOUT 10000
  8696. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8697. {
  8698. int i;
  8699. tw32(NVRAM_CMD, nvram_cmd);
  8700. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8701. udelay(10);
  8702. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8703. udelay(10);
  8704. break;
  8705. }
  8706. }
  8707. if (i == NVRAM_CMD_TIMEOUT) {
  8708. return -EBUSY;
  8709. }
  8710. return 0;
  8711. }
  8712. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8713. {
  8714. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8715. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8716. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8717. !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
  8718. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8719. addr = ((addr / tp->nvram_pagesize) <<
  8720. ATMEL_AT45DB0X1B_PAGE_POS) +
  8721. (addr % tp->nvram_pagesize);
  8722. return addr;
  8723. }
  8724. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8725. {
  8726. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8727. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8728. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8729. !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
  8730. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8731. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8732. tp->nvram_pagesize) +
  8733. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8734. return addr;
  8735. }
  8736. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8737. {
  8738. int ret;
  8739. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8740. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8741. offset = tg3_nvram_phys_addr(tp, offset);
  8742. if (offset > NVRAM_ADDR_MSK)
  8743. return -EINVAL;
  8744. ret = tg3_nvram_lock(tp);
  8745. if (ret)
  8746. return ret;
  8747. tg3_enable_nvram_access(tp);
  8748. tw32(NVRAM_ADDR, offset);
  8749. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8750. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8751. if (ret == 0)
  8752. *val = swab32(tr32(NVRAM_RDDATA));
  8753. tg3_disable_nvram_access(tp);
  8754. tg3_nvram_unlock(tp);
  8755. return ret;
  8756. }
  8757. static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val)
  8758. {
  8759. u32 v;
  8760. int res = tg3_nvram_read(tp, offset, &v);
  8761. if (!res)
  8762. *val = cpu_to_le32(v);
  8763. return res;
  8764. }
  8765. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8766. {
  8767. int err;
  8768. u32 tmp;
  8769. err = tg3_nvram_read(tp, offset, &tmp);
  8770. *val = swab32(tmp);
  8771. return err;
  8772. }
  8773. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8774. u32 offset, u32 len, u8 *buf)
  8775. {
  8776. int i, j, rc = 0;
  8777. u32 val;
  8778. for (i = 0; i < len; i += 4) {
  8779. u32 addr;
  8780. __le32 data;
  8781. addr = offset + i;
  8782. memcpy(&data, buf + i, 4);
  8783. tw32(GRC_EEPROM_DATA, le32_to_cpu(data));
  8784. val = tr32(GRC_EEPROM_ADDR);
  8785. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8786. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8787. EEPROM_ADDR_READ);
  8788. tw32(GRC_EEPROM_ADDR, val |
  8789. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8790. (addr & EEPROM_ADDR_ADDR_MASK) |
  8791. EEPROM_ADDR_START |
  8792. EEPROM_ADDR_WRITE);
  8793. for (j = 0; j < 1000; j++) {
  8794. val = tr32(GRC_EEPROM_ADDR);
  8795. if (val & EEPROM_ADDR_COMPLETE)
  8796. break;
  8797. msleep(1);
  8798. }
  8799. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8800. rc = -EBUSY;
  8801. break;
  8802. }
  8803. }
  8804. return rc;
  8805. }
  8806. /* offset and length are dword aligned */
  8807. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8808. u8 *buf)
  8809. {
  8810. int ret = 0;
  8811. u32 pagesize = tp->nvram_pagesize;
  8812. u32 pagemask = pagesize - 1;
  8813. u32 nvram_cmd;
  8814. u8 *tmp;
  8815. tmp = kmalloc(pagesize, GFP_KERNEL);
  8816. if (tmp == NULL)
  8817. return -ENOMEM;
  8818. while (len) {
  8819. int j;
  8820. u32 phy_addr, page_off, size;
  8821. phy_addr = offset & ~pagemask;
  8822. for (j = 0; j < pagesize; j += 4) {
  8823. if ((ret = tg3_nvram_read_le(tp, phy_addr + j,
  8824. (__le32 *) (tmp + j))))
  8825. break;
  8826. }
  8827. if (ret)
  8828. break;
  8829. page_off = offset & pagemask;
  8830. size = pagesize;
  8831. if (len < size)
  8832. size = len;
  8833. len -= size;
  8834. memcpy(tmp + page_off, buf, size);
  8835. offset = offset + (pagesize - page_off);
  8836. tg3_enable_nvram_access(tp);
  8837. /*
  8838. * Before we can erase the flash page, we need
  8839. * to issue a special "write enable" command.
  8840. */
  8841. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8842. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8843. break;
  8844. /* Erase the target page */
  8845. tw32(NVRAM_ADDR, phy_addr);
  8846. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8847. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8848. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8849. break;
  8850. /* Issue another write enable to start the write. */
  8851. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8852. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8853. break;
  8854. for (j = 0; j < pagesize; j += 4) {
  8855. __be32 data;
  8856. data = *((__be32 *) (tmp + j));
  8857. /* swab32(le32_to_cpu(data)), actually */
  8858. tw32(NVRAM_WRDATA, be32_to_cpu(data));
  8859. tw32(NVRAM_ADDR, phy_addr + j);
  8860. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8861. NVRAM_CMD_WR;
  8862. if (j == 0)
  8863. nvram_cmd |= NVRAM_CMD_FIRST;
  8864. else if (j == (pagesize - 4))
  8865. nvram_cmd |= NVRAM_CMD_LAST;
  8866. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8867. break;
  8868. }
  8869. if (ret)
  8870. break;
  8871. }
  8872. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8873. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8874. kfree(tmp);
  8875. return ret;
  8876. }
  8877. /* offset and length are dword aligned */
  8878. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8879. u8 *buf)
  8880. {
  8881. int i, ret = 0;
  8882. for (i = 0; i < len; i += 4, offset += 4) {
  8883. u32 page_off, phy_addr, nvram_cmd;
  8884. __be32 data;
  8885. memcpy(&data, buf + i, 4);
  8886. tw32(NVRAM_WRDATA, be32_to_cpu(data));
  8887. page_off = offset % tp->nvram_pagesize;
  8888. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8889. tw32(NVRAM_ADDR, phy_addr);
  8890. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8891. if ((page_off == 0) || (i == 0))
  8892. nvram_cmd |= NVRAM_CMD_FIRST;
  8893. if (page_off == (tp->nvram_pagesize - 4))
  8894. nvram_cmd |= NVRAM_CMD_LAST;
  8895. if (i == (len - 4))
  8896. nvram_cmd |= NVRAM_CMD_LAST;
  8897. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8898. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8899. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8900. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784) &&
  8901. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) &&
  8902. (tp->nvram_jedecnum == JEDEC_ST) &&
  8903. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8904. if ((ret = tg3_nvram_exec_cmd(tp,
  8905. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8906. NVRAM_CMD_DONE)))
  8907. break;
  8908. }
  8909. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8910. /* We always do complete word writes to eeprom. */
  8911. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8912. }
  8913. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8914. break;
  8915. }
  8916. return ret;
  8917. }
  8918. /* offset and length are dword aligned */
  8919. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8920. {
  8921. int ret;
  8922. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8923. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8924. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8925. udelay(40);
  8926. }
  8927. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8928. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8929. }
  8930. else {
  8931. u32 grc_mode;
  8932. ret = tg3_nvram_lock(tp);
  8933. if (ret)
  8934. return ret;
  8935. tg3_enable_nvram_access(tp);
  8936. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8937. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8938. tw32(NVRAM_WRITE1, 0x406);
  8939. grc_mode = tr32(GRC_MODE);
  8940. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8941. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8942. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8943. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8944. buf);
  8945. }
  8946. else {
  8947. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8948. buf);
  8949. }
  8950. grc_mode = tr32(GRC_MODE);
  8951. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8952. tg3_disable_nvram_access(tp);
  8953. tg3_nvram_unlock(tp);
  8954. }
  8955. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8956. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8957. udelay(40);
  8958. }
  8959. return ret;
  8960. }
  8961. struct subsys_tbl_ent {
  8962. u16 subsys_vendor, subsys_devid;
  8963. u32 phy_id;
  8964. };
  8965. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8966. /* Broadcom boards. */
  8967. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8968. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8969. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8970. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8971. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8972. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8973. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8974. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8975. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8976. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8977. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8978. /* 3com boards. */
  8979. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8980. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8981. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8982. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8983. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8984. /* DELL boards. */
  8985. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8986. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8987. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8988. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8989. /* Compaq boards. */
  8990. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8991. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8992. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8993. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8994. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8995. /* IBM boards. */
  8996. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8997. };
  8998. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8999. {
  9000. int i;
  9001. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  9002. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  9003. tp->pdev->subsystem_vendor) &&
  9004. (subsys_id_to_phy_id[i].subsys_devid ==
  9005. tp->pdev->subsystem_device))
  9006. return &subsys_id_to_phy_id[i];
  9007. }
  9008. return NULL;
  9009. }
  9010. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  9011. {
  9012. u32 val;
  9013. u16 pmcsr;
  9014. /* On some early chips the SRAM cannot be accessed in D3hot state,
  9015. * so need make sure we're in D0.
  9016. */
  9017. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  9018. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  9019. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  9020. msleep(1);
  9021. /* Make sure register accesses (indirect or otherwise)
  9022. * will function correctly.
  9023. */
  9024. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9025. tp->misc_host_ctrl);
  9026. /* The memory arbiter has to be enabled in order for SRAM accesses
  9027. * to succeed. Normally on powerup the tg3 chip firmware will make
  9028. * sure it is enabled, but other entities such as system netboot
  9029. * code might disable it.
  9030. */
  9031. val = tr32(MEMARB_MODE);
  9032. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  9033. tp->phy_id = PHY_ID_INVALID;
  9034. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9035. /* Assume an onboard device and WOL capable by default. */
  9036. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
  9037. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9038. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  9039. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9040. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  9041. }
  9042. val = tr32(VCPU_CFGSHDW);
  9043. if (val & VCPU_CFGSHDW_ASPM_DBNC)
  9044. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  9045. if ((val & VCPU_CFGSHDW_WOL_ENABLE) &&
  9046. (val & VCPU_CFGSHDW_WOL_MAGPKT))
  9047. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  9048. return;
  9049. }
  9050. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  9051. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  9052. u32 nic_cfg, led_cfg;
  9053. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  9054. int eeprom_phy_serdes = 0;
  9055. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  9056. tp->nic_sram_data_cfg = nic_cfg;
  9057. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  9058. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  9059. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  9060. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  9061. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  9062. (ver > 0) && (ver < 0x100))
  9063. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  9064. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  9065. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  9066. eeprom_phy_serdes = 1;
  9067. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  9068. if (nic_phy_id != 0) {
  9069. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  9070. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  9071. eeprom_phy_id = (id1 >> 16) << 10;
  9072. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  9073. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  9074. } else
  9075. eeprom_phy_id = 0;
  9076. tp->phy_id = eeprom_phy_id;
  9077. if (eeprom_phy_serdes) {
  9078. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  9079. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  9080. else
  9081. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9082. }
  9083. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  9084. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  9085. SHASTA_EXT_LED_MODE_MASK);
  9086. else
  9087. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  9088. switch (led_cfg) {
  9089. default:
  9090. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  9091. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9092. break;
  9093. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  9094. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  9095. break;
  9096. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  9097. tp->led_ctrl = LED_CTRL_MODE_MAC;
  9098. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  9099. * read on some older 5700/5701 bootcode.
  9100. */
  9101. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9102. ASIC_REV_5700 ||
  9103. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9104. ASIC_REV_5701)
  9105. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9106. break;
  9107. case SHASTA_EXT_LED_SHARED:
  9108. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  9109. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  9110. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  9111. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  9112. LED_CTRL_MODE_PHY_2);
  9113. break;
  9114. case SHASTA_EXT_LED_MAC:
  9115. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  9116. break;
  9117. case SHASTA_EXT_LED_COMBO:
  9118. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  9119. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  9120. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  9121. LED_CTRL_MODE_PHY_2);
  9122. break;
  9123. };
  9124. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9125. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  9126. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  9127. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  9128. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX)
  9129. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9130. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  9131. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  9132. if ((tp->pdev->subsystem_vendor ==
  9133. PCI_VENDOR_ID_ARIMA) &&
  9134. (tp->pdev->subsystem_device == 0x205a ||
  9135. tp->pdev->subsystem_device == 0x2063))
  9136. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9137. } else {
  9138. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9139. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  9140. }
  9141. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  9142. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  9143. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  9144. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  9145. }
  9146. if (nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE)
  9147. tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE;
  9148. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  9149. !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
  9150. tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
  9151. if (tp->tg3_flags & TG3_FLAG_WOL_CAP &&
  9152. nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)
  9153. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  9154. if (cfg2 & (1 << 17))
  9155. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  9156. /* serdes signal pre-emphasis in register 0x590 set by */
  9157. /* bootcode if bit 18 is set */
  9158. if (cfg2 & (1 << 18))
  9159. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  9160. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9161. u32 cfg3;
  9162. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3);
  9163. if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)
  9164. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  9165. }
  9166. }
  9167. }
  9168. static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd)
  9169. {
  9170. int i;
  9171. u32 val;
  9172. tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START);
  9173. tw32(OTP_CTRL, cmd);
  9174. /* Wait for up to 1 ms for command to execute. */
  9175. for (i = 0; i < 100; i++) {
  9176. val = tr32(OTP_STATUS);
  9177. if (val & OTP_STATUS_CMD_DONE)
  9178. break;
  9179. udelay(10);
  9180. }
  9181. return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY;
  9182. }
  9183. /* Read the gphy configuration from the OTP region of the chip. The gphy
  9184. * configuration is a 32-bit value that straddles the alignment boundary.
  9185. * We do two 32-bit reads and then shift and merge the results.
  9186. */
  9187. static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp)
  9188. {
  9189. u32 bhalf_otp, thalf_otp;
  9190. tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC);
  9191. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT))
  9192. return 0;
  9193. tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1);
  9194. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
  9195. return 0;
  9196. thalf_otp = tr32(OTP_READ_DATA);
  9197. tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2);
  9198. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
  9199. return 0;
  9200. bhalf_otp = tr32(OTP_READ_DATA);
  9201. return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16);
  9202. }
  9203. static int __devinit tg3_phy_probe(struct tg3 *tp)
  9204. {
  9205. u32 hw_phy_id_1, hw_phy_id_2;
  9206. u32 hw_phy_id, hw_phy_id_masked;
  9207. int err;
  9208. /* Reading the PHY ID register can conflict with ASF
  9209. * firwmare access to the PHY hardware.
  9210. */
  9211. err = 0;
  9212. if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
  9213. (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
  9214. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  9215. } else {
  9216. /* Now read the physical PHY_ID from the chip and verify
  9217. * that it is sane. If it doesn't look good, we fall back
  9218. * to either the hard-coded table based PHY_ID and failing
  9219. * that the value found in the eeprom area.
  9220. */
  9221. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  9222. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  9223. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  9224. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  9225. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  9226. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  9227. }
  9228. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  9229. tp->phy_id = hw_phy_id;
  9230. if (hw_phy_id_masked == PHY_ID_BCM8002)
  9231. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9232. else
  9233. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  9234. } else {
  9235. if (tp->phy_id != PHY_ID_INVALID) {
  9236. /* Do nothing, phy ID already set up in
  9237. * tg3_get_eeprom_hw_cfg().
  9238. */
  9239. } else {
  9240. struct subsys_tbl_ent *p;
  9241. /* No eeprom signature? Try the hardcoded
  9242. * subsys device table.
  9243. */
  9244. p = lookup_by_subsys(tp);
  9245. if (!p)
  9246. return -ENODEV;
  9247. tp->phy_id = p->phy_id;
  9248. if (!tp->phy_id ||
  9249. tp->phy_id == PHY_ID_BCM8002)
  9250. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9251. }
  9252. }
  9253. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  9254. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) &&
  9255. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  9256. u32 bmsr, adv_reg, tg3_ctrl, mask;
  9257. tg3_readphy(tp, MII_BMSR, &bmsr);
  9258. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  9259. (bmsr & BMSR_LSTATUS))
  9260. goto skip_phy_reset;
  9261. err = tg3_phy_reset(tp);
  9262. if (err)
  9263. return err;
  9264. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  9265. ADVERTISE_100HALF | ADVERTISE_100FULL |
  9266. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  9267. tg3_ctrl = 0;
  9268. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  9269. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  9270. MII_TG3_CTRL_ADV_1000_FULL);
  9271. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9272. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  9273. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  9274. MII_TG3_CTRL_ENABLE_AS_MASTER);
  9275. }
  9276. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9277. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9278. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  9279. if (!tg3_copper_is_advertising_all(tp, mask)) {
  9280. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  9281. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  9282. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  9283. tg3_writephy(tp, MII_BMCR,
  9284. BMCR_ANENABLE | BMCR_ANRESTART);
  9285. }
  9286. tg3_phy_set_wirespeed(tp);
  9287. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  9288. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  9289. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  9290. }
  9291. skip_phy_reset:
  9292. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  9293. err = tg3_init_5401phy_dsp(tp);
  9294. if (err)
  9295. return err;
  9296. }
  9297. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  9298. err = tg3_init_5401phy_dsp(tp);
  9299. }
  9300. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  9301. tp->link_config.advertising =
  9302. (ADVERTISED_1000baseT_Half |
  9303. ADVERTISED_1000baseT_Full |
  9304. ADVERTISED_Autoneg |
  9305. ADVERTISED_FIBRE);
  9306. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  9307. tp->link_config.advertising &=
  9308. ~(ADVERTISED_1000baseT_Half |
  9309. ADVERTISED_1000baseT_Full);
  9310. return err;
  9311. }
  9312. static void __devinit tg3_read_partno(struct tg3 *tp)
  9313. {
  9314. unsigned char vpd_data[256];
  9315. unsigned int i;
  9316. u32 magic;
  9317. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  9318. goto out_not_found;
  9319. if (magic == TG3_EEPROM_MAGIC) {
  9320. for (i = 0; i < 256; i += 4) {
  9321. u32 tmp;
  9322. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  9323. goto out_not_found;
  9324. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  9325. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  9326. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  9327. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  9328. }
  9329. } else {
  9330. int vpd_cap;
  9331. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  9332. for (i = 0; i < 256; i += 4) {
  9333. u32 tmp, j = 0;
  9334. __le32 v;
  9335. u16 tmp16;
  9336. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  9337. i);
  9338. while (j++ < 100) {
  9339. pci_read_config_word(tp->pdev, vpd_cap +
  9340. PCI_VPD_ADDR, &tmp16);
  9341. if (tmp16 & 0x8000)
  9342. break;
  9343. msleep(1);
  9344. }
  9345. if (!(tmp16 & 0x8000))
  9346. goto out_not_found;
  9347. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  9348. &tmp);
  9349. v = cpu_to_le32(tmp);
  9350. memcpy(&vpd_data[i], &v, 4);
  9351. }
  9352. }
  9353. /* Now parse and find the part number. */
  9354. for (i = 0; i < 254; ) {
  9355. unsigned char val = vpd_data[i];
  9356. unsigned int block_end;
  9357. if (val == 0x82 || val == 0x91) {
  9358. i = (i + 3 +
  9359. (vpd_data[i + 1] +
  9360. (vpd_data[i + 2] << 8)));
  9361. continue;
  9362. }
  9363. if (val != 0x90)
  9364. goto out_not_found;
  9365. block_end = (i + 3 +
  9366. (vpd_data[i + 1] +
  9367. (vpd_data[i + 2] << 8)));
  9368. i += 3;
  9369. if (block_end > 256)
  9370. goto out_not_found;
  9371. while (i < (block_end - 2)) {
  9372. if (vpd_data[i + 0] == 'P' &&
  9373. vpd_data[i + 1] == 'N') {
  9374. int partno_len = vpd_data[i + 2];
  9375. i += 3;
  9376. if (partno_len > 24 || (partno_len + i) > 256)
  9377. goto out_not_found;
  9378. memcpy(tp->board_part_number,
  9379. &vpd_data[i], partno_len);
  9380. /* Success. */
  9381. return;
  9382. }
  9383. i += 3 + vpd_data[i + 2];
  9384. }
  9385. /* Part number not found. */
  9386. goto out_not_found;
  9387. }
  9388. out_not_found:
  9389. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9390. strcpy(tp->board_part_number, "BCM95906");
  9391. else
  9392. strcpy(tp->board_part_number, "none");
  9393. }
  9394. static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset)
  9395. {
  9396. u32 val;
  9397. if (tg3_nvram_read_swab(tp, offset, &val) ||
  9398. (val & 0xfc000000) != 0x0c000000 ||
  9399. tg3_nvram_read_swab(tp, offset + 4, &val) ||
  9400. val != 0)
  9401. return 0;
  9402. return 1;
  9403. }
  9404. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  9405. {
  9406. u32 val, offset, start;
  9407. u32 ver_offset;
  9408. int i, bcnt;
  9409. if (tg3_nvram_read_swab(tp, 0, &val))
  9410. return;
  9411. if (val != TG3_EEPROM_MAGIC)
  9412. return;
  9413. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  9414. tg3_nvram_read_swab(tp, 0x4, &start))
  9415. return;
  9416. offset = tg3_nvram_logical_addr(tp, offset);
  9417. if (!tg3_fw_img_is_valid(tp, offset) ||
  9418. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  9419. return;
  9420. offset = offset + ver_offset - start;
  9421. for (i = 0; i < 16; i += 4) {
  9422. __le32 v;
  9423. if (tg3_nvram_read_le(tp, offset + i, &v))
  9424. return;
  9425. memcpy(tp->fw_ver + i, &v, 4);
  9426. }
  9427. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
  9428. (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  9429. return;
  9430. for (offset = TG3_NVM_DIR_START;
  9431. offset < TG3_NVM_DIR_END;
  9432. offset += TG3_NVM_DIRENT_SIZE) {
  9433. if (tg3_nvram_read_swab(tp, offset, &val))
  9434. return;
  9435. if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI)
  9436. break;
  9437. }
  9438. if (offset == TG3_NVM_DIR_END)
  9439. return;
  9440. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  9441. start = 0x08000000;
  9442. else if (tg3_nvram_read_swab(tp, offset - 4, &start))
  9443. return;
  9444. if (tg3_nvram_read_swab(tp, offset + 4, &offset) ||
  9445. !tg3_fw_img_is_valid(tp, offset) ||
  9446. tg3_nvram_read_swab(tp, offset + 8, &val))
  9447. return;
  9448. offset += val - start;
  9449. bcnt = strlen(tp->fw_ver);
  9450. tp->fw_ver[bcnt++] = ',';
  9451. tp->fw_ver[bcnt++] = ' ';
  9452. for (i = 0; i < 4; i++) {
  9453. __le32 v;
  9454. if (tg3_nvram_read_le(tp, offset, &v))
  9455. return;
  9456. offset += sizeof(v);
  9457. if (bcnt > TG3_VER_SIZE - sizeof(v)) {
  9458. memcpy(&tp->fw_ver[bcnt], &v, TG3_VER_SIZE - bcnt);
  9459. break;
  9460. }
  9461. memcpy(&tp->fw_ver[bcnt], &v, sizeof(v));
  9462. bcnt += sizeof(v);
  9463. }
  9464. tp->fw_ver[TG3_VER_SIZE - 1] = 0;
  9465. }
  9466. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
  9467. static int __devinit tg3_get_invariants(struct tg3 *tp)
  9468. {
  9469. static struct pci_device_id write_reorder_chipsets[] = {
  9470. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  9471. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  9472. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  9473. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  9474. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  9475. PCI_DEVICE_ID_VIA_8385_0) },
  9476. { },
  9477. };
  9478. u32 misc_ctrl_reg;
  9479. u32 cacheline_sz_reg;
  9480. u32 pci_state_reg, grc_misc_cfg;
  9481. u32 val;
  9482. u16 pci_cmd;
  9483. int err, pcie_cap;
  9484. /* Force memory write invalidate off. If we leave it on,
  9485. * then on 5700_BX chips we have to enable a workaround.
  9486. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  9487. * to match the cacheline size. The Broadcom driver have this
  9488. * workaround but turns MWI off all the times so never uses
  9489. * it. This seems to suggest that the workaround is insufficient.
  9490. */
  9491. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9492. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  9493. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9494. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  9495. * has the register indirect write enable bit set before
  9496. * we try to access any of the MMIO registers. It is also
  9497. * critical that the PCI-X hw workaround situation is decided
  9498. * before that as well.
  9499. */
  9500. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9501. &misc_ctrl_reg);
  9502. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  9503. MISC_HOST_CTRL_CHIPREV_SHIFT);
  9504. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) {
  9505. u32 prod_id_asic_rev;
  9506. pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV,
  9507. &prod_id_asic_rev);
  9508. tp->pci_chip_rev_id = prod_id_asic_rev & PROD_ID_ASIC_REV_MASK;
  9509. }
  9510. /* Wrong chip ID in 5752 A0. This code can be removed later
  9511. * as A0 is not in production.
  9512. */
  9513. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  9514. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  9515. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  9516. * we need to disable memory and use config. cycles
  9517. * only to access all registers. The 5702/03 chips
  9518. * can mistakenly decode the special cycles from the
  9519. * ICH chipsets as memory write cycles, causing corruption
  9520. * of register and memory space. Only certain ICH bridges
  9521. * will drive special cycles with non-zero data during the
  9522. * address phase which can fall within the 5703's address
  9523. * range. This is not an ICH bug as the PCI spec allows
  9524. * non-zero address during special cycles. However, only
  9525. * these ICH bridges are known to drive non-zero addresses
  9526. * during special cycles.
  9527. *
  9528. * Since special cycles do not cross PCI bridges, we only
  9529. * enable this workaround if the 5703 is on the secondary
  9530. * bus of these ICH bridges.
  9531. */
  9532. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  9533. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  9534. static struct tg3_dev_id {
  9535. u32 vendor;
  9536. u32 device;
  9537. u32 rev;
  9538. } ich_chipsets[] = {
  9539. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  9540. PCI_ANY_ID },
  9541. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  9542. PCI_ANY_ID },
  9543. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  9544. 0xa },
  9545. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  9546. PCI_ANY_ID },
  9547. { },
  9548. };
  9549. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  9550. struct pci_dev *bridge = NULL;
  9551. while (pci_id->vendor != 0) {
  9552. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  9553. bridge);
  9554. if (!bridge) {
  9555. pci_id++;
  9556. continue;
  9557. }
  9558. if (pci_id->rev != PCI_ANY_ID) {
  9559. if (bridge->revision > pci_id->rev)
  9560. continue;
  9561. }
  9562. if (bridge->subordinate &&
  9563. (bridge->subordinate->number ==
  9564. tp->pdev->bus->number)) {
  9565. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  9566. pci_dev_put(bridge);
  9567. break;
  9568. }
  9569. }
  9570. }
  9571. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  9572. static struct tg3_dev_id {
  9573. u32 vendor;
  9574. u32 device;
  9575. } bridge_chipsets[] = {
  9576. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 },
  9577. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 },
  9578. { },
  9579. };
  9580. struct tg3_dev_id *pci_id = &bridge_chipsets[0];
  9581. struct pci_dev *bridge = NULL;
  9582. while (pci_id->vendor != 0) {
  9583. bridge = pci_get_device(pci_id->vendor,
  9584. pci_id->device,
  9585. bridge);
  9586. if (!bridge) {
  9587. pci_id++;
  9588. continue;
  9589. }
  9590. if (bridge->subordinate &&
  9591. (bridge->subordinate->number <=
  9592. tp->pdev->bus->number) &&
  9593. (bridge->subordinate->subordinate >=
  9594. tp->pdev->bus->number)) {
  9595. tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG;
  9596. pci_dev_put(bridge);
  9597. break;
  9598. }
  9599. }
  9600. }
  9601. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  9602. * DMA addresses > 40-bit. This bridge may have other additional
  9603. * 57xx devices behind it in some 4-port NIC designs for example.
  9604. * Any tg3 device found behind the bridge will also need the 40-bit
  9605. * DMA workaround.
  9606. */
  9607. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  9608. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9609. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  9610. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  9611. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  9612. }
  9613. else {
  9614. struct pci_dev *bridge = NULL;
  9615. do {
  9616. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  9617. PCI_DEVICE_ID_SERVERWORKS_EPB,
  9618. bridge);
  9619. if (bridge && bridge->subordinate &&
  9620. (bridge->subordinate->number <=
  9621. tp->pdev->bus->number) &&
  9622. (bridge->subordinate->subordinate >=
  9623. tp->pdev->bus->number)) {
  9624. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  9625. pci_dev_put(bridge);
  9626. break;
  9627. }
  9628. } while (bridge);
  9629. }
  9630. /* Initialize misc host control in PCI block. */
  9631. tp->misc_host_ctrl |= (misc_ctrl_reg &
  9632. MISC_HOST_CTRL_CHIPREV);
  9633. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9634. tp->misc_host_ctrl);
  9635. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9636. &cacheline_sz_reg);
  9637. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  9638. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  9639. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  9640. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  9641. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9642. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  9643. tp->pdev_peer = tg3_find_peer(tp);
  9644. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9645. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9646. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9647. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9648. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9649. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  9650. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  9651. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9652. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  9653. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  9654. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  9655. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  9656. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  9657. tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
  9658. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
  9659. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
  9660. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
  9661. tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
  9662. tp->pdev_peer == tp->pdev))
  9663. tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
  9664. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9665. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9666. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9667. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  9668. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9669. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  9670. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  9671. } else {
  9672. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  9673. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9674. ASIC_REV_5750 &&
  9675. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  9676. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  9677. }
  9678. }
  9679. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  9680. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  9681. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  9682. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  9683. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  9684. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 &&
  9685. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761 &&
  9686. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9687. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  9688. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  9689. if (pcie_cap != 0) {
  9690. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  9691. pcie_set_readrq(tp->pdev, 4096);
  9692. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9693. u16 lnkctl;
  9694. pci_read_config_word(tp->pdev,
  9695. pcie_cap + PCI_EXP_LNKCTL,
  9696. &lnkctl);
  9697. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  9698. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  9699. }
  9700. }
  9701. /* If we have an AMD 762 or VIA K8T800 chipset, write
  9702. * reordering to the mailbox registers done by the host
  9703. * controller can cause major troubles. We read back from
  9704. * every mailbox register write to force the writes to be
  9705. * posted to the chip in order.
  9706. */
  9707. if (pci_dev_present(write_reorder_chipsets) &&
  9708. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9709. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  9710. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9711. tp->pci_lat_timer < 64) {
  9712. tp->pci_lat_timer = 64;
  9713. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  9714. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  9715. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  9716. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  9717. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9718. cacheline_sz_reg);
  9719. }
  9720. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  9721. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9722. tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX);
  9723. if (!tp->pcix_cap) {
  9724. printk(KERN_ERR PFX "Cannot find PCI-X "
  9725. "capability, aborting.\n");
  9726. return -EIO;
  9727. }
  9728. }
  9729. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9730. &pci_state_reg);
  9731. if (tp->pcix_cap && (pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  9732. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  9733. /* If this is a 5700 BX chipset, and we are in PCI-X
  9734. * mode, enable register write workaround.
  9735. *
  9736. * The workaround is to use indirect register accesses
  9737. * for all chip writes not to mailbox registers.
  9738. */
  9739. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  9740. u32 pm_reg;
  9741. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9742. /* The chip can have it's power management PCI config
  9743. * space registers clobbered due to this bug.
  9744. * So explicitly force the chip into D0 here.
  9745. */
  9746. pci_read_config_dword(tp->pdev,
  9747. tp->pm_cap + PCI_PM_CTRL,
  9748. &pm_reg);
  9749. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9750. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9751. pci_write_config_dword(tp->pdev,
  9752. tp->pm_cap + PCI_PM_CTRL,
  9753. pm_reg);
  9754. /* Also, force SERR#/PERR# in PCI command. */
  9755. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9756. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9757. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9758. }
  9759. }
  9760. /* 5700 BX chips need to have their TX producer index mailboxes
  9761. * written twice to workaround a bug.
  9762. */
  9763. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9764. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9765. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9766. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9767. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9768. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9769. /* Chip-specific fixup from Broadcom driver */
  9770. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9771. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9772. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9773. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9774. }
  9775. /* Default fast path register access methods */
  9776. tp->read32 = tg3_read32;
  9777. tp->write32 = tg3_write32;
  9778. tp->read32_mbox = tg3_read32;
  9779. tp->write32_mbox = tg3_write32;
  9780. tp->write32_tx_mbox = tg3_write32;
  9781. tp->write32_rx_mbox = tg3_write32;
  9782. /* Various workaround register access methods */
  9783. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9784. tp->write32 = tg3_write_indirect_reg32;
  9785. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9786. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9787. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
  9788. /*
  9789. * Back to back register writes can cause problems on these
  9790. * chips, the workaround is to read back all reg writes
  9791. * except those to mailbox regs.
  9792. *
  9793. * See tg3_write_indirect_reg32().
  9794. */
  9795. tp->write32 = tg3_write_flush_reg32;
  9796. }
  9797. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9798. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9799. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9800. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9801. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9802. }
  9803. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9804. tp->read32 = tg3_read_indirect_reg32;
  9805. tp->write32 = tg3_write_indirect_reg32;
  9806. tp->read32_mbox = tg3_read_indirect_mbox;
  9807. tp->write32_mbox = tg3_write_indirect_mbox;
  9808. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9809. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9810. iounmap(tp->regs);
  9811. tp->regs = NULL;
  9812. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9813. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9814. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9815. }
  9816. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9817. tp->read32_mbox = tg3_read32_mbox_5906;
  9818. tp->write32_mbox = tg3_write32_mbox_5906;
  9819. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9820. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9821. }
  9822. if (tp->write32 == tg3_write_indirect_reg32 ||
  9823. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9824. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9825. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9826. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9827. /* Get eeprom hw config before calling tg3_set_power_state().
  9828. * In particular, the TG3_FLG2_IS_NIC flag must be
  9829. * determined before calling tg3_set_power_state() so that
  9830. * we know whether or not to switch out of Vaux power.
  9831. * When the flag is set, it means that GPIO1 is used for eeprom
  9832. * write protect and also implies that it is a LOM where GPIOs
  9833. * are not used to switch power.
  9834. */
  9835. tg3_get_eeprom_hw_cfg(tp);
  9836. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  9837. /* Allow reads and writes to the
  9838. * APE register and memory space.
  9839. */
  9840. pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  9841. PCISTATE_ALLOW_APE_SHMEM_WR;
  9842. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9843. pci_state_reg);
  9844. }
  9845. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9846. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  9847. tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT;
  9848. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  9849. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1 ||
  9850. tp->pci_chip_rev_id == CHIPREV_ID_5761_A0 ||
  9851. tp->pci_chip_rev_id == CHIPREV_ID_5761_A1)
  9852. tp->tg3_flags3 |= TG3_FLG3_5761_5784_AX_FIXES;
  9853. }
  9854. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9855. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9856. * It is also used as eeprom write protect on LOMs.
  9857. */
  9858. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9859. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9860. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9861. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9862. GRC_LCLCTRL_GPIO_OUTPUT1);
  9863. /* Unused GPIO3 must be driven as output on 5752 because there
  9864. * are no pull-up resistors on unused GPIO pins.
  9865. */
  9866. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9867. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9868. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9869. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9870. /* Force the chip into D0. */
  9871. err = tg3_set_power_state(tp, PCI_D0);
  9872. if (err) {
  9873. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9874. pci_name(tp->pdev));
  9875. return err;
  9876. }
  9877. /* 5700 B0 chips do not support checksumming correctly due
  9878. * to hardware bugs.
  9879. */
  9880. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9881. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9882. /* Derive initial jumbo mode from MTU assigned in
  9883. * ether_setup() via the alloc_etherdev() call
  9884. */
  9885. if (tp->dev->mtu > ETH_DATA_LEN &&
  9886. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9887. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9888. /* Determine WakeOnLan speed to use. */
  9889. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9890. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9891. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9892. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9893. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9894. } else {
  9895. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9896. }
  9897. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9898. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9899. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9900. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9901. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9902. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9903. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9904. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9905. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9906. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9907. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9908. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9909. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9910. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9911. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9912. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9913. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9914. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  9915. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9916. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9917. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9918. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9919. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9920. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9921. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9922. }
  9923. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
  9924. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
  9925. tp->phy_otp = tg3_read_otp_phycfg(tp);
  9926. if (tp->phy_otp == 0)
  9927. tp->phy_otp = TG3_OTP_DEFAULT;
  9928. }
  9929. tp->coalesce_mode = 0;
  9930. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9931. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9932. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9933. /* Initialize MAC MI mode, polling disabled. */
  9934. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9935. udelay(80);
  9936. /* Initialize data/descriptor byte/word swapping. */
  9937. val = tr32(GRC_MODE);
  9938. val &= GRC_MODE_HOST_STACKUP;
  9939. tw32(GRC_MODE, val | tp->grc_mode);
  9940. tg3_switch_clocks(tp);
  9941. /* Clear this out for sanity. */
  9942. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9943. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9944. &pci_state_reg);
  9945. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9946. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9947. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9948. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9949. chiprevid == CHIPREV_ID_5701_B0 ||
  9950. chiprevid == CHIPREV_ID_5701_B2 ||
  9951. chiprevid == CHIPREV_ID_5701_B5) {
  9952. void __iomem *sram_base;
  9953. /* Write some dummy words into the SRAM status block
  9954. * area, see if it reads back correctly. If the return
  9955. * value is bad, force enable the PCIX workaround.
  9956. */
  9957. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9958. writel(0x00000000, sram_base);
  9959. writel(0x00000000, sram_base + 4);
  9960. writel(0xffffffff, sram_base + 4);
  9961. if (readl(sram_base) != 0x00000000)
  9962. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9963. }
  9964. }
  9965. udelay(50);
  9966. tg3_nvram_init(tp);
  9967. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9968. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9969. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9970. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9971. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9972. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9973. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9974. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9975. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9976. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9977. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9978. HOSTCC_MODE_CLRTICK_TXBD);
  9979. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9980. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9981. tp->misc_host_ctrl);
  9982. }
  9983. /* these are limited to 10/100 only */
  9984. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9985. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9986. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9987. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9988. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9989. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9990. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9991. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9992. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9993. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9994. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9995. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9996. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9997. err = tg3_phy_probe(tp);
  9998. if (err) {
  9999. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  10000. pci_name(tp->pdev), err);
  10001. /* ... but do not return immediately ... */
  10002. }
  10003. tg3_read_partno(tp);
  10004. tg3_read_fw_ver(tp);
  10005. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  10006. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  10007. } else {
  10008. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  10009. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  10010. else
  10011. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  10012. }
  10013. /* 5700 {AX,BX} chips have a broken status block link
  10014. * change bit implementation, so we must use the
  10015. * status register in those cases.
  10016. */
  10017. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  10018. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  10019. else
  10020. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  10021. /* The led_ctrl is set during tg3_phy_probe, here we might
  10022. * have to force the link status polling mechanism based
  10023. * upon subsystem IDs.
  10024. */
  10025. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  10026. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  10027. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  10028. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  10029. TG3_FLAG_USE_LINKCHG_REG);
  10030. }
  10031. /* For all SERDES we poll the MAC status register. */
  10032. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  10033. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  10034. else
  10035. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  10036. /* All chips before 5787 can get confused if TX buffers
  10037. * straddle the 4GB address boundary in some cases.
  10038. */
  10039. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10040. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  10041. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  10042. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  10043. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10044. tp->dev->hard_start_xmit = tg3_start_xmit;
  10045. else
  10046. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  10047. tp->rx_offset = 2;
  10048. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  10049. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  10050. tp->rx_offset = 0;
  10051. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  10052. /* Increment the rx prod index on the rx std ring by at most
  10053. * 8 for these chips to workaround hw errata.
  10054. */
  10055. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  10056. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  10057. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  10058. tp->rx_std_max_post = 8;
  10059. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND)
  10060. tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) &
  10061. PCIE_PWR_MGMT_L1_THRESH_MSK;
  10062. return err;
  10063. }
  10064. #ifdef CONFIG_SPARC
  10065. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  10066. {
  10067. struct net_device *dev = tp->dev;
  10068. struct pci_dev *pdev = tp->pdev;
  10069. struct device_node *dp = pci_device_to_OF_node(pdev);
  10070. const unsigned char *addr;
  10071. int len;
  10072. addr = of_get_property(dp, "local-mac-address", &len);
  10073. if (addr && len == 6) {
  10074. memcpy(dev->dev_addr, addr, 6);
  10075. memcpy(dev->perm_addr, dev->dev_addr, 6);
  10076. return 0;
  10077. }
  10078. return -ENODEV;
  10079. }
  10080. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  10081. {
  10082. struct net_device *dev = tp->dev;
  10083. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  10084. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  10085. return 0;
  10086. }
  10087. #endif
  10088. static int __devinit tg3_get_device_address(struct tg3 *tp)
  10089. {
  10090. struct net_device *dev = tp->dev;
  10091. u32 hi, lo, mac_offset;
  10092. int addr_ok = 0;
  10093. #ifdef CONFIG_SPARC
  10094. if (!tg3_get_macaddr_sparc(tp))
  10095. return 0;
  10096. #endif
  10097. mac_offset = 0x7c;
  10098. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  10099. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  10100. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  10101. mac_offset = 0xcc;
  10102. if (tg3_nvram_lock(tp))
  10103. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  10104. else
  10105. tg3_nvram_unlock(tp);
  10106. }
  10107. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10108. mac_offset = 0x10;
  10109. /* First try to get it from MAC address mailbox. */
  10110. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  10111. if ((hi >> 16) == 0x484b) {
  10112. dev->dev_addr[0] = (hi >> 8) & 0xff;
  10113. dev->dev_addr[1] = (hi >> 0) & 0xff;
  10114. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  10115. dev->dev_addr[2] = (lo >> 24) & 0xff;
  10116. dev->dev_addr[3] = (lo >> 16) & 0xff;
  10117. dev->dev_addr[4] = (lo >> 8) & 0xff;
  10118. dev->dev_addr[5] = (lo >> 0) & 0xff;
  10119. /* Some old bootcode may report a 0 MAC address in SRAM */
  10120. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  10121. }
  10122. if (!addr_ok) {
  10123. /* Next, try NVRAM. */
  10124. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  10125. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  10126. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  10127. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  10128. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  10129. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  10130. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  10131. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  10132. }
  10133. /* Finally just fetch it out of the MAC control regs. */
  10134. else {
  10135. hi = tr32(MAC_ADDR_0_HIGH);
  10136. lo = tr32(MAC_ADDR_0_LOW);
  10137. dev->dev_addr[5] = lo & 0xff;
  10138. dev->dev_addr[4] = (lo >> 8) & 0xff;
  10139. dev->dev_addr[3] = (lo >> 16) & 0xff;
  10140. dev->dev_addr[2] = (lo >> 24) & 0xff;
  10141. dev->dev_addr[1] = hi & 0xff;
  10142. dev->dev_addr[0] = (hi >> 8) & 0xff;
  10143. }
  10144. }
  10145. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  10146. #ifdef CONFIG_SPARC
  10147. if (!tg3_get_default_macaddr_sparc(tp))
  10148. return 0;
  10149. #endif
  10150. return -EINVAL;
  10151. }
  10152. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  10153. return 0;
  10154. }
  10155. #define BOUNDARY_SINGLE_CACHELINE 1
  10156. #define BOUNDARY_MULTI_CACHELINE 2
  10157. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  10158. {
  10159. int cacheline_size;
  10160. u8 byte;
  10161. int goal;
  10162. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  10163. if (byte == 0)
  10164. cacheline_size = 1024;
  10165. else
  10166. cacheline_size = (int) byte * 4;
  10167. /* On 5703 and later chips, the boundary bits have no
  10168. * effect.
  10169. */
  10170. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  10171. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  10172. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  10173. goto out;
  10174. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  10175. goal = BOUNDARY_MULTI_CACHELINE;
  10176. #else
  10177. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  10178. goal = BOUNDARY_SINGLE_CACHELINE;
  10179. #else
  10180. goal = 0;
  10181. #endif
  10182. #endif
  10183. if (!goal)
  10184. goto out;
  10185. /* PCI controllers on most RISC systems tend to disconnect
  10186. * when a device tries to burst across a cache-line boundary.
  10187. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  10188. *
  10189. * Unfortunately, for PCI-E there are only limited
  10190. * write-side controls for this, and thus for reads
  10191. * we will still get the disconnects. We'll also waste
  10192. * these PCI cycles for both read and write for chips
  10193. * other than 5700 and 5701 which do not implement the
  10194. * boundary bits.
  10195. */
  10196. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  10197. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  10198. switch (cacheline_size) {
  10199. case 16:
  10200. case 32:
  10201. case 64:
  10202. case 128:
  10203. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10204. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  10205. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  10206. } else {
  10207. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  10208. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  10209. }
  10210. break;
  10211. case 256:
  10212. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  10213. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  10214. break;
  10215. default:
  10216. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  10217. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  10218. break;
  10219. };
  10220. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10221. switch (cacheline_size) {
  10222. case 16:
  10223. case 32:
  10224. case 64:
  10225. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10226. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  10227. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  10228. break;
  10229. }
  10230. /* fallthrough */
  10231. case 128:
  10232. default:
  10233. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  10234. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  10235. break;
  10236. };
  10237. } else {
  10238. switch (cacheline_size) {
  10239. case 16:
  10240. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10241. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  10242. DMA_RWCTRL_WRITE_BNDRY_16);
  10243. break;
  10244. }
  10245. /* fallthrough */
  10246. case 32:
  10247. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10248. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  10249. DMA_RWCTRL_WRITE_BNDRY_32);
  10250. break;
  10251. }
  10252. /* fallthrough */
  10253. case 64:
  10254. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10255. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  10256. DMA_RWCTRL_WRITE_BNDRY_64);
  10257. break;
  10258. }
  10259. /* fallthrough */
  10260. case 128:
  10261. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10262. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  10263. DMA_RWCTRL_WRITE_BNDRY_128);
  10264. break;
  10265. }
  10266. /* fallthrough */
  10267. case 256:
  10268. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  10269. DMA_RWCTRL_WRITE_BNDRY_256);
  10270. break;
  10271. case 512:
  10272. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  10273. DMA_RWCTRL_WRITE_BNDRY_512);
  10274. break;
  10275. case 1024:
  10276. default:
  10277. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  10278. DMA_RWCTRL_WRITE_BNDRY_1024);
  10279. break;
  10280. };
  10281. }
  10282. out:
  10283. return val;
  10284. }
  10285. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  10286. {
  10287. struct tg3_internal_buffer_desc test_desc;
  10288. u32 sram_dma_descs;
  10289. int i, ret;
  10290. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  10291. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  10292. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  10293. tw32(RDMAC_STATUS, 0);
  10294. tw32(WDMAC_STATUS, 0);
  10295. tw32(BUFMGR_MODE, 0);
  10296. tw32(FTQ_RESET, 0);
  10297. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  10298. test_desc.addr_lo = buf_dma & 0xffffffff;
  10299. test_desc.nic_mbuf = 0x00002100;
  10300. test_desc.len = size;
  10301. /*
  10302. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  10303. * the *second* time the tg3 driver was getting loaded after an
  10304. * initial scan.
  10305. *
  10306. * Broadcom tells me:
  10307. * ...the DMA engine is connected to the GRC block and a DMA
  10308. * reset may affect the GRC block in some unpredictable way...
  10309. * The behavior of resets to individual blocks has not been tested.
  10310. *
  10311. * Broadcom noted the GRC reset will also reset all sub-components.
  10312. */
  10313. if (to_device) {
  10314. test_desc.cqid_sqid = (13 << 8) | 2;
  10315. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  10316. udelay(40);
  10317. } else {
  10318. test_desc.cqid_sqid = (16 << 8) | 7;
  10319. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  10320. udelay(40);
  10321. }
  10322. test_desc.flags = 0x00000005;
  10323. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  10324. u32 val;
  10325. val = *(((u32 *)&test_desc) + i);
  10326. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  10327. sram_dma_descs + (i * sizeof(u32)));
  10328. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  10329. }
  10330. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  10331. if (to_device) {
  10332. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  10333. } else {
  10334. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  10335. }
  10336. ret = -ENODEV;
  10337. for (i = 0; i < 40; i++) {
  10338. u32 val;
  10339. if (to_device)
  10340. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  10341. else
  10342. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  10343. if ((val & 0xffff) == sram_dma_descs) {
  10344. ret = 0;
  10345. break;
  10346. }
  10347. udelay(100);
  10348. }
  10349. return ret;
  10350. }
  10351. #define TEST_BUFFER_SIZE 0x2000
  10352. static int __devinit tg3_test_dma(struct tg3 *tp)
  10353. {
  10354. dma_addr_t buf_dma;
  10355. u32 *buf, saved_dma_rwctrl;
  10356. int ret;
  10357. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  10358. if (!buf) {
  10359. ret = -ENOMEM;
  10360. goto out_nofree;
  10361. }
  10362. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  10363. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  10364. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  10365. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10366. /* DMA read watermark not used on PCIE */
  10367. tp->dma_rwctrl |= 0x00180000;
  10368. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  10369. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  10370. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  10371. tp->dma_rwctrl |= 0x003f0000;
  10372. else
  10373. tp->dma_rwctrl |= 0x003f000f;
  10374. } else {
  10375. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  10376. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  10377. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  10378. u32 read_water = 0x7;
  10379. /* If the 5704 is behind the EPB bridge, we can
  10380. * do the less restrictive ONE_DMA workaround for
  10381. * better performance.
  10382. */
  10383. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  10384. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  10385. tp->dma_rwctrl |= 0x8000;
  10386. else if (ccval == 0x6 || ccval == 0x7)
  10387. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  10388. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  10389. read_water = 4;
  10390. /* Set bit 23 to enable PCIX hw bug fix */
  10391. tp->dma_rwctrl |=
  10392. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  10393. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  10394. (1 << 23);
  10395. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  10396. /* 5780 always in PCIX mode */
  10397. tp->dma_rwctrl |= 0x00144000;
  10398. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  10399. /* 5714 always in PCIX mode */
  10400. tp->dma_rwctrl |= 0x00148000;
  10401. } else {
  10402. tp->dma_rwctrl |= 0x001b000f;
  10403. }
  10404. }
  10405. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  10406. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  10407. tp->dma_rwctrl &= 0xfffffff0;
  10408. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10409. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  10410. /* Remove this if it causes problems for some boards. */
  10411. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  10412. /* On 5700/5701 chips, we need to set this bit.
  10413. * Otherwise the chip will issue cacheline transactions
  10414. * to streamable DMA memory with not all the byte
  10415. * enables turned on. This is an error on several
  10416. * RISC PCI controllers, in particular sparc64.
  10417. *
  10418. * On 5703/5704 chips, this bit has been reassigned
  10419. * a different meaning. In particular, it is used
  10420. * on those chips to enable a PCI-X workaround.
  10421. */
  10422. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  10423. }
  10424. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10425. #if 0
  10426. /* Unneeded, already done by tg3_get_invariants. */
  10427. tg3_switch_clocks(tp);
  10428. #endif
  10429. ret = 0;
  10430. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  10431. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  10432. goto out;
  10433. /* It is best to perform DMA test with maximum write burst size
  10434. * to expose the 5700/5701 write DMA bug.
  10435. */
  10436. saved_dma_rwctrl = tp->dma_rwctrl;
  10437. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10438. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10439. while (1) {
  10440. u32 *p = buf, i;
  10441. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  10442. p[i] = i;
  10443. /* Send the buffer to the chip. */
  10444. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  10445. if (ret) {
  10446. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  10447. break;
  10448. }
  10449. #if 0
  10450. /* validate data reached card RAM correctly. */
  10451. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  10452. u32 val;
  10453. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  10454. if (le32_to_cpu(val) != p[i]) {
  10455. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  10456. /* ret = -ENODEV here? */
  10457. }
  10458. p[i] = 0;
  10459. }
  10460. #endif
  10461. /* Now read it back. */
  10462. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  10463. if (ret) {
  10464. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  10465. break;
  10466. }
  10467. /* Verify it. */
  10468. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  10469. if (p[i] == i)
  10470. continue;
  10471. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  10472. DMA_RWCTRL_WRITE_BNDRY_16) {
  10473. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10474. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  10475. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10476. break;
  10477. } else {
  10478. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  10479. ret = -ENODEV;
  10480. goto out;
  10481. }
  10482. }
  10483. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  10484. /* Success. */
  10485. ret = 0;
  10486. break;
  10487. }
  10488. }
  10489. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  10490. DMA_RWCTRL_WRITE_BNDRY_16) {
  10491. static struct pci_device_id dma_wait_state_chipsets[] = {
  10492. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  10493. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  10494. { },
  10495. };
  10496. /* DMA test passed without adjusting DMA boundary,
  10497. * now look for chipsets that are known to expose the
  10498. * DMA bug without failing the test.
  10499. */
  10500. if (pci_dev_present(dma_wait_state_chipsets)) {
  10501. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10502. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  10503. }
  10504. else
  10505. /* Safe to use the calculated DMA boundary. */
  10506. tp->dma_rwctrl = saved_dma_rwctrl;
  10507. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10508. }
  10509. out:
  10510. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  10511. out_nofree:
  10512. return ret;
  10513. }
  10514. static void __devinit tg3_init_link_config(struct tg3 *tp)
  10515. {
  10516. tp->link_config.advertising =
  10517. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  10518. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  10519. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  10520. ADVERTISED_Autoneg | ADVERTISED_MII);
  10521. tp->link_config.speed = SPEED_INVALID;
  10522. tp->link_config.duplex = DUPLEX_INVALID;
  10523. tp->link_config.autoneg = AUTONEG_ENABLE;
  10524. tp->link_config.active_speed = SPEED_INVALID;
  10525. tp->link_config.active_duplex = DUPLEX_INVALID;
  10526. tp->link_config.phy_is_low_power = 0;
  10527. tp->link_config.orig_speed = SPEED_INVALID;
  10528. tp->link_config.orig_duplex = DUPLEX_INVALID;
  10529. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  10530. }
  10531. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  10532. {
  10533. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  10534. tp->bufmgr_config.mbuf_read_dma_low_water =
  10535. DEFAULT_MB_RDMA_LOW_WATER_5705;
  10536. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10537. DEFAULT_MB_MACRX_LOW_WATER_5705;
  10538. tp->bufmgr_config.mbuf_high_water =
  10539. DEFAULT_MB_HIGH_WATER_5705;
  10540. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  10541. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10542. DEFAULT_MB_MACRX_LOW_WATER_5906;
  10543. tp->bufmgr_config.mbuf_high_water =
  10544. DEFAULT_MB_HIGH_WATER_5906;
  10545. }
  10546. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  10547. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  10548. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  10549. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  10550. tp->bufmgr_config.mbuf_high_water_jumbo =
  10551. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  10552. } else {
  10553. tp->bufmgr_config.mbuf_read_dma_low_water =
  10554. DEFAULT_MB_RDMA_LOW_WATER;
  10555. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10556. DEFAULT_MB_MACRX_LOW_WATER;
  10557. tp->bufmgr_config.mbuf_high_water =
  10558. DEFAULT_MB_HIGH_WATER;
  10559. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  10560. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  10561. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  10562. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  10563. tp->bufmgr_config.mbuf_high_water_jumbo =
  10564. DEFAULT_MB_HIGH_WATER_JUMBO;
  10565. }
  10566. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  10567. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  10568. }
  10569. static char * __devinit tg3_phy_string(struct tg3 *tp)
  10570. {
  10571. switch (tp->phy_id & PHY_ID_MASK) {
  10572. case PHY_ID_BCM5400: return "5400";
  10573. case PHY_ID_BCM5401: return "5401";
  10574. case PHY_ID_BCM5411: return "5411";
  10575. case PHY_ID_BCM5701: return "5701";
  10576. case PHY_ID_BCM5703: return "5703";
  10577. case PHY_ID_BCM5704: return "5704";
  10578. case PHY_ID_BCM5705: return "5705";
  10579. case PHY_ID_BCM5750: return "5750";
  10580. case PHY_ID_BCM5752: return "5752";
  10581. case PHY_ID_BCM5714: return "5714";
  10582. case PHY_ID_BCM5780: return "5780";
  10583. case PHY_ID_BCM5755: return "5755";
  10584. case PHY_ID_BCM5787: return "5787";
  10585. case PHY_ID_BCM5784: return "5784";
  10586. case PHY_ID_BCM5756: return "5722/5756";
  10587. case PHY_ID_BCM5906: return "5906";
  10588. case PHY_ID_BCM5761: return "5761";
  10589. case PHY_ID_BCM8002: return "8002/serdes";
  10590. case 0: return "serdes";
  10591. default: return "unknown";
  10592. };
  10593. }
  10594. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  10595. {
  10596. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10597. strcpy(str, "PCI Express");
  10598. return str;
  10599. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  10600. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  10601. strcpy(str, "PCIX:");
  10602. if ((clock_ctrl == 7) ||
  10603. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  10604. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  10605. strcat(str, "133MHz");
  10606. else if (clock_ctrl == 0)
  10607. strcat(str, "33MHz");
  10608. else if (clock_ctrl == 2)
  10609. strcat(str, "50MHz");
  10610. else if (clock_ctrl == 4)
  10611. strcat(str, "66MHz");
  10612. else if (clock_ctrl == 6)
  10613. strcat(str, "100MHz");
  10614. } else {
  10615. strcpy(str, "PCI:");
  10616. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  10617. strcat(str, "66MHz");
  10618. else
  10619. strcat(str, "33MHz");
  10620. }
  10621. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  10622. strcat(str, ":32-bit");
  10623. else
  10624. strcat(str, ":64-bit");
  10625. return str;
  10626. }
  10627. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  10628. {
  10629. struct pci_dev *peer;
  10630. unsigned int func, devnr = tp->pdev->devfn & ~7;
  10631. for (func = 0; func < 8; func++) {
  10632. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  10633. if (peer && peer != tp->pdev)
  10634. break;
  10635. pci_dev_put(peer);
  10636. }
  10637. /* 5704 can be configured in single-port mode, set peer to
  10638. * tp->pdev in that case.
  10639. */
  10640. if (!peer) {
  10641. peer = tp->pdev;
  10642. return peer;
  10643. }
  10644. /*
  10645. * We don't need to keep the refcount elevated; there's no way
  10646. * to remove one half of this device without removing the other
  10647. */
  10648. pci_dev_put(peer);
  10649. return peer;
  10650. }
  10651. static void __devinit tg3_init_coal(struct tg3 *tp)
  10652. {
  10653. struct ethtool_coalesce *ec = &tp->coal;
  10654. memset(ec, 0, sizeof(*ec));
  10655. ec->cmd = ETHTOOL_GCOALESCE;
  10656. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  10657. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  10658. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  10659. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  10660. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  10661. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  10662. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  10663. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  10664. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  10665. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  10666. HOSTCC_MODE_CLRTICK_TXBD)) {
  10667. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  10668. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  10669. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  10670. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  10671. }
  10672. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  10673. ec->rx_coalesce_usecs_irq = 0;
  10674. ec->tx_coalesce_usecs_irq = 0;
  10675. ec->stats_block_coalesce_usecs = 0;
  10676. }
  10677. }
  10678. static int __devinit tg3_init_one(struct pci_dev *pdev,
  10679. const struct pci_device_id *ent)
  10680. {
  10681. static int tg3_version_printed = 0;
  10682. resource_size_t tg3reg_base;
  10683. unsigned long tg3reg_len;
  10684. struct net_device *dev;
  10685. struct tg3 *tp;
  10686. int err, pm_cap;
  10687. char str[40];
  10688. u64 dma_mask, persist_dma_mask;
  10689. DECLARE_MAC_BUF(mac);
  10690. if (tg3_version_printed++ == 0)
  10691. printk(KERN_INFO "%s", version);
  10692. err = pci_enable_device(pdev);
  10693. if (err) {
  10694. printk(KERN_ERR PFX "Cannot enable PCI device, "
  10695. "aborting.\n");
  10696. return err;
  10697. }
  10698. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10699. printk(KERN_ERR PFX "Cannot find proper PCI device "
  10700. "base address, aborting.\n");
  10701. err = -ENODEV;
  10702. goto err_out_disable_pdev;
  10703. }
  10704. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  10705. if (err) {
  10706. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  10707. "aborting.\n");
  10708. goto err_out_disable_pdev;
  10709. }
  10710. pci_set_master(pdev);
  10711. /* Find power-management capability. */
  10712. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  10713. if (pm_cap == 0) {
  10714. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  10715. "aborting.\n");
  10716. err = -EIO;
  10717. goto err_out_free_res;
  10718. }
  10719. tg3reg_base = pci_resource_start(pdev, 0);
  10720. tg3reg_len = pci_resource_len(pdev, 0);
  10721. dev = alloc_etherdev(sizeof(*tp));
  10722. if (!dev) {
  10723. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  10724. err = -ENOMEM;
  10725. goto err_out_free_res;
  10726. }
  10727. SET_NETDEV_DEV(dev, &pdev->dev);
  10728. #if TG3_VLAN_TAG_USED
  10729. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  10730. dev->vlan_rx_register = tg3_vlan_rx_register;
  10731. #endif
  10732. tp = netdev_priv(dev);
  10733. tp->pdev = pdev;
  10734. tp->dev = dev;
  10735. tp->pm_cap = pm_cap;
  10736. tp->mac_mode = TG3_DEF_MAC_MODE;
  10737. tp->rx_mode = TG3_DEF_RX_MODE;
  10738. tp->tx_mode = TG3_DEF_TX_MODE;
  10739. tp->mi_mode = MAC_MI_MODE_BASE;
  10740. if (tg3_debug > 0)
  10741. tp->msg_enable = tg3_debug;
  10742. else
  10743. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  10744. /* The word/byte swap controls here control register access byte
  10745. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  10746. * setting below.
  10747. */
  10748. tp->misc_host_ctrl =
  10749. MISC_HOST_CTRL_MASK_PCI_INT |
  10750. MISC_HOST_CTRL_WORD_SWAP |
  10751. MISC_HOST_CTRL_INDIR_ACCESS |
  10752. MISC_HOST_CTRL_PCISTATE_RW;
  10753. /* The NONFRM (non-frame) byte/word swap controls take effect
  10754. * on descriptor entries, anything which isn't packet data.
  10755. *
  10756. * The StrongARM chips on the board (one for tx, one for rx)
  10757. * are running in big-endian mode.
  10758. */
  10759. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  10760. GRC_MODE_WSWAP_NONFRM_DATA);
  10761. #ifdef __BIG_ENDIAN
  10762. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  10763. #endif
  10764. spin_lock_init(&tp->lock);
  10765. spin_lock_init(&tp->indirect_lock);
  10766. INIT_WORK(&tp->reset_task, tg3_reset_task);
  10767. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10768. if (!tp->regs) {
  10769. printk(KERN_ERR PFX "Cannot map device registers, "
  10770. "aborting.\n");
  10771. err = -ENOMEM;
  10772. goto err_out_free_dev;
  10773. }
  10774. tg3_init_link_config(tp);
  10775. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10776. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10777. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10778. dev->open = tg3_open;
  10779. dev->stop = tg3_close;
  10780. dev->get_stats = tg3_get_stats;
  10781. dev->set_multicast_list = tg3_set_rx_mode;
  10782. dev->set_mac_address = tg3_set_mac_addr;
  10783. dev->do_ioctl = tg3_ioctl;
  10784. dev->tx_timeout = tg3_tx_timeout;
  10785. netif_napi_add(dev, &tp->napi, tg3_poll, 64);
  10786. dev->ethtool_ops = &tg3_ethtool_ops;
  10787. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10788. dev->change_mtu = tg3_change_mtu;
  10789. dev->irq = pdev->irq;
  10790. #ifdef CONFIG_NET_POLL_CONTROLLER
  10791. dev->poll_controller = tg3_poll_controller;
  10792. #endif
  10793. err = tg3_get_invariants(tp);
  10794. if (err) {
  10795. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10796. "aborting.\n");
  10797. goto err_out_iounmap;
  10798. }
  10799. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10800. * device behind the EPB cannot support DMA addresses > 40-bit.
  10801. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10802. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10803. * do DMA address check in tg3_start_xmit().
  10804. */
  10805. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10806. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10807. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10808. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10809. #ifdef CONFIG_HIGHMEM
  10810. dma_mask = DMA_64BIT_MASK;
  10811. #endif
  10812. } else
  10813. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10814. /* Configure DMA attributes. */
  10815. if (dma_mask > DMA_32BIT_MASK) {
  10816. err = pci_set_dma_mask(pdev, dma_mask);
  10817. if (!err) {
  10818. dev->features |= NETIF_F_HIGHDMA;
  10819. err = pci_set_consistent_dma_mask(pdev,
  10820. persist_dma_mask);
  10821. if (err < 0) {
  10822. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10823. "DMA for consistent allocations\n");
  10824. goto err_out_iounmap;
  10825. }
  10826. }
  10827. }
  10828. if (err || dma_mask == DMA_32BIT_MASK) {
  10829. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10830. if (err) {
  10831. printk(KERN_ERR PFX "No usable DMA configuration, "
  10832. "aborting.\n");
  10833. goto err_out_iounmap;
  10834. }
  10835. }
  10836. tg3_init_bufmgr_config(tp);
  10837. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10838. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10839. }
  10840. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10841. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10842. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10843. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10844. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10845. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10846. } else {
  10847. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10848. }
  10849. /* TSO is on by default on chips that support hardware TSO.
  10850. * Firmware TSO on older chips gives lower performance, so it
  10851. * is off by default, but can be enabled using ethtool.
  10852. */
  10853. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10854. dev->features |= NETIF_F_TSO;
  10855. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10856. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10857. dev->features |= NETIF_F_TSO6;
  10858. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  10859. dev->features |= NETIF_F_TSO_ECN;
  10860. }
  10861. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10862. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10863. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10864. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10865. tp->rx_pending = 63;
  10866. }
  10867. err = tg3_get_device_address(tp);
  10868. if (err) {
  10869. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10870. "aborting.\n");
  10871. goto err_out_iounmap;
  10872. }
  10873. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  10874. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10875. printk(KERN_ERR PFX "Cannot find proper PCI device "
  10876. "base address for APE, aborting.\n");
  10877. err = -ENODEV;
  10878. goto err_out_iounmap;
  10879. }
  10880. tg3reg_base = pci_resource_start(pdev, 2);
  10881. tg3reg_len = pci_resource_len(pdev, 2);
  10882. tp->aperegs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10883. if (!tp->aperegs) {
  10884. printk(KERN_ERR PFX "Cannot map APE registers, "
  10885. "aborting.\n");
  10886. err = -ENOMEM;
  10887. goto err_out_iounmap;
  10888. }
  10889. tg3_ape_lock_init(tp);
  10890. }
  10891. /*
  10892. * Reset chip in case UNDI or EFI driver did not shutdown
  10893. * DMA self test will enable WDMAC and we'll see (spurious)
  10894. * pending DMA on the PCI bus at that point.
  10895. */
  10896. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10897. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10898. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10899. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10900. }
  10901. err = tg3_test_dma(tp);
  10902. if (err) {
  10903. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10904. goto err_out_apeunmap;
  10905. }
  10906. /* Tigon3 can do ipv4 only... and some chips have buggy
  10907. * checksumming.
  10908. */
  10909. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10910. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  10911. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10912. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  10913. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  10914. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  10915. dev->features |= NETIF_F_IPV6_CSUM;
  10916. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10917. } else
  10918. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10919. /* flow control autonegotiation is default behavior */
  10920. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10921. tp->link_config.flowctrl = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  10922. tg3_init_coal(tp);
  10923. pci_set_drvdata(pdev, dev);
  10924. err = register_netdev(dev);
  10925. if (err) {
  10926. printk(KERN_ERR PFX "Cannot register net device, "
  10927. "aborting.\n");
  10928. goto err_out_apeunmap;
  10929. }
  10930. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] "
  10931. "(%s) %s Ethernet %s\n",
  10932. dev->name,
  10933. tp->board_part_number,
  10934. tp->pci_chip_rev_id,
  10935. tg3_phy_string(tp),
  10936. tg3_bus_string(tp, str),
  10937. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10938. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10939. "10/100/1000Base-T")),
  10940. print_mac(mac, dev->dev_addr));
  10941. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10942. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10943. dev->name,
  10944. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10945. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10946. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10947. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10948. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10949. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10950. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10951. dev->name, tp->dma_rwctrl,
  10952. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10953. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10954. return 0;
  10955. err_out_apeunmap:
  10956. if (tp->aperegs) {
  10957. iounmap(tp->aperegs);
  10958. tp->aperegs = NULL;
  10959. }
  10960. err_out_iounmap:
  10961. if (tp->regs) {
  10962. iounmap(tp->regs);
  10963. tp->regs = NULL;
  10964. }
  10965. err_out_free_dev:
  10966. free_netdev(dev);
  10967. err_out_free_res:
  10968. pci_release_regions(pdev);
  10969. err_out_disable_pdev:
  10970. pci_disable_device(pdev);
  10971. pci_set_drvdata(pdev, NULL);
  10972. return err;
  10973. }
  10974. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10975. {
  10976. struct net_device *dev = pci_get_drvdata(pdev);
  10977. if (dev) {
  10978. struct tg3 *tp = netdev_priv(dev);
  10979. flush_scheduled_work();
  10980. unregister_netdev(dev);
  10981. if (tp->aperegs) {
  10982. iounmap(tp->aperegs);
  10983. tp->aperegs = NULL;
  10984. }
  10985. if (tp->regs) {
  10986. iounmap(tp->regs);
  10987. tp->regs = NULL;
  10988. }
  10989. free_netdev(dev);
  10990. pci_release_regions(pdev);
  10991. pci_disable_device(pdev);
  10992. pci_set_drvdata(pdev, NULL);
  10993. }
  10994. }
  10995. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10996. {
  10997. struct net_device *dev = pci_get_drvdata(pdev);
  10998. struct tg3 *tp = netdev_priv(dev);
  10999. int err;
  11000. /* PCI register 4 needs to be saved whether netif_running() or not.
  11001. * MSI address and data need to be saved if using MSI and
  11002. * netif_running().
  11003. */
  11004. pci_save_state(pdev);
  11005. if (!netif_running(dev))
  11006. return 0;
  11007. flush_scheduled_work();
  11008. tg3_netif_stop(tp);
  11009. del_timer_sync(&tp->timer);
  11010. tg3_full_lock(tp, 1);
  11011. tg3_disable_ints(tp);
  11012. tg3_full_unlock(tp);
  11013. netif_device_detach(dev);
  11014. tg3_full_lock(tp, 0);
  11015. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  11016. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  11017. tg3_full_unlock(tp);
  11018. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  11019. if (err) {
  11020. tg3_full_lock(tp, 0);
  11021. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  11022. if (tg3_restart_hw(tp, 1))
  11023. goto out;
  11024. tp->timer.expires = jiffies + tp->timer_offset;
  11025. add_timer(&tp->timer);
  11026. netif_device_attach(dev);
  11027. tg3_netif_start(tp);
  11028. out:
  11029. tg3_full_unlock(tp);
  11030. }
  11031. return err;
  11032. }
  11033. static int tg3_resume(struct pci_dev *pdev)
  11034. {
  11035. struct net_device *dev = pci_get_drvdata(pdev);
  11036. struct tg3 *tp = netdev_priv(dev);
  11037. int err;
  11038. pci_restore_state(tp->pdev);
  11039. if (!netif_running(dev))
  11040. return 0;
  11041. err = tg3_set_power_state(tp, PCI_D0);
  11042. if (err)
  11043. return err;
  11044. netif_device_attach(dev);
  11045. tg3_full_lock(tp, 0);
  11046. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  11047. err = tg3_restart_hw(tp, 1);
  11048. if (err)
  11049. goto out;
  11050. tp->timer.expires = jiffies + tp->timer_offset;
  11051. add_timer(&tp->timer);
  11052. tg3_netif_start(tp);
  11053. out:
  11054. tg3_full_unlock(tp);
  11055. return err;
  11056. }
  11057. static struct pci_driver tg3_driver = {
  11058. .name = DRV_MODULE_NAME,
  11059. .id_table = tg3_pci_tbl,
  11060. .probe = tg3_init_one,
  11061. .remove = __devexit_p(tg3_remove_one),
  11062. .suspend = tg3_suspend,
  11063. .resume = tg3_resume
  11064. };
  11065. static int __init tg3_init(void)
  11066. {
  11067. return pci_register_driver(&tg3_driver);
  11068. }
  11069. static void __exit tg3_cleanup(void)
  11070. {
  11071. pci_unregister_driver(&tg3_driver);
  11072. }
  11073. module_init(tg3_init);
  11074. module_exit(tg3_cleanup);