phy.c 88 KB

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