tg3.c 338 KB

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