blob: ca11572a49a93cab33554bdf49d422155c194f46 [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>
13#include "efx.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010014#include "mdio_10g.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000015#include "nic.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010016#include "phy.h"
Ben Hutchings3e6c4532009-10-23 08:30:36 +000017#include "regs.h"
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080018#include "workarounds.h"
19#include "selftest.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010020
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080021/* 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 Hutchings68e7f452009-04-29 08:05:08 +000025#define TENXPRESS_REQUIRED_DEVS (MDIO_DEVS_PMAPMD | \
26 MDIO_DEVS_PCS | \
27 MDIO_DEVS_PHYXS | \
28 MDIO_DEVS_AN)
Ben Hutchings8ceee662008-04-27 12:55:59 +010029
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080030#define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
31 (1 << LOOPBACK_PCS) | \
32 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000033 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080034
35#define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \
36 (1 << LOOPBACK_PHYXS) | \
37 (1 << LOOPBACK_PCS) | \
38 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000039 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchings3273c2e2008-05-07 13:36:19 +010040
Ben Hutchings8ceee662008-04-27 12:55:59 +010041/* 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 Hutchingse6fa2eb2008-12-12 22:00:17 -080047#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 Hodgson869b5b32009-01-29 17:48:10 +000058#define PMA_PMD_EXT_ROBUST_LBN 14
59#define PMA_PMD_EXT_ROBUST_WIDTH 1
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080060#define PMA_PMD_EXT_SSR_LBN 15
61#define PMA_PMD_EXT_SSR_WIDTH 1
Ben Hutchings8ceee662008-04-27 12:55:59 +010062
63/* extended status register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080064#define PMA_PMD_XSTATUS_REG 49153
Ben Hutchingse762cd72009-06-10 05:30:05 +000065#define PMA_PMD_XSTAT_MDIX_LBN 14
Ben Hutchings8ceee662008-04-27 12:55:59 +010066#define PMA_PMD_XSTAT_FLP_LBN (12)
67
68/* LED control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080069#define PMA_PMD_LED_CTRL_REG 49159
Ben Hutchings8ceee662008-04-27 12:55:59 +010070#define PMA_PMA_LED_ACTIVITY_LBN (3)
71
72/* LED function override register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080073#define PMA_PMD_LED_OVERR_REG 49161
Ben Hutchings8ceee662008-04-27 12:55:59 +010074/* 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 Hutchings04cc8ca2008-12-12 21:50:46 -080084#define PMA_PMD_LED_MASK 3
Ben Hutchings8ceee662008-04-27 12:55:59 +010085/* All LEDs under hardware control */
Ben Hutchingsdcf477b2009-11-23 16:02:49 +000086#define SFT9001_PMA_PMD_LED_DEFAULT 0
Ben Hutchings8ceee662008-04-27 12:55:59 +010087/* Green and Amber under hardware control, Red off */
Ben Hutchingsdcf477b2009-11-23 16:02:49 +000088#define SFX7101_PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
Ben Hutchings8ceee662008-04-27 12:55:59 +010089
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080090#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 Hutchings8ceee662008-04-27 12:55:59 +010099
Ben Hutchings307505e2008-12-26 13:48:00 -0800100/* 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 Hutchingse6fa2eb2008-12-12 22:00:17 -0800119/* 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 Hutchings3273c2e2008-05-07 13:36:19 +0100123
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800124/* Misc register defines - SFX7101 only */
125#define PCS_CLOCK_CTRL_REG 55297
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126#define PLL312_RST_N_LBN 2
127
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800128#define PCS_SOFT_RST2_REG 55302
Ben Hutchings8ceee662008-04-27 12:55:59 +0100129#define SERDES_RST_N_LBN 13
130#define XGXS_RST_N_LBN 12
131
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800132#define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100133#define CLK312_EN_LBN 3
134
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100135/* PHYXS registers */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800136#define PHYXS_XCONTROL_REG 49152
137#define PHYXS_RESET_LBN 15
138#define PHYXS_RESET_WIDTH 1
139
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100140#define PHYXS_TEST1 (49162)
141#define LOOPBACK_NEAR_LBN (8)
142#define LOOPBACK_NEAR_WIDTH (1)
143
Ben Hutchings8ceee662008-04-27 12:55:59 +0100144/* Boot status register */
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000145#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 Hutchings8ceee662008-04-27 12:55:59 +0100155
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800156/* 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 Hutchingsaf4ad9b2009-01-29 17:59:37 +0000169#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 Hutchingse6fa2eb2008-12-12 22:00:17 -0800176
Ben Hutchings8ceee662008-04-27 12:55:59 +0100177/* Time to wait between powering down the LNPGA and turning off the power
178 * rails */
179#define LNPGA_PDOWN_WAIT (HZ / 5)
180
Ben Hutchings8ceee662008-04-27 12:55:59 +0100181struct tenxpress_phy_data {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100182 enum efx_loopback_mode loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100183 enum efx_phy_mode phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100184 int bad_lp_tries;
185};
186
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800187static 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 Hutchings68e7f452009-04-29 08:05:08 +0000193 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 Hutchingse6fa2eb2008-12-12 22:00:17 -0800195}
196
197static 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));
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000202 int rc;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800203
204 rtnl_lock();
Ben Hutchings68e7f452009-04-29 08:05:08 +0000205 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TXPWR,
206 MDIO_PMA_10GBT_TXPWR_SHORT,
207 count != 0 && *buf != '0');
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000208 rc = efx_reconfigure_port(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800209 rtnl_unlock();
210
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000211 return rc < 0 ? rc : (ssize_t)count;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800212}
213
214static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
215 set_phy_short_reach);
216
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000217int sft9001_wait_boot(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100218{
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000219 unsigned long timeout = jiffies + HZ + 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100220 int boot_stat;
221
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000222 for (;;) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000223 boot_stat = efx_mdio_read(efx, MDIO_MMD_PCS,
224 PCS_BOOT_STATUS_REG);
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000225 if (boot_stat >= 0) {
226 EFX_LOG(efx, "PHY boot status = %#x\n", boot_stat);
227 switch (boot_stat &
228 ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
229 (3 << PCS_BOOT_PROGRESS_LBN) |
230 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN) |
231 (1 << PCS_BOOT_CODE_STARTED_LBN))) {
232 case ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
233 (PCS_BOOT_PROGRESS_CHECKSUM <<
234 PCS_BOOT_PROGRESS_LBN)):
235 case ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
236 (PCS_BOOT_PROGRESS_INIT <<
237 PCS_BOOT_PROGRESS_LBN) |
238 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN)):
239 return -EINVAL;
240 case ((PCS_BOOT_PROGRESS_WAIT_MDIO <<
241 PCS_BOOT_PROGRESS_LBN) |
242 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN)):
243 return (efx->phy_mode & PHY_MODE_SPECIAL) ?
244 0 : -EIO;
245 case ((PCS_BOOT_PROGRESS_JUMP <<
246 PCS_BOOT_PROGRESS_LBN) |
247 (1 << PCS_BOOT_CODE_STARTED_LBN)):
248 case ((PCS_BOOT_PROGRESS_JUMP <<
249 PCS_BOOT_PROGRESS_LBN) |
250 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN) |
251 (1 << PCS_BOOT_CODE_STARTED_LBN)):
252 return (efx->phy_mode & PHY_MODE_SPECIAL) ?
253 -EIO : 0;
254 default:
255 if (boot_stat & (1 << PCS_BOOT_FATAL_ERROR_LBN))
256 return -EIO;
257 break;
258 }
259 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100260
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000261 if (time_after_eq(jiffies, timeout))
262 return -ETIMEDOUT;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100263
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000264 msleep(50);
265 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100266}
267
Ben Hutchings8ceee662008-04-27 12:55:59 +0100268static int tenxpress_init(struct efx_nic *efx)
269{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800270 int reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100271
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800272 if (efx->phy_type == PHY_TYPE_SFX7101) {
273 /* Enable 312.5 MHz clock */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000274 efx_mdio_write(efx, MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
275 1 << CLK312_EN_LBN);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800276 } else {
277 /* Enable 312.5 MHz clock and GMII */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000278 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800279 reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
280 (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
Steve Hodgson869b5b32009-01-29 17:48:10 +0000281 (1 << PMA_PMD_EXT_CLK312_LBN) |
282 (1 << PMA_PMD_EXT_ROBUST_LBN));
283
Ben Hutchings68e7f452009-04-29 08:05:08 +0000284 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
285 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT,
286 GPHY_XCONTROL_REG, 1 << GPHY_ISOLATE_LBN,
287 false);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800288 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100289
Ben Hutchings8ceee662008-04-27 12:55:59 +0100290 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800291 if (efx->phy_type == PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000292 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG,
293 1 << PMA_PMA_LED_ACTIVITY_LBN, true);
294 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG,
Ben Hutchingsdcf477b2009-11-23 16:02:49 +0000295 SFX7101_PMA_PMD_LED_DEFAULT);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800296 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100297
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000298 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100299}
300
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000301static int sfx7101_phy_probe(struct efx_nic *efx)
302{
303 efx->mdio.mmds = TENXPRESS_REQUIRED_DEVS;
304 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
305 efx->loopback_modes = SFX7101_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
306 return 0;
307}
308
309static int sft9001_phy_probe(struct efx_nic *efx)
310{
311 efx->mdio.mmds = TENXPRESS_REQUIRED_DEVS;
312 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
313 efx->loopback_modes = (SFT9001_LOOPBACKS | FALCON_XMAC_LOOPBACKS |
314 FALCON_GMAC_LOOPBACKS);
315 return 0;
316}
317
Ben Hutchings8ceee662008-04-27 12:55:59 +0100318static int tenxpress_phy_init(struct efx_nic *efx)
319{
320 struct tenxpress_phy_data *phy_data;
321 int rc = 0;
322
Ben Hutchings44838a42009-11-25 16:09:41 +0000323 falcon_board(efx)->type->init_phy(efx);
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000324
Ben Hutchings8ceee662008-04-27 12:55:59 +0100325 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
Ben Hutchings9b7bfc42008-05-16 21:20:20 +0100326 if (!phy_data)
327 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100328 efx->phy_data = phy_data;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100329 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100330
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800331 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
332 if (efx->phy_type == PHY_TYPE_SFT9001A) {
333 int reg;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000334 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
335 PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800336 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000337 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
338 PMA_PMD_XCONTROL_REG, reg);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800339 mdelay(200);
340 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100341
Ben Hutchings68e7f452009-04-29 08:05:08 +0000342 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800343 if (rc < 0)
344 goto fail;
345
Ben Hutchings68e7f452009-04-29 08:05:08 +0000346 rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800347 if (rc < 0)
348 goto fail;
349 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100350
351 rc = tenxpress_init(efx);
352 if (rc < 0)
353 goto fail;
354
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000355 /* Initialise advertising flags */
356 efx->link_advertising = (ADVERTISED_TP | ADVERTISED_Autoneg |
357 ADVERTISED_10000baseT_Full);
358 if (efx->phy_type != PHY_TYPE_SFX7101)
359 efx->link_advertising |= (ADVERTISED_1000baseT_Full |
360 ADVERTISED_100baseT_Full);
361 efx_link_set_wanted_fc(efx, efx->wanted_fc);
362 efx_mdio_an_reconfigure(efx);
Ben Hutchingsc6342632009-10-12 09:27:07 +0000363
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800364 if (efx->phy_type == PHY_TYPE_SFT9001B) {
365 rc = device_create_file(&efx->pci_dev->dev,
366 &dev_attr_phy_short_reach);
367 if (rc)
368 goto fail;
369 }
370
Ben Hutchings8ceee662008-04-27 12:55:59 +0100371 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
372
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800373 /* Let XGXS and SerDes out of reset */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100374 falcon_reset_xaui(efx);
375
376 return 0;
377
378 fail:
379 kfree(efx->phy_data);
380 efx->phy_data = NULL;
381 return rc;
382}
383
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800384/* Perform a "special software reset" on the PHY. The caller is
385 * responsible for saving and restoring the PHY hardware registers
386 * properly, and masking/unmasking LASI */
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100387static int tenxpress_special_reset(struct efx_nic *efx)
388{
389 int rc, reg;
390
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100391 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
392 * a special software reset can glitch the XGMAC sufficiently for stats
Ben Hutchings1974cc22009-01-29 18:00:07 +0000393 * requests to fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000394 falcon_stop_nic_stats(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100395
396 /* Initiate reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000397 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100398 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000399 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100400
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100401 mdelay(200);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100402
403 /* Wait for the blocks to come out of reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000404 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100405 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000406 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100407
408 /* Try and reconfigure the device */
409 rc = tenxpress_init(efx);
410 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000411 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100412
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800413 /* Wait for the XGXS state machine to churn */
414 mdelay(10);
Ben Hutchings1974cc22009-01-29 18:00:07 +0000415out:
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000416 falcon_start_nic_stats(efx);
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100417 return rc;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100418}
419
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800420static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100421{
422 struct tenxpress_phy_data *pd = efx->phy_data;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800423 bool bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100424 int reg;
425
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800426 if (link_ok) {
427 bad_lp = false;
428 } else {
429 /* Check that AN has started but not completed. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000430 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
431 if (!(reg & MDIO_AN_STAT1_LPABLE))
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800432 return; /* LP status is unknown */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000433 bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800434 if (bad_lp)
435 pd->bad_lp_tries++;
436 }
437
Ben Hutchings8ceee662008-04-27 12:55:59 +0100438 /* Nothing to do if all is well and was previously so. */
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800439 if (!pd->bad_lp_tries)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100440 return;
441
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800442 /* Use the RX (red) LED as an error indicator once we've seen AN
443 * failure several times in a row, and also log a message. */
444 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000445 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
446 PMA_PMD_LED_OVERR_REG);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800447 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
448 if (!bad_lp) {
449 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
450 } else {
451 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
452 EFX_ERR(efx, "appears to be plugged into a port"
453 " that is not 10GBASE-T capable. The PHY"
454 " supports 10GBASE-T ONLY, so no link can"
455 " be established\n");
456 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000457 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
458 PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800459 pd->bad_lp_tries = bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100460 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100461}
462
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800463static bool sfx7101_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100464{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000465 return efx_mdio_links_ok(efx,
466 MDIO_DEVS_PMAPMD |
467 MDIO_DEVS_PCS |
468 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800469}
470
471static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
472{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800473 u32 reg;
474
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800475 if (efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800476 return false;
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800477 else if (efx->loopback_mode == LOOPBACK_GPHY)
478 return true;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800479 else if (efx->loopback_mode)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000480 return efx_mdio_links_ok(efx,
481 MDIO_DEVS_PMAPMD |
482 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800483
484 /* We must use the same definition of link state as LASI,
485 * otherwise we can miss a link state transition
486 */
487 if (ecmd->speed == 10000) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000488 reg = efx_mdio_read(efx, MDIO_MMD_PCS, MDIO_PCS_10GBRT_STAT1);
489 return reg & MDIO_PCS_10GBRT_STAT1_BLKLK;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800490 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000491 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_STATUS_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800492 return reg & (1 << C22EXT_STATUS_LINK_LBN);
493 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100494}
495
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800496static void tenxpress_ext_loopback(struct efx_nic *efx)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100497{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000498 efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
499 1 << LOOPBACK_NEAR_LBN,
500 efx->loopback_mode == LOOPBACK_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800501 if (efx->phy_type != PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000502 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, GPHY_XCONTROL_REG,
503 1 << GPHY_LOOPBACK_NEAR_LBN,
504 efx->loopback_mode == LOOPBACK_GPHY);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800505}
506
507static void tenxpress_low_power(struct efx_nic *efx)
508{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800509 if (efx->phy_type == PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000510 efx_mdio_set_mmds_lpower(
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800511 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
512 TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100513 else
Ben Hutchings68e7f452009-04-29 08:05:08 +0000514 efx_mdio_set_flag(
515 efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG,
516 1 << PMA_PMD_EXT_LPOWER_LBN,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800517 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100518}
519
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000520static int tenxpress_phy_reconfigure(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100521{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100522 struct tenxpress_phy_data *phy_data = efx->phy_data;
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000523 bool phy_mode_change, loop_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100524
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800525 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100526 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000527 return 0;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100528 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100529
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800530 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
531 phy_data->phy_mode != PHY_MODE_NORMAL);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000532 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, LOOPBACKS_EXTERNAL(efx)) ||
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800533 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
534
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000535 if (loop_reset || phy_mode_change) {
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000536 tenxpress_special_reset(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800537
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000538 /* Reset XAUI if we were in 10G, and are staying
539 * in 10G. If we're moving into and out of 10G
540 * then xaui will be reset anyway */
541 if (EFX_IS10G(efx))
542 falcon_reset_xaui(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100543 }
544
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000545 tenxpress_low_power(efx);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000546 efx_mdio_transmit_disable(efx);
547 efx_mdio_phy_reconfigure(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800548 tenxpress_ext_loopback(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000549 efx_mdio_an_reconfigure(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100550
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100551 phy_data->loopback_mode = efx->loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100552 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000553
554 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100555}
556
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000557static void
558tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd);
559
560/* Poll for link state changes */
561static bool tenxpress_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100562{
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000563 struct efx_link_state old_state = efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100564
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800565 if (efx->phy_type == PHY_TYPE_SFX7101) {
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000566 efx->link_state.up = sfx7101_link_ok(efx);
567 efx->link_state.speed = 10000;
568 efx->link_state.fd = true;
569 efx->link_state.fc = efx_mdio_get_pause(efx);
570
571 sfx7101_check_bad_lp(efx, efx->link_state.up);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800572 } else {
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000573 struct ethtool_cmd ecmd;
574
575 /* Check the LASI alarm first */
576 if (efx->loopback_mode == LOOPBACK_NONE &&
577 !(efx_mdio_read(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_STAT) &
578 MDIO_PMA_LASI_LSALARM))
579 return false;
580
581 tenxpress_get_settings(efx, &ecmd);
582
583 efx->link_state.up = sft9001_link_ok(efx, &ecmd);
584 efx->link_state.speed = ecmd.speed;
585 efx->link_state.fd = (ecmd.duplex == DUPLEX_FULL);
586 efx->link_state.fc = efx_mdio_get_pause(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800587 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100588
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000589 return !efx_link_state_equal(&efx->link_state, &old_state);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100590}
591
592static void tenxpress_phy_fini(struct efx_nic *efx)
593{
594 int reg;
595
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800596 if (efx->phy_type == PHY_TYPE_SFT9001B)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800597 device_remove_file(&efx->pci_dev->dev,
598 &dev_attr_phy_short_reach);
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800599
600 if (efx->phy_type == PHY_TYPE_SFX7101) {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800601 /* Power down the LNPGA */
602 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000603 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100604
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800605 /* Waiting here ensures that the board fini, which can turn
606 * off the power to the PHY, won't get run until the LNPGA
607 * powerdown has been given long enough to complete. */
608 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
609 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100610
611 kfree(efx->phy_data);
612 efx->phy_data = NULL;
613}
614
615
Ben Hutchings398468e2009-11-23 16:03:45 +0000616/* Override the RX, TX and link LEDs */
617void tenxpress_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100618{
619 int reg;
620
Ben Hutchings398468e2009-11-23 16:03:45 +0000621 switch (mode) {
622 case EFX_LED_OFF:
623 reg = (PMA_PMD_LED_OFF << PMA_PMD_LED_TX_LBN) |
624 (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN) |
625 (PMA_PMD_LED_OFF << PMA_PMD_LED_LINK_LBN);
626 break;
627 case EFX_LED_ON:
628 reg = (PMA_PMD_LED_ON << PMA_PMD_LED_TX_LBN) |
629 (PMA_PMD_LED_ON << PMA_PMD_LED_RX_LBN) |
630 (PMA_PMD_LED_ON << PMA_PMD_LED_LINK_LBN);
631 break;
632 default:
Ben Hutchingsdcf477b2009-11-23 16:02:49 +0000633 if (efx->phy_type == PHY_TYPE_SFX7101)
634 reg = SFX7101_PMA_PMD_LED_DEFAULT;
635 else
636 reg = SFT9001_PMA_PMD_LED_DEFAULT;
Ben Hutchings398468e2009-11-23 16:03:45 +0000637 break;
638 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100639
Ben Hutchings68e7f452009-04-29 08:05:08 +0000640 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100641}
642
Ben Hutchings307505e2008-12-26 13:48:00 -0800643static const char *const sfx7101_test_names[] = {
Ben Hutchings17967212008-12-26 13:47:25 -0800644 "bist"
645};
646
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000647static const char *sfx7101_test_name(struct efx_nic *efx, unsigned int index)
648{
649 if (index < ARRAY_SIZE(sfx7101_test_names))
650 return sfx7101_test_names[index];
651 return NULL;
652}
653
Ben Hutchings17967212008-12-26 13:47:25 -0800654static int
Ben Hutchings307505e2008-12-26 13:48:00 -0800655sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100656{
Ben Hutchings17967212008-12-26 13:47:25 -0800657 int rc;
658
659 if (!(flags & ETH_TEST_FL_OFFLINE))
660 return 0;
661
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100662 /* BIST is automatically run after a special software reset */
Ben Hutchings17967212008-12-26 13:47:25 -0800663 rc = tenxpress_special_reset(efx);
664 results[0] = rc ? -1 : 1;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000665
666 efx_mdio_an_reconfigure(efx);
667
Ben Hutchings17967212008-12-26 13:47:25 -0800668 return rc;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100669}
670
Ben Hutchings307505e2008-12-26 13:48:00 -0800671static const char *const sft9001_test_names[] = {
672 "bist",
673 "cable.pairA.status",
674 "cable.pairB.status",
675 "cable.pairC.status",
676 "cable.pairD.status",
677 "cable.pairA.length",
678 "cable.pairB.length",
679 "cable.pairC.length",
680 "cable.pairD.length",
681};
682
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000683static const char *sft9001_test_name(struct efx_nic *efx, unsigned int index)
684{
685 if (index < ARRAY_SIZE(sft9001_test_names))
686 return sft9001_test_names[index];
687 return NULL;
688}
689
Ben Hutchings307505e2008-12-26 13:48:00 -0800690static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
691{
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000692 int rc = 0, rc2, i, ctrl_reg, res_reg;
Ben Hutchings307505e2008-12-26 13:48:00 -0800693
Ben Hutchings307505e2008-12-26 13:48:00 -0800694 /* Initialise cable diagnostic results to unknown failure */
695 for (i = 1; i < 9; ++i)
696 results[i] = -1;
697
698 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
699 * A cable fault is not a self-test failure, but a timeout is. */
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000700 ctrl_reg = ((1 << CDIAG_CTRL_IMMED_LBN) |
701 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
702 if (flags & ETH_TEST_FL_OFFLINE) {
703 /* Break the link in order to run full diagnostics. We
704 * must reset the PHY to resume normal service. */
705 ctrl_reg |= (1 << CDIAG_CTRL_BRK_LINK_LBN);
706 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000707 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG,
708 ctrl_reg);
Ben Hutchings307505e2008-12-26 13:48:00 -0800709 i = 0;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000710 while (efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG) &
Ben Hutchings307505e2008-12-26 13:48:00 -0800711 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
712 if (++i == 50) {
713 rc = -ETIMEDOUT;
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000714 goto out;
Ben Hutchings307505e2008-12-26 13:48:00 -0800715 }
716 msleep(100);
717 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000718 res_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_RES_REG);
Ben Hutchings307505e2008-12-26 13:48:00 -0800719 for (i = 0; i < 4; i++) {
720 int pair_res =
721 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
722 & ((1 << CDIAG_RES_WIDTH) - 1);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000723 int len_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
724 PMA_PMD_CDIAG_LEN_REG + i);
Ben Hutchings307505e2008-12-26 13:48:00 -0800725 if (pair_res == CDIAG_RES_OK)
726 results[1 + i] = 1;
727 else if (pair_res == CDIAG_RES_INVALID)
728 results[1 + i] = -1;
729 else
730 results[1 + i] = -pair_res;
731 if (pair_res != CDIAG_RES_INVALID &&
732 pair_res != CDIAG_RES_OPEN &&
733 len_reg != 0xffff)
734 results[5 + i] = len_reg;
735 }
736
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000737out:
738 if (flags & ETH_TEST_FL_OFFLINE) {
739 /* Reset, running the BIST and then resuming normal service. */
740 rc2 = tenxpress_special_reset(efx);
741 results[0] = rc2 ? -1 : 1;
742 if (!rc)
743 rc = rc2;
Ben Hutchings307505e2008-12-26 13:48:00 -0800744
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000745 efx_mdio_an_reconfigure(efx);
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000746 }
Ben Hutchings307505e2008-12-26 13:48:00 -0800747
748 return rc;
749}
750
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000751static void
752tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800753{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000754 u32 adv = 0, lpa = 0;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800755 int reg;
756
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800757 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000758 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000759 if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
760 adv |= ADVERTISED_1000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000761 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_STATUS);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000762 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800763 lpa |= ADVERTISED_1000baseT_Half;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000764 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800765 lpa |= ADVERTISED_1000baseT_Full;
766 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000767 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
768 if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000769 adv |= ADVERTISED_10000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000770 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
771 if (reg & MDIO_AN_10GBT_STAT_LP10G)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800772 lpa |= ADVERTISED_10000baseT_Full;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800773
Ben Hutchings68e7f452009-04-29 08:05:08 +0000774 mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800775
Ben Hutchingse762cd72009-06-10 05:30:05 +0000776 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000777 ecmd->supported |= (SUPPORTED_100baseT_Full |
778 SUPPORTED_1000baseT_Full);
Ben Hutchingse762cd72009-06-10 05:30:05 +0000779 if (ecmd->speed != SPEED_10000) {
780 ecmd->eth_tp_mdix =
781 (efx_mdio_read(efx, MDIO_MMD_PMAPMD,
782 PMA_PMD_XSTATUS_REG) &
783 (1 << PMA_PMD_XSTAT_MDIX_LBN))
784 ? ETH_TP_MDI_X : ETH_TP_MDI;
785 }
786 }
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000787
788 /* In loopback, the PHY automatically brings up the correct interface,
789 * but doesn't advertise the correct speed. So override it */
790 if (efx->loopback_mode == LOOPBACK_GPHY)
791 ecmd->speed = SPEED_1000;
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000792 else if (LOOPBACK_EXTERNAL(efx))
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000793 ecmd->speed = SPEED_10000;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100794}
795
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000796static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100797{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000798 if (!ecmd->autoneg)
799 return -EINVAL;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800800
Ben Hutchings68e7f452009-04-29 08:05:08 +0000801 return efx_mdio_set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100802}
803
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000804static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800805{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000806 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
807 MDIO_AN_10GBT_CTRL_ADV10G,
808 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000809}
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800810
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000811static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800812{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000813 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL,
814 1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
815 advertising & ADVERTISED_1000baseT_Full);
816 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
817 MDIO_AN_10GBT_CTRL_ADV10G,
818 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800819}
820
821struct efx_phy_operations falcon_sfx7101_phy_ops = {
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000822 .probe = sfx7101_phy_probe,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100823 .init = tenxpress_phy_init,
824 .reconfigure = tenxpress_phy_reconfigure,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800825 .poll = tenxpress_phy_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100826 .fini = tenxpress_phy_fini,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000827 .get_settings = tenxpress_get_settings,
828 .set_settings = tenxpress_set_settings,
829 .set_npage_adv = sfx7101_set_npage_adv,
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000830 .test_name = sfx7101_test_name,
Ben Hutchings307505e2008-12-26 13:48:00 -0800831 .run_tests = sfx7101_run_tests,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800832};
833
834struct efx_phy_operations falcon_sft9001_phy_ops = {
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000835 .probe = sft9001_phy_probe,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800836 .init = tenxpress_phy_init,
837 .reconfigure = tenxpress_phy_reconfigure,
838 .poll = tenxpress_phy_poll,
839 .fini = tenxpress_phy_fini,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000840 .get_settings = tenxpress_get_settings,
841 .set_settings = tenxpress_set_settings,
842 .set_npage_adv = sft9001_set_npage_adv,
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000843 .test_name = sft9001_test_name,
Ben Hutchings307505e2008-12-26 13:48:00 -0800844 .run_tests = sft9001_run_tests,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100845};