phy.c 90 KB

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