phy.c 85 KB

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