ixgbe_phy.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  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. /* All DA cables are supported */
  583. if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE) {
  584. status = 0;
  585. goto out;
  586. }
  587. /* 1G SFP modules are not supported */
  588. if (comp_codes_10g == 0) {
  589. hw->phy.type = ixgbe_phy_sfp_unsupported;
  590. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  591. goto out;
  592. }
  593. /* Anything else 82598-based is supported */
  594. if (hw->mac.type == ixgbe_mac_82598EB) {
  595. status = 0;
  596. goto out;
  597. }
  598. /* This is guaranteed to be 82599, no need to check for NULL */
  599. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  600. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
  601. /* Make sure we're a supported PHY type */
  602. if (hw->phy.type == ixgbe_phy_sfp_intel) {
  603. status = 0;
  604. } else {
  605. hw_dbg(hw, "SFP+ module not supported\n");
  606. hw->phy.type = ixgbe_phy_sfp_unsupported;
  607. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  608. }
  609. } else {
  610. status = 0;
  611. }
  612. }
  613. out:
  614. return status;
  615. }
  616. /**
  617. * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
  618. * if it supports a given SFP+ module type, if so it returns the offsets to the
  619. * phy init sequence block.
  620. * @hw: pointer to hardware structure
  621. * @list_offset: offset to the SFP ID list
  622. * @data_offset: offset to the SFP data block
  623. **/
  624. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  625. u16 *list_offset,
  626. u16 *data_offset)
  627. {
  628. u16 sfp_id;
  629. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  630. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  631. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  632. return IXGBE_ERR_SFP_NOT_PRESENT;
  633. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  634. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  635. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  636. /* Read offset to PHY init contents */
  637. hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
  638. if ((!*list_offset) || (*list_offset == 0xFFFF))
  639. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  640. /* Shift offset to first ID word */
  641. (*list_offset)++;
  642. /*
  643. * Find the matching SFP ID in the EEPROM
  644. * and program the init sequence
  645. */
  646. hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
  647. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  648. if (sfp_id == hw->phy.sfp_type) {
  649. (*list_offset)++;
  650. hw->eeprom.ops.read(hw, *list_offset, data_offset);
  651. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  652. hw_dbg(hw, "SFP+ module not supported\n");
  653. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  654. } else {
  655. break;
  656. }
  657. } else {
  658. (*list_offset) += 2;
  659. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  660. return IXGBE_ERR_PHY;
  661. }
  662. }
  663. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  664. hw_dbg(hw, "No matching SFP+ module found\n");
  665. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  666. }
  667. return 0;
  668. }
  669. /**
  670. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  671. * @hw: pointer to hardware structure
  672. * @byte_offset: EEPROM byte offset to read
  673. * @eeprom_data: value read
  674. *
  675. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  676. **/
  677. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  678. u8 *eeprom_data)
  679. {
  680. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  681. IXGBE_I2C_EEPROM_DEV_ADDR,
  682. eeprom_data);
  683. }
  684. /**
  685. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  686. * @hw: pointer to hardware structure
  687. * @byte_offset: EEPROM byte offset to write
  688. * @eeprom_data: value to write
  689. *
  690. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  691. **/
  692. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  693. u8 eeprom_data)
  694. {
  695. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  696. IXGBE_I2C_EEPROM_DEV_ADDR,
  697. eeprom_data);
  698. }
  699. /**
  700. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  701. * @hw: pointer to hardware structure
  702. * @byte_offset: byte offset to read
  703. * @data: value read
  704. *
  705. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  706. * a specified deivce address.
  707. **/
  708. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  709. u8 dev_addr, u8 *data)
  710. {
  711. s32 status = 0;
  712. u32 max_retry = 1;
  713. u32 retry = 0;
  714. bool nack = 1;
  715. do {
  716. ixgbe_i2c_start(hw);
  717. /* Device Address and write indication */
  718. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  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_out_i2c_byte(hw, byte_offset);
  725. if (status != 0)
  726. goto fail;
  727. status = ixgbe_get_i2c_ack(hw);
  728. if (status != 0)
  729. goto fail;
  730. ixgbe_i2c_start(hw);
  731. /* Device Address and read indication */
  732. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  733. if (status != 0)
  734. goto fail;
  735. status = ixgbe_get_i2c_ack(hw);
  736. if (status != 0)
  737. goto fail;
  738. status = ixgbe_clock_in_i2c_byte(hw, data);
  739. if (status != 0)
  740. goto fail;
  741. status = ixgbe_clock_out_i2c_bit(hw, nack);
  742. if (status != 0)
  743. goto fail;
  744. ixgbe_i2c_stop(hw);
  745. break;
  746. fail:
  747. ixgbe_i2c_bus_clear(hw);
  748. retry++;
  749. if (retry < max_retry)
  750. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  751. else
  752. hw_dbg(hw, "I2C byte read error.\n");
  753. } while (retry < max_retry);
  754. return status;
  755. }
  756. /**
  757. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  758. * @hw: pointer to hardware structure
  759. * @byte_offset: byte offset to write
  760. * @data: value to write
  761. *
  762. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  763. * a specified device address.
  764. **/
  765. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  766. u8 dev_addr, u8 data)
  767. {
  768. s32 status = 0;
  769. u32 max_retry = 1;
  770. u32 retry = 0;
  771. do {
  772. ixgbe_i2c_start(hw);
  773. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  774. if (status != 0)
  775. goto fail;
  776. status = ixgbe_get_i2c_ack(hw);
  777. if (status != 0)
  778. goto fail;
  779. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  780. if (status != 0)
  781. goto fail;
  782. status = ixgbe_get_i2c_ack(hw);
  783. if (status != 0)
  784. goto fail;
  785. status = ixgbe_clock_out_i2c_byte(hw, data);
  786. if (status != 0)
  787. goto fail;
  788. status = ixgbe_get_i2c_ack(hw);
  789. if (status != 0)
  790. goto fail;
  791. ixgbe_i2c_stop(hw);
  792. break;
  793. fail:
  794. ixgbe_i2c_bus_clear(hw);
  795. retry++;
  796. if (retry < max_retry)
  797. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  798. else
  799. hw_dbg(hw, "I2C byte write error.\n");
  800. } while (retry < max_retry);
  801. return status;
  802. }
  803. /**
  804. * ixgbe_i2c_start - Sets I2C start condition
  805. * @hw: pointer to hardware structure
  806. *
  807. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  808. **/
  809. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  810. {
  811. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  812. /* Start condition must begin with data and clock high */
  813. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  814. ixgbe_raise_i2c_clk(hw, &i2cctl);
  815. /* Setup time for start condition (4.7us) */
  816. udelay(IXGBE_I2C_T_SU_STA);
  817. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  818. /* Hold time for start condition (4us) */
  819. udelay(IXGBE_I2C_T_HD_STA);
  820. ixgbe_lower_i2c_clk(hw, &i2cctl);
  821. /* Minimum low period of clock is 4.7 us */
  822. udelay(IXGBE_I2C_T_LOW);
  823. }
  824. /**
  825. * ixgbe_i2c_stop - Sets I2C stop condition
  826. * @hw: pointer to hardware structure
  827. *
  828. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  829. **/
  830. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  831. {
  832. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  833. /* Stop condition must begin with data low and clock high */
  834. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  835. ixgbe_raise_i2c_clk(hw, &i2cctl);
  836. /* Setup time for stop condition (4us) */
  837. udelay(IXGBE_I2C_T_SU_STO);
  838. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  839. /* bus free time between stop and start (4.7us)*/
  840. udelay(IXGBE_I2C_T_BUF);
  841. }
  842. /**
  843. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  844. * @hw: pointer to hardware structure
  845. * @data: data byte to clock in
  846. *
  847. * Clocks in one byte data via I2C data/clock
  848. **/
  849. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  850. {
  851. s32 status = 0;
  852. s32 i;
  853. bool bit = 0;
  854. for (i = 7; i >= 0; i--) {
  855. status = ixgbe_clock_in_i2c_bit(hw, &bit);
  856. *data |= bit << i;
  857. if (status != 0)
  858. break;
  859. }
  860. return status;
  861. }
  862. /**
  863. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  864. * @hw: pointer to hardware structure
  865. * @data: data byte clocked out
  866. *
  867. * Clocks out one byte data via I2C data/clock
  868. **/
  869. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  870. {
  871. s32 status = 0;
  872. s32 i;
  873. u32 i2cctl;
  874. bool bit = 0;
  875. for (i = 7; i >= 0; i--) {
  876. bit = (data >> i) & 0x1;
  877. status = ixgbe_clock_out_i2c_bit(hw, bit);
  878. if (status != 0)
  879. break;
  880. }
  881. /* Release SDA line (set high) */
  882. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  883. i2cctl |= IXGBE_I2C_DATA_OUT;
  884. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  885. return status;
  886. }
  887. /**
  888. * ixgbe_get_i2c_ack - Polls for I2C ACK
  889. * @hw: pointer to hardware structure
  890. *
  891. * Clocks in/out one bit via I2C data/clock
  892. **/
  893. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  894. {
  895. s32 status;
  896. u32 i = 0;
  897. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  898. u32 timeout = 10;
  899. bool ack = 1;
  900. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  901. if (status != 0)
  902. goto out;
  903. /* Minimum high period of clock is 4us */
  904. udelay(IXGBE_I2C_T_HIGH);
  905. /* Poll for ACK. Note that ACK in I2C spec is
  906. * transition from 1 to 0 */
  907. for (i = 0; i < timeout; i++) {
  908. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  909. ack = ixgbe_get_i2c_data(&i2cctl);
  910. udelay(1);
  911. if (ack == 0)
  912. break;
  913. }
  914. if (ack == 1) {
  915. hw_dbg(hw, "I2C ack was not received.\n");
  916. status = IXGBE_ERR_I2C;
  917. }
  918. ixgbe_lower_i2c_clk(hw, &i2cctl);
  919. /* Minimum low period of clock is 4.7 us */
  920. udelay(IXGBE_I2C_T_LOW);
  921. out:
  922. return status;
  923. }
  924. /**
  925. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  926. * @hw: pointer to hardware structure
  927. * @data: read data value
  928. *
  929. * Clocks in one bit via I2C data/clock
  930. **/
  931. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  932. {
  933. s32 status;
  934. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  935. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  936. /* Minimum high period of clock is 4us */
  937. udelay(IXGBE_I2C_T_HIGH);
  938. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  939. *data = ixgbe_get_i2c_data(&i2cctl);
  940. ixgbe_lower_i2c_clk(hw, &i2cctl);
  941. /* Minimum low period of clock is 4.7 us */
  942. udelay(IXGBE_I2C_T_LOW);
  943. return status;
  944. }
  945. /**
  946. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  947. * @hw: pointer to hardware structure
  948. * @data: data value to write
  949. *
  950. * Clocks out one bit via I2C data/clock
  951. **/
  952. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  953. {
  954. s32 status;
  955. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  956. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  957. if (status == 0) {
  958. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  959. /* Minimum high period of clock is 4us */
  960. udelay(IXGBE_I2C_T_HIGH);
  961. ixgbe_lower_i2c_clk(hw, &i2cctl);
  962. /* Minimum low period of clock is 4.7 us.
  963. * This also takes care of the data hold time.
  964. */
  965. udelay(IXGBE_I2C_T_LOW);
  966. } else {
  967. status = IXGBE_ERR_I2C;
  968. hw_dbg(hw, "I2C data was not set to %X\n", data);
  969. }
  970. return status;
  971. }
  972. /**
  973. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  974. * @hw: pointer to hardware structure
  975. * @i2cctl: Current value of I2CCTL register
  976. *
  977. * Raises the I2C clock line '0'->'1'
  978. **/
  979. static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  980. {
  981. s32 status = 0;
  982. *i2cctl |= IXGBE_I2C_CLK_OUT;
  983. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  984. /* SCL rise time (1000ns) */
  985. udelay(IXGBE_I2C_T_RISE);
  986. return status;
  987. }
  988. /**
  989. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  990. * @hw: pointer to hardware structure
  991. * @i2cctl: Current value of I2CCTL register
  992. *
  993. * Lowers the I2C clock line '1'->'0'
  994. **/
  995. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  996. {
  997. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  998. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  999. /* SCL fall time (300ns) */
  1000. udelay(IXGBE_I2C_T_FALL);
  1001. }
  1002. /**
  1003. * ixgbe_set_i2c_data - Sets the I2C data bit
  1004. * @hw: pointer to hardware structure
  1005. * @i2cctl: Current value of I2CCTL register
  1006. * @data: I2C data value (0 or 1) to set
  1007. *
  1008. * Sets the I2C data bit
  1009. **/
  1010. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  1011. {
  1012. s32 status = 0;
  1013. if (data)
  1014. *i2cctl |= IXGBE_I2C_DATA_OUT;
  1015. else
  1016. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  1017. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1018. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  1019. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  1020. /* Verify data was set correctly */
  1021. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1022. if (data != ixgbe_get_i2c_data(i2cctl)) {
  1023. status = IXGBE_ERR_I2C;
  1024. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  1025. }
  1026. return status;
  1027. }
  1028. /**
  1029. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1030. * @hw: pointer to hardware structure
  1031. * @i2cctl: Current value of I2CCTL register
  1032. *
  1033. * Returns the I2C data bit value
  1034. **/
  1035. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1036. {
  1037. bool data;
  1038. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1039. data = 1;
  1040. else
  1041. data = 0;
  1042. return data;
  1043. }
  1044. /**
  1045. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1046. * @hw: pointer to hardware structure
  1047. *
  1048. * Clears the I2C bus by sending nine clock pulses.
  1049. * Used when data line is stuck low.
  1050. **/
  1051. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1052. {
  1053. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1054. u32 i;
  1055. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1056. for (i = 0; i < 9; i++) {
  1057. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1058. /* Min high period of clock is 4us */
  1059. udelay(IXGBE_I2C_T_HIGH);
  1060. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1061. /* Min low period of clock is 4.7us*/
  1062. udelay(IXGBE_I2C_T_LOW);
  1063. }
  1064. /* Put the i2c bus back to default state */
  1065. ixgbe_i2c_stop(hw);
  1066. }
  1067. /**
  1068. * ixgbe_check_phy_link_tnx - Determine link and speed status
  1069. * @hw: pointer to hardware structure
  1070. *
  1071. * Reads the VS1 register to determine if link is up and the current speed for
  1072. * the PHY.
  1073. **/
  1074. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  1075. bool *link_up)
  1076. {
  1077. s32 status = 0;
  1078. u32 time_out;
  1079. u32 max_time_out = 10;
  1080. u16 phy_link = 0;
  1081. u16 phy_speed = 0;
  1082. u16 phy_data = 0;
  1083. /* Initialize speed and link to default case */
  1084. *link_up = false;
  1085. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  1086. /*
  1087. * Check current speed and link status of the PHY register.
  1088. * This is a vendor specific register and may have to
  1089. * be changed for other copper PHYs.
  1090. */
  1091. for (time_out = 0; time_out < max_time_out; time_out++) {
  1092. udelay(10);
  1093. status = hw->phy.ops.read_reg(hw,
  1094. IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
  1095. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1096. &phy_data);
  1097. phy_link = phy_data &
  1098. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  1099. phy_speed = phy_data &
  1100. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  1101. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  1102. *link_up = true;
  1103. if (phy_speed ==
  1104. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  1105. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1106. break;
  1107. }
  1108. }
  1109. return status;
  1110. }
  1111. /**
  1112. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  1113. * @hw: pointer to hardware structure
  1114. * @firmware_version: pointer to the PHY Firmware Version
  1115. **/
  1116. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  1117. u16 *firmware_version)
  1118. {
  1119. s32 status = 0;
  1120. status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
  1121. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1122. firmware_version);
  1123. return status;
  1124. }