e1000_phy.c 65 KB

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