ich8lan.c 96 KB

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