e1000_phy.c 69 KB

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