82571.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2008 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. */
  36. #include <linux/netdevice.h>
  37. #include <linux/delay.h>
  38. #include <linux/pci.h>
  39. #include "e1000.h"
  40. #define ID_LED_RESERVED_F746 0xF746
  41. #define ID_LED_DEFAULT_82573 ((ID_LED_DEF1_DEF2 << 12) | \
  42. (ID_LED_OFF1_ON2 << 8) | \
  43. (ID_LED_DEF1_DEF2 << 4) | \
  44. (ID_LED_DEF1_DEF2))
  45. #define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
  46. #define E1000_NVM_INIT_CTRL2_MNGM 0x6000 /* Manageability Operation Mode mask */
  47. static s32 e1000_get_phy_id_82571(struct e1000_hw *hw);
  48. static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw);
  49. static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw);
  50. static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw);
  51. static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
  52. u16 words, u16 *data);
  53. static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw);
  54. static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw);
  55. static s32 e1000_setup_link_82571(struct e1000_hw *hw);
  56. static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw);
  57. static bool e1000_check_mng_mode_82574(struct e1000_hw *hw);
  58. static s32 e1000_led_on_82574(struct e1000_hw *hw);
  59. /**
  60. * e1000_init_phy_params_82571 - Init PHY func ptrs.
  61. * @hw: pointer to the HW structure
  62. *
  63. * This is a function pointer entry point called by the api module.
  64. **/
  65. static s32 e1000_init_phy_params_82571(struct e1000_hw *hw)
  66. {
  67. struct e1000_phy_info *phy = &hw->phy;
  68. s32 ret_val;
  69. if (hw->phy.media_type != e1000_media_type_copper) {
  70. phy->type = e1000_phy_none;
  71. return 0;
  72. }
  73. phy->addr = 1;
  74. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  75. phy->reset_delay_us = 100;
  76. switch (hw->mac.type) {
  77. case e1000_82571:
  78. case e1000_82572:
  79. phy->type = e1000_phy_igp_2;
  80. break;
  81. case e1000_82573:
  82. phy->type = e1000_phy_m88;
  83. break;
  84. case e1000_82574:
  85. phy->type = e1000_phy_bm;
  86. break;
  87. default:
  88. return -E1000_ERR_PHY;
  89. break;
  90. }
  91. /* This can only be done after all function pointers are setup. */
  92. ret_val = e1000_get_phy_id_82571(hw);
  93. /* Verify phy id */
  94. switch (hw->mac.type) {
  95. case e1000_82571:
  96. case e1000_82572:
  97. if (phy->id != IGP01E1000_I_PHY_ID)
  98. return -E1000_ERR_PHY;
  99. break;
  100. case e1000_82573:
  101. if (phy->id != M88E1111_I_PHY_ID)
  102. return -E1000_ERR_PHY;
  103. break;
  104. case e1000_82574:
  105. if (phy->id != BME1000_E_PHY_ID_R2)
  106. return -E1000_ERR_PHY;
  107. break;
  108. default:
  109. return -E1000_ERR_PHY;
  110. break;
  111. }
  112. return 0;
  113. }
  114. /**
  115. * e1000_init_nvm_params_82571 - Init NVM func ptrs.
  116. * @hw: pointer to the HW structure
  117. *
  118. * This is a function pointer entry point called by the api module.
  119. **/
  120. static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
  121. {
  122. struct e1000_nvm_info *nvm = &hw->nvm;
  123. u32 eecd = er32(EECD);
  124. u16 size;
  125. nvm->opcode_bits = 8;
  126. nvm->delay_usec = 1;
  127. switch (nvm->override) {
  128. case e1000_nvm_override_spi_large:
  129. nvm->page_size = 32;
  130. nvm->address_bits = 16;
  131. break;
  132. case e1000_nvm_override_spi_small:
  133. nvm->page_size = 8;
  134. nvm->address_bits = 8;
  135. break;
  136. default:
  137. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  138. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
  139. break;
  140. }
  141. switch (hw->mac.type) {
  142. case e1000_82573:
  143. case e1000_82574:
  144. if (((eecd >> 15) & 0x3) == 0x3) {
  145. nvm->type = e1000_nvm_flash_hw;
  146. nvm->word_size = 2048;
  147. /*
  148. * Autonomous Flash update bit must be cleared due
  149. * to Flash update issue.
  150. */
  151. eecd &= ~E1000_EECD_AUPDEN;
  152. ew32(EECD, eecd);
  153. break;
  154. }
  155. /* Fall Through */
  156. default:
  157. nvm->type = e1000_nvm_eeprom_spi;
  158. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  159. E1000_EECD_SIZE_EX_SHIFT);
  160. /*
  161. * Added to a constant, "size" becomes the left-shift value
  162. * for setting word_size.
  163. */
  164. size += NVM_WORD_SIZE_BASE_SHIFT;
  165. /* EEPROM access above 16k is unsupported */
  166. if (size > 14)
  167. size = 14;
  168. nvm->word_size = 1 << size;
  169. break;
  170. }
  171. return 0;
  172. }
  173. /**
  174. * e1000_init_mac_params_82571 - Init MAC func ptrs.
  175. * @hw: pointer to the HW structure
  176. *
  177. * This is a function pointer entry point called by the api module.
  178. **/
  179. static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
  180. {
  181. struct e1000_hw *hw = &adapter->hw;
  182. struct e1000_mac_info *mac = &hw->mac;
  183. struct e1000_mac_operations *func = &mac->ops;
  184. /* Set media type */
  185. switch (adapter->pdev->device) {
  186. case E1000_DEV_ID_82571EB_FIBER:
  187. case E1000_DEV_ID_82572EI_FIBER:
  188. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  189. hw->phy.media_type = e1000_media_type_fiber;
  190. break;
  191. case E1000_DEV_ID_82571EB_SERDES:
  192. case E1000_DEV_ID_82572EI_SERDES:
  193. case E1000_DEV_ID_82571EB_SERDES_DUAL:
  194. case E1000_DEV_ID_82571EB_SERDES_QUAD:
  195. hw->phy.media_type = e1000_media_type_internal_serdes;
  196. break;
  197. default:
  198. hw->phy.media_type = e1000_media_type_copper;
  199. break;
  200. }
  201. /* Set mta register count */
  202. mac->mta_reg_count = 128;
  203. /* Set rar entry count */
  204. mac->rar_entry_count = E1000_RAR_ENTRIES;
  205. /* Set if manageability features are enabled. */
  206. mac->arc_subsystem_valid = (er32(FWSM) & E1000_FWSM_MODE_MASK) ? 1 : 0;
  207. /* check for link */
  208. switch (hw->phy.media_type) {
  209. case e1000_media_type_copper:
  210. func->setup_physical_interface = e1000_setup_copper_link_82571;
  211. func->check_for_link = e1000e_check_for_copper_link;
  212. func->get_link_up_info = e1000e_get_speed_and_duplex_copper;
  213. break;
  214. case e1000_media_type_fiber:
  215. func->setup_physical_interface =
  216. e1000_setup_fiber_serdes_link_82571;
  217. func->check_for_link = e1000e_check_for_fiber_link;
  218. func->get_link_up_info =
  219. e1000e_get_speed_and_duplex_fiber_serdes;
  220. break;
  221. case e1000_media_type_internal_serdes:
  222. func->setup_physical_interface =
  223. e1000_setup_fiber_serdes_link_82571;
  224. func->check_for_link = e1000_check_for_serdes_link_82571;
  225. func->get_link_up_info =
  226. e1000e_get_speed_and_duplex_fiber_serdes;
  227. break;
  228. default:
  229. return -E1000_ERR_CONFIG;
  230. break;
  231. }
  232. switch (hw->mac.type) {
  233. case e1000_82574:
  234. func->check_mng_mode = e1000_check_mng_mode_82574;
  235. func->led_on = e1000_led_on_82574;
  236. break;
  237. default:
  238. func->check_mng_mode = e1000e_check_mng_mode_generic;
  239. func->led_on = e1000e_led_on_generic;
  240. break;
  241. }
  242. return 0;
  243. }
  244. static s32 e1000_get_variants_82571(struct e1000_adapter *adapter)
  245. {
  246. struct e1000_hw *hw = &adapter->hw;
  247. static int global_quad_port_a; /* global port a indication */
  248. struct pci_dev *pdev = adapter->pdev;
  249. u16 eeprom_data = 0;
  250. int is_port_b = er32(STATUS) & E1000_STATUS_FUNC_1;
  251. s32 rc;
  252. rc = e1000_init_mac_params_82571(adapter);
  253. if (rc)
  254. return rc;
  255. rc = e1000_init_nvm_params_82571(hw);
  256. if (rc)
  257. return rc;
  258. rc = e1000_init_phy_params_82571(hw);
  259. if (rc)
  260. return rc;
  261. /* tag quad port adapters first, it's used below */
  262. switch (pdev->device) {
  263. case E1000_DEV_ID_82571EB_QUAD_COPPER:
  264. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  265. case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:
  266. case E1000_DEV_ID_82571PT_QUAD_COPPER:
  267. adapter->flags |= FLAG_IS_QUAD_PORT;
  268. /* mark the first port */
  269. if (global_quad_port_a == 0)
  270. adapter->flags |= FLAG_IS_QUAD_PORT_A;
  271. /* Reset for multiple quad port adapters */
  272. global_quad_port_a++;
  273. if (global_quad_port_a == 4)
  274. global_quad_port_a = 0;
  275. break;
  276. default:
  277. break;
  278. }
  279. switch (adapter->hw.mac.type) {
  280. case e1000_82571:
  281. /* these dual ports don't have WoL on port B at all */
  282. if (((pdev->device == E1000_DEV_ID_82571EB_FIBER) ||
  283. (pdev->device == E1000_DEV_ID_82571EB_SERDES) ||
  284. (pdev->device == E1000_DEV_ID_82571EB_COPPER)) &&
  285. (is_port_b))
  286. adapter->flags &= ~FLAG_HAS_WOL;
  287. /* quad ports only support WoL on port A */
  288. if (adapter->flags & FLAG_IS_QUAD_PORT &&
  289. (!(adapter->flags & FLAG_IS_QUAD_PORT_A)))
  290. adapter->flags &= ~FLAG_HAS_WOL;
  291. /* Does not support WoL on any port */
  292. if (pdev->device == E1000_DEV_ID_82571EB_SERDES_QUAD)
  293. adapter->flags &= ~FLAG_HAS_WOL;
  294. break;
  295. case e1000_82573:
  296. if (pdev->device == E1000_DEV_ID_82573L) {
  297. if (e1000_read_nvm(&adapter->hw, NVM_INIT_3GIO_3, 1,
  298. &eeprom_data) < 0)
  299. break;
  300. if (eeprom_data & NVM_WORD1A_ASPM_MASK)
  301. adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
  302. }
  303. break;
  304. default:
  305. break;
  306. }
  307. return 0;
  308. }
  309. /**
  310. * e1000_get_phy_id_82571 - Retrieve the PHY ID and revision
  311. * @hw: pointer to the HW structure
  312. *
  313. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  314. * revision in the hardware structure.
  315. **/
  316. static s32 e1000_get_phy_id_82571(struct e1000_hw *hw)
  317. {
  318. struct e1000_phy_info *phy = &hw->phy;
  319. s32 ret_val;
  320. u16 phy_id = 0;
  321. switch (hw->mac.type) {
  322. case e1000_82571:
  323. case e1000_82572:
  324. /*
  325. * The 82571 firmware may still be configuring the PHY.
  326. * In this case, we cannot access the PHY until the
  327. * configuration is done. So we explicitly set the
  328. * PHY ID.
  329. */
  330. phy->id = IGP01E1000_I_PHY_ID;
  331. break;
  332. case e1000_82573:
  333. return e1000e_get_phy_id(hw);
  334. break;
  335. case e1000_82574:
  336. ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
  337. if (ret_val)
  338. return ret_val;
  339. phy->id = (u32)(phy_id << 16);
  340. udelay(20);
  341. ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
  342. if (ret_val)
  343. return ret_val;
  344. phy->id |= (u32)(phy_id);
  345. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  346. break;
  347. default:
  348. return -E1000_ERR_PHY;
  349. break;
  350. }
  351. return 0;
  352. }
  353. /**
  354. * e1000_get_hw_semaphore_82571 - Acquire hardware semaphore
  355. * @hw: pointer to the HW structure
  356. *
  357. * Acquire the HW semaphore to access the PHY or NVM
  358. **/
  359. static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw)
  360. {
  361. u32 swsm;
  362. s32 timeout = hw->nvm.word_size + 1;
  363. s32 i = 0;
  364. /* Get the FW semaphore. */
  365. for (i = 0; i < timeout; i++) {
  366. swsm = er32(SWSM);
  367. ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
  368. /* Semaphore acquired if bit latched */
  369. if (er32(SWSM) & E1000_SWSM_SWESMBI)
  370. break;
  371. udelay(50);
  372. }
  373. if (i == timeout) {
  374. /* Release semaphores */
  375. e1000e_put_hw_semaphore(hw);
  376. hw_dbg(hw, "Driver can't access the NVM\n");
  377. return -E1000_ERR_NVM;
  378. }
  379. return 0;
  380. }
  381. /**
  382. * e1000_put_hw_semaphore_82571 - Release hardware semaphore
  383. * @hw: pointer to the HW structure
  384. *
  385. * Release hardware semaphore used to access the PHY or NVM
  386. **/
  387. static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw)
  388. {
  389. u32 swsm;
  390. swsm = er32(SWSM);
  391. swsm &= ~E1000_SWSM_SWESMBI;
  392. ew32(SWSM, swsm);
  393. }
  394. /**
  395. * e1000_acquire_nvm_82571 - Request for access to the EEPROM
  396. * @hw: pointer to the HW structure
  397. *
  398. * To gain access to the EEPROM, first we must obtain a hardware semaphore.
  399. * Then for non-82573 hardware, set the EEPROM access request bit and wait
  400. * for EEPROM access grant bit. If the access grant bit is not set, release
  401. * hardware semaphore.
  402. **/
  403. static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw)
  404. {
  405. s32 ret_val;
  406. ret_val = e1000_get_hw_semaphore_82571(hw);
  407. if (ret_val)
  408. return ret_val;
  409. if (hw->mac.type != e1000_82573 && hw->mac.type != e1000_82574)
  410. ret_val = e1000e_acquire_nvm(hw);
  411. if (ret_val)
  412. e1000_put_hw_semaphore_82571(hw);
  413. return ret_val;
  414. }
  415. /**
  416. * e1000_release_nvm_82571 - Release exclusive access to EEPROM
  417. * @hw: pointer to the HW structure
  418. *
  419. * Stop any current commands to the EEPROM and clear the EEPROM request bit.
  420. **/
  421. static void e1000_release_nvm_82571(struct e1000_hw *hw)
  422. {
  423. e1000e_release_nvm(hw);
  424. e1000_put_hw_semaphore_82571(hw);
  425. }
  426. /**
  427. * e1000_write_nvm_82571 - Write to EEPROM using appropriate interface
  428. * @hw: pointer to the HW structure
  429. * @offset: offset within the EEPROM to be written to
  430. * @words: number of words to write
  431. * @data: 16 bit word(s) to be written to the EEPROM
  432. *
  433. * For non-82573 silicon, write data to EEPROM at offset using SPI interface.
  434. *
  435. * If e1000e_update_nvm_checksum is not called after this function, the
  436. * EEPROM will most likely contain an invalid checksum.
  437. **/
  438. static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset, u16 words,
  439. u16 *data)
  440. {
  441. s32 ret_val;
  442. switch (hw->mac.type) {
  443. case e1000_82573:
  444. case e1000_82574:
  445. ret_val = e1000_write_nvm_eewr_82571(hw, offset, words, data);
  446. break;
  447. case e1000_82571:
  448. case e1000_82572:
  449. ret_val = e1000e_write_nvm_spi(hw, offset, words, data);
  450. break;
  451. default:
  452. ret_val = -E1000_ERR_NVM;
  453. break;
  454. }
  455. return ret_val;
  456. }
  457. /**
  458. * e1000_update_nvm_checksum_82571 - Update EEPROM checksum
  459. * @hw: pointer to the HW structure
  460. *
  461. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  462. * up to the checksum. Then calculates the EEPROM checksum and writes the
  463. * value to the EEPROM.
  464. **/
  465. static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw)
  466. {
  467. u32 eecd;
  468. s32 ret_val;
  469. u16 i;
  470. ret_val = e1000e_update_nvm_checksum_generic(hw);
  471. if (ret_val)
  472. return ret_val;
  473. /*
  474. * If our nvm is an EEPROM, then we're done
  475. * otherwise, commit the checksum to the flash NVM.
  476. */
  477. if (hw->nvm.type != e1000_nvm_flash_hw)
  478. return ret_val;
  479. /* Check for pending operations. */
  480. for (i = 0; i < E1000_FLASH_UPDATES; i++) {
  481. msleep(1);
  482. if ((er32(EECD) & E1000_EECD_FLUPD) == 0)
  483. break;
  484. }
  485. if (i == E1000_FLASH_UPDATES)
  486. return -E1000_ERR_NVM;
  487. /* Reset the firmware if using STM opcode. */
  488. if ((er32(FLOP) & 0xFF00) == E1000_STM_OPCODE) {
  489. /*
  490. * The enabling of and the actual reset must be done
  491. * in two write cycles.
  492. */
  493. ew32(HICR, E1000_HICR_FW_RESET_ENABLE);
  494. e1e_flush();
  495. ew32(HICR, E1000_HICR_FW_RESET);
  496. }
  497. /* Commit the write to flash */
  498. eecd = er32(EECD) | E1000_EECD_FLUPD;
  499. ew32(EECD, eecd);
  500. for (i = 0; i < E1000_FLASH_UPDATES; i++) {
  501. msleep(1);
  502. if ((er32(EECD) & E1000_EECD_FLUPD) == 0)
  503. break;
  504. }
  505. if (i == E1000_FLASH_UPDATES)
  506. return -E1000_ERR_NVM;
  507. return 0;
  508. }
  509. /**
  510. * e1000_validate_nvm_checksum_82571 - Validate EEPROM checksum
  511. * @hw: pointer to the HW structure
  512. *
  513. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  514. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  515. **/
  516. static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw)
  517. {
  518. if (hw->nvm.type == e1000_nvm_flash_hw)
  519. e1000_fix_nvm_checksum_82571(hw);
  520. return e1000e_validate_nvm_checksum_generic(hw);
  521. }
  522. /**
  523. * e1000_write_nvm_eewr_82571 - Write to EEPROM for 82573 silicon
  524. * @hw: pointer to the HW structure
  525. * @offset: offset within the EEPROM to be written to
  526. * @words: number of words to write
  527. * @data: 16 bit word(s) to be written to the EEPROM
  528. *
  529. * After checking for invalid values, poll the EEPROM to ensure the previous
  530. * command has completed before trying to write the next word. After write
  531. * poll for completion.
  532. *
  533. * If e1000e_update_nvm_checksum is not called after this function, the
  534. * EEPROM will most likely contain an invalid checksum.
  535. **/
  536. static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
  537. u16 words, u16 *data)
  538. {
  539. struct e1000_nvm_info *nvm = &hw->nvm;
  540. u32 i;
  541. u32 eewr = 0;
  542. s32 ret_val = 0;
  543. /*
  544. * A check for invalid values: offset too large, too many words,
  545. * and not enough words.
  546. */
  547. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  548. (words == 0)) {
  549. hw_dbg(hw, "nvm parameter(s) out of bounds\n");
  550. return -E1000_ERR_NVM;
  551. }
  552. for (i = 0; i < words; i++) {
  553. eewr = (data[i] << E1000_NVM_RW_REG_DATA) |
  554. ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
  555. E1000_NVM_RW_REG_START;
  556. ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
  557. if (ret_val)
  558. break;
  559. ew32(EEWR, eewr);
  560. ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
  561. if (ret_val)
  562. break;
  563. }
  564. return ret_val;
  565. }
  566. /**
  567. * e1000_get_cfg_done_82571 - Poll for configuration done
  568. * @hw: pointer to the HW structure
  569. *
  570. * Reads the management control register for the config done bit to be set.
  571. **/
  572. static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw)
  573. {
  574. s32 timeout = PHY_CFG_TIMEOUT;
  575. while (timeout) {
  576. if (er32(EEMNGCTL) &
  577. E1000_NVM_CFG_DONE_PORT_0)
  578. break;
  579. msleep(1);
  580. timeout--;
  581. }
  582. if (!timeout) {
  583. hw_dbg(hw, "MNG configuration cycle has not completed.\n");
  584. return -E1000_ERR_RESET;
  585. }
  586. return 0;
  587. }
  588. /**
  589. * e1000_set_d0_lplu_state_82571 - Set Low Power Linkup D0 state
  590. * @hw: pointer to the HW structure
  591. * @active: TRUE to enable LPLU, FALSE to disable
  592. *
  593. * Sets the LPLU D0 state according to the active flag. When activating LPLU
  594. * this function also disables smart speed and vice versa. LPLU will not be
  595. * activated unless the device autonegotiation advertisement meets standards
  596. * of either 10 or 10/100 or 10/100/1000 at all duplexes. This is a function
  597. * pointer entry point only called by PHY setup routines.
  598. **/
  599. static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw, bool active)
  600. {
  601. struct e1000_phy_info *phy = &hw->phy;
  602. s32 ret_val;
  603. u16 data;
  604. ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  605. if (ret_val)
  606. return ret_val;
  607. if (active) {
  608. data |= IGP02E1000_PM_D0_LPLU;
  609. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  610. if (ret_val)
  611. return ret_val;
  612. /* When LPLU is enabled, we should disable SmartSpeed */
  613. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  614. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  615. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  616. if (ret_val)
  617. return ret_val;
  618. } else {
  619. data &= ~IGP02E1000_PM_D0_LPLU;
  620. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  621. /*
  622. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  623. * during Dx states where the power conservation is most
  624. * important. During driver activity we should enable
  625. * SmartSpeed, so performance is maintained.
  626. */
  627. if (phy->smart_speed == e1000_smart_speed_on) {
  628. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  629. &data);
  630. if (ret_val)
  631. return ret_val;
  632. data |= IGP01E1000_PSCFR_SMART_SPEED;
  633. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  634. data);
  635. if (ret_val)
  636. return ret_val;
  637. } else if (phy->smart_speed == e1000_smart_speed_off) {
  638. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  639. &data);
  640. if (ret_val)
  641. return ret_val;
  642. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  643. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  644. data);
  645. if (ret_val)
  646. return ret_val;
  647. }
  648. }
  649. return 0;
  650. }
  651. /**
  652. * e1000_reset_hw_82571 - Reset hardware
  653. * @hw: pointer to the HW structure
  654. *
  655. * This resets the hardware into a known state. This is a
  656. * function pointer entry point called by the api module.
  657. **/
  658. static s32 e1000_reset_hw_82571(struct e1000_hw *hw)
  659. {
  660. u32 ctrl;
  661. u32 extcnf_ctrl;
  662. u32 ctrl_ext;
  663. u32 icr;
  664. s32 ret_val;
  665. u16 i = 0;
  666. /*
  667. * Prevent the PCI-E bus from sticking if there is no TLP connection
  668. * on the last TLP read/write transaction when MAC is reset.
  669. */
  670. ret_val = e1000e_disable_pcie_master(hw);
  671. if (ret_val)
  672. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  673. hw_dbg(hw, "Masking off all interrupts\n");
  674. ew32(IMC, 0xffffffff);
  675. ew32(RCTL, 0);
  676. ew32(TCTL, E1000_TCTL_PSP);
  677. e1e_flush();
  678. msleep(10);
  679. /*
  680. * Must acquire the MDIO ownership before MAC reset.
  681. * Ownership defaults to firmware after a reset.
  682. */
  683. if (hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574) {
  684. extcnf_ctrl = er32(EXTCNF_CTRL);
  685. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  686. do {
  687. ew32(EXTCNF_CTRL, extcnf_ctrl);
  688. extcnf_ctrl = er32(EXTCNF_CTRL);
  689. if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
  690. break;
  691. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  692. msleep(2);
  693. i++;
  694. } while (i < MDIO_OWNERSHIP_TIMEOUT);
  695. }
  696. ctrl = er32(CTRL);
  697. hw_dbg(hw, "Issuing a global reset to MAC\n");
  698. ew32(CTRL, ctrl | E1000_CTRL_RST);
  699. if (hw->nvm.type == e1000_nvm_flash_hw) {
  700. udelay(10);
  701. ctrl_ext = er32(CTRL_EXT);
  702. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  703. ew32(CTRL_EXT, ctrl_ext);
  704. e1e_flush();
  705. }
  706. ret_val = e1000e_get_auto_rd_done(hw);
  707. if (ret_val)
  708. /* We don't want to continue accessing MAC registers. */
  709. return ret_val;
  710. /*
  711. * Phy configuration from NVM just starts after EECD_AUTO_RD is set.
  712. * Need to wait for Phy configuration completion before accessing
  713. * NVM and Phy.
  714. */
  715. if (hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574)
  716. msleep(25);
  717. /* Clear any pending interrupt events. */
  718. ew32(IMC, 0xffffffff);
  719. icr = er32(ICR);
  720. if (hw->mac.type == e1000_82571 &&
  721. hw->dev_spec.e82571.alt_mac_addr_is_present)
  722. e1000e_set_laa_state_82571(hw, true);
  723. /* Reinitialize the 82571 serdes link state machine */
  724. if (hw->phy.media_type == e1000_media_type_internal_serdes)
  725. hw->mac.serdes_link_state = e1000_serdes_link_down;
  726. return 0;
  727. }
  728. /**
  729. * e1000_init_hw_82571 - Initialize hardware
  730. * @hw: pointer to the HW structure
  731. *
  732. * This inits the hardware readying it for operation.
  733. **/
  734. static s32 e1000_init_hw_82571(struct e1000_hw *hw)
  735. {
  736. struct e1000_mac_info *mac = &hw->mac;
  737. u32 reg_data;
  738. s32 ret_val;
  739. u16 i;
  740. u16 rar_count = mac->rar_entry_count;
  741. e1000_initialize_hw_bits_82571(hw);
  742. /* Initialize identification LED */
  743. ret_val = e1000e_id_led_init(hw);
  744. if (ret_val) {
  745. hw_dbg(hw, "Error initializing identification LED\n");
  746. return ret_val;
  747. }
  748. /* Disabling VLAN filtering */
  749. hw_dbg(hw, "Initializing the IEEE VLAN\n");
  750. e1000e_clear_vfta(hw);
  751. /* Setup the receive address. */
  752. /*
  753. * If, however, a locally administered address was assigned to the
  754. * 82571, we must reserve a RAR for it to work around an issue where
  755. * resetting one port will reload the MAC on the other port.
  756. */
  757. if (e1000e_get_laa_state_82571(hw))
  758. rar_count--;
  759. e1000e_init_rx_addrs(hw, rar_count);
  760. /* Zero out the Multicast HASH table */
  761. hw_dbg(hw, "Zeroing the MTA\n");
  762. for (i = 0; i < mac->mta_reg_count; i++)
  763. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  764. /* Setup link and flow control */
  765. ret_val = e1000_setup_link_82571(hw);
  766. /* Set the transmit descriptor write-back policy */
  767. reg_data = er32(TXDCTL(0));
  768. reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
  769. E1000_TXDCTL_FULL_TX_DESC_WB |
  770. E1000_TXDCTL_COUNT_DESC;
  771. ew32(TXDCTL(0), reg_data);
  772. /* ...for both queues. */
  773. if (mac->type != e1000_82573 && mac->type != e1000_82574) {
  774. reg_data = er32(TXDCTL(1));
  775. reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
  776. E1000_TXDCTL_FULL_TX_DESC_WB |
  777. E1000_TXDCTL_COUNT_DESC;
  778. ew32(TXDCTL(1), reg_data);
  779. } else {
  780. e1000e_enable_tx_pkt_filtering(hw);
  781. reg_data = er32(GCR);
  782. reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  783. ew32(GCR, reg_data);
  784. }
  785. /*
  786. * Clear all of the statistics registers (clear on read). It is
  787. * important that we do this after we have tried to establish link
  788. * because the symbol error count will increment wildly if there
  789. * is no link.
  790. */
  791. e1000_clear_hw_cntrs_82571(hw);
  792. return ret_val;
  793. }
  794. /**
  795. * e1000_initialize_hw_bits_82571 - Initialize hardware-dependent bits
  796. * @hw: pointer to the HW structure
  797. *
  798. * Initializes required hardware-dependent bits needed for normal operation.
  799. **/
  800. static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw)
  801. {
  802. u32 reg;
  803. /* Transmit Descriptor Control 0 */
  804. reg = er32(TXDCTL(0));
  805. reg |= (1 << 22);
  806. ew32(TXDCTL(0), reg);
  807. /* Transmit Descriptor Control 1 */
  808. reg = er32(TXDCTL(1));
  809. reg |= (1 << 22);
  810. ew32(TXDCTL(1), reg);
  811. /* Transmit Arbitration Control 0 */
  812. reg = er32(TARC(0));
  813. reg &= ~(0xF << 27); /* 30:27 */
  814. switch (hw->mac.type) {
  815. case e1000_82571:
  816. case e1000_82572:
  817. reg |= (1 << 23) | (1 << 24) | (1 << 25) | (1 << 26);
  818. break;
  819. default:
  820. break;
  821. }
  822. ew32(TARC(0), reg);
  823. /* Transmit Arbitration Control 1 */
  824. reg = er32(TARC(1));
  825. switch (hw->mac.type) {
  826. case e1000_82571:
  827. case e1000_82572:
  828. reg &= ~((1 << 29) | (1 << 30));
  829. reg |= (1 << 22) | (1 << 24) | (1 << 25) | (1 << 26);
  830. if (er32(TCTL) & E1000_TCTL_MULR)
  831. reg &= ~(1 << 28);
  832. else
  833. reg |= (1 << 28);
  834. ew32(TARC(1), reg);
  835. break;
  836. default:
  837. break;
  838. }
  839. /* Device Control */
  840. if (hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574) {
  841. reg = er32(CTRL);
  842. reg &= ~(1 << 29);
  843. ew32(CTRL, reg);
  844. }
  845. /* Extended Device Control */
  846. if (hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574) {
  847. reg = er32(CTRL_EXT);
  848. reg &= ~(1 << 23);
  849. reg |= (1 << 22);
  850. ew32(CTRL_EXT, reg);
  851. }
  852. if (hw->mac.type == e1000_82571) {
  853. reg = er32(PBA_ECC);
  854. reg |= E1000_PBA_ECC_CORR_EN;
  855. ew32(PBA_ECC, reg);
  856. }
  857. /*
  858. * Workaround for hardware errata.
  859. * Ensure that DMA Dynamic Clock gating is disabled on 82571 and 82572
  860. */
  861. if ((hw->mac.type == e1000_82571) ||
  862. (hw->mac.type == e1000_82572)) {
  863. reg = er32(CTRL_EXT);
  864. reg &= ~E1000_CTRL_EXT_DMA_DYN_CLK_EN;
  865. ew32(CTRL_EXT, reg);
  866. }
  867. /* PCI-Ex Control Registers */
  868. if (hw->mac.type == e1000_82574) {
  869. reg = er32(GCR);
  870. reg |= (1 << 22);
  871. ew32(GCR, reg);
  872. reg = er32(GCR2);
  873. reg |= 1;
  874. ew32(GCR2, reg);
  875. }
  876. return;
  877. }
  878. /**
  879. * e1000e_clear_vfta - Clear VLAN filter table
  880. * @hw: pointer to the HW structure
  881. *
  882. * Clears the register array which contains the VLAN filter table by
  883. * setting all the values to 0.
  884. **/
  885. void e1000e_clear_vfta(struct e1000_hw *hw)
  886. {
  887. u32 offset;
  888. u32 vfta_value = 0;
  889. u32 vfta_offset = 0;
  890. u32 vfta_bit_in_reg = 0;
  891. if (hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574) {
  892. if (hw->mng_cookie.vlan_id != 0) {
  893. /*
  894. * The VFTA is a 4096b bit-field, each identifying
  895. * a single VLAN ID. The following operations
  896. * determine which 32b entry (i.e. offset) into the
  897. * array we want to set the VLAN ID (i.e. bit) of
  898. * the manageability unit.
  899. */
  900. vfta_offset = (hw->mng_cookie.vlan_id >>
  901. E1000_VFTA_ENTRY_SHIFT) &
  902. E1000_VFTA_ENTRY_MASK;
  903. vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
  904. E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
  905. }
  906. }
  907. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  908. /*
  909. * If the offset we want to clear is the same offset of the
  910. * manageability VLAN ID, then clear all bits except that of
  911. * the manageability unit.
  912. */
  913. vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
  914. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, vfta_value);
  915. e1e_flush();
  916. }
  917. }
  918. /**
  919. * e1000_check_mng_mode_82574 - Check manageability is enabled
  920. * @hw: pointer to the HW structure
  921. *
  922. * Reads the NVM Initialization Control Word 2 and returns true
  923. * (>0) if any manageability is enabled, else false (0).
  924. **/
  925. static bool e1000_check_mng_mode_82574(struct e1000_hw *hw)
  926. {
  927. u16 data;
  928. e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
  929. return (data & E1000_NVM_INIT_CTRL2_MNGM) != 0;
  930. }
  931. /**
  932. * e1000_led_on_82574 - Turn LED on
  933. * @hw: pointer to the HW structure
  934. *
  935. * Turn LED on.
  936. **/
  937. static s32 e1000_led_on_82574(struct e1000_hw *hw)
  938. {
  939. u32 ctrl;
  940. u32 i;
  941. ctrl = hw->mac.ledctl_mode2;
  942. if (!(E1000_STATUS_LU & er32(STATUS))) {
  943. /*
  944. * If no link, then turn LED on by setting the invert bit
  945. * for each LED that's "on" (0x0E) in ledctl_mode2.
  946. */
  947. for (i = 0; i < 4; i++)
  948. if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
  949. E1000_LEDCTL_MODE_LED_ON)
  950. ctrl |= (E1000_LEDCTL_LED0_IVRT << (i * 8));
  951. }
  952. ew32(LEDCTL, ctrl);
  953. return 0;
  954. }
  955. /**
  956. * e1000_update_mc_addr_list_82571 - Update Multicast addresses
  957. * @hw: pointer to the HW structure
  958. * @mc_addr_list: array of multicast addresses to program
  959. * @mc_addr_count: number of multicast addresses to program
  960. * @rar_used_count: the first RAR register free to program
  961. * @rar_count: total number of supported Receive Address Registers
  962. *
  963. * Updates the Receive Address Registers and Multicast Table Array.
  964. * The caller must have a packed mc_addr_list of multicast addresses.
  965. * The parameter rar_count will usually be hw->mac.rar_entry_count
  966. * unless there are workarounds that change this.
  967. **/
  968. static void e1000_update_mc_addr_list_82571(struct e1000_hw *hw,
  969. u8 *mc_addr_list,
  970. u32 mc_addr_count,
  971. u32 rar_used_count,
  972. u32 rar_count)
  973. {
  974. if (e1000e_get_laa_state_82571(hw))
  975. rar_count--;
  976. e1000e_update_mc_addr_list_generic(hw, mc_addr_list, mc_addr_count,
  977. rar_used_count, rar_count);
  978. }
  979. /**
  980. * e1000_setup_link_82571 - Setup flow control and link settings
  981. * @hw: pointer to the HW structure
  982. *
  983. * Determines which flow control settings to use, then configures flow
  984. * control. Calls the appropriate media-specific link configuration
  985. * function. Assuming the adapter has a valid link partner, a valid link
  986. * should be established. Assumes the hardware has previously been reset
  987. * and the transmitter and receiver are not enabled.
  988. **/
  989. static s32 e1000_setup_link_82571(struct e1000_hw *hw)
  990. {
  991. /*
  992. * 82573 does not have a word in the NVM to determine
  993. * the default flow control setting, so we explicitly
  994. * set it to full.
  995. */
  996. if ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574) &&
  997. hw->fc.requested_mode == e1000_fc_default)
  998. hw->fc.requested_mode = e1000_fc_full;
  999. return e1000e_setup_link(hw);
  1000. }
  1001. /**
  1002. * e1000_setup_copper_link_82571 - Configure copper link settings
  1003. * @hw: pointer to the HW structure
  1004. *
  1005. * Configures the link for auto-neg or forced speed and duplex. Then we check
  1006. * for link, once link is established calls to configure collision distance
  1007. * and flow control are called.
  1008. **/
  1009. static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw)
  1010. {
  1011. u32 ctrl;
  1012. u32 led_ctrl;
  1013. s32 ret_val;
  1014. ctrl = er32(CTRL);
  1015. ctrl |= E1000_CTRL_SLU;
  1016. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1017. ew32(CTRL, ctrl);
  1018. switch (hw->phy.type) {
  1019. case e1000_phy_m88:
  1020. case e1000_phy_bm:
  1021. ret_val = e1000e_copper_link_setup_m88(hw);
  1022. break;
  1023. case e1000_phy_igp_2:
  1024. ret_val = e1000e_copper_link_setup_igp(hw);
  1025. /* Setup activity LED */
  1026. led_ctrl = er32(LEDCTL);
  1027. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  1028. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  1029. ew32(LEDCTL, led_ctrl);
  1030. break;
  1031. default:
  1032. return -E1000_ERR_PHY;
  1033. break;
  1034. }
  1035. if (ret_val)
  1036. return ret_val;
  1037. ret_val = e1000e_setup_copper_link(hw);
  1038. return ret_val;
  1039. }
  1040. /**
  1041. * e1000_setup_fiber_serdes_link_82571 - Setup link for fiber/serdes
  1042. * @hw: pointer to the HW structure
  1043. *
  1044. * Configures collision distance and flow control for fiber and serdes links.
  1045. * Upon successful setup, poll for link.
  1046. **/
  1047. static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw)
  1048. {
  1049. switch (hw->mac.type) {
  1050. case e1000_82571:
  1051. case e1000_82572:
  1052. /*
  1053. * If SerDes loopback mode is entered, there is no form
  1054. * of reset to take the adapter out of that mode. So we
  1055. * have to explicitly take the adapter out of loopback
  1056. * mode. This prevents drivers from twiddling their thumbs
  1057. * if another tool failed to take it out of loopback mode.
  1058. */
  1059. ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1060. break;
  1061. default:
  1062. break;
  1063. }
  1064. return e1000e_setup_fiber_serdes_link(hw);
  1065. }
  1066. /**
  1067. * e1000_check_for_serdes_link_82571 - Check for link (Serdes)
  1068. * @hw: pointer to the HW structure
  1069. *
  1070. * Checks for link up on the hardware. If link is not up and we have
  1071. * a signal, then we need to force link up.
  1072. **/
  1073. s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw)
  1074. {
  1075. struct e1000_mac_info *mac = &hw->mac;
  1076. u32 rxcw;
  1077. u32 ctrl;
  1078. u32 status;
  1079. s32 ret_val = 0;
  1080. ctrl = er32(CTRL);
  1081. status = er32(STATUS);
  1082. rxcw = er32(RXCW);
  1083. if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
  1084. /* Receiver is synchronized with no invalid bits. */
  1085. switch (mac->serdes_link_state) {
  1086. case e1000_serdes_link_autoneg_complete:
  1087. if (!(status & E1000_STATUS_LU)) {
  1088. /*
  1089. * We have lost link, retry autoneg before
  1090. * reporting link failure
  1091. */
  1092. mac->serdes_link_state =
  1093. e1000_serdes_link_autoneg_progress;
  1094. hw_dbg(hw, "AN_UP -> AN_PROG\n");
  1095. }
  1096. break;
  1097. case e1000_serdes_link_forced_up:
  1098. /*
  1099. * If we are receiving /C/ ordered sets, re-enable
  1100. * auto-negotiation in the TXCW register and disable
  1101. * forced link in the Device Control register in an
  1102. * attempt to auto-negotiate with our link partner.
  1103. */
  1104. if (rxcw & E1000_RXCW_C) {
  1105. /* Enable autoneg, and unforce link up */
  1106. ew32(TXCW, mac->txcw);
  1107. ew32(CTRL,
  1108. (ctrl & ~E1000_CTRL_SLU));
  1109. mac->serdes_link_state =
  1110. e1000_serdes_link_autoneg_progress;
  1111. hw_dbg(hw, "FORCED_UP -> AN_PROG\n");
  1112. }
  1113. break;
  1114. case e1000_serdes_link_autoneg_progress:
  1115. /*
  1116. * If the LU bit is set in the STATUS register,
  1117. * autoneg has completed sucessfully. If not,
  1118. * try foring the link because the far end may be
  1119. * available but not capable of autonegotiation.
  1120. */
  1121. if (status & E1000_STATUS_LU) {
  1122. mac->serdes_link_state =
  1123. e1000_serdes_link_autoneg_complete;
  1124. hw_dbg(hw, "AN_PROG -> AN_UP\n");
  1125. } else {
  1126. /*
  1127. * Disable autoneg, force link up and
  1128. * full duplex, and change state to forced
  1129. */
  1130. ew32(TXCW,
  1131. (mac->txcw & ~E1000_TXCW_ANE));
  1132. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  1133. ew32(CTRL, ctrl);
  1134. /* Configure Flow Control after link up. */
  1135. ret_val =
  1136. e1000e_config_fc_after_link_up(hw);
  1137. if (ret_val) {
  1138. hw_dbg(hw, "Error config flow control\n");
  1139. break;
  1140. }
  1141. mac->serdes_link_state =
  1142. e1000_serdes_link_forced_up;
  1143. hw_dbg(hw, "AN_PROG -> FORCED_UP\n");
  1144. }
  1145. mac->serdes_has_link = true;
  1146. break;
  1147. case e1000_serdes_link_down:
  1148. default:
  1149. /* The link was down but the receiver has now gained
  1150. * valid sync, so lets see if we can bring the link
  1151. * up. */
  1152. ew32(TXCW, mac->txcw);
  1153. ew32(CTRL,
  1154. (ctrl & ~E1000_CTRL_SLU));
  1155. mac->serdes_link_state =
  1156. e1000_serdes_link_autoneg_progress;
  1157. hw_dbg(hw, "DOWN -> AN_PROG\n");
  1158. break;
  1159. }
  1160. } else {
  1161. if (!(rxcw & E1000_RXCW_SYNCH)) {
  1162. mac->serdes_has_link = false;
  1163. mac->serdes_link_state = e1000_serdes_link_down;
  1164. hw_dbg(hw, "ANYSTATE -> DOWN\n");
  1165. } else {
  1166. /*
  1167. * We have sync, and can tolerate one
  1168. * invalid (IV) codeword before declaring
  1169. * link down, so reread to look again
  1170. */
  1171. udelay(10);
  1172. rxcw = er32(RXCW);
  1173. if (rxcw & E1000_RXCW_IV) {
  1174. mac->serdes_link_state = e1000_serdes_link_down;
  1175. mac->serdes_has_link = false;
  1176. hw_dbg(hw, "ANYSTATE -> DOWN\n");
  1177. }
  1178. }
  1179. }
  1180. return ret_val;
  1181. }
  1182. /**
  1183. * e1000_valid_led_default_82571 - Verify a valid default LED config
  1184. * @hw: pointer to the HW structure
  1185. * @data: pointer to the NVM (EEPROM)
  1186. *
  1187. * Read the EEPROM for the current default LED configuration. If the
  1188. * LED configuration is not valid, set to a valid LED configuration.
  1189. **/
  1190. static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data)
  1191. {
  1192. s32 ret_val;
  1193. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1194. if (ret_val) {
  1195. hw_dbg(hw, "NVM Read Error\n");
  1196. return ret_val;
  1197. }
  1198. if ((hw->mac.type == e1000_82573 || hw->mac.type == e1000_82574) &&
  1199. *data == ID_LED_RESERVED_F746)
  1200. *data = ID_LED_DEFAULT_82573;
  1201. else if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  1202. *data = ID_LED_DEFAULT;
  1203. return 0;
  1204. }
  1205. /**
  1206. * e1000e_get_laa_state_82571 - Get locally administered address state
  1207. * @hw: pointer to the HW structure
  1208. *
  1209. * Retrieve and return the current locally administered address state.
  1210. **/
  1211. bool e1000e_get_laa_state_82571(struct e1000_hw *hw)
  1212. {
  1213. if (hw->mac.type != e1000_82571)
  1214. return 0;
  1215. return hw->dev_spec.e82571.laa_is_present;
  1216. }
  1217. /**
  1218. * e1000e_set_laa_state_82571 - Set locally administered address state
  1219. * @hw: pointer to the HW structure
  1220. * @state: enable/disable locally administered address
  1221. *
  1222. * Enable/Disable the current locally administers address state.
  1223. **/
  1224. void e1000e_set_laa_state_82571(struct e1000_hw *hw, bool state)
  1225. {
  1226. if (hw->mac.type != e1000_82571)
  1227. return;
  1228. hw->dev_spec.e82571.laa_is_present = state;
  1229. /* If workaround is activated... */
  1230. if (state)
  1231. /*
  1232. * Hold a copy of the LAA in RAR[14] This is done so that
  1233. * between the time RAR[0] gets clobbered and the time it
  1234. * gets fixed, the actual LAA is in one of the RARs and no
  1235. * incoming packets directed to this port are dropped.
  1236. * Eventually the LAA will be in RAR[0] and RAR[14].
  1237. */
  1238. e1000e_rar_set(hw, hw->mac.addr, hw->mac.rar_entry_count - 1);
  1239. }
  1240. /**
  1241. * e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
  1242. * @hw: pointer to the HW structure
  1243. *
  1244. * Verifies that the EEPROM has completed the update. After updating the
  1245. * EEPROM, we need to check bit 15 in work 0x23 for the checksum fix. If
  1246. * the checksum fix is not implemented, we need to set the bit and update
  1247. * the checksum. Otherwise, if bit 15 is set and the checksum is incorrect,
  1248. * we need to return bad checksum.
  1249. **/
  1250. static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
  1251. {
  1252. struct e1000_nvm_info *nvm = &hw->nvm;
  1253. s32 ret_val;
  1254. u16 data;
  1255. if (nvm->type != e1000_nvm_flash_hw)
  1256. return 0;
  1257. /*
  1258. * Check bit 4 of word 10h. If it is 0, firmware is done updating
  1259. * 10h-12h. Checksum may need to be fixed.
  1260. */
  1261. ret_val = e1000_read_nvm(hw, 0x10, 1, &data);
  1262. if (ret_val)
  1263. return ret_val;
  1264. if (!(data & 0x10)) {
  1265. /*
  1266. * Read 0x23 and check bit 15. This bit is a 1
  1267. * when the checksum has already been fixed. If
  1268. * the checksum is still wrong and this bit is a
  1269. * 1, we need to return bad checksum. Otherwise,
  1270. * we need to set this bit to a 1 and update the
  1271. * checksum.
  1272. */
  1273. ret_val = e1000_read_nvm(hw, 0x23, 1, &data);
  1274. if (ret_val)
  1275. return ret_val;
  1276. if (!(data & 0x8000)) {
  1277. data |= 0x8000;
  1278. ret_val = e1000_write_nvm(hw, 0x23, 1, &data);
  1279. if (ret_val)
  1280. return ret_val;
  1281. ret_val = e1000e_update_nvm_checksum(hw);
  1282. }
  1283. }
  1284. return 0;
  1285. }
  1286. /**
  1287. * e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
  1288. * @hw: pointer to the HW structure
  1289. *
  1290. * Clears the hardware counters by reading the counter registers.
  1291. **/
  1292. static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
  1293. {
  1294. u32 temp;
  1295. e1000e_clear_hw_cntrs_base(hw);
  1296. temp = er32(PRC64);
  1297. temp = er32(PRC127);
  1298. temp = er32(PRC255);
  1299. temp = er32(PRC511);
  1300. temp = er32(PRC1023);
  1301. temp = er32(PRC1522);
  1302. temp = er32(PTC64);
  1303. temp = er32(PTC127);
  1304. temp = er32(PTC255);
  1305. temp = er32(PTC511);
  1306. temp = er32(PTC1023);
  1307. temp = er32(PTC1522);
  1308. temp = er32(ALGNERRC);
  1309. temp = er32(RXERRC);
  1310. temp = er32(TNCRS);
  1311. temp = er32(CEXTERR);
  1312. temp = er32(TSCTC);
  1313. temp = er32(TSCTFC);
  1314. temp = er32(MGTPRC);
  1315. temp = er32(MGTPDC);
  1316. temp = er32(MGTPTC);
  1317. temp = er32(IAC);
  1318. temp = er32(ICRXOC);
  1319. temp = er32(ICRXPTC);
  1320. temp = er32(ICRXATC);
  1321. temp = er32(ICTXPTC);
  1322. temp = er32(ICTXATC);
  1323. temp = er32(ICTXQEC);
  1324. temp = er32(ICTXQMTC);
  1325. temp = er32(ICRXDMTC);
  1326. }
  1327. static struct e1000_mac_operations e82571_mac_ops = {
  1328. /* .check_mng_mode: mac type dependent */
  1329. /* .check_for_link: media type dependent */
  1330. .cleanup_led = e1000e_cleanup_led_generic,
  1331. .clear_hw_cntrs = e1000_clear_hw_cntrs_82571,
  1332. .get_bus_info = e1000e_get_bus_info_pcie,
  1333. /* .get_link_up_info: media type dependent */
  1334. /* .led_on: mac type dependent */
  1335. .led_off = e1000e_led_off_generic,
  1336. .update_mc_addr_list = e1000_update_mc_addr_list_82571,
  1337. .reset_hw = e1000_reset_hw_82571,
  1338. .init_hw = e1000_init_hw_82571,
  1339. .setup_link = e1000_setup_link_82571,
  1340. /* .setup_physical_interface: media type dependent */
  1341. };
  1342. static struct e1000_phy_operations e82_phy_ops_igp = {
  1343. .acquire_phy = e1000_get_hw_semaphore_82571,
  1344. .check_reset_block = e1000e_check_reset_block_generic,
  1345. .commit_phy = NULL,
  1346. .force_speed_duplex = e1000e_phy_force_speed_duplex_igp,
  1347. .get_cfg_done = e1000_get_cfg_done_82571,
  1348. .get_cable_length = e1000e_get_cable_length_igp_2,
  1349. .get_phy_info = e1000e_get_phy_info_igp,
  1350. .read_phy_reg = e1000e_read_phy_reg_igp,
  1351. .release_phy = e1000_put_hw_semaphore_82571,
  1352. .reset_phy = e1000e_phy_hw_reset_generic,
  1353. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1354. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1355. .write_phy_reg = e1000e_write_phy_reg_igp,
  1356. .cfg_on_link_up = NULL,
  1357. };
  1358. static struct e1000_phy_operations e82_phy_ops_m88 = {
  1359. .acquire_phy = e1000_get_hw_semaphore_82571,
  1360. .check_reset_block = e1000e_check_reset_block_generic,
  1361. .commit_phy = e1000e_phy_sw_reset,
  1362. .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
  1363. .get_cfg_done = e1000e_get_cfg_done,
  1364. .get_cable_length = e1000e_get_cable_length_m88,
  1365. .get_phy_info = e1000e_get_phy_info_m88,
  1366. .read_phy_reg = e1000e_read_phy_reg_m88,
  1367. .release_phy = e1000_put_hw_semaphore_82571,
  1368. .reset_phy = e1000e_phy_hw_reset_generic,
  1369. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1370. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1371. .write_phy_reg = e1000e_write_phy_reg_m88,
  1372. .cfg_on_link_up = NULL,
  1373. };
  1374. static struct e1000_phy_operations e82_phy_ops_bm = {
  1375. .acquire_phy = e1000_get_hw_semaphore_82571,
  1376. .check_reset_block = e1000e_check_reset_block_generic,
  1377. .commit_phy = e1000e_phy_sw_reset,
  1378. .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
  1379. .get_cfg_done = e1000e_get_cfg_done,
  1380. .get_cable_length = e1000e_get_cable_length_m88,
  1381. .get_phy_info = e1000e_get_phy_info_m88,
  1382. .read_phy_reg = e1000e_read_phy_reg_bm2,
  1383. .release_phy = e1000_put_hw_semaphore_82571,
  1384. .reset_phy = e1000e_phy_hw_reset_generic,
  1385. .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
  1386. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1387. .write_phy_reg = e1000e_write_phy_reg_bm2,
  1388. .cfg_on_link_up = NULL,
  1389. };
  1390. static struct e1000_nvm_operations e82571_nvm_ops = {
  1391. .acquire_nvm = e1000_acquire_nvm_82571,
  1392. .read_nvm = e1000e_read_nvm_eerd,
  1393. .release_nvm = e1000_release_nvm_82571,
  1394. .update_nvm = e1000_update_nvm_checksum_82571,
  1395. .valid_led_default = e1000_valid_led_default_82571,
  1396. .validate_nvm = e1000_validate_nvm_checksum_82571,
  1397. .write_nvm = e1000_write_nvm_82571,
  1398. };
  1399. struct e1000_info e1000_82571_info = {
  1400. .mac = e1000_82571,
  1401. .flags = FLAG_HAS_HW_VLAN_FILTER
  1402. | FLAG_HAS_JUMBO_FRAMES
  1403. | FLAG_HAS_WOL
  1404. | FLAG_APME_IN_CTRL3
  1405. | FLAG_RX_CSUM_ENABLED
  1406. | FLAG_HAS_CTRLEXT_ON_LOAD
  1407. | FLAG_HAS_SMART_POWER_DOWN
  1408. | FLAG_RESET_OVERWRITES_LAA /* errata */
  1409. | FLAG_TARC_SPEED_MODE_BIT /* errata */
  1410. | FLAG_APME_CHECK_PORT_B,
  1411. .pba = 38,
  1412. .get_variants = e1000_get_variants_82571,
  1413. .mac_ops = &e82571_mac_ops,
  1414. .phy_ops = &e82_phy_ops_igp,
  1415. .nvm_ops = &e82571_nvm_ops,
  1416. };
  1417. struct e1000_info e1000_82572_info = {
  1418. .mac = e1000_82572,
  1419. .flags = FLAG_HAS_HW_VLAN_FILTER
  1420. | FLAG_HAS_JUMBO_FRAMES
  1421. | FLAG_HAS_WOL
  1422. | FLAG_APME_IN_CTRL3
  1423. | FLAG_RX_CSUM_ENABLED
  1424. | FLAG_HAS_CTRLEXT_ON_LOAD
  1425. | FLAG_TARC_SPEED_MODE_BIT, /* errata */
  1426. .pba = 38,
  1427. .get_variants = e1000_get_variants_82571,
  1428. .mac_ops = &e82571_mac_ops,
  1429. .phy_ops = &e82_phy_ops_igp,
  1430. .nvm_ops = &e82571_nvm_ops,
  1431. };
  1432. struct e1000_info e1000_82573_info = {
  1433. .mac = e1000_82573,
  1434. .flags = FLAG_HAS_HW_VLAN_FILTER
  1435. | FLAG_HAS_JUMBO_FRAMES
  1436. | FLAG_HAS_WOL
  1437. | FLAG_APME_IN_CTRL3
  1438. | FLAG_RX_CSUM_ENABLED
  1439. | FLAG_HAS_SMART_POWER_DOWN
  1440. | FLAG_HAS_AMT
  1441. | FLAG_HAS_ERT
  1442. | FLAG_HAS_SWSM_ON_LOAD,
  1443. .pba = 20,
  1444. .get_variants = e1000_get_variants_82571,
  1445. .mac_ops = &e82571_mac_ops,
  1446. .phy_ops = &e82_phy_ops_m88,
  1447. .nvm_ops = &e82571_nvm_ops,
  1448. };
  1449. struct e1000_info e1000_82574_info = {
  1450. .mac = e1000_82574,
  1451. .flags = FLAG_HAS_HW_VLAN_FILTER
  1452. | FLAG_HAS_MSIX
  1453. | FLAG_HAS_JUMBO_FRAMES
  1454. | FLAG_HAS_WOL
  1455. | FLAG_APME_IN_CTRL3
  1456. | FLAG_RX_CSUM_ENABLED
  1457. | FLAG_HAS_SMART_POWER_DOWN
  1458. | FLAG_HAS_AMT
  1459. | FLAG_HAS_CTRLEXT_ON_LOAD,
  1460. .pba = 20,
  1461. .get_variants = e1000_get_variants_82571,
  1462. .mac_ops = &e82571_mac_ops,
  1463. .phy_ops = &e82_phy_ops_bm,
  1464. .nvm_ops = &e82571_nvm_ops,
  1465. };