ixgbe_phy.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 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 void 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. **/
  415. s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  416. ixgbe_link_speed speed,
  417. bool autoneg_wait_to_complete)
  418. {
  419. /*
  420. * Clear autoneg_advertised and set new values based on input link
  421. * speed.
  422. */
  423. hw->phy.autoneg_advertised = 0;
  424. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  425. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  426. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  427. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  428. if (speed & IXGBE_LINK_SPEED_100_FULL)
  429. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  430. /* Setup link based on the new speed settings */
  431. hw->phy.ops.setup_link(hw);
  432. return 0;
  433. }
  434. /**
  435. * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
  436. * @hw: pointer to hardware structure
  437. * @speed: pointer to link speed
  438. * @autoneg: boolean auto-negotiation value
  439. *
  440. * Determines the link capabilities by reading the AUTOC register.
  441. */
  442. s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
  443. ixgbe_link_speed *speed,
  444. bool *autoneg)
  445. {
  446. s32 status = IXGBE_ERR_LINK_SETUP;
  447. u16 speed_ability;
  448. *speed = 0;
  449. *autoneg = true;
  450. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  451. &speed_ability);
  452. if (status == 0) {
  453. if (speed_ability & MDIO_SPEED_10G)
  454. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  455. if (speed_ability & MDIO_PMA_SPEED_1000)
  456. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  457. if (speed_ability & MDIO_PMA_SPEED_100)
  458. *speed |= IXGBE_LINK_SPEED_100_FULL;
  459. }
  460. return status;
  461. }
  462. /**
  463. * ixgbe_check_phy_link_tnx - Determine link and speed status
  464. * @hw: pointer to hardware structure
  465. *
  466. * Reads the VS1 register to determine if link is up and the current speed for
  467. * the PHY.
  468. **/
  469. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  470. bool *link_up)
  471. {
  472. s32 status = 0;
  473. u32 time_out;
  474. u32 max_time_out = 10;
  475. u16 phy_link = 0;
  476. u16 phy_speed = 0;
  477. u16 phy_data = 0;
  478. /* Initialize speed and link to default case */
  479. *link_up = false;
  480. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  481. /*
  482. * Check current speed and link status of the PHY register.
  483. * This is a vendor specific register and may have to
  484. * be changed for other copper PHYs.
  485. */
  486. for (time_out = 0; time_out < max_time_out; time_out++) {
  487. udelay(10);
  488. status = hw->phy.ops.read_reg(hw,
  489. MDIO_STAT1,
  490. MDIO_MMD_VEND1,
  491. &phy_data);
  492. phy_link = phy_data &
  493. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  494. phy_speed = phy_data &
  495. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  496. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  497. *link_up = true;
  498. if (phy_speed ==
  499. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  500. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  501. break;
  502. }
  503. }
  504. return status;
  505. }
  506. /**
  507. * ixgbe_setup_phy_link_tnx - Set and restart autoneg
  508. * @hw: pointer to hardware structure
  509. *
  510. * Restart autonegotiation and PHY and waits for completion.
  511. **/
  512. s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
  513. {
  514. s32 status = 0;
  515. u32 time_out;
  516. u32 max_time_out = 10;
  517. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  518. bool autoneg = false;
  519. ixgbe_link_speed speed;
  520. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  521. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  522. /* Set or unset auto-negotiation 10G advertisement */
  523. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  524. MDIO_MMD_AN,
  525. &autoneg_reg);
  526. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  527. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  528. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  529. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  530. MDIO_MMD_AN,
  531. autoneg_reg);
  532. }
  533. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  534. /* Set or unset auto-negotiation 1G advertisement */
  535. hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  536. MDIO_MMD_AN,
  537. &autoneg_reg);
  538. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  539. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  540. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  541. hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  542. MDIO_MMD_AN,
  543. autoneg_reg);
  544. }
  545. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  546. /* Set or unset auto-negotiation 100M advertisement */
  547. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  548. MDIO_MMD_AN,
  549. &autoneg_reg);
  550. autoneg_reg &= ~(ADVERTISE_100FULL |
  551. ADVERTISE_100HALF);
  552. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  553. autoneg_reg |= ADVERTISE_100FULL;
  554. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  555. MDIO_MMD_AN,
  556. autoneg_reg);
  557. }
  558. /* Restart PHY autonegotiation and wait for completion */
  559. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  560. MDIO_MMD_AN, &autoneg_reg);
  561. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  562. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  563. MDIO_MMD_AN, autoneg_reg);
  564. /* Wait for autonegotiation to finish */
  565. for (time_out = 0; time_out < max_time_out; time_out++) {
  566. udelay(10);
  567. /* Restart PHY autonegotiation and wait for completion */
  568. status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
  569. MDIO_MMD_AN,
  570. &autoneg_reg);
  571. autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
  572. if (autoneg_reg == MDIO_AN_STAT1_COMPLETE)
  573. break;
  574. }
  575. if (time_out == max_time_out) {
  576. status = IXGBE_ERR_LINK_SETUP;
  577. hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out");
  578. }
  579. return status;
  580. }
  581. /**
  582. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  583. * @hw: pointer to hardware structure
  584. * @firmware_version: pointer to the PHY Firmware Version
  585. **/
  586. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  587. u16 *firmware_version)
  588. {
  589. s32 status = 0;
  590. status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
  591. MDIO_MMD_VEND1,
  592. firmware_version);
  593. return status;
  594. }
  595. /**
  596. * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
  597. * @hw: pointer to hardware structure
  598. * @firmware_version: pointer to the PHY Firmware Version
  599. **/
  600. s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
  601. u16 *firmware_version)
  602. {
  603. s32 status = 0;
  604. status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
  605. MDIO_MMD_VEND1,
  606. firmware_version);
  607. return status;
  608. }
  609. /**
  610. * ixgbe_reset_phy_nl - Performs a PHY reset
  611. * @hw: pointer to hardware structure
  612. **/
  613. s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  614. {
  615. u16 phy_offset, control, eword, edata, block_crc;
  616. bool end_data = false;
  617. u16 list_offset, data_offset;
  618. u16 phy_data = 0;
  619. s32 ret_val = 0;
  620. u32 i;
  621. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
  622. /* reset the PHY and poll for completion */
  623. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  624. (phy_data | MDIO_CTRL1_RESET));
  625. for (i = 0; i < 100; i++) {
  626. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  627. &phy_data);
  628. if ((phy_data & MDIO_CTRL1_RESET) == 0)
  629. break;
  630. usleep_range(10000, 20000);
  631. }
  632. if ((phy_data & MDIO_CTRL1_RESET) != 0) {
  633. hw_dbg(hw, "PHY reset did not complete.\n");
  634. ret_val = IXGBE_ERR_PHY;
  635. goto out;
  636. }
  637. /* Get init offsets */
  638. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  639. &data_offset);
  640. if (ret_val != 0)
  641. goto out;
  642. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  643. data_offset++;
  644. while (!end_data) {
  645. /*
  646. * Read control word from PHY init contents offset
  647. */
  648. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  649. control = (eword & IXGBE_CONTROL_MASK_NL) >>
  650. IXGBE_CONTROL_SHIFT_NL;
  651. edata = eword & IXGBE_DATA_MASK_NL;
  652. switch (control) {
  653. case IXGBE_DELAY_NL:
  654. data_offset++;
  655. hw_dbg(hw, "DELAY: %d MS\n", edata);
  656. usleep_range(edata * 1000, edata * 2000);
  657. break;
  658. case IXGBE_DATA_NL:
  659. hw_dbg(hw, "DATA:\n");
  660. data_offset++;
  661. hw->eeprom.ops.read(hw, data_offset++,
  662. &phy_offset);
  663. for (i = 0; i < edata; i++) {
  664. hw->eeprom.ops.read(hw, data_offset, &eword);
  665. hw->phy.ops.write_reg(hw, phy_offset,
  666. MDIO_MMD_PMAPMD, eword);
  667. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  668. phy_offset);
  669. data_offset++;
  670. phy_offset++;
  671. }
  672. break;
  673. case IXGBE_CONTROL_NL:
  674. data_offset++;
  675. hw_dbg(hw, "CONTROL:\n");
  676. if (edata == IXGBE_CONTROL_EOL_NL) {
  677. hw_dbg(hw, "EOL\n");
  678. end_data = true;
  679. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  680. hw_dbg(hw, "SOL\n");
  681. } else {
  682. hw_dbg(hw, "Bad control value\n");
  683. ret_val = IXGBE_ERR_PHY;
  684. goto out;
  685. }
  686. break;
  687. default:
  688. hw_dbg(hw, "Bad control type\n");
  689. ret_val = IXGBE_ERR_PHY;
  690. goto out;
  691. }
  692. }
  693. out:
  694. return ret_val;
  695. }
  696. /**
  697. * ixgbe_identify_sfp_module_generic - Identifies SFP modules
  698. * @hw: pointer to hardware structure
  699. *
  700. * Searches for and identifies the SFP module and assigns appropriate PHY type.
  701. **/
  702. s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  703. {
  704. struct ixgbe_adapter *adapter = hw->back;
  705. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  706. u32 vendor_oui = 0;
  707. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  708. u8 identifier = 0;
  709. u8 comp_codes_1g = 0;
  710. u8 comp_codes_10g = 0;
  711. u8 oui_bytes[3] = {0, 0, 0};
  712. u8 cable_tech = 0;
  713. u8 cable_spec = 0;
  714. u16 enforce_sfp = 0;
  715. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
  716. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  717. status = IXGBE_ERR_SFP_NOT_PRESENT;
  718. goto out;
  719. }
  720. status = hw->phy.ops.read_i2c_eeprom(hw,
  721. IXGBE_SFF_IDENTIFIER,
  722. &identifier);
  723. if (status != 0)
  724. goto err_read_i2c_eeprom;
  725. /* LAN ID is needed for sfp_type determination */
  726. hw->mac.ops.set_lan_id(hw);
  727. if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
  728. hw->phy.type = ixgbe_phy_sfp_unsupported;
  729. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  730. } else {
  731. status = hw->phy.ops.read_i2c_eeprom(hw,
  732. IXGBE_SFF_1GBE_COMP_CODES,
  733. &comp_codes_1g);
  734. if (status != 0)
  735. goto err_read_i2c_eeprom;
  736. status = hw->phy.ops.read_i2c_eeprom(hw,
  737. IXGBE_SFF_10GBE_COMP_CODES,
  738. &comp_codes_10g);
  739. if (status != 0)
  740. goto err_read_i2c_eeprom;
  741. status = hw->phy.ops.read_i2c_eeprom(hw,
  742. IXGBE_SFF_CABLE_TECHNOLOGY,
  743. &cable_tech);
  744. if (status != 0)
  745. goto err_read_i2c_eeprom;
  746. /* ID Module
  747. * =========
  748. * 0 SFP_DA_CU
  749. * 1 SFP_SR
  750. * 2 SFP_LR
  751. * 3 SFP_DA_CORE0 - 82599-specific
  752. * 4 SFP_DA_CORE1 - 82599-specific
  753. * 5 SFP_SR/LR_CORE0 - 82599-specific
  754. * 6 SFP_SR/LR_CORE1 - 82599-specific
  755. * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
  756. * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
  757. * 9 SFP_1g_cu_CORE0 - 82599-specific
  758. * 10 SFP_1g_cu_CORE1 - 82599-specific
  759. * 11 SFP_1g_sx_CORE0 - 82599-specific
  760. * 12 SFP_1g_sx_CORE1 - 82599-specific
  761. */
  762. if (hw->mac.type == ixgbe_mac_82598EB) {
  763. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  764. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  765. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  766. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  767. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  768. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  769. else
  770. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  771. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  772. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
  773. if (hw->bus.lan_id == 0)
  774. hw->phy.sfp_type =
  775. ixgbe_sfp_type_da_cu_core0;
  776. else
  777. hw->phy.sfp_type =
  778. ixgbe_sfp_type_da_cu_core1;
  779. } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
  780. hw->phy.ops.read_i2c_eeprom(
  781. hw, IXGBE_SFF_CABLE_SPEC_COMP,
  782. &cable_spec);
  783. if (cable_spec &
  784. IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
  785. if (hw->bus.lan_id == 0)
  786. hw->phy.sfp_type =
  787. ixgbe_sfp_type_da_act_lmt_core0;
  788. else
  789. hw->phy.sfp_type =
  790. ixgbe_sfp_type_da_act_lmt_core1;
  791. } else {
  792. hw->phy.sfp_type =
  793. ixgbe_sfp_type_unknown;
  794. }
  795. } else if (comp_codes_10g &
  796. (IXGBE_SFF_10GBASESR_CAPABLE |
  797. IXGBE_SFF_10GBASELR_CAPABLE)) {
  798. if (hw->bus.lan_id == 0)
  799. hw->phy.sfp_type =
  800. ixgbe_sfp_type_srlr_core0;
  801. else
  802. hw->phy.sfp_type =
  803. ixgbe_sfp_type_srlr_core1;
  804. } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
  805. if (hw->bus.lan_id == 0)
  806. hw->phy.sfp_type =
  807. ixgbe_sfp_type_1g_cu_core0;
  808. else
  809. hw->phy.sfp_type =
  810. ixgbe_sfp_type_1g_cu_core1;
  811. } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
  812. if (hw->bus.lan_id == 0)
  813. hw->phy.sfp_type =
  814. ixgbe_sfp_type_1g_sx_core0;
  815. else
  816. hw->phy.sfp_type =
  817. ixgbe_sfp_type_1g_sx_core1;
  818. } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
  819. if (hw->bus.lan_id == 0)
  820. hw->phy.sfp_type =
  821. ixgbe_sfp_type_1g_lx_core0;
  822. else
  823. hw->phy.sfp_type =
  824. ixgbe_sfp_type_1g_lx_core1;
  825. } else {
  826. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  827. }
  828. }
  829. if (hw->phy.sfp_type != stored_sfp_type)
  830. hw->phy.sfp_setup_needed = true;
  831. /* Determine if the SFP+ PHY is dual speed or not. */
  832. hw->phy.multispeed_fiber = false;
  833. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  834. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  835. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  836. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  837. hw->phy.multispeed_fiber = true;
  838. /* Determine PHY vendor */
  839. if (hw->phy.type != ixgbe_phy_nl) {
  840. hw->phy.id = identifier;
  841. status = hw->phy.ops.read_i2c_eeprom(hw,
  842. IXGBE_SFF_VENDOR_OUI_BYTE0,
  843. &oui_bytes[0]);
  844. if (status != 0)
  845. goto err_read_i2c_eeprom;
  846. status = hw->phy.ops.read_i2c_eeprom(hw,
  847. IXGBE_SFF_VENDOR_OUI_BYTE1,
  848. &oui_bytes[1]);
  849. if (status != 0)
  850. goto err_read_i2c_eeprom;
  851. status = hw->phy.ops.read_i2c_eeprom(hw,
  852. IXGBE_SFF_VENDOR_OUI_BYTE2,
  853. &oui_bytes[2]);
  854. if (status != 0)
  855. goto err_read_i2c_eeprom;
  856. vendor_oui =
  857. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  858. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  859. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  860. switch (vendor_oui) {
  861. case IXGBE_SFF_VENDOR_OUI_TYCO:
  862. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  863. hw->phy.type =
  864. ixgbe_phy_sfp_passive_tyco;
  865. break;
  866. case IXGBE_SFF_VENDOR_OUI_FTL:
  867. if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  868. hw->phy.type = ixgbe_phy_sfp_ftl_active;
  869. else
  870. hw->phy.type = ixgbe_phy_sfp_ftl;
  871. break;
  872. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  873. hw->phy.type = ixgbe_phy_sfp_avago;
  874. break;
  875. case IXGBE_SFF_VENDOR_OUI_INTEL:
  876. hw->phy.type = ixgbe_phy_sfp_intel;
  877. break;
  878. default:
  879. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  880. hw->phy.type =
  881. ixgbe_phy_sfp_passive_unknown;
  882. else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  883. hw->phy.type =
  884. ixgbe_phy_sfp_active_unknown;
  885. else
  886. hw->phy.type = ixgbe_phy_sfp_unknown;
  887. break;
  888. }
  889. }
  890. /* Allow any DA cable vendor */
  891. if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
  892. IXGBE_SFF_DA_ACTIVE_CABLE)) {
  893. status = 0;
  894. goto out;
  895. }
  896. /* Verify supported 1G SFP modules */
  897. if (comp_codes_10g == 0 &&
  898. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  899. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  900. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  901. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  902. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  903. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
  904. hw->phy.type = ixgbe_phy_sfp_unsupported;
  905. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  906. goto out;
  907. }
  908. /* Anything else 82598-based is supported */
  909. if (hw->mac.type == ixgbe_mac_82598EB) {
  910. status = 0;
  911. goto out;
  912. }
  913. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  914. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
  915. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  916. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  917. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  918. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  919. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  920. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
  921. /* Make sure we're a supported PHY type */
  922. if (hw->phy.type == ixgbe_phy_sfp_intel) {
  923. status = 0;
  924. } else {
  925. if (hw->allow_unsupported_sfp) {
  926. e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.");
  927. status = 0;
  928. } else {
  929. hw_dbg(hw,
  930. "SFP+ module not supported\n");
  931. hw->phy.type =
  932. ixgbe_phy_sfp_unsupported;
  933. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  934. }
  935. }
  936. } else {
  937. status = 0;
  938. }
  939. }
  940. out:
  941. return status;
  942. err_read_i2c_eeprom:
  943. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  944. if (hw->phy.type != ixgbe_phy_nl) {
  945. hw->phy.id = 0;
  946. hw->phy.type = ixgbe_phy_unknown;
  947. }
  948. return IXGBE_ERR_SFP_NOT_PRESENT;
  949. }
  950. /**
  951. * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
  952. * @hw: pointer to hardware structure
  953. * @list_offset: offset to the SFP ID list
  954. * @data_offset: offset to the SFP data block
  955. *
  956. * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
  957. * so it returns the offsets to the phy init sequence block.
  958. **/
  959. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  960. u16 *list_offset,
  961. u16 *data_offset)
  962. {
  963. u16 sfp_id;
  964. u16 sfp_type = hw->phy.sfp_type;
  965. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  966. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  967. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  968. return IXGBE_ERR_SFP_NOT_PRESENT;
  969. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  970. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  971. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  972. /*
  973. * Limiting active cables and 1G Phys must be initialized as
  974. * SR modules
  975. */
  976. if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
  977. sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  978. sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  979. sfp_type == ixgbe_sfp_type_1g_sx_core0)
  980. sfp_type = ixgbe_sfp_type_srlr_core0;
  981. else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
  982. sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  983. sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  984. sfp_type == ixgbe_sfp_type_1g_sx_core1)
  985. sfp_type = ixgbe_sfp_type_srlr_core1;
  986. /* Read offset to PHY init contents */
  987. hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
  988. if ((!*list_offset) || (*list_offset == 0xFFFF))
  989. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  990. /* Shift offset to first ID word */
  991. (*list_offset)++;
  992. /*
  993. * Find the matching SFP ID in the EEPROM
  994. * and program the init sequence
  995. */
  996. hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
  997. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  998. if (sfp_id == sfp_type) {
  999. (*list_offset)++;
  1000. hw->eeprom.ops.read(hw, *list_offset, data_offset);
  1001. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  1002. hw_dbg(hw, "SFP+ module not supported\n");
  1003. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1004. } else {
  1005. break;
  1006. }
  1007. } else {
  1008. (*list_offset) += 2;
  1009. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1010. return IXGBE_ERR_PHY;
  1011. }
  1012. }
  1013. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  1014. hw_dbg(hw, "No matching SFP+ module found\n");
  1015. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1016. }
  1017. return 0;
  1018. }
  1019. /**
  1020. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  1021. * @hw: pointer to hardware structure
  1022. * @byte_offset: EEPROM byte offset to read
  1023. * @eeprom_data: value read
  1024. *
  1025. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  1026. **/
  1027. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1028. u8 *eeprom_data)
  1029. {
  1030. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1031. IXGBE_I2C_EEPROM_DEV_ADDR,
  1032. eeprom_data);
  1033. }
  1034. /**
  1035. * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
  1036. * @hw: pointer to hardware structure
  1037. * @byte_offset: byte offset at address 0xA2
  1038. * @eeprom_data: value read
  1039. *
  1040. * Performs byte read operation to SFP module's SFF-8472 data over I2C
  1041. **/
  1042. s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1043. u8 *sff8472_data)
  1044. {
  1045. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1046. IXGBE_I2C_EEPROM_DEV_ADDR2,
  1047. sff8472_data);
  1048. }
  1049. /**
  1050. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  1051. * @hw: pointer to hardware structure
  1052. * @byte_offset: EEPROM byte offset to write
  1053. * @eeprom_data: value to write
  1054. *
  1055. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  1056. **/
  1057. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1058. u8 eeprom_data)
  1059. {
  1060. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  1061. IXGBE_I2C_EEPROM_DEV_ADDR,
  1062. eeprom_data);
  1063. }
  1064. /**
  1065. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  1066. * @hw: pointer to hardware structure
  1067. * @byte_offset: byte offset to read
  1068. * @data: value read
  1069. *
  1070. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1071. * a specified device address.
  1072. **/
  1073. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1074. u8 dev_addr, u8 *data)
  1075. {
  1076. s32 status = 0;
  1077. u32 max_retry = 10;
  1078. u32 retry = 0;
  1079. u16 swfw_mask = 0;
  1080. bool nack = true;
  1081. *data = 0;
  1082. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1083. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1084. else
  1085. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1086. do {
  1087. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
  1088. status = IXGBE_ERR_SWFW_SYNC;
  1089. goto read_byte_out;
  1090. }
  1091. ixgbe_i2c_start(hw);
  1092. /* Device Address and write indication */
  1093. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1094. if (status != 0)
  1095. goto fail;
  1096. status = ixgbe_get_i2c_ack(hw);
  1097. if (status != 0)
  1098. goto fail;
  1099. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1100. if (status != 0)
  1101. goto fail;
  1102. status = ixgbe_get_i2c_ack(hw);
  1103. if (status != 0)
  1104. goto fail;
  1105. ixgbe_i2c_start(hw);
  1106. /* Device Address and read indication */
  1107. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  1108. if (status != 0)
  1109. goto fail;
  1110. status = ixgbe_get_i2c_ack(hw);
  1111. if (status != 0)
  1112. goto fail;
  1113. status = ixgbe_clock_in_i2c_byte(hw, data);
  1114. if (status != 0)
  1115. goto fail;
  1116. status = ixgbe_clock_out_i2c_bit(hw, nack);
  1117. if (status != 0)
  1118. goto fail;
  1119. ixgbe_i2c_stop(hw);
  1120. break;
  1121. fail:
  1122. ixgbe_i2c_bus_clear(hw);
  1123. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1124. msleep(100);
  1125. retry++;
  1126. if (retry < max_retry)
  1127. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  1128. else
  1129. hw_dbg(hw, "I2C byte read error.\n");
  1130. } while (retry < max_retry);
  1131. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1132. read_byte_out:
  1133. return status;
  1134. }
  1135. /**
  1136. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  1137. * @hw: pointer to hardware structure
  1138. * @byte_offset: byte offset to write
  1139. * @data: value to write
  1140. *
  1141. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  1142. * a specified device address.
  1143. **/
  1144. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1145. u8 dev_addr, u8 data)
  1146. {
  1147. s32 status = 0;
  1148. u32 max_retry = 1;
  1149. u32 retry = 0;
  1150. u16 swfw_mask = 0;
  1151. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1152. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1153. else
  1154. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1155. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
  1156. status = IXGBE_ERR_SWFW_SYNC;
  1157. goto write_byte_out;
  1158. }
  1159. do {
  1160. ixgbe_i2c_start(hw);
  1161. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1162. if (status != 0)
  1163. goto fail;
  1164. status = ixgbe_get_i2c_ack(hw);
  1165. if (status != 0)
  1166. goto fail;
  1167. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1168. if (status != 0)
  1169. goto fail;
  1170. status = ixgbe_get_i2c_ack(hw);
  1171. if (status != 0)
  1172. goto fail;
  1173. status = ixgbe_clock_out_i2c_byte(hw, data);
  1174. if (status != 0)
  1175. goto fail;
  1176. status = ixgbe_get_i2c_ack(hw);
  1177. if (status != 0)
  1178. goto fail;
  1179. ixgbe_i2c_stop(hw);
  1180. break;
  1181. fail:
  1182. ixgbe_i2c_bus_clear(hw);
  1183. retry++;
  1184. if (retry < max_retry)
  1185. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  1186. else
  1187. hw_dbg(hw, "I2C byte write error.\n");
  1188. } while (retry < max_retry);
  1189. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1190. write_byte_out:
  1191. return status;
  1192. }
  1193. /**
  1194. * ixgbe_i2c_start - Sets I2C start condition
  1195. * @hw: pointer to hardware structure
  1196. *
  1197. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  1198. **/
  1199. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  1200. {
  1201. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1202. /* Start condition must begin with data and clock high */
  1203. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1204. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1205. /* Setup time for start condition (4.7us) */
  1206. udelay(IXGBE_I2C_T_SU_STA);
  1207. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1208. /* Hold time for start condition (4us) */
  1209. udelay(IXGBE_I2C_T_HD_STA);
  1210. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1211. /* Minimum low period of clock is 4.7 us */
  1212. udelay(IXGBE_I2C_T_LOW);
  1213. }
  1214. /**
  1215. * ixgbe_i2c_stop - Sets I2C stop condition
  1216. * @hw: pointer to hardware structure
  1217. *
  1218. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  1219. **/
  1220. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  1221. {
  1222. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1223. /* Stop condition must begin with data low and clock high */
  1224. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1225. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1226. /* Setup time for stop condition (4us) */
  1227. udelay(IXGBE_I2C_T_SU_STO);
  1228. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1229. /* bus free time between stop and start (4.7us)*/
  1230. udelay(IXGBE_I2C_T_BUF);
  1231. }
  1232. /**
  1233. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  1234. * @hw: pointer to hardware structure
  1235. * @data: data byte to clock in
  1236. *
  1237. * Clocks in one byte data via I2C data/clock
  1238. **/
  1239. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  1240. {
  1241. s32 i;
  1242. bool bit = false;
  1243. for (i = 7; i >= 0; i--) {
  1244. ixgbe_clock_in_i2c_bit(hw, &bit);
  1245. *data |= bit << i;
  1246. }
  1247. return 0;
  1248. }
  1249. /**
  1250. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  1251. * @hw: pointer to hardware structure
  1252. * @data: data byte clocked out
  1253. *
  1254. * Clocks out one byte data via I2C data/clock
  1255. **/
  1256. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  1257. {
  1258. s32 status = 0;
  1259. s32 i;
  1260. u32 i2cctl;
  1261. bool bit = false;
  1262. for (i = 7; i >= 0; i--) {
  1263. bit = (data >> i) & 0x1;
  1264. status = ixgbe_clock_out_i2c_bit(hw, bit);
  1265. if (status != 0)
  1266. break;
  1267. }
  1268. /* Release SDA line (set high) */
  1269. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1270. i2cctl |= IXGBE_I2C_DATA_OUT;
  1271. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  1272. IXGBE_WRITE_FLUSH(hw);
  1273. return status;
  1274. }
  1275. /**
  1276. * ixgbe_get_i2c_ack - Polls for I2C ACK
  1277. * @hw: pointer to hardware structure
  1278. *
  1279. * Clocks in/out one bit via I2C data/clock
  1280. **/
  1281. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  1282. {
  1283. s32 status = 0;
  1284. u32 i = 0;
  1285. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1286. u32 timeout = 10;
  1287. bool ack = true;
  1288. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1289. /* Minimum high period of clock is 4us */
  1290. udelay(IXGBE_I2C_T_HIGH);
  1291. /* Poll for ACK. Note that ACK in I2C spec is
  1292. * transition from 1 to 0 */
  1293. for (i = 0; i < timeout; i++) {
  1294. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1295. ack = ixgbe_get_i2c_data(&i2cctl);
  1296. udelay(1);
  1297. if (ack == 0)
  1298. break;
  1299. }
  1300. if (ack == 1) {
  1301. hw_dbg(hw, "I2C ack was not received.\n");
  1302. status = IXGBE_ERR_I2C;
  1303. }
  1304. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1305. /* Minimum low period of clock is 4.7 us */
  1306. udelay(IXGBE_I2C_T_LOW);
  1307. return status;
  1308. }
  1309. /**
  1310. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  1311. * @hw: pointer to hardware structure
  1312. * @data: read data value
  1313. *
  1314. * Clocks in one bit via I2C data/clock
  1315. **/
  1316. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  1317. {
  1318. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1319. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1320. /* Minimum high period of clock is 4us */
  1321. udelay(IXGBE_I2C_T_HIGH);
  1322. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1323. *data = ixgbe_get_i2c_data(&i2cctl);
  1324. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1325. /* Minimum low period of clock is 4.7 us */
  1326. udelay(IXGBE_I2C_T_LOW);
  1327. return 0;
  1328. }
  1329. /**
  1330. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  1331. * @hw: pointer to hardware structure
  1332. * @data: data value to write
  1333. *
  1334. * Clocks out one bit via I2C data/clock
  1335. **/
  1336. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  1337. {
  1338. s32 status;
  1339. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1340. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  1341. if (status == 0) {
  1342. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1343. /* Minimum high period of clock is 4us */
  1344. udelay(IXGBE_I2C_T_HIGH);
  1345. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1346. /* Minimum low period of clock is 4.7 us.
  1347. * This also takes care of the data hold time.
  1348. */
  1349. udelay(IXGBE_I2C_T_LOW);
  1350. } else {
  1351. status = IXGBE_ERR_I2C;
  1352. hw_dbg(hw, "I2C data was not set to %X\n", data);
  1353. }
  1354. return status;
  1355. }
  1356. /**
  1357. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  1358. * @hw: pointer to hardware structure
  1359. * @i2cctl: Current value of I2CCTL register
  1360. *
  1361. * Raises the I2C clock line '0'->'1'
  1362. **/
  1363. static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1364. {
  1365. u32 i = 0;
  1366. u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
  1367. u32 i2cctl_r = 0;
  1368. for (i = 0; i < timeout; i++) {
  1369. *i2cctl |= IXGBE_I2C_CLK_OUT;
  1370. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1371. IXGBE_WRITE_FLUSH(hw);
  1372. /* SCL rise time (1000ns) */
  1373. udelay(IXGBE_I2C_T_RISE);
  1374. i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1375. if (i2cctl_r & IXGBE_I2C_CLK_IN)
  1376. break;
  1377. }
  1378. }
  1379. /**
  1380. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  1381. * @hw: pointer to hardware structure
  1382. * @i2cctl: Current value of I2CCTL register
  1383. *
  1384. * Lowers the I2C clock line '1'->'0'
  1385. **/
  1386. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1387. {
  1388. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  1389. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1390. IXGBE_WRITE_FLUSH(hw);
  1391. /* SCL fall time (300ns) */
  1392. udelay(IXGBE_I2C_T_FALL);
  1393. }
  1394. /**
  1395. * ixgbe_set_i2c_data - Sets the I2C data bit
  1396. * @hw: pointer to hardware structure
  1397. * @i2cctl: Current value of I2CCTL register
  1398. * @data: I2C data value (0 or 1) to set
  1399. *
  1400. * Sets the I2C data bit
  1401. **/
  1402. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  1403. {
  1404. s32 status = 0;
  1405. if (data)
  1406. *i2cctl |= IXGBE_I2C_DATA_OUT;
  1407. else
  1408. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  1409. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1410. IXGBE_WRITE_FLUSH(hw);
  1411. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  1412. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  1413. /* Verify data was set correctly */
  1414. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1415. if (data != ixgbe_get_i2c_data(i2cctl)) {
  1416. status = IXGBE_ERR_I2C;
  1417. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  1418. }
  1419. return status;
  1420. }
  1421. /**
  1422. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1423. * @hw: pointer to hardware structure
  1424. * @i2cctl: Current value of I2CCTL register
  1425. *
  1426. * Returns the I2C data bit value
  1427. **/
  1428. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1429. {
  1430. bool data;
  1431. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1432. data = true;
  1433. else
  1434. data = false;
  1435. return data;
  1436. }
  1437. /**
  1438. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1439. * @hw: pointer to hardware structure
  1440. *
  1441. * Clears the I2C bus by sending nine clock pulses.
  1442. * Used when data line is stuck low.
  1443. **/
  1444. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1445. {
  1446. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1447. u32 i;
  1448. ixgbe_i2c_start(hw);
  1449. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1450. for (i = 0; i < 9; i++) {
  1451. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1452. /* Min high period of clock is 4us */
  1453. udelay(IXGBE_I2C_T_HIGH);
  1454. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1455. /* Min low period of clock is 4.7us*/
  1456. udelay(IXGBE_I2C_T_LOW);
  1457. }
  1458. ixgbe_i2c_start(hw);
  1459. /* Put the i2c bus back to default state */
  1460. ixgbe_i2c_stop(hw);
  1461. }
  1462. /**
  1463. * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
  1464. * @hw: pointer to hardware structure
  1465. *
  1466. * Checks if the LASI temp alarm status was triggered due to overtemp
  1467. **/
  1468. s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
  1469. {
  1470. s32 status = 0;
  1471. u16 phy_data = 0;
  1472. if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
  1473. goto out;
  1474. /* Check that the LASI temp alarm status was triggered */
  1475. hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
  1476. MDIO_MMD_PMAPMD, &phy_data);
  1477. if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
  1478. goto out;
  1479. status = IXGBE_ERR_OVERTEMP;
  1480. out:
  1481. return status;
  1482. }