mv88x201x.c 8.6 KB

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