ethernet-sgmii.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/kernel.h>
  28. #include <linux/netdevice.h>
  29. #include <net/dst.h>
  30. #include <asm/octeon/octeon.h>
  31. #include "ethernet-defines.h"
  32. #include "octeon-ethernet.h"
  33. #include "ethernet-util.h"
  34. #include "cvmx-helper.h"
  35. #include "cvmx-gmxx-defs.h"
  36. int cvm_oct_sgmii_open(struct net_device *dev)
  37. {
  38. union cvmx_gmxx_prtx_cfg gmx_cfg;
  39. struct octeon_ethernet *priv = netdev_priv(dev);
  40. int interface = INTERFACE(priv->port);
  41. int index = INDEX(priv->port);
  42. cvmx_helper_link_info_t link_info;
  43. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  44. gmx_cfg.s.en = 1;
  45. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  46. if (!octeon_is_simulation()) {
  47. link_info = cvmx_helper_link_get(priv->port);
  48. if (!link_info.s.link_up)
  49. netif_carrier_off(dev);
  50. }
  51. return 0;
  52. }
  53. int cvm_oct_sgmii_stop(struct net_device *dev)
  54. {
  55. union cvmx_gmxx_prtx_cfg gmx_cfg;
  56. struct octeon_ethernet *priv = netdev_priv(dev);
  57. int interface = INTERFACE(priv->port);
  58. int index = INDEX(priv->port);
  59. gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  60. gmx_cfg.s.en = 0;
  61. cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
  62. return 0;
  63. }
  64. static void cvm_oct_sgmii_poll(struct net_device *dev)
  65. {
  66. struct octeon_ethernet *priv = netdev_priv(dev);
  67. cvmx_helper_link_info_t link_info;
  68. link_info = cvmx_helper_link_get(priv->port);
  69. if (link_info.u64 == priv->link_info)
  70. return;
  71. link_info = cvmx_helper_link_autoconf(priv->port);
  72. priv->link_info = link_info.u64;
  73. /* Tell Linux */
  74. if (link_info.s.link_up) {
  75. if (!netif_carrier_ok(dev))
  76. netif_carrier_on(dev);
  77. if (priv->queue != -1)
  78. DEBUGPRINT
  79. ("%s: %u Mbps %s duplex, port %2d, queue %2d\n",
  80. dev->name, link_info.s.speed,
  81. (link_info.s.full_duplex) ? "Full" : "Half",
  82. priv->port, priv->queue);
  83. else
  84. DEBUGPRINT("%s: %u Mbps %s duplex, port %2d, POW\n",
  85. dev->name, link_info.s.speed,
  86. (link_info.s.full_duplex) ? "Full" : "Half",
  87. priv->port);
  88. } else {
  89. if (netif_carrier_ok(dev))
  90. netif_carrier_off(dev);
  91. DEBUGPRINT("%s: Link down\n", dev->name);
  92. }
  93. }
  94. int cvm_oct_sgmii_init(struct net_device *dev)
  95. {
  96. struct octeon_ethernet *priv = netdev_priv(dev);
  97. cvm_oct_common_init(dev);
  98. dev->netdev_ops->ndo_stop(dev);
  99. if (!octeon_is_simulation() && priv->phydev == NULL)
  100. priv->poll = cvm_oct_sgmii_poll;
  101. /* FIXME: Need autoneg logic */
  102. return 0;
  103. }
  104. void cvm_oct_sgmii_uninit(struct net_device *dev)
  105. {
  106. cvm_oct_common_uninit(dev);
  107. }