82571.c 54 KB

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