82571.c 55 KB

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