82571.c 54 KB

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