phy.c 91 KB

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