ixgbe_phy.c 63 KB

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