82571.c 55 KB

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