tg3.c 332 KB

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