ixgbe_phy.c 53 KB

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