blob: 1bc6c48c96ee5ff064f40423c05be0c6d8701b0e [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
Ben Hutchings177dfcd2008-12-12 21:50:08 -08002 * Driver for Solarflare Solarstorm network controllers and boards
Ben Hutchings906bb262009-11-29 15:16:19 +00003 * Copyright 2007-2009 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01004 *
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 Xuda3bc072009-01-18 21:50:16 -080011#include <linux/rtnetlink.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010012#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010014#include "efx.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010015#include "mdio_10g.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000016#include "nic.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010017#include "phy.h"
Ben Hutchings3e6c4532009-10-23 08:30:36 +000018#include "regs.h"
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080019#include "workarounds.h"
20#include "selftest.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010021
Ben Hutchings8fbca792010-09-22 10:00:11 +000022/* We expect these MMDs to be in the package. */
Ben Hutchings68e7f452009-04-29 08:05:08 +000023#define TENXPRESS_REQUIRED_DEVS (MDIO_DEVS_PMAPMD | \
24 MDIO_DEVS_PCS | \
25 MDIO_DEVS_PHYXS | \
26 MDIO_DEVS_AN)
Ben Hutchings8ceee662008-04-27 12:55:59 +010027
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080028#define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
29 (1 << LOOPBACK_PCS) | \
30 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000031 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080032
Ben Hutchings8ceee662008-04-27 12:55:59 +010033/* We complain if we fail to see the link partner as 10G capable this many
34 * times in a row (must be > 1 as sampling the autoneg. registers is racy)
35 */
36#define MAX_BAD_LP_TRIES (5)
37
38/* Extended control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080039#define PMA_PMD_XCONTROL_REG 49152
40#define PMA_PMD_EXT_GMII_EN_LBN 1
41#define PMA_PMD_EXT_GMII_EN_WIDTH 1
42#define PMA_PMD_EXT_CLK_OUT_LBN 2
43#define PMA_PMD_EXT_CLK_OUT_WIDTH 1
Ben Hutchings8fbca792010-09-22 10:00:11 +000044#define PMA_PMD_LNPGA_POWERDOWN_LBN 8
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080045#define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080046#define PMA_PMD_EXT_CLK312_WIDTH 1
47#define PMA_PMD_EXT_LPOWER_LBN 12
48#define PMA_PMD_EXT_LPOWER_WIDTH 1
Steve Hodgson869b5b32009-01-29 17:48:10 +000049#define PMA_PMD_EXT_ROBUST_LBN 14
50#define PMA_PMD_EXT_ROBUST_WIDTH 1
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080051#define PMA_PMD_EXT_SSR_LBN 15
52#define PMA_PMD_EXT_SSR_WIDTH 1
Ben Hutchings8ceee662008-04-27 12:55:59 +010053
54/* extended status register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080055#define PMA_PMD_XSTATUS_REG 49153
Ben Hutchingse762cd72009-06-10 05:30:05 +000056#define PMA_PMD_XSTAT_MDIX_LBN 14
Ben Hutchings8ceee662008-04-27 12:55:59 +010057#define PMA_PMD_XSTAT_FLP_LBN (12)
58
59/* LED control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080060#define PMA_PMD_LED_CTRL_REG 49159
Ben Hutchings8ceee662008-04-27 12:55:59 +010061#define PMA_PMA_LED_ACTIVITY_LBN (3)
62
63/* LED function override register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080064#define PMA_PMD_LED_OVERR_REG 49161
Ben Hutchings8ceee662008-04-27 12:55:59 +010065/* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
66#define PMA_PMD_LED_LINK_LBN (0)
67#define PMA_PMD_LED_SPEED_LBN (2)
68#define PMA_PMD_LED_TX_LBN (4)
69#define PMA_PMD_LED_RX_LBN (6)
70/* Override settings */
71#define PMA_PMD_LED_AUTO (0) /* H/W control */
72#define PMA_PMD_LED_ON (1)
73#define PMA_PMD_LED_OFF (2)
74#define PMA_PMD_LED_FLASH (3)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080075#define PMA_PMD_LED_MASK 3
Ben Hutchings8ceee662008-04-27 12:55:59 +010076/* All LEDs under hardware control */
Ben Hutchings8ceee662008-04-27 12:55:59 +010077/* Green and Amber under hardware control, Red off */
Ben Hutchingsdcf477b2009-11-23 16:02:49 +000078#define SFX7101_PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
Ben Hutchings8ceee662008-04-27 12:55:59 +010079
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080080#define PMA_PMD_SPEED_ENABLE_REG 49192
81#define PMA_PMD_100TX_ADV_LBN 1
82#define PMA_PMD_100TX_ADV_WIDTH 1
83#define PMA_PMD_1000T_ADV_LBN 2
84#define PMA_PMD_1000T_ADV_WIDTH 1
85#define PMA_PMD_10000T_ADV_LBN 3
86#define PMA_PMD_10000T_ADV_WIDTH 1
87#define PMA_PMD_SPEED_LBN 4
88#define PMA_PMD_SPEED_WIDTH 4
Ben Hutchings8ceee662008-04-27 12:55:59 +010089
Ben Hutchings8fbca792010-09-22 10:00:11 +000090/* Misc register defines */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080091#define PCS_CLOCK_CTRL_REG 55297
Ben Hutchings8ceee662008-04-27 12:55:59 +010092#define PLL312_RST_N_LBN 2
93
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080094#define PCS_SOFT_RST2_REG 55302
Ben Hutchings8ceee662008-04-27 12:55:59 +010095#define SERDES_RST_N_LBN 13
96#define XGXS_RST_N_LBN 12
97
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080098#define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
Ben Hutchings8ceee662008-04-27 12:55:59 +010099#define CLK312_EN_LBN 3
100
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100101/* PHYXS registers */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800102#define PHYXS_XCONTROL_REG 49152
103#define PHYXS_RESET_LBN 15
104#define PHYXS_RESET_WIDTH 1
105
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100106#define PHYXS_TEST1 (49162)
107#define LOOPBACK_NEAR_LBN (8)
108#define LOOPBACK_NEAR_WIDTH (1)
109
Ben Hutchings8ceee662008-04-27 12:55:59 +0100110/* Boot status register */
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000111#define PCS_BOOT_STATUS_REG 53248
112#define PCS_BOOT_FATAL_ERROR_LBN 0
113#define PCS_BOOT_PROGRESS_LBN 1
114#define PCS_BOOT_PROGRESS_WIDTH 2
115#define PCS_BOOT_PROGRESS_INIT 0
116#define PCS_BOOT_PROGRESS_WAIT_MDIO 1
117#define PCS_BOOT_PROGRESS_CHECKSUM 2
118#define PCS_BOOT_PROGRESS_JUMP 3
119#define PCS_BOOT_DOWNLOAD_WAIT_LBN 3
120#define PCS_BOOT_CODE_STARTED_LBN 4
Ben Hutchings8ceee662008-04-27 12:55:59 +0100121
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800122/* 100M/1G PHY registers */
123#define GPHY_XCONTROL_REG 49152
124#define GPHY_ISOLATE_LBN 10
125#define GPHY_ISOLATE_WIDTH 1
126#define GPHY_DUPLEX_LBN 8
127#define GPHY_DUPLEX_WIDTH 1
128#define GPHY_LOOPBACK_NEAR_LBN 14
129#define GPHY_LOOPBACK_NEAR_WIDTH 1
130
131#define C22EXT_STATUS_REG 49153
132#define C22EXT_STATUS_LINK_LBN 2
133#define C22EXT_STATUS_LINK_WIDTH 1
134
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000135#define C22EXT_MSTSLV_CTRL 49161
136#define C22EXT_MSTSLV_CTRL_ADV_1000_HD_LBN 8
137#define C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN 9
138
139#define C22EXT_MSTSLV_STATUS 49162
140#define C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN 10
141#define C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN 11
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800142
Ben Hutchings8ceee662008-04-27 12:55:59 +0100143/* Time to wait between powering down the LNPGA and turning off the power
144 * rails */
145#define LNPGA_PDOWN_WAIT (HZ / 5)
146
Ben Hutchings8ceee662008-04-27 12:55:59 +0100147struct tenxpress_phy_data {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100148 enum efx_loopback_mode loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100149 enum efx_phy_mode phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100150 int bad_lp_tries;
151};
152
Ben Hutchings8ceee662008-04-27 12:55:59 +0100153static int tenxpress_init(struct efx_nic *efx)
154{
Ben Hutchings8fbca792010-09-22 10:00:11 +0000155 /* Enable 312.5 MHz clock */
156 efx_mdio_write(efx, MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
157 1 << CLK312_EN_LBN);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100158
Ben Hutchings8ceee662008-04-27 12:55:59 +0100159 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
Ben Hutchings8fbca792010-09-22 10:00:11 +0000160 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG,
161 1 << PMA_PMA_LED_ACTIVITY_LBN, true);
162 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG,
163 SFX7101_PMA_PMD_LED_DEFAULT);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100164
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000165 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100166}
167
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000168static int tenxpress_phy_probe(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100169{
170 struct tenxpress_phy_data *phy_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100171
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000172 /* Allocate phy private storage */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100173 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
Ben Hutchings9b7bfc42008-05-16 21:20:20 +0100174 if (!phy_data)
175 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100176 efx->phy_data = phy_data;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100177 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100178
Ben Hutchings8fbca792010-09-22 10:00:11 +0000179 efx->mdio.mmds = TENXPRESS_REQUIRED_DEVS;
180 efx->mdio.mode_support = MDIO_SUPPORTS_C45;
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000181
Ben Hutchings8fbca792010-09-22 10:00:11 +0000182 efx->loopback_modes = SFX7101_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000183
Ben Hutchings8fbca792010-09-22 10:00:11 +0000184 efx->link_advertising = (ADVERTISED_TP | ADVERTISED_Autoneg |
185 ADVERTISED_10000baseT_Full);
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000186
187 return 0;
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000188}
189
190static int tenxpress_phy_init(struct efx_nic *efx)
191{
192 int rc;
193
194 falcon_board(efx)->type->init_phy(efx);
195
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800196 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000197 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800198 if (rc < 0)
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000199 return rc;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800200
Ben Hutchings68e7f452009-04-29 08:05:08 +0000201 rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800202 if (rc < 0)
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000203 return rc;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800204 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100205
206 rc = tenxpress_init(efx);
207 if (rc < 0)
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000208 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100209
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000210 /* Reinitialise flow control settings */
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000211 efx_link_set_wanted_fc(efx, efx->wanted_fc);
212 efx_mdio_an_reconfigure(efx);
Ben Hutchingsc6342632009-10-12 09:27:07 +0000213
Ben Hutchings8ceee662008-04-27 12:55:59 +0100214 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
215
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800216 /* Let XGXS and SerDes out of reset */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100217 falcon_reset_xaui(efx);
218
219 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100220}
221
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800222/* Perform a "special software reset" on the PHY. The caller is
223 * responsible for saving and restoring the PHY hardware registers
224 * properly, and masking/unmasking LASI */
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100225static int tenxpress_special_reset(struct efx_nic *efx)
226{
227 int rc, reg;
228
Ben Hutchings8fbca792010-09-22 10:00:11 +0000229 /* The XGMAC clock is driven from the SFX7101 312MHz clock, so
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100230 * a special software reset can glitch the XGMAC sufficiently for stats
Ben Hutchings1974cc22009-01-29 18:00:07 +0000231 * requests to fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000232 falcon_stop_nic_stats(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100233
234 /* Initiate reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000235 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100236 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000237 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100238
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100239 mdelay(200);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100240
241 /* Wait for the blocks to come out of reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000242 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100243 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000244 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100245
246 /* Try and reconfigure the device */
247 rc = tenxpress_init(efx);
248 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000249 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100250
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800251 /* Wait for the XGXS state machine to churn */
252 mdelay(10);
Ben Hutchings1974cc22009-01-29 18:00:07 +0000253out:
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000254 falcon_start_nic_stats(efx);
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100255 return rc;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100256}
257
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800258static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100259{
260 struct tenxpress_phy_data *pd = efx->phy_data;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800261 bool bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100262 int reg;
263
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800264 if (link_ok) {
265 bad_lp = false;
266 } else {
267 /* Check that AN has started but not completed. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000268 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
269 if (!(reg & MDIO_AN_STAT1_LPABLE))
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800270 return; /* LP status is unknown */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000271 bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800272 if (bad_lp)
273 pd->bad_lp_tries++;
274 }
275
Ben Hutchings8ceee662008-04-27 12:55:59 +0100276 /* Nothing to do if all is well and was previously so. */
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800277 if (!pd->bad_lp_tries)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100278 return;
279
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800280 /* Use the RX (red) LED as an error indicator once we've seen AN
281 * failure several times in a row, and also log a message. */
282 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000283 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
284 PMA_PMD_LED_OVERR_REG);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800285 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
286 if (!bad_lp) {
287 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
288 } else {
289 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
Ben Hutchings62776d02010-06-23 11:30:07 +0000290 netif_err(efx, link, efx->net_dev,
291 "appears to be plugged into a port"
292 " that is not 10GBASE-T capable. The PHY"
293 " supports 10GBASE-T ONLY, so no link can"
294 " be established\n");
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800295 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000296 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
297 PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800298 pd->bad_lp_tries = bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100299 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100300}
301
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800302static bool sfx7101_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100303{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000304 return efx_mdio_links_ok(efx,
305 MDIO_DEVS_PMAPMD |
306 MDIO_DEVS_PCS |
307 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800308}
309
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800310static void tenxpress_ext_loopback(struct efx_nic *efx)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100311{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000312 efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
313 1 << LOOPBACK_NEAR_LBN,
314 efx->loopback_mode == LOOPBACK_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800315}
316
317static void tenxpress_low_power(struct efx_nic *efx)
318{
Ben Hutchings8fbca792010-09-22 10:00:11 +0000319 efx_mdio_set_mmds_lpower(
320 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
321 TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100322}
323
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000324static int tenxpress_phy_reconfigure(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100325{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100326 struct tenxpress_phy_data *phy_data = efx->phy_data;
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000327 bool phy_mode_change, loop_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100328
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800329 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100330 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000331 return 0;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100332 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100333
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800334 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
335 phy_data->phy_mode != PHY_MODE_NORMAL);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000336 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, LOOPBACKS_EXTERNAL(efx)) ||
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800337 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
338
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000339 if (loop_reset || phy_mode_change) {
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000340 tenxpress_special_reset(efx);
Ben Hutchings8fbca792010-09-22 10:00:11 +0000341 falcon_reset_xaui(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100342 }
343
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000344 tenxpress_low_power(efx);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000345 efx_mdio_transmit_disable(efx);
346 efx_mdio_phy_reconfigure(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800347 tenxpress_ext_loopback(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000348 efx_mdio_an_reconfigure(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100349
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100350 phy_data->loopback_mode = efx->loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100351 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000352
353 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100354}
355
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000356static void
357tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd);
358
359/* Poll for link state changes */
360static bool tenxpress_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100361{
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000362 struct efx_link_state old_state = efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100363
Ben Hutchings8fbca792010-09-22 10:00:11 +0000364 efx->link_state.up = sfx7101_link_ok(efx);
365 efx->link_state.speed = 10000;
366 efx->link_state.fd = true;
367 efx->link_state.fc = efx_mdio_get_pause(efx);
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000368
Ben Hutchings8fbca792010-09-22 10:00:11 +0000369 sfx7101_check_bad_lp(efx, efx->link_state.up);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100370
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000371 return !efx_link_state_equal(&efx->link_state, &old_state);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100372}
373
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000374static void sfx7101_phy_fini(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100375{
376 int reg;
377
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000378 /* Power down the LNPGA */
379 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
380 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
381
382 /* Waiting here ensures that the board fini, which can turn
383 * off the power to the PHY, won't get run until the LNPGA
384 * powerdown has been given long enough to complete. */
385 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
386}
387
388static void tenxpress_phy_remove(struct efx_nic *efx)
389{
Ben Hutchings8ceee662008-04-27 12:55:59 +0100390 kfree(efx->phy_data);
391 efx->phy_data = NULL;
392}
393
394
Ben Hutchings398468e2009-11-23 16:03:45 +0000395/* Override the RX, TX and link LEDs */
396void tenxpress_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100397{
398 int reg;
399
Ben Hutchings398468e2009-11-23 16:03:45 +0000400 switch (mode) {
401 case EFX_LED_OFF:
402 reg = (PMA_PMD_LED_OFF << PMA_PMD_LED_TX_LBN) |
403 (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN) |
404 (PMA_PMD_LED_OFF << PMA_PMD_LED_LINK_LBN);
405 break;
406 case EFX_LED_ON:
407 reg = (PMA_PMD_LED_ON << PMA_PMD_LED_TX_LBN) |
408 (PMA_PMD_LED_ON << PMA_PMD_LED_RX_LBN) |
409 (PMA_PMD_LED_ON << PMA_PMD_LED_LINK_LBN);
410 break;
411 default:
Ben Hutchings8fbca792010-09-22 10:00:11 +0000412 reg = SFX7101_PMA_PMD_LED_DEFAULT;
Ben Hutchings398468e2009-11-23 16:03:45 +0000413 break;
414 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100415
Ben Hutchings68e7f452009-04-29 08:05:08 +0000416 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100417}
418
Ben Hutchings307505e2008-12-26 13:48:00 -0800419static const char *const sfx7101_test_names[] = {
Ben Hutchings17967212008-12-26 13:47:25 -0800420 "bist"
421};
422
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000423static const char *sfx7101_test_name(struct efx_nic *efx, unsigned int index)
424{
425 if (index < ARRAY_SIZE(sfx7101_test_names))
426 return sfx7101_test_names[index];
427 return NULL;
428}
429
Ben Hutchings17967212008-12-26 13:47:25 -0800430static int
Ben Hutchings307505e2008-12-26 13:48:00 -0800431sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100432{
Ben Hutchings17967212008-12-26 13:47:25 -0800433 int rc;
434
435 if (!(flags & ETH_TEST_FL_OFFLINE))
436 return 0;
437
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100438 /* BIST is automatically run after a special software reset */
Ben Hutchings17967212008-12-26 13:47:25 -0800439 rc = tenxpress_special_reset(efx);
440 results[0] = rc ? -1 : 1;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000441
442 efx_mdio_an_reconfigure(efx);
443
Ben Hutchings17967212008-12-26 13:47:25 -0800444 return rc;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100445}
446
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000447static void
448tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800449{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000450 u32 adv = 0, lpa = 0;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800451 int reg;
452
Ben Hutchings68e7f452009-04-29 08:05:08 +0000453 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
454 if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000455 adv |= ADVERTISED_10000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000456 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
457 if (reg & MDIO_AN_10GBT_STAT_LP10G)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800458 lpa |= ADVERTISED_10000baseT_Full;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800459
Ben Hutchings68e7f452009-04-29 08:05:08 +0000460 mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800461
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000462 /* In loopback, the PHY automatically brings up the correct interface,
463 * but doesn't advertise the correct speed. So override it */
Ben Hutchings8fbca792010-09-22 10:00:11 +0000464 if (LOOPBACK_EXTERNAL(efx))
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000465 ecmd->speed = SPEED_10000;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100466}
467
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000468static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100469{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000470 if (!ecmd->autoneg)
471 return -EINVAL;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800472
Ben Hutchings68e7f452009-04-29 08:05:08 +0000473 return efx_mdio_set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100474}
475
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000476static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800477{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000478 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
479 MDIO_AN_10GBT_CTRL_ADV10G,
480 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000481}
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800482
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800483struct efx_phy_operations falcon_sfx7101_phy_ops = {
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000484 .probe = tenxpress_phy_probe,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100485 .init = tenxpress_phy_init,
486 .reconfigure = tenxpress_phy_reconfigure,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800487 .poll = tenxpress_phy_poll,
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000488 .fini = sfx7101_phy_fini,
489 .remove = tenxpress_phy_remove,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000490 .get_settings = tenxpress_get_settings,
491 .set_settings = tenxpress_set_settings,
492 .set_npage_adv = sfx7101_set_npage_adv,
Ben Hutchings4f16c072010-02-03 09:30:50 +0000493 .test_alive = efx_mdio_test_alive,
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000494 .test_name = sfx7101_test_name,
Ben Hutchings307505e2008-12-26 13:48:00 -0800495 .run_tests = sfx7101_run_tests,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800496};