ixgbe_phy.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  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 transmission_media = 0;
  450. u16 enforce_sfp = 0;
  451. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
  452. &identifier);
  453. if (status == IXGBE_ERR_SFP_NOT_PRESENT) {
  454. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  455. goto out;
  456. }
  457. if (identifier == IXGBE_SFF_IDENTIFIER_SFP) {
  458. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES,
  459. &comp_codes_1g);
  460. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES,
  461. &comp_codes_10g);
  462. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_TRANSMISSION_MEDIA,
  463. &transmission_media);
  464. /* ID Module
  465. * =========
  466. * 0 SFP_DA_CU
  467. * 1 SFP_SR
  468. * 2 SFP_LR
  469. * 3 SFP_DA_CORE0 - 82599-specific
  470. * 4 SFP_DA_CORE1 - 82599-specific
  471. * 5 SFP_SR/LR_CORE0 - 82599-specific
  472. * 6 SFP_SR/LR_CORE1 - 82599-specific
  473. */
  474. if (hw->mac.type == ixgbe_mac_82598EB) {
  475. if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
  476. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  477. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  478. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  479. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  480. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  481. else
  482. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  483. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  484. if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
  485. if (hw->bus.lan_id == 0)
  486. hw->phy.sfp_type =
  487. ixgbe_sfp_type_da_cu_core0;
  488. else
  489. hw->phy.sfp_type =
  490. ixgbe_sfp_type_da_cu_core1;
  491. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  492. if (hw->bus.lan_id == 0)
  493. hw->phy.sfp_type =
  494. ixgbe_sfp_type_srlr_core0;
  495. else
  496. hw->phy.sfp_type =
  497. ixgbe_sfp_type_srlr_core1;
  498. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  499. if (hw->bus.lan_id == 0)
  500. hw->phy.sfp_type =
  501. ixgbe_sfp_type_srlr_core0;
  502. else
  503. hw->phy.sfp_type =
  504. ixgbe_sfp_type_srlr_core1;
  505. else
  506. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  507. }
  508. if (hw->phy.sfp_type != stored_sfp_type)
  509. hw->phy.sfp_setup_needed = true;
  510. /* Determine if the SFP+ PHY is dual speed or not. */
  511. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  512. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  513. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  514. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  515. hw->phy.multispeed_fiber = true;
  516. /* Determine PHY vendor */
  517. if (hw->phy.type != ixgbe_phy_nl) {
  518. hw->phy.id = identifier;
  519. hw->phy.ops.read_i2c_eeprom(hw,
  520. IXGBE_SFF_VENDOR_OUI_BYTE0,
  521. &oui_bytes[0]);
  522. hw->phy.ops.read_i2c_eeprom(hw,
  523. IXGBE_SFF_VENDOR_OUI_BYTE1,
  524. &oui_bytes[1]);
  525. hw->phy.ops.read_i2c_eeprom(hw,
  526. IXGBE_SFF_VENDOR_OUI_BYTE2,
  527. &oui_bytes[2]);
  528. vendor_oui =
  529. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  530. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  531. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  532. switch (vendor_oui) {
  533. case IXGBE_SFF_VENDOR_OUI_TYCO:
  534. if (transmission_media &
  535. IXGBE_SFF_TWIN_AX_CAPABLE)
  536. hw->phy.type = ixgbe_phy_tw_tyco;
  537. break;
  538. case IXGBE_SFF_VENDOR_OUI_FTL:
  539. hw->phy.type = ixgbe_phy_sfp_ftl;
  540. break;
  541. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  542. hw->phy.type = ixgbe_phy_sfp_avago;
  543. break;
  544. case IXGBE_SFF_VENDOR_OUI_INTEL:
  545. hw->phy.type = ixgbe_phy_sfp_intel;
  546. break;
  547. default:
  548. if (transmission_media &
  549. IXGBE_SFF_TWIN_AX_CAPABLE)
  550. hw->phy.type = ixgbe_phy_tw_unknown;
  551. else
  552. hw->phy.type = ixgbe_phy_sfp_unknown;
  553. break;
  554. }
  555. }
  556. /* All DA cables are supported */
  557. if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE) {
  558. status = 0;
  559. goto out;
  560. }
  561. /* 1G SFP modules are not supported */
  562. if (comp_codes_10g == 0) {
  563. hw->phy.type = ixgbe_phy_sfp_unsupported;
  564. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  565. goto out;
  566. }
  567. /* Anything else 82598-based is supported */
  568. if (hw->mac.type == ixgbe_mac_82598EB) {
  569. status = 0;
  570. goto out;
  571. }
  572. /* This is guaranteed to be 82599, no need to check for NULL */
  573. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  574. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
  575. /* Make sure we're a supported PHY type */
  576. if (hw->phy.type == ixgbe_phy_sfp_intel) {
  577. status = 0;
  578. } else {
  579. hw_dbg(hw, "SFP+ module not supported\n");
  580. hw->phy.type = ixgbe_phy_sfp_unsupported;
  581. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  582. }
  583. } else {
  584. status = 0;
  585. }
  586. }
  587. out:
  588. return status;
  589. }
  590. /**
  591. * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
  592. * if it supports a given SFP+ module type, if so it returns the offsets to the
  593. * phy init sequence block.
  594. * @hw: pointer to hardware structure
  595. * @list_offset: offset to the SFP ID list
  596. * @data_offset: offset to the SFP data block
  597. **/
  598. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  599. u16 *list_offset,
  600. u16 *data_offset)
  601. {
  602. u16 sfp_id;
  603. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  604. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  605. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  606. return IXGBE_ERR_SFP_NOT_PRESENT;
  607. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  608. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  609. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  610. /* Read offset to PHY init contents */
  611. hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
  612. if ((!*list_offset) || (*list_offset == 0xFFFF))
  613. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  614. /* Shift offset to first ID word */
  615. (*list_offset)++;
  616. /*
  617. * Find the matching SFP ID in the EEPROM
  618. * and program the init sequence
  619. */
  620. hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
  621. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  622. if (sfp_id == hw->phy.sfp_type) {
  623. (*list_offset)++;
  624. hw->eeprom.ops.read(hw, *list_offset, data_offset);
  625. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  626. hw_dbg(hw, "SFP+ module not supported\n");
  627. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  628. } else {
  629. break;
  630. }
  631. } else {
  632. (*list_offset) += 2;
  633. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  634. return IXGBE_ERR_PHY;
  635. }
  636. }
  637. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  638. hw_dbg(hw, "No matching SFP+ module found\n");
  639. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  640. }
  641. return 0;
  642. }
  643. /**
  644. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  645. * @hw: pointer to hardware structure
  646. * @byte_offset: EEPROM byte offset to read
  647. * @eeprom_data: value read
  648. *
  649. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  650. **/
  651. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  652. u8 *eeprom_data)
  653. {
  654. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  655. IXGBE_I2C_EEPROM_DEV_ADDR,
  656. eeprom_data);
  657. }
  658. /**
  659. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  660. * @hw: pointer to hardware structure
  661. * @byte_offset: EEPROM byte offset to write
  662. * @eeprom_data: value to write
  663. *
  664. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  665. **/
  666. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  667. u8 eeprom_data)
  668. {
  669. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  670. IXGBE_I2C_EEPROM_DEV_ADDR,
  671. eeprom_data);
  672. }
  673. /**
  674. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  675. * @hw: pointer to hardware structure
  676. * @byte_offset: byte offset to read
  677. * @data: value read
  678. *
  679. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  680. * a specified deivce address.
  681. **/
  682. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  683. u8 dev_addr, u8 *data)
  684. {
  685. s32 status = 0;
  686. u32 max_retry = 1;
  687. u32 retry = 0;
  688. bool nack = 1;
  689. do {
  690. ixgbe_i2c_start(hw);
  691. /* Device Address and write indication */
  692. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  693. if (status != 0)
  694. goto fail;
  695. status = ixgbe_get_i2c_ack(hw);
  696. if (status != 0)
  697. goto fail;
  698. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  699. if (status != 0)
  700. goto fail;
  701. status = ixgbe_get_i2c_ack(hw);
  702. if (status != 0)
  703. goto fail;
  704. ixgbe_i2c_start(hw);
  705. /* Device Address and read indication */
  706. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  707. if (status != 0)
  708. goto fail;
  709. status = ixgbe_get_i2c_ack(hw);
  710. if (status != 0)
  711. goto fail;
  712. status = ixgbe_clock_in_i2c_byte(hw, data);
  713. if (status != 0)
  714. goto fail;
  715. status = ixgbe_clock_out_i2c_bit(hw, nack);
  716. if (status != 0)
  717. goto fail;
  718. ixgbe_i2c_stop(hw);
  719. break;
  720. fail:
  721. ixgbe_i2c_bus_clear(hw);
  722. retry++;
  723. if (retry < max_retry)
  724. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  725. else
  726. hw_dbg(hw, "I2C byte read error.\n");
  727. } while (retry < max_retry);
  728. return status;
  729. }
  730. /**
  731. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  732. * @hw: pointer to hardware structure
  733. * @byte_offset: byte offset to write
  734. * @data: value to write
  735. *
  736. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  737. * a specified device address.
  738. **/
  739. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  740. u8 dev_addr, u8 data)
  741. {
  742. s32 status = 0;
  743. u32 max_retry = 1;
  744. u32 retry = 0;
  745. do {
  746. ixgbe_i2c_start(hw);
  747. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  748. if (status != 0)
  749. goto fail;
  750. status = ixgbe_get_i2c_ack(hw);
  751. if (status != 0)
  752. goto fail;
  753. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  754. if (status != 0)
  755. goto fail;
  756. status = ixgbe_get_i2c_ack(hw);
  757. if (status != 0)
  758. goto fail;
  759. status = ixgbe_clock_out_i2c_byte(hw, data);
  760. if (status != 0)
  761. goto fail;
  762. status = ixgbe_get_i2c_ack(hw);
  763. if (status != 0)
  764. goto fail;
  765. ixgbe_i2c_stop(hw);
  766. break;
  767. fail:
  768. ixgbe_i2c_bus_clear(hw);
  769. retry++;
  770. if (retry < max_retry)
  771. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  772. else
  773. hw_dbg(hw, "I2C byte write error.\n");
  774. } while (retry < max_retry);
  775. return status;
  776. }
  777. /**
  778. * ixgbe_i2c_start - Sets I2C start condition
  779. * @hw: pointer to hardware structure
  780. *
  781. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  782. **/
  783. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  784. {
  785. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  786. /* Start condition must begin with data and clock high */
  787. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  788. ixgbe_raise_i2c_clk(hw, &i2cctl);
  789. /* Setup time for start condition (4.7us) */
  790. udelay(IXGBE_I2C_T_SU_STA);
  791. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  792. /* Hold time for start condition (4us) */
  793. udelay(IXGBE_I2C_T_HD_STA);
  794. ixgbe_lower_i2c_clk(hw, &i2cctl);
  795. /* Minimum low period of clock is 4.7 us */
  796. udelay(IXGBE_I2C_T_LOW);
  797. }
  798. /**
  799. * ixgbe_i2c_stop - Sets I2C stop condition
  800. * @hw: pointer to hardware structure
  801. *
  802. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  803. **/
  804. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  805. {
  806. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  807. /* Stop condition must begin with data low and clock high */
  808. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  809. ixgbe_raise_i2c_clk(hw, &i2cctl);
  810. /* Setup time for stop condition (4us) */
  811. udelay(IXGBE_I2C_T_SU_STO);
  812. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  813. /* bus free time between stop and start (4.7us)*/
  814. udelay(IXGBE_I2C_T_BUF);
  815. }
  816. /**
  817. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  818. * @hw: pointer to hardware structure
  819. * @data: data byte to clock in
  820. *
  821. * Clocks in one byte data via I2C data/clock
  822. **/
  823. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  824. {
  825. s32 status = 0;
  826. s32 i;
  827. bool bit = 0;
  828. for (i = 7; i >= 0; i--) {
  829. status = ixgbe_clock_in_i2c_bit(hw, &bit);
  830. *data |= bit << i;
  831. if (status != 0)
  832. break;
  833. }
  834. return status;
  835. }
  836. /**
  837. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  838. * @hw: pointer to hardware structure
  839. * @data: data byte clocked out
  840. *
  841. * Clocks out one byte data via I2C data/clock
  842. **/
  843. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  844. {
  845. s32 status = 0;
  846. s32 i;
  847. u32 i2cctl;
  848. bool bit = 0;
  849. for (i = 7; i >= 0; i--) {
  850. bit = (data >> i) & 0x1;
  851. status = ixgbe_clock_out_i2c_bit(hw, bit);
  852. if (status != 0)
  853. break;
  854. }
  855. /* Release SDA line (set high) */
  856. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  857. i2cctl |= IXGBE_I2C_DATA_OUT;
  858. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  859. return status;
  860. }
  861. /**
  862. * ixgbe_get_i2c_ack - Polls for I2C ACK
  863. * @hw: pointer to hardware structure
  864. *
  865. * Clocks in/out one bit via I2C data/clock
  866. **/
  867. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  868. {
  869. s32 status;
  870. u32 i = 0;
  871. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  872. u32 timeout = 10;
  873. bool ack = 1;
  874. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  875. if (status != 0)
  876. goto out;
  877. /* Minimum high period of clock is 4us */
  878. udelay(IXGBE_I2C_T_HIGH);
  879. /* Poll for ACK. Note that ACK in I2C spec is
  880. * transition from 1 to 0 */
  881. for (i = 0; i < timeout; i++) {
  882. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  883. ack = ixgbe_get_i2c_data(&i2cctl);
  884. udelay(1);
  885. if (ack == 0)
  886. break;
  887. }
  888. if (ack == 1) {
  889. hw_dbg(hw, "I2C ack was not received.\n");
  890. status = IXGBE_ERR_I2C;
  891. }
  892. ixgbe_lower_i2c_clk(hw, &i2cctl);
  893. /* Minimum low period of clock is 4.7 us */
  894. udelay(IXGBE_I2C_T_LOW);
  895. out:
  896. return status;
  897. }
  898. /**
  899. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  900. * @hw: pointer to hardware structure
  901. * @data: read data value
  902. *
  903. * Clocks in one bit via I2C data/clock
  904. **/
  905. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  906. {
  907. s32 status;
  908. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  909. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  910. /* Minimum high period of clock is 4us */
  911. udelay(IXGBE_I2C_T_HIGH);
  912. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  913. *data = ixgbe_get_i2c_data(&i2cctl);
  914. ixgbe_lower_i2c_clk(hw, &i2cctl);
  915. /* Minimum low period of clock is 4.7 us */
  916. udelay(IXGBE_I2C_T_LOW);
  917. return status;
  918. }
  919. /**
  920. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  921. * @hw: pointer to hardware structure
  922. * @data: data value to write
  923. *
  924. * Clocks out one bit via I2C data/clock
  925. **/
  926. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  927. {
  928. s32 status;
  929. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  930. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  931. if (status == 0) {
  932. status = ixgbe_raise_i2c_clk(hw, &i2cctl);
  933. /* Minimum high period of clock is 4us */
  934. udelay(IXGBE_I2C_T_HIGH);
  935. ixgbe_lower_i2c_clk(hw, &i2cctl);
  936. /* Minimum low period of clock is 4.7 us.
  937. * This also takes care of the data hold time.
  938. */
  939. udelay(IXGBE_I2C_T_LOW);
  940. } else {
  941. status = IXGBE_ERR_I2C;
  942. hw_dbg(hw, "I2C data was not set to %X\n", data);
  943. }
  944. return status;
  945. }
  946. /**
  947. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  948. * @hw: pointer to hardware structure
  949. * @i2cctl: Current value of I2CCTL register
  950. *
  951. * Raises the I2C clock line '0'->'1'
  952. **/
  953. static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  954. {
  955. s32 status = 0;
  956. *i2cctl |= IXGBE_I2C_CLK_OUT;
  957. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  958. /* SCL rise time (1000ns) */
  959. udelay(IXGBE_I2C_T_RISE);
  960. return status;
  961. }
  962. /**
  963. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  964. * @hw: pointer to hardware structure
  965. * @i2cctl: Current value of I2CCTL register
  966. *
  967. * Lowers the I2C clock line '1'->'0'
  968. **/
  969. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  970. {
  971. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  972. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  973. /* SCL fall time (300ns) */
  974. udelay(IXGBE_I2C_T_FALL);
  975. }
  976. /**
  977. * ixgbe_set_i2c_data - Sets the I2C data bit
  978. * @hw: pointer to hardware structure
  979. * @i2cctl: Current value of I2CCTL register
  980. * @data: I2C data value (0 or 1) to set
  981. *
  982. * Sets the I2C data bit
  983. **/
  984. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  985. {
  986. s32 status = 0;
  987. if (data)
  988. *i2cctl |= IXGBE_I2C_DATA_OUT;
  989. else
  990. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  991. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  992. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  993. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  994. /* Verify data was set correctly */
  995. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  996. if (data != ixgbe_get_i2c_data(i2cctl)) {
  997. status = IXGBE_ERR_I2C;
  998. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  999. }
  1000. return status;
  1001. }
  1002. /**
  1003. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1004. * @hw: pointer to hardware structure
  1005. * @i2cctl: Current value of I2CCTL register
  1006. *
  1007. * Returns the I2C data bit value
  1008. **/
  1009. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1010. {
  1011. bool data;
  1012. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1013. data = 1;
  1014. else
  1015. data = 0;
  1016. return data;
  1017. }
  1018. /**
  1019. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1020. * @hw: pointer to hardware structure
  1021. *
  1022. * Clears the I2C bus by sending nine clock pulses.
  1023. * Used when data line is stuck low.
  1024. **/
  1025. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1026. {
  1027. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1028. u32 i;
  1029. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1030. for (i = 0; i < 9; i++) {
  1031. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1032. /* Min high period of clock is 4us */
  1033. udelay(IXGBE_I2C_T_HIGH);
  1034. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1035. /* Min low period of clock is 4.7us*/
  1036. udelay(IXGBE_I2C_T_LOW);
  1037. }
  1038. /* Put the i2c bus back to default state */
  1039. ixgbe_i2c_stop(hw);
  1040. }
  1041. /**
  1042. * ixgbe_check_phy_link_tnx - Determine link and speed status
  1043. * @hw: pointer to hardware structure
  1044. *
  1045. * Reads the VS1 register to determine if link is up and the current speed for
  1046. * the PHY.
  1047. **/
  1048. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  1049. bool *link_up)
  1050. {
  1051. s32 status = 0;
  1052. u32 time_out;
  1053. u32 max_time_out = 10;
  1054. u16 phy_link = 0;
  1055. u16 phy_speed = 0;
  1056. u16 phy_data = 0;
  1057. /* Initialize speed and link to default case */
  1058. *link_up = false;
  1059. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  1060. /*
  1061. * Check current speed and link status of the PHY register.
  1062. * This is a vendor specific register and may have to
  1063. * be changed for other copper PHYs.
  1064. */
  1065. for (time_out = 0; time_out < max_time_out; time_out++) {
  1066. udelay(10);
  1067. status = hw->phy.ops.read_reg(hw,
  1068. IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
  1069. MDIO_MMD_VEND1,
  1070. &phy_data);
  1071. phy_link = phy_data &
  1072. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  1073. phy_speed = phy_data &
  1074. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  1075. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  1076. *link_up = true;
  1077. if (phy_speed ==
  1078. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  1079. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1080. break;
  1081. }
  1082. }
  1083. return status;
  1084. }
  1085. /**
  1086. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  1087. * @hw: pointer to hardware structure
  1088. * @firmware_version: pointer to the PHY Firmware Version
  1089. **/
  1090. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  1091. u16 *firmware_version)
  1092. {
  1093. s32 status = 0;
  1094. status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1,
  1095. firmware_version);
  1096. return status;
  1097. }