82571.c 45 KB

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