ixgbe_phy.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822
  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/iopoll.h>
  6. #include <linux/sched.h>
  7. #include "ixgbe.h"
  8. #include "ixgbe_phy.h"
  9. static void ixgbe_i2c_start(struct ixgbe_hw *hw);
  10. static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
  11. static int ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
  12. static int ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
  13. static int ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
  14. static int ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
  15. static int ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
  16. static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
  17. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
  18. static int ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
  19. static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl);
  20. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
  21. static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
  22. static int ixgbe_get_phy_id(struct ixgbe_hw *hw);
  23. static int ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw);
  24. /**
  25. * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
  26. * @hw: pointer to the hardware structure
  27. * @byte: byte to send
  28. *
  29. * Returns an error code on error.
  30. **/
  31. static int ixgbe_out_i2c_byte_ack(struct ixgbe_hw *hw, u8 byte)
  32. {
  33. int status;
  34. status = ixgbe_clock_out_i2c_byte(hw, byte);
  35. if (status)
  36. return status;
  37. return ixgbe_get_i2c_ack(hw);
  38. }
  39. /**
  40. * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
  41. * @hw: pointer to the hardware structure
  42. * @byte: pointer to a u8 to receive the byte
  43. *
  44. * Returns an error code on error.
  45. **/
  46. static int ixgbe_in_i2c_byte_ack(struct ixgbe_hw *hw, u8 *byte)
  47. {
  48. int status;
  49. status = ixgbe_clock_in_i2c_byte(hw, byte);
  50. if (status)
  51. return status;
  52. /* ACK */
  53. return ixgbe_clock_out_i2c_bit(hw, false);
  54. }
  55. /**
  56. * ixgbe_ones_comp_byte_add - Perform one's complement addition
  57. * @add1: addend 1
  58. * @add2: addend 2
  59. *
  60. * Returns one's complement 8-bit sum.
  61. **/
  62. static u8 ixgbe_ones_comp_byte_add(u8 add1, u8 add2)
  63. {
  64. u16 sum = add1 + add2;
  65. sum = (sum & 0xFF) + (sum >> 8);
  66. return sum & 0xFF;
  67. }
  68. /**
  69. * ixgbe_read_i2c_combined_generic_int - Perform I2C read combined operation
  70. * @hw: pointer to the hardware structure
  71. * @addr: I2C bus address to read from
  72. * @reg: I2C device register to read from
  73. * @val: pointer to location to receive read value
  74. * @lock: true if to take and release semaphore
  75. *
  76. * Returns an error code on error.
  77. */
  78. int ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr,
  79. u16 reg, u16 *val, bool lock)
  80. {
  81. u32 swfw_mask = hw->phy.phy_semaphore_mask;
  82. int max_retry = 3;
  83. int retry = 0;
  84. u8 csum_byte;
  85. u8 high_bits;
  86. u8 low_bits;
  87. u8 reg_high;
  88. u8 csum;
  89. reg_high = ((reg >> 7) & 0xFE) | 1; /* Indicate read combined */
  90. csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
  91. csum = ~csum;
  92. do {
  93. if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
  94. return -EBUSY;
  95. ixgbe_i2c_start(hw);
  96. /* Device Address and write indication */
  97. if (ixgbe_out_i2c_byte_ack(hw, addr))
  98. goto fail;
  99. /* Write bits 14:8 */
  100. if (ixgbe_out_i2c_byte_ack(hw, reg_high))
  101. goto fail;
  102. /* Write bits 7:0 */
  103. if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
  104. goto fail;
  105. /* Write csum */
  106. if (ixgbe_out_i2c_byte_ack(hw, csum))
  107. goto fail;
  108. /* Re-start condition */
  109. ixgbe_i2c_start(hw);
  110. /* Device Address and read indication */
  111. if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
  112. goto fail;
  113. /* Get upper bits */
  114. if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
  115. goto fail;
  116. /* Get low bits */
  117. if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
  118. goto fail;
  119. /* Get csum */
  120. if (ixgbe_clock_in_i2c_byte(hw, &csum_byte))
  121. goto fail;
  122. /* NACK */
  123. if (ixgbe_clock_out_i2c_bit(hw, false))
  124. goto fail;
  125. ixgbe_i2c_stop(hw);
  126. if (lock)
  127. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  128. *val = (high_bits << 8) | low_bits;
  129. return 0;
  130. fail:
  131. ixgbe_i2c_bus_clear(hw);
  132. if (lock)
  133. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  134. retry++;
  135. if (retry < max_retry)
  136. hw_dbg(hw, "I2C byte read combined error - Retry.\n");
  137. else
  138. hw_dbg(hw, "I2C byte read combined error.\n");
  139. } while (retry < max_retry);
  140. return -EIO;
  141. }
  142. /**
  143. * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
  144. * @hw: pointer to the hardware structure
  145. * @addr: I2C bus address to write to
  146. * @reg: I2C device register to write to
  147. * @val: value to write
  148. * @lock: true if to take and release semaphore
  149. *
  150. * Returns an error code on error.
  151. */
  152. int ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr,
  153. u16 reg, u16 val, bool lock)
  154. {
  155. u32 swfw_mask = hw->phy.phy_semaphore_mask;
  156. int max_retry = 3;
  157. int retry = 0;
  158. u8 reg_high;
  159. u8 csum;
  160. reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
  161. csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
  162. csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
  163. csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
  164. csum = ~csum;
  165. do {
  166. if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
  167. return -EBUSY;
  168. ixgbe_i2c_start(hw);
  169. /* Device Address and write indication */
  170. if (ixgbe_out_i2c_byte_ack(hw, addr))
  171. goto fail;
  172. /* Write bits 14:8 */
  173. if (ixgbe_out_i2c_byte_ack(hw, reg_high))
  174. goto fail;
  175. /* Write bits 7:0 */
  176. if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
  177. goto fail;
  178. /* Write data 15:8 */
  179. if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
  180. goto fail;
  181. /* Write data 7:0 */
  182. if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
  183. goto fail;
  184. /* Write csum */
  185. if (ixgbe_out_i2c_byte_ack(hw, csum))
  186. goto fail;
  187. ixgbe_i2c_stop(hw);
  188. if (lock)
  189. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  190. return 0;
  191. fail:
  192. ixgbe_i2c_bus_clear(hw);
  193. if (lock)
  194. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  195. retry++;
  196. if (retry < max_retry)
  197. hw_dbg(hw, "I2C byte write combined error - Retry.\n");
  198. else
  199. hw_dbg(hw, "I2C byte write combined error.\n");
  200. } while (retry < max_retry);
  201. return -EIO;
  202. }
  203. /**
  204. * ixgbe_probe_phy - Probe a single address for a PHY
  205. * @hw: pointer to hardware structure
  206. * @phy_addr: PHY address to probe
  207. *
  208. * Returns true if PHY found
  209. **/
  210. static bool ixgbe_probe_phy(struct ixgbe_hw *hw, u16 phy_addr)
  211. {
  212. u16 ext_ability = 0;
  213. hw->phy.mdio.prtad = phy_addr;
  214. if (mdio45_probe(&hw->phy.mdio, phy_addr) != 0)
  215. return false;
  216. if (ixgbe_get_phy_id(hw))
  217. return false;
  218. hw->phy.type = ixgbe_get_phy_type_from_id(hw->phy.id);
  219. if (hw->phy.type == ixgbe_phy_unknown) {
  220. hw->phy.ops.read_reg(hw,
  221. MDIO_PMA_EXTABLE,
  222. MDIO_MMD_PMAPMD,
  223. &ext_ability);
  224. if (ext_ability &
  225. (MDIO_PMA_EXTABLE_10GBT |
  226. MDIO_PMA_EXTABLE_1000BT))
  227. hw->phy.type = ixgbe_phy_cu_unknown;
  228. else
  229. hw->phy.type = ixgbe_phy_generic;
  230. }
  231. return true;
  232. }
  233. /**
  234. * ixgbe_identify_phy_generic - Get physical layer module
  235. * @hw: pointer to hardware structure
  236. *
  237. * Determines the physical layer module found on the current adapter.
  238. **/
  239. int ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
  240. {
  241. u32 status = -EFAULT;
  242. u32 phy_addr;
  243. if (!hw->phy.phy_semaphore_mask) {
  244. if (hw->bus.lan_id)
  245. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
  246. else
  247. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
  248. }
  249. if (hw->phy.type != ixgbe_phy_unknown)
  250. return 0;
  251. if (hw->phy.nw_mng_if_sel) {
  252. phy_addr = FIELD_GET(IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD,
  253. hw->phy.nw_mng_if_sel);
  254. if (ixgbe_probe_phy(hw, phy_addr))
  255. return 0;
  256. else
  257. return -EFAULT;
  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 int ixgbe_get_phy_id(struct ixgbe_hw *hw)
  301. {
  302. u16 phy_id_high = 0;
  303. u16 phy_id_low = 0;
  304. int status;
  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. case BCM54616S_E_PHY_ID:
  344. phy_type = ixgbe_phy_ext_1g_t;
  345. break;
  346. default:
  347. phy_type = ixgbe_phy_unknown;
  348. break;
  349. }
  350. return phy_type;
  351. }
  352. /**
  353. * ixgbe_reset_phy_generic - Performs a PHY reset
  354. * @hw: pointer to hardware structure
  355. **/
  356. int ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
  357. {
  358. u32 i;
  359. u16 ctrl = 0;
  360. int status = 0;
  361. if (hw->phy.type == ixgbe_phy_unknown)
  362. status = ixgbe_identify_phy_generic(hw);
  363. if (status != 0 || hw->phy.type == ixgbe_phy_none)
  364. return status;
  365. /* Don't reset PHY if it's shut down due to overtemp. */
  366. if (!hw->phy.reset_if_overtemp && hw->phy.ops.check_overtemp(hw))
  367. return 0;
  368. /* Blocked by MNG FW so bail */
  369. if (ixgbe_check_reset_blocked(hw))
  370. return 0;
  371. /*
  372. * Perform soft PHY reset to the PHY_XS.
  373. * This will cause a soft reset to the PHY
  374. */
  375. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  376. MDIO_MMD_PHYXS,
  377. MDIO_CTRL1_RESET);
  378. /*
  379. * Poll for reset bit to self-clear indicating reset is complete.
  380. * Some PHYs could take up to 3 seconds to complete and need about
  381. * 1.7 usec delay after the reset is complete.
  382. */
  383. for (i = 0; i < 30; i++) {
  384. msleep(100);
  385. if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
  386. status = hw->phy.ops.read_reg(hw,
  387. IXGBE_MDIO_TX_VENDOR_ALARMS_3,
  388. MDIO_MMD_PMAPMD, &ctrl);
  389. if (status)
  390. return status;
  391. if (ctrl & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
  392. udelay(2);
  393. break;
  394. }
  395. } else {
  396. status = hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  397. MDIO_MMD_PHYXS, &ctrl);
  398. if (status)
  399. return status;
  400. if (!(ctrl & MDIO_CTRL1_RESET)) {
  401. udelay(2);
  402. break;
  403. }
  404. }
  405. }
  406. if (ctrl & MDIO_CTRL1_RESET) {
  407. hw_dbg(hw, "PHY reset polling failed to complete.\n");
  408. return -EIO;
  409. }
  410. return 0;
  411. }
  412. /**
  413. * ixgbe_read_phy_reg_mdi - read PHY register
  414. * @hw: pointer to hardware structure
  415. * @reg_addr: 32 bit address of PHY register to read
  416. * @device_type: 5 bit device type
  417. * @phy_data: Pointer to read data from PHY register
  418. *
  419. * Reads a value from a specified PHY register without the SWFW lock
  420. **/
  421. int ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
  422. u16 *phy_data)
  423. {
  424. u32 i, data, command;
  425. /* Setup and write the address cycle command */
  426. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  427. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  428. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  429. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  430. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  431. /* Check every 10 usec to see if the address cycle completed.
  432. * The MDI Command bit will clear when the operation is
  433. * complete
  434. */
  435. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  436. udelay(10);
  437. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  438. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  439. break;
  440. }
  441. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  442. hw_dbg(hw, "PHY address command did not complete.\n");
  443. return -EIO;
  444. }
  445. /* Address cycle complete, setup and write the read
  446. * command
  447. */
  448. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  449. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  450. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  451. (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
  452. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  453. /* Check every 10 usec to see if the address cycle
  454. * completed. The MDI Command bit will clear when the
  455. * operation is complete
  456. */
  457. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  458. udelay(10);
  459. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  460. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  461. break;
  462. }
  463. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  464. hw_dbg(hw, "PHY read command didn't complete\n");
  465. return -EIO;
  466. }
  467. /* Read operation is complete. Get the data
  468. * from MSRWD
  469. */
  470. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  471. data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
  472. *phy_data = (u16)(data);
  473. return 0;
  474. }
  475. /**
  476. * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
  477. * using the SWFW lock - this function is needed in most cases
  478. * @hw: pointer to hardware structure
  479. * @reg_addr: 32 bit address of PHY register to read
  480. * @device_type: 5 bit device type
  481. * @phy_data: Pointer to read data from PHY register
  482. **/
  483. int ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  484. u32 device_type, u16 *phy_data)
  485. {
  486. u32 gssr = hw->phy.phy_semaphore_mask;
  487. int status;
  488. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
  489. status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
  490. phy_data);
  491. hw->mac.ops.release_swfw_sync(hw, gssr);
  492. } else {
  493. return -EBUSY;
  494. }
  495. return status;
  496. }
  497. /**
  498. * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
  499. * without SWFW lock
  500. * @hw: pointer to hardware structure
  501. * @reg_addr: 32 bit PHY register to write
  502. * @device_type: 5 bit device type
  503. * @phy_data: Data to write to the PHY register
  504. **/
  505. int ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
  506. u16 phy_data)
  507. {
  508. u32 i, command;
  509. /* Put the data in the MDI single read and write data register*/
  510. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
  511. /* Setup and write the address cycle command */
  512. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  513. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  514. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  515. (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
  516. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  517. /*
  518. * Check every 10 usec to see if the address cycle completed.
  519. * The MDI Command bit will clear when the operation is
  520. * complete
  521. */
  522. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  523. udelay(10);
  524. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  525. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  526. break;
  527. }
  528. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  529. hw_dbg(hw, "PHY address cmd didn't complete\n");
  530. return -EIO;
  531. }
  532. /*
  533. * Address cycle complete, setup and write the write
  534. * command
  535. */
  536. command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
  537. (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
  538. (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
  539. (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
  540. IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
  541. /* Check every 10 usec to see if the address cycle
  542. * completed. The MDI Command bit will clear when the
  543. * operation is complete
  544. */
  545. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  546. udelay(10);
  547. command = IXGBE_READ_REG(hw, IXGBE_MSCA);
  548. if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
  549. break;
  550. }
  551. if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
  552. hw_dbg(hw, "PHY write cmd didn't complete\n");
  553. return -EIO;
  554. }
  555. return 0;
  556. }
  557. /**
  558. * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
  559. * using SWFW lock- this function is needed in most cases
  560. * @hw: pointer to hardware structure
  561. * @reg_addr: 32 bit PHY register to write
  562. * @device_type: 5 bit device type
  563. * @phy_data: Data to write to the PHY register
  564. **/
  565. int ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
  566. u32 device_type, u16 phy_data)
  567. {
  568. u32 gssr = hw->phy.phy_semaphore_mask;
  569. int status;
  570. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
  571. status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
  572. phy_data);
  573. hw->mac.ops.release_swfw_sync(hw, gssr);
  574. } else {
  575. return -EBUSY;
  576. }
  577. return status;
  578. }
  579. #define IXGBE_HW_READ_REG(addr) IXGBE_READ_REG(hw, addr)
  580. /**
  581. * ixgbe_msca_cmd - Write the command register and poll for completion/timeout
  582. * @hw: pointer to hardware structure
  583. * @cmd: command register value to write
  584. **/
  585. static int ixgbe_msca_cmd(struct ixgbe_hw *hw, u32 cmd)
  586. {
  587. IXGBE_WRITE_REG(hw, IXGBE_MSCA, cmd);
  588. return readx_poll_timeout(IXGBE_HW_READ_REG, IXGBE_MSCA, cmd,
  589. !(cmd & IXGBE_MSCA_MDI_COMMAND), 10,
  590. 10 * IXGBE_MDIO_COMMAND_TIMEOUT);
  591. }
  592. /**
  593. * ixgbe_mii_bus_read_generic_c22 - Read a clause 22 register with gssr flags
  594. * @hw: pointer to hardware structure
  595. * @addr: address
  596. * @regnum: register number
  597. * @gssr: semaphore flags to acquire
  598. **/
  599. static int ixgbe_mii_bus_read_generic_c22(struct ixgbe_hw *hw, int addr,
  600. int regnum, u32 gssr)
  601. {
  602. u32 hwaddr, cmd;
  603. int data;
  604. if (hw->mac.ops.acquire_swfw_sync(hw, gssr))
  605. return -EBUSY;
  606. hwaddr = addr << IXGBE_MSCA_PHY_ADDR_SHIFT;
  607. hwaddr |= (regnum & GENMASK(5, 0)) << IXGBE_MSCA_DEV_TYPE_SHIFT;
  608. cmd = hwaddr | IXGBE_MSCA_OLD_PROTOCOL |
  609. IXGBE_MSCA_READ_AUTOINC | IXGBE_MSCA_MDI_COMMAND;
  610. data = ixgbe_msca_cmd(hw, cmd);
  611. if (data < 0)
  612. goto mii_bus_read_done;
  613. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  614. data = (data >> IXGBE_MSRWD_READ_DATA_SHIFT) & GENMASK(16, 0);
  615. mii_bus_read_done:
  616. hw->mac.ops.release_swfw_sync(hw, gssr);
  617. return data;
  618. }
  619. /**
  620. * ixgbe_mii_bus_read_generic_c45 - Read a clause 45 register with gssr flags
  621. * @hw: pointer to hardware structure
  622. * @addr: address
  623. * @devad: device address to read
  624. * @regnum: register number
  625. * @gssr: semaphore flags to acquire
  626. **/
  627. static int ixgbe_mii_bus_read_generic_c45(struct ixgbe_hw *hw, int addr,
  628. int devad, int regnum, u32 gssr)
  629. {
  630. u32 hwaddr, cmd;
  631. int data;
  632. if (hw->mac.ops.acquire_swfw_sync(hw, gssr))
  633. return -EBUSY;
  634. hwaddr = addr << IXGBE_MSCA_PHY_ADDR_SHIFT;
  635. hwaddr |= devad << 16 | regnum;
  636. cmd = hwaddr | IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND;
  637. data = ixgbe_msca_cmd(hw, cmd);
  638. if (data < 0)
  639. goto mii_bus_read_done;
  640. cmd = hwaddr | IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND;
  641. data = ixgbe_msca_cmd(hw, cmd);
  642. if (data < 0)
  643. goto mii_bus_read_done;
  644. data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  645. data = (data >> IXGBE_MSRWD_READ_DATA_SHIFT) & GENMASK(16, 0);
  646. mii_bus_read_done:
  647. hw->mac.ops.release_swfw_sync(hw, gssr);
  648. return data;
  649. }
  650. /**
  651. * ixgbe_mii_bus_write_generic_c22 - Write a clause 22 register with gssr flags
  652. * @hw: pointer to hardware structure
  653. * @addr: address
  654. * @regnum: register number
  655. * @val: value to write
  656. * @gssr: semaphore flags to acquire
  657. **/
  658. static int ixgbe_mii_bus_write_generic_c22(struct ixgbe_hw *hw, int addr,
  659. int regnum, u16 val, u32 gssr)
  660. {
  661. u32 hwaddr, cmd;
  662. int err;
  663. if (hw->mac.ops.acquire_swfw_sync(hw, gssr))
  664. return -EBUSY;
  665. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)val);
  666. hwaddr = addr << IXGBE_MSCA_PHY_ADDR_SHIFT;
  667. hwaddr |= (regnum & GENMASK(5, 0)) << IXGBE_MSCA_DEV_TYPE_SHIFT;
  668. cmd = hwaddr | IXGBE_MSCA_OLD_PROTOCOL | IXGBE_MSCA_WRITE |
  669. IXGBE_MSCA_MDI_COMMAND;
  670. err = ixgbe_msca_cmd(hw, cmd);
  671. hw->mac.ops.release_swfw_sync(hw, gssr);
  672. return err;
  673. }
  674. /**
  675. * ixgbe_mii_bus_write_generic_c45 - Write a clause 45 register with gssr flags
  676. * @hw: pointer to hardware structure
  677. * @addr: address
  678. * @devad: device address to read
  679. * @regnum: register number
  680. * @val: value to write
  681. * @gssr: semaphore flags to acquire
  682. **/
  683. static int ixgbe_mii_bus_write_generic_c45(struct ixgbe_hw *hw, int addr,
  684. int devad, int regnum, u16 val,
  685. u32 gssr)
  686. {
  687. u32 hwaddr, cmd;
  688. int err;
  689. if (hw->mac.ops.acquire_swfw_sync(hw, gssr))
  690. return -EBUSY;
  691. IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)val);
  692. hwaddr = addr << IXGBE_MSCA_PHY_ADDR_SHIFT;
  693. hwaddr |= devad << 16 | regnum;
  694. cmd = hwaddr | IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND;
  695. err = ixgbe_msca_cmd(hw, cmd);
  696. if (err < 0)
  697. goto mii_bus_write_done;
  698. cmd = hwaddr | IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND;
  699. err = ixgbe_msca_cmd(hw, cmd);
  700. mii_bus_write_done:
  701. hw->mac.ops.release_swfw_sync(hw, gssr);
  702. return err;
  703. }
  704. /**
  705. * ixgbe_mii_bus_read_c22 - Read a clause 22 register
  706. * @bus: pointer to mii_bus structure which points to our driver private
  707. * @addr: address
  708. * @regnum: register number
  709. **/
  710. static int ixgbe_mii_bus_read_c22(struct mii_bus *bus, int addr, int regnum)
  711. {
  712. struct ixgbe_adapter *adapter = bus->priv;
  713. struct ixgbe_hw *hw = &adapter->hw;
  714. u32 gssr = hw->phy.phy_semaphore_mask;
  715. return ixgbe_mii_bus_read_generic_c22(hw, addr, regnum, gssr);
  716. }
  717. /**
  718. * ixgbe_mii_bus_read_c45 - Read a clause 45 register
  719. * @bus: pointer to mii_bus structure which points to our driver private
  720. * @devad: device address to read
  721. * @addr: address
  722. * @regnum: register number
  723. **/
  724. static int ixgbe_mii_bus_read_c45(struct mii_bus *bus, int devad, int addr,
  725. int regnum)
  726. {
  727. struct ixgbe_adapter *adapter = bus->priv;
  728. struct ixgbe_hw *hw = &adapter->hw;
  729. u32 gssr = hw->phy.phy_semaphore_mask;
  730. return ixgbe_mii_bus_read_generic_c45(hw, addr, devad, regnum, gssr);
  731. }
  732. /**
  733. * ixgbe_mii_bus_write_c22 - Write a clause 22 register
  734. * @bus: pointer to mii_bus structure which points to our driver private
  735. * @addr: address
  736. * @regnum: register number
  737. * @val: value to write
  738. **/
  739. static int ixgbe_mii_bus_write_c22(struct mii_bus *bus, int addr, int regnum,
  740. u16 val)
  741. {
  742. struct ixgbe_adapter *adapter = bus->priv;
  743. struct ixgbe_hw *hw = &adapter->hw;
  744. u32 gssr = hw->phy.phy_semaphore_mask;
  745. return ixgbe_mii_bus_write_generic_c22(hw, addr, regnum, val, gssr);
  746. }
  747. /**
  748. * ixgbe_mii_bus_write_c45 - Write a clause 45 register
  749. * @bus: pointer to mii_bus structure which points to our driver private
  750. * @addr: address
  751. * @devad: device address to read
  752. * @regnum: register number
  753. * @val: value to write
  754. **/
  755. static int ixgbe_mii_bus_write_c45(struct mii_bus *bus, int addr, int devad,
  756. int regnum, u16 val)
  757. {
  758. struct ixgbe_adapter *adapter = bus->priv;
  759. struct ixgbe_hw *hw = &adapter->hw;
  760. u32 gssr = hw->phy.phy_semaphore_mask;
  761. return ixgbe_mii_bus_write_generic_c45(hw, addr, devad, regnum, val,
  762. gssr);
  763. }
  764. /**
  765. * ixgbe_x550em_a_mii_bus_read_c22 - Read a clause 22 register on x550em_a
  766. * @bus: pointer to mii_bus structure which points to our driver private
  767. * @addr: address
  768. * @regnum: register number
  769. **/
  770. static int ixgbe_x550em_a_mii_bus_read_c22(struct mii_bus *bus, int addr,
  771. int regnum)
  772. {
  773. struct ixgbe_adapter *adapter = bus->priv;
  774. struct ixgbe_hw *hw = &adapter->hw;
  775. u32 gssr = hw->phy.phy_semaphore_mask;
  776. gssr |= IXGBE_GSSR_TOKEN_SM | IXGBE_GSSR_PHY0_SM;
  777. return ixgbe_mii_bus_read_generic_c22(hw, addr, regnum, gssr);
  778. }
  779. /**
  780. * ixgbe_x550em_a_mii_bus_read_c45 - Read a clause 45 register on x550em_a
  781. * @bus: pointer to mii_bus structure which points to our driver private
  782. * @addr: address
  783. * @devad: device address to read
  784. * @regnum: register number
  785. **/
  786. static int ixgbe_x550em_a_mii_bus_read_c45(struct mii_bus *bus, int addr,
  787. int devad, int regnum)
  788. {
  789. struct ixgbe_adapter *adapter = bus->priv;
  790. struct ixgbe_hw *hw = &adapter->hw;
  791. u32 gssr = hw->phy.phy_semaphore_mask;
  792. gssr |= IXGBE_GSSR_TOKEN_SM | IXGBE_GSSR_PHY0_SM;
  793. return ixgbe_mii_bus_read_generic_c45(hw, addr, devad, regnum, gssr);
  794. }
  795. /**
  796. * ixgbe_x550em_a_mii_bus_write_c22 - Write a clause 22 register on x550em_a
  797. * @bus: pointer to mii_bus structure which points to our driver private
  798. * @addr: address
  799. * @regnum: register number
  800. * @val: value to write
  801. **/
  802. static int ixgbe_x550em_a_mii_bus_write_c22(struct mii_bus *bus, int addr,
  803. int regnum, u16 val)
  804. {
  805. struct ixgbe_adapter *adapter = bus->priv;
  806. struct ixgbe_hw *hw = &adapter->hw;
  807. u32 gssr = hw->phy.phy_semaphore_mask;
  808. gssr |= IXGBE_GSSR_TOKEN_SM | IXGBE_GSSR_PHY0_SM;
  809. return ixgbe_mii_bus_write_generic_c22(hw, addr, regnum, val, gssr);
  810. }
  811. /**
  812. * ixgbe_x550em_a_mii_bus_write_c45 - Write a clause 45 register on x550em_a
  813. * @bus: pointer to mii_bus structure which points to our driver private
  814. * @addr: address
  815. * @devad: device address to read
  816. * @regnum: register number
  817. * @val: value to write
  818. **/
  819. static int ixgbe_x550em_a_mii_bus_write_c45(struct mii_bus *bus, int addr,
  820. int devad, int regnum, u16 val)
  821. {
  822. struct ixgbe_adapter *adapter = bus->priv;
  823. struct ixgbe_hw *hw = &adapter->hw;
  824. u32 gssr = hw->phy.phy_semaphore_mask;
  825. gssr |= IXGBE_GSSR_TOKEN_SM | IXGBE_GSSR_PHY0_SM;
  826. return ixgbe_mii_bus_write_generic_c45(hw, addr, devad, regnum, val,
  827. gssr);
  828. }
  829. /**
  830. * ixgbe_get_first_secondary_devfn - get first device downstream of root port
  831. * @devfn: PCI_DEVFN of root port on domain 0, bus 0
  832. *
  833. * Returns pci_dev pointer to PCI_DEVFN(0, 0) on subordinate side of root
  834. * on domain 0, bus 0, devfn = 'devfn'
  835. **/
  836. static struct pci_dev *ixgbe_get_first_secondary_devfn(unsigned int devfn)
  837. {
  838. struct pci_dev *rp_pdev;
  839. int bus;
  840. rp_pdev = pci_get_domain_bus_and_slot(0, 0, devfn);
  841. if (rp_pdev && rp_pdev->subordinate) {
  842. bus = rp_pdev->subordinate->number;
  843. pci_dev_put(rp_pdev);
  844. return pci_get_domain_bus_and_slot(0, bus, 0);
  845. }
  846. pci_dev_put(rp_pdev);
  847. return NULL;
  848. }
  849. /**
  850. * ixgbe_x550em_a_has_mii - is this the first ixgbe x550em_a PCI function?
  851. * @hw: pointer to hardware structure
  852. *
  853. * Returns true if hw points to lowest numbered PCI B:D.F x550_em_a device in
  854. * the SoC. There are up to 4 MACs sharing a single MDIO bus on the x550em_a,
  855. * but we only want to register one MDIO bus.
  856. **/
  857. static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)
  858. {
  859. struct ixgbe_adapter *adapter = hw->back;
  860. struct pci_dev *pdev = adapter->pdev;
  861. struct pci_dev *func0_pdev;
  862. bool has_mii = false;
  863. /* For the C3000 family of SoCs (x550em_a) the internal ixgbe devices
  864. * are always downstream of root ports @ 0000:00:16.0 & 0000:00:17.0
  865. * It's not valid for function 0 to be disabled and function 1 is up,
  866. * so the lowest numbered ixgbe dev will be device 0 function 0 on one
  867. * of those two root ports
  868. */
  869. func0_pdev = ixgbe_get_first_secondary_devfn(PCI_DEVFN(0x16, 0));
  870. if (func0_pdev) {
  871. if (func0_pdev == pdev)
  872. has_mii = true;
  873. goto out;
  874. }
  875. func0_pdev = ixgbe_get_first_secondary_devfn(PCI_DEVFN(0x17, 0));
  876. if (func0_pdev == pdev)
  877. has_mii = true;
  878. out:
  879. pci_dev_put(func0_pdev);
  880. return has_mii;
  881. }
  882. /**
  883. * ixgbe_mii_bus_init - mii_bus structure setup
  884. * @hw: pointer to hardware structure
  885. *
  886. * Returns 0 on success, negative on failure
  887. *
  888. * ixgbe_mii_bus_init initializes a mii_bus structure in adapter
  889. **/
  890. int ixgbe_mii_bus_init(struct ixgbe_hw *hw)
  891. {
  892. int (*write_c22)(struct mii_bus *bus, int addr, int regnum, u16 val);
  893. int (*read_c22)(struct mii_bus *bus, int addr, int regnum);
  894. int (*write_c45)(struct mii_bus *bus, int addr, int devad, int regnum,
  895. u16 val);
  896. int (*read_c45)(struct mii_bus *bus, int addr, int devad, int regnum);
  897. struct ixgbe_adapter *adapter = hw->back;
  898. struct pci_dev *pdev = adapter->pdev;
  899. struct device *dev = &adapter->netdev->dev;
  900. struct mii_bus *bus;
  901. switch (hw->device_id) {
  902. /* C3000 SoCs */
  903. case IXGBE_DEV_ID_X550EM_A_KR:
  904. case IXGBE_DEV_ID_X550EM_A_KR_L:
  905. case IXGBE_DEV_ID_X550EM_A_SFP_N:
  906. case IXGBE_DEV_ID_X550EM_A_SGMII:
  907. case IXGBE_DEV_ID_X550EM_A_SGMII_L:
  908. case IXGBE_DEV_ID_X550EM_A_10G_T:
  909. case IXGBE_DEV_ID_X550EM_A_SFP:
  910. case IXGBE_DEV_ID_X550EM_A_1G_T:
  911. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  912. if (!ixgbe_x550em_a_has_mii(hw))
  913. return 0;
  914. read_c22 = ixgbe_x550em_a_mii_bus_read_c22;
  915. write_c22 = ixgbe_x550em_a_mii_bus_write_c22;
  916. read_c45 = ixgbe_x550em_a_mii_bus_read_c45;
  917. write_c45 = ixgbe_x550em_a_mii_bus_write_c45;
  918. break;
  919. default:
  920. read_c22 = ixgbe_mii_bus_read_c22;
  921. write_c22 = ixgbe_mii_bus_write_c22;
  922. read_c45 = ixgbe_mii_bus_read_c45;
  923. write_c45 = ixgbe_mii_bus_write_c45;
  924. break;
  925. }
  926. bus = devm_mdiobus_alloc(dev);
  927. if (!bus)
  928. return -ENOMEM;
  929. bus->read = read_c22;
  930. bus->write = write_c22;
  931. bus->read_c45 = read_c45;
  932. bus->write_c45 = write_c45;
  933. /* Use the position of the device in the PCI hierarchy as the id */
  934. snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mdio-%s", ixgbe_driver_name,
  935. pci_name(pdev));
  936. bus->name = "ixgbe-mdio";
  937. bus->priv = adapter;
  938. bus->parent = dev;
  939. bus->phy_mask = GENMASK(31, 0);
  940. /* Support clause 22/45 natively. ixgbe_probe() sets MDIO_EMULATE_C22
  941. * unfortunately that causes some clause 22 frames to be sent with
  942. * clause 45 addressing. We don't want that.
  943. */
  944. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22;
  945. adapter->mii_bus = bus;
  946. return mdiobus_register(bus);
  947. }
  948. /**
  949. * ixgbe_setup_phy_link_generic - Set and restart autoneg
  950. * @hw: pointer to hardware structure
  951. *
  952. * Restart autonegotiation and PHY and waits for completion.
  953. **/
  954. int ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
  955. {
  956. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  957. ixgbe_link_speed speed;
  958. bool autoneg = false;
  959. int status = 0;
  960. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  961. /* Set or unset auto-negotiation 10G advertisement */
  962. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, MDIO_MMD_AN, &autoneg_reg);
  963. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  964. if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) &&
  965. (speed & IXGBE_LINK_SPEED_10GB_FULL))
  966. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  967. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, MDIO_MMD_AN, autoneg_reg);
  968. hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  969. MDIO_MMD_AN, &autoneg_reg);
  970. if (hw->mac.type == ixgbe_mac_X550) {
  971. /* Set or unset auto-negotiation 5G advertisement */
  972. autoneg_reg &= ~IXGBE_MII_5GBASE_T_ADVERTISE;
  973. if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_5GB_FULL) &&
  974. (speed & IXGBE_LINK_SPEED_5GB_FULL))
  975. autoneg_reg |= IXGBE_MII_5GBASE_T_ADVERTISE;
  976. /* Set or unset auto-negotiation 2.5G advertisement */
  977. autoneg_reg &= ~IXGBE_MII_2_5GBASE_T_ADVERTISE;
  978. if ((hw->phy.autoneg_advertised &
  979. IXGBE_LINK_SPEED_2_5GB_FULL) &&
  980. (speed & IXGBE_LINK_SPEED_2_5GB_FULL))
  981. autoneg_reg |= IXGBE_MII_2_5GBASE_T_ADVERTISE;
  982. }
  983. /* Set or unset auto-negotiation 1G advertisement */
  984. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
  985. if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) &&
  986. (speed & IXGBE_LINK_SPEED_1GB_FULL))
  987. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
  988. hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  989. MDIO_MMD_AN, autoneg_reg);
  990. /* Set or unset auto-negotiation 100M advertisement */
  991. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
  992. autoneg_reg &= ~(ADVERTISE_100FULL | ADVERTISE_100HALF);
  993. if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) &&
  994. (speed & IXGBE_LINK_SPEED_100_FULL))
  995. autoneg_reg |= ADVERTISE_100FULL;
  996. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
  997. /* Blocked by MNG FW so don't reset PHY */
  998. if (ixgbe_check_reset_blocked(hw))
  999. return 0;
  1000. /* Restart PHY autonegotiation and wait for completion */
  1001. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  1002. MDIO_MMD_AN, &autoneg_reg);
  1003. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  1004. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  1005. MDIO_MMD_AN, autoneg_reg);
  1006. return status;
  1007. }
  1008. /**
  1009. * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
  1010. * @hw: pointer to hardware structure
  1011. * @speed: new link speed
  1012. * @autoneg_wait_to_complete: unused
  1013. **/
  1014. int ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
  1015. ixgbe_link_speed speed,
  1016. bool autoneg_wait_to_complete)
  1017. {
  1018. /* Clear autoneg_advertised and set new values based on input link
  1019. * speed.
  1020. */
  1021. hw->phy.autoneg_advertised = 0;
  1022. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  1023. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  1024. if (speed & IXGBE_LINK_SPEED_5GB_FULL)
  1025. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_5GB_FULL;
  1026. if (speed & IXGBE_LINK_SPEED_2_5GB_FULL)
  1027. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_2_5GB_FULL;
  1028. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  1029. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  1030. if (speed & IXGBE_LINK_SPEED_100_FULL)
  1031. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  1032. if (speed & IXGBE_LINK_SPEED_10_FULL)
  1033. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10_FULL;
  1034. /* Setup link based on the new speed settings */
  1035. if (hw->phy.ops.setup_link)
  1036. hw->phy.ops.setup_link(hw);
  1037. return 0;
  1038. }
  1039. /**
  1040. * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
  1041. * @hw: pointer to hardware structure
  1042. *
  1043. * Determines the supported link capabilities by reading the PHY auto
  1044. * negotiation register.
  1045. */
  1046. static int ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
  1047. {
  1048. u16 speed_ability;
  1049. int status;
  1050. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  1051. &speed_ability);
  1052. if (status)
  1053. return status;
  1054. if (speed_ability & MDIO_SPEED_10G)
  1055. hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
  1056. if (speed_ability & MDIO_PMA_SPEED_1000)
  1057. hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
  1058. if (speed_ability & MDIO_PMA_SPEED_100)
  1059. hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
  1060. switch (hw->mac.type) {
  1061. case ixgbe_mac_X550:
  1062. hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
  1063. hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
  1064. break;
  1065. case ixgbe_mac_X550EM_x:
  1066. case ixgbe_mac_x550em_a:
  1067. hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
  1068. break;
  1069. default:
  1070. break;
  1071. }
  1072. return 0;
  1073. }
  1074. /**
  1075. * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
  1076. * @hw: pointer to hardware structure
  1077. * @speed: pointer to link speed
  1078. * @autoneg: boolean auto-negotiation value
  1079. */
  1080. int ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
  1081. ixgbe_link_speed *speed,
  1082. bool *autoneg)
  1083. {
  1084. int status = 0;
  1085. *autoneg = true;
  1086. if (!hw->phy.speeds_supported)
  1087. status = ixgbe_get_copper_speeds_supported(hw);
  1088. *speed = hw->phy.speeds_supported;
  1089. return status;
  1090. }
  1091. /**
  1092. * ixgbe_check_phy_link_tnx - Determine link and speed status
  1093. * @hw: pointer to hardware structure
  1094. * @speed: link speed
  1095. * @link_up: status of link
  1096. *
  1097. * Reads the VS1 register to determine if link is up and the current speed for
  1098. * the PHY.
  1099. **/
  1100. int ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  1101. bool *link_up)
  1102. {
  1103. u32 max_time_out = 10;
  1104. u16 phy_speed = 0;
  1105. u16 phy_link = 0;
  1106. u16 phy_data = 0;
  1107. u32 time_out;
  1108. int status;
  1109. /* Initialize speed and link to default case */
  1110. *link_up = false;
  1111. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  1112. /*
  1113. * Check current speed and link status of the PHY register.
  1114. * This is a vendor specific register and may have to
  1115. * be changed for other copper PHYs.
  1116. */
  1117. for (time_out = 0; time_out < max_time_out; time_out++) {
  1118. udelay(10);
  1119. status = hw->phy.ops.read_reg(hw,
  1120. MDIO_STAT1,
  1121. MDIO_MMD_VEND1,
  1122. &phy_data);
  1123. phy_link = phy_data &
  1124. IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
  1125. phy_speed = phy_data &
  1126. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
  1127. if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
  1128. *link_up = true;
  1129. if (phy_speed ==
  1130. IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
  1131. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1132. break;
  1133. }
  1134. }
  1135. return status;
  1136. }
  1137. /**
  1138. * ixgbe_setup_phy_link_tnx - Set and restart autoneg
  1139. * @hw: pointer to hardware structure
  1140. *
  1141. * Restart autonegotiation and PHY and waits for completion.
  1142. * This function always returns success, this is nessary since
  1143. * it is called via a function pointer that could call other
  1144. * functions that could return an error.
  1145. **/
  1146. int ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
  1147. {
  1148. u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
  1149. bool autoneg = false;
  1150. ixgbe_link_speed speed;
  1151. ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
  1152. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  1153. /* Set or unset auto-negotiation 10G advertisement */
  1154. hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  1155. MDIO_MMD_AN,
  1156. &autoneg_reg);
  1157. autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
  1158. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  1159. autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
  1160. hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
  1161. MDIO_MMD_AN,
  1162. autoneg_reg);
  1163. }
  1164. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  1165. /* Set or unset auto-negotiation 1G advertisement */
  1166. hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  1167. MDIO_MMD_AN,
  1168. &autoneg_reg);
  1169. autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  1170. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  1171. autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
  1172. hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
  1173. MDIO_MMD_AN,
  1174. autoneg_reg);
  1175. }
  1176. if (speed & IXGBE_LINK_SPEED_100_FULL) {
  1177. /* Set or unset auto-negotiation 100M advertisement */
  1178. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  1179. MDIO_MMD_AN,
  1180. &autoneg_reg);
  1181. autoneg_reg &= ~(ADVERTISE_100FULL |
  1182. ADVERTISE_100HALF);
  1183. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
  1184. autoneg_reg |= ADVERTISE_100FULL;
  1185. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  1186. MDIO_MMD_AN,
  1187. autoneg_reg);
  1188. }
  1189. /* Blocked by MNG FW so don't reset PHY */
  1190. if (ixgbe_check_reset_blocked(hw))
  1191. return 0;
  1192. /* Restart PHY autonegotiation and wait for completion */
  1193. hw->phy.ops.read_reg(hw, MDIO_CTRL1,
  1194. MDIO_MMD_AN, &autoneg_reg);
  1195. autoneg_reg |= MDIO_AN_CTRL1_RESTART;
  1196. hw->phy.ops.write_reg(hw, MDIO_CTRL1,
  1197. MDIO_MMD_AN, autoneg_reg);
  1198. return 0;
  1199. }
  1200. /**
  1201. * ixgbe_reset_phy_nl - Performs a PHY reset
  1202. * @hw: pointer to hardware structure
  1203. **/
  1204. int ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
  1205. {
  1206. u16 phy_offset, control, eword, edata, block_crc;
  1207. u16 list_offset, data_offset;
  1208. bool end_data = false;
  1209. u16 phy_data = 0;
  1210. int ret_val;
  1211. u32 i;
  1212. /* Blocked by MNG FW so bail */
  1213. if (ixgbe_check_reset_blocked(hw))
  1214. return 0;
  1215. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
  1216. /* reset the PHY and poll for completion */
  1217. hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  1218. (phy_data | MDIO_CTRL1_RESET));
  1219. for (i = 0; i < 100; i++) {
  1220. hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
  1221. &phy_data);
  1222. if ((phy_data & MDIO_CTRL1_RESET) == 0)
  1223. break;
  1224. usleep_range(10000, 20000);
  1225. }
  1226. if ((phy_data & MDIO_CTRL1_RESET) != 0) {
  1227. hw_dbg(hw, "PHY reset did not complete.\n");
  1228. return -EIO;
  1229. }
  1230. /* Get init offsets */
  1231. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  1232. &data_offset);
  1233. if (ret_val)
  1234. return ret_val;
  1235. ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
  1236. data_offset++;
  1237. while (!end_data) {
  1238. /*
  1239. * Read control word from PHY init contents offset
  1240. */
  1241. ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
  1242. if (ret_val)
  1243. goto err_eeprom;
  1244. control = FIELD_GET(IXGBE_CONTROL_MASK_NL, eword);
  1245. edata = eword & IXGBE_DATA_MASK_NL;
  1246. switch (control) {
  1247. case IXGBE_DELAY_NL:
  1248. data_offset++;
  1249. hw_dbg(hw, "DELAY: %d MS\n", edata);
  1250. usleep_range(edata * 1000, edata * 2000);
  1251. break;
  1252. case IXGBE_DATA_NL:
  1253. hw_dbg(hw, "DATA:\n");
  1254. data_offset++;
  1255. ret_val = hw->eeprom.ops.read(hw, data_offset++,
  1256. &phy_offset);
  1257. if (ret_val)
  1258. goto err_eeprom;
  1259. for (i = 0; i < edata; i++) {
  1260. ret_val = hw->eeprom.ops.read(hw, data_offset,
  1261. &eword);
  1262. if (ret_val)
  1263. goto err_eeprom;
  1264. hw->phy.ops.write_reg(hw, phy_offset,
  1265. MDIO_MMD_PMAPMD, eword);
  1266. hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
  1267. phy_offset);
  1268. data_offset++;
  1269. phy_offset++;
  1270. }
  1271. break;
  1272. case IXGBE_CONTROL_NL:
  1273. data_offset++;
  1274. hw_dbg(hw, "CONTROL:\n");
  1275. if (edata == IXGBE_CONTROL_EOL_NL) {
  1276. hw_dbg(hw, "EOL\n");
  1277. end_data = true;
  1278. } else if (edata == IXGBE_CONTROL_SOL_NL) {
  1279. hw_dbg(hw, "SOL\n");
  1280. } else {
  1281. hw_dbg(hw, "Bad control value\n");
  1282. return -EIO;
  1283. }
  1284. break;
  1285. default:
  1286. hw_dbg(hw, "Bad control type\n");
  1287. return -EIO;
  1288. }
  1289. }
  1290. return ret_val;
  1291. err_eeprom:
  1292. hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
  1293. return -EIO;
  1294. }
  1295. /**
  1296. * ixgbe_identify_module_generic - Identifies module type
  1297. * @hw: pointer to hardware structure
  1298. *
  1299. * Determines HW type and calls appropriate function.
  1300. **/
  1301. int ixgbe_identify_module_generic(struct ixgbe_hw *hw)
  1302. {
  1303. switch (hw->mac.ops.get_media_type(hw)) {
  1304. case ixgbe_media_type_fiber:
  1305. return ixgbe_identify_sfp_module_generic(hw);
  1306. case ixgbe_media_type_fiber_qsfp:
  1307. return ixgbe_identify_qsfp_module_generic(hw);
  1308. default:
  1309. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1310. return -ENOENT;
  1311. }
  1312. return -ENOENT;
  1313. }
  1314. /**
  1315. * ixgbe_identify_sfp_module_generic - Identifies SFP modules
  1316. * @hw: pointer to hardware structure
  1317. *
  1318. * Searches for and identifies the SFP module and assigns appropriate PHY type.
  1319. **/
  1320. int ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
  1321. {
  1322. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  1323. struct ixgbe_adapter *adapter = hw->back;
  1324. u8 oui_bytes[3] = {0, 0, 0};
  1325. u8 bitrate_nominal = 0;
  1326. u8 comp_codes_10g = 0;
  1327. u8 comp_codes_1g = 0;
  1328. u16 enforce_sfp = 0;
  1329. u32 vendor_oui = 0;
  1330. u8 identifier = 0;
  1331. u8 cable_tech = 0;
  1332. u8 cable_spec = 0;
  1333. int status;
  1334. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
  1335. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1336. return -ENOENT;
  1337. }
  1338. /* LAN ID is needed for sfp_type determination */
  1339. hw->mac.ops.set_lan_id(hw);
  1340. status = hw->phy.ops.read_i2c_eeprom(hw,
  1341. IXGBE_SFF_IDENTIFIER,
  1342. &identifier);
  1343. if (status)
  1344. goto err_read_i2c_eeprom;
  1345. if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
  1346. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1347. return -EOPNOTSUPP;
  1348. }
  1349. status = hw->phy.ops.read_i2c_eeprom(hw,
  1350. IXGBE_SFF_1GBE_COMP_CODES,
  1351. &comp_codes_1g);
  1352. if (status)
  1353. goto err_read_i2c_eeprom;
  1354. status = hw->phy.ops.read_i2c_eeprom(hw,
  1355. IXGBE_SFF_10GBE_COMP_CODES,
  1356. &comp_codes_10g);
  1357. if (status)
  1358. goto err_read_i2c_eeprom;
  1359. status = hw->phy.ops.read_i2c_eeprom(hw,
  1360. IXGBE_SFF_CABLE_TECHNOLOGY,
  1361. &cable_tech);
  1362. if (status)
  1363. goto err_read_i2c_eeprom;
  1364. status = hw->phy.ops.read_i2c_eeprom(hw,
  1365. IXGBE_SFF_BITRATE_NOMINAL,
  1366. &bitrate_nominal);
  1367. if (status)
  1368. goto err_read_i2c_eeprom;
  1369. /* ID Module
  1370. * =========
  1371. * 0 SFP_DA_CU
  1372. * 1 SFP_SR
  1373. * 2 SFP_LR
  1374. * 3 SFP_DA_CORE0 - 82599-specific
  1375. * 4 SFP_DA_CORE1 - 82599-specific
  1376. * 5 SFP_SR/LR_CORE0 - 82599-specific
  1377. * 6 SFP_SR/LR_CORE1 - 82599-specific
  1378. * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
  1379. * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
  1380. * 9 SFP_1g_cu_CORE0 - 82599-specific
  1381. * 10 SFP_1g_cu_CORE1 - 82599-specific
  1382. * 11 SFP_1g_sx_CORE0 - 82599-specific
  1383. * 12 SFP_1g_sx_CORE1 - 82599-specific
  1384. */
  1385. if (hw->mac.type == ixgbe_mac_82598EB) {
  1386. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  1387. hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
  1388. else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  1389. hw->phy.sfp_type = ixgbe_sfp_type_sr;
  1390. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  1391. hw->phy.sfp_type = ixgbe_sfp_type_lr;
  1392. else
  1393. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  1394. } else {
  1395. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
  1396. if (hw->bus.lan_id == 0)
  1397. hw->phy.sfp_type =
  1398. ixgbe_sfp_type_da_cu_core0;
  1399. else
  1400. hw->phy.sfp_type =
  1401. ixgbe_sfp_type_da_cu_core1;
  1402. } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
  1403. hw->phy.ops.read_i2c_eeprom(
  1404. hw, IXGBE_SFF_CABLE_SPEC_COMP,
  1405. &cable_spec);
  1406. if (cable_spec &
  1407. IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
  1408. if (hw->bus.lan_id == 0)
  1409. hw->phy.sfp_type =
  1410. ixgbe_sfp_type_da_act_lmt_core0;
  1411. else
  1412. hw->phy.sfp_type =
  1413. ixgbe_sfp_type_da_act_lmt_core1;
  1414. } else {
  1415. hw->phy.sfp_type =
  1416. ixgbe_sfp_type_unknown;
  1417. }
  1418. } else if (comp_codes_10g &
  1419. (IXGBE_SFF_10GBASESR_CAPABLE |
  1420. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1421. if (hw->bus.lan_id == 0)
  1422. hw->phy.sfp_type =
  1423. ixgbe_sfp_type_srlr_core0;
  1424. else
  1425. hw->phy.sfp_type =
  1426. ixgbe_sfp_type_srlr_core1;
  1427. } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
  1428. if (hw->bus.lan_id == 0)
  1429. hw->phy.sfp_type =
  1430. ixgbe_sfp_type_1g_cu_core0;
  1431. else
  1432. hw->phy.sfp_type =
  1433. ixgbe_sfp_type_1g_cu_core1;
  1434. } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
  1435. if (hw->bus.lan_id == 0)
  1436. hw->phy.sfp_type =
  1437. ixgbe_sfp_type_1g_sx_core0;
  1438. else
  1439. hw->phy.sfp_type =
  1440. ixgbe_sfp_type_1g_sx_core1;
  1441. } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
  1442. if (hw->bus.lan_id == 0)
  1443. hw->phy.sfp_type =
  1444. ixgbe_sfp_type_1g_lx_core0;
  1445. else
  1446. hw->phy.sfp_type =
  1447. ixgbe_sfp_type_1g_lx_core1;
  1448. /* Support only Ethernet 1000BASE-BX10, checking the Bit Rate
  1449. * Nominal Value as per SFF-8472 by convention 1.25 Gb/s should
  1450. * be rounded up to 0Dh (13 in units of 100 MBd) for 1000BASE-BX
  1451. */
  1452. } else if ((comp_codes_1g & IXGBE_SFF_BASEBX10_CAPABLE) &&
  1453. (bitrate_nominal == 0xD)) {
  1454. if (hw->bus.lan_id == 0)
  1455. hw->phy.sfp_type =
  1456. ixgbe_sfp_type_1g_bx_core0;
  1457. else
  1458. hw->phy.sfp_type =
  1459. ixgbe_sfp_type_1g_bx_core1;
  1460. } else {
  1461. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  1462. }
  1463. }
  1464. if (hw->phy.sfp_type != stored_sfp_type)
  1465. hw->phy.sfp_setup_needed = true;
  1466. /* Determine if the SFP+ PHY is dual speed or not. */
  1467. hw->phy.multispeed_fiber = false;
  1468. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  1469. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  1470. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  1471. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  1472. hw->phy.multispeed_fiber = true;
  1473. /* Determine PHY vendor */
  1474. if (hw->phy.type != ixgbe_phy_nl) {
  1475. hw->phy.id = identifier;
  1476. status = hw->phy.ops.read_i2c_eeprom(hw,
  1477. IXGBE_SFF_VENDOR_OUI_BYTE0,
  1478. &oui_bytes[0]);
  1479. if (status != 0)
  1480. goto err_read_i2c_eeprom;
  1481. status = hw->phy.ops.read_i2c_eeprom(hw,
  1482. IXGBE_SFF_VENDOR_OUI_BYTE1,
  1483. &oui_bytes[1]);
  1484. if (status != 0)
  1485. goto err_read_i2c_eeprom;
  1486. status = hw->phy.ops.read_i2c_eeprom(hw,
  1487. IXGBE_SFF_VENDOR_OUI_BYTE2,
  1488. &oui_bytes[2]);
  1489. if (status != 0)
  1490. goto err_read_i2c_eeprom;
  1491. vendor_oui =
  1492. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  1493. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  1494. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  1495. switch (vendor_oui) {
  1496. case IXGBE_SFF_VENDOR_OUI_TYCO:
  1497. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  1498. hw->phy.type =
  1499. ixgbe_phy_sfp_passive_tyco;
  1500. break;
  1501. case IXGBE_SFF_VENDOR_OUI_FTL:
  1502. if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  1503. hw->phy.type = ixgbe_phy_sfp_ftl_active;
  1504. else
  1505. hw->phy.type = ixgbe_phy_sfp_ftl;
  1506. break;
  1507. case IXGBE_SFF_VENDOR_OUI_AVAGO:
  1508. hw->phy.type = ixgbe_phy_sfp_avago;
  1509. break;
  1510. case IXGBE_SFF_VENDOR_OUI_INTEL:
  1511. hw->phy.type = ixgbe_phy_sfp_intel;
  1512. break;
  1513. default:
  1514. if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
  1515. hw->phy.type =
  1516. ixgbe_phy_sfp_passive_unknown;
  1517. else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
  1518. hw->phy.type =
  1519. ixgbe_phy_sfp_active_unknown;
  1520. else
  1521. hw->phy.type = ixgbe_phy_sfp_unknown;
  1522. break;
  1523. }
  1524. }
  1525. /* Allow any DA cable vendor */
  1526. if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
  1527. IXGBE_SFF_DA_ACTIVE_CABLE))
  1528. return 0;
  1529. /* Verify supported 1G SFP modules */
  1530. if (comp_codes_10g == 0 &&
  1531. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  1532. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  1533. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  1534. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  1535. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  1536. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1 ||
  1537. hw->phy.sfp_type == ixgbe_sfp_type_1g_bx_core0 ||
  1538. hw->phy.sfp_type == ixgbe_sfp_type_1g_bx_core1)) {
  1539. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1540. return -EOPNOTSUPP;
  1541. }
  1542. /* Anything else 82598-based is supported */
  1543. if (hw->mac.type == ixgbe_mac_82598EB)
  1544. return 0;
  1545. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  1546. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
  1547. !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  1548. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  1549. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  1550. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  1551. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  1552. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1 ||
  1553. hw->phy.sfp_type == ixgbe_sfp_type_1g_bx_core0 ||
  1554. hw->phy.sfp_type == ixgbe_sfp_type_1g_bx_core1)) {
  1555. /* Make sure we're a supported PHY type */
  1556. if (hw->phy.type == ixgbe_phy_sfp_intel)
  1557. return 0;
  1558. if (hw->allow_unsupported_sfp) {
  1559. 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");
  1560. return 0;
  1561. }
  1562. hw_dbg(hw, "SFP+ module not supported\n");
  1563. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1564. return -EOPNOTSUPP;
  1565. }
  1566. return 0;
  1567. err_read_i2c_eeprom:
  1568. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1569. if (hw->phy.type != ixgbe_phy_nl) {
  1570. hw->phy.id = 0;
  1571. hw->phy.type = ixgbe_phy_unknown;
  1572. }
  1573. return -ENOENT;
  1574. }
  1575. /**
  1576. * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
  1577. * @hw: pointer to hardware structure
  1578. *
  1579. * Searches for and identifies the QSFP module and assigns appropriate PHY type
  1580. **/
  1581. static int ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
  1582. {
  1583. struct ixgbe_adapter *adapter = hw->back;
  1584. int status;
  1585. u32 vendor_oui = 0;
  1586. enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
  1587. u8 identifier = 0;
  1588. u8 comp_codes_1g = 0;
  1589. u8 comp_codes_10g = 0;
  1590. u8 oui_bytes[3] = {0, 0, 0};
  1591. u16 enforce_sfp = 0;
  1592. u8 connector = 0;
  1593. u8 cable_length = 0;
  1594. u8 device_tech = 0;
  1595. bool active_cable = false;
  1596. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
  1597. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1598. return -ENOENT;
  1599. }
  1600. /* LAN ID is needed for sfp_type determination */
  1601. hw->mac.ops.set_lan_id(hw);
  1602. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
  1603. &identifier);
  1604. if (status != 0)
  1605. goto err_read_i2c_eeprom;
  1606. if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
  1607. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1608. return -EOPNOTSUPP;
  1609. }
  1610. hw->phy.id = identifier;
  1611. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
  1612. &comp_codes_10g);
  1613. if (status != 0)
  1614. goto err_read_i2c_eeprom;
  1615. status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
  1616. &comp_codes_1g);
  1617. if (status != 0)
  1618. goto err_read_i2c_eeprom;
  1619. if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
  1620. hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
  1621. if (hw->bus.lan_id == 0)
  1622. hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
  1623. else
  1624. hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
  1625. } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
  1626. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1627. if (hw->bus.lan_id == 0)
  1628. hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
  1629. else
  1630. hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
  1631. } else {
  1632. if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
  1633. active_cable = true;
  1634. if (!active_cable) {
  1635. /* check for active DA cables that pre-date
  1636. * SFF-8436 v3.6
  1637. */
  1638. hw->phy.ops.read_i2c_eeprom(hw,
  1639. IXGBE_SFF_QSFP_CONNECTOR,
  1640. &connector);
  1641. hw->phy.ops.read_i2c_eeprom(hw,
  1642. IXGBE_SFF_QSFP_CABLE_LENGTH,
  1643. &cable_length);
  1644. hw->phy.ops.read_i2c_eeprom(hw,
  1645. IXGBE_SFF_QSFP_DEVICE_TECH,
  1646. &device_tech);
  1647. if ((connector ==
  1648. IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
  1649. (cable_length > 0) &&
  1650. ((device_tech >> 4) ==
  1651. IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
  1652. active_cable = true;
  1653. }
  1654. if (active_cable) {
  1655. hw->phy.type = ixgbe_phy_qsfp_active_unknown;
  1656. if (hw->bus.lan_id == 0)
  1657. hw->phy.sfp_type =
  1658. ixgbe_sfp_type_da_act_lmt_core0;
  1659. else
  1660. hw->phy.sfp_type =
  1661. ixgbe_sfp_type_da_act_lmt_core1;
  1662. } else {
  1663. /* unsupported module type */
  1664. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1665. return -EOPNOTSUPP;
  1666. }
  1667. }
  1668. if (hw->phy.sfp_type != stored_sfp_type)
  1669. hw->phy.sfp_setup_needed = true;
  1670. /* Determine if the QSFP+ PHY is dual speed or not. */
  1671. hw->phy.multispeed_fiber = false;
  1672. if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
  1673. (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
  1674. ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
  1675. (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
  1676. hw->phy.multispeed_fiber = true;
  1677. /* Determine PHY vendor for optical modules */
  1678. if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
  1679. IXGBE_SFF_10GBASELR_CAPABLE)) {
  1680. status = hw->phy.ops.read_i2c_eeprom(hw,
  1681. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
  1682. &oui_bytes[0]);
  1683. if (status != 0)
  1684. goto err_read_i2c_eeprom;
  1685. status = hw->phy.ops.read_i2c_eeprom(hw,
  1686. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
  1687. &oui_bytes[1]);
  1688. if (status != 0)
  1689. goto err_read_i2c_eeprom;
  1690. status = hw->phy.ops.read_i2c_eeprom(hw,
  1691. IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
  1692. &oui_bytes[2]);
  1693. if (status != 0)
  1694. goto err_read_i2c_eeprom;
  1695. vendor_oui =
  1696. ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
  1697. (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
  1698. (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
  1699. if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
  1700. hw->phy.type = ixgbe_phy_qsfp_intel;
  1701. else
  1702. hw->phy.type = ixgbe_phy_qsfp_unknown;
  1703. hw->mac.ops.get_device_caps(hw, &enforce_sfp);
  1704. if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
  1705. /* Make sure we're a supported PHY type */
  1706. if (hw->phy.type == ixgbe_phy_qsfp_intel)
  1707. return 0;
  1708. if (hw->allow_unsupported_sfp) {
  1709. 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");
  1710. return 0;
  1711. }
  1712. hw_dbg(hw, "QSFP module not supported\n");
  1713. hw->phy.type = ixgbe_phy_sfp_unsupported;
  1714. return -EOPNOTSUPP;
  1715. }
  1716. return 0;
  1717. }
  1718. return 0;
  1719. err_read_i2c_eeprom:
  1720. hw->phy.sfp_type = ixgbe_sfp_type_not_present;
  1721. hw->phy.id = 0;
  1722. hw->phy.type = ixgbe_phy_unknown;
  1723. return -ENOENT;
  1724. }
  1725. /**
  1726. * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
  1727. * @hw: pointer to hardware structure
  1728. * @list_offset: offset to the SFP ID list
  1729. * @data_offset: offset to the SFP data block
  1730. *
  1731. * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
  1732. * so it returns the offsets to the phy init sequence block.
  1733. **/
  1734. int ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
  1735. u16 *list_offset,
  1736. u16 *data_offset)
  1737. {
  1738. u16 sfp_id;
  1739. u16 sfp_type = hw->phy.sfp_type;
  1740. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  1741. return -EOPNOTSUPP;
  1742. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  1743. return -ENOENT;
  1744. if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
  1745. (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
  1746. return -EOPNOTSUPP;
  1747. /*
  1748. * Limiting active cables and 1G Phys must be initialized as
  1749. * SR modules
  1750. */
  1751. if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
  1752. sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  1753. sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  1754. sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  1755. sfp_type == ixgbe_sfp_type_1g_bx_core0)
  1756. sfp_type = ixgbe_sfp_type_srlr_core0;
  1757. else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
  1758. sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  1759. sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  1760. sfp_type == ixgbe_sfp_type_1g_sx_core1 ||
  1761. sfp_type == ixgbe_sfp_type_1g_bx_core1)
  1762. sfp_type = ixgbe_sfp_type_srlr_core1;
  1763. /* Read offset to PHY init contents */
  1764. if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
  1765. hw_err(hw, "eeprom read at %d failed\n",
  1766. IXGBE_PHY_INIT_OFFSET_NL);
  1767. return -EIO;
  1768. }
  1769. if ((!*list_offset) || (*list_offset == 0xFFFF))
  1770. return -EIO;
  1771. /* Shift offset to first ID word */
  1772. (*list_offset)++;
  1773. /*
  1774. * Find the matching SFP ID in the EEPROM
  1775. * and program the init sequence
  1776. */
  1777. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1778. goto err_phy;
  1779. while (sfp_id != IXGBE_PHY_INIT_END_NL) {
  1780. if (sfp_id == sfp_type) {
  1781. (*list_offset)++;
  1782. if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
  1783. goto err_phy;
  1784. if ((!*data_offset) || (*data_offset == 0xFFFF)) {
  1785. hw_dbg(hw, "SFP+ module not supported\n");
  1786. return -EOPNOTSUPP;
  1787. } else {
  1788. break;
  1789. }
  1790. } else {
  1791. (*list_offset) += 2;
  1792. if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
  1793. goto err_phy;
  1794. }
  1795. }
  1796. if (sfp_id == IXGBE_PHY_INIT_END_NL) {
  1797. hw_dbg(hw, "No matching SFP+ module found\n");
  1798. return -EOPNOTSUPP;
  1799. }
  1800. return 0;
  1801. err_phy:
  1802. hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
  1803. return -EIO;
  1804. }
  1805. /**
  1806. * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
  1807. * @hw: pointer to hardware structure
  1808. * @byte_offset: EEPROM byte offset to read
  1809. * @eeprom_data: value read
  1810. *
  1811. * Performs byte read operation to SFP module's EEPROM over I2C interface.
  1812. **/
  1813. int ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1814. u8 *eeprom_data)
  1815. {
  1816. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1817. IXGBE_I2C_EEPROM_DEV_ADDR,
  1818. eeprom_data);
  1819. }
  1820. /**
  1821. * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
  1822. * @hw: pointer to hardware structure
  1823. * @byte_offset: byte offset at address 0xA2
  1824. * @sff8472_data: value read
  1825. *
  1826. * Performs byte read operation to SFP module's SFF-8472 data over I2C
  1827. **/
  1828. int ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1829. u8 *sff8472_data)
  1830. {
  1831. return hw->phy.ops.read_i2c_byte(hw, byte_offset,
  1832. IXGBE_I2C_EEPROM_DEV_ADDR2,
  1833. sff8472_data);
  1834. }
  1835. /**
  1836. * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
  1837. * @hw: pointer to hardware structure
  1838. * @byte_offset: EEPROM byte offset to write
  1839. * @eeprom_data: value to write
  1840. *
  1841. * Performs byte write operation to SFP module's EEPROM over I2C interface.
  1842. **/
  1843. int ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1844. u8 eeprom_data)
  1845. {
  1846. return hw->phy.ops.write_i2c_byte(hw, byte_offset,
  1847. IXGBE_I2C_EEPROM_DEV_ADDR,
  1848. eeprom_data);
  1849. }
  1850. /**
  1851. * ixgbe_is_sfp_probe - Returns true if SFP is being detected
  1852. * @hw: pointer to hardware structure
  1853. * @offset: eeprom offset to be read
  1854. * @addr: I2C address to be read
  1855. */
  1856. static bool ixgbe_is_sfp_probe(struct ixgbe_hw *hw, u8 offset, u8 addr)
  1857. {
  1858. if (addr == IXGBE_I2C_EEPROM_DEV_ADDR &&
  1859. offset == IXGBE_SFF_IDENTIFIER &&
  1860. hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  1861. return true;
  1862. return false;
  1863. }
  1864. /**
  1865. * ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
  1866. * @hw: pointer to hardware structure
  1867. * @byte_offset: byte offset to read
  1868. * @dev_addr: device address
  1869. * @data: value read
  1870. * @lock: true if to take and release semaphore
  1871. *
  1872. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1873. * a specified device address.
  1874. */
  1875. static int ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
  1876. u8 dev_addr, u8 *data, bool lock)
  1877. {
  1878. u32 swfw_mask = hw->phy.phy_semaphore_mask;
  1879. u32 max_retry = 10;
  1880. bool nack = true;
  1881. u32 retry = 0;
  1882. int status;
  1883. if (hw->mac.type >= ixgbe_mac_X550)
  1884. max_retry = 3;
  1885. if (ixgbe_is_sfp_probe(hw, byte_offset, dev_addr))
  1886. max_retry = IXGBE_SFP_DETECT_RETRIES;
  1887. *data = 0;
  1888. do {
  1889. if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
  1890. return -EBUSY;
  1891. ixgbe_i2c_start(hw);
  1892. /* Device Address and write indication */
  1893. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1894. if (status != 0)
  1895. goto fail;
  1896. status = ixgbe_get_i2c_ack(hw);
  1897. if (status != 0)
  1898. goto fail;
  1899. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1900. if (status != 0)
  1901. goto fail;
  1902. status = ixgbe_get_i2c_ack(hw);
  1903. if (status != 0)
  1904. goto fail;
  1905. ixgbe_i2c_start(hw);
  1906. /* Device Address and read indication */
  1907. status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
  1908. if (status != 0)
  1909. goto fail;
  1910. status = ixgbe_get_i2c_ack(hw);
  1911. if (status != 0)
  1912. goto fail;
  1913. status = ixgbe_clock_in_i2c_byte(hw, data);
  1914. if (status != 0)
  1915. goto fail;
  1916. status = ixgbe_clock_out_i2c_bit(hw, nack);
  1917. if (status != 0)
  1918. goto fail;
  1919. ixgbe_i2c_stop(hw);
  1920. if (lock)
  1921. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1922. return 0;
  1923. fail:
  1924. ixgbe_i2c_bus_clear(hw);
  1925. if (lock) {
  1926. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  1927. msleep(100);
  1928. }
  1929. retry++;
  1930. if (retry < max_retry)
  1931. hw_dbg(hw, "I2C byte read error - Retrying.\n");
  1932. else
  1933. hw_dbg(hw, "I2C byte read error.\n");
  1934. } while (retry < max_retry);
  1935. return status;
  1936. }
  1937. /**
  1938. * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
  1939. * @hw: pointer to hardware structure
  1940. * @byte_offset: byte offset to read
  1941. * @dev_addr: device address
  1942. * @data: value read
  1943. *
  1944. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1945. * a specified device address.
  1946. */
  1947. int ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  1948. u8 dev_addr, u8 *data)
  1949. {
  1950. return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
  1951. data, true);
  1952. }
  1953. /**
  1954. * ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
  1955. * @hw: pointer to hardware structure
  1956. * @byte_offset: byte offset to read
  1957. * @dev_addr: device address
  1958. * @data: value read
  1959. *
  1960. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1961. * a specified device address.
  1962. */
  1963. int ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
  1964. u8 dev_addr, u8 *data)
  1965. {
  1966. return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
  1967. data, false);
  1968. }
  1969. /**
  1970. * ixgbe_write_i2c_byte_generic_int - Writes 8 bit word over I2C
  1971. * @hw: pointer to hardware structure
  1972. * @byte_offset: byte offset to write
  1973. * @dev_addr: device address
  1974. * @data: value to write
  1975. * @lock: true if to take and release semaphore
  1976. *
  1977. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  1978. * a specified device address.
  1979. */
  1980. static int ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
  1981. u8 dev_addr, u8 data, bool lock)
  1982. {
  1983. u32 swfw_mask = hw->phy.phy_semaphore_mask;
  1984. u32 max_retry = 3;
  1985. u32 retry = 0;
  1986. int status;
  1987. if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
  1988. return -EBUSY;
  1989. do {
  1990. ixgbe_i2c_start(hw);
  1991. status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
  1992. if (status != 0)
  1993. goto fail;
  1994. status = ixgbe_get_i2c_ack(hw);
  1995. if (status != 0)
  1996. goto fail;
  1997. status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
  1998. if (status != 0)
  1999. goto fail;
  2000. status = ixgbe_get_i2c_ack(hw);
  2001. if (status != 0)
  2002. goto fail;
  2003. status = ixgbe_clock_out_i2c_byte(hw, data);
  2004. if (status != 0)
  2005. goto fail;
  2006. status = ixgbe_get_i2c_ack(hw);
  2007. if (status != 0)
  2008. goto fail;
  2009. ixgbe_i2c_stop(hw);
  2010. if (lock)
  2011. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  2012. return 0;
  2013. fail:
  2014. ixgbe_i2c_bus_clear(hw);
  2015. retry++;
  2016. if (retry < max_retry)
  2017. hw_dbg(hw, "I2C byte write error - Retrying.\n");
  2018. else
  2019. hw_dbg(hw, "I2C byte write error.\n");
  2020. } while (retry < max_retry);
  2021. if (lock)
  2022. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  2023. return status;
  2024. }
  2025. /**
  2026. * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
  2027. * @hw: pointer to hardware structure
  2028. * @byte_offset: byte offset to write
  2029. * @dev_addr: device address
  2030. * @data: value to write
  2031. *
  2032. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  2033. * a specified device address.
  2034. */
  2035. int ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
  2036. u8 dev_addr, u8 data)
  2037. {
  2038. return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
  2039. data, true);
  2040. }
  2041. /**
  2042. * ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
  2043. * @hw: pointer to hardware structure
  2044. * @byte_offset: byte offset to write
  2045. * @dev_addr: device address
  2046. * @data: value to write
  2047. *
  2048. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  2049. * a specified device address.
  2050. */
  2051. int ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
  2052. u8 dev_addr, u8 data)
  2053. {
  2054. return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
  2055. data, false);
  2056. }
  2057. /**
  2058. * ixgbe_i2c_start - Sets I2C start condition
  2059. * @hw: pointer to hardware structure
  2060. *
  2061. * Sets I2C start condition (High -> Low on SDA while SCL is High)
  2062. * Set bit-bang mode on X550 hardware.
  2063. **/
  2064. static void ixgbe_i2c_start(struct ixgbe_hw *hw)
  2065. {
  2066. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2067. i2cctl |= IXGBE_I2C_BB_EN(hw);
  2068. /* Start condition must begin with data and clock high */
  2069. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  2070. ixgbe_raise_i2c_clk(hw, &i2cctl);
  2071. /* Setup time for start condition (4.7us) */
  2072. udelay(IXGBE_I2C_T_SU_STA);
  2073. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  2074. /* Hold time for start condition (4us) */
  2075. udelay(IXGBE_I2C_T_HD_STA);
  2076. ixgbe_lower_i2c_clk(hw, &i2cctl);
  2077. /* Minimum low period of clock is 4.7 us */
  2078. udelay(IXGBE_I2C_T_LOW);
  2079. }
  2080. /**
  2081. * ixgbe_i2c_stop - Sets I2C stop condition
  2082. * @hw: pointer to hardware structure
  2083. *
  2084. * Sets I2C stop condition (Low -> High on SDA while SCL is High)
  2085. * Disables bit-bang mode and negates data output enable on X550
  2086. * hardware.
  2087. **/
  2088. static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
  2089. {
  2090. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2091. u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
  2092. u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN(hw);
  2093. u32 bb_en_bit = IXGBE_I2C_BB_EN(hw);
  2094. /* Stop condition must begin with data low and clock high */
  2095. ixgbe_set_i2c_data(hw, &i2cctl, 0);
  2096. ixgbe_raise_i2c_clk(hw, &i2cctl);
  2097. /* Setup time for stop condition (4us) */
  2098. udelay(IXGBE_I2C_T_SU_STO);
  2099. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  2100. /* bus free time between stop and start (4.7us)*/
  2101. udelay(IXGBE_I2C_T_BUF);
  2102. if (bb_en_bit || data_oe_bit || clk_oe_bit) {
  2103. i2cctl &= ~bb_en_bit;
  2104. i2cctl |= data_oe_bit | clk_oe_bit;
  2105. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
  2106. IXGBE_WRITE_FLUSH(hw);
  2107. }
  2108. }
  2109. /**
  2110. * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
  2111. * @hw: pointer to hardware structure
  2112. * @data: data byte to clock in
  2113. *
  2114. * Clocks in one byte data via I2C data/clock
  2115. **/
  2116. static int ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
  2117. {
  2118. bool bit = false;
  2119. int i;
  2120. *data = 0;
  2121. for (i = 7; i >= 0; i--) {
  2122. ixgbe_clock_in_i2c_bit(hw, &bit);
  2123. *data |= bit << i;
  2124. }
  2125. return 0;
  2126. }
  2127. /**
  2128. * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
  2129. * @hw: pointer to hardware structure
  2130. * @data: data byte clocked out
  2131. *
  2132. * Clocks out one byte data via I2C data/clock
  2133. **/
  2134. static int ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
  2135. {
  2136. bool bit = false;
  2137. int status;
  2138. u32 i2cctl;
  2139. int i;
  2140. for (i = 7; i >= 0; i--) {
  2141. bit = (data >> i) & 0x1;
  2142. status = ixgbe_clock_out_i2c_bit(hw, bit);
  2143. if (status != 0)
  2144. break;
  2145. }
  2146. /* Release SDA line (set high) */
  2147. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2148. i2cctl |= IXGBE_I2C_DATA_OUT(hw);
  2149. i2cctl |= IXGBE_I2C_DATA_OE_N_EN(hw);
  2150. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
  2151. IXGBE_WRITE_FLUSH(hw);
  2152. return status;
  2153. }
  2154. /**
  2155. * ixgbe_get_i2c_ack - Polls for I2C ACK
  2156. * @hw: pointer to hardware structure
  2157. *
  2158. * Clocks in/out one bit via I2C data/clock
  2159. **/
  2160. static int ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
  2161. {
  2162. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2163. u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
  2164. u32 timeout = 10;
  2165. bool ack = true;
  2166. int status = 0;
  2167. u32 i = 0;
  2168. if (data_oe_bit) {
  2169. i2cctl |= IXGBE_I2C_DATA_OUT(hw);
  2170. i2cctl |= data_oe_bit;
  2171. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
  2172. IXGBE_WRITE_FLUSH(hw);
  2173. }
  2174. ixgbe_raise_i2c_clk(hw, &i2cctl);
  2175. /* Minimum high period of clock is 4us */
  2176. udelay(IXGBE_I2C_T_HIGH);
  2177. /* Poll for ACK. Note that ACK in I2C spec is
  2178. * transition from 1 to 0 */
  2179. for (i = 0; i < timeout; i++) {
  2180. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2181. ack = ixgbe_get_i2c_data(hw, &i2cctl);
  2182. udelay(1);
  2183. if (ack == 0)
  2184. break;
  2185. }
  2186. if (ack == 1) {
  2187. hw_dbg(hw, "I2C ack was not received.\n");
  2188. status = -EIO;
  2189. }
  2190. ixgbe_lower_i2c_clk(hw, &i2cctl);
  2191. /* Minimum low period of clock is 4.7 us */
  2192. udelay(IXGBE_I2C_T_LOW);
  2193. return status;
  2194. }
  2195. /**
  2196. * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
  2197. * @hw: pointer to hardware structure
  2198. * @data: read data value
  2199. *
  2200. * Clocks in one bit via I2C data/clock
  2201. **/
  2202. static int ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
  2203. {
  2204. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2205. u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
  2206. if (data_oe_bit) {
  2207. i2cctl |= IXGBE_I2C_DATA_OUT(hw);
  2208. i2cctl |= data_oe_bit;
  2209. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
  2210. IXGBE_WRITE_FLUSH(hw);
  2211. }
  2212. ixgbe_raise_i2c_clk(hw, &i2cctl);
  2213. /* Minimum high period of clock is 4us */
  2214. udelay(IXGBE_I2C_T_HIGH);
  2215. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2216. *data = ixgbe_get_i2c_data(hw, &i2cctl);
  2217. ixgbe_lower_i2c_clk(hw, &i2cctl);
  2218. /* Minimum low period of clock is 4.7 us */
  2219. udelay(IXGBE_I2C_T_LOW);
  2220. return 0;
  2221. }
  2222. /**
  2223. * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
  2224. * @hw: pointer to hardware structure
  2225. * @data: data value to write
  2226. *
  2227. * Clocks out one bit via I2C data/clock
  2228. **/
  2229. static int ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
  2230. {
  2231. u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2232. int status;
  2233. status = ixgbe_set_i2c_data(hw, &i2cctl, data);
  2234. if (status == 0) {
  2235. ixgbe_raise_i2c_clk(hw, &i2cctl);
  2236. /* Minimum high period of clock is 4us */
  2237. udelay(IXGBE_I2C_T_HIGH);
  2238. ixgbe_lower_i2c_clk(hw, &i2cctl);
  2239. /* Minimum low period of clock is 4.7 us.
  2240. * This also takes care of the data hold time.
  2241. */
  2242. udelay(IXGBE_I2C_T_LOW);
  2243. } else {
  2244. hw_dbg(hw, "I2C data was not set to %X\n", data);
  2245. return -EIO;
  2246. }
  2247. return 0;
  2248. }
  2249. /**
  2250. * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
  2251. * @hw: pointer to hardware structure
  2252. * @i2cctl: Current value of I2CCTL register
  2253. *
  2254. * Raises the I2C clock line '0'->'1'
  2255. * Negates the I2C clock output enable on X550 hardware.
  2256. **/
  2257. static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  2258. {
  2259. u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN(hw);
  2260. u32 i = 0;
  2261. u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
  2262. u32 i2cctl_r = 0;
  2263. if (clk_oe_bit) {
  2264. *i2cctl |= clk_oe_bit;
  2265. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
  2266. }
  2267. for (i = 0; i < timeout; i++) {
  2268. *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
  2269. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
  2270. IXGBE_WRITE_FLUSH(hw);
  2271. /* SCL rise time (1000ns) */
  2272. udelay(IXGBE_I2C_T_RISE);
  2273. i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2274. if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
  2275. break;
  2276. }
  2277. }
  2278. /**
  2279. * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
  2280. * @hw: pointer to hardware structure
  2281. * @i2cctl: Current value of I2CCTL register
  2282. *
  2283. * Lowers the I2C clock line '1'->'0'
  2284. * Asserts the I2C clock output enable on X550 hardware.
  2285. **/
  2286. static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
  2287. {
  2288. *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
  2289. *i2cctl &= ~IXGBE_I2C_CLK_OE_N_EN(hw);
  2290. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
  2291. IXGBE_WRITE_FLUSH(hw);
  2292. /* SCL fall time (300ns) */
  2293. udelay(IXGBE_I2C_T_FALL);
  2294. }
  2295. /**
  2296. * ixgbe_set_i2c_data - Sets the I2C data bit
  2297. * @hw: pointer to hardware structure
  2298. * @i2cctl: Current value of I2CCTL register
  2299. * @data: I2C data value (0 or 1) to set
  2300. *
  2301. * Sets the I2C data bit
  2302. * Asserts the I2C data output enable on X550 hardware.
  2303. **/
  2304. static int ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
  2305. {
  2306. u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
  2307. if (data)
  2308. *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
  2309. else
  2310. *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
  2311. *i2cctl &= ~data_oe_bit;
  2312. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
  2313. IXGBE_WRITE_FLUSH(hw);
  2314. /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
  2315. udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
  2316. if (!data) /* Can't verify data in this case */
  2317. return 0;
  2318. if (data_oe_bit) {
  2319. *i2cctl |= data_oe_bit;
  2320. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
  2321. IXGBE_WRITE_FLUSH(hw);
  2322. }
  2323. /* Verify data was set correctly */
  2324. *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2325. if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
  2326. hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
  2327. return -EIO;
  2328. }
  2329. return 0;
  2330. }
  2331. /**
  2332. * ixgbe_get_i2c_data - Reads the I2C SDA data bit
  2333. * @hw: pointer to hardware structure
  2334. * @i2cctl: Current value of I2CCTL register
  2335. *
  2336. * Returns the I2C data bit value
  2337. * Negates the I2C data output enable on X550 hardware.
  2338. **/
  2339. static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
  2340. {
  2341. u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
  2342. if (data_oe_bit) {
  2343. *i2cctl |= data_oe_bit;
  2344. IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
  2345. IXGBE_WRITE_FLUSH(hw);
  2346. udelay(IXGBE_I2C_T_FALL);
  2347. }
  2348. if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
  2349. return true;
  2350. return false;
  2351. }
  2352. /**
  2353. * ixgbe_i2c_bus_clear - Clears the I2C bus
  2354. * @hw: pointer to hardware structure
  2355. *
  2356. * Clears the I2C bus by sending nine clock pulses.
  2357. * Used when data line is stuck low.
  2358. **/
  2359. static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
  2360. {
  2361. u32 i2cctl;
  2362. u32 i;
  2363. ixgbe_i2c_start(hw);
  2364. i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
  2365. ixgbe_set_i2c_data(hw, &i2cctl, 1);
  2366. for (i = 0; i < 9; i++) {
  2367. ixgbe_raise_i2c_clk(hw, &i2cctl);
  2368. /* Min high period of clock is 4us */
  2369. udelay(IXGBE_I2C_T_HIGH);
  2370. ixgbe_lower_i2c_clk(hw, &i2cctl);
  2371. /* Min low period of clock is 4.7us*/
  2372. udelay(IXGBE_I2C_T_LOW);
  2373. }
  2374. ixgbe_i2c_start(hw);
  2375. /* Put the i2c bus back to default state */
  2376. ixgbe_i2c_stop(hw);
  2377. }
  2378. /**
  2379. * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
  2380. * @hw: pointer to hardware structure
  2381. *
  2382. * Checks if the LASI temp alarm status was triggered due to overtemp
  2383. *
  2384. * Return true when an overtemp event detected, otherwise false.
  2385. **/
  2386. bool ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
  2387. {
  2388. u16 phy_data = 0;
  2389. u32 status;
  2390. if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
  2391. return false;
  2392. /* Check that the LASI temp alarm status was triggered */
  2393. status = hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
  2394. MDIO_MMD_PMAPMD, &phy_data);
  2395. if (status)
  2396. return false;
  2397. return !!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM);
  2398. }
  2399. /** ixgbe_set_copper_phy_power - Control power for copper phy
  2400. * @hw: pointer to hardware structure
  2401. * @on: true for on, false for off
  2402. **/
  2403. int ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
  2404. {
  2405. u32 status;
  2406. u16 reg;
  2407. /* Bail if we don't have copper phy */
  2408. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
  2409. return 0;
  2410. if (!on && ixgbe_mng_present(hw))
  2411. return 0;
  2412. status = hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_VEND1, &reg);
  2413. if (status)
  2414. return status;
  2415. if (on) {
  2416. reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
  2417. } else {
  2418. if (ixgbe_check_reset_blocked(hw))
  2419. return 0;
  2420. reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
  2421. }
  2422. status = hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_VEND1, reg);
  2423. return status;
  2424. }