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