e1000_phy.c 69 KB

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