e1000_phy.c 61 KB

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