mv88x201x.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*****************************************************************************
  2. * *
  3. * File: mv88x201x.c *
  4. * $Revision: 1.12 $ *
  5. * $Date: 2005/04/15 19:27:14 $ *
  6. * Description: *
  7. * Marvell PHY (mv88x201x) functionality. *
  8. * part of the Chelsio 10Gb Ethernet Driver. *
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License, version 2, as *
  12. * published by the Free Software Foundation. *
  13. * *
  14. * You should have received a copy of the GNU General Public License along *
  15. * with this program; if not, see <http://www.gnu.org/licenses/>. *
  16. * *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * http://www.chelsio.com *
  22. * *
  23. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  24. * All rights reserved. *
  25. * *
  26. * Maintainers: maintainers@chelsio.com *
  27. * *
  28. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  29. * Tina Yang <tainay@chelsio.com> *
  30. * Felix Marti <felix@chelsio.com> *
  31. * Scott Bardone <sbardone@chelsio.com> *
  32. * Kurt Ottaway <kottaway@chelsio.com> *
  33. * Frank DiMambro <frank@chelsio.com> *
  34. * *
  35. * History: *
  36. * *
  37. ****************************************************************************/
  38. #include "cphy.h"
  39. #include "elmer0.h"
  40. /*
  41. * The 88x2010 Rev C. requires some link status registers * to be read
  42. * twice in order to get the right values. Future * revisions will fix
  43. * this problem and then this macro * can disappear.
  44. */
  45. #define MV88x2010_LINK_STATUS_BUGS 1
  46. static int led_init(struct cphy *cphy)
  47. {
  48. /* Setup the LED registers so we can turn on/off.
  49. * Writing these bits maps control to another
  50. * register. mmd(0x1) addr(0x7)
  51. */
  52. cphy_mdio_write(cphy, MDIO_MMD_PCS, 0x8304, 0xdddd);
  53. return 0;
  54. }
  55. static int led_link(struct cphy *cphy, u32 do_enable)
  56. {
  57. u32 led = 0;
  58. #define LINK_ENABLE_BIT 0x1
  59. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_CTRL2, &led);
  60. if (do_enable & LINK_ENABLE_BIT) {
  61. led |= LINK_ENABLE_BIT;
  62. cphy_mdio_write(cphy, MDIO_MMD_PMAPMD, MDIO_CTRL2, led);
  63. } else {
  64. led &= ~LINK_ENABLE_BIT;
  65. cphy_mdio_write(cphy, MDIO_MMD_PMAPMD, MDIO_CTRL2, led);
  66. }
  67. return 0;
  68. }
  69. /* Port Reset */
  70. static int mv88x201x_reset(struct cphy *cphy, int wait)
  71. {
  72. /* This can be done through registers. It is not required since
  73. * a full chip reset is used.
  74. */
  75. return 0;
  76. }
  77. static int mv88x201x_interrupt_enable(struct cphy *cphy)
  78. {
  79. /* Enable PHY LASI interrupts. */
  80. cphy_mdio_write(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL,
  81. MDIO_PMA_LASI_LSALARM);
  82. /* Enable Marvell interrupts through Elmer0. */
  83. if (t1_is_asic(cphy->adapter)) {
  84. u32 elmer;
  85. t1_tpi_read(cphy->adapter, A_ELMER0_INT_ENABLE, &elmer);
  86. elmer |= ELMER0_GP_BIT6;
  87. t1_tpi_write(cphy->adapter, A_ELMER0_INT_ENABLE, elmer);
  88. }
  89. return 0;
  90. }
  91. static int mv88x201x_interrupt_disable(struct cphy *cphy)
  92. {
  93. /* Disable PHY LASI interrupts. */
  94. cphy_mdio_write(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL, 0x0);
  95. /* Disable Marvell interrupts through Elmer0. */
  96. if (t1_is_asic(cphy->adapter)) {
  97. u32 elmer;
  98. t1_tpi_read(cphy->adapter, A_ELMER0_INT_ENABLE, &elmer);
  99. elmer &= ~ELMER0_GP_BIT6;
  100. t1_tpi_write(cphy->adapter, A_ELMER0_INT_ENABLE, elmer);
  101. }
  102. return 0;
  103. }
  104. static int mv88x201x_interrupt_clear(struct cphy *cphy)
  105. {
  106. u32 elmer;
  107. u32 val;
  108. #ifdef MV88x2010_LINK_STATUS_BUGS
  109. /* Required to read twice before clear takes affect. */
  110. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_RXSTAT, &val);
  111. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_TXSTAT, &val);
  112. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_STAT, &val);
  113. /* Read this register after the others above it else
  114. * the register doesn't clear correctly.
  115. */
  116. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_STAT1, &val);
  117. #endif
  118. /* Clear link status. */
  119. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_STAT1, &val);
  120. /* Clear PHY LASI interrupts. */
  121. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_STAT, &val);
  122. #ifdef MV88x2010_LINK_STATUS_BUGS
  123. /* Do it again. */
  124. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_RXSTAT, &val);
  125. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_TXSTAT, &val);
  126. #endif
  127. /* Clear Marvell interrupts through Elmer0. */
  128. if (t1_is_asic(cphy->adapter)) {
  129. t1_tpi_read(cphy->adapter, A_ELMER0_INT_CAUSE, &elmer);
  130. elmer |= ELMER0_GP_BIT6;
  131. t1_tpi_write(cphy->adapter, A_ELMER0_INT_CAUSE, elmer);
  132. }
  133. return 0;
  134. }
  135. static int mv88x201x_interrupt_handler(struct cphy *cphy)
  136. {
  137. /* Clear interrupts */
  138. mv88x201x_interrupt_clear(cphy);
  139. /* We have only enabled link change interrupts and so
  140. * cphy_cause must be a link change interrupt.
  141. */
  142. return cphy_cause_link_change;
  143. }
  144. static int mv88x201x_set_loopback(struct cphy *cphy, int on)
  145. {
  146. return 0;
  147. }
  148. static int mv88x201x_get_link_status(struct cphy *cphy, int *link_ok,
  149. int *speed, int *duplex, int *fc)
  150. {
  151. u32 val = 0;
  152. if (link_ok) {
  153. /* Read link status. */
  154. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_STAT1, &val);
  155. val &= MDIO_STAT1_LSTATUS;
  156. *link_ok = (val == MDIO_STAT1_LSTATUS);
  157. /* Turn on/off Link LED */
  158. led_link(cphy, *link_ok);
  159. }
  160. if (speed)
  161. *speed = SPEED_10000;
  162. if (duplex)
  163. *duplex = DUPLEX_FULL;
  164. if (fc)
  165. *fc = PAUSE_RX | PAUSE_TX;
  166. return 0;
  167. }
  168. static void mv88x201x_destroy(struct cphy *cphy)
  169. {
  170. kfree(cphy);
  171. }
  172. static struct cphy_ops mv88x201x_ops = {
  173. .destroy = mv88x201x_destroy,
  174. .reset = mv88x201x_reset,
  175. .interrupt_enable = mv88x201x_interrupt_enable,
  176. .interrupt_disable = mv88x201x_interrupt_disable,
  177. .interrupt_clear = mv88x201x_interrupt_clear,
  178. .interrupt_handler = mv88x201x_interrupt_handler,
  179. .get_link_status = mv88x201x_get_link_status,
  180. .set_loopback = mv88x201x_set_loopback,
  181. .mmds = (MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS |
  182. MDIO_DEVS_PHYXS | MDIO_DEVS_WIS),
  183. };
  184. static struct cphy *mv88x201x_phy_create(struct net_device *dev, int phy_addr,
  185. const struct mdio_ops *mdio_ops)
  186. {
  187. u32 val;
  188. struct cphy *cphy = kzalloc(sizeof(*cphy), GFP_KERNEL);
  189. if (!cphy)
  190. return NULL;
  191. cphy_init(cphy, dev, phy_addr, &mv88x201x_ops, mdio_ops);
  192. /* Commands the PHY to enable XFP's clock. */
  193. cphy_mdio_read(cphy, MDIO_MMD_PCS, 0x8300, &val);
  194. cphy_mdio_write(cphy, MDIO_MMD_PCS, 0x8300, val | 1);
  195. /* Clear link status. Required because of a bug in the PHY. */
  196. cphy_mdio_read(cphy, MDIO_MMD_PMAPMD, MDIO_STAT2, &val);
  197. cphy_mdio_read(cphy, MDIO_MMD_PCS, MDIO_STAT2, &val);
  198. /* Allows for Link,Ack LED turn on/off */
  199. led_init(cphy);
  200. return cphy;
  201. }
  202. /* Chip Reset */
  203. static int mv88x201x_phy_reset(adapter_t *adapter)
  204. {
  205. u32 val;
  206. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  207. val &= ~4;
  208. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  209. msleep(100);
  210. t1_tpi_write(adapter, A_ELMER0_GPO, val | 4);
  211. msleep(1000);
  212. /* Now lets enable the Laser. Delay 100us */
  213. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  214. val |= 0x8000;
  215. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  216. udelay(100);
  217. return 0;
  218. }
  219. const struct gphy t1_mv88x201x_ops = {
  220. .create = mv88x201x_phy_create,
  221. .reset = mv88x201x_phy_reset
  222. };