ael1002.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. /*
  2. * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include "common.h"
  33. #include "regs.h"
  34. enum {
  35. AEL100X_TX_CONFIG1 = 0xc002,
  36. AEL1002_PWR_DOWN_HI = 0xc011,
  37. AEL1002_PWR_DOWN_LO = 0xc012,
  38. AEL1002_XFI_EQL = 0xc015,
  39. AEL1002_LB_EN = 0xc017,
  40. AEL_OPT_SETTINGS = 0xc017,
  41. AEL_I2C_CTRL = 0xc30a,
  42. AEL_I2C_DATA = 0xc30b,
  43. AEL_I2C_STAT = 0xc30c,
  44. AEL2005_GPIO_CTRL = 0xc214,
  45. AEL2005_GPIO_STAT = 0xc215,
  46. AEL2020_GPIO_INTR = 0xc103, /* Latch High (LH) */
  47. AEL2020_GPIO_CTRL = 0xc108, /* Store Clear (SC) */
  48. AEL2020_GPIO_STAT = 0xc10c, /* Read Only (RO) */
  49. AEL2020_GPIO_CFG = 0xc110, /* Read Write (RW) */
  50. AEL2020_GPIO_SDA = 0, /* IN: i2c serial data */
  51. AEL2020_GPIO_MODDET = 1, /* IN: Module Detect */
  52. AEL2020_GPIO_0 = 3, /* IN: unassigned */
  53. AEL2020_GPIO_1 = 2, /* OUT: unassigned */
  54. AEL2020_GPIO_LSTAT = AEL2020_GPIO_1, /* wired to link status LED */
  55. };
  56. enum { edc_none, edc_sr, edc_twinax };
  57. /* PHY module I2C device address */
  58. enum {
  59. MODULE_DEV_ADDR = 0xa0,
  60. SFF_DEV_ADDR = 0xa2,
  61. };
  62. /* PHY transceiver type */
  63. enum {
  64. phy_transtype_unknown = 0,
  65. phy_transtype_sfp = 3,
  66. phy_transtype_xfp = 6,
  67. };
  68. #define AEL2005_MODDET_IRQ 4
  69. struct reg_val {
  70. unsigned short mmd_addr;
  71. unsigned short reg_addr;
  72. unsigned short clear_bits;
  73. unsigned short set_bits;
  74. };
  75. static int set_phy_regs(struct cphy *phy, const struct reg_val *rv)
  76. {
  77. int err;
  78. for (err = 0; rv->mmd_addr && !err; rv++) {
  79. if (rv->clear_bits == 0xffff)
  80. err = t3_mdio_write(phy, rv->mmd_addr, rv->reg_addr,
  81. rv->set_bits);
  82. else
  83. err = t3_mdio_change_bits(phy, rv->mmd_addr,
  84. rv->reg_addr, rv->clear_bits,
  85. rv->set_bits);
  86. }
  87. return err;
  88. }
  89. static void ael100x_txon(struct cphy *phy)
  90. {
  91. int tx_on_gpio =
  92. phy->mdio.prtad == 0 ? F_GPIO7_OUT_VAL : F_GPIO2_OUT_VAL;
  93. msleep(100);
  94. t3_set_reg_field(phy->adapter, A_T3DBG_GPIO_EN, 0, tx_on_gpio);
  95. msleep(30);
  96. }
  97. /*
  98. * Read an 8-bit word from a device attached to the PHY's i2c bus.
  99. */
  100. static int ael_i2c_rd(struct cphy *phy, int dev_addr, int word_addr)
  101. {
  102. int i, err;
  103. unsigned int stat, data;
  104. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL_I2C_CTRL,
  105. (dev_addr << 8) | (1 << 8) | word_addr);
  106. if (err)
  107. return err;
  108. for (i = 0; i < 200; i++) {
  109. msleep(1);
  110. err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL_I2C_STAT, &stat);
  111. if (err)
  112. return err;
  113. if ((stat & 3) == 1) {
  114. err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL_I2C_DATA,
  115. &data);
  116. if (err)
  117. return err;
  118. return data >> 8;
  119. }
  120. }
  121. CH_WARN(phy->adapter, "PHY %u i2c read of dev.addr %#x.%#x timed out\n",
  122. phy->mdio.prtad, dev_addr, word_addr);
  123. return -ETIMEDOUT;
  124. }
  125. static int ael1002_power_down(struct cphy *phy, int enable)
  126. {
  127. int err;
  128. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, MDIO_PMA_TXDIS, !!enable);
  129. if (!err)
  130. err = mdio_set_flag(&phy->mdio, phy->mdio.prtad,
  131. MDIO_MMD_PMAPMD, MDIO_CTRL1,
  132. MDIO_CTRL1_LPOWER, enable);
  133. return err;
  134. }
  135. static int ael1002_reset(struct cphy *phy, int wait)
  136. {
  137. int err;
  138. if ((err = ael1002_power_down(phy, 0)) ||
  139. (err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL100X_TX_CONFIG1, 1)) ||
  140. (err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL1002_PWR_DOWN_HI, 0)) ||
  141. (err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL1002_PWR_DOWN_LO, 0)) ||
  142. (err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL1002_XFI_EQL, 0x18)) ||
  143. (err = t3_mdio_change_bits(phy, MDIO_MMD_PMAPMD, AEL1002_LB_EN,
  144. 0, 1 << 5)))
  145. return err;
  146. return 0;
  147. }
  148. static int ael1002_intr_noop(struct cphy *phy)
  149. {
  150. return 0;
  151. }
  152. /*
  153. * Get link status for a 10GBASE-R device.
  154. */
  155. static int get_link_status_r(struct cphy *phy, int *link_ok, int *speed,
  156. int *duplex, int *fc)
  157. {
  158. if (link_ok) {
  159. unsigned int stat0, stat1, stat2;
  160. int err = t3_mdio_read(phy, MDIO_MMD_PMAPMD,
  161. MDIO_PMA_RXDET, &stat0);
  162. if (!err)
  163. err = t3_mdio_read(phy, MDIO_MMD_PCS,
  164. MDIO_PCS_10GBRT_STAT1, &stat1);
  165. if (!err)
  166. err = t3_mdio_read(phy, MDIO_MMD_PHYXS,
  167. MDIO_PHYXS_LNSTAT, &stat2);
  168. if (err)
  169. return err;
  170. *link_ok = (stat0 & stat1 & (stat2 >> 12)) & 1;
  171. }
  172. if (speed)
  173. *speed = SPEED_10000;
  174. if (duplex)
  175. *duplex = DUPLEX_FULL;
  176. return 0;
  177. }
  178. static struct cphy_ops ael1002_ops = {
  179. .reset = ael1002_reset,
  180. .intr_enable = ael1002_intr_noop,
  181. .intr_disable = ael1002_intr_noop,
  182. .intr_clear = ael1002_intr_noop,
  183. .intr_handler = ael1002_intr_noop,
  184. .get_link_status = get_link_status_r,
  185. .power_down = ael1002_power_down,
  186. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  187. };
  188. int t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
  189. int phy_addr, const struct mdio_ops *mdio_ops)
  190. {
  191. cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops,
  192. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
  193. "10GBASE-R");
  194. ael100x_txon(phy);
  195. return 0;
  196. }
  197. static int ael1006_reset(struct cphy *phy, int wait)
  198. {
  199. return t3_phy_reset(phy, MDIO_MMD_PMAPMD, wait);
  200. }
  201. static int ael1006_power_down(struct cphy *phy, int enable)
  202. {
  203. return mdio_set_flag(&phy->mdio, phy->mdio.prtad, MDIO_MMD_PMAPMD,
  204. MDIO_CTRL1, MDIO_CTRL1_LPOWER, enable);
  205. }
  206. static struct cphy_ops ael1006_ops = {
  207. .reset = ael1006_reset,
  208. .intr_enable = t3_phy_lasi_intr_enable,
  209. .intr_disable = t3_phy_lasi_intr_disable,
  210. .intr_clear = t3_phy_lasi_intr_clear,
  211. .intr_handler = t3_phy_lasi_intr_handler,
  212. .get_link_status = get_link_status_r,
  213. .power_down = ael1006_power_down,
  214. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  215. };
  216. int t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
  217. int phy_addr, const struct mdio_ops *mdio_ops)
  218. {
  219. cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops,
  220. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
  221. "10GBASE-SR");
  222. ael100x_txon(phy);
  223. return 0;
  224. }
  225. /*
  226. * Decode our module type.
  227. */
  228. static int ael2xxx_get_module_type(struct cphy *phy, int delay_ms)
  229. {
  230. int v;
  231. if (delay_ms)
  232. msleep(delay_ms);
  233. /* see SFF-8472 for below */
  234. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 3);
  235. if (v < 0)
  236. return v;
  237. if (v == 0x10)
  238. return phy_modtype_sr;
  239. if (v == 0x20)
  240. return phy_modtype_lr;
  241. if (v == 0x40)
  242. return phy_modtype_lrm;
  243. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 6);
  244. if (v < 0)
  245. return v;
  246. if (v != 4)
  247. goto unknown;
  248. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 10);
  249. if (v < 0)
  250. return v;
  251. if (v & 0x80) {
  252. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 0x12);
  253. if (v < 0)
  254. return v;
  255. return v > 10 ? phy_modtype_twinax_long : phy_modtype_twinax;
  256. }
  257. unknown:
  258. return phy_modtype_unknown;
  259. }
  260. /*
  261. * Code to support the Aeluros/NetLogic 2005 10Gb PHY.
  262. */
  263. static int ael2005_setup_sr_edc(struct cphy *phy)
  264. {
  265. static struct reg_val regs[] = {
  266. { MDIO_MMD_PMAPMD, 0xc003, 0xffff, 0x181 },
  267. { MDIO_MMD_PMAPMD, 0xc010, 0xffff, 0x448a },
  268. { MDIO_MMD_PMAPMD, 0xc04a, 0xffff, 0x5200 },
  269. { 0, 0, 0, 0 }
  270. };
  271. static u16 sr_edc[] = {
  272. 0xcc00, 0x2ff4,
  273. 0xcc01, 0x3cd4,
  274. 0xcc02, 0x2015,
  275. 0xcc03, 0x3105,
  276. 0xcc04, 0x6524,
  277. 0xcc05, 0x27ff,
  278. 0xcc06, 0x300f,
  279. 0xcc07, 0x2c8b,
  280. 0xcc08, 0x300b,
  281. 0xcc09, 0x4009,
  282. 0xcc0a, 0x400e,
  283. 0xcc0b, 0x2f72,
  284. 0xcc0c, 0x3002,
  285. 0xcc0d, 0x1002,
  286. 0xcc0e, 0x2172,
  287. 0xcc0f, 0x3012,
  288. 0xcc10, 0x1002,
  289. 0xcc11, 0x25d2,
  290. 0xcc12, 0x3012,
  291. 0xcc13, 0x1002,
  292. 0xcc14, 0xd01e,
  293. 0xcc15, 0x27d2,
  294. 0xcc16, 0x3012,
  295. 0xcc17, 0x1002,
  296. 0xcc18, 0x2004,
  297. 0xcc19, 0x3c84,
  298. 0xcc1a, 0x6436,
  299. 0xcc1b, 0x2007,
  300. 0xcc1c, 0x3f87,
  301. 0xcc1d, 0x8676,
  302. 0xcc1e, 0x40b7,
  303. 0xcc1f, 0xa746,
  304. 0xcc20, 0x4047,
  305. 0xcc21, 0x5673,
  306. 0xcc22, 0x2982,
  307. 0xcc23, 0x3002,
  308. 0xcc24, 0x13d2,
  309. 0xcc25, 0x8bbd,
  310. 0xcc26, 0x2862,
  311. 0xcc27, 0x3012,
  312. 0xcc28, 0x1002,
  313. 0xcc29, 0x2092,
  314. 0xcc2a, 0x3012,
  315. 0xcc2b, 0x1002,
  316. 0xcc2c, 0x5cc3,
  317. 0xcc2d, 0x314,
  318. 0xcc2e, 0x2942,
  319. 0xcc2f, 0x3002,
  320. 0xcc30, 0x1002,
  321. 0xcc31, 0xd019,
  322. 0xcc32, 0x2032,
  323. 0xcc33, 0x3012,
  324. 0xcc34, 0x1002,
  325. 0xcc35, 0x2a04,
  326. 0xcc36, 0x3c74,
  327. 0xcc37, 0x6435,
  328. 0xcc38, 0x2fa4,
  329. 0xcc39, 0x3cd4,
  330. 0xcc3a, 0x6624,
  331. 0xcc3b, 0x5563,
  332. 0xcc3c, 0x2d42,
  333. 0xcc3d, 0x3002,
  334. 0xcc3e, 0x13d2,
  335. 0xcc3f, 0x464d,
  336. 0xcc40, 0x2862,
  337. 0xcc41, 0x3012,
  338. 0xcc42, 0x1002,
  339. 0xcc43, 0x2032,
  340. 0xcc44, 0x3012,
  341. 0xcc45, 0x1002,
  342. 0xcc46, 0x2fb4,
  343. 0xcc47, 0x3cd4,
  344. 0xcc48, 0x6624,
  345. 0xcc49, 0x5563,
  346. 0xcc4a, 0x2d42,
  347. 0xcc4b, 0x3002,
  348. 0xcc4c, 0x13d2,
  349. 0xcc4d, 0x2ed2,
  350. 0xcc4e, 0x3002,
  351. 0xcc4f, 0x1002,
  352. 0xcc50, 0x2fd2,
  353. 0xcc51, 0x3002,
  354. 0xcc52, 0x1002,
  355. 0xcc53, 0x004,
  356. 0xcc54, 0x2942,
  357. 0xcc55, 0x3002,
  358. 0xcc56, 0x1002,
  359. 0xcc57, 0x2092,
  360. 0xcc58, 0x3012,
  361. 0xcc59, 0x1002,
  362. 0xcc5a, 0x5cc3,
  363. 0xcc5b, 0x317,
  364. 0xcc5c, 0x2f72,
  365. 0xcc5d, 0x3002,
  366. 0xcc5e, 0x1002,
  367. 0xcc5f, 0x2942,
  368. 0xcc60, 0x3002,
  369. 0xcc61, 0x1002,
  370. 0xcc62, 0x22cd,
  371. 0xcc63, 0x301d,
  372. 0xcc64, 0x2862,
  373. 0xcc65, 0x3012,
  374. 0xcc66, 0x1002,
  375. 0xcc67, 0x2ed2,
  376. 0xcc68, 0x3002,
  377. 0xcc69, 0x1002,
  378. 0xcc6a, 0x2d72,
  379. 0xcc6b, 0x3002,
  380. 0xcc6c, 0x1002,
  381. 0xcc6d, 0x628f,
  382. 0xcc6e, 0x2112,
  383. 0xcc6f, 0x3012,
  384. 0xcc70, 0x1002,
  385. 0xcc71, 0x5aa3,
  386. 0xcc72, 0x2dc2,
  387. 0xcc73, 0x3002,
  388. 0xcc74, 0x1312,
  389. 0xcc75, 0x6f72,
  390. 0xcc76, 0x1002,
  391. 0xcc77, 0x2807,
  392. 0xcc78, 0x31a7,
  393. 0xcc79, 0x20c4,
  394. 0xcc7a, 0x3c24,
  395. 0xcc7b, 0x6724,
  396. 0xcc7c, 0x1002,
  397. 0xcc7d, 0x2807,
  398. 0xcc7e, 0x3187,
  399. 0xcc7f, 0x20c4,
  400. 0xcc80, 0x3c24,
  401. 0xcc81, 0x6724,
  402. 0xcc82, 0x1002,
  403. 0xcc83, 0x2514,
  404. 0xcc84, 0x3c64,
  405. 0xcc85, 0x6436,
  406. 0xcc86, 0xdff4,
  407. 0xcc87, 0x6436,
  408. 0xcc88, 0x1002,
  409. 0xcc89, 0x40a4,
  410. 0xcc8a, 0x643c,
  411. 0xcc8b, 0x4016,
  412. 0xcc8c, 0x8c6c,
  413. 0xcc8d, 0x2b24,
  414. 0xcc8e, 0x3c24,
  415. 0xcc8f, 0x6435,
  416. 0xcc90, 0x1002,
  417. 0xcc91, 0x2b24,
  418. 0xcc92, 0x3c24,
  419. 0xcc93, 0x643a,
  420. 0xcc94, 0x4025,
  421. 0xcc95, 0x8a5a,
  422. 0xcc96, 0x1002,
  423. 0xcc97, 0x2731,
  424. 0xcc98, 0x3011,
  425. 0xcc99, 0x1001,
  426. 0xcc9a, 0xc7a0,
  427. 0xcc9b, 0x100,
  428. 0xcc9c, 0xc502,
  429. 0xcc9d, 0x53ac,
  430. 0xcc9e, 0xc503,
  431. 0xcc9f, 0xd5d5,
  432. 0xcca0, 0xc600,
  433. 0xcca1, 0x2a6d,
  434. 0xcca2, 0xc601,
  435. 0xcca3, 0x2a4c,
  436. 0xcca4, 0xc602,
  437. 0xcca5, 0x111,
  438. 0xcca6, 0xc60c,
  439. 0xcca7, 0x5900,
  440. 0xcca8, 0xc710,
  441. 0xcca9, 0x700,
  442. 0xccaa, 0xc718,
  443. 0xccab, 0x700,
  444. 0xccac, 0xc720,
  445. 0xccad, 0x4700,
  446. 0xccae, 0xc801,
  447. 0xccaf, 0x7f50,
  448. 0xccb0, 0xc802,
  449. 0xccb1, 0x7760,
  450. 0xccb2, 0xc803,
  451. 0xccb3, 0x7fce,
  452. 0xccb4, 0xc804,
  453. 0xccb5, 0x5700,
  454. 0xccb6, 0xc805,
  455. 0xccb7, 0x5f11,
  456. 0xccb8, 0xc806,
  457. 0xccb9, 0x4751,
  458. 0xccba, 0xc807,
  459. 0xccbb, 0x57e1,
  460. 0xccbc, 0xc808,
  461. 0xccbd, 0x2700,
  462. 0xccbe, 0xc809,
  463. 0xccbf, 0x000,
  464. 0xccc0, 0xc821,
  465. 0xccc1, 0x002,
  466. 0xccc2, 0xc822,
  467. 0xccc3, 0x014,
  468. 0xccc4, 0xc832,
  469. 0xccc5, 0x1186,
  470. 0xccc6, 0xc847,
  471. 0xccc7, 0x1e02,
  472. 0xccc8, 0xc013,
  473. 0xccc9, 0xf341,
  474. 0xccca, 0xc01a,
  475. 0xcccb, 0x446,
  476. 0xcccc, 0xc024,
  477. 0xcccd, 0x1000,
  478. 0xccce, 0xc025,
  479. 0xcccf, 0xa00,
  480. 0xccd0, 0xc026,
  481. 0xccd1, 0xc0c,
  482. 0xccd2, 0xc027,
  483. 0xccd3, 0xc0c,
  484. 0xccd4, 0xc029,
  485. 0xccd5, 0x0a0,
  486. 0xccd6, 0xc030,
  487. 0xccd7, 0xa00,
  488. 0xccd8, 0xc03c,
  489. 0xccd9, 0x01c,
  490. 0xccda, 0xc005,
  491. 0xccdb, 0x7a06,
  492. 0xccdc, 0x000,
  493. 0xccdd, 0x2731,
  494. 0xccde, 0x3011,
  495. 0xccdf, 0x1001,
  496. 0xcce0, 0xc620,
  497. 0xcce1, 0x000,
  498. 0xcce2, 0xc621,
  499. 0xcce3, 0x03f,
  500. 0xcce4, 0xc622,
  501. 0xcce5, 0x000,
  502. 0xcce6, 0xc623,
  503. 0xcce7, 0x000,
  504. 0xcce8, 0xc624,
  505. 0xcce9, 0x000,
  506. 0xccea, 0xc625,
  507. 0xcceb, 0x000,
  508. 0xccec, 0xc627,
  509. 0xcced, 0x000,
  510. 0xccee, 0xc628,
  511. 0xccef, 0x000,
  512. 0xccf0, 0xc62c,
  513. 0xccf1, 0x000,
  514. 0xccf2, 0x000,
  515. 0xccf3, 0x2806,
  516. 0xccf4, 0x3cb6,
  517. 0xccf5, 0xc161,
  518. 0xccf6, 0x6134,
  519. 0xccf7, 0x6135,
  520. 0xccf8, 0x5443,
  521. 0xccf9, 0x303,
  522. 0xccfa, 0x6524,
  523. 0xccfb, 0x00b,
  524. 0xccfc, 0x1002,
  525. 0xccfd, 0x2104,
  526. 0xccfe, 0x3c24,
  527. 0xccff, 0x2105,
  528. 0xcd00, 0x3805,
  529. 0xcd01, 0x6524,
  530. 0xcd02, 0xdff4,
  531. 0xcd03, 0x4005,
  532. 0xcd04, 0x6524,
  533. 0xcd05, 0x1002,
  534. 0xcd06, 0x5dd3,
  535. 0xcd07, 0x306,
  536. 0xcd08, 0x2ff7,
  537. 0xcd09, 0x38f7,
  538. 0xcd0a, 0x60b7,
  539. 0xcd0b, 0xdffd,
  540. 0xcd0c, 0x00a,
  541. 0xcd0d, 0x1002,
  542. 0xcd0e, 0
  543. };
  544. int i, err;
  545. err = set_phy_regs(phy, regs);
  546. if (err)
  547. return err;
  548. msleep(50);
  549. for (i = 0; i < ARRAY_SIZE(sr_edc) && !err; i += 2)
  550. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, sr_edc[i],
  551. sr_edc[i + 1]);
  552. if (!err)
  553. phy->priv = edc_sr;
  554. return err;
  555. }
  556. static int ael2005_setup_twinax_edc(struct cphy *phy, int modtype)
  557. {
  558. static struct reg_val regs[] = {
  559. { MDIO_MMD_PMAPMD, 0xc04a, 0xffff, 0x5a00 },
  560. { 0, 0, 0, 0 }
  561. };
  562. static struct reg_val preemphasis[] = {
  563. { MDIO_MMD_PMAPMD, 0xc014, 0xffff, 0xfe16 },
  564. { MDIO_MMD_PMAPMD, 0xc015, 0xffff, 0xa000 },
  565. { 0, 0, 0, 0 }
  566. };
  567. static u16 twinax_edc[] = {
  568. 0xcc00, 0x4009,
  569. 0xcc01, 0x27ff,
  570. 0xcc02, 0x300f,
  571. 0xcc03, 0x40aa,
  572. 0xcc04, 0x401c,
  573. 0xcc05, 0x401e,
  574. 0xcc06, 0x2ff4,
  575. 0xcc07, 0x3cd4,
  576. 0xcc08, 0x2035,
  577. 0xcc09, 0x3145,
  578. 0xcc0a, 0x6524,
  579. 0xcc0b, 0x26a2,
  580. 0xcc0c, 0x3012,
  581. 0xcc0d, 0x1002,
  582. 0xcc0e, 0x29c2,
  583. 0xcc0f, 0x3002,
  584. 0xcc10, 0x1002,
  585. 0xcc11, 0x2072,
  586. 0xcc12, 0x3012,
  587. 0xcc13, 0x1002,
  588. 0xcc14, 0x22cd,
  589. 0xcc15, 0x301d,
  590. 0xcc16, 0x2e52,
  591. 0xcc17, 0x3012,
  592. 0xcc18, 0x1002,
  593. 0xcc19, 0x28e2,
  594. 0xcc1a, 0x3002,
  595. 0xcc1b, 0x1002,
  596. 0xcc1c, 0x628f,
  597. 0xcc1d, 0x2ac2,
  598. 0xcc1e, 0x3012,
  599. 0xcc1f, 0x1002,
  600. 0xcc20, 0x5553,
  601. 0xcc21, 0x2ae2,
  602. 0xcc22, 0x3002,
  603. 0xcc23, 0x1302,
  604. 0xcc24, 0x401e,
  605. 0xcc25, 0x2be2,
  606. 0xcc26, 0x3012,
  607. 0xcc27, 0x1002,
  608. 0xcc28, 0x2da2,
  609. 0xcc29, 0x3012,
  610. 0xcc2a, 0x1002,
  611. 0xcc2b, 0x2ba2,
  612. 0xcc2c, 0x3002,
  613. 0xcc2d, 0x1002,
  614. 0xcc2e, 0x5ee3,
  615. 0xcc2f, 0x305,
  616. 0xcc30, 0x400e,
  617. 0xcc31, 0x2bc2,
  618. 0xcc32, 0x3002,
  619. 0xcc33, 0x1002,
  620. 0xcc34, 0x2b82,
  621. 0xcc35, 0x3012,
  622. 0xcc36, 0x1002,
  623. 0xcc37, 0x5663,
  624. 0xcc38, 0x302,
  625. 0xcc39, 0x401e,
  626. 0xcc3a, 0x6f72,
  627. 0xcc3b, 0x1002,
  628. 0xcc3c, 0x628f,
  629. 0xcc3d, 0x2be2,
  630. 0xcc3e, 0x3012,
  631. 0xcc3f, 0x1002,
  632. 0xcc40, 0x22cd,
  633. 0xcc41, 0x301d,
  634. 0xcc42, 0x2e52,
  635. 0xcc43, 0x3012,
  636. 0xcc44, 0x1002,
  637. 0xcc45, 0x2522,
  638. 0xcc46, 0x3012,
  639. 0xcc47, 0x1002,
  640. 0xcc48, 0x2da2,
  641. 0xcc49, 0x3012,
  642. 0xcc4a, 0x1002,
  643. 0xcc4b, 0x2ca2,
  644. 0xcc4c, 0x3012,
  645. 0xcc4d, 0x1002,
  646. 0xcc4e, 0x2fa4,
  647. 0xcc4f, 0x3cd4,
  648. 0xcc50, 0x6624,
  649. 0xcc51, 0x410b,
  650. 0xcc52, 0x56b3,
  651. 0xcc53, 0x3c4,
  652. 0xcc54, 0x2fb2,
  653. 0xcc55, 0x3002,
  654. 0xcc56, 0x1002,
  655. 0xcc57, 0x220b,
  656. 0xcc58, 0x303b,
  657. 0xcc59, 0x56b3,
  658. 0xcc5a, 0x3c3,
  659. 0xcc5b, 0x866b,
  660. 0xcc5c, 0x400c,
  661. 0xcc5d, 0x23a2,
  662. 0xcc5e, 0x3012,
  663. 0xcc5f, 0x1002,
  664. 0xcc60, 0x2da2,
  665. 0xcc61, 0x3012,
  666. 0xcc62, 0x1002,
  667. 0xcc63, 0x2ca2,
  668. 0xcc64, 0x3012,
  669. 0xcc65, 0x1002,
  670. 0xcc66, 0x2fb4,
  671. 0xcc67, 0x3cd4,
  672. 0xcc68, 0x6624,
  673. 0xcc69, 0x56b3,
  674. 0xcc6a, 0x3c3,
  675. 0xcc6b, 0x866b,
  676. 0xcc6c, 0x401c,
  677. 0xcc6d, 0x2205,
  678. 0xcc6e, 0x3035,
  679. 0xcc6f, 0x5b53,
  680. 0xcc70, 0x2c52,
  681. 0xcc71, 0x3002,
  682. 0xcc72, 0x13c2,
  683. 0xcc73, 0x5cc3,
  684. 0xcc74, 0x317,
  685. 0xcc75, 0x2522,
  686. 0xcc76, 0x3012,
  687. 0xcc77, 0x1002,
  688. 0xcc78, 0x2da2,
  689. 0xcc79, 0x3012,
  690. 0xcc7a, 0x1002,
  691. 0xcc7b, 0x2b82,
  692. 0xcc7c, 0x3012,
  693. 0xcc7d, 0x1002,
  694. 0xcc7e, 0x5663,
  695. 0xcc7f, 0x303,
  696. 0xcc80, 0x401e,
  697. 0xcc81, 0x004,
  698. 0xcc82, 0x2c42,
  699. 0xcc83, 0x3012,
  700. 0xcc84, 0x1002,
  701. 0xcc85, 0x6f72,
  702. 0xcc86, 0x1002,
  703. 0xcc87, 0x628f,
  704. 0xcc88, 0x2304,
  705. 0xcc89, 0x3c84,
  706. 0xcc8a, 0x6436,
  707. 0xcc8b, 0xdff4,
  708. 0xcc8c, 0x6436,
  709. 0xcc8d, 0x2ff5,
  710. 0xcc8e, 0x3005,
  711. 0xcc8f, 0x8656,
  712. 0xcc90, 0xdfba,
  713. 0xcc91, 0x56a3,
  714. 0xcc92, 0xd05a,
  715. 0xcc93, 0x21c2,
  716. 0xcc94, 0x3012,
  717. 0xcc95, 0x1392,
  718. 0xcc96, 0xd05a,
  719. 0xcc97, 0x56a3,
  720. 0xcc98, 0xdfba,
  721. 0xcc99, 0x383,
  722. 0xcc9a, 0x6f72,
  723. 0xcc9b, 0x1002,
  724. 0xcc9c, 0x28c5,
  725. 0xcc9d, 0x3005,
  726. 0xcc9e, 0x4178,
  727. 0xcc9f, 0x5653,
  728. 0xcca0, 0x384,
  729. 0xcca1, 0x22b2,
  730. 0xcca2, 0x3012,
  731. 0xcca3, 0x1002,
  732. 0xcca4, 0x2be5,
  733. 0xcca5, 0x3005,
  734. 0xcca6, 0x41e8,
  735. 0xcca7, 0x5653,
  736. 0xcca8, 0x382,
  737. 0xcca9, 0x002,
  738. 0xccaa, 0x4258,
  739. 0xccab, 0x2474,
  740. 0xccac, 0x3c84,
  741. 0xccad, 0x6437,
  742. 0xccae, 0xdff4,
  743. 0xccaf, 0x6437,
  744. 0xccb0, 0x2ff5,
  745. 0xccb1, 0x3c05,
  746. 0xccb2, 0x8757,
  747. 0xccb3, 0xb888,
  748. 0xccb4, 0x9787,
  749. 0xccb5, 0xdff4,
  750. 0xccb6, 0x6724,
  751. 0xccb7, 0x866a,
  752. 0xccb8, 0x6f72,
  753. 0xccb9, 0x1002,
  754. 0xccba, 0x2d01,
  755. 0xccbb, 0x3011,
  756. 0xccbc, 0x1001,
  757. 0xccbd, 0xc620,
  758. 0xccbe, 0x14e5,
  759. 0xccbf, 0xc621,
  760. 0xccc0, 0xc53d,
  761. 0xccc1, 0xc622,
  762. 0xccc2, 0x3cbe,
  763. 0xccc3, 0xc623,
  764. 0xccc4, 0x4452,
  765. 0xccc5, 0xc624,
  766. 0xccc6, 0xc5c5,
  767. 0xccc7, 0xc625,
  768. 0xccc8, 0xe01e,
  769. 0xccc9, 0xc627,
  770. 0xccca, 0x000,
  771. 0xcccb, 0xc628,
  772. 0xcccc, 0x000,
  773. 0xcccd, 0xc62b,
  774. 0xccce, 0x000,
  775. 0xcccf, 0xc62c,
  776. 0xccd0, 0x000,
  777. 0xccd1, 0x000,
  778. 0xccd2, 0x2d01,
  779. 0xccd3, 0x3011,
  780. 0xccd4, 0x1001,
  781. 0xccd5, 0xc620,
  782. 0xccd6, 0x000,
  783. 0xccd7, 0xc621,
  784. 0xccd8, 0x000,
  785. 0xccd9, 0xc622,
  786. 0xccda, 0x0ce,
  787. 0xccdb, 0xc623,
  788. 0xccdc, 0x07f,
  789. 0xccdd, 0xc624,
  790. 0xccde, 0x032,
  791. 0xccdf, 0xc625,
  792. 0xcce0, 0x000,
  793. 0xcce1, 0xc627,
  794. 0xcce2, 0x000,
  795. 0xcce3, 0xc628,
  796. 0xcce4, 0x000,
  797. 0xcce5, 0xc62b,
  798. 0xcce6, 0x000,
  799. 0xcce7, 0xc62c,
  800. 0xcce8, 0x000,
  801. 0xcce9, 0x000,
  802. 0xccea, 0x2d01,
  803. 0xcceb, 0x3011,
  804. 0xccec, 0x1001,
  805. 0xcced, 0xc502,
  806. 0xccee, 0x609f,
  807. 0xccef, 0xc600,
  808. 0xccf0, 0x2a6e,
  809. 0xccf1, 0xc601,
  810. 0xccf2, 0x2a2c,
  811. 0xccf3, 0xc60c,
  812. 0xccf4, 0x5400,
  813. 0xccf5, 0xc710,
  814. 0xccf6, 0x700,
  815. 0xccf7, 0xc718,
  816. 0xccf8, 0x700,
  817. 0xccf9, 0xc720,
  818. 0xccfa, 0x4700,
  819. 0xccfb, 0xc728,
  820. 0xccfc, 0x700,
  821. 0xccfd, 0xc729,
  822. 0xccfe, 0x1207,
  823. 0xccff, 0xc801,
  824. 0xcd00, 0x7f50,
  825. 0xcd01, 0xc802,
  826. 0xcd02, 0x7760,
  827. 0xcd03, 0xc803,
  828. 0xcd04, 0x7fce,
  829. 0xcd05, 0xc804,
  830. 0xcd06, 0x520e,
  831. 0xcd07, 0xc805,
  832. 0xcd08, 0x5c11,
  833. 0xcd09, 0xc806,
  834. 0xcd0a, 0x3c51,
  835. 0xcd0b, 0xc807,
  836. 0xcd0c, 0x4061,
  837. 0xcd0d, 0xc808,
  838. 0xcd0e, 0x49c1,
  839. 0xcd0f, 0xc809,
  840. 0xcd10, 0x3840,
  841. 0xcd11, 0xc80a,
  842. 0xcd12, 0x000,
  843. 0xcd13, 0xc821,
  844. 0xcd14, 0x002,
  845. 0xcd15, 0xc822,
  846. 0xcd16, 0x046,
  847. 0xcd17, 0xc844,
  848. 0xcd18, 0x182f,
  849. 0xcd19, 0xc013,
  850. 0xcd1a, 0xf341,
  851. 0xcd1b, 0xc01a,
  852. 0xcd1c, 0x446,
  853. 0xcd1d, 0xc024,
  854. 0xcd1e, 0x1000,
  855. 0xcd1f, 0xc025,
  856. 0xcd20, 0xa00,
  857. 0xcd21, 0xc026,
  858. 0xcd22, 0xc0c,
  859. 0xcd23, 0xc027,
  860. 0xcd24, 0xc0c,
  861. 0xcd25, 0xc029,
  862. 0xcd26, 0x0a0,
  863. 0xcd27, 0xc030,
  864. 0xcd28, 0xa00,
  865. 0xcd29, 0xc03c,
  866. 0xcd2a, 0x01c,
  867. 0xcd2b, 0x000,
  868. 0xcd2c, 0x2b84,
  869. 0xcd2d, 0x3c74,
  870. 0xcd2e, 0x6435,
  871. 0xcd2f, 0xdff4,
  872. 0xcd30, 0x6435,
  873. 0xcd31, 0x2806,
  874. 0xcd32, 0x3006,
  875. 0xcd33, 0x8565,
  876. 0xcd34, 0x2b24,
  877. 0xcd35, 0x3c24,
  878. 0xcd36, 0x6436,
  879. 0xcd37, 0x1002,
  880. 0xcd38, 0x2b24,
  881. 0xcd39, 0x3c24,
  882. 0xcd3a, 0x6436,
  883. 0xcd3b, 0x4045,
  884. 0xcd3c, 0x8656,
  885. 0xcd3d, 0x1002,
  886. 0xcd3e, 0x2807,
  887. 0xcd3f, 0x31a7,
  888. 0xcd40, 0x20c4,
  889. 0xcd41, 0x3c24,
  890. 0xcd42, 0x6724,
  891. 0xcd43, 0x1002,
  892. 0xcd44, 0x2807,
  893. 0xcd45, 0x3187,
  894. 0xcd46, 0x20c4,
  895. 0xcd47, 0x3c24,
  896. 0xcd48, 0x6724,
  897. 0xcd49, 0x1002,
  898. 0xcd4a, 0x2514,
  899. 0xcd4b, 0x3c64,
  900. 0xcd4c, 0x6436,
  901. 0xcd4d, 0xdff4,
  902. 0xcd4e, 0x6436,
  903. 0xcd4f, 0x1002,
  904. 0xcd50, 0x2806,
  905. 0xcd51, 0x3cb6,
  906. 0xcd52, 0xc161,
  907. 0xcd53, 0x6134,
  908. 0xcd54, 0x6135,
  909. 0xcd55, 0x5443,
  910. 0xcd56, 0x303,
  911. 0xcd57, 0x6524,
  912. 0xcd58, 0x00b,
  913. 0xcd59, 0x1002,
  914. 0xcd5a, 0xd019,
  915. 0xcd5b, 0x2104,
  916. 0xcd5c, 0x3c24,
  917. 0xcd5d, 0x2105,
  918. 0xcd5e, 0x3805,
  919. 0xcd5f, 0x6524,
  920. 0xcd60, 0xdff4,
  921. 0xcd61, 0x4005,
  922. 0xcd62, 0x6524,
  923. 0xcd63, 0x2e8d,
  924. 0xcd64, 0x303d,
  925. 0xcd65, 0x5dd3,
  926. 0xcd66, 0x306,
  927. 0xcd67, 0x2ff7,
  928. 0xcd68, 0x38f7,
  929. 0xcd69, 0x60b7,
  930. 0xcd6a, 0xdffd,
  931. 0xcd6b, 0x00a,
  932. 0xcd6c, 0x1002,
  933. 0xcd6d, 0
  934. };
  935. int i, err;
  936. err = set_phy_regs(phy, regs);
  937. if (!err && modtype == phy_modtype_twinax_long)
  938. err = set_phy_regs(phy, preemphasis);
  939. if (err)
  940. return err;
  941. msleep(50);
  942. for (i = 0; i < ARRAY_SIZE(twinax_edc) && !err; i += 2)
  943. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, twinax_edc[i],
  944. twinax_edc[i + 1]);
  945. if (!err)
  946. phy->priv = edc_twinax;
  947. return err;
  948. }
  949. static int ael2005_get_module_type(struct cphy *phy, int delay_ms)
  950. {
  951. int v;
  952. unsigned int stat;
  953. v = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, &stat);
  954. if (v)
  955. return v;
  956. if (stat & (1 << 8)) /* module absent */
  957. return phy_modtype_none;
  958. return ael2xxx_get_module_type(phy, delay_ms);
  959. }
  960. static int ael2005_intr_enable(struct cphy *phy)
  961. {
  962. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, 0x200);
  963. return err ? err : t3_phy_lasi_intr_enable(phy);
  964. }
  965. static int ael2005_intr_disable(struct cphy *phy)
  966. {
  967. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, 0x100);
  968. return err ? err : t3_phy_lasi_intr_disable(phy);
  969. }
  970. static int ael2005_intr_clear(struct cphy *phy)
  971. {
  972. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, 0xd00);
  973. return err ? err : t3_phy_lasi_intr_clear(phy);
  974. }
  975. static int ael2005_reset(struct cphy *phy, int wait)
  976. {
  977. static struct reg_val regs0[] = {
  978. { MDIO_MMD_PMAPMD, 0xc001, 0, 1 << 5 },
  979. { MDIO_MMD_PMAPMD, 0xc017, 0, 1 << 5 },
  980. { MDIO_MMD_PMAPMD, 0xc013, 0xffff, 0xf341 },
  981. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0x8000 },
  982. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0x8100 },
  983. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0x8000 },
  984. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0 },
  985. { 0, 0, 0, 0 }
  986. };
  987. static struct reg_val regs1[] = {
  988. { MDIO_MMD_PMAPMD, 0xca00, 0xffff, 0x0080 },
  989. { MDIO_MMD_PMAPMD, 0xca12, 0xffff, 0 },
  990. { 0, 0, 0, 0 }
  991. };
  992. int err;
  993. unsigned int lasi_ctrl;
  994. err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL,
  995. &lasi_ctrl);
  996. if (err)
  997. return err;
  998. err = t3_phy_reset(phy, MDIO_MMD_PMAPMD, 0);
  999. if (err)
  1000. return err;
  1001. msleep(125);
  1002. phy->priv = edc_none;
  1003. err = set_phy_regs(phy, regs0);
  1004. if (err)
  1005. return err;
  1006. msleep(50);
  1007. err = ael2005_get_module_type(phy, 0);
  1008. if (err < 0)
  1009. return err;
  1010. phy->modtype = err;
  1011. if (err == phy_modtype_twinax || err == phy_modtype_twinax_long)
  1012. err = ael2005_setup_twinax_edc(phy, err);
  1013. else
  1014. err = ael2005_setup_sr_edc(phy);
  1015. if (err)
  1016. return err;
  1017. err = set_phy_regs(phy, regs1);
  1018. if (err)
  1019. return err;
  1020. /* reset wipes out interrupts, reenable them if they were on */
  1021. if (lasi_ctrl & 1)
  1022. err = ael2005_intr_enable(phy);
  1023. return err;
  1024. }
  1025. static int ael2005_intr_handler(struct cphy *phy)
  1026. {
  1027. unsigned int stat;
  1028. int ret, edc_needed, cause = 0;
  1029. ret = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_STAT, &stat);
  1030. if (ret)
  1031. return ret;
  1032. if (stat & AEL2005_MODDET_IRQ) {
  1033. ret = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL,
  1034. 0xd00);
  1035. if (ret)
  1036. return ret;
  1037. /* modules have max 300 ms init time after hot plug */
  1038. ret = ael2005_get_module_type(phy, 300);
  1039. if (ret < 0)
  1040. return ret;
  1041. phy->modtype = ret;
  1042. if (ret == phy_modtype_none)
  1043. edc_needed = phy->priv; /* on unplug retain EDC */
  1044. else if (ret == phy_modtype_twinax ||
  1045. ret == phy_modtype_twinax_long)
  1046. edc_needed = edc_twinax;
  1047. else
  1048. edc_needed = edc_sr;
  1049. if (edc_needed != phy->priv) {
  1050. ret = ael2005_reset(phy, 0);
  1051. return ret ? ret : cphy_cause_module_change;
  1052. }
  1053. cause = cphy_cause_module_change;
  1054. }
  1055. ret = t3_phy_lasi_intr_handler(phy);
  1056. if (ret < 0)
  1057. return ret;
  1058. ret |= cause;
  1059. return ret ? ret : cphy_cause_link_change;
  1060. }
  1061. static struct cphy_ops ael2005_ops = {
  1062. .reset = ael2005_reset,
  1063. .intr_enable = ael2005_intr_enable,
  1064. .intr_disable = ael2005_intr_disable,
  1065. .intr_clear = ael2005_intr_clear,
  1066. .intr_handler = ael2005_intr_handler,
  1067. .get_link_status = get_link_status_r,
  1068. .power_down = ael1002_power_down,
  1069. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  1070. };
  1071. int t3_ael2005_phy_prep(struct cphy *phy, struct adapter *adapter,
  1072. int phy_addr, const struct mdio_ops *mdio_ops)
  1073. {
  1074. cphy_init(phy, adapter, phy_addr, &ael2005_ops, mdio_ops,
  1075. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE |
  1076. SUPPORTED_IRQ, "10GBASE-R");
  1077. msleep(125);
  1078. return t3_mdio_change_bits(phy, MDIO_MMD_PMAPMD, AEL_OPT_SETTINGS, 0,
  1079. 1 << 5);
  1080. }
  1081. /*
  1082. * Setup EDC and other parameters for operation with an optical module.
  1083. */
  1084. static int ael2020_setup_sr_edc(struct cphy *phy)
  1085. {
  1086. static struct reg_val regs[] = {
  1087. /* set CDR offset to 10 */
  1088. { MDIO_MMD_PMAPMD, 0xcc01, 0xffff, 0x488a },
  1089. /* adjust 10G RX bias current */
  1090. { MDIO_MMD_PMAPMD, 0xcb1b, 0xffff, 0x0200 },
  1091. { MDIO_MMD_PMAPMD, 0xcb1c, 0xffff, 0x00f0 },
  1092. { MDIO_MMD_PMAPMD, 0xcc06, 0xffff, 0x00e0 },
  1093. /* end */
  1094. { 0, 0, 0, 0 }
  1095. };
  1096. int err;
  1097. err = set_phy_regs(phy, regs);
  1098. msleep(50);
  1099. if (err)
  1100. return err;
  1101. phy->priv = edc_sr;
  1102. return 0;
  1103. }
  1104. /*
  1105. * Setup EDC and other parameters for operation with an TWINAX module.
  1106. */
  1107. static int ael2020_setup_twinax_edc(struct cphy *phy, int modtype)
  1108. {
  1109. /* set uC to 40MHz */
  1110. static struct reg_val uCclock40MHz[] = {
  1111. { MDIO_MMD_PMAPMD, 0xff28, 0xffff, 0x4001 },
  1112. { MDIO_MMD_PMAPMD, 0xff2a, 0xffff, 0x0002 },
  1113. { 0, 0, 0, 0 }
  1114. };
  1115. /* activate uC clock */
  1116. static struct reg_val uCclockActivate[] = {
  1117. { MDIO_MMD_PMAPMD, 0xd000, 0xffff, 0x5200 },
  1118. { 0, 0, 0, 0 }
  1119. };
  1120. /* set PC to start of SRAM and activate uC */
  1121. static struct reg_val uCactivate[] = {
  1122. { MDIO_MMD_PMAPMD, 0xd080, 0xffff, 0x0100 },
  1123. { MDIO_MMD_PMAPMD, 0xd092, 0xffff, 0x0000 },
  1124. { 0, 0, 0, 0 }
  1125. };
  1126. /* TWINAX EDC firmware */
  1127. static u16 twinax_edc[] = {
  1128. 0xd800, 0x4009,
  1129. 0xd801, 0x2fff,
  1130. 0xd802, 0x300f,
  1131. 0xd803, 0x40aa,
  1132. 0xd804, 0x401c,
  1133. 0xd805, 0x401e,
  1134. 0xd806, 0x2ff4,
  1135. 0xd807, 0x3dc4,
  1136. 0xd808, 0x2035,
  1137. 0xd809, 0x3035,
  1138. 0xd80a, 0x6524,
  1139. 0xd80b, 0x2cb2,
  1140. 0xd80c, 0x3012,
  1141. 0xd80d, 0x1002,
  1142. 0xd80e, 0x26e2,
  1143. 0xd80f, 0x3022,
  1144. 0xd810, 0x1002,
  1145. 0xd811, 0x27d2,
  1146. 0xd812, 0x3022,
  1147. 0xd813, 0x1002,
  1148. 0xd814, 0x2822,
  1149. 0xd815, 0x3012,
  1150. 0xd816, 0x1002,
  1151. 0xd817, 0x2492,
  1152. 0xd818, 0x3022,
  1153. 0xd819, 0x1002,
  1154. 0xd81a, 0x2772,
  1155. 0xd81b, 0x3012,
  1156. 0xd81c, 0x1002,
  1157. 0xd81d, 0x23d2,
  1158. 0xd81e, 0x3022,
  1159. 0xd81f, 0x1002,
  1160. 0xd820, 0x22cd,
  1161. 0xd821, 0x301d,
  1162. 0xd822, 0x27f2,
  1163. 0xd823, 0x3022,
  1164. 0xd824, 0x1002,
  1165. 0xd825, 0x5553,
  1166. 0xd826, 0x0307,
  1167. 0xd827, 0x2522,
  1168. 0xd828, 0x3022,
  1169. 0xd829, 0x1002,
  1170. 0xd82a, 0x2142,
  1171. 0xd82b, 0x3012,
  1172. 0xd82c, 0x1002,
  1173. 0xd82d, 0x4016,
  1174. 0xd82e, 0x5e63,
  1175. 0xd82f, 0x0344,
  1176. 0xd830, 0x2142,
  1177. 0xd831, 0x3012,
  1178. 0xd832, 0x1002,
  1179. 0xd833, 0x400e,
  1180. 0xd834, 0x2522,
  1181. 0xd835, 0x3022,
  1182. 0xd836, 0x1002,
  1183. 0xd837, 0x2b52,
  1184. 0xd838, 0x3012,
  1185. 0xd839, 0x1002,
  1186. 0xd83a, 0x2742,
  1187. 0xd83b, 0x3022,
  1188. 0xd83c, 0x1002,
  1189. 0xd83d, 0x25e2,
  1190. 0xd83e, 0x3022,
  1191. 0xd83f, 0x1002,
  1192. 0xd840, 0x2fa4,
  1193. 0xd841, 0x3dc4,
  1194. 0xd842, 0x6624,
  1195. 0xd843, 0x414b,
  1196. 0xd844, 0x56b3,
  1197. 0xd845, 0x03c6,
  1198. 0xd846, 0x866b,
  1199. 0xd847, 0x400c,
  1200. 0xd848, 0x2712,
  1201. 0xd849, 0x3012,
  1202. 0xd84a, 0x1002,
  1203. 0xd84b, 0x2c4b,
  1204. 0xd84c, 0x309b,
  1205. 0xd84d, 0x56b3,
  1206. 0xd84e, 0x03c3,
  1207. 0xd84f, 0x866b,
  1208. 0xd850, 0x400c,
  1209. 0xd851, 0x2272,
  1210. 0xd852, 0x3022,
  1211. 0xd853, 0x1002,
  1212. 0xd854, 0x2742,
  1213. 0xd855, 0x3022,
  1214. 0xd856, 0x1002,
  1215. 0xd857, 0x25e2,
  1216. 0xd858, 0x3022,
  1217. 0xd859, 0x1002,
  1218. 0xd85a, 0x2fb4,
  1219. 0xd85b, 0x3dc4,
  1220. 0xd85c, 0x6624,
  1221. 0xd85d, 0x56b3,
  1222. 0xd85e, 0x03c3,
  1223. 0xd85f, 0x866b,
  1224. 0xd860, 0x401c,
  1225. 0xd861, 0x2c45,
  1226. 0xd862, 0x3095,
  1227. 0xd863, 0x5b53,
  1228. 0xd864, 0x2372,
  1229. 0xd865, 0x3012,
  1230. 0xd866, 0x13c2,
  1231. 0xd867, 0x5cc3,
  1232. 0xd868, 0x2712,
  1233. 0xd869, 0x3012,
  1234. 0xd86a, 0x1312,
  1235. 0xd86b, 0x2b52,
  1236. 0xd86c, 0x3012,
  1237. 0xd86d, 0x1002,
  1238. 0xd86e, 0x2742,
  1239. 0xd86f, 0x3022,
  1240. 0xd870, 0x1002,
  1241. 0xd871, 0x2582,
  1242. 0xd872, 0x3022,
  1243. 0xd873, 0x1002,
  1244. 0xd874, 0x2142,
  1245. 0xd875, 0x3012,
  1246. 0xd876, 0x1002,
  1247. 0xd877, 0x628f,
  1248. 0xd878, 0x2985,
  1249. 0xd879, 0x33a5,
  1250. 0xd87a, 0x25e2,
  1251. 0xd87b, 0x3022,
  1252. 0xd87c, 0x1002,
  1253. 0xd87d, 0x5653,
  1254. 0xd87e, 0x03d2,
  1255. 0xd87f, 0x401e,
  1256. 0xd880, 0x6f72,
  1257. 0xd881, 0x1002,
  1258. 0xd882, 0x628f,
  1259. 0xd883, 0x2304,
  1260. 0xd884, 0x3c84,
  1261. 0xd885, 0x6436,
  1262. 0xd886, 0xdff4,
  1263. 0xd887, 0x6436,
  1264. 0xd888, 0x2ff5,
  1265. 0xd889, 0x3005,
  1266. 0xd88a, 0x8656,
  1267. 0xd88b, 0xdfba,
  1268. 0xd88c, 0x56a3,
  1269. 0xd88d, 0xd05a,
  1270. 0xd88e, 0x2972,
  1271. 0xd88f, 0x3012,
  1272. 0xd890, 0x1392,
  1273. 0xd891, 0xd05a,
  1274. 0xd892, 0x56a3,
  1275. 0xd893, 0xdfba,
  1276. 0xd894, 0x0383,
  1277. 0xd895, 0x6f72,
  1278. 0xd896, 0x1002,
  1279. 0xd897, 0x2b45,
  1280. 0xd898, 0x3005,
  1281. 0xd899, 0x4178,
  1282. 0xd89a, 0x5653,
  1283. 0xd89b, 0x0384,
  1284. 0xd89c, 0x2a62,
  1285. 0xd89d, 0x3012,
  1286. 0xd89e, 0x1002,
  1287. 0xd89f, 0x2f05,
  1288. 0xd8a0, 0x3005,
  1289. 0xd8a1, 0x41c8,
  1290. 0xd8a2, 0x5653,
  1291. 0xd8a3, 0x0382,
  1292. 0xd8a4, 0x0002,
  1293. 0xd8a5, 0x4218,
  1294. 0xd8a6, 0x2474,
  1295. 0xd8a7, 0x3c84,
  1296. 0xd8a8, 0x6437,
  1297. 0xd8a9, 0xdff4,
  1298. 0xd8aa, 0x6437,
  1299. 0xd8ab, 0x2ff5,
  1300. 0xd8ac, 0x3c05,
  1301. 0xd8ad, 0x8757,
  1302. 0xd8ae, 0xb888,
  1303. 0xd8af, 0x9787,
  1304. 0xd8b0, 0xdff4,
  1305. 0xd8b1, 0x6724,
  1306. 0xd8b2, 0x866a,
  1307. 0xd8b3, 0x6f72,
  1308. 0xd8b4, 0x1002,
  1309. 0xd8b5, 0x2641,
  1310. 0xd8b6, 0x3021,
  1311. 0xd8b7, 0x1001,
  1312. 0xd8b8, 0xc620,
  1313. 0xd8b9, 0x0000,
  1314. 0xd8ba, 0xc621,
  1315. 0xd8bb, 0x0000,
  1316. 0xd8bc, 0xc622,
  1317. 0xd8bd, 0x00ce,
  1318. 0xd8be, 0xc623,
  1319. 0xd8bf, 0x007f,
  1320. 0xd8c0, 0xc624,
  1321. 0xd8c1, 0x0032,
  1322. 0xd8c2, 0xc625,
  1323. 0xd8c3, 0x0000,
  1324. 0xd8c4, 0xc627,
  1325. 0xd8c5, 0x0000,
  1326. 0xd8c6, 0xc628,
  1327. 0xd8c7, 0x0000,
  1328. 0xd8c8, 0xc62c,
  1329. 0xd8c9, 0x0000,
  1330. 0xd8ca, 0x0000,
  1331. 0xd8cb, 0x2641,
  1332. 0xd8cc, 0x3021,
  1333. 0xd8cd, 0x1001,
  1334. 0xd8ce, 0xc502,
  1335. 0xd8cf, 0x53ac,
  1336. 0xd8d0, 0xc503,
  1337. 0xd8d1, 0x2cd3,
  1338. 0xd8d2, 0xc600,
  1339. 0xd8d3, 0x2a6e,
  1340. 0xd8d4, 0xc601,
  1341. 0xd8d5, 0x2a2c,
  1342. 0xd8d6, 0xc605,
  1343. 0xd8d7, 0x5557,
  1344. 0xd8d8, 0xc60c,
  1345. 0xd8d9, 0x5400,
  1346. 0xd8da, 0xc710,
  1347. 0xd8db, 0x0700,
  1348. 0xd8dc, 0xc711,
  1349. 0xd8dd, 0x0f06,
  1350. 0xd8de, 0xc718,
  1351. 0xd8df, 0x0700,
  1352. 0xd8e0, 0xc719,
  1353. 0xd8e1, 0x0f06,
  1354. 0xd8e2, 0xc720,
  1355. 0xd8e3, 0x4700,
  1356. 0xd8e4, 0xc721,
  1357. 0xd8e5, 0x0f06,
  1358. 0xd8e6, 0xc728,
  1359. 0xd8e7, 0x0700,
  1360. 0xd8e8, 0xc729,
  1361. 0xd8e9, 0x1207,
  1362. 0xd8ea, 0xc801,
  1363. 0xd8eb, 0x7f50,
  1364. 0xd8ec, 0xc802,
  1365. 0xd8ed, 0x7760,
  1366. 0xd8ee, 0xc803,
  1367. 0xd8ef, 0x7fce,
  1368. 0xd8f0, 0xc804,
  1369. 0xd8f1, 0x520e,
  1370. 0xd8f2, 0xc805,
  1371. 0xd8f3, 0x5c11,
  1372. 0xd8f4, 0xc806,
  1373. 0xd8f5, 0x3c51,
  1374. 0xd8f6, 0xc807,
  1375. 0xd8f7, 0x4061,
  1376. 0xd8f8, 0xc808,
  1377. 0xd8f9, 0x49c1,
  1378. 0xd8fa, 0xc809,
  1379. 0xd8fb, 0x3840,
  1380. 0xd8fc, 0xc80a,
  1381. 0xd8fd, 0x0000,
  1382. 0xd8fe, 0xc821,
  1383. 0xd8ff, 0x0002,
  1384. 0xd900, 0xc822,
  1385. 0xd901, 0x0046,
  1386. 0xd902, 0xc844,
  1387. 0xd903, 0x182f,
  1388. 0xd904, 0xc013,
  1389. 0xd905, 0xf341,
  1390. 0xd906, 0xc084,
  1391. 0xd907, 0x0030,
  1392. 0xd908, 0xc904,
  1393. 0xd909, 0x1401,
  1394. 0xd90a, 0xcb0c,
  1395. 0xd90b, 0x0004,
  1396. 0xd90c, 0xcb0e,
  1397. 0xd90d, 0xa00a,
  1398. 0xd90e, 0xcb0f,
  1399. 0xd90f, 0xc0c0,
  1400. 0xd910, 0xcb10,
  1401. 0xd911, 0xc0c0,
  1402. 0xd912, 0xcb11,
  1403. 0xd913, 0x00a0,
  1404. 0xd914, 0xcb12,
  1405. 0xd915, 0x0007,
  1406. 0xd916, 0xc241,
  1407. 0xd917, 0xa000,
  1408. 0xd918, 0xc243,
  1409. 0xd919, 0x7fe0,
  1410. 0xd91a, 0xc604,
  1411. 0xd91b, 0x000e,
  1412. 0xd91c, 0xc609,
  1413. 0xd91d, 0x00f5,
  1414. 0xd91e, 0xc611,
  1415. 0xd91f, 0x000e,
  1416. 0xd920, 0xc660,
  1417. 0xd921, 0x9600,
  1418. 0xd922, 0xc687,
  1419. 0xd923, 0x0004,
  1420. 0xd924, 0xc60a,
  1421. 0xd925, 0x04f5,
  1422. 0xd926, 0x0000,
  1423. 0xd927, 0x2641,
  1424. 0xd928, 0x3021,
  1425. 0xd929, 0x1001,
  1426. 0xd92a, 0xc620,
  1427. 0xd92b, 0x14e5,
  1428. 0xd92c, 0xc621,
  1429. 0xd92d, 0xc53d,
  1430. 0xd92e, 0xc622,
  1431. 0xd92f, 0x3cbe,
  1432. 0xd930, 0xc623,
  1433. 0xd931, 0x4452,
  1434. 0xd932, 0xc624,
  1435. 0xd933, 0xc5c5,
  1436. 0xd934, 0xc625,
  1437. 0xd935, 0xe01e,
  1438. 0xd936, 0xc627,
  1439. 0xd937, 0x0000,
  1440. 0xd938, 0xc628,
  1441. 0xd939, 0x0000,
  1442. 0xd93a, 0xc62c,
  1443. 0xd93b, 0x0000,
  1444. 0xd93c, 0x0000,
  1445. 0xd93d, 0x2b84,
  1446. 0xd93e, 0x3c74,
  1447. 0xd93f, 0x6435,
  1448. 0xd940, 0xdff4,
  1449. 0xd941, 0x6435,
  1450. 0xd942, 0x2806,
  1451. 0xd943, 0x3006,
  1452. 0xd944, 0x8565,
  1453. 0xd945, 0x2b24,
  1454. 0xd946, 0x3c24,
  1455. 0xd947, 0x6436,
  1456. 0xd948, 0x1002,
  1457. 0xd949, 0x2b24,
  1458. 0xd94a, 0x3c24,
  1459. 0xd94b, 0x6436,
  1460. 0xd94c, 0x4045,
  1461. 0xd94d, 0x8656,
  1462. 0xd94e, 0x5663,
  1463. 0xd94f, 0x0302,
  1464. 0xd950, 0x401e,
  1465. 0xd951, 0x1002,
  1466. 0xd952, 0x2807,
  1467. 0xd953, 0x31a7,
  1468. 0xd954, 0x20c4,
  1469. 0xd955, 0x3c24,
  1470. 0xd956, 0x6724,
  1471. 0xd957, 0x1002,
  1472. 0xd958, 0x2807,
  1473. 0xd959, 0x3187,
  1474. 0xd95a, 0x20c4,
  1475. 0xd95b, 0x3c24,
  1476. 0xd95c, 0x6724,
  1477. 0xd95d, 0x1002,
  1478. 0xd95e, 0x24f4,
  1479. 0xd95f, 0x3c64,
  1480. 0xd960, 0x6436,
  1481. 0xd961, 0xdff4,
  1482. 0xd962, 0x6436,
  1483. 0xd963, 0x1002,
  1484. 0xd964, 0x2006,
  1485. 0xd965, 0x3d76,
  1486. 0xd966, 0xc161,
  1487. 0xd967, 0x6134,
  1488. 0xd968, 0x6135,
  1489. 0xd969, 0x5443,
  1490. 0xd96a, 0x0303,
  1491. 0xd96b, 0x6524,
  1492. 0xd96c, 0x00fb,
  1493. 0xd96d, 0x1002,
  1494. 0xd96e, 0x20d4,
  1495. 0xd96f, 0x3c24,
  1496. 0xd970, 0x2025,
  1497. 0xd971, 0x3005,
  1498. 0xd972, 0x6524,
  1499. 0xd973, 0x1002,
  1500. 0xd974, 0xd019,
  1501. 0xd975, 0x2104,
  1502. 0xd976, 0x3c24,
  1503. 0xd977, 0x2105,
  1504. 0xd978, 0x3805,
  1505. 0xd979, 0x6524,
  1506. 0xd97a, 0xdff4,
  1507. 0xd97b, 0x4005,
  1508. 0xd97c, 0x6524,
  1509. 0xd97d, 0x2e8d,
  1510. 0xd97e, 0x303d,
  1511. 0xd97f, 0x2408,
  1512. 0xd980, 0x35d8,
  1513. 0xd981, 0x5dd3,
  1514. 0xd982, 0x0307,
  1515. 0xd983, 0x8887,
  1516. 0xd984, 0x63a7,
  1517. 0xd985, 0x8887,
  1518. 0xd986, 0x63a7,
  1519. 0xd987, 0xdffd,
  1520. 0xd988, 0x00f9,
  1521. 0xd989, 0x1002,
  1522. 0xd98a, 0x0000,
  1523. };
  1524. int i, err;
  1525. /* set uC clock and activate it */
  1526. err = set_phy_regs(phy, uCclock40MHz);
  1527. msleep(500);
  1528. if (err)
  1529. return err;
  1530. err = set_phy_regs(phy, uCclockActivate);
  1531. msleep(500);
  1532. if (err)
  1533. return err;
  1534. /* write TWINAX EDC firmware into PHY */
  1535. for (i = 0; i < ARRAY_SIZE(twinax_edc) && !err; i += 2)
  1536. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, twinax_edc[i],
  1537. twinax_edc[i + 1]);
  1538. /* activate uC */
  1539. err = set_phy_regs(phy, uCactivate);
  1540. if (!err)
  1541. phy->priv = edc_twinax;
  1542. return err;
  1543. }
  1544. /*
  1545. * Return Module Type.
  1546. */
  1547. static int ael2020_get_module_type(struct cphy *phy, int delay_ms)
  1548. {
  1549. int v;
  1550. unsigned int stat;
  1551. v = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_STAT, &stat);
  1552. if (v)
  1553. return v;
  1554. if (stat & (0x1 << (AEL2020_GPIO_MODDET*4))) {
  1555. /* module absent */
  1556. return phy_modtype_none;
  1557. }
  1558. return ael2xxx_get_module_type(phy, delay_ms);
  1559. }
  1560. /*
  1561. * Enable PHY interrupts. We enable "Module Detection" interrupts (on any
  1562. * state transition) and then generic Link Alarm Status Interrupt (LASI).
  1563. */
  1564. static int ael2020_intr_enable(struct cphy *phy)
  1565. {
  1566. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  1567. 0x2 << (AEL2020_GPIO_MODDET*4));
  1568. return err ? err : t3_phy_lasi_intr_enable(phy);
  1569. }
  1570. /*
  1571. * Disable PHY interrupts. The mirror of the above ...
  1572. */
  1573. static int ael2020_intr_disable(struct cphy *phy)
  1574. {
  1575. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  1576. 0x1 << (AEL2020_GPIO_MODDET*4));
  1577. return err ? err : t3_phy_lasi_intr_disable(phy);
  1578. }
  1579. /*
  1580. * Clear PHY interrupt state.
  1581. */
  1582. static int ael2020_intr_clear(struct cphy *phy)
  1583. {
  1584. /*
  1585. * The GPIO Interrupt register on the AEL2020 is a "Latching High"
  1586. * (LH) register which is cleared to the current state when it's read.
  1587. * Thus, we simply read the register and discard the result.
  1588. */
  1589. unsigned int stat;
  1590. int err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_INTR, &stat);
  1591. return err ? err : t3_phy_lasi_intr_clear(phy);
  1592. }
  1593. /*
  1594. * Reset the PHY and put it into a canonical operating state.
  1595. */
  1596. static int ael2020_reset(struct cphy *phy, int wait)
  1597. {
  1598. static struct reg_val regs0[] = {
  1599. /* Erratum #2: CDRLOL asserted, causing PMA link down status */
  1600. { MDIO_MMD_PMAPMD, 0xc003, 0xffff, 0x3101 },
  1601. /* force XAUI to send LF when RX_LOS is asserted */
  1602. { MDIO_MMD_PMAPMD, 0xcd40, 0xffff, 0x0001 },
  1603. /* RX_LOS pin is active high */
  1604. { MDIO_MMD_PMAPMD, AEL_OPT_SETTINGS,
  1605. 0x0020, 0x0020 },
  1606. /* output Module's Loss Of Signal (LOS) to LED */
  1607. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CFG+AEL2020_GPIO_LSTAT,
  1608. 0xffff, 0x0004 },
  1609. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  1610. 0xffff, 0x8 << (AEL2020_GPIO_LSTAT*4) },
  1611. /* end */
  1612. { 0, 0, 0, 0 }
  1613. };
  1614. int err;
  1615. unsigned int lasi_ctrl;
  1616. /* grab current interrupt state */
  1617. err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL,
  1618. &lasi_ctrl);
  1619. if (err)
  1620. return err;
  1621. err = t3_phy_reset(phy, MDIO_MMD_PMAPMD, 125);
  1622. if (err)
  1623. return err;
  1624. msleep(100);
  1625. /* basic initialization for all module types */
  1626. phy->priv = edc_none;
  1627. err = set_phy_regs(phy, regs0);
  1628. if (err)
  1629. return err;
  1630. /* determine module type and perform appropriate initialization */
  1631. err = ael2020_get_module_type(phy, 0);
  1632. if (err < 0)
  1633. return err;
  1634. phy->modtype = (u8)err;
  1635. if (err == phy_modtype_twinax || err == phy_modtype_twinax_long)
  1636. err = ael2020_setup_twinax_edc(phy, err);
  1637. else
  1638. err = ael2020_setup_sr_edc(phy);
  1639. if (err)
  1640. return err;
  1641. /* reset wipes out interrupts, reenable them if they were on */
  1642. if (lasi_ctrl & 1)
  1643. err = ael2005_intr_enable(phy);
  1644. return err;
  1645. }
  1646. /*
  1647. * Handle a PHY interrupt.
  1648. */
  1649. static int ael2020_intr_handler(struct cphy *phy)
  1650. {
  1651. unsigned int stat;
  1652. int ret, edc_needed, cause = 0;
  1653. ret = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_INTR, &stat);
  1654. if (ret)
  1655. return ret;
  1656. if (stat & (0x1 << AEL2020_GPIO_MODDET)) {
  1657. /* modules have max 300 ms init time after hot plug */
  1658. ret = ael2020_get_module_type(phy, 300);
  1659. if (ret < 0)
  1660. return ret;
  1661. phy->modtype = (u8)ret;
  1662. if (ret == phy_modtype_none)
  1663. edc_needed = phy->priv; /* on unplug retain EDC */
  1664. else if (ret == phy_modtype_twinax ||
  1665. ret == phy_modtype_twinax_long)
  1666. edc_needed = edc_twinax;
  1667. else
  1668. edc_needed = edc_sr;
  1669. if (edc_needed != phy->priv) {
  1670. ret = ael2020_reset(phy, 0);
  1671. return ret ? ret : cphy_cause_module_change;
  1672. }
  1673. cause = cphy_cause_module_change;
  1674. }
  1675. ret = t3_phy_lasi_intr_handler(phy);
  1676. if (ret < 0)
  1677. return ret;
  1678. ret |= cause;
  1679. return ret ? ret : cphy_cause_link_change;
  1680. }
  1681. static struct cphy_ops ael2020_ops = {
  1682. .reset = ael2020_reset,
  1683. .intr_enable = ael2020_intr_enable,
  1684. .intr_disable = ael2020_intr_disable,
  1685. .intr_clear = ael2020_intr_clear,
  1686. .intr_handler = ael2020_intr_handler,
  1687. .get_link_status = get_link_status_r,
  1688. .power_down = ael1002_power_down,
  1689. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  1690. };
  1691. int t3_ael2020_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
  1692. const struct mdio_ops *mdio_ops)
  1693. {
  1694. cphy_init(phy, adapter, phy_addr, &ael2020_ops, mdio_ops,
  1695. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE |
  1696. SUPPORTED_IRQ, "10GBASE-R");
  1697. msleep(125);
  1698. return 0;
  1699. }
  1700. /*
  1701. * Get link status for a 10GBASE-X device.
  1702. */
  1703. static int get_link_status_x(struct cphy *phy, int *link_ok, int *speed,
  1704. int *duplex, int *fc)
  1705. {
  1706. if (link_ok) {
  1707. unsigned int stat0, stat1, stat2;
  1708. int err = t3_mdio_read(phy, MDIO_MMD_PMAPMD,
  1709. MDIO_PMA_RXDET, &stat0);
  1710. if (!err)
  1711. err = t3_mdio_read(phy, MDIO_MMD_PCS,
  1712. MDIO_PCS_10GBX_STAT1, &stat1);
  1713. if (!err)
  1714. err = t3_mdio_read(phy, MDIO_MMD_PHYXS,
  1715. MDIO_PHYXS_LNSTAT, &stat2);
  1716. if (err)
  1717. return err;
  1718. *link_ok = (stat0 & (stat1 >> 12) & (stat2 >> 12)) & 1;
  1719. }
  1720. if (speed)
  1721. *speed = SPEED_10000;
  1722. if (duplex)
  1723. *duplex = DUPLEX_FULL;
  1724. return 0;
  1725. }
  1726. static struct cphy_ops qt2045_ops = {
  1727. .reset = ael1006_reset,
  1728. .intr_enable = t3_phy_lasi_intr_enable,
  1729. .intr_disable = t3_phy_lasi_intr_disable,
  1730. .intr_clear = t3_phy_lasi_intr_clear,
  1731. .intr_handler = t3_phy_lasi_intr_handler,
  1732. .get_link_status = get_link_status_x,
  1733. .power_down = ael1006_power_down,
  1734. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  1735. };
  1736. int t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter,
  1737. int phy_addr, const struct mdio_ops *mdio_ops)
  1738. {
  1739. unsigned int stat;
  1740. cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops,
  1741. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
  1742. "10GBASE-CX4");
  1743. /*
  1744. * Some cards where the PHY is supposed to be at address 0 actually
  1745. * have it at 1.
  1746. */
  1747. if (!phy_addr &&
  1748. !t3_mdio_read(phy, MDIO_MMD_PMAPMD, MDIO_STAT1, &stat) &&
  1749. stat == 0xffff)
  1750. phy->mdio.prtad = 1;
  1751. return 0;
  1752. }
  1753. static int xaui_direct_reset(struct cphy *phy, int wait)
  1754. {
  1755. return 0;
  1756. }
  1757. static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
  1758. int *speed, int *duplex, int *fc)
  1759. {
  1760. if (link_ok) {
  1761. unsigned int status;
  1762. int prtad = phy->mdio.prtad;
  1763. status = t3_read_reg(phy->adapter,
  1764. XGM_REG(A_XGM_SERDES_STAT0, prtad)) |
  1765. t3_read_reg(phy->adapter,
  1766. XGM_REG(A_XGM_SERDES_STAT1, prtad)) |
  1767. t3_read_reg(phy->adapter,
  1768. XGM_REG(A_XGM_SERDES_STAT2, prtad)) |
  1769. t3_read_reg(phy->adapter,
  1770. XGM_REG(A_XGM_SERDES_STAT3, prtad));
  1771. *link_ok = !(status & F_LOWSIG0);
  1772. }
  1773. if (speed)
  1774. *speed = SPEED_10000;
  1775. if (duplex)
  1776. *duplex = DUPLEX_FULL;
  1777. return 0;
  1778. }
  1779. static int xaui_direct_power_down(struct cphy *phy, int enable)
  1780. {
  1781. return 0;
  1782. }
  1783. static struct cphy_ops xaui_direct_ops = {
  1784. .reset = xaui_direct_reset,
  1785. .intr_enable = ael1002_intr_noop,
  1786. .intr_disable = ael1002_intr_noop,
  1787. .intr_clear = ael1002_intr_noop,
  1788. .intr_handler = ael1002_intr_noop,
  1789. .get_link_status = xaui_direct_get_link_status,
  1790. .power_down = xaui_direct_power_down,
  1791. };
  1792. int t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
  1793. int phy_addr, const struct mdio_ops *mdio_ops)
  1794. {
  1795. cphy_init(phy, adapter, MDIO_PRTAD_NONE, &xaui_direct_ops, mdio_ops,
  1796. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
  1797. "10GBASE-CX4");
  1798. return 0;
  1799. }