tg3.c 337 KB

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