e1000_phy.c 66 KB

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