phy.c 87 KB

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