phy.c 87 KB

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