xfp_phy.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 2022/32)
  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 void xfp_phy_poll(struct efx_nic *efx)
  98. {
  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_sim_phy_event(efx);
  103. }
  104. static void xfp_phy_reconfigure(struct efx_nic *efx)
  105. {
  106. struct xfp_phy_data *phy_data = efx->phy_data;
  107. /* Reset the PHY when moving from tx off to tx on */
  108. if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) &&
  109. (phy_data->phy_mode & PHY_MODE_TX_DISABLED))
  110. xfp_reset_phy(efx);
  111. mdio_clause45_transmit_disable(efx);
  112. mdio_clause45_phy_reconfigure(efx);
  113. phy_data->phy_mode = efx->phy_mode;
  114. efx->link_up = xfp_link_ok(efx);
  115. efx->link_speed = 10000;
  116. efx->link_fd = true;
  117. efx->link_fc = efx->wanted_fc;
  118. }
  119. static void xfp_phy_fini(struct efx_nic *efx)
  120. {
  121. /* Clobber the LED if it was blinking */
  122. efx->board_info.blink(efx, false);
  123. /* Free the context block */
  124. kfree(efx->phy_data);
  125. efx->phy_data = NULL;
  126. }
  127. struct efx_phy_operations falcon_xfp_phy_ops = {
  128. .macs = EFX_XMAC,
  129. .init = xfp_phy_init,
  130. .reconfigure = xfp_phy_reconfigure,
  131. .poll = xfp_phy_poll,
  132. .fini = xfp_phy_fini,
  133. .clear_interrupt = xfp_phy_clear_interrupt,
  134. .get_settings = mdio_clause45_get_settings,
  135. .set_settings = mdio_clause45_set_settings,
  136. .mmds = XFP_REQUIRED_DEVS,
  137. .loopbacks = XFP_LOOPBACKS,
  138. };