xfp_phy.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 "mdio_10g.h"
  17. #include "xenpack.h"
  18. #include "phy.h"
  19. #include "falcon.h"
  20. #define XFP_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PCS | \
  21. MDIO_MMDREG_DEVS_PMAPMD | \
  22. MDIO_MMDREG_DEVS_PHYXS)
  23. #define XFP_LOOPBACKS ((1 << LOOPBACK_PCS) | \
  24. (1 << LOOPBACK_PMAPMD) | \
  25. (1 << LOOPBACK_NETWORK))
  26. /****************************************************************************/
  27. /* Quake-specific MDIO registers */
  28. #define MDIO_QUAKE_LED0_REG (0xD006)
  29. void xfp_set_led(struct efx_nic *p, int led, int mode)
  30. {
  31. int addr = MDIO_QUAKE_LED0_REG + led;
  32. mdio_clause45_write(p, p->mii.phy_id, MDIO_MMD_PMAPMD, addr,
  33. mode);
  34. }
  35. struct xfp_phy_data {
  36. enum efx_phy_mode phy_mode;
  37. };
  38. #define XFP_MAX_RESET_TIME 500
  39. #define XFP_RESET_WAIT 10
  40. /* Reset the PHYXS MMD. This is documented (for the Quake PHY) as doing
  41. * a complete soft reset.
  42. */
  43. static int xfp_reset_phy(struct efx_nic *efx)
  44. {
  45. int rc;
  46. rc = mdio_clause45_reset_mmd(efx, MDIO_MMD_PHYXS,
  47. XFP_MAX_RESET_TIME / XFP_RESET_WAIT,
  48. XFP_RESET_WAIT);
  49. if (rc < 0)
  50. goto fail;
  51. /* Wait 250ms for the PHY to complete bootup */
  52. msleep(250);
  53. /* Check that all the MMDs we expect are present and responding. We
  54. * expect faults on some if the link is down, but not on the PHY XS */
  55. rc = mdio_clause45_check_mmds(efx, XFP_REQUIRED_DEVS,
  56. MDIO_MMDREG_DEVS_PHYXS);
  57. if (rc < 0)
  58. goto fail;
  59. efx->board_info.init_leds(efx);
  60. return rc;
  61. fail:
  62. EFX_ERR(efx, "XFP: reset timed out!\n");
  63. return rc;
  64. }
  65. static int xfp_phy_init(struct efx_nic *efx)
  66. {
  67. struct xfp_phy_data *phy_data;
  68. u32 devid = mdio_clause45_read_id(efx, MDIO_MMD_PHYXS);
  69. int rc;
  70. phy_data = kzalloc(sizeof(struct xfp_phy_data), GFP_KERNEL);
  71. if (!phy_data)
  72. return -ENOMEM;
  73. efx->phy_data = phy_data;
  74. EFX_INFO(efx, "XFP: PHY ID reg %x (OUI %x model %x revision"
  75. " %x)\n", devid, MDIO_ID_OUI(devid), MDIO_ID_MODEL(devid),
  76. MDIO_ID_REV(devid));
  77. phy_data->phy_mode = efx->phy_mode;
  78. rc = xfp_reset_phy(efx);
  79. EFX_INFO(efx, "XFP: PHY init %s.\n",
  80. rc ? "failed" : "successful");
  81. if (rc < 0)
  82. goto fail;
  83. return 0;
  84. fail:
  85. kfree(efx->phy_data);
  86. efx->phy_data = NULL;
  87. return rc;
  88. }
  89. static void xfp_phy_clear_interrupt(struct efx_nic *efx)
  90. {
  91. xenpack_clear_lasi_irqs(efx);
  92. }
  93. static int xfp_link_ok(struct efx_nic *efx)
  94. {
  95. return mdio_clause45_links_ok(efx, XFP_REQUIRED_DEVS);
  96. }
  97. static int xfp_phy_check_hw(struct efx_nic *efx)
  98. {
  99. int rc = 0;
  100. int link_up = xfp_link_ok(efx);
  101. /* Simulate a PHY event if link state has changed */
  102. if (link_up != efx->link_up)
  103. falcon_sim_phy_event(efx);
  104. rc = efx->board_info.monitor(efx);
  105. if (rc) {
  106. struct xfp_phy_data *phy_data = efx->phy_data;
  107. EFX_ERR(efx, "XFP sensor alert; putting PHY into low power\n");
  108. efx->phy_mode |= PHY_MODE_LOW_POWER;
  109. mdio_clause45_set_mmds_lpower(efx, 1, XFP_REQUIRED_DEVS);
  110. phy_data->phy_mode |= PHY_MODE_LOW_POWER;
  111. }
  112. return rc;
  113. }
  114. static void xfp_phy_reconfigure(struct efx_nic *efx)
  115. {
  116. struct xfp_phy_data *phy_data = efx->phy_data;
  117. /* Reset the PHY when moving from tx off to tx on */
  118. if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) &&
  119. (phy_data->phy_mode & PHY_MODE_TX_DISABLED))
  120. xfp_reset_phy(efx);
  121. mdio_clause45_transmit_disable(efx);
  122. mdio_clause45_phy_reconfigure(efx);
  123. phy_data->phy_mode = efx->phy_mode;
  124. efx->link_up = xfp_link_ok(efx);
  125. efx->link_speed = 10000;
  126. efx->link_fd = true;
  127. }
  128. static void xfp_phy_fini(struct efx_nic *efx)
  129. {
  130. /* Clobber the LED if it was blinking */
  131. efx->board_info.blink(efx, false);
  132. /* Free the context block */
  133. kfree(efx->phy_data);
  134. efx->phy_data = NULL;
  135. }
  136. struct efx_phy_operations falcon_xfp_phy_ops = {
  137. .macs = EFX_XMAC,
  138. .init = xfp_phy_init,
  139. .reconfigure = xfp_phy_reconfigure,
  140. .check_hw = xfp_phy_check_hw,
  141. .fini = xfp_phy_fini,
  142. .clear_interrupt = xfp_phy_clear_interrupt,
  143. .get_settings = mdio_clause45_get_settings,
  144. .set_settings = mdio_clause45_set_settings,
  145. .mmds = XFP_REQUIRED_DEVS,
  146. .loopbacks = XFP_LOOPBACKS,
  147. };