phy.c 48 KB

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