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 | /* |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 10 | * Driver for SFP+ and XFP optical PHYs plus some support specific to the |
| 11 | * AMCC QT20xx adapters; see www.amcc.com for details |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 18 | #include "phy.h" |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 19 | #include "falcon.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 20 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 21 | #define XFP_REQUIRED_DEVS (MDIO_DEVS_PCS | \ |
| 22 | MDIO_DEVS_PMAPMD | \ |
| 23 | MDIO_DEVS_PHYXS) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 24 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 25 | #define XFP_LOOPBACKS ((1 << LOOPBACK_PCS) | \ |
| 26 | (1 << LOOPBACK_PMAPMD) | \ |
| 27 | (1 << LOOPBACK_NETWORK)) |
| 28 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 29 | /****************************************************************************/ |
| 30 | /* Quake-specific MDIO registers */ |
| 31 | #define MDIO_QUAKE_LED0_REG (0xD006) |
| 32 | |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 33 | /* QT2025C only */ |
| 34 | #define PCS_FW_HEARTBEAT_REG 0xd7ee |
| 35 | #define PCS_FW_HEARTB_LBN 0 |
| 36 | #define PCS_FW_HEARTB_WIDTH 8 |
| 37 | #define PCS_UC8051_STATUS_REG 0xd7fd |
| 38 | #define PCS_UC_STATUS_LBN 0 |
| 39 | #define PCS_UC_STATUS_WIDTH 8 |
| 40 | #define PCS_UC_STATUS_FW_SAVE 0x20 |
| 41 | #define PMA_PMD_FTX_CTRL2_REG 0xc309 |
| 42 | #define PMA_PMD_FTX_STATIC_LBN 13 |
| 43 | #define PMA_PMD_VEND1_REG 0xc001 |
| 44 | #define PMA_PMD_VEND1_LBTXD_LBN 15 |
| 45 | #define PCS_VEND1_REG 0xc000 |
| 46 | #define PCS_VEND1_LBTXD_LBN 5 |
| 47 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 48 | void xfp_set_led(struct efx_nic *p, int led, int mode) |
| 49 | { |
| 50 | int addr = MDIO_QUAKE_LED0_REG + led; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 51 | efx_mdio_write(p, MDIO_MMD_PMAPMD, addr, mode); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 54 | struct xfp_phy_data { |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 55 | enum efx_phy_mode phy_mode; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 58 | #define XFP_MAX_RESET_TIME 500 |
| 59 | #define XFP_RESET_WAIT 10 |
| 60 | |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 61 | static int qt2025c_wait_reset(struct efx_nic *efx) |
| 62 | { |
| 63 | unsigned long timeout = jiffies + 10 * HZ; |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 64 | int reg, old_counter = 0; |
| 65 | |
| 66 | /* Wait for firmware heartbeat to start */ |
| 67 | for (;;) { |
| 68 | int counter; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 69 | reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_FW_HEARTBEAT_REG); |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 70 | if (reg < 0) |
| 71 | return reg; |
| 72 | counter = ((reg >> PCS_FW_HEARTB_LBN) & |
| 73 | ((1 << PCS_FW_HEARTB_WIDTH) - 1)); |
| 74 | if (old_counter == 0) |
| 75 | old_counter = counter; |
| 76 | else if (counter != old_counter) |
| 77 | break; |
| 78 | if (time_after(jiffies, timeout)) |
| 79 | return -ETIMEDOUT; |
| 80 | msleep(10); |
| 81 | } |
| 82 | |
| 83 | /* Wait for firmware status to look good */ |
| 84 | for (;;) { |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 85 | reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_UC8051_STATUS_REG); |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 86 | if (reg < 0) |
| 87 | return reg; |
| 88 | if ((reg & |
| 89 | ((1 << PCS_UC_STATUS_WIDTH) - 1) << PCS_UC_STATUS_LBN) >= |
| 90 | PCS_UC_STATUS_FW_SAVE) |
| 91 | break; |
| 92 | if (time_after(jiffies, timeout)) |
| 93 | return -ETIMEDOUT; |
| 94 | msleep(100); |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 100 | static int xfp_reset_phy(struct efx_nic *efx) |
| 101 | { |
| 102 | int rc; |
| 103 | |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 104 | if (efx->phy_type == PHY_TYPE_QT2025C) { |
Ben Hutchings | 5afaa75 | 2009-08-26 08:17:19 +0000 | [diff] [blame] | 105 | /* Wait for the reset triggered by falcon_reset_hw() |
| 106 | * to complete */ |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 107 | rc = qt2025c_wait_reset(efx); |
| 108 | if (rc < 0) |
| 109 | goto fail; |
Ben Hutchings | 5afaa75 | 2009-08-26 08:17:19 +0000 | [diff] [blame] | 110 | } else { |
| 111 | /* Reset the PHYXS MMD. This is documented as doing |
| 112 | * a complete soft reset. */ |
| 113 | rc = efx_mdio_reset_mmd(efx, MDIO_MMD_PHYXS, |
| 114 | XFP_MAX_RESET_TIME / XFP_RESET_WAIT, |
| 115 | XFP_RESET_WAIT); |
| 116 | if (rc < 0) |
| 117 | goto fail; |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 120 | /* Wait 250ms for the PHY to complete bootup */ |
| 121 | msleep(250); |
| 122 | |
| 123 | /* Check that all the MMDs we expect are present and responding. We |
| 124 | * expect faults on some if the link is down, but not on the PHY XS */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 125 | rc = efx_mdio_check_mmds(efx, XFP_REQUIRED_DEVS, MDIO_DEVS_PHYXS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 126 | if (rc < 0) |
| 127 | goto fail; |
| 128 | |
| 129 | efx->board_info.init_leds(efx); |
| 130 | |
| 131 | return rc; |
| 132 | |
| 133 | fail: |
Ben Hutchings | f794fd4 | 2009-02-27 13:06:58 +0000 | [diff] [blame] | 134 | EFX_ERR(efx, "PHY reset timed out\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 135 | return rc; |
| 136 | } |
| 137 | |
| 138 | static int xfp_phy_init(struct efx_nic *efx) |
| 139 | { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 140 | struct xfp_phy_data *phy_data; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 141 | u32 devid = efx_mdio_read_id(efx, MDIO_MMD_PHYXS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 142 | int rc; |
| 143 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 144 | phy_data = kzalloc(sizeof(struct xfp_phy_data), GFP_KERNEL); |
Ben Hutchings | 9b7bfc4 | 2008-05-16 21:20:20 +0100 | [diff] [blame] | 145 | if (!phy_data) |
| 146 | return -ENOMEM; |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 147 | efx->phy_data = phy_data; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 148 | |
Ben Hutchings | 3f39a5e | 2009-02-27 13:07:15 +0000 | [diff] [blame] | 149 | EFX_INFO(efx, "PHY ID reg %x (OUI %06x model %02x revision %x)\n", |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 150 | devid, efx_mdio_id_oui(devid), efx_mdio_id_model(devid), |
| 151 | efx_mdio_id_rev(devid)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 152 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 153 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 154 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 155 | rc = xfp_reset_phy(efx); |
| 156 | |
Ben Hutchings | f794fd4 | 2009-02-27 13:06:58 +0000 | [diff] [blame] | 157 | EFX_INFO(efx, "PHY init %s.\n", |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 158 | rc ? "failed" : "successful"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 159 | if (rc < 0) |
| 160 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 161 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 162 | return 0; |
| 163 | |
| 164 | fail: |
| 165 | kfree(efx->phy_data); |
| 166 | efx->phy_data = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 167 | return rc; |
| 168 | } |
| 169 | |
| 170 | static void xfp_phy_clear_interrupt(struct efx_nic *efx) |
| 171 | { |
Ben Hutchings | 6bc5046 | 2009-05-15 06:06:16 +0000 | [diff] [blame] | 172 | /* Read to clear link status alarm */ |
| 173 | efx_mdio_read(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_STAT); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static int xfp_link_ok(struct efx_nic *efx) |
| 177 | { |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 178 | return efx_mdio_links_ok(efx, XFP_REQUIRED_DEVS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 181 | static void xfp_phy_poll(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 182 | { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 183 | int link_up = xfp_link_ok(efx); |
| 184 | /* Simulate a PHY event if link state has changed */ |
| 185 | if (link_up != efx->link_up) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 186 | falcon_sim_phy_event(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static void xfp_phy_reconfigure(struct efx_nic *efx) |
| 190 | { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 191 | struct xfp_phy_data *phy_data = efx->phy_data; |
| 192 | |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 193 | if (efx->phy_type == PHY_TYPE_QT2025C) { |
| 194 | /* There are several different register bits which can |
| 195 | * disable TX (and save power) on direct-attach cables |
| 196 | * or optical transceivers, varying somewhat between |
| 197 | * firmware versions. Only 'static mode' appears to |
| 198 | * cover everything. */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 199 | mdio_set_flag( |
| 200 | &efx->mdio, efx->mdio.prtad, MDIO_MMD_PMAPMD, |
| 201 | PMA_PMD_FTX_CTRL2_REG, 1 << PMA_PMD_FTX_STATIC_LBN, |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 202 | efx->phy_mode & PHY_MODE_TX_DISABLED || |
| 203 | efx->phy_mode & PHY_MODE_LOW_POWER || |
| 204 | efx->loopback_mode == LOOPBACK_PCS || |
| 205 | efx->loopback_mode == LOOPBACK_PMAPMD); |
| 206 | } else { |
| 207 | /* Reset the PHY when moving from tx off to tx on */ |
| 208 | if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) && |
| 209 | (phy_data->phy_mode & PHY_MODE_TX_DISABLED)) |
| 210 | xfp_reset_phy(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 211 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 212 | efx_mdio_transmit_disable(efx); |
Ben Hutchings | d2d2c37 | 2009-02-27 13:07:33 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 215 | efx_mdio_phy_reconfigure(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 216 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 217 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 218 | efx->link_up = xfp_link_ok(efx); |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 219 | efx->link_speed = 10000; |
| 220 | efx->link_fd = true; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 221 | efx->link_fc = efx->wanted_fc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 224 | static void xfp_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
| 225 | { |
| 226 | mdio45_ethtool_gset(&efx->mdio, ecmd); |
| 227 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 228 | |
| 229 | static void xfp_phy_fini(struct efx_nic *efx) |
| 230 | { |
| 231 | /* Clobber the LED if it was blinking */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 232 | efx->board_info.blink(efx, false); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 233 | |
| 234 | /* Free the context block */ |
| 235 | kfree(efx->phy_data); |
| 236 | efx->phy_data = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | struct efx_phy_operations falcon_xfp_phy_ops = { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 240 | .macs = EFX_XMAC, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 241 | .init = xfp_phy_init, |
| 242 | .reconfigure = xfp_phy_reconfigure, |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 243 | .poll = xfp_phy_poll, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 244 | .fini = xfp_phy_fini, |
| 245 | .clear_interrupt = xfp_phy_clear_interrupt, |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 246 | .get_settings = xfp_phy_get_settings, |
| 247 | .set_settings = efx_mdio_set_settings, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 248 | .mmds = XFP_REQUIRED_DEVS, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 249 | .loopbacks = XFP_LOOPBACKS, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 250 | }; |