ixgbe_phy.c 62 KB

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