ich8lan.c 71 KB

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