ich8lan.c 116 KB

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