82571.c 54 KB

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