ixgbe_phy.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 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 void 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. static s32 ixgbe_identify_qsfp_module_generic(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. u16 ext_ability = 0;
  51. if (hw->phy.type == ixgbe_phy_unknown) {
  52. for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
  53. hw->phy.mdio.prtad = phy_addr;
  54. if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
  55. ixgbe_get_phy_id(hw);
  56. hw->phy.type =
  57. ixgbe_get_phy_type_from_id(hw->phy.id);
  58. if (hw->phy.type == ixgbe_phy_unknown) {
  59. hw->phy.ops.read_reg(hw,
  60. MDIO_PMA_EXTABLE,
  61. MDIO_MMD_PMAPMD,
  62. &ext_ability);
  63. if (ext_ability &
  64. (MDIO_PMA_EXTABLE_10GBT |
  65. MDIO_PMA_EXTABLE_1000BT))
  66. hw->phy.type =
  67. ixgbe_phy_cu_unknown;
  68. else
  69. hw->phy.type =
  70. ixgbe_phy_generic;
  71. }
  72. status = 0;
  73. break;
  74. }
  75. }
  76. /* clear value if nothing found */
  77. if (status != 0)
  78. hw->phy.mdio.prtad = 0;
  79. } else {
  80. status = 0;
  81. }
  82. return status;
  83. }
  84. /**
  85. * ixgbe_get_phy_id - Get the phy type
  86. * @hw: pointer to hardware structure
  87. *
  88. **/
  89. static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
  90. {
  91. u32 status;
  92. u16 phy_id_high = 0;
  93. u16 phy_id_low = 0;
  94. status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
  95. &phy_id_high);
  96. if (status == 0) {
  97. hw->phy.id = (u32)(phy_id_high << 16);
  98. status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
  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 X540_PHY_ID:
  118. phy_type = ixgbe_phy_aq;
  119. break;
  120. case QT2022_PHY_ID:
  121. phy_type = ixgbe_phy_qt;
  122. break;
  123. case ATH_PHY_ID:
  124. phy_type = ixgbe_phy_nl;
  125. break;
  126. default:
  127. phy_type = ixgbe_phy_unknown;
  128. break;
  129. }
  130. return phy_type;
  131. }
  132. /**
  133. * ixgbe_reset_phy_generic - Performs a PHY reset
  134. * @hw: pointer to hardware structure
  135. **/
  136. s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
  137. {
  138. u32 i;
  139. u16 ctrl = 0;
  140. s32 status = 0;
  141. if (hw->phy.type == ixgbe_phy_unknown)
  142. status = ixgbe_identify_phy_generic(hw);
  143. if (status != 0 || hw->phy.type == ixgbe_phy_none)
  144. goto out;
  145. /* Don't reset PHY if it's shut down due to overtemp. */
  146. if (!hw->phy.reset_if_overtemp &&
  147. (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
  148. goto out;
  149. /*
  150. * Perform soft PHY reset to the PHY_XS.
  151. * This will cause a soft reset to the PHY
  152. */
  153. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  154. MDIO_MMD_PHYXS,
  155. MDIO_CTRL1_RESET);
  156. /*
  157. * Poll for reset bit to self-clear indicating reset is complete.
  158. * Some PHYs could take up to 3 seconds to complete and need about
  159. * 1.7 usec delay after the reset is complete.
  160. */
  161. for (i = 0; i < 30; i++) {
  162. msleep(100);
  163. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  164. MDIO_MMD_PHYXS, &ctrl);
  165. if (!(ctrl & MDIO_CTRL1_RESET)) {
  166. udelay(2);
  167. break;
  168. }
  169. }
  170. if (ctrl & MDIO_CTRL1_RESET) {
  171. status = IXGBE_ERR_RESET_FAILED;
  172. hw_dbg(hw, "PHY reset polling failed to complete.\n");
  173. }
  174. out:
  175. return status;
  176. }
  177. /**
  178. * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
  179. * the SWFW lock
  180. * @hw: pointer to hardware structure
  181. * @reg_addr: 32 bit address of PHY register to read
  182. * @phy_data: Pointer to read data from PHY register
  183. **/
  184. s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
  185. u16 *phy_data)
  186. {
  187. u32 i, data, command;
  188. /* Setup and write the address cycle command */
  189. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  190. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  191. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  192. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  193. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  194. /* Check every 10 usec to see if the address cycle completed.
  195. * The MDI Command bit will clear when the operation is
  196. * complete
  197. */
  198. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  199. udelay(10);
  200. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  201. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  202. break;
  203. }
  204. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  205. hw_dbg(hw, "PHY address command did not complete.\n");
  206. return IXGBE_ERR_PHY;
  207. }
  208. /* Address cycle complete, setup and write the read
  209. * command
  210. */
  211. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  212. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  213. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  214. (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
  215. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  216. /* Check every 10 usec to see if the address cycle
  217. * completed. The MDI Command bit will clear when the
  218. * operation is complete
  219. */
  220. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  221. udelay(10);
  222. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  223. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  224. break;
  225. }
  226. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  227. hw_dbg(hw, "PHY read command didn't complete\n");
  228. return IXGBE_ERR_PHY;
  229. }
  230. /* Read operation is complete. Get the data
  231. * from MSRWD
  232. */
  233. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  234. data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
  235. *phy_data = (u16)(data);
  236. return 0;
  237. }
  238. /**
  239. * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
  240. * using the SWFW lock - this function is needed in most cases
  241. * @hw: pointer to hardware structure
  242. * @reg_addr: 32 bit address of PHY register to read
  243. * @phy_data: Pointer to read data from PHY register
  244. **/
  245. s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  246. u32 device_type, u16 *phy_data)
  247. {
  248. s32 status;
  249. u16 gssr;
  250. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  251. gssr = IXGBE_GSSR_PHY1_SM;
  252. else
  253. gssr = IXGBE_GSSR_PHY0_SM;
  254. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
  255. status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
  256. phy_data);
  257. hw->mac.ops.release_swfw_sync(hw, gssr);
  258. } else {
  259. status = IXGBE_ERR_SWFW_SYNC;
  260. }
  261. return status;
  262. }
  263. /**
  264. * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
  265. * without SWFW lock
  266. * @hw: pointer to hardware structure
  267. * @reg_addr: 32 bit PHY register to write
  268. * @device_type: 5 bit device type
  269. * @phy_data: Data to write to the PHY register
  270. **/
  271. s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
  272. u32 device_type, u16 phy_data)
  273. {
  274. u32 i, command;
  275. /* Put the data in the MDI single read and write data register*/
  276. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
  277. /* Setup and write the address cycle command */
  278. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  279. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  280. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  281. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  282. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  283. /*
  284. * Check every 10 usec to see if the address cycle completed.
  285. * The MDI Command bit will clear when the operation is
  286. * complete
  287. */
  288. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  289. udelay(10);
  290. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  291. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  292. break;
  293. }
  294. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  295. hw_dbg(hw, "PHY address cmd didn't complete\n");
  296. return IXGBE_ERR_PHY;
  297. }
  298. /*
  299. * Address cycle complete, setup and write the write
  300. * command
  301. */
  302. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  303. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  304. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  305. (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
  306. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  307. /* Check every 10 usec to see if the address cycle
  308. * completed. The MDI Command bit will clear when the
  309. * operation is complete
  310. */
  311. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  312. udelay(10);
  313. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  314. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  315. break;
  316. }
  317. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  318. hw_dbg(hw, "PHY write cmd didn't complete\n");
  319. return IXGBE_ERR_PHY;
  320. }
  321. return 0;
  322. }
  323. /**
  324. * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
  325. * using SWFW lock- this function is needed in most cases
  326. * @hw: pointer to hardware structure
  327. * @reg_addr: 32 bit PHY register to write
  328. * @device_type: 5 bit device type
  329. * @phy_data: Data to write to the PHY register
  330. **/
  331. s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  332. u32 device_type, u16 phy_data)
  333. {
  334. s32 status;
  335. u16 gssr;
  336. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  337. gssr = IXGBE_GSSR_PHY1_SM;
  338. else
  339. gssr = IXGBE_GSSR_PHY0_SM;
  340. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
  341. status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
  342. phy_data);
  343. hw->mac.ops.release_swfw_sync(hw, gssr);
  344. } else {
  345. status = IXGBE_ERR_SWFW_SYNC;
  346. }
  347. return status;
  348. }
  349. /**
  350. * ixgbe_setup_phy_link_generic - Set and restart autoneg
  351. * @hw: pointer to hardware structure
  352. *
  353. * Restart autonegotiation and PHY and waits for completion.
  354. **/
  355. s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
  356. {
  357. s32 status = 0;
  358. u32 time_out;
  359. u32 max_time_out = 10;
  360. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  361. bool autoneg = false;
  362. ixgbe_link_speed speed;
  363. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  364. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  365. /* Set or unset auto-negotiation 10G advertisement */
  366. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  367. MDIO_MMD_AN,
  368. &autoneg_reg);
  369. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  370. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  371. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  372. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  373. MDIO_MMD_AN,
  374. autoneg_reg);
  375. }
  376. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  377. /* Set or unset auto-negotiation 1G advertisement */
  378. hw->phy.ops.read_reg(hw,
  379. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  380. MDIO_MMD_AN,
  381. &autoneg_reg);
  382. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
  383. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  384. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
  385. hw->phy.ops.write_reg(hw,
  386. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  387. MDIO_MMD_AN,
  388. autoneg_reg);
  389. }
  390. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  391. /* Set or unset auto-negotiation 100M advertisement */
  392. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  393. MDIO_MMD_AN,
  394. &autoneg_reg);
  395. autoneg_reg &= ~(ADVERTISE_100FULL |
  396. ADVERTISE_100HALF);
  397. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  398. autoneg_reg |= ADVERTISE_100FULL;
  399. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  400. MDIO_MMD_AN,
  401. autoneg_reg);
  402. }
  403. /* Restart PHY autonegotiation and wait for completion */
  404. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  405. MDIO_MMD_AN, &autoneg_reg);
  406. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  407. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  408. MDIO_MMD_AN, autoneg_reg);
  409. /* Wait for autonegotiation to finish */
  410. for (time_out = 0; time_out < max_time_out; time_out++) {
  411. udelay(10);
  412. /* Restart PHY autonegotiation and wait for completion */
  413. status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
  414. MDIO_MMD_AN,
  415. &autoneg_reg);
  416. autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
  417. if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
  418. break;
  419. }
  420. }
  421. if (time_out == max_time_out) {
  422. status = IXGBE_ERR_LINK_SETUP;
  423. hw_dbg(hw, "ixgbe_setup_phy_link_generic: time out");
  424. }
  425. return status;
  426. }
  427. /**
  428. * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
  429. * @hw: pointer to hardware structure
  430. * @speed: new link speed
  431. **/
  432. s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  433. ixgbe_link_speed speed,
  434. bool autoneg_wait_to_complete)
  435. {
  436. /*
  437. * Clear autoneg_advertised and set new values based on input link
  438. * speed.
  439. */
  440. hw->phy.autoneg_advertised = 0;
  441. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  442. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  443. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  444. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  445. if (speed & IXGBE_LINK_SPEED_100_FULL)
  446. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  447. /* Setup link based on the new speed settings */
  448. hw->phy.ops.setup_link(hw);
  449. return 0;
  450. }
  451. /**
  452. * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
  453. * @hw: pointer to hardware structure
  454. * @speed: pointer to link speed
  455. * @autoneg: boolean auto-negotiation value
  456. *
  457. * Determines the link capabilities by reading the AUTOC register.
  458. */
  459. s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
  460. ixgbe_link_speed *speed,
  461. bool *autoneg)
  462. {
  463. s32 status = IXGBE_ERR_LINK_SETUP;
  464. u16 speed_ability;
  465. *speed = 0;
  466. *autoneg = true;
  467. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  468. &speed_ability);
  469. if (status == 0) {
  470. if (speed_ability & MDIO_SPEED_10G)
  471. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  472. if (speed_ability & MDIO_PMA_SPEED_1000)
  473. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  474. if (speed_ability & MDIO_PMA_SPEED_100)
  475. *speed |= IXGBE_LINK_SPEED_100_FULL;
  476. }
  477. return status;
  478. }
  479. /**
  480. * ixgbe_check_phy_link_tnx - Determine link and speed status
  481. * @hw: pointer to hardware structure
  482. *
  483. * Reads the VS1 register to determine if link is up and the current speed for
  484. * the PHY.
  485. **/
  486. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  487. bool *link_up)
  488. {
  489. s32 status = 0;
  490. u32 time_out;
  491. u32 max_time_out = 10;
  492. u16 phy_link = 0;
  493. u16 phy_speed = 0;
  494. u16 phy_data = 0;
  495. /* Initialize speed and link to default case */
  496. *link_up = false;
  497. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  498. /*
  499. * Check current speed and link status of the PHY register.
  500. * This is a vendor specific register and may have to
  501. * be changed for other copper PHYs.
  502. */
  503. for (time_out = 0; time_out < max_time_out; time_out++) {
  504. udelay(10);
  505. status = hw->phy.ops.read_reg(hw,
  506. MDIO_STAT1,
  507. MDIO_MMD_VEND1,
  508. &phy_data);
  509. phy_link = phy_data &
  510. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  511. phy_speed = phy_data &
  512. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  513. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  514. *link_up = true;
  515. if (phy_speed ==
  516. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  517. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  518. break;
  519. }
  520. }
  521. return status;
  522. }
  523. /**
  524. * ixgbe_setup_phy_link_tnx - Set and restart autoneg
  525. * @hw: pointer to hardware structure
  526. *
  527. * Restart autonegotiation and PHY and waits for completion.
  528. **/
  529. s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
  530. {
  531. s32 status = 0;
  532. u32 time_out;
  533. u32 max_time_out = 10;
  534. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  535. bool autoneg = false;
  536. ixgbe_link_speed speed;
  537. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  538. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  539. /* Set or unset auto-negotiation 10G advertisement */
  540. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  541. MDIO_MMD_AN,
  542. &autoneg_reg);
  543. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  544. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  545. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  546. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  547. MDIO_MMD_AN,
  548. autoneg_reg);
  549. }
  550. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  551. /* Set or unset auto-negotiation 1G advertisement */
  552. hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  553. MDIO_MMD_AN,
  554. &autoneg_reg);
  555. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  556. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  557. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  558. hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  559. MDIO_MMD_AN,
  560. autoneg_reg);
  561. }
  562. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  563. /* Set or unset auto-negotiation 100M advertisement */
  564. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  565. MDIO_MMD_AN,
  566. &autoneg_reg);
  567. autoneg_reg &= ~(ADVERTISE_100FULL |
  568. ADVERTISE_100HALF);
  569. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  570. autoneg_reg |= ADVERTISE_100FULL;
  571. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  572. MDIO_MMD_AN,
  573. autoneg_reg);
  574. }
  575. /* Restart PHY autonegotiation and wait for completion */
  576. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  577. MDIO_MMD_AN, &autoneg_reg);
  578. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  579. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  580. MDIO_MMD_AN, autoneg_reg);
  581. /* Wait for autonegotiation to finish */
  582. for (time_out = 0; time_out < max_time_out; time_out++) {
  583. udelay(10);
  584. /* Restart PHY autonegotiation and wait for completion */
  585. status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
  586. MDIO_MMD_AN,
  587. &autoneg_reg);
  588. autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
  589. if (autoneg_reg == MDIO_AN_STAT1_COMPLETE)
  590. break;
  591. }
  592. if (time_out == max_time_out) {
  593. status = IXGBE_ERR_LINK_SETUP;
  594. hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out");
  595. }
  596. return status;
  597. }
  598. /**
  599. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  600. * @hw: pointer to hardware structure
  601. * @firmware_version: pointer to the PHY Firmware Version
  602. **/
  603. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  604. u16 *firmware_version)
  605. {
  606. s32 status = 0;
  607. status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
  608. MDIO_MMD_VEND1,
  609. firmware_version);
  610. return status;
  611. }
  612. /**
  613. * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
  614. * @hw: pointer to hardware structure
  615. * @firmware_version: pointer to the PHY Firmware Version
  616. **/
  617. s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
  618. u16 *firmware_version)
  619. {
  620. s32 status = 0;
  621. status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
  622. MDIO_MMD_VEND1,
  623. firmware_version);
  624. return status;
  625. }
  626. /**
  627. * ixgbe_reset_phy_nl - Performs a PHY reset
  628. * @hw: pointer to hardware structure
  629. **/
  630. s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  631. {
  632. u16 phy_offset, control, eword, edata, block_crc;
  633. bool end_data = false;
  634. u16 list_offset, data_offset;
  635. u16 phy_data = 0;
  636. s32 ret_val = 0;
  637. u32 i;
  638. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
  639. /* reset the PHY and poll for completion */
  640. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  641. (phy_data | MDIO_CTRL1_RESET));
  642. for (i = 0; i < 100; i++) {
  643. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  644. &phy_data);
  645. if ((phy_data & MDIO_CTRL1_RESET) == 0)
  646. break;
  647. usleep_range(10000, 20000);
  648. }
  649. if ((phy_data & MDIO_CTRL1_RESET) != 0) {
  650. hw_dbg(hw, "PHY reset did not complete.\n");
  651. ret_val = IXGBE_ERR_PHY;
  652. goto out;
  653. }
  654. /* Get init offsets */
  655. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  656. &data_offset);
  657. if (ret_val != 0)
  658. goto out;
  659. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  660. data_offset++;
  661. while (!end_data) {
  662. /*
  663. * Read control word from PHY init contents offset
  664. */
  665. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  666. if (ret_val)
  667. goto err_eeprom;
  668. control = (eword & IXGBE_CONTROL_MASK_NL) >>
  669. IXGBE_CONTROL_SHIFT_NL;
  670. edata = eword & IXGBE_DATA_MASK_NL;
  671. switch (control) {
  672. case IXGBE_DELAY_NL:
  673. data_offset++;
  674. hw_dbg(hw, "DELAY: %d MS\n", edata);
  675. usleep_range(edata * 1000, edata * 2000);
  676. break;
  677. case IXGBE_DATA_NL:
  678. hw_dbg(hw, "DATA:\n");
  679. data_offset++;
  680. ret_val = hw->eeprom.ops.read(hw, data_offset++,
  681. &phy_offset);
  682. if (ret_val)
  683. goto err_eeprom;
  684. for (i = 0; i < edata; i++) {
  685. ret_val = hw->eeprom.ops.read(hw, data_offset,
  686. &eword);
  687. if (ret_val)
  688. goto err_eeprom;
  689. hw->phy.ops.write_reg(hw, phy_offset,
  690. MDIO_MMD_PMAPMD, eword);
  691. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  692. phy_offset);
  693. data_offset++;
  694. phy_offset++;
  695. }
  696. break;
  697. case IXGBE_CONTROL_NL:
  698. data_offset++;
  699. hw_dbg(hw, "CONTROL:\n");
  700. if (edata == IXGBE_CONTROL_EOL_NL) {
  701. hw_dbg(hw, "EOL\n");
  702. end_data = true;
  703. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  704. hw_dbg(hw, "SOL\n");
  705. } else {
  706. hw_dbg(hw, "Bad control value\n");
  707. ret_val = IXGBE_ERR_PHY;
  708. goto out;
  709. }
  710. break;
  711. default:
  712. hw_dbg(hw, "Bad control type\n");
  713. ret_val = IXGBE_ERR_PHY;
  714. goto out;
  715. }
  716. }
  717. out:
  718. return ret_val;
  719. err_eeprom:
  720. hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
  721. return IXGBE_ERR_PHY;
  722. }
  723. /**
  724. * ixgbe_identify_module_generic - Identifies module type
  725. * @hw: pointer to hardware structure
  726. *
  727. * Determines HW type and calls appropriate function.
  728. **/
  729. s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
  730. {
  731. s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
  732. switch (hw->mac.ops.get_media_type(hw)) {
  733. case ixgbe_media_type_fiber:
  734. status = ixgbe_identify_sfp_module_generic(hw);
  735. break;
  736. case ixgbe_media_type_fiber_qsfp:
  737. status = ixgbe_identify_qsfp_module_generic(hw);
  738. break;
  739. default:
  740. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  741. status = IXGBE_ERR_SFP_NOT_PRESENT;
  742. break;
  743. }
  744. return status;
  745. }
  746. /**
  747. * ixgbe_identify_sfp_module_generic - Identifies SFP modules
  748. * @hw: pointer to hardware structure
  749. *
  750. * Searches for and identifies the SFP module and assigns appropriate PHY type.
  751. **/
  752. s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  753. {
  754. struct ixgbe_adapter *adapter = hw->back;
  755. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  756. u32 vendor_oui = 0;
  757. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  758. u8 identifier = 0;
  759. u8 comp_codes_1g = 0;
  760. u8 comp_codes_10g = 0;
  761. u8 oui_bytes[3] = {0, 0, 0};
  762. u8 cable_tech = 0;
  763. u8 cable_spec = 0;
  764. u16 enforce_sfp = 0;
  765. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
  766. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  767. status = IXGBE_ERR_SFP_NOT_PRESENT;
  768. goto out;
  769. }
  770. status = hw->phy.ops.read_i2c_eeprom(hw,
  771. IXGBE_SFF_IDENTIFIER,
  772. &identifier);
  773. if (status != 0)
  774. goto err_read_i2c_eeprom;
  775. /* LAN ID is needed for sfp_type determination */
  776. hw->mac.ops.set_lan_id(hw);
  777. if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
  778. hw->phy.type = ixgbe_phy_sfp_unsupported;
  779. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  780. } else {
  781. status = hw->phy.ops.read_i2c_eeprom(hw,
  782. IXGBE_SFF_1GBE_COMP_CODES,
  783. &comp_codes_1g);
  784. if (status != 0)
  785. goto err_read_i2c_eeprom;
  786. status = hw->phy.ops.read_i2c_eeprom(hw,
  787. IXGBE_SFF_10GBE_COMP_CODES,
  788. &comp_codes_10g);
  789. if (status != 0)
  790. goto err_read_i2c_eeprom;
  791. status = hw->phy.ops.read_i2c_eeprom(hw,
  792. IXGBE_SFF_CABLE_TECHNOLOGY,
  793. &cable_tech);
  794. if (status != 0)
  795. goto err_read_i2c_eeprom;
  796. /* ID Module
  797. * =========
  798. * 0 SFP_DA_CU
  799. * 1 SFP_SR
  800. * 2 SFP_LR
  801. * 3 SFP_DA_CORE0 - 82599-specific
  802. * 4 SFP_DA_CORE1 - 82599-specific
  803. * 5 SFP_SR/LR_CORE0 - 82599-specific
  804. * 6 SFP_SR/LR_CORE1 - 82599-specific
  805. * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
  806. * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
  807. * 9 SFP_1g_cu_CORE0 - 82599-specific
  808. * 10 SFP_1g_cu_CORE1 - 82599-specific
  809. * 11 SFP_1g_sx_CORE0 - 82599-specific
  810. * 12 SFP_1g_sx_CORE1 - 82599-specific
  811. */
  812. if (hw->mac.type == ixgbe_mac_82598EB) {
  813. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  814. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  815. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  816. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  817. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  818. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  819. else
  820. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  821. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  822. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
  823. if (hw->bus.lan_id == 0)
  824. hw->phy.sfp_type =
  825. ixgbe_sfp_type_da_cu_core0;
  826. else
  827. hw->phy.sfp_type =
  828. ixgbe_sfp_type_da_cu_core1;
  829. } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
  830. hw->phy.ops.read_i2c_eeprom(
  831. hw, IXGBE_SFF_CABLE_SPEC_COMP,
  832. &cable_spec);
  833. if (cable_spec &
  834. IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
  835. if (hw->bus.lan_id == 0)
  836. hw->phy.sfp_type =
  837. ixgbe_sfp_type_da_act_lmt_core0;
  838. else
  839. hw->phy.sfp_type =
  840. ixgbe_sfp_type_da_act_lmt_core1;
  841. } else {
  842. hw->phy.sfp_type =
  843. ixgbe_sfp_type_unknown;
  844. }
  845. } else if (comp_codes_10g &
  846. (IXGBE_SFF_10GBASESR_CAPABLE |
  847. IXGBE_SFF_10GBASELR_CAPABLE)) {
  848. if (hw->bus.lan_id == 0)
  849. hw->phy.sfp_type =
  850. ixgbe_sfp_type_srlr_core0;
  851. else
  852. hw->phy.sfp_type =
  853. ixgbe_sfp_type_srlr_core1;
  854. } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
  855. if (hw->bus.lan_id == 0)
  856. hw->phy.sfp_type =
  857. ixgbe_sfp_type_1g_cu_core0;
  858. else
  859. hw->phy.sfp_type =
  860. ixgbe_sfp_type_1g_cu_core1;
  861. } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
  862. if (hw->bus.lan_id == 0)
  863. hw->phy.sfp_type =
  864. ixgbe_sfp_type_1g_sx_core0;
  865. else
  866. hw->phy.sfp_type =
  867. ixgbe_sfp_type_1g_sx_core1;
  868. } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
  869. if (hw->bus.lan_id == 0)
  870. hw->phy.sfp_type =
  871. ixgbe_sfp_type_1g_lx_core0;
  872. else
  873. hw->phy.sfp_type =
  874. ixgbe_sfp_type_1g_lx_core1;
  875. } else {
  876. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  877. }
  878. }
  879. if (hw->phy.sfp_type != stored_sfp_type)
  880. hw->phy.sfp_setup_needed = true;
  881. /* Determine if the SFP+ PHY is dual speed or not. */
  882. hw->phy.multispeed_fiber = false;
  883. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  884. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  885. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  886. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  887. hw->phy.multispeed_fiber = true;
  888. /* Determine PHY vendor */
  889. if (hw->phy.type != ixgbe_phy_nl) {
  890. hw->phy.id = identifier;
  891. status = hw->phy.ops.read_i2c_eeprom(hw,
  892. IXGBE_SFF_VENDOR_OUI_BYTE0,
  893. &oui_bytes[0]);
  894. if (status != 0)
  895. goto err_read_i2c_eeprom;
  896. status = hw->phy.ops.read_i2c_eeprom(hw,
  897. IXGBE_SFF_VENDOR_OUI_BYTE1,
  898. &oui_bytes[1]);
  899. if (status != 0)
  900. goto err_read_i2c_eeprom;
  901. status = hw->phy.ops.read_i2c_eeprom(hw,
  902. IXGBE_SFF_VENDOR_OUI_BYTE2,
  903. &oui_bytes[2]);
  904. if (status != 0)
  905. goto err_read_i2c_eeprom;
  906. vendor_oui =
  907. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  908. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  909. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  910. switch (vendor_oui) {
  911. case IXGBE_SFF_VENDOR_OUI_TYCO:
  912. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  913. hw->phy.type =
  914. ixgbe_phy_sfp_passive_tyco;
  915. break;
  916. case IXGBE_SFF_VENDOR_OUI_FTL:
  917. if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  918. hw->phy.type = ixgbe_phy_sfp_ftl_active;
  919. else
  920. hw->phy.type = ixgbe_phy_sfp_ftl;
  921. break;
  922. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  923. hw->phy.type = ixgbe_phy_sfp_avago;
  924. break;
  925. case IXGBE_SFF_VENDOR_OUI_INTEL:
  926. hw->phy.type = ixgbe_phy_sfp_intel;
  927. break;
  928. default:
  929. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  930. hw->phy.type =
  931. ixgbe_phy_sfp_passive_unknown;
  932. else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  933. hw->phy.type =
  934. ixgbe_phy_sfp_active_unknown;
  935. else
  936. hw->phy.type = ixgbe_phy_sfp_unknown;
  937. break;
  938. }
  939. }
  940. /* Allow any DA cable vendor */
  941. if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
  942. IXGBE_SFF_DA_ACTIVE_CABLE)) {
  943. status = 0;
  944. goto out;
  945. }
  946. /* Verify supported 1G SFP modules */
  947. if (comp_codes_10g == 0 &&
  948. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  949. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  950. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  951. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  952. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  953. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
  954. hw->phy.type = ixgbe_phy_sfp_unsupported;
  955. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  956. goto out;
  957. }
  958. /* Anything else 82598-based is supported */
  959. if (hw->mac.type == ixgbe_mac_82598EB) {
  960. status = 0;
  961. goto out;
  962. }
  963. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  964. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
  965. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  966. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  967. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  968. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  969. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  970. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
  971. /* Make sure we're a supported PHY type */
  972. if (hw->phy.type == ixgbe_phy_sfp_intel) {
  973. status = 0;
  974. } else {
  975. if (hw->allow_unsupported_sfp) {
  976. e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.");
  977. status = 0;
  978. } else {
  979. hw_dbg(hw,
  980. "SFP+ module not supported\n");
  981. hw->phy.type =
  982. ixgbe_phy_sfp_unsupported;
  983. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  984. }
  985. }
  986. } else {
  987. status = 0;
  988. }
  989. }
  990. out:
  991. return status;
  992. err_read_i2c_eeprom:
  993. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  994. if (hw->phy.type != ixgbe_phy_nl) {
  995. hw->phy.id = 0;
  996. hw->phy.type = ixgbe_phy_unknown;
  997. }
  998. return IXGBE_ERR_SFP_NOT_PRESENT;
  999. }
  1000. /**
  1001. * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
  1002. * @hw: pointer to hardware structure
  1003. *
  1004. * Searches for and identifies the QSFP module and assigns appropriate PHY type
  1005. **/
  1006. static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
  1007. {
  1008. struct ixgbe_adapter *adapter = hw->back;
  1009. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  1010. u32 vendor_oui = 0;
  1011. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  1012. u8 identifier = 0;
  1013. u8 comp_codes_1g = 0;
  1014. u8 comp_codes_10g = 0;
  1015. u8 oui_bytes[3] = {0, 0, 0};
  1016. u16 enforce_sfp = 0;
  1017. u8 connector = 0;
  1018. u8 cable_length = 0;
  1019. u8 device_tech = 0;
  1020. bool active_cable = false;
  1021. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
  1022. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1023. status = IXGBE_ERR_SFP_NOT_PRESENT;
  1024. goto out;
  1025. }
  1026. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
  1027. &identifier);
  1028. if (status != 0)
  1029. goto err_read_i2c_eeprom;
  1030. if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
  1031. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1032. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  1033. goto out;
  1034. }
  1035. hw->phy.id = identifier;
  1036. /* LAN ID is needed for sfp_type determination */
  1037. hw->mac.ops.set_lan_id(hw);
  1038. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
  1039. &comp_codes_10g);
  1040. if (status != 0)
  1041. goto err_read_i2c_eeprom;
  1042. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
  1043. &comp_codes_1g);
  1044. if (status != 0)
  1045. goto err_read_i2c_eeprom;
  1046. if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
  1047. hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
  1048. if (hw->bus.lan_id == 0)
  1049. hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
  1050. else
  1051. hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
  1052. } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
  1053. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1054. if (hw->bus.lan_id == 0)
  1055. hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
  1056. else
  1057. hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
  1058. } else {
  1059. if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
  1060. active_cable = true;
  1061. if (!active_cable) {
  1062. /* check for active DA cables that pre-date
  1063. * SFF-8436 v3.6
  1064. */
  1065. hw->phy.ops.read_i2c_eeprom(hw,
  1066. IXGBE_SFF_QSFP_CONNECTOR,
  1067. &connector);
  1068. hw->phy.ops.read_i2c_eeprom(hw,
  1069. IXGBE_SFF_QSFP_CABLE_LENGTH,
  1070. &cable_length);
  1071. hw->phy.ops.read_i2c_eeprom(hw,
  1072. IXGBE_SFF_QSFP_DEVICE_TECH,
  1073. &device_tech);
  1074. if ((connector ==
  1075. IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
  1076. (cable_length > 0) &&
  1077. ((device_tech >> 4) ==
  1078. IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
  1079. active_cable = true;
  1080. }
  1081. if (active_cable) {
  1082. hw->phy.type = ixgbe_phy_qsfp_active_unknown;
  1083. if (hw->bus.lan_id == 0)
  1084. hw->phy.sfp_type =
  1085. ixgbe_sfp_type_da_act_lmt_core0;
  1086. else
  1087. hw->phy.sfp_type =
  1088. ixgbe_sfp_type_da_act_lmt_core1;
  1089. } else {
  1090. /* unsupported module type */
  1091. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1092. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  1093. goto out;
  1094. }
  1095. }
  1096. if (hw->phy.sfp_type != stored_sfp_type)
  1097. hw->phy.sfp_setup_needed = true;
  1098. /* Determine if the QSFP+ PHY is dual speed or not. */
  1099. hw->phy.multispeed_fiber = false;
  1100. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  1101. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  1102. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  1103. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  1104. hw->phy.multispeed_fiber = true;
  1105. /* Determine PHY vendor for optical modules */
  1106. if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
  1107. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1108. status = hw->phy.ops.read_i2c_eeprom(hw,
  1109. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
  1110. &oui_bytes[0]);
  1111. if (status != 0)
  1112. goto err_read_i2c_eeprom;
  1113. status = hw->phy.ops.read_i2c_eeprom(hw,
  1114. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
  1115. &oui_bytes[1]);
  1116. if (status != 0)
  1117. goto err_read_i2c_eeprom;
  1118. status = hw->phy.ops.read_i2c_eeprom(hw,
  1119. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
  1120. &oui_bytes[2]);
  1121. if (status != 0)
  1122. goto err_read_i2c_eeprom;
  1123. vendor_oui =
  1124. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  1125. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  1126. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  1127. if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
  1128. hw->phy.type = ixgbe_phy_qsfp_intel;
  1129. else
  1130. hw->phy.type = ixgbe_phy_qsfp_unknown;
  1131. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  1132. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
  1133. /* Make sure we're a supported PHY type */
  1134. if (hw->phy.type == ixgbe_phy_qsfp_intel) {
  1135. status = 0;
  1136. } else {
  1137. if (hw->allow_unsupported_sfp == true) {
  1138. e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
  1139. status = 0;
  1140. } else {
  1141. hw_dbg(hw,
  1142. "QSFP module not supported\n");
  1143. hw->phy.type =
  1144. ixgbe_phy_sfp_unsupported;
  1145. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  1146. }
  1147. }
  1148. } else {
  1149. status = 0;
  1150. }
  1151. }
  1152. out:
  1153. return status;
  1154. err_read_i2c_eeprom:
  1155. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1156. hw->phy.id = 0;
  1157. hw->phy.type = ixgbe_phy_unknown;
  1158. return IXGBE_ERR_SFP_NOT_PRESENT;
  1159. }
  1160. /**
  1161. * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
  1162. * @hw: pointer to hardware structure
  1163. * @list_offset: offset to the SFP ID list
  1164. * @data_offset: offset to the SFP data block
  1165. *
  1166. * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
  1167. * so it returns the offsets to the phy init sequence block.
  1168. **/
  1169. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  1170. u16 *list_offset,
  1171. u16 *data_offset)
  1172. {
  1173. u16 sfp_id;
  1174. u16 sfp_type = hw->phy.sfp_type;
  1175. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  1176. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1177. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  1178. return IXGBE_ERR_SFP_NOT_PRESENT;
  1179. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  1180. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  1181. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1182. /*
  1183. * Limiting active cables and 1G Phys must be initialized as
  1184. * SR modules
  1185. */
  1186. if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
  1187. sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  1188. sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  1189. sfp_type == ixgbe_sfp_type_1g_sx_core0)
  1190. sfp_type = ixgbe_sfp_type_srlr_core0;
  1191. else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
  1192. sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  1193. sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  1194. sfp_type == ixgbe_sfp_type_1g_sx_core1)
  1195. sfp_type = ixgbe_sfp_type_srlr_core1;
  1196. /* Read offset to PHY init contents */
  1197. if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
  1198. hw_err(hw, "eeprom read at %d failed\n",
  1199. IXGBE_PHY_INIT_OFFSET_NL);
  1200. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  1201. }
  1202. if ((!*list_offset) || (*list_offset == 0xFFFF))
  1203. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  1204. /* Shift offset to first ID word */
  1205. (*list_offset)++;
  1206. /*
  1207. * Find the matching SFP ID in the EEPROM
  1208. * and program the init sequence
  1209. */
  1210. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1211. goto err_phy;
  1212. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  1213. if (sfp_id == sfp_type) {
  1214. (*list_offset)++;
  1215. if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
  1216. goto err_phy;
  1217. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  1218. hw_dbg(hw, "SFP+ module not supported\n");
  1219. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1220. } else {
  1221. break;
  1222. }
  1223. } else {
  1224. (*list_offset) += 2;
  1225. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1226. goto err_phy;
  1227. }
  1228. }
  1229. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  1230. hw_dbg(hw, "No matching SFP+ module found\n");
  1231. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1232. }
  1233. return 0;
  1234. err_phy:
  1235. hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
  1236. return IXGBE_ERR_PHY;
  1237. }
  1238. /**
  1239. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  1240. * @hw: pointer to hardware structure
  1241. * @byte_offset: EEPROM byte offset to read
  1242. * @eeprom_data: value read
  1243. *
  1244. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  1245. **/
  1246. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1247. u8 *eeprom_data)
  1248. {
  1249. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1250. IXGBE_I2C_EEPROM_DEV_ADDR,
  1251. eeprom_data);
  1252. }
  1253. /**
  1254. * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
  1255. * @hw: pointer to hardware structure
  1256. * @byte_offset: byte offset at address 0xA2
  1257. * @eeprom_data: value read
  1258. *
  1259. * Performs byte read operation to SFP module's SFF-8472 data over I2C
  1260. **/
  1261. s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1262. u8 *sff8472_data)
  1263. {
  1264. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1265. IXGBE_I2C_EEPROM_DEV_ADDR2,
  1266. sff8472_data);
  1267. }
  1268. /**
  1269. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  1270. * @hw: pointer to hardware structure
  1271. * @byte_offset: EEPROM byte offset to write
  1272. * @eeprom_data: value to write
  1273. *
  1274. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  1275. **/
  1276. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1277. u8 eeprom_data)
  1278. {
  1279. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  1280. IXGBE_I2C_EEPROM_DEV_ADDR,
  1281. eeprom_data);
  1282. }
  1283. /**
  1284. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  1285. * @hw: pointer to hardware structure
  1286. * @byte_offset: byte offset to read
  1287. * @data: value read
  1288. *
  1289. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1290. * a specified device address.
  1291. **/
  1292. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1293. u8 dev_addr, u8 *data)
  1294. {
  1295. s32 status = 0;
  1296. u32 max_retry = 10;
  1297. u32 retry = 0;
  1298. u16 swfw_mask = 0;
  1299. bool nack = true;
  1300. *data = 0;
  1301. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1302. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1303. else
  1304. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1305. do {
  1306. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
  1307. status = IXGBE_ERR_SWFW_SYNC;
  1308. goto read_byte_out;
  1309. }
  1310. ixgbe_i2c_start(hw);
  1311. /* Device Address and write indication */
  1312. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1313. if (status != 0)
  1314. goto fail;
  1315. status = ixgbe_get_i2c_ack(hw);
  1316. if (status != 0)
  1317. goto fail;
  1318. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1319. if (status != 0)
  1320. goto fail;
  1321. status = ixgbe_get_i2c_ack(hw);
  1322. if (status != 0)
  1323. goto fail;
  1324. ixgbe_i2c_start(hw);
  1325. /* Device Address and read indication */
  1326. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  1327. if (status != 0)
  1328. goto fail;
  1329. status = ixgbe_get_i2c_ack(hw);
  1330. if (status != 0)
  1331. goto fail;
  1332. status = ixgbe_clock_in_i2c_byte(hw, data);
  1333. if (status != 0)
  1334. goto fail;
  1335. status = ixgbe_clock_out_i2c_bit(hw, nack);
  1336. if (status != 0)
  1337. goto fail;
  1338. ixgbe_i2c_stop(hw);
  1339. break;
  1340. fail:
  1341. ixgbe_i2c_bus_clear(hw);
  1342. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1343. msleep(100);
  1344. retry++;
  1345. if (retry < max_retry)
  1346. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  1347. else
  1348. hw_dbg(hw, "I2C byte read error.\n");
  1349. } while (retry < max_retry);
  1350. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1351. read_byte_out:
  1352. return status;
  1353. }
  1354. /**
  1355. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  1356. * @hw: pointer to hardware structure
  1357. * @byte_offset: byte offset to write
  1358. * @data: value to write
  1359. *
  1360. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  1361. * a specified device address.
  1362. **/
  1363. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1364. u8 dev_addr, u8 data)
  1365. {
  1366. s32 status = 0;
  1367. u32 max_retry = 1;
  1368. u32 retry = 0;
  1369. u16 swfw_mask = 0;
  1370. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1371. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1372. else
  1373. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1374. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
  1375. status = IXGBE_ERR_SWFW_SYNC;
  1376. goto write_byte_out;
  1377. }
  1378. do {
  1379. ixgbe_i2c_start(hw);
  1380. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1381. if (status != 0)
  1382. goto fail;
  1383. status = ixgbe_get_i2c_ack(hw);
  1384. if (status != 0)
  1385. goto fail;
  1386. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1387. if (status != 0)
  1388. goto fail;
  1389. status = ixgbe_get_i2c_ack(hw);
  1390. if (status != 0)
  1391. goto fail;
  1392. status = ixgbe_clock_out_i2c_byte(hw, data);
  1393. if (status != 0)
  1394. goto fail;
  1395. status = ixgbe_get_i2c_ack(hw);
  1396. if (status != 0)
  1397. goto fail;
  1398. ixgbe_i2c_stop(hw);
  1399. break;
  1400. fail:
  1401. ixgbe_i2c_bus_clear(hw);
  1402. retry++;
  1403. if (retry < max_retry)
  1404. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  1405. else
  1406. hw_dbg(hw, "I2C byte write error.\n");
  1407. } while (retry < max_retry);
  1408. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1409. write_byte_out:
  1410. return status;
  1411. }
  1412. /**
  1413. * ixgbe_i2c_start - Sets I2C start condition
  1414. * @hw: pointer to hardware structure
  1415. *
  1416. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  1417. **/
  1418. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  1419. {
  1420. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1421. /* Start condition must begin with data and clock high */
  1422. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1423. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1424. /* Setup time for start condition (4.7us) */
  1425. udelay(IXGBE_I2C_T_SU_STA);
  1426. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1427. /* Hold time for start condition (4us) */
  1428. udelay(IXGBE_I2C_T_HD_STA);
  1429. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1430. /* Minimum low period of clock is 4.7 us */
  1431. udelay(IXGBE_I2C_T_LOW);
  1432. }
  1433. /**
  1434. * ixgbe_i2c_stop - Sets I2C stop condition
  1435. * @hw: pointer to hardware structure
  1436. *
  1437. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  1438. **/
  1439. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  1440. {
  1441. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1442. /* Stop condition must begin with data low and clock high */
  1443. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1444. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1445. /* Setup time for stop condition (4us) */
  1446. udelay(IXGBE_I2C_T_SU_STO);
  1447. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1448. /* bus free time between stop and start (4.7us)*/
  1449. udelay(IXGBE_I2C_T_BUF);
  1450. }
  1451. /**
  1452. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  1453. * @hw: pointer to hardware structure
  1454. * @data: data byte to clock in
  1455. *
  1456. * Clocks in one byte data via I2C data/clock
  1457. **/
  1458. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  1459. {
  1460. s32 i;
  1461. bool bit = false;
  1462. for (i = 7; i >= 0; i--) {
  1463. ixgbe_clock_in_i2c_bit(hw, &bit);
  1464. *data |= bit << i;
  1465. }
  1466. return 0;
  1467. }
  1468. /**
  1469. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  1470. * @hw: pointer to hardware structure
  1471. * @data: data byte clocked out
  1472. *
  1473. * Clocks out one byte data via I2C data/clock
  1474. **/
  1475. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  1476. {
  1477. s32 status = 0;
  1478. s32 i;
  1479. u32 i2cctl;
  1480. bool bit = false;
  1481. for (i = 7; i >= 0; i--) {
  1482. bit = (data >> i) & 0x1;
  1483. status = ixgbe_clock_out_i2c_bit(hw, bit);
  1484. if (status != 0)
  1485. break;
  1486. }
  1487. /* Release SDA line (set high) */
  1488. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1489. i2cctl |= IXGBE_I2C_DATA_OUT;
  1490. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  1491. IXGBE_WRITE_FLUSH(hw);
  1492. return status;
  1493. }
  1494. /**
  1495. * ixgbe_get_i2c_ack - Polls for I2C ACK
  1496. * @hw: pointer to hardware structure
  1497. *
  1498. * Clocks in/out one bit via I2C data/clock
  1499. **/
  1500. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  1501. {
  1502. s32 status = 0;
  1503. u32 i = 0;
  1504. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1505. u32 timeout = 10;
  1506. bool ack = true;
  1507. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1508. /* Minimum high period of clock is 4us */
  1509. udelay(IXGBE_I2C_T_HIGH);
  1510. /* Poll for ACK. Note that ACK in I2C spec is
  1511. * transition from 1 to 0 */
  1512. for (i = 0; i < timeout; i++) {
  1513. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1514. ack = ixgbe_get_i2c_data(&i2cctl);
  1515. udelay(1);
  1516. if (ack == 0)
  1517. break;
  1518. }
  1519. if (ack == 1) {
  1520. hw_dbg(hw, "I2C ack was not received.\n");
  1521. status = IXGBE_ERR_I2C;
  1522. }
  1523. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1524. /* Minimum low period of clock is 4.7 us */
  1525. udelay(IXGBE_I2C_T_LOW);
  1526. return status;
  1527. }
  1528. /**
  1529. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  1530. * @hw: pointer to hardware structure
  1531. * @data: read data value
  1532. *
  1533. * Clocks in one bit via I2C data/clock
  1534. **/
  1535. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  1536. {
  1537. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1538. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1539. /* Minimum high period of clock is 4us */
  1540. udelay(IXGBE_I2C_T_HIGH);
  1541. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1542. *data = ixgbe_get_i2c_data(&i2cctl);
  1543. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1544. /* Minimum low period of clock is 4.7 us */
  1545. udelay(IXGBE_I2C_T_LOW);
  1546. return 0;
  1547. }
  1548. /**
  1549. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  1550. * @hw: pointer to hardware structure
  1551. * @data: data value to write
  1552. *
  1553. * Clocks out one bit via I2C data/clock
  1554. **/
  1555. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  1556. {
  1557. s32 status;
  1558. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1559. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  1560. if (status == 0) {
  1561. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1562. /* Minimum high period of clock is 4us */
  1563. udelay(IXGBE_I2C_T_HIGH);
  1564. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1565. /* Minimum low period of clock is 4.7 us.
  1566. * This also takes care of the data hold time.
  1567. */
  1568. udelay(IXGBE_I2C_T_LOW);
  1569. } else {
  1570. status = IXGBE_ERR_I2C;
  1571. hw_dbg(hw, "I2C data was not set to %X\n", data);
  1572. }
  1573. return status;
  1574. }
  1575. /**
  1576. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  1577. * @hw: pointer to hardware structure
  1578. * @i2cctl: Current value of I2CCTL register
  1579. *
  1580. * Raises the I2C clock line '0'->'1'
  1581. **/
  1582. static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1583. {
  1584. u32 i = 0;
  1585. u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
  1586. u32 i2cctl_r = 0;
  1587. for (i = 0; i < timeout; i++) {
  1588. *i2cctl |= IXGBE_I2C_CLK_OUT;
  1589. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1590. IXGBE_WRITE_FLUSH(hw);
  1591. /* SCL rise time (1000ns) */
  1592. udelay(IXGBE_I2C_T_RISE);
  1593. i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1594. if (i2cctl_r & IXGBE_I2C_CLK_IN)
  1595. break;
  1596. }
  1597. }
  1598. /**
  1599. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  1600. * @hw: pointer to hardware structure
  1601. * @i2cctl: Current value of I2CCTL register
  1602. *
  1603. * Lowers the I2C clock line '1'->'0'
  1604. **/
  1605. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1606. {
  1607. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  1608. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1609. IXGBE_WRITE_FLUSH(hw);
  1610. /* SCL fall time (300ns) */
  1611. udelay(IXGBE_I2C_T_FALL);
  1612. }
  1613. /**
  1614. * ixgbe_set_i2c_data - Sets the I2C data bit
  1615. * @hw: pointer to hardware structure
  1616. * @i2cctl: Current value of I2CCTL register
  1617. * @data: I2C data value (0 or 1) to set
  1618. *
  1619. * Sets the I2C data bit
  1620. **/
  1621. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  1622. {
  1623. s32 status = 0;
  1624. if (data)
  1625. *i2cctl |= IXGBE_I2C_DATA_OUT;
  1626. else
  1627. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  1628. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1629. IXGBE_WRITE_FLUSH(hw);
  1630. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  1631. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  1632. /* Verify data was set correctly */
  1633. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1634. if (data != ixgbe_get_i2c_data(i2cctl)) {
  1635. status = IXGBE_ERR_I2C;
  1636. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  1637. }
  1638. return status;
  1639. }
  1640. /**
  1641. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1642. * @hw: pointer to hardware structure
  1643. * @i2cctl: Current value of I2CCTL register
  1644. *
  1645. * Returns the I2C data bit value
  1646. **/
  1647. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1648. {
  1649. bool data;
  1650. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1651. data = true;
  1652. else
  1653. data = false;
  1654. return data;
  1655. }
  1656. /**
  1657. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1658. * @hw: pointer to hardware structure
  1659. *
  1660. * Clears the I2C bus by sending nine clock pulses.
  1661. * Used when data line is stuck low.
  1662. **/
  1663. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1664. {
  1665. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1666. u32 i;
  1667. ixgbe_i2c_start(hw);
  1668. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1669. for (i = 0; i < 9; i++) {
  1670. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1671. /* Min high period of clock is 4us */
  1672. udelay(IXGBE_I2C_T_HIGH);
  1673. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1674. /* Min low period of clock is 4.7us*/
  1675. udelay(IXGBE_I2C_T_LOW);
  1676. }
  1677. ixgbe_i2c_start(hw);
  1678. /* Put the i2c bus back to default state */
  1679. ixgbe_i2c_stop(hw);
  1680. }
  1681. /**
  1682. * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
  1683. * @hw: pointer to hardware structure
  1684. *
  1685. * Checks if the LASI temp alarm status was triggered due to overtemp
  1686. **/
  1687. s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
  1688. {
  1689. s32 status = 0;
  1690. u16 phy_data = 0;
  1691. if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
  1692. goto out;
  1693. /* Check that the LASI temp alarm status was triggered */
  1694. hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
  1695. MDIO_MMD_PMAPMD, &phy_data);
  1696. if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
  1697. goto out;
  1698. status = IXGBE_ERR_OVERTEMP;
  1699. out:
  1700. return status;
  1701. }