ich8lan.c 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2014 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  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. /* 82562G 10/100 Network Connection
  22. * 82562G-2 10/100 Network Connection
  23. * 82562GT 10/100 Network Connection
  24. * 82562GT-2 10/100 Network Connection
  25. * 82562V 10/100 Network Connection
  26. * 82562V-2 10/100 Network Connection
  27. * 82566DC-2 Gigabit Network Connection
  28. * 82566DC Gigabit Network Connection
  29. * 82566DM-2 Gigabit Network Connection
  30. * 82566DM Gigabit Network Connection
  31. * 82566MC Gigabit Network Connection
  32. * 82566MM Gigabit Network Connection
  33. * 82567LM Gigabit Network Connection
  34. * 82567LF Gigabit Network Connection
  35. * 82567V Gigabit Network Connection
  36. * 82567LM-2 Gigabit Network Connection
  37. * 82567LF-2 Gigabit Network Connection
  38. * 82567V-2 Gigabit Network Connection
  39. * 82567LF-3 Gigabit Network Connection
  40. * 82567LM-3 Gigabit Network Connection
  41. * 82567LM-4 Gigabit Network Connection
  42. * 82577LM Gigabit Network Connection
  43. * 82577LC Gigabit Network Connection
  44. * 82578DM Gigabit Network Connection
  45. * 82578DC Gigabit Network Connection
  46. * 82579LM Gigabit Network Connection
  47. * 82579V Gigabit Network Connection
  48. * Ethernet Connection I217-LM
  49. * Ethernet Connection I217-V
  50. * Ethernet Connection I218-V
  51. * Ethernet Connection I218-LM
  52. * Ethernet Connection (2) I218-LM
  53. * Ethernet Connection (2) I218-V
  54. * Ethernet Connection (3) I218-LM
  55. * Ethernet Connection (3) I218-V
  56. */
  57. #include "e1000.h"
  58. /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
  59. /* Offset 04h HSFSTS */
  60. union ich8_hws_flash_status {
  61. struct ich8_hsfsts {
  62. u16 flcdone:1; /* bit 0 Flash Cycle Done */
  63. u16 flcerr:1; /* bit 1 Flash Cycle Error */
  64. u16 dael:1; /* bit 2 Direct Access error Log */
  65. u16 berasesz:2; /* bit 4:3 Sector Erase Size */
  66. u16 flcinprog:1; /* bit 5 flash cycle in Progress */
  67. u16 reserved1:2; /* bit 13:6 Reserved */
  68. u16 reserved2:6; /* bit 13:6 Reserved */
  69. u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
  70. u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
  71. } hsf_status;
  72. u16 regval;
  73. };
  74. /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
  75. /* Offset 06h FLCTL */
  76. union ich8_hws_flash_ctrl {
  77. struct ich8_hsflctl {
  78. u16 flcgo:1; /* 0 Flash Cycle Go */
  79. u16 flcycle:2; /* 2:1 Flash Cycle */
  80. u16 reserved:5; /* 7:3 Reserved */
  81. u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
  82. u16 flockdn:6; /* 15:10 Reserved */
  83. } hsf_ctrl;
  84. u16 regval;
  85. };
  86. /* ICH Flash Region Access Permissions */
  87. union ich8_hws_flash_regacc {
  88. struct ich8_flracc {
  89. u32 grra:8; /* 0:7 GbE region Read Access */
  90. u32 grwa:8; /* 8:15 GbE region Write Access */
  91. u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
  92. u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
  93. } hsf_flregacc;
  94. u16 regval;
  95. };
  96. /* ICH Flash Protected Region */
  97. union ich8_flash_protected_range {
  98. struct ich8_pr {
  99. u32 base:13; /* 0:12 Protected Range Base */
  100. u32 reserved1:2; /* 13:14 Reserved */
  101. u32 rpe:1; /* 15 Read Protection Enable */
  102. u32 limit:13; /* 16:28 Protected Range Limit */
  103. u32 reserved2:2; /* 29:30 Reserved */
  104. u32 wpe:1; /* 31 Write Protection Enable */
  105. } range;
  106. u32 regval;
  107. };
  108. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
  109. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
  110. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
  111. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  112. u32 offset, u8 byte);
  113. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  114. u8 *data);
  115. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  116. u16 *data);
  117. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  118. u8 size, u16 *data);
  119. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
  120. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
  121. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
  122. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
  123. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
  124. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
  125. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
  126. static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
  127. static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
  128. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
  129. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
  130. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
  131. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
  132. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
  133. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
  134. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
  135. static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
  136. static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
  137. static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw);
  138. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
  139. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
  140. static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force);
  141. static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
  142. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
  143. static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
  144. {
  145. return readw(hw->flash_address + reg);
  146. }
  147. static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
  148. {
  149. return readl(hw->flash_address + reg);
  150. }
  151. static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
  152. {
  153. writew(val, hw->flash_address + reg);
  154. }
  155. static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
  156. {
  157. writel(val, hw->flash_address + reg);
  158. }
  159. #define er16flash(reg) __er16flash(hw, (reg))
  160. #define er32flash(reg) __er32flash(hw, (reg))
  161. #define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
  162. #define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
  163. /**
  164. * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
  165. * @hw: pointer to the HW structure
  166. *
  167. * Test access to the PHY registers by reading the PHY ID registers. If
  168. * the PHY ID is already known (e.g. resume path) compare it with known ID,
  169. * otherwise assume the read PHY ID is correct if it is valid.
  170. *
  171. * Assumes the sw/fw/hw semaphore is already acquired.
  172. **/
  173. static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
  174. {
  175. u16 phy_reg = 0;
  176. u32 phy_id = 0;
  177. s32 ret_val = 0;
  178. u16 retry_count;
  179. u32 mac_reg = 0;
  180. for (retry_count = 0; retry_count < 2; retry_count++) {
  181. ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
  182. if (ret_val || (phy_reg == 0xFFFF))
  183. continue;
  184. phy_id = (u32)(phy_reg << 16);
  185. ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
  186. if (ret_val || (phy_reg == 0xFFFF)) {
  187. phy_id = 0;
  188. continue;
  189. }
  190. phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
  191. break;
  192. }
  193. if (hw->phy.id) {
  194. if (hw->phy.id == phy_id)
  195. goto out;
  196. } else if (phy_id) {
  197. hw->phy.id = phy_id;
  198. hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
  199. goto out;
  200. }
  201. /* In case the PHY needs to be in mdio slow mode,
  202. * set slow mode and try to get the PHY id again.
  203. */
  204. if (hw->mac.type < e1000_pch_lpt) {
  205. hw->phy.ops.release(hw);
  206. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  207. if (!ret_val)
  208. ret_val = e1000e_get_phy_id(hw);
  209. hw->phy.ops.acquire(hw);
  210. }
  211. if (ret_val)
  212. return false;
  213. out:
  214. if (hw->mac.type == e1000_pch_lpt) {
  215. /* Unforce SMBus mode in PHY */
  216. e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
  217. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  218. e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
  219. /* Unforce SMBus mode in MAC */
  220. mac_reg = er32(CTRL_EXT);
  221. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  222. ew32(CTRL_EXT, mac_reg);
  223. }
  224. return true;
  225. }
  226. /**
  227. * e1000_toggle_lanphypc_pch_lpt - toggle the LANPHYPC pin value
  228. * @hw: pointer to the HW structure
  229. *
  230. * Toggling the LANPHYPC pin value fully power-cycles the PHY and is
  231. * used to reset the PHY to a quiescent state when necessary.
  232. **/
  233. static void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
  234. {
  235. u32 mac_reg;
  236. /* Set Phy Config Counter to 50msec */
  237. mac_reg = er32(FEXTNVM3);
  238. mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  239. mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  240. ew32(FEXTNVM3, mac_reg);
  241. /* Toggle LANPHYPC Value bit */
  242. mac_reg = er32(CTRL);
  243. mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
  244. mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
  245. ew32(CTRL, mac_reg);
  246. e1e_flush();
  247. usleep_range(10, 20);
  248. mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
  249. ew32(CTRL, mac_reg);
  250. e1e_flush();
  251. if (hw->mac.type < e1000_pch_lpt) {
  252. msleep(50);
  253. } else {
  254. u16 count = 20;
  255. do {
  256. usleep_range(5000, 10000);
  257. } while (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LPCD) && count--);
  258. msleep(30);
  259. }
  260. }
  261. /**
  262. * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
  263. * @hw: pointer to the HW structure
  264. *
  265. * Workarounds/flow necessary for PHY initialization during driver load
  266. * and resume paths.
  267. **/
  268. static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
  269. {
  270. struct e1000_adapter *adapter = hw->adapter;
  271. u32 mac_reg, fwsm = er32(FWSM);
  272. s32 ret_val;
  273. /* Gate automatic PHY configuration by hardware on managed and
  274. * non-managed 82579 and newer adapters.
  275. */
  276. e1000_gate_hw_phy_config_ich8lan(hw, true);
  277. /* It is not possible to be certain of the current state of ULP
  278. * so forcibly disable it.
  279. */
  280. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
  281. e1000_disable_ulp_lpt_lp(hw, true);
  282. ret_val = hw->phy.ops.acquire(hw);
  283. if (ret_val) {
  284. e_dbg("Failed to initialize PHY flow\n");
  285. goto out;
  286. }
  287. /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
  288. * inaccessible and resetting the PHY is not blocked, toggle the
  289. * LANPHYPC Value bit to force the interconnect to PCIe mode.
  290. */
  291. switch (hw->mac.type) {
  292. case e1000_pch_lpt:
  293. if (e1000_phy_is_accessible_pchlan(hw))
  294. break;
  295. /* Before toggling LANPHYPC, see if PHY is accessible by
  296. * forcing MAC to SMBus mode first.
  297. */
  298. mac_reg = er32(CTRL_EXT);
  299. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  300. ew32(CTRL_EXT, mac_reg);
  301. /* Wait 50 milliseconds for MAC to finish any retries
  302. * that it might be trying to perform from previous
  303. * attempts to acknowledge any phy read requests.
  304. */
  305. msleep(50);
  306. /* fall-through */
  307. case e1000_pch2lan:
  308. if (e1000_phy_is_accessible_pchlan(hw))
  309. break;
  310. /* fall-through */
  311. case e1000_pchlan:
  312. if ((hw->mac.type == e1000_pchlan) &&
  313. (fwsm & E1000_ICH_FWSM_FW_VALID))
  314. break;
  315. if (hw->phy.ops.check_reset_block(hw)) {
  316. e_dbg("Required LANPHYPC toggle blocked by ME\n");
  317. ret_val = -E1000_ERR_PHY;
  318. break;
  319. }
  320. /* Toggle LANPHYPC Value bit */
  321. e1000_toggle_lanphypc_pch_lpt(hw);
  322. if (hw->mac.type >= e1000_pch_lpt) {
  323. if (e1000_phy_is_accessible_pchlan(hw))
  324. break;
  325. /* Toggling LANPHYPC brings the PHY out of SMBus mode
  326. * so ensure that the MAC is also out of SMBus mode
  327. */
  328. mac_reg = er32(CTRL_EXT);
  329. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  330. ew32(CTRL_EXT, mac_reg);
  331. if (e1000_phy_is_accessible_pchlan(hw))
  332. break;
  333. ret_val = -E1000_ERR_PHY;
  334. }
  335. break;
  336. default:
  337. break;
  338. }
  339. hw->phy.ops.release(hw);
  340. if (!ret_val) {
  341. /* Check to see if able to reset PHY. Print error if not */
  342. if (hw->phy.ops.check_reset_block(hw)) {
  343. e_err("Reset blocked by ME\n");
  344. goto out;
  345. }
  346. /* Reset the PHY before any access to it. Doing so, ensures
  347. * that the PHY is in a known good state before we read/write
  348. * PHY registers. The generic reset is sufficient here,
  349. * because we haven't determined the PHY type yet.
  350. */
  351. ret_val = e1000e_phy_hw_reset_generic(hw);
  352. if (ret_val)
  353. goto out;
  354. /* On a successful reset, possibly need to wait for the PHY
  355. * to quiesce to an accessible state before returning control
  356. * to the calling function. If the PHY does not quiesce, then
  357. * return E1000E_BLK_PHY_RESET, as this is the condition that
  358. * the PHY is in.
  359. */
  360. ret_val = hw->phy.ops.check_reset_block(hw);
  361. if (ret_val)
  362. e_err("ME blocked access to PHY after reset\n");
  363. }
  364. out:
  365. /* Ungate automatic PHY configuration on non-managed 82579 */
  366. if ((hw->mac.type == e1000_pch2lan) &&
  367. !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
  368. usleep_range(10000, 20000);
  369. e1000_gate_hw_phy_config_ich8lan(hw, false);
  370. }
  371. return ret_val;
  372. }
  373. /**
  374. * e1000_init_phy_params_pchlan - Initialize PHY function pointers
  375. * @hw: pointer to the HW structure
  376. *
  377. * Initialize family-specific PHY parameters and function pointers.
  378. **/
  379. static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
  380. {
  381. struct e1000_phy_info *phy = &hw->phy;
  382. s32 ret_val;
  383. phy->addr = 1;
  384. phy->reset_delay_us = 100;
  385. phy->ops.set_page = e1000_set_page_igp;
  386. phy->ops.read_reg = e1000_read_phy_reg_hv;
  387. phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
  388. phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
  389. phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
  390. phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
  391. phy->ops.write_reg = e1000_write_phy_reg_hv;
  392. phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
  393. phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
  394. phy->ops.power_up = e1000_power_up_phy_copper;
  395. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  396. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  397. phy->id = e1000_phy_unknown;
  398. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  399. if (ret_val)
  400. return ret_val;
  401. if (phy->id == e1000_phy_unknown)
  402. switch (hw->mac.type) {
  403. default:
  404. ret_val = e1000e_get_phy_id(hw);
  405. if (ret_val)
  406. return ret_val;
  407. if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
  408. break;
  409. /* fall-through */
  410. case e1000_pch2lan:
  411. case e1000_pch_lpt:
  412. /* In case the PHY needs to be in mdio slow mode,
  413. * set slow mode and try to get the PHY id again.
  414. */
  415. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  416. if (ret_val)
  417. return ret_val;
  418. ret_val = e1000e_get_phy_id(hw);
  419. if (ret_val)
  420. return ret_val;
  421. break;
  422. }
  423. phy->type = e1000e_get_phy_type_from_id(phy->id);
  424. switch (phy->type) {
  425. case e1000_phy_82577:
  426. case e1000_phy_82579:
  427. case e1000_phy_i217:
  428. phy->ops.check_polarity = e1000_check_polarity_82577;
  429. phy->ops.force_speed_duplex =
  430. e1000_phy_force_speed_duplex_82577;
  431. phy->ops.get_cable_length = e1000_get_cable_length_82577;
  432. phy->ops.get_info = e1000_get_phy_info_82577;
  433. phy->ops.commit = e1000e_phy_sw_reset;
  434. break;
  435. case e1000_phy_82578:
  436. phy->ops.check_polarity = e1000_check_polarity_m88;
  437. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  438. phy->ops.get_cable_length = e1000e_get_cable_length_m88;
  439. phy->ops.get_info = e1000e_get_phy_info_m88;
  440. break;
  441. default:
  442. ret_val = -E1000_ERR_PHY;
  443. break;
  444. }
  445. return ret_val;
  446. }
  447. /**
  448. * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
  449. * @hw: pointer to the HW structure
  450. *
  451. * Initialize family-specific PHY parameters and function pointers.
  452. **/
  453. static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
  454. {
  455. struct e1000_phy_info *phy = &hw->phy;
  456. s32 ret_val;
  457. u16 i = 0;
  458. phy->addr = 1;
  459. phy->reset_delay_us = 100;
  460. phy->ops.power_up = e1000_power_up_phy_copper;
  461. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  462. /* We may need to do this twice - once for IGP and if that fails,
  463. * we'll set BM func pointers and try again
  464. */
  465. ret_val = e1000e_determine_phy_address(hw);
  466. if (ret_val) {
  467. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  468. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  469. ret_val = e1000e_determine_phy_address(hw);
  470. if (ret_val) {
  471. e_dbg("Cannot determine PHY addr. Erroring out\n");
  472. return ret_val;
  473. }
  474. }
  475. phy->id = 0;
  476. while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
  477. (i++ < 100)) {
  478. usleep_range(1000, 2000);
  479. ret_val = e1000e_get_phy_id(hw);
  480. if (ret_val)
  481. return ret_val;
  482. }
  483. /* Verify phy id */
  484. switch (phy->id) {
  485. case IGP03E1000_E_PHY_ID:
  486. phy->type = e1000_phy_igp_3;
  487. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  488. phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
  489. phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
  490. phy->ops.get_info = e1000e_get_phy_info_igp;
  491. phy->ops.check_polarity = e1000_check_polarity_igp;
  492. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
  493. break;
  494. case IFE_E_PHY_ID:
  495. case IFE_PLUS_E_PHY_ID:
  496. case IFE_C_E_PHY_ID:
  497. phy->type = e1000_phy_ife;
  498. phy->autoneg_mask = E1000_ALL_NOT_GIG;
  499. phy->ops.get_info = e1000_get_phy_info_ife;
  500. phy->ops.check_polarity = e1000_check_polarity_ife;
  501. phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
  502. break;
  503. case BME1000_E_PHY_ID:
  504. phy->type = e1000_phy_bm;
  505. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  506. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  507. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  508. phy->ops.commit = e1000e_phy_sw_reset;
  509. phy->ops.get_info = e1000e_get_phy_info_m88;
  510. phy->ops.check_polarity = e1000_check_polarity_m88;
  511. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  512. break;
  513. default:
  514. return -E1000_ERR_PHY;
  515. break;
  516. }
  517. return 0;
  518. }
  519. /**
  520. * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
  521. * @hw: pointer to the HW structure
  522. *
  523. * Initialize family-specific NVM parameters and function
  524. * pointers.
  525. **/
  526. static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
  527. {
  528. struct e1000_nvm_info *nvm = &hw->nvm;
  529. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  530. u32 gfpreg, sector_base_addr, sector_end_addr;
  531. u16 i;
  532. /* Can't read flash registers if the register set isn't mapped. */
  533. if (!hw->flash_address) {
  534. e_dbg("ERROR: Flash registers not mapped\n");
  535. return -E1000_ERR_CONFIG;
  536. }
  537. nvm->type = e1000_nvm_flash_sw;
  538. gfpreg = er32flash(ICH_FLASH_GFPREG);
  539. /* sector_X_addr is a "sector"-aligned address (4096 bytes)
  540. * Add 1 to sector_end_addr since this sector is included in
  541. * the overall size.
  542. */
  543. sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
  544. sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
  545. /* flash_base_addr is byte-aligned */
  546. nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
  547. /* find total size of the NVM, then cut in half since the total
  548. * size represents two separate NVM banks.
  549. */
  550. nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
  551. << FLASH_SECTOR_ADDR_SHIFT);
  552. nvm->flash_bank_size /= 2;
  553. /* Adjust to word count */
  554. nvm->flash_bank_size /= sizeof(u16);
  555. nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
  556. /* Clear shadow ram */
  557. for (i = 0; i < nvm->word_size; i++) {
  558. dev_spec->shadow_ram[i].modified = false;
  559. dev_spec->shadow_ram[i].value = 0xFFFF;
  560. }
  561. return 0;
  562. }
  563. /**
  564. * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
  565. * @hw: pointer to the HW structure
  566. *
  567. * Initialize family-specific MAC parameters and function
  568. * pointers.
  569. **/
  570. static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
  571. {
  572. struct e1000_mac_info *mac = &hw->mac;
  573. /* Set media type function pointer */
  574. hw->phy.media_type = e1000_media_type_copper;
  575. /* Set mta register count */
  576. mac->mta_reg_count = 32;
  577. /* Set rar entry count */
  578. mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
  579. if (mac->type == e1000_ich8lan)
  580. mac->rar_entry_count--;
  581. /* FWSM register */
  582. mac->has_fwsm = true;
  583. /* ARC subsystem not supported */
  584. mac->arc_subsystem_valid = false;
  585. /* Adaptive IFS supported */
  586. mac->adaptive_ifs = true;
  587. /* LED and other operations */
  588. switch (mac->type) {
  589. case e1000_ich8lan:
  590. case e1000_ich9lan:
  591. case e1000_ich10lan:
  592. /* check management mode */
  593. mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
  594. /* ID LED init */
  595. mac->ops.id_led_init = e1000e_id_led_init_generic;
  596. /* blink LED */
  597. mac->ops.blink_led = e1000e_blink_led_generic;
  598. /* setup LED */
  599. mac->ops.setup_led = e1000e_setup_led_generic;
  600. /* cleanup LED */
  601. mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
  602. /* turn on/off LED */
  603. mac->ops.led_on = e1000_led_on_ich8lan;
  604. mac->ops.led_off = e1000_led_off_ich8lan;
  605. break;
  606. case e1000_pch2lan:
  607. mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
  608. mac->ops.rar_set = e1000_rar_set_pch2lan;
  609. /* fall-through */
  610. case e1000_pch_lpt:
  611. case e1000_pchlan:
  612. /* check management mode */
  613. mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
  614. /* ID LED init */
  615. mac->ops.id_led_init = e1000_id_led_init_pchlan;
  616. /* setup LED */
  617. mac->ops.setup_led = e1000_setup_led_pchlan;
  618. /* cleanup LED */
  619. mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
  620. /* turn on/off LED */
  621. mac->ops.led_on = e1000_led_on_pchlan;
  622. mac->ops.led_off = e1000_led_off_pchlan;
  623. break;
  624. default:
  625. break;
  626. }
  627. if (mac->type == e1000_pch_lpt) {
  628. mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
  629. mac->ops.rar_set = e1000_rar_set_pch_lpt;
  630. mac->ops.setup_physical_interface =
  631. e1000_setup_copper_link_pch_lpt;
  632. mac->ops.rar_get_count = e1000_rar_get_count_pch_lpt;
  633. }
  634. /* Enable PCS Lock-loss workaround for ICH8 */
  635. if (mac->type == e1000_ich8lan)
  636. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
  637. return 0;
  638. }
  639. /**
  640. * __e1000_access_emi_reg_locked - Read/write EMI register
  641. * @hw: pointer to the HW structure
  642. * @addr: EMI address to program
  643. * @data: pointer to value to read/write from/to the EMI address
  644. * @read: boolean flag to indicate read or write
  645. *
  646. * This helper function assumes the SW/FW/HW Semaphore is already acquired.
  647. **/
  648. static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
  649. u16 *data, bool read)
  650. {
  651. s32 ret_val;
  652. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
  653. if (ret_val)
  654. return ret_val;
  655. if (read)
  656. ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
  657. else
  658. ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
  659. return ret_val;
  660. }
  661. /**
  662. * e1000_read_emi_reg_locked - Read Extended Management Interface register
  663. * @hw: pointer to the HW structure
  664. * @addr: EMI address to program
  665. * @data: value to be read from the EMI address
  666. *
  667. * Assumes the SW/FW/HW Semaphore is already acquired.
  668. **/
  669. s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
  670. {
  671. return __e1000_access_emi_reg_locked(hw, addr, data, true);
  672. }
  673. /**
  674. * e1000_write_emi_reg_locked - Write Extended Management Interface register
  675. * @hw: pointer to the HW structure
  676. * @addr: EMI address to program
  677. * @data: value to be written to the EMI address
  678. *
  679. * Assumes the SW/FW/HW Semaphore is already acquired.
  680. **/
  681. s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
  682. {
  683. return __e1000_access_emi_reg_locked(hw, addr, &data, false);
  684. }
  685. /**
  686. * e1000_set_eee_pchlan - Enable/disable EEE support
  687. * @hw: pointer to the HW structure
  688. *
  689. * Enable/disable EEE based on setting in dev_spec structure, the duplex of
  690. * the link and the EEE capabilities of the link partner. The LPI Control
  691. * register bits will remain set only if/when link is up.
  692. *
  693. * EEE LPI must not be asserted earlier than one second after link is up.
  694. * On 82579, EEE LPI should not be enabled until such time otherwise there
  695. * can be link issues with some switches. Other devices can have EEE LPI
  696. * enabled immediately upon link up since they have a timer in hardware which
  697. * prevents LPI from being asserted too early.
  698. **/
  699. s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
  700. {
  701. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  702. s32 ret_val;
  703. u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
  704. switch (hw->phy.type) {
  705. case e1000_phy_82579:
  706. lpa = I82579_EEE_LP_ABILITY;
  707. pcs_status = I82579_EEE_PCS_STATUS;
  708. adv_addr = I82579_EEE_ADVERTISEMENT;
  709. break;
  710. case e1000_phy_i217:
  711. lpa = I217_EEE_LP_ABILITY;
  712. pcs_status = I217_EEE_PCS_STATUS;
  713. adv_addr = I217_EEE_ADVERTISEMENT;
  714. break;
  715. default:
  716. return 0;
  717. }
  718. ret_val = hw->phy.ops.acquire(hw);
  719. if (ret_val)
  720. return ret_val;
  721. ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
  722. if (ret_val)
  723. goto release;
  724. /* Clear bits that enable EEE in various speeds */
  725. lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
  726. /* Enable EEE if not disabled by user */
  727. if (!dev_spec->eee_disable) {
  728. /* Save off link partner's EEE ability */
  729. ret_val = e1000_read_emi_reg_locked(hw, lpa,
  730. &dev_spec->eee_lp_ability);
  731. if (ret_val)
  732. goto release;
  733. /* Read EEE advertisement */
  734. ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
  735. if (ret_val)
  736. goto release;
  737. /* Enable EEE only for speeds in which the link partner is
  738. * EEE capable and for which we advertise EEE.
  739. */
  740. if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
  741. lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
  742. if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
  743. e1e_rphy_locked(hw, MII_LPA, &data);
  744. if (data & LPA_100FULL)
  745. lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
  746. else
  747. /* EEE is not supported in 100Half, so ignore
  748. * partner's EEE in 100 ability if full-duplex
  749. * is not advertised.
  750. */
  751. dev_spec->eee_lp_ability &=
  752. ~I82579_EEE_100_SUPPORTED;
  753. }
  754. }
  755. if (hw->phy.type == e1000_phy_82579) {
  756. ret_val = e1000_read_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
  757. &data);
  758. if (ret_val)
  759. goto release;
  760. data &= ~I82579_LPI_100_PLL_SHUT;
  761. ret_val = e1000_write_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
  762. data);
  763. }
  764. /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
  765. ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
  766. if (ret_val)
  767. goto release;
  768. ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
  769. release:
  770. hw->phy.ops.release(hw);
  771. return ret_val;
  772. }
  773. /**
  774. * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
  775. * @hw: pointer to the HW structure
  776. * @link: link up bool flag
  777. *
  778. * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
  779. * preventing further DMA write requests. Workaround the issue by disabling
  780. * the de-assertion of the clock request when in 1Gpbs mode.
  781. * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
  782. * speeds in order to avoid Tx hangs.
  783. **/
  784. static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
  785. {
  786. u32 fextnvm6 = er32(FEXTNVM6);
  787. u32 status = er32(STATUS);
  788. s32 ret_val = 0;
  789. u16 reg;
  790. if (link && (status & E1000_STATUS_SPEED_1000)) {
  791. ret_val = hw->phy.ops.acquire(hw);
  792. if (ret_val)
  793. return ret_val;
  794. ret_val =
  795. e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  796. &reg);
  797. if (ret_val)
  798. goto release;
  799. ret_val =
  800. e1000e_write_kmrn_reg_locked(hw,
  801. E1000_KMRNCTRLSTA_K1_CONFIG,
  802. reg &
  803. ~E1000_KMRNCTRLSTA_K1_ENABLE);
  804. if (ret_val)
  805. goto release;
  806. usleep_range(10, 20);
  807. ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
  808. ret_val =
  809. e1000e_write_kmrn_reg_locked(hw,
  810. E1000_KMRNCTRLSTA_K1_CONFIG,
  811. reg);
  812. release:
  813. hw->phy.ops.release(hw);
  814. } else {
  815. /* clear FEXTNVM6 bit 8 on link down or 10/100 */
  816. fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
  817. if (!link || ((status & E1000_STATUS_SPEED_100) &&
  818. (status & E1000_STATUS_FD)))
  819. goto update_fextnvm6;
  820. ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
  821. if (ret_val)
  822. return ret_val;
  823. /* Clear link status transmit timeout */
  824. reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
  825. if (status & E1000_STATUS_SPEED_100) {
  826. /* Set inband Tx timeout to 5x10us for 100Half */
  827. reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
  828. /* Do not extend the K1 entry latency for 100Half */
  829. fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
  830. } else {
  831. /* Set inband Tx timeout to 50x10us for 10Full/Half */
  832. reg |= 50 <<
  833. I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
  834. /* Extend the K1 entry latency for 10 Mbps */
  835. fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
  836. }
  837. ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
  838. if (ret_val)
  839. return ret_val;
  840. update_fextnvm6:
  841. ew32(FEXTNVM6, fextnvm6);
  842. }
  843. return ret_val;
  844. }
  845. /**
  846. * e1000_platform_pm_pch_lpt - Set platform power management values
  847. * @hw: pointer to the HW structure
  848. * @link: bool indicating link status
  849. *
  850. * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
  851. * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
  852. * when link is up (which must not exceed the maximum latency supported
  853. * by the platform), otherwise specify there is no LTR requirement.
  854. * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
  855. * latencies in the LTR Extended Capability Structure in the PCIe Extended
  856. * Capability register set, on this device LTR is set by writing the
  857. * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
  858. * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
  859. * message to the PMC.
  860. **/
  861. static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
  862. {
  863. u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
  864. link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
  865. u16 lat_enc = 0; /* latency encoded */
  866. if (link) {
  867. u16 speed, duplex, scale = 0;
  868. u16 max_snoop, max_nosnoop;
  869. u16 max_ltr_enc; /* max LTR latency encoded */
  870. s64 lat_ns; /* latency (ns) */
  871. s64 value;
  872. u32 rxa;
  873. if (!hw->adapter->max_frame_size) {
  874. e_dbg("max_frame_size not set.\n");
  875. return -E1000_ERR_CONFIG;
  876. }
  877. hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
  878. if (!speed) {
  879. e_dbg("Speed not set.\n");
  880. return -E1000_ERR_CONFIG;
  881. }
  882. /* Rx Packet Buffer Allocation size (KB) */
  883. rxa = er32(PBA) & E1000_PBA_RXA_MASK;
  884. /* Determine the maximum latency tolerated by the device.
  885. *
  886. * Per the PCIe spec, the tolerated latencies are encoded as
  887. * a 3-bit encoded scale (only 0-5 are valid) multiplied by
  888. * a 10-bit value (0-1023) to provide a range from 1 ns to
  889. * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
  890. * 1=2^5ns, 2=2^10ns,...5=2^25ns.
  891. */
  892. lat_ns = ((s64)rxa * 1024 -
  893. (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
  894. if (lat_ns < 0)
  895. lat_ns = 0;
  896. else
  897. do_div(lat_ns, speed);
  898. value = lat_ns;
  899. while (value > PCI_LTR_VALUE_MASK) {
  900. scale++;
  901. value = DIV_ROUND_UP(value, (1 << 5));
  902. }
  903. if (scale > E1000_LTRV_SCALE_MAX) {
  904. e_dbg("Invalid LTR latency scale %d\n", scale);
  905. return -E1000_ERR_CONFIG;
  906. }
  907. lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
  908. /* Determine the maximum latency tolerated by the platform */
  909. pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
  910. &max_snoop);
  911. pci_read_config_word(hw->adapter->pdev,
  912. E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
  913. max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
  914. if (lat_enc > max_ltr_enc)
  915. lat_enc = max_ltr_enc;
  916. }
  917. /* Set Snoop and No-Snoop latencies the same */
  918. reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
  919. ew32(LTRV, reg);
  920. return 0;
  921. }
  922. /**
  923. * e1000_enable_ulp_lpt_lp - configure Ultra Low Power mode for LynxPoint-LP
  924. * @hw: pointer to the HW structure
  925. * @to_sx: boolean indicating a system power state transition to Sx
  926. *
  927. * When link is down, configure ULP mode to significantly reduce the power
  928. * to the PHY. If on a Manageability Engine (ME) enabled system, tell the
  929. * ME firmware to start the ULP configuration. If not on an ME enabled
  930. * system, configure the ULP mode by software.
  931. */
  932. s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
  933. {
  934. u32 mac_reg;
  935. s32 ret_val = 0;
  936. u16 phy_reg;
  937. if ((hw->mac.type < e1000_pch_lpt) ||
  938. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
  939. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
  940. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
  941. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
  942. (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
  943. return 0;
  944. if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
  945. /* Request ME configure ULP mode in the PHY */
  946. mac_reg = er32(H2ME);
  947. mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
  948. ew32(H2ME, mac_reg);
  949. goto out;
  950. }
  951. if (!to_sx) {
  952. int i = 0;
  953. /* Poll up to 5 seconds for Cable Disconnected indication */
  954. while (!(er32(FEXT) & E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
  955. /* Bail if link is re-acquired */
  956. if (er32(STATUS) & E1000_STATUS_LU)
  957. return -E1000_ERR_PHY;
  958. if (i++ == 100)
  959. break;
  960. msleep(50);
  961. }
  962. e_dbg("CABLE_DISCONNECTED %s set after %dmsec\n",
  963. (er32(FEXT) &
  964. E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not", i * 50);
  965. }
  966. ret_val = hw->phy.ops.acquire(hw);
  967. if (ret_val)
  968. goto out;
  969. /* Force SMBus mode in PHY */
  970. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
  971. if (ret_val)
  972. goto release;
  973. phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
  974. e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
  975. /* Force SMBus mode in MAC */
  976. mac_reg = er32(CTRL_EXT);
  977. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  978. ew32(CTRL_EXT, mac_reg);
  979. /* Set Inband ULP Exit, Reset to SMBus mode and
  980. * Disable SMBus Release on PERST# in PHY
  981. */
  982. ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
  983. if (ret_val)
  984. goto release;
  985. phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
  986. I218_ULP_CONFIG1_DISABLE_SMB_PERST);
  987. if (to_sx) {
  988. if (er32(WUFC) & E1000_WUFC_LNKC)
  989. phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
  990. phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
  991. } else {
  992. phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
  993. }
  994. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  995. /* Set Disable SMBus Release on PERST# in MAC */
  996. mac_reg = er32(FEXTNVM7);
  997. mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
  998. ew32(FEXTNVM7, mac_reg);
  999. /* Commit ULP changes in PHY by starting auto ULP configuration */
  1000. phy_reg |= I218_ULP_CONFIG1_START;
  1001. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1002. release:
  1003. hw->phy.ops.release(hw);
  1004. out:
  1005. if (ret_val)
  1006. e_dbg("Error in ULP enable flow: %d\n", ret_val);
  1007. else
  1008. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
  1009. return ret_val;
  1010. }
  1011. /**
  1012. * e1000_disable_ulp_lpt_lp - unconfigure Ultra Low Power mode for LynxPoint-LP
  1013. * @hw: pointer to the HW structure
  1014. * @force: boolean indicating whether or not to force disabling ULP
  1015. *
  1016. * Un-configure ULP mode when link is up, the system is transitioned from
  1017. * Sx or the driver is unloaded. If on a Manageability Engine (ME) enabled
  1018. * system, poll for an indication from ME that ULP has been un-configured.
  1019. * If not on an ME enabled system, un-configure the ULP mode by software.
  1020. *
  1021. * During nominal operation, this function is called when link is acquired
  1022. * to disable ULP mode (force=false); otherwise, for example when unloading
  1023. * the driver or during Sx->S0 transitions, this is called with force=true
  1024. * to forcibly disable ULP.
  1025. */
  1026. static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
  1027. {
  1028. s32 ret_val = 0;
  1029. u32 mac_reg;
  1030. u16 phy_reg;
  1031. int i = 0;
  1032. if ((hw->mac.type < e1000_pch_lpt) ||
  1033. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
  1034. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
  1035. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
  1036. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
  1037. (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
  1038. return 0;
  1039. if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
  1040. if (force) {
  1041. /* Request ME un-configure ULP mode in the PHY */
  1042. mac_reg = er32(H2ME);
  1043. mac_reg &= ~E1000_H2ME_ULP;
  1044. mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
  1045. ew32(H2ME, mac_reg);
  1046. }
  1047. /* Poll up to 100msec for ME to clear ULP_CFG_DONE */
  1048. while (er32(FWSM) & E1000_FWSM_ULP_CFG_DONE) {
  1049. if (i++ == 10) {
  1050. ret_val = -E1000_ERR_PHY;
  1051. goto out;
  1052. }
  1053. usleep_range(10000, 20000);
  1054. }
  1055. e_dbg("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
  1056. if (force) {
  1057. mac_reg = er32(H2ME);
  1058. mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
  1059. ew32(H2ME, mac_reg);
  1060. } else {
  1061. /* Clear H2ME.ULP after ME ULP configuration */
  1062. mac_reg = er32(H2ME);
  1063. mac_reg &= ~E1000_H2ME_ULP;
  1064. ew32(H2ME, mac_reg);
  1065. }
  1066. goto out;
  1067. }
  1068. ret_val = hw->phy.ops.acquire(hw);
  1069. if (ret_val)
  1070. goto out;
  1071. if (force)
  1072. /* Toggle LANPHYPC Value bit */
  1073. e1000_toggle_lanphypc_pch_lpt(hw);
  1074. /* Unforce SMBus mode in PHY */
  1075. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
  1076. if (ret_val) {
  1077. /* The MAC might be in PCIe mode, so temporarily force to
  1078. * SMBus mode in order to access the PHY.
  1079. */
  1080. mac_reg = er32(CTRL_EXT);
  1081. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  1082. ew32(CTRL_EXT, mac_reg);
  1083. msleep(50);
  1084. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
  1085. &phy_reg);
  1086. if (ret_val)
  1087. goto release;
  1088. }
  1089. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  1090. e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
  1091. /* Unforce SMBus mode in MAC */
  1092. mac_reg = er32(CTRL_EXT);
  1093. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  1094. ew32(CTRL_EXT, mac_reg);
  1095. /* When ULP mode was previously entered, K1 was disabled by the
  1096. * hardware. Re-Enable K1 in the PHY when exiting ULP.
  1097. */
  1098. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
  1099. if (ret_val)
  1100. goto release;
  1101. phy_reg |= HV_PM_CTRL_K1_ENABLE;
  1102. e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
  1103. /* Clear ULP enabled configuration */
  1104. ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
  1105. if (ret_val)
  1106. goto release;
  1107. phy_reg &= ~(I218_ULP_CONFIG1_IND |
  1108. I218_ULP_CONFIG1_STICKY_ULP |
  1109. I218_ULP_CONFIG1_RESET_TO_SMBUS |
  1110. I218_ULP_CONFIG1_WOL_HOST |
  1111. I218_ULP_CONFIG1_INBAND_EXIT |
  1112. I218_ULP_CONFIG1_DISABLE_SMB_PERST);
  1113. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1114. /* Commit ULP changes by starting auto ULP configuration */
  1115. phy_reg |= I218_ULP_CONFIG1_START;
  1116. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1117. /* Clear Disable SMBus Release on PERST# in MAC */
  1118. mac_reg = er32(FEXTNVM7);
  1119. mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
  1120. ew32(FEXTNVM7, mac_reg);
  1121. release:
  1122. hw->phy.ops.release(hw);
  1123. if (force) {
  1124. e1000_phy_hw_reset(hw);
  1125. msleep(50);
  1126. }
  1127. out:
  1128. if (ret_val)
  1129. e_dbg("Error in ULP disable flow: %d\n", ret_val);
  1130. else
  1131. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
  1132. return ret_val;
  1133. }
  1134. /**
  1135. * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
  1136. * @hw: pointer to the HW structure
  1137. *
  1138. * Checks to see of the link status of the hardware has changed. If a
  1139. * change in link status has been detected, then we read the PHY registers
  1140. * to get the current speed/duplex if link exists.
  1141. **/
  1142. static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
  1143. {
  1144. struct e1000_mac_info *mac = &hw->mac;
  1145. s32 ret_val;
  1146. bool link;
  1147. u16 phy_reg;
  1148. /* We only want to go out to the PHY registers to see if Auto-Neg
  1149. * has completed and/or if our link status has changed. The
  1150. * get_link_status flag is set upon receiving a Link Status
  1151. * Change or Rx Sequence Error interrupt.
  1152. */
  1153. if (!mac->get_link_status)
  1154. return 0;
  1155. /* First we want to see if the MII Status Register reports
  1156. * link. If so, then we want to get the current speed/duplex
  1157. * of the PHY.
  1158. */
  1159. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1160. if (ret_val)
  1161. return ret_val;
  1162. if (hw->mac.type == e1000_pchlan) {
  1163. ret_val = e1000_k1_gig_workaround_hv(hw, link);
  1164. if (ret_val)
  1165. return ret_val;
  1166. }
  1167. /* When connected at 10Mbps half-duplex, some parts are excessively
  1168. * aggressive resulting in many collisions. To avoid this, increase
  1169. * the IPG and reduce Rx latency in the PHY.
  1170. */
  1171. if (((hw->mac.type == e1000_pch2lan) ||
  1172. (hw->mac.type == e1000_pch_lpt)) && link) {
  1173. u32 reg;
  1174. reg = er32(STATUS);
  1175. if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
  1176. u16 emi_addr;
  1177. reg = er32(TIPG);
  1178. reg &= ~E1000_TIPG_IPGT_MASK;
  1179. reg |= 0xFF;
  1180. ew32(TIPG, reg);
  1181. /* Reduce Rx latency in analog PHY */
  1182. ret_val = hw->phy.ops.acquire(hw);
  1183. if (ret_val)
  1184. return ret_val;
  1185. if (hw->mac.type == e1000_pch2lan)
  1186. emi_addr = I82579_RX_CONFIG;
  1187. else
  1188. emi_addr = I217_RX_CONFIG;
  1189. ret_val = e1000_write_emi_reg_locked(hw, emi_addr, 0);
  1190. hw->phy.ops.release(hw);
  1191. if (ret_val)
  1192. return ret_val;
  1193. }
  1194. }
  1195. /* Work-around I218 hang issue */
  1196. if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
  1197. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
  1198. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
  1199. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
  1200. ret_val = e1000_k1_workaround_lpt_lp(hw, link);
  1201. if (ret_val)
  1202. return ret_val;
  1203. }
  1204. if (hw->mac.type == e1000_pch_lpt) {
  1205. /* Set platform power management values for
  1206. * Latency Tolerance Reporting (LTR)
  1207. */
  1208. ret_val = e1000_platform_pm_pch_lpt(hw, link);
  1209. if (ret_val)
  1210. return ret_val;
  1211. }
  1212. /* Clear link partner's EEE ability */
  1213. hw->dev_spec.ich8lan.eee_lp_ability = 0;
  1214. if (!link)
  1215. return 0; /* No link detected */
  1216. mac->get_link_status = false;
  1217. switch (hw->mac.type) {
  1218. case e1000_pch2lan:
  1219. ret_val = e1000_k1_workaround_lv(hw);
  1220. if (ret_val)
  1221. return ret_val;
  1222. /* fall-thru */
  1223. case e1000_pchlan:
  1224. if (hw->phy.type == e1000_phy_82578) {
  1225. ret_val = e1000_link_stall_workaround_hv(hw);
  1226. if (ret_val)
  1227. return ret_val;
  1228. }
  1229. /* Workaround for PCHx parts in half-duplex:
  1230. * Set the number of preambles removed from the packet
  1231. * when it is passed from the PHY to the MAC to prevent
  1232. * the MAC from misinterpreting the packet type.
  1233. */
  1234. e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
  1235. phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
  1236. if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
  1237. phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
  1238. e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
  1239. break;
  1240. default:
  1241. break;
  1242. }
  1243. /* Check if there was DownShift, must be checked
  1244. * immediately after link-up
  1245. */
  1246. e1000e_check_downshift(hw);
  1247. /* Enable/Disable EEE after link up */
  1248. if (hw->phy.type > e1000_phy_82579) {
  1249. ret_val = e1000_set_eee_pchlan(hw);
  1250. if (ret_val)
  1251. return ret_val;
  1252. }
  1253. /* If we are forcing speed/duplex, then we simply return since
  1254. * we have already determined whether we have link or not.
  1255. */
  1256. if (!mac->autoneg)
  1257. return -E1000_ERR_CONFIG;
  1258. /* Auto-Neg is enabled. Auto Speed Detection takes care
  1259. * of MAC speed/duplex configuration. So we only need to
  1260. * configure Collision Distance in the MAC.
  1261. */
  1262. mac->ops.config_collision_dist(hw);
  1263. /* Configure Flow Control now that Auto-Neg has completed.
  1264. * First, we need to restore the desired flow control
  1265. * settings because we may have had to re-autoneg with a
  1266. * different link partner.
  1267. */
  1268. ret_val = e1000e_config_fc_after_link_up(hw);
  1269. if (ret_val)
  1270. e_dbg("Error configuring flow control\n");
  1271. return ret_val;
  1272. }
  1273. static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
  1274. {
  1275. struct e1000_hw *hw = &adapter->hw;
  1276. s32 rc;
  1277. rc = e1000_init_mac_params_ich8lan(hw);
  1278. if (rc)
  1279. return rc;
  1280. rc = e1000_init_nvm_params_ich8lan(hw);
  1281. if (rc)
  1282. return rc;
  1283. switch (hw->mac.type) {
  1284. case e1000_ich8lan:
  1285. case e1000_ich9lan:
  1286. case e1000_ich10lan:
  1287. rc = e1000_init_phy_params_ich8lan(hw);
  1288. break;
  1289. case e1000_pchlan:
  1290. case e1000_pch2lan:
  1291. case e1000_pch_lpt:
  1292. rc = e1000_init_phy_params_pchlan(hw);
  1293. break;
  1294. default:
  1295. break;
  1296. }
  1297. if (rc)
  1298. return rc;
  1299. /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
  1300. * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
  1301. */
  1302. if ((adapter->hw.phy.type == e1000_phy_ife) ||
  1303. ((adapter->hw.mac.type >= e1000_pch2lan) &&
  1304. (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
  1305. adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
  1306. adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
  1307. hw->mac.ops.blink_led = NULL;
  1308. }
  1309. if ((adapter->hw.mac.type == e1000_ich8lan) &&
  1310. (adapter->hw.phy.type != e1000_phy_ife))
  1311. adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
  1312. /* Enable workaround for 82579 w/ ME enabled */
  1313. if ((adapter->hw.mac.type == e1000_pch2lan) &&
  1314. (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  1315. adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
  1316. return 0;
  1317. }
  1318. static DEFINE_MUTEX(nvm_mutex);
  1319. /**
  1320. * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
  1321. * @hw: pointer to the HW structure
  1322. *
  1323. * Acquires the mutex for performing NVM operations.
  1324. **/
  1325. static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
  1326. {
  1327. mutex_lock(&nvm_mutex);
  1328. return 0;
  1329. }
  1330. /**
  1331. * e1000_release_nvm_ich8lan - Release NVM mutex
  1332. * @hw: pointer to the HW structure
  1333. *
  1334. * Releases the mutex used while performing NVM operations.
  1335. **/
  1336. static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
  1337. {
  1338. mutex_unlock(&nvm_mutex);
  1339. }
  1340. /**
  1341. * e1000_acquire_swflag_ich8lan - Acquire software control flag
  1342. * @hw: pointer to the HW structure
  1343. *
  1344. * Acquires the software control flag for performing PHY and select
  1345. * MAC CSR accesses.
  1346. **/
  1347. static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
  1348. {
  1349. u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
  1350. s32 ret_val = 0;
  1351. if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
  1352. &hw->adapter->state)) {
  1353. e_dbg("contention for Phy access\n");
  1354. return -E1000_ERR_PHY;
  1355. }
  1356. while (timeout) {
  1357. extcnf_ctrl = er32(EXTCNF_CTRL);
  1358. if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
  1359. break;
  1360. mdelay(1);
  1361. timeout--;
  1362. }
  1363. if (!timeout) {
  1364. e_dbg("SW has already locked the resource.\n");
  1365. ret_val = -E1000_ERR_CONFIG;
  1366. goto out;
  1367. }
  1368. timeout = SW_FLAG_TIMEOUT;
  1369. extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
  1370. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1371. while (timeout) {
  1372. extcnf_ctrl = er32(EXTCNF_CTRL);
  1373. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
  1374. break;
  1375. mdelay(1);
  1376. timeout--;
  1377. }
  1378. if (!timeout) {
  1379. e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
  1380. er32(FWSM), extcnf_ctrl);
  1381. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  1382. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1383. ret_val = -E1000_ERR_CONFIG;
  1384. goto out;
  1385. }
  1386. out:
  1387. if (ret_val)
  1388. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  1389. return ret_val;
  1390. }
  1391. /**
  1392. * e1000_release_swflag_ich8lan - Release software control flag
  1393. * @hw: pointer to the HW structure
  1394. *
  1395. * Releases the software control flag for performing PHY and select
  1396. * MAC CSR accesses.
  1397. **/
  1398. static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
  1399. {
  1400. u32 extcnf_ctrl;
  1401. extcnf_ctrl = er32(EXTCNF_CTRL);
  1402. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
  1403. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  1404. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1405. } else {
  1406. e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
  1407. }
  1408. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  1409. }
  1410. /**
  1411. * e1000_check_mng_mode_ich8lan - Checks management mode
  1412. * @hw: pointer to the HW structure
  1413. *
  1414. * This checks if the adapter has any manageability enabled.
  1415. * This is a function pointer entry point only called by read/write
  1416. * routines for the PHY and NVM parts.
  1417. **/
  1418. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
  1419. {
  1420. u32 fwsm;
  1421. fwsm = er32(FWSM);
  1422. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  1423. ((fwsm & E1000_FWSM_MODE_MASK) ==
  1424. (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  1425. }
  1426. /**
  1427. * e1000_check_mng_mode_pchlan - Checks management mode
  1428. * @hw: pointer to the HW structure
  1429. *
  1430. * This checks if the adapter has iAMT enabled.
  1431. * This is a function pointer entry point only called by read/write
  1432. * routines for the PHY and NVM parts.
  1433. **/
  1434. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
  1435. {
  1436. u32 fwsm;
  1437. fwsm = er32(FWSM);
  1438. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  1439. (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  1440. }
  1441. /**
  1442. * e1000_rar_set_pch2lan - Set receive address register
  1443. * @hw: pointer to the HW structure
  1444. * @addr: pointer to the receive address
  1445. * @index: receive address array register
  1446. *
  1447. * Sets the receive address array register at index to the address passed
  1448. * in by addr. For 82579, RAR[0] is the base address register that is to
  1449. * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
  1450. * Use SHRA[0-3] in place of those reserved for ME.
  1451. **/
  1452. static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
  1453. {
  1454. u32 rar_low, rar_high;
  1455. /* HW expects these in little endian so we reverse the byte order
  1456. * from network order (big endian) to little endian
  1457. */
  1458. rar_low = ((u32)addr[0] |
  1459. ((u32)addr[1] << 8) |
  1460. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1461. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1462. /* If MAC address zero, no need to set the AV bit */
  1463. if (rar_low || rar_high)
  1464. rar_high |= E1000_RAH_AV;
  1465. if (index == 0) {
  1466. ew32(RAL(index), rar_low);
  1467. e1e_flush();
  1468. ew32(RAH(index), rar_high);
  1469. e1e_flush();
  1470. return 0;
  1471. }
  1472. /* RAR[1-6] are owned by manageability. Skip those and program the
  1473. * next address into the SHRA register array.
  1474. */
  1475. if (index < (u32)(hw->mac.rar_entry_count)) {
  1476. s32 ret_val;
  1477. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1478. if (ret_val)
  1479. goto out;
  1480. ew32(SHRAL(index - 1), rar_low);
  1481. e1e_flush();
  1482. ew32(SHRAH(index - 1), rar_high);
  1483. e1e_flush();
  1484. e1000_release_swflag_ich8lan(hw);
  1485. /* verify the register updates */
  1486. if ((er32(SHRAL(index - 1)) == rar_low) &&
  1487. (er32(SHRAH(index - 1)) == rar_high))
  1488. return 0;
  1489. e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
  1490. (index - 1), er32(FWSM));
  1491. }
  1492. out:
  1493. e_dbg("Failed to write receive address at index %d\n", index);
  1494. return -E1000_ERR_CONFIG;
  1495. }
  1496. /**
  1497. * e1000_rar_get_count_pch_lpt - Get the number of available SHRA
  1498. * @hw: pointer to the HW structure
  1499. *
  1500. * Get the number of available receive registers that the Host can
  1501. * program. SHRA[0-10] are the shared receive address registers
  1502. * that are shared between the Host and manageability engine (ME).
  1503. * ME can reserve any number of addresses and the host needs to be
  1504. * able to tell how many available registers it has access to.
  1505. **/
  1506. static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw)
  1507. {
  1508. u32 wlock_mac;
  1509. u32 num_entries;
  1510. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1511. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1512. switch (wlock_mac) {
  1513. case 0:
  1514. /* All SHRA[0..10] and RAR[0] available */
  1515. num_entries = hw->mac.rar_entry_count;
  1516. break;
  1517. case 1:
  1518. /* Only RAR[0] available */
  1519. num_entries = 1;
  1520. break;
  1521. default:
  1522. /* SHRA[0..(wlock_mac - 1)] available + RAR[0] */
  1523. num_entries = wlock_mac + 1;
  1524. break;
  1525. }
  1526. return num_entries;
  1527. }
  1528. /**
  1529. * e1000_rar_set_pch_lpt - Set receive address registers
  1530. * @hw: pointer to the HW structure
  1531. * @addr: pointer to the receive address
  1532. * @index: receive address array register
  1533. *
  1534. * Sets the receive address register array at index to the address passed
  1535. * in by addr. For LPT, RAR[0] is the base address register that is to
  1536. * contain the MAC address. SHRA[0-10] are the shared receive address
  1537. * registers that are shared between the Host and manageability engine (ME).
  1538. **/
  1539. static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
  1540. {
  1541. u32 rar_low, rar_high;
  1542. u32 wlock_mac;
  1543. /* HW expects these in little endian so we reverse the byte order
  1544. * from network order (big endian) to little endian
  1545. */
  1546. rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
  1547. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1548. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1549. /* If MAC address zero, no need to set the AV bit */
  1550. if (rar_low || rar_high)
  1551. rar_high |= E1000_RAH_AV;
  1552. if (index == 0) {
  1553. ew32(RAL(index), rar_low);
  1554. e1e_flush();
  1555. ew32(RAH(index), rar_high);
  1556. e1e_flush();
  1557. return 0;
  1558. }
  1559. /* The manageability engine (ME) can lock certain SHRAR registers that
  1560. * it is using - those registers are unavailable for use.
  1561. */
  1562. if (index < hw->mac.rar_entry_count) {
  1563. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1564. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1565. /* Check if all SHRAR registers are locked */
  1566. if (wlock_mac == 1)
  1567. goto out;
  1568. if ((wlock_mac == 0) || (index <= wlock_mac)) {
  1569. s32 ret_val;
  1570. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1571. if (ret_val)
  1572. goto out;
  1573. ew32(SHRAL_PCH_LPT(index - 1), rar_low);
  1574. e1e_flush();
  1575. ew32(SHRAH_PCH_LPT(index - 1), rar_high);
  1576. e1e_flush();
  1577. e1000_release_swflag_ich8lan(hw);
  1578. /* verify the register updates */
  1579. if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
  1580. (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
  1581. return 0;
  1582. }
  1583. }
  1584. out:
  1585. e_dbg("Failed to write receive address at index %d\n", index);
  1586. return -E1000_ERR_CONFIG;
  1587. }
  1588. /**
  1589. * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
  1590. * @hw: pointer to the HW structure
  1591. *
  1592. * Checks if firmware is blocking the reset of the PHY.
  1593. * This is a function pointer entry point only called by
  1594. * reset routines.
  1595. **/
  1596. static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
  1597. {
  1598. bool blocked = false;
  1599. int i = 0;
  1600. while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
  1601. (i++ < 10))
  1602. usleep_range(10000, 20000);
  1603. return blocked ? E1000_BLK_PHY_RESET : 0;
  1604. }
  1605. /**
  1606. * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
  1607. * @hw: pointer to the HW structure
  1608. *
  1609. * Assumes semaphore already acquired.
  1610. *
  1611. **/
  1612. static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
  1613. {
  1614. u16 phy_data;
  1615. u32 strap = er32(STRAP);
  1616. u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
  1617. E1000_STRAP_SMT_FREQ_SHIFT;
  1618. s32 ret_val;
  1619. strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
  1620. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
  1621. if (ret_val)
  1622. return ret_val;
  1623. phy_data &= ~HV_SMB_ADDR_MASK;
  1624. phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
  1625. phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
  1626. if (hw->phy.type == e1000_phy_i217) {
  1627. /* Restore SMBus frequency */
  1628. if (freq--) {
  1629. phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
  1630. phy_data |= (freq & (1 << 0)) <<
  1631. HV_SMB_ADDR_FREQ_LOW_SHIFT;
  1632. phy_data |= (freq & (1 << 1)) <<
  1633. (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
  1634. } else {
  1635. e_dbg("Unsupported SMB frequency in PHY\n");
  1636. }
  1637. }
  1638. return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
  1639. }
  1640. /**
  1641. * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
  1642. * @hw: pointer to the HW structure
  1643. *
  1644. * SW should configure the LCD from the NVM extended configuration region
  1645. * as a workaround for certain parts.
  1646. **/
  1647. static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
  1648. {
  1649. struct e1000_phy_info *phy = &hw->phy;
  1650. u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
  1651. s32 ret_val = 0;
  1652. u16 word_addr, reg_data, reg_addr, phy_page = 0;
  1653. /* Initialize the PHY from the NVM on ICH platforms. This
  1654. * is needed due to an issue where the NVM configuration is
  1655. * not properly autoloaded after power transitions.
  1656. * Therefore, after each PHY reset, we will load the
  1657. * configuration data out of the NVM manually.
  1658. */
  1659. switch (hw->mac.type) {
  1660. case e1000_ich8lan:
  1661. if (phy->type != e1000_phy_igp_3)
  1662. return ret_val;
  1663. if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
  1664. (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
  1665. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
  1666. break;
  1667. }
  1668. /* Fall-thru */
  1669. case e1000_pchlan:
  1670. case e1000_pch2lan:
  1671. case e1000_pch_lpt:
  1672. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
  1673. break;
  1674. default:
  1675. return ret_val;
  1676. }
  1677. ret_val = hw->phy.ops.acquire(hw);
  1678. if (ret_val)
  1679. return ret_val;
  1680. data = er32(FEXTNVM);
  1681. if (!(data & sw_cfg_mask))
  1682. goto release;
  1683. /* Make sure HW does not configure LCD from PHY
  1684. * extended configuration before SW configuration
  1685. */
  1686. data = er32(EXTCNF_CTRL);
  1687. if ((hw->mac.type < e1000_pch2lan) &&
  1688. (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
  1689. goto release;
  1690. cnf_size = er32(EXTCNF_SIZE);
  1691. cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
  1692. cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
  1693. if (!cnf_size)
  1694. goto release;
  1695. cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
  1696. cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
  1697. if (((hw->mac.type == e1000_pchlan) &&
  1698. !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
  1699. (hw->mac.type > e1000_pchlan)) {
  1700. /* HW configures the SMBus address and LEDs when the
  1701. * OEM and LCD Write Enable bits are set in the NVM.
  1702. * When both NVM bits are cleared, SW will configure
  1703. * them instead.
  1704. */
  1705. ret_val = e1000_write_smbus_addr(hw);
  1706. if (ret_val)
  1707. goto release;
  1708. data = er32(LEDCTL);
  1709. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
  1710. (u16)data);
  1711. if (ret_val)
  1712. goto release;
  1713. }
  1714. /* Configure LCD from extended configuration region. */
  1715. /* cnf_base_addr is in DWORD */
  1716. word_addr = (u16)(cnf_base_addr << 1);
  1717. for (i = 0; i < cnf_size; i++) {
  1718. ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
  1719. if (ret_val)
  1720. goto release;
  1721. ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
  1722. 1, &reg_addr);
  1723. if (ret_val)
  1724. goto release;
  1725. /* Save off the PHY page for future writes. */
  1726. if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
  1727. phy_page = reg_data;
  1728. continue;
  1729. }
  1730. reg_addr &= PHY_REG_MASK;
  1731. reg_addr |= phy_page;
  1732. ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
  1733. if (ret_val)
  1734. goto release;
  1735. }
  1736. release:
  1737. hw->phy.ops.release(hw);
  1738. return ret_val;
  1739. }
  1740. /**
  1741. * e1000_k1_gig_workaround_hv - K1 Si workaround
  1742. * @hw: pointer to the HW structure
  1743. * @link: link up bool flag
  1744. *
  1745. * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
  1746. * from a lower speed. This workaround disables K1 whenever link is at 1Gig
  1747. * If link is down, the function will restore the default K1 setting located
  1748. * in the NVM.
  1749. **/
  1750. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
  1751. {
  1752. s32 ret_val = 0;
  1753. u16 status_reg = 0;
  1754. bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
  1755. if (hw->mac.type != e1000_pchlan)
  1756. return 0;
  1757. /* Wrap the whole flow with the sw flag */
  1758. ret_val = hw->phy.ops.acquire(hw);
  1759. if (ret_val)
  1760. return ret_val;
  1761. /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
  1762. if (link) {
  1763. if (hw->phy.type == e1000_phy_82578) {
  1764. ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
  1765. &status_reg);
  1766. if (ret_val)
  1767. goto release;
  1768. status_reg &= (BM_CS_STATUS_LINK_UP |
  1769. BM_CS_STATUS_RESOLVED |
  1770. BM_CS_STATUS_SPEED_MASK);
  1771. if (status_reg == (BM_CS_STATUS_LINK_UP |
  1772. BM_CS_STATUS_RESOLVED |
  1773. BM_CS_STATUS_SPEED_1000))
  1774. k1_enable = false;
  1775. }
  1776. if (hw->phy.type == e1000_phy_82577) {
  1777. ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
  1778. if (ret_val)
  1779. goto release;
  1780. status_reg &= (HV_M_STATUS_LINK_UP |
  1781. HV_M_STATUS_AUTONEG_COMPLETE |
  1782. HV_M_STATUS_SPEED_MASK);
  1783. if (status_reg == (HV_M_STATUS_LINK_UP |
  1784. HV_M_STATUS_AUTONEG_COMPLETE |
  1785. HV_M_STATUS_SPEED_1000))
  1786. k1_enable = false;
  1787. }
  1788. /* Link stall fix for link up */
  1789. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
  1790. if (ret_val)
  1791. goto release;
  1792. } else {
  1793. /* Link stall fix for link down */
  1794. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
  1795. if (ret_val)
  1796. goto release;
  1797. }
  1798. ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
  1799. release:
  1800. hw->phy.ops.release(hw);
  1801. return ret_val;
  1802. }
  1803. /**
  1804. * e1000_configure_k1_ich8lan - Configure K1 power state
  1805. * @hw: pointer to the HW structure
  1806. * @enable: K1 state to configure
  1807. *
  1808. * Configure the K1 power state based on the provided parameter.
  1809. * Assumes semaphore already acquired.
  1810. *
  1811. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1812. **/
  1813. s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
  1814. {
  1815. s32 ret_val;
  1816. u32 ctrl_reg = 0;
  1817. u32 ctrl_ext = 0;
  1818. u32 reg = 0;
  1819. u16 kmrn_reg = 0;
  1820. ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1821. &kmrn_reg);
  1822. if (ret_val)
  1823. return ret_val;
  1824. if (k1_enable)
  1825. kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
  1826. else
  1827. kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
  1828. ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1829. kmrn_reg);
  1830. if (ret_val)
  1831. return ret_val;
  1832. usleep_range(20, 40);
  1833. ctrl_ext = er32(CTRL_EXT);
  1834. ctrl_reg = er32(CTRL);
  1835. reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1836. reg |= E1000_CTRL_FRCSPD;
  1837. ew32(CTRL, reg);
  1838. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
  1839. e1e_flush();
  1840. usleep_range(20, 40);
  1841. ew32(CTRL, ctrl_reg);
  1842. ew32(CTRL_EXT, ctrl_ext);
  1843. e1e_flush();
  1844. usleep_range(20, 40);
  1845. return 0;
  1846. }
  1847. /**
  1848. * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
  1849. * @hw: pointer to the HW structure
  1850. * @d0_state: boolean if entering d0 or d3 device state
  1851. *
  1852. * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
  1853. * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
  1854. * in NVM determines whether HW should configure LPLU and Gbe Disable.
  1855. **/
  1856. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
  1857. {
  1858. s32 ret_val = 0;
  1859. u32 mac_reg;
  1860. u16 oem_reg;
  1861. if (hw->mac.type < e1000_pchlan)
  1862. return ret_val;
  1863. ret_val = hw->phy.ops.acquire(hw);
  1864. if (ret_val)
  1865. return ret_val;
  1866. if (hw->mac.type == e1000_pchlan) {
  1867. mac_reg = er32(EXTCNF_CTRL);
  1868. if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
  1869. goto release;
  1870. }
  1871. mac_reg = er32(FEXTNVM);
  1872. if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
  1873. goto release;
  1874. mac_reg = er32(PHY_CTRL);
  1875. ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
  1876. if (ret_val)
  1877. goto release;
  1878. oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
  1879. if (d0_state) {
  1880. if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
  1881. oem_reg |= HV_OEM_BITS_GBE_DIS;
  1882. if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
  1883. oem_reg |= HV_OEM_BITS_LPLU;
  1884. } else {
  1885. if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
  1886. E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
  1887. oem_reg |= HV_OEM_BITS_GBE_DIS;
  1888. if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
  1889. E1000_PHY_CTRL_NOND0A_LPLU))
  1890. oem_reg |= HV_OEM_BITS_LPLU;
  1891. }
  1892. /* Set Restart auto-neg to activate the bits */
  1893. if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
  1894. !hw->phy.ops.check_reset_block(hw))
  1895. oem_reg |= HV_OEM_BITS_RESTART_AN;
  1896. ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
  1897. release:
  1898. hw->phy.ops.release(hw);
  1899. return ret_val;
  1900. }
  1901. /**
  1902. * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
  1903. * @hw: pointer to the HW structure
  1904. **/
  1905. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
  1906. {
  1907. s32 ret_val;
  1908. u16 data;
  1909. ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
  1910. if (ret_val)
  1911. return ret_val;
  1912. data |= HV_KMRN_MDIO_SLOW;
  1913. ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
  1914. return ret_val;
  1915. }
  1916. /**
  1917. * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  1918. * done after every PHY reset.
  1919. **/
  1920. static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  1921. {
  1922. s32 ret_val = 0;
  1923. u16 phy_data;
  1924. if (hw->mac.type != e1000_pchlan)
  1925. return 0;
  1926. /* Set MDIO slow mode before any other MDIO access */
  1927. if (hw->phy.type == e1000_phy_82577) {
  1928. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  1929. if (ret_val)
  1930. return ret_val;
  1931. }
  1932. if (((hw->phy.type == e1000_phy_82577) &&
  1933. ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
  1934. ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
  1935. /* Disable generation of early preamble */
  1936. ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
  1937. if (ret_val)
  1938. return ret_val;
  1939. /* Preamble tuning for SSC */
  1940. ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
  1941. if (ret_val)
  1942. return ret_val;
  1943. }
  1944. if (hw->phy.type == e1000_phy_82578) {
  1945. /* Return registers to default by doing a soft reset then
  1946. * writing 0x3140 to the control register.
  1947. */
  1948. if (hw->phy.revision < 2) {
  1949. e1000e_phy_sw_reset(hw);
  1950. ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
  1951. }
  1952. }
  1953. /* Select page 0 */
  1954. ret_val = hw->phy.ops.acquire(hw);
  1955. if (ret_val)
  1956. return ret_val;
  1957. hw->phy.addr = 1;
  1958. ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
  1959. hw->phy.ops.release(hw);
  1960. if (ret_val)
  1961. return ret_val;
  1962. /* Configure the K1 Si workaround during phy reset assuming there is
  1963. * link so that it disables K1 if link is in 1Gbps.
  1964. */
  1965. ret_val = e1000_k1_gig_workaround_hv(hw, true);
  1966. if (ret_val)
  1967. return ret_val;
  1968. /* Workaround for link disconnects on a busy hub in half duplex */
  1969. ret_val = hw->phy.ops.acquire(hw);
  1970. if (ret_val)
  1971. return ret_val;
  1972. ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
  1973. if (ret_val)
  1974. goto release;
  1975. ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
  1976. if (ret_val)
  1977. goto release;
  1978. /* set MSE higher to enable link to stay up when noise is high */
  1979. ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
  1980. release:
  1981. hw->phy.ops.release(hw);
  1982. return ret_val;
  1983. }
  1984. /**
  1985. * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
  1986. * @hw: pointer to the HW structure
  1987. **/
  1988. void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
  1989. {
  1990. u32 mac_reg;
  1991. u16 i, phy_reg = 0;
  1992. s32 ret_val;
  1993. ret_val = hw->phy.ops.acquire(hw);
  1994. if (ret_val)
  1995. return;
  1996. ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  1997. if (ret_val)
  1998. goto release;
  1999. /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
  2000. for (i = 0; i < (hw->mac.rar_entry_count); i++) {
  2001. mac_reg = er32(RAL(i));
  2002. hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
  2003. (u16)(mac_reg & 0xFFFF));
  2004. hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
  2005. (u16)((mac_reg >> 16) & 0xFFFF));
  2006. mac_reg = er32(RAH(i));
  2007. hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
  2008. (u16)(mac_reg & 0xFFFF));
  2009. hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
  2010. (u16)((mac_reg & E1000_RAH_AV)
  2011. >> 16));
  2012. }
  2013. e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2014. release:
  2015. hw->phy.ops.release(hw);
  2016. }
  2017. /**
  2018. * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
  2019. * with 82579 PHY
  2020. * @hw: pointer to the HW structure
  2021. * @enable: flag to enable/disable workaround when enabling/disabling jumbos
  2022. **/
  2023. s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
  2024. {
  2025. s32 ret_val = 0;
  2026. u16 phy_reg, data;
  2027. u32 mac_reg;
  2028. u16 i;
  2029. if (hw->mac.type < e1000_pch2lan)
  2030. return 0;
  2031. /* disable Rx path while enabling/disabling workaround */
  2032. e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
  2033. ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
  2034. if (ret_val)
  2035. return ret_val;
  2036. if (enable) {
  2037. /* Write Rx addresses (rar_entry_count for RAL/H, and
  2038. * SHRAL/H) and initial CRC values to the MAC
  2039. */
  2040. for (i = 0; i < hw->mac.rar_entry_count; i++) {
  2041. u8 mac_addr[ETH_ALEN] = { 0 };
  2042. u32 addr_high, addr_low;
  2043. addr_high = er32(RAH(i));
  2044. if (!(addr_high & E1000_RAH_AV))
  2045. continue;
  2046. addr_low = er32(RAL(i));
  2047. mac_addr[0] = (addr_low & 0xFF);
  2048. mac_addr[1] = ((addr_low >> 8) & 0xFF);
  2049. mac_addr[2] = ((addr_low >> 16) & 0xFF);
  2050. mac_addr[3] = ((addr_low >> 24) & 0xFF);
  2051. mac_addr[4] = (addr_high & 0xFF);
  2052. mac_addr[5] = ((addr_high >> 8) & 0xFF);
  2053. ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
  2054. }
  2055. /* Write Rx addresses to the PHY */
  2056. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  2057. /* Enable jumbo frame workaround in the MAC */
  2058. mac_reg = er32(FFLT_DBG);
  2059. mac_reg &= ~(1 << 14);
  2060. mac_reg |= (7 << 15);
  2061. ew32(FFLT_DBG, mac_reg);
  2062. mac_reg = er32(RCTL);
  2063. mac_reg |= E1000_RCTL_SECRC;
  2064. ew32(RCTL, mac_reg);
  2065. ret_val = e1000e_read_kmrn_reg(hw,
  2066. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2067. &data);
  2068. if (ret_val)
  2069. return ret_val;
  2070. ret_val = e1000e_write_kmrn_reg(hw,
  2071. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2072. data | (1 << 0));
  2073. if (ret_val)
  2074. return ret_val;
  2075. ret_val = e1000e_read_kmrn_reg(hw,
  2076. E1000_KMRNCTRLSTA_HD_CTRL,
  2077. &data);
  2078. if (ret_val)
  2079. return ret_val;
  2080. data &= ~(0xF << 8);
  2081. data |= (0xB << 8);
  2082. ret_val = e1000e_write_kmrn_reg(hw,
  2083. E1000_KMRNCTRLSTA_HD_CTRL,
  2084. data);
  2085. if (ret_val)
  2086. return ret_val;
  2087. /* Enable jumbo frame workaround in the PHY */
  2088. e1e_rphy(hw, PHY_REG(769, 23), &data);
  2089. data &= ~(0x7F << 5);
  2090. data |= (0x37 << 5);
  2091. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  2092. if (ret_val)
  2093. return ret_val;
  2094. e1e_rphy(hw, PHY_REG(769, 16), &data);
  2095. data &= ~(1 << 13);
  2096. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  2097. if (ret_val)
  2098. return ret_val;
  2099. e1e_rphy(hw, PHY_REG(776, 20), &data);
  2100. data &= ~(0x3FF << 2);
  2101. data |= (0x1A << 2);
  2102. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  2103. if (ret_val)
  2104. return ret_val;
  2105. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
  2106. if (ret_val)
  2107. return ret_val;
  2108. e1e_rphy(hw, HV_PM_CTRL, &data);
  2109. ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
  2110. if (ret_val)
  2111. return ret_val;
  2112. } else {
  2113. /* Write MAC register values back to h/w defaults */
  2114. mac_reg = er32(FFLT_DBG);
  2115. mac_reg &= ~(0xF << 14);
  2116. ew32(FFLT_DBG, mac_reg);
  2117. mac_reg = er32(RCTL);
  2118. mac_reg &= ~E1000_RCTL_SECRC;
  2119. ew32(RCTL, mac_reg);
  2120. ret_val = e1000e_read_kmrn_reg(hw,
  2121. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2122. &data);
  2123. if (ret_val)
  2124. return ret_val;
  2125. ret_val = e1000e_write_kmrn_reg(hw,
  2126. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2127. data & ~(1 << 0));
  2128. if (ret_val)
  2129. return ret_val;
  2130. ret_val = e1000e_read_kmrn_reg(hw,
  2131. E1000_KMRNCTRLSTA_HD_CTRL,
  2132. &data);
  2133. if (ret_val)
  2134. return ret_val;
  2135. data &= ~(0xF << 8);
  2136. data |= (0xB << 8);
  2137. ret_val = e1000e_write_kmrn_reg(hw,
  2138. E1000_KMRNCTRLSTA_HD_CTRL,
  2139. data);
  2140. if (ret_val)
  2141. return ret_val;
  2142. /* Write PHY register values back to h/w defaults */
  2143. e1e_rphy(hw, PHY_REG(769, 23), &data);
  2144. data &= ~(0x7F << 5);
  2145. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  2146. if (ret_val)
  2147. return ret_val;
  2148. e1e_rphy(hw, PHY_REG(769, 16), &data);
  2149. data |= (1 << 13);
  2150. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  2151. if (ret_val)
  2152. return ret_val;
  2153. e1e_rphy(hw, PHY_REG(776, 20), &data);
  2154. data &= ~(0x3FF << 2);
  2155. data |= (0x8 << 2);
  2156. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  2157. if (ret_val)
  2158. return ret_val;
  2159. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
  2160. if (ret_val)
  2161. return ret_val;
  2162. e1e_rphy(hw, HV_PM_CTRL, &data);
  2163. ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
  2164. if (ret_val)
  2165. return ret_val;
  2166. }
  2167. /* re-enable Rx path after enabling/disabling workaround */
  2168. return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
  2169. }
  2170. /**
  2171. * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  2172. * done after every PHY reset.
  2173. **/
  2174. static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  2175. {
  2176. s32 ret_val = 0;
  2177. if (hw->mac.type != e1000_pch2lan)
  2178. return 0;
  2179. /* Set MDIO slow mode before any other MDIO access */
  2180. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  2181. if (ret_val)
  2182. return ret_val;
  2183. ret_val = hw->phy.ops.acquire(hw);
  2184. if (ret_val)
  2185. return ret_val;
  2186. /* set MSE higher to enable link to stay up when noise is high */
  2187. ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
  2188. if (ret_val)
  2189. goto release;
  2190. /* drop link after 5 times MSE threshold was reached */
  2191. ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
  2192. release:
  2193. hw->phy.ops.release(hw);
  2194. return ret_val;
  2195. }
  2196. /**
  2197. * e1000_k1_gig_workaround_lv - K1 Si workaround
  2198. * @hw: pointer to the HW structure
  2199. *
  2200. * Workaround to set the K1 beacon duration for 82579 parts in 10Mbps
  2201. * Disable K1 in 1000Mbps and 100Mbps
  2202. **/
  2203. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
  2204. {
  2205. s32 ret_val = 0;
  2206. u16 status_reg = 0;
  2207. if (hw->mac.type != e1000_pch2lan)
  2208. return 0;
  2209. /* Set K1 beacon duration based on 10Mbs speed */
  2210. ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
  2211. if (ret_val)
  2212. return ret_val;
  2213. if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
  2214. == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
  2215. if (status_reg &
  2216. (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
  2217. u16 pm_phy_reg;
  2218. /* LV 1G/100 Packet drop issue wa */
  2219. ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
  2220. if (ret_val)
  2221. return ret_val;
  2222. pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
  2223. ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
  2224. if (ret_val)
  2225. return ret_val;
  2226. } else {
  2227. u32 mac_reg;
  2228. mac_reg = er32(FEXTNVM4);
  2229. mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
  2230. mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
  2231. ew32(FEXTNVM4, mac_reg);
  2232. }
  2233. }
  2234. return ret_val;
  2235. }
  2236. /**
  2237. * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
  2238. * @hw: pointer to the HW structure
  2239. * @gate: boolean set to true to gate, false to ungate
  2240. *
  2241. * Gate/ungate the automatic PHY configuration via hardware; perform
  2242. * the configuration via software instead.
  2243. **/
  2244. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
  2245. {
  2246. u32 extcnf_ctrl;
  2247. if (hw->mac.type < e1000_pch2lan)
  2248. return;
  2249. extcnf_ctrl = er32(EXTCNF_CTRL);
  2250. if (gate)
  2251. extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  2252. else
  2253. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  2254. ew32(EXTCNF_CTRL, extcnf_ctrl);
  2255. }
  2256. /**
  2257. * e1000_lan_init_done_ich8lan - Check for PHY config completion
  2258. * @hw: pointer to the HW structure
  2259. *
  2260. * Check the appropriate indication the MAC has finished configuring the
  2261. * PHY after a software reset.
  2262. **/
  2263. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
  2264. {
  2265. u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
  2266. /* Wait for basic configuration completes before proceeding */
  2267. do {
  2268. data = er32(STATUS);
  2269. data &= E1000_STATUS_LAN_INIT_DONE;
  2270. usleep_range(100, 200);
  2271. } while ((!data) && --loop);
  2272. /* If basic configuration is incomplete before the above loop
  2273. * count reaches 0, loading the configuration from NVM will
  2274. * leave the PHY in a bad state possibly resulting in no link.
  2275. */
  2276. if (loop == 0)
  2277. e_dbg("LAN_INIT_DONE not set, increase timeout\n");
  2278. /* Clear the Init Done bit for the next init event */
  2279. data = er32(STATUS);
  2280. data &= ~E1000_STATUS_LAN_INIT_DONE;
  2281. ew32(STATUS, data);
  2282. }
  2283. /**
  2284. * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
  2285. * @hw: pointer to the HW structure
  2286. **/
  2287. static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
  2288. {
  2289. s32 ret_val = 0;
  2290. u16 reg;
  2291. if (hw->phy.ops.check_reset_block(hw))
  2292. return 0;
  2293. /* Allow time for h/w to get to quiescent state after reset */
  2294. usleep_range(10000, 20000);
  2295. /* Perform any necessary post-reset workarounds */
  2296. switch (hw->mac.type) {
  2297. case e1000_pchlan:
  2298. ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
  2299. if (ret_val)
  2300. return ret_val;
  2301. break;
  2302. case e1000_pch2lan:
  2303. ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
  2304. if (ret_val)
  2305. return ret_val;
  2306. break;
  2307. default:
  2308. break;
  2309. }
  2310. /* Clear the host wakeup bit after lcd reset */
  2311. if (hw->mac.type >= e1000_pchlan) {
  2312. e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
  2313. reg &= ~BM_WUC_HOST_WU_BIT;
  2314. e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
  2315. }
  2316. /* Configure the LCD with the extended configuration region in NVM */
  2317. ret_val = e1000_sw_lcd_config_ich8lan(hw);
  2318. if (ret_val)
  2319. return ret_val;
  2320. /* Configure the LCD with the OEM bits in NVM */
  2321. ret_val = e1000_oem_bits_config_ich8lan(hw, true);
  2322. if (hw->mac.type == e1000_pch2lan) {
  2323. /* Ungate automatic PHY configuration on non-managed 82579 */
  2324. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  2325. usleep_range(10000, 20000);
  2326. e1000_gate_hw_phy_config_ich8lan(hw, false);
  2327. }
  2328. /* Set EEE LPI Update Timer to 200usec */
  2329. ret_val = hw->phy.ops.acquire(hw);
  2330. if (ret_val)
  2331. return ret_val;
  2332. ret_val = e1000_write_emi_reg_locked(hw,
  2333. I82579_LPI_UPDATE_TIMER,
  2334. 0x1387);
  2335. hw->phy.ops.release(hw);
  2336. }
  2337. return ret_val;
  2338. }
  2339. /**
  2340. * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
  2341. * @hw: pointer to the HW structure
  2342. *
  2343. * Resets the PHY
  2344. * This is a function pointer entry point called by drivers
  2345. * or other shared routines.
  2346. **/
  2347. static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
  2348. {
  2349. s32 ret_val = 0;
  2350. /* Gate automatic PHY configuration by hardware on non-managed 82579 */
  2351. if ((hw->mac.type == e1000_pch2lan) &&
  2352. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  2353. e1000_gate_hw_phy_config_ich8lan(hw, true);
  2354. ret_val = e1000e_phy_hw_reset_generic(hw);
  2355. if (ret_val)
  2356. return ret_val;
  2357. return e1000_post_phy_reset_ich8lan(hw);
  2358. }
  2359. /**
  2360. * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
  2361. * @hw: pointer to the HW structure
  2362. * @active: true to enable LPLU, false to disable
  2363. *
  2364. * Sets the LPLU state according to the active flag. For PCH, if OEM write
  2365. * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
  2366. * the phy speed. This function will manually set the LPLU bit and restart
  2367. * auto-neg as hw would do. D3 and D0 LPLU will call the same function
  2368. * since it configures the same bit.
  2369. **/
  2370. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
  2371. {
  2372. s32 ret_val;
  2373. u16 oem_reg;
  2374. ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
  2375. if (ret_val)
  2376. return ret_val;
  2377. if (active)
  2378. oem_reg |= HV_OEM_BITS_LPLU;
  2379. else
  2380. oem_reg &= ~HV_OEM_BITS_LPLU;
  2381. if (!hw->phy.ops.check_reset_block(hw))
  2382. oem_reg |= HV_OEM_BITS_RESTART_AN;
  2383. return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
  2384. }
  2385. /**
  2386. * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
  2387. * @hw: pointer to the HW structure
  2388. * @active: true to enable LPLU, false to disable
  2389. *
  2390. * Sets the LPLU D0 state according to the active flag. When
  2391. * activating LPLU this function also disables smart speed
  2392. * and vice versa. LPLU will not be activated unless the
  2393. * device autonegotiation advertisement meets standards of
  2394. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  2395. * This is a function pointer entry point only called by
  2396. * PHY setup routines.
  2397. **/
  2398. static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  2399. {
  2400. struct e1000_phy_info *phy = &hw->phy;
  2401. u32 phy_ctrl;
  2402. s32 ret_val = 0;
  2403. u16 data;
  2404. if (phy->type == e1000_phy_ife)
  2405. return 0;
  2406. phy_ctrl = er32(PHY_CTRL);
  2407. if (active) {
  2408. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2409. ew32(PHY_CTRL, phy_ctrl);
  2410. if (phy->type != e1000_phy_igp_3)
  2411. return 0;
  2412. /* Call gig speed drop workaround on LPLU before accessing
  2413. * any PHY registers
  2414. */
  2415. if (hw->mac.type == e1000_ich8lan)
  2416. e1000e_gig_downshift_workaround_ich8lan(hw);
  2417. /* When LPLU is enabled, we should disable SmartSpeed */
  2418. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2419. if (ret_val)
  2420. return ret_val;
  2421. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2422. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2423. if (ret_val)
  2424. return ret_val;
  2425. } else {
  2426. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2427. ew32(PHY_CTRL, phy_ctrl);
  2428. if (phy->type != e1000_phy_igp_3)
  2429. return 0;
  2430. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2431. * during Dx states where the power conservation is most
  2432. * important. During driver activity we should enable
  2433. * SmartSpeed, so performance is maintained.
  2434. */
  2435. if (phy->smart_speed == e1000_smart_speed_on) {
  2436. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2437. &data);
  2438. if (ret_val)
  2439. return ret_val;
  2440. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2441. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2442. data);
  2443. if (ret_val)
  2444. return ret_val;
  2445. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2446. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2447. &data);
  2448. if (ret_val)
  2449. return ret_val;
  2450. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2451. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2452. data);
  2453. if (ret_val)
  2454. return ret_val;
  2455. }
  2456. }
  2457. return 0;
  2458. }
  2459. /**
  2460. * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
  2461. * @hw: pointer to the HW structure
  2462. * @active: true to enable LPLU, false to disable
  2463. *
  2464. * Sets the LPLU D3 state according to the active flag. When
  2465. * activating LPLU this function also disables smart speed
  2466. * and vice versa. LPLU will not be activated unless the
  2467. * device autonegotiation advertisement meets standards of
  2468. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  2469. * This is a function pointer entry point only called by
  2470. * PHY setup routines.
  2471. **/
  2472. static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  2473. {
  2474. struct e1000_phy_info *phy = &hw->phy;
  2475. u32 phy_ctrl;
  2476. s32 ret_val = 0;
  2477. u16 data;
  2478. phy_ctrl = er32(PHY_CTRL);
  2479. if (!active) {
  2480. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  2481. ew32(PHY_CTRL, phy_ctrl);
  2482. if (phy->type != e1000_phy_igp_3)
  2483. return 0;
  2484. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2485. * during Dx states where the power conservation is most
  2486. * important. During driver activity we should enable
  2487. * SmartSpeed, so performance is maintained.
  2488. */
  2489. if (phy->smart_speed == e1000_smart_speed_on) {
  2490. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2491. &data);
  2492. if (ret_val)
  2493. return ret_val;
  2494. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2495. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2496. data);
  2497. if (ret_val)
  2498. return ret_val;
  2499. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2500. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2501. &data);
  2502. if (ret_val)
  2503. return ret_val;
  2504. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2505. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2506. data);
  2507. if (ret_val)
  2508. return ret_val;
  2509. }
  2510. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  2511. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  2512. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  2513. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  2514. ew32(PHY_CTRL, phy_ctrl);
  2515. if (phy->type != e1000_phy_igp_3)
  2516. return 0;
  2517. /* Call gig speed drop workaround on LPLU before accessing
  2518. * any PHY registers
  2519. */
  2520. if (hw->mac.type == e1000_ich8lan)
  2521. e1000e_gig_downshift_workaround_ich8lan(hw);
  2522. /* When LPLU is enabled, we should disable SmartSpeed */
  2523. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2524. if (ret_val)
  2525. return ret_val;
  2526. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2527. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2528. }
  2529. return ret_val;
  2530. }
  2531. /**
  2532. * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
  2533. * @hw: pointer to the HW structure
  2534. * @bank: pointer to the variable that returns the active bank
  2535. *
  2536. * Reads signature byte from the NVM using the flash access registers.
  2537. * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
  2538. **/
  2539. static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
  2540. {
  2541. u32 eecd;
  2542. struct e1000_nvm_info *nvm = &hw->nvm;
  2543. u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
  2544. u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
  2545. u8 sig_byte = 0;
  2546. s32 ret_val;
  2547. switch (hw->mac.type) {
  2548. case e1000_ich8lan:
  2549. case e1000_ich9lan:
  2550. eecd = er32(EECD);
  2551. if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
  2552. E1000_EECD_SEC1VAL_VALID_MASK) {
  2553. if (eecd & E1000_EECD_SEC1VAL)
  2554. *bank = 1;
  2555. else
  2556. *bank = 0;
  2557. return 0;
  2558. }
  2559. e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
  2560. /* fall-thru */
  2561. default:
  2562. /* set bank to 0 in case flash read fails */
  2563. *bank = 0;
  2564. /* Check bank 0 */
  2565. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
  2566. &sig_byte);
  2567. if (ret_val)
  2568. return ret_val;
  2569. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2570. E1000_ICH_NVM_SIG_VALUE) {
  2571. *bank = 0;
  2572. return 0;
  2573. }
  2574. /* Check bank 1 */
  2575. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
  2576. bank1_offset,
  2577. &sig_byte);
  2578. if (ret_val)
  2579. return ret_val;
  2580. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2581. E1000_ICH_NVM_SIG_VALUE) {
  2582. *bank = 1;
  2583. return 0;
  2584. }
  2585. e_dbg("ERROR: No valid NVM bank present\n");
  2586. return -E1000_ERR_NVM;
  2587. }
  2588. }
  2589. /**
  2590. * e1000_read_nvm_ich8lan - Read word(s) from the NVM
  2591. * @hw: pointer to the HW structure
  2592. * @offset: The offset (in bytes) of the word(s) to read.
  2593. * @words: Size of data to read in words
  2594. * @data: Pointer to the word(s) to read at offset.
  2595. *
  2596. * Reads a word(s) from the NVM using the flash access registers.
  2597. **/
  2598. static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  2599. u16 *data)
  2600. {
  2601. struct e1000_nvm_info *nvm = &hw->nvm;
  2602. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2603. u32 act_offset;
  2604. s32 ret_val = 0;
  2605. u32 bank = 0;
  2606. u16 i, word;
  2607. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2608. (words == 0)) {
  2609. e_dbg("nvm parameter(s) out of bounds\n");
  2610. ret_val = -E1000_ERR_NVM;
  2611. goto out;
  2612. }
  2613. nvm->ops.acquire(hw);
  2614. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2615. if (ret_val) {
  2616. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2617. bank = 0;
  2618. }
  2619. act_offset = (bank) ? nvm->flash_bank_size : 0;
  2620. act_offset += offset;
  2621. ret_val = 0;
  2622. for (i = 0; i < words; i++) {
  2623. if (dev_spec->shadow_ram[offset + i].modified) {
  2624. data[i] = dev_spec->shadow_ram[offset + i].value;
  2625. } else {
  2626. ret_val = e1000_read_flash_word_ich8lan(hw,
  2627. act_offset + i,
  2628. &word);
  2629. if (ret_val)
  2630. break;
  2631. data[i] = word;
  2632. }
  2633. }
  2634. nvm->ops.release(hw);
  2635. out:
  2636. if (ret_val)
  2637. e_dbg("NVM read error: %d\n", ret_val);
  2638. return ret_val;
  2639. }
  2640. /**
  2641. * e1000_flash_cycle_init_ich8lan - Initialize flash
  2642. * @hw: pointer to the HW structure
  2643. *
  2644. * This function does initial flash setup so that a new read/write/erase cycle
  2645. * can be started.
  2646. **/
  2647. static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
  2648. {
  2649. union ich8_hws_flash_status hsfsts;
  2650. s32 ret_val = -E1000_ERR_NVM;
  2651. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2652. /* Check if the flash descriptor is valid */
  2653. if (!hsfsts.hsf_status.fldesvalid) {
  2654. e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
  2655. return -E1000_ERR_NVM;
  2656. }
  2657. /* Clear FCERR and DAEL in hw status by writing 1 */
  2658. hsfsts.hsf_status.flcerr = 1;
  2659. hsfsts.hsf_status.dael = 1;
  2660. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2661. /* Either we should have a hardware SPI cycle in progress
  2662. * bit to check against, in order to start a new cycle or
  2663. * FDONE bit should be changed in the hardware so that it
  2664. * is 1 after hardware reset, which can then be used as an
  2665. * indication whether a cycle is in progress or has been
  2666. * completed.
  2667. */
  2668. if (!hsfsts.hsf_status.flcinprog) {
  2669. /* There is no cycle running at present,
  2670. * so we can start a cycle.
  2671. * Begin by setting Flash Cycle Done.
  2672. */
  2673. hsfsts.hsf_status.flcdone = 1;
  2674. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2675. ret_val = 0;
  2676. } else {
  2677. s32 i;
  2678. /* Otherwise poll for sometime so the current
  2679. * cycle has a chance to end before giving up.
  2680. */
  2681. for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
  2682. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2683. if (!hsfsts.hsf_status.flcinprog) {
  2684. ret_val = 0;
  2685. break;
  2686. }
  2687. udelay(1);
  2688. }
  2689. if (!ret_val) {
  2690. /* Successful in waiting for previous cycle to timeout,
  2691. * now set the Flash Cycle Done.
  2692. */
  2693. hsfsts.hsf_status.flcdone = 1;
  2694. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2695. } else {
  2696. e_dbg("Flash controller busy, cannot get access\n");
  2697. }
  2698. }
  2699. return ret_val;
  2700. }
  2701. /**
  2702. * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
  2703. * @hw: pointer to the HW structure
  2704. * @timeout: maximum time to wait for completion
  2705. *
  2706. * This function starts a flash cycle and waits for its completion.
  2707. **/
  2708. static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
  2709. {
  2710. union ich8_hws_flash_ctrl hsflctl;
  2711. union ich8_hws_flash_status hsfsts;
  2712. u32 i = 0;
  2713. /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
  2714. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2715. hsflctl.hsf_ctrl.flcgo = 1;
  2716. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2717. /* wait till FDONE bit is set to 1 */
  2718. do {
  2719. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2720. if (hsfsts.hsf_status.flcdone)
  2721. break;
  2722. udelay(1);
  2723. } while (i++ < timeout);
  2724. if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
  2725. return 0;
  2726. return -E1000_ERR_NVM;
  2727. }
  2728. /**
  2729. * e1000_read_flash_word_ich8lan - Read word from flash
  2730. * @hw: pointer to the HW structure
  2731. * @offset: offset to data location
  2732. * @data: pointer to the location for storing the data
  2733. *
  2734. * Reads the flash word at offset into data. Offset is converted
  2735. * to bytes before read.
  2736. **/
  2737. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  2738. u16 *data)
  2739. {
  2740. /* Must convert offset into bytes. */
  2741. offset <<= 1;
  2742. return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
  2743. }
  2744. /**
  2745. * e1000_read_flash_byte_ich8lan - Read byte from flash
  2746. * @hw: pointer to the HW structure
  2747. * @offset: The offset of the byte to read.
  2748. * @data: Pointer to a byte to store the value read.
  2749. *
  2750. * Reads a single byte from the NVM using the flash access registers.
  2751. **/
  2752. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  2753. u8 *data)
  2754. {
  2755. s32 ret_val;
  2756. u16 word = 0;
  2757. ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
  2758. if (ret_val)
  2759. return ret_val;
  2760. *data = (u8)word;
  2761. return 0;
  2762. }
  2763. /**
  2764. * e1000_read_flash_data_ich8lan - Read byte or word from NVM
  2765. * @hw: pointer to the HW structure
  2766. * @offset: The offset (in bytes) of the byte or word to read.
  2767. * @size: Size of data to read, 1=byte 2=word
  2768. * @data: Pointer to the word to store the value read.
  2769. *
  2770. * Reads a byte or word from the NVM using the flash access registers.
  2771. **/
  2772. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  2773. u8 size, u16 *data)
  2774. {
  2775. union ich8_hws_flash_status hsfsts;
  2776. union ich8_hws_flash_ctrl hsflctl;
  2777. u32 flash_linear_addr;
  2778. u32 flash_data = 0;
  2779. s32 ret_val = -E1000_ERR_NVM;
  2780. u8 count = 0;
  2781. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  2782. return -E1000_ERR_NVM;
  2783. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  2784. hw->nvm.flash_base_addr);
  2785. do {
  2786. udelay(1);
  2787. /* Steps */
  2788. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  2789. if (ret_val)
  2790. break;
  2791. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2792. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  2793. hsflctl.hsf_ctrl.fldbcount = size - 1;
  2794. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  2795. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2796. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  2797. ret_val =
  2798. e1000_flash_cycle_ich8lan(hw,
  2799. ICH_FLASH_READ_COMMAND_TIMEOUT);
  2800. /* Check if FCERR is set to 1, if set to 1, clear it
  2801. * and try the whole sequence a few more times, else
  2802. * read in (shift in) the Flash Data0, the order is
  2803. * least significant byte first msb to lsb
  2804. */
  2805. if (!ret_val) {
  2806. flash_data = er32flash(ICH_FLASH_FDATA0);
  2807. if (size == 1)
  2808. *data = (u8)(flash_data & 0x000000FF);
  2809. else if (size == 2)
  2810. *data = (u16)(flash_data & 0x0000FFFF);
  2811. break;
  2812. } else {
  2813. /* If we've gotten here, then things are probably
  2814. * completely hosed, but if the error condition is
  2815. * detected, it won't hurt to give it another try...
  2816. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  2817. */
  2818. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2819. if (hsfsts.hsf_status.flcerr) {
  2820. /* Repeat for some time before giving up. */
  2821. continue;
  2822. } else if (!hsfsts.hsf_status.flcdone) {
  2823. e_dbg("Timeout error - flash cycle did not complete.\n");
  2824. break;
  2825. }
  2826. }
  2827. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  2828. return ret_val;
  2829. }
  2830. /**
  2831. * e1000_write_nvm_ich8lan - Write word(s) to the NVM
  2832. * @hw: pointer to the HW structure
  2833. * @offset: The offset (in bytes) of the word(s) to write.
  2834. * @words: Size of data to write in words
  2835. * @data: Pointer to the word(s) to write at offset.
  2836. *
  2837. * Writes a byte or word to the NVM using the flash access registers.
  2838. **/
  2839. static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  2840. u16 *data)
  2841. {
  2842. struct e1000_nvm_info *nvm = &hw->nvm;
  2843. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2844. u16 i;
  2845. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2846. (words == 0)) {
  2847. e_dbg("nvm parameter(s) out of bounds\n");
  2848. return -E1000_ERR_NVM;
  2849. }
  2850. nvm->ops.acquire(hw);
  2851. for (i = 0; i < words; i++) {
  2852. dev_spec->shadow_ram[offset + i].modified = true;
  2853. dev_spec->shadow_ram[offset + i].value = data[i];
  2854. }
  2855. nvm->ops.release(hw);
  2856. return 0;
  2857. }
  2858. /**
  2859. * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
  2860. * @hw: pointer to the HW structure
  2861. *
  2862. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  2863. * which writes the checksum to the shadow ram. The changes in the shadow
  2864. * ram are then committed to the EEPROM by processing each bank at a time
  2865. * checking for the modified bit and writing only the pending changes.
  2866. * After a successful commit, the shadow ram is cleared and is ready for
  2867. * future writes.
  2868. **/
  2869. static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
  2870. {
  2871. struct e1000_nvm_info *nvm = &hw->nvm;
  2872. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2873. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  2874. s32 ret_val;
  2875. u16 data;
  2876. ret_val = e1000e_update_nvm_checksum_generic(hw);
  2877. if (ret_val)
  2878. goto out;
  2879. if (nvm->type != e1000_nvm_flash_sw)
  2880. goto out;
  2881. nvm->ops.acquire(hw);
  2882. /* We're writing to the opposite bank so if we're on bank 1,
  2883. * write to bank 0 etc. We also need to erase the segment that
  2884. * is going to be written
  2885. */
  2886. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2887. if (ret_val) {
  2888. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2889. bank = 0;
  2890. }
  2891. if (bank == 0) {
  2892. new_bank_offset = nvm->flash_bank_size;
  2893. old_bank_offset = 0;
  2894. ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
  2895. if (ret_val)
  2896. goto release;
  2897. } else {
  2898. old_bank_offset = nvm->flash_bank_size;
  2899. new_bank_offset = 0;
  2900. ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
  2901. if (ret_val)
  2902. goto release;
  2903. }
  2904. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  2905. /* Determine whether to write the value stored
  2906. * in the other NVM bank or a modified value stored
  2907. * in the shadow RAM
  2908. */
  2909. if (dev_spec->shadow_ram[i].modified) {
  2910. data = dev_spec->shadow_ram[i].value;
  2911. } else {
  2912. ret_val = e1000_read_flash_word_ich8lan(hw, i +
  2913. old_bank_offset,
  2914. &data);
  2915. if (ret_val)
  2916. break;
  2917. }
  2918. /* If the word is 0x13, then make sure the signature bits
  2919. * (15:14) are 11b until the commit has completed.
  2920. * This will allow us to write 10b which indicates the
  2921. * signature is valid. We want to do this after the write
  2922. * has completed so that we don't mark the segment valid
  2923. * while the write is still in progress
  2924. */
  2925. if (i == E1000_ICH_NVM_SIG_WORD)
  2926. data |= E1000_ICH_NVM_SIG_MASK;
  2927. /* Convert offset to bytes. */
  2928. act_offset = (i + new_bank_offset) << 1;
  2929. usleep_range(100, 200);
  2930. /* Write the bytes to the new bank. */
  2931. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  2932. act_offset,
  2933. (u8)data);
  2934. if (ret_val)
  2935. break;
  2936. usleep_range(100, 200);
  2937. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  2938. act_offset + 1,
  2939. (u8)(data >> 8));
  2940. if (ret_val)
  2941. break;
  2942. }
  2943. /* Don't bother writing the segment valid bits if sector
  2944. * programming failed.
  2945. */
  2946. if (ret_val) {
  2947. /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
  2948. e_dbg("Flash commit failed.\n");
  2949. goto release;
  2950. }
  2951. /* Finally validate the new segment by setting bit 15:14
  2952. * to 10b in word 0x13 , this can be done without an
  2953. * erase as well since these bits are 11 to start with
  2954. * and we need to change bit 14 to 0b
  2955. */
  2956. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  2957. ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
  2958. if (ret_val)
  2959. goto release;
  2960. data &= 0xBFFF;
  2961. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  2962. act_offset * 2 + 1,
  2963. (u8)(data >> 8));
  2964. if (ret_val)
  2965. goto release;
  2966. /* And invalidate the previously valid segment by setting
  2967. * its signature word (0x13) high_byte to 0b. This can be
  2968. * done without an erase because flash erase sets all bits
  2969. * to 1's. We can write 1's to 0's without an erase
  2970. */
  2971. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  2972. ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
  2973. if (ret_val)
  2974. goto release;
  2975. /* Great! Everything worked, we can now clear the cached entries. */
  2976. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  2977. dev_spec->shadow_ram[i].modified = false;
  2978. dev_spec->shadow_ram[i].value = 0xFFFF;
  2979. }
  2980. release:
  2981. nvm->ops.release(hw);
  2982. /* Reload the EEPROM, or else modifications will not appear
  2983. * until after the next adapter reset.
  2984. */
  2985. if (!ret_val) {
  2986. nvm->ops.reload(hw);
  2987. usleep_range(10000, 20000);
  2988. }
  2989. out:
  2990. if (ret_val)
  2991. e_dbg("NVM update error: %d\n", ret_val);
  2992. return ret_val;
  2993. }
  2994. /**
  2995. * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
  2996. * @hw: pointer to the HW structure
  2997. *
  2998. * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
  2999. * If the bit is 0, that the EEPROM had been modified, but the checksum was not
  3000. * calculated, in which case we need to calculate the checksum and set bit 6.
  3001. **/
  3002. static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
  3003. {
  3004. s32 ret_val;
  3005. u16 data;
  3006. u16 word;
  3007. u16 valid_csum_mask;
  3008. /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
  3009. * the checksum needs to be fixed. This bit is an indication that
  3010. * the NVM was prepared by OEM software and did not calculate
  3011. * the checksum...a likely scenario.
  3012. */
  3013. switch (hw->mac.type) {
  3014. case e1000_pch_lpt:
  3015. word = NVM_COMPAT;
  3016. valid_csum_mask = NVM_COMPAT_VALID_CSUM;
  3017. break;
  3018. default:
  3019. word = NVM_FUTURE_INIT_WORD1;
  3020. valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
  3021. break;
  3022. }
  3023. ret_val = e1000_read_nvm(hw, word, 1, &data);
  3024. if (ret_val)
  3025. return ret_val;
  3026. if (!(data & valid_csum_mask)) {
  3027. data |= valid_csum_mask;
  3028. ret_val = e1000_write_nvm(hw, word, 1, &data);
  3029. if (ret_val)
  3030. return ret_val;
  3031. ret_val = e1000e_update_nvm_checksum(hw);
  3032. if (ret_val)
  3033. return ret_val;
  3034. }
  3035. return e1000e_validate_nvm_checksum_generic(hw);
  3036. }
  3037. /**
  3038. * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
  3039. * @hw: pointer to the HW structure
  3040. *
  3041. * To prevent malicious write/erase of the NVM, set it to be read-only
  3042. * so that the hardware ignores all write/erase cycles of the NVM via
  3043. * the flash control registers. The shadow-ram copy of the NVM will
  3044. * still be updated, however any updates to this copy will not stick
  3045. * across driver reloads.
  3046. **/
  3047. void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
  3048. {
  3049. struct e1000_nvm_info *nvm = &hw->nvm;
  3050. union ich8_flash_protected_range pr0;
  3051. union ich8_hws_flash_status hsfsts;
  3052. u32 gfpreg;
  3053. nvm->ops.acquire(hw);
  3054. gfpreg = er32flash(ICH_FLASH_GFPREG);
  3055. /* Write-protect GbE Sector of NVM */
  3056. pr0.regval = er32flash(ICH_FLASH_PR0);
  3057. pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
  3058. pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
  3059. pr0.range.wpe = true;
  3060. ew32flash(ICH_FLASH_PR0, pr0.regval);
  3061. /* Lock down a subset of GbE Flash Control Registers, e.g.
  3062. * PR0 to prevent the write-protection from being lifted.
  3063. * Once FLOCKDN is set, the registers protected by it cannot
  3064. * be written until FLOCKDN is cleared by a hardware reset.
  3065. */
  3066. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3067. hsfsts.hsf_status.flockdn = true;
  3068. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  3069. nvm->ops.release(hw);
  3070. }
  3071. /**
  3072. * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
  3073. * @hw: pointer to the HW structure
  3074. * @offset: The offset (in bytes) of the byte/word to read.
  3075. * @size: Size of data to read, 1=byte 2=word
  3076. * @data: The byte(s) to write to the NVM.
  3077. *
  3078. * Writes one/two bytes to the NVM using the flash access registers.
  3079. **/
  3080. static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  3081. u8 size, u16 data)
  3082. {
  3083. union ich8_hws_flash_status hsfsts;
  3084. union ich8_hws_flash_ctrl hsflctl;
  3085. u32 flash_linear_addr;
  3086. u32 flash_data = 0;
  3087. s32 ret_val;
  3088. u8 count = 0;
  3089. if (size < 1 || size > 2 || data > size * 0xff ||
  3090. offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3091. return -E1000_ERR_NVM;
  3092. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3093. hw->nvm.flash_base_addr);
  3094. do {
  3095. udelay(1);
  3096. /* Steps */
  3097. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3098. if (ret_val)
  3099. break;
  3100. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3101. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  3102. hsflctl.hsf_ctrl.fldbcount = size - 1;
  3103. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  3104. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3105. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3106. if (size == 1)
  3107. flash_data = (u32)data & 0x00FF;
  3108. else
  3109. flash_data = (u32)data;
  3110. ew32flash(ICH_FLASH_FDATA0, flash_data);
  3111. /* check if FCERR is set to 1 , if set to 1, clear it
  3112. * and try the whole sequence a few more times else done
  3113. */
  3114. ret_val =
  3115. e1000_flash_cycle_ich8lan(hw,
  3116. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  3117. if (!ret_val)
  3118. break;
  3119. /* If we're here, then things are most likely
  3120. * completely hosed, but if the error condition
  3121. * is detected, it won't hurt to give it another
  3122. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3123. */
  3124. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3125. if (hsfsts.hsf_status.flcerr)
  3126. /* Repeat for some time before giving up. */
  3127. continue;
  3128. if (!hsfsts.hsf_status.flcdone) {
  3129. e_dbg("Timeout error - flash cycle did not complete.\n");
  3130. break;
  3131. }
  3132. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3133. return ret_val;
  3134. }
  3135. /**
  3136. * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
  3137. * @hw: pointer to the HW structure
  3138. * @offset: The index of the byte to read.
  3139. * @data: The byte to write to the NVM.
  3140. *
  3141. * Writes a single byte to the NVM using the flash access registers.
  3142. **/
  3143. static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  3144. u8 data)
  3145. {
  3146. u16 word = (u16)data;
  3147. return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
  3148. }
  3149. /**
  3150. * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
  3151. * @hw: pointer to the HW structure
  3152. * @offset: The offset of the byte to write.
  3153. * @byte: The byte to write to the NVM.
  3154. *
  3155. * Writes a single byte to the NVM using the flash access registers.
  3156. * Goes through a retry algorithm before giving up.
  3157. **/
  3158. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  3159. u32 offset, u8 byte)
  3160. {
  3161. s32 ret_val;
  3162. u16 program_retries;
  3163. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  3164. if (!ret_val)
  3165. return ret_val;
  3166. for (program_retries = 0; program_retries < 100; program_retries++) {
  3167. e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
  3168. usleep_range(100, 200);
  3169. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  3170. if (!ret_val)
  3171. break;
  3172. }
  3173. if (program_retries == 100)
  3174. return -E1000_ERR_NVM;
  3175. return 0;
  3176. }
  3177. /**
  3178. * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
  3179. * @hw: pointer to the HW structure
  3180. * @bank: 0 for first bank, 1 for second bank, etc.
  3181. *
  3182. * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
  3183. * bank N is 4096 * N + flash_reg_addr.
  3184. **/
  3185. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
  3186. {
  3187. struct e1000_nvm_info *nvm = &hw->nvm;
  3188. union ich8_hws_flash_status hsfsts;
  3189. union ich8_hws_flash_ctrl hsflctl;
  3190. u32 flash_linear_addr;
  3191. /* bank size is in 16bit words - adjust to bytes */
  3192. u32 flash_bank_size = nvm->flash_bank_size * 2;
  3193. s32 ret_val;
  3194. s32 count = 0;
  3195. s32 j, iteration, sector_size;
  3196. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3197. /* Determine HW Sector size: Read BERASE bits of hw flash status
  3198. * register
  3199. * 00: The Hw sector is 256 bytes, hence we need to erase 16
  3200. * consecutive sectors. The start index for the nth Hw sector
  3201. * can be calculated as = bank * 4096 + n * 256
  3202. * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
  3203. * The start index for the nth Hw sector can be calculated
  3204. * as = bank * 4096
  3205. * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
  3206. * (ich9 only, otherwise error condition)
  3207. * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
  3208. */
  3209. switch (hsfsts.hsf_status.berasesz) {
  3210. case 0:
  3211. /* Hw sector size 256 */
  3212. sector_size = ICH_FLASH_SEG_SIZE_256;
  3213. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
  3214. break;
  3215. case 1:
  3216. sector_size = ICH_FLASH_SEG_SIZE_4K;
  3217. iteration = 1;
  3218. break;
  3219. case 2:
  3220. sector_size = ICH_FLASH_SEG_SIZE_8K;
  3221. iteration = 1;
  3222. break;
  3223. case 3:
  3224. sector_size = ICH_FLASH_SEG_SIZE_64K;
  3225. iteration = 1;
  3226. break;
  3227. default:
  3228. return -E1000_ERR_NVM;
  3229. }
  3230. /* Start with the base address, then add the sector offset. */
  3231. flash_linear_addr = hw->nvm.flash_base_addr;
  3232. flash_linear_addr += (bank) ? flash_bank_size : 0;
  3233. for (j = 0; j < iteration; j++) {
  3234. do {
  3235. u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
  3236. /* Steps */
  3237. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3238. if (ret_val)
  3239. return ret_val;
  3240. /* Write a value 11 (block Erase) in Flash
  3241. * Cycle field in hw flash control
  3242. */
  3243. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3244. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
  3245. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3246. /* Write the last 24 bits of an index within the
  3247. * block into Flash Linear address field in Flash
  3248. * Address.
  3249. */
  3250. flash_linear_addr += (j * sector_size);
  3251. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3252. ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
  3253. if (!ret_val)
  3254. break;
  3255. /* Check if FCERR is set to 1. If 1,
  3256. * clear it and try the whole sequence
  3257. * a few more times else Done
  3258. */
  3259. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3260. if (hsfsts.hsf_status.flcerr)
  3261. /* repeat for some time before giving up */
  3262. continue;
  3263. else if (!hsfsts.hsf_status.flcdone)
  3264. return ret_val;
  3265. } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3266. }
  3267. return 0;
  3268. }
  3269. /**
  3270. * e1000_valid_led_default_ich8lan - Set the default LED settings
  3271. * @hw: pointer to the HW structure
  3272. * @data: Pointer to the LED settings
  3273. *
  3274. * Reads the LED default settings from the NVM to data. If the NVM LED
  3275. * settings is all 0's or F's, set the LED default to a valid LED default
  3276. * setting.
  3277. **/
  3278. static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
  3279. {
  3280. s32 ret_val;
  3281. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  3282. if (ret_val) {
  3283. e_dbg("NVM Read Error\n");
  3284. return ret_val;
  3285. }
  3286. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  3287. *data = ID_LED_DEFAULT_ICH8LAN;
  3288. return 0;
  3289. }
  3290. /**
  3291. * e1000_id_led_init_pchlan - store LED configurations
  3292. * @hw: pointer to the HW structure
  3293. *
  3294. * PCH does not control LEDs via the LEDCTL register, rather it uses
  3295. * the PHY LED configuration register.
  3296. *
  3297. * PCH also does not have an "always on" or "always off" mode which
  3298. * complicates the ID feature. Instead of using the "on" mode to indicate
  3299. * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
  3300. * use "link_up" mode. The LEDs will still ID on request if there is no
  3301. * link based on logic in e1000_led_[on|off]_pchlan().
  3302. **/
  3303. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
  3304. {
  3305. struct e1000_mac_info *mac = &hw->mac;
  3306. s32 ret_val;
  3307. const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
  3308. const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
  3309. u16 data, i, temp, shift;
  3310. /* Get default ID LED modes */
  3311. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  3312. if (ret_val)
  3313. return ret_val;
  3314. mac->ledctl_default = er32(LEDCTL);
  3315. mac->ledctl_mode1 = mac->ledctl_default;
  3316. mac->ledctl_mode2 = mac->ledctl_default;
  3317. for (i = 0; i < 4; i++) {
  3318. temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
  3319. shift = (i * 5);
  3320. switch (temp) {
  3321. case ID_LED_ON1_DEF2:
  3322. case ID_LED_ON1_ON2:
  3323. case ID_LED_ON1_OFF2:
  3324. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  3325. mac->ledctl_mode1 |= (ledctl_on << shift);
  3326. break;
  3327. case ID_LED_OFF1_DEF2:
  3328. case ID_LED_OFF1_ON2:
  3329. case ID_LED_OFF1_OFF2:
  3330. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  3331. mac->ledctl_mode1 |= (ledctl_off << shift);
  3332. break;
  3333. default:
  3334. /* Do nothing */
  3335. break;
  3336. }
  3337. switch (temp) {
  3338. case ID_LED_DEF1_ON2:
  3339. case ID_LED_ON1_ON2:
  3340. case ID_LED_OFF1_ON2:
  3341. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  3342. mac->ledctl_mode2 |= (ledctl_on << shift);
  3343. break;
  3344. case ID_LED_DEF1_OFF2:
  3345. case ID_LED_ON1_OFF2:
  3346. case ID_LED_OFF1_OFF2:
  3347. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  3348. mac->ledctl_mode2 |= (ledctl_off << shift);
  3349. break;
  3350. default:
  3351. /* Do nothing */
  3352. break;
  3353. }
  3354. }
  3355. return 0;
  3356. }
  3357. /**
  3358. * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
  3359. * @hw: pointer to the HW structure
  3360. *
  3361. * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
  3362. * register, so the the bus width is hard coded.
  3363. **/
  3364. static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
  3365. {
  3366. struct e1000_bus_info *bus = &hw->bus;
  3367. s32 ret_val;
  3368. ret_val = e1000e_get_bus_info_pcie(hw);
  3369. /* ICH devices are "PCI Express"-ish. They have
  3370. * a configuration space, but do not contain
  3371. * PCI Express Capability registers, so bus width
  3372. * must be hardcoded.
  3373. */
  3374. if (bus->width == e1000_bus_width_unknown)
  3375. bus->width = e1000_bus_width_pcie_x1;
  3376. return ret_val;
  3377. }
  3378. /**
  3379. * e1000_reset_hw_ich8lan - Reset the hardware
  3380. * @hw: pointer to the HW structure
  3381. *
  3382. * Does a full reset of the hardware which includes a reset of the PHY and
  3383. * MAC.
  3384. **/
  3385. static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
  3386. {
  3387. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3388. u16 kum_cfg;
  3389. u32 ctrl, reg;
  3390. s32 ret_val;
  3391. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  3392. * on the last TLP read/write transaction when MAC is reset.
  3393. */
  3394. ret_val = e1000e_disable_pcie_master(hw);
  3395. if (ret_val)
  3396. e_dbg("PCI-E Master disable polling has failed.\n");
  3397. e_dbg("Masking off all interrupts\n");
  3398. ew32(IMC, 0xffffffff);
  3399. /* Disable the Transmit and Receive units. Then delay to allow
  3400. * any pending transactions to complete before we hit the MAC
  3401. * with the global reset.
  3402. */
  3403. ew32(RCTL, 0);
  3404. ew32(TCTL, E1000_TCTL_PSP);
  3405. e1e_flush();
  3406. usleep_range(10000, 20000);
  3407. /* Workaround for ICH8 bit corruption issue in FIFO memory */
  3408. if (hw->mac.type == e1000_ich8lan) {
  3409. /* Set Tx and Rx buffer allocation to 8k apiece. */
  3410. ew32(PBA, E1000_PBA_8K);
  3411. /* Set Packet Buffer Size to 16k. */
  3412. ew32(PBS, E1000_PBS_16K);
  3413. }
  3414. if (hw->mac.type == e1000_pchlan) {
  3415. /* Save the NVM K1 bit setting */
  3416. ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
  3417. if (ret_val)
  3418. return ret_val;
  3419. if (kum_cfg & E1000_NVM_K1_ENABLE)
  3420. dev_spec->nvm_k1_enabled = true;
  3421. else
  3422. dev_spec->nvm_k1_enabled = false;
  3423. }
  3424. ctrl = er32(CTRL);
  3425. if (!hw->phy.ops.check_reset_block(hw)) {
  3426. /* Full-chip reset requires MAC and PHY reset at the same
  3427. * time to make sure the interface between MAC and the
  3428. * external PHY is reset.
  3429. */
  3430. ctrl |= E1000_CTRL_PHY_RST;
  3431. /* Gate automatic PHY configuration by hardware on
  3432. * non-managed 82579
  3433. */
  3434. if ((hw->mac.type == e1000_pch2lan) &&
  3435. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  3436. e1000_gate_hw_phy_config_ich8lan(hw, true);
  3437. }
  3438. ret_val = e1000_acquire_swflag_ich8lan(hw);
  3439. e_dbg("Issuing a global reset to ich8lan\n");
  3440. ew32(CTRL, (ctrl | E1000_CTRL_RST));
  3441. /* cannot issue a flush here because it hangs the hardware */
  3442. msleep(20);
  3443. /* Set Phy Config Counter to 50msec */
  3444. if (hw->mac.type == e1000_pch2lan) {
  3445. reg = er32(FEXTNVM3);
  3446. reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  3447. reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  3448. ew32(FEXTNVM3, reg);
  3449. }
  3450. if (!ret_val)
  3451. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  3452. if (ctrl & E1000_CTRL_PHY_RST) {
  3453. ret_val = hw->phy.ops.get_cfg_done(hw);
  3454. if (ret_val)
  3455. return ret_val;
  3456. ret_val = e1000_post_phy_reset_ich8lan(hw);
  3457. if (ret_val)
  3458. return ret_val;
  3459. }
  3460. /* For PCH, this write will make sure that any noise
  3461. * will be detected as a CRC error and be dropped rather than show up
  3462. * as a bad packet to the DMA engine.
  3463. */
  3464. if (hw->mac.type == e1000_pchlan)
  3465. ew32(CRC_OFFSET, 0x65656565);
  3466. ew32(IMC, 0xffffffff);
  3467. er32(ICR);
  3468. reg = er32(KABGTXD);
  3469. reg |= E1000_KABGTXD_BGSQLBIAS;
  3470. ew32(KABGTXD, reg);
  3471. return 0;
  3472. }
  3473. /**
  3474. * e1000_init_hw_ich8lan - Initialize the hardware
  3475. * @hw: pointer to the HW structure
  3476. *
  3477. * Prepares the hardware for transmit and receive by doing the following:
  3478. * - initialize hardware bits
  3479. * - initialize LED identification
  3480. * - setup receive address registers
  3481. * - setup flow control
  3482. * - setup transmit descriptors
  3483. * - clear statistics
  3484. **/
  3485. static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
  3486. {
  3487. struct e1000_mac_info *mac = &hw->mac;
  3488. u32 ctrl_ext, txdctl, snoop;
  3489. s32 ret_val;
  3490. u16 i;
  3491. e1000_initialize_hw_bits_ich8lan(hw);
  3492. /* Initialize identification LED */
  3493. ret_val = mac->ops.id_led_init(hw);
  3494. /* An error is not fatal and we should not stop init due to this */
  3495. if (ret_val)
  3496. e_dbg("Error initializing identification LED\n");
  3497. /* Setup the receive address. */
  3498. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  3499. /* Zero out the Multicast HASH table */
  3500. e_dbg("Zeroing the MTA\n");
  3501. for (i = 0; i < mac->mta_reg_count; i++)
  3502. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  3503. /* The 82578 Rx buffer will stall if wakeup is enabled in host and
  3504. * the ME. Disable wakeup by clearing the host wakeup bit.
  3505. * Reset the phy after disabling host wakeup to reset the Rx buffer.
  3506. */
  3507. if (hw->phy.type == e1000_phy_82578) {
  3508. e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
  3509. i &= ~BM_WUC_HOST_WU_BIT;
  3510. e1e_wphy(hw, BM_PORT_GEN_CFG, i);
  3511. ret_val = e1000_phy_hw_reset_ich8lan(hw);
  3512. if (ret_val)
  3513. return ret_val;
  3514. }
  3515. /* Setup link and flow control */
  3516. ret_val = mac->ops.setup_link(hw);
  3517. /* Set the transmit descriptor write-back policy for both queues */
  3518. txdctl = er32(TXDCTL(0));
  3519. txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
  3520. E1000_TXDCTL_FULL_TX_DESC_WB);
  3521. txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
  3522. E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
  3523. ew32(TXDCTL(0), txdctl);
  3524. txdctl = er32(TXDCTL(1));
  3525. txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
  3526. E1000_TXDCTL_FULL_TX_DESC_WB);
  3527. txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
  3528. E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
  3529. ew32(TXDCTL(1), txdctl);
  3530. /* ICH8 has opposite polarity of no_snoop bits.
  3531. * By default, we should use snoop behavior.
  3532. */
  3533. if (mac->type == e1000_ich8lan)
  3534. snoop = PCIE_ICH8_SNOOP_ALL;
  3535. else
  3536. snoop = (u32)~(PCIE_NO_SNOOP_ALL);
  3537. e1000e_set_pcie_no_snoop(hw, snoop);
  3538. ctrl_ext = er32(CTRL_EXT);
  3539. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  3540. ew32(CTRL_EXT, ctrl_ext);
  3541. /* Clear all of the statistics registers (clear on read). It is
  3542. * important that we do this after we have tried to establish link
  3543. * because the symbol error count will increment wildly if there
  3544. * is no link.
  3545. */
  3546. e1000_clear_hw_cntrs_ich8lan(hw);
  3547. return ret_val;
  3548. }
  3549. /**
  3550. * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
  3551. * @hw: pointer to the HW structure
  3552. *
  3553. * Sets/Clears required hardware bits necessary for correctly setting up the
  3554. * hardware for transmit and receive.
  3555. **/
  3556. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
  3557. {
  3558. u32 reg;
  3559. /* Extended Device Control */
  3560. reg = er32(CTRL_EXT);
  3561. reg |= (1 << 22);
  3562. /* Enable PHY low-power state when MAC is at D3 w/o WoL */
  3563. if (hw->mac.type >= e1000_pchlan)
  3564. reg |= E1000_CTRL_EXT_PHYPDEN;
  3565. ew32(CTRL_EXT, reg);
  3566. /* Transmit Descriptor Control 0 */
  3567. reg = er32(TXDCTL(0));
  3568. reg |= (1 << 22);
  3569. ew32(TXDCTL(0), reg);
  3570. /* Transmit Descriptor Control 1 */
  3571. reg = er32(TXDCTL(1));
  3572. reg |= (1 << 22);
  3573. ew32(TXDCTL(1), reg);
  3574. /* Transmit Arbitration Control 0 */
  3575. reg = er32(TARC(0));
  3576. if (hw->mac.type == e1000_ich8lan)
  3577. reg |= (1 << 28) | (1 << 29);
  3578. reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
  3579. ew32(TARC(0), reg);
  3580. /* Transmit Arbitration Control 1 */
  3581. reg = er32(TARC(1));
  3582. if (er32(TCTL) & E1000_TCTL_MULR)
  3583. reg &= ~(1 << 28);
  3584. else
  3585. reg |= (1 << 28);
  3586. reg |= (1 << 24) | (1 << 26) | (1 << 30);
  3587. ew32(TARC(1), reg);
  3588. /* Device Status */
  3589. if (hw->mac.type == e1000_ich8lan) {
  3590. reg = er32(STATUS);
  3591. reg &= ~(1 << 31);
  3592. ew32(STATUS, reg);
  3593. }
  3594. /* work-around descriptor data corruption issue during nfs v2 udp
  3595. * traffic, just disable the nfs filtering capability
  3596. */
  3597. reg = er32(RFCTL);
  3598. reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
  3599. /* Disable IPv6 extension header parsing because some malformed
  3600. * IPv6 headers can hang the Rx.
  3601. */
  3602. if (hw->mac.type == e1000_ich8lan)
  3603. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  3604. ew32(RFCTL, reg);
  3605. /* Enable ECC on Lynxpoint */
  3606. if (hw->mac.type == e1000_pch_lpt) {
  3607. reg = er32(PBECCSTS);
  3608. reg |= E1000_PBECCSTS_ECC_ENABLE;
  3609. ew32(PBECCSTS, reg);
  3610. reg = er32(CTRL);
  3611. reg |= E1000_CTRL_MEHE;
  3612. ew32(CTRL, reg);
  3613. }
  3614. }
  3615. /**
  3616. * e1000_setup_link_ich8lan - Setup flow control and link settings
  3617. * @hw: pointer to the HW structure
  3618. *
  3619. * Determines which flow control settings to use, then configures flow
  3620. * control. Calls the appropriate media-specific link configuration
  3621. * function. Assuming the adapter has a valid link partner, a valid link
  3622. * should be established. Assumes the hardware has previously been reset
  3623. * and the transmitter and receiver are not enabled.
  3624. **/
  3625. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
  3626. {
  3627. s32 ret_val;
  3628. if (hw->phy.ops.check_reset_block(hw))
  3629. return 0;
  3630. /* ICH parts do not have a word in the NVM to determine
  3631. * the default flow control setting, so we explicitly
  3632. * set it to full.
  3633. */
  3634. if (hw->fc.requested_mode == e1000_fc_default) {
  3635. /* Workaround h/w hang when Tx flow control enabled */
  3636. if (hw->mac.type == e1000_pchlan)
  3637. hw->fc.requested_mode = e1000_fc_rx_pause;
  3638. else
  3639. hw->fc.requested_mode = e1000_fc_full;
  3640. }
  3641. /* Save off the requested flow control mode for use later. Depending
  3642. * on the link partner's capabilities, we may or may not use this mode.
  3643. */
  3644. hw->fc.current_mode = hw->fc.requested_mode;
  3645. e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
  3646. /* Continue to configure the copper link. */
  3647. ret_val = hw->mac.ops.setup_physical_interface(hw);
  3648. if (ret_val)
  3649. return ret_val;
  3650. ew32(FCTTV, hw->fc.pause_time);
  3651. if ((hw->phy.type == e1000_phy_82578) ||
  3652. (hw->phy.type == e1000_phy_82579) ||
  3653. (hw->phy.type == e1000_phy_i217) ||
  3654. (hw->phy.type == e1000_phy_82577)) {
  3655. ew32(FCRTV_PCH, hw->fc.refresh_time);
  3656. ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
  3657. hw->fc.pause_time);
  3658. if (ret_val)
  3659. return ret_val;
  3660. }
  3661. return e1000e_set_fc_watermarks(hw);
  3662. }
  3663. /**
  3664. * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
  3665. * @hw: pointer to the HW structure
  3666. *
  3667. * Configures the kumeran interface to the PHY to wait the appropriate time
  3668. * when polling the PHY, then call the generic setup_copper_link to finish
  3669. * configuring the copper link.
  3670. **/
  3671. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
  3672. {
  3673. u32 ctrl;
  3674. s32 ret_val;
  3675. u16 reg_data;
  3676. ctrl = er32(CTRL);
  3677. ctrl |= E1000_CTRL_SLU;
  3678. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  3679. ew32(CTRL, ctrl);
  3680. /* Set the mac to wait the maximum time between each iteration
  3681. * and increase the max iterations when polling the phy;
  3682. * this fixes erroneous timeouts at 10Mbps.
  3683. */
  3684. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
  3685. if (ret_val)
  3686. return ret_val;
  3687. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  3688. &reg_data);
  3689. if (ret_val)
  3690. return ret_val;
  3691. reg_data |= 0x3F;
  3692. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  3693. reg_data);
  3694. if (ret_val)
  3695. return ret_val;
  3696. switch (hw->phy.type) {
  3697. case e1000_phy_igp_3:
  3698. ret_val = e1000e_copper_link_setup_igp(hw);
  3699. if (ret_val)
  3700. return ret_val;
  3701. break;
  3702. case e1000_phy_bm:
  3703. case e1000_phy_82578:
  3704. ret_val = e1000e_copper_link_setup_m88(hw);
  3705. if (ret_val)
  3706. return ret_val;
  3707. break;
  3708. case e1000_phy_82577:
  3709. case e1000_phy_82579:
  3710. ret_val = e1000_copper_link_setup_82577(hw);
  3711. if (ret_val)
  3712. return ret_val;
  3713. break;
  3714. case e1000_phy_ife:
  3715. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
  3716. if (ret_val)
  3717. return ret_val;
  3718. reg_data &= ~IFE_PMC_AUTO_MDIX;
  3719. switch (hw->phy.mdix) {
  3720. case 1:
  3721. reg_data &= ~IFE_PMC_FORCE_MDIX;
  3722. break;
  3723. case 2:
  3724. reg_data |= IFE_PMC_FORCE_MDIX;
  3725. break;
  3726. case 0:
  3727. default:
  3728. reg_data |= IFE_PMC_AUTO_MDIX;
  3729. break;
  3730. }
  3731. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
  3732. if (ret_val)
  3733. return ret_val;
  3734. break;
  3735. default:
  3736. break;
  3737. }
  3738. return e1000e_setup_copper_link(hw);
  3739. }
  3740. /**
  3741. * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
  3742. * @hw: pointer to the HW structure
  3743. *
  3744. * Calls the PHY specific link setup function and then calls the
  3745. * generic setup_copper_link to finish configuring the link for
  3746. * Lynxpoint PCH devices
  3747. **/
  3748. static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
  3749. {
  3750. u32 ctrl;
  3751. s32 ret_val;
  3752. ctrl = er32(CTRL);
  3753. ctrl |= E1000_CTRL_SLU;
  3754. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  3755. ew32(CTRL, ctrl);
  3756. ret_val = e1000_copper_link_setup_82577(hw);
  3757. if (ret_val)
  3758. return ret_val;
  3759. return e1000e_setup_copper_link(hw);
  3760. }
  3761. /**
  3762. * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
  3763. * @hw: pointer to the HW structure
  3764. * @speed: pointer to store current link speed
  3765. * @duplex: pointer to store the current link duplex
  3766. *
  3767. * Calls the generic get_speed_and_duplex to retrieve the current link
  3768. * information and then calls the Kumeran lock loss workaround for links at
  3769. * gigabit speeds.
  3770. **/
  3771. static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
  3772. u16 *duplex)
  3773. {
  3774. s32 ret_val;
  3775. ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
  3776. if (ret_val)
  3777. return ret_val;
  3778. if ((hw->mac.type == e1000_ich8lan) &&
  3779. (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
  3780. ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
  3781. }
  3782. return ret_val;
  3783. }
  3784. /**
  3785. * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
  3786. * @hw: pointer to the HW structure
  3787. *
  3788. * Work-around for 82566 Kumeran PCS lock loss:
  3789. * On link status change (i.e. PCI reset, speed change) and link is up and
  3790. * speed is gigabit-
  3791. * 0) if workaround is optionally disabled do nothing
  3792. * 1) wait 1ms for Kumeran link to come up
  3793. * 2) check Kumeran Diagnostic register PCS lock loss bit
  3794. * 3) if not set the link is locked (all is good), otherwise...
  3795. * 4) reset the PHY
  3796. * 5) repeat up to 10 times
  3797. * Note: this is only called for IGP3 copper when speed is 1gb.
  3798. **/
  3799. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
  3800. {
  3801. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3802. u32 phy_ctrl;
  3803. s32 ret_val;
  3804. u16 i, data;
  3805. bool link;
  3806. if (!dev_spec->kmrn_lock_loss_workaround_enabled)
  3807. return 0;
  3808. /* Make sure link is up before proceeding. If not just return.
  3809. * Attempting this while link is negotiating fouled up link
  3810. * stability
  3811. */
  3812. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  3813. if (!link)
  3814. return 0;
  3815. for (i = 0; i < 10; i++) {
  3816. /* read once to clear */
  3817. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  3818. if (ret_val)
  3819. return ret_val;
  3820. /* and again to get new status */
  3821. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  3822. if (ret_val)
  3823. return ret_val;
  3824. /* check for PCS lock */
  3825. if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
  3826. return 0;
  3827. /* Issue PHY reset */
  3828. e1000_phy_hw_reset(hw);
  3829. mdelay(5);
  3830. }
  3831. /* Disable GigE link negotiation */
  3832. phy_ctrl = er32(PHY_CTRL);
  3833. phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
  3834. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  3835. ew32(PHY_CTRL, phy_ctrl);
  3836. /* Call gig speed drop workaround on Gig disable before accessing
  3837. * any PHY registers
  3838. */
  3839. e1000e_gig_downshift_workaround_ich8lan(hw);
  3840. /* unable to acquire PCS lock */
  3841. return -E1000_ERR_PHY;
  3842. }
  3843. /**
  3844. * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
  3845. * @hw: pointer to the HW structure
  3846. * @state: boolean value used to set the current Kumeran workaround state
  3847. *
  3848. * If ICH8, set the current Kumeran workaround state (enabled - true
  3849. * /disabled - false).
  3850. **/
  3851. void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
  3852. bool state)
  3853. {
  3854. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3855. if (hw->mac.type != e1000_ich8lan) {
  3856. e_dbg("Workaround applies to ICH8 only.\n");
  3857. return;
  3858. }
  3859. dev_spec->kmrn_lock_loss_workaround_enabled = state;
  3860. }
  3861. /**
  3862. * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
  3863. * @hw: pointer to the HW structure
  3864. *
  3865. * Workaround for 82566 power-down on D3 entry:
  3866. * 1) disable gigabit link
  3867. * 2) write VR power-down enable
  3868. * 3) read it back
  3869. * Continue if successful, else issue LCD reset and repeat
  3870. **/
  3871. void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
  3872. {
  3873. u32 reg;
  3874. u16 data;
  3875. u8 retry = 0;
  3876. if (hw->phy.type != e1000_phy_igp_3)
  3877. return;
  3878. /* Try the workaround twice (if needed) */
  3879. do {
  3880. /* Disable link */
  3881. reg = er32(PHY_CTRL);
  3882. reg |= (E1000_PHY_CTRL_GBE_DISABLE |
  3883. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  3884. ew32(PHY_CTRL, reg);
  3885. /* Call gig speed drop workaround on Gig disable before
  3886. * accessing any PHY registers
  3887. */
  3888. if (hw->mac.type == e1000_ich8lan)
  3889. e1000e_gig_downshift_workaround_ich8lan(hw);
  3890. /* Write VR power-down enable */
  3891. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  3892. data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  3893. e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
  3894. /* Read it back and test */
  3895. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  3896. data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  3897. if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
  3898. break;
  3899. /* Issue PHY reset and repeat at most one more time */
  3900. reg = er32(CTRL);
  3901. ew32(CTRL, reg | E1000_CTRL_PHY_RST);
  3902. retry++;
  3903. } while (retry);
  3904. }
  3905. /**
  3906. * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
  3907. * @hw: pointer to the HW structure
  3908. *
  3909. * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
  3910. * LPLU, Gig disable, MDIC PHY reset):
  3911. * 1) Set Kumeran Near-end loopback
  3912. * 2) Clear Kumeran Near-end loopback
  3913. * Should only be called for ICH8[m] devices with any 1G Phy.
  3914. **/
  3915. void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
  3916. {
  3917. s32 ret_val;
  3918. u16 reg_data;
  3919. if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
  3920. return;
  3921. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  3922. &reg_data);
  3923. if (ret_val)
  3924. return;
  3925. reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
  3926. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  3927. reg_data);
  3928. if (ret_val)
  3929. return;
  3930. reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
  3931. e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
  3932. }
  3933. /**
  3934. * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
  3935. * @hw: pointer to the HW structure
  3936. *
  3937. * During S0 to Sx transition, it is possible the link remains at gig
  3938. * instead of negotiating to a lower speed. Before going to Sx, set
  3939. * 'Gig Disable' to force link speed negotiation to a lower speed based on
  3940. * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
  3941. * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
  3942. * needs to be written.
  3943. * Parts that support (and are linked to a partner which support) EEE in
  3944. * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
  3945. * than 10Mbps w/o EEE.
  3946. **/
  3947. void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
  3948. {
  3949. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3950. u32 phy_ctrl;
  3951. s32 ret_val;
  3952. phy_ctrl = er32(PHY_CTRL);
  3953. phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
  3954. if (hw->phy.type == e1000_phy_i217) {
  3955. u16 phy_reg, device_id = hw->adapter->pdev->device;
  3956. if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
  3957. (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
  3958. (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
  3959. (device_id == E1000_DEV_ID_PCH_I218_V3)) {
  3960. u32 fextnvm6 = er32(FEXTNVM6);
  3961. ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
  3962. }
  3963. ret_val = hw->phy.ops.acquire(hw);
  3964. if (ret_val)
  3965. goto out;
  3966. if (!dev_spec->eee_disable) {
  3967. u16 eee_advert;
  3968. ret_val =
  3969. e1000_read_emi_reg_locked(hw,
  3970. I217_EEE_ADVERTISEMENT,
  3971. &eee_advert);
  3972. if (ret_val)
  3973. goto release;
  3974. /* Disable LPLU if both link partners support 100BaseT
  3975. * EEE and 100Full is advertised on both ends of the
  3976. * link.
  3977. */
  3978. if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
  3979. (dev_spec->eee_lp_ability &
  3980. I82579_EEE_100_SUPPORTED) &&
  3981. (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
  3982. phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
  3983. E1000_PHY_CTRL_NOND0A_LPLU);
  3984. }
  3985. /* For i217 Intel Rapid Start Technology support,
  3986. * when the system is going into Sx and no manageability engine
  3987. * is present, the driver must configure proxy to reset only on
  3988. * power good. LPI (Low Power Idle) state must also reset only
  3989. * on power good, as well as the MTA (Multicast table array).
  3990. * The SMBus release must also be disabled on LCD reset.
  3991. */
  3992. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  3993. /* Enable proxy to reset only on power good. */
  3994. e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
  3995. phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
  3996. e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
  3997. /* Set bit enable LPI (EEE) to reset only on
  3998. * power good.
  3999. */
  4000. e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
  4001. phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
  4002. e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
  4003. /* Disable the SMB release on LCD reset. */
  4004. e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  4005. phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
  4006. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  4007. }
  4008. /* Enable MTA to reset for Intel Rapid Start Technology
  4009. * Support
  4010. */
  4011. e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  4012. phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
  4013. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  4014. release:
  4015. hw->phy.ops.release(hw);
  4016. }
  4017. out:
  4018. ew32(PHY_CTRL, phy_ctrl);
  4019. if (hw->mac.type == e1000_ich8lan)
  4020. e1000e_gig_downshift_workaround_ich8lan(hw);
  4021. if (hw->mac.type >= e1000_pchlan) {
  4022. e1000_oem_bits_config_ich8lan(hw, false);
  4023. /* Reset PHY to activate OEM bits on 82577/8 */
  4024. if (hw->mac.type == e1000_pchlan)
  4025. e1000e_phy_hw_reset_generic(hw);
  4026. ret_val = hw->phy.ops.acquire(hw);
  4027. if (ret_val)
  4028. return;
  4029. e1000_write_smbus_addr(hw);
  4030. hw->phy.ops.release(hw);
  4031. }
  4032. }
  4033. /**
  4034. * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
  4035. * @hw: pointer to the HW structure
  4036. *
  4037. * During Sx to S0 transitions on non-managed devices or managed devices
  4038. * on which PHY resets are not blocked, if the PHY registers cannot be
  4039. * accessed properly by the s/w toggle the LANPHYPC value to power cycle
  4040. * the PHY.
  4041. * On i217, setup Intel Rapid Start Technology.
  4042. **/
  4043. void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
  4044. {
  4045. s32 ret_val;
  4046. if (hw->mac.type < e1000_pch2lan)
  4047. return;
  4048. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  4049. if (ret_val) {
  4050. e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
  4051. return;
  4052. }
  4053. /* For i217 Intel Rapid Start Technology support when the system
  4054. * is transitioning from Sx and no manageability engine is present
  4055. * configure SMBus to restore on reset, disable proxy, and enable
  4056. * the reset on MTA (Multicast table array).
  4057. */
  4058. if (hw->phy.type == e1000_phy_i217) {
  4059. u16 phy_reg;
  4060. ret_val = hw->phy.ops.acquire(hw);
  4061. if (ret_val) {
  4062. e_dbg("Failed to setup iRST\n");
  4063. return;
  4064. }
  4065. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  4066. /* Restore clear on SMB if no manageability engine
  4067. * is present
  4068. */
  4069. ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  4070. if (ret_val)
  4071. goto release;
  4072. phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
  4073. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  4074. /* Disable Proxy */
  4075. e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
  4076. }
  4077. /* Enable reset on MTA */
  4078. ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  4079. if (ret_val)
  4080. goto release;
  4081. phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
  4082. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  4083. release:
  4084. if (ret_val)
  4085. e_dbg("Error %d in resume workarounds\n", ret_val);
  4086. hw->phy.ops.release(hw);
  4087. }
  4088. }
  4089. /**
  4090. * e1000_cleanup_led_ich8lan - Restore the default LED operation
  4091. * @hw: pointer to the HW structure
  4092. *
  4093. * Return the LED back to the default configuration.
  4094. **/
  4095. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
  4096. {
  4097. if (hw->phy.type == e1000_phy_ife)
  4098. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  4099. ew32(LEDCTL, hw->mac.ledctl_default);
  4100. return 0;
  4101. }
  4102. /**
  4103. * e1000_led_on_ich8lan - Turn LEDs on
  4104. * @hw: pointer to the HW structure
  4105. *
  4106. * Turn on the LEDs.
  4107. **/
  4108. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
  4109. {
  4110. if (hw->phy.type == e1000_phy_ife)
  4111. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  4112. (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
  4113. ew32(LEDCTL, hw->mac.ledctl_mode2);
  4114. return 0;
  4115. }
  4116. /**
  4117. * e1000_led_off_ich8lan - Turn LEDs off
  4118. * @hw: pointer to the HW structure
  4119. *
  4120. * Turn off the LEDs.
  4121. **/
  4122. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
  4123. {
  4124. if (hw->phy.type == e1000_phy_ife)
  4125. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  4126. (IFE_PSCL_PROBE_MODE |
  4127. IFE_PSCL_PROBE_LEDS_OFF));
  4128. ew32(LEDCTL, hw->mac.ledctl_mode1);
  4129. return 0;
  4130. }
  4131. /**
  4132. * e1000_setup_led_pchlan - Configures SW controllable LED
  4133. * @hw: pointer to the HW structure
  4134. *
  4135. * This prepares the SW controllable LED for use.
  4136. **/
  4137. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
  4138. {
  4139. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
  4140. }
  4141. /**
  4142. * e1000_cleanup_led_pchlan - Restore the default LED operation
  4143. * @hw: pointer to the HW structure
  4144. *
  4145. * Return the LED back to the default configuration.
  4146. **/
  4147. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
  4148. {
  4149. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
  4150. }
  4151. /**
  4152. * e1000_led_on_pchlan - Turn LEDs on
  4153. * @hw: pointer to the HW structure
  4154. *
  4155. * Turn on the LEDs.
  4156. **/
  4157. static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
  4158. {
  4159. u16 data = (u16)hw->mac.ledctl_mode2;
  4160. u32 i, led;
  4161. /* If no link, then turn LED on by setting the invert bit
  4162. * for each LED that's mode is "link_up" in ledctl_mode2.
  4163. */
  4164. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  4165. for (i = 0; i < 3; i++) {
  4166. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  4167. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  4168. E1000_LEDCTL_MODE_LINK_UP)
  4169. continue;
  4170. if (led & E1000_PHY_LED0_IVRT)
  4171. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  4172. else
  4173. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  4174. }
  4175. }
  4176. return e1e_wphy(hw, HV_LED_CONFIG, data);
  4177. }
  4178. /**
  4179. * e1000_led_off_pchlan - Turn LEDs off
  4180. * @hw: pointer to the HW structure
  4181. *
  4182. * Turn off the LEDs.
  4183. **/
  4184. static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
  4185. {
  4186. u16 data = (u16)hw->mac.ledctl_mode1;
  4187. u32 i, led;
  4188. /* If no link, then turn LED off by clearing the invert bit
  4189. * for each LED that's mode is "link_up" in ledctl_mode1.
  4190. */
  4191. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  4192. for (i = 0; i < 3; i++) {
  4193. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  4194. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  4195. E1000_LEDCTL_MODE_LINK_UP)
  4196. continue;
  4197. if (led & E1000_PHY_LED0_IVRT)
  4198. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  4199. else
  4200. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  4201. }
  4202. }
  4203. return e1e_wphy(hw, HV_LED_CONFIG, data);
  4204. }
  4205. /**
  4206. * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
  4207. * @hw: pointer to the HW structure
  4208. *
  4209. * Read appropriate register for the config done bit for completion status
  4210. * and configure the PHY through s/w for EEPROM-less parts.
  4211. *
  4212. * NOTE: some silicon which is EEPROM-less will fail trying to read the
  4213. * config done bit, so only an error is logged and continues. If we were
  4214. * to return with error, EEPROM-less silicon would not be able to be reset
  4215. * or change link.
  4216. **/
  4217. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
  4218. {
  4219. s32 ret_val = 0;
  4220. u32 bank = 0;
  4221. u32 status;
  4222. e1000e_get_cfg_done_generic(hw);
  4223. /* Wait for indication from h/w that it has completed basic config */
  4224. if (hw->mac.type >= e1000_ich10lan) {
  4225. e1000_lan_init_done_ich8lan(hw);
  4226. } else {
  4227. ret_val = e1000e_get_auto_rd_done(hw);
  4228. if (ret_val) {
  4229. /* When auto config read does not complete, do not
  4230. * return with an error. This can happen in situations
  4231. * where there is no eeprom and prevents getting link.
  4232. */
  4233. e_dbg("Auto Read Done did not complete\n");
  4234. ret_val = 0;
  4235. }
  4236. }
  4237. /* Clear PHY Reset Asserted bit */
  4238. status = er32(STATUS);
  4239. if (status & E1000_STATUS_PHYRA)
  4240. ew32(STATUS, status & ~E1000_STATUS_PHYRA);
  4241. else
  4242. e_dbg("PHY Reset Asserted not set - needs delay\n");
  4243. /* If EEPROM is not marked present, init the IGP 3 PHY manually */
  4244. if (hw->mac.type <= e1000_ich9lan) {
  4245. if (!(er32(EECD) & E1000_EECD_PRES) &&
  4246. (hw->phy.type == e1000_phy_igp_3)) {
  4247. e1000e_phy_init_script_igp3(hw);
  4248. }
  4249. } else {
  4250. if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
  4251. /* Maybe we should do a basic PHY config */
  4252. e_dbg("EEPROM not present\n");
  4253. ret_val = -E1000_ERR_CONFIG;
  4254. }
  4255. }
  4256. return ret_val;
  4257. }
  4258. /**
  4259. * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
  4260. * @hw: pointer to the HW structure
  4261. *
  4262. * In the case of a PHY power down to save power, or to turn off link during a
  4263. * driver unload, or wake on lan is not enabled, remove the link.
  4264. **/
  4265. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
  4266. {
  4267. /* If the management interface is not enabled, then power down */
  4268. if (!(hw->mac.ops.check_mng_mode(hw) ||
  4269. hw->phy.ops.check_reset_block(hw)))
  4270. e1000_power_down_phy_copper(hw);
  4271. }
  4272. /**
  4273. * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
  4274. * @hw: pointer to the HW structure
  4275. *
  4276. * Clears hardware counters specific to the silicon family and calls
  4277. * clear_hw_cntrs_generic to clear all general purpose counters.
  4278. **/
  4279. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
  4280. {
  4281. u16 phy_data;
  4282. s32 ret_val;
  4283. e1000e_clear_hw_cntrs_base(hw);
  4284. er32(ALGNERRC);
  4285. er32(RXERRC);
  4286. er32(TNCRS);
  4287. er32(CEXTERR);
  4288. er32(TSCTC);
  4289. er32(TSCTFC);
  4290. er32(MGTPRC);
  4291. er32(MGTPDC);
  4292. er32(MGTPTC);
  4293. er32(IAC);
  4294. er32(ICRXOC);
  4295. /* Clear PHY statistics registers */
  4296. if ((hw->phy.type == e1000_phy_82578) ||
  4297. (hw->phy.type == e1000_phy_82579) ||
  4298. (hw->phy.type == e1000_phy_i217) ||
  4299. (hw->phy.type == e1000_phy_82577)) {
  4300. ret_val = hw->phy.ops.acquire(hw);
  4301. if (ret_val)
  4302. return;
  4303. ret_val = hw->phy.ops.set_page(hw,
  4304. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  4305. if (ret_val)
  4306. goto release;
  4307. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  4308. hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  4309. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  4310. hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  4311. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  4312. hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  4313. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  4314. hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  4315. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  4316. hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  4317. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  4318. hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  4319. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  4320. hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  4321. release:
  4322. hw->phy.ops.release(hw);
  4323. }
  4324. }
  4325. static const struct e1000_mac_operations ich8_mac_ops = {
  4326. /* check_mng_mode dependent on mac type */
  4327. .check_for_link = e1000_check_for_copper_link_ich8lan,
  4328. /* cleanup_led dependent on mac type */
  4329. .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
  4330. .get_bus_info = e1000_get_bus_info_ich8lan,
  4331. .set_lan_id = e1000_set_lan_id_single_port,
  4332. .get_link_up_info = e1000_get_link_up_info_ich8lan,
  4333. /* led_on dependent on mac type */
  4334. /* led_off dependent on mac type */
  4335. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  4336. .reset_hw = e1000_reset_hw_ich8lan,
  4337. .init_hw = e1000_init_hw_ich8lan,
  4338. .setup_link = e1000_setup_link_ich8lan,
  4339. .setup_physical_interface = e1000_setup_copper_link_ich8lan,
  4340. /* id_led_init dependent on mac type */
  4341. .config_collision_dist = e1000e_config_collision_dist_generic,
  4342. .rar_set = e1000e_rar_set_generic,
  4343. .rar_get_count = e1000e_rar_get_count_generic,
  4344. };
  4345. static const struct e1000_phy_operations ich8_phy_ops = {
  4346. .acquire = e1000_acquire_swflag_ich8lan,
  4347. .check_reset_block = e1000_check_reset_block_ich8lan,
  4348. .commit = NULL,
  4349. .get_cfg_done = e1000_get_cfg_done_ich8lan,
  4350. .get_cable_length = e1000e_get_cable_length_igp_2,
  4351. .read_reg = e1000e_read_phy_reg_igp,
  4352. .release = e1000_release_swflag_ich8lan,
  4353. .reset = e1000_phy_hw_reset_ich8lan,
  4354. .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
  4355. .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
  4356. .write_reg = e1000e_write_phy_reg_igp,
  4357. };
  4358. static const struct e1000_nvm_operations ich8_nvm_ops = {
  4359. .acquire = e1000_acquire_nvm_ich8lan,
  4360. .read = e1000_read_nvm_ich8lan,
  4361. .release = e1000_release_nvm_ich8lan,
  4362. .reload = e1000e_reload_nvm_generic,
  4363. .update = e1000_update_nvm_checksum_ich8lan,
  4364. .valid_led_default = e1000_valid_led_default_ich8lan,
  4365. .validate = e1000_validate_nvm_checksum_ich8lan,
  4366. .write = e1000_write_nvm_ich8lan,
  4367. };
  4368. const struct e1000_info e1000_ich8_info = {
  4369. .mac = e1000_ich8lan,
  4370. .flags = FLAG_HAS_WOL
  4371. | FLAG_IS_ICH
  4372. | FLAG_HAS_CTRLEXT_ON_LOAD
  4373. | FLAG_HAS_AMT
  4374. | FLAG_HAS_FLASH
  4375. | FLAG_APME_IN_WUC,
  4376. .pba = 8,
  4377. .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
  4378. .get_variants = e1000_get_variants_ich8lan,
  4379. .mac_ops = &ich8_mac_ops,
  4380. .phy_ops = &ich8_phy_ops,
  4381. .nvm_ops = &ich8_nvm_ops,
  4382. };
  4383. const struct e1000_info e1000_ich9_info = {
  4384. .mac = e1000_ich9lan,
  4385. .flags = FLAG_HAS_JUMBO_FRAMES
  4386. | FLAG_IS_ICH
  4387. | FLAG_HAS_WOL
  4388. | FLAG_HAS_CTRLEXT_ON_LOAD
  4389. | FLAG_HAS_AMT
  4390. | FLAG_HAS_FLASH
  4391. | FLAG_APME_IN_WUC,
  4392. .pba = 18,
  4393. .max_hw_frame_size = DEFAULT_JUMBO,
  4394. .get_variants = e1000_get_variants_ich8lan,
  4395. .mac_ops = &ich8_mac_ops,
  4396. .phy_ops = &ich8_phy_ops,
  4397. .nvm_ops = &ich8_nvm_ops,
  4398. };
  4399. const struct e1000_info e1000_ich10_info = {
  4400. .mac = e1000_ich10lan,
  4401. .flags = FLAG_HAS_JUMBO_FRAMES
  4402. | FLAG_IS_ICH
  4403. | FLAG_HAS_WOL
  4404. | FLAG_HAS_CTRLEXT_ON_LOAD
  4405. | FLAG_HAS_AMT
  4406. | FLAG_HAS_FLASH
  4407. | FLAG_APME_IN_WUC,
  4408. .pba = 18,
  4409. .max_hw_frame_size = DEFAULT_JUMBO,
  4410. .get_variants = e1000_get_variants_ich8lan,
  4411. .mac_ops = &ich8_mac_ops,
  4412. .phy_ops = &ich8_phy_ops,
  4413. .nvm_ops = &ich8_nvm_ops,
  4414. };
  4415. const struct e1000_info e1000_pch_info = {
  4416. .mac = e1000_pchlan,
  4417. .flags = FLAG_IS_ICH
  4418. | FLAG_HAS_WOL
  4419. | FLAG_HAS_CTRLEXT_ON_LOAD
  4420. | FLAG_HAS_AMT
  4421. | FLAG_HAS_FLASH
  4422. | FLAG_HAS_JUMBO_FRAMES
  4423. | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
  4424. | FLAG_APME_IN_WUC,
  4425. .flags2 = FLAG2_HAS_PHY_STATS,
  4426. .pba = 26,
  4427. .max_hw_frame_size = 4096,
  4428. .get_variants = e1000_get_variants_ich8lan,
  4429. .mac_ops = &ich8_mac_ops,
  4430. .phy_ops = &ich8_phy_ops,
  4431. .nvm_ops = &ich8_nvm_ops,
  4432. };
  4433. const struct e1000_info e1000_pch2_info = {
  4434. .mac = e1000_pch2lan,
  4435. .flags = FLAG_IS_ICH
  4436. | FLAG_HAS_WOL
  4437. | FLAG_HAS_HW_TIMESTAMP
  4438. | FLAG_HAS_CTRLEXT_ON_LOAD
  4439. | FLAG_HAS_AMT
  4440. | FLAG_HAS_FLASH
  4441. | FLAG_HAS_JUMBO_FRAMES
  4442. | FLAG_APME_IN_WUC,
  4443. .flags2 = FLAG2_HAS_PHY_STATS
  4444. | FLAG2_HAS_EEE,
  4445. .pba = 26,
  4446. .max_hw_frame_size = 9018,
  4447. .get_variants = e1000_get_variants_ich8lan,
  4448. .mac_ops = &ich8_mac_ops,
  4449. .phy_ops = &ich8_phy_ops,
  4450. .nvm_ops = &ich8_nvm_ops,
  4451. };
  4452. const struct e1000_info e1000_pch_lpt_info = {
  4453. .mac = e1000_pch_lpt,
  4454. .flags = FLAG_IS_ICH
  4455. | FLAG_HAS_WOL
  4456. | FLAG_HAS_HW_TIMESTAMP
  4457. | FLAG_HAS_CTRLEXT_ON_LOAD
  4458. | FLAG_HAS_AMT
  4459. | FLAG_HAS_FLASH
  4460. | FLAG_HAS_JUMBO_FRAMES
  4461. | FLAG_APME_IN_WUC,
  4462. .flags2 = FLAG2_HAS_PHY_STATS
  4463. | FLAG2_HAS_EEE,
  4464. .pba = 26,
  4465. .max_hw_frame_size = 9018,
  4466. .get_variants = e1000_get_variants_ich8lan,
  4467. .mac_ops = &ich8_mac_ops,
  4468. .phy_ops = &ich8_phy_ops,
  4469. .nvm_ops = &ich8_nvm_ops,
  4470. };