blob: 6791be90c2fe095f213e8d94e3f5077f0e8053da [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 Hutchingse6fa2eb2008-12-12 22:00:17 -080022/* We expect these MMDs to be in the package. SFT9001 also has a
23 * clause 22 extension MMD, but since it doesn't have all the generic
24 * MMD registers it is pointless to include it here.
25 */
Ben Hutchings68e7f452009-04-29 08:05:08 +000026#define TENXPRESS_REQUIRED_DEVS (MDIO_DEVS_PMAPMD | \
27 MDIO_DEVS_PCS | \
28 MDIO_DEVS_PHYXS | \
29 MDIO_DEVS_AN)
Ben Hutchings8ceee662008-04-27 12:55:59 +010030
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080031#define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
32 (1 << LOOPBACK_PCS) | \
33 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000034 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080035
36#define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \
37 (1 << LOOPBACK_PHYXS) | \
38 (1 << LOOPBACK_PCS) | \
39 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000040 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchings3273c2e2008-05-07 13:36:19 +010041
Ben Hutchings8ceee662008-04-27 12:55:59 +010042/* We complain if we fail to see the link partner as 10G capable this many
43 * times in a row (must be > 1 as sampling the autoneg. registers is racy)
44 */
45#define MAX_BAD_LP_TRIES (5)
46
47/* Extended control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080048#define PMA_PMD_XCONTROL_REG 49152
49#define PMA_PMD_EXT_GMII_EN_LBN 1
50#define PMA_PMD_EXT_GMII_EN_WIDTH 1
51#define PMA_PMD_EXT_CLK_OUT_LBN 2
52#define PMA_PMD_EXT_CLK_OUT_WIDTH 1
53#define PMA_PMD_LNPGA_POWERDOWN_LBN 8 /* SFX7101 only */
54#define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
55#define PMA_PMD_EXT_CLK312_LBN 8 /* SFT9001 only */
56#define PMA_PMD_EXT_CLK312_WIDTH 1
57#define PMA_PMD_EXT_LPOWER_LBN 12
58#define PMA_PMD_EXT_LPOWER_WIDTH 1
Steve Hodgson869b5b32009-01-29 17:48:10 +000059#define PMA_PMD_EXT_ROBUST_LBN 14
60#define PMA_PMD_EXT_ROBUST_WIDTH 1
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080061#define PMA_PMD_EXT_SSR_LBN 15
62#define PMA_PMD_EXT_SSR_WIDTH 1
Ben Hutchings8ceee662008-04-27 12:55:59 +010063
64/* extended status register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080065#define PMA_PMD_XSTATUS_REG 49153
Ben Hutchingse762cd72009-06-10 05:30:05 +000066#define PMA_PMD_XSTAT_MDIX_LBN 14
Ben Hutchings8ceee662008-04-27 12:55:59 +010067#define PMA_PMD_XSTAT_FLP_LBN (12)
68
69/* LED control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080070#define PMA_PMD_LED_CTRL_REG 49159
Ben Hutchings8ceee662008-04-27 12:55:59 +010071#define PMA_PMA_LED_ACTIVITY_LBN (3)
72
73/* LED function override register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080074#define PMA_PMD_LED_OVERR_REG 49161
Ben Hutchings8ceee662008-04-27 12:55:59 +010075/* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
76#define PMA_PMD_LED_LINK_LBN (0)
77#define PMA_PMD_LED_SPEED_LBN (2)
78#define PMA_PMD_LED_TX_LBN (4)
79#define PMA_PMD_LED_RX_LBN (6)
80/* Override settings */
81#define PMA_PMD_LED_AUTO (0) /* H/W control */
82#define PMA_PMD_LED_ON (1)
83#define PMA_PMD_LED_OFF (2)
84#define PMA_PMD_LED_FLASH (3)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080085#define PMA_PMD_LED_MASK 3
Ben Hutchings8ceee662008-04-27 12:55:59 +010086/* All LEDs under hardware control */
Ben Hutchingsdcf477b2009-11-23 16:02:49 +000087#define SFT9001_PMA_PMD_LED_DEFAULT 0
Ben Hutchings8ceee662008-04-27 12:55:59 +010088/* Green and Amber under hardware control, Red off */
Ben Hutchingsdcf477b2009-11-23 16:02:49 +000089#define SFX7101_PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
Ben Hutchings8ceee662008-04-27 12:55:59 +010090
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080091#define PMA_PMD_SPEED_ENABLE_REG 49192
92#define PMA_PMD_100TX_ADV_LBN 1
93#define PMA_PMD_100TX_ADV_WIDTH 1
94#define PMA_PMD_1000T_ADV_LBN 2
95#define PMA_PMD_1000T_ADV_WIDTH 1
96#define PMA_PMD_10000T_ADV_LBN 3
97#define PMA_PMD_10000T_ADV_WIDTH 1
98#define PMA_PMD_SPEED_LBN 4
99#define PMA_PMD_SPEED_WIDTH 4
Ben Hutchings8ceee662008-04-27 12:55:59 +0100100
Ben Hutchings307505e2008-12-26 13:48:00 -0800101/* Cable diagnostics - SFT9001 only */
102#define PMA_PMD_CDIAG_CTRL_REG 49213
103#define CDIAG_CTRL_IMMED_LBN 15
104#define CDIAG_CTRL_BRK_LINK_LBN 12
105#define CDIAG_CTRL_IN_PROG_LBN 11
106#define CDIAG_CTRL_LEN_UNIT_LBN 10
107#define CDIAG_CTRL_LEN_METRES 1
108#define PMA_PMD_CDIAG_RES_REG 49174
109#define CDIAG_RES_A_LBN 12
110#define CDIAG_RES_B_LBN 8
111#define CDIAG_RES_C_LBN 4
112#define CDIAG_RES_D_LBN 0
113#define CDIAG_RES_WIDTH 4
114#define CDIAG_RES_OPEN 2
115#define CDIAG_RES_OK 1
116#define CDIAG_RES_INVALID 0
117/* Set of 4 registers for pairs A-D */
118#define PMA_PMD_CDIAG_LEN_REG 49175
119
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800120/* Serdes control registers - SFT9001 only */
121#define PMA_PMD_CSERDES_CTRL_REG 64258
122/* Set the 156.25 MHz output to 312.5 MHz to drive Falcon's XMAC */
123#define PMA_PMD_CSERDES_DEFAULT 0x000f
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100124
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800125/* Misc register defines - SFX7101 only */
126#define PCS_CLOCK_CTRL_REG 55297
Ben Hutchings8ceee662008-04-27 12:55:59 +0100127#define PLL312_RST_N_LBN 2
128
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800129#define PCS_SOFT_RST2_REG 55302
Ben Hutchings8ceee662008-04-27 12:55:59 +0100130#define SERDES_RST_N_LBN 13
131#define XGXS_RST_N_LBN 12
132
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800133#define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100134#define CLK312_EN_LBN 3
135
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100136/* PHYXS registers */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800137#define PHYXS_XCONTROL_REG 49152
138#define PHYXS_RESET_LBN 15
139#define PHYXS_RESET_WIDTH 1
140
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100141#define PHYXS_TEST1 (49162)
142#define LOOPBACK_NEAR_LBN (8)
143#define LOOPBACK_NEAR_WIDTH (1)
144
Ben Hutchings8ceee662008-04-27 12:55:59 +0100145/* Boot status register */
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000146#define PCS_BOOT_STATUS_REG 53248
147#define PCS_BOOT_FATAL_ERROR_LBN 0
148#define PCS_BOOT_PROGRESS_LBN 1
149#define PCS_BOOT_PROGRESS_WIDTH 2
150#define PCS_BOOT_PROGRESS_INIT 0
151#define PCS_BOOT_PROGRESS_WAIT_MDIO 1
152#define PCS_BOOT_PROGRESS_CHECKSUM 2
153#define PCS_BOOT_PROGRESS_JUMP 3
154#define PCS_BOOT_DOWNLOAD_WAIT_LBN 3
155#define PCS_BOOT_CODE_STARTED_LBN 4
Ben Hutchings8ceee662008-04-27 12:55:59 +0100156
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800157/* 100M/1G PHY registers */
158#define GPHY_XCONTROL_REG 49152
159#define GPHY_ISOLATE_LBN 10
160#define GPHY_ISOLATE_WIDTH 1
161#define GPHY_DUPLEX_LBN 8
162#define GPHY_DUPLEX_WIDTH 1
163#define GPHY_LOOPBACK_NEAR_LBN 14
164#define GPHY_LOOPBACK_NEAR_WIDTH 1
165
166#define C22EXT_STATUS_REG 49153
167#define C22EXT_STATUS_LINK_LBN 2
168#define C22EXT_STATUS_LINK_WIDTH 1
169
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000170#define C22EXT_MSTSLV_CTRL 49161
171#define C22EXT_MSTSLV_CTRL_ADV_1000_HD_LBN 8
172#define C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN 9
173
174#define C22EXT_MSTSLV_STATUS 49162
175#define C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN 10
176#define C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN 11
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800177
Ben Hutchings8ceee662008-04-27 12:55:59 +0100178/* Time to wait between powering down the LNPGA and turning off the power
179 * rails */
180#define LNPGA_PDOWN_WAIT (HZ / 5)
181
Ben Hutchings8ceee662008-04-27 12:55:59 +0100182struct tenxpress_phy_data {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100183 enum efx_loopback_mode loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100184 enum efx_phy_mode phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100185 int bad_lp_tries;
186};
187
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800188static ssize_t show_phy_short_reach(struct device *dev,
189 struct device_attribute *attr, char *buf)
190{
191 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
192 int reg;
193
Ben Hutchings68e7f452009-04-29 08:05:08 +0000194 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TXPWR);
195 return sprintf(buf, "%d\n", !!(reg & MDIO_PMA_10GBT_TXPWR_SHORT));
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800196}
197
198static ssize_t set_phy_short_reach(struct device *dev,
199 struct device_attribute *attr,
200 const char *buf, size_t count)
201{
202 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000203 int rc;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800204
205 rtnl_lock();
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000206 if (efx->state != STATE_RUNNING) {
207 rc = -EBUSY;
208 } else {
209 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TXPWR,
210 MDIO_PMA_10GBT_TXPWR_SHORT,
211 count != 0 && *buf != '0');
212 rc = efx_reconfigure_port(efx);
213 }
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800214 rtnl_unlock();
215
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000216 return rc < 0 ? rc : (ssize_t)count;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800217}
218
219static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
220 set_phy_short_reach);
221
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000222int sft9001_wait_boot(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100223{
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000224 unsigned long timeout = jiffies + HZ + 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100225 int boot_stat;
226
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000227 for (;;) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000228 boot_stat = efx_mdio_read(efx, MDIO_MMD_PCS,
229 PCS_BOOT_STATUS_REG);
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000230 if (boot_stat >= 0) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000231 netif_dbg(efx, hw, efx->net_dev,
232 "PHY boot status = %#x\n", boot_stat);
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000233 switch (boot_stat &
234 ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
235 (3 << PCS_BOOT_PROGRESS_LBN) |
236 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN) |
237 (1 << PCS_BOOT_CODE_STARTED_LBN))) {
238 case ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
239 (PCS_BOOT_PROGRESS_CHECKSUM <<
240 PCS_BOOT_PROGRESS_LBN)):
241 case ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
242 (PCS_BOOT_PROGRESS_INIT <<
243 PCS_BOOT_PROGRESS_LBN) |
244 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN)):
245 return -EINVAL;
246 case ((PCS_BOOT_PROGRESS_WAIT_MDIO <<
247 PCS_BOOT_PROGRESS_LBN) |
248 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN)):
249 return (efx->phy_mode & PHY_MODE_SPECIAL) ?
250 0 : -EIO;
251 case ((PCS_BOOT_PROGRESS_JUMP <<
252 PCS_BOOT_PROGRESS_LBN) |
253 (1 << PCS_BOOT_CODE_STARTED_LBN)):
254 case ((PCS_BOOT_PROGRESS_JUMP <<
255 PCS_BOOT_PROGRESS_LBN) |
256 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN) |
257 (1 << PCS_BOOT_CODE_STARTED_LBN)):
258 return (efx->phy_mode & PHY_MODE_SPECIAL) ?
259 -EIO : 0;
260 default:
261 if (boot_stat & (1 << PCS_BOOT_FATAL_ERROR_LBN))
262 return -EIO;
263 break;
264 }
265 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100266
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000267 if (time_after_eq(jiffies, timeout))
268 return -ETIMEDOUT;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100269
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000270 msleep(50);
271 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100272}
273
Ben Hutchings8ceee662008-04-27 12:55:59 +0100274static int tenxpress_init(struct efx_nic *efx)
275{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800276 int reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100277
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800278 if (efx->phy_type == PHY_TYPE_SFX7101) {
279 /* Enable 312.5 MHz clock */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000280 efx_mdio_write(efx, MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
281 1 << CLK312_EN_LBN);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800282 } else {
283 /* Enable 312.5 MHz clock and GMII */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000284 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800285 reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
286 (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
Steve Hodgson869b5b32009-01-29 17:48:10 +0000287 (1 << PMA_PMD_EXT_CLK312_LBN) |
288 (1 << PMA_PMD_EXT_ROBUST_LBN));
289
Ben Hutchings68e7f452009-04-29 08:05:08 +0000290 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
291 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT,
292 GPHY_XCONTROL_REG, 1 << GPHY_ISOLATE_LBN,
293 false);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800294 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100295
Ben Hutchings8ceee662008-04-27 12:55:59 +0100296 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800297 if (efx->phy_type == PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000298 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG,
299 1 << PMA_PMA_LED_ACTIVITY_LBN, true);
300 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG,
Ben Hutchingsdcf477b2009-11-23 16:02:49 +0000301 SFX7101_PMA_PMD_LED_DEFAULT);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800302 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100303
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000304 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100305}
306
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000307static int tenxpress_phy_probe(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100308{
309 struct tenxpress_phy_data *phy_data;
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000310 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100311
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000312 /* Allocate phy private storage */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100313 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
Ben Hutchings9b7bfc42008-05-16 21:20:20 +0100314 if (!phy_data)
315 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100316 efx->phy_data = phy_data;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100317 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100318
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000319 /* Create any special files */
320 if (efx->phy_type == PHY_TYPE_SFT9001B) {
321 rc = device_create_file(&efx->pci_dev->dev,
322 &dev_attr_phy_short_reach);
323 if (rc)
324 goto fail;
325 }
326
327 if (efx->phy_type == PHY_TYPE_SFX7101) {
328 efx->mdio.mmds = TENXPRESS_REQUIRED_DEVS;
329 efx->mdio.mode_support = MDIO_SUPPORTS_C45;
330
331 efx->loopback_modes = SFX7101_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
332
333 efx->link_advertising = (ADVERTISED_TP | ADVERTISED_Autoneg |
334 ADVERTISED_10000baseT_Full);
335 } else {
336 efx->mdio.mmds = TENXPRESS_REQUIRED_DEVS;
337 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
338
339 efx->loopback_modes = (SFT9001_LOOPBACKS |
340 FALCON_XMAC_LOOPBACKS |
341 FALCON_GMAC_LOOPBACKS);
342
343 efx->link_advertising = (ADVERTISED_TP | ADVERTISED_Autoneg |
344 ADVERTISED_10000baseT_Full |
345 ADVERTISED_1000baseT_Full |
346 ADVERTISED_100baseT_Full);
347 }
348
349 return 0;
350
351fail:
352 kfree(efx->phy_data);
353 efx->phy_data = NULL;
354 return rc;
355}
356
357static int tenxpress_phy_init(struct efx_nic *efx)
358{
359 int rc;
360
361 falcon_board(efx)->type->init_phy(efx);
362
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800363 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
364 if (efx->phy_type == PHY_TYPE_SFT9001A) {
365 int reg;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000366 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
367 PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800368 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000369 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
370 PMA_PMD_XCONTROL_REG, reg);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800371 mdelay(200);
372 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100373
Ben Hutchings68e7f452009-04-29 08:05:08 +0000374 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800375 if (rc < 0)
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000376 return rc;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800377
Ben Hutchings68e7f452009-04-29 08:05:08 +0000378 rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800379 if (rc < 0)
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000380 return rc;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800381 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100382
383 rc = tenxpress_init(efx);
384 if (rc < 0)
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000385 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100386
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000387 /* Reinitialise flow control settings */
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000388 efx_link_set_wanted_fc(efx, efx->wanted_fc);
389 efx_mdio_an_reconfigure(efx);
Ben Hutchingsc6342632009-10-12 09:27:07 +0000390
Ben Hutchings8ceee662008-04-27 12:55:59 +0100391 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
392
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800393 /* Let XGXS and SerDes out of reset */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100394 falcon_reset_xaui(efx);
395
396 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100397}
398
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800399/* Perform a "special software reset" on the PHY. The caller is
400 * responsible for saving and restoring the PHY hardware registers
401 * properly, and masking/unmasking LASI */
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100402static int tenxpress_special_reset(struct efx_nic *efx)
403{
404 int rc, reg;
405
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100406 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
407 * a special software reset can glitch the XGMAC sufficiently for stats
Ben Hutchings1974cc22009-01-29 18:00:07 +0000408 * requests to fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000409 falcon_stop_nic_stats(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100410
411 /* Initiate reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000412 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100413 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000414 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100415
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100416 mdelay(200);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100417
418 /* Wait for the blocks to come out of reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000419 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100420 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000421 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100422
423 /* Try and reconfigure the device */
424 rc = tenxpress_init(efx);
425 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000426 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100427
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800428 /* Wait for the XGXS state machine to churn */
429 mdelay(10);
Ben Hutchings1974cc22009-01-29 18:00:07 +0000430out:
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000431 falcon_start_nic_stats(efx);
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100432 return rc;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100433}
434
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800435static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100436{
437 struct tenxpress_phy_data *pd = efx->phy_data;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800438 bool bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100439 int reg;
440
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800441 if (link_ok) {
442 bad_lp = false;
443 } else {
444 /* Check that AN has started but not completed. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000445 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
446 if (!(reg & MDIO_AN_STAT1_LPABLE))
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800447 return; /* LP status is unknown */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000448 bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800449 if (bad_lp)
450 pd->bad_lp_tries++;
451 }
452
Ben Hutchings8ceee662008-04-27 12:55:59 +0100453 /* Nothing to do if all is well and was previously so. */
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800454 if (!pd->bad_lp_tries)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100455 return;
456
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800457 /* Use the RX (red) LED as an error indicator once we've seen AN
458 * failure several times in a row, and also log a message. */
459 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000460 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
461 PMA_PMD_LED_OVERR_REG);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800462 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
463 if (!bad_lp) {
464 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
465 } else {
466 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
Ben Hutchings62776d02010-06-23 11:30:07 +0000467 netif_err(efx, link, efx->net_dev,
468 "appears to be plugged into a port"
469 " that is not 10GBASE-T capable. The PHY"
470 " supports 10GBASE-T ONLY, so no link can"
471 " be established\n");
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800472 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000473 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
474 PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800475 pd->bad_lp_tries = bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100476 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100477}
478
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800479static bool sfx7101_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100480{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000481 return efx_mdio_links_ok(efx,
482 MDIO_DEVS_PMAPMD |
483 MDIO_DEVS_PCS |
484 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800485}
486
487static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
488{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800489 u32 reg;
490
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800491 if (efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800492 return false;
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800493 else if (efx->loopback_mode == LOOPBACK_GPHY)
494 return true;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800495 else if (efx->loopback_mode)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000496 return efx_mdio_links_ok(efx,
497 MDIO_DEVS_PMAPMD |
498 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800499
500 /* We must use the same definition of link state as LASI,
501 * otherwise we can miss a link state transition
502 */
503 if (ecmd->speed == 10000) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000504 reg = efx_mdio_read(efx, MDIO_MMD_PCS, MDIO_PCS_10GBRT_STAT1);
505 return reg & MDIO_PCS_10GBRT_STAT1_BLKLK;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800506 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000507 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_STATUS_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800508 return reg & (1 << C22EXT_STATUS_LINK_LBN);
509 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100510}
511
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800512static void tenxpress_ext_loopback(struct efx_nic *efx)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100513{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000514 efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
515 1 << LOOPBACK_NEAR_LBN,
516 efx->loopback_mode == LOOPBACK_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800517 if (efx->phy_type != PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000518 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, GPHY_XCONTROL_REG,
519 1 << GPHY_LOOPBACK_NEAR_LBN,
520 efx->loopback_mode == LOOPBACK_GPHY);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800521}
522
523static void tenxpress_low_power(struct efx_nic *efx)
524{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800525 if (efx->phy_type == PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000526 efx_mdio_set_mmds_lpower(
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800527 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
528 TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100529 else
Ben Hutchings68e7f452009-04-29 08:05:08 +0000530 efx_mdio_set_flag(
531 efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG,
532 1 << PMA_PMD_EXT_LPOWER_LBN,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800533 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100534}
535
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000536static int tenxpress_phy_reconfigure(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100537{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100538 struct tenxpress_phy_data *phy_data = efx->phy_data;
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000539 bool phy_mode_change, loop_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100540
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800541 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100542 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000543 return 0;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100544 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100545
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800546 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
547 phy_data->phy_mode != PHY_MODE_NORMAL);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000548 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, LOOPBACKS_EXTERNAL(efx)) ||
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800549 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
550
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000551 if (loop_reset || phy_mode_change) {
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000552 tenxpress_special_reset(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800553
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000554 /* Reset XAUI if we were in 10G, and are staying
555 * in 10G. If we're moving into and out of 10G
556 * then xaui will be reset anyway */
557 if (EFX_IS10G(efx))
558 falcon_reset_xaui(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100559 }
560
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000561 tenxpress_low_power(efx);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000562 efx_mdio_transmit_disable(efx);
563 efx_mdio_phy_reconfigure(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800564 tenxpress_ext_loopback(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000565 efx_mdio_an_reconfigure(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100566
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100567 phy_data->loopback_mode = efx->loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100568 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000569
570 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100571}
572
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000573static void
574tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd);
575
576/* Poll for link state changes */
577static bool tenxpress_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100578{
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000579 struct efx_link_state old_state = efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100580
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800581 if (efx->phy_type == PHY_TYPE_SFX7101) {
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000582 efx->link_state.up = sfx7101_link_ok(efx);
583 efx->link_state.speed = 10000;
584 efx->link_state.fd = true;
585 efx->link_state.fc = efx_mdio_get_pause(efx);
586
587 sfx7101_check_bad_lp(efx, efx->link_state.up);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800588 } else {
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000589 struct ethtool_cmd ecmd;
590
591 /* Check the LASI alarm first */
592 if (efx->loopback_mode == LOOPBACK_NONE &&
593 !(efx_mdio_read(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_STAT) &
594 MDIO_PMA_LASI_LSALARM))
595 return false;
596
597 tenxpress_get_settings(efx, &ecmd);
598
599 efx->link_state.up = sft9001_link_ok(efx, &ecmd);
600 efx->link_state.speed = ecmd.speed;
601 efx->link_state.fd = (ecmd.duplex == DUPLEX_FULL);
602 efx->link_state.fc = efx_mdio_get_pause(efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800603 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100604
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000605 return !efx_link_state_equal(&efx->link_state, &old_state);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100606}
607
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000608static void sfx7101_phy_fini(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100609{
610 int reg;
611
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000612 /* Power down the LNPGA */
613 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
614 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
615
616 /* Waiting here ensures that the board fini, which can turn
617 * off the power to the PHY, won't get run until the LNPGA
618 * powerdown has been given long enough to complete. */
619 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
620}
621
622static void tenxpress_phy_remove(struct efx_nic *efx)
623{
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800624 if (efx->phy_type == PHY_TYPE_SFT9001B)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800625 device_remove_file(&efx->pci_dev->dev,
626 &dev_attr_phy_short_reach);
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800627
Ben Hutchings8ceee662008-04-27 12:55:59 +0100628 kfree(efx->phy_data);
629 efx->phy_data = NULL;
630}
631
632
Ben Hutchings398468e2009-11-23 16:03:45 +0000633/* Override the RX, TX and link LEDs */
634void tenxpress_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100635{
636 int reg;
637
Ben Hutchings398468e2009-11-23 16:03:45 +0000638 switch (mode) {
639 case EFX_LED_OFF:
640 reg = (PMA_PMD_LED_OFF << PMA_PMD_LED_TX_LBN) |
641 (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN) |
642 (PMA_PMD_LED_OFF << PMA_PMD_LED_LINK_LBN);
643 break;
644 case EFX_LED_ON:
645 reg = (PMA_PMD_LED_ON << PMA_PMD_LED_TX_LBN) |
646 (PMA_PMD_LED_ON << PMA_PMD_LED_RX_LBN) |
647 (PMA_PMD_LED_ON << PMA_PMD_LED_LINK_LBN);
648 break;
649 default:
Ben Hutchingsdcf477b2009-11-23 16:02:49 +0000650 if (efx->phy_type == PHY_TYPE_SFX7101)
651 reg = SFX7101_PMA_PMD_LED_DEFAULT;
652 else
653 reg = SFT9001_PMA_PMD_LED_DEFAULT;
Ben Hutchings398468e2009-11-23 16:03:45 +0000654 break;
655 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100656
Ben Hutchings68e7f452009-04-29 08:05:08 +0000657 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100658}
659
Ben Hutchings307505e2008-12-26 13:48:00 -0800660static const char *const sfx7101_test_names[] = {
Ben Hutchings17967212008-12-26 13:47:25 -0800661 "bist"
662};
663
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000664static const char *sfx7101_test_name(struct efx_nic *efx, unsigned int index)
665{
666 if (index < ARRAY_SIZE(sfx7101_test_names))
667 return sfx7101_test_names[index];
668 return NULL;
669}
670
Ben Hutchings17967212008-12-26 13:47:25 -0800671static int
Ben Hutchings307505e2008-12-26 13:48:00 -0800672sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100673{
Ben Hutchings17967212008-12-26 13:47:25 -0800674 int rc;
675
676 if (!(flags & ETH_TEST_FL_OFFLINE))
677 return 0;
678
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100679 /* BIST is automatically run after a special software reset */
Ben Hutchings17967212008-12-26 13:47:25 -0800680 rc = tenxpress_special_reset(efx);
681 results[0] = rc ? -1 : 1;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000682
683 efx_mdio_an_reconfigure(efx);
684
Ben Hutchings17967212008-12-26 13:47:25 -0800685 return rc;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100686}
687
Ben Hutchings307505e2008-12-26 13:48:00 -0800688static const char *const sft9001_test_names[] = {
689 "bist",
690 "cable.pairA.status",
691 "cable.pairB.status",
692 "cable.pairC.status",
693 "cable.pairD.status",
694 "cable.pairA.length",
695 "cable.pairB.length",
696 "cable.pairC.length",
697 "cable.pairD.length",
698};
699
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000700static const char *sft9001_test_name(struct efx_nic *efx, unsigned int index)
701{
702 if (index < ARRAY_SIZE(sft9001_test_names))
703 return sft9001_test_names[index];
704 return NULL;
705}
706
Ben Hutchings307505e2008-12-26 13:48:00 -0800707static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
708{
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000709 int rc = 0, rc2, i, ctrl_reg, res_reg;
Ben Hutchings307505e2008-12-26 13:48:00 -0800710
Ben Hutchings307505e2008-12-26 13:48:00 -0800711 /* Initialise cable diagnostic results to unknown failure */
712 for (i = 1; i < 9; ++i)
713 results[i] = -1;
714
715 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
716 * A cable fault is not a self-test failure, but a timeout is. */
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000717 ctrl_reg = ((1 << CDIAG_CTRL_IMMED_LBN) |
718 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
719 if (flags & ETH_TEST_FL_OFFLINE) {
720 /* Break the link in order to run full diagnostics. We
721 * must reset the PHY to resume normal service. */
722 ctrl_reg |= (1 << CDIAG_CTRL_BRK_LINK_LBN);
723 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000724 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG,
725 ctrl_reg);
Ben Hutchings307505e2008-12-26 13:48:00 -0800726 i = 0;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000727 while (efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG) &
Ben Hutchings307505e2008-12-26 13:48:00 -0800728 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
729 if (++i == 50) {
730 rc = -ETIMEDOUT;
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000731 goto out;
Ben Hutchings307505e2008-12-26 13:48:00 -0800732 }
733 msleep(100);
734 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000735 res_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_RES_REG);
Ben Hutchings307505e2008-12-26 13:48:00 -0800736 for (i = 0; i < 4; i++) {
737 int pair_res =
738 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
739 & ((1 << CDIAG_RES_WIDTH) - 1);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000740 int len_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
741 PMA_PMD_CDIAG_LEN_REG + i);
Ben Hutchings307505e2008-12-26 13:48:00 -0800742 if (pair_res == CDIAG_RES_OK)
743 results[1 + i] = 1;
744 else if (pair_res == CDIAG_RES_INVALID)
745 results[1 + i] = -1;
746 else
747 results[1 + i] = -pair_res;
748 if (pair_res != CDIAG_RES_INVALID &&
749 pair_res != CDIAG_RES_OPEN &&
750 len_reg != 0xffff)
751 results[5 + i] = len_reg;
752 }
753
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000754out:
755 if (flags & ETH_TEST_FL_OFFLINE) {
756 /* Reset, running the BIST and then resuming normal service. */
757 rc2 = tenxpress_special_reset(efx);
758 results[0] = rc2 ? -1 : 1;
759 if (!rc)
760 rc = rc2;
Ben Hutchings307505e2008-12-26 13:48:00 -0800761
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000762 efx_mdio_an_reconfigure(efx);
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000763 }
Ben Hutchings307505e2008-12-26 13:48:00 -0800764
765 return rc;
766}
767
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000768static void
769tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800770{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000771 u32 adv = 0, lpa = 0;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800772 int reg;
773
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800774 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000775 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000776 if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
777 adv |= ADVERTISED_1000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000778 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_STATUS);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000779 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800780 lpa |= ADVERTISED_1000baseT_Half;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000781 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800782 lpa |= ADVERTISED_1000baseT_Full;
783 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000784 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
785 if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000786 adv |= ADVERTISED_10000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000787 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
788 if (reg & MDIO_AN_10GBT_STAT_LP10G)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800789 lpa |= ADVERTISED_10000baseT_Full;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800790
Ben Hutchings68e7f452009-04-29 08:05:08 +0000791 mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800792
Ben Hutchingse762cd72009-06-10 05:30:05 +0000793 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000794 ecmd->supported |= (SUPPORTED_100baseT_Full |
795 SUPPORTED_1000baseT_Full);
Ben Hutchingse762cd72009-06-10 05:30:05 +0000796 if (ecmd->speed != SPEED_10000) {
797 ecmd->eth_tp_mdix =
798 (efx_mdio_read(efx, MDIO_MMD_PMAPMD,
799 PMA_PMD_XSTATUS_REG) &
800 (1 << PMA_PMD_XSTAT_MDIX_LBN))
801 ? ETH_TP_MDI_X : ETH_TP_MDI;
802 }
803 }
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000804
805 /* In loopback, the PHY automatically brings up the correct interface,
806 * but doesn't advertise the correct speed. So override it */
807 if (efx->loopback_mode == LOOPBACK_GPHY)
808 ecmd->speed = SPEED_1000;
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000809 else if (LOOPBACK_EXTERNAL(efx))
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000810 ecmd->speed = SPEED_10000;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100811}
812
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000813static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100814{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000815 if (!ecmd->autoneg)
816 return -EINVAL;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800817
Ben Hutchings68e7f452009-04-29 08:05:08 +0000818 return efx_mdio_set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100819}
820
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000821static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800822{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000823 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
824 MDIO_AN_10GBT_CTRL_ADV10G,
825 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000826}
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800827
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000828static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800829{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000830 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL,
831 1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
832 advertising & ADVERTISED_1000baseT_Full);
833 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
834 MDIO_AN_10GBT_CTRL_ADV10G,
835 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800836}
837
838struct efx_phy_operations falcon_sfx7101_phy_ops = {
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000839 .probe = tenxpress_phy_probe,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100840 .init = tenxpress_phy_init,
841 .reconfigure = tenxpress_phy_reconfigure,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800842 .poll = tenxpress_phy_poll,
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000843 .fini = sfx7101_phy_fini,
844 .remove = tenxpress_phy_remove,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000845 .get_settings = tenxpress_get_settings,
846 .set_settings = tenxpress_set_settings,
847 .set_npage_adv = sfx7101_set_npage_adv,
Ben Hutchings4f16c072010-02-03 09:30:50 +0000848 .test_alive = efx_mdio_test_alive,
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000849 .test_name = sfx7101_test_name,
Ben Hutchings307505e2008-12-26 13:48:00 -0800850 .run_tests = sfx7101_run_tests,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800851};
852
853struct efx_phy_operations falcon_sft9001_phy_ops = {
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000854 .probe = tenxpress_phy_probe,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800855 .init = tenxpress_phy_init,
856 .reconfigure = tenxpress_phy_reconfigure,
857 .poll = tenxpress_phy_poll,
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000858 .fini = efx_port_dummy_op_void,
859 .remove = tenxpress_phy_remove,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000860 .get_settings = tenxpress_get_settings,
861 .set_settings = tenxpress_set_settings,
862 .set_npage_adv = sft9001_set_npage_adv,
Ben Hutchings4f16c072010-02-03 09:30:50 +0000863 .test_alive = efx_mdio_test_alive,
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000864 .test_name = sft9001_test_name,
Ben Hutchings307505e2008-12-26 13:48:00 -0800865 .run_tests = sft9001_run_tests,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100866};