ael1002.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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 const 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 const struct cphy_ops ael1006_ops = {
  202. .reset = ael1006_reset,
  203. .intr_enable = t3_phy_lasi_intr_enable,
  204. .intr_disable = t3_phy_lasi_intr_disable,
  205. .intr_clear = t3_phy_lasi_intr_clear,
  206. .intr_handler = t3_phy_lasi_intr_handler,
  207. .get_link_status = get_link_status_r,
  208. .power_down = ael1002_power_down,
  209. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  210. };
  211. int t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
  212. int phy_addr, const struct mdio_ops *mdio_ops)
  213. {
  214. cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops,
  215. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
  216. "10GBASE-SR");
  217. ael100x_txon(phy);
  218. return 0;
  219. }
  220. /*
  221. * Decode our module type.
  222. */
  223. static int ael2xxx_get_module_type(struct cphy *phy, int delay_ms)
  224. {
  225. int v;
  226. if (delay_ms)
  227. msleep(delay_ms);
  228. /* see SFF-8472 for below */
  229. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 3);
  230. if (v < 0)
  231. return v;
  232. if (v == 0x10)
  233. return phy_modtype_sr;
  234. if (v == 0x20)
  235. return phy_modtype_lr;
  236. if (v == 0x40)
  237. return phy_modtype_lrm;
  238. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 6);
  239. if (v < 0)
  240. return v;
  241. if (v != 4)
  242. goto unknown;
  243. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 10);
  244. if (v < 0)
  245. return v;
  246. if (v & 0x80) {
  247. v = ael_i2c_rd(phy, MODULE_DEV_ADDR, 0x12);
  248. if (v < 0)
  249. return v;
  250. return v > 10 ? phy_modtype_twinax_long : phy_modtype_twinax;
  251. }
  252. unknown:
  253. return phy_modtype_unknown;
  254. }
  255. /*
  256. * Code to support the Aeluros/NetLogic 2005 10Gb PHY.
  257. */
  258. static int ael2005_setup_sr_edc(struct cphy *phy)
  259. {
  260. static const struct reg_val regs[] = {
  261. { MDIO_MMD_PMAPMD, 0xc003, 0xffff, 0x181 },
  262. { MDIO_MMD_PMAPMD, 0xc010, 0xffff, 0x448a },
  263. { MDIO_MMD_PMAPMD, 0xc04a, 0xffff, 0x5200 },
  264. { 0, 0, 0, 0 }
  265. };
  266. int i, err;
  267. err = set_phy_regs(phy, regs);
  268. if (err)
  269. return err;
  270. msleep(50);
  271. if (phy->priv != edc_sr)
  272. err = t3_get_edc_fw(phy, EDC_OPT_AEL2005,
  273. EDC_OPT_AEL2005_SIZE);
  274. if (err)
  275. return err;
  276. for (i = 0; i < EDC_OPT_AEL2005_SIZE / sizeof(u16) && !err; i += 2)
  277. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD,
  278. phy->phy_cache[i],
  279. phy->phy_cache[i + 1]);
  280. if (!err)
  281. phy->priv = edc_sr;
  282. return err;
  283. }
  284. static int ael2005_setup_twinax_edc(struct cphy *phy, int modtype)
  285. {
  286. static const struct reg_val regs[] = {
  287. { MDIO_MMD_PMAPMD, 0xc04a, 0xffff, 0x5a00 },
  288. { 0, 0, 0, 0 }
  289. };
  290. static const struct reg_val preemphasis[] = {
  291. { MDIO_MMD_PMAPMD, 0xc014, 0xffff, 0xfe16 },
  292. { MDIO_MMD_PMAPMD, 0xc015, 0xffff, 0xa000 },
  293. { 0, 0, 0, 0 }
  294. };
  295. int i, err;
  296. err = set_phy_regs(phy, regs);
  297. if (!err && modtype == phy_modtype_twinax_long)
  298. err = set_phy_regs(phy, preemphasis);
  299. if (err)
  300. return err;
  301. msleep(50);
  302. if (phy->priv != edc_twinax)
  303. err = t3_get_edc_fw(phy, EDC_TWX_AEL2005,
  304. EDC_TWX_AEL2005_SIZE);
  305. if (err)
  306. return err;
  307. for (i = 0; i < EDC_TWX_AEL2005_SIZE / sizeof(u16) && !err; i += 2)
  308. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD,
  309. phy->phy_cache[i],
  310. phy->phy_cache[i + 1]);
  311. if (!err)
  312. phy->priv = edc_twinax;
  313. return err;
  314. }
  315. static int ael2005_get_module_type(struct cphy *phy, int delay_ms)
  316. {
  317. int v;
  318. unsigned int stat;
  319. v = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, &stat);
  320. if (v)
  321. return v;
  322. if (stat & (1 << 8)) /* module absent */
  323. return phy_modtype_none;
  324. return ael2xxx_get_module_type(phy, delay_ms);
  325. }
  326. static int ael2005_intr_enable(struct cphy *phy)
  327. {
  328. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, 0x200);
  329. return err ? err : t3_phy_lasi_intr_enable(phy);
  330. }
  331. static int ael2005_intr_disable(struct cphy *phy)
  332. {
  333. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, 0x100);
  334. return err ? err : t3_phy_lasi_intr_disable(phy);
  335. }
  336. static int ael2005_intr_clear(struct cphy *phy)
  337. {
  338. int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL, 0xd00);
  339. return err ? err : t3_phy_lasi_intr_clear(phy);
  340. }
  341. static int ael2005_reset(struct cphy *phy, int wait)
  342. {
  343. static const struct reg_val regs0[] = {
  344. { MDIO_MMD_PMAPMD, 0xc001, 0, 1 << 5 },
  345. { MDIO_MMD_PMAPMD, 0xc017, 0, 1 << 5 },
  346. { MDIO_MMD_PMAPMD, 0xc013, 0xffff, 0xf341 },
  347. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0x8000 },
  348. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0x8100 },
  349. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0x8000 },
  350. { MDIO_MMD_PMAPMD, 0xc210, 0xffff, 0 },
  351. { 0, 0, 0, 0 }
  352. };
  353. static const struct reg_val regs1[] = {
  354. { MDIO_MMD_PMAPMD, 0xca00, 0xffff, 0x0080 },
  355. { MDIO_MMD_PMAPMD, 0xca12, 0xffff, 0 },
  356. { 0, 0, 0, 0 }
  357. };
  358. int err;
  359. unsigned int lasi_ctrl;
  360. err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL,
  361. &lasi_ctrl);
  362. if (err)
  363. return err;
  364. err = t3_phy_reset(phy, MDIO_MMD_PMAPMD, 0);
  365. if (err)
  366. return err;
  367. msleep(125);
  368. phy->priv = edc_none;
  369. err = set_phy_regs(phy, regs0);
  370. if (err)
  371. return err;
  372. msleep(50);
  373. err = ael2005_get_module_type(phy, 0);
  374. if (err < 0)
  375. return err;
  376. phy->modtype = err;
  377. if (err == phy_modtype_twinax || err == phy_modtype_twinax_long)
  378. err = ael2005_setup_twinax_edc(phy, err);
  379. else
  380. err = ael2005_setup_sr_edc(phy);
  381. if (err)
  382. return err;
  383. err = set_phy_regs(phy, regs1);
  384. if (err)
  385. return err;
  386. /* reset wipes out interrupts, reenable them if they were on */
  387. if (lasi_ctrl & 1)
  388. err = ael2005_intr_enable(phy);
  389. return err;
  390. }
  391. static int ael2005_intr_handler(struct cphy *phy)
  392. {
  393. unsigned int stat;
  394. int ret, edc_needed, cause = 0;
  395. ret = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_STAT, &stat);
  396. if (ret)
  397. return ret;
  398. if (stat & AEL2005_MODDET_IRQ) {
  399. ret = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2005_GPIO_CTRL,
  400. 0xd00);
  401. if (ret)
  402. return ret;
  403. /* modules have max 300 ms init time after hot plug */
  404. ret = ael2005_get_module_type(phy, 300);
  405. if (ret < 0)
  406. return ret;
  407. phy->modtype = ret;
  408. if (ret == phy_modtype_none)
  409. edc_needed = phy->priv; /* on unplug retain EDC */
  410. else if (ret == phy_modtype_twinax ||
  411. ret == phy_modtype_twinax_long)
  412. edc_needed = edc_twinax;
  413. else
  414. edc_needed = edc_sr;
  415. if (edc_needed != phy->priv) {
  416. ret = ael2005_reset(phy, 0);
  417. return ret ? ret : cphy_cause_module_change;
  418. }
  419. cause = cphy_cause_module_change;
  420. }
  421. ret = t3_phy_lasi_intr_handler(phy);
  422. if (ret < 0)
  423. return ret;
  424. ret |= cause;
  425. return ret ? ret : cphy_cause_link_change;
  426. }
  427. static const struct cphy_ops ael2005_ops = {
  428. .reset = ael2005_reset,
  429. .intr_enable = ael2005_intr_enable,
  430. .intr_disable = ael2005_intr_disable,
  431. .intr_clear = ael2005_intr_clear,
  432. .intr_handler = ael2005_intr_handler,
  433. .get_link_status = get_link_status_r,
  434. .power_down = ael1002_power_down,
  435. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  436. };
  437. int t3_ael2005_phy_prep(struct cphy *phy, struct adapter *adapter,
  438. int phy_addr, const struct mdio_ops *mdio_ops)
  439. {
  440. cphy_init(phy, adapter, phy_addr, &ael2005_ops, mdio_ops,
  441. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE |
  442. SUPPORTED_IRQ, "10GBASE-R");
  443. msleep(125);
  444. return t3_mdio_change_bits(phy, MDIO_MMD_PMAPMD, AEL_OPT_SETTINGS, 0,
  445. 1 << 5);
  446. }
  447. /*
  448. * Setup EDC and other parameters for operation with an optical module.
  449. */
  450. static int ael2020_setup_sr_edc(struct cphy *phy)
  451. {
  452. static const struct reg_val regs[] = {
  453. /* set CDR offset to 10 */
  454. { MDIO_MMD_PMAPMD, 0xcc01, 0xffff, 0x488a },
  455. /* adjust 10G RX bias current */
  456. { MDIO_MMD_PMAPMD, 0xcb1b, 0xffff, 0x0200 },
  457. { MDIO_MMD_PMAPMD, 0xcb1c, 0xffff, 0x00f0 },
  458. { MDIO_MMD_PMAPMD, 0xcc06, 0xffff, 0x00e0 },
  459. /* end */
  460. { 0, 0, 0, 0 }
  461. };
  462. int err;
  463. err = set_phy_regs(phy, regs);
  464. msleep(50);
  465. if (err)
  466. return err;
  467. phy->priv = edc_sr;
  468. return 0;
  469. }
  470. /*
  471. * Setup EDC and other parameters for operation with an TWINAX module.
  472. */
  473. static int ael2020_setup_twinax_edc(struct cphy *phy, int modtype)
  474. {
  475. /* set uC to 40MHz */
  476. static const struct reg_val uCclock40MHz[] = {
  477. { MDIO_MMD_PMAPMD, 0xff28, 0xffff, 0x4001 },
  478. { MDIO_MMD_PMAPMD, 0xff2a, 0xffff, 0x0002 },
  479. { 0, 0, 0, 0 }
  480. };
  481. /* activate uC clock */
  482. static const struct reg_val uCclockActivate[] = {
  483. { MDIO_MMD_PMAPMD, 0xd000, 0xffff, 0x5200 },
  484. { 0, 0, 0, 0 }
  485. };
  486. /* set PC to start of SRAM and activate uC */
  487. static const struct reg_val uCactivate[] = {
  488. { MDIO_MMD_PMAPMD, 0xd080, 0xffff, 0x0100 },
  489. { MDIO_MMD_PMAPMD, 0xd092, 0xffff, 0x0000 },
  490. { 0, 0, 0, 0 }
  491. };
  492. int i, err;
  493. /* set uC clock and activate it */
  494. err = set_phy_regs(phy, uCclock40MHz);
  495. msleep(500);
  496. if (err)
  497. return err;
  498. err = set_phy_regs(phy, uCclockActivate);
  499. msleep(500);
  500. if (err)
  501. return err;
  502. if (phy->priv != edc_twinax)
  503. err = t3_get_edc_fw(phy, EDC_TWX_AEL2020,
  504. EDC_TWX_AEL2020_SIZE);
  505. if (err)
  506. return err;
  507. for (i = 0; i < EDC_TWX_AEL2020_SIZE / sizeof(u16) && !err; i += 2)
  508. err = t3_mdio_write(phy, MDIO_MMD_PMAPMD,
  509. phy->phy_cache[i],
  510. phy->phy_cache[i + 1]);
  511. /* activate uC */
  512. err = set_phy_regs(phy, uCactivate);
  513. if (!err)
  514. phy->priv = edc_twinax;
  515. return err;
  516. }
  517. /*
  518. * Return Module Type.
  519. */
  520. static int ael2020_get_module_type(struct cphy *phy, int delay_ms)
  521. {
  522. int v;
  523. unsigned int stat;
  524. v = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_STAT, &stat);
  525. if (v)
  526. return v;
  527. if (stat & (0x1 << (AEL2020_GPIO_MODDET*4))) {
  528. /* module absent */
  529. return phy_modtype_none;
  530. }
  531. return ael2xxx_get_module_type(phy, delay_ms);
  532. }
  533. /*
  534. * Enable PHY interrupts. We enable "Module Detection" interrupts (on any
  535. * state transition) and then generic Link Alarm Status Interrupt (LASI).
  536. */
  537. static int ael2020_intr_enable(struct cphy *phy)
  538. {
  539. static const struct reg_val regs[] = {
  540. /* output Module's Loss Of Signal (LOS) to LED */
  541. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CFG+AEL2020_GPIO_LSTAT,
  542. 0xffff, 0x4 },
  543. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  544. 0xffff, 0x8 << (AEL2020_GPIO_LSTAT*4) },
  545. /* enable module detect status change interrupts */
  546. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  547. 0xffff, 0x2 << (AEL2020_GPIO_MODDET*4) },
  548. /* end */
  549. { 0, 0, 0, 0 }
  550. };
  551. int err, link_ok = 0;
  552. /* set up "link status" LED and enable module change interrupts */
  553. err = set_phy_regs(phy, regs);
  554. if (err)
  555. return err;
  556. err = get_link_status_r(phy, &link_ok, NULL, NULL, NULL);
  557. if (err)
  558. return err;
  559. if (link_ok)
  560. t3_link_changed(phy->adapter,
  561. phy2portid(phy));
  562. err = t3_phy_lasi_intr_enable(phy);
  563. if (err)
  564. return err;
  565. return 0;
  566. }
  567. /*
  568. * Disable PHY interrupts. The mirror of the above ...
  569. */
  570. static int ael2020_intr_disable(struct cphy *phy)
  571. {
  572. static const struct reg_val regs[] = {
  573. /* reset "link status" LED to "off" */
  574. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  575. 0xffff, 0xb << (AEL2020_GPIO_LSTAT*4) },
  576. /* disable module detect status change interrupts */
  577. { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
  578. 0xffff, 0x1 << (AEL2020_GPIO_MODDET*4) },
  579. /* end */
  580. { 0, 0, 0, 0 }
  581. };
  582. int err;
  583. /* turn off "link status" LED and disable module change interrupts */
  584. err = set_phy_regs(phy, regs);
  585. if (err)
  586. return err;
  587. return t3_phy_lasi_intr_disable(phy);
  588. }
  589. /*
  590. * Clear PHY interrupt state.
  591. */
  592. static int ael2020_intr_clear(struct cphy *phy)
  593. {
  594. /*
  595. * The GPIO Interrupt register on the AEL2020 is a "Latching High"
  596. * (LH) register which is cleared to the current state when it's read.
  597. * Thus, we simply read the register and discard the result.
  598. */
  599. unsigned int stat;
  600. int err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_INTR, &stat);
  601. return err ? err : t3_phy_lasi_intr_clear(phy);
  602. }
  603. static const struct reg_val ael2020_reset_regs[] = {
  604. /* Erratum #2: CDRLOL asserted, causing PMA link down status */
  605. { MDIO_MMD_PMAPMD, 0xc003, 0xffff, 0x3101 },
  606. /* force XAUI to send LF when RX_LOS is asserted */
  607. { MDIO_MMD_PMAPMD, 0xcd40, 0xffff, 0x0001 },
  608. /* allow writes to transceiver module EEPROM on i2c bus */
  609. { MDIO_MMD_PMAPMD, 0xff02, 0xffff, 0x0023 },
  610. { MDIO_MMD_PMAPMD, 0xff03, 0xffff, 0x0000 },
  611. { MDIO_MMD_PMAPMD, 0xff04, 0xffff, 0x0000 },
  612. /* end */
  613. { 0, 0, 0, 0 }
  614. };
  615. /*
  616. * Reset the PHY and put it into a canonical operating state.
  617. */
  618. static int ael2020_reset(struct cphy *phy, int wait)
  619. {
  620. int err;
  621. unsigned int lasi_ctrl;
  622. /* grab current interrupt state */
  623. err = t3_mdio_read(phy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL,
  624. &lasi_ctrl);
  625. if (err)
  626. return err;
  627. err = t3_phy_reset(phy, MDIO_MMD_PMAPMD, 125);
  628. if (err)
  629. return err;
  630. msleep(100);
  631. /* basic initialization for all module types */
  632. phy->priv = edc_none;
  633. err = set_phy_regs(phy, ael2020_reset_regs);
  634. if (err)
  635. return err;
  636. /* determine module type and perform appropriate initialization */
  637. err = ael2020_get_module_type(phy, 0);
  638. if (err < 0)
  639. return err;
  640. phy->modtype = (u8)err;
  641. if (err == phy_modtype_twinax || err == phy_modtype_twinax_long)
  642. err = ael2020_setup_twinax_edc(phy, err);
  643. else
  644. err = ael2020_setup_sr_edc(phy);
  645. if (err)
  646. return err;
  647. /* reset wipes out interrupts, reenable them if they were on */
  648. if (lasi_ctrl & 1)
  649. err = ael2005_intr_enable(phy);
  650. return err;
  651. }
  652. /*
  653. * Handle a PHY interrupt.
  654. */
  655. static int ael2020_intr_handler(struct cphy *phy)
  656. {
  657. unsigned int stat;
  658. int ret, edc_needed, cause = 0;
  659. ret = t3_mdio_read(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_INTR, &stat);
  660. if (ret)
  661. return ret;
  662. if (stat & (0x1 << AEL2020_GPIO_MODDET)) {
  663. /* modules have max 300 ms init time after hot plug */
  664. ret = ael2020_get_module_type(phy, 300);
  665. if (ret < 0)
  666. return ret;
  667. phy->modtype = (u8)ret;
  668. if (ret == phy_modtype_none)
  669. edc_needed = phy->priv; /* on unplug retain EDC */
  670. else if (ret == phy_modtype_twinax ||
  671. ret == phy_modtype_twinax_long)
  672. edc_needed = edc_twinax;
  673. else
  674. edc_needed = edc_sr;
  675. if (edc_needed != phy->priv) {
  676. ret = ael2020_reset(phy, 0);
  677. return ret ? ret : cphy_cause_module_change;
  678. }
  679. cause = cphy_cause_module_change;
  680. }
  681. ret = t3_phy_lasi_intr_handler(phy);
  682. if (ret < 0)
  683. return ret;
  684. ret |= cause;
  685. return ret ? ret : cphy_cause_link_change;
  686. }
  687. static const struct cphy_ops ael2020_ops = {
  688. .reset = ael2020_reset,
  689. .intr_enable = ael2020_intr_enable,
  690. .intr_disable = ael2020_intr_disable,
  691. .intr_clear = ael2020_intr_clear,
  692. .intr_handler = ael2020_intr_handler,
  693. .get_link_status = get_link_status_r,
  694. .power_down = ael1002_power_down,
  695. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  696. };
  697. int t3_ael2020_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
  698. const struct mdio_ops *mdio_ops)
  699. {
  700. int err;
  701. cphy_init(phy, adapter, phy_addr, &ael2020_ops, mdio_ops,
  702. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE |
  703. SUPPORTED_IRQ, "10GBASE-R");
  704. msleep(125);
  705. err = set_phy_regs(phy, ael2020_reset_regs);
  706. if (err)
  707. return err;
  708. return 0;
  709. }
  710. /*
  711. * Get link status for a 10GBASE-X device.
  712. */
  713. static int get_link_status_x(struct cphy *phy, int *link_ok, int *speed,
  714. int *duplex, int *fc)
  715. {
  716. if (link_ok) {
  717. unsigned int stat0, stat1, stat2;
  718. int err = t3_mdio_read(phy, MDIO_MMD_PMAPMD,
  719. MDIO_PMA_RXDET, &stat0);
  720. if (!err)
  721. err = t3_mdio_read(phy, MDIO_MMD_PCS,
  722. MDIO_PCS_10GBX_STAT1, &stat1);
  723. if (!err)
  724. err = t3_mdio_read(phy, MDIO_MMD_PHYXS,
  725. MDIO_PHYXS_LNSTAT, &stat2);
  726. if (err)
  727. return err;
  728. *link_ok = (stat0 & (stat1 >> 12) & (stat2 >> 12)) & 1;
  729. }
  730. if (speed)
  731. *speed = SPEED_10000;
  732. if (duplex)
  733. *duplex = DUPLEX_FULL;
  734. return 0;
  735. }
  736. static const struct cphy_ops qt2045_ops = {
  737. .reset = ael1006_reset,
  738. .intr_enable = t3_phy_lasi_intr_enable,
  739. .intr_disable = t3_phy_lasi_intr_disable,
  740. .intr_clear = t3_phy_lasi_intr_clear,
  741. .intr_handler = t3_phy_lasi_intr_handler,
  742. .get_link_status = get_link_status_x,
  743. .power_down = ael1002_power_down,
  744. .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
  745. };
  746. int t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter,
  747. int phy_addr, const struct mdio_ops *mdio_ops)
  748. {
  749. unsigned int stat;
  750. cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops,
  751. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
  752. "10GBASE-CX4");
  753. /*
  754. * Some cards where the PHY is supposed to be at address 0 actually
  755. * have it at 1.
  756. */
  757. if (!phy_addr &&
  758. !t3_mdio_read(phy, MDIO_MMD_PMAPMD, MDIO_STAT1, &stat) &&
  759. stat == 0xffff)
  760. phy->mdio.prtad = 1;
  761. return 0;
  762. }
  763. static int xaui_direct_reset(struct cphy *phy, int wait)
  764. {
  765. return 0;
  766. }
  767. static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
  768. int *speed, int *duplex, int *fc)
  769. {
  770. if (link_ok) {
  771. unsigned int status;
  772. int prtad = phy->mdio.prtad;
  773. status = t3_read_reg(phy->adapter,
  774. XGM_REG(A_XGM_SERDES_STAT0, prtad)) |
  775. t3_read_reg(phy->adapter,
  776. XGM_REG(A_XGM_SERDES_STAT1, prtad)) |
  777. t3_read_reg(phy->adapter,
  778. XGM_REG(A_XGM_SERDES_STAT2, prtad)) |
  779. t3_read_reg(phy->adapter,
  780. XGM_REG(A_XGM_SERDES_STAT3, prtad));
  781. *link_ok = !(status & F_LOWSIG0);
  782. }
  783. if (speed)
  784. *speed = SPEED_10000;
  785. if (duplex)
  786. *duplex = DUPLEX_FULL;
  787. return 0;
  788. }
  789. static int xaui_direct_power_down(struct cphy *phy, int enable)
  790. {
  791. return 0;
  792. }
  793. static const struct cphy_ops xaui_direct_ops = {
  794. .reset = xaui_direct_reset,
  795. .intr_enable = ael1002_intr_noop,
  796. .intr_disable = ael1002_intr_noop,
  797. .intr_clear = ael1002_intr_noop,
  798. .intr_handler = ael1002_intr_noop,
  799. .get_link_status = xaui_direct_get_link_status,
  800. .power_down = xaui_direct_power_down,
  801. };
  802. int t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
  803. int phy_addr, const struct mdio_ops *mdio_ops)
  804. {
  805. cphy_init(phy, adapter, phy_addr, &xaui_direct_ops, mdio_ops,
  806. SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
  807. "10GBASE-CX4");
  808. return 0;
  809. }