tg3.c 308 KB

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