ich8lan.c 95 KB

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