82571.c 55 KB

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