ixgbe_phy.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  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. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  380. bool autoneg = false;
  381. ixgbe_link_speed speed;
  382. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  383. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  384. /* Set or unset auto-negotiation 10G advertisement */
  385. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  386. MDIO_MMD_AN,
  387. &autoneg_reg);
  388. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  389. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  390. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  391. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  392. MDIO_MMD_AN,
  393. autoneg_reg);
  394. }
  395. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  396. /* Set or unset auto-negotiation 1G advertisement */
  397. hw->phy.ops.read_reg(hw,
  398. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  399. MDIO_MMD_AN,
  400. &autoneg_reg);
  401. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
  402. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  403. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
  404. hw->phy.ops.write_reg(hw,
  405. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  406. MDIO_MMD_AN,
  407. autoneg_reg);
  408. }
  409. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  410. /* Set or unset auto-negotiation 100M advertisement */
  411. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  412. MDIO_MMD_AN,
  413. &autoneg_reg);
  414. autoneg_reg &= ~(ADVERTISE_100FULL |
  415. ADVERTISE_100HALF);
  416. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  417. autoneg_reg |= ADVERTISE_100FULL;
  418. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  419. MDIO_MMD_AN,
  420. autoneg_reg);
  421. }
  422. /* Blocked by MNG FW so don't reset PHY */
  423. if (ixgbe_check_reset_blocked(hw))
  424. return 0;
  425. /* Restart PHY autonegotiation and wait for completion */
  426. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  427. MDIO_MMD_AN, &autoneg_reg);
  428. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  429. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  430. MDIO_MMD_AN, autoneg_reg);
  431. return status;
  432. }
  433. /**
  434. * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
  435. * @hw: pointer to hardware structure
  436. * @speed: new link speed
  437. **/
  438. s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  439. ixgbe_link_speed speed,
  440. bool autoneg_wait_to_complete)
  441. {
  442. /*
  443. * Clear autoneg_advertised and set new values based on input link
  444. * speed.
  445. */
  446. hw->phy.autoneg_advertised = 0;
  447. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  448. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  449. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  450. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  451. if (speed & IXGBE_LINK_SPEED_100_FULL)
  452. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  453. /* Setup link based on the new speed settings */
  454. hw->phy.ops.setup_link(hw);
  455. return 0;
  456. }
  457. /**
  458. * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
  459. * @hw: pointer to hardware structure
  460. * @speed: pointer to link speed
  461. * @autoneg: boolean auto-negotiation value
  462. *
  463. * Determines the link capabilities by reading the AUTOC register.
  464. */
  465. s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
  466. ixgbe_link_speed *speed,
  467. bool *autoneg)
  468. {
  469. s32 status;
  470. u16 speed_ability;
  471. *speed = 0;
  472. *autoneg = true;
  473. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  474. &speed_ability);
  475. if (status == 0) {
  476. if (speed_ability & MDIO_SPEED_10G)
  477. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  478. if (speed_ability & MDIO_PMA_SPEED_1000)
  479. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  480. if (speed_ability & MDIO_PMA_SPEED_100)
  481. *speed |= IXGBE_LINK_SPEED_100_FULL;
  482. }
  483. return status;
  484. }
  485. /**
  486. * ixgbe_check_phy_link_tnx - Determine link and speed status
  487. * @hw: pointer to hardware structure
  488. *
  489. * Reads the VS1 register to determine if link is up and the current speed for
  490. * the PHY.
  491. **/
  492. s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  493. bool *link_up)
  494. {
  495. s32 status;
  496. u32 time_out;
  497. u32 max_time_out = 10;
  498. u16 phy_link = 0;
  499. u16 phy_speed = 0;
  500. u16 phy_data = 0;
  501. /* Initialize speed and link to default case */
  502. *link_up = false;
  503. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  504. /*
  505. * Check current speed and link status of the PHY register.
  506. * This is a vendor specific register and may have to
  507. * be changed for other copper PHYs.
  508. */
  509. for (time_out = 0; time_out < max_time_out; time_out++) {
  510. udelay(10);
  511. status = hw->phy.ops.read_reg(hw,
  512. MDIO_STAT1,
  513. MDIO_MMD_VEND1,
  514. &phy_data);
  515. phy_link = phy_data &
  516. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  517. phy_speed = phy_data &
  518. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  519. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  520. *link_up = true;
  521. if (phy_speed ==
  522. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  523. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  524. break;
  525. }
  526. }
  527. return status;
  528. }
  529. /**
  530. * ixgbe_setup_phy_link_tnx - Set and restart autoneg
  531. * @hw: pointer to hardware structure
  532. *
  533. * Restart autonegotiation and PHY and waits for completion.
  534. **/
  535. s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
  536. {
  537. s32 status;
  538. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  539. bool autoneg = false;
  540. ixgbe_link_speed speed;
  541. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  542. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  543. /* Set or unset auto-negotiation 10G advertisement */
  544. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  545. MDIO_MMD_AN,
  546. &autoneg_reg);
  547. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  548. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  549. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  550. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  551. MDIO_MMD_AN,
  552. autoneg_reg);
  553. }
  554. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  555. /* Set or unset auto-negotiation 1G advertisement */
  556. hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  557. MDIO_MMD_AN,
  558. &autoneg_reg);
  559. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  560. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  561. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  562. hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  563. MDIO_MMD_AN,
  564. autoneg_reg);
  565. }
  566. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  567. /* Set or unset auto-negotiation 100M advertisement */
  568. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  569. MDIO_MMD_AN,
  570. &autoneg_reg);
  571. autoneg_reg &= ~(ADVERTISE_100FULL |
  572. ADVERTISE_100HALF);
  573. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  574. autoneg_reg |= ADVERTISE_100FULL;
  575. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  576. MDIO_MMD_AN,
  577. autoneg_reg);
  578. }
  579. /* Blocked by MNG FW so don't reset PHY */
  580. if (ixgbe_check_reset_blocked(hw))
  581. return 0;
  582. /* Restart PHY autonegotiation and wait for completion */
  583. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  584. MDIO_MMD_AN, &autoneg_reg);
  585. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  586. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  587. MDIO_MMD_AN, autoneg_reg);
  588. return status;
  589. }
  590. /**
  591. * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
  592. * @hw: pointer to hardware structure
  593. * @firmware_version: pointer to the PHY Firmware Version
  594. **/
  595. s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
  596. u16 *firmware_version)
  597. {
  598. s32 status;
  599. status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
  600. MDIO_MMD_VEND1,
  601. firmware_version);
  602. return status;
  603. }
  604. /**
  605. * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
  606. * @hw: pointer to hardware structure
  607. * @firmware_version: pointer to the PHY Firmware Version
  608. **/
  609. s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
  610. u16 *firmware_version)
  611. {
  612. s32 status;
  613. status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
  614. MDIO_MMD_VEND1,
  615. firmware_version);
  616. return status;
  617. }
  618. /**
  619. * ixgbe_reset_phy_nl - Performs a PHY reset
  620. * @hw: pointer to hardware structure
  621. **/
  622. s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  623. {
  624. u16 phy_offset, control, eword, edata, block_crc;
  625. bool end_data = false;
  626. u16 list_offset, data_offset;
  627. u16 phy_data = 0;
  628. s32 ret_val;
  629. u32 i;
  630. /* Blocked by MNG FW so bail */
  631. if (ixgbe_check_reset_blocked(hw))
  632. return 0;
  633. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
  634. /* reset the PHY and poll for completion */
  635. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  636. (phy_data | MDIO_CTRL1_RESET));
  637. for (i = 0; i < 100; i++) {
  638. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  639. &phy_data);
  640. if ((phy_data & MDIO_CTRL1_RESET) == 0)
  641. break;
  642. usleep_range(10000, 20000);
  643. }
  644. if ((phy_data & MDIO_CTRL1_RESET) != 0) {
  645. hw_dbg(hw, "PHY reset did not complete.\n");
  646. return IXGBE_ERR_PHY;
  647. }
  648. /* Get init offsets */
  649. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  650. &data_offset);
  651. if (ret_val)
  652. return ret_val;
  653. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  654. data_offset++;
  655. while (!end_data) {
  656. /*
  657. * Read control word from PHY init contents offset
  658. */
  659. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  660. if (ret_val)
  661. goto err_eeprom;
  662. control = (eword & IXGBE_CONTROL_MASK_NL) >>
  663. IXGBE_CONTROL_SHIFT_NL;
  664. edata = eword & IXGBE_DATA_MASK_NL;
  665. switch (control) {
  666. case IXGBE_DELAY_NL:
  667. data_offset++;
  668. hw_dbg(hw, "DELAY: %d MS\n", edata);
  669. usleep_range(edata * 1000, edata * 2000);
  670. break;
  671. case IXGBE_DATA_NL:
  672. hw_dbg(hw, "DATA:\n");
  673. data_offset++;
  674. ret_val = hw->eeprom.ops.read(hw, data_offset++,
  675. &phy_offset);
  676. if (ret_val)
  677. goto err_eeprom;
  678. for (i = 0; i < edata; i++) {
  679. ret_val = hw->eeprom.ops.read(hw, data_offset,
  680. &eword);
  681. if (ret_val)
  682. goto err_eeprom;
  683. hw->phy.ops.write_reg(hw, phy_offset,
  684. MDIO_MMD_PMAPMD, eword);
  685. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  686. phy_offset);
  687. data_offset++;
  688. phy_offset++;
  689. }
  690. break;
  691. case IXGBE_CONTROL_NL:
  692. data_offset++;
  693. hw_dbg(hw, "CONTROL:\n");
  694. if (edata == IXGBE_CONTROL_EOL_NL) {
  695. hw_dbg(hw, "EOL\n");
  696. end_data = true;
  697. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  698. hw_dbg(hw, "SOL\n");
  699. } else {
  700. hw_dbg(hw, "Bad control value\n");
  701. return IXGBE_ERR_PHY;
  702. }
  703. break;
  704. default:
  705. hw_dbg(hw, "Bad control type\n");
  706. return IXGBE_ERR_PHY;
  707. }
  708. }
  709. return ret_val;
  710. err_eeprom:
  711. hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
  712. return IXGBE_ERR_PHY;
  713. }
  714. /**
  715. * ixgbe_identify_module_generic - Identifies module type
  716. * @hw: pointer to hardware structure
  717. *
  718. * Determines HW type and calls appropriate function.
  719. **/
  720. s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
  721. {
  722. switch (hw->mac.ops.get_media_type(hw)) {
  723. case ixgbe_media_type_fiber:
  724. return ixgbe_identify_sfp_module_generic(hw);
  725. case ixgbe_media_type_fiber_qsfp:
  726. return ixgbe_identify_qsfp_module_generic(hw);
  727. default:
  728. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  729. return IXGBE_ERR_SFP_NOT_PRESENT;
  730. }
  731. return IXGBE_ERR_SFP_NOT_PRESENT;
  732. }
  733. /**
  734. * ixgbe_identify_sfp_module_generic - Identifies SFP modules
  735. * @hw: pointer to hardware structure
  736. *
  737. * Searches for and identifies the SFP module and assigns appropriate PHY type.
  738. **/
  739. s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  740. {
  741. struct ixgbe_adapter *adapter = hw->back;
  742. s32 status;
  743. u32 vendor_oui = 0;
  744. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  745. u8 identifier = 0;
  746. u8 comp_codes_1g = 0;
  747. u8 comp_codes_10g = 0;
  748. u8 oui_bytes[3] = {0, 0, 0};
  749. u8 cable_tech = 0;
  750. u8 cable_spec = 0;
  751. u16 enforce_sfp = 0;
  752. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
  753. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  754. return IXGBE_ERR_SFP_NOT_PRESENT;
  755. }
  756. status = hw->phy.ops.read_i2c_eeprom(hw,
  757. IXGBE_SFF_IDENTIFIER,
  758. &identifier);
  759. if (status)
  760. goto err_read_i2c_eeprom;
  761. /* LAN ID is needed for sfp_type determination */
  762. hw->mac.ops.set_lan_id(hw);
  763. if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
  764. hw->phy.type = ixgbe_phy_sfp_unsupported;
  765. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  766. }
  767. status = hw->phy.ops.read_i2c_eeprom(hw,
  768. IXGBE_SFF_1GBE_COMP_CODES,
  769. &comp_codes_1g);
  770. if (status)
  771. goto err_read_i2c_eeprom;
  772. status = hw->phy.ops.read_i2c_eeprom(hw,
  773. IXGBE_SFF_10GBE_COMP_CODES,
  774. &comp_codes_10g);
  775. if (status)
  776. goto err_read_i2c_eeprom;
  777. status = hw->phy.ops.read_i2c_eeprom(hw,
  778. IXGBE_SFF_CABLE_TECHNOLOGY,
  779. &cable_tech);
  780. if (status)
  781. goto err_read_i2c_eeprom;
  782. /* ID Module
  783. * =========
  784. * 0 SFP_DA_CU
  785. * 1 SFP_SR
  786. * 2 SFP_LR
  787. * 3 SFP_DA_CORE0 - 82599-specific
  788. * 4 SFP_DA_CORE1 - 82599-specific
  789. * 5 SFP_SR/LR_CORE0 - 82599-specific
  790. * 6 SFP_SR/LR_CORE1 - 82599-specific
  791. * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
  792. * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
  793. * 9 SFP_1g_cu_CORE0 - 82599-specific
  794. * 10 SFP_1g_cu_CORE1 - 82599-specific
  795. * 11 SFP_1g_sx_CORE0 - 82599-specific
  796. * 12 SFP_1g_sx_CORE1 - 82599-specific
  797. */
  798. if (hw->mac.type == ixgbe_mac_82598EB) {
  799. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  800. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  801. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  802. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  803. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  804. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  805. else
  806. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  807. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  808. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
  809. if (hw->bus.lan_id == 0)
  810. hw->phy.sfp_type =
  811. ixgbe_sfp_type_da_cu_core0;
  812. else
  813. hw->phy.sfp_type =
  814. ixgbe_sfp_type_da_cu_core1;
  815. } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
  816. hw->phy.ops.read_i2c_eeprom(
  817. hw, IXGBE_SFF_CABLE_SPEC_COMP,
  818. &cable_spec);
  819. if (cable_spec &
  820. IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
  821. if (hw->bus.lan_id == 0)
  822. hw->phy.sfp_type =
  823. ixgbe_sfp_type_da_act_lmt_core0;
  824. else
  825. hw->phy.sfp_type =
  826. ixgbe_sfp_type_da_act_lmt_core1;
  827. } else {
  828. hw->phy.sfp_type =
  829. ixgbe_sfp_type_unknown;
  830. }
  831. } else if (comp_codes_10g &
  832. (IXGBE_SFF_10GBASESR_CAPABLE |
  833. IXGBE_SFF_10GBASELR_CAPABLE)) {
  834. if (hw->bus.lan_id == 0)
  835. hw->phy.sfp_type =
  836. ixgbe_sfp_type_srlr_core0;
  837. else
  838. hw->phy.sfp_type =
  839. ixgbe_sfp_type_srlr_core1;
  840. } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
  841. if (hw->bus.lan_id == 0)
  842. hw->phy.sfp_type =
  843. ixgbe_sfp_type_1g_cu_core0;
  844. else
  845. hw->phy.sfp_type =
  846. ixgbe_sfp_type_1g_cu_core1;
  847. } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
  848. if (hw->bus.lan_id == 0)
  849. hw->phy.sfp_type =
  850. ixgbe_sfp_type_1g_sx_core0;
  851. else
  852. hw->phy.sfp_type =
  853. ixgbe_sfp_type_1g_sx_core1;
  854. } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
  855. if (hw->bus.lan_id == 0)
  856. hw->phy.sfp_type =
  857. ixgbe_sfp_type_1g_lx_core0;
  858. else
  859. hw->phy.sfp_type =
  860. ixgbe_sfp_type_1g_lx_core1;
  861. } else {
  862. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  863. }
  864. }
  865. if (hw->phy.sfp_type != stored_sfp_type)
  866. hw->phy.sfp_setup_needed = true;
  867. /* Determine if the SFP+ PHY is dual speed or not. */
  868. hw->phy.multispeed_fiber = false;
  869. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  870. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  871. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  872. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  873. hw->phy.multispeed_fiber = true;
  874. /* Determine PHY vendor */
  875. if (hw->phy.type != ixgbe_phy_nl) {
  876. hw->phy.id = identifier;
  877. status = hw->phy.ops.read_i2c_eeprom(hw,
  878. IXGBE_SFF_VENDOR_OUI_BYTE0,
  879. &oui_bytes[0]);
  880. if (status != 0)
  881. goto err_read_i2c_eeprom;
  882. status = hw->phy.ops.read_i2c_eeprom(hw,
  883. IXGBE_SFF_VENDOR_OUI_BYTE1,
  884. &oui_bytes[1]);
  885. if (status != 0)
  886. goto err_read_i2c_eeprom;
  887. status = hw->phy.ops.read_i2c_eeprom(hw,
  888. IXGBE_SFF_VENDOR_OUI_BYTE2,
  889. &oui_bytes[2]);
  890. if (status != 0)
  891. goto err_read_i2c_eeprom;
  892. vendor_oui =
  893. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  894. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  895. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  896. switch (vendor_oui) {
  897. case IXGBE_SFF_VENDOR_OUI_TYCO:
  898. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  899. hw->phy.type =
  900. ixgbe_phy_sfp_passive_tyco;
  901. break;
  902. case IXGBE_SFF_VENDOR_OUI_FTL:
  903. if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  904. hw->phy.type = ixgbe_phy_sfp_ftl_active;
  905. else
  906. hw->phy.type = ixgbe_phy_sfp_ftl;
  907. break;
  908. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  909. hw->phy.type = ixgbe_phy_sfp_avago;
  910. break;
  911. case IXGBE_SFF_VENDOR_OUI_INTEL:
  912. hw->phy.type = ixgbe_phy_sfp_intel;
  913. break;
  914. default:
  915. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  916. hw->phy.type =
  917. ixgbe_phy_sfp_passive_unknown;
  918. else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  919. hw->phy.type =
  920. ixgbe_phy_sfp_active_unknown;
  921. else
  922. hw->phy.type = ixgbe_phy_sfp_unknown;
  923. break;
  924. }
  925. }
  926. /* Allow any DA cable vendor */
  927. if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
  928. IXGBE_SFF_DA_ACTIVE_CABLE))
  929. return 0;
  930. /* Verify supported 1G SFP modules */
  931. if (comp_codes_10g == 0 &&
  932. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  933. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  934. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  935. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  936. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  937. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
  938. hw->phy.type = ixgbe_phy_sfp_unsupported;
  939. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  940. }
  941. /* Anything else 82598-based is supported */
  942. if (hw->mac.type == ixgbe_mac_82598EB)
  943. return 0;
  944. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  945. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
  946. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  947. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  948. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  949. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  950. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  951. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
  952. /* Make sure we're a supported PHY type */
  953. if (hw->phy.type == ixgbe_phy_sfp_intel)
  954. return 0;
  955. if (hw->allow_unsupported_sfp) {
  956. 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");
  957. return 0;
  958. }
  959. hw_dbg(hw, "SFP+ module not supported\n");
  960. hw->phy.type = ixgbe_phy_sfp_unsupported;
  961. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  962. }
  963. return 0;
  964. err_read_i2c_eeprom:
  965. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  966. if (hw->phy.type != ixgbe_phy_nl) {
  967. hw->phy.id = 0;
  968. hw->phy.type = ixgbe_phy_unknown;
  969. }
  970. return IXGBE_ERR_SFP_NOT_PRESENT;
  971. }
  972. /**
  973. * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
  974. * @hw: pointer to hardware structure
  975. *
  976. * Searches for and identifies the QSFP module and assigns appropriate PHY type
  977. **/
  978. static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
  979. {
  980. struct ixgbe_adapter *adapter = hw->back;
  981. s32 status;
  982. u32 vendor_oui = 0;
  983. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  984. u8 identifier = 0;
  985. u8 comp_codes_1g = 0;
  986. u8 comp_codes_10g = 0;
  987. u8 oui_bytes[3] = {0, 0, 0};
  988. u16 enforce_sfp = 0;
  989. u8 connector = 0;
  990. u8 cable_length = 0;
  991. u8 device_tech = 0;
  992. bool active_cable = false;
  993. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
  994. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  995. return IXGBE_ERR_SFP_NOT_PRESENT;
  996. }
  997. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
  998. &identifier);
  999. if (status != 0)
  1000. goto err_read_i2c_eeprom;
  1001. if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
  1002. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1003. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1004. }
  1005. hw->phy.id = identifier;
  1006. /* LAN ID is needed for sfp_type determination */
  1007. hw->mac.ops.set_lan_id(hw);
  1008. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
  1009. &comp_codes_10g);
  1010. if (status != 0)
  1011. goto err_read_i2c_eeprom;
  1012. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
  1013. &comp_codes_1g);
  1014. if (status != 0)
  1015. goto err_read_i2c_eeprom;
  1016. if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
  1017. hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
  1018. if (hw->bus.lan_id == 0)
  1019. hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
  1020. else
  1021. hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
  1022. } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
  1023. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1024. if (hw->bus.lan_id == 0)
  1025. hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
  1026. else
  1027. hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
  1028. } else {
  1029. if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
  1030. active_cable = true;
  1031. if (!active_cable) {
  1032. /* check for active DA cables that pre-date
  1033. * SFF-8436 v3.6
  1034. */
  1035. hw->phy.ops.read_i2c_eeprom(hw,
  1036. IXGBE_SFF_QSFP_CONNECTOR,
  1037. &connector);
  1038. hw->phy.ops.read_i2c_eeprom(hw,
  1039. IXGBE_SFF_QSFP_CABLE_LENGTH,
  1040. &cable_length);
  1041. hw->phy.ops.read_i2c_eeprom(hw,
  1042. IXGBE_SFF_QSFP_DEVICE_TECH,
  1043. &device_tech);
  1044. if ((connector ==
  1045. IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
  1046. (cable_length > 0) &&
  1047. ((device_tech >> 4) ==
  1048. IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
  1049. active_cable = true;
  1050. }
  1051. if (active_cable) {
  1052. hw->phy.type = ixgbe_phy_qsfp_active_unknown;
  1053. if (hw->bus.lan_id == 0)
  1054. hw->phy.sfp_type =
  1055. ixgbe_sfp_type_da_act_lmt_core0;
  1056. else
  1057. hw->phy.sfp_type =
  1058. ixgbe_sfp_type_da_act_lmt_core1;
  1059. } else {
  1060. /* unsupported module type */
  1061. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1062. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1063. }
  1064. }
  1065. if (hw->phy.sfp_type != stored_sfp_type)
  1066. hw->phy.sfp_setup_needed = true;
  1067. /* Determine if the QSFP+ PHY is dual speed or not. */
  1068. hw->phy.multispeed_fiber = false;
  1069. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  1070. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  1071. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  1072. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  1073. hw->phy.multispeed_fiber = true;
  1074. /* Determine PHY vendor for optical modules */
  1075. if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
  1076. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1077. status = hw->phy.ops.read_i2c_eeprom(hw,
  1078. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
  1079. &oui_bytes[0]);
  1080. if (status != 0)
  1081. goto err_read_i2c_eeprom;
  1082. status = hw->phy.ops.read_i2c_eeprom(hw,
  1083. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
  1084. &oui_bytes[1]);
  1085. if (status != 0)
  1086. goto err_read_i2c_eeprom;
  1087. status = hw->phy.ops.read_i2c_eeprom(hw,
  1088. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
  1089. &oui_bytes[2]);
  1090. if (status != 0)
  1091. goto err_read_i2c_eeprom;
  1092. vendor_oui =
  1093. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  1094. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  1095. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  1096. if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
  1097. hw->phy.type = ixgbe_phy_qsfp_intel;
  1098. else
  1099. hw->phy.type = ixgbe_phy_qsfp_unknown;
  1100. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  1101. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
  1102. /* Make sure we're a supported PHY type */
  1103. if (hw->phy.type == ixgbe_phy_qsfp_intel)
  1104. return 0;
  1105. if (hw->allow_unsupported_sfp) {
  1106. 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");
  1107. return 0;
  1108. }
  1109. hw_dbg(hw, "QSFP module not supported\n");
  1110. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1111. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1112. }
  1113. return 0;
  1114. }
  1115. return 0;
  1116. err_read_i2c_eeprom:
  1117. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1118. hw->phy.id = 0;
  1119. hw->phy.type = ixgbe_phy_unknown;
  1120. return IXGBE_ERR_SFP_NOT_PRESENT;
  1121. }
  1122. /**
  1123. * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
  1124. * @hw: pointer to hardware structure
  1125. * @list_offset: offset to the SFP ID list
  1126. * @data_offset: offset to the SFP data block
  1127. *
  1128. * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
  1129. * so it returns the offsets to the phy init sequence block.
  1130. **/
  1131. s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  1132. u16 *list_offset,
  1133. u16 *data_offset)
  1134. {
  1135. u16 sfp_id;
  1136. u16 sfp_type = hw->phy.sfp_type;
  1137. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  1138. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1139. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  1140. return IXGBE_ERR_SFP_NOT_PRESENT;
  1141. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  1142. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  1143. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1144. /*
  1145. * Limiting active cables and 1G Phys must be initialized as
  1146. * SR modules
  1147. */
  1148. if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
  1149. sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  1150. sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  1151. sfp_type == ixgbe_sfp_type_1g_sx_core0)
  1152. sfp_type = ixgbe_sfp_type_srlr_core0;
  1153. else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
  1154. sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  1155. sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  1156. sfp_type == ixgbe_sfp_type_1g_sx_core1)
  1157. sfp_type = ixgbe_sfp_type_srlr_core1;
  1158. /* Read offset to PHY init contents */
  1159. if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
  1160. hw_err(hw, "eeprom read at %d failed\n",
  1161. IXGBE_PHY_INIT_OFFSET_NL);
  1162. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  1163. }
  1164. if ((!*list_offset) || (*list_offset == 0xFFFF))
  1165. return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
  1166. /* Shift offset to first ID word */
  1167. (*list_offset)++;
  1168. /*
  1169. * Find the matching SFP ID in the EEPROM
  1170. * and program the init sequence
  1171. */
  1172. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1173. goto err_phy;
  1174. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  1175. if (sfp_id == sfp_type) {
  1176. (*list_offset)++;
  1177. if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
  1178. goto err_phy;
  1179. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  1180. hw_dbg(hw, "SFP+ module not supported\n");
  1181. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1182. } else {
  1183. break;
  1184. }
  1185. } else {
  1186. (*list_offset) += 2;
  1187. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1188. goto err_phy;
  1189. }
  1190. }
  1191. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  1192. hw_dbg(hw, "No matching SFP+ module found\n");
  1193. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1194. }
  1195. return 0;
  1196. err_phy:
  1197. hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
  1198. return IXGBE_ERR_PHY;
  1199. }
  1200. /**
  1201. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  1202. * @hw: pointer to hardware structure
  1203. * @byte_offset: EEPROM byte offset to read
  1204. * @eeprom_data: value read
  1205. *
  1206. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  1207. **/
  1208. s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1209. u8 *eeprom_data)
  1210. {
  1211. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1212. IXGBE_I2C_EEPROM_DEV_ADDR,
  1213. eeprom_data);
  1214. }
  1215. /**
  1216. * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
  1217. * @hw: pointer to hardware structure
  1218. * @byte_offset: byte offset at address 0xA2
  1219. * @eeprom_data: value read
  1220. *
  1221. * Performs byte read operation to SFP module's SFF-8472 data over I2C
  1222. **/
  1223. s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1224. u8 *sff8472_data)
  1225. {
  1226. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1227. IXGBE_I2C_EEPROM_DEV_ADDR2,
  1228. sff8472_data);
  1229. }
  1230. /**
  1231. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  1232. * @hw: pointer to hardware structure
  1233. * @byte_offset: EEPROM byte offset to write
  1234. * @eeprom_data: value to write
  1235. *
  1236. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  1237. **/
  1238. s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1239. u8 eeprom_data)
  1240. {
  1241. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  1242. IXGBE_I2C_EEPROM_DEV_ADDR,
  1243. eeprom_data);
  1244. }
  1245. /**
  1246. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  1247. * @hw: pointer to hardware structure
  1248. * @byte_offset: byte offset to read
  1249. * @data: value read
  1250. *
  1251. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1252. * a specified device address.
  1253. **/
  1254. s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1255. u8 dev_addr, u8 *data)
  1256. {
  1257. s32 status;
  1258. u32 max_retry = 10;
  1259. u32 retry = 0;
  1260. u16 swfw_mask = 0;
  1261. bool nack = true;
  1262. *data = 0;
  1263. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1264. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1265. else
  1266. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1267. do {
  1268. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
  1269. return IXGBE_ERR_SWFW_SYNC;
  1270. ixgbe_i2c_start(hw);
  1271. /* Device Address and write indication */
  1272. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1273. if (status != 0)
  1274. goto fail;
  1275. status = ixgbe_get_i2c_ack(hw);
  1276. if (status != 0)
  1277. goto fail;
  1278. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1279. if (status != 0)
  1280. goto fail;
  1281. status = ixgbe_get_i2c_ack(hw);
  1282. if (status != 0)
  1283. goto fail;
  1284. ixgbe_i2c_start(hw);
  1285. /* Device Address and read indication */
  1286. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  1287. if (status != 0)
  1288. goto fail;
  1289. status = ixgbe_get_i2c_ack(hw);
  1290. if (status != 0)
  1291. goto fail;
  1292. status = ixgbe_clock_in_i2c_byte(hw, data);
  1293. if (status != 0)
  1294. goto fail;
  1295. status = ixgbe_clock_out_i2c_bit(hw, nack);
  1296. if (status != 0)
  1297. goto fail;
  1298. ixgbe_i2c_stop(hw);
  1299. break;
  1300. fail:
  1301. ixgbe_i2c_bus_clear(hw);
  1302. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1303. msleep(100);
  1304. retry++;
  1305. if (retry < max_retry)
  1306. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  1307. else
  1308. hw_dbg(hw, "I2C byte read error.\n");
  1309. } while (retry < max_retry);
  1310. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1311. return status;
  1312. }
  1313. /**
  1314. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  1315. * @hw: pointer to hardware structure
  1316. * @byte_offset: byte offset to write
  1317. * @data: value to write
  1318. *
  1319. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  1320. * a specified device address.
  1321. **/
  1322. s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1323. u8 dev_addr, u8 data)
  1324. {
  1325. s32 status;
  1326. u32 max_retry = 1;
  1327. u32 retry = 0;
  1328. u16 swfw_mask = 0;
  1329. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  1330. swfw_mask = IXGBE_GSSR_PHY1_SM;
  1331. else
  1332. swfw_mask = IXGBE_GSSR_PHY0_SM;
  1333. if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
  1334. return IXGBE_ERR_SWFW_SYNC;
  1335. do {
  1336. ixgbe_i2c_start(hw);
  1337. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1338. if (status != 0)
  1339. goto fail;
  1340. status = ixgbe_get_i2c_ack(hw);
  1341. if (status != 0)
  1342. goto fail;
  1343. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1344. if (status != 0)
  1345. goto fail;
  1346. status = ixgbe_get_i2c_ack(hw);
  1347. if (status != 0)
  1348. goto fail;
  1349. status = ixgbe_clock_out_i2c_byte(hw, data);
  1350. if (status != 0)
  1351. goto fail;
  1352. status = ixgbe_get_i2c_ack(hw);
  1353. if (status != 0)
  1354. goto fail;
  1355. ixgbe_i2c_stop(hw);
  1356. break;
  1357. fail:
  1358. ixgbe_i2c_bus_clear(hw);
  1359. retry++;
  1360. if (retry < max_retry)
  1361. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  1362. else
  1363. hw_dbg(hw, "I2C byte write error.\n");
  1364. } while (retry < max_retry);
  1365. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1366. return status;
  1367. }
  1368. /**
  1369. * ixgbe_i2c_start - Sets I2C start condition
  1370. * @hw: pointer to hardware structure
  1371. *
  1372. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  1373. **/
  1374. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  1375. {
  1376. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1377. /* Start condition must begin with data and clock high */
  1378. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1379. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1380. /* Setup time for start condition (4.7us) */
  1381. udelay(IXGBE_I2C_T_SU_STA);
  1382. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1383. /* Hold time for start condition (4us) */
  1384. udelay(IXGBE_I2C_T_HD_STA);
  1385. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1386. /* Minimum low period of clock is 4.7 us */
  1387. udelay(IXGBE_I2C_T_LOW);
  1388. }
  1389. /**
  1390. * ixgbe_i2c_stop - Sets I2C stop condition
  1391. * @hw: pointer to hardware structure
  1392. *
  1393. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  1394. **/
  1395. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  1396. {
  1397. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1398. /* Stop condition must begin with data low and clock high */
  1399. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  1400. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1401. /* Setup time for stop condition (4us) */
  1402. udelay(IXGBE_I2C_T_SU_STO);
  1403. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1404. /* bus free time between stop and start (4.7us)*/
  1405. udelay(IXGBE_I2C_T_BUF);
  1406. }
  1407. /**
  1408. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  1409. * @hw: pointer to hardware structure
  1410. * @data: data byte to clock in
  1411. *
  1412. * Clocks in one byte data via I2C data/clock
  1413. **/
  1414. static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  1415. {
  1416. s32 i;
  1417. bool bit = false;
  1418. for (i = 7; i >= 0; i--) {
  1419. ixgbe_clock_in_i2c_bit(hw, &bit);
  1420. *data |= bit << i;
  1421. }
  1422. return 0;
  1423. }
  1424. /**
  1425. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  1426. * @hw: pointer to hardware structure
  1427. * @data: data byte clocked out
  1428. *
  1429. * Clocks out one byte data via I2C data/clock
  1430. **/
  1431. static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  1432. {
  1433. s32 status;
  1434. s32 i;
  1435. u32 i2cctl;
  1436. bool bit = false;
  1437. for (i = 7; i >= 0; i--) {
  1438. bit = (data >> i) & 0x1;
  1439. status = ixgbe_clock_out_i2c_bit(hw, bit);
  1440. if (status != 0)
  1441. break;
  1442. }
  1443. /* Release SDA line (set high) */
  1444. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1445. i2cctl |= IXGBE_I2C_DATA_OUT;
  1446. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
  1447. IXGBE_WRITE_FLUSH(hw);
  1448. return status;
  1449. }
  1450. /**
  1451. * ixgbe_get_i2c_ack - Polls for I2C ACK
  1452. * @hw: pointer to hardware structure
  1453. *
  1454. * Clocks in/out one bit via I2C data/clock
  1455. **/
  1456. static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  1457. {
  1458. s32 status = 0;
  1459. u32 i = 0;
  1460. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1461. u32 timeout = 10;
  1462. bool ack = true;
  1463. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1464. /* Minimum high period of clock is 4us */
  1465. udelay(IXGBE_I2C_T_HIGH);
  1466. /* Poll for ACK. Note that ACK in I2C spec is
  1467. * transition from 1 to 0 */
  1468. for (i = 0; i < timeout; i++) {
  1469. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1470. ack = ixgbe_get_i2c_data(&i2cctl);
  1471. udelay(1);
  1472. if (ack == 0)
  1473. break;
  1474. }
  1475. if (ack == 1) {
  1476. hw_dbg(hw, "I2C ack was not received.\n");
  1477. status = IXGBE_ERR_I2C;
  1478. }
  1479. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1480. /* Minimum low period of clock is 4.7 us */
  1481. udelay(IXGBE_I2C_T_LOW);
  1482. return status;
  1483. }
  1484. /**
  1485. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  1486. * @hw: pointer to hardware structure
  1487. * @data: read data value
  1488. *
  1489. * Clocks in one bit via I2C data/clock
  1490. **/
  1491. static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  1492. {
  1493. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1494. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1495. /* Minimum high period of clock is 4us */
  1496. udelay(IXGBE_I2C_T_HIGH);
  1497. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1498. *data = ixgbe_get_i2c_data(&i2cctl);
  1499. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1500. /* Minimum low period of clock is 4.7 us */
  1501. udelay(IXGBE_I2C_T_LOW);
  1502. return 0;
  1503. }
  1504. /**
  1505. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  1506. * @hw: pointer to hardware structure
  1507. * @data: data value to write
  1508. *
  1509. * Clocks out one bit via I2C data/clock
  1510. **/
  1511. static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  1512. {
  1513. s32 status;
  1514. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1515. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  1516. if (status == 0) {
  1517. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1518. /* Minimum high period of clock is 4us */
  1519. udelay(IXGBE_I2C_T_HIGH);
  1520. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1521. /* Minimum low period of clock is 4.7 us.
  1522. * This also takes care of the data hold time.
  1523. */
  1524. udelay(IXGBE_I2C_T_LOW);
  1525. } else {
  1526. hw_dbg(hw, "I2C data was not set to %X\n", data);
  1527. return IXGBE_ERR_I2C;
  1528. }
  1529. return 0;
  1530. }
  1531. /**
  1532. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  1533. * @hw: pointer to hardware structure
  1534. * @i2cctl: Current value of I2CCTL register
  1535. *
  1536. * Raises the I2C clock line '0'->'1'
  1537. **/
  1538. static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1539. {
  1540. u32 i = 0;
  1541. u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
  1542. u32 i2cctl_r = 0;
  1543. for (i = 0; i < timeout; i++) {
  1544. *i2cctl |= IXGBE_I2C_CLK_OUT;
  1545. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1546. IXGBE_WRITE_FLUSH(hw);
  1547. /* SCL rise time (1000ns) */
  1548. udelay(IXGBE_I2C_T_RISE);
  1549. i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1550. if (i2cctl_r & IXGBE_I2C_CLK_IN)
  1551. break;
  1552. }
  1553. }
  1554. /**
  1555. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  1556. * @hw: pointer to hardware structure
  1557. * @i2cctl: Current value of I2CCTL register
  1558. *
  1559. * Lowers the I2C clock line '1'->'0'
  1560. **/
  1561. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  1562. {
  1563. *i2cctl &= ~IXGBE_I2C_CLK_OUT;
  1564. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1565. IXGBE_WRITE_FLUSH(hw);
  1566. /* SCL fall time (300ns) */
  1567. udelay(IXGBE_I2C_T_FALL);
  1568. }
  1569. /**
  1570. * ixgbe_set_i2c_data - Sets the I2C data bit
  1571. * @hw: pointer to hardware structure
  1572. * @i2cctl: Current value of I2CCTL register
  1573. * @data: I2C data value (0 or 1) to set
  1574. *
  1575. * Sets the I2C data bit
  1576. **/
  1577. static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  1578. {
  1579. if (data)
  1580. *i2cctl |= IXGBE_I2C_DATA_OUT;
  1581. else
  1582. *i2cctl &= ~IXGBE_I2C_DATA_OUT;
  1583. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
  1584. IXGBE_WRITE_FLUSH(hw);
  1585. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  1586. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  1587. /* Verify data was set correctly */
  1588. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1589. if (data != ixgbe_get_i2c_data(i2cctl)) {
  1590. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  1591. return IXGBE_ERR_I2C;
  1592. }
  1593. return 0;
  1594. }
  1595. /**
  1596. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  1597. * @hw: pointer to hardware structure
  1598. * @i2cctl: Current value of I2CCTL register
  1599. *
  1600. * Returns the I2C data bit value
  1601. **/
  1602. static bool ixgbe_get_i2c_data(u32 *i2cctl)
  1603. {
  1604. if (*i2cctl & IXGBE_I2C_DATA_IN)
  1605. return true;
  1606. return false;
  1607. }
  1608. /**
  1609. * ixgbe_i2c_bus_clear - Clears the I2C bus
  1610. * @hw: pointer to hardware structure
  1611. *
  1612. * Clears the I2C bus by sending nine clock pulses.
  1613. * Used when data line is stuck low.
  1614. **/
  1615. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  1616. {
  1617. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
  1618. u32 i;
  1619. ixgbe_i2c_start(hw);
  1620. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  1621. for (i = 0; i < 9; i++) {
  1622. ixgbe_raise_i2c_clk(hw, &i2cctl);
  1623. /* Min high period of clock is 4us */
  1624. udelay(IXGBE_I2C_T_HIGH);
  1625. ixgbe_lower_i2c_clk(hw, &i2cctl);
  1626. /* Min low period of clock is 4.7us*/
  1627. udelay(IXGBE_I2C_T_LOW);
  1628. }
  1629. ixgbe_i2c_start(hw);
  1630. /* Put the i2c bus back to default state */
  1631. ixgbe_i2c_stop(hw);
  1632. }
  1633. /**
  1634. * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
  1635. * @hw: pointer to hardware structure
  1636. *
  1637. * Checks if the LASI temp alarm status was triggered due to overtemp
  1638. **/
  1639. s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
  1640. {
  1641. u16 phy_data = 0;
  1642. if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
  1643. return 0;
  1644. /* Check that the LASI temp alarm status was triggered */
  1645. hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
  1646. MDIO_MMD_PMAPMD, &phy_data);
  1647. if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
  1648. return 0;
  1649. return IXGBE_ERR_OVERTEMP;
  1650. }