ixgbe_phy.c 34 KB

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