phy.c 85 KB

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