e1000_hw.c 191 KB

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