e1000_phy.c 56 KB

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