82571.c 54 KB

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