ixgbe_phy.c 52 KB

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