e1000_phy.c 45 KB

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