tg3.c 337 KB

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