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