ixgbe_phy.c 52 KB

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