ixgbe_phy.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2011 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include "ixgbe_common.h"
  24. #include "ixgbe_phy.h"
  25. static void ixgbe_i2c_start(struct ixgbe_hw *hw);
  26. static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
  27. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
  28. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
  29. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
  30. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
  31. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
  32. static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
  33. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
  34. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
  35. static bool ixgbe_get_i2c_data(u32 *i2cctl);
  36. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
  37. static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
  38. static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
  39. /**
  40. * ixgbe_identify_phy_generic - Get physical layer module
  41. * @hw: pointer to hardware structure
  42. *
  43. * Determines the physical layer module found on the current adapter.
  44. **/
  45. s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
  46. {
  47. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  48. u32 phy_addr;
  49. u16 ext_ability = 0;
  50. if (hw->phy.type == ixgbe_phy_unknown) {
  51. for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
  52. hw->phy.mdio.prtad = phy_addr;
  53. if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
  54. ixgbe_get_phy_id(hw);
  55. hw->phy.type =
  56. ixgbe_get_phy_type_from_id(hw->phy.id);
  57. if (hw->phy.type == ixgbe_phy_unknown) {
  58. hw->phy.ops.read_reg(hw,
  59. MDIO_PMA_EXTABLE,
  60. MDIO_MMD_PMAPMD,
  61. &ext_ability);
  62. if (ext_ability &
  63. (MDIO_PMA_EXTABLE_10GBT |
  64. MDIO_PMA_EXTABLE_1000BT))
  65. hw->phy.type =
  66. ixgbe_phy_cu_unknown;
  67. else
  68. hw->phy.type =
  69. ixgbe_phy_generic;
  70. }
  71. status = 0;
  72. break;
  73. }
  74. }
  75. /* clear value if nothing found */
  76. if (status != 0)
  77. hw->phy.mdio.prtad = 0;
  78. } else {
  79. status = 0;
  80. }
  81. return status;
  82. }
  83. /**
  84. * ixgbe_get_phy_id - Get the phy type
  85. * @hw: pointer to hardware structure
  86. *
  87. **/
  88. static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
  89. {
  90. u32 status;
  91. u16 phy_id_high = 0;
  92. u16 phy_id_low = 0;
  93. status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
  94. &phy_id_high);
  95. if (status == 0) {
  96. hw->phy.id = (u32)(phy_id_high << 16);
  97. status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
  98. &phy_id_low);
  99. hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
  100. hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
  101. }
  102. return status;
  103. }
  104. /**
  105. * ixgbe_get_phy_type_from_id - Get the phy type
  106. * @hw: pointer to hardware structure
  107. *
  108. **/
  109. static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
  110. {
  111. enum ixgbe_phy_type phy_type;
  112. switch (phy_id) {
  113. case TN1010_PHY_ID:
  114. phy_type = ixgbe_phy_tn;
  115. break;
  116. case X540_PHY_ID:
  117. phy_type = ixgbe_phy_aq;
  118. break;
  119. case QT2022_PHY_ID:
  120. phy_type = ixgbe_phy_qt;
  121. break;
  122. case ATH_PHY_ID:
  123. phy_type = ixgbe_phy_nl;
  124. break;
  125. default:
  126. phy_type = ixgbe_phy_unknown;
  127. break;
  128. }
  129. return phy_type;
  130. }
  131. /**
  132. * ixgbe_reset_phy_generic - Performs a PHY reset
  133. * @hw: pointer to hardware structure
  134. **/
  135. s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
  136. {
  137. u32 i;
  138. u16 ctrl = 0;
  139. s32 status = 0;
  140. if (hw->phy.type == ixgbe_phy_unknown)
  141. status = ixgbe_identify_phy_generic(hw);
  142. if (status != 0 || hw->phy.type == ixgbe_phy_none)
  143. goto out;
  144. /* Don't reset PHY if it's shut down due to overtemp. */
  145. if (!hw->phy.reset_if_overtemp &&
  146. (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
  147. goto out;
  148. /*
  149. * Perform soft PHY reset to the PHY_XS.
  150. * This will cause a soft reset to the PHY
  151. */
  152. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  153. MDIO_MMD_PHYXS,
  154. MDIO_CTRL1_RESET);
  155. /*
  156. * Poll for reset bit to self-clear indicating reset is complete.
  157. * Some PHYs could take up to 3 seconds to complete and need about
  158. * 1.7 usec delay after the reset is complete.
  159. */
  160. for (i = 0; i < 30; i++) {
  161. msleep(100);
  162. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  163. MDIO_MMD_PHYXS, &ctrl);
  164. if (!(ctrl & MDIO_CTRL1_RESET)) {
  165. udelay(2);
  166. break;
  167. }
  168. }
  169. if (ctrl & MDIO_CTRL1_RESET) {
  170. status = IXGBE_ERR_RESET_FAILED;
  171. hw_dbg(hw, "PHY reset polling failed to complete.\n");
  172. }
  173. out:
  174. return status;
  175. }
  176. /**
  177. * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
  178. * @hw: pointer to hardware structure
  179. * @reg_addr: 32 bit address of PHY register to read
  180. * @phy_data: Pointer to read data from PHY register
  181. **/
  182. s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  183. u32 device_type, u16 *phy_data)
  184. {
  185. u32 command;
  186. u32 i;
  187. u32 data;
  188. s32 status = 0;
  189. u16 gssr;
  190. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  191. gssr = IXGBE_GSSR_PHY1_SM;
  192. else
  193. gssr = IXGBE_GSSR_PHY0_SM;
  194. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0)
  195. status = IXGBE_ERR_SWFW_SYNC;
  196. if (status == 0) {
  197. /* Setup and write the address cycle command */
  198. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  199. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  200. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  201. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  202. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  203. /*
  204. * Check every 10 usec to see if the address cycle completed.
  205. * The MDI Command bit will clear when the operation is
  206. * complete
  207. */
  208. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  209. udelay(10);
  210. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  211. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  212. break;
  213. }
  214. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  215. hw_dbg(hw, "PHY address command did not complete.\n");
  216. status = IXGBE_ERR_PHY;
  217. }
  218. if (status == 0) {
  219. /*
  220. * Address cycle complete, setup and write the read
  221. * command
  222. */
  223. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  224. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  225. (hw->phy.mdio.prtad <<
  226. IXGBE_MSCA_PHY_ADDR_SHIFT) |
  227. (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
  228. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  229. /*
  230. * Check every 10 usec to see if the address cycle
  231. * completed. The MDI Command bit will clear when the
  232. * operation is complete
  233. */
  234. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  235. udelay(10);
  236. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  237. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  238. break;
  239. }
  240. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  241. hw_dbg(hw, "PHY read command didn't complete\n");
  242. status = IXGBE_ERR_PHY;
  243. } else {
  244. /*
  245. * Read operation is complete. Get the data
  246. * from MSRWD
  247. */
  248. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  249. data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
  250. *phy_data = (u16)(data);
  251. }
  252. }
  253. hw->mac.ops.release_swfw_sync(hw, gssr);
  254. }
  255. return status;
  256. }
  257. /**
  258. * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
  259. * @hw: pointer to hardware structure
  260. * @reg_addr: 32 bit PHY register to write
  261. * @device_type: 5 bit device type
  262. * @phy_data: Data to write to the PHY register
  263. **/
  264. s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  265. u32 device_type, u16 phy_data)
  266. {
  267. u32 command;
  268. u32 i;
  269. s32 status = 0;
  270. u16 gssr;
  271. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  272. gssr = IXGBE_GSSR_PHY1_SM;
  273. else
  274. gssr = IXGBE_GSSR_PHY0_SM;
  275. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0)
  276. status = IXGBE_ERR_SWFW_SYNC;
  277. if (status == 0) {
  278. /* Put the data in the MDI single read and write data register*/
  279. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
  280. /* Setup and write the address cycle command */
  281. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  282. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  283. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  284. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  285. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  286. /*
  287. * Check every 10 usec to see if the address cycle completed.
  288. * The MDI Command bit will clear when the operation is
  289. * complete
  290. */
  291. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  292. udelay(10);
  293. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  294. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  295. break;
  296. }
  297. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  298. hw_dbg(hw, "PHY address cmd didn't complete\n");
  299. status = IXGBE_ERR_PHY;
  300. }
  301. if (status == 0) {
  302. /*
  303. * Address cycle complete, setup and write the write
  304. * command
  305. */
  306. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  307. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  308. (hw->phy.mdio.prtad <<
  309. IXGBE_MSCA_PHY_ADDR_SHIFT) |
  310. (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
  311. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  312. /*
  313. * Check every 10 usec to see if the address cycle
  314. * completed. The MDI Command bit will clear when the
  315. * operation is complete
  316. */
  317. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  318. udelay(10);
  319. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  320. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  321. break;
  322. }
  323. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  324. hw_dbg(hw, "PHY address cmd didn't complete\n");
  325. status = IXGBE_ERR_PHY;
  326. }
  327. }
  328. hw->mac.ops.release_swfw_sync(hw, gssr);
  329. }
  330. return status;
  331. }
  332. /**
  333. * ixgbe_setup_phy_link_generic - Set and restart autoneg
  334. * @hw: pointer to hardware structure
  335. *
  336. * Restart autonegotiation and PHY and waits for completion.
  337. **/
  338. s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
  339. {
  340. s32 status = 0;
  341. u32 time_out;
  342. u32 max_time_out = 10;
  343. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  344. bool autoneg = false;
  345. ixgbe_link_speed speed;
  346. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  347. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  348. /* Set or unset auto-negotiation 10G advertisement */
  349. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  350. MDIO_MMD_AN,
  351. &autoneg_reg);
  352. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  353. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  354. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  355. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  356. MDIO_MMD_AN,
  357. autoneg_reg);
  358. }
  359. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  360. /* Set or unset auto-negotiation 1G advertisement */
  361. hw->phy.ops.read_reg(hw,
  362. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  363. MDIO_MMD_AN,
  364. &autoneg_reg);
  365. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
  366. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  367. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
  368. hw->phy.ops.write_reg(hw,
  369. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  370. MDIO_MMD_AN,
  371. autoneg_reg);
  372. }
  373. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  374. /* Set or unset auto-negotiation 100M advertisement */
  375. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  376. MDIO_MMD_AN,
  377. &autoneg_reg);
  378. autoneg_reg &= ~(ADVERTISE_100FULL |
  379. ADVERTISE_100HALF);
  380. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  381. autoneg_reg |= ADVERTISE_100FULL;
  382. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  383. MDIO_MMD_AN,
  384. autoneg_reg);
  385. }
  386. /* Restart PHY autonegotiation and wait for completion */
  387. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  388. MDIO_MMD_AN, &autoneg_reg);
  389. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  390. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  391. MDIO_MMD_AN, autoneg_reg);
  392. /* Wait for autonegotiation to finish */
  393. for (time_out = 0; time_out < max_time_out; time_out++) {
  394. udelay(10);
  395. /* Restart PHY autonegotiation and wait for completion */
  396. status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
  397. MDIO_MMD_AN,
  398. &autoneg_reg);
  399. autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
  400. if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
  401. break;
  402. }
  403. }
  404. if (time_out == max_time_out) {
  405. status = IXGBE_ERR_LINK_SETUP;
  406. hw_dbg(hw, "ixgbe_setup_phy_link_generic: time out");
  407. }
  408. return status;
  409. }
  410. /**
  411. * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
  412. * @hw: pointer to hardware structure
  413. * @speed: new link speed
  414. * @autoneg: true if autonegotiation enabled
  415. **/
  416. s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  417. ixgbe_link_speed speed,
  418. bool autoneg,
  419. bool autoneg_wait_to_complete)
  420. {
  421. /*
  422. * Clear autoneg_advertised and set new values based on input link
  423. * speed.
  424. */
  425. hw->phy.autoneg_advertised = 0;
  426. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  427. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  428. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  429. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  430. if (speed & IXGBE_LINK_SPEED_100_FULL)
  431. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  432. /* Setup link based on the new speed settings */
  433. hw->phy.ops.setup_link(hw);
  434. return 0;
  435. }
  436. /**
  437. * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
  438. * @hw: pointer to hardware structure
  439. * @speed: pointer to link speed
  440. * @autoneg: boolean auto-negotiation value
  441. *
  442. * Determines the link capabilities by reading the AUTOC register.
  443. */
  444. s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
  445. ixgbe_link_speed *speed,
  446. bool *autoneg)
  447. {
  448. s32 status = IXGBE_ERR_LINK_SETUP;
  449. u16 speed_ability;
  450. *speed = 0;
  451. *autoneg = true;
  452. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  453. &speed_ability);
  454. if (status == 0) {
  455. if (speed_ability & MDIO_SPEED_10G)
  456. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  457. if (speed_ability & MDIO_PMA_SPEED_1000)
  458. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  459. if (speed_ability & MDIO_PMA_SPEED_100)
  460. *speed |= IXGBE_LINK_SPEED_100_FULL;
  461. }
  462. return status;
  463. }
  464. /**
  465. * ixgbe_check_phy_link_tnx - Determine link and speed status
  466. * @hw: pointer to hardware structure
  467. *
  468. * Reads the VS1 register to determine if link is up and the current speed for
  469. * the PHY.
  470. **/
  471. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  472. bool *link_up)
  473. {
  474. s32 status = 0;
  475. u32 time_out;
  476. u32 max_time_out = 10;
  477. u16 phy_link = 0;
  478. u16 phy_speed = 0;
  479. u16 phy_data = 0;
  480. /* Initialize speed and link to default case */
  481. *link_up = false;
  482. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  483. /*
  484. * Check current speed and link status of the PHY register.
  485. * This is a vendor specific register and may have to
  486. * be changed for other copper PHYs.
  487. */
  488. for (time_out = 0; time_out < max_time_out; time_out++) {
  489. udelay(10);
  490. status = hw->phy.ops.read_reg(hw,
  491. MDIO_STAT1,
  492. MDIO_MMD_VEND1,
  493. &phy_data);
  494. phy_link = phy_data &
  495. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  496. phy_speed = phy_data &
  497. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  498. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  499. *link_up = true;
  500. if (phy_speed ==
  501. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  502. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  503. break;
  504. }
  505. }
  506. return status;
  507. }
  508. /**
  509. * ixgbe_setup_phy_link_tnx - Set and restart autoneg
  510. * @hw: pointer to hardware structure
  511. *
  512. * Restart autonegotiation and PHY and waits for completion.
  513. **/
  514. s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
  515. {
  516. s32 status = 0;
  517. u32 time_out;
  518. u32 max_time_out = 10;
  519. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  520. bool autoneg = false;
  521. ixgbe_link_speed speed;
  522. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  523. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  524. /* Set or unset auto-negotiation 10G advertisement */
  525. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  526. MDIO_MMD_AN,
  527. &autoneg_reg);
  528. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  529. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  530. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  531. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  532. MDIO_MMD_AN,
  533. autoneg_reg);
  534. }
  535. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  536. /* Set or unset auto-negotiation 1G advertisement */
  537. hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  538. MDIO_MMD_AN,
  539. &autoneg_reg);
  540. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  541. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  542. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  543. hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  544. MDIO_MMD_AN,
  545. autoneg_reg);
  546. }
  547. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  548. /* Set or unset auto-negotiation 100M advertisement */
  549. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  550. MDIO_MMD_AN,
  551. &autoneg_reg);
  552. autoneg_reg &= ~(ADVERTISE_100FULL |
  553. ADVERTISE_100HALF);
  554. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  555. autoneg_reg |= ADVERTISE_100FULL;
  556. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  557. MDIO_MMD_AN,
  558. autoneg_reg);
  559. }
  560. /* Restart PHY autonegotiation and wait for completion */
  561. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  562. MDIO_MMD_AN, &autoneg_reg);
  563. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  564. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  565. MDIO_MMD_AN, autoneg_reg);
  566. /* Wait for autonegotiation to finish */
  567. for (time_out = 0; time_out < max_time_out; time_out++) {
  568. udelay(10);
  569. /* Restart PHY autonegotiation and wait for completion */
  570. status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
  571. MDIO_MMD_AN,
  572. &autoneg_reg);
  573. autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
  574. if (autoneg_reg == MDIO_AN_STAT1_COMPLETE)
  575. break;
  576. }
  577. if (time_out == max_time_out) {
  578. status = IXGBE_ERR_LINK_SETUP;
  579. hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out");
  580. }
  581. return status;
  582. }
  583. /**
  584. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  585. * @hw: pointer to hardware structure
  586. * @firmware_version: pointer to the PHY Firmware Version
  587. **/
  588. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  589. u16 *firmware_version)
  590. {
  591. s32 status = 0;
  592. status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
  593. MDIO_MMD_VEND1,
  594. firmware_version);
  595. return status;
  596. }
  597. /**
  598. * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
  599. * @hw: pointer to hardware structure
  600. * @firmware_version: pointer to the PHY Firmware Version
  601. **/
  602. s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
  603. u16 *firmware_version)
  604. {
  605. s32 status = 0;
  606. status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
  607. MDIO_MMD_VEND1,
  608. firmware_version);
  609. return status;
  610. }
  611. /**
  612. * ixgbe_reset_phy_nl - Performs a PHY reset
  613. * @hw: pointer to hardware structure
  614. **/
  615. s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  616. {
  617. u16 phy_offset, control, eword, edata, block_crc;
  618. bool end_data = false;
  619. u16 list_offset, data_offset;
  620. u16 phy_data = 0;
  621. s32 ret_val = 0;
  622. u32 i;
  623. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
  624. /* reset the PHY and poll for completion */
  625. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  626. (phy_data | MDIO_CTRL1_RESET));
  627. for (i = 0; i < 100; i++) {
  628. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  629. &phy_data);
  630. if ((phy_data & MDIO_CTRL1_RESET) == 0)
  631. break;
  632. usleep_range(10000, 20000);
  633. }
  634. if ((phy_data & MDIO_CTRL1_RESET) != 0) {
  635. hw_dbg(hw, "PHY reset did not complete.\n");
  636. ret_val = IXGBE_ERR_PHY;
  637. goto out;
  638. }
  639. /* Get init offsets */
  640. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  641. &data_offset);
  642. if (ret_val != 0)
  643. goto out;
  644. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  645. data_offset++;
  646. while (!end_data) {
  647. /*
  648. * Read control word from PHY init contents offset
  649. */
  650. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  651. control = (eword & IXGBE_CONTROL_MASK_NL) >>
  652. IXGBE_CONTROL_SHIFT_NL;
  653. edata = eword & IXGBE_DATA_MASK_NL;
  654. switch (control) {
  655. case IXGBE_DELAY_NL:
  656. data_offset++;
  657. hw_dbg(hw, "DELAY: %d MS\n", edata);
  658. usleep_range(edata * 1000, edata * 2000);
  659. break;
  660. case IXGBE_DATA_NL:
  661. hw_dbg(hw, "DATA:\n");
  662. data_offset++;
  663. hw->eeprom.ops.read(hw, data_offset++,
  664. &phy_offset);
  665. for (i = 0; i < edata; i++) {
  666. hw->eeprom.ops.read(hw, data_offset, &eword);
  667. hw->phy.ops.write_reg(hw, phy_offset,
  668. MDIO_MMD_PMAPMD, eword);
  669. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  670. phy_offset);
  671. data_offset++;
  672. phy_offset++;
  673. }
  674. break;
  675. case IXGBE_CONTROL_NL:
  676. data_offset++;
  677. hw_dbg(hw, "CONTROL:\n");
  678. if (edata == IXGBE_CONTROL_EOL_NL) {
  679. hw_dbg(hw, "EOL\n");
  680. end_data = true;
  681. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  682. hw_dbg(hw, "SOL\n");
  683. } else {
  684. hw_dbg(hw, "Bad control value\n");
  685. ret_val = IXGBE_ERR_PHY;
  686. goto out;
  687. }
  688. break;
  689. default:
  690. hw_dbg(hw, "Bad control type\n");
  691. ret_val = IXGBE_ERR_PHY;
  692. goto out;
  693. }
  694. }
  695. out:
  696. return ret_val;
  697. }
  698. /**
  699. * ixgbe_identify_sfp_module_generic - Identifies SFP modules
  700. * @hw: pointer to hardware structure
  701. *
  702. * Searches for and identifies the SFP module and assigns appropriate PHY type.
  703. **/
  704. s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  705. {
  706. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  707. u32 vendor_oui = 0;
  708. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  709. u8 identifier = 0;
  710. u8 comp_codes_1g = 0;
  711. u8 comp_codes_10g = 0;
  712. u8 oui_bytes[3] = {0, 0, 0};
  713. u8 cable_tech = 0;
  714. u8 cable_spec = 0;
  715. u16 enforce_sfp = 0;
  716. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
  717. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  718. status = IXGBE_ERR_SFP_NOT_PRESENT;
  719. goto out;
  720. }
  721. status = hw->phy.ops.read_i2c_eeprom(hw,
  722. IXGBE_SFF_IDENTIFIER,
  723. &identifier);
  724. if (status == IXGBE_ERR_SWFW_SYNC ||
  725. status == IXGBE_ERR_I2C ||
  726. status == IXGBE_ERR_SFP_NOT_PRESENT)
  727. goto err_read_i2c_eeprom;
  728. /* LAN ID is needed for sfp_type determination */
  729. hw->mac.ops.set_lan_id(hw);
  730. if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
  731. hw->phy.type = ixgbe_phy_sfp_unsupported;
  732. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  733. } else {
  734. status = hw->phy.ops.read_i2c_eeprom(hw,
  735. IXGBE_SFF_1GBE_COMP_CODES,
  736. &comp_codes_1g);
  737. if (status == IXGBE_ERR_SWFW_SYNC ||
  738. status == IXGBE_ERR_I2C ||
  739. status == IXGBE_ERR_SFP_NOT_PRESENT)
  740. goto err_read_i2c_eeprom;
  741. status = hw->phy.ops.read_i2c_eeprom(hw,
  742. IXGBE_SFF_10GBE_COMP_CODES,
  743. &comp_codes_10g);
  744. if (status == IXGBE_ERR_SWFW_SYNC ||
  745. status == IXGBE_ERR_I2C ||
  746. status == IXGBE_ERR_SFP_NOT_PRESENT)
  747. goto err_read_i2c_eeprom;
  748. status = hw->phy.ops.read_i2c_eeprom(hw,
  749. IXGBE_SFF_CABLE_TECHNOLOGY,
  750. &cable_tech);
  751. if (status == IXGBE_ERR_SWFW_SYNC ||
  752. status == IXGBE_ERR_I2C ||
  753. status == IXGBE_ERR_SFP_NOT_PRESENT)
  754. goto err_read_i2c_eeprom;
  755. /* ID Module
  756. * =========
  757. * 0 SFP_DA_CU
  758. * 1 SFP_SR
  759. * 2 SFP_LR
  760. * 3 SFP_DA_CORE0 - 82599-specific
  761. * 4 SFP_DA_CORE1 - 82599-specific
  762. * 5 SFP_SR/LR_CORE0 - 82599-specific
  763. * 6 SFP_SR/LR_CORE1 - 82599-specific
  764. * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
  765. * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
  766. * 9 SFP_1g_cu_CORE0 - 82599-specific
  767. * 10 SFP_1g_cu_CORE1 - 82599-specific
  768. */
  769. if (hw->mac.type == ixgbe_mac_82598EB) {
  770. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  771. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  772. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  773. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  774. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  775. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  776. else
  777. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  778. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  779. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
  780. if (hw->bus.lan_id == 0)
  781. hw->phy.sfp_type =
  782. ixgbe_sfp_type_da_cu_core0;
  783. else
  784. hw->phy.sfp_type =
  785. ixgbe_sfp_type_da_cu_core1;
  786. } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
  787. hw->phy.ops.read_i2c_eeprom(
  788. hw, IXGBE_SFF_CABLE_SPEC_COMP,
  789. &cable_spec);
  790. if (cable_spec &
  791. IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
  792. if (hw->bus.lan_id == 0)
  793. hw->phy.sfp_type =
  794. ixgbe_sfp_type_da_act_lmt_core0;
  795. else
  796. hw->phy.sfp_type =
  797. ixgbe_sfp_type_da_act_lmt_core1;
  798. } else {
  799. hw->phy.sfp_type =
  800. ixgbe_sfp_type_unknown;
  801. }
  802. } else if (comp_codes_10g &
  803. (IXGBE_SFF_10GBASESR_CAPABLE |
  804. IXGBE_SFF_10GBASELR_CAPABLE)) {
  805. if (hw->bus.lan_id == 0)
  806. hw->phy.sfp_type =
  807. ixgbe_sfp_type_srlr_core0;
  808. else
  809. hw->phy.sfp_type =
  810. ixgbe_sfp_type_srlr_core1;
  811. } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
  812. if (hw->bus.lan_id == 0)
  813. hw->phy.sfp_type =
  814. ixgbe_sfp_type_1g_cu_core0;
  815. else
  816. hw->phy.sfp_type =
  817. ixgbe_sfp_type_1g_cu_core1;
  818. } else {
  819. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  820. }
  821. }
  822. if (hw->phy.sfp_type != stored_sfp_type)
  823. hw->phy.sfp_setup_needed = true;
  824. /* Determine if the SFP+ PHY is dual speed or not. */
  825. hw->phy.multispeed_fiber = false;
  826. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  827. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  828. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  829. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  830. hw->phy.multispeed_fiber = true;
  831. /* Determine PHY vendor */
  832. if (hw->phy.type != ixgbe_phy_nl) {
  833. hw->phy.id = identifier;
  834. status = hw->phy.ops.read_i2c_eeprom(hw,
  835. IXGBE_SFF_VENDOR_OUI_BYTE0,
  836. &oui_bytes[0]);
  837. if (status == IXGBE_ERR_SWFW_SYNC ||
  838. status == IXGBE_ERR_I2C ||
  839. status == IXGBE_ERR_SFP_NOT_PRESENT)
  840. goto err_read_i2c_eeprom;
  841. status = hw->phy.ops.read_i2c_eeprom(hw,
  842. IXGBE_SFF_VENDOR_OUI_BYTE1,
  843. &oui_bytes[1]);
  844. if (status == IXGBE_ERR_SWFW_SYNC ||
  845. status == IXGBE_ERR_I2C ||
  846. status == IXGBE_ERR_SFP_NOT_PRESENT)
  847. goto err_read_i2c_eeprom;
  848. status = hw->phy.ops.read_i2c_eeprom(hw,
  849. IXGBE_SFF_VENDOR_OUI_BYTE2,
  850. &oui_bytes[2]);
  851. if (status == IXGBE_ERR_SWFW_SYNC ||
  852. status == IXGBE_ERR_I2C ||
  853. status == IXGBE_ERR_SFP_NOT_PRESENT)
  854. goto err_read_i2c_eeprom;
  855. vendor_oui =
  856. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  857. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  858. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  859. switch (vendor_oui) {
  860. case IXGBE_SFF_VENDOR_OUI_TYCO:
  861. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  862. hw->phy.type =
  863. ixgbe_phy_sfp_passive_tyco;
  864. break;
  865. case IXGBE_SFF_VENDOR_OUI_FTL:
  866. if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  867. hw->phy.type = ixgbe_phy_sfp_ftl_active;
  868. else
  869. hw->phy.type = ixgbe_phy_sfp_ftl;
  870. break;
  871. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  872. hw->phy.type = ixgbe_phy_sfp_avago;
  873. break;
  874. case IXGBE_SFF_VENDOR_OUI_INTEL:
  875. hw->phy.type = ixgbe_phy_sfp_intel;
  876. break;
  877. default:
  878. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  879. hw->phy.type =
  880. ixgbe_phy_sfp_passive_unknown;
  881. else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  882. hw->phy.type =
  883. ixgbe_phy_sfp_active_unknown;
  884. else
  885. hw->phy.type = ixgbe_phy_sfp_unknown;
  886. break;
  887. }
  888. }
  889. /* Allow any DA cable vendor */
  890. if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
  891. IXGBE_SFF_DA_ACTIVE_CABLE)) {
  892. status = 0;
  893. goto out;
  894. }
  895. /* Verify supported 1G SFP modules */
  896. if (comp_codes_10g == 0 &&
  897. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  898. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0)) {
  899. hw->phy.type = ixgbe_phy_sfp_unsupported;
  900. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  901. goto out;
  902. }
  903. /* Anything else 82598-based is supported */
  904. if (hw->mac.type == ixgbe_mac_82598EB) {
  905. status = 0;
  906. goto out;
  907. }
  908. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  909. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
  910. !((hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0) ||
  911. (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1))) {
  912. /* Make sure we're a supported PHY type */
  913. if (hw->phy.type == ixgbe_phy_sfp_intel) {
  914. status = 0;
  915. } else {
  916. hw_dbg(hw, "SFP+ module not supported\n");
  917. hw->phy.type = ixgbe_phy_sfp_unsupported;
  918. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  919. }
  920. } else {
  921. status = 0;
  922. }
  923. }
  924. out:
  925. return status;
  926. err_read_i2c_eeprom:
  927. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  928. if (hw->phy.type != ixgbe_phy_nl) {
  929. hw->phy.id = 0;
  930. hw->phy.type = ixgbe_phy_unknown;
  931. }
  932. return IXGBE_ERR_SFP_NOT_PRESENT;
  933. }
  934. /**
  935. * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
  936. * @hw: pointer to hardware structure
  937. * @list_offset: offset to the SFP ID list
  938. * @data_offset: offset to the SFP data block
  939. *
  940. * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
  941. * so it returns the offsets to the phy init sequence block.
  942. **/
  943. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  944. u16 *list_offset,
  945. u16 *data_offset)
  946. {
  947. u16 sfp_id;
  948. u16 sfp_type = hw->phy.sfp_type;
  949. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  950. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  951. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  952. return IXGBE_ERR_SFP_NOT_PRESENT;
  953. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  954. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  955. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  956. /*
  957. * Limiting active cables and 1G Phys must be initialized as
  958. * SR modules
  959. */
  960. if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
  961. sfp_type == ixgbe_sfp_type_1g_cu_core0)
  962. sfp_type = ixgbe_sfp_type_srlr_core0;
  963. else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
  964. sfp_type == ixgbe_sfp_type_1g_cu_core1)
  965. sfp_type = ixgbe_sfp_type_srlr_core1;
  966. /* Read offset to PHY init contents */
  967. hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
  968. if ((!*list_offset) || (*list_offset == 0xFFFF))
  969. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  970. /* Shift offset to first ID word */
  971. (*list_offset)++;
  972. /*
  973. * Find the matching SFP ID in the EEPROM
  974. * and program the init sequence
  975. */
  976. hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
  977. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  978. if (sfp_id == sfp_type) {
  979. (*list_offset)++;
  980. hw->eeprom.ops.read(hw, *list_offset, data_offset);
  981. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  982. hw_dbg(hw, "SFP+ module not supported\n");
  983. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  984. } else {
  985. break;
  986. }
  987. } else {
  988. (*list_offset) += 2;
  989. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  990. return IXGBE_ERR_PHY;
  991. }
  992. }
  993. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  994. hw_dbg(hw, "No matching SFP+ module found\n");
  995. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  996. }
  997. return 0;
  998. }
  999. /**
  1000. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  1001. * @hw: pointer to hardware structure
  1002. * @byte_offset: EEPROM byte offset to read
  1003. * @eeprom_data: value read
  1004. *
  1005. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  1006. **/
  1007. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1008. u8 *eeprom_data)
  1009. {
  1010. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1011. IXGBE_I2C_EEPROM_DEV_ADDR,
  1012. eeprom_data);
  1013. }
  1014. /**
  1015. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  1016. * @hw: pointer to hardware structure
  1017. * @byte_offset: EEPROM byte offset to write
  1018. * @eeprom_data: value to write
  1019. *
  1020. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  1021. **/
  1022. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1023. u8 eeprom_data)
  1024. {
  1025. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  1026. IXGBE_I2C_EEPROM_DEV_ADDR,
  1027. eeprom_data);
  1028. }
  1029. /**
  1030. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  1031. * @hw: pointer to hardware structure
  1032. * @byte_offset: byte offset to read
  1033. * @data: value read
  1034. *
  1035. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1036. * a specified deivce address.
  1037. **/
  1038. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1039. u8 dev_addr, u8 *data)
  1040. {
  1041. s32 status = 0;
  1042. u32 max_retry = 10;
  1043. u32 retry = 0;
  1044. u16 swfw_mask = 0;
  1045. bool nack = 1;
  1046. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1047. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1048. else
  1049. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1050. do {
  1051. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
  1052. status = IXGBE_ERR_SWFW_SYNC;
  1053. goto read_byte_out;
  1054. }
  1055. ixgbe_i2c_start(hw);
  1056. /* Device Address and write indication */
  1057. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1058. if (status != 0)
  1059. goto fail;
  1060. status = ixgbe_get_i2c_ack(hw);
  1061. if (status != 0)
  1062. goto fail;
  1063. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1064. if (status != 0)
  1065. goto fail;
  1066. status = ixgbe_get_i2c_ack(hw);
  1067. if (status != 0)
  1068. goto fail;
  1069. ixgbe_i2c_start(hw);
  1070. /* Device Address and read indication */
  1071. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  1072. if (status != 0)
  1073. goto fail;
  1074. status = ixgbe_get_i2c_ack(hw);
  1075. if (status != 0)
  1076. goto fail;
  1077. status = ixgbe_clock_in_i2c_byte(hw, data);
  1078. if (status != 0)
  1079. goto fail;
  1080. status = ixgbe_clock_out_i2c_bit(hw, nack);
  1081. if (status != 0)
  1082. goto fail;
  1083. ixgbe_i2c_stop(hw);
  1084. break;
  1085. fail:
  1086. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1087. msleep(100);
  1088. ixgbe_i2c_bus_clear(hw);
  1089. retry++;
  1090. if (retry < max_retry)
  1091. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  1092. else
  1093. hw_dbg(hw, "I2C byte read error.\n");
  1094. } while (retry < max_retry);
  1095. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1096. read_byte_out:
  1097. return status;
  1098. }
  1099. /**
  1100. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  1101. * @hw: pointer to hardware structure
  1102. * @byte_offset: byte offset to write
  1103. * @data: value to write
  1104. *
  1105. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  1106. * a specified device address.
  1107. **/
  1108. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1109. u8 dev_addr, u8 data)
  1110. {
  1111. s32 status = 0;
  1112. u32 max_retry = 1;
  1113. u32 retry = 0;
  1114. u16 swfw_mask = 0;
  1115. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1116. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1117. else
  1118. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1119. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
  1120. status = IXGBE_ERR_SWFW_SYNC;
  1121. goto write_byte_out;
  1122. }
  1123. do {
  1124. ixgbe_i2c_start(hw);
  1125. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1126. if (status != 0)
  1127. goto fail;
  1128. status = ixgbe_get_i2c_ack(hw);
  1129. if (status != 0)
  1130. goto fail;
  1131. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1132. if (status != 0)
  1133. goto fail;
  1134. status = ixgbe_get_i2c_ack(hw);
  1135. if (status != 0)
  1136. goto fail;
  1137. status = ixgbe_clock_out_i2c_byte(hw, data);
  1138. if (status != 0)
  1139. goto fail;
  1140. status = ixgbe_get_i2c_ack(hw);
  1141. if (status != 0)
  1142. goto fail;
  1143. ixgbe_i2c_stop(hw);
  1144. break;
  1145. fail:
  1146. ixgbe_i2c_bus_clear(hw);
  1147. retry++;
  1148. if (retry < max_retry)
  1149. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  1150. else
  1151. hw_dbg(hw, "I2C byte write error.\n");
  1152. } while (retry < max_retry);
  1153. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1154. write_byte_out:
  1155. return status;
  1156. }
  1157. /**
  1158. * ixgbe_i2c_start - Sets I2C start condition
  1159. * @hw: pointer to hardware structure
  1160. *
  1161. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  1162. **/
  1163. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  1164. {
  1165. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1166. /* Start condition must begin with data and clock high */
  1167. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1168. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1169. /* Setup time for start condition (4.7us) */
  1170. udelay(IXGBE_I2C_T_SU_STA);
  1171. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1172. /* Hold time for start condition (4us) */
  1173. udelay(IXGBE_I2C_T_HD_STA);
  1174. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1175. /* Minimum low period of clock is 4.7 us */
  1176. udelay(IXGBE_I2C_T_LOW);
  1177. }
  1178. /**
  1179. * ixgbe_i2c_stop - Sets I2C stop condition
  1180. * @hw: pointer to hardware structure
  1181. *
  1182. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  1183. **/
  1184. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  1185. {
  1186. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1187. /* Stop condition must begin with data low and clock high */
  1188. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1189. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1190. /* Setup time for stop condition (4us) */
  1191. udelay(IXGBE_I2C_T_SU_STO);
  1192. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1193. /* bus free time between stop and start (4.7us)*/
  1194. udelay(IXGBE_I2C_T_BUF);
  1195. }
  1196. /**
  1197. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  1198. * @hw: pointer to hardware structure
  1199. * @data: data byte to clock in
  1200. *
  1201. * Clocks in one byte data via I2C data/clock
  1202. **/
  1203. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  1204. {
  1205. s32 status = 0;
  1206. s32 i;
  1207. bool bit = 0;
  1208. for (i = 7; i >= 0; i--) {
  1209. status = ixgbe_clock_in_i2c_bit(hw, &bit);
  1210. *data |= bit << i;
  1211. if (status != 0)
  1212. break;
  1213. }
  1214. return status;
  1215. }
  1216. /**
  1217. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  1218. * @hw: pointer to hardware structure
  1219. * @data: data byte clocked out
  1220. *
  1221. * Clocks out one byte data via I2C data/clock
  1222. **/
  1223. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  1224. {
  1225. s32 status = 0;
  1226. s32 i;
  1227. u32 i2cctl;
  1228. bool bit = 0;
  1229. for (i = 7; i >= 0; i--) {
  1230. bit = (data >> i) & 0x1;
  1231. status = ixgbe_clock_out_i2c_bit(hw, bit);
  1232. if (status != 0)
  1233. break;
  1234. }
  1235. /* Release SDA line (set high) */
  1236. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1237. i2cctl |= IXGBE_I2C_DATA_OUT;
  1238. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  1239. return status;
  1240. }
  1241. /**
  1242. * ixgbe_get_i2c_ack - Polls for I2C ACK
  1243. * @hw: pointer to hardware structure
  1244. *
  1245. * Clocks in/out one bit via I2C data/clock
  1246. **/
  1247. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  1248. {
  1249. s32 status;
  1250. u32 i = 0;
  1251. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1252. u32 timeout = 10;
  1253. bool ack = 1;
  1254. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  1255. if (status != 0)
  1256. goto out;
  1257. /* Minimum high period of clock is 4us */
  1258. udelay(IXGBE_I2C_T_HIGH);
  1259. /* Poll for ACK. Note that ACK in I2C spec is
  1260. * transition from 1 to 0 */
  1261. for (i = 0; i < timeout; i++) {
  1262. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1263. ack = ixgbe_get_i2c_data(&i2cctl);
  1264. udelay(1);
  1265. if (ack == 0)
  1266. break;
  1267. }
  1268. if (ack == 1) {
  1269. hw_dbg(hw, "I2C ack was not received.\n");
  1270. status = IXGBE_ERR_I2C;
  1271. }
  1272. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1273. /* Minimum low period of clock is 4.7 us */
  1274. udelay(IXGBE_I2C_T_LOW);
  1275. out:
  1276. return status;
  1277. }
  1278. /**
  1279. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  1280. * @hw: pointer to hardware structure
  1281. * @data: read data value
  1282. *
  1283. * Clocks in one bit via I2C data/clock
  1284. **/
  1285. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  1286. {
  1287. s32 status;
  1288. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1289. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  1290. /* Minimum high period of clock is 4us */
  1291. udelay(IXGBE_I2C_T_HIGH);
  1292. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1293. *data = ixgbe_get_i2c_data(&i2cctl);
  1294. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1295. /* Minimum low period of clock is 4.7 us */
  1296. udelay(IXGBE_I2C_T_LOW);
  1297. return status;
  1298. }
  1299. /**
  1300. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  1301. * @hw: pointer to hardware structure
  1302. * @data: data value to write
  1303. *
  1304. * Clocks out one bit via I2C data/clock
  1305. **/
  1306. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  1307. {
  1308. s32 status;
  1309. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1310. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  1311. if (status == 0) {
  1312. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  1313. /* Minimum high period of clock is 4us */
  1314. udelay(IXGBE_I2C_T_HIGH);
  1315. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1316. /* Minimum low period of clock is 4.7 us.
  1317. * This also takes care of the data hold time.
  1318. */
  1319. udelay(IXGBE_I2C_T_LOW);
  1320. } else {
  1321. status = IXGBE_ERR_I2C;
  1322. hw_dbg(hw, "I2C data was not set to %X\n", data);
  1323. }
  1324. return status;
  1325. }
  1326. /**
  1327. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  1328. * @hw: pointer to hardware structure
  1329. * @i2cctl: Current value of I2CCTL register
  1330. *
  1331. * Raises the I2C clock line '0'->'1'
  1332. **/
  1333. static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1334. {
  1335. s32 status = 0;
  1336. *i2cctl |= IXGBE_I2C_CLK_OUT;
  1337. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1338. /* SCL rise time (1000ns) */
  1339. udelay(IXGBE_I2C_T_RISE);
  1340. return status;
  1341. }
  1342. /**
  1343. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  1344. * @hw: pointer to hardware structure
  1345. * @i2cctl: Current value of I2CCTL register
  1346. *
  1347. * Lowers the I2C clock line '1'->'0'
  1348. **/
  1349. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1350. {
  1351. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  1352. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1353. /* SCL fall time (300ns) */
  1354. udelay(IXGBE_I2C_T_FALL);
  1355. }
  1356. /**
  1357. * ixgbe_set_i2c_data - Sets the I2C data bit
  1358. * @hw: pointer to hardware structure
  1359. * @i2cctl: Current value of I2CCTL register
  1360. * @data: I2C data value (0 or 1) to set
  1361. *
  1362. * Sets the I2C data bit
  1363. **/
  1364. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  1365. {
  1366. s32 status = 0;
  1367. if (data)
  1368. *i2cctl |= IXGBE_I2C_DATA_OUT;
  1369. else
  1370. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  1371. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1372. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  1373. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  1374. /* Verify data was set correctly */
  1375. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1376. if (data != ixgbe_get_i2c_data(i2cctl)) {
  1377. status = IXGBE_ERR_I2C;
  1378. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  1379. }
  1380. return status;
  1381. }
  1382. /**
  1383. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1384. * @hw: pointer to hardware structure
  1385. * @i2cctl: Current value of I2CCTL register
  1386. *
  1387. * Returns the I2C data bit value
  1388. **/
  1389. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1390. {
  1391. bool data;
  1392. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1393. data = 1;
  1394. else
  1395. data = 0;
  1396. return data;
  1397. }
  1398. /**
  1399. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1400. * @hw: pointer to hardware structure
  1401. *
  1402. * Clears the I2C bus by sending nine clock pulses.
  1403. * Used when data line is stuck low.
  1404. **/
  1405. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1406. {
  1407. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1408. u32 i;
  1409. ixgbe_i2c_start(hw);
  1410. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1411. for (i = 0; i < 9; i++) {
  1412. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1413. /* Min high period of clock is 4us */
  1414. udelay(IXGBE_I2C_T_HIGH);
  1415. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1416. /* Min low period of clock is 4.7us*/
  1417. udelay(IXGBE_I2C_T_LOW);
  1418. }
  1419. ixgbe_i2c_start(hw);
  1420. /* Put the i2c bus back to default state */
  1421. ixgbe_i2c_stop(hw);
  1422. }
  1423. /**
  1424. * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
  1425. * @hw: pointer to hardware structure
  1426. *
  1427. * Checks if the LASI temp alarm status was triggered due to overtemp
  1428. **/
  1429. s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
  1430. {
  1431. s32 status = 0;
  1432. u16 phy_data = 0;
  1433. if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
  1434. goto out;
  1435. /* Check that the LASI temp alarm status was triggered */
  1436. hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
  1437. MDIO_MMD_PMAPMD, &phy_data);
  1438. if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
  1439. goto out;
  1440. status = IXGBE_ERR_OVERTEMP;
  1441. out:
  1442. return status;
  1443. }