ixgbe_phy.c 63 KB

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