phy.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2008 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/delay.h>
  22. #include "e1000.h"
  23. static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
  24. static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  25. static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active);
  26. static s32 e1000_wait_autoneg(struct e1000_hw *hw);
  27. static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg);
  28. static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
  29. u16 *data, bool read);
  30. static u32 e1000_get_phy_addr_for_hv_page(u32 page);
  31. static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
  32. u16 *data, bool read);
  33. /* Cable length tables */
  34. static const u16 e1000_m88_cable_length_table[] =
  35. { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
  36. static const u16 e1000_igp_2_cable_length_table[] =
  37. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
  38. 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
  39. 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
  40. 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
  41. 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
  42. 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
  43. 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
  44. 124};
  45. #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
  46. ARRAY_SIZE(e1000_igp_2_cable_length_table)
  47. #define BM_PHY_REG_PAGE(offset) \
  48. ((u16)(((offset) >> PHY_PAGE_SHIFT) & 0xFFFF))
  49. #define BM_PHY_REG_NUM(offset) \
  50. ((u16)(((offset) & MAX_PHY_REG_ADDRESS) |\
  51. (((offset) >> (PHY_UPPER_SHIFT - PHY_PAGE_SHIFT)) &\
  52. ~MAX_PHY_REG_ADDRESS)))
  53. #define HV_INTC_FC_PAGE_START 768
  54. #define I82578_ADDR_REG 29
  55. #define I82577_ADDR_REG 16
  56. #define I82577_CFG_REG 22
  57. #define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15)
  58. #define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */
  59. #define I82577_CTRL_REG 23
  60. #define I82577_CTRL_DOWNSHIFT_MASK (7 << 10)
  61. /* 82577 specific PHY registers */
  62. #define I82577_PHY_CTRL_2 18
  63. #define I82577_PHY_STATUS_2 26
  64. #define I82577_PHY_DIAG_STATUS 31
  65. /* I82577 PHY Status 2 */
  66. #define I82577_PHY_STATUS2_REV_POLARITY 0x0400
  67. #define I82577_PHY_STATUS2_MDIX 0x0800
  68. #define I82577_PHY_STATUS2_SPEED_MASK 0x0300
  69. #define I82577_PHY_STATUS2_SPEED_1000MBPS 0x0200
  70. /* I82577 PHY Control 2 */
  71. #define I82577_PHY_CTRL2_AUTO_MDIX 0x0400
  72. #define I82577_PHY_CTRL2_FORCE_MDI_MDIX 0x0200
  73. /* I82577 PHY Diagnostics Status */
  74. #define I82577_DSTATUS_CABLE_LENGTH 0x03FC
  75. #define I82577_DSTATUS_CABLE_LENGTH_SHIFT 2
  76. /* BM PHY Copper Specific Control 1 */
  77. #define BM_CS_CTRL1 16
  78. /* BM PHY Copper Specific Status */
  79. #define BM_CS_STATUS 17
  80. #define BM_CS_STATUS_LINK_UP 0x0400
  81. #define BM_CS_STATUS_RESOLVED 0x0800
  82. #define BM_CS_STATUS_SPEED_MASK 0xC000
  83. #define BM_CS_STATUS_SPEED_1000 0x8000
  84. #define HV_MUX_DATA_CTRL PHY_REG(776, 16)
  85. #define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400
  86. #define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004
  87. /**
  88. * e1000e_check_reset_block_generic - Check if PHY reset is blocked
  89. * @hw: pointer to the HW structure
  90. *
  91. * Read the PHY management control register and check whether a PHY reset
  92. * is blocked. If a reset is not blocked return 0, otherwise
  93. * return E1000_BLK_PHY_RESET (12).
  94. **/
  95. s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
  96. {
  97. u32 manc;
  98. manc = er32(MANC);
  99. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  100. E1000_BLK_PHY_RESET : 0;
  101. }
  102. /**
  103. * e1000e_get_phy_id - Retrieve the PHY ID and revision
  104. * @hw: pointer to the HW structure
  105. *
  106. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  107. * revision in the hardware structure.
  108. **/
  109. s32 e1000e_get_phy_id(struct e1000_hw *hw)
  110. {
  111. struct e1000_phy_info *phy = &hw->phy;
  112. s32 ret_val = 0;
  113. u16 phy_id;
  114. u16 retry_count = 0;
  115. if (!(phy->ops.read_phy_reg))
  116. goto out;
  117. while (retry_count < 2) {
  118. ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
  119. if (ret_val)
  120. goto out;
  121. phy->id = (u32)(phy_id << 16);
  122. udelay(20);
  123. ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
  124. if (ret_val)
  125. goto out;
  126. phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
  127. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  128. if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
  129. goto out;
  130. /*
  131. * If the PHY ID is still unknown, we may have an 82577i
  132. * without link. We will try again after setting Slow
  133. * MDIC mode. No harm in trying again in this case since
  134. * the PHY ID is unknown at this point anyway
  135. */
  136. ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
  137. if (ret_val)
  138. goto out;
  139. retry_count++;
  140. }
  141. out:
  142. /* Revert to MDIO fast mode, if applicable */
  143. if (retry_count)
  144. ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
  145. return ret_val;
  146. }
  147. /**
  148. * e1000e_phy_reset_dsp - Reset PHY DSP
  149. * @hw: pointer to the HW structure
  150. *
  151. * Reset the digital signal processor.
  152. **/
  153. s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
  154. {
  155. s32 ret_val;
  156. ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
  157. if (ret_val)
  158. return ret_val;
  159. return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
  160. }
  161. /**
  162. * e1000e_read_phy_reg_mdic - Read MDI control register
  163. * @hw: pointer to the HW structure
  164. * @offset: register offset to be read
  165. * @data: pointer to the read data
  166. *
  167. * Reads the MDI control register in the PHY at offset and stores the
  168. * information read to data.
  169. **/
  170. s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
  171. {
  172. struct e1000_phy_info *phy = &hw->phy;
  173. u32 i, mdic = 0;
  174. if (offset > MAX_PHY_REG_ADDRESS) {
  175. hw_dbg(hw, "PHY Address %d is out of range\n", offset);
  176. return -E1000_ERR_PARAM;
  177. }
  178. /*
  179. * Set up Op-code, Phy Address, and register offset in the MDI
  180. * Control register. The MAC will take care of interfacing with the
  181. * PHY to retrieve the desired data.
  182. */
  183. mdic = ((offset << E1000_MDIC_REG_SHIFT) |
  184. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  185. (E1000_MDIC_OP_READ));
  186. ew32(MDIC, mdic);
  187. /*
  188. * Poll the ready bit to see if the MDI read completed
  189. * Increasing the time out as testing showed failures with
  190. * the lower time out
  191. */
  192. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  193. udelay(50);
  194. mdic = er32(MDIC);
  195. if (mdic & E1000_MDIC_READY)
  196. break;
  197. }
  198. if (!(mdic & E1000_MDIC_READY)) {
  199. hw_dbg(hw, "MDI Read did not complete\n");
  200. return -E1000_ERR_PHY;
  201. }
  202. if (mdic & E1000_MDIC_ERROR) {
  203. hw_dbg(hw, "MDI Error\n");
  204. return -E1000_ERR_PHY;
  205. }
  206. *data = (u16) mdic;
  207. return 0;
  208. }
  209. /**
  210. * e1000e_write_phy_reg_mdic - Write MDI control register
  211. * @hw: pointer to the HW structure
  212. * @offset: register offset to write to
  213. * @data: data to write to register at offset
  214. *
  215. * Writes data to MDI control register in the PHY at offset.
  216. **/
  217. s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
  218. {
  219. struct e1000_phy_info *phy = &hw->phy;
  220. u32 i, mdic = 0;
  221. if (offset > MAX_PHY_REG_ADDRESS) {
  222. hw_dbg(hw, "PHY Address %d is out of range\n", offset);
  223. return -E1000_ERR_PARAM;
  224. }
  225. /*
  226. * Set up Op-code, Phy Address, and register offset in the MDI
  227. * Control register. The MAC will take care of interfacing with the
  228. * PHY to retrieve the desired data.
  229. */
  230. mdic = (((u32)data) |
  231. (offset << E1000_MDIC_REG_SHIFT) |
  232. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  233. (E1000_MDIC_OP_WRITE));
  234. ew32(MDIC, mdic);
  235. /*
  236. * Poll the ready bit to see if the MDI read completed
  237. * Increasing the time out as testing showed failures with
  238. * the lower time out
  239. */
  240. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  241. udelay(50);
  242. mdic = er32(MDIC);
  243. if (mdic & E1000_MDIC_READY)
  244. break;
  245. }
  246. if (!(mdic & E1000_MDIC_READY)) {
  247. hw_dbg(hw, "MDI Write did not complete\n");
  248. return -E1000_ERR_PHY;
  249. }
  250. if (mdic & E1000_MDIC_ERROR) {
  251. hw_dbg(hw, "MDI Error\n");
  252. return -E1000_ERR_PHY;
  253. }
  254. return 0;
  255. }
  256. /**
  257. * e1000e_read_phy_reg_m88 - Read m88 PHY register
  258. * @hw: pointer to the HW structure
  259. * @offset: register offset to be read
  260. * @data: pointer to the read data
  261. *
  262. * Acquires semaphore, if necessary, then reads the PHY register at offset
  263. * and storing the retrieved information in data. Release any acquired
  264. * semaphores before exiting.
  265. **/
  266. s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
  267. {
  268. s32 ret_val;
  269. ret_val = hw->phy.ops.acquire_phy(hw);
  270. if (ret_val)
  271. return ret_val;
  272. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  273. data);
  274. hw->phy.ops.release_phy(hw);
  275. return ret_val;
  276. }
  277. /**
  278. * e1000e_write_phy_reg_m88 - Write m88 PHY register
  279. * @hw: pointer to the HW structure
  280. * @offset: register offset to write to
  281. * @data: data to write at register offset
  282. *
  283. * Acquires semaphore, if necessary, then writes the data to PHY register
  284. * at the offset. Release any acquired semaphores before exiting.
  285. **/
  286. s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
  287. {
  288. s32 ret_val;
  289. ret_val = hw->phy.ops.acquire_phy(hw);
  290. if (ret_val)
  291. return ret_val;
  292. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  293. data);
  294. hw->phy.ops.release_phy(hw);
  295. return ret_val;
  296. }
  297. /**
  298. * e1000e_read_phy_reg_igp - Read igp PHY register
  299. * @hw: pointer to the HW structure
  300. * @offset: register offset to be read
  301. * @data: pointer to the read data
  302. *
  303. * Acquires semaphore, if necessary, then reads the PHY register at offset
  304. * and storing the retrieved information in data. Release any acquired
  305. * semaphores before exiting.
  306. **/
  307. s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
  308. {
  309. s32 ret_val;
  310. ret_val = hw->phy.ops.acquire_phy(hw);
  311. if (ret_val)
  312. return ret_val;
  313. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  314. ret_val = e1000e_write_phy_reg_mdic(hw,
  315. IGP01E1000_PHY_PAGE_SELECT,
  316. (u16)offset);
  317. if (ret_val) {
  318. hw->phy.ops.release_phy(hw);
  319. return ret_val;
  320. }
  321. }
  322. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  323. data);
  324. hw->phy.ops.release_phy(hw);
  325. return ret_val;
  326. }
  327. /**
  328. * e1000e_write_phy_reg_igp - Write igp PHY register
  329. * @hw: pointer to the HW structure
  330. * @offset: register offset to write to
  331. * @data: data to write at register offset
  332. *
  333. * Acquires semaphore, if necessary, then writes the data to PHY register
  334. * at the offset. Release any acquired semaphores before exiting.
  335. **/
  336. s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
  337. {
  338. s32 ret_val;
  339. ret_val = hw->phy.ops.acquire_phy(hw);
  340. if (ret_val)
  341. return ret_val;
  342. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  343. ret_val = e1000e_write_phy_reg_mdic(hw,
  344. IGP01E1000_PHY_PAGE_SELECT,
  345. (u16)offset);
  346. if (ret_val) {
  347. hw->phy.ops.release_phy(hw);
  348. return ret_val;
  349. }
  350. }
  351. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  352. data);
  353. hw->phy.ops.release_phy(hw);
  354. return ret_val;
  355. }
  356. /**
  357. * e1000e_read_kmrn_reg - Read kumeran register
  358. * @hw: pointer to the HW structure
  359. * @offset: register offset to be read
  360. * @data: pointer to the read data
  361. *
  362. * Acquires semaphore, if necessary. Then reads the PHY register at offset
  363. * using the kumeran interface. The information retrieved is stored in data.
  364. * Release any acquired semaphores before exiting.
  365. **/
  366. s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
  367. {
  368. u32 kmrnctrlsta;
  369. s32 ret_val;
  370. ret_val = hw->phy.ops.acquire_phy(hw);
  371. if (ret_val)
  372. return ret_val;
  373. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  374. E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
  375. ew32(KMRNCTRLSTA, kmrnctrlsta);
  376. udelay(2);
  377. kmrnctrlsta = er32(KMRNCTRLSTA);
  378. *data = (u16)kmrnctrlsta;
  379. hw->phy.ops.release_phy(hw);
  380. return ret_val;
  381. }
  382. /**
  383. * e1000e_write_kmrn_reg - Write kumeran register
  384. * @hw: pointer to the HW structure
  385. * @offset: register offset to write to
  386. * @data: data to write at register offset
  387. *
  388. * Acquires semaphore, if necessary. Then write the data to PHY register
  389. * at the offset using the kumeran interface. Release any acquired semaphores
  390. * before exiting.
  391. **/
  392. s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
  393. {
  394. u32 kmrnctrlsta;
  395. s32 ret_val;
  396. ret_val = hw->phy.ops.acquire_phy(hw);
  397. if (ret_val)
  398. return ret_val;
  399. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  400. E1000_KMRNCTRLSTA_OFFSET) | data;
  401. ew32(KMRNCTRLSTA, kmrnctrlsta);
  402. udelay(2);
  403. hw->phy.ops.release_phy(hw);
  404. return ret_val;
  405. }
  406. /**
  407. * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
  408. * @hw: pointer to the HW structure
  409. *
  410. * Sets up Carrier-sense on Transmit and downshift values.
  411. **/
  412. s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
  413. {
  414. struct e1000_phy_info *phy = &hw->phy;
  415. s32 ret_val;
  416. u16 phy_data;
  417. /* Enable CRS on TX. This must be set for half-duplex operation. */
  418. ret_val = phy->ops.read_phy_reg(hw, I82577_CFG_REG, &phy_data);
  419. if (ret_val)
  420. goto out;
  421. phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
  422. /* Enable downshift */
  423. phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
  424. ret_val = phy->ops.write_phy_reg(hw, I82577_CFG_REG, phy_data);
  425. if (ret_val)
  426. goto out;
  427. /* Set number of link attempts before downshift */
  428. ret_val = phy->ops.read_phy_reg(hw, I82577_CTRL_REG, &phy_data);
  429. if (ret_val)
  430. goto out;
  431. phy_data &= ~I82577_CTRL_DOWNSHIFT_MASK;
  432. ret_val = phy->ops.write_phy_reg(hw, I82577_CTRL_REG, phy_data);
  433. out:
  434. return ret_val;
  435. }
  436. /**
  437. * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
  438. * @hw: pointer to the HW structure
  439. *
  440. * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
  441. * and downshift values are set also.
  442. **/
  443. s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
  444. {
  445. struct e1000_phy_info *phy = &hw->phy;
  446. s32 ret_val;
  447. u16 phy_data;
  448. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  449. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  450. if (ret_val)
  451. return ret_val;
  452. /* For BM PHY this bit is downshift enable */
  453. if (phy->type != e1000_phy_bm)
  454. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  455. /*
  456. * Options:
  457. * MDI/MDI-X = 0 (default)
  458. * 0 - Auto for all speeds
  459. * 1 - MDI mode
  460. * 2 - MDI-X mode
  461. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  462. */
  463. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  464. switch (phy->mdix) {
  465. case 1:
  466. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  467. break;
  468. case 2:
  469. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  470. break;
  471. case 3:
  472. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  473. break;
  474. case 0:
  475. default:
  476. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  477. break;
  478. }
  479. /*
  480. * Options:
  481. * disable_polarity_correction = 0 (default)
  482. * Automatic Correction for Reversed Cable Polarity
  483. * 0 - Disabled
  484. * 1 - Enabled
  485. */
  486. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  487. if (phy->disable_polarity_correction == 1)
  488. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  489. /* Enable downshift on BM (disabled by default) */
  490. if (phy->type == e1000_phy_bm)
  491. phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
  492. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  493. if (ret_val)
  494. return ret_val;
  495. if ((phy->type == e1000_phy_m88) &&
  496. (phy->revision < E1000_REVISION_4) &&
  497. (phy->id != BME1000_E_PHY_ID_R2)) {
  498. /*
  499. * Force TX_CLK in the Extended PHY Specific Control Register
  500. * to 25MHz clock.
  501. */
  502. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  503. if (ret_val)
  504. return ret_val;
  505. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  506. if ((phy->revision == 2) &&
  507. (phy->id == M88E1111_I_PHY_ID)) {
  508. /* 82573L PHY - set the downshift counter to 5x. */
  509. phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
  510. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  511. } else {
  512. /* Configure Master and Slave downshift values */
  513. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  514. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  515. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  516. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  517. }
  518. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  519. if (ret_val)
  520. return ret_val;
  521. }
  522. if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
  523. /* Set PHY page 0, register 29 to 0x0003 */
  524. ret_val = e1e_wphy(hw, 29, 0x0003);
  525. if (ret_val)
  526. return ret_val;
  527. /* Set PHY page 0, register 30 to 0x0000 */
  528. ret_val = e1e_wphy(hw, 30, 0x0000);
  529. if (ret_val)
  530. return ret_val;
  531. }
  532. /* Commit the changes. */
  533. ret_val = e1000e_commit_phy(hw);
  534. if (ret_val) {
  535. hw_dbg(hw, "Error committing the PHY changes\n");
  536. return ret_val;
  537. }
  538. if (phy->type == e1000_phy_82578) {
  539. ret_val = phy->ops.read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  540. &phy_data);
  541. if (ret_val)
  542. return ret_val;
  543. /* 82578 PHY - set the downshift count to 1x. */
  544. phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
  545. phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
  546. ret_val = phy->ops.write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  547. phy_data);
  548. if (ret_val)
  549. return ret_val;
  550. }
  551. return 0;
  552. }
  553. /**
  554. * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
  555. * @hw: pointer to the HW structure
  556. *
  557. * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
  558. * igp PHY's.
  559. **/
  560. s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
  561. {
  562. struct e1000_phy_info *phy = &hw->phy;
  563. s32 ret_val;
  564. u16 data;
  565. ret_val = e1000_phy_hw_reset(hw);
  566. if (ret_val) {
  567. hw_dbg(hw, "Error resetting the PHY.\n");
  568. return ret_val;
  569. }
  570. /*
  571. * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
  572. * timeout issues when LFS is enabled.
  573. */
  574. msleep(100);
  575. /* disable lplu d0 during driver init */
  576. ret_val = e1000_set_d0_lplu_state(hw, 0);
  577. if (ret_val) {
  578. hw_dbg(hw, "Error Disabling LPLU D0\n");
  579. return ret_val;
  580. }
  581. /* Configure mdi-mdix settings */
  582. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
  583. if (ret_val)
  584. return ret_val;
  585. data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  586. switch (phy->mdix) {
  587. case 1:
  588. data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  589. break;
  590. case 2:
  591. data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  592. break;
  593. case 0:
  594. default:
  595. data |= IGP01E1000_PSCR_AUTO_MDIX;
  596. break;
  597. }
  598. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
  599. if (ret_val)
  600. return ret_val;
  601. /* set auto-master slave resolution settings */
  602. if (hw->mac.autoneg) {
  603. /*
  604. * when autonegotiation advertisement is only 1000Mbps then we
  605. * should disable SmartSpeed and enable Auto MasterSlave
  606. * resolution as hardware default.
  607. */
  608. if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
  609. /* Disable SmartSpeed */
  610. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  611. &data);
  612. if (ret_val)
  613. return ret_val;
  614. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  615. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  616. data);
  617. if (ret_val)
  618. return ret_val;
  619. /* Set auto Master/Slave resolution process */
  620. ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
  621. if (ret_val)
  622. return ret_val;
  623. data &= ~CR_1000T_MS_ENABLE;
  624. ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
  625. if (ret_val)
  626. return ret_val;
  627. }
  628. ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
  629. if (ret_val)
  630. return ret_val;
  631. /* load defaults for future use */
  632. phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
  633. ((data & CR_1000T_MS_VALUE) ?
  634. e1000_ms_force_master :
  635. e1000_ms_force_slave) :
  636. e1000_ms_auto;
  637. switch (phy->ms_type) {
  638. case e1000_ms_force_master:
  639. data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  640. break;
  641. case e1000_ms_force_slave:
  642. data |= CR_1000T_MS_ENABLE;
  643. data &= ~(CR_1000T_MS_VALUE);
  644. break;
  645. case e1000_ms_auto:
  646. data &= ~CR_1000T_MS_ENABLE;
  647. default:
  648. break;
  649. }
  650. ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
  651. }
  652. return ret_val;
  653. }
  654. /**
  655. * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
  656. * @hw: pointer to the HW structure
  657. *
  658. * Reads the MII auto-neg advertisement register and/or the 1000T control
  659. * register and if the PHY is already setup for auto-negotiation, then
  660. * return successful. Otherwise, setup advertisement and flow control to
  661. * the appropriate values for the wanted auto-negotiation.
  662. **/
  663. static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
  664. {
  665. struct e1000_phy_info *phy = &hw->phy;
  666. s32 ret_val;
  667. u16 mii_autoneg_adv_reg;
  668. u16 mii_1000t_ctrl_reg = 0;
  669. phy->autoneg_advertised &= phy->autoneg_mask;
  670. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  671. ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  672. if (ret_val)
  673. return ret_val;
  674. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  675. /* Read the MII 1000Base-T Control Register (Address 9). */
  676. ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  677. if (ret_val)
  678. return ret_val;
  679. }
  680. /*
  681. * Need to parse both autoneg_advertised and fc and set up
  682. * the appropriate PHY registers. First we will parse for
  683. * autoneg_advertised software override. Since we can advertise
  684. * a plethora of combinations, we need to check each bit
  685. * individually.
  686. */
  687. /*
  688. * First we clear all the 10/100 mb speed bits in the Auto-Neg
  689. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  690. * the 1000Base-T Control Register (Address 9).
  691. */
  692. mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
  693. NWAY_AR_100TX_HD_CAPS |
  694. NWAY_AR_10T_FD_CAPS |
  695. NWAY_AR_10T_HD_CAPS);
  696. mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
  697. hw_dbg(hw, "autoneg_advertised %x\n", phy->autoneg_advertised);
  698. /* Do we want to advertise 10 Mb Half Duplex? */
  699. if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
  700. hw_dbg(hw, "Advertise 10mb Half duplex\n");
  701. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  702. }
  703. /* Do we want to advertise 10 Mb Full Duplex? */
  704. if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
  705. hw_dbg(hw, "Advertise 10mb Full duplex\n");
  706. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  707. }
  708. /* Do we want to advertise 100 Mb Half Duplex? */
  709. if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
  710. hw_dbg(hw, "Advertise 100mb Half duplex\n");
  711. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  712. }
  713. /* Do we want to advertise 100 Mb Full Duplex? */
  714. if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
  715. hw_dbg(hw, "Advertise 100mb Full duplex\n");
  716. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  717. }
  718. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  719. if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
  720. hw_dbg(hw, "Advertise 1000mb Half duplex request denied!\n");
  721. /* Do we want to advertise 1000 Mb Full Duplex? */
  722. if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
  723. hw_dbg(hw, "Advertise 1000mb Full duplex\n");
  724. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  725. }
  726. /*
  727. * Check for a software override of the flow control settings, and
  728. * setup the PHY advertisement registers accordingly. If
  729. * auto-negotiation is enabled, then software will have to set the
  730. * "PAUSE" bits to the correct value in the Auto-Negotiation
  731. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
  732. * negotiation.
  733. *
  734. * The possible values of the "fc" parameter are:
  735. * 0: Flow control is completely disabled
  736. * 1: Rx flow control is enabled (we can receive pause frames
  737. * but not send pause frames).
  738. * 2: Tx flow control is enabled (we can send pause frames
  739. * but we do not support receiving pause frames).
  740. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  741. * other: No software override. The flow control configuration
  742. * in the EEPROM is used.
  743. */
  744. switch (hw->fc.current_mode) {
  745. case e1000_fc_none:
  746. /*
  747. * Flow control (Rx & Tx) is completely disabled by a
  748. * software over-ride.
  749. */
  750. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  751. break;
  752. case e1000_fc_rx_pause:
  753. /*
  754. * Rx Flow control is enabled, and Tx Flow control is
  755. * disabled, by a software over-ride.
  756. *
  757. * Since there really isn't a way to advertise that we are
  758. * capable of Rx Pause ONLY, we will advertise that we
  759. * support both symmetric and asymmetric Rx PAUSE. Later
  760. * (in e1000e_config_fc_after_link_up) we will disable the
  761. * hw's ability to send PAUSE frames.
  762. */
  763. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  764. break;
  765. case e1000_fc_tx_pause:
  766. /*
  767. * Tx Flow control is enabled, and Rx Flow control is
  768. * disabled, by a software over-ride.
  769. */
  770. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  771. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  772. break;
  773. case e1000_fc_full:
  774. /*
  775. * Flow control (both Rx and Tx) is enabled by a software
  776. * over-ride.
  777. */
  778. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  779. break;
  780. default:
  781. hw_dbg(hw, "Flow control param set incorrectly\n");
  782. ret_val = -E1000_ERR_CONFIG;
  783. return ret_val;
  784. }
  785. ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  786. if (ret_val)
  787. return ret_val;
  788. hw_dbg(hw, "Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  789. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  790. ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
  791. }
  792. return ret_val;
  793. }
  794. /**
  795. * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
  796. * @hw: pointer to the HW structure
  797. *
  798. * Performs initial bounds checking on autoneg advertisement parameter, then
  799. * configure to advertise the full capability. Setup the PHY to autoneg
  800. * and restart the negotiation process between the link partner. If
  801. * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
  802. **/
  803. static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
  804. {
  805. struct e1000_phy_info *phy = &hw->phy;
  806. s32 ret_val;
  807. u16 phy_ctrl;
  808. /*
  809. * Perform some bounds checking on the autoneg advertisement
  810. * parameter.
  811. */
  812. phy->autoneg_advertised &= phy->autoneg_mask;
  813. /*
  814. * If autoneg_advertised is zero, we assume it was not defaulted
  815. * by the calling code so we set to advertise full capability.
  816. */
  817. if (phy->autoneg_advertised == 0)
  818. phy->autoneg_advertised = phy->autoneg_mask;
  819. hw_dbg(hw, "Reconfiguring auto-neg advertisement params\n");
  820. ret_val = e1000_phy_setup_autoneg(hw);
  821. if (ret_val) {
  822. hw_dbg(hw, "Error Setting up Auto-Negotiation\n");
  823. return ret_val;
  824. }
  825. hw_dbg(hw, "Restarting Auto-Neg\n");
  826. /*
  827. * Restart auto-negotiation by setting the Auto Neg Enable bit and
  828. * the Auto Neg Restart bit in the PHY control register.
  829. */
  830. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
  831. if (ret_val)
  832. return ret_val;
  833. phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  834. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
  835. if (ret_val)
  836. return ret_val;
  837. /*
  838. * Does the user want to wait for Auto-Neg to complete here, or
  839. * check at a later time (for example, callback routine).
  840. */
  841. if (phy->autoneg_wait_to_complete) {
  842. ret_val = e1000_wait_autoneg(hw);
  843. if (ret_val) {
  844. hw_dbg(hw, "Error while waiting for "
  845. "autoneg to complete\n");
  846. return ret_val;
  847. }
  848. }
  849. hw->mac.get_link_status = 1;
  850. return ret_val;
  851. }
  852. /**
  853. * e1000e_setup_copper_link - Configure copper link settings
  854. * @hw: pointer to the HW structure
  855. *
  856. * Calls the appropriate function to configure the link for auto-neg or forced
  857. * speed and duplex. Then we check for link, once link is established calls
  858. * to configure collision distance and flow control are called. If link is
  859. * not established, we return -E1000_ERR_PHY (-2).
  860. **/
  861. s32 e1000e_setup_copper_link(struct e1000_hw *hw)
  862. {
  863. s32 ret_val;
  864. bool link;
  865. if (hw->mac.autoneg) {
  866. /*
  867. * Setup autoneg and flow control advertisement and perform
  868. * autonegotiation.
  869. */
  870. ret_val = e1000_copper_link_autoneg(hw);
  871. if (ret_val)
  872. return ret_val;
  873. } else {
  874. /*
  875. * PHY will be set to 10H, 10F, 100H or 100F
  876. * depending on user settings.
  877. */
  878. hw_dbg(hw, "Forcing Speed and Duplex\n");
  879. ret_val = e1000_phy_force_speed_duplex(hw);
  880. if (ret_val) {
  881. hw_dbg(hw, "Error Forcing Speed and Duplex\n");
  882. return ret_val;
  883. }
  884. }
  885. /*
  886. * Check link status. Wait up to 100 microseconds for link to become
  887. * valid.
  888. */
  889. ret_val = e1000e_phy_has_link_generic(hw,
  890. COPPER_LINK_UP_LIMIT,
  891. 10,
  892. &link);
  893. if (ret_val)
  894. return ret_val;
  895. if (link) {
  896. hw_dbg(hw, "Valid link established!!!\n");
  897. e1000e_config_collision_dist(hw);
  898. ret_val = e1000e_config_fc_after_link_up(hw);
  899. } else {
  900. hw_dbg(hw, "Unable to establish link!!!\n");
  901. }
  902. return ret_val;
  903. }
  904. /**
  905. * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
  906. * @hw: pointer to the HW structure
  907. *
  908. * Calls the PHY setup function to force speed and duplex. Clears the
  909. * auto-crossover to force MDI manually. Waits for link and returns
  910. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  911. **/
  912. s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
  913. {
  914. struct e1000_phy_info *phy = &hw->phy;
  915. s32 ret_val;
  916. u16 phy_data;
  917. bool link;
  918. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
  919. if (ret_val)
  920. return ret_val;
  921. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  922. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
  923. if (ret_val)
  924. return ret_val;
  925. /*
  926. * Clear Auto-Crossover to force MDI manually. IGP requires MDI
  927. * forced whenever speed and duplex are forced.
  928. */
  929. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  930. if (ret_val)
  931. return ret_val;
  932. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  933. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  934. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  935. if (ret_val)
  936. return ret_val;
  937. hw_dbg(hw, "IGP PSCR: %X\n", phy_data);
  938. udelay(1);
  939. if (phy->autoneg_wait_to_complete) {
  940. hw_dbg(hw, "Waiting for forced speed/duplex link on IGP phy.\n");
  941. ret_val = e1000e_phy_has_link_generic(hw,
  942. PHY_FORCE_LIMIT,
  943. 100000,
  944. &link);
  945. if (ret_val)
  946. return ret_val;
  947. if (!link)
  948. hw_dbg(hw, "Link taking longer than expected.\n");
  949. /* Try once more */
  950. ret_val = e1000e_phy_has_link_generic(hw,
  951. PHY_FORCE_LIMIT,
  952. 100000,
  953. &link);
  954. if (ret_val)
  955. return ret_val;
  956. }
  957. return ret_val;
  958. }
  959. /**
  960. * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
  961. * @hw: pointer to the HW structure
  962. *
  963. * Calls the PHY setup function to force speed and duplex. Clears the
  964. * auto-crossover to force MDI manually. Resets the PHY to commit the
  965. * changes. If time expires while waiting for link up, we reset the DSP.
  966. * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
  967. * successful completion, else return corresponding error code.
  968. **/
  969. s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
  970. {
  971. struct e1000_phy_info *phy = &hw->phy;
  972. s32 ret_val;
  973. u16 phy_data;
  974. bool link;
  975. /*
  976. * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  977. * forced whenever speed and duplex are forced.
  978. */
  979. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  980. if (ret_val)
  981. return ret_val;
  982. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  983. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  984. if (ret_val)
  985. return ret_val;
  986. hw_dbg(hw, "M88E1000 PSCR: %X\n", phy_data);
  987. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
  988. if (ret_val)
  989. return ret_val;
  990. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  991. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
  992. if (ret_val)
  993. return ret_val;
  994. /* Reset the phy to commit changes. */
  995. ret_val = e1000e_commit_phy(hw);
  996. if (ret_val)
  997. return ret_val;
  998. if (phy->autoneg_wait_to_complete) {
  999. hw_dbg(hw, "Waiting for forced speed/duplex link on M88 phy.\n");
  1000. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1001. 100000, &link);
  1002. if (ret_val)
  1003. return ret_val;
  1004. if (!link) {
  1005. /*
  1006. * We didn't get link.
  1007. * Reset the DSP and cross our fingers.
  1008. */
  1009. ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
  1010. 0x001d);
  1011. if (ret_val)
  1012. return ret_val;
  1013. ret_val = e1000e_phy_reset_dsp(hw);
  1014. if (ret_val)
  1015. return ret_val;
  1016. }
  1017. /* Try once more */
  1018. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1019. 100000, &link);
  1020. if (ret_val)
  1021. return ret_val;
  1022. }
  1023. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1024. if (ret_val)
  1025. return ret_val;
  1026. /*
  1027. * Resetting the phy means we need to re-force TX_CLK in the
  1028. * Extended PHY Specific Control Register to 25MHz clock from
  1029. * the reset value of 2.5MHz.
  1030. */
  1031. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1032. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1033. if (ret_val)
  1034. return ret_val;
  1035. /*
  1036. * In addition, we must re-enable CRS on Tx for both half and full
  1037. * duplex.
  1038. */
  1039. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1040. if (ret_val)
  1041. return ret_val;
  1042. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1043. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1044. return ret_val;
  1045. }
  1046. /**
  1047. * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
  1048. * @hw: pointer to the HW structure
  1049. * @phy_ctrl: pointer to current value of PHY_CONTROL
  1050. *
  1051. * Forces speed and duplex on the PHY by doing the following: disable flow
  1052. * control, force speed/duplex on the MAC, disable auto speed detection,
  1053. * disable auto-negotiation, configure duplex, configure speed, configure
  1054. * the collision distance, write configuration to CTRL register. The
  1055. * caller must write to the PHY_CONTROL register for these settings to
  1056. * take affect.
  1057. **/
  1058. void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
  1059. {
  1060. struct e1000_mac_info *mac = &hw->mac;
  1061. u32 ctrl;
  1062. /* Turn off flow control when forcing speed/duplex */
  1063. hw->fc.current_mode = e1000_fc_none;
  1064. /* Force speed/duplex on the mac */
  1065. ctrl = er32(CTRL);
  1066. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1067. ctrl &= ~E1000_CTRL_SPD_SEL;
  1068. /* Disable Auto Speed Detection */
  1069. ctrl &= ~E1000_CTRL_ASDE;
  1070. /* Disable autoneg on the phy */
  1071. *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
  1072. /* Forcing Full or Half Duplex? */
  1073. if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
  1074. ctrl &= ~E1000_CTRL_FD;
  1075. *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
  1076. hw_dbg(hw, "Half Duplex\n");
  1077. } else {
  1078. ctrl |= E1000_CTRL_FD;
  1079. *phy_ctrl |= MII_CR_FULL_DUPLEX;
  1080. hw_dbg(hw, "Full Duplex\n");
  1081. }
  1082. /* Forcing 10mb or 100mb? */
  1083. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
  1084. ctrl |= E1000_CTRL_SPD_100;
  1085. *phy_ctrl |= MII_CR_SPEED_100;
  1086. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1087. hw_dbg(hw, "Forcing 100mb\n");
  1088. } else {
  1089. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1090. *phy_ctrl |= MII_CR_SPEED_10;
  1091. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1092. hw_dbg(hw, "Forcing 10mb\n");
  1093. }
  1094. e1000e_config_collision_dist(hw);
  1095. ew32(CTRL, ctrl);
  1096. }
  1097. /**
  1098. * e1000e_set_d3_lplu_state - Sets low power link up state for D3
  1099. * @hw: pointer to the HW structure
  1100. * @active: boolean used to enable/disable lplu
  1101. *
  1102. * Success returns 0, Failure returns 1
  1103. *
  1104. * The low power link up (lplu) state is set to the power management level D3
  1105. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  1106. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  1107. * is used during Dx states where the power conservation is most important.
  1108. * During driver activity, SmartSpeed should be enabled so performance is
  1109. * maintained.
  1110. **/
  1111. s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  1112. {
  1113. struct e1000_phy_info *phy = &hw->phy;
  1114. s32 ret_val;
  1115. u16 data;
  1116. ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  1117. if (ret_val)
  1118. return ret_val;
  1119. if (!active) {
  1120. data &= ~IGP02E1000_PM_D3_LPLU;
  1121. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1122. if (ret_val)
  1123. return ret_val;
  1124. /*
  1125. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  1126. * during Dx states where the power conservation is most
  1127. * important. During driver activity we should enable
  1128. * SmartSpeed, so performance is maintained.
  1129. */
  1130. if (phy->smart_speed == e1000_smart_speed_on) {
  1131. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1132. &data);
  1133. if (ret_val)
  1134. return ret_val;
  1135. data |= IGP01E1000_PSCFR_SMART_SPEED;
  1136. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1137. data);
  1138. if (ret_val)
  1139. return ret_val;
  1140. } else if (phy->smart_speed == e1000_smart_speed_off) {
  1141. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1142. &data);
  1143. if (ret_val)
  1144. return ret_val;
  1145. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1146. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1147. data);
  1148. if (ret_val)
  1149. return ret_val;
  1150. }
  1151. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  1152. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  1153. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  1154. data |= IGP02E1000_PM_D3_LPLU;
  1155. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1156. if (ret_val)
  1157. return ret_val;
  1158. /* When LPLU is enabled, we should disable SmartSpeed */
  1159. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  1160. if (ret_val)
  1161. return ret_val;
  1162. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1163. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  1164. }
  1165. return ret_val;
  1166. }
  1167. /**
  1168. * e1000e_check_downshift - Checks whether a downshift in speed occurred
  1169. * @hw: pointer to the HW structure
  1170. *
  1171. * Success returns 0, Failure returns 1
  1172. *
  1173. * A downshift is detected by querying the PHY link health.
  1174. **/
  1175. s32 e1000e_check_downshift(struct e1000_hw *hw)
  1176. {
  1177. struct e1000_phy_info *phy = &hw->phy;
  1178. s32 ret_val;
  1179. u16 phy_data, offset, mask;
  1180. switch (phy->type) {
  1181. case e1000_phy_m88:
  1182. case e1000_phy_gg82563:
  1183. case e1000_phy_82578:
  1184. case e1000_phy_82577:
  1185. offset = M88E1000_PHY_SPEC_STATUS;
  1186. mask = M88E1000_PSSR_DOWNSHIFT;
  1187. break;
  1188. case e1000_phy_igp_2:
  1189. case e1000_phy_igp_3:
  1190. offset = IGP01E1000_PHY_LINK_HEALTH;
  1191. mask = IGP01E1000_PLHR_SS_DOWNGRADE;
  1192. break;
  1193. default:
  1194. /* speed downshift not supported */
  1195. phy->speed_downgraded = 0;
  1196. return 0;
  1197. }
  1198. ret_val = e1e_rphy(hw, offset, &phy_data);
  1199. if (!ret_val)
  1200. phy->speed_downgraded = (phy_data & mask);
  1201. return ret_val;
  1202. }
  1203. /**
  1204. * e1000_check_polarity_m88 - Checks the polarity.
  1205. * @hw: pointer to the HW structure
  1206. *
  1207. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1208. *
  1209. * Polarity is determined based on the PHY specific status register.
  1210. **/
  1211. static s32 e1000_check_polarity_m88(struct e1000_hw *hw)
  1212. {
  1213. struct e1000_phy_info *phy = &hw->phy;
  1214. s32 ret_val;
  1215. u16 data;
  1216. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
  1217. if (!ret_val)
  1218. phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
  1219. ? e1000_rev_polarity_reversed
  1220. : e1000_rev_polarity_normal;
  1221. return ret_val;
  1222. }
  1223. /**
  1224. * e1000_check_polarity_igp - Checks the polarity.
  1225. * @hw: pointer to the HW structure
  1226. *
  1227. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1228. *
  1229. * Polarity is determined based on the PHY port status register, and the
  1230. * current speed (since there is no polarity at 100Mbps).
  1231. **/
  1232. static s32 e1000_check_polarity_igp(struct e1000_hw *hw)
  1233. {
  1234. struct e1000_phy_info *phy = &hw->phy;
  1235. s32 ret_val;
  1236. u16 data, offset, mask;
  1237. /*
  1238. * Polarity is determined based on the speed of
  1239. * our connection.
  1240. */
  1241. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1242. if (ret_val)
  1243. return ret_val;
  1244. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1245. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1246. offset = IGP01E1000_PHY_PCS_INIT_REG;
  1247. mask = IGP01E1000_PHY_POLARITY_MASK;
  1248. } else {
  1249. /*
  1250. * This really only applies to 10Mbps since
  1251. * there is no polarity for 100Mbps (always 0).
  1252. */
  1253. offset = IGP01E1000_PHY_PORT_STATUS;
  1254. mask = IGP01E1000_PSSR_POLARITY_REVERSED;
  1255. }
  1256. ret_val = e1e_rphy(hw, offset, &data);
  1257. if (!ret_val)
  1258. phy->cable_polarity = (data & mask)
  1259. ? e1000_rev_polarity_reversed
  1260. : e1000_rev_polarity_normal;
  1261. return ret_val;
  1262. }
  1263. /**
  1264. * e1000_wait_autoneg - Wait for auto-neg completion
  1265. * @hw: pointer to the HW structure
  1266. *
  1267. * Waits for auto-negotiation to complete or for the auto-negotiation time
  1268. * limit to expire, which ever happens first.
  1269. **/
  1270. static s32 e1000_wait_autoneg(struct e1000_hw *hw)
  1271. {
  1272. s32 ret_val = 0;
  1273. u16 i, phy_status;
  1274. /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
  1275. for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
  1276. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1277. if (ret_val)
  1278. break;
  1279. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1280. if (ret_val)
  1281. break;
  1282. if (phy_status & MII_SR_AUTONEG_COMPLETE)
  1283. break;
  1284. msleep(100);
  1285. }
  1286. /*
  1287. * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
  1288. * has completed.
  1289. */
  1290. return ret_val;
  1291. }
  1292. /**
  1293. * e1000e_phy_has_link_generic - Polls PHY for link
  1294. * @hw: pointer to the HW structure
  1295. * @iterations: number of times to poll for link
  1296. * @usec_interval: delay between polling attempts
  1297. * @success: pointer to whether polling was successful or not
  1298. *
  1299. * Polls the PHY status register for link, 'iterations' number of times.
  1300. **/
  1301. s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
  1302. u32 usec_interval, bool *success)
  1303. {
  1304. s32 ret_val = 0;
  1305. u16 i, phy_status;
  1306. for (i = 0; i < iterations; i++) {
  1307. /*
  1308. * Some PHYs require the PHY_STATUS register to be read
  1309. * twice due to the link bit being sticky. No harm doing
  1310. * it across the board.
  1311. */
  1312. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1313. if (ret_val)
  1314. /*
  1315. * If the first read fails, another entity may have
  1316. * ownership of the resources, wait and try again to
  1317. * see if they have relinquished the resources yet.
  1318. */
  1319. udelay(usec_interval);
  1320. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1321. if (ret_val)
  1322. break;
  1323. if (phy_status & MII_SR_LINK_STATUS)
  1324. break;
  1325. if (usec_interval >= 1000)
  1326. mdelay(usec_interval/1000);
  1327. else
  1328. udelay(usec_interval);
  1329. }
  1330. *success = (i < iterations);
  1331. return ret_val;
  1332. }
  1333. /**
  1334. * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
  1335. * @hw: pointer to the HW structure
  1336. *
  1337. * Reads the PHY specific status register to retrieve the cable length
  1338. * information. The cable length is determined by averaging the minimum and
  1339. * maximum values to get the "average" cable length. The m88 PHY has four
  1340. * possible cable length values, which are:
  1341. * Register Value Cable Length
  1342. * 0 < 50 meters
  1343. * 1 50 - 80 meters
  1344. * 2 80 - 110 meters
  1345. * 3 110 - 140 meters
  1346. * 4 > 140 meters
  1347. **/
  1348. s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
  1349. {
  1350. struct e1000_phy_info *phy = &hw->phy;
  1351. s32 ret_val;
  1352. u16 phy_data, index;
  1353. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1354. if (ret_val)
  1355. return ret_val;
  1356. index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1357. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  1358. phy->min_cable_length = e1000_m88_cable_length_table[index];
  1359. phy->max_cable_length = e1000_m88_cable_length_table[index+1];
  1360. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1361. return ret_val;
  1362. }
  1363. /**
  1364. * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
  1365. * @hw: pointer to the HW structure
  1366. *
  1367. * The automatic gain control (agc) normalizes the amplitude of the
  1368. * received signal, adjusting for the attenuation produced by the
  1369. * cable. By reading the AGC registers, which represent the
  1370. * combination of course and fine gain value, the value can be put
  1371. * into a lookup table to obtain the approximate cable length
  1372. * for each channel.
  1373. **/
  1374. s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
  1375. {
  1376. struct e1000_phy_info *phy = &hw->phy;
  1377. s32 ret_val;
  1378. u16 phy_data, i, agc_value = 0;
  1379. u16 cur_agc_index, max_agc_index = 0;
  1380. u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
  1381. u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
  1382. {IGP02E1000_PHY_AGC_A,
  1383. IGP02E1000_PHY_AGC_B,
  1384. IGP02E1000_PHY_AGC_C,
  1385. IGP02E1000_PHY_AGC_D};
  1386. /* Read the AGC registers for all channels */
  1387. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  1388. ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
  1389. if (ret_val)
  1390. return ret_val;
  1391. /*
  1392. * Getting bits 15:9, which represent the combination of
  1393. * course and fine gain values. The result is a number
  1394. * that can be put into the lookup table to obtain the
  1395. * approximate cable length.
  1396. */
  1397. cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  1398. IGP02E1000_AGC_LENGTH_MASK;
  1399. /* Array index bound check. */
  1400. if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
  1401. (cur_agc_index == 0))
  1402. return -E1000_ERR_PHY;
  1403. /* Remove min & max AGC values from calculation. */
  1404. if (e1000_igp_2_cable_length_table[min_agc_index] >
  1405. e1000_igp_2_cable_length_table[cur_agc_index])
  1406. min_agc_index = cur_agc_index;
  1407. if (e1000_igp_2_cable_length_table[max_agc_index] <
  1408. e1000_igp_2_cable_length_table[cur_agc_index])
  1409. max_agc_index = cur_agc_index;
  1410. agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
  1411. }
  1412. agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
  1413. e1000_igp_2_cable_length_table[max_agc_index]);
  1414. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  1415. /* Calculate cable length with the error range of +/- 10 meters. */
  1416. phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  1417. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  1418. phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
  1419. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1420. return ret_val;
  1421. }
  1422. /**
  1423. * e1000e_get_phy_info_m88 - Retrieve PHY information
  1424. * @hw: pointer to the HW structure
  1425. *
  1426. * Valid for only copper links. Read the PHY status register (sticky read)
  1427. * to verify that link is up. Read the PHY special control register to
  1428. * determine the polarity and 10base-T extended distance. Read the PHY
  1429. * special status register to determine MDI/MDIx and current speed. If
  1430. * speed is 1000, then determine cable length, local and remote receiver.
  1431. **/
  1432. s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
  1433. {
  1434. struct e1000_phy_info *phy = &hw->phy;
  1435. s32 ret_val;
  1436. u16 phy_data;
  1437. bool link;
  1438. if (hw->phy.media_type != e1000_media_type_copper) {
  1439. hw_dbg(hw, "Phy info is only valid for copper media\n");
  1440. return -E1000_ERR_CONFIG;
  1441. }
  1442. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1443. if (ret_val)
  1444. return ret_val;
  1445. if (!link) {
  1446. hw_dbg(hw, "Phy info is only valid if link is up\n");
  1447. return -E1000_ERR_CONFIG;
  1448. }
  1449. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1450. if (ret_val)
  1451. return ret_val;
  1452. phy->polarity_correction = (phy_data &
  1453. M88E1000_PSCR_POLARITY_REVERSAL);
  1454. ret_val = e1000_check_polarity_m88(hw);
  1455. if (ret_val)
  1456. return ret_val;
  1457. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1458. if (ret_val)
  1459. return ret_val;
  1460. phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);
  1461. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  1462. ret_val = e1000_get_cable_length(hw);
  1463. if (ret_val)
  1464. return ret_val;
  1465. ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
  1466. if (ret_val)
  1467. return ret_val;
  1468. phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
  1469. ? e1000_1000t_rx_status_ok
  1470. : e1000_1000t_rx_status_not_ok;
  1471. phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
  1472. ? e1000_1000t_rx_status_ok
  1473. : e1000_1000t_rx_status_not_ok;
  1474. } else {
  1475. /* Set values to "undefined" */
  1476. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1477. phy->local_rx = e1000_1000t_rx_status_undefined;
  1478. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1479. }
  1480. return ret_val;
  1481. }
  1482. /**
  1483. * e1000e_get_phy_info_igp - Retrieve igp PHY information
  1484. * @hw: pointer to the HW structure
  1485. *
  1486. * Read PHY status to determine if link is up. If link is up, then
  1487. * set/determine 10base-T extended distance and polarity correction. Read
  1488. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  1489. * determine on the cable length, local and remote receiver.
  1490. **/
  1491. s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
  1492. {
  1493. struct e1000_phy_info *phy = &hw->phy;
  1494. s32 ret_val;
  1495. u16 data;
  1496. bool link;
  1497. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1498. if (ret_val)
  1499. return ret_val;
  1500. if (!link) {
  1501. hw_dbg(hw, "Phy info is only valid if link is up\n");
  1502. return -E1000_ERR_CONFIG;
  1503. }
  1504. phy->polarity_correction = 1;
  1505. ret_val = e1000_check_polarity_igp(hw);
  1506. if (ret_val)
  1507. return ret_val;
  1508. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1509. if (ret_val)
  1510. return ret_val;
  1511. phy->is_mdix = (data & IGP01E1000_PSSR_MDIX);
  1512. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1513. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1514. ret_val = e1000_get_cable_length(hw);
  1515. if (ret_val)
  1516. return ret_val;
  1517. ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
  1518. if (ret_val)
  1519. return ret_val;
  1520. phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
  1521. ? e1000_1000t_rx_status_ok
  1522. : e1000_1000t_rx_status_not_ok;
  1523. phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
  1524. ? e1000_1000t_rx_status_ok
  1525. : e1000_1000t_rx_status_not_ok;
  1526. } else {
  1527. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1528. phy->local_rx = e1000_1000t_rx_status_undefined;
  1529. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1530. }
  1531. return ret_val;
  1532. }
  1533. /**
  1534. * e1000e_phy_sw_reset - PHY software reset
  1535. * @hw: pointer to the HW structure
  1536. *
  1537. * Does a software reset of the PHY by reading the PHY control register and
  1538. * setting/write the control register reset bit to the PHY.
  1539. **/
  1540. s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
  1541. {
  1542. s32 ret_val;
  1543. u16 phy_ctrl;
  1544. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
  1545. if (ret_val)
  1546. return ret_val;
  1547. phy_ctrl |= MII_CR_RESET;
  1548. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
  1549. if (ret_val)
  1550. return ret_val;
  1551. udelay(1);
  1552. return ret_val;
  1553. }
  1554. /**
  1555. * e1000e_phy_hw_reset_generic - PHY hardware reset
  1556. * @hw: pointer to the HW structure
  1557. *
  1558. * Verify the reset block is not blocking us from resetting. Acquire
  1559. * semaphore (if necessary) and read/set/write the device control reset
  1560. * bit in the PHY. Wait the appropriate delay time for the device to
  1561. * reset and release the semaphore (if necessary).
  1562. **/
  1563. s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
  1564. {
  1565. struct e1000_phy_info *phy = &hw->phy;
  1566. s32 ret_val;
  1567. u32 ctrl;
  1568. ret_val = e1000_check_reset_block(hw);
  1569. if (ret_val)
  1570. return 0;
  1571. ret_val = phy->ops.acquire_phy(hw);
  1572. if (ret_val)
  1573. return ret_val;
  1574. ctrl = er32(CTRL);
  1575. ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
  1576. e1e_flush();
  1577. udelay(phy->reset_delay_us);
  1578. ew32(CTRL, ctrl);
  1579. e1e_flush();
  1580. udelay(150);
  1581. phy->ops.release_phy(hw);
  1582. return e1000_get_phy_cfg_done(hw);
  1583. }
  1584. /**
  1585. * e1000e_get_cfg_done - Generic configuration done
  1586. * @hw: pointer to the HW structure
  1587. *
  1588. * Generic function to wait 10 milli-seconds for configuration to complete
  1589. * and return success.
  1590. **/
  1591. s32 e1000e_get_cfg_done(struct e1000_hw *hw)
  1592. {
  1593. mdelay(10);
  1594. return 0;
  1595. }
  1596. /**
  1597. * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
  1598. * @hw: pointer to the HW structure
  1599. *
  1600. * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
  1601. **/
  1602. s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
  1603. {
  1604. hw_dbg(hw, "Running IGP 3 PHY init script\n");
  1605. /* PHY init IGP 3 */
  1606. /* Enable rise/fall, 10-mode work in class-A */
  1607. e1e_wphy(hw, 0x2F5B, 0x9018);
  1608. /* Remove all caps from Replica path filter */
  1609. e1e_wphy(hw, 0x2F52, 0x0000);
  1610. /* Bias trimming for ADC, AFE and Driver (Default) */
  1611. e1e_wphy(hw, 0x2FB1, 0x8B24);
  1612. /* Increase Hybrid poly bias */
  1613. e1e_wphy(hw, 0x2FB2, 0xF8F0);
  1614. /* Add 4% to Tx amplitude in Gig mode */
  1615. e1e_wphy(hw, 0x2010, 0x10B0);
  1616. /* Disable trimming (TTT) */
  1617. e1e_wphy(hw, 0x2011, 0x0000);
  1618. /* Poly DC correction to 94.6% + 2% for all channels */
  1619. e1e_wphy(hw, 0x20DD, 0x249A);
  1620. /* ABS DC correction to 95.9% */
  1621. e1e_wphy(hw, 0x20DE, 0x00D3);
  1622. /* BG temp curve trim */
  1623. e1e_wphy(hw, 0x28B4, 0x04CE);
  1624. /* Increasing ADC OPAMP stage 1 currents to max */
  1625. e1e_wphy(hw, 0x2F70, 0x29E4);
  1626. /* Force 1000 ( required for enabling PHY regs configuration) */
  1627. e1e_wphy(hw, 0x0000, 0x0140);
  1628. /* Set upd_freq to 6 */
  1629. e1e_wphy(hw, 0x1F30, 0x1606);
  1630. /* Disable NPDFE */
  1631. e1e_wphy(hw, 0x1F31, 0xB814);
  1632. /* Disable adaptive fixed FFE (Default) */
  1633. e1e_wphy(hw, 0x1F35, 0x002A);
  1634. /* Enable FFE hysteresis */
  1635. e1e_wphy(hw, 0x1F3E, 0x0067);
  1636. /* Fixed FFE for short cable lengths */
  1637. e1e_wphy(hw, 0x1F54, 0x0065);
  1638. /* Fixed FFE for medium cable lengths */
  1639. e1e_wphy(hw, 0x1F55, 0x002A);
  1640. /* Fixed FFE for long cable lengths */
  1641. e1e_wphy(hw, 0x1F56, 0x002A);
  1642. /* Enable Adaptive Clip Threshold */
  1643. e1e_wphy(hw, 0x1F72, 0x3FB0);
  1644. /* AHT reset limit to 1 */
  1645. e1e_wphy(hw, 0x1F76, 0xC0FF);
  1646. /* Set AHT master delay to 127 msec */
  1647. e1e_wphy(hw, 0x1F77, 0x1DEC);
  1648. /* Set scan bits for AHT */
  1649. e1e_wphy(hw, 0x1F78, 0xF9EF);
  1650. /* Set AHT Preset bits */
  1651. e1e_wphy(hw, 0x1F79, 0x0210);
  1652. /* Change integ_factor of channel A to 3 */
  1653. e1e_wphy(hw, 0x1895, 0x0003);
  1654. /* Change prop_factor of channels BCD to 8 */
  1655. e1e_wphy(hw, 0x1796, 0x0008);
  1656. /* Change cg_icount + enable integbp for channels BCD */
  1657. e1e_wphy(hw, 0x1798, 0xD008);
  1658. /*
  1659. * Change cg_icount + enable integbp + change prop_factor_master
  1660. * to 8 for channel A
  1661. */
  1662. e1e_wphy(hw, 0x1898, 0xD918);
  1663. /* Disable AHT in Slave mode on channel A */
  1664. e1e_wphy(hw, 0x187A, 0x0800);
  1665. /*
  1666. * Enable LPLU and disable AN to 1000 in non-D0a states,
  1667. * Enable SPD+B2B
  1668. */
  1669. e1e_wphy(hw, 0x0019, 0x008D);
  1670. /* Enable restart AN on an1000_dis change */
  1671. e1e_wphy(hw, 0x001B, 0x2080);
  1672. /* Enable wh_fifo read clock in 10/100 modes */
  1673. e1e_wphy(hw, 0x0014, 0x0045);
  1674. /* Restart AN, Speed selection is 1000 */
  1675. e1e_wphy(hw, 0x0000, 0x1340);
  1676. return 0;
  1677. }
  1678. /* Internal function pointers */
  1679. /**
  1680. * e1000_get_phy_cfg_done - Generic PHY configuration done
  1681. * @hw: pointer to the HW structure
  1682. *
  1683. * Return success if silicon family did not implement a family specific
  1684. * get_cfg_done function.
  1685. **/
  1686. static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
  1687. {
  1688. if (hw->phy.ops.get_cfg_done)
  1689. return hw->phy.ops.get_cfg_done(hw);
  1690. return 0;
  1691. }
  1692. /**
  1693. * e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
  1694. * @hw: pointer to the HW structure
  1695. *
  1696. * When the silicon family has not implemented a forced speed/duplex
  1697. * function for the PHY, simply return 0.
  1698. **/
  1699. static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1700. {
  1701. if (hw->phy.ops.force_speed_duplex)
  1702. return hw->phy.ops.force_speed_duplex(hw);
  1703. return 0;
  1704. }
  1705. /**
  1706. * e1000e_get_phy_type_from_id - Get PHY type from id
  1707. * @phy_id: phy_id read from the phy
  1708. *
  1709. * Returns the phy type from the id.
  1710. **/
  1711. enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
  1712. {
  1713. enum e1000_phy_type phy_type = e1000_phy_unknown;
  1714. switch (phy_id) {
  1715. case M88E1000_I_PHY_ID:
  1716. case M88E1000_E_PHY_ID:
  1717. case M88E1111_I_PHY_ID:
  1718. case M88E1011_I_PHY_ID:
  1719. phy_type = e1000_phy_m88;
  1720. break;
  1721. case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
  1722. phy_type = e1000_phy_igp_2;
  1723. break;
  1724. case GG82563_E_PHY_ID:
  1725. phy_type = e1000_phy_gg82563;
  1726. break;
  1727. case IGP03E1000_E_PHY_ID:
  1728. phy_type = e1000_phy_igp_3;
  1729. break;
  1730. case IFE_E_PHY_ID:
  1731. case IFE_PLUS_E_PHY_ID:
  1732. case IFE_C_E_PHY_ID:
  1733. phy_type = e1000_phy_ife;
  1734. break;
  1735. case BME1000_E_PHY_ID:
  1736. case BME1000_E_PHY_ID_R2:
  1737. phy_type = e1000_phy_bm;
  1738. break;
  1739. case I82578_E_PHY_ID:
  1740. phy_type = e1000_phy_82578;
  1741. break;
  1742. case I82577_E_PHY_ID:
  1743. phy_type = e1000_phy_82577;
  1744. break;
  1745. default:
  1746. phy_type = e1000_phy_unknown;
  1747. break;
  1748. }
  1749. return phy_type;
  1750. }
  1751. /**
  1752. * e1000e_determine_phy_address - Determines PHY address.
  1753. * @hw: pointer to the HW structure
  1754. *
  1755. * This uses a trial and error method to loop through possible PHY
  1756. * addresses. It tests each by reading the PHY ID registers and
  1757. * checking for a match.
  1758. **/
  1759. s32 e1000e_determine_phy_address(struct e1000_hw *hw)
  1760. {
  1761. s32 ret_val = -E1000_ERR_PHY_TYPE;
  1762. u32 phy_addr= 0;
  1763. u32 i = 0;
  1764. enum e1000_phy_type phy_type = e1000_phy_unknown;
  1765. do {
  1766. for (phy_addr = 0; phy_addr < 4; phy_addr++) {
  1767. hw->phy.addr = phy_addr;
  1768. e1000e_get_phy_id(hw);
  1769. phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
  1770. /*
  1771. * If phy_type is valid, break - we found our
  1772. * PHY address
  1773. */
  1774. if (phy_type != e1000_phy_unknown) {
  1775. ret_val = 0;
  1776. break;
  1777. }
  1778. }
  1779. i++;
  1780. } while ((ret_val != 0) && (i < 100));
  1781. return ret_val;
  1782. }
  1783. /**
  1784. * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
  1785. * @page: page to access
  1786. *
  1787. * Returns the phy address for the page requested.
  1788. **/
  1789. static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
  1790. {
  1791. u32 phy_addr = 2;
  1792. if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
  1793. phy_addr = 1;
  1794. return phy_addr;
  1795. }
  1796. /**
  1797. * e1000e_write_phy_reg_bm - Write BM PHY register
  1798. * @hw: pointer to the HW structure
  1799. * @offset: register offset to write to
  1800. * @data: data to write at register offset
  1801. *
  1802. * Acquires semaphore, if necessary, then writes the data to PHY register
  1803. * at the offset. Release any acquired semaphores before exiting.
  1804. **/
  1805. s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
  1806. {
  1807. s32 ret_val;
  1808. u32 page_select = 0;
  1809. u32 page = offset >> IGP_PAGE_SHIFT;
  1810. u32 page_shift = 0;
  1811. /* Page 800 works differently than the rest so it has its own func */
  1812. if (page == BM_WUC_PAGE) {
  1813. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
  1814. false);
  1815. goto out;
  1816. }
  1817. ret_val = hw->phy.ops.acquire_phy(hw);
  1818. if (ret_val)
  1819. goto out;
  1820. hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
  1821. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  1822. /*
  1823. * Page select is register 31 for phy address 1 and 22 for
  1824. * phy address 2 and 3. Page select is shifted only for
  1825. * phy address 1.
  1826. */
  1827. if (hw->phy.addr == 1) {
  1828. page_shift = IGP_PAGE_SHIFT;
  1829. page_select = IGP01E1000_PHY_PAGE_SELECT;
  1830. } else {
  1831. page_shift = 0;
  1832. page_select = BM_PHY_PAGE_SELECT;
  1833. }
  1834. /* Page is shifted left, PHY expects (page x 32) */
  1835. ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
  1836. (page << page_shift));
  1837. if (ret_val) {
  1838. hw->phy.ops.release_phy(hw);
  1839. goto out;
  1840. }
  1841. }
  1842. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  1843. data);
  1844. hw->phy.ops.release_phy(hw);
  1845. out:
  1846. return ret_val;
  1847. }
  1848. /**
  1849. * e1000e_read_phy_reg_bm - Read BM PHY register
  1850. * @hw: pointer to the HW structure
  1851. * @offset: register offset to be read
  1852. * @data: pointer to the read data
  1853. *
  1854. * Acquires semaphore, if necessary, then reads the PHY register at offset
  1855. * and storing the retrieved information in data. Release any acquired
  1856. * semaphores before exiting.
  1857. **/
  1858. s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
  1859. {
  1860. s32 ret_val;
  1861. u32 page_select = 0;
  1862. u32 page = offset >> IGP_PAGE_SHIFT;
  1863. u32 page_shift = 0;
  1864. /* Page 800 works differently than the rest so it has its own func */
  1865. if (page == BM_WUC_PAGE) {
  1866. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
  1867. true);
  1868. goto out;
  1869. }
  1870. ret_val = hw->phy.ops.acquire_phy(hw);
  1871. if (ret_val)
  1872. goto out;
  1873. hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
  1874. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  1875. /*
  1876. * Page select is register 31 for phy address 1 and 22 for
  1877. * phy address 2 and 3. Page select is shifted only for
  1878. * phy address 1.
  1879. */
  1880. if (hw->phy.addr == 1) {
  1881. page_shift = IGP_PAGE_SHIFT;
  1882. page_select = IGP01E1000_PHY_PAGE_SELECT;
  1883. } else {
  1884. page_shift = 0;
  1885. page_select = BM_PHY_PAGE_SELECT;
  1886. }
  1887. /* Page is shifted left, PHY expects (page x 32) */
  1888. ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
  1889. (page << page_shift));
  1890. if (ret_val) {
  1891. hw->phy.ops.release_phy(hw);
  1892. goto out;
  1893. }
  1894. }
  1895. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  1896. data);
  1897. hw->phy.ops.release_phy(hw);
  1898. out:
  1899. return ret_val;
  1900. }
  1901. /**
  1902. * e1000e_read_phy_reg_bm2 - Read BM PHY register
  1903. * @hw: pointer to the HW structure
  1904. * @offset: register offset to be read
  1905. * @data: pointer to the read data
  1906. *
  1907. * Acquires semaphore, if necessary, then reads the PHY register at offset
  1908. * and storing the retrieved information in data. Release any acquired
  1909. * semaphores before exiting.
  1910. **/
  1911. s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
  1912. {
  1913. s32 ret_val;
  1914. u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
  1915. /* Page 800 works differently than the rest so it has its own func */
  1916. if (page == BM_WUC_PAGE) {
  1917. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
  1918. true);
  1919. return ret_val;
  1920. }
  1921. ret_val = hw->phy.ops.acquire_phy(hw);
  1922. if (ret_val)
  1923. return ret_val;
  1924. hw->phy.addr = 1;
  1925. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  1926. /* Page is shifted left, PHY expects (page x 32) */
  1927. ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
  1928. page);
  1929. if (ret_val) {
  1930. hw->phy.ops.release_phy(hw);
  1931. return ret_val;
  1932. }
  1933. }
  1934. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  1935. data);
  1936. hw->phy.ops.release_phy(hw);
  1937. return ret_val;
  1938. }
  1939. /**
  1940. * e1000e_write_phy_reg_bm2 - Write BM PHY register
  1941. * @hw: pointer to the HW structure
  1942. * @offset: register offset to write to
  1943. * @data: data to write at register offset
  1944. *
  1945. * Acquires semaphore, if necessary, then writes the data to PHY register
  1946. * at the offset. Release any acquired semaphores before exiting.
  1947. **/
  1948. s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
  1949. {
  1950. s32 ret_val;
  1951. u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
  1952. /* Page 800 works differently than the rest so it has its own func */
  1953. if (page == BM_WUC_PAGE) {
  1954. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
  1955. false);
  1956. return ret_val;
  1957. }
  1958. ret_val = hw->phy.ops.acquire_phy(hw);
  1959. if (ret_val)
  1960. return ret_val;
  1961. hw->phy.addr = 1;
  1962. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  1963. /* Page is shifted left, PHY expects (page x 32) */
  1964. ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
  1965. page);
  1966. if (ret_val) {
  1967. hw->phy.ops.release_phy(hw);
  1968. return ret_val;
  1969. }
  1970. }
  1971. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  1972. data);
  1973. hw->phy.ops.release_phy(hw);
  1974. return ret_val;
  1975. }
  1976. /**
  1977. * e1000_access_phy_wakeup_reg_bm - Read BM PHY wakeup register
  1978. * @hw: pointer to the HW structure
  1979. * @offset: register offset to be read or written
  1980. * @data: pointer to the data to read or write
  1981. * @read: determines if operation is read or write
  1982. *
  1983. * Acquires semaphore, if necessary, then reads the PHY register at offset
  1984. * and storing the retrieved information in data. Release any acquired
  1985. * semaphores before exiting. Note that procedure to read the wakeup
  1986. * registers are different. It works as such:
  1987. * 1) Set page 769, register 17, bit 2 = 1
  1988. * 2) Set page to 800 for host (801 if we were manageability)
  1989. * 3) Write the address using the address opcode (0x11)
  1990. * 4) Read or write the data using the data opcode (0x12)
  1991. * 5) Restore 769_17.2 to its original value
  1992. **/
  1993. static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
  1994. u16 *data, bool read)
  1995. {
  1996. s32 ret_val;
  1997. u16 reg = BM_PHY_REG_NUM(offset);
  1998. u16 phy_reg = 0;
  1999. u8 phy_acquired = 1;
  2000. /* Gig must be disabled for MDIO accesses to page 800 */
  2001. if ((hw->mac.type == e1000_pchlan) &&
  2002. (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
  2003. hw_dbg(hw, "Attempting to access page 800 while gig enabled\n");
  2004. ret_val = hw->phy.ops.acquire_phy(hw);
  2005. if (ret_val) {
  2006. phy_acquired = 0;
  2007. goto out;
  2008. }
  2009. /* All operations in this function are phy address 1 */
  2010. hw->phy.addr = 1;
  2011. /* Set page 769 */
  2012. e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  2013. (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
  2014. ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
  2015. if (ret_val)
  2016. goto out;
  2017. /* First clear bit 4 to avoid a power state change */
  2018. phy_reg &= ~(BM_WUC_HOST_WU_BIT);
  2019. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
  2020. if (ret_val)
  2021. goto out;
  2022. /* Write bit 2 = 1, and clear bit 4 to 769_17 */
  2023. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG,
  2024. phy_reg | BM_WUC_ENABLE_BIT);
  2025. if (ret_val)
  2026. goto out;
  2027. /* Select page 800 */
  2028. ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  2029. (BM_WUC_PAGE << IGP_PAGE_SHIFT));
  2030. /* Write the page 800 offset value using opcode 0x11 */
  2031. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
  2032. if (ret_val)
  2033. goto out;
  2034. if (read) {
  2035. /* Read the page 800 value using opcode 0x12 */
  2036. ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
  2037. data);
  2038. } else {
  2039. /* Read the page 800 value using opcode 0x12 */
  2040. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
  2041. *data);
  2042. }
  2043. if (ret_val)
  2044. goto out;
  2045. /*
  2046. * Restore 769_17.2 to its original value
  2047. * Set page 769
  2048. */
  2049. e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  2050. (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
  2051. /* Clear 769_17.2 */
  2052. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
  2053. out:
  2054. if (phy_acquired == 1)
  2055. hw->phy.ops.release_phy(hw);
  2056. return ret_val;
  2057. }
  2058. /**
  2059. * e1000e_commit_phy - Soft PHY reset
  2060. * @hw: pointer to the HW structure
  2061. *
  2062. * Performs a soft PHY reset on those that apply. This is a function pointer
  2063. * entry point called by drivers.
  2064. **/
  2065. s32 e1000e_commit_phy(struct e1000_hw *hw)
  2066. {
  2067. if (hw->phy.ops.commit_phy)
  2068. return hw->phy.ops.commit_phy(hw);
  2069. return 0;
  2070. }
  2071. /**
  2072. * e1000_set_d0_lplu_state - Sets low power link up state for D0
  2073. * @hw: pointer to the HW structure
  2074. * @active: boolean used to enable/disable lplu
  2075. *
  2076. * Success returns 0, Failure returns 1
  2077. *
  2078. * The low power link up (lplu) state is set to the power management level D0
  2079. * and SmartSpeed is disabled when active is true, else clear lplu for D0
  2080. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  2081. * is used during Dx states where the power conservation is most important.
  2082. * During driver activity, SmartSpeed should be enabled so performance is
  2083. * maintained. This is a function pointer entry point called by drivers.
  2084. **/
  2085. static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
  2086. {
  2087. if (hw->phy.ops.set_d0_lplu_state)
  2088. return hw->phy.ops.set_d0_lplu_state(hw, active);
  2089. return 0;
  2090. }
  2091. s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow)
  2092. {
  2093. s32 ret_val = 0;
  2094. u16 data = 0;
  2095. ret_val = hw->phy.ops.acquire_phy(hw);
  2096. if (ret_val)
  2097. return ret_val;
  2098. /* Set MDIO mode - page 769, register 16: 0x2580==slow, 0x2180==fast */
  2099. hw->phy.addr = 1;
  2100. ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  2101. (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
  2102. if (ret_val) {
  2103. hw->phy.ops.release_phy(hw);
  2104. return ret_val;
  2105. }
  2106. ret_val = e1000e_write_phy_reg_mdic(hw, BM_CS_CTRL1,
  2107. (0x2180 | (slow << 10)));
  2108. /* dummy read when reverting to fast mode - throw away result */
  2109. if (!slow)
  2110. e1000e_read_phy_reg_mdic(hw, BM_CS_CTRL1, &data);
  2111. hw->phy.ops.release_phy(hw);
  2112. return ret_val;
  2113. }
  2114. /**
  2115. * e1000_read_phy_reg_hv - Read HV PHY register
  2116. * @hw: pointer to the HW structure
  2117. * @offset: register offset to be read
  2118. * @data: pointer to the read data
  2119. *
  2120. * Acquires semaphore, if necessary, then reads the PHY register at offset
  2121. * and storing the retrieved information in data. Release any acquired
  2122. * semaphore before exiting.
  2123. **/
  2124. s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
  2125. {
  2126. s32 ret_val;
  2127. u16 page = BM_PHY_REG_PAGE(offset);
  2128. u16 reg = BM_PHY_REG_NUM(offset);
  2129. bool in_slow_mode = false;
  2130. /* Workaround failure in MDIO access while cable is disconnected */
  2131. if ((hw->phy.type == e1000_phy_82577) &&
  2132. !(er32(STATUS) & E1000_STATUS_LU)) {
  2133. ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
  2134. if (ret_val)
  2135. goto out;
  2136. in_slow_mode = true;
  2137. }
  2138. /* Page 800 works differently than the rest so it has its own func */
  2139. if (page == BM_WUC_PAGE) {
  2140. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset,
  2141. data, true);
  2142. goto out;
  2143. }
  2144. if (page > 0 && page < HV_INTC_FC_PAGE_START) {
  2145. ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
  2146. data, true);
  2147. goto out;
  2148. }
  2149. ret_val = hw->phy.ops.acquire_phy(hw);
  2150. if (ret_val)
  2151. goto out;
  2152. hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
  2153. if (page == HV_INTC_FC_PAGE_START)
  2154. page = 0;
  2155. if (reg > MAX_PHY_MULTI_PAGE_REG) {
  2156. if ((hw->phy.type != e1000_phy_82578) ||
  2157. ((reg != I82578_ADDR_REG) &&
  2158. (reg != I82578_ADDR_REG + 1))) {
  2159. u32 phy_addr = hw->phy.addr;
  2160. hw->phy.addr = 1;
  2161. /* Page is shifted left, PHY expects (page x 32) */
  2162. ret_val = e1000e_write_phy_reg_mdic(hw,
  2163. IGP01E1000_PHY_PAGE_SELECT,
  2164. (page << IGP_PAGE_SHIFT));
  2165. if (ret_val) {
  2166. hw->phy.ops.release_phy(hw);
  2167. goto out;
  2168. }
  2169. hw->phy.addr = phy_addr;
  2170. }
  2171. }
  2172. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
  2173. data);
  2174. hw->phy.ops.release_phy(hw);
  2175. out:
  2176. /* Revert to MDIO fast mode, if applicable */
  2177. if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
  2178. ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
  2179. return ret_val;
  2180. }
  2181. /**
  2182. * e1000_write_phy_reg_hv - Write HV PHY register
  2183. * @hw: pointer to the HW structure
  2184. * @offset: register offset to write to
  2185. * @data: data to write at register offset
  2186. *
  2187. * Acquires semaphore, if necessary, then writes the data to PHY register
  2188. * at the offset. Release any acquired semaphores before exiting.
  2189. **/
  2190. s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
  2191. {
  2192. s32 ret_val;
  2193. u16 page = BM_PHY_REG_PAGE(offset);
  2194. u16 reg = BM_PHY_REG_NUM(offset);
  2195. bool in_slow_mode = false;
  2196. /* Workaround failure in MDIO access while cable is disconnected */
  2197. if ((hw->phy.type == e1000_phy_82577) &&
  2198. !(er32(STATUS) & E1000_STATUS_LU)) {
  2199. ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
  2200. if (ret_val)
  2201. goto out;
  2202. in_slow_mode = true;
  2203. }
  2204. /* Page 800 works differently than the rest so it has its own func */
  2205. if (page == BM_WUC_PAGE) {
  2206. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset,
  2207. &data, false);
  2208. goto out;
  2209. }
  2210. if (page > 0 && page < HV_INTC_FC_PAGE_START) {
  2211. ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
  2212. &data, false);
  2213. goto out;
  2214. }
  2215. ret_val = hw->phy.ops.acquire_phy(hw);
  2216. if (ret_val)
  2217. goto out;
  2218. hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
  2219. if (page == HV_INTC_FC_PAGE_START)
  2220. page = 0;
  2221. /*
  2222. * Workaround MDIO accesses being disabled after entering IEEE Power
  2223. * Down (whenever bit 11 of the PHY Control register is set)
  2224. */
  2225. if ((hw->phy.type == e1000_phy_82578) &&
  2226. (hw->phy.revision >= 1) &&
  2227. (hw->phy.addr == 2) &&
  2228. ((MAX_PHY_REG_ADDRESS & reg) == 0) &&
  2229. (data & (1 << 11))) {
  2230. u16 data2 = 0x7EFF;
  2231. hw->phy.ops.release_phy(hw);
  2232. ret_val = e1000_access_phy_debug_regs_hv(hw, (1 << 6) | 0x3,
  2233. &data2, false);
  2234. if (ret_val)
  2235. goto out;
  2236. ret_val = hw->phy.ops.acquire_phy(hw);
  2237. if (ret_val)
  2238. goto out;
  2239. }
  2240. if (reg > MAX_PHY_MULTI_PAGE_REG) {
  2241. if ((hw->phy.type != e1000_phy_82578) ||
  2242. ((reg != I82578_ADDR_REG) &&
  2243. (reg != I82578_ADDR_REG + 1))) {
  2244. u32 phy_addr = hw->phy.addr;
  2245. hw->phy.addr = 1;
  2246. /* Page is shifted left, PHY expects (page x 32) */
  2247. ret_val = e1000e_write_phy_reg_mdic(hw,
  2248. IGP01E1000_PHY_PAGE_SELECT,
  2249. (page << IGP_PAGE_SHIFT));
  2250. if (ret_val) {
  2251. hw->phy.ops.release_phy(hw);
  2252. goto out;
  2253. }
  2254. hw->phy.addr = phy_addr;
  2255. }
  2256. }
  2257. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
  2258. data);
  2259. hw->phy.ops.release_phy(hw);
  2260. out:
  2261. /* Revert to MDIO fast mode, if applicable */
  2262. if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
  2263. ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
  2264. return ret_val;
  2265. }
  2266. /**
  2267. * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
  2268. * @page: page to be accessed
  2269. **/
  2270. static u32 e1000_get_phy_addr_for_hv_page(u32 page)
  2271. {
  2272. u32 phy_addr = 2;
  2273. if (page >= HV_INTC_FC_PAGE_START)
  2274. phy_addr = 1;
  2275. return phy_addr;
  2276. }
  2277. /**
  2278. * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
  2279. * @hw: pointer to the HW structure
  2280. * @offset: register offset to be read or written
  2281. * @data: pointer to the data to be read or written
  2282. * @read: determines if operation is read or written
  2283. *
  2284. * Acquires semaphore, if necessary, then reads the PHY register at offset
  2285. * and storing the retreived information in data. Release any acquired
  2286. * semaphores before exiting. Note that the procedure to read these regs
  2287. * uses the address port and data port to read/write.
  2288. **/
  2289. static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
  2290. u16 *data, bool read)
  2291. {
  2292. s32 ret_val;
  2293. u32 addr_reg = 0;
  2294. u32 data_reg = 0;
  2295. u8 phy_acquired = 1;
  2296. /* This takes care of the difference with desktop vs mobile phy */
  2297. addr_reg = (hw->phy.type == e1000_phy_82578) ?
  2298. I82578_ADDR_REG : I82577_ADDR_REG;
  2299. data_reg = addr_reg + 1;
  2300. ret_val = hw->phy.ops.acquire_phy(hw);
  2301. if (ret_val) {
  2302. hw_dbg(hw, "Could not acquire PHY\n");
  2303. phy_acquired = 0;
  2304. goto out;
  2305. }
  2306. /* All operations in this function are phy address 2 */
  2307. hw->phy.addr = 2;
  2308. /* masking with 0x3F to remove the page from offset */
  2309. ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
  2310. if (ret_val) {
  2311. hw_dbg(hw, "Could not write PHY the HV address register\n");
  2312. goto out;
  2313. }
  2314. /* Read or write the data value next */
  2315. if (read)
  2316. ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
  2317. else
  2318. ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
  2319. if (ret_val) {
  2320. hw_dbg(hw, "Could not read data value from HV data register\n");
  2321. goto out;
  2322. }
  2323. out:
  2324. if (phy_acquired == 1)
  2325. hw->phy.ops.release_phy(hw);
  2326. return ret_val;
  2327. }
  2328. /**
  2329. * e1000_link_stall_workaround_hv - Si workaround
  2330. * @hw: pointer to the HW structure
  2331. *
  2332. * This function works around a Si bug where the link partner can get
  2333. * a link up indication before the PHY does. If small packets are sent
  2334. * by the link partner they can be placed in the packet buffer without
  2335. * being properly accounted for by the PHY and will stall preventing
  2336. * further packets from being received. The workaround is to clear the
  2337. * packet buffer after the PHY detects link up.
  2338. **/
  2339. s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
  2340. {
  2341. s32 ret_val = 0;
  2342. u16 data;
  2343. if (hw->phy.type != e1000_phy_82578)
  2344. goto out;
  2345. /* Do not apply workaround if in PHY loopback bit 14 set */
  2346. hw->phy.ops.read_phy_reg(hw, PHY_CONTROL, &data);
  2347. if (data & PHY_CONTROL_LB)
  2348. goto out;
  2349. /* check if link is up and at 1Gbps */
  2350. ret_val = hw->phy.ops.read_phy_reg(hw, BM_CS_STATUS, &data);
  2351. if (ret_val)
  2352. goto out;
  2353. data &= BM_CS_STATUS_LINK_UP |
  2354. BM_CS_STATUS_RESOLVED |
  2355. BM_CS_STATUS_SPEED_MASK;
  2356. if (data != (BM_CS_STATUS_LINK_UP |
  2357. BM_CS_STATUS_RESOLVED |
  2358. BM_CS_STATUS_SPEED_1000))
  2359. goto out;
  2360. mdelay(200);
  2361. /* flush the packets in the fifo buffer */
  2362. ret_val = hw->phy.ops.write_phy_reg(hw, HV_MUX_DATA_CTRL,
  2363. HV_MUX_DATA_CTRL_GEN_TO_MAC |
  2364. HV_MUX_DATA_CTRL_FORCE_SPEED);
  2365. if (ret_val)
  2366. goto out;
  2367. ret_val = hw->phy.ops.write_phy_reg(hw, HV_MUX_DATA_CTRL,
  2368. HV_MUX_DATA_CTRL_GEN_TO_MAC);
  2369. out:
  2370. return ret_val;
  2371. }
  2372. /**
  2373. * e1000_check_polarity_82577 - Checks the polarity.
  2374. * @hw: pointer to the HW structure
  2375. *
  2376. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  2377. *
  2378. * Polarity is determined based on the PHY specific status register.
  2379. **/
  2380. s32 e1000_check_polarity_82577(struct e1000_hw *hw)
  2381. {
  2382. struct e1000_phy_info *phy = &hw->phy;
  2383. s32 ret_val;
  2384. u16 data;
  2385. ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_STATUS_2, &data);
  2386. if (!ret_val)
  2387. phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
  2388. ? e1000_rev_polarity_reversed
  2389. : e1000_rev_polarity_normal;
  2390. return ret_val;
  2391. }
  2392. /**
  2393. * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
  2394. * @hw: pointer to the HW structure
  2395. *
  2396. * Calls the PHY setup function to force speed and duplex. Clears the
  2397. * auto-crossover to force MDI manually. Waits for link and returns
  2398. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  2399. **/
  2400. s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
  2401. {
  2402. struct e1000_phy_info *phy = &hw->phy;
  2403. s32 ret_val;
  2404. u16 phy_data;
  2405. bool link;
  2406. ret_val = phy->ops.read_phy_reg(hw, PHY_CONTROL, &phy_data);
  2407. if (ret_val)
  2408. goto out;
  2409. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  2410. ret_val = phy->ops.write_phy_reg(hw, PHY_CONTROL, phy_data);
  2411. if (ret_val)
  2412. goto out;
  2413. /*
  2414. * Clear Auto-Crossover to force MDI manually. 82577 requires MDI
  2415. * forced whenever speed and duplex are forced.
  2416. */
  2417. ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_CTRL_2, &phy_data);
  2418. if (ret_val)
  2419. goto out;
  2420. phy_data &= ~I82577_PHY_CTRL2_AUTO_MDIX;
  2421. phy_data &= ~I82577_PHY_CTRL2_FORCE_MDI_MDIX;
  2422. ret_val = phy->ops.write_phy_reg(hw, I82577_PHY_CTRL_2, phy_data);
  2423. if (ret_val)
  2424. goto out;
  2425. hw_dbg(hw, "I82577_PHY_CTRL_2: %X\n", phy_data);
  2426. udelay(1);
  2427. if (phy->autoneg_wait_to_complete) {
  2428. hw_dbg(hw, "Waiting for forced speed/duplex link on 82577 phy\n");
  2429. ret_val = e1000e_phy_has_link_generic(hw,
  2430. PHY_FORCE_LIMIT,
  2431. 100000,
  2432. &link);
  2433. if (ret_val)
  2434. goto out;
  2435. if (!link)
  2436. hw_dbg(hw, "Link taking longer than expected.\n");
  2437. /* Try once more */
  2438. ret_val = e1000e_phy_has_link_generic(hw,
  2439. PHY_FORCE_LIMIT,
  2440. 100000,
  2441. &link);
  2442. if (ret_val)
  2443. goto out;
  2444. }
  2445. out:
  2446. return ret_val;
  2447. }
  2448. /**
  2449. * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
  2450. * @hw: pointer to the HW structure
  2451. *
  2452. * Read PHY status to determine if link is up. If link is up, then
  2453. * set/determine 10base-T extended distance and polarity correction. Read
  2454. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  2455. * determine on the cable length, local and remote receiver.
  2456. **/
  2457. s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
  2458. {
  2459. struct e1000_phy_info *phy = &hw->phy;
  2460. s32 ret_val;
  2461. u16 data;
  2462. bool link;
  2463. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  2464. if (ret_val)
  2465. goto out;
  2466. if (!link) {
  2467. hw_dbg(hw, "Phy info is only valid if link is up\n");
  2468. ret_val = -E1000_ERR_CONFIG;
  2469. goto out;
  2470. }
  2471. phy->polarity_correction = true;
  2472. ret_val = e1000_check_polarity_82577(hw);
  2473. if (ret_val)
  2474. goto out;
  2475. ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_STATUS_2, &data);
  2476. if (ret_val)
  2477. goto out;
  2478. phy->is_mdix = (data & I82577_PHY_STATUS2_MDIX) ? true : false;
  2479. if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
  2480. I82577_PHY_STATUS2_SPEED_1000MBPS) {
  2481. ret_val = hw->phy.ops.get_cable_length(hw);
  2482. if (ret_val)
  2483. goto out;
  2484. ret_val = phy->ops.read_phy_reg(hw, PHY_1000T_STATUS, &data);
  2485. if (ret_val)
  2486. goto out;
  2487. phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
  2488. ? e1000_1000t_rx_status_ok
  2489. : e1000_1000t_rx_status_not_ok;
  2490. phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
  2491. ? e1000_1000t_rx_status_ok
  2492. : e1000_1000t_rx_status_not_ok;
  2493. } else {
  2494. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  2495. phy->local_rx = e1000_1000t_rx_status_undefined;
  2496. phy->remote_rx = e1000_1000t_rx_status_undefined;
  2497. }
  2498. out:
  2499. return ret_val;
  2500. }
  2501. /**
  2502. * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
  2503. * @hw: pointer to the HW structure
  2504. *
  2505. * Reads the diagnostic status register and verifies result is valid before
  2506. * placing it in the phy_cable_length field.
  2507. **/
  2508. s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
  2509. {
  2510. struct e1000_phy_info *phy = &hw->phy;
  2511. s32 ret_val;
  2512. u16 phy_data, length;
  2513. ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
  2514. if (ret_val)
  2515. goto out;
  2516. length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
  2517. I82577_DSTATUS_CABLE_LENGTH_SHIFT;
  2518. if (length == E1000_CABLE_LENGTH_UNDEFINED)
  2519. ret_val = E1000_ERR_PHY;
  2520. phy->cable_length = length;
  2521. out:
  2522. return ret_val;
  2523. }