phy.c 87 KB

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