e1000_phy.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007 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. #include <linux/if_ether.h>
  21. #include <linux/delay.h>
  22. #include "e1000_mac.h"
  23. #include "e1000_phy.h"
  24. static s32 igb_get_phy_cfg_done(struct e1000_hw *hw);
  25. static void igb_release_phy(struct e1000_hw *hw);
  26. static s32 igb_acquire_phy(struct e1000_hw *hw);
  27. static s32 igb_phy_reset_dsp(struct e1000_hw *hw);
  28. static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
  29. static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
  30. u16 *phy_ctrl);
  31. static s32 igb_wait_autoneg(struct e1000_hw *hw);
  32. /* Cable length tables */
  33. static const u16 e1000_m88_cable_length_table[] =
  34. { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
  35. #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
  36. (sizeof(e1000_m88_cable_length_table) / \
  37. sizeof(e1000_m88_cable_length_table[0]))
  38. static const u16 e1000_igp_2_cable_length_table[] =
  39. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
  40. 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
  41. 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
  42. 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
  43. 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
  44. 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
  45. 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
  46. 104, 109, 114, 118, 121, 124};
  47. #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
  48. (sizeof(e1000_igp_2_cable_length_table) / \
  49. sizeof(e1000_igp_2_cable_length_table[0]))
  50. /**
  51. * e1000_check_reset_block - Check if PHY reset is blocked
  52. * @hw: pointer to the HW structure
  53. *
  54. * Read the PHY management control register and check whether a PHY reset
  55. * is blocked. If a reset is not blocked return 0, otherwise
  56. * return E1000_BLK_PHY_RESET (12).
  57. **/
  58. s32 igb_check_reset_block(struct e1000_hw *hw)
  59. {
  60. u32 manc;
  61. manc = rd32(E1000_MANC);
  62. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  63. E1000_BLK_PHY_RESET : 0;
  64. }
  65. /**
  66. * e1000_get_phy_id - Retrieve the PHY ID and revision
  67. * @hw: pointer to the HW structure
  68. *
  69. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  70. * revision in the hardware structure.
  71. **/
  72. s32 igb_get_phy_id(struct e1000_hw *hw)
  73. {
  74. struct e1000_phy_info *phy = &hw->phy;
  75. s32 ret_val = 0;
  76. u16 phy_id;
  77. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_ID1, &phy_id);
  78. if (ret_val)
  79. goto out;
  80. phy->id = (u32)(phy_id << 16);
  81. udelay(20);
  82. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_ID2, &phy_id);
  83. if (ret_val)
  84. goto out;
  85. phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
  86. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  87. out:
  88. return ret_val;
  89. }
  90. /**
  91. * e1000_phy_reset_dsp - Reset PHY DSP
  92. * @hw: pointer to the HW structure
  93. *
  94. * Reset the digital signal processor.
  95. **/
  96. static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
  97. {
  98. s32 ret_val;
  99. ret_val = hw->phy.ops.write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
  100. if (ret_val)
  101. goto out;
  102. ret_val = hw->phy.ops.write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
  103. out:
  104. return ret_val;
  105. }
  106. /**
  107. * e1000_read_phy_reg_mdic - Read MDI control register
  108. * @hw: pointer to the HW structure
  109. * @offset: register offset to be read
  110. * @data: pointer to the read data
  111. *
  112. * Reads the MDI control regsiter in the PHY at offset and stores the
  113. * information read to data.
  114. **/
  115. static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
  116. {
  117. struct e1000_phy_info *phy = &hw->phy;
  118. u32 i, mdic = 0;
  119. s32 ret_val = 0;
  120. if (offset > MAX_PHY_REG_ADDRESS) {
  121. hw_dbg(hw, "PHY Address %d is out of range\n", offset);
  122. ret_val = -E1000_ERR_PARAM;
  123. goto out;
  124. }
  125. /*
  126. * Set up Op-code, Phy Address, and register offset in the MDI
  127. * Control register. The MAC will take care of interfacing with the
  128. * PHY to retrieve the desired data.
  129. */
  130. mdic = ((offset << E1000_MDIC_REG_SHIFT) |
  131. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  132. (E1000_MDIC_OP_READ));
  133. wr32(E1000_MDIC, mdic);
  134. /*
  135. * Poll the ready bit to see if the MDI read completed
  136. * Increasing the time out as testing showed failures with
  137. * the lower time out
  138. */
  139. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  140. udelay(50);
  141. mdic = rd32(E1000_MDIC);
  142. if (mdic & E1000_MDIC_READY)
  143. break;
  144. }
  145. if (!(mdic & E1000_MDIC_READY)) {
  146. hw_dbg(hw, "MDI Read did not complete\n");
  147. ret_val = -E1000_ERR_PHY;
  148. goto out;
  149. }
  150. if (mdic & E1000_MDIC_ERROR) {
  151. hw_dbg(hw, "MDI Error\n");
  152. ret_val = -E1000_ERR_PHY;
  153. goto out;
  154. }
  155. *data = (u16) mdic;
  156. out:
  157. return ret_val;
  158. }
  159. /**
  160. * e1000_write_phy_reg_mdic - Write MDI control register
  161. * @hw: pointer to the HW structure
  162. * @offset: register offset to write to
  163. * @data: data to write to register at offset
  164. *
  165. * Writes data to MDI control register in the PHY at offset.
  166. **/
  167. static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
  168. {
  169. struct e1000_phy_info *phy = &hw->phy;
  170. u32 i, mdic = 0;
  171. s32 ret_val = 0;
  172. if (offset > MAX_PHY_REG_ADDRESS) {
  173. hw_dbg(hw, "PHY Address %d is out of range\n", offset);
  174. ret_val = -E1000_ERR_PARAM;
  175. goto out;
  176. }
  177. /*
  178. * Set up Op-code, Phy Address, and register offset in the MDI
  179. * Control register. The MAC will take care of interfacing with the
  180. * PHY to retrieve the desired data.
  181. */
  182. mdic = (((u32)data) |
  183. (offset << E1000_MDIC_REG_SHIFT) |
  184. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  185. (E1000_MDIC_OP_WRITE));
  186. wr32(E1000_MDIC, mdic);
  187. /*
  188. * Poll the ready bit to see if the MDI read completed
  189. * Increasing the time out as testing showed failures with
  190. * the lower time out
  191. */
  192. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  193. udelay(50);
  194. mdic = rd32(E1000_MDIC);
  195. if (mdic & E1000_MDIC_READY)
  196. break;
  197. }
  198. if (!(mdic & E1000_MDIC_READY)) {
  199. hw_dbg(hw, "MDI Write did not complete\n");
  200. ret_val = -E1000_ERR_PHY;
  201. goto out;
  202. }
  203. if (mdic & E1000_MDIC_ERROR) {
  204. hw_dbg(hw, "MDI Error\n");
  205. ret_val = -E1000_ERR_PHY;
  206. goto out;
  207. }
  208. out:
  209. return ret_val;
  210. }
  211. /**
  212. * e1000_read_phy_reg_igp - Read igp PHY register
  213. * @hw: pointer to the HW structure
  214. * @offset: register offset to be read
  215. * @data: pointer to the read data
  216. *
  217. * Acquires semaphore, if necessary, then reads the PHY register at offset
  218. * and storing the retrieved information in data. Release any acquired
  219. * semaphores before exiting.
  220. **/
  221. s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
  222. {
  223. s32 ret_val;
  224. ret_val = igb_acquire_phy(hw);
  225. if (ret_val)
  226. goto out;
  227. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  228. ret_val = igb_write_phy_reg_mdic(hw,
  229. IGP01E1000_PHY_PAGE_SELECT,
  230. (u16)offset);
  231. if (ret_val) {
  232. igb_release_phy(hw);
  233. goto out;
  234. }
  235. }
  236. ret_val = igb_read_phy_reg_mdic(hw,
  237. MAX_PHY_REG_ADDRESS & offset,
  238. data);
  239. igb_release_phy(hw);
  240. out:
  241. return ret_val;
  242. }
  243. /**
  244. * e1000_write_phy_reg_igp - Write igp PHY register
  245. * @hw: pointer to the HW structure
  246. * @offset: register offset to write to
  247. * @data: data to write at register offset
  248. *
  249. * Acquires semaphore, if necessary, then writes the data to PHY register
  250. * at the offset. Release any acquired semaphores before exiting.
  251. **/
  252. s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
  253. {
  254. s32 ret_val;
  255. ret_val = igb_acquire_phy(hw);
  256. if (ret_val)
  257. goto out;
  258. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  259. ret_val = igb_write_phy_reg_mdic(hw,
  260. IGP01E1000_PHY_PAGE_SELECT,
  261. (u16)offset);
  262. if (ret_val) {
  263. igb_release_phy(hw);
  264. goto out;
  265. }
  266. }
  267. ret_val = igb_write_phy_reg_mdic(hw,
  268. MAX_PHY_REG_ADDRESS & offset,
  269. data);
  270. igb_release_phy(hw);
  271. out:
  272. return ret_val;
  273. }
  274. /**
  275. * e1000_copper_link_setup_m88 - Setup m88 PHY's for copper link
  276. * @hw: pointer to the HW structure
  277. *
  278. * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
  279. * and downshift values are set also.
  280. **/
  281. s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
  282. {
  283. struct e1000_phy_info *phy = &hw->phy;
  284. s32 ret_val;
  285. u16 phy_data;
  286. if (phy->reset_disable) {
  287. ret_val = 0;
  288. goto out;
  289. }
  290. /* Enable CRS on TX. This must be set for half-duplex operation. */
  291. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  292. &phy_data);
  293. if (ret_val)
  294. goto out;
  295. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  296. /*
  297. * Options:
  298. * MDI/MDI-X = 0 (default)
  299. * 0 - Auto for all speeds
  300. * 1 - MDI mode
  301. * 2 - MDI-X mode
  302. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  303. */
  304. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  305. switch (phy->mdix) {
  306. case 1:
  307. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  308. break;
  309. case 2:
  310. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  311. break;
  312. case 3:
  313. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  314. break;
  315. case 0:
  316. default:
  317. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  318. break;
  319. }
  320. /*
  321. * Options:
  322. * disable_polarity_correction = 0 (default)
  323. * Automatic Correction for Reversed Cable Polarity
  324. * 0 - Disabled
  325. * 1 - Enabled
  326. */
  327. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  328. if (phy->disable_polarity_correction == 1)
  329. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  330. ret_val = hw->phy.ops.write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  331. phy_data);
  332. if (ret_val)
  333. goto out;
  334. if (phy->revision < E1000_REVISION_4) {
  335. /*
  336. * Force TX_CLK in the Extended PHY Specific Control Register
  337. * to 25MHz clock.
  338. */
  339. ret_val = hw->phy.ops.read_phy_reg(hw,
  340. M88E1000_EXT_PHY_SPEC_CTRL,
  341. &phy_data);
  342. if (ret_val)
  343. goto out;
  344. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  345. if ((phy->revision == E1000_REVISION_2) &&
  346. (phy->id == M88E1111_I_PHY_ID)) {
  347. /* 82573L PHY - set the downshift counter to 5x. */
  348. phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
  349. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  350. } else {
  351. /* Configure Master and Slave downshift values */
  352. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  353. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  354. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  355. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  356. }
  357. ret_val = hw->phy.ops.write_phy_reg(hw,
  358. M88E1000_EXT_PHY_SPEC_CTRL,
  359. phy_data);
  360. if (ret_val)
  361. goto out;
  362. }
  363. /* Commit the changes. */
  364. ret_val = igb_phy_sw_reset(hw);
  365. if (ret_val) {
  366. hw_dbg(hw, "Error committing the PHY changes\n");
  367. goto out;
  368. }
  369. out:
  370. return ret_val;
  371. }
  372. /**
  373. * e1000_copper_link_setup_igp - Setup igp PHY's for copper link
  374. * @hw: pointer to the HW structure
  375. *
  376. * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
  377. * igp PHY's.
  378. **/
  379. s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
  380. {
  381. struct e1000_phy_info *phy = &hw->phy;
  382. s32 ret_val;
  383. u16 data;
  384. if (phy->reset_disable) {
  385. ret_val = 0;
  386. goto out;
  387. }
  388. ret_val = hw->phy.ops.reset_phy(hw);
  389. if (ret_val) {
  390. hw_dbg(hw, "Error resetting the PHY.\n");
  391. goto out;
  392. }
  393. /* Wait 15ms for MAC to configure PHY from NVM settings. */
  394. msleep(15);
  395. /*
  396. * The NVM settings will configure LPLU in D3 for
  397. * non-IGP1 PHYs.
  398. */
  399. if (phy->type == e1000_phy_igp) {
  400. /* disable lplu d3 during driver init */
  401. if (hw->phy.ops.set_d3_lplu_state)
  402. ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
  403. if (ret_val) {
  404. hw_dbg(hw, "Error Disabling LPLU D3\n");
  405. goto out;
  406. }
  407. }
  408. /* disable lplu d0 during driver init */
  409. ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
  410. if (ret_val) {
  411. hw_dbg(hw, "Error Disabling LPLU D0\n");
  412. goto out;
  413. }
  414. /* Configure mdi-mdix settings */
  415. ret_val = hw->phy.ops.read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
  416. if (ret_val)
  417. goto out;
  418. data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  419. switch (phy->mdix) {
  420. case 1:
  421. data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  422. break;
  423. case 2:
  424. data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  425. break;
  426. case 0:
  427. default:
  428. data |= IGP01E1000_PSCR_AUTO_MDIX;
  429. break;
  430. }
  431. ret_val = hw->phy.ops.write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
  432. if (ret_val)
  433. goto out;
  434. /* set auto-master slave resolution settings */
  435. if (hw->mac.autoneg) {
  436. /*
  437. * when autonegotiation advertisement is only 1000Mbps then we
  438. * should disable SmartSpeed and enable Auto MasterSlave
  439. * resolution as hardware default.
  440. */
  441. if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
  442. /* Disable SmartSpeed */
  443. ret_val = hw->phy.ops.read_phy_reg(hw,
  444. IGP01E1000_PHY_PORT_CONFIG,
  445. &data);
  446. if (ret_val)
  447. goto out;
  448. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  449. ret_val = hw->phy.ops.write_phy_reg(hw,
  450. IGP01E1000_PHY_PORT_CONFIG,
  451. data);
  452. if (ret_val)
  453. goto out;
  454. /* Set auto Master/Slave resolution process */
  455. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_1000T_CTRL,
  456. &data);
  457. if (ret_val)
  458. goto out;
  459. data &= ~CR_1000T_MS_ENABLE;
  460. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_1000T_CTRL,
  461. data);
  462. if (ret_val)
  463. goto out;
  464. }
  465. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_1000T_CTRL, &data);
  466. if (ret_val)
  467. goto out;
  468. /* load defaults for future use */
  469. phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
  470. ((data & CR_1000T_MS_VALUE) ?
  471. e1000_ms_force_master :
  472. e1000_ms_force_slave) :
  473. e1000_ms_auto;
  474. switch (phy->ms_type) {
  475. case e1000_ms_force_master:
  476. data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  477. break;
  478. case e1000_ms_force_slave:
  479. data |= CR_1000T_MS_ENABLE;
  480. data &= ~(CR_1000T_MS_VALUE);
  481. break;
  482. case e1000_ms_auto:
  483. data &= ~CR_1000T_MS_ENABLE;
  484. default:
  485. break;
  486. }
  487. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_1000T_CTRL, data);
  488. if (ret_val)
  489. goto out;
  490. }
  491. out:
  492. return ret_val;
  493. }
  494. /**
  495. * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
  496. * @hw: pointer to the HW structure
  497. *
  498. * Performs initial bounds checking on autoneg advertisement parameter, then
  499. * configure to advertise the full capability. Setup the PHY to autoneg
  500. * and restart the negotiation process between the link partner. If
  501. * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
  502. **/
  503. s32 igb_copper_link_autoneg(struct e1000_hw *hw)
  504. {
  505. struct e1000_phy_info *phy = &hw->phy;
  506. s32 ret_val;
  507. u16 phy_ctrl;
  508. /*
  509. * Perform some bounds checking on the autoneg advertisement
  510. * parameter.
  511. */
  512. phy->autoneg_advertised &= phy->autoneg_mask;
  513. /*
  514. * If autoneg_advertised is zero, we assume it was not defaulted
  515. * by the calling code so we set to advertise full capability.
  516. */
  517. if (phy->autoneg_advertised == 0)
  518. phy->autoneg_advertised = phy->autoneg_mask;
  519. hw_dbg(hw, "Reconfiguring auto-neg advertisement params\n");
  520. ret_val = igb_phy_setup_autoneg(hw);
  521. if (ret_val) {
  522. hw_dbg(hw, "Error Setting up Auto-Negotiation\n");
  523. goto out;
  524. }
  525. hw_dbg(hw, "Restarting Auto-Neg\n");
  526. /*
  527. * Restart auto-negotiation by setting the Auto Neg Enable bit and
  528. * the Auto Neg Restart bit in the PHY control register.
  529. */
  530. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_CONTROL, &phy_ctrl);
  531. if (ret_val)
  532. goto out;
  533. phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  534. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_CONTROL, phy_ctrl);
  535. if (ret_val)
  536. goto out;
  537. /*
  538. * Does the user want to wait for Auto-Neg to complete here, or
  539. * check at a later time (for example, callback routine).
  540. */
  541. if (phy->autoneg_wait_to_complete) {
  542. ret_val = igb_wait_autoneg(hw);
  543. if (ret_val) {
  544. hw_dbg(hw, "Error while waiting for "
  545. "autoneg to complete\n");
  546. goto out;
  547. }
  548. }
  549. hw->mac.get_link_status = true;
  550. out:
  551. return ret_val;
  552. }
  553. /**
  554. * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
  555. * @hw: pointer to the HW structure
  556. *
  557. * Reads the MII auto-neg advertisement register and/or the 1000T control
  558. * register and if the PHY is already setup for auto-negotiation, then
  559. * return successful. Otherwise, setup advertisement and flow control to
  560. * the appropriate values for the wanted auto-negotiation.
  561. **/
  562. static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
  563. {
  564. struct e1000_phy_info *phy = &hw->phy;
  565. s32 ret_val;
  566. u16 mii_autoneg_adv_reg;
  567. u16 mii_1000t_ctrl_reg = 0;
  568. phy->autoneg_advertised &= phy->autoneg_mask;
  569. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  570. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_AUTONEG_ADV,
  571. &mii_autoneg_adv_reg);
  572. if (ret_val)
  573. goto out;
  574. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  575. /* Read the MII 1000Base-T Control Register (Address 9). */
  576. ret_val = hw->phy.ops.read_phy_reg(hw,
  577. PHY_1000T_CTRL,
  578. &mii_1000t_ctrl_reg);
  579. if (ret_val)
  580. goto out;
  581. }
  582. /*
  583. * Need to parse both autoneg_advertised and fc and set up
  584. * the appropriate PHY registers. First we will parse for
  585. * autoneg_advertised software override. Since we can advertise
  586. * a plethora of combinations, we need to check each bit
  587. * individually.
  588. */
  589. /*
  590. * First we clear all the 10/100 mb speed bits in the Auto-Neg
  591. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  592. * the 1000Base-T Control Register (Address 9).
  593. */
  594. mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
  595. NWAY_AR_100TX_HD_CAPS |
  596. NWAY_AR_10T_FD_CAPS |
  597. NWAY_AR_10T_HD_CAPS);
  598. mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
  599. hw_dbg(hw, "autoneg_advertised %x\n", phy->autoneg_advertised);
  600. /* Do we want to advertise 10 Mb Half Duplex? */
  601. if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
  602. hw_dbg(hw, "Advertise 10mb Half duplex\n");
  603. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  604. }
  605. /* Do we want to advertise 10 Mb Full Duplex? */
  606. if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
  607. hw_dbg(hw, "Advertise 10mb Full duplex\n");
  608. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  609. }
  610. /* Do we want to advertise 100 Mb Half Duplex? */
  611. if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
  612. hw_dbg(hw, "Advertise 100mb Half duplex\n");
  613. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  614. }
  615. /* Do we want to advertise 100 Mb Full Duplex? */
  616. if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
  617. hw_dbg(hw, "Advertise 100mb Full duplex\n");
  618. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  619. }
  620. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  621. if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
  622. hw_dbg(hw, "Advertise 1000mb Half duplex request denied!\n");
  623. /* Do we want to advertise 1000 Mb Full Duplex? */
  624. if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
  625. hw_dbg(hw, "Advertise 1000mb Full duplex\n");
  626. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  627. }
  628. /*
  629. * Check for a software override of the flow control settings, and
  630. * setup the PHY advertisement registers accordingly. If
  631. * auto-negotiation is enabled, then software will have to set the
  632. * "PAUSE" bits to the correct value in the Auto-Negotiation
  633. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
  634. * negotiation.
  635. *
  636. * The possible values of the "fc" parameter are:
  637. * 0: Flow control is completely disabled
  638. * 1: Rx flow control is enabled (we can receive pause frames
  639. * but not send pause frames).
  640. * 2: Tx flow control is enabled (we can send pause frames
  641. * but we do not support receiving pause frames).
  642. * 3: Both Rx and TX flow control (symmetric) are enabled.
  643. * other: No software override. The flow control configuration
  644. * in the EEPROM is used.
  645. */
  646. switch (hw->fc.type) {
  647. case e1000_fc_none:
  648. /*
  649. * Flow control (RX & TX) is completely disabled by a
  650. * software over-ride.
  651. */
  652. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  653. break;
  654. case e1000_fc_rx_pause:
  655. /*
  656. * RX Flow control is enabled, and TX Flow control is
  657. * disabled, by a software over-ride.
  658. *
  659. * Since there really isn't a way to advertise that we are
  660. * capable of RX Pause ONLY, we will advertise that we
  661. * support both symmetric and asymmetric RX PAUSE. Later
  662. * (in e1000_config_fc_after_link_up) we will disable the
  663. * hw's ability to send PAUSE frames.
  664. */
  665. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  666. break;
  667. case e1000_fc_tx_pause:
  668. /*
  669. * TX Flow control is enabled, and RX Flow control is
  670. * disabled, by a software over-ride.
  671. */
  672. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  673. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  674. break;
  675. case e1000_fc_full:
  676. /*
  677. * Flow control (both RX and TX) is enabled by a software
  678. * over-ride.
  679. */
  680. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  681. break;
  682. default:
  683. hw_dbg(hw, "Flow control param set incorrectly\n");
  684. ret_val = -E1000_ERR_CONFIG;
  685. goto out;
  686. }
  687. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_AUTONEG_ADV,
  688. mii_autoneg_adv_reg);
  689. if (ret_val)
  690. goto out;
  691. hw_dbg(hw, "Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  692. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  693. ret_val = hw->phy.ops.write_phy_reg(hw,
  694. PHY_1000T_CTRL,
  695. mii_1000t_ctrl_reg);
  696. if (ret_val)
  697. goto out;
  698. }
  699. out:
  700. return ret_val;
  701. }
  702. /**
  703. * e1000_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
  704. * @hw: pointer to the HW structure
  705. *
  706. * Calls the PHY setup function to force speed and duplex. Clears the
  707. * auto-crossover to force MDI manually. Waits for link and returns
  708. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  709. **/
  710. s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
  711. {
  712. struct e1000_phy_info *phy = &hw->phy;
  713. s32 ret_val;
  714. u16 phy_data;
  715. bool link;
  716. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_CONTROL, &phy_data);
  717. if (ret_val)
  718. goto out;
  719. igb_phy_force_speed_duplex_setup(hw, &phy_data);
  720. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_CONTROL, phy_data);
  721. if (ret_val)
  722. goto out;
  723. /*
  724. * Clear Auto-Crossover to force MDI manually. IGP requires MDI
  725. * forced whenever speed and duplex are forced.
  726. */
  727. ret_val = hw->phy.ops.read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
  728. &phy_data);
  729. if (ret_val)
  730. goto out;
  731. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  732. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  733. ret_val = hw->phy.ops.write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
  734. phy_data);
  735. if (ret_val)
  736. goto out;
  737. hw_dbg(hw, "IGP PSCR: %X\n", phy_data);
  738. udelay(1);
  739. if (phy->autoneg_wait_to_complete) {
  740. hw_dbg(hw,
  741. "Waiting for forced speed/duplex link on IGP phy.\n");
  742. ret_val = igb_phy_has_link(hw,
  743. PHY_FORCE_LIMIT,
  744. 100000,
  745. &link);
  746. if (ret_val)
  747. goto out;
  748. if (!link)
  749. hw_dbg(hw, "Link taking longer than expected.\n");
  750. /* Try once more */
  751. ret_val = igb_phy_has_link(hw,
  752. PHY_FORCE_LIMIT,
  753. 100000,
  754. &link);
  755. if (ret_val)
  756. goto out;
  757. }
  758. out:
  759. return ret_val;
  760. }
  761. /**
  762. * e1000_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
  763. * @hw: pointer to the HW structure
  764. *
  765. * Calls the PHY setup function to force speed and duplex. Clears the
  766. * auto-crossover to force MDI manually. Resets the PHY to commit the
  767. * changes. If time expires while waiting for link up, we reset the DSP.
  768. * After reset, TX_CLK and CRS on TX must be set. Return successful upon
  769. * successful completion, else return corresponding error code.
  770. **/
  771. s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
  772. {
  773. struct e1000_phy_info *phy = &hw->phy;
  774. s32 ret_val;
  775. u16 phy_data;
  776. bool link;
  777. /*
  778. * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  779. * forced whenever speed and duplex are forced.
  780. */
  781. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  782. &phy_data);
  783. if (ret_val)
  784. goto out;
  785. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  786. ret_val = hw->phy.ops.write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  787. phy_data);
  788. if (ret_val)
  789. goto out;
  790. hw_dbg(hw, "M88E1000 PSCR: %X\n", phy_data);
  791. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_CONTROL, &phy_data);
  792. if (ret_val)
  793. goto out;
  794. igb_phy_force_speed_duplex_setup(hw, &phy_data);
  795. /* Reset the phy to commit changes. */
  796. phy_data |= MII_CR_RESET;
  797. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_CONTROL, phy_data);
  798. if (ret_val)
  799. goto out;
  800. udelay(1);
  801. if (phy->autoneg_wait_to_complete) {
  802. hw_dbg(hw,
  803. "Waiting for forced speed/duplex link on M88 phy.\n");
  804. ret_val = igb_phy_has_link(hw,
  805. PHY_FORCE_LIMIT,
  806. 100000,
  807. &link);
  808. if (ret_val)
  809. goto out;
  810. if (!link) {
  811. /*
  812. * We didn't get link.
  813. * Reset the DSP and cross our fingers.
  814. */
  815. ret_val = hw->phy.ops.write_phy_reg(hw,
  816. M88E1000_PHY_PAGE_SELECT,
  817. 0x001d);
  818. if (ret_val)
  819. goto out;
  820. ret_val = igb_phy_reset_dsp(hw);
  821. if (ret_val)
  822. goto out;
  823. }
  824. /* Try once more */
  825. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
  826. 100000, &link);
  827. if (ret_val)
  828. goto out;
  829. }
  830. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  831. &phy_data);
  832. if (ret_val)
  833. goto out;
  834. /*
  835. * Resetting the phy means we need to re-force TX_CLK in the
  836. * Extended PHY Specific Control Register to 25MHz clock from
  837. * the reset value of 2.5MHz.
  838. */
  839. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  840. ret_val = hw->phy.ops.write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  841. phy_data);
  842. if (ret_val)
  843. goto out;
  844. /*
  845. * In addition, we must re-enable CRS on Tx for both half and full
  846. * duplex.
  847. */
  848. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  849. &phy_data);
  850. if (ret_val)
  851. goto out;
  852. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  853. ret_val = hw->phy.ops.write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  854. phy_data);
  855. out:
  856. return ret_val;
  857. }
  858. /**
  859. * e1000_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
  860. * @hw: pointer to the HW structure
  861. * @phy_ctrl: pointer to current value of PHY_CONTROL
  862. *
  863. * Forces speed and duplex on the PHY by doing the following: disable flow
  864. * control, force speed/duplex on the MAC, disable auto speed detection,
  865. * disable auto-negotiation, configure duplex, configure speed, configure
  866. * the collision distance, write configuration to CTRL register. The
  867. * caller must write to the PHY_CONTROL register for these settings to
  868. * take affect.
  869. **/
  870. static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
  871. u16 *phy_ctrl)
  872. {
  873. struct e1000_mac_info *mac = &hw->mac;
  874. u32 ctrl;
  875. /* Turn off flow control when forcing speed/duplex */
  876. hw->fc.type = e1000_fc_none;
  877. /* Force speed/duplex on the mac */
  878. ctrl = rd32(E1000_CTRL);
  879. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  880. ctrl &= ~E1000_CTRL_SPD_SEL;
  881. /* Disable Auto Speed Detection */
  882. ctrl &= ~E1000_CTRL_ASDE;
  883. /* Disable autoneg on the phy */
  884. *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
  885. /* Forcing Full or Half Duplex? */
  886. if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
  887. ctrl &= ~E1000_CTRL_FD;
  888. *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
  889. hw_dbg(hw, "Half Duplex\n");
  890. } else {
  891. ctrl |= E1000_CTRL_FD;
  892. *phy_ctrl |= MII_CR_FULL_DUPLEX;
  893. hw_dbg(hw, "Full Duplex\n");
  894. }
  895. /* Forcing 10mb or 100mb? */
  896. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
  897. ctrl |= E1000_CTRL_SPD_100;
  898. *phy_ctrl |= MII_CR_SPEED_100;
  899. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  900. hw_dbg(hw, "Forcing 100mb\n");
  901. } else {
  902. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  903. *phy_ctrl |= MII_CR_SPEED_10;
  904. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  905. hw_dbg(hw, "Forcing 10mb\n");
  906. }
  907. igb_config_collision_dist(hw);
  908. wr32(E1000_CTRL, ctrl);
  909. }
  910. /**
  911. * e1000_set_d3_lplu_state - Sets low power link up state for D3
  912. * @hw: pointer to the HW structure
  913. * @active: boolean used to enable/disable lplu
  914. *
  915. * Success returns 0, Failure returns 1
  916. *
  917. * The low power link up (lplu) state is set to the power management level D3
  918. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  919. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  920. * is used during Dx states where the power conservation is most important.
  921. * During driver activity, SmartSpeed should be enabled so performance is
  922. * maintained.
  923. **/
  924. s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  925. {
  926. struct e1000_phy_info *phy = &hw->phy;
  927. s32 ret_val;
  928. u16 data;
  929. ret_val = hw->phy.ops.read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  930. &data);
  931. if (ret_val)
  932. goto out;
  933. if (!active) {
  934. data &= ~IGP02E1000_PM_D3_LPLU;
  935. ret_val = hw->phy.ops.write_phy_reg(hw,
  936. IGP02E1000_PHY_POWER_MGMT,
  937. data);
  938. if (ret_val)
  939. goto out;
  940. /*
  941. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  942. * during Dx states where the power conservation is most
  943. * important. During driver activity we should enable
  944. * SmartSpeed, so performance is maintained.
  945. */
  946. if (phy->smart_speed == e1000_smart_speed_on) {
  947. ret_val = hw->phy.ops.read_phy_reg(hw,
  948. IGP01E1000_PHY_PORT_CONFIG,
  949. &data);
  950. if (ret_val)
  951. goto out;
  952. data |= IGP01E1000_PSCFR_SMART_SPEED;
  953. ret_val = hw->phy.ops.write_phy_reg(hw,
  954. IGP01E1000_PHY_PORT_CONFIG,
  955. data);
  956. if (ret_val)
  957. goto out;
  958. } else if (phy->smart_speed == e1000_smart_speed_off) {
  959. ret_val = hw->phy.ops.read_phy_reg(hw,
  960. IGP01E1000_PHY_PORT_CONFIG,
  961. &data);
  962. if (ret_val)
  963. goto out;
  964. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  965. ret_val = hw->phy.ops.write_phy_reg(hw,
  966. IGP01E1000_PHY_PORT_CONFIG,
  967. data);
  968. if (ret_val)
  969. goto out;
  970. }
  971. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  972. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  973. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  974. data |= IGP02E1000_PM_D3_LPLU;
  975. ret_val = hw->phy.ops.write_phy_reg(hw,
  976. IGP02E1000_PHY_POWER_MGMT,
  977. data);
  978. if (ret_val)
  979. goto out;
  980. /* When LPLU is enabled, we should disable SmartSpeed */
  981. ret_val = hw->phy.ops.read_phy_reg(hw,
  982. IGP01E1000_PHY_PORT_CONFIG,
  983. &data);
  984. if (ret_val)
  985. goto out;
  986. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  987. ret_val = hw->phy.ops.write_phy_reg(hw,
  988. IGP01E1000_PHY_PORT_CONFIG,
  989. data);
  990. }
  991. out:
  992. return ret_val;
  993. }
  994. /**
  995. * e1000_check_downshift - Checks whether a downshift in speed occured
  996. * @hw: pointer to the HW structure
  997. *
  998. * Success returns 0, Failure returns 1
  999. *
  1000. * A downshift is detected by querying the PHY link health.
  1001. **/
  1002. s32 igb_check_downshift(struct e1000_hw *hw)
  1003. {
  1004. struct e1000_phy_info *phy = &hw->phy;
  1005. s32 ret_val;
  1006. u16 phy_data, offset, mask;
  1007. switch (phy->type) {
  1008. case e1000_phy_m88:
  1009. case e1000_phy_gg82563:
  1010. offset = M88E1000_PHY_SPEC_STATUS;
  1011. mask = M88E1000_PSSR_DOWNSHIFT;
  1012. break;
  1013. case e1000_phy_igp_2:
  1014. case e1000_phy_igp:
  1015. case e1000_phy_igp_3:
  1016. offset = IGP01E1000_PHY_LINK_HEALTH;
  1017. mask = IGP01E1000_PLHR_SS_DOWNGRADE;
  1018. break;
  1019. default:
  1020. /* speed downshift not supported */
  1021. phy->speed_downgraded = false;
  1022. ret_val = 0;
  1023. goto out;
  1024. }
  1025. ret_val = hw->phy.ops.read_phy_reg(hw, offset, &phy_data);
  1026. if (!ret_val)
  1027. phy->speed_downgraded = (phy_data & mask) ? true : false;
  1028. out:
  1029. return ret_val;
  1030. }
  1031. /**
  1032. * e1000_check_polarity_m88 - Checks the polarity.
  1033. * @hw: pointer to the HW structure
  1034. *
  1035. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1036. *
  1037. * Polarity is determined based on the PHY specific status register.
  1038. **/
  1039. static s32 igb_check_polarity_m88(struct e1000_hw *hw)
  1040. {
  1041. struct e1000_phy_info *phy = &hw->phy;
  1042. s32 ret_val;
  1043. u16 data;
  1044. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
  1045. if (!ret_val)
  1046. phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
  1047. ? e1000_rev_polarity_reversed
  1048. : e1000_rev_polarity_normal;
  1049. return ret_val;
  1050. }
  1051. /**
  1052. * e1000_check_polarity_igp - Checks the polarity.
  1053. * @hw: pointer to the HW structure
  1054. *
  1055. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1056. *
  1057. * Polarity is determined based on the PHY port status register, and the
  1058. * current speed (since there is no polarity at 100Mbps).
  1059. **/
  1060. static s32 igb_check_polarity_igp(struct e1000_hw *hw)
  1061. {
  1062. struct e1000_phy_info *phy = &hw->phy;
  1063. s32 ret_val;
  1064. u16 data, offset, mask;
  1065. /*
  1066. * Polarity is determined based on the speed of
  1067. * our connection.
  1068. */
  1069. ret_val = hw->phy.ops.read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  1070. &data);
  1071. if (ret_val)
  1072. goto out;
  1073. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1074. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1075. offset = IGP01E1000_PHY_PCS_INIT_REG;
  1076. mask = IGP01E1000_PHY_POLARITY_MASK;
  1077. } else {
  1078. /*
  1079. * This really only applies to 10Mbps since
  1080. * there is no polarity for 100Mbps (always 0).
  1081. */
  1082. offset = IGP01E1000_PHY_PORT_STATUS;
  1083. mask = IGP01E1000_PSSR_POLARITY_REVERSED;
  1084. }
  1085. ret_val = hw->phy.ops.read_phy_reg(hw, offset, &data);
  1086. if (!ret_val)
  1087. phy->cable_polarity = (data & mask)
  1088. ? e1000_rev_polarity_reversed
  1089. : e1000_rev_polarity_normal;
  1090. out:
  1091. return ret_val;
  1092. }
  1093. /**
  1094. * e1000_wait_autoneg - Wait for auto-neg compeletion
  1095. * @hw: pointer to the HW structure
  1096. *
  1097. * Waits for auto-negotiation to complete or for the auto-negotiation time
  1098. * limit to expire, which ever happens first.
  1099. **/
  1100. static s32 igb_wait_autoneg(struct e1000_hw *hw)
  1101. {
  1102. s32 ret_val = 0;
  1103. u16 i, phy_status;
  1104. /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
  1105. for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
  1106. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS, &phy_status);
  1107. if (ret_val)
  1108. break;
  1109. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS, &phy_status);
  1110. if (ret_val)
  1111. break;
  1112. if (phy_status & MII_SR_AUTONEG_COMPLETE)
  1113. break;
  1114. msleep(100);
  1115. }
  1116. /*
  1117. * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
  1118. * has completed.
  1119. */
  1120. return ret_val;
  1121. }
  1122. /**
  1123. * e1000_phy_has_link - Polls PHY for link
  1124. * @hw: pointer to the HW structure
  1125. * @iterations: number of times to poll for link
  1126. * @usec_interval: delay between polling attempts
  1127. * @success: pointer to whether polling was successful or not
  1128. *
  1129. * Polls the PHY status register for link, 'iterations' number of times.
  1130. **/
  1131. s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
  1132. u32 usec_interval, bool *success)
  1133. {
  1134. s32 ret_val = 0;
  1135. u16 i, phy_status;
  1136. for (i = 0; i < iterations; i++) {
  1137. /*
  1138. * Some PHYs require the PHY_STATUS register to be read
  1139. * twice due to the link bit being sticky. No harm doing
  1140. * it across the board.
  1141. */
  1142. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS, &phy_status);
  1143. if (ret_val)
  1144. break;
  1145. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS, &phy_status);
  1146. if (ret_val)
  1147. break;
  1148. if (phy_status & MII_SR_LINK_STATUS)
  1149. break;
  1150. if (usec_interval >= 1000)
  1151. mdelay(usec_interval/1000);
  1152. else
  1153. udelay(usec_interval);
  1154. }
  1155. *success = (i < iterations) ? true : false;
  1156. return ret_val;
  1157. }
  1158. /**
  1159. * e1000_get_cable_length_m88 - Determine cable length for m88 PHY
  1160. * @hw: pointer to the HW structure
  1161. *
  1162. * Reads the PHY specific status register to retrieve the cable length
  1163. * information. The cable length is determined by averaging the minimum and
  1164. * maximum values to get the "average" cable length. The m88 PHY has four
  1165. * possible cable length values, which are:
  1166. * Register Value Cable Length
  1167. * 0 < 50 meters
  1168. * 1 50 - 80 meters
  1169. * 2 80 - 110 meters
  1170. * 3 110 - 140 meters
  1171. * 4 > 140 meters
  1172. **/
  1173. s32 igb_get_cable_length_m88(struct e1000_hw *hw)
  1174. {
  1175. struct e1000_phy_info *phy = &hw->phy;
  1176. s32 ret_val;
  1177. u16 phy_data, index;
  1178. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  1179. &phy_data);
  1180. if (ret_val)
  1181. goto out;
  1182. index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1183. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  1184. phy->min_cable_length = e1000_m88_cable_length_table[index];
  1185. phy->max_cable_length = e1000_m88_cable_length_table[index+1];
  1186. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1187. out:
  1188. return ret_val;
  1189. }
  1190. /**
  1191. * e1000_get_cable_length_igp_2 - Determine cable length for igp2 PHY
  1192. * @hw: pointer to the HW structure
  1193. *
  1194. * The automatic gain control (agc) normalizes the amplitude of the
  1195. * received signal, adjusting for the attenuation produced by the
  1196. * cable. By reading the AGC registers, which reperesent the
  1197. * cobination of course and fine gain value, the value can be put
  1198. * into a lookup table to obtain the approximate cable length
  1199. * for each channel.
  1200. **/
  1201. s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
  1202. {
  1203. struct e1000_phy_info *phy = &hw->phy;
  1204. s32 ret_val = 0;
  1205. u16 phy_data, i, agc_value = 0;
  1206. u16 cur_agc_index, max_agc_index = 0;
  1207. u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
  1208. u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
  1209. {IGP02E1000_PHY_AGC_A,
  1210. IGP02E1000_PHY_AGC_B,
  1211. IGP02E1000_PHY_AGC_C,
  1212. IGP02E1000_PHY_AGC_D};
  1213. /* Read the AGC registers for all channels */
  1214. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  1215. ret_val = hw->phy.ops.read_phy_reg(hw, agc_reg_array[i],
  1216. &phy_data);
  1217. if (ret_val)
  1218. goto out;
  1219. /*
  1220. * Getting bits 15:9, which represent the combination of
  1221. * course and fine gain values. The result is a number
  1222. * that can be put into the lookup table to obtain the
  1223. * approximate cable length.
  1224. */
  1225. cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  1226. IGP02E1000_AGC_LENGTH_MASK;
  1227. /* Array index bound check. */
  1228. if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
  1229. (cur_agc_index == 0)) {
  1230. ret_val = -E1000_ERR_PHY;
  1231. goto out;
  1232. }
  1233. /* Remove min & max AGC values from calculation. */
  1234. if (e1000_igp_2_cable_length_table[min_agc_index] >
  1235. e1000_igp_2_cable_length_table[cur_agc_index])
  1236. min_agc_index = cur_agc_index;
  1237. if (e1000_igp_2_cable_length_table[max_agc_index] <
  1238. e1000_igp_2_cable_length_table[cur_agc_index])
  1239. max_agc_index = cur_agc_index;
  1240. agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
  1241. }
  1242. agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
  1243. e1000_igp_2_cable_length_table[max_agc_index]);
  1244. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  1245. /* Calculate cable length with the error range of +/- 10 meters. */
  1246. phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  1247. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  1248. phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
  1249. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1250. out:
  1251. return ret_val;
  1252. }
  1253. /**
  1254. * e1000_get_phy_info_m88 - Retrieve PHY information
  1255. * @hw: pointer to the HW structure
  1256. *
  1257. * Valid for only copper links. Read the PHY status register (sticky read)
  1258. * to verify that link is up. Read the PHY special control register to
  1259. * determine the polarity and 10base-T extended distance. Read the PHY
  1260. * special status register to determine MDI/MDIx and current speed. If
  1261. * speed is 1000, then determine cable length, local and remote receiver.
  1262. **/
  1263. s32 igb_get_phy_info_m88(struct e1000_hw *hw)
  1264. {
  1265. struct e1000_phy_info *phy = &hw->phy;
  1266. s32 ret_val;
  1267. u16 phy_data;
  1268. bool link;
  1269. if (hw->phy.media_type != e1000_media_type_copper) {
  1270. hw_dbg(hw, "Phy info is only valid for copper media\n");
  1271. ret_val = -E1000_ERR_CONFIG;
  1272. goto out;
  1273. }
  1274. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  1275. if (ret_val)
  1276. goto out;
  1277. if (!link) {
  1278. hw_dbg(hw, "Phy info is only valid if link is up\n");
  1279. ret_val = -E1000_ERR_CONFIG;
  1280. goto out;
  1281. }
  1282. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1283. &phy_data);
  1284. if (ret_val)
  1285. goto out;
  1286. phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
  1287. ? true
  1288. : false;
  1289. ret_val = igb_check_polarity_m88(hw);
  1290. if (ret_val)
  1291. goto out;
  1292. ret_val = hw->phy.ops.read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  1293. &phy_data);
  1294. if (ret_val)
  1295. goto out;
  1296. phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
  1297. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  1298. ret_val = hw->phy.ops.get_cable_length(hw);
  1299. if (ret_val)
  1300. goto out;
  1301. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_1000T_STATUS,
  1302. &phy_data);
  1303. if (ret_val)
  1304. goto out;
  1305. phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
  1306. ? e1000_1000t_rx_status_ok
  1307. : e1000_1000t_rx_status_not_ok;
  1308. phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
  1309. ? e1000_1000t_rx_status_ok
  1310. : e1000_1000t_rx_status_not_ok;
  1311. } else {
  1312. /* Set values to "undefined" */
  1313. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1314. phy->local_rx = e1000_1000t_rx_status_undefined;
  1315. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1316. }
  1317. out:
  1318. return ret_val;
  1319. }
  1320. /**
  1321. * e1000_get_phy_info_igp - Retrieve igp PHY information
  1322. * @hw: pointer to the HW structure
  1323. *
  1324. * Read PHY status to determine if link is up. If link is up, then
  1325. * set/determine 10base-T extended distance and polarity correction. Read
  1326. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  1327. * determine on the cable length, local and remote receiver.
  1328. **/
  1329. s32 igb_get_phy_info_igp(struct e1000_hw *hw)
  1330. {
  1331. struct e1000_phy_info *phy = &hw->phy;
  1332. s32 ret_val;
  1333. u16 data;
  1334. bool link;
  1335. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  1336. if (ret_val)
  1337. goto out;
  1338. if (!link) {
  1339. hw_dbg(hw, "Phy info is only valid if link is up\n");
  1340. ret_val = -E1000_ERR_CONFIG;
  1341. goto out;
  1342. }
  1343. phy->polarity_correction = true;
  1344. ret_val = igb_check_polarity_igp(hw);
  1345. if (ret_val)
  1346. goto out;
  1347. ret_val = hw->phy.ops.read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  1348. &data);
  1349. if (ret_val)
  1350. goto out;
  1351. phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
  1352. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1353. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1354. ret_val = hw->phy.ops.get_cable_length(hw);
  1355. if (ret_val)
  1356. goto out;
  1357. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_1000T_STATUS,
  1358. &data);
  1359. if (ret_val)
  1360. goto out;
  1361. phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
  1362. ? e1000_1000t_rx_status_ok
  1363. : e1000_1000t_rx_status_not_ok;
  1364. phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
  1365. ? e1000_1000t_rx_status_ok
  1366. : e1000_1000t_rx_status_not_ok;
  1367. } else {
  1368. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1369. phy->local_rx = e1000_1000t_rx_status_undefined;
  1370. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1371. }
  1372. out:
  1373. return ret_val;
  1374. }
  1375. /**
  1376. * e1000_phy_sw_reset - PHY software reset
  1377. * @hw: pointer to the HW structure
  1378. *
  1379. * Does a software reset of the PHY by reading the PHY control register and
  1380. * setting/write the control register reset bit to the PHY.
  1381. **/
  1382. s32 igb_phy_sw_reset(struct e1000_hw *hw)
  1383. {
  1384. s32 ret_val;
  1385. u16 phy_ctrl;
  1386. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_CONTROL, &phy_ctrl);
  1387. if (ret_val)
  1388. goto out;
  1389. phy_ctrl |= MII_CR_RESET;
  1390. ret_val = hw->phy.ops.write_phy_reg(hw, PHY_CONTROL, phy_ctrl);
  1391. if (ret_val)
  1392. goto out;
  1393. udelay(1);
  1394. out:
  1395. return ret_val;
  1396. }
  1397. /**
  1398. * e1000_phy_hw_reset - PHY hardware reset
  1399. * @hw: pointer to the HW structure
  1400. *
  1401. * Verify the reset block is not blocking us from resetting. Acquire
  1402. * semaphore (if necessary) and read/set/write the device control reset
  1403. * bit in the PHY. Wait the appropriate delay time for the device to
  1404. * reset and relase the semaphore (if necessary).
  1405. **/
  1406. s32 igb_phy_hw_reset(struct e1000_hw *hw)
  1407. {
  1408. struct e1000_phy_info *phy = &hw->phy;
  1409. s32 ret_val;
  1410. u32 ctrl;
  1411. ret_val = igb_check_reset_block(hw);
  1412. if (ret_val) {
  1413. ret_val = 0;
  1414. goto out;
  1415. }
  1416. ret_val = igb_acquire_phy(hw);
  1417. if (ret_val)
  1418. goto out;
  1419. ctrl = rd32(E1000_CTRL);
  1420. wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
  1421. wrfl();
  1422. udelay(phy->reset_delay_us);
  1423. wr32(E1000_CTRL, ctrl);
  1424. wrfl();
  1425. udelay(150);
  1426. igb_release_phy(hw);
  1427. ret_val = igb_get_phy_cfg_done(hw);
  1428. out:
  1429. return ret_val;
  1430. }
  1431. /* Internal function pointers */
  1432. /**
  1433. * e1000_get_phy_cfg_done - Generic PHY configuration done
  1434. * @hw: pointer to the HW structure
  1435. *
  1436. * Return success if silicon family did not implement a family specific
  1437. * get_cfg_done function.
  1438. **/
  1439. static s32 igb_get_phy_cfg_done(struct e1000_hw *hw)
  1440. {
  1441. if (hw->phy.ops.get_cfg_done)
  1442. return hw->phy.ops.get_cfg_done(hw);
  1443. return 0;
  1444. }
  1445. /**
  1446. * e1000_release_phy - Generic release PHY
  1447. * @hw: pointer to the HW structure
  1448. *
  1449. * Return if silicon family does not require a semaphore when accessing the
  1450. * PHY.
  1451. **/
  1452. static void igb_release_phy(struct e1000_hw *hw)
  1453. {
  1454. if (hw->phy.ops.release_phy)
  1455. hw->phy.ops.release_phy(hw);
  1456. }
  1457. /**
  1458. * e1000_acquire_phy - Generic acquire PHY
  1459. * @hw: pointer to the HW structure
  1460. *
  1461. * Return success if silicon family does not require a semaphore when
  1462. * accessing the PHY.
  1463. **/
  1464. static s32 igb_acquire_phy(struct e1000_hw *hw)
  1465. {
  1466. if (hw->phy.ops.acquire_phy)
  1467. return hw->phy.ops.acquire_phy(hw);
  1468. return 0;
  1469. }
  1470. /**
  1471. * e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
  1472. * @hw: pointer to the HW structure
  1473. *
  1474. * When the silicon family has not implemented a forced speed/duplex
  1475. * function for the PHY, simply return 0.
  1476. **/
  1477. s32 igb_phy_force_speed_duplex(struct e1000_hw *hw)
  1478. {
  1479. if (hw->phy.ops.force_speed_duplex)
  1480. return hw->phy.ops.force_speed_duplex(hw);
  1481. return 0;
  1482. }
  1483. /**
  1484. * e1000_phy_init_script_igp3 - Inits the IGP3 PHY
  1485. * @hw: pointer to the HW structure
  1486. *
  1487. * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
  1488. **/
  1489. s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
  1490. {
  1491. hw_dbg(hw, "Running IGP 3 PHY init script\n");
  1492. /* PHY init IGP 3 */
  1493. /* Enable rise/fall, 10-mode work in class-A */
  1494. hw->phy.ops.write_phy_reg(hw, 0x2F5B, 0x9018);
  1495. /* Remove all caps from Replica path filter */
  1496. hw->phy.ops.write_phy_reg(hw, 0x2F52, 0x0000);
  1497. /* Bias trimming for ADC, AFE and Driver (Default) */
  1498. hw->phy.ops.write_phy_reg(hw, 0x2FB1, 0x8B24);
  1499. /* Increase Hybrid poly bias */
  1500. hw->phy.ops.write_phy_reg(hw, 0x2FB2, 0xF8F0);
  1501. /* Add 4% to TX amplitude in Giga mode */
  1502. hw->phy.ops.write_phy_reg(hw, 0x2010, 0x10B0);
  1503. /* Disable trimming (TTT) */
  1504. hw->phy.ops.write_phy_reg(hw, 0x2011, 0x0000);
  1505. /* Poly DC correction to 94.6% + 2% for all channels */
  1506. hw->phy.ops.write_phy_reg(hw, 0x20DD, 0x249A);
  1507. /* ABS DC correction to 95.9% */
  1508. hw->phy.ops.write_phy_reg(hw, 0x20DE, 0x00D3);
  1509. /* BG temp curve trim */
  1510. hw->phy.ops.write_phy_reg(hw, 0x28B4, 0x04CE);
  1511. /* Increasing ADC OPAMP stage 1 currents to max */
  1512. hw->phy.ops.write_phy_reg(hw, 0x2F70, 0x29E4);
  1513. /* Force 1000 ( required for enabling PHY regs configuration) */
  1514. hw->phy.ops.write_phy_reg(hw, 0x0000, 0x0140);
  1515. /* Set upd_freq to 6 */
  1516. hw->phy.ops.write_phy_reg(hw, 0x1F30, 0x1606);
  1517. /* Disable NPDFE */
  1518. hw->phy.ops.write_phy_reg(hw, 0x1F31, 0xB814);
  1519. /* Disable adaptive fixed FFE (Default) */
  1520. hw->phy.ops.write_phy_reg(hw, 0x1F35, 0x002A);
  1521. /* Enable FFE hysteresis */
  1522. hw->phy.ops.write_phy_reg(hw, 0x1F3E, 0x0067);
  1523. /* Fixed FFE for short cable lengths */
  1524. hw->phy.ops.write_phy_reg(hw, 0x1F54, 0x0065);
  1525. /* Fixed FFE for medium cable lengths */
  1526. hw->phy.ops.write_phy_reg(hw, 0x1F55, 0x002A);
  1527. /* Fixed FFE for long cable lengths */
  1528. hw->phy.ops.write_phy_reg(hw, 0x1F56, 0x002A);
  1529. /* Enable Adaptive Clip Threshold */
  1530. hw->phy.ops.write_phy_reg(hw, 0x1F72, 0x3FB0);
  1531. /* AHT reset limit to 1 */
  1532. hw->phy.ops.write_phy_reg(hw, 0x1F76, 0xC0FF);
  1533. /* Set AHT master delay to 127 msec */
  1534. hw->phy.ops.write_phy_reg(hw, 0x1F77, 0x1DEC);
  1535. /* Set scan bits for AHT */
  1536. hw->phy.ops.write_phy_reg(hw, 0x1F78, 0xF9EF);
  1537. /* Set AHT Preset bits */
  1538. hw->phy.ops.write_phy_reg(hw, 0x1F79, 0x0210);
  1539. /* Change integ_factor of channel A to 3 */
  1540. hw->phy.ops.write_phy_reg(hw, 0x1895, 0x0003);
  1541. /* Change prop_factor of channels BCD to 8 */
  1542. hw->phy.ops.write_phy_reg(hw, 0x1796, 0x0008);
  1543. /* Change cg_icount + enable integbp for channels BCD */
  1544. hw->phy.ops.write_phy_reg(hw, 0x1798, 0xD008);
  1545. /*
  1546. * Change cg_icount + enable integbp + change prop_factor_master
  1547. * to 8 for channel A
  1548. */
  1549. hw->phy.ops.write_phy_reg(hw, 0x1898, 0xD918);
  1550. /* Disable AHT in Slave mode on channel A */
  1551. hw->phy.ops.write_phy_reg(hw, 0x187A, 0x0800);
  1552. /*
  1553. * Enable LPLU and disable AN to 1000 in non-D0a states,
  1554. * Enable SPD+B2B
  1555. */
  1556. hw->phy.ops.write_phy_reg(hw, 0x0019, 0x008D);
  1557. /* Enable restart AN on an1000_dis change */
  1558. hw->phy.ops.write_phy_reg(hw, 0x001B, 0x2080);
  1559. /* Enable wh_fifo read clock in 10/100 modes */
  1560. hw->phy.ops.write_phy_reg(hw, 0x0014, 0x0045);
  1561. /* Restart AN, Speed selection is 1000 */
  1562. hw->phy.ops.write_phy_reg(hw, 0x0000, 0x1340);
  1563. return 0;
  1564. }