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> |
| 11 | #include <linux/seq_file.h> |
| 12 | #include "efx.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 13 | #include "mdio_10g.h" |
| 14 | #include "falcon.h" |
| 15 | #include "phy.h" |
| 16 | #include "falcon_hwdefs.h" |
| 17 | #include "boards.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 18 | |
| 19 | /* We expect these MMDs to be in the package */ |
| 20 | /* AN not here as mdio_check_mmds() requires STAT2 support */ |
Ben Hutchings | 27dd2ca | 2008-12-12 21:44:14 -0800 | [diff] [blame] | 21 | #define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PMAPMD | \ |
| 22 | MDIO_MMDREG_DEVS_PCS | \ |
| 23 | MDIO_MMDREG_DEVS_PHYXS) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 24 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 25 | #define TENXPRESS_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \ |
| 26 | (1 << LOOPBACK_PCS) | \ |
| 27 | (1 << LOOPBACK_PMAPMD) | \ |
| 28 | (1 << LOOPBACK_NETWORK)) |
| 29 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | /* We complain if we fail to see the link partner as 10G capable this many |
| 31 | * times in a row (must be > 1 as sampling the autoneg. registers is racy) |
| 32 | */ |
| 33 | #define MAX_BAD_LP_TRIES (5) |
| 34 | |
| 35 | /* Extended control register */ |
| 36 | #define PMA_PMD_XCONTROL_REG 0xc000 |
| 37 | #define PMA_PMD_LNPGA_POWERDOWN_LBN 8 |
| 38 | #define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1 |
| 39 | |
| 40 | /* extended status register */ |
| 41 | #define PMA_PMD_XSTATUS_REG 0xc001 |
| 42 | #define PMA_PMD_XSTAT_FLP_LBN (12) |
| 43 | |
| 44 | /* LED control register */ |
| 45 | #define PMA_PMD_LED_CTRL_REG (0xc007) |
| 46 | #define PMA_PMA_LED_ACTIVITY_LBN (3) |
| 47 | |
| 48 | /* LED function override register */ |
| 49 | #define PMA_PMD_LED_OVERR_REG (0xc009) |
| 50 | /* Bit positions for different LEDs (there are more but not wired on SFE4001)*/ |
| 51 | #define PMA_PMD_LED_LINK_LBN (0) |
| 52 | #define PMA_PMD_LED_SPEED_LBN (2) |
| 53 | #define PMA_PMD_LED_TX_LBN (4) |
| 54 | #define PMA_PMD_LED_RX_LBN (6) |
| 55 | /* Override settings */ |
| 56 | #define PMA_PMD_LED_AUTO (0) /* H/W control */ |
| 57 | #define PMA_PMD_LED_ON (1) |
| 58 | #define PMA_PMD_LED_OFF (2) |
| 59 | #define PMA_PMD_LED_FLASH (3) |
| 60 | /* All LEDs under hardware control */ |
| 61 | #define PMA_PMD_LED_FULL_AUTO (0) |
| 62 | /* Green and Amber under hardware control, Red off */ |
| 63 | #define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN) |
| 64 | |
| 65 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 66 | /* Special Software reset register */ |
| 67 | #define PMA_PMD_EXT_CTRL_REG 49152 |
| 68 | #define PMA_PMD_EXT_SSR_LBN 15 |
| 69 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 70 | /* Misc register defines */ |
| 71 | #define PCS_CLOCK_CTRL_REG 0xd801 |
| 72 | #define PLL312_RST_N_LBN 2 |
| 73 | |
| 74 | #define PCS_SOFT_RST2_REG 0xd806 |
| 75 | #define SERDES_RST_N_LBN 13 |
| 76 | #define XGXS_RST_N_LBN 12 |
| 77 | |
| 78 | #define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */ |
| 79 | #define CLK312_EN_LBN 3 |
| 80 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 81 | /* PHYXS registers */ |
| 82 | #define PHYXS_TEST1 (49162) |
| 83 | #define LOOPBACK_NEAR_LBN (8) |
| 84 | #define LOOPBACK_NEAR_WIDTH (1) |
| 85 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 86 | /* Boot status register */ |
| 87 | #define PCS_BOOT_STATUS_REG (0xd000) |
| 88 | #define PCS_BOOT_FATAL_ERR_LBN (0) |
| 89 | #define PCS_BOOT_PROGRESS_LBN (1) |
| 90 | #define PCS_BOOT_PROGRESS_WIDTH (2) |
| 91 | #define PCS_BOOT_COMPLETE_LBN (3) |
| 92 | #define PCS_BOOT_MAX_DELAY (100) |
| 93 | #define PCS_BOOT_POLL_DELAY (10) |
| 94 | |
| 95 | /* Time to wait between powering down the LNPGA and turning off the power |
| 96 | * rails */ |
| 97 | #define LNPGA_PDOWN_WAIT (HZ / 5) |
| 98 | |
| 99 | static int crc_error_reset_threshold = 100; |
| 100 | module_param(crc_error_reset_threshold, int, 0644); |
| 101 | MODULE_PARM_DESC(crc_error_reset_threshold, |
| 102 | "Max number of CRC errors before XAUI reset"); |
| 103 | |
| 104 | struct tenxpress_phy_data { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 105 | enum efx_loopback_mode loopback_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 106 | atomic_t bad_crc_count; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 107 | enum efx_phy_mode phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 108 | int bad_lp_tries; |
| 109 | }; |
| 110 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 111 | void tenxpress_crc_err(struct efx_nic *efx) |
| 112 | { |
| 113 | struct tenxpress_phy_data *phy_data = efx->phy_data; |
| 114 | if (phy_data != NULL) |
| 115 | atomic_inc(&phy_data->bad_crc_count); |
| 116 | } |
| 117 | |
| 118 | /* Check that the C166 has booted successfully */ |
| 119 | static int tenxpress_phy_check(struct efx_nic *efx) |
| 120 | { |
| 121 | int phy_id = efx->mii.phy_id; |
| 122 | int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY; |
| 123 | int boot_stat; |
| 124 | |
| 125 | /* Wait for the boot to complete (or not) */ |
| 126 | while (count) { |
| 127 | boot_stat = mdio_clause45_read(efx, phy_id, |
| 128 | MDIO_MMD_PCS, |
| 129 | PCS_BOOT_STATUS_REG); |
| 130 | if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN)) |
| 131 | break; |
| 132 | count--; |
| 133 | udelay(PCS_BOOT_POLL_DELAY); |
| 134 | } |
| 135 | |
| 136 | if (!count) { |
| 137 | EFX_ERR(efx, "%s: PHY boot timed out. Last status " |
| 138 | "%x\n", __func__, |
| 139 | (boot_stat >> PCS_BOOT_PROGRESS_LBN) & |
| 140 | ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1)); |
| 141 | return -ETIMEDOUT; |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 147 | static int tenxpress_init(struct efx_nic *efx) |
| 148 | { |
| 149 | int rc, reg; |
| 150 | |
| 151 | /* Turn on the clock */ |
| 152 | reg = (1 << CLK312_EN_LBN); |
| 153 | mdio_clause45_write(efx, efx->mii.phy_id, |
| 154 | MDIO_MMD_PCS, PCS_TEST_SELECT_REG, reg); |
| 155 | |
| 156 | rc = tenxpress_phy_check(efx); |
| 157 | if (rc < 0) |
| 158 | return rc; |
| 159 | |
| 160 | /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */ |
| 161 | reg = mdio_clause45_read(efx, efx->mii.phy_id, |
| 162 | MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG); |
| 163 | reg |= (1 << PMA_PMA_LED_ACTIVITY_LBN); |
| 164 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 165 | PMA_PMD_LED_CTRL_REG, reg); |
| 166 | |
| 167 | reg = PMA_PMD_LED_DEFAULT; |
| 168 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 169 | PMA_PMD_LED_OVERR_REG, reg); |
| 170 | |
| 171 | return rc; |
| 172 | } |
| 173 | |
| 174 | static int tenxpress_phy_init(struct efx_nic *efx) |
| 175 | { |
| 176 | struct tenxpress_phy_data *phy_data; |
| 177 | int rc = 0; |
| 178 | |
| 179 | phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL); |
Ben Hutchings | 9b7bfc4 | 2008-05-16 21:20:20 +0100 | [diff] [blame] | 180 | if (!phy_data) |
| 181 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 182 | efx->phy_data = phy_data; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 183 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 184 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 185 | rc = mdio_clause45_wait_reset_mmds(efx, |
| 186 | TENXPRESS_REQUIRED_DEVS); |
| 187 | if (rc < 0) |
| 188 | goto fail; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 189 | |
| 190 | rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0); |
| 191 | if (rc < 0) |
| 192 | goto fail; |
| 193 | |
| 194 | rc = tenxpress_init(efx); |
| 195 | if (rc < 0) |
| 196 | goto fail; |
| 197 | |
| 198 | schedule_timeout_uninterruptible(HZ / 5); /* 200ms */ |
| 199 | |
| 200 | /* Let XGXS and SerDes out of reset and resets 10XPress */ |
| 201 | falcon_reset_xaui(efx); |
| 202 | |
| 203 | return 0; |
| 204 | |
| 205 | fail: |
| 206 | kfree(efx->phy_data); |
| 207 | efx->phy_data = NULL; |
| 208 | return rc; |
| 209 | } |
| 210 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 211 | static int tenxpress_special_reset(struct efx_nic *efx) |
| 212 | { |
| 213 | int rc, reg; |
| 214 | |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 215 | /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so |
| 216 | * a special software reset can glitch the XGMAC sufficiently for stats |
| 217 | * requests to fail. Since we don't ofen special_reset, just lock. */ |
| 218 | spin_lock(&efx->stats_lock); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 219 | |
| 220 | /* Initiate reset */ |
| 221 | reg = mdio_clause45_read(efx, efx->mii.phy_id, |
| 222 | MDIO_MMD_PMAPMD, PMA_PMD_EXT_CTRL_REG); |
| 223 | reg |= (1 << PMA_PMD_EXT_SSR_LBN); |
| 224 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 225 | PMA_PMD_EXT_CTRL_REG, reg); |
| 226 | |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 227 | mdelay(200); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 228 | |
| 229 | /* Wait for the blocks to come out of reset */ |
| 230 | rc = mdio_clause45_wait_reset_mmds(efx, |
| 231 | TENXPRESS_REQUIRED_DEVS); |
| 232 | if (rc < 0) |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 233 | goto unlock; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 234 | |
| 235 | /* Try and reconfigure the device */ |
| 236 | rc = tenxpress_init(efx); |
| 237 | if (rc < 0) |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 238 | goto unlock; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 239 | |
Ben Hutchings | c8fcc49 | 2008-09-01 12:49:25 +0100 | [diff] [blame] | 240 | unlock: |
| 241 | spin_unlock(&efx->stats_lock); |
| 242 | return rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 245 | static void tenxpress_set_bad_lp(struct efx_nic *efx, bool bad_lp) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 246 | { |
| 247 | struct tenxpress_phy_data *pd = efx->phy_data; |
| 248 | int reg; |
| 249 | |
| 250 | /* Nothing to do if all is well and was previously so. */ |
| 251 | if (!(bad_lp || pd->bad_lp_tries)) |
| 252 | return; |
| 253 | |
| 254 | reg = mdio_clause45_read(efx, efx->mii.phy_id, |
| 255 | MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG); |
| 256 | |
| 257 | if (bad_lp) |
| 258 | pd->bad_lp_tries++; |
| 259 | else |
| 260 | pd->bad_lp_tries = 0; |
| 261 | |
| 262 | if (pd->bad_lp_tries == MAX_BAD_LP_TRIES) { |
| 263 | pd->bad_lp_tries = 0; /* Restart count */ |
| 264 | reg &= ~(PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN); |
| 265 | reg |= (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN); |
| 266 | EFX_ERR(efx, "This NIC appears to be plugged into" |
| 267 | " a port that is not 10GBASE-T capable.\n" |
| 268 | " This PHY is 10GBASE-T ONLY, so no link can" |
| 269 | " be established.\n"); |
| 270 | } else { |
| 271 | reg |= (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN); |
| 272 | } |
| 273 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 274 | PMA_PMD_LED_OVERR_REG, reg); |
| 275 | } |
| 276 | |
| 277 | /* Check link status and return a boolean OK value. If the link is NOT |
| 278 | * OK we have a quick rummage round to see if we appear to be plugged |
| 279 | * into a non-10GBT port and if so warn the user that they won't get |
| 280 | * link any time soon as we are 10GBT only, unless caller specified |
| 281 | * not to do this check (it isn't useful in loopback) */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 282 | static bool tenxpress_link_ok(struct efx_nic *efx, bool check_lp) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 283 | { |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 284 | bool ok = mdio_clause45_links_ok(efx, TENXPRESS_REQUIRED_DEVS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 285 | |
| 286 | if (ok) { |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 287 | tenxpress_set_bad_lp(efx, false); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 288 | } else if (check_lp) { |
| 289 | /* Are we plugged into the wrong sort of link? */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 290 | bool bad_lp = false; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 291 | int phy_id = efx->mii.phy_id; |
| 292 | int an_stat = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, |
| 293 | MDIO_AN_STATUS); |
| 294 | int xphy_stat = mdio_clause45_read(efx, phy_id, |
| 295 | MDIO_MMD_PMAPMD, |
| 296 | PMA_PMD_XSTATUS_REG); |
| 297 | /* Are we plugged into anything that sends FLPs? If |
| 298 | * not we can't distinguish between not being plugged |
| 299 | * in and being plugged into a non-AN antique. The FLP |
| 300 | * bit has the advantage of not clearing when autoneg |
| 301 | * restarts. */ |
| 302 | if (!(xphy_stat & (1 << PMA_PMD_XSTAT_FLP_LBN))) { |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 303 | tenxpress_set_bad_lp(efx, false); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 304 | return ok; |
| 305 | } |
| 306 | |
| 307 | /* If it can do 10GBT it must be XNP capable */ |
| 308 | bad_lp = !(an_stat & (1 << MDIO_AN_STATUS_XNP_LBN)); |
| 309 | if (!bad_lp && (an_stat & (1 << MDIO_AN_STATUS_PAGE_LBN))) { |
| 310 | bad_lp = !(mdio_clause45_read(efx, phy_id, |
| 311 | MDIO_MMD_AN, MDIO_AN_10GBT_STATUS) & |
| 312 | (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN)); |
| 313 | } |
| 314 | tenxpress_set_bad_lp(efx, bad_lp); |
| 315 | } |
| 316 | return ok; |
| 317 | } |
| 318 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 319 | static void tenxpress_phyxs_loopback(struct efx_nic *efx) |
| 320 | { |
| 321 | int phy_id = efx->mii.phy_id; |
| 322 | int ctrl1, ctrl2; |
| 323 | |
| 324 | ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PHYXS, |
| 325 | PHYXS_TEST1); |
| 326 | if (efx->loopback_mode == LOOPBACK_PHYXS) |
| 327 | ctrl2 |= (1 << LOOPBACK_NEAR_LBN); |
| 328 | else |
| 329 | ctrl2 &= ~(1 << LOOPBACK_NEAR_LBN); |
| 330 | if (ctrl1 != ctrl2) |
| 331 | mdio_clause45_write(efx, phy_id, MDIO_MMD_PHYXS, |
| 332 | PHYXS_TEST1, ctrl2); |
| 333 | } |
| 334 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 335 | static void tenxpress_phy_reconfigure(struct efx_nic *efx) |
| 336 | { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 337 | struct tenxpress_phy_data *phy_data = efx->phy_data; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 338 | bool loop_change = LOOPBACK_OUT_OF(phy_data, efx, |
| 339 | TENXPRESS_LOOPBACKS); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 340 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 341 | if (efx->phy_mode & PHY_MODE_SPECIAL) { |
| 342 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 343 | return; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 344 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 345 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 346 | /* When coming out of transmit disable, coming out of low power |
| 347 | * mode, or moving out of any PHY internal loopback mode, |
| 348 | * perform a special software reset */ |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 349 | if ((efx->phy_mode == PHY_MODE_NORMAL && |
| 350 | phy_data->phy_mode != PHY_MODE_NORMAL) || |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 351 | loop_change) { |
Ben Hutchings | 91ad757 | 2008-05-16 21:14:27 +0100 | [diff] [blame] | 352 | tenxpress_special_reset(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 353 | falcon_reset_xaui(efx); |
| 354 | } |
| 355 | |
| 356 | mdio_clause45_transmit_disable(efx); |
| 357 | mdio_clause45_phy_reconfigure(efx); |
| 358 | tenxpress_phyxs_loopback(efx); |
| 359 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 360 | phy_data->loopback_mode = efx->loopback_mode; |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 361 | phy_data->phy_mode = efx->phy_mode; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 362 | efx->link_up = tenxpress_link_ok(efx, false); |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 363 | efx->link_speed = 10000; |
| 364 | efx->link_fd = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static void tenxpress_phy_clear_interrupt(struct efx_nic *efx) |
| 368 | { |
| 369 | /* Nothing done here - LASI interrupts aren't reliable so poll */ |
| 370 | } |
| 371 | |
| 372 | |
| 373 | /* Poll PHY for interrupt */ |
| 374 | static int tenxpress_phy_check_hw(struct efx_nic *efx) |
| 375 | { |
| 376 | struct tenxpress_phy_data *phy_data = efx->phy_data; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 377 | bool link_ok; |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 378 | int rc = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 379 | |
Ben Hutchings | a620e13 | 2008-09-01 12:50:01 +0100 | [diff] [blame] | 380 | link_ok = tenxpress_link_ok(efx, true); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 381 | |
| 382 | if (link_ok != efx->link_up) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame^] | 383 | falcon_sim_phy_event(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 384 | |
Ben Hutchings | f8b87c1 | 2008-09-01 12:48:17 +0100 | [diff] [blame] | 385 | if (phy_data->phy_mode != PHY_MODE_NORMAL) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 386 | return 0; |
| 387 | |
| 388 | if (atomic_read(&phy_data->bad_crc_count) > crc_error_reset_threshold) { |
| 389 | EFX_ERR(efx, "Resetting XAUI due to too many CRC errors\n"); |
| 390 | falcon_reset_xaui(efx); |
| 391 | atomic_set(&phy_data->bad_crc_count, 0); |
| 392 | } |
| 393 | |
Ben Hutchings | 3e133c4 | 2008-11-04 20:34:56 +0000 | [diff] [blame] | 394 | rc = efx->board_info.monitor(efx); |
| 395 | if (rc) { |
| 396 | EFX_ERR(efx, "Board sensor %s; shutting down PHY\n", |
| 397 | (rc == -ERANGE) ? "reported fault" : "failed"); |
| 398 | if (efx->phy_mode & PHY_MODE_OFF) { |
| 399 | /* Assume that board has shut PHY off */ |
| 400 | phy_data->phy_mode = PHY_MODE_OFF; |
| 401 | } else { |
| 402 | efx->phy_mode |= PHY_MODE_LOW_POWER; |
| 403 | mdio_clause45_set_mmds_lpower(efx, true, |
| 404 | efx->phy_op->mmds); |
| 405 | phy_data->phy_mode |= PHY_MODE_LOW_POWER; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void tenxpress_phy_fini(struct efx_nic *efx) |
| 413 | { |
| 414 | int reg; |
| 415 | |
| 416 | /* Power down the LNPGA */ |
| 417 | reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN); |
| 418 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 419 | PMA_PMD_XCONTROL_REG, reg); |
| 420 | |
| 421 | /* Waiting here ensures that the board fini, which can turn off the |
| 422 | * power to the PHY, won't get run until the LNPGA powerdown has been |
| 423 | * given long enough to complete. */ |
| 424 | schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */ |
| 425 | |
| 426 | kfree(efx->phy_data); |
| 427 | efx->phy_data = NULL; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | /* Set the RX and TX LEDs and Link LED flashing. The other LEDs |
| 432 | * (which probably aren't wired anyway) are left in AUTO mode */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 433 | void tenxpress_phy_blink(struct efx_nic *efx, bool blink) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 434 | { |
| 435 | int reg; |
| 436 | |
| 437 | if (blink) |
| 438 | reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) | |
| 439 | (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) | |
| 440 | (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN); |
| 441 | else |
| 442 | reg = PMA_PMD_LED_DEFAULT; |
| 443 | |
| 444 | mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD, |
| 445 | PMA_PMD_LED_OVERR_REG, reg); |
| 446 | } |
| 447 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 448 | static int tenxpress_phy_test(struct efx_nic *efx) |
| 449 | { |
| 450 | /* BIST is automatically run after a special software reset */ |
| 451 | return tenxpress_special_reset(efx); |
| 452 | } |
| 453 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 454 | struct efx_phy_operations falcon_tenxpress_phy_ops = { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame^] | 455 | .macs = EFX_XMAC, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 456 | .init = tenxpress_phy_init, |
| 457 | .reconfigure = tenxpress_phy_reconfigure, |
| 458 | .check_hw = tenxpress_phy_check_hw, |
| 459 | .fini = tenxpress_phy_fini, |
| 460 | .clear_interrupt = tenxpress_phy_clear_interrupt, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 461 | .test = tenxpress_phy_test, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame^] | 462 | .get_settings = mdio_clause45_get_settings, |
| 463 | .set_settings = mdio_clause45_set_settings, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 464 | .mmds = TENXPRESS_REQUIRED_DEVS, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 465 | .loopbacks = TENXPRESS_LOOPBACKS, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 466 | }; |