tg3.c 349 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005-2007 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <net/ip.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/byteorder.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_SPARC
  46. #include <asm/idprom.h>
  47. #include <asm/prom.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #define TG3_TSO_SUPPORT 1
  55. #include "tg3.h"
  56. #define DRV_MODULE_NAME "tg3"
  57. #define PFX DRV_MODULE_NAME ": "
  58. #define DRV_MODULE_VERSION "3.78"
  59. #define DRV_MODULE_RELDATE "July 11, 2007"
  60. #define TG3_DEF_MAC_MODE 0
  61. #define TG3_DEF_RX_MODE 0
  62. #define TG3_DEF_TX_MODE 0
  63. #define TG3_DEF_MSG_ENABLE \
  64. (NETIF_MSG_DRV | \
  65. NETIF_MSG_PROBE | \
  66. NETIF_MSG_LINK | \
  67. NETIF_MSG_TIMER | \
  68. NETIF_MSG_IFDOWN | \
  69. NETIF_MSG_IFUP | \
  70. NETIF_MSG_RX_ERR | \
  71. NETIF_MSG_TX_ERR)
  72. /* length of time before we decide the hardware is borked,
  73. * and dev->tx_timeout() should be called to fix the problem
  74. */
  75. #define TG3_TX_TIMEOUT (5 * HZ)
  76. /* hardware minimum and maximum for a single frame's data payload */
  77. #define TG3_MIN_MTU 60
  78. #define TG3_MAX_MTU(tp) \
  79. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  80. /* These numbers seem to be hard coded in the NIC firmware somehow.
  81. * You can't change the ring sizes, but you can change where you place
  82. * them in the NIC onboard memory.
  83. */
  84. #define TG3_RX_RING_SIZE 512
  85. #define TG3_DEF_RX_RING_PENDING 200
  86. #define TG3_RX_JUMBO_RING_SIZE 256
  87. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  88. /* Do not place this n-ring entries value into the tp struct itself,
  89. * we really want to expose these constants to GCC so that modulo et
  90. * al. operations are done with shifts and masks instead of with
  91. * hw multiply/modulo instructions. Another solution would be to
  92. * replace things like '% foo' with '& (foo - 1)'.
  93. */
  94. #define TG3_RX_RCB_RING_SIZE(tp) \
  95. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  96. #define TG3_TX_RING_SIZE 512
  97. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  98. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  99. TG3_RX_RING_SIZE)
  100. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  101. TG3_RX_JUMBO_RING_SIZE)
  102. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RCB_RING_SIZE(tp))
  104. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  105. TG3_TX_RING_SIZE)
  106. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  107. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  108. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  109. /* minimum number of free TX descriptors required to wake up TX process */
  110. #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
  111. /* number of ETHTOOL_GSTATS u64's */
  112. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  113. #define TG3_NUM_TEST 6
  114. static char version[] __devinitdata =
  115. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  116. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  117. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  118. MODULE_LICENSE("GPL");
  119. MODULE_VERSION(DRV_MODULE_VERSION);
  120. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  121. module_param(tg3_debug, int, 0);
  122. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  123. static struct pci_device_id tg3_pci_tbl[] = {
  124. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  125. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  126. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  127. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  184. {}
  185. };
  186. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  187. static const struct {
  188. const char string[ETH_GSTRING_LEN];
  189. } ethtool_stats_keys[TG3_NUM_STATS] = {
  190. { "rx_octets" },
  191. { "rx_fragments" },
  192. { "rx_ucast_packets" },
  193. { "rx_mcast_packets" },
  194. { "rx_bcast_packets" },
  195. { "rx_fcs_errors" },
  196. { "rx_align_errors" },
  197. { "rx_xon_pause_rcvd" },
  198. { "rx_xoff_pause_rcvd" },
  199. { "rx_mac_ctrl_rcvd" },
  200. { "rx_xoff_entered" },
  201. { "rx_frame_too_long_errors" },
  202. { "rx_jabbers" },
  203. { "rx_undersize_packets" },
  204. { "rx_in_length_errors" },
  205. { "rx_out_length_errors" },
  206. { "rx_64_or_less_octet_packets" },
  207. { "rx_65_to_127_octet_packets" },
  208. { "rx_128_to_255_octet_packets" },
  209. { "rx_256_to_511_octet_packets" },
  210. { "rx_512_to_1023_octet_packets" },
  211. { "rx_1024_to_1522_octet_packets" },
  212. { "rx_1523_to_2047_octet_packets" },
  213. { "rx_2048_to_4095_octet_packets" },
  214. { "rx_4096_to_8191_octet_packets" },
  215. { "rx_8192_to_9022_octet_packets" },
  216. { "tx_octets" },
  217. { "tx_collisions" },
  218. { "tx_xon_sent" },
  219. { "tx_xoff_sent" },
  220. { "tx_flow_control" },
  221. { "tx_mac_errors" },
  222. { "tx_single_collisions" },
  223. { "tx_mult_collisions" },
  224. { "tx_deferred" },
  225. { "tx_excessive_collisions" },
  226. { "tx_late_collisions" },
  227. { "tx_collide_2times" },
  228. { "tx_collide_3times" },
  229. { "tx_collide_4times" },
  230. { "tx_collide_5times" },
  231. { "tx_collide_6times" },
  232. { "tx_collide_7times" },
  233. { "tx_collide_8times" },
  234. { "tx_collide_9times" },
  235. { "tx_collide_10times" },
  236. { "tx_collide_11times" },
  237. { "tx_collide_12times" },
  238. { "tx_collide_13times" },
  239. { "tx_collide_14times" },
  240. { "tx_collide_15times" },
  241. { "tx_ucast_packets" },
  242. { "tx_mcast_packets" },
  243. { "tx_bcast_packets" },
  244. { "tx_carrier_sense_errors" },
  245. { "tx_discards" },
  246. { "tx_errors" },
  247. { "dma_writeq_full" },
  248. { "dma_write_prioq_full" },
  249. { "rxbds_empty" },
  250. { "rx_discards" },
  251. { "rx_errors" },
  252. { "rx_threshold_hit" },
  253. { "dma_readq_full" },
  254. { "dma_read_prioq_full" },
  255. { "tx_comp_queue_full" },
  256. { "ring_set_send_prod_index" },
  257. { "ring_status_update" },
  258. { "nic_irqs" },
  259. { "nic_avoided_irqs" },
  260. { "nic_tx_threshold_hit" }
  261. };
  262. static const struct {
  263. const char string[ETH_GSTRING_LEN];
  264. } ethtool_test_keys[TG3_NUM_TEST] = {
  265. { "nvram test (online) " },
  266. { "link test (online) " },
  267. { "register test (offline)" },
  268. { "memory test (offline)" },
  269. { "loopback test (offline)" },
  270. { "interrupt test (offline)" },
  271. };
  272. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  273. {
  274. writel(val, tp->regs + off);
  275. }
  276. static u32 tg3_read32(struct tg3 *tp, u32 off)
  277. {
  278. return (readl(tp->regs + off));
  279. }
  280. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  281. {
  282. unsigned long flags;
  283. spin_lock_irqsave(&tp->indirect_lock, flags);
  284. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  285. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  286. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  287. }
  288. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  289. {
  290. writel(val, tp->regs + off);
  291. readl(tp->regs + off);
  292. }
  293. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  294. {
  295. unsigned long flags;
  296. u32 val;
  297. spin_lock_irqsave(&tp->indirect_lock, flags);
  298. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  299. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  300. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  301. return val;
  302. }
  303. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  304. {
  305. unsigned long flags;
  306. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  307. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  308. TG3_64BIT_REG_LOW, val);
  309. return;
  310. }
  311. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  312. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  313. TG3_64BIT_REG_LOW, val);
  314. return;
  315. }
  316. spin_lock_irqsave(&tp->indirect_lock, flags);
  317. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  318. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  319. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  320. /* In indirect mode when disabling interrupts, we also need
  321. * to clear the interrupt bit in the GRC local ctrl register.
  322. */
  323. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  324. (val == 0x1)) {
  325. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  326. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  327. }
  328. }
  329. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  330. {
  331. unsigned long flags;
  332. u32 val;
  333. spin_lock_irqsave(&tp->indirect_lock, flags);
  334. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  335. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  336. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  337. return val;
  338. }
  339. /* usec_wait specifies the wait time in usec when writing to certain registers
  340. * where it is unsafe to read back the register without some delay.
  341. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  342. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  343. */
  344. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  345. {
  346. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  347. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  348. /* Non-posted methods */
  349. tp->write32(tp, off, val);
  350. else {
  351. /* Posted method */
  352. tg3_write32(tp, off, val);
  353. if (usec_wait)
  354. udelay(usec_wait);
  355. tp->read32(tp, off);
  356. }
  357. /* Wait again after the read for the posted method to guarantee that
  358. * the wait time is met.
  359. */
  360. if (usec_wait)
  361. udelay(usec_wait);
  362. }
  363. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  364. {
  365. tp->write32_mbox(tp, off, val);
  366. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  367. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  368. tp->read32_mbox(tp, off);
  369. }
  370. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  371. {
  372. void __iomem *mbox = tp->regs + off;
  373. writel(val, mbox);
  374. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  375. writel(val, mbox);
  376. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  377. readl(mbox);
  378. }
  379. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  380. {
  381. return (readl(tp->regs + off + GRCMBOX_BASE));
  382. }
  383. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  384. {
  385. writel(val, tp->regs + off + GRCMBOX_BASE);
  386. }
  387. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  388. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  389. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  390. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  391. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  392. #define tw32(reg,val) tp->write32(tp, reg, val)
  393. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  394. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  395. #define tr32(reg) tp->read32(tp, reg)
  396. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  397. {
  398. unsigned long flags;
  399. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  400. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  401. return;
  402. spin_lock_irqsave(&tp->indirect_lock, flags);
  403. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  404. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  405. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  406. /* Always leave this as zero. */
  407. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  408. } else {
  409. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  410. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  411. /* Always leave this as zero. */
  412. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  413. }
  414. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  415. }
  416. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  417. {
  418. unsigned long flags;
  419. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  420. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  421. *val = 0;
  422. return;
  423. }
  424. spin_lock_irqsave(&tp->indirect_lock, flags);
  425. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  426. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  427. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  428. /* Always leave this as zero. */
  429. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  430. } else {
  431. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  432. *val = tr32(TG3PCI_MEM_WIN_DATA);
  433. /* Always leave this as zero. */
  434. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  435. }
  436. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  437. }
  438. static void tg3_disable_ints(struct tg3 *tp)
  439. {
  440. tw32(TG3PCI_MISC_HOST_CTRL,
  441. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  442. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  443. }
  444. static inline void tg3_cond_int(struct tg3 *tp)
  445. {
  446. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  447. (tp->hw_status->status & SD_STATUS_UPDATED))
  448. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  449. else
  450. tw32(HOSTCC_MODE, tp->coalesce_mode |
  451. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  452. }
  453. static void tg3_enable_ints(struct tg3 *tp)
  454. {
  455. tp->irq_sync = 0;
  456. wmb();
  457. tw32(TG3PCI_MISC_HOST_CTRL,
  458. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  459. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  460. (tp->last_tag << 24));
  461. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  462. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  463. (tp->last_tag << 24));
  464. tg3_cond_int(tp);
  465. }
  466. static inline unsigned int tg3_has_work(struct tg3 *tp)
  467. {
  468. struct tg3_hw_status *sblk = tp->hw_status;
  469. unsigned int work_exists = 0;
  470. /* check for phy events */
  471. if (!(tp->tg3_flags &
  472. (TG3_FLAG_USE_LINKCHG_REG |
  473. TG3_FLAG_POLL_SERDES))) {
  474. if (sblk->status & SD_STATUS_LINK_CHG)
  475. work_exists = 1;
  476. }
  477. /* check for RX/TX work to do */
  478. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  479. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  480. work_exists = 1;
  481. return work_exists;
  482. }
  483. /* tg3_restart_ints
  484. * similar to tg3_enable_ints, but it accurately determines whether there
  485. * is new work pending and can return without flushing the PIO write
  486. * which reenables interrupts
  487. */
  488. static void tg3_restart_ints(struct tg3 *tp)
  489. {
  490. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  491. tp->last_tag << 24);
  492. mmiowb();
  493. /* When doing tagged status, this work check is unnecessary.
  494. * The last_tag we write above tells the chip which piece of
  495. * work we've completed.
  496. */
  497. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  498. tg3_has_work(tp))
  499. tw32(HOSTCC_MODE, tp->coalesce_mode |
  500. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  501. }
  502. static inline void tg3_netif_stop(struct tg3 *tp)
  503. {
  504. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  505. netif_poll_disable(tp->dev);
  506. netif_tx_disable(tp->dev);
  507. }
  508. static inline void tg3_netif_start(struct tg3 *tp)
  509. {
  510. netif_wake_queue(tp->dev);
  511. /* NOTE: unconditional netif_wake_queue is only appropriate
  512. * so long as all callers are assured to have free tx slots
  513. * (such as after tg3_init_hw)
  514. */
  515. netif_poll_enable(tp->dev);
  516. tp->hw_status->status |= SD_STATUS_UPDATED;
  517. tg3_enable_ints(tp);
  518. }
  519. static void tg3_switch_clocks(struct tg3 *tp)
  520. {
  521. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  522. u32 orig_clock_ctrl;
  523. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  524. return;
  525. orig_clock_ctrl = clock_ctrl;
  526. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  527. CLOCK_CTRL_CLKRUN_OENABLE |
  528. 0x1f);
  529. tp->pci_clock_ctrl = clock_ctrl;
  530. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  531. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  532. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  533. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  534. }
  535. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  536. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  537. clock_ctrl |
  538. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  539. 40);
  540. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  541. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  542. 40);
  543. }
  544. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  545. }
  546. #define PHY_BUSY_LOOPS 5000
  547. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  548. {
  549. u32 frame_val;
  550. unsigned int loops;
  551. int ret;
  552. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  553. tw32_f(MAC_MI_MODE,
  554. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  555. udelay(80);
  556. }
  557. *val = 0x0;
  558. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  559. MI_COM_PHY_ADDR_MASK);
  560. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  561. MI_COM_REG_ADDR_MASK);
  562. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  563. tw32_f(MAC_MI_COM, frame_val);
  564. loops = PHY_BUSY_LOOPS;
  565. while (loops != 0) {
  566. udelay(10);
  567. frame_val = tr32(MAC_MI_COM);
  568. if ((frame_val & MI_COM_BUSY) == 0) {
  569. udelay(5);
  570. frame_val = tr32(MAC_MI_COM);
  571. break;
  572. }
  573. loops -= 1;
  574. }
  575. ret = -EBUSY;
  576. if (loops != 0) {
  577. *val = frame_val & MI_COM_DATA_MASK;
  578. ret = 0;
  579. }
  580. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  581. tw32_f(MAC_MI_MODE, tp->mi_mode);
  582. udelay(80);
  583. }
  584. return ret;
  585. }
  586. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  587. {
  588. u32 frame_val;
  589. unsigned int loops;
  590. int ret;
  591. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  592. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  593. return 0;
  594. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  595. tw32_f(MAC_MI_MODE,
  596. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  597. udelay(80);
  598. }
  599. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  600. MI_COM_PHY_ADDR_MASK);
  601. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  602. MI_COM_REG_ADDR_MASK);
  603. frame_val |= (val & MI_COM_DATA_MASK);
  604. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  605. tw32_f(MAC_MI_COM, frame_val);
  606. loops = PHY_BUSY_LOOPS;
  607. while (loops != 0) {
  608. udelay(10);
  609. frame_val = tr32(MAC_MI_COM);
  610. if ((frame_val & MI_COM_BUSY) == 0) {
  611. udelay(5);
  612. frame_val = tr32(MAC_MI_COM);
  613. break;
  614. }
  615. loops -= 1;
  616. }
  617. ret = -EBUSY;
  618. if (loops != 0)
  619. ret = 0;
  620. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  621. tw32_f(MAC_MI_MODE, tp->mi_mode);
  622. udelay(80);
  623. }
  624. return ret;
  625. }
  626. static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
  627. {
  628. u32 phy;
  629. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  630. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  631. return;
  632. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  633. u32 ephy;
  634. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &ephy)) {
  635. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  636. ephy | MII_TG3_EPHY_SHADOW_EN);
  637. if (!tg3_readphy(tp, MII_TG3_EPHYTST_MISCCTRL, &phy)) {
  638. if (enable)
  639. phy |= MII_TG3_EPHYTST_MISCCTRL_MDIX;
  640. else
  641. phy &= ~MII_TG3_EPHYTST_MISCCTRL_MDIX;
  642. tg3_writephy(tp, MII_TG3_EPHYTST_MISCCTRL, phy);
  643. }
  644. tg3_writephy(tp, MII_TG3_EPHY_TEST, ephy);
  645. }
  646. } else {
  647. phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
  648. MII_TG3_AUXCTL_SHDWSEL_MISC;
  649. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
  650. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
  651. if (enable)
  652. phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  653. else
  654. phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  655. phy |= MII_TG3_AUXCTL_MISC_WREN;
  656. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  657. }
  658. }
  659. }
  660. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  661. {
  662. u32 val;
  663. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  664. return;
  665. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  666. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  667. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  668. (val | (1 << 15) | (1 << 4)));
  669. }
  670. static int tg3_bmcr_reset(struct tg3 *tp)
  671. {
  672. u32 phy_control;
  673. int limit, err;
  674. /* OK, reset it, and poll the BMCR_RESET bit until it
  675. * clears or we time out.
  676. */
  677. phy_control = BMCR_RESET;
  678. err = tg3_writephy(tp, MII_BMCR, phy_control);
  679. if (err != 0)
  680. return -EBUSY;
  681. limit = 5000;
  682. while (limit--) {
  683. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  684. if (err != 0)
  685. return -EBUSY;
  686. if ((phy_control & BMCR_RESET) == 0) {
  687. udelay(40);
  688. break;
  689. }
  690. udelay(10);
  691. }
  692. if (limit <= 0)
  693. return -EBUSY;
  694. return 0;
  695. }
  696. static int tg3_wait_macro_done(struct tg3 *tp)
  697. {
  698. int limit = 100;
  699. while (limit--) {
  700. u32 tmp32;
  701. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  702. if ((tmp32 & 0x1000) == 0)
  703. break;
  704. }
  705. }
  706. if (limit <= 0)
  707. return -EBUSY;
  708. return 0;
  709. }
  710. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  711. {
  712. static const u32 test_pat[4][6] = {
  713. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  714. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  715. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  716. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  717. };
  718. int chan;
  719. for (chan = 0; chan < 4; chan++) {
  720. int i;
  721. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  722. (chan * 0x2000) | 0x0200);
  723. tg3_writephy(tp, 0x16, 0x0002);
  724. for (i = 0; i < 6; i++)
  725. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  726. test_pat[chan][i]);
  727. tg3_writephy(tp, 0x16, 0x0202);
  728. if (tg3_wait_macro_done(tp)) {
  729. *resetp = 1;
  730. return -EBUSY;
  731. }
  732. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  733. (chan * 0x2000) | 0x0200);
  734. tg3_writephy(tp, 0x16, 0x0082);
  735. if (tg3_wait_macro_done(tp)) {
  736. *resetp = 1;
  737. return -EBUSY;
  738. }
  739. tg3_writephy(tp, 0x16, 0x0802);
  740. if (tg3_wait_macro_done(tp)) {
  741. *resetp = 1;
  742. return -EBUSY;
  743. }
  744. for (i = 0; i < 6; i += 2) {
  745. u32 low, high;
  746. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  747. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  748. tg3_wait_macro_done(tp)) {
  749. *resetp = 1;
  750. return -EBUSY;
  751. }
  752. low &= 0x7fff;
  753. high &= 0x000f;
  754. if (low != test_pat[chan][i] ||
  755. high != test_pat[chan][i+1]) {
  756. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  757. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  758. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  759. return -EBUSY;
  760. }
  761. }
  762. }
  763. return 0;
  764. }
  765. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  766. {
  767. int chan;
  768. for (chan = 0; chan < 4; chan++) {
  769. int i;
  770. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  771. (chan * 0x2000) | 0x0200);
  772. tg3_writephy(tp, 0x16, 0x0002);
  773. for (i = 0; i < 6; i++)
  774. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  775. tg3_writephy(tp, 0x16, 0x0202);
  776. if (tg3_wait_macro_done(tp))
  777. return -EBUSY;
  778. }
  779. return 0;
  780. }
  781. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  782. {
  783. u32 reg32, phy9_orig;
  784. int retries, do_phy_reset, err;
  785. retries = 10;
  786. do_phy_reset = 1;
  787. do {
  788. if (do_phy_reset) {
  789. err = tg3_bmcr_reset(tp);
  790. if (err)
  791. return err;
  792. do_phy_reset = 0;
  793. }
  794. /* Disable transmitter and interrupt. */
  795. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  796. continue;
  797. reg32 |= 0x3000;
  798. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  799. /* Set full-duplex, 1000 mbps. */
  800. tg3_writephy(tp, MII_BMCR,
  801. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  802. /* Set to master mode. */
  803. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  804. continue;
  805. tg3_writephy(tp, MII_TG3_CTRL,
  806. (MII_TG3_CTRL_AS_MASTER |
  807. MII_TG3_CTRL_ENABLE_AS_MASTER));
  808. /* Enable SM_DSP_CLOCK and 6dB. */
  809. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  810. /* Block the PHY control access. */
  811. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  812. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  813. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  814. if (!err)
  815. break;
  816. } while (--retries);
  817. err = tg3_phy_reset_chanpat(tp);
  818. if (err)
  819. return err;
  820. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  821. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  822. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  823. tg3_writephy(tp, 0x16, 0x0000);
  824. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  825. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  826. /* Set Extended packet length bit for jumbo frames */
  827. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  828. }
  829. else {
  830. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  831. }
  832. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  833. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  834. reg32 &= ~0x3000;
  835. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  836. } else if (!err)
  837. err = -EBUSY;
  838. return err;
  839. }
  840. static void tg3_link_report(struct tg3 *);
  841. /* This will reset the tigon3 PHY if there is no valid
  842. * link unless the FORCE argument is non-zero.
  843. */
  844. static int tg3_phy_reset(struct tg3 *tp)
  845. {
  846. u32 phy_status;
  847. int err;
  848. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  849. u32 val;
  850. val = tr32(GRC_MISC_CFG);
  851. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  852. udelay(40);
  853. }
  854. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  855. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  856. if (err != 0)
  857. return -EBUSY;
  858. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  859. netif_carrier_off(tp->dev);
  860. tg3_link_report(tp);
  861. }
  862. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  863. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  864. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  865. err = tg3_phy_reset_5703_4_5(tp);
  866. if (err)
  867. return err;
  868. goto out;
  869. }
  870. err = tg3_bmcr_reset(tp);
  871. if (err)
  872. return err;
  873. out:
  874. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  875. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  876. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  877. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  878. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  879. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  880. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  881. }
  882. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  883. tg3_writephy(tp, 0x1c, 0x8d68);
  884. tg3_writephy(tp, 0x1c, 0x8d68);
  885. }
  886. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  887. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  888. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  889. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  890. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  891. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  892. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  893. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  894. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  895. }
  896. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  897. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  898. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  899. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  900. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  901. tg3_writephy(tp, MII_TG3_TEST1,
  902. MII_TG3_TEST1_TRIM_EN | 0x4);
  903. } else
  904. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  905. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  906. }
  907. /* Set Extended packet length bit (bit 14) on all chips that */
  908. /* support jumbo frames */
  909. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  910. /* Cannot do read-modify-write on 5401 */
  911. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  912. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  913. u32 phy_reg;
  914. /* Set bit 14 with read-modify-write to preserve other bits */
  915. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  916. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  917. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  918. }
  919. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  920. * jumbo frames transmission.
  921. */
  922. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  923. u32 phy_reg;
  924. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  925. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  926. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  927. }
  928. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  929. /* adjust output voltage */
  930. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  931. }
  932. tg3_phy_toggle_automdix(tp, 1);
  933. tg3_phy_set_wirespeed(tp);
  934. return 0;
  935. }
  936. static void tg3_frob_aux_power(struct tg3 *tp)
  937. {
  938. struct tg3 *tp_peer = tp;
  939. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  940. return;
  941. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  942. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  943. struct net_device *dev_peer;
  944. dev_peer = pci_get_drvdata(tp->pdev_peer);
  945. /* remove_one() may have been run on the peer. */
  946. if (!dev_peer)
  947. tp_peer = tp;
  948. else
  949. tp_peer = netdev_priv(dev_peer);
  950. }
  951. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  952. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  953. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  954. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  955. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  956. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  957. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  958. (GRC_LCLCTRL_GPIO_OE0 |
  959. GRC_LCLCTRL_GPIO_OE1 |
  960. GRC_LCLCTRL_GPIO_OE2 |
  961. GRC_LCLCTRL_GPIO_OUTPUT0 |
  962. GRC_LCLCTRL_GPIO_OUTPUT1),
  963. 100);
  964. } else {
  965. u32 no_gpio2;
  966. u32 grc_local_ctrl = 0;
  967. if (tp_peer != tp &&
  968. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  969. return;
  970. /* Workaround to prevent overdrawing Amps. */
  971. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  972. ASIC_REV_5714) {
  973. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  974. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  975. grc_local_ctrl, 100);
  976. }
  977. /* On 5753 and variants, GPIO2 cannot be used. */
  978. no_gpio2 = tp->nic_sram_data_cfg &
  979. NIC_SRAM_DATA_CFG_NO_GPIO2;
  980. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  981. GRC_LCLCTRL_GPIO_OE1 |
  982. GRC_LCLCTRL_GPIO_OE2 |
  983. GRC_LCLCTRL_GPIO_OUTPUT1 |
  984. GRC_LCLCTRL_GPIO_OUTPUT2;
  985. if (no_gpio2) {
  986. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  987. GRC_LCLCTRL_GPIO_OUTPUT2);
  988. }
  989. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  990. grc_local_ctrl, 100);
  991. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  992. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  993. grc_local_ctrl, 100);
  994. if (!no_gpio2) {
  995. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  996. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  997. grc_local_ctrl, 100);
  998. }
  999. }
  1000. } else {
  1001. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  1002. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  1003. if (tp_peer != tp &&
  1004. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1005. return;
  1006. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1007. (GRC_LCLCTRL_GPIO_OE1 |
  1008. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1009. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1010. GRC_LCLCTRL_GPIO_OE1, 100);
  1011. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1012. (GRC_LCLCTRL_GPIO_OE1 |
  1013. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1014. }
  1015. }
  1016. }
  1017. static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
  1018. {
  1019. if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
  1020. return 1;
  1021. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411) {
  1022. if (speed != SPEED_10)
  1023. return 1;
  1024. } else if (speed == SPEED_10)
  1025. return 1;
  1026. return 0;
  1027. }
  1028. static int tg3_setup_phy(struct tg3 *, int);
  1029. #define RESET_KIND_SHUTDOWN 0
  1030. #define RESET_KIND_INIT 1
  1031. #define RESET_KIND_SUSPEND 2
  1032. static void tg3_write_sig_post_reset(struct tg3 *, int);
  1033. static int tg3_halt_cpu(struct tg3 *, u32);
  1034. static int tg3_nvram_lock(struct tg3 *);
  1035. static void tg3_nvram_unlock(struct tg3 *);
  1036. static void tg3_power_down_phy(struct tg3 *tp)
  1037. {
  1038. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1039. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1040. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1041. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1042. sg_dig_ctrl |=
  1043. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1044. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1045. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1046. }
  1047. return;
  1048. }
  1049. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1050. u32 val;
  1051. tg3_bmcr_reset(tp);
  1052. val = tr32(GRC_MISC_CFG);
  1053. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1054. udelay(40);
  1055. return;
  1056. } else {
  1057. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1058. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1059. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1060. }
  1061. /* The PHY should not be powered down on some chips because
  1062. * of bugs.
  1063. */
  1064. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1065. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1066. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1067. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1068. return;
  1069. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1070. }
  1071. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1072. {
  1073. u32 misc_host_ctrl;
  1074. u16 power_control, power_caps;
  1075. int pm = tp->pm_cap;
  1076. /* Make sure register accesses (indirect or otherwise)
  1077. * will function correctly.
  1078. */
  1079. pci_write_config_dword(tp->pdev,
  1080. TG3PCI_MISC_HOST_CTRL,
  1081. tp->misc_host_ctrl);
  1082. pci_read_config_word(tp->pdev,
  1083. pm + PCI_PM_CTRL,
  1084. &power_control);
  1085. power_control |= PCI_PM_CTRL_PME_STATUS;
  1086. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1087. switch (state) {
  1088. case PCI_D0:
  1089. power_control |= 0;
  1090. pci_write_config_word(tp->pdev,
  1091. pm + PCI_PM_CTRL,
  1092. power_control);
  1093. udelay(100); /* Delay after power state change */
  1094. /* Switch out of Vaux if it is a NIC */
  1095. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1096. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1097. return 0;
  1098. case PCI_D1:
  1099. power_control |= 1;
  1100. break;
  1101. case PCI_D2:
  1102. power_control |= 2;
  1103. break;
  1104. case PCI_D3hot:
  1105. power_control |= 3;
  1106. break;
  1107. default:
  1108. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1109. "requested.\n",
  1110. tp->dev->name, state);
  1111. return -EINVAL;
  1112. };
  1113. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1114. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1115. tw32(TG3PCI_MISC_HOST_CTRL,
  1116. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1117. if (tp->link_config.phy_is_low_power == 0) {
  1118. tp->link_config.phy_is_low_power = 1;
  1119. tp->link_config.orig_speed = tp->link_config.speed;
  1120. tp->link_config.orig_duplex = tp->link_config.duplex;
  1121. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1122. }
  1123. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1124. tp->link_config.speed = SPEED_10;
  1125. tp->link_config.duplex = DUPLEX_HALF;
  1126. tp->link_config.autoneg = AUTONEG_ENABLE;
  1127. tg3_setup_phy(tp, 0);
  1128. }
  1129. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1130. u32 val;
  1131. val = tr32(GRC_VCPU_EXT_CTRL);
  1132. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1133. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1134. int i;
  1135. u32 val;
  1136. for (i = 0; i < 200; i++) {
  1137. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1138. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1139. break;
  1140. msleep(1);
  1141. }
  1142. }
  1143. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  1144. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1145. WOL_DRV_STATE_SHUTDOWN |
  1146. WOL_DRV_WOL |
  1147. WOL_SET_MAGIC_PKT);
  1148. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1149. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1150. u32 mac_mode;
  1151. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1152. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1153. udelay(40);
  1154. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1155. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1156. else
  1157. mac_mode = MAC_MODE_PORT_MODE_MII;
  1158. mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
  1159. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1160. ASIC_REV_5700) {
  1161. u32 speed = (tp->tg3_flags &
  1162. TG3_FLAG_WOL_SPEED_100MB) ?
  1163. SPEED_100 : SPEED_10;
  1164. if (tg3_5700_link_polarity(tp, speed))
  1165. mac_mode |= MAC_MODE_LINK_POLARITY;
  1166. else
  1167. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1168. }
  1169. } else {
  1170. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1171. }
  1172. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1173. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1174. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1175. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1176. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1177. tw32_f(MAC_MODE, mac_mode);
  1178. udelay(100);
  1179. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1180. udelay(10);
  1181. }
  1182. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1183. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1184. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1185. u32 base_val;
  1186. base_val = tp->pci_clock_ctrl;
  1187. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1188. CLOCK_CTRL_TXCLK_DISABLE);
  1189. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1190. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1191. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1192. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1193. /* do nothing */
  1194. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1195. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1196. u32 newbits1, newbits2;
  1197. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1198. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1199. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1200. CLOCK_CTRL_TXCLK_DISABLE |
  1201. CLOCK_CTRL_ALTCLK);
  1202. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1203. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1204. newbits1 = CLOCK_CTRL_625_CORE;
  1205. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1206. } else {
  1207. newbits1 = CLOCK_CTRL_ALTCLK;
  1208. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1209. }
  1210. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1211. 40);
  1212. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1213. 40);
  1214. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1215. u32 newbits3;
  1216. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1217. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1218. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1219. CLOCK_CTRL_TXCLK_DISABLE |
  1220. CLOCK_CTRL_44MHZ_CORE);
  1221. } else {
  1222. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1223. }
  1224. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1225. tp->pci_clock_ctrl | newbits3, 40);
  1226. }
  1227. }
  1228. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1229. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  1230. tg3_power_down_phy(tp);
  1231. tg3_frob_aux_power(tp);
  1232. /* Workaround for unstable PLL clock */
  1233. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1234. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1235. u32 val = tr32(0x7d00);
  1236. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1237. tw32(0x7d00, val);
  1238. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1239. int err;
  1240. err = tg3_nvram_lock(tp);
  1241. tg3_halt_cpu(tp, RX_CPU_BASE);
  1242. if (!err)
  1243. tg3_nvram_unlock(tp);
  1244. }
  1245. }
  1246. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1247. /* Finally, set the new power state. */
  1248. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1249. udelay(100); /* Delay after power state change */
  1250. return 0;
  1251. }
  1252. static void tg3_link_report(struct tg3 *tp)
  1253. {
  1254. if (!netif_carrier_ok(tp->dev)) {
  1255. if (netif_msg_link(tp))
  1256. printk(KERN_INFO PFX "%s: Link is down.\n",
  1257. tp->dev->name);
  1258. } else if (netif_msg_link(tp)) {
  1259. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  1260. tp->dev->name,
  1261. (tp->link_config.active_speed == SPEED_1000 ?
  1262. 1000 :
  1263. (tp->link_config.active_speed == SPEED_100 ?
  1264. 100 : 10)),
  1265. (tp->link_config.active_duplex == DUPLEX_FULL ?
  1266. "full" : "half"));
  1267. printk(KERN_INFO PFX "%s: Flow control is %s for TX and "
  1268. "%s for RX.\n",
  1269. tp->dev->name,
  1270. (tp->tg3_flags & TG3_FLAG_TX_PAUSE) ? "on" : "off",
  1271. (tp->tg3_flags & TG3_FLAG_RX_PAUSE) ? "on" : "off");
  1272. }
  1273. }
  1274. static void tg3_setup_flow_control(struct tg3 *tp, u32 local_adv, u32 remote_adv)
  1275. {
  1276. u32 new_tg3_flags = 0;
  1277. u32 old_rx_mode = tp->rx_mode;
  1278. u32 old_tx_mode = tp->tx_mode;
  1279. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) {
  1280. /* Convert 1000BaseX flow control bits to 1000BaseT
  1281. * bits before resolving flow control.
  1282. */
  1283. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  1284. local_adv &= ~(ADVERTISE_PAUSE_CAP |
  1285. ADVERTISE_PAUSE_ASYM);
  1286. remote_adv &= ~(LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1287. if (local_adv & ADVERTISE_1000XPAUSE)
  1288. local_adv |= ADVERTISE_PAUSE_CAP;
  1289. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  1290. local_adv |= ADVERTISE_PAUSE_ASYM;
  1291. if (remote_adv & LPA_1000XPAUSE)
  1292. remote_adv |= LPA_PAUSE_CAP;
  1293. if (remote_adv & LPA_1000XPAUSE_ASYM)
  1294. remote_adv |= LPA_PAUSE_ASYM;
  1295. }
  1296. if (local_adv & ADVERTISE_PAUSE_CAP) {
  1297. if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1298. if (remote_adv & LPA_PAUSE_CAP)
  1299. new_tg3_flags |=
  1300. (TG3_FLAG_RX_PAUSE |
  1301. TG3_FLAG_TX_PAUSE);
  1302. else if (remote_adv & LPA_PAUSE_ASYM)
  1303. new_tg3_flags |=
  1304. (TG3_FLAG_RX_PAUSE);
  1305. } else {
  1306. if (remote_adv & LPA_PAUSE_CAP)
  1307. new_tg3_flags |=
  1308. (TG3_FLAG_RX_PAUSE |
  1309. TG3_FLAG_TX_PAUSE);
  1310. }
  1311. } else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  1312. if ((remote_adv & LPA_PAUSE_CAP) &&
  1313. (remote_adv & LPA_PAUSE_ASYM))
  1314. new_tg3_flags |= TG3_FLAG_TX_PAUSE;
  1315. }
  1316. tp->tg3_flags &= ~(TG3_FLAG_RX_PAUSE | TG3_FLAG_TX_PAUSE);
  1317. tp->tg3_flags |= new_tg3_flags;
  1318. } else {
  1319. new_tg3_flags = tp->tg3_flags;
  1320. }
  1321. if (new_tg3_flags & TG3_FLAG_RX_PAUSE)
  1322. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  1323. else
  1324. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  1325. if (old_rx_mode != tp->rx_mode) {
  1326. tw32_f(MAC_RX_MODE, tp->rx_mode);
  1327. }
  1328. if (new_tg3_flags & TG3_FLAG_TX_PAUSE)
  1329. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  1330. else
  1331. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  1332. if (old_tx_mode != tp->tx_mode) {
  1333. tw32_f(MAC_TX_MODE, tp->tx_mode);
  1334. }
  1335. }
  1336. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1337. {
  1338. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1339. case MII_TG3_AUX_STAT_10HALF:
  1340. *speed = SPEED_10;
  1341. *duplex = DUPLEX_HALF;
  1342. break;
  1343. case MII_TG3_AUX_STAT_10FULL:
  1344. *speed = SPEED_10;
  1345. *duplex = DUPLEX_FULL;
  1346. break;
  1347. case MII_TG3_AUX_STAT_100HALF:
  1348. *speed = SPEED_100;
  1349. *duplex = DUPLEX_HALF;
  1350. break;
  1351. case MII_TG3_AUX_STAT_100FULL:
  1352. *speed = SPEED_100;
  1353. *duplex = DUPLEX_FULL;
  1354. break;
  1355. case MII_TG3_AUX_STAT_1000HALF:
  1356. *speed = SPEED_1000;
  1357. *duplex = DUPLEX_HALF;
  1358. break;
  1359. case MII_TG3_AUX_STAT_1000FULL:
  1360. *speed = SPEED_1000;
  1361. *duplex = DUPLEX_FULL;
  1362. break;
  1363. default:
  1364. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1365. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1366. SPEED_10;
  1367. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1368. DUPLEX_HALF;
  1369. break;
  1370. }
  1371. *speed = SPEED_INVALID;
  1372. *duplex = DUPLEX_INVALID;
  1373. break;
  1374. };
  1375. }
  1376. static void tg3_phy_copper_begin(struct tg3 *tp)
  1377. {
  1378. u32 new_adv;
  1379. int i;
  1380. if (tp->link_config.phy_is_low_power) {
  1381. /* Entering low power mode. Disable gigabit and
  1382. * 100baseT advertisements.
  1383. */
  1384. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1385. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1386. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1387. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1388. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1389. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1390. } else if (tp->link_config.speed == SPEED_INVALID) {
  1391. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1392. tp->link_config.advertising &=
  1393. ~(ADVERTISED_1000baseT_Half |
  1394. ADVERTISED_1000baseT_Full);
  1395. new_adv = (ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1396. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1397. new_adv |= ADVERTISE_10HALF;
  1398. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1399. new_adv |= ADVERTISE_10FULL;
  1400. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1401. new_adv |= ADVERTISE_100HALF;
  1402. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1403. new_adv |= ADVERTISE_100FULL;
  1404. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1405. if (tp->link_config.advertising &
  1406. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1407. new_adv = 0;
  1408. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1409. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1410. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1411. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1412. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1413. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1414. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1415. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1416. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1417. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1418. } else {
  1419. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1420. }
  1421. } else {
  1422. /* Asking for a specific link mode. */
  1423. if (tp->link_config.speed == SPEED_1000) {
  1424. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1425. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1426. if (tp->link_config.duplex == DUPLEX_FULL)
  1427. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1428. else
  1429. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1430. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1431. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1432. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1433. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1434. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1435. } else {
  1436. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1437. new_adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
  1438. if (tp->link_config.speed == SPEED_100) {
  1439. if (tp->link_config.duplex == DUPLEX_FULL)
  1440. new_adv |= ADVERTISE_100FULL;
  1441. else
  1442. new_adv |= ADVERTISE_100HALF;
  1443. } else {
  1444. if (tp->link_config.duplex == DUPLEX_FULL)
  1445. new_adv |= ADVERTISE_10FULL;
  1446. else
  1447. new_adv |= ADVERTISE_10HALF;
  1448. }
  1449. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1450. }
  1451. }
  1452. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1453. tp->link_config.speed != SPEED_INVALID) {
  1454. u32 bmcr, orig_bmcr;
  1455. tp->link_config.active_speed = tp->link_config.speed;
  1456. tp->link_config.active_duplex = tp->link_config.duplex;
  1457. bmcr = 0;
  1458. switch (tp->link_config.speed) {
  1459. default:
  1460. case SPEED_10:
  1461. break;
  1462. case SPEED_100:
  1463. bmcr |= BMCR_SPEED100;
  1464. break;
  1465. case SPEED_1000:
  1466. bmcr |= TG3_BMCR_SPEED1000;
  1467. break;
  1468. };
  1469. if (tp->link_config.duplex == DUPLEX_FULL)
  1470. bmcr |= BMCR_FULLDPLX;
  1471. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1472. (bmcr != orig_bmcr)) {
  1473. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1474. for (i = 0; i < 1500; i++) {
  1475. u32 tmp;
  1476. udelay(10);
  1477. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1478. tg3_readphy(tp, MII_BMSR, &tmp))
  1479. continue;
  1480. if (!(tmp & BMSR_LSTATUS)) {
  1481. udelay(40);
  1482. break;
  1483. }
  1484. }
  1485. tg3_writephy(tp, MII_BMCR, bmcr);
  1486. udelay(40);
  1487. }
  1488. } else {
  1489. tg3_writephy(tp, MII_BMCR,
  1490. BMCR_ANENABLE | BMCR_ANRESTART);
  1491. }
  1492. }
  1493. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1494. {
  1495. int err;
  1496. /* Turn off tap power management. */
  1497. /* Set Extended packet length bit */
  1498. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1499. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1500. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1501. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1502. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1503. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1504. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1505. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1506. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1507. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1508. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1509. udelay(40);
  1510. return err;
  1511. }
  1512. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1513. {
  1514. u32 adv_reg, all_mask = 0;
  1515. if (mask & ADVERTISED_10baseT_Half)
  1516. all_mask |= ADVERTISE_10HALF;
  1517. if (mask & ADVERTISED_10baseT_Full)
  1518. all_mask |= ADVERTISE_10FULL;
  1519. if (mask & ADVERTISED_100baseT_Half)
  1520. all_mask |= ADVERTISE_100HALF;
  1521. if (mask & ADVERTISED_100baseT_Full)
  1522. all_mask |= ADVERTISE_100FULL;
  1523. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1524. return 0;
  1525. if ((adv_reg & all_mask) != all_mask)
  1526. return 0;
  1527. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1528. u32 tg3_ctrl;
  1529. all_mask = 0;
  1530. if (mask & ADVERTISED_1000baseT_Half)
  1531. all_mask |= ADVERTISE_1000HALF;
  1532. if (mask & ADVERTISED_1000baseT_Full)
  1533. all_mask |= ADVERTISE_1000FULL;
  1534. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1535. return 0;
  1536. if ((tg3_ctrl & all_mask) != all_mask)
  1537. return 0;
  1538. }
  1539. return 1;
  1540. }
  1541. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1542. {
  1543. int current_link_up;
  1544. u32 bmsr, dummy;
  1545. u16 current_speed;
  1546. u8 current_duplex;
  1547. int i, err;
  1548. tw32(MAC_EVENT, 0);
  1549. tw32_f(MAC_STATUS,
  1550. (MAC_STATUS_SYNC_CHANGED |
  1551. MAC_STATUS_CFG_CHANGED |
  1552. MAC_STATUS_MI_COMPLETION |
  1553. MAC_STATUS_LNKSTATE_CHANGED));
  1554. udelay(40);
  1555. tp->mi_mode = MAC_MI_MODE_BASE;
  1556. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1557. udelay(80);
  1558. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1559. /* Some third-party PHYs need to be reset on link going
  1560. * down.
  1561. */
  1562. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1563. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1564. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1565. netif_carrier_ok(tp->dev)) {
  1566. tg3_readphy(tp, MII_BMSR, &bmsr);
  1567. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1568. !(bmsr & BMSR_LSTATUS))
  1569. force_reset = 1;
  1570. }
  1571. if (force_reset)
  1572. tg3_phy_reset(tp);
  1573. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1574. tg3_readphy(tp, MII_BMSR, &bmsr);
  1575. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1576. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1577. bmsr = 0;
  1578. if (!(bmsr & BMSR_LSTATUS)) {
  1579. err = tg3_init_5401phy_dsp(tp);
  1580. if (err)
  1581. return err;
  1582. tg3_readphy(tp, MII_BMSR, &bmsr);
  1583. for (i = 0; i < 1000; i++) {
  1584. udelay(10);
  1585. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1586. (bmsr & BMSR_LSTATUS)) {
  1587. udelay(40);
  1588. break;
  1589. }
  1590. }
  1591. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1592. !(bmsr & BMSR_LSTATUS) &&
  1593. tp->link_config.active_speed == SPEED_1000) {
  1594. err = tg3_phy_reset(tp);
  1595. if (!err)
  1596. err = tg3_init_5401phy_dsp(tp);
  1597. if (err)
  1598. return err;
  1599. }
  1600. }
  1601. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1602. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1603. /* 5701 {A0,B0} CRC bug workaround */
  1604. tg3_writephy(tp, 0x15, 0x0a75);
  1605. tg3_writephy(tp, 0x1c, 0x8c68);
  1606. tg3_writephy(tp, 0x1c, 0x8d68);
  1607. tg3_writephy(tp, 0x1c, 0x8c68);
  1608. }
  1609. /* Clear pending interrupts... */
  1610. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1611. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1612. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1613. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1614. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1615. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1616. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1617. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1618. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1619. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1620. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1621. else
  1622. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1623. }
  1624. current_link_up = 0;
  1625. current_speed = SPEED_INVALID;
  1626. current_duplex = DUPLEX_INVALID;
  1627. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1628. u32 val;
  1629. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1630. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1631. if (!(val & (1 << 10))) {
  1632. val |= (1 << 10);
  1633. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1634. goto relink;
  1635. }
  1636. }
  1637. bmsr = 0;
  1638. for (i = 0; i < 100; i++) {
  1639. tg3_readphy(tp, MII_BMSR, &bmsr);
  1640. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1641. (bmsr & BMSR_LSTATUS))
  1642. break;
  1643. udelay(40);
  1644. }
  1645. if (bmsr & BMSR_LSTATUS) {
  1646. u32 aux_stat, bmcr;
  1647. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1648. for (i = 0; i < 2000; i++) {
  1649. udelay(10);
  1650. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1651. aux_stat)
  1652. break;
  1653. }
  1654. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1655. &current_speed,
  1656. &current_duplex);
  1657. bmcr = 0;
  1658. for (i = 0; i < 200; i++) {
  1659. tg3_readphy(tp, MII_BMCR, &bmcr);
  1660. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1661. continue;
  1662. if (bmcr && bmcr != 0x7fff)
  1663. break;
  1664. udelay(10);
  1665. }
  1666. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1667. if (bmcr & BMCR_ANENABLE) {
  1668. current_link_up = 1;
  1669. /* Force autoneg restart if we are exiting
  1670. * low power mode.
  1671. */
  1672. if (!tg3_copper_is_advertising_all(tp,
  1673. tp->link_config.advertising))
  1674. current_link_up = 0;
  1675. } else {
  1676. current_link_up = 0;
  1677. }
  1678. } else {
  1679. if (!(bmcr & BMCR_ANENABLE) &&
  1680. tp->link_config.speed == current_speed &&
  1681. tp->link_config.duplex == current_duplex) {
  1682. current_link_up = 1;
  1683. } else {
  1684. current_link_up = 0;
  1685. }
  1686. }
  1687. tp->link_config.active_speed = current_speed;
  1688. tp->link_config.active_duplex = current_duplex;
  1689. }
  1690. if (current_link_up == 1 &&
  1691. (tp->link_config.active_duplex == DUPLEX_FULL) &&
  1692. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  1693. u32 local_adv, remote_adv;
  1694. if (tg3_readphy(tp, MII_ADVERTISE, &local_adv))
  1695. local_adv = 0;
  1696. local_adv &= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1697. if (tg3_readphy(tp, MII_LPA, &remote_adv))
  1698. remote_adv = 0;
  1699. remote_adv &= (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  1700. /* If we are not advertising full pause capability,
  1701. * something is wrong. Bring the link down and reconfigure.
  1702. */
  1703. if (local_adv != ADVERTISE_PAUSE_CAP) {
  1704. current_link_up = 0;
  1705. } else {
  1706. tg3_setup_flow_control(tp, local_adv, remote_adv);
  1707. }
  1708. }
  1709. relink:
  1710. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1711. u32 tmp;
  1712. tg3_phy_copper_begin(tp);
  1713. tg3_readphy(tp, MII_BMSR, &tmp);
  1714. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1715. (tmp & BMSR_LSTATUS))
  1716. current_link_up = 1;
  1717. }
  1718. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1719. if (current_link_up == 1) {
  1720. if (tp->link_config.active_speed == SPEED_100 ||
  1721. tp->link_config.active_speed == SPEED_10)
  1722. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1723. else
  1724. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1725. } else
  1726. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1727. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1728. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1729. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1730. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1731. if (current_link_up == 1 &&
  1732. tg3_5700_link_polarity(tp, tp->link_config.active_speed))
  1733. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1734. else
  1735. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1736. }
  1737. /* ??? Without this setting Netgear GA302T PHY does not
  1738. * ??? send/receive packets...
  1739. */
  1740. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1741. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1742. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1743. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1744. udelay(80);
  1745. }
  1746. tw32_f(MAC_MODE, tp->mac_mode);
  1747. udelay(40);
  1748. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1749. /* Polled via timer. */
  1750. tw32_f(MAC_EVENT, 0);
  1751. } else {
  1752. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1753. }
  1754. udelay(40);
  1755. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1756. current_link_up == 1 &&
  1757. tp->link_config.active_speed == SPEED_1000 &&
  1758. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1759. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1760. udelay(120);
  1761. tw32_f(MAC_STATUS,
  1762. (MAC_STATUS_SYNC_CHANGED |
  1763. MAC_STATUS_CFG_CHANGED));
  1764. udelay(40);
  1765. tg3_write_mem(tp,
  1766. NIC_SRAM_FIRMWARE_MBOX,
  1767. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  1768. }
  1769. if (current_link_up != netif_carrier_ok(tp->dev)) {
  1770. if (current_link_up)
  1771. netif_carrier_on(tp->dev);
  1772. else
  1773. netif_carrier_off(tp->dev);
  1774. tg3_link_report(tp);
  1775. }
  1776. return 0;
  1777. }
  1778. struct tg3_fiber_aneginfo {
  1779. int state;
  1780. #define ANEG_STATE_UNKNOWN 0
  1781. #define ANEG_STATE_AN_ENABLE 1
  1782. #define ANEG_STATE_RESTART_INIT 2
  1783. #define ANEG_STATE_RESTART 3
  1784. #define ANEG_STATE_DISABLE_LINK_OK 4
  1785. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  1786. #define ANEG_STATE_ABILITY_DETECT 6
  1787. #define ANEG_STATE_ACK_DETECT_INIT 7
  1788. #define ANEG_STATE_ACK_DETECT 8
  1789. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  1790. #define ANEG_STATE_COMPLETE_ACK 10
  1791. #define ANEG_STATE_IDLE_DETECT_INIT 11
  1792. #define ANEG_STATE_IDLE_DETECT 12
  1793. #define ANEG_STATE_LINK_OK 13
  1794. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  1795. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  1796. u32 flags;
  1797. #define MR_AN_ENABLE 0x00000001
  1798. #define MR_RESTART_AN 0x00000002
  1799. #define MR_AN_COMPLETE 0x00000004
  1800. #define MR_PAGE_RX 0x00000008
  1801. #define MR_NP_LOADED 0x00000010
  1802. #define MR_TOGGLE_TX 0x00000020
  1803. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  1804. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  1805. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  1806. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  1807. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  1808. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  1809. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  1810. #define MR_TOGGLE_RX 0x00002000
  1811. #define MR_NP_RX 0x00004000
  1812. #define MR_LINK_OK 0x80000000
  1813. unsigned long link_time, cur_time;
  1814. u32 ability_match_cfg;
  1815. int ability_match_count;
  1816. char ability_match, idle_match, ack_match;
  1817. u32 txconfig, rxconfig;
  1818. #define ANEG_CFG_NP 0x00000080
  1819. #define ANEG_CFG_ACK 0x00000040
  1820. #define ANEG_CFG_RF2 0x00000020
  1821. #define ANEG_CFG_RF1 0x00000010
  1822. #define ANEG_CFG_PS2 0x00000001
  1823. #define ANEG_CFG_PS1 0x00008000
  1824. #define ANEG_CFG_HD 0x00004000
  1825. #define ANEG_CFG_FD 0x00002000
  1826. #define ANEG_CFG_INVAL 0x00001f06
  1827. };
  1828. #define ANEG_OK 0
  1829. #define ANEG_DONE 1
  1830. #define ANEG_TIMER_ENAB 2
  1831. #define ANEG_FAILED -1
  1832. #define ANEG_STATE_SETTLE_TIME 10000
  1833. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  1834. struct tg3_fiber_aneginfo *ap)
  1835. {
  1836. unsigned long delta;
  1837. u32 rx_cfg_reg;
  1838. int ret;
  1839. if (ap->state == ANEG_STATE_UNKNOWN) {
  1840. ap->rxconfig = 0;
  1841. ap->link_time = 0;
  1842. ap->cur_time = 0;
  1843. ap->ability_match_cfg = 0;
  1844. ap->ability_match_count = 0;
  1845. ap->ability_match = 0;
  1846. ap->idle_match = 0;
  1847. ap->ack_match = 0;
  1848. }
  1849. ap->cur_time++;
  1850. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  1851. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  1852. if (rx_cfg_reg != ap->ability_match_cfg) {
  1853. ap->ability_match_cfg = rx_cfg_reg;
  1854. ap->ability_match = 0;
  1855. ap->ability_match_count = 0;
  1856. } else {
  1857. if (++ap->ability_match_count > 1) {
  1858. ap->ability_match = 1;
  1859. ap->ability_match_cfg = rx_cfg_reg;
  1860. }
  1861. }
  1862. if (rx_cfg_reg & ANEG_CFG_ACK)
  1863. ap->ack_match = 1;
  1864. else
  1865. ap->ack_match = 0;
  1866. ap->idle_match = 0;
  1867. } else {
  1868. ap->idle_match = 1;
  1869. ap->ability_match_cfg = 0;
  1870. ap->ability_match_count = 0;
  1871. ap->ability_match = 0;
  1872. ap->ack_match = 0;
  1873. rx_cfg_reg = 0;
  1874. }
  1875. ap->rxconfig = rx_cfg_reg;
  1876. ret = ANEG_OK;
  1877. switch(ap->state) {
  1878. case ANEG_STATE_UNKNOWN:
  1879. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  1880. ap->state = ANEG_STATE_AN_ENABLE;
  1881. /* fallthru */
  1882. case ANEG_STATE_AN_ENABLE:
  1883. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  1884. if (ap->flags & MR_AN_ENABLE) {
  1885. ap->link_time = 0;
  1886. ap->cur_time = 0;
  1887. ap->ability_match_cfg = 0;
  1888. ap->ability_match_count = 0;
  1889. ap->ability_match = 0;
  1890. ap->idle_match = 0;
  1891. ap->ack_match = 0;
  1892. ap->state = ANEG_STATE_RESTART_INIT;
  1893. } else {
  1894. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  1895. }
  1896. break;
  1897. case ANEG_STATE_RESTART_INIT:
  1898. ap->link_time = ap->cur_time;
  1899. ap->flags &= ~(MR_NP_LOADED);
  1900. ap->txconfig = 0;
  1901. tw32(MAC_TX_AUTO_NEG, 0);
  1902. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1903. tw32_f(MAC_MODE, tp->mac_mode);
  1904. udelay(40);
  1905. ret = ANEG_TIMER_ENAB;
  1906. ap->state = ANEG_STATE_RESTART;
  1907. /* fallthru */
  1908. case ANEG_STATE_RESTART:
  1909. delta = ap->cur_time - ap->link_time;
  1910. if (delta > ANEG_STATE_SETTLE_TIME) {
  1911. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  1912. } else {
  1913. ret = ANEG_TIMER_ENAB;
  1914. }
  1915. break;
  1916. case ANEG_STATE_DISABLE_LINK_OK:
  1917. ret = ANEG_DONE;
  1918. break;
  1919. case ANEG_STATE_ABILITY_DETECT_INIT:
  1920. ap->flags &= ~(MR_TOGGLE_TX);
  1921. ap->txconfig = (ANEG_CFG_FD | ANEG_CFG_PS1);
  1922. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1923. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1924. tw32_f(MAC_MODE, tp->mac_mode);
  1925. udelay(40);
  1926. ap->state = ANEG_STATE_ABILITY_DETECT;
  1927. break;
  1928. case ANEG_STATE_ABILITY_DETECT:
  1929. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  1930. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  1931. }
  1932. break;
  1933. case ANEG_STATE_ACK_DETECT_INIT:
  1934. ap->txconfig |= ANEG_CFG_ACK;
  1935. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  1936. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  1937. tw32_f(MAC_MODE, tp->mac_mode);
  1938. udelay(40);
  1939. ap->state = ANEG_STATE_ACK_DETECT;
  1940. /* fallthru */
  1941. case ANEG_STATE_ACK_DETECT:
  1942. if (ap->ack_match != 0) {
  1943. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  1944. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  1945. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  1946. } else {
  1947. ap->state = ANEG_STATE_AN_ENABLE;
  1948. }
  1949. } else if (ap->ability_match != 0 &&
  1950. ap->rxconfig == 0) {
  1951. ap->state = ANEG_STATE_AN_ENABLE;
  1952. }
  1953. break;
  1954. case ANEG_STATE_COMPLETE_ACK_INIT:
  1955. if (ap->rxconfig & ANEG_CFG_INVAL) {
  1956. ret = ANEG_FAILED;
  1957. break;
  1958. }
  1959. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  1960. MR_LP_ADV_HALF_DUPLEX |
  1961. MR_LP_ADV_SYM_PAUSE |
  1962. MR_LP_ADV_ASYM_PAUSE |
  1963. MR_LP_ADV_REMOTE_FAULT1 |
  1964. MR_LP_ADV_REMOTE_FAULT2 |
  1965. MR_LP_ADV_NEXT_PAGE |
  1966. MR_TOGGLE_RX |
  1967. MR_NP_RX);
  1968. if (ap->rxconfig & ANEG_CFG_FD)
  1969. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  1970. if (ap->rxconfig & ANEG_CFG_HD)
  1971. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  1972. if (ap->rxconfig & ANEG_CFG_PS1)
  1973. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  1974. if (ap->rxconfig & ANEG_CFG_PS2)
  1975. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  1976. if (ap->rxconfig & ANEG_CFG_RF1)
  1977. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  1978. if (ap->rxconfig & ANEG_CFG_RF2)
  1979. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  1980. if (ap->rxconfig & ANEG_CFG_NP)
  1981. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  1982. ap->link_time = ap->cur_time;
  1983. ap->flags ^= (MR_TOGGLE_TX);
  1984. if (ap->rxconfig & 0x0008)
  1985. ap->flags |= MR_TOGGLE_RX;
  1986. if (ap->rxconfig & ANEG_CFG_NP)
  1987. ap->flags |= MR_NP_RX;
  1988. ap->flags |= MR_PAGE_RX;
  1989. ap->state = ANEG_STATE_COMPLETE_ACK;
  1990. ret = ANEG_TIMER_ENAB;
  1991. break;
  1992. case ANEG_STATE_COMPLETE_ACK:
  1993. if (ap->ability_match != 0 &&
  1994. ap->rxconfig == 0) {
  1995. ap->state = ANEG_STATE_AN_ENABLE;
  1996. break;
  1997. }
  1998. delta = ap->cur_time - ap->link_time;
  1999. if (delta > ANEG_STATE_SETTLE_TIME) {
  2000. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  2001. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2002. } else {
  2003. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  2004. !(ap->flags & MR_NP_RX)) {
  2005. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2006. } else {
  2007. ret = ANEG_FAILED;
  2008. }
  2009. }
  2010. }
  2011. break;
  2012. case ANEG_STATE_IDLE_DETECT_INIT:
  2013. ap->link_time = ap->cur_time;
  2014. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2015. tw32_f(MAC_MODE, tp->mac_mode);
  2016. udelay(40);
  2017. ap->state = ANEG_STATE_IDLE_DETECT;
  2018. ret = ANEG_TIMER_ENAB;
  2019. break;
  2020. case ANEG_STATE_IDLE_DETECT:
  2021. if (ap->ability_match != 0 &&
  2022. ap->rxconfig == 0) {
  2023. ap->state = ANEG_STATE_AN_ENABLE;
  2024. break;
  2025. }
  2026. delta = ap->cur_time - ap->link_time;
  2027. if (delta > ANEG_STATE_SETTLE_TIME) {
  2028. /* XXX another gem from the Broadcom driver :( */
  2029. ap->state = ANEG_STATE_LINK_OK;
  2030. }
  2031. break;
  2032. case ANEG_STATE_LINK_OK:
  2033. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  2034. ret = ANEG_DONE;
  2035. break;
  2036. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  2037. /* ??? unimplemented */
  2038. break;
  2039. case ANEG_STATE_NEXT_PAGE_WAIT:
  2040. /* ??? unimplemented */
  2041. break;
  2042. default:
  2043. ret = ANEG_FAILED;
  2044. break;
  2045. };
  2046. return ret;
  2047. }
  2048. static int fiber_autoneg(struct tg3 *tp, u32 *flags)
  2049. {
  2050. int res = 0;
  2051. struct tg3_fiber_aneginfo aninfo;
  2052. int status = ANEG_FAILED;
  2053. unsigned int tick;
  2054. u32 tmp;
  2055. tw32_f(MAC_TX_AUTO_NEG, 0);
  2056. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2057. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2058. udelay(40);
  2059. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2060. udelay(40);
  2061. memset(&aninfo, 0, sizeof(aninfo));
  2062. aninfo.flags |= MR_AN_ENABLE;
  2063. aninfo.state = ANEG_STATE_UNKNOWN;
  2064. aninfo.cur_time = 0;
  2065. tick = 0;
  2066. while (++tick < 195000) {
  2067. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2068. if (status == ANEG_DONE || status == ANEG_FAILED)
  2069. break;
  2070. udelay(1);
  2071. }
  2072. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2073. tw32_f(MAC_MODE, tp->mac_mode);
  2074. udelay(40);
  2075. *flags = aninfo.flags;
  2076. if (status == ANEG_DONE &&
  2077. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2078. MR_LP_ADV_FULL_DUPLEX)))
  2079. res = 1;
  2080. return res;
  2081. }
  2082. static void tg3_init_bcm8002(struct tg3 *tp)
  2083. {
  2084. u32 mac_status = tr32(MAC_STATUS);
  2085. int i;
  2086. /* Reset when initting first time or we have a link. */
  2087. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2088. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2089. return;
  2090. /* Set PLL lock range. */
  2091. tg3_writephy(tp, 0x16, 0x8007);
  2092. /* SW reset */
  2093. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2094. /* Wait for reset to complete. */
  2095. /* XXX schedule_timeout() ... */
  2096. for (i = 0; i < 500; i++)
  2097. udelay(10);
  2098. /* Config mode; select PMA/Ch 1 regs. */
  2099. tg3_writephy(tp, 0x10, 0x8411);
  2100. /* Enable auto-lock and comdet, select txclk for tx. */
  2101. tg3_writephy(tp, 0x11, 0x0a10);
  2102. tg3_writephy(tp, 0x18, 0x00a0);
  2103. tg3_writephy(tp, 0x16, 0x41ff);
  2104. /* Assert and deassert POR. */
  2105. tg3_writephy(tp, 0x13, 0x0400);
  2106. udelay(40);
  2107. tg3_writephy(tp, 0x13, 0x0000);
  2108. tg3_writephy(tp, 0x11, 0x0a50);
  2109. udelay(40);
  2110. tg3_writephy(tp, 0x11, 0x0a10);
  2111. /* Wait for signal to stabilize */
  2112. /* XXX schedule_timeout() ... */
  2113. for (i = 0; i < 15000; i++)
  2114. udelay(10);
  2115. /* Deselect the channel register so we can read the PHYID
  2116. * later.
  2117. */
  2118. tg3_writephy(tp, 0x10, 0x8011);
  2119. }
  2120. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2121. {
  2122. u32 sg_dig_ctrl, sg_dig_status;
  2123. u32 serdes_cfg, expected_sg_dig_ctrl;
  2124. int workaround, port_a;
  2125. int current_link_up;
  2126. serdes_cfg = 0;
  2127. expected_sg_dig_ctrl = 0;
  2128. workaround = 0;
  2129. port_a = 1;
  2130. current_link_up = 0;
  2131. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2132. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2133. workaround = 1;
  2134. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2135. port_a = 0;
  2136. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2137. /* preserve bits 20-23 for voltage regulator */
  2138. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2139. }
  2140. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2141. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2142. if (sg_dig_ctrl & (1 << 31)) {
  2143. if (workaround) {
  2144. u32 val = serdes_cfg;
  2145. if (port_a)
  2146. val |= 0xc010000;
  2147. else
  2148. val |= 0x4010000;
  2149. tw32_f(MAC_SERDES_CFG, val);
  2150. }
  2151. tw32_f(SG_DIG_CTRL, 0x01388400);
  2152. }
  2153. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2154. tg3_setup_flow_control(tp, 0, 0);
  2155. current_link_up = 1;
  2156. }
  2157. goto out;
  2158. }
  2159. /* Want auto-negotiation. */
  2160. expected_sg_dig_ctrl = 0x81388400;
  2161. /* Pause capability */
  2162. expected_sg_dig_ctrl |= (1 << 11);
  2163. /* Asymettric pause */
  2164. expected_sg_dig_ctrl |= (1 << 12);
  2165. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2166. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2167. tp->serdes_counter &&
  2168. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2169. MAC_STATUS_RCVD_CFG)) ==
  2170. MAC_STATUS_PCS_SYNCED)) {
  2171. tp->serdes_counter--;
  2172. current_link_up = 1;
  2173. goto out;
  2174. }
  2175. restart_autoneg:
  2176. if (workaround)
  2177. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2178. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
  2179. udelay(5);
  2180. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2181. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2182. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2183. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2184. MAC_STATUS_SIGNAL_DET)) {
  2185. sg_dig_status = tr32(SG_DIG_STATUS);
  2186. mac_status = tr32(MAC_STATUS);
  2187. if ((sg_dig_status & (1 << 1)) &&
  2188. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2189. u32 local_adv, remote_adv;
  2190. local_adv = ADVERTISE_PAUSE_CAP;
  2191. remote_adv = 0;
  2192. if (sg_dig_status & (1 << 19))
  2193. remote_adv |= LPA_PAUSE_CAP;
  2194. if (sg_dig_status & (1 << 20))
  2195. remote_adv |= LPA_PAUSE_ASYM;
  2196. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2197. current_link_up = 1;
  2198. tp->serdes_counter = 0;
  2199. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2200. } else if (!(sg_dig_status & (1 << 1))) {
  2201. if (tp->serdes_counter)
  2202. tp->serdes_counter--;
  2203. else {
  2204. if (workaround) {
  2205. u32 val = serdes_cfg;
  2206. if (port_a)
  2207. val |= 0xc010000;
  2208. else
  2209. val |= 0x4010000;
  2210. tw32_f(MAC_SERDES_CFG, val);
  2211. }
  2212. tw32_f(SG_DIG_CTRL, 0x01388400);
  2213. udelay(40);
  2214. /* Link parallel detection - link is up */
  2215. /* only if we have PCS_SYNC and not */
  2216. /* receiving config code words */
  2217. mac_status = tr32(MAC_STATUS);
  2218. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2219. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2220. tg3_setup_flow_control(tp, 0, 0);
  2221. current_link_up = 1;
  2222. tp->tg3_flags2 |=
  2223. TG3_FLG2_PARALLEL_DETECT;
  2224. tp->serdes_counter =
  2225. SERDES_PARALLEL_DET_TIMEOUT;
  2226. } else
  2227. goto restart_autoneg;
  2228. }
  2229. }
  2230. } else {
  2231. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2232. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2233. }
  2234. out:
  2235. return current_link_up;
  2236. }
  2237. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2238. {
  2239. int current_link_up = 0;
  2240. if (!(mac_status & MAC_STATUS_PCS_SYNCED))
  2241. goto out;
  2242. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2243. u32 flags;
  2244. int i;
  2245. if (fiber_autoneg(tp, &flags)) {
  2246. u32 local_adv, remote_adv;
  2247. local_adv = ADVERTISE_PAUSE_CAP;
  2248. remote_adv = 0;
  2249. if (flags & MR_LP_ADV_SYM_PAUSE)
  2250. remote_adv |= LPA_PAUSE_CAP;
  2251. if (flags & MR_LP_ADV_ASYM_PAUSE)
  2252. remote_adv |= LPA_PAUSE_ASYM;
  2253. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2254. current_link_up = 1;
  2255. }
  2256. for (i = 0; i < 30; i++) {
  2257. udelay(20);
  2258. tw32_f(MAC_STATUS,
  2259. (MAC_STATUS_SYNC_CHANGED |
  2260. MAC_STATUS_CFG_CHANGED));
  2261. udelay(40);
  2262. if ((tr32(MAC_STATUS) &
  2263. (MAC_STATUS_SYNC_CHANGED |
  2264. MAC_STATUS_CFG_CHANGED)) == 0)
  2265. break;
  2266. }
  2267. mac_status = tr32(MAC_STATUS);
  2268. if (current_link_up == 0 &&
  2269. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2270. !(mac_status & MAC_STATUS_RCVD_CFG))
  2271. current_link_up = 1;
  2272. } else {
  2273. /* Forcing 1000FD link up. */
  2274. current_link_up = 1;
  2275. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2276. udelay(40);
  2277. tw32_f(MAC_MODE, tp->mac_mode);
  2278. udelay(40);
  2279. }
  2280. out:
  2281. return current_link_up;
  2282. }
  2283. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2284. {
  2285. u32 orig_pause_cfg;
  2286. u16 orig_active_speed;
  2287. u8 orig_active_duplex;
  2288. u32 mac_status;
  2289. int current_link_up;
  2290. int i;
  2291. orig_pause_cfg =
  2292. (tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2293. TG3_FLAG_TX_PAUSE));
  2294. orig_active_speed = tp->link_config.active_speed;
  2295. orig_active_duplex = tp->link_config.active_duplex;
  2296. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2297. netif_carrier_ok(tp->dev) &&
  2298. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2299. mac_status = tr32(MAC_STATUS);
  2300. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2301. MAC_STATUS_SIGNAL_DET |
  2302. MAC_STATUS_CFG_CHANGED |
  2303. MAC_STATUS_RCVD_CFG);
  2304. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2305. MAC_STATUS_SIGNAL_DET)) {
  2306. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2307. MAC_STATUS_CFG_CHANGED));
  2308. return 0;
  2309. }
  2310. }
  2311. tw32_f(MAC_TX_AUTO_NEG, 0);
  2312. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2313. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2314. tw32_f(MAC_MODE, tp->mac_mode);
  2315. udelay(40);
  2316. if (tp->phy_id == PHY_ID_BCM8002)
  2317. tg3_init_bcm8002(tp);
  2318. /* Enable link change event even when serdes polling. */
  2319. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2320. udelay(40);
  2321. current_link_up = 0;
  2322. mac_status = tr32(MAC_STATUS);
  2323. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2324. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2325. else
  2326. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2327. tp->hw_status->status =
  2328. (SD_STATUS_UPDATED |
  2329. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2330. for (i = 0; i < 100; i++) {
  2331. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2332. MAC_STATUS_CFG_CHANGED));
  2333. udelay(5);
  2334. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2335. MAC_STATUS_CFG_CHANGED |
  2336. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2337. break;
  2338. }
  2339. mac_status = tr32(MAC_STATUS);
  2340. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2341. current_link_up = 0;
  2342. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2343. tp->serdes_counter == 0) {
  2344. tw32_f(MAC_MODE, (tp->mac_mode |
  2345. MAC_MODE_SEND_CONFIGS));
  2346. udelay(1);
  2347. tw32_f(MAC_MODE, tp->mac_mode);
  2348. }
  2349. }
  2350. if (current_link_up == 1) {
  2351. tp->link_config.active_speed = SPEED_1000;
  2352. tp->link_config.active_duplex = DUPLEX_FULL;
  2353. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2354. LED_CTRL_LNKLED_OVERRIDE |
  2355. LED_CTRL_1000MBPS_ON));
  2356. } else {
  2357. tp->link_config.active_speed = SPEED_INVALID;
  2358. tp->link_config.active_duplex = DUPLEX_INVALID;
  2359. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2360. LED_CTRL_LNKLED_OVERRIDE |
  2361. LED_CTRL_TRAFFIC_OVERRIDE));
  2362. }
  2363. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2364. if (current_link_up)
  2365. netif_carrier_on(tp->dev);
  2366. else
  2367. netif_carrier_off(tp->dev);
  2368. tg3_link_report(tp);
  2369. } else {
  2370. u32 now_pause_cfg =
  2371. tp->tg3_flags & (TG3_FLAG_RX_PAUSE |
  2372. TG3_FLAG_TX_PAUSE);
  2373. if (orig_pause_cfg != now_pause_cfg ||
  2374. orig_active_speed != tp->link_config.active_speed ||
  2375. orig_active_duplex != tp->link_config.active_duplex)
  2376. tg3_link_report(tp);
  2377. }
  2378. return 0;
  2379. }
  2380. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2381. {
  2382. int current_link_up, err = 0;
  2383. u32 bmsr, bmcr;
  2384. u16 current_speed;
  2385. u8 current_duplex;
  2386. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2387. tw32_f(MAC_MODE, tp->mac_mode);
  2388. udelay(40);
  2389. tw32(MAC_EVENT, 0);
  2390. tw32_f(MAC_STATUS,
  2391. (MAC_STATUS_SYNC_CHANGED |
  2392. MAC_STATUS_CFG_CHANGED |
  2393. MAC_STATUS_MI_COMPLETION |
  2394. MAC_STATUS_LNKSTATE_CHANGED));
  2395. udelay(40);
  2396. if (force_reset)
  2397. tg3_phy_reset(tp);
  2398. current_link_up = 0;
  2399. current_speed = SPEED_INVALID;
  2400. current_duplex = DUPLEX_INVALID;
  2401. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2402. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2403. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2404. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2405. bmsr |= BMSR_LSTATUS;
  2406. else
  2407. bmsr &= ~BMSR_LSTATUS;
  2408. }
  2409. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2410. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2411. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2412. /* do nothing, just check for link up at the end */
  2413. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2414. u32 adv, new_adv;
  2415. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2416. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2417. ADVERTISE_1000XPAUSE |
  2418. ADVERTISE_1000XPSE_ASYM |
  2419. ADVERTISE_SLCT);
  2420. /* Always advertise symmetric PAUSE just like copper */
  2421. new_adv |= ADVERTISE_1000XPAUSE;
  2422. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2423. new_adv |= ADVERTISE_1000XHALF;
  2424. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2425. new_adv |= ADVERTISE_1000XFULL;
  2426. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2427. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2428. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2429. tg3_writephy(tp, MII_BMCR, bmcr);
  2430. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2431. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2432. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2433. return err;
  2434. }
  2435. } else {
  2436. u32 new_bmcr;
  2437. bmcr &= ~BMCR_SPEED1000;
  2438. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2439. if (tp->link_config.duplex == DUPLEX_FULL)
  2440. new_bmcr |= BMCR_FULLDPLX;
  2441. if (new_bmcr != bmcr) {
  2442. /* BMCR_SPEED1000 is a reserved bit that needs
  2443. * to be set on write.
  2444. */
  2445. new_bmcr |= BMCR_SPEED1000;
  2446. /* Force a linkdown */
  2447. if (netif_carrier_ok(tp->dev)) {
  2448. u32 adv;
  2449. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2450. adv &= ~(ADVERTISE_1000XFULL |
  2451. ADVERTISE_1000XHALF |
  2452. ADVERTISE_SLCT);
  2453. tg3_writephy(tp, MII_ADVERTISE, adv);
  2454. tg3_writephy(tp, MII_BMCR, bmcr |
  2455. BMCR_ANRESTART |
  2456. BMCR_ANENABLE);
  2457. udelay(10);
  2458. netif_carrier_off(tp->dev);
  2459. }
  2460. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2461. bmcr = new_bmcr;
  2462. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2463. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2464. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2465. ASIC_REV_5714) {
  2466. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2467. bmsr |= BMSR_LSTATUS;
  2468. else
  2469. bmsr &= ~BMSR_LSTATUS;
  2470. }
  2471. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2472. }
  2473. }
  2474. if (bmsr & BMSR_LSTATUS) {
  2475. current_speed = SPEED_1000;
  2476. current_link_up = 1;
  2477. if (bmcr & BMCR_FULLDPLX)
  2478. current_duplex = DUPLEX_FULL;
  2479. else
  2480. current_duplex = DUPLEX_HALF;
  2481. if (bmcr & BMCR_ANENABLE) {
  2482. u32 local_adv, remote_adv, common;
  2483. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2484. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2485. common = local_adv & remote_adv;
  2486. if (common & (ADVERTISE_1000XHALF |
  2487. ADVERTISE_1000XFULL)) {
  2488. if (common & ADVERTISE_1000XFULL)
  2489. current_duplex = DUPLEX_FULL;
  2490. else
  2491. current_duplex = DUPLEX_HALF;
  2492. tg3_setup_flow_control(tp, local_adv,
  2493. remote_adv);
  2494. }
  2495. else
  2496. current_link_up = 0;
  2497. }
  2498. }
  2499. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2500. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2501. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2502. tw32_f(MAC_MODE, tp->mac_mode);
  2503. udelay(40);
  2504. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2505. tp->link_config.active_speed = current_speed;
  2506. tp->link_config.active_duplex = current_duplex;
  2507. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2508. if (current_link_up)
  2509. netif_carrier_on(tp->dev);
  2510. else {
  2511. netif_carrier_off(tp->dev);
  2512. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2513. }
  2514. tg3_link_report(tp);
  2515. }
  2516. return err;
  2517. }
  2518. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2519. {
  2520. if (tp->serdes_counter) {
  2521. /* Give autoneg time to complete. */
  2522. tp->serdes_counter--;
  2523. return;
  2524. }
  2525. if (!netif_carrier_ok(tp->dev) &&
  2526. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2527. u32 bmcr;
  2528. tg3_readphy(tp, MII_BMCR, &bmcr);
  2529. if (bmcr & BMCR_ANENABLE) {
  2530. u32 phy1, phy2;
  2531. /* Select shadow register 0x1f */
  2532. tg3_writephy(tp, 0x1c, 0x7c00);
  2533. tg3_readphy(tp, 0x1c, &phy1);
  2534. /* Select expansion interrupt status register */
  2535. tg3_writephy(tp, 0x17, 0x0f01);
  2536. tg3_readphy(tp, 0x15, &phy2);
  2537. tg3_readphy(tp, 0x15, &phy2);
  2538. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2539. /* We have signal detect and not receiving
  2540. * config code words, link is up by parallel
  2541. * detection.
  2542. */
  2543. bmcr &= ~BMCR_ANENABLE;
  2544. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2545. tg3_writephy(tp, MII_BMCR, bmcr);
  2546. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2547. }
  2548. }
  2549. }
  2550. else if (netif_carrier_ok(tp->dev) &&
  2551. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2552. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2553. u32 phy2;
  2554. /* Select expansion interrupt status register */
  2555. tg3_writephy(tp, 0x17, 0x0f01);
  2556. tg3_readphy(tp, 0x15, &phy2);
  2557. if (phy2 & 0x20) {
  2558. u32 bmcr;
  2559. /* Config code words received, turn on autoneg. */
  2560. tg3_readphy(tp, MII_BMCR, &bmcr);
  2561. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2562. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2563. }
  2564. }
  2565. }
  2566. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2567. {
  2568. int err;
  2569. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2570. err = tg3_setup_fiber_phy(tp, force_reset);
  2571. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2572. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2573. } else {
  2574. err = tg3_setup_copper_phy(tp, force_reset);
  2575. }
  2576. if (tp->link_config.active_speed == SPEED_1000 &&
  2577. tp->link_config.active_duplex == DUPLEX_HALF)
  2578. tw32(MAC_TX_LENGTHS,
  2579. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2580. (6 << TX_LENGTHS_IPG_SHIFT) |
  2581. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2582. else
  2583. tw32(MAC_TX_LENGTHS,
  2584. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2585. (6 << TX_LENGTHS_IPG_SHIFT) |
  2586. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2587. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2588. if (netif_carrier_ok(tp->dev)) {
  2589. tw32(HOSTCC_STAT_COAL_TICKS,
  2590. tp->coal.stats_block_coalesce_usecs);
  2591. } else {
  2592. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2593. }
  2594. }
  2595. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) {
  2596. u32 val = tr32(PCIE_PWR_MGMT_THRESH);
  2597. if (!netif_carrier_ok(tp->dev))
  2598. val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) |
  2599. tp->pwrmgmt_thresh;
  2600. else
  2601. val |= PCIE_PWR_MGMT_L1_THRESH_MSK;
  2602. tw32(PCIE_PWR_MGMT_THRESH, val);
  2603. }
  2604. return err;
  2605. }
  2606. /* This is called whenever we suspect that the system chipset is re-
  2607. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2608. * is bogus tx completions. We try to recover by setting the
  2609. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2610. * in the workqueue.
  2611. */
  2612. static void tg3_tx_recover(struct tg3 *tp)
  2613. {
  2614. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2615. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2616. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2617. "mapped I/O cycles to the network device, attempting to "
  2618. "recover. Please report the problem to the driver maintainer "
  2619. "and include system chipset information.\n", tp->dev->name);
  2620. spin_lock(&tp->lock);
  2621. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2622. spin_unlock(&tp->lock);
  2623. }
  2624. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2625. {
  2626. smp_mb();
  2627. return (tp->tx_pending -
  2628. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2629. }
  2630. /* Tigon3 never reports partial packet sends. So we do not
  2631. * need special logic to handle SKBs that have not had all
  2632. * of their frags sent yet, like SunGEM does.
  2633. */
  2634. static void tg3_tx(struct tg3 *tp)
  2635. {
  2636. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2637. u32 sw_idx = tp->tx_cons;
  2638. while (sw_idx != hw_idx) {
  2639. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2640. struct sk_buff *skb = ri->skb;
  2641. int i, tx_bug = 0;
  2642. if (unlikely(skb == NULL)) {
  2643. tg3_tx_recover(tp);
  2644. return;
  2645. }
  2646. pci_unmap_single(tp->pdev,
  2647. pci_unmap_addr(ri, mapping),
  2648. skb_headlen(skb),
  2649. PCI_DMA_TODEVICE);
  2650. ri->skb = NULL;
  2651. sw_idx = NEXT_TX(sw_idx);
  2652. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2653. ri = &tp->tx_buffers[sw_idx];
  2654. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2655. tx_bug = 1;
  2656. pci_unmap_page(tp->pdev,
  2657. pci_unmap_addr(ri, mapping),
  2658. skb_shinfo(skb)->frags[i].size,
  2659. PCI_DMA_TODEVICE);
  2660. sw_idx = NEXT_TX(sw_idx);
  2661. }
  2662. dev_kfree_skb(skb);
  2663. if (unlikely(tx_bug)) {
  2664. tg3_tx_recover(tp);
  2665. return;
  2666. }
  2667. }
  2668. tp->tx_cons = sw_idx;
  2669. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2670. * before checking for netif_queue_stopped(). Without the
  2671. * memory barrier, there is a small possibility that tg3_start_xmit()
  2672. * will miss it and cause the queue to be stopped forever.
  2673. */
  2674. smp_mb();
  2675. if (unlikely(netif_queue_stopped(tp->dev) &&
  2676. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2677. netif_tx_lock(tp->dev);
  2678. if (netif_queue_stopped(tp->dev) &&
  2679. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2680. netif_wake_queue(tp->dev);
  2681. netif_tx_unlock(tp->dev);
  2682. }
  2683. }
  2684. /* Returns size of skb allocated or < 0 on error.
  2685. *
  2686. * We only need to fill in the address because the other members
  2687. * of the RX descriptor are invariant, see tg3_init_rings.
  2688. *
  2689. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2690. * posting buffers we only dirty the first cache line of the RX
  2691. * descriptor (containing the address). Whereas for the RX status
  2692. * buffers the cpu only reads the last cacheline of the RX descriptor
  2693. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2694. */
  2695. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2696. int src_idx, u32 dest_idx_unmasked)
  2697. {
  2698. struct tg3_rx_buffer_desc *desc;
  2699. struct ring_info *map, *src_map;
  2700. struct sk_buff *skb;
  2701. dma_addr_t mapping;
  2702. int skb_size, dest_idx;
  2703. src_map = NULL;
  2704. switch (opaque_key) {
  2705. case RXD_OPAQUE_RING_STD:
  2706. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2707. desc = &tp->rx_std[dest_idx];
  2708. map = &tp->rx_std_buffers[dest_idx];
  2709. if (src_idx >= 0)
  2710. src_map = &tp->rx_std_buffers[src_idx];
  2711. skb_size = tp->rx_pkt_buf_sz;
  2712. break;
  2713. case RXD_OPAQUE_RING_JUMBO:
  2714. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2715. desc = &tp->rx_jumbo[dest_idx];
  2716. map = &tp->rx_jumbo_buffers[dest_idx];
  2717. if (src_idx >= 0)
  2718. src_map = &tp->rx_jumbo_buffers[src_idx];
  2719. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2720. break;
  2721. default:
  2722. return -EINVAL;
  2723. };
  2724. /* Do not overwrite any of the map or rp information
  2725. * until we are sure we can commit to a new buffer.
  2726. *
  2727. * Callers depend upon this behavior and assume that
  2728. * we leave everything unchanged if we fail.
  2729. */
  2730. skb = netdev_alloc_skb(tp->dev, skb_size);
  2731. if (skb == NULL)
  2732. return -ENOMEM;
  2733. skb_reserve(skb, tp->rx_offset);
  2734. mapping = pci_map_single(tp->pdev, skb->data,
  2735. skb_size - tp->rx_offset,
  2736. PCI_DMA_FROMDEVICE);
  2737. map->skb = skb;
  2738. pci_unmap_addr_set(map, mapping, mapping);
  2739. if (src_map != NULL)
  2740. src_map->skb = NULL;
  2741. desc->addr_hi = ((u64)mapping >> 32);
  2742. desc->addr_lo = ((u64)mapping & 0xffffffff);
  2743. return skb_size;
  2744. }
  2745. /* We only need to move over in the address because the other
  2746. * members of the RX descriptor are invariant. See notes above
  2747. * tg3_alloc_rx_skb for full details.
  2748. */
  2749. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  2750. int src_idx, u32 dest_idx_unmasked)
  2751. {
  2752. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  2753. struct ring_info *src_map, *dest_map;
  2754. int dest_idx;
  2755. switch (opaque_key) {
  2756. case RXD_OPAQUE_RING_STD:
  2757. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2758. dest_desc = &tp->rx_std[dest_idx];
  2759. dest_map = &tp->rx_std_buffers[dest_idx];
  2760. src_desc = &tp->rx_std[src_idx];
  2761. src_map = &tp->rx_std_buffers[src_idx];
  2762. break;
  2763. case RXD_OPAQUE_RING_JUMBO:
  2764. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2765. dest_desc = &tp->rx_jumbo[dest_idx];
  2766. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  2767. src_desc = &tp->rx_jumbo[src_idx];
  2768. src_map = &tp->rx_jumbo_buffers[src_idx];
  2769. break;
  2770. default:
  2771. return;
  2772. };
  2773. dest_map->skb = src_map->skb;
  2774. pci_unmap_addr_set(dest_map, mapping,
  2775. pci_unmap_addr(src_map, mapping));
  2776. dest_desc->addr_hi = src_desc->addr_hi;
  2777. dest_desc->addr_lo = src_desc->addr_lo;
  2778. src_map->skb = NULL;
  2779. }
  2780. #if TG3_VLAN_TAG_USED
  2781. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  2782. {
  2783. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  2784. }
  2785. #endif
  2786. /* The RX ring scheme is composed of multiple rings which post fresh
  2787. * buffers to the chip, and one special ring the chip uses to report
  2788. * status back to the host.
  2789. *
  2790. * The special ring reports the status of received packets to the
  2791. * host. The chip does not write into the original descriptor the
  2792. * RX buffer was obtained from. The chip simply takes the original
  2793. * descriptor as provided by the host, updates the status and length
  2794. * field, then writes this into the next status ring entry.
  2795. *
  2796. * Each ring the host uses to post buffers to the chip is described
  2797. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  2798. * it is first placed into the on-chip ram. When the packet's length
  2799. * is known, it walks down the TG3_BDINFO entries to select the ring.
  2800. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  2801. * which is within the range of the new packet's length is chosen.
  2802. *
  2803. * The "separate ring for rx status" scheme may sound queer, but it makes
  2804. * sense from a cache coherency perspective. If only the host writes
  2805. * to the buffer post rings, and only the chip writes to the rx status
  2806. * rings, then cache lines never move beyond shared-modified state.
  2807. * If both the host and chip were to write into the same ring, cache line
  2808. * eviction could occur since both entities want it in an exclusive state.
  2809. */
  2810. static int tg3_rx(struct tg3 *tp, int budget)
  2811. {
  2812. u32 work_mask, rx_std_posted = 0;
  2813. u32 sw_idx = tp->rx_rcb_ptr;
  2814. u16 hw_idx;
  2815. int received;
  2816. hw_idx = tp->hw_status->idx[0].rx_producer;
  2817. /*
  2818. * We need to order the read of hw_idx and the read of
  2819. * the opaque cookie.
  2820. */
  2821. rmb();
  2822. work_mask = 0;
  2823. received = 0;
  2824. while (sw_idx != hw_idx && budget > 0) {
  2825. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  2826. unsigned int len;
  2827. struct sk_buff *skb;
  2828. dma_addr_t dma_addr;
  2829. u32 opaque_key, desc_idx, *post_ptr;
  2830. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  2831. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  2832. if (opaque_key == RXD_OPAQUE_RING_STD) {
  2833. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  2834. mapping);
  2835. skb = tp->rx_std_buffers[desc_idx].skb;
  2836. post_ptr = &tp->rx_std_ptr;
  2837. rx_std_posted++;
  2838. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  2839. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  2840. mapping);
  2841. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  2842. post_ptr = &tp->rx_jumbo_ptr;
  2843. }
  2844. else {
  2845. goto next_pkt_nopost;
  2846. }
  2847. work_mask |= opaque_key;
  2848. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  2849. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  2850. drop_it:
  2851. tg3_recycle_rx(tp, opaque_key,
  2852. desc_idx, *post_ptr);
  2853. drop_it_no_recycle:
  2854. /* Other statistics kept track of by card. */
  2855. tp->net_stats.rx_dropped++;
  2856. goto next_pkt;
  2857. }
  2858. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  2859. if (len > RX_COPY_THRESHOLD
  2860. && tp->rx_offset == 2
  2861. /* rx_offset != 2 iff this is a 5701 card running
  2862. * in PCI-X mode [see tg3_get_invariants()] */
  2863. ) {
  2864. int skb_size;
  2865. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  2866. desc_idx, *post_ptr);
  2867. if (skb_size < 0)
  2868. goto drop_it;
  2869. pci_unmap_single(tp->pdev, dma_addr,
  2870. skb_size - tp->rx_offset,
  2871. PCI_DMA_FROMDEVICE);
  2872. skb_put(skb, len);
  2873. } else {
  2874. struct sk_buff *copy_skb;
  2875. tg3_recycle_rx(tp, opaque_key,
  2876. desc_idx, *post_ptr);
  2877. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  2878. if (copy_skb == NULL)
  2879. goto drop_it_no_recycle;
  2880. skb_reserve(copy_skb, 2);
  2881. skb_put(copy_skb, len);
  2882. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2883. skb_copy_from_linear_data(skb, copy_skb->data, len);
  2884. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  2885. /* We'll reuse the original ring buffer. */
  2886. skb = copy_skb;
  2887. }
  2888. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  2889. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  2890. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  2891. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  2892. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2893. else
  2894. skb->ip_summed = CHECKSUM_NONE;
  2895. skb->protocol = eth_type_trans(skb, tp->dev);
  2896. #if TG3_VLAN_TAG_USED
  2897. if (tp->vlgrp != NULL &&
  2898. desc->type_flags & RXD_FLAG_VLAN) {
  2899. tg3_vlan_rx(tp, skb,
  2900. desc->err_vlan & RXD_VLAN_MASK);
  2901. } else
  2902. #endif
  2903. netif_receive_skb(skb);
  2904. tp->dev->last_rx = jiffies;
  2905. received++;
  2906. budget--;
  2907. next_pkt:
  2908. (*post_ptr)++;
  2909. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  2910. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  2911. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  2912. TG3_64BIT_REG_LOW, idx);
  2913. work_mask &= ~RXD_OPAQUE_RING_STD;
  2914. rx_std_posted = 0;
  2915. }
  2916. next_pkt_nopost:
  2917. sw_idx++;
  2918. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  2919. /* Refresh hw_idx to see if there is new work */
  2920. if (sw_idx == hw_idx) {
  2921. hw_idx = tp->hw_status->idx[0].rx_producer;
  2922. rmb();
  2923. }
  2924. }
  2925. /* ACK the status ring. */
  2926. tp->rx_rcb_ptr = sw_idx;
  2927. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  2928. /* Refill RX ring(s). */
  2929. if (work_mask & RXD_OPAQUE_RING_STD) {
  2930. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  2931. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  2932. sw_idx);
  2933. }
  2934. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  2935. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  2936. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  2937. sw_idx);
  2938. }
  2939. mmiowb();
  2940. return received;
  2941. }
  2942. static int tg3_poll(struct net_device *netdev, int *budget)
  2943. {
  2944. struct tg3 *tp = netdev_priv(netdev);
  2945. struct tg3_hw_status *sblk = tp->hw_status;
  2946. int done;
  2947. /* handle link change and other phy events */
  2948. if (!(tp->tg3_flags &
  2949. (TG3_FLAG_USE_LINKCHG_REG |
  2950. TG3_FLAG_POLL_SERDES))) {
  2951. if (sblk->status & SD_STATUS_LINK_CHG) {
  2952. sblk->status = SD_STATUS_UPDATED |
  2953. (sblk->status & ~SD_STATUS_LINK_CHG);
  2954. spin_lock(&tp->lock);
  2955. tg3_setup_phy(tp, 0);
  2956. spin_unlock(&tp->lock);
  2957. }
  2958. }
  2959. /* run TX completion thread */
  2960. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  2961. tg3_tx(tp);
  2962. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) {
  2963. netif_rx_complete(netdev);
  2964. schedule_work(&tp->reset_task);
  2965. return 0;
  2966. }
  2967. }
  2968. /* run RX thread, within the bounds set by NAPI.
  2969. * All RX "locking" is done by ensuring outside
  2970. * code synchronizes with dev->poll()
  2971. */
  2972. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr) {
  2973. int orig_budget = *budget;
  2974. int work_done;
  2975. if (orig_budget > netdev->quota)
  2976. orig_budget = netdev->quota;
  2977. work_done = tg3_rx(tp, orig_budget);
  2978. *budget -= work_done;
  2979. netdev->quota -= work_done;
  2980. }
  2981. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  2982. tp->last_tag = sblk->status_tag;
  2983. rmb();
  2984. } else
  2985. sblk->status &= ~SD_STATUS_UPDATED;
  2986. /* if no more work, tell net stack and NIC we're done */
  2987. done = !tg3_has_work(tp);
  2988. if (done) {
  2989. netif_rx_complete(netdev);
  2990. tg3_restart_ints(tp);
  2991. }
  2992. return (done ? 0 : 1);
  2993. }
  2994. static void tg3_irq_quiesce(struct tg3 *tp)
  2995. {
  2996. BUG_ON(tp->irq_sync);
  2997. tp->irq_sync = 1;
  2998. smp_mb();
  2999. synchronize_irq(tp->pdev->irq);
  3000. }
  3001. static inline int tg3_irq_sync(struct tg3 *tp)
  3002. {
  3003. return tp->irq_sync;
  3004. }
  3005. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  3006. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  3007. * with as well. Most of the time, this is not necessary except when
  3008. * shutting down the device.
  3009. */
  3010. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  3011. {
  3012. spin_lock_bh(&tp->lock);
  3013. if (irq_sync)
  3014. tg3_irq_quiesce(tp);
  3015. }
  3016. static inline void tg3_full_unlock(struct tg3 *tp)
  3017. {
  3018. spin_unlock_bh(&tp->lock);
  3019. }
  3020. /* One-shot MSI handler - Chip automatically disables interrupt
  3021. * after sending MSI so driver doesn't have to do it.
  3022. */
  3023. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  3024. {
  3025. struct net_device *dev = dev_id;
  3026. struct tg3 *tp = netdev_priv(dev);
  3027. prefetch(tp->hw_status);
  3028. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3029. if (likely(!tg3_irq_sync(tp)))
  3030. netif_rx_schedule(dev); /* schedule NAPI poll */
  3031. return IRQ_HANDLED;
  3032. }
  3033. /* MSI ISR - No need to check for interrupt sharing and no need to
  3034. * flush status block and interrupt mailbox. PCI ordering rules
  3035. * guarantee that MSI will arrive after the status block.
  3036. */
  3037. static irqreturn_t tg3_msi(int irq, void *dev_id)
  3038. {
  3039. struct net_device *dev = dev_id;
  3040. struct tg3 *tp = netdev_priv(dev);
  3041. prefetch(tp->hw_status);
  3042. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3043. /*
  3044. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3045. * chip-internal interrupt pending events.
  3046. * Writing non-zero to intr-mbox-0 additional tells the
  3047. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3048. * event coalescing.
  3049. */
  3050. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3051. if (likely(!tg3_irq_sync(tp)))
  3052. netif_rx_schedule(dev); /* schedule NAPI poll */
  3053. return IRQ_RETVAL(1);
  3054. }
  3055. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3056. {
  3057. struct net_device *dev = dev_id;
  3058. struct tg3 *tp = netdev_priv(dev);
  3059. struct tg3_hw_status *sblk = tp->hw_status;
  3060. unsigned int handled = 1;
  3061. /* In INTx mode, it is possible for the interrupt to arrive at
  3062. * the CPU before the status block posted prior to the interrupt.
  3063. * Reading the PCI State register will confirm whether the
  3064. * interrupt is ours and will flush the status block.
  3065. */
  3066. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3067. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3068. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3069. handled = 0;
  3070. goto out;
  3071. }
  3072. }
  3073. /*
  3074. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3075. * chip-internal interrupt pending events.
  3076. * Writing non-zero to intr-mbox-0 additional tells the
  3077. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3078. * event coalescing.
  3079. *
  3080. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3081. * spurious interrupts. The flush impacts performance but
  3082. * excessive spurious interrupts can be worse in some cases.
  3083. */
  3084. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3085. if (tg3_irq_sync(tp))
  3086. goto out;
  3087. sblk->status &= ~SD_STATUS_UPDATED;
  3088. if (likely(tg3_has_work(tp))) {
  3089. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3090. netif_rx_schedule(dev); /* schedule NAPI poll */
  3091. } else {
  3092. /* No work, shared interrupt perhaps? re-enable
  3093. * interrupts, and flush that PCI write
  3094. */
  3095. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3096. 0x00000000);
  3097. }
  3098. out:
  3099. return IRQ_RETVAL(handled);
  3100. }
  3101. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3102. {
  3103. struct net_device *dev = dev_id;
  3104. struct tg3 *tp = netdev_priv(dev);
  3105. struct tg3_hw_status *sblk = tp->hw_status;
  3106. unsigned int handled = 1;
  3107. /* In INTx mode, it is possible for the interrupt to arrive at
  3108. * the CPU before the status block posted prior to the interrupt.
  3109. * Reading the PCI State register will confirm whether the
  3110. * interrupt is ours and will flush the status block.
  3111. */
  3112. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3113. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3114. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3115. handled = 0;
  3116. goto out;
  3117. }
  3118. }
  3119. /*
  3120. * writing any value to intr-mbox-0 clears PCI INTA# and
  3121. * chip-internal interrupt pending events.
  3122. * writing non-zero to intr-mbox-0 additional tells the
  3123. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3124. * event coalescing.
  3125. *
  3126. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3127. * spurious interrupts. The flush impacts performance but
  3128. * excessive spurious interrupts can be worse in some cases.
  3129. */
  3130. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3131. if (tg3_irq_sync(tp))
  3132. goto out;
  3133. if (netif_rx_schedule_prep(dev)) {
  3134. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3135. /* Update last_tag to mark that this status has been
  3136. * seen. Because interrupt may be shared, we may be
  3137. * racing with tg3_poll(), so only update last_tag
  3138. * if tg3_poll() is not scheduled.
  3139. */
  3140. tp->last_tag = sblk->status_tag;
  3141. __netif_rx_schedule(dev);
  3142. }
  3143. out:
  3144. return IRQ_RETVAL(handled);
  3145. }
  3146. /* ISR for interrupt test */
  3147. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3148. {
  3149. struct net_device *dev = dev_id;
  3150. struct tg3 *tp = netdev_priv(dev);
  3151. struct tg3_hw_status *sblk = tp->hw_status;
  3152. if ((sblk->status & SD_STATUS_UPDATED) ||
  3153. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3154. tg3_disable_ints(tp);
  3155. return IRQ_RETVAL(1);
  3156. }
  3157. return IRQ_RETVAL(0);
  3158. }
  3159. static int tg3_init_hw(struct tg3 *, int);
  3160. static int tg3_halt(struct tg3 *, int, int);
  3161. /* Restart hardware after configuration changes, self-test, etc.
  3162. * Invoked with tp->lock held.
  3163. */
  3164. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3165. {
  3166. int err;
  3167. err = tg3_init_hw(tp, reset_phy);
  3168. if (err) {
  3169. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3170. "aborting.\n", tp->dev->name);
  3171. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3172. tg3_full_unlock(tp);
  3173. del_timer_sync(&tp->timer);
  3174. tp->irq_sync = 0;
  3175. netif_poll_enable(tp->dev);
  3176. dev_close(tp->dev);
  3177. tg3_full_lock(tp, 0);
  3178. }
  3179. return err;
  3180. }
  3181. #ifdef CONFIG_NET_POLL_CONTROLLER
  3182. static void tg3_poll_controller(struct net_device *dev)
  3183. {
  3184. struct tg3 *tp = netdev_priv(dev);
  3185. tg3_interrupt(tp->pdev->irq, dev);
  3186. }
  3187. #endif
  3188. static void tg3_reset_task(struct work_struct *work)
  3189. {
  3190. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3191. unsigned int restart_timer;
  3192. tg3_full_lock(tp, 0);
  3193. if (!netif_running(tp->dev)) {
  3194. tg3_full_unlock(tp);
  3195. return;
  3196. }
  3197. tg3_full_unlock(tp);
  3198. tg3_netif_stop(tp);
  3199. tg3_full_lock(tp, 1);
  3200. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3201. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3202. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3203. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3204. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3205. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3206. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3207. }
  3208. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3209. if (tg3_init_hw(tp, 1))
  3210. goto out;
  3211. tg3_netif_start(tp);
  3212. if (restart_timer)
  3213. mod_timer(&tp->timer, jiffies + 1);
  3214. out:
  3215. tg3_full_unlock(tp);
  3216. }
  3217. static void tg3_dump_short_state(struct tg3 *tp)
  3218. {
  3219. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3220. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3221. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3222. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3223. }
  3224. static void tg3_tx_timeout(struct net_device *dev)
  3225. {
  3226. struct tg3 *tp = netdev_priv(dev);
  3227. if (netif_msg_tx_err(tp)) {
  3228. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3229. dev->name);
  3230. tg3_dump_short_state(tp);
  3231. }
  3232. schedule_work(&tp->reset_task);
  3233. }
  3234. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3235. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3236. {
  3237. u32 base = (u32) mapping & 0xffffffff;
  3238. return ((base > 0xffffdcc0) &&
  3239. (base + len + 8 < base));
  3240. }
  3241. /* Test for DMA addresses > 40-bit */
  3242. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3243. int len)
  3244. {
  3245. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3246. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3247. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3248. return 0;
  3249. #else
  3250. return 0;
  3251. #endif
  3252. }
  3253. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3254. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3255. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3256. u32 last_plus_one, u32 *start,
  3257. u32 base_flags, u32 mss)
  3258. {
  3259. struct sk_buff *new_skb = skb_copy(skb, GFP_ATOMIC);
  3260. dma_addr_t new_addr = 0;
  3261. u32 entry = *start;
  3262. int i, ret = 0;
  3263. if (!new_skb) {
  3264. ret = -1;
  3265. } else {
  3266. /* New SKB is guaranteed to be linear. */
  3267. entry = *start;
  3268. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3269. PCI_DMA_TODEVICE);
  3270. /* Make sure new skb does not cross any 4G boundaries.
  3271. * Drop the packet if it does.
  3272. */
  3273. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3274. ret = -1;
  3275. dev_kfree_skb(new_skb);
  3276. new_skb = NULL;
  3277. } else {
  3278. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3279. base_flags, 1 | (mss << 1));
  3280. *start = NEXT_TX(entry);
  3281. }
  3282. }
  3283. /* Now clean up the sw ring entries. */
  3284. i = 0;
  3285. while (entry != last_plus_one) {
  3286. int len;
  3287. if (i == 0)
  3288. len = skb_headlen(skb);
  3289. else
  3290. len = skb_shinfo(skb)->frags[i-1].size;
  3291. pci_unmap_single(tp->pdev,
  3292. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3293. len, PCI_DMA_TODEVICE);
  3294. if (i == 0) {
  3295. tp->tx_buffers[entry].skb = new_skb;
  3296. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3297. } else {
  3298. tp->tx_buffers[entry].skb = NULL;
  3299. }
  3300. entry = NEXT_TX(entry);
  3301. i++;
  3302. }
  3303. dev_kfree_skb(skb);
  3304. return ret;
  3305. }
  3306. static void tg3_set_txd(struct tg3 *tp, int entry,
  3307. dma_addr_t mapping, int len, u32 flags,
  3308. u32 mss_and_is_end)
  3309. {
  3310. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3311. int is_end = (mss_and_is_end & 0x1);
  3312. u32 mss = (mss_and_is_end >> 1);
  3313. u32 vlan_tag = 0;
  3314. if (is_end)
  3315. flags |= TXD_FLAG_END;
  3316. if (flags & TXD_FLAG_VLAN) {
  3317. vlan_tag = flags >> 16;
  3318. flags &= 0xffff;
  3319. }
  3320. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3321. txd->addr_hi = ((u64) mapping >> 32);
  3322. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3323. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3324. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3325. }
  3326. /* hard_start_xmit for devices that don't have any bugs and
  3327. * support TG3_FLG2_HW_TSO_2 only.
  3328. */
  3329. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3330. {
  3331. struct tg3 *tp = netdev_priv(dev);
  3332. dma_addr_t mapping;
  3333. u32 len, entry, base_flags, mss;
  3334. len = skb_headlen(skb);
  3335. /* We are running in BH disabled context with netif_tx_lock
  3336. * and TX reclaim runs via tp->poll inside of a software
  3337. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3338. * no IRQ context deadlocks to worry about either. Rejoice!
  3339. */
  3340. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3341. if (!netif_queue_stopped(dev)) {
  3342. netif_stop_queue(dev);
  3343. /* This is a hard error, log it. */
  3344. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3345. "queue awake!\n", dev->name);
  3346. }
  3347. return NETDEV_TX_BUSY;
  3348. }
  3349. entry = tp->tx_prod;
  3350. base_flags = 0;
  3351. mss = 0;
  3352. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3353. int tcp_opt_len, ip_tcp_len;
  3354. if (skb_header_cloned(skb) &&
  3355. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3356. dev_kfree_skb(skb);
  3357. goto out_unlock;
  3358. }
  3359. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3360. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3361. else {
  3362. struct iphdr *iph = ip_hdr(skb);
  3363. tcp_opt_len = tcp_optlen(skb);
  3364. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3365. iph->check = 0;
  3366. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3367. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3368. }
  3369. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3370. TXD_FLAG_CPU_POST_DMA);
  3371. tcp_hdr(skb)->check = 0;
  3372. }
  3373. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3374. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3375. #if TG3_VLAN_TAG_USED
  3376. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3377. base_flags |= (TXD_FLAG_VLAN |
  3378. (vlan_tx_tag_get(skb) << 16));
  3379. #endif
  3380. /* Queue skb data, a.k.a. the main skb fragment. */
  3381. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3382. tp->tx_buffers[entry].skb = skb;
  3383. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3384. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3385. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3386. entry = NEXT_TX(entry);
  3387. /* Now loop through additional data fragments, and queue them. */
  3388. if (skb_shinfo(skb)->nr_frags > 0) {
  3389. unsigned int i, last;
  3390. last = skb_shinfo(skb)->nr_frags - 1;
  3391. for (i = 0; i <= last; i++) {
  3392. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3393. len = frag->size;
  3394. mapping = pci_map_page(tp->pdev,
  3395. frag->page,
  3396. frag->page_offset,
  3397. len, PCI_DMA_TODEVICE);
  3398. tp->tx_buffers[entry].skb = NULL;
  3399. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3400. tg3_set_txd(tp, entry, mapping, len,
  3401. base_flags, (i == last) | (mss << 1));
  3402. entry = NEXT_TX(entry);
  3403. }
  3404. }
  3405. /* Packets are ready, update Tx producer idx local and on card. */
  3406. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3407. tp->tx_prod = entry;
  3408. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3409. netif_stop_queue(dev);
  3410. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3411. netif_wake_queue(tp->dev);
  3412. }
  3413. out_unlock:
  3414. mmiowb();
  3415. dev->trans_start = jiffies;
  3416. return NETDEV_TX_OK;
  3417. }
  3418. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3419. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3420. * TSO header is greater than 80 bytes.
  3421. */
  3422. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3423. {
  3424. struct sk_buff *segs, *nskb;
  3425. /* Estimate the number of fragments in the worst case */
  3426. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3427. netif_stop_queue(tp->dev);
  3428. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3429. return NETDEV_TX_BUSY;
  3430. netif_wake_queue(tp->dev);
  3431. }
  3432. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3433. if (unlikely(IS_ERR(segs)))
  3434. goto tg3_tso_bug_end;
  3435. do {
  3436. nskb = segs;
  3437. segs = segs->next;
  3438. nskb->next = NULL;
  3439. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3440. } while (segs);
  3441. tg3_tso_bug_end:
  3442. dev_kfree_skb(skb);
  3443. return NETDEV_TX_OK;
  3444. }
  3445. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3446. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3447. */
  3448. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3449. {
  3450. struct tg3 *tp = netdev_priv(dev);
  3451. dma_addr_t mapping;
  3452. u32 len, entry, base_flags, mss;
  3453. int would_hit_hwbug;
  3454. len = skb_headlen(skb);
  3455. /* We are running in BH disabled context with netif_tx_lock
  3456. * and TX reclaim runs via tp->poll inside of a software
  3457. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3458. * no IRQ context deadlocks to worry about either. Rejoice!
  3459. */
  3460. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3461. if (!netif_queue_stopped(dev)) {
  3462. netif_stop_queue(dev);
  3463. /* This is a hard error, log it. */
  3464. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3465. "queue awake!\n", dev->name);
  3466. }
  3467. return NETDEV_TX_BUSY;
  3468. }
  3469. entry = tp->tx_prod;
  3470. base_flags = 0;
  3471. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3472. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3473. mss = 0;
  3474. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3475. struct iphdr *iph;
  3476. int tcp_opt_len, ip_tcp_len, hdr_len;
  3477. if (skb_header_cloned(skb) &&
  3478. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3479. dev_kfree_skb(skb);
  3480. goto out_unlock;
  3481. }
  3482. tcp_opt_len = tcp_optlen(skb);
  3483. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3484. hdr_len = ip_tcp_len + tcp_opt_len;
  3485. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3486. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3487. return (tg3_tso_bug(tp, skb));
  3488. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3489. TXD_FLAG_CPU_POST_DMA);
  3490. iph = ip_hdr(skb);
  3491. iph->check = 0;
  3492. iph->tot_len = htons(mss + hdr_len);
  3493. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3494. tcp_hdr(skb)->check = 0;
  3495. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3496. } else
  3497. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3498. iph->daddr, 0,
  3499. IPPROTO_TCP,
  3500. 0);
  3501. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3502. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3503. if (tcp_opt_len || iph->ihl > 5) {
  3504. int tsflags;
  3505. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3506. mss |= (tsflags << 11);
  3507. }
  3508. } else {
  3509. if (tcp_opt_len || iph->ihl > 5) {
  3510. int tsflags;
  3511. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3512. base_flags |= tsflags << 12;
  3513. }
  3514. }
  3515. }
  3516. #if TG3_VLAN_TAG_USED
  3517. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3518. base_flags |= (TXD_FLAG_VLAN |
  3519. (vlan_tx_tag_get(skb) << 16));
  3520. #endif
  3521. /* Queue skb data, a.k.a. the main skb fragment. */
  3522. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3523. tp->tx_buffers[entry].skb = skb;
  3524. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3525. would_hit_hwbug = 0;
  3526. if (tg3_4g_overflow_test(mapping, len))
  3527. would_hit_hwbug = 1;
  3528. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3529. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3530. entry = NEXT_TX(entry);
  3531. /* Now loop through additional data fragments, and queue them. */
  3532. if (skb_shinfo(skb)->nr_frags > 0) {
  3533. unsigned int i, last;
  3534. last = skb_shinfo(skb)->nr_frags - 1;
  3535. for (i = 0; i <= last; i++) {
  3536. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3537. len = frag->size;
  3538. mapping = pci_map_page(tp->pdev,
  3539. frag->page,
  3540. frag->page_offset,
  3541. len, PCI_DMA_TODEVICE);
  3542. tp->tx_buffers[entry].skb = NULL;
  3543. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3544. if (tg3_4g_overflow_test(mapping, len))
  3545. would_hit_hwbug = 1;
  3546. if (tg3_40bit_overflow_test(tp, mapping, len))
  3547. would_hit_hwbug = 1;
  3548. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3549. tg3_set_txd(tp, entry, mapping, len,
  3550. base_flags, (i == last)|(mss << 1));
  3551. else
  3552. tg3_set_txd(tp, entry, mapping, len,
  3553. base_flags, (i == last));
  3554. entry = NEXT_TX(entry);
  3555. }
  3556. }
  3557. if (would_hit_hwbug) {
  3558. u32 last_plus_one = entry;
  3559. u32 start;
  3560. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3561. start &= (TG3_TX_RING_SIZE - 1);
  3562. /* If the workaround fails due to memory/mapping
  3563. * failure, silently drop this packet.
  3564. */
  3565. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3566. &start, base_flags, mss))
  3567. goto out_unlock;
  3568. entry = start;
  3569. }
  3570. /* Packets are ready, update Tx producer idx local and on card. */
  3571. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3572. tp->tx_prod = entry;
  3573. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3574. netif_stop_queue(dev);
  3575. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3576. netif_wake_queue(tp->dev);
  3577. }
  3578. out_unlock:
  3579. mmiowb();
  3580. dev->trans_start = jiffies;
  3581. return NETDEV_TX_OK;
  3582. }
  3583. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3584. int new_mtu)
  3585. {
  3586. dev->mtu = new_mtu;
  3587. if (new_mtu > ETH_DATA_LEN) {
  3588. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3589. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3590. ethtool_op_set_tso(dev, 0);
  3591. }
  3592. else
  3593. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3594. } else {
  3595. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3596. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3597. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3598. }
  3599. }
  3600. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3601. {
  3602. struct tg3 *tp = netdev_priv(dev);
  3603. int err;
  3604. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3605. return -EINVAL;
  3606. if (!netif_running(dev)) {
  3607. /* We'll just catch it later when the
  3608. * device is up'd.
  3609. */
  3610. tg3_set_mtu(dev, tp, new_mtu);
  3611. return 0;
  3612. }
  3613. tg3_netif_stop(tp);
  3614. tg3_full_lock(tp, 1);
  3615. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3616. tg3_set_mtu(dev, tp, new_mtu);
  3617. err = tg3_restart_hw(tp, 0);
  3618. if (!err)
  3619. tg3_netif_start(tp);
  3620. tg3_full_unlock(tp);
  3621. return err;
  3622. }
  3623. /* Free up pending packets in all rx/tx rings.
  3624. *
  3625. * The chip has been shut down and the driver detached from
  3626. * the networking, so no interrupts or new tx packets will
  3627. * end up in the driver. tp->{tx,}lock is not held and we are not
  3628. * in an interrupt context and thus may sleep.
  3629. */
  3630. static void tg3_free_rings(struct tg3 *tp)
  3631. {
  3632. struct ring_info *rxp;
  3633. int i;
  3634. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3635. rxp = &tp->rx_std_buffers[i];
  3636. if (rxp->skb == NULL)
  3637. continue;
  3638. pci_unmap_single(tp->pdev,
  3639. pci_unmap_addr(rxp, mapping),
  3640. tp->rx_pkt_buf_sz - tp->rx_offset,
  3641. PCI_DMA_FROMDEVICE);
  3642. dev_kfree_skb_any(rxp->skb);
  3643. rxp->skb = NULL;
  3644. }
  3645. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3646. rxp = &tp->rx_jumbo_buffers[i];
  3647. if (rxp->skb == NULL)
  3648. continue;
  3649. pci_unmap_single(tp->pdev,
  3650. pci_unmap_addr(rxp, mapping),
  3651. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3652. PCI_DMA_FROMDEVICE);
  3653. dev_kfree_skb_any(rxp->skb);
  3654. rxp->skb = NULL;
  3655. }
  3656. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3657. struct tx_ring_info *txp;
  3658. struct sk_buff *skb;
  3659. int j;
  3660. txp = &tp->tx_buffers[i];
  3661. skb = txp->skb;
  3662. if (skb == NULL) {
  3663. i++;
  3664. continue;
  3665. }
  3666. pci_unmap_single(tp->pdev,
  3667. pci_unmap_addr(txp, mapping),
  3668. skb_headlen(skb),
  3669. PCI_DMA_TODEVICE);
  3670. txp->skb = NULL;
  3671. i++;
  3672. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3673. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3674. pci_unmap_page(tp->pdev,
  3675. pci_unmap_addr(txp, mapping),
  3676. skb_shinfo(skb)->frags[j].size,
  3677. PCI_DMA_TODEVICE);
  3678. i++;
  3679. }
  3680. dev_kfree_skb_any(skb);
  3681. }
  3682. }
  3683. /* Initialize tx/rx rings for packet processing.
  3684. *
  3685. * The chip has been shut down and the driver detached from
  3686. * the networking, so no interrupts or new tx packets will
  3687. * end up in the driver. tp->{tx,}lock are held and thus
  3688. * we may not sleep.
  3689. */
  3690. static int tg3_init_rings(struct tg3 *tp)
  3691. {
  3692. u32 i;
  3693. /* Free up all the SKBs. */
  3694. tg3_free_rings(tp);
  3695. /* Zero out all descriptors. */
  3696. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3697. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3698. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3699. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3700. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3701. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3702. (tp->dev->mtu > ETH_DATA_LEN))
  3703. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3704. /* Initialize invariants of the rings, we only set this
  3705. * stuff once. This works because the card does not
  3706. * write into the rx buffer posting rings.
  3707. */
  3708. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3709. struct tg3_rx_buffer_desc *rxd;
  3710. rxd = &tp->rx_std[i];
  3711. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3712. << RXD_LEN_SHIFT;
  3713. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  3714. rxd->opaque = (RXD_OPAQUE_RING_STD |
  3715. (i << RXD_OPAQUE_INDEX_SHIFT));
  3716. }
  3717. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3718. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3719. struct tg3_rx_buffer_desc *rxd;
  3720. rxd = &tp->rx_jumbo[i];
  3721. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  3722. << RXD_LEN_SHIFT;
  3723. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  3724. RXD_FLAG_JUMBO;
  3725. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  3726. (i << RXD_OPAQUE_INDEX_SHIFT));
  3727. }
  3728. }
  3729. /* Now allocate fresh SKBs for each rx ring. */
  3730. for (i = 0; i < tp->rx_pending; i++) {
  3731. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  3732. printk(KERN_WARNING PFX
  3733. "%s: Using a smaller RX standard ring, "
  3734. "only %d out of %d buffers were allocated "
  3735. "successfully.\n",
  3736. tp->dev->name, i, tp->rx_pending);
  3737. if (i == 0)
  3738. return -ENOMEM;
  3739. tp->rx_pending = i;
  3740. break;
  3741. }
  3742. }
  3743. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  3744. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  3745. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  3746. -1, i) < 0) {
  3747. printk(KERN_WARNING PFX
  3748. "%s: Using a smaller RX jumbo ring, "
  3749. "only %d out of %d buffers were "
  3750. "allocated successfully.\n",
  3751. tp->dev->name, i, tp->rx_jumbo_pending);
  3752. if (i == 0) {
  3753. tg3_free_rings(tp);
  3754. return -ENOMEM;
  3755. }
  3756. tp->rx_jumbo_pending = i;
  3757. break;
  3758. }
  3759. }
  3760. }
  3761. return 0;
  3762. }
  3763. /*
  3764. * Must not be invoked with interrupt sources disabled and
  3765. * the hardware shutdown down.
  3766. */
  3767. static void tg3_free_consistent(struct tg3 *tp)
  3768. {
  3769. kfree(tp->rx_std_buffers);
  3770. tp->rx_std_buffers = NULL;
  3771. if (tp->rx_std) {
  3772. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3773. tp->rx_std, tp->rx_std_mapping);
  3774. tp->rx_std = NULL;
  3775. }
  3776. if (tp->rx_jumbo) {
  3777. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3778. tp->rx_jumbo, tp->rx_jumbo_mapping);
  3779. tp->rx_jumbo = NULL;
  3780. }
  3781. if (tp->rx_rcb) {
  3782. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3783. tp->rx_rcb, tp->rx_rcb_mapping);
  3784. tp->rx_rcb = NULL;
  3785. }
  3786. if (tp->tx_ring) {
  3787. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3788. tp->tx_ring, tp->tx_desc_mapping);
  3789. tp->tx_ring = NULL;
  3790. }
  3791. if (tp->hw_status) {
  3792. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  3793. tp->hw_status, tp->status_mapping);
  3794. tp->hw_status = NULL;
  3795. }
  3796. if (tp->hw_stats) {
  3797. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  3798. tp->hw_stats, tp->stats_mapping);
  3799. tp->hw_stats = NULL;
  3800. }
  3801. }
  3802. /*
  3803. * Must not be invoked with interrupt sources disabled and
  3804. * the hardware shutdown down. Can sleep.
  3805. */
  3806. static int tg3_alloc_consistent(struct tg3 *tp)
  3807. {
  3808. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  3809. (TG3_RX_RING_SIZE +
  3810. TG3_RX_JUMBO_RING_SIZE)) +
  3811. (sizeof(struct tx_ring_info) *
  3812. TG3_TX_RING_SIZE),
  3813. GFP_KERNEL);
  3814. if (!tp->rx_std_buffers)
  3815. return -ENOMEM;
  3816. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  3817. tp->tx_buffers = (struct tx_ring_info *)
  3818. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  3819. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  3820. &tp->rx_std_mapping);
  3821. if (!tp->rx_std)
  3822. goto err_out;
  3823. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  3824. &tp->rx_jumbo_mapping);
  3825. if (!tp->rx_jumbo)
  3826. goto err_out;
  3827. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  3828. &tp->rx_rcb_mapping);
  3829. if (!tp->rx_rcb)
  3830. goto err_out;
  3831. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  3832. &tp->tx_desc_mapping);
  3833. if (!tp->tx_ring)
  3834. goto err_out;
  3835. tp->hw_status = pci_alloc_consistent(tp->pdev,
  3836. TG3_HW_STATUS_SIZE,
  3837. &tp->status_mapping);
  3838. if (!tp->hw_status)
  3839. goto err_out;
  3840. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  3841. sizeof(struct tg3_hw_stats),
  3842. &tp->stats_mapping);
  3843. if (!tp->hw_stats)
  3844. goto err_out;
  3845. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3846. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3847. return 0;
  3848. err_out:
  3849. tg3_free_consistent(tp);
  3850. return -ENOMEM;
  3851. }
  3852. #define MAX_WAIT_CNT 1000
  3853. /* To stop a block, clear the enable bit and poll till it
  3854. * clears. tp->lock is held.
  3855. */
  3856. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  3857. {
  3858. unsigned int i;
  3859. u32 val;
  3860. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  3861. switch (ofs) {
  3862. case RCVLSC_MODE:
  3863. case DMAC_MODE:
  3864. case MBFREE_MODE:
  3865. case BUFMGR_MODE:
  3866. case MEMARB_MODE:
  3867. /* We can't enable/disable these bits of the
  3868. * 5705/5750, just say success.
  3869. */
  3870. return 0;
  3871. default:
  3872. break;
  3873. };
  3874. }
  3875. val = tr32(ofs);
  3876. val &= ~enable_bit;
  3877. tw32_f(ofs, val);
  3878. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3879. udelay(100);
  3880. val = tr32(ofs);
  3881. if ((val & enable_bit) == 0)
  3882. break;
  3883. }
  3884. if (i == MAX_WAIT_CNT && !silent) {
  3885. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  3886. "ofs=%lx enable_bit=%x\n",
  3887. ofs, enable_bit);
  3888. return -ENODEV;
  3889. }
  3890. return 0;
  3891. }
  3892. /* tp->lock is held. */
  3893. static int tg3_abort_hw(struct tg3 *tp, int silent)
  3894. {
  3895. int i, err;
  3896. tg3_disable_ints(tp);
  3897. tp->rx_mode &= ~RX_MODE_ENABLE;
  3898. tw32_f(MAC_RX_MODE, tp->rx_mode);
  3899. udelay(10);
  3900. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  3901. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  3902. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  3903. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  3904. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  3905. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  3906. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  3907. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  3908. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  3909. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  3910. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  3911. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  3912. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  3913. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  3914. tw32_f(MAC_MODE, tp->mac_mode);
  3915. udelay(40);
  3916. tp->tx_mode &= ~TX_MODE_ENABLE;
  3917. tw32_f(MAC_TX_MODE, tp->tx_mode);
  3918. for (i = 0; i < MAX_WAIT_CNT; i++) {
  3919. udelay(100);
  3920. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  3921. break;
  3922. }
  3923. if (i >= MAX_WAIT_CNT) {
  3924. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  3925. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  3926. tp->dev->name, tr32(MAC_TX_MODE));
  3927. err |= -ENODEV;
  3928. }
  3929. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  3930. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  3931. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  3932. tw32(FTQ_RESET, 0xffffffff);
  3933. tw32(FTQ_RESET, 0x00000000);
  3934. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  3935. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  3936. if (tp->hw_status)
  3937. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  3938. if (tp->hw_stats)
  3939. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  3940. return err;
  3941. }
  3942. /* tp->lock is held. */
  3943. static int tg3_nvram_lock(struct tg3 *tp)
  3944. {
  3945. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3946. int i;
  3947. if (tp->nvram_lock_cnt == 0) {
  3948. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  3949. for (i = 0; i < 8000; i++) {
  3950. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  3951. break;
  3952. udelay(20);
  3953. }
  3954. if (i == 8000) {
  3955. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  3956. return -ENODEV;
  3957. }
  3958. }
  3959. tp->nvram_lock_cnt++;
  3960. }
  3961. return 0;
  3962. }
  3963. /* tp->lock is held. */
  3964. static void tg3_nvram_unlock(struct tg3 *tp)
  3965. {
  3966. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  3967. if (tp->nvram_lock_cnt > 0)
  3968. tp->nvram_lock_cnt--;
  3969. if (tp->nvram_lock_cnt == 0)
  3970. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  3971. }
  3972. }
  3973. /* tp->lock is held. */
  3974. static void tg3_enable_nvram_access(struct tg3 *tp)
  3975. {
  3976. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3977. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3978. u32 nvaccess = tr32(NVRAM_ACCESS);
  3979. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  3980. }
  3981. }
  3982. /* tp->lock is held. */
  3983. static void tg3_disable_nvram_access(struct tg3 *tp)
  3984. {
  3985. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  3986. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  3987. u32 nvaccess = tr32(NVRAM_ACCESS);
  3988. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  3989. }
  3990. }
  3991. /* tp->lock is held. */
  3992. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  3993. {
  3994. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  3995. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  3996. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  3997. switch (kind) {
  3998. case RESET_KIND_INIT:
  3999. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4000. DRV_STATE_START);
  4001. break;
  4002. case RESET_KIND_SHUTDOWN:
  4003. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4004. DRV_STATE_UNLOAD);
  4005. break;
  4006. case RESET_KIND_SUSPEND:
  4007. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4008. DRV_STATE_SUSPEND);
  4009. break;
  4010. default:
  4011. break;
  4012. };
  4013. }
  4014. }
  4015. /* tp->lock is held. */
  4016. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  4017. {
  4018. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4019. switch (kind) {
  4020. case RESET_KIND_INIT:
  4021. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4022. DRV_STATE_START_DONE);
  4023. break;
  4024. case RESET_KIND_SHUTDOWN:
  4025. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4026. DRV_STATE_UNLOAD_DONE);
  4027. break;
  4028. default:
  4029. break;
  4030. };
  4031. }
  4032. }
  4033. /* tp->lock is held. */
  4034. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  4035. {
  4036. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4037. switch (kind) {
  4038. case RESET_KIND_INIT:
  4039. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4040. DRV_STATE_START);
  4041. break;
  4042. case RESET_KIND_SHUTDOWN:
  4043. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4044. DRV_STATE_UNLOAD);
  4045. break;
  4046. case RESET_KIND_SUSPEND:
  4047. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4048. DRV_STATE_SUSPEND);
  4049. break;
  4050. default:
  4051. break;
  4052. };
  4053. }
  4054. }
  4055. static int tg3_poll_fw(struct tg3 *tp)
  4056. {
  4057. int i;
  4058. u32 val;
  4059. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4060. /* Wait up to 20ms for init done. */
  4061. for (i = 0; i < 200; i++) {
  4062. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4063. return 0;
  4064. udelay(100);
  4065. }
  4066. return -ENODEV;
  4067. }
  4068. /* Wait for firmware initialization to complete. */
  4069. for (i = 0; i < 100000; i++) {
  4070. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4071. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4072. break;
  4073. udelay(10);
  4074. }
  4075. /* Chip might not be fitted with firmware. Some Sun onboard
  4076. * parts are configured like that. So don't signal the timeout
  4077. * of the above loop as an error, but do report the lack of
  4078. * running firmware once.
  4079. */
  4080. if (i >= 100000 &&
  4081. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4082. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4083. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4084. tp->dev->name);
  4085. }
  4086. return 0;
  4087. }
  4088. static void tg3_stop_fw(struct tg3 *);
  4089. /* tp->lock is held. */
  4090. static int tg3_chip_reset(struct tg3 *tp)
  4091. {
  4092. u32 val;
  4093. void (*write_op)(struct tg3 *, u32, u32);
  4094. int err;
  4095. tg3_nvram_lock(tp);
  4096. /* No matching tg3_nvram_unlock() after this because
  4097. * chip reset below will undo the nvram lock.
  4098. */
  4099. tp->nvram_lock_cnt = 0;
  4100. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4101. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4102. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  4103. tw32(GRC_FASTBOOT_PC, 0);
  4104. /*
  4105. * We must avoid the readl() that normally takes place.
  4106. * It locks machines, causes machine checks, and other
  4107. * fun things. So, temporarily disable the 5701
  4108. * hardware workaround, while we do the reset.
  4109. */
  4110. write_op = tp->write32;
  4111. if (write_op == tg3_write_flush_reg32)
  4112. tp->write32 = tg3_write32;
  4113. /* Prevent the irq handler from reading or writing PCI registers
  4114. * during chip reset when the memory enable bit in the PCI command
  4115. * register may be cleared. The chip does not generate interrupt
  4116. * at this time, but the irq handler may still be called due to irq
  4117. * sharing or irqpoll.
  4118. */
  4119. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4120. if (tp->hw_status) {
  4121. tp->hw_status->status = 0;
  4122. tp->hw_status->status_tag = 0;
  4123. }
  4124. tp->last_tag = 0;
  4125. smp_mb();
  4126. synchronize_irq(tp->pdev->irq);
  4127. /* do the reset */
  4128. val = GRC_MISC_CFG_CORECLK_RESET;
  4129. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4130. if (tr32(0x7e2c) == 0x60) {
  4131. tw32(0x7e2c, 0x20);
  4132. }
  4133. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4134. tw32(GRC_MISC_CFG, (1 << 29));
  4135. val |= (1 << 29);
  4136. }
  4137. }
  4138. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4139. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4140. tw32(GRC_VCPU_EXT_CTRL,
  4141. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4142. }
  4143. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4144. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4145. tw32(GRC_MISC_CFG, val);
  4146. /* restore 5701 hardware bug workaround write method */
  4147. tp->write32 = write_op;
  4148. /* Unfortunately, we have to delay before the PCI read back.
  4149. * Some 575X chips even will not respond to a PCI cfg access
  4150. * when the reset command is given to the chip.
  4151. *
  4152. * How do these hardware designers expect things to work
  4153. * properly if the PCI write is posted for a long period
  4154. * of time? It is always necessary to have some method by
  4155. * which a register read back can occur to push the write
  4156. * out which does the reset.
  4157. *
  4158. * For most tg3 variants the trick below was working.
  4159. * Ho hum...
  4160. */
  4161. udelay(120);
  4162. /* Flush PCI posted writes. The normal MMIO registers
  4163. * are inaccessible at this time so this is the only
  4164. * way to make this reliably (actually, this is no longer
  4165. * the case, see above). I tried to use indirect
  4166. * register read/write but this upset some 5701 variants.
  4167. */
  4168. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4169. udelay(120);
  4170. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4171. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4172. int i;
  4173. u32 cfg_val;
  4174. /* Wait for link training to complete. */
  4175. for (i = 0; i < 5000; i++)
  4176. udelay(100);
  4177. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4178. pci_write_config_dword(tp->pdev, 0xc4,
  4179. cfg_val | (1 << 15));
  4180. }
  4181. /* Set PCIE max payload size and clear error status. */
  4182. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4183. }
  4184. /* Re-enable indirect register accesses. */
  4185. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4186. tp->misc_host_ctrl);
  4187. /* Set MAX PCI retry to zero. */
  4188. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4189. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4190. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4191. val |= PCISTATE_RETRY_SAME_DMA;
  4192. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4193. pci_restore_state(tp->pdev);
  4194. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4195. /* Make sure PCI-X relaxed ordering bit is clear. */
  4196. pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
  4197. val &= ~PCIX_CAPS_RELAXED_ORDERING;
  4198. pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
  4199. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4200. u32 val;
  4201. /* Chip reset on 5780 will reset MSI enable bit,
  4202. * so need to restore it.
  4203. */
  4204. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4205. u16 ctrl;
  4206. pci_read_config_word(tp->pdev,
  4207. tp->msi_cap + PCI_MSI_FLAGS,
  4208. &ctrl);
  4209. pci_write_config_word(tp->pdev,
  4210. tp->msi_cap + PCI_MSI_FLAGS,
  4211. ctrl | PCI_MSI_FLAGS_ENABLE);
  4212. val = tr32(MSGINT_MODE);
  4213. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4214. }
  4215. val = tr32(MEMARB_MODE);
  4216. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4217. } else
  4218. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  4219. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4220. tg3_stop_fw(tp);
  4221. tw32(0x5000, 0x400);
  4222. }
  4223. tw32(GRC_MODE, tp->grc_mode);
  4224. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4225. u32 val = tr32(0xc4);
  4226. tw32(0xc4, val | (1 << 15));
  4227. }
  4228. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4229. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4230. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4231. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4232. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4233. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4234. }
  4235. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4236. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4237. tw32_f(MAC_MODE, tp->mac_mode);
  4238. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4239. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4240. tw32_f(MAC_MODE, tp->mac_mode);
  4241. } else
  4242. tw32_f(MAC_MODE, 0);
  4243. udelay(40);
  4244. err = tg3_poll_fw(tp);
  4245. if (err)
  4246. return err;
  4247. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4248. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4249. u32 val = tr32(0x7c00);
  4250. tw32(0x7c00, val | (1 << 25));
  4251. }
  4252. /* Reprobe ASF enable state. */
  4253. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4254. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4255. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4256. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4257. u32 nic_cfg;
  4258. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4259. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4260. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4261. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4262. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4263. }
  4264. }
  4265. return 0;
  4266. }
  4267. /* tp->lock is held. */
  4268. static void tg3_stop_fw(struct tg3 *tp)
  4269. {
  4270. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4271. u32 val;
  4272. int i;
  4273. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4274. val = tr32(GRC_RX_CPU_EVENT);
  4275. val |= (1 << 14);
  4276. tw32(GRC_RX_CPU_EVENT, val);
  4277. /* Wait for RX cpu to ACK the event. */
  4278. for (i = 0; i < 100; i++) {
  4279. if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
  4280. break;
  4281. udelay(1);
  4282. }
  4283. }
  4284. }
  4285. /* tp->lock is held. */
  4286. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4287. {
  4288. int err;
  4289. tg3_stop_fw(tp);
  4290. tg3_write_sig_pre_reset(tp, kind);
  4291. tg3_abort_hw(tp, silent);
  4292. err = tg3_chip_reset(tp);
  4293. tg3_write_sig_legacy(tp, kind);
  4294. tg3_write_sig_post_reset(tp, kind);
  4295. if (err)
  4296. return err;
  4297. return 0;
  4298. }
  4299. #define TG3_FW_RELEASE_MAJOR 0x0
  4300. #define TG3_FW_RELASE_MINOR 0x0
  4301. #define TG3_FW_RELEASE_FIX 0x0
  4302. #define TG3_FW_START_ADDR 0x08000000
  4303. #define TG3_FW_TEXT_ADDR 0x08000000
  4304. #define TG3_FW_TEXT_LEN 0x9c0
  4305. #define TG3_FW_RODATA_ADDR 0x080009c0
  4306. #define TG3_FW_RODATA_LEN 0x60
  4307. #define TG3_FW_DATA_ADDR 0x08000a40
  4308. #define TG3_FW_DATA_LEN 0x20
  4309. #define TG3_FW_SBSS_ADDR 0x08000a60
  4310. #define TG3_FW_SBSS_LEN 0xc
  4311. #define TG3_FW_BSS_ADDR 0x08000a70
  4312. #define TG3_FW_BSS_LEN 0x10
  4313. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4314. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4315. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4316. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4317. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4318. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4319. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4320. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4321. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4322. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4323. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4324. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4325. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4326. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4327. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4328. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4329. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4330. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4331. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4332. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4333. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4334. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4335. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4336. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4339. 0, 0, 0, 0, 0, 0,
  4340. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4341. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4342. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4343. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4344. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4345. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4346. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4347. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4348. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4349. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4350. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4354. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4355. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4356. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4357. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4358. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4359. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4360. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4361. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4362. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4363. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4364. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4365. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4366. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4367. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4368. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4369. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4370. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4371. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4372. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4373. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4374. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4375. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4376. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4377. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4378. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4379. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4380. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4381. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4382. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4383. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4384. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4385. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4386. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4387. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4388. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4389. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4390. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4391. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4392. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4393. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4394. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4395. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4396. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4397. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4398. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4399. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4400. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4401. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4402. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4403. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4404. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4405. };
  4406. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4407. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4408. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4409. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4410. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4411. 0x00000000
  4412. };
  4413. #if 0 /* All zeros, don't eat up space with it. */
  4414. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4415. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4416. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4417. };
  4418. #endif
  4419. #define RX_CPU_SCRATCH_BASE 0x30000
  4420. #define RX_CPU_SCRATCH_SIZE 0x04000
  4421. #define TX_CPU_SCRATCH_BASE 0x34000
  4422. #define TX_CPU_SCRATCH_SIZE 0x04000
  4423. /* tp->lock is held. */
  4424. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4425. {
  4426. int i;
  4427. BUG_ON(offset == TX_CPU_BASE &&
  4428. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4429. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4430. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4431. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4432. return 0;
  4433. }
  4434. if (offset == RX_CPU_BASE) {
  4435. for (i = 0; i < 10000; i++) {
  4436. tw32(offset + CPU_STATE, 0xffffffff);
  4437. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4438. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4439. break;
  4440. }
  4441. tw32(offset + CPU_STATE, 0xffffffff);
  4442. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4443. udelay(10);
  4444. } else {
  4445. for (i = 0; i < 10000; i++) {
  4446. tw32(offset + CPU_STATE, 0xffffffff);
  4447. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4448. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4449. break;
  4450. }
  4451. }
  4452. if (i >= 10000) {
  4453. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4454. "and %s CPU\n",
  4455. tp->dev->name,
  4456. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4457. return -ENODEV;
  4458. }
  4459. /* Clear firmware's nvram arbitration. */
  4460. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4461. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4462. return 0;
  4463. }
  4464. struct fw_info {
  4465. unsigned int text_base;
  4466. unsigned int text_len;
  4467. const u32 *text_data;
  4468. unsigned int rodata_base;
  4469. unsigned int rodata_len;
  4470. const u32 *rodata_data;
  4471. unsigned int data_base;
  4472. unsigned int data_len;
  4473. const u32 *data_data;
  4474. };
  4475. /* tp->lock is held. */
  4476. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4477. int cpu_scratch_size, struct fw_info *info)
  4478. {
  4479. int err, lock_err, i;
  4480. void (*write_op)(struct tg3 *, u32, u32);
  4481. if (cpu_base == TX_CPU_BASE &&
  4482. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4483. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4484. "TX cpu firmware on %s which is 5705.\n",
  4485. tp->dev->name);
  4486. return -EINVAL;
  4487. }
  4488. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4489. write_op = tg3_write_mem;
  4490. else
  4491. write_op = tg3_write_indirect_reg32;
  4492. /* It is possible that bootcode is still loading at this point.
  4493. * Get the nvram lock first before halting the cpu.
  4494. */
  4495. lock_err = tg3_nvram_lock(tp);
  4496. err = tg3_halt_cpu(tp, cpu_base);
  4497. if (!lock_err)
  4498. tg3_nvram_unlock(tp);
  4499. if (err)
  4500. goto out;
  4501. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4502. write_op(tp, cpu_scratch_base + i, 0);
  4503. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4504. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4505. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4506. write_op(tp, (cpu_scratch_base +
  4507. (info->text_base & 0xffff) +
  4508. (i * sizeof(u32))),
  4509. (info->text_data ?
  4510. info->text_data[i] : 0));
  4511. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4512. write_op(tp, (cpu_scratch_base +
  4513. (info->rodata_base & 0xffff) +
  4514. (i * sizeof(u32))),
  4515. (info->rodata_data ?
  4516. info->rodata_data[i] : 0));
  4517. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4518. write_op(tp, (cpu_scratch_base +
  4519. (info->data_base & 0xffff) +
  4520. (i * sizeof(u32))),
  4521. (info->data_data ?
  4522. info->data_data[i] : 0));
  4523. err = 0;
  4524. out:
  4525. return err;
  4526. }
  4527. /* tp->lock is held. */
  4528. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4529. {
  4530. struct fw_info info;
  4531. int err, i;
  4532. info.text_base = TG3_FW_TEXT_ADDR;
  4533. info.text_len = TG3_FW_TEXT_LEN;
  4534. info.text_data = &tg3FwText[0];
  4535. info.rodata_base = TG3_FW_RODATA_ADDR;
  4536. info.rodata_len = TG3_FW_RODATA_LEN;
  4537. info.rodata_data = &tg3FwRodata[0];
  4538. info.data_base = TG3_FW_DATA_ADDR;
  4539. info.data_len = TG3_FW_DATA_LEN;
  4540. info.data_data = NULL;
  4541. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4542. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4543. &info);
  4544. if (err)
  4545. return err;
  4546. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4547. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4548. &info);
  4549. if (err)
  4550. return err;
  4551. /* Now startup only the RX cpu. */
  4552. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4553. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4554. for (i = 0; i < 5; i++) {
  4555. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4556. break;
  4557. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4558. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4559. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4560. udelay(1000);
  4561. }
  4562. if (i >= 5) {
  4563. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4564. "to set RX CPU PC, is %08x should be %08x\n",
  4565. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4566. TG3_FW_TEXT_ADDR);
  4567. return -ENODEV;
  4568. }
  4569. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4570. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4571. return 0;
  4572. }
  4573. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4574. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4575. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4576. #define TG3_TSO_FW_START_ADDR 0x08000000
  4577. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4578. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4579. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4580. #define TG3_TSO_FW_RODATA_LEN 0x60
  4581. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4582. #define TG3_TSO_FW_DATA_LEN 0x30
  4583. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4584. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4585. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4586. #define TG3_TSO_FW_BSS_LEN 0x894
  4587. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4588. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4589. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4590. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4591. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4592. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4593. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4594. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4595. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4596. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4597. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4598. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4599. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4600. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4601. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4602. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4603. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4604. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4605. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4606. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4607. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4608. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4609. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4610. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4611. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4612. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4613. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4614. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4615. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4616. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  4617. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4618. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  4619. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  4620. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  4621. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  4622. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  4623. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  4624. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  4625. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  4626. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4627. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  4628. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  4629. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  4630. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  4631. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  4632. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  4633. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  4634. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  4635. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4636. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  4637. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  4638. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  4639. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  4640. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  4641. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  4642. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  4643. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  4644. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  4645. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  4646. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  4647. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  4648. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  4649. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  4650. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  4651. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  4652. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  4653. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  4654. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  4655. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  4656. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  4657. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  4658. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  4659. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  4660. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  4661. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  4662. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  4663. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  4664. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  4665. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  4666. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  4667. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  4668. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  4669. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  4670. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  4671. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  4672. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  4673. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  4674. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  4675. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4676. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  4677. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  4678. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  4679. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  4680. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  4681. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  4682. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  4683. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  4684. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  4685. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  4686. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  4687. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  4688. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  4689. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  4690. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  4691. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  4692. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  4693. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  4694. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  4695. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  4696. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  4697. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  4698. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  4699. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  4700. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  4701. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  4702. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  4703. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  4704. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  4705. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  4706. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  4707. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  4708. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  4709. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  4710. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  4711. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  4712. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  4713. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  4714. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  4715. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  4716. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  4717. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  4718. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  4719. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  4720. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  4721. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  4722. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  4723. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  4724. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  4725. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  4726. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4727. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  4728. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  4729. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  4730. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  4731. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  4732. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  4733. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  4734. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  4735. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  4736. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  4737. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  4738. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  4739. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  4740. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  4741. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  4742. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  4743. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  4744. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  4745. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  4746. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  4747. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  4748. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  4749. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  4750. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  4751. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  4752. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  4753. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  4754. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  4755. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  4756. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  4757. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4758. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  4759. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  4760. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  4761. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  4762. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  4763. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  4764. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  4765. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  4766. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  4767. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  4768. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  4769. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  4770. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  4771. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  4772. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  4773. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  4774. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  4775. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  4776. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  4777. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  4778. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  4779. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  4780. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  4781. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  4782. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  4783. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  4784. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  4785. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  4786. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  4787. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  4788. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  4789. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  4790. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  4791. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  4792. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  4793. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  4794. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  4795. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  4796. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  4797. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  4798. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  4799. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  4800. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  4801. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  4802. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  4803. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  4804. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  4805. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  4806. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  4807. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  4808. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4809. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  4810. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  4811. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  4812. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  4813. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  4814. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  4815. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  4816. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  4817. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  4818. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  4819. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  4820. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  4821. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  4822. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  4823. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  4824. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  4825. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  4826. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  4827. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  4828. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  4829. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  4830. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  4831. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  4832. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  4833. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  4834. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  4835. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  4836. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  4837. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  4838. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  4839. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  4840. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  4841. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  4842. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  4843. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  4844. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  4845. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  4846. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  4847. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  4848. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  4849. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  4850. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  4851. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  4852. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  4853. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  4854. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  4855. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  4856. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  4857. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  4858. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  4859. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  4860. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  4861. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  4862. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  4863. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  4864. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  4865. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  4866. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  4867. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  4868. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  4869. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  4870. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  4871. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  4872. };
  4873. static const u32 tg3TsoFwRodata[] = {
  4874. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  4875. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  4876. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  4877. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  4878. 0x00000000,
  4879. };
  4880. static const u32 tg3TsoFwData[] = {
  4881. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  4882. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4883. 0x00000000,
  4884. };
  4885. /* 5705 needs a special version of the TSO firmware. */
  4886. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  4887. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  4888. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  4889. #define TG3_TSO5_FW_START_ADDR 0x00010000
  4890. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  4891. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  4892. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  4893. #define TG3_TSO5_FW_RODATA_LEN 0x50
  4894. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  4895. #define TG3_TSO5_FW_DATA_LEN 0x20
  4896. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  4897. #define TG3_TSO5_FW_SBSS_LEN 0x28
  4898. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  4899. #define TG3_TSO5_FW_BSS_LEN 0x88
  4900. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  4901. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  4902. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  4903. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4904. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  4905. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  4906. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  4907. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  4908. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  4909. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  4910. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  4911. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  4912. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  4913. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  4914. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  4915. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  4916. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  4917. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  4918. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  4919. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  4920. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  4921. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  4922. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  4923. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  4924. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  4925. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  4926. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  4927. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  4928. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  4929. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  4930. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  4931. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4932. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  4933. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  4934. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  4935. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  4936. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  4937. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  4938. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  4939. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  4940. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  4941. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  4942. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  4943. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  4944. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  4945. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  4946. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  4947. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  4948. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  4949. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  4950. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  4951. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  4952. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  4953. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  4954. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  4955. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  4956. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  4957. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  4958. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  4959. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  4960. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  4961. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  4962. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  4963. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  4964. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  4965. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  4966. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  4967. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  4968. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  4969. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  4970. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  4971. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  4972. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  4973. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  4974. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  4975. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  4976. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  4977. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  4978. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  4979. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  4980. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  4981. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  4982. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  4983. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  4984. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  4985. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  4986. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  4987. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  4988. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  4989. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  4990. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  4991. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  4992. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  4993. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  4994. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  4995. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  4996. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  4997. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  4998. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  4999. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  5000. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  5001. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  5002. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  5003. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  5004. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  5005. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  5006. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  5007. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5008. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5009. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  5010. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  5011. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  5012. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  5013. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  5014. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  5015. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  5016. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  5017. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  5018. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5019. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5020. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  5021. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  5022. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  5023. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  5024. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5025. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  5026. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  5027. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  5028. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  5029. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  5030. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  5031. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  5032. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  5033. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  5034. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  5035. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  5036. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  5037. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  5038. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  5039. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  5040. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  5041. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  5042. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  5043. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  5044. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  5045. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  5046. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  5047. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  5048. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  5049. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  5050. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  5051. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  5052. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  5053. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5054. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5055. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5056. 0x00000000, 0x00000000, 0x00000000,
  5057. };
  5058. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5059. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5060. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5061. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5062. 0x00000000, 0x00000000, 0x00000000,
  5063. };
  5064. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5065. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5066. 0x00000000, 0x00000000, 0x00000000,
  5067. };
  5068. /* tp->lock is held. */
  5069. static int tg3_load_tso_firmware(struct tg3 *tp)
  5070. {
  5071. struct fw_info info;
  5072. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5073. int err, i;
  5074. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5075. return 0;
  5076. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5077. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5078. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5079. info.text_data = &tg3Tso5FwText[0];
  5080. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5081. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5082. info.rodata_data = &tg3Tso5FwRodata[0];
  5083. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5084. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5085. info.data_data = &tg3Tso5FwData[0];
  5086. cpu_base = RX_CPU_BASE;
  5087. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5088. cpu_scratch_size = (info.text_len +
  5089. info.rodata_len +
  5090. info.data_len +
  5091. TG3_TSO5_FW_SBSS_LEN +
  5092. TG3_TSO5_FW_BSS_LEN);
  5093. } else {
  5094. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5095. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5096. info.text_data = &tg3TsoFwText[0];
  5097. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5098. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5099. info.rodata_data = &tg3TsoFwRodata[0];
  5100. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5101. info.data_len = TG3_TSO_FW_DATA_LEN;
  5102. info.data_data = &tg3TsoFwData[0];
  5103. cpu_base = TX_CPU_BASE;
  5104. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5105. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5106. }
  5107. err = tg3_load_firmware_cpu(tp, cpu_base,
  5108. cpu_scratch_base, cpu_scratch_size,
  5109. &info);
  5110. if (err)
  5111. return err;
  5112. /* Now startup the cpu. */
  5113. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5114. tw32_f(cpu_base + CPU_PC, info.text_base);
  5115. for (i = 0; i < 5; i++) {
  5116. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5117. break;
  5118. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5119. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5120. tw32_f(cpu_base + CPU_PC, info.text_base);
  5121. udelay(1000);
  5122. }
  5123. if (i >= 5) {
  5124. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5125. "to set CPU PC, is %08x should be %08x\n",
  5126. tp->dev->name, tr32(cpu_base + CPU_PC),
  5127. info.text_base);
  5128. return -ENODEV;
  5129. }
  5130. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5131. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5132. return 0;
  5133. }
  5134. /* tp->lock is held. */
  5135. static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
  5136. {
  5137. u32 addr_high, addr_low;
  5138. int i;
  5139. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5140. tp->dev->dev_addr[1]);
  5141. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5142. (tp->dev->dev_addr[3] << 16) |
  5143. (tp->dev->dev_addr[4] << 8) |
  5144. (tp->dev->dev_addr[5] << 0));
  5145. for (i = 0; i < 4; i++) {
  5146. if (i == 1 && skip_mac_1)
  5147. continue;
  5148. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5149. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5150. }
  5151. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5152. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5153. for (i = 0; i < 12; i++) {
  5154. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5155. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5156. }
  5157. }
  5158. addr_high = (tp->dev->dev_addr[0] +
  5159. tp->dev->dev_addr[1] +
  5160. tp->dev->dev_addr[2] +
  5161. tp->dev->dev_addr[3] +
  5162. tp->dev->dev_addr[4] +
  5163. tp->dev->dev_addr[5]) &
  5164. TX_BACKOFF_SEED_MASK;
  5165. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5166. }
  5167. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5168. {
  5169. struct tg3 *tp = netdev_priv(dev);
  5170. struct sockaddr *addr = p;
  5171. int err = 0, skip_mac_1 = 0;
  5172. if (!is_valid_ether_addr(addr->sa_data))
  5173. return -EINVAL;
  5174. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5175. if (!netif_running(dev))
  5176. return 0;
  5177. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5178. u32 addr0_high, addr0_low, addr1_high, addr1_low;
  5179. addr0_high = tr32(MAC_ADDR_0_HIGH);
  5180. addr0_low = tr32(MAC_ADDR_0_LOW);
  5181. addr1_high = tr32(MAC_ADDR_1_HIGH);
  5182. addr1_low = tr32(MAC_ADDR_1_LOW);
  5183. /* Skip MAC addr 1 if ASF is using it. */
  5184. if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
  5185. !(addr1_high == 0 && addr1_low == 0))
  5186. skip_mac_1 = 1;
  5187. }
  5188. spin_lock_bh(&tp->lock);
  5189. __tg3_set_mac_addr(tp, skip_mac_1);
  5190. spin_unlock_bh(&tp->lock);
  5191. return err;
  5192. }
  5193. /* tp->lock is held. */
  5194. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5195. dma_addr_t mapping, u32 maxlen_flags,
  5196. u32 nic_addr)
  5197. {
  5198. tg3_write_mem(tp,
  5199. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5200. ((u64) mapping >> 32));
  5201. tg3_write_mem(tp,
  5202. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5203. ((u64) mapping & 0xffffffff));
  5204. tg3_write_mem(tp,
  5205. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5206. maxlen_flags);
  5207. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5208. tg3_write_mem(tp,
  5209. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5210. nic_addr);
  5211. }
  5212. static void __tg3_set_rx_mode(struct net_device *);
  5213. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5214. {
  5215. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5216. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5217. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5218. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5219. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5220. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5221. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5222. }
  5223. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5224. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5225. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5226. u32 val = ec->stats_block_coalesce_usecs;
  5227. if (!netif_carrier_ok(tp->dev))
  5228. val = 0;
  5229. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5230. }
  5231. }
  5232. /* tp->lock is held. */
  5233. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5234. {
  5235. u32 val, rdmac_mode;
  5236. int i, err, limit;
  5237. tg3_disable_ints(tp);
  5238. tg3_stop_fw(tp);
  5239. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5240. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5241. tg3_abort_hw(tp, 1);
  5242. }
  5243. if (reset_phy)
  5244. tg3_phy_reset(tp);
  5245. err = tg3_chip_reset(tp);
  5246. if (err)
  5247. return err;
  5248. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5249. /* This works around an issue with Athlon chipsets on
  5250. * B3 tigon3 silicon. This bit has no effect on any
  5251. * other revision. But do not set this on PCI Express
  5252. * chips.
  5253. */
  5254. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5255. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5256. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5257. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5258. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5259. val = tr32(TG3PCI_PCISTATE);
  5260. val |= PCISTATE_RETRY_SAME_DMA;
  5261. tw32(TG3PCI_PCISTATE, val);
  5262. }
  5263. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5264. /* Enable some hw fixes. */
  5265. val = tr32(TG3PCI_MSI_DATA);
  5266. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5267. tw32(TG3PCI_MSI_DATA, val);
  5268. }
  5269. /* Descriptor ring init may make accesses to the
  5270. * NIC SRAM area to setup the TX descriptors, so we
  5271. * can only do this after the hardware has been
  5272. * successfully reset.
  5273. */
  5274. err = tg3_init_rings(tp);
  5275. if (err)
  5276. return err;
  5277. /* This value is determined during the probe time DMA
  5278. * engine test, tg3_test_dma.
  5279. */
  5280. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5281. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5282. GRC_MODE_4X_NIC_SEND_RINGS |
  5283. GRC_MODE_NO_TX_PHDR_CSUM |
  5284. GRC_MODE_NO_RX_PHDR_CSUM);
  5285. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5286. /* Pseudo-header checksum is done by hardware logic and not
  5287. * the offload processers, so make the chip do the pseudo-
  5288. * header checksums on receive. For transmit it is more
  5289. * convenient to do the pseudo-header checksum in software
  5290. * as Linux does that on transmit for us in all cases.
  5291. */
  5292. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5293. tw32(GRC_MODE,
  5294. tp->grc_mode |
  5295. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5296. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5297. val = tr32(GRC_MISC_CFG);
  5298. val &= ~0xff;
  5299. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5300. tw32(GRC_MISC_CFG, val);
  5301. /* Initialize MBUF/DESC pool. */
  5302. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5303. /* Do nothing. */
  5304. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5305. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5306. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5307. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5308. else
  5309. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5310. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5311. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5312. }
  5313. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5314. int fw_len;
  5315. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5316. TG3_TSO5_FW_RODATA_LEN +
  5317. TG3_TSO5_FW_DATA_LEN +
  5318. TG3_TSO5_FW_SBSS_LEN +
  5319. TG3_TSO5_FW_BSS_LEN);
  5320. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5321. tw32(BUFMGR_MB_POOL_ADDR,
  5322. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5323. tw32(BUFMGR_MB_POOL_SIZE,
  5324. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5325. }
  5326. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5327. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5328. tp->bufmgr_config.mbuf_read_dma_low_water);
  5329. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5330. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5331. tw32(BUFMGR_MB_HIGH_WATER,
  5332. tp->bufmgr_config.mbuf_high_water);
  5333. } else {
  5334. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5335. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5336. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5337. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5338. tw32(BUFMGR_MB_HIGH_WATER,
  5339. tp->bufmgr_config.mbuf_high_water_jumbo);
  5340. }
  5341. tw32(BUFMGR_DMA_LOW_WATER,
  5342. tp->bufmgr_config.dma_low_water);
  5343. tw32(BUFMGR_DMA_HIGH_WATER,
  5344. tp->bufmgr_config.dma_high_water);
  5345. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5346. for (i = 0; i < 2000; i++) {
  5347. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5348. break;
  5349. udelay(10);
  5350. }
  5351. if (i >= 2000) {
  5352. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5353. tp->dev->name);
  5354. return -ENODEV;
  5355. }
  5356. /* Setup replenish threshold. */
  5357. val = tp->rx_pending / 8;
  5358. if (val == 0)
  5359. val = 1;
  5360. else if (val > tp->rx_std_max_post)
  5361. val = tp->rx_std_max_post;
  5362. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5363. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5364. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5365. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5366. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5367. }
  5368. tw32(RCVBDI_STD_THRESH, val);
  5369. /* Initialize TG3_BDINFO's at:
  5370. * RCVDBDI_STD_BD: standard eth size rx ring
  5371. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5372. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5373. *
  5374. * like so:
  5375. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5376. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5377. * ring attribute flags
  5378. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5379. *
  5380. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5381. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5382. *
  5383. * The size of each ring is fixed in the firmware, but the location is
  5384. * configurable.
  5385. */
  5386. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5387. ((u64) tp->rx_std_mapping >> 32));
  5388. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5389. ((u64) tp->rx_std_mapping & 0xffffffff));
  5390. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5391. NIC_SRAM_RX_BUFFER_DESC);
  5392. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5393. * configs on 5705.
  5394. */
  5395. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5396. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5397. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5398. } else {
  5399. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5400. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5401. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5402. BDINFO_FLAGS_DISABLED);
  5403. /* Setup replenish threshold. */
  5404. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5405. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5406. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5407. ((u64) tp->rx_jumbo_mapping >> 32));
  5408. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5409. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5410. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5411. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5412. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5413. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5414. } else {
  5415. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5416. BDINFO_FLAGS_DISABLED);
  5417. }
  5418. }
  5419. /* There is only one send ring on 5705/5750, no need to explicitly
  5420. * disable the others.
  5421. */
  5422. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5423. /* Clear out send RCB ring in SRAM. */
  5424. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5425. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5426. BDINFO_FLAGS_DISABLED);
  5427. }
  5428. tp->tx_prod = 0;
  5429. tp->tx_cons = 0;
  5430. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5431. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5432. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5433. tp->tx_desc_mapping,
  5434. (TG3_TX_RING_SIZE <<
  5435. BDINFO_FLAGS_MAXLEN_SHIFT),
  5436. NIC_SRAM_TX_BUFFER_DESC);
  5437. /* There is only one receive return ring on 5705/5750, no need
  5438. * to explicitly disable the others.
  5439. */
  5440. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5441. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5442. i += TG3_BDINFO_SIZE) {
  5443. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5444. BDINFO_FLAGS_DISABLED);
  5445. }
  5446. }
  5447. tp->rx_rcb_ptr = 0;
  5448. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5449. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5450. tp->rx_rcb_mapping,
  5451. (TG3_RX_RCB_RING_SIZE(tp) <<
  5452. BDINFO_FLAGS_MAXLEN_SHIFT),
  5453. 0);
  5454. tp->rx_std_ptr = tp->rx_pending;
  5455. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5456. tp->rx_std_ptr);
  5457. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5458. tp->rx_jumbo_pending : 0;
  5459. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5460. tp->rx_jumbo_ptr);
  5461. /* Initialize MAC address and backoff seed. */
  5462. __tg3_set_mac_addr(tp, 0);
  5463. /* MTU + ethernet header + FCS + optional VLAN tag */
  5464. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5465. /* The slot time is changed by tg3_setup_phy if we
  5466. * run at gigabit with half duplex.
  5467. */
  5468. tw32(MAC_TX_LENGTHS,
  5469. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5470. (6 << TX_LENGTHS_IPG_SHIFT) |
  5471. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5472. /* Receive rules. */
  5473. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5474. tw32(RCVLPC_CONFIG, 0x0181);
  5475. /* Calculate RDMAC_MODE setting early, we need it to determine
  5476. * the RCVLPC_STATE_ENABLE mask.
  5477. */
  5478. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5479. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5480. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5481. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5482. RDMAC_MODE_LNGREAD_ENAB);
  5483. /* If statement applies to 5705 and 5750 PCI devices only */
  5484. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5485. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5486. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5487. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5488. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5489. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5490. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5491. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5492. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5493. }
  5494. }
  5495. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5496. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5497. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5498. rdmac_mode |= (1 << 27);
  5499. /* Receive/send statistics. */
  5500. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5501. val = tr32(RCVLPC_STATS_ENABLE);
  5502. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5503. tw32(RCVLPC_STATS_ENABLE, val);
  5504. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5505. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5506. val = tr32(RCVLPC_STATS_ENABLE);
  5507. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5508. tw32(RCVLPC_STATS_ENABLE, val);
  5509. } else {
  5510. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5511. }
  5512. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5513. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5514. tw32(SNDDATAI_STATSCTRL,
  5515. (SNDDATAI_SCTRL_ENABLE |
  5516. SNDDATAI_SCTRL_FASTUPD));
  5517. /* Setup host coalescing engine. */
  5518. tw32(HOSTCC_MODE, 0);
  5519. for (i = 0; i < 2000; i++) {
  5520. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5521. break;
  5522. udelay(10);
  5523. }
  5524. __tg3_set_coalesce(tp, &tp->coal);
  5525. /* set status block DMA address */
  5526. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5527. ((u64) tp->status_mapping >> 32));
  5528. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5529. ((u64) tp->status_mapping & 0xffffffff));
  5530. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5531. /* Status/statistics block address. See tg3_timer,
  5532. * the tg3_periodic_fetch_stats call there, and
  5533. * tg3_get_stats to see how this works for 5705/5750 chips.
  5534. */
  5535. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5536. ((u64) tp->stats_mapping >> 32));
  5537. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5538. ((u64) tp->stats_mapping & 0xffffffff));
  5539. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5540. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5541. }
  5542. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5543. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5544. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5545. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5546. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5547. /* Clear statistics/status block in chip, and status block in ram. */
  5548. for (i = NIC_SRAM_STATS_BLK;
  5549. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5550. i += sizeof(u32)) {
  5551. tg3_write_mem(tp, i, 0);
  5552. udelay(40);
  5553. }
  5554. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5555. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5556. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5557. /* reset to prevent losing 1st rx packet intermittently */
  5558. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5559. udelay(10);
  5560. }
  5561. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5562. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5563. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5564. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5565. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
  5566. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  5567. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5568. udelay(40);
  5569. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5570. * If TG3_FLG2_IS_NIC is zero, we should read the
  5571. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5572. * whether used as inputs or outputs, are set by boot code after
  5573. * reset.
  5574. */
  5575. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5576. u32 gpio_mask;
  5577. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5578. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5579. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5580. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  5581. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  5582. GRC_LCLCTRL_GPIO_OUTPUT3;
  5583. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5584. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  5585. tp->grc_local_ctrl &= ~gpio_mask;
  5586. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  5587. /* GPIO1 must be driven high for eeprom write protect */
  5588. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  5589. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  5590. GRC_LCLCTRL_GPIO_OUTPUT1);
  5591. }
  5592. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5593. udelay(100);
  5594. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  5595. tp->last_tag = 0;
  5596. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5597. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  5598. udelay(40);
  5599. }
  5600. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  5601. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  5602. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  5603. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  5604. WDMAC_MODE_LNGREAD_ENAB);
  5605. /* If statement applies to 5705 and 5750 PCI devices only */
  5606. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5607. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5608. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  5609. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  5610. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  5611. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  5612. /* nothing */
  5613. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5614. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  5615. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  5616. val |= WDMAC_MODE_RX_ACCEL;
  5617. }
  5618. }
  5619. /* Enable host coalescing bug fix */
  5620. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  5621. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
  5622. val |= (1 << 29);
  5623. tw32_f(WDMAC_MODE, val);
  5624. udelay(40);
  5625. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) {
  5626. val = tr32(TG3PCI_X_CAPS);
  5627. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  5628. val &= ~PCIX_CAPS_BURST_MASK;
  5629. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5630. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5631. val &= ~(PCIX_CAPS_SPLIT_MASK | PCIX_CAPS_BURST_MASK);
  5632. val |= (PCIX_CAPS_MAX_BURST_CPIOB << PCIX_CAPS_BURST_SHIFT);
  5633. }
  5634. tw32(TG3PCI_X_CAPS, val);
  5635. }
  5636. tw32_f(RDMAC_MODE, rdmac_mode);
  5637. udelay(40);
  5638. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  5639. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5640. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  5641. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  5642. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  5643. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  5644. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  5645. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  5646. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5647. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  5648. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  5649. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  5650. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  5651. err = tg3_load_5701_a0_firmware_fix(tp);
  5652. if (err)
  5653. return err;
  5654. }
  5655. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5656. err = tg3_load_tso_firmware(tp);
  5657. if (err)
  5658. return err;
  5659. }
  5660. tp->tx_mode = TX_MODE_ENABLE;
  5661. tw32_f(MAC_TX_MODE, tp->tx_mode);
  5662. udelay(100);
  5663. tp->rx_mode = RX_MODE_ENABLE;
  5664. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  5665. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  5666. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5667. udelay(10);
  5668. if (tp->link_config.phy_is_low_power) {
  5669. tp->link_config.phy_is_low_power = 0;
  5670. tp->link_config.speed = tp->link_config.orig_speed;
  5671. tp->link_config.duplex = tp->link_config.orig_duplex;
  5672. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  5673. }
  5674. tp->mi_mode = MAC_MI_MODE_BASE;
  5675. tw32_f(MAC_MI_MODE, tp->mi_mode);
  5676. udelay(80);
  5677. tw32(MAC_LED_CTRL, tp->led_ctrl);
  5678. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  5679. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5680. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5681. udelay(10);
  5682. }
  5683. tw32_f(MAC_RX_MODE, tp->rx_mode);
  5684. udelay(10);
  5685. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  5686. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  5687. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  5688. /* Set drive transmission level to 1.2V */
  5689. /* only if the signal pre-emphasis bit is not set */
  5690. val = tr32(MAC_SERDES_CFG);
  5691. val &= 0xfffff000;
  5692. val |= 0x880;
  5693. tw32(MAC_SERDES_CFG, val);
  5694. }
  5695. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  5696. tw32(MAC_SERDES_CFG, 0x616000);
  5697. }
  5698. /* Prevent chip from dropping frames when flow control
  5699. * is enabled.
  5700. */
  5701. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  5702. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  5703. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  5704. /* Use hardware link auto-negotiation */
  5705. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  5706. }
  5707. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  5708. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  5709. u32 tmp;
  5710. tmp = tr32(SERDES_RX_CTRL);
  5711. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  5712. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  5713. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  5714. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  5715. }
  5716. err = tg3_setup_phy(tp, 0);
  5717. if (err)
  5718. return err;
  5719. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5720. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  5721. u32 tmp;
  5722. /* Clear CRC stats. */
  5723. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  5724. tg3_writephy(tp, MII_TG3_TEST1,
  5725. tmp | MII_TG3_TEST1_CRC_EN);
  5726. tg3_readphy(tp, 0x14, &tmp);
  5727. }
  5728. }
  5729. __tg3_set_rx_mode(tp->dev);
  5730. /* Initialize receive rules. */
  5731. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  5732. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5733. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  5734. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  5735. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5736. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  5737. limit = 8;
  5738. else
  5739. limit = 16;
  5740. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  5741. limit -= 4;
  5742. switch (limit) {
  5743. case 16:
  5744. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  5745. case 15:
  5746. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  5747. case 14:
  5748. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  5749. case 13:
  5750. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  5751. case 12:
  5752. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  5753. case 11:
  5754. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  5755. case 10:
  5756. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  5757. case 9:
  5758. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  5759. case 8:
  5760. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  5761. case 7:
  5762. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  5763. case 6:
  5764. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  5765. case 5:
  5766. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  5767. case 4:
  5768. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  5769. case 3:
  5770. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  5771. case 2:
  5772. case 1:
  5773. default:
  5774. break;
  5775. };
  5776. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  5777. return 0;
  5778. }
  5779. /* Called at device open time to get the chip ready for
  5780. * packet processing. Invoked with tp->lock held.
  5781. */
  5782. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  5783. {
  5784. int err;
  5785. /* Force the chip into D0. */
  5786. err = tg3_set_power_state(tp, PCI_D0);
  5787. if (err)
  5788. goto out;
  5789. tg3_switch_clocks(tp);
  5790. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  5791. err = tg3_reset_hw(tp, reset_phy);
  5792. out:
  5793. return err;
  5794. }
  5795. #define TG3_STAT_ADD32(PSTAT, REG) \
  5796. do { u32 __val = tr32(REG); \
  5797. (PSTAT)->low += __val; \
  5798. if ((PSTAT)->low < __val) \
  5799. (PSTAT)->high += 1; \
  5800. } while (0)
  5801. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  5802. {
  5803. struct tg3_hw_stats *sp = tp->hw_stats;
  5804. if (!netif_carrier_ok(tp->dev))
  5805. return;
  5806. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  5807. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  5808. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  5809. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  5810. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  5811. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  5812. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  5813. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  5814. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  5815. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  5816. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  5817. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  5818. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  5819. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  5820. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  5821. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  5822. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  5823. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  5824. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  5825. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  5826. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  5827. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  5828. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  5829. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  5830. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  5831. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  5832. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  5833. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  5834. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  5835. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  5836. }
  5837. static void tg3_timer(unsigned long __opaque)
  5838. {
  5839. struct tg3 *tp = (struct tg3 *) __opaque;
  5840. if (tp->irq_sync)
  5841. goto restart_timer;
  5842. spin_lock(&tp->lock);
  5843. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  5844. /* All of this garbage is because when using non-tagged
  5845. * IRQ status the mailbox/status_block protocol the chip
  5846. * uses with the cpu is race prone.
  5847. */
  5848. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  5849. tw32(GRC_LOCAL_CTRL,
  5850. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  5851. } else {
  5852. tw32(HOSTCC_MODE, tp->coalesce_mode |
  5853. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  5854. }
  5855. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  5856. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  5857. spin_unlock(&tp->lock);
  5858. schedule_work(&tp->reset_task);
  5859. return;
  5860. }
  5861. }
  5862. /* This part only runs once per second. */
  5863. if (!--tp->timer_counter) {
  5864. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  5865. tg3_periodic_fetch_stats(tp);
  5866. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  5867. u32 mac_stat;
  5868. int phy_event;
  5869. mac_stat = tr32(MAC_STATUS);
  5870. phy_event = 0;
  5871. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  5872. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  5873. phy_event = 1;
  5874. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  5875. phy_event = 1;
  5876. if (phy_event)
  5877. tg3_setup_phy(tp, 0);
  5878. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  5879. u32 mac_stat = tr32(MAC_STATUS);
  5880. int need_setup = 0;
  5881. if (netif_carrier_ok(tp->dev) &&
  5882. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  5883. need_setup = 1;
  5884. }
  5885. if (! netif_carrier_ok(tp->dev) &&
  5886. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  5887. MAC_STATUS_SIGNAL_DET))) {
  5888. need_setup = 1;
  5889. }
  5890. if (need_setup) {
  5891. if (!tp->serdes_counter) {
  5892. tw32_f(MAC_MODE,
  5893. (tp->mac_mode &
  5894. ~MAC_MODE_PORT_MODE_MASK));
  5895. udelay(40);
  5896. tw32_f(MAC_MODE, tp->mac_mode);
  5897. udelay(40);
  5898. }
  5899. tg3_setup_phy(tp, 0);
  5900. }
  5901. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  5902. tg3_serdes_parallel_detect(tp);
  5903. tp->timer_counter = tp->timer_multiplier;
  5904. }
  5905. /* Heartbeat is only sent once every 2 seconds.
  5906. *
  5907. * The heartbeat is to tell the ASF firmware that the host
  5908. * driver is still alive. In the event that the OS crashes,
  5909. * ASF needs to reset the hardware to free up the FIFO space
  5910. * that may be filled with rx packets destined for the host.
  5911. * If the FIFO is full, ASF will no longer function properly.
  5912. *
  5913. * Unintended resets have been reported on real time kernels
  5914. * where the timer doesn't run on time. Netpoll will also have
  5915. * same problem.
  5916. *
  5917. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  5918. * to check the ring condition when the heartbeat is expiring
  5919. * before doing the reset. This will prevent most unintended
  5920. * resets.
  5921. */
  5922. if (!--tp->asf_counter) {
  5923. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5924. u32 val;
  5925. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  5926. FWCMD_NICDRV_ALIVE3);
  5927. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  5928. /* 5 seconds timeout */
  5929. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  5930. val = tr32(GRC_RX_CPU_EVENT);
  5931. val |= (1 << 14);
  5932. tw32(GRC_RX_CPU_EVENT, val);
  5933. }
  5934. tp->asf_counter = tp->asf_multiplier;
  5935. }
  5936. spin_unlock(&tp->lock);
  5937. restart_timer:
  5938. tp->timer.expires = jiffies + tp->timer_offset;
  5939. add_timer(&tp->timer);
  5940. }
  5941. static int tg3_request_irq(struct tg3 *tp)
  5942. {
  5943. irq_handler_t fn;
  5944. unsigned long flags;
  5945. struct net_device *dev = tp->dev;
  5946. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  5947. fn = tg3_msi;
  5948. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  5949. fn = tg3_msi_1shot;
  5950. flags = IRQF_SAMPLE_RANDOM;
  5951. } else {
  5952. fn = tg3_interrupt;
  5953. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  5954. fn = tg3_interrupt_tagged;
  5955. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  5956. }
  5957. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  5958. }
  5959. static int tg3_test_interrupt(struct tg3 *tp)
  5960. {
  5961. struct net_device *dev = tp->dev;
  5962. int err, i, intr_ok = 0;
  5963. if (!netif_running(dev))
  5964. return -ENODEV;
  5965. tg3_disable_ints(tp);
  5966. free_irq(tp->pdev->irq, dev);
  5967. err = request_irq(tp->pdev->irq, tg3_test_isr,
  5968. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  5969. if (err)
  5970. return err;
  5971. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  5972. tg3_enable_ints(tp);
  5973. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  5974. HOSTCC_MODE_NOW);
  5975. for (i = 0; i < 5; i++) {
  5976. u32 int_mbox, misc_host_ctrl;
  5977. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  5978. TG3_64BIT_REG_LOW);
  5979. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  5980. if ((int_mbox != 0) ||
  5981. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  5982. intr_ok = 1;
  5983. break;
  5984. }
  5985. msleep(10);
  5986. }
  5987. tg3_disable_ints(tp);
  5988. free_irq(tp->pdev->irq, dev);
  5989. err = tg3_request_irq(tp);
  5990. if (err)
  5991. return err;
  5992. if (intr_ok)
  5993. return 0;
  5994. return -EIO;
  5995. }
  5996. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  5997. * successfully restored
  5998. */
  5999. static int tg3_test_msi(struct tg3 *tp)
  6000. {
  6001. struct net_device *dev = tp->dev;
  6002. int err;
  6003. u16 pci_cmd;
  6004. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  6005. return 0;
  6006. /* Turn off SERR reporting in case MSI terminates with Master
  6007. * Abort.
  6008. */
  6009. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  6010. pci_write_config_word(tp->pdev, PCI_COMMAND,
  6011. pci_cmd & ~PCI_COMMAND_SERR);
  6012. err = tg3_test_interrupt(tp);
  6013. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  6014. if (!err)
  6015. return 0;
  6016. /* other failures */
  6017. if (err != -EIO)
  6018. return err;
  6019. /* MSI test failed, go back to INTx mode */
  6020. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  6021. "switching to INTx mode. Please report this failure to "
  6022. "the PCI maintainer and include system chipset information.\n",
  6023. tp->dev->name);
  6024. free_irq(tp->pdev->irq, dev);
  6025. pci_disable_msi(tp->pdev);
  6026. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6027. err = tg3_request_irq(tp);
  6028. if (err)
  6029. return err;
  6030. /* Need to reset the chip because the MSI cycle may have terminated
  6031. * with Master Abort.
  6032. */
  6033. tg3_full_lock(tp, 1);
  6034. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6035. err = tg3_init_hw(tp, 1);
  6036. tg3_full_unlock(tp);
  6037. if (err)
  6038. free_irq(tp->pdev->irq, dev);
  6039. return err;
  6040. }
  6041. static int tg3_open(struct net_device *dev)
  6042. {
  6043. struct tg3 *tp = netdev_priv(dev);
  6044. int err;
  6045. netif_carrier_off(tp->dev);
  6046. tg3_full_lock(tp, 0);
  6047. err = tg3_set_power_state(tp, PCI_D0);
  6048. if (err) {
  6049. tg3_full_unlock(tp);
  6050. return err;
  6051. }
  6052. tg3_disable_ints(tp);
  6053. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6054. tg3_full_unlock(tp);
  6055. /* The placement of this call is tied
  6056. * to the setup and use of Host TX descriptors.
  6057. */
  6058. err = tg3_alloc_consistent(tp);
  6059. if (err)
  6060. return err;
  6061. if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) {
  6062. /* All MSI supporting chips should support tagged
  6063. * status. Assert that this is the case.
  6064. */
  6065. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6066. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6067. "Not using MSI.\n", tp->dev->name);
  6068. } else if (pci_enable_msi(tp->pdev) == 0) {
  6069. u32 msi_mode;
  6070. msi_mode = tr32(MSGINT_MODE);
  6071. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6072. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6073. }
  6074. }
  6075. err = tg3_request_irq(tp);
  6076. if (err) {
  6077. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6078. pci_disable_msi(tp->pdev);
  6079. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6080. }
  6081. tg3_free_consistent(tp);
  6082. return err;
  6083. }
  6084. tg3_full_lock(tp, 0);
  6085. err = tg3_init_hw(tp, 1);
  6086. if (err) {
  6087. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6088. tg3_free_rings(tp);
  6089. } else {
  6090. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6091. tp->timer_offset = HZ;
  6092. else
  6093. tp->timer_offset = HZ / 10;
  6094. BUG_ON(tp->timer_offset > HZ);
  6095. tp->timer_counter = tp->timer_multiplier =
  6096. (HZ / tp->timer_offset);
  6097. tp->asf_counter = tp->asf_multiplier =
  6098. ((HZ / tp->timer_offset) * 2);
  6099. init_timer(&tp->timer);
  6100. tp->timer.expires = jiffies + tp->timer_offset;
  6101. tp->timer.data = (unsigned long) tp;
  6102. tp->timer.function = tg3_timer;
  6103. }
  6104. tg3_full_unlock(tp);
  6105. if (err) {
  6106. free_irq(tp->pdev->irq, dev);
  6107. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6108. pci_disable_msi(tp->pdev);
  6109. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6110. }
  6111. tg3_free_consistent(tp);
  6112. return err;
  6113. }
  6114. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6115. err = tg3_test_msi(tp);
  6116. if (err) {
  6117. tg3_full_lock(tp, 0);
  6118. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6119. pci_disable_msi(tp->pdev);
  6120. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6121. }
  6122. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6123. tg3_free_rings(tp);
  6124. tg3_free_consistent(tp);
  6125. tg3_full_unlock(tp);
  6126. return err;
  6127. }
  6128. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6129. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6130. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6131. tw32(PCIE_TRANSACTION_CFG,
  6132. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6133. }
  6134. }
  6135. }
  6136. tg3_full_lock(tp, 0);
  6137. add_timer(&tp->timer);
  6138. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6139. tg3_enable_ints(tp);
  6140. tg3_full_unlock(tp);
  6141. netif_start_queue(dev);
  6142. return 0;
  6143. }
  6144. #if 0
  6145. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6146. {
  6147. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6148. u16 val16;
  6149. int i;
  6150. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6151. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6152. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6153. val16, val32);
  6154. /* MAC block */
  6155. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6156. tr32(MAC_MODE), tr32(MAC_STATUS));
  6157. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6158. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6159. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6160. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6161. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6162. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6163. /* Send data initiator control block */
  6164. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6165. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6166. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6167. tr32(SNDDATAI_STATSCTRL));
  6168. /* Send data completion control block */
  6169. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6170. /* Send BD ring selector block */
  6171. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6172. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6173. /* Send BD initiator control block */
  6174. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6175. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6176. /* Send BD completion control block */
  6177. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6178. /* Receive list placement control block */
  6179. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6180. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6181. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6182. tr32(RCVLPC_STATSCTRL));
  6183. /* Receive data and receive BD initiator control block */
  6184. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6185. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6186. /* Receive data completion control block */
  6187. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6188. tr32(RCVDCC_MODE));
  6189. /* Receive BD initiator control block */
  6190. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6191. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6192. /* Receive BD completion control block */
  6193. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6194. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6195. /* Receive list selector control block */
  6196. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6197. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6198. /* Mbuf cluster free block */
  6199. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6200. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6201. /* Host coalescing control block */
  6202. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6203. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6204. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6205. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6206. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6207. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6208. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6209. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6210. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6211. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6212. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6213. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6214. /* Memory arbiter control block */
  6215. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6216. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6217. /* Buffer manager control block */
  6218. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6219. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6220. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6221. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6222. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6223. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6224. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6225. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6226. /* Read DMA control block */
  6227. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6228. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6229. /* Write DMA control block */
  6230. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6231. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6232. /* DMA completion block */
  6233. printk("DEBUG: DMAC_MODE[%08x]\n",
  6234. tr32(DMAC_MODE));
  6235. /* GRC block */
  6236. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6237. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6238. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6239. tr32(GRC_LOCAL_CTRL));
  6240. /* TG3_BDINFOs */
  6241. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6242. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6243. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6244. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6245. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6246. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6247. tr32(RCVDBDI_STD_BD + 0x0),
  6248. tr32(RCVDBDI_STD_BD + 0x4),
  6249. tr32(RCVDBDI_STD_BD + 0x8),
  6250. tr32(RCVDBDI_STD_BD + 0xc));
  6251. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6252. tr32(RCVDBDI_MINI_BD + 0x0),
  6253. tr32(RCVDBDI_MINI_BD + 0x4),
  6254. tr32(RCVDBDI_MINI_BD + 0x8),
  6255. tr32(RCVDBDI_MINI_BD + 0xc));
  6256. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6257. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6258. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6259. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6260. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6261. val32, val32_2, val32_3, val32_4);
  6262. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6263. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6264. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6265. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6266. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6267. val32, val32_2, val32_3, val32_4);
  6268. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6269. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6270. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6271. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6272. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6273. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6274. val32, val32_2, val32_3, val32_4, val32_5);
  6275. /* SW status block */
  6276. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6277. tp->hw_status->status,
  6278. tp->hw_status->status_tag,
  6279. tp->hw_status->rx_jumbo_consumer,
  6280. tp->hw_status->rx_consumer,
  6281. tp->hw_status->rx_mini_consumer,
  6282. tp->hw_status->idx[0].rx_producer,
  6283. tp->hw_status->idx[0].tx_consumer);
  6284. /* SW statistics block */
  6285. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6286. ((u32 *)tp->hw_stats)[0],
  6287. ((u32 *)tp->hw_stats)[1],
  6288. ((u32 *)tp->hw_stats)[2],
  6289. ((u32 *)tp->hw_stats)[3]);
  6290. /* Mailboxes */
  6291. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6292. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6293. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6294. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6295. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6296. /* NIC side send descriptors. */
  6297. for (i = 0; i < 6; i++) {
  6298. unsigned long txd;
  6299. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6300. + (i * sizeof(struct tg3_tx_buffer_desc));
  6301. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6302. i,
  6303. readl(txd + 0x0), readl(txd + 0x4),
  6304. readl(txd + 0x8), readl(txd + 0xc));
  6305. }
  6306. /* NIC side RX descriptors. */
  6307. for (i = 0; i < 6; i++) {
  6308. unsigned long rxd;
  6309. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6310. + (i * sizeof(struct tg3_rx_buffer_desc));
  6311. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6312. i,
  6313. readl(rxd + 0x0), readl(rxd + 0x4),
  6314. readl(rxd + 0x8), readl(rxd + 0xc));
  6315. rxd += (4 * sizeof(u32));
  6316. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6317. i,
  6318. readl(rxd + 0x0), readl(rxd + 0x4),
  6319. readl(rxd + 0x8), readl(rxd + 0xc));
  6320. }
  6321. for (i = 0; i < 6; i++) {
  6322. unsigned long rxd;
  6323. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6324. + (i * sizeof(struct tg3_rx_buffer_desc));
  6325. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6326. i,
  6327. readl(rxd + 0x0), readl(rxd + 0x4),
  6328. readl(rxd + 0x8), readl(rxd + 0xc));
  6329. rxd += (4 * sizeof(u32));
  6330. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6331. i,
  6332. readl(rxd + 0x0), readl(rxd + 0x4),
  6333. readl(rxd + 0x8), readl(rxd + 0xc));
  6334. }
  6335. }
  6336. #endif
  6337. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6338. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6339. static int tg3_close(struct net_device *dev)
  6340. {
  6341. struct tg3 *tp = netdev_priv(dev);
  6342. cancel_work_sync(&tp->reset_task);
  6343. netif_stop_queue(dev);
  6344. del_timer_sync(&tp->timer);
  6345. tg3_full_lock(tp, 1);
  6346. #if 0
  6347. tg3_dump_state(tp);
  6348. #endif
  6349. tg3_disable_ints(tp);
  6350. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6351. tg3_free_rings(tp);
  6352. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6353. tg3_full_unlock(tp);
  6354. free_irq(tp->pdev->irq, dev);
  6355. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6356. pci_disable_msi(tp->pdev);
  6357. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6358. }
  6359. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6360. sizeof(tp->net_stats_prev));
  6361. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6362. sizeof(tp->estats_prev));
  6363. tg3_free_consistent(tp);
  6364. tg3_set_power_state(tp, PCI_D3hot);
  6365. netif_carrier_off(tp->dev);
  6366. return 0;
  6367. }
  6368. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6369. {
  6370. unsigned long ret;
  6371. #if (BITS_PER_LONG == 32)
  6372. ret = val->low;
  6373. #else
  6374. ret = ((u64)val->high << 32) | ((u64)val->low);
  6375. #endif
  6376. return ret;
  6377. }
  6378. static unsigned long calc_crc_errors(struct tg3 *tp)
  6379. {
  6380. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6381. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6382. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6383. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6384. u32 val;
  6385. spin_lock_bh(&tp->lock);
  6386. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6387. tg3_writephy(tp, MII_TG3_TEST1,
  6388. val | MII_TG3_TEST1_CRC_EN);
  6389. tg3_readphy(tp, 0x14, &val);
  6390. } else
  6391. val = 0;
  6392. spin_unlock_bh(&tp->lock);
  6393. tp->phy_crc_errors += val;
  6394. return tp->phy_crc_errors;
  6395. }
  6396. return get_stat64(&hw_stats->rx_fcs_errors);
  6397. }
  6398. #define ESTAT_ADD(member) \
  6399. estats->member = old_estats->member + \
  6400. get_stat64(&hw_stats->member)
  6401. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6402. {
  6403. struct tg3_ethtool_stats *estats = &tp->estats;
  6404. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6405. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6406. if (!hw_stats)
  6407. return old_estats;
  6408. ESTAT_ADD(rx_octets);
  6409. ESTAT_ADD(rx_fragments);
  6410. ESTAT_ADD(rx_ucast_packets);
  6411. ESTAT_ADD(rx_mcast_packets);
  6412. ESTAT_ADD(rx_bcast_packets);
  6413. ESTAT_ADD(rx_fcs_errors);
  6414. ESTAT_ADD(rx_align_errors);
  6415. ESTAT_ADD(rx_xon_pause_rcvd);
  6416. ESTAT_ADD(rx_xoff_pause_rcvd);
  6417. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6418. ESTAT_ADD(rx_xoff_entered);
  6419. ESTAT_ADD(rx_frame_too_long_errors);
  6420. ESTAT_ADD(rx_jabbers);
  6421. ESTAT_ADD(rx_undersize_packets);
  6422. ESTAT_ADD(rx_in_length_errors);
  6423. ESTAT_ADD(rx_out_length_errors);
  6424. ESTAT_ADD(rx_64_or_less_octet_packets);
  6425. ESTAT_ADD(rx_65_to_127_octet_packets);
  6426. ESTAT_ADD(rx_128_to_255_octet_packets);
  6427. ESTAT_ADD(rx_256_to_511_octet_packets);
  6428. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6429. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6430. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6431. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6432. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6433. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6434. ESTAT_ADD(tx_octets);
  6435. ESTAT_ADD(tx_collisions);
  6436. ESTAT_ADD(tx_xon_sent);
  6437. ESTAT_ADD(tx_xoff_sent);
  6438. ESTAT_ADD(tx_flow_control);
  6439. ESTAT_ADD(tx_mac_errors);
  6440. ESTAT_ADD(tx_single_collisions);
  6441. ESTAT_ADD(tx_mult_collisions);
  6442. ESTAT_ADD(tx_deferred);
  6443. ESTAT_ADD(tx_excessive_collisions);
  6444. ESTAT_ADD(tx_late_collisions);
  6445. ESTAT_ADD(tx_collide_2times);
  6446. ESTAT_ADD(tx_collide_3times);
  6447. ESTAT_ADD(tx_collide_4times);
  6448. ESTAT_ADD(tx_collide_5times);
  6449. ESTAT_ADD(tx_collide_6times);
  6450. ESTAT_ADD(tx_collide_7times);
  6451. ESTAT_ADD(tx_collide_8times);
  6452. ESTAT_ADD(tx_collide_9times);
  6453. ESTAT_ADD(tx_collide_10times);
  6454. ESTAT_ADD(tx_collide_11times);
  6455. ESTAT_ADD(tx_collide_12times);
  6456. ESTAT_ADD(tx_collide_13times);
  6457. ESTAT_ADD(tx_collide_14times);
  6458. ESTAT_ADD(tx_collide_15times);
  6459. ESTAT_ADD(tx_ucast_packets);
  6460. ESTAT_ADD(tx_mcast_packets);
  6461. ESTAT_ADD(tx_bcast_packets);
  6462. ESTAT_ADD(tx_carrier_sense_errors);
  6463. ESTAT_ADD(tx_discards);
  6464. ESTAT_ADD(tx_errors);
  6465. ESTAT_ADD(dma_writeq_full);
  6466. ESTAT_ADD(dma_write_prioq_full);
  6467. ESTAT_ADD(rxbds_empty);
  6468. ESTAT_ADD(rx_discards);
  6469. ESTAT_ADD(rx_errors);
  6470. ESTAT_ADD(rx_threshold_hit);
  6471. ESTAT_ADD(dma_readq_full);
  6472. ESTAT_ADD(dma_read_prioq_full);
  6473. ESTAT_ADD(tx_comp_queue_full);
  6474. ESTAT_ADD(ring_set_send_prod_index);
  6475. ESTAT_ADD(ring_status_update);
  6476. ESTAT_ADD(nic_irqs);
  6477. ESTAT_ADD(nic_avoided_irqs);
  6478. ESTAT_ADD(nic_tx_threshold_hit);
  6479. return estats;
  6480. }
  6481. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6482. {
  6483. struct tg3 *tp = netdev_priv(dev);
  6484. struct net_device_stats *stats = &tp->net_stats;
  6485. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6486. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6487. if (!hw_stats)
  6488. return old_stats;
  6489. stats->rx_packets = old_stats->rx_packets +
  6490. get_stat64(&hw_stats->rx_ucast_packets) +
  6491. get_stat64(&hw_stats->rx_mcast_packets) +
  6492. get_stat64(&hw_stats->rx_bcast_packets);
  6493. stats->tx_packets = old_stats->tx_packets +
  6494. get_stat64(&hw_stats->tx_ucast_packets) +
  6495. get_stat64(&hw_stats->tx_mcast_packets) +
  6496. get_stat64(&hw_stats->tx_bcast_packets);
  6497. stats->rx_bytes = old_stats->rx_bytes +
  6498. get_stat64(&hw_stats->rx_octets);
  6499. stats->tx_bytes = old_stats->tx_bytes +
  6500. get_stat64(&hw_stats->tx_octets);
  6501. stats->rx_errors = old_stats->rx_errors +
  6502. get_stat64(&hw_stats->rx_errors);
  6503. stats->tx_errors = old_stats->tx_errors +
  6504. get_stat64(&hw_stats->tx_errors) +
  6505. get_stat64(&hw_stats->tx_mac_errors) +
  6506. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6507. get_stat64(&hw_stats->tx_discards);
  6508. stats->multicast = old_stats->multicast +
  6509. get_stat64(&hw_stats->rx_mcast_packets);
  6510. stats->collisions = old_stats->collisions +
  6511. get_stat64(&hw_stats->tx_collisions);
  6512. stats->rx_length_errors = old_stats->rx_length_errors +
  6513. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6514. get_stat64(&hw_stats->rx_undersize_packets);
  6515. stats->rx_over_errors = old_stats->rx_over_errors +
  6516. get_stat64(&hw_stats->rxbds_empty);
  6517. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6518. get_stat64(&hw_stats->rx_align_errors);
  6519. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6520. get_stat64(&hw_stats->tx_discards);
  6521. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6522. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6523. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6524. calc_crc_errors(tp);
  6525. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6526. get_stat64(&hw_stats->rx_discards);
  6527. return stats;
  6528. }
  6529. static inline u32 calc_crc(unsigned char *buf, int len)
  6530. {
  6531. u32 reg;
  6532. u32 tmp;
  6533. int j, k;
  6534. reg = 0xffffffff;
  6535. for (j = 0; j < len; j++) {
  6536. reg ^= buf[j];
  6537. for (k = 0; k < 8; k++) {
  6538. tmp = reg & 0x01;
  6539. reg >>= 1;
  6540. if (tmp) {
  6541. reg ^= 0xedb88320;
  6542. }
  6543. }
  6544. }
  6545. return ~reg;
  6546. }
  6547. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6548. {
  6549. /* accept or reject all multicast frames */
  6550. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6551. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6552. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6553. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6554. }
  6555. static void __tg3_set_rx_mode(struct net_device *dev)
  6556. {
  6557. struct tg3 *tp = netdev_priv(dev);
  6558. u32 rx_mode;
  6559. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6560. RX_MODE_KEEP_VLAN_TAG);
  6561. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  6562. * flag clear.
  6563. */
  6564. #if TG3_VLAN_TAG_USED
  6565. if (!tp->vlgrp &&
  6566. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6567. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6568. #else
  6569. /* By definition, VLAN is disabled always in this
  6570. * case.
  6571. */
  6572. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  6573. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  6574. #endif
  6575. if (dev->flags & IFF_PROMISC) {
  6576. /* Promiscuous mode. */
  6577. rx_mode |= RX_MODE_PROMISC;
  6578. } else if (dev->flags & IFF_ALLMULTI) {
  6579. /* Accept all multicast. */
  6580. tg3_set_multi (tp, 1);
  6581. } else if (dev->mc_count < 1) {
  6582. /* Reject all multicast. */
  6583. tg3_set_multi (tp, 0);
  6584. } else {
  6585. /* Accept one or more multicast(s). */
  6586. struct dev_mc_list *mclist;
  6587. unsigned int i;
  6588. u32 mc_filter[4] = { 0, };
  6589. u32 regidx;
  6590. u32 bit;
  6591. u32 crc;
  6592. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  6593. i++, mclist = mclist->next) {
  6594. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  6595. bit = ~crc & 0x7f;
  6596. regidx = (bit & 0x60) >> 5;
  6597. bit &= 0x1f;
  6598. mc_filter[regidx] |= (1 << bit);
  6599. }
  6600. tw32(MAC_HASH_REG_0, mc_filter[0]);
  6601. tw32(MAC_HASH_REG_1, mc_filter[1]);
  6602. tw32(MAC_HASH_REG_2, mc_filter[2]);
  6603. tw32(MAC_HASH_REG_3, mc_filter[3]);
  6604. }
  6605. if (rx_mode != tp->rx_mode) {
  6606. tp->rx_mode = rx_mode;
  6607. tw32_f(MAC_RX_MODE, rx_mode);
  6608. udelay(10);
  6609. }
  6610. }
  6611. static void tg3_set_rx_mode(struct net_device *dev)
  6612. {
  6613. struct tg3 *tp = netdev_priv(dev);
  6614. if (!netif_running(dev))
  6615. return;
  6616. tg3_full_lock(tp, 0);
  6617. __tg3_set_rx_mode(dev);
  6618. tg3_full_unlock(tp);
  6619. }
  6620. #define TG3_REGDUMP_LEN (32 * 1024)
  6621. static int tg3_get_regs_len(struct net_device *dev)
  6622. {
  6623. return TG3_REGDUMP_LEN;
  6624. }
  6625. static void tg3_get_regs(struct net_device *dev,
  6626. struct ethtool_regs *regs, void *_p)
  6627. {
  6628. u32 *p = _p;
  6629. struct tg3 *tp = netdev_priv(dev);
  6630. u8 *orig_p = _p;
  6631. int i;
  6632. regs->version = 0;
  6633. memset(p, 0, TG3_REGDUMP_LEN);
  6634. if (tp->link_config.phy_is_low_power)
  6635. return;
  6636. tg3_full_lock(tp, 0);
  6637. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  6638. #define GET_REG32_LOOP(base,len) \
  6639. do { p = (u32 *)(orig_p + (base)); \
  6640. for (i = 0; i < len; i += 4) \
  6641. __GET_REG32((base) + i); \
  6642. } while (0)
  6643. #define GET_REG32_1(reg) \
  6644. do { p = (u32 *)(orig_p + (reg)); \
  6645. __GET_REG32((reg)); \
  6646. } while (0)
  6647. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  6648. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  6649. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  6650. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  6651. GET_REG32_1(SNDDATAC_MODE);
  6652. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  6653. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  6654. GET_REG32_1(SNDBDC_MODE);
  6655. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  6656. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  6657. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  6658. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  6659. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  6660. GET_REG32_1(RCVDCC_MODE);
  6661. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  6662. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  6663. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  6664. GET_REG32_1(MBFREE_MODE);
  6665. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  6666. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  6667. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  6668. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  6669. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  6670. GET_REG32_1(RX_CPU_MODE);
  6671. GET_REG32_1(RX_CPU_STATE);
  6672. GET_REG32_1(RX_CPU_PGMCTR);
  6673. GET_REG32_1(RX_CPU_HWBKPT);
  6674. GET_REG32_1(TX_CPU_MODE);
  6675. GET_REG32_1(TX_CPU_STATE);
  6676. GET_REG32_1(TX_CPU_PGMCTR);
  6677. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  6678. GET_REG32_LOOP(FTQ_RESET, 0x120);
  6679. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  6680. GET_REG32_1(DMAC_MODE);
  6681. GET_REG32_LOOP(GRC_MODE, 0x4c);
  6682. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  6683. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  6684. #undef __GET_REG32
  6685. #undef GET_REG32_LOOP
  6686. #undef GET_REG32_1
  6687. tg3_full_unlock(tp);
  6688. }
  6689. static int tg3_get_eeprom_len(struct net_device *dev)
  6690. {
  6691. struct tg3 *tp = netdev_priv(dev);
  6692. return tp->nvram_size;
  6693. }
  6694. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  6695. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  6696. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6697. {
  6698. struct tg3 *tp = netdev_priv(dev);
  6699. int ret;
  6700. u8 *pd;
  6701. u32 i, offset, len, val, b_offset, b_count;
  6702. if (tp->link_config.phy_is_low_power)
  6703. return -EAGAIN;
  6704. offset = eeprom->offset;
  6705. len = eeprom->len;
  6706. eeprom->len = 0;
  6707. eeprom->magic = TG3_EEPROM_MAGIC;
  6708. if (offset & 3) {
  6709. /* adjustments to start on required 4 byte boundary */
  6710. b_offset = offset & 3;
  6711. b_count = 4 - b_offset;
  6712. if (b_count > len) {
  6713. /* i.e. offset=1 len=2 */
  6714. b_count = len;
  6715. }
  6716. ret = tg3_nvram_read(tp, offset-b_offset, &val);
  6717. if (ret)
  6718. return ret;
  6719. val = cpu_to_le32(val);
  6720. memcpy(data, ((char*)&val) + b_offset, b_count);
  6721. len -= b_count;
  6722. offset += b_count;
  6723. eeprom->len += b_count;
  6724. }
  6725. /* read bytes upto the last 4 byte boundary */
  6726. pd = &data[eeprom->len];
  6727. for (i = 0; i < (len - (len & 3)); i += 4) {
  6728. ret = tg3_nvram_read(tp, offset + i, &val);
  6729. if (ret) {
  6730. eeprom->len += i;
  6731. return ret;
  6732. }
  6733. val = cpu_to_le32(val);
  6734. memcpy(pd + i, &val, 4);
  6735. }
  6736. eeprom->len += i;
  6737. if (len & 3) {
  6738. /* read last bytes not ending on 4 byte boundary */
  6739. pd = &data[eeprom->len];
  6740. b_count = len & 3;
  6741. b_offset = offset + len - b_count;
  6742. ret = tg3_nvram_read(tp, b_offset, &val);
  6743. if (ret)
  6744. return ret;
  6745. val = cpu_to_le32(val);
  6746. memcpy(pd, ((char*)&val), b_count);
  6747. eeprom->len += b_count;
  6748. }
  6749. return 0;
  6750. }
  6751. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  6752. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  6753. {
  6754. struct tg3 *tp = netdev_priv(dev);
  6755. int ret;
  6756. u32 offset, len, b_offset, odd_len, start, end;
  6757. u8 *buf;
  6758. if (tp->link_config.phy_is_low_power)
  6759. return -EAGAIN;
  6760. if (eeprom->magic != TG3_EEPROM_MAGIC)
  6761. return -EINVAL;
  6762. offset = eeprom->offset;
  6763. len = eeprom->len;
  6764. if ((b_offset = (offset & 3))) {
  6765. /* adjustments to start on required 4 byte boundary */
  6766. ret = tg3_nvram_read(tp, offset-b_offset, &start);
  6767. if (ret)
  6768. return ret;
  6769. start = cpu_to_le32(start);
  6770. len += b_offset;
  6771. offset &= ~3;
  6772. if (len < 4)
  6773. len = 4;
  6774. }
  6775. odd_len = 0;
  6776. if (len & 3) {
  6777. /* adjustments to end on required 4 byte boundary */
  6778. odd_len = 1;
  6779. len = (len + 3) & ~3;
  6780. ret = tg3_nvram_read(tp, offset+len-4, &end);
  6781. if (ret)
  6782. return ret;
  6783. end = cpu_to_le32(end);
  6784. }
  6785. buf = data;
  6786. if (b_offset || odd_len) {
  6787. buf = kmalloc(len, GFP_KERNEL);
  6788. if (buf == 0)
  6789. return -ENOMEM;
  6790. if (b_offset)
  6791. memcpy(buf, &start, 4);
  6792. if (odd_len)
  6793. memcpy(buf+len-4, &end, 4);
  6794. memcpy(buf + b_offset, data, eeprom->len);
  6795. }
  6796. ret = tg3_nvram_write_block(tp, offset, len, buf);
  6797. if (buf != data)
  6798. kfree(buf);
  6799. return ret;
  6800. }
  6801. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6802. {
  6803. struct tg3 *tp = netdev_priv(dev);
  6804. cmd->supported = (SUPPORTED_Autoneg);
  6805. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  6806. cmd->supported |= (SUPPORTED_1000baseT_Half |
  6807. SUPPORTED_1000baseT_Full);
  6808. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  6809. cmd->supported |= (SUPPORTED_100baseT_Half |
  6810. SUPPORTED_100baseT_Full |
  6811. SUPPORTED_10baseT_Half |
  6812. SUPPORTED_10baseT_Full |
  6813. SUPPORTED_MII);
  6814. cmd->port = PORT_TP;
  6815. } else {
  6816. cmd->supported |= SUPPORTED_FIBRE;
  6817. cmd->port = PORT_FIBRE;
  6818. }
  6819. cmd->advertising = tp->link_config.advertising;
  6820. if (netif_running(dev)) {
  6821. cmd->speed = tp->link_config.active_speed;
  6822. cmd->duplex = tp->link_config.active_duplex;
  6823. }
  6824. cmd->phy_address = PHY_ADDR;
  6825. cmd->transceiver = 0;
  6826. cmd->autoneg = tp->link_config.autoneg;
  6827. cmd->maxtxpkt = 0;
  6828. cmd->maxrxpkt = 0;
  6829. return 0;
  6830. }
  6831. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6832. {
  6833. struct tg3 *tp = netdev_priv(dev);
  6834. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  6835. /* These are the only valid advertisement bits allowed. */
  6836. if (cmd->autoneg == AUTONEG_ENABLE &&
  6837. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  6838. ADVERTISED_1000baseT_Full |
  6839. ADVERTISED_Autoneg |
  6840. ADVERTISED_FIBRE)))
  6841. return -EINVAL;
  6842. /* Fiber can only do SPEED_1000. */
  6843. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6844. (cmd->speed != SPEED_1000))
  6845. return -EINVAL;
  6846. /* Copper cannot force SPEED_1000. */
  6847. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  6848. (cmd->speed == SPEED_1000))
  6849. return -EINVAL;
  6850. else if ((cmd->speed == SPEED_1000) &&
  6851. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  6852. return -EINVAL;
  6853. tg3_full_lock(tp, 0);
  6854. tp->link_config.autoneg = cmd->autoneg;
  6855. if (cmd->autoneg == AUTONEG_ENABLE) {
  6856. tp->link_config.advertising = cmd->advertising;
  6857. tp->link_config.speed = SPEED_INVALID;
  6858. tp->link_config.duplex = DUPLEX_INVALID;
  6859. } else {
  6860. tp->link_config.advertising = 0;
  6861. tp->link_config.speed = cmd->speed;
  6862. tp->link_config.duplex = cmd->duplex;
  6863. }
  6864. tp->link_config.orig_speed = tp->link_config.speed;
  6865. tp->link_config.orig_duplex = tp->link_config.duplex;
  6866. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  6867. if (netif_running(dev))
  6868. tg3_setup_phy(tp, 1);
  6869. tg3_full_unlock(tp);
  6870. return 0;
  6871. }
  6872. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  6873. {
  6874. struct tg3 *tp = netdev_priv(dev);
  6875. strcpy(info->driver, DRV_MODULE_NAME);
  6876. strcpy(info->version, DRV_MODULE_VERSION);
  6877. strcpy(info->fw_version, tp->fw_ver);
  6878. strcpy(info->bus_info, pci_name(tp->pdev));
  6879. }
  6880. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6881. {
  6882. struct tg3 *tp = netdev_priv(dev);
  6883. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  6884. wol->supported = WAKE_MAGIC;
  6885. else
  6886. wol->supported = 0;
  6887. wol->wolopts = 0;
  6888. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  6889. wol->wolopts = WAKE_MAGIC;
  6890. memset(&wol->sopass, 0, sizeof(wol->sopass));
  6891. }
  6892. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  6893. {
  6894. struct tg3 *tp = netdev_priv(dev);
  6895. if (wol->wolopts & ~WAKE_MAGIC)
  6896. return -EINVAL;
  6897. if ((wol->wolopts & WAKE_MAGIC) &&
  6898. !(tp->tg3_flags & TG3_FLAG_WOL_CAP))
  6899. return -EINVAL;
  6900. spin_lock_bh(&tp->lock);
  6901. if (wol->wolopts & WAKE_MAGIC)
  6902. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  6903. else
  6904. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  6905. spin_unlock_bh(&tp->lock);
  6906. return 0;
  6907. }
  6908. static u32 tg3_get_msglevel(struct net_device *dev)
  6909. {
  6910. struct tg3 *tp = netdev_priv(dev);
  6911. return tp->msg_enable;
  6912. }
  6913. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  6914. {
  6915. struct tg3 *tp = netdev_priv(dev);
  6916. tp->msg_enable = value;
  6917. }
  6918. static int tg3_set_tso(struct net_device *dev, u32 value)
  6919. {
  6920. struct tg3 *tp = netdev_priv(dev);
  6921. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  6922. if (value)
  6923. return -EINVAL;
  6924. return 0;
  6925. }
  6926. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  6927. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  6928. if (value)
  6929. dev->features |= NETIF_F_TSO6;
  6930. else
  6931. dev->features &= ~NETIF_F_TSO6;
  6932. }
  6933. return ethtool_op_set_tso(dev, value);
  6934. }
  6935. static int tg3_nway_reset(struct net_device *dev)
  6936. {
  6937. struct tg3 *tp = netdev_priv(dev);
  6938. u32 bmcr;
  6939. int r;
  6940. if (!netif_running(dev))
  6941. return -EAGAIN;
  6942. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  6943. return -EINVAL;
  6944. spin_lock_bh(&tp->lock);
  6945. r = -EINVAL;
  6946. tg3_readphy(tp, MII_BMCR, &bmcr);
  6947. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  6948. ((bmcr & BMCR_ANENABLE) ||
  6949. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  6950. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  6951. BMCR_ANENABLE);
  6952. r = 0;
  6953. }
  6954. spin_unlock_bh(&tp->lock);
  6955. return r;
  6956. }
  6957. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6958. {
  6959. struct tg3 *tp = netdev_priv(dev);
  6960. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  6961. ering->rx_mini_max_pending = 0;
  6962. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6963. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  6964. else
  6965. ering->rx_jumbo_max_pending = 0;
  6966. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  6967. ering->rx_pending = tp->rx_pending;
  6968. ering->rx_mini_pending = 0;
  6969. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  6970. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  6971. else
  6972. ering->rx_jumbo_pending = 0;
  6973. ering->tx_pending = tp->tx_pending;
  6974. }
  6975. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  6976. {
  6977. struct tg3 *tp = netdev_priv(dev);
  6978. int irq_sync = 0, err = 0;
  6979. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  6980. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  6981. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  6982. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  6983. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  6984. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  6985. return -EINVAL;
  6986. if (netif_running(dev)) {
  6987. tg3_netif_stop(tp);
  6988. irq_sync = 1;
  6989. }
  6990. tg3_full_lock(tp, irq_sync);
  6991. tp->rx_pending = ering->rx_pending;
  6992. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  6993. tp->rx_pending > 63)
  6994. tp->rx_pending = 63;
  6995. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  6996. tp->tx_pending = ering->tx_pending;
  6997. if (netif_running(dev)) {
  6998. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6999. err = tg3_restart_hw(tp, 1);
  7000. if (!err)
  7001. tg3_netif_start(tp);
  7002. }
  7003. tg3_full_unlock(tp);
  7004. return err;
  7005. }
  7006. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7007. {
  7008. struct tg3 *tp = netdev_priv(dev);
  7009. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  7010. epause->rx_pause = (tp->tg3_flags & TG3_FLAG_RX_PAUSE) != 0;
  7011. epause->tx_pause = (tp->tg3_flags & TG3_FLAG_TX_PAUSE) != 0;
  7012. }
  7013. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7014. {
  7015. struct tg3 *tp = netdev_priv(dev);
  7016. int irq_sync = 0, err = 0;
  7017. if (netif_running(dev)) {
  7018. tg3_netif_stop(tp);
  7019. irq_sync = 1;
  7020. }
  7021. tg3_full_lock(tp, irq_sync);
  7022. if (epause->autoneg)
  7023. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  7024. else
  7025. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  7026. if (epause->rx_pause)
  7027. tp->tg3_flags |= TG3_FLAG_RX_PAUSE;
  7028. else
  7029. tp->tg3_flags &= ~TG3_FLAG_RX_PAUSE;
  7030. if (epause->tx_pause)
  7031. tp->tg3_flags |= TG3_FLAG_TX_PAUSE;
  7032. else
  7033. tp->tg3_flags &= ~TG3_FLAG_TX_PAUSE;
  7034. if (netif_running(dev)) {
  7035. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7036. err = tg3_restart_hw(tp, 1);
  7037. if (!err)
  7038. tg3_netif_start(tp);
  7039. }
  7040. tg3_full_unlock(tp);
  7041. return err;
  7042. }
  7043. static u32 tg3_get_rx_csum(struct net_device *dev)
  7044. {
  7045. struct tg3 *tp = netdev_priv(dev);
  7046. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  7047. }
  7048. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  7049. {
  7050. struct tg3 *tp = netdev_priv(dev);
  7051. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7052. if (data != 0)
  7053. return -EINVAL;
  7054. return 0;
  7055. }
  7056. spin_lock_bh(&tp->lock);
  7057. if (data)
  7058. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7059. else
  7060. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7061. spin_unlock_bh(&tp->lock);
  7062. return 0;
  7063. }
  7064. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7065. {
  7066. struct tg3 *tp = netdev_priv(dev);
  7067. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7068. if (data != 0)
  7069. return -EINVAL;
  7070. return 0;
  7071. }
  7072. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7073. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7074. ethtool_op_set_tx_ipv6_csum(dev, data);
  7075. else
  7076. ethtool_op_set_tx_csum(dev, data);
  7077. return 0;
  7078. }
  7079. static int tg3_get_stats_count (struct net_device *dev)
  7080. {
  7081. return TG3_NUM_STATS;
  7082. }
  7083. static int tg3_get_test_count (struct net_device *dev)
  7084. {
  7085. return TG3_NUM_TEST;
  7086. }
  7087. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7088. {
  7089. switch (stringset) {
  7090. case ETH_SS_STATS:
  7091. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7092. break;
  7093. case ETH_SS_TEST:
  7094. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7095. break;
  7096. default:
  7097. WARN_ON(1); /* we need a WARN() */
  7098. break;
  7099. }
  7100. }
  7101. static int tg3_phys_id(struct net_device *dev, u32 data)
  7102. {
  7103. struct tg3 *tp = netdev_priv(dev);
  7104. int i;
  7105. if (!netif_running(tp->dev))
  7106. return -EAGAIN;
  7107. if (data == 0)
  7108. data = 2;
  7109. for (i = 0; i < (data * 2); i++) {
  7110. if ((i % 2) == 0)
  7111. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7112. LED_CTRL_1000MBPS_ON |
  7113. LED_CTRL_100MBPS_ON |
  7114. LED_CTRL_10MBPS_ON |
  7115. LED_CTRL_TRAFFIC_OVERRIDE |
  7116. LED_CTRL_TRAFFIC_BLINK |
  7117. LED_CTRL_TRAFFIC_LED);
  7118. else
  7119. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7120. LED_CTRL_TRAFFIC_OVERRIDE);
  7121. if (msleep_interruptible(500))
  7122. break;
  7123. }
  7124. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7125. return 0;
  7126. }
  7127. static void tg3_get_ethtool_stats (struct net_device *dev,
  7128. struct ethtool_stats *estats, u64 *tmp_stats)
  7129. {
  7130. struct tg3 *tp = netdev_priv(dev);
  7131. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7132. }
  7133. #define NVRAM_TEST_SIZE 0x100
  7134. #define NVRAM_SELFBOOT_FORMAT1_SIZE 0x14
  7135. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7136. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7137. static int tg3_test_nvram(struct tg3 *tp)
  7138. {
  7139. u32 *buf, csum, magic;
  7140. int i, j, err = 0, size;
  7141. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7142. return -EIO;
  7143. if (magic == TG3_EEPROM_MAGIC)
  7144. size = NVRAM_TEST_SIZE;
  7145. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7146. if ((magic & 0xe00000) == 0x200000)
  7147. size = NVRAM_SELFBOOT_FORMAT1_SIZE;
  7148. else
  7149. return 0;
  7150. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7151. size = NVRAM_SELFBOOT_HW_SIZE;
  7152. else
  7153. return -EIO;
  7154. buf = kmalloc(size, GFP_KERNEL);
  7155. if (buf == NULL)
  7156. return -ENOMEM;
  7157. err = -EIO;
  7158. for (i = 0, j = 0; i < size; i += 4, j++) {
  7159. u32 val;
  7160. if ((err = tg3_nvram_read(tp, i, &val)) != 0)
  7161. break;
  7162. buf[j] = cpu_to_le32(val);
  7163. }
  7164. if (i < size)
  7165. goto out;
  7166. /* Selfboot format */
  7167. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) ==
  7168. TG3_EEPROM_MAGIC_FW) {
  7169. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7170. for (i = 0; i < size; i++)
  7171. csum8 += buf8[i];
  7172. if (csum8 == 0) {
  7173. err = 0;
  7174. goto out;
  7175. }
  7176. err = -EIO;
  7177. goto out;
  7178. }
  7179. if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) ==
  7180. TG3_EEPROM_MAGIC_HW) {
  7181. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7182. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7183. u8 *buf8 = (u8 *) buf;
  7184. int j, k;
  7185. /* Separate the parity bits and the data bytes. */
  7186. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7187. if ((i == 0) || (i == 8)) {
  7188. int l;
  7189. u8 msk;
  7190. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7191. parity[k++] = buf8[i] & msk;
  7192. i++;
  7193. }
  7194. else if (i == 16) {
  7195. int l;
  7196. u8 msk;
  7197. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7198. parity[k++] = buf8[i] & msk;
  7199. i++;
  7200. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7201. parity[k++] = buf8[i] & msk;
  7202. i++;
  7203. }
  7204. data[j++] = buf8[i];
  7205. }
  7206. err = -EIO;
  7207. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7208. u8 hw8 = hweight8(data[i]);
  7209. if ((hw8 & 0x1) && parity[i])
  7210. goto out;
  7211. else if (!(hw8 & 0x1) && !parity[i])
  7212. goto out;
  7213. }
  7214. err = 0;
  7215. goto out;
  7216. }
  7217. /* Bootstrap checksum at offset 0x10 */
  7218. csum = calc_crc((unsigned char *) buf, 0x10);
  7219. if(csum != cpu_to_le32(buf[0x10/4]))
  7220. goto out;
  7221. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7222. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7223. if (csum != cpu_to_le32(buf[0xfc/4]))
  7224. goto out;
  7225. err = 0;
  7226. out:
  7227. kfree(buf);
  7228. return err;
  7229. }
  7230. #define TG3_SERDES_TIMEOUT_SEC 2
  7231. #define TG3_COPPER_TIMEOUT_SEC 6
  7232. static int tg3_test_link(struct tg3 *tp)
  7233. {
  7234. int i, max;
  7235. if (!netif_running(tp->dev))
  7236. return -ENODEV;
  7237. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7238. max = TG3_SERDES_TIMEOUT_SEC;
  7239. else
  7240. max = TG3_COPPER_TIMEOUT_SEC;
  7241. for (i = 0; i < max; i++) {
  7242. if (netif_carrier_ok(tp->dev))
  7243. return 0;
  7244. if (msleep_interruptible(1000))
  7245. break;
  7246. }
  7247. return -EIO;
  7248. }
  7249. /* Only test the commonly used registers */
  7250. static int tg3_test_registers(struct tg3 *tp)
  7251. {
  7252. int i, is_5705, is_5750;
  7253. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7254. static struct {
  7255. u16 offset;
  7256. u16 flags;
  7257. #define TG3_FL_5705 0x1
  7258. #define TG3_FL_NOT_5705 0x2
  7259. #define TG3_FL_NOT_5788 0x4
  7260. #define TG3_FL_NOT_5750 0x8
  7261. u32 read_mask;
  7262. u32 write_mask;
  7263. } reg_tbl[] = {
  7264. /* MAC Control Registers */
  7265. { MAC_MODE, TG3_FL_NOT_5705,
  7266. 0x00000000, 0x00ef6f8c },
  7267. { MAC_MODE, TG3_FL_5705,
  7268. 0x00000000, 0x01ef6b8c },
  7269. { MAC_STATUS, TG3_FL_NOT_5705,
  7270. 0x03800107, 0x00000000 },
  7271. { MAC_STATUS, TG3_FL_5705,
  7272. 0x03800100, 0x00000000 },
  7273. { MAC_ADDR_0_HIGH, 0x0000,
  7274. 0x00000000, 0x0000ffff },
  7275. { MAC_ADDR_0_LOW, 0x0000,
  7276. 0x00000000, 0xffffffff },
  7277. { MAC_RX_MTU_SIZE, 0x0000,
  7278. 0x00000000, 0x0000ffff },
  7279. { MAC_TX_MODE, 0x0000,
  7280. 0x00000000, 0x00000070 },
  7281. { MAC_TX_LENGTHS, 0x0000,
  7282. 0x00000000, 0x00003fff },
  7283. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7284. 0x00000000, 0x000007fc },
  7285. { MAC_RX_MODE, TG3_FL_5705,
  7286. 0x00000000, 0x000007dc },
  7287. { MAC_HASH_REG_0, 0x0000,
  7288. 0x00000000, 0xffffffff },
  7289. { MAC_HASH_REG_1, 0x0000,
  7290. 0x00000000, 0xffffffff },
  7291. { MAC_HASH_REG_2, 0x0000,
  7292. 0x00000000, 0xffffffff },
  7293. { MAC_HASH_REG_3, 0x0000,
  7294. 0x00000000, 0xffffffff },
  7295. /* Receive Data and Receive BD Initiator Control Registers. */
  7296. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7297. 0x00000000, 0xffffffff },
  7298. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7299. 0x00000000, 0xffffffff },
  7300. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7301. 0x00000000, 0x00000003 },
  7302. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7303. 0x00000000, 0xffffffff },
  7304. { RCVDBDI_STD_BD+0, 0x0000,
  7305. 0x00000000, 0xffffffff },
  7306. { RCVDBDI_STD_BD+4, 0x0000,
  7307. 0x00000000, 0xffffffff },
  7308. { RCVDBDI_STD_BD+8, 0x0000,
  7309. 0x00000000, 0xffff0002 },
  7310. { RCVDBDI_STD_BD+0xc, 0x0000,
  7311. 0x00000000, 0xffffffff },
  7312. /* Receive BD Initiator Control Registers. */
  7313. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7314. 0x00000000, 0xffffffff },
  7315. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7316. 0x00000000, 0x000003ff },
  7317. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7318. 0x00000000, 0xffffffff },
  7319. /* Host Coalescing Control Registers. */
  7320. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7321. 0x00000000, 0x00000004 },
  7322. { HOSTCC_MODE, TG3_FL_5705,
  7323. 0x00000000, 0x000000f6 },
  7324. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7325. 0x00000000, 0xffffffff },
  7326. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7327. 0x00000000, 0x000003ff },
  7328. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7329. 0x00000000, 0xffffffff },
  7330. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7331. 0x00000000, 0x000003ff },
  7332. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7333. 0x00000000, 0xffffffff },
  7334. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7335. 0x00000000, 0x000000ff },
  7336. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7337. 0x00000000, 0xffffffff },
  7338. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7339. 0x00000000, 0x000000ff },
  7340. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7341. 0x00000000, 0xffffffff },
  7342. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7343. 0x00000000, 0xffffffff },
  7344. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7345. 0x00000000, 0xffffffff },
  7346. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7347. 0x00000000, 0x000000ff },
  7348. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7349. 0x00000000, 0xffffffff },
  7350. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7351. 0x00000000, 0x000000ff },
  7352. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7353. 0x00000000, 0xffffffff },
  7354. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7355. 0x00000000, 0xffffffff },
  7356. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7357. 0x00000000, 0xffffffff },
  7358. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7359. 0x00000000, 0xffffffff },
  7360. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7361. 0x00000000, 0xffffffff },
  7362. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7363. 0xffffffff, 0x00000000 },
  7364. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7365. 0xffffffff, 0x00000000 },
  7366. /* Buffer Manager Control Registers. */
  7367. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7368. 0x00000000, 0x007fff80 },
  7369. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7370. 0x00000000, 0x007fffff },
  7371. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7372. 0x00000000, 0x0000003f },
  7373. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7374. 0x00000000, 0x000001ff },
  7375. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7376. 0x00000000, 0x000001ff },
  7377. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7378. 0xffffffff, 0x00000000 },
  7379. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7380. 0xffffffff, 0x00000000 },
  7381. /* Mailbox Registers */
  7382. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7383. 0x00000000, 0x000001ff },
  7384. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7385. 0x00000000, 0x000001ff },
  7386. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7387. 0x00000000, 0x000007ff },
  7388. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7389. 0x00000000, 0x000001ff },
  7390. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7391. };
  7392. is_5705 = is_5750 = 0;
  7393. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7394. is_5705 = 1;
  7395. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7396. is_5750 = 1;
  7397. }
  7398. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7399. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7400. continue;
  7401. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7402. continue;
  7403. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7404. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7405. continue;
  7406. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7407. continue;
  7408. offset = (u32) reg_tbl[i].offset;
  7409. read_mask = reg_tbl[i].read_mask;
  7410. write_mask = reg_tbl[i].write_mask;
  7411. /* Save the original register content */
  7412. save_val = tr32(offset);
  7413. /* Determine the read-only value. */
  7414. read_val = save_val & read_mask;
  7415. /* Write zero to the register, then make sure the read-only bits
  7416. * are not changed and the read/write bits are all zeros.
  7417. */
  7418. tw32(offset, 0);
  7419. val = tr32(offset);
  7420. /* Test the read-only and read/write bits. */
  7421. if (((val & read_mask) != read_val) || (val & write_mask))
  7422. goto out;
  7423. /* Write ones to all the bits defined by RdMask and WrMask, then
  7424. * make sure the read-only bits are not changed and the
  7425. * read/write bits are all ones.
  7426. */
  7427. tw32(offset, read_mask | write_mask);
  7428. val = tr32(offset);
  7429. /* Test the read-only bits. */
  7430. if ((val & read_mask) != read_val)
  7431. goto out;
  7432. /* Test the read/write bits. */
  7433. if ((val & write_mask) != write_mask)
  7434. goto out;
  7435. tw32(offset, save_val);
  7436. }
  7437. return 0;
  7438. out:
  7439. if (netif_msg_hw(tp))
  7440. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7441. offset);
  7442. tw32(offset, save_val);
  7443. return -EIO;
  7444. }
  7445. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7446. {
  7447. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7448. int i;
  7449. u32 j;
  7450. for (i = 0; i < sizeof(test_pattern)/sizeof(u32); i++) {
  7451. for (j = 0; j < len; j += 4) {
  7452. u32 val;
  7453. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7454. tg3_read_mem(tp, offset + j, &val);
  7455. if (val != test_pattern[i])
  7456. return -EIO;
  7457. }
  7458. }
  7459. return 0;
  7460. }
  7461. static int tg3_test_memory(struct tg3 *tp)
  7462. {
  7463. static struct mem_entry {
  7464. u32 offset;
  7465. u32 len;
  7466. } mem_tbl_570x[] = {
  7467. { 0x00000000, 0x00b50},
  7468. { 0x00002000, 0x1c000},
  7469. { 0xffffffff, 0x00000}
  7470. }, mem_tbl_5705[] = {
  7471. { 0x00000100, 0x0000c},
  7472. { 0x00000200, 0x00008},
  7473. { 0x00004000, 0x00800},
  7474. { 0x00006000, 0x01000},
  7475. { 0x00008000, 0x02000},
  7476. { 0x00010000, 0x0e000},
  7477. { 0xffffffff, 0x00000}
  7478. }, mem_tbl_5755[] = {
  7479. { 0x00000200, 0x00008},
  7480. { 0x00004000, 0x00800},
  7481. { 0x00006000, 0x00800},
  7482. { 0x00008000, 0x02000},
  7483. { 0x00010000, 0x0c000},
  7484. { 0xffffffff, 0x00000}
  7485. }, mem_tbl_5906[] = {
  7486. { 0x00000200, 0x00008},
  7487. { 0x00004000, 0x00400},
  7488. { 0x00006000, 0x00400},
  7489. { 0x00008000, 0x01000},
  7490. { 0x00010000, 0x01000},
  7491. { 0xffffffff, 0x00000}
  7492. };
  7493. struct mem_entry *mem_tbl;
  7494. int err = 0;
  7495. int i;
  7496. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7497. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7498. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  7499. mem_tbl = mem_tbl_5755;
  7500. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7501. mem_tbl = mem_tbl_5906;
  7502. else
  7503. mem_tbl = mem_tbl_5705;
  7504. } else
  7505. mem_tbl = mem_tbl_570x;
  7506. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7507. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7508. mem_tbl[i].len)) != 0)
  7509. break;
  7510. }
  7511. return err;
  7512. }
  7513. #define TG3_MAC_LOOPBACK 0
  7514. #define TG3_PHY_LOOPBACK 1
  7515. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7516. {
  7517. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7518. u32 desc_idx;
  7519. struct sk_buff *skb, *rx_skb;
  7520. u8 *tx_data;
  7521. dma_addr_t map;
  7522. int num_pkts, tx_len, rx_len, i, err;
  7523. struct tg3_rx_buffer_desc *desc;
  7524. if (loopback_mode == TG3_MAC_LOOPBACK) {
  7525. /* HW errata - mac loopback fails in some cases on 5780.
  7526. * Normal traffic and PHY loopback are not affected by
  7527. * errata.
  7528. */
  7529. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  7530. return 0;
  7531. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  7532. MAC_MODE_PORT_INT_LPBACK;
  7533. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7534. mac_mode |= MAC_MODE_LINK_POLARITY;
  7535. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  7536. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7537. else
  7538. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7539. tw32(MAC_MODE, mac_mode);
  7540. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  7541. u32 val;
  7542. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7543. u32 phytest;
  7544. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  7545. u32 phy;
  7546. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  7547. phytest | MII_TG3_EPHY_SHADOW_EN);
  7548. if (!tg3_readphy(tp, 0x1b, &phy))
  7549. tg3_writephy(tp, 0x1b, phy & ~0x20);
  7550. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  7551. }
  7552. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  7553. } else
  7554. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  7555. tg3_phy_toggle_automdix(tp, 0);
  7556. tg3_writephy(tp, MII_BMCR, val);
  7557. udelay(40);
  7558. mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  7559. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  7560. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  7561. mac_mode |= MAC_MODE_PORT_MODE_MII;
  7562. } else
  7563. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  7564. /* reset to prevent losing 1st rx packet intermittently */
  7565. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  7566. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  7567. udelay(10);
  7568. tw32_f(MAC_RX_MODE, tp->rx_mode);
  7569. }
  7570. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  7571. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
  7572. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  7573. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411)
  7574. mac_mode |= MAC_MODE_LINK_POLARITY;
  7575. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  7576. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  7577. }
  7578. tw32(MAC_MODE, mac_mode);
  7579. }
  7580. else
  7581. return -EINVAL;
  7582. err = -EIO;
  7583. tx_len = 1514;
  7584. skb = netdev_alloc_skb(tp->dev, tx_len);
  7585. if (!skb)
  7586. return -ENOMEM;
  7587. tx_data = skb_put(skb, tx_len);
  7588. memcpy(tx_data, tp->dev->dev_addr, 6);
  7589. memset(tx_data + 6, 0x0, 8);
  7590. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  7591. for (i = 14; i < tx_len; i++)
  7592. tx_data[i] = (u8) (i & 0xff);
  7593. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  7594. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7595. HOSTCC_MODE_NOW);
  7596. udelay(10);
  7597. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  7598. num_pkts = 0;
  7599. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  7600. tp->tx_prod++;
  7601. num_pkts++;
  7602. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  7603. tp->tx_prod);
  7604. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  7605. udelay(10);
  7606. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  7607. for (i = 0; i < 25; i++) {
  7608. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  7609. HOSTCC_MODE_NOW);
  7610. udelay(10);
  7611. tx_idx = tp->hw_status->idx[0].tx_consumer;
  7612. rx_idx = tp->hw_status->idx[0].rx_producer;
  7613. if ((tx_idx == tp->tx_prod) &&
  7614. (rx_idx == (rx_start_idx + num_pkts)))
  7615. break;
  7616. }
  7617. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  7618. dev_kfree_skb(skb);
  7619. if (tx_idx != tp->tx_prod)
  7620. goto out;
  7621. if (rx_idx != rx_start_idx + num_pkts)
  7622. goto out;
  7623. desc = &tp->rx_rcb[rx_start_idx];
  7624. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  7625. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  7626. if (opaque_key != RXD_OPAQUE_RING_STD)
  7627. goto out;
  7628. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  7629. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  7630. goto out;
  7631. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  7632. if (rx_len != tx_len)
  7633. goto out;
  7634. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  7635. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  7636. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  7637. for (i = 14; i < tx_len; i++) {
  7638. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  7639. goto out;
  7640. }
  7641. err = 0;
  7642. /* tg3_free_rings will unmap and free the rx_skb */
  7643. out:
  7644. return err;
  7645. }
  7646. #define TG3_MAC_LOOPBACK_FAILED 1
  7647. #define TG3_PHY_LOOPBACK_FAILED 2
  7648. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  7649. TG3_PHY_LOOPBACK_FAILED)
  7650. static int tg3_test_loopback(struct tg3 *tp)
  7651. {
  7652. int err = 0;
  7653. if (!netif_running(tp->dev))
  7654. return TG3_LOOPBACK_FAILED;
  7655. err = tg3_reset_hw(tp, 1);
  7656. if (err)
  7657. return TG3_LOOPBACK_FAILED;
  7658. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  7659. err |= TG3_MAC_LOOPBACK_FAILED;
  7660. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  7661. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  7662. err |= TG3_PHY_LOOPBACK_FAILED;
  7663. }
  7664. return err;
  7665. }
  7666. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  7667. u64 *data)
  7668. {
  7669. struct tg3 *tp = netdev_priv(dev);
  7670. if (tp->link_config.phy_is_low_power)
  7671. tg3_set_power_state(tp, PCI_D0);
  7672. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  7673. if (tg3_test_nvram(tp) != 0) {
  7674. etest->flags |= ETH_TEST_FL_FAILED;
  7675. data[0] = 1;
  7676. }
  7677. if (tg3_test_link(tp) != 0) {
  7678. etest->flags |= ETH_TEST_FL_FAILED;
  7679. data[1] = 1;
  7680. }
  7681. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7682. int err, irq_sync = 0;
  7683. if (netif_running(dev)) {
  7684. tg3_netif_stop(tp);
  7685. irq_sync = 1;
  7686. }
  7687. tg3_full_lock(tp, irq_sync);
  7688. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  7689. err = tg3_nvram_lock(tp);
  7690. tg3_halt_cpu(tp, RX_CPU_BASE);
  7691. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  7692. tg3_halt_cpu(tp, TX_CPU_BASE);
  7693. if (!err)
  7694. tg3_nvram_unlock(tp);
  7695. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  7696. tg3_phy_reset(tp);
  7697. if (tg3_test_registers(tp) != 0) {
  7698. etest->flags |= ETH_TEST_FL_FAILED;
  7699. data[2] = 1;
  7700. }
  7701. if (tg3_test_memory(tp) != 0) {
  7702. etest->flags |= ETH_TEST_FL_FAILED;
  7703. data[3] = 1;
  7704. }
  7705. if ((data[4] = tg3_test_loopback(tp)) != 0)
  7706. etest->flags |= ETH_TEST_FL_FAILED;
  7707. tg3_full_unlock(tp);
  7708. if (tg3_test_interrupt(tp) != 0) {
  7709. etest->flags |= ETH_TEST_FL_FAILED;
  7710. data[5] = 1;
  7711. }
  7712. tg3_full_lock(tp, 0);
  7713. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7714. if (netif_running(dev)) {
  7715. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  7716. if (!tg3_restart_hw(tp, 1))
  7717. tg3_netif_start(tp);
  7718. }
  7719. tg3_full_unlock(tp);
  7720. }
  7721. if (tp->link_config.phy_is_low_power)
  7722. tg3_set_power_state(tp, PCI_D3hot);
  7723. }
  7724. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7725. {
  7726. struct mii_ioctl_data *data = if_mii(ifr);
  7727. struct tg3 *tp = netdev_priv(dev);
  7728. int err;
  7729. switch(cmd) {
  7730. case SIOCGMIIPHY:
  7731. data->phy_id = PHY_ADDR;
  7732. /* fallthru */
  7733. case SIOCGMIIREG: {
  7734. u32 mii_regval;
  7735. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7736. break; /* We have no PHY */
  7737. if (tp->link_config.phy_is_low_power)
  7738. return -EAGAIN;
  7739. spin_lock_bh(&tp->lock);
  7740. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  7741. spin_unlock_bh(&tp->lock);
  7742. data->val_out = mii_regval;
  7743. return err;
  7744. }
  7745. case SIOCSMIIREG:
  7746. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7747. break; /* We have no PHY */
  7748. if (!capable(CAP_NET_ADMIN))
  7749. return -EPERM;
  7750. if (tp->link_config.phy_is_low_power)
  7751. return -EAGAIN;
  7752. spin_lock_bh(&tp->lock);
  7753. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  7754. spin_unlock_bh(&tp->lock);
  7755. return err;
  7756. default:
  7757. /* do nothing */
  7758. break;
  7759. }
  7760. return -EOPNOTSUPP;
  7761. }
  7762. #if TG3_VLAN_TAG_USED
  7763. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  7764. {
  7765. struct tg3 *tp = netdev_priv(dev);
  7766. if (netif_running(dev))
  7767. tg3_netif_stop(tp);
  7768. tg3_full_lock(tp, 0);
  7769. tp->vlgrp = grp;
  7770. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  7771. __tg3_set_rx_mode(dev);
  7772. if (netif_running(dev))
  7773. tg3_netif_start(tp);
  7774. tg3_full_unlock(tp);
  7775. }
  7776. #endif
  7777. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7778. {
  7779. struct tg3 *tp = netdev_priv(dev);
  7780. memcpy(ec, &tp->coal, sizeof(*ec));
  7781. return 0;
  7782. }
  7783. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  7784. {
  7785. struct tg3 *tp = netdev_priv(dev);
  7786. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  7787. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  7788. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  7789. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  7790. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  7791. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  7792. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  7793. }
  7794. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  7795. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  7796. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  7797. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  7798. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  7799. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  7800. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  7801. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  7802. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  7803. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  7804. return -EINVAL;
  7805. /* No rx interrupts will be generated if both are zero */
  7806. if ((ec->rx_coalesce_usecs == 0) &&
  7807. (ec->rx_max_coalesced_frames == 0))
  7808. return -EINVAL;
  7809. /* No tx interrupts will be generated if both are zero */
  7810. if ((ec->tx_coalesce_usecs == 0) &&
  7811. (ec->tx_max_coalesced_frames == 0))
  7812. return -EINVAL;
  7813. /* Only copy relevant parameters, ignore all others. */
  7814. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  7815. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  7816. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  7817. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  7818. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  7819. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  7820. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  7821. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  7822. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  7823. if (netif_running(dev)) {
  7824. tg3_full_lock(tp, 0);
  7825. __tg3_set_coalesce(tp, &tp->coal);
  7826. tg3_full_unlock(tp);
  7827. }
  7828. return 0;
  7829. }
  7830. static const struct ethtool_ops tg3_ethtool_ops = {
  7831. .get_settings = tg3_get_settings,
  7832. .set_settings = tg3_set_settings,
  7833. .get_drvinfo = tg3_get_drvinfo,
  7834. .get_regs_len = tg3_get_regs_len,
  7835. .get_regs = tg3_get_regs,
  7836. .get_wol = tg3_get_wol,
  7837. .set_wol = tg3_set_wol,
  7838. .get_msglevel = tg3_get_msglevel,
  7839. .set_msglevel = tg3_set_msglevel,
  7840. .nway_reset = tg3_nway_reset,
  7841. .get_link = ethtool_op_get_link,
  7842. .get_eeprom_len = tg3_get_eeprom_len,
  7843. .get_eeprom = tg3_get_eeprom,
  7844. .set_eeprom = tg3_set_eeprom,
  7845. .get_ringparam = tg3_get_ringparam,
  7846. .set_ringparam = tg3_set_ringparam,
  7847. .get_pauseparam = tg3_get_pauseparam,
  7848. .set_pauseparam = tg3_set_pauseparam,
  7849. .get_rx_csum = tg3_get_rx_csum,
  7850. .set_rx_csum = tg3_set_rx_csum,
  7851. .get_tx_csum = ethtool_op_get_tx_csum,
  7852. .set_tx_csum = tg3_set_tx_csum,
  7853. .get_sg = ethtool_op_get_sg,
  7854. .set_sg = ethtool_op_set_sg,
  7855. .get_tso = ethtool_op_get_tso,
  7856. .set_tso = tg3_set_tso,
  7857. .self_test_count = tg3_get_test_count,
  7858. .self_test = tg3_self_test,
  7859. .get_strings = tg3_get_strings,
  7860. .phys_id = tg3_phys_id,
  7861. .get_stats_count = tg3_get_stats_count,
  7862. .get_ethtool_stats = tg3_get_ethtool_stats,
  7863. .get_coalesce = tg3_get_coalesce,
  7864. .set_coalesce = tg3_set_coalesce,
  7865. .get_perm_addr = ethtool_op_get_perm_addr,
  7866. };
  7867. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  7868. {
  7869. u32 cursize, val, magic;
  7870. tp->nvram_size = EEPROM_CHIP_SIZE;
  7871. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7872. return;
  7873. if ((magic != TG3_EEPROM_MAGIC) &&
  7874. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  7875. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  7876. return;
  7877. /*
  7878. * Size the chip by reading offsets at increasing powers of two.
  7879. * When we encounter our validation signature, we know the addressing
  7880. * has wrapped around, and thus have our chip size.
  7881. */
  7882. cursize = 0x10;
  7883. while (cursize < tp->nvram_size) {
  7884. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  7885. return;
  7886. if (val == magic)
  7887. break;
  7888. cursize <<= 1;
  7889. }
  7890. tp->nvram_size = cursize;
  7891. }
  7892. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  7893. {
  7894. u32 val;
  7895. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  7896. return;
  7897. /* Selfboot format */
  7898. if (val != TG3_EEPROM_MAGIC) {
  7899. tg3_get_eeprom_size(tp);
  7900. return;
  7901. }
  7902. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  7903. if (val != 0) {
  7904. tp->nvram_size = (val >> 16) * 1024;
  7905. return;
  7906. }
  7907. }
  7908. tp->nvram_size = 0x80000;
  7909. }
  7910. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  7911. {
  7912. u32 nvcfg1;
  7913. nvcfg1 = tr32(NVRAM_CFG1);
  7914. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  7915. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7916. }
  7917. else {
  7918. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  7919. tw32(NVRAM_CFG1, nvcfg1);
  7920. }
  7921. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  7922. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  7923. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  7924. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  7925. tp->nvram_jedecnum = JEDEC_ATMEL;
  7926. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7927. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7928. break;
  7929. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  7930. tp->nvram_jedecnum = JEDEC_ATMEL;
  7931. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  7932. break;
  7933. case FLASH_VENDOR_ATMEL_EEPROM:
  7934. tp->nvram_jedecnum = JEDEC_ATMEL;
  7935. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  7936. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7937. break;
  7938. case FLASH_VENDOR_ST:
  7939. tp->nvram_jedecnum = JEDEC_ST;
  7940. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  7941. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7942. break;
  7943. case FLASH_VENDOR_SAIFUN:
  7944. tp->nvram_jedecnum = JEDEC_SAIFUN;
  7945. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  7946. break;
  7947. case FLASH_VENDOR_SST_SMALL:
  7948. case FLASH_VENDOR_SST_LARGE:
  7949. tp->nvram_jedecnum = JEDEC_SST;
  7950. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  7951. break;
  7952. }
  7953. }
  7954. else {
  7955. tp->nvram_jedecnum = JEDEC_ATMEL;
  7956. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  7957. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7958. }
  7959. }
  7960. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  7961. {
  7962. u32 nvcfg1;
  7963. nvcfg1 = tr32(NVRAM_CFG1);
  7964. /* NVRAM protection for TPM */
  7965. if (nvcfg1 & (1 << 27))
  7966. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  7967. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  7968. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  7969. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  7970. tp->nvram_jedecnum = JEDEC_ATMEL;
  7971. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7972. break;
  7973. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  7974. tp->nvram_jedecnum = JEDEC_ATMEL;
  7975. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7976. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7977. break;
  7978. case FLASH_5752VENDOR_ST_M45PE10:
  7979. case FLASH_5752VENDOR_ST_M45PE20:
  7980. case FLASH_5752VENDOR_ST_M45PE40:
  7981. tp->nvram_jedecnum = JEDEC_ST;
  7982. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  7983. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  7984. break;
  7985. }
  7986. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  7987. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  7988. case FLASH_5752PAGE_SIZE_256:
  7989. tp->nvram_pagesize = 256;
  7990. break;
  7991. case FLASH_5752PAGE_SIZE_512:
  7992. tp->nvram_pagesize = 512;
  7993. break;
  7994. case FLASH_5752PAGE_SIZE_1K:
  7995. tp->nvram_pagesize = 1024;
  7996. break;
  7997. case FLASH_5752PAGE_SIZE_2K:
  7998. tp->nvram_pagesize = 2048;
  7999. break;
  8000. case FLASH_5752PAGE_SIZE_4K:
  8001. tp->nvram_pagesize = 4096;
  8002. break;
  8003. case FLASH_5752PAGE_SIZE_264:
  8004. tp->nvram_pagesize = 264;
  8005. break;
  8006. }
  8007. }
  8008. else {
  8009. /* For eeprom, set pagesize to maximum eeprom size */
  8010. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8011. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8012. tw32(NVRAM_CFG1, nvcfg1);
  8013. }
  8014. }
  8015. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  8016. {
  8017. u32 nvcfg1, protect = 0;
  8018. nvcfg1 = tr32(NVRAM_CFG1);
  8019. /* NVRAM protection for TPM */
  8020. if (nvcfg1 & (1 << 27)) {
  8021. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8022. protect = 1;
  8023. }
  8024. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8025. switch (nvcfg1) {
  8026. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8027. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8028. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8029. case FLASH_5755VENDOR_ATMEL_FLASH_5:
  8030. tp->nvram_jedecnum = JEDEC_ATMEL;
  8031. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8032. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8033. tp->nvram_pagesize = 264;
  8034. if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
  8035. nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
  8036. tp->nvram_size = (protect ? 0x3e200 : 0x80000);
  8037. else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
  8038. tp->nvram_size = (protect ? 0x1f200 : 0x40000);
  8039. else
  8040. tp->nvram_size = (protect ? 0x1f200 : 0x20000);
  8041. break;
  8042. case FLASH_5752VENDOR_ST_M45PE10:
  8043. case FLASH_5752VENDOR_ST_M45PE20:
  8044. case FLASH_5752VENDOR_ST_M45PE40:
  8045. tp->nvram_jedecnum = JEDEC_ST;
  8046. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8047. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8048. tp->nvram_pagesize = 256;
  8049. if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
  8050. tp->nvram_size = (protect ? 0x10000 : 0x20000);
  8051. else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
  8052. tp->nvram_size = (protect ? 0x10000 : 0x40000);
  8053. else
  8054. tp->nvram_size = (protect ? 0x20000 : 0x80000);
  8055. break;
  8056. }
  8057. }
  8058. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8059. {
  8060. u32 nvcfg1;
  8061. nvcfg1 = tr32(NVRAM_CFG1);
  8062. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8063. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8064. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8065. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8066. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8067. tp->nvram_jedecnum = JEDEC_ATMEL;
  8068. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8069. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8070. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8071. tw32(NVRAM_CFG1, nvcfg1);
  8072. break;
  8073. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8074. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8075. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8076. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8077. tp->nvram_jedecnum = JEDEC_ATMEL;
  8078. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8079. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8080. tp->nvram_pagesize = 264;
  8081. break;
  8082. case FLASH_5752VENDOR_ST_M45PE10:
  8083. case FLASH_5752VENDOR_ST_M45PE20:
  8084. case FLASH_5752VENDOR_ST_M45PE40:
  8085. tp->nvram_jedecnum = JEDEC_ST;
  8086. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8087. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8088. tp->nvram_pagesize = 256;
  8089. break;
  8090. }
  8091. }
  8092. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8093. {
  8094. tp->nvram_jedecnum = JEDEC_ATMEL;
  8095. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8096. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8097. }
  8098. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8099. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8100. {
  8101. tw32_f(GRC_EEPROM_ADDR,
  8102. (EEPROM_ADDR_FSM_RESET |
  8103. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8104. EEPROM_ADDR_CLKPERD_SHIFT)));
  8105. msleep(1);
  8106. /* Enable seeprom accesses. */
  8107. tw32_f(GRC_LOCAL_CTRL,
  8108. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8109. udelay(100);
  8110. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8111. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8112. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8113. if (tg3_nvram_lock(tp)) {
  8114. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8115. "tg3_nvram_init failed.\n", tp->dev->name);
  8116. return;
  8117. }
  8118. tg3_enable_nvram_access(tp);
  8119. tp->nvram_size = 0;
  8120. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8121. tg3_get_5752_nvram_info(tp);
  8122. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8123. tg3_get_5755_nvram_info(tp);
  8124. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  8125. tg3_get_5787_nvram_info(tp);
  8126. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8127. tg3_get_5906_nvram_info(tp);
  8128. else
  8129. tg3_get_nvram_info(tp);
  8130. if (tp->nvram_size == 0)
  8131. tg3_get_nvram_size(tp);
  8132. tg3_disable_nvram_access(tp);
  8133. tg3_nvram_unlock(tp);
  8134. } else {
  8135. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8136. tg3_get_eeprom_size(tp);
  8137. }
  8138. }
  8139. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8140. u32 offset, u32 *val)
  8141. {
  8142. u32 tmp;
  8143. int i;
  8144. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8145. (offset % 4) != 0)
  8146. return -EINVAL;
  8147. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8148. EEPROM_ADDR_DEVID_MASK |
  8149. EEPROM_ADDR_READ);
  8150. tw32(GRC_EEPROM_ADDR,
  8151. tmp |
  8152. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8153. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8154. EEPROM_ADDR_ADDR_MASK) |
  8155. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8156. for (i = 0; i < 1000; i++) {
  8157. tmp = tr32(GRC_EEPROM_ADDR);
  8158. if (tmp & EEPROM_ADDR_COMPLETE)
  8159. break;
  8160. msleep(1);
  8161. }
  8162. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8163. return -EBUSY;
  8164. *val = tr32(GRC_EEPROM_DATA);
  8165. return 0;
  8166. }
  8167. #define NVRAM_CMD_TIMEOUT 10000
  8168. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8169. {
  8170. int i;
  8171. tw32(NVRAM_CMD, nvram_cmd);
  8172. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8173. udelay(10);
  8174. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8175. udelay(10);
  8176. break;
  8177. }
  8178. }
  8179. if (i == NVRAM_CMD_TIMEOUT) {
  8180. return -EBUSY;
  8181. }
  8182. return 0;
  8183. }
  8184. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8185. {
  8186. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8187. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8188. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8189. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8190. addr = ((addr / tp->nvram_pagesize) <<
  8191. ATMEL_AT45DB0X1B_PAGE_POS) +
  8192. (addr % tp->nvram_pagesize);
  8193. return addr;
  8194. }
  8195. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8196. {
  8197. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8198. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8199. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8200. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8201. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8202. tp->nvram_pagesize) +
  8203. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8204. return addr;
  8205. }
  8206. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8207. {
  8208. int ret;
  8209. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8210. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8211. offset = tg3_nvram_phys_addr(tp, offset);
  8212. if (offset > NVRAM_ADDR_MSK)
  8213. return -EINVAL;
  8214. ret = tg3_nvram_lock(tp);
  8215. if (ret)
  8216. return ret;
  8217. tg3_enable_nvram_access(tp);
  8218. tw32(NVRAM_ADDR, offset);
  8219. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8220. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8221. if (ret == 0)
  8222. *val = swab32(tr32(NVRAM_RDDATA));
  8223. tg3_disable_nvram_access(tp);
  8224. tg3_nvram_unlock(tp);
  8225. return ret;
  8226. }
  8227. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8228. {
  8229. int err;
  8230. u32 tmp;
  8231. err = tg3_nvram_read(tp, offset, &tmp);
  8232. *val = swab32(tmp);
  8233. return err;
  8234. }
  8235. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8236. u32 offset, u32 len, u8 *buf)
  8237. {
  8238. int i, j, rc = 0;
  8239. u32 val;
  8240. for (i = 0; i < len; i += 4) {
  8241. u32 addr, data;
  8242. addr = offset + i;
  8243. memcpy(&data, buf + i, 4);
  8244. tw32(GRC_EEPROM_DATA, cpu_to_le32(data));
  8245. val = tr32(GRC_EEPROM_ADDR);
  8246. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8247. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8248. EEPROM_ADDR_READ);
  8249. tw32(GRC_EEPROM_ADDR, val |
  8250. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8251. (addr & EEPROM_ADDR_ADDR_MASK) |
  8252. EEPROM_ADDR_START |
  8253. EEPROM_ADDR_WRITE);
  8254. for (j = 0; j < 1000; j++) {
  8255. val = tr32(GRC_EEPROM_ADDR);
  8256. if (val & EEPROM_ADDR_COMPLETE)
  8257. break;
  8258. msleep(1);
  8259. }
  8260. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8261. rc = -EBUSY;
  8262. break;
  8263. }
  8264. }
  8265. return rc;
  8266. }
  8267. /* offset and length are dword aligned */
  8268. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8269. u8 *buf)
  8270. {
  8271. int ret = 0;
  8272. u32 pagesize = tp->nvram_pagesize;
  8273. u32 pagemask = pagesize - 1;
  8274. u32 nvram_cmd;
  8275. u8 *tmp;
  8276. tmp = kmalloc(pagesize, GFP_KERNEL);
  8277. if (tmp == NULL)
  8278. return -ENOMEM;
  8279. while (len) {
  8280. int j;
  8281. u32 phy_addr, page_off, size;
  8282. phy_addr = offset & ~pagemask;
  8283. for (j = 0; j < pagesize; j += 4) {
  8284. if ((ret = tg3_nvram_read(tp, phy_addr + j,
  8285. (u32 *) (tmp + j))))
  8286. break;
  8287. }
  8288. if (ret)
  8289. break;
  8290. page_off = offset & pagemask;
  8291. size = pagesize;
  8292. if (len < size)
  8293. size = len;
  8294. len -= size;
  8295. memcpy(tmp + page_off, buf, size);
  8296. offset = offset + (pagesize - page_off);
  8297. tg3_enable_nvram_access(tp);
  8298. /*
  8299. * Before we can erase the flash page, we need
  8300. * to issue a special "write enable" command.
  8301. */
  8302. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8303. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8304. break;
  8305. /* Erase the target page */
  8306. tw32(NVRAM_ADDR, phy_addr);
  8307. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8308. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8309. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8310. break;
  8311. /* Issue another write enable to start the write. */
  8312. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8313. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8314. break;
  8315. for (j = 0; j < pagesize; j += 4) {
  8316. u32 data;
  8317. data = *((u32 *) (tmp + j));
  8318. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8319. tw32(NVRAM_ADDR, phy_addr + j);
  8320. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8321. NVRAM_CMD_WR;
  8322. if (j == 0)
  8323. nvram_cmd |= NVRAM_CMD_FIRST;
  8324. else if (j == (pagesize - 4))
  8325. nvram_cmd |= NVRAM_CMD_LAST;
  8326. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8327. break;
  8328. }
  8329. if (ret)
  8330. break;
  8331. }
  8332. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8333. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8334. kfree(tmp);
  8335. return ret;
  8336. }
  8337. /* offset and length are dword aligned */
  8338. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8339. u8 *buf)
  8340. {
  8341. int i, ret = 0;
  8342. for (i = 0; i < len; i += 4, offset += 4) {
  8343. u32 data, page_off, phy_addr, nvram_cmd;
  8344. memcpy(&data, buf + i, 4);
  8345. tw32(NVRAM_WRDATA, cpu_to_be32(data));
  8346. page_off = offset % tp->nvram_pagesize;
  8347. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8348. tw32(NVRAM_ADDR, phy_addr);
  8349. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8350. if ((page_off == 0) || (i == 0))
  8351. nvram_cmd |= NVRAM_CMD_FIRST;
  8352. if (page_off == (tp->nvram_pagesize - 4))
  8353. nvram_cmd |= NVRAM_CMD_LAST;
  8354. if (i == (len - 4))
  8355. nvram_cmd |= NVRAM_CMD_LAST;
  8356. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8357. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8358. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8359. (tp->nvram_jedecnum == JEDEC_ST) &&
  8360. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8361. if ((ret = tg3_nvram_exec_cmd(tp,
  8362. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8363. NVRAM_CMD_DONE)))
  8364. break;
  8365. }
  8366. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8367. /* We always do complete word writes to eeprom. */
  8368. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8369. }
  8370. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8371. break;
  8372. }
  8373. return ret;
  8374. }
  8375. /* offset and length are dword aligned */
  8376. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8377. {
  8378. int ret;
  8379. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8380. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8381. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8382. udelay(40);
  8383. }
  8384. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8385. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8386. }
  8387. else {
  8388. u32 grc_mode;
  8389. ret = tg3_nvram_lock(tp);
  8390. if (ret)
  8391. return ret;
  8392. tg3_enable_nvram_access(tp);
  8393. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8394. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8395. tw32(NVRAM_WRITE1, 0x406);
  8396. grc_mode = tr32(GRC_MODE);
  8397. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8398. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8399. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8400. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8401. buf);
  8402. }
  8403. else {
  8404. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8405. buf);
  8406. }
  8407. grc_mode = tr32(GRC_MODE);
  8408. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  8409. tg3_disable_nvram_access(tp);
  8410. tg3_nvram_unlock(tp);
  8411. }
  8412. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8413. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  8414. udelay(40);
  8415. }
  8416. return ret;
  8417. }
  8418. struct subsys_tbl_ent {
  8419. u16 subsys_vendor, subsys_devid;
  8420. u32 phy_id;
  8421. };
  8422. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  8423. /* Broadcom boards. */
  8424. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  8425. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  8426. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  8427. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  8428. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  8429. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  8430. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  8431. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  8432. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  8433. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  8434. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  8435. /* 3com boards. */
  8436. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  8437. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  8438. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  8439. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  8440. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  8441. /* DELL boards. */
  8442. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  8443. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  8444. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  8445. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  8446. /* Compaq boards. */
  8447. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  8448. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  8449. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  8450. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  8451. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  8452. /* IBM boards. */
  8453. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  8454. };
  8455. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  8456. {
  8457. int i;
  8458. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  8459. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  8460. tp->pdev->subsystem_vendor) &&
  8461. (subsys_id_to_phy_id[i].subsys_devid ==
  8462. tp->pdev->subsystem_device))
  8463. return &subsys_id_to_phy_id[i];
  8464. }
  8465. return NULL;
  8466. }
  8467. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  8468. {
  8469. u32 val;
  8470. u16 pmcsr;
  8471. /* On some early chips the SRAM cannot be accessed in D3hot state,
  8472. * so need make sure we're in D0.
  8473. */
  8474. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8475. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8476. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  8477. msleep(1);
  8478. /* Make sure register accesses (indirect or otherwise)
  8479. * will function correctly.
  8480. */
  8481. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8482. tp->misc_host_ctrl);
  8483. /* The memory arbiter has to be enabled in order for SRAM accesses
  8484. * to succeed. Normally on powerup the tg3 chip firmware will make
  8485. * sure it is enabled, but other entities such as system netboot
  8486. * code might disable it.
  8487. */
  8488. val = tr32(MEMARB_MODE);
  8489. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  8490. tp->phy_id = PHY_ID_INVALID;
  8491. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8492. /* Assume an onboard device and WOL capable by default. */
  8493. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
  8494. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8495. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  8496. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8497. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8498. }
  8499. if (tr32(VCPU_CFGSHDW) & VCPU_CFGSHDW_ASPM_DBNC)
  8500. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  8501. return;
  8502. }
  8503. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  8504. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  8505. u32 nic_cfg, led_cfg;
  8506. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  8507. int eeprom_phy_serdes = 0;
  8508. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  8509. tp->nic_sram_data_cfg = nic_cfg;
  8510. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  8511. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  8512. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  8513. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  8514. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  8515. (ver > 0) && (ver < 0x100))
  8516. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  8517. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  8518. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  8519. eeprom_phy_serdes = 1;
  8520. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  8521. if (nic_phy_id != 0) {
  8522. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  8523. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  8524. eeprom_phy_id = (id1 >> 16) << 10;
  8525. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  8526. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  8527. } else
  8528. eeprom_phy_id = 0;
  8529. tp->phy_id = eeprom_phy_id;
  8530. if (eeprom_phy_serdes) {
  8531. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  8532. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  8533. else
  8534. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8535. }
  8536. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8537. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  8538. SHASTA_EXT_LED_MODE_MASK);
  8539. else
  8540. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  8541. switch (led_cfg) {
  8542. default:
  8543. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  8544. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8545. break;
  8546. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  8547. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8548. break;
  8549. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  8550. tp->led_ctrl = LED_CTRL_MODE_MAC;
  8551. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  8552. * read on some older 5700/5701 bootcode.
  8553. */
  8554. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8555. ASIC_REV_5700 ||
  8556. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  8557. ASIC_REV_5701)
  8558. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  8559. break;
  8560. case SHASTA_EXT_LED_SHARED:
  8561. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  8562. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  8563. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  8564. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8565. LED_CTRL_MODE_PHY_2);
  8566. break;
  8567. case SHASTA_EXT_LED_MAC:
  8568. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  8569. break;
  8570. case SHASTA_EXT_LED_COMBO:
  8571. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  8572. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  8573. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  8574. LED_CTRL_MODE_PHY_2);
  8575. break;
  8576. };
  8577. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  8578. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  8579. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  8580. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  8581. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  8582. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  8583. if ((tp->pdev->subsystem_vendor ==
  8584. PCI_VENDOR_ID_ARIMA) &&
  8585. (tp->pdev->subsystem_device == 0x205a ||
  8586. tp->pdev->subsystem_device == 0x2063))
  8587. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8588. } else {
  8589. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  8590. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  8591. }
  8592. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  8593. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  8594. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  8595. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  8596. }
  8597. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  8598. !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
  8599. tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
  8600. if (cfg2 & (1 << 17))
  8601. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  8602. /* serdes signal pre-emphasis in register 0x590 set by */
  8603. /* bootcode if bit 18 is set */
  8604. if (cfg2 & (1 << 18))
  8605. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  8606. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  8607. u32 cfg3;
  8608. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3);
  8609. if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)
  8610. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  8611. }
  8612. }
  8613. }
  8614. static int __devinit tg3_phy_probe(struct tg3 *tp)
  8615. {
  8616. u32 hw_phy_id_1, hw_phy_id_2;
  8617. u32 hw_phy_id, hw_phy_id_masked;
  8618. int err;
  8619. /* Reading the PHY ID register can conflict with ASF
  8620. * firwmare access to the PHY hardware.
  8621. */
  8622. err = 0;
  8623. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  8624. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  8625. } else {
  8626. /* Now read the physical PHY_ID from the chip and verify
  8627. * that it is sane. If it doesn't look good, we fall back
  8628. * to either the hard-coded table based PHY_ID and failing
  8629. * that the value found in the eeprom area.
  8630. */
  8631. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  8632. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  8633. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  8634. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  8635. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  8636. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  8637. }
  8638. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  8639. tp->phy_id = hw_phy_id;
  8640. if (hw_phy_id_masked == PHY_ID_BCM8002)
  8641. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8642. else
  8643. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  8644. } else {
  8645. if (tp->phy_id != PHY_ID_INVALID) {
  8646. /* Do nothing, phy ID already set up in
  8647. * tg3_get_eeprom_hw_cfg().
  8648. */
  8649. } else {
  8650. struct subsys_tbl_ent *p;
  8651. /* No eeprom signature? Try the hardcoded
  8652. * subsys device table.
  8653. */
  8654. p = lookup_by_subsys(tp);
  8655. if (!p)
  8656. return -ENODEV;
  8657. tp->phy_id = p->phy_id;
  8658. if (!tp->phy_id ||
  8659. tp->phy_id == PHY_ID_BCM8002)
  8660. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  8661. }
  8662. }
  8663. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  8664. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  8665. u32 bmsr, adv_reg, tg3_ctrl, mask;
  8666. tg3_readphy(tp, MII_BMSR, &bmsr);
  8667. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  8668. (bmsr & BMSR_LSTATUS))
  8669. goto skip_phy_reset;
  8670. err = tg3_phy_reset(tp);
  8671. if (err)
  8672. return err;
  8673. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  8674. ADVERTISE_100HALF | ADVERTISE_100FULL |
  8675. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  8676. tg3_ctrl = 0;
  8677. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  8678. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  8679. MII_TG3_CTRL_ADV_1000_FULL);
  8680. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  8681. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  8682. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  8683. MII_TG3_CTRL_ENABLE_AS_MASTER);
  8684. }
  8685. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  8686. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  8687. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  8688. if (!tg3_copper_is_advertising_all(tp, mask)) {
  8689. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8690. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8691. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8692. tg3_writephy(tp, MII_BMCR,
  8693. BMCR_ANENABLE | BMCR_ANRESTART);
  8694. }
  8695. tg3_phy_set_wirespeed(tp);
  8696. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  8697. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  8698. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  8699. }
  8700. skip_phy_reset:
  8701. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  8702. err = tg3_init_5401phy_dsp(tp);
  8703. if (err)
  8704. return err;
  8705. }
  8706. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  8707. err = tg3_init_5401phy_dsp(tp);
  8708. }
  8709. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  8710. tp->link_config.advertising =
  8711. (ADVERTISED_1000baseT_Half |
  8712. ADVERTISED_1000baseT_Full |
  8713. ADVERTISED_Autoneg |
  8714. ADVERTISED_FIBRE);
  8715. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8716. tp->link_config.advertising &=
  8717. ~(ADVERTISED_1000baseT_Half |
  8718. ADVERTISED_1000baseT_Full);
  8719. return err;
  8720. }
  8721. static void __devinit tg3_read_partno(struct tg3 *tp)
  8722. {
  8723. unsigned char vpd_data[256];
  8724. unsigned int i;
  8725. u32 magic;
  8726. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  8727. goto out_not_found;
  8728. if (magic == TG3_EEPROM_MAGIC) {
  8729. for (i = 0; i < 256; i += 4) {
  8730. u32 tmp;
  8731. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  8732. goto out_not_found;
  8733. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  8734. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  8735. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  8736. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  8737. }
  8738. } else {
  8739. int vpd_cap;
  8740. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  8741. for (i = 0; i < 256; i += 4) {
  8742. u32 tmp, j = 0;
  8743. u16 tmp16;
  8744. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  8745. i);
  8746. while (j++ < 100) {
  8747. pci_read_config_word(tp->pdev, vpd_cap +
  8748. PCI_VPD_ADDR, &tmp16);
  8749. if (tmp16 & 0x8000)
  8750. break;
  8751. msleep(1);
  8752. }
  8753. if (!(tmp16 & 0x8000))
  8754. goto out_not_found;
  8755. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  8756. &tmp);
  8757. tmp = cpu_to_le32(tmp);
  8758. memcpy(&vpd_data[i], &tmp, 4);
  8759. }
  8760. }
  8761. /* Now parse and find the part number. */
  8762. for (i = 0; i < 254; ) {
  8763. unsigned char val = vpd_data[i];
  8764. unsigned int block_end;
  8765. if (val == 0x82 || val == 0x91) {
  8766. i = (i + 3 +
  8767. (vpd_data[i + 1] +
  8768. (vpd_data[i + 2] << 8)));
  8769. continue;
  8770. }
  8771. if (val != 0x90)
  8772. goto out_not_found;
  8773. block_end = (i + 3 +
  8774. (vpd_data[i + 1] +
  8775. (vpd_data[i + 2] << 8)));
  8776. i += 3;
  8777. if (block_end > 256)
  8778. goto out_not_found;
  8779. while (i < (block_end - 2)) {
  8780. if (vpd_data[i + 0] == 'P' &&
  8781. vpd_data[i + 1] == 'N') {
  8782. int partno_len = vpd_data[i + 2];
  8783. i += 3;
  8784. if (partno_len > 24 || (partno_len + i) > 256)
  8785. goto out_not_found;
  8786. memcpy(tp->board_part_number,
  8787. &vpd_data[i], partno_len);
  8788. /* Success. */
  8789. return;
  8790. }
  8791. i += 3 + vpd_data[i + 2];
  8792. }
  8793. /* Part number not found. */
  8794. goto out_not_found;
  8795. }
  8796. out_not_found:
  8797. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8798. strcpy(tp->board_part_number, "BCM95906");
  8799. else
  8800. strcpy(tp->board_part_number, "none");
  8801. }
  8802. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  8803. {
  8804. u32 val, offset, start;
  8805. if (tg3_nvram_read_swab(tp, 0, &val))
  8806. return;
  8807. if (val != TG3_EEPROM_MAGIC)
  8808. return;
  8809. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  8810. tg3_nvram_read_swab(tp, 0x4, &start))
  8811. return;
  8812. offset = tg3_nvram_logical_addr(tp, offset);
  8813. if (tg3_nvram_read_swab(tp, offset, &val))
  8814. return;
  8815. if ((val & 0xfc000000) == 0x0c000000) {
  8816. u32 ver_offset, addr;
  8817. int i;
  8818. if (tg3_nvram_read_swab(tp, offset + 4, &val) ||
  8819. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  8820. return;
  8821. if (val != 0)
  8822. return;
  8823. addr = offset + ver_offset - start;
  8824. for (i = 0; i < 16; i += 4) {
  8825. if (tg3_nvram_read(tp, addr + i, &val))
  8826. return;
  8827. val = cpu_to_le32(val);
  8828. memcpy(tp->fw_ver + i, &val, 4);
  8829. }
  8830. }
  8831. }
  8832. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
  8833. static int __devinit tg3_get_invariants(struct tg3 *tp)
  8834. {
  8835. static struct pci_device_id write_reorder_chipsets[] = {
  8836. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8837. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  8838. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  8839. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  8840. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  8841. PCI_DEVICE_ID_VIA_8385_0) },
  8842. { },
  8843. };
  8844. u32 misc_ctrl_reg;
  8845. u32 cacheline_sz_reg;
  8846. u32 pci_state_reg, grc_misc_cfg;
  8847. u32 val;
  8848. u16 pci_cmd;
  8849. int err, pcie_cap;
  8850. /* Force memory write invalidate off. If we leave it on,
  8851. * then on 5700_BX chips we have to enable a workaround.
  8852. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  8853. * to match the cacheline size. The Broadcom driver have this
  8854. * workaround but turns MWI off all the times so never uses
  8855. * it. This seems to suggest that the workaround is insufficient.
  8856. */
  8857. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  8858. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  8859. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  8860. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  8861. * has the register indirect write enable bit set before
  8862. * we try to access any of the MMIO registers. It is also
  8863. * critical that the PCI-X hw workaround situation is decided
  8864. * before that as well.
  8865. */
  8866. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8867. &misc_ctrl_reg);
  8868. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  8869. MISC_HOST_CTRL_CHIPREV_SHIFT);
  8870. /* Wrong chip ID in 5752 A0. This code can be removed later
  8871. * as A0 is not in production.
  8872. */
  8873. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  8874. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  8875. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  8876. * we need to disable memory and use config. cycles
  8877. * only to access all registers. The 5702/03 chips
  8878. * can mistakenly decode the special cycles from the
  8879. * ICH chipsets as memory write cycles, causing corruption
  8880. * of register and memory space. Only certain ICH bridges
  8881. * will drive special cycles with non-zero data during the
  8882. * address phase which can fall within the 5703's address
  8883. * range. This is not an ICH bug as the PCI spec allows
  8884. * non-zero address during special cycles. However, only
  8885. * these ICH bridges are known to drive non-zero addresses
  8886. * during special cycles.
  8887. *
  8888. * Since special cycles do not cross PCI bridges, we only
  8889. * enable this workaround if the 5703 is on the secondary
  8890. * bus of these ICH bridges.
  8891. */
  8892. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  8893. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  8894. static struct tg3_dev_id {
  8895. u32 vendor;
  8896. u32 device;
  8897. u32 rev;
  8898. } ich_chipsets[] = {
  8899. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  8900. PCI_ANY_ID },
  8901. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  8902. PCI_ANY_ID },
  8903. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  8904. 0xa },
  8905. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  8906. PCI_ANY_ID },
  8907. { },
  8908. };
  8909. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  8910. struct pci_dev *bridge = NULL;
  8911. while (pci_id->vendor != 0) {
  8912. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  8913. bridge);
  8914. if (!bridge) {
  8915. pci_id++;
  8916. continue;
  8917. }
  8918. if (pci_id->rev != PCI_ANY_ID) {
  8919. if (bridge->revision > pci_id->rev)
  8920. continue;
  8921. }
  8922. if (bridge->subordinate &&
  8923. (bridge->subordinate->number ==
  8924. tp->pdev->bus->number)) {
  8925. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  8926. pci_dev_put(bridge);
  8927. break;
  8928. }
  8929. }
  8930. }
  8931. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  8932. * DMA addresses > 40-bit. This bridge may have other additional
  8933. * 57xx devices behind it in some 4-port NIC designs for example.
  8934. * Any tg3 device found behind the bridge will also need the 40-bit
  8935. * DMA workaround.
  8936. */
  8937. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  8938. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  8939. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  8940. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8941. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  8942. }
  8943. else {
  8944. struct pci_dev *bridge = NULL;
  8945. do {
  8946. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  8947. PCI_DEVICE_ID_SERVERWORKS_EPB,
  8948. bridge);
  8949. if (bridge && bridge->subordinate &&
  8950. (bridge->subordinate->number <=
  8951. tp->pdev->bus->number) &&
  8952. (bridge->subordinate->subordinate >=
  8953. tp->pdev->bus->number)) {
  8954. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  8955. pci_dev_put(bridge);
  8956. break;
  8957. }
  8958. } while (bridge);
  8959. }
  8960. /* Initialize misc host control in PCI block. */
  8961. tp->misc_host_ctrl |= (misc_ctrl_reg &
  8962. MISC_HOST_CTRL_CHIPREV);
  8963. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  8964. tp->misc_host_ctrl);
  8965. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  8966. &cacheline_sz_reg);
  8967. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  8968. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  8969. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  8970. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  8971. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  8972. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  8973. tp->pdev_peer = tg3_find_peer(tp);
  8974. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  8975. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  8976. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8977. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8978. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  8979. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  8980. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  8981. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  8982. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  8983. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  8984. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  8985. tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
  8986. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
  8987. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
  8988. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
  8989. tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
  8990. tp->pdev_peer == tp->pdev))
  8991. tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
  8992. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  8993. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8994. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8995. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  8996. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  8997. } else {
  8998. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  8999. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9000. ASIC_REV_5750 &&
  9001. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  9002. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  9003. }
  9004. }
  9005. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
  9006. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
  9007. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
  9008. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
  9009. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787 &&
  9010. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9011. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  9012. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  9013. if (pcie_cap != 0) {
  9014. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  9015. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9016. u16 lnkctl;
  9017. pci_read_config_word(tp->pdev,
  9018. pcie_cap + PCI_EXP_LNKCTL,
  9019. &lnkctl);
  9020. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  9021. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  9022. }
  9023. }
  9024. /* If we have an AMD 762 or VIA K8T800 chipset, write
  9025. * reordering to the mailbox registers done by the host
  9026. * controller can cause major troubles. We read back from
  9027. * every mailbox register write to force the writes to be
  9028. * posted to the chip in order.
  9029. */
  9030. if (pci_dev_present(write_reorder_chipsets) &&
  9031. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9032. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  9033. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9034. tp->pci_lat_timer < 64) {
  9035. tp->pci_lat_timer = 64;
  9036. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  9037. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  9038. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  9039. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  9040. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9041. cacheline_sz_reg);
  9042. }
  9043. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9044. &pci_state_reg);
  9045. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  9046. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  9047. /* If this is a 5700 BX chipset, and we are in PCI-X
  9048. * mode, enable register write workaround.
  9049. *
  9050. * The workaround is to use indirect register accesses
  9051. * for all chip writes not to mailbox registers.
  9052. */
  9053. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  9054. u32 pm_reg;
  9055. u16 pci_cmd;
  9056. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9057. /* The chip can have it's power management PCI config
  9058. * space registers clobbered due to this bug.
  9059. * So explicitly force the chip into D0 here.
  9060. */
  9061. pci_read_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9062. &pm_reg);
  9063. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9064. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9065. pci_write_config_dword(tp->pdev, TG3PCI_PM_CTRL_STAT,
  9066. pm_reg);
  9067. /* Also, force SERR#/PERR# in PCI command. */
  9068. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9069. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9070. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9071. }
  9072. }
  9073. /* 5700 BX chips need to have their TX producer index mailboxes
  9074. * written twice to workaround a bug.
  9075. */
  9076. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9077. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9078. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9079. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9080. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9081. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9082. /* Chip-specific fixup from Broadcom driver */
  9083. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9084. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9085. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9086. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9087. }
  9088. /* Default fast path register access methods */
  9089. tp->read32 = tg3_read32;
  9090. tp->write32 = tg3_write32;
  9091. tp->read32_mbox = tg3_read32;
  9092. tp->write32_mbox = tg3_write32;
  9093. tp->write32_tx_mbox = tg3_write32;
  9094. tp->write32_rx_mbox = tg3_write32;
  9095. /* Various workaround register access methods */
  9096. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9097. tp->write32 = tg3_write_indirect_reg32;
  9098. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9099. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9100. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
  9101. /*
  9102. * Back to back register writes can cause problems on these
  9103. * chips, the workaround is to read back all reg writes
  9104. * except those to mailbox regs.
  9105. *
  9106. * See tg3_write_indirect_reg32().
  9107. */
  9108. tp->write32 = tg3_write_flush_reg32;
  9109. }
  9110. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9111. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9112. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9113. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9114. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9115. }
  9116. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9117. tp->read32 = tg3_read_indirect_reg32;
  9118. tp->write32 = tg3_write_indirect_reg32;
  9119. tp->read32_mbox = tg3_read_indirect_mbox;
  9120. tp->write32_mbox = tg3_write_indirect_mbox;
  9121. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9122. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9123. iounmap(tp->regs);
  9124. tp->regs = NULL;
  9125. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9126. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9127. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9128. }
  9129. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9130. tp->read32_mbox = tg3_read32_mbox_5906;
  9131. tp->write32_mbox = tg3_write32_mbox_5906;
  9132. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9133. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9134. }
  9135. if (tp->write32 == tg3_write_indirect_reg32 ||
  9136. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9137. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9138. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9139. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9140. /* Get eeprom hw config before calling tg3_set_power_state().
  9141. * In particular, the TG3_FLG2_IS_NIC flag must be
  9142. * determined before calling tg3_set_power_state() so that
  9143. * we know whether or not to switch out of Vaux power.
  9144. * When the flag is set, it means that GPIO1 is used for eeprom
  9145. * write protect and also implies that it is a LOM where GPIOs
  9146. * are not used to switch power.
  9147. */
  9148. tg3_get_eeprom_hw_cfg(tp);
  9149. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9150. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9151. * It is also used as eeprom write protect on LOMs.
  9152. */
  9153. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9154. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9155. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9156. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9157. GRC_LCLCTRL_GPIO_OUTPUT1);
  9158. /* Unused GPIO3 must be driven as output on 5752 because there
  9159. * are no pull-up resistors on unused GPIO pins.
  9160. */
  9161. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9162. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9163. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9164. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9165. /* Force the chip into D0. */
  9166. err = tg3_set_power_state(tp, PCI_D0);
  9167. if (err) {
  9168. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9169. pci_name(tp->pdev));
  9170. return err;
  9171. }
  9172. /* 5700 B0 chips do not support checksumming correctly due
  9173. * to hardware bugs.
  9174. */
  9175. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9176. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9177. /* Derive initial jumbo mode from MTU assigned in
  9178. * ether_setup() via the alloc_etherdev() call
  9179. */
  9180. if (tp->dev->mtu > ETH_DATA_LEN &&
  9181. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9182. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9183. /* Determine WakeOnLan speed to use. */
  9184. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9185. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9186. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9187. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9188. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9189. } else {
  9190. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9191. }
  9192. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9193. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9194. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9195. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9196. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9197. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9198. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9199. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9200. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9201. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9202. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9203. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9204. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9205. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9206. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9207. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
  9208. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9209. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9210. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9211. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9212. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9213. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9214. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9215. }
  9216. tp->coalesce_mode = 0;
  9217. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9218. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9219. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9220. /* Initialize MAC MI mode, polling disabled. */
  9221. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9222. udelay(80);
  9223. /* Initialize data/descriptor byte/word swapping. */
  9224. val = tr32(GRC_MODE);
  9225. val &= GRC_MODE_HOST_STACKUP;
  9226. tw32(GRC_MODE, val | tp->grc_mode);
  9227. tg3_switch_clocks(tp);
  9228. /* Clear this out for sanity. */
  9229. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9230. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9231. &pci_state_reg);
  9232. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9233. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9234. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9235. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9236. chiprevid == CHIPREV_ID_5701_B0 ||
  9237. chiprevid == CHIPREV_ID_5701_B2 ||
  9238. chiprevid == CHIPREV_ID_5701_B5) {
  9239. void __iomem *sram_base;
  9240. /* Write some dummy words into the SRAM status block
  9241. * area, see if it reads back correctly. If the return
  9242. * value is bad, force enable the PCIX workaround.
  9243. */
  9244. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  9245. writel(0x00000000, sram_base);
  9246. writel(0x00000000, sram_base + 4);
  9247. writel(0xffffffff, sram_base + 4);
  9248. if (readl(sram_base) != 0x00000000)
  9249. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9250. }
  9251. }
  9252. udelay(50);
  9253. tg3_nvram_init(tp);
  9254. grc_misc_cfg = tr32(GRC_MISC_CFG);
  9255. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  9256. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9257. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  9258. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  9259. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  9260. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  9261. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  9262. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  9263. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  9264. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  9265. HOSTCC_MODE_CLRTICK_TXBD);
  9266. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  9267. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9268. tp->misc_host_ctrl);
  9269. }
  9270. /* these are limited to 10/100 only */
  9271. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9272. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  9273. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  9274. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9275. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  9276. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  9277. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  9278. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  9279. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  9280. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  9281. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  9282. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9283. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  9284. err = tg3_phy_probe(tp);
  9285. if (err) {
  9286. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  9287. pci_name(tp->pdev), err);
  9288. /* ... but do not return immediately ... */
  9289. }
  9290. tg3_read_partno(tp);
  9291. tg3_read_fw_ver(tp);
  9292. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  9293. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9294. } else {
  9295. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9296. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  9297. else
  9298. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  9299. }
  9300. /* 5700 {AX,BX} chips have a broken status block link
  9301. * change bit implementation, so we must use the
  9302. * status register in those cases.
  9303. */
  9304. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  9305. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  9306. else
  9307. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  9308. /* The led_ctrl is set during tg3_phy_probe, here we might
  9309. * have to force the link status polling mechanism based
  9310. * upon subsystem IDs.
  9311. */
  9312. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  9313. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9314. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  9315. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  9316. TG3_FLAG_USE_LINKCHG_REG);
  9317. }
  9318. /* For all SERDES we poll the MAC status register. */
  9319. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  9320. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  9321. else
  9322. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  9323. /* All chips before 5787 can get confused if TX buffers
  9324. * straddle the 4GB address boundary in some cases.
  9325. */
  9326. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9327. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9328. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9329. tp->dev->hard_start_xmit = tg3_start_xmit;
  9330. else
  9331. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  9332. tp->rx_offset = 2;
  9333. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  9334. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  9335. tp->rx_offset = 0;
  9336. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  9337. /* Increment the rx prod index on the rx std ring by at most
  9338. * 8 for these chips to workaround hw errata.
  9339. */
  9340. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9341. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9342. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9343. tp->rx_std_max_post = 8;
  9344. /* By default, disable wake-on-lan. User can change this
  9345. * using ETHTOOL_SWOL.
  9346. */
  9347. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  9348. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND)
  9349. tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) &
  9350. PCIE_PWR_MGMT_L1_THRESH_MSK;
  9351. return err;
  9352. }
  9353. #ifdef CONFIG_SPARC
  9354. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  9355. {
  9356. struct net_device *dev = tp->dev;
  9357. struct pci_dev *pdev = tp->pdev;
  9358. struct device_node *dp = pci_device_to_OF_node(pdev);
  9359. const unsigned char *addr;
  9360. int len;
  9361. addr = of_get_property(dp, "local-mac-address", &len);
  9362. if (addr && len == 6) {
  9363. memcpy(dev->dev_addr, addr, 6);
  9364. memcpy(dev->perm_addr, dev->dev_addr, 6);
  9365. return 0;
  9366. }
  9367. return -ENODEV;
  9368. }
  9369. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  9370. {
  9371. struct net_device *dev = tp->dev;
  9372. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  9373. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  9374. return 0;
  9375. }
  9376. #endif
  9377. static int __devinit tg3_get_device_address(struct tg3 *tp)
  9378. {
  9379. struct net_device *dev = tp->dev;
  9380. u32 hi, lo, mac_offset;
  9381. int addr_ok = 0;
  9382. #ifdef CONFIG_SPARC
  9383. if (!tg3_get_macaddr_sparc(tp))
  9384. return 0;
  9385. #endif
  9386. mac_offset = 0x7c;
  9387. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9388. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9389. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  9390. mac_offset = 0xcc;
  9391. if (tg3_nvram_lock(tp))
  9392. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  9393. else
  9394. tg3_nvram_unlock(tp);
  9395. }
  9396. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9397. mac_offset = 0x10;
  9398. /* First try to get it from MAC address mailbox. */
  9399. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  9400. if ((hi >> 16) == 0x484b) {
  9401. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9402. dev->dev_addr[1] = (hi >> 0) & 0xff;
  9403. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  9404. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9405. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9406. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9407. dev->dev_addr[5] = (lo >> 0) & 0xff;
  9408. /* Some old bootcode may report a 0 MAC address in SRAM */
  9409. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  9410. }
  9411. if (!addr_ok) {
  9412. /* Next, try NVRAM. */
  9413. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  9414. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  9415. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  9416. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  9417. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  9418. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  9419. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  9420. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  9421. }
  9422. /* Finally just fetch it out of the MAC control regs. */
  9423. else {
  9424. hi = tr32(MAC_ADDR_0_HIGH);
  9425. lo = tr32(MAC_ADDR_0_LOW);
  9426. dev->dev_addr[5] = lo & 0xff;
  9427. dev->dev_addr[4] = (lo >> 8) & 0xff;
  9428. dev->dev_addr[3] = (lo >> 16) & 0xff;
  9429. dev->dev_addr[2] = (lo >> 24) & 0xff;
  9430. dev->dev_addr[1] = hi & 0xff;
  9431. dev->dev_addr[0] = (hi >> 8) & 0xff;
  9432. }
  9433. }
  9434. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  9435. #ifdef CONFIG_SPARC64
  9436. if (!tg3_get_default_macaddr_sparc(tp))
  9437. return 0;
  9438. #endif
  9439. return -EINVAL;
  9440. }
  9441. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  9442. return 0;
  9443. }
  9444. #define BOUNDARY_SINGLE_CACHELINE 1
  9445. #define BOUNDARY_MULTI_CACHELINE 2
  9446. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  9447. {
  9448. int cacheline_size;
  9449. u8 byte;
  9450. int goal;
  9451. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  9452. if (byte == 0)
  9453. cacheline_size = 1024;
  9454. else
  9455. cacheline_size = (int) byte * 4;
  9456. /* On 5703 and later chips, the boundary bits have no
  9457. * effect.
  9458. */
  9459. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9460. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  9461. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9462. goto out;
  9463. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  9464. goal = BOUNDARY_MULTI_CACHELINE;
  9465. #else
  9466. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  9467. goal = BOUNDARY_SINGLE_CACHELINE;
  9468. #else
  9469. goal = 0;
  9470. #endif
  9471. #endif
  9472. if (!goal)
  9473. goto out;
  9474. /* PCI controllers on most RISC systems tend to disconnect
  9475. * when a device tries to burst across a cache-line boundary.
  9476. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  9477. *
  9478. * Unfortunately, for PCI-E there are only limited
  9479. * write-side controls for this, and thus for reads
  9480. * we will still get the disconnects. We'll also waste
  9481. * these PCI cycles for both read and write for chips
  9482. * other than 5700 and 5701 which do not implement the
  9483. * boundary bits.
  9484. */
  9485. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9486. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  9487. switch (cacheline_size) {
  9488. case 16:
  9489. case 32:
  9490. case 64:
  9491. case 128:
  9492. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9493. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  9494. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  9495. } else {
  9496. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9497. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9498. }
  9499. break;
  9500. case 256:
  9501. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  9502. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  9503. break;
  9504. default:
  9505. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  9506. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  9507. break;
  9508. };
  9509. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9510. switch (cacheline_size) {
  9511. case 16:
  9512. case 32:
  9513. case 64:
  9514. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9515. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9516. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  9517. break;
  9518. }
  9519. /* fallthrough */
  9520. case 128:
  9521. default:
  9522. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  9523. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  9524. break;
  9525. };
  9526. } else {
  9527. switch (cacheline_size) {
  9528. case 16:
  9529. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9530. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  9531. DMA_RWCTRL_WRITE_BNDRY_16);
  9532. break;
  9533. }
  9534. /* fallthrough */
  9535. case 32:
  9536. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9537. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  9538. DMA_RWCTRL_WRITE_BNDRY_32);
  9539. break;
  9540. }
  9541. /* fallthrough */
  9542. case 64:
  9543. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9544. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  9545. DMA_RWCTRL_WRITE_BNDRY_64);
  9546. break;
  9547. }
  9548. /* fallthrough */
  9549. case 128:
  9550. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  9551. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  9552. DMA_RWCTRL_WRITE_BNDRY_128);
  9553. break;
  9554. }
  9555. /* fallthrough */
  9556. case 256:
  9557. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  9558. DMA_RWCTRL_WRITE_BNDRY_256);
  9559. break;
  9560. case 512:
  9561. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  9562. DMA_RWCTRL_WRITE_BNDRY_512);
  9563. break;
  9564. case 1024:
  9565. default:
  9566. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  9567. DMA_RWCTRL_WRITE_BNDRY_1024);
  9568. break;
  9569. };
  9570. }
  9571. out:
  9572. return val;
  9573. }
  9574. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  9575. {
  9576. struct tg3_internal_buffer_desc test_desc;
  9577. u32 sram_dma_descs;
  9578. int i, ret;
  9579. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  9580. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  9581. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  9582. tw32(RDMAC_STATUS, 0);
  9583. tw32(WDMAC_STATUS, 0);
  9584. tw32(BUFMGR_MODE, 0);
  9585. tw32(FTQ_RESET, 0);
  9586. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  9587. test_desc.addr_lo = buf_dma & 0xffffffff;
  9588. test_desc.nic_mbuf = 0x00002100;
  9589. test_desc.len = size;
  9590. /*
  9591. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  9592. * the *second* time the tg3 driver was getting loaded after an
  9593. * initial scan.
  9594. *
  9595. * Broadcom tells me:
  9596. * ...the DMA engine is connected to the GRC block and a DMA
  9597. * reset may affect the GRC block in some unpredictable way...
  9598. * The behavior of resets to individual blocks has not been tested.
  9599. *
  9600. * Broadcom noted the GRC reset will also reset all sub-components.
  9601. */
  9602. if (to_device) {
  9603. test_desc.cqid_sqid = (13 << 8) | 2;
  9604. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  9605. udelay(40);
  9606. } else {
  9607. test_desc.cqid_sqid = (16 << 8) | 7;
  9608. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  9609. udelay(40);
  9610. }
  9611. test_desc.flags = 0x00000005;
  9612. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  9613. u32 val;
  9614. val = *(((u32 *)&test_desc) + i);
  9615. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  9616. sram_dma_descs + (i * sizeof(u32)));
  9617. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  9618. }
  9619. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9620. if (to_device) {
  9621. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  9622. } else {
  9623. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  9624. }
  9625. ret = -ENODEV;
  9626. for (i = 0; i < 40; i++) {
  9627. u32 val;
  9628. if (to_device)
  9629. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  9630. else
  9631. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  9632. if ((val & 0xffff) == sram_dma_descs) {
  9633. ret = 0;
  9634. break;
  9635. }
  9636. udelay(100);
  9637. }
  9638. return ret;
  9639. }
  9640. #define TEST_BUFFER_SIZE 0x2000
  9641. static int __devinit tg3_test_dma(struct tg3 *tp)
  9642. {
  9643. dma_addr_t buf_dma;
  9644. u32 *buf, saved_dma_rwctrl;
  9645. int ret;
  9646. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  9647. if (!buf) {
  9648. ret = -ENOMEM;
  9649. goto out_nofree;
  9650. }
  9651. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  9652. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  9653. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  9654. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9655. /* DMA read watermark not used on PCIE */
  9656. tp->dma_rwctrl |= 0x00180000;
  9657. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  9658. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  9659. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  9660. tp->dma_rwctrl |= 0x003f0000;
  9661. else
  9662. tp->dma_rwctrl |= 0x003f000f;
  9663. } else {
  9664. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9665. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  9666. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  9667. u32 read_water = 0x7;
  9668. /* If the 5704 is behind the EPB bridge, we can
  9669. * do the less restrictive ONE_DMA workaround for
  9670. * better performance.
  9671. */
  9672. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  9673. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9674. tp->dma_rwctrl |= 0x8000;
  9675. else if (ccval == 0x6 || ccval == 0x7)
  9676. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  9677. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  9678. read_water = 4;
  9679. /* Set bit 23 to enable PCIX hw bug fix */
  9680. tp->dma_rwctrl |=
  9681. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  9682. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  9683. (1 << 23);
  9684. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  9685. /* 5780 always in PCIX mode */
  9686. tp->dma_rwctrl |= 0x00144000;
  9687. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9688. /* 5714 always in PCIX mode */
  9689. tp->dma_rwctrl |= 0x00148000;
  9690. } else {
  9691. tp->dma_rwctrl |= 0x001b000f;
  9692. }
  9693. }
  9694. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  9695. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  9696. tp->dma_rwctrl &= 0xfffffff0;
  9697. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9698. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  9699. /* Remove this if it causes problems for some boards. */
  9700. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  9701. /* On 5700/5701 chips, we need to set this bit.
  9702. * Otherwise the chip will issue cacheline transactions
  9703. * to streamable DMA memory with not all the byte
  9704. * enables turned on. This is an error on several
  9705. * RISC PCI controllers, in particular sparc64.
  9706. *
  9707. * On 5703/5704 chips, this bit has been reassigned
  9708. * a different meaning. In particular, it is used
  9709. * on those chips to enable a PCI-X workaround.
  9710. */
  9711. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  9712. }
  9713. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9714. #if 0
  9715. /* Unneeded, already done by tg3_get_invariants. */
  9716. tg3_switch_clocks(tp);
  9717. #endif
  9718. ret = 0;
  9719. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  9720. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  9721. goto out;
  9722. /* It is best to perform DMA test with maximum write burst size
  9723. * to expose the 5700/5701 write DMA bug.
  9724. */
  9725. saved_dma_rwctrl = tp->dma_rwctrl;
  9726. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9727. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9728. while (1) {
  9729. u32 *p = buf, i;
  9730. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  9731. p[i] = i;
  9732. /* Send the buffer to the chip. */
  9733. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  9734. if (ret) {
  9735. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  9736. break;
  9737. }
  9738. #if 0
  9739. /* validate data reached card RAM correctly. */
  9740. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9741. u32 val;
  9742. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  9743. if (le32_to_cpu(val) != p[i]) {
  9744. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  9745. /* ret = -ENODEV here? */
  9746. }
  9747. p[i] = 0;
  9748. }
  9749. #endif
  9750. /* Now read it back. */
  9751. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  9752. if (ret) {
  9753. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  9754. break;
  9755. }
  9756. /* Verify it. */
  9757. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  9758. if (p[i] == i)
  9759. continue;
  9760. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9761. DMA_RWCTRL_WRITE_BNDRY_16) {
  9762. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9763. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9764. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9765. break;
  9766. } else {
  9767. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  9768. ret = -ENODEV;
  9769. goto out;
  9770. }
  9771. }
  9772. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  9773. /* Success. */
  9774. ret = 0;
  9775. break;
  9776. }
  9777. }
  9778. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  9779. DMA_RWCTRL_WRITE_BNDRY_16) {
  9780. static struct pci_device_id dma_wait_state_chipsets[] = {
  9781. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  9782. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  9783. { },
  9784. };
  9785. /* DMA test passed without adjusting DMA boundary,
  9786. * now look for chipsets that are known to expose the
  9787. * DMA bug without failing the test.
  9788. */
  9789. if (pci_dev_present(dma_wait_state_chipsets)) {
  9790. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  9791. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  9792. }
  9793. else
  9794. /* Safe to use the calculated DMA boundary. */
  9795. tp->dma_rwctrl = saved_dma_rwctrl;
  9796. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  9797. }
  9798. out:
  9799. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  9800. out_nofree:
  9801. return ret;
  9802. }
  9803. static void __devinit tg3_init_link_config(struct tg3 *tp)
  9804. {
  9805. tp->link_config.advertising =
  9806. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9807. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9808. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  9809. ADVERTISED_Autoneg | ADVERTISED_MII);
  9810. tp->link_config.speed = SPEED_INVALID;
  9811. tp->link_config.duplex = DUPLEX_INVALID;
  9812. tp->link_config.autoneg = AUTONEG_ENABLE;
  9813. tp->link_config.active_speed = SPEED_INVALID;
  9814. tp->link_config.active_duplex = DUPLEX_INVALID;
  9815. tp->link_config.phy_is_low_power = 0;
  9816. tp->link_config.orig_speed = SPEED_INVALID;
  9817. tp->link_config.orig_duplex = DUPLEX_INVALID;
  9818. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  9819. }
  9820. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  9821. {
  9822. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9823. tp->bufmgr_config.mbuf_read_dma_low_water =
  9824. DEFAULT_MB_RDMA_LOW_WATER_5705;
  9825. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9826. DEFAULT_MB_MACRX_LOW_WATER_5705;
  9827. tp->bufmgr_config.mbuf_high_water =
  9828. DEFAULT_MB_HIGH_WATER_5705;
  9829. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9830. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9831. DEFAULT_MB_MACRX_LOW_WATER_5906;
  9832. tp->bufmgr_config.mbuf_high_water =
  9833. DEFAULT_MB_HIGH_WATER_5906;
  9834. }
  9835. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9836. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  9837. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9838. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  9839. tp->bufmgr_config.mbuf_high_water_jumbo =
  9840. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  9841. } else {
  9842. tp->bufmgr_config.mbuf_read_dma_low_water =
  9843. DEFAULT_MB_RDMA_LOW_WATER;
  9844. tp->bufmgr_config.mbuf_mac_rx_low_water =
  9845. DEFAULT_MB_MACRX_LOW_WATER;
  9846. tp->bufmgr_config.mbuf_high_water =
  9847. DEFAULT_MB_HIGH_WATER;
  9848. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  9849. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  9850. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  9851. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  9852. tp->bufmgr_config.mbuf_high_water_jumbo =
  9853. DEFAULT_MB_HIGH_WATER_JUMBO;
  9854. }
  9855. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  9856. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  9857. }
  9858. static char * __devinit tg3_phy_string(struct tg3 *tp)
  9859. {
  9860. switch (tp->phy_id & PHY_ID_MASK) {
  9861. case PHY_ID_BCM5400: return "5400";
  9862. case PHY_ID_BCM5401: return "5401";
  9863. case PHY_ID_BCM5411: return "5411";
  9864. case PHY_ID_BCM5701: return "5701";
  9865. case PHY_ID_BCM5703: return "5703";
  9866. case PHY_ID_BCM5704: return "5704";
  9867. case PHY_ID_BCM5705: return "5705";
  9868. case PHY_ID_BCM5750: return "5750";
  9869. case PHY_ID_BCM5752: return "5752";
  9870. case PHY_ID_BCM5714: return "5714";
  9871. case PHY_ID_BCM5780: return "5780";
  9872. case PHY_ID_BCM5755: return "5755";
  9873. case PHY_ID_BCM5787: return "5787";
  9874. case PHY_ID_BCM5756: return "5722/5756";
  9875. case PHY_ID_BCM5906: return "5906";
  9876. case PHY_ID_BCM8002: return "8002/serdes";
  9877. case 0: return "serdes";
  9878. default: return "unknown";
  9879. };
  9880. }
  9881. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  9882. {
  9883. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9884. strcpy(str, "PCI Express");
  9885. return str;
  9886. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  9887. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  9888. strcpy(str, "PCIX:");
  9889. if ((clock_ctrl == 7) ||
  9890. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  9891. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  9892. strcat(str, "133MHz");
  9893. else if (clock_ctrl == 0)
  9894. strcat(str, "33MHz");
  9895. else if (clock_ctrl == 2)
  9896. strcat(str, "50MHz");
  9897. else if (clock_ctrl == 4)
  9898. strcat(str, "66MHz");
  9899. else if (clock_ctrl == 6)
  9900. strcat(str, "100MHz");
  9901. } else {
  9902. strcpy(str, "PCI:");
  9903. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  9904. strcat(str, "66MHz");
  9905. else
  9906. strcat(str, "33MHz");
  9907. }
  9908. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  9909. strcat(str, ":32-bit");
  9910. else
  9911. strcat(str, ":64-bit");
  9912. return str;
  9913. }
  9914. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  9915. {
  9916. struct pci_dev *peer;
  9917. unsigned int func, devnr = tp->pdev->devfn & ~7;
  9918. for (func = 0; func < 8; func++) {
  9919. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  9920. if (peer && peer != tp->pdev)
  9921. break;
  9922. pci_dev_put(peer);
  9923. }
  9924. /* 5704 can be configured in single-port mode, set peer to
  9925. * tp->pdev in that case.
  9926. */
  9927. if (!peer) {
  9928. peer = tp->pdev;
  9929. return peer;
  9930. }
  9931. /*
  9932. * We don't need to keep the refcount elevated; there's no way
  9933. * to remove one half of this device without removing the other
  9934. */
  9935. pci_dev_put(peer);
  9936. return peer;
  9937. }
  9938. static void __devinit tg3_init_coal(struct tg3 *tp)
  9939. {
  9940. struct ethtool_coalesce *ec = &tp->coal;
  9941. memset(ec, 0, sizeof(*ec));
  9942. ec->cmd = ETHTOOL_GCOALESCE;
  9943. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  9944. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  9945. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  9946. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  9947. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  9948. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  9949. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  9950. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  9951. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  9952. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  9953. HOSTCC_MODE_CLRTICK_TXBD)) {
  9954. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  9955. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  9956. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  9957. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  9958. }
  9959. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9960. ec->rx_coalesce_usecs_irq = 0;
  9961. ec->tx_coalesce_usecs_irq = 0;
  9962. ec->stats_block_coalesce_usecs = 0;
  9963. }
  9964. }
  9965. static int __devinit tg3_init_one(struct pci_dev *pdev,
  9966. const struct pci_device_id *ent)
  9967. {
  9968. static int tg3_version_printed = 0;
  9969. unsigned long tg3reg_base, tg3reg_len;
  9970. struct net_device *dev;
  9971. struct tg3 *tp;
  9972. int i, err, pm_cap;
  9973. char str[40];
  9974. u64 dma_mask, persist_dma_mask;
  9975. if (tg3_version_printed++ == 0)
  9976. printk(KERN_INFO "%s", version);
  9977. err = pci_enable_device(pdev);
  9978. if (err) {
  9979. printk(KERN_ERR PFX "Cannot enable PCI device, "
  9980. "aborting.\n");
  9981. return err;
  9982. }
  9983. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9984. printk(KERN_ERR PFX "Cannot find proper PCI device "
  9985. "base address, aborting.\n");
  9986. err = -ENODEV;
  9987. goto err_out_disable_pdev;
  9988. }
  9989. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  9990. if (err) {
  9991. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  9992. "aborting.\n");
  9993. goto err_out_disable_pdev;
  9994. }
  9995. pci_set_master(pdev);
  9996. /* Find power-management capability. */
  9997. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9998. if (pm_cap == 0) {
  9999. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  10000. "aborting.\n");
  10001. err = -EIO;
  10002. goto err_out_free_res;
  10003. }
  10004. tg3reg_base = pci_resource_start(pdev, 0);
  10005. tg3reg_len = pci_resource_len(pdev, 0);
  10006. dev = alloc_etherdev(sizeof(*tp));
  10007. if (!dev) {
  10008. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  10009. err = -ENOMEM;
  10010. goto err_out_free_res;
  10011. }
  10012. SET_MODULE_OWNER(dev);
  10013. SET_NETDEV_DEV(dev, &pdev->dev);
  10014. #if TG3_VLAN_TAG_USED
  10015. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  10016. dev->vlan_rx_register = tg3_vlan_rx_register;
  10017. #endif
  10018. tp = netdev_priv(dev);
  10019. tp->pdev = pdev;
  10020. tp->dev = dev;
  10021. tp->pm_cap = pm_cap;
  10022. tp->mac_mode = TG3_DEF_MAC_MODE;
  10023. tp->rx_mode = TG3_DEF_RX_MODE;
  10024. tp->tx_mode = TG3_DEF_TX_MODE;
  10025. tp->mi_mode = MAC_MI_MODE_BASE;
  10026. if (tg3_debug > 0)
  10027. tp->msg_enable = tg3_debug;
  10028. else
  10029. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  10030. /* The word/byte swap controls here control register access byte
  10031. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  10032. * setting below.
  10033. */
  10034. tp->misc_host_ctrl =
  10035. MISC_HOST_CTRL_MASK_PCI_INT |
  10036. MISC_HOST_CTRL_WORD_SWAP |
  10037. MISC_HOST_CTRL_INDIR_ACCESS |
  10038. MISC_HOST_CTRL_PCISTATE_RW;
  10039. /* The NONFRM (non-frame) byte/word swap controls take effect
  10040. * on descriptor entries, anything which isn't packet data.
  10041. *
  10042. * The StrongARM chips on the board (one for tx, one for rx)
  10043. * are running in big-endian mode.
  10044. */
  10045. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  10046. GRC_MODE_WSWAP_NONFRM_DATA);
  10047. #ifdef __BIG_ENDIAN
  10048. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  10049. #endif
  10050. spin_lock_init(&tp->lock);
  10051. spin_lock_init(&tp->indirect_lock);
  10052. INIT_WORK(&tp->reset_task, tg3_reset_task);
  10053. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10054. if (tp->regs == 0UL) {
  10055. printk(KERN_ERR PFX "Cannot map device registers, "
  10056. "aborting.\n");
  10057. err = -ENOMEM;
  10058. goto err_out_free_dev;
  10059. }
  10060. tg3_init_link_config(tp);
  10061. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10062. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10063. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10064. dev->open = tg3_open;
  10065. dev->stop = tg3_close;
  10066. dev->get_stats = tg3_get_stats;
  10067. dev->set_multicast_list = tg3_set_rx_mode;
  10068. dev->set_mac_address = tg3_set_mac_addr;
  10069. dev->do_ioctl = tg3_ioctl;
  10070. dev->tx_timeout = tg3_tx_timeout;
  10071. dev->poll = tg3_poll;
  10072. dev->ethtool_ops = &tg3_ethtool_ops;
  10073. dev->weight = 64;
  10074. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10075. dev->change_mtu = tg3_change_mtu;
  10076. dev->irq = pdev->irq;
  10077. #ifdef CONFIG_NET_POLL_CONTROLLER
  10078. dev->poll_controller = tg3_poll_controller;
  10079. #endif
  10080. err = tg3_get_invariants(tp);
  10081. if (err) {
  10082. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10083. "aborting.\n");
  10084. goto err_out_iounmap;
  10085. }
  10086. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10087. * device behind the EPB cannot support DMA addresses > 40-bit.
  10088. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10089. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10090. * do DMA address check in tg3_start_xmit().
  10091. */
  10092. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10093. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10094. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10095. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10096. #ifdef CONFIG_HIGHMEM
  10097. dma_mask = DMA_64BIT_MASK;
  10098. #endif
  10099. } else
  10100. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10101. /* Configure DMA attributes. */
  10102. if (dma_mask > DMA_32BIT_MASK) {
  10103. err = pci_set_dma_mask(pdev, dma_mask);
  10104. if (!err) {
  10105. dev->features |= NETIF_F_HIGHDMA;
  10106. err = pci_set_consistent_dma_mask(pdev,
  10107. persist_dma_mask);
  10108. if (err < 0) {
  10109. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10110. "DMA for consistent allocations\n");
  10111. goto err_out_iounmap;
  10112. }
  10113. }
  10114. }
  10115. if (err || dma_mask == DMA_32BIT_MASK) {
  10116. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10117. if (err) {
  10118. printk(KERN_ERR PFX "No usable DMA configuration, "
  10119. "aborting.\n");
  10120. goto err_out_iounmap;
  10121. }
  10122. }
  10123. tg3_init_bufmgr_config(tp);
  10124. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10125. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10126. }
  10127. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10128. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10129. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10130. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10131. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10132. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10133. } else {
  10134. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10135. }
  10136. /* TSO is on by default on chips that support hardware TSO.
  10137. * Firmware TSO on older chips gives lower performance, so it
  10138. * is off by default, but can be enabled using ethtool.
  10139. */
  10140. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10141. dev->features |= NETIF_F_TSO;
  10142. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10143. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10144. dev->features |= NETIF_F_TSO6;
  10145. }
  10146. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10147. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10148. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10149. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10150. tp->rx_pending = 63;
  10151. }
  10152. err = tg3_get_device_address(tp);
  10153. if (err) {
  10154. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10155. "aborting.\n");
  10156. goto err_out_iounmap;
  10157. }
  10158. /*
  10159. * Reset chip in case UNDI or EFI driver did not shutdown
  10160. * DMA self test will enable WDMAC and we'll see (spurious)
  10161. * pending DMA on the PCI bus at that point.
  10162. */
  10163. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10164. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10165. pci_save_state(tp->pdev);
  10166. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10167. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10168. }
  10169. err = tg3_test_dma(tp);
  10170. if (err) {
  10171. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10172. goto err_out_iounmap;
  10173. }
  10174. /* Tigon3 can do ipv4 only... and some chips have buggy
  10175. * checksumming.
  10176. */
  10177. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10178. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  10179. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10180. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
  10181. dev->features |= NETIF_F_IPV6_CSUM;
  10182. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10183. } else
  10184. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10185. /* flow control autonegotiation is default behavior */
  10186. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10187. tg3_init_coal(tp);
  10188. /* Now that we have fully setup the chip, save away a snapshot
  10189. * of the PCI config space. We need to restore this after
  10190. * GRC_MISC_CFG core clock resets and some resume events.
  10191. */
  10192. pci_save_state(tp->pdev);
  10193. pci_set_drvdata(pdev, dev);
  10194. err = register_netdev(dev);
  10195. if (err) {
  10196. printk(KERN_ERR PFX "Cannot register net device, "
  10197. "aborting.\n");
  10198. goto err_out_iounmap;
  10199. }
  10200. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ",
  10201. dev->name,
  10202. tp->board_part_number,
  10203. tp->pci_chip_rev_id,
  10204. tg3_phy_string(tp),
  10205. tg3_bus_string(tp, str),
  10206. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10207. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10208. "10/100/1000Base-T")));
  10209. for (i = 0; i < 6; i++)
  10210. printk("%2.2x%c", dev->dev_addr[i],
  10211. i == 5 ? '\n' : ':');
  10212. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10213. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10214. dev->name,
  10215. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10216. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10217. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10218. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10219. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10220. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10221. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10222. dev->name, tp->dma_rwctrl,
  10223. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  10224. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  10225. return 0;
  10226. err_out_iounmap:
  10227. if (tp->regs) {
  10228. iounmap(tp->regs);
  10229. tp->regs = NULL;
  10230. }
  10231. err_out_free_dev:
  10232. free_netdev(dev);
  10233. err_out_free_res:
  10234. pci_release_regions(pdev);
  10235. err_out_disable_pdev:
  10236. pci_disable_device(pdev);
  10237. pci_set_drvdata(pdev, NULL);
  10238. return err;
  10239. }
  10240. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  10241. {
  10242. struct net_device *dev = pci_get_drvdata(pdev);
  10243. if (dev) {
  10244. struct tg3 *tp = netdev_priv(dev);
  10245. flush_scheduled_work();
  10246. unregister_netdev(dev);
  10247. if (tp->regs) {
  10248. iounmap(tp->regs);
  10249. tp->regs = NULL;
  10250. }
  10251. free_netdev(dev);
  10252. pci_release_regions(pdev);
  10253. pci_disable_device(pdev);
  10254. pci_set_drvdata(pdev, NULL);
  10255. }
  10256. }
  10257. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  10258. {
  10259. struct net_device *dev = pci_get_drvdata(pdev);
  10260. struct tg3 *tp = netdev_priv(dev);
  10261. int err;
  10262. if (!netif_running(dev))
  10263. return 0;
  10264. flush_scheduled_work();
  10265. tg3_netif_stop(tp);
  10266. del_timer_sync(&tp->timer);
  10267. tg3_full_lock(tp, 1);
  10268. tg3_disable_ints(tp);
  10269. tg3_full_unlock(tp);
  10270. netif_device_detach(dev);
  10271. tg3_full_lock(tp, 0);
  10272. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10273. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  10274. tg3_full_unlock(tp);
  10275. /* Save MSI address and data for resume. */
  10276. pci_save_state(pdev);
  10277. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  10278. if (err) {
  10279. tg3_full_lock(tp, 0);
  10280. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10281. if (tg3_restart_hw(tp, 1))
  10282. goto out;
  10283. tp->timer.expires = jiffies + tp->timer_offset;
  10284. add_timer(&tp->timer);
  10285. netif_device_attach(dev);
  10286. tg3_netif_start(tp);
  10287. out:
  10288. tg3_full_unlock(tp);
  10289. }
  10290. return err;
  10291. }
  10292. static int tg3_resume(struct pci_dev *pdev)
  10293. {
  10294. struct net_device *dev = pci_get_drvdata(pdev);
  10295. struct tg3 *tp = netdev_priv(dev);
  10296. int err;
  10297. if (!netif_running(dev))
  10298. return 0;
  10299. pci_restore_state(tp->pdev);
  10300. err = tg3_set_power_state(tp, PCI_D0);
  10301. if (err)
  10302. return err;
  10303. netif_device_attach(dev);
  10304. tg3_full_lock(tp, 0);
  10305. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  10306. err = tg3_restart_hw(tp, 1);
  10307. if (err)
  10308. goto out;
  10309. tp->timer.expires = jiffies + tp->timer_offset;
  10310. add_timer(&tp->timer);
  10311. tg3_netif_start(tp);
  10312. out:
  10313. tg3_full_unlock(tp);
  10314. return err;
  10315. }
  10316. static struct pci_driver tg3_driver = {
  10317. .name = DRV_MODULE_NAME,
  10318. .id_table = tg3_pci_tbl,
  10319. .probe = tg3_init_one,
  10320. .remove = __devexit_p(tg3_remove_one),
  10321. .suspend = tg3_suspend,
  10322. .resume = tg3_resume
  10323. };
  10324. static int __init tg3_init(void)
  10325. {
  10326. return pci_register_driver(&tg3_driver);
  10327. }
  10328. static void __exit tg3_cleanup(void)
  10329. {
  10330. pci_unregister_driver(&tg3_driver);
  10331. }
  10332. module_init(tg3_init);
  10333. module_exit(tg3_cleanup);