xfp_phy.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2006-2008 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. /*
  10. * Driver for XFP optical PHYs (plus some support specific to the Quake 2032)
  11. * See www.amcc.com for details (search for qt2032)
  12. */
  13. #include <linux/timer.h>
  14. #include <linux/delay.h>
  15. #include "efx.h"
  16. #include "gmii.h"
  17. #include "mdio_10g.h"
  18. #include "xenpack.h"
  19. #include "phy.h"
  20. #include "mac.h"
  21. #define XFP_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_PCS | \
  22. MDIO_MMDREG_DEVS0_PMAPMD | \
  23. MDIO_MMDREG_DEVS0_PHYXS)
  24. #define XFP_LOOPBACKS ((1 << LOOPBACK_PCS) | \
  25. (1 << LOOPBACK_PMAPMD) | \
  26. (1 << LOOPBACK_NETWORK))
  27. /****************************************************************************/
  28. /* Quake-specific MDIO registers */
  29. #define MDIO_QUAKE_LED0_REG (0xD006)
  30. void xfp_set_led(struct efx_nic *p, int led, int mode)
  31. {
  32. int addr = MDIO_QUAKE_LED0_REG + led;
  33. mdio_clause45_write(p, p->mii.phy_id, MDIO_MMD_PMAPMD, addr,
  34. mode);
  35. }
  36. struct xfp_phy_data {
  37. int tx_disabled;
  38. };
  39. #define XFP_MAX_RESET_TIME 500
  40. #define XFP_RESET_WAIT 10
  41. /* Reset the PHYXS MMD. This is documented (for the Quake PHY) as doing
  42. * a complete soft reset.
  43. */
  44. static int xfp_reset_phy(struct efx_nic *efx)
  45. {
  46. int rc;
  47. rc = mdio_clause45_reset_mmd(efx, MDIO_MMD_PHYXS,
  48. XFP_MAX_RESET_TIME / XFP_RESET_WAIT,
  49. XFP_RESET_WAIT);
  50. if (rc < 0)
  51. goto fail;
  52. /* Wait 250ms for the PHY to complete bootup */
  53. msleep(250);
  54. /* Check that all the MMDs we expect are present and responding. We
  55. * expect faults on some if the link is down, but not on the PHY XS */
  56. rc = mdio_clause45_check_mmds(efx, XFP_REQUIRED_DEVS,
  57. MDIO_MMDREG_DEVS0_PHYXS);
  58. if (rc < 0)
  59. goto fail;
  60. efx->board_info.init_leds(efx);
  61. return rc;
  62. fail:
  63. EFX_ERR(efx, "XFP: reset timed out!\n");
  64. return rc;
  65. }
  66. static int xfp_phy_init(struct efx_nic *efx)
  67. {
  68. struct xfp_phy_data *phy_data;
  69. u32 devid = mdio_clause45_read_id(efx, MDIO_MMD_PHYXS);
  70. int rc;
  71. phy_data = kzalloc(sizeof(struct xfp_phy_data), GFP_KERNEL);
  72. efx->phy_data = (void *) phy_data;
  73. EFX_INFO(efx, "XFP: PHY ID reg %x (OUI %x model %x revision"
  74. " %x)\n", devid, MDIO_ID_OUI(devid), MDIO_ID_MODEL(devid),
  75. MDIO_ID_REV(devid));
  76. phy_data->tx_disabled = efx->tx_disabled;
  77. rc = xfp_reset_phy(efx);
  78. EFX_INFO(efx, "XFP: PHY init %s.\n",
  79. rc ? "failed" : "successful");
  80. if (rc < 0)
  81. goto fail;
  82. return 0;
  83. fail:
  84. kfree(efx->phy_data);
  85. efx->phy_data = NULL;
  86. return rc;
  87. }
  88. static void xfp_phy_clear_interrupt(struct efx_nic *efx)
  89. {
  90. xenpack_clear_lasi_irqs(efx);
  91. }
  92. static int xfp_link_ok(struct efx_nic *efx)
  93. {
  94. return mdio_clause45_links_ok(efx, XFP_REQUIRED_DEVS);
  95. }
  96. static int xfp_phy_check_hw(struct efx_nic *efx)
  97. {
  98. int rc = 0;
  99. int link_up = xfp_link_ok(efx);
  100. /* Simulate a PHY event if link state has changed */
  101. if (link_up != efx->link_up)
  102. falcon_xmac_sim_phy_event(efx);
  103. return rc;
  104. }
  105. static void xfp_phy_reconfigure(struct efx_nic *efx)
  106. {
  107. struct xfp_phy_data *phy_data = efx->phy_data;
  108. /* Reset the PHY when moving from tx off to tx on */
  109. if (phy_data->tx_disabled && !efx->tx_disabled)
  110. xfp_reset_phy(efx);
  111. mdio_clause45_transmit_disable(efx);
  112. mdio_clause45_phy_reconfigure(efx);
  113. phy_data->tx_disabled = efx->tx_disabled;
  114. efx->link_up = xfp_link_ok(efx);
  115. efx->link_options = GM_LPA_10000FULL;
  116. }
  117. static void xfp_phy_fini(struct efx_nic *efx)
  118. {
  119. /* Clobber the LED if it was blinking */
  120. efx->board_info.blink(efx, 0);
  121. /* Free the context block */
  122. kfree(efx->phy_data);
  123. efx->phy_data = NULL;
  124. }
  125. struct efx_phy_operations falcon_xfp_phy_ops = {
  126. .init = xfp_phy_init,
  127. .reconfigure = xfp_phy_reconfigure,
  128. .check_hw = xfp_phy_check_hw,
  129. .fini = xfp_phy_fini,
  130. .clear_interrupt = xfp_phy_clear_interrupt,
  131. .reset_xaui = efx_port_dummy_op_void,
  132. .mmds = XFP_REQUIRED_DEVS,
  133. .loopbacks = XFP_LOOPBACKS,
  134. };