82571.c 40 KB

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