82571.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2012 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. * 82571EB Gigabit Ethernet Controller
  23. * 82571EB Gigabit Ethernet Controller (Copper)
  24. * 82571EB Gigabit Ethernet Controller (Fiber)
  25. * 82571EB Dual Port Gigabit Mezzanine Adapter
  26. * 82571EB Quad Port Gigabit Mezzanine Adapter
  27. * 82571PT Gigabit PT Quad Port Server ExpressModule
  28. * 82572EI Gigabit Ethernet Controller (Copper)
  29. * 82572EI Gigabit Ethernet Controller (Fiber)
  30. * 82572EI Gigabit Ethernet Controller
  31. * 82573V Gigabit Ethernet Controller (Copper)
  32. * 82573E Gigabit Ethernet Controller (Copper)
  33. * 82573L Gigabit Ethernet Controller
  34. * 82574L Gigabit Network Connection
  35. * 82583V Gigabit Network Connection
  36. */
  37. #include "e1000.h"
  38. #define ID_LED_RESERVED_F746 0xF746
  39. #define ID_LED_DEFAULT_82573 ((ID_LED_DEF1_DEF2 << 12) | \
  40. (ID_LED_OFF1_ON2 << 8) | \
  41. (ID_LED_DEF1_DEF2 << 4) | \
  42. (ID_LED_DEF1_DEF2))
  43. #define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
  44. #define AN_RETRY_COUNT 5 /* Autoneg Retry Count value */
  45. #define E1000_BASE1000T_STATUS 10
  46. #define E1000_IDLE_ERROR_COUNT_MASK 0xFF
  47. #define E1000_RECEIVE_ERROR_COUNTER 21
  48. #define E1000_RECEIVE_ERROR_MAX 0xFFFF
  49. #define E1000_NVM_INIT_CTRL2_MNGM 0x6000 /* Manageability Operation Mode mask */
  50. static s32 e1000_get_phy_id_82571(struct e1000_hw *hw);
  51. static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw);
  52. static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw);
  53. static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw);
  54. static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
  55. u16 words, u16 *data);
  56. static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw);
  57. static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw);
  58. static s32 e1000_setup_link_82571(struct e1000_hw *hw);
  59. static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw);
  60. static void e1000_clear_vfta_82571(struct e1000_hw *hw);
  61. static bool e1000_check_mng_mode_82574(struct e1000_hw *hw);
  62. static s32 e1000_led_on_82574(struct e1000_hw *hw);
  63. static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw);
  64. static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw);
  65. static void e1000_put_hw_semaphore_82573(struct e1000_hw *hw);
  66. static s32 e1000_get_hw_semaphore_82574(struct e1000_hw *hw);
  67. static void e1000_put_hw_semaphore_82574(struct e1000_hw *hw);
  68. static s32 e1000_set_d0_lplu_state_82574(struct e1000_hw *hw, bool active);
  69. static s32 e1000_set_d3_lplu_state_82574(struct e1000_hw *hw, bool active);
  70. /**
  71. * e1000_init_phy_params_82571 - Init PHY func ptrs.
  72. * @hw: pointer to the HW structure
  73. **/
  74. static s32 e1000_init_phy_params_82571(struct e1000_hw *hw)
  75. {
  76. struct e1000_phy_info *phy = &hw->phy;
  77. s32 ret_val;
  78. if (hw->phy.media_type != e1000_media_type_copper) {
  79. phy->type = e1000_phy_none;
  80. return 0;
  81. }
  82. phy->addr = 1;
  83. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  84. phy->reset_delay_us = 100;
  85. phy->ops.power_up = e1000_power_up_phy_copper;
  86. phy->ops.power_down = e1000_power_down_phy_copper_82571;
  87. switch (hw->mac.type) {
  88. case e1000_82571:
  89. case e1000_82572:
  90. phy->type = e1000_phy_igp_2;
  91. break;
  92. case e1000_82573:
  93. phy->type = e1000_phy_m88;
  94. break;
  95. case e1000_82574:
  96. case e1000_82583:
  97. phy->type = e1000_phy_bm;
  98. phy->ops.acquire = e1000_get_hw_semaphore_82574;
  99. phy->ops.release = e1000_put_hw_semaphore_82574;
  100. phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82574;
  101. phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82574;
  102. break;
  103. default:
  104. return -E1000_ERR_PHY;
  105. break;
  106. }
  107. /* This can only be done after all function pointers are setup. */
  108. ret_val = e1000_get_phy_id_82571(hw);
  109. if (ret_val) {
  110. e_dbg("Error getting PHY ID\n");
  111. return ret_val;
  112. }
  113. /* Verify phy id */
  114. switch (hw->mac.type) {
  115. case e1000_82571:
  116. case e1000_82572:
  117. if (phy->id != IGP01E1000_I_PHY_ID)
  118. ret_val = -E1000_ERR_PHY;
  119. break;
  120. case e1000_82573:
  121. if (phy->id != M88E1111_I_PHY_ID)
  122. ret_val = -E1000_ERR_PHY;
  123. break;
  124. case e1000_82574:
  125. case e1000_82583:
  126. if (phy->id != BME1000_E_PHY_ID_R2)
  127. ret_val = -E1000_ERR_PHY;
  128. break;
  129. default:
  130. ret_val = -E1000_ERR_PHY;
  131. break;
  132. }
  133. if (ret_val)
  134. e_dbg("PHY ID unknown: type = 0x%08x\n", phy->id);
  135. return ret_val;
  136. }
  137. /**
  138. * e1000_init_nvm_params_82571 - Init NVM func ptrs.
  139. * @hw: pointer to the HW structure
  140. **/
  141. static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
  142. {
  143. struct e1000_nvm_info *nvm = &hw->nvm;
  144. u32 eecd = er32(EECD);
  145. u16 size;
  146. nvm->opcode_bits = 8;
  147. nvm->delay_usec = 1;
  148. switch (nvm->override) {
  149. case e1000_nvm_override_spi_large:
  150. nvm->page_size = 32;
  151. nvm->address_bits = 16;
  152. break;
  153. case e1000_nvm_override_spi_small:
  154. nvm->page_size = 8;
  155. nvm->address_bits = 8;
  156. break;
  157. default:
  158. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  159. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
  160. break;
  161. }
  162. switch (hw->mac.type) {
  163. case e1000_82573:
  164. case e1000_82574:
  165. case e1000_82583:
  166. if (((eecd >> 15) & 0x3) == 0x3) {
  167. nvm->type = e1000_nvm_flash_hw;
  168. nvm->word_size = 2048;
  169. /*
  170. * Autonomous Flash update bit must be cleared due
  171. * to Flash update issue.
  172. */
  173. eecd &= ~E1000_EECD_AUPDEN;
  174. ew32(EECD, eecd);
  175. break;
  176. }
  177. /* Fall Through */
  178. default:
  179. nvm->type = e1000_nvm_eeprom_spi;
  180. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  181. E1000_EECD_SIZE_EX_SHIFT);
  182. /*
  183. * Added to a constant, "size" becomes the left-shift value
  184. * for setting word_size.
  185. */
  186. size += NVM_WORD_SIZE_BASE_SHIFT;
  187. /* EEPROM access above 16k is unsupported */
  188. if (size > 14)
  189. size = 14;
  190. nvm->word_size = 1 << size;
  191. break;
  192. }
  193. /* Function Pointers */
  194. switch (hw->mac.type) {
  195. case e1000_82574:
  196. case e1000_82583:
  197. nvm->ops.acquire = e1000_get_hw_semaphore_82574;
  198. nvm->ops.release = e1000_put_hw_semaphore_82574;
  199. break;
  200. default:
  201. break;
  202. }
  203. return 0;
  204. }
  205. /**
  206. * e1000_init_mac_params_82571 - Init MAC func ptrs.
  207. * @hw: pointer to the HW structure
  208. **/
  209. static s32 e1000_init_mac_params_82571(struct e1000_hw *hw)
  210. {
  211. struct e1000_mac_info *mac = &hw->mac;
  212. u32 swsm = 0;
  213. u32 swsm2 = 0;
  214. bool force_clear_smbi = false;
  215. /* Set media type and media-dependent function pointers */
  216. switch (hw->adapter->pdev->device) {
  217. case E1000_DEV_ID_82571EB_FIBER:
  218. case E1000_DEV_ID_82572EI_FIBER:
  219. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  220. hw->phy.media_type = e1000_media_type_fiber;
  221. mac->ops.setup_physical_interface =
  222. e1000_setup_fiber_serdes_link_82571;
  223. mac->ops.check_for_link = e1000e_check_for_fiber_link;
  224. mac->ops.get_link_up_info =
  225. e1000e_get_speed_and_duplex_fiber_serdes;
  226. break;
  227. case E1000_DEV_ID_82571EB_SERDES:
  228. case E1000_DEV_ID_82571EB_SERDES_DUAL:
  229. case E1000_DEV_ID_82571EB_SERDES_QUAD:
  230. case E1000_DEV_ID_82572EI_SERDES:
  231. hw->phy.media_type = e1000_media_type_internal_serdes;
  232. mac->ops.setup_physical_interface =
  233. e1000_setup_fiber_serdes_link_82571;
  234. mac->ops.check_for_link = e1000_check_for_serdes_link_82571;
  235. mac->ops.get_link_up_info =
  236. e1000e_get_speed_and_duplex_fiber_serdes;
  237. break;
  238. default:
  239. hw->phy.media_type = e1000_media_type_copper;
  240. mac->ops.setup_physical_interface =
  241. e1000_setup_copper_link_82571;
  242. mac->ops.check_for_link = e1000e_check_for_copper_link;
  243. mac->ops.get_link_up_info = e1000e_get_speed_and_duplex_copper;
  244. break;
  245. }
  246. /* Set mta register count */
  247. mac->mta_reg_count = 128;
  248. /* Set rar entry count */
  249. mac->rar_entry_count = E1000_RAR_ENTRIES;
  250. /* Adaptive IFS supported */
  251. mac->adaptive_ifs = true;
  252. /* MAC-specific function pointers */
  253. switch (hw->mac.type) {
  254. case e1000_82573:
  255. mac->ops.set_lan_id = e1000_set_lan_id_single_port;
  256. mac->ops.check_mng_mode = e1000e_check_mng_mode_generic;
  257. mac->ops.led_on = e1000e_led_on_generic;
  258. mac->ops.blink_led = e1000e_blink_led_generic;
  259. /* FWSM register */
  260. mac->has_fwsm = true;
  261. /*
  262. * ARC supported; valid only if manageability features are
  263. * enabled.
  264. */
  265. mac->arc_subsystem_valid = !!(er32(FWSM) &
  266. E1000_FWSM_MODE_MASK);
  267. break;
  268. case e1000_82574:
  269. case e1000_82583:
  270. mac->ops.set_lan_id = e1000_set_lan_id_single_port;
  271. mac->ops.check_mng_mode = e1000_check_mng_mode_82574;
  272. mac->ops.led_on = e1000_led_on_82574;
  273. break;
  274. default:
  275. mac->ops.check_mng_mode = e1000e_check_mng_mode_generic;
  276. mac->ops.led_on = e1000e_led_on_generic;
  277. mac->ops.blink_led = e1000e_blink_led_generic;
  278. /* FWSM register */
  279. mac->has_fwsm = true;
  280. break;
  281. }
  282. /*
  283. * Ensure that the inter-port SWSM.SMBI lock bit is clear before
  284. * first NVM or PHY access. This should be done for single-port
  285. * devices, and for one port only on dual-port devices so that
  286. * for those devices we can still use the SMBI lock to synchronize
  287. * inter-port accesses to the PHY & NVM.
  288. */
  289. switch (hw->mac.type) {
  290. case e1000_82571:
  291. case e1000_82572:
  292. swsm2 = er32(SWSM2);
  293. if (!(swsm2 & E1000_SWSM2_LOCK)) {
  294. /* Only do this for the first interface on this card */
  295. ew32(SWSM2, swsm2 | E1000_SWSM2_LOCK);
  296. force_clear_smbi = true;
  297. } else {
  298. force_clear_smbi = false;
  299. }
  300. break;
  301. default:
  302. force_clear_smbi = true;
  303. break;
  304. }
  305. if (force_clear_smbi) {
  306. /* Make sure SWSM.SMBI is clear */
  307. swsm = er32(SWSM);
  308. if (swsm & E1000_SWSM_SMBI) {
  309. /* This bit should not be set on a first interface, and
  310. * indicates that the bootagent or EFI code has
  311. * improperly left this bit enabled
  312. */
  313. e_dbg("Please update your 82571 Bootagent\n");
  314. }
  315. ew32(SWSM, swsm & ~E1000_SWSM_SMBI);
  316. }
  317. /*
  318. * Initialize device specific counter of SMBI acquisition
  319. * timeouts.
  320. */
  321. hw->dev_spec.e82571.smb_counter = 0;
  322. return 0;
  323. }
  324. static s32 e1000_get_variants_82571(struct e1000_adapter *adapter)
  325. {
  326. struct e1000_hw *hw = &adapter->hw;
  327. static int global_quad_port_a; /* global port a indication */
  328. struct pci_dev *pdev = adapter->pdev;
  329. int is_port_b = er32(STATUS) & E1000_STATUS_FUNC_1;
  330. s32 rc;
  331. rc = e1000_init_mac_params_82571(hw);
  332. if (rc)
  333. return rc;
  334. rc = e1000_init_nvm_params_82571(hw);
  335. if (rc)
  336. return rc;
  337. rc = e1000_init_phy_params_82571(hw);
  338. if (rc)
  339. return rc;
  340. /* tag quad port adapters first, it's used below */
  341. switch (pdev->device) {
  342. case E1000_DEV_ID_82571EB_QUAD_COPPER:
  343. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  344. case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:
  345. case E1000_DEV_ID_82571PT_QUAD_COPPER:
  346. adapter->flags |= FLAG_IS_QUAD_PORT;
  347. /* mark the first port */
  348. if (global_quad_port_a == 0)
  349. adapter->flags |= FLAG_IS_QUAD_PORT_A;
  350. /* Reset for multiple quad port adapters */
  351. global_quad_port_a++;
  352. if (global_quad_port_a == 4)
  353. global_quad_port_a = 0;
  354. break;
  355. default:
  356. break;
  357. }
  358. switch (adapter->hw.mac.type) {
  359. case e1000_82571:
  360. /* these dual ports don't have WoL on port B at all */
  361. if (((pdev->device == E1000_DEV_ID_82571EB_FIBER) ||
  362. (pdev->device == E1000_DEV_ID_82571EB_SERDES) ||
  363. (pdev->device == E1000_DEV_ID_82571EB_COPPER)) &&
  364. (is_port_b))
  365. adapter->flags &= ~FLAG_HAS_WOL;
  366. /* quad ports only support WoL on port A */
  367. if (adapter->flags & FLAG_IS_QUAD_PORT &&
  368. (!(adapter->flags & FLAG_IS_QUAD_PORT_A)))
  369. adapter->flags &= ~FLAG_HAS_WOL;
  370. /* Does not support WoL on any port */
  371. if (pdev->device == E1000_DEV_ID_82571EB_SERDES_QUAD)
  372. adapter->flags &= ~FLAG_HAS_WOL;
  373. break;
  374. case e1000_82573:
  375. if (pdev->device == E1000_DEV_ID_82573L) {
  376. adapter->flags |= FLAG_HAS_JUMBO_FRAMES;
  377. adapter->max_hw_frame_size = DEFAULT_JUMBO;
  378. }
  379. break;
  380. default:
  381. break;
  382. }
  383. return 0;
  384. }
  385. /**
  386. * e1000_get_phy_id_82571 - Retrieve the PHY ID and revision
  387. * @hw: pointer to the HW structure
  388. *
  389. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  390. * revision in the hardware structure.
  391. **/
  392. static s32 e1000_get_phy_id_82571(struct e1000_hw *hw)
  393. {
  394. struct e1000_phy_info *phy = &hw->phy;
  395. s32 ret_val;
  396. u16 phy_id = 0;
  397. switch (hw->mac.type) {
  398. case e1000_82571:
  399. case e1000_82572:
  400. /*
  401. * The 82571 firmware may still be configuring the PHY.
  402. * In this case, we cannot access the PHY until the
  403. * configuration is done. So we explicitly set the
  404. * PHY ID.
  405. */
  406. phy->id = IGP01E1000_I_PHY_ID;
  407. break;
  408. case e1000_82573:
  409. return e1000e_get_phy_id(hw);
  410. break;
  411. case e1000_82574:
  412. case e1000_82583:
  413. ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
  414. if (ret_val)
  415. return ret_val;
  416. phy->id = (u32)(phy_id << 16);
  417. udelay(20);
  418. ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
  419. if (ret_val)
  420. return ret_val;
  421. phy->id |= (u32)(phy_id);
  422. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  423. break;
  424. default:
  425. return -E1000_ERR_PHY;
  426. break;
  427. }
  428. return 0;
  429. }
  430. /**
  431. * e1000_get_hw_semaphore_82571 - Acquire hardware semaphore
  432. * @hw: pointer to the HW structure
  433. *
  434. * Acquire the HW semaphore to access the PHY or NVM
  435. **/
  436. static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw)
  437. {
  438. u32 swsm;
  439. s32 sw_timeout = hw->nvm.word_size + 1;
  440. s32 fw_timeout = hw->nvm.word_size + 1;
  441. s32 i = 0;
  442. /*
  443. * If we have timedout 3 times on trying to acquire
  444. * the inter-port SMBI semaphore, there is old code
  445. * operating on the other port, and it is not
  446. * releasing SMBI. Modify the number of times that
  447. * we try for the semaphore to interwork with this
  448. * older code.
  449. */
  450. if (hw->dev_spec.e82571.smb_counter > 2)
  451. sw_timeout = 1;
  452. /* Get the SW semaphore */
  453. while (i < sw_timeout) {
  454. swsm = er32(SWSM);
  455. if (!(swsm & E1000_SWSM_SMBI))
  456. break;
  457. udelay(50);
  458. i++;
  459. }
  460. if (i == sw_timeout) {
  461. e_dbg("Driver can't access device - SMBI bit is set.\n");
  462. hw->dev_spec.e82571.smb_counter++;
  463. }
  464. /* Get the FW semaphore. */
  465. for (i = 0; i < fw_timeout; i++) {
  466. swsm = er32(SWSM);
  467. ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
  468. /* Semaphore acquired if bit latched */
  469. if (er32(SWSM) & E1000_SWSM_SWESMBI)
  470. break;
  471. udelay(50);
  472. }
  473. if (i == fw_timeout) {
  474. /* Release semaphores */
  475. e1000_put_hw_semaphore_82571(hw);
  476. e_dbg("Driver can't access the NVM\n");
  477. return -E1000_ERR_NVM;
  478. }
  479. return 0;
  480. }
  481. /**
  482. * e1000_put_hw_semaphore_82571 - Release hardware semaphore
  483. * @hw: pointer to the HW structure
  484. *
  485. * Release hardware semaphore used to access the PHY or NVM
  486. **/
  487. static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw)
  488. {
  489. u32 swsm;
  490. swsm = er32(SWSM);
  491. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  492. ew32(SWSM, swsm);
  493. }
  494. /**
  495. * e1000_get_hw_semaphore_82573 - Acquire hardware semaphore
  496. * @hw: pointer to the HW structure
  497. *
  498. * Acquire the HW semaphore during reset.
  499. *
  500. **/
  501. static s32 e1000_get_hw_semaphore_82573(struct e1000_hw *hw)
  502. {
  503. u32 extcnf_ctrl;
  504. s32 i = 0;
  505. extcnf_ctrl = er32(EXTCNF_CTRL);
  506. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  507. do {
  508. ew32(EXTCNF_CTRL, extcnf_ctrl);
  509. extcnf_ctrl = er32(EXTCNF_CTRL);
  510. if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
  511. break;
  512. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  513. usleep_range(2000, 4000);
  514. i++;
  515. } while (i < MDIO_OWNERSHIP_TIMEOUT);
  516. if (i == MDIO_OWNERSHIP_TIMEOUT) {
  517. /* Release semaphores */
  518. e1000_put_hw_semaphore_82573(hw);
  519. e_dbg("Driver can't access the PHY\n");
  520. return -E1000_ERR_PHY;
  521. }
  522. return 0;
  523. }
  524. /**
  525. * e1000_put_hw_semaphore_82573 - Release hardware semaphore
  526. * @hw: pointer to the HW structure
  527. *
  528. * Release hardware semaphore used during reset.
  529. *
  530. **/
  531. static void e1000_put_hw_semaphore_82573(struct e1000_hw *hw)
  532. {
  533. u32 extcnf_ctrl;
  534. extcnf_ctrl = er32(EXTCNF_CTRL);
  535. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  536. ew32(EXTCNF_CTRL, extcnf_ctrl);
  537. }
  538. static DEFINE_MUTEX(swflag_mutex);
  539. /**
  540. * e1000_get_hw_semaphore_82574 - Acquire hardware semaphore
  541. * @hw: pointer to the HW structure
  542. *
  543. * Acquire the HW semaphore to access the PHY or NVM.
  544. *
  545. **/
  546. static s32 e1000_get_hw_semaphore_82574(struct e1000_hw *hw)
  547. {
  548. s32 ret_val;
  549. mutex_lock(&swflag_mutex);
  550. ret_val = e1000_get_hw_semaphore_82573(hw);
  551. if (ret_val)
  552. mutex_unlock(&swflag_mutex);
  553. return ret_val;
  554. }
  555. /**
  556. * e1000_put_hw_semaphore_82574 - Release hardware semaphore
  557. * @hw: pointer to the HW structure
  558. *
  559. * Release hardware semaphore used to access the PHY or NVM
  560. *
  561. **/
  562. static void e1000_put_hw_semaphore_82574(struct e1000_hw *hw)
  563. {
  564. e1000_put_hw_semaphore_82573(hw);
  565. mutex_unlock(&swflag_mutex);
  566. }
  567. /**
  568. * e1000_set_d0_lplu_state_82574 - Set Low Power Linkup D0 state
  569. * @hw: pointer to the HW structure
  570. * @active: true to enable LPLU, false to disable
  571. *
  572. * Sets the LPLU D0 state according to the active flag.
  573. * LPLU will not be activated unless the
  574. * device autonegotiation advertisement meets standards of
  575. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  576. * This is a function pointer entry point only called by
  577. * PHY setup routines.
  578. **/
  579. static s32 e1000_set_d0_lplu_state_82574(struct e1000_hw *hw, bool active)
  580. {
  581. u16 data = er32(POEMB);
  582. if (active)
  583. data |= E1000_PHY_CTRL_D0A_LPLU;
  584. else
  585. data &= ~E1000_PHY_CTRL_D0A_LPLU;
  586. ew32(POEMB, data);
  587. return 0;
  588. }
  589. /**
  590. * e1000_set_d3_lplu_state_82574 - Sets low power link up state for D3
  591. * @hw: pointer to the HW structure
  592. * @active: boolean used to enable/disable lplu
  593. *
  594. * The low power link up (lplu) state is set to the power management level D3
  595. * when active is true, else clear lplu for D3. LPLU
  596. * is used during Dx states where the power conservation is most important.
  597. * During driver activity, SmartSpeed should be enabled so performance is
  598. * maintained.
  599. **/
  600. static s32 e1000_set_d3_lplu_state_82574(struct e1000_hw *hw, bool active)
  601. {
  602. u16 data = er32(POEMB);
  603. if (!active) {
  604. data &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  605. } else if ((hw->phy.autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  606. (hw->phy.autoneg_advertised == E1000_ALL_NOT_GIG) ||
  607. (hw->phy.autoneg_advertised == E1000_ALL_10_SPEED)) {
  608. data |= E1000_PHY_CTRL_NOND0A_LPLU;
  609. }
  610. ew32(POEMB, data);
  611. return 0;
  612. }
  613. /**
  614. * e1000_acquire_nvm_82571 - Request for access to the EEPROM
  615. * @hw: pointer to the HW structure
  616. *
  617. * To gain access to the EEPROM, first we must obtain a hardware semaphore.
  618. * Then for non-82573 hardware, set the EEPROM access request bit and wait
  619. * for EEPROM access grant bit. If the access grant bit is not set, release
  620. * hardware semaphore.
  621. **/
  622. static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw)
  623. {
  624. s32 ret_val;
  625. ret_val = e1000_get_hw_semaphore_82571(hw);
  626. if (ret_val)
  627. return ret_val;
  628. switch (hw->mac.type) {
  629. case e1000_82573:
  630. break;
  631. default:
  632. ret_val = e1000e_acquire_nvm(hw);
  633. break;
  634. }
  635. if (ret_val)
  636. e1000_put_hw_semaphore_82571(hw);
  637. return ret_val;
  638. }
  639. /**
  640. * e1000_release_nvm_82571 - Release exclusive access to EEPROM
  641. * @hw: pointer to the HW structure
  642. *
  643. * Stop any current commands to the EEPROM and clear the EEPROM request bit.
  644. **/
  645. static void e1000_release_nvm_82571(struct e1000_hw *hw)
  646. {
  647. e1000e_release_nvm(hw);
  648. e1000_put_hw_semaphore_82571(hw);
  649. }
  650. /**
  651. * e1000_write_nvm_82571 - Write to EEPROM using appropriate interface
  652. * @hw: pointer to the HW structure
  653. * @offset: offset within the EEPROM to be written to
  654. * @words: number of words to write
  655. * @data: 16 bit word(s) to be written to the EEPROM
  656. *
  657. * For non-82573 silicon, write data to EEPROM at offset using SPI interface.
  658. *
  659. * If e1000e_update_nvm_checksum is not called after this function, the
  660. * EEPROM will most likely contain an invalid checksum.
  661. **/
  662. static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset, u16 words,
  663. u16 *data)
  664. {
  665. s32 ret_val;
  666. switch (hw->mac.type) {
  667. case e1000_82573:
  668. case e1000_82574:
  669. case e1000_82583:
  670. ret_val = e1000_write_nvm_eewr_82571(hw, offset, words, data);
  671. break;
  672. case e1000_82571:
  673. case e1000_82572:
  674. ret_val = e1000e_write_nvm_spi(hw, offset, words, data);
  675. break;
  676. default:
  677. ret_val = -E1000_ERR_NVM;
  678. break;
  679. }
  680. return ret_val;
  681. }
  682. /**
  683. * e1000_update_nvm_checksum_82571 - Update EEPROM checksum
  684. * @hw: pointer to the HW structure
  685. *
  686. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  687. * up to the checksum. Then calculates the EEPROM checksum and writes the
  688. * value to the EEPROM.
  689. **/
  690. static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw)
  691. {
  692. u32 eecd;
  693. s32 ret_val;
  694. u16 i;
  695. ret_val = e1000e_update_nvm_checksum_generic(hw);
  696. if (ret_val)
  697. return ret_val;
  698. /*
  699. * If our nvm is an EEPROM, then we're done
  700. * otherwise, commit the checksum to the flash NVM.
  701. */
  702. if (hw->nvm.type != e1000_nvm_flash_hw)
  703. return 0;
  704. /* Check for pending operations. */
  705. for (i = 0; i < E1000_FLASH_UPDATES; i++) {
  706. usleep_range(1000, 2000);
  707. if (!(er32(EECD) & E1000_EECD_FLUPD))
  708. break;
  709. }
  710. if (i == E1000_FLASH_UPDATES)
  711. return -E1000_ERR_NVM;
  712. /* Reset the firmware if using STM opcode. */
  713. if ((er32(FLOP) & 0xFF00) == E1000_STM_OPCODE) {
  714. /*
  715. * The enabling of and the actual reset must be done
  716. * in two write cycles.
  717. */
  718. ew32(HICR, E1000_HICR_FW_RESET_ENABLE);
  719. e1e_flush();
  720. ew32(HICR, E1000_HICR_FW_RESET);
  721. }
  722. /* Commit the write to flash */
  723. eecd = er32(EECD) | E1000_EECD_FLUPD;
  724. ew32(EECD, eecd);
  725. for (i = 0; i < E1000_FLASH_UPDATES; i++) {
  726. usleep_range(1000, 2000);
  727. if (!(er32(EECD) & E1000_EECD_FLUPD))
  728. break;
  729. }
  730. if (i == E1000_FLASH_UPDATES)
  731. return -E1000_ERR_NVM;
  732. return 0;
  733. }
  734. /**
  735. * e1000_validate_nvm_checksum_82571 - Validate EEPROM checksum
  736. * @hw: pointer to the HW structure
  737. *
  738. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  739. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  740. **/
  741. static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw)
  742. {
  743. if (hw->nvm.type == e1000_nvm_flash_hw)
  744. e1000_fix_nvm_checksum_82571(hw);
  745. return e1000e_validate_nvm_checksum_generic(hw);
  746. }
  747. /**
  748. * e1000_write_nvm_eewr_82571 - Write to EEPROM for 82573 silicon
  749. * @hw: pointer to the HW structure
  750. * @offset: offset within the EEPROM to be written to
  751. * @words: number of words to write
  752. * @data: 16 bit word(s) to be written to the EEPROM
  753. *
  754. * After checking for invalid values, poll the EEPROM to ensure the previous
  755. * command has completed before trying to write the next word. After write
  756. * poll for completion.
  757. *
  758. * If e1000e_update_nvm_checksum is not called after this function, the
  759. * EEPROM will most likely contain an invalid checksum.
  760. **/
  761. static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
  762. u16 words, u16 *data)
  763. {
  764. struct e1000_nvm_info *nvm = &hw->nvm;
  765. u32 i, eewr = 0;
  766. s32 ret_val = 0;
  767. /*
  768. * A check for invalid values: offset too large, too many words,
  769. * and not enough words.
  770. */
  771. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  772. (words == 0)) {
  773. e_dbg("nvm parameter(s) out of bounds\n");
  774. return -E1000_ERR_NVM;
  775. }
  776. for (i = 0; i < words; i++) {
  777. eewr = (data[i] << E1000_NVM_RW_REG_DATA) |
  778. ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
  779. E1000_NVM_RW_REG_START;
  780. ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
  781. if (ret_val)
  782. break;
  783. ew32(EEWR, eewr);
  784. ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
  785. if (ret_val)
  786. break;
  787. }
  788. return ret_val;
  789. }
  790. /**
  791. * e1000_get_cfg_done_82571 - Poll for configuration done
  792. * @hw: pointer to the HW structure
  793. *
  794. * Reads the management control register for the config done bit to be set.
  795. **/
  796. static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw)
  797. {
  798. s32 timeout = PHY_CFG_TIMEOUT;
  799. while (timeout) {
  800. if (er32(EEMNGCTL) &
  801. E1000_NVM_CFG_DONE_PORT_0)
  802. break;
  803. usleep_range(1000, 2000);
  804. timeout--;
  805. }
  806. if (!timeout) {
  807. e_dbg("MNG configuration cycle has not completed.\n");
  808. return -E1000_ERR_RESET;
  809. }
  810. return 0;
  811. }
  812. /**
  813. * e1000_set_d0_lplu_state_82571 - Set Low Power Linkup D0 state
  814. * @hw: pointer to the HW structure
  815. * @active: true to enable LPLU, false to disable
  816. *
  817. * Sets the LPLU D0 state according to the active flag. When activating LPLU
  818. * this function also disables smart speed and vice versa. LPLU will not be
  819. * activated unless the device autonegotiation advertisement meets standards
  820. * of either 10 or 10/100 or 10/100/1000 at all duplexes. This is a function
  821. * pointer entry point only called by PHY setup routines.
  822. **/
  823. static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw, bool active)
  824. {
  825. struct e1000_phy_info *phy = &hw->phy;
  826. s32 ret_val;
  827. u16 data;
  828. ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  829. if (ret_val)
  830. return ret_val;
  831. if (active) {
  832. data |= IGP02E1000_PM_D0_LPLU;
  833. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  834. if (ret_val)
  835. return ret_val;
  836. /* When LPLU is enabled, we should disable SmartSpeed */
  837. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  838. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  839. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  840. if (ret_val)
  841. return ret_val;
  842. } else {
  843. data &= ~IGP02E1000_PM_D0_LPLU;
  844. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  845. /*
  846. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  847. * during Dx states where the power conservation is most
  848. * important. During driver activity we should enable
  849. * SmartSpeed, so performance is maintained.
  850. */
  851. if (phy->smart_speed == e1000_smart_speed_on) {
  852. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  853. &data);
  854. if (ret_val)
  855. return ret_val;
  856. data |= IGP01E1000_PSCFR_SMART_SPEED;
  857. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  858. data);
  859. if (ret_val)
  860. return ret_val;
  861. } else if (phy->smart_speed == e1000_smart_speed_off) {
  862. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  863. &data);
  864. if (ret_val)
  865. return ret_val;
  866. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  867. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  868. data);
  869. if (ret_val)
  870. return ret_val;
  871. }
  872. }
  873. return 0;
  874. }
  875. /**
  876. * e1000_reset_hw_82571 - Reset hardware
  877. * @hw: pointer to the HW structure
  878. *
  879. * This resets the hardware into a known state.
  880. **/
  881. static s32 e1000_reset_hw_82571(struct e1000_hw *hw)
  882. {
  883. u32 ctrl, ctrl_ext, eecd;
  884. s32 ret_val;
  885. /*
  886. * Prevent the PCI-E bus from sticking if there is no TLP connection
  887. * on the last TLP read/write transaction when MAC is reset.
  888. */
  889. ret_val = e1000e_disable_pcie_master(hw);
  890. if (ret_val)
  891. e_dbg("PCI-E Master disable polling has failed.\n");
  892. e_dbg("Masking off all interrupts\n");
  893. ew32(IMC, 0xffffffff);
  894. ew32(RCTL, 0);
  895. ew32(TCTL, E1000_TCTL_PSP);
  896. e1e_flush();
  897. usleep_range(10000, 20000);
  898. /*
  899. * Must acquire the MDIO ownership before MAC reset.
  900. * Ownership defaults to firmware after a reset.
  901. */
  902. switch (hw->mac.type) {
  903. case e1000_82573:
  904. ret_val = e1000_get_hw_semaphore_82573(hw);
  905. break;
  906. case e1000_82574:
  907. case e1000_82583:
  908. ret_val = e1000_get_hw_semaphore_82574(hw);
  909. break;
  910. default:
  911. break;
  912. }
  913. if (ret_val)
  914. e_dbg("Cannot acquire MDIO ownership\n");
  915. ctrl = er32(CTRL);
  916. e_dbg("Issuing a global reset to MAC\n");
  917. ew32(CTRL, ctrl | E1000_CTRL_RST);
  918. /* Must release MDIO ownership and mutex after MAC reset. */
  919. switch (hw->mac.type) {
  920. case e1000_82574:
  921. case e1000_82583:
  922. e1000_put_hw_semaphore_82574(hw);
  923. break;
  924. default:
  925. break;
  926. }
  927. if (hw->nvm.type == e1000_nvm_flash_hw) {
  928. udelay(10);
  929. ctrl_ext = er32(CTRL_EXT);
  930. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  931. ew32(CTRL_EXT, ctrl_ext);
  932. e1e_flush();
  933. }
  934. ret_val = e1000e_get_auto_rd_done(hw);
  935. if (ret_val)
  936. /* We don't want to continue accessing MAC registers. */
  937. return ret_val;
  938. /*
  939. * Phy configuration from NVM just starts after EECD_AUTO_RD is set.
  940. * Need to wait for Phy configuration completion before accessing
  941. * NVM and Phy.
  942. */
  943. switch (hw->mac.type) {
  944. case e1000_82571:
  945. case e1000_82572:
  946. /*
  947. * REQ and GNT bits need to be cleared when using AUTO_RD
  948. * to access the EEPROM.
  949. */
  950. eecd = er32(EECD);
  951. eecd &= ~(E1000_EECD_REQ | E1000_EECD_GNT);
  952. ew32(EECD, eecd);
  953. break;
  954. case e1000_82573:
  955. case e1000_82574:
  956. case e1000_82583:
  957. msleep(25);
  958. break;
  959. default:
  960. break;
  961. }
  962. /* Clear any pending interrupt events. */
  963. ew32(IMC, 0xffffffff);
  964. er32(ICR);
  965. if (hw->mac.type == e1000_82571) {
  966. /* Install any alternate MAC address into RAR0 */
  967. ret_val = e1000_check_alt_mac_addr_generic(hw);
  968. if (ret_val)
  969. return ret_val;
  970. e1000e_set_laa_state_82571(hw, true);
  971. }
  972. /* Reinitialize the 82571 serdes link state machine */
  973. if (hw->phy.media_type == e1000_media_type_internal_serdes)
  974. hw->mac.serdes_link_state = e1000_serdes_link_down;
  975. return 0;
  976. }
  977. /**
  978. * e1000_init_hw_82571 - Initialize hardware
  979. * @hw: pointer to the HW structure
  980. *
  981. * This inits the hardware readying it for operation.
  982. **/
  983. static s32 e1000_init_hw_82571(struct e1000_hw *hw)
  984. {
  985. struct e1000_mac_info *mac = &hw->mac;
  986. u32 reg_data;
  987. s32 ret_val;
  988. u16 i, rar_count = mac->rar_entry_count;
  989. e1000_initialize_hw_bits_82571(hw);
  990. /* Initialize identification LED */
  991. ret_val = mac->ops.id_led_init(hw);
  992. if (ret_val)
  993. e_dbg("Error initializing identification LED\n");
  994. /* This is not fatal and we should not stop init due to this */
  995. /* Disabling VLAN filtering */
  996. e_dbg("Initializing the IEEE VLAN\n");
  997. mac->ops.clear_vfta(hw);
  998. /* Setup the receive address. */
  999. /*
  1000. * If, however, a locally administered address was assigned to the
  1001. * 82571, we must reserve a RAR for it to work around an issue where
  1002. * resetting one port will reload the MAC on the other port.
  1003. */
  1004. if (e1000e_get_laa_state_82571(hw))
  1005. rar_count--;
  1006. e1000e_init_rx_addrs(hw, rar_count);
  1007. /* Zero out the Multicast HASH table */
  1008. e_dbg("Zeroing the MTA\n");
  1009. for (i = 0; i < mac->mta_reg_count; i++)
  1010. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  1011. /* Setup link and flow control */
  1012. ret_val = mac->ops.setup_link(hw);
  1013. /* Set the transmit descriptor write-back policy */
  1014. reg_data = er32(TXDCTL(0));
  1015. reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
  1016. E1000_TXDCTL_FULL_TX_DESC_WB |
  1017. E1000_TXDCTL_COUNT_DESC;
  1018. ew32(TXDCTL(0), reg_data);
  1019. /* ...for both queues. */
  1020. switch (mac->type) {
  1021. case e1000_82573:
  1022. e1000e_enable_tx_pkt_filtering(hw);
  1023. /* fall through */
  1024. case e1000_82574:
  1025. case e1000_82583:
  1026. reg_data = er32(GCR);
  1027. reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  1028. ew32(GCR, reg_data);
  1029. break;
  1030. default:
  1031. reg_data = er32(TXDCTL(1));
  1032. reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
  1033. E1000_TXDCTL_FULL_TX_DESC_WB |
  1034. E1000_TXDCTL_COUNT_DESC;
  1035. ew32(TXDCTL(1), reg_data);
  1036. break;
  1037. }
  1038. /*
  1039. * Clear all of the statistics registers (clear on read). It is
  1040. * important that we do this after we have tried to establish link
  1041. * because the symbol error count will increment wildly if there
  1042. * is no link.
  1043. */
  1044. e1000_clear_hw_cntrs_82571(hw);
  1045. return ret_val;
  1046. }
  1047. /**
  1048. * e1000_initialize_hw_bits_82571 - Initialize hardware-dependent bits
  1049. * @hw: pointer to the HW structure
  1050. *
  1051. * Initializes required hardware-dependent bits needed for normal operation.
  1052. **/
  1053. static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw)
  1054. {
  1055. u32 reg;
  1056. /* Transmit Descriptor Control 0 */
  1057. reg = er32(TXDCTL(0));
  1058. reg |= (1 << 22);
  1059. ew32(TXDCTL(0), reg);
  1060. /* Transmit Descriptor Control 1 */
  1061. reg = er32(TXDCTL(1));
  1062. reg |= (1 << 22);
  1063. ew32(TXDCTL(1), reg);
  1064. /* Transmit Arbitration Control 0 */
  1065. reg = er32(TARC(0));
  1066. reg &= ~(0xF << 27); /* 30:27 */
  1067. switch (hw->mac.type) {
  1068. case e1000_82571:
  1069. case e1000_82572:
  1070. reg |= (1 << 23) | (1 << 24) | (1 << 25) | (1 << 26);
  1071. break;
  1072. case e1000_82574:
  1073. case e1000_82583:
  1074. reg |= (1 << 26);
  1075. break;
  1076. default:
  1077. break;
  1078. }
  1079. ew32(TARC(0), reg);
  1080. /* Transmit Arbitration Control 1 */
  1081. reg = er32(TARC(1));
  1082. switch (hw->mac.type) {
  1083. case e1000_82571:
  1084. case e1000_82572:
  1085. reg &= ~((1 << 29) | (1 << 30));
  1086. reg |= (1 << 22) | (1 << 24) | (1 << 25) | (1 << 26);
  1087. if (er32(TCTL) & E1000_TCTL_MULR)
  1088. reg &= ~(1 << 28);
  1089. else
  1090. reg |= (1 << 28);
  1091. ew32(TARC(1), reg);
  1092. break;
  1093. default:
  1094. break;
  1095. }
  1096. /* Device Control */
  1097. switch (hw->mac.type) {
  1098. case e1000_82573:
  1099. case e1000_82574:
  1100. case e1000_82583:
  1101. reg = er32(CTRL);
  1102. reg &= ~(1 << 29);
  1103. ew32(CTRL, reg);
  1104. break;
  1105. default:
  1106. break;
  1107. }
  1108. /* Extended Device Control */
  1109. switch (hw->mac.type) {
  1110. case e1000_82573:
  1111. case e1000_82574:
  1112. case e1000_82583:
  1113. reg = er32(CTRL_EXT);
  1114. reg &= ~(1 << 23);
  1115. reg |= (1 << 22);
  1116. ew32(CTRL_EXT, reg);
  1117. break;
  1118. default:
  1119. break;
  1120. }
  1121. if (hw->mac.type == e1000_82571) {
  1122. reg = er32(PBA_ECC);
  1123. reg |= E1000_PBA_ECC_CORR_EN;
  1124. ew32(PBA_ECC, reg);
  1125. }
  1126. /*
  1127. * Workaround for hardware errata.
  1128. * Ensure that DMA Dynamic Clock gating is disabled on 82571 and 82572
  1129. */
  1130. if ((hw->mac.type == e1000_82571) || (hw->mac.type == e1000_82572)) {
  1131. reg = er32(CTRL_EXT);
  1132. reg &= ~E1000_CTRL_EXT_DMA_DYN_CLK_EN;
  1133. ew32(CTRL_EXT, reg);
  1134. }
  1135. /*
  1136. * Disable IPv6 extension header parsing because some malformed
  1137. * IPv6 headers can hang the Rx.
  1138. */
  1139. if (hw->mac.type <= e1000_82573) {
  1140. reg = er32(RFCTL);
  1141. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  1142. ew32(RFCTL, reg);
  1143. }
  1144. /* PCI-Ex Control Registers */
  1145. switch (hw->mac.type) {
  1146. case e1000_82574:
  1147. case e1000_82583:
  1148. reg = er32(GCR);
  1149. reg |= (1 << 22);
  1150. ew32(GCR, reg);
  1151. /*
  1152. * Workaround for hardware errata.
  1153. * apply workaround for hardware errata documented in errata
  1154. * docs Fixes issue where some error prone or unreliable PCIe
  1155. * completions are occurring, particularly with ASPM enabled.
  1156. * Without fix, issue can cause Tx timeouts.
  1157. */
  1158. reg = er32(GCR2);
  1159. reg |= 1;
  1160. ew32(GCR2, reg);
  1161. break;
  1162. default:
  1163. break;
  1164. }
  1165. }
  1166. /**
  1167. * e1000_clear_vfta_82571 - Clear VLAN filter table
  1168. * @hw: pointer to the HW structure
  1169. *
  1170. * Clears the register array which contains the VLAN filter table by
  1171. * setting all the values to 0.
  1172. **/
  1173. static void e1000_clear_vfta_82571(struct e1000_hw *hw)
  1174. {
  1175. u32 offset;
  1176. u32 vfta_value = 0;
  1177. u32 vfta_offset = 0;
  1178. u32 vfta_bit_in_reg = 0;
  1179. switch (hw->mac.type) {
  1180. case e1000_82573:
  1181. case e1000_82574:
  1182. case e1000_82583:
  1183. if (hw->mng_cookie.vlan_id != 0) {
  1184. /*
  1185. * The VFTA is a 4096b bit-field, each identifying
  1186. * a single VLAN ID. The following operations
  1187. * determine which 32b entry (i.e. offset) into the
  1188. * array we want to set the VLAN ID (i.e. bit) of
  1189. * the manageability unit.
  1190. */
  1191. vfta_offset = (hw->mng_cookie.vlan_id >>
  1192. E1000_VFTA_ENTRY_SHIFT) &
  1193. E1000_VFTA_ENTRY_MASK;
  1194. vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
  1195. E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
  1196. }
  1197. break;
  1198. default:
  1199. break;
  1200. }
  1201. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  1202. /*
  1203. * If the offset we want to clear is the same offset of the
  1204. * manageability VLAN ID, then clear all bits except that of
  1205. * the manageability unit.
  1206. */
  1207. vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
  1208. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, vfta_value);
  1209. e1e_flush();
  1210. }
  1211. }
  1212. /**
  1213. * e1000_check_mng_mode_82574 - Check manageability is enabled
  1214. * @hw: pointer to the HW structure
  1215. *
  1216. * Reads the NVM Initialization Control Word 2 and returns true
  1217. * (>0) if any manageability is enabled, else false (0).
  1218. **/
  1219. static bool e1000_check_mng_mode_82574(struct e1000_hw *hw)
  1220. {
  1221. u16 data;
  1222. e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
  1223. return (data & E1000_NVM_INIT_CTRL2_MNGM) != 0;
  1224. }
  1225. /**
  1226. * e1000_led_on_82574 - Turn LED on
  1227. * @hw: pointer to the HW structure
  1228. *
  1229. * Turn LED on.
  1230. **/
  1231. static s32 e1000_led_on_82574(struct e1000_hw *hw)
  1232. {
  1233. u32 ctrl;
  1234. u32 i;
  1235. ctrl = hw->mac.ledctl_mode2;
  1236. if (!(E1000_STATUS_LU & er32(STATUS))) {
  1237. /*
  1238. * If no link, then turn LED on by setting the invert bit
  1239. * for each LED that's "on" (0x0E) in ledctl_mode2.
  1240. */
  1241. for (i = 0; i < 4; i++)
  1242. if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
  1243. E1000_LEDCTL_MODE_LED_ON)
  1244. ctrl |= (E1000_LEDCTL_LED0_IVRT << (i * 8));
  1245. }
  1246. ew32(LEDCTL, ctrl);
  1247. return 0;
  1248. }
  1249. /**
  1250. * e1000_check_phy_82574 - check 82574 phy hung state
  1251. * @hw: pointer to the HW structure
  1252. *
  1253. * Returns whether phy is hung or not
  1254. **/
  1255. bool e1000_check_phy_82574(struct e1000_hw *hw)
  1256. {
  1257. u16 status_1kbt = 0;
  1258. u16 receive_errors = 0;
  1259. s32 ret_val = 0;
  1260. /*
  1261. * Read PHY Receive Error counter first, if its is max - all F's then
  1262. * read the Base1000T status register If both are max then PHY is hung.
  1263. */
  1264. ret_val = e1e_rphy(hw, E1000_RECEIVE_ERROR_COUNTER, &receive_errors);
  1265. if (ret_val)
  1266. return false;
  1267. if (receive_errors == E1000_RECEIVE_ERROR_MAX) {
  1268. ret_val = e1e_rphy(hw, E1000_BASE1000T_STATUS, &status_1kbt);
  1269. if (ret_val)
  1270. return false;
  1271. if ((status_1kbt & E1000_IDLE_ERROR_COUNT_MASK) ==
  1272. E1000_IDLE_ERROR_COUNT_MASK)
  1273. return true;
  1274. }
  1275. return false;
  1276. }
  1277. /**
  1278. * e1000_setup_link_82571 - Setup flow control and link settings
  1279. * @hw: pointer to the HW structure
  1280. *
  1281. * Determines which flow control settings to use, then configures flow
  1282. * control. Calls the appropriate media-specific link configuration
  1283. * function. Assuming the adapter has a valid link partner, a valid link
  1284. * should be established. Assumes the hardware has previously been reset
  1285. * and the transmitter and receiver are not enabled.
  1286. **/
  1287. static s32 e1000_setup_link_82571(struct e1000_hw *hw)
  1288. {
  1289. /*
  1290. * 82573 does not have a word in the NVM to determine
  1291. * the default flow control setting, so we explicitly
  1292. * set it to full.
  1293. */
  1294. switch (hw->mac.type) {
  1295. case e1000_82573:
  1296. case e1000_82574:
  1297. case e1000_82583:
  1298. if (hw->fc.requested_mode == e1000_fc_default)
  1299. hw->fc.requested_mode = e1000_fc_full;
  1300. break;
  1301. default:
  1302. break;
  1303. }
  1304. return e1000e_setup_link_generic(hw);
  1305. }
  1306. /**
  1307. * e1000_setup_copper_link_82571 - Configure copper link settings
  1308. * @hw: pointer to the HW structure
  1309. *
  1310. * Configures the link for auto-neg or forced speed and duplex. Then we check
  1311. * for link, once link is established calls to configure collision distance
  1312. * and flow control are called.
  1313. **/
  1314. static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw)
  1315. {
  1316. u32 ctrl;
  1317. s32 ret_val;
  1318. ctrl = er32(CTRL);
  1319. ctrl |= E1000_CTRL_SLU;
  1320. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1321. ew32(CTRL, ctrl);
  1322. switch (hw->phy.type) {
  1323. case e1000_phy_m88:
  1324. case e1000_phy_bm:
  1325. ret_val = e1000e_copper_link_setup_m88(hw);
  1326. break;
  1327. case e1000_phy_igp_2:
  1328. ret_val = e1000e_copper_link_setup_igp(hw);
  1329. break;
  1330. default:
  1331. return -E1000_ERR_PHY;
  1332. break;
  1333. }
  1334. if (ret_val)
  1335. return ret_val;
  1336. return e1000e_setup_copper_link(hw);
  1337. }
  1338. /**
  1339. * e1000_setup_fiber_serdes_link_82571 - Setup link for fiber/serdes
  1340. * @hw: pointer to the HW structure
  1341. *
  1342. * Configures collision distance and flow control for fiber and serdes links.
  1343. * Upon successful setup, poll for link.
  1344. **/
  1345. static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw)
  1346. {
  1347. switch (hw->mac.type) {
  1348. case e1000_82571:
  1349. case e1000_82572:
  1350. /*
  1351. * If SerDes loopback mode is entered, there is no form
  1352. * of reset to take the adapter out of that mode. So we
  1353. * have to explicitly take the adapter out of loopback
  1354. * mode. This prevents drivers from twiddling their thumbs
  1355. * if another tool failed to take it out of loopback mode.
  1356. */
  1357. ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1358. break;
  1359. default:
  1360. break;
  1361. }
  1362. return e1000e_setup_fiber_serdes_link(hw);
  1363. }
  1364. /**
  1365. * e1000_check_for_serdes_link_82571 - Check for link (Serdes)
  1366. * @hw: pointer to the HW structure
  1367. *
  1368. * Reports the link state as up or down.
  1369. *
  1370. * If autonegotiation is supported by the link partner, the link state is
  1371. * determined by the result of autonegotiation. This is the most likely case.
  1372. * If autonegotiation is not supported by the link partner, and the link
  1373. * has a valid signal, force the link up.
  1374. *
  1375. * The link state is represented internally here by 4 states:
  1376. *
  1377. * 1) down
  1378. * 2) autoneg_progress
  1379. * 3) autoneg_complete (the link successfully autonegotiated)
  1380. * 4) forced_up (the link has been forced up, it did not autonegotiate)
  1381. *
  1382. **/
  1383. static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw)
  1384. {
  1385. struct e1000_mac_info *mac = &hw->mac;
  1386. u32 rxcw;
  1387. u32 ctrl;
  1388. u32 status;
  1389. u32 txcw;
  1390. u32 i;
  1391. s32 ret_val = 0;
  1392. ctrl = er32(CTRL);
  1393. status = er32(STATUS);
  1394. rxcw = er32(RXCW);
  1395. /* SYNCH bit and IV bit are sticky */
  1396. udelay(10);
  1397. rxcw = er32(RXCW);
  1398. if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
  1399. /* Receiver is synchronized with no invalid bits. */
  1400. switch (mac->serdes_link_state) {
  1401. case e1000_serdes_link_autoneg_complete:
  1402. if (!(status & E1000_STATUS_LU)) {
  1403. /*
  1404. * We have lost link, retry autoneg before
  1405. * reporting link failure
  1406. */
  1407. mac->serdes_link_state =
  1408. e1000_serdes_link_autoneg_progress;
  1409. mac->serdes_has_link = false;
  1410. e_dbg("AN_UP -> AN_PROG\n");
  1411. } else {
  1412. mac->serdes_has_link = true;
  1413. }
  1414. break;
  1415. case e1000_serdes_link_forced_up:
  1416. /*
  1417. * If we are receiving /C/ ordered sets, re-enable
  1418. * auto-negotiation in the TXCW register and disable
  1419. * forced link in the Device Control register in an
  1420. * attempt to auto-negotiate with our link partner.
  1421. * If the partner code word is null, stop forcing
  1422. * and restart auto negotiation.
  1423. */
  1424. if ((rxcw & E1000_RXCW_C) || !(rxcw & E1000_RXCW_CW)) {
  1425. /* Enable autoneg, and unforce link up */
  1426. ew32(TXCW, mac->txcw);
  1427. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  1428. mac->serdes_link_state =
  1429. e1000_serdes_link_autoneg_progress;
  1430. mac->serdes_has_link = false;
  1431. e_dbg("FORCED_UP -> AN_PROG\n");
  1432. } else {
  1433. mac->serdes_has_link = true;
  1434. }
  1435. break;
  1436. case e1000_serdes_link_autoneg_progress:
  1437. if (rxcw & E1000_RXCW_C) {
  1438. /*
  1439. * We received /C/ ordered sets, meaning the
  1440. * link partner has autonegotiated, and we can
  1441. * trust the Link Up (LU) status bit.
  1442. */
  1443. if (status & E1000_STATUS_LU) {
  1444. mac->serdes_link_state =
  1445. e1000_serdes_link_autoneg_complete;
  1446. e_dbg("AN_PROG -> AN_UP\n");
  1447. mac->serdes_has_link = true;
  1448. } else {
  1449. /* Autoneg completed, but failed. */
  1450. mac->serdes_link_state =
  1451. e1000_serdes_link_down;
  1452. e_dbg("AN_PROG -> DOWN\n");
  1453. }
  1454. } else {
  1455. /*
  1456. * The link partner did not autoneg.
  1457. * Force link up and full duplex, and change
  1458. * state to forced.
  1459. */
  1460. ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  1461. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  1462. ew32(CTRL, ctrl);
  1463. /* Configure Flow Control after link up. */
  1464. ret_val = e1000e_config_fc_after_link_up(hw);
  1465. if (ret_val) {
  1466. e_dbg("Error config flow control\n");
  1467. break;
  1468. }
  1469. mac->serdes_link_state =
  1470. e1000_serdes_link_forced_up;
  1471. mac->serdes_has_link = true;
  1472. e_dbg("AN_PROG -> FORCED_UP\n");
  1473. }
  1474. break;
  1475. case e1000_serdes_link_down:
  1476. default:
  1477. /*
  1478. * The link was down but the receiver has now gained
  1479. * valid sync, so lets see if we can bring the link
  1480. * up.
  1481. */
  1482. ew32(TXCW, mac->txcw);
  1483. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  1484. mac->serdes_link_state =
  1485. e1000_serdes_link_autoneg_progress;
  1486. mac->serdes_has_link = false;
  1487. e_dbg("DOWN -> AN_PROG\n");
  1488. break;
  1489. }
  1490. } else {
  1491. if (!(rxcw & E1000_RXCW_SYNCH)) {
  1492. mac->serdes_has_link = false;
  1493. mac->serdes_link_state = e1000_serdes_link_down;
  1494. e_dbg("ANYSTATE -> DOWN\n");
  1495. } else {
  1496. /*
  1497. * Check several times, if SYNCH bit and CONFIG
  1498. * bit both are consistently 1 then simply ignore
  1499. * the IV bit and restart Autoneg
  1500. */
  1501. for (i = 0; i < AN_RETRY_COUNT; i++) {
  1502. udelay(10);
  1503. rxcw = er32(RXCW);
  1504. if ((rxcw & E1000_RXCW_SYNCH) &&
  1505. (rxcw & E1000_RXCW_C))
  1506. continue;
  1507. if (rxcw & E1000_RXCW_IV) {
  1508. mac->serdes_has_link = false;
  1509. mac->serdes_link_state =
  1510. e1000_serdes_link_down;
  1511. e_dbg("ANYSTATE -> DOWN\n");
  1512. break;
  1513. }
  1514. }
  1515. if (i == AN_RETRY_COUNT) {
  1516. txcw = er32(TXCW);
  1517. txcw |= E1000_TXCW_ANE;
  1518. ew32(TXCW, txcw);
  1519. mac->serdes_link_state =
  1520. e1000_serdes_link_autoneg_progress;
  1521. mac->serdes_has_link = false;
  1522. e_dbg("ANYSTATE -> AN_PROG\n");
  1523. }
  1524. }
  1525. }
  1526. return ret_val;
  1527. }
  1528. /**
  1529. * e1000_valid_led_default_82571 - Verify a valid default LED config
  1530. * @hw: pointer to the HW structure
  1531. * @data: pointer to the NVM (EEPROM)
  1532. *
  1533. * Read the EEPROM for the current default LED configuration. If the
  1534. * LED configuration is not valid, set to a valid LED configuration.
  1535. **/
  1536. static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data)
  1537. {
  1538. s32 ret_val;
  1539. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1540. if (ret_val) {
  1541. e_dbg("NVM Read Error\n");
  1542. return ret_val;
  1543. }
  1544. switch (hw->mac.type) {
  1545. case e1000_82573:
  1546. case e1000_82574:
  1547. case e1000_82583:
  1548. if (*data == ID_LED_RESERVED_F746)
  1549. *data = ID_LED_DEFAULT_82573;
  1550. break;
  1551. default:
  1552. if (*data == ID_LED_RESERVED_0000 ||
  1553. *data == ID_LED_RESERVED_FFFF)
  1554. *data = ID_LED_DEFAULT;
  1555. break;
  1556. }
  1557. return 0;
  1558. }
  1559. /**
  1560. * e1000e_get_laa_state_82571 - Get locally administered address state
  1561. * @hw: pointer to the HW structure
  1562. *
  1563. * Retrieve and return the current locally administered address state.
  1564. **/
  1565. bool e1000e_get_laa_state_82571(struct e1000_hw *hw)
  1566. {
  1567. if (hw->mac.type != e1000_82571)
  1568. return false;
  1569. return hw->dev_spec.e82571.laa_is_present;
  1570. }
  1571. /**
  1572. * e1000e_set_laa_state_82571 - Set locally administered address state
  1573. * @hw: pointer to the HW structure
  1574. * @state: enable/disable locally administered address
  1575. *
  1576. * Enable/Disable the current locally administered address state.
  1577. **/
  1578. void e1000e_set_laa_state_82571(struct e1000_hw *hw, bool state)
  1579. {
  1580. if (hw->mac.type != e1000_82571)
  1581. return;
  1582. hw->dev_spec.e82571.laa_is_present = state;
  1583. /* If workaround is activated... */
  1584. if (state)
  1585. /*
  1586. * Hold a copy of the LAA in RAR[14] This is done so that
  1587. * between the time RAR[0] gets clobbered and the time it
  1588. * gets fixed, the actual LAA is in one of the RARs and no
  1589. * incoming packets directed to this port are dropped.
  1590. * Eventually the LAA will be in RAR[0] and RAR[14].
  1591. */
  1592. hw->mac.ops.rar_set(hw, hw->mac.addr,
  1593. hw->mac.rar_entry_count - 1);
  1594. }
  1595. /**
  1596. * e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
  1597. * @hw: pointer to the HW structure
  1598. *
  1599. * Verifies that the EEPROM has completed the update. After updating the
  1600. * EEPROM, we need to check bit 15 in work 0x23 for the checksum fix. If
  1601. * the checksum fix is not implemented, we need to set the bit and update
  1602. * the checksum. Otherwise, if bit 15 is set and the checksum is incorrect,
  1603. * we need to return bad checksum.
  1604. **/
  1605. static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
  1606. {
  1607. struct e1000_nvm_info *nvm = &hw->nvm;
  1608. s32 ret_val;
  1609. u16 data;
  1610. if (nvm->type != e1000_nvm_flash_hw)
  1611. return 0;
  1612. /*
  1613. * Check bit 4 of word 10h. If it is 0, firmware is done updating
  1614. * 10h-12h. Checksum may need to be fixed.
  1615. */
  1616. ret_val = e1000_read_nvm(hw, 0x10, 1, &data);
  1617. if (ret_val)
  1618. return ret_val;
  1619. if (!(data & 0x10)) {
  1620. /*
  1621. * Read 0x23 and check bit 15. This bit is a 1
  1622. * when the checksum has already been fixed. If
  1623. * the checksum is still wrong and this bit is a
  1624. * 1, we need to return bad checksum. Otherwise,
  1625. * we need to set this bit to a 1 and update the
  1626. * checksum.
  1627. */
  1628. ret_val = e1000_read_nvm(hw, 0x23, 1, &data);
  1629. if (ret_val)
  1630. return ret_val;
  1631. if (!(data & 0x8000)) {
  1632. data |= 0x8000;
  1633. ret_val = e1000_write_nvm(hw, 0x23, 1, &data);
  1634. if (ret_val)
  1635. return ret_val;
  1636. ret_val = e1000e_update_nvm_checksum(hw);
  1637. }
  1638. }
  1639. return 0;
  1640. }
  1641. /**
  1642. * e1000_read_mac_addr_82571 - Read device MAC address
  1643. * @hw: pointer to the HW structure
  1644. **/
  1645. static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw)
  1646. {
  1647. if (hw->mac.type == e1000_82571) {
  1648. s32 ret_val = 0;
  1649. /*
  1650. * If there's an alternate MAC address place it in RAR0
  1651. * so that it will override the Si installed default perm
  1652. * address.
  1653. */
  1654. ret_val = e1000_check_alt_mac_addr_generic(hw);
  1655. if (ret_val)
  1656. return ret_val;
  1657. }
  1658. return e1000_read_mac_addr_generic(hw);
  1659. }
  1660. /**
  1661. * e1000_power_down_phy_copper_82571 - Remove link during PHY power down
  1662. * @hw: pointer to the HW structure
  1663. *
  1664. * In the case of a PHY power down to save power, or to turn off link during a
  1665. * driver unload, or wake on lan is not enabled, remove the link.
  1666. **/
  1667. static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw)
  1668. {
  1669. struct e1000_phy_info *phy = &hw->phy;
  1670. struct e1000_mac_info *mac = &hw->mac;
  1671. if (!phy->ops.check_reset_block)
  1672. return;
  1673. /* If the management interface is not enabled, then power down */
  1674. if (!(mac->ops.check_mng_mode(hw) || phy->ops.check_reset_block(hw)))
  1675. e1000_power_down_phy_copper(hw);
  1676. }
  1677. /**
  1678. * e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
  1679. * @hw: pointer to the HW structure
  1680. *
  1681. * Clears the hardware counters by reading the counter registers.
  1682. **/
  1683. static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
  1684. {
  1685. e1000e_clear_hw_cntrs_base(hw);
  1686. er32(PRC64);
  1687. er32(PRC127);
  1688. er32(PRC255);
  1689. er32(PRC511);
  1690. er32(PRC1023);
  1691. er32(PRC1522);
  1692. er32(PTC64);
  1693. er32(PTC127);
  1694. er32(PTC255);
  1695. er32(PTC511);
  1696. er32(PTC1023);
  1697. er32(PTC1522);
  1698. er32(ALGNERRC);
  1699. er32(RXERRC);
  1700. er32(TNCRS);
  1701. er32(CEXTERR);
  1702. er32(TSCTC);
  1703. er32(TSCTFC);
  1704. er32(MGTPRC);
  1705. er32(MGTPDC);
  1706. er32(MGTPTC);
  1707. er32(IAC);
  1708. er32(ICRXOC);
  1709. er32(ICRXPTC);
  1710. er32(ICRXATC);
  1711. er32(ICTXPTC);
  1712. er32(ICTXATC);
  1713. er32(ICTXQEC);
  1714. er32(ICTXQMTC);
  1715. er32(ICRXDMTC);
  1716. }
  1717. static const struct e1000_mac_operations e82571_mac_ops = {
  1718. /* .check_mng_mode: mac type dependent */
  1719. /* .check_for_link: media type dependent */
  1720. .id_led_init = e1000e_id_led_init_generic,
  1721. .cleanup_led = e1000e_cleanup_led_generic,
  1722. .clear_hw_cntrs = e1000_clear_hw_cntrs_82571,
  1723. .get_bus_info = e1000e_get_bus_info_pcie,
  1724. .set_lan_id = e1000_set_lan_id_multi_port_pcie,
  1725. /* .get_link_up_info: media type dependent */
  1726. /* .led_on: mac type dependent */
  1727. .led_off = e1000e_led_off_generic,
  1728. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  1729. .write_vfta = e1000_write_vfta_generic,
  1730. .clear_vfta = e1000_clear_vfta_82571,
  1731. .reset_hw = e1000_reset_hw_82571,
  1732. .init_hw = e1000_init_hw_82571,
  1733. .setup_link = e1000_setup_link_82571,
  1734. /* .setup_physical_interface: media type dependent */
  1735. .setup_led = e1000e_setup_led_generic,
  1736. .config_collision_dist = e1000e_config_collision_dist_generic,
  1737. .read_mac_addr = e1000_read_mac_addr_82571,
  1738. .rar_set = e1000e_rar_set_generic,
  1739. };
  1740. static const struct e1000_phy_operations e82_phy_ops_igp = {
  1741. .acquire = e1000_get_hw_semaphore_82571,
  1742. .check_polarity = e1000_check_polarity_igp,
  1743. .check_reset_block = e1000e_check_reset_block_generic,
  1744. .commit = NULL,
  1745. .force_speed_duplex = e1000e_phy_force_speed_duplex_igp,
  1746. .get_cfg_done = e1000_get_cfg_done_82571,
  1747. .get_cable_length = e1000e_get_cable_length_igp_2,
  1748. .get_info = e1000e_get_phy_info_igp,
  1749. .read_reg = e1000e_read_phy_reg_igp,
  1750. .release = e1000_put_hw_semaphore_82571,
  1751. .reset = e1000e_phy_hw_reset_generic,
  1752. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1753. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1754. .write_reg = e1000e_write_phy_reg_igp,
  1755. .cfg_on_link_up = NULL,
  1756. };
  1757. static const struct e1000_phy_operations e82_phy_ops_m88 = {
  1758. .acquire = e1000_get_hw_semaphore_82571,
  1759. .check_polarity = e1000_check_polarity_m88,
  1760. .check_reset_block = e1000e_check_reset_block_generic,
  1761. .commit = e1000e_phy_sw_reset,
  1762. .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
  1763. .get_cfg_done = e1000e_get_cfg_done,
  1764. .get_cable_length = e1000e_get_cable_length_m88,
  1765. .get_info = e1000e_get_phy_info_m88,
  1766. .read_reg = e1000e_read_phy_reg_m88,
  1767. .release = e1000_put_hw_semaphore_82571,
  1768. .reset = e1000e_phy_hw_reset_generic,
  1769. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1770. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1771. .write_reg = e1000e_write_phy_reg_m88,
  1772. .cfg_on_link_up = NULL,
  1773. };
  1774. static const struct e1000_phy_operations e82_phy_ops_bm = {
  1775. .acquire = e1000_get_hw_semaphore_82571,
  1776. .check_polarity = e1000_check_polarity_m88,
  1777. .check_reset_block = e1000e_check_reset_block_generic,
  1778. .commit = e1000e_phy_sw_reset,
  1779. .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
  1780. .get_cfg_done = e1000e_get_cfg_done,
  1781. .get_cable_length = e1000e_get_cable_length_m88,
  1782. .get_info = e1000e_get_phy_info_m88,
  1783. .read_reg = e1000e_read_phy_reg_bm2,
  1784. .release = e1000_put_hw_semaphore_82571,
  1785. .reset = e1000e_phy_hw_reset_generic,
  1786. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1787. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1788. .write_reg = e1000e_write_phy_reg_bm2,
  1789. .cfg_on_link_up = NULL,
  1790. };
  1791. static const struct e1000_nvm_operations e82571_nvm_ops = {
  1792. .acquire = e1000_acquire_nvm_82571,
  1793. .read = e1000e_read_nvm_eerd,
  1794. .release = e1000_release_nvm_82571,
  1795. .reload = e1000e_reload_nvm_generic,
  1796. .update = e1000_update_nvm_checksum_82571,
  1797. .valid_led_default = e1000_valid_led_default_82571,
  1798. .validate = e1000_validate_nvm_checksum_82571,
  1799. .write = e1000_write_nvm_82571,
  1800. };
  1801. const struct e1000_info e1000_82571_info = {
  1802. .mac = e1000_82571,
  1803. .flags = FLAG_HAS_HW_VLAN_FILTER
  1804. | FLAG_HAS_JUMBO_FRAMES
  1805. | FLAG_HAS_WOL
  1806. | FLAG_APME_IN_CTRL3
  1807. | FLAG_HAS_CTRLEXT_ON_LOAD
  1808. | FLAG_HAS_SMART_POWER_DOWN
  1809. | FLAG_RESET_OVERWRITES_LAA /* errata */
  1810. | FLAG_TARC_SPEED_MODE_BIT /* errata */
  1811. | FLAG_APME_CHECK_PORT_B,
  1812. .flags2 = FLAG2_DISABLE_ASPM_L1 /* errata 13 */
  1813. | FLAG2_DMA_BURST,
  1814. .pba = 38,
  1815. .max_hw_frame_size = DEFAULT_JUMBO,
  1816. .get_variants = e1000_get_variants_82571,
  1817. .mac_ops = &e82571_mac_ops,
  1818. .phy_ops = &e82_phy_ops_igp,
  1819. .nvm_ops = &e82571_nvm_ops,
  1820. };
  1821. const struct e1000_info e1000_82572_info = {
  1822. .mac = e1000_82572,
  1823. .flags = FLAG_HAS_HW_VLAN_FILTER
  1824. | FLAG_HAS_JUMBO_FRAMES
  1825. | FLAG_HAS_WOL
  1826. | FLAG_APME_IN_CTRL3
  1827. | FLAG_HAS_CTRLEXT_ON_LOAD
  1828. | FLAG_TARC_SPEED_MODE_BIT, /* errata */
  1829. .flags2 = FLAG2_DISABLE_ASPM_L1 /* errata 13 */
  1830. | FLAG2_DMA_BURST,
  1831. .pba = 38,
  1832. .max_hw_frame_size = DEFAULT_JUMBO,
  1833. .get_variants = e1000_get_variants_82571,
  1834. .mac_ops = &e82571_mac_ops,
  1835. .phy_ops = &e82_phy_ops_igp,
  1836. .nvm_ops = &e82571_nvm_ops,
  1837. };
  1838. const struct e1000_info e1000_82573_info = {
  1839. .mac = e1000_82573,
  1840. .flags = FLAG_HAS_HW_VLAN_FILTER
  1841. | FLAG_HAS_WOL
  1842. | FLAG_APME_IN_CTRL3
  1843. | FLAG_HAS_SMART_POWER_DOWN
  1844. | FLAG_HAS_AMT
  1845. | FLAG_HAS_SWSM_ON_LOAD,
  1846. .flags2 = FLAG2_DISABLE_ASPM_L1
  1847. | FLAG2_DISABLE_ASPM_L0S,
  1848. .pba = 20,
  1849. .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
  1850. .get_variants = e1000_get_variants_82571,
  1851. .mac_ops = &e82571_mac_ops,
  1852. .phy_ops = &e82_phy_ops_m88,
  1853. .nvm_ops = &e82571_nvm_ops,
  1854. };
  1855. const struct e1000_info e1000_82574_info = {
  1856. .mac = e1000_82574,
  1857. .flags = FLAG_HAS_HW_VLAN_FILTER
  1858. | FLAG_HAS_MSIX
  1859. | FLAG_HAS_JUMBO_FRAMES
  1860. | FLAG_HAS_WOL
  1861. | FLAG_APME_IN_CTRL3
  1862. | FLAG_HAS_SMART_POWER_DOWN
  1863. | FLAG_HAS_AMT
  1864. | FLAG_HAS_CTRLEXT_ON_LOAD,
  1865. .flags2 = FLAG2_CHECK_PHY_HANG
  1866. | FLAG2_DISABLE_ASPM_L0S
  1867. | FLAG2_DISABLE_ASPM_L1
  1868. | FLAG2_NO_DISABLE_RX
  1869. | FLAG2_DMA_BURST,
  1870. .pba = 32,
  1871. .max_hw_frame_size = DEFAULT_JUMBO,
  1872. .get_variants = e1000_get_variants_82571,
  1873. .mac_ops = &e82571_mac_ops,
  1874. .phy_ops = &e82_phy_ops_bm,
  1875. .nvm_ops = &e82571_nvm_ops,
  1876. };
  1877. const struct e1000_info e1000_82583_info = {
  1878. .mac = e1000_82583,
  1879. .flags = FLAG_HAS_HW_VLAN_FILTER
  1880. | FLAG_HAS_WOL
  1881. | FLAG_APME_IN_CTRL3
  1882. | FLAG_HAS_SMART_POWER_DOWN
  1883. | FLAG_HAS_AMT
  1884. | FLAG_HAS_JUMBO_FRAMES
  1885. | FLAG_HAS_CTRLEXT_ON_LOAD,
  1886. .flags2 = FLAG2_DISABLE_ASPM_L0S
  1887. | FLAG2_NO_DISABLE_RX,
  1888. .pba = 32,
  1889. .max_hw_frame_size = DEFAULT_JUMBO,
  1890. .get_variants = e1000_get_variants_82571,
  1891. .mac_ops = &e82571_mac_ops,
  1892. .phy_ops = &e82_phy_ops_bm,
  1893. .nvm_ops = &e82571_nvm_ops,
  1894. };