tg3.c 375 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160
  1. /*
  2. * tg3.c: Broadcom Tigon3 ethernet driver.
  3. *
  4. * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com)
  6. * Copyright (C) 2004 Sun Microsystems Inc.
  7. * Copyright (C) 2005-2007 Broadcom Corporation.
  8. *
  9. * Firmware is:
  10. * Derived from proprietary unpublished source code,
  11. * Copyright (C) 2000-2003 Broadcom Corporation.
  12. *
  13. * Permission is hereby granted for the distribution of this firmware
  14. * data in hexadecimal or equivalent format, provided this copyright
  15. * notice is accompanying it.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/in.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/mii.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/tcp.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/prefetch.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <net/ip.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/byteorder.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_SPARC
  46. #include <asm/idprom.h>
  47. #include <asm/prom.h>
  48. #endif
  49. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  50. #define TG3_VLAN_TAG_USED 1
  51. #else
  52. #define TG3_VLAN_TAG_USED 0
  53. #endif
  54. #define TG3_TSO_SUPPORT 1
  55. #include "tg3.h"
  56. #define DRV_MODULE_NAME "tg3"
  57. #define PFX DRV_MODULE_NAME ": "
  58. #define DRV_MODULE_VERSION "3.92"
  59. #define DRV_MODULE_RELDATE "May 2, 2008"
  60. #define TG3_DEF_MAC_MODE 0
  61. #define TG3_DEF_RX_MODE 0
  62. #define TG3_DEF_TX_MODE 0
  63. #define TG3_DEF_MSG_ENABLE \
  64. (NETIF_MSG_DRV | \
  65. NETIF_MSG_PROBE | \
  66. NETIF_MSG_LINK | \
  67. NETIF_MSG_TIMER | \
  68. NETIF_MSG_IFDOWN | \
  69. NETIF_MSG_IFUP | \
  70. NETIF_MSG_RX_ERR | \
  71. NETIF_MSG_TX_ERR)
  72. /* length of time before we decide the hardware is borked,
  73. * and dev->tx_timeout() should be called to fix the problem
  74. */
  75. #define TG3_TX_TIMEOUT (5 * HZ)
  76. /* hardware minimum and maximum for a single frame's data payload */
  77. #define TG3_MIN_MTU 60
  78. #define TG3_MAX_MTU(tp) \
  79. ((tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) ? 9000 : 1500)
  80. /* These numbers seem to be hard coded in the NIC firmware somehow.
  81. * You can't change the ring sizes, but you can change where you place
  82. * them in the NIC onboard memory.
  83. */
  84. #define TG3_RX_RING_SIZE 512
  85. #define TG3_DEF_RX_RING_PENDING 200
  86. #define TG3_RX_JUMBO_RING_SIZE 256
  87. #define TG3_DEF_RX_JUMBO_RING_PENDING 100
  88. /* Do not place this n-ring entries value into the tp struct itself,
  89. * we really want to expose these constants to GCC so that modulo et
  90. * al. operations are done with shifts and masks instead of with
  91. * hw multiply/modulo instructions. Another solution would be to
  92. * replace things like '% foo' with '& (foo - 1)'.
  93. */
  94. #define TG3_RX_RCB_RING_SIZE(tp) \
  95. ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ? 512 : 1024)
  96. #define TG3_TX_RING_SIZE 512
  97. #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1)
  98. #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  99. TG3_RX_RING_SIZE)
  100. #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \
  101. TG3_RX_JUMBO_RING_SIZE)
  102. #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \
  103. TG3_RX_RCB_RING_SIZE(tp))
  104. #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
  105. TG3_TX_RING_SIZE)
  106. #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
  107. #define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
  108. #define RX_JUMBO_PKT_BUF_SZ (9046 + tp->rx_offset + 64)
  109. /* minimum number of free TX descriptors required to wake up TX process */
  110. #define TG3_TX_WAKEUP_THRESH(tp) ((tp)->tx_pending / 4)
  111. /* number of ETHTOOL_GSTATS u64's */
  112. #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64))
  113. #define TG3_NUM_TEST 6
  114. static char version[] __devinitdata =
  115. DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  116. MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)");
  117. MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver");
  118. MODULE_LICENSE("GPL");
  119. MODULE_VERSION(DRV_MODULE_VERSION);
  120. static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */
  121. module_param(tg3_debug, int, 0);
  122. MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
  123. static struct pci_device_id tg3_pci_tbl[] = {
  124. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)},
  125. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)},
  126. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)},
  127. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)},
  128. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)},
  129. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)},
  130. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)},
  131. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)},
  132. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)},
  133. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)},
  134. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)},
  135. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)},
  136. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)},
  137. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)},
  138. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)},
  139. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)},
  140. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)},
  142. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)},
  143. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)},
  144. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)},
  145. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)},
  146. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)},
  147. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)},
  148. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)},
  149. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)},
  150. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)},
  151. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)},
  152. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)},
  153. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)},
  154. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)},
  155. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)},
  156. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)},
  157. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)},
  158. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)},
  159. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)},
  160. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)},
  161. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)},
  162. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)},
  163. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)},
  164. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)},
  165. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)},
  166. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)},
  167. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)},
  168. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)},
  169. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)},
  170. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)},
  171. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)},
  172. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)},
  173. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)},
  174. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)},
  175. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)},
  176. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)},
  177. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)},
  178. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)},
  179. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)},
  180. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)},
  181. {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)},
  182. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)},
  183. {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)},
  184. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)},
  185. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)},
  186. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)},
  187. {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)},
  188. {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)},
  189. {}
  190. };
  191. MODULE_DEVICE_TABLE(pci, tg3_pci_tbl);
  192. static const struct {
  193. const char string[ETH_GSTRING_LEN];
  194. } ethtool_stats_keys[TG3_NUM_STATS] = {
  195. { "rx_octets" },
  196. { "rx_fragments" },
  197. { "rx_ucast_packets" },
  198. { "rx_mcast_packets" },
  199. { "rx_bcast_packets" },
  200. { "rx_fcs_errors" },
  201. { "rx_align_errors" },
  202. { "rx_xon_pause_rcvd" },
  203. { "rx_xoff_pause_rcvd" },
  204. { "rx_mac_ctrl_rcvd" },
  205. { "rx_xoff_entered" },
  206. { "rx_frame_too_long_errors" },
  207. { "rx_jabbers" },
  208. { "rx_undersize_packets" },
  209. { "rx_in_length_errors" },
  210. { "rx_out_length_errors" },
  211. { "rx_64_or_less_octet_packets" },
  212. { "rx_65_to_127_octet_packets" },
  213. { "rx_128_to_255_octet_packets" },
  214. { "rx_256_to_511_octet_packets" },
  215. { "rx_512_to_1023_octet_packets" },
  216. { "rx_1024_to_1522_octet_packets" },
  217. { "rx_1523_to_2047_octet_packets" },
  218. { "rx_2048_to_4095_octet_packets" },
  219. { "rx_4096_to_8191_octet_packets" },
  220. { "rx_8192_to_9022_octet_packets" },
  221. { "tx_octets" },
  222. { "tx_collisions" },
  223. { "tx_xon_sent" },
  224. { "tx_xoff_sent" },
  225. { "tx_flow_control" },
  226. { "tx_mac_errors" },
  227. { "tx_single_collisions" },
  228. { "tx_mult_collisions" },
  229. { "tx_deferred" },
  230. { "tx_excessive_collisions" },
  231. { "tx_late_collisions" },
  232. { "tx_collide_2times" },
  233. { "tx_collide_3times" },
  234. { "tx_collide_4times" },
  235. { "tx_collide_5times" },
  236. { "tx_collide_6times" },
  237. { "tx_collide_7times" },
  238. { "tx_collide_8times" },
  239. { "tx_collide_9times" },
  240. { "tx_collide_10times" },
  241. { "tx_collide_11times" },
  242. { "tx_collide_12times" },
  243. { "tx_collide_13times" },
  244. { "tx_collide_14times" },
  245. { "tx_collide_15times" },
  246. { "tx_ucast_packets" },
  247. { "tx_mcast_packets" },
  248. { "tx_bcast_packets" },
  249. { "tx_carrier_sense_errors" },
  250. { "tx_discards" },
  251. { "tx_errors" },
  252. { "dma_writeq_full" },
  253. { "dma_write_prioq_full" },
  254. { "rxbds_empty" },
  255. { "rx_discards" },
  256. { "rx_errors" },
  257. { "rx_threshold_hit" },
  258. { "dma_readq_full" },
  259. { "dma_read_prioq_full" },
  260. { "tx_comp_queue_full" },
  261. { "ring_set_send_prod_index" },
  262. { "ring_status_update" },
  263. { "nic_irqs" },
  264. { "nic_avoided_irqs" },
  265. { "nic_tx_threshold_hit" }
  266. };
  267. static const struct {
  268. const char string[ETH_GSTRING_LEN];
  269. } ethtool_test_keys[TG3_NUM_TEST] = {
  270. { "nvram test (online) " },
  271. { "link test (online) " },
  272. { "register test (offline)" },
  273. { "memory test (offline)" },
  274. { "loopback test (offline)" },
  275. { "interrupt test (offline)" },
  276. };
  277. static void tg3_write32(struct tg3 *tp, u32 off, u32 val)
  278. {
  279. writel(val, tp->regs + off);
  280. }
  281. static u32 tg3_read32(struct tg3 *tp, u32 off)
  282. {
  283. return (readl(tp->regs + off));
  284. }
  285. static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val)
  286. {
  287. writel(val, tp->aperegs + off);
  288. }
  289. static u32 tg3_ape_read32(struct tg3 *tp, u32 off)
  290. {
  291. return (readl(tp->aperegs + off));
  292. }
  293. static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val)
  294. {
  295. unsigned long flags;
  296. spin_lock_irqsave(&tp->indirect_lock, flags);
  297. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  298. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  299. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  300. }
  301. static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val)
  302. {
  303. writel(val, tp->regs + off);
  304. readl(tp->regs + off);
  305. }
  306. static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off)
  307. {
  308. unsigned long flags;
  309. u32 val;
  310. spin_lock_irqsave(&tp->indirect_lock, flags);
  311. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off);
  312. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  313. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  314. return val;
  315. }
  316. static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val)
  317. {
  318. unsigned long flags;
  319. if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) {
  320. pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX +
  321. TG3_64BIT_REG_LOW, val);
  322. return;
  323. }
  324. if (off == (MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW)) {
  325. pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX +
  326. TG3_64BIT_REG_LOW, val);
  327. return;
  328. }
  329. spin_lock_irqsave(&tp->indirect_lock, flags);
  330. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  331. pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val);
  332. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  333. /* In indirect mode when disabling interrupts, we also need
  334. * to clear the interrupt bit in the GRC local ctrl register.
  335. */
  336. if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) &&
  337. (val == 0x1)) {
  338. pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL,
  339. tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT);
  340. }
  341. }
  342. static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off)
  343. {
  344. unsigned long flags;
  345. u32 val;
  346. spin_lock_irqsave(&tp->indirect_lock, flags);
  347. pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600);
  348. pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val);
  349. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  350. return val;
  351. }
  352. /* usec_wait specifies the wait time in usec when writing to certain registers
  353. * where it is unsafe to read back the register without some delay.
  354. * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power.
  355. * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed.
  356. */
  357. static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait)
  358. {
  359. if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
  360. (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  361. /* Non-posted methods */
  362. tp->write32(tp, off, val);
  363. else {
  364. /* Posted method */
  365. tg3_write32(tp, off, val);
  366. if (usec_wait)
  367. udelay(usec_wait);
  368. tp->read32(tp, off);
  369. }
  370. /* Wait again after the read for the posted method to guarantee that
  371. * the wait time is met.
  372. */
  373. if (usec_wait)
  374. udelay(usec_wait);
  375. }
  376. static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val)
  377. {
  378. tp->write32_mbox(tp, off, val);
  379. if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) &&
  380. !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
  381. tp->read32_mbox(tp, off);
  382. }
  383. static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val)
  384. {
  385. void __iomem *mbox = tp->regs + off;
  386. writel(val, mbox);
  387. if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG)
  388. writel(val, mbox);
  389. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  390. readl(mbox);
  391. }
  392. static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off)
  393. {
  394. return (readl(tp->regs + off + GRCMBOX_BASE));
  395. }
  396. static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val)
  397. {
  398. writel(val, tp->regs + off + GRCMBOX_BASE);
  399. }
  400. #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val)
  401. #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val))
  402. #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val)
  403. #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val)
  404. #define tr32_mailbox(reg) tp->read32_mbox(tp, reg)
  405. #define tw32(reg,val) tp->write32(tp, reg, val)
  406. #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0)
  407. #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us))
  408. #define tr32(reg) tp->read32(tp, reg)
  409. static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
  410. {
  411. unsigned long flags;
  412. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  413. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC))
  414. return;
  415. spin_lock_irqsave(&tp->indirect_lock, flags);
  416. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  417. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  418. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  419. /* Always leave this as zero. */
  420. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  421. } else {
  422. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  423. tw32_f(TG3PCI_MEM_WIN_DATA, val);
  424. /* Always leave this as zero. */
  425. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  426. }
  427. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  428. }
  429. static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
  430. {
  431. unsigned long flags;
  432. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) &&
  433. (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) {
  434. *val = 0;
  435. return;
  436. }
  437. spin_lock_irqsave(&tp->indirect_lock, flags);
  438. if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
  439. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
  440. pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  441. /* Always leave this as zero. */
  442. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  443. } else {
  444. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
  445. *val = tr32(TG3PCI_MEM_WIN_DATA);
  446. /* Always leave this as zero. */
  447. tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  448. }
  449. spin_unlock_irqrestore(&tp->indirect_lock, flags);
  450. }
  451. static void tg3_ape_lock_init(struct tg3 *tp)
  452. {
  453. int i;
  454. /* Make sure the driver hasn't any stale locks. */
  455. for (i = 0; i < 8; i++)
  456. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + 4 * i,
  457. APE_LOCK_GRANT_DRIVER);
  458. }
  459. static int tg3_ape_lock(struct tg3 *tp, int locknum)
  460. {
  461. int i, off;
  462. int ret = 0;
  463. u32 status;
  464. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  465. return 0;
  466. switch (locknum) {
  467. case TG3_APE_LOCK_MEM:
  468. break;
  469. default:
  470. return -EINVAL;
  471. }
  472. off = 4 * locknum;
  473. tg3_ape_write32(tp, TG3_APE_LOCK_REQ + off, APE_LOCK_REQ_DRIVER);
  474. /* Wait for up to 1 millisecond to acquire lock. */
  475. for (i = 0; i < 100; i++) {
  476. status = tg3_ape_read32(tp, TG3_APE_LOCK_GRANT + off);
  477. if (status == APE_LOCK_GRANT_DRIVER)
  478. break;
  479. udelay(10);
  480. }
  481. if (status != APE_LOCK_GRANT_DRIVER) {
  482. /* Revoke the lock request. */
  483. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off,
  484. APE_LOCK_GRANT_DRIVER);
  485. ret = -EBUSY;
  486. }
  487. return ret;
  488. }
  489. static void tg3_ape_unlock(struct tg3 *tp, int locknum)
  490. {
  491. int off;
  492. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  493. return;
  494. switch (locknum) {
  495. case TG3_APE_LOCK_MEM:
  496. break;
  497. default:
  498. return;
  499. }
  500. off = 4 * locknum;
  501. tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off, APE_LOCK_GRANT_DRIVER);
  502. }
  503. static void tg3_disable_ints(struct tg3 *tp)
  504. {
  505. tw32(TG3PCI_MISC_HOST_CTRL,
  506. (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT));
  507. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  508. }
  509. static inline void tg3_cond_int(struct tg3 *tp)
  510. {
  511. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  512. (tp->hw_status->status & SD_STATUS_UPDATED))
  513. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  514. else
  515. tw32(HOSTCC_MODE, tp->coalesce_mode |
  516. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  517. }
  518. static void tg3_enable_ints(struct tg3 *tp)
  519. {
  520. tp->irq_sync = 0;
  521. wmb();
  522. tw32(TG3PCI_MISC_HOST_CTRL,
  523. (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT));
  524. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  525. (tp->last_tag << 24));
  526. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  527. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  528. (tp->last_tag << 24));
  529. tg3_cond_int(tp);
  530. }
  531. static inline unsigned int tg3_has_work(struct tg3 *tp)
  532. {
  533. struct tg3_hw_status *sblk = tp->hw_status;
  534. unsigned int work_exists = 0;
  535. /* check for phy events */
  536. if (!(tp->tg3_flags &
  537. (TG3_FLAG_USE_LINKCHG_REG |
  538. TG3_FLAG_POLL_SERDES))) {
  539. if (sblk->status & SD_STATUS_LINK_CHG)
  540. work_exists = 1;
  541. }
  542. /* check for RX/TX work to do */
  543. if (sblk->idx[0].tx_consumer != tp->tx_cons ||
  544. sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  545. work_exists = 1;
  546. return work_exists;
  547. }
  548. /* tg3_restart_ints
  549. * similar to tg3_enable_ints, but it accurately determines whether there
  550. * is new work pending and can return without flushing the PIO write
  551. * which reenables interrupts
  552. */
  553. static void tg3_restart_ints(struct tg3 *tp)
  554. {
  555. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  556. tp->last_tag << 24);
  557. mmiowb();
  558. /* When doing tagged status, this work check is unnecessary.
  559. * The last_tag we write above tells the chip which piece of
  560. * work we've completed.
  561. */
  562. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
  563. tg3_has_work(tp))
  564. tw32(HOSTCC_MODE, tp->coalesce_mode |
  565. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  566. }
  567. static inline void tg3_netif_stop(struct tg3 *tp)
  568. {
  569. tp->dev->trans_start = jiffies; /* prevent tx timeout */
  570. napi_disable(&tp->napi);
  571. netif_tx_disable(tp->dev);
  572. }
  573. static inline void tg3_netif_start(struct tg3 *tp)
  574. {
  575. netif_wake_queue(tp->dev);
  576. /* NOTE: unconditional netif_wake_queue is only appropriate
  577. * so long as all callers are assured to have free tx slots
  578. * (such as after tg3_init_hw)
  579. */
  580. napi_enable(&tp->napi);
  581. tp->hw_status->status |= SD_STATUS_UPDATED;
  582. tg3_enable_ints(tp);
  583. }
  584. static void tg3_switch_clocks(struct tg3 *tp)
  585. {
  586. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
  587. u32 orig_clock_ctrl;
  588. if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
  589. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  590. return;
  591. orig_clock_ctrl = clock_ctrl;
  592. clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN |
  593. CLOCK_CTRL_CLKRUN_OENABLE |
  594. 0x1f);
  595. tp->pci_clock_ctrl = clock_ctrl;
  596. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  597. if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) {
  598. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  599. clock_ctrl | CLOCK_CTRL_625_CORE, 40);
  600. }
  601. } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) {
  602. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  603. clock_ctrl |
  604. (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK),
  605. 40);
  606. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  607. clock_ctrl | (CLOCK_CTRL_ALTCLK),
  608. 40);
  609. }
  610. tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40);
  611. }
  612. #define PHY_BUSY_LOOPS 5000
  613. static int tg3_readphy(struct tg3 *tp, int reg, u32 *val)
  614. {
  615. u32 frame_val;
  616. unsigned int loops;
  617. int ret;
  618. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  619. tw32_f(MAC_MI_MODE,
  620. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  621. udelay(80);
  622. }
  623. *val = 0x0;
  624. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  625. MI_COM_PHY_ADDR_MASK);
  626. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  627. MI_COM_REG_ADDR_MASK);
  628. frame_val |= (MI_COM_CMD_READ | MI_COM_START);
  629. tw32_f(MAC_MI_COM, frame_val);
  630. loops = PHY_BUSY_LOOPS;
  631. while (loops != 0) {
  632. udelay(10);
  633. frame_val = tr32(MAC_MI_COM);
  634. if ((frame_val & MI_COM_BUSY) == 0) {
  635. udelay(5);
  636. frame_val = tr32(MAC_MI_COM);
  637. break;
  638. }
  639. loops -= 1;
  640. }
  641. ret = -EBUSY;
  642. if (loops != 0) {
  643. *val = frame_val & MI_COM_DATA_MASK;
  644. ret = 0;
  645. }
  646. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  647. tw32_f(MAC_MI_MODE, tp->mi_mode);
  648. udelay(80);
  649. }
  650. return ret;
  651. }
  652. static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
  653. {
  654. u32 frame_val;
  655. unsigned int loops;
  656. int ret;
  657. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 &&
  658. (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL))
  659. return 0;
  660. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  661. tw32_f(MAC_MI_MODE,
  662. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  663. udelay(80);
  664. }
  665. frame_val = ((PHY_ADDR << MI_COM_PHY_ADDR_SHIFT) &
  666. MI_COM_PHY_ADDR_MASK);
  667. frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) &
  668. MI_COM_REG_ADDR_MASK);
  669. frame_val |= (val & MI_COM_DATA_MASK);
  670. frame_val |= (MI_COM_CMD_WRITE | MI_COM_START);
  671. tw32_f(MAC_MI_COM, frame_val);
  672. loops = PHY_BUSY_LOOPS;
  673. while (loops != 0) {
  674. udelay(10);
  675. frame_val = tr32(MAC_MI_COM);
  676. if ((frame_val & MI_COM_BUSY) == 0) {
  677. udelay(5);
  678. frame_val = tr32(MAC_MI_COM);
  679. break;
  680. }
  681. loops -= 1;
  682. }
  683. ret = -EBUSY;
  684. if (loops != 0)
  685. ret = 0;
  686. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  687. tw32_f(MAC_MI_MODE, tp->mi_mode);
  688. udelay(80);
  689. }
  690. return ret;
  691. }
  692. static int tg3_bmcr_reset(struct tg3 *tp)
  693. {
  694. u32 phy_control;
  695. int limit, err;
  696. /* OK, reset it, and poll the BMCR_RESET bit until it
  697. * clears or we time out.
  698. */
  699. phy_control = BMCR_RESET;
  700. err = tg3_writephy(tp, MII_BMCR, phy_control);
  701. if (err != 0)
  702. return -EBUSY;
  703. limit = 5000;
  704. while (limit--) {
  705. err = tg3_readphy(tp, MII_BMCR, &phy_control);
  706. if (err != 0)
  707. return -EBUSY;
  708. if ((phy_control & BMCR_RESET) == 0) {
  709. udelay(40);
  710. break;
  711. }
  712. udelay(10);
  713. }
  714. if (limit <= 0)
  715. return -EBUSY;
  716. return 0;
  717. }
  718. /* tp->lock is held. */
  719. static void tg3_wait_for_event_ack(struct tg3 *tp)
  720. {
  721. int i;
  722. /* Wait for up to 2.5 milliseconds */
  723. for (i = 0; i < 250000; i++) {
  724. if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT))
  725. break;
  726. udelay(10);
  727. }
  728. }
  729. /* tp->lock is held. */
  730. static void tg3_ump_link_report(struct tg3 *tp)
  731. {
  732. u32 reg;
  733. u32 val;
  734. if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  735. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  736. return;
  737. tg3_wait_for_event_ack(tp);
  738. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE);
  739. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14);
  740. val = 0;
  741. if (!tg3_readphy(tp, MII_BMCR, &reg))
  742. val = reg << 16;
  743. if (!tg3_readphy(tp, MII_BMSR, &reg))
  744. val |= (reg & 0xffff);
  745. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val);
  746. val = 0;
  747. if (!tg3_readphy(tp, MII_ADVERTISE, &reg))
  748. val = reg << 16;
  749. if (!tg3_readphy(tp, MII_LPA, &reg))
  750. val |= (reg & 0xffff);
  751. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val);
  752. val = 0;
  753. if (!(tp->tg3_flags2 & TG3_FLG2_MII_SERDES)) {
  754. if (!tg3_readphy(tp, MII_CTRL1000, &reg))
  755. val = reg << 16;
  756. if (!tg3_readphy(tp, MII_STAT1000, &reg))
  757. val |= (reg & 0xffff);
  758. }
  759. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val);
  760. if (!tg3_readphy(tp, MII_PHYADDR, &reg))
  761. val = reg << 16;
  762. else
  763. val = 0;
  764. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val);
  765. val = tr32(GRC_RX_CPU_EVENT);
  766. val |= GRC_RX_CPU_DRIVER_EVENT;
  767. tw32_f(GRC_RX_CPU_EVENT, val);
  768. }
  769. static void tg3_link_report(struct tg3 *tp)
  770. {
  771. if (!netif_carrier_ok(tp->dev)) {
  772. if (netif_msg_link(tp))
  773. printk(KERN_INFO PFX "%s: Link is down.\n",
  774. tp->dev->name);
  775. tg3_ump_link_report(tp);
  776. } else if (netif_msg_link(tp)) {
  777. printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
  778. tp->dev->name,
  779. (tp->link_config.active_speed == SPEED_1000 ?
  780. 1000 :
  781. (tp->link_config.active_speed == SPEED_100 ?
  782. 100 : 10)),
  783. (tp->link_config.active_duplex == DUPLEX_FULL ?
  784. "full" : "half"));
  785. printk(KERN_INFO PFX
  786. "%s: Flow control is %s for TX and %s for RX.\n",
  787. tp->dev->name,
  788. (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_TX) ?
  789. "on" : "off",
  790. (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX) ?
  791. "on" : "off");
  792. tg3_ump_link_report(tp);
  793. }
  794. }
  795. static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl)
  796. {
  797. u16 miireg;
  798. if ((flow_ctrl & TG3_FLOW_CTRL_TX) && (flow_ctrl & TG3_FLOW_CTRL_RX))
  799. miireg = ADVERTISE_PAUSE_CAP;
  800. else if (flow_ctrl & TG3_FLOW_CTRL_TX)
  801. miireg = ADVERTISE_PAUSE_ASYM;
  802. else if (flow_ctrl & TG3_FLOW_CTRL_RX)
  803. miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  804. else
  805. miireg = 0;
  806. return miireg;
  807. }
  808. static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl)
  809. {
  810. u16 miireg;
  811. if ((flow_ctrl & TG3_FLOW_CTRL_TX) && (flow_ctrl & TG3_FLOW_CTRL_RX))
  812. miireg = ADVERTISE_1000XPAUSE;
  813. else if (flow_ctrl & TG3_FLOW_CTRL_TX)
  814. miireg = ADVERTISE_1000XPSE_ASYM;
  815. else if (flow_ctrl & TG3_FLOW_CTRL_RX)
  816. miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  817. else
  818. miireg = 0;
  819. return miireg;
  820. }
  821. static u8 tg3_resolve_flowctrl_1000T(u16 lcladv, u16 rmtadv)
  822. {
  823. u8 cap = 0;
  824. if (lcladv & ADVERTISE_PAUSE_CAP) {
  825. if (lcladv & ADVERTISE_PAUSE_ASYM) {
  826. if (rmtadv & LPA_PAUSE_CAP)
  827. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  828. else if (rmtadv & LPA_PAUSE_ASYM)
  829. cap = TG3_FLOW_CTRL_RX;
  830. } else {
  831. if (rmtadv & LPA_PAUSE_CAP)
  832. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  833. }
  834. } else if (lcladv & ADVERTISE_PAUSE_ASYM) {
  835. if ((rmtadv & LPA_PAUSE_CAP) && (rmtadv & LPA_PAUSE_ASYM))
  836. cap = TG3_FLOW_CTRL_TX;
  837. }
  838. return cap;
  839. }
  840. static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv)
  841. {
  842. u8 cap = 0;
  843. if (lcladv & ADVERTISE_1000XPAUSE) {
  844. if (lcladv & ADVERTISE_1000XPSE_ASYM) {
  845. if (rmtadv & LPA_1000XPAUSE)
  846. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  847. else if (rmtadv & LPA_1000XPAUSE_ASYM)
  848. cap = TG3_FLOW_CTRL_RX;
  849. } else {
  850. if (rmtadv & LPA_1000XPAUSE)
  851. cap = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  852. }
  853. } else if (lcladv & ADVERTISE_1000XPSE_ASYM) {
  854. if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM))
  855. cap = TG3_FLOW_CTRL_TX;
  856. }
  857. return cap;
  858. }
  859. static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv)
  860. {
  861. u8 flowctrl = 0;
  862. u32 old_rx_mode = tp->rx_mode;
  863. u32 old_tx_mode = tp->tx_mode;
  864. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  865. (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) {
  866. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  867. flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv);
  868. else
  869. flowctrl = tg3_resolve_flowctrl_1000T(lcladv, rmtadv);
  870. } else
  871. flowctrl = tp->link_config.flowctrl;
  872. tp->link_config.active_flowctrl = flowctrl;
  873. if (flowctrl & TG3_FLOW_CTRL_RX)
  874. tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE;
  875. else
  876. tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE;
  877. if (old_rx_mode != tp->rx_mode)
  878. tw32_f(MAC_RX_MODE, tp->rx_mode);
  879. if (flowctrl & TG3_FLOW_CTRL_TX)
  880. tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE;
  881. else
  882. tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE;
  883. if (old_tx_mode != tp->tx_mode)
  884. tw32_f(MAC_TX_MODE, tp->tx_mode);
  885. }
  886. static void tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val)
  887. {
  888. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg);
  889. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val);
  890. }
  891. static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
  892. {
  893. u32 phy;
  894. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  895. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  896. return;
  897. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  898. u32 ephy;
  899. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &ephy)) {
  900. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  901. ephy | MII_TG3_EPHY_SHADOW_EN);
  902. if (!tg3_readphy(tp, MII_TG3_EPHYTST_MISCCTRL, &phy)) {
  903. if (enable)
  904. phy |= MII_TG3_EPHYTST_MISCCTRL_MDIX;
  905. else
  906. phy &= ~MII_TG3_EPHYTST_MISCCTRL_MDIX;
  907. tg3_writephy(tp, MII_TG3_EPHYTST_MISCCTRL, phy);
  908. }
  909. tg3_writephy(tp, MII_TG3_EPHY_TEST, ephy);
  910. }
  911. } else {
  912. phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
  913. MII_TG3_AUXCTL_SHDWSEL_MISC;
  914. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
  915. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
  916. if (enable)
  917. phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  918. else
  919. phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
  920. phy |= MII_TG3_AUXCTL_MISC_WREN;
  921. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  922. }
  923. }
  924. }
  925. static void tg3_phy_set_wirespeed(struct tg3 *tp)
  926. {
  927. u32 val;
  928. if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED)
  929. return;
  930. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) &&
  931. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val))
  932. tg3_writephy(tp, MII_TG3_AUX_CTRL,
  933. (val | (1 << 15) | (1 << 4)));
  934. }
  935. static void tg3_phy_apply_otp(struct tg3 *tp)
  936. {
  937. u32 otp, phy;
  938. if (!tp->phy_otp)
  939. return;
  940. otp = tp->phy_otp;
  941. /* Enable SM_DSP clock and tx 6dB coding. */
  942. phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
  943. MII_TG3_AUXCTL_ACTL_SMDSP_ENA |
  944. MII_TG3_AUXCTL_ACTL_TX_6DB;
  945. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  946. phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT);
  947. phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT;
  948. tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy);
  949. phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) |
  950. ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT);
  951. tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy);
  952. phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT);
  953. phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ;
  954. tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy);
  955. phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT);
  956. tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy);
  957. phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT);
  958. tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy);
  959. phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) |
  960. ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT);
  961. tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy);
  962. /* Turn off SM_DSP clock. */
  963. phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL |
  964. MII_TG3_AUXCTL_ACTL_TX_6DB;
  965. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
  966. }
  967. static int tg3_wait_macro_done(struct tg3 *tp)
  968. {
  969. int limit = 100;
  970. while (limit--) {
  971. u32 tmp32;
  972. if (!tg3_readphy(tp, 0x16, &tmp32)) {
  973. if ((tmp32 & 0x1000) == 0)
  974. break;
  975. }
  976. }
  977. if (limit <= 0)
  978. return -EBUSY;
  979. return 0;
  980. }
  981. static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp)
  982. {
  983. static const u32 test_pat[4][6] = {
  984. { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 },
  985. { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 },
  986. { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 },
  987. { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 }
  988. };
  989. int chan;
  990. for (chan = 0; chan < 4; chan++) {
  991. int i;
  992. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  993. (chan * 0x2000) | 0x0200);
  994. tg3_writephy(tp, 0x16, 0x0002);
  995. for (i = 0; i < 6; i++)
  996. tg3_writephy(tp, MII_TG3_DSP_RW_PORT,
  997. test_pat[chan][i]);
  998. tg3_writephy(tp, 0x16, 0x0202);
  999. if (tg3_wait_macro_done(tp)) {
  1000. *resetp = 1;
  1001. return -EBUSY;
  1002. }
  1003. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  1004. (chan * 0x2000) | 0x0200);
  1005. tg3_writephy(tp, 0x16, 0x0082);
  1006. if (tg3_wait_macro_done(tp)) {
  1007. *resetp = 1;
  1008. return -EBUSY;
  1009. }
  1010. tg3_writephy(tp, 0x16, 0x0802);
  1011. if (tg3_wait_macro_done(tp)) {
  1012. *resetp = 1;
  1013. return -EBUSY;
  1014. }
  1015. for (i = 0; i < 6; i += 2) {
  1016. u32 low, high;
  1017. if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) ||
  1018. tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) ||
  1019. tg3_wait_macro_done(tp)) {
  1020. *resetp = 1;
  1021. return -EBUSY;
  1022. }
  1023. low &= 0x7fff;
  1024. high &= 0x000f;
  1025. if (low != test_pat[chan][i] ||
  1026. high != test_pat[chan][i+1]) {
  1027. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
  1028. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
  1029. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
  1030. return -EBUSY;
  1031. }
  1032. }
  1033. }
  1034. return 0;
  1035. }
  1036. static int tg3_phy_reset_chanpat(struct tg3 *tp)
  1037. {
  1038. int chan;
  1039. for (chan = 0; chan < 4; chan++) {
  1040. int i;
  1041. tg3_writephy(tp, MII_TG3_DSP_ADDRESS,
  1042. (chan * 0x2000) | 0x0200);
  1043. tg3_writephy(tp, 0x16, 0x0002);
  1044. for (i = 0; i < 6; i++)
  1045. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000);
  1046. tg3_writephy(tp, 0x16, 0x0202);
  1047. if (tg3_wait_macro_done(tp))
  1048. return -EBUSY;
  1049. }
  1050. return 0;
  1051. }
  1052. static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
  1053. {
  1054. u32 reg32, phy9_orig;
  1055. int retries, do_phy_reset, err;
  1056. retries = 10;
  1057. do_phy_reset = 1;
  1058. do {
  1059. if (do_phy_reset) {
  1060. err = tg3_bmcr_reset(tp);
  1061. if (err)
  1062. return err;
  1063. do_phy_reset = 0;
  1064. }
  1065. /* Disable transmitter and interrupt. */
  1066. if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
  1067. continue;
  1068. reg32 |= 0x3000;
  1069. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  1070. /* Set full-duplex, 1000 mbps. */
  1071. tg3_writephy(tp, MII_BMCR,
  1072. BMCR_FULLDPLX | TG3_BMCR_SPEED1000);
  1073. /* Set to master mode. */
  1074. if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig))
  1075. continue;
  1076. tg3_writephy(tp, MII_TG3_CTRL,
  1077. (MII_TG3_CTRL_AS_MASTER |
  1078. MII_TG3_CTRL_ENABLE_AS_MASTER));
  1079. /* Enable SM_DSP_CLOCK and 6dB. */
  1080. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1081. /* Block the PHY control access. */
  1082. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  1083. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800);
  1084. err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset);
  1085. if (!err)
  1086. break;
  1087. } while (--retries);
  1088. err = tg3_phy_reset_chanpat(tp);
  1089. if (err)
  1090. return err;
  1091. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005);
  1092. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000);
  1093. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200);
  1094. tg3_writephy(tp, 0x16, 0x0000);
  1095. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1096. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1097. /* Set Extended packet length bit for jumbo frames */
  1098. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400);
  1099. }
  1100. else {
  1101. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1102. }
  1103. tg3_writephy(tp, MII_TG3_CTRL, phy9_orig);
  1104. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32)) {
  1105. reg32 &= ~0x3000;
  1106. tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
  1107. } else if (!err)
  1108. err = -EBUSY;
  1109. return err;
  1110. }
  1111. /* This will reset the tigon3 PHY if there is no valid
  1112. * link unless the FORCE argument is non-zero.
  1113. */
  1114. static int tg3_phy_reset(struct tg3 *tp)
  1115. {
  1116. u32 cpmuctrl;
  1117. u32 phy_status;
  1118. int err;
  1119. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1120. u32 val;
  1121. val = tr32(GRC_MISC_CFG);
  1122. tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
  1123. udelay(40);
  1124. }
  1125. err = tg3_readphy(tp, MII_BMSR, &phy_status);
  1126. err |= tg3_readphy(tp, MII_BMSR, &phy_status);
  1127. if (err != 0)
  1128. return -EBUSY;
  1129. if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) {
  1130. netif_carrier_off(tp->dev);
  1131. tg3_link_report(tp);
  1132. }
  1133. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1134. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1135. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  1136. err = tg3_phy_reset_5703_4_5(tp);
  1137. if (err)
  1138. return err;
  1139. goto out;
  1140. }
  1141. cpmuctrl = 0;
  1142. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
  1143. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
  1144. cpmuctrl = tr32(TG3_CPMU_CTRL);
  1145. if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY)
  1146. tw32(TG3_CPMU_CTRL,
  1147. cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY);
  1148. }
  1149. err = tg3_bmcr_reset(tp);
  1150. if (err)
  1151. return err;
  1152. if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) {
  1153. u32 phy;
  1154. phy = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz;
  1155. tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, phy);
  1156. tw32(TG3_CPMU_CTRL, cpmuctrl);
  1157. }
  1158. if (tp->tg3_flags3 & TG3_FLG3_5761_5784_AX_FIXES) {
  1159. u32 val;
  1160. val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
  1161. if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) ==
  1162. CPMU_LSPD_1000MB_MACCLK_12_5) {
  1163. val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
  1164. udelay(40);
  1165. tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
  1166. }
  1167. /* Disable GPHY autopowerdown. */
  1168. tg3_writephy(tp, MII_TG3_MISC_SHDW,
  1169. MII_TG3_MISC_SHDW_WREN |
  1170. MII_TG3_MISC_SHDW_APD_SEL |
  1171. MII_TG3_MISC_SHDW_APD_WKTM_84MS);
  1172. }
  1173. tg3_phy_apply_otp(tp);
  1174. out:
  1175. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) {
  1176. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1177. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1178. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa);
  1179. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1180. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323);
  1181. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1182. }
  1183. if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) {
  1184. tg3_writephy(tp, 0x1c, 0x8d68);
  1185. tg3_writephy(tp, 0x1c, 0x8d68);
  1186. }
  1187. if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) {
  1188. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1189. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1190. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b);
  1191. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1192. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506);
  1193. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f);
  1194. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2);
  1195. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1196. }
  1197. else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) {
  1198. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00);
  1199. tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a);
  1200. if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) {
  1201. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b);
  1202. tg3_writephy(tp, MII_TG3_TEST1,
  1203. MII_TG3_TEST1_TRIM_EN | 0x4);
  1204. } else
  1205. tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b);
  1206. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400);
  1207. }
  1208. /* Set Extended packet length bit (bit 14) on all chips that */
  1209. /* support jumbo frames */
  1210. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1211. /* Cannot do read-modify-write on 5401 */
  1212. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1213. } else if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  1214. u32 phy_reg;
  1215. /* Set bit 14 with read-modify-write to preserve other bits */
  1216. if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) &&
  1217. !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg))
  1218. tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000);
  1219. }
  1220. /* Set phy register 0x10 bit 0 to high fifo elasticity to support
  1221. * jumbo frames transmission.
  1222. */
  1223. if (tp->tg3_flags2 & TG3_FLG2_JUMBO_CAPABLE) {
  1224. u32 phy_reg;
  1225. if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg))
  1226. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1227. phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC);
  1228. }
  1229. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1230. /* adjust output voltage */
  1231. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
  1232. }
  1233. tg3_phy_toggle_automdix(tp, 1);
  1234. tg3_phy_set_wirespeed(tp);
  1235. return 0;
  1236. }
  1237. static void tg3_frob_aux_power(struct tg3 *tp)
  1238. {
  1239. struct tg3 *tp_peer = tp;
  1240. if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0)
  1241. return;
  1242. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  1243. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  1244. struct net_device *dev_peer;
  1245. dev_peer = pci_get_drvdata(tp->pdev_peer);
  1246. /* remove_one() may have been run on the peer. */
  1247. if (!dev_peer)
  1248. tp_peer = tp;
  1249. else
  1250. tp_peer = netdev_priv(dev_peer);
  1251. }
  1252. if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  1253. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 ||
  1254. (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 ||
  1255. (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  1256. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1257. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1258. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1259. (GRC_LCLCTRL_GPIO_OE0 |
  1260. GRC_LCLCTRL_GPIO_OE1 |
  1261. GRC_LCLCTRL_GPIO_OE2 |
  1262. GRC_LCLCTRL_GPIO_OUTPUT0 |
  1263. GRC_LCLCTRL_GPIO_OUTPUT1),
  1264. 100);
  1265. } else {
  1266. u32 no_gpio2;
  1267. u32 grc_local_ctrl = 0;
  1268. if (tp_peer != tp &&
  1269. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1270. return;
  1271. /* Workaround to prevent overdrawing Amps. */
  1272. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1273. ASIC_REV_5714) {
  1274. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  1275. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1276. grc_local_ctrl, 100);
  1277. }
  1278. /* On 5753 and variants, GPIO2 cannot be used. */
  1279. no_gpio2 = tp->nic_sram_data_cfg &
  1280. NIC_SRAM_DATA_CFG_NO_GPIO2;
  1281. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
  1282. GRC_LCLCTRL_GPIO_OE1 |
  1283. GRC_LCLCTRL_GPIO_OE2 |
  1284. GRC_LCLCTRL_GPIO_OUTPUT1 |
  1285. GRC_LCLCTRL_GPIO_OUTPUT2;
  1286. if (no_gpio2) {
  1287. grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
  1288. GRC_LCLCTRL_GPIO_OUTPUT2);
  1289. }
  1290. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1291. grc_local_ctrl, 100);
  1292. grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
  1293. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1294. grc_local_ctrl, 100);
  1295. if (!no_gpio2) {
  1296. grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
  1297. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1298. grc_local_ctrl, 100);
  1299. }
  1300. }
  1301. } else {
  1302. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  1303. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  1304. if (tp_peer != tp &&
  1305. (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0)
  1306. return;
  1307. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1308. (GRC_LCLCTRL_GPIO_OE1 |
  1309. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1310. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1311. GRC_LCLCTRL_GPIO_OE1, 100);
  1312. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
  1313. (GRC_LCLCTRL_GPIO_OE1 |
  1314. GRC_LCLCTRL_GPIO_OUTPUT1), 100);
  1315. }
  1316. }
  1317. }
  1318. static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
  1319. {
  1320. if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
  1321. return 1;
  1322. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411) {
  1323. if (speed != SPEED_10)
  1324. return 1;
  1325. } else if (speed == SPEED_10)
  1326. return 1;
  1327. return 0;
  1328. }
  1329. static int tg3_setup_phy(struct tg3 *, int);
  1330. #define RESET_KIND_SHUTDOWN 0
  1331. #define RESET_KIND_INIT 1
  1332. #define RESET_KIND_SUSPEND 2
  1333. static void tg3_write_sig_post_reset(struct tg3 *, int);
  1334. static int tg3_halt_cpu(struct tg3 *, u32);
  1335. static int tg3_nvram_lock(struct tg3 *);
  1336. static void tg3_nvram_unlock(struct tg3 *);
  1337. static void tg3_power_down_phy(struct tg3 *tp)
  1338. {
  1339. u32 val;
  1340. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  1341. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  1342. u32 sg_dig_ctrl = tr32(SG_DIG_CTRL);
  1343. u32 serdes_cfg = tr32(MAC_SERDES_CFG);
  1344. sg_dig_ctrl |=
  1345. SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET;
  1346. tw32(SG_DIG_CTRL, sg_dig_ctrl);
  1347. tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15));
  1348. }
  1349. return;
  1350. }
  1351. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1352. tg3_bmcr_reset(tp);
  1353. val = tr32(GRC_MISC_CFG);
  1354. tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
  1355. udelay(40);
  1356. return;
  1357. } else {
  1358. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1359. MII_TG3_EXT_CTRL_FORCE_LED_OFF);
  1360. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
  1361. }
  1362. /* The PHY should not be powered down on some chips because
  1363. * of bugs.
  1364. */
  1365. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1366. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1367. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 &&
  1368. (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)))
  1369. return;
  1370. if (tp->tg3_flags3 & TG3_FLG3_5761_5784_AX_FIXES) {
  1371. val = tr32(TG3_CPMU_LSPD_1000MB_CLK);
  1372. val &= ~CPMU_LSPD_1000MB_MACCLK_MASK;
  1373. val |= CPMU_LSPD_1000MB_MACCLK_12_5;
  1374. tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val);
  1375. }
  1376. tg3_writephy(tp, MII_BMCR, BMCR_PDOWN);
  1377. }
  1378. static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
  1379. {
  1380. u32 misc_host_ctrl;
  1381. u16 power_control, power_caps;
  1382. int pm = tp->pm_cap;
  1383. /* Make sure register accesses (indirect or otherwise)
  1384. * will function correctly.
  1385. */
  1386. pci_write_config_dword(tp->pdev,
  1387. TG3PCI_MISC_HOST_CTRL,
  1388. tp->misc_host_ctrl);
  1389. pci_read_config_word(tp->pdev,
  1390. pm + PCI_PM_CTRL,
  1391. &power_control);
  1392. power_control |= PCI_PM_CTRL_PME_STATUS;
  1393. power_control &= ~(PCI_PM_CTRL_STATE_MASK);
  1394. switch (state) {
  1395. case PCI_D0:
  1396. power_control |= 0;
  1397. pci_write_config_word(tp->pdev,
  1398. pm + PCI_PM_CTRL,
  1399. power_control);
  1400. udelay(100); /* Delay after power state change */
  1401. /* Switch out of Vaux if it is a NIC */
  1402. if (tp->tg3_flags2 & TG3_FLG2_IS_NIC)
  1403. tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
  1404. return 0;
  1405. case PCI_D1:
  1406. power_control |= 1;
  1407. break;
  1408. case PCI_D2:
  1409. power_control |= 2;
  1410. break;
  1411. case PCI_D3hot:
  1412. power_control |= 3;
  1413. break;
  1414. default:
  1415. printk(KERN_WARNING PFX "%s: Invalid power state (%d) "
  1416. "requested.\n",
  1417. tp->dev->name, state);
  1418. return -EINVAL;
  1419. };
  1420. power_control |= PCI_PM_CTRL_PME_ENABLE;
  1421. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  1422. tw32(TG3PCI_MISC_HOST_CTRL,
  1423. misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
  1424. if (tp->link_config.phy_is_low_power == 0) {
  1425. tp->link_config.phy_is_low_power = 1;
  1426. tp->link_config.orig_speed = tp->link_config.speed;
  1427. tp->link_config.orig_duplex = tp->link_config.duplex;
  1428. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  1429. }
  1430. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  1431. tp->link_config.speed = SPEED_10;
  1432. tp->link_config.duplex = DUPLEX_HALF;
  1433. tp->link_config.autoneg = AUTONEG_ENABLE;
  1434. tg3_setup_phy(tp, 0);
  1435. }
  1436. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1437. u32 val;
  1438. val = tr32(GRC_VCPU_EXT_CTRL);
  1439. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL);
  1440. } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1441. int i;
  1442. u32 val;
  1443. for (i = 0; i < 200; i++) {
  1444. tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
  1445. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  1446. break;
  1447. msleep(1);
  1448. }
  1449. }
  1450. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  1451. tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
  1452. WOL_DRV_STATE_SHUTDOWN |
  1453. WOL_DRV_WOL |
  1454. WOL_SET_MAGIC_PKT);
  1455. pci_read_config_word(tp->pdev, pm + PCI_PM_PMC, &power_caps);
  1456. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
  1457. u32 mac_mode;
  1458. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  1459. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
  1460. udelay(40);
  1461. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  1462. mac_mode = MAC_MODE_PORT_MODE_GMII;
  1463. else
  1464. mac_mode = MAC_MODE_PORT_MODE_MII;
  1465. mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
  1466. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  1467. ASIC_REV_5700) {
  1468. u32 speed = (tp->tg3_flags &
  1469. TG3_FLAG_WOL_SPEED_100MB) ?
  1470. SPEED_100 : SPEED_10;
  1471. if (tg3_5700_link_polarity(tp, speed))
  1472. mac_mode |= MAC_MODE_LINK_POLARITY;
  1473. else
  1474. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1475. }
  1476. } else {
  1477. mac_mode = MAC_MODE_PORT_MODE_TBI;
  1478. }
  1479. if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  1480. tw32(MAC_LED_CTRL, tp->led_ctrl);
  1481. if (((power_caps & PCI_PM_CAP_PME_D3cold) &&
  1482. (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)))
  1483. mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
  1484. tw32_f(MAC_MODE, mac_mode);
  1485. udelay(100);
  1486. tw32_f(MAC_RX_MODE, RX_MODE_ENABLE);
  1487. udelay(10);
  1488. }
  1489. if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) &&
  1490. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1491. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  1492. u32 base_val;
  1493. base_val = tp->pci_clock_ctrl;
  1494. base_val |= (CLOCK_CTRL_RXCLK_DISABLE |
  1495. CLOCK_CTRL_TXCLK_DISABLE);
  1496. tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK |
  1497. CLOCK_CTRL_PWRDOWN_PLL133, 40);
  1498. } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
  1499. (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) ||
  1500. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) {
  1501. /* do nothing */
  1502. } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  1503. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
  1504. u32 newbits1, newbits2;
  1505. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1506. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1507. newbits1 = (CLOCK_CTRL_RXCLK_DISABLE |
  1508. CLOCK_CTRL_TXCLK_DISABLE |
  1509. CLOCK_CTRL_ALTCLK);
  1510. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1511. } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  1512. newbits1 = CLOCK_CTRL_625_CORE;
  1513. newbits2 = newbits1 | CLOCK_CTRL_ALTCLK;
  1514. } else {
  1515. newbits1 = CLOCK_CTRL_ALTCLK;
  1516. newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE;
  1517. }
  1518. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1,
  1519. 40);
  1520. tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2,
  1521. 40);
  1522. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  1523. u32 newbits3;
  1524. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1525. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1526. newbits3 = (CLOCK_CTRL_RXCLK_DISABLE |
  1527. CLOCK_CTRL_TXCLK_DISABLE |
  1528. CLOCK_CTRL_44MHZ_CORE);
  1529. } else {
  1530. newbits3 = CLOCK_CTRL_44MHZ_CORE;
  1531. }
  1532. tw32_wait_f(TG3PCI_CLOCK_CTRL,
  1533. tp->pci_clock_ctrl | newbits3, 40);
  1534. }
  1535. }
  1536. if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
  1537. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
  1538. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  1539. tg3_power_down_phy(tp);
  1540. tg3_frob_aux_power(tp);
  1541. /* Workaround for unstable PLL clock */
  1542. if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) ||
  1543. (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) {
  1544. u32 val = tr32(0x7d00);
  1545. val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1);
  1546. tw32(0x7d00, val);
  1547. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  1548. int err;
  1549. err = tg3_nvram_lock(tp);
  1550. tg3_halt_cpu(tp, RX_CPU_BASE);
  1551. if (!err)
  1552. tg3_nvram_unlock(tp);
  1553. }
  1554. }
  1555. tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
  1556. /* Finally, set the new power state. */
  1557. pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
  1558. udelay(100); /* Delay after power state change */
  1559. return 0;
  1560. }
  1561. static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex)
  1562. {
  1563. switch (val & MII_TG3_AUX_STAT_SPDMASK) {
  1564. case MII_TG3_AUX_STAT_10HALF:
  1565. *speed = SPEED_10;
  1566. *duplex = DUPLEX_HALF;
  1567. break;
  1568. case MII_TG3_AUX_STAT_10FULL:
  1569. *speed = SPEED_10;
  1570. *duplex = DUPLEX_FULL;
  1571. break;
  1572. case MII_TG3_AUX_STAT_100HALF:
  1573. *speed = SPEED_100;
  1574. *duplex = DUPLEX_HALF;
  1575. break;
  1576. case MII_TG3_AUX_STAT_100FULL:
  1577. *speed = SPEED_100;
  1578. *duplex = DUPLEX_FULL;
  1579. break;
  1580. case MII_TG3_AUX_STAT_1000HALF:
  1581. *speed = SPEED_1000;
  1582. *duplex = DUPLEX_HALF;
  1583. break;
  1584. case MII_TG3_AUX_STAT_1000FULL:
  1585. *speed = SPEED_1000;
  1586. *duplex = DUPLEX_FULL;
  1587. break;
  1588. default:
  1589. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  1590. *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 :
  1591. SPEED_10;
  1592. *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL :
  1593. DUPLEX_HALF;
  1594. break;
  1595. }
  1596. *speed = SPEED_INVALID;
  1597. *duplex = DUPLEX_INVALID;
  1598. break;
  1599. };
  1600. }
  1601. static void tg3_phy_copper_begin(struct tg3 *tp)
  1602. {
  1603. u32 new_adv;
  1604. int i;
  1605. if (tp->link_config.phy_is_low_power) {
  1606. /* Entering low power mode. Disable gigabit and
  1607. * 100baseT advertisements.
  1608. */
  1609. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1610. new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1611. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  1612. if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
  1613. new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
  1614. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1615. } else if (tp->link_config.speed == SPEED_INVALID) {
  1616. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  1617. tp->link_config.advertising &=
  1618. ~(ADVERTISED_1000baseT_Half |
  1619. ADVERTISED_1000baseT_Full);
  1620. new_adv = ADVERTISE_CSMA;
  1621. if (tp->link_config.advertising & ADVERTISED_10baseT_Half)
  1622. new_adv |= ADVERTISE_10HALF;
  1623. if (tp->link_config.advertising & ADVERTISED_10baseT_Full)
  1624. new_adv |= ADVERTISE_10FULL;
  1625. if (tp->link_config.advertising & ADVERTISED_100baseT_Half)
  1626. new_adv |= ADVERTISE_100HALF;
  1627. if (tp->link_config.advertising & ADVERTISED_100baseT_Full)
  1628. new_adv |= ADVERTISE_100FULL;
  1629. new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1630. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1631. if (tp->link_config.advertising &
  1632. (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) {
  1633. new_adv = 0;
  1634. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  1635. new_adv |= MII_TG3_CTRL_ADV_1000_HALF;
  1636. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  1637. new_adv |= MII_TG3_CTRL_ADV_1000_FULL;
  1638. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) &&
  1639. (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1640. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0))
  1641. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1642. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1643. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1644. } else {
  1645. tg3_writephy(tp, MII_TG3_CTRL, 0);
  1646. }
  1647. } else {
  1648. new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1649. new_adv |= ADVERTISE_CSMA;
  1650. /* Asking for a specific link mode. */
  1651. if (tp->link_config.speed == SPEED_1000) {
  1652. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1653. if (tp->link_config.duplex == DUPLEX_FULL)
  1654. new_adv = MII_TG3_CTRL_ADV_1000_FULL;
  1655. else
  1656. new_adv = MII_TG3_CTRL_ADV_1000_HALF;
  1657. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1658. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  1659. new_adv |= (MII_TG3_CTRL_AS_MASTER |
  1660. MII_TG3_CTRL_ENABLE_AS_MASTER);
  1661. } else {
  1662. if (tp->link_config.speed == SPEED_100) {
  1663. if (tp->link_config.duplex == DUPLEX_FULL)
  1664. new_adv |= ADVERTISE_100FULL;
  1665. else
  1666. new_adv |= ADVERTISE_100HALF;
  1667. } else {
  1668. if (tp->link_config.duplex == DUPLEX_FULL)
  1669. new_adv |= ADVERTISE_10FULL;
  1670. else
  1671. new_adv |= ADVERTISE_10HALF;
  1672. }
  1673. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  1674. new_adv = 0;
  1675. }
  1676. tg3_writephy(tp, MII_TG3_CTRL, new_adv);
  1677. }
  1678. if (tp->link_config.autoneg == AUTONEG_DISABLE &&
  1679. tp->link_config.speed != SPEED_INVALID) {
  1680. u32 bmcr, orig_bmcr;
  1681. tp->link_config.active_speed = tp->link_config.speed;
  1682. tp->link_config.active_duplex = tp->link_config.duplex;
  1683. bmcr = 0;
  1684. switch (tp->link_config.speed) {
  1685. default:
  1686. case SPEED_10:
  1687. break;
  1688. case SPEED_100:
  1689. bmcr |= BMCR_SPEED100;
  1690. break;
  1691. case SPEED_1000:
  1692. bmcr |= TG3_BMCR_SPEED1000;
  1693. break;
  1694. };
  1695. if (tp->link_config.duplex == DUPLEX_FULL)
  1696. bmcr |= BMCR_FULLDPLX;
  1697. if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) &&
  1698. (bmcr != orig_bmcr)) {
  1699. tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK);
  1700. for (i = 0; i < 1500; i++) {
  1701. u32 tmp;
  1702. udelay(10);
  1703. if (tg3_readphy(tp, MII_BMSR, &tmp) ||
  1704. tg3_readphy(tp, MII_BMSR, &tmp))
  1705. continue;
  1706. if (!(tmp & BMSR_LSTATUS)) {
  1707. udelay(40);
  1708. break;
  1709. }
  1710. }
  1711. tg3_writephy(tp, MII_BMCR, bmcr);
  1712. udelay(40);
  1713. }
  1714. } else {
  1715. tg3_writephy(tp, MII_BMCR,
  1716. BMCR_ANENABLE | BMCR_ANRESTART);
  1717. }
  1718. }
  1719. static int tg3_init_5401phy_dsp(struct tg3 *tp)
  1720. {
  1721. int err;
  1722. /* Turn off tap power management. */
  1723. /* Set Extended packet length bit */
  1724. err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20);
  1725. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012);
  1726. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804);
  1727. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013);
  1728. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204);
  1729. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1730. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132);
  1731. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006);
  1732. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232);
  1733. err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f);
  1734. err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20);
  1735. udelay(40);
  1736. return err;
  1737. }
  1738. static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask)
  1739. {
  1740. u32 adv_reg, all_mask = 0;
  1741. if (mask & ADVERTISED_10baseT_Half)
  1742. all_mask |= ADVERTISE_10HALF;
  1743. if (mask & ADVERTISED_10baseT_Full)
  1744. all_mask |= ADVERTISE_10FULL;
  1745. if (mask & ADVERTISED_100baseT_Half)
  1746. all_mask |= ADVERTISE_100HALF;
  1747. if (mask & ADVERTISED_100baseT_Full)
  1748. all_mask |= ADVERTISE_100FULL;
  1749. if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg))
  1750. return 0;
  1751. if ((adv_reg & all_mask) != all_mask)
  1752. return 0;
  1753. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  1754. u32 tg3_ctrl;
  1755. all_mask = 0;
  1756. if (mask & ADVERTISED_1000baseT_Half)
  1757. all_mask |= ADVERTISE_1000HALF;
  1758. if (mask & ADVERTISED_1000baseT_Full)
  1759. all_mask |= ADVERTISE_1000FULL;
  1760. if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl))
  1761. return 0;
  1762. if ((tg3_ctrl & all_mask) != all_mask)
  1763. return 0;
  1764. }
  1765. return 1;
  1766. }
  1767. static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv)
  1768. {
  1769. u32 curadv, reqadv;
  1770. if (tg3_readphy(tp, MII_ADVERTISE, lcladv))
  1771. return 1;
  1772. curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  1773. reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl);
  1774. if (tp->link_config.active_duplex == DUPLEX_FULL) {
  1775. if (curadv != reqadv)
  1776. return 0;
  1777. if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)
  1778. tg3_readphy(tp, MII_LPA, rmtadv);
  1779. } else {
  1780. /* Reprogram the advertisement register, even if it
  1781. * does not affect the current link. If the link
  1782. * gets renegotiated in the future, we can save an
  1783. * additional renegotiation cycle by advertising
  1784. * it correctly in the first place.
  1785. */
  1786. if (curadv != reqadv) {
  1787. *lcladv &= ~(ADVERTISE_PAUSE_CAP |
  1788. ADVERTISE_PAUSE_ASYM);
  1789. tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv);
  1790. }
  1791. }
  1792. return 1;
  1793. }
  1794. static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
  1795. {
  1796. int current_link_up;
  1797. u32 bmsr, dummy;
  1798. u32 lcl_adv, rmt_adv;
  1799. u16 current_speed;
  1800. u8 current_duplex;
  1801. int i, err;
  1802. tw32(MAC_EVENT, 0);
  1803. tw32_f(MAC_STATUS,
  1804. (MAC_STATUS_SYNC_CHANGED |
  1805. MAC_STATUS_CFG_CHANGED |
  1806. MAC_STATUS_MI_COMPLETION |
  1807. MAC_STATUS_LNKSTATE_CHANGED));
  1808. udelay(40);
  1809. if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
  1810. tw32_f(MAC_MI_MODE,
  1811. (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
  1812. udelay(80);
  1813. }
  1814. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
  1815. /* Some third-party PHYs need to be reset on link going
  1816. * down.
  1817. */
  1818. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  1819. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
  1820. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  1821. netif_carrier_ok(tp->dev)) {
  1822. tg3_readphy(tp, MII_BMSR, &bmsr);
  1823. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1824. !(bmsr & BMSR_LSTATUS))
  1825. force_reset = 1;
  1826. }
  1827. if (force_reset)
  1828. tg3_phy_reset(tp);
  1829. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  1830. tg3_readphy(tp, MII_BMSR, &bmsr);
  1831. if (tg3_readphy(tp, MII_BMSR, &bmsr) ||
  1832. !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE))
  1833. bmsr = 0;
  1834. if (!(bmsr & BMSR_LSTATUS)) {
  1835. err = tg3_init_5401phy_dsp(tp);
  1836. if (err)
  1837. return err;
  1838. tg3_readphy(tp, MII_BMSR, &bmsr);
  1839. for (i = 0; i < 1000; i++) {
  1840. udelay(10);
  1841. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1842. (bmsr & BMSR_LSTATUS)) {
  1843. udelay(40);
  1844. break;
  1845. }
  1846. }
  1847. if ((tp->phy_id & PHY_ID_REV_MASK) == PHY_REV_BCM5401_B0 &&
  1848. !(bmsr & BMSR_LSTATUS) &&
  1849. tp->link_config.active_speed == SPEED_1000) {
  1850. err = tg3_phy_reset(tp);
  1851. if (!err)
  1852. err = tg3_init_5401phy_dsp(tp);
  1853. if (err)
  1854. return err;
  1855. }
  1856. }
  1857. } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  1858. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) {
  1859. /* 5701 {A0,B0} CRC bug workaround */
  1860. tg3_writephy(tp, 0x15, 0x0a75);
  1861. tg3_writephy(tp, 0x1c, 0x8c68);
  1862. tg3_writephy(tp, 0x1c, 0x8d68);
  1863. tg3_writephy(tp, 0x1c, 0x8c68);
  1864. }
  1865. /* Clear pending interrupts... */
  1866. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1867. tg3_readphy(tp, MII_TG3_ISTAT, &dummy);
  1868. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT)
  1869. tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG);
  1870. else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  1871. tg3_writephy(tp, MII_TG3_IMASK, ~0);
  1872. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  1873. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  1874. if (tp->led_ctrl == LED_CTRL_MODE_PHY_1)
  1875. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  1876. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  1877. else
  1878. tg3_writephy(tp, MII_TG3_EXT_CTRL, 0);
  1879. }
  1880. current_link_up = 0;
  1881. current_speed = SPEED_INVALID;
  1882. current_duplex = DUPLEX_INVALID;
  1883. if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) {
  1884. u32 val;
  1885. tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007);
  1886. tg3_readphy(tp, MII_TG3_AUX_CTRL, &val);
  1887. if (!(val & (1 << 10))) {
  1888. val |= (1 << 10);
  1889. tg3_writephy(tp, MII_TG3_AUX_CTRL, val);
  1890. goto relink;
  1891. }
  1892. }
  1893. bmsr = 0;
  1894. for (i = 0; i < 100; i++) {
  1895. tg3_readphy(tp, MII_BMSR, &bmsr);
  1896. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  1897. (bmsr & BMSR_LSTATUS))
  1898. break;
  1899. udelay(40);
  1900. }
  1901. if (bmsr & BMSR_LSTATUS) {
  1902. u32 aux_stat, bmcr;
  1903. tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat);
  1904. for (i = 0; i < 2000; i++) {
  1905. udelay(10);
  1906. if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) &&
  1907. aux_stat)
  1908. break;
  1909. }
  1910. tg3_aux_stat_to_speed_duplex(tp, aux_stat,
  1911. &current_speed,
  1912. &current_duplex);
  1913. bmcr = 0;
  1914. for (i = 0; i < 200; i++) {
  1915. tg3_readphy(tp, MII_BMCR, &bmcr);
  1916. if (tg3_readphy(tp, MII_BMCR, &bmcr))
  1917. continue;
  1918. if (bmcr && bmcr != 0x7fff)
  1919. break;
  1920. udelay(10);
  1921. }
  1922. lcl_adv = 0;
  1923. rmt_adv = 0;
  1924. tp->link_config.active_speed = current_speed;
  1925. tp->link_config.active_duplex = current_duplex;
  1926. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  1927. if ((bmcr & BMCR_ANENABLE) &&
  1928. tg3_copper_is_advertising_all(tp,
  1929. tp->link_config.advertising)) {
  1930. if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv,
  1931. &rmt_adv))
  1932. current_link_up = 1;
  1933. }
  1934. } else {
  1935. if (!(bmcr & BMCR_ANENABLE) &&
  1936. tp->link_config.speed == current_speed &&
  1937. tp->link_config.duplex == current_duplex &&
  1938. tp->link_config.flowctrl ==
  1939. tp->link_config.active_flowctrl) {
  1940. current_link_up = 1;
  1941. }
  1942. }
  1943. if (current_link_up == 1 &&
  1944. tp->link_config.active_duplex == DUPLEX_FULL)
  1945. tg3_setup_flow_control(tp, lcl_adv, rmt_adv);
  1946. }
  1947. relink:
  1948. if (current_link_up == 0 || tp->link_config.phy_is_low_power) {
  1949. u32 tmp;
  1950. tg3_phy_copper_begin(tp);
  1951. tg3_readphy(tp, MII_BMSR, &tmp);
  1952. if (!tg3_readphy(tp, MII_BMSR, &tmp) &&
  1953. (tmp & BMSR_LSTATUS))
  1954. current_link_up = 1;
  1955. }
  1956. tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK;
  1957. if (current_link_up == 1) {
  1958. if (tp->link_config.active_speed == SPEED_100 ||
  1959. tp->link_config.active_speed == SPEED_10)
  1960. tp->mac_mode |= MAC_MODE_PORT_MODE_MII;
  1961. else
  1962. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1963. } else
  1964. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  1965. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  1966. if (tp->link_config.active_duplex == DUPLEX_HALF)
  1967. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  1968. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  1969. if (current_link_up == 1 &&
  1970. tg3_5700_link_polarity(tp, tp->link_config.active_speed))
  1971. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  1972. else
  1973. tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
  1974. }
  1975. /* ??? Without this setting Netgear GA302T PHY does not
  1976. * ??? send/receive packets...
  1977. */
  1978. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
  1979. tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
  1980. tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
  1981. tw32_f(MAC_MI_MODE, tp->mi_mode);
  1982. udelay(80);
  1983. }
  1984. tw32_f(MAC_MODE, tp->mac_mode);
  1985. udelay(40);
  1986. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  1987. /* Polled via timer. */
  1988. tw32_f(MAC_EVENT, 0);
  1989. } else {
  1990. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  1991. }
  1992. udelay(40);
  1993. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 &&
  1994. current_link_up == 1 &&
  1995. tp->link_config.active_speed == SPEED_1000 &&
  1996. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) ||
  1997. (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) {
  1998. udelay(120);
  1999. tw32_f(MAC_STATUS,
  2000. (MAC_STATUS_SYNC_CHANGED |
  2001. MAC_STATUS_CFG_CHANGED));
  2002. udelay(40);
  2003. tg3_write_mem(tp,
  2004. NIC_SRAM_FIRMWARE_MBOX,
  2005. NIC_SRAM_FIRMWARE_MBOX_MAGIC2);
  2006. }
  2007. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2008. if (current_link_up)
  2009. netif_carrier_on(tp->dev);
  2010. else
  2011. netif_carrier_off(tp->dev);
  2012. tg3_link_report(tp);
  2013. }
  2014. return 0;
  2015. }
  2016. struct tg3_fiber_aneginfo {
  2017. int state;
  2018. #define ANEG_STATE_UNKNOWN 0
  2019. #define ANEG_STATE_AN_ENABLE 1
  2020. #define ANEG_STATE_RESTART_INIT 2
  2021. #define ANEG_STATE_RESTART 3
  2022. #define ANEG_STATE_DISABLE_LINK_OK 4
  2023. #define ANEG_STATE_ABILITY_DETECT_INIT 5
  2024. #define ANEG_STATE_ABILITY_DETECT 6
  2025. #define ANEG_STATE_ACK_DETECT_INIT 7
  2026. #define ANEG_STATE_ACK_DETECT 8
  2027. #define ANEG_STATE_COMPLETE_ACK_INIT 9
  2028. #define ANEG_STATE_COMPLETE_ACK 10
  2029. #define ANEG_STATE_IDLE_DETECT_INIT 11
  2030. #define ANEG_STATE_IDLE_DETECT 12
  2031. #define ANEG_STATE_LINK_OK 13
  2032. #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14
  2033. #define ANEG_STATE_NEXT_PAGE_WAIT 15
  2034. u32 flags;
  2035. #define MR_AN_ENABLE 0x00000001
  2036. #define MR_RESTART_AN 0x00000002
  2037. #define MR_AN_COMPLETE 0x00000004
  2038. #define MR_PAGE_RX 0x00000008
  2039. #define MR_NP_LOADED 0x00000010
  2040. #define MR_TOGGLE_TX 0x00000020
  2041. #define MR_LP_ADV_FULL_DUPLEX 0x00000040
  2042. #define MR_LP_ADV_HALF_DUPLEX 0x00000080
  2043. #define MR_LP_ADV_SYM_PAUSE 0x00000100
  2044. #define MR_LP_ADV_ASYM_PAUSE 0x00000200
  2045. #define MR_LP_ADV_REMOTE_FAULT1 0x00000400
  2046. #define MR_LP_ADV_REMOTE_FAULT2 0x00000800
  2047. #define MR_LP_ADV_NEXT_PAGE 0x00001000
  2048. #define MR_TOGGLE_RX 0x00002000
  2049. #define MR_NP_RX 0x00004000
  2050. #define MR_LINK_OK 0x80000000
  2051. unsigned long link_time, cur_time;
  2052. u32 ability_match_cfg;
  2053. int ability_match_count;
  2054. char ability_match, idle_match, ack_match;
  2055. u32 txconfig, rxconfig;
  2056. #define ANEG_CFG_NP 0x00000080
  2057. #define ANEG_CFG_ACK 0x00000040
  2058. #define ANEG_CFG_RF2 0x00000020
  2059. #define ANEG_CFG_RF1 0x00000010
  2060. #define ANEG_CFG_PS2 0x00000001
  2061. #define ANEG_CFG_PS1 0x00008000
  2062. #define ANEG_CFG_HD 0x00004000
  2063. #define ANEG_CFG_FD 0x00002000
  2064. #define ANEG_CFG_INVAL 0x00001f06
  2065. };
  2066. #define ANEG_OK 0
  2067. #define ANEG_DONE 1
  2068. #define ANEG_TIMER_ENAB 2
  2069. #define ANEG_FAILED -1
  2070. #define ANEG_STATE_SETTLE_TIME 10000
  2071. static int tg3_fiber_aneg_smachine(struct tg3 *tp,
  2072. struct tg3_fiber_aneginfo *ap)
  2073. {
  2074. u16 flowctrl;
  2075. unsigned long delta;
  2076. u32 rx_cfg_reg;
  2077. int ret;
  2078. if (ap->state == ANEG_STATE_UNKNOWN) {
  2079. ap->rxconfig = 0;
  2080. ap->link_time = 0;
  2081. ap->cur_time = 0;
  2082. ap->ability_match_cfg = 0;
  2083. ap->ability_match_count = 0;
  2084. ap->ability_match = 0;
  2085. ap->idle_match = 0;
  2086. ap->ack_match = 0;
  2087. }
  2088. ap->cur_time++;
  2089. if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) {
  2090. rx_cfg_reg = tr32(MAC_RX_AUTO_NEG);
  2091. if (rx_cfg_reg != ap->ability_match_cfg) {
  2092. ap->ability_match_cfg = rx_cfg_reg;
  2093. ap->ability_match = 0;
  2094. ap->ability_match_count = 0;
  2095. } else {
  2096. if (++ap->ability_match_count > 1) {
  2097. ap->ability_match = 1;
  2098. ap->ability_match_cfg = rx_cfg_reg;
  2099. }
  2100. }
  2101. if (rx_cfg_reg & ANEG_CFG_ACK)
  2102. ap->ack_match = 1;
  2103. else
  2104. ap->ack_match = 0;
  2105. ap->idle_match = 0;
  2106. } else {
  2107. ap->idle_match = 1;
  2108. ap->ability_match_cfg = 0;
  2109. ap->ability_match_count = 0;
  2110. ap->ability_match = 0;
  2111. ap->ack_match = 0;
  2112. rx_cfg_reg = 0;
  2113. }
  2114. ap->rxconfig = rx_cfg_reg;
  2115. ret = ANEG_OK;
  2116. switch(ap->state) {
  2117. case ANEG_STATE_UNKNOWN:
  2118. if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN))
  2119. ap->state = ANEG_STATE_AN_ENABLE;
  2120. /* fallthru */
  2121. case ANEG_STATE_AN_ENABLE:
  2122. ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX);
  2123. if (ap->flags & MR_AN_ENABLE) {
  2124. ap->link_time = 0;
  2125. ap->cur_time = 0;
  2126. ap->ability_match_cfg = 0;
  2127. ap->ability_match_count = 0;
  2128. ap->ability_match = 0;
  2129. ap->idle_match = 0;
  2130. ap->ack_match = 0;
  2131. ap->state = ANEG_STATE_RESTART_INIT;
  2132. } else {
  2133. ap->state = ANEG_STATE_DISABLE_LINK_OK;
  2134. }
  2135. break;
  2136. case ANEG_STATE_RESTART_INIT:
  2137. ap->link_time = ap->cur_time;
  2138. ap->flags &= ~(MR_NP_LOADED);
  2139. ap->txconfig = 0;
  2140. tw32(MAC_TX_AUTO_NEG, 0);
  2141. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2142. tw32_f(MAC_MODE, tp->mac_mode);
  2143. udelay(40);
  2144. ret = ANEG_TIMER_ENAB;
  2145. ap->state = ANEG_STATE_RESTART;
  2146. /* fallthru */
  2147. case ANEG_STATE_RESTART:
  2148. delta = ap->cur_time - ap->link_time;
  2149. if (delta > ANEG_STATE_SETTLE_TIME) {
  2150. ap->state = ANEG_STATE_ABILITY_DETECT_INIT;
  2151. } else {
  2152. ret = ANEG_TIMER_ENAB;
  2153. }
  2154. break;
  2155. case ANEG_STATE_DISABLE_LINK_OK:
  2156. ret = ANEG_DONE;
  2157. break;
  2158. case ANEG_STATE_ABILITY_DETECT_INIT:
  2159. ap->flags &= ~(MR_TOGGLE_TX);
  2160. ap->txconfig = ANEG_CFG_FD;
  2161. flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2162. if (flowctrl & ADVERTISE_1000XPAUSE)
  2163. ap->txconfig |= ANEG_CFG_PS1;
  2164. if (flowctrl & ADVERTISE_1000XPSE_ASYM)
  2165. ap->txconfig |= ANEG_CFG_PS2;
  2166. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  2167. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2168. tw32_f(MAC_MODE, tp->mac_mode);
  2169. udelay(40);
  2170. ap->state = ANEG_STATE_ABILITY_DETECT;
  2171. break;
  2172. case ANEG_STATE_ABILITY_DETECT:
  2173. if (ap->ability_match != 0 && ap->rxconfig != 0) {
  2174. ap->state = ANEG_STATE_ACK_DETECT_INIT;
  2175. }
  2176. break;
  2177. case ANEG_STATE_ACK_DETECT_INIT:
  2178. ap->txconfig |= ANEG_CFG_ACK;
  2179. tw32(MAC_TX_AUTO_NEG, ap->txconfig);
  2180. tp->mac_mode |= MAC_MODE_SEND_CONFIGS;
  2181. tw32_f(MAC_MODE, tp->mac_mode);
  2182. udelay(40);
  2183. ap->state = ANEG_STATE_ACK_DETECT;
  2184. /* fallthru */
  2185. case ANEG_STATE_ACK_DETECT:
  2186. if (ap->ack_match != 0) {
  2187. if ((ap->rxconfig & ~ANEG_CFG_ACK) ==
  2188. (ap->ability_match_cfg & ~ANEG_CFG_ACK)) {
  2189. ap->state = ANEG_STATE_COMPLETE_ACK_INIT;
  2190. } else {
  2191. ap->state = ANEG_STATE_AN_ENABLE;
  2192. }
  2193. } else if (ap->ability_match != 0 &&
  2194. ap->rxconfig == 0) {
  2195. ap->state = ANEG_STATE_AN_ENABLE;
  2196. }
  2197. break;
  2198. case ANEG_STATE_COMPLETE_ACK_INIT:
  2199. if (ap->rxconfig & ANEG_CFG_INVAL) {
  2200. ret = ANEG_FAILED;
  2201. break;
  2202. }
  2203. ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX |
  2204. MR_LP_ADV_HALF_DUPLEX |
  2205. MR_LP_ADV_SYM_PAUSE |
  2206. MR_LP_ADV_ASYM_PAUSE |
  2207. MR_LP_ADV_REMOTE_FAULT1 |
  2208. MR_LP_ADV_REMOTE_FAULT2 |
  2209. MR_LP_ADV_NEXT_PAGE |
  2210. MR_TOGGLE_RX |
  2211. MR_NP_RX);
  2212. if (ap->rxconfig & ANEG_CFG_FD)
  2213. ap->flags |= MR_LP_ADV_FULL_DUPLEX;
  2214. if (ap->rxconfig & ANEG_CFG_HD)
  2215. ap->flags |= MR_LP_ADV_HALF_DUPLEX;
  2216. if (ap->rxconfig & ANEG_CFG_PS1)
  2217. ap->flags |= MR_LP_ADV_SYM_PAUSE;
  2218. if (ap->rxconfig & ANEG_CFG_PS2)
  2219. ap->flags |= MR_LP_ADV_ASYM_PAUSE;
  2220. if (ap->rxconfig & ANEG_CFG_RF1)
  2221. ap->flags |= MR_LP_ADV_REMOTE_FAULT1;
  2222. if (ap->rxconfig & ANEG_CFG_RF2)
  2223. ap->flags |= MR_LP_ADV_REMOTE_FAULT2;
  2224. if (ap->rxconfig & ANEG_CFG_NP)
  2225. ap->flags |= MR_LP_ADV_NEXT_PAGE;
  2226. ap->link_time = ap->cur_time;
  2227. ap->flags ^= (MR_TOGGLE_TX);
  2228. if (ap->rxconfig & 0x0008)
  2229. ap->flags |= MR_TOGGLE_RX;
  2230. if (ap->rxconfig & ANEG_CFG_NP)
  2231. ap->flags |= MR_NP_RX;
  2232. ap->flags |= MR_PAGE_RX;
  2233. ap->state = ANEG_STATE_COMPLETE_ACK;
  2234. ret = ANEG_TIMER_ENAB;
  2235. break;
  2236. case ANEG_STATE_COMPLETE_ACK:
  2237. if (ap->ability_match != 0 &&
  2238. ap->rxconfig == 0) {
  2239. ap->state = ANEG_STATE_AN_ENABLE;
  2240. break;
  2241. }
  2242. delta = ap->cur_time - ap->link_time;
  2243. if (delta > ANEG_STATE_SETTLE_TIME) {
  2244. if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) {
  2245. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2246. } else {
  2247. if ((ap->txconfig & ANEG_CFG_NP) == 0 &&
  2248. !(ap->flags & MR_NP_RX)) {
  2249. ap->state = ANEG_STATE_IDLE_DETECT_INIT;
  2250. } else {
  2251. ret = ANEG_FAILED;
  2252. }
  2253. }
  2254. }
  2255. break;
  2256. case ANEG_STATE_IDLE_DETECT_INIT:
  2257. ap->link_time = ap->cur_time;
  2258. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2259. tw32_f(MAC_MODE, tp->mac_mode);
  2260. udelay(40);
  2261. ap->state = ANEG_STATE_IDLE_DETECT;
  2262. ret = ANEG_TIMER_ENAB;
  2263. break;
  2264. case ANEG_STATE_IDLE_DETECT:
  2265. if (ap->ability_match != 0 &&
  2266. ap->rxconfig == 0) {
  2267. ap->state = ANEG_STATE_AN_ENABLE;
  2268. break;
  2269. }
  2270. delta = ap->cur_time - ap->link_time;
  2271. if (delta > ANEG_STATE_SETTLE_TIME) {
  2272. /* XXX another gem from the Broadcom driver :( */
  2273. ap->state = ANEG_STATE_LINK_OK;
  2274. }
  2275. break;
  2276. case ANEG_STATE_LINK_OK:
  2277. ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK);
  2278. ret = ANEG_DONE;
  2279. break;
  2280. case ANEG_STATE_NEXT_PAGE_WAIT_INIT:
  2281. /* ??? unimplemented */
  2282. break;
  2283. case ANEG_STATE_NEXT_PAGE_WAIT:
  2284. /* ??? unimplemented */
  2285. break;
  2286. default:
  2287. ret = ANEG_FAILED;
  2288. break;
  2289. };
  2290. return ret;
  2291. }
  2292. static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags)
  2293. {
  2294. int res = 0;
  2295. struct tg3_fiber_aneginfo aninfo;
  2296. int status = ANEG_FAILED;
  2297. unsigned int tick;
  2298. u32 tmp;
  2299. tw32_f(MAC_TX_AUTO_NEG, 0);
  2300. tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  2301. tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII);
  2302. udelay(40);
  2303. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS);
  2304. udelay(40);
  2305. memset(&aninfo, 0, sizeof(aninfo));
  2306. aninfo.flags |= MR_AN_ENABLE;
  2307. aninfo.state = ANEG_STATE_UNKNOWN;
  2308. aninfo.cur_time = 0;
  2309. tick = 0;
  2310. while (++tick < 195000) {
  2311. status = tg3_fiber_aneg_smachine(tp, &aninfo);
  2312. if (status == ANEG_DONE || status == ANEG_FAILED)
  2313. break;
  2314. udelay(1);
  2315. }
  2316. tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS;
  2317. tw32_f(MAC_MODE, tp->mac_mode);
  2318. udelay(40);
  2319. *txflags = aninfo.txconfig;
  2320. *rxflags = aninfo.flags;
  2321. if (status == ANEG_DONE &&
  2322. (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK |
  2323. MR_LP_ADV_FULL_DUPLEX)))
  2324. res = 1;
  2325. return res;
  2326. }
  2327. static void tg3_init_bcm8002(struct tg3 *tp)
  2328. {
  2329. u32 mac_status = tr32(MAC_STATUS);
  2330. int i;
  2331. /* Reset when initting first time or we have a link. */
  2332. if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) &&
  2333. !(mac_status & MAC_STATUS_PCS_SYNCED))
  2334. return;
  2335. /* Set PLL lock range. */
  2336. tg3_writephy(tp, 0x16, 0x8007);
  2337. /* SW reset */
  2338. tg3_writephy(tp, MII_BMCR, BMCR_RESET);
  2339. /* Wait for reset to complete. */
  2340. /* XXX schedule_timeout() ... */
  2341. for (i = 0; i < 500; i++)
  2342. udelay(10);
  2343. /* Config mode; select PMA/Ch 1 regs. */
  2344. tg3_writephy(tp, 0x10, 0x8411);
  2345. /* Enable auto-lock and comdet, select txclk for tx. */
  2346. tg3_writephy(tp, 0x11, 0x0a10);
  2347. tg3_writephy(tp, 0x18, 0x00a0);
  2348. tg3_writephy(tp, 0x16, 0x41ff);
  2349. /* Assert and deassert POR. */
  2350. tg3_writephy(tp, 0x13, 0x0400);
  2351. udelay(40);
  2352. tg3_writephy(tp, 0x13, 0x0000);
  2353. tg3_writephy(tp, 0x11, 0x0a50);
  2354. udelay(40);
  2355. tg3_writephy(tp, 0x11, 0x0a10);
  2356. /* Wait for signal to stabilize */
  2357. /* XXX schedule_timeout() ... */
  2358. for (i = 0; i < 15000; i++)
  2359. udelay(10);
  2360. /* Deselect the channel register so we can read the PHYID
  2361. * later.
  2362. */
  2363. tg3_writephy(tp, 0x10, 0x8011);
  2364. }
  2365. static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
  2366. {
  2367. u16 flowctrl;
  2368. u32 sg_dig_ctrl, sg_dig_status;
  2369. u32 serdes_cfg, expected_sg_dig_ctrl;
  2370. int workaround, port_a;
  2371. int current_link_up;
  2372. serdes_cfg = 0;
  2373. expected_sg_dig_ctrl = 0;
  2374. workaround = 0;
  2375. port_a = 1;
  2376. current_link_up = 0;
  2377. if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 &&
  2378. tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) {
  2379. workaround = 1;
  2380. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  2381. port_a = 0;
  2382. /* preserve bits 0-11,13,14 for signal pre-emphasis */
  2383. /* preserve bits 20-23 for voltage regulator */
  2384. serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff;
  2385. }
  2386. sg_dig_ctrl = tr32(SG_DIG_CTRL);
  2387. if (tp->link_config.autoneg != AUTONEG_ENABLE) {
  2388. if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) {
  2389. if (workaround) {
  2390. u32 val = serdes_cfg;
  2391. if (port_a)
  2392. val |= 0xc010000;
  2393. else
  2394. val |= 0x4010000;
  2395. tw32_f(MAC_SERDES_CFG, val);
  2396. }
  2397. tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
  2398. }
  2399. if (mac_status & MAC_STATUS_PCS_SYNCED) {
  2400. tg3_setup_flow_control(tp, 0, 0);
  2401. current_link_up = 1;
  2402. }
  2403. goto out;
  2404. }
  2405. /* Want auto-negotiation. */
  2406. expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP;
  2407. flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2408. if (flowctrl & ADVERTISE_1000XPAUSE)
  2409. expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP;
  2410. if (flowctrl & ADVERTISE_1000XPSE_ASYM)
  2411. expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE;
  2412. if (sg_dig_ctrl != expected_sg_dig_ctrl) {
  2413. if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2414. tp->serdes_counter &&
  2415. ((mac_status & (MAC_STATUS_PCS_SYNCED |
  2416. MAC_STATUS_RCVD_CFG)) ==
  2417. MAC_STATUS_PCS_SYNCED)) {
  2418. tp->serdes_counter--;
  2419. current_link_up = 1;
  2420. goto out;
  2421. }
  2422. restart_autoneg:
  2423. if (workaround)
  2424. tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
  2425. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET);
  2426. udelay(5);
  2427. tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl);
  2428. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2429. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2430. } else if (mac_status & (MAC_STATUS_PCS_SYNCED |
  2431. MAC_STATUS_SIGNAL_DET)) {
  2432. sg_dig_status = tr32(SG_DIG_STATUS);
  2433. mac_status = tr32(MAC_STATUS);
  2434. if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) &&
  2435. (mac_status & MAC_STATUS_PCS_SYNCED)) {
  2436. u32 local_adv = 0, remote_adv = 0;
  2437. if (sg_dig_ctrl & SG_DIG_PAUSE_CAP)
  2438. local_adv |= ADVERTISE_1000XPAUSE;
  2439. if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE)
  2440. local_adv |= ADVERTISE_1000XPSE_ASYM;
  2441. if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE)
  2442. remote_adv |= LPA_1000XPAUSE;
  2443. if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE)
  2444. remote_adv |= LPA_1000XPAUSE_ASYM;
  2445. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2446. current_link_up = 1;
  2447. tp->serdes_counter = 0;
  2448. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2449. } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) {
  2450. if (tp->serdes_counter)
  2451. tp->serdes_counter--;
  2452. else {
  2453. if (workaround) {
  2454. u32 val = serdes_cfg;
  2455. if (port_a)
  2456. val |= 0xc010000;
  2457. else
  2458. val |= 0x4010000;
  2459. tw32_f(MAC_SERDES_CFG, val);
  2460. }
  2461. tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP);
  2462. udelay(40);
  2463. /* Link parallel detection - link is up */
  2464. /* only if we have PCS_SYNC and not */
  2465. /* receiving config code words */
  2466. mac_status = tr32(MAC_STATUS);
  2467. if ((mac_status & MAC_STATUS_PCS_SYNCED) &&
  2468. !(mac_status & MAC_STATUS_RCVD_CFG)) {
  2469. tg3_setup_flow_control(tp, 0, 0);
  2470. current_link_up = 1;
  2471. tp->tg3_flags2 |=
  2472. TG3_FLG2_PARALLEL_DETECT;
  2473. tp->serdes_counter =
  2474. SERDES_PARALLEL_DET_TIMEOUT;
  2475. } else
  2476. goto restart_autoneg;
  2477. }
  2478. }
  2479. } else {
  2480. tp->serdes_counter = SERDES_AN_TIMEOUT_5704S;
  2481. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2482. }
  2483. out:
  2484. return current_link_up;
  2485. }
  2486. static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
  2487. {
  2488. int current_link_up = 0;
  2489. if (!(mac_status & MAC_STATUS_PCS_SYNCED))
  2490. goto out;
  2491. if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2492. u32 txflags, rxflags;
  2493. int i;
  2494. if (fiber_autoneg(tp, &txflags, &rxflags)) {
  2495. u32 local_adv = 0, remote_adv = 0;
  2496. if (txflags & ANEG_CFG_PS1)
  2497. local_adv |= ADVERTISE_1000XPAUSE;
  2498. if (txflags & ANEG_CFG_PS2)
  2499. local_adv |= ADVERTISE_1000XPSE_ASYM;
  2500. if (rxflags & MR_LP_ADV_SYM_PAUSE)
  2501. remote_adv |= LPA_1000XPAUSE;
  2502. if (rxflags & MR_LP_ADV_ASYM_PAUSE)
  2503. remote_adv |= LPA_1000XPAUSE_ASYM;
  2504. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2505. current_link_up = 1;
  2506. }
  2507. for (i = 0; i < 30; i++) {
  2508. udelay(20);
  2509. tw32_f(MAC_STATUS,
  2510. (MAC_STATUS_SYNC_CHANGED |
  2511. MAC_STATUS_CFG_CHANGED));
  2512. udelay(40);
  2513. if ((tr32(MAC_STATUS) &
  2514. (MAC_STATUS_SYNC_CHANGED |
  2515. MAC_STATUS_CFG_CHANGED)) == 0)
  2516. break;
  2517. }
  2518. mac_status = tr32(MAC_STATUS);
  2519. if (current_link_up == 0 &&
  2520. (mac_status & MAC_STATUS_PCS_SYNCED) &&
  2521. !(mac_status & MAC_STATUS_RCVD_CFG))
  2522. current_link_up = 1;
  2523. } else {
  2524. tg3_setup_flow_control(tp, 0, 0);
  2525. /* Forcing 1000FD link up. */
  2526. current_link_up = 1;
  2527. tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
  2528. udelay(40);
  2529. tw32_f(MAC_MODE, tp->mac_mode);
  2530. udelay(40);
  2531. }
  2532. out:
  2533. return current_link_up;
  2534. }
  2535. static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
  2536. {
  2537. u32 orig_pause_cfg;
  2538. u16 orig_active_speed;
  2539. u8 orig_active_duplex;
  2540. u32 mac_status;
  2541. int current_link_up;
  2542. int i;
  2543. orig_pause_cfg = tp->link_config.active_flowctrl;
  2544. orig_active_speed = tp->link_config.active_speed;
  2545. orig_active_duplex = tp->link_config.active_duplex;
  2546. if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) &&
  2547. netif_carrier_ok(tp->dev) &&
  2548. (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) {
  2549. mac_status = tr32(MAC_STATUS);
  2550. mac_status &= (MAC_STATUS_PCS_SYNCED |
  2551. MAC_STATUS_SIGNAL_DET |
  2552. MAC_STATUS_CFG_CHANGED |
  2553. MAC_STATUS_RCVD_CFG);
  2554. if (mac_status == (MAC_STATUS_PCS_SYNCED |
  2555. MAC_STATUS_SIGNAL_DET)) {
  2556. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2557. MAC_STATUS_CFG_CHANGED));
  2558. return 0;
  2559. }
  2560. }
  2561. tw32_f(MAC_TX_AUTO_NEG, 0);
  2562. tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX);
  2563. tp->mac_mode |= MAC_MODE_PORT_MODE_TBI;
  2564. tw32_f(MAC_MODE, tp->mac_mode);
  2565. udelay(40);
  2566. if (tp->phy_id == PHY_ID_BCM8002)
  2567. tg3_init_bcm8002(tp);
  2568. /* Enable link change event even when serdes polling. */
  2569. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2570. udelay(40);
  2571. current_link_up = 0;
  2572. mac_status = tr32(MAC_STATUS);
  2573. if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG)
  2574. current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status);
  2575. else
  2576. current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
  2577. tp->hw_status->status =
  2578. (SD_STATUS_UPDATED |
  2579. (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
  2580. for (i = 0; i < 100; i++) {
  2581. tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED |
  2582. MAC_STATUS_CFG_CHANGED));
  2583. udelay(5);
  2584. if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED |
  2585. MAC_STATUS_CFG_CHANGED |
  2586. MAC_STATUS_LNKSTATE_CHANGED)) == 0)
  2587. break;
  2588. }
  2589. mac_status = tr32(MAC_STATUS);
  2590. if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) {
  2591. current_link_up = 0;
  2592. if (tp->link_config.autoneg == AUTONEG_ENABLE &&
  2593. tp->serdes_counter == 0) {
  2594. tw32_f(MAC_MODE, (tp->mac_mode |
  2595. MAC_MODE_SEND_CONFIGS));
  2596. udelay(1);
  2597. tw32_f(MAC_MODE, tp->mac_mode);
  2598. }
  2599. }
  2600. if (current_link_up == 1) {
  2601. tp->link_config.active_speed = SPEED_1000;
  2602. tp->link_config.active_duplex = DUPLEX_FULL;
  2603. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2604. LED_CTRL_LNKLED_OVERRIDE |
  2605. LED_CTRL_1000MBPS_ON));
  2606. } else {
  2607. tp->link_config.active_speed = SPEED_INVALID;
  2608. tp->link_config.active_duplex = DUPLEX_INVALID;
  2609. tw32(MAC_LED_CTRL, (tp->led_ctrl |
  2610. LED_CTRL_LNKLED_OVERRIDE |
  2611. LED_CTRL_TRAFFIC_OVERRIDE));
  2612. }
  2613. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2614. if (current_link_up)
  2615. netif_carrier_on(tp->dev);
  2616. else
  2617. netif_carrier_off(tp->dev);
  2618. tg3_link_report(tp);
  2619. } else {
  2620. u32 now_pause_cfg = tp->link_config.active_flowctrl;
  2621. if (orig_pause_cfg != now_pause_cfg ||
  2622. orig_active_speed != tp->link_config.active_speed ||
  2623. orig_active_duplex != tp->link_config.active_duplex)
  2624. tg3_link_report(tp);
  2625. }
  2626. return 0;
  2627. }
  2628. static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset)
  2629. {
  2630. int current_link_up, err = 0;
  2631. u32 bmsr, bmcr;
  2632. u16 current_speed;
  2633. u8 current_duplex;
  2634. u32 local_adv, remote_adv;
  2635. tp->mac_mode |= MAC_MODE_PORT_MODE_GMII;
  2636. tw32_f(MAC_MODE, tp->mac_mode);
  2637. udelay(40);
  2638. tw32(MAC_EVENT, 0);
  2639. tw32_f(MAC_STATUS,
  2640. (MAC_STATUS_SYNC_CHANGED |
  2641. MAC_STATUS_CFG_CHANGED |
  2642. MAC_STATUS_MI_COMPLETION |
  2643. MAC_STATUS_LNKSTATE_CHANGED));
  2644. udelay(40);
  2645. if (force_reset)
  2646. tg3_phy_reset(tp);
  2647. current_link_up = 0;
  2648. current_speed = SPEED_INVALID;
  2649. current_duplex = DUPLEX_INVALID;
  2650. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2651. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2652. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  2653. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2654. bmsr |= BMSR_LSTATUS;
  2655. else
  2656. bmsr &= ~BMSR_LSTATUS;
  2657. }
  2658. err |= tg3_readphy(tp, MII_BMCR, &bmcr);
  2659. if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset &&
  2660. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) &&
  2661. tp->link_config.flowctrl == tp->link_config.active_flowctrl) {
  2662. /* do nothing, just check for link up at the end */
  2663. } else if (tp->link_config.autoneg == AUTONEG_ENABLE) {
  2664. u32 adv, new_adv;
  2665. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2666. new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF |
  2667. ADVERTISE_1000XPAUSE |
  2668. ADVERTISE_1000XPSE_ASYM |
  2669. ADVERTISE_SLCT);
  2670. new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl);
  2671. if (tp->link_config.advertising & ADVERTISED_1000baseT_Half)
  2672. new_adv |= ADVERTISE_1000XHALF;
  2673. if (tp->link_config.advertising & ADVERTISED_1000baseT_Full)
  2674. new_adv |= ADVERTISE_1000XFULL;
  2675. if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) {
  2676. tg3_writephy(tp, MII_ADVERTISE, new_adv);
  2677. bmcr |= BMCR_ANENABLE | BMCR_ANRESTART;
  2678. tg3_writephy(tp, MII_BMCR, bmcr);
  2679. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2680. tp->serdes_counter = SERDES_AN_TIMEOUT_5714S;
  2681. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2682. return err;
  2683. }
  2684. } else {
  2685. u32 new_bmcr;
  2686. bmcr &= ~BMCR_SPEED1000;
  2687. new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX);
  2688. if (tp->link_config.duplex == DUPLEX_FULL)
  2689. new_bmcr |= BMCR_FULLDPLX;
  2690. if (new_bmcr != bmcr) {
  2691. /* BMCR_SPEED1000 is a reserved bit that needs
  2692. * to be set on write.
  2693. */
  2694. new_bmcr |= BMCR_SPEED1000;
  2695. /* Force a linkdown */
  2696. if (netif_carrier_ok(tp->dev)) {
  2697. u32 adv;
  2698. err |= tg3_readphy(tp, MII_ADVERTISE, &adv);
  2699. adv &= ~(ADVERTISE_1000XFULL |
  2700. ADVERTISE_1000XHALF |
  2701. ADVERTISE_SLCT);
  2702. tg3_writephy(tp, MII_ADVERTISE, adv);
  2703. tg3_writephy(tp, MII_BMCR, bmcr |
  2704. BMCR_ANRESTART |
  2705. BMCR_ANENABLE);
  2706. udelay(10);
  2707. netif_carrier_off(tp->dev);
  2708. }
  2709. tg3_writephy(tp, MII_BMCR, new_bmcr);
  2710. bmcr = new_bmcr;
  2711. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2712. err |= tg3_readphy(tp, MII_BMSR, &bmsr);
  2713. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  2714. ASIC_REV_5714) {
  2715. if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP)
  2716. bmsr |= BMSR_LSTATUS;
  2717. else
  2718. bmsr &= ~BMSR_LSTATUS;
  2719. }
  2720. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2721. }
  2722. }
  2723. if (bmsr & BMSR_LSTATUS) {
  2724. current_speed = SPEED_1000;
  2725. current_link_up = 1;
  2726. if (bmcr & BMCR_FULLDPLX)
  2727. current_duplex = DUPLEX_FULL;
  2728. else
  2729. current_duplex = DUPLEX_HALF;
  2730. local_adv = 0;
  2731. remote_adv = 0;
  2732. if (bmcr & BMCR_ANENABLE) {
  2733. u32 common;
  2734. err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv);
  2735. err |= tg3_readphy(tp, MII_LPA, &remote_adv);
  2736. common = local_adv & remote_adv;
  2737. if (common & (ADVERTISE_1000XHALF |
  2738. ADVERTISE_1000XFULL)) {
  2739. if (common & ADVERTISE_1000XFULL)
  2740. current_duplex = DUPLEX_FULL;
  2741. else
  2742. current_duplex = DUPLEX_HALF;
  2743. }
  2744. else
  2745. current_link_up = 0;
  2746. }
  2747. }
  2748. if (current_link_up == 1 && current_duplex == DUPLEX_FULL)
  2749. tg3_setup_flow_control(tp, local_adv, remote_adv);
  2750. tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX;
  2751. if (tp->link_config.active_duplex == DUPLEX_HALF)
  2752. tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
  2753. tw32_f(MAC_MODE, tp->mac_mode);
  2754. udelay(40);
  2755. tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED);
  2756. tp->link_config.active_speed = current_speed;
  2757. tp->link_config.active_duplex = current_duplex;
  2758. if (current_link_up != netif_carrier_ok(tp->dev)) {
  2759. if (current_link_up)
  2760. netif_carrier_on(tp->dev);
  2761. else {
  2762. netif_carrier_off(tp->dev);
  2763. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2764. }
  2765. tg3_link_report(tp);
  2766. }
  2767. return err;
  2768. }
  2769. static void tg3_serdes_parallel_detect(struct tg3 *tp)
  2770. {
  2771. if (tp->serdes_counter) {
  2772. /* Give autoneg time to complete. */
  2773. tp->serdes_counter--;
  2774. return;
  2775. }
  2776. if (!netif_carrier_ok(tp->dev) &&
  2777. (tp->link_config.autoneg == AUTONEG_ENABLE)) {
  2778. u32 bmcr;
  2779. tg3_readphy(tp, MII_BMCR, &bmcr);
  2780. if (bmcr & BMCR_ANENABLE) {
  2781. u32 phy1, phy2;
  2782. /* Select shadow register 0x1f */
  2783. tg3_writephy(tp, 0x1c, 0x7c00);
  2784. tg3_readphy(tp, 0x1c, &phy1);
  2785. /* Select expansion interrupt status register */
  2786. tg3_writephy(tp, 0x17, 0x0f01);
  2787. tg3_readphy(tp, 0x15, &phy2);
  2788. tg3_readphy(tp, 0x15, &phy2);
  2789. if ((phy1 & 0x10) && !(phy2 & 0x20)) {
  2790. /* We have signal detect and not receiving
  2791. * config code words, link is up by parallel
  2792. * detection.
  2793. */
  2794. bmcr &= ~BMCR_ANENABLE;
  2795. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  2796. tg3_writephy(tp, MII_BMCR, bmcr);
  2797. tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT;
  2798. }
  2799. }
  2800. }
  2801. else if (netif_carrier_ok(tp->dev) &&
  2802. (tp->link_config.autoneg == AUTONEG_ENABLE) &&
  2803. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) {
  2804. u32 phy2;
  2805. /* Select expansion interrupt status register */
  2806. tg3_writephy(tp, 0x17, 0x0f01);
  2807. tg3_readphy(tp, 0x15, &phy2);
  2808. if (phy2 & 0x20) {
  2809. u32 bmcr;
  2810. /* Config code words received, turn on autoneg. */
  2811. tg3_readphy(tp, MII_BMCR, &bmcr);
  2812. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE);
  2813. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  2814. }
  2815. }
  2816. }
  2817. static int tg3_setup_phy(struct tg3 *tp, int force_reset)
  2818. {
  2819. int err;
  2820. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  2821. err = tg3_setup_fiber_phy(tp, force_reset);
  2822. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  2823. err = tg3_setup_fiber_mii_phy(tp, force_reset);
  2824. } else {
  2825. err = tg3_setup_copper_phy(tp, force_reset);
  2826. }
  2827. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  2828. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1) {
  2829. u32 val, scale;
  2830. val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK;
  2831. if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5)
  2832. scale = 65;
  2833. else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25)
  2834. scale = 6;
  2835. else
  2836. scale = 12;
  2837. val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK;
  2838. val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT);
  2839. tw32(GRC_MISC_CFG, val);
  2840. }
  2841. if (tp->link_config.active_speed == SPEED_1000 &&
  2842. tp->link_config.active_duplex == DUPLEX_HALF)
  2843. tw32(MAC_TX_LENGTHS,
  2844. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2845. (6 << TX_LENGTHS_IPG_SHIFT) |
  2846. (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2847. else
  2848. tw32(MAC_TX_LENGTHS,
  2849. ((2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  2850. (6 << TX_LENGTHS_IPG_SHIFT) |
  2851. (32 << TX_LENGTHS_SLOT_TIME_SHIFT)));
  2852. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  2853. if (netif_carrier_ok(tp->dev)) {
  2854. tw32(HOSTCC_STAT_COAL_TICKS,
  2855. tp->coal.stats_block_coalesce_usecs);
  2856. } else {
  2857. tw32(HOSTCC_STAT_COAL_TICKS, 0);
  2858. }
  2859. }
  2860. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) {
  2861. u32 val = tr32(PCIE_PWR_MGMT_THRESH);
  2862. if (!netif_carrier_ok(tp->dev))
  2863. val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) |
  2864. tp->pwrmgmt_thresh;
  2865. else
  2866. val |= PCIE_PWR_MGMT_L1_THRESH_MSK;
  2867. tw32(PCIE_PWR_MGMT_THRESH, val);
  2868. }
  2869. return err;
  2870. }
  2871. /* This is called whenever we suspect that the system chipset is re-
  2872. * ordering the sequence of MMIO to the tx send mailbox. The symptom
  2873. * is bogus tx completions. We try to recover by setting the
  2874. * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later
  2875. * in the workqueue.
  2876. */
  2877. static void tg3_tx_recover(struct tg3 *tp)
  2878. {
  2879. BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) ||
  2880. tp->write32_tx_mbox == tg3_write_indirect_mbox);
  2881. printk(KERN_WARNING PFX "%s: The system may be re-ordering memory-"
  2882. "mapped I/O cycles to the network device, attempting to "
  2883. "recover. Please report the problem to the driver maintainer "
  2884. "and include system chipset information.\n", tp->dev->name);
  2885. spin_lock(&tp->lock);
  2886. tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING;
  2887. spin_unlock(&tp->lock);
  2888. }
  2889. static inline u32 tg3_tx_avail(struct tg3 *tp)
  2890. {
  2891. smp_mb();
  2892. return (tp->tx_pending -
  2893. ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
  2894. }
  2895. /* Tigon3 never reports partial packet sends. So we do not
  2896. * need special logic to handle SKBs that have not had all
  2897. * of their frags sent yet, like SunGEM does.
  2898. */
  2899. static void tg3_tx(struct tg3 *tp)
  2900. {
  2901. u32 hw_idx = tp->hw_status->idx[0].tx_consumer;
  2902. u32 sw_idx = tp->tx_cons;
  2903. while (sw_idx != hw_idx) {
  2904. struct tx_ring_info *ri = &tp->tx_buffers[sw_idx];
  2905. struct sk_buff *skb = ri->skb;
  2906. int i, tx_bug = 0;
  2907. if (unlikely(skb == NULL)) {
  2908. tg3_tx_recover(tp);
  2909. return;
  2910. }
  2911. pci_unmap_single(tp->pdev,
  2912. pci_unmap_addr(ri, mapping),
  2913. skb_headlen(skb),
  2914. PCI_DMA_TODEVICE);
  2915. ri->skb = NULL;
  2916. sw_idx = NEXT_TX(sw_idx);
  2917. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2918. ri = &tp->tx_buffers[sw_idx];
  2919. if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
  2920. tx_bug = 1;
  2921. pci_unmap_page(tp->pdev,
  2922. pci_unmap_addr(ri, mapping),
  2923. skb_shinfo(skb)->frags[i].size,
  2924. PCI_DMA_TODEVICE);
  2925. sw_idx = NEXT_TX(sw_idx);
  2926. }
  2927. dev_kfree_skb(skb);
  2928. if (unlikely(tx_bug)) {
  2929. tg3_tx_recover(tp);
  2930. return;
  2931. }
  2932. }
  2933. tp->tx_cons = sw_idx;
  2934. /* Need to make the tx_cons update visible to tg3_start_xmit()
  2935. * before checking for netif_queue_stopped(). Without the
  2936. * memory barrier, there is a small possibility that tg3_start_xmit()
  2937. * will miss it and cause the queue to be stopped forever.
  2938. */
  2939. smp_mb();
  2940. if (unlikely(netif_queue_stopped(tp->dev) &&
  2941. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))) {
  2942. netif_tx_lock(tp->dev);
  2943. if (netif_queue_stopped(tp->dev) &&
  2944. (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp)))
  2945. netif_wake_queue(tp->dev);
  2946. netif_tx_unlock(tp->dev);
  2947. }
  2948. }
  2949. /* Returns size of skb allocated or < 0 on error.
  2950. *
  2951. * We only need to fill in the address because the other members
  2952. * of the RX descriptor are invariant, see tg3_init_rings.
  2953. *
  2954. * Note the purposeful assymetry of cpu vs. chip accesses. For
  2955. * posting buffers we only dirty the first cache line of the RX
  2956. * descriptor (containing the address). Whereas for the RX status
  2957. * buffers the cpu only reads the last cacheline of the RX descriptor
  2958. * (to fetch the error flags, vlan tag, checksum, and opaque cookie).
  2959. */
  2960. static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
  2961. int src_idx, u32 dest_idx_unmasked)
  2962. {
  2963. struct tg3_rx_buffer_desc *desc;
  2964. struct ring_info *map, *src_map;
  2965. struct sk_buff *skb;
  2966. dma_addr_t mapping;
  2967. int skb_size, dest_idx;
  2968. src_map = NULL;
  2969. switch (opaque_key) {
  2970. case RXD_OPAQUE_RING_STD:
  2971. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  2972. desc = &tp->rx_std[dest_idx];
  2973. map = &tp->rx_std_buffers[dest_idx];
  2974. if (src_idx >= 0)
  2975. src_map = &tp->rx_std_buffers[src_idx];
  2976. skb_size = tp->rx_pkt_buf_sz;
  2977. break;
  2978. case RXD_OPAQUE_RING_JUMBO:
  2979. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  2980. desc = &tp->rx_jumbo[dest_idx];
  2981. map = &tp->rx_jumbo_buffers[dest_idx];
  2982. if (src_idx >= 0)
  2983. src_map = &tp->rx_jumbo_buffers[src_idx];
  2984. skb_size = RX_JUMBO_PKT_BUF_SZ;
  2985. break;
  2986. default:
  2987. return -EINVAL;
  2988. };
  2989. /* Do not overwrite any of the map or rp information
  2990. * until we are sure we can commit to a new buffer.
  2991. *
  2992. * Callers depend upon this behavior and assume that
  2993. * we leave everything unchanged if we fail.
  2994. */
  2995. skb = netdev_alloc_skb(tp->dev, skb_size);
  2996. if (skb == NULL)
  2997. return -ENOMEM;
  2998. skb_reserve(skb, tp->rx_offset);
  2999. mapping = pci_map_single(tp->pdev, skb->data,
  3000. skb_size - tp->rx_offset,
  3001. PCI_DMA_FROMDEVICE);
  3002. map->skb = skb;
  3003. pci_unmap_addr_set(map, mapping, mapping);
  3004. if (src_map != NULL)
  3005. src_map->skb = NULL;
  3006. desc->addr_hi = ((u64)mapping >> 32);
  3007. desc->addr_lo = ((u64)mapping & 0xffffffff);
  3008. return skb_size;
  3009. }
  3010. /* We only need to move over in the address because the other
  3011. * members of the RX descriptor are invariant. See notes above
  3012. * tg3_alloc_rx_skb for full details.
  3013. */
  3014. static void tg3_recycle_rx(struct tg3 *tp, u32 opaque_key,
  3015. int src_idx, u32 dest_idx_unmasked)
  3016. {
  3017. struct tg3_rx_buffer_desc *src_desc, *dest_desc;
  3018. struct ring_info *src_map, *dest_map;
  3019. int dest_idx;
  3020. switch (opaque_key) {
  3021. case RXD_OPAQUE_RING_STD:
  3022. dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE;
  3023. dest_desc = &tp->rx_std[dest_idx];
  3024. dest_map = &tp->rx_std_buffers[dest_idx];
  3025. src_desc = &tp->rx_std[src_idx];
  3026. src_map = &tp->rx_std_buffers[src_idx];
  3027. break;
  3028. case RXD_OPAQUE_RING_JUMBO:
  3029. dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE;
  3030. dest_desc = &tp->rx_jumbo[dest_idx];
  3031. dest_map = &tp->rx_jumbo_buffers[dest_idx];
  3032. src_desc = &tp->rx_jumbo[src_idx];
  3033. src_map = &tp->rx_jumbo_buffers[src_idx];
  3034. break;
  3035. default:
  3036. return;
  3037. };
  3038. dest_map->skb = src_map->skb;
  3039. pci_unmap_addr_set(dest_map, mapping,
  3040. pci_unmap_addr(src_map, mapping));
  3041. dest_desc->addr_hi = src_desc->addr_hi;
  3042. dest_desc->addr_lo = src_desc->addr_lo;
  3043. src_map->skb = NULL;
  3044. }
  3045. #if TG3_VLAN_TAG_USED
  3046. static int tg3_vlan_rx(struct tg3 *tp, struct sk_buff *skb, u16 vlan_tag)
  3047. {
  3048. return vlan_hwaccel_receive_skb(skb, tp->vlgrp, vlan_tag);
  3049. }
  3050. #endif
  3051. /* The RX ring scheme is composed of multiple rings which post fresh
  3052. * buffers to the chip, and one special ring the chip uses to report
  3053. * status back to the host.
  3054. *
  3055. * The special ring reports the status of received packets to the
  3056. * host. The chip does not write into the original descriptor the
  3057. * RX buffer was obtained from. The chip simply takes the original
  3058. * descriptor as provided by the host, updates the status and length
  3059. * field, then writes this into the next status ring entry.
  3060. *
  3061. * Each ring the host uses to post buffers to the chip is described
  3062. * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives,
  3063. * it is first placed into the on-chip ram. When the packet's length
  3064. * is known, it walks down the TG3_BDINFO entries to select the ring.
  3065. * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO
  3066. * which is within the range of the new packet's length is chosen.
  3067. *
  3068. * The "separate ring for rx status" scheme may sound queer, but it makes
  3069. * sense from a cache coherency perspective. If only the host writes
  3070. * to the buffer post rings, and only the chip writes to the rx status
  3071. * rings, then cache lines never move beyond shared-modified state.
  3072. * If both the host and chip were to write into the same ring, cache line
  3073. * eviction could occur since both entities want it in an exclusive state.
  3074. */
  3075. static int tg3_rx(struct tg3 *tp, int budget)
  3076. {
  3077. u32 work_mask, rx_std_posted = 0;
  3078. u32 sw_idx = tp->rx_rcb_ptr;
  3079. u16 hw_idx;
  3080. int received;
  3081. hw_idx = tp->hw_status->idx[0].rx_producer;
  3082. /*
  3083. * We need to order the read of hw_idx and the read of
  3084. * the opaque cookie.
  3085. */
  3086. rmb();
  3087. work_mask = 0;
  3088. received = 0;
  3089. while (sw_idx != hw_idx && budget > 0) {
  3090. struct tg3_rx_buffer_desc *desc = &tp->rx_rcb[sw_idx];
  3091. unsigned int len;
  3092. struct sk_buff *skb;
  3093. dma_addr_t dma_addr;
  3094. u32 opaque_key, desc_idx, *post_ptr;
  3095. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  3096. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  3097. if (opaque_key == RXD_OPAQUE_RING_STD) {
  3098. dma_addr = pci_unmap_addr(&tp->rx_std_buffers[desc_idx],
  3099. mapping);
  3100. skb = tp->rx_std_buffers[desc_idx].skb;
  3101. post_ptr = &tp->rx_std_ptr;
  3102. rx_std_posted++;
  3103. } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) {
  3104. dma_addr = pci_unmap_addr(&tp->rx_jumbo_buffers[desc_idx],
  3105. mapping);
  3106. skb = tp->rx_jumbo_buffers[desc_idx].skb;
  3107. post_ptr = &tp->rx_jumbo_ptr;
  3108. }
  3109. else {
  3110. goto next_pkt_nopost;
  3111. }
  3112. work_mask |= opaque_key;
  3113. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  3114. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
  3115. drop_it:
  3116. tg3_recycle_rx(tp, opaque_key,
  3117. desc_idx, *post_ptr);
  3118. drop_it_no_recycle:
  3119. /* Other statistics kept track of by card. */
  3120. tp->net_stats.rx_dropped++;
  3121. goto next_pkt;
  3122. }
  3123. len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; /* omit crc */
  3124. if (len > RX_COPY_THRESHOLD
  3125. && tp->rx_offset == 2
  3126. /* rx_offset != 2 iff this is a 5701 card running
  3127. * in PCI-X mode [see tg3_get_invariants()] */
  3128. ) {
  3129. int skb_size;
  3130. skb_size = tg3_alloc_rx_skb(tp, opaque_key,
  3131. desc_idx, *post_ptr);
  3132. if (skb_size < 0)
  3133. goto drop_it;
  3134. pci_unmap_single(tp->pdev, dma_addr,
  3135. skb_size - tp->rx_offset,
  3136. PCI_DMA_FROMDEVICE);
  3137. skb_put(skb, len);
  3138. } else {
  3139. struct sk_buff *copy_skb;
  3140. tg3_recycle_rx(tp, opaque_key,
  3141. desc_idx, *post_ptr);
  3142. copy_skb = netdev_alloc_skb(tp->dev, len + 2);
  3143. if (copy_skb == NULL)
  3144. goto drop_it_no_recycle;
  3145. skb_reserve(copy_skb, 2);
  3146. skb_put(copy_skb, len);
  3147. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  3148. skb_copy_from_linear_data(skb, copy_skb->data, len);
  3149. pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
  3150. /* We'll reuse the original ring buffer. */
  3151. skb = copy_skb;
  3152. }
  3153. if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) &&
  3154. (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) &&
  3155. (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK)
  3156. >> RXD_TCPCSUM_SHIFT) == 0xffff))
  3157. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3158. else
  3159. skb->ip_summed = CHECKSUM_NONE;
  3160. skb->protocol = eth_type_trans(skb, tp->dev);
  3161. #if TG3_VLAN_TAG_USED
  3162. if (tp->vlgrp != NULL &&
  3163. desc->type_flags & RXD_FLAG_VLAN) {
  3164. tg3_vlan_rx(tp, skb,
  3165. desc->err_vlan & RXD_VLAN_MASK);
  3166. } else
  3167. #endif
  3168. netif_receive_skb(skb);
  3169. tp->dev->last_rx = jiffies;
  3170. received++;
  3171. budget--;
  3172. next_pkt:
  3173. (*post_ptr)++;
  3174. if (unlikely(rx_std_posted >= tp->rx_std_max_post)) {
  3175. u32 idx = *post_ptr % TG3_RX_RING_SIZE;
  3176. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX +
  3177. TG3_64BIT_REG_LOW, idx);
  3178. work_mask &= ~RXD_OPAQUE_RING_STD;
  3179. rx_std_posted = 0;
  3180. }
  3181. next_pkt_nopost:
  3182. sw_idx++;
  3183. sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1);
  3184. /* Refresh hw_idx to see if there is new work */
  3185. if (sw_idx == hw_idx) {
  3186. hw_idx = tp->hw_status->idx[0].rx_producer;
  3187. rmb();
  3188. }
  3189. }
  3190. /* ACK the status ring. */
  3191. tp->rx_rcb_ptr = sw_idx;
  3192. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
  3193. /* Refill RX ring(s). */
  3194. if (work_mask & RXD_OPAQUE_RING_STD) {
  3195. sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
  3196. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  3197. sw_idx);
  3198. }
  3199. if (work_mask & RXD_OPAQUE_RING_JUMBO) {
  3200. sw_idx = tp->rx_jumbo_ptr % TG3_RX_JUMBO_RING_SIZE;
  3201. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  3202. sw_idx);
  3203. }
  3204. mmiowb();
  3205. return received;
  3206. }
  3207. static int tg3_poll_work(struct tg3 *tp, int work_done, int budget)
  3208. {
  3209. struct tg3_hw_status *sblk = tp->hw_status;
  3210. /* handle link change and other phy events */
  3211. if (!(tp->tg3_flags &
  3212. (TG3_FLAG_USE_LINKCHG_REG |
  3213. TG3_FLAG_POLL_SERDES))) {
  3214. if (sblk->status & SD_STATUS_LINK_CHG) {
  3215. sblk->status = SD_STATUS_UPDATED |
  3216. (sblk->status & ~SD_STATUS_LINK_CHG);
  3217. spin_lock(&tp->lock);
  3218. tg3_setup_phy(tp, 0);
  3219. spin_unlock(&tp->lock);
  3220. }
  3221. }
  3222. /* run TX completion thread */
  3223. if (sblk->idx[0].tx_consumer != tp->tx_cons) {
  3224. tg3_tx(tp);
  3225. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
  3226. return work_done;
  3227. }
  3228. /* run RX thread, within the bounds set by NAPI.
  3229. * All RX "locking" is done by ensuring outside
  3230. * code synchronizes with tg3->napi.poll()
  3231. */
  3232. if (sblk->idx[0].rx_producer != tp->rx_rcb_ptr)
  3233. work_done += tg3_rx(tp, budget - work_done);
  3234. return work_done;
  3235. }
  3236. static int tg3_poll(struct napi_struct *napi, int budget)
  3237. {
  3238. struct tg3 *tp = container_of(napi, struct tg3, napi);
  3239. int work_done = 0;
  3240. struct tg3_hw_status *sblk = tp->hw_status;
  3241. while (1) {
  3242. work_done = tg3_poll_work(tp, work_done, budget);
  3243. if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING))
  3244. goto tx_recovery;
  3245. if (unlikely(work_done >= budget))
  3246. break;
  3247. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  3248. /* tp->last_tag is used in tg3_restart_ints() below
  3249. * to tell the hw how much work has been processed,
  3250. * so we must read it before checking for more work.
  3251. */
  3252. tp->last_tag = sblk->status_tag;
  3253. rmb();
  3254. } else
  3255. sblk->status &= ~SD_STATUS_UPDATED;
  3256. if (likely(!tg3_has_work(tp))) {
  3257. netif_rx_complete(tp->dev, napi);
  3258. tg3_restart_ints(tp);
  3259. break;
  3260. }
  3261. }
  3262. return work_done;
  3263. tx_recovery:
  3264. /* work_done is guaranteed to be less than budget. */
  3265. netif_rx_complete(tp->dev, napi);
  3266. schedule_work(&tp->reset_task);
  3267. return work_done;
  3268. }
  3269. static void tg3_irq_quiesce(struct tg3 *tp)
  3270. {
  3271. BUG_ON(tp->irq_sync);
  3272. tp->irq_sync = 1;
  3273. smp_mb();
  3274. synchronize_irq(tp->pdev->irq);
  3275. }
  3276. static inline int tg3_irq_sync(struct tg3 *tp)
  3277. {
  3278. return tp->irq_sync;
  3279. }
  3280. /* Fully shutdown all tg3 driver activity elsewhere in the system.
  3281. * If irq_sync is non-zero, then the IRQ handler must be synchronized
  3282. * with as well. Most of the time, this is not necessary except when
  3283. * shutting down the device.
  3284. */
  3285. static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
  3286. {
  3287. spin_lock_bh(&tp->lock);
  3288. if (irq_sync)
  3289. tg3_irq_quiesce(tp);
  3290. }
  3291. static inline void tg3_full_unlock(struct tg3 *tp)
  3292. {
  3293. spin_unlock_bh(&tp->lock);
  3294. }
  3295. /* One-shot MSI handler - Chip automatically disables interrupt
  3296. * after sending MSI so driver doesn't have to do it.
  3297. */
  3298. static irqreturn_t tg3_msi_1shot(int irq, void *dev_id)
  3299. {
  3300. struct net_device *dev = dev_id;
  3301. struct tg3 *tp = netdev_priv(dev);
  3302. prefetch(tp->hw_status);
  3303. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3304. if (likely(!tg3_irq_sync(tp)))
  3305. netif_rx_schedule(dev, &tp->napi);
  3306. return IRQ_HANDLED;
  3307. }
  3308. /* MSI ISR - No need to check for interrupt sharing and no need to
  3309. * flush status block and interrupt mailbox. PCI ordering rules
  3310. * guarantee that MSI will arrive after the status block.
  3311. */
  3312. static irqreturn_t tg3_msi(int irq, void *dev_id)
  3313. {
  3314. struct net_device *dev = dev_id;
  3315. struct tg3 *tp = netdev_priv(dev);
  3316. prefetch(tp->hw_status);
  3317. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3318. /*
  3319. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3320. * chip-internal interrupt pending events.
  3321. * Writing non-zero to intr-mbox-0 additional tells the
  3322. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3323. * event coalescing.
  3324. */
  3325. tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3326. if (likely(!tg3_irq_sync(tp)))
  3327. netif_rx_schedule(dev, &tp->napi);
  3328. return IRQ_RETVAL(1);
  3329. }
  3330. static irqreturn_t tg3_interrupt(int irq, void *dev_id)
  3331. {
  3332. struct net_device *dev = dev_id;
  3333. struct tg3 *tp = netdev_priv(dev);
  3334. struct tg3_hw_status *sblk = tp->hw_status;
  3335. unsigned int handled = 1;
  3336. /* In INTx mode, it is possible for the interrupt to arrive at
  3337. * the CPU before the status block posted prior to the interrupt.
  3338. * Reading the PCI State register will confirm whether the
  3339. * interrupt is ours and will flush the status block.
  3340. */
  3341. if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) {
  3342. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3343. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3344. handled = 0;
  3345. goto out;
  3346. }
  3347. }
  3348. /*
  3349. * Writing any value to intr-mbox-0 clears PCI INTA# and
  3350. * chip-internal interrupt pending events.
  3351. * Writing non-zero to intr-mbox-0 additional tells the
  3352. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3353. * event coalescing.
  3354. *
  3355. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3356. * spurious interrupts. The flush impacts performance but
  3357. * excessive spurious interrupts can be worse in some cases.
  3358. */
  3359. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3360. if (tg3_irq_sync(tp))
  3361. goto out;
  3362. sblk->status &= ~SD_STATUS_UPDATED;
  3363. if (likely(tg3_has_work(tp))) {
  3364. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3365. netif_rx_schedule(dev, &tp->napi);
  3366. } else {
  3367. /* No work, shared interrupt perhaps? re-enable
  3368. * interrupts, and flush that PCI write
  3369. */
  3370. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
  3371. 0x00000000);
  3372. }
  3373. out:
  3374. return IRQ_RETVAL(handled);
  3375. }
  3376. static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id)
  3377. {
  3378. struct net_device *dev = dev_id;
  3379. struct tg3 *tp = netdev_priv(dev);
  3380. struct tg3_hw_status *sblk = tp->hw_status;
  3381. unsigned int handled = 1;
  3382. /* In INTx mode, it is possible for the interrupt to arrive at
  3383. * the CPU before the status block posted prior to the interrupt.
  3384. * Reading the PCI State register will confirm whether the
  3385. * interrupt is ours and will flush the status block.
  3386. */
  3387. if (unlikely(sblk->status_tag == tp->last_tag)) {
  3388. if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) ||
  3389. (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3390. handled = 0;
  3391. goto out;
  3392. }
  3393. }
  3394. /*
  3395. * writing any value to intr-mbox-0 clears PCI INTA# and
  3396. * chip-internal interrupt pending events.
  3397. * writing non-zero to intr-mbox-0 additional tells the
  3398. * NIC to stop sending us irqs, engaging "in-intr-handler"
  3399. * event coalescing.
  3400. *
  3401. * Flush the mailbox to de-assert the IRQ immediately to prevent
  3402. * spurious interrupts. The flush impacts performance but
  3403. * excessive spurious interrupts can be worse in some cases.
  3404. */
  3405. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
  3406. if (tg3_irq_sync(tp))
  3407. goto out;
  3408. if (netif_rx_schedule_prep(dev, &tp->napi)) {
  3409. prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
  3410. /* Update last_tag to mark that this status has been
  3411. * seen. Because interrupt may be shared, we may be
  3412. * racing with tg3_poll(), so only update last_tag
  3413. * if tg3_poll() is not scheduled.
  3414. */
  3415. tp->last_tag = sblk->status_tag;
  3416. __netif_rx_schedule(dev, &tp->napi);
  3417. }
  3418. out:
  3419. return IRQ_RETVAL(handled);
  3420. }
  3421. /* ISR for interrupt test */
  3422. static irqreturn_t tg3_test_isr(int irq, void *dev_id)
  3423. {
  3424. struct net_device *dev = dev_id;
  3425. struct tg3 *tp = netdev_priv(dev);
  3426. struct tg3_hw_status *sblk = tp->hw_status;
  3427. if ((sblk->status & SD_STATUS_UPDATED) ||
  3428. !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
  3429. tg3_disable_ints(tp);
  3430. return IRQ_RETVAL(1);
  3431. }
  3432. return IRQ_RETVAL(0);
  3433. }
  3434. static int tg3_init_hw(struct tg3 *, int);
  3435. static int tg3_halt(struct tg3 *, int, int);
  3436. /* Restart hardware after configuration changes, self-test, etc.
  3437. * Invoked with tp->lock held.
  3438. */
  3439. static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
  3440. __releases(tp->lock)
  3441. __acquires(tp->lock)
  3442. {
  3443. int err;
  3444. err = tg3_init_hw(tp, reset_phy);
  3445. if (err) {
  3446. printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
  3447. "aborting.\n", tp->dev->name);
  3448. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3449. tg3_full_unlock(tp);
  3450. del_timer_sync(&tp->timer);
  3451. tp->irq_sync = 0;
  3452. napi_enable(&tp->napi);
  3453. dev_close(tp->dev);
  3454. tg3_full_lock(tp, 0);
  3455. }
  3456. return err;
  3457. }
  3458. #ifdef CONFIG_NET_POLL_CONTROLLER
  3459. static void tg3_poll_controller(struct net_device *dev)
  3460. {
  3461. struct tg3 *tp = netdev_priv(dev);
  3462. tg3_interrupt(tp->pdev->irq, dev);
  3463. }
  3464. #endif
  3465. static void tg3_reset_task(struct work_struct *work)
  3466. {
  3467. struct tg3 *tp = container_of(work, struct tg3, reset_task);
  3468. unsigned int restart_timer;
  3469. tg3_full_lock(tp, 0);
  3470. if (!netif_running(tp->dev)) {
  3471. tg3_full_unlock(tp);
  3472. return;
  3473. }
  3474. tg3_full_unlock(tp);
  3475. tg3_netif_stop(tp);
  3476. tg3_full_lock(tp, 1);
  3477. restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER;
  3478. tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER;
  3479. if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) {
  3480. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  3481. tp->write32_rx_mbox = tg3_write_flush_reg32;
  3482. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  3483. tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING;
  3484. }
  3485. tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
  3486. if (tg3_init_hw(tp, 1))
  3487. goto out;
  3488. tg3_netif_start(tp);
  3489. if (restart_timer)
  3490. mod_timer(&tp->timer, jiffies + 1);
  3491. out:
  3492. tg3_full_unlock(tp);
  3493. }
  3494. static void tg3_dump_short_state(struct tg3 *tp)
  3495. {
  3496. printk(KERN_ERR PFX "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n",
  3497. tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS));
  3498. printk(KERN_ERR PFX "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n",
  3499. tr32(RDMAC_STATUS), tr32(WDMAC_STATUS));
  3500. }
  3501. static void tg3_tx_timeout(struct net_device *dev)
  3502. {
  3503. struct tg3 *tp = netdev_priv(dev);
  3504. if (netif_msg_tx_err(tp)) {
  3505. printk(KERN_ERR PFX "%s: transmit timed out, resetting\n",
  3506. dev->name);
  3507. tg3_dump_short_state(tp);
  3508. }
  3509. schedule_work(&tp->reset_task);
  3510. }
  3511. /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
  3512. static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len)
  3513. {
  3514. u32 base = (u32) mapping & 0xffffffff;
  3515. return ((base > 0xffffdcc0) &&
  3516. (base + len + 8 < base));
  3517. }
  3518. /* Test for DMA addresses > 40-bit */
  3519. static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
  3520. int len)
  3521. {
  3522. #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
  3523. if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
  3524. return (((u64) mapping + len) > DMA_40BIT_MASK);
  3525. return 0;
  3526. #else
  3527. return 0;
  3528. #endif
  3529. }
  3530. static void tg3_set_txd(struct tg3 *, int, dma_addr_t, int, u32, u32);
  3531. /* Workaround 4GB and 40-bit hardware DMA bugs. */
  3532. static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
  3533. u32 last_plus_one, u32 *start,
  3534. u32 base_flags, u32 mss)
  3535. {
  3536. struct sk_buff *new_skb;
  3537. dma_addr_t new_addr = 0;
  3538. u32 entry = *start;
  3539. int i, ret = 0;
  3540. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  3541. new_skb = skb_copy(skb, GFP_ATOMIC);
  3542. else {
  3543. int more_headroom = 4 - ((unsigned long)skb->data & 3);
  3544. new_skb = skb_copy_expand(skb,
  3545. skb_headroom(skb) + more_headroom,
  3546. skb_tailroom(skb), GFP_ATOMIC);
  3547. }
  3548. if (!new_skb) {
  3549. ret = -1;
  3550. } else {
  3551. /* New SKB is guaranteed to be linear. */
  3552. entry = *start;
  3553. new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
  3554. PCI_DMA_TODEVICE);
  3555. /* Make sure new skb does not cross any 4G boundaries.
  3556. * Drop the packet if it does.
  3557. */
  3558. if (tg3_4g_overflow_test(new_addr, new_skb->len)) {
  3559. ret = -1;
  3560. dev_kfree_skb(new_skb);
  3561. new_skb = NULL;
  3562. } else {
  3563. tg3_set_txd(tp, entry, new_addr, new_skb->len,
  3564. base_flags, 1 | (mss << 1));
  3565. *start = NEXT_TX(entry);
  3566. }
  3567. }
  3568. /* Now clean up the sw ring entries. */
  3569. i = 0;
  3570. while (entry != last_plus_one) {
  3571. int len;
  3572. if (i == 0)
  3573. len = skb_headlen(skb);
  3574. else
  3575. len = skb_shinfo(skb)->frags[i-1].size;
  3576. pci_unmap_single(tp->pdev,
  3577. pci_unmap_addr(&tp->tx_buffers[entry], mapping),
  3578. len, PCI_DMA_TODEVICE);
  3579. if (i == 0) {
  3580. tp->tx_buffers[entry].skb = new_skb;
  3581. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
  3582. } else {
  3583. tp->tx_buffers[entry].skb = NULL;
  3584. }
  3585. entry = NEXT_TX(entry);
  3586. i++;
  3587. }
  3588. dev_kfree_skb(skb);
  3589. return ret;
  3590. }
  3591. static void tg3_set_txd(struct tg3 *tp, int entry,
  3592. dma_addr_t mapping, int len, u32 flags,
  3593. u32 mss_and_is_end)
  3594. {
  3595. struct tg3_tx_buffer_desc *txd = &tp->tx_ring[entry];
  3596. int is_end = (mss_and_is_end & 0x1);
  3597. u32 mss = (mss_and_is_end >> 1);
  3598. u32 vlan_tag = 0;
  3599. if (is_end)
  3600. flags |= TXD_FLAG_END;
  3601. if (flags & TXD_FLAG_VLAN) {
  3602. vlan_tag = flags >> 16;
  3603. flags &= 0xffff;
  3604. }
  3605. vlan_tag |= (mss << TXD_MSS_SHIFT);
  3606. txd->addr_hi = ((u64) mapping >> 32);
  3607. txd->addr_lo = ((u64) mapping & 0xffffffff);
  3608. txd->len_flags = (len << TXD_LEN_SHIFT) | flags;
  3609. txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT;
  3610. }
  3611. /* hard_start_xmit for devices that don't have any bugs and
  3612. * support TG3_FLG2_HW_TSO_2 only.
  3613. */
  3614. static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3615. {
  3616. struct tg3 *tp = netdev_priv(dev);
  3617. dma_addr_t mapping;
  3618. u32 len, entry, base_flags, mss;
  3619. len = skb_headlen(skb);
  3620. /* We are running in BH disabled context with netif_tx_lock
  3621. * and TX reclaim runs via tp->napi.poll inside of a software
  3622. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3623. * no IRQ context deadlocks to worry about either. Rejoice!
  3624. */
  3625. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3626. if (!netif_queue_stopped(dev)) {
  3627. netif_stop_queue(dev);
  3628. /* This is a hard error, log it. */
  3629. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3630. "queue awake!\n", dev->name);
  3631. }
  3632. return NETDEV_TX_BUSY;
  3633. }
  3634. entry = tp->tx_prod;
  3635. base_flags = 0;
  3636. mss = 0;
  3637. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3638. int tcp_opt_len, ip_tcp_len;
  3639. if (skb_header_cloned(skb) &&
  3640. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3641. dev_kfree_skb(skb);
  3642. goto out_unlock;
  3643. }
  3644. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  3645. mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
  3646. else {
  3647. struct iphdr *iph = ip_hdr(skb);
  3648. tcp_opt_len = tcp_optlen(skb);
  3649. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3650. iph->check = 0;
  3651. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3652. mss |= (ip_tcp_len + tcp_opt_len) << 9;
  3653. }
  3654. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3655. TXD_FLAG_CPU_POST_DMA);
  3656. tcp_hdr(skb)->check = 0;
  3657. }
  3658. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  3659. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3660. #if TG3_VLAN_TAG_USED
  3661. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3662. base_flags |= (TXD_FLAG_VLAN |
  3663. (vlan_tx_tag_get(skb) << 16));
  3664. #endif
  3665. /* Queue skb data, a.k.a. the main skb fragment. */
  3666. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3667. tp->tx_buffers[entry].skb = skb;
  3668. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3669. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3670. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3671. entry = NEXT_TX(entry);
  3672. /* Now loop through additional data fragments, and queue them. */
  3673. if (skb_shinfo(skb)->nr_frags > 0) {
  3674. unsigned int i, last;
  3675. last = skb_shinfo(skb)->nr_frags - 1;
  3676. for (i = 0; i <= last; i++) {
  3677. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3678. len = frag->size;
  3679. mapping = pci_map_page(tp->pdev,
  3680. frag->page,
  3681. frag->page_offset,
  3682. len, PCI_DMA_TODEVICE);
  3683. tp->tx_buffers[entry].skb = NULL;
  3684. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3685. tg3_set_txd(tp, entry, mapping, len,
  3686. base_flags, (i == last) | (mss << 1));
  3687. entry = NEXT_TX(entry);
  3688. }
  3689. }
  3690. /* Packets are ready, update Tx producer idx local and on card. */
  3691. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3692. tp->tx_prod = entry;
  3693. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3694. netif_stop_queue(dev);
  3695. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3696. netif_wake_queue(tp->dev);
  3697. }
  3698. out_unlock:
  3699. mmiowb();
  3700. dev->trans_start = jiffies;
  3701. return NETDEV_TX_OK;
  3702. }
  3703. static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
  3704. /* Use GSO to workaround a rare TSO bug that may be triggered when the
  3705. * TSO header is greater than 80 bytes.
  3706. */
  3707. static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
  3708. {
  3709. struct sk_buff *segs, *nskb;
  3710. /* Estimate the number of fragments in the worst case */
  3711. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
  3712. netif_stop_queue(tp->dev);
  3713. if (tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))
  3714. return NETDEV_TX_BUSY;
  3715. netif_wake_queue(tp->dev);
  3716. }
  3717. segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO);
  3718. if (IS_ERR(segs))
  3719. goto tg3_tso_bug_end;
  3720. do {
  3721. nskb = segs;
  3722. segs = segs->next;
  3723. nskb->next = NULL;
  3724. tg3_start_xmit_dma_bug(nskb, tp->dev);
  3725. } while (segs);
  3726. tg3_tso_bug_end:
  3727. dev_kfree_skb(skb);
  3728. return NETDEV_TX_OK;
  3729. }
  3730. /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  3731. * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
  3732. */
  3733. static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
  3734. {
  3735. struct tg3 *tp = netdev_priv(dev);
  3736. dma_addr_t mapping;
  3737. u32 len, entry, base_flags, mss;
  3738. int would_hit_hwbug;
  3739. len = skb_headlen(skb);
  3740. /* We are running in BH disabled context with netif_tx_lock
  3741. * and TX reclaim runs via tp->napi.poll inside of a software
  3742. * interrupt. Furthermore, IRQ processing runs lockless so we have
  3743. * no IRQ context deadlocks to worry about either. Rejoice!
  3744. */
  3745. if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
  3746. if (!netif_queue_stopped(dev)) {
  3747. netif_stop_queue(dev);
  3748. /* This is a hard error, log it. */
  3749. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when "
  3750. "queue awake!\n", dev->name);
  3751. }
  3752. return NETDEV_TX_BUSY;
  3753. }
  3754. entry = tp->tx_prod;
  3755. base_flags = 0;
  3756. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3757. base_flags |= TXD_FLAG_TCPUDP_CSUM;
  3758. mss = 0;
  3759. if ((mss = skb_shinfo(skb)->gso_size) != 0) {
  3760. struct iphdr *iph;
  3761. int tcp_opt_len, ip_tcp_len, hdr_len;
  3762. if (skb_header_cloned(skb) &&
  3763. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3764. dev_kfree_skb(skb);
  3765. goto out_unlock;
  3766. }
  3767. tcp_opt_len = tcp_optlen(skb);
  3768. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3769. hdr_len = ip_tcp_len + tcp_opt_len;
  3770. if (unlikely((ETH_HLEN + hdr_len) > 80) &&
  3771. (tp->tg3_flags2 & TG3_FLG2_TSO_BUG))
  3772. return (tg3_tso_bug(tp, skb));
  3773. base_flags |= (TXD_FLAG_CPU_PRE_DMA |
  3774. TXD_FLAG_CPU_POST_DMA);
  3775. iph = ip_hdr(skb);
  3776. iph->check = 0;
  3777. iph->tot_len = htons(mss + hdr_len);
  3778. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  3779. tcp_hdr(skb)->check = 0;
  3780. base_flags &= ~TXD_FLAG_TCPUDP_CSUM;
  3781. } else
  3782. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3783. iph->daddr, 0,
  3784. IPPROTO_TCP,
  3785. 0);
  3786. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) ||
  3787. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705)) {
  3788. if (tcp_opt_len || iph->ihl > 5) {
  3789. int tsflags;
  3790. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3791. mss |= (tsflags << 11);
  3792. }
  3793. } else {
  3794. if (tcp_opt_len || iph->ihl > 5) {
  3795. int tsflags;
  3796. tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2);
  3797. base_flags |= tsflags << 12;
  3798. }
  3799. }
  3800. }
  3801. #if TG3_VLAN_TAG_USED
  3802. if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
  3803. base_flags |= (TXD_FLAG_VLAN |
  3804. (vlan_tx_tag_get(skb) << 16));
  3805. #endif
  3806. /* Queue skb data, a.k.a. the main skb fragment. */
  3807. mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3808. tp->tx_buffers[entry].skb = skb;
  3809. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3810. would_hit_hwbug = 0;
  3811. if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG)
  3812. would_hit_hwbug = 1;
  3813. else if (tg3_4g_overflow_test(mapping, len))
  3814. would_hit_hwbug = 1;
  3815. tg3_set_txd(tp, entry, mapping, len, base_flags,
  3816. (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
  3817. entry = NEXT_TX(entry);
  3818. /* Now loop through additional data fragments, and queue them. */
  3819. if (skb_shinfo(skb)->nr_frags > 0) {
  3820. unsigned int i, last;
  3821. last = skb_shinfo(skb)->nr_frags - 1;
  3822. for (i = 0; i <= last; i++) {
  3823. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3824. len = frag->size;
  3825. mapping = pci_map_page(tp->pdev,
  3826. frag->page,
  3827. frag->page_offset,
  3828. len, PCI_DMA_TODEVICE);
  3829. tp->tx_buffers[entry].skb = NULL;
  3830. pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
  3831. if (tg3_4g_overflow_test(mapping, len))
  3832. would_hit_hwbug = 1;
  3833. if (tg3_40bit_overflow_test(tp, mapping, len))
  3834. would_hit_hwbug = 1;
  3835. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  3836. tg3_set_txd(tp, entry, mapping, len,
  3837. base_flags, (i == last)|(mss << 1));
  3838. else
  3839. tg3_set_txd(tp, entry, mapping, len,
  3840. base_flags, (i == last));
  3841. entry = NEXT_TX(entry);
  3842. }
  3843. }
  3844. if (would_hit_hwbug) {
  3845. u32 last_plus_one = entry;
  3846. u32 start;
  3847. start = entry - 1 - skb_shinfo(skb)->nr_frags;
  3848. start &= (TG3_TX_RING_SIZE - 1);
  3849. /* If the workaround fails due to memory/mapping
  3850. * failure, silently drop this packet.
  3851. */
  3852. if (tigon3_dma_hwbug_workaround(tp, skb, last_plus_one,
  3853. &start, base_flags, mss))
  3854. goto out_unlock;
  3855. entry = start;
  3856. }
  3857. /* Packets are ready, update Tx producer idx local and on card. */
  3858. tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
  3859. tp->tx_prod = entry;
  3860. if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
  3861. netif_stop_queue(dev);
  3862. if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH(tp))
  3863. netif_wake_queue(tp->dev);
  3864. }
  3865. out_unlock:
  3866. mmiowb();
  3867. dev->trans_start = jiffies;
  3868. return NETDEV_TX_OK;
  3869. }
  3870. static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
  3871. int new_mtu)
  3872. {
  3873. dev->mtu = new_mtu;
  3874. if (new_mtu > ETH_DATA_LEN) {
  3875. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  3876. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  3877. ethtool_op_set_tso(dev, 0);
  3878. }
  3879. else
  3880. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  3881. } else {
  3882. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  3883. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  3884. tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
  3885. }
  3886. }
  3887. static int tg3_change_mtu(struct net_device *dev, int new_mtu)
  3888. {
  3889. struct tg3 *tp = netdev_priv(dev);
  3890. int err;
  3891. if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
  3892. return -EINVAL;
  3893. if (!netif_running(dev)) {
  3894. /* We'll just catch it later when the
  3895. * device is up'd.
  3896. */
  3897. tg3_set_mtu(dev, tp, new_mtu);
  3898. return 0;
  3899. }
  3900. tg3_netif_stop(tp);
  3901. tg3_full_lock(tp, 1);
  3902. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  3903. tg3_set_mtu(dev, tp, new_mtu);
  3904. err = tg3_restart_hw(tp, 0);
  3905. if (!err)
  3906. tg3_netif_start(tp);
  3907. tg3_full_unlock(tp);
  3908. return err;
  3909. }
  3910. /* Free up pending packets in all rx/tx rings.
  3911. *
  3912. * The chip has been shut down and the driver detached from
  3913. * the networking, so no interrupts or new tx packets will
  3914. * end up in the driver. tp->{tx,}lock is not held and we are not
  3915. * in an interrupt context and thus may sleep.
  3916. */
  3917. static void tg3_free_rings(struct tg3 *tp)
  3918. {
  3919. struct ring_info *rxp;
  3920. int i;
  3921. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3922. rxp = &tp->rx_std_buffers[i];
  3923. if (rxp->skb == NULL)
  3924. continue;
  3925. pci_unmap_single(tp->pdev,
  3926. pci_unmap_addr(rxp, mapping),
  3927. tp->rx_pkt_buf_sz - tp->rx_offset,
  3928. PCI_DMA_FROMDEVICE);
  3929. dev_kfree_skb_any(rxp->skb);
  3930. rxp->skb = NULL;
  3931. }
  3932. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  3933. rxp = &tp->rx_jumbo_buffers[i];
  3934. if (rxp->skb == NULL)
  3935. continue;
  3936. pci_unmap_single(tp->pdev,
  3937. pci_unmap_addr(rxp, mapping),
  3938. RX_JUMBO_PKT_BUF_SZ - tp->rx_offset,
  3939. PCI_DMA_FROMDEVICE);
  3940. dev_kfree_skb_any(rxp->skb);
  3941. rxp->skb = NULL;
  3942. }
  3943. for (i = 0; i < TG3_TX_RING_SIZE; ) {
  3944. struct tx_ring_info *txp;
  3945. struct sk_buff *skb;
  3946. int j;
  3947. txp = &tp->tx_buffers[i];
  3948. skb = txp->skb;
  3949. if (skb == NULL) {
  3950. i++;
  3951. continue;
  3952. }
  3953. pci_unmap_single(tp->pdev,
  3954. pci_unmap_addr(txp, mapping),
  3955. skb_headlen(skb),
  3956. PCI_DMA_TODEVICE);
  3957. txp->skb = NULL;
  3958. i++;
  3959. for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) {
  3960. txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
  3961. pci_unmap_page(tp->pdev,
  3962. pci_unmap_addr(txp, mapping),
  3963. skb_shinfo(skb)->frags[j].size,
  3964. PCI_DMA_TODEVICE);
  3965. i++;
  3966. }
  3967. dev_kfree_skb_any(skb);
  3968. }
  3969. }
  3970. /* Initialize tx/rx rings for packet processing.
  3971. *
  3972. * The chip has been shut down and the driver detached from
  3973. * the networking, so no interrupts or new tx packets will
  3974. * end up in the driver. tp->{tx,}lock are held and thus
  3975. * we may not sleep.
  3976. */
  3977. static int tg3_init_rings(struct tg3 *tp)
  3978. {
  3979. u32 i;
  3980. /* Free up all the SKBs. */
  3981. tg3_free_rings(tp);
  3982. /* Zero out all descriptors. */
  3983. memset(tp->rx_std, 0, TG3_RX_RING_BYTES);
  3984. memset(tp->rx_jumbo, 0, TG3_RX_JUMBO_RING_BYTES);
  3985. memset(tp->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
  3986. memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
  3987. tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
  3988. if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
  3989. (tp->dev->mtu > ETH_DATA_LEN))
  3990. tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
  3991. /* Initialize invariants of the rings, we only set this
  3992. * stuff once. This works because the card does not
  3993. * write into the rx buffer posting rings.
  3994. */
  3995. for (i = 0; i < TG3_RX_RING_SIZE; i++) {
  3996. struct tg3_rx_buffer_desc *rxd;
  3997. rxd = &tp->rx_std[i];
  3998. rxd->idx_len = (tp->rx_pkt_buf_sz - tp->rx_offset - 64)
  3999. << RXD_LEN_SHIFT;
  4000. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT);
  4001. rxd->opaque = (RXD_OPAQUE_RING_STD |
  4002. (i << RXD_OPAQUE_INDEX_SHIFT));
  4003. }
  4004. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  4005. for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) {
  4006. struct tg3_rx_buffer_desc *rxd;
  4007. rxd = &tp->rx_jumbo[i];
  4008. rxd->idx_len = (RX_JUMBO_PKT_BUF_SZ - tp->rx_offset - 64)
  4009. << RXD_LEN_SHIFT;
  4010. rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) |
  4011. RXD_FLAG_JUMBO;
  4012. rxd->opaque = (RXD_OPAQUE_RING_JUMBO |
  4013. (i << RXD_OPAQUE_INDEX_SHIFT));
  4014. }
  4015. }
  4016. /* Now allocate fresh SKBs for each rx ring. */
  4017. for (i = 0; i < tp->rx_pending; i++) {
  4018. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
  4019. printk(KERN_WARNING PFX
  4020. "%s: Using a smaller RX standard ring, "
  4021. "only %d out of %d buffers were allocated "
  4022. "successfully.\n",
  4023. tp->dev->name, i, tp->rx_pending);
  4024. if (i == 0)
  4025. return -ENOMEM;
  4026. tp->rx_pending = i;
  4027. break;
  4028. }
  4029. }
  4030. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  4031. for (i = 0; i < tp->rx_jumbo_pending; i++) {
  4032. if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
  4033. -1, i) < 0) {
  4034. printk(KERN_WARNING PFX
  4035. "%s: Using a smaller RX jumbo ring, "
  4036. "only %d out of %d buffers were "
  4037. "allocated successfully.\n",
  4038. tp->dev->name, i, tp->rx_jumbo_pending);
  4039. if (i == 0) {
  4040. tg3_free_rings(tp);
  4041. return -ENOMEM;
  4042. }
  4043. tp->rx_jumbo_pending = i;
  4044. break;
  4045. }
  4046. }
  4047. }
  4048. return 0;
  4049. }
  4050. /*
  4051. * Must not be invoked with interrupt sources disabled and
  4052. * the hardware shutdown down.
  4053. */
  4054. static void tg3_free_consistent(struct tg3 *tp)
  4055. {
  4056. kfree(tp->rx_std_buffers);
  4057. tp->rx_std_buffers = NULL;
  4058. if (tp->rx_std) {
  4059. pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
  4060. tp->rx_std, tp->rx_std_mapping);
  4061. tp->rx_std = NULL;
  4062. }
  4063. if (tp->rx_jumbo) {
  4064. pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  4065. tp->rx_jumbo, tp->rx_jumbo_mapping);
  4066. tp->rx_jumbo = NULL;
  4067. }
  4068. if (tp->rx_rcb) {
  4069. pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  4070. tp->rx_rcb, tp->rx_rcb_mapping);
  4071. tp->rx_rcb = NULL;
  4072. }
  4073. if (tp->tx_ring) {
  4074. pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES,
  4075. tp->tx_ring, tp->tx_desc_mapping);
  4076. tp->tx_ring = NULL;
  4077. }
  4078. if (tp->hw_status) {
  4079. pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE,
  4080. tp->hw_status, tp->status_mapping);
  4081. tp->hw_status = NULL;
  4082. }
  4083. if (tp->hw_stats) {
  4084. pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats),
  4085. tp->hw_stats, tp->stats_mapping);
  4086. tp->hw_stats = NULL;
  4087. }
  4088. }
  4089. /*
  4090. * Must not be invoked with interrupt sources disabled and
  4091. * the hardware shutdown down. Can sleep.
  4092. */
  4093. static int tg3_alloc_consistent(struct tg3 *tp)
  4094. {
  4095. tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
  4096. (TG3_RX_RING_SIZE +
  4097. TG3_RX_JUMBO_RING_SIZE)) +
  4098. (sizeof(struct tx_ring_info) *
  4099. TG3_TX_RING_SIZE),
  4100. GFP_KERNEL);
  4101. if (!tp->rx_std_buffers)
  4102. return -ENOMEM;
  4103. tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
  4104. tp->tx_buffers = (struct tx_ring_info *)
  4105. &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
  4106. tp->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES,
  4107. &tp->rx_std_mapping);
  4108. if (!tp->rx_std)
  4109. goto err_out;
  4110. tp->rx_jumbo = pci_alloc_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES,
  4111. &tp->rx_jumbo_mapping);
  4112. if (!tp->rx_jumbo)
  4113. goto err_out;
  4114. tp->rx_rcb = pci_alloc_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp),
  4115. &tp->rx_rcb_mapping);
  4116. if (!tp->rx_rcb)
  4117. goto err_out;
  4118. tp->tx_ring = pci_alloc_consistent(tp->pdev, TG3_TX_RING_BYTES,
  4119. &tp->tx_desc_mapping);
  4120. if (!tp->tx_ring)
  4121. goto err_out;
  4122. tp->hw_status = pci_alloc_consistent(tp->pdev,
  4123. TG3_HW_STATUS_SIZE,
  4124. &tp->status_mapping);
  4125. if (!tp->hw_status)
  4126. goto err_out;
  4127. tp->hw_stats = pci_alloc_consistent(tp->pdev,
  4128. sizeof(struct tg3_hw_stats),
  4129. &tp->stats_mapping);
  4130. if (!tp->hw_stats)
  4131. goto err_out;
  4132. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  4133. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  4134. return 0;
  4135. err_out:
  4136. tg3_free_consistent(tp);
  4137. return -ENOMEM;
  4138. }
  4139. #define MAX_WAIT_CNT 1000
  4140. /* To stop a block, clear the enable bit and poll till it
  4141. * clears. tp->lock is held.
  4142. */
  4143. static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent)
  4144. {
  4145. unsigned int i;
  4146. u32 val;
  4147. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  4148. switch (ofs) {
  4149. case RCVLSC_MODE:
  4150. case DMAC_MODE:
  4151. case MBFREE_MODE:
  4152. case BUFMGR_MODE:
  4153. case MEMARB_MODE:
  4154. /* We can't enable/disable these bits of the
  4155. * 5705/5750, just say success.
  4156. */
  4157. return 0;
  4158. default:
  4159. break;
  4160. };
  4161. }
  4162. val = tr32(ofs);
  4163. val &= ~enable_bit;
  4164. tw32_f(ofs, val);
  4165. for (i = 0; i < MAX_WAIT_CNT; i++) {
  4166. udelay(100);
  4167. val = tr32(ofs);
  4168. if ((val & enable_bit) == 0)
  4169. break;
  4170. }
  4171. if (i == MAX_WAIT_CNT && !silent) {
  4172. printk(KERN_ERR PFX "tg3_stop_block timed out, "
  4173. "ofs=%lx enable_bit=%x\n",
  4174. ofs, enable_bit);
  4175. return -ENODEV;
  4176. }
  4177. return 0;
  4178. }
  4179. /* tp->lock is held. */
  4180. static int tg3_abort_hw(struct tg3 *tp, int silent)
  4181. {
  4182. int i, err;
  4183. tg3_disable_ints(tp);
  4184. tp->rx_mode &= ~RX_MODE_ENABLE;
  4185. tw32_f(MAC_RX_MODE, tp->rx_mode);
  4186. udelay(10);
  4187. err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent);
  4188. err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent);
  4189. err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent);
  4190. err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent);
  4191. err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent);
  4192. err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent);
  4193. err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent);
  4194. err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent);
  4195. err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent);
  4196. err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent);
  4197. err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent);
  4198. err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent);
  4199. err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent);
  4200. tp->mac_mode &= ~MAC_MODE_TDE_ENABLE;
  4201. tw32_f(MAC_MODE, tp->mac_mode);
  4202. udelay(40);
  4203. tp->tx_mode &= ~TX_MODE_ENABLE;
  4204. tw32_f(MAC_TX_MODE, tp->tx_mode);
  4205. for (i = 0; i < MAX_WAIT_CNT; i++) {
  4206. udelay(100);
  4207. if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE))
  4208. break;
  4209. }
  4210. if (i >= MAX_WAIT_CNT) {
  4211. printk(KERN_ERR PFX "tg3_abort_hw timed out for %s, "
  4212. "TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n",
  4213. tp->dev->name, tr32(MAC_TX_MODE));
  4214. err |= -ENODEV;
  4215. }
  4216. err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent);
  4217. err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent);
  4218. err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent);
  4219. tw32(FTQ_RESET, 0xffffffff);
  4220. tw32(FTQ_RESET, 0x00000000);
  4221. err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent);
  4222. err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent);
  4223. if (tp->hw_status)
  4224. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  4225. if (tp->hw_stats)
  4226. memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats));
  4227. return err;
  4228. }
  4229. /* tp->lock is held. */
  4230. static int tg3_nvram_lock(struct tg3 *tp)
  4231. {
  4232. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  4233. int i;
  4234. if (tp->nvram_lock_cnt == 0) {
  4235. tw32(NVRAM_SWARB, SWARB_REQ_SET1);
  4236. for (i = 0; i < 8000; i++) {
  4237. if (tr32(NVRAM_SWARB) & SWARB_GNT1)
  4238. break;
  4239. udelay(20);
  4240. }
  4241. if (i == 8000) {
  4242. tw32(NVRAM_SWARB, SWARB_REQ_CLR1);
  4243. return -ENODEV;
  4244. }
  4245. }
  4246. tp->nvram_lock_cnt++;
  4247. }
  4248. return 0;
  4249. }
  4250. /* tp->lock is held. */
  4251. static void tg3_nvram_unlock(struct tg3 *tp)
  4252. {
  4253. if (tp->tg3_flags & TG3_FLAG_NVRAM) {
  4254. if (tp->nvram_lock_cnt > 0)
  4255. tp->nvram_lock_cnt--;
  4256. if (tp->nvram_lock_cnt == 0)
  4257. tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1);
  4258. }
  4259. }
  4260. /* tp->lock is held. */
  4261. static void tg3_enable_nvram_access(struct tg3 *tp)
  4262. {
  4263. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  4264. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  4265. u32 nvaccess = tr32(NVRAM_ACCESS);
  4266. tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE);
  4267. }
  4268. }
  4269. /* tp->lock is held. */
  4270. static void tg3_disable_nvram_access(struct tg3 *tp)
  4271. {
  4272. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  4273. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM)) {
  4274. u32 nvaccess = tr32(NVRAM_ACCESS);
  4275. tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE);
  4276. }
  4277. }
  4278. static void tg3_ape_send_event(struct tg3 *tp, u32 event)
  4279. {
  4280. int i;
  4281. u32 apedata;
  4282. apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG);
  4283. if (apedata != APE_SEG_SIG_MAGIC)
  4284. return;
  4285. apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS);
  4286. if (apedata != APE_FW_STATUS_READY)
  4287. return;
  4288. /* Wait for up to 1 millisecond for APE to service previous event. */
  4289. for (i = 0; i < 10; i++) {
  4290. if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM))
  4291. return;
  4292. apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS);
  4293. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4294. tg3_ape_write32(tp, TG3_APE_EVENT_STATUS,
  4295. event | APE_EVENT_STATUS_EVENT_PENDING);
  4296. tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
  4297. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4298. break;
  4299. udelay(100);
  4300. }
  4301. if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING))
  4302. tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1);
  4303. }
  4304. static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
  4305. {
  4306. u32 event;
  4307. u32 apedata;
  4308. if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  4309. return;
  4310. switch (kind) {
  4311. case RESET_KIND_INIT:
  4312. tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG,
  4313. APE_HOST_SEG_SIG_MAGIC);
  4314. tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN,
  4315. APE_HOST_SEG_LEN_MAGIC);
  4316. apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT);
  4317. tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata);
  4318. tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID,
  4319. APE_HOST_DRIVER_ID_MAGIC);
  4320. tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR,
  4321. APE_HOST_BEHAV_NO_PHYLOCK);
  4322. event = APE_EVENT_STATUS_STATE_START;
  4323. break;
  4324. case RESET_KIND_SHUTDOWN:
  4325. event = APE_EVENT_STATUS_STATE_UNLOAD;
  4326. break;
  4327. case RESET_KIND_SUSPEND:
  4328. event = APE_EVENT_STATUS_STATE_SUSPEND;
  4329. break;
  4330. default:
  4331. return;
  4332. }
  4333. event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE;
  4334. tg3_ape_send_event(tp, event);
  4335. }
  4336. /* tp->lock is held. */
  4337. static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind)
  4338. {
  4339. tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX,
  4340. NIC_SRAM_FIRMWARE_MBOX_MAGIC1);
  4341. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4342. switch (kind) {
  4343. case RESET_KIND_INIT:
  4344. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4345. DRV_STATE_START);
  4346. break;
  4347. case RESET_KIND_SHUTDOWN:
  4348. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4349. DRV_STATE_UNLOAD);
  4350. break;
  4351. case RESET_KIND_SUSPEND:
  4352. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4353. DRV_STATE_SUSPEND);
  4354. break;
  4355. default:
  4356. break;
  4357. };
  4358. }
  4359. if (kind == RESET_KIND_INIT ||
  4360. kind == RESET_KIND_SUSPEND)
  4361. tg3_ape_driver_state_change(tp, kind);
  4362. }
  4363. /* tp->lock is held. */
  4364. static void tg3_write_sig_post_reset(struct tg3 *tp, int kind)
  4365. {
  4366. if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) {
  4367. switch (kind) {
  4368. case RESET_KIND_INIT:
  4369. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4370. DRV_STATE_START_DONE);
  4371. break;
  4372. case RESET_KIND_SHUTDOWN:
  4373. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4374. DRV_STATE_UNLOAD_DONE);
  4375. break;
  4376. default:
  4377. break;
  4378. };
  4379. }
  4380. if (kind == RESET_KIND_SHUTDOWN)
  4381. tg3_ape_driver_state_change(tp, kind);
  4382. }
  4383. /* tp->lock is held. */
  4384. static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
  4385. {
  4386. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  4387. switch (kind) {
  4388. case RESET_KIND_INIT:
  4389. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4390. DRV_STATE_START);
  4391. break;
  4392. case RESET_KIND_SHUTDOWN:
  4393. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4394. DRV_STATE_UNLOAD);
  4395. break;
  4396. case RESET_KIND_SUSPEND:
  4397. tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX,
  4398. DRV_STATE_SUSPEND);
  4399. break;
  4400. default:
  4401. break;
  4402. };
  4403. }
  4404. }
  4405. static int tg3_poll_fw(struct tg3 *tp)
  4406. {
  4407. int i;
  4408. u32 val;
  4409. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4410. /* Wait up to 20ms for init done. */
  4411. for (i = 0; i < 200; i++) {
  4412. if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE)
  4413. return 0;
  4414. udelay(100);
  4415. }
  4416. return -ENODEV;
  4417. }
  4418. /* Wait for firmware initialization to complete. */
  4419. for (i = 0; i < 100000; i++) {
  4420. tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
  4421. if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
  4422. break;
  4423. udelay(10);
  4424. }
  4425. /* Chip might not be fitted with firmware. Some Sun onboard
  4426. * parts are configured like that. So don't signal the timeout
  4427. * of the above loop as an error, but do report the lack of
  4428. * running firmware once.
  4429. */
  4430. if (i >= 100000 &&
  4431. !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
  4432. tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
  4433. printk(KERN_INFO PFX "%s: No firmware running.\n",
  4434. tp->dev->name);
  4435. }
  4436. return 0;
  4437. }
  4438. /* Save PCI command register before chip reset */
  4439. static void tg3_save_pci_state(struct tg3 *tp)
  4440. {
  4441. pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd);
  4442. }
  4443. /* Restore PCI state after chip reset */
  4444. static void tg3_restore_pci_state(struct tg3 *tp)
  4445. {
  4446. u32 val;
  4447. /* Re-enable indirect register accesses. */
  4448. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  4449. tp->misc_host_ctrl);
  4450. /* Set MAX PCI retry to zero. */
  4451. val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE);
  4452. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  4453. (tp->tg3_flags & TG3_FLAG_PCIX_MODE))
  4454. val |= PCISTATE_RETRY_SAME_DMA;
  4455. /* Allow reads and writes to the APE register and memory space. */
  4456. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
  4457. val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  4458. PCISTATE_ALLOW_APE_SHMEM_WR;
  4459. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
  4460. pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd);
  4461. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  4462. pcie_set_readrq(tp->pdev, 4096);
  4463. else {
  4464. pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE,
  4465. tp->pci_cacheline_sz);
  4466. pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER,
  4467. tp->pci_lat_timer);
  4468. }
  4469. /* Make sure PCI-X relaxed ordering bit is clear. */
  4470. if (tp->pcix_cap) {
  4471. u16 pcix_cmd;
  4472. pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  4473. &pcix_cmd);
  4474. pcix_cmd &= ~PCI_X_CMD_ERO;
  4475. pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  4476. pcix_cmd);
  4477. }
  4478. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
  4479. /* Chip reset on 5780 will reset MSI enable bit,
  4480. * so need to restore it.
  4481. */
  4482. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  4483. u16 ctrl;
  4484. pci_read_config_word(tp->pdev,
  4485. tp->msi_cap + PCI_MSI_FLAGS,
  4486. &ctrl);
  4487. pci_write_config_word(tp->pdev,
  4488. tp->msi_cap + PCI_MSI_FLAGS,
  4489. ctrl | PCI_MSI_FLAGS_ENABLE);
  4490. val = tr32(MSGINT_MODE);
  4491. tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE);
  4492. }
  4493. }
  4494. }
  4495. static void tg3_stop_fw(struct tg3 *);
  4496. /* tp->lock is held. */
  4497. static int tg3_chip_reset(struct tg3 *tp)
  4498. {
  4499. u32 val;
  4500. void (*write_op)(struct tg3 *, u32, u32);
  4501. int err;
  4502. tg3_nvram_lock(tp);
  4503. /* No matching tg3_nvram_unlock() after this because
  4504. * chip reset below will undo the nvram lock.
  4505. */
  4506. tp->nvram_lock_cnt = 0;
  4507. /* GRC_MISC_CFG core clock reset will clear the memory
  4508. * enable bit in PCI register 4 and the MSI enable bit
  4509. * on some chips, so we save relevant registers here.
  4510. */
  4511. tg3_save_pci_state(tp);
  4512. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  4513. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  4514. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  4515. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  4516. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  4517. tw32(GRC_FASTBOOT_PC, 0);
  4518. /*
  4519. * We must avoid the readl() that normally takes place.
  4520. * It locks machines, causes machine checks, and other
  4521. * fun things. So, temporarily disable the 5701
  4522. * hardware workaround, while we do the reset.
  4523. */
  4524. write_op = tp->write32;
  4525. if (write_op == tg3_write_flush_reg32)
  4526. tp->write32 = tg3_write32;
  4527. /* Prevent the irq handler from reading or writing PCI registers
  4528. * during chip reset when the memory enable bit in the PCI command
  4529. * register may be cleared. The chip does not generate interrupt
  4530. * at this time, but the irq handler may still be called due to irq
  4531. * sharing or irqpoll.
  4532. */
  4533. tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING;
  4534. if (tp->hw_status) {
  4535. tp->hw_status->status = 0;
  4536. tp->hw_status->status_tag = 0;
  4537. }
  4538. tp->last_tag = 0;
  4539. smp_mb();
  4540. synchronize_irq(tp->pdev->irq);
  4541. /* do the reset */
  4542. val = GRC_MISC_CFG_CORECLK_RESET;
  4543. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4544. if (tr32(0x7e2c) == 0x60) {
  4545. tw32(0x7e2c, 0x20);
  4546. }
  4547. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4548. tw32(GRC_MISC_CFG, (1 << 29));
  4549. val |= (1 << 29);
  4550. }
  4551. }
  4552. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4553. tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET);
  4554. tw32(GRC_VCPU_EXT_CTRL,
  4555. tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU);
  4556. }
  4557. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4558. val |= GRC_MISC_CFG_KEEP_GPHY_POWER;
  4559. tw32(GRC_MISC_CFG, val);
  4560. /* restore 5701 hardware bug workaround write method */
  4561. tp->write32 = write_op;
  4562. /* Unfortunately, we have to delay before the PCI read back.
  4563. * Some 575X chips even will not respond to a PCI cfg access
  4564. * when the reset command is given to the chip.
  4565. *
  4566. * How do these hardware designers expect things to work
  4567. * properly if the PCI write is posted for a long period
  4568. * of time? It is always necessary to have some method by
  4569. * which a register read back can occur to push the write
  4570. * out which does the reset.
  4571. *
  4572. * For most tg3 variants the trick below was working.
  4573. * Ho hum...
  4574. */
  4575. udelay(120);
  4576. /* Flush PCI posted writes. The normal MMIO registers
  4577. * are inaccessible at this time so this is the only
  4578. * way to make this reliably (actually, this is no longer
  4579. * the case, see above). I tried to use indirect
  4580. * register read/write but this upset some 5701 variants.
  4581. */
  4582. pci_read_config_dword(tp->pdev, PCI_COMMAND, &val);
  4583. udelay(120);
  4584. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  4585. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
  4586. int i;
  4587. u32 cfg_val;
  4588. /* Wait for link training to complete. */
  4589. for (i = 0; i < 5000; i++)
  4590. udelay(100);
  4591. pci_read_config_dword(tp->pdev, 0xc4, &cfg_val);
  4592. pci_write_config_dword(tp->pdev, 0xc4,
  4593. cfg_val | (1 << 15));
  4594. }
  4595. /* Set PCIE max payload size and clear error status. */
  4596. pci_write_config_dword(tp->pdev, 0xd8, 0xf5000);
  4597. }
  4598. tg3_restore_pci_state(tp);
  4599. tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING;
  4600. val = 0;
  4601. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  4602. val = tr32(MEMARB_MODE);
  4603. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  4604. if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) {
  4605. tg3_stop_fw(tp);
  4606. tw32(0x5000, 0x400);
  4607. }
  4608. tw32(GRC_MODE, tp->grc_mode);
  4609. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) {
  4610. val = tr32(0xc4);
  4611. tw32(0xc4, val | (1 << 15));
  4612. }
  4613. if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 &&
  4614. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  4615. tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE;
  4616. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0)
  4617. tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN;
  4618. tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  4619. }
  4620. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  4621. tp->mac_mode = MAC_MODE_PORT_MODE_TBI;
  4622. tw32_f(MAC_MODE, tp->mac_mode);
  4623. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  4624. tp->mac_mode = MAC_MODE_PORT_MODE_GMII;
  4625. tw32_f(MAC_MODE, tp->mac_mode);
  4626. } else
  4627. tw32_f(MAC_MODE, 0);
  4628. udelay(40);
  4629. err = tg3_poll_fw(tp);
  4630. if (err)
  4631. return err;
  4632. if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  4633. tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
  4634. val = tr32(0x7c00);
  4635. tw32(0x7c00, val | (1 << 25));
  4636. }
  4637. /* Reprobe ASF enable state. */
  4638. tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF;
  4639. tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE;
  4640. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  4641. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  4642. u32 nic_cfg;
  4643. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  4644. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  4645. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  4646. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  4647. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  4648. }
  4649. }
  4650. return 0;
  4651. }
  4652. /* tp->lock is held. */
  4653. static void tg3_stop_fw(struct tg3 *tp)
  4654. {
  4655. if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
  4656. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
  4657. u32 val;
  4658. /* Wait for RX cpu to ACK the previous event. */
  4659. tg3_wait_for_event_ack(tp);
  4660. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
  4661. val = tr32(GRC_RX_CPU_EVENT);
  4662. val |= GRC_RX_CPU_DRIVER_EVENT;
  4663. tw32(GRC_RX_CPU_EVENT, val);
  4664. /* Wait for RX cpu to ACK this event. */
  4665. tg3_wait_for_event_ack(tp);
  4666. }
  4667. }
  4668. /* tp->lock is held. */
  4669. static int tg3_halt(struct tg3 *tp, int kind, int silent)
  4670. {
  4671. int err;
  4672. tg3_stop_fw(tp);
  4673. tg3_write_sig_pre_reset(tp, kind);
  4674. tg3_abort_hw(tp, silent);
  4675. err = tg3_chip_reset(tp);
  4676. tg3_write_sig_legacy(tp, kind);
  4677. tg3_write_sig_post_reset(tp, kind);
  4678. if (err)
  4679. return err;
  4680. return 0;
  4681. }
  4682. #define TG3_FW_RELEASE_MAJOR 0x0
  4683. #define TG3_FW_RELASE_MINOR 0x0
  4684. #define TG3_FW_RELEASE_FIX 0x0
  4685. #define TG3_FW_START_ADDR 0x08000000
  4686. #define TG3_FW_TEXT_ADDR 0x08000000
  4687. #define TG3_FW_TEXT_LEN 0x9c0
  4688. #define TG3_FW_RODATA_ADDR 0x080009c0
  4689. #define TG3_FW_RODATA_LEN 0x60
  4690. #define TG3_FW_DATA_ADDR 0x08000a40
  4691. #define TG3_FW_DATA_LEN 0x20
  4692. #define TG3_FW_SBSS_ADDR 0x08000a60
  4693. #define TG3_FW_SBSS_LEN 0xc
  4694. #define TG3_FW_BSS_ADDR 0x08000a70
  4695. #define TG3_FW_BSS_LEN 0x10
  4696. static const u32 tg3FwText[(TG3_FW_TEXT_LEN / sizeof(u32)) + 1] = {
  4697. 0x00000000, 0x10000003, 0x00000000, 0x0000000d, 0x0000000d, 0x3c1d0800,
  4698. 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100000, 0x0e000018, 0x00000000,
  4699. 0x0000000d, 0x3c1d0800, 0x37bd3ffc, 0x03a0f021, 0x3c100800, 0x26100034,
  4700. 0x0e00021c, 0x00000000, 0x0000000d, 0x00000000, 0x00000000, 0x00000000,
  4701. 0x27bdffe0, 0x3c1cc000, 0xafbf0018, 0xaf80680c, 0x0e00004c, 0x241b2105,
  4702. 0x97850000, 0x97870002, 0x9782002c, 0x9783002e, 0x3c040800, 0x248409c0,
  4703. 0xafa00014, 0x00021400, 0x00621825, 0x00052c00, 0xafa30010, 0x8f860010,
  4704. 0x00e52825, 0x0e000060, 0x24070102, 0x3c02ac00, 0x34420100, 0x3c03ac01,
  4705. 0x34630100, 0xaf820490, 0x3c02ffff, 0xaf820494, 0xaf830498, 0xaf82049c,
  4706. 0x24020001, 0xaf825ce0, 0x0e00003f, 0xaf825d00, 0x0e000140, 0x00000000,
  4707. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x2402ffff, 0xaf825404, 0x8f835400,
  4708. 0x34630400, 0xaf835400, 0xaf825404, 0x3c020800, 0x24420034, 0xaf82541c,
  4709. 0x03e00008, 0xaf805400, 0x00000000, 0x00000000, 0x3c020800, 0x34423000,
  4710. 0x3c030800, 0x34633000, 0x3c040800, 0x348437ff, 0x3c010800, 0xac220a64,
  4711. 0x24020040, 0x3c010800, 0xac220a68, 0x3c010800, 0xac200a60, 0xac600000,
  4712. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  4713. 0x00804821, 0x8faa0010, 0x3c020800, 0x8c420a60, 0x3c040800, 0x8c840a68,
  4714. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010800, 0xac230a60, 0x14400003,
  4715. 0x00004021, 0x3c010800, 0xac200a60, 0x3c020800, 0x8c420a60, 0x3c030800,
  4716. 0x8c630a64, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  4717. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020800, 0x8c420a60,
  4718. 0x3c030800, 0x8c630a64, 0x8f84680c, 0x00021140, 0x00431021, 0xac440008,
  4719. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  4720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4722. 0, 0, 0, 0, 0, 0,
  4723. 0x02000008, 0x00000000, 0x0a0001e3, 0x3c0a0001, 0x0a0001e3, 0x3c0a0002,
  4724. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4725. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4726. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4727. 0x0a0001e3, 0x3c0a0007, 0x0a0001e3, 0x3c0a0008, 0x0a0001e3, 0x3c0a0009,
  4728. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000b,
  4729. 0x0a0001e3, 0x3c0a000c, 0x0a0001e3, 0x3c0a000d, 0x0a0001e3, 0x00000000,
  4730. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a000e, 0x0a0001e3, 0x00000000,
  4731. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4732. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x00000000,
  4733. 0x0a0001e3, 0x00000000, 0x0a0001e3, 0x3c0a0013, 0x0a0001e3, 0x3c0a0014,
  4734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  4737. 0x27bdffe0, 0x00001821, 0x00001021, 0xafbf0018, 0xafb10014, 0xafb00010,
  4738. 0x3c010800, 0x00220821, 0xac200a70, 0x3c010800, 0x00220821, 0xac200a74,
  4739. 0x3c010800, 0x00220821, 0xac200a78, 0x24630001, 0x1860fff5, 0x2442000c,
  4740. 0x24110001, 0x8f906810, 0x32020004, 0x14400005, 0x24040001, 0x3c020800,
  4741. 0x8c420a78, 0x18400003, 0x00002021, 0x0e000182, 0x00000000, 0x32020001,
  4742. 0x10400003, 0x00000000, 0x0e000169, 0x00000000, 0x0a000153, 0xaf915028,
  4743. 0x8fbf0018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020, 0x3c050800,
  4744. 0x8ca50a70, 0x3c060800, 0x8cc60a80, 0x3c070800, 0x8ce70a78, 0x27bdffe0,
  4745. 0x3c040800, 0x248409d0, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014,
  4746. 0x0e00017b, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x24020001,
  4747. 0x8f836810, 0x00821004, 0x00021027, 0x00621824, 0x03e00008, 0xaf836810,
  4748. 0x27bdffd8, 0xafbf0024, 0x1080002e, 0xafb00020, 0x8f825cec, 0xafa20018,
  4749. 0x8f825cec, 0x3c100800, 0x26100a78, 0xafa2001c, 0x34028000, 0xaf825cec,
  4750. 0x8e020000, 0x18400016, 0x00000000, 0x3c020800, 0x94420a74, 0x8fa3001c,
  4751. 0x000221c0, 0xac830004, 0x8fa2001c, 0x3c010800, 0x0e000201, 0xac220a74,
  4752. 0x10400005, 0x00000000, 0x8e020000, 0x24420001, 0x0a0001df, 0xae020000,
  4753. 0x3c020800, 0x8c420a70, 0x00021c02, 0x000321c0, 0x0a0001c5, 0xafa2001c,
  4754. 0x0e000201, 0x00000000, 0x1040001f, 0x00000000, 0x8e020000, 0x8fa3001c,
  4755. 0x24420001, 0x3c010800, 0xac230a70, 0x3c010800, 0xac230a74, 0x0a0001df,
  4756. 0xae020000, 0x3c100800, 0x26100a78, 0x8e020000, 0x18400028, 0x00000000,
  4757. 0x0e000201, 0x00000000, 0x14400024, 0x00000000, 0x8e020000, 0x3c030800,
  4758. 0x8c630a70, 0x2442ffff, 0xafa3001c, 0x18400006, 0xae020000, 0x00031402,
  4759. 0x000221c0, 0x8c820004, 0x3c010800, 0xac220a70, 0x97a2001e, 0x2442ff00,
  4760. 0x2c420300, 0x1440000b, 0x24024000, 0x3c040800, 0x248409dc, 0xafa00010,
  4761. 0xafa00014, 0x8fa6001c, 0x24050008, 0x0e000060, 0x00003821, 0x0a0001df,
  4762. 0x00000000, 0xaf825cf8, 0x3c020800, 0x8c420a40, 0x8fa3001c, 0x24420001,
  4763. 0xaf835cf8, 0x3c010800, 0xac220a40, 0x8fbf0024, 0x8fb00020, 0x03e00008,
  4764. 0x27bd0028, 0x27bdffe0, 0x3c040800, 0x248409e8, 0x00002821, 0x00003021,
  4765. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x8fbf0018,
  4766. 0x03e00008, 0x27bd0020, 0x8f82680c, 0x8f85680c, 0x00021827, 0x0003182b,
  4767. 0x00031823, 0x00431024, 0x00441021, 0x00a2282b, 0x10a00006, 0x00000000,
  4768. 0x00401821, 0x8f82680c, 0x0043102b, 0x1440fffd, 0x00000000, 0x03e00008,
  4769. 0x00000000, 0x3c040800, 0x8c840000, 0x3c030800, 0x8c630a40, 0x0064102b,
  4770. 0x54400002, 0x00831023, 0x00641023, 0x2c420008, 0x03e00008, 0x38420001,
  4771. 0x27bdffe0, 0x00802821, 0x3c040800, 0x24840a00, 0x00003021, 0x00003821,
  4772. 0xafbf0018, 0xafa00010, 0x0e000060, 0xafa00014, 0x0a000216, 0x00000000,
  4773. 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000, 0x27bdffe0, 0x3c1cc000,
  4774. 0xafbf0018, 0x0e00004c, 0xaf80680c, 0x3c040800, 0x24840a10, 0x03802821,
  4775. 0x00003021, 0x00003821, 0xafa00010, 0x0e000060, 0xafa00014, 0x2402ffff,
  4776. 0xaf825404, 0x3c0200aa, 0x0e000234, 0xaf825434, 0x8fbf0018, 0x03e00008,
  4777. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe8, 0xafb00010,
  4778. 0x24100001, 0xafbf0014, 0x3c01c003, 0xac200000, 0x8f826810, 0x30422000,
  4779. 0x10400003, 0x00000000, 0x0e000246, 0x00000000, 0x0a00023a, 0xaf905428,
  4780. 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x27bdfff8, 0x8f845d0c,
  4781. 0x3c0200ff, 0x3c030800, 0x8c630a50, 0x3442fff8, 0x00821024, 0x1043001e,
  4782. 0x3c0500ff, 0x34a5fff8, 0x3c06c003, 0x3c074000, 0x00851824, 0x8c620010,
  4783. 0x3c010800, 0xac230a50, 0x30420008, 0x10400005, 0x00871025, 0x8cc20000,
  4784. 0x24420001, 0xacc20000, 0x00871025, 0xaf825d0c, 0x8fa20000, 0x24420001,
  4785. 0xafa20000, 0x8fa20000, 0x8fa20000, 0x24420001, 0xafa20000, 0x8fa20000,
  4786. 0x8f845d0c, 0x3c030800, 0x8c630a50, 0x00851024, 0x1443ffe8, 0x00851824,
  4787. 0x27bd0008, 0x03e00008, 0x00000000, 0x00000000, 0x00000000
  4788. };
  4789. static const u32 tg3FwRodata[(TG3_FW_RODATA_LEN / sizeof(u32)) + 1] = {
  4790. 0x35373031, 0x726c7341, 0x00000000, 0x00000000, 0x53774576, 0x656e7430,
  4791. 0x00000000, 0x726c7045, 0x76656e74, 0x31000000, 0x556e6b6e, 0x45766e74,
  4792. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  4793. 0x00000000, 0x00000000, 0x4d61696e, 0x43707542, 0x00000000, 0x00000000,
  4794. 0x00000000
  4795. };
  4796. #if 0 /* All zeros, don't eat up space with it. */
  4797. u32 tg3FwData[(TG3_FW_DATA_LEN / sizeof(u32)) + 1] = {
  4798. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  4799. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  4800. };
  4801. #endif
  4802. #define RX_CPU_SCRATCH_BASE 0x30000
  4803. #define RX_CPU_SCRATCH_SIZE 0x04000
  4804. #define TX_CPU_SCRATCH_BASE 0x34000
  4805. #define TX_CPU_SCRATCH_SIZE 0x04000
  4806. /* tp->lock is held. */
  4807. static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
  4808. {
  4809. int i;
  4810. BUG_ON(offset == TX_CPU_BASE &&
  4811. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
  4812. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  4813. u32 val = tr32(GRC_VCPU_EXT_CTRL);
  4814. tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU);
  4815. return 0;
  4816. }
  4817. if (offset == RX_CPU_BASE) {
  4818. for (i = 0; i < 10000; i++) {
  4819. tw32(offset + CPU_STATE, 0xffffffff);
  4820. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4821. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4822. break;
  4823. }
  4824. tw32(offset + CPU_STATE, 0xffffffff);
  4825. tw32_f(offset + CPU_MODE, CPU_MODE_HALT);
  4826. udelay(10);
  4827. } else {
  4828. for (i = 0; i < 10000; i++) {
  4829. tw32(offset + CPU_STATE, 0xffffffff);
  4830. tw32(offset + CPU_MODE, CPU_MODE_HALT);
  4831. if (tr32(offset + CPU_MODE) & CPU_MODE_HALT)
  4832. break;
  4833. }
  4834. }
  4835. if (i >= 10000) {
  4836. printk(KERN_ERR PFX "tg3_reset_cpu timed out for %s, "
  4837. "and %s CPU\n",
  4838. tp->dev->name,
  4839. (offset == RX_CPU_BASE ? "RX" : "TX"));
  4840. return -ENODEV;
  4841. }
  4842. /* Clear firmware's nvram arbitration. */
  4843. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  4844. tw32(NVRAM_SWARB, SWARB_REQ_CLR0);
  4845. return 0;
  4846. }
  4847. struct fw_info {
  4848. unsigned int text_base;
  4849. unsigned int text_len;
  4850. const u32 *text_data;
  4851. unsigned int rodata_base;
  4852. unsigned int rodata_len;
  4853. const u32 *rodata_data;
  4854. unsigned int data_base;
  4855. unsigned int data_len;
  4856. const u32 *data_data;
  4857. };
  4858. /* tp->lock is held. */
  4859. static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base,
  4860. int cpu_scratch_size, struct fw_info *info)
  4861. {
  4862. int err, lock_err, i;
  4863. void (*write_op)(struct tg3 *, u32, u32);
  4864. if (cpu_base == TX_CPU_BASE &&
  4865. (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  4866. printk(KERN_ERR PFX "tg3_load_firmware_cpu: Trying to load "
  4867. "TX cpu firmware on %s which is 5705.\n",
  4868. tp->dev->name);
  4869. return -EINVAL;
  4870. }
  4871. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  4872. write_op = tg3_write_mem;
  4873. else
  4874. write_op = tg3_write_indirect_reg32;
  4875. /* It is possible that bootcode is still loading at this point.
  4876. * Get the nvram lock first before halting the cpu.
  4877. */
  4878. lock_err = tg3_nvram_lock(tp);
  4879. err = tg3_halt_cpu(tp, cpu_base);
  4880. if (!lock_err)
  4881. tg3_nvram_unlock(tp);
  4882. if (err)
  4883. goto out;
  4884. for (i = 0; i < cpu_scratch_size; i += sizeof(u32))
  4885. write_op(tp, cpu_scratch_base + i, 0);
  4886. tw32(cpu_base + CPU_STATE, 0xffffffff);
  4887. tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT);
  4888. for (i = 0; i < (info->text_len / sizeof(u32)); i++)
  4889. write_op(tp, (cpu_scratch_base +
  4890. (info->text_base & 0xffff) +
  4891. (i * sizeof(u32))),
  4892. (info->text_data ?
  4893. info->text_data[i] : 0));
  4894. for (i = 0; i < (info->rodata_len / sizeof(u32)); i++)
  4895. write_op(tp, (cpu_scratch_base +
  4896. (info->rodata_base & 0xffff) +
  4897. (i * sizeof(u32))),
  4898. (info->rodata_data ?
  4899. info->rodata_data[i] : 0));
  4900. for (i = 0; i < (info->data_len / sizeof(u32)); i++)
  4901. write_op(tp, (cpu_scratch_base +
  4902. (info->data_base & 0xffff) +
  4903. (i * sizeof(u32))),
  4904. (info->data_data ?
  4905. info->data_data[i] : 0));
  4906. err = 0;
  4907. out:
  4908. return err;
  4909. }
  4910. /* tp->lock is held. */
  4911. static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
  4912. {
  4913. struct fw_info info;
  4914. int err, i;
  4915. info.text_base = TG3_FW_TEXT_ADDR;
  4916. info.text_len = TG3_FW_TEXT_LEN;
  4917. info.text_data = &tg3FwText[0];
  4918. info.rodata_base = TG3_FW_RODATA_ADDR;
  4919. info.rodata_len = TG3_FW_RODATA_LEN;
  4920. info.rodata_data = &tg3FwRodata[0];
  4921. info.data_base = TG3_FW_DATA_ADDR;
  4922. info.data_len = TG3_FW_DATA_LEN;
  4923. info.data_data = NULL;
  4924. err = tg3_load_firmware_cpu(tp, RX_CPU_BASE,
  4925. RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE,
  4926. &info);
  4927. if (err)
  4928. return err;
  4929. err = tg3_load_firmware_cpu(tp, TX_CPU_BASE,
  4930. TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE,
  4931. &info);
  4932. if (err)
  4933. return err;
  4934. /* Now startup only the RX cpu. */
  4935. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4936. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4937. for (i = 0; i < 5; i++) {
  4938. if (tr32(RX_CPU_BASE + CPU_PC) == TG3_FW_TEXT_ADDR)
  4939. break;
  4940. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4941. tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT);
  4942. tw32_f(RX_CPU_BASE + CPU_PC, TG3_FW_TEXT_ADDR);
  4943. udelay(1000);
  4944. }
  4945. if (i >= 5) {
  4946. printk(KERN_ERR PFX "tg3_load_firmware fails for %s "
  4947. "to set RX CPU PC, is %08x should be %08x\n",
  4948. tp->dev->name, tr32(RX_CPU_BASE + CPU_PC),
  4949. TG3_FW_TEXT_ADDR);
  4950. return -ENODEV;
  4951. }
  4952. tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff);
  4953. tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000);
  4954. return 0;
  4955. }
  4956. #define TG3_TSO_FW_RELEASE_MAJOR 0x1
  4957. #define TG3_TSO_FW_RELASE_MINOR 0x6
  4958. #define TG3_TSO_FW_RELEASE_FIX 0x0
  4959. #define TG3_TSO_FW_START_ADDR 0x08000000
  4960. #define TG3_TSO_FW_TEXT_ADDR 0x08000000
  4961. #define TG3_TSO_FW_TEXT_LEN 0x1aa0
  4962. #define TG3_TSO_FW_RODATA_ADDR 0x08001aa0
  4963. #define TG3_TSO_FW_RODATA_LEN 0x60
  4964. #define TG3_TSO_FW_DATA_ADDR 0x08001b20
  4965. #define TG3_TSO_FW_DATA_LEN 0x30
  4966. #define TG3_TSO_FW_SBSS_ADDR 0x08001b50
  4967. #define TG3_TSO_FW_SBSS_LEN 0x2c
  4968. #define TG3_TSO_FW_BSS_ADDR 0x08001b80
  4969. #define TG3_TSO_FW_BSS_LEN 0x894
  4970. static const u32 tg3TsoFwText[(TG3_TSO_FW_TEXT_LEN / 4) + 1] = {
  4971. 0x0e000003, 0x00000000, 0x08001b24, 0x00000000, 0x10000003, 0x00000000,
  4972. 0x0000000d, 0x0000000d, 0x3c1d0800, 0x37bd4000, 0x03a0f021, 0x3c100800,
  4973. 0x26100000, 0x0e000010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  4974. 0xafbf0018, 0x0e0005d8, 0x34840002, 0x0e000668, 0x00000000, 0x3c030800,
  4975. 0x90631b68, 0x24020002, 0x3c040800, 0x24841aac, 0x14620003, 0x24050001,
  4976. 0x3c040800, 0x24841aa0, 0x24060006, 0x00003821, 0xafa00010, 0x0e00067c,
  4977. 0xafa00014, 0x8f625c50, 0x34420001, 0xaf625c50, 0x8f625c90, 0x34420001,
  4978. 0xaf625c90, 0x2402ffff, 0x0e000034, 0xaf625404, 0x8fbf0018, 0x03e00008,
  4979. 0x27bd0020, 0x00000000, 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c,
  4980. 0xafb20018, 0xafb10014, 0x0e00005b, 0xafb00010, 0x24120002, 0x24110001,
  4981. 0x8f706820, 0x32020100, 0x10400003, 0x00000000, 0x0e0000bb, 0x00000000,
  4982. 0x8f706820, 0x32022000, 0x10400004, 0x32020001, 0x0e0001f0, 0x24040001,
  4983. 0x32020001, 0x10400003, 0x00000000, 0x0e0000a3, 0x00000000, 0x3c020800,
  4984. 0x90421b98, 0x14520003, 0x00000000, 0x0e0004c0, 0x00000000, 0x0a00003c,
  4985. 0xaf715028, 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008,
  4986. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ac0, 0x00002821, 0x00003021,
  4987. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x3c040800,
  4988. 0x248423d8, 0xa4800000, 0x3c010800, 0xa0201b98, 0x3c010800, 0xac201b9c,
  4989. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  4990. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bbc, 0x8f624434, 0x3c010800,
  4991. 0xac221b88, 0x8f624438, 0x3c010800, 0xac221b8c, 0x8f624410, 0xac80f7a8,
  4992. 0x3c010800, 0xac201b84, 0x3c010800, 0xac2023e0, 0x3c010800, 0xac2023c8,
  4993. 0x3c010800, 0xac2023cc, 0x3c010800, 0xac202400, 0x3c010800, 0xac221b90,
  4994. 0x8f620068, 0x24030007, 0x00021702, 0x10430005, 0x00000000, 0x8f620068,
  4995. 0x00021702, 0x14400004, 0x24020001, 0x3c010800, 0x0a000097, 0xac20240c,
  4996. 0xac820034, 0x3c040800, 0x24841acc, 0x3c050800, 0x8ca5240c, 0x00003021,
  4997. 0x00003821, 0xafa00010, 0x0e00067c, 0xafa00014, 0x8fbf0018, 0x03e00008,
  4998. 0x27bd0020, 0x27bdffe0, 0x3c040800, 0x24841ad8, 0x00002821, 0x00003021,
  4999. 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014, 0x0e00005b,
  5000. 0x00000000, 0x0e0000b4, 0x00002021, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5001. 0x24020001, 0x8f636820, 0x00821004, 0x00021027, 0x00621824, 0x03e00008,
  5002. 0xaf636820, 0x27bdffd0, 0xafbf002c, 0xafb60028, 0xafb50024, 0xafb40020,
  5003. 0xafb3001c, 0xafb20018, 0xafb10014, 0xafb00010, 0x8f675c5c, 0x3c030800,
  5004. 0x24631bbc, 0x8c620000, 0x14470005, 0x3c0200ff, 0x3c020800, 0x90421b98,
  5005. 0x14400119, 0x3c0200ff, 0x3442fff8, 0x00e28824, 0xac670000, 0x00111902,
  5006. 0x306300ff, 0x30e20003, 0x000211c0, 0x00622825, 0x00a04021, 0x00071602,
  5007. 0x3c030800, 0x90631b98, 0x3044000f, 0x14600036, 0x00804821, 0x24020001,
  5008. 0x3c010800, 0xa0221b98, 0x00051100, 0x00821025, 0x3c010800, 0xac201b9c,
  5009. 0x3c010800, 0xac201ba0, 0x3c010800, 0xac201ba4, 0x3c010800, 0xac201bac,
  5010. 0x3c010800, 0xac201bb8, 0x3c010800, 0xac201bb0, 0x3c010800, 0xac201bb4,
  5011. 0x3c010800, 0xa42223d8, 0x9622000c, 0x30437fff, 0x3c010800, 0xa4222410,
  5012. 0x30428000, 0x3c010800, 0xa4231bc6, 0x10400005, 0x24020001, 0x3c010800,
  5013. 0xac2223f4, 0x0a000102, 0x2406003e, 0x24060036, 0x3c010800, 0xac2023f4,
  5014. 0x9622000a, 0x3c030800, 0x94631bc6, 0x3c010800, 0xac2023f0, 0x3c010800,
  5015. 0xac2023f8, 0x00021302, 0x00021080, 0x00c21021, 0x00621821, 0x3c010800,
  5016. 0xa42223d0, 0x3c010800, 0x0a000115, 0xa4231b96, 0x9622000c, 0x3c010800,
  5017. 0xa42223ec, 0x3c040800, 0x24841b9c, 0x8c820000, 0x00021100, 0x3c010800,
  5018. 0x00220821, 0xac311bc8, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  5019. 0xac271bcc, 0x8c820000, 0x25030001, 0x306601ff, 0x00021100, 0x3c010800,
  5020. 0x00220821, 0xac261bd0, 0x8c820000, 0x00021100, 0x3c010800, 0x00220821,
  5021. 0xac291bd4, 0x96230008, 0x3c020800, 0x8c421bac, 0x00432821, 0x3c010800,
  5022. 0xac251bac, 0x9622000a, 0x30420004, 0x14400018, 0x00061100, 0x8f630c14,
  5023. 0x3063000f, 0x2c620002, 0x1440000b, 0x3c02c000, 0x8f630c14, 0x3c020800,
  5024. 0x8c421b40, 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002,
  5025. 0x1040fff7, 0x3c02c000, 0x00e21825, 0xaf635c5c, 0x8f625c50, 0x30420002,
  5026. 0x10400014, 0x00000000, 0x0a000147, 0x00000000, 0x3c030800, 0x8c631b80,
  5027. 0x3c040800, 0x94841b94, 0x01221025, 0x3c010800, 0xa42223da, 0x24020001,
  5028. 0x3c010800, 0xac221bb8, 0x24630001, 0x0085202a, 0x3c010800, 0x10800003,
  5029. 0xac231b80, 0x3c010800, 0xa4251b94, 0x3c060800, 0x24c61b9c, 0x8cc20000,
  5030. 0x24420001, 0xacc20000, 0x28420080, 0x14400005, 0x00000000, 0x0e000656,
  5031. 0x24040002, 0x0a0001e6, 0x00000000, 0x3c020800, 0x8c421bb8, 0x10400078,
  5032. 0x24020001, 0x3c050800, 0x90a51b98, 0x14a20072, 0x00000000, 0x3c150800,
  5033. 0x96b51b96, 0x3c040800, 0x8c841bac, 0x32a3ffff, 0x0083102a, 0x1440006c,
  5034. 0x00000000, 0x14830003, 0x00000000, 0x3c010800, 0xac2523f0, 0x1060005c,
  5035. 0x00009021, 0x24d60004, 0x0060a021, 0x24d30014, 0x8ec20000, 0x00028100,
  5036. 0x3c110800, 0x02308821, 0x0e000625, 0x8e311bc8, 0x00402821, 0x10a00054,
  5037. 0x00000000, 0x9628000a, 0x31020040, 0x10400005, 0x2407180c, 0x8e22000c,
  5038. 0x2407188c, 0x00021400, 0xaca20018, 0x3c030800, 0x00701821, 0x8c631bd0,
  5039. 0x3c020800, 0x00501021, 0x8c421bd4, 0x00031d00, 0x00021400, 0x00621825,
  5040. 0xaca30014, 0x8ec30004, 0x96220008, 0x00432023, 0x3242ffff, 0x3083ffff,
  5041. 0x00431021, 0x0282102a, 0x14400002, 0x02b23023, 0x00803021, 0x8e620000,
  5042. 0x30c4ffff, 0x00441021, 0xae620000, 0x8e220000, 0xaca20000, 0x8e220004,
  5043. 0x8e63fff4, 0x00431021, 0xaca20004, 0xa4a6000e, 0x8e62fff4, 0x00441021,
  5044. 0xae62fff4, 0x96230008, 0x0043102a, 0x14400005, 0x02469021, 0x8e62fff0,
  5045. 0xae60fff4, 0x24420001, 0xae62fff0, 0xaca00008, 0x3242ffff, 0x14540008,
  5046. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x24020905, 0xa4a2000c,
  5047. 0x0a0001cb, 0x34e70020, 0xa4a2000c, 0x3c020800, 0x8c4223f0, 0x10400003,
  5048. 0x3c024b65, 0x0a0001d3, 0x34427654, 0x3c02b49a, 0x344289ab, 0xaca2001c,
  5049. 0x30e2ffff, 0xaca20010, 0x0e0005a2, 0x00a02021, 0x3242ffff, 0x0054102b,
  5050. 0x1440ffa9, 0x00000000, 0x24020002, 0x3c010800, 0x0a0001e6, 0xa0221b98,
  5051. 0x8ec2083c, 0x24420001, 0x0a0001e6, 0xaec2083c, 0x0e0004c0, 0x00000000,
  5052. 0x8fbf002c, 0x8fb60028, 0x8fb50024, 0x8fb40020, 0x8fb3001c, 0x8fb20018,
  5053. 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0030, 0x27bdffd0, 0xafbf0028,
  5054. 0xafb30024, 0xafb20020, 0xafb1001c, 0xafb00018, 0x8f725c9c, 0x3c0200ff,
  5055. 0x3442fff8, 0x3c070800, 0x24e71bb4, 0x02428824, 0x9623000e, 0x8ce20000,
  5056. 0x00431021, 0xace20000, 0x8e220010, 0x30420020, 0x14400011, 0x00809821,
  5057. 0x0e00063b, 0x02202021, 0x3c02c000, 0x02421825, 0xaf635c9c, 0x8f625c90,
  5058. 0x30420002, 0x1040011e, 0x00000000, 0xaf635c9c, 0x8f625c90, 0x30420002,
  5059. 0x10400119, 0x00000000, 0x0a00020d, 0x00000000, 0x8e240008, 0x8e230014,
  5060. 0x00041402, 0x000231c0, 0x00031502, 0x304201ff, 0x2442ffff, 0x3042007f,
  5061. 0x00031942, 0x30637800, 0x00021100, 0x24424000, 0x00624821, 0x9522000a,
  5062. 0x3084ffff, 0x30420008, 0x104000b0, 0x000429c0, 0x3c020800, 0x8c422400,
  5063. 0x14400024, 0x24c50008, 0x94c20014, 0x3c010800, 0xa42223d0, 0x8cc40010,
  5064. 0x00041402, 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42423d4, 0x94c2000e,
  5065. 0x3083ffff, 0x00431023, 0x3c010800, 0xac222408, 0x94c2001a, 0x3c010800,
  5066. 0xac262400, 0x3c010800, 0xac322404, 0x3c010800, 0xac2223fc, 0x3c02c000,
  5067. 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e5, 0x00000000,
  5068. 0xaf635c9c, 0x8f625c90, 0x30420002, 0x104000e0, 0x00000000, 0x0a000246,
  5069. 0x00000000, 0x94c2000e, 0x3c030800, 0x946323d4, 0x00434023, 0x3103ffff,
  5070. 0x2c620008, 0x1040001c, 0x00000000, 0x94c20014, 0x24420028, 0x00a22821,
  5071. 0x00031042, 0x1840000b, 0x00002021, 0x24e60848, 0x00403821, 0x94a30000,
  5072. 0x8cc20000, 0x24840001, 0x00431021, 0xacc20000, 0x0087102a, 0x1440fff9,
  5073. 0x24a50002, 0x31020001, 0x1040001f, 0x3c024000, 0x3c040800, 0x248423fc,
  5074. 0xa0a00001, 0x94a30000, 0x8c820000, 0x00431021, 0x0a000285, 0xac820000,
  5075. 0x8f626800, 0x3c030010, 0x00431024, 0x10400009, 0x00000000, 0x94c2001a,
  5076. 0x3c030800, 0x8c6323fc, 0x00431021, 0x3c010800, 0xac2223fc, 0x0a000286,
  5077. 0x3c024000, 0x94c2001a, 0x94c4001c, 0x3c030800, 0x8c6323fc, 0x00441023,
  5078. 0x00621821, 0x3c010800, 0xac2323fc, 0x3c024000, 0x02421825, 0xaf635c9c,
  5079. 0x8f625c90, 0x30420002, 0x1440fffc, 0x00000000, 0x9522000a, 0x30420010,
  5080. 0x1040009b, 0x00000000, 0x3c030800, 0x946323d4, 0x3c070800, 0x24e72400,
  5081. 0x8ce40000, 0x8f626800, 0x24630030, 0x00832821, 0x3c030010, 0x00431024,
  5082. 0x1440000a, 0x00000000, 0x94a20004, 0x3c040800, 0x8c842408, 0x3c030800,
  5083. 0x8c6323fc, 0x00441023, 0x00621821, 0x3c010800, 0xac2323fc, 0x3c040800,
  5084. 0x8c8423fc, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402, 0x00822021,
  5085. 0x00041027, 0xa4a20006, 0x3c030800, 0x8c632404, 0x3c0200ff, 0x3442fff8,
  5086. 0x00628824, 0x96220008, 0x24050001, 0x24034000, 0x000231c0, 0x00801021,
  5087. 0xa4c2001a, 0xa4c0001c, 0xace00000, 0x3c010800, 0xac251b60, 0xaf635cb8,
  5088. 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000, 0x3c010800, 0xac201b60,
  5089. 0x8e220008, 0xaf625cb8, 0x8f625cb0, 0x30420002, 0x10400003, 0x00000000,
  5090. 0x3c010800, 0xac201b60, 0x3c020800, 0x8c421b60, 0x1040ffec, 0x00000000,
  5091. 0x3c040800, 0x0e00063b, 0x8c842404, 0x0a00032a, 0x00000000, 0x3c030800,
  5092. 0x90631b98, 0x24020002, 0x14620003, 0x3c034b65, 0x0a0002e1, 0x00008021,
  5093. 0x8e22001c, 0x34637654, 0x10430002, 0x24100002, 0x24100001, 0x00c02021,
  5094. 0x0e000350, 0x02003021, 0x24020003, 0x3c010800, 0xa0221b98, 0x24020002,
  5095. 0x1202000a, 0x24020001, 0x3c030800, 0x8c6323f0, 0x10620006, 0x00000000,
  5096. 0x3c020800, 0x944223d8, 0x00021400, 0x0a00031f, 0xae220014, 0x3c040800,
  5097. 0x248423da, 0x94820000, 0x00021400, 0xae220014, 0x3c020800, 0x8c421bbc,
  5098. 0x3c03c000, 0x3c010800, 0xa0201b98, 0x00431025, 0xaf625c5c, 0x8f625c50,
  5099. 0x30420002, 0x10400009, 0x00000000, 0x2484f7e2, 0x8c820000, 0x00431025,
  5100. 0xaf625c5c, 0x8f625c50, 0x30420002, 0x1440fffa, 0x00000000, 0x3c020800,
  5101. 0x24421b84, 0x8c430000, 0x24630001, 0xac430000, 0x8f630c14, 0x3063000f,
  5102. 0x2c620002, 0x1440000c, 0x3c024000, 0x8f630c14, 0x3c020800, 0x8c421b40,
  5103. 0x3063000f, 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7,
  5104. 0x00000000, 0x3c024000, 0x02421825, 0xaf635c9c, 0x8f625c90, 0x30420002,
  5105. 0x1440fffc, 0x00000000, 0x12600003, 0x00000000, 0x0e0004c0, 0x00000000,
  5106. 0x8fbf0028, 0x8fb30024, 0x8fb20020, 0x8fb1001c, 0x8fb00018, 0x03e00008,
  5107. 0x27bd0030, 0x8f634450, 0x3c040800, 0x24841b88, 0x8c820000, 0x00031c02,
  5108. 0x0043102b, 0x14400007, 0x3c038000, 0x8c840004, 0x8f624450, 0x00021c02,
  5109. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  5110. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3c024000,
  5111. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00000000,
  5112. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00805821, 0x14c00011, 0x256e0008,
  5113. 0x3c020800, 0x8c4223f4, 0x10400007, 0x24020016, 0x3c010800, 0xa42223d2,
  5114. 0x2402002a, 0x3c010800, 0x0a000364, 0xa42223d4, 0x8d670010, 0x00071402,
  5115. 0x3c010800, 0xa42223d2, 0x3c010800, 0xa42723d4, 0x3c040800, 0x948423d4,
  5116. 0x3c030800, 0x946323d2, 0x95cf0006, 0x3c020800, 0x944223d0, 0x00832023,
  5117. 0x01e2c023, 0x3065ffff, 0x24a20028, 0x01c24821, 0x3082ffff, 0x14c0001a,
  5118. 0x01226021, 0x9582000c, 0x3042003f, 0x3c010800, 0xa42223d6, 0x95820004,
  5119. 0x95830006, 0x3c010800, 0xac2023e4, 0x3c010800, 0xac2023e8, 0x00021400,
  5120. 0x00431025, 0x3c010800, 0xac221bc0, 0x95220004, 0x3c010800, 0xa4221bc4,
  5121. 0x95230002, 0x01e51023, 0x0043102a, 0x10400010, 0x24020001, 0x3c010800,
  5122. 0x0a000398, 0xac2223f8, 0x3c030800, 0x8c6323e8, 0x3c020800, 0x94421bc4,
  5123. 0x00431021, 0xa5220004, 0x3c020800, 0x94421bc0, 0xa5820004, 0x3c020800,
  5124. 0x8c421bc0, 0xa5820006, 0x3c020800, 0x8c4223f0, 0x3c0d0800, 0x8dad23e4,
  5125. 0x3c0a0800, 0x144000e5, 0x8d4a23e8, 0x3c020800, 0x94421bc4, 0x004a1821,
  5126. 0x3063ffff, 0x0062182b, 0x24020002, 0x10c2000d, 0x01435023, 0x3c020800,
  5127. 0x944223d6, 0x30420009, 0x10400008, 0x00000000, 0x9582000c, 0x3042fff6,
  5128. 0xa582000c, 0x3c020800, 0x944223d6, 0x30420009, 0x01a26823, 0x3c020800,
  5129. 0x8c4223f8, 0x1040004a, 0x01203821, 0x3c020800, 0x944223d2, 0x00004021,
  5130. 0xa520000a, 0x01e21023, 0xa5220002, 0x3082ffff, 0x00021042, 0x18400008,
  5131. 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021, 0x0103102a,
  5132. 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061402,
  5133. 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021, 0x2527000c,
  5134. 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004, 0x1440fffb,
  5135. 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023, 0x01803821,
  5136. 0x3082ffff, 0xa4e00010, 0x00621821, 0x00021042, 0x18400010, 0x00c33021,
  5137. 0x00404821, 0x94e20000, 0x24e70002, 0x00c23021, 0x30e2007f, 0x14400006,
  5138. 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80, 0x00625824, 0x25670008,
  5139. 0x0109102a, 0x1440fff3, 0x00000000, 0x30820001, 0x10400005, 0x00061c02,
  5140. 0xa0e00001, 0x94e20000, 0x00c23021, 0x00061c02, 0x30c2ffff, 0x00623021,
  5141. 0x00061402, 0x00c23021, 0x0a00047d, 0x30c6ffff, 0x24020002, 0x14c20081,
  5142. 0x00000000, 0x3c020800, 0x8c42240c, 0x14400007, 0x00000000, 0x3c020800,
  5143. 0x944223d2, 0x95230002, 0x01e21023, 0x10620077, 0x00000000, 0x3c020800,
  5144. 0x944223d2, 0x01e21023, 0xa5220002, 0x3c020800, 0x8c42240c, 0x1040001a,
  5145. 0x31e3ffff, 0x8dc70010, 0x3c020800, 0x94421b96, 0x00e04021, 0x00072c02,
  5146. 0x00aa2021, 0x00431023, 0x00823823, 0x00072402, 0x30e2ffff, 0x00823821,
  5147. 0x00071027, 0xa522000a, 0x3102ffff, 0x3c040800, 0x948423d4, 0x00453023,
  5148. 0x00e02821, 0x00641823, 0x006d1821, 0x00c33021, 0x00061c02, 0x30c2ffff,
  5149. 0x0a00047d, 0x00623021, 0x01203821, 0x00004021, 0x3082ffff, 0x00021042,
  5150. 0x18400008, 0x00003021, 0x00401821, 0x94e20000, 0x25080001, 0x00c23021,
  5151. 0x0103102a, 0x1440fffb, 0x24e70002, 0x00061c02, 0x30c2ffff, 0x00623021,
  5152. 0x00061402, 0x00c23021, 0x00c02821, 0x00061027, 0xa522000a, 0x00003021,
  5153. 0x2527000c, 0x00004021, 0x94e20000, 0x25080001, 0x00c23021, 0x2d020004,
  5154. 0x1440fffb, 0x24e70002, 0x95220002, 0x00004021, 0x91230009, 0x00442023,
  5155. 0x01803821, 0x3082ffff, 0xa4e00010, 0x3c040800, 0x948423d4, 0x00621821,
  5156. 0x00c33021, 0x00061c02, 0x30c2ffff, 0x00623021, 0x00061c02, 0x3c020800,
  5157. 0x944223d0, 0x00c34821, 0x00441023, 0x00021fc2, 0x00431021, 0x00021043,
  5158. 0x18400010, 0x00003021, 0x00402021, 0x94e20000, 0x24e70002, 0x00c23021,
  5159. 0x30e2007f, 0x14400006, 0x25080001, 0x8d630000, 0x3c02007f, 0x3442ff80,
  5160. 0x00625824, 0x25670008, 0x0104102a, 0x1440fff3, 0x00000000, 0x3c020800,
  5161. 0x944223ec, 0x00c23021, 0x3122ffff, 0x00c23021, 0x00061c02, 0x30c2ffff,
  5162. 0x00623021, 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010,
  5163. 0xadc00014, 0x0a00049d, 0xadc00000, 0x8dc70010, 0x00e04021, 0x11400007,
  5164. 0x00072c02, 0x00aa3021, 0x00061402, 0x30c3ffff, 0x00433021, 0x00061402,
  5165. 0x00c22821, 0x00051027, 0xa522000a, 0x3c030800, 0x946323d4, 0x3102ffff,
  5166. 0x01e21021, 0x00433023, 0x00cd3021, 0x00061c02, 0x30c2ffff, 0x00623021,
  5167. 0x00061402, 0x00c23021, 0x00c04021, 0x00061027, 0xa5820010, 0x3102ffff,
  5168. 0x00051c00, 0x00431025, 0xadc20010, 0x3c020800, 0x8c4223f4, 0x10400005,
  5169. 0x2de205eb, 0x14400002, 0x25e2fff2, 0x34028870, 0xa5c20034, 0x3c030800,
  5170. 0x246323e8, 0x8c620000, 0x24420001, 0xac620000, 0x3c040800, 0x8c8423e4,
  5171. 0x3c020800, 0x8c421bc0, 0x3303ffff, 0x00832021, 0x00431821, 0x0062102b,
  5172. 0x3c010800, 0xac2423e4, 0x10400003, 0x2482ffff, 0x3c010800, 0xac2223e4,
  5173. 0x3c010800, 0xac231bc0, 0x03e00008, 0x27bd0020, 0x27bdffb8, 0x3c050800,
  5174. 0x24a51b96, 0xafbf0044, 0xafbe0040, 0xafb7003c, 0xafb60038, 0xafb50034,
  5175. 0xafb40030, 0xafb3002c, 0xafb20028, 0xafb10024, 0xafb00020, 0x94a90000,
  5176. 0x3c020800, 0x944223d0, 0x3c030800, 0x8c631bb0, 0x3c040800, 0x8c841bac,
  5177. 0x01221023, 0x0064182a, 0xa7a9001e, 0x106000be, 0xa7a20016, 0x24be0022,
  5178. 0x97b6001e, 0x24b3001a, 0x24b70016, 0x8fc20000, 0x14400008, 0x00000000,
  5179. 0x8fc2fff8, 0x97a30016, 0x8fc4fff4, 0x00431021, 0x0082202a, 0x148000b0,
  5180. 0x00000000, 0x97d50818, 0x32a2ffff, 0x104000a3, 0x00009021, 0x0040a021,
  5181. 0x00008821, 0x0e000625, 0x00000000, 0x00403021, 0x14c00007, 0x00000000,
  5182. 0x3c020800, 0x8c4223dc, 0x24420001, 0x3c010800, 0x0a000596, 0xac2223dc,
  5183. 0x3c100800, 0x02118021, 0x8e101bc8, 0x9608000a, 0x31020040, 0x10400005,
  5184. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x31020080,
  5185. 0x54400001, 0x34e70010, 0x3c020800, 0x00511021, 0x8c421bd0, 0x3c030800,
  5186. 0x00711821, 0x8c631bd4, 0x00021500, 0x00031c00, 0x00431025, 0xacc20014,
  5187. 0x96040008, 0x3242ffff, 0x00821021, 0x0282102a, 0x14400002, 0x02b22823,
  5188. 0x00802821, 0x8e020000, 0x02459021, 0xacc20000, 0x8e020004, 0x00c02021,
  5189. 0x26310010, 0xac820004, 0x30e2ffff, 0xac800008, 0xa485000e, 0xac820010,
  5190. 0x24020305, 0x0e0005a2, 0xa482000c, 0x3242ffff, 0x0054102b, 0x1440ffc5,
  5191. 0x3242ffff, 0x0a00058e, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  5192. 0x10400067, 0x00000000, 0x8e62fff0, 0x00028900, 0x3c100800, 0x02118021,
  5193. 0x0e000625, 0x8e101bc8, 0x00403021, 0x14c00005, 0x00000000, 0x8e62082c,
  5194. 0x24420001, 0x0a000596, 0xae62082c, 0x9608000a, 0x31020040, 0x10400005,
  5195. 0x2407180c, 0x8e02000c, 0x2407188c, 0x00021400, 0xacc20018, 0x3c020800,
  5196. 0x00511021, 0x8c421bd0, 0x3c030800, 0x00711821, 0x8c631bd4, 0x00021500,
  5197. 0x00031c00, 0x00431025, 0xacc20014, 0x8e63fff4, 0x96020008, 0x00432023,
  5198. 0x3242ffff, 0x3083ffff, 0x00431021, 0x02c2102a, 0x10400003, 0x00802821,
  5199. 0x97a9001e, 0x01322823, 0x8e620000, 0x30a4ffff, 0x00441021, 0xae620000,
  5200. 0xa4c5000e, 0x8e020000, 0xacc20000, 0x8e020004, 0x8e63fff4, 0x00431021,
  5201. 0xacc20004, 0x8e63fff4, 0x96020008, 0x00641821, 0x0062102a, 0x14400006,
  5202. 0x02459021, 0x8e62fff0, 0xae60fff4, 0x24420001, 0x0a000571, 0xae62fff0,
  5203. 0xae63fff4, 0xacc00008, 0x3242ffff, 0x10560003, 0x31020004, 0x10400006,
  5204. 0x24020305, 0x31020080, 0x54400001, 0x34e70010, 0x34e70020, 0x24020905,
  5205. 0xa4c2000c, 0x8ee30000, 0x8ee20004, 0x14620007, 0x3c02b49a, 0x8ee20860,
  5206. 0x54400001, 0x34e70400, 0x3c024b65, 0x0a000588, 0x34427654, 0x344289ab,
  5207. 0xacc2001c, 0x30e2ffff, 0xacc20010, 0x0e0005a2, 0x00c02021, 0x3242ffff,
  5208. 0x0056102b, 0x1440ff9b, 0x00000000, 0x8e620000, 0x8e63fffc, 0x0043102a,
  5209. 0x1440ff48, 0x00000000, 0x8fbf0044, 0x8fbe0040, 0x8fb7003c, 0x8fb60038,
  5210. 0x8fb50034, 0x8fb40030, 0x8fb3002c, 0x8fb20028, 0x8fb10024, 0x8fb00020,
  5211. 0x03e00008, 0x27bd0048, 0x27bdffe8, 0xafbf0014, 0xafb00010, 0x8f624450,
  5212. 0x8f634410, 0x0a0005b1, 0x00808021, 0x8f626820, 0x30422000, 0x10400003,
  5213. 0x00000000, 0x0e0001f0, 0x00002021, 0x8f624450, 0x8f634410, 0x3042ffff,
  5214. 0x0043102b, 0x1440fff5, 0x00000000, 0x8f630c14, 0x3063000f, 0x2c620002,
  5215. 0x1440000b, 0x00000000, 0x8f630c14, 0x3c020800, 0x8c421b40, 0x3063000f,
  5216. 0x24420001, 0x3c010800, 0xac221b40, 0x2c620002, 0x1040fff7, 0x00000000,
  5217. 0xaf705c18, 0x8f625c10, 0x30420002, 0x10400009, 0x00000000, 0x8f626820,
  5218. 0x30422000, 0x1040fff8, 0x00000000, 0x0e0001f0, 0x00002021, 0x0a0005c4,
  5219. 0x00000000, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000,
  5220. 0x00000000, 0x00000000, 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010,
  5221. 0xaf60680c, 0x8f626804, 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50,
  5222. 0x3c010800, 0xac221b54, 0x24020b78, 0x3c010800, 0xac221b64, 0x34630002,
  5223. 0xaf634000, 0x0e000605, 0x00808021, 0x3c010800, 0xa0221b68, 0x304200ff,
  5224. 0x24030002, 0x14430005, 0x00000000, 0x3c020800, 0x8c421b54, 0x0a0005f8,
  5225. 0xac5000c0, 0x3c020800, 0x8c421b54, 0xac5000bc, 0x8f624434, 0x8f634438,
  5226. 0x8f644410, 0x3c010800, 0xac221b5c, 0x3c010800, 0xac231b6c, 0x3c010800,
  5227. 0xac241b58, 0x8fbf0014, 0x8fb00010, 0x03e00008, 0x27bd0018, 0x3c040800,
  5228. 0x8c870000, 0x3c03aa55, 0x3463aa55, 0x3c06c003, 0xac830000, 0x8cc20000,
  5229. 0x14430007, 0x24050002, 0x3c0355aa, 0x346355aa, 0xac830000, 0x8cc20000,
  5230. 0x50430001, 0x24050001, 0x3c020800, 0xac470000, 0x03e00008, 0x00a01021,
  5231. 0x27bdfff8, 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe,
  5232. 0x00000000, 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008,
  5233. 0x27bd0008, 0x8f634450, 0x3c020800, 0x8c421b5c, 0x00031c02, 0x0043102b,
  5234. 0x14400008, 0x3c038000, 0x3c040800, 0x8c841b6c, 0x8f624450, 0x00021c02,
  5235. 0x0083102b, 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024,
  5236. 0x1440fffd, 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff,
  5237. 0x2442e000, 0x2c422001, 0x14400003, 0x3c024000, 0x0a000648, 0x2402ffff,
  5238. 0x00822025, 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021,
  5239. 0x03e00008, 0x00000000, 0x8f624450, 0x3c030800, 0x8c631b58, 0x0a000651,
  5240. 0x3042ffff, 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000,
  5241. 0x03e00008, 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040800, 0x24841af0,
  5242. 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010, 0x0e00067c, 0xafa00014,
  5243. 0x0a000660, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x00000000,
  5244. 0x00000000, 0x00000000, 0x3c020800, 0x34423000, 0x3c030800, 0x34633000,
  5245. 0x3c040800, 0x348437ff, 0x3c010800, 0xac221b74, 0x24020040, 0x3c010800,
  5246. 0xac221b78, 0x3c010800, 0xac201b70, 0xac600000, 0x24630004, 0x0083102b,
  5247. 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000, 0x00804821, 0x8faa0010,
  5248. 0x3c020800, 0x8c421b70, 0x3c040800, 0x8c841b78, 0x8fab0014, 0x24430001,
  5249. 0x0044102b, 0x3c010800, 0xac231b70, 0x14400003, 0x00004021, 0x3c010800,
  5250. 0xac201b70, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74, 0x91240000,
  5251. 0x00021140, 0x00431021, 0x00481021, 0x25080001, 0xa0440000, 0x29020008,
  5252. 0x1440fff4, 0x25290001, 0x3c020800, 0x8c421b70, 0x3c030800, 0x8c631b74,
  5253. 0x8f64680c, 0x00021140, 0x00431021, 0xac440008, 0xac45000c, 0xac460010,
  5254. 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c, 0x00000000, 0x00000000,
  5255. };
  5256. static const u32 tg3TsoFwRodata[] = {
  5257. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5258. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x496e0000, 0x73746b6f,
  5259. 0x66662a2a, 0x00000000, 0x53774576, 0x656e7430, 0x00000000, 0x00000000,
  5260. 0x00000000, 0x00000000, 0x66617461, 0x6c457272, 0x00000000, 0x00000000,
  5261. 0x00000000,
  5262. };
  5263. static const u32 tg3TsoFwData[] = {
  5264. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x362e3000, 0x00000000,
  5265. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  5266. 0x00000000,
  5267. };
  5268. /* 5705 needs a special version of the TSO firmware. */
  5269. #define TG3_TSO5_FW_RELEASE_MAJOR 0x1
  5270. #define TG3_TSO5_FW_RELASE_MINOR 0x2
  5271. #define TG3_TSO5_FW_RELEASE_FIX 0x0
  5272. #define TG3_TSO5_FW_START_ADDR 0x00010000
  5273. #define TG3_TSO5_FW_TEXT_ADDR 0x00010000
  5274. #define TG3_TSO5_FW_TEXT_LEN 0xe90
  5275. #define TG3_TSO5_FW_RODATA_ADDR 0x00010e90
  5276. #define TG3_TSO5_FW_RODATA_LEN 0x50
  5277. #define TG3_TSO5_FW_DATA_ADDR 0x00010f00
  5278. #define TG3_TSO5_FW_DATA_LEN 0x20
  5279. #define TG3_TSO5_FW_SBSS_ADDR 0x00010f20
  5280. #define TG3_TSO5_FW_SBSS_LEN 0x28
  5281. #define TG3_TSO5_FW_BSS_ADDR 0x00010f50
  5282. #define TG3_TSO5_FW_BSS_LEN 0x88
  5283. static const u32 tg3Tso5FwText[(TG3_TSO5_FW_TEXT_LEN / 4) + 1] = {
  5284. 0x0c004003, 0x00000000, 0x00010f04, 0x00000000, 0x10000003, 0x00000000,
  5285. 0x0000000d, 0x0000000d, 0x3c1d0001, 0x37bde000, 0x03a0f021, 0x3c100001,
  5286. 0x26100000, 0x0c004010, 0x00000000, 0x0000000d, 0x27bdffe0, 0x3c04fefe,
  5287. 0xafbf0018, 0x0c0042e8, 0x34840002, 0x0c004364, 0x00000000, 0x3c030001,
  5288. 0x90630f34, 0x24020002, 0x3c040001, 0x24840e9c, 0x14620003, 0x24050001,
  5289. 0x3c040001, 0x24840e90, 0x24060002, 0x00003821, 0xafa00010, 0x0c004378,
  5290. 0xafa00014, 0x0c00402c, 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5291. 0x00000000, 0x00000000, 0x27bdffe0, 0xafbf001c, 0xafb20018, 0xafb10014,
  5292. 0x0c0042d4, 0xafb00010, 0x3c128000, 0x24110001, 0x8f706810, 0x32020400,
  5293. 0x10400007, 0x00000000, 0x8f641008, 0x00921024, 0x14400003, 0x00000000,
  5294. 0x0c004064, 0x00000000, 0x3c020001, 0x90420f56, 0x10510003, 0x32020200,
  5295. 0x1040fff1, 0x00000000, 0x0c0041b4, 0x00000000, 0x08004034, 0x00000000,
  5296. 0x8fbf001c, 0x8fb20018, 0x8fb10014, 0x8fb00010, 0x03e00008, 0x27bd0020,
  5297. 0x27bdffe0, 0x3c040001, 0x24840eb0, 0x00002821, 0x00003021, 0x00003821,
  5298. 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130,
  5299. 0xaf625000, 0x3c010001, 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018,
  5300. 0x03e00008, 0x27bd0020, 0x00000000, 0x00000000, 0x3c030001, 0x24630f60,
  5301. 0x90620000, 0x27bdfff0, 0x14400003, 0x0080c021, 0x08004073, 0x00004821,
  5302. 0x3c022000, 0x03021024, 0x10400003, 0x24090002, 0x08004073, 0xa0600000,
  5303. 0x24090001, 0x00181040, 0x30431f80, 0x346f8008, 0x1520004b, 0x25eb0028,
  5304. 0x3c040001, 0x00832021, 0x8c848010, 0x3c050001, 0x24a50f7a, 0x00041402,
  5305. 0xa0a20000, 0x3c010001, 0xa0240f7b, 0x3c020001, 0x00431021, 0x94428014,
  5306. 0x3c010001, 0xa0220f7c, 0x3c0c0001, 0x01836021, 0x8d8c8018, 0x304200ff,
  5307. 0x24420008, 0x000220c3, 0x24020001, 0x3c010001, 0xa0220f60, 0x0124102b,
  5308. 0x1040000c, 0x00003821, 0x24a6000e, 0x01602821, 0x8ca20000, 0x8ca30004,
  5309. 0x24a50008, 0x24e70001, 0xacc20000, 0xacc30004, 0x00e4102b, 0x1440fff8,
  5310. 0x24c60008, 0x00003821, 0x3c080001, 0x25080f7b, 0x91060000, 0x3c020001,
  5311. 0x90420f7c, 0x2503000d, 0x00c32821, 0x00461023, 0x00021fc2, 0x00431021,
  5312. 0x00021043, 0x1840000c, 0x00002021, 0x91020001, 0x00461023, 0x00021fc2,
  5313. 0x00431021, 0x00021843, 0x94a20000, 0x24e70001, 0x00822021, 0x00e3102a,
  5314. 0x1440fffb, 0x24a50002, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  5315. 0x00822021, 0x3c02ffff, 0x01821024, 0x3083ffff, 0x00431025, 0x3c010001,
  5316. 0x080040fa, 0xac220f80, 0x3c050001, 0x24a50f7c, 0x90a20000, 0x3c0c0001,
  5317. 0x01836021, 0x8d8c8018, 0x000220c2, 0x1080000e, 0x00003821, 0x01603021,
  5318. 0x24a5000c, 0x8ca20000, 0x8ca30004, 0x24a50008, 0x24e70001, 0xacc20000,
  5319. 0xacc30004, 0x00e4102b, 0x1440fff8, 0x24c60008, 0x3c050001, 0x24a50f7c,
  5320. 0x90a20000, 0x30430007, 0x24020004, 0x10620011, 0x28620005, 0x10400005,
  5321. 0x24020002, 0x10620008, 0x000710c0, 0x080040fa, 0x00000000, 0x24020006,
  5322. 0x1062000e, 0x000710c0, 0x080040fa, 0x00000000, 0x00a21821, 0x9463000c,
  5323. 0x004b1021, 0x080040fa, 0xa4430000, 0x000710c0, 0x00a21821, 0x8c63000c,
  5324. 0x004b1021, 0x080040fa, 0xac430000, 0x00a21821, 0x8c63000c, 0x004b2021,
  5325. 0x00a21021, 0xac830000, 0x94420010, 0xa4820004, 0x95e70006, 0x3c020001,
  5326. 0x90420f7c, 0x3c030001, 0x90630f7a, 0x00e2c823, 0x3c020001, 0x90420f7b,
  5327. 0x24630028, 0x01e34021, 0x24420028, 0x15200012, 0x01e23021, 0x94c2000c,
  5328. 0x3c010001, 0xa4220f78, 0x94c20004, 0x94c30006, 0x3c010001, 0xa4200f76,
  5329. 0x3c010001, 0xa4200f72, 0x00021400, 0x00431025, 0x3c010001, 0xac220f6c,
  5330. 0x95020004, 0x3c010001, 0x08004124, 0xa4220f70, 0x3c020001, 0x94420f70,
  5331. 0x3c030001, 0x94630f72, 0x00431021, 0xa5020004, 0x3c020001, 0x94420f6c,
  5332. 0xa4c20004, 0x3c020001, 0x8c420f6c, 0xa4c20006, 0x3c040001, 0x94840f72,
  5333. 0x3c020001, 0x94420f70, 0x3c0a0001, 0x954a0f76, 0x00441821, 0x3063ffff,
  5334. 0x0062182a, 0x24020002, 0x1122000b, 0x00832023, 0x3c030001, 0x94630f78,
  5335. 0x30620009, 0x10400006, 0x3062fff6, 0xa4c2000c, 0x3c020001, 0x94420f78,
  5336. 0x30420009, 0x01425023, 0x24020001, 0x1122001b, 0x29220002, 0x50400005,
  5337. 0x24020002, 0x11200007, 0x31a2ffff, 0x08004197, 0x00000000, 0x1122001d,
  5338. 0x24020016, 0x08004197, 0x31a2ffff, 0x3c0e0001, 0x95ce0f80, 0x10800005,
  5339. 0x01806821, 0x01c42021, 0x00041c02, 0x3082ffff, 0x00627021, 0x000e1027,
  5340. 0xa502000a, 0x3c030001, 0x90630f7b, 0x31a2ffff, 0x00e21021, 0x0800418d,
  5341. 0x00432023, 0x3c020001, 0x94420f80, 0x00442021, 0x00041c02, 0x3082ffff,
  5342. 0x00622021, 0x00807021, 0x00041027, 0x08004185, 0xa502000a, 0x3c050001,
  5343. 0x24a50f7a, 0x90a30000, 0x14620002, 0x24e2fff2, 0xa5e20034, 0x90a20000,
  5344. 0x00e21023, 0xa5020002, 0x3c030001, 0x94630f80, 0x3c020001, 0x94420f5a,
  5345. 0x30e5ffff, 0x00641821, 0x00451023, 0x00622023, 0x00041c02, 0x3082ffff,
  5346. 0x00622021, 0x00041027, 0xa502000a, 0x3c030001, 0x90630f7c, 0x24620001,
  5347. 0x14a20005, 0x00807021, 0x01631021, 0x90420000, 0x08004185, 0x00026200,
  5348. 0x24620002, 0x14a20003, 0x306200fe, 0x004b1021, 0x944c0000, 0x3c020001,
  5349. 0x94420f82, 0x3183ffff, 0x3c040001, 0x90840f7b, 0x00431021, 0x00e21021,
  5350. 0x00442023, 0x008a2021, 0x00041c02, 0x3082ffff, 0x00622021, 0x00041402,
  5351. 0x00822021, 0x00806821, 0x00041027, 0xa4c20010, 0x31a2ffff, 0x000e1c00,
  5352. 0x00431025, 0x3c040001, 0x24840f72, 0xade20010, 0x94820000, 0x3c050001,
  5353. 0x94a50f76, 0x3c030001, 0x8c630f6c, 0x24420001, 0x00b92821, 0xa4820000,
  5354. 0x3322ffff, 0x00622021, 0x0083182b, 0x3c010001, 0xa4250f76, 0x10600003,
  5355. 0x24a2ffff, 0x3c010001, 0xa4220f76, 0x3c024000, 0x03021025, 0x3c010001,
  5356. 0xac240f6c, 0xaf621008, 0x03e00008, 0x27bd0010, 0x3c030001, 0x90630f56,
  5357. 0x27bdffe8, 0x24020001, 0xafbf0014, 0x10620026, 0xafb00010, 0x8f620cf4,
  5358. 0x2442ffff, 0x3042007f, 0x00021100, 0x8c434000, 0x3c010001, 0xac230f64,
  5359. 0x8c434008, 0x24444000, 0x8c5c4004, 0x30620040, 0x14400002, 0x24020088,
  5360. 0x24020008, 0x3c010001, 0xa4220f68, 0x30620004, 0x10400005, 0x24020001,
  5361. 0x3c010001, 0xa0220f57, 0x080041d5, 0x00031402, 0x3c010001, 0xa0200f57,
  5362. 0x00031402, 0x3c010001, 0xa4220f54, 0x9483000c, 0x24020001, 0x3c010001,
  5363. 0xa4200f50, 0x3c010001, 0xa0220f56, 0x3c010001, 0xa4230f62, 0x24020001,
  5364. 0x1342001e, 0x00000000, 0x13400005, 0x24020003, 0x13420067, 0x00000000,
  5365. 0x080042cf, 0x00000000, 0x3c020001, 0x94420f62, 0x241a0001, 0x3c010001,
  5366. 0xa4200f5e, 0x3c010001, 0xa4200f52, 0x304407ff, 0x00021bc2, 0x00031823,
  5367. 0x3063003e, 0x34630036, 0x00021242, 0x3042003c, 0x00621821, 0x3c010001,
  5368. 0xa4240f58, 0x00832021, 0x24630030, 0x3c010001, 0xa4240f5a, 0x3c010001,
  5369. 0xa4230f5c, 0x3c060001, 0x24c60f52, 0x94c50000, 0x94c30002, 0x3c040001,
  5370. 0x94840f5a, 0x00651021, 0x0044102a, 0x10400013, 0x3c108000, 0x00a31021,
  5371. 0xa4c20000, 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008,
  5372. 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4,
  5373. 0x00501024, 0x104000b7, 0x00000000, 0x0800420f, 0x00000000, 0x3c030001,
  5374. 0x94630f50, 0x00851023, 0xa4c40000, 0x00621821, 0x3042ffff, 0x3c010001,
  5375. 0xa4230f50, 0xaf620ce8, 0x3c020001, 0x94420f68, 0x34420024, 0xaf620cec,
  5376. 0x94c30002, 0x3c020001, 0x94420f50, 0x14620012, 0x3c028000, 0x3c108000,
  5377. 0x3c02a000, 0xaf620cf4, 0x3c010001, 0xa0200f56, 0x8f641008, 0x00901024,
  5378. 0x14400003, 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024,
  5379. 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003, 0xaf620cf4, 0x3c108000,
  5380. 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064, 0x00000000,
  5381. 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x080042cf, 0x241a0003,
  5382. 0x3c070001, 0x24e70f50, 0x94e20000, 0x03821021, 0xaf620ce0, 0x3c020001,
  5383. 0x8c420f64, 0xaf620ce4, 0x3c050001, 0x94a50f54, 0x94e30000, 0x3c040001,
  5384. 0x94840f58, 0x3c020001, 0x94420f5e, 0x00a32823, 0x00822023, 0x30a6ffff,
  5385. 0x3083ffff, 0x00c3102b, 0x14400043, 0x00000000, 0x3c020001, 0x94420f5c,
  5386. 0x00021400, 0x00621025, 0xaf620ce8, 0x94e20000, 0x3c030001, 0x94630f54,
  5387. 0x00441021, 0xa4e20000, 0x3042ffff, 0x14430021, 0x3c020008, 0x3c020001,
  5388. 0x90420f57, 0x10400006, 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624,
  5389. 0x0800427c, 0x0000d021, 0x3c020001, 0x94420f68, 0x3c030008, 0x34630624,
  5390. 0x00431025, 0xaf620cec, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5391. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5392. 0x00000000, 0x8f620cf4, 0x00501024, 0x10400015, 0x00000000, 0x08004283,
  5393. 0x00000000, 0x3c030001, 0x94630f68, 0x34420624, 0x3c108000, 0x00621825,
  5394. 0x3c028000, 0xaf630cec, 0xaf620cf4, 0x8f641008, 0x00901024, 0x14400003,
  5395. 0x00000000, 0x0c004064, 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7,
  5396. 0x00000000, 0x3c010001, 0x080042cf, 0xa4200f5e, 0x3c020001, 0x94420f5c,
  5397. 0x00021400, 0x00c21025, 0xaf620ce8, 0x3c020001, 0x90420f57, 0x10400009,
  5398. 0x3c03000c, 0x3c020001, 0x94420f68, 0x34630624, 0x0000d021, 0x00431025,
  5399. 0xaf620cec, 0x080042c1, 0x3c108000, 0x3c020001, 0x94420f68, 0x3c030008,
  5400. 0x34630604, 0x00431025, 0xaf620cec, 0x3c020001, 0x94420f5e, 0x00451021,
  5401. 0x3c010001, 0xa4220f5e, 0x3c108000, 0x3c02a000, 0xaf620cf4, 0x3c010001,
  5402. 0xa0200f56, 0x8f641008, 0x00901024, 0x14400003, 0x00000000, 0x0c004064,
  5403. 0x00000000, 0x8f620cf4, 0x00501024, 0x1440fff7, 0x00000000, 0x8fbf0014,
  5404. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x00000000, 0x27bdffe0, 0x3c040001,
  5405. 0x24840ec0, 0x00002821, 0x00003021, 0x00003821, 0xafbf0018, 0xafa00010,
  5406. 0x0c004378, 0xafa00014, 0x0000d021, 0x24020130, 0xaf625000, 0x3c010001,
  5407. 0xa4200f50, 0x3c010001, 0xa0200f57, 0x8fbf0018, 0x03e00008, 0x27bd0020,
  5408. 0x27bdffe8, 0x3c1bc000, 0xafbf0014, 0xafb00010, 0xaf60680c, 0x8f626804,
  5409. 0x34420082, 0xaf626804, 0x8f634000, 0x24020b50, 0x3c010001, 0xac220f20,
  5410. 0x24020b78, 0x3c010001, 0xac220f30, 0x34630002, 0xaf634000, 0x0c004315,
  5411. 0x00808021, 0x3c010001, 0xa0220f34, 0x304200ff, 0x24030002, 0x14430005,
  5412. 0x00000000, 0x3c020001, 0x8c420f20, 0x08004308, 0xac5000c0, 0x3c020001,
  5413. 0x8c420f20, 0xac5000bc, 0x8f624434, 0x8f634438, 0x8f644410, 0x3c010001,
  5414. 0xac220f28, 0x3c010001, 0xac230f38, 0x3c010001, 0xac240f24, 0x8fbf0014,
  5415. 0x8fb00010, 0x03e00008, 0x27bd0018, 0x03e00008, 0x24020001, 0x27bdfff8,
  5416. 0x18800009, 0x00002821, 0x8f63680c, 0x8f62680c, 0x1043fffe, 0x00000000,
  5417. 0x24a50001, 0x00a4102a, 0x1440fff9, 0x00000000, 0x03e00008, 0x27bd0008,
  5418. 0x8f634450, 0x3c020001, 0x8c420f28, 0x00031c02, 0x0043102b, 0x14400008,
  5419. 0x3c038000, 0x3c040001, 0x8c840f38, 0x8f624450, 0x00021c02, 0x0083102b,
  5420. 0x1040fffc, 0x3c038000, 0xaf634444, 0x8f624444, 0x00431024, 0x1440fffd,
  5421. 0x00000000, 0x8f624448, 0x03e00008, 0x3042ffff, 0x3082ffff, 0x2442e000,
  5422. 0x2c422001, 0x14400003, 0x3c024000, 0x08004347, 0x2402ffff, 0x00822025,
  5423. 0xaf645c38, 0x8f625c30, 0x30420002, 0x1440fffc, 0x00001021, 0x03e00008,
  5424. 0x00000000, 0x8f624450, 0x3c030001, 0x8c630f24, 0x08004350, 0x3042ffff,
  5425. 0x8f624450, 0x3042ffff, 0x0043102b, 0x1440fffc, 0x00000000, 0x03e00008,
  5426. 0x00000000, 0x27bdffe0, 0x00802821, 0x3c040001, 0x24840ed0, 0x00003021,
  5427. 0x00003821, 0xafbf0018, 0xafa00010, 0x0c004378, 0xafa00014, 0x0800435f,
  5428. 0x00000000, 0x8fbf0018, 0x03e00008, 0x27bd0020, 0x3c020001, 0x3442d600,
  5429. 0x3c030001, 0x3463d600, 0x3c040001, 0x3484ddff, 0x3c010001, 0xac220f40,
  5430. 0x24020040, 0x3c010001, 0xac220f44, 0x3c010001, 0xac200f3c, 0xac600000,
  5431. 0x24630004, 0x0083102b, 0x5040fffd, 0xac600000, 0x03e00008, 0x00000000,
  5432. 0x00804821, 0x8faa0010, 0x3c020001, 0x8c420f3c, 0x3c040001, 0x8c840f44,
  5433. 0x8fab0014, 0x24430001, 0x0044102b, 0x3c010001, 0xac230f3c, 0x14400003,
  5434. 0x00004021, 0x3c010001, 0xac200f3c, 0x3c020001, 0x8c420f3c, 0x3c030001,
  5435. 0x8c630f40, 0x91240000, 0x00021140, 0x00431021, 0x00481021, 0x25080001,
  5436. 0xa0440000, 0x29020008, 0x1440fff4, 0x25290001, 0x3c020001, 0x8c420f3c,
  5437. 0x3c030001, 0x8c630f40, 0x8f64680c, 0x00021140, 0x00431021, 0xac440008,
  5438. 0xac45000c, 0xac460010, 0xac470014, 0xac4a0018, 0x03e00008, 0xac4b001c,
  5439. 0x00000000, 0x00000000, 0x00000000,
  5440. };
  5441. static const u32 tg3Tso5FwRodata[(TG3_TSO5_FW_RODATA_LEN / 4) + 1] = {
  5442. 0x4d61696e, 0x43707542, 0x00000000, 0x4d61696e, 0x43707541, 0x00000000,
  5443. 0x00000000, 0x00000000, 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000,
  5444. 0x73746b6f, 0x66666c64, 0x00000000, 0x00000000, 0x66617461, 0x6c457272,
  5445. 0x00000000, 0x00000000, 0x00000000,
  5446. };
  5447. static const u32 tg3Tso5FwData[(TG3_TSO5_FW_DATA_LEN / 4) + 1] = {
  5448. 0x00000000, 0x73746b6f, 0x66666c64, 0x5f76312e, 0x322e3000, 0x00000000,
  5449. 0x00000000, 0x00000000, 0x00000000,
  5450. };
  5451. /* tp->lock is held. */
  5452. static int tg3_load_tso_firmware(struct tg3 *tp)
  5453. {
  5454. struct fw_info info;
  5455. unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size;
  5456. int err, i;
  5457. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5458. return 0;
  5459. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5460. info.text_base = TG3_TSO5_FW_TEXT_ADDR;
  5461. info.text_len = TG3_TSO5_FW_TEXT_LEN;
  5462. info.text_data = &tg3Tso5FwText[0];
  5463. info.rodata_base = TG3_TSO5_FW_RODATA_ADDR;
  5464. info.rodata_len = TG3_TSO5_FW_RODATA_LEN;
  5465. info.rodata_data = &tg3Tso5FwRodata[0];
  5466. info.data_base = TG3_TSO5_FW_DATA_ADDR;
  5467. info.data_len = TG3_TSO5_FW_DATA_LEN;
  5468. info.data_data = &tg3Tso5FwData[0];
  5469. cpu_base = RX_CPU_BASE;
  5470. cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705;
  5471. cpu_scratch_size = (info.text_len +
  5472. info.rodata_len +
  5473. info.data_len +
  5474. TG3_TSO5_FW_SBSS_LEN +
  5475. TG3_TSO5_FW_BSS_LEN);
  5476. } else {
  5477. info.text_base = TG3_TSO_FW_TEXT_ADDR;
  5478. info.text_len = TG3_TSO_FW_TEXT_LEN;
  5479. info.text_data = &tg3TsoFwText[0];
  5480. info.rodata_base = TG3_TSO_FW_RODATA_ADDR;
  5481. info.rodata_len = TG3_TSO_FW_RODATA_LEN;
  5482. info.rodata_data = &tg3TsoFwRodata[0];
  5483. info.data_base = TG3_TSO_FW_DATA_ADDR;
  5484. info.data_len = TG3_TSO_FW_DATA_LEN;
  5485. info.data_data = &tg3TsoFwData[0];
  5486. cpu_base = TX_CPU_BASE;
  5487. cpu_scratch_base = TX_CPU_SCRATCH_BASE;
  5488. cpu_scratch_size = TX_CPU_SCRATCH_SIZE;
  5489. }
  5490. err = tg3_load_firmware_cpu(tp, cpu_base,
  5491. cpu_scratch_base, cpu_scratch_size,
  5492. &info);
  5493. if (err)
  5494. return err;
  5495. /* Now startup the cpu. */
  5496. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5497. tw32_f(cpu_base + CPU_PC, info.text_base);
  5498. for (i = 0; i < 5; i++) {
  5499. if (tr32(cpu_base + CPU_PC) == info.text_base)
  5500. break;
  5501. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5502. tw32(cpu_base + CPU_MODE, CPU_MODE_HALT);
  5503. tw32_f(cpu_base + CPU_PC, info.text_base);
  5504. udelay(1000);
  5505. }
  5506. if (i >= 5) {
  5507. printk(KERN_ERR PFX "tg3_load_tso_firmware fails for %s "
  5508. "to set CPU PC, is %08x should be %08x\n",
  5509. tp->dev->name, tr32(cpu_base + CPU_PC),
  5510. info.text_base);
  5511. return -ENODEV;
  5512. }
  5513. tw32(cpu_base + CPU_STATE, 0xffffffff);
  5514. tw32_f(cpu_base + CPU_MODE, 0x00000000);
  5515. return 0;
  5516. }
  5517. /* tp->lock is held. */
  5518. static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
  5519. {
  5520. u32 addr_high, addr_low;
  5521. int i;
  5522. addr_high = ((tp->dev->dev_addr[0] << 8) |
  5523. tp->dev->dev_addr[1]);
  5524. addr_low = ((tp->dev->dev_addr[2] << 24) |
  5525. (tp->dev->dev_addr[3] << 16) |
  5526. (tp->dev->dev_addr[4] << 8) |
  5527. (tp->dev->dev_addr[5] << 0));
  5528. for (i = 0; i < 4; i++) {
  5529. if (i == 1 && skip_mac_1)
  5530. continue;
  5531. tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high);
  5532. tw32(MAC_ADDR_0_LOW + (i * 8), addr_low);
  5533. }
  5534. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  5535. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  5536. for (i = 0; i < 12; i++) {
  5537. tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high);
  5538. tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low);
  5539. }
  5540. }
  5541. addr_high = (tp->dev->dev_addr[0] +
  5542. tp->dev->dev_addr[1] +
  5543. tp->dev->dev_addr[2] +
  5544. tp->dev->dev_addr[3] +
  5545. tp->dev->dev_addr[4] +
  5546. tp->dev->dev_addr[5]) &
  5547. TX_BACKOFF_SEED_MASK;
  5548. tw32(MAC_TX_BACKOFF_SEED, addr_high);
  5549. }
  5550. static int tg3_set_mac_addr(struct net_device *dev, void *p)
  5551. {
  5552. struct tg3 *tp = netdev_priv(dev);
  5553. struct sockaddr *addr = p;
  5554. int err = 0, skip_mac_1 = 0;
  5555. if (!is_valid_ether_addr(addr->sa_data))
  5556. return -EINVAL;
  5557. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5558. if (!netif_running(dev))
  5559. return 0;
  5560. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  5561. u32 addr0_high, addr0_low, addr1_high, addr1_low;
  5562. addr0_high = tr32(MAC_ADDR_0_HIGH);
  5563. addr0_low = tr32(MAC_ADDR_0_LOW);
  5564. addr1_high = tr32(MAC_ADDR_1_HIGH);
  5565. addr1_low = tr32(MAC_ADDR_1_LOW);
  5566. /* Skip MAC addr 1 if ASF is using it. */
  5567. if ((addr0_high != addr1_high || addr0_low != addr1_low) &&
  5568. !(addr1_high == 0 && addr1_low == 0))
  5569. skip_mac_1 = 1;
  5570. }
  5571. spin_lock_bh(&tp->lock);
  5572. __tg3_set_mac_addr(tp, skip_mac_1);
  5573. spin_unlock_bh(&tp->lock);
  5574. return err;
  5575. }
  5576. /* tp->lock is held. */
  5577. static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
  5578. dma_addr_t mapping, u32 maxlen_flags,
  5579. u32 nic_addr)
  5580. {
  5581. tg3_write_mem(tp,
  5582. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH),
  5583. ((u64) mapping >> 32));
  5584. tg3_write_mem(tp,
  5585. (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW),
  5586. ((u64) mapping & 0xffffffff));
  5587. tg3_write_mem(tp,
  5588. (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS),
  5589. maxlen_flags);
  5590. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5591. tg3_write_mem(tp,
  5592. (bdinfo_addr + TG3_BDINFO_NIC_ADDR),
  5593. nic_addr);
  5594. }
  5595. static void __tg3_set_rx_mode(struct net_device *);
  5596. static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
  5597. {
  5598. tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
  5599. tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
  5600. tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames);
  5601. tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames);
  5602. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5603. tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq);
  5604. tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq);
  5605. }
  5606. tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq);
  5607. tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq);
  5608. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5609. u32 val = ec->stats_block_coalesce_usecs;
  5610. if (!netif_carrier_ok(tp->dev))
  5611. val = 0;
  5612. tw32(HOSTCC_STAT_COAL_TICKS, val);
  5613. }
  5614. }
  5615. /* tp->lock is held. */
  5616. static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
  5617. {
  5618. u32 val, rdmac_mode;
  5619. int i, err, limit;
  5620. tg3_disable_ints(tp);
  5621. tg3_stop_fw(tp);
  5622. tg3_write_sig_pre_reset(tp, RESET_KIND_INIT);
  5623. if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) {
  5624. tg3_abort_hw(tp, 1);
  5625. }
  5626. if (reset_phy)
  5627. tg3_phy_reset(tp);
  5628. err = tg3_chip_reset(tp);
  5629. if (err)
  5630. return err;
  5631. tg3_write_sig_legacy(tp, RESET_KIND_INIT);
  5632. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  5633. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1) {
  5634. val = tr32(TG3_CPMU_CTRL);
  5635. val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE);
  5636. tw32(TG3_CPMU_CTRL, val);
  5637. val = tr32(TG3_CPMU_LSPD_10MB_CLK);
  5638. val &= ~CPMU_LSPD_10MB_MACCLK_MASK;
  5639. val |= CPMU_LSPD_10MB_MACCLK_6_25;
  5640. tw32(TG3_CPMU_LSPD_10MB_CLK, val);
  5641. val = tr32(TG3_CPMU_LNK_AWARE_PWRMD);
  5642. val &= ~CPMU_LNK_AWARE_MACCLK_MASK;
  5643. val |= CPMU_LNK_AWARE_MACCLK_6_25;
  5644. tw32(TG3_CPMU_LNK_AWARE_PWRMD, val);
  5645. val = tr32(TG3_CPMU_HST_ACC);
  5646. val &= ~CPMU_HST_ACC_MACCLK_MASK;
  5647. val |= CPMU_HST_ACC_MACCLK_6_25;
  5648. tw32(TG3_CPMU_HST_ACC, val);
  5649. }
  5650. /* This works around an issue with Athlon chipsets on
  5651. * B3 tigon3 silicon. This bit has no effect on any
  5652. * other revision. But do not set this on PCI Express
  5653. * chips and don't even touch the clocks if the CPMU is present.
  5654. */
  5655. if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) {
  5656. if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  5657. tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT;
  5658. tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl);
  5659. }
  5660. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 &&
  5661. (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  5662. val = tr32(TG3PCI_PCISTATE);
  5663. val |= PCISTATE_RETRY_SAME_DMA;
  5664. tw32(TG3PCI_PCISTATE, val);
  5665. }
  5666. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  5667. /* Allow reads and writes to the
  5668. * APE register and memory space.
  5669. */
  5670. val = tr32(TG3PCI_PCISTATE);
  5671. val |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  5672. PCISTATE_ALLOW_APE_SHMEM_WR;
  5673. tw32(TG3PCI_PCISTATE, val);
  5674. }
  5675. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) {
  5676. /* Enable some hw fixes. */
  5677. val = tr32(TG3PCI_MSI_DATA);
  5678. val |= (1 << 26) | (1 << 28) | (1 << 29);
  5679. tw32(TG3PCI_MSI_DATA, val);
  5680. }
  5681. /* Descriptor ring init may make accesses to the
  5682. * NIC SRAM area to setup the TX descriptors, so we
  5683. * can only do this after the hardware has been
  5684. * successfully reset.
  5685. */
  5686. err = tg3_init_rings(tp);
  5687. if (err)
  5688. return err;
  5689. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 &&
  5690. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) {
  5691. /* This value is determined during the probe time DMA
  5692. * engine test, tg3_test_dma.
  5693. */
  5694. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  5695. }
  5696. tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS |
  5697. GRC_MODE_4X_NIC_SEND_RINGS |
  5698. GRC_MODE_NO_TX_PHDR_CSUM |
  5699. GRC_MODE_NO_RX_PHDR_CSUM);
  5700. tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
  5701. /* Pseudo-header checksum is done by hardware logic and not
  5702. * the offload processers, so make the chip do the pseudo-
  5703. * header checksums on receive. For transmit it is more
  5704. * convenient to do the pseudo-header checksum in software
  5705. * as Linux does that on transmit for us in all cases.
  5706. */
  5707. tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
  5708. tw32(GRC_MODE,
  5709. tp->grc_mode |
  5710. (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP));
  5711. /* Setup the timer prescalar register. Clock is always 66Mhz. */
  5712. val = tr32(GRC_MISC_CFG);
  5713. val &= ~0xff;
  5714. val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT);
  5715. tw32(GRC_MISC_CFG, val);
  5716. /* Initialize MBUF/DESC pool. */
  5717. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5718. /* Do nothing. */
  5719. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
  5720. tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
  5721. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  5722. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
  5723. else
  5724. tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96);
  5725. tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
  5726. tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
  5727. }
  5728. else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  5729. int fw_len;
  5730. fw_len = (TG3_TSO5_FW_TEXT_LEN +
  5731. TG3_TSO5_FW_RODATA_LEN +
  5732. TG3_TSO5_FW_DATA_LEN +
  5733. TG3_TSO5_FW_SBSS_LEN +
  5734. TG3_TSO5_FW_BSS_LEN);
  5735. fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1);
  5736. tw32(BUFMGR_MB_POOL_ADDR,
  5737. NIC_SRAM_MBUF_POOL_BASE5705 + fw_len);
  5738. tw32(BUFMGR_MB_POOL_SIZE,
  5739. NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
  5740. }
  5741. if (tp->dev->mtu <= ETH_DATA_LEN) {
  5742. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5743. tp->bufmgr_config.mbuf_read_dma_low_water);
  5744. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5745. tp->bufmgr_config.mbuf_mac_rx_low_water);
  5746. tw32(BUFMGR_MB_HIGH_WATER,
  5747. tp->bufmgr_config.mbuf_high_water);
  5748. } else {
  5749. tw32(BUFMGR_MB_RDMA_LOW_WATER,
  5750. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo);
  5751. tw32(BUFMGR_MB_MACRX_LOW_WATER,
  5752. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo);
  5753. tw32(BUFMGR_MB_HIGH_WATER,
  5754. tp->bufmgr_config.mbuf_high_water_jumbo);
  5755. }
  5756. tw32(BUFMGR_DMA_LOW_WATER,
  5757. tp->bufmgr_config.dma_low_water);
  5758. tw32(BUFMGR_DMA_HIGH_WATER,
  5759. tp->bufmgr_config.dma_high_water);
  5760. tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
  5761. for (i = 0; i < 2000; i++) {
  5762. if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE)
  5763. break;
  5764. udelay(10);
  5765. }
  5766. if (i >= 2000) {
  5767. printk(KERN_ERR PFX "tg3_reset_hw cannot enable BUFMGR for %s.\n",
  5768. tp->dev->name);
  5769. return -ENODEV;
  5770. }
  5771. /* Setup replenish threshold. */
  5772. val = tp->rx_pending / 8;
  5773. if (val == 0)
  5774. val = 1;
  5775. else if (val > tp->rx_std_max_post)
  5776. val = tp->rx_std_max_post;
  5777. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  5778. if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1)
  5779. tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2);
  5780. if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2))
  5781. val = TG3_RX_INTERNAL_RING_SZ_5906 / 2;
  5782. }
  5783. tw32(RCVBDI_STD_THRESH, val);
  5784. /* Initialize TG3_BDINFO's at:
  5785. * RCVDBDI_STD_BD: standard eth size rx ring
  5786. * RCVDBDI_JUMBO_BD: jumbo frame rx ring
  5787. * RCVDBDI_MINI_BD: small frame rx ring (??? does not work)
  5788. *
  5789. * like so:
  5790. * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring
  5791. * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) |
  5792. * ring attribute flags
  5793. * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM
  5794. *
  5795. * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries.
  5796. * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries.
  5797. *
  5798. * The size of each ring is fixed in the firmware, but the location is
  5799. * configurable.
  5800. */
  5801. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5802. ((u64) tp->rx_std_mapping >> 32));
  5803. tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5804. ((u64) tp->rx_std_mapping & 0xffffffff));
  5805. tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR,
  5806. NIC_SRAM_RX_BUFFER_DESC);
  5807. /* Don't even try to program the JUMBO/MINI buffer descriptor
  5808. * configs on 5705.
  5809. */
  5810. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  5811. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5812. RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT);
  5813. } else {
  5814. tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5815. RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5816. tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5817. BDINFO_FLAGS_DISABLED);
  5818. /* Setup replenish threshold. */
  5819. tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8);
  5820. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
  5821. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5822. ((u64) tp->rx_jumbo_mapping >> 32));
  5823. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW,
  5824. ((u64) tp->rx_jumbo_mapping & 0xffffffff));
  5825. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5826. RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT);
  5827. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR,
  5828. NIC_SRAM_RX_JUMBO_BUFFER_DESC);
  5829. } else {
  5830. tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS,
  5831. BDINFO_FLAGS_DISABLED);
  5832. }
  5833. }
  5834. /* There is only one send ring on 5705/5750, no need to explicitly
  5835. * disable the others.
  5836. */
  5837. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5838. /* Clear out send RCB ring in SRAM. */
  5839. for (i = NIC_SRAM_SEND_RCB; i < NIC_SRAM_RCV_RET_RCB; i += TG3_BDINFO_SIZE)
  5840. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5841. BDINFO_FLAGS_DISABLED);
  5842. }
  5843. tp->tx_prod = 0;
  5844. tp->tx_cons = 0;
  5845. tw32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5846. tw32_tx_mbox(MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5847. tg3_set_bdinfo(tp, NIC_SRAM_SEND_RCB,
  5848. tp->tx_desc_mapping,
  5849. (TG3_TX_RING_SIZE <<
  5850. BDINFO_FLAGS_MAXLEN_SHIFT),
  5851. NIC_SRAM_TX_BUFFER_DESC);
  5852. /* There is only one receive return ring on 5705/5750, no need
  5853. * to explicitly disable the others.
  5854. */
  5855. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5856. for (i = NIC_SRAM_RCV_RET_RCB; i < NIC_SRAM_STATS_BLK;
  5857. i += TG3_BDINFO_SIZE) {
  5858. tg3_write_mem(tp, i + TG3_BDINFO_MAXLEN_FLAGS,
  5859. BDINFO_FLAGS_DISABLED);
  5860. }
  5861. }
  5862. tp->rx_rcb_ptr = 0;
  5863. tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, 0);
  5864. tg3_set_bdinfo(tp, NIC_SRAM_RCV_RET_RCB,
  5865. tp->rx_rcb_mapping,
  5866. (TG3_RX_RCB_RING_SIZE(tp) <<
  5867. BDINFO_FLAGS_MAXLEN_SHIFT),
  5868. 0);
  5869. tp->rx_std_ptr = tp->rx_pending;
  5870. tw32_rx_mbox(MAILBOX_RCV_STD_PROD_IDX + TG3_64BIT_REG_LOW,
  5871. tp->rx_std_ptr);
  5872. tp->rx_jumbo_ptr = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ?
  5873. tp->rx_jumbo_pending : 0;
  5874. tw32_rx_mbox(MAILBOX_RCV_JUMBO_PROD_IDX + TG3_64BIT_REG_LOW,
  5875. tp->rx_jumbo_ptr);
  5876. /* Initialize MAC address and backoff seed. */
  5877. __tg3_set_mac_addr(tp, 0);
  5878. /* MTU + ethernet header + FCS + optional VLAN tag */
  5879. tw32(MAC_RX_MTU_SIZE, tp->dev->mtu + ETH_HLEN + 8);
  5880. /* The slot time is changed by tg3_setup_phy if we
  5881. * run at gigabit with half duplex.
  5882. */
  5883. tw32(MAC_TX_LENGTHS,
  5884. (2 << TX_LENGTHS_IPG_CRS_SHIFT) |
  5885. (6 << TX_LENGTHS_IPG_SHIFT) |
  5886. (32 << TX_LENGTHS_SLOT_TIME_SHIFT));
  5887. /* Receive rules. */
  5888. tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS);
  5889. tw32(RCVLPC_CONFIG, 0x0181);
  5890. /* Calculate RDMAC_MODE setting early, we need it to determine
  5891. * the RCVLPC_STATE_ENABLE mask.
  5892. */
  5893. rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB |
  5894. RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB |
  5895. RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB |
  5896. RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB |
  5897. RDMAC_MODE_LNGREAD_ENAB);
  5898. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)
  5899. rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB |
  5900. RDMAC_MODE_MBUF_RBD_CRPT_ENAB |
  5901. RDMAC_MODE_MBUF_SBD_CRPT_ENAB;
  5902. /* If statement applies to 5705 and 5750 PCI devices only */
  5903. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  5904. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  5905. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) {
  5906. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE &&
  5907. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) {
  5908. rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128;
  5909. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  5910. !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) {
  5911. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5912. }
  5913. }
  5914. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
  5915. rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
  5916. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  5917. rdmac_mode |= (1 << 27);
  5918. /* Receive/send statistics. */
  5919. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  5920. val = tr32(RCVLPC_STATS_ENABLE);
  5921. val &= ~RCVLPC_STATSENAB_DACK_FIX;
  5922. tw32(RCVLPC_STATS_ENABLE, val);
  5923. } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) &&
  5924. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  5925. val = tr32(RCVLPC_STATS_ENABLE);
  5926. val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX;
  5927. tw32(RCVLPC_STATS_ENABLE, val);
  5928. } else {
  5929. tw32(RCVLPC_STATS_ENABLE, 0xffffff);
  5930. }
  5931. tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE);
  5932. tw32(SNDDATAI_STATSENAB, 0xffffff);
  5933. tw32(SNDDATAI_STATSCTRL,
  5934. (SNDDATAI_SCTRL_ENABLE |
  5935. SNDDATAI_SCTRL_FASTUPD));
  5936. /* Setup host coalescing engine. */
  5937. tw32(HOSTCC_MODE, 0);
  5938. for (i = 0; i < 2000; i++) {
  5939. if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE))
  5940. break;
  5941. udelay(10);
  5942. }
  5943. __tg3_set_coalesce(tp, &tp->coal);
  5944. /* set status block DMA address */
  5945. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5946. ((u64) tp->status_mapping >> 32));
  5947. tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5948. ((u64) tp->status_mapping & 0xffffffff));
  5949. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  5950. /* Status/statistics block address. See tg3_timer,
  5951. * the tg3_periodic_fetch_stats call there, and
  5952. * tg3_get_stats to see how this works for 5705/5750 chips.
  5953. */
  5954. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
  5955. ((u64) tp->stats_mapping >> 32));
  5956. tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW,
  5957. ((u64) tp->stats_mapping & 0xffffffff));
  5958. tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK);
  5959. tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK);
  5960. }
  5961. tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode);
  5962. tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE);
  5963. tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE);
  5964. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  5965. tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE);
  5966. /* Clear statistics/status block in chip, and status block in ram. */
  5967. for (i = NIC_SRAM_STATS_BLK;
  5968. i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE;
  5969. i += sizeof(u32)) {
  5970. tg3_write_mem(tp, i, 0);
  5971. udelay(40);
  5972. }
  5973. memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
  5974. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  5975. tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT;
  5976. /* reset to prevent losing 1st rx packet intermittently */
  5977. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  5978. udelay(10);
  5979. }
  5980. tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
  5981. MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
  5982. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  5983. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  5984. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
  5985. tp->mac_mode |= MAC_MODE_LINK_POLARITY;
  5986. tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
  5987. udelay(40);
  5988. /* tp->grc_local_ctrl is partially set up during tg3_get_invariants().
  5989. * If TG3_FLG2_IS_NIC is zero, we should read the
  5990. * register to preserve the GPIO settings for LOMs. The GPIOs,
  5991. * whether used as inputs or outputs, are set by boot code after
  5992. * reset.
  5993. */
  5994. if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) {
  5995. u32 gpio_mask;
  5996. gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 |
  5997. GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 |
  5998. GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2;
  5999. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  6000. gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
  6001. GRC_LCLCTRL_GPIO_OUTPUT3;
  6002. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  6003. gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
  6004. tp->grc_local_ctrl &= ~gpio_mask;
  6005. tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
  6006. /* GPIO1 must be driven high for eeprom write protect */
  6007. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)
  6008. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  6009. GRC_LCLCTRL_GPIO_OUTPUT1);
  6010. }
  6011. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  6012. udelay(100);
  6013. tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0);
  6014. tp->last_tag = 0;
  6015. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  6016. tw32_f(DMAC_MODE, DMAC_MODE_ENABLE);
  6017. udelay(40);
  6018. }
  6019. val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB |
  6020. WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB |
  6021. WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB |
  6022. WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB |
  6023. WDMAC_MODE_LNGREAD_ENAB);
  6024. /* If statement applies to 5705 and 5750 PCI devices only */
  6025. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  6026. tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) ||
  6027. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) {
  6028. if ((tp->tg3_flags & TG3_FLG2_TSO_CAPABLE) &&
  6029. (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 ||
  6030. tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) {
  6031. /* nothing */
  6032. } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) &&
  6033. !(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  6034. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  6035. val |= WDMAC_MODE_RX_ACCEL;
  6036. }
  6037. }
  6038. /* Enable host coalescing bug fix */
  6039. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
  6040. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) ||
  6041. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784) ||
  6042. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761))
  6043. val |= WDMAC_MODE_STATUS_TAG_FIX;
  6044. tw32_f(WDMAC_MODE, val);
  6045. udelay(40);
  6046. if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  6047. u16 pcix_cmd;
  6048. pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  6049. &pcix_cmd);
  6050. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) {
  6051. pcix_cmd &= ~PCI_X_CMD_MAX_READ;
  6052. pcix_cmd |= PCI_X_CMD_READ_2K;
  6053. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  6054. pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ);
  6055. pcix_cmd |= PCI_X_CMD_READ_2K;
  6056. }
  6057. pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD,
  6058. pcix_cmd);
  6059. }
  6060. tw32_f(RDMAC_MODE, rdmac_mode);
  6061. udelay(40);
  6062. tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE);
  6063. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  6064. tw32(MBFREE_MODE, MBFREE_MODE_ENABLE);
  6065. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  6066. tw32(SNDDATAC_MODE,
  6067. SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY);
  6068. else
  6069. tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE);
  6070. tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE);
  6071. tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
  6072. tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
  6073. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
  6074. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
  6075. tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
  6076. tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
  6077. tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
  6078. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) {
  6079. err = tg3_load_5701_a0_firmware_fix(tp);
  6080. if (err)
  6081. return err;
  6082. }
  6083. if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
  6084. err = tg3_load_tso_firmware(tp);
  6085. if (err)
  6086. return err;
  6087. }
  6088. tp->tx_mode = TX_MODE_ENABLE;
  6089. tw32_f(MAC_TX_MODE, tp->tx_mode);
  6090. udelay(100);
  6091. tp->rx_mode = RX_MODE_ENABLE;
  6092. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  6093. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  6094. tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
  6095. tw32_f(MAC_RX_MODE, tp->rx_mode);
  6096. udelay(10);
  6097. if (tp->link_config.phy_is_low_power) {
  6098. tp->link_config.phy_is_low_power = 0;
  6099. tp->link_config.speed = tp->link_config.orig_speed;
  6100. tp->link_config.duplex = tp->link_config.orig_duplex;
  6101. tp->link_config.autoneg = tp->link_config.orig_autoneg;
  6102. }
  6103. tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL;
  6104. tw32_f(MAC_MI_MODE, tp->mi_mode);
  6105. udelay(80);
  6106. tw32(MAC_LED_CTRL, tp->led_ctrl);
  6107. tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
  6108. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  6109. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  6110. udelay(10);
  6111. }
  6112. tw32_f(MAC_RX_MODE, tp->rx_mode);
  6113. udelay(10);
  6114. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  6115. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) &&
  6116. !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) {
  6117. /* Set drive transmission level to 1.2V */
  6118. /* only if the signal pre-emphasis bit is not set */
  6119. val = tr32(MAC_SERDES_CFG);
  6120. val &= 0xfffff000;
  6121. val |= 0x880;
  6122. tw32(MAC_SERDES_CFG, val);
  6123. }
  6124. if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1)
  6125. tw32(MAC_SERDES_CFG, 0x616000);
  6126. }
  6127. /* Prevent chip from dropping frames when flow control
  6128. * is enabled.
  6129. */
  6130. tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, 2);
  6131. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
  6132. (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  6133. /* Use hardware link auto-negotiation */
  6134. tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG;
  6135. }
  6136. if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) &&
  6137. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) {
  6138. u32 tmp;
  6139. tmp = tr32(SERDES_RX_CTRL);
  6140. tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT);
  6141. tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT;
  6142. tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT;
  6143. tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  6144. }
  6145. err = tg3_setup_phy(tp, 0);
  6146. if (err)
  6147. return err;
  6148. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6149. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) {
  6150. u32 tmp;
  6151. /* Clear CRC stats. */
  6152. if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) {
  6153. tg3_writephy(tp, MII_TG3_TEST1,
  6154. tmp | MII_TG3_TEST1_CRC_EN);
  6155. tg3_readphy(tp, 0x14, &tmp);
  6156. }
  6157. }
  6158. __tg3_set_rx_mode(tp->dev);
  6159. /* Initialize receive rules. */
  6160. tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK);
  6161. tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK);
  6162. tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK);
  6163. tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
  6164. if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
  6165. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  6166. limit = 8;
  6167. else
  6168. limit = 16;
  6169. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF)
  6170. limit -= 4;
  6171. switch (limit) {
  6172. case 16:
  6173. tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0);
  6174. case 15:
  6175. tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0);
  6176. case 14:
  6177. tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0);
  6178. case 13:
  6179. tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0);
  6180. case 12:
  6181. tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0);
  6182. case 11:
  6183. tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0);
  6184. case 10:
  6185. tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0);
  6186. case 9:
  6187. tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0);
  6188. case 8:
  6189. tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0);
  6190. case 7:
  6191. tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0);
  6192. case 6:
  6193. tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0);
  6194. case 5:
  6195. tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0);
  6196. case 4:
  6197. /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */
  6198. case 3:
  6199. /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */
  6200. case 2:
  6201. case 1:
  6202. default:
  6203. break;
  6204. };
  6205. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)
  6206. /* Write our heartbeat update interval to APE. */
  6207. tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS,
  6208. APE_HOST_HEARTBEAT_INT_DISABLE);
  6209. tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
  6210. return 0;
  6211. }
  6212. /* Called at device open time to get the chip ready for
  6213. * packet processing. Invoked with tp->lock held.
  6214. */
  6215. static int tg3_init_hw(struct tg3 *tp, int reset_phy)
  6216. {
  6217. int err;
  6218. /* Force the chip into D0. */
  6219. err = tg3_set_power_state(tp, PCI_D0);
  6220. if (err)
  6221. goto out;
  6222. tg3_switch_clocks(tp);
  6223. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  6224. err = tg3_reset_hw(tp, reset_phy);
  6225. out:
  6226. return err;
  6227. }
  6228. #define TG3_STAT_ADD32(PSTAT, REG) \
  6229. do { u32 __val = tr32(REG); \
  6230. (PSTAT)->low += __val; \
  6231. if ((PSTAT)->low < __val) \
  6232. (PSTAT)->high += 1; \
  6233. } while (0)
  6234. static void tg3_periodic_fetch_stats(struct tg3 *tp)
  6235. {
  6236. struct tg3_hw_stats *sp = tp->hw_stats;
  6237. if (!netif_carrier_ok(tp->dev))
  6238. return;
  6239. TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS);
  6240. TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS);
  6241. TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT);
  6242. TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT);
  6243. TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS);
  6244. TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS);
  6245. TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS);
  6246. TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED);
  6247. TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL);
  6248. TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL);
  6249. TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST);
  6250. TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST);
  6251. TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST);
  6252. TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS);
  6253. TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS);
  6254. TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST);
  6255. TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST);
  6256. TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST);
  6257. TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS);
  6258. TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS);
  6259. TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD);
  6260. TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD);
  6261. TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD);
  6262. TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED);
  6263. TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG);
  6264. TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS);
  6265. TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE);
  6266. TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT);
  6267. TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT);
  6268. TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT);
  6269. }
  6270. static void tg3_timer(unsigned long __opaque)
  6271. {
  6272. struct tg3 *tp = (struct tg3 *) __opaque;
  6273. if (tp->irq_sync)
  6274. goto restart_timer;
  6275. spin_lock(&tp->lock);
  6276. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6277. /* All of this garbage is because when using non-tagged
  6278. * IRQ status the mailbox/status_block protocol the chip
  6279. * uses with the cpu is race prone.
  6280. */
  6281. if (tp->hw_status->status & SD_STATUS_UPDATED) {
  6282. tw32(GRC_LOCAL_CTRL,
  6283. tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
  6284. } else {
  6285. tw32(HOSTCC_MODE, tp->coalesce_mode |
  6286. (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
  6287. }
  6288. if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  6289. tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER;
  6290. spin_unlock(&tp->lock);
  6291. schedule_work(&tp->reset_task);
  6292. return;
  6293. }
  6294. }
  6295. /* This part only runs once per second. */
  6296. if (!--tp->timer_counter) {
  6297. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
  6298. tg3_periodic_fetch_stats(tp);
  6299. if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
  6300. u32 mac_stat;
  6301. int phy_event;
  6302. mac_stat = tr32(MAC_STATUS);
  6303. phy_event = 0;
  6304. if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) {
  6305. if (mac_stat & MAC_STATUS_MI_INTERRUPT)
  6306. phy_event = 1;
  6307. } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)
  6308. phy_event = 1;
  6309. if (phy_event)
  6310. tg3_setup_phy(tp, 0);
  6311. } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) {
  6312. u32 mac_stat = tr32(MAC_STATUS);
  6313. int need_setup = 0;
  6314. if (netif_carrier_ok(tp->dev) &&
  6315. (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) {
  6316. need_setup = 1;
  6317. }
  6318. if (! netif_carrier_ok(tp->dev) &&
  6319. (mac_stat & (MAC_STATUS_PCS_SYNCED |
  6320. MAC_STATUS_SIGNAL_DET))) {
  6321. need_setup = 1;
  6322. }
  6323. if (need_setup) {
  6324. if (!tp->serdes_counter) {
  6325. tw32_f(MAC_MODE,
  6326. (tp->mac_mode &
  6327. ~MAC_MODE_PORT_MODE_MASK));
  6328. udelay(40);
  6329. tw32_f(MAC_MODE, tp->mac_mode);
  6330. udelay(40);
  6331. }
  6332. tg3_setup_phy(tp, 0);
  6333. }
  6334. } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  6335. tg3_serdes_parallel_detect(tp);
  6336. tp->timer_counter = tp->timer_multiplier;
  6337. }
  6338. /* Heartbeat is only sent once every 2 seconds.
  6339. *
  6340. * The heartbeat is to tell the ASF firmware that the host
  6341. * driver is still alive. In the event that the OS crashes,
  6342. * ASF needs to reset the hardware to free up the FIFO space
  6343. * that may be filled with rx packets destined for the host.
  6344. * If the FIFO is full, ASF will no longer function properly.
  6345. *
  6346. * Unintended resets have been reported on real time kernels
  6347. * where the timer doesn't run on time. Netpoll will also have
  6348. * same problem.
  6349. *
  6350. * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware
  6351. * to check the ring condition when the heartbeat is expiring
  6352. * before doing the reset. This will prevent most unintended
  6353. * resets.
  6354. */
  6355. if (!--tp->asf_counter) {
  6356. if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
  6357. u32 val;
  6358. tg3_wait_for_event_ack(tp);
  6359. tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
  6360. FWCMD_NICDRV_ALIVE3);
  6361. tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
  6362. /* 5 seconds timeout */
  6363. tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
  6364. val = tr32(GRC_RX_CPU_EVENT);
  6365. val |= GRC_RX_CPU_DRIVER_EVENT;
  6366. tw32_f(GRC_RX_CPU_EVENT, val);
  6367. }
  6368. tp->asf_counter = tp->asf_multiplier;
  6369. }
  6370. spin_unlock(&tp->lock);
  6371. restart_timer:
  6372. tp->timer.expires = jiffies + tp->timer_offset;
  6373. add_timer(&tp->timer);
  6374. }
  6375. static int tg3_request_irq(struct tg3 *tp)
  6376. {
  6377. irq_handler_t fn;
  6378. unsigned long flags;
  6379. struct net_device *dev = tp->dev;
  6380. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6381. fn = tg3_msi;
  6382. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
  6383. fn = tg3_msi_1shot;
  6384. flags = IRQF_SAMPLE_RANDOM;
  6385. } else {
  6386. fn = tg3_interrupt;
  6387. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6388. fn = tg3_interrupt_tagged;
  6389. flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM;
  6390. }
  6391. return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
  6392. }
  6393. static int tg3_test_interrupt(struct tg3 *tp)
  6394. {
  6395. struct net_device *dev = tp->dev;
  6396. int err, i, intr_ok = 0;
  6397. if (!netif_running(dev))
  6398. return -ENODEV;
  6399. tg3_disable_ints(tp);
  6400. free_irq(tp->pdev->irq, dev);
  6401. err = request_irq(tp->pdev->irq, tg3_test_isr,
  6402. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  6403. if (err)
  6404. return err;
  6405. tp->hw_status->status &= ~SD_STATUS_UPDATED;
  6406. tg3_enable_ints(tp);
  6407. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  6408. HOSTCC_MODE_NOW);
  6409. for (i = 0; i < 5; i++) {
  6410. u32 int_mbox, misc_host_ctrl;
  6411. int_mbox = tr32_mailbox(MAILBOX_INTERRUPT_0 +
  6412. TG3_64BIT_REG_LOW);
  6413. misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
  6414. if ((int_mbox != 0) ||
  6415. (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) {
  6416. intr_ok = 1;
  6417. break;
  6418. }
  6419. msleep(10);
  6420. }
  6421. tg3_disable_ints(tp);
  6422. free_irq(tp->pdev->irq, dev);
  6423. err = tg3_request_irq(tp);
  6424. if (err)
  6425. return err;
  6426. if (intr_ok)
  6427. return 0;
  6428. return -EIO;
  6429. }
  6430. /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is
  6431. * successfully restored
  6432. */
  6433. static int tg3_test_msi(struct tg3 *tp)
  6434. {
  6435. struct net_device *dev = tp->dev;
  6436. int err;
  6437. u16 pci_cmd;
  6438. if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI))
  6439. return 0;
  6440. /* Turn off SERR reporting in case MSI terminates with Master
  6441. * Abort.
  6442. */
  6443. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  6444. pci_write_config_word(tp->pdev, PCI_COMMAND,
  6445. pci_cmd & ~PCI_COMMAND_SERR);
  6446. err = tg3_test_interrupt(tp);
  6447. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  6448. if (!err)
  6449. return 0;
  6450. /* other failures */
  6451. if (err != -EIO)
  6452. return err;
  6453. /* MSI test failed, go back to INTx mode */
  6454. printk(KERN_WARNING PFX "%s: No interrupt was generated using MSI, "
  6455. "switching to INTx mode. Please report this failure to "
  6456. "the PCI maintainer and include system chipset information.\n",
  6457. tp->dev->name);
  6458. free_irq(tp->pdev->irq, dev);
  6459. pci_disable_msi(tp->pdev);
  6460. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6461. err = tg3_request_irq(tp);
  6462. if (err)
  6463. return err;
  6464. /* Need to reset the chip because the MSI cycle may have terminated
  6465. * with Master Abort.
  6466. */
  6467. tg3_full_lock(tp, 1);
  6468. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6469. err = tg3_init_hw(tp, 1);
  6470. tg3_full_unlock(tp);
  6471. if (err)
  6472. free_irq(tp->pdev->irq, dev);
  6473. return err;
  6474. }
  6475. static int tg3_open(struct net_device *dev)
  6476. {
  6477. struct tg3 *tp = netdev_priv(dev);
  6478. int err;
  6479. netif_carrier_off(tp->dev);
  6480. tg3_full_lock(tp, 0);
  6481. err = tg3_set_power_state(tp, PCI_D0);
  6482. if (err) {
  6483. tg3_full_unlock(tp);
  6484. return err;
  6485. }
  6486. tg3_disable_ints(tp);
  6487. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6488. tg3_full_unlock(tp);
  6489. /* The placement of this call is tied
  6490. * to the setup and use of Host TX descriptors.
  6491. */
  6492. err = tg3_alloc_consistent(tp);
  6493. if (err)
  6494. return err;
  6495. if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) {
  6496. /* All MSI supporting chips should support tagged
  6497. * status. Assert that this is the case.
  6498. */
  6499. if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
  6500. printk(KERN_WARNING PFX "%s: MSI without TAGGED? "
  6501. "Not using MSI.\n", tp->dev->name);
  6502. } else if (pci_enable_msi(tp->pdev) == 0) {
  6503. u32 msi_mode;
  6504. msi_mode = tr32(MSGINT_MODE);
  6505. tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE);
  6506. tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
  6507. }
  6508. }
  6509. err = tg3_request_irq(tp);
  6510. if (err) {
  6511. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6512. pci_disable_msi(tp->pdev);
  6513. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6514. }
  6515. tg3_free_consistent(tp);
  6516. return err;
  6517. }
  6518. napi_enable(&tp->napi);
  6519. tg3_full_lock(tp, 0);
  6520. err = tg3_init_hw(tp, 1);
  6521. if (err) {
  6522. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6523. tg3_free_rings(tp);
  6524. } else {
  6525. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
  6526. tp->timer_offset = HZ;
  6527. else
  6528. tp->timer_offset = HZ / 10;
  6529. BUG_ON(tp->timer_offset > HZ);
  6530. tp->timer_counter = tp->timer_multiplier =
  6531. (HZ / tp->timer_offset);
  6532. tp->asf_counter = tp->asf_multiplier =
  6533. ((HZ / tp->timer_offset) * 2);
  6534. init_timer(&tp->timer);
  6535. tp->timer.expires = jiffies + tp->timer_offset;
  6536. tp->timer.data = (unsigned long) tp;
  6537. tp->timer.function = tg3_timer;
  6538. }
  6539. tg3_full_unlock(tp);
  6540. if (err) {
  6541. napi_disable(&tp->napi);
  6542. free_irq(tp->pdev->irq, dev);
  6543. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6544. pci_disable_msi(tp->pdev);
  6545. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6546. }
  6547. tg3_free_consistent(tp);
  6548. return err;
  6549. }
  6550. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6551. err = tg3_test_msi(tp);
  6552. if (err) {
  6553. tg3_full_lock(tp, 0);
  6554. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6555. pci_disable_msi(tp->pdev);
  6556. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6557. }
  6558. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6559. tg3_free_rings(tp);
  6560. tg3_free_consistent(tp);
  6561. tg3_full_unlock(tp);
  6562. napi_disable(&tp->napi);
  6563. return err;
  6564. }
  6565. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6566. if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) {
  6567. u32 val = tr32(PCIE_TRANSACTION_CFG);
  6568. tw32(PCIE_TRANSACTION_CFG,
  6569. val | PCIE_TRANS_CFG_1SHOT_MSI);
  6570. }
  6571. }
  6572. }
  6573. tg3_full_lock(tp, 0);
  6574. add_timer(&tp->timer);
  6575. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  6576. tg3_enable_ints(tp);
  6577. tg3_full_unlock(tp);
  6578. netif_start_queue(dev);
  6579. return 0;
  6580. }
  6581. #if 0
  6582. /*static*/ void tg3_dump_state(struct tg3 *tp)
  6583. {
  6584. u32 val32, val32_2, val32_3, val32_4, val32_5;
  6585. u16 val16;
  6586. int i;
  6587. pci_read_config_word(tp->pdev, PCI_STATUS, &val16);
  6588. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32);
  6589. printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n",
  6590. val16, val32);
  6591. /* MAC block */
  6592. printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n",
  6593. tr32(MAC_MODE), tr32(MAC_STATUS));
  6594. printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n",
  6595. tr32(MAC_EVENT), tr32(MAC_LED_CTRL));
  6596. printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n",
  6597. tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS));
  6598. printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n",
  6599. tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS));
  6600. /* Send data initiator control block */
  6601. printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n",
  6602. tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS));
  6603. printk(" SNDDATAI_STATSCTRL[%08x]\n",
  6604. tr32(SNDDATAI_STATSCTRL));
  6605. /* Send data completion control block */
  6606. printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE));
  6607. /* Send BD ring selector block */
  6608. printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n",
  6609. tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS));
  6610. /* Send BD initiator control block */
  6611. printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n",
  6612. tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS));
  6613. /* Send BD completion control block */
  6614. printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE));
  6615. /* Receive list placement control block */
  6616. printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n",
  6617. tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS));
  6618. printk(" RCVLPC_STATSCTRL[%08x]\n",
  6619. tr32(RCVLPC_STATSCTRL));
  6620. /* Receive data and receive BD initiator control block */
  6621. printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n",
  6622. tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS));
  6623. /* Receive data completion control block */
  6624. printk("DEBUG: RCVDCC_MODE[%08x]\n",
  6625. tr32(RCVDCC_MODE));
  6626. /* Receive BD initiator control block */
  6627. printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n",
  6628. tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS));
  6629. /* Receive BD completion control block */
  6630. printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n",
  6631. tr32(RCVCC_MODE), tr32(RCVCC_STATUS));
  6632. /* Receive list selector control block */
  6633. printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n",
  6634. tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS));
  6635. /* Mbuf cluster free block */
  6636. printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n",
  6637. tr32(MBFREE_MODE), tr32(MBFREE_STATUS));
  6638. /* Host coalescing control block */
  6639. printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n",
  6640. tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS));
  6641. printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n",
  6642. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6643. tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6644. printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n",
  6645. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH),
  6646. tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW));
  6647. printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n",
  6648. tr32(HOSTCC_STATS_BLK_NIC_ADDR));
  6649. printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n",
  6650. tr32(HOSTCC_STATUS_BLK_NIC_ADDR));
  6651. /* Memory arbiter control block */
  6652. printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n",
  6653. tr32(MEMARB_MODE), tr32(MEMARB_STATUS));
  6654. /* Buffer manager control block */
  6655. printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n",
  6656. tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS));
  6657. printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n",
  6658. tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE));
  6659. printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] "
  6660. "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n",
  6661. tr32(BUFMGR_DMA_DESC_POOL_ADDR),
  6662. tr32(BUFMGR_DMA_DESC_POOL_SIZE));
  6663. /* Read DMA control block */
  6664. printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n",
  6665. tr32(RDMAC_MODE), tr32(RDMAC_STATUS));
  6666. /* Write DMA control block */
  6667. printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n",
  6668. tr32(WDMAC_MODE), tr32(WDMAC_STATUS));
  6669. /* DMA completion block */
  6670. printk("DEBUG: DMAC_MODE[%08x]\n",
  6671. tr32(DMAC_MODE));
  6672. /* GRC block */
  6673. printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n",
  6674. tr32(GRC_MODE), tr32(GRC_MISC_CFG));
  6675. printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n",
  6676. tr32(GRC_LOCAL_CTRL));
  6677. /* TG3_BDINFOs */
  6678. printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n",
  6679. tr32(RCVDBDI_JUMBO_BD + 0x0),
  6680. tr32(RCVDBDI_JUMBO_BD + 0x4),
  6681. tr32(RCVDBDI_JUMBO_BD + 0x8),
  6682. tr32(RCVDBDI_JUMBO_BD + 0xc));
  6683. printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n",
  6684. tr32(RCVDBDI_STD_BD + 0x0),
  6685. tr32(RCVDBDI_STD_BD + 0x4),
  6686. tr32(RCVDBDI_STD_BD + 0x8),
  6687. tr32(RCVDBDI_STD_BD + 0xc));
  6688. printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n",
  6689. tr32(RCVDBDI_MINI_BD + 0x0),
  6690. tr32(RCVDBDI_MINI_BD + 0x4),
  6691. tr32(RCVDBDI_MINI_BD + 0x8),
  6692. tr32(RCVDBDI_MINI_BD + 0xc));
  6693. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32);
  6694. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2);
  6695. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3);
  6696. tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4);
  6697. printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n",
  6698. val32, val32_2, val32_3, val32_4);
  6699. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32);
  6700. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2);
  6701. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3);
  6702. tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4);
  6703. printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n",
  6704. val32, val32_2, val32_3, val32_4);
  6705. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32);
  6706. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2);
  6707. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3);
  6708. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4);
  6709. tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5);
  6710. printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n",
  6711. val32, val32_2, val32_3, val32_4, val32_5);
  6712. /* SW status block */
  6713. printk("DEBUG: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n",
  6714. tp->hw_status->status,
  6715. tp->hw_status->status_tag,
  6716. tp->hw_status->rx_jumbo_consumer,
  6717. tp->hw_status->rx_consumer,
  6718. tp->hw_status->rx_mini_consumer,
  6719. tp->hw_status->idx[0].rx_producer,
  6720. tp->hw_status->idx[0].tx_consumer);
  6721. /* SW statistics block */
  6722. printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n",
  6723. ((u32 *)tp->hw_stats)[0],
  6724. ((u32 *)tp->hw_stats)[1],
  6725. ((u32 *)tp->hw_stats)[2],
  6726. ((u32 *)tp->hw_stats)[3]);
  6727. /* Mailboxes */
  6728. printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n",
  6729. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0),
  6730. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4),
  6731. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0),
  6732. tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4));
  6733. /* NIC side send descriptors. */
  6734. for (i = 0; i < 6; i++) {
  6735. unsigned long txd;
  6736. txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC
  6737. + (i * sizeof(struct tg3_tx_buffer_desc));
  6738. printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n",
  6739. i,
  6740. readl(txd + 0x0), readl(txd + 0x4),
  6741. readl(txd + 0x8), readl(txd + 0xc));
  6742. }
  6743. /* NIC side RX descriptors. */
  6744. for (i = 0; i < 6; i++) {
  6745. unsigned long rxd;
  6746. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC
  6747. + (i * sizeof(struct tg3_rx_buffer_desc));
  6748. printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n",
  6749. i,
  6750. readl(rxd + 0x0), readl(rxd + 0x4),
  6751. readl(rxd + 0x8), readl(rxd + 0xc));
  6752. rxd += (4 * sizeof(u32));
  6753. printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n",
  6754. i,
  6755. readl(rxd + 0x0), readl(rxd + 0x4),
  6756. readl(rxd + 0x8), readl(rxd + 0xc));
  6757. }
  6758. for (i = 0; i < 6; i++) {
  6759. unsigned long rxd;
  6760. rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC
  6761. + (i * sizeof(struct tg3_rx_buffer_desc));
  6762. printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n",
  6763. i,
  6764. readl(rxd + 0x0), readl(rxd + 0x4),
  6765. readl(rxd + 0x8), readl(rxd + 0xc));
  6766. rxd += (4 * sizeof(u32));
  6767. printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n",
  6768. i,
  6769. readl(rxd + 0x0), readl(rxd + 0x4),
  6770. readl(rxd + 0x8), readl(rxd + 0xc));
  6771. }
  6772. }
  6773. #endif
  6774. static struct net_device_stats *tg3_get_stats(struct net_device *);
  6775. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *);
  6776. static int tg3_close(struct net_device *dev)
  6777. {
  6778. struct tg3 *tp = netdev_priv(dev);
  6779. napi_disable(&tp->napi);
  6780. cancel_work_sync(&tp->reset_task);
  6781. netif_stop_queue(dev);
  6782. del_timer_sync(&tp->timer);
  6783. tg3_full_lock(tp, 1);
  6784. #if 0
  6785. tg3_dump_state(tp);
  6786. #endif
  6787. tg3_disable_ints(tp);
  6788. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  6789. tg3_free_rings(tp);
  6790. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  6791. tg3_full_unlock(tp);
  6792. free_irq(tp->pdev->irq, dev);
  6793. if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
  6794. pci_disable_msi(tp->pdev);
  6795. tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
  6796. }
  6797. memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev),
  6798. sizeof(tp->net_stats_prev));
  6799. memcpy(&tp->estats_prev, tg3_get_estats(tp),
  6800. sizeof(tp->estats_prev));
  6801. tg3_free_consistent(tp);
  6802. tg3_set_power_state(tp, PCI_D3hot);
  6803. netif_carrier_off(tp->dev);
  6804. return 0;
  6805. }
  6806. static inline unsigned long get_stat64(tg3_stat64_t *val)
  6807. {
  6808. unsigned long ret;
  6809. #if (BITS_PER_LONG == 32)
  6810. ret = val->low;
  6811. #else
  6812. ret = ((u64)val->high << 32) | ((u64)val->low);
  6813. #endif
  6814. return ret;
  6815. }
  6816. static unsigned long calc_crc_errors(struct tg3 *tp)
  6817. {
  6818. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6819. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
  6820. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  6821. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  6822. u32 val;
  6823. spin_lock_bh(&tp->lock);
  6824. if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) {
  6825. tg3_writephy(tp, MII_TG3_TEST1,
  6826. val | MII_TG3_TEST1_CRC_EN);
  6827. tg3_readphy(tp, 0x14, &val);
  6828. } else
  6829. val = 0;
  6830. spin_unlock_bh(&tp->lock);
  6831. tp->phy_crc_errors += val;
  6832. return tp->phy_crc_errors;
  6833. }
  6834. return get_stat64(&hw_stats->rx_fcs_errors);
  6835. }
  6836. #define ESTAT_ADD(member) \
  6837. estats->member = old_estats->member + \
  6838. get_stat64(&hw_stats->member)
  6839. static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp)
  6840. {
  6841. struct tg3_ethtool_stats *estats = &tp->estats;
  6842. struct tg3_ethtool_stats *old_estats = &tp->estats_prev;
  6843. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6844. if (!hw_stats)
  6845. return old_estats;
  6846. ESTAT_ADD(rx_octets);
  6847. ESTAT_ADD(rx_fragments);
  6848. ESTAT_ADD(rx_ucast_packets);
  6849. ESTAT_ADD(rx_mcast_packets);
  6850. ESTAT_ADD(rx_bcast_packets);
  6851. ESTAT_ADD(rx_fcs_errors);
  6852. ESTAT_ADD(rx_align_errors);
  6853. ESTAT_ADD(rx_xon_pause_rcvd);
  6854. ESTAT_ADD(rx_xoff_pause_rcvd);
  6855. ESTAT_ADD(rx_mac_ctrl_rcvd);
  6856. ESTAT_ADD(rx_xoff_entered);
  6857. ESTAT_ADD(rx_frame_too_long_errors);
  6858. ESTAT_ADD(rx_jabbers);
  6859. ESTAT_ADD(rx_undersize_packets);
  6860. ESTAT_ADD(rx_in_length_errors);
  6861. ESTAT_ADD(rx_out_length_errors);
  6862. ESTAT_ADD(rx_64_or_less_octet_packets);
  6863. ESTAT_ADD(rx_65_to_127_octet_packets);
  6864. ESTAT_ADD(rx_128_to_255_octet_packets);
  6865. ESTAT_ADD(rx_256_to_511_octet_packets);
  6866. ESTAT_ADD(rx_512_to_1023_octet_packets);
  6867. ESTAT_ADD(rx_1024_to_1522_octet_packets);
  6868. ESTAT_ADD(rx_1523_to_2047_octet_packets);
  6869. ESTAT_ADD(rx_2048_to_4095_octet_packets);
  6870. ESTAT_ADD(rx_4096_to_8191_octet_packets);
  6871. ESTAT_ADD(rx_8192_to_9022_octet_packets);
  6872. ESTAT_ADD(tx_octets);
  6873. ESTAT_ADD(tx_collisions);
  6874. ESTAT_ADD(tx_xon_sent);
  6875. ESTAT_ADD(tx_xoff_sent);
  6876. ESTAT_ADD(tx_flow_control);
  6877. ESTAT_ADD(tx_mac_errors);
  6878. ESTAT_ADD(tx_single_collisions);
  6879. ESTAT_ADD(tx_mult_collisions);
  6880. ESTAT_ADD(tx_deferred);
  6881. ESTAT_ADD(tx_excessive_collisions);
  6882. ESTAT_ADD(tx_late_collisions);
  6883. ESTAT_ADD(tx_collide_2times);
  6884. ESTAT_ADD(tx_collide_3times);
  6885. ESTAT_ADD(tx_collide_4times);
  6886. ESTAT_ADD(tx_collide_5times);
  6887. ESTAT_ADD(tx_collide_6times);
  6888. ESTAT_ADD(tx_collide_7times);
  6889. ESTAT_ADD(tx_collide_8times);
  6890. ESTAT_ADD(tx_collide_9times);
  6891. ESTAT_ADD(tx_collide_10times);
  6892. ESTAT_ADD(tx_collide_11times);
  6893. ESTAT_ADD(tx_collide_12times);
  6894. ESTAT_ADD(tx_collide_13times);
  6895. ESTAT_ADD(tx_collide_14times);
  6896. ESTAT_ADD(tx_collide_15times);
  6897. ESTAT_ADD(tx_ucast_packets);
  6898. ESTAT_ADD(tx_mcast_packets);
  6899. ESTAT_ADD(tx_bcast_packets);
  6900. ESTAT_ADD(tx_carrier_sense_errors);
  6901. ESTAT_ADD(tx_discards);
  6902. ESTAT_ADD(tx_errors);
  6903. ESTAT_ADD(dma_writeq_full);
  6904. ESTAT_ADD(dma_write_prioq_full);
  6905. ESTAT_ADD(rxbds_empty);
  6906. ESTAT_ADD(rx_discards);
  6907. ESTAT_ADD(rx_errors);
  6908. ESTAT_ADD(rx_threshold_hit);
  6909. ESTAT_ADD(dma_readq_full);
  6910. ESTAT_ADD(dma_read_prioq_full);
  6911. ESTAT_ADD(tx_comp_queue_full);
  6912. ESTAT_ADD(ring_set_send_prod_index);
  6913. ESTAT_ADD(ring_status_update);
  6914. ESTAT_ADD(nic_irqs);
  6915. ESTAT_ADD(nic_avoided_irqs);
  6916. ESTAT_ADD(nic_tx_threshold_hit);
  6917. return estats;
  6918. }
  6919. static struct net_device_stats *tg3_get_stats(struct net_device *dev)
  6920. {
  6921. struct tg3 *tp = netdev_priv(dev);
  6922. struct net_device_stats *stats = &tp->net_stats;
  6923. struct net_device_stats *old_stats = &tp->net_stats_prev;
  6924. struct tg3_hw_stats *hw_stats = tp->hw_stats;
  6925. if (!hw_stats)
  6926. return old_stats;
  6927. stats->rx_packets = old_stats->rx_packets +
  6928. get_stat64(&hw_stats->rx_ucast_packets) +
  6929. get_stat64(&hw_stats->rx_mcast_packets) +
  6930. get_stat64(&hw_stats->rx_bcast_packets);
  6931. stats->tx_packets = old_stats->tx_packets +
  6932. get_stat64(&hw_stats->tx_ucast_packets) +
  6933. get_stat64(&hw_stats->tx_mcast_packets) +
  6934. get_stat64(&hw_stats->tx_bcast_packets);
  6935. stats->rx_bytes = old_stats->rx_bytes +
  6936. get_stat64(&hw_stats->rx_octets);
  6937. stats->tx_bytes = old_stats->tx_bytes +
  6938. get_stat64(&hw_stats->tx_octets);
  6939. stats->rx_errors = old_stats->rx_errors +
  6940. get_stat64(&hw_stats->rx_errors);
  6941. stats->tx_errors = old_stats->tx_errors +
  6942. get_stat64(&hw_stats->tx_errors) +
  6943. get_stat64(&hw_stats->tx_mac_errors) +
  6944. get_stat64(&hw_stats->tx_carrier_sense_errors) +
  6945. get_stat64(&hw_stats->tx_discards);
  6946. stats->multicast = old_stats->multicast +
  6947. get_stat64(&hw_stats->rx_mcast_packets);
  6948. stats->collisions = old_stats->collisions +
  6949. get_stat64(&hw_stats->tx_collisions);
  6950. stats->rx_length_errors = old_stats->rx_length_errors +
  6951. get_stat64(&hw_stats->rx_frame_too_long_errors) +
  6952. get_stat64(&hw_stats->rx_undersize_packets);
  6953. stats->rx_over_errors = old_stats->rx_over_errors +
  6954. get_stat64(&hw_stats->rxbds_empty);
  6955. stats->rx_frame_errors = old_stats->rx_frame_errors +
  6956. get_stat64(&hw_stats->rx_align_errors);
  6957. stats->tx_aborted_errors = old_stats->tx_aborted_errors +
  6958. get_stat64(&hw_stats->tx_discards);
  6959. stats->tx_carrier_errors = old_stats->tx_carrier_errors +
  6960. get_stat64(&hw_stats->tx_carrier_sense_errors);
  6961. stats->rx_crc_errors = old_stats->rx_crc_errors +
  6962. calc_crc_errors(tp);
  6963. stats->rx_missed_errors = old_stats->rx_missed_errors +
  6964. get_stat64(&hw_stats->rx_discards);
  6965. return stats;
  6966. }
  6967. static inline u32 calc_crc(unsigned char *buf, int len)
  6968. {
  6969. u32 reg;
  6970. u32 tmp;
  6971. int j, k;
  6972. reg = 0xffffffff;
  6973. for (j = 0; j < len; j++) {
  6974. reg ^= buf[j];
  6975. for (k = 0; k < 8; k++) {
  6976. tmp = reg & 0x01;
  6977. reg >>= 1;
  6978. if (tmp) {
  6979. reg ^= 0xedb88320;
  6980. }
  6981. }
  6982. }
  6983. return ~reg;
  6984. }
  6985. static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all)
  6986. {
  6987. /* accept or reject all multicast frames */
  6988. tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0);
  6989. tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0);
  6990. tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0);
  6991. tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0);
  6992. }
  6993. static void __tg3_set_rx_mode(struct net_device *dev)
  6994. {
  6995. struct tg3 *tp = netdev_priv(dev);
  6996. u32 rx_mode;
  6997. rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC |
  6998. RX_MODE_KEEP_VLAN_TAG);
  6999. /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG
  7000. * flag clear.
  7001. */
  7002. #if TG3_VLAN_TAG_USED
  7003. if (!tp->vlgrp &&
  7004. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  7005. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  7006. #else
  7007. /* By definition, VLAN is disabled always in this
  7008. * case.
  7009. */
  7010. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
  7011. rx_mode |= RX_MODE_KEEP_VLAN_TAG;
  7012. #endif
  7013. if (dev->flags & IFF_PROMISC) {
  7014. /* Promiscuous mode. */
  7015. rx_mode |= RX_MODE_PROMISC;
  7016. } else if (dev->flags & IFF_ALLMULTI) {
  7017. /* Accept all multicast. */
  7018. tg3_set_multi (tp, 1);
  7019. } else if (dev->mc_count < 1) {
  7020. /* Reject all multicast. */
  7021. tg3_set_multi (tp, 0);
  7022. } else {
  7023. /* Accept one or more multicast(s). */
  7024. struct dev_mc_list *mclist;
  7025. unsigned int i;
  7026. u32 mc_filter[4] = { 0, };
  7027. u32 regidx;
  7028. u32 bit;
  7029. u32 crc;
  7030. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  7031. i++, mclist = mclist->next) {
  7032. crc = calc_crc (mclist->dmi_addr, ETH_ALEN);
  7033. bit = ~crc & 0x7f;
  7034. regidx = (bit & 0x60) >> 5;
  7035. bit &= 0x1f;
  7036. mc_filter[regidx] |= (1 << bit);
  7037. }
  7038. tw32(MAC_HASH_REG_0, mc_filter[0]);
  7039. tw32(MAC_HASH_REG_1, mc_filter[1]);
  7040. tw32(MAC_HASH_REG_2, mc_filter[2]);
  7041. tw32(MAC_HASH_REG_3, mc_filter[3]);
  7042. }
  7043. if (rx_mode != tp->rx_mode) {
  7044. tp->rx_mode = rx_mode;
  7045. tw32_f(MAC_RX_MODE, rx_mode);
  7046. udelay(10);
  7047. }
  7048. }
  7049. static void tg3_set_rx_mode(struct net_device *dev)
  7050. {
  7051. struct tg3 *tp = netdev_priv(dev);
  7052. if (!netif_running(dev))
  7053. return;
  7054. tg3_full_lock(tp, 0);
  7055. __tg3_set_rx_mode(dev);
  7056. tg3_full_unlock(tp);
  7057. }
  7058. #define TG3_REGDUMP_LEN (32 * 1024)
  7059. static int tg3_get_regs_len(struct net_device *dev)
  7060. {
  7061. return TG3_REGDUMP_LEN;
  7062. }
  7063. static void tg3_get_regs(struct net_device *dev,
  7064. struct ethtool_regs *regs, void *_p)
  7065. {
  7066. u32 *p = _p;
  7067. struct tg3 *tp = netdev_priv(dev);
  7068. u8 *orig_p = _p;
  7069. int i;
  7070. regs->version = 0;
  7071. memset(p, 0, TG3_REGDUMP_LEN);
  7072. if (tp->link_config.phy_is_low_power)
  7073. return;
  7074. tg3_full_lock(tp, 0);
  7075. #define __GET_REG32(reg) (*(p)++ = tr32(reg))
  7076. #define GET_REG32_LOOP(base,len) \
  7077. do { p = (u32 *)(orig_p + (base)); \
  7078. for (i = 0; i < len; i += 4) \
  7079. __GET_REG32((base) + i); \
  7080. } while (0)
  7081. #define GET_REG32_1(reg) \
  7082. do { p = (u32 *)(orig_p + (reg)); \
  7083. __GET_REG32((reg)); \
  7084. } while (0)
  7085. GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0);
  7086. GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200);
  7087. GET_REG32_LOOP(MAC_MODE, 0x4f0);
  7088. GET_REG32_LOOP(SNDDATAI_MODE, 0xe0);
  7089. GET_REG32_1(SNDDATAC_MODE);
  7090. GET_REG32_LOOP(SNDBDS_MODE, 0x80);
  7091. GET_REG32_LOOP(SNDBDI_MODE, 0x48);
  7092. GET_REG32_1(SNDBDC_MODE);
  7093. GET_REG32_LOOP(RCVLPC_MODE, 0x20);
  7094. GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c);
  7095. GET_REG32_LOOP(RCVDBDI_MODE, 0x0c);
  7096. GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c);
  7097. GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44);
  7098. GET_REG32_1(RCVDCC_MODE);
  7099. GET_REG32_LOOP(RCVBDI_MODE, 0x20);
  7100. GET_REG32_LOOP(RCVCC_MODE, 0x14);
  7101. GET_REG32_LOOP(RCVLSC_MODE, 0x08);
  7102. GET_REG32_1(MBFREE_MODE);
  7103. GET_REG32_LOOP(HOSTCC_MODE, 0x100);
  7104. GET_REG32_LOOP(MEMARB_MODE, 0x10);
  7105. GET_REG32_LOOP(BUFMGR_MODE, 0x58);
  7106. GET_REG32_LOOP(RDMAC_MODE, 0x08);
  7107. GET_REG32_LOOP(WDMAC_MODE, 0x08);
  7108. GET_REG32_1(RX_CPU_MODE);
  7109. GET_REG32_1(RX_CPU_STATE);
  7110. GET_REG32_1(RX_CPU_PGMCTR);
  7111. GET_REG32_1(RX_CPU_HWBKPT);
  7112. GET_REG32_1(TX_CPU_MODE);
  7113. GET_REG32_1(TX_CPU_STATE);
  7114. GET_REG32_1(TX_CPU_PGMCTR);
  7115. GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110);
  7116. GET_REG32_LOOP(FTQ_RESET, 0x120);
  7117. GET_REG32_LOOP(MSGINT_MODE, 0x0c);
  7118. GET_REG32_1(DMAC_MODE);
  7119. GET_REG32_LOOP(GRC_MODE, 0x4c);
  7120. if (tp->tg3_flags & TG3_FLAG_NVRAM)
  7121. GET_REG32_LOOP(NVRAM_CMD, 0x24);
  7122. #undef __GET_REG32
  7123. #undef GET_REG32_LOOP
  7124. #undef GET_REG32_1
  7125. tg3_full_unlock(tp);
  7126. }
  7127. static int tg3_get_eeprom_len(struct net_device *dev)
  7128. {
  7129. struct tg3 *tp = netdev_priv(dev);
  7130. return tp->nvram_size;
  7131. }
  7132. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
  7133. static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val);
  7134. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
  7135. static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  7136. {
  7137. struct tg3 *tp = netdev_priv(dev);
  7138. int ret;
  7139. u8 *pd;
  7140. u32 i, offset, len, b_offset, b_count;
  7141. __le32 val;
  7142. if (tp->link_config.phy_is_low_power)
  7143. return -EAGAIN;
  7144. offset = eeprom->offset;
  7145. len = eeprom->len;
  7146. eeprom->len = 0;
  7147. eeprom->magic = TG3_EEPROM_MAGIC;
  7148. if (offset & 3) {
  7149. /* adjustments to start on required 4 byte boundary */
  7150. b_offset = offset & 3;
  7151. b_count = 4 - b_offset;
  7152. if (b_count > len) {
  7153. /* i.e. offset=1 len=2 */
  7154. b_count = len;
  7155. }
  7156. ret = tg3_nvram_read_le(tp, offset-b_offset, &val);
  7157. if (ret)
  7158. return ret;
  7159. memcpy(data, ((char*)&val) + b_offset, b_count);
  7160. len -= b_count;
  7161. offset += b_count;
  7162. eeprom->len += b_count;
  7163. }
  7164. /* read bytes upto the last 4 byte boundary */
  7165. pd = &data[eeprom->len];
  7166. for (i = 0; i < (len - (len & 3)); i += 4) {
  7167. ret = tg3_nvram_read_le(tp, offset + i, &val);
  7168. if (ret) {
  7169. eeprom->len += i;
  7170. return ret;
  7171. }
  7172. memcpy(pd + i, &val, 4);
  7173. }
  7174. eeprom->len += i;
  7175. if (len & 3) {
  7176. /* read last bytes not ending on 4 byte boundary */
  7177. pd = &data[eeprom->len];
  7178. b_count = len & 3;
  7179. b_offset = offset + len - b_count;
  7180. ret = tg3_nvram_read_le(tp, b_offset, &val);
  7181. if (ret)
  7182. return ret;
  7183. memcpy(pd, &val, b_count);
  7184. eeprom->len += b_count;
  7185. }
  7186. return 0;
  7187. }
  7188. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf);
  7189. static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
  7190. {
  7191. struct tg3 *tp = netdev_priv(dev);
  7192. int ret;
  7193. u32 offset, len, b_offset, odd_len;
  7194. u8 *buf;
  7195. __le32 start, end;
  7196. if (tp->link_config.phy_is_low_power)
  7197. return -EAGAIN;
  7198. if (eeprom->magic != TG3_EEPROM_MAGIC)
  7199. return -EINVAL;
  7200. offset = eeprom->offset;
  7201. len = eeprom->len;
  7202. if ((b_offset = (offset & 3))) {
  7203. /* adjustments to start on required 4 byte boundary */
  7204. ret = tg3_nvram_read_le(tp, offset-b_offset, &start);
  7205. if (ret)
  7206. return ret;
  7207. len += b_offset;
  7208. offset &= ~3;
  7209. if (len < 4)
  7210. len = 4;
  7211. }
  7212. odd_len = 0;
  7213. if (len & 3) {
  7214. /* adjustments to end on required 4 byte boundary */
  7215. odd_len = 1;
  7216. len = (len + 3) & ~3;
  7217. ret = tg3_nvram_read_le(tp, offset+len-4, &end);
  7218. if (ret)
  7219. return ret;
  7220. }
  7221. buf = data;
  7222. if (b_offset || odd_len) {
  7223. buf = kmalloc(len, GFP_KERNEL);
  7224. if (!buf)
  7225. return -ENOMEM;
  7226. if (b_offset)
  7227. memcpy(buf, &start, 4);
  7228. if (odd_len)
  7229. memcpy(buf+len-4, &end, 4);
  7230. memcpy(buf + b_offset, data, eeprom->len);
  7231. }
  7232. ret = tg3_nvram_write_block(tp, offset, len, buf);
  7233. if (buf != data)
  7234. kfree(buf);
  7235. return ret;
  7236. }
  7237. static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7238. {
  7239. struct tg3 *tp = netdev_priv(dev);
  7240. cmd->supported = (SUPPORTED_Autoneg);
  7241. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  7242. cmd->supported |= (SUPPORTED_1000baseT_Half |
  7243. SUPPORTED_1000baseT_Full);
  7244. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) {
  7245. cmd->supported |= (SUPPORTED_100baseT_Half |
  7246. SUPPORTED_100baseT_Full |
  7247. SUPPORTED_10baseT_Half |
  7248. SUPPORTED_10baseT_Full |
  7249. SUPPORTED_TP);
  7250. cmd->port = PORT_TP;
  7251. } else {
  7252. cmd->supported |= SUPPORTED_FIBRE;
  7253. cmd->port = PORT_FIBRE;
  7254. }
  7255. cmd->advertising = tp->link_config.advertising;
  7256. if (netif_running(dev)) {
  7257. cmd->speed = tp->link_config.active_speed;
  7258. cmd->duplex = tp->link_config.active_duplex;
  7259. }
  7260. cmd->phy_address = PHY_ADDR;
  7261. cmd->transceiver = 0;
  7262. cmd->autoneg = tp->link_config.autoneg;
  7263. cmd->maxtxpkt = 0;
  7264. cmd->maxrxpkt = 0;
  7265. return 0;
  7266. }
  7267. static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7268. {
  7269. struct tg3 *tp = netdev_priv(dev);
  7270. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
  7271. /* These are the only valid advertisement bits allowed. */
  7272. if (cmd->autoneg == AUTONEG_ENABLE &&
  7273. (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
  7274. ADVERTISED_1000baseT_Full |
  7275. ADVERTISED_Autoneg |
  7276. ADVERTISED_FIBRE)))
  7277. return -EINVAL;
  7278. /* Fiber can only do SPEED_1000. */
  7279. else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  7280. (cmd->speed != SPEED_1000))
  7281. return -EINVAL;
  7282. /* Copper cannot force SPEED_1000. */
  7283. } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
  7284. (cmd->speed == SPEED_1000))
  7285. return -EINVAL;
  7286. else if ((cmd->speed == SPEED_1000) &&
  7287. (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
  7288. return -EINVAL;
  7289. tg3_full_lock(tp, 0);
  7290. tp->link_config.autoneg = cmd->autoneg;
  7291. if (cmd->autoneg == AUTONEG_ENABLE) {
  7292. tp->link_config.advertising = (cmd->advertising |
  7293. ADVERTISED_Autoneg);
  7294. tp->link_config.speed = SPEED_INVALID;
  7295. tp->link_config.duplex = DUPLEX_INVALID;
  7296. } else {
  7297. tp->link_config.advertising = 0;
  7298. tp->link_config.speed = cmd->speed;
  7299. tp->link_config.duplex = cmd->duplex;
  7300. }
  7301. tp->link_config.orig_speed = tp->link_config.speed;
  7302. tp->link_config.orig_duplex = tp->link_config.duplex;
  7303. tp->link_config.orig_autoneg = tp->link_config.autoneg;
  7304. if (netif_running(dev))
  7305. tg3_setup_phy(tp, 1);
  7306. tg3_full_unlock(tp);
  7307. return 0;
  7308. }
  7309. static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  7310. {
  7311. struct tg3 *tp = netdev_priv(dev);
  7312. strcpy(info->driver, DRV_MODULE_NAME);
  7313. strcpy(info->version, DRV_MODULE_VERSION);
  7314. strcpy(info->fw_version, tp->fw_ver);
  7315. strcpy(info->bus_info, pci_name(tp->pdev));
  7316. }
  7317. static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7318. {
  7319. struct tg3 *tp = netdev_priv(dev);
  7320. if (tp->tg3_flags & TG3_FLAG_WOL_CAP)
  7321. wol->supported = WAKE_MAGIC;
  7322. else
  7323. wol->supported = 0;
  7324. wol->wolopts = 0;
  7325. if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
  7326. wol->wolopts = WAKE_MAGIC;
  7327. memset(&wol->sopass, 0, sizeof(wol->sopass));
  7328. }
  7329. static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7330. {
  7331. struct tg3 *tp = netdev_priv(dev);
  7332. if (wol->wolopts & ~WAKE_MAGIC)
  7333. return -EINVAL;
  7334. if ((wol->wolopts & WAKE_MAGIC) &&
  7335. !(tp->tg3_flags & TG3_FLAG_WOL_CAP))
  7336. return -EINVAL;
  7337. spin_lock_bh(&tp->lock);
  7338. if (wol->wolopts & WAKE_MAGIC)
  7339. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  7340. else
  7341. tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
  7342. spin_unlock_bh(&tp->lock);
  7343. return 0;
  7344. }
  7345. static u32 tg3_get_msglevel(struct net_device *dev)
  7346. {
  7347. struct tg3 *tp = netdev_priv(dev);
  7348. return tp->msg_enable;
  7349. }
  7350. static void tg3_set_msglevel(struct net_device *dev, u32 value)
  7351. {
  7352. struct tg3 *tp = netdev_priv(dev);
  7353. tp->msg_enable = value;
  7354. }
  7355. static int tg3_set_tso(struct net_device *dev, u32 value)
  7356. {
  7357. struct tg3 *tp = netdev_priv(dev);
  7358. if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) {
  7359. if (value)
  7360. return -EINVAL;
  7361. return 0;
  7362. }
  7363. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  7364. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)) {
  7365. if (value) {
  7366. dev->features |= NETIF_F_TSO6;
  7367. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7368. dev->features |= NETIF_F_TSO_ECN;
  7369. } else
  7370. dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN);
  7371. }
  7372. return ethtool_op_set_tso(dev, value);
  7373. }
  7374. static int tg3_nway_reset(struct net_device *dev)
  7375. {
  7376. struct tg3 *tp = netdev_priv(dev);
  7377. u32 bmcr;
  7378. int r;
  7379. if (!netif_running(dev))
  7380. return -EAGAIN;
  7381. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  7382. return -EINVAL;
  7383. spin_lock_bh(&tp->lock);
  7384. r = -EINVAL;
  7385. tg3_readphy(tp, MII_BMCR, &bmcr);
  7386. if (!tg3_readphy(tp, MII_BMCR, &bmcr) &&
  7387. ((bmcr & BMCR_ANENABLE) ||
  7388. (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) {
  7389. tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART |
  7390. BMCR_ANENABLE);
  7391. r = 0;
  7392. }
  7393. spin_unlock_bh(&tp->lock);
  7394. return r;
  7395. }
  7396. static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  7397. {
  7398. struct tg3 *tp = netdev_priv(dev);
  7399. ering->rx_max_pending = TG3_RX_RING_SIZE - 1;
  7400. ering->rx_mini_max_pending = 0;
  7401. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  7402. ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1;
  7403. else
  7404. ering->rx_jumbo_max_pending = 0;
  7405. ering->tx_max_pending = TG3_TX_RING_SIZE - 1;
  7406. ering->rx_pending = tp->rx_pending;
  7407. ering->rx_mini_pending = 0;
  7408. if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)
  7409. ering->rx_jumbo_pending = tp->rx_jumbo_pending;
  7410. else
  7411. ering->rx_jumbo_pending = 0;
  7412. ering->tx_pending = tp->tx_pending;
  7413. }
  7414. static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  7415. {
  7416. struct tg3 *tp = netdev_priv(dev);
  7417. int irq_sync = 0, err = 0;
  7418. if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
  7419. (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
  7420. (ering->tx_pending > TG3_TX_RING_SIZE - 1) ||
  7421. (ering->tx_pending <= MAX_SKB_FRAGS) ||
  7422. ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) &&
  7423. (ering->tx_pending <= (MAX_SKB_FRAGS * 3))))
  7424. return -EINVAL;
  7425. if (netif_running(dev)) {
  7426. tg3_netif_stop(tp);
  7427. irq_sync = 1;
  7428. }
  7429. tg3_full_lock(tp, irq_sync);
  7430. tp->rx_pending = ering->rx_pending;
  7431. if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) &&
  7432. tp->rx_pending > 63)
  7433. tp->rx_pending = 63;
  7434. tp->rx_jumbo_pending = ering->rx_jumbo_pending;
  7435. tp->tx_pending = ering->tx_pending;
  7436. if (netif_running(dev)) {
  7437. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7438. err = tg3_restart_hw(tp, 1);
  7439. if (!err)
  7440. tg3_netif_start(tp);
  7441. }
  7442. tg3_full_unlock(tp);
  7443. return err;
  7444. }
  7445. static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7446. {
  7447. struct tg3 *tp = netdev_priv(dev);
  7448. epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0;
  7449. if (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX)
  7450. epause->rx_pause = 1;
  7451. else
  7452. epause->rx_pause = 0;
  7453. if (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_TX)
  7454. epause->tx_pause = 1;
  7455. else
  7456. epause->tx_pause = 0;
  7457. }
  7458. static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  7459. {
  7460. struct tg3 *tp = netdev_priv(dev);
  7461. int irq_sync = 0, err = 0;
  7462. if (netif_running(dev)) {
  7463. tg3_netif_stop(tp);
  7464. irq_sync = 1;
  7465. }
  7466. tg3_full_lock(tp, irq_sync);
  7467. if (epause->autoneg)
  7468. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  7469. else
  7470. tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG;
  7471. if (epause->rx_pause)
  7472. tp->link_config.flowctrl |= TG3_FLOW_CTRL_RX;
  7473. else
  7474. tp->link_config.flowctrl &= ~TG3_FLOW_CTRL_RX;
  7475. if (epause->tx_pause)
  7476. tp->link_config.flowctrl |= TG3_FLOW_CTRL_TX;
  7477. else
  7478. tp->link_config.flowctrl &= ~TG3_FLOW_CTRL_TX;
  7479. if (netif_running(dev)) {
  7480. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  7481. err = tg3_restart_hw(tp, 1);
  7482. if (!err)
  7483. tg3_netif_start(tp);
  7484. }
  7485. tg3_full_unlock(tp);
  7486. return err;
  7487. }
  7488. static u32 tg3_get_rx_csum(struct net_device *dev)
  7489. {
  7490. struct tg3 *tp = netdev_priv(dev);
  7491. return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0;
  7492. }
  7493. static int tg3_set_rx_csum(struct net_device *dev, u32 data)
  7494. {
  7495. struct tg3 *tp = netdev_priv(dev);
  7496. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7497. if (data != 0)
  7498. return -EINVAL;
  7499. return 0;
  7500. }
  7501. spin_lock_bh(&tp->lock);
  7502. if (data)
  7503. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  7504. else
  7505. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  7506. spin_unlock_bh(&tp->lock);
  7507. return 0;
  7508. }
  7509. static int tg3_set_tx_csum(struct net_device *dev, u32 data)
  7510. {
  7511. struct tg3 *tp = netdev_priv(dev);
  7512. if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) {
  7513. if (data != 0)
  7514. return -EINVAL;
  7515. return 0;
  7516. }
  7517. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7518. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  7519. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  7520. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7521. ethtool_op_set_tx_ipv6_csum(dev, data);
  7522. else
  7523. ethtool_op_set_tx_csum(dev, data);
  7524. return 0;
  7525. }
  7526. static int tg3_get_sset_count (struct net_device *dev, int sset)
  7527. {
  7528. switch (sset) {
  7529. case ETH_SS_TEST:
  7530. return TG3_NUM_TEST;
  7531. case ETH_SS_STATS:
  7532. return TG3_NUM_STATS;
  7533. default:
  7534. return -EOPNOTSUPP;
  7535. }
  7536. }
  7537. static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
  7538. {
  7539. switch (stringset) {
  7540. case ETH_SS_STATS:
  7541. memcpy(buf, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  7542. break;
  7543. case ETH_SS_TEST:
  7544. memcpy(buf, &ethtool_test_keys, sizeof(ethtool_test_keys));
  7545. break;
  7546. default:
  7547. WARN_ON(1); /* we need a WARN() */
  7548. break;
  7549. }
  7550. }
  7551. static int tg3_phys_id(struct net_device *dev, u32 data)
  7552. {
  7553. struct tg3 *tp = netdev_priv(dev);
  7554. int i;
  7555. if (!netif_running(tp->dev))
  7556. return -EAGAIN;
  7557. if (data == 0)
  7558. data = UINT_MAX / 2;
  7559. for (i = 0; i < (data * 2); i++) {
  7560. if ((i % 2) == 0)
  7561. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7562. LED_CTRL_1000MBPS_ON |
  7563. LED_CTRL_100MBPS_ON |
  7564. LED_CTRL_10MBPS_ON |
  7565. LED_CTRL_TRAFFIC_OVERRIDE |
  7566. LED_CTRL_TRAFFIC_BLINK |
  7567. LED_CTRL_TRAFFIC_LED);
  7568. else
  7569. tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
  7570. LED_CTRL_TRAFFIC_OVERRIDE);
  7571. if (msleep_interruptible(500))
  7572. break;
  7573. }
  7574. tw32(MAC_LED_CTRL, tp->led_ctrl);
  7575. return 0;
  7576. }
  7577. static void tg3_get_ethtool_stats (struct net_device *dev,
  7578. struct ethtool_stats *estats, u64 *tmp_stats)
  7579. {
  7580. struct tg3 *tp = netdev_priv(dev);
  7581. memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
  7582. }
  7583. #define NVRAM_TEST_SIZE 0x100
  7584. #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14
  7585. #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18
  7586. #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c
  7587. #define NVRAM_SELFBOOT_HW_SIZE 0x20
  7588. #define NVRAM_SELFBOOT_DATA_SIZE 0x1c
  7589. static int tg3_test_nvram(struct tg3 *tp)
  7590. {
  7591. u32 csum, magic;
  7592. __le32 *buf;
  7593. int i, j, k, err = 0, size;
  7594. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  7595. return -EIO;
  7596. if (magic == TG3_EEPROM_MAGIC)
  7597. size = NVRAM_TEST_SIZE;
  7598. else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) {
  7599. if ((magic & TG3_EEPROM_SB_FORMAT_MASK) ==
  7600. TG3_EEPROM_SB_FORMAT_1) {
  7601. switch (magic & TG3_EEPROM_SB_REVISION_MASK) {
  7602. case TG3_EEPROM_SB_REVISION_0:
  7603. size = NVRAM_SELFBOOT_FORMAT1_0_SIZE;
  7604. break;
  7605. case TG3_EEPROM_SB_REVISION_2:
  7606. size = NVRAM_SELFBOOT_FORMAT1_2_SIZE;
  7607. break;
  7608. case TG3_EEPROM_SB_REVISION_3:
  7609. size = NVRAM_SELFBOOT_FORMAT1_3_SIZE;
  7610. break;
  7611. default:
  7612. return 0;
  7613. }
  7614. } else
  7615. return 0;
  7616. } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW)
  7617. size = NVRAM_SELFBOOT_HW_SIZE;
  7618. else
  7619. return -EIO;
  7620. buf = kmalloc(size, GFP_KERNEL);
  7621. if (buf == NULL)
  7622. return -ENOMEM;
  7623. err = -EIO;
  7624. for (i = 0, j = 0; i < size; i += 4, j++) {
  7625. if ((err = tg3_nvram_read_le(tp, i, &buf[j])) != 0)
  7626. break;
  7627. }
  7628. if (i < size)
  7629. goto out;
  7630. /* Selfboot format */
  7631. magic = swab32(le32_to_cpu(buf[0]));
  7632. if ((magic & TG3_EEPROM_MAGIC_FW_MSK) ==
  7633. TG3_EEPROM_MAGIC_FW) {
  7634. u8 *buf8 = (u8 *) buf, csum8 = 0;
  7635. if ((magic & TG3_EEPROM_SB_REVISION_MASK) ==
  7636. TG3_EEPROM_SB_REVISION_2) {
  7637. /* For rev 2, the csum doesn't include the MBA. */
  7638. for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++)
  7639. csum8 += buf8[i];
  7640. for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++)
  7641. csum8 += buf8[i];
  7642. } else {
  7643. for (i = 0; i < size; i++)
  7644. csum8 += buf8[i];
  7645. }
  7646. if (csum8 == 0) {
  7647. err = 0;
  7648. goto out;
  7649. }
  7650. err = -EIO;
  7651. goto out;
  7652. }
  7653. if ((magic & TG3_EEPROM_MAGIC_HW_MSK) ==
  7654. TG3_EEPROM_MAGIC_HW) {
  7655. u8 data[NVRAM_SELFBOOT_DATA_SIZE];
  7656. u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
  7657. u8 *buf8 = (u8 *) buf;
  7658. /* Separate the parity bits and the data bytes. */
  7659. for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) {
  7660. if ((i == 0) || (i == 8)) {
  7661. int l;
  7662. u8 msk;
  7663. for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1)
  7664. parity[k++] = buf8[i] & msk;
  7665. i++;
  7666. }
  7667. else if (i == 16) {
  7668. int l;
  7669. u8 msk;
  7670. for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1)
  7671. parity[k++] = buf8[i] & msk;
  7672. i++;
  7673. for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1)
  7674. parity[k++] = buf8[i] & msk;
  7675. i++;
  7676. }
  7677. data[j++] = buf8[i];
  7678. }
  7679. err = -EIO;
  7680. for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) {
  7681. u8 hw8 = hweight8(data[i]);
  7682. if ((hw8 & 0x1) && parity[i])
  7683. goto out;
  7684. else if (!(hw8 & 0x1) && !parity[i])
  7685. goto out;
  7686. }
  7687. err = 0;
  7688. goto out;
  7689. }
  7690. /* Bootstrap checksum at offset 0x10 */
  7691. csum = calc_crc((unsigned char *) buf, 0x10);
  7692. if(csum != le32_to_cpu(buf[0x10/4]))
  7693. goto out;
  7694. /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
  7695. csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
  7696. if (csum != le32_to_cpu(buf[0xfc/4]))
  7697. goto out;
  7698. err = 0;
  7699. out:
  7700. kfree(buf);
  7701. return err;
  7702. }
  7703. #define TG3_SERDES_TIMEOUT_SEC 2
  7704. #define TG3_COPPER_TIMEOUT_SEC 6
  7705. static int tg3_test_link(struct tg3 *tp)
  7706. {
  7707. int i, max;
  7708. if (!netif_running(tp->dev))
  7709. return -ENODEV;
  7710. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  7711. max = TG3_SERDES_TIMEOUT_SEC;
  7712. else
  7713. max = TG3_COPPER_TIMEOUT_SEC;
  7714. for (i = 0; i < max; i++) {
  7715. if (netif_carrier_ok(tp->dev))
  7716. return 0;
  7717. if (msleep_interruptible(1000))
  7718. break;
  7719. }
  7720. return -EIO;
  7721. }
  7722. /* Only test the commonly used registers */
  7723. static int tg3_test_registers(struct tg3 *tp)
  7724. {
  7725. int i, is_5705, is_5750;
  7726. u32 offset, read_mask, write_mask, val, save_val, read_val;
  7727. static struct {
  7728. u16 offset;
  7729. u16 flags;
  7730. #define TG3_FL_5705 0x1
  7731. #define TG3_FL_NOT_5705 0x2
  7732. #define TG3_FL_NOT_5788 0x4
  7733. #define TG3_FL_NOT_5750 0x8
  7734. u32 read_mask;
  7735. u32 write_mask;
  7736. } reg_tbl[] = {
  7737. /* MAC Control Registers */
  7738. { MAC_MODE, TG3_FL_NOT_5705,
  7739. 0x00000000, 0x00ef6f8c },
  7740. { MAC_MODE, TG3_FL_5705,
  7741. 0x00000000, 0x01ef6b8c },
  7742. { MAC_STATUS, TG3_FL_NOT_5705,
  7743. 0x03800107, 0x00000000 },
  7744. { MAC_STATUS, TG3_FL_5705,
  7745. 0x03800100, 0x00000000 },
  7746. { MAC_ADDR_0_HIGH, 0x0000,
  7747. 0x00000000, 0x0000ffff },
  7748. { MAC_ADDR_0_LOW, 0x0000,
  7749. 0x00000000, 0xffffffff },
  7750. { MAC_RX_MTU_SIZE, 0x0000,
  7751. 0x00000000, 0x0000ffff },
  7752. { MAC_TX_MODE, 0x0000,
  7753. 0x00000000, 0x00000070 },
  7754. { MAC_TX_LENGTHS, 0x0000,
  7755. 0x00000000, 0x00003fff },
  7756. { MAC_RX_MODE, TG3_FL_NOT_5705,
  7757. 0x00000000, 0x000007fc },
  7758. { MAC_RX_MODE, TG3_FL_5705,
  7759. 0x00000000, 0x000007dc },
  7760. { MAC_HASH_REG_0, 0x0000,
  7761. 0x00000000, 0xffffffff },
  7762. { MAC_HASH_REG_1, 0x0000,
  7763. 0x00000000, 0xffffffff },
  7764. { MAC_HASH_REG_2, 0x0000,
  7765. 0x00000000, 0xffffffff },
  7766. { MAC_HASH_REG_3, 0x0000,
  7767. 0x00000000, 0xffffffff },
  7768. /* Receive Data and Receive BD Initiator Control Registers. */
  7769. { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705,
  7770. 0x00000000, 0xffffffff },
  7771. { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705,
  7772. 0x00000000, 0xffffffff },
  7773. { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705,
  7774. 0x00000000, 0x00000003 },
  7775. { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705,
  7776. 0x00000000, 0xffffffff },
  7777. { RCVDBDI_STD_BD+0, 0x0000,
  7778. 0x00000000, 0xffffffff },
  7779. { RCVDBDI_STD_BD+4, 0x0000,
  7780. 0x00000000, 0xffffffff },
  7781. { RCVDBDI_STD_BD+8, 0x0000,
  7782. 0x00000000, 0xffff0002 },
  7783. { RCVDBDI_STD_BD+0xc, 0x0000,
  7784. 0x00000000, 0xffffffff },
  7785. /* Receive BD Initiator Control Registers. */
  7786. { RCVBDI_STD_THRESH, TG3_FL_NOT_5705,
  7787. 0x00000000, 0xffffffff },
  7788. { RCVBDI_STD_THRESH, TG3_FL_5705,
  7789. 0x00000000, 0x000003ff },
  7790. { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705,
  7791. 0x00000000, 0xffffffff },
  7792. /* Host Coalescing Control Registers. */
  7793. { HOSTCC_MODE, TG3_FL_NOT_5705,
  7794. 0x00000000, 0x00000004 },
  7795. { HOSTCC_MODE, TG3_FL_5705,
  7796. 0x00000000, 0x000000f6 },
  7797. { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705,
  7798. 0x00000000, 0xffffffff },
  7799. { HOSTCC_RXCOL_TICKS, TG3_FL_5705,
  7800. 0x00000000, 0x000003ff },
  7801. { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705,
  7802. 0x00000000, 0xffffffff },
  7803. { HOSTCC_TXCOL_TICKS, TG3_FL_5705,
  7804. 0x00000000, 0x000003ff },
  7805. { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705,
  7806. 0x00000000, 0xffffffff },
  7807. { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7808. 0x00000000, 0x000000ff },
  7809. { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705,
  7810. 0x00000000, 0xffffffff },
  7811. { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788,
  7812. 0x00000000, 0x000000ff },
  7813. { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7814. 0x00000000, 0xffffffff },
  7815. { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705,
  7816. 0x00000000, 0xffffffff },
  7817. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7818. 0x00000000, 0xffffffff },
  7819. { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7820. 0x00000000, 0x000000ff },
  7821. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705,
  7822. 0x00000000, 0xffffffff },
  7823. { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788,
  7824. 0x00000000, 0x000000ff },
  7825. { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705,
  7826. 0x00000000, 0xffffffff },
  7827. { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705,
  7828. 0x00000000, 0xffffffff },
  7829. { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705,
  7830. 0x00000000, 0xffffffff },
  7831. { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000,
  7832. 0x00000000, 0xffffffff },
  7833. { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000,
  7834. 0x00000000, 0xffffffff },
  7835. { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000,
  7836. 0xffffffff, 0x00000000 },
  7837. { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000,
  7838. 0xffffffff, 0x00000000 },
  7839. /* Buffer Manager Control Registers. */
  7840. { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
  7841. 0x00000000, 0x007fff80 },
  7842. { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
  7843. 0x00000000, 0x007fffff },
  7844. { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
  7845. 0x00000000, 0x0000003f },
  7846. { BUFMGR_MB_MACRX_LOW_WATER, 0x0000,
  7847. 0x00000000, 0x000001ff },
  7848. { BUFMGR_MB_HIGH_WATER, 0x0000,
  7849. 0x00000000, 0x000001ff },
  7850. { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705,
  7851. 0xffffffff, 0x00000000 },
  7852. { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705,
  7853. 0xffffffff, 0x00000000 },
  7854. /* Mailbox Registers */
  7855. { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000,
  7856. 0x00000000, 0x000001ff },
  7857. { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705,
  7858. 0x00000000, 0x000001ff },
  7859. { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000,
  7860. 0x00000000, 0x000007ff },
  7861. { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000,
  7862. 0x00000000, 0x000001ff },
  7863. { 0xffff, 0x0000, 0x00000000, 0x00000000 },
  7864. };
  7865. is_5705 = is_5750 = 0;
  7866. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7867. is_5705 = 1;
  7868. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  7869. is_5750 = 1;
  7870. }
  7871. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  7872. if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
  7873. continue;
  7874. if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705))
  7875. continue;
  7876. if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  7877. (reg_tbl[i].flags & TG3_FL_NOT_5788))
  7878. continue;
  7879. if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
  7880. continue;
  7881. offset = (u32) reg_tbl[i].offset;
  7882. read_mask = reg_tbl[i].read_mask;
  7883. write_mask = reg_tbl[i].write_mask;
  7884. /* Save the original register content */
  7885. save_val = tr32(offset);
  7886. /* Determine the read-only value. */
  7887. read_val = save_val & read_mask;
  7888. /* Write zero to the register, then make sure the read-only bits
  7889. * are not changed and the read/write bits are all zeros.
  7890. */
  7891. tw32(offset, 0);
  7892. val = tr32(offset);
  7893. /* Test the read-only and read/write bits. */
  7894. if (((val & read_mask) != read_val) || (val & write_mask))
  7895. goto out;
  7896. /* Write ones to all the bits defined by RdMask and WrMask, then
  7897. * make sure the read-only bits are not changed and the
  7898. * read/write bits are all ones.
  7899. */
  7900. tw32(offset, read_mask | write_mask);
  7901. val = tr32(offset);
  7902. /* Test the read-only bits. */
  7903. if ((val & read_mask) != read_val)
  7904. goto out;
  7905. /* Test the read/write bits. */
  7906. if ((val & write_mask) != write_mask)
  7907. goto out;
  7908. tw32(offset, save_val);
  7909. }
  7910. return 0;
  7911. out:
  7912. if (netif_msg_hw(tp))
  7913. printk(KERN_ERR PFX "Register test failed at offset %x\n",
  7914. offset);
  7915. tw32(offset, save_val);
  7916. return -EIO;
  7917. }
  7918. static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len)
  7919. {
  7920. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a };
  7921. int i;
  7922. u32 j;
  7923. for (i = 0; i < ARRAY_SIZE(test_pattern); i++) {
  7924. for (j = 0; j < len; j += 4) {
  7925. u32 val;
  7926. tg3_write_mem(tp, offset + j, test_pattern[i]);
  7927. tg3_read_mem(tp, offset + j, &val);
  7928. if (val != test_pattern[i])
  7929. return -EIO;
  7930. }
  7931. }
  7932. return 0;
  7933. }
  7934. static int tg3_test_memory(struct tg3 *tp)
  7935. {
  7936. static struct mem_entry {
  7937. u32 offset;
  7938. u32 len;
  7939. } mem_tbl_570x[] = {
  7940. { 0x00000000, 0x00b50},
  7941. { 0x00002000, 0x1c000},
  7942. { 0xffffffff, 0x00000}
  7943. }, mem_tbl_5705[] = {
  7944. { 0x00000100, 0x0000c},
  7945. { 0x00000200, 0x00008},
  7946. { 0x00004000, 0x00800},
  7947. { 0x00006000, 0x01000},
  7948. { 0x00008000, 0x02000},
  7949. { 0x00010000, 0x0e000},
  7950. { 0xffffffff, 0x00000}
  7951. }, mem_tbl_5755[] = {
  7952. { 0x00000200, 0x00008},
  7953. { 0x00004000, 0x00800},
  7954. { 0x00006000, 0x00800},
  7955. { 0x00008000, 0x02000},
  7956. { 0x00010000, 0x0c000},
  7957. { 0xffffffff, 0x00000}
  7958. }, mem_tbl_5906[] = {
  7959. { 0x00000200, 0x00008},
  7960. { 0x00004000, 0x00400},
  7961. { 0x00006000, 0x00400},
  7962. { 0x00008000, 0x01000},
  7963. { 0x00010000, 0x01000},
  7964. { 0xffffffff, 0x00000}
  7965. };
  7966. struct mem_entry *mem_tbl;
  7967. int err = 0;
  7968. int i;
  7969. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  7970. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  7971. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  7972. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  7973. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  7974. mem_tbl = mem_tbl_5755;
  7975. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  7976. mem_tbl = mem_tbl_5906;
  7977. else
  7978. mem_tbl = mem_tbl_5705;
  7979. } else
  7980. mem_tbl = mem_tbl_570x;
  7981. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  7982. if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset,
  7983. mem_tbl[i].len)) != 0)
  7984. break;
  7985. }
  7986. return err;
  7987. }
  7988. #define TG3_MAC_LOOPBACK 0
  7989. #define TG3_PHY_LOOPBACK 1
  7990. static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
  7991. {
  7992. u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
  7993. u32 desc_idx;
  7994. struct sk_buff *skb, *rx_skb;
  7995. u8 *tx_data;
  7996. dma_addr_t map;
  7997. int num_pkts, tx_len, rx_len, i, err;
  7998. struct tg3_rx_buffer_desc *desc;
  7999. if (loopback_mode == TG3_MAC_LOOPBACK) {
  8000. /* HW errata - mac loopback fails in some cases on 5780.
  8001. * Normal traffic and PHY loopback are not affected by
  8002. * errata.
  8003. */
  8004. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)
  8005. return 0;
  8006. mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
  8007. MAC_MODE_PORT_INT_LPBACK;
  8008. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  8009. mac_mode |= MAC_MODE_LINK_POLARITY;
  8010. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  8011. mac_mode |= MAC_MODE_PORT_MODE_MII;
  8012. else
  8013. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  8014. tw32(MAC_MODE, mac_mode);
  8015. } else if (loopback_mode == TG3_PHY_LOOPBACK) {
  8016. u32 val;
  8017. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8018. u32 phytest;
  8019. if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phytest)) {
  8020. u32 phy;
  8021. tg3_writephy(tp, MII_TG3_EPHY_TEST,
  8022. phytest | MII_TG3_EPHY_SHADOW_EN);
  8023. if (!tg3_readphy(tp, 0x1b, &phy))
  8024. tg3_writephy(tp, 0x1b, phy & ~0x20);
  8025. tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
  8026. }
  8027. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
  8028. } else
  8029. val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  8030. tg3_phy_toggle_automdix(tp, 0);
  8031. tg3_writephy(tp, MII_BMCR, val);
  8032. udelay(40);
  8033. mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
  8034. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  8035. tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
  8036. mac_mode |= MAC_MODE_PORT_MODE_MII;
  8037. } else
  8038. mac_mode |= MAC_MODE_PORT_MODE_GMII;
  8039. /* reset to prevent losing 1st rx packet intermittently */
  8040. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
  8041. tw32_f(MAC_RX_MODE, RX_MODE_RESET);
  8042. udelay(10);
  8043. tw32_f(MAC_RX_MODE, tp->rx_mode);
  8044. }
  8045. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
  8046. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
  8047. mac_mode &= ~MAC_MODE_LINK_POLARITY;
  8048. else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411)
  8049. mac_mode |= MAC_MODE_LINK_POLARITY;
  8050. tg3_writephy(tp, MII_TG3_EXT_CTRL,
  8051. MII_TG3_EXT_CTRL_LNK3_LED_MODE);
  8052. }
  8053. tw32(MAC_MODE, mac_mode);
  8054. }
  8055. else
  8056. return -EINVAL;
  8057. err = -EIO;
  8058. tx_len = 1514;
  8059. skb = netdev_alloc_skb(tp->dev, tx_len);
  8060. if (!skb)
  8061. return -ENOMEM;
  8062. tx_data = skb_put(skb, tx_len);
  8063. memcpy(tx_data, tp->dev->dev_addr, 6);
  8064. memset(tx_data + 6, 0x0, 8);
  8065. tw32(MAC_RX_MTU_SIZE, tx_len + 4);
  8066. for (i = 14; i < tx_len; i++)
  8067. tx_data[i] = (u8) (i & 0xff);
  8068. map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE);
  8069. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  8070. HOSTCC_MODE_NOW);
  8071. udelay(10);
  8072. rx_start_idx = tp->hw_status->idx[0].rx_producer;
  8073. num_pkts = 0;
  8074. tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
  8075. tp->tx_prod++;
  8076. num_pkts++;
  8077. tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
  8078. tp->tx_prod);
  8079. tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
  8080. udelay(10);
  8081. /* 250 usec to allow enough time on some 10/100 Mbps devices. */
  8082. for (i = 0; i < 25; i++) {
  8083. tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
  8084. HOSTCC_MODE_NOW);
  8085. udelay(10);
  8086. tx_idx = tp->hw_status->idx[0].tx_consumer;
  8087. rx_idx = tp->hw_status->idx[0].rx_producer;
  8088. if ((tx_idx == tp->tx_prod) &&
  8089. (rx_idx == (rx_start_idx + num_pkts)))
  8090. break;
  8091. }
  8092. pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
  8093. dev_kfree_skb(skb);
  8094. if (tx_idx != tp->tx_prod)
  8095. goto out;
  8096. if (rx_idx != rx_start_idx + num_pkts)
  8097. goto out;
  8098. desc = &tp->rx_rcb[rx_start_idx];
  8099. desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK;
  8100. opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK;
  8101. if (opaque_key != RXD_OPAQUE_RING_STD)
  8102. goto out;
  8103. if ((desc->err_vlan & RXD_ERR_MASK) != 0 &&
  8104. (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII))
  8105. goto out;
  8106. rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4;
  8107. if (rx_len != tx_len)
  8108. goto out;
  8109. rx_skb = tp->rx_std_buffers[desc_idx].skb;
  8110. map = pci_unmap_addr(&tp->rx_std_buffers[desc_idx], mapping);
  8111. pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE);
  8112. for (i = 14; i < tx_len; i++) {
  8113. if (*(rx_skb->data + i) != (u8) (i & 0xff))
  8114. goto out;
  8115. }
  8116. err = 0;
  8117. /* tg3_free_rings will unmap and free the rx_skb */
  8118. out:
  8119. return err;
  8120. }
  8121. #define TG3_MAC_LOOPBACK_FAILED 1
  8122. #define TG3_PHY_LOOPBACK_FAILED 2
  8123. #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
  8124. TG3_PHY_LOOPBACK_FAILED)
  8125. static int tg3_test_loopback(struct tg3 *tp)
  8126. {
  8127. int err = 0;
  8128. u32 cpmuctrl = 0;
  8129. if (!netif_running(tp->dev))
  8130. return TG3_LOOPBACK_FAILED;
  8131. err = tg3_reset_hw(tp, 1);
  8132. if (err)
  8133. return TG3_LOOPBACK_FAILED;
  8134. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8135. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  8136. int i;
  8137. u32 status;
  8138. tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER);
  8139. /* Wait for up to 40 microseconds to acquire lock. */
  8140. for (i = 0; i < 4; i++) {
  8141. status = tr32(TG3_CPMU_MUTEX_GNT);
  8142. if (status == CPMU_MUTEX_GNT_DRIVER)
  8143. break;
  8144. udelay(10);
  8145. }
  8146. if (status != CPMU_MUTEX_GNT_DRIVER)
  8147. return TG3_LOOPBACK_FAILED;
  8148. /* Turn off link-based power management. */
  8149. cpmuctrl = tr32(TG3_CPMU_CTRL);
  8150. tw32(TG3_CPMU_CTRL,
  8151. cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE |
  8152. CPMU_CTRL_LINK_AWARE_MODE));
  8153. }
  8154. if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
  8155. err |= TG3_MAC_LOOPBACK_FAILED;
  8156. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  8157. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  8158. tw32(TG3_CPMU_CTRL, cpmuctrl);
  8159. /* Release the mutex */
  8160. tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER);
  8161. }
  8162. if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  8163. if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
  8164. err |= TG3_PHY_LOOPBACK_FAILED;
  8165. }
  8166. return err;
  8167. }
  8168. static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
  8169. u64 *data)
  8170. {
  8171. struct tg3 *tp = netdev_priv(dev);
  8172. if (tp->link_config.phy_is_low_power)
  8173. tg3_set_power_state(tp, PCI_D0);
  8174. memset(data, 0, sizeof(u64) * TG3_NUM_TEST);
  8175. if (tg3_test_nvram(tp) != 0) {
  8176. etest->flags |= ETH_TEST_FL_FAILED;
  8177. data[0] = 1;
  8178. }
  8179. if (tg3_test_link(tp) != 0) {
  8180. etest->flags |= ETH_TEST_FL_FAILED;
  8181. data[1] = 1;
  8182. }
  8183. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  8184. int err, irq_sync = 0;
  8185. if (netif_running(dev)) {
  8186. tg3_netif_stop(tp);
  8187. irq_sync = 1;
  8188. }
  8189. tg3_full_lock(tp, irq_sync);
  8190. tg3_halt(tp, RESET_KIND_SUSPEND, 1);
  8191. err = tg3_nvram_lock(tp);
  8192. tg3_halt_cpu(tp, RX_CPU_BASE);
  8193. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  8194. tg3_halt_cpu(tp, TX_CPU_BASE);
  8195. if (!err)
  8196. tg3_nvram_unlock(tp);
  8197. if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
  8198. tg3_phy_reset(tp);
  8199. if (tg3_test_registers(tp) != 0) {
  8200. etest->flags |= ETH_TEST_FL_FAILED;
  8201. data[2] = 1;
  8202. }
  8203. if (tg3_test_memory(tp) != 0) {
  8204. etest->flags |= ETH_TEST_FL_FAILED;
  8205. data[3] = 1;
  8206. }
  8207. if ((data[4] = tg3_test_loopback(tp)) != 0)
  8208. etest->flags |= ETH_TEST_FL_FAILED;
  8209. tg3_full_unlock(tp);
  8210. if (tg3_test_interrupt(tp) != 0) {
  8211. etest->flags |= ETH_TEST_FL_FAILED;
  8212. data[5] = 1;
  8213. }
  8214. tg3_full_lock(tp, 0);
  8215. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  8216. if (netif_running(dev)) {
  8217. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  8218. if (!tg3_restart_hw(tp, 1))
  8219. tg3_netif_start(tp);
  8220. }
  8221. tg3_full_unlock(tp);
  8222. }
  8223. if (tp->link_config.phy_is_low_power)
  8224. tg3_set_power_state(tp, PCI_D3hot);
  8225. }
  8226. static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8227. {
  8228. struct mii_ioctl_data *data = if_mii(ifr);
  8229. struct tg3 *tp = netdev_priv(dev);
  8230. int err;
  8231. switch(cmd) {
  8232. case SIOCGMIIPHY:
  8233. data->phy_id = PHY_ADDR;
  8234. /* fallthru */
  8235. case SIOCGMIIREG: {
  8236. u32 mii_regval;
  8237. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  8238. break; /* We have no PHY */
  8239. if (tp->link_config.phy_is_low_power)
  8240. return -EAGAIN;
  8241. spin_lock_bh(&tp->lock);
  8242. err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval);
  8243. spin_unlock_bh(&tp->lock);
  8244. data->val_out = mii_regval;
  8245. return err;
  8246. }
  8247. case SIOCSMIIREG:
  8248. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  8249. break; /* We have no PHY */
  8250. if (!capable(CAP_NET_ADMIN))
  8251. return -EPERM;
  8252. if (tp->link_config.phy_is_low_power)
  8253. return -EAGAIN;
  8254. spin_lock_bh(&tp->lock);
  8255. err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in);
  8256. spin_unlock_bh(&tp->lock);
  8257. return err;
  8258. default:
  8259. /* do nothing */
  8260. break;
  8261. }
  8262. return -EOPNOTSUPP;
  8263. }
  8264. #if TG3_VLAN_TAG_USED
  8265. static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  8266. {
  8267. struct tg3 *tp = netdev_priv(dev);
  8268. if (netif_running(dev))
  8269. tg3_netif_stop(tp);
  8270. tg3_full_lock(tp, 0);
  8271. tp->vlgrp = grp;
  8272. /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
  8273. __tg3_set_rx_mode(dev);
  8274. if (netif_running(dev))
  8275. tg3_netif_start(tp);
  8276. tg3_full_unlock(tp);
  8277. }
  8278. #endif
  8279. static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  8280. {
  8281. struct tg3 *tp = netdev_priv(dev);
  8282. memcpy(ec, &tp->coal, sizeof(*ec));
  8283. return 0;
  8284. }
  8285. static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  8286. {
  8287. struct tg3 *tp = netdev_priv(dev);
  8288. u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
  8289. u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
  8290. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
  8291. max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
  8292. max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
  8293. max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
  8294. min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
  8295. }
  8296. if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
  8297. (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
  8298. (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
  8299. (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
  8300. (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
  8301. (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
  8302. (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
  8303. (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
  8304. (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
  8305. (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
  8306. return -EINVAL;
  8307. /* No rx interrupts will be generated if both are zero */
  8308. if ((ec->rx_coalesce_usecs == 0) &&
  8309. (ec->rx_max_coalesced_frames == 0))
  8310. return -EINVAL;
  8311. /* No tx interrupts will be generated if both are zero */
  8312. if ((ec->tx_coalesce_usecs == 0) &&
  8313. (ec->tx_max_coalesced_frames == 0))
  8314. return -EINVAL;
  8315. /* Only copy relevant parameters, ignore all others. */
  8316. tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
  8317. tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
  8318. tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
  8319. tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
  8320. tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
  8321. tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
  8322. tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
  8323. tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
  8324. tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
  8325. if (netif_running(dev)) {
  8326. tg3_full_lock(tp, 0);
  8327. __tg3_set_coalesce(tp, &tp->coal);
  8328. tg3_full_unlock(tp);
  8329. }
  8330. return 0;
  8331. }
  8332. static const struct ethtool_ops tg3_ethtool_ops = {
  8333. .get_settings = tg3_get_settings,
  8334. .set_settings = tg3_set_settings,
  8335. .get_drvinfo = tg3_get_drvinfo,
  8336. .get_regs_len = tg3_get_regs_len,
  8337. .get_regs = tg3_get_regs,
  8338. .get_wol = tg3_get_wol,
  8339. .set_wol = tg3_set_wol,
  8340. .get_msglevel = tg3_get_msglevel,
  8341. .set_msglevel = tg3_set_msglevel,
  8342. .nway_reset = tg3_nway_reset,
  8343. .get_link = ethtool_op_get_link,
  8344. .get_eeprom_len = tg3_get_eeprom_len,
  8345. .get_eeprom = tg3_get_eeprom,
  8346. .set_eeprom = tg3_set_eeprom,
  8347. .get_ringparam = tg3_get_ringparam,
  8348. .set_ringparam = tg3_set_ringparam,
  8349. .get_pauseparam = tg3_get_pauseparam,
  8350. .set_pauseparam = tg3_set_pauseparam,
  8351. .get_rx_csum = tg3_get_rx_csum,
  8352. .set_rx_csum = tg3_set_rx_csum,
  8353. .set_tx_csum = tg3_set_tx_csum,
  8354. .set_sg = ethtool_op_set_sg,
  8355. .set_tso = tg3_set_tso,
  8356. .self_test = tg3_self_test,
  8357. .get_strings = tg3_get_strings,
  8358. .phys_id = tg3_phys_id,
  8359. .get_ethtool_stats = tg3_get_ethtool_stats,
  8360. .get_coalesce = tg3_get_coalesce,
  8361. .set_coalesce = tg3_set_coalesce,
  8362. .get_sset_count = tg3_get_sset_count,
  8363. };
  8364. static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
  8365. {
  8366. u32 cursize, val, magic;
  8367. tp->nvram_size = EEPROM_CHIP_SIZE;
  8368. if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
  8369. return;
  8370. if ((magic != TG3_EEPROM_MAGIC) &&
  8371. ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) &&
  8372. ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW))
  8373. return;
  8374. /*
  8375. * Size the chip by reading offsets at increasing powers of two.
  8376. * When we encounter our validation signature, we know the addressing
  8377. * has wrapped around, and thus have our chip size.
  8378. */
  8379. cursize = 0x10;
  8380. while (cursize < tp->nvram_size) {
  8381. if (tg3_nvram_read_swab(tp, cursize, &val) != 0)
  8382. return;
  8383. if (val == magic)
  8384. break;
  8385. cursize <<= 1;
  8386. }
  8387. tp->nvram_size = cursize;
  8388. }
  8389. static void __devinit tg3_get_nvram_size(struct tg3 *tp)
  8390. {
  8391. u32 val;
  8392. if (tg3_nvram_read_swab(tp, 0, &val) != 0)
  8393. return;
  8394. /* Selfboot format */
  8395. if (val != TG3_EEPROM_MAGIC) {
  8396. tg3_get_eeprom_size(tp);
  8397. return;
  8398. }
  8399. if (tg3_nvram_read(tp, 0xf0, &val) == 0) {
  8400. if (val != 0) {
  8401. tp->nvram_size = (val >> 16) * 1024;
  8402. return;
  8403. }
  8404. }
  8405. tp->nvram_size = TG3_NVRAM_SIZE_512KB;
  8406. }
  8407. static void __devinit tg3_get_nvram_info(struct tg3 *tp)
  8408. {
  8409. u32 nvcfg1;
  8410. nvcfg1 = tr32(NVRAM_CFG1);
  8411. if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) {
  8412. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8413. }
  8414. else {
  8415. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8416. tw32(NVRAM_CFG1, nvcfg1);
  8417. }
  8418. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
  8419. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  8420. switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
  8421. case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
  8422. tp->nvram_jedecnum = JEDEC_ATMEL;
  8423. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  8424. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8425. break;
  8426. case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED:
  8427. tp->nvram_jedecnum = JEDEC_ATMEL;
  8428. tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE;
  8429. break;
  8430. case FLASH_VENDOR_ATMEL_EEPROM:
  8431. tp->nvram_jedecnum = JEDEC_ATMEL;
  8432. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8433. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8434. break;
  8435. case FLASH_VENDOR_ST:
  8436. tp->nvram_jedecnum = JEDEC_ST;
  8437. tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE;
  8438. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8439. break;
  8440. case FLASH_VENDOR_SAIFUN:
  8441. tp->nvram_jedecnum = JEDEC_SAIFUN;
  8442. tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE;
  8443. break;
  8444. case FLASH_VENDOR_SST_SMALL:
  8445. case FLASH_VENDOR_SST_LARGE:
  8446. tp->nvram_jedecnum = JEDEC_SST;
  8447. tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
  8448. break;
  8449. }
  8450. }
  8451. else {
  8452. tp->nvram_jedecnum = JEDEC_ATMEL;
  8453. tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE;
  8454. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8455. }
  8456. }
  8457. static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
  8458. {
  8459. u32 nvcfg1;
  8460. nvcfg1 = tr32(NVRAM_CFG1);
  8461. /* NVRAM protection for TPM */
  8462. if (nvcfg1 & (1 << 27))
  8463. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8464. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8465. case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ:
  8466. case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ:
  8467. tp->nvram_jedecnum = JEDEC_ATMEL;
  8468. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8469. break;
  8470. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8471. tp->nvram_jedecnum = JEDEC_ATMEL;
  8472. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8473. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8474. break;
  8475. case FLASH_5752VENDOR_ST_M45PE10:
  8476. case FLASH_5752VENDOR_ST_M45PE20:
  8477. case FLASH_5752VENDOR_ST_M45PE40:
  8478. tp->nvram_jedecnum = JEDEC_ST;
  8479. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8480. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8481. break;
  8482. }
  8483. if (tp->tg3_flags2 & TG3_FLG2_FLASH) {
  8484. switch (nvcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) {
  8485. case FLASH_5752PAGE_SIZE_256:
  8486. tp->nvram_pagesize = 256;
  8487. break;
  8488. case FLASH_5752PAGE_SIZE_512:
  8489. tp->nvram_pagesize = 512;
  8490. break;
  8491. case FLASH_5752PAGE_SIZE_1K:
  8492. tp->nvram_pagesize = 1024;
  8493. break;
  8494. case FLASH_5752PAGE_SIZE_2K:
  8495. tp->nvram_pagesize = 2048;
  8496. break;
  8497. case FLASH_5752PAGE_SIZE_4K:
  8498. tp->nvram_pagesize = 4096;
  8499. break;
  8500. case FLASH_5752PAGE_SIZE_264:
  8501. tp->nvram_pagesize = 264;
  8502. break;
  8503. }
  8504. }
  8505. else {
  8506. /* For eeprom, set pagesize to maximum eeprom size */
  8507. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8508. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8509. tw32(NVRAM_CFG1, nvcfg1);
  8510. }
  8511. }
  8512. static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
  8513. {
  8514. u32 nvcfg1, protect = 0;
  8515. nvcfg1 = tr32(NVRAM_CFG1);
  8516. /* NVRAM protection for TPM */
  8517. if (nvcfg1 & (1 << 27)) {
  8518. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8519. protect = 1;
  8520. }
  8521. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8522. switch (nvcfg1) {
  8523. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8524. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8525. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8526. case FLASH_5755VENDOR_ATMEL_FLASH_5:
  8527. tp->nvram_jedecnum = JEDEC_ATMEL;
  8528. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8529. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8530. tp->nvram_pagesize = 264;
  8531. if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
  8532. nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
  8533. tp->nvram_size = (protect ? 0x3e200 :
  8534. TG3_NVRAM_SIZE_512KB);
  8535. else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
  8536. tp->nvram_size = (protect ? 0x1f200 :
  8537. TG3_NVRAM_SIZE_256KB);
  8538. else
  8539. tp->nvram_size = (protect ? 0x1f200 :
  8540. TG3_NVRAM_SIZE_128KB);
  8541. break;
  8542. case FLASH_5752VENDOR_ST_M45PE10:
  8543. case FLASH_5752VENDOR_ST_M45PE20:
  8544. case FLASH_5752VENDOR_ST_M45PE40:
  8545. tp->nvram_jedecnum = JEDEC_ST;
  8546. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8547. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8548. tp->nvram_pagesize = 256;
  8549. if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
  8550. tp->nvram_size = (protect ?
  8551. TG3_NVRAM_SIZE_64KB :
  8552. TG3_NVRAM_SIZE_128KB);
  8553. else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
  8554. tp->nvram_size = (protect ?
  8555. TG3_NVRAM_SIZE_64KB :
  8556. TG3_NVRAM_SIZE_256KB);
  8557. else
  8558. tp->nvram_size = (protect ?
  8559. TG3_NVRAM_SIZE_128KB :
  8560. TG3_NVRAM_SIZE_512KB);
  8561. break;
  8562. }
  8563. }
  8564. static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
  8565. {
  8566. u32 nvcfg1;
  8567. nvcfg1 = tr32(NVRAM_CFG1);
  8568. switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
  8569. case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ:
  8570. case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ:
  8571. case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ:
  8572. case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ:
  8573. tp->nvram_jedecnum = JEDEC_ATMEL;
  8574. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8575. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8576. nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
  8577. tw32(NVRAM_CFG1, nvcfg1);
  8578. break;
  8579. case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
  8580. case FLASH_5755VENDOR_ATMEL_FLASH_1:
  8581. case FLASH_5755VENDOR_ATMEL_FLASH_2:
  8582. case FLASH_5755VENDOR_ATMEL_FLASH_3:
  8583. tp->nvram_jedecnum = JEDEC_ATMEL;
  8584. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8585. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8586. tp->nvram_pagesize = 264;
  8587. break;
  8588. case FLASH_5752VENDOR_ST_M45PE10:
  8589. case FLASH_5752VENDOR_ST_M45PE20:
  8590. case FLASH_5752VENDOR_ST_M45PE40:
  8591. tp->nvram_jedecnum = JEDEC_ST;
  8592. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8593. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8594. tp->nvram_pagesize = 256;
  8595. break;
  8596. }
  8597. }
  8598. static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp)
  8599. {
  8600. u32 nvcfg1, protect = 0;
  8601. nvcfg1 = tr32(NVRAM_CFG1);
  8602. /* NVRAM protection for TPM */
  8603. if (nvcfg1 & (1 << 27)) {
  8604. tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
  8605. protect = 1;
  8606. }
  8607. nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK;
  8608. switch (nvcfg1) {
  8609. case FLASH_5761VENDOR_ATMEL_ADB021D:
  8610. case FLASH_5761VENDOR_ATMEL_ADB041D:
  8611. case FLASH_5761VENDOR_ATMEL_ADB081D:
  8612. case FLASH_5761VENDOR_ATMEL_ADB161D:
  8613. case FLASH_5761VENDOR_ATMEL_MDB021D:
  8614. case FLASH_5761VENDOR_ATMEL_MDB041D:
  8615. case FLASH_5761VENDOR_ATMEL_MDB081D:
  8616. case FLASH_5761VENDOR_ATMEL_MDB161D:
  8617. tp->nvram_jedecnum = JEDEC_ATMEL;
  8618. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8619. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8620. tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS;
  8621. tp->nvram_pagesize = 256;
  8622. break;
  8623. case FLASH_5761VENDOR_ST_A_M45PE20:
  8624. case FLASH_5761VENDOR_ST_A_M45PE40:
  8625. case FLASH_5761VENDOR_ST_A_M45PE80:
  8626. case FLASH_5761VENDOR_ST_A_M45PE16:
  8627. case FLASH_5761VENDOR_ST_M_M45PE20:
  8628. case FLASH_5761VENDOR_ST_M_M45PE40:
  8629. case FLASH_5761VENDOR_ST_M_M45PE80:
  8630. case FLASH_5761VENDOR_ST_M_M45PE16:
  8631. tp->nvram_jedecnum = JEDEC_ST;
  8632. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8633. tp->tg3_flags2 |= TG3_FLG2_FLASH;
  8634. tp->nvram_pagesize = 256;
  8635. break;
  8636. }
  8637. if (protect) {
  8638. tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT);
  8639. } else {
  8640. switch (nvcfg1) {
  8641. case FLASH_5761VENDOR_ATMEL_ADB161D:
  8642. case FLASH_5761VENDOR_ATMEL_MDB161D:
  8643. case FLASH_5761VENDOR_ST_A_M45PE16:
  8644. case FLASH_5761VENDOR_ST_M_M45PE16:
  8645. tp->nvram_size = TG3_NVRAM_SIZE_2MB;
  8646. break;
  8647. case FLASH_5761VENDOR_ATMEL_ADB081D:
  8648. case FLASH_5761VENDOR_ATMEL_MDB081D:
  8649. case FLASH_5761VENDOR_ST_A_M45PE80:
  8650. case FLASH_5761VENDOR_ST_M_M45PE80:
  8651. tp->nvram_size = TG3_NVRAM_SIZE_1MB;
  8652. break;
  8653. case FLASH_5761VENDOR_ATMEL_ADB041D:
  8654. case FLASH_5761VENDOR_ATMEL_MDB041D:
  8655. case FLASH_5761VENDOR_ST_A_M45PE40:
  8656. case FLASH_5761VENDOR_ST_M_M45PE40:
  8657. tp->nvram_size = TG3_NVRAM_SIZE_512KB;
  8658. break;
  8659. case FLASH_5761VENDOR_ATMEL_ADB021D:
  8660. case FLASH_5761VENDOR_ATMEL_MDB021D:
  8661. case FLASH_5761VENDOR_ST_A_M45PE20:
  8662. case FLASH_5761VENDOR_ST_M_M45PE20:
  8663. tp->nvram_size = TG3_NVRAM_SIZE_256KB;
  8664. break;
  8665. }
  8666. }
  8667. }
  8668. static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp)
  8669. {
  8670. tp->nvram_jedecnum = JEDEC_ATMEL;
  8671. tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
  8672. tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
  8673. }
  8674. /* Chips other than 5700/5701 use the NVRAM for fetching info. */
  8675. static void __devinit tg3_nvram_init(struct tg3 *tp)
  8676. {
  8677. tw32_f(GRC_EEPROM_ADDR,
  8678. (EEPROM_ADDR_FSM_RESET |
  8679. (EEPROM_DEFAULT_CLOCK_PERIOD <<
  8680. EEPROM_ADDR_CLKPERD_SHIFT)));
  8681. msleep(1);
  8682. /* Enable seeprom accesses. */
  8683. tw32_f(GRC_LOCAL_CTRL,
  8684. tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM);
  8685. udelay(100);
  8686. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  8687. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
  8688. tp->tg3_flags |= TG3_FLAG_NVRAM;
  8689. if (tg3_nvram_lock(tp)) {
  8690. printk(KERN_WARNING PFX "%s: Cannot get nvarm lock, "
  8691. "tg3_nvram_init failed.\n", tp->dev->name);
  8692. return;
  8693. }
  8694. tg3_enable_nvram_access(tp);
  8695. tp->nvram_size = 0;
  8696. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  8697. tg3_get_5752_nvram_info(tp);
  8698. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  8699. tg3_get_5755_nvram_info(tp);
  8700. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  8701. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)
  8702. tg3_get_5787_nvram_info(tp);
  8703. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  8704. tg3_get_5761_nvram_info(tp);
  8705. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  8706. tg3_get_5906_nvram_info(tp);
  8707. else
  8708. tg3_get_nvram_info(tp);
  8709. if (tp->nvram_size == 0)
  8710. tg3_get_nvram_size(tp);
  8711. tg3_disable_nvram_access(tp);
  8712. tg3_nvram_unlock(tp);
  8713. } else {
  8714. tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED);
  8715. tg3_get_eeprom_size(tp);
  8716. }
  8717. }
  8718. static int tg3_nvram_read_using_eeprom(struct tg3 *tp,
  8719. u32 offset, u32 *val)
  8720. {
  8721. u32 tmp;
  8722. int i;
  8723. if (offset > EEPROM_ADDR_ADDR_MASK ||
  8724. (offset % 4) != 0)
  8725. return -EINVAL;
  8726. tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK |
  8727. EEPROM_ADDR_DEVID_MASK |
  8728. EEPROM_ADDR_READ);
  8729. tw32(GRC_EEPROM_ADDR,
  8730. tmp |
  8731. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8732. ((offset << EEPROM_ADDR_ADDR_SHIFT) &
  8733. EEPROM_ADDR_ADDR_MASK) |
  8734. EEPROM_ADDR_READ | EEPROM_ADDR_START);
  8735. for (i = 0; i < 1000; i++) {
  8736. tmp = tr32(GRC_EEPROM_ADDR);
  8737. if (tmp & EEPROM_ADDR_COMPLETE)
  8738. break;
  8739. msleep(1);
  8740. }
  8741. if (!(tmp & EEPROM_ADDR_COMPLETE))
  8742. return -EBUSY;
  8743. *val = tr32(GRC_EEPROM_DATA);
  8744. return 0;
  8745. }
  8746. #define NVRAM_CMD_TIMEOUT 10000
  8747. static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd)
  8748. {
  8749. int i;
  8750. tw32(NVRAM_CMD, nvram_cmd);
  8751. for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) {
  8752. udelay(10);
  8753. if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) {
  8754. udelay(10);
  8755. break;
  8756. }
  8757. }
  8758. if (i == NVRAM_CMD_TIMEOUT) {
  8759. return -EBUSY;
  8760. }
  8761. return 0;
  8762. }
  8763. static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr)
  8764. {
  8765. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8766. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8767. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8768. !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
  8769. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8770. addr = ((addr / tp->nvram_pagesize) <<
  8771. ATMEL_AT45DB0X1B_PAGE_POS) +
  8772. (addr % tp->nvram_pagesize);
  8773. return addr;
  8774. }
  8775. static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr)
  8776. {
  8777. if ((tp->tg3_flags & TG3_FLAG_NVRAM) &&
  8778. (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) &&
  8779. (tp->tg3_flags2 & TG3_FLG2_FLASH) &&
  8780. !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) &&
  8781. (tp->nvram_jedecnum == JEDEC_ATMEL))
  8782. addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) *
  8783. tp->nvram_pagesize) +
  8784. (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1));
  8785. return addr;
  8786. }
  8787. static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
  8788. {
  8789. int ret;
  8790. if (!(tp->tg3_flags & TG3_FLAG_NVRAM))
  8791. return tg3_nvram_read_using_eeprom(tp, offset, val);
  8792. offset = tg3_nvram_phys_addr(tp, offset);
  8793. if (offset > NVRAM_ADDR_MSK)
  8794. return -EINVAL;
  8795. ret = tg3_nvram_lock(tp);
  8796. if (ret)
  8797. return ret;
  8798. tg3_enable_nvram_access(tp);
  8799. tw32(NVRAM_ADDR, offset);
  8800. ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO |
  8801. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
  8802. if (ret == 0)
  8803. *val = swab32(tr32(NVRAM_RDDATA));
  8804. tg3_disable_nvram_access(tp);
  8805. tg3_nvram_unlock(tp);
  8806. return ret;
  8807. }
  8808. static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val)
  8809. {
  8810. u32 v;
  8811. int res = tg3_nvram_read(tp, offset, &v);
  8812. if (!res)
  8813. *val = cpu_to_le32(v);
  8814. return res;
  8815. }
  8816. static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
  8817. {
  8818. int err;
  8819. u32 tmp;
  8820. err = tg3_nvram_read(tp, offset, &tmp);
  8821. *val = swab32(tmp);
  8822. return err;
  8823. }
  8824. static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
  8825. u32 offset, u32 len, u8 *buf)
  8826. {
  8827. int i, j, rc = 0;
  8828. u32 val;
  8829. for (i = 0; i < len; i += 4) {
  8830. u32 addr;
  8831. __le32 data;
  8832. addr = offset + i;
  8833. memcpy(&data, buf + i, 4);
  8834. tw32(GRC_EEPROM_DATA, le32_to_cpu(data));
  8835. val = tr32(GRC_EEPROM_ADDR);
  8836. tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
  8837. val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK |
  8838. EEPROM_ADDR_READ);
  8839. tw32(GRC_EEPROM_ADDR, val |
  8840. (0 << EEPROM_ADDR_DEVID_SHIFT) |
  8841. (addr & EEPROM_ADDR_ADDR_MASK) |
  8842. EEPROM_ADDR_START |
  8843. EEPROM_ADDR_WRITE);
  8844. for (j = 0; j < 1000; j++) {
  8845. val = tr32(GRC_EEPROM_ADDR);
  8846. if (val & EEPROM_ADDR_COMPLETE)
  8847. break;
  8848. msleep(1);
  8849. }
  8850. if (!(val & EEPROM_ADDR_COMPLETE)) {
  8851. rc = -EBUSY;
  8852. break;
  8853. }
  8854. }
  8855. return rc;
  8856. }
  8857. /* offset and length are dword aligned */
  8858. static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
  8859. u8 *buf)
  8860. {
  8861. int ret = 0;
  8862. u32 pagesize = tp->nvram_pagesize;
  8863. u32 pagemask = pagesize - 1;
  8864. u32 nvram_cmd;
  8865. u8 *tmp;
  8866. tmp = kmalloc(pagesize, GFP_KERNEL);
  8867. if (tmp == NULL)
  8868. return -ENOMEM;
  8869. while (len) {
  8870. int j;
  8871. u32 phy_addr, page_off, size;
  8872. phy_addr = offset & ~pagemask;
  8873. for (j = 0; j < pagesize; j += 4) {
  8874. if ((ret = tg3_nvram_read_le(tp, phy_addr + j,
  8875. (__le32 *) (tmp + j))))
  8876. break;
  8877. }
  8878. if (ret)
  8879. break;
  8880. page_off = offset & pagemask;
  8881. size = pagesize;
  8882. if (len < size)
  8883. size = len;
  8884. len -= size;
  8885. memcpy(tmp + page_off, buf, size);
  8886. offset = offset + (pagesize - page_off);
  8887. tg3_enable_nvram_access(tp);
  8888. /*
  8889. * Before we can erase the flash page, we need
  8890. * to issue a special "write enable" command.
  8891. */
  8892. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8893. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8894. break;
  8895. /* Erase the target page */
  8896. tw32(NVRAM_ADDR, phy_addr);
  8897. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR |
  8898. NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE;
  8899. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8900. break;
  8901. /* Issue another write enable to start the write. */
  8902. nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8903. if (tg3_nvram_exec_cmd(tp, nvram_cmd))
  8904. break;
  8905. for (j = 0; j < pagesize; j += 4) {
  8906. __be32 data;
  8907. data = *((__be32 *) (tmp + j));
  8908. /* swab32(le32_to_cpu(data)), actually */
  8909. tw32(NVRAM_WRDATA, be32_to_cpu(data));
  8910. tw32(NVRAM_ADDR, phy_addr + j);
  8911. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE |
  8912. NVRAM_CMD_WR;
  8913. if (j == 0)
  8914. nvram_cmd |= NVRAM_CMD_FIRST;
  8915. else if (j == (pagesize - 4))
  8916. nvram_cmd |= NVRAM_CMD_LAST;
  8917. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8918. break;
  8919. }
  8920. if (ret)
  8921. break;
  8922. }
  8923. nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE;
  8924. tg3_nvram_exec_cmd(tp, nvram_cmd);
  8925. kfree(tmp);
  8926. return ret;
  8927. }
  8928. /* offset and length are dword aligned */
  8929. static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
  8930. u8 *buf)
  8931. {
  8932. int i, ret = 0;
  8933. for (i = 0; i < len; i += 4, offset += 4) {
  8934. u32 page_off, phy_addr, nvram_cmd;
  8935. __be32 data;
  8936. memcpy(&data, buf + i, 4);
  8937. tw32(NVRAM_WRDATA, be32_to_cpu(data));
  8938. page_off = offset % tp->nvram_pagesize;
  8939. phy_addr = tg3_nvram_phys_addr(tp, offset);
  8940. tw32(NVRAM_ADDR, phy_addr);
  8941. nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR;
  8942. if ((page_off == 0) || (i == 0))
  8943. nvram_cmd |= NVRAM_CMD_FIRST;
  8944. if (page_off == (tp->nvram_pagesize - 4))
  8945. nvram_cmd |= NVRAM_CMD_LAST;
  8946. if (i == (len - 4))
  8947. nvram_cmd |= NVRAM_CMD_LAST;
  8948. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
  8949. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
  8950. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
  8951. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784) &&
  8952. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) &&
  8953. (tp->nvram_jedecnum == JEDEC_ST) &&
  8954. (nvram_cmd & NVRAM_CMD_FIRST)) {
  8955. if ((ret = tg3_nvram_exec_cmd(tp,
  8956. NVRAM_CMD_WREN | NVRAM_CMD_GO |
  8957. NVRAM_CMD_DONE)))
  8958. break;
  8959. }
  8960. if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8961. /* We always do complete word writes to eeprom. */
  8962. nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST);
  8963. }
  8964. if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd)))
  8965. break;
  8966. }
  8967. return ret;
  8968. }
  8969. /* offset and length are dword aligned */
  8970. static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf)
  8971. {
  8972. int ret;
  8973. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  8974. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl &
  8975. ~GRC_LCLCTRL_GPIO_OUTPUT1);
  8976. udelay(40);
  8977. }
  8978. if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) {
  8979. ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf);
  8980. }
  8981. else {
  8982. u32 grc_mode;
  8983. ret = tg3_nvram_lock(tp);
  8984. if (ret)
  8985. return ret;
  8986. tg3_enable_nvram_access(tp);
  8987. if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
  8988. !(tp->tg3_flags2 & TG3_FLG2_PROTECTED_NVRAM))
  8989. tw32(NVRAM_WRITE1, 0x406);
  8990. grc_mode = tr32(GRC_MODE);
  8991. tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE);
  8992. if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) ||
  8993. !(tp->tg3_flags2 & TG3_FLG2_FLASH)) {
  8994. ret = tg3_nvram_write_block_buffered(tp, offset, len,
  8995. buf);
  8996. }
  8997. else {
  8998. ret = tg3_nvram_write_block_unbuffered(tp, offset, len,
  8999. buf);
  9000. }
  9001. grc_mode = tr32(GRC_MODE);
  9002. tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE);
  9003. tg3_disable_nvram_access(tp);
  9004. tg3_nvram_unlock(tp);
  9005. }
  9006. if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) {
  9007. tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl);
  9008. udelay(40);
  9009. }
  9010. return ret;
  9011. }
  9012. struct subsys_tbl_ent {
  9013. u16 subsys_vendor, subsys_devid;
  9014. u32 phy_id;
  9015. };
  9016. static struct subsys_tbl_ent subsys_id_to_phy_id[] = {
  9017. /* Broadcom boards. */
  9018. { PCI_VENDOR_ID_BROADCOM, 0x1644, PHY_ID_BCM5401 }, /* BCM95700A6 */
  9019. { PCI_VENDOR_ID_BROADCOM, 0x0001, PHY_ID_BCM5701 }, /* BCM95701A5 */
  9020. { PCI_VENDOR_ID_BROADCOM, 0x0002, PHY_ID_BCM8002 }, /* BCM95700T6 */
  9021. { PCI_VENDOR_ID_BROADCOM, 0x0003, 0 }, /* BCM95700A9 */
  9022. { PCI_VENDOR_ID_BROADCOM, 0x0005, PHY_ID_BCM5701 }, /* BCM95701T1 */
  9023. { PCI_VENDOR_ID_BROADCOM, 0x0006, PHY_ID_BCM5701 }, /* BCM95701T8 */
  9024. { PCI_VENDOR_ID_BROADCOM, 0x0007, 0 }, /* BCM95701A7 */
  9025. { PCI_VENDOR_ID_BROADCOM, 0x0008, PHY_ID_BCM5701 }, /* BCM95701A10 */
  9026. { PCI_VENDOR_ID_BROADCOM, 0x8008, PHY_ID_BCM5701 }, /* BCM95701A12 */
  9027. { PCI_VENDOR_ID_BROADCOM, 0x0009, PHY_ID_BCM5703 }, /* BCM95703Ax1 */
  9028. { PCI_VENDOR_ID_BROADCOM, 0x8009, PHY_ID_BCM5703 }, /* BCM95703Ax2 */
  9029. /* 3com boards. */
  9030. { PCI_VENDOR_ID_3COM, 0x1000, PHY_ID_BCM5401 }, /* 3C996T */
  9031. { PCI_VENDOR_ID_3COM, 0x1006, PHY_ID_BCM5701 }, /* 3C996BT */
  9032. { PCI_VENDOR_ID_3COM, 0x1004, 0 }, /* 3C996SX */
  9033. { PCI_VENDOR_ID_3COM, 0x1007, PHY_ID_BCM5701 }, /* 3C1000T */
  9034. { PCI_VENDOR_ID_3COM, 0x1008, PHY_ID_BCM5701 }, /* 3C940BR01 */
  9035. /* DELL boards. */
  9036. { PCI_VENDOR_ID_DELL, 0x00d1, PHY_ID_BCM5401 }, /* VIPER */
  9037. { PCI_VENDOR_ID_DELL, 0x0106, PHY_ID_BCM5401 }, /* JAGUAR */
  9038. { PCI_VENDOR_ID_DELL, 0x0109, PHY_ID_BCM5411 }, /* MERLOT */
  9039. { PCI_VENDOR_ID_DELL, 0x010a, PHY_ID_BCM5411 }, /* SLIM_MERLOT */
  9040. /* Compaq boards. */
  9041. { PCI_VENDOR_ID_COMPAQ, 0x007c, PHY_ID_BCM5701 }, /* BANSHEE */
  9042. { PCI_VENDOR_ID_COMPAQ, 0x009a, PHY_ID_BCM5701 }, /* BANSHEE_2 */
  9043. { PCI_VENDOR_ID_COMPAQ, 0x007d, 0 }, /* CHANGELING */
  9044. { PCI_VENDOR_ID_COMPAQ, 0x0085, PHY_ID_BCM5701 }, /* NC7780 */
  9045. { PCI_VENDOR_ID_COMPAQ, 0x0099, PHY_ID_BCM5701 }, /* NC7780_2 */
  9046. /* IBM boards. */
  9047. { PCI_VENDOR_ID_IBM, 0x0281, 0 } /* IBM??? */
  9048. };
  9049. static inline struct subsys_tbl_ent *lookup_by_subsys(struct tg3 *tp)
  9050. {
  9051. int i;
  9052. for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) {
  9053. if ((subsys_id_to_phy_id[i].subsys_vendor ==
  9054. tp->pdev->subsystem_vendor) &&
  9055. (subsys_id_to_phy_id[i].subsys_devid ==
  9056. tp->pdev->subsystem_device))
  9057. return &subsys_id_to_phy_id[i];
  9058. }
  9059. return NULL;
  9060. }
  9061. static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
  9062. {
  9063. u32 val;
  9064. u16 pmcsr;
  9065. /* On some early chips the SRAM cannot be accessed in D3hot state,
  9066. * so need make sure we're in D0.
  9067. */
  9068. pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
  9069. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  9070. pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
  9071. msleep(1);
  9072. /* Make sure register accesses (indirect or otherwise)
  9073. * will function correctly.
  9074. */
  9075. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9076. tp->misc_host_ctrl);
  9077. /* The memory arbiter has to be enabled in order for SRAM accesses
  9078. * to succeed. Normally on powerup the tg3 chip firmware will make
  9079. * sure it is enabled, but other entities such as system netboot
  9080. * code might disable it.
  9081. */
  9082. val = tr32(MEMARB_MODE);
  9083. tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
  9084. tp->phy_id = PHY_ID_INVALID;
  9085. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9086. /* Assume an onboard device and WOL capable by default. */
  9087. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP;
  9088. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9089. if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) {
  9090. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9091. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  9092. }
  9093. val = tr32(VCPU_CFGSHDW);
  9094. if (val & VCPU_CFGSHDW_ASPM_DBNC)
  9095. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  9096. if ((val & VCPU_CFGSHDW_WOL_ENABLE) &&
  9097. (val & VCPU_CFGSHDW_WOL_MAGPKT))
  9098. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  9099. return;
  9100. }
  9101. tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
  9102. if (val == NIC_SRAM_DATA_SIG_MAGIC) {
  9103. u32 nic_cfg, led_cfg;
  9104. u32 nic_phy_id, ver, cfg2 = 0, eeprom_phy_id;
  9105. int eeprom_phy_serdes = 0;
  9106. tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
  9107. tp->nic_sram_data_cfg = nic_cfg;
  9108. tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver);
  9109. ver >>= NIC_SRAM_DATA_VER_SHIFT;
  9110. if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) &&
  9111. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
  9112. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) &&
  9113. (ver > 0) && (ver < 0x100))
  9114. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2);
  9115. if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) ==
  9116. NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER)
  9117. eeprom_phy_serdes = 1;
  9118. tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id);
  9119. if (nic_phy_id != 0) {
  9120. u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK;
  9121. u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK;
  9122. eeprom_phy_id = (id1 >> 16) << 10;
  9123. eeprom_phy_id |= (id2 & 0xfc00) << 16;
  9124. eeprom_phy_id |= (id2 & 0x03ff) << 0;
  9125. } else
  9126. eeprom_phy_id = 0;
  9127. tp->phy_id = eeprom_phy_id;
  9128. if (eeprom_phy_serdes) {
  9129. if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
  9130. tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
  9131. else
  9132. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9133. }
  9134. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  9135. led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK |
  9136. SHASTA_EXT_LED_MODE_MASK);
  9137. else
  9138. led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK;
  9139. switch (led_cfg) {
  9140. default:
  9141. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1:
  9142. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9143. break;
  9144. case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2:
  9145. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  9146. break;
  9147. case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
  9148. tp->led_ctrl = LED_CTRL_MODE_MAC;
  9149. /* Default to PHY_1_MODE if 0 (MAC_MODE) is
  9150. * read on some older 5700/5701 bootcode.
  9151. */
  9152. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9153. ASIC_REV_5700 ||
  9154. GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9155. ASIC_REV_5701)
  9156. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9157. break;
  9158. case SHASTA_EXT_LED_SHARED:
  9159. tp->led_ctrl = LED_CTRL_MODE_SHARED;
  9160. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 &&
  9161. tp->pci_chip_rev_id != CHIPREV_ID_5750_A1)
  9162. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  9163. LED_CTRL_MODE_PHY_2);
  9164. break;
  9165. case SHASTA_EXT_LED_MAC:
  9166. tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC;
  9167. break;
  9168. case SHASTA_EXT_LED_COMBO:
  9169. tp->led_ctrl = LED_CTRL_MODE_COMBO;
  9170. if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0)
  9171. tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 |
  9172. LED_CTRL_MODE_PHY_2);
  9173. break;
  9174. };
  9175. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9176. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) &&
  9177. tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  9178. tp->led_ctrl = LED_CTRL_MODE_PHY_2;
  9179. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX)
  9180. tp->led_ctrl = LED_CTRL_MODE_PHY_1;
  9181. if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) {
  9182. tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
  9183. if ((tp->pdev->subsystem_vendor ==
  9184. PCI_VENDOR_ID_ARIMA) &&
  9185. (tp->pdev->subsystem_device == 0x205a ||
  9186. tp->pdev->subsystem_device == 0x2063))
  9187. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9188. } else {
  9189. tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT;
  9190. tp->tg3_flags2 |= TG3_FLG2_IS_NIC;
  9191. }
  9192. if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
  9193. tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
  9194. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
  9195. tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
  9196. }
  9197. if (nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE)
  9198. tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE;
  9199. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
  9200. !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL))
  9201. tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
  9202. if (tp->tg3_flags & TG3_FLAG_WOL_CAP &&
  9203. nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)
  9204. tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
  9205. if (cfg2 & (1 << 17))
  9206. tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING;
  9207. /* serdes signal pre-emphasis in register 0x590 set by */
  9208. /* bootcode if bit 18 is set */
  9209. if (cfg2 & (1 << 18))
  9210. tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS;
  9211. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  9212. u32 cfg3;
  9213. tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3);
  9214. if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)
  9215. tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND;
  9216. }
  9217. }
  9218. }
  9219. static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd)
  9220. {
  9221. int i;
  9222. u32 val;
  9223. tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START);
  9224. tw32(OTP_CTRL, cmd);
  9225. /* Wait for up to 1 ms for command to execute. */
  9226. for (i = 0; i < 100; i++) {
  9227. val = tr32(OTP_STATUS);
  9228. if (val & OTP_STATUS_CMD_DONE)
  9229. break;
  9230. udelay(10);
  9231. }
  9232. return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY;
  9233. }
  9234. /* Read the gphy configuration from the OTP region of the chip. The gphy
  9235. * configuration is a 32-bit value that straddles the alignment boundary.
  9236. * We do two 32-bit reads and then shift and merge the results.
  9237. */
  9238. static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp)
  9239. {
  9240. u32 bhalf_otp, thalf_otp;
  9241. tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC);
  9242. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT))
  9243. return 0;
  9244. tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1);
  9245. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
  9246. return 0;
  9247. thalf_otp = tr32(OTP_READ_DATA);
  9248. tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2);
  9249. if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ))
  9250. return 0;
  9251. bhalf_otp = tr32(OTP_READ_DATA);
  9252. return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16);
  9253. }
  9254. static int __devinit tg3_phy_probe(struct tg3 *tp)
  9255. {
  9256. u32 hw_phy_id_1, hw_phy_id_2;
  9257. u32 hw_phy_id, hw_phy_id_masked;
  9258. int err;
  9259. /* Reading the PHY ID register can conflict with ASF
  9260. * firwmare access to the PHY hardware.
  9261. */
  9262. err = 0;
  9263. if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
  9264. (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
  9265. hw_phy_id = hw_phy_id_masked = PHY_ID_INVALID;
  9266. } else {
  9267. /* Now read the physical PHY_ID from the chip and verify
  9268. * that it is sane. If it doesn't look good, we fall back
  9269. * to either the hard-coded table based PHY_ID and failing
  9270. * that the value found in the eeprom area.
  9271. */
  9272. err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1);
  9273. err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2);
  9274. hw_phy_id = (hw_phy_id_1 & 0xffff) << 10;
  9275. hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16;
  9276. hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0;
  9277. hw_phy_id_masked = hw_phy_id & PHY_ID_MASK;
  9278. }
  9279. if (!err && KNOWN_PHY_ID(hw_phy_id_masked)) {
  9280. tp->phy_id = hw_phy_id;
  9281. if (hw_phy_id_masked == PHY_ID_BCM8002)
  9282. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9283. else
  9284. tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES;
  9285. } else {
  9286. if (tp->phy_id != PHY_ID_INVALID) {
  9287. /* Do nothing, phy ID already set up in
  9288. * tg3_get_eeprom_hw_cfg().
  9289. */
  9290. } else {
  9291. struct subsys_tbl_ent *p;
  9292. /* No eeprom signature? Try the hardcoded
  9293. * subsys device table.
  9294. */
  9295. p = lookup_by_subsys(tp);
  9296. if (!p)
  9297. return -ENODEV;
  9298. tp->phy_id = p->phy_id;
  9299. if (!tp->phy_id ||
  9300. tp->phy_id == PHY_ID_BCM8002)
  9301. tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
  9302. }
  9303. }
  9304. if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) &&
  9305. !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) &&
  9306. !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
  9307. u32 bmsr, adv_reg, tg3_ctrl, mask;
  9308. tg3_readphy(tp, MII_BMSR, &bmsr);
  9309. if (!tg3_readphy(tp, MII_BMSR, &bmsr) &&
  9310. (bmsr & BMSR_LSTATUS))
  9311. goto skip_phy_reset;
  9312. err = tg3_phy_reset(tp);
  9313. if (err)
  9314. return err;
  9315. adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL |
  9316. ADVERTISE_100HALF | ADVERTISE_100FULL |
  9317. ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  9318. tg3_ctrl = 0;
  9319. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) {
  9320. tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF |
  9321. MII_TG3_CTRL_ADV_1000_FULL);
  9322. if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9323. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)
  9324. tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER |
  9325. MII_TG3_CTRL_ENABLE_AS_MASTER);
  9326. }
  9327. mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  9328. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  9329. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full);
  9330. if (!tg3_copper_is_advertising_all(tp, mask)) {
  9331. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  9332. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  9333. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  9334. tg3_writephy(tp, MII_BMCR,
  9335. BMCR_ANENABLE | BMCR_ANRESTART);
  9336. }
  9337. tg3_phy_set_wirespeed(tp);
  9338. tg3_writephy(tp, MII_ADVERTISE, adv_reg);
  9339. if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY))
  9340. tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl);
  9341. }
  9342. skip_phy_reset:
  9343. if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
  9344. err = tg3_init_5401phy_dsp(tp);
  9345. if (err)
  9346. return err;
  9347. }
  9348. if (!err && ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)) {
  9349. err = tg3_init_5401phy_dsp(tp);
  9350. }
  9351. if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
  9352. tp->link_config.advertising =
  9353. (ADVERTISED_1000baseT_Half |
  9354. ADVERTISED_1000baseT_Full |
  9355. ADVERTISED_Autoneg |
  9356. ADVERTISED_FIBRE);
  9357. if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
  9358. tp->link_config.advertising &=
  9359. ~(ADVERTISED_1000baseT_Half |
  9360. ADVERTISED_1000baseT_Full);
  9361. return err;
  9362. }
  9363. static void __devinit tg3_read_partno(struct tg3 *tp)
  9364. {
  9365. unsigned char vpd_data[256];
  9366. unsigned int i;
  9367. u32 magic;
  9368. if (tg3_nvram_read_swab(tp, 0x0, &magic))
  9369. goto out_not_found;
  9370. if (magic == TG3_EEPROM_MAGIC) {
  9371. for (i = 0; i < 256; i += 4) {
  9372. u32 tmp;
  9373. if (tg3_nvram_read(tp, 0x100 + i, &tmp))
  9374. goto out_not_found;
  9375. vpd_data[i + 0] = ((tmp >> 0) & 0xff);
  9376. vpd_data[i + 1] = ((tmp >> 8) & 0xff);
  9377. vpd_data[i + 2] = ((tmp >> 16) & 0xff);
  9378. vpd_data[i + 3] = ((tmp >> 24) & 0xff);
  9379. }
  9380. } else {
  9381. int vpd_cap;
  9382. vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
  9383. for (i = 0; i < 256; i += 4) {
  9384. u32 tmp, j = 0;
  9385. __le32 v;
  9386. u16 tmp16;
  9387. pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
  9388. i);
  9389. while (j++ < 100) {
  9390. pci_read_config_word(tp->pdev, vpd_cap +
  9391. PCI_VPD_ADDR, &tmp16);
  9392. if (tmp16 & 0x8000)
  9393. break;
  9394. msleep(1);
  9395. }
  9396. if (!(tmp16 & 0x8000))
  9397. goto out_not_found;
  9398. pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
  9399. &tmp);
  9400. v = cpu_to_le32(tmp);
  9401. memcpy(&vpd_data[i], &v, 4);
  9402. }
  9403. }
  9404. /* Now parse and find the part number. */
  9405. for (i = 0; i < 254; ) {
  9406. unsigned char val = vpd_data[i];
  9407. unsigned int block_end;
  9408. if (val == 0x82 || val == 0x91) {
  9409. i = (i + 3 +
  9410. (vpd_data[i + 1] +
  9411. (vpd_data[i + 2] << 8)));
  9412. continue;
  9413. }
  9414. if (val != 0x90)
  9415. goto out_not_found;
  9416. block_end = (i + 3 +
  9417. (vpd_data[i + 1] +
  9418. (vpd_data[i + 2] << 8)));
  9419. i += 3;
  9420. if (block_end > 256)
  9421. goto out_not_found;
  9422. while (i < (block_end - 2)) {
  9423. if (vpd_data[i + 0] == 'P' &&
  9424. vpd_data[i + 1] == 'N') {
  9425. int partno_len = vpd_data[i + 2];
  9426. i += 3;
  9427. if (partno_len > 24 || (partno_len + i) > 256)
  9428. goto out_not_found;
  9429. memcpy(tp->board_part_number,
  9430. &vpd_data[i], partno_len);
  9431. /* Success. */
  9432. return;
  9433. }
  9434. i += 3 + vpd_data[i + 2];
  9435. }
  9436. /* Part number not found. */
  9437. goto out_not_found;
  9438. }
  9439. out_not_found:
  9440. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  9441. strcpy(tp->board_part_number, "BCM95906");
  9442. else
  9443. strcpy(tp->board_part_number, "none");
  9444. }
  9445. static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset)
  9446. {
  9447. u32 val;
  9448. if (tg3_nvram_read_swab(tp, offset, &val) ||
  9449. (val & 0xfc000000) != 0x0c000000 ||
  9450. tg3_nvram_read_swab(tp, offset + 4, &val) ||
  9451. val != 0)
  9452. return 0;
  9453. return 1;
  9454. }
  9455. static void __devinit tg3_read_fw_ver(struct tg3 *tp)
  9456. {
  9457. u32 val, offset, start;
  9458. u32 ver_offset;
  9459. int i, bcnt;
  9460. if (tg3_nvram_read_swab(tp, 0, &val))
  9461. return;
  9462. if (val != TG3_EEPROM_MAGIC)
  9463. return;
  9464. if (tg3_nvram_read_swab(tp, 0xc, &offset) ||
  9465. tg3_nvram_read_swab(tp, 0x4, &start))
  9466. return;
  9467. offset = tg3_nvram_logical_addr(tp, offset);
  9468. if (!tg3_fw_img_is_valid(tp, offset) ||
  9469. tg3_nvram_read_swab(tp, offset + 8, &ver_offset))
  9470. return;
  9471. offset = offset + ver_offset - start;
  9472. for (i = 0; i < 16; i += 4) {
  9473. __le32 v;
  9474. if (tg3_nvram_read_le(tp, offset + i, &v))
  9475. return;
  9476. memcpy(tp->fw_ver + i, &v, 4);
  9477. }
  9478. if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
  9479. (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
  9480. return;
  9481. for (offset = TG3_NVM_DIR_START;
  9482. offset < TG3_NVM_DIR_END;
  9483. offset += TG3_NVM_DIRENT_SIZE) {
  9484. if (tg3_nvram_read_swab(tp, offset, &val))
  9485. return;
  9486. if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI)
  9487. break;
  9488. }
  9489. if (offset == TG3_NVM_DIR_END)
  9490. return;
  9491. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
  9492. start = 0x08000000;
  9493. else if (tg3_nvram_read_swab(tp, offset - 4, &start))
  9494. return;
  9495. if (tg3_nvram_read_swab(tp, offset + 4, &offset) ||
  9496. !tg3_fw_img_is_valid(tp, offset) ||
  9497. tg3_nvram_read_swab(tp, offset + 8, &val))
  9498. return;
  9499. offset += val - start;
  9500. bcnt = strlen(tp->fw_ver);
  9501. tp->fw_ver[bcnt++] = ',';
  9502. tp->fw_ver[bcnt++] = ' ';
  9503. for (i = 0; i < 4; i++) {
  9504. __le32 v;
  9505. if (tg3_nvram_read_le(tp, offset, &v))
  9506. return;
  9507. offset += sizeof(v);
  9508. if (bcnt > TG3_VER_SIZE - sizeof(v)) {
  9509. memcpy(&tp->fw_ver[bcnt], &v, TG3_VER_SIZE - bcnt);
  9510. break;
  9511. }
  9512. memcpy(&tp->fw_ver[bcnt], &v, sizeof(v));
  9513. bcnt += sizeof(v);
  9514. }
  9515. tp->fw_ver[TG3_VER_SIZE - 1] = 0;
  9516. }
  9517. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *);
  9518. static int __devinit tg3_get_invariants(struct tg3 *tp)
  9519. {
  9520. static struct pci_device_id write_reorder_chipsets[] = {
  9521. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  9522. PCI_DEVICE_ID_AMD_FE_GATE_700C) },
  9523. { PCI_DEVICE(PCI_VENDOR_ID_AMD,
  9524. PCI_DEVICE_ID_AMD_8131_BRIDGE) },
  9525. { PCI_DEVICE(PCI_VENDOR_ID_VIA,
  9526. PCI_DEVICE_ID_VIA_8385_0) },
  9527. { },
  9528. };
  9529. u32 misc_ctrl_reg;
  9530. u32 cacheline_sz_reg;
  9531. u32 pci_state_reg, grc_misc_cfg;
  9532. u32 val;
  9533. u16 pci_cmd;
  9534. int err, pcie_cap;
  9535. /* Force memory write invalidate off. If we leave it on,
  9536. * then on 5700_BX chips we have to enable a workaround.
  9537. * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary
  9538. * to match the cacheline size. The Broadcom driver have this
  9539. * workaround but turns MWI off all the times so never uses
  9540. * it. This seems to suggest that the workaround is insufficient.
  9541. */
  9542. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9543. pci_cmd &= ~PCI_COMMAND_INVALIDATE;
  9544. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9545. /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL
  9546. * has the register indirect write enable bit set before
  9547. * we try to access any of the MMIO registers. It is also
  9548. * critical that the PCI-X hw workaround situation is decided
  9549. * before that as well.
  9550. */
  9551. pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9552. &misc_ctrl_reg);
  9553. tp->pci_chip_rev_id = (misc_ctrl_reg >>
  9554. MISC_HOST_CTRL_CHIPREV_SHIFT);
  9555. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) {
  9556. u32 prod_id_asic_rev;
  9557. pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV,
  9558. &prod_id_asic_rev);
  9559. tp->pci_chip_rev_id = prod_id_asic_rev & PROD_ID_ASIC_REV_MASK;
  9560. }
  9561. /* Wrong chip ID in 5752 A0. This code can be removed later
  9562. * as A0 is not in production.
  9563. */
  9564. if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW)
  9565. tp->pci_chip_rev_id = CHIPREV_ID_5752_A0;
  9566. /* If we have 5702/03 A1 or A2 on certain ICH chipsets,
  9567. * we need to disable memory and use config. cycles
  9568. * only to access all registers. The 5702/03 chips
  9569. * can mistakenly decode the special cycles from the
  9570. * ICH chipsets as memory write cycles, causing corruption
  9571. * of register and memory space. Only certain ICH bridges
  9572. * will drive special cycles with non-zero data during the
  9573. * address phase which can fall within the 5703's address
  9574. * range. This is not an ICH bug as the PCI spec allows
  9575. * non-zero address during special cycles. However, only
  9576. * these ICH bridges are known to drive non-zero addresses
  9577. * during special cycles.
  9578. *
  9579. * Since special cycles do not cross PCI bridges, we only
  9580. * enable this workaround if the 5703 is on the secondary
  9581. * bus of these ICH bridges.
  9582. */
  9583. if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) ||
  9584. (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) {
  9585. static struct tg3_dev_id {
  9586. u32 vendor;
  9587. u32 device;
  9588. u32 rev;
  9589. } ich_chipsets[] = {
  9590. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8,
  9591. PCI_ANY_ID },
  9592. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8,
  9593. PCI_ANY_ID },
  9594. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11,
  9595. 0xa },
  9596. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6,
  9597. PCI_ANY_ID },
  9598. { },
  9599. };
  9600. struct tg3_dev_id *pci_id = &ich_chipsets[0];
  9601. struct pci_dev *bridge = NULL;
  9602. while (pci_id->vendor != 0) {
  9603. bridge = pci_get_device(pci_id->vendor, pci_id->device,
  9604. bridge);
  9605. if (!bridge) {
  9606. pci_id++;
  9607. continue;
  9608. }
  9609. if (pci_id->rev != PCI_ANY_ID) {
  9610. if (bridge->revision > pci_id->rev)
  9611. continue;
  9612. }
  9613. if (bridge->subordinate &&
  9614. (bridge->subordinate->number ==
  9615. tp->pdev->bus->number)) {
  9616. tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND;
  9617. pci_dev_put(bridge);
  9618. break;
  9619. }
  9620. }
  9621. }
  9622. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) {
  9623. static struct tg3_dev_id {
  9624. u32 vendor;
  9625. u32 device;
  9626. } bridge_chipsets[] = {
  9627. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 },
  9628. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 },
  9629. { },
  9630. };
  9631. struct tg3_dev_id *pci_id = &bridge_chipsets[0];
  9632. struct pci_dev *bridge = NULL;
  9633. while (pci_id->vendor != 0) {
  9634. bridge = pci_get_device(pci_id->vendor,
  9635. pci_id->device,
  9636. bridge);
  9637. if (!bridge) {
  9638. pci_id++;
  9639. continue;
  9640. }
  9641. if (bridge->subordinate &&
  9642. (bridge->subordinate->number <=
  9643. tp->pdev->bus->number) &&
  9644. (bridge->subordinate->subordinate >=
  9645. tp->pdev->bus->number)) {
  9646. tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG;
  9647. pci_dev_put(bridge);
  9648. break;
  9649. }
  9650. }
  9651. }
  9652. /* The EPB bridge inside 5714, 5715, and 5780 cannot support
  9653. * DMA addresses > 40-bit. This bridge may have other additional
  9654. * 57xx devices behind it in some 4-port NIC designs for example.
  9655. * Any tg3 device found behind the bridge will also need the 40-bit
  9656. * DMA workaround.
  9657. */
  9658. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
  9659. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  9660. tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
  9661. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  9662. tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
  9663. }
  9664. else {
  9665. struct pci_dev *bridge = NULL;
  9666. do {
  9667. bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
  9668. PCI_DEVICE_ID_SERVERWORKS_EPB,
  9669. bridge);
  9670. if (bridge && bridge->subordinate &&
  9671. (bridge->subordinate->number <=
  9672. tp->pdev->bus->number) &&
  9673. (bridge->subordinate->subordinate >=
  9674. tp->pdev->bus->number)) {
  9675. tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG;
  9676. pci_dev_put(bridge);
  9677. break;
  9678. }
  9679. } while (bridge);
  9680. }
  9681. /* Initialize misc host control in PCI block. */
  9682. tp->misc_host_ctrl |= (misc_ctrl_reg &
  9683. MISC_HOST_CTRL_CHIPREV);
  9684. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  9685. tp->misc_host_ctrl);
  9686. pci_read_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9687. &cacheline_sz_reg);
  9688. tp->pci_cacheline_sz = (cacheline_sz_reg >> 0) & 0xff;
  9689. tp->pci_lat_timer = (cacheline_sz_reg >> 8) & 0xff;
  9690. tp->pci_hdr_type = (cacheline_sz_reg >> 16) & 0xff;
  9691. tp->pci_bist = (cacheline_sz_reg >> 24) & 0xff;
  9692. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  9693. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714))
  9694. tp->pdev_peer = tg3_find_peer(tp);
  9695. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  9696. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  9697. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9698. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9699. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9700. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  9701. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  9702. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9703. tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
  9704. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
  9705. (tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
  9706. tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
  9707. if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
  9708. tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI;
  9709. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX ||
  9710. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX ||
  9711. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 &&
  9712. tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 &&
  9713. tp->pdev_peer == tp->pdev))
  9714. tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI;
  9715. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9716. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9717. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9718. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  9719. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9720. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
  9721. tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
  9722. } else {
  9723. tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG;
  9724. if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
  9725. ASIC_REV_5750 &&
  9726. tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2)
  9727. tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG;
  9728. }
  9729. }
  9730. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  9731. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9732. tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
  9733. pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP);
  9734. if (pcie_cap != 0) {
  9735. tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS;
  9736. pcie_set_readrq(tp->pdev, 4096);
  9737. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9738. u16 lnkctl;
  9739. pci_read_config_word(tp->pdev,
  9740. pcie_cap + PCI_EXP_LNKCTL,
  9741. &lnkctl);
  9742. if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN)
  9743. tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2;
  9744. }
  9745. }
  9746. /* If we have an AMD 762 or VIA K8T800 chipset, write
  9747. * reordering to the mailbox registers done by the host
  9748. * controller can cause major troubles. We read back from
  9749. * every mailbox register write to force the writes to be
  9750. * posted to the chip in order.
  9751. */
  9752. if (pci_dev_present(write_reorder_chipsets) &&
  9753. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  9754. tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
  9755. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  9756. tp->pci_lat_timer < 64) {
  9757. tp->pci_lat_timer = 64;
  9758. cacheline_sz_reg = ((tp->pci_cacheline_sz & 0xff) << 0);
  9759. cacheline_sz_reg |= ((tp->pci_lat_timer & 0xff) << 8);
  9760. cacheline_sz_reg |= ((tp->pci_hdr_type & 0xff) << 16);
  9761. cacheline_sz_reg |= ((tp->pci_bist & 0xff) << 24);
  9762. pci_write_config_dword(tp->pdev, TG3PCI_CACHELINESZ,
  9763. cacheline_sz_reg);
  9764. }
  9765. if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
  9766. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  9767. tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX);
  9768. if (!tp->pcix_cap) {
  9769. printk(KERN_ERR PFX "Cannot find PCI-X "
  9770. "capability, aborting.\n");
  9771. return -EIO;
  9772. }
  9773. }
  9774. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9775. &pci_state_reg);
  9776. if (tp->pcix_cap && (pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0) {
  9777. tp->tg3_flags |= TG3_FLAG_PCIX_MODE;
  9778. /* If this is a 5700 BX chipset, and we are in PCI-X
  9779. * mode, enable register write workaround.
  9780. *
  9781. * The workaround is to use indirect register accesses
  9782. * for all chip writes not to mailbox registers.
  9783. */
  9784. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) {
  9785. u32 pm_reg;
  9786. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  9787. /* The chip can have it's power management PCI config
  9788. * space registers clobbered due to this bug.
  9789. * So explicitly force the chip into D0 here.
  9790. */
  9791. pci_read_config_dword(tp->pdev,
  9792. tp->pm_cap + PCI_PM_CTRL,
  9793. &pm_reg);
  9794. pm_reg &= ~PCI_PM_CTRL_STATE_MASK;
  9795. pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */;
  9796. pci_write_config_dword(tp->pdev,
  9797. tp->pm_cap + PCI_PM_CTRL,
  9798. pm_reg);
  9799. /* Also, force SERR#/PERR# in PCI command. */
  9800. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9801. pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  9802. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9803. }
  9804. }
  9805. /* 5700 BX chips need to have their TX producer index mailboxes
  9806. * written twice to workaround a bug.
  9807. */
  9808. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX)
  9809. tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG;
  9810. if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0)
  9811. tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED;
  9812. if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0)
  9813. tp->tg3_flags |= TG3_FLAG_PCI_32BIT;
  9814. /* Chip-specific fixup from Broadcom driver */
  9815. if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) &&
  9816. (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) {
  9817. pci_state_reg |= PCISTATE_RETRY_SAME_DMA;
  9818. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg);
  9819. }
  9820. /* Default fast path register access methods */
  9821. tp->read32 = tg3_read32;
  9822. tp->write32 = tg3_write32;
  9823. tp->read32_mbox = tg3_read32;
  9824. tp->write32_mbox = tg3_write32;
  9825. tp->write32_tx_mbox = tg3_write32;
  9826. tp->write32_rx_mbox = tg3_write32;
  9827. /* Various workaround register access methods */
  9828. if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG)
  9829. tp->write32 = tg3_write_indirect_reg32;
  9830. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  9831. ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
  9832. tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) {
  9833. /*
  9834. * Back to back register writes can cause problems on these
  9835. * chips, the workaround is to read back all reg writes
  9836. * except those to mailbox regs.
  9837. *
  9838. * See tg3_write_indirect_reg32().
  9839. */
  9840. tp->write32 = tg3_write_flush_reg32;
  9841. }
  9842. if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) ||
  9843. (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) {
  9844. tp->write32_tx_mbox = tg3_write32_tx_mbox;
  9845. if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)
  9846. tp->write32_rx_mbox = tg3_write_flush_reg32;
  9847. }
  9848. if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) {
  9849. tp->read32 = tg3_read_indirect_reg32;
  9850. tp->write32 = tg3_write_indirect_reg32;
  9851. tp->read32_mbox = tg3_read_indirect_mbox;
  9852. tp->write32_mbox = tg3_write_indirect_mbox;
  9853. tp->write32_tx_mbox = tg3_write_indirect_mbox;
  9854. tp->write32_rx_mbox = tg3_write_indirect_mbox;
  9855. iounmap(tp->regs);
  9856. tp->regs = NULL;
  9857. pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd);
  9858. pci_cmd &= ~PCI_COMMAND_MEMORY;
  9859. pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
  9860. }
  9861. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  9862. tp->read32_mbox = tg3_read32_mbox_5906;
  9863. tp->write32_mbox = tg3_write32_mbox_5906;
  9864. tp->write32_tx_mbox = tg3_write32_mbox_5906;
  9865. tp->write32_rx_mbox = tg3_write32_mbox_5906;
  9866. }
  9867. if (tp->write32 == tg3_write_indirect_reg32 ||
  9868. ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  9869. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9870. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)))
  9871. tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
  9872. /* Get eeprom hw config before calling tg3_set_power_state().
  9873. * In particular, the TG3_FLG2_IS_NIC flag must be
  9874. * determined before calling tg3_set_power_state() so that
  9875. * we know whether or not to switch out of Vaux power.
  9876. * When the flag is set, it means that GPIO1 is used for eeprom
  9877. * write protect and also implies that it is a LOM where GPIOs
  9878. * are not used to switch power.
  9879. */
  9880. tg3_get_eeprom_hw_cfg(tp);
  9881. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  9882. /* Allow reads and writes to the
  9883. * APE register and memory space.
  9884. */
  9885. pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR |
  9886. PCISTATE_ALLOW_APE_SHMEM_WR;
  9887. pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9888. pci_state_reg);
  9889. }
  9890. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9891. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  9892. tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT;
  9893. if (tp->pci_chip_rev_id == CHIPREV_ID_5784_A0 ||
  9894. tp->pci_chip_rev_id == CHIPREV_ID_5784_A1 ||
  9895. tp->pci_chip_rev_id == CHIPREV_ID_5761_A0 ||
  9896. tp->pci_chip_rev_id == CHIPREV_ID_5761_A1)
  9897. tp->tg3_flags3 |= TG3_FLG3_5761_5784_AX_FIXES;
  9898. }
  9899. /* Set up tp->grc_local_ctrl before calling tg3_set_power_state().
  9900. * GPIO1 driven high will bring 5700's external PHY out of reset.
  9901. * It is also used as eeprom write protect on LOMs.
  9902. */
  9903. tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM;
  9904. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9905. (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT))
  9906. tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 |
  9907. GRC_LCLCTRL_GPIO_OUTPUT1);
  9908. /* Unused GPIO3 must be driven as output on 5752 because there
  9909. * are no pull-up resistors on unused GPIO pins.
  9910. */
  9911. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
  9912. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
  9913. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  9914. tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
  9915. /* Force the chip into D0. */
  9916. err = tg3_set_power_state(tp, PCI_D0);
  9917. if (err) {
  9918. printk(KERN_ERR PFX "(%s) transition to D0 failed\n",
  9919. pci_name(tp->pdev));
  9920. return err;
  9921. }
  9922. /* 5700 B0 chips do not support checksumming correctly due
  9923. * to hardware bugs.
  9924. */
  9925. if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
  9926. tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
  9927. /* Derive initial jumbo mode from MTU assigned in
  9928. * ether_setup() via the alloc_etherdev() call
  9929. */
  9930. if (tp->dev->mtu > ETH_DATA_LEN &&
  9931. !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
  9932. tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
  9933. /* Determine WakeOnLan speed to use. */
  9934. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  9935. tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 ||
  9936. tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 ||
  9937. tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) {
  9938. tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB);
  9939. } else {
  9940. tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB;
  9941. }
  9942. /* A few boards don't want Ethernet@WireSpeed phy feature */
  9943. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) ||
  9944. ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
  9945. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) &&
  9946. (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) ||
  9947. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) ||
  9948. (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
  9949. tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED;
  9950. if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX ||
  9951. GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX)
  9952. tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG;
  9953. if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0)
  9954. tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
  9955. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  9956. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  9957. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  9958. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  9959. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) {
  9960. if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 &&
  9961. tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722)
  9962. tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG;
  9963. if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M)
  9964. tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM;
  9965. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906)
  9966. tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
  9967. }
  9968. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 &&
  9969. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) {
  9970. tp->phy_otp = tg3_read_otp_phycfg(tp);
  9971. if (tp->phy_otp == 0)
  9972. tp->phy_otp = TG3_OTP_DEFAULT;
  9973. }
  9974. if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)
  9975. tp->mi_mode = MAC_MI_MODE_500KHZ_CONST;
  9976. else
  9977. tp->mi_mode = MAC_MI_MODE_BASE;
  9978. tp->coalesce_mode = 0;
  9979. if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
  9980. GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
  9981. tp->coalesce_mode |= HOSTCC_MODE_32BYTE;
  9982. /* Initialize MAC MI mode, polling disabled. */
  9983. tw32_f(MAC_MI_MODE, tp->mi_mode);
  9984. udelay(80);
  9985. /* Initialize data/descriptor byte/word swapping. */
  9986. val = tr32(GRC_MODE);
  9987. val &= GRC_MODE_HOST_STACKUP;
  9988. tw32(GRC_MODE, val | tp->grc_mode);
  9989. tg3_switch_clocks(tp);
  9990. /* Clear this out for sanity. */
  9991. tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0);
  9992. pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE,
  9993. &pci_state_reg);
  9994. if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 &&
  9995. (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) {
  9996. u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl);
  9997. if (chiprevid == CHIPREV_ID_5701_A0 ||
  9998. chiprevid == CHIPREV_ID_5701_B0 ||
  9999. chiprevid == CHIPREV_ID_5701_B2 ||
  10000. chiprevid == CHIPREV_ID_5701_B5) {
  10001. void __iomem *sram_base;
  10002. /* Write some dummy words into the SRAM status block
  10003. * area, see if it reads back correctly. If the return
  10004. * value is bad, force enable the PCIX workaround.
  10005. */
  10006. sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK;
  10007. writel(0x00000000, sram_base);
  10008. writel(0x00000000, sram_base + 4);
  10009. writel(0xffffffff, sram_base + 4);
  10010. if (readl(sram_base) != 0x00000000)
  10011. tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG;
  10012. }
  10013. }
  10014. udelay(50);
  10015. tg3_nvram_init(tp);
  10016. grc_misc_cfg = tr32(GRC_MISC_CFG);
  10017. grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK;
  10018. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  10019. (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 ||
  10020. grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M))
  10021. tp->tg3_flags2 |= TG3_FLG2_IS_5788;
  10022. if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) &&
  10023. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700))
  10024. tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS;
  10025. if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
  10026. tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD |
  10027. HOSTCC_MODE_CLRTICK_TXBD);
  10028. tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS;
  10029. pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL,
  10030. tp->misc_host_ctrl);
  10031. }
  10032. /* these are limited to 10/100 only */
  10033. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 &&
  10034. (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) ||
  10035. (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 &&
  10036. tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  10037. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 ||
  10038. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 ||
  10039. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) ||
  10040. (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM &&
  10041. (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F ||
  10042. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F ||
  10043. tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) ||
  10044. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10045. tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
  10046. err = tg3_phy_probe(tp);
  10047. if (err) {
  10048. printk(KERN_ERR PFX "(%s) phy probe failed, err %d\n",
  10049. pci_name(tp->pdev), err);
  10050. /* ... but do not return immediately ... */
  10051. }
  10052. tg3_read_partno(tp);
  10053. tg3_read_fw_ver(tp);
  10054. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) {
  10055. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  10056. } else {
  10057. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  10058. tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT;
  10059. else
  10060. tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT;
  10061. }
  10062. /* 5700 {AX,BX} chips have a broken status block link
  10063. * change bit implementation, so we must use the
  10064. * status register in those cases.
  10065. */
  10066. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700)
  10067. tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG;
  10068. else
  10069. tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG;
  10070. /* The led_ctrl is set during tg3_phy_probe, here we might
  10071. * have to force the link status polling mechanism based
  10072. * upon subsystem IDs.
  10073. */
  10074. if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  10075. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  10076. !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
  10077. tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT |
  10078. TG3_FLAG_USE_LINKCHG_REG);
  10079. }
  10080. /* For all SERDES we poll the MAC status register. */
  10081. if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
  10082. tp->tg3_flags |= TG3_FLAG_POLL_SERDES;
  10083. else
  10084. tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES;
  10085. /* All chips before 5787 can get confused if TX buffers
  10086. * straddle the 4GB address boundary in some cases.
  10087. */
  10088. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10089. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  10090. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  10091. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 ||
  10092. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10093. tp->dev->hard_start_xmit = tg3_start_xmit;
  10094. else
  10095. tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
  10096. tp->rx_offset = 2;
  10097. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 &&
  10098. (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0)
  10099. tp->rx_offset = 0;
  10100. tp->rx_std_max_post = TG3_RX_RING_SIZE;
  10101. /* Increment the rx prod index on the rx std ring by at most
  10102. * 8 for these chips to workaround hw errata.
  10103. */
  10104. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
  10105. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
  10106. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
  10107. tp->rx_std_max_post = 8;
  10108. if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND)
  10109. tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) &
  10110. PCIE_PWR_MGMT_L1_THRESH_MSK;
  10111. return err;
  10112. }
  10113. #ifdef CONFIG_SPARC
  10114. static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp)
  10115. {
  10116. struct net_device *dev = tp->dev;
  10117. struct pci_dev *pdev = tp->pdev;
  10118. struct device_node *dp = pci_device_to_OF_node(pdev);
  10119. const unsigned char *addr;
  10120. int len;
  10121. addr = of_get_property(dp, "local-mac-address", &len);
  10122. if (addr && len == 6) {
  10123. memcpy(dev->dev_addr, addr, 6);
  10124. memcpy(dev->perm_addr, dev->dev_addr, 6);
  10125. return 0;
  10126. }
  10127. return -ENODEV;
  10128. }
  10129. static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp)
  10130. {
  10131. struct net_device *dev = tp->dev;
  10132. memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
  10133. memcpy(dev->perm_addr, idprom->id_ethaddr, 6);
  10134. return 0;
  10135. }
  10136. #endif
  10137. static int __devinit tg3_get_device_address(struct tg3 *tp)
  10138. {
  10139. struct net_device *dev = tp->dev;
  10140. u32 hi, lo, mac_offset;
  10141. int addr_ok = 0;
  10142. #ifdef CONFIG_SPARC
  10143. if (!tg3_get_macaddr_sparc(tp))
  10144. return 0;
  10145. #endif
  10146. mac_offset = 0x7c;
  10147. if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) ||
  10148. (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
  10149. if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
  10150. mac_offset = 0xcc;
  10151. if (tg3_nvram_lock(tp))
  10152. tw32_f(NVRAM_CMD, NVRAM_CMD_RESET);
  10153. else
  10154. tg3_nvram_unlock(tp);
  10155. }
  10156. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)
  10157. mac_offset = 0x10;
  10158. /* First try to get it from MAC address mailbox. */
  10159. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
  10160. if ((hi >> 16) == 0x484b) {
  10161. dev->dev_addr[0] = (hi >> 8) & 0xff;
  10162. dev->dev_addr[1] = (hi >> 0) & 0xff;
  10163. tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
  10164. dev->dev_addr[2] = (lo >> 24) & 0xff;
  10165. dev->dev_addr[3] = (lo >> 16) & 0xff;
  10166. dev->dev_addr[4] = (lo >> 8) & 0xff;
  10167. dev->dev_addr[5] = (lo >> 0) & 0xff;
  10168. /* Some old bootcode may report a 0 MAC address in SRAM */
  10169. addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
  10170. }
  10171. if (!addr_ok) {
  10172. /* Next, try NVRAM. */
  10173. if (!tg3_nvram_read(tp, mac_offset + 0, &hi) &&
  10174. !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
  10175. dev->dev_addr[0] = ((hi >> 16) & 0xff);
  10176. dev->dev_addr[1] = ((hi >> 24) & 0xff);
  10177. dev->dev_addr[2] = ((lo >> 0) & 0xff);
  10178. dev->dev_addr[3] = ((lo >> 8) & 0xff);
  10179. dev->dev_addr[4] = ((lo >> 16) & 0xff);
  10180. dev->dev_addr[5] = ((lo >> 24) & 0xff);
  10181. }
  10182. /* Finally just fetch it out of the MAC control regs. */
  10183. else {
  10184. hi = tr32(MAC_ADDR_0_HIGH);
  10185. lo = tr32(MAC_ADDR_0_LOW);
  10186. dev->dev_addr[5] = lo & 0xff;
  10187. dev->dev_addr[4] = (lo >> 8) & 0xff;
  10188. dev->dev_addr[3] = (lo >> 16) & 0xff;
  10189. dev->dev_addr[2] = (lo >> 24) & 0xff;
  10190. dev->dev_addr[1] = hi & 0xff;
  10191. dev->dev_addr[0] = (hi >> 8) & 0xff;
  10192. }
  10193. }
  10194. if (!is_valid_ether_addr(&dev->dev_addr[0])) {
  10195. #ifdef CONFIG_SPARC
  10196. if (!tg3_get_default_macaddr_sparc(tp))
  10197. return 0;
  10198. #endif
  10199. return -EINVAL;
  10200. }
  10201. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  10202. return 0;
  10203. }
  10204. #define BOUNDARY_SINGLE_CACHELINE 1
  10205. #define BOUNDARY_MULTI_CACHELINE 2
  10206. static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val)
  10207. {
  10208. int cacheline_size;
  10209. u8 byte;
  10210. int goal;
  10211. pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte);
  10212. if (byte == 0)
  10213. cacheline_size = 1024;
  10214. else
  10215. cacheline_size = (int) byte * 4;
  10216. /* On 5703 and later chips, the boundary bits have no
  10217. * effect.
  10218. */
  10219. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  10220. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 &&
  10221. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
  10222. goto out;
  10223. #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
  10224. goal = BOUNDARY_MULTI_CACHELINE;
  10225. #else
  10226. #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA)
  10227. goal = BOUNDARY_SINGLE_CACHELINE;
  10228. #else
  10229. goal = 0;
  10230. #endif
  10231. #endif
  10232. if (!goal)
  10233. goto out;
  10234. /* PCI controllers on most RISC systems tend to disconnect
  10235. * when a device tries to burst across a cache-line boundary.
  10236. * Therefore, letting tg3 do so just wastes PCI bandwidth.
  10237. *
  10238. * Unfortunately, for PCI-E there are only limited
  10239. * write-side controls for this, and thus for reads
  10240. * we will still get the disconnects. We'll also waste
  10241. * these PCI cycles for both read and write for chips
  10242. * other than 5700 and 5701 which do not implement the
  10243. * boundary bits.
  10244. */
  10245. if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
  10246. !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) {
  10247. switch (cacheline_size) {
  10248. case 16:
  10249. case 32:
  10250. case 64:
  10251. case 128:
  10252. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10253. val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX |
  10254. DMA_RWCTRL_WRITE_BNDRY_128_PCIX);
  10255. } else {
  10256. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  10257. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  10258. }
  10259. break;
  10260. case 256:
  10261. val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX |
  10262. DMA_RWCTRL_WRITE_BNDRY_256_PCIX);
  10263. break;
  10264. default:
  10265. val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX |
  10266. DMA_RWCTRL_WRITE_BNDRY_384_PCIX);
  10267. break;
  10268. };
  10269. } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10270. switch (cacheline_size) {
  10271. case 16:
  10272. case 32:
  10273. case 64:
  10274. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10275. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  10276. val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE;
  10277. break;
  10278. }
  10279. /* fallthrough */
  10280. case 128:
  10281. default:
  10282. val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE;
  10283. val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE;
  10284. break;
  10285. };
  10286. } else {
  10287. switch (cacheline_size) {
  10288. case 16:
  10289. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10290. val |= (DMA_RWCTRL_READ_BNDRY_16 |
  10291. DMA_RWCTRL_WRITE_BNDRY_16);
  10292. break;
  10293. }
  10294. /* fallthrough */
  10295. case 32:
  10296. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10297. val |= (DMA_RWCTRL_READ_BNDRY_32 |
  10298. DMA_RWCTRL_WRITE_BNDRY_32);
  10299. break;
  10300. }
  10301. /* fallthrough */
  10302. case 64:
  10303. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10304. val |= (DMA_RWCTRL_READ_BNDRY_64 |
  10305. DMA_RWCTRL_WRITE_BNDRY_64);
  10306. break;
  10307. }
  10308. /* fallthrough */
  10309. case 128:
  10310. if (goal == BOUNDARY_SINGLE_CACHELINE) {
  10311. val |= (DMA_RWCTRL_READ_BNDRY_128 |
  10312. DMA_RWCTRL_WRITE_BNDRY_128);
  10313. break;
  10314. }
  10315. /* fallthrough */
  10316. case 256:
  10317. val |= (DMA_RWCTRL_READ_BNDRY_256 |
  10318. DMA_RWCTRL_WRITE_BNDRY_256);
  10319. break;
  10320. case 512:
  10321. val |= (DMA_RWCTRL_READ_BNDRY_512 |
  10322. DMA_RWCTRL_WRITE_BNDRY_512);
  10323. break;
  10324. case 1024:
  10325. default:
  10326. val |= (DMA_RWCTRL_READ_BNDRY_1024 |
  10327. DMA_RWCTRL_WRITE_BNDRY_1024);
  10328. break;
  10329. };
  10330. }
  10331. out:
  10332. return val;
  10333. }
  10334. static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device)
  10335. {
  10336. struct tg3_internal_buffer_desc test_desc;
  10337. u32 sram_dma_descs;
  10338. int i, ret;
  10339. sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE;
  10340. tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0);
  10341. tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0);
  10342. tw32(RDMAC_STATUS, 0);
  10343. tw32(WDMAC_STATUS, 0);
  10344. tw32(BUFMGR_MODE, 0);
  10345. tw32(FTQ_RESET, 0);
  10346. test_desc.addr_hi = ((u64) buf_dma) >> 32;
  10347. test_desc.addr_lo = buf_dma & 0xffffffff;
  10348. test_desc.nic_mbuf = 0x00002100;
  10349. test_desc.len = size;
  10350. /*
  10351. * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz
  10352. * the *second* time the tg3 driver was getting loaded after an
  10353. * initial scan.
  10354. *
  10355. * Broadcom tells me:
  10356. * ...the DMA engine is connected to the GRC block and a DMA
  10357. * reset may affect the GRC block in some unpredictable way...
  10358. * The behavior of resets to individual blocks has not been tested.
  10359. *
  10360. * Broadcom noted the GRC reset will also reset all sub-components.
  10361. */
  10362. if (to_device) {
  10363. test_desc.cqid_sqid = (13 << 8) | 2;
  10364. tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE);
  10365. udelay(40);
  10366. } else {
  10367. test_desc.cqid_sqid = (16 << 8) | 7;
  10368. tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE);
  10369. udelay(40);
  10370. }
  10371. test_desc.flags = 0x00000005;
  10372. for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) {
  10373. u32 val;
  10374. val = *(((u32 *)&test_desc) + i);
  10375. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR,
  10376. sram_dma_descs + (i * sizeof(u32)));
  10377. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
  10378. }
  10379. pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
  10380. if (to_device) {
  10381. tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs);
  10382. } else {
  10383. tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs);
  10384. }
  10385. ret = -ENODEV;
  10386. for (i = 0; i < 40; i++) {
  10387. u32 val;
  10388. if (to_device)
  10389. val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ);
  10390. else
  10391. val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ);
  10392. if ((val & 0xffff) == sram_dma_descs) {
  10393. ret = 0;
  10394. break;
  10395. }
  10396. udelay(100);
  10397. }
  10398. return ret;
  10399. }
  10400. #define TEST_BUFFER_SIZE 0x2000
  10401. static int __devinit tg3_test_dma(struct tg3 *tp)
  10402. {
  10403. dma_addr_t buf_dma;
  10404. u32 *buf, saved_dma_rwctrl;
  10405. int ret;
  10406. buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma);
  10407. if (!buf) {
  10408. ret = -ENOMEM;
  10409. goto out_nofree;
  10410. }
  10411. tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) |
  10412. (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT));
  10413. tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl);
  10414. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10415. /* DMA read watermark not used on PCIE */
  10416. tp->dma_rwctrl |= 0x00180000;
  10417. } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) {
  10418. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 ||
  10419. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)
  10420. tp->dma_rwctrl |= 0x003f0000;
  10421. else
  10422. tp->dma_rwctrl |= 0x003f000f;
  10423. } else {
  10424. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  10425. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) {
  10426. u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f);
  10427. u32 read_water = 0x7;
  10428. /* If the 5704 is behind the EPB bridge, we can
  10429. * do the less restrictive ONE_DMA workaround for
  10430. * better performance.
  10431. */
  10432. if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) &&
  10433. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  10434. tp->dma_rwctrl |= 0x8000;
  10435. else if (ccval == 0x6 || ccval == 0x7)
  10436. tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA;
  10437. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703)
  10438. read_water = 4;
  10439. /* Set bit 23 to enable PCIX hw bug fix */
  10440. tp->dma_rwctrl |=
  10441. (read_water << DMA_RWCTRL_READ_WATER_SHIFT) |
  10442. (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) |
  10443. (1 << 23);
  10444. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
  10445. /* 5780 always in PCIX mode */
  10446. tp->dma_rwctrl |= 0x00144000;
  10447. } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
  10448. /* 5714 always in PCIX mode */
  10449. tp->dma_rwctrl |= 0x00148000;
  10450. } else {
  10451. tp->dma_rwctrl |= 0x001b000f;
  10452. }
  10453. }
  10454. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 ||
  10455. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
  10456. tp->dma_rwctrl &= 0xfffffff0;
  10457. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10458. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
  10459. /* Remove this if it causes problems for some boards. */
  10460. tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT;
  10461. /* On 5700/5701 chips, we need to set this bit.
  10462. * Otherwise the chip will issue cacheline transactions
  10463. * to streamable DMA memory with not all the byte
  10464. * enables turned on. This is an error on several
  10465. * RISC PCI controllers, in particular sparc64.
  10466. *
  10467. * On 5703/5704 chips, this bit has been reassigned
  10468. * a different meaning. In particular, it is used
  10469. * on those chips to enable a PCI-X workaround.
  10470. */
  10471. tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE;
  10472. }
  10473. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10474. #if 0
  10475. /* Unneeded, already done by tg3_get_invariants. */
  10476. tg3_switch_clocks(tp);
  10477. #endif
  10478. ret = 0;
  10479. if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
  10480. GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701)
  10481. goto out;
  10482. /* It is best to perform DMA test with maximum write burst size
  10483. * to expose the 5700/5701 write DMA bug.
  10484. */
  10485. saved_dma_rwctrl = tp->dma_rwctrl;
  10486. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10487. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10488. while (1) {
  10489. u32 *p = buf, i;
  10490. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++)
  10491. p[i] = i;
  10492. /* Send the buffer to the chip. */
  10493. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1);
  10494. if (ret) {
  10495. printk(KERN_ERR "tg3_test_dma() Write the buffer failed %d\n", ret);
  10496. break;
  10497. }
  10498. #if 0
  10499. /* validate data reached card RAM correctly. */
  10500. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  10501. u32 val;
  10502. tg3_read_mem(tp, 0x2100 + (i*4), &val);
  10503. if (le32_to_cpu(val) != p[i]) {
  10504. printk(KERN_ERR " tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", val, i);
  10505. /* ret = -ENODEV here? */
  10506. }
  10507. p[i] = 0;
  10508. }
  10509. #endif
  10510. /* Now read it back. */
  10511. ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0);
  10512. if (ret) {
  10513. printk(KERN_ERR "tg3_test_dma() Read the buffer failed %d\n", ret);
  10514. break;
  10515. }
  10516. /* Verify it. */
  10517. for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) {
  10518. if (p[i] == i)
  10519. continue;
  10520. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  10521. DMA_RWCTRL_WRITE_BNDRY_16) {
  10522. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10523. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  10524. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10525. break;
  10526. } else {
  10527. printk(KERN_ERR "tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", p[i], i);
  10528. ret = -ENODEV;
  10529. goto out;
  10530. }
  10531. }
  10532. if (i == (TEST_BUFFER_SIZE / sizeof(u32))) {
  10533. /* Success. */
  10534. ret = 0;
  10535. break;
  10536. }
  10537. }
  10538. if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
  10539. DMA_RWCTRL_WRITE_BNDRY_16) {
  10540. static struct pci_device_id dma_wait_state_chipsets[] = {
  10541. { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
  10542. PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
  10543. { },
  10544. };
  10545. /* DMA test passed without adjusting DMA boundary,
  10546. * now look for chipsets that are known to expose the
  10547. * DMA bug without failing the test.
  10548. */
  10549. if (pci_dev_present(dma_wait_state_chipsets)) {
  10550. tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
  10551. tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
  10552. }
  10553. else
  10554. /* Safe to use the calculated DMA boundary. */
  10555. tp->dma_rwctrl = saved_dma_rwctrl;
  10556. tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
  10557. }
  10558. out:
  10559. pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma);
  10560. out_nofree:
  10561. return ret;
  10562. }
  10563. static void __devinit tg3_init_link_config(struct tg3 *tp)
  10564. {
  10565. tp->link_config.advertising =
  10566. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  10567. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
  10568. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full |
  10569. ADVERTISED_Autoneg | ADVERTISED_MII);
  10570. tp->link_config.speed = SPEED_INVALID;
  10571. tp->link_config.duplex = DUPLEX_INVALID;
  10572. tp->link_config.autoneg = AUTONEG_ENABLE;
  10573. tp->link_config.active_speed = SPEED_INVALID;
  10574. tp->link_config.active_duplex = DUPLEX_INVALID;
  10575. tp->link_config.phy_is_low_power = 0;
  10576. tp->link_config.orig_speed = SPEED_INVALID;
  10577. tp->link_config.orig_duplex = DUPLEX_INVALID;
  10578. tp->link_config.orig_autoneg = AUTONEG_INVALID;
  10579. }
  10580. static void __devinit tg3_init_bufmgr_config(struct tg3 *tp)
  10581. {
  10582. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  10583. tp->bufmgr_config.mbuf_read_dma_low_water =
  10584. DEFAULT_MB_RDMA_LOW_WATER_5705;
  10585. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10586. DEFAULT_MB_MACRX_LOW_WATER_5705;
  10587. tp->bufmgr_config.mbuf_high_water =
  10588. DEFAULT_MB_HIGH_WATER_5705;
  10589. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
  10590. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10591. DEFAULT_MB_MACRX_LOW_WATER_5906;
  10592. tp->bufmgr_config.mbuf_high_water =
  10593. DEFAULT_MB_HIGH_WATER_5906;
  10594. }
  10595. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  10596. DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780;
  10597. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  10598. DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780;
  10599. tp->bufmgr_config.mbuf_high_water_jumbo =
  10600. DEFAULT_MB_HIGH_WATER_JUMBO_5780;
  10601. } else {
  10602. tp->bufmgr_config.mbuf_read_dma_low_water =
  10603. DEFAULT_MB_RDMA_LOW_WATER;
  10604. tp->bufmgr_config.mbuf_mac_rx_low_water =
  10605. DEFAULT_MB_MACRX_LOW_WATER;
  10606. tp->bufmgr_config.mbuf_high_water =
  10607. DEFAULT_MB_HIGH_WATER;
  10608. tp->bufmgr_config.mbuf_read_dma_low_water_jumbo =
  10609. DEFAULT_MB_RDMA_LOW_WATER_JUMBO;
  10610. tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo =
  10611. DEFAULT_MB_MACRX_LOW_WATER_JUMBO;
  10612. tp->bufmgr_config.mbuf_high_water_jumbo =
  10613. DEFAULT_MB_HIGH_WATER_JUMBO;
  10614. }
  10615. tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER;
  10616. tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER;
  10617. }
  10618. static char * __devinit tg3_phy_string(struct tg3 *tp)
  10619. {
  10620. switch (tp->phy_id & PHY_ID_MASK) {
  10621. case PHY_ID_BCM5400: return "5400";
  10622. case PHY_ID_BCM5401: return "5401";
  10623. case PHY_ID_BCM5411: return "5411";
  10624. case PHY_ID_BCM5701: return "5701";
  10625. case PHY_ID_BCM5703: return "5703";
  10626. case PHY_ID_BCM5704: return "5704";
  10627. case PHY_ID_BCM5705: return "5705";
  10628. case PHY_ID_BCM5750: return "5750";
  10629. case PHY_ID_BCM5752: return "5752";
  10630. case PHY_ID_BCM5714: return "5714";
  10631. case PHY_ID_BCM5780: return "5780";
  10632. case PHY_ID_BCM5755: return "5755";
  10633. case PHY_ID_BCM5787: return "5787";
  10634. case PHY_ID_BCM5784: return "5784";
  10635. case PHY_ID_BCM5756: return "5722/5756";
  10636. case PHY_ID_BCM5906: return "5906";
  10637. case PHY_ID_BCM5761: return "5761";
  10638. case PHY_ID_BCM8002: return "8002/serdes";
  10639. case 0: return "serdes";
  10640. default: return "unknown";
  10641. };
  10642. }
  10643. static char * __devinit tg3_bus_string(struct tg3 *tp, char *str)
  10644. {
  10645. if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) {
  10646. strcpy(str, "PCI Express");
  10647. return str;
  10648. } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) {
  10649. u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f;
  10650. strcpy(str, "PCIX:");
  10651. if ((clock_ctrl == 7) ||
  10652. ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) ==
  10653. GRC_MISC_CFG_BOARD_ID_5704CIOBE))
  10654. strcat(str, "133MHz");
  10655. else if (clock_ctrl == 0)
  10656. strcat(str, "33MHz");
  10657. else if (clock_ctrl == 2)
  10658. strcat(str, "50MHz");
  10659. else if (clock_ctrl == 4)
  10660. strcat(str, "66MHz");
  10661. else if (clock_ctrl == 6)
  10662. strcat(str, "100MHz");
  10663. } else {
  10664. strcpy(str, "PCI:");
  10665. if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED)
  10666. strcat(str, "66MHz");
  10667. else
  10668. strcat(str, "33MHz");
  10669. }
  10670. if (tp->tg3_flags & TG3_FLAG_PCI_32BIT)
  10671. strcat(str, ":32-bit");
  10672. else
  10673. strcat(str, ":64-bit");
  10674. return str;
  10675. }
  10676. static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp)
  10677. {
  10678. struct pci_dev *peer;
  10679. unsigned int func, devnr = tp->pdev->devfn & ~7;
  10680. for (func = 0; func < 8; func++) {
  10681. peer = pci_get_slot(tp->pdev->bus, devnr | func);
  10682. if (peer && peer != tp->pdev)
  10683. break;
  10684. pci_dev_put(peer);
  10685. }
  10686. /* 5704 can be configured in single-port mode, set peer to
  10687. * tp->pdev in that case.
  10688. */
  10689. if (!peer) {
  10690. peer = tp->pdev;
  10691. return peer;
  10692. }
  10693. /*
  10694. * We don't need to keep the refcount elevated; there's no way
  10695. * to remove one half of this device without removing the other
  10696. */
  10697. pci_dev_put(peer);
  10698. return peer;
  10699. }
  10700. static void __devinit tg3_init_coal(struct tg3 *tp)
  10701. {
  10702. struct ethtool_coalesce *ec = &tp->coal;
  10703. memset(ec, 0, sizeof(*ec));
  10704. ec->cmd = ETHTOOL_GCOALESCE;
  10705. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS;
  10706. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS;
  10707. ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES;
  10708. ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES;
  10709. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT;
  10710. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT;
  10711. ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT;
  10712. ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT;
  10713. ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS;
  10714. if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD |
  10715. HOSTCC_MODE_CLRTICK_TXBD)) {
  10716. ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS;
  10717. ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS;
  10718. ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
  10719. ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
  10720. }
  10721. if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
  10722. ec->rx_coalesce_usecs_irq = 0;
  10723. ec->tx_coalesce_usecs_irq = 0;
  10724. ec->stats_block_coalesce_usecs = 0;
  10725. }
  10726. }
  10727. static int __devinit tg3_init_one(struct pci_dev *pdev,
  10728. const struct pci_device_id *ent)
  10729. {
  10730. static int tg3_version_printed = 0;
  10731. resource_size_t tg3reg_base;
  10732. unsigned long tg3reg_len;
  10733. struct net_device *dev;
  10734. struct tg3 *tp;
  10735. int err, pm_cap;
  10736. char str[40];
  10737. u64 dma_mask, persist_dma_mask;
  10738. DECLARE_MAC_BUF(mac);
  10739. if (tg3_version_printed++ == 0)
  10740. printk(KERN_INFO "%s", version);
  10741. err = pci_enable_device(pdev);
  10742. if (err) {
  10743. printk(KERN_ERR PFX "Cannot enable PCI device, "
  10744. "aborting.\n");
  10745. return err;
  10746. }
  10747. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10748. printk(KERN_ERR PFX "Cannot find proper PCI device "
  10749. "base address, aborting.\n");
  10750. err = -ENODEV;
  10751. goto err_out_disable_pdev;
  10752. }
  10753. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  10754. if (err) {
  10755. printk(KERN_ERR PFX "Cannot obtain PCI resources, "
  10756. "aborting.\n");
  10757. goto err_out_disable_pdev;
  10758. }
  10759. pci_set_master(pdev);
  10760. /* Find power-management capability. */
  10761. pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  10762. if (pm_cap == 0) {
  10763. printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
  10764. "aborting.\n");
  10765. err = -EIO;
  10766. goto err_out_free_res;
  10767. }
  10768. tg3reg_base = pci_resource_start(pdev, 0);
  10769. tg3reg_len = pci_resource_len(pdev, 0);
  10770. dev = alloc_etherdev(sizeof(*tp));
  10771. if (!dev) {
  10772. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  10773. err = -ENOMEM;
  10774. goto err_out_free_res;
  10775. }
  10776. SET_NETDEV_DEV(dev, &pdev->dev);
  10777. #if TG3_VLAN_TAG_USED
  10778. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  10779. dev->vlan_rx_register = tg3_vlan_rx_register;
  10780. #endif
  10781. tp = netdev_priv(dev);
  10782. tp->pdev = pdev;
  10783. tp->dev = dev;
  10784. tp->pm_cap = pm_cap;
  10785. tp->mac_mode = TG3_DEF_MAC_MODE;
  10786. tp->rx_mode = TG3_DEF_RX_MODE;
  10787. tp->tx_mode = TG3_DEF_TX_MODE;
  10788. if (tg3_debug > 0)
  10789. tp->msg_enable = tg3_debug;
  10790. else
  10791. tp->msg_enable = TG3_DEF_MSG_ENABLE;
  10792. /* The word/byte swap controls here control register access byte
  10793. * swapping. DMA data byte swapping is controlled in the GRC_MODE
  10794. * setting below.
  10795. */
  10796. tp->misc_host_ctrl =
  10797. MISC_HOST_CTRL_MASK_PCI_INT |
  10798. MISC_HOST_CTRL_WORD_SWAP |
  10799. MISC_HOST_CTRL_INDIR_ACCESS |
  10800. MISC_HOST_CTRL_PCISTATE_RW;
  10801. /* The NONFRM (non-frame) byte/word swap controls take effect
  10802. * on descriptor entries, anything which isn't packet data.
  10803. *
  10804. * The StrongARM chips on the board (one for tx, one for rx)
  10805. * are running in big-endian mode.
  10806. */
  10807. tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA |
  10808. GRC_MODE_WSWAP_NONFRM_DATA);
  10809. #ifdef __BIG_ENDIAN
  10810. tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
  10811. #endif
  10812. spin_lock_init(&tp->lock);
  10813. spin_lock_init(&tp->indirect_lock);
  10814. INIT_WORK(&tp->reset_task, tg3_reset_task);
  10815. tp->regs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10816. if (!tp->regs) {
  10817. printk(KERN_ERR PFX "Cannot map device registers, "
  10818. "aborting.\n");
  10819. err = -ENOMEM;
  10820. goto err_out_free_dev;
  10821. }
  10822. tg3_init_link_config(tp);
  10823. tp->rx_pending = TG3_DEF_RX_RING_PENDING;
  10824. tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING;
  10825. tp->tx_pending = TG3_DEF_TX_RING_PENDING;
  10826. dev->open = tg3_open;
  10827. dev->stop = tg3_close;
  10828. dev->get_stats = tg3_get_stats;
  10829. dev->set_multicast_list = tg3_set_rx_mode;
  10830. dev->set_mac_address = tg3_set_mac_addr;
  10831. dev->do_ioctl = tg3_ioctl;
  10832. dev->tx_timeout = tg3_tx_timeout;
  10833. netif_napi_add(dev, &tp->napi, tg3_poll, 64);
  10834. dev->ethtool_ops = &tg3_ethtool_ops;
  10835. dev->watchdog_timeo = TG3_TX_TIMEOUT;
  10836. dev->change_mtu = tg3_change_mtu;
  10837. dev->irq = pdev->irq;
  10838. #ifdef CONFIG_NET_POLL_CONTROLLER
  10839. dev->poll_controller = tg3_poll_controller;
  10840. #endif
  10841. err = tg3_get_invariants(tp);
  10842. if (err) {
  10843. printk(KERN_ERR PFX "Problem fetching invariants of chip, "
  10844. "aborting.\n");
  10845. goto err_out_iounmap;
  10846. }
  10847. /* The EPB bridge inside 5714, 5715, and 5780 and any
  10848. * device behind the EPB cannot support DMA addresses > 40-bit.
  10849. * On 64-bit systems with IOMMU, use 40-bit dma_mask.
  10850. * On 64-bit systems without IOMMU, use 64-bit dma_mask and
  10851. * do DMA address check in tg3_start_xmit().
  10852. */
  10853. if (tp->tg3_flags2 & TG3_FLG2_IS_5788)
  10854. persist_dma_mask = dma_mask = DMA_32BIT_MASK;
  10855. else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) {
  10856. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  10857. #ifdef CONFIG_HIGHMEM
  10858. dma_mask = DMA_64BIT_MASK;
  10859. #endif
  10860. } else
  10861. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  10862. /* Configure DMA attributes. */
  10863. if (dma_mask > DMA_32BIT_MASK) {
  10864. err = pci_set_dma_mask(pdev, dma_mask);
  10865. if (!err) {
  10866. dev->features |= NETIF_F_HIGHDMA;
  10867. err = pci_set_consistent_dma_mask(pdev,
  10868. persist_dma_mask);
  10869. if (err < 0) {
  10870. printk(KERN_ERR PFX "Unable to obtain 64 bit "
  10871. "DMA for consistent allocations\n");
  10872. goto err_out_iounmap;
  10873. }
  10874. }
  10875. }
  10876. if (err || dma_mask == DMA_32BIT_MASK) {
  10877. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  10878. if (err) {
  10879. printk(KERN_ERR PFX "No usable DMA configuration, "
  10880. "aborting.\n");
  10881. goto err_out_iounmap;
  10882. }
  10883. }
  10884. tg3_init_bufmgr_config(tp);
  10885. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10886. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
  10887. }
  10888. else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
  10889. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 ||
  10890. tp->pci_chip_rev_id == CHIPREV_ID_5705_A0 ||
  10891. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 ||
  10892. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) {
  10893. tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
  10894. } else {
  10895. tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG;
  10896. }
  10897. /* TSO is on by default on chips that support hardware TSO.
  10898. * Firmware TSO on older chips gives lower performance, so it
  10899. * is off by default, but can be enabled using ethtool.
  10900. */
  10901. if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
  10902. dev->features |= NETIF_F_TSO;
  10903. if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) &&
  10904. (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906))
  10905. dev->features |= NETIF_F_TSO6;
  10906. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  10907. dev->features |= NETIF_F_TSO_ECN;
  10908. }
  10909. if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
  10910. !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
  10911. !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) {
  10912. tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64;
  10913. tp->rx_pending = 63;
  10914. }
  10915. err = tg3_get_device_address(tp);
  10916. if (err) {
  10917. printk(KERN_ERR PFX "Could not obtain valid ethernet address, "
  10918. "aborting.\n");
  10919. goto err_out_iounmap;
  10920. }
  10921. if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
  10922. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10923. printk(KERN_ERR PFX "Cannot find proper PCI device "
  10924. "base address for APE, aborting.\n");
  10925. err = -ENODEV;
  10926. goto err_out_iounmap;
  10927. }
  10928. tg3reg_base = pci_resource_start(pdev, 2);
  10929. tg3reg_len = pci_resource_len(pdev, 2);
  10930. tp->aperegs = ioremap_nocache(tg3reg_base, tg3reg_len);
  10931. if (!tp->aperegs) {
  10932. printk(KERN_ERR PFX "Cannot map APE registers, "
  10933. "aborting.\n");
  10934. err = -ENOMEM;
  10935. goto err_out_iounmap;
  10936. }
  10937. tg3_ape_lock_init(tp);
  10938. }
  10939. /*
  10940. * Reset chip in case UNDI or EFI driver did not shutdown
  10941. * DMA self test will enable WDMAC and we'll see (spurious)
  10942. * pending DMA on the PCI bus at that point.
  10943. */
  10944. if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  10945. (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  10946. tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  10947. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  10948. }
  10949. err = tg3_test_dma(tp);
  10950. if (err) {
  10951. printk(KERN_ERR PFX "DMA engine test failed, aborting.\n");
  10952. goto err_out_apeunmap;
  10953. }
  10954. /* Tigon3 can do ipv4 only... and some chips have buggy
  10955. * checksumming.
  10956. */
  10957. if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
  10958. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  10959. if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
  10960. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
  10961. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
  10962. GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
  10963. dev->features |= NETIF_F_IPV6_CSUM;
  10964. tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
  10965. } else
  10966. tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
  10967. /* flow control autonegotiation is default behavior */
  10968. tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG;
  10969. tp->link_config.flowctrl = TG3_FLOW_CTRL_TX | TG3_FLOW_CTRL_RX;
  10970. tg3_init_coal(tp);
  10971. pci_set_drvdata(pdev, dev);
  10972. err = register_netdev(dev);
  10973. if (err) {
  10974. printk(KERN_ERR PFX "Cannot register net device, "
  10975. "aborting.\n");
  10976. goto err_out_apeunmap;
  10977. }
  10978. printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] "
  10979. "(%s) %s Ethernet %s\n",
  10980. dev->name,
  10981. tp->board_part_number,
  10982. tp->pci_chip_rev_id,
  10983. tg3_phy_string(tp),
  10984. tg3_bus_string(tp, str),
  10985. ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" :
  10986. ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" :
  10987. "10/100/1000Base-T")),
  10988. print_mac(mac, dev->dev_addr));
  10989. printk(KERN_INFO "%s: RXcsums[%d] LinkChgREG[%d] "
  10990. "MIirq[%d] ASF[%d] WireSpeed[%d] TSOcap[%d]\n",
  10991. dev->name,
  10992. (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0,
  10993. (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0,
  10994. (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0,
  10995. (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0,
  10996. (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0,
  10997. (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0);
  10998. printk(KERN_INFO "%s: dma_rwctrl[%08x] dma_mask[%d-bit]\n",
  10999. dev->name, tp->dma_rwctrl,
  11000. (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
  11001. (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
  11002. return 0;
  11003. err_out_apeunmap:
  11004. if (tp->aperegs) {
  11005. iounmap(tp->aperegs);
  11006. tp->aperegs = NULL;
  11007. }
  11008. err_out_iounmap:
  11009. if (tp->regs) {
  11010. iounmap(tp->regs);
  11011. tp->regs = NULL;
  11012. }
  11013. err_out_free_dev:
  11014. free_netdev(dev);
  11015. err_out_free_res:
  11016. pci_release_regions(pdev);
  11017. err_out_disable_pdev:
  11018. pci_disable_device(pdev);
  11019. pci_set_drvdata(pdev, NULL);
  11020. return err;
  11021. }
  11022. static void __devexit tg3_remove_one(struct pci_dev *pdev)
  11023. {
  11024. struct net_device *dev = pci_get_drvdata(pdev);
  11025. if (dev) {
  11026. struct tg3 *tp = netdev_priv(dev);
  11027. flush_scheduled_work();
  11028. unregister_netdev(dev);
  11029. if (tp->aperegs) {
  11030. iounmap(tp->aperegs);
  11031. tp->aperegs = NULL;
  11032. }
  11033. if (tp->regs) {
  11034. iounmap(tp->regs);
  11035. tp->regs = NULL;
  11036. }
  11037. free_netdev(dev);
  11038. pci_release_regions(pdev);
  11039. pci_disable_device(pdev);
  11040. pci_set_drvdata(pdev, NULL);
  11041. }
  11042. }
  11043. static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
  11044. {
  11045. struct net_device *dev = pci_get_drvdata(pdev);
  11046. struct tg3 *tp = netdev_priv(dev);
  11047. int err;
  11048. /* PCI register 4 needs to be saved whether netif_running() or not.
  11049. * MSI address and data need to be saved if using MSI and
  11050. * netif_running().
  11051. */
  11052. pci_save_state(pdev);
  11053. if (!netif_running(dev))
  11054. return 0;
  11055. flush_scheduled_work();
  11056. tg3_netif_stop(tp);
  11057. del_timer_sync(&tp->timer);
  11058. tg3_full_lock(tp, 1);
  11059. tg3_disable_ints(tp);
  11060. tg3_full_unlock(tp);
  11061. netif_device_detach(dev);
  11062. tg3_full_lock(tp, 0);
  11063. tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  11064. tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
  11065. tg3_full_unlock(tp);
  11066. err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
  11067. if (err) {
  11068. tg3_full_lock(tp, 0);
  11069. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  11070. if (tg3_restart_hw(tp, 1))
  11071. goto out;
  11072. tp->timer.expires = jiffies + tp->timer_offset;
  11073. add_timer(&tp->timer);
  11074. netif_device_attach(dev);
  11075. tg3_netif_start(tp);
  11076. out:
  11077. tg3_full_unlock(tp);
  11078. }
  11079. return err;
  11080. }
  11081. static int tg3_resume(struct pci_dev *pdev)
  11082. {
  11083. struct net_device *dev = pci_get_drvdata(pdev);
  11084. struct tg3 *tp = netdev_priv(dev);
  11085. int err;
  11086. pci_restore_state(tp->pdev);
  11087. if (!netif_running(dev))
  11088. return 0;
  11089. err = tg3_set_power_state(tp, PCI_D0);
  11090. if (err)
  11091. return err;
  11092. netif_device_attach(dev);
  11093. tg3_full_lock(tp, 0);
  11094. tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
  11095. err = tg3_restart_hw(tp, 1);
  11096. if (err)
  11097. goto out;
  11098. tp->timer.expires = jiffies + tp->timer_offset;
  11099. add_timer(&tp->timer);
  11100. tg3_netif_start(tp);
  11101. out:
  11102. tg3_full_unlock(tp);
  11103. return err;
  11104. }
  11105. static struct pci_driver tg3_driver = {
  11106. .name = DRV_MODULE_NAME,
  11107. .id_table = tg3_pci_tbl,
  11108. .probe = tg3_init_one,
  11109. .remove = __devexit_p(tg3_remove_one),
  11110. .suspend = tg3_suspend,
  11111. .resume = tg3_resume
  11112. };
  11113. static int __init tg3_init(void)
  11114. {
  11115. return pci_register_driver(&tg3_driver);
  11116. }
  11117. static void __exit tg3_cleanup(void)
  11118. {
  11119. pci_unregister_driver(&tg3_driver);
  11120. }
  11121. module_init(tg3_init);
  11122. module_exit(tg3_cleanup);