e1000_phy.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511
  1. /* Intel(R) Gigabit Ethernet Linux driver
  2. * Copyright(c) 2007-2014 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * The full GNU General Public License is included in this distribution in
  17. * the file called "COPYING".
  18. *
  19. * Contact Information:
  20. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  21. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  22. */
  23. #include <linux/if_ether.h>
  24. #include <linux/delay.h>
  25. #include "e1000_mac.h"
  26. #include "e1000_phy.h"
  27. static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
  28. static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
  29. u16 *phy_ctrl);
  30. static s32 igb_wait_autoneg(struct e1000_hw *hw);
  31. static s32 igb_set_master_slave_mode(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) ? E1000_BLK_PHY_RESET : 0;
  63. }
  64. /**
  65. * igb_get_phy_id - Retrieve the PHY ID and revision
  66. * @hw: pointer to the HW structure
  67. *
  68. * Reads the PHY registers and stores the PHY ID and possibly the PHY
  69. * revision in the hardware structure.
  70. **/
  71. s32 igb_get_phy_id(struct e1000_hw *hw)
  72. {
  73. struct e1000_phy_info *phy = &hw->phy;
  74. s32 ret_val = 0;
  75. u16 phy_id;
  76. ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
  77. if (ret_val)
  78. goto out;
  79. phy->id = (u32)(phy_id << 16);
  80. udelay(20);
  81. ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
  82. if (ret_val)
  83. goto out;
  84. phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
  85. phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
  86. out:
  87. return ret_val;
  88. }
  89. /**
  90. * igb_phy_reset_dsp - Reset PHY DSP
  91. * @hw: pointer to the HW structure
  92. *
  93. * Reset the digital signal processor.
  94. **/
  95. static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
  96. {
  97. s32 ret_val = 0;
  98. if (!(hw->phy.ops.write_reg))
  99. goto out;
  100. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
  101. if (ret_val)
  102. goto out;
  103. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
  104. out:
  105. return ret_val;
  106. }
  107. /**
  108. * igb_read_phy_reg_mdic - Read MDI control register
  109. * @hw: pointer to the HW structure
  110. * @offset: register offset to be read
  111. * @data: pointer to the read data
  112. *
  113. * Reads the MDI control regsiter in the PHY at offset and stores the
  114. * information read to data.
  115. **/
  116. s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
  117. {
  118. struct e1000_phy_info *phy = &hw->phy;
  119. u32 i, mdic = 0;
  120. s32 ret_val = 0;
  121. if (offset > MAX_PHY_REG_ADDRESS) {
  122. hw_dbg("PHY Address %d is out of range\n", offset);
  123. ret_val = -E1000_ERR_PARAM;
  124. goto out;
  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. /* Poll the ready bit to see if the MDI read completed
  135. * Increasing the time out as testing showed failures with
  136. * the lower time out
  137. */
  138. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  139. udelay(50);
  140. mdic = rd32(E1000_MDIC);
  141. if (mdic & E1000_MDIC_READY)
  142. break;
  143. }
  144. if (!(mdic & E1000_MDIC_READY)) {
  145. hw_dbg("MDI Read did not complete\n");
  146. ret_val = -E1000_ERR_PHY;
  147. goto out;
  148. }
  149. if (mdic & E1000_MDIC_ERROR) {
  150. hw_dbg("MDI Error\n");
  151. ret_val = -E1000_ERR_PHY;
  152. goto out;
  153. }
  154. *data = (u16) mdic;
  155. out:
  156. return ret_val;
  157. }
  158. /**
  159. * igb_write_phy_reg_mdic - Write MDI control register
  160. * @hw: pointer to the HW structure
  161. * @offset: register offset to write to
  162. * @data: data to write to register at offset
  163. *
  164. * Writes data to MDI control register in the PHY at offset.
  165. **/
  166. s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
  167. {
  168. struct e1000_phy_info *phy = &hw->phy;
  169. u32 i, mdic = 0;
  170. s32 ret_val = 0;
  171. if (offset > MAX_PHY_REG_ADDRESS) {
  172. hw_dbg("PHY Address %d is out of range\n", offset);
  173. ret_val = -E1000_ERR_PARAM;
  174. goto out;
  175. }
  176. /* Set up Op-code, Phy Address, and register offset in the MDI
  177. * Control register. The MAC will take care of interfacing with the
  178. * PHY to retrieve the desired data.
  179. */
  180. mdic = (((u32)data) |
  181. (offset << E1000_MDIC_REG_SHIFT) |
  182. (phy->addr << E1000_MDIC_PHY_SHIFT) |
  183. (E1000_MDIC_OP_WRITE));
  184. wr32(E1000_MDIC, mdic);
  185. /* Poll the ready bit to see if the MDI read completed
  186. * Increasing the time out as testing showed failures with
  187. * the lower time out
  188. */
  189. for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
  190. udelay(50);
  191. mdic = rd32(E1000_MDIC);
  192. if (mdic & E1000_MDIC_READY)
  193. break;
  194. }
  195. if (!(mdic & E1000_MDIC_READY)) {
  196. hw_dbg("MDI Write did not complete\n");
  197. ret_val = -E1000_ERR_PHY;
  198. goto out;
  199. }
  200. if (mdic & E1000_MDIC_ERROR) {
  201. hw_dbg("MDI Error\n");
  202. ret_val = -E1000_ERR_PHY;
  203. goto out;
  204. }
  205. out:
  206. return ret_val;
  207. }
  208. /**
  209. * igb_read_phy_reg_i2c - Read PHY register using i2c
  210. * @hw: pointer to the HW structure
  211. * @offset: register offset to be read
  212. * @data: pointer to the read data
  213. *
  214. * Reads the PHY register at offset using the i2c interface and stores the
  215. * retrieved information in data.
  216. **/
  217. s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
  218. {
  219. struct e1000_phy_info *phy = &hw->phy;
  220. u32 i, i2ccmd = 0;
  221. /* Set up Op-code, Phy Address, and register address in the I2CCMD
  222. * register. The MAC will take care of interfacing with the
  223. * PHY to retrieve the desired data.
  224. */
  225. i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
  226. (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
  227. (E1000_I2CCMD_OPCODE_READ));
  228. wr32(E1000_I2CCMD, i2ccmd);
  229. /* Poll the ready bit to see if the I2C read completed */
  230. for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
  231. udelay(50);
  232. i2ccmd = rd32(E1000_I2CCMD);
  233. if (i2ccmd & E1000_I2CCMD_READY)
  234. break;
  235. }
  236. if (!(i2ccmd & E1000_I2CCMD_READY)) {
  237. hw_dbg("I2CCMD Read did not complete\n");
  238. return -E1000_ERR_PHY;
  239. }
  240. if (i2ccmd & E1000_I2CCMD_ERROR) {
  241. hw_dbg("I2CCMD Error bit set\n");
  242. return -E1000_ERR_PHY;
  243. }
  244. /* Need to byte-swap the 16-bit value. */
  245. *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
  246. return 0;
  247. }
  248. /**
  249. * igb_write_phy_reg_i2c - Write PHY register using i2c
  250. * @hw: pointer to the HW structure
  251. * @offset: register offset to write to
  252. * @data: data to write at register offset
  253. *
  254. * Writes the data to PHY register at the offset using the i2c interface.
  255. **/
  256. s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
  257. {
  258. struct e1000_phy_info *phy = &hw->phy;
  259. u32 i, i2ccmd = 0;
  260. u16 phy_data_swapped;
  261. /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
  262. if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
  263. hw_dbg("PHY I2C Address %d is out of range.\n",
  264. hw->phy.addr);
  265. return -E1000_ERR_CONFIG;
  266. }
  267. /* Swap the data bytes for the I2C interface */
  268. phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
  269. /* Set up Op-code, Phy Address, and register address in the I2CCMD
  270. * register. The MAC will take care of interfacing with the
  271. * PHY to retrieve the desired data.
  272. */
  273. i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
  274. (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
  275. E1000_I2CCMD_OPCODE_WRITE |
  276. phy_data_swapped);
  277. wr32(E1000_I2CCMD, i2ccmd);
  278. /* Poll the ready bit to see if the I2C read completed */
  279. for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
  280. udelay(50);
  281. i2ccmd = rd32(E1000_I2CCMD);
  282. if (i2ccmd & E1000_I2CCMD_READY)
  283. break;
  284. }
  285. if (!(i2ccmd & E1000_I2CCMD_READY)) {
  286. hw_dbg("I2CCMD Write did not complete\n");
  287. return -E1000_ERR_PHY;
  288. }
  289. if (i2ccmd & E1000_I2CCMD_ERROR) {
  290. hw_dbg("I2CCMD Error bit set\n");
  291. return -E1000_ERR_PHY;
  292. }
  293. return 0;
  294. }
  295. /**
  296. * igb_read_sfp_data_byte - Reads SFP module data.
  297. * @hw: pointer to the HW structure
  298. * @offset: byte location offset to be read
  299. * @data: read data buffer pointer
  300. *
  301. * Reads one byte from SFP module data stored
  302. * in SFP resided EEPROM memory or SFP diagnostic area.
  303. * Function should be called with
  304. * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
  305. * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
  306. * access
  307. **/
  308. s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
  309. {
  310. u32 i = 0;
  311. u32 i2ccmd = 0;
  312. u32 data_local = 0;
  313. if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
  314. hw_dbg("I2CCMD command address exceeds upper limit\n");
  315. return -E1000_ERR_PHY;
  316. }
  317. /* Set up Op-code, EEPROM Address,in the I2CCMD
  318. * register. The MAC will take care of interfacing with the
  319. * EEPROM to retrieve the desired data.
  320. */
  321. i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
  322. E1000_I2CCMD_OPCODE_READ);
  323. wr32(E1000_I2CCMD, i2ccmd);
  324. /* Poll the ready bit to see if the I2C read completed */
  325. for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
  326. udelay(50);
  327. data_local = rd32(E1000_I2CCMD);
  328. if (data_local & E1000_I2CCMD_READY)
  329. break;
  330. }
  331. if (!(data_local & E1000_I2CCMD_READY)) {
  332. hw_dbg("I2CCMD Read did not complete\n");
  333. return -E1000_ERR_PHY;
  334. }
  335. if (data_local & E1000_I2CCMD_ERROR) {
  336. hw_dbg("I2CCMD Error bit set\n");
  337. return -E1000_ERR_PHY;
  338. }
  339. *data = (u8) data_local & 0xFF;
  340. return 0;
  341. }
  342. /**
  343. * igb_read_phy_reg_igp - Read igp PHY register
  344. * @hw: pointer to the HW structure
  345. * @offset: register offset to be read
  346. * @data: pointer to the read data
  347. *
  348. * Acquires semaphore, if necessary, then reads the PHY register at offset
  349. * and storing the retrieved information in data. Release any acquired
  350. * semaphores before exiting.
  351. **/
  352. s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
  353. {
  354. s32 ret_val = 0;
  355. if (!(hw->phy.ops.acquire))
  356. goto out;
  357. ret_val = hw->phy.ops.acquire(hw);
  358. if (ret_val)
  359. goto out;
  360. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  361. ret_val = igb_write_phy_reg_mdic(hw,
  362. IGP01E1000_PHY_PAGE_SELECT,
  363. (u16)offset);
  364. if (ret_val) {
  365. hw->phy.ops.release(hw);
  366. goto out;
  367. }
  368. }
  369. ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  370. data);
  371. hw->phy.ops.release(hw);
  372. out:
  373. return ret_val;
  374. }
  375. /**
  376. * igb_write_phy_reg_igp - Write igp PHY register
  377. * @hw: pointer to the HW structure
  378. * @offset: register offset to write to
  379. * @data: data to write at register offset
  380. *
  381. * Acquires semaphore, if necessary, then writes the data to PHY register
  382. * at the offset. Release any acquired semaphores before exiting.
  383. **/
  384. s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
  385. {
  386. s32 ret_val = 0;
  387. if (!(hw->phy.ops.acquire))
  388. goto out;
  389. ret_val = hw->phy.ops.acquire(hw);
  390. if (ret_val)
  391. goto out;
  392. if (offset > MAX_PHY_MULTI_PAGE_REG) {
  393. ret_val = igb_write_phy_reg_mdic(hw,
  394. IGP01E1000_PHY_PAGE_SELECT,
  395. (u16)offset);
  396. if (ret_val) {
  397. hw->phy.ops.release(hw);
  398. goto out;
  399. }
  400. }
  401. ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
  402. data);
  403. hw->phy.ops.release(hw);
  404. out:
  405. return ret_val;
  406. }
  407. /**
  408. * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
  409. * @hw: pointer to the HW structure
  410. *
  411. * Sets up Carrier-sense on Transmit and downshift values.
  412. **/
  413. s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
  414. {
  415. struct e1000_phy_info *phy = &hw->phy;
  416. s32 ret_val;
  417. u16 phy_data;
  418. if (phy->reset_disable) {
  419. ret_val = 0;
  420. goto out;
  421. }
  422. if (phy->type == e1000_phy_82580) {
  423. ret_val = hw->phy.ops.reset(hw);
  424. if (ret_val) {
  425. hw_dbg("Error resetting the PHY.\n");
  426. goto out;
  427. }
  428. }
  429. /* Enable CRS on TX. This must be set for half-duplex operation. */
  430. ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
  431. if (ret_val)
  432. goto out;
  433. phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
  434. /* Enable downshift */
  435. phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
  436. ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
  437. if (ret_val)
  438. goto out;
  439. /* Set MDI/MDIX mode */
  440. ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
  441. if (ret_val)
  442. goto out;
  443. phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
  444. /* Options:
  445. * 0 - Auto (default)
  446. * 1 - MDI mode
  447. * 2 - MDI-X mode
  448. */
  449. switch (hw->phy.mdix) {
  450. case 1:
  451. break;
  452. case 2:
  453. phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX;
  454. break;
  455. case 0:
  456. default:
  457. phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX;
  458. break;
  459. }
  460. ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
  461. out:
  462. return ret_val;
  463. }
  464. /**
  465. * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
  466. * @hw: pointer to the HW structure
  467. *
  468. * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
  469. * and downshift values are set also.
  470. **/
  471. s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
  472. {
  473. struct e1000_phy_info *phy = &hw->phy;
  474. s32 ret_val;
  475. u16 phy_data;
  476. if (phy->reset_disable) {
  477. ret_val = 0;
  478. goto out;
  479. }
  480. /* Enable CRS on TX. This must be set for half-duplex operation. */
  481. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  482. if (ret_val)
  483. goto out;
  484. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  485. /* Options:
  486. * MDI/MDI-X = 0 (default)
  487. * 0 - Auto for all speeds
  488. * 1 - MDI mode
  489. * 2 - MDI-X mode
  490. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  491. */
  492. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  493. switch (phy->mdix) {
  494. case 1:
  495. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  496. break;
  497. case 2:
  498. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  499. break;
  500. case 3:
  501. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  502. break;
  503. case 0:
  504. default:
  505. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  506. break;
  507. }
  508. /* Options:
  509. * disable_polarity_correction = 0 (default)
  510. * Automatic Correction for Reversed Cable Polarity
  511. * 0 - Disabled
  512. * 1 - Enabled
  513. */
  514. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  515. if (phy->disable_polarity_correction == 1)
  516. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  517. ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  518. if (ret_val)
  519. goto out;
  520. if (phy->revision < E1000_REVISION_4) {
  521. /* Force TX_CLK in the Extended PHY Specific Control Register
  522. * to 25MHz clock.
  523. */
  524. ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  525. &phy_data);
  526. if (ret_val)
  527. goto out;
  528. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  529. if ((phy->revision == E1000_REVISION_2) &&
  530. (phy->id == M88E1111_I_PHY_ID)) {
  531. /* 82573L PHY - set the downshift counter to 5x. */
  532. phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
  533. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  534. } else {
  535. /* Configure Master and Slave downshift values */
  536. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  537. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  538. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  539. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  540. }
  541. ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  542. phy_data);
  543. if (ret_val)
  544. goto out;
  545. }
  546. /* Commit the changes. */
  547. ret_val = igb_phy_sw_reset(hw);
  548. if (ret_val) {
  549. hw_dbg("Error committing the PHY changes\n");
  550. goto out;
  551. }
  552. out:
  553. return ret_val;
  554. }
  555. /**
  556. * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
  557. * @hw: pointer to the HW structure
  558. *
  559. * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
  560. * Also enables and sets the downshift parameters.
  561. **/
  562. s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw)
  563. {
  564. struct e1000_phy_info *phy = &hw->phy;
  565. s32 ret_val;
  566. u16 phy_data;
  567. if (phy->reset_disable)
  568. return 0;
  569. /* Enable CRS on Tx. This must be set for half-duplex operation. */
  570. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  571. if (ret_val)
  572. return ret_val;
  573. /* Options:
  574. * MDI/MDI-X = 0 (default)
  575. * 0 - Auto for all speeds
  576. * 1 - MDI mode
  577. * 2 - MDI-X mode
  578. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  579. */
  580. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  581. switch (phy->mdix) {
  582. case 1:
  583. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  584. break;
  585. case 2:
  586. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  587. break;
  588. case 3:
  589. /* M88E1112 does not support this mode) */
  590. if (phy->id != M88E1112_E_PHY_ID) {
  591. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  592. break;
  593. }
  594. case 0:
  595. default:
  596. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  597. break;
  598. }
  599. /* Options:
  600. * disable_polarity_correction = 0 (default)
  601. * Automatic Correction for Reversed Cable Polarity
  602. * 0 - Disabled
  603. * 1 - Enabled
  604. */
  605. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  606. if (phy->disable_polarity_correction == 1)
  607. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  608. /* Enable downshift and setting it to X6 */
  609. if (phy->id == M88E1543_E_PHY_ID) {
  610. phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
  611. ret_val =
  612. phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  613. if (ret_val)
  614. return ret_val;
  615. ret_val = igb_phy_sw_reset(hw);
  616. if (ret_val) {
  617. hw_dbg("Error committing the PHY changes\n");
  618. return ret_val;
  619. }
  620. }
  621. phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
  622. phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
  623. phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
  624. ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  625. if (ret_val)
  626. return ret_val;
  627. /* Commit the changes. */
  628. ret_val = igb_phy_sw_reset(hw);
  629. if (ret_val) {
  630. hw_dbg("Error committing the PHY changes\n");
  631. return ret_val;
  632. }
  633. ret_val = igb_set_master_slave_mode(hw);
  634. if (ret_val)
  635. return ret_val;
  636. return 0;
  637. }
  638. /**
  639. * igb_copper_link_setup_igp - Setup igp PHY's for copper link
  640. * @hw: pointer to the HW structure
  641. *
  642. * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
  643. * igp PHY's.
  644. **/
  645. s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
  646. {
  647. struct e1000_phy_info *phy = &hw->phy;
  648. s32 ret_val;
  649. u16 data;
  650. if (phy->reset_disable) {
  651. ret_val = 0;
  652. goto out;
  653. }
  654. ret_val = phy->ops.reset(hw);
  655. if (ret_val) {
  656. hw_dbg("Error resetting the PHY.\n");
  657. goto out;
  658. }
  659. /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
  660. * timeout issues when LFS is enabled.
  661. */
  662. msleep(100);
  663. /* The NVM settings will configure LPLU in D3 for
  664. * non-IGP1 PHYs.
  665. */
  666. if (phy->type == e1000_phy_igp) {
  667. /* disable lplu d3 during driver init */
  668. if (phy->ops.set_d3_lplu_state)
  669. ret_val = phy->ops.set_d3_lplu_state(hw, false);
  670. if (ret_val) {
  671. hw_dbg("Error Disabling LPLU D3\n");
  672. goto out;
  673. }
  674. }
  675. /* disable lplu d0 during driver init */
  676. ret_val = phy->ops.set_d0_lplu_state(hw, false);
  677. if (ret_val) {
  678. hw_dbg("Error Disabling LPLU D0\n");
  679. goto out;
  680. }
  681. /* Configure mdi-mdix settings */
  682. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
  683. if (ret_val)
  684. goto out;
  685. data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  686. switch (phy->mdix) {
  687. case 1:
  688. data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  689. break;
  690. case 2:
  691. data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  692. break;
  693. case 0:
  694. default:
  695. data |= IGP01E1000_PSCR_AUTO_MDIX;
  696. break;
  697. }
  698. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
  699. if (ret_val)
  700. goto out;
  701. /* set auto-master slave resolution settings */
  702. if (hw->mac.autoneg) {
  703. /* when autonegotiation advertisement is only 1000Mbps then we
  704. * should disable SmartSpeed and enable Auto MasterSlave
  705. * resolution as hardware default.
  706. */
  707. if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
  708. /* Disable SmartSpeed */
  709. ret_val = phy->ops.read_reg(hw,
  710. IGP01E1000_PHY_PORT_CONFIG,
  711. &data);
  712. if (ret_val)
  713. goto out;
  714. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  715. ret_val = phy->ops.write_reg(hw,
  716. IGP01E1000_PHY_PORT_CONFIG,
  717. data);
  718. if (ret_val)
  719. goto out;
  720. /* Set auto Master/Slave resolution process */
  721. ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
  722. if (ret_val)
  723. goto out;
  724. data &= ~CR_1000T_MS_ENABLE;
  725. ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
  726. if (ret_val)
  727. goto out;
  728. }
  729. ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
  730. if (ret_val)
  731. goto out;
  732. /* load defaults for future use */
  733. phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
  734. ((data & CR_1000T_MS_VALUE) ?
  735. e1000_ms_force_master :
  736. e1000_ms_force_slave) :
  737. e1000_ms_auto;
  738. switch (phy->ms_type) {
  739. case e1000_ms_force_master:
  740. data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  741. break;
  742. case e1000_ms_force_slave:
  743. data |= CR_1000T_MS_ENABLE;
  744. data &= ~(CR_1000T_MS_VALUE);
  745. break;
  746. case e1000_ms_auto:
  747. data &= ~CR_1000T_MS_ENABLE;
  748. default:
  749. break;
  750. }
  751. ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
  752. if (ret_val)
  753. goto out;
  754. }
  755. out:
  756. return ret_val;
  757. }
  758. /**
  759. * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
  760. * @hw: pointer to the HW structure
  761. *
  762. * Performs initial bounds checking on autoneg advertisement parameter, then
  763. * configure to advertise the full capability. Setup the PHY to autoneg
  764. * and restart the negotiation process between the link partner. If
  765. * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
  766. **/
  767. static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
  768. {
  769. struct e1000_phy_info *phy = &hw->phy;
  770. s32 ret_val;
  771. u16 phy_ctrl;
  772. /* Perform some bounds checking on the autoneg advertisement
  773. * parameter.
  774. */
  775. phy->autoneg_advertised &= phy->autoneg_mask;
  776. /* If autoneg_advertised is zero, we assume it was not defaulted
  777. * by the calling code so we set to advertise full capability.
  778. */
  779. if (phy->autoneg_advertised == 0)
  780. phy->autoneg_advertised = phy->autoneg_mask;
  781. hw_dbg("Reconfiguring auto-neg advertisement params\n");
  782. ret_val = igb_phy_setup_autoneg(hw);
  783. if (ret_val) {
  784. hw_dbg("Error Setting up Auto-Negotiation\n");
  785. goto out;
  786. }
  787. hw_dbg("Restarting Auto-Neg\n");
  788. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  789. * the Auto Neg Restart bit in the PHY control register.
  790. */
  791. ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
  792. if (ret_val)
  793. goto out;
  794. phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  795. ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
  796. if (ret_val)
  797. goto out;
  798. /* Does the user want to wait for Auto-Neg to complete here, or
  799. * check at a later time (for example, callback routine).
  800. */
  801. if (phy->autoneg_wait_to_complete) {
  802. ret_val = igb_wait_autoneg(hw);
  803. if (ret_val) {
  804. hw_dbg("Error while waiting for autoneg to complete\n");
  805. goto out;
  806. }
  807. }
  808. hw->mac.get_link_status = true;
  809. out:
  810. return ret_val;
  811. }
  812. /**
  813. * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
  814. * @hw: pointer to the HW structure
  815. *
  816. * Reads the MII auto-neg advertisement register and/or the 1000T control
  817. * register and if the PHY is already setup for auto-negotiation, then
  818. * return successful. Otherwise, setup advertisement and flow control to
  819. * the appropriate values for the wanted auto-negotiation.
  820. **/
  821. static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
  822. {
  823. struct e1000_phy_info *phy = &hw->phy;
  824. s32 ret_val;
  825. u16 mii_autoneg_adv_reg;
  826. u16 mii_1000t_ctrl_reg = 0;
  827. phy->autoneg_advertised &= phy->autoneg_mask;
  828. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  829. ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  830. if (ret_val)
  831. goto out;
  832. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  833. /* Read the MII 1000Base-T Control Register (Address 9). */
  834. ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
  835. &mii_1000t_ctrl_reg);
  836. if (ret_val)
  837. goto out;
  838. }
  839. /* Need to parse both autoneg_advertised and fc and set up
  840. * the appropriate PHY registers. First we will parse for
  841. * autoneg_advertised software override. Since we can advertise
  842. * a plethora of combinations, we need to check each bit
  843. * individually.
  844. */
  845. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  846. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  847. * the 1000Base-T Control Register (Address 9).
  848. */
  849. mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
  850. NWAY_AR_100TX_HD_CAPS |
  851. NWAY_AR_10T_FD_CAPS |
  852. NWAY_AR_10T_HD_CAPS);
  853. mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
  854. hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
  855. /* Do we want to advertise 10 Mb Half Duplex? */
  856. if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
  857. hw_dbg("Advertise 10mb Half duplex\n");
  858. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  859. }
  860. /* Do we want to advertise 10 Mb Full Duplex? */
  861. if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
  862. hw_dbg("Advertise 10mb Full duplex\n");
  863. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  864. }
  865. /* Do we want to advertise 100 Mb Half Duplex? */
  866. if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
  867. hw_dbg("Advertise 100mb Half duplex\n");
  868. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  869. }
  870. /* Do we want to advertise 100 Mb Full Duplex? */
  871. if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
  872. hw_dbg("Advertise 100mb Full duplex\n");
  873. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  874. }
  875. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  876. if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
  877. hw_dbg("Advertise 1000mb Half duplex request denied!\n");
  878. /* Do we want to advertise 1000 Mb Full Duplex? */
  879. if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
  880. hw_dbg("Advertise 1000mb Full duplex\n");
  881. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  882. }
  883. /* Check for a software override of the flow control settings, and
  884. * setup the PHY advertisement registers accordingly. If
  885. * auto-negotiation is enabled, then software will have to set the
  886. * "PAUSE" bits to the correct value in the Auto-Negotiation
  887. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
  888. * negotiation.
  889. *
  890. * The possible values of the "fc" parameter are:
  891. * 0: Flow control is completely disabled
  892. * 1: Rx flow control is enabled (we can receive pause frames
  893. * but not send pause frames).
  894. * 2: Tx flow control is enabled (we can send pause frames
  895. * but we do not support receiving pause frames).
  896. * 3: Both Rx and TX flow control (symmetric) are enabled.
  897. * other: No software override. The flow control configuration
  898. * in the EEPROM is used.
  899. */
  900. switch (hw->fc.current_mode) {
  901. case e1000_fc_none:
  902. /* Flow control (RX & TX) is completely disabled by a
  903. * software over-ride.
  904. */
  905. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  906. break;
  907. case e1000_fc_rx_pause:
  908. /* RX Flow control is enabled, and TX Flow control is
  909. * disabled, by a software over-ride.
  910. *
  911. * Since there really isn't a way to advertise that we are
  912. * capable of RX Pause ONLY, we will advertise that we
  913. * support both symmetric and asymmetric RX PAUSE. Later
  914. * (in e1000_config_fc_after_link_up) we will disable the
  915. * hw's ability to send PAUSE frames.
  916. */
  917. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  918. break;
  919. case e1000_fc_tx_pause:
  920. /* TX Flow control is enabled, and RX Flow control is
  921. * disabled, by a software over-ride.
  922. */
  923. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  924. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  925. break;
  926. case e1000_fc_full:
  927. /* Flow control (both RX and TX) is enabled by a software
  928. * over-ride.
  929. */
  930. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  931. break;
  932. default:
  933. hw_dbg("Flow control param set incorrectly\n");
  934. ret_val = -E1000_ERR_CONFIG;
  935. goto out;
  936. }
  937. ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  938. if (ret_val)
  939. goto out;
  940. hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  941. if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
  942. ret_val = phy->ops.write_reg(hw,
  943. PHY_1000T_CTRL,
  944. mii_1000t_ctrl_reg);
  945. if (ret_val)
  946. goto out;
  947. }
  948. out:
  949. return ret_val;
  950. }
  951. /**
  952. * igb_setup_copper_link - Configure copper link settings
  953. * @hw: pointer to the HW structure
  954. *
  955. * Calls the appropriate function to configure the link for auto-neg or forced
  956. * speed and duplex. Then we check for link, once link is established calls
  957. * to configure collision distance and flow control are called. If link is
  958. * not established, we return -E1000_ERR_PHY (-2).
  959. **/
  960. s32 igb_setup_copper_link(struct e1000_hw *hw)
  961. {
  962. s32 ret_val;
  963. bool link;
  964. if (hw->mac.autoneg) {
  965. /* Setup autoneg and flow control advertisement and perform
  966. * autonegotiation.
  967. */
  968. ret_val = igb_copper_link_autoneg(hw);
  969. if (ret_val)
  970. goto out;
  971. } else {
  972. /* PHY will be set to 10H, 10F, 100H or 100F
  973. * depending on user settings.
  974. */
  975. hw_dbg("Forcing Speed and Duplex\n");
  976. ret_val = hw->phy.ops.force_speed_duplex(hw);
  977. if (ret_val) {
  978. hw_dbg("Error Forcing Speed and Duplex\n");
  979. goto out;
  980. }
  981. }
  982. /* Check link status. Wait up to 100 microseconds for link to become
  983. * valid.
  984. */
  985. ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
  986. if (ret_val)
  987. goto out;
  988. if (link) {
  989. hw_dbg("Valid link established!!!\n");
  990. igb_config_collision_dist(hw);
  991. ret_val = igb_config_fc_after_link_up(hw);
  992. } else {
  993. hw_dbg("Unable to establish link!!!\n");
  994. }
  995. out:
  996. return ret_val;
  997. }
  998. /**
  999. * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
  1000. * @hw: pointer to the HW structure
  1001. *
  1002. * Calls the PHY setup function to force speed and duplex. Clears the
  1003. * auto-crossover to force MDI manually. Waits for link and returns
  1004. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  1005. **/
  1006. s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
  1007. {
  1008. struct e1000_phy_info *phy = &hw->phy;
  1009. s32 ret_val;
  1010. u16 phy_data;
  1011. bool link;
  1012. ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
  1013. if (ret_val)
  1014. goto out;
  1015. igb_phy_force_speed_duplex_setup(hw, &phy_data);
  1016. ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
  1017. if (ret_val)
  1018. goto out;
  1019. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1020. * forced whenever speed and duplex are forced.
  1021. */
  1022. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1023. if (ret_val)
  1024. goto out;
  1025. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1026. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1027. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1028. if (ret_val)
  1029. goto out;
  1030. hw_dbg("IGP PSCR: %X\n", phy_data);
  1031. udelay(1);
  1032. if (phy->autoneg_wait_to_complete) {
  1033. hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
  1034. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
  1035. if (ret_val)
  1036. goto out;
  1037. if (!link)
  1038. hw_dbg("Link taking longer than expected.\n");
  1039. /* Try once more */
  1040. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
  1041. if (ret_val)
  1042. goto out;
  1043. }
  1044. out:
  1045. return ret_val;
  1046. }
  1047. /**
  1048. * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
  1049. * @hw: pointer to the HW structure
  1050. *
  1051. * Calls the PHY setup function to force speed and duplex. Clears the
  1052. * auto-crossover to force MDI manually. Resets the PHY to commit the
  1053. * changes. If time expires while waiting for link up, we reset the DSP.
  1054. * After reset, TX_CLK and CRS on TX must be set. Return successful upon
  1055. * successful completion, else return corresponding error code.
  1056. **/
  1057. s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
  1058. {
  1059. struct e1000_phy_info *phy = &hw->phy;
  1060. s32 ret_val;
  1061. u16 phy_data;
  1062. bool link;
  1063. /* I210 and I211 devices support Auto-Crossover in forced operation. */
  1064. if (phy->type != e1000_phy_i210) {
  1065. /* Clear Auto-Crossover to force MDI manually. M88E1000
  1066. * requires MDI forced whenever speed and duplex are forced.
  1067. */
  1068. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1069. &phy_data);
  1070. if (ret_val)
  1071. goto out;
  1072. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1073. ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1074. phy_data);
  1075. if (ret_val)
  1076. goto out;
  1077. hw_dbg("M88E1000 PSCR: %X\n", phy_data);
  1078. }
  1079. ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
  1080. if (ret_val)
  1081. goto out;
  1082. igb_phy_force_speed_duplex_setup(hw, &phy_data);
  1083. ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
  1084. if (ret_val)
  1085. goto out;
  1086. /* Reset the phy to commit changes. */
  1087. ret_val = igb_phy_sw_reset(hw);
  1088. if (ret_val)
  1089. goto out;
  1090. if (phy->autoneg_wait_to_complete) {
  1091. hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
  1092. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
  1093. if (ret_val)
  1094. goto out;
  1095. if (!link) {
  1096. bool reset_dsp = true;
  1097. switch (hw->phy.id) {
  1098. case I347AT4_E_PHY_ID:
  1099. case M88E1112_E_PHY_ID:
  1100. case I210_I_PHY_ID:
  1101. reset_dsp = false;
  1102. break;
  1103. default:
  1104. if (hw->phy.type != e1000_phy_m88)
  1105. reset_dsp = false;
  1106. break;
  1107. }
  1108. if (!reset_dsp)
  1109. hw_dbg("Link taking longer than expected.\n");
  1110. else {
  1111. /* We didn't get link.
  1112. * Reset the DSP and cross our fingers.
  1113. */
  1114. ret_val = phy->ops.write_reg(hw,
  1115. M88E1000_PHY_PAGE_SELECT,
  1116. 0x001d);
  1117. if (ret_val)
  1118. goto out;
  1119. ret_val = igb_phy_reset_dsp(hw);
  1120. if (ret_val)
  1121. goto out;
  1122. }
  1123. }
  1124. /* Try once more */
  1125. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
  1126. 100000, &link);
  1127. if (ret_val)
  1128. goto out;
  1129. }
  1130. if (hw->phy.type != e1000_phy_m88 ||
  1131. hw->phy.id == I347AT4_E_PHY_ID ||
  1132. hw->phy.id == M88E1112_E_PHY_ID ||
  1133. hw->phy.id == I210_I_PHY_ID)
  1134. goto out;
  1135. ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1136. if (ret_val)
  1137. goto out;
  1138. /* Resetting the phy means we need to re-force TX_CLK in the
  1139. * Extended PHY Specific Control Register to 25MHz clock from
  1140. * the reset value of 2.5MHz.
  1141. */
  1142. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1143. ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1144. if (ret_val)
  1145. goto out;
  1146. /* In addition, we must re-enable CRS on Tx for both half and full
  1147. * duplex.
  1148. */
  1149. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1150. if (ret_val)
  1151. goto out;
  1152. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1153. ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1154. out:
  1155. return ret_val;
  1156. }
  1157. /**
  1158. * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
  1159. * @hw: pointer to the HW structure
  1160. * @phy_ctrl: pointer to current value of PHY_CONTROL
  1161. *
  1162. * Forces speed and duplex on the PHY by doing the following: disable flow
  1163. * control, force speed/duplex on the MAC, disable auto speed detection,
  1164. * disable auto-negotiation, configure duplex, configure speed, configure
  1165. * the collision distance, write configuration to CTRL register. The
  1166. * caller must write to the PHY_CONTROL register for these settings to
  1167. * take affect.
  1168. **/
  1169. static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
  1170. u16 *phy_ctrl)
  1171. {
  1172. struct e1000_mac_info *mac = &hw->mac;
  1173. u32 ctrl;
  1174. /* Turn off flow control when forcing speed/duplex */
  1175. hw->fc.current_mode = e1000_fc_none;
  1176. /* Force speed/duplex on the mac */
  1177. ctrl = rd32(E1000_CTRL);
  1178. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1179. ctrl &= ~E1000_CTRL_SPD_SEL;
  1180. /* Disable Auto Speed Detection */
  1181. ctrl &= ~E1000_CTRL_ASDE;
  1182. /* Disable autoneg on the phy */
  1183. *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
  1184. /* Forcing Full or Half Duplex? */
  1185. if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
  1186. ctrl &= ~E1000_CTRL_FD;
  1187. *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
  1188. hw_dbg("Half Duplex\n");
  1189. } else {
  1190. ctrl |= E1000_CTRL_FD;
  1191. *phy_ctrl |= MII_CR_FULL_DUPLEX;
  1192. hw_dbg("Full Duplex\n");
  1193. }
  1194. /* Forcing 10mb or 100mb? */
  1195. if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
  1196. ctrl |= E1000_CTRL_SPD_100;
  1197. *phy_ctrl |= MII_CR_SPEED_100;
  1198. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1199. hw_dbg("Forcing 100mb\n");
  1200. } else {
  1201. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1202. *phy_ctrl |= MII_CR_SPEED_10;
  1203. *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1204. hw_dbg("Forcing 10mb\n");
  1205. }
  1206. igb_config_collision_dist(hw);
  1207. wr32(E1000_CTRL, ctrl);
  1208. }
  1209. /**
  1210. * igb_set_d3_lplu_state - Sets low power link up state for D3
  1211. * @hw: pointer to the HW structure
  1212. * @active: boolean used to enable/disable lplu
  1213. *
  1214. * Success returns 0, Failure returns 1
  1215. *
  1216. * The low power link up (lplu) state is set to the power management level D3
  1217. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  1218. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  1219. * is used during Dx states where the power conservation is most important.
  1220. * During driver activity, SmartSpeed should be enabled so performance is
  1221. * maintained.
  1222. **/
  1223. s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  1224. {
  1225. struct e1000_phy_info *phy = &hw->phy;
  1226. s32 ret_val = 0;
  1227. u16 data;
  1228. if (!(hw->phy.ops.read_reg))
  1229. goto out;
  1230. ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  1231. if (ret_val)
  1232. goto out;
  1233. if (!active) {
  1234. data &= ~IGP02E1000_PM_D3_LPLU;
  1235. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  1236. data);
  1237. if (ret_val)
  1238. goto out;
  1239. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  1240. * during Dx states where the power conservation is most
  1241. * important. During driver activity we should enable
  1242. * SmartSpeed, so performance is maintained.
  1243. */
  1244. if (phy->smart_speed == e1000_smart_speed_on) {
  1245. ret_val = phy->ops.read_reg(hw,
  1246. IGP01E1000_PHY_PORT_CONFIG,
  1247. &data);
  1248. if (ret_val)
  1249. goto out;
  1250. data |= IGP01E1000_PSCFR_SMART_SPEED;
  1251. ret_val = phy->ops.write_reg(hw,
  1252. IGP01E1000_PHY_PORT_CONFIG,
  1253. data);
  1254. if (ret_val)
  1255. goto out;
  1256. } else if (phy->smart_speed == e1000_smart_speed_off) {
  1257. ret_val = phy->ops.read_reg(hw,
  1258. IGP01E1000_PHY_PORT_CONFIG,
  1259. &data);
  1260. if (ret_val)
  1261. goto out;
  1262. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1263. ret_val = phy->ops.write_reg(hw,
  1264. IGP01E1000_PHY_PORT_CONFIG,
  1265. data);
  1266. if (ret_val)
  1267. goto out;
  1268. }
  1269. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  1270. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  1271. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  1272. data |= IGP02E1000_PM_D3_LPLU;
  1273. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  1274. data);
  1275. if (ret_val)
  1276. goto out;
  1277. /* When LPLU is enabled, we should disable SmartSpeed */
  1278. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  1279. &data);
  1280. if (ret_val)
  1281. goto out;
  1282. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1283. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  1284. data);
  1285. }
  1286. out:
  1287. return ret_val;
  1288. }
  1289. /**
  1290. * igb_check_downshift - Checks whether a downshift in speed occurred
  1291. * @hw: pointer to the HW structure
  1292. *
  1293. * Success returns 0, Failure returns 1
  1294. *
  1295. * A downshift is detected by querying the PHY link health.
  1296. **/
  1297. s32 igb_check_downshift(struct e1000_hw *hw)
  1298. {
  1299. struct e1000_phy_info *phy = &hw->phy;
  1300. s32 ret_val;
  1301. u16 phy_data, offset, mask;
  1302. switch (phy->type) {
  1303. case e1000_phy_i210:
  1304. case e1000_phy_m88:
  1305. case e1000_phy_gg82563:
  1306. offset = M88E1000_PHY_SPEC_STATUS;
  1307. mask = M88E1000_PSSR_DOWNSHIFT;
  1308. break;
  1309. case e1000_phy_igp_2:
  1310. case e1000_phy_igp:
  1311. case e1000_phy_igp_3:
  1312. offset = IGP01E1000_PHY_LINK_HEALTH;
  1313. mask = IGP01E1000_PLHR_SS_DOWNGRADE;
  1314. break;
  1315. default:
  1316. /* speed downshift not supported */
  1317. phy->speed_downgraded = false;
  1318. ret_val = 0;
  1319. goto out;
  1320. }
  1321. ret_val = phy->ops.read_reg(hw, offset, &phy_data);
  1322. if (!ret_val)
  1323. phy->speed_downgraded = (phy_data & mask) ? true : false;
  1324. out:
  1325. return ret_val;
  1326. }
  1327. /**
  1328. * igb_check_polarity_m88 - Checks the polarity.
  1329. * @hw: pointer to the HW structure
  1330. *
  1331. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1332. *
  1333. * Polarity is determined based on the PHY specific status register.
  1334. **/
  1335. s32 igb_check_polarity_m88(struct e1000_hw *hw)
  1336. {
  1337. struct e1000_phy_info *phy = &hw->phy;
  1338. s32 ret_val;
  1339. u16 data;
  1340. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
  1341. if (!ret_val)
  1342. phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
  1343. ? e1000_rev_polarity_reversed
  1344. : e1000_rev_polarity_normal;
  1345. return ret_val;
  1346. }
  1347. /**
  1348. * igb_check_polarity_igp - Checks the polarity.
  1349. * @hw: pointer to the HW structure
  1350. *
  1351. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1352. *
  1353. * Polarity is determined based on the PHY port status register, and the
  1354. * current speed (since there is no polarity at 100Mbps).
  1355. **/
  1356. static s32 igb_check_polarity_igp(struct e1000_hw *hw)
  1357. {
  1358. struct e1000_phy_info *phy = &hw->phy;
  1359. s32 ret_val;
  1360. u16 data, offset, mask;
  1361. /* Polarity is determined based on the speed of
  1362. * our connection.
  1363. */
  1364. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1365. if (ret_val)
  1366. goto out;
  1367. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1368. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1369. offset = IGP01E1000_PHY_PCS_INIT_REG;
  1370. mask = IGP01E1000_PHY_POLARITY_MASK;
  1371. } else {
  1372. /* This really only applies to 10Mbps since
  1373. * there is no polarity for 100Mbps (always 0).
  1374. */
  1375. offset = IGP01E1000_PHY_PORT_STATUS;
  1376. mask = IGP01E1000_PSSR_POLARITY_REVERSED;
  1377. }
  1378. ret_val = phy->ops.read_reg(hw, offset, &data);
  1379. if (!ret_val)
  1380. phy->cable_polarity = (data & mask)
  1381. ? e1000_rev_polarity_reversed
  1382. : e1000_rev_polarity_normal;
  1383. out:
  1384. return ret_val;
  1385. }
  1386. /**
  1387. * igb_wait_autoneg - Wait for auto-neg completion
  1388. * @hw: pointer to the HW structure
  1389. *
  1390. * Waits for auto-negotiation to complete or for the auto-negotiation time
  1391. * limit to expire, which ever happens first.
  1392. **/
  1393. static s32 igb_wait_autoneg(struct e1000_hw *hw)
  1394. {
  1395. s32 ret_val = 0;
  1396. u16 i, phy_status;
  1397. /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
  1398. for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
  1399. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
  1400. if (ret_val)
  1401. break;
  1402. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
  1403. if (ret_val)
  1404. break;
  1405. if (phy_status & MII_SR_AUTONEG_COMPLETE)
  1406. break;
  1407. msleep(100);
  1408. }
  1409. /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
  1410. * has completed.
  1411. */
  1412. return ret_val;
  1413. }
  1414. /**
  1415. * igb_phy_has_link - Polls PHY for link
  1416. * @hw: pointer to the HW structure
  1417. * @iterations: number of times to poll for link
  1418. * @usec_interval: delay between polling attempts
  1419. * @success: pointer to whether polling was successful or not
  1420. *
  1421. * Polls the PHY status register for link, 'iterations' number of times.
  1422. **/
  1423. s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
  1424. u32 usec_interval, bool *success)
  1425. {
  1426. s32 ret_val = 0;
  1427. u16 i, phy_status;
  1428. for (i = 0; i < iterations; i++) {
  1429. /* Some PHYs require the PHY_STATUS register to be read
  1430. * twice due to the link bit being sticky. No harm doing
  1431. * it across the board.
  1432. */
  1433. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
  1434. if (ret_val && usec_interval > 0) {
  1435. /* If the first read fails, another entity may have
  1436. * ownership of the resources, wait and try again to
  1437. * see if they have relinquished the resources yet.
  1438. */
  1439. if (usec_interval >= 1000)
  1440. mdelay(usec_interval/1000);
  1441. else
  1442. udelay(usec_interval);
  1443. }
  1444. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
  1445. if (ret_val)
  1446. break;
  1447. if (phy_status & MII_SR_LINK_STATUS)
  1448. break;
  1449. if (usec_interval >= 1000)
  1450. mdelay(usec_interval/1000);
  1451. else
  1452. udelay(usec_interval);
  1453. }
  1454. *success = (i < iterations) ? true : false;
  1455. return ret_val;
  1456. }
  1457. /**
  1458. * igb_get_cable_length_m88 - Determine cable length for m88 PHY
  1459. * @hw: pointer to the HW structure
  1460. *
  1461. * Reads the PHY specific status register to retrieve the cable length
  1462. * information. The cable length is determined by averaging the minimum and
  1463. * maximum values to get the "average" cable length. The m88 PHY has four
  1464. * possible cable length values, which are:
  1465. * Register Value Cable Length
  1466. * 0 < 50 meters
  1467. * 1 50 - 80 meters
  1468. * 2 80 - 110 meters
  1469. * 3 110 - 140 meters
  1470. * 4 > 140 meters
  1471. **/
  1472. s32 igb_get_cable_length_m88(struct e1000_hw *hw)
  1473. {
  1474. struct e1000_phy_info *phy = &hw->phy;
  1475. s32 ret_val;
  1476. u16 phy_data, index;
  1477. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1478. if (ret_val)
  1479. goto out;
  1480. index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1481. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  1482. if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
  1483. ret_val = -E1000_ERR_PHY;
  1484. goto out;
  1485. }
  1486. phy->min_cable_length = e1000_m88_cable_length_table[index];
  1487. phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
  1488. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1489. out:
  1490. return ret_val;
  1491. }
  1492. s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
  1493. {
  1494. struct e1000_phy_info *phy = &hw->phy;
  1495. s32 ret_val;
  1496. u16 phy_data, phy_data2, index, default_page, is_cm;
  1497. switch (hw->phy.id) {
  1498. case I210_I_PHY_ID:
  1499. /* Get cable length from PHY Cable Diagnostics Control Reg */
  1500. ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
  1501. (I347AT4_PCDL + phy->addr),
  1502. &phy_data);
  1503. if (ret_val)
  1504. return ret_val;
  1505. /* Check if the unit of cable length is meters or cm */
  1506. ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
  1507. I347AT4_PCDC, &phy_data2);
  1508. if (ret_val)
  1509. return ret_val;
  1510. is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
  1511. /* Populate the phy structure with cable length in meters */
  1512. phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
  1513. phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
  1514. phy->cable_length = phy_data / (is_cm ? 100 : 1);
  1515. break;
  1516. case M88E1543_E_PHY_ID:
  1517. case I347AT4_E_PHY_ID:
  1518. /* Remember the original page select and set it to 7 */
  1519. ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
  1520. &default_page);
  1521. if (ret_val)
  1522. goto out;
  1523. ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
  1524. if (ret_val)
  1525. goto out;
  1526. /* Get cable length from PHY Cable Diagnostics Control Reg */
  1527. ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
  1528. &phy_data);
  1529. if (ret_val)
  1530. goto out;
  1531. /* Check if the unit of cable length is meters or cm */
  1532. ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
  1533. if (ret_val)
  1534. goto out;
  1535. is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
  1536. /* Populate the phy structure with cable length in meters */
  1537. phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
  1538. phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
  1539. phy->cable_length = phy_data / (is_cm ? 100 : 1);
  1540. /* Reset the page selec to its original value */
  1541. ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
  1542. default_page);
  1543. if (ret_val)
  1544. goto out;
  1545. break;
  1546. case M88E1112_E_PHY_ID:
  1547. /* Remember the original page select and set it to 5 */
  1548. ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
  1549. &default_page);
  1550. if (ret_val)
  1551. goto out;
  1552. ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
  1553. if (ret_val)
  1554. goto out;
  1555. ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
  1556. &phy_data);
  1557. if (ret_val)
  1558. goto out;
  1559. index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  1560. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  1561. if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
  1562. ret_val = -E1000_ERR_PHY;
  1563. goto out;
  1564. }
  1565. phy->min_cable_length = e1000_m88_cable_length_table[index];
  1566. phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
  1567. phy->cable_length = (phy->min_cable_length +
  1568. phy->max_cable_length) / 2;
  1569. /* Reset the page select to its original value */
  1570. ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
  1571. default_page);
  1572. if (ret_val)
  1573. goto out;
  1574. break;
  1575. default:
  1576. ret_val = -E1000_ERR_PHY;
  1577. goto out;
  1578. }
  1579. out:
  1580. return ret_val;
  1581. }
  1582. /**
  1583. * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
  1584. * @hw: pointer to the HW structure
  1585. *
  1586. * The automatic gain control (agc) normalizes the amplitude of the
  1587. * received signal, adjusting for the attenuation produced by the
  1588. * cable. By reading the AGC registers, which represent the
  1589. * combination of coarse and fine gain value, the value can be put
  1590. * into a lookup table to obtain the approximate cable length
  1591. * for each channel.
  1592. **/
  1593. s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
  1594. {
  1595. struct e1000_phy_info *phy = &hw->phy;
  1596. s32 ret_val = 0;
  1597. u16 phy_data, i, agc_value = 0;
  1598. u16 cur_agc_index, max_agc_index = 0;
  1599. u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
  1600. static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
  1601. IGP02E1000_PHY_AGC_A,
  1602. IGP02E1000_PHY_AGC_B,
  1603. IGP02E1000_PHY_AGC_C,
  1604. IGP02E1000_PHY_AGC_D
  1605. };
  1606. /* Read the AGC registers for all channels */
  1607. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  1608. ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
  1609. if (ret_val)
  1610. goto out;
  1611. /* Getting bits 15:9, which represent the combination of
  1612. * coarse and fine gain values. The result is a number
  1613. * that can be put into the lookup table to obtain the
  1614. * approximate cable length.
  1615. */
  1616. cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  1617. IGP02E1000_AGC_LENGTH_MASK;
  1618. /* Array index bound check. */
  1619. if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
  1620. (cur_agc_index == 0)) {
  1621. ret_val = -E1000_ERR_PHY;
  1622. goto out;
  1623. }
  1624. /* Remove min & max AGC values from calculation. */
  1625. if (e1000_igp_2_cable_length_table[min_agc_index] >
  1626. e1000_igp_2_cable_length_table[cur_agc_index])
  1627. min_agc_index = cur_agc_index;
  1628. if (e1000_igp_2_cable_length_table[max_agc_index] <
  1629. e1000_igp_2_cable_length_table[cur_agc_index])
  1630. max_agc_index = cur_agc_index;
  1631. agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
  1632. }
  1633. agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
  1634. e1000_igp_2_cable_length_table[max_agc_index]);
  1635. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  1636. /* Calculate cable length with the error range of +/- 10 meters. */
  1637. phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  1638. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  1639. phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
  1640. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  1641. out:
  1642. return ret_val;
  1643. }
  1644. /**
  1645. * igb_get_phy_info_m88 - Retrieve PHY information
  1646. * @hw: pointer to the HW structure
  1647. *
  1648. * Valid for only copper links. Read the PHY status register (sticky read)
  1649. * to verify that link is up. Read the PHY special control register to
  1650. * determine the polarity and 10base-T extended distance. Read the PHY
  1651. * special status register to determine MDI/MDIx and current speed. If
  1652. * speed is 1000, then determine cable length, local and remote receiver.
  1653. **/
  1654. s32 igb_get_phy_info_m88(struct e1000_hw *hw)
  1655. {
  1656. struct e1000_phy_info *phy = &hw->phy;
  1657. s32 ret_val;
  1658. u16 phy_data;
  1659. bool link;
  1660. if (phy->media_type != e1000_media_type_copper) {
  1661. hw_dbg("Phy info is only valid for copper media\n");
  1662. ret_val = -E1000_ERR_CONFIG;
  1663. goto out;
  1664. }
  1665. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  1666. if (ret_val)
  1667. goto out;
  1668. if (!link) {
  1669. hw_dbg("Phy info is only valid if link is up\n");
  1670. ret_val = -E1000_ERR_CONFIG;
  1671. goto out;
  1672. }
  1673. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1674. if (ret_val)
  1675. goto out;
  1676. phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
  1677. ? true : false;
  1678. ret_val = igb_check_polarity_m88(hw);
  1679. if (ret_val)
  1680. goto out;
  1681. ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1682. if (ret_val)
  1683. goto out;
  1684. phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
  1685. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  1686. ret_val = phy->ops.get_cable_length(hw);
  1687. if (ret_val)
  1688. goto out;
  1689. ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
  1690. if (ret_val)
  1691. goto out;
  1692. phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
  1693. ? e1000_1000t_rx_status_ok
  1694. : e1000_1000t_rx_status_not_ok;
  1695. phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
  1696. ? e1000_1000t_rx_status_ok
  1697. : e1000_1000t_rx_status_not_ok;
  1698. } else {
  1699. /* Set values to "undefined" */
  1700. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1701. phy->local_rx = e1000_1000t_rx_status_undefined;
  1702. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1703. }
  1704. out:
  1705. return ret_val;
  1706. }
  1707. /**
  1708. * igb_get_phy_info_igp - Retrieve igp PHY information
  1709. * @hw: pointer to the HW structure
  1710. *
  1711. * Read PHY status to determine if link is up. If link is up, then
  1712. * set/determine 10base-T extended distance and polarity correction. Read
  1713. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  1714. * determine on the cable length, local and remote receiver.
  1715. **/
  1716. s32 igb_get_phy_info_igp(struct e1000_hw *hw)
  1717. {
  1718. struct e1000_phy_info *phy = &hw->phy;
  1719. s32 ret_val;
  1720. u16 data;
  1721. bool link;
  1722. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  1723. if (ret_val)
  1724. goto out;
  1725. if (!link) {
  1726. hw_dbg("Phy info is only valid if link is up\n");
  1727. ret_val = -E1000_ERR_CONFIG;
  1728. goto out;
  1729. }
  1730. phy->polarity_correction = true;
  1731. ret_val = igb_check_polarity_igp(hw);
  1732. if (ret_val)
  1733. goto out;
  1734. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
  1735. if (ret_val)
  1736. goto out;
  1737. phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
  1738. if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
  1739. IGP01E1000_PSSR_SPEED_1000MBPS) {
  1740. ret_val = phy->ops.get_cable_length(hw);
  1741. if (ret_val)
  1742. goto out;
  1743. ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
  1744. if (ret_val)
  1745. goto out;
  1746. phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
  1747. ? e1000_1000t_rx_status_ok
  1748. : e1000_1000t_rx_status_not_ok;
  1749. phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
  1750. ? e1000_1000t_rx_status_ok
  1751. : e1000_1000t_rx_status_not_ok;
  1752. } else {
  1753. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  1754. phy->local_rx = e1000_1000t_rx_status_undefined;
  1755. phy->remote_rx = e1000_1000t_rx_status_undefined;
  1756. }
  1757. out:
  1758. return ret_val;
  1759. }
  1760. /**
  1761. * igb_phy_sw_reset - PHY software reset
  1762. * @hw: pointer to the HW structure
  1763. *
  1764. * Does a software reset of the PHY by reading the PHY control register and
  1765. * setting/write the control register reset bit to the PHY.
  1766. **/
  1767. s32 igb_phy_sw_reset(struct e1000_hw *hw)
  1768. {
  1769. s32 ret_val = 0;
  1770. u16 phy_ctrl;
  1771. if (!(hw->phy.ops.read_reg))
  1772. goto out;
  1773. ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
  1774. if (ret_val)
  1775. goto out;
  1776. phy_ctrl |= MII_CR_RESET;
  1777. ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
  1778. if (ret_val)
  1779. goto out;
  1780. udelay(1);
  1781. out:
  1782. return ret_val;
  1783. }
  1784. /**
  1785. * igb_phy_hw_reset - PHY hardware reset
  1786. * @hw: pointer to the HW structure
  1787. *
  1788. * Verify the reset block is not blocking us from resetting. Acquire
  1789. * semaphore (if necessary) and read/set/write the device control reset
  1790. * bit in the PHY. Wait the appropriate delay time for the device to
  1791. * reset and release the semaphore (if necessary).
  1792. **/
  1793. s32 igb_phy_hw_reset(struct e1000_hw *hw)
  1794. {
  1795. struct e1000_phy_info *phy = &hw->phy;
  1796. s32 ret_val;
  1797. u32 ctrl;
  1798. ret_val = igb_check_reset_block(hw);
  1799. if (ret_val) {
  1800. ret_val = 0;
  1801. goto out;
  1802. }
  1803. ret_val = phy->ops.acquire(hw);
  1804. if (ret_val)
  1805. goto out;
  1806. ctrl = rd32(E1000_CTRL);
  1807. wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
  1808. wrfl();
  1809. udelay(phy->reset_delay_us);
  1810. wr32(E1000_CTRL, ctrl);
  1811. wrfl();
  1812. udelay(150);
  1813. phy->ops.release(hw);
  1814. ret_val = phy->ops.get_cfg_done(hw);
  1815. out:
  1816. return ret_val;
  1817. }
  1818. /**
  1819. * igb_phy_init_script_igp3 - Inits the IGP3 PHY
  1820. * @hw: pointer to the HW structure
  1821. *
  1822. * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
  1823. **/
  1824. s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
  1825. {
  1826. hw_dbg("Running IGP 3 PHY init script\n");
  1827. /* PHY init IGP 3 */
  1828. /* Enable rise/fall, 10-mode work in class-A */
  1829. hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
  1830. /* Remove all caps from Replica path filter */
  1831. hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
  1832. /* Bias trimming for ADC, AFE and Driver (Default) */
  1833. hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
  1834. /* Increase Hybrid poly bias */
  1835. hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
  1836. /* Add 4% to TX amplitude in Giga mode */
  1837. hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
  1838. /* Disable trimming (TTT) */
  1839. hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
  1840. /* Poly DC correction to 94.6% + 2% for all channels */
  1841. hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
  1842. /* ABS DC correction to 95.9% */
  1843. hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
  1844. /* BG temp curve trim */
  1845. hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
  1846. /* Increasing ADC OPAMP stage 1 currents to max */
  1847. hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
  1848. /* Force 1000 ( required for enabling PHY regs configuration) */
  1849. hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
  1850. /* Set upd_freq to 6 */
  1851. hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
  1852. /* Disable NPDFE */
  1853. hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
  1854. /* Disable adaptive fixed FFE (Default) */
  1855. hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
  1856. /* Enable FFE hysteresis */
  1857. hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
  1858. /* Fixed FFE for short cable lengths */
  1859. hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
  1860. /* Fixed FFE for medium cable lengths */
  1861. hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
  1862. /* Fixed FFE for long cable lengths */
  1863. hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
  1864. /* Enable Adaptive Clip Threshold */
  1865. hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
  1866. /* AHT reset limit to 1 */
  1867. hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
  1868. /* Set AHT master delay to 127 msec */
  1869. hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
  1870. /* Set scan bits for AHT */
  1871. hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
  1872. /* Set AHT Preset bits */
  1873. hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
  1874. /* Change integ_factor of channel A to 3 */
  1875. hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
  1876. /* Change prop_factor of channels BCD to 8 */
  1877. hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
  1878. /* Change cg_icount + enable integbp for channels BCD */
  1879. hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
  1880. /* Change cg_icount + enable integbp + change prop_factor_master
  1881. * to 8 for channel A
  1882. */
  1883. hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
  1884. /* Disable AHT in Slave mode on channel A */
  1885. hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
  1886. /* Enable LPLU and disable AN to 1000 in non-D0a states,
  1887. * Enable SPD+B2B
  1888. */
  1889. hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
  1890. /* Enable restart AN on an1000_dis change */
  1891. hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
  1892. /* Enable wh_fifo read clock in 10/100 modes */
  1893. hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
  1894. /* Restart AN, Speed selection is 1000 */
  1895. hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
  1896. return 0;
  1897. }
  1898. /**
  1899. * igb_power_up_phy_copper - Restore copper link in case of PHY power down
  1900. * @hw: pointer to the HW structure
  1901. *
  1902. * In the case of a PHY power down to save power, or to turn off link during a
  1903. * driver unload, restore the link to previous settings.
  1904. **/
  1905. void igb_power_up_phy_copper(struct e1000_hw *hw)
  1906. {
  1907. u16 mii_reg = 0;
  1908. /* The PHY will retain its settings across a power down/up cycle */
  1909. hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
  1910. mii_reg &= ~MII_CR_POWER_DOWN;
  1911. hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
  1912. }
  1913. /**
  1914. * igb_power_down_phy_copper - Power down copper PHY
  1915. * @hw: pointer to the HW structure
  1916. *
  1917. * Power down PHY to save power when interface is down and wake on lan
  1918. * is not enabled.
  1919. **/
  1920. void igb_power_down_phy_copper(struct e1000_hw *hw)
  1921. {
  1922. u16 mii_reg = 0;
  1923. /* The PHY will retain its settings across a power down/up cycle */
  1924. hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
  1925. mii_reg |= MII_CR_POWER_DOWN;
  1926. hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
  1927. usleep_range(1000, 2000);
  1928. }
  1929. /**
  1930. * igb_check_polarity_82580 - Checks the polarity.
  1931. * @hw: pointer to the HW structure
  1932. *
  1933. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1934. *
  1935. * Polarity is determined based on the PHY specific status register.
  1936. **/
  1937. static s32 igb_check_polarity_82580(struct e1000_hw *hw)
  1938. {
  1939. struct e1000_phy_info *phy = &hw->phy;
  1940. s32 ret_val;
  1941. u16 data;
  1942. ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
  1943. if (!ret_val)
  1944. phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
  1945. ? e1000_rev_polarity_reversed
  1946. : e1000_rev_polarity_normal;
  1947. return ret_val;
  1948. }
  1949. /**
  1950. * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
  1951. * @hw: pointer to the HW structure
  1952. *
  1953. * Calls the PHY setup function to force speed and duplex. Clears the
  1954. * auto-crossover to force MDI manually. Waits for link and returns
  1955. * successful if link up is successful, else -E1000_ERR_PHY (-2).
  1956. **/
  1957. s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
  1958. {
  1959. struct e1000_phy_info *phy = &hw->phy;
  1960. s32 ret_val;
  1961. u16 phy_data;
  1962. bool link;
  1963. ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
  1964. if (ret_val)
  1965. goto out;
  1966. igb_phy_force_speed_duplex_setup(hw, &phy_data);
  1967. ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
  1968. if (ret_val)
  1969. goto out;
  1970. /* Clear Auto-Crossover to force MDI manually. 82580 requires MDI
  1971. * forced whenever speed and duplex are forced.
  1972. */
  1973. ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
  1974. if (ret_val)
  1975. goto out;
  1976. phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
  1977. ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
  1978. if (ret_val)
  1979. goto out;
  1980. hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
  1981. udelay(1);
  1982. if (phy->autoneg_wait_to_complete) {
  1983. hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
  1984. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
  1985. if (ret_val)
  1986. goto out;
  1987. if (!link)
  1988. hw_dbg("Link taking longer than expected.\n");
  1989. /* Try once more */
  1990. ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
  1991. if (ret_val)
  1992. goto out;
  1993. }
  1994. out:
  1995. return ret_val;
  1996. }
  1997. /**
  1998. * igb_get_phy_info_82580 - Retrieve I82580 PHY information
  1999. * @hw: pointer to the HW structure
  2000. *
  2001. * Read PHY status to determine if link is up. If link is up, then
  2002. * set/determine 10base-T extended distance and polarity correction. Read
  2003. * PHY port status to determine MDI/MDIx and speed. Based on the speed,
  2004. * determine on the cable length, local and remote receiver.
  2005. **/
  2006. s32 igb_get_phy_info_82580(struct e1000_hw *hw)
  2007. {
  2008. struct e1000_phy_info *phy = &hw->phy;
  2009. s32 ret_val;
  2010. u16 data;
  2011. bool link;
  2012. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  2013. if (ret_val)
  2014. goto out;
  2015. if (!link) {
  2016. hw_dbg("Phy info is only valid if link is up\n");
  2017. ret_val = -E1000_ERR_CONFIG;
  2018. goto out;
  2019. }
  2020. phy->polarity_correction = true;
  2021. ret_val = igb_check_polarity_82580(hw);
  2022. if (ret_val)
  2023. goto out;
  2024. ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
  2025. if (ret_val)
  2026. goto out;
  2027. phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
  2028. if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
  2029. I82580_PHY_STATUS2_SPEED_1000MBPS) {
  2030. ret_val = hw->phy.ops.get_cable_length(hw);
  2031. if (ret_val)
  2032. goto out;
  2033. ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
  2034. if (ret_val)
  2035. goto out;
  2036. phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
  2037. ? e1000_1000t_rx_status_ok
  2038. : e1000_1000t_rx_status_not_ok;
  2039. phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
  2040. ? e1000_1000t_rx_status_ok
  2041. : e1000_1000t_rx_status_not_ok;
  2042. } else {
  2043. phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  2044. phy->local_rx = e1000_1000t_rx_status_undefined;
  2045. phy->remote_rx = e1000_1000t_rx_status_undefined;
  2046. }
  2047. out:
  2048. return ret_val;
  2049. }
  2050. /**
  2051. * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
  2052. * @hw: pointer to the HW structure
  2053. *
  2054. * Reads the diagnostic status register and verifies result is valid before
  2055. * placing it in the phy_cable_length field.
  2056. **/
  2057. s32 igb_get_cable_length_82580(struct e1000_hw *hw)
  2058. {
  2059. struct e1000_phy_info *phy = &hw->phy;
  2060. s32 ret_val;
  2061. u16 phy_data, length;
  2062. ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data);
  2063. if (ret_val)
  2064. goto out;
  2065. length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >>
  2066. I82580_DSTATUS_CABLE_LENGTH_SHIFT;
  2067. if (length == E1000_CABLE_LENGTH_UNDEFINED)
  2068. ret_val = -E1000_ERR_PHY;
  2069. phy->cable_length = length;
  2070. out:
  2071. return ret_val;
  2072. }
  2073. /**
  2074. * igb_write_phy_reg_gs40g - Write GS40G PHY register
  2075. * @hw: pointer to the HW structure
  2076. * @offset: lower half is register offset to write to
  2077. * upper half is page to use.
  2078. * @data: data to write at register offset
  2079. *
  2080. * Acquires semaphore, if necessary, then writes the data to PHY register
  2081. * at the offset. Release any acquired semaphores before exiting.
  2082. **/
  2083. s32 igb_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data)
  2084. {
  2085. s32 ret_val;
  2086. u16 page = offset >> GS40G_PAGE_SHIFT;
  2087. offset = offset & GS40G_OFFSET_MASK;
  2088. ret_val = hw->phy.ops.acquire(hw);
  2089. if (ret_val)
  2090. return ret_val;
  2091. ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
  2092. if (ret_val)
  2093. goto release;
  2094. ret_val = igb_write_phy_reg_mdic(hw, offset, data);
  2095. release:
  2096. hw->phy.ops.release(hw);
  2097. return ret_val;
  2098. }
  2099. /**
  2100. * igb_read_phy_reg_gs40g - Read GS40G PHY register
  2101. * @hw: pointer to the HW structure
  2102. * @offset: lower half is register offset to read to
  2103. * upper half is page to use.
  2104. * @data: data to read at register offset
  2105. *
  2106. * Acquires semaphore, if necessary, then reads the data in the PHY register
  2107. * at the offset. Release any acquired semaphores before exiting.
  2108. **/
  2109. s32 igb_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data)
  2110. {
  2111. s32 ret_val;
  2112. u16 page = offset >> GS40G_PAGE_SHIFT;
  2113. offset = offset & GS40G_OFFSET_MASK;
  2114. ret_val = hw->phy.ops.acquire(hw);
  2115. if (ret_val)
  2116. return ret_val;
  2117. ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
  2118. if (ret_val)
  2119. goto release;
  2120. ret_val = igb_read_phy_reg_mdic(hw, offset, data);
  2121. release:
  2122. hw->phy.ops.release(hw);
  2123. return ret_val;
  2124. }
  2125. /**
  2126. * igb_set_master_slave_mode - Setup PHY for Master/slave mode
  2127. * @hw: pointer to the HW structure
  2128. *
  2129. * Sets up Master/slave mode
  2130. **/
  2131. static s32 igb_set_master_slave_mode(struct e1000_hw *hw)
  2132. {
  2133. s32 ret_val;
  2134. u16 phy_data;
  2135. /* Resolve Master/Slave mode */
  2136. ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
  2137. if (ret_val)
  2138. return ret_val;
  2139. /* load defaults for future use */
  2140. hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
  2141. ((phy_data & CR_1000T_MS_VALUE) ?
  2142. e1000_ms_force_master :
  2143. e1000_ms_force_slave) : e1000_ms_auto;
  2144. switch (hw->phy.ms_type) {
  2145. case e1000_ms_force_master:
  2146. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  2147. break;
  2148. case e1000_ms_force_slave:
  2149. phy_data |= CR_1000T_MS_ENABLE;
  2150. phy_data &= ~(CR_1000T_MS_VALUE);
  2151. break;
  2152. case e1000_ms_auto:
  2153. phy_data &= ~CR_1000T_MS_ENABLE;
  2154. /* fall-through */
  2155. default:
  2156. break;
  2157. }
  2158. return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
  2159. }