Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2007-2008 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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 | #include <linux/delay.h> |
Herbert Xu | da3bc07 | 2009-01-18 21:50:16 -0800 | [diff] [blame] | 11 | #include <linux/rtnetlink.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 12 | #include <linux/seq_file.h> |
| 13 | #include "efx.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 14 | #include "mdio_10g.h" |
| 15 | #include "falcon.h" |
| 16 | #include "phy.h" |
| 17 | #include "falcon_hwdefs.h" |
| 18 | #include "boards.h" |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 19 | #include "workarounds.h" |
| 20 | #include "selftest.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 21 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 22 | /* We expect these MMDs to be in the package. SFT9001 also has a |
| 23 | * clause 22 extension MMD, but since it doesn't have all the generic |
| 24 | * MMD registers it is pointless to include it here. |
| 25 | */ |
Ben Hutchings | 27dd2ca | 2008-12-12 21:44:14 -0800 | [diff] [blame] | 26 | #define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PMAPMD | \ |
| 27 | MDIO_MMDREG_DEVS_PCS | \ |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 28 | MDIO_MMDREG_DEVS_PHYXS | \ |
| 29 | MDIO_MMDREG_DEVS_AN) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 31 | #define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \ |
| 32 | (1 << LOOPBACK_PCS) | \ |
| 33 | (1 << LOOPBACK_PMAPMD) | \ |
| 34 | (1 << LOOPBACK_NETWORK)) |
| 35 | |
| 36 | #define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \ |
| 37 | (1 << LOOPBACK_PHYXS) | \ |
| 38 | (1 << LOOPBACK_PCS) | \ |
| 39 | (1 << LOOPBACK_PMAPMD) | \ |
| 40 | (1 << LOOPBACK_NETWORK)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 41 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 42 | /* We complain if we fail to see the link partner as 10G capable this many |
| 43 | * times in a row (must be > 1 as sampling the autoneg. registers is racy) |
| 44 | */ |
| 45 | #define MAX_BAD_LP_TRIES (5) |
| 46 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 47 | /* LASI Control */ |
| 48 | #define PMA_PMD_LASI_CTRL 36866 |
| 49 | #define PMA_PMD_LASI_STATUS 36869 |
| 50 | #define PMA_PMD_LS_ALARM_LBN 0 |
| 51 | #define PMA_PMD_LS_ALARM_WIDTH 1 |
| 52 | #define PMA_PMD_TX_ALARM_LBN 1 |
| 53 | #define PMA_PMD_TX_ALARM_WIDTH 1 |
| 54 | #define PMA_PMD_RX_ALARM_LBN 2 |
| 55 | #define PMA_PMD_RX_ALARM_WIDTH 1 |
| 56 | #define PMA_PMD_AN_ALARM_LBN 3 |
| 57 | #define PMA_PMD_AN_ALARM_WIDTH 1 |
| 58 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 59 | /* Extended control register */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 60 | #define PMA_PMD_XCONTROL_REG 49152 |
| 61 | #define PMA_PMD_EXT_GMII_EN_LBN 1 |
| 62 | #define PMA_PMD_EXT_GMII_EN_WIDTH 1 |
| 63 | #define PMA_PMD_EXT_CLK_OUT_LBN 2 |
| 64 | #define PMA_PMD_EXT_CLK_OUT_WIDTH 1 |
| 65 | #define PMA_PMD_LNPGA_POWERDOWN_LBN 8 /* SFX7101 only */ |
| 66 | #define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1 |
| 67 | #define PMA_PMD_EXT_CLK312_LBN 8 /* SFT9001 only */ |
| 68 | #define PMA_PMD_EXT_CLK312_WIDTH 1 |
| 69 | #define PMA_PMD_EXT_LPOWER_LBN 12 |
| 70 | #define PMA_PMD_EXT_LPOWER_WIDTH 1 |
Steve Hodgson | 869b5b3 | 2009-01-29 17:48:10 +0000 | [diff] [blame] | 71 | #define PMA_PMD_EXT_ROBUST_LBN 14 |
| 72 | #define PMA_PMD_EXT_ROBUST_WIDTH 1 |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 73 | #define PMA_PMD_EXT_SSR_LBN 15 |
| 74 | #define PMA_PMD_EXT_SSR_WIDTH 1 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 75 | |
| 76 | /* extended status register */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 77 | #define PMA_PMD_XSTATUS_REG 49153 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 78 | #define PMA_PMD_XSTAT_FLP_LBN (12) |
| 79 | |
| 80 | /* LED control register */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 81 | #define PMA_PMD_LED_CTRL_REG 49159 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 82 | #define PMA_PMA_LED_ACTIVITY_LBN (3) |
| 83 | |
| 84 | /* LED function override register */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 85 | #define PMA_PMD_LED_OVERR_REG 49161 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 86 | /* Bit positions for different LEDs (there are more but not wired on SFE4001)*/ |
| 87 | #define PMA_PMD_LED_LINK_LBN (0) |
| 88 | #define PMA_PMD_LED_SPEED_LBN (2) |
| 89 | #define PMA_PMD_LED_TX_LBN (4) |
| 90 | #define PMA_PMD_LED_RX_LBN (6) |
| 91 | /* Override settings */ |
| 92 | #define PMA_PMD_LED_AUTO (0) /* H/W control */ |
| 93 | #define PMA_PMD_LED_ON (1) |
| 94 | #define PMA_PMD_LED_OFF (2) |
| 95 | #define PMA_PMD_LED_FLASH (3) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 96 | #define PMA_PMD_LED_MASK 3 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 97 | /* All LEDs under hardware control */ |
| 98 | #define PMA_PMD_LED_FULL_AUTO (0) |
| 99 | /* Green and Amber under hardware control, Red off */ |
| 100 | #define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN) |
| 101 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 102 | #define PMA_PMD_SPEED_ENABLE_REG 49192 |
| 103 | #define PMA_PMD_100TX_ADV_LBN 1 |
| 104 | #define PMA_PMD_100TX_ADV_WIDTH 1 |
| 105 | #define PMA_PMD_1000T_ADV_LBN 2 |
| 106 | #define PMA_PMD_1000T_ADV_WIDTH 1 |
| 107 | #define PMA_PMD_10000T_ADV_LBN 3 |
| 108 | #define PMA_PMD_10000T_ADV_WIDTH 1 |
| 109 | #define PMA_PMD_SPEED_LBN 4 |
| 110 | #define PMA_PMD_SPEED_WIDTH 4 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 111 | |
Ben Hutchings | 307505e | 2008-12-26 13:48:00 -0800 | [diff] [blame] | 112 | /* Cable diagnostics - SFT9001 only */ |
| 113 | #define PMA_PMD_CDIAG_CTRL_REG 49213 |
| 114 | #define CDIAG_CTRL_IMMED_LBN 15 |
| 115 | #define CDIAG_CTRL_BRK_LINK_LBN 12 |
| 116 | #define CDIAG_CTRL_IN_PROG_LBN 11 |
| 117 | #define CDIAG_CTRL_LEN_UNIT_LBN 10 |
| 118 | #define CDIAG_CTRL_LEN_METRES 1 |
| 119 | #define PMA_PMD_CDIAG_RES_REG 49174 |
| 120 | #define CDIAG_RES_A_LBN 12 |
| 121 | #define CDIAG_RES_B_LBN 8 |
| 122 | #define CDIAG_RES_C_LBN 4 |
| 123 | #define CDIAG_RES_D_LBN 0 |
| 124 | #define CDIAG_RES_WIDTH 4 |
| 125 | #define CDIAG_RES_OPEN 2 |
| 126 | #define CDIAG_RES_OK 1 |
| 127 | #define CDIAG_RES_INVALID 0 |
| 128 | /* Set of 4 registers for pairs A-D */ |
| 129 | #define PMA_PMD_CDIAG_LEN_REG 49175 |
| 130 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 131 | /* Serdes control registers - SFT9001 only */ |
| 132 | #define PMA_PMD_CSERDES_CTRL_REG 64258 |
| 133 | /* Set the 156.25 MHz output to 312.5 MHz to drive Falcon's XMAC */ |
| 134 | #define PMA_PMD_CSERDES_DEFAULT 0x000f |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 135 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 136 | /* Misc register defines - SFX7101 only */ |
| 137 | #define PCS_CLOCK_CTRL_REG 55297 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 138 | #define PLL312_RST_N_LBN 2 |
| 139 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 140 | #define PCS_SOFT_RST2_REG 55302 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 141 | #define SERDES_RST_N_LBN 13 |
| 142 | #define XGXS_RST_N_LBN 12 |
| 143 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 144 | #define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 145 | #define CLK312_EN_LBN 3 |
| 146 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 147 | /* PHYXS registers */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 148 | #define PHYXS_XCONTROL_REG 49152 |
| 149 | #define PHYXS_RESET_LBN 15 |
| 150 | #define PHYXS_RESET_WIDTH 1 |
| 151 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 152 | #define PHYXS_TEST1 (49162) |
| 153 | #define LOOPBACK_NEAR_LBN (8) |
| 154 | #define LOOPBACK_NEAR_WIDTH (1) |
| 155 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 156 | #define PCS_10GBASET_STAT1 32 |
| 157 | #define PCS_10GBASET_BLKLK_LBN 0 |
| 158 | #define PCS_10GBASET_BLKLK_WIDTH 1 |
| 159 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 160 | /* Boot status register */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 161 | #define PCS_BOOT_STATUS_REG 53248 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 162 | #define PCS_BOOT_FATAL_ERR_LBN (0) |
| 163 | #define PCS_BOOT_PROGRESS_LBN (1) |
| 164 | #define PCS_BOOT_PROGRESS_WIDTH (2) |
| 165 | #define PCS_BOOT_COMPLETE_LBN (3) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 166 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 167 | #define PCS_BOOT_MAX_DELAY (100) |
| 168 | #define PCS_BOOT_POLL_DELAY (10) |
| 169 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 170 | /* 100M/1G PHY registers */ |
| 171 | #define GPHY_XCONTROL_REG 49152 |
| 172 | #define GPHY_ISOLATE_LBN 10 |
| 173 | #define GPHY_ISOLATE_WIDTH 1 |
| 174 | #define GPHY_DUPLEX_LBN 8 |
| 175 | #define GPHY_DUPLEX_WIDTH 1 |
| 176 | #define GPHY_LOOPBACK_NEAR_LBN 14 |
| 177 | #define GPHY_LOOPBACK_NEAR_WIDTH 1 |
| 178 | |
| 179 | #define C22EXT_STATUS_REG 49153 |
| 180 | #define C22EXT_STATUS_LINK_LBN 2 |
| 181 | #define C22EXT_STATUS_LINK_WIDTH 1 |
| 182 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 183 | #define C22EXT_MSTSLV_CTRL 49161 |
| 184 | #define C22EXT_MSTSLV_CTRL_ADV_1000_HD_LBN 8 |
| 185 | #define C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN 9 |
| 186 | |
| 187 | #define C22EXT_MSTSLV_STATUS 49162 |
| 188 | #define C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN 10 |
| 189 | #define C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN 11 |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 190 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 191 | /* Time to wait between powering down the LNPGA and turning off the power |
| 192 | * rails */ |
| 193 | #define LNPGA_PDOWN_WAIT (HZ / 5) |
| 194 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 195 | struct tenxpress_phy_data { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 196 | enum efx_loopback_mode loopback_mode; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 197 | enum efx_phy_mode phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 198 | int bad_lp_tries; |
| 199 | }; |
| 200 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 201 | static ssize_t show_phy_short_reach(struct device *dev, |
| 202 | struct device_attribute *attr, char *buf) |
| 203 | { |
| 204 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 205 | int reg; |
| 206 | |
| 207 | reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 208 | MDIO_PMAPMD_10GBT_TXPWR); |
| 209 | return sprintf(buf, "%d\n", |
| 210 | !!(reg & (1 << MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN))); |
| 211 | } |
| 212 | |
| 213 | static ssize_t set_phy_short_reach(struct device *dev, |
| 214 | struct device_attribute *attr, |
| 215 | const char *buf, size_t count) |
| 216 | { |
| 217 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); |
| 218 | |
| 219 | rtnl_lock(); |
| 220 | mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 221 | MDIO_PMAPMD_10GBT_TXPWR, |
| 222 | MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN, |
| 223 | count != 0 && *buf != '0'); |
| 224 | efx_reconfigure_port(efx); |
| 225 | rtnl_unlock(); |
| 226 | |
| 227 | return count; |
| 228 | } |
| 229 | |
| 230 | static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach, |
| 231 | set_phy_short_reach); |
| 232 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 233 | /* Check that the C166 has booted successfully */ |
| 234 | static int tenxpress_phy_check(struct efx_nic *efx) |
| 235 | { |
| 236 | int phy_id = efx->mii.phy_id; |
| 237 | int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY; |
| 238 | int boot_stat; |
| 239 | |
| 240 | /* Wait for the boot to complete (or not) */ |
| 241 | while (count) { |
| 242 | boot_stat = mdio_clause45_read(efx, phy_id, |
| 243 | MDIO_MMD_PCS, |
| 244 | PCS_BOOT_STATUS_REG); |
| 245 | if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN)) |
| 246 | break; |
| 247 | count--; |
| 248 | udelay(PCS_BOOT_POLL_DELAY); |
| 249 | } |
| 250 | |
| 251 | if (!count) { |
| 252 | EFX_ERR(efx, "%s: PHY boot timed out. Last status " |
| 253 | "%x\n", __func__, |
| 254 | (boot_stat >> PCS_BOOT_PROGRESS_LBN) & |
| 255 | ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1)); |
| 256 | return -ETIMEDOUT; |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 262 | static int tenxpress_init(struct efx_nic *efx) |
| 263 | { |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 264 | int phy_id = efx->mii.phy_id; |
| 265 | int reg; |
| 266 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 267 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 268 | if (efx->phy_type == PHY_TYPE_SFX7101) { |
| 269 | /* Enable 312.5 MHz clock */ |
| 270 | mdio_clause45_write(efx, phy_id, |
| 271 | MDIO_MMD_PCS, PCS_TEST_SELECT_REG, |
| 272 | 1 << CLK312_EN_LBN); |
| 273 | } else { |
| 274 | /* Enable 312.5 MHz clock and GMII */ |
| 275 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD, |
| 276 | PMA_PMD_XCONTROL_REG); |
| 277 | reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) | |
| 278 | (1 << PMA_PMD_EXT_CLK_OUT_LBN) | |
Steve Hodgson | 869b5b3 | 2009-01-29 17:48:10 +0000 | [diff] [blame] | 279 | (1 << PMA_PMD_EXT_CLK312_LBN) | |
| 280 | (1 << PMA_PMD_EXT_ROBUST_LBN)); |
| 281 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 282 | mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, |
| 283 | PMA_PMD_XCONTROL_REG, reg); |
| 284 | mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT, |
| 285 | GPHY_XCONTROL_REG, GPHY_ISOLATE_LBN, |
| 286 | false); |
| 287 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 288 | |
| 289 | rc = tenxpress_phy_check(efx); |
| 290 | if (rc < 0) |
| 291 | return rc; |
| 292 | |
| 293 | /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */ |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 294 | if (efx->phy_type == PHY_TYPE_SFX7101) { |
| 295 | mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD, |
| 296 | PMA_PMD_LED_CTRL_REG, |
| 297 | PMA_PMA_LED_ACTIVITY_LBN, |
| 298 | true); |
| 299 | mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, |
| 300 | PMA_PMD_LED_OVERR_REG, PMA_PMD_LED_DEFAULT); |
| 301 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 302 | |
| 303 | return rc; |
| 304 | } |
| 305 | |
| 306 | static int tenxpress_phy_init(struct efx_nic *efx) |
| 307 | { |
| 308 | struct tenxpress_phy_data *phy_data; |
| 309 | int rc = 0; |
| 310 | |
| 311 | phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL); |
Ben Hutchings | 9b7bfc4 | 2008-05-16 21:20:20 +0100 | [diff] [blame] | 312 | if (!phy_data) |
| 313 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 314 | efx->phy_data = phy_data; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 315 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 316 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 317 | if (!(efx->phy_mode & PHY_MODE_SPECIAL)) { |
| 318 | if (efx->phy_type == PHY_TYPE_SFT9001A) { |
| 319 | int reg; |
| 320 | reg = mdio_clause45_read(efx, efx->mii.phy_id, |
| 321 | MDIO_MMD_PMAPMD, |
| 322 | PMA_PMD_XCONTROL_REG); |
| 323 | reg |= (1 << PMA_PMD_EXT_SSR_LBN); |
| 324 | mdio_clause45_write(efx, efx->mii.phy_id, |
| 325 | MDIO_MMD_PMAPMD, |
| 326 | PMA_PMD_XCONTROL_REG, reg); |
| 327 | mdelay(200); |
| 328 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 329 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 330 | rc = mdio_clause45_wait_reset_mmds(efx, |
| 331 | TENXPRESS_REQUIRED_DEVS); |
| 332 | if (rc < 0) |
| 333 | goto fail; |
| 334 | |
| 335 | rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0); |
| 336 | if (rc < 0) |
| 337 | goto fail; |
| 338 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 339 | |
| 340 | rc = tenxpress_init(efx); |
| 341 | if (rc < 0) |
| 342 | goto fail; |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 343 | mdio_clause45_set_pause(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 344 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 345 | if (efx->phy_type == PHY_TYPE_SFT9001B) { |
| 346 | rc = device_create_file(&efx->pci_dev->dev, |
| 347 | &dev_attr_phy_short_reach); |
| 348 | if (rc) |
| 349 | goto fail; |
| 350 | } |
| 351 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 352 | schedule_timeout_uninterruptible(HZ / 5); /* 200ms */ |
| 353 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 354 | /* Let XGXS and SerDes out of reset */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 355 | falcon_reset_xaui(efx); |
| 356 | |
| 357 | return 0; |
| 358 | |
| 359 | fail: |
| 360 | kfree(efx->phy_data); |
| 361 | efx->phy_data = NULL; |
| 362 | return rc; |
| 363 | } |
| 364 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 365 | /* Perform a "special software reset" on the PHY. The caller is |
| 366 | * responsible for saving and restoring the PHY hardware registers |
| 367 | * properly, and masking/unmasking LASI */ |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 368 | static int tenxpress_special_reset(struct efx_nic *efx) |
| 369 | { |
| 370 | int rc, reg; |
| 371 | |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 372 | /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so |
| 373 | * a special software reset can glitch the XGMAC sufficiently for stats |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 374 | * requests to fail. */ |
| 375 | efx_stats_disable(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 376 | |
| 377 | /* Initiate reset */ |
| 378 | reg = mdio_clause45_read(efx, efx->mii.phy_id, |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 379 | MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 380 | reg |= (1 << PMA_PMD_EXT_SSR_LBN); |
| 381 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 382 | PMA_PMD_XCONTROL_REG, reg); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 383 | |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 384 | mdelay(200); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 385 | |
| 386 | /* Wait for the blocks to come out of reset */ |
| 387 | rc = mdio_clause45_wait_reset_mmds(efx, |
| 388 | TENXPRESS_REQUIRED_DEVS); |
| 389 | if (rc < 0) |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 390 | goto out; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 391 | |
| 392 | /* Try and reconfigure the device */ |
| 393 | rc = tenxpress_init(efx); |
| 394 | if (rc < 0) |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 395 | goto out; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 396 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 397 | /* Wait for the XGXS state machine to churn */ |
| 398 | mdelay(10); |
Ben Hutchings | 1974cc2 | 2009-01-29 18:00:07 +0000 | [diff] [blame] | 399 | out: |
| 400 | efx_stats_enable(efx); |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 401 | return rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 404 | static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 405 | { |
| 406 | struct tenxpress_phy_data *pd = efx->phy_data; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 407 | int phy_id = efx->mii.phy_id; |
| 408 | bool bad_lp; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 409 | int reg; |
| 410 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 411 | if (link_ok) { |
| 412 | bad_lp = false; |
| 413 | } else { |
| 414 | /* Check that AN has started but not completed. */ |
| 415 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, |
| 416 | MDIO_AN_STATUS); |
| 417 | if (!(reg & (1 << MDIO_AN_STATUS_LP_AN_CAP_LBN))) |
| 418 | return; /* LP status is unknown */ |
| 419 | bad_lp = !(reg & (1 << MDIO_AN_STATUS_AN_DONE_LBN)); |
| 420 | if (bad_lp) |
| 421 | pd->bad_lp_tries++; |
| 422 | } |
| 423 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 424 | /* Nothing to do if all is well and was previously so. */ |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 425 | if (!pd->bad_lp_tries) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 426 | return; |
| 427 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 428 | /* Use the RX (red) LED as an error indicator once we've seen AN |
| 429 | * failure several times in a row, and also log a message. */ |
| 430 | if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) { |
| 431 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD, |
| 432 | PMA_PMD_LED_OVERR_REG); |
| 433 | reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN); |
| 434 | if (!bad_lp) { |
| 435 | reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN; |
| 436 | } else { |
| 437 | reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN; |
| 438 | EFX_ERR(efx, "appears to be plugged into a port" |
| 439 | " that is not 10GBASE-T capable. The PHY" |
| 440 | " supports 10GBASE-T ONLY, so no link can" |
| 441 | " be established\n"); |
| 442 | } |
| 443 | mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, |
| 444 | PMA_PMD_LED_OVERR_REG, reg); |
| 445 | pd->bad_lp_tries = bad_lp; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 446 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 449 | static bool sfx7101_link_ok(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 450 | { |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 451 | return mdio_clause45_links_ok(efx, |
| 452 | MDIO_MMDREG_DEVS_PMAPMD | |
| 453 | MDIO_MMDREG_DEVS_PCS | |
| 454 | MDIO_MMDREG_DEVS_PHYXS); |
| 455 | } |
| 456 | |
| 457 | static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
| 458 | { |
| 459 | int phy_id = efx->mii.phy_id; |
| 460 | u32 reg; |
| 461 | |
Ben Hutchings | caa8d8b | 2008-12-26 13:46:12 -0800 | [diff] [blame] | 462 | if (efx_phy_mode_disabled(efx->phy_mode)) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 463 | return false; |
Ben Hutchings | caa8d8b | 2008-12-26 13:46:12 -0800 | [diff] [blame] | 464 | else if (efx->loopback_mode == LOOPBACK_GPHY) |
| 465 | return true; |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 466 | else if (efx->loopback_mode) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 467 | return mdio_clause45_links_ok(efx, |
| 468 | MDIO_MMDREG_DEVS_PMAPMD | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 469 | MDIO_MMDREG_DEVS_PHYXS); |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 470 | |
| 471 | /* We must use the same definition of link state as LASI, |
| 472 | * otherwise we can miss a link state transition |
| 473 | */ |
| 474 | if (ecmd->speed == 10000) { |
| 475 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS, |
| 476 | PCS_10GBASET_STAT1); |
| 477 | return reg & (1 << PCS_10GBASET_BLKLK_LBN); |
| 478 | } else { |
| 479 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT, |
| 480 | C22EXT_STATUS_REG); |
| 481 | return reg & (1 << C22EXT_STATUS_LINK_LBN); |
| 482 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 485 | static void tenxpress_ext_loopback(struct efx_nic *efx) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 486 | { |
| 487 | int phy_id = efx->mii.phy_id; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 488 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 489 | mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS, |
| 490 | PHYXS_TEST1, LOOPBACK_NEAR_LBN, |
| 491 | efx->loopback_mode == LOOPBACK_PHYXS); |
| 492 | if (efx->phy_type != PHY_TYPE_SFX7101) |
| 493 | mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT, |
| 494 | GPHY_XCONTROL_REG, |
| 495 | GPHY_LOOPBACK_NEAR_LBN, |
| 496 | efx->loopback_mode == LOOPBACK_GPHY); |
| 497 | } |
| 498 | |
| 499 | static void tenxpress_low_power(struct efx_nic *efx) |
| 500 | { |
| 501 | int phy_id = efx->mii.phy_id; |
| 502 | |
| 503 | if (efx->phy_type == PHY_TYPE_SFX7101) |
| 504 | mdio_clause45_set_mmds_lpower( |
| 505 | efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER), |
| 506 | TENXPRESS_REQUIRED_DEVS); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 507 | else |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 508 | mdio_clause45_set_flag( |
| 509 | efx, phy_id, MDIO_MMD_PMAPMD, |
| 510 | PMA_PMD_XCONTROL_REG, PMA_PMD_EXT_LPOWER_LBN, |
| 511 | !!(efx->phy_mode & PHY_MODE_LOW_POWER)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 514 | static void tenxpress_phy_reconfigure(struct efx_nic *efx) |
| 515 | { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 516 | struct tenxpress_phy_data *phy_data = efx->phy_data; |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 517 | struct ethtool_cmd ecmd; |
Steve Hodgson | 8b9dc8d | 2009-01-29 17:49:09 +0000 | [diff] [blame] | 518 | bool phy_mode_change, loop_reset; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 519 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 520 | if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) { |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 521 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 522 | return; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 523 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 524 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 525 | tenxpress_low_power(efx); |
| 526 | |
| 527 | phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL && |
| 528 | phy_data->phy_mode != PHY_MODE_NORMAL); |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 529 | loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) || |
| 530 | LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY)); |
| 531 | |
Steve Hodgson | 8b9dc8d | 2009-01-29 17:49:09 +0000 | [diff] [blame] | 532 | if (loop_reset || phy_mode_change) { |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 533 | int rc; |
| 534 | |
| 535 | efx->phy_op->get_settings(efx, &ecmd); |
| 536 | |
| 537 | if (loop_reset || phy_mode_change) { |
| 538 | tenxpress_special_reset(efx); |
| 539 | |
| 540 | /* Reset XAUI if we were in 10G, and are staying |
| 541 | * in 10G. If we're moving into and out of 10G |
| 542 | * then xaui will be reset anyway */ |
| 543 | if (EFX_IS10G(efx)) |
| 544 | falcon_reset_xaui(efx); |
| 545 | } |
| 546 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 547 | rc = efx->phy_op->set_settings(efx, &ecmd); |
| 548 | WARN_ON(rc); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | mdio_clause45_transmit_disable(efx); |
| 552 | mdio_clause45_phy_reconfigure(efx); |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 553 | tenxpress_ext_loopback(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 554 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 555 | phy_data->loopback_mode = efx->loopback_mode; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 556 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 557 | |
| 558 | if (efx->phy_type == PHY_TYPE_SFX7101) { |
| 559 | efx->link_speed = 10000; |
| 560 | efx->link_fd = true; |
| 561 | efx->link_up = sfx7101_link_ok(efx); |
| 562 | } else { |
| 563 | efx->phy_op->get_settings(efx, &ecmd); |
| 564 | efx->link_speed = ecmd.speed; |
| 565 | efx->link_fd = ecmd.duplex == DUPLEX_FULL; |
| 566 | efx->link_up = sft9001_link_ok(efx, &ecmd); |
| 567 | } |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 568 | efx->link_fc = mdio_clause45_get_pause(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 571 | /* Poll PHY for interrupt */ |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 572 | static void tenxpress_phy_poll(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 573 | { |
| 574 | struct tenxpress_phy_data *phy_data = efx->phy_data; |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 575 | bool change = false, link_ok; |
| 576 | unsigned link_fc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 577 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 578 | if (efx->phy_type == PHY_TYPE_SFX7101) { |
| 579 | link_ok = sfx7101_link_ok(efx); |
| 580 | if (link_ok != efx->link_up) { |
| 581 | change = true; |
| 582 | } else { |
| 583 | link_fc = mdio_clause45_get_pause(efx); |
| 584 | if (link_fc != efx->link_fc) |
| 585 | change = true; |
| 586 | } |
| 587 | sfx7101_check_bad_lp(efx, link_ok); |
Ben Hutchings | caa8d8b | 2008-12-26 13:46:12 -0800 | [diff] [blame] | 588 | } else if (efx->loopback_mode) { |
| 589 | bool link_ok = sft9001_link_ok(efx, NULL); |
| 590 | if (link_ok != efx->link_up) |
| 591 | change = true; |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 592 | } else { |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 593 | u32 status = mdio_clause45_read(efx, efx->mii.phy_id, |
| 594 | MDIO_MMD_PMAPMD, |
| 595 | PMA_PMD_LASI_STATUS); |
| 596 | if (status & (1 << PMA_PMD_LS_ALARM_LBN)) |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 597 | change = true; |
| 598 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 599 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 600 | if (change) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 601 | falcon_sim_phy_event(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 602 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 603 | if (phy_data->phy_mode != PHY_MODE_NORMAL) |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 604 | return; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void tenxpress_phy_fini(struct efx_nic *efx) |
| 608 | { |
| 609 | int reg; |
| 610 | |
Ben Hutchings | 2a7e637 | 2009-01-11 00:18:13 -0800 | [diff] [blame] | 611 | if (efx->phy_type == PHY_TYPE_SFT9001B) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 612 | device_remove_file(&efx->pci_dev->dev, |
| 613 | &dev_attr_phy_short_reach); |
Ben Hutchings | 2a7e637 | 2009-01-11 00:18:13 -0800 | [diff] [blame] | 614 | |
| 615 | if (efx->phy_type == PHY_TYPE_SFX7101) { |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 616 | /* Power down the LNPGA */ |
| 617 | reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN); |
| 618 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 619 | PMA_PMD_XCONTROL_REG, reg); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 620 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 621 | /* Waiting here ensures that the board fini, which can turn |
| 622 | * off the power to the PHY, won't get run until the LNPGA |
| 623 | * powerdown has been given long enough to complete. */ |
| 624 | schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */ |
| 625 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 626 | |
| 627 | kfree(efx->phy_data); |
| 628 | efx->phy_data = NULL; |
| 629 | } |
| 630 | |
| 631 | |
| 632 | /* Set the RX and TX LEDs and Link LED flashing. The other LEDs |
| 633 | * (which probably aren't wired anyway) are left in AUTO mode */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 634 | void tenxpress_phy_blink(struct efx_nic *efx, bool blink) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 635 | { |
| 636 | int reg; |
| 637 | |
| 638 | if (blink) |
| 639 | reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) | |
| 640 | (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) | |
| 641 | (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN); |
| 642 | else |
| 643 | reg = PMA_PMD_LED_DEFAULT; |
| 644 | |
| 645 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 646 | PMA_PMD_LED_OVERR_REG, reg); |
| 647 | } |
| 648 | |
Ben Hutchings | 307505e | 2008-12-26 13:48:00 -0800 | [diff] [blame] | 649 | static const char *const sfx7101_test_names[] = { |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 650 | "bist" |
| 651 | }; |
| 652 | |
| 653 | static int |
Ben Hutchings | 307505e | 2008-12-26 13:48:00 -0800 | [diff] [blame] | 654 | sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags) |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 655 | { |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 656 | int rc; |
| 657 | |
| 658 | if (!(flags & ETH_TEST_FL_OFFLINE)) |
| 659 | return 0; |
| 660 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 661 | /* BIST is automatically run after a special software reset */ |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 662 | rc = tenxpress_special_reset(efx); |
| 663 | results[0] = rc ? -1 : 1; |
| 664 | return rc; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Ben Hutchings | 307505e | 2008-12-26 13:48:00 -0800 | [diff] [blame] | 667 | static const char *const sft9001_test_names[] = { |
| 668 | "bist", |
| 669 | "cable.pairA.status", |
| 670 | "cable.pairB.status", |
| 671 | "cable.pairC.status", |
| 672 | "cable.pairD.status", |
| 673 | "cable.pairA.length", |
| 674 | "cable.pairB.length", |
| 675 | "cable.pairC.length", |
| 676 | "cable.pairD.length", |
| 677 | }; |
| 678 | |
| 679 | static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags) |
| 680 | { |
| 681 | struct ethtool_cmd ecmd; |
| 682 | int phy_id = efx->mii.phy_id; |
| 683 | int rc = 0, rc2, i, res_reg; |
| 684 | |
| 685 | if (!(flags & ETH_TEST_FL_OFFLINE)) |
| 686 | return 0; |
| 687 | |
| 688 | efx->phy_op->get_settings(efx, &ecmd); |
| 689 | |
| 690 | /* Initialise cable diagnostic results to unknown failure */ |
| 691 | for (i = 1; i < 9; ++i) |
| 692 | results[i] = -1; |
| 693 | |
| 694 | /* Run cable diagnostics; wait up to 5 seconds for them to complete. |
| 695 | * A cable fault is not a self-test failure, but a timeout is. */ |
| 696 | mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, |
| 697 | PMA_PMD_CDIAG_CTRL_REG, |
| 698 | (1 << CDIAG_CTRL_IMMED_LBN) | |
| 699 | (1 << CDIAG_CTRL_BRK_LINK_LBN) | |
| 700 | (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN)); |
| 701 | i = 0; |
| 702 | while (mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD, |
| 703 | PMA_PMD_CDIAG_CTRL_REG) & |
| 704 | (1 << CDIAG_CTRL_IN_PROG_LBN)) { |
| 705 | if (++i == 50) { |
| 706 | rc = -ETIMEDOUT; |
| 707 | goto reset; |
| 708 | } |
| 709 | msleep(100); |
| 710 | } |
| 711 | res_reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 712 | PMA_PMD_CDIAG_RES_REG); |
| 713 | for (i = 0; i < 4; i++) { |
| 714 | int pair_res = |
| 715 | (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH)) |
| 716 | & ((1 << CDIAG_RES_WIDTH) - 1); |
| 717 | int len_reg = mdio_clause45_read(efx, efx->mii.phy_id, |
| 718 | MDIO_MMD_PMAPMD, |
| 719 | PMA_PMD_CDIAG_LEN_REG + i); |
| 720 | if (pair_res == CDIAG_RES_OK) |
| 721 | results[1 + i] = 1; |
| 722 | else if (pair_res == CDIAG_RES_INVALID) |
| 723 | results[1 + i] = -1; |
| 724 | else |
| 725 | results[1 + i] = -pair_res; |
| 726 | if (pair_res != CDIAG_RES_INVALID && |
| 727 | pair_res != CDIAG_RES_OPEN && |
| 728 | len_reg != 0xffff) |
| 729 | results[5 + i] = len_reg; |
| 730 | } |
| 731 | |
| 732 | /* We must reset to exit cable diagnostic mode. The BIST will |
| 733 | * also run when we do this. */ |
| 734 | reset: |
| 735 | rc2 = tenxpress_special_reset(efx); |
| 736 | results[0] = rc2 ? -1 : 1; |
| 737 | if (!rc) |
| 738 | rc = rc2; |
| 739 | |
| 740 | rc2 = efx->phy_op->set_settings(efx, &ecmd); |
| 741 | if (!rc) |
| 742 | rc = rc2; |
| 743 | |
| 744 | return rc; |
| 745 | } |
| 746 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 747 | static void |
| 748 | tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 749 | { |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 750 | int phy_id = efx->mii.phy_id; |
| 751 | u32 adv = 0, lpa = 0; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 752 | int reg; |
| 753 | |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 754 | if (efx->phy_type != PHY_TYPE_SFX7101) { |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 755 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT, |
| 756 | C22EXT_MSTSLV_CTRL); |
| 757 | if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN)) |
| 758 | adv |= ADVERTISED_1000baseT_Full; |
| 759 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT, |
| 760 | C22EXT_MSTSLV_STATUS); |
| 761 | if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN)) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 762 | lpa |= ADVERTISED_1000baseT_Half; |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 763 | if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN)) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 764 | lpa |= ADVERTISED_1000baseT_Full; |
| 765 | } |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 766 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, |
| 767 | MDIO_AN_10GBT_CTRL); |
| 768 | if (reg & (1 << MDIO_AN_10GBT_CTRL_ADV_10G_LBN)) |
| 769 | adv |= ADVERTISED_10000baseT_Full; |
| 770 | reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, |
| 771 | MDIO_AN_10GBT_STATUS); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 772 | if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN)) |
| 773 | lpa |= ADVERTISED_10000baseT_Full; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 774 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 775 | mdio_clause45_get_settings_ext(efx, ecmd, adv, lpa); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 776 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 777 | if (efx->phy_type != PHY_TYPE_SFX7101) |
| 778 | ecmd->supported |= (SUPPORTED_100baseT_Full | |
| 779 | SUPPORTED_1000baseT_Full); |
Steve Hodgson | 8b9dc8d | 2009-01-29 17:49:09 +0000 | [diff] [blame] | 780 | |
| 781 | /* In loopback, the PHY automatically brings up the correct interface, |
| 782 | * but doesn't advertise the correct speed. So override it */ |
| 783 | if (efx->loopback_mode == LOOPBACK_GPHY) |
| 784 | ecmd->speed = SPEED_1000; |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 785 | else if (LOOPBACK_MASK(efx) & efx->phy_op->loopbacks) |
Steve Hodgson | 8b9dc8d | 2009-01-29 17:49:09 +0000 | [diff] [blame] | 786 | ecmd->speed = SPEED_10000; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 789 | static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 790 | { |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 791 | if (!ecmd->autoneg) |
| 792 | return -EINVAL; |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 793 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 794 | return mdio_clause45_set_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 797 | static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 798 | { |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 799 | mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_AN, |
| 800 | MDIO_AN_10GBT_CTRL, |
| 801 | MDIO_AN_10GBT_CTRL_ADV_10G_LBN, |
| 802 | advertising & ADVERTISED_10000baseT_Full); |
| 803 | } |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 804 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 805 | static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising) |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 806 | { |
| 807 | int phy_id = efx->mii.phy_id; |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 808 | |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 809 | mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT, |
| 810 | C22EXT_MSTSLV_CTRL, |
| 811 | C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN, |
| 812 | advertising & ADVERTISED_1000baseT_Full); |
| 813 | mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_AN, |
| 814 | MDIO_AN_10GBT_CTRL, |
| 815 | MDIO_AN_10GBT_CTRL_ADV_10G_LBN, |
| 816 | advertising & ADVERTISED_10000baseT_Full); |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | struct efx_phy_operations falcon_sfx7101_phy_ops = { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 820 | .macs = EFX_XMAC, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 821 | .init = tenxpress_phy_init, |
| 822 | .reconfigure = tenxpress_phy_reconfigure, |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 823 | .poll = tenxpress_phy_poll, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 824 | .fini = tenxpress_phy_fini, |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 825 | .clear_interrupt = efx_port_dummy_op_void, |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 826 | .get_settings = tenxpress_get_settings, |
| 827 | .set_settings = tenxpress_set_settings, |
| 828 | .set_npage_adv = sfx7101_set_npage_adv, |
Ben Hutchings | 307505e | 2008-12-26 13:48:00 -0800 | [diff] [blame] | 829 | .num_tests = ARRAY_SIZE(sfx7101_test_names), |
| 830 | .test_names = sfx7101_test_names, |
| 831 | .run_tests = sfx7101_run_tests, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 832 | .mmds = TENXPRESS_REQUIRED_DEVS, |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 833 | .loopbacks = SFX7101_LOOPBACKS, |
| 834 | }; |
| 835 | |
| 836 | struct efx_phy_operations falcon_sft9001_phy_ops = { |
| 837 | .macs = EFX_GMAC | EFX_XMAC, |
| 838 | .init = tenxpress_phy_init, |
| 839 | .reconfigure = tenxpress_phy_reconfigure, |
| 840 | .poll = tenxpress_phy_poll, |
| 841 | .fini = tenxpress_phy_fini, |
| 842 | .clear_interrupt = efx_port_dummy_op_void, |
Ben Hutchings | af4ad9b | 2009-01-29 17:59:37 +0000 | [diff] [blame] | 843 | .get_settings = tenxpress_get_settings, |
| 844 | .set_settings = tenxpress_set_settings, |
| 845 | .set_npage_adv = sft9001_set_npage_adv, |
Ben Hutchings | 307505e | 2008-12-26 13:48:00 -0800 | [diff] [blame] | 846 | .num_tests = ARRAY_SIZE(sft9001_test_names), |
| 847 | .test_names = sft9001_test_names, |
| 848 | .run_tests = sft9001_run_tests, |
Ben Hutchings | e6fa2eb | 2008-12-12 22:00:17 -0800 | [diff] [blame] | 849 | .mmds = TENXPRESS_REQUIRED_DEVS, |
| 850 | .loopbacks = SFT9001_LOOPBACKS, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 851 | }; |