ixgbe_phy.c 34 KB

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