ixgbe_phy.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2008 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 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr);
  26. static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
  27. static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
  28. /**
  29. * ixgbe_identify_phy_generic - Get physical layer module
  30. * @hw: pointer to hardware structure
  31. *
  32. * Determines the physical layer module found on the current adapter.
  33. **/
  34. s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
  35. {
  36. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  37. u32 phy_addr;
  38. if (hw->phy.type == ixgbe_phy_unknown) {
  39. for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
  40. if (ixgbe_validate_phy_addr(hw, phy_addr)) {
  41. hw->phy.addr = phy_addr;
  42. ixgbe_get_phy_id(hw);
  43. hw->phy.type =
  44. ixgbe_get_phy_type_from_id(hw->phy.id);
  45. status = 0;
  46. break;
  47. }
  48. }
  49. } else {
  50. status = 0;
  51. }
  52. return status;
  53. }
  54. /**
  55. * ixgbe_validate_phy_addr - Determines phy address is valid
  56. * @hw: pointer to hardware structure
  57. *
  58. **/
  59. static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
  60. {
  61. u16 phy_id = 0;
  62. bool valid = false;
  63. hw->phy.addr = phy_addr;
  64. hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
  65. IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
  66. if (phy_id != 0xFFFF && phy_id != 0x0)
  67. valid = true;
  68. return valid;
  69. }
  70. /**
  71. * ixgbe_get_phy_id - Get the phy type
  72. * @hw: pointer to hardware structure
  73. *
  74. **/
  75. static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
  76. {
  77. u32 status;
  78. u16 phy_id_high = 0;
  79. u16 phy_id_low = 0;
  80. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
  81. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  82. &phy_id_high);
  83. if (status == 0) {
  84. hw->phy.id = (u32)(phy_id_high << 16);
  85. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
  86. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  87. &phy_id_low);
  88. hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
  89. hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
  90. }
  91. return status;
  92. }
  93. /**
  94. * ixgbe_get_phy_type_from_id - Get the phy type
  95. * @hw: pointer to hardware structure
  96. *
  97. **/
  98. static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
  99. {
  100. enum ixgbe_phy_type phy_type;
  101. switch (phy_id) {
  102. case TN1010_PHY_ID:
  103. phy_type = ixgbe_phy_tn;
  104. break;
  105. case QT2022_PHY_ID:
  106. phy_type = ixgbe_phy_qt;
  107. break;
  108. case ATH_PHY_ID:
  109. phy_type = ixgbe_phy_nl;
  110. break;
  111. default:
  112. phy_type = ixgbe_phy_unknown;
  113. break;
  114. }
  115. return phy_type;
  116. }
  117. /**
  118. * ixgbe_reset_phy_generic - Performs a PHY reset
  119. * @hw: pointer to hardware structure
  120. **/
  121. s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
  122. {
  123. /*
  124. * Perform soft PHY reset to the PHY_XS.
  125. * This will cause a soft reset to the PHY
  126. */
  127. return hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
  128. IXGBE_MDIO_PHY_XS_DEV_TYPE,
  129. IXGBE_MDIO_PHY_XS_RESET);
  130. }
  131. /**
  132. * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
  133. * @hw: pointer to hardware structure
  134. * @reg_addr: 32 bit address of PHY register to read
  135. * @phy_data: Pointer to read data from PHY register
  136. **/
  137. s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  138. u32 device_type, u16 *phy_data)
  139. {
  140. u32 command;
  141. u32 i;
  142. u32 data;
  143. s32 status = 0;
  144. u16 gssr;
  145. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  146. gssr = IXGBE_GSSR_PHY1_SM;
  147. else
  148. gssr = IXGBE_GSSR_PHY0_SM;
  149. if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
  150. status = IXGBE_ERR_SWFW_SYNC;
  151. if (status == 0) {
  152. /* Setup and write the address cycle command */
  153. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  154. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  155. (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  156. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  157. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  158. /*
  159. * Check every 10 usec to see if the address cycle completed.
  160. * The MDI Command bit will clear when the operation is
  161. * complete
  162. */
  163. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  164. udelay(10);
  165. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  166. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  167. break;
  168. }
  169. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  170. hw_dbg(hw, "PHY address command did not complete.\n");
  171. status = IXGBE_ERR_PHY;
  172. }
  173. if (status == 0) {
  174. /*
  175. * Address cycle complete, setup and write the read
  176. * command
  177. */
  178. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  179. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  180. (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  181. (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
  182. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  183. /*
  184. * Check every 10 usec to see if the address cycle
  185. * completed. The MDI Command bit will clear when the
  186. * operation is complete
  187. */
  188. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  189. udelay(10);
  190. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  191. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  192. break;
  193. }
  194. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  195. hw_dbg(hw, "PHY read command didn't complete\n");
  196. status = IXGBE_ERR_PHY;
  197. } else {
  198. /*
  199. * Read operation is complete. Get the data
  200. * from MSRWD
  201. */
  202. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  203. data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
  204. *phy_data = (u16)(data);
  205. }
  206. }
  207. ixgbe_release_swfw_sync(hw, gssr);
  208. }
  209. return status;
  210. }
  211. /**
  212. * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
  213. * @hw: pointer to hardware structure
  214. * @reg_addr: 32 bit PHY register to write
  215. * @device_type: 5 bit device type
  216. * @phy_data: Data to write to the PHY register
  217. **/
  218. s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  219. u32 device_type, u16 phy_data)
  220. {
  221. u32 command;
  222. u32 i;
  223. s32 status = 0;
  224. u16 gssr;
  225. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  226. gssr = IXGBE_GSSR_PHY1_SM;
  227. else
  228. gssr = IXGBE_GSSR_PHY0_SM;
  229. if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
  230. status = IXGBE_ERR_SWFW_SYNC;
  231. if (status == 0) {
  232. /* Put the data in the MDI single read and write data register*/
  233. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
  234. /* Setup and write the address cycle command */
  235. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  236. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  237. (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  238. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  239. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  240. /*
  241. * Check every 10 usec to see if the address cycle completed.
  242. * The MDI Command bit will clear when the operation is
  243. * complete
  244. */
  245. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  246. udelay(10);
  247. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  248. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  249. break;
  250. }
  251. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  252. hw_dbg(hw, "PHY address cmd didn't complete\n");
  253. status = IXGBE_ERR_PHY;
  254. }
  255. if (status == 0) {
  256. /*
  257. * Address cycle complete, setup and write the write
  258. * command
  259. */
  260. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  261. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  262. (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  263. (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
  264. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  265. /*
  266. * Check every 10 usec to see if the address cycle
  267. * completed. The MDI Command bit will clear when the
  268. * operation is complete
  269. */
  270. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  271. udelay(10);
  272. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  273. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  274. break;
  275. }
  276. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  277. hw_dbg(hw, "PHY address cmd didn't complete\n");
  278. status = IXGBE_ERR_PHY;
  279. }
  280. }
  281. ixgbe_release_swfw_sync(hw, gssr);
  282. }
  283. return status;
  284. }
  285. /**
  286. * ixgbe_setup_phy_link_generic - Set and restart autoneg
  287. * @hw: pointer to hardware structure
  288. *
  289. * Restart autonegotiation and PHY and waits for completion.
  290. **/
  291. s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
  292. {
  293. s32 status = IXGBE_NOT_IMPLEMENTED;
  294. u32 time_out;
  295. u32 max_time_out = 10;
  296. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  297. /*
  298. * Set advertisement settings in PHY based on autoneg_advertised
  299. * settings. If autoneg_advertised = 0, then advertise default values
  300. * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
  301. * for a 1G.
  302. */
  303. hw->phy.ops.read_reg(hw, IXGBE_MII_SPEED_SELECTION_REG,
  304. IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
  305. if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
  306. autoneg_reg &= 0xEFFF; /* 0 in bit 12 is 1G operation */
  307. else
  308. autoneg_reg |= 0x1000; /* 1 in bit 12 is 10G/1G operation */
  309. hw->phy.ops.write_reg(hw, IXGBE_MII_SPEED_SELECTION_REG,
  310. IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
  311. /* Restart PHY autonegotiation and wait for completion */
  312. hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
  313. IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
  314. autoneg_reg |= IXGBE_MII_RESTART;
  315. hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
  316. IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
  317. /* Wait for autonegotiation to finish */
  318. for (time_out = 0; time_out < max_time_out; time_out++) {
  319. udelay(10);
  320. /* Restart PHY autonegotiation and wait for completion */
  321. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
  322. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  323. &autoneg_reg);
  324. autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
  325. if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE) {
  326. status = 0;
  327. break;
  328. }
  329. }
  330. if (time_out == max_time_out)
  331. status = IXGBE_ERR_LINK_SETUP;
  332. return status;
  333. }
  334. /**
  335. * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
  336. * @hw: pointer to hardware structure
  337. * @speed: new link speed
  338. * @autoneg: true if autonegotiation enabled
  339. **/
  340. s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  341. ixgbe_link_speed speed,
  342. bool autoneg,
  343. bool autoneg_wait_to_complete)
  344. {
  345. /*
  346. * Clear autoneg_advertised and set new values based on input link
  347. * speed.
  348. */
  349. hw->phy.autoneg_advertised = 0;
  350. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  351. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  352. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  353. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  354. /* Setup link based on the new speed settings */
  355. hw->phy.ops.setup_link(hw);
  356. return 0;
  357. }
  358. /**
  359. * ixgbe_reset_phy_nl - Performs a PHY reset
  360. * @hw: pointer to hardware structure
  361. **/
  362. s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  363. {
  364. u16 phy_offset, control, eword, edata, block_crc;
  365. bool end_data = false;
  366. u16 list_offset, data_offset;
  367. u16 phy_data = 0;
  368. s32 ret_val = 0;
  369. u32 i;
  370. hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
  371. IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
  372. /* reset the PHY and poll for completion */
  373. hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
  374. IXGBE_MDIO_PHY_XS_DEV_TYPE,
  375. (phy_data | IXGBE_MDIO_PHY_XS_RESET));
  376. for (i = 0; i < 100; i++) {
  377. hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
  378. IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
  379. if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
  380. break;
  381. msleep(10);
  382. }
  383. if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
  384. hw_dbg(hw, "PHY reset did not complete.\n");
  385. ret_val = IXGBE_ERR_PHY;
  386. goto out;
  387. }
  388. /* Get init offsets */
  389. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  390. &data_offset);
  391. if (ret_val != 0)
  392. goto out;
  393. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  394. data_offset++;
  395. while (!end_data) {
  396. /*
  397. * Read control word from PHY init contents offset
  398. */
  399. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  400. control = (eword & IXGBE_CONTROL_MASK_NL) >>
  401. IXGBE_CONTROL_SHIFT_NL;
  402. edata = eword & IXGBE_DATA_MASK_NL;
  403. switch (control) {
  404. case IXGBE_DELAY_NL:
  405. data_offset++;
  406. hw_dbg(hw, "DELAY: %d MS\n", edata);
  407. msleep(edata);
  408. break;
  409. case IXGBE_DATA_NL:
  410. hw_dbg(hw, "DATA: \n");
  411. data_offset++;
  412. hw->eeprom.ops.read(hw, data_offset++,
  413. &phy_offset);
  414. for (i = 0; i < edata; i++) {
  415. hw->eeprom.ops.read(hw, data_offset, &eword);
  416. hw->phy.ops.write_reg(hw, phy_offset,
  417. IXGBE_TWINAX_DEV, eword);
  418. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  419. phy_offset);
  420. data_offset++;
  421. phy_offset++;
  422. }
  423. break;
  424. case IXGBE_CONTROL_NL:
  425. data_offset++;
  426. hw_dbg(hw, "CONTROL: \n");
  427. if (edata == IXGBE_CONTROL_EOL_NL) {
  428. hw_dbg(hw, "EOL\n");
  429. end_data = true;
  430. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  431. hw_dbg(hw, "SOL\n");
  432. } else {
  433. hw_dbg(hw, "Bad control value\n");
  434. ret_val = IXGBE_ERR_PHY;
  435. goto out;
  436. }
  437. break;
  438. default:
  439. hw_dbg(hw, "Bad control type\n");
  440. ret_val = IXGBE_ERR_PHY;
  441. goto out;
  442. }
  443. }
  444. out:
  445. return ret_val;
  446. }
  447. /**
  448. * ixgbe_identify_sfp_module_generic - Identifies SFP module and assigns
  449. * the PHY type.
  450. * @hw: pointer to hardware structure
  451. *
  452. * Searches for and indentifies the SFP module. Assings appropriate PHY type.
  453. **/
  454. s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  455. {
  456. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  457. u32 vendor_oui = 0;
  458. u8 identifier = 0;
  459. u8 comp_codes_1g = 0;
  460. u8 comp_codes_10g = 0;
  461. u8 oui_bytes[4] = {0, 0, 0, 0};
  462. u8 transmission_media = 0;
  463. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
  464. &identifier);
  465. if (status == IXGBE_ERR_SFP_NOT_PRESENT) {
  466. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  467. goto out;
  468. }
  469. if (identifier == IXGBE_SFF_IDENTIFIER_SFP) {
  470. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES,
  471. &comp_codes_1g);
  472. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES,
  473. &comp_codes_10g);
  474. hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_TRANSMISSION_MEDIA,
  475. &transmission_media);
  476. /* ID Module
  477. * =========
  478. * 0 SFP_DA_CU
  479. * 1 SFP_SR
  480. * 2 SFP_LR
  481. */
  482. if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
  483. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  484. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  485. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  486. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  487. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  488. else
  489. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  490. /* Determine PHY vendor */
  491. if (hw->phy.type == ixgbe_phy_unknown) {
  492. hw->phy.id = identifier;
  493. hw->phy.ops.read_i2c_eeprom(hw,
  494. IXGBE_SFF_VENDOR_OUI_BYTE0,
  495. &oui_bytes[0]);
  496. hw->phy.ops.read_i2c_eeprom(hw,
  497. IXGBE_SFF_VENDOR_OUI_BYTE1,
  498. &oui_bytes[1]);
  499. hw->phy.ops.read_i2c_eeprom(hw,
  500. IXGBE_SFF_VENDOR_OUI_BYTE2,
  501. &oui_bytes[2]);
  502. vendor_oui =
  503. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  504. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  505. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  506. switch (vendor_oui) {
  507. case IXGBE_SFF_VENDOR_OUI_TYCO:
  508. if (transmission_media &
  509. IXGBE_SFF_TWIN_AX_CAPABLE)
  510. hw->phy.type = ixgbe_phy_tw_tyco;
  511. break;
  512. case IXGBE_SFF_VENDOR_OUI_FTL:
  513. hw->phy.type = ixgbe_phy_sfp_ftl;
  514. break;
  515. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  516. hw->phy.type = ixgbe_phy_sfp_avago;
  517. break;
  518. default:
  519. if (transmission_media &
  520. IXGBE_SFF_TWIN_AX_CAPABLE)
  521. hw->phy.type = ixgbe_phy_tw_unknown;
  522. else
  523. hw->phy.type = ixgbe_phy_sfp_unknown;
  524. break;
  525. }
  526. }
  527. status = 0;
  528. }
  529. out:
  530. return status;
  531. }
  532. /**
  533. * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
  534. * if it supports a given SFP+ module type, if so it returns the offsets to the
  535. * phy init sequence block.
  536. * @hw: pointer to hardware structure
  537. * @list_offset: offset to the SFP ID list
  538. * @data_offset: offset to the SFP data block
  539. **/
  540. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  541. u16 *list_offset,
  542. u16 *data_offset)
  543. {
  544. u16 sfp_id;
  545. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  546. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  547. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  548. return IXGBE_ERR_SFP_NOT_PRESENT;
  549. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  550. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  551. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  552. /* Read offset to PHY init contents */
  553. hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
  554. if ((!*list_offset) || (*list_offset == 0xFFFF))
  555. return IXGBE_ERR_PHY;
  556. /* Shift offset to first ID word */
  557. (*list_offset)++;
  558. /*
  559. * Find the matching SFP ID in the EEPROM
  560. * and program the init sequence
  561. */
  562. hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
  563. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  564. if (sfp_id == hw->phy.sfp_type) {
  565. (*list_offset)++;
  566. hw->eeprom.ops.read(hw, *list_offset, data_offset);
  567. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  568. hw_dbg(hw, "SFP+ module not supported\n");
  569. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  570. } else {
  571. break;
  572. }
  573. } else {
  574. (*list_offset) += 2;
  575. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  576. return IXGBE_ERR_PHY;
  577. }
  578. }
  579. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  580. hw_dbg(hw, "No matching SFP+ module found\n");
  581. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  582. }
  583. return 0;
  584. }
  585. /**
  586. * ixgbe_check_phy_link_tnx - Determine link and speed status
  587. * @hw: pointer to hardware structure
  588. *
  589. * Reads the VS1 register to determine if link is up and the current speed for
  590. * the PHY.
  591. **/
  592. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  593. bool *link_up)
  594. {
  595. s32 status = 0;
  596. u32 time_out;
  597. u32 max_time_out = 10;
  598. u16 phy_link = 0;
  599. u16 phy_speed = 0;
  600. u16 phy_data = 0;
  601. /* Initialize speed and link to default case */
  602. *link_up = false;
  603. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  604. /*
  605. * Check current speed and link status of the PHY register.
  606. * This is a vendor specific register and may have to
  607. * be changed for other copper PHYs.
  608. */
  609. for (time_out = 0; time_out < max_time_out; time_out++) {
  610. udelay(10);
  611. status = hw->phy.ops.read_reg(hw,
  612. IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
  613. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  614. &phy_data);
  615. phy_link = phy_data &
  616. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  617. phy_speed = phy_data &
  618. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  619. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  620. *link_up = true;
  621. if (phy_speed ==
  622. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  623. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  624. break;
  625. }
  626. }
  627. return status;
  628. }
  629. /**
  630. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  631. * @hw: pointer to hardware structure
  632. * @firmware_version: pointer to the PHY Firmware Version
  633. **/
  634. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  635. u16 *firmware_version)
  636. {
  637. s32 status = 0;
  638. status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
  639. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  640. firmware_version);
  641. return status;
  642. }