tg3.c 337 KB

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