phy.c 90 KB

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