Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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 | |
| 14 | #include <linux/timer.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include "efx.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 17 | #include "mdio_10g.h" |
| 18 | #include "xenpack.h" |
| 19 | #include "phy.h" |
| 20 | #include "mac.h" |
| 21 | |
| 22 | #define XFP_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_PCS | \ |
| 23 | MDIO_MMDREG_DEVS0_PMAPMD | \ |
| 24 | MDIO_MMDREG_DEVS0_PHYXS) |
| 25 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 26 | #define XFP_LOOPBACKS ((1 << LOOPBACK_PCS) | \ |
| 27 | (1 << LOOPBACK_PMAPMD) | \ |
| 28 | (1 << LOOPBACK_NETWORK)) |
| 29 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | /****************************************************************************/ |
| 31 | /* Quake-specific MDIO registers */ |
| 32 | #define MDIO_QUAKE_LED0_REG (0xD006) |
| 33 | |
| 34 | void xfp_set_led(struct efx_nic *p, int led, int mode) |
| 35 | { |
| 36 | int addr = MDIO_QUAKE_LED0_REG + led; |
| 37 | mdio_clause45_write(p, p->mii.phy_id, MDIO_MMD_PMAPMD, addr, |
| 38 | mode); |
| 39 | } |
| 40 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 41 | struct xfp_phy_data { |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 42 | enum efx_phy_mode phy_mode; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 45 | #define XFP_MAX_RESET_TIME 500 |
| 46 | #define XFP_RESET_WAIT 10 |
| 47 | |
| 48 | /* Reset the PHYXS MMD. This is documented (for the Quake PHY) as doing |
| 49 | * a complete soft reset. |
| 50 | */ |
| 51 | static int xfp_reset_phy(struct efx_nic *efx) |
| 52 | { |
| 53 | int rc; |
| 54 | |
| 55 | rc = mdio_clause45_reset_mmd(efx, MDIO_MMD_PHYXS, |
| 56 | XFP_MAX_RESET_TIME / XFP_RESET_WAIT, |
| 57 | XFP_RESET_WAIT); |
| 58 | if (rc < 0) |
| 59 | goto fail; |
| 60 | |
| 61 | /* Wait 250ms for the PHY to complete bootup */ |
| 62 | msleep(250); |
| 63 | |
| 64 | /* Check that all the MMDs we expect are present and responding. We |
| 65 | * expect faults on some if the link is down, but not on the PHY XS */ |
| 66 | rc = mdio_clause45_check_mmds(efx, XFP_REQUIRED_DEVS, |
| 67 | MDIO_MMDREG_DEVS0_PHYXS); |
| 68 | if (rc < 0) |
| 69 | goto fail; |
| 70 | |
| 71 | efx->board_info.init_leds(efx); |
| 72 | |
| 73 | return rc; |
| 74 | |
| 75 | fail: |
| 76 | EFX_ERR(efx, "XFP: reset timed out!\n"); |
| 77 | return rc; |
| 78 | } |
| 79 | |
| 80 | static int xfp_phy_init(struct efx_nic *efx) |
| 81 | { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 82 | struct xfp_phy_data *phy_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 83 | u32 devid = mdio_clause45_read_id(efx, MDIO_MMD_PHYXS); |
| 84 | int rc; |
| 85 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 86 | phy_data = kzalloc(sizeof(struct xfp_phy_data), GFP_KERNEL); |
Ben Hutchings | 9b7bfc4 | 2008-05-16 21:20:20 +0100 | [diff] [blame] | 87 | if (!phy_data) |
| 88 | return -ENOMEM; |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 89 | efx->phy_data = phy_data; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 90 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 91 | EFX_INFO(efx, "XFP: PHY ID reg %x (OUI %x model %x revision" |
| 92 | " %x)\n", devid, MDIO_ID_OUI(devid), MDIO_ID_MODEL(devid), |
| 93 | MDIO_ID_REV(devid)); |
| 94 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 95 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 96 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 97 | rc = xfp_reset_phy(efx); |
| 98 | |
| 99 | EFX_INFO(efx, "XFP: PHY init %s.\n", |
| 100 | rc ? "failed" : "successful"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 101 | if (rc < 0) |
| 102 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 103 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 104 | return 0; |
| 105 | |
| 106 | fail: |
| 107 | kfree(efx->phy_data); |
| 108 | efx->phy_data = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 109 | return rc; |
| 110 | } |
| 111 | |
| 112 | static void xfp_phy_clear_interrupt(struct efx_nic *efx) |
| 113 | { |
| 114 | xenpack_clear_lasi_irqs(efx); |
| 115 | } |
| 116 | |
| 117 | static int xfp_link_ok(struct efx_nic *efx) |
| 118 | { |
| 119 | return mdio_clause45_links_ok(efx, XFP_REQUIRED_DEVS); |
| 120 | } |
| 121 | |
| 122 | static int xfp_phy_check_hw(struct efx_nic *efx) |
| 123 | { |
| 124 | int rc = 0; |
| 125 | int link_up = xfp_link_ok(efx); |
| 126 | /* Simulate a PHY event if link state has changed */ |
| 127 | if (link_up != efx->link_up) |
| 128 | falcon_xmac_sim_phy_event(efx); |
| 129 | |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 130 | rc = efx->board_info.monitor(efx); |
| 131 | if (rc) { |
| 132 | struct xfp_phy_data *phy_data = efx->phy_data; |
| 133 | EFX_ERR(efx, "XFP sensor alert; putting PHY into low power\n"); |
| 134 | efx->phy_mode |= PHY_MODE_LOW_POWER; |
| 135 | mdio_clause45_set_mmds_lpower(efx, 1, XFP_REQUIRED_DEVS); |
| 136 | phy_data->phy_mode |= PHY_MODE_LOW_POWER; |
| 137 | } |
| 138 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 139 | return rc; |
| 140 | } |
| 141 | |
| 142 | static void xfp_phy_reconfigure(struct efx_nic *efx) |
| 143 | { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 144 | struct xfp_phy_data *phy_data = efx->phy_data; |
| 145 | |
| 146 | /* Reset the PHY when moving from tx off to tx on */ |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 147 | if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) && |
| 148 | (phy_data->phy_mode & PHY_MODE_TX_DISABLED)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 149 | xfp_reset_phy(efx); |
| 150 | |
| 151 | mdio_clause45_transmit_disable(efx); |
| 152 | mdio_clause45_phy_reconfigure(efx); |
| 153 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 154 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 155 | efx->link_up = xfp_link_ok(efx); |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame^] | 156 | efx->link_speed = 10000; |
| 157 | efx->link_fd = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | static void xfp_phy_fini(struct efx_nic *efx) |
| 162 | { |
| 163 | /* Clobber the LED if it was blinking */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 164 | efx->board_info.blink(efx, false); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 165 | |
| 166 | /* Free the context block */ |
| 167 | kfree(efx->phy_data); |
| 168 | efx->phy_data = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | struct efx_phy_operations falcon_xfp_phy_ops = { |
| 172 | .init = xfp_phy_init, |
| 173 | .reconfigure = xfp_phy_reconfigure, |
| 174 | .check_hw = xfp_phy_check_hw, |
| 175 | .fini = xfp_phy_fini, |
| 176 | .clear_interrupt = xfp_phy_clear_interrupt, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 177 | .mmds = XFP_REQUIRED_DEVS, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 178 | .loopbacks = XFP_LOOPBACKS, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 179 | }; |