82571.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116
  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. if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
  1396. /* Receiver is synchronized with no invalid bits. */
  1397. switch (mac->serdes_link_state) {
  1398. case e1000_serdes_link_autoneg_complete:
  1399. if (!(status & E1000_STATUS_LU)) {
  1400. /*
  1401. * We have lost link, retry autoneg before
  1402. * reporting link failure
  1403. */
  1404. mac->serdes_link_state =
  1405. e1000_serdes_link_autoneg_progress;
  1406. mac->serdes_has_link = false;
  1407. e_dbg("AN_UP -> AN_PROG\n");
  1408. } else {
  1409. mac->serdes_has_link = true;
  1410. }
  1411. break;
  1412. case e1000_serdes_link_forced_up:
  1413. /*
  1414. * If we are receiving /C/ ordered sets, re-enable
  1415. * auto-negotiation in the TXCW register and disable
  1416. * forced link in the Device Control register in an
  1417. * attempt to auto-negotiate with our link partner.
  1418. * If the partner code word is null, stop forcing
  1419. * and restart auto negotiation.
  1420. */
  1421. if ((rxcw & E1000_RXCW_C) || !(rxcw & E1000_RXCW_CW)) {
  1422. /* Enable autoneg, and unforce link up */
  1423. ew32(TXCW, mac->txcw);
  1424. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  1425. mac->serdes_link_state =
  1426. e1000_serdes_link_autoneg_progress;
  1427. mac->serdes_has_link = false;
  1428. e_dbg("FORCED_UP -> AN_PROG\n");
  1429. } else {
  1430. mac->serdes_has_link = true;
  1431. }
  1432. break;
  1433. case e1000_serdes_link_autoneg_progress:
  1434. if (rxcw & E1000_RXCW_C) {
  1435. /*
  1436. * We received /C/ ordered sets, meaning the
  1437. * link partner has autonegotiated, and we can
  1438. * trust the Link Up (LU) status bit.
  1439. */
  1440. if (status & E1000_STATUS_LU) {
  1441. mac->serdes_link_state =
  1442. e1000_serdes_link_autoneg_complete;
  1443. e_dbg("AN_PROG -> AN_UP\n");
  1444. mac->serdes_has_link = true;
  1445. } else {
  1446. /* Autoneg completed, but failed. */
  1447. mac->serdes_link_state =
  1448. e1000_serdes_link_down;
  1449. e_dbg("AN_PROG -> DOWN\n");
  1450. }
  1451. } else {
  1452. /*
  1453. * The link partner did not autoneg.
  1454. * Force link up and full duplex, and change
  1455. * state to forced.
  1456. */
  1457. ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  1458. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  1459. ew32(CTRL, ctrl);
  1460. /* Configure Flow Control after link up. */
  1461. ret_val = e1000e_config_fc_after_link_up(hw);
  1462. if (ret_val) {
  1463. e_dbg("Error config flow control\n");
  1464. break;
  1465. }
  1466. mac->serdes_link_state =
  1467. e1000_serdes_link_forced_up;
  1468. mac->serdes_has_link = true;
  1469. e_dbg("AN_PROG -> FORCED_UP\n");
  1470. }
  1471. break;
  1472. case e1000_serdes_link_down:
  1473. default:
  1474. /*
  1475. * The link was down but the receiver has now gained
  1476. * valid sync, so lets see if we can bring the link
  1477. * up.
  1478. */
  1479. ew32(TXCW, mac->txcw);
  1480. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  1481. mac->serdes_link_state =
  1482. e1000_serdes_link_autoneg_progress;
  1483. mac->serdes_has_link = false;
  1484. e_dbg("DOWN -> AN_PROG\n");
  1485. break;
  1486. }
  1487. } else {
  1488. if (!(rxcw & E1000_RXCW_SYNCH)) {
  1489. mac->serdes_has_link = false;
  1490. mac->serdes_link_state = e1000_serdes_link_down;
  1491. e_dbg("ANYSTATE -> DOWN\n");
  1492. } else {
  1493. /*
  1494. * Check several times, if Sync and Config
  1495. * both are consistently 1 then simply ignore
  1496. * the Invalid bit and restart Autoneg
  1497. */
  1498. for (i = 0; i < AN_RETRY_COUNT; i++) {
  1499. udelay(10);
  1500. rxcw = er32(RXCW);
  1501. if ((rxcw & E1000_RXCW_IV) &&
  1502. !((rxcw & E1000_RXCW_SYNCH) &&
  1503. (rxcw & E1000_RXCW_C))) {
  1504. mac->serdes_has_link = false;
  1505. mac->serdes_link_state =
  1506. e1000_serdes_link_down;
  1507. e_dbg("ANYSTATE -> DOWN\n");
  1508. break;
  1509. }
  1510. }
  1511. if (i == AN_RETRY_COUNT) {
  1512. txcw = er32(TXCW);
  1513. txcw |= E1000_TXCW_ANE;
  1514. ew32(TXCW, txcw);
  1515. mac->serdes_link_state =
  1516. e1000_serdes_link_autoneg_progress;
  1517. mac->serdes_has_link = false;
  1518. e_dbg("ANYSTATE -> AN_PROG\n");
  1519. }
  1520. }
  1521. }
  1522. return ret_val;
  1523. }
  1524. /**
  1525. * e1000_valid_led_default_82571 - Verify a valid default LED config
  1526. * @hw: pointer to the HW structure
  1527. * @data: pointer to the NVM (EEPROM)
  1528. *
  1529. * Read the EEPROM for the current default LED configuration. If the
  1530. * LED configuration is not valid, set to a valid LED configuration.
  1531. **/
  1532. static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data)
  1533. {
  1534. s32 ret_val;
  1535. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1536. if (ret_val) {
  1537. e_dbg("NVM Read Error\n");
  1538. return ret_val;
  1539. }
  1540. switch (hw->mac.type) {
  1541. case e1000_82573:
  1542. case e1000_82574:
  1543. case e1000_82583:
  1544. if (*data == ID_LED_RESERVED_F746)
  1545. *data = ID_LED_DEFAULT_82573;
  1546. break;
  1547. default:
  1548. if (*data == ID_LED_RESERVED_0000 ||
  1549. *data == ID_LED_RESERVED_FFFF)
  1550. *data = ID_LED_DEFAULT;
  1551. break;
  1552. }
  1553. return 0;
  1554. }
  1555. /**
  1556. * e1000e_get_laa_state_82571 - Get locally administered address state
  1557. * @hw: pointer to the HW structure
  1558. *
  1559. * Retrieve and return the current locally administered address state.
  1560. **/
  1561. bool e1000e_get_laa_state_82571(struct e1000_hw *hw)
  1562. {
  1563. if (hw->mac.type != e1000_82571)
  1564. return false;
  1565. return hw->dev_spec.e82571.laa_is_present;
  1566. }
  1567. /**
  1568. * e1000e_set_laa_state_82571 - Set locally administered address state
  1569. * @hw: pointer to the HW structure
  1570. * @state: enable/disable locally administered address
  1571. *
  1572. * Enable/Disable the current locally administered address state.
  1573. **/
  1574. void e1000e_set_laa_state_82571(struct e1000_hw *hw, bool state)
  1575. {
  1576. if (hw->mac.type != e1000_82571)
  1577. return;
  1578. hw->dev_spec.e82571.laa_is_present = state;
  1579. /* If workaround is activated... */
  1580. if (state)
  1581. /*
  1582. * Hold a copy of the LAA in RAR[14] This is done so that
  1583. * between the time RAR[0] gets clobbered and the time it
  1584. * gets fixed, the actual LAA is in one of the RARs and no
  1585. * incoming packets directed to this port are dropped.
  1586. * Eventually the LAA will be in RAR[0] and RAR[14].
  1587. */
  1588. hw->mac.ops.rar_set(hw, hw->mac.addr,
  1589. hw->mac.rar_entry_count - 1);
  1590. }
  1591. /**
  1592. * e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
  1593. * @hw: pointer to the HW structure
  1594. *
  1595. * Verifies that the EEPROM has completed the update. After updating the
  1596. * EEPROM, we need to check bit 15 in work 0x23 for the checksum fix. If
  1597. * the checksum fix is not implemented, we need to set the bit and update
  1598. * the checksum. Otherwise, if bit 15 is set and the checksum is incorrect,
  1599. * we need to return bad checksum.
  1600. **/
  1601. static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
  1602. {
  1603. struct e1000_nvm_info *nvm = &hw->nvm;
  1604. s32 ret_val;
  1605. u16 data;
  1606. if (nvm->type != e1000_nvm_flash_hw)
  1607. return 0;
  1608. /*
  1609. * Check bit 4 of word 10h. If it is 0, firmware is done updating
  1610. * 10h-12h. Checksum may need to be fixed.
  1611. */
  1612. ret_val = e1000_read_nvm(hw, 0x10, 1, &data);
  1613. if (ret_val)
  1614. return ret_val;
  1615. if (!(data & 0x10)) {
  1616. /*
  1617. * Read 0x23 and check bit 15. This bit is a 1
  1618. * when the checksum has already been fixed. If
  1619. * the checksum is still wrong and this bit is a
  1620. * 1, we need to return bad checksum. Otherwise,
  1621. * we need to set this bit to a 1 and update the
  1622. * checksum.
  1623. */
  1624. ret_val = e1000_read_nvm(hw, 0x23, 1, &data);
  1625. if (ret_val)
  1626. return ret_val;
  1627. if (!(data & 0x8000)) {
  1628. data |= 0x8000;
  1629. ret_val = e1000_write_nvm(hw, 0x23, 1, &data);
  1630. if (ret_val)
  1631. return ret_val;
  1632. ret_val = e1000e_update_nvm_checksum(hw);
  1633. }
  1634. }
  1635. return 0;
  1636. }
  1637. /**
  1638. * e1000_read_mac_addr_82571 - Read device MAC address
  1639. * @hw: pointer to the HW structure
  1640. **/
  1641. static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw)
  1642. {
  1643. if (hw->mac.type == e1000_82571) {
  1644. s32 ret_val = 0;
  1645. /*
  1646. * If there's an alternate MAC address place it in RAR0
  1647. * so that it will override the Si installed default perm
  1648. * address.
  1649. */
  1650. ret_val = e1000_check_alt_mac_addr_generic(hw);
  1651. if (ret_val)
  1652. return ret_val;
  1653. }
  1654. return e1000_read_mac_addr_generic(hw);
  1655. }
  1656. /**
  1657. * e1000_power_down_phy_copper_82571 - Remove link during PHY power down
  1658. * @hw: pointer to the HW structure
  1659. *
  1660. * In the case of a PHY power down to save power, or to turn off link during a
  1661. * driver unload, or wake on lan is not enabled, remove the link.
  1662. **/
  1663. static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw)
  1664. {
  1665. struct e1000_phy_info *phy = &hw->phy;
  1666. struct e1000_mac_info *mac = &hw->mac;
  1667. if (!phy->ops.check_reset_block)
  1668. return;
  1669. /* If the management interface is not enabled, then power down */
  1670. if (!(mac->ops.check_mng_mode(hw) || phy->ops.check_reset_block(hw)))
  1671. e1000_power_down_phy_copper(hw);
  1672. }
  1673. /**
  1674. * e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
  1675. * @hw: pointer to the HW structure
  1676. *
  1677. * Clears the hardware counters by reading the counter registers.
  1678. **/
  1679. static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
  1680. {
  1681. e1000e_clear_hw_cntrs_base(hw);
  1682. er32(PRC64);
  1683. er32(PRC127);
  1684. er32(PRC255);
  1685. er32(PRC511);
  1686. er32(PRC1023);
  1687. er32(PRC1522);
  1688. er32(PTC64);
  1689. er32(PTC127);
  1690. er32(PTC255);
  1691. er32(PTC511);
  1692. er32(PTC1023);
  1693. er32(PTC1522);
  1694. er32(ALGNERRC);
  1695. er32(RXERRC);
  1696. er32(TNCRS);
  1697. er32(CEXTERR);
  1698. er32(TSCTC);
  1699. er32(TSCTFC);
  1700. er32(MGTPRC);
  1701. er32(MGTPDC);
  1702. er32(MGTPTC);
  1703. er32(IAC);
  1704. er32(ICRXOC);
  1705. er32(ICRXPTC);
  1706. er32(ICRXATC);
  1707. er32(ICTXPTC);
  1708. er32(ICTXATC);
  1709. er32(ICTXQEC);
  1710. er32(ICTXQMTC);
  1711. er32(ICRXDMTC);
  1712. }
  1713. static const struct e1000_mac_operations e82571_mac_ops = {
  1714. /* .check_mng_mode: mac type dependent */
  1715. /* .check_for_link: media type dependent */
  1716. .id_led_init = e1000e_id_led_init_generic,
  1717. .cleanup_led = e1000e_cleanup_led_generic,
  1718. .clear_hw_cntrs = e1000_clear_hw_cntrs_82571,
  1719. .get_bus_info = e1000e_get_bus_info_pcie,
  1720. .set_lan_id = e1000_set_lan_id_multi_port_pcie,
  1721. /* .get_link_up_info: media type dependent */
  1722. /* .led_on: mac type dependent */
  1723. .led_off = e1000e_led_off_generic,
  1724. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  1725. .write_vfta = e1000_write_vfta_generic,
  1726. .clear_vfta = e1000_clear_vfta_82571,
  1727. .reset_hw = e1000_reset_hw_82571,
  1728. .init_hw = e1000_init_hw_82571,
  1729. .setup_link = e1000_setup_link_82571,
  1730. /* .setup_physical_interface: media type dependent */
  1731. .setup_led = e1000e_setup_led_generic,
  1732. .config_collision_dist = e1000e_config_collision_dist_generic,
  1733. .read_mac_addr = e1000_read_mac_addr_82571,
  1734. .rar_set = e1000e_rar_set_generic,
  1735. };
  1736. static const struct e1000_phy_operations e82_phy_ops_igp = {
  1737. .acquire = e1000_get_hw_semaphore_82571,
  1738. .check_polarity = e1000_check_polarity_igp,
  1739. .check_reset_block = e1000e_check_reset_block_generic,
  1740. .commit = NULL,
  1741. .force_speed_duplex = e1000e_phy_force_speed_duplex_igp,
  1742. .get_cfg_done = e1000_get_cfg_done_82571,
  1743. .get_cable_length = e1000e_get_cable_length_igp_2,
  1744. .get_info = e1000e_get_phy_info_igp,
  1745. .read_reg = e1000e_read_phy_reg_igp,
  1746. .release = e1000_put_hw_semaphore_82571,
  1747. .reset = e1000e_phy_hw_reset_generic,
  1748. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1749. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1750. .write_reg = e1000e_write_phy_reg_igp,
  1751. .cfg_on_link_up = NULL,
  1752. };
  1753. static const struct e1000_phy_operations e82_phy_ops_m88 = {
  1754. .acquire = e1000_get_hw_semaphore_82571,
  1755. .check_polarity = e1000_check_polarity_m88,
  1756. .check_reset_block = e1000e_check_reset_block_generic,
  1757. .commit = e1000e_phy_sw_reset,
  1758. .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
  1759. .get_cfg_done = e1000e_get_cfg_done,
  1760. .get_cable_length = e1000e_get_cable_length_m88,
  1761. .get_info = e1000e_get_phy_info_m88,
  1762. .read_reg = e1000e_read_phy_reg_m88,
  1763. .release = e1000_put_hw_semaphore_82571,
  1764. .reset = e1000e_phy_hw_reset_generic,
  1765. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1766. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1767. .write_reg = e1000e_write_phy_reg_m88,
  1768. .cfg_on_link_up = NULL,
  1769. };
  1770. static const struct e1000_phy_operations e82_phy_ops_bm = {
  1771. .acquire = e1000_get_hw_semaphore_82571,
  1772. .check_polarity = e1000_check_polarity_m88,
  1773. .check_reset_block = e1000e_check_reset_block_generic,
  1774. .commit = e1000e_phy_sw_reset,
  1775. .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
  1776. .get_cfg_done = e1000e_get_cfg_done,
  1777. .get_cable_length = e1000e_get_cable_length_m88,
  1778. .get_info = e1000e_get_phy_info_m88,
  1779. .read_reg = e1000e_read_phy_reg_bm2,
  1780. .release = e1000_put_hw_semaphore_82571,
  1781. .reset = e1000e_phy_hw_reset_generic,
  1782. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1783. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1784. .write_reg = e1000e_write_phy_reg_bm2,
  1785. .cfg_on_link_up = NULL,
  1786. };
  1787. static const struct e1000_nvm_operations e82571_nvm_ops = {
  1788. .acquire = e1000_acquire_nvm_82571,
  1789. .read = e1000e_read_nvm_eerd,
  1790. .release = e1000_release_nvm_82571,
  1791. .reload = e1000e_reload_nvm_generic,
  1792. .update = e1000_update_nvm_checksum_82571,
  1793. .valid_led_default = e1000_valid_led_default_82571,
  1794. .validate = e1000_validate_nvm_checksum_82571,
  1795. .write = e1000_write_nvm_82571,
  1796. };
  1797. const struct e1000_info e1000_82571_info = {
  1798. .mac = e1000_82571,
  1799. .flags = FLAG_HAS_HW_VLAN_FILTER
  1800. | FLAG_HAS_JUMBO_FRAMES
  1801. | FLAG_HAS_WOL
  1802. | FLAG_APME_IN_CTRL3
  1803. | FLAG_HAS_CTRLEXT_ON_LOAD
  1804. | FLAG_HAS_SMART_POWER_DOWN
  1805. | FLAG_RESET_OVERWRITES_LAA /* errata */
  1806. | FLAG_TARC_SPEED_MODE_BIT /* errata */
  1807. | FLAG_APME_CHECK_PORT_B,
  1808. .flags2 = FLAG2_DISABLE_ASPM_L1 /* errata 13 */
  1809. | FLAG2_DMA_BURST,
  1810. .pba = 38,
  1811. .max_hw_frame_size = DEFAULT_JUMBO,
  1812. .get_variants = e1000_get_variants_82571,
  1813. .mac_ops = &e82571_mac_ops,
  1814. .phy_ops = &e82_phy_ops_igp,
  1815. .nvm_ops = &e82571_nvm_ops,
  1816. };
  1817. const struct e1000_info e1000_82572_info = {
  1818. .mac = e1000_82572,
  1819. .flags = FLAG_HAS_HW_VLAN_FILTER
  1820. | FLAG_HAS_JUMBO_FRAMES
  1821. | FLAG_HAS_WOL
  1822. | FLAG_APME_IN_CTRL3
  1823. | FLAG_HAS_CTRLEXT_ON_LOAD
  1824. | FLAG_TARC_SPEED_MODE_BIT, /* errata */
  1825. .flags2 = FLAG2_DISABLE_ASPM_L1 /* errata 13 */
  1826. | FLAG2_DMA_BURST,
  1827. .pba = 38,
  1828. .max_hw_frame_size = DEFAULT_JUMBO,
  1829. .get_variants = e1000_get_variants_82571,
  1830. .mac_ops = &e82571_mac_ops,
  1831. .phy_ops = &e82_phy_ops_igp,
  1832. .nvm_ops = &e82571_nvm_ops,
  1833. };
  1834. const struct e1000_info e1000_82573_info = {
  1835. .mac = e1000_82573,
  1836. .flags = FLAG_HAS_HW_VLAN_FILTER
  1837. | FLAG_HAS_WOL
  1838. | FLAG_APME_IN_CTRL3
  1839. | FLAG_HAS_SMART_POWER_DOWN
  1840. | FLAG_HAS_AMT
  1841. | FLAG_HAS_SWSM_ON_LOAD,
  1842. .flags2 = FLAG2_DISABLE_ASPM_L1
  1843. | FLAG2_DISABLE_ASPM_L0S,
  1844. .pba = 20,
  1845. .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
  1846. .get_variants = e1000_get_variants_82571,
  1847. .mac_ops = &e82571_mac_ops,
  1848. .phy_ops = &e82_phy_ops_m88,
  1849. .nvm_ops = &e82571_nvm_ops,
  1850. };
  1851. const struct e1000_info e1000_82574_info = {
  1852. .mac = e1000_82574,
  1853. .flags = FLAG_HAS_HW_VLAN_FILTER
  1854. | FLAG_HAS_MSIX
  1855. | FLAG_HAS_JUMBO_FRAMES
  1856. | FLAG_HAS_WOL
  1857. | FLAG_APME_IN_CTRL3
  1858. | FLAG_HAS_SMART_POWER_DOWN
  1859. | FLAG_HAS_AMT
  1860. | FLAG_HAS_CTRLEXT_ON_LOAD,
  1861. .flags2 = FLAG2_CHECK_PHY_HANG
  1862. | FLAG2_DISABLE_ASPM_L0S
  1863. | FLAG2_DISABLE_ASPM_L1
  1864. | FLAG2_NO_DISABLE_RX
  1865. | FLAG2_DMA_BURST,
  1866. .pba = 32,
  1867. .max_hw_frame_size = DEFAULT_JUMBO,
  1868. .get_variants = e1000_get_variants_82571,
  1869. .mac_ops = &e82571_mac_ops,
  1870. .phy_ops = &e82_phy_ops_bm,
  1871. .nvm_ops = &e82571_nvm_ops,
  1872. };
  1873. const struct e1000_info e1000_82583_info = {
  1874. .mac = e1000_82583,
  1875. .flags = FLAG_HAS_HW_VLAN_FILTER
  1876. | FLAG_HAS_WOL
  1877. | FLAG_APME_IN_CTRL3
  1878. | FLAG_HAS_SMART_POWER_DOWN
  1879. | FLAG_HAS_AMT
  1880. | FLAG_HAS_JUMBO_FRAMES
  1881. | FLAG_HAS_CTRLEXT_ON_LOAD,
  1882. .flags2 = FLAG2_DISABLE_ASPM_L0S
  1883. | FLAG2_NO_DISABLE_RX,
  1884. .pba = 32,
  1885. .max_hw_frame_size = DEFAULT_JUMBO,
  1886. .get_variants = e1000_get_variants_82571,
  1887. .mac_ops = &e82571_mac_ops,
  1888. .phy_ops = &e82_phy_ops_bm,
  1889. .nvm_ops = &e82571_nvm_ops,
  1890. };