e1000_phy.c 68 KB

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