e1000_82575.c 41 KB

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