phy.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include "e1000.h"
  4. static s32 e1000_wait_autoneg(struct e1000_hw *hw);
  5. static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
  6. u16 *data, bool read, bool page_set);
  7. static u32 e1000_get_phy_addr_for_hv_page(u32 page);
  8. static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
  9. u16 *data, bool read);
  10. /* Cable length tables */
  11. static const u16 e1000_m88_cable_length_table[] = {
  12. 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED
  13. };
  14. #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
  15. ARRAY_SIZE(e1000_m88_cable_length_table)
  16. static const u16 e1000_igp_2_cable_length_table[] = {
  17. 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
  18. 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
  19. 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
  20. 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
  21. 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
  22. 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
  23. 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
  24. 124
  25. };
  26. #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
  27. ARRAY_SIZE(e1000_igp_2_cable_length_table)
  28. /**
  29. * e1000e_check_reset_block_generic - Check if PHY reset is blocked
  30. * @hw: pointer to the HW structure
  31. *
  32. * Read the PHY management control register and check whether a PHY reset
  33. * is blocked. If a reset is not blocked return 0, otherwise
  34. * return E1000_BLK_PHY_RESET (12).
  35. **/
  36. s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
  37. {
  38. u32 manc;
  39. manc = er32(MANC);
  40. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0;
  41. }
  42. /**
  43. * e1000e_get_phy_id - Retrieve the PHY ID and revision
  44. * @hw: pointer to the HW structure
  45. *
  46. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  47. * revision in the hardware structure.
  48. **/
  49. s32 e1000e_get_phy_id(struct e1000_hw *hw)
  50. {
  51. struct e1000_phy_info *phy = &hw->phy;
  52. s32 ret_val = 0;
  53. u16 phy_id;
  54. u16 retry_count = 0;
  55. if (!phy->ops.read_reg)
  56. return 0;
  57. while (retry_count < 2) {
  58. ret_val = e1e_rphy(hw, MII_PHYSID1, &phy_id);
  59. if (ret_val)
  60. return ret_val;
  61. phy->id = (u32)(phy_id << 16);
  62. usleep_range(20, 40);
  63. ret_val = e1e_rphy(hw, MII_PHYSID2, &phy_id);
  64. if (ret_val)
  65. return ret_val;
  66. phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
  67. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  68. if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
  69. return 0;
  70. retry_count++;
  71. }
  72. return 0;
  73. }
  74. /**
  75. * e1000e_phy_reset_dsp - Reset PHY DSP
  76. * @hw: pointer to the HW structure
  77. *
  78. * Reset the digital signal processor.
  79. **/
  80. s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
  81. {
  82. s32 ret_val;
  83. ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
  84. if (ret_val)
  85. return ret_val;
  86. return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
  87. }
  88. /**
  89. * e1000e_read_phy_reg_mdic - Read MDI control register
  90. * @hw: pointer to the HW structure
  91. * @offset: register offset to be read
  92. * @data: pointer to the read data
  93. *
  94. * Reads the MDI control register in the PHY at offset and stores the
  95. * information read to data.
  96. **/
  97. s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
  98. {
  99. struct e1000_phy_info *phy = &hw->phy;
  100. u32 i, mdic = 0;
  101. if (offset > MAX_PHY_REG_ADDRESS) {
  102. e_dbg("PHY Address %d is out of range\n", offset);
  103. return -E1000_ERR_PARAM;
  104. }
  105. /* Set up Op-code, Phy Address, and register offset in the MDI
  106. * Control register. The MAC will take care of interfacing with the
  107. * PHY to retrieve the desired data.
  108. */
  109. mdic = ((offset << E1000_MDIC_REG_SHIFT) |
  110. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  111. (E1000_MDIC_OP_READ));
  112. ew32(MDIC, mdic);
  113. /* Poll the ready bit to see if the MDI read completed
  114. * Increasing the time out as testing showed failures with
  115. * the lower time out
  116. */
  117. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  118. udelay(50);
  119. mdic = er32(MDIC);
  120. if (mdic & E1000_MDIC_READY)
  121. break;
  122. }
  123. if (!(mdic & E1000_MDIC_READY)) {
  124. e_dbg("MDI Read did not complete\n");
  125. return -E1000_ERR_PHY;
  126. }
  127. if (mdic & E1000_MDIC_ERROR) {
  128. e_dbg("MDI Error\n");
  129. return -E1000_ERR_PHY;
  130. }
  131. if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
  132. e_dbg("MDI Read offset error - requested %d, returned %d\n",
  133. offset,
  134. (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
  135. return -E1000_ERR_PHY;
  136. }
  137. *data = (u16)mdic;
  138. /* Allow some time after each MDIC transaction to avoid
  139. * reading duplicate data in the next MDIC transaction.
  140. */
  141. if (hw->mac.type == e1000_pch2lan)
  142. udelay(100);
  143. return 0;
  144. }
  145. /**
  146. * e1000e_write_phy_reg_mdic - Write MDI control register
  147. * @hw: pointer to the HW structure
  148. * @offset: register offset to write to
  149. * @data: data to write to register at offset
  150. *
  151. * Writes data to MDI control register in the PHY at offset.
  152. **/
  153. s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
  154. {
  155. struct e1000_phy_info *phy = &hw->phy;
  156. u32 i, mdic = 0;
  157. if (offset > MAX_PHY_REG_ADDRESS) {
  158. e_dbg("PHY Address %d is out of range\n", offset);
  159. return -E1000_ERR_PARAM;
  160. }
  161. /* Set up Op-code, Phy Address, and register offset in the MDI
  162. * Control register. The MAC will take care of interfacing with the
  163. * PHY to retrieve the desired data.
  164. */
  165. mdic = (((u32)data) |
  166. (offset << E1000_MDIC_REG_SHIFT) |
  167. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  168. (E1000_MDIC_OP_WRITE));
  169. ew32(MDIC, mdic);
  170. /* Poll the ready bit to see if the MDI read completed
  171. * Increasing the time out as testing showed failures with
  172. * the lower time out
  173. */
  174. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  175. udelay(50);
  176. mdic = er32(MDIC);
  177. if (mdic & E1000_MDIC_READY)
  178. break;
  179. }
  180. if (!(mdic & E1000_MDIC_READY)) {
  181. e_dbg("MDI Write did not complete\n");
  182. return -E1000_ERR_PHY;
  183. }
  184. if (mdic & E1000_MDIC_ERROR) {
  185. e_dbg("MDI Error\n");
  186. return -E1000_ERR_PHY;
  187. }
  188. if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
  189. e_dbg("MDI Write offset error - requested %d, returned %d\n",
  190. offset,
  191. (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
  192. return -E1000_ERR_PHY;
  193. }
  194. /* Allow some time after each MDIC transaction to avoid
  195. * reading duplicate data in the next MDIC transaction.
  196. */
  197. if (hw->mac.type == e1000_pch2lan)
  198. udelay(100);
  199. return 0;
  200. }
  201. /**
  202. * e1000e_read_phy_reg_m88 - Read m88 PHY register
  203. * @hw: pointer to the HW structure
  204. * @offset: register offset to be read
  205. * @data: pointer to the read data
  206. *
  207. * Acquires semaphore, if necessary, then reads the PHY register at offset
  208. * and storing the retrieved information in data. Release any acquired
  209. * semaphores before exiting.
  210. **/
  211. s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
  212. {
  213. s32 ret_val;
  214. ret_val = hw->phy.ops.acquire(hw);
  215. if (ret_val)
  216. return ret_val;
  217. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  218. data);
  219. hw->phy.ops.release(hw);
  220. return ret_val;
  221. }
  222. /**
  223. * e1000e_write_phy_reg_m88 - Write m88 PHY register
  224. * @hw: pointer to the HW structure
  225. * @offset: register offset to write to
  226. * @data: data to write at register offset
  227. *
  228. * Acquires semaphore, if necessary, then writes the data to PHY register
  229. * at the offset. Release any acquired semaphores before exiting.
  230. **/
  231. s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
  232. {
  233. s32 ret_val;
  234. ret_val = hw->phy.ops.acquire(hw);
  235. if (ret_val)
  236. return ret_val;
  237. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  238. data);
  239. hw->phy.ops.release(hw);
  240. return ret_val;
  241. }
  242. /**
  243. * e1000_set_page_igp - Set page as on IGP-like PHY(s)
  244. * @hw: pointer to the HW structure
  245. * @page: page to set (shifted left when necessary)
  246. *
  247. * Sets PHY page required for PHY register access. Assumes semaphore is
  248. * already acquired. Note, this function sets phy.addr to 1 so the caller
  249. * must set it appropriately (if necessary) after this function returns.
  250. **/
  251. s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
  252. {
  253. e_dbg("Setting page 0x%x\n", page);
  254. hw->phy.addr = 1;
  255. return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
  256. }
  257. /**
  258. * __e1000e_read_phy_reg_igp - Read igp PHY register
  259. * @hw: pointer to the HW structure
  260. * @offset: register offset to be read
  261. * @data: pointer to the read data
  262. * @locked: semaphore has already been acquired or not
  263. *
  264. * Acquires semaphore, if necessary, then reads the PHY register at offset
  265. * and stores the retrieved information in data. Release any acquired
  266. * semaphores before exiting.
  267. **/
  268. static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
  269. bool locked)
  270. {
  271. s32 ret_val = 0;
  272. if (!locked) {
  273. if (!hw->phy.ops.acquire)
  274. return 0;
  275. ret_val = hw->phy.ops.acquire(hw);
  276. if (ret_val)
  277. return ret_val;
  278. }
  279. if (offset > MAX_PHY_MULTI_PAGE_REG)
  280. ret_val = e1000e_write_phy_reg_mdic(hw,
  281. IGP01E1000_PHY_PAGE_SELECT,
  282. (u16)offset);
  283. if (!ret_val)
  284. ret_val = e1000e_read_phy_reg_mdic(hw,
  285. MAX_PHY_REG_ADDRESS & offset,
  286. data);
  287. if (!locked)
  288. hw->phy.ops.release(hw);
  289. return ret_val;
  290. }
  291. /**
  292. * e1000e_read_phy_reg_igp - Read igp PHY register
  293. * @hw: pointer to the HW structure
  294. * @offset: register offset to be read
  295. * @data: pointer to the read data
  296. *
  297. * Acquires semaphore then reads the PHY register at offset and stores the
  298. * retrieved information in data.
  299. * Release the acquired semaphore before exiting.
  300. **/
  301. s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
  302. {
  303. return __e1000e_read_phy_reg_igp(hw, offset, data, false);
  304. }
  305. /**
  306. * e1000e_read_phy_reg_igp_locked - Read igp PHY register
  307. * @hw: pointer to the HW structure
  308. * @offset: register offset to be read
  309. * @data: pointer to the read data
  310. *
  311. * Reads the PHY register at offset and stores the retrieved information
  312. * in data. Assumes semaphore already acquired.
  313. **/
  314. s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
  315. {
  316. return __e1000e_read_phy_reg_igp(hw, offset, data, true);
  317. }
  318. /**
  319. * e1000e_write_phy_reg_igp - Write igp PHY register
  320. * @hw: pointer to the HW structure
  321. * @offset: register offset to write to
  322. * @data: data to write at register offset
  323. * @locked: semaphore has already been acquired or not
  324. *
  325. * Acquires semaphore, if necessary, then writes the data to PHY register
  326. * at the offset. Release any acquired semaphores before exiting.
  327. **/
  328. static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
  329. bool locked)
  330. {
  331. s32 ret_val = 0;
  332. if (!locked) {
  333. if (!hw->phy.ops.acquire)
  334. return 0;
  335. ret_val = hw->phy.ops.acquire(hw);
  336. if (ret_val)
  337. return ret_val;
  338. }
  339. if (offset > MAX_PHY_MULTI_PAGE_REG)
  340. ret_val = e1000e_write_phy_reg_mdic(hw,
  341. IGP01E1000_PHY_PAGE_SELECT,
  342. (u16)offset);
  343. if (!ret_val)
  344. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
  345. offset, data);
  346. if (!locked)
  347. hw->phy.ops.release(hw);
  348. return ret_val;
  349. }
  350. /**
  351. * e1000e_write_phy_reg_igp - Write igp PHY register
  352. * @hw: pointer to the HW structure
  353. * @offset: register offset to write to
  354. * @data: data to write at register offset
  355. *
  356. * Acquires semaphore then writes the data to PHY register
  357. * at the offset. Release any acquired semaphores before exiting.
  358. **/
  359. s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
  360. {
  361. return __e1000e_write_phy_reg_igp(hw, offset, data, false);
  362. }
  363. /**
  364. * e1000e_write_phy_reg_igp_locked - Write igp PHY register
  365. * @hw: pointer to the HW structure
  366. * @offset: register offset to write to
  367. * @data: data to write at register offset
  368. *
  369. * Writes the data to PHY register at the offset.
  370. * Assumes semaphore already acquired.
  371. **/
  372. s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
  373. {
  374. return __e1000e_write_phy_reg_igp(hw, offset, data, true);
  375. }
  376. /**
  377. * __e1000_read_kmrn_reg - Read kumeran register
  378. * @hw: pointer to the HW structure
  379. * @offset: register offset to be read
  380. * @data: pointer to the read data
  381. * @locked: semaphore has already been acquired or not
  382. *
  383. * Acquires semaphore, if necessary. Then reads the PHY register at offset
  384. * using the kumeran interface. The information retrieved is stored in data.
  385. * Release any acquired semaphores before exiting.
  386. **/
  387. static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
  388. bool locked)
  389. {
  390. u32 kmrnctrlsta;
  391. if (!locked) {
  392. s32 ret_val = 0;
  393. if (!hw->phy.ops.acquire)
  394. return 0;
  395. ret_val = hw->phy.ops.acquire(hw);
  396. if (ret_val)
  397. return ret_val;
  398. }
  399. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  400. E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
  401. ew32(KMRNCTRLSTA, kmrnctrlsta);
  402. e1e_flush();
  403. udelay(2);
  404. kmrnctrlsta = er32(KMRNCTRLSTA);
  405. *data = (u16)kmrnctrlsta;
  406. if (!locked)
  407. hw->phy.ops.release(hw);
  408. return 0;
  409. }
  410. /**
  411. * e1000e_read_kmrn_reg - Read kumeran register
  412. * @hw: pointer to the HW structure
  413. * @offset: register offset to be read
  414. * @data: pointer to the read data
  415. *
  416. * Acquires semaphore then reads the PHY register at offset using the
  417. * kumeran interface. The information retrieved is stored in data.
  418. * Release the acquired semaphore before exiting.
  419. **/
  420. s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
  421. {
  422. return __e1000_read_kmrn_reg(hw, offset, data, false);
  423. }
  424. /**
  425. * e1000e_read_kmrn_reg_locked - Read kumeran register
  426. * @hw: pointer to the HW structure
  427. * @offset: register offset to be read
  428. * @data: pointer to the read data
  429. *
  430. * Reads the PHY register at offset using the kumeran interface. The
  431. * information retrieved is stored in data.
  432. * Assumes semaphore already acquired.
  433. **/
  434. s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
  435. {
  436. return __e1000_read_kmrn_reg(hw, offset, data, true);
  437. }
  438. /**
  439. * __e1000_write_kmrn_reg - Write kumeran register
  440. * @hw: pointer to the HW structure
  441. * @offset: register offset to write to
  442. * @data: data to write at register offset
  443. * @locked: semaphore has already been acquired or not
  444. *
  445. * Acquires semaphore, if necessary. Then write the data to PHY register
  446. * at the offset using the kumeran interface. Release any acquired semaphores
  447. * before exiting.
  448. **/
  449. static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
  450. bool locked)
  451. {
  452. u32 kmrnctrlsta;
  453. if (!locked) {
  454. s32 ret_val = 0;
  455. if (!hw->phy.ops.acquire)
  456. return 0;
  457. ret_val = hw->phy.ops.acquire(hw);
  458. if (ret_val)
  459. return ret_val;
  460. }
  461. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  462. E1000_KMRNCTRLSTA_OFFSET) | data;
  463. ew32(KMRNCTRLSTA, kmrnctrlsta);
  464. e1e_flush();
  465. udelay(2);
  466. if (!locked)
  467. hw->phy.ops.release(hw);
  468. return 0;
  469. }
  470. /**
  471. * e1000e_write_kmrn_reg - Write kumeran register
  472. * @hw: pointer to the HW structure
  473. * @offset: register offset to write to
  474. * @data: data to write at register offset
  475. *
  476. * Acquires semaphore then writes the data to the PHY register at the offset
  477. * using the kumeran interface. Release the acquired semaphore before exiting.
  478. **/
  479. s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
  480. {
  481. return __e1000_write_kmrn_reg(hw, offset, data, false);
  482. }
  483. /**
  484. * e1000e_write_kmrn_reg_locked - Write kumeran register
  485. * @hw: pointer to the HW structure
  486. * @offset: register offset to write to
  487. * @data: data to write at register offset
  488. *
  489. * Write the data to PHY register at the offset using the kumeran interface.
  490. * Assumes semaphore already acquired.
  491. **/
  492. s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
  493. {
  494. return __e1000_write_kmrn_reg(hw, offset, data, true);
  495. }
  496. /**
  497. * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
  498. * @hw: pointer to the HW structure
  499. *
  500. * Sets up Master/slave mode
  501. **/
  502. static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
  503. {
  504. s32 ret_val;
  505. u16 phy_data;
  506. /* Resolve Master/Slave mode */
  507. ret_val = e1e_rphy(hw, MII_CTRL1000, &phy_data);
  508. if (ret_val)
  509. return ret_val;
  510. /* load defaults for future use */
  511. hw->phy.original_ms_type = (phy_data & CTL1000_ENABLE_MASTER) ?
  512. ((phy_data & CTL1000_AS_MASTER) ?
  513. e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
  514. switch (hw->phy.ms_type) {
  515. case e1000_ms_force_master:
  516. phy_data |= (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
  517. break;
  518. case e1000_ms_force_slave:
  519. phy_data |= CTL1000_ENABLE_MASTER;
  520. phy_data &= ~(CTL1000_AS_MASTER);
  521. break;
  522. case e1000_ms_auto:
  523. phy_data &= ~CTL1000_ENABLE_MASTER;
  524. /* fall-through */
  525. default:
  526. break;
  527. }
  528. return e1e_wphy(hw, MII_CTRL1000, phy_data);
  529. }
  530. /**
  531. * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
  532. * @hw: pointer to the HW structure
  533. *
  534. * Sets up Carrier-sense on Transmit and downshift values.
  535. **/
  536. s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
  537. {
  538. s32 ret_val;
  539. u16 phy_data;
  540. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  541. ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
  542. if (ret_val)
  543. return ret_val;
  544. phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
  545. /* Enable downshift */
  546. phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
  547. ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
  548. if (ret_val)
  549. return ret_val;
  550. /* Set MDI/MDIX mode */
  551. ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
  552. if (ret_val)
  553. return ret_val;
  554. phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
  555. /* Options:
  556. * 0 - Auto (default)
  557. * 1 - MDI mode
  558. * 2 - MDI-X mode
  559. */
  560. switch (hw->phy.mdix) {
  561. case 1:
  562. break;
  563. case 2:
  564. phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
  565. break;
  566. case 0:
  567. default:
  568. phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
  569. break;
  570. }
  571. ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
  572. if (ret_val)
  573. return ret_val;
  574. return e1000_set_master_slave_mode(hw);
  575. }
  576. /**
  577. * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
  578. * @hw: pointer to the HW structure
  579. *
  580. * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
  581. * and downshift values are set also.
  582. **/
  583. s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
  584. {
  585. struct e1000_phy_info *phy = &hw->phy;
  586. s32 ret_val;
  587. u16 phy_data;
  588. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  589. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  590. if (ret_val)
  591. return ret_val;
  592. /* For BM PHY this bit is downshift enable */
  593. if (phy->type != e1000_phy_bm)
  594. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  595. /* Options:
  596. * MDI/MDI-X = 0 (default)
  597. * 0 - Auto for all speeds
  598. * 1 - MDI mode
  599. * 2 - MDI-X mode
  600. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  601. */
  602. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  603. switch (phy->mdix) {
  604. case 1:
  605. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  606. break;
  607. case 2:
  608. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  609. break;
  610. case 3:
  611. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  612. break;
  613. case 0:
  614. default:
  615. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  616. break;
  617. }
  618. /* Options:
  619. * disable_polarity_correction = 0 (default)
  620. * Automatic Correction for Reversed Cable Polarity
  621. * 0 - Disabled
  622. * 1 - Enabled
  623. */
  624. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  625. if (phy->disable_polarity_correction)
  626. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  627. /* Enable downshift on BM (disabled by default) */
  628. if (phy->type == e1000_phy_bm) {
  629. /* For 82574/82583, first disable then enable downshift */
  630. if (phy->id == BME1000_E_PHY_ID_R2) {
  631. phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
  632. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
  633. phy_data);
  634. if (ret_val)
  635. return ret_val;
  636. /* Commit the changes. */
  637. ret_val = phy->ops.commit(hw);
  638. if (ret_val) {
  639. e_dbg("Error committing the PHY changes\n");
  640. return ret_val;
  641. }
  642. }
  643. phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
  644. }
  645. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  646. if (ret_val)
  647. return ret_val;
  648. if ((phy->type == e1000_phy_m88) &&
  649. (phy->revision < E1000_REVISION_4) &&
  650. (phy->id != BME1000_E_PHY_ID_R2)) {
  651. /* Force TX_CLK in the Extended PHY Specific Control Register
  652. * to 25MHz clock.
  653. */
  654. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  655. if (ret_val)
  656. return ret_val;
  657. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  658. if ((phy->revision == 2) && (phy->id == M88E1111_I_PHY_ID)) {
  659. /* 82573L PHY - set the downshift counter to 5x. */
  660. phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
  661. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  662. } else {
  663. /* Configure Master and Slave downshift values */
  664. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  665. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  666. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  667. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  668. }
  669. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  670. if (ret_val)
  671. return ret_val;
  672. }
  673. if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
  674. /* Set PHY page 0, register 29 to 0x0003 */
  675. ret_val = e1e_wphy(hw, 29, 0x0003);
  676. if (ret_val)
  677. return ret_val;
  678. /* Set PHY page 0, register 30 to 0x0000 */
  679. ret_val = e1e_wphy(hw, 30, 0x0000);
  680. if (ret_val)
  681. return ret_val;
  682. }
  683. /* Commit the changes. */
  684. if (phy->ops.commit) {
  685. ret_val = phy->ops.commit(hw);
  686. if (ret_val) {
  687. e_dbg("Error committing the PHY changes\n");
  688. return ret_val;
  689. }
  690. }
  691. if (phy->type == e1000_phy_82578) {
  692. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  693. if (ret_val)
  694. return ret_val;
  695. /* 82578 PHY - set the downshift count to 1x. */
  696. phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
  697. phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
  698. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  699. if (ret_val)
  700. return ret_val;
  701. }
  702. return 0;
  703. }
  704. /**
  705. * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
  706. * @hw: pointer to the HW structure
  707. *
  708. * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
  709. * igp PHY's.
  710. **/
  711. s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
  712. {
  713. struct e1000_phy_info *phy = &hw->phy;
  714. s32 ret_val;
  715. u16 data;
  716. ret_val = e1000_phy_hw_reset(hw);
  717. if (ret_val) {
  718. e_dbg("Error resetting the PHY.\n");
  719. return ret_val;
  720. }
  721. /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
  722. * timeout issues when LFS is enabled.
  723. */
  724. msleep(100);
  725. /* disable lplu d0 during driver init */
  726. if (hw->phy.ops.set_d0_lplu_state) {
  727. ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
  728. if (ret_val) {
  729. e_dbg("Error Disabling LPLU D0\n");
  730. return ret_val;
  731. }
  732. }
  733. /* Configure mdi-mdix settings */
  734. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
  735. if (ret_val)
  736. return ret_val;
  737. data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  738. switch (phy->mdix) {
  739. case 1:
  740. data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  741. break;
  742. case 2:
  743. data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  744. break;
  745. case 0:
  746. default:
  747. data |= IGP01E1000_PSCR_AUTO_MDIX;
  748. break;
  749. }
  750. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
  751. if (ret_val)
  752. return ret_val;
  753. /* set auto-master slave resolution settings */
  754. if (hw->mac.autoneg) {
  755. /* when autonegotiation advertisement is only 1000Mbps then we
  756. * should disable SmartSpeed and enable Auto MasterSlave
  757. * resolution as hardware default.
  758. */
  759. if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
  760. /* Disable SmartSpeed */
  761. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  762. &data);
  763. if (ret_val)
  764. return ret_val;
  765. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  766. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  767. data);
  768. if (ret_val)
  769. return ret_val;
  770. /* Set auto Master/Slave resolution process */
  771. ret_val = e1e_rphy(hw, MII_CTRL1000, &data);
  772. if (ret_val)
  773. return ret_val;
  774. data &= ~CTL1000_ENABLE_MASTER;
  775. ret_val = e1e_wphy(hw, MII_CTRL1000, data);
  776. if (ret_val)
  777. return ret_val;
  778. }
  779. ret_val = e1000_set_master_slave_mode(hw);
  780. }
  781. return ret_val;
  782. }
  783. /**
  784. * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
  785. * @hw: pointer to the HW structure
  786. *
  787. * Reads the MII auto-neg advertisement register and/or the 1000T control
  788. * register and if the PHY is already setup for auto-negotiation, then
  789. * return successful. Otherwise, setup advertisement and flow control to
  790. * the appropriate values for the wanted auto-negotiation.
  791. **/
  792. static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
  793. {
  794. struct e1000_phy_info *phy = &hw->phy;
  795. s32 ret_val;
  796. u16 mii_autoneg_adv_reg;
  797. u16 mii_1000t_ctrl_reg = 0;
  798. phy->autoneg_advertised &= phy->autoneg_mask;
  799. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  800. ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_autoneg_adv_reg);
  801. if (ret_val)
  802. return ret_val;
  803. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  804. /* Read the MII 1000Base-T Control Register (Address 9). */
  805. ret_val = e1e_rphy(hw, MII_CTRL1000, &mii_1000t_ctrl_reg);
  806. if (ret_val)
  807. return ret_val;
  808. }
  809. /* Need to parse both autoneg_advertised and fc and set up
  810. * the appropriate PHY registers. First we will parse for
  811. * autoneg_advertised software override. Since we can advertise
  812. * a plethora of combinations, we need to check each bit
  813. * individually.
  814. */
  815. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  816. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  817. * the 1000Base-T Control Register (Address 9).
  818. */
  819. mii_autoneg_adv_reg &= ~(ADVERTISE_100FULL |
  820. ADVERTISE_100HALF |
  821. ADVERTISE_10FULL | ADVERTISE_10HALF);
  822. mii_1000t_ctrl_reg &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
  823. e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
  824. /* Do we want to advertise 10 Mb Half Duplex? */
  825. if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
  826. e_dbg("Advertise 10mb Half duplex\n");
  827. mii_autoneg_adv_reg |= ADVERTISE_10HALF;
  828. }
  829. /* Do we want to advertise 10 Mb Full Duplex? */
  830. if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
  831. e_dbg("Advertise 10mb Full duplex\n");
  832. mii_autoneg_adv_reg |= ADVERTISE_10FULL;
  833. }
  834. /* Do we want to advertise 100 Mb Half Duplex? */
  835. if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
  836. e_dbg("Advertise 100mb Half duplex\n");
  837. mii_autoneg_adv_reg |= ADVERTISE_100HALF;
  838. }
  839. /* Do we want to advertise 100 Mb Full Duplex? */
  840. if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
  841. e_dbg("Advertise 100mb Full duplex\n");
  842. mii_autoneg_adv_reg |= ADVERTISE_100FULL;
  843. }
  844. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  845. if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
  846. e_dbg("Advertise 1000mb Half duplex request denied!\n");
  847. /* Do we want to advertise 1000 Mb Full Duplex? */
  848. if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
  849. e_dbg("Advertise 1000mb Full duplex\n");
  850. mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
  851. }
  852. /* Check for a software override of the flow control settings, and
  853. * setup the PHY advertisement registers accordingly. If
  854. * auto-negotiation is enabled, then software will have to set the
  855. * "PAUSE" bits to the correct value in the Auto-Negotiation
  856. * Advertisement Register (MII_ADVERTISE) and re-start auto-
  857. * negotiation.
  858. *
  859. * The possible values of the "fc" parameter are:
  860. * 0: Flow control is completely disabled
  861. * 1: Rx flow control is enabled (we can receive pause frames
  862. * but not send pause frames).
  863. * 2: Tx flow control is enabled (we can send pause frames
  864. * but we do not support receiving pause frames).
  865. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  866. * other: No software override. The flow control configuration
  867. * in the EEPROM is used.
  868. */
  869. switch (hw->fc.current_mode) {
  870. case e1000_fc_none:
  871. /* Flow control (Rx & Tx) is completely disabled by a
  872. * software over-ride.
  873. */
  874. mii_autoneg_adv_reg &=
  875. ~(ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  876. break;
  877. case e1000_fc_rx_pause:
  878. /* Rx Flow control is enabled, and Tx Flow control is
  879. * disabled, by a software over-ride.
  880. *
  881. * Since there really isn't a way to advertise that we are
  882. * capable of Rx Pause ONLY, we will advertise that we
  883. * support both symmetric and asymmetric Rx PAUSE. Later
  884. * (in e1000e_config_fc_after_link_up) we will disable the
  885. * hw's ability to send PAUSE frames.
  886. */
  887. mii_autoneg_adv_reg |=
  888. (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  889. break;
  890. case e1000_fc_tx_pause:
  891. /* Tx Flow control is enabled, and Rx Flow control is
  892. * disabled, by a software over-ride.
  893. */
  894. mii_autoneg_adv_reg |= ADVERTISE_PAUSE_ASYM;
  895. mii_autoneg_adv_reg &= ~ADVERTISE_PAUSE_CAP;
  896. break;
  897. case e1000_fc_full:
  898. /* Flow control (both Rx and Tx) is enabled by a software
  899. * over-ride.
  900. */
  901. mii_autoneg_adv_reg |=
  902. (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  903. break;
  904. default:
  905. e_dbg("Flow control param set incorrectly\n");
  906. return -E1000_ERR_CONFIG;
  907. }
  908. ret_val = e1e_wphy(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
  909. if (ret_val)
  910. return ret_val;
  911. e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  912. if (phy->autoneg_mask & ADVERTISE_1000_FULL)
  913. ret_val = e1e_wphy(hw, MII_CTRL1000, mii_1000t_ctrl_reg);
  914. return ret_val;
  915. }
  916. /**
  917. * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
  918. * @hw: pointer to the HW structure
  919. *
  920. * Performs initial bounds checking on autoneg advertisement parameter, then
  921. * configure to advertise the full capability. Setup the PHY to autoneg
  922. * and restart the negotiation process between the link partner. If
  923. * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
  924. **/
  925. static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
  926. {
  927. struct e1000_phy_info *phy = &hw->phy;
  928. s32 ret_val;
  929. u16 phy_ctrl;
  930. /* Perform some bounds checking on the autoneg advertisement
  931. * parameter.
  932. */
  933. phy->autoneg_advertised &= phy->autoneg_mask;
  934. /* If autoneg_advertised is zero, we assume it was not defaulted
  935. * by the calling code so we set to advertise full capability.
  936. */
  937. if (!phy->autoneg_advertised)
  938. phy->autoneg_advertised = phy->autoneg_mask;
  939. e_dbg("Reconfiguring auto-neg advertisement params\n");
  940. ret_val = e1000_phy_setup_autoneg(hw);
  941. if (ret_val) {
  942. e_dbg("Error Setting up Auto-Negotiation\n");
  943. return ret_val;
  944. }
  945. e_dbg("Restarting Auto-Neg\n");
  946. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  947. * the Auto Neg Restart bit in the PHY control register.
  948. */
  949. ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
  950. if (ret_val)
  951. return ret_val;
  952. phy_ctrl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  953. ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
  954. if (ret_val)
  955. return ret_val;
  956. /* Does the user want to wait for Auto-Neg to complete here, or
  957. * check at a later time (for example, callback routine).
  958. */
  959. if (phy->autoneg_wait_to_complete) {
  960. ret_val = e1000_wait_autoneg(hw);
  961. if (ret_val) {
  962. e_dbg("Error while waiting for autoneg to complete\n");
  963. return ret_val;
  964. }
  965. }
  966. hw->mac.get_link_status = true;
  967. return ret_val;
  968. }
  969. /**
  970. * e1000e_setup_copper_link - Configure copper link settings
  971. * @hw: pointer to the HW structure
  972. *
  973. * Calls the appropriate function to configure the link for auto-neg or forced
  974. * speed and duplex. Then we check for link, once link is established calls
  975. * to configure collision distance and flow control are called. If link is
  976. * not established, we return -E1000_ERR_PHY (-2).
  977. **/
  978. s32 e1000e_setup_copper_link(struct e1000_hw *hw)
  979. {
  980. s32 ret_val;
  981. bool link;
  982. if (hw->mac.autoneg) {
  983. /* Setup autoneg and flow control advertisement and perform
  984. * autonegotiation.
  985. */
  986. ret_val = e1000_copper_link_autoneg(hw);
  987. if (ret_val)
  988. return ret_val;
  989. } else {
  990. /* PHY will be set to 10H, 10F, 100H or 100F
  991. * depending on user settings.
  992. */
  993. e_dbg("Forcing Speed and Duplex\n");
  994. ret_val = hw->phy.ops.force_speed_duplex(hw);
  995. if (ret_val) {
  996. e_dbg("Error Forcing Speed and Duplex\n");
  997. return ret_val;
  998. }
  999. }
  1000. /* Check link status. Wait up to 100 microseconds for link to become
  1001. * valid.
  1002. */
  1003. ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
  1004. &link);
  1005. if (ret_val)
  1006. return ret_val;
  1007. if (link) {
  1008. e_dbg("Valid link established!!!\n");
  1009. hw->mac.ops.config_collision_dist(hw);
  1010. ret_val = e1000e_config_fc_after_link_up(hw);
  1011. } else {
  1012. e_dbg("Unable to establish link!!!\n");
  1013. }
  1014. return ret_val;
  1015. }
  1016. /**
  1017. * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
  1018. * @hw: pointer to the HW structure
  1019. *
  1020. * Calls the PHY setup function to force speed and duplex. Clears the
  1021. * auto-crossover to force MDI manually. Waits for link and returns
  1022. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  1023. **/
  1024. s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
  1025. {
  1026. struct e1000_phy_info *phy = &hw->phy;
  1027. s32 ret_val;
  1028. u16 phy_data;
  1029. bool link;
  1030. ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
  1031. if (ret_val)
  1032. return ret_val;
  1033. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  1034. ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
  1035. if (ret_val)
  1036. return ret_val;
  1037. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1038. * forced whenever speed and duplex are forced.
  1039. */
  1040. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1041. if (ret_val)
  1042. return ret_val;
  1043. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1044. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1045. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1046. if (ret_val)
  1047. return ret_val;
  1048. e_dbg("IGP PSCR: %X\n", phy_data);
  1049. udelay(1);
  1050. if (phy->autoneg_wait_to_complete) {
  1051. e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
  1052. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1053. 100000, &link);
  1054. if (ret_val)
  1055. return ret_val;
  1056. if (!link)
  1057. e_dbg("Link taking longer than expected.\n");
  1058. /* Try once more */
  1059. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1060. 100000, &link);
  1061. }
  1062. return ret_val;
  1063. }
  1064. /**
  1065. * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
  1066. * @hw: pointer to the HW structure
  1067. *
  1068. * Calls the PHY setup function to force speed and duplex. Clears the
  1069. * auto-crossover to force MDI manually. Resets the PHY to commit the
  1070. * changes. If time expires while waiting for link up, we reset the DSP.
  1071. * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
  1072. * successful completion, else return corresponding error code.
  1073. **/
  1074. s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
  1075. {
  1076. struct e1000_phy_info *phy = &hw->phy;
  1077. s32 ret_val;
  1078. u16 phy_data;
  1079. bool link;
  1080. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  1081. * forced whenever speed and duplex are forced.
  1082. */
  1083. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1084. if (ret_val)
  1085. return ret_val;
  1086. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1087. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1088. if (ret_val)
  1089. return ret_val;
  1090. e_dbg("M88E1000 PSCR: %X\n", phy_data);
  1091. ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
  1092. if (ret_val)
  1093. return ret_val;
  1094. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  1095. ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
  1096. if (ret_val)
  1097. return ret_val;
  1098. /* Reset the phy to commit changes. */
  1099. if (hw->phy.ops.commit) {
  1100. ret_val = hw->phy.ops.commit(hw);
  1101. if (ret_val)
  1102. return ret_val;
  1103. }
  1104. if (phy->autoneg_wait_to_complete) {
  1105. e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
  1106. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1107. 100000, &link);
  1108. if (ret_val)
  1109. return ret_val;
  1110. if (!link) {
  1111. if (hw->phy.type != e1000_phy_m88) {
  1112. e_dbg("Link taking longer than expected.\n");
  1113. } else {
  1114. /* We didn't get link.
  1115. * Reset the DSP and cross our fingers.
  1116. */
  1117. ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
  1118. 0x001d);
  1119. if (ret_val)
  1120. return ret_val;
  1121. ret_val = e1000e_phy_reset_dsp(hw);
  1122. if (ret_val)
  1123. return ret_val;
  1124. }
  1125. }
  1126. /* Try once more */
  1127. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1128. 100000, &link);
  1129. if (ret_val)
  1130. return ret_val;
  1131. }
  1132. if (hw->phy.type != e1000_phy_m88)
  1133. return 0;
  1134. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1135. if (ret_val)
  1136. return ret_val;
  1137. /* Resetting the phy means we need to re-force TX_CLK in the
  1138. * Extended PHY Specific Control Register to 25MHz clock from
  1139. * the reset value of 2.5MHz.
  1140. */
  1141. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1142. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1143. if (ret_val)
  1144. return ret_val;
  1145. /* In addition, we must re-enable CRS on Tx for both half and full
  1146. * duplex.
  1147. */
  1148. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1149. if (ret_val)
  1150. return ret_val;
  1151. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1152. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1153. return ret_val;
  1154. }
  1155. /**
  1156. * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
  1157. * @hw: pointer to the HW structure
  1158. *
  1159. * Forces the speed and duplex settings of the PHY.
  1160. * This is a function pointer entry point only called by
  1161. * PHY setup routines.
  1162. **/
  1163. s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
  1164. {
  1165. struct e1000_phy_info *phy = &hw->phy;
  1166. s32 ret_val;
  1167. u16 data;
  1168. bool link;
  1169. ret_val = e1e_rphy(hw, MII_BMCR, &data);
  1170. if (ret_val)
  1171. return ret_val;
  1172. e1000e_phy_force_speed_duplex_setup(hw, &data);
  1173. ret_val = e1e_wphy(hw, MII_BMCR, data);
  1174. if (ret_val)
  1175. return ret_val;
  1176. /* Disable MDI-X support for 10/100 */
  1177. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
  1178. if (ret_val)
  1179. return ret_val;
  1180. data &= ~IFE_PMC_AUTO_MDIX;
  1181. data &= ~IFE_PMC_FORCE_MDIX;
  1182. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
  1183. if (ret_val)
  1184. return ret_val;
  1185. e_dbg("IFE PMC: %X\n", data);
  1186. udelay(1);
  1187. if (phy->autoneg_wait_to_complete) {
  1188. e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
  1189. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1190. 100000, &link);
  1191. if (ret_val)
  1192. return ret_val;
  1193. if (!link)
  1194. e_dbg("Link taking longer than expected.\n");
  1195. /* Try once more */
  1196. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  1197. 100000, &link);
  1198. if (ret_val)
  1199. return ret_val;
  1200. }
  1201. return 0;
  1202. }
  1203. /**
  1204. * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
  1205. * @hw: pointer to the HW structure
  1206. * @phy_ctrl: pointer to current value of MII_BMCR
  1207. *
  1208. * Forces speed and duplex on the PHY by doing the following: disable flow
  1209. * control, force speed/duplex on the MAC, disable auto speed detection,
  1210. * disable auto-negotiation, configure duplex, configure speed, configure
  1211. * the collision distance, write configuration to CTRL register. The
  1212. * caller must write to the MII_BMCR register for these settings to
  1213. * take affect.
  1214. **/
  1215. void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
  1216. {
  1217. struct e1000_mac_info *mac = &hw->mac;
  1218. u32 ctrl;
  1219. /* Turn off flow control when forcing speed/duplex */
  1220. hw->fc.current_mode = e1000_fc_none;
  1221. /* Force speed/duplex on the mac */
  1222. ctrl = er32(CTRL);
  1223. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1224. ctrl &= ~E1000_CTRL_SPD_SEL;
  1225. /* Disable Auto Speed Detection */
  1226. ctrl &= ~E1000_CTRL_ASDE;
  1227. /* Disable autoneg on the phy */
  1228. *phy_ctrl &= ~BMCR_ANENABLE;
  1229. /* Forcing Full or Half Duplex? */
  1230. if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
  1231. ctrl &= ~E1000_CTRL_FD;
  1232. *phy_ctrl &= ~BMCR_FULLDPLX;
  1233. e_dbg("Half Duplex\n");
  1234. } else {
  1235. ctrl |= E1000_CTRL_FD;
  1236. *phy_ctrl |= BMCR_FULLDPLX;
  1237. e_dbg("Full Duplex\n");
  1238. }
  1239. /* Forcing 10mb or 100mb? */
  1240. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
  1241. ctrl |= E1000_CTRL_SPD_100;
  1242. *phy_ctrl |= BMCR_SPEED100;
  1243. *phy_ctrl &= ~BMCR_SPEED1000;
  1244. e_dbg("Forcing 100mb\n");
  1245. } else {
  1246. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1247. *phy_ctrl &= ~(BMCR_SPEED1000 | BMCR_SPEED100);
  1248. e_dbg("Forcing 10mb\n");
  1249. }
  1250. hw->mac.ops.config_collision_dist(hw);
  1251. ew32(CTRL, ctrl);
  1252. }
  1253. /**
  1254. * e1000e_set_d3_lplu_state - Sets low power link up state for D3
  1255. * @hw: pointer to the HW structure
  1256. * @active: boolean used to enable/disable lplu
  1257. *
  1258. * Success returns 0, Failure returns 1
  1259. *
  1260. * The low power link up (lplu) state is set to the power management level D3
  1261. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  1262. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  1263. * is used during Dx states where the power conservation is most important.
  1264. * During driver activity, SmartSpeed should be enabled so performance is
  1265. * maintained.
  1266. **/
  1267. s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  1268. {
  1269. struct e1000_phy_info *phy = &hw->phy;
  1270. s32 ret_val;
  1271. u16 data;
  1272. ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  1273. if (ret_val)
  1274. return ret_val;
  1275. if (!active) {
  1276. data &= ~IGP02E1000_PM_D3_LPLU;
  1277. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1278. if (ret_val)
  1279. return ret_val;
  1280. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  1281. * during Dx states where the power conservation is most
  1282. * important. During driver activity we should enable
  1283. * SmartSpeed, so performance is maintained.
  1284. */
  1285. if (phy->smart_speed == e1000_smart_speed_on) {
  1286. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1287. &data);
  1288. if (ret_val)
  1289. return ret_val;
  1290. data |= IGP01E1000_PSCFR_SMART_SPEED;
  1291. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1292. data);
  1293. if (ret_val)
  1294. return ret_val;
  1295. } else if (phy->smart_speed == e1000_smart_speed_off) {
  1296. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1297. &data);
  1298. if (ret_val)
  1299. return ret_val;
  1300. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1301. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1302. data);
  1303. if (ret_val)
  1304. return ret_val;
  1305. }
  1306. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  1307. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  1308. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  1309. data |= IGP02E1000_PM_D3_LPLU;
  1310. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1311. if (ret_val)
  1312. return ret_val;
  1313. /* When LPLU is enabled, we should disable SmartSpeed */
  1314. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  1315. if (ret_val)
  1316. return ret_val;
  1317. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1318. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  1319. }
  1320. return ret_val;
  1321. }
  1322. /**
  1323. * e1000e_check_downshift - Checks whether a downshift in speed occurred
  1324. * @hw: pointer to the HW structure
  1325. *
  1326. * Success returns 0, Failure returns 1
  1327. *
  1328. * A downshift is detected by querying the PHY link health.
  1329. **/
  1330. s32 e1000e_check_downshift(struct e1000_hw *hw)
  1331. {
  1332. struct e1000_phy_info *phy = &hw->phy;
  1333. s32 ret_val;
  1334. u16 phy_data, offset, mask;
  1335. switch (phy->type) {
  1336. case e1000_phy_m88:
  1337. case e1000_phy_gg82563:
  1338. case e1000_phy_bm:
  1339. case e1000_phy_82578:
  1340. offset = M88E1000_PHY_SPEC_STATUS;
  1341. mask = M88E1000_PSSR_DOWNSHIFT;
  1342. break;
  1343. case e1000_phy_igp_2:
  1344. case e1000_phy_igp_3:
  1345. offset = IGP01E1000_PHY_LINK_HEALTH;
  1346. mask = IGP01E1000_PLHR_SS_DOWNGRADE;
  1347. break;
  1348. default:
  1349. /* speed downshift not supported */
  1350. phy->speed_downgraded = false;
  1351. return 0;
  1352. }
  1353. ret_val = e1e_rphy(hw, offset, &phy_data);
  1354. if (!ret_val)
  1355. phy->speed_downgraded = !!(phy_data & mask);
  1356. return ret_val;
  1357. }
  1358. /**
  1359. * e1000_check_polarity_m88 - Checks the polarity.
  1360. * @hw: pointer to the HW structure
  1361. *
  1362. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1363. *
  1364. * Polarity is determined based on the PHY specific status register.
  1365. **/
  1366. s32 e1000_check_polarity_m88(struct e1000_hw *hw)
  1367. {
  1368. struct e1000_phy_info *phy = &hw->phy;
  1369. s32 ret_val;
  1370. u16 data;
  1371. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
  1372. if (!ret_val)
  1373. phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
  1374. ? e1000_rev_polarity_reversed
  1375. : e1000_rev_polarity_normal);
  1376. return ret_val;
  1377. }
  1378. /**
  1379. * e1000_check_polarity_igp - Checks the polarity.
  1380. * @hw: pointer to the HW structure
  1381. *
  1382. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1383. *
  1384. * Polarity is determined based on the PHY port status register, and the
  1385. * current speed (since there is no polarity at 100Mbps).
  1386. **/
  1387. s32 e1000_check_polarity_igp(struct e1000_hw *hw)
  1388. {
  1389. struct e1000_phy_info *phy = &hw->phy;
  1390. s32 ret_val;
  1391. u16 data, offset, mask;
  1392. /* Polarity is determined based on the speed of
  1393. * our connection.
  1394. */
  1395. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1396. if (ret_val)
  1397. return ret_val;
  1398. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1399. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1400. offset = IGP01E1000_PHY_PCS_INIT_REG;
  1401. mask = IGP01E1000_PHY_POLARITY_MASK;
  1402. } else {
  1403. /* This really only applies to 10Mbps since
  1404. * there is no polarity for 100Mbps (always 0).
  1405. */
  1406. offset = IGP01E1000_PHY_PORT_STATUS;
  1407. mask = IGP01E1000_PSSR_POLARITY_REVERSED;
  1408. }
  1409. ret_val = e1e_rphy(hw, offset, &data);
  1410. if (!ret_val)
  1411. phy->cable_polarity = ((data & mask)
  1412. ? e1000_rev_polarity_reversed
  1413. : e1000_rev_polarity_normal);
  1414. return ret_val;
  1415. }
  1416. /**
  1417. * e1000_check_polarity_ife - Check cable polarity for IFE PHY
  1418. * @hw: pointer to the HW structure
  1419. *
  1420. * Polarity is determined on the polarity reversal feature being enabled.
  1421. **/
  1422. s32 e1000_check_polarity_ife(struct e1000_hw *hw)
  1423. {
  1424. struct e1000_phy_info *phy = &hw->phy;
  1425. s32 ret_val;
  1426. u16 phy_data, offset, mask;
  1427. /* Polarity is determined based on the reversal feature being enabled.
  1428. */
  1429. if (phy->polarity_correction) {
  1430. offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
  1431. mask = IFE_PESC_POLARITY_REVERSED;
  1432. } else {
  1433. offset = IFE_PHY_SPECIAL_CONTROL;
  1434. mask = IFE_PSC_FORCE_POLARITY;
  1435. }
  1436. ret_val = e1e_rphy(hw, offset, &phy_data);
  1437. if (!ret_val)
  1438. phy->cable_polarity = ((phy_data & mask)
  1439. ? e1000_rev_polarity_reversed
  1440. : e1000_rev_polarity_normal);
  1441. return ret_val;
  1442. }
  1443. /**
  1444. * e1000_wait_autoneg - Wait for auto-neg completion
  1445. * @hw: pointer to the HW structure
  1446. *
  1447. * Waits for auto-negotiation to complete or for the auto-negotiation time
  1448. * limit to expire, which ever happens first.
  1449. **/
  1450. static s32 e1000_wait_autoneg(struct e1000_hw *hw)
  1451. {
  1452. s32 ret_val = 0;
  1453. u16 i, phy_status;
  1454. /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
  1455. for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
  1456. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1457. if (ret_val)
  1458. break;
  1459. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1460. if (ret_val)
  1461. break;
  1462. if (phy_status & BMSR_ANEGCOMPLETE)
  1463. break;
  1464. msleep(100);
  1465. }
  1466. /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
  1467. * has completed.
  1468. */
  1469. return ret_val;
  1470. }
  1471. /**
  1472. * e1000e_phy_has_link_generic - Polls PHY for link
  1473. * @hw: pointer to the HW structure
  1474. * @iterations: number of times to poll for link
  1475. * @usec_interval: delay between polling attempts
  1476. * @success: pointer to whether polling was successful or not
  1477. *
  1478. * Polls the PHY status register for link, 'iterations' number of times.
  1479. **/
  1480. s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
  1481. u32 usec_interval, bool *success)
  1482. {
  1483. s32 ret_val = 0;
  1484. u16 i, phy_status;
  1485. *success = false;
  1486. for (i = 0; i < iterations; i++) {
  1487. /* Some PHYs require the MII_BMSR register to be read
  1488. * twice due to the link bit being sticky. No harm doing
  1489. * it across the board.
  1490. */
  1491. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1492. if (ret_val) {
  1493. /* If the first read fails, another entity may have
  1494. * ownership of the resources, wait and try again to
  1495. * see if they have relinquished the resources yet.
  1496. */
  1497. if (usec_interval >= 1000)
  1498. msleep(usec_interval / 1000);
  1499. else
  1500. udelay(usec_interval);
  1501. }
  1502. ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
  1503. if (ret_val)
  1504. break;
  1505. if (phy_status & BMSR_LSTATUS) {
  1506. *success = true;
  1507. break;
  1508. }
  1509. if (usec_interval >= 1000)
  1510. msleep(usec_interval / 1000);
  1511. else
  1512. udelay(usec_interval);
  1513. }
  1514. return ret_val;
  1515. }
  1516. /**
  1517. * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
  1518. * @hw: pointer to the HW structure
  1519. *
  1520. * Reads the PHY specific status register to retrieve the cable length
  1521. * information. The cable length is determined by averaging the minimum and
  1522. * maximum values to get the "average" cable length. The m88 PHY has four
  1523. * possible cable length values, which are:
  1524. * Register Value Cable Length
  1525. * 0 < 50 meters
  1526. * 1 50 - 80 meters
  1527. * 2 80 - 110 meters
  1528. * 3 110 - 140 meters
  1529. * 4 > 140 meters
  1530. **/
  1531. s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
  1532. {
  1533. struct e1000_phy_info *phy = &hw->phy;
  1534. s32 ret_val;
  1535. u16 phy_data, index;
  1536. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1537. if (ret_val)
  1538. return ret_val;
  1539. index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1540. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  1541. if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
  1542. return -E1000_ERR_PHY;
  1543. phy->min_cable_length = e1000_m88_cable_length_table[index];
  1544. phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
  1545. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1546. return 0;
  1547. }
  1548. /**
  1549. * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
  1550. * @hw: pointer to the HW structure
  1551. *
  1552. * The automatic gain control (agc) normalizes the amplitude of the
  1553. * received signal, adjusting for the attenuation produced by the
  1554. * cable. By reading the AGC registers, which represent the
  1555. * combination of coarse and fine gain value, the value can be put
  1556. * into a lookup table to obtain the approximate cable length
  1557. * for each channel.
  1558. **/
  1559. s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
  1560. {
  1561. struct e1000_phy_info *phy = &hw->phy;
  1562. s32 ret_val;
  1563. u16 phy_data, i, agc_value = 0;
  1564. u16 cur_agc_index, max_agc_index = 0;
  1565. u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
  1566. static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
  1567. IGP02E1000_PHY_AGC_A,
  1568. IGP02E1000_PHY_AGC_B,
  1569. IGP02E1000_PHY_AGC_C,
  1570. IGP02E1000_PHY_AGC_D
  1571. };
  1572. /* Read the AGC registers for all channels */
  1573. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  1574. ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
  1575. if (ret_val)
  1576. return ret_val;
  1577. /* Getting bits 15:9, which represent the combination of
  1578. * coarse and fine gain values. The result is a number
  1579. * that can be put into the lookup table to obtain the
  1580. * approximate cable length.
  1581. */
  1582. cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  1583. IGP02E1000_AGC_LENGTH_MASK);
  1584. /* Array index bound check. */
  1585. if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
  1586. (cur_agc_index == 0))
  1587. return -E1000_ERR_PHY;
  1588. /* Remove min & max AGC values from calculation. */
  1589. if (e1000_igp_2_cable_length_table[min_agc_index] >
  1590. e1000_igp_2_cable_length_table[cur_agc_index])
  1591. min_agc_index = cur_agc_index;
  1592. if (e1000_igp_2_cable_length_table[max_agc_index] <
  1593. e1000_igp_2_cable_length_table[cur_agc_index])
  1594. max_agc_index = cur_agc_index;
  1595. agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
  1596. }
  1597. agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
  1598. e1000_igp_2_cable_length_table[max_agc_index]);
  1599. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  1600. /* Calculate cable length with the error range of +/- 10 meters. */
  1601. phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  1602. (agc_value - IGP02E1000_AGC_RANGE) : 0);
  1603. phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
  1604. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1605. return 0;
  1606. }
  1607. /**
  1608. * e1000e_get_phy_info_m88 - Retrieve PHY information
  1609. * @hw: pointer to the HW structure
  1610. *
  1611. * Valid for only copper links. Read the PHY status register (sticky read)
  1612. * to verify that link is up. Read the PHY special control register to
  1613. * determine the polarity and 10base-T extended distance. Read the PHY
  1614. * special status register to determine MDI/MDIx and current speed. If
  1615. * speed is 1000, then determine cable length, local and remote receiver.
  1616. **/
  1617. s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
  1618. {
  1619. struct e1000_phy_info *phy = &hw->phy;
  1620. s32 ret_val;
  1621. u16 phy_data;
  1622. bool link;
  1623. if (phy->media_type != e1000_media_type_copper) {
  1624. e_dbg("Phy info is only valid for copper media\n");
  1625. return -E1000_ERR_CONFIG;
  1626. }
  1627. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1628. if (ret_val)
  1629. return ret_val;
  1630. if (!link) {
  1631. e_dbg("Phy info is only valid if link is up\n");
  1632. return -E1000_ERR_CONFIG;
  1633. }
  1634. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1635. if (ret_val)
  1636. return ret_val;
  1637. phy->polarity_correction = !!(phy_data &
  1638. M88E1000_PSCR_POLARITY_REVERSAL);
  1639. ret_val = e1000_check_polarity_m88(hw);
  1640. if (ret_val)
  1641. return ret_val;
  1642. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1643. if (ret_val)
  1644. return ret_val;
  1645. phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
  1646. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  1647. ret_val = hw->phy.ops.get_cable_length(hw);
  1648. if (ret_val)
  1649. return ret_val;
  1650. ret_val = e1e_rphy(hw, MII_STAT1000, &phy_data);
  1651. if (ret_val)
  1652. return ret_val;
  1653. phy->local_rx = (phy_data & LPA_1000LOCALRXOK)
  1654. ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  1655. phy->remote_rx = (phy_data & LPA_1000REMRXOK)
  1656. ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  1657. } else {
  1658. /* Set values to "undefined" */
  1659. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1660. phy->local_rx = e1000_1000t_rx_status_undefined;
  1661. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1662. }
  1663. return ret_val;
  1664. }
  1665. /**
  1666. * e1000e_get_phy_info_igp - Retrieve igp PHY information
  1667. * @hw: pointer to the HW structure
  1668. *
  1669. * Read PHY status to determine if link is up. If link is up, then
  1670. * set/determine 10base-T extended distance and polarity correction. Read
  1671. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  1672. * determine on the cable length, local and remote receiver.
  1673. **/
  1674. s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
  1675. {
  1676. struct e1000_phy_info *phy = &hw->phy;
  1677. s32 ret_val;
  1678. u16 data;
  1679. bool link;
  1680. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1681. if (ret_val)
  1682. return ret_val;
  1683. if (!link) {
  1684. e_dbg("Phy info is only valid if link is up\n");
  1685. return -E1000_ERR_CONFIG;
  1686. }
  1687. phy->polarity_correction = true;
  1688. ret_val = e1000_check_polarity_igp(hw);
  1689. if (ret_val)
  1690. return ret_val;
  1691. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1692. if (ret_val)
  1693. return ret_val;
  1694. phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
  1695. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1696. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1697. ret_val = phy->ops.get_cable_length(hw);
  1698. if (ret_val)
  1699. return ret_val;
  1700. ret_val = e1e_rphy(hw, MII_STAT1000, &data);
  1701. if (ret_val)
  1702. return ret_val;
  1703. phy->local_rx = (data & LPA_1000LOCALRXOK)
  1704. ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  1705. phy->remote_rx = (data & LPA_1000REMRXOK)
  1706. ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
  1707. } else {
  1708. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1709. phy->local_rx = e1000_1000t_rx_status_undefined;
  1710. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1711. }
  1712. return ret_val;
  1713. }
  1714. /**
  1715. * e1000_get_phy_info_ife - Retrieves various IFE PHY states
  1716. * @hw: pointer to the HW structure
  1717. *
  1718. * Populates "phy" structure with various feature states.
  1719. **/
  1720. s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
  1721. {
  1722. struct e1000_phy_info *phy = &hw->phy;
  1723. s32 ret_val;
  1724. u16 data;
  1725. bool link;
  1726. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1727. if (ret_val)
  1728. return ret_val;
  1729. if (!link) {
  1730. e_dbg("Phy info is only valid if link is up\n");
  1731. return -E1000_ERR_CONFIG;
  1732. }
  1733. ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
  1734. if (ret_val)
  1735. return ret_val;
  1736. phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
  1737. if (phy->polarity_correction) {
  1738. ret_val = e1000_check_polarity_ife(hw);
  1739. if (ret_val)
  1740. return ret_val;
  1741. } else {
  1742. /* Polarity is forced */
  1743. phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
  1744. ? e1000_rev_polarity_reversed
  1745. : e1000_rev_polarity_normal);
  1746. }
  1747. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
  1748. if (ret_val)
  1749. return ret_val;
  1750. phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
  1751. /* The following parameters are undefined for 10/100 operation. */
  1752. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1753. phy->local_rx = e1000_1000t_rx_status_undefined;
  1754. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1755. return 0;
  1756. }
  1757. /**
  1758. * e1000e_phy_sw_reset - PHY software reset
  1759. * @hw: pointer to the HW structure
  1760. *
  1761. * Does a software reset of the PHY by reading the PHY control register and
  1762. * setting/write the control register reset bit to the PHY.
  1763. **/
  1764. s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
  1765. {
  1766. s32 ret_val;
  1767. u16 phy_ctrl;
  1768. ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
  1769. if (ret_val)
  1770. return ret_val;
  1771. phy_ctrl |= BMCR_RESET;
  1772. ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
  1773. if (ret_val)
  1774. return ret_val;
  1775. udelay(1);
  1776. return ret_val;
  1777. }
  1778. /**
  1779. * e1000e_phy_hw_reset_generic - PHY hardware reset
  1780. * @hw: pointer to the HW structure
  1781. *
  1782. * Verify the reset block is not blocking us from resetting. Acquire
  1783. * semaphore (if necessary) and read/set/write the device control reset
  1784. * bit in the PHY. Wait the appropriate delay time for the device to
  1785. * reset and release the semaphore (if necessary).
  1786. **/
  1787. s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
  1788. {
  1789. struct e1000_phy_info *phy = &hw->phy;
  1790. s32 ret_val;
  1791. u32 ctrl;
  1792. if (phy->ops.check_reset_block) {
  1793. ret_val = phy->ops.check_reset_block(hw);
  1794. if (ret_val)
  1795. return 0;
  1796. }
  1797. ret_val = phy->ops.acquire(hw);
  1798. if (ret_val)
  1799. return ret_val;
  1800. ctrl = er32(CTRL);
  1801. ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
  1802. e1e_flush();
  1803. udelay(phy->reset_delay_us);
  1804. ew32(CTRL, ctrl);
  1805. e1e_flush();
  1806. usleep_range(150, 300);
  1807. phy->ops.release(hw);
  1808. return phy->ops.get_cfg_done(hw);
  1809. }
  1810. /**
  1811. * e1000e_get_cfg_done_generic - Generic configuration done
  1812. * @hw: pointer to the HW structure
  1813. *
  1814. * Generic function to wait 10 milli-seconds for configuration to complete
  1815. * and return success.
  1816. **/
  1817. s32 e1000e_get_cfg_done_generic(struct e1000_hw __always_unused *hw)
  1818. {
  1819. mdelay(10);
  1820. return 0;
  1821. }
  1822. /**
  1823. * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
  1824. * @hw: pointer to the HW structure
  1825. *
  1826. * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
  1827. **/
  1828. s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
  1829. {
  1830. e_dbg("Running IGP 3 PHY init script\n");
  1831. /* PHY init IGP 3 */
  1832. /* Enable rise/fall, 10-mode work in class-A */
  1833. e1e_wphy(hw, 0x2F5B, 0x9018);
  1834. /* Remove all caps from Replica path filter */
  1835. e1e_wphy(hw, 0x2F52, 0x0000);
  1836. /* Bias trimming for ADC, AFE and Driver (Default) */
  1837. e1e_wphy(hw, 0x2FB1, 0x8B24);
  1838. /* Increase Hybrid poly bias */
  1839. e1e_wphy(hw, 0x2FB2, 0xF8F0);
  1840. /* Add 4% to Tx amplitude in Gig mode */
  1841. e1e_wphy(hw, 0x2010, 0x10B0);
  1842. /* Disable trimming (TTT) */
  1843. e1e_wphy(hw, 0x2011, 0x0000);
  1844. /* Poly DC correction to 94.6% + 2% for all channels */
  1845. e1e_wphy(hw, 0x20DD, 0x249A);
  1846. /* ABS DC correction to 95.9% */
  1847. e1e_wphy(hw, 0x20DE, 0x00D3);
  1848. /* BG temp curve trim */
  1849. e1e_wphy(hw, 0x28B4, 0x04CE);
  1850. /* Increasing ADC OPAMP stage 1 currents to max */
  1851. e1e_wphy(hw, 0x2F70, 0x29E4);
  1852. /* Force 1000 ( required for enabling PHY regs configuration) */
  1853. e1e_wphy(hw, 0x0000, 0x0140);
  1854. /* Set upd_freq to 6 */
  1855. e1e_wphy(hw, 0x1F30, 0x1606);
  1856. /* Disable NPDFE */
  1857. e1e_wphy(hw, 0x1F31, 0xB814);
  1858. /* Disable adaptive fixed FFE (Default) */
  1859. e1e_wphy(hw, 0x1F35, 0x002A);
  1860. /* Enable FFE hysteresis */
  1861. e1e_wphy(hw, 0x1F3E, 0x0067);
  1862. /* Fixed FFE for short cable lengths */
  1863. e1e_wphy(hw, 0x1F54, 0x0065);
  1864. /* Fixed FFE for medium cable lengths */
  1865. e1e_wphy(hw, 0x1F55, 0x002A);
  1866. /* Fixed FFE for long cable lengths */
  1867. e1e_wphy(hw, 0x1F56, 0x002A);
  1868. /* Enable Adaptive Clip Threshold */
  1869. e1e_wphy(hw, 0x1F72, 0x3FB0);
  1870. /* AHT reset limit to 1 */
  1871. e1e_wphy(hw, 0x1F76, 0xC0FF);
  1872. /* Set AHT master delay to 127 msec */
  1873. e1e_wphy(hw, 0x1F77, 0x1DEC);
  1874. /* Set scan bits for AHT */
  1875. e1e_wphy(hw, 0x1F78, 0xF9EF);
  1876. /* Set AHT Preset bits */
  1877. e1e_wphy(hw, 0x1F79, 0x0210);
  1878. /* Change integ_factor of channel A to 3 */
  1879. e1e_wphy(hw, 0x1895, 0x0003);
  1880. /* Change prop_factor of channels BCD to 8 */
  1881. e1e_wphy(hw, 0x1796, 0x0008);
  1882. /* Change cg_icount + enable integbp for channels BCD */
  1883. e1e_wphy(hw, 0x1798, 0xD008);
  1884. /* Change cg_icount + enable integbp + change prop_factor_master
  1885. * to 8 for channel A
  1886. */
  1887. e1e_wphy(hw, 0x1898, 0xD918);
  1888. /* Disable AHT in Slave mode on channel A */
  1889. e1e_wphy(hw, 0x187A, 0x0800);
  1890. /* Enable LPLU and disable AN to 1000 in non-D0a states,
  1891. * Enable SPD+B2B
  1892. */
  1893. e1e_wphy(hw, 0x0019, 0x008D);
  1894. /* Enable restart AN on an1000_dis change */
  1895. e1e_wphy(hw, 0x001B, 0x2080);
  1896. /* Enable wh_fifo read clock in 10/100 modes */
  1897. e1e_wphy(hw, 0x0014, 0x0045);
  1898. /* Restart AN, Speed selection is 1000 */
  1899. e1e_wphy(hw, 0x0000, 0x1340);
  1900. return 0;
  1901. }
  1902. /**
  1903. * e1000e_get_phy_type_from_id - Get PHY type from id
  1904. * @phy_id: phy_id read from the phy
  1905. *
  1906. * Returns the phy type from the id.
  1907. **/
  1908. enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
  1909. {
  1910. enum e1000_phy_type phy_type = e1000_phy_unknown;
  1911. switch (phy_id) {
  1912. case M88E1000_I_PHY_ID:
  1913. case M88E1000_E_PHY_ID:
  1914. case M88E1111_I_PHY_ID:
  1915. case M88E1011_I_PHY_ID:
  1916. phy_type = e1000_phy_m88;
  1917. break;
  1918. case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
  1919. phy_type = e1000_phy_igp_2;
  1920. break;
  1921. case GG82563_E_PHY_ID:
  1922. phy_type = e1000_phy_gg82563;
  1923. break;
  1924. case IGP03E1000_E_PHY_ID:
  1925. phy_type = e1000_phy_igp_3;
  1926. break;
  1927. case IFE_E_PHY_ID:
  1928. case IFE_PLUS_E_PHY_ID:
  1929. case IFE_C_E_PHY_ID:
  1930. phy_type = e1000_phy_ife;
  1931. break;
  1932. case BME1000_E_PHY_ID:
  1933. case BME1000_E_PHY_ID_R2:
  1934. phy_type = e1000_phy_bm;
  1935. break;
  1936. case I82578_E_PHY_ID:
  1937. phy_type = e1000_phy_82578;
  1938. break;
  1939. case I82577_E_PHY_ID:
  1940. phy_type = e1000_phy_82577;
  1941. break;
  1942. case I82579_E_PHY_ID:
  1943. phy_type = e1000_phy_82579;
  1944. break;
  1945. case I217_E_PHY_ID:
  1946. phy_type = e1000_phy_i217;
  1947. break;
  1948. default:
  1949. phy_type = e1000_phy_unknown;
  1950. break;
  1951. }
  1952. return phy_type;
  1953. }
  1954. /**
  1955. * e1000e_determine_phy_address - Determines PHY address.
  1956. * @hw: pointer to the HW structure
  1957. *
  1958. * This uses a trial and error method to loop through possible PHY
  1959. * addresses. It tests each by reading the PHY ID registers and
  1960. * checking for a match.
  1961. **/
  1962. s32 e1000e_determine_phy_address(struct e1000_hw *hw)
  1963. {
  1964. u32 phy_addr = 0;
  1965. u32 i;
  1966. enum e1000_phy_type phy_type = e1000_phy_unknown;
  1967. hw->phy.id = phy_type;
  1968. for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
  1969. hw->phy.addr = phy_addr;
  1970. i = 0;
  1971. do {
  1972. e1000e_get_phy_id(hw);
  1973. phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
  1974. /* If phy_type is valid, break - we found our
  1975. * PHY address
  1976. */
  1977. if (phy_type != e1000_phy_unknown)
  1978. return 0;
  1979. usleep_range(1000, 2000);
  1980. i++;
  1981. } while (i < 10);
  1982. }
  1983. return -E1000_ERR_PHY_TYPE;
  1984. }
  1985. /**
  1986. * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
  1987. * @page: page to access
  1988. *
  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 & BIT(11))) {
  2477. u16 data2 = 0x7EFF;
  2478. ret_val = e1000_access_phy_debug_regs_hv(hw,
  2479. BIT(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. }