82571.c 54 KB

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