phy.c 90 KB

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