ixgbe_phy.c 34 KB

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