xfp_phy.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. enum efx_phy_mode phy_mode;
  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. if (!phy_data)
  73. return -ENOMEM;
  74. efx->phy_data = phy_data;
  75. EFX_INFO(efx, "XFP: PHY ID reg %x (OUI %x model %x revision"
  76. " %x)\n", devid, MDIO_ID_OUI(devid), MDIO_ID_MODEL(devid),
  77. MDIO_ID_REV(devid));
  78. phy_data->phy_mode = efx->phy_mode;
  79. rc = xfp_reset_phy(efx);
  80. EFX_INFO(efx, "XFP: PHY init %s.\n",
  81. rc ? "failed" : "successful");
  82. if (rc < 0)
  83. goto fail;
  84. return 0;
  85. fail:
  86. kfree(efx->phy_data);
  87. efx->phy_data = NULL;
  88. return rc;
  89. }
  90. static void xfp_phy_clear_interrupt(struct efx_nic *efx)
  91. {
  92. xenpack_clear_lasi_irqs(efx);
  93. }
  94. static int xfp_link_ok(struct efx_nic *efx)
  95. {
  96. return mdio_clause45_links_ok(efx, XFP_REQUIRED_DEVS);
  97. }
  98. static int xfp_phy_check_hw(struct efx_nic *efx)
  99. {
  100. int rc = 0;
  101. int link_up = xfp_link_ok(efx);
  102. /* Simulate a PHY event if link state has changed */
  103. if (link_up != efx->link_up)
  104. falcon_xmac_sim_phy_event(efx);
  105. return rc;
  106. }
  107. static void xfp_phy_reconfigure(struct efx_nic *efx)
  108. {
  109. struct xfp_phy_data *phy_data = efx->phy_data;
  110. /* Reset the PHY when moving from tx off to tx on */
  111. if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) &&
  112. (phy_data->phy_mode & PHY_MODE_TX_DISABLED))
  113. xfp_reset_phy(efx);
  114. mdio_clause45_transmit_disable(efx);
  115. mdio_clause45_phy_reconfigure(efx);
  116. phy_data->phy_mode = efx->phy_mode;
  117. efx->link_up = xfp_link_ok(efx);
  118. efx->link_options = GM_LPA_10000FULL;
  119. }
  120. static void xfp_phy_fini(struct efx_nic *efx)
  121. {
  122. /* Clobber the LED if it was blinking */
  123. efx->board_info.blink(efx, false);
  124. /* Free the context block */
  125. kfree(efx->phy_data);
  126. efx->phy_data = NULL;
  127. }
  128. struct efx_phy_operations falcon_xfp_phy_ops = {
  129. .init = xfp_phy_init,
  130. .reconfigure = xfp_phy_reconfigure,
  131. .check_hw = xfp_phy_check_hw,
  132. .fini = xfp_phy_fini,
  133. .clear_interrupt = xfp_phy_clear_interrupt,
  134. .mmds = XFP_REQUIRED_DEVS,
  135. .loopbacks = XFP_LOOPBACKS,
  136. };