ixgbe_phy.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 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. if (hw->phy.type == ixgbe_phy_unknown) {
  50. for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
  51. hw->phy.mdio.prtad = phy_addr;
  52. if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
  53. ixgbe_get_phy_id(hw);
  54. hw->phy.type =
  55. ixgbe_get_phy_type_from_id(hw->phy.id);
  56. status = 0;
  57. break;
  58. }
  59. }
  60. /* clear value if nothing found */
  61. hw->phy.mdio.prtad = 0;
  62. } else {
  63. status = 0;
  64. }
  65. return status;
  66. }
  67. /**
  68. * ixgbe_get_phy_id - Get the phy type
  69. * @hw: pointer to hardware structure
  70. *
  71. **/
  72. static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
  73. {
  74. u32 status;
  75. u16 phy_id_high = 0;
  76. u16 phy_id_low = 0;
  77. status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
  78. &phy_id_high);
  79. if (status == 0) {
  80. hw->phy.id = (u32)(phy_id_high << 16);
  81. status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
  82. &phy_id_low);
  83. hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
  84. hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
  85. }
  86. return status;
  87. }
  88. /**
  89. * ixgbe_get_phy_type_from_id - Get the phy type
  90. * @hw: pointer to hardware structure
  91. *
  92. **/
  93. static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
  94. {
  95. enum ixgbe_phy_type phy_type;
  96. switch (phy_id) {
  97. case TN1010_PHY_ID:
  98. phy_type = ixgbe_phy_tn;
  99. break;
  100. case QT2022_PHY_ID:
  101. phy_type = ixgbe_phy_qt;
  102. break;
  103. case ATH_PHY_ID:
  104. phy_type = ixgbe_phy_nl;
  105. break;
  106. default:
  107. phy_type = ixgbe_phy_unknown;
  108. break;
  109. }
  110. return phy_type;
  111. }
  112. /**
  113. * ixgbe_reset_phy_generic - Performs a PHY reset
  114. * @hw: pointer to hardware structure
  115. **/
  116. s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
  117. {
  118. /*
  119. * Perform soft PHY reset to the PHY_XS.
  120. * This will cause a soft reset to the PHY
  121. */
  122. return hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  123. MDIO_CTRL1_RESET);
  124. }
  125. /**
  126. * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
  127. * @hw: pointer to hardware structure
  128. * @reg_addr: 32 bit address of PHY register to read
  129. * @phy_data: Pointer to read data from PHY register
  130. **/
  131. s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  132. u32 device_type, u16 *phy_data)
  133. {
  134. u32 command;
  135. u32 i;
  136. u32 data;
  137. s32 status = 0;
  138. u16 gssr;
  139. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  140. gssr = IXGBE_GSSR_PHY1_SM;
  141. else
  142. gssr = IXGBE_GSSR_PHY0_SM;
  143. if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
  144. status = IXGBE_ERR_SWFW_SYNC;
  145. if (status == 0) {
  146. /* Setup and write the address cycle command */
  147. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  148. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  149. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  150. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  151. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  152. /*
  153. * Check every 10 usec to see if the address cycle completed.
  154. * The MDI Command bit will clear when the operation is
  155. * complete
  156. */
  157. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  158. udelay(10);
  159. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  160. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  161. break;
  162. }
  163. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  164. hw_dbg(hw, "PHY address command did not complete.\n");
  165. status = IXGBE_ERR_PHY;
  166. }
  167. if (status == 0) {
  168. /*
  169. * Address cycle complete, setup and write the read
  170. * command
  171. */
  172. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  173. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  174. (hw->phy.mdio.prtad <<
  175. IXGBE_MSCA_PHY_ADDR_SHIFT) |
  176. (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
  177. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  178. /*
  179. * Check every 10 usec to see if the address cycle
  180. * completed. The MDI Command bit will clear when the
  181. * operation is complete
  182. */
  183. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  184. udelay(10);
  185. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  186. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  187. break;
  188. }
  189. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  190. hw_dbg(hw, "PHY read command didn't complete\n");
  191. status = IXGBE_ERR_PHY;
  192. } else {
  193. /*
  194. * Read operation is complete. Get the data
  195. * from MSRWD
  196. */
  197. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  198. data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
  199. *phy_data = (u16)(data);
  200. }
  201. }
  202. ixgbe_release_swfw_sync(hw, gssr);
  203. }
  204. return status;
  205. }
  206. /**
  207. * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
  208. * @hw: pointer to hardware structure
  209. * @reg_addr: 32 bit PHY register to write
  210. * @device_type: 5 bit device type
  211. * @phy_data: Data to write to the PHY register
  212. **/
  213. s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  214. u32 device_type, u16 phy_data)
  215. {
  216. u32 command;
  217. u32 i;
  218. s32 status = 0;
  219. u16 gssr;
  220. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  221. gssr = IXGBE_GSSR_PHY1_SM;
  222. else
  223. gssr = IXGBE_GSSR_PHY0_SM;
  224. if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
  225. status = IXGBE_ERR_SWFW_SYNC;
  226. if (status == 0) {
  227. /* Put the data in the MDI single read and write data register*/
  228. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
  229. /* Setup and write the address cycle command */
  230. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  231. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  232. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  233. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  234. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  235. /*
  236. * Check every 10 usec to see if the address cycle completed.
  237. * The MDI Command bit will clear when the operation is
  238. * complete
  239. */
  240. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  241. udelay(10);
  242. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  243. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  244. break;
  245. }
  246. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  247. hw_dbg(hw, "PHY address cmd didn't complete\n");
  248. status = IXGBE_ERR_PHY;
  249. }
  250. if (status == 0) {
  251. /*
  252. * Address cycle complete, setup and write the write
  253. * command
  254. */
  255. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  256. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  257. (hw->phy.mdio.prtad <<
  258. IXGBE_MSCA_PHY_ADDR_SHIFT) |
  259. (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
  260. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  261. /*
  262. * Check every 10 usec to see if the address cycle
  263. * completed. The MDI Command bit will clear when the
  264. * operation is complete
  265. */
  266. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  267. udelay(10);
  268. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  269. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  270. break;
  271. }
  272. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  273. hw_dbg(hw, "PHY address cmd didn't complete\n");
  274. status = IXGBE_ERR_PHY;
  275. }
  276. }
  277. ixgbe_release_swfw_sync(hw, gssr);
  278. }
  279. return status;
  280. }
  281. /**
  282. * ixgbe_setup_phy_link_generic - Set and restart autoneg
  283. * @hw: pointer to hardware structure
  284. *
  285. * Restart autonegotiation and PHY and waits for completion.
  286. **/
  287. s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
  288. {
  289. s32 status = IXGBE_NOT_IMPLEMENTED;
  290. u32 time_out;
  291. u32 max_time_out = 10;
  292. u16 autoneg_reg;
  293. /*
  294. * Set advertisement settings in PHY based on autoneg_advertised
  295. * settings. If autoneg_advertised = 0, then advertise default values
  296. * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
  297. * for a 1G.
  298. */
  299. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
  300. if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
  301. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  302. else
  303. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  304. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
  305. /* Restart PHY autonegotiation and wait for completion */
  306. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg);
  307. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  308. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg);
  309. /* Wait for autonegotiation to finish */
  310. for (time_out = 0; time_out < max_time_out; time_out++) {
  311. udelay(10);
  312. /* Restart PHY autonegotiation and wait for completion */
  313. status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
  314. &autoneg_reg);
  315. autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
  316. if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
  317. status = 0;
  318. break;
  319. }
  320. }
  321. if (time_out == max_time_out)
  322. status = IXGBE_ERR_LINK_SETUP;
  323. return status;
  324. }
  325. /**
  326. * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
  327. * @hw: pointer to hardware structure
  328. * @speed: new link speed
  329. * @autoneg: true if autonegotiation enabled
  330. **/
  331. s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  332. ixgbe_link_speed speed,
  333. bool autoneg,
  334. bool autoneg_wait_to_complete)
  335. {
  336. /*
  337. * Clear autoneg_advertised and set new values based on input link
  338. * speed.
  339. */
  340. hw->phy.autoneg_advertised = 0;
  341. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  342. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  343. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  344. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  345. /* Setup link based on the new speed settings */
  346. hw->phy.ops.setup_link(hw);
  347. return 0;
  348. }
  349. /**
  350. * ixgbe_reset_phy_nl - Performs a PHY reset
  351. * @hw: pointer to hardware structure
  352. **/
  353. s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  354. {
  355. u16 phy_offset, control, eword, edata, block_crc;
  356. bool end_data = false;
  357. u16 list_offset, data_offset;
  358. u16 phy_data = 0;
  359. s32 ret_val = 0;
  360. u32 i;
  361. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
  362. /* reset the PHY and poll for completion */
  363. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  364. (phy_data | MDIO_CTRL1_RESET));
  365. for (i = 0; i < 100; i++) {
  366. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  367. &phy_data);
  368. if ((phy_data & MDIO_CTRL1_RESET) == 0)
  369. break;
  370. msleep(10);
  371. }
  372. if ((phy_data & MDIO_CTRL1_RESET) != 0) {
  373. hw_dbg(hw, "PHY reset did not complete.\n");
  374. ret_val = IXGBE_ERR_PHY;
  375. goto out;
  376. }
  377. /* Get init offsets */
  378. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  379. &data_offset);
  380. if (ret_val != 0)
  381. goto out;
  382. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  383. data_offset++;
  384. while (!end_data) {
  385. /*
  386. * Read control word from PHY init contents offset
  387. */
  388. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  389. control = (eword & IXGBE_CONTROL_MASK_NL) >>
  390. IXGBE_CONTROL_SHIFT_NL;
  391. edata = eword & IXGBE_DATA_MASK_NL;
  392. switch (control) {
  393. case IXGBE_DELAY_NL:
  394. data_offset++;
  395. hw_dbg(hw, "DELAY: %d MS\n", edata);
  396. msleep(edata);
  397. break;
  398. case IXGBE_DATA_NL:
  399. hw_dbg(hw, "DATA: \n");
  400. data_offset++;
  401. hw->eeprom.ops.read(hw, data_offset++,
  402. &phy_offset);
  403. for (i = 0; i < edata; i++) {
  404. hw->eeprom.ops.read(hw, data_offset, &eword);
  405. hw->phy.ops.write_reg(hw, phy_offset,
  406. MDIO_MMD_PMAPMD, eword);
  407. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  408. phy_offset);
  409. data_offset++;
  410. phy_offset++;
  411. }
  412. break;
  413. case IXGBE_CONTROL_NL:
  414. data_offset++;
  415. hw_dbg(hw, "CONTROL: \n");
  416. if (edata == IXGBE_CONTROL_EOL_NL) {
  417. hw_dbg(hw, "EOL\n");
  418. end_data = true;
  419. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  420. hw_dbg(hw, "SOL\n");
  421. } else {
  422. hw_dbg(hw, "Bad control value\n");
  423. ret_val = IXGBE_ERR_PHY;
  424. goto out;
  425. }
  426. break;
  427. default:
  428. hw_dbg(hw, "Bad control type\n");
  429. ret_val = IXGBE_ERR_PHY;
  430. goto out;
  431. }
  432. }
  433. out:
  434. return ret_val;
  435. }
  436. /**
  437. * ixgbe_identify_sfp_module_generic - Identifies SFP module and assigns
  438. * the PHY type.
  439. * @hw: pointer to hardware structure
  440. *
  441. * Searches for and indentifies the SFP module. Assings appropriate PHY type.
  442. **/
  443. s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  444. {
  445. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  446. u32 vendor_oui = 0;
  447. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  448. u8 identifier = 0;
  449. u8 comp_codes_1g = 0;
  450. u8 comp_codes_10g = 0;
  451. u8 oui_bytes[3] = {0, 0, 0};
  452. u8 cable_tech = 0;
  453. u16 enforce_sfp = 0;
  454. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
  455. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  456. status = IXGBE_ERR_SFP_NOT_PRESENT;
  457. goto out;
  458. }
  459. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
  460. &identifier);
  461. if (status == IXGBE_ERR_SFP_NOT_PRESENT || status == IXGBE_ERR_I2C) {
  462. status = IXGBE_ERR_SFP_NOT_PRESENT;
  463. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  464. if (hw->phy.type != ixgbe_phy_nl) {
  465. hw->phy.id = 0;
  466. hw->phy.type = ixgbe_phy_unknown;
  467. }
  468. goto out;
  469. }
  470. if (identifier == IXGBE_SFF_IDENTIFIER_SFP) {
  471. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES,
  472. &comp_codes_1g);
  473. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES,
  474. &comp_codes_10g);
  475. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_CABLE_TECHNOLOGY,
  476. &cable_tech);
  477. /* ID Module
  478. * =========
  479. * 0 SFP_DA_CU
  480. * 1 SFP_SR
  481. * 2 SFP_LR
  482. * 3 SFP_DA_CORE0 - 82599-specific
  483. * 4 SFP_DA_CORE1 - 82599-specific
  484. * 5 SFP_SR/LR_CORE0 - 82599-specific
  485. * 6 SFP_SR/LR_CORE1 - 82599-specific
  486. */
  487. if (hw->mac.type == ixgbe_mac_82598EB) {
  488. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  489. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  490. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  491. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  492. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  493. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  494. else
  495. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  496. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  497. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  498. if (hw->bus.lan_id == 0)
  499. hw->phy.sfp_type =
  500. ixgbe_sfp_type_da_cu_core0;
  501. else
  502. hw->phy.sfp_type =
  503. ixgbe_sfp_type_da_cu_core1;
  504. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  505. if (hw->bus.lan_id == 0)
  506. hw->phy.sfp_type =
  507. ixgbe_sfp_type_srlr_core0;
  508. else
  509. hw->phy.sfp_type =
  510. ixgbe_sfp_type_srlr_core1;
  511. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  512. if (hw->bus.lan_id == 0)
  513. hw->phy.sfp_type =
  514. ixgbe_sfp_type_srlr_core0;
  515. else
  516. hw->phy.sfp_type =
  517. ixgbe_sfp_type_srlr_core1;
  518. else
  519. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  520. }
  521. if (hw->phy.sfp_type != stored_sfp_type)
  522. hw->phy.sfp_setup_needed = true;
  523. /* Determine if the SFP+ PHY is dual speed or not. */
  524. hw->phy.multispeed_fiber = false;
  525. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  526. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  527. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  528. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  529. hw->phy.multispeed_fiber = true;
  530. /* Determine PHY vendor */
  531. if (hw->phy.type != ixgbe_phy_nl) {
  532. hw->phy.id = identifier;
  533. hw->phy.ops.read_i2c_eeprom(hw,
  534. IXGBE_SFF_VENDOR_OUI_BYTE0,
  535. &oui_bytes[0]);
  536. hw->phy.ops.read_i2c_eeprom(hw,
  537. IXGBE_SFF_VENDOR_OUI_BYTE1,
  538. &oui_bytes[1]);
  539. hw->phy.ops.read_i2c_eeprom(hw,
  540. IXGBE_SFF_VENDOR_OUI_BYTE2,
  541. &oui_bytes[2]);
  542. vendor_oui =
  543. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  544. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  545. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  546. switch (vendor_oui) {
  547. case IXGBE_SFF_VENDOR_OUI_TYCO:
  548. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  549. hw->phy.type = ixgbe_phy_tw_tyco;
  550. break;
  551. case IXGBE_SFF_VENDOR_OUI_FTL:
  552. hw->phy.type = ixgbe_phy_sfp_ftl;
  553. break;
  554. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  555. hw->phy.type = ixgbe_phy_sfp_avago;
  556. break;
  557. case IXGBE_SFF_VENDOR_OUI_INTEL:
  558. hw->phy.type = ixgbe_phy_sfp_intel;
  559. break;
  560. default:
  561. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  562. hw->phy.type = ixgbe_phy_tw_unknown;
  563. else
  564. hw->phy.type = ixgbe_phy_sfp_unknown;
  565. break;
  566. }
  567. }
  568. /* All passive DA cables are supported */
  569. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
  570. status = 0;
  571. goto out;
  572. }
  573. /* 1G SFP modules are not supported */
  574. if (comp_codes_10g == 0) {
  575. hw->phy.type = ixgbe_phy_sfp_unsupported;
  576. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  577. goto out;
  578. }
  579. /* Anything else 82598-based is supported */
  580. if (hw->mac.type == ixgbe_mac_82598EB) {
  581. status = 0;
  582. goto out;
  583. }
  584. /* This is guaranteed to be 82599, no need to check for NULL */
  585. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  586. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
  587. /* Make sure we're a supported PHY type */
  588. if (hw->phy.type == ixgbe_phy_sfp_intel) {
  589. status = 0;
  590. } else {
  591. hw_dbg(hw, "SFP+ module not supported\n");
  592. hw->phy.type = ixgbe_phy_sfp_unsupported;
  593. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  594. }
  595. } else {
  596. status = 0;
  597. }
  598. }
  599. out:
  600. return status;
  601. }
  602. /**
  603. * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
  604. * if it supports a given SFP+ module type, if so it returns the offsets to the
  605. * phy init sequence block.
  606. * @hw: pointer to hardware structure
  607. * @list_offset: offset to the SFP ID list
  608. * @data_offset: offset to the SFP data block
  609. **/
  610. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  611. u16 *list_offset,
  612. u16 *data_offset)
  613. {
  614. u16 sfp_id;
  615. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  616. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  617. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  618. return IXGBE_ERR_SFP_NOT_PRESENT;
  619. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  620. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  621. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  622. /* Read offset to PHY init contents */
  623. hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
  624. if ((!*list_offset) || (*list_offset == 0xFFFF))
  625. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  626. /* Shift offset to first ID word */
  627. (*list_offset)++;
  628. /*
  629. * Find the matching SFP ID in the EEPROM
  630. * and program the init sequence
  631. */
  632. hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
  633. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  634. if (sfp_id == hw->phy.sfp_type) {
  635. (*list_offset)++;
  636. hw->eeprom.ops.read(hw, *list_offset, data_offset);
  637. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  638. hw_dbg(hw, "SFP+ module not supported\n");
  639. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  640. } else {
  641. break;
  642. }
  643. } else {
  644. (*list_offset) += 2;
  645. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  646. return IXGBE_ERR_PHY;
  647. }
  648. }
  649. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  650. hw_dbg(hw, "No matching SFP+ module found\n");
  651. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  652. }
  653. return 0;
  654. }
  655. /**
  656. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  657. * @hw: pointer to hardware structure
  658. * @byte_offset: EEPROM byte offset to read
  659. * @eeprom_data: value read
  660. *
  661. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  662. **/
  663. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  664. u8 *eeprom_data)
  665. {
  666. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  667. IXGBE_I2C_EEPROM_DEV_ADDR,
  668. eeprom_data);
  669. }
  670. /**
  671. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  672. * @hw: pointer to hardware structure
  673. * @byte_offset: EEPROM byte offset to write
  674. * @eeprom_data: value to write
  675. *
  676. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  677. **/
  678. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  679. u8 eeprom_data)
  680. {
  681. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  682. IXGBE_I2C_EEPROM_DEV_ADDR,
  683. eeprom_data);
  684. }
  685. /**
  686. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  687. * @hw: pointer to hardware structure
  688. * @byte_offset: byte offset to read
  689. * @data: value read
  690. *
  691. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  692. * a specified deivce address.
  693. **/
  694. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  695. u8 dev_addr, u8 *data)
  696. {
  697. s32 status = 0;
  698. u32 max_retry = 1;
  699. u32 retry = 0;
  700. bool nack = 1;
  701. do {
  702. ixgbe_i2c_start(hw);
  703. /* Device Address and write indication */
  704. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  705. if (status != 0)
  706. goto fail;
  707. status = ixgbe_get_i2c_ack(hw);
  708. if (status != 0)
  709. goto fail;
  710. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  711. if (status != 0)
  712. goto fail;
  713. status = ixgbe_get_i2c_ack(hw);
  714. if (status != 0)
  715. goto fail;
  716. ixgbe_i2c_start(hw);
  717. /* Device Address and read indication */
  718. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  719. if (status != 0)
  720. goto fail;
  721. status = ixgbe_get_i2c_ack(hw);
  722. if (status != 0)
  723. goto fail;
  724. status = ixgbe_clock_in_i2c_byte(hw, data);
  725. if (status != 0)
  726. goto fail;
  727. status = ixgbe_clock_out_i2c_bit(hw, nack);
  728. if (status != 0)
  729. goto fail;
  730. ixgbe_i2c_stop(hw);
  731. break;
  732. fail:
  733. ixgbe_i2c_bus_clear(hw);
  734. retry++;
  735. if (retry < max_retry)
  736. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  737. else
  738. hw_dbg(hw, "I2C byte read error.\n");
  739. } while (retry < max_retry);
  740. return status;
  741. }
  742. /**
  743. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  744. * @hw: pointer to hardware structure
  745. * @byte_offset: byte offset to write
  746. * @data: value to write
  747. *
  748. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  749. * a specified device address.
  750. **/
  751. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  752. u8 dev_addr, u8 data)
  753. {
  754. s32 status = 0;
  755. u32 max_retry = 1;
  756. u32 retry = 0;
  757. do {
  758. ixgbe_i2c_start(hw);
  759. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  760. if (status != 0)
  761. goto fail;
  762. status = ixgbe_get_i2c_ack(hw);
  763. if (status != 0)
  764. goto fail;
  765. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  766. if (status != 0)
  767. goto fail;
  768. status = ixgbe_get_i2c_ack(hw);
  769. if (status != 0)
  770. goto fail;
  771. status = ixgbe_clock_out_i2c_byte(hw, data);
  772. if (status != 0)
  773. goto fail;
  774. status = ixgbe_get_i2c_ack(hw);
  775. if (status != 0)
  776. goto fail;
  777. ixgbe_i2c_stop(hw);
  778. break;
  779. fail:
  780. ixgbe_i2c_bus_clear(hw);
  781. retry++;
  782. if (retry < max_retry)
  783. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  784. else
  785. hw_dbg(hw, "I2C byte write error.\n");
  786. } while (retry < max_retry);
  787. return status;
  788. }
  789. /**
  790. * ixgbe_i2c_start - Sets I2C start condition
  791. * @hw: pointer to hardware structure
  792. *
  793. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  794. **/
  795. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  796. {
  797. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  798. /* Start condition must begin with data and clock high */
  799. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  800. ixgbe_raise_i2c_clk(hw, &i2cctl);
  801. /* Setup time for start condition (4.7us) */
  802. udelay(IXGBE_I2C_T_SU_STA);
  803. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  804. /* Hold time for start condition (4us) */
  805. udelay(IXGBE_I2C_T_HD_STA);
  806. ixgbe_lower_i2c_clk(hw, &i2cctl);
  807. /* Minimum low period of clock is 4.7 us */
  808. udelay(IXGBE_I2C_T_LOW);
  809. }
  810. /**
  811. * ixgbe_i2c_stop - Sets I2C stop condition
  812. * @hw: pointer to hardware structure
  813. *
  814. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  815. **/
  816. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  817. {
  818. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  819. /* Stop condition must begin with data low and clock high */
  820. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  821. ixgbe_raise_i2c_clk(hw, &i2cctl);
  822. /* Setup time for stop condition (4us) */
  823. udelay(IXGBE_I2C_T_SU_STO);
  824. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  825. /* bus free time between stop and start (4.7us)*/
  826. udelay(IXGBE_I2C_T_BUF);
  827. }
  828. /**
  829. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  830. * @hw: pointer to hardware structure
  831. * @data: data byte to clock in
  832. *
  833. * Clocks in one byte data via I2C data/clock
  834. **/
  835. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  836. {
  837. s32 status = 0;
  838. s32 i;
  839. bool bit = 0;
  840. for (i = 7; i >= 0; i--) {
  841. status = ixgbe_clock_in_i2c_bit(hw, &bit);
  842. *data |= bit << i;
  843. if (status != 0)
  844. break;
  845. }
  846. return status;
  847. }
  848. /**
  849. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  850. * @hw: pointer to hardware structure
  851. * @data: data byte clocked out
  852. *
  853. * Clocks out one byte data via I2C data/clock
  854. **/
  855. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  856. {
  857. s32 status = 0;
  858. s32 i;
  859. u32 i2cctl;
  860. bool bit = 0;
  861. for (i = 7; i >= 0; i--) {
  862. bit = (data >> i) & 0x1;
  863. status = ixgbe_clock_out_i2c_bit(hw, bit);
  864. if (status != 0)
  865. break;
  866. }
  867. /* Release SDA line (set high) */
  868. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  869. i2cctl |= IXGBE_I2C_DATA_OUT;
  870. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  871. return status;
  872. }
  873. /**
  874. * ixgbe_get_i2c_ack - Polls for I2C ACK
  875. * @hw: pointer to hardware structure
  876. *
  877. * Clocks in/out one bit via I2C data/clock
  878. **/
  879. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  880. {
  881. s32 status;
  882. u32 i = 0;
  883. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  884. u32 timeout = 10;
  885. bool ack = 1;
  886. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  887. if (status != 0)
  888. goto out;
  889. /* Minimum high period of clock is 4us */
  890. udelay(IXGBE_I2C_T_HIGH);
  891. /* Poll for ACK. Note that ACK in I2C spec is
  892. * transition from 1 to 0 */
  893. for (i = 0; i < timeout; i++) {
  894. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  895. ack = ixgbe_get_i2c_data(&i2cctl);
  896. udelay(1);
  897. if (ack == 0)
  898. break;
  899. }
  900. if (ack == 1) {
  901. hw_dbg(hw, "I2C ack was not received.\n");
  902. status = IXGBE_ERR_I2C;
  903. }
  904. ixgbe_lower_i2c_clk(hw, &i2cctl);
  905. /* Minimum low period of clock is 4.7 us */
  906. udelay(IXGBE_I2C_T_LOW);
  907. out:
  908. return status;
  909. }
  910. /**
  911. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  912. * @hw: pointer to hardware structure
  913. * @data: read data value
  914. *
  915. * Clocks in one bit via I2C data/clock
  916. **/
  917. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  918. {
  919. s32 status;
  920. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  921. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  922. /* Minimum high period of clock is 4us */
  923. udelay(IXGBE_I2C_T_HIGH);
  924. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  925. *data = ixgbe_get_i2c_data(&i2cctl);
  926. ixgbe_lower_i2c_clk(hw, &i2cctl);
  927. /* Minimum low period of clock is 4.7 us */
  928. udelay(IXGBE_I2C_T_LOW);
  929. return status;
  930. }
  931. /**
  932. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  933. * @hw: pointer to hardware structure
  934. * @data: data value to write
  935. *
  936. * Clocks out one bit via I2C data/clock
  937. **/
  938. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  939. {
  940. s32 status;
  941. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  942. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  943. if (status == 0) {
  944. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  945. /* Minimum high period of clock is 4us */
  946. udelay(IXGBE_I2C_T_HIGH);
  947. ixgbe_lower_i2c_clk(hw, &i2cctl);
  948. /* Minimum low period of clock is 4.7 us.
  949. * This also takes care of the data hold time.
  950. */
  951. udelay(IXGBE_I2C_T_LOW);
  952. } else {
  953. status = IXGBE_ERR_I2C;
  954. hw_dbg(hw, "I2C data was not set to %X\n", data);
  955. }
  956. return status;
  957. }
  958. /**
  959. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  960. * @hw: pointer to hardware structure
  961. * @i2cctl: Current value of I2CCTL register
  962. *
  963. * Raises the I2C clock line '0'->'1'
  964. **/
  965. static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  966. {
  967. s32 status = 0;
  968. *i2cctl |= IXGBE_I2C_CLK_OUT;
  969. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  970. /* SCL rise time (1000ns) */
  971. udelay(IXGBE_I2C_T_RISE);
  972. return status;
  973. }
  974. /**
  975. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  976. * @hw: pointer to hardware structure
  977. * @i2cctl: Current value of I2CCTL register
  978. *
  979. * Lowers the I2C clock line '1'->'0'
  980. **/
  981. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  982. {
  983. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  984. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  985. /* SCL fall time (300ns) */
  986. udelay(IXGBE_I2C_T_FALL);
  987. }
  988. /**
  989. * ixgbe_set_i2c_data - Sets the I2C data bit
  990. * @hw: pointer to hardware structure
  991. * @i2cctl: Current value of I2CCTL register
  992. * @data: I2C data value (0 or 1) to set
  993. *
  994. * Sets the I2C data bit
  995. **/
  996. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  997. {
  998. s32 status = 0;
  999. if (data)
  1000. *i2cctl |= IXGBE_I2C_DATA_OUT;
  1001. else
  1002. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  1003. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1004. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  1005. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  1006. /* Verify data was set correctly */
  1007. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1008. if (data != ixgbe_get_i2c_data(i2cctl)) {
  1009. status = IXGBE_ERR_I2C;
  1010. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  1011. }
  1012. return status;
  1013. }
  1014. /**
  1015. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1016. * @hw: pointer to hardware structure
  1017. * @i2cctl: Current value of I2CCTL register
  1018. *
  1019. * Returns the I2C data bit value
  1020. **/
  1021. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1022. {
  1023. bool data;
  1024. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1025. data = 1;
  1026. else
  1027. data = 0;
  1028. return data;
  1029. }
  1030. /**
  1031. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1032. * @hw: pointer to hardware structure
  1033. *
  1034. * Clears the I2C bus by sending nine clock pulses.
  1035. * Used when data line is stuck low.
  1036. **/
  1037. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1038. {
  1039. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1040. u32 i;
  1041. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1042. for (i = 0; i < 9; i++) {
  1043. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1044. /* Min high period of clock is 4us */
  1045. udelay(IXGBE_I2C_T_HIGH);
  1046. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1047. /* Min low period of clock is 4.7us*/
  1048. udelay(IXGBE_I2C_T_LOW);
  1049. }
  1050. /* Put the i2c bus back to default state */
  1051. ixgbe_i2c_stop(hw);
  1052. }
  1053. /**
  1054. * ixgbe_check_phy_link_tnx - Determine link and speed status
  1055. * @hw: pointer to hardware structure
  1056. *
  1057. * Reads the VS1 register to determine if link is up and the current speed for
  1058. * the PHY.
  1059. **/
  1060. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  1061. bool *link_up)
  1062. {
  1063. s32 status = 0;
  1064. u32 time_out;
  1065. u32 max_time_out = 10;
  1066. u16 phy_link = 0;
  1067. u16 phy_speed = 0;
  1068. u16 phy_data = 0;
  1069. /* Initialize speed and link to default case */
  1070. *link_up = false;
  1071. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  1072. /*
  1073. * Check current speed and link status of the PHY register.
  1074. * This is a vendor specific register and may have to
  1075. * be changed for other copper PHYs.
  1076. */
  1077. for (time_out = 0; time_out < max_time_out; time_out++) {
  1078. udelay(10);
  1079. status = hw->phy.ops.read_reg(hw,
  1080. IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
  1081. MDIO_MMD_VEND1,
  1082. &phy_data);
  1083. phy_link = phy_data &
  1084. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  1085. phy_speed = phy_data &
  1086. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  1087. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  1088. *link_up = true;
  1089. if (phy_speed ==
  1090. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  1091. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1092. break;
  1093. }
  1094. }
  1095. return status;
  1096. }
  1097. /**
  1098. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  1099. * @hw: pointer to hardware structure
  1100. * @firmware_version: pointer to the PHY Firmware Version
  1101. **/
  1102. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  1103. u16 *firmware_version)
  1104. {
  1105. s32 status = 0;
  1106. status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1,
  1107. firmware_version);
  1108. return status;
  1109. }