phy.c 90 KB

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