e1000_phy.c 48 KB

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