phy.c 56 KB

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