e1000_82575.c 38 KB

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