82571.c 54 KB

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