e1000_phy.c 69 KB

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