e1000_hw.c 162 KB

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