phy.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2008 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. /* Cable length tables */
  28. static const u16 e1000_m88_cable_length_table[] =
  29. { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
  30. static const u16 e1000_igp_2_cable_length_table[] =
  31. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
  32. 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
  33. 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
  34. 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
  35. 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
  36. 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
  37. 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
  38. 124};
  39. #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
  40. ARRAY_SIZE(e1000_igp_2_cable_length_table)
  41. /**
  42. * e1000e_check_reset_block_generic - Check if PHY reset is blocked
  43. * @hw: pointer to the HW structure
  44. *
  45. * Read the PHY management control register and check whether a PHY reset
  46. * is blocked. If a reset is not blocked return 0, otherwise
  47. * return E1000_BLK_PHY_RESET (12).
  48. **/
  49. s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
  50. {
  51. u32 manc;
  52. manc = er32(MANC);
  53. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  54. E1000_BLK_PHY_RESET : 0;
  55. }
  56. /**
  57. * e1000e_get_phy_id - Retrieve the PHY ID and revision
  58. * @hw: pointer to the HW structure
  59. *
  60. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  61. * revision in the hardware structure.
  62. **/
  63. s32 e1000e_get_phy_id(struct e1000_hw *hw)
  64. {
  65. struct e1000_phy_info *phy = &hw->phy;
  66. s32 ret_val;
  67. u16 phy_id;
  68. ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
  69. if (ret_val)
  70. return ret_val;
  71. phy->id = (u32)(phy_id << 16);
  72. udelay(20);
  73. ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
  74. if (ret_val)
  75. return ret_val;
  76. phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
  77. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  78. return 0;
  79. }
  80. /**
  81. * e1000e_phy_reset_dsp - Reset PHY DSP
  82. * @hw: pointer to the HW structure
  83. *
  84. * Reset the digital signal processor.
  85. **/
  86. s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
  87. {
  88. s32 ret_val;
  89. ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
  90. if (ret_val)
  91. return ret_val;
  92. return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
  93. }
  94. /**
  95. * e1000e_read_phy_reg_mdic - Read MDI control register
  96. * @hw: pointer to the HW structure
  97. * @offset: register offset to be read
  98. * @data: pointer to the read data
  99. *
  100. * Reads the MDI control register in the PHY at offset and stores the
  101. * information read to data.
  102. **/
  103. s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
  104. {
  105. struct e1000_phy_info *phy = &hw->phy;
  106. u32 i, mdic = 0;
  107. if (offset > MAX_PHY_REG_ADDRESS) {
  108. hw_dbg(hw, "PHY Address %d is out of range\n", offset);
  109. return -E1000_ERR_PARAM;
  110. }
  111. /*
  112. * Set up Op-code, Phy Address, and register offset in the MDI
  113. * Control register. The MAC will take care of interfacing with the
  114. * PHY to retrieve the desired data.
  115. */
  116. mdic = ((offset << E1000_MDIC_REG_SHIFT) |
  117. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  118. (E1000_MDIC_OP_READ));
  119. ew32(MDIC, mdic);
  120. /*
  121. * Poll the ready bit to see if the MDI read completed
  122. * Increasing the time out as testing showed failures with
  123. * the lower time out
  124. */
  125. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  126. udelay(50);
  127. mdic = er32(MDIC);
  128. if (mdic & E1000_MDIC_READY)
  129. break;
  130. }
  131. if (!(mdic & E1000_MDIC_READY)) {
  132. hw_dbg(hw, "MDI Read did not complete\n");
  133. return -E1000_ERR_PHY;
  134. }
  135. if (mdic & E1000_MDIC_ERROR) {
  136. hw_dbg(hw, "MDI Error\n");
  137. return -E1000_ERR_PHY;
  138. }
  139. *data = (u16) mdic;
  140. return 0;
  141. }
  142. /**
  143. * e1000e_write_phy_reg_mdic - Write MDI control register
  144. * @hw: pointer to the HW structure
  145. * @offset: register offset to write to
  146. * @data: data to write to register at offset
  147. *
  148. * Writes data to MDI control register in the PHY at offset.
  149. **/
  150. s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
  151. {
  152. struct e1000_phy_info *phy = &hw->phy;
  153. u32 i, mdic = 0;
  154. if (offset > MAX_PHY_REG_ADDRESS) {
  155. hw_dbg(hw, "PHY Address %d is out of range\n", offset);
  156. return -E1000_ERR_PARAM;
  157. }
  158. /*
  159. * Set up Op-code, Phy Address, and register offset in the MDI
  160. * Control register. The MAC will take care of interfacing with the
  161. * PHY to retrieve the desired data.
  162. */
  163. mdic = (((u32)data) |
  164. (offset << E1000_MDIC_REG_SHIFT) |
  165. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  166. (E1000_MDIC_OP_WRITE));
  167. ew32(MDIC, mdic);
  168. /*
  169. * Poll the ready bit to see if the MDI read completed
  170. * Increasing the time out as testing showed failures with
  171. * the lower time out
  172. */
  173. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  174. udelay(50);
  175. mdic = er32(MDIC);
  176. if (mdic & E1000_MDIC_READY)
  177. break;
  178. }
  179. if (!(mdic & E1000_MDIC_READY)) {
  180. hw_dbg(hw, "MDI Write did not complete\n");
  181. return -E1000_ERR_PHY;
  182. }
  183. if (mdic & E1000_MDIC_ERROR) {
  184. hw_dbg(hw, "MDI Error\n");
  185. return -E1000_ERR_PHY;
  186. }
  187. return 0;
  188. }
  189. /**
  190. * e1000e_read_phy_reg_m88 - Read m88 PHY register
  191. * @hw: pointer to the HW structure
  192. * @offset: register offset to be read
  193. * @data: pointer to the read data
  194. *
  195. * Acquires semaphore, if necessary, then reads the PHY register at offset
  196. * and storing the retrieved information in data. Release any acquired
  197. * semaphores before exiting.
  198. **/
  199. s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
  200. {
  201. s32 ret_val;
  202. ret_val = hw->phy.ops.acquire_phy(hw);
  203. if (ret_val)
  204. return ret_val;
  205. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  206. data);
  207. hw->phy.ops.release_phy(hw);
  208. return ret_val;
  209. }
  210. /**
  211. * e1000e_write_phy_reg_m88 - Write m88 PHY register
  212. * @hw: pointer to the HW structure
  213. * @offset: register offset to write to
  214. * @data: data to write at register offset
  215. *
  216. * Acquires semaphore, if necessary, then writes the data to PHY register
  217. * at the offset. Release any acquired semaphores before exiting.
  218. **/
  219. s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
  220. {
  221. s32 ret_val;
  222. ret_val = hw->phy.ops.acquire_phy(hw);
  223. if (ret_val)
  224. return ret_val;
  225. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  226. data);
  227. hw->phy.ops.release_phy(hw);
  228. return ret_val;
  229. }
  230. /**
  231. * e1000e_read_phy_reg_igp - Read igp PHY register
  232. * @hw: pointer to the HW structure
  233. * @offset: register offset to be read
  234. * @data: pointer to the read data
  235. *
  236. * Acquires semaphore, if necessary, then reads the PHY register at offset
  237. * and storing the retrieved information in data. Release any acquired
  238. * semaphores before exiting.
  239. **/
  240. s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
  241. {
  242. s32 ret_val;
  243. ret_val = hw->phy.ops.acquire_phy(hw);
  244. if (ret_val)
  245. return ret_val;
  246. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  247. ret_val = e1000e_write_phy_reg_mdic(hw,
  248. IGP01E1000_PHY_PAGE_SELECT,
  249. (u16)offset);
  250. if (ret_val) {
  251. hw->phy.ops.release_phy(hw);
  252. return ret_val;
  253. }
  254. }
  255. ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  256. data);
  257. hw->phy.ops.release_phy(hw);
  258. return ret_val;
  259. }
  260. /**
  261. * e1000e_write_phy_reg_igp - Write igp PHY register
  262. * @hw: pointer to the HW structure
  263. * @offset: register offset to write to
  264. * @data: data to write at register offset
  265. *
  266. * Acquires semaphore, if necessary, then writes the data to PHY register
  267. * at the offset. Release any acquired semaphores before exiting.
  268. **/
  269. s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
  270. {
  271. s32 ret_val;
  272. ret_val = hw->phy.ops.acquire_phy(hw);
  273. if (ret_val)
  274. return ret_val;
  275. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  276. ret_val = e1000e_write_phy_reg_mdic(hw,
  277. IGP01E1000_PHY_PAGE_SELECT,
  278. (u16)offset);
  279. if (ret_val) {
  280. hw->phy.ops.release_phy(hw);
  281. return ret_val;
  282. }
  283. }
  284. ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  285. data);
  286. hw->phy.ops.release_phy(hw);
  287. return ret_val;
  288. }
  289. /**
  290. * e1000e_read_kmrn_reg - Read kumeran register
  291. * @hw: pointer to the HW structure
  292. * @offset: register offset to be read
  293. * @data: pointer to the read data
  294. *
  295. * Acquires semaphore, if necessary. Then reads the PHY register at offset
  296. * using the kumeran interface. The information retrieved is stored in data.
  297. * Release any acquired semaphores before exiting.
  298. **/
  299. s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
  300. {
  301. u32 kmrnctrlsta;
  302. s32 ret_val;
  303. ret_val = hw->phy.ops.acquire_phy(hw);
  304. if (ret_val)
  305. return ret_val;
  306. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  307. E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
  308. ew32(KMRNCTRLSTA, kmrnctrlsta);
  309. udelay(2);
  310. kmrnctrlsta = er32(KMRNCTRLSTA);
  311. *data = (u16)kmrnctrlsta;
  312. hw->phy.ops.release_phy(hw);
  313. return ret_val;
  314. }
  315. /**
  316. * e1000e_write_kmrn_reg - Write kumeran register
  317. * @hw: pointer to the HW structure
  318. * @offset: register offset to write to
  319. * @data: data to write at register offset
  320. *
  321. * Acquires semaphore, if necessary. Then write the data to PHY register
  322. * at the offset using the kumeran interface. Release any acquired semaphores
  323. * before exiting.
  324. **/
  325. s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
  326. {
  327. u32 kmrnctrlsta;
  328. s32 ret_val;
  329. ret_val = hw->phy.ops.acquire_phy(hw);
  330. if (ret_val)
  331. return ret_val;
  332. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  333. E1000_KMRNCTRLSTA_OFFSET) | data;
  334. ew32(KMRNCTRLSTA, kmrnctrlsta);
  335. udelay(2);
  336. hw->phy.ops.release_phy(hw);
  337. return ret_val;
  338. }
  339. /**
  340. * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
  341. * @hw: pointer to the HW structure
  342. *
  343. * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
  344. * and downshift values are set also.
  345. **/
  346. s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
  347. {
  348. struct e1000_phy_info *phy = &hw->phy;
  349. s32 ret_val;
  350. u16 phy_data;
  351. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  352. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  353. if (ret_val)
  354. return ret_val;
  355. /* For newer PHYs this bit is downshift enable */
  356. if (phy->type == e1000_phy_m88)
  357. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  358. /*
  359. * Options:
  360. * MDI/MDI-X = 0 (default)
  361. * 0 - Auto for all speeds
  362. * 1 - MDI mode
  363. * 2 - MDI-X mode
  364. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  365. */
  366. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  367. switch (phy->mdix) {
  368. case 1:
  369. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  370. break;
  371. case 2:
  372. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  373. break;
  374. case 3:
  375. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  376. break;
  377. case 0:
  378. default:
  379. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  380. break;
  381. }
  382. /*
  383. * Options:
  384. * disable_polarity_correction = 0 (default)
  385. * Automatic Correction for Reversed Cable Polarity
  386. * 0 - Disabled
  387. * 1 - Enabled
  388. */
  389. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  390. if (phy->disable_polarity_correction == 1)
  391. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  392. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  393. if (ret_val)
  394. return ret_val;
  395. if ((phy->type == e1000_phy_m88) && (phy->revision < 4)) {
  396. /*
  397. * Force TX_CLK in the Extended PHY Specific Control Register
  398. * to 25MHz clock.
  399. */
  400. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  401. if (ret_val)
  402. return ret_val;
  403. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  404. if ((phy->revision == 2) &&
  405. (phy->id == M88E1111_I_PHY_ID)) {
  406. /* 82573L PHY - set the downshift counter to 5x. */
  407. phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
  408. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  409. } else {
  410. /* Configure Master and Slave downshift values */
  411. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  412. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  413. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  414. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  415. }
  416. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  417. if (ret_val)
  418. return ret_val;
  419. }
  420. /* Commit the changes. */
  421. ret_val = e1000e_commit_phy(hw);
  422. if (ret_val)
  423. hw_dbg(hw, "Error committing the PHY changes\n");
  424. return ret_val;
  425. }
  426. /**
  427. * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
  428. * @hw: pointer to the HW structure
  429. *
  430. * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
  431. * igp PHY's.
  432. **/
  433. s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
  434. {
  435. struct e1000_phy_info *phy = &hw->phy;
  436. s32 ret_val;
  437. u16 data;
  438. ret_val = e1000_phy_hw_reset(hw);
  439. if (ret_val) {
  440. hw_dbg(hw, "Error resetting the PHY.\n");
  441. return ret_val;
  442. }
  443. /*
  444. * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
  445. * timeout issues when LFS is enabled.
  446. */
  447. msleep(100);
  448. /* disable lplu d0 during driver init */
  449. ret_val = e1000_set_d0_lplu_state(hw, 0);
  450. if (ret_val) {
  451. hw_dbg(hw, "Error Disabling LPLU D0\n");
  452. return ret_val;
  453. }
  454. /* Configure mdi-mdix settings */
  455. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
  456. if (ret_val)
  457. return ret_val;
  458. data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  459. switch (phy->mdix) {
  460. case 1:
  461. data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  462. break;
  463. case 2:
  464. data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  465. break;
  466. case 0:
  467. default:
  468. data |= IGP01E1000_PSCR_AUTO_MDIX;
  469. break;
  470. }
  471. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
  472. if (ret_val)
  473. return ret_val;
  474. /* set auto-master slave resolution settings */
  475. if (hw->mac.autoneg) {
  476. /*
  477. * when autonegotiation advertisement is only 1000Mbps then we
  478. * should disable SmartSpeed and enable Auto MasterSlave
  479. * resolution as hardware default.
  480. */
  481. if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
  482. /* Disable SmartSpeed */
  483. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  484. &data);
  485. if (ret_val)
  486. return ret_val;
  487. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  488. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  489. data);
  490. if (ret_val)
  491. return ret_val;
  492. /* Set auto Master/Slave resolution process */
  493. ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
  494. if (ret_val)
  495. return ret_val;
  496. data &= ~CR_1000T_MS_ENABLE;
  497. ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
  498. if (ret_val)
  499. return ret_val;
  500. }
  501. ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
  502. if (ret_val)
  503. return ret_val;
  504. /* load defaults for future use */
  505. phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
  506. ((data & CR_1000T_MS_VALUE) ?
  507. e1000_ms_force_master :
  508. e1000_ms_force_slave) :
  509. e1000_ms_auto;
  510. switch (phy->ms_type) {
  511. case e1000_ms_force_master:
  512. data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  513. break;
  514. case e1000_ms_force_slave:
  515. data |= CR_1000T_MS_ENABLE;
  516. data &= ~(CR_1000T_MS_VALUE);
  517. break;
  518. case e1000_ms_auto:
  519. data &= ~CR_1000T_MS_ENABLE;
  520. default:
  521. break;
  522. }
  523. ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
  524. }
  525. return ret_val;
  526. }
  527. /**
  528. * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
  529. * @hw: pointer to the HW structure
  530. *
  531. * Reads the MII auto-neg advertisement register and/or the 1000T control
  532. * register and if the PHY is already setup for auto-negotiation, then
  533. * return successful. Otherwise, setup advertisement and flow control to
  534. * the appropriate values for the wanted auto-negotiation.
  535. **/
  536. static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
  537. {
  538. struct e1000_phy_info *phy = &hw->phy;
  539. s32 ret_val;
  540. u16 mii_autoneg_adv_reg;
  541. u16 mii_1000t_ctrl_reg = 0;
  542. phy->autoneg_advertised &= phy->autoneg_mask;
  543. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  544. ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  545. if (ret_val)
  546. return ret_val;
  547. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  548. /* Read the MII 1000Base-T Control Register (Address 9). */
  549. ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  550. if (ret_val)
  551. return ret_val;
  552. }
  553. /*
  554. * Need to parse both autoneg_advertised and fc and set up
  555. * the appropriate PHY registers. First we will parse for
  556. * autoneg_advertised software override. Since we can advertise
  557. * a plethora of combinations, we need to check each bit
  558. * individually.
  559. */
  560. /*
  561. * First we clear all the 10/100 mb speed bits in the Auto-Neg
  562. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  563. * the 1000Base-T Control Register (Address 9).
  564. */
  565. mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
  566. NWAY_AR_100TX_HD_CAPS |
  567. NWAY_AR_10T_FD_CAPS |
  568. NWAY_AR_10T_HD_CAPS);
  569. mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
  570. hw_dbg(hw, "autoneg_advertised %x\n", phy->autoneg_advertised);
  571. /* Do we want to advertise 10 Mb Half Duplex? */
  572. if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
  573. hw_dbg(hw, "Advertise 10mb Half duplex\n");
  574. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  575. }
  576. /* Do we want to advertise 10 Mb Full Duplex? */
  577. if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
  578. hw_dbg(hw, "Advertise 10mb Full duplex\n");
  579. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  580. }
  581. /* Do we want to advertise 100 Mb Half Duplex? */
  582. if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
  583. hw_dbg(hw, "Advertise 100mb Half duplex\n");
  584. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  585. }
  586. /* Do we want to advertise 100 Mb Full Duplex? */
  587. if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
  588. hw_dbg(hw, "Advertise 100mb Full duplex\n");
  589. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  590. }
  591. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  592. if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
  593. hw_dbg(hw, "Advertise 1000mb Half duplex request denied!\n");
  594. /* Do we want to advertise 1000 Mb Full Duplex? */
  595. if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
  596. hw_dbg(hw, "Advertise 1000mb Full duplex\n");
  597. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  598. }
  599. /*
  600. * Check for a software override of the flow control settings, and
  601. * setup the PHY advertisement registers accordingly. If
  602. * auto-negotiation is enabled, then software will have to set the
  603. * "PAUSE" bits to the correct value in the Auto-Negotiation
  604. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
  605. * negotiation.
  606. *
  607. * The possible values of the "fc" parameter are:
  608. * 0: Flow control is completely disabled
  609. * 1: Rx flow control is enabled (we can receive pause frames
  610. * but not send pause frames).
  611. * 2: Tx flow control is enabled (we can send pause frames
  612. * but we do not support receiving pause frames).
  613. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  614. * other: No software override. The flow control configuration
  615. * in the EEPROM is used.
  616. */
  617. switch (hw->fc.type) {
  618. case e1000_fc_none:
  619. /*
  620. * Flow control (Rx & Tx) is completely disabled by a
  621. * software over-ride.
  622. */
  623. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  624. break;
  625. case e1000_fc_rx_pause:
  626. /*
  627. * Rx Flow control is enabled, and Tx Flow control is
  628. * disabled, by a software over-ride.
  629. *
  630. * Since there really isn't a way to advertise that we are
  631. * capable of Rx Pause ONLY, we will advertise that we
  632. * support both symmetric and asymmetric Rx PAUSE. Later
  633. * (in e1000e_config_fc_after_link_up) we will disable the
  634. * hw's ability to send PAUSE frames.
  635. */
  636. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  637. break;
  638. case e1000_fc_tx_pause:
  639. /*
  640. * Tx Flow control is enabled, and Rx Flow control is
  641. * disabled, by a software over-ride.
  642. */
  643. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  644. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  645. break;
  646. case e1000_fc_full:
  647. /*
  648. * Flow control (both Rx and Tx) is enabled by a software
  649. * over-ride.
  650. */
  651. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  652. break;
  653. default:
  654. hw_dbg(hw, "Flow control param set incorrectly\n");
  655. ret_val = -E1000_ERR_CONFIG;
  656. return ret_val;
  657. }
  658. ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  659. if (ret_val)
  660. return ret_val;
  661. hw_dbg(hw, "Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  662. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  663. ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
  664. }
  665. return ret_val;
  666. }
  667. /**
  668. * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
  669. * @hw: pointer to the HW structure
  670. *
  671. * Performs initial bounds checking on autoneg advertisement parameter, then
  672. * configure to advertise the full capability. Setup the PHY to autoneg
  673. * and restart the negotiation process between the link partner. If
  674. * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
  675. **/
  676. static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
  677. {
  678. struct e1000_phy_info *phy = &hw->phy;
  679. s32 ret_val;
  680. u16 phy_ctrl;
  681. /*
  682. * Perform some bounds checking on the autoneg advertisement
  683. * parameter.
  684. */
  685. phy->autoneg_advertised &= phy->autoneg_mask;
  686. /*
  687. * If autoneg_advertised is zero, we assume it was not defaulted
  688. * by the calling code so we set to advertise full capability.
  689. */
  690. if (phy->autoneg_advertised == 0)
  691. phy->autoneg_advertised = phy->autoneg_mask;
  692. hw_dbg(hw, "Reconfiguring auto-neg advertisement params\n");
  693. ret_val = e1000_phy_setup_autoneg(hw);
  694. if (ret_val) {
  695. hw_dbg(hw, "Error Setting up Auto-Negotiation\n");
  696. return ret_val;
  697. }
  698. hw_dbg(hw, "Restarting Auto-Neg\n");
  699. /*
  700. * Restart auto-negotiation by setting the Auto Neg Enable bit and
  701. * the Auto Neg Restart bit in the PHY control register.
  702. */
  703. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
  704. if (ret_val)
  705. return ret_val;
  706. phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  707. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
  708. if (ret_val)
  709. return ret_val;
  710. /*
  711. * Does the user want to wait for Auto-Neg to complete here, or
  712. * check at a later time (for example, callback routine).
  713. */
  714. if (phy->autoneg_wait_to_complete) {
  715. ret_val = e1000_wait_autoneg(hw);
  716. if (ret_val) {
  717. hw_dbg(hw, "Error while waiting for "
  718. "autoneg to complete\n");
  719. return ret_val;
  720. }
  721. }
  722. hw->mac.get_link_status = 1;
  723. return ret_val;
  724. }
  725. /**
  726. * e1000e_setup_copper_link - Configure copper link settings
  727. * @hw: pointer to the HW structure
  728. *
  729. * Calls the appropriate function to configure the link for auto-neg or forced
  730. * speed and duplex. Then we check for link, once link is established calls
  731. * to configure collision distance and flow control are called. If link is
  732. * not established, we return -E1000_ERR_PHY (-2).
  733. **/
  734. s32 e1000e_setup_copper_link(struct e1000_hw *hw)
  735. {
  736. s32 ret_val;
  737. bool link;
  738. if (hw->mac.autoneg) {
  739. /*
  740. * Setup autoneg and flow control advertisement and perform
  741. * autonegotiation.
  742. */
  743. ret_val = e1000_copper_link_autoneg(hw);
  744. if (ret_val)
  745. return ret_val;
  746. } else {
  747. /*
  748. * PHY will be set to 10H, 10F, 100H or 100F
  749. * depending on user settings.
  750. */
  751. hw_dbg(hw, "Forcing Speed and Duplex\n");
  752. ret_val = e1000_phy_force_speed_duplex(hw);
  753. if (ret_val) {
  754. hw_dbg(hw, "Error Forcing Speed and Duplex\n");
  755. return ret_val;
  756. }
  757. }
  758. /*
  759. * Check link status. Wait up to 100 microseconds for link to become
  760. * valid.
  761. */
  762. ret_val = e1000e_phy_has_link_generic(hw,
  763. COPPER_LINK_UP_LIMIT,
  764. 10,
  765. &link);
  766. if (ret_val)
  767. return ret_val;
  768. if (link) {
  769. hw_dbg(hw, "Valid link established!!!\n");
  770. e1000e_config_collision_dist(hw);
  771. ret_val = e1000e_config_fc_after_link_up(hw);
  772. } else {
  773. hw_dbg(hw, "Unable to establish link!!!\n");
  774. }
  775. return ret_val;
  776. }
  777. /**
  778. * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
  779. * @hw: pointer to the HW structure
  780. *
  781. * Calls the PHY setup function to force speed and duplex. Clears the
  782. * auto-crossover to force MDI manually. Waits for link and returns
  783. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  784. **/
  785. s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
  786. {
  787. struct e1000_phy_info *phy = &hw->phy;
  788. s32 ret_val;
  789. u16 phy_data;
  790. bool link;
  791. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
  792. if (ret_val)
  793. return ret_val;
  794. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  795. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
  796. if (ret_val)
  797. return ret_val;
  798. /*
  799. * Clear Auto-Crossover to force MDI manually. IGP requires MDI
  800. * forced whenever speed and duplex are forced.
  801. */
  802. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  803. if (ret_val)
  804. return ret_val;
  805. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  806. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  807. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  808. if (ret_val)
  809. return ret_val;
  810. hw_dbg(hw, "IGP PSCR: %X\n", phy_data);
  811. udelay(1);
  812. if (phy->autoneg_wait_to_complete) {
  813. hw_dbg(hw, "Waiting for forced speed/duplex link on IGP phy.\n");
  814. ret_val = e1000e_phy_has_link_generic(hw,
  815. PHY_FORCE_LIMIT,
  816. 100000,
  817. &link);
  818. if (ret_val)
  819. return ret_val;
  820. if (!link)
  821. hw_dbg(hw, "Link taking longer than expected.\n");
  822. /* Try once more */
  823. ret_val = e1000e_phy_has_link_generic(hw,
  824. PHY_FORCE_LIMIT,
  825. 100000,
  826. &link);
  827. if (ret_val)
  828. return ret_val;
  829. }
  830. return ret_val;
  831. }
  832. /**
  833. * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
  834. * @hw: pointer to the HW structure
  835. *
  836. * Calls the PHY setup function to force speed and duplex. Clears the
  837. * auto-crossover to force MDI manually. Resets the PHY to commit the
  838. * changes. If time expires while waiting for link up, we reset the DSP.
  839. * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
  840. * successful completion, else return corresponding error code.
  841. **/
  842. s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
  843. {
  844. struct e1000_phy_info *phy = &hw->phy;
  845. s32 ret_val;
  846. u16 phy_data;
  847. bool link;
  848. /*
  849. * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  850. * forced whenever speed and duplex are forced.
  851. */
  852. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  853. if (ret_val)
  854. return ret_val;
  855. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  856. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  857. if (ret_val)
  858. return ret_val;
  859. hw_dbg(hw, "M88E1000 PSCR: %X\n", phy_data);
  860. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
  861. if (ret_val)
  862. return ret_val;
  863. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  864. /* Reset the phy to commit changes. */
  865. phy_data |= MII_CR_RESET;
  866. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
  867. if (ret_val)
  868. return ret_val;
  869. udelay(1);
  870. if (phy->autoneg_wait_to_complete) {
  871. hw_dbg(hw, "Waiting for forced speed/duplex link on M88 phy.\n");
  872. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  873. 100000, &link);
  874. if (ret_val)
  875. return ret_val;
  876. if (!link) {
  877. /*
  878. * We didn't get link.
  879. * Reset the DSP and cross our fingers.
  880. */
  881. ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
  882. 0x001d);
  883. if (ret_val)
  884. return ret_val;
  885. ret_val = e1000e_phy_reset_dsp(hw);
  886. if (ret_val)
  887. return ret_val;
  888. }
  889. /* Try once more */
  890. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  891. 100000, &link);
  892. if (ret_val)
  893. return ret_val;
  894. }
  895. ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  896. if (ret_val)
  897. return ret_val;
  898. /*
  899. * Resetting the phy means we need to re-force TX_CLK in the
  900. * Extended PHY Specific Control Register to 25MHz clock from
  901. * the reset value of 2.5MHz.
  902. */
  903. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  904. ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  905. if (ret_val)
  906. return ret_val;
  907. /*
  908. * In addition, we must re-enable CRS on Tx for both half and full
  909. * duplex.
  910. */
  911. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  912. if (ret_val)
  913. return ret_val;
  914. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  915. ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  916. return ret_val;
  917. }
  918. /**
  919. * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
  920. * @hw: pointer to the HW structure
  921. * @phy_ctrl: pointer to current value of PHY_CONTROL
  922. *
  923. * Forces speed and duplex on the PHY by doing the following: disable flow
  924. * control, force speed/duplex on the MAC, disable auto speed detection,
  925. * disable auto-negotiation, configure duplex, configure speed, configure
  926. * the collision distance, write configuration to CTRL register. The
  927. * caller must write to the PHY_CONTROL register for these settings to
  928. * take affect.
  929. **/
  930. void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
  931. {
  932. struct e1000_mac_info *mac = &hw->mac;
  933. u32 ctrl;
  934. /* Turn off flow control when forcing speed/duplex */
  935. hw->fc.type = e1000_fc_none;
  936. /* Force speed/duplex on the mac */
  937. ctrl = er32(CTRL);
  938. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  939. ctrl &= ~E1000_CTRL_SPD_SEL;
  940. /* Disable Auto Speed Detection */
  941. ctrl &= ~E1000_CTRL_ASDE;
  942. /* Disable autoneg on the phy */
  943. *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
  944. /* Forcing Full or Half Duplex? */
  945. if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
  946. ctrl &= ~E1000_CTRL_FD;
  947. *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
  948. hw_dbg(hw, "Half Duplex\n");
  949. } else {
  950. ctrl |= E1000_CTRL_FD;
  951. *phy_ctrl |= MII_CR_FULL_DUPLEX;
  952. hw_dbg(hw, "Full Duplex\n");
  953. }
  954. /* Forcing 10mb or 100mb? */
  955. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
  956. ctrl |= E1000_CTRL_SPD_100;
  957. *phy_ctrl |= MII_CR_SPEED_100;
  958. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  959. hw_dbg(hw, "Forcing 100mb\n");
  960. } else {
  961. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  962. *phy_ctrl |= MII_CR_SPEED_10;
  963. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  964. hw_dbg(hw, "Forcing 10mb\n");
  965. }
  966. e1000e_config_collision_dist(hw);
  967. ew32(CTRL, ctrl);
  968. }
  969. /**
  970. * e1000e_set_d3_lplu_state - Sets low power link up state for D3
  971. * @hw: pointer to the HW structure
  972. * @active: boolean used to enable/disable lplu
  973. *
  974. * Success returns 0, Failure returns 1
  975. *
  976. * The low power link up (lplu) state is set to the power management level D3
  977. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  978. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  979. * is used during Dx states where the power conservation is most important.
  980. * During driver activity, SmartSpeed should be enabled so performance is
  981. * maintained.
  982. **/
  983. s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  984. {
  985. struct e1000_phy_info *phy = &hw->phy;
  986. s32 ret_val;
  987. u16 data;
  988. ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  989. if (ret_val)
  990. return ret_val;
  991. if (!active) {
  992. data &= ~IGP02E1000_PM_D3_LPLU;
  993. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  994. if (ret_val)
  995. return ret_val;
  996. /*
  997. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  998. * during Dx states where the power conservation is most
  999. * important. During driver activity we should enable
  1000. * SmartSpeed, so performance is maintained.
  1001. */
  1002. if (phy->smart_speed == e1000_smart_speed_on) {
  1003. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1004. &data);
  1005. if (ret_val)
  1006. return ret_val;
  1007. data |= IGP01E1000_PSCFR_SMART_SPEED;
  1008. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1009. data);
  1010. if (ret_val)
  1011. return ret_val;
  1012. } else if (phy->smart_speed == e1000_smart_speed_off) {
  1013. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1014. &data);
  1015. if (ret_val)
  1016. return ret_val;
  1017. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1018. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  1019. data);
  1020. if (ret_val)
  1021. return ret_val;
  1022. }
  1023. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  1024. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  1025. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  1026. data |= IGP02E1000_PM_D3_LPLU;
  1027. ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
  1028. if (ret_val)
  1029. return ret_val;
  1030. /* When LPLU is enabled, we should disable SmartSpeed */
  1031. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  1032. if (ret_val)
  1033. return ret_val;
  1034. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1035. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  1036. }
  1037. return ret_val;
  1038. }
  1039. /**
  1040. * e1000e_check_downshift - Checks whether a downshift in speed occurred
  1041. * @hw: pointer to the HW structure
  1042. *
  1043. * Success returns 0, Failure returns 1
  1044. *
  1045. * A downshift is detected by querying the PHY link health.
  1046. **/
  1047. s32 e1000e_check_downshift(struct e1000_hw *hw)
  1048. {
  1049. struct e1000_phy_info *phy = &hw->phy;
  1050. s32 ret_val;
  1051. u16 phy_data, offset, mask;
  1052. switch (phy->type) {
  1053. case e1000_phy_m88:
  1054. case e1000_phy_gg82563:
  1055. offset = M88E1000_PHY_SPEC_STATUS;
  1056. mask = M88E1000_PSSR_DOWNSHIFT;
  1057. break;
  1058. case e1000_phy_igp_2:
  1059. case e1000_phy_igp_3:
  1060. offset = IGP01E1000_PHY_LINK_HEALTH;
  1061. mask = IGP01E1000_PLHR_SS_DOWNGRADE;
  1062. break;
  1063. default:
  1064. /* speed downshift not supported */
  1065. phy->speed_downgraded = 0;
  1066. return 0;
  1067. }
  1068. ret_val = e1e_rphy(hw, offset, &phy_data);
  1069. if (!ret_val)
  1070. phy->speed_downgraded = (phy_data & mask);
  1071. return ret_val;
  1072. }
  1073. /**
  1074. * e1000_check_polarity_m88 - Checks the polarity.
  1075. * @hw: pointer to the HW structure
  1076. *
  1077. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1078. *
  1079. * Polarity is determined based on the PHY specific status register.
  1080. **/
  1081. static s32 e1000_check_polarity_m88(struct e1000_hw *hw)
  1082. {
  1083. struct e1000_phy_info *phy = &hw->phy;
  1084. s32 ret_val;
  1085. u16 data;
  1086. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
  1087. if (!ret_val)
  1088. phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
  1089. ? e1000_rev_polarity_reversed
  1090. : e1000_rev_polarity_normal;
  1091. return ret_val;
  1092. }
  1093. /**
  1094. * e1000_check_polarity_igp - Checks the polarity.
  1095. * @hw: pointer to the HW structure
  1096. *
  1097. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1098. *
  1099. * Polarity is determined based on the PHY port status register, and the
  1100. * current speed (since there is no polarity at 100Mbps).
  1101. **/
  1102. static s32 e1000_check_polarity_igp(struct e1000_hw *hw)
  1103. {
  1104. struct e1000_phy_info *phy = &hw->phy;
  1105. s32 ret_val;
  1106. u16 data, offset, mask;
  1107. /*
  1108. * Polarity is determined based on the speed of
  1109. * our connection.
  1110. */
  1111. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1112. if (ret_val)
  1113. return ret_val;
  1114. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1115. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1116. offset = IGP01E1000_PHY_PCS_INIT_REG;
  1117. mask = IGP01E1000_PHY_POLARITY_MASK;
  1118. } else {
  1119. /*
  1120. * This really only applies to 10Mbps since
  1121. * there is no polarity for 100Mbps (always 0).
  1122. */
  1123. offset = IGP01E1000_PHY_PORT_STATUS;
  1124. mask = IGP01E1000_PSSR_POLARITY_REVERSED;
  1125. }
  1126. ret_val = e1e_rphy(hw, offset, &data);
  1127. if (!ret_val)
  1128. phy->cable_polarity = (data & mask)
  1129. ? e1000_rev_polarity_reversed
  1130. : e1000_rev_polarity_normal;
  1131. return ret_val;
  1132. }
  1133. /**
  1134. * e1000_wait_autoneg - Wait for auto-neg completion
  1135. * @hw: pointer to the HW structure
  1136. *
  1137. * Waits for auto-negotiation to complete or for the auto-negotiation time
  1138. * limit to expire, which ever happens first.
  1139. **/
  1140. static s32 e1000_wait_autoneg(struct e1000_hw *hw)
  1141. {
  1142. s32 ret_val = 0;
  1143. u16 i, phy_status;
  1144. /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
  1145. for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
  1146. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1147. if (ret_val)
  1148. break;
  1149. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1150. if (ret_val)
  1151. break;
  1152. if (phy_status & MII_SR_AUTONEG_COMPLETE)
  1153. break;
  1154. msleep(100);
  1155. }
  1156. /*
  1157. * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
  1158. * has completed.
  1159. */
  1160. return ret_val;
  1161. }
  1162. /**
  1163. * e1000e_phy_has_link_generic - Polls PHY for link
  1164. * @hw: pointer to the HW structure
  1165. * @iterations: number of times to poll for link
  1166. * @usec_interval: delay between polling attempts
  1167. * @success: pointer to whether polling was successful or not
  1168. *
  1169. * Polls the PHY status register for link, 'iterations' number of times.
  1170. **/
  1171. s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
  1172. u32 usec_interval, bool *success)
  1173. {
  1174. s32 ret_val = 0;
  1175. u16 i, phy_status;
  1176. for (i = 0; i < iterations; i++) {
  1177. /*
  1178. * Some PHYs require the PHY_STATUS register to be read
  1179. * twice due to the link bit being sticky. No harm doing
  1180. * it across the board.
  1181. */
  1182. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1183. if (ret_val)
  1184. break;
  1185. ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
  1186. if (ret_val)
  1187. break;
  1188. if (phy_status & MII_SR_LINK_STATUS)
  1189. break;
  1190. if (usec_interval >= 1000)
  1191. mdelay(usec_interval/1000);
  1192. else
  1193. udelay(usec_interval);
  1194. }
  1195. *success = (i < iterations);
  1196. return ret_val;
  1197. }
  1198. /**
  1199. * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
  1200. * @hw: pointer to the HW structure
  1201. *
  1202. * Reads the PHY specific status register to retrieve the cable length
  1203. * information. The cable length is determined by averaging the minimum and
  1204. * maximum values to get the "average" cable length. The m88 PHY has four
  1205. * possible cable length values, which are:
  1206. * Register Value Cable Length
  1207. * 0 < 50 meters
  1208. * 1 50 - 80 meters
  1209. * 2 80 - 110 meters
  1210. * 3 110 - 140 meters
  1211. * 4 > 140 meters
  1212. **/
  1213. s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
  1214. {
  1215. struct e1000_phy_info *phy = &hw->phy;
  1216. s32 ret_val;
  1217. u16 phy_data, index;
  1218. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1219. if (ret_val)
  1220. return ret_val;
  1221. index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1222. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  1223. phy->min_cable_length = e1000_m88_cable_length_table[index];
  1224. phy->max_cable_length = e1000_m88_cable_length_table[index+1];
  1225. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1226. return ret_val;
  1227. }
  1228. /**
  1229. * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
  1230. * @hw: pointer to the HW structure
  1231. *
  1232. * The automatic gain control (agc) normalizes the amplitude of the
  1233. * received signal, adjusting for the attenuation produced by the
  1234. * cable. By reading the AGC registers, which represent the
  1235. * combination of course and fine gain value, the value can be put
  1236. * into a lookup table to obtain the approximate cable length
  1237. * for each channel.
  1238. **/
  1239. s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
  1240. {
  1241. struct e1000_phy_info *phy = &hw->phy;
  1242. s32 ret_val;
  1243. u16 phy_data, i, agc_value = 0;
  1244. u16 cur_agc_index, max_agc_index = 0;
  1245. u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
  1246. u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
  1247. {IGP02E1000_PHY_AGC_A,
  1248. IGP02E1000_PHY_AGC_B,
  1249. IGP02E1000_PHY_AGC_C,
  1250. IGP02E1000_PHY_AGC_D};
  1251. /* Read the AGC registers for all channels */
  1252. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  1253. ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
  1254. if (ret_val)
  1255. return ret_val;
  1256. /*
  1257. * Getting bits 15:9, which represent the combination of
  1258. * course and fine gain values. The result is a number
  1259. * that can be put into the lookup table to obtain the
  1260. * approximate cable length.
  1261. */
  1262. cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  1263. IGP02E1000_AGC_LENGTH_MASK;
  1264. /* Array index bound check. */
  1265. if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
  1266. (cur_agc_index == 0))
  1267. return -E1000_ERR_PHY;
  1268. /* Remove min & max AGC values from calculation. */
  1269. if (e1000_igp_2_cable_length_table[min_agc_index] >
  1270. e1000_igp_2_cable_length_table[cur_agc_index])
  1271. min_agc_index = cur_agc_index;
  1272. if (e1000_igp_2_cable_length_table[max_agc_index] <
  1273. e1000_igp_2_cable_length_table[cur_agc_index])
  1274. max_agc_index = cur_agc_index;
  1275. agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
  1276. }
  1277. agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
  1278. e1000_igp_2_cable_length_table[max_agc_index]);
  1279. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  1280. /* Calculate cable length with the error range of +/- 10 meters. */
  1281. phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  1282. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  1283. phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
  1284. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1285. return ret_val;
  1286. }
  1287. /**
  1288. * e1000e_get_phy_info_m88 - Retrieve PHY information
  1289. * @hw: pointer to the HW structure
  1290. *
  1291. * Valid for only copper links. Read the PHY status register (sticky read)
  1292. * to verify that link is up. Read the PHY special control register to
  1293. * determine the polarity and 10base-T extended distance. Read the PHY
  1294. * special status register to determine MDI/MDIx and current speed. If
  1295. * speed is 1000, then determine cable length, local and remote receiver.
  1296. **/
  1297. s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
  1298. {
  1299. struct e1000_phy_info *phy = &hw->phy;
  1300. s32 ret_val;
  1301. u16 phy_data;
  1302. bool link;
  1303. if (hw->phy.media_type != e1000_media_type_copper) {
  1304. hw_dbg(hw, "Phy info is only valid for copper media\n");
  1305. return -E1000_ERR_CONFIG;
  1306. }
  1307. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1308. if (ret_val)
  1309. return ret_val;
  1310. if (!link) {
  1311. hw_dbg(hw, "Phy info is only valid if link is up\n");
  1312. return -E1000_ERR_CONFIG;
  1313. }
  1314. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1315. if (ret_val)
  1316. return ret_val;
  1317. phy->polarity_correction = (phy_data &
  1318. M88E1000_PSCR_POLARITY_REVERSAL);
  1319. ret_val = e1000_check_polarity_m88(hw);
  1320. if (ret_val)
  1321. return ret_val;
  1322. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1323. if (ret_val)
  1324. return ret_val;
  1325. phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);
  1326. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  1327. ret_val = e1000_get_cable_length(hw);
  1328. if (ret_val)
  1329. return ret_val;
  1330. ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
  1331. if (ret_val)
  1332. return ret_val;
  1333. phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
  1334. ? e1000_1000t_rx_status_ok
  1335. : e1000_1000t_rx_status_not_ok;
  1336. phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
  1337. ? e1000_1000t_rx_status_ok
  1338. : e1000_1000t_rx_status_not_ok;
  1339. } else {
  1340. /* Set values to "undefined" */
  1341. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1342. phy->local_rx = e1000_1000t_rx_status_undefined;
  1343. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1344. }
  1345. return ret_val;
  1346. }
  1347. /**
  1348. * e1000e_get_phy_info_igp - Retrieve igp PHY information
  1349. * @hw: pointer to the HW structure
  1350. *
  1351. * Read PHY status to determine if link is up. If link is up, then
  1352. * set/determine 10base-T extended distance and polarity correction. Read
  1353. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  1354. * determine on the cable length, local and remote receiver.
  1355. **/
  1356. s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
  1357. {
  1358. struct e1000_phy_info *phy = &hw->phy;
  1359. s32 ret_val;
  1360. u16 data;
  1361. bool link;
  1362. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1363. if (ret_val)
  1364. return ret_val;
  1365. if (!link) {
  1366. hw_dbg(hw, "Phy info is only valid if link is up\n");
  1367. return -E1000_ERR_CONFIG;
  1368. }
  1369. phy->polarity_correction = 1;
  1370. ret_val = e1000_check_polarity_igp(hw);
  1371. if (ret_val)
  1372. return ret_val;
  1373. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1374. if (ret_val)
  1375. return ret_val;
  1376. phy->is_mdix = (data & IGP01E1000_PSSR_MDIX);
  1377. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1378. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1379. ret_val = e1000_get_cable_length(hw);
  1380. if (ret_val)
  1381. return ret_val;
  1382. ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
  1383. if (ret_val)
  1384. return ret_val;
  1385. phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
  1386. ? e1000_1000t_rx_status_ok
  1387. : e1000_1000t_rx_status_not_ok;
  1388. phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
  1389. ? e1000_1000t_rx_status_ok
  1390. : e1000_1000t_rx_status_not_ok;
  1391. } else {
  1392. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1393. phy->local_rx = e1000_1000t_rx_status_undefined;
  1394. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1395. }
  1396. return ret_val;
  1397. }
  1398. /**
  1399. * e1000e_phy_sw_reset - PHY software reset
  1400. * @hw: pointer to the HW structure
  1401. *
  1402. * Does a software reset of the PHY by reading the PHY control register and
  1403. * setting/write the control register reset bit to the PHY.
  1404. **/
  1405. s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
  1406. {
  1407. s32 ret_val;
  1408. u16 phy_ctrl;
  1409. ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
  1410. if (ret_val)
  1411. return ret_val;
  1412. phy_ctrl |= MII_CR_RESET;
  1413. ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
  1414. if (ret_val)
  1415. return ret_val;
  1416. udelay(1);
  1417. return ret_val;
  1418. }
  1419. /**
  1420. * e1000e_phy_hw_reset_generic - PHY hardware reset
  1421. * @hw: pointer to the HW structure
  1422. *
  1423. * Verify the reset block is not blocking us from resetting. Acquire
  1424. * semaphore (if necessary) and read/set/write the device control reset
  1425. * bit in the PHY. Wait the appropriate delay time for the device to
  1426. * reset and release the semaphore (if necessary).
  1427. **/
  1428. s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
  1429. {
  1430. struct e1000_phy_info *phy = &hw->phy;
  1431. s32 ret_val;
  1432. u32 ctrl;
  1433. ret_val = e1000_check_reset_block(hw);
  1434. if (ret_val)
  1435. return 0;
  1436. ret_val = phy->ops.acquire_phy(hw);
  1437. if (ret_val)
  1438. return ret_val;
  1439. ctrl = er32(CTRL);
  1440. ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
  1441. e1e_flush();
  1442. udelay(phy->reset_delay_us);
  1443. ew32(CTRL, ctrl);
  1444. e1e_flush();
  1445. udelay(150);
  1446. phy->ops.release_phy(hw);
  1447. return e1000_get_phy_cfg_done(hw);
  1448. }
  1449. /**
  1450. * e1000e_get_cfg_done - Generic configuration done
  1451. * @hw: pointer to the HW structure
  1452. *
  1453. * Generic function to wait 10 milli-seconds for configuration to complete
  1454. * and return success.
  1455. **/
  1456. s32 e1000e_get_cfg_done(struct e1000_hw *hw)
  1457. {
  1458. mdelay(10);
  1459. return 0;
  1460. }
  1461. /* Internal function pointers */
  1462. /**
  1463. * e1000_get_phy_cfg_done - Generic PHY configuration done
  1464. * @hw: pointer to the HW structure
  1465. *
  1466. * Return success if silicon family did not implement a family specific
  1467. * get_cfg_done function.
  1468. **/
  1469. static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
  1470. {
  1471. if (hw->phy.ops.get_cfg_done)
  1472. return hw->phy.ops.get_cfg_done(hw);
  1473. return 0;
  1474. }
  1475. /**
  1476. * e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
  1477. * @hw: pointer to the HW structure
  1478. *
  1479. * When the silicon family has not implemented a forced speed/duplex
  1480. * function for the PHY, simply return 0.
  1481. **/
  1482. static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1483. {
  1484. if (hw->phy.ops.force_speed_duplex)
  1485. return hw->phy.ops.force_speed_duplex(hw);
  1486. return 0;
  1487. }
  1488. /**
  1489. * e1000e_get_phy_type_from_id - Get PHY type from id
  1490. * @phy_id: phy_id read from the phy
  1491. *
  1492. * Returns the phy type from the id.
  1493. **/
  1494. enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
  1495. {
  1496. enum e1000_phy_type phy_type = e1000_phy_unknown;
  1497. switch (phy_id) {
  1498. case M88E1000_I_PHY_ID:
  1499. case M88E1000_E_PHY_ID:
  1500. case M88E1111_I_PHY_ID:
  1501. case M88E1011_I_PHY_ID:
  1502. phy_type = e1000_phy_m88;
  1503. break;
  1504. case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
  1505. phy_type = e1000_phy_igp_2;
  1506. break;
  1507. case GG82563_E_PHY_ID:
  1508. phy_type = e1000_phy_gg82563;
  1509. break;
  1510. case IGP03E1000_E_PHY_ID:
  1511. phy_type = e1000_phy_igp_3;
  1512. break;
  1513. case IFE_E_PHY_ID:
  1514. case IFE_PLUS_E_PHY_ID:
  1515. case IFE_C_E_PHY_ID:
  1516. phy_type = e1000_phy_ife;
  1517. break;
  1518. default:
  1519. phy_type = e1000_phy_unknown;
  1520. break;
  1521. }
  1522. return phy_type;
  1523. }
  1524. /**
  1525. * e1000e_commit_phy - Soft PHY reset
  1526. * @hw: pointer to the HW structure
  1527. *
  1528. * Performs a soft PHY reset on those that apply. This is a function pointer
  1529. * entry point called by drivers.
  1530. **/
  1531. s32 e1000e_commit_phy(struct e1000_hw *hw)
  1532. {
  1533. if (hw->phy.ops.commit_phy)
  1534. return hw->phy.ops.commit_phy(hw);
  1535. return 0;
  1536. }
  1537. /**
  1538. * e1000_set_d0_lplu_state - Sets low power link up state for D0
  1539. * @hw: pointer to the HW structure
  1540. * @active: boolean used to enable/disable lplu
  1541. *
  1542. * Success returns 0, Failure returns 1
  1543. *
  1544. * The low power link up (lplu) state is set to the power management level D0
  1545. * and SmartSpeed is disabled when active is true, else clear lplu for D0
  1546. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  1547. * is used during Dx states where the power conservation is most important.
  1548. * During driver activity, SmartSpeed should be enabled so performance is
  1549. * maintained. This is a function pointer entry point called by drivers.
  1550. **/
  1551. static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
  1552. {
  1553. if (hw->phy.ops.set_d0_lplu_state)
  1554. return hw->phy.ops.set_d0_lplu_state(hw, active);
  1555. return 0;
  1556. }