ethernet-sgmii.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**********************************************************************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2007 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. **********************************************************************/
  27. #include <linux/phy.h>
  28. #include <linux/kernel.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/ratelimit.h>
  31. #include <net/dst.h>
  32. #include <asm/octeon/octeon.h>
  33. #include "ethernet-defines.h"
  34. #include "octeon-ethernet.h"
  35. #include "ethernet-util.h"
  36. #include "ethernet-mdio.h"
  37. #include <asm/octeon/cvmx-helper.h>
  38. #include <asm/octeon/cvmx-gmxx-defs.h>
  39. static void cvm_oct_sgmii_poll(struct net_device *dev)
  40. {
  41. struct octeon_ethernet *priv = netdev_priv(dev);
  42. cvmx_helper_link_info_t link_info;
  43. link_info = cvmx_helper_link_get(priv->port);
  44. if (link_info.u64 == priv->link_info)
  45. return;
  46. link_info = cvmx_helper_link_autoconf(priv->port);
  47. priv->link_info = link_info.u64;
  48. /* Tell Linux */
  49. if (link_info.s.link_up) {
  50. if (!netif_carrier_ok(dev))
  51. netif_carrier_on(dev);
  52. if (priv->queue != -1)
  53. printk_ratelimited
  54. ("%s: %u Mbps %s duplex, port %2d, queue %2d\n",
  55. dev->name, link_info.s.speed,
  56. (link_info.s.full_duplex) ? "Full" : "Half",
  57. priv->port, priv->queue);
  58. else
  59. printk_ratelimited
  60. ("%s: %u Mbps %s duplex, port %2d, POW\n",
  61. dev->name, link_info.s.speed,
  62. (link_info.s.full_duplex) ? "Full" : "Half",
  63. priv->port);
  64. } else {
  65. if (netif_carrier_ok(dev))
  66. netif_carrier_off(dev);
  67. printk_ratelimited("%s: Link down\n", dev->name);
  68. }
  69. }
  70. int cvm_oct_sgmii_open(struct net_device *dev)
  71. {
  72. union cvmx_gmxx_prtx_cfg gmx_cfg;
  73. struct octeon_ethernet *priv = netdev_priv(dev);
  74. int interface = INTERFACE(priv->port);
  75. int index = INDEX(priv->port);
  76. cvmx_helper_link_info_t link_info;
  77. int rv;
  78. rv = cvm_oct_phy_setup_device(dev);
  79. if (rv)
  80. return rv;
  81. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  82. gmx_cfg.s.en = 1;
  83. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  84. if (octeon_is_simulation())
  85. return 0;
  86. if (priv->phydev) {
  87. int r = phy_read_status(priv->phydev);
  88. if (r == 0 && priv->phydev->link == 0)
  89. netif_carrier_off(dev);
  90. cvm_oct_adjust_link(dev);
  91. } else {
  92. link_info = cvmx_helper_link_get(priv->port);
  93. if (!link_info.s.link_up)
  94. netif_carrier_off(dev);
  95. priv->poll = cvm_oct_sgmii_poll;
  96. cvm_oct_sgmii_poll(dev);
  97. }
  98. return 0;
  99. }
  100. int cvm_oct_sgmii_stop(struct net_device *dev)
  101. {
  102. union cvmx_gmxx_prtx_cfg gmx_cfg;
  103. struct octeon_ethernet *priv = netdev_priv(dev);
  104. int interface = INTERFACE(priv->port);
  105. int index = INDEX(priv->port);
  106. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  107. gmx_cfg.s.en = 0;
  108. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  109. return cvm_oct_common_stop(dev);
  110. }
  111. int cvm_oct_sgmii_init(struct net_device *dev)
  112. {
  113. cvm_oct_common_init(dev);
  114. dev->netdev_ops->ndo_stop(dev);
  115. /* FIXME: Need autoneg logic */
  116. return 0;
  117. }
  118. void cvm_oct_sgmii_uninit(struct net_device *dev)
  119. {
  120. cvm_oct_common_uninit(dev);
  121. }