ich8lan.c 87 KB

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