e1000_82575.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  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/slab.h>
  25. #include <linux/if_ether.h>
  26. #include "e1000_mac.h"
  27. #include "e1000_82575.h"
  28. static s32 igb_get_invariants_82575(struct e1000_hw *);
  29. static s32 igb_acquire_phy_82575(struct e1000_hw *);
  30. static void igb_release_phy_82575(struct e1000_hw *);
  31. static s32 igb_acquire_nvm_82575(struct e1000_hw *);
  32. static void igb_release_nvm_82575(struct e1000_hw *);
  33. static s32 igb_check_for_link_82575(struct e1000_hw *);
  34. static s32 igb_get_cfg_done_82575(struct e1000_hw *);
  35. static s32 igb_init_hw_82575(struct e1000_hw *);
  36. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
  37. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
  38. static s32 igb_reset_hw_82575(struct e1000_hw *);
  39. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
  40. static s32 igb_setup_copper_link_82575(struct e1000_hw *);
  41. static s32 igb_setup_fiber_serdes_link_82575(struct e1000_hw *);
  42. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
  43. static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
  44. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
  45. static void igb_configure_pcs_link_82575(struct e1000_hw *);
  46. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
  47. u16 *);
  48. static s32 igb_get_phy_id_82575(struct e1000_hw *);
  49. static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
  50. static bool igb_sgmii_active_82575(struct e1000_hw *);
  51. static s32 igb_reset_init_script_82575(struct e1000_hw *);
  52. static s32 igb_read_mac_addr_82575(struct e1000_hw *);
  53. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
  54. static s32 igb_get_invariants_82575(struct e1000_hw *hw)
  55. {
  56. struct e1000_phy_info *phy = &hw->phy;
  57. struct e1000_nvm_info *nvm = &hw->nvm;
  58. struct e1000_mac_info *mac = &hw->mac;
  59. struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
  60. u32 eecd;
  61. s32 ret_val;
  62. u16 size;
  63. u32 ctrl_ext = 0;
  64. switch (hw->device_id) {
  65. case E1000_DEV_ID_82575EB_COPPER:
  66. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  67. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  68. mac->type = e1000_82575;
  69. break;
  70. case E1000_DEV_ID_82576:
  71. case E1000_DEV_ID_82576_NS:
  72. case E1000_DEV_ID_82576_FIBER:
  73. case E1000_DEV_ID_82576_SERDES:
  74. case E1000_DEV_ID_82576_QUAD_COPPER:
  75. mac->type = e1000_82576;
  76. break;
  77. default:
  78. return -E1000_ERR_MAC_INIT;
  79. break;
  80. }
  81. /* Set media type */
  82. /*
  83. * The 82575 uses bits 22:23 for link mode. The mode can be changed
  84. * based on the EEPROM. We cannot rely upon device ID. There
  85. * is no distinguishable difference between fiber and internal
  86. * SerDes mode on the 82575. There can be an external PHY attached
  87. * on the SGMII interface. For this, we'll set sgmii_active to true.
  88. */
  89. phy->media_type = e1000_media_type_copper;
  90. dev_spec->sgmii_active = false;
  91. ctrl_ext = rd32(E1000_CTRL_EXT);
  92. if ((ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) ==
  93. E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES) {
  94. hw->phy.media_type = e1000_media_type_internal_serdes;
  95. ctrl_ext |= E1000_CTRL_I2C_ENA;
  96. } else if (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII) {
  97. dev_spec->sgmii_active = true;
  98. ctrl_ext |= E1000_CTRL_I2C_ENA;
  99. } else {
  100. ctrl_ext &= ~E1000_CTRL_I2C_ENA;
  101. }
  102. wr32(E1000_CTRL_EXT, ctrl_ext);
  103. /* Set mta register count */
  104. mac->mta_reg_count = 128;
  105. /* Set rar entry count */
  106. mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
  107. if (mac->type == e1000_82576)
  108. mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
  109. /* Set if part includes ASF firmware */
  110. mac->asf_firmware_present = true;
  111. /* Set if manageability features are enabled. */
  112. mac->arc_subsystem_valid =
  113. (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
  114. ? true : false;
  115. /* physical interface link setup */
  116. mac->ops.setup_physical_interface =
  117. (hw->phy.media_type == e1000_media_type_copper)
  118. ? igb_setup_copper_link_82575
  119. : igb_setup_fiber_serdes_link_82575;
  120. /* NVM initialization */
  121. eecd = rd32(E1000_EECD);
  122. nvm->opcode_bits = 8;
  123. nvm->delay_usec = 1;
  124. switch (nvm->override) {
  125. case e1000_nvm_override_spi_large:
  126. nvm->page_size = 32;
  127. nvm->address_bits = 16;
  128. break;
  129. case e1000_nvm_override_spi_small:
  130. nvm->page_size = 8;
  131. nvm->address_bits = 8;
  132. break;
  133. default:
  134. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  135. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
  136. break;
  137. }
  138. nvm->type = e1000_nvm_eeprom_spi;
  139. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  140. E1000_EECD_SIZE_EX_SHIFT);
  141. /*
  142. * Added to a constant, "size" becomes the left-shift value
  143. * for setting word_size.
  144. */
  145. size += NVM_WORD_SIZE_BASE_SHIFT;
  146. /* EEPROM access above 16k is unsupported */
  147. if (size > 14)
  148. size = 14;
  149. nvm->word_size = 1 << size;
  150. /* setup PHY parameters */
  151. if (phy->media_type != e1000_media_type_copper) {
  152. phy->type = e1000_phy_none;
  153. return 0;
  154. }
  155. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  156. phy->reset_delay_us = 100;
  157. /* PHY function pointers */
  158. if (igb_sgmii_active_82575(hw)) {
  159. phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
  160. phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
  161. phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
  162. } else {
  163. phy->ops.reset = igb_phy_hw_reset;
  164. phy->ops.read_reg = igb_read_phy_reg_igp;
  165. phy->ops.write_reg = igb_write_phy_reg_igp;
  166. }
  167. /* set lan id */
  168. hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
  169. E1000_STATUS_FUNC_SHIFT;
  170. /* Set phy->phy_addr and phy->id. */
  171. ret_val = igb_get_phy_id_82575(hw);
  172. if (ret_val)
  173. return ret_val;
  174. /* Verify phy id and set remaining function pointers */
  175. switch (phy->id) {
  176. case M88E1111_I_PHY_ID:
  177. phy->type = e1000_phy_m88;
  178. phy->ops.get_phy_info = igb_get_phy_info_m88;
  179. phy->ops.get_cable_length = igb_get_cable_length_m88;
  180. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  181. break;
  182. case IGP03E1000_E_PHY_ID:
  183. phy->type = e1000_phy_igp_3;
  184. phy->ops.get_phy_info = igb_get_phy_info_igp;
  185. phy->ops.get_cable_length = igb_get_cable_length_igp_2;
  186. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
  187. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
  188. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
  189. break;
  190. default:
  191. return -E1000_ERR_PHY;
  192. }
  193. /* if 82576 then initialize mailbox parameters */
  194. if (mac->type == e1000_82576)
  195. igb_init_mbx_params_pf(hw);
  196. return 0;
  197. }
  198. /**
  199. * igb_acquire_phy_82575 - Acquire rights to access PHY
  200. * @hw: pointer to the HW structure
  201. *
  202. * Acquire access rights to the correct PHY. This is a
  203. * function pointer entry point called by the api module.
  204. **/
  205. static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
  206. {
  207. u16 mask;
  208. mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
  209. return igb_acquire_swfw_sync_82575(hw, mask);
  210. }
  211. /**
  212. * igb_release_phy_82575 - Release rights to access PHY
  213. * @hw: pointer to the HW structure
  214. *
  215. * A wrapper to release access rights to the correct PHY. This is a
  216. * function pointer entry point called by the api module.
  217. **/
  218. static void igb_release_phy_82575(struct e1000_hw *hw)
  219. {
  220. u16 mask;
  221. mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
  222. igb_release_swfw_sync_82575(hw, mask);
  223. }
  224. /**
  225. * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
  226. * @hw: pointer to the HW structure
  227. * @offset: register offset to be read
  228. * @data: pointer to the read data
  229. *
  230. * Reads the PHY register at offset using the serial gigabit media independent
  231. * interface and stores the retrieved information in data.
  232. **/
  233. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  234. u16 *data)
  235. {
  236. struct e1000_phy_info *phy = &hw->phy;
  237. u32 i, i2ccmd = 0;
  238. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  239. hw_dbg("PHY Address %u is out of range\n", offset);
  240. return -E1000_ERR_PARAM;
  241. }
  242. /*
  243. * Set up Op-code, Phy Address, and register address in the I2CCMD
  244. * register. The MAC will take care of interfacing with the
  245. * PHY to retrieve the desired data.
  246. */
  247. i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
  248. (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
  249. (E1000_I2CCMD_OPCODE_READ));
  250. wr32(E1000_I2CCMD, i2ccmd);
  251. /* Poll the ready bit to see if the I2C read completed */
  252. for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
  253. udelay(50);
  254. i2ccmd = rd32(E1000_I2CCMD);
  255. if (i2ccmd & E1000_I2CCMD_READY)
  256. break;
  257. }
  258. if (!(i2ccmd & E1000_I2CCMD_READY)) {
  259. hw_dbg("I2CCMD Read did not complete\n");
  260. return -E1000_ERR_PHY;
  261. }
  262. if (i2ccmd & E1000_I2CCMD_ERROR) {
  263. hw_dbg("I2CCMD Error bit set\n");
  264. return -E1000_ERR_PHY;
  265. }
  266. /* Need to byte-swap the 16-bit value. */
  267. *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
  268. return 0;
  269. }
  270. /**
  271. * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
  272. * @hw: pointer to the HW structure
  273. * @offset: register offset to write to
  274. * @data: data to write at register offset
  275. *
  276. * Writes the data to PHY register at the offset using the serial gigabit
  277. * media independent interface.
  278. **/
  279. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  280. u16 data)
  281. {
  282. struct e1000_phy_info *phy = &hw->phy;
  283. u32 i, i2ccmd = 0;
  284. u16 phy_data_swapped;
  285. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  286. hw_dbg("PHY Address %d is out of range\n", offset);
  287. return -E1000_ERR_PARAM;
  288. }
  289. /* Swap the data bytes for the I2C interface */
  290. phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
  291. /*
  292. * Set up Op-code, Phy Address, and register address in the I2CCMD
  293. * register. The MAC will take care of interfacing with the
  294. * PHY to retrieve the desired data.
  295. */
  296. i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
  297. (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
  298. E1000_I2CCMD_OPCODE_WRITE |
  299. phy_data_swapped);
  300. wr32(E1000_I2CCMD, i2ccmd);
  301. /* Poll the ready bit to see if the I2C read completed */
  302. for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
  303. udelay(50);
  304. i2ccmd = rd32(E1000_I2CCMD);
  305. if (i2ccmd & E1000_I2CCMD_READY)
  306. break;
  307. }
  308. if (!(i2ccmd & E1000_I2CCMD_READY)) {
  309. hw_dbg("I2CCMD Write did not complete\n");
  310. return -E1000_ERR_PHY;
  311. }
  312. if (i2ccmd & E1000_I2CCMD_ERROR) {
  313. hw_dbg("I2CCMD Error bit set\n");
  314. return -E1000_ERR_PHY;
  315. }
  316. return 0;
  317. }
  318. /**
  319. * igb_get_phy_id_82575 - Retrieve PHY addr and id
  320. * @hw: pointer to the HW structure
  321. *
  322. * Retrieves the PHY address and ID for both PHY's which do and do not use
  323. * sgmi interface.
  324. **/
  325. static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
  326. {
  327. struct e1000_phy_info *phy = &hw->phy;
  328. s32 ret_val = 0;
  329. u16 phy_id;
  330. /*
  331. * For SGMII PHYs, we try the list of possible addresses until
  332. * we find one that works. For non-SGMII PHYs
  333. * (e.g. integrated copper PHYs), an address of 1 should
  334. * work. The result of this function should mean phy->phy_addr
  335. * and phy->id are set correctly.
  336. */
  337. if (!(igb_sgmii_active_82575(hw))) {
  338. phy->addr = 1;
  339. ret_val = igb_get_phy_id(hw);
  340. goto out;
  341. }
  342. /*
  343. * The address field in the I2CCMD register is 3 bits and 0 is invalid.
  344. * Therefore, we need to test 1-7
  345. */
  346. for (phy->addr = 1; phy->addr < 8; phy->addr++) {
  347. ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
  348. if (ret_val == 0) {
  349. hw_dbg("Vendor ID 0x%08X read at address %u\n",
  350. phy_id, phy->addr);
  351. /*
  352. * At the time of this writing, The M88 part is
  353. * the only supported SGMII PHY product.
  354. */
  355. if (phy_id == M88_VENDOR)
  356. break;
  357. } else {
  358. hw_dbg("PHY address %u was unreadable\n", phy->addr);
  359. }
  360. }
  361. /* A valid PHY type couldn't be found. */
  362. if (phy->addr == 8) {
  363. phy->addr = 0;
  364. ret_val = -E1000_ERR_PHY;
  365. goto out;
  366. }
  367. ret_val = igb_get_phy_id(hw);
  368. out:
  369. return ret_val;
  370. }
  371. /**
  372. * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
  373. * @hw: pointer to the HW structure
  374. *
  375. * Resets the PHY using the serial gigabit media independent interface.
  376. **/
  377. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
  378. {
  379. s32 ret_val;
  380. /*
  381. * This isn't a true "hard" reset, but is the only reset
  382. * available to us at this time.
  383. */
  384. hw_dbg("Soft resetting SGMII attached PHY...\n");
  385. /*
  386. * SFP documentation requires the following to configure the SPF module
  387. * to work on SGMII. No further documentation is given.
  388. */
  389. ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
  390. if (ret_val)
  391. goto out;
  392. ret_val = igb_phy_sw_reset(hw);
  393. out:
  394. return ret_val;
  395. }
  396. /**
  397. * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
  398. * @hw: pointer to the HW structure
  399. * @active: true to enable LPLU, false to disable
  400. *
  401. * Sets the LPLU D0 state according to the active flag. When
  402. * activating LPLU this function also disables smart speed
  403. * and vice versa. LPLU will not be activated unless the
  404. * device autonegotiation advertisement meets standards of
  405. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  406. * This is a function pointer entry point only called by
  407. * PHY setup routines.
  408. **/
  409. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
  410. {
  411. struct e1000_phy_info *phy = &hw->phy;
  412. s32 ret_val;
  413. u16 data;
  414. ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  415. if (ret_val)
  416. goto out;
  417. if (active) {
  418. data |= IGP02E1000_PM_D0_LPLU;
  419. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  420. data);
  421. if (ret_val)
  422. goto out;
  423. /* When LPLU is enabled, we should disable SmartSpeed */
  424. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  425. &data);
  426. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  427. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  428. data);
  429. if (ret_val)
  430. goto out;
  431. } else {
  432. data &= ~IGP02E1000_PM_D0_LPLU;
  433. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  434. data);
  435. /*
  436. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  437. * during Dx states where the power conservation is most
  438. * important. During driver activity we should enable
  439. * SmartSpeed, so performance is maintained.
  440. */
  441. if (phy->smart_speed == e1000_smart_speed_on) {
  442. ret_val = phy->ops.read_reg(hw,
  443. IGP01E1000_PHY_PORT_CONFIG, &data);
  444. if (ret_val)
  445. goto out;
  446. data |= IGP01E1000_PSCFR_SMART_SPEED;
  447. ret_val = phy->ops.write_reg(hw,
  448. IGP01E1000_PHY_PORT_CONFIG, data);
  449. if (ret_val)
  450. goto out;
  451. } else if (phy->smart_speed == e1000_smart_speed_off) {
  452. ret_val = phy->ops.read_reg(hw,
  453. IGP01E1000_PHY_PORT_CONFIG, &data);
  454. if (ret_val)
  455. goto out;
  456. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  457. ret_val = phy->ops.write_reg(hw,
  458. IGP01E1000_PHY_PORT_CONFIG, data);
  459. if (ret_val)
  460. goto out;
  461. }
  462. }
  463. out:
  464. return ret_val;
  465. }
  466. /**
  467. * igb_acquire_nvm_82575 - Request for access to EEPROM
  468. * @hw: pointer to the HW structure
  469. *
  470. * Acquire the necessary semaphores for exclusive access to the EEPROM.
  471. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  472. * Return successful if access grant bit set, else clear the request for
  473. * EEPROM access and return -E1000_ERR_NVM (-1).
  474. **/
  475. static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
  476. {
  477. s32 ret_val;
  478. ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  479. if (ret_val)
  480. goto out;
  481. ret_val = igb_acquire_nvm(hw);
  482. if (ret_val)
  483. igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  484. out:
  485. return ret_val;
  486. }
  487. /**
  488. * igb_release_nvm_82575 - Release exclusive access to EEPROM
  489. * @hw: pointer to the HW structure
  490. *
  491. * Stop any current commands to the EEPROM and clear the EEPROM request bit,
  492. * then release the semaphores acquired.
  493. **/
  494. static void igb_release_nvm_82575(struct e1000_hw *hw)
  495. {
  496. igb_release_nvm(hw);
  497. igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  498. }
  499. /**
  500. * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
  501. * @hw: pointer to the HW structure
  502. * @mask: specifies which semaphore to acquire
  503. *
  504. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  505. * will also specify which port we're acquiring the lock for.
  506. **/
  507. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  508. {
  509. u32 swfw_sync;
  510. u32 swmask = mask;
  511. u32 fwmask = mask << 16;
  512. s32 ret_val = 0;
  513. s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
  514. while (i < timeout) {
  515. if (igb_get_hw_semaphore(hw)) {
  516. ret_val = -E1000_ERR_SWFW_SYNC;
  517. goto out;
  518. }
  519. swfw_sync = rd32(E1000_SW_FW_SYNC);
  520. if (!(swfw_sync & (fwmask | swmask)))
  521. break;
  522. /*
  523. * Firmware currently using resource (fwmask)
  524. * or other software thread using resource (swmask)
  525. */
  526. igb_put_hw_semaphore(hw);
  527. mdelay(5);
  528. i++;
  529. }
  530. if (i == timeout) {
  531. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  532. ret_val = -E1000_ERR_SWFW_SYNC;
  533. goto out;
  534. }
  535. swfw_sync |= swmask;
  536. wr32(E1000_SW_FW_SYNC, swfw_sync);
  537. igb_put_hw_semaphore(hw);
  538. out:
  539. return ret_val;
  540. }
  541. /**
  542. * igb_release_swfw_sync_82575 - Release SW/FW semaphore
  543. * @hw: pointer to the HW structure
  544. * @mask: specifies which semaphore to acquire
  545. *
  546. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  547. * will also specify which port we're releasing the lock for.
  548. **/
  549. static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  550. {
  551. u32 swfw_sync;
  552. while (igb_get_hw_semaphore(hw) != 0);
  553. /* Empty */
  554. swfw_sync = rd32(E1000_SW_FW_SYNC);
  555. swfw_sync &= ~mask;
  556. wr32(E1000_SW_FW_SYNC, swfw_sync);
  557. igb_put_hw_semaphore(hw);
  558. }
  559. /**
  560. * igb_get_cfg_done_82575 - Read config done bit
  561. * @hw: pointer to the HW structure
  562. *
  563. * Read the management control register for the config done bit for
  564. * completion status. NOTE: silicon which is EEPROM-less will fail trying
  565. * to read the config done bit, so an error is *ONLY* logged and returns
  566. * 0. If we were to return with error, EEPROM-less silicon
  567. * would not be able to be reset or change link.
  568. **/
  569. static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
  570. {
  571. s32 timeout = PHY_CFG_TIMEOUT;
  572. s32 ret_val = 0;
  573. u32 mask = E1000_NVM_CFG_DONE_PORT_0;
  574. if (hw->bus.func == 1)
  575. mask = E1000_NVM_CFG_DONE_PORT_1;
  576. while (timeout) {
  577. if (rd32(E1000_EEMNGCTL) & mask)
  578. break;
  579. msleep(1);
  580. timeout--;
  581. }
  582. if (!timeout)
  583. hw_dbg("MNG configuration cycle has not completed.\n");
  584. /* If EEPROM is not marked present, init the PHY manually */
  585. if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
  586. (hw->phy.type == e1000_phy_igp_3))
  587. igb_phy_init_script_igp3(hw);
  588. return ret_val;
  589. }
  590. /**
  591. * igb_check_for_link_82575 - Check for link
  592. * @hw: pointer to the HW structure
  593. *
  594. * If sgmii is enabled, then use the pcs register to determine link, otherwise
  595. * use the generic interface for determining link.
  596. **/
  597. static s32 igb_check_for_link_82575(struct e1000_hw *hw)
  598. {
  599. s32 ret_val;
  600. u16 speed, duplex;
  601. /* SGMII link check is done through the PCS register. */
  602. if ((hw->phy.media_type != e1000_media_type_copper) ||
  603. (igb_sgmii_active_82575(hw))) {
  604. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
  605. &duplex);
  606. /*
  607. * Use this flag to determine if link needs to be checked or
  608. * not. If we have link clear the flag so that we do not
  609. * continue to check for link.
  610. */
  611. hw->mac.get_link_status = !hw->mac.serdes_has_link;
  612. } else {
  613. ret_val = igb_check_for_copper_link(hw);
  614. }
  615. return ret_val;
  616. }
  617. /**
  618. * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
  619. * @hw: pointer to the HW structure
  620. * @speed: stores the current speed
  621. * @duplex: stores the current duplex
  622. *
  623. * Using the physical coding sub-layer (PCS), retrieve the current speed and
  624. * duplex, then store the values in the pointers provided.
  625. **/
  626. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
  627. u16 *duplex)
  628. {
  629. struct e1000_mac_info *mac = &hw->mac;
  630. u32 pcs;
  631. /* Set up defaults for the return values of this function */
  632. mac->serdes_has_link = false;
  633. *speed = 0;
  634. *duplex = 0;
  635. /*
  636. * Read the PCS Status register for link state. For non-copper mode,
  637. * the status register is not accurate. The PCS status register is
  638. * used instead.
  639. */
  640. pcs = rd32(E1000_PCS_LSTAT);
  641. /*
  642. * The link up bit determines when link is up on autoneg. The sync ok
  643. * gets set once both sides sync up and agree upon link. Stable link
  644. * can be determined by checking for both link up and link sync ok
  645. */
  646. if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
  647. mac->serdes_has_link = true;
  648. /* Detect and store PCS speed */
  649. if (pcs & E1000_PCS_LSTS_SPEED_1000) {
  650. *speed = SPEED_1000;
  651. } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
  652. *speed = SPEED_100;
  653. } else {
  654. *speed = SPEED_10;
  655. }
  656. /* Detect and store PCS duplex */
  657. if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
  658. *duplex = FULL_DUPLEX;
  659. } else {
  660. *duplex = HALF_DUPLEX;
  661. }
  662. }
  663. return 0;
  664. }
  665. /**
  666. * igb_shutdown_fiber_serdes_link_82575 - Remove link during power down
  667. * @hw: pointer to the HW structure
  668. *
  669. * In the case of fiber serdes, shut down optics and PCS on driver unload
  670. * when management pass thru is not enabled.
  671. **/
  672. void igb_shutdown_fiber_serdes_link_82575(struct e1000_hw *hw)
  673. {
  674. u32 reg;
  675. if (hw->phy.media_type != e1000_media_type_internal_serdes)
  676. return;
  677. /* if the management interface is not enabled, then power down */
  678. if (!igb_enable_mng_pass_thru(hw)) {
  679. /* Disable PCS to turn off link */
  680. reg = rd32(E1000_PCS_CFG0);
  681. reg &= ~E1000_PCS_CFG_PCS_EN;
  682. wr32(E1000_PCS_CFG0, reg);
  683. /* shutdown the laser */
  684. reg = rd32(E1000_CTRL_EXT);
  685. reg |= E1000_CTRL_EXT_SDP7_DATA;
  686. wr32(E1000_CTRL_EXT, reg);
  687. /* flush the write to verify completion */
  688. wrfl();
  689. msleep(1);
  690. }
  691. return;
  692. }
  693. /**
  694. * igb_reset_hw_82575 - Reset hardware
  695. * @hw: pointer to the HW structure
  696. *
  697. * This resets the hardware into a known state. This is a
  698. * function pointer entry point called by the api module.
  699. **/
  700. static s32 igb_reset_hw_82575(struct e1000_hw *hw)
  701. {
  702. u32 ctrl, icr;
  703. s32 ret_val;
  704. /*
  705. * Prevent the PCI-E bus from sticking if there is no TLP connection
  706. * on the last TLP read/write transaction when MAC is reset.
  707. */
  708. ret_val = igb_disable_pcie_master(hw);
  709. if (ret_val)
  710. hw_dbg("PCI-E Master disable polling has failed.\n");
  711. /* set the completion timeout for interface */
  712. ret_val = igb_set_pcie_completion_timeout(hw);
  713. if (ret_val) {
  714. hw_dbg("PCI-E Set completion timeout has failed.\n");
  715. }
  716. hw_dbg("Masking off all interrupts\n");
  717. wr32(E1000_IMC, 0xffffffff);
  718. wr32(E1000_RCTL, 0);
  719. wr32(E1000_TCTL, E1000_TCTL_PSP);
  720. wrfl();
  721. msleep(10);
  722. ctrl = rd32(E1000_CTRL);
  723. hw_dbg("Issuing a global reset to MAC\n");
  724. wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
  725. ret_val = igb_get_auto_rd_done(hw);
  726. if (ret_val) {
  727. /*
  728. * When auto config read does not complete, do not
  729. * return with an error. This can happen in situations
  730. * where there is no eeprom and prevents getting link.
  731. */
  732. hw_dbg("Auto Read Done did not complete\n");
  733. }
  734. /* If EEPROM is not present, run manual init scripts */
  735. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  736. igb_reset_init_script_82575(hw);
  737. /* Clear any pending interrupt events. */
  738. wr32(E1000_IMC, 0xffffffff);
  739. icr = rd32(E1000_ICR);
  740. /* Install any alternate MAC address into RAR0 */
  741. ret_val = igb_check_alt_mac_addr(hw);
  742. return ret_val;
  743. }
  744. /**
  745. * igb_init_hw_82575 - Initialize hardware
  746. * @hw: pointer to the HW structure
  747. *
  748. * This inits the hardware readying it for operation.
  749. **/
  750. static s32 igb_init_hw_82575(struct e1000_hw *hw)
  751. {
  752. struct e1000_mac_info *mac = &hw->mac;
  753. s32 ret_val;
  754. u16 i, rar_count = mac->rar_entry_count;
  755. /* Initialize identification LED */
  756. ret_val = igb_id_led_init(hw);
  757. if (ret_val) {
  758. hw_dbg("Error initializing identification LED\n");
  759. /* This is not fatal and we should not stop init due to this */
  760. }
  761. /* Disabling VLAN filtering */
  762. hw_dbg("Initializing the IEEE VLAN\n");
  763. igb_clear_vfta(hw);
  764. /* Setup the receive address */
  765. igb_init_rx_addrs(hw, rar_count);
  766. /* Zero out the Multicast HASH table */
  767. hw_dbg("Zeroing the MTA\n");
  768. for (i = 0; i < mac->mta_reg_count; i++)
  769. array_wr32(E1000_MTA, i, 0);
  770. /* Setup link and flow control */
  771. ret_val = igb_setup_link(hw);
  772. /*
  773. * Clear all of the statistics registers (clear on read). It is
  774. * important that we do this after we have tried to establish link
  775. * because the symbol error count will increment wildly if there
  776. * is no link.
  777. */
  778. igb_clear_hw_cntrs_82575(hw);
  779. return ret_val;
  780. }
  781. /**
  782. * igb_setup_copper_link_82575 - Configure copper link settings
  783. * @hw: pointer to the HW structure
  784. *
  785. * Configures the link for auto-neg or forced speed and duplex. Then we check
  786. * for link, once link is established calls to configure collision distance
  787. * and flow control are called.
  788. **/
  789. static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
  790. {
  791. u32 ctrl;
  792. s32 ret_val;
  793. bool link;
  794. ctrl = rd32(E1000_CTRL);
  795. ctrl |= E1000_CTRL_SLU;
  796. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  797. wr32(E1000_CTRL, ctrl);
  798. switch (hw->phy.type) {
  799. case e1000_phy_m88:
  800. ret_val = igb_copper_link_setup_m88(hw);
  801. break;
  802. case e1000_phy_igp_3:
  803. ret_val = igb_copper_link_setup_igp(hw);
  804. break;
  805. default:
  806. ret_val = -E1000_ERR_PHY;
  807. break;
  808. }
  809. if (ret_val)
  810. goto out;
  811. if (hw->mac.autoneg) {
  812. /*
  813. * Setup autoneg and flow control advertisement
  814. * and perform autonegotiation.
  815. */
  816. ret_val = igb_copper_link_autoneg(hw);
  817. if (ret_val)
  818. goto out;
  819. } else {
  820. /*
  821. * PHY will be set to 10H, 10F, 100H or 100F
  822. * depending on user settings.
  823. */
  824. hw_dbg("Forcing Speed and Duplex\n");
  825. ret_val = hw->phy.ops.force_speed_duplex(hw);
  826. if (ret_val) {
  827. hw_dbg("Error Forcing Speed and Duplex\n");
  828. goto out;
  829. }
  830. }
  831. igb_configure_pcs_link_82575(hw);
  832. /*
  833. * Check link status. Wait up to 100 microseconds for link to become
  834. * valid.
  835. */
  836. ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
  837. if (ret_val)
  838. goto out;
  839. if (link) {
  840. hw_dbg("Valid link established!!!\n");
  841. /* Config the MAC and PHY after link is up */
  842. igb_config_collision_dist(hw);
  843. ret_val = igb_config_fc_after_link_up(hw);
  844. } else {
  845. hw_dbg("Unable to establish link!!!\n");
  846. }
  847. out:
  848. return ret_val;
  849. }
  850. /**
  851. * igb_setup_fiber_serdes_link_82575 - Setup link for fiber/serdes
  852. * @hw: pointer to the HW structure
  853. *
  854. * Configures speed and duplex for fiber and serdes links.
  855. **/
  856. static s32 igb_setup_fiber_serdes_link_82575(struct e1000_hw *hw)
  857. {
  858. u32 reg;
  859. /*
  860. * On the 82575, SerDes loopback mode persists until it is
  861. * explicitly turned off or a power cycle is performed. A read to
  862. * the register does not indicate its status. Therefore, we ensure
  863. * loopback mode is disabled during initialization.
  864. */
  865. wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  866. /* Force link up, set 1gb, set both sw defined pins */
  867. reg = rd32(E1000_CTRL);
  868. reg |= E1000_CTRL_SLU |
  869. E1000_CTRL_SPD_1000 |
  870. E1000_CTRL_FRCSPD |
  871. E1000_CTRL_SWDPIN0 |
  872. E1000_CTRL_SWDPIN1;
  873. wr32(E1000_CTRL, reg);
  874. /* Power on phy for 82576 fiber adapters */
  875. if (hw->mac.type == e1000_82576) {
  876. reg = rd32(E1000_CTRL_EXT);
  877. reg &= ~E1000_CTRL_EXT_SDP7_DATA;
  878. wr32(E1000_CTRL_EXT, reg);
  879. }
  880. /* Set switch control to serdes energy detect */
  881. reg = rd32(E1000_CONNSW);
  882. reg |= E1000_CONNSW_ENRGSRC;
  883. wr32(E1000_CONNSW, reg);
  884. /*
  885. * New SerDes mode allows for forcing speed or autonegotiating speed
  886. * at 1gb. Autoneg should be default set by most drivers. This is the
  887. * mode that will be compatible with older link partners and switches.
  888. * However, both are supported by the hardware and some drivers/tools.
  889. */
  890. reg = rd32(E1000_PCS_LCTL);
  891. reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
  892. E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
  893. if (hw->mac.autoneg) {
  894. /* Set PCS register for autoneg */
  895. reg |= E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
  896. E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
  897. E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
  898. E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
  899. hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
  900. } else {
  901. /* Set PCS register for forced speed */
  902. reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
  903. E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
  904. E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
  905. E1000_PCS_LCTL_FSD | /* Force Speed */
  906. E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
  907. hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
  908. }
  909. if (hw->mac.type == e1000_82576) {
  910. reg |= E1000_PCS_LCTL_FORCE_FCTRL;
  911. igb_force_mac_fc(hw);
  912. }
  913. wr32(E1000_PCS_LCTL, reg);
  914. return 0;
  915. }
  916. /**
  917. * igb_configure_pcs_link_82575 - Configure PCS link
  918. * @hw: pointer to the HW structure
  919. *
  920. * Configure the physical coding sub-layer (PCS) link. The PCS link is
  921. * only used on copper connections where the serialized gigabit media
  922. * independent interface (sgmii) is being used. Configures the link
  923. * for auto-negotiation or forces speed/duplex.
  924. **/
  925. static void igb_configure_pcs_link_82575(struct e1000_hw *hw)
  926. {
  927. struct e1000_mac_info *mac = &hw->mac;
  928. u32 reg = 0;
  929. if (hw->phy.media_type != e1000_media_type_copper ||
  930. !(igb_sgmii_active_82575(hw)))
  931. return;
  932. /* For SGMII, we need to issue a PCS autoneg restart */
  933. reg = rd32(E1000_PCS_LCTL);
  934. /* AN time out should be disabled for SGMII mode */
  935. reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
  936. if (mac->autoneg) {
  937. /* Make sure forced speed and force link are not set */
  938. reg &= ~(E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
  939. /*
  940. * The PHY should be setup prior to calling this function.
  941. * All we need to do is restart autoneg and enable autoneg.
  942. */
  943. reg |= E1000_PCS_LCTL_AN_RESTART | E1000_PCS_LCTL_AN_ENABLE;
  944. } else {
  945. /* Set PCS register for forced speed */
  946. /* Turn off bits for full duplex, speed, and autoneg */
  947. reg &= ~(E1000_PCS_LCTL_FSV_1000 |
  948. E1000_PCS_LCTL_FSV_100 |
  949. E1000_PCS_LCTL_FDV_FULL |
  950. E1000_PCS_LCTL_AN_ENABLE);
  951. /* Check for duplex first */
  952. if (mac->forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
  953. reg |= E1000_PCS_LCTL_FDV_FULL;
  954. /* Now set speed */
  955. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED)
  956. reg |= E1000_PCS_LCTL_FSV_100;
  957. /* Force speed and force link */
  958. reg |= E1000_PCS_LCTL_FSD |
  959. E1000_PCS_LCTL_FORCE_LINK |
  960. E1000_PCS_LCTL_FLV_LINK_UP;
  961. hw_dbg("Wrote 0x%08X to PCS_LCTL to configure forced link\n",
  962. reg);
  963. }
  964. wr32(E1000_PCS_LCTL, reg);
  965. }
  966. /**
  967. * igb_sgmii_active_82575 - Return sgmii state
  968. * @hw: pointer to the HW structure
  969. *
  970. * 82575 silicon has a serialized gigabit media independent interface (sgmii)
  971. * which can be enabled for use in the embedded applications. Simply
  972. * return the current state of the sgmii interface.
  973. **/
  974. static bool igb_sgmii_active_82575(struct e1000_hw *hw)
  975. {
  976. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  977. return dev_spec->sgmii_active;
  978. }
  979. /**
  980. * igb_reset_init_script_82575 - Inits HW defaults after reset
  981. * @hw: pointer to the HW structure
  982. *
  983. * Inits recommended HW defaults after a reset when there is no EEPROM
  984. * detected. This is only for the 82575.
  985. **/
  986. static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
  987. {
  988. if (hw->mac.type == e1000_82575) {
  989. hw_dbg("Running reset init script for 82575\n");
  990. /* SerDes configuration via SERDESCTRL */
  991. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
  992. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
  993. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
  994. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
  995. /* CCM configuration via CCMCTL register */
  996. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
  997. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
  998. /* PCIe lanes configuration */
  999. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
  1000. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
  1001. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
  1002. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
  1003. /* PCIe PLL Configuration */
  1004. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
  1005. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
  1006. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
  1007. }
  1008. return 0;
  1009. }
  1010. /**
  1011. * igb_read_mac_addr_82575 - Read device MAC address
  1012. * @hw: pointer to the HW structure
  1013. **/
  1014. static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
  1015. {
  1016. s32 ret_val = 0;
  1017. if (igb_check_alt_mac_addr(hw))
  1018. ret_val = igb_read_mac_addr(hw);
  1019. return ret_val;
  1020. }
  1021. /**
  1022. * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
  1023. * @hw: pointer to the HW structure
  1024. *
  1025. * Clears the hardware counters by reading the counter registers.
  1026. **/
  1027. static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
  1028. {
  1029. u32 temp;
  1030. igb_clear_hw_cntrs_base(hw);
  1031. temp = rd32(E1000_PRC64);
  1032. temp = rd32(E1000_PRC127);
  1033. temp = rd32(E1000_PRC255);
  1034. temp = rd32(E1000_PRC511);
  1035. temp = rd32(E1000_PRC1023);
  1036. temp = rd32(E1000_PRC1522);
  1037. temp = rd32(E1000_PTC64);
  1038. temp = rd32(E1000_PTC127);
  1039. temp = rd32(E1000_PTC255);
  1040. temp = rd32(E1000_PTC511);
  1041. temp = rd32(E1000_PTC1023);
  1042. temp = rd32(E1000_PTC1522);
  1043. temp = rd32(E1000_ALGNERRC);
  1044. temp = rd32(E1000_RXERRC);
  1045. temp = rd32(E1000_TNCRS);
  1046. temp = rd32(E1000_CEXTERR);
  1047. temp = rd32(E1000_TSCTC);
  1048. temp = rd32(E1000_TSCTFC);
  1049. temp = rd32(E1000_MGTPRC);
  1050. temp = rd32(E1000_MGTPDC);
  1051. temp = rd32(E1000_MGTPTC);
  1052. temp = rd32(E1000_IAC);
  1053. temp = rd32(E1000_ICRXOC);
  1054. temp = rd32(E1000_ICRXPTC);
  1055. temp = rd32(E1000_ICRXATC);
  1056. temp = rd32(E1000_ICTXPTC);
  1057. temp = rd32(E1000_ICTXATC);
  1058. temp = rd32(E1000_ICTXQEC);
  1059. temp = rd32(E1000_ICTXQMTC);
  1060. temp = rd32(E1000_ICRXDMTC);
  1061. temp = rd32(E1000_CBTMPC);
  1062. temp = rd32(E1000_HTDPMC);
  1063. temp = rd32(E1000_CBRMPC);
  1064. temp = rd32(E1000_RPTHC);
  1065. temp = rd32(E1000_HGPTC);
  1066. temp = rd32(E1000_HTCBDPC);
  1067. temp = rd32(E1000_HGORCL);
  1068. temp = rd32(E1000_HGORCH);
  1069. temp = rd32(E1000_HGOTCL);
  1070. temp = rd32(E1000_HGOTCH);
  1071. temp = rd32(E1000_LENERRS);
  1072. /* This register should not be read in copper configurations */
  1073. if (hw->phy.media_type == e1000_media_type_internal_serdes)
  1074. temp = rd32(E1000_SCVPC);
  1075. }
  1076. /**
  1077. * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
  1078. * @hw: pointer to the HW structure
  1079. *
  1080. * After rx enable if managability is enabled then there is likely some
  1081. * bad data at the start of the fifo and possibly in the DMA fifo. This
  1082. * function clears the fifos and flushes any packets that came in as rx was
  1083. * being enabled.
  1084. **/
  1085. void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
  1086. {
  1087. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  1088. int i, ms_wait;
  1089. if (hw->mac.type != e1000_82575 ||
  1090. !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
  1091. return;
  1092. /* Disable all RX queues */
  1093. for (i = 0; i < 4; i++) {
  1094. rxdctl[i] = rd32(E1000_RXDCTL(i));
  1095. wr32(E1000_RXDCTL(i),
  1096. rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
  1097. }
  1098. /* Poll all queues to verify they have shut down */
  1099. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  1100. msleep(1);
  1101. rx_enabled = 0;
  1102. for (i = 0; i < 4; i++)
  1103. rx_enabled |= rd32(E1000_RXDCTL(i));
  1104. if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
  1105. break;
  1106. }
  1107. if (ms_wait == 10)
  1108. hw_dbg("Queue disable timed out after 10ms\n");
  1109. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  1110. * incoming packets are rejected. Set enable and wait 2ms so that
  1111. * any packet that was coming in as RCTL.EN was set is flushed
  1112. */
  1113. rfctl = rd32(E1000_RFCTL);
  1114. wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
  1115. rlpml = rd32(E1000_RLPML);
  1116. wr32(E1000_RLPML, 0);
  1117. rctl = rd32(E1000_RCTL);
  1118. temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
  1119. temp_rctl |= E1000_RCTL_LPE;
  1120. wr32(E1000_RCTL, temp_rctl);
  1121. wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
  1122. wrfl();
  1123. msleep(2);
  1124. /* Enable RX queues that were previously enabled and restore our
  1125. * previous state
  1126. */
  1127. for (i = 0; i < 4; i++)
  1128. wr32(E1000_RXDCTL(i), rxdctl[i]);
  1129. wr32(E1000_RCTL, rctl);
  1130. wrfl();
  1131. wr32(E1000_RLPML, rlpml);
  1132. wr32(E1000_RFCTL, rfctl);
  1133. /* Flush receive errors generated by workaround */
  1134. rd32(E1000_ROC);
  1135. rd32(E1000_RNBC);
  1136. rd32(E1000_MPC);
  1137. }
  1138. /**
  1139. * igb_set_pcie_completion_timeout - set pci-e completion timeout
  1140. * @hw: pointer to the HW structure
  1141. *
  1142. * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
  1143. * however the hardware default for these parts is 500us to 1ms which is less
  1144. * than the 10ms recommended by the pci-e spec. To address this we need to
  1145. * increase the value to either 10ms to 200ms for capability version 1 config,
  1146. * or 16ms to 55ms for version 2.
  1147. **/
  1148. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
  1149. {
  1150. u32 gcr = rd32(E1000_GCR);
  1151. s32 ret_val = 0;
  1152. u16 pcie_devctl2;
  1153. /* only take action if timeout value is defaulted to 0 */
  1154. if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
  1155. goto out;
  1156. /*
  1157. * if capababilities version is type 1 we can write the
  1158. * timeout of 10ms to 200ms through the GCR register
  1159. */
  1160. if (!(gcr & E1000_GCR_CAP_VER2)) {
  1161. gcr |= E1000_GCR_CMPL_TMOUT_10ms;
  1162. goto out;
  1163. }
  1164. /*
  1165. * for version 2 capabilities we need to write the config space
  1166. * directly in order to set the completion timeout value for
  1167. * 16ms to 55ms
  1168. */
  1169. ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1170. &pcie_devctl2);
  1171. if (ret_val)
  1172. goto out;
  1173. pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
  1174. ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1175. &pcie_devctl2);
  1176. out:
  1177. /* disable completion timeout resend */
  1178. gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
  1179. wr32(E1000_GCR, gcr);
  1180. return ret_val;
  1181. }
  1182. /**
  1183. * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
  1184. * @hw: pointer to the hardware struct
  1185. * @enable: state to enter, either enabled or disabled
  1186. *
  1187. * enables/disables L2 switch loopback functionality.
  1188. **/
  1189. void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
  1190. {
  1191. u32 dtxswc = rd32(E1000_DTXSWC);
  1192. if (enable)
  1193. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1194. else
  1195. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1196. wr32(E1000_DTXSWC, dtxswc);
  1197. }
  1198. /**
  1199. * igb_vmdq_set_replication_pf - enable or disable vmdq replication
  1200. * @hw: pointer to the hardware struct
  1201. * @enable: state to enter, either enabled or disabled
  1202. *
  1203. * enables/disables replication of packets across multiple pools.
  1204. **/
  1205. void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
  1206. {
  1207. u32 vt_ctl = rd32(E1000_VT_CTL);
  1208. if (enable)
  1209. vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
  1210. else
  1211. vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
  1212. wr32(E1000_VT_CTL, vt_ctl);
  1213. }
  1214. static struct e1000_mac_operations e1000_mac_ops_82575 = {
  1215. .reset_hw = igb_reset_hw_82575,
  1216. .init_hw = igb_init_hw_82575,
  1217. .check_for_link = igb_check_for_link_82575,
  1218. .rar_set = igb_rar_set,
  1219. .read_mac_addr = igb_read_mac_addr_82575,
  1220. .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
  1221. };
  1222. static struct e1000_phy_operations e1000_phy_ops_82575 = {
  1223. .acquire = igb_acquire_phy_82575,
  1224. .get_cfg_done = igb_get_cfg_done_82575,
  1225. .release = igb_release_phy_82575,
  1226. };
  1227. static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
  1228. .acquire = igb_acquire_nvm_82575,
  1229. .read = igb_read_nvm_eerd,
  1230. .release = igb_release_nvm_82575,
  1231. .write = igb_write_nvm_spi,
  1232. };
  1233. const struct e1000_info e1000_82575_info = {
  1234. .get_invariants = igb_get_invariants_82575,
  1235. .mac_ops = &e1000_mac_ops_82575,
  1236. .phy_ops = &e1000_phy_ops_82575,
  1237. .nvm_ops = &e1000_nvm_ops_82575,
  1238. };