phy.c 85 KB

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