phy.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2013 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "e1000.h"
  22. static s32 e1000_wait_autoneg(struct e1000_hw *hw);
  23. static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
  24. u16 *data, bool read, bool page_set);
  25. static u32 e1000_get_phy_addr_for_hv_page(u32 page);
  26. static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
  27. u16 *data, bool read);
  28. /* Cable length tables */
  29. static const u16 e1000_m88_cable_length_table[] = {
  30. 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
  31. #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
  32. ARRAY_SIZE(e1000_m88_cable_length_table)
  33. static const u16 e1000_igp_2_cable_length_table[] = {
  34. 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
  35. 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
  36. 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
  37. 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
  38. 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
  39. 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
  40. 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
  41. 124};
  42. #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
  43. ARRAY_SIZE(e1000_igp_2_cable_length_table)
  44. /**
  45. * e1000e_check_reset_block_generic - Check if PHY reset is blocked
  46. * @hw: pointer to the HW structure
  47. *
  48. * Read the PHY management control register and check whether a PHY reset
  49. * is blocked. If a reset is not blocked return 0, otherwise
  50. * return E1000_BLK_PHY_RESET (12).
  51. **/
  52. s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
  53. {
  54. u32 manc;
  55. manc = er32(MANC);
  56. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  57. E1000_BLK_PHY_RESET : 0;
  58. }
  59. /**
  60. * e1000e_get_phy_id - Retrieve the PHY ID and revision
  61. * @hw: pointer to the HW structure
  62. *
  63. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  64. * revision in the hardware structure.
  65. **/
  66. s32 e1000e_get_phy_id(struct e1000_hw *hw)
  67. {
  68. struct e1000_phy_info *phy = &hw->phy;
  69. s32 ret_val = 0;
  70. u16 phy_id;
  71. u16 retry_count = 0;
  72. if (!phy->ops.read_reg)
  73. return 0;
  74. while (retry_count < 2) {
  75. ret_val = e1e_rphy(hw, MII_PHYSID1, &phy_id);
  76. if (ret_val)
  77. return ret_val;
  78. phy->id = (u32)(phy_id << 16);
  79. udelay(20);
  80. ret_val = e1e_rphy(hw, MII_PHYSID2, &phy_id);
  81. if (ret_val)
  82. return ret_val;
  83. phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
  84. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  85. if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
  86. return 0;
  87. retry_count++;
  88. }
  89. return 0;
  90. }
  91. /**
  92. * e1000e_phy_reset_dsp - Reset PHY DSP
  93. * @hw: pointer to the HW structure
  94. *
  95. * Reset the digital signal processor.
  96. **/
  97. s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
  98. {
  99. s32 ret_val;
  100. ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
  101. if (ret_val)
  102. return ret_val;
  103. return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
  104. }
  105. /**
  106. * e1000e_read_phy_reg_mdic - Read MDI control register
  107. * @hw: pointer to the HW structure
  108. * @offset: register offset to be read
  109. * @data: pointer to the read data
  110. *
  111. * Reads the MDI control register in the PHY at offset and stores the
  112. * information read to data.
  113. **/
  114. s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
  115. {
  116. struct e1000_phy_info *phy = &hw->phy;
  117. u32 i, mdic = 0;
  118. if (offset > MAX_PHY_REG_ADDRESS) {
  119. e_dbg("PHY Address %d is out of range\n", offset);
  120. return -E1000_ERR_PARAM;
  121. }
  122. /* Set up Op-code, Phy Address, and register offset in the MDI
  123. * Control register. The MAC will take care of interfacing with the
  124. * PHY to retrieve the desired data.
  125. */
  126. mdic = ((offset << E1000_MDIC_REG_SHIFT) |
  127. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  128. (E1000_MDIC_OP_READ));
  129. ew32(MDIC, mdic);
  130. /* Poll the ready bit to see if the MDI read completed
  131. * Increasing the time out as testing showed failures with
  132. * the lower time out
  133. */
  134. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  135. udelay(50);
  136. mdic = er32(MDIC);
  137. if (mdic & E1000_MDIC_READY)
  138. break;
  139. }
  140. if (!(mdic & E1000_MDIC_READY)) {
  141. e_dbg("MDI Read did not complete\n");
  142. return -E1000_ERR_PHY;
  143. }
  144. if (mdic & E1000_MDIC_ERROR) {
  145. e_dbg("MDI Error\n");
  146. return -E1000_ERR_PHY;
  147. }
  148. *data = (u16) mdic;
  149. /* Allow some time after each MDIC transaction to avoid
  150. * reading duplicate data in the next MDIC transaction.
  151. */
  152. if (hw->mac.type == e1000_pch2lan)
  153. udelay(100);
  154. return 0;
  155. }
  156. /**
  157. * e1000e_write_phy_reg_mdic - Write MDI control register
  158. * @hw: pointer to the HW structure
  159. * @offset: register offset to write to
  160. * @data: data to write to register at offset
  161. *
  162. * Writes data to MDI control register in the PHY at offset.
  163. **/
  164. s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
  165. {
  166. struct e1000_phy_info *phy = &hw->phy;
  167. u32 i, mdic = 0;
  168. if (offset > MAX_PHY_REG_ADDRESS) {
  169. e_dbg("PHY Address %d is out of range\n", offset);
  170. return -E1000_ERR_PARAM;
  171. }
  172. /* Set up Op-code, Phy Address, and register offset in the MDI
  173. * Control register. The MAC will take care of interfacing with the
  174. * PHY to retrieve the desired data.
  175. */
  176. mdic = (((u32)data) |
  177. (offset << E1000_MDIC_REG_SHIFT) |
  178. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  179. (E1000_MDIC_OP_WRITE));
  180. ew32(MDIC, mdic);
  181. /* Poll the ready bit to see if the MDI read completed
  182. * Increasing the time out as testing showed failures with
  183. * the lower time out
  184. */
  185. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  186. udelay(50);
  187. mdic = er32(MDIC);
  188. if (mdic & E1000_MDIC_READY)
  189. break;
  190. }
  191. if (!(mdic & E1000_MDIC_READY)) {
  192. e_dbg("MDI Write did not complete\n");
  193. return -E1000_ERR_PHY;
  194. }
  195. if (mdic & E1000_MDIC_ERROR) {
  196. e_dbg("MDI Error\n");
  197. return -E1000_ERR_PHY;
  198. }
  199. /* Allow some time after each MDIC transaction to avoid
  200. * reading duplicate data in the next MDIC transaction.
  201. */
  202. if (hw->mac.type == e1000_pch2lan)
  203. udelay(100);
  204. return 0;
  205. }
  206. /**
  207. * e1000e_read_phy_reg_m88 - Read m88 PHY register
  208. * @hw: pointer to the HW structure
  209. * @offset: register offset to be read
  210. * @data: pointer to the read data
  211. *
  212. * Acquires semaphore, if necessary, then reads the PHY register at offset
  213. * and storing the retrieved information in data. Release any acquired
  214. * semaphores before exiting.
  215. **/
  216. s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
  217. {
  218. s32 ret_val;
  219. ret_val = hw->phy.ops.acquire(hw);
  220. if (ret_val)
  221. return ret_val;
  222. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  223. data);
  224. hw->phy.ops.release(hw);
  225. return ret_val;
  226. }
  227. /**
  228. * e1000e_write_phy_reg_m88 - Write m88 PHY register
  229. * @hw: pointer to the HW structure
  230. * @offset: register offset to write to
  231. * @data: data to write at register offset
  232. *
  233. * Acquires semaphore, if necessary, then writes the data to PHY register
  234. * at the offset. Release any acquired semaphores before exiting.
  235. **/
  236. s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
  237. {
  238. s32 ret_val;
  239. ret_val = hw->phy.ops.acquire(hw);
  240. if (ret_val)
  241. return ret_val;
  242. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  243. data);
  244. hw->phy.ops.release(hw);
  245. return ret_val;
  246. }
  247. /**
  248. * e1000_set_page_igp - Set page as on IGP-like PHY(s)
  249. * @hw: pointer to the HW structure
  250. * @page: page to set (shifted left when necessary)
  251. *
  252. * Sets PHY page required for PHY register access. Assumes semaphore is
  253. * already acquired. Note, this function sets phy.addr to 1 so the caller
  254. * must set it appropriately (if necessary) after this function returns.
  255. **/
  256. s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
  257. {
  258. e_dbg("Setting page 0x%x\n", page);
  259. hw->phy.addr = 1;
  260. return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
  261. }
  262. /**
  263. * __e1000e_read_phy_reg_igp - Read igp PHY register
  264. * @hw: pointer to the HW structure
  265. * @offset: register offset to be read
  266. * @data: pointer to the read data
  267. * @locked: semaphore has already been acquired or not
  268. *
  269. * Acquires semaphore, if necessary, then reads the PHY register at offset
  270. * and stores the retrieved information in data. Release any acquired
  271. * semaphores before exiting.
  272. **/
  273. static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
  274. bool locked)
  275. {
  276. s32 ret_val = 0;
  277. if (!locked) {
  278. if (!hw->phy.ops.acquire)
  279. return 0;
  280. ret_val = hw->phy.ops.acquire(hw);
  281. if (ret_val)
  282. return ret_val;
  283. }
  284. if (offset > MAX_PHY_MULTI_PAGE_REG)
  285. ret_val = e1000e_write_phy_reg_mdic(hw,
  286. IGP01E1000_PHY_PAGE_SELECT,
  287. (u16)offset);
  288. if (!ret_val)
  289. ret_val = e1000e_read_phy_reg_mdic(hw,
  290. MAX_PHY_REG_ADDRESS & offset,
  291. data);
  292. if (!locked)
  293. hw->phy.ops.release(hw);
  294. return ret_val;
  295. }
  296. /**
  297. * e1000e_read_phy_reg_igp - Read igp PHY register
  298. * @hw: pointer to the HW structure
  299. * @offset: register offset to be read
  300. * @data: pointer to the read data
  301. *
  302. * Acquires semaphore then reads the PHY register at offset and stores the
  303. * retrieved information in data.
  304. * Release the acquired semaphore before exiting.
  305. **/
  306. s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
  307. {
  308. return __e1000e_read_phy_reg_igp(hw, offset, data, false);
  309. }
  310. /**
  311. * e1000e_read_phy_reg_igp_locked - Read igp PHY register
  312. * @hw: pointer to the HW structure
  313. * @offset: register offset to be read
  314. * @data: pointer to the read data
  315. *
  316. * Reads the PHY register at offset and stores the retrieved information
  317. * in data. Assumes semaphore already acquired.
  318. **/
  319. s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
  320. {
  321. return __e1000e_read_phy_reg_igp(hw, offset, data, true);
  322. }
  323. /**
  324. * e1000e_write_phy_reg_igp - Write igp PHY register
  325. * @hw: pointer to the HW structure
  326. * @offset: register offset to write to
  327. * @data: data to write at register offset
  328. * @locked: semaphore has already been acquired or not
  329. *
  330. * Acquires semaphore, if necessary, then writes the data to PHY register
  331. * at the offset. Release any acquired semaphores before exiting.
  332. **/
  333. static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
  334. bool locked)
  335. {
  336. s32 ret_val = 0;
  337. if (!locked) {
  338. if (!hw->phy.ops.acquire)
  339. return 0;
  340. ret_val = hw->phy.ops.acquire(hw);
  341. if (ret_val)
  342. return ret_val;
  343. }
  344. if (offset > MAX_PHY_MULTI_PAGE_REG)
  345. ret_val = e1000e_write_phy_reg_mdic(hw,
  346. IGP01E1000_PHY_PAGE_SELECT,
  347. (u16)offset);
  348. if (!ret_val)
  349. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
  350. offset, data);
  351. if (!locked)
  352. hw->phy.ops.release(hw);
  353. return ret_val;
  354. }
  355. /**
  356. * e1000e_write_phy_reg_igp - Write igp PHY register
  357. * @hw: pointer to the HW structure
  358. * @offset: register offset to write to
  359. * @data: data to write at register offset
  360. *
  361. * Acquires semaphore then writes the data to PHY register
  362. * at the offset. Release any acquired semaphores before exiting.
  363. **/
  364. s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
  365. {
  366. return __e1000e_write_phy_reg_igp(hw, offset, data, false);
  367. }
  368. /**
  369. * e1000e_write_phy_reg_igp_locked - Write igp PHY register
  370. * @hw: pointer to the HW structure
  371. * @offset: register offset to write to
  372. * @data: data to write at register offset
  373. *
  374. * Writes the data to PHY register at the offset.
  375. * Assumes semaphore already acquired.
  376. **/
  377. s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
  378. {
  379. return __e1000e_write_phy_reg_igp(hw, offset, data, true);
  380. }
  381. /**
  382. * __e1000_read_kmrn_reg - Read kumeran register
  383. * @hw: pointer to the HW structure
  384. * @offset: register offset to be read
  385. * @data: pointer to the read data
  386. * @locked: semaphore has already been acquired or not
  387. *
  388. * Acquires semaphore, if necessary. Then reads the PHY register at offset
  389. * using the kumeran interface. The information retrieved is stored in data.
  390. * Release any acquired semaphores before exiting.
  391. **/
  392. static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
  393. bool locked)
  394. {
  395. u32 kmrnctrlsta;
  396. if (!locked) {
  397. s32 ret_val = 0;
  398. if (!hw->phy.ops.acquire)
  399. return 0;
  400. ret_val = hw->phy.ops.acquire(hw);
  401. if (ret_val)
  402. return ret_val;
  403. }
  404. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  405. E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
  406. ew32(KMRNCTRLSTA, kmrnctrlsta);
  407. e1e_flush();
  408. udelay(2);
  409. kmrnctrlsta = er32(KMRNCTRLSTA);
  410. *data = (u16)kmrnctrlsta;
  411. if (!locked)
  412. hw->phy.ops.release(hw);
  413. return 0;
  414. }
  415. /**
  416. * e1000e_read_kmrn_reg - Read kumeran register
  417. * @hw: pointer to the HW structure
  418. * @offset: register offset to be read
  419. * @data: pointer to the read data
  420. *
  421. * Acquires semaphore then reads the PHY register at offset using the
  422. * kumeran interface. The information retrieved is stored in data.
  423. * Release the acquired semaphore before exiting.
  424. **/
  425. s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
  426. {
  427. return __e1000_read_kmrn_reg(hw, offset, data, false);
  428. }
  429. /**
  430. * e1000e_read_kmrn_reg_locked - Read kumeran register
  431. * @hw: pointer to the HW structure
  432. * @offset: register offset to be read
  433. * @data: pointer to the read data
  434. *
  435. * Reads the PHY register at offset using the kumeran interface. The
  436. * information retrieved is stored in data.
  437. * Assumes semaphore already acquired.
  438. **/
  439. s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
  440. {
  441. return __e1000_read_kmrn_reg(hw, offset, data, true);
  442. }
  443. /**
  444. * __e1000_write_kmrn_reg - Write kumeran register
  445. * @hw: pointer to the HW structure
  446. * @offset: register offset to write to
  447. * @data: data to write at register offset
  448. * @locked: semaphore has already been acquired or not
  449. *
  450. * Acquires semaphore, if necessary. Then write the data to PHY register
  451. * at the offset using the kumeran interface. Release any acquired semaphores
  452. * before exiting.
  453. **/
  454. static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
  455. bool locked)
  456. {
  457. u32 kmrnctrlsta;
  458. if (!locked) {
  459. s32 ret_val = 0;
  460. if (!hw->phy.ops.acquire)
  461. return 0;
  462. ret_val = hw->phy.ops.acquire(hw);
  463. if (ret_val)
  464. return ret_val;
  465. }
  466. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  467. E1000_KMRNCTRLSTA_OFFSET) | data;
  468. ew32(KMRNCTRLSTA, kmrnctrlsta);
  469. e1e_flush();
  470. udelay(2);
  471. if (!locked)
  472. hw->phy.ops.release(hw);
  473. return 0;
  474. }
  475. /**
  476. * e1000e_write_kmrn_reg - Write kumeran register
  477. * @hw: pointer to the HW structure
  478. * @offset: register offset to write to
  479. * @data: data to write at register offset
  480. *
  481. * Acquires semaphore then writes the data to the PHY register at the offset
  482. * using the kumeran interface. Release the acquired semaphore before exiting.
  483. **/
  484. s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
  485. {
  486. return __e1000_write_kmrn_reg(hw, offset, data, false);
  487. }
  488. /**
  489. * e1000e_write_kmrn_reg_locked - Write kumeran register
  490. * @hw: pointer to the HW structure
  491. * @offset: register offset to write to
  492. * @data: data to write at register offset
  493. *
  494. * Write the data to PHY register at the offset using the kumeran interface.
  495. * Assumes semaphore already acquired.
  496. **/
  497. s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
  498. {
  499. return __e1000_write_kmrn_reg(hw, offset, data, true);
  500. }
  501. /**
  502. * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
  503. * @hw: pointer to the HW structure
  504. *
  505. * Sets up Master/slave mode
  506. **/
  507. static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
  508. {
  509. s32 ret_val;
  510. u16 phy_data;
  511. /* Resolve Master/Slave mode */
  512. ret_val = e1e_rphy(hw, MII_CTRL1000, &phy_data);
  513. if (ret_val)
  514. return ret_val;
  515. /* load defaults for future use */
  516. hw->phy.original_ms_type = (phy_data & CTL1000_ENABLE_MASTER) ?
  517. ((phy_data & CTL1000_AS_MASTER) ?
  518. e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
  519. switch (hw->phy.ms_type) {
  520. case e1000_ms_force_master:
  521. phy_data |= (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
  522. break;
  523. case e1000_ms_force_slave:
  524. phy_data |= CTL1000_ENABLE_MASTER;
  525. phy_data &= ~(CTL1000_AS_MASTER);
  526. break;
  527. case e1000_ms_auto:
  528. phy_data &= ~CTL1000_ENABLE_MASTER;
  529. /* fall-through */
  530. default:
  531. break;
  532. }
  533. return e1e_wphy(hw, MII_CTRL1000, phy_data);
  534. }
  535. /**
  536. * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
  537. * @hw: pointer to the HW structure
  538. *
  539. * Sets up Carrier-sense on Transmit and downshift values.
  540. **/
  541. s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
  542. {
  543. s32 ret_val;
  544. u16 phy_data;
  545. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  546. ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
  547. if (ret_val)
  548. return ret_val;
  549. phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
  550. /* Enable downshift */
  551. phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
  552. ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
  553. if (ret_val)
  554. return ret_val;
  555. /* Set MDI/MDIX mode */
  556. ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
  557. if (ret_val)
  558. return ret_val;
  559. phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
  560. /* Options:
  561. * 0 - Auto (default)
  562. * 1 - MDI mode
  563. * 2 - MDI-X mode
  564. */
  565. switch (hw->phy.mdix) {
  566. case 1:
  567. break;
  568. case 2:
  569. phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
  570. break;
  571. case 0:
  572. default:
  573. phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
  574. break;
  575. }
  576. ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
  577. if (ret_val)
  578. return ret_val;
  579. return e1000_set_master_slave_mode(hw);
  580. }
  581. /**
  582. * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
  583. * @hw: pointer to the HW structure
  584. *
  585. * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
  586. * and downshift values are set also.
  587. **/
  588. s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
  589. {
  590. struct e1000_phy_info *phy = &hw->phy;
  591. s32 ret_val;
  592. u16 phy_data;
  593. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  594. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  595. if (ret_val)
  596. return ret_val;
  597. /* For BM PHY this bit is downshift enable */
  598. if (phy->type != e1000_phy_bm)
  599. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  600. /* Options:
  601. * MDI/MDI-X = 0 (default)
  602. * 0 - Auto for all speeds
  603. * 1 - MDI mode
  604. * 2 - MDI-X mode
  605. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  606. */
  607. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  608. switch (phy->mdix) {
  609. case 1:
  610. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  611. break;
  612. case 2:
  613. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  614. break;
  615. case 3:
  616. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  617. break;
  618. case 0:
  619. default:
  620. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  621. break;
  622. }
  623. /* Options:
  624. * disable_polarity_correction = 0 (default)
  625. * Automatic Correction for Reversed Cable Polarity
  626. * 0 - Disabled
  627. * 1 - Enabled
  628. */
  629. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  630. if (phy->disable_polarity_correction)
  631. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  632. /* Enable downshift on BM (disabled by default) */
  633. if (phy->type == e1000_phy_bm) {
  634. /* For 82574/82583, first disable then enable downshift */
  635. if (phy->id == BME1000_E_PHY_ID_R2) {
  636. phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
  637. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
  638. phy_data);
  639. if (ret_val)
  640. return ret_val;
  641. /* Commit the changes. */
  642. ret_val = phy->ops.commit(hw);
  643. if (ret_val) {
  644. e_dbg("Error committing the PHY changes\n");
  645. return ret_val;
  646. }
  647. }
  648. phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
  649. }
  650. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  651. if (ret_val)
  652. return ret_val;
  653. if ((phy->type == e1000_phy_m88) &&
  654. (phy->revision < E1000_REVISION_4) &&
  655. (phy->id != BME1000_E_PHY_ID_R2)) {
  656. /* Force TX_CLK in the Extended PHY Specific Control Register
  657. * to 25MHz clock.
  658. */
  659. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  660. if (ret_val)
  661. return ret_val;
  662. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  663. if ((phy->revision == 2) &&
  664. (phy->id == M88E1111_I_PHY_ID)) {
  665. /* 82573L PHY - set the downshift counter to 5x. */
  666. phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
  667. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  668. } else {
  669. /* Configure Master and Slave downshift values */
  670. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  671. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  672. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  673. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  674. }
  675. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  676. if (ret_val)
  677. return ret_val;
  678. }
  679. if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
  680. /* Set PHY page 0, register 29 to 0x0003 */
  681. ret_val = e1e_wphy(hw, 29, 0x0003);
  682. if (ret_val)
  683. return ret_val;
  684. /* Set PHY page 0, register 30 to 0x0000 */
  685. ret_val = e1e_wphy(hw, 30, 0x0000);
  686. if (ret_val)
  687. return ret_val;
  688. }
  689. /* Commit the changes. */
  690. if (phy->ops.commit) {
  691. ret_val = phy->ops.commit(hw);
  692. if (ret_val) {
  693. e_dbg("Error committing the PHY changes\n");
  694. return ret_val;
  695. }
  696. }
  697. if (phy->type == e1000_phy_82578) {
  698. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  699. if (ret_val)
  700. return ret_val;
  701. /* 82578 PHY - set the downshift count to 1x. */
  702. phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
  703. phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
  704. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  705. if (ret_val)
  706. return ret_val;
  707. }
  708. return 0;
  709. }
  710. /**
  711. * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
  712. * @hw: pointer to the HW structure
  713. *
  714. * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
  715. * igp PHY's.
  716. **/
  717. s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
  718. {
  719. struct e1000_phy_info *phy = &hw->phy;
  720. s32 ret_val;
  721. u16 data;
  722. ret_val = e1000_phy_hw_reset(hw);
  723. if (ret_val) {
  724. e_dbg("Error resetting the PHY.\n");
  725. return ret_val;
  726. }
  727. /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
  728. * timeout issues when LFS is enabled.
  729. */
  730. msleep(100);
  731. /* disable lplu d0 during driver init */
  732. if (hw->phy.ops.set_d0_lplu_state) {
  733. ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
  734. if (ret_val) {
  735. e_dbg("Error Disabling LPLU D0\n");
  736. return ret_val;
  737. }
  738. }
  739. /* Configure mdi-mdix settings */
  740. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
  741. if (ret_val)
  742. return ret_val;
  743. data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  744. switch (phy->mdix) {
  745. case 1:
  746. data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  747. break;
  748. case 2:
  749. data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  750. break;
  751. case 0:
  752. default:
  753. data |= IGP01E1000_PSCR_AUTO_MDIX;
  754. break;
  755. }
  756. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
  757. if (ret_val)
  758. return ret_val;
  759. /* set auto-master slave resolution settings */
  760. if (hw->mac.autoneg) {
  761. /* when autonegotiation advertisement is only 1000Mbps then we
  762. * should disable SmartSpeed and enable Auto MasterSlave
  763. * resolution as hardware default.
  764. */
  765. if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
  766. /* Disable SmartSpeed */
  767. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  768. &data);
  769. if (ret_val)
  770. return ret_val;
  771. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  772. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  773. data);
  774. if (ret_val)
  775. return ret_val;
  776. /* Set auto Master/Slave resolution process */
  777. ret_val = e1e_rphy(hw, MII_CTRL1000, &data);
  778. if (ret_val)
  779. return ret_val;
  780. data &= ~CTL1000_ENABLE_MASTER;
  781. ret_val = e1e_wphy(hw, MII_CTRL1000, data);
  782. if (ret_val)
  783. return ret_val;
  784. }
  785. ret_val = e1000_set_master_slave_mode(hw);
  786. }
  787. return ret_val;
  788. }
  789. /**
  790. * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
  791. * @hw: pointer to the HW structure
  792. *
  793. * Reads the MII auto-neg advertisement register and/or the 1000T control
  794. * register and if the PHY is already setup for auto-negotiation, then
  795. * return successful. Otherwise, setup advertisement and flow control to
  796. * the appropriate values for the wanted auto-negotiation.
  797. **/
  798. static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
  799. {
  800. struct e1000_phy_info *phy = &hw->phy;
  801. s32 ret_val;
  802. u16 mii_autoneg_adv_reg;
  803. u16 mii_1000t_ctrl_reg = 0;
  804. phy->autoneg_advertised &= phy->autoneg_mask;
  805. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  806. ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_autoneg_adv_reg);
  807. if (ret_val)
  808. return ret_val;
  809. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  810. /* Read the MII 1000Base-T Control Register (Address 9). */
  811. ret_val = e1e_rphy(hw, MII_CTRL1000, &mii_1000t_ctrl_reg);
  812. if (ret_val)
  813. return ret_val;
  814. }
  815. /* Need to parse both autoneg_advertised and fc and set up
  816. * the appropriate PHY registers. First we will parse for
  817. * autoneg_advertised software override. Since we can advertise
  818. * a plethora of combinations, we need to check each bit
  819. * individually.
  820. */
  821. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  822. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  823. * the 1000Base-T Control Register (Address 9).
  824. */
  825. mii_autoneg_adv_reg &= ~(ADVERTISE_100FULL |
  826. ADVERTISE_100HALF |
  827. ADVERTISE_10FULL | ADVERTISE_10HALF);
  828. mii_1000t_ctrl_reg &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
  829. e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
  830. /* Do we want to advertise 10 Mb Half Duplex? */
  831. if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
  832. e_dbg("Advertise 10mb Half duplex\n");
  833. mii_autoneg_adv_reg |= ADVERTISE_10HALF;
  834. }
  835. /* Do we want to advertise 10 Mb Full Duplex? */
  836. if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
  837. e_dbg("Advertise 10mb Full duplex\n");
  838. mii_autoneg_adv_reg |= ADVERTISE_10FULL;
  839. }
  840. /* Do we want to advertise 100 Mb Half Duplex? */
  841. if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
  842. e_dbg("Advertise 100mb Half duplex\n");
  843. mii_autoneg_adv_reg |= ADVERTISE_100HALF;
  844. }
  845. /* Do we want to advertise 100 Mb Full Duplex? */
  846. if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
  847. e_dbg("Advertise 100mb Full duplex\n");
  848. mii_autoneg_adv_reg |= ADVERTISE_100FULL;
  849. }
  850. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  851. if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
  852. e_dbg("Advertise 1000mb Half duplex request denied!\n");
  853. /* Do we want to advertise 1000 Mb Full Duplex? */
  854. if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
  855. e_dbg("Advertise 1000mb Full duplex\n");
  856. mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
  857. }
  858. /* Check for a software override of the flow control settings, and
  859. * setup the PHY advertisement registers accordingly. If
  860. * auto-negotiation is enabled, then software will have to set the
  861. * "PAUSE" bits to the correct value in the Auto-Negotiation
  862. * Advertisement Register (MII_ADVERTISE) and re-start auto-
  863. * negotiation.
  864. *
  865. * The possible values of the "fc" parameter are:
  866. * 0: Flow control is completely disabled
  867. * 1: Rx flow control is enabled (we can receive pause frames
  868. * but not send pause frames).
  869. * 2: Tx flow control is enabled (we can send pause frames
  870. * but we do not support receiving pause frames).
  871. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  872. * other: No software override. The flow control configuration
  873. * in the EEPROM is used.
  874. */
  875. switch (hw->fc.current_mode) {
  876. case e1000_fc_none:
  877. /* Flow control (Rx & Tx) is completely disabled by a
  878. * software over-ride.
  879. */
  880. mii_autoneg_adv_reg &=
  881. ~(ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  882. break;
  883. case e1000_fc_rx_pause:
  884. /* Rx Flow control is enabled, and Tx Flow control is
  885. * disabled, by a software over-ride.
  886. *
  887. * Since there really isn't a way to advertise that we are
  888. * capable of Rx Pause ONLY, we will advertise that we
  889. * support both symmetric and asymmetric Rx PAUSE. Later
  890. * (in e1000e_config_fc_after_link_up) we will disable the
  891. * hw's ability to send PAUSE frames.
  892. */
  893. mii_autoneg_adv_reg |=
  894. (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  895. break;
  896. case e1000_fc_tx_pause:
  897. /* Tx Flow control is enabled, and Rx Flow control is
  898. * disabled, by a software over-ride.
  899. */
  900. mii_autoneg_adv_reg |= ADVERTISE_PAUSE_ASYM;
  901. mii_autoneg_adv_reg &= ~ADVERTISE_PAUSE_CAP;
  902. break;
  903. case e1000_fc_full:
  904. /* Flow control (both Rx and Tx) is enabled by a software
  905. * over-ride.
  906. */
  907. mii_autoneg_adv_reg |=
  908. (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  909. break;
  910. default:
  911. e_dbg("Flow control param set incorrectly\n");
  912. return -E1000_ERR_CONFIG;
  913. }
  914. ret_val = e1e_wphy(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
  915. if (ret_val)
  916. return ret_val;
  917. e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  918. if (phy->autoneg_mask & ADVERTISE_1000_FULL)
  919. ret_val = e1e_wphy(hw, MII_CTRL1000, mii_1000t_ctrl_reg);
  920. return ret_val;
  921. }
  922. /**
  923. * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
  924. * @hw: pointer to the HW structure
  925. *
  926. * Performs initial bounds checking on autoneg advertisement parameter, then
  927. * configure to advertise the full capability. Setup the PHY to autoneg
  928. * and restart the negotiation process between the link partner. If
  929. * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
  930. **/
  931. static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
  932. {
  933. struct e1000_phy_info *phy = &hw->phy;
  934. s32 ret_val;
  935. u16 phy_ctrl;
  936. /* Perform some bounds checking on the autoneg advertisement
  937. * parameter.
  938. */
  939. phy->autoneg_advertised &= phy->autoneg_mask;
  940. /* If autoneg_advertised is zero, we assume it was not defaulted
  941. * by the calling code so we set to advertise full capability.
  942. */
  943. if (!phy->autoneg_advertised)
  944. phy->autoneg_advertised = phy->autoneg_mask;
  945. e_dbg("Reconfiguring auto-neg advertisement params\n");
  946. ret_val = e1000_phy_setup_autoneg(hw);
  947. if (ret_val) {
  948. e_dbg("Error Setting up Auto-Negotiation\n");
  949. return ret_val;
  950. }
  951. e_dbg("Restarting Auto-Neg\n");
  952. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  953. * the Auto Neg Restart bit in the PHY control register.
  954. */
  955. ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
  956. if (ret_val)
  957. return ret_val;
  958. phy_ctrl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  959. ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
  960. if (ret_val)
  961. return ret_val;
  962. /* Does the user want to wait for Auto-Neg to complete here, or
  963. * check at a later time (for example, callback routine).
  964. */
  965. if (phy->autoneg_wait_to_complete) {
  966. ret_val = e1000_wait_autoneg(hw);
  967. if (ret_val) {
  968. e_dbg("Error while waiting for autoneg to complete\n");
  969. return ret_val;
  970. }
  971. }
  972. hw->mac.get_link_status = true;
  973. return ret_val;
  974. }
  975. /**
  976. * e1000e_setup_copper_link - Configure copper link settings
  977. * @hw: pointer to the HW structure
  978. *
  979. * Calls the appropriate function to configure the link for auto-neg or forced
  980. * speed and duplex. Then we check for link, once link is established calls
  981. * to configure collision distance and flow control are called. If link is
  982. * not established, we return -E1000_ERR_PHY (-2).
  983. **/
  984. s32 e1000e_setup_copper_link(struct e1000_hw *hw)
  985. {
  986. s32 ret_val;
  987. bool link;
  988. if (hw->mac.autoneg) {
  989. /* Setup autoneg and flow control advertisement and perform
  990. * autonegotiation.
  991. */
  992. ret_val = e1000_copper_link_autoneg(hw);
  993. if (ret_val)
  994. return ret_val;
  995. } else {
  996. /* PHY will be set to 10H, 10F, 100H or 100F
  997. * depending on user settings.
  998. */
  999. e_dbg("Forcing Speed and Duplex\n");
  1000. ret_val = hw->phy.ops.force_speed_duplex(hw);
  1001. if (ret_val) {
  1002. e_dbg("Error Forcing Speed and Duplex\n");
  1003. return ret_val;
  1004. }
  1005. }
  1006. /* Check link status. Wait up to 100 microseconds for link to become
  1007. * valid.
  1008. */
  1009. ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
  1010. &link);
  1011. if (ret_val)
  1012. return ret_val;
  1013. if (link) {
  1014. e_dbg("Valid link established!!!\n");
  1015. hw->mac.ops.config_collision_dist(hw);
  1016. ret_val = e1000e_config_fc_after_link_up(hw);
  1017. } else {
  1018. e_dbg("Unable to establish link!!!\n");
  1019. }
  1020. return ret_val;
  1021. }
  1022. /**
  1023. * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
  1024. * @hw: pointer to the HW structure
  1025. *
  1026. * Calls the PHY setup function to force speed and duplex. Clears the
  1027. * auto-crossover to force MDI manually. Waits for link and returns
  1028. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  1029. **/
  1030. s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
  1031. {
  1032. struct e1000_phy_info *phy = &hw->phy;
  1033. s32 ret_val;
  1034. u16 phy_data;
  1035. bool link;
  1036. ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
  1037. if (ret_val)
  1038. return ret_val;
  1039. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  1040. ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
  1041. if (ret_val)
  1042. return ret_val;
  1043. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1044. * forced whenever speed and duplex are forced.
  1045. */
  1046. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1047. if (ret_val)
  1048. return ret_val;
  1049. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1050. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1051. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1052. if (ret_val)
  1053. return ret_val;
  1054. e_dbg("IGP PSCR: %X\n", phy_data);
  1055. udelay(1);
  1056. if (phy->autoneg_wait_to_complete) {
  1057. e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
  1058. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1059. 100000, &link);
  1060. if (ret_val)
  1061. return ret_val;
  1062. if (!link)
  1063. e_dbg("Link taking longer than expected.\n");
  1064. /* Try once more */
  1065. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1066. 100000, &link);
  1067. }
  1068. return ret_val;
  1069. }
  1070. /**
  1071. * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
  1072. * @hw: pointer to the HW structure
  1073. *
  1074. * Calls the PHY setup function to force speed and duplex. Clears the
  1075. * auto-crossover to force MDI manually. Resets the PHY to commit the
  1076. * changes. If time expires while waiting for link up, we reset the DSP.
  1077. * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
  1078. * successful completion, else return corresponding error code.
  1079. **/
  1080. s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
  1081. {
  1082. struct e1000_phy_info *phy = &hw->phy;
  1083. s32 ret_val;
  1084. u16 phy_data;
  1085. bool link;
  1086. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  1087. * forced whenever speed and duplex are forced.
  1088. */
  1089. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1090. if (ret_val)
  1091. return ret_val;
  1092. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1093. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1094. if (ret_val)
  1095. return ret_val;
  1096. e_dbg("M88E1000 PSCR: %X\n", phy_data);
  1097. ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
  1098. if (ret_val)
  1099. return ret_val;
  1100. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  1101. ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
  1102. if (ret_val)
  1103. return ret_val;
  1104. /* Reset the phy to commit changes. */
  1105. if (hw->phy.ops.commit) {
  1106. ret_val = hw->phy.ops.commit(hw);
  1107. if (ret_val)
  1108. return ret_val;
  1109. }
  1110. if (phy->autoneg_wait_to_complete) {
  1111. e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
  1112. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1113. 100000, &link);
  1114. if (ret_val)
  1115. return ret_val;
  1116. if (!link) {
  1117. if (hw->phy.type != e1000_phy_m88) {
  1118. e_dbg("Link taking longer than expected.\n");
  1119. } else {
  1120. /* We didn't get link.
  1121. * Reset the DSP and cross our fingers.
  1122. */
  1123. ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
  1124. 0x001d);
  1125. if (ret_val)
  1126. return ret_val;
  1127. ret_val = e1000e_phy_reset_dsp(hw);
  1128. if (ret_val)
  1129. return ret_val;
  1130. }
  1131. }
  1132. /* Try once more */
  1133. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1134. 100000, &link);
  1135. if (ret_val)
  1136. return ret_val;
  1137. }
  1138. if (hw->phy.type != e1000_phy_m88)
  1139. return 0;
  1140. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1141. if (ret_val)
  1142. return ret_val;
  1143. /* Resetting the phy means we need to re-force TX_CLK in the
  1144. * Extended PHY Specific Control Register to 25MHz clock from
  1145. * the reset value of 2.5MHz.
  1146. */
  1147. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1148. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1149. if (ret_val)
  1150. return ret_val;
  1151. /* In addition, we must re-enable CRS on Tx for both half and full
  1152. * duplex.
  1153. */
  1154. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1155. if (ret_val)
  1156. return ret_val;
  1157. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1158. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1159. return ret_val;
  1160. }
  1161. /**
  1162. * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
  1163. * @hw: pointer to the HW structure
  1164. *
  1165. * Forces the speed and duplex settings of the PHY.
  1166. * This is a function pointer entry point only called by
  1167. * PHY setup routines.
  1168. **/
  1169. s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
  1170. {
  1171. struct e1000_phy_info *phy = &hw->phy;
  1172. s32 ret_val;
  1173. u16 data;
  1174. bool link;
  1175. ret_val = e1e_rphy(hw, MII_BMCR, &data);
  1176. if (ret_val)
  1177. return ret_val;
  1178. e1000e_phy_force_speed_duplex_setup(hw, &data);
  1179. ret_val = e1e_wphy(hw, MII_BMCR, data);
  1180. if (ret_val)
  1181. return ret_val;
  1182. /* Disable MDI-X support for 10/100 */
  1183. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
  1184. if (ret_val)
  1185. return ret_val;
  1186. data &= ~IFE_PMC_AUTO_MDIX;
  1187. data &= ~IFE_PMC_FORCE_MDIX;
  1188. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
  1189. if (ret_val)
  1190. return ret_val;
  1191. e_dbg("IFE PMC: %X\n", data);
  1192. udelay(1);
  1193. if (phy->autoneg_wait_to_complete) {
  1194. e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
  1195. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1196. 100000, &link);
  1197. if (ret_val)
  1198. return ret_val;
  1199. if (!link)
  1200. e_dbg("Link taking longer than expected.\n");
  1201. /* Try once more */
  1202. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1203. 100000, &link);
  1204. if (ret_val)
  1205. return ret_val;
  1206. }
  1207. return 0;
  1208. }
  1209. /**
  1210. * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
  1211. * @hw: pointer to the HW structure
  1212. * @phy_ctrl: pointer to current value of MII_BMCR
  1213. *
  1214. * Forces speed and duplex on the PHY by doing the following: disable flow
  1215. * control, force speed/duplex on the MAC, disable auto speed detection,
  1216. * disable auto-negotiation, configure duplex, configure speed, configure
  1217. * the collision distance, write configuration to CTRL register. The
  1218. * caller must write to the MII_BMCR register for these settings to
  1219. * take affect.
  1220. **/
  1221. void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
  1222. {
  1223. struct e1000_mac_info *mac = &hw->mac;
  1224. u32 ctrl;
  1225. /* Turn off flow control when forcing speed/duplex */
  1226. hw->fc.current_mode = e1000_fc_none;
  1227. /* Force speed/duplex on the mac */
  1228. ctrl = er32(CTRL);
  1229. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1230. ctrl &= ~E1000_CTRL_SPD_SEL;
  1231. /* Disable Auto Speed Detection */
  1232. ctrl &= ~E1000_CTRL_ASDE;
  1233. /* Disable autoneg on the phy */
  1234. *phy_ctrl &= ~BMCR_ANENABLE;
  1235. /* Forcing Full or Half Duplex? */
  1236. if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
  1237. ctrl &= ~E1000_CTRL_FD;
  1238. *phy_ctrl &= ~BMCR_FULLDPLX;
  1239. e_dbg("Half Duplex\n");
  1240. } else {
  1241. ctrl |= E1000_CTRL_FD;
  1242. *phy_ctrl |= BMCR_FULLDPLX;
  1243. e_dbg("Full Duplex\n");
  1244. }
  1245. /* Forcing 10mb or 100mb? */
  1246. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
  1247. ctrl |= E1000_CTRL_SPD_100;
  1248. *phy_ctrl |= BMCR_SPEED100;
  1249. *phy_ctrl &= ~BMCR_SPEED1000;
  1250. e_dbg("Forcing 100mb\n");
  1251. } else {
  1252. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1253. *phy_ctrl &= ~(BMCR_SPEED1000 | BMCR_SPEED100);
  1254. e_dbg("Forcing 10mb\n");
  1255. }
  1256. hw->mac.ops.config_collision_dist(hw);
  1257. ew32(CTRL, ctrl);
  1258. }
  1259. /**
  1260. * e1000e_set_d3_lplu_state - Sets low power link up state for D3
  1261. * @hw: pointer to the HW structure
  1262. * @active: boolean used to enable/disable lplu
  1263. *
  1264. * Success returns 0, Failure returns 1
  1265. *
  1266. * The low power link up (lplu) state is set to the power management level D3
  1267. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  1268. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  1269. * is used during Dx states where the power conservation is most important.
  1270. * During driver activity, SmartSpeed should be enabled so performance is
  1271. * maintained.
  1272. **/
  1273. s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  1274. {
  1275. struct e1000_phy_info *phy = &hw->phy;
  1276. s32 ret_val;
  1277. u16 data;
  1278. ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  1279. if (ret_val)
  1280. return ret_val;
  1281. if (!active) {
  1282. data &= ~IGP02E1000_PM_D3_LPLU;
  1283. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1284. if (ret_val)
  1285. return ret_val;
  1286. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  1287. * during Dx states where the power conservation is most
  1288. * important. During driver activity we should enable
  1289. * SmartSpeed, so performance is maintained.
  1290. */
  1291. if (phy->smart_speed == e1000_smart_speed_on) {
  1292. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1293. &data);
  1294. if (ret_val)
  1295. return ret_val;
  1296. data |= IGP01E1000_PSCFR_SMART_SPEED;
  1297. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1298. data);
  1299. if (ret_val)
  1300. return ret_val;
  1301. } else if (phy->smart_speed == e1000_smart_speed_off) {
  1302. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1303. &data);
  1304. if (ret_val)
  1305. return ret_val;
  1306. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1307. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1308. data);
  1309. if (ret_val)
  1310. return ret_val;
  1311. }
  1312. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  1313. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  1314. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  1315. data |= IGP02E1000_PM_D3_LPLU;
  1316. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1317. if (ret_val)
  1318. return ret_val;
  1319. /* When LPLU is enabled, we should disable SmartSpeed */
  1320. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  1321. if (ret_val)
  1322. return ret_val;
  1323. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1324. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  1325. }
  1326. return ret_val;
  1327. }
  1328. /**
  1329. * e1000e_check_downshift - Checks whether a downshift in speed occurred
  1330. * @hw: pointer to the HW structure
  1331. *
  1332. * Success returns 0, Failure returns 1
  1333. *
  1334. * A downshift is detected by querying the PHY link health.
  1335. **/
  1336. s32 e1000e_check_downshift(struct e1000_hw *hw)
  1337. {
  1338. struct e1000_phy_info *phy = &hw->phy;
  1339. s32 ret_val;
  1340. u16 phy_data, offset, mask;
  1341. switch (phy->type) {
  1342. case e1000_phy_m88:
  1343. case e1000_phy_gg82563:
  1344. case e1000_phy_bm:
  1345. case e1000_phy_82578:
  1346. offset = M88E1000_PHY_SPEC_STATUS;
  1347. mask = M88E1000_PSSR_DOWNSHIFT;
  1348. break;
  1349. case e1000_phy_igp_2:
  1350. case e1000_phy_igp_3:
  1351. offset = IGP01E1000_PHY_LINK_HEALTH;
  1352. mask = IGP01E1000_PLHR_SS_DOWNGRADE;
  1353. break;
  1354. default:
  1355. /* speed downshift not supported */
  1356. phy->speed_downgraded = false;
  1357. return 0;
  1358. }
  1359. ret_val = e1e_rphy(hw, offset, &phy_data);
  1360. if (!ret_val)
  1361. phy->speed_downgraded = !!(phy_data & mask);
  1362. return ret_val;
  1363. }
  1364. /**
  1365. * e1000_check_polarity_m88 - Checks the polarity.
  1366. * @hw: pointer to the HW structure
  1367. *
  1368. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1369. *
  1370. * Polarity is determined based on the PHY specific status register.
  1371. **/
  1372. s32 e1000_check_polarity_m88(struct e1000_hw *hw)
  1373. {
  1374. struct e1000_phy_info *phy = &hw->phy;
  1375. s32 ret_val;
  1376. u16 data;
  1377. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
  1378. if (!ret_val)
  1379. phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
  1380. ? e1000_rev_polarity_reversed
  1381. : e1000_rev_polarity_normal);
  1382. return ret_val;
  1383. }
  1384. /**
  1385. * e1000_check_polarity_igp - Checks the polarity.
  1386. * @hw: pointer to the HW structure
  1387. *
  1388. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1389. *
  1390. * Polarity is determined based on the PHY port status register, and the
  1391. * current speed (since there is no polarity at 100Mbps).
  1392. **/
  1393. s32 e1000_check_polarity_igp(struct e1000_hw *hw)
  1394. {
  1395. struct e1000_phy_info *phy = &hw->phy;
  1396. s32 ret_val;
  1397. u16 data, offset, mask;
  1398. /* Polarity is determined based on the speed of
  1399. * our connection.
  1400. */
  1401. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1402. if (ret_val)
  1403. return ret_val;
  1404. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1405. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1406. offset = IGP01E1000_PHY_PCS_INIT_REG;
  1407. mask = IGP01E1000_PHY_POLARITY_MASK;
  1408. } else {
  1409. /* This really only applies to 10Mbps since
  1410. * there is no polarity for 100Mbps (always 0).
  1411. */
  1412. offset = IGP01E1000_PHY_PORT_STATUS;
  1413. mask = IGP01E1000_PSSR_POLARITY_REVERSED;
  1414. }
  1415. ret_val = e1e_rphy(hw, offset, &data);
  1416. if (!ret_val)
  1417. phy->cable_polarity = ((data & mask)
  1418. ? e1000_rev_polarity_reversed
  1419. : e1000_rev_polarity_normal);
  1420. return ret_val;
  1421. }
  1422. /**
  1423. * e1000_check_polarity_ife - Check cable polarity for IFE PHY
  1424. * @hw: pointer to the HW structure
  1425. *
  1426. * Polarity is determined on the polarity reversal feature being enabled.
  1427. **/
  1428. s32 e1000_check_polarity_ife(struct e1000_hw *hw)
  1429. {
  1430. struct e1000_phy_info *phy = &hw->phy;
  1431. s32 ret_val;
  1432. u16 phy_data, offset, mask;
  1433. /* Polarity is determined based on the reversal feature being enabled.
  1434. */
  1435. if (phy->polarity_correction) {
  1436. offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
  1437. mask = IFE_PESC_POLARITY_REVERSED;
  1438. } else {
  1439. offset = IFE_PHY_SPECIAL_CONTROL;
  1440. mask = IFE_PSC_FORCE_POLARITY;
  1441. }
  1442. ret_val = e1e_rphy(hw, offset, &phy_data);
  1443. if (!ret_val)
  1444. phy->cable_polarity = ((phy_data & mask)
  1445. ? e1000_rev_polarity_reversed
  1446. : e1000_rev_polarity_normal);
  1447. return ret_val;
  1448. }
  1449. /**
  1450. * e1000_wait_autoneg - Wait for auto-neg completion
  1451. * @hw: pointer to the HW structure
  1452. *
  1453. * Waits for auto-negotiation to complete or for the auto-negotiation time
  1454. * limit to expire, which ever happens first.
  1455. **/
  1456. static s32 e1000_wait_autoneg(struct e1000_hw *hw)
  1457. {
  1458. s32 ret_val = 0;
  1459. u16 i, phy_status;
  1460. /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
  1461. for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
  1462. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1463. if (ret_val)
  1464. break;
  1465. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1466. if (ret_val)
  1467. break;
  1468. if (phy_status & BMSR_ANEGCOMPLETE)
  1469. break;
  1470. msleep(100);
  1471. }
  1472. /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
  1473. * has completed.
  1474. */
  1475. return ret_val;
  1476. }
  1477. /**
  1478. * e1000e_phy_has_link_generic - Polls PHY for link
  1479. * @hw: pointer to the HW structure
  1480. * @iterations: number of times to poll for link
  1481. * @usec_interval: delay between polling attempts
  1482. * @success: pointer to whether polling was successful or not
  1483. *
  1484. * Polls the PHY status register for link, 'iterations' number of times.
  1485. **/
  1486. s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
  1487. u32 usec_interval, bool *success)
  1488. {
  1489. s32 ret_val = 0;
  1490. u16 i, phy_status;
  1491. for (i = 0; i < iterations; i++) {
  1492. /* Some PHYs require the MII_BMSR register to be read
  1493. * twice due to the link bit being sticky. No harm doing
  1494. * it across the board.
  1495. */
  1496. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1497. if (ret_val)
  1498. /* If the first read fails, another entity may have
  1499. * ownership of the resources, wait and try again to
  1500. * see if they have relinquished the resources yet.
  1501. */
  1502. udelay(usec_interval);
  1503. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1504. if (ret_val)
  1505. break;
  1506. if (phy_status & BMSR_LSTATUS)
  1507. break;
  1508. if (usec_interval >= 1000)
  1509. mdelay(usec_interval / 1000);
  1510. else
  1511. udelay(usec_interval);
  1512. }
  1513. *success = (i < iterations);
  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. udelay(150);
  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. *
  1989. * Returns the phy address for the page requested.
  1990. **/
  1991. static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
  1992. {
  1993. u32 phy_addr = 2;
  1994. if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
  1995. phy_addr = 1;
  1996. return phy_addr;
  1997. }
  1998. /**
  1999. * e1000e_write_phy_reg_bm - Write BM PHY register
  2000. * @hw: pointer to the HW structure
  2001. * @offset: register offset to write to
  2002. * @data: data to write at register offset
  2003. *
  2004. * Acquires semaphore, if necessary, then writes the data to PHY register
  2005. * at the offset. Release any acquired semaphores before exiting.
  2006. **/
  2007. s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
  2008. {
  2009. s32 ret_val;
  2010. u32 page = offset >> IGP_PAGE_SHIFT;
  2011. ret_val = hw->phy.ops.acquire(hw);
  2012. if (ret_val)
  2013. return ret_val;
  2014. /* Page 800 works differently than the rest so it has its own func */
  2015. if (page == BM_WUC_PAGE) {
  2016. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
  2017. false, false);
  2018. goto release;
  2019. }
  2020. hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
  2021. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  2022. u32 page_shift, page_select;
  2023. /* Page select is register 31 for phy address 1 and 22 for
  2024. * phy address 2 and 3. Page select is shifted only for
  2025. * phy address 1.
  2026. */
  2027. if (hw->phy.addr == 1) {
  2028. page_shift = IGP_PAGE_SHIFT;
  2029. page_select = IGP01E1000_PHY_PAGE_SELECT;
  2030. } else {
  2031. page_shift = 0;
  2032. page_select = BM_PHY_PAGE_SELECT;
  2033. }
  2034. /* Page is shifted left, PHY expects (page x 32) */
  2035. ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
  2036. (page << page_shift));
  2037. if (ret_val)
  2038. goto release;
  2039. }
  2040. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  2041. data);
  2042. release:
  2043. hw->phy.ops.release(hw);
  2044. return ret_val;
  2045. }
  2046. /**
  2047. * e1000e_read_phy_reg_bm - Read BM PHY register
  2048. * @hw: pointer to the HW structure
  2049. * @offset: register offset to be read
  2050. * @data: pointer to the read data
  2051. *
  2052. * Acquires semaphore, if necessary, then reads the PHY register at offset
  2053. * and storing the retrieved information in data. Release any acquired
  2054. * semaphores before exiting.
  2055. **/
  2056. s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
  2057. {
  2058. s32 ret_val;
  2059. u32 page = offset >> IGP_PAGE_SHIFT;
  2060. ret_val = hw->phy.ops.acquire(hw);
  2061. if (ret_val)
  2062. return ret_val;
  2063. /* Page 800 works differently than the rest so it has its own func */
  2064. if (page == BM_WUC_PAGE) {
  2065. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
  2066. true, false);
  2067. goto release;
  2068. }
  2069. hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
  2070. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  2071. u32 page_shift, page_select;
  2072. /* Page select is register 31 for phy address 1 and 22 for
  2073. * phy address 2 and 3. Page select is shifted only for
  2074. * phy address 1.
  2075. */
  2076. if (hw->phy.addr == 1) {
  2077. page_shift = IGP_PAGE_SHIFT;
  2078. page_select = IGP01E1000_PHY_PAGE_SELECT;
  2079. } else {
  2080. page_shift = 0;
  2081. page_select = BM_PHY_PAGE_SELECT;
  2082. }
  2083. /* Page is shifted left, PHY expects (page x 32) */
  2084. ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
  2085. (page << page_shift));
  2086. if (ret_val)
  2087. goto release;
  2088. }
  2089. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  2090. data);
  2091. release:
  2092. hw->phy.ops.release(hw);
  2093. return ret_val;
  2094. }
  2095. /**
  2096. * e1000e_read_phy_reg_bm2 - Read BM PHY register
  2097. * @hw: pointer to the HW structure
  2098. * @offset: register offset to be read
  2099. * @data: pointer to the read data
  2100. *
  2101. * Acquires semaphore, if necessary, then reads the PHY register at offset
  2102. * and storing the retrieved information in data. Release any acquired
  2103. * semaphores before exiting.
  2104. **/
  2105. s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
  2106. {
  2107. s32 ret_val;
  2108. u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
  2109. ret_val = hw->phy.ops.acquire(hw);
  2110. if (ret_val)
  2111. return ret_val;
  2112. /* Page 800 works differently than the rest so it has its own func */
  2113. if (page == BM_WUC_PAGE) {
  2114. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
  2115. true, false);
  2116. goto release;
  2117. }
  2118. hw->phy.addr = 1;
  2119. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  2120. /* Page is shifted left, PHY expects (page x 32) */
  2121. ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
  2122. page);
  2123. if (ret_val)
  2124. goto release;
  2125. }
  2126. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  2127. data);
  2128. release:
  2129. hw->phy.ops.release(hw);
  2130. return ret_val;
  2131. }
  2132. /**
  2133. * e1000e_write_phy_reg_bm2 - Write BM PHY register
  2134. * @hw: pointer to the HW structure
  2135. * @offset: register offset to write to
  2136. * @data: data to write at register offset
  2137. *
  2138. * Acquires semaphore, if necessary, then writes the data to PHY register
  2139. * at the offset. Release any acquired semaphores before exiting.
  2140. **/
  2141. s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
  2142. {
  2143. s32 ret_val;
  2144. u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
  2145. ret_val = hw->phy.ops.acquire(hw);
  2146. if (ret_val)
  2147. return ret_val;
  2148. /* Page 800 works differently than the rest so it has its own func */
  2149. if (page == BM_WUC_PAGE) {
  2150. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
  2151. false, false);
  2152. goto release;
  2153. }
  2154. hw->phy.addr = 1;
  2155. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  2156. /* Page is shifted left, PHY expects (page x 32) */
  2157. ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
  2158. page);
  2159. if (ret_val)
  2160. goto release;
  2161. }
  2162. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  2163. data);
  2164. release:
  2165. hw->phy.ops.release(hw);
  2166. return ret_val;
  2167. }
  2168. /**
  2169. * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
  2170. * @hw: pointer to the HW structure
  2171. * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
  2172. *
  2173. * Assumes semaphore already acquired and phy_reg points to a valid memory
  2174. * address to store contents of the BM_WUC_ENABLE_REG register.
  2175. **/
  2176. s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
  2177. {
  2178. s32 ret_val;
  2179. u16 temp;
  2180. /* All page select, port ctrl and wakeup registers use phy address 1 */
  2181. hw->phy.addr = 1;
  2182. /* Select Port Control Registers page */
  2183. ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
  2184. if (ret_val) {
  2185. e_dbg("Could not set Port Control page\n");
  2186. return ret_val;
  2187. }
  2188. ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
  2189. if (ret_val) {
  2190. e_dbg("Could not read PHY register %d.%d\n",
  2191. BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
  2192. return ret_val;
  2193. }
  2194. /* Enable both PHY wakeup mode and Wakeup register page writes.
  2195. * Prevent a power state change by disabling ME and Host PHY wakeup.
  2196. */
  2197. temp = *phy_reg;
  2198. temp |= BM_WUC_ENABLE_BIT;
  2199. temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
  2200. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
  2201. if (ret_val) {
  2202. e_dbg("Could not write PHY register %d.%d\n",
  2203. BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
  2204. return ret_val;
  2205. }
  2206. /* Select Host Wakeup Registers page - caller now able to write
  2207. * registers on the Wakeup registers page
  2208. */
  2209. return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
  2210. }
  2211. /**
  2212. * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
  2213. * @hw: pointer to the HW structure
  2214. * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
  2215. *
  2216. * Restore BM_WUC_ENABLE_REG to its original value.
  2217. *
  2218. * Assumes semaphore already acquired and *phy_reg is the contents of the
  2219. * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
  2220. * caller.
  2221. **/
  2222. s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
  2223. {
  2224. s32 ret_val;
  2225. /* Select Port Control Registers page */
  2226. ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
  2227. if (ret_val) {
  2228. e_dbg("Could not set Port Control page\n");
  2229. return ret_val;
  2230. }
  2231. /* Restore 769.17 to its original value */
  2232. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
  2233. if (ret_val)
  2234. e_dbg("Could not restore PHY register %d.%d\n",
  2235. BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
  2236. return ret_val;
  2237. }
  2238. /**
  2239. * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
  2240. * @hw: pointer to the HW structure
  2241. * @offset: register offset to be read or written
  2242. * @data: pointer to the data to read or write
  2243. * @read: determines if operation is read or write
  2244. * @page_set: BM_WUC_PAGE already set and access enabled
  2245. *
  2246. * Read the PHY register at offset and store the retrieved information in
  2247. * data, or write data to PHY register at offset. Note the procedure to
  2248. * access the PHY wakeup registers is different than reading the other PHY
  2249. * registers. It works as such:
  2250. * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
  2251. * 2) Set page to 800 for host (801 if we were manageability)
  2252. * 3) Write the address using the address opcode (0x11)
  2253. * 4) Read or write the data using the data opcode (0x12)
  2254. * 5) Restore 769.17.2 to its original value
  2255. *
  2256. * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
  2257. * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
  2258. *
  2259. * Assumes semaphore is already acquired. When page_set==true, assumes
  2260. * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
  2261. * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
  2262. **/
  2263. static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
  2264. u16 *data, bool read, bool page_set)
  2265. {
  2266. s32 ret_val;
  2267. u16 reg = BM_PHY_REG_NUM(offset);
  2268. u16 page = BM_PHY_REG_PAGE(offset);
  2269. u16 phy_reg = 0;
  2270. /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
  2271. if ((hw->mac.type == e1000_pchlan) &&
  2272. (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
  2273. e_dbg("Attempting to access page %d while gig enabled.\n",
  2274. page);
  2275. if (!page_set) {
  2276. /* Enable access to PHY wakeup registers */
  2277. ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2278. if (ret_val) {
  2279. e_dbg("Could not enable PHY wakeup reg access\n");
  2280. return ret_val;
  2281. }
  2282. }
  2283. e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
  2284. /* Write the Wakeup register page offset value using opcode 0x11 */
  2285. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
  2286. if (ret_val) {
  2287. e_dbg("Could not write address opcode to page %d\n", page);
  2288. return ret_val;
  2289. }
  2290. if (read) {
  2291. /* Read the Wakeup register page value using opcode 0x12 */
  2292. ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
  2293. data);
  2294. } else {
  2295. /* Write the Wakeup register page value using opcode 0x12 */
  2296. ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
  2297. *data);
  2298. }
  2299. if (ret_val) {
  2300. e_dbg("Could not access PHY reg %d.%d\n", page, reg);
  2301. return ret_val;
  2302. }
  2303. if (!page_set)
  2304. ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2305. return ret_val;
  2306. }
  2307. /**
  2308. * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
  2309. * @hw: pointer to the HW structure
  2310. *
  2311. * In the case of a PHY power down to save power, or to turn off link during a
  2312. * driver unload, or wake on lan is not enabled, restore the link to previous
  2313. * settings.
  2314. **/
  2315. void e1000_power_up_phy_copper(struct e1000_hw *hw)
  2316. {
  2317. u16 mii_reg = 0;
  2318. /* The PHY will retain its settings across a power down/up cycle */
  2319. e1e_rphy(hw, MII_BMCR, &mii_reg);
  2320. mii_reg &= ~BMCR_PDOWN;
  2321. e1e_wphy(hw, MII_BMCR, mii_reg);
  2322. }
  2323. /**
  2324. * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
  2325. * @hw: pointer to the HW structure
  2326. *
  2327. * In the case of a PHY power down to save power, or to turn off link during a
  2328. * driver unload, or wake on lan is not enabled, restore the link to previous
  2329. * settings.
  2330. **/
  2331. void e1000_power_down_phy_copper(struct e1000_hw *hw)
  2332. {
  2333. u16 mii_reg = 0;
  2334. /* The PHY will retain its settings across a power down/up cycle */
  2335. e1e_rphy(hw, MII_BMCR, &mii_reg);
  2336. mii_reg |= BMCR_PDOWN;
  2337. e1e_wphy(hw, MII_BMCR, mii_reg);
  2338. usleep_range(1000, 2000);
  2339. }
  2340. /**
  2341. * __e1000_read_phy_reg_hv - Read HV PHY register
  2342. * @hw: pointer to the HW structure
  2343. * @offset: register offset to be read
  2344. * @data: pointer to the read data
  2345. * @locked: semaphore has already been acquired or not
  2346. *
  2347. * Acquires semaphore, if necessary, then reads the PHY register at offset
  2348. * and stores the retrieved information in data. Release any acquired
  2349. * semaphore before exiting.
  2350. **/
  2351. static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
  2352. bool locked, bool page_set)
  2353. {
  2354. s32 ret_val;
  2355. u16 page = BM_PHY_REG_PAGE(offset);
  2356. u16 reg = BM_PHY_REG_NUM(offset);
  2357. u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
  2358. if (!locked) {
  2359. ret_val = hw->phy.ops.acquire(hw);
  2360. if (ret_val)
  2361. return ret_val;
  2362. }
  2363. /* Page 800 works differently than the rest so it has its own func */
  2364. if (page == BM_WUC_PAGE) {
  2365. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
  2366. true, page_set);
  2367. goto out;
  2368. }
  2369. if (page > 0 && page < HV_INTC_FC_PAGE_START) {
  2370. ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
  2371. data, true);
  2372. goto out;
  2373. }
  2374. if (!page_set) {
  2375. if (page == HV_INTC_FC_PAGE_START)
  2376. page = 0;
  2377. if (reg > MAX_PHY_MULTI_PAGE_REG) {
  2378. /* Page is shifted left, PHY expects (page x 32) */
  2379. ret_val = e1000_set_page_igp(hw,
  2380. (page << IGP_PAGE_SHIFT));
  2381. hw->phy.addr = phy_addr;
  2382. if (ret_val)
  2383. goto out;
  2384. }
  2385. }
  2386. e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
  2387. page << IGP_PAGE_SHIFT, reg);
  2388. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg, data);
  2389. out:
  2390. if (!locked)
  2391. hw->phy.ops.release(hw);
  2392. return ret_val;
  2393. }
  2394. /**
  2395. * e1000_read_phy_reg_hv - Read HV PHY register
  2396. * @hw: pointer to the HW structure
  2397. * @offset: register offset to be read
  2398. * @data: pointer to the read data
  2399. *
  2400. * Acquires semaphore then reads the PHY register at offset and stores
  2401. * the retrieved information in data. Release the acquired semaphore
  2402. * before exiting.
  2403. **/
  2404. s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
  2405. {
  2406. return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
  2407. }
  2408. /**
  2409. * e1000_read_phy_reg_hv_locked - Read HV PHY register
  2410. * @hw: pointer to the HW structure
  2411. * @offset: register offset to be read
  2412. * @data: pointer to the read data
  2413. *
  2414. * Reads the PHY register at offset and stores the retrieved information
  2415. * in data. Assumes semaphore already acquired.
  2416. **/
  2417. s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
  2418. {
  2419. return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
  2420. }
  2421. /**
  2422. * e1000_read_phy_reg_page_hv - Read HV PHY register
  2423. * @hw: pointer to the HW structure
  2424. * @offset: register offset to write to
  2425. * @data: data to write at register offset
  2426. *
  2427. * Reads the PHY register at offset and stores the retrieved information
  2428. * in data. Assumes semaphore already acquired and page already set.
  2429. **/
  2430. s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
  2431. {
  2432. return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
  2433. }
  2434. /**
  2435. * __e1000_write_phy_reg_hv - Write HV PHY register
  2436. * @hw: pointer to the HW structure
  2437. * @offset: register offset to write to
  2438. * @data: data to write at register offset
  2439. * @locked: semaphore has already been acquired or not
  2440. *
  2441. * Acquires semaphore, if necessary, then writes the data to PHY register
  2442. * at the offset. Release any acquired semaphores before exiting.
  2443. **/
  2444. static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
  2445. bool locked, bool page_set)
  2446. {
  2447. s32 ret_val;
  2448. u16 page = BM_PHY_REG_PAGE(offset);
  2449. u16 reg = BM_PHY_REG_NUM(offset);
  2450. u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
  2451. if (!locked) {
  2452. ret_val = hw->phy.ops.acquire(hw);
  2453. if (ret_val)
  2454. return ret_val;
  2455. }
  2456. /* Page 800 works differently than the rest so it has its own func */
  2457. if (page == BM_WUC_PAGE) {
  2458. ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
  2459. false, page_set);
  2460. goto out;
  2461. }
  2462. if (page > 0 && page < HV_INTC_FC_PAGE_START) {
  2463. ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
  2464. &data, false);
  2465. goto out;
  2466. }
  2467. if (!page_set) {
  2468. if (page == HV_INTC_FC_PAGE_START)
  2469. page = 0;
  2470. /* Workaround MDIO accesses being disabled after entering IEEE
  2471. * Power Down (when bit 11 of the PHY Control register is set)
  2472. */
  2473. if ((hw->phy.type == e1000_phy_82578) &&
  2474. (hw->phy.revision >= 1) &&
  2475. (hw->phy.addr == 2) &&
  2476. !(MAX_PHY_REG_ADDRESS & reg) && (data & (1 << 11))) {
  2477. u16 data2 = 0x7EFF;
  2478. ret_val = e1000_access_phy_debug_regs_hv(hw,
  2479. (1 << 6) | 0x3,
  2480. &data2, false);
  2481. if (ret_val)
  2482. goto out;
  2483. }
  2484. if (reg > MAX_PHY_MULTI_PAGE_REG) {
  2485. /* Page is shifted left, PHY expects (page x 32) */
  2486. ret_val = e1000_set_page_igp(hw,
  2487. (page << IGP_PAGE_SHIFT));
  2488. hw->phy.addr = phy_addr;
  2489. if (ret_val)
  2490. goto out;
  2491. }
  2492. }
  2493. e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
  2494. page << IGP_PAGE_SHIFT, reg);
  2495. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
  2496. data);
  2497. out:
  2498. if (!locked)
  2499. hw->phy.ops.release(hw);
  2500. return ret_val;
  2501. }
  2502. /**
  2503. * e1000_write_phy_reg_hv - Write HV PHY register
  2504. * @hw: pointer to the HW structure
  2505. * @offset: register offset to write to
  2506. * @data: data to write at register offset
  2507. *
  2508. * Acquires semaphore then writes the data to PHY register at the offset.
  2509. * Release the acquired semaphores before exiting.
  2510. **/
  2511. s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
  2512. {
  2513. return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
  2514. }
  2515. /**
  2516. * e1000_write_phy_reg_hv_locked - 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. * Writes the data to PHY register at the offset. Assumes semaphore
  2522. * already acquired.
  2523. **/
  2524. s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
  2525. {
  2526. return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
  2527. }
  2528. /**
  2529. * e1000_write_phy_reg_page_hv - 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 and page already set.
  2536. **/
  2537. s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
  2538. {
  2539. return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
  2540. }
  2541. /**
  2542. * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
  2543. * @page: page to be accessed
  2544. **/
  2545. static u32 e1000_get_phy_addr_for_hv_page(u32 page)
  2546. {
  2547. u32 phy_addr = 2;
  2548. if (page >= HV_INTC_FC_PAGE_START)
  2549. phy_addr = 1;
  2550. return phy_addr;
  2551. }
  2552. /**
  2553. * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
  2554. * @hw: pointer to the HW structure
  2555. * @offset: register offset to be read or written
  2556. * @data: pointer to the data to be read or written
  2557. * @read: determines if operation is read or write
  2558. *
  2559. * Reads the PHY register at offset and stores the retreived information
  2560. * in data. Assumes semaphore already acquired. Note that the procedure
  2561. * to access these regs uses the address port and data port to read/write.
  2562. * These accesses done with PHY address 2 and without using pages.
  2563. **/
  2564. static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
  2565. u16 *data, bool read)
  2566. {
  2567. s32 ret_val;
  2568. u32 addr_reg;
  2569. u32 data_reg;
  2570. /* This takes care of the difference with desktop vs mobile phy */
  2571. addr_reg = ((hw->phy.type == e1000_phy_82578) ?
  2572. I82578_ADDR_REG : I82577_ADDR_REG);
  2573. data_reg = addr_reg + 1;
  2574. /* All operations in this function are phy address 2 */
  2575. hw->phy.addr = 2;
  2576. /* masking with 0x3F to remove the page from offset */
  2577. ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
  2578. if (ret_val) {
  2579. e_dbg("Could not write the Address Offset port register\n");
  2580. return ret_val;
  2581. }
  2582. /* Read or write the data value next */
  2583. if (read)
  2584. ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
  2585. else
  2586. ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
  2587. if (ret_val)
  2588. e_dbg("Could not access the Data port register\n");
  2589. return ret_val;
  2590. }
  2591. /**
  2592. * e1000_link_stall_workaround_hv - Si workaround
  2593. * @hw: pointer to the HW structure
  2594. *
  2595. * This function works around a Si bug where the link partner can get
  2596. * a link up indication before the PHY does. If small packets are sent
  2597. * by the link partner they can be placed in the packet buffer without
  2598. * being properly accounted for by the PHY and will stall preventing
  2599. * further packets from being received. The workaround is to clear the
  2600. * packet buffer after the PHY detects link up.
  2601. **/
  2602. s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
  2603. {
  2604. s32 ret_val = 0;
  2605. u16 data;
  2606. if (hw->phy.type != e1000_phy_82578)
  2607. return 0;
  2608. /* Do not apply workaround if in PHY loopback bit 14 set */
  2609. e1e_rphy(hw, MII_BMCR, &data);
  2610. if (data & BMCR_LOOPBACK)
  2611. return 0;
  2612. /* check if link is up and at 1Gbps */
  2613. ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
  2614. if (ret_val)
  2615. return ret_val;
  2616. data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
  2617. BM_CS_STATUS_SPEED_MASK);
  2618. if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
  2619. BM_CS_STATUS_SPEED_1000))
  2620. return 0;
  2621. msleep(200);
  2622. /* flush the packets in the fifo buffer */
  2623. ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL,
  2624. (HV_MUX_DATA_CTRL_GEN_TO_MAC |
  2625. HV_MUX_DATA_CTRL_FORCE_SPEED));
  2626. if (ret_val)
  2627. return ret_val;
  2628. return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
  2629. }
  2630. /**
  2631. * e1000_check_polarity_82577 - Checks the polarity.
  2632. * @hw: pointer to the HW structure
  2633. *
  2634. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  2635. *
  2636. * Polarity is determined based on the PHY specific status register.
  2637. **/
  2638. s32 e1000_check_polarity_82577(struct e1000_hw *hw)
  2639. {
  2640. struct e1000_phy_info *phy = &hw->phy;
  2641. s32 ret_val;
  2642. u16 data;
  2643. ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
  2644. if (!ret_val)
  2645. phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
  2646. ? e1000_rev_polarity_reversed
  2647. : e1000_rev_polarity_normal);
  2648. return ret_val;
  2649. }
  2650. /**
  2651. * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
  2652. * @hw: pointer to the HW structure
  2653. *
  2654. * Calls the PHY setup function to force speed and duplex.
  2655. **/
  2656. s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
  2657. {
  2658. struct e1000_phy_info *phy = &hw->phy;
  2659. s32 ret_val;
  2660. u16 phy_data;
  2661. bool link;
  2662. ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
  2663. if (ret_val)
  2664. return ret_val;
  2665. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  2666. ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
  2667. if (ret_val)
  2668. return ret_val;
  2669. udelay(1);
  2670. if (phy->autoneg_wait_to_complete) {
  2671. e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
  2672. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  2673. 100000, &link);
  2674. if (ret_val)
  2675. return ret_val;
  2676. if (!link)
  2677. e_dbg("Link taking longer than expected.\n");
  2678. /* Try once more */
  2679. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  2680. 100000, &link);
  2681. }
  2682. return ret_val;
  2683. }
  2684. /**
  2685. * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
  2686. * @hw: pointer to the HW structure
  2687. *
  2688. * Read PHY status to determine if link is up. If link is up, then
  2689. * set/determine 10base-T extended distance and polarity correction. Read
  2690. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  2691. * determine on the cable length, local and remote receiver.
  2692. **/
  2693. s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
  2694. {
  2695. struct e1000_phy_info *phy = &hw->phy;
  2696. s32 ret_val;
  2697. u16 data;
  2698. bool link;
  2699. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  2700. if (ret_val)
  2701. return ret_val;
  2702. if (!link) {
  2703. e_dbg("Phy info is only valid if link is up\n");
  2704. return -E1000_ERR_CONFIG;
  2705. }
  2706. phy->polarity_correction = true;
  2707. ret_val = e1000_check_polarity_82577(hw);
  2708. if (ret_val)
  2709. return ret_val;
  2710. ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
  2711. if (ret_val)
  2712. return ret_val;
  2713. phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
  2714. if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
  2715. I82577_PHY_STATUS2_SPEED_1000MBPS) {
  2716. ret_val = hw->phy.ops.get_cable_length(hw);
  2717. if (ret_val)
  2718. return ret_val;
  2719. ret_val = e1e_rphy(hw, MII_STAT1000, &data);
  2720. if (ret_val)
  2721. return ret_val;
  2722. phy->local_rx = (data & LPA_1000LOCALRXOK)
  2723. ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  2724. phy->remote_rx = (data & LPA_1000REMRXOK)
  2725. ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  2726. } else {
  2727. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  2728. phy->local_rx = e1000_1000t_rx_status_undefined;
  2729. phy->remote_rx = e1000_1000t_rx_status_undefined;
  2730. }
  2731. return 0;
  2732. }
  2733. /**
  2734. * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
  2735. * @hw: pointer to the HW structure
  2736. *
  2737. * Reads the diagnostic status register and verifies result is valid before
  2738. * placing it in the phy_cable_length field.
  2739. **/
  2740. s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
  2741. {
  2742. struct e1000_phy_info *phy = &hw->phy;
  2743. s32 ret_val;
  2744. u16 phy_data, length;
  2745. ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
  2746. if (ret_val)
  2747. return ret_val;
  2748. length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
  2749. I82577_DSTATUS_CABLE_LENGTH_SHIFT);
  2750. if (length == E1000_CABLE_LENGTH_UNDEFINED)
  2751. return -E1000_ERR_PHY;
  2752. phy->cable_length = length;
  2753. return 0;
  2754. }