e1000_phy.c 69 KB

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