e1000_hw.c 162 KB

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