82571.c 45 KB

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