e1000_82575.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-2009 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. /* e1000_82575
  21. * e1000_82576
  22. */
  23. #include <linux/types.h>
  24. #include <linux/if_ether.h>
  25. #include "e1000_mac.h"
  26. #include "e1000_82575.h"
  27. static s32 igb_get_invariants_82575(struct e1000_hw *);
  28. static s32 igb_acquire_phy_82575(struct e1000_hw *);
  29. static void igb_release_phy_82575(struct e1000_hw *);
  30. static s32 igb_acquire_nvm_82575(struct e1000_hw *);
  31. static void igb_release_nvm_82575(struct e1000_hw *);
  32. static s32 igb_check_for_link_82575(struct e1000_hw *);
  33. static s32 igb_get_cfg_done_82575(struct e1000_hw *);
  34. static s32 igb_init_hw_82575(struct e1000_hw *);
  35. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
  36. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
  37. static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
  38. static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
  39. static s32 igb_reset_hw_82575(struct e1000_hw *);
  40. static s32 igb_reset_hw_82580(struct e1000_hw *);
  41. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
  42. static s32 igb_setup_copper_link_82575(struct e1000_hw *);
  43. static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
  44. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
  45. static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
  46. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
  47. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
  48. u16 *);
  49. static s32 igb_get_phy_id_82575(struct e1000_hw *);
  50. static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
  51. static bool igb_sgmii_active_82575(struct e1000_hw *);
  52. static s32 igb_reset_init_script_82575(struct e1000_hw *);
  53. static s32 igb_read_mac_addr_82575(struct e1000_hw *);
  54. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
  55. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
  56. static const u16 e1000_82580_rxpbs_table[] =
  57. { 36, 72, 144, 1, 2, 4, 8, 16,
  58. 35, 70, 140 };
  59. #define E1000_82580_RXPBS_TABLE_SIZE \
  60. (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
  61. /**
  62. * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
  63. * @hw: pointer to the HW structure
  64. *
  65. * Called to determine if the I2C pins are being used for I2C or as an
  66. * external MDIO interface since the two options are mutually exclusive.
  67. **/
  68. static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
  69. {
  70. u32 reg = 0;
  71. bool ext_mdio = false;
  72. switch (hw->mac.type) {
  73. case e1000_82575:
  74. case e1000_82576:
  75. reg = rd32(E1000_MDIC);
  76. ext_mdio = !!(reg & E1000_MDIC_DEST);
  77. break;
  78. case e1000_82580:
  79. case e1000_i350:
  80. reg = rd32(E1000_MDICNFG);
  81. ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
  82. break;
  83. default:
  84. break;
  85. }
  86. return ext_mdio;
  87. }
  88. static s32 igb_get_invariants_82575(struct e1000_hw *hw)
  89. {
  90. struct e1000_phy_info *phy = &hw->phy;
  91. struct e1000_nvm_info *nvm = &hw->nvm;
  92. struct e1000_mac_info *mac = &hw->mac;
  93. struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
  94. u32 eecd;
  95. s32 ret_val;
  96. u16 size;
  97. u32 ctrl_ext = 0;
  98. switch (hw->device_id) {
  99. case E1000_DEV_ID_82575EB_COPPER:
  100. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  101. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  102. mac->type = e1000_82575;
  103. break;
  104. case E1000_DEV_ID_82576:
  105. case E1000_DEV_ID_82576_NS:
  106. case E1000_DEV_ID_82576_NS_SERDES:
  107. case E1000_DEV_ID_82576_FIBER:
  108. case E1000_DEV_ID_82576_SERDES:
  109. case E1000_DEV_ID_82576_QUAD_COPPER:
  110. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  111. case E1000_DEV_ID_82576_SERDES_QUAD:
  112. mac->type = e1000_82576;
  113. break;
  114. case E1000_DEV_ID_82580_COPPER:
  115. case E1000_DEV_ID_82580_FIBER:
  116. case E1000_DEV_ID_82580_QUAD_FIBER:
  117. case E1000_DEV_ID_82580_SERDES:
  118. case E1000_DEV_ID_82580_SGMII:
  119. case E1000_DEV_ID_82580_COPPER_DUAL:
  120. case E1000_DEV_ID_DH89XXCC_SGMII:
  121. case E1000_DEV_ID_DH89XXCC_SERDES:
  122. case E1000_DEV_ID_DH89XXCC_BACKPLANE:
  123. case E1000_DEV_ID_DH89XXCC_SFP:
  124. mac->type = e1000_82580;
  125. break;
  126. case E1000_DEV_ID_I350_COPPER:
  127. case E1000_DEV_ID_I350_FIBER:
  128. case E1000_DEV_ID_I350_SERDES:
  129. case E1000_DEV_ID_I350_SGMII:
  130. mac->type = e1000_i350;
  131. break;
  132. default:
  133. return -E1000_ERR_MAC_INIT;
  134. break;
  135. }
  136. /* Set media type */
  137. /*
  138. * The 82575 uses bits 22:23 for link mode. The mode can be changed
  139. * based on the EEPROM. We cannot rely upon device ID. There
  140. * is no distinguishable difference between fiber and internal
  141. * SerDes mode on the 82575. There can be an external PHY attached
  142. * on the SGMII interface. For this, we'll set sgmii_active to true.
  143. */
  144. phy->media_type = e1000_media_type_copper;
  145. dev_spec->sgmii_active = false;
  146. ctrl_ext = rd32(E1000_CTRL_EXT);
  147. switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
  148. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  149. dev_spec->sgmii_active = true;
  150. break;
  151. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  152. case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
  153. hw->phy.media_type = e1000_media_type_internal_serdes;
  154. break;
  155. default:
  156. break;
  157. }
  158. /* Set mta register count */
  159. mac->mta_reg_count = 128;
  160. /* Set rar entry count */
  161. mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
  162. if (mac->type == e1000_82576)
  163. mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
  164. if (mac->type == e1000_82580)
  165. mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
  166. if (mac->type == e1000_i350)
  167. mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
  168. /* reset */
  169. if (mac->type >= e1000_82580)
  170. mac->ops.reset_hw = igb_reset_hw_82580;
  171. else
  172. mac->ops.reset_hw = igb_reset_hw_82575;
  173. /* Set if part includes ASF firmware */
  174. mac->asf_firmware_present = true;
  175. /* Set if manageability features are enabled. */
  176. mac->arc_subsystem_valid =
  177. (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
  178. ? true : false;
  179. /* enable EEE on i350 parts */
  180. if (mac->type == e1000_i350)
  181. dev_spec->eee_disable = false;
  182. else
  183. dev_spec->eee_disable = true;
  184. /* physical interface link setup */
  185. mac->ops.setup_physical_interface =
  186. (hw->phy.media_type == e1000_media_type_copper)
  187. ? igb_setup_copper_link_82575
  188. : igb_setup_serdes_link_82575;
  189. /* NVM initialization */
  190. eecd = rd32(E1000_EECD);
  191. nvm->opcode_bits = 8;
  192. nvm->delay_usec = 1;
  193. switch (nvm->override) {
  194. case e1000_nvm_override_spi_large:
  195. nvm->page_size = 32;
  196. nvm->address_bits = 16;
  197. break;
  198. case e1000_nvm_override_spi_small:
  199. nvm->page_size = 8;
  200. nvm->address_bits = 8;
  201. break;
  202. default:
  203. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  204. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
  205. break;
  206. }
  207. nvm->type = e1000_nvm_eeprom_spi;
  208. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  209. E1000_EECD_SIZE_EX_SHIFT);
  210. /*
  211. * Added to a constant, "size" becomes the left-shift value
  212. * for setting word_size.
  213. */
  214. size += NVM_WORD_SIZE_BASE_SHIFT;
  215. /* EEPROM access above 16k is unsupported */
  216. if (size > 14)
  217. size = 14;
  218. nvm->word_size = 1 << size;
  219. /* if part supports SR-IOV then initialize mailbox parameters */
  220. switch (mac->type) {
  221. case e1000_82576:
  222. case e1000_i350:
  223. igb_init_mbx_params_pf(hw);
  224. break;
  225. default:
  226. break;
  227. }
  228. /* setup PHY parameters */
  229. if (phy->media_type != e1000_media_type_copper) {
  230. phy->type = e1000_phy_none;
  231. return 0;
  232. }
  233. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  234. phy->reset_delay_us = 100;
  235. ctrl_ext = rd32(E1000_CTRL_EXT);
  236. /* PHY function pointers */
  237. if (igb_sgmii_active_82575(hw)) {
  238. phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
  239. ctrl_ext |= E1000_CTRL_I2C_ENA;
  240. } else {
  241. phy->ops.reset = igb_phy_hw_reset;
  242. ctrl_ext &= ~E1000_CTRL_I2C_ENA;
  243. }
  244. wr32(E1000_CTRL_EXT, ctrl_ext);
  245. igb_reset_mdicnfg_82580(hw);
  246. if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
  247. phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
  248. phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
  249. } else if (hw->mac.type >= e1000_82580) {
  250. phy->ops.read_reg = igb_read_phy_reg_82580;
  251. phy->ops.write_reg = igb_write_phy_reg_82580;
  252. } else {
  253. phy->ops.read_reg = igb_read_phy_reg_igp;
  254. phy->ops.write_reg = igb_write_phy_reg_igp;
  255. }
  256. /* set lan id */
  257. hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
  258. E1000_STATUS_FUNC_SHIFT;
  259. /* Set phy->phy_addr and phy->id. */
  260. ret_val = igb_get_phy_id_82575(hw);
  261. if (ret_val)
  262. return ret_val;
  263. /* Verify phy id and set remaining function pointers */
  264. switch (phy->id) {
  265. case I347AT4_E_PHY_ID:
  266. case M88E1112_E_PHY_ID:
  267. case M88E1111_I_PHY_ID:
  268. phy->type = e1000_phy_m88;
  269. phy->ops.get_phy_info = igb_get_phy_info_m88;
  270. if (phy->id == I347AT4_E_PHY_ID ||
  271. phy->id == M88E1112_E_PHY_ID)
  272. phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
  273. else
  274. phy->ops.get_cable_length = igb_get_cable_length_m88;
  275. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  276. break;
  277. case IGP03E1000_E_PHY_ID:
  278. phy->type = e1000_phy_igp_3;
  279. phy->ops.get_phy_info = igb_get_phy_info_igp;
  280. phy->ops.get_cable_length = igb_get_cable_length_igp_2;
  281. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
  282. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
  283. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
  284. break;
  285. case I82580_I_PHY_ID:
  286. case I350_I_PHY_ID:
  287. phy->type = e1000_phy_82580;
  288. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_82580;
  289. phy->ops.get_cable_length = igb_get_cable_length_82580;
  290. phy->ops.get_phy_info = igb_get_phy_info_82580;
  291. break;
  292. default:
  293. return -E1000_ERR_PHY;
  294. }
  295. return 0;
  296. }
  297. /**
  298. * igb_acquire_phy_82575 - Acquire rights to access PHY
  299. * @hw: pointer to the HW structure
  300. *
  301. * Acquire access rights to the correct PHY. This is a
  302. * function pointer entry point called by the api module.
  303. **/
  304. static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
  305. {
  306. u16 mask = E1000_SWFW_PHY0_SM;
  307. if (hw->bus.func == E1000_FUNC_1)
  308. mask = E1000_SWFW_PHY1_SM;
  309. else if (hw->bus.func == E1000_FUNC_2)
  310. mask = E1000_SWFW_PHY2_SM;
  311. else if (hw->bus.func == E1000_FUNC_3)
  312. mask = E1000_SWFW_PHY3_SM;
  313. return igb_acquire_swfw_sync_82575(hw, mask);
  314. }
  315. /**
  316. * igb_release_phy_82575 - Release rights to access PHY
  317. * @hw: pointer to the HW structure
  318. *
  319. * A wrapper to release access rights to the correct PHY. This is a
  320. * function pointer entry point called by the api module.
  321. **/
  322. static void igb_release_phy_82575(struct e1000_hw *hw)
  323. {
  324. u16 mask = E1000_SWFW_PHY0_SM;
  325. if (hw->bus.func == E1000_FUNC_1)
  326. mask = E1000_SWFW_PHY1_SM;
  327. else if (hw->bus.func == E1000_FUNC_2)
  328. mask = E1000_SWFW_PHY2_SM;
  329. else if (hw->bus.func == E1000_FUNC_3)
  330. mask = E1000_SWFW_PHY3_SM;
  331. igb_release_swfw_sync_82575(hw, mask);
  332. }
  333. /**
  334. * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
  335. * @hw: pointer to the HW structure
  336. * @offset: register offset to be read
  337. * @data: pointer to the read data
  338. *
  339. * Reads the PHY register at offset using the serial gigabit media independent
  340. * interface and stores the retrieved information in data.
  341. **/
  342. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  343. u16 *data)
  344. {
  345. s32 ret_val = -E1000_ERR_PARAM;
  346. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  347. hw_dbg("PHY Address %u is out of range\n", offset);
  348. goto out;
  349. }
  350. ret_val = hw->phy.ops.acquire(hw);
  351. if (ret_val)
  352. goto out;
  353. ret_val = igb_read_phy_reg_i2c(hw, offset, data);
  354. hw->phy.ops.release(hw);
  355. out:
  356. return ret_val;
  357. }
  358. /**
  359. * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
  360. * @hw: pointer to the HW structure
  361. * @offset: register offset to write to
  362. * @data: data to write at register offset
  363. *
  364. * Writes the data to PHY register at the offset using the serial gigabit
  365. * media independent interface.
  366. **/
  367. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  368. u16 data)
  369. {
  370. s32 ret_val = -E1000_ERR_PARAM;
  371. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  372. hw_dbg("PHY Address %d is out of range\n", offset);
  373. goto out;
  374. }
  375. ret_val = hw->phy.ops.acquire(hw);
  376. if (ret_val)
  377. goto out;
  378. ret_val = igb_write_phy_reg_i2c(hw, offset, data);
  379. hw->phy.ops.release(hw);
  380. out:
  381. return ret_val;
  382. }
  383. /**
  384. * igb_get_phy_id_82575 - Retrieve PHY addr and id
  385. * @hw: pointer to the HW structure
  386. *
  387. * Retrieves the PHY address and ID for both PHY's which do and do not use
  388. * sgmi interface.
  389. **/
  390. static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
  391. {
  392. struct e1000_phy_info *phy = &hw->phy;
  393. s32 ret_val = 0;
  394. u16 phy_id;
  395. u32 ctrl_ext;
  396. u32 mdic;
  397. /*
  398. * For SGMII PHYs, we try the list of possible addresses until
  399. * we find one that works. For non-SGMII PHYs
  400. * (e.g. integrated copper PHYs), an address of 1 should
  401. * work. The result of this function should mean phy->phy_addr
  402. * and phy->id are set correctly.
  403. */
  404. if (!(igb_sgmii_active_82575(hw))) {
  405. phy->addr = 1;
  406. ret_val = igb_get_phy_id(hw);
  407. goto out;
  408. }
  409. if (igb_sgmii_uses_mdio_82575(hw)) {
  410. switch (hw->mac.type) {
  411. case e1000_82575:
  412. case e1000_82576:
  413. mdic = rd32(E1000_MDIC);
  414. mdic &= E1000_MDIC_PHY_MASK;
  415. phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
  416. break;
  417. case e1000_82580:
  418. case e1000_i350:
  419. mdic = rd32(E1000_MDICNFG);
  420. mdic &= E1000_MDICNFG_PHY_MASK;
  421. phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
  422. break;
  423. default:
  424. ret_val = -E1000_ERR_PHY;
  425. goto out;
  426. break;
  427. }
  428. ret_val = igb_get_phy_id(hw);
  429. goto out;
  430. }
  431. /* Power on sgmii phy if it is disabled */
  432. ctrl_ext = rd32(E1000_CTRL_EXT);
  433. wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
  434. wrfl();
  435. msleep(300);
  436. /*
  437. * The address field in the I2CCMD register is 3 bits and 0 is invalid.
  438. * Therefore, we need to test 1-7
  439. */
  440. for (phy->addr = 1; phy->addr < 8; phy->addr++) {
  441. ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
  442. if (ret_val == 0) {
  443. hw_dbg("Vendor ID 0x%08X read at address %u\n",
  444. phy_id, phy->addr);
  445. /*
  446. * At the time of this writing, The M88 part is
  447. * the only supported SGMII PHY product.
  448. */
  449. if (phy_id == M88_VENDOR)
  450. break;
  451. } else {
  452. hw_dbg("PHY address %u was unreadable\n", phy->addr);
  453. }
  454. }
  455. /* A valid PHY type couldn't be found. */
  456. if (phy->addr == 8) {
  457. phy->addr = 0;
  458. ret_val = -E1000_ERR_PHY;
  459. goto out;
  460. } else {
  461. ret_val = igb_get_phy_id(hw);
  462. }
  463. /* restore previous sfp cage power state */
  464. wr32(E1000_CTRL_EXT, ctrl_ext);
  465. out:
  466. return ret_val;
  467. }
  468. /**
  469. * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
  470. * @hw: pointer to the HW structure
  471. *
  472. * Resets the PHY using the serial gigabit media independent interface.
  473. **/
  474. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
  475. {
  476. s32 ret_val;
  477. /*
  478. * This isn't a true "hard" reset, but is the only reset
  479. * available to us at this time.
  480. */
  481. hw_dbg("Soft resetting SGMII attached PHY...\n");
  482. /*
  483. * SFP documentation requires the following to configure the SPF module
  484. * to work on SGMII. No further documentation is given.
  485. */
  486. ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
  487. if (ret_val)
  488. goto out;
  489. ret_val = igb_phy_sw_reset(hw);
  490. out:
  491. return ret_val;
  492. }
  493. /**
  494. * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
  495. * @hw: pointer to the HW structure
  496. * @active: true to enable LPLU, false to disable
  497. *
  498. * Sets the LPLU D0 state according to the active flag. When
  499. * activating LPLU this function also disables smart speed
  500. * and vice versa. LPLU will not be activated unless the
  501. * device autonegotiation advertisement meets standards of
  502. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  503. * This is a function pointer entry point only called by
  504. * PHY setup routines.
  505. **/
  506. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
  507. {
  508. struct e1000_phy_info *phy = &hw->phy;
  509. s32 ret_val;
  510. u16 data;
  511. ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  512. if (ret_val)
  513. goto out;
  514. if (active) {
  515. data |= IGP02E1000_PM_D0_LPLU;
  516. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  517. data);
  518. if (ret_val)
  519. goto out;
  520. /* When LPLU is enabled, we should disable SmartSpeed */
  521. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  522. &data);
  523. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  524. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  525. data);
  526. if (ret_val)
  527. goto out;
  528. } else {
  529. data &= ~IGP02E1000_PM_D0_LPLU;
  530. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  531. data);
  532. /*
  533. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  534. * during Dx states where the power conservation is most
  535. * important. During driver activity we should enable
  536. * SmartSpeed, so performance is maintained.
  537. */
  538. if (phy->smart_speed == e1000_smart_speed_on) {
  539. ret_val = phy->ops.read_reg(hw,
  540. IGP01E1000_PHY_PORT_CONFIG, &data);
  541. if (ret_val)
  542. goto out;
  543. data |= IGP01E1000_PSCFR_SMART_SPEED;
  544. ret_val = phy->ops.write_reg(hw,
  545. IGP01E1000_PHY_PORT_CONFIG, data);
  546. if (ret_val)
  547. goto out;
  548. } else if (phy->smart_speed == e1000_smart_speed_off) {
  549. ret_val = phy->ops.read_reg(hw,
  550. IGP01E1000_PHY_PORT_CONFIG, &data);
  551. if (ret_val)
  552. goto out;
  553. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  554. ret_val = phy->ops.write_reg(hw,
  555. IGP01E1000_PHY_PORT_CONFIG, data);
  556. if (ret_val)
  557. goto out;
  558. }
  559. }
  560. out:
  561. return ret_val;
  562. }
  563. /**
  564. * igb_acquire_nvm_82575 - Request for access to EEPROM
  565. * @hw: pointer to the HW structure
  566. *
  567. * Acquire the necessary semaphores for exclusive access to the EEPROM.
  568. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  569. * Return successful if access grant bit set, else clear the request for
  570. * EEPROM access and return -E1000_ERR_NVM (-1).
  571. **/
  572. static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
  573. {
  574. s32 ret_val;
  575. ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  576. if (ret_val)
  577. goto out;
  578. ret_val = igb_acquire_nvm(hw);
  579. if (ret_val)
  580. igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  581. out:
  582. return ret_val;
  583. }
  584. /**
  585. * igb_release_nvm_82575 - Release exclusive access to EEPROM
  586. * @hw: pointer to the HW structure
  587. *
  588. * Stop any current commands to the EEPROM and clear the EEPROM request bit,
  589. * then release the semaphores acquired.
  590. **/
  591. static void igb_release_nvm_82575(struct e1000_hw *hw)
  592. {
  593. igb_release_nvm(hw);
  594. igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  595. }
  596. /**
  597. * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
  598. * @hw: pointer to the HW structure
  599. * @mask: specifies which semaphore to acquire
  600. *
  601. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  602. * will also specify which port we're acquiring the lock for.
  603. **/
  604. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  605. {
  606. u32 swfw_sync;
  607. u32 swmask = mask;
  608. u32 fwmask = mask << 16;
  609. s32 ret_val = 0;
  610. s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
  611. while (i < timeout) {
  612. if (igb_get_hw_semaphore(hw)) {
  613. ret_val = -E1000_ERR_SWFW_SYNC;
  614. goto out;
  615. }
  616. swfw_sync = rd32(E1000_SW_FW_SYNC);
  617. if (!(swfw_sync & (fwmask | swmask)))
  618. break;
  619. /*
  620. * Firmware currently using resource (fwmask)
  621. * or other software thread using resource (swmask)
  622. */
  623. igb_put_hw_semaphore(hw);
  624. mdelay(5);
  625. i++;
  626. }
  627. if (i == timeout) {
  628. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  629. ret_val = -E1000_ERR_SWFW_SYNC;
  630. goto out;
  631. }
  632. swfw_sync |= swmask;
  633. wr32(E1000_SW_FW_SYNC, swfw_sync);
  634. igb_put_hw_semaphore(hw);
  635. out:
  636. return ret_val;
  637. }
  638. /**
  639. * igb_release_swfw_sync_82575 - Release SW/FW semaphore
  640. * @hw: pointer to the HW structure
  641. * @mask: specifies which semaphore to acquire
  642. *
  643. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  644. * will also specify which port we're releasing the lock for.
  645. **/
  646. static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  647. {
  648. u32 swfw_sync;
  649. while (igb_get_hw_semaphore(hw) != 0);
  650. /* Empty */
  651. swfw_sync = rd32(E1000_SW_FW_SYNC);
  652. swfw_sync &= ~mask;
  653. wr32(E1000_SW_FW_SYNC, swfw_sync);
  654. igb_put_hw_semaphore(hw);
  655. }
  656. /**
  657. * igb_get_cfg_done_82575 - Read config done bit
  658. * @hw: pointer to the HW structure
  659. *
  660. * Read the management control register for the config done bit for
  661. * completion status. NOTE: silicon which is EEPROM-less will fail trying
  662. * to read the config done bit, so an error is *ONLY* logged and returns
  663. * 0. If we were to return with error, EEPROM-less silicon
  664. * would not be able to be reset or change link.
  665. **/
  666. static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
  667. {
  668. s32 timeout = PHY_CFG_TIMEOUT;
  669. s32 ret_val = 0;
  670. u32 mask = E1000_NVM_CFG_DONE_PORT_0;
  671. if (hw->bus.func == 1)
  672. mask = E1000_NVM_CFG_DONE_PORT_1;
  673. else if (hw->bus.func == E1000_FUNC_2)
  674. mask = E1000_NVM_CFG_DONE_PORT_2;
  675. else if (hw->bus.func == E1000_FUNC_3)
  676. mask = E1000_NVM_CFG_DONE_PORT_3;
  677. while (timeout) {
  678. if (rd32(E1000_EEMNGCTL) & mask)
  679. break;
  680. msleep(1);
  681. timeout--;
  682. }
  683. if (!timeout)
  684. hw_dbg("MNG configuration cycle has not completed.\n");
  685. /* If EEPROM is not marked present, init the PHY manually */
  686. if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
  687. (hw->phy.type == e1000_phy_igp_3))
  688. igb_phy_init_script_igp3(hw);
  689. return ret_val;
  690. }
  691. /**
  692. * igb_check_for_link_82575 - Check for link
  693. * @hw: pointer to the HW structure
  694. *
  695. * If sgmii is enabled, then use the pcs register to determine link, otherwise
  696. * use the generic interface for determining link.
  697. **/
  698. static s32 igb_check_for_link_82575(struct e1000_hw *hw)
  699. {
  700. s32 ret_val;
  701. u16 speed, duplex;
  702. if (hw->phy.media_type != e1000_media_type_copper) {
  703. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
  704. &duplex);
  705. /*
  706. * Use this flag to determine if link needs to be checked or
  707. * not. If we have link clear the flag so that we do not
  708. * continue to check for link.
  709. */
  710. hw->mac.get_link_status = !hw->mac.serdes_has_link;
  711. } else {
  712. ret_val = igb_check_for_copper_link(hw);
  713. }
  714. return ret_val;
  715. }
  716. /**
  717. * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
  718. * @hw: pointer to the HW structure
  719. **/
  720. void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
  721. {
  722. u32 reg;
  723. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  724. !igb_sgmii_active_82575(hw))
  725. return;
  726. /* Enable PCS to turn on link */
  727. reg = rd32(E1000_PCS_CFG0);
  728. reg |= E1000_PCS_CFG_PCS_EN;
  729. wr32(E1000_PCS_CFG0, reg);
  730. /* Power up the laser */
  731. reg = rd32(E1000_CTRL_EXT);
  732. reg &= ~E1000_CTRL_EXT_SDP3_DATA;
  733. wr32(E1000_CTRL_EXT, reg);
  734. /* flush the write to verify completion */
  735. wrfl();
  736. msleep(1);
  737. }
  738. /**
  739. * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
  740. * @hw: pointer to the HW structure
  741. * @speed: stores the current speed
  742. * @duplex: stores the current duplex
  743. *
  744. * Using the physical coding sub-layer (PCS), retrieve the current speed and
  745. * duplex, then store the values in the pointers provided.
  746. **/
  747. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
  748. u16 *duplex)
  749. {
  750. struct e1000_mac_info *mac = &hw->mac;
  751. u32 pcs;
  752. /* Set up defaults for the return values of this function */
  753. mac->serdes_has_link = false;
  754. *speed = 0;
  755. *duplex = 0;
  756. /*
  757. * Read the PCS Status register for link state. For non-copper mode,
  758. * the status register is not accurate. The PCS status register is
  759. * used instead.
  760. */
  761. pcs = rd32(E1000_PCS_LSTAT);
  762. /*
  763. * The link up bit determines when link is up on autoneg. The sync ok
  764. * gets set once both sides sync up and agree upon link. Stable link
  765. * can be determined by checking for both link up and link sync ok
  766. */
  767. if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
  768. mac->serdes_has_link = true;
  769. /* Detect and store PCS speed */
  770. if (pcs & E1000_PCS_LSTS_SPEED_1000) {
  771. *speed = SPEED_1000;
  772. } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
  773. *speed = SPEED_100;
  774. } else {
  775. *speed = SPEED_10;
  776. }
  777. /* Detect and store PCS duplex */
  778. if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
  779. *duplex = FULL_DUPLEX;
  780. } else {
  781. *duplex = HALF_DUPLEX;
  782. }
  783. }
  784. return 0;
  785. }
  786. /**
  787. * igb_shutdown_serdes_link_82575 - Remove link during power down
  788. * @hw: pointer to the HW structure
  789. *
  790. * In the case of fiber serdes, shut down optics and PCS on driver unload
  791. * when management pass thru is not enabled.
  792. **/
  793. void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
  794. {
  795. u32 reg;
  796. if (hw->phy.media_type != e1000_media_type_internal_serdes &&
  797. igb_sgmii_active_82575(hw))
  798. return;
  799. if (!igb_enable_mng_pass_thru(hw)) {
  800. /* Disable PCS to turn off link */
  801. reg = rd32(E1000_PCS_CFG0);
  802. reg &= ~E1000_PCS_CFG_PCS_EN;
  803. wr32(E1000_PCS_CFG0, reg);
  804. /* shutdown the laser */
  805. reg = rd32(E1000_CTRL_EXT);
  806. reg |= E1000_CTRL_EXT_SDP3_DATA;
  807. wr32(E1000_CTRL_EXT, reg);
  808. /* flush the write to verify completion */
  809. wrfl();
  810. msleep(1);
  811. }
  812. }
  813. /**
  814. * igb_reset_hw_82575 - Reset hardware
  815. * @hw: pointer to the HW structure
  816. *
  817. * This resets the hardware into a known state. This is a
  818. * function pointer entry point called by the api module.
  819. **/
  820. static s32 igb_reset_hw_82575(struct e1000_hw *hw)
  821. {
  822. u32 ctrl, icr;
  823. s32 ret_val;
  824. /*
  825. * Prevent the PCI-E bus from sticking if there is no TLP connection
  826. * on the last TLP read/write transaction when MAC is reset.
  827. */
  828. ret_val = igb_disable_pcie_master(hw);
  829. if (ret_val)
  830. hw_dbg("PCI-E Master disable polling has failed.\n");
  831. /* set the completion timeout for interface */
  832. ret_val = igb_set_pcie_completion_timeout(hw);
  833. if (ret_val) {
  834. hw_dbg("PCI-E Set completion timeout has failed.\n");
  835. }
  836. hw_dbg("Masking off all interrupts\n");
  837. wr32(E1000_IMC, 0xffffffff);
  838. wr32(E1000_RCTL, 0);
  839. wr32(E1000_TCTL, E1000_TCTL_PSP);
  840. wrfl();
  841. msleep(10);
  842. ctrl = rd32(E1000_CTRL);
  843. hw_dbg("Issuing a global reset to MAC\n");
  844. wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
  845. ret_val = igb_get_auto_rd_done(hw);
  846. if (ret_val) {
  847. /*
  848. * When auto config read does not complete, do not
  849. * return with an error. This can happen in situations
  850. * where there is no eeprom and prevents getting link.
  851. */
  852. hw_dbg("Auto Read Done did not complete\n");
  853. }
  854. /* If EEPROM is not present, run manual init scripts */
  855. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  856. igb_reset_init_script_82575(hw);
  857. /* Clear any pending interrupt events. */
  858. wr32(E1000_IMC, 0xffffffff);
  859. icr = rd32(E1000_ICR);
  860. /* Install any alternate MAC address into RAR0 */
  861. ret_val = igb_check_alt_mac_addr(hw);
  862. return ret_val;
  863. }
  864. /**
  865. * igb_init_hw_82575 - Initialize hardware
  866. * @hw: pointer to the HW structure
  867. *
  868. * This inits the hardware readying it for operation.
  869. **/
  870. static s32 igb_init_hw_82575(struct e1000_hw *hw)
  871. {
  872. struct e1000_mac_info *mac = &hw->mac;
  873. s32 ret_val;
  874. u16 i, rar_count = mac->rar_entry_count;
  875. /* Initialize identification LED */
  876. ret_val = igb_id_led_init(hw);
  877. if (ret_val) {
  878. hw_dbg("Error initializing identification LED\n");
  879. /* This is not fatal and we should not stop init due to this */
  880. }
  881. /* Disabling VLAN filtering */
  882. hw_dbg("Initializing the IEEE VLAN\n");
  883. igb_clear_vfta(hw);
  884. /* Setup the receive address */
  885. igb_init_rx_addrs(hw, rar_count);
  886. /* Zero out the Multicast HASH table */
  887. hw_dbg("Zeroing the MTA\n");
  888. for (i = 0; i < mac->mta_reg_count; i++)
  889. array_wr32(E1000_MTA, i, 0);
  890. /* Zero out the Unicast HASH table */
  891. hw_dbg("Zeroing the UTA\n");
  892. for (i = 0; i < mac->uta_reg_count; i++)
  893. array_wr32(E1000_UTA, i, 0);
  894. /* Setup link and flow control */
  895. ret_val = igb_setup_link(hw);
  896. /*
  897. * Clear all of the statistics registers (clear on read). It is
  898. * important that we do this after we have tried to establish link
  899. * because the symbol error count will increment wildly if there
  900. * is no link.
  901. */
  902. igb_clear_hw_cntrs_82575(hw);
  903. return ret_val;
  904. }
  905. /**
  906. * igb_setup_copper_link_82575 - Configure copper link settings
  907. * @hw: pointer to the HW structure
  908. *
  909. * Configures the link for auto-neg or forced speed and duplex. Then we check
  910. * for link, once link is established calls to configure collision distance
  911. * and flow control are called.
  912. **/
  913. static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
  914. {
  915. u32 ctrl;
  916. s32 ret_val;
  917. ctrl = rd32(E1000_CTRL);
  918. ctrl |= E1000_CTRL_SLU;
  919. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  920. wr32(E1000_CTRL, ctrl);
  921. ret_val = igb_setup_serdes_link_82575(hw);
  922. if (ret_val)
  923. goto out;
  924. if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
  925. /* allow time for SFP cage time to power up phy */
  926. msleep(300);
  927. ret_val = hw->phy.ops.reset(hw);
  928. if (ret_val) {
  929. hw_dbg("Error resetting the PHY.\n");
  930. goto out;
  931. }
  932. }
  933. switch (hw->phy.type) {
  934. case e1000_phy_m88:
  935. if (hw->phy.id == I347AT4_E_PHY_ID ||
  936. hw->phy.id == M88E1112_E_PHY_ID)
  937. ret_val = igb_copper_link_setup_m88_gen2(hw);
  938. else
  939. ret_val = igb_copper_link_setup_m88(hw);
  940. break;
  941. case e1000_phy_igp_3:
  942. ret_val = igb_copper_link_setup_igp(hw);
  943. break;
  944. case e1000_phy_82580:
  945. ret_val = igb_copper_link_setup_82580(hw);
  946. break;
  947. default:
  948. ret_val = -E1000_ERR_PHY;
  949. break;
  950. }
  951. if (ret_val)
  952. goto out;
  953. ret_val = igb_setup_copper_link(hw);
  954. out:
  955. return ret_val;
  956. }
  957. /**
  958. * igb_setup_serdes_link_82575 - Setup link for serdes
  959. * @hw: pointer to the HW structure
  960. *
  961. * Configure the physical coding sub-layer (PCS) link. The PCS link is
  962. * used on copper connections where the serialized gigabit media independent
  963. * interface (sgmii), or serdes fiber is being used. Configures the link
  964. * for auto-negotiation or forces speed/duplex.
  965. **/
  966. static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
  967. {
  968. u32 ctrl_ext, ctrl_reg, reg;
  969. bool pcs_autoneg;
  970. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  971. !igb_sgmii_active_82575(hw))
  972. return 0;
  973. /*
  974. * On the 82575, SerDes loopback mode persists until it is
  975. * explicitly turned off or a power cycle is performed. A read to
  976. * the register does not indicate its status. Therefore, we ensure
  977. * loopback mode is disabled during initialization.
  978. */
  979. wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  980. /* power on the sfp cage if present */
  981. ctrl_ext = rd32(E1000_CTRL_EXT);
  982. ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
  983. wr32(E1000_CTRL_EXT, ctrl_ext);
  984. ctrl_reg = rd32(E1000_CTRL);
  985. ctrl_reg |= E1000_CTRL_SLU;
  986. if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
  987. /* set both sw defined pins */
  988. ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
  989. /* Set switch control to serdes energy detect */
  990. reg = rd32(E1000_CONNSW);
  991. reg |= E1000_CONNSW_ENRGSRC;
  992. wr32(E1000_CONNSW, reg);
  993. }
  994. reg = rd32(E1000_PCS_LCTL);
  995. /* default pcs_autoneg to the same setting as mac autoneg */
  996. pcs_autoneg = hw->mac.autoneg;
  997. switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
  998. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  999. /* sgmii mode lets the phy handle forcing speed/duplex */
  1000. pcs_autoneg = true;
  1001. /* autoneg time out should be disabled for SGMII mode */
  1002. reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
  1003. break;
  1004. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  1005. /* disable PCS autoneg and support parallel detect only */
  1006. pcs_autoneg = false;
  1007. default:
  1008. /*
  1009. * non-SGMII modes only supports a speed of 1000/Full for the
  1010. * link so it is best to just force the MAC and let the pcs
  1011. * link either autoneg or be forced to 1000/Full
  1012. */
  1013. ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
  1014. E1000_CTRL_FD | E1000_CTRL_FRCDPX;
  1015. /* set speed of 1000/Full if speed/duplex is forced */
  1016. reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
  1017. break;
  1018. }
  1019. wr32(E1000_CTRL, ctrl_reg);
  1020. /*
  1021. * New SerDes mode allows for forcing speed or autonegotiating speed
  1022. * at 1gb. Autoneg should be default set by most drivers. This is the
  1023. * mode that will be compatible with older link partners and switches.
  1024. * However, both are supported by the hardware and some drivers/tools.
  1025. */
  1026. reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
  1027. E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
  1028. /*
  1029. * We force flow control to prevent the CTRL register values from being
  1030. * overwritten by the autonegotiated flow control values
  1031. */
  1032. reg |= E1000_PCS_LCTL_FORCE_FCTRL;
  1033. if (pcs_autoneg) {
  1034. /* Set PCS register for autoneg */
  1035. reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
  1036. E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
  1037. hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
  1038. } else {
  1039. /* Set PCS register for forced link */
  1040. reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
  1041. hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
  1042. }
  1043. wr32(E1000_PCS_LCTL, reg);
  1044. if (!igb_sgmii_active_82575(hw))
  1045. igb_force_mac_fc(hw);
  1046. return 0;
  1047. }
  1048. /**
  1049. * igb_sgmii_active_82575 - Return sgmii state
  1050. * @hw: pointer to the HW structure
  1051. *
  1052. * 82575 silicon has a serialized gigabit media independent interface (sgmii)
  1053. * which can be enabled for use in the embedded applications. Simply
  1054. * return the current state of the sgmii interface.
  1055. **/
  1056. static bool igb_sgmii_active_82575(struct e1000_hw *hw)
  1057. {
  1058. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  1059. return dev_spec->sgmii_active;
  1060. }
  1061. /**
  1062. * igb_reset_init_script_82575 - Inits HW defaults after reset
  1063. * @hw: pointer to the HW structure
  1064. *
  1065. * Inits recommended HW defaults after a reset when there is no EEPROM
  1066. * detected. This is only for the 82575.
  1067. **/
  1068. static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
  1069. {
  1070. if (hw->mac.type == e1000_82575) {
  1071. hw_dbg("Running reset init script for 82575\n");
  1072. /* SerDes configuration via SERDESCTRL */
  1073. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
  1074. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
  1075. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
  1076. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
  1077. /* CCM configuration via CCMCTL register */
  1078. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
  1079. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
  1080. /* PCIe lanes configuration */
  1081. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
  1082. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
  1083. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
  1084. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
  1085. /* PCIe PLL Configuration */
  1086. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
  1087. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
  1088. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
  1089. }
  1090. return 0;
  1091. }
  1092. /**
  1093. * igb_read_mac_addr_82575 - Read device MAC address
  1094. * @hw: pointer to the HW structure
  1095. **/
  1096. static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
  1097. {
  1098. s32 ret_val = 0;
  1099. /*
  1100. * If there's an alternate MAC address place it in RAR0
  1101. * so that it will override the Si installed default perm
  1102. * address.
  1103. */
  1104. ret_val = igb_check_alt_mac_addr(hw);
  1105. if (ret_val)
  1106. goto out;
  1107. ret_val = igb_read_mac_addr(hw);
  1108. out:
  1109. return ret_val;
  1110. }
  1111. /**
  1112. * igb_power_down_phy_copper_82575 - Remove link during PHY power down
  1113. * @hw: pointer to the HW structure
  1114. *
  1115. * In the case of a PHY power down to save power, or to turn off link during a
  1116. * driver unload, or wake on lan is not enabled, remove the link.
  1117. **/
  1118. void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
  1119. {
  1120. /* If the management interface is not enabled, then power down */
  1121. if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
  1122. igb_power_down_phy_copper(hw);
  1123. }
  1124. /**
  1125. * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
  1126. * @hw: pointer to the HW structure
  1127. *
  1128. * Clears the hardware counters by reading the counter registers.
  1129. **/
  1130. static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
  1131. {
  1132. igb_clear_hw_cntrs_base(hw);
  1133. rd32(E1000_PRC64);
  1134. rd32(E1000_PRC127);
  1135. rd32(E1000_PRC255);
  1136. rd32(E1000_PRC511);
  1137. rd32(E1000_PRC1023);
  1138. rd32(E1000_PRC1522);
  1139. rd32(E1000_PTC64);
  1140. rd32(E1000_PTC127);
  1141. rd32(E1000_PTC255);
  1142. rd32(E1000_PTC511);
  1143. rd32(E1000_PTC1023);
  1144. rd32(E1000_PTC1522);
  1145. rd32(E1000_ALGNERRC);
  1146. rd32(E1000_RXERRC);
  1147. rd32(E1000_TNCRS);
  1148. rd32(E1000_CEXTERR);
  1149. rd32(E1000_TSCTC);
  1150. rd32(E1000_TSCTFC);
  1151. rd32(E1000_MGTPRC);
  1152. rd32(E1000_MGTPDC);
  1153. rd32(E1000_MGTPTC);
  1154. rd32(E1000_IAC);
  1155. rd32(E1000_ICRXOC);
  1156. rd32(E1000_ICRXPTC);
  1157. rd32(E1000_ICRXATC);
  1158. rd32(E1000_ICTXPTC);
  1159. rd32(E1000_ICTXATC);
  1160. rd32(E1000_ICTXQEC);
  1161. rd32(E1000_ICTXQMTC);
  1162. rd32(E1000_ICRXDMTC);
  1163. rd32(E1000_CBTMPC);
  1164. rd32(E1000_HTDPMC);
  1165. rd32(E1000_CBRMPC);
  1166. rd32(E1000_RPTHC);
  1167. rd32(E1000_HGPTC);
  1168. rd32(E1000_HTCBDPC);
  1169. rd32(E1000_HGORCL);
  1170. rd32(E1000_HGORCH);
  1171. rd32(E1000_HGOTCL);
  1172. rd32(E1000_HGOTCH);
  1173. rd32(E1000_LENERRS);
  1174. /* This register should not be read in copper configurations */
  1175. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  1176. igb_sgmii_active_82575(hw))
  1177. rd32(E1000_SCVPC);
  1178. }
  1179. /**
  1180. * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
  1181. * @hw: pointer to the HW structure
  1182. *
  1183. * After rx enable if managability is enabled then there is likely some
  1184. * bad data at the start of the fifo and possibly in the DMA fifo. This
  1185. * function clears the fifos and flushes any packets that came in as rx was
  1186. * being enabled.
  1187. **/
  1188. void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
  1189. {
  1190. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  1191. int i, ms_wait;
  1192. if (hw->mac.type != e1000_82575 ||
  1193. !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
  1194. return;
  1195. /* Disable all RX queues */
  1196. for (i = 0; i < 4; i++) {
  1197. rxdctl[i] = rd32(E1000_RXDCTL(i));
  1198. wr32(E1000_RXDCTL(i),
  1199. rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
  1200. }
  1201. /* Poll all queues to verify they have shut down */
  1202. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  1203. msleep(1);
  1204. rx_enabled = 0;
  1205. for (i = 0; i < 4; i++)
  1206. rx_enabled |= rd32(E1000_RXDCTL(i));
  1207. if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
  1208. break;
  1209. }
  1210. if (ms_wait == 10)
  1211. hw_dbg("Queue disable timed out after 10ms\n");
  1212. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  1213. * incoming packets are rejected. Set enable and wait 2ms so that
  1214. * any packet that was coming in as RCTL.EN was set is flushed
  1215. */
  1216. rfctl = rd32(E1000_RFCTL);
  1217. wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
  1218. rlpml = rd32(E1000_RLPML);
  1219. wr32(E1000_RLPML, 0);
  1220. rctl = rd32(E1000_RCTL);
  1221. temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
  1222. temp_rctl |= E1000_RCTL_LPE;
  1223. wr32(E1000_RCTL, temp_rctl);
  1224. wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
  1225. wrfl();
  1226. msleep(2);
  1227. /* Enable RX queues that were previously enabled and restore our
  1228. * previous state
  1229. */
  1230. for (i = 0; i < 4; i++)
  1231. wr32(E1000_RXDCTL(i), rxdctl[i]);
  1232. wr32(E1000_RCTL, rctl);
  1233. wrfl();
  1234. wr32(E1000_RLPML, rlpml);
  1235. wr32(E1000_RFCTL, rfctl);
  1236. /* Flush receive errors generated by workaround */
  1237. rd32(E1000_ROC);
  1238. rd32(E1000_RNBC);
  1239. rd32(E1000_MPC);
  1240. }
  1241. /**
  1242. * igb_set_pcie_completion_timeout - set pci-e completion timeout
  1243. * @hw: pointer to the HW structure
  1244. *
  1245. * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
  1246. * however the hardware default for these parts is 500us to 1ms which is less
  1247. * than the 10ms recommended by the pci-e spec. To address this we need to
  1248. * increase the value to either 10ms to 200ms for capability version 1 config,
  1249. * or 16ms to 55ms for version 2.
  1250. **/
  1251. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
  1252. {
  1253. u32 gcr = rd32(E1000_GCR);
  1254. s32 ret_val = 0;
  1255. u16 pcie_devctl2;
  1256. /* only take action if timeout value is defaulted to 0 */
  1257. if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
  1258. goto out;
  1259. /*
  1260. * if capababilities version is type 1 we can write the
  1261. * timeout of 10ms to 200ms through the GCR register
  1262. */
  1263. if (!(gcr & E1000_GCR_CAP_VER2)) {
  1264. gcr |= E1000_GCR_CMPL_TMOUT_10ms;
  1265. goto out;
  1266. }
  1267. /*
  1268. * for version 2 capabilities we need to write the config space
  1269. * directly in order to set the completion timeout value for
  1270. * 16ms to 55ms
  1271. */
  1272. ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1273. &pcie_devctl2);
  1274. if (ret_val)
  1275. goto out;
  1276. pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
  1277. ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1278. &pcie_devctl2);
  1279. out:
  1280. /* disable completion timeout resend */
  1281. gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
  1282. wr32(E1000_GCR, gcr);
  1283. return ret_val;
  1284. }
  1285. /**
  1286. * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
  1287. * @hw: pointer to the hardware struct
  1288. * @enable: state to enter, either enabled or disabled
  1289. * @pf: Physical Function pool - do not set anti-spoofing for the PF
  1290. *
  1291. * enables/disables L2 switch anti-spoofing functionality.
  1292. **/
  1293. void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
  1294. {
  1295. u32 dtxswc;
  1296. switch (hw->mac.type) {
  1297. case e1000_82576:
  1298. case e1000_i350:
  1299. dtxswc = rd32(E1000_DTXSWC);
  1300. if (enable) {
  1301. dtxswc |= (E1000_DTXSWC_MAC_SPOOF_MASK |
  1302. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1303. /* The PF can spoof - it has to in order to
  1304. * support emulation mode NICs */
  1305. dtxswc ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
  1306. } else {
  1307. dtxswc &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
  1308. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1309. }
  1310. wr32(E1000_DTXSWC, dtxswc);
  1311. break;
  1312. default:
  1313. break;
  1314. }
  1315. }
  1316. /**
  1317. * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
  1318. * @hw: pointer to the hardware struct
  1319. * @enable: state to enter, either enabled or disabled
  1320. *
  1321. * enables/disables L2 switch loopback functionality.
  1322. **/
  1323. void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
  1324. {
  1325. u32 dtxswc = rd32(E1000_DTXSWC);
  1326. if (enable)
  1327. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1328. else
  1329. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1330. wr32(E1000_DTXSWC, dtxswc);
  1331. }
  1332. /**
  1333. * igb_vmdq_set_replication_pf - enable or disable vmdq replication
  1334. * @hw: pointer to the hardware struct
  1335. * @enable: state to enter, either enabled or disabled
  1336. *
  1337. * enables/disables replication of packets across multiple pools.
  1338. **/
  1339. void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
  1340. {
  1341. u32 vt_ctl = rd32(E1000_VT_CTL);
  1342. if (enable)
  1343. vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
  1344. else
  1345. vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
  1346. wr32(E1000_VT_CTL, vt_ctl);
  1347. }
  1348. /**
  1349. * igb_read_phy_reg_82580 - Read 82580 MDI control register
  1350. * @hw: pointer to the HW structure
  1351. * @offset: register offset to be read
  1352. * @data: pointer to the read data
  1353. *
  1354. * Reads the MDI control register in the PHY at offset and stores the
  1355. * information read to data.
  1356. **/
  1357. static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
  1358. {
  1359. s32 ret_val;
  1360. ret_val = hw->phy.ops.acquire(hw);
  1361. if (ret_val)
  1362. goto out;
  1363. ret_val = igb_read_phy_reg_mdic(hw, offset, data);
  1364. hw->phy.ops.release(hw);
  1365. out:
  1366. return ret_val;
  1367. }
  1368. /**
  1369. * igb_write_phy_reg_82580 - Write 82580 MDI control register
  1370. * @hw: pointer to the HW structure
  1371. * @offset: register offset to write to
  1372. * @data: data to write to register at offset
  1373. *
  1374. * Writes data to MDI control register in the PHY at offset.
  1375. **/
  1376. static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
  1377. {
  1378. s32 ret_val;
  1379. ret_val = hw->phy.ops.acquire(hw);
  1380. if (ret_val)
  1381. goto out;
  1382. ret_val = igb_write_phy_reg_mdic(hw, offset, data);
  1383. hw->phy.ops.release(hw);
  1384. out:
  1385. return ret_val;
  1386. }
  1387. /**
  1388. * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
  1389. * @hw: pointer to the HW structure
  1390. *
  1391. * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
  1392. * the values found in the EEPROM. This addresses an issue in which these
  1393. * bits are not restored from EEPROM after reset.
  1394. **/
  1395. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
  1396. {
  1397. s32 ret_val = 0;
  1398. u32 mdicnfg;
  1399. u16 nvm_data = 0;
  1400. if (hw->mac.type != e1000_82580)
  1401. goto out;
  1402. if (!igb_sgmii_active_82575(hw))
  1403. goto out;
  1404. ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1405. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1406. &nvm_data);
  1407. if (ret_val) {
  1408. hw_dbg("NVM Read Error\n");
  1409. goto out;
  1410. }
  1411. mdicnfg = rd32(E1000_MDICNFG);
  1412. if (nvm_data & NVM_WORD24_EXT_MDIO)
  1413. mdicnfg |= E1000_MDICNFG_EXT_MDIO;
  1414. if (nvm_data & NVM_WORD24_COM_MDIO)
  1415. mdicnfg |= E1000_MDICNFG_COM_MDIO;
  1416. wr32(E1000_MDICNFG, mdicnfg);
  1417. out:
  1418. return ret_val;
  1419. }
  1420. /**
  1421. * igb_reset_hw_82580 - Reset hardware
  1422. * @hw: pointer to the HW structure
  1423. *
  1424. * This resets function or entire device (all ports, etc.)
  1425. * to a known state.
  1426. **/
  1427. static s32 igb_reset_hw_82580(struct e1000_hw *hw)
  1428. {
  1429. s32 ret_val = 0;
  1430. /* BH SW mailbox bit in SW_FW_SYNC */
  1431. u16 swmbsw_mask = E1000_SW_SYNCH_MB;
  1432. u32 ctrl, icr;
  1433. bool global_device_reset = hw->dev_spec._82575.global_device_reset;
  1434. hw->dev_spec._82575.global_device_reset = false;
  1435. /* Get current control state. */
  1436. ctrl = rd32(E1000_CTRL);
  1437. /*
  1438. * Prevent the PCI-E bus from sticking if there is no TLP connection
  1439. * on the last TLP read/write transaction when MAC is reset.
  1440. */
  1441. ret_val = igb_disable_pcie_master(hw);
  1442. if (ret_val)
  1443. hw_dbg("PCI-E Master disable polling has failed.\n");
  1444. hw_dbg("Masking off all interrupts\n");
  1445. wr32(E1000_IMC, 0xffffffff);
  1446. wr32(E1000_RCTL, 0);
  1447. wr32(E1000_TCTL, E1000_TCTL_PSP);
  1448. wrfl();
  1449. msleep(10);
  1450. /* Determine whether or not a global dev reset is requested */
  1451. if (global_device_reset &&
  1452. igb_acquire_swfw_sync_82575(hw, swmbsw_mask))
  1453. global_device_reset = false;
  1454. if (global_device_reset &&
  1455. !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
  1456. ctrl |= E1000_CTRL_DEV_RST;
  1457. else
  1458. ctrl |= E1000_CTRL_RST;
  1459. wr32(E1000_CTRL, ctrl);
  1460. /* Add delay to insure DEV_RST has time to complete */
  1461. if (global_device_reset)
  1462. msleep(5);
  1463. ret_val = igb_get_auto_rd_done(hw);
  1464. if (ret_val) {
  1465. /*
  1466. * When auto config read does not complete, do not
  1467. * return with an error. This can happen in situations
  1468. * where there is no eeprom and prevents getting link.
  1469. */
  1470. hw_dbg("Auto Read Done did not complete\n");
  1471. }
  1472. /* If EEPROM is not present, run manual init scripts */
  1473. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  1474. igb_reset_init_script_82575(hw);
  1475. /* clear global device reset status bit */
  1476. wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
  1477. /* Clear any pending interrupt events. */
  1478. wr32(E1000_IMC, 0xffffffff);
  1479. icr = rd32(E1000_ICR);
  1480. ret_val = igb_reset_mdicnfg_82580(hw);
  1481. if (ret_val)
  1482. hw_dbg("Could not reset MDICNFG based on EEPROM\n");
  1483. /* Install any alternate MAC address into RAR0 */
  1484. ret_val = igb_check_alt_mac_addr(hw);
  1485. /* Release semaphore */
  1486. if (global_device_reset)
  1487. igb_release_swfw_sync_82575(hw, swmbsw_mask);
  1488. return ret_val;
  1489. }
  1490. /**
  1491. * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
  1492. * @data: data received by reading RXPBS register
  1493. *
  1494. * The 82580 uses a table based approach for packet buffer allocation sizes.
  1495. * This function converts the retrieved value into the correct table value
  1496. * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
  1497. * 0x0 36 72 144 1 2 4 8 16
  1498. * 0x8 35 70 140 rsv rsv rsv rsv rsv
  1499. */
  1500. u16 igb_rxpbs_adjust_82580(u32 data)
  1501. {
  1502. u16 ret_val = 0;
  1503. if (data < E1000_82580_RXPBS_TABLE_SIZE)
  1504. ret_val = e1000_82580_rxpbs_table[data];
  1505. return ret_val;
  1506. }
  1507. /**
  1508. * igb_set_eee_i350 - Enable/disable EEE support
  1509. * @hw: pointer to the HW structure
  1510. *
  1511. * Enable/disable EEE based on setting in dev_spec structure.
  1512. *
  1513. **/
  1514. s32 igb_set_eee_i350(struct e1000_hw *hw)
  1515. {
  1516. s32 ret_val = 0;
  1517. u32 ipcnfg, eeer, ctrl_ext;
  1518. ctrl_ext = rd32(E1000_CTRL_EXT);
  1519. if ((hw->mac.type != e1000_i350) ||
  1520. (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK))
  1521. goto out;
  1522. ipcnfg = rd32(E1000_IPCNFG);
  1523. eeer = rd32(E1000_EEER);
  1524. /* enable or disable per user setting */
  1525. if (!(hw->dev_spec._82575.eee_disable)) {
  1526. ipcnfg |= (E1000_IPCNFG_EEE_1G_AN |
  1527. E1000_IPCNFG_EEE_100M_AN);
  1528. eeer |= (E1000_EEER_TX_LPI_EN |
  1529. E1000_EEER_RX_LPI_EN |
  1530. E1000_EEER_LPI_FC);
  1531. } else {
  1532. ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
  1533. E1000_IPCNFG_EEE_100M_AN);
  1534. eeer &= ~(E1000_EEER_TX_LPI_EN |
  1535. E1000_EEER_RX_LPI_EN |
  1536. E1000_EEER_LPI_FC);
  1537. }
  1538. wr32(E1000_IPCNFG, ipcnfg);
  1539. wr32(E1000_EEER, eeer);
  1540. out:
  1541. return ret_val;
  1542. }
  1543. static struct e1000_mac_operations e1000_mac_ops_82575 = {
  1544. .init_hw = igb_init_hw_82575,
  1545. .check_for_link = igb_check_for_link_82575,
  1546. .rar_set = igb_rar_set,
  1547. .read_mac_addr = igb_read_mac_addr_82575,
  1548. .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
  1549. };
  1550. static struct e1000_phy_operations e1000_phy_ops_82575 = {
  1551. .acquire = igb_acquire_phy_82575,
  1552. .get_cfg_done = igb_get_cfg_done_82575,
  1553. .release = igb_release_phy_82575,
  1554. };
  1555. static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
  1556. .acquire = igb_acquire_nvm_82575,
  1557. .read = igb_read_nvm_eerd,
  1558. .release = igb_release_nvm_82575,
  1559. .write = igb_write_nvm_spi,
  1560. };
  1561. const struct e1000_info e1000_82575_info = {
  1562. .get_invariants = igb_get_invariants_82575,
  1563. .mac_ops = &e1000_mac_ops_82575,
  1564. .phy_ops = &e1000_phy_ops_82575,
  1565. .nvm_ops = &e1000_nvm_ops_82575,
  1566. };