e1000_hw.c 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2006 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. */
  21. /* e1000_hw.c
  22. * Shared functions for accessing and configuring the MAC
  23. */
  24. #include "e1000.h"
  25. static s32 e1000_check_downshift(struct e1000_hw *hw);
  26. static s32 e1000_check_polarity(struct e1000_hw *hw,
  27. e1000_rev_polarity *polarity);
  28. static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
  29. static void e1000_clear_vfta(struct e1000_hw *hw);
  30. static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  31. bool link_up);
  32. static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
  33. static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
  34. static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
  35. static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
  36. u16 *max_length);
  37. static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
  38. static s32 e1000_id_led_init(struct e1000_hw *hw);
  39. static void e1000_init_rx_addrs(struct e1000_hw *hw);
  40. static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
  41. struct e1000_phy_info *phy_info);
  42. static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
  43. struct e1000_phy_info *phy_info);
  44. static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
  45. static s32 e1000_wait_autoneg(struct e1000_hw *hw);
  46. static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
  47. static s32 e1000_set_phy_type(struct e1000_hw *hw);
  48. static void e1000_phy_init_script(struct e1000_hw *hw);
  49. static s32 e1000_setup_copper_link(struct e1000_hw *hw);
  50. static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
  51. static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
  52. static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  53. static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
  54. static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
  55. static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
  56. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
  57. static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
  58. static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
  59. static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
  60. u16 words, u16 *data);
  61. static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
  62. u16 words, u16 *data);
  63. static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
  64. static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
  65. static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
  66. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
  67. static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
  68. u16 phy_data);
  69. static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
  70. u16 *phy_data);
  71. static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
  72. static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
  73. static void e1000_release_eeprom(struct e1000_hw *hw);
  74. static void e1000_standby_eeprom(struct e1000_hw *hw);
  75. static s32 e1000_set_vco_speed(struct e1000_hw *hw);
  76. static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
  77. static s32 e1000_set_phy_mode(struct e1000_hw *hw);
  78. static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
  79. u16 *data);
  80. static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
  81. u16 *data);
  82. /* IGP cable length table */
  83. static const
  84. u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
  85. 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  86. 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
  87. 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
  88. 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
  89. 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
  90. 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
  91. 100,
  92. 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
  93. 110, 110,
  94. 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
  95. 120, 120
  96. };
  97. static DEFINE_SPINLOCK(e1000_eeprom_lock);
  98. static DEFINE_SPINLOCK(e1000_phy_lock);
  99. /**
  100. * e1000_set_phy_type - Set the phy type member in the hw struct.
  101. * @hw: Struct containing variables accessed by shared code
  102. */
  103. static s32 e1000_set_phy_type(struct e1000_hw *hw)
  104. {
  105. e_dbg("e1000_set_phy_type");
  106. if (hw->mac_type == e1000_undefined)
  107. return -E1000_ERR_PHY_TYPE;
  108. switch (hw->phy_id) {
  109. case M88E1000_E_PHY_ID:
  110. case M88E1000_I_PHY_ID:
  111. case M88E1011_I_PHY_ID:
  112. case M88E1111_I_PHY_ID:
  113. case M88E1118_E_PHY_ID:
  114. hw->phy_type = e1000_phy_m88;
  115. break;
  116. case IGP01E1000_I_PHY_ID:
  117. if (hw->mac_type == e1000_82541 ||
  118. hw->mac_type == e1000_82541_rev_2 ||
  119. hw->mac_type == e1000_82547 ||
  120. hw->mac_type == e1000_82547_rev_2)
  121. hw->phy_type = e1000_phy_igp;
  122. break;
  123. case RTL8211B_PHY_ID:
  124. hw->phy_type = e1000_phy_8211;
  125. break;
  126. case RTL8201N_PHY_ID:
  127. hw->phy_type = e1000_phy_8201;
  128. break;
  129. default:
  130. /* Should never have loaded on this device */
  131. hw->phy_type = e1000_phy_undefined;
  132. return -E1000_ERR_PHY_TYPE;
  133. }
  134. return E1000_SUCCESS;
  135. }
  136. /**
  137. * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
  138. * @hw: Struct containing variables accessed by shared code
  139. */
  140. static void e1000_phy_init_script(struct e1000_hw *hw)
  141. {
  142. u32 ret_val;
  143. u16 phy_saved_data;
  144. e_dbg("e1000_phy_init_script");
  145. if (hw->phy_init_script) {
  146. msleep(20);
  147. /* Save off the current value of register 0x2F5B to be restored
  148. * at the end of this routine.
  149. */
  150. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  151. /* Disabled the PHY transmitter */
  152. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  153. msleep(20);
  154. e1000_write_phy_reg(hw, 0x0000, 0x0140);
  155. msleep(5);
  156. switch (hw->mac_type) {
  157. case e1000_82541:
  158. case e1000_82547:
  159. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  160. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  161. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  162. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  163. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  164. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  165. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  166. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  167. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  168. break;
  169. case e1000_82541_rev_2:
  170. case e1000_82547_rev_2:
  171. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  172. break;
  173. default:
  174. break;
  175. }
  176. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  177. msleep(20);
  178. /* Now enable the transmitter */
  179. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  180. if (hw->mac_type == e1000_82547) {
  181. u16 fused, fine, coarse;
  182. /* Move to analog registers page */
  183. e1000_read_phy_reg(hw,
  184. IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
  185. &fused);
  186. if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  187. e1000_read_phy_reg(hw,
  188. IGP01E1000_ANALOG_FUSE_STATUS,
  189. &fused);
  190. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  191. coarse =
  192. fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  193. if (coarse >
  194. IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  195. coarse -=
  196. IGP01E1000_ANALOG_FUSE_COARSE_10;
  197. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  198. } else if (coarse ==
  199. IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  200. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  201. fused =
  202. (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  203. (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  204. (coarse &
  205. IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  206. e1000_write_phy_reg(hw,
  207. IGP01E1000_ANALOG_FUSE_CONTROL,
  208. fused);
  209. e1000_write_phy_reg(hw,
  210. IGP01E1000_ANALOG_FUSE_BYPASS,
  211. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  212. }
  213. }
  214. }
  215. }
  216. /**
  217. * e1000_set_mac_type - Set the mac type member in the hw struct.
  218. * @hw: Struct containing variables accessed by shared code
  219. */
  220. s32 e1000_set_mac_type(struct e1000_hw *hw)
  221. {
  222. e_dbg("e1000_set_mac_type");
  223. switch (hw->device_id) {
  224. case E1000_DEV_ID_82542:
  225. switch (hw->revision_id) {
  226. case E1000_82542_2_0_REV_ID:
  227. hw->mac_type = e1000_82542_rev2_0;
  228. break;
  229. case E1000_82542_2_1_REV_ID:
  230. hw->mac_type = e1000_82542_rev2_1;
  231. break;
  232. default:
  233. /* Invalid 82542 revision ID */
  234. return -E1000_ERR_MAC_TYPE;
  235. }
  236. break;
  237. case E1000_DEV_ID_82543GC_FIBER:
  238. case E1000_DEV_ID_82543GC_COPPER:
  239. hw->mac_type = e1000_82543;
  240. break;
  241. case E1000_DEV_ID_82544EI_COPPER:
  242. case E1000_DEV_ID_82544EI_FIBER:
  243. case E1000_DEV_ID_82544GC_COPPER:
  244. case E1000_DEV_ID_82544GC_LOM:
  245. hw->mac_type = e1000_82544;
  246. break;
  247. case E1000_DEV_ID_82540EM:
  248. case E1000_DEV_ID_82540EM_LOM:
  249. case E1000_DEV_ID_82540EP:
  250. case E1000_DEV_ID_82540EP_LOM:
  251. case E1000_DEV_ID_82540EP_LP:
  252. hw->mac_type = e1000_82540;
  253. break;
  254. case E1000_DEV_ID_82545EM_COPPER:
  255. case E1000_DEV_ID_82545EM_FIBER:
  256. hw->mac_type = e1000_82545;
  257. break;
  258. case E1000_DEV_ID_82545GM_COPPER:
  259. case E1000_DEV_ID_82545GM_FIBER:
  260. case E1000_DEV_ID_82545GM_SERDES:
  261. hw->mac_type = e1000_82545_rev_3;
  262. break;
  263. case E1000_DEV_ID_82546EB_COPPER:
  264. case E1000_DEV_ID_82546EB_FIBER:
  265. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  266. hw->mac_type = e1000_82546;
  267. break;
  268. case E1000_DEV_ID_82546GB_COPPER:
  269. case E1000_DEV_ID_82546GB_FIBER:
  270. case E1000_DEV_ID_82546GB_SERDES:
  271. case E1000_DEV_ID_82546GB_PCIE:
  272. case E1000_DEV_ID_82546GB_QUAD_COPPER:
  273. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  274. hw->mac_type = e1000_82546_rev_3;
  275. break;
  276. case E1000_DEV_ID_82541EI:
  277. case E1000_DEV_ID_82541EI_MOBILE:
  278. case E1000_DEV_ID_82541ER_LOM:
  279. hw->mac_type = e1000_82541;
  280. break;
  281. case E1000_DEV_ID_82541ER:
  282. case E1000_DEV_ID_82541GI:
  283. case E1000_DEV_ID_82541GI_LF:
  284. case E1000_DEV_ID_82541GI_MOBILE:
  285. hw->mac_type = e1000_82541_rev_2;
  286. break;
  287. case E1000_DEV_ID_82547EI:
  288. case E1000_DEV_ID_82547EI_MOBILE:
  289. hw->mac_type = e1000_82547;
  290. break;
  291. case E1000_DEV_ID_82547GI:
  292. hw->mac_type = e1000_82547_rev_2;
  293. break;
  294. case E1000_DEV_ID_INTEL_CE4100_GBE:
  295. hw->mac_type = e1000_ce4100;
  296. break;
  297. default:
  298. /* Should never have loaded on this device */
  299. return -E1000_ERR_MAC_TYPE;
  300. }
  301. switch (hw->mac_type) {
  302. case e1000_82541:
  303. case e1000_82547:
  304. case e1000_82541_rev_2:
  305. case e1000_82547_rev_2:
  306. hw->asf_firmware_present = true;
  307. break;
  308. default:
  309. break;
  310. }
  311. /* The 82543 chip does not count tx_carrier_errors properly in
  312. * FD mode
  313. */
  314. if (hw->mac_type == e1000_82543)
  315. hw->bad_tx_carr_stats_fd = true;
  316. if (hw->mac_type > e1000_82544)
  317. hw->has_smbus = true;
  318. return E1000_SUCCESS;
  319. }
  320. /**
  321. * e1000_set_media_type - Set media type and TBI compatibility.
  322. * @hw: Struct containing variables accessed by shared code
  323. */
  324. void e1000_set_media_type(struct e1000_hw *hw)
  325. {
  326. u32 status;
  327. e_dbg("e1000_set_media_type");
  328. if (hw->mac_type != e1000_82543) {
  329. /* tbi_compatibility is only valid on 82543 */
  330. hw->tbi_compatibility_en = false;
  331. }
  332. switch (hw->device_id) {
  333. case E1000_DEV_ID_82545GM_SERDES:
  334. case E1000_DEV_ID_82546GB_SERDES:
  335. hw->media_type = e1000_media_type_internal_serdes;
  336. break;
  337. default:
  338. switch (hw->mac_type) {
  339. case e1000_82542_rev2_0:
  340. case e1000_82542_rev2_1:
  341. hw->media_type = e1000_media_type_fiber;
  342. break;
  343. case e1000_ce4100:
  344. hw->media_type = e1000_media_type_copper;
  345. break;
  346. default:
  347. status = er32(STATUS);
  348. if (status & E1000_STATUS_TBIMODE) {
  349. hw->media_type = e1000_media_type_fiber;
  350. /* tbi_compatibility not valid on fiber */
  351. hw->tbi_compatibility_en = false;
  352. } else {
  353. hw->media_type = e1000_media_type_copper;
  354. }
  355. break;
  356. }
  357. }
  358. }
  359. /**
  360. * e1000_reset_hw - reset the hardware completely
  361. * @hw: Struct containing variables accessed by shared code
  362. *
  363. * Reset the transmit and receive units; mask and clear all interrupts.
  364. */
  365. s32 e1000_reset_hw(struct e1000_hw *hw)
  366. {
  367. u32 ctrl;
  368. u32 ctrl_ext;
  369. u32 icr;
  370. u32 manc;
  371. u32 led_ctrl;
  372. s32 ret_val;
  373. e_dbg("e1000_reset_hw");
  374. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  375. if (hw->mac_type == e1000_82542_rev2_0) {
  376. e_dbg("Disabling MWI on 82542 rev 2.0\n");
  377. e1000_pci_clear_mwi(hw);
  378. }
  379. /* Clear interrupt mask to stop board from generating interrupts */
  380. e_dbg("Masking off all interrupts\n");
  381. ew32(IMC, 0xffffffff);
  382. /* Disable the Transmit and Receive units. Then delay to allow
  383. * any pending transactions to complete before we hit the MAC with
  384. * the global reset.
  385. */
  386. ew32(RCTL, 0);
  387. ew32(TCTL, E1000_TCTL_PSP);
  388. E1000_WRITE_FLUSH();
  389. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  390. hw->tbi_compatibility_on = false;
  391. /* Delay to allow any outstanding PCI transactions to complete before
  392. * resetting the device
  393. */
  394. msleep(10);
  395. ctrl = er32(CTRL);
  396. /* Must reset the PHY before resetting the MAC */
  397. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  398. ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
  399. E1000_WRITE_FLUSH();
  400. msleep(5);
  401. }
  402. /* Issue a global reset to the MAC. This will reset the chip's
  403. * transmit, receive, DMA, and link units. It will not effect
  404. * the current PCI configuration. The global reset bit is self-
  405. * clearing, and should clear within a microsecond.
  406. */
  407. e_dbg("Issuing a global reset to MAC\n");
  408. switch (hw->mac_type) {
  409. case e1000_82544:
  410. case e1000_82540:
  411. case e1000_82545:
  412. case e1000_82546:
  413. case e1000_82541:
  414. case e1000_82541_rev_2:
  415. /* These controllers can't ack the 64-bit write when issuing the
  416. * reset, so use IO-mapping as a workaround to issue the reset
  417. */
  418. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  419. break;
  420. case e1000_82545_rev_3:
  421. case e1000_82546_rev_3:
  422. /* Reset is performed on a shadow of the control register */
  423. ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
  424. break;
  425. case e1000_ce4100:
  426. default:
  427. ew32(CTRL, (ctrl | E1000_CTRL_RST));
  428. break;
  429. }
  430. /* After MAC reset, force reload of EEPROM to restore power-on settings
  431. * to device. Later controllers reload the EEPROM automatically, so
  432. * just wait for reload to complete.
  433. */
  434. switch (hw->mac_type) {
  435. case e1000_82542_rev2_0:
  436. case e1000_82542_rev2_1:
  437. case e1000_82543:
  438. case e1000_82544:
  439. /* Wait for reset to complete */
  440. udelay(10);
  441. ctrl_ext = er32(CTRL_EXT);
  442. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  443. ew32(CTRL_EXT, ctrl_ext);
  444. E1000_WRITE_FLUSH();
  445. /* Wait for EEPROM reload */
  446. msleep(2);
  447. break;
  448. case e1000_82541:
  449. case e1000_82541_rev_2:
  450. case e1000_82547:
  451. case e1000_82547_rev_2:
  452. /* Wait for EEPROM reload */
  453. msleep(20);
  454. break;
  455. default:
  456. /* Auto read done will delay 5ms or poll based on mac type */
  457. ret_val = e1000_get_auto_rd_done(hw);
  458. if (ret_val)
  459. return ret_val;
  460. break;
  461. }
  462. /* Disable HW ARPs on ASF enabled adapters */
  463. if (hw->mac_type >= e1000_82540) {
  464. manc = er32(MANC);
  465. manc &= ~(E1000_MANC_ARP_EN);
  466. ew32(MANC, manc);
  467. }
  468. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  469. e1000_phy_init_script(hw);
  470. /* Configure activity LED after PHY reset */
  471. led_ctrl = er32(LEDCTL);
  472. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  473. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  474. ew32(LEDCTL, led_ctrl);
  475. }
  476. /* Clear interrupt mask to stop board from generating interrupts */
  477. e_dbg("Masking off all interrupts\n");
  478. ew32(IMC, 0xffffffff);
  479. /* Clear any pending interrupt events. */
  480. icr = er32(ICR);
  481. /* If MWI was previously enabled, reenable it. */
  482. if (hw->mac_type == e1000_82542_rev2_0) {
  483. if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
  484. e1000_pci_set_mwi(hw);
  485. }
  486. return E1000_SUCCESS;
  487. }
  488. /**
  489. * e1000_init_hw - Performs basic configuration of the adapter.
  490. * @hw: Struct containing variables accessed by shared code
  491. *
  492. * Assumes that the controller has previously been reset and is in a
  493. * post-reset uninitialized state. Initializes the receive address registers,
  494. * multicast table, and VLAN filter table. Calls routines to setup link
  495. * configuration and flow control settings. Clears all on-chip counters. Leaves
  496. * the transmit and receive units disabled and uninitialized.
  497. */
  498. s32 e1000_init_hw(struct e1000_hw *hw)
  499. {
  500. u32 ctrl;
  501. u32 i;
  502. s32 ret_val;
  503. u32 mta_size;
  504. u32 ctrl_ext;
  505. e_dbg("e1000_init_hw");
  506. /* Initialize Identification LED */
  507. ret_val = e1000_id_led_init(hw);
  508. if (ret_val) {
  509. e_dbg("Error Initializing Identification LED\n");
  510. return ret_val;
  511. }
  512. /* Set the media type and TBI compatibility */
  513. e1000_set_media_type(hw);
  514. /* Disabling VLAN filtering. */
  515. e_dbg("Initializing the IEEE VLAN\n");
  516. if (hw->mac_type < e1000_82545_rev_3)
  517. ew32(VET, 0);
  518. e1000_clear_vfta(hw);
  519. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  520. if (hw->mac_type == e1000_82542_rev2_0) {
  521. e_dbg("Disabling MWI on 82542 rev 2.0\n");
  522. e1000_pci_clear_mwi(hw);
  523. ew32(RCTL, E1000_RCTL_RST);
  524. E1000_WRITE_FLUSH();
  525. msleep(5);
  526. }
  527. /* Setup the receive address. This involves initializing all of the
  528. * Receive Address Registers (RARs 0 - 15).
  529. */
  530. e1000_init_rx_addrs(hw);
  531. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  532. if (hw->mac_type == e1000_82542_rev2_0) {
  533. ew32(RCTL, 0);
  534. E1000_WRITE_FLUSH();
  535. msleep(1);
  536. if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
  537. e1000_pci_set_mwi(hw);
  538. }
  539. /* Zero out the Multicast HASH table */
  540. e_dbg("Zeroing the MTA\n");
  541. mta_size = E1000_MC_TBL_SIZE;
  542. for (i = 0; i < mta_size; i++) {
  543. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  544. /* use write flush to prevent Memory Write Block (MWB) from
  545. * occurring when accessing our register space
  546. */
  547. E1000_WRITE_FLUSH();
  548. }
  549. /* Set the PCI priority bit correctly in the CTRL register. This
  550. * determines if the adapter gives priority to receives, or if it
  551. * gives equal priority to transmits and receives. Valid only on
  552. * 82542 and 82543 silicon.
  553. */
  554. if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
  555. ctrl = er32(CTRL);
  556. ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
  557. }
  558. switch (hw->mac_type) {
  559. case e1000_82545_rev_3:
  560. case e1000_82546_rev_3:
  561. break;
  562. default:
  563. /* Workaround for PCI-X problem when BIOS sets MMRBC
  564. * incorrectly.
  565. */
  566. if (hw->bus_type == e1000_bus_type_pcix
  567. && e1000_pcix_get_mmrbc(hw) > 2048)
  568. e1000_pcix_set_mmrbc(hw, 2048);
  569. break;
  570. }
  571. /* Call a subroutine to configure the link and setup flow control. */
  572. ret_val = e1000_setup_link(hw);
  573. /* Set the transmit descriptor write-back policy */
  574. if (hw->mac_type > e1000_82544) {
  575. ctrl = er32(TXDCTL);
  576. ctrl =
  577. (ctrl & ~E1000_TXDCTL_WTHRESH) |
  578. E1000_TXDCTL_FULL_TX_DESC_WB;
  579. ew32(TXDCTL, ctrl);
  580. }
  581. /* Clear all of the statistics registers (clear on read). It is
  582. * important that we do this after we have tried to establish link
  583. * because the symbol error count will increment wildly if there
  584. * is no link.
  585. */
  586. e1000_clear_hw_cntrs(hw);
  587. if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
  588. hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
  589. ctrl_ext = er32(CTRL_EXT);
  590. /* Relaxed ordering must be disabled to avoid a parity
  591. * error crash in a PCI slot.
  592. */
  593. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  594. ew32(CTRL_EXT, ctrl_ext);
  595. }
  596. return ret_val;
  597. }
  598. /**
  599. * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
  600. * @hw: Struct containing variables accessed by shared code.
  601. */
  602. static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
  603. {
  604. u16 eeprom_data;
  605. s32 ret_val;
  606. e_dbg("e1000_adjust_serdes_amplitude");
  607. if (hw->media_type != e1000_media_type_internal_serdes)
  608. return E1000_SUCCESS;
  609. switch (hw->mac_type) {
  610. case e1000_82545_rev_3:
  611. case e1000_82546_rev_3:
  612. break;
  613. default:
  614. return E1000_SUCCESS;
  615. }
  616. ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
  617. &eeprom_data);
  618. if (ret_val) {
  619. return ret_val;
  620. }
  621. if (eeprom_data != EEPROM_RESERVED_WORD) {
  622. /* Adjust SERDES output amplitude only. */
  623. eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
  624. ret_val =
  625. e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
  626. if (ret_val)
  627. return ret_val;
  628. }
  629. return E1000_SUCCESS;
  630. }
  631. /**
  632. * e1000_setup_link - Configures flow control and link settings.
  633. * @hw: Struct containing variables accessed by shared code
  634. *
  635. * Determines which flow control settings to use. Calls the appropriate media-
  636. * specific link configuration function. Configures the flow control settings.
  637. * Assuming the adapter has a valid link partner, a valid link should be
  638. * established. Assumes the hardware has previously been reset and the
  639. * transmitter and receiver are not enabled.
  640. */
  641. s32 e1000_setup_link(struct e1000_hw *hw)
  642. {
  643. u32 ctrl_ext;
  644. s32 ret_val;
  645. u16 eeprom_data;
  646. e_dbg("e1000_setup_link");
  647. /* Read and store word 0x0F of the EEPROM. This word contains bits
  648. * that determine the hardware's default PAUSE (flow control) mode,
  649. * a bit that determines whether the HW defaults to enabling or
  650. * disabling auto-negotiation, and the direction of the
  651. * SW defined pins. If there is no SW over-ride of the flow
  652. * control setting, then the variable hw->fc will
  653. * be initialized based on a value in the EEPROM.
  654. */
  655. if (hw->fc == E1000_FC_DEFAULT) {
  656. ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
  657. 1, &eeprom_data);
  658. if (ret_val) {
  659. e_dbg("EEPROM Read Error\n");
  660. return -E1000_ERR_EEPROM;
  661. }
  662. if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  663. hw->fc = E1000_FC_NONE;
  664. else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  665. EEPROM_WORD0F_ASM_DIR)
  666. hw->fc = E1000_FC_TX_PAUSE;
  667. else
  668. hw->fc = E1000_FC_FULL;
  669. }
  670. /* We want to save off the original Flow Control configuration just
  671. * in case we get disconnected and then reconnected into a different
  672. * hub or switch with different Flow Control capabilities.
  673. */
  674. if (hw->mac_type == e1000_82542_rev2_0)
  675. hw->fc &= (~E1000_FC_TX_PAUSE);
  676. if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  677. hw->fc &= (~E1000_FC_RX_PAUSE);
  678. hw->original_fc = hw->fc;
  679. e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc);
  680. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  681. * polarity value for the SW controlled pins, and setup the
  682. * Extended Device Control reg with that info.
  683. * This is needed because one of the SW controlled pins is used for
  684. * signal detection. So this should be done before e1000_setup_pcs_link()
  685. * or e1000_phy_setup() is called.
  686. */
  687. if (hw->mac_type == e1000_82543) {
  688. ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
  689. 1, &eeprom_data);
  690. if (ret_val) {
  691. e_dbg("EEPROM Read Error\n");
  692. return -E1000_ERR_EEPROM;
  693. }
  694. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  695. SWDPIO__EXT_SHIFT);
  696. ew32(CTRL_EXT, ctrl_ext);
  697. }
  698. /* Call the necessary subroutine to configure the link. */
  699. ret_val = (hw->media_type == e1000_media_type_copper) ?
  700. e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
  701. /* Initialize the flow control address, type, and PAUSE timer
  702. * registers to their default values. This is done even if flow
  703. * control is disabled, because it does not hurt anything to
  704. * initialize these registers.
  705. */
  706. e_dbg("Initializing the Flow Control address, type and timer regs\n");
  707. ew32(FCT, FLOW_CONTROL_TYPE);
  708. ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  709. ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
  710. ew32(FCTTV, hw->fc_pause_time);
  711. /* Set the flow control receive threshold registers. Normally,
  712. * these registers will be set to a default threshold that may be
  713. * adjusted later by the driver's runtime code. However, if the
  714. * ability to transmit pause frames in not enabled, then these
  715. * registers will be set to 0.
  716. */
  717. if (!(hw->fc & E1000_FC_TX_PAUSE)) {
  718. ew32(FCRTL, 0);
  719. ew32(FCRTH, 0);
  720. } else {
  721. /* We need to set up the Receive Threshold high and low water
  722. * marks as well as (optionally) enabling the transmission of
  723. * XON frames.
  724. */
  725. if (hw->fc_send_xon) {
  726. ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  727. ew32(FCRTH, hw->fc_high_water);
  728. } else {
  729. ew32(FCRTL, hw->fc_low_water);
  730. ew32(FCRTH, hw->fc_high_water);
  731. }
  732. }
  733. return ret_val;
  734. }
  735. /**
  736. * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
  737. * @hw: Struct containing variables accessed by shared code
  738. *
  739. * Manipulates Physical Coding Sublayer functions in order to configure
  740. * link. Assumes the hardware has been previously reset and the transmitter
  741. * and receiver are not enabled.
  742. */
  743. static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
  744. {
  745. u32 ctrl;
  746. u32 status;
  747. u32 txcw = 0;
  748. u32 i;
  749. u32 signal = 0;
  750. s32 ret_val;
  751. e_dbg("e1000_setup_fiber_serdes_link");
  752. /* On adapters with a MAC newer than 82544, SWDP 1 will be
  753. * set when the optics detect a signal. On older adapters, it will be
  754. * cleared when there is a signal. This applies to fiber media only.
  755. * If we're on serdes media, adjust the output amplitude to value
  756. * set in the EEPROM.
  757. */
  758. ctrl = er32(CTRL);
  759. if (hw->media_type == e1000_media_type_fiber)
  760. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  761. ret_val = e1000_adjust_serdes_amplitude(hw);
  762. if (ret_val)
  763. return ret_val;
  764. /* Take the link out of reset */
  765. ctrl &= ~(E1000_CTRL_LRST);
  766. /* Adjust VCO speed to improve BER performance */
  767. ret_val = e1000_set_vco_speed(hw);
  768. if (ret_val)
  769. return ret_val;
  770. e1000_config_collision_dist(hw);
  771. /* Check for a software override of the flow control settings, and setup
  772. * the device accordingly. If auto-negotiation is enabled, then
  773. * software will have to set the "PAUSE" bits to the correct value in
  774. * the Tranmsit Config Word Register (TXCW) and re-start
  775. * auto-negotiation. However, if auto-negotiation is disabled, then
  776. * software will have to manually configure the two flow control enable
  777. * bits in the CTRL register.
  778. *
  779. * The possible values of the "fc" parameter are:
  780. * 0: Flow control is completely disabled
  781. * 1: Rx flow control is enabled (we can receive pause frames, but
  782. * not send pause frames).
  783. * 2: Tx flow control is enabled (we can send pause frames but we do
  784. * not support receiving pause frames).
  785. * 3: Both Rx and TX flow control (symmetric) are enabled.
  786. */
  787. switch (hw->fc) {
  788. case E1000_FC_NONE:
  789. /* Flow ctrl is completely disabled by a software over-ride */
  790. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  791. break;
  792. case E1000_FC_RX_PAUSE:
  793. /* Rx Flow control is enabled and Tx Flow control is disabled by
  794. * a software over-ride. Since there really isn't a way to
  795. * advertise that we are capable of Rx Pause ONLY, we will
  796. * advertise that we support both symmetric and asymmetric Rx
  797. * PAUSE. Later, we will disable the adapter's ability to send
  798. * PAUSE frames.
  799. */
  800. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  801. break;
  802. case E1000_FC_TX_PAUSE:
  803. /* Tx Flow control is enabled, and Rx Flow control is disabled,
  804. * by a software over-ride.
  805. */
  806. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  807. break;
  808. case E1000_FC_FULL:
  809. /* Flow control (both Rx and Tx) is enabled by a software
  810. * over-ride.
  811. */
  812. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  813. break;
  814. default:
  815. e_dbg("Flow control param set incorrectly\n");
  816. return -E1000_ERR_CONFIG;
  817. break;
  818. }
  819. /* Since auto-negotiation is enabled, take the link out of reset (the
  820. * link will be in reset, because we previously reset the chip). This
  821. * will restart auto-negotiation. If auto-negotiation is successful
  822. * then the link-up status bit will be set and the flow control enable
  823. * bits (RFCE and TFCE) will be set according to their negotiated value.
  824. */
  825. e_dbg("Auto-negotiation enabled\n");
  826. ew32(TXCW, txcw);
  827. ew32(CTRL, ctrl);
  828. E1000_WRITE_FLUSH();
  829. hw->txcw = txcw;
  830. msleep(1);
  831. /* If we have a signal (the cable is plugged in) then poll for a
  832. * "Link-Up" indication in the Device Status Register. Time-out if a
  833. * link isn't seen in 500 milliseconds seconds (Auto-negotiation should
  834. * complete in less than 500 milliseconds even if the other end is doing
  835. * it in SW). For internal serdes, we just assume a signal is present,
  836. * then poll.
  837. */
  838. if (hw->media_type == e1000_media_type_internal_serdes ||
  839. (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  840. e_dbg("Looking for Link\n");
  841. for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  842. msleep(10);
  843. status = er32(STATUS);
  844. if (status & E1000_STATUS_LU)
  845. break;
  846. }
  847. if (i == (LINK_UP_TIMEOUT / 10)) {
  848. e_dbg("Never got a valid link from auto-neg!!!\n");
  849. hw->autoneg_failed = 1;
  850. /* AutoNeg failed to achieve a link, so we'll call
  851. * e1000_check_for_link. This routine will force the
  852. * link up if we detect a signal. This will allow us to
  853. * communicate with non-autonegotiating link partners.
  854. */
  855. ret_val = e1000_check_for_link(hw);
  856. if (ret_val) {
  857. e_dbg("Error while checking for link\n");
  858. return ret_val;
  859. }
  860. hw->autoneg_failed = 0;
  861. } else {
  862. hw->autoneg_failed = 0;
  863. e_dbg("Valid Link Found\n");
  864. }
  865. } else {
  866. e_dbg("No Signal Detected\n");
  867. }
  868. return E1000_SUCCESS;
  869. }
  870. /**
  871. * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series.
  872. * @hw: Struct containing variables accessed by shared code
  873. *
  874. * Commits changes to PHY configuration by calling e1000_phy_reset().
  875. */
  876. static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw)
  877. {
  878. s32 ret_val;
  879. /* SW reset the PHY so all changes take effect */
  880. ret_val = e1000_phy_reset(hw);
  881. if (ret_val) {
  882. e_dbg("Error Resetting the PHY\n");
  883. return ret_val;
  884. }
  885. return E1000_SUCCESS;
  886. }
  887. static s32 gbe_dhg_phy_setup(struct e1000_hw *hw)
  888. {
  889. s32 ret_val;
  890. u32 ctrl_aux;
  891. switch (hw->phy_type) {
  892. case e1000_phy_8211:
  893. ret_val = e1000_copper_link_rtl_setup(hw);
  894. if (ret_val) {
  895. e_dbg("e1000_copper_link_rtl_setup failed!\n");
  896. return ret_val;
  897. }
  898. break;
  899. case e1000_phy_8201:
  900. /* Set RMII mode */
  901. ctrl_aux = er32(CTL_AUX);
  902. ctrl_aux |= E1000_CTL_AUX_RMII;
  903. ew32(CTL_AUX, ctrl_aux);
  904. E1000_WRITE_FLUSH();
  905. /* Disable the J/K bits required for receive */
  906. ctrl_aux = er32(CTL_AUX);
  907. ctrl_aux |= 0x4;
  908. ctrl_aux &= ~0x2;
  909. ew32(CTL_AUX, ctrl_aux);
  910. E1000_WRITE_FLUSH();
  911. ret_val = e1000_copper_link_rtl_setup(hw);
  912. if (ret_val) {
  913. e_dbg("e1000_copper_link_rtl_setup failed!\n");
  914. return ret_val;
  915. }
  916. break;
  917. default:
  918. e_dbg("Error Resetting the PHY\n");
  919. return E1000_ERR_PHY_TYPE;
  920. }
  921. return E1000_SUCCESS;
  922. }
  923. /**
  924. * e1000_copper_link_preconfig - early configuration for copper
  925. * @hw: Struct containing variables accessed by shared code
  926. *
  927. * Make sure we have a valid PHY and change PHY mode before link setup.
  928. */
  929. static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
  930. {
  931. u32 ctrl;
  932. s32 ret_val;
  933. u16 phy_data;
  934. e_dbg("e1000_copper_link_preconfig");
  935. ctrl = er32(CTRL);
  936. /* With 82543, we need to force speed and duplex on the MAC equal to
  937. * what the PHY speed and duplex configuration is. In addition, we need
  938. * to perform a hardware reset on the PHY to take it out of reset.
  939. */
  940. if (hw->mac_type > e1000_82543) {
  941. ctrl |= E1000_CTRL_SLU;
  942. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  943. ew32(CTRL, ctrl);
  944. } else {
  945. ctrl |=
  946. (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  947. ew32(CTRL, ctrl);
  948. ret_val = e1000_phy_hw_reset(hw);
  949. if (ret_val)
  950. return ret_val;
  951. }
  952. /* Make sure we have a valid PHY */
  953. ret_val = e1000_detect_gig_phy(hw);
  954. if (ret_val) {
  955. e_dbg("Error, did not detect valid phy.\n");
  956. return ret_val;
  957. }
  958. e_dbg("Phy ID = %x\n", hw->phy_id);
  959. /* Set PHY to class A mode (if necessary) */
  960. ret_val = e1000_set_phy_mode(hw);
  961. if (ret_val)
  962. return ret_val;
  963. if ((hw->mac_type == e1000_82545_rev_3) ||
  964. (hw->mac_type == e1000_82546_rev_3)) {
  965. ret_val =
  966. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  967. phy_data |= 0x00000008;
  968. ret_val =
  969. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  970. }
  971. if (hw->mac_type <= e1000_82543 ||
  972. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  973. hw->mac_type == e1000_82541_rev_2
  974. || hw->mac_type == e1000_82547_rev_2)
  975. hw->phy_reset_disable = false;
  976. return E1000_SUCCESS;
  977. }
  978. /**
  979. * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
  980. * @hw: Struct containing variables accessed by shared code
  981. */
  982. static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
  983. {
  984. u32 led_ctrl;
  985. s32 ret_val;
  986. u16 phy_data;
  987. e_dbg("e1000_copper_link_igp_setup");
  988. if (hw->phy_reset_disable)
  989. return E1000_SUCCESS;
  990. ret_val = e1000_phy_reset(hw);
  991. if (ret_val) {
  992. e_dbg("Error Resetting the PHY\n");
  993. return ret_val;
  994. }
  995. /* Wait 15ms for MAC to configure PHY from eeprom settings */
  996. msleep(15);
  997. /* Configure activity LED after PHY reset */
  998. led_ctrl = er32(LEDCTL);
  999. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  1000. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  1001. ew32(LEDCTL, led_ctrl);
  1002. /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
  1003. if (hw->phy_type == e1000_phy_igp) {
  1004. /* disable lplu d3 during driver init */
  1005. ret_val = e1000_set_d3_lplu_state(hw, false);
  1006. if (ret_val) {
  1007. e_dbg("Error Disabling LPLU D3\n");
  1008. return ret_val;
  1009. }
  1010. }
  1011. /* Configure mdi-mdix settings */
  1012. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1013. if (ret_val)
  1014. return ret_val;
  1015. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  1016. hw->dsp_config_state = e1000_dsp_config_disabled;
  1017. /* Force MDI for earlier revs of the IGP PHY */
  1018. phy_data &=
  1019. ~(IGP01E1000_PSCR_AUTO_MDIX |
  1020. IGP01E1000_PSCR_FORCE_MDI_MDIX);
  1021. hw->mdix = 1;
  1022. } else {
  1023. hw->dsp_config_state = e1000_dsp_config_enabled;
  1024. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1025. switch (hw->mdix) {
  1026. case 1:
  1027. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1028. break;
  1029. case 2:
  1030. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1031. break;
  1032. case 0:
  1033. default:
  1034. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  1035. break;
  1036. }
  1037. }
  1038. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1039. if (ret_val)
  1040. return ret_val;
  1041. /* set auto-master slave resolution settings */
  1042. if (hw->autoneg) {
  1043. e1000_ms_type phy_ms_setting = hw->master_slave;
  1044. if (hw->ffe_config_state == e1000_ffe_config_active)
  1045. hw->ffe_config_state = e1000_ffe_config_enabled;
  1046. if (hw->dsp_config_state == e1000_dsp_config_activated)
  1047. hw->dsp_config_state = e1000_dsp_config_enabled;
  1048. /* when autonegotiation advertisement is only 1000Mbps then we
  1049. * should disable SmartSpeed and enable Auto MasterSlave
  1050. * resolution as hardware default.
  1051. */
  1052. if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  1053. /* Disable SmartSpeed */
  1054. ret_val =
  1055. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  1056. &phy_data);
  1057. if (ret_val)
  1058. return ret_val;
  1059. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1060. ret_val =
  1061. e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  1062. phy_data);
  1063. if (ret_val)
  1064. return ret_val;
  1065. /* Set auto Master/Slave resolution process */
  1066. ret_val =
  1067. e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1068. if (ret_val)
  1069. return ret_val;
  1070. phy_data &= ~CR_1000T_MS_ENABLE;
  1071. ret_val =
  1072. e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1073. if (ret_val)
  1074. return ret_val;
  1075. }
  1076. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1077. if (ret_val)
  1078. return ret_val;
  1079. /* load defaults for future use */
  1080. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  1081. ((phy_data & CR_1000T_MS_VALUE) ?
  1082. e1000_ms_force_master :
  1083. e1000_ms_force_slave) : e1000_ms_auto;
  1084. switch (phy_ms_setting) {
  1085. case e1000_ms_force_master:
  1086. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  1087. break;
  1088. case e1000_ms_force_slave:
  1089. phy_data |= CR_1000T_MS_ENABLE;
  1090. phy_data &= ~(CR_1000T_MS_VALUE);
  1091. break;
  1092. case e1000_ms_auto:
  1093. phy_data &= ~CR_1000T_MS_ENABLE;
  1094. default:
  1095. break;
  1096. }
  1097. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1098. if (ret_val)
  1099. return ret_val;
  1100. }
  1101. return E1000_SUCCESS;
  1102. }
  1103. /**
  1104. * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
  1105. * @hw: Struct containing variables accessed by shared code
  1106. */
  1107. static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  1108. {
  1109. s32 ret_val;
  1110. u16 phy_data;
  1111. e_dbg("e1000_copper_link_mgp_setup");
  1112. if (hw->phy_reset_disable)
  1113. return E1000_SUCCESS;
  1114. /* Enable CRS on TX. This must be set for half-duplex operation. */
  1115. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1116. if (ret_val)
  1117. return ret_val;
  1118. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1119. /* Options:
  1120. * MDI/MDI-X = 0 (default)
  1121. * 0 - Auto for all speeds
  1122. * 1 - MDI mode
  1123. * 2 - MDI-X mode
  1124. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  1125. */
  1126. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1127. switch (hw->mdix) {
  1128. case 1:
  1129. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  1130. break;
  1131. case 2:
  1132. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  1133. break;
  1134. case 3:
  1135. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  1136. break;
  1137. case 0:
  1138. default:
  1139. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  1140. break;
  1141. }
  1142. /* Options:
  1143. * disable_polarity_correction = 0 (default)
  1144. * Automatic Correction for Reversed Cable Polarity
  1145. * 0 - Disabled
  1146. * 1 - Enabled
  1147. */
  1148. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  1149. if (hw->disable_polarity_correction == 1)
  1150. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  1151. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1152. if (ret_val)
  1153. return ret_val;
  1154. if (hw->phy_revision < M88E1011_I_REV_4) {
  1155. /* Force TX_CLK in the Extended PHY Specific Control Register
  1156. * to 25MHz clock.
  1157. */
  1158. ret_val =
  1159. e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  1160. &phy_data);
  1161. if (ret_val)
  1162. return ret_val;
  1163. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1164. if ((hw->phy_revision == E1000_REVISION_2) &&
  1165. (hw->phy_id == M88E1111_I_PHY_ID)) {
  1166. /* Vidalia Phy, set the downshift counter to 5x */
  1167. phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
  1168. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  1169. ret_val = e1000_write_phy_reg(hw,
  1170. M88E1000_EXT_PHY_SPEC_CTRL,
  1171. phy_data);
  1172. if (ret_val)
  1173. return ret_val;
  1174. } else {
  1175. /* Configure Master and Slave downshift values */
  1176. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  1177. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  1178. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  1179. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  1180. ret_val = e1000_write_phy_reg(hw,
  1181. M88E1000_EXT_PHY_SPEC_CTRL,
  1182. phy_data);
  1183. if (ret_val)
  1184. return ret_val;
  1185. }
  1186. }
  1187. /* SW Reset the PHY so all changes take effect */
  1188. ret_val = e1000_phy_reset(hw);
  1189. if (ret_val) {
  1190. e_dbg("Error Resetting the PHY\n");
  1191. return ret_val;
  1192. }
  1193. return E1000_SUCCESS;
  1194. }
  1195. /**
  1196. * e1000_copper_link_autoneg - setup auto-neg
  1197. * @hw: Struct containing variables accessed by shared code
  1198. *
  1199. * Setup auto-negotiation and flow control advertisements,
  1200. * and then perform auto-negotiation.
  1201. */
  1202. static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
  1203. {
  1204. s32 ret_val;
  1205. u16 phy_data;
  1206. e_dbg("e1000_copper_link_autoneg");
  1207. /* Perform some bounds checking on the hw->autoneg_advertised
  1208. * parameter. If this variable is zero, then set it to the default.
  1209. */
  1210. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1211. /* If autoneg_advertised is zero, we assume it was not defaulted
  1212. * by the calling code so we set to advertise full capability.
  1213. */
  1214. if (hw->autoneg_advertised == 0)
  1215. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1216. /* IFE/RTL8201N PHY only supports 10/100 */
  1217. if (hw->phy_type == e1000_phy_8201)
  1218. hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
  1219. e_dbg("Reconfiguring auto-neg advertisement params\n");
  1220. ret_val = e1000_phy_setup_autoneg(hw);
  1221. if (ret_val) {
  1222. e_dbg("Error Setting up Auto-Negotiation\n");
  1223. return ret_val;
  1224. }
  1225. e_dbg("Restarting Auto-Neg\n");
  1226. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  1227. * the Auto Neg Restart bit in the PHY control register.
  1228. */
  1229. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  1230. if (ret_val)
  1231. return ret_val;
  1232. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  1233. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  1234. if (ret_val)
  1235. return ret_val;
  1236. /* Does the user want to wait for Auto-Neg to complete here, or
  1237. * check at a later time (for example, callback routine).
  1238. */
  1239. if (hw->wait_autoneg_complete) {
  1240. ret_val = e1000_wait_autoneg(hw);
  1241. if (ret_val) {
  1242. e_dbg
  1243. ("Error while waiting for autoneg to complete\n");
  1244. return ret_val;
  1245. }
  1246. }
  1247. hw->get_link_status = true;
  1248. return E1000_SUCCESS;
  1249. }
  1250. /**
  1251. * e1000_copper_link_postconfig - post link setup
  1252. * @hw: Struct containing variables accessed by shared code
  1253. *
  1254. * Config the MAC and the PHY after link is up.
  1255. * 1) Set up the MAC to the current PHY speed/duplex
  1256. * if we are on 82543. If we
  1257. * are on newer silicon, we only need to configure
  1258. * collision distance in the Transmit Control Register.
  1259. * 2) Set up flow control on the MAC to that established with
  1260. * the link partner.
  1261. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  1262. */
  1263. static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
  1264. {
  1265. s32 ret_val;
  1266. e_dbg("e1000_copper_link_postconfig");
  1267. if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) {
  1268. e1000_config_collision_dist(hw);
  1269. } else {
  1270. ret_val = e1000_config_mac_to_phy(hw);
  1271. if (ret_val) {
  1272. e_dbg("Error configuring MAC to PHY settings\n");
  1273. return ret_val;
  1274. }
  1275. }
  1276. ret_val = e1000_config_fc_after_link_up(hw);
  1277. if (ret_val) {
  1278. e_dbg("Error Configuring Flow Control\n");
  1279. return ret_val;
  1280. }
  1281. /* Config DSP to improve Giga link quality */
  1282. if (hw->phy_type == e1000_phy_igp) {
  1283. ret_val = e1000_config_dsp_after_link_change(hw, true);
  1284. if (ret_val) {
  1285. e_dbg("Error Configuring DSP after link up\n");
  1286. return ret_val;
  1287. }
  1288. }
  1289. return E1000_SUCCESS;
  1290. }
  1291. /**
  1292. * e1000_setup_copper_link - phy/speed/duplex setting
  1293. * @hw: Struct containing variables accessed by shared code
  1294. *
  1295. * Detects which PHY is present and sets up the speed and duplex
  1296. */
  1297. static s32 e1000_setup_copper_link(struct e1000_hw *hw)
  1298. {
  1299. s32 ret_val;
  1300. u16 i;
  1301. u16 phy_data;
  1302. e_dbg("e1000_setup_copper_link");
  1303. /* Check if it is a valid PHY and set PHY mode if necessary. */
  1304. ret_val = e1000_copper_link_preconfig(hw);
  1305. if (ret_val)
  1306. return ret_val;
  1307. if (hw->phy_type == e1000_phy_igp) {
  1308. ret_val = e1000_copper_link_igp_setup(hw);
  1309. if (ret_val)
  1310. return ret_val;
  1311. } else if (hw->phy_type == e1000_phy_m88) {
  1312. ret_val = e1000_copper_link_mgp_setup(hw);
  1313. if (ret_val)
  1314. return ret_val;
  1315. } else {
  1316. ret_val = gbe_dhg_phy_setup(hw);
  1317. if (ret_val) {
  1318. e_dbg("gbe_dhg_phy_setup failed!\n");
  1319. return ret_val;
  1320. }
  1321. }
  1322. if (hw->autoneg) {
  1323. /* Setup autoneg and flow control advertisement
  1324. * and perform autonegotiation
  1325. */
  1326. ret_val = e1000_copper_link_autoneg(hw);
  1327. if (ret_val)
  1328. return ret_val;
  1329. } else {
  1330. /* PHY will be set to 10H, 10F, 100H,or 100F
  1331. * depending on value from forced_speed_duplex.
  1332. */
  1333. e_dbg("Forcing speed and duplex\n");
  1334. ret_val = e1000_phy_force_speed_duplex(hw);
  1335. if (ret_val) {
  1336. e_dbg("Error Forcing Speed and Duplex\n");
  1337. return ret_val;
  1338. }
  1339. }
  1340. /* Check link status. Wait up to 100 microseconds for link to become
  1341. * valid.
  1342. */
  1343. for (i = 0; i < 10; i++) {
  1344. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1345. if (ret_val)
  1346. return ret_val;
  1347. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1348. if (ret_val)
  1349. return ret_val;
  1350. if (phy_data & MII_SR_LINK_STATUS) {
  1351. /* Config the MAC and PHY after link is up */
  1352. ret_val = e1000_copper_link_postconfig(hw);
  1353. if (ret_val)
  1354. return ret_val;
  1355. e_dbg("Valid link established!!!\n");
  1356. return E1000_SUCCESS;
  1357. }
  1358. udelay(10);
  1359. }
  1360. e_dbg("Unable to establish link!!!\n");
  1361. return E1000_SUCCESS;
  1362. }
  1363. /**
  1364. * e1000_phy_setup_autoneg - phy settings
  1365. * @hw: Struct containing variables accessed by shared code
  1366. *
  1367. * Configures PHY autoneg and flow control advertisement settings
  1368. */
  1369. s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
  1370. {
  1371. s32 ret_val;
  1372. u16 mii_autoneg_adv_reg;
  1373. u16 mii_1000t_ctrl_reg;
  1374. e_dbg("e1000_phy_setup_autoneg");
  1375. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  1376. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  1377. if (ret_val)
  1378. return ret_val;
  1379. /* Read the MII 1000Base-T Control Register (Address 9). */
  1380. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  1381. if (ret_val)
  1382. return ret_val;
  1383. else if (hw->phy_type == e1000_phy_8201)
  1384. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1385. /* Need to parse both autoneg_advertised and fc and set up
  1386. * the appropriate PHY registers. First we will parse for
  1387. * autoneg_advertised software override. Since we can advertise
  1388. * a plethora of combinations, we need to check each bit
  1389. * individually.
  1390. */
  1391. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  1392. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  1393. * the 1000Base-T Control Register (Address 9).
  1394. */
  1395. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  1396. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1397. e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised);
  1398. /* Do we want to advertise 10 Mb Half Duplex? */
  1399. if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
  1400. e_dbg("Advertise 10mb Half duplex\n");
  1401. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  1402. }
  1403. /* Do we want to advertise 10 Mb Full Duplex? */
  1404. if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
  1405. e_dbg("Advertise 10mb Full duplex\n");
  1406. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  1407. }
  1408. /* Do we want to advertise 100 Mb Half Duplex? */
  1409. if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
  1410. e_dbg("Advertise 100mb Half duplex\n");
  1411. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  1412. }
  1413. /* Do we want to advertise 100 Mb Full Duplex? */
  1414. if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
  1415. e_dbg("Advertise 100mb Full duplex\n");
  1416. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  1417. }
  1418. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  1419. if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  1420. e_dbg
  1421. ("Advertise 1000mb Half duplex requested, request denied!\n");
  1422. }
  1423. /* Do we want to advertise 1000 Mb Full Duplex? */
  1424. if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  1425. e_dbg("Advertise 1000mb Full duplex\n");
  1426. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  1427. }
  1428. /* Check for a software override of the flow control settings, and
  1429. * setup the PHY advertisement registers accordingly. If
  1430. * auto-negotiation is enabled, then software will have to set the
  1431. * "PAUSE" bits to the correct value in the Auto-Negotiation
  1432. * Advertisement Register (PHY_AUTONEG_ADV) and re-start
  1433. * auto-negotiation.
  1434. *
  1435. * The possible values of the "fc" parameter are:
  1436. * 0: Flow control is completely disabled
  1437. * 1: Rx flow control is enabled (we can receive pause frames
  1438. * but not send pause frames).
  1439. * 2: Tx flow control is enabled (we can send pause frames
  1440. * but we do not support receiving pause frames).
  1441. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1442. * other: No software override. The flow control configuration
  1443. * in the EEPROM is used.
  1444. */
  1445. switch (hw->fc) {
  1446. case E1000_FC_NONE: /* 0 */
  1447. /* Flow control (RX & TX) is completely disabled by a
  1448. * software over-ride.
  1449. */
  1450. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1451. break;
  1452. case E1000_FC_RX_PAUSE: /* 1 */
  1453. /* RX Flow control is enabled, and TX Flow control is
  1454. * disabled, by a software over-ride.
  1455. */
  1456. /* Since there really isn't a way to advertise that we are
  1457. * capable of RX Pause ONLY, we will advertise that we
  1458. * support both symmetric and asymmetric RX PAUSE. Later
  1459. * (in e1000_config_fc_after_link_up) we will disable the
  1460. * hw's ability to send PAUSE frames.
  1461. */
  1462. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1463. break;
  1464. case E1000_FC_TX_PAUSE: /* 2 */
  1465. /* TX Flow control is enabled, and RX Flow control is
  1466. * disabled, by a software over-ride.
  1467. */
  1468. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  1469. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  1470. break;
  1471. case E1000_FC_FULL: /* 3 */
  1472. /* Flow control (both RX and TX) is enabled by a software
  1473. * over-ride.
  1474. */
  1475. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1476. break;
  1477. default:
  1478. e_dbg("Flow control param set incorrectly\n");
  1479. return -E1000_ERR_CONFIG;
  1480. }
  1481. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  1482. if (ret_val)
  1483. return ret_val;
  1484. e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  1485. if (hw->phy_type == e1000_phy_8201) {
  1486. mii_1000t_ctrl_reg = 0;
  1487. } else {
  1488. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  1489. mii_1000t_ctrl_reg);
  1490. if (ret_val)
  1491. return ret_val;
  1492. }
  1493. return E1000_SUCCESS;
  1494. }
  1495. /**
  1496. * e1000_phy_force_speed_duplex - force link settings
  1497. * @hw: Struct containing variables accessed by shared code
  1498. *
  1499. * Force PHY speed and duplex settings to hw->forced_speed_duplex
  1500. */
  1501. static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1502. {
  1503. u32 ctrl;
  1504. s32 ret_val;
  1505. u16 mii_ctrl_reg;
  1506. u16 mii_status_reg;
  1507. u16 phy_data;
  1508. u16 i;
  1509. e_dbg("e1000_phy_force_speed_duplex");
  1510. /* Turn off Flow control if we are forcing speed and duplex. */
  1511. hw->fc = E1000_FC_NONE;
  1512. e_dbg("hw->fc = %d\n", hw->fc);
  1513. /* Read the Device Control Register. */
  1514. ctrl = er32(CTRL);
  1515. /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  1516. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1517. ctrl &= ~(DEVICE_SPEED_MASK);
  1518. /* Clear the Auto Speed Detect Enable bit. */
  1519. ctrl &= ~E1000_CTRL_ASDE;
  1520. /* Read the MII Control Register. */
  1521. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
  1522. if (ret_val)
  1523. return ret_val;
  1524. /* We need to disable autoneg in order to force link and duplex. */
  1525. mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  1526. /* Are we forcing Full or Half Duplex? */
  1527. if (hw->forced_speed_duplex == e1000_100_full ||
  1528. hw->forced_speed_duplex == e1000_10_full) {
  1529. /* We want to force full duplex so we SET the full duplex bits
  1530. * in the Device and MII Control Registers.
  1531. */
  1532. ctrl |= E1000_CTRL_FD;
  1533. mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  1534. e_dbg("Full Duplex\n");
  1535. } else {
  1536. /* We want to force half duplex so we CLEAR the full duplex bits
  1537. * in the Device and MII Control Registers.
  1538. */
  1539. ctrl &= ~E1000_CTRL_FD;
  1540. mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  1541. e_dbg("Half Duplex\n");
  1542. }
  1543. /* Are we forcing 100Mbps??? */
  1544. if (hw->forced_speed_duplex == e1000_100_full ||
  1545. hw->forced_speed_duplex == e1000_100_half) {
  1546. /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
  1547. ctrl |= E1000_CTRL_SPD_100;
  1548. mii_ctrl_reg |= MII_CR_SPEED_100;
  1549. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1550. e_dbg("Forcing 100mb ");
  1551. } else {
  1552. /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
  1553. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1554. mii_ctrl_reg |= MII_CR_SPEED_10;
  1555. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1556. e_dbg("Forcing 10mb ");
  1557. }
  1558. e1000_config_collision_dist(hw);
  1559. /* Write the configured values back to the Device Control Reg. */
  1560. ew32(CTRL, ctrl);
  1561. if (hw->phy_type == e1000_phy_m88) {
  1562. ret_val =
  1563. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1564. if (ret_val)
  1565. return ret_val;
  1566. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires
  1567. * MDI forced whenever speed are duplex are forced.
  1568. */
  1569. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1570. ret_val =
  1571. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1572. if (ret_val)
  1573. return ret_val;
  1574. e_dbg("M88E1000 PSCR: %x\n", phy_data);
  1575. /* Need to reset the PHY or these changes will be ignored */
  1576. mii_ctrl_reg |= MII_CR_RESET;
  1577. /* Disable MDI-X support for 10/100 */
  1578. } else {
  1579. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1580. * forced whenever speed or duplex are forced.
  1581. */
  1582. ret_val =
  1583. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1584. if (ret_val)
  1585. return ret_val;
  1586. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1587. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1588. ret_val =
  1589. e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1590. if (ret_val)
  1591. return ret_val;
  1592. }
  1593. /* Write back the modified PHY MII control register. */
  1594. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
  1595. if (ret_val)
  1596. return ret_val;
  1597. udelay(1);
  1598. /* The wait_autoneg_complete flag may be a little misleading here.
  1599. * Since we are forcing speed and duplex, Auto-Neg is not enabled.
  1600. * But we do want to delay for a period while forcing only so we
  1601. * don't generate false No Link messages. So we will wait here
  1602. * only if the user has set wait_autoneg_complete to 1, which is
  1603. * the default.
  1604. */
  1605. if (hw->wait_autoneg_complete) {
  1606. /* We will wait for autoneg to complete. */
  1607. e_dbg("Waiting for forced speed/duplex link.\n");
  1608. mii_status_reg = 0;
  1609. /* Wait for autoneg to complete or 4.5 seconds to expire */
  1610. for (i = PHY_FORCE_TIME; i > 0; i--) {
  1611. /* Read the MII Status Register and wait for Auto-Neg
  1612. * Complete bit to be set.
  1613. */
  1614. ret_val =
  1615. e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1616. if (ret_val)
  1617. return ret_val;
  1618. ret_val =
  1619. e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1620. if (ret_val)
  1621. return ret_val;
  1622. if (mii_status_reg & MII_SR_LINK_STATUS)
  1623. break;
  1624. msleep(100);
  1625. }
  1626. if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
  1627. /* We didn't get link. Reset the DSP and wait again
  1628. * for link.
  1629. */
  1630. ret_val = e1000_phy_reset_dsp(hw);
  1631. if (ret_val) {
  1632. e_dbg("Error Resetting PHY DSP\n");
  1633. return ret_val;
  1634. }
  1635. }
  1636. /* This loop will early-out if the link condition has been
  1637. * met
  1638. */
  1639. for (i = PHY_FORCE_TIME; i > 0; i--) {
  1640. if (mii_status_reg & MII_SR_LINK_STATUS)
  1641. break;
  1642. msleep(100);
  1643. /* Read the MII Status Register and wait for Auto-Neg
  1644. * Complete bit to be set.
  1645. */
  1646. ret_val =
  1647. e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1648. if (ret_val)
  1649. return ret_val;
  1650. ret_val =
  1651. e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1652. if (ret_val)
  1653. return ret_val;
  1654. }
  1655. }
  1656. if (hw->phy_type == e1000_phy_m88) {
  1657. /* Because we reset the PHY above, we need to re-force TX_CLK in
  1658. * the Extended PHY Specific Control Register to 25MHz clock.
  1659. * This value defaults back to a 2.5MHz clock when the PHY is
  1660. * reset.
  1661. */
  1662. ret_val =
  1663. e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  1664. &phy_data);
  1665. if (ret_val)
  1666. return ret_val;
  1667. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1668. ret_val =
  1669. e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  1670. phy_data);
  1671. if (ret_val)
  1672. return ret_val;
  1673. /* In addition, because of the s/w reset above, we need to
  1674. * enable CRS on Tx. This must be set for both full and half
  1675. * duplex operation.
  1676. */
  1677. ret_val =
  1678. e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1679. if (ret_val)
  1680. return ret_val;
  1681. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1682. ret_val =
  1683. e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1684. if (ret_val)
  1685. return ret_val;
  1686. if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
  1687. && (!hw->autoneg)
  1688. && (hw->forced_speed_duplex == e1000_10_full
  1689. || hw->forced_speed_duplex == e1000_10_half)) {
  1690. ret_val = e1000_polarity_reversal_workaround(hw);
  1691. if (ret_val)
  1692. return ret_val;
  1693. }
  1694. }
  1695. return E1000_SUCCESS;
  1696. }
  1697. /**
  1698. * e1000_config_collision_dist - set collision distance register
  1699. * @hw: Struct containing variables accessed by shared code
  1700. *
  1701. * Sets the collision distance in the Transmit Control register.
  1702. * Link should have been established previously. Reads the speed and duplex
  1703. * information from the Device Status register.
  1704. */
  1705. void e1000_config_collision_dist(struct e1000_hw *hw)
  1706. {
  1707. u32 tctl, coll_dist;
  1708. e_dbg("e1000_config_collision_dist");
  1709. if (hw->mac_type < e1000_82543)
  1710. coll_dist = E1000_COLLISION_DISTANCE_82542;
  1711. else
  1712. coll_dist = E1000_COLLISION_DISTANCE;
  1713. tctl = er32(TCTL);
  1714. tctl &= ~E1000_TCTL_COLD;
  1715. tctl |= coll_dist << E1000_COLD_SHIFT;
  1716. ew32(TCTL, tctl);
  1717. E1000_WRITE_FLUSH();
  1718. }
  1719. /**
  1720. * e1000_config_mac_to_phy - sync phy and mac settings
  1721. * @hw: Struct containing variables accessed by shared code
  1722. * @mii_reg: data to write to the MII control register
  1723. *
  1724. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1725. * The contents of the PHY register containing the needed information need to
  1726. * be passed in.
  1727. */
  1728. static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
  1729. {
  1730. u32 ctrl;
  1731. s32 ret_val;
  1732. u16 phy_data;
  1733. e_dbg("e1000_config_mac_to_phy");
  1734. /* 82544 or newer MAC, Auto Speed Detection takes care of
  1735. * MAC speed/duplex configuration.
  1736. */
  1737. if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100))
  1738. return E1000_SUCCESS;
  1739. /* Read the Device Control Register and set the bits to Force Speed
  1740. * and Duplex.
  1741. */
  1742. ctrl = er32(CTRL);
  1743. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1744. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1745. switch (hw->phy_type) {
  1746. case e1000_phy_8201:
  1747. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  1748. if (ret_val)
  1749. return ret_val;
  1750. if (phy_data & RTL_PHY_CTRL_FD)
  1751. ctrl |= E1000_CTRL_FD;
  1752. else
  1753. ctrl &= ~E1000_CTRL_FD;
  1754. if (phy_data & RTL_PHY_CTRL_SPD_100)
  1755. ctrl |= E1000_CTRL_SPD_100;
  1756. else
  1757. ctrl |= E1000_CTRL_SPD_10;
  1758. e1000_config_collision_dist(hw);
  1759. break;
  1760. default:
  1761. /* Set up duplex in the Device Control and Transmit Control
  1762. * registers depending on negotiated values.
  1763. */
  1764. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  1765. &phy_data);
  1766. if (ret_val)
  1767. return ret_val;
  1768. if (phy_data & M88E1000_PSSR_DPLX)
  1769. ctrl |= E1000_CTRL_FD;
  1770. else
  1771. ctrl &= ~E1000_CTRL_FD;
  1772. e1000_config_collision_dist(hw);
  1773. /* Set up speed in the Device Control register depending on
  1774. * negotiated values.
  1775. */
  1776. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1777. ctrl |= E1000_CTRL_SPD_1000;
  1778. else if ((phy_data & M88E1000_PSSR_SPEED) ==
  1779. M88E1000_PSSR_100MBS)
  1780. ctrl |= E1000_CTRL_SPD_100;
  1781. }
  1782. /* Write the configured values back to the Device Control Reg. */
  1783. ew32(CTRL, ctrl);
  1784. return E1000_SUCCESS;
  1785. }
  1786. /**
  1787. * e1000_force_mac_fc - force flow control settings
  1788. * @hw: Struct containing variables accessed by shared code
  1789. *
  1790. * Forces the MAC's flow control settings.
  1791. * Sets the TFCE and RFCE bits in the device control register to reflect
  1792. * the adapter settings. TFCE and RFCE need to be explicitly set by
  1793. * software when a Copper PHY is used because autonegotiation is managed
  1794. * by the PHY rather than the MAC. Software must also configure these
  1795. * bits when link is forced on a fiber connection.
  1796. */
  1797. s32 e1000_force_mac_fc(struct e1000_hw *hw)
  1798. {
  1799. u32 ctrl;
  1800. e_dbg("e1000_force_mac_fc");
  1801. /* Get the current configuration of the Device Control Register */
  1802. ctrl = er32(CTRL);
  1803. /* Because we didn't get link via the internal auto-negotiation
  1804. * mechanism (we either forced link or we got link via PHY
  1805. * auto-neg), we have to manually enable/disable transmit an
  1806. * receive flow control.
  1807. *
  1808. * The "Case" statement below enables/disable flow control
  1809. * according to the "hw->fc" parameter.
  1810. *
  1811. * The possible values of the "fc" parameter are:
  1812. * 0: Flow control is completely disabled
  1813. * 1: Rx flow control is enabled (we can receive pause
  1814. * frames but not send pause frames).
  1815. * 2: Tx flow control is enabled (we can send pause frames
  1816. * frames but we do not receive pause frames).
  1817. * 3: Both Rx and TX flow control (symmetric) is enabled.
  1818. * other: No other values should be possible at this point.
  1819. */
  1820. switch (hw->fc) {
  1821. case E1000_FC_NONE:
  1822. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  1823. break;
  1824. case E1000_FC_RX_PAUSE:
  1825. ctrl &= (~E1000_CTRL_TFCE);
  1826. ctrl |= E1000_CTRL_RFCE;
  1827. break;
  1828. case E1000_FC_TX_PAUSE:
  1829. ctrl &= (~E1000_CTRL_RFCE);
  1830. ctrl |= E1000_CTRL_TFCE;
  1831. break;
  1832. case E1000_FC_FULL:
  1833. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  1834. break;
  1835. default:
  1836. e_dbg("Flow control param set incorrectly\n");
  1837. return -E1000_ERR_CONFIG;
  1838. }
  1839. /* Disable TX Flow Control for 82542 (rev 2.0) */
  1840. if (hw->mac_type == e1000_82542_rev2_0)
  1841. ctrl &= (~E1000_CTRL_TFCE);
  1842. ew32(CTRL, ctrl);
  1843. return E1000_SUCCESS;
  1844. }
  1845. /**
  1846. * e1000_config_fc_after_link_up - configure flow control after autoneg
  1847. * @hw: Struct containing variables accessed by shared code
  1848. *
  1849. * Configures flow control settings after link is established
  1850. * Should be called immediately after a valid link has been established.
  1851. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  1852. * and autonegotiation is enabled, the MAC flow control settings will be set
  1853. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  1854. * and RFCE bits will be automatically set to the negotiated flow control mode.
  1855. */
  1856. static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
  1857. {
  1858. s32 ret_val;
  1859. u16 mii_status_reg;
  1860. u16 mii_nway_adv_reg;
  1861. u16 mii_nway_lp_ability_reg;
  1862. u16 speed;
  1863. u16 duplex;
  1864. e_dbg("e1000_config_fc_after_link_up");
  1865. /* Check for the case where we have fiber media and auto-neg failed
  1866. * so we had to force link. In this case, we need to force the
  1867. * configuration of the MAC to match the "fc" parameter.
  1868. */
  1869. if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
  1870. || ((hw->media_type == e1000_media_type_internal_serdes)
  1871. && (hw->autoneg_failed))
  1872. || ((hw->media_type == e1000_media_type_copper)
  1873. && (!hw->autoneg))) {
  1874. ret_val = e1000_force_mac_fc(hw);
  1875. if (ret_val) {
  1876. e_dbg("Error forcing flow control settings\n");
  1877. return ret_val;
  1878. }
  1879. }
  1880. /* Check for the case where we have copper media and auto-neg is
  1881. * enabled. In this case, we need to check and see if Auto-Neg
  1882. * has completed, and if so, how the PHY and link partner has
  1883. * flow control configured.
  1884. */
  1885. if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
  1886. /* Read the MII Status Register and check to see if AutoNeg
  1887. * has completed. We read this twice because this reg has
  1888. * some "sticky" (latched) bits.
  1889. */
  1890. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1891. if (ret_val)
  1892. return ret_val;
  1893. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1894. if (ret_val)
  1895. return ret_val;
  1896. if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  1897. /* The AutoNeg process has completed, so we now need to
  1898. * read both the Auto Negotiation Advertisement Register
  1899. * (Address 4) and the Auto_Negotiation Base Page
  1900. * Ability Register (Address 5) to determine how flow
  1901. * control was negotiated.
  1902. */
  1903. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  1904. &mii_nway_adv_reg);
  1905. if (ret_val)
  1906. return ret_val;
  1907. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  1908. &mii_nway_lp_ability_reg);
  1909. if (ret_val)
  1910. return ret_val;
  1911. /* Two bits in the Auto Negotiation Advertisement
  1912. * Register (Address 4) and two bits in the Auto
  1913. * Negotiation Base Page Ability Register (Address 5)
  1914. * determine flow control for both the PHY and the link
  1915. * partner. The following table, taken out of the IEEE
  1916. * 802.3ab/D6.0 dated March 25, 1999, describes these
  1917. * PAUSE resolution bits and how flow control is
  1918. * determined based upon these settings.
  1919. * NOTE: DC = Don't Care
  1920. *
  1921. * LOCAL DEVICE | LINK PARTNER
  1922. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1923. *-------|---------|-------|---------|------------------
  1924. * 0 | 0 | DC | DC | E1000_FC_NONE
  1925. * 0 | 1 | 0 | DC | E1000_FC_NONE
  1926. * 0 | 1 | 1 | 0 | E1000_FC_NONE
  1927. * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
  1928. * 1 | 0 | 0 | DC | E1000_FC_NONE
  1929. * 1 | DC | 1 | DC | E1000_FC_FULL
  1930. * 1 | 1 | 0 | 0 | E1000_FC_NONE
  1931. * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
  1932. *
  1933. */
  1934. /* Are both PAUSE bits set to 1? If so, this implies
  1935. * Symmetric Flow Control is enabled at both ends. The
  1936. * ASM_DIR bits are irrelevant per the spec.
  1937. *
  1938. * For Symmetric Flow Control:
  1939. *
  1940. * LOCAL DEVICE | LINK PARTNER
  1941. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1942. *-------|---------|-------|---------|------------------
  1943. * 1 | DC | 1 | DC | E1000_FC_FULL
  1944. *
  1945. */
  1946. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1947. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1948. /* Now we need to check if the user selected Rx
  1949. * ONLY of pause frames. In this case, we had
  1950. * to advertise FULL flow control because we
  1951. * could not advertise Rx ONLY. Hence, we must
  1952. * now check to see if we need to turn OFF the
  1953. * TRANSMISSION of PAUSE frames.
  1954. */
  1955. if (hw->original_fc == E1000_FC_FULL) {
  1956. hw->fc = E1000_FC_FULL;
  1957. e_dbg("Flow Control = FULL.\n");
  1958. } else {
  1959. hw->fc = E1000_FC_RX_PAUSE;
  1960. e_dbg
  1961. ("Flow Control = RX PAUSE frames only.\n");
  1962. }
  1963. }
  1964. /* For receiving PAUSE frames ONLY.
  1965. *
  1966. * LOCAL DEVICE | LINK PARTNER
  1967. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1968. *-------|---------|-------|---------|------------------
  1969. * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
  1970. *
  1971. */
  1972. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1973. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1974. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1975. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  1976. {
  1977. hw->fc = E1000_FC_TX_PAUSE;
  1978. e_dbg
  1979. ("Flow Control = TX PAUSE frames only.\n");
  1980. }
  1981. /* For transmitting PAUSE frames ONLY.
  1982. *
  1983. * LOCAL DEVICE | LINK PARTNER
  1984. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1985. *-------|---------|-------|---------|------------------
  1986. * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
  1987. *
  1988. */
  1989. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1990. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1991. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1992. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  1993. {
  1994. hw->fc = E1000_FC_RX_PAUSE;
  1995. e_dbg
  1996. ("Flow Control = RX PAUSE frames only.\n");
  1997. }
  1998. /* Per the IEEE spec, at this point flow control should
  1999. * be disabled. However, we want to consider that we
  2000. * could be connected to a legacy switch that doesn't
  2001. * advertise desired flow control, but can be forced on
  2002. * the link partner. So if we advertised no flow
  2003. * control, that is what we will resolve to. If we
  2004. * advertised some kind of receive capability (Rx Pause
  2005. * Only or Full Flow Control) and the link partner
  2006. * advertised none, we will configure ourselves to
  2007. * enable Rx Flow Control only. We can do this safely
  2008. * for two reasons: If the link partner really
  2009. * didn't want flow control enabled, and we enable Rx,
  2010. * no harm done since we won't be receiving any PAUSE
  2011. * frames anyway. If the intent on the link partner was
  2012. * to have flow control enabled, then by us enabling Rx
  2013. * only, we can at least receive pause frames and
  2014. * process them. This is a good idea because in most
  2015. * cases, since we are predominantly a server NIC, more
  2016. * times than not we will be asked to delay transmission
  2017. * of packets than asking our link partner to pause
  2018. * transmission of frames.
  2019. */
  2020. else if ((hw->original_fc == E1000_FC_NONE ||
  2021. hw->original_fc == E1000_FC_TX_PAUSE) ||
  2022. hw->fc_strict_ieee) {
  2023. hw->fc = E1000_FC_NONE;
  2024. e_dbg("Flow Control = NONE.\n");
  2025. } else {
  2026. hw->fc = E1000_FC_RX_PAUSE;
  2027. e_dbg
  2028. ("Flow Control = RX PAUSE frames only.\n");
  2029. }
  2030. /* Now we need to do one last check... If we auto-
  2031. * negotiated to HALF DUPLEX, flow control should not be
  2032. * enabled per IEEE 802.3 spec.
  2033. */
  2034. ret_val =
  2035. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2036. if (ret_val) {
  2037. e_dbg
  2038. ("Error getting link speed and duplex\n");
  2039. return ret_val;
  2040. }
  2041. if (duplex == HALF_DUPLEX)
  2042. hw->fc = E1000_FC_NONE;
  2043. /* Now we call a subroutine to actually force the MAC
  2044. * controller to use the correct flow control settings.
  2045. */
  2046. ret_val = e1000_force_mac_fc(hw);
  2047. if (ret_val) {
  2048. e_dbg
  2049. ("Error forcing flow control settings\n");
  2050. return ret_val;
  2051. }
  2052. } else {
  2053. e_dbg
  2054. ("Copper PHY and Auto Neg has not completed.\n");
  2055. }
  2056. }
  2057. return E1000_SUCCESS;
  2058. }
  2059. /**
  2060. * e1000_check_for_serdes_link_generic - Check for link (Serdes)
  2061. * @hw: pointer to the HW structure
  2062. *
  2063. * Checks for link up on the hardware. If link is not up and we have
  2064. * a signal, then we need to force link up.
  2065. */
  2066. static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
  2067. {
  2068. u32 rxcw;
  2069. u32 ctrl;
  2070. u32 status;
  2071. s32 ret_val = E1000_SUCCESS;
  2072. e_dbg("e1000_check_for_serdes_link_generic");
  2073. ctrl = er32(CTRL);
  2074. status = er32(STATUS);
  2075. rxcw = er32(RXCW);
  2076. /* If we don't have link (auto-negotiation failed or link partner
  2077. * cannot auto-negotiate), and our link partner is not trying to
  2078. * auto-negotiate with us (we are receiving idles or data),
  2079. * we need to force link up. We also need to give auto-negotiation
  2080. * time to complete.
  2081. */
  2082. /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
  2083. if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
  2084. if (hw->autoneg_failed == 0) {
  2085. hw->autoneg_failed = 1;
  2086. goto out;
  2087. }
  2088. e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
  2089. /* Disable auto-negotiation in the TXCW register */
  2090. ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  2091. /* Force link-up and also force full-duplex. */
  2092. ctrl = er32(CTRL);
  2093. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  2094. ew32(CTRL, ctrl);
  2095. /* Configure Flow Control after forcing link up. */
  2096. ret_val = e1000_config_fc_after_link_up(hw);
  2097. if (ret_val) {
  2098. e_dbg("Error configuring flow control\n");
  2099. goto out;
  2100. }
  2101. } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  2102. /* If we are forcing link and we are receiving /C/ ordered
  2103. * sets, re-enable auto-negotiation in the TXCW register
  2104. * and disable forced link in the Device Control register
  2105. * in an attempt to auto-negotiate with our link partner.
  2106. */
  2107. e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
  2108. ew32(TXCW, hw->txcw);
  2109. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  2110. hw->serdes_has_link = true;
  2111. } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
  2112. /* If we force link for non-auto-negotiation switch, check
  2113. * link status based on MAC synchronization for internal
  2114. * serdes media type.
  2115. */
  2116. /* SYNCH bit and IV bit are sticky. */
  2117. udelay(10);
  2118. rxcw = er32(RXCW);
  2119. if (rxcw & E1000_RXCW_SYNCH) {
  2120. if (!(rxcw & E1000_RXCW_IV)) {
  2121. hw->serdes_has_link = true;
  2122. e_dbg("SERDES: Link up - forced.\n");
  2123. }
  2124. } else {
  2125. hw->serdes_has_link = false;
  2126. e_dbg("SERDES: Link down - force failed.\n");
  2127. }
  2128. }
  2129. if (E1000_TXCW_ANE & er32(TXCW)) {
  2130. status = er32(STATUS);
  2131. if (status & E1000_STATUS_LU) {
  2132. /* SYNCH bit and IV bit are sticky, so reread rxcw. */
  2133. udelay(10);
  2134. rxcw = er32(RXCW);
  2135. if (rxcw & E1000_RXCW_SYNCH) {
  2136. if (!(rxcw & E1000_RXCW_IV)) {
  2137. hw->serdes_has_link = true;
  2138. e_dbg("SERDES: Link up - autoneg "
  2139. "completed successfully.\n");
  2140. } else {
  2141. hw->serdes_has_link = false;
  2142. e_dbg("SERDES: Link down - invalid"
  2143. "codewords detected in autoneg.\n");
  2144. }
  2145. } else {
  2146. hw->serdes_has_link = false;
  2147. e_dbg("SERDES: Link down - no sync.\n");
  2148. }
  2149. } else {
  2150. hw->serdes_has_link = false;
  2151. e_dbg("SERDES: Link down - autoneg failed\n");
  2152. }
  2153. }
  2154. out:
  2155. return ret_val;
  2156. }
  2157. /**
  2158. * e1000_check_for_link
  2159. * @hw: Struct containing variables accessed by shared code
  2160. *
  2161. * Checks to see if the link status of the hardware has changed.
  2162. * Called by any function that needs to check the link status of the adapter.
  2163. */
  2164. s32 e1000_check_for_link(struct e1000_hw *hw)
  2165. {
  2166. u32 rxcw = 0;
  2167. u32 ctrl;
  2168. u32 status;
  2169. u32 rctl;
  2170. u32 icr;
  2171. u32 signal = 0;
  2172. s32 ret_val;
  2173. u16 phy_data;
  2174. e_dbg("e1000_check_for_link");
  2175. ctrl = er32(CTRL);
  2176. status = er32(STATUS);
  2177. /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
  2178. * set when the optics detect a signal. On older adapters, it will be
  2179. * cleared when there is a signal. This applies to fiber media only.
  2180. */
  2181. if ((hw->media_type == e1000_media_type_fiber) ||
  2182. (hw->media_type == e1000_media_type_internal_serdes)) {
  2183. rxcw = er32(RXCW);
  2184. if (hw->media_type == e1000_media_type_fiber) {
  2185. signal =
  2186. (hw->mac_type >
  2187. e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  2188. if (status & E1000_STATUS_LU)
  2189. hw->get_link_status = false;
  2190. }
  2191. }
  2192. /* If we have a copper PHY then we only want to go out to the PHY
  2193. * registers to see if Auto-Neg has completed and/or if our link
  2194. * status has changed. The get_link_status flag will be set if we
  2195. * receive a Link Status Change interrupt or we have Rx Sequence
  2196. * Errors.
  2197. */
  2198. if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  2199. /* First we want to see if the MII Status Register reports
  2200. * link. If so, then we want to get the current speed/duplex
  2201. * of the PHY.
  2202. * Read the register twice since the link bit is sticky.
  2203. */
  2204. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2205. if (ret_val)
  2206. return ret_val;
  2207. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2208. if (ret_val)
  2209. return ret_val;
  2210. if (phy_data & MII_SR_LINK_STATUS) {
  2211. hw->get_link_status = false;
  2212. /* Check if there was DownShift, must be checked
  2213. * immediately after link-up
  2214. */
  2215. e1000_check_downshift(hw);
  2216. /* If we are on 82544 or 82543 silicon and speed/duplex
  2217. * are forced to 10H or 10F, then we will implement the
  2218. * polarity reversal workaround. We disable interrupts
  2219. * first, and upon returning, place the devices
  2220. * interrupt state to its previous value except for the
  2221. * link status change interrupt which will
  2222. * happen due to the execution of this workaround.
  2223. */
  2224. if ((hw->mac_type == e1000_82544
  2225. || hw->mac_type == e1000_82543) && (!hw->autoneg)
  2226. && (hw->forced_speed_duplex == e1000_10_full
  2227. || hw->forced_speed_duplex == e1000_10_half)) {
  2228. ew32(IMC, 0xffffffff);
  2229. ret_val =
  2230. e1000_polarity_reversal_workaround(hw);
  2231. icr = er32(ICR);
  2232. ew32(ICS, (icr & ~E1000_ICS_LSC));
  2233. ew32(IMS, IMS_ENABLE_MASK);
  2234. }
  2235. } else {
  2236. /* No link detected */
  2237. e1000_config_dsp_after_link_change(hw, false);
  2238. return 0;
  2239. }
  2240. /* If we are forcing speed/duplex, then we simply return since
  2241. * we have already determined whether we have link or not.
  2242. */
  2243. if (!hw->autoneg)
  2244. return -E1000_ERR_CONFIG;
  2245. /* optimize the dsp settings for the igp phy */
  2246. e1000_config_dsp_after_link_change(hw, true);
  2247. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  2248. * have Si on board that is 82544 or newer, Auto
  2249. * Speed Detection takes care of MAC speed/duplex
  2250. * configuration. So we only need to configure Collision
  2251. * Distance in the MAC. Otherwise, we need to force
  2252. * speed/duplex on the MAC to the current PHY speed/duplex
  2253. * settings.
  2254. */
  2255. if ((hw->mac_type >= e1000_82544) &&
  2256. (hw->mac_type != e1000_ce4100))
  2257. e1000_config_collision_dist(hw);
  2258. else {
  2259. ret_val = e1000_config_mac_to_phy(hw);
  2260. if (ret_val) {
  2261. e_dbg
  2262. ("Error configuring MAC to PHY settings\n");
  2263. return ret_val;
  2264. }
  2265. }
  2266. /* Configure Flow Control now that Auto-Neg has completed.
  2267. * First, we need to restore the desired flow control settings
  2268. * because we may have had to re-autoneg with a different link
  2269. * partner.
  2270. */
  2271. ret_val = e1000_config_fc_after_link_up(hw);
  2272. if (ret_val) {
  2273. e_dbg("Error configuring flow control\n");
  2274. return ret_val;
  2275. }
  2276. /* At this point we know that we are on copper and we have
  2277. * auto-negotiated link. These are conditions for checking the
  2278. * link partner capability register. We use the link speed to
  2279. * determine if TBI compatibility needs to be turned on or off.
  2280. * If the link is not at gigabit speed, then TBI compatibility
  2281. * is not needed. If we are at gigabit speed, we turn on TBI
  2282. * compatibility.
  2283. */
  2284. if (hw->tbi_compatibility_en) {
  2285. u16 speed, duplex;
  2286. ret_val =
  2287. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2288. if (ret_val) {
  2289. e_dbg
  2290. ("Error getting link speed and duplex\n");
  2291. return ret_val;
  2292. }
  2293. if (speed != SPEED_1000) {
  2294. /* If link speed is not set to gigabit speed, we
  2295. * do not need to enable TBI compatibility.
  2296. */
  2297. if (hw->tbi_compatibility_on) {
  2298. /* If we previously were in the mode,
  2299. * turn it off.
  2300. */
  2301. rctl = er32(RCTL);
  2302. rctl &= ~E1000_RCTL_SBP;
  2303. ew32(RCTL, rctl);
  2304. hw->tbi_compatibility_on = false;
  2305. }
  2306. } else {
  2307. /* If TBI compatibility is was previously off,
  2308. * turn it on. For compatibility with a TBI link
  2309. * partner, we will store bad packets. Some
  2310. * frames have an additional byte on the end and
  2311. * will look like CRC errors to to the hardware.
  2312. */
  2313. if (!hw->tbi_compatibility_on) {
  2314. hw->tbi_compatibility_on = true;
  2315. rctl = er32(RCTL);
  2316. rctl |= E1000_RCTL_SBP;
  2317. ew32(RCTL, rctl);
  2318. }
  2319. }
  2320. }
  2321. }
  2322. if ((hw->media_type == e1000_media_type_fiber) ||
  2323. (hw->media_type == e1000_media_type_internal_serdes))
  2324. e1000_check_for_serdes_link_generic(hw);
  2325. return E1000_SUCCESS;
  2326. }
  2327. /**
  2328. * e1000_get_speed_and_duplex
  2329. * @hw: Struct containing variables accessed by shared code
  2330. * @speed: Speed of the connection
  2331. * @duplex: Duplex setting of the connection
  2332. *
  2333. * Detects the current speed and duplex settings of the hardware.
  2334. */
  2335. s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
  2336. {
  2337. u32 status;
  2338. s32 ret_val;
  2339. u16 phy_data;
  2340. e_dbg("e1000_get_speed_and_duplex");
  2341. if (hw->mac_type >= e1000_82543) {
  2342. status = er32(STATUS);
  2343. if (status & E1000_STATUS_SPEED_1000) {
  2344. *speed = SPEED_1000;
  2345. e_dbg("1000 Mbs, ");
  2346. } else if (status & E1000_STATUS_SPEED_100) {
  2347. *speed = SPEED_100;
  2348. e_dbg("100 Mbs, ");
  2349. } else {
  2350. *speed = SPEED_10;
  2351. e_dbg("10 Mbs, ");
  2352. }
  2353. if (status & E1000_STATUS_FD) {
  2354. *duplex = FULL_DUPLEX;
  2355. e_dbg("Full Duplex\n");
  2356. } else {
  2357. *duplex = HALF_DUPLEX;
  2358. e_dbg(" Half Duplex\n");
  2359. }
  2360. } else {
  2361. e_dbg("1000 Mbs, Full Duplex\n");
  2362. *speed = SPEED_1000;
  2363. *duplex = FULL_DUPLEX;
  2364. }
  2365. /* IGP01 PHY may advertise full duplex operation after speed downgrade
  2366. * even if it is operating at half duplex. Here we set the duplex
  2367. * settings to match the duplex in the link partner's capabilities.
  2368. */
  2369. if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  2370. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  2371. if (ret_val)
  2372. return ret_val;
  2373. if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  2374. *duplex = HALF_DUPLEX;
  2375. else {
  2376. ret_val =
  2377. e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
  2378. if (ret_val)
  2379. return ret_val;
  2380. if ((*speed == SPEED_100
  2381. && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
  2382. || (*speed == SPEED_10
  2383. && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  2384. *duplex = HALF_DUPLEX;
  2385. }
  2386. }
  2387. return E1000_SUCCESS;
  2388. }
  2389. /**
  2390. * e1000_wait_autoneg
  2391. * @hw: Struct containing variables accessed by shared code
  2392. *
  2393. * Blocks until autoneg completes or times out (~4.5 seconds)
  2394. */
  2395. static s32 e1000_wait_autoneg(struct e1000_hw *hw)
  2396. {
  2397. s32 ret_val;
  2398. u16 i;
  2399. u16 phy_data;
  2400. e_dbg("e1000_wait_autoneg");
  2401. e_dbg("Waiting for Auto-Neg to complete.\n");
  2402. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  2403. for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  2404. /* Read the MII Status Register and wait for Auto-Neg
  2405. * Complete bit to be set.
  2406. */
  2407. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2408. if (ret_val)
  2409. return ret_val;
  2410. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2411. if (ret_val)
  2412. return ret_val;
  2413. if (phy_data & MII_SR_AUTONEG_COMPLETE) {
  2414. return E1000_SUCCESS;
  2415. }
  2416. msleep(100);
  2417. }
  2418. return E1000_SUCCESS;
  2419. }
  2420. /**
  2421. * e1000_raise_mdi_clk - Raises the Management Data Clock
  2422. * @hw: Struct containing variables accessed by shared code
  2423. * @ctrl: Device control register's current value
  2424. */
  2425. static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
  2426. {
  2427. /* Raise the clock input to the Management Data Clock (by setting the
  2428. * MDC bit), and then delay 10 microseconds.
  2429. */
  2430. ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
  2431. E1000_WRITE_FLUSH();
  2432. udelay(10);
  2433. }
  2434. /**
  2435. * e1000_lower_mdi_clk - Lowers the Management Data Clock
  2436. * @hw: Struct containing variables accessed by shared code
  2437. * @ctrl: Device control register's current value
  2438. */
  2439. static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
  2440. {
  2441. /* Lower the clock input to the Management Data Clock (by clearing the
  2442. * MDC bit), and then delay 10 microseconds.
  2443. */
  2444. ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
  2445. E1000_WRITE_FLUSH();
  2446. udelay(10);
  2447. }
  2448. /**
  2449. * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
  2450. * @hw: Struct containing variables accessed by shared code
  2451. * @data: Data to send out to the PHY
  2452. * @count: Number of bits to shift out
  2453. *
  2454. * Bits are shifted out in MSB to LSB order.
  2455. */
  2456. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
  2457. {
  2458. u32 ctrl;
  2459. u32 mask;
  2460. /* We need to shift "count" number of bits out to the PHY. So, the value
  2461. * in the "data" parameter will be shifted out to the PHY one bit at a
  2462. * time. In order to do this, "data" must be broken down into bits.
  2463. */
  2464. mask = 0x01;
  2465. mask <<= (count - 1);
  2466. ctrl = er32(CTRL);
  2467. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  2468. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  2469. while (mask) {
  2470. /* A "1" is shifted out to the PHY by setting the MDIO bit to
  2471. * "1" and then raising and lowering the Management Data Clock.
  2472. * A "0" is shifted out to the PHY by setting the MDIO bit to
  2473. * "0" and then raising and lowering the clock.
  2474. */
  2475. if (data & mask)
  2476. ctrl |= E1000_CTRL_MDIO;
  2477. else
  2478. ctrl &= ~E1000_CTRL_MDIO;
  2479. ew32(CTRL, ctrl);
  2480. E1000_WRITE_FLUSH();
  2481. udelay(10);
  2482. e1000_raise_mdi_clk(hw, &ctrl);
  2483. e1000_lower_mdi_clk(hw, &ctrl);
  2484. mask = mask >> 1;
  2485. }
  2486. }
  2487. /**
  2488. * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
  2489. * @hw: Struct containing variables accessed by shared code
  2490. *
  2491. * Bits are shifted in in MSB to LSB order.
  2492. */
  2493. static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  2494. {
  2495. u32 ctrl;
  2496. u16 data = 0;
  2497. u8 i;
  2498. /* In order to read a register from the PHY, we need to shift in a total
  2499. * of 18 bits from the PHY. The first two bit (turnaround) times are
  2500. * used to avoid contention on the MDIO pin when a read operation is
  2501. * performed. These two bits are ignored by us and thrown away. Bits are
  2502. * "shifted in" by raising the input to the Management Data Clock
  2503. * (setting the MDC bit), and then reading the value of the MDIO bit.
  2504. */
  2505. ctrl = er32(CTRL);
  2506. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
  2507. * input.
  2508. */
  2509. ctrl &= ~E1000_CTRL_MDIO_DIR;
  2510. ctrl &= ~E1000_CTRL_MDIO;
  2511. ew32(CTRL, ctrl);
  2512. E1000_WRITE_FLUSH();
  2513. /* Raise and Lower the clock before reading in the data. This accounts
  2514. * for the turnaround bits. The first clock occurred when we clocked out
  2515. * the last bit of the Register Address.
  2516. */
  2517. e1000_raise_mdi_clk(hw, &ctrl);
  2518. e1000_lower_mdi_clk(hw, &ctrl);
  2519. for (data = 0, i = 0; i < 16; i++) {
  2520. data = data << 1;
  2521. e1000_raise_mdi_clk(hw, &ctrl);
  2522. ctrl = er32(CTRL);
  2523. /* Check to see if we shifted in a "1". */
  2524. if (ctrl & E1000_CTRL_MDIO)
  2525. data |= 1;
  2526. e1000_lower_mdi_clk(hw, &ctrl);
  2527. }
  2528. e1000_raise_mdi_clk(hw, &ctrl);
  2529. e1000_lower_mdi_clk(hw, &ctrl);
  2530. return data;
  2531. }
  2532. /**
  2533. * e1000_read_phy_reg - read a phy register
  2534. * @hw: Struct containing variables accessed by shared code
  2535. * @reg_addr: address of the PHY register to read
  2536. *
  2537. * Reads the value from a PHY register, if the value is on a specific non zero
  2538. * page, sets the page first.
  2539. */
  2540. s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
  2541. {
  2542. u32 ret_val;
  2543. unsigned long flags;
  2544. e_dbg("e1000_read_phy_reg");
  2545. spin_lock_irqsave(&e1000_phy_lock, flags);
  2546. if ((hw->phy_type == e1000_phy_igp) &&
  2547. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2548. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2549. (u16) reg_addr);
  2550. if (ret_val) {
  2551. spin_unlock_irqrestore(&e1000_phy_lock, flags);
  2552. return ret_val;
  2553. }
  2554. }
  2555. ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2556. phy_data);
  2557. spin_unlock_irqrestore(&e1000_phy_lock, flags);
  2558. return ret_val;
  2559. }
  2560. static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
  2561. u16 *phy_data)
  2562. {
  2563. u32 i;
  2564. u32 mdic = 0;
  2565. const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
  2566. e_dbg("e1000_read_phy_reg_ex");
  2567. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  2568. e_dbg("PHY Address %d is out of range\n", reg_addr);
  2569. return -E1000_ERR_PARAM;
  2570. }
  2571. if (hw->mac_type > e1000_82543) {
  2572. /* Set up Op-code, Phy Address, and register address in the MDI
  2573. * Control register. The MAC will take care of interfacing with
  2574. * the PHY to retrieve the desired data.
  2575. */
  2576. if (hw->mac_type == e1000_ce4100) {
  2577. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2578. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2579. (INTEL_CE_GBE_MDIC_OP_READ) |
  2580. (INTEL_CE_GBE_MDIC_GO));
  2581. writel(mdic, E1000_MDIO_CMD);
  2582. /* Poll the ready bit to see if the MDI read
  2583. * completed
  2584. */
  2585. for (i = 0; i < 64; i++) {
  2586. udelay(50);
  2587. mdic = readl(E1000_MDIO_CMD);
  2588. if (!(mdic & INTEL_CE_GBE_MDIC_GO))
  2589. break;
  2590. }
  2591. if (mdic & INTEL_CE_GBE_MDIC_GO) {
  2592. e_dbg("MDI Read did not complete\n");
  2593. return -E1000_ERR_PHY;
  2594. }
  2595. mdic = readl(E1000_MDIO_STS);
  2596. if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) {
  2597. e_dbg("MDI Read Error\n");
  2598. return -E1000_ERR_PHY;
  2599. }
  2600. *phy_data = (u16) mdic;
  2601. } else {
  2602. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2603. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2604. (E1000_MDIC_OP_READ));
  2605. ew32(MDIC, mdic);
  2606. /* Poll the ready bit to see if the MDI read
  2607. * completed
  2608. */
  2609. for (i = 0; i < 64; i++) {
  2610. udelay(50);
  2611. mdic = er32(MDIC);
  2612. if (mdic & E1000_MDIC_READY)
  2613. break;
  2614. }
  2615. if (!(mdic & E1000_MDIC_READY)) {
  2616. e_dbg("MDI Read did not complete\n");
  2617. return -E1000_ERR_PHY;
  2618. }
  2619. if (mdic & E1000_MDIC_ERROR) {
  2620. e_dbg("MDI Error\n");
  2621. return -E1000_ERR_PHY;
  2622. }
  2623. *phy_data = (u16) mdic;
  2624. }
  2625. } else {
  2626. /* We must first send a preamble through the MDIO pin to signal
  2627. * the beginning of an MII instruction. This is done by sending
  2628. * 32 consecutive "1" bits.
  2629. */
  2630. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2631. /* Now combine the next few fields that are required for a read
  2632. * operation. We use this method instead of calling the
  2633. * e1000_shift_out_mdi_bits routine five different times. The
  2634. * format of a MII read instruction consists of a shift out of
  2635. * 14 bits and is defined as follows:
  2636. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  2637. * followed by a shift in of 18 bits. This first two bits
  2638. * shifted in are TurnAround bits used to avoid contention on
  2639. * the MDIO pin when a READ operation is performed. These two
  2640. * bits are thrown away followed by a shift in of 16 bits which
  2641. * contains the desired data.
  2642. */
  2643. mdic = ((reg_addr) | (phy_addr << 5) |
  2644. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  2645. e1000_shift_out_mdi_bits(hw, mdic, 14);
  2646. /* Now that we've shifted out the read command to the MII, we
  2647. * need to "shift in" the 16-bit value (18 total bits) of the
  2648. * requested PHY register address.
  2649. */
  2650. *phy_data = e1000_shift_in_mdi_bits(hw);
  2651. }
  2652. return E1000_SUCCESS;
  2653. }
  2654. /**
  2655. * e1000_write_phy_reg - write a phy register
  2656. *
  2657. * @hw: Struct containing variables accessed by shared code
  2658. * @reg_addr: address of the PHY register to write
  2659. * @data: data to write to the PHY
  2660. *
  2661. * Writes a value to a PHY register
  2662. */
  2663. s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
  2664. {
  2665. u32 ret_val;
  2666. unsigned long flags;
  2667. e_dbg("e1000_write_phy_reg");
  2668. spin_lock_irqsave(&e1000_phy_lock, flags);
  2669. if ((hw->phy_type == e1000_phy_igp) &&
  2670. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2671. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2672. (u16) reg_addr);
  2673. if (ret_val) {
  2674. spin_unlock_irqrestore(&e1000_phy_lock, flags);
  2675. return ret_val;
  2676. }
  2677. }
  2678. ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2679. phy_data);
  2680. spin_unlock_irqrestore(&e1000_phy_lock, flags);
  2681. return ret_val;
  2682. }
  2683. static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
  2684. u16 phy_data)
  2685. {
  2686. u32 i;
  2687. u32 mdic = 0;
  2688. const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
  2689. e_dbg("e1000_write_phy_reg_ex");
  2690. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  2691. e_dbg("PHY Address %d is out of range\n", reg_addr);
  2692. return -E1000_ERR_PARAM;
  2693. }
  2694. if (hw->mac_type > e1000_82543) {
  2695. /* Set up Op-code, Phy Address, register address, and data
  2696. * intended for the PHY register in the MDI Control register.
  2697. * The MAC will take care of interfacing with the PHY to send
  2698. * the desired data.
  2699. */
  2700. if (hw->mac_type == e1000_ce4100) {
  2701. mdic = (((u32) phy_data) |
  2702. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2703. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2704. (INTEL_CE_GBE_MDIC_OP_WRITE) |
  2705. (INTEL_CE_GBE_MDIC_GO));
  2706. writel(mdic, E1000_MDIO_CMD);
  2707. /* Poll the ready bit to see if the MDI read
  2708. * completed
  2709. */
  2710. for (i = 0; i < 640; i++) {
  2711. udelay(5);
  2712. mdic = readl(E1000_MDIO_CMD);
  2713. if (!(mdic & INTEL_CE_GBE_MDIC_GO))
  2714. break;
  2715. }
  2716. if (mdic & INTEL_CE_GBE_MDIC_GO) {
  2717. e_dbg("MDI Write did not complete\n");
  2718. return -E1000_ERR_PHY;
  2719. }
  2720. } else {
  2721. mdic = (((u32) phy_data) |
  2722. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2723. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2724. (E1000_MDIC_OP_WRITE));
  2725. ew32(MDIC, mdic);
  2726. /* Poll the ready bit to see if the MDI read
  2727. * completed
  2728. */
  2729. for (i = 0; i < 641; i++) {
  2730. udelay(5);
  2731. mdic = er32(MDIC);
  2732. if (mdic & E1000_MDIC_READY)
  2733. break;
  2734. }
  2735. if (!(mdic & E1000_MDIC_READY)) {
  2736. e_dbg("MDI Write did not complete\n");
  2737. return -E1000_ERR_PHY;
  2738. }
  2739. }
  2740. } else {
  2741. /* We'll need to use the SW defined pins to shift the write
  2742. * command out to the PHY. We first send a preamble to the PHY
  2743. * to signal the beginning of the MII instruction. This is done
  2744. * by sending 32 consecutive "1" bits.
  2745. */
  2746. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2747. /* Now combine the remaining required fields that will indicate
  2748. * a write operation. We use this method instead of calling the
  2749. * e1000_shift_out_mdi_bits routine for each field in the
  2750. * command. The format of a MII write instruction is as follows:
  2751. * <Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>.
  2752. */
  2753. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  2754. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  2755. mdic <<= 16;
  2756. mdic |= (u32) phy_data;
  2757. e1000_shift_out_mdi_bits(hw, mdic, 32);
  2758. }
  2759. return E1000_SUCCESS;
  2760. }
  2761. /**
  2762. * e1000_phy_hw_reset - reset the phy, hardware style
  2763. * @hw: Struct containing variables accessed by shared code
  2764. *
  2765. * Returns the PHY to the power-on reset state
  2766. */
  2767. s32 e1000_phy_hw_reset(struct e1000_hw *hw)
  2768. {
  2769. u32 ctrl, ctrl_ext;
  2770. u32 led_ctrl;
  2771. e_dbg("e1000_phy_hw_reset");
  2772. e_dbg("Resetting Phy...\n");
  2773. if (hw->mac_type > e1000_82543) {
  2774. /* Read the device control register and assert the
  2775. * E1000_CTRL_PHY_RST bit. Then, take it out of reset.
  2776. * For e1000 hardware, we delay for 10ms between the assert
  2777. * and de-assert.
  2778. */
  2779. ctrl = er32(CTRL);
  2780. ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
  2781. E1000_WRITE_FLUSH();
  2782. msleep(10);
  2783. ew32(CTRL, ctrl);
  2784. E1000_WRITE_FLUSH();
  2785. } else {
  2786. /* Read the Extended Device Control Register, assert the
  2787. * PHY_RESET_DIR bit to put the PHY into reset. Then, take it
  2788. * out of reset.
  2789. */
  2790. ctrl_ext = er32(CTRL_EXT);
  2791. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  2792. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  2793. ew32(CTRL_EXT, ctrl_ext);
  2794. E1000_WRITE_FLUSH();
  2795. msleep(10);
  2796. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  2797. ew32(CTRL_EXT, ctrl_ext);
  2798. E1000_WRITE_FLUSH();
  2799. }
  2800. udelay(150);
  2801. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2802. /* Configure activity LED after PHY reset */
  2803. led_ctrl = er32(LEDCTL);
  2804. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2805. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2806. ew32(LEDCTL, led_ctrl);
  2807. }
  2808. /* Wait for FW to finish PHY configuration. */
  2809. return e1000_get_phy_cfg_done(hw);
  2810. }
  2811. /**
  2812. * e1000_phy_reset - reset the phy to commit settings
  2813. * @hw: Struct containing variables accessed by shared code
  2814. *
  2815. * Resets the PHY
  2816. * Sets bit 15 of the MII Control register
  2817. */
  2818. s32 e1000_phy_reset(struct e1000_hw *hw)
  2819. {
  2820. s32 ret_val;
  2821. u16 phy_data;
  2822. e_dbg("e1000_phy_reset");
  2823. switch (hw->phy_type) {
  2824. case e1000_phy_igp:
  2825. ret_val = e1000_phy_hw_reset(hw);
  2826. if (ret_val)
  2827. return ret_val;
  2828. break;
  2829. default:
  2830. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2831. if (ret_val)
  2832. return ret_val;
  2833. phy_data |= MII_CR_RESET;
  2834. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2835. if (ret_val)
  2836. return ret_val;
  2837. udelay(1);
  2838. break;
  2839. }
  2840. if (hw->phy_type == e1000_phy_igp)
  2841. e1000_phy_init_script(hw);
  2842. return E1000_SUCCESS;
  2843. }
  2844. /**
  2845. * e1000_detect_gig_phy - check the phy type
  2846. * @hw: Struct containing variables accessed by shared code
  2847. *
  2848. * Probes the expected PHY address for known PHY IDs
  2849. */
  2850. static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
  2851. {
  2852. s32 phy_init_status, ret_val;
  2853. u16 phy_id_high, phy_id_low;
  2854. bool match = false;
  2855. e_dbg("e1000_detect_gig_phy");
  2856. if (hw->phy_id != 0)
  2857. return E1000_SUCCESS;
  2858. /* Read the PHY ID Registers to identify which PHY is onboard. */
  2859. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  2860. if (ret_val)
  2861. return ret_val;
  2862. hw->phy_id = (u32) (phy_id_high << 16);
  2863. udelay(20);
  2864. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  2865. if (ret_val)
  2866. return ret_val;
  2867. hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
  2868. hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
  2869. switch (hw->mac_type) {
  2870. case e1000_82543:
  2871. if (hw->phy_id == M88E1000_E_PHY_ID)
  2872. match = true;
  2873. break;
  2874. case e1000_82544:
  2875. if (hw->phy_id == M88E1000_I_PHY_ID)
  2876. match = true;
  2877. break;
  2878. case e1000_82540:
  2879. case e1000_82545:
  2880. case e1000_82545_rev_3:
  2881. case e1000_82546:
  2882. case e1000_82546_rev_3:
  2883. if (hw->phy_id == M88E1011_I_PHY_ID)
  2884. match = true;
  2885. break;
  2886. case e1000_ce4100:
  2887. if ((hw->phy_id == RTL8211B_PHY_ID) ||
  2888. (hw->phy_id == RTL8201N_PHY_ID) ||
  2889. (hw->phy_id == M88E1118_E_PHY_ID))
  2890. match = true;
  2891. break;
  2892. case e1000_82541:
  2893. case e1000_82541_rev_2:
  2894. case e1000_82547:
  2895. case e1000_82547_rev_2:
  2896. if (hw->phy_id == IGP01E1000_I_PHY_ID)
  2897. match = true;
  2898. break;
  2899. default:
  2900. e_dbg("Invalid MAC type %d\n", hw->mac_type);
  2901. return -E1000_ERR_CONFIG;
  2902. }
  2903. phy_init_status = e1000_set_phy_type(hw);
  2904. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  2905. e_dbg("PHY ID 0x%X detected\n", hw->phy_id);
  2906. return E1000_SUCCESS;
  2907. }
  2908. e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id);
  2909. return -E1000_ERR_PHY;
  2910. }
  2911. /**
  2912. * e1000_phy_reset_dsp - reset DSP
  2913. * @hw: Struct containing variables accessed by shared code
  2914. *
  2915. * Resets the PHY's DSP
  2916. */
  2917. static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
  2918. {
  2919. s32 ret_val;
  2920. e_dbg("e1000_phy_reset_dsp");
  2921. do {
  2922. ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
  2923. if (ret_val)
  2924. break;
  2925. ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
  2926. if (ret_val)
  2927. break;
  2928. ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
  2929. if (ret_val)
  2930. break;
  2931. ret_val = E1000_SUCCESS;
  2932. } while (0);
  2933. return ret_val;
  2934. }
  2935. /**
  2936. * e1000_phy_igp_get_info - get igp specific registers
  2937. * @hw: Struct containing variables accessed by shared code
  2938. * @phy_info: PHY information structure
  2939. *
  2940. * Get PHY information from various PHY registers for igp PHY only.
  2941. */
  2942. static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
  2943. struct e1000_phy_info *phy_info)
  2944. {
  2945. s32 ret_val;
  2946. u16 phy_data, min_length, max_length, average;
  2947. e1000_rev_polarity polarity;
  2948. e_dbg("e1000_phy_igp_get_info");
  2949. /* The downshift status is checked only once, after link is established,
  2950. * and it stored in the hw->speed_downgraded parameter.
  2951. */
  2952. phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
  2953. /* IGP01E1000 does not need to support it. */
  2954. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
  2955. /* IGP01E1000 always correct polarity reversal */
  2956. phy_info->polarity_correction = e1000_polarity_reversal_enabled;
  2957. /* Check polarity status */
  2958. ret_val = e1000_check_polarity(hw, &polarity);
  2959. if (ret_val)
  2960. return ret_val;
  2961. phy_info->cable_polarity = polarity;
  2962. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
  2963. if (ret_val)
  2964. return ret_val;
  2965. phy_info->mdix_mode =
  2966. (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
  2967. IGP01E1000_PSSR_MDIX_SHIFT);
  2968. if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  2969. IGP01E1000_PSSR_SPEED_1000MBPS) {
  2970. /* Local/Remote Receiver Information are only valid @ 1000
  2971. * Mbps
  2972. */
  2973. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2974. if (ret_val)
  2975. return ret_val;
  2976. phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2977. SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
  2978. e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  2979. phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2980. SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
  2981. e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  2982. /* Get cable length */
  2983. ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
  2984. if (ret_val)
  2985. return ret_val;
  2986. /* Translate to old method */
  2987. average = (max_length + min_length) / 2;
  2988. if (average <= e1000_igp_cable_length_50)
  2989. phy_info->cable_length = e1000_cable_length_50;
  2990. else if (average <= e1000_igp_cable_length_80)
  2991. phy_info->cable_length = e1000_cable_length_50_80;
  2992. else if (average <= e1000_igp_cable_length_110)
  2993. phy_info->cable_length = e1000_cable_length_80_110;
  2994. else if (average <= e1000_igp_cable_length_140)
  2995. phy_info->cable_length = e1000_cable_length_110_140;
  2996. else
  2997. phy_info->cable_length = e1000_cable_length_140;
  2998. }
  2999. return E1000_SUCCESS;
  3000. }
  3001. /**
  3002. * e1000_phy_m88_get_info - get m88 specific registers
  3003. * @hw: Struct containing variables accessed by shared code
  3004. * @phy_info: PHY information structure
  3005. *
  3006. * Get PHY information from various PHY registers for m88 PHY only.
  3007. */
  3008. static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
  3009. struct e1000_phy_info *phy_info)
  3010. {
  3011. s32 ret_val;
  3012. u16 phy_data;
  3013. e1000_rev_polarity polarity;
  3014. e_dbg("e1000_phy_m88_get_info");
  3015. /* The downshift status is checked only once, after link is established,
  3016. * and it stored in the hw->speed_downgraded parameter.
  3017. */
  3018. phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
  3019. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  3020. if (ret_val)
  3021. return ret_val;
  3022. phy_info->extended_10bt_distance =
  3023. ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
  3024. M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
  3025. e1000_10bt_ext_dist_enable_lower :
  3026. e1000_10bt_ext_dist_enable_normal;
  3027. phy_info->polarity_correction =
  3028. ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
  3029. M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
  3030. e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
  3031. /* Check polarity status */
  3032. ret_val = e1000_check_polarity(hw, &polarity);
  3033. if (ret_val)
  3034. return ret_val;
  3035. phy_info->cable_polarity = polarity;
  3036. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  3037. if (ret_val)
  3038. return ret_val;
  3039. phy_info->mdix_mode =
  3040. (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
  3041. M88E1000_PSSR_MDIX_SHIFT);
  3042. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  3043. /* Cable Length Estimation and Local/Remote Receiver Information
  3044. * are only valid at 1000 Mbps.
  3045. */
  3046. phy_info->cable_length =
  3047. (e1000_cable_length) ((phy_data &
  3048. M88E1000_PSSR_CABLE_LENGTH) >>
  3049. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  3050. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  3051. if (ret_val)
  3052. return ret_val;
  3053. phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  3054. SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
  3055. e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  3056. phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  3057. SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
  3058. e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  3059. }
  3060. return E1000_SUCCESS;
  3061. }
  3062. /**
  3063. * e1000_phy_get_info - request phy info
  3064. * @hw: Struct containing variables accessed by shared code
  3065. * @phy_info: PHY information structure
  3066. *
  3067. * Get PHY information from various PHY registers
  3068. */
  3069. s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
  3070. {
  3071. s32 ret_val;
  3072. u16 phy_data;
  3073. e_dbg("e1000_phy_get_info");
  3074. phy_info->cable_length = e1000_cable_length_undefined;
  3075. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
  3076. phy_info->cable_polarity = e1000_rev_polarity_undefined;
  3077. phy_info->downshift = e1000_downshift_undefined;
  3078. phy_info->polarity_correction = e1000_polarity_reversal_undefined;
  3079. phy_info->mdix_mode = e1000_auto_x_mode_undefined;
  3080. phy_info->local_rx = e1000_1000t_rx_status_undefined;
  3081. phy_info->remote_rx = e1000_1000t_rx_status_undefined;
  3082. if (hw->media_type != e1000_media_type_copper) {
  3083. e_dbg("PHY info is only valid for copper media\n");
  3084. return -E1000_ERR_CONFIG;
  3085. }
  3086. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  3087. if (ret_val)
  3088. return ret_val;
  3089. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  3090. if (ret_val)
  3091. return ret_val;
  3092. if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
  3093. e_dbg("PHY info is only valid if link is up\n");
  3094. return -E1000_ERR_CONFIG;
  3095. }
  3096. if (hw->phy_type == e1000_phy_igp)
  3097. return e1000_phy_igp_get_info(hw, phy_info);
  3098. else if ((hw->phy_type == e1000_phy_8211) ||
  3099. (hw->phy_type == e1000_phy_8201))
  3100. return E1000_SUCCESS;
  3101. else
  3102. return e1000_phy_m88_get_info(hw, phy_info);
  3103. }
  3104. s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
  3105. {
  3106. e_dbg("e1000_validate_mdi_settings");
  3107. if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
  3108. e_dbg("Invalid MDI setting detected\n");
  3109. hw->mdix = 1;
  3110. return -E1000_ERR_CONFIG;
  3111. }
  3112. return E1000_SUCCESS;
  3113. }
  3114. /**
  3115. * e1000_init_eeprom_params - initialize sw eeprom vars
  3116. * @hw: Struct containing variables accessed by shared code
  3117. *
  3118. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  3119. * is configured.
  3120. */
  3121. s32 e1000_init_eeprom_params(struct e1000_hw *hw)
  3122. {
  3123. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3124. u32 eecd = er32(EECD);
  3125. s32 ret_val = E1000_SUCCESS;
  3126. u16 eeprom_size;
  3127. e_dbg("e1000_init_eeprom_params");
  3128. switch (hw->mac_type) {
  3129. case e1000_82542_rev2_0:
  3130. case e1000_82542_rev2_1:
  3131. case e1000_82543:
  3132. case e1000_82544:
  3133. eeprom->type = e1000_eeprom_microwire;
  3134. eeprom->word_size = 64;
  3135. eeprom->opcode_bits = 3;
  3136. eeprom->address_bits = 6;
  3137. eeprom->delay_usec = 50;
  3138. break;
  3139. case e1000_82540:
  3140. case e1000_82545:
  3141. case e1000_82545_rev_3:
  3142. case e1000_82546:
  3143. case e1000_82546_rev_3:
  3144. eeprom->type = e1000_eeprom_microwire;
  3145. eeprom->opcode_bits = 3;
  3146. eeprom->delay_usec = 50;
  3147. if (eecd & E1000_EECD_SIZE) {
  3148. eeprom->word_size = 256;
  3149. eeprom->address_bits = 8;
  3150. } else {
  3151. eeprom->word_size = 64;
  3152. eeprom->address_bits = 6;
  3153. }
  3154. break;
  3155. case e1000_82541:
  3156. case e1000_82541_rev_2:
  3157. case e1000_82547:
  3158. case e1000_82547_rev_2:
  3159. if (eecd & E1000_EECD_TYPE) {
  3160. eeprom->type = e1000_eeprom_spi;
  3161. eeprom->opcode_bits = 8;
  3162. eeprom->delay_usec = 1;
  3163. if (eecd & E1000_EECD_ADDR_BITS) {
  3164. eeprom->page_size = 32;
  3165. eeprom->address_bits = 16;
  3166. } else {
  3167. eeprom->page_size = 8;
  3168. eeprom->address_bits = 8;
  3169. }
  3170. } else {
  3171. eeprom->type = e1000_eeprom_microwire;
  3172. eeprom->opcode_bits = 3;
  3173. eeprom->delay_usec = 50;
  3174. if (eecd & E1000_EECD_ADDR_BITS) {
  3175. eeprom->word_size = 256;
  3176. eeprom->address_bits = 8;
  3177. } else {
  3178. eeprom->word_size = 64;
  3179. eeprom->address_bits = 6;
  3180. }
  3181. }
  3182. break;
  3183. default:
  3184. break;
  3185. }
  3186. if (eeprom->type == e1000_eeprom_spi) {
  3187. /* eeprom_size will be an enum [0..8] that maps to eeprom sizes
  3188. * 128B to 32KB (incremented by powers of 2).
  3189. */
  3190. /* Set to default value for initial eeprom read. */
  3191. eeprom->word_size = 64;
  3192. ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
  3193. if (ret_val)
  3194. return ret_val;
  3195. eeprom_size =
  3196. (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
  3197. /* 256B eeprom size was not supported in earlier hardware, so we
  3198. * bump eeprom_size up one to ensure that "1" (which maps to
  3199. * 256B) is never the result used in the shifting logic below.
  3200. */
  3201. if (eeprom_size)
  3202. eeprom_size++;
  3203. eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
  3204. }
  3205. return ret_val;
  3206. }
  3207. /**
  3208. * e1000_raise_ee_clk - Raises the EEPROM's clock input.
  3209. * @hw: Struct containing variables accessed by shared code
  3210. * @eecd: EECD's current value
  3211. */
  3212. static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
  3213. {
  3214. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  3215. * wait <delay> microseconds.
  3216. */
  3217. *eecd = *eecd | E1000_EECD_SK;
  3218. ew32(EECD, *eecd);
  3219. E1000_WRITE_FLUSH();
  3220. udelay(hw->eeprom.delay_usec);
  3221. }
  3222. /**
  3223. * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
  3224. * @hw: Struct containing variables accessed by shared code
  3225. * @eecd: EECD's current value
  3226. */
  3227. static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
  3228. {
  3229. /* Lower the clock input to the EEPROM (by clearing the SK bit), and
  3230. * then wait 50 microseconds.
  3231. */
  3232. *eecd = *eecd & ~E1000_EECD_SK;
  3233. ew32(EECD, *eecd);
  3234. E1000_WRITE_FLUSH();
  3235. udelay(hw->eeprom.delay_usec);
  3236. }
  3237. /**
  3238. * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
  3239. * @hw: Struct containing variables accessed by shared code
  3240. * @data: data to send to the EEPROM
  3241. * @count: number of bits to shift out
  3242. */
  3243. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
  3244. {
  3245. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3246. u32 eecd;
  3247. u32 mask;
  3248. /* We need to shift "count" bits out to the EEPROM. So, value in the
  3249. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  3250. * In order to do this, "data" must be broken down into bits.
  3251. */
  3252. mask = 0x01 << (count - 1);
  3253. eecd = er32(EECD);
  3254. if (eeprom->type == e1000_eeprom_microwire) {
  3255. eecd &= ~E1000_EECD_DO;
  3256. } else if (eeprom->type == e1000_eeprom_spi) {
  3257. eecd |= E1000_EECD_DO;
  3258. }
  3259. do {
  3260. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a
  3261. * "1", and then raising and then lowering the clock (the SK bit
  3262. * controls the clock input to the EEPROM). A "0" is shifted
  3263. * out to the EEPROM by setting "DI" to "0" and then raising and
  3264. * then lowering the clock.
  3265. */
  3266. eecd &= ~E1000_EECD_DI;
  3267. if (data & mask)
  3268. eecd |= E1000_EECD_DI;
  3269. ew32(EECD, eecd);
  3270. E1000_WRITE_FLUSH();
  3271. udelay(eeprom->delay_usec);
  3272. e1000_raise_ee_clk(hw, &eecd);
  3273. e1000_lower_ee_clk(hw, &eecd);
  3274. mask = mask >> 1;
  3275. } while (mask);
  3276. /* We leave the "DI" bit set to "0" when we leave this routine. */
  3277. eecd &= ~E1000_EECD_DI;
  3278. ew32(EECD, eecd);
  3279. }
  3280. /**
  3281. * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
  3282. * @hw: Struct containing variables accessed by shared code
  3283. * @count: number of bits to shift in
  3284. */
  3285. static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
  3286. {
  3287. u32 eecd;
  3288. u32 i;
  3289. u16 data;
  3290. /* In order to read a register from the EEPROM, we need to shift 'count'
  3291. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  3292. * input to the EEPROM (setting the SK bit), and then reading the value
  3293. * of the "DO" bit. During this "shifting in" process the "DI" bit
  3294. * should always be clear.
  3295. */
  3296. eecd = er32(EECD);
  3297. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  3298. data = 0;
  3299. for (i = 0; i < count; i++) {
  3300. data = data << 1;
  3301. e1000_raise_ee_clk(hw, &eecd);
  3302. eecd = er32(EECD);
  3303. eecd &= ~(E1000_EECD_DI);
  3304. if (eecd & E1000_EECD_DO)
  3305. data |= 1;
  3306. e1000_lower_ee_clk(hw, &eecd);
  3307. }
  3308. return data;
  3309. }
  3310. /**
  3311. * e1000_acquire_eeprom - Prepares EEPROM for access
  3312. * @hw: Struct containing variables accessed by shared code
  3313. *
  3314. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  3315. * function should be called before issuing a command to the EEPROM.
  3316. */
  3317. static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
  3318. {
  3319. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3320. u32 eecd, i = 0;
  3321. e_dbg("e1000_acquire_eeprom");
  3322. eecd = er32(EECD);
  3323. /* Request EEPROM Access */
  3324. if (hw->mac_type > e1000_82544) {
  3325. eecd |= E1000_EECD_REQ;
  3326. ew32(EECD, eecd);
  3327. eecd = er32(EECD);
  3328. while ((!(eecd & E1000_EECD_GNT)) &&
  3329. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  3330. i++;
  3331. udelay(5);
  3332. eecd = er32(EECD);
  3333. }
  3334. if (!(eecd & E1000_EECD_GNT)) {
  3335. eecd &= ~E1000_EECD_REQ;
  3336. ew32(EECD, eecd);
  3337. e_dbg("Could not acquire EEPROM grant\n");
  3338. return -E1000_ERR_EEPROM;
  3339. }
  3340. }
  3341. /* Setup EEPROM for Read/Write */
  3342. if (eeprom->type == e1000_eeprom_microwire) {
  3343. /* Clear SK and DI */
  3344. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  3345. ew32(EECD, eecd);
  3346. /* Set CS */
  3347. eecd |= E1000_EECD_CS;
  3348. ew32(EECD, eecd);
  3349. } else if (eeprom->type == e1000_eeprom_spi) {
  3350. /* Clear SK and CS */
  3351. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3352. ew32(EECD, eecd);
  3353. E1000_WRITE_FLUSH();
  3354. udelay(1);
  3355. }
  3356. return E1000_SUCCESS;
  3357. }
  3358. /**
  3359. * e1000_standby_eeprom - Returns EEPROM to a "standby" state
  3360. * @hw: Struct containing variables accessed by shared code
  3361. */
  3362. static void e1000_standby_eeprom(struct e1000_hw *hw)
  3363. {
  3364. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3365. u32 eecd;
  3366. eecd = er32(EECD);
  3367. if (eeprom->type == e1000_eeprom_microwire) {
  3368. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3369. ew32(EECD, eecd);
  3370. E1000_WRITE_FLUSH();
  3371. udelay(eeprom->delay_usec);
  3372. /* Clock high */
  3373. eecd |= E1000_EECD_SK;
  3374. ew32(EECD, eecd);
  3375. E1000_WRITE_FLUSH();
  3376. udelay(eeprom->delay_usec);
  3377. /* Select EEPROM */
  3378. eecd |= E1000_EECD_CS;
  3379. ew32(EECD, eecd);
  3380. E1000_WRITE_FLUSH();
  3381. udelay(eeprom->delay_usec);
  3382. /* Clock low */
  3383. eecd &= ~E1000_EECD_SK;
  3384. ew32(EECD, eecd);
  3385. E1000_WRITE_FLUSH();
  3386. udelay(eeprom->delay_usec);
  3387. } else if (eeprom->type == e1000_eeprom_spi) {
  3388. /* Toggle CS to flush commands */
  3389. eecd |= E1000_EECD_CS;
  3390. ew32(EECD, eecd);
  3391. E1000_WRITE_FLUSH();
  3392. udelay(eeprom->delay_usec);
  3393. eecd &= ~E1000_EECD_CS;
  3394. ew32(EECD, eecd);
  3395. E1000_WRITE_FLUSH();
  3396. udelay(eeprom->delay_usec);
  3397. }
  3398. }
  3399. /**
  3400. * e1000_release_eeprom - drop chip select
  3401. * @hw: Struct containing variables accessed by shared code
  3402. *
  3403. * Terminates a command by inverting the EEPROM's chip select pin
  3404. */
  3405. static void e1000_release_eeprom(struct e1000_hw *hw)
  3406. {
  3407. u32 eecd;
  3408. e_dbg("e1000_release_eeprom");
  3409. eecd = er32(EECD);
  3410. if (hw->eeprom.type == e1000_eeprom_spi) {
  3411. eecd |= E1000_EECD_CS; /* Pull CS high */
  3412. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  3413. ew32(EECD, eecd);
  3414. E1000_WRITE_FLUSH();
  3415. udelay(hw->eeprom.delay_usec);
  3416. } else if (hw->eeprom.type == e1000_eeprom_microwire) {
  3417. /* cleanup eeprom */
  3418. /* CS on Microwire is active-high */
  3419. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  3420. ew32(EECD, eecd);
  3421. /* Rising edge of clock */
  3422. eecd |= E1000_EECD_SK;
  3423. ew32(EECD, eecd);
  3424. E1000_WRITE_FLUSH();
  3425. udelay(hw->eeprom.delay_usec);
  3426. /* Falling edge of clock */
  3427. eecd &= ~E1000_EECD_SK;
  3428. ew32(EECD, eecd);
  3429. E1000_WRITE_FLUSH();
  3430. udelay(hw->eeprom.delay_usec);
  3431. }
  3432. /* Stop requesting EEPROM access */
  3433. if (hw->mac_type > e1000_82544) {
  3434. eecd &= ~E1000_EECD_REQ;
  3435. ew32(EECD, eecd);
  3436. }
  3437. }
  3438. /**
  3439. * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
  3440. * @hw: Struct containing variables accessed by shared code
  3441. */
  3442. static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
  3443. {
  3444. u16 retry_count = 0;
  3445. u8 spi_stat_reg;
  3446. e_dbg("e1000_spi_eeprom_ready");
  3447. /* Read "Status Register" repeatedly until the LSB is cleared. The
  3448. * EEPROM will signal that the command has been completed by clearing
  3449. * bit 0 of the internal status register. If it's not cleared within
  3450. * 5 milliseconds, then error out.
  3451. */
  3452. retry_count = 0;
  3453. do {
  3454. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  3455. hw->eeprom.opcode_bits);
  3456. spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
  3457. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  3458. break;
  3459. udelay(5);
  3460. retry_count += 5;
  3461. e1000_standby_eeprom(hw);
  3462. } while (retry_count < EEPROM_MAX_RETRY_SPI);
  3463. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  3464. * only 0-5mSec on 5V devices)
  3465. */
  3466. if (retry_count >= EEPROM_MAX_RETRY_SPI) {
  3467. e_dbg("SPI EEPROM Status error\n");
  3468. return -E1000_ERR_EEPROM;
  3469. }
  3470. return E1000_SUCCESS;
  3471. }
  3472. /**
  3473. * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
  3474. * @hw: Struct containing variables accessed by shared code
  3475. * @offset: offset of word in the EEPROM to read
  3476. * @data: word read from the EEPROM
  3477. * @words: number of words to read
  3478. */
  3479. s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
  3480. {
  3481. s32 ret;
  3482. spin_lock(&e1000_eeprom_lock);
  3483. ret = e1000_do_read_eeprom(hw, offset, words, data);
  3484. spin_unlock(&e1000_eeprom_lock);
  3485. return ret;
  3486. }
  3487. static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
  3488. u16 *data)
  3489. {
  3490. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3491. u32 i = 0;
  3492. e_dbg("e1000_read_eeprom");
  3493. if (hw->mac_type == e1000_ce4100) {
  3494. GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words,
  3495. data);
  3496. return E1000_SUCCESS;
  3497. }
  3498. /* If eeprom is not yet detected, do so now */
  3499. if (eeprom->word_size == 0)
  3500. e1000_init_eeprom_params(hw);
  3501. /* A check for invalid values: offset too large, too many words, and
  3502. * not enough words.
  3503. */
  3504. if ((offset >= eeprom->word_size)
  3505. || (words > eeprom->word_size - offset) || (words == 0)) {
  3506. e_dbg("\"words\" parameter out of bounds. Words = %d,"
  3507. "size = %d\n", offset, eeprom->word_size);
  3508. return -E1000_ERR_EEPROM;
  3509. }
  3510. /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
  3511. * directly. In this case, we need to acquire the EEPROM so that
  3512. * FW or other port software does not interrupt.
  3513. */
  3514. /* Prepare the EEPROM for bit-bang reading */
  3515. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3516. return -E1000_ERR_EEPROM;
  3517. /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
  3518. * acquired the EEPROM at this point, so any returns should release it
  3519. */
  3520. if (eeprom->type == e1000_eeprom_spi) {
  3521. u16 word_in;
  3522. u8 read_opcode = EEPROM_READ_OPCODE_SPI;
  3523. if (e1000_spi_eeprom_ready(hw)) {
  3524. e1000_release_eeprom(hw);
  3525. return -E1000_ERR_EEPROM;
  3526. }
  3527. e1000_standby_eeprom(hw);
  3528. /* Some SPI eeproms use the 8th address bit embedded in the
  3529. * opcode
  3530. */
  3531. if ((eeprom->address_bits == 8) && (offset >= 128))
  3532. read_opcode |= EEPROM_A8_OPCODE_SPI;
  3533. /* Send the READ command (opcode + addr) */
  3534. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  3535. e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
  3536. eeprom->address_bits);
  3537. /* Read the data. The address of the eeprom internally
  3538. * increments with each byte (spi) being read, saving on the
  3539. * overhead of eeprom setup and tear-down. The address counter
  3540. * will roll over if reading beyond the size of the eeprom, thus
  3541. * allowing the entire memory to be read starting from any
  3542. * offset.
  3543. */
  3544. for (i = 0; i < words; i++) {
  3545. word_in = e1000_shift_in_ee_bits(hw, 16);
  3546. data[i] = (word_in >> 8) | (word_in << 8);
  3547. }
  3548. } else if (eeprom->type == e1000_eeprom_microwire) {
  3549. for (i = 0; i < words; i++) {
  3550. /* Send the READ command (opcode + addr) */
  3551. e1000_shift_out_ee_bits(hw,
  3552. EEPROM_READ_OPCODE_MICROWIRE,
  3553. eeprom->opcode_bits);
  3554. e1000_shift_out_ee_bits(hw, (u16) (offset + i),
  3555. eeprom->address_bits);
  3556. /* Read the data. For microwire, each word requires the
  3557. * overhead of eeprom setup and tear-down.
  3558. */
  3559. data[i] = e1000_shift_in_ee_bits(hw, 16);
  3560. e1000_standby_eeprom(hw);
  3561. }
  3562. }
  3563. /* End this read operation */
  3564. e1000_release_eeprom(hw);
  3565. return E1000_SUCCESS;
  3566. }
  3567. /**
  3568. * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
  3569. * @hw: Struct containing variables accessed by shared code
  3570. *
  3571. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  3572. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  3573. * valid.
  3574. */
  3575. s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  3576. {
  3577. u16 checksum = 0;
  3578. u16 i, eeprom_data;
  3579. e_dbg("e1000_validate_eeprom_checksum");
  3580. for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  3581. if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3582. e_dbg("EEPROM Read Error\n");
  3583. return -E1000_ERR_EEPROM;
  3584. }
  3585. checksum += eeprom_data;
  3586. }
  3587. #ifdef CONFIG_PARISC
  3588. /* This is a signature and not a checksum on HP c8000 */
  3589. if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6))
  3590. return E1000_SUCCESS;
  3591. #endif
  3592. if (checksum == (u16) EEPROM_SUM)
  3593. return E1000_SUCCESS;
  3594. else {
  3595. e_dbg("EEPROM Checksum Invalid\n");
  3596. return -E1000_ERR_EEPROM;
  3597. }
  3598. }
  3599. /**
  3600. * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
  3601. * @hw: Struct containing variables accessed by shared code
  3602. *
  3603. * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
  3604. * Writes the difference to word offset 63 of the EEPROM.
  3605. */
  3606. s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
  3607. {
  3608. u16 checksum = 0;
  3609. u16 i, eeprom_data;
  3610. e_dbg("e1000_update_eeprom_checksum");
  3611. for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
  3612. if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3613. e_dbg("EEPROM Read Error\n");
  3614. return -E1000_ERR_EEPROM;
  3615. }
  3616. checksum += eeprom_data;
  3617. }
  3618. checksum = (u16) EEPROM_SUM - checksum;
  3619. if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
  3620. e_dbg("EEPROM Write Error\n");
  3621. return -E1000_ERR_EEPROM;
  3622. }
  3623. return E1000_SUCCESS;
  3624. }
  3625. /**
  3626. * e1000_write_eeprom - write words to the different EEPROM types.
  3627. * @hw: Struct containing variables accessed by shared code
  3628. * @offset: offset within the EEPROM to be written to
  3629. * @words: number of words to write
  3630. * @data: 16 bit word to be written to the EEPROM
  3631. *
  3632. * If e1000_update_eeprom_checksum is not called after this function, the
  3633. * EEPROM will most likely contain an invalid checksum.
  3634. */
  3635. s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
  3636. {
  3637. s32 ret;
  3638. spin_lock(&e1000_eeprom_lock);
  3639. ret = e1000_do_write_eeprom(hw, offset, words, data);
  3640. spin_unlock(&e1000_eeprom_lock);
  3641. return ret;
  3642. }
  3643. static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
  3644. u16 *data)
  3645. {
  3646. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3647. s32 status = 0;
  3648. e_dbg("e1000_write_eeprom");
  3649. if (hw->mac_type == e1000_ce4100) {
  3650. GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words,
  3651. data);
  3652. return E1000_SUCCESS;
  3653. }
  3654. /* If eeprom is not yet detected, do so now */
  3655. if (eeprom->word_size == 0)
  3656. e1000_init_eeprom_params(hw);
  3657. /* A check for invalid values: offset too large, too many words, and
  3658. * not enough words.
  3659. */
  3660. if ((offset >= eeprom->word_size)
  3661. || (words > eeprom->word_size - offset) || (words == 0)) {
  3662. e_dbg("\"words\" parameter out of bounds\n");
  3663. return -E1000_ERR_EEPROM;
  3664. }
  3665. /* Prepare the EEPROM for writing */
  3666. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3667. return -E1000_ERR_EEPROM;
  3668. if (eeprom->type == e1000_eeprom_microwire) {
  3669. status = e1000_write_eeprom_microwire(hw, offset, words, data);
  3670. } else {
  3671. status = e1000_write_eeprom_spi(hw, offset, words, data);
  3672. msleep(10);
  3673. }
  3674. /* Done with writing */
  3675. e1000_release_eeprom(hw);
  3676. return status;
  3677. }
  3678. /**
  3679. * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
  3680. * @hw: Struct containing variables accessed by shared code
  3681. * @offset: offset within the EEPROM to be written to
  3682. * @words: number of words to write
  3683. * @data: pointer to array of 8 bit words to be written to the EEPROM
  3684. */
  3685. static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
  3686. u16 *data)
  3687. {
  3688. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3689. u16 widx = 0;
  3690. e_dbg("e1000_write_eeprom_spi");
  3691. while (widx < words) {
  3692. u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
  3693. if (e1000_spi_eeprom_ready(hw))
  3694. return -E1000_ERR_EEPROM;
  3695. e1000_standby_eeprom(hw);
  3696. /* Send the WRITE ENABLE command (8 bit opcode ) */
  3697. e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
  3698. eeprom->opcode_bits);
  3699. e1000_standby_eeprom(hw);
  3700. /* Some SPI eeproms use the 8th address bit embedded in the
  3701. * opcode
  3702. */
  3703. if ((eeprom->address_bits == 8) && (offset >= 128))
  3704. write_opcode |= EEPROM_A8_OPCODE_SPI;
  3705. /* Send the Write command (8-bit opcode + addr) */
  3706. e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
  3707. e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
  3708. eeprom->address_bits);
  3709. /* Send the data */
  3710. /* Loop to allow for up to whole page write (32 bytes) of
  3711. * eeprom
  3712. */
  3713. while (widx < words) {
  3714. u16 word_out = data[widx];
  3715. word_out = (word_out >> 8) | (word_out << 8);
  3716. e1000_shift_out_ee_bits(hw, word_out, 16);
  3717. widx++;
  3718. /* Some larger eeprom sizes are capable of a 32-byte
  3719. * PAGE WRITE operation, while the smaller eeproms are
  3720. * capable of an 8-byte PAGE WRITE operation. Break the
  3721. * inner loop to pass new address
  3722. */
  3723. if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
  3724. e1000_standby_eeprom(hw);
  3725. break;
  3726. }
  3727. }
  3728. }
  3729. return E1000_SUCCESS;
  3730. }
  3731. /**
  3732. * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
  3733. * @hw: Struct containing variables accessed by shared code
  3734. * @offset: offset within the EEPROM to be written to
  3735. * @words: number of words to write
  3736. * @data: pointer to array of 8 bit words to be written to the EEPROM
  3737. */
  3738. static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
  3739. u16 words, u16 *data)
  3740. {
  3741. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3742. u32 eecd;
  3743. u16 words_written = 0;
  3744. u16 i = 0;
  3745. e_dbg("e1000_write_eeprom_microwire");
  3746. /* Send the write enable command to the EEPROM (3-bit opcode plus
  3747. * 6/8-bit dummy address beginning with 11). It's less work to include
  3748. * the 11 of the dummy address as part of the opcode than it is to shift
  3749. * it over the correct number of bits for the address. This puts the
  3750. * EEPROM into write/erase mode.
  3751. */
  3752. e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
  3753. (u16) (eeprom->opcode_bits + 2));
  3754. e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
  3755. /* Prepare the EEPROM */
  3756. e1000_standby_eeprom(hw);
  3757. while (words_written < words) {
  3758. /* Send the Write command (3-bit opcode + addr) */
  3759. e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
  3760. eeprom->opcode_bits);
  3761. e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
  3762. eeprom->address_bits);
  3763. /* Send the data */
  3764. e1000_shift_out_ee_bits(hw, data[words_written], 16);
  3765. /* Toggle the CS line. This in effect tells the EEPROM to
  3766. * execute the previous command.
  3767. */
  3768. e1000_standby_eeprom(hw);
  3769. /* Read DO repeatedly until it is high (equal to '1'). The
  3770. * EEPROM will signal that the command has been completed by
  3771. * raising the DO signal. If DO does not go high in 10
  3772. * milliseconds, then error out.
  3773. */
  3774. for (i = 0; i < 200; i++) {
  3775. eecd = er32(EECD);
  3776. if (eecd & E1000_EECD_DO)
  3777. break;
  3778. udelay(50);
  3779. }
  3780. if (i == 200) {
  3781. e_dbg("EEPROM Write did not complete\n");
  3782. return -E1000_ERR_EEPROM;
  3783. }
  3784. /* Recover from write */
  3785. e1000_standby_eeprom(hw);
  3786. words_written++;
  3787. }
  3788. /* Send the write disable command to the EEPROM (3-bit opcode plus
  3789. * 6/8-bit dummy address beginning with 10). It's less work to include
  3790. * the 10 of the dummy address as part of the opcode than it is to shift
  3791. * it over the correct number of bits for the address. This takes the
  3792. * EEPROM out of write/erase mode.
  3793. */
  3794. e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
  3795. (u16) (eeprom->opcode_bits + 2));
  3796. e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
  3797. return E1000_SUCCESS;
  3798. }
  3799. /**
  3800. * e1000_read_mac_addr - read the adapters MAC from eeprom
  3801. * @hw: Struct containing variables accessed by shared code
  3802. *
  3803. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  3804. * second function of dual function devices
  3805. */
  3806. s32 e1000_read_mac_addr(struct e1000_hw *hw)
  3807. {
  3808. u16 offset;
  3809. u16 eeprom_data, i;
  3810. e_dbg("e1000_read_mac_addr");
  3811. for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  3812. offset = i >> 1;
  3813. if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3814. e_dbg("EEPROM Read Error\n");
  3815. return -E1000_ERR_EEPROM;
  3816. }
  3817. hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
  3818. hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
  3819. }
  3820. switch (hw->mac_type) {
  3821. default:
  3822. break;
  3823. case e1000_82546:
  3824. case e1000_82546_rev_3:
  3825. if (er32(STATUS) & E1000_STATUS_FUNC_1)
  3826. hw->perm_mac_addr[5] ^= 0x01;
  3827. break;
  3828. }
  3829. for (i = 0; i < NODE_ADDRESS_SIZE; i++)
  3830. hw->mac_addr[i] = hw->perm_mac_addr[i];
  3831. return E1000_SUCCESS;
  3832. }
  3833. /**
  3834. * e1000_init_rx_addrs - Initializes receive address filters.
  3835. * @hw: Struct containing variables accessed by shared code
  3836. *
  3837. * Places the MAC address in receive address register 0 and clears the rest
  3838. * of the receive address registers. Clears the multicast table. Assumes
  3839. * the receiver is in reset when the routine is called.
  3840. */
  3841. static void e1000_init_rx_addrs(struct e1000_hw *hw)
  3842. {
  3843. u32 i;
  3844. u32 rar_num;
  3845. e_dbg("e1000_init_rx_addrs");
  3846. /* Setup the receive address. */
  3847. e_dbg("Programming MAC Address into RAR[0]\n");
  3848. e1000_rar_set(hw, hw->mac_addr, 0);
  3849. rar_num = E1000_RAR_ENTRIES;
  3850. /* Zero out the other 15 receive addresses. */
  3851. e_dbg("Clearing RAR[1-15]\n");
  3852. for (i = 1; i < rar_num; i++) {
  3853. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3854. E1000_WRITE_FLUSH();
  3855. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3856. E1000_WRITE_FLUSH();
  3857. }
  3858. }
  3859. /**
  3860. * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
  3861. * @hw: Struct containing variables accessed by shared code
  3862. * @mc_addr: the multicast address to hash
  3863. */
  3864. u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
  3865. {
  3866. u32 hash_value = 0;
  3867. /* The portion of the address that is used for the hash table is
  3868. * determined by the mc_filter_type setting.
  3869. */
  3870. switch (hw->mc_filter_type) {
  3871. /* [0] [1] [2] [3] [4] [5]
  3872. * 01 AA 00 12 34 56
  3873. * LSB MSB
  3874. */
  3875. case 0:
  3876. /* [47:36] i.e. 0x563 for above example address */
  3877. hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
  3878. break;
  3879. case 1:
  3880. /* [46:35] i.e. 0xAC6 for above example address */
  3881. hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
  3882. break;
  3883. case 2:
  3884. /* [45:34] i.e. 0x5D8 for above example address */
  3885. hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
  3886. break;
  3887. case 3:
  3888. /* [43:32] i.e. 0x634 for above example address */
  3889. hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
  3890. break;
  3891. }
  3892. hash_value &= 0xFFF;
  3893. return hash_value;
  3894. }
  3895. /**
  3896. * e1000_rar_set - Puts an ethernet address into a receive address register.
  3897. * @hw: Struct containing variables accessed by shared code
  3898. * @addr: Address to put into receive address register
  3899. * @index: Receive address register to write
  3900. */
  3901. void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
  3902. {
  3903. u32 rar_low, rar_high;
  3904. /* HW expects these in little endian so we reverse the byte order
  3905. * from network order (big endian) to little endian
  3906. */
  3907. rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
  3908. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  3909. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  3910. /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
  3911. * unit hang.
  3912. *
  3913. * Description:
  3914. * If there are any Rx frames queued up or otherwise present in the HW
  3915. * before RSS is enabled, and then we enable RSS, the HW Rx unit will
  3916. * hang. To work around this issue, we have to disable receives and
  3917. * flush out all Rx frames before we enable RSS. To do so, we modify we
  3918. * redirect all Rx traffic to manageability and then reset the HW.
  3919. * This flushes away Rx frames, and (since the redirections to
  3920. * manageability persists across resets) keeps new ones from coming in
  3921. * while we work. Then, we clear the Address Valid AV bit for all MAC
  3922. * addresses and undo the re-direction to manageability.
  3923. * Now, frames are coming in again, but the MAC won't accept them, so
  3924. * far so good. We now proceed to initialize RSS (if necessary) and
  3925. * configure the Rx unit. Last, we re-enable the AV bits and continue
  3926. * on our merry way.
  3927. */
  3928. switch (hw->mac_type) {
  3929. default:
  3930. /* Indicate to hardware the Address is Valid. */
  3931. rar_high |= E1000_RAH_AV;
  3932. break;
  3933. }
  3934. E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  3935. E1000_WRITE_FLUSH();
  3936. E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  3937. E1000_WRITE_FLUSH();
  3938. }
  3939. /**
  3940. * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
  3941. * @hw: Struct containing variables accessed by shared code
  3942. * @offset: Offset in VLAN filer table to write
  3943. * @value: Value to write into VLAN filter table
  3944. */
  3945. void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
  3946. {
  3947. u32 temp;
  3948. if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
  3949. temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
  3950. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  3951. E1000_WRITE_FLUSH();
  3952. E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
  3953. E1000_WRITE_FLUSH();
  3954. } else {
  3955. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  3956. E1000_WRITE_FLUSH();
  3957. }
  3958. }
  3959. /**
  3960. * e1000_clear_vfta - Clears the VLAN filer table
  3961. * @hw: Struct containing variables accessed by shared code
  3962. */
  3963. static void e1000_clear_vfta(struct e1000_hw *hw)
  3964. {
  3965. u32 offset;
  3966. u32 vfta_value = 0;
  3967. u32 vfta_offset = 0;
  3968. u32 vfta_bit_in_reg = 0;
  3969. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  3970. /* If the offset we want to clear is the same offset of the
  3971. * manageability VLAN ID, then clear all bits except that of the
  3972. * manageability unit
  3973. */
  3974. vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
  3975. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
  3976. E1000_WRITE_FLUSH();
  3977. }
  3978. }
  3979. static s32 e1000_id_led_init(struct e1000_hw *hw)
  3980. {
  3981. u32 ledctl;
  3982. const u32 ledctl_mask = 0x000000FF;
  3983. const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  3984. const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  3985. u16 eeprom_data, i, temp;
  3986. const u16 led_mask = 0x0F;
  3987. e_dbg("e1000_id_led_init");
  3988. if (hw->mac_type < e1000_82540) {
  3989. /* Nothing to do */
  3990. return E1000_SUCCESS;
  3991. }
  3992. ledctl = er32(LEDCTL);
  3993. hw->ledctl_default = ledctl;
  3994. hw->ledctl_mode1 = hw->ledctl_default;
  3995. hw->ledctl_mode2 = hw->ledctl_default;
  3996. if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
  3997. e_dbg("EEPROM Read Error\n");
  3998. return -E1000_ERR_EEPROM;
  3999. }
  4000. if ((eeprom_data == ID_LED_RESERVED_0000) ||
  4001. (eeprom_data == ID_LED_RESERVED_FFFF)) {
  4002. eeprom_data = ID_LED_DEFAULT;
  4003. }
  4004. for (i = 0; i < 4; i++) {
  4005. temp = (eeprom_data >> (i << 2)) & led_mask;
  4006. switch (temp) {
  4007. case ID_LED_ON1_DEF2:
  4008. case ID_LED_ON1_ON2:
  4009. case ID_LED_ON1_OFF2:
  4010. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4011. hw->ledctl_mode1 |= ledctl_on << (i << 3);
  4012. break;
  4013. case ID_LED_OFF1_DEF2:
  4014. case ID_LED_OFF1_ON2:
  4015. case ID_LED_OFF1_OFF2:
  4016. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4017. hw->ledctl_mode1 |= ledctl_off << (i << 3);
  4018. break;
  4019. default:
  4020. /* Do nothing */
  4021. break;
  4022. }
  4023. switch (temp) {
  4024. case ID_LED_DEF1_ON2:
  4025. case ID_LED_ON1_ON2:
  4026. case ID_LED_OFF1_ON2:
  4027. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4028. hw->ledctl_mode2 |= ledctl_on << (i << 3);
  4029. break;
  4030. case ID_LED_DEF1_OFF2:
  4031. case ID_LED_ON1_OFF2:
  4032. case ID_LED_OFF1_OFF2:
  4033. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4034. hw->ledctl_mode2 |= ledctl_off << (i << 3);
  4035. break;
  4036. default:
  4037. /* Do nothing */
  4038. break;
  4039. }
  4040. }
  4041. return E1000_SUCCESS;
  4042. }
  4043. /**
  4044. * e1000_setup_led
  4045. * @hw: Struct containing variables accessed by shared code
  4046. *
  4047. * Prepares SW controlable LED for use and saves the current state of the LED.
  4048. */
  4049. s32 e1000_setup_led(struct e1000_hw *hw)
  4050. {
  4051. u32 ledctl;
  4052. s32 ret_val = E1000_SUCCESS;
  4053. e_dbg("e1000_setup_led");
  4054. switch (hw->mac_type) {
  4055. case e1000_82542_rev2_0:
  4056. case e1000_82542_rev2_1:
  4057. case e1000_82543:
  4058. case e1000_82544:
  4059. /* No setup necessary */
  4060. break;
  4061. case e1000_82541:
  4062. case e1000_82547:
  4063. case e1000_82541_rev_2:
  4064. case e1000_82547_rev_2:
  4065. /* Turn off PHY Smart Power Down (if enabled) */
  4066. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4067. &hw->phy_spd_default);
  4068. if (ret_val)
  4069. return ret_val;
  4070. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4071. (u16) (hw->phy_spd_default &
  4072. ~IGP01E1000_GMII_SPD));
  4073. if (ret_val)
  4074. return ret_val;
  4075. /* Fall Through */
  4076. default:
  4077. if (hw->media_type == e1000_media_type_fiber) {
  4078. ledctl = er32(LEDCTL);
  4079. /* Save current LEDCTL settings */
  4080. hw->ledctl_default = ledctl;
  4081. /* Turn off LED0 */
  4082. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  4083. E1000_LEDCTL_LED0_BLINK |
  4084. E1000_LEDCTL_LED0_MODE_MASK);
  4085. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  4086. E1000_LEDCTL_LED0_MODE_SHIFT);
  4087. ew32(LEDCTL, ledctl);
  4088. } else if (hw->media_type == e1000_media_type_copper)
  4089. ew32(LEDCTL, hw->ledctl_mode1);
  4090. break;
  4091. }
  4092. return E1000_SUCCESS;
  4093. }
  4094. /**
  4095. * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
  4096. * @hw: Struct containing variables accessed by shared code
  4097. */
  4098. s32 e1000_cleanup_led(struct e1000_hw *hw)
  4099. {
  4100. s32 ret_val = E1000_SUCCESS;
  4101. e_dbg("e1000_cleanup_led");
  4102. switch (hw->mac_type) {
  4103. case e1000_82542_rev2_0:
  4104. case e1000_82542_rev2_1:
  4105. case e1000_82543:
  4106. case e1000_82544:
  4107. /* No cleanup necessary */
  4108. break;
  4109. case e1000_82541:
  4110. case e1000_82547:
  4111. case e1000_82541_rev_2:
  4112. case e1000_82547_rev_2:
  4113. /* Turn on PHY Smart Power Down (if previously enabled) */
  4114. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4115. hw->phy_spd_default);
  4116. if (ret_val)
  4117. return ret_val;
  4118. /* Fall Through */
  4119. default:
  4120. /* Restore LEDCTL settings */
  4121. ew32(LEDCTL, hw->ledctl_default);
  4122. break;
  4123. }
  4124. return E1000_SUCCESS;
  4125. }
  4126. /**
  4127. * e1000_led_on - Turns on the software controllable LED
  4128. * @hw: Struct containing variables accessed by shared code
  4129. */
  4130. s32 e1000_led_on(struct e1000_hw *hw)
  4131. {
  4132. u32 ctrl = er32(CTRL);
  4133. e_dbg("e1000_led_on");
  4134. switch (hw->mac_type) {
  4135. case e1000_82542_rev2_0:
  4136. case e1000_82542_rev2_1:
  4137. case e1000_82543:
  4138. /* Set SW Defineable Pin 0 to turn on the LED */
  4139. ctrl |= E1000_CTRL_SWDPIN0;
  4140. ctrl |= E1000_CTRL_SWDPIO0;
  4141. break;
  4142. case e1000_82544:
  4143. if (hw->media_type == e1000_media_type_fiber) {
  4144. /* Set SW Defineable Pin 0 to turn on the LED */
  4145. ctrl |= E1000_CTRL_SWDPIN0;
  4146. ctrl |= E1000_CTRL_SWDPIO0;
  4147. } else {
  4148. /* Clear SW Defineable Pin 0 to turn on the LED */
  4149. ctrl &= ~E1000_CTRL_SWDPIN0;
  4150. ctrl |= E1000_CTRL_SWDPIO0;
  4151. }
  4152. break;
  4153. default:
  4154. if (hw->media_type == e1000_media_type_fiber) {
  4155. /* Clear SW Defineable Pin 0 to turn on the LED */
  4156. ctrl &= ~E1000_CTRL_SWDPIN0;
  4157. ctrl |= E1000_CTRL_SWDPIO0;
  4158. } else if (hw->media_type == e1000_media_type_copper) {
  4159. ew32(LEDCTL, hw->ledctl_mode2);
  4160. return E1000_SUCCESS;
  4161. }
  4162. break;
  4163. }
  4164. ew32(CTRL, ctrl);
  4165. return E1000_SUCCESS;
  4166. }
  4167. /**
  4168. * e1000_led_off - Turns off the software controllable LED
  4169. * @hw: Struct containing variables accessed by shared code
  4170. */
  4171. s32 e1000_led_off(struct e1000_hw *hw)
  4172. {
  4173. u32 ctrl = er32(CTRL);
  4174. e_dbg("e1000_led_off");
  4175. switch (hw->mac_type) {
  4176. case e1000_82542_rev2_0:
  4177. case e1000_82542_rev2_1:
  4178. case e1000_82543:
  4179. /* Clear SW Defineable Pin 0 to turn off the LED */
  4180. ctrl &= ~E1000_CTRL_SWDPIN0;
  4181. ctrl |= E1000_CTRL_SWDPIO0;
  4182. break;
  4183. case e1000_82544:
  4184. if (hw->media_type == e1000_media_type_fiber) {
  4185. /* Clear SW Defineable Pin 0 to turn off the LED */
  4186. ctrl &= ~E1000_CTRL_SWDPIN0;
  4187. ctrl |= E1000_CTRL_SWDPIO0;
  4188. } else {
  4189. /* Set SW Defineable Pin 0 to turn off the LED */
  4190. ctrl |= E1000_CTRL_SWDPIN0;
  4191. ctrl |= E1000_CTRL_SWDPIO0;
  4192. }
  4193. break;
  4194. default:
  4195. if (hw->media_type == e1000_media_type_fiber) {
  4196. /* Set SW Defineable Pin 0 to turn off the LED */
  4197. ctrl |= E1000_CTRL_SWDPIN0;
  4198. ctrl |= E1000_CTRL_SWDPIO0;
  4199. } else if (hw->media_type == e1000_media_type_copper) {
  4200. ew32(LEDCTL, hw->ledctl_mode1);
  4201. return E1000_SUCCESS;
  4202. }
  4203. break;
  4204. }
  4205. ew32(CTRL, ctrl);
  4206. return E1000_SUCCESS;
  4207. }
  4208. /**
  4209. * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
  4210. * @hw: Struct containing variables accessed by shared code
  4211. */
  4212. static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
  4213. {
  4214. volatile u32 temp;
  4215. temp = er32(CRCERRS);
  4216. temp = er32(SYMERRS);
  4217. temp = er32(MPC);
  4218. temp = er32(SCC);
  4219. temp = er32(ECOL);
  4220. temp = er32(MCC);
  4221. temp = er32(LATECOL);
  4222. temp = er32(COLC);
  4223. temp = er32(DC);
  4224. temp = er32(SEC);
  4225. temp = er32(RLEC);
  4226. temp = er32(XONRXC);
  4227. temp = er32(XONTXC);
  4228. temp = er32(XOFFRXC);
  4229. temp = er32(XOFFTXC);
  4230. temp = er32(FCRUC);
  4231. temp = er32(PRC64);
  4232. temp = er32(PRC127);
  4233. temp = er32(PRC255);
  4234. temp = er32(PRC511);
  4235. temp = er32(PRC1023);
  4236. temp = er32(PRC1522);
  4237. temp = er32(GPRC);
  4238. temp = er32(BPRC);
  4239. temp = er32(MPRC);
  4240. temp = er32(GPTC);
  4241. temp = er32(GORCL);
  4242. temp = er32(GORCH);
  4243. temp = er32(GOTCL);
  4244. temp = er32(GOTCH);
  4245. temp = er32(RNBC);
  4246. temp = er32(RUC);
  4247. temp = er32(RFC);
  4248. temp = er32(ROC);
  4249. temp = er32(RJC);
  4250. temp = er32(TORL);
  4251. temp = er32(TORH);
  4252. temp = er32(TOTL);
  4253. temp = er32(TOTH);
  4254. temp = er32(TPR);
  4255. temp = er32(TPT);
  4256. temp = er32(PTC64);
  4257. temp = er32(PTC127);
  4258. temp = er32(PTC255);
  4259. temp = er32(PTC511);
  4260. temp = er32(PTC1023);
  4261. temp = er32(PTC1522);
  4262. temp = er32(MPTC);
  4263. temp = er32(BPTC);
  4264. if (hw->mac_type < e1000_82543)
  4265. return;
  4266. temp = er32(ALGNERRC);
  4267. temp = er32(RXERRC);
  4268. temp = er32(TNCRS);
  4269. temp = er32(CEXTERR);
  4270. temp = er32(TSCTC);
  4271. temp = er32(TSCTFC);
  4272. if (hw->mac_type <= e1000_82544)
  4273. return;
  4274. temp = er32(MGTPRC);
  4275. temp = er32(MGTPDC);
  4276. temp = er32(MGTPTC);
  4277. }
  4278. /**
  4279. * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
  4280. * @hw: Struct containing variables accessed by shared code
  4281. *
  4282. * Call this after e1000_init_hw. You may override the IFS defaults by setting
  4283. * hw->ifs_params_forced to true. However, you must initialize hw->
  4284. * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
  4285. * before calling this function.
  4286. */
  4287. void e1000_reset_adaptive(struct e1000_hw *hw)
  4288. {
  4289. e_dbg("e1000_reset_adaptive");
  4290. if (hw->adaptive_ifs) {
  4291. if (!hw->ifs_params_forced) {
  4292. hw->current_ifs_val = 0;
  4293. hw->ifs_min_val = IFS_MIN;
  4294. hw->ifs_max_val = IFS_MAX;
  4295. hw->ifs_step_size = IFS_STEP;
  4296. hw->ifs_ratio = IFS_RATIO;
  4297. }
  4298. hw->in_ifs_mode = false;
  4299. ew32(AIT, 0);
  4300. } else {
  4301. e_dbg("Not in Adaptive IFS mode!\n");
  4302. }
  4303. }
  4304. /**
  4305. * e1000_update_adaptive - update adaptive IFS
  4306. * @hw: Struct containing variables accessed by shared code
  4307. * @tx_packets: Number of transmits since last callback
  4308. * @total_collisions: Number of collisions since last callback
  4309. *
  4310. * Called during the callback/watchdog routine to update IFS value based on
  4311. * the ratio of transmits to collisions.
  4312. */
  4313. void e1000_update_adaptive(struct e1000_hw *hw)
  4314. {
  4315. e_dbg("e1000_update_adaptive");
  4316. if (hw->adaptive_ifs) {
  4317. if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
  4318. if (hw->tx_packet_delta > MIN_NUM_XMITS) {
  4319. hw->in_ifs_mode = true;
  4320. if (hw->current_ifs_val < hw->ifs_max_val) {
  4321. if (hw->current_ifs_val == 0)
  4322. hw->current_ifs_val =
  4323. hw->ifs_min_val;
  4324. else
  4325. hw->current_ifs_val +=
  4326. hw->ifs_step_size;
  4327. ew32(AIT, hw->current_ifs_val);
  4328. }
  4329. }
  4330. } else {
  4331. if (hw->in_ifs_mode
  4332. && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
  4333. hw->current_ifs_val = 0;
  4334. hw->in_ifs_mode = false;
  4335. ew32(AIT, 0);
  4336. }
  4337. }
  4338. } else {
  4339. e_dbg("Not in Adaptive IFS mode!\n");
  4340. }
  4341. }
  4342. /**
  4343. * e1000_tbi_adjust_stats
  4344. * @hw: Struct containing variables accessed by shared code
  4345. * @frame_len: The length of the frame in question
  4346. * @mac_addr: The Ethernet destination address of the frame in question
  4347. *
  4348. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  4349. */
  4350. void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
  4351. u32 frame_len, u8 *mac_addr)
  4352. {
  4353. u64 carry_bit;
  4354. /* First adjust the frame length. */
  4355. frame_len--;
  4356. /* We need to adjust the statistics counters, since the hardware
  4357. * counters overcount this packet as a CRC error and undercount
  4358. * the packet as a good packet
  4359. */
  4360. /* This packet should not be counted as a CRC error. */
  4361. stats->crcerrs--;
  4362. /* This packet does count as a Good Packet Received. */
  4363. stats->gprc++;
  4364. /* Adjust the Good Octets received counters */
  4365. carry_bit = 0x80000000 & stats->gorcl;
  4366. stats->gorcl += frame_len;
  4367. /* If the high bit of Gorcl (the low 32 bits of the Good Octets
  4368. * Received Count) was one before the addition,
  4369. * AND it is zero after, then we lost the carry out,
  4370. * need to add one to Gorch (Good Octets Received Count High).
  4371. * This could be simplified if all environments supported
  4372. * 64-bit integers.
  4373. */
  4374. if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
  4375. stats->gorch++;
  4376. /* Is this a broadcast or multicast? Check broadcast first,
  4377. * since the test for a multicast frame will test positive on
  4378. * a broadcast frame.
  4379. */
  4380. if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
  4381. /* Broadcast packet */
  4382. stats->bprc++;
  4383. else if (*mac_addr & 0x01)
  4384. /* Multicast packet */
  4385. stats->mprc++;
  4386. if (frame_len == hw->max_frame_size) {
  4387. /* In this case, the hardware has overcounted the number of
  4388. * oversize frames.
  4389. */
  4390. if (stats->roc > 0)
  4391. stats->roc--;
  4392. }
  4393. /* Adjust the bin counters when the extra byte put the frame in the
  4394. * wrong bin. Remember that the frame_len was adjusted above.
  4395. */
  4396. if (frame_len == 64) {
  4397. stats->prc64++;
  4398. stats->prc127--;
  4399. } else if (frame_len == 127) {
  4400. stats->prc127++;
  4401. stats->prc255--;
  4402. } else if (frame_len == 255) {
  4403. stats->prc255++;
  4404. stats->prc511--;
  4405. } else if (frame_len == 511) {
  4406. stats->prc511++;
  4407. stats->prc1023--;
  4408. } else if (frame_len == 1023) {
  4409. stats->prc1023++;
  4410. stats->prc1522--;
  4411. } else if (frame_len == 1522) {
  4412. stats->prc1522++;
  4413. }
  4414. }
  4415. /**
  4416. * e1000_get_bus_info
  4417. * @hw: Struct containing variables accessed by shared code
  4418. *
  4419. * Gets the current PCI bus type, speed, and width of the hardware
  4420. */
  4421. void e1000_get_bus_info(struct e1000_hw *hw)
  4422. {
  4423. u32 status;
  4424. switch (hw->mac_type) {
  4425. case e1000_82542_rev2_0:
  4426. case e1000_82542_rev2_1:
  4427. hw->bus_type = e1000_bus_type_pci;
  4428. hw->bus_speed = e1000_bus_speed_unknown;
  4429. hw->bus_width = e1000_bus_width_unknown;
  4430. break;
  4431. default:
  4432. status = er32(STATUS);
  4433. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  4434. e1000_bus_type_pcix : e1000_bus_type_pci;
  4435. if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
  4436. hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
  4437. e1000_bus_speed_66 : e1000_bus_speed_120;
  4438. } else if (hw->bus_type == e1000_bus_type_pci) {
  4439. hw->bus_speed = (status & E1000_STATUS_PCI66) ?
  4440. e1000_bus_speed_66 : e1000_bus_speed_33;
  4441. } else {
  4442. switch (status & E1000_STATUS_PCIX_SPEED) {
  4443. case E1000_STATUS_PCIX_SPEED_66:
  4444. hw->bus_speed = e1000_bus_speed_66;
  4445. break;
  4446. case E1000_STATUS_PCIX_SPEED_100:
  4447. hw->bus_speed = e1000_bus_speed_100;
  4448. break;
  4449. case E1000_STATUS_PCIX_SPEED_133:
  4450. hw->bus_speed = e1000_bus_speed_133;
  4451. break;
  4452. default:
  4453. hw->bus_speed = e1000_bus_speed_reserved;
  4454. break;
  4455. }
  4456. }
  4457. hw->bus_width = (status & E1000_STATUS_BUS64) ?
  4458. e1000_bus_width_64 : e1000_bus_width_32;
  4459. break;
  4460. }
  4461. }
  4462. /**
  4463. * e1000_write_reg_io
  4464. * @hw: Struct containing variables accessed by shared code
  4465. * @offset: offset to write to
  4466. * @value: value to write
  4467. *
  4468. * Writes a value to one of the devices registers using port I/O (as opposed to
  4469. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4470. */
  4471. static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
  4472. {
  4473. unsigned long io_addr = hw->io_base;
  4474. unsigned long io_data = hw->io_base + 4;
  4475. e1000_io_write(hw, io_addr, offset);
  4476. e1000_io_write(hw, io_data, value);
  4477. }
  4478. /**
  4479. * e1000_get_cable_length - Estimates the cable length.
  4480. * @hw: Struct containing variables accessed by shared code
  4481. * @min_length: The estimated minimum length
  4482. * @max_length: The estimated maximum length
  4483. *
  4484. * returns: - E1000_ERR_XXX
  4485. * E1000_SUCCESS
  4486. *
  4487. * This function always returns a ranged length (minimum & maximum).
  4488. * So for M88 phy's, this function interprets the one value returned from the
  4489. * register to the minimum and maximum range.
  4490. * For IGP phy's, the function calculates the range by the AGC registers.
  4491. */
  4492. static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
  4493. u16 *max_length)
  4494. {
  4495. s32 ret_val;
  4496. u16 agc_value = 0;
  4497. u16 i, phy_data;
  4498. u16 cable_length;
  4499. e_dbg("e1000_get_cable_length");
  4500. *min_length = *max_length = 0;
  4501. /* Use old method for Phy older than IGP */
  4502. if (hw->phy_type == e1000_phy_m88) {
  4503. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4504. &phy_data);
  4505. if (ret_val)
  4506. return ret_val;
  4507. cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  4508. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  4509. /* Convert the enum value to ranged values */
  4510. switch (cable_length) {
  4511. case e1000_cable_length_50:
  4512. *min_length = 0;
  4513. *max_length = e1000_igp_cable_length_50;
  4514. break;
  4515. case e1000_cable_length_50_80:
  4516. *min_length = e1000_igp_cable_length_50;
  4517. *max_length = e1000_igp_cable_length_80;
  4518. break;
  4519. case e1000_cable_length_80_110:
  4520. *min_length = e1000_igp_cable_length_80;
  4521. *max_length = e1000_igp_cable_length_110;
  4522. break;
  4523. case e1000_cable_length_110_140:
  4524. *min_length = e1000_igp_cable_length_110;
  4525. *max_length = e1000_igp_cable_length_140;
  4526. break;
  4527. case e1000_cable_length_140:
  4528. *min_length = e1000_igp_cable_length_140;
  4529. *max_length = e1000_igp_cable_length_170;
  4530. break;
  4531. default:
  4532. return -E1000_ERR_PHY;
  4533. break;
  4534. }
  4535. } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
  4536. u16 cur_agc_value;
  4537. u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
  4538. static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
  4539. IGP01E1000_PHY_AGC_A,
  4540. IGP01E1000_PHY_AGC_B,
  4541. IGP01E1000_PHY_AGC_C,
  4542. IGP01E1000_PHY_AGC_D
  4543. };
  4544. /* Read the AGC registers for all channels */
  4545. for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4546. ret_val =
  4547. e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  4548. if (ret_val)
  4549. return ret_val;
  4550. cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
  4551. /* Value bound check. */
  4552. if ((cur_agc_value >=
  4553. IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
  4554. || (cur_agc_value == 0))
  4555. return -E1000_ERR_PHY;
  4556. agc_value += cur_agc_value;
  4557. /* Update minimal AGC value. */
  4558. if (min_agc_value > cur_agc_value)
  4559. min_agc_value = cur_agc_value;
  4560. }
  4561. /* Remove the minimal AGC result for length < 50m */
  4562. if (agc_value <
  4563. IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
  4564. agc_value -= min_agc_value;
  4565. /* Get the average length of the remaining 3 channels */
  4566. agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
  4567. } else {
  4568. /* Get the average length of all the 4 channels. */
  4569. agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
  4570. }
  4571. /* Set the range of the calculated length. */
  4572. *min_length = ((e1000_igp_cable_length_table[agc_value] -
  4573. IGP01E1000_AGC_RANGE) > 0) ?
  4574. (e1000_igp_cable_length_table[agc_value] -
  4575. IGP01E1000_AGC_RANGE) : 0;
  4576. *max_length = e1000_igp_cable_length_table[agc_value] +
  4577. IGP01E1000_AGC_RANGE;
  4578. }
  4579. return E1000_SUCCESS;
  4580. }
  4581. /**
  4582. * e1000_check_polarity - Check the cable polarity
  4583. * @hw: Struct containing variables accessed by shared code
  4584. * @polarity: output parameter : 0 - Polarity is not reversed
  4585. * 1 - Polarity is reversed.
  4586. *
  4587. * returns: - E1000_ERR_XXX
  4588. * E1000_SUCCESS
  4589. *
  4590. * For phy's older than IGP, this function simply reads the polarity bit in the
  4591. * Phy Status register. For IGP phy's, this bit is valid only if link speed is
  4592. * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
  4593. * return 0. If the link speed is 1000 Mbps the polarity status is in the
  4594. * IGP01E1000_PHY_PCS_INIT_REG.
  4595. */
  4596. static s32 e1000_check_polarity(struct e1000_hw *hw,
  4597. e1000_rev_polarity *polarity)
  4598. {
  4599. s32 ret_val;
  4600. u16 phy_data;
  4601. e_dbg("e1000_check_polarity");
  4602. if (hw->phy_type == e1000_phy_m88) {
  4603. /* return the Polarity bit in the Status register. */
  4604. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4605. &phy_data);
  4606. if (ret_val)
  4607. return ret_val;
  4608. *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
  4609. M88E1000_PSSR_REV_POLARITY_SHIFT) ?
  4610. e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
  4611. } else if (hw->phy_type == e1000_phy_igp) {
  4612. /* Read the Status register to check the speed */
  4613. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  4614. &phy_data);
  4615. if (ret_val)
  4616. return ret_val;
  4617. /* If speed is 1000 Mbps, must read the
  4618. * IGP01E1000_PHY_PCS_INIT_REG to find the polarity status
  4619. */
  4620. if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  4621. IGP01E1000_PSSR_SPEED_1000MBPS) {
  4622. /* Read the GIG initialization PCS register (0x00B4) */
  4623. ret_val =
  4624. e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
  4625. &phy_data);
  4626. if (ret_val)
  4627. return ret_val;
  4628. /* Check the polarity bits */
  4629. *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
  4630. e1000_rev_polarity_reversed :
  4631. e1000_rev_polarity_normal;
  4632. } else {
  4633. /* For 10 Mbps, read the polarity bit in the status
  4634. * register. (for 100 Mbps this bit is always 0)
  4635. */
  4636. *polarity =
  4637. (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
  4638. e1000_rev_polarity_reversed :
  4639. e1000_rev_polarity_normal;
  4640. }
  4641. }
  4642. return E1000_SUCCESS;
  4643. }
  4644. /**
  4645. * e1000_check_downshift - Check if Downshift occurred
  4646. * @hw: Struct containing variables accessed by shared code
  4647. * @downshift: output parameter : 0 - No Downshift occurred.
  4648. * 1 - Downshift occurred.
  4649. *
  4650. * returns: - E1000_ERR_XXX
  4651. * E1000_SUCCESS
  4652. *
  4653. * For phy's older than IGP, this function reads the Downshift bit in the Phy
  4654. * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
  4655. * Link Health register. In IGP this bit is latched high, so the driver must
  4656. * read it immediately after link is established.
  4657. */
  4658. static s32 e1000_check_downshift(struct e1000_hw *hw)
  4659. {
  4660. s32 ret_val;
  4661. u16 phy_data;
  4662. e_dbg("e1000_check_downshift");
  4663. if (hw->phy_type == e1000_phy_igp) {
  4664. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
  4665. &phy_data);
  4666. if (ret_val)
  4667. return ret_val;
  4668. hw->speed_downgraded =
  4669. (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
  4670. } else if (hw->phy_type == e1000_phy_m88) {
  4671. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4672. &phy_data);
  4673. if (ret_val)
  4674. return ret_val;
  4675. hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
  4676. M88E1000_PSSR_DOWNSHIFT_SHIFT;
  4677. }
  4678. return E1000_SUCCESS;
  4679. }
  4680. static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
  4681. IGP01E1000_PHY_AGC_PARAM_A,
  4682. IGP01E1000_PHY_AGC_PARAM_B,
  4683. IGP01E1000_PHY_AGC_PARAM_C,
  4684. IGP01E1000_PHY_AGC_PARAM_D
  4685. };
  4686. static s32 e1000_1000Mb_check_cable_length(struct e1000_hw *hw)
  4687. {
  4688. u16 min_length, max_length;
  4689. u16 phy_data, i;
  4690. s32 ret_val;
  4691. ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
  4692. if (ret_val)
  4693. return ret_val;
  4694. if (hw->dsp_config_state != e1000_dsp_config_enabled)
  4695. return 0;
  4696. if (min_length >= e1000_igp_cable_length_50) {
  4697. for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4698. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
  4699. &phy_data);
  4700. if (ret_val)
  4701. return ret_val;
  4702. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4703. ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
  4704. phy_data);
  4705. if (ret_val)
  4706. return ret_val;
  4707. }
  4708. hw->dsp_config_state = e1000_dsp_config_activated;
  4709. } else {
  4710. u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
  4711. u32 idle_errs = 0;
  4712. /* clear previous idle error counts */
  4713. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  4714. if (ret_val)
  4715. return ret_val;
  4716. for (i = 0; i < ffe_idle_err_timeout; i++) {
  4717. udelay(1000);
  4718. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4719. &phy_data);
  4720. if (ret_val)
  4721. return ret_val;
  4722. idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
  4723. if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
  4724. hw->ffe_config_state = e1000_ffe_config_active;
  4725. ret_val = e1000_write_phy_reg(hw,
  4726. IGP01E1000_PHY_DSP_FFE,
  4727. IGP01E1000_PHY_DSP_FFE_CM_CP);
  4728. if (ret_val)
  4729. return ret_val;
  4730. break;
  4731. }
  4732. if (idle_errs)
  4733. ffe_idle_err_timeout =
  4734. FFE_IDLE_ERR_COUNT_TIMEOUT_100;
  4735. }
  4736. }
  4737. return 0;
  4738. }
  4739. /**
  4740. * e1000_config_dsp_after_link_change
  4741. * @hw: Struct containing variables accessed by shared code
  4742. * @link_up: was link up at the time this was called
  4743. *
  4744. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  4745. * E1000_SUCCESS at any other case.
  4746. *
  4747. * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
  4748. * gigabit link is achieved to improve link quality.
  4749. */
  4750. static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
  4751. {
  4752. s32 ret_val;
  4753. u16 phy_data, phy_saved_data, speed, duplex, i;
  4754. e_dbg("e1000_config_dsp_after_link_change");
  4755. if (hw->phy_type != e1000_phy_igp)
  4756. return E1000_SUCCESS;
  4757. if (link_up) {
  4758. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  4759. if (ret_val) {
  4760. e_dbg("Error getting link speed and duplex\n");
  4761. return ret_val;
  4762. }
  4763. if (speed == SPEED_1000) {
  4764. ret_val = e1000_1000Mb_check_cable_length(hw);
  4765. if (ret_val)
  4766. return ret_val;
  4767. }
  4768. } else {
  4769. if (hw->dsp_config_state == e1000_dsp_config_activated) {
  4770. /* Save off the current value of register 0x2F5B to be
  4771. * restored at the end of the routines.
  4772. */
  4773. ret_val =
  4774. e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  4775. if (ret_val)
  4776. return ret_val;
  4777. /* Disable the PHY transmitter */
  4778. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  4779. if (ret_val)
  4780. return ret_val;
  4781. msleep(20);
  4782. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4783. IGP01E1000_IEEE_FORCE_GIGA);
  4784. if (ret_val)
  4785. return ret_val;
  4786. for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4787. ret_val =
  4788. e1000_read_phy_reg(hw, dsp_reg_array[i],
  4789. &phy_data);
  4790. if (ret_val)
  4791. return ret_val;
  4792. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4793. phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
  4794. ret_val =
  4795. e1000_write_phy_reg(hw, dsp_reg_array[i],
  4796. phy_data);
  4797. if (ret_val)
  4798. return ret_val;
  4799. }
  4800. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4801. IGP01E1000_IEEE_RESTART_AUTONEG);
  4802. if (ret_val)
  4803. return ret_val;
  4804. msleep(20);
  4805. /* Now enable the transmitter */
  4806. ret_val =
  4807. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  4808. if (ret_val)
  4809. return ret_val;
  4810. hw->dsp_config_state = e1000_dsp_config_enabled;
  4811. }
  4812. if (hw->ffe_config_state == e1000_ffe_config_active) {
  4813. /* Save off the current value of register 0x2F5B to be
  4814. * restored at the end of the routines.
  4815. */
  4816. ret_val =
  4817. e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  4818. if (ret_val)
  4819. return ret_val;
  4820. /* Disable the PHY transmitter */
  4821. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  4822. if (ret_val)
  4823. return ret_val;
  4824. msleep(20);
  4825. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4826. IGP01E1000_IEEE_FORCE_GIGA);
  4827. if (ret_val)
  4828. return ret_val;
  4829. ret_val =
  4830. e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
  4831. IGP01E1000_PHY_DSP_FFE_DEFAULT);
  4832. if (ret_val)
  4833. return ret_val;
  4834. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4835. IGP01E1000_IEEE_RESTART_AUTONEG);
  4836. if (ret_val)
  4837. return ret_val;
  4838. msleep(20);
  4839. /* Now enable the transmitter */
  4840. ret_val =
  4841. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  4842. if (ret_val)
  4843. return ret_val;
  4844. hw->ffe_config_state = e1000_ffe_config_enabled;
  4845. }
  4846. }
  4847. return E1000_SUCCESS;
  4848. }
  4849. /**
  4850. * e1000_set_phy_mode - Set PHY to class A mode
  4851. * @hw: Struct containing variables accessed by shared code
  4852. *
  4853. * Assumes the following operations will follow to enable the new class mode.
  4854. * 1. Do a PHY soft reset
  4855. * 2. Restart auto-negotiation or force link.
  4856. */
  4857. static s32 e1000_set_phy_mode(struct e1000_hw *hw)
  4858. {
  4859. s32 ret_val;
  4860. u16 eeprom_data;
  4861. e_dbg("e1000_set_phy_mode");
  4862. if ((hw->mac_type == e1000_82545_rev_3) &&
  4863. (hw->media_type == e1000_media_type_copper)) {
  4864. ret_val =
  4865. e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
  4866. &eeprom_data);
  4867. if (ret_val) {
  4868. return ret_val;
  4869. }
  4870. if ((eeprom_data != EEPROM_RESERVED_WORD) &&
  4871. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  4872. ret_val =
  4873. e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
  4874. 0x000B);
  4875. if (ret_val)
  4876. return ret_val;
  4877. ret_val =
  4878. e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
  4879. 0x8104);
  4880. if (ret_val)
  4881. return ret_val;
  4882. hw->phy_reset_disable = false;
  4883. }
  4884. }
  4885. return E1000_SUCCESS;
  4886. }
  4887. /**
  4888. * e1000_set_d3_lplu_state - set d3 link power state
  4889. * @hw: Struct containing variables accessed by shared code
  4890. * @active: true to enable lplu false to disable lplu.
  4891. *
  4892. * This function sets the lplu state according to the active flag. When
  4893. * activating lplu this function also disables smart speed and vise versa.
  4894. * lplu will not be activated unless the device autonegotiation advertisement
  4895. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  4896. *
  4897. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  4898. * E1000_SUCCESS at any other case.
  4899. */
  4900. static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  4901. {
  4902. s32 ret_val;
  4903. u16 phy_data;
  4904. e_dbg("e1000_set_d3_lplu_state");
  4905. if (hw->phy_type != e1000_phy_igp)
  4906. return E1000_SUCCESS;
  4907. /* During driver activity LPLU should not be used or it will attain link
  4908. * from the lowest speeds starting from 10Mbps. The capability is used
  4909. * for Dx transitions and states
  4910. */
  4911. if (hw->mac_type == e1000_82541_rev_2
  4912. || hw->mac_type == e1000_82547_rev_2) {
  4913. ret_val =
  4914. e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
  4915. if (ret_val)
  4916. return ret_val;
  4917. }
  4918. if (!active) {
  4919. if (hw->mac_type == e1000_82541_rev_2 ||
  4920. hw->mac_type == e1000_82547_rev_2) {
  4921. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  4922. ret_val =
  4923. e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4924. phy_data);
  4925. if (ret_val)
  4926. return ret_val;
  4927. }
  4928. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  4929. * during Dx states where the power conservation is most
  4930. * important. During driver activity we should enable
  4931. * SmartSpeed, so performance is maintained.
  4932. */
  4933. if (hw->smart_speed == e1000_smart_speed_on) {
  4934. ret_val =
  4935. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4936. &phy_data);
  4937. if (ret_val)
  4938. return ret_val;
  4939. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  4940. ret_val =
  4941. e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4942. phy_data);
  4943. if (ret_val)
  4944. return ret_val;
  4945. } else if (hw->smart_speed == e1000_smart_speed_off) {
  4946. ret_val =
  4947. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4948. &phy_data);
  4949. if (ret_val)
  4950. return ret_val;
  4951. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  4952. ret_val =
  4953. e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4954. phy_data);
  4955. if (ret_val)
  4956. return ret_val;
  4957. }
  4958. } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
  4959. || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
  4960. || (hw->autoneg_advertised ==
  4961. AUTONEG_ADVERTISE_10_100_ALL)) {
  4962. if (hw->mac_type == e1000_82541_rev_2 ||
  4963. hw->mac_type == e1000_82547_rev_2) {
  4964. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  4965. ret_val =
  4966. e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4967. phy_data);
  4968. if (ret_val)
  4969. return ret_val;
  4970. }
  4971. /* When LPLU is enabled we should disable SmartSpeed */
  4972. ret_val =
  4973. e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4974. &phy_data);
  4975. if (ret_val)
  4976. return ret_val;
  4977. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  4978. ret_val =
  4979. e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4980. phy_data);
  4981. if (ret_val)
  4982. return ret_val;
  4983. }
  4984. return E1000_SUCCESS;
  4985. }
  4986. /**
  4987. * e1000_set_vco_speed
  4988. * @hw: Struct containing variables accessed by shared code
  4989. *
  4990. * Change VCO speed register to improve Bit Error Rate performance of SERDES.
  4991. */
  4992. static s32 e1000_set_vco_speed(struct e1000_hw *hw)
  4993. {
  4994. s32 ret_val;
  4995. u16 default_page = 0;
  4996. u16 phy_data;
  4997. e_dbg("e1000_set_vco_speed");
  4998. switch (hw->mac_type) {
  4999. case e1000_82545_rev_3:
  5000. case e1000_82546_rev_3:
  5001. break;
  5002. default:
  5003. return E1000_SUCCESS;
  5004. }
  5005. /* Set PHY register 30, page 5, bit 8 to 0 */
  5006. ret_val =
  5007. e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
  5008. if (ret_val)
  5009. return ret_val;
  5010. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
  5011. if (ret_val)
  5012. return ret_val;
  5013. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5014. if (ret_val)
  5015. return ret_val;
  5016. phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
  5017. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5018. if (ret_val)
  5019. return ret_val;
  5020. /* Set PHY register 30, page 4, bit 11 to 1 */
  5021. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
  5022. if (ret_val)
  5023. return ret_val;
  5024. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5025. if (ret_val)
  5026. return ret_val;
  5027. phy_data |= M88E1000_PHY_VCO_REG_BIT11;
  5028. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5029. if (ret_val)
  5030. return ret_val;
  5031. ret_val =
  5032. e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
  5033. if (ret_val)
  5034. return ret_val;
  5035. return E1000_SUCCESS;
  5036. }
  5037. /**
  5038. * e1000_enable_mng_pass_thru - check for bmc pass through
  5039. * @hw: Struct containing variables accessed by shared code
  5040. *
  5041. * Verifies the hardware needs to allow ARPs to be processed by the host
  5042. * returns: - true/false
  5043. */
  5044. u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
  5045. {
  5046. u32 manc;
  5047. if (hw->asf_firmware_present) {
  5048. manc = er32(MANC);
  5049. if (!(manc & E1000_MANC_RCV_TCO_EN) ||
  5050. !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
  5051. return false;
  5052. if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
  5053. return true;
  5054. }
  5055. return false;
  5056. }
  5057. static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
  5058. {
  5059. s32 ret_val;
  5060. u16 mii_status_reg;
  5061. u16 i;
  5062. /* Polarity reversal workaround for forced 10F/10H links. */
  5063. /* Disable the transmitter on the PHY */
  5064. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  5065. if (ret_val)
  5066. return ret_val;
  5067. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
  5068. if (ret_val)
  5069. return ret_val;
  5070. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  5071. if (ret_val)
  5072. return ret_val;
  5073. /* This loop will early-out if the NO link condition has been met. */
  5074. for (i = PHY_FORCE_TIME; i > 0; i--) {
  5075. /* Read the MII Status Register and wait for Link Status bit
  5076. * to be clear.
  5077. */
  5078. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5079. if (ret_val)
  5080. return ret_val;
  5081. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5082. if (ret_val)
  5083. return ret_val;
  5084. if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
  5085. break;
  5086. msleep(100);
  5087. }
  5088. /* Recommended delay time after link has been lost */
  5089. msleep(1000);
  5090. /* Now we will re-enable th transmitter on the PHY */
  5091. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  5092. if (ret_val)
  5093. return ret_val;
  5094. msleep(50);
  5095. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
  5096. if (ret_val)
  5097. return ret_val;
  5098. msleep(50);
  5099. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
  5100. if (ret_val)
  5101. return ret_val;
  5102. msleep(50);
  5103. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
  5104. if (ret_val)
  5105. return ret_val;
  5106. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  5107. if (ret_val)
  5108. return ret_val;
  5109. /* This loop will early-out if the link condition has been met. */
  5110. for (i = PHY_FORCE_TIME; i > 0; i--) {
  5111. /* Read the MII Status Register and wait for Link Status bit
  5112. * to be set.
  5113. */
  5114. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5115. if (ret_val)
  5116. return ret_val;
  5117. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  5118. if (ret_val)
  5119. return ret_val;
  5120. if (mii_status_reg & MII_SR_LINK_STATUS)
  5121. break;
  5122. msleep(100);
  5123. }
  5124. return E1000_SUCCESS;
  5125. }
  5126. /**
  5127. * e1000_get_auto_rd_done
  5128. * @hw: Struct containing variables accessed by shared code
  5129. *
  5130. * Check for EEPROM Auto Read bit done.
  5131. * returns: - E1000_ERR_RESET if fail to reset MAC
  5132. * E1000_SUCCESS at any other case.
  5133. */
  5134. static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
  5135. {
  5136. e_dbg("e1000_get_auto_rd_done");
  5137. msleep(5);
  5138. return E1000_SUCCESS;
  5139. }
  5140. /**
  5141. * e1000_get_phy_cfg_done
  5142. * @hw: Struct containing variables accessed by shared code
  5143. *
  5144. * Checks if the PHY configuration is done
  5145. * returns: - E1000_ERR_RESET if fail to reset MAC
  5146. * E1000_SUCCESS at any other case.
  5147. */
  5148. static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
  5149. {
  5150. e_dbg("e1000_get_phy_cfg_done");
  5151. msleep(10);
  5152. return E1000_SUCCESS;
  5153. }