82571.c 55 KB

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