blob: 390b27b5ace99b6cd5d7c82fb6de0e9ee77680d5 [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
3 * Copyright 2007-2008 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"
15#include "falcon.h"
16#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) | \
33 (1 << LOOPBACK_NETWORK))
34
35#define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \
36 (1 << LOOPBACK_PHYXS) | \
37 (1 << LOOPBACK_PCS) | \
38 (1 << LOOPBACK_PMAPMD) | \
39 (1 << LOOPBACK_NETWORK))
Ben 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 */
86#define PMA_PMD_LED_FULL_AUTO (0)
87/* Green and Amber under hardware control, Red off */
88#define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
89
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));
202
203 rtnl_lock();
Ben Hutchings68e7f452009-04-29 08:05:08 +0000204 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TXPWR,
205 MDIO_PMA_10GBT_TXPWR_SHORT,
206 count != 0 && *buf != '0');
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800207 efx_reconfigure_port(efx);
208 rtnl_unlock();
209
210 return count;
211}
212
213static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
214 set_phy_short_reach);
215
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000216int sft9001_wait_boot(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100217{
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000218 unsigned long timeout = jiffies + HZ + 1;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100219 int boot_stat;
220
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000221 for (;;) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000222 boot_stat = efx_mdio_read(efx, MDIO_MMD_PCS,
223 PCS_BOOT_STATUS_REG);
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000224 if (boot_stat >= 0) {
225 EFX_LOG(efx, "PHY boot status = %#x\n", boot_stat);
226 switch (boot_stat &
227 ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
228 (3 << PCS_BOOT_PROGRESS_LBN) |
229 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN) |
230 (1 << PCS_BOOT_CODE_STARTED_LBN))) {
231 case ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
232 (PCS_BOOT_PROGRESS_CHECKSUM <<
233 PCS_BOOT_PROGRESS_LBN)):
234 case ((1 << PCS_BOOT_FATAL_ERROR_LBN) |
235 (PCS_BOOT_PROGRESS_INIT <<
236 PCS_BOOT_PROGRESS_LBN) |
237 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN)):
238 return -EINVAL;
239 case ((PCS_BOOT_PROGRESS_WAIT_MDIO <<
240 PCS_BOOT_PROGRESS_LBN) |
241 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN)):
242 return (efx->phy_mode & PHY_MODE_SPECIAL) ?
243 0 : -EIO;
244 case ((PCS_BOOT_PROGRESS_JUMP <<
245 PCS_BOOT_PROGRESS_LBN) |
246 (1 << PCS_BOOT_CODE_STARTED_LBN)):
247 case ((PCS_BOOT_PROGRESS_JUMP <<
248 PCS_BOOT_PROGRESS_LBN) |
249 (1 << PCS_BOOT_DOWNLOAD_WAIT_LBN) |
250 (1 << PCS_BOOT_CODE_STARTED_LBN)):
251 return (efx->phy_mode & PHY_MODE_SPECIAL) ?
252 -EIO : 0;
253 default:
254 if (boot_stat & (1 << PCS_BOOT_FATAL_ERROR_LBN))
255 return -EIO;
256 break;
257 }
258 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100259
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000260 if (time_after_eq(jiffies, timeout))
261 return -ETIMEDOUT;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100262
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000263 msleep(50);
264 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100265}
266
Ben Hutchings8ceee662008-04-27 12:55:59 +0100267static int tenxpress_init(struct efx_nic *efx)
268{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800269 int reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100270
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800271 if (efx->phy_type == PHY_TYPE_SFX7101) {
272 /* Enable 312.5 MHz clock */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000273 efx_mdio_write(efx, MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
274 1 << CLK312_EN_LBN);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800275 } else {
276 /* Enable 312.5 MHz clock and GMII */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000277 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800278 reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
279 (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
Steve Hodgson869b5b32009-01-29 17:48:10 +0000280 (1 << PMA_PMD_EXT_CLK312_LBN) |
281 (1 << PMA_PMD_EXT_ROBUST_LBN));
282
Ben Hutchings68e7f452009-04-29 08:05:08 +0000283 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
284 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT,
285 GPHY_XCONTROL_REG, 1 << GPHY_ISOLATE_LBN,
286 false);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800287 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100288
Ben Hutchings8ceee662008-04-27 12:55:59 +0100289 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800290 if (efx->phy_type == PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000291 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG,
292 1 << PMA_PMA_LED_ACTIVITY_LBN, true);
293 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG,
294 PMA_PMD_LED_DEFAULT);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800295 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100296
Ben Hutchings190dbcf2009-02-27 13:06:45 +0000297 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100298}
299
300static int tenxpress_phy_init(struct efx_nic *efx)
301{
302 struct tenxpress_phy_data *phy_data;
Ben Hutchingsc6342632009-10-12 09:27:07 +0000303 u16 old_adv, adv;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100304 int rc = 0;
305
306 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
Ben Hutchings9b7bfc42008-05-16 21:20:20 +0100307 if (!phy_data)
308 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100309 efx->phy_data = phy_data;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100310 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100311
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800312 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
313 if (efx->phy_type == PHY_TYPE_SFT9001A) {
314 int reg;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000315 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
316 PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800317 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000318 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
319 PMA_PMD_XCONTROL_REG, reg);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800320 mdelay(200);
321 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100322
Ben Hutchings68e7f452009-04-29 08:05:08 +0000323 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800324 if (rc < 0)
325 goto fail;
326
Ben Hutchings68e7f452009-04-29 08:05:08 +0000327 rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800328 if (rc < 0)
329 goto fail;
330 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100331
332 rc = tenxpress_init(efx);
333 if (rc < 0)
334 goto fail;
335
Ben Hutchingsc6342632009-10-12 09:27:07 +0000336 /* Set pause advertising */
337 old_adv = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
338 adv = ((old_adv & ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM)) |
339 mii_advertise_flowctrl(efx->wanted_fc));
340 if (adv != old_adv) {
341 efx_mdio_write(efx, MDIO_MMD_AN, MDIO_AN_ADVERTISE, adv);
342 mdio45_nway_restart(&efx->mdio);
343 }
344
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800345 if (efx->phy_type == PHY_TYPE_SFT9001B) {
346 rc = device_create_file(&efx->pci_dev->dev,
347 &dev_attr_phy_short_reach);
348 if (rc)
349 goto fail;
350 }
351
Ben Hutchings8ceee662008-04-27 12:55:59 +0100352 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
353
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800354 /* Let XGXS and SerDes out of reset */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100355 falcon_reset_xaui(efx);
356
357 return 0;
358
359 fail:
360 kfree(efx->phy_data);
361 efx->phy_data = NULL;
362 return rc;
363}
364
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800365/* Perform a "special software reset" on the PHY. The caller is
366 * responsible for saving and restoring the PHY hardware registers
367 * properly, and masking/unmasking LASI */
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100368static int tenxpress_special_reset(struct efx_nic *efx)
369{
370 int rc, reg;
371
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100372 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
373 * a special software reset can glitch the XGMAC sufficiently for stats
Ben Hutchings1974cc22009-01-29 18:00:07 +0000374 * requests to fail. */
375 efx_stats_disable(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100376
377 /* Initiate reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000378 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100379 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000380 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100381
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100382 mdelay(200);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100383
384 /* Wait for the blocks to come out of reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000385 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100386 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000387 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100388
389 /* Try and reconfigure the device */
390 rc = tenxpress_init(efx);
391 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000392 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100393
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800394 /* Wait for the XGXS state machine to churn */
395 mdelay(10);
Ben Hutchings1974cc22009-01-29 18:00:07 +0000396out:
397 efx_stats_enable(efx);
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100398 return rc;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100399}
400
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800401static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100402{
403 struct tenxpress_phy_data *pd = efx->phy_data;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800404 bool bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100405 int reg;
406
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800407 if (link_ok) {
408 bad_lp = false;
409 } else {
410 /* Check that AN has started but not completed. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000411 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
412 if (!(reg & MDIO_AN_STAT1_LPABLE))
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800413 return; /* LP status is unknown */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000414 bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800415 if (bad_lp)
416 pd->bad_lp_tries++;
417 }
418
Ben Hutchings8ceee662008-04-27 12:55:59 +0100419 /* Nothing to do if all is well and was previously so. */
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800420 if (!pd->bad_lp_tries)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100421 return;
422
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800423 /* Use the RX (red) LED as an error indicator once we've seen AN
424 * failure several times in a row, and also log a message. */
425 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000426 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
427 PMA_PMD_LED_OVERR_REG);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800428 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
429 if (!bad_lp) {
430 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
431 } else {
432 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
433 EFX_ERR(efx, "appears to be plugged into a port"
434 " that is not 10GBASE-T capable. The PHY"
435 " supports 10GBASE-T ONLY, so no link can"
436 " be established\n");
437 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000438 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
439 PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800440 pd->bad_lp_tries = bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100441 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100442}
443
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800444static bool sfx7101_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100445{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000446 return efx_mdio_links_ok(efx,
447 MDIO_DEVS_PMAPMD |
448 MDIO_DEVS_PCS |
449 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800450}
451
452static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
453{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800454 u32 reg;
455
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800456 if (efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800457 return false;
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800458 else if (efx->loopback_mode == LOOPBACK_GPHY)
459 return true;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800460 else if (efx->loopback_mode)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000461 return efx_mdio_links_ok(efx,
462 MDIO_DEVS_PMAPMD |
463 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800464
465 /* We must use the same definition of link state as LASI,
466 * otherwise we can miss a link state transition
467 */
468 if (ecmd->speed == 10000) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000469 reg = efx_mdio_read(efx, MDIO_MMD_PCS, MDIO_PCS_10GBRT_STAT1);
470 return reg & MDIO_PCS_10GBRT_STAT1_BLKLK;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800471 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000472 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_STATUS_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800473 return reg & (1 << C22EXT_STATUS_LINK_LBN);
474 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100475}
476
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800477static void tenxpress_ext_loopback(struct efx_nic *efx)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100478{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000479 efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
480 1 << LOOPBACK_NEAR_LBN,
481 efx->loopback_mode == LOOPBACK_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800482 if (efx->phy_type != PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000483 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, GPHY_XCONTROL_REG,
484 1 << GPHY_LOOPBACK_NEAR_LBN,
485 efx->loopback_mode == LOOPBACK_GPHY);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800486}
487
488static void tenxpress_low_power(struct efx_nic *efx)
489{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800490 if (efx->phy_type == PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000491 efx_mdio_set_mmds_lpower(
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800492 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
493 TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100494 else
Ben Hutchings68e7f452009-04-29 08:05:08 +0000495 efx_mdio_set_flag(
496 efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG,
497 1 << PMA_PMD_EXT_LPOWER_LBN,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800498 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100499}
500
Ben Hutchings8ceee662008-04-27 12:55:59 +0100501static void tenxpress_phy_reconfigure(struct efx_nic *efx)
502{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100503 struct tenxpress_phy_data *phy_data = efx->phy_data;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800504 struct ethtool_cmd ecmd;
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000505 bool phy_mode_change, loop_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100506
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800507 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100508 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100509 return;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100510 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100511
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800512 tenxpress_low_power(efx);
513
514 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
515 phy_data->phy_mode != PHY_MODE_NORMAL);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800516 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
517 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
518
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000519 if (loop_reset || phy_mode_change) {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800520 int rc;
521
522 efx->phy_op->get_settings(efx, &ecmd);
523
524 if (loop_reset || phy_mode_change) {
525 tenxpress_special_reset(efx);
526
527 /* Reset XAUI if we were in 10G, and are staying
528 * in 10G. If we're moving into and out of 10G
529 * then xaui will be reset anyway */
530 if (EFX_IS10G(efx))
531 falcon_reset_xaui(efx);
532 }
533
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800534 rc = efx->phy_op->set_settings(efx, &ecmd);
535 WARN_ON(rc);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100536 }
537
Ben Hutchings68e7f452009-04-29 08:05:08 +0000538 efx_mdio_transmit_disable(efx);
539 efx_mdio_phy_reconfigure(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800540 tenxpress_ext_loopback(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100541
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100542 phy_data->loopback_mode = efx->loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100543 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800544
545 if (efx->phy_type == PHY_TYPE_SFX7101) {
546 efx->link_speed = 10000;
547 efx->link_fd = true;
548 efx->link_up = sfx7101_link_ok(efx);
549 } else {
550 efx->phy_op->get_settings(efx, &ecmd);
551 efx->link_speed = ecmd.speed;
552 efx->link_fd = ecmd.duplex == DUPLEX_FULL;
553 efx->link_up = sft9001_link_ok(efx, &ecmd);
554 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000555 efx->link_fc = efx_mdio_get_pause(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100556}
557
Ben Hutchings8ceee662008-04-27 12:55:59 +0100558/* Poll PHY for interrupt */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800559static void tenxpress_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100560{
561 struct tenxpress_phy_data *phy_data = efx->phy_data;
Hannes Eder37d37692009-02-14 11:41:03 +0000562 bool change = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100563
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800564 if (efx->phy_type == PHY_TYPE_SFX7101) {
Hannes Eder37d37692009-02-14 11:41:03 +0000565 bool link_ok = sfx7101_link_ok(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800566 if (link_ok != efx->link_up) {
567 change = true;
568 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000569 unsigned int link_fc = efx_mdio_get_pause(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800570 if (link_fc != efx->link_fc)
571 change = true;
572 }
573 sfx7101_check_bad_lp(efx, link_ok);
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800574 } else if (efx->loopback_mode) {
575 bool link_ok = sft9001_link_ok(efx, NULL);
576 if (link_ok != efx->link_up)
577 change = true;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800578 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000579 int status = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
Ben Hutchings6bc50462009-05-15 06:06:16 +0000580 MDIO_PMA_LASI_STAT);
581 if (status & MDIO_PMA_LASI_LSALARM)
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800582 change = true;
583 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100584
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800585 if (change)
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800586 falcon_sim_phy_event(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100587
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100588 if (phy_data->phy_mode != PHY_MODE_NORMAL)
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800589 return;
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
616/* Set the RX and TX LEDs and Link LED flashing. The other LEDs
617 * (which probably aren't wired anyway) are left in AUTO mode */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100618void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100619{
620 int reg;
621
622 if (blink)
623 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
624 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
625 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
626 else
627 reg = PMA_PMD_LED_DEFAULT;
628
Ben Hutchings68e7f452009-04-29 08:05:08 +0000629 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100630}
631
Ben Hutchings307505e2008-12-26 13:48:00 -0800632static const char *const sfx7101_test_names[] = {
Ben Hutchings17967212008-12-26 13:47:25 -0800633 "bist"
634};
635
636static int
Ben Hutchings307505e2008-12-26 13:48:00 -0800637sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100638{
Ben Hutchings17967212008-12-26 13:47:25 -0800639 int rc;
640
641 if (!(flags & ETH_TEST_FL_OFFLINE))
642 return 0;
643
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100644 /* BIST is automatically run after a special software reset */
Ben Hutchings17967212008-12-26 13:47:25 -0800645 rc = tenxpress_special_reset(efx);
646 results[0] = rc ? -1 : 1;
647 return rc;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100648}
649
Ben Hutchings307505e2008-12-26 13:48:00 -0800650static const char *const sft9001_test_names[] = {
651 "bist",
652 "cable.pairA.status",
653 "cable.pairB.status",
654 "cable.pairC.status",
655 "cable.pairD.status",
656 "cable.pairA.length",
657 "cable.pairB.length",
658 "cable.pairC.length",
659 "cable.pairD.length",
660};
661
662static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
663{
664 struct ethtool_cmd ecmd;
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000665 int rc = 0, rc2, i, ctrl_reg, res_reg;
Ben Hutchings307505e2008-12-26 13:48:00 -0800666
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000667 if (flags & ETH_TEST_FL_OFFLINE)
668 efx->phy_op->get_settings(efx, &ecmd);
Ben Hutchings307505e2008-12-26 13:48:00 -0800669
670 /* Initialise cable diagnostic results to unknown failure */
671 for (i = 1; i < 9; ++i)
672 results[i] = -1;
673
674 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
675 * A cable fault is not a self-test failure, but a timeout is. */
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000676 ctrl_reg = ((1 << CDIAG_CTRL_IMMED_LBN) |
677 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
678 if (flags & ETH_TEST_FL_OFFLINE) {
679 /* Break the link in order to run full diagnostics. We
680 * must reset the PHY to resume normal service. */
681 ctrl_reg |= (1 << CDIAG_CTRL_BRK_LINK_LBN);
682 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000683 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG,
684 ctrl_reg);
Ben Hutchings307505e2008-12-26 13:48:00 -0800685 i = 0;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000686 while (efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG) &
Ben Hutchings307505e2008-12-26 13:48:00 -0800687 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
688 if (++i == 50) {
689 rc = -ETIMEDOUT;
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000690 goto out;
Ben Hutchings307505e2008-12-26 13:48:00 -0800691 }
692 msleep(100);
693 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000694 res_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_RES_REG);
Ben Hutchings307505e2008-12-26 13:48:00 -0800695 for (i = 0; i < 4; i++) {
696 int pair_res =
697 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
698 & ((1 << CDIAG_RES_WIDTH) - 1);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000699 int len_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
700 PMA_PMD_CDIAG_LEN_REG + i);
Ben Hutchings307505e2008-12-26 13:48:00 -0800701 if (pair_res == CDIAG_RES_OK)
702 results[1 + i] = 1;
703 else if (pair_res == CDIAG_RES_INVALID)
704 results[1 + i] = -1;
705 else
706 results[1 + i] = -pair_res;
707 if (pair_res != CDIAG_RES_INVALID &&
708 pair_res != CDIAG_RES_OPEN &&
709 len_reg != 0xffff)
710 results[5 + i] = len_reg;
711 }
712
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000713out:
714 if (flags & ETH_TEST_FL_OFFLINE) {
715 /* Reset, running the BIST and then resuming normal service. */
716 rc2 = tenxpress_special_reset(efx);
717 results[0] = rc2 ? -1 : 1;
718 if (!rc)
719 rc = rc2;
Ben Hutchings307505e2008-12-26 13:48:00 -0800720
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000721 rc2 = efx->phy_op->set_settings(efx, &ecmd);
722 if (!rc)
723 rc = rc2;
724 }
Ben Hutchings307505e2008-12-26 13:48:00 -0800725
726 return rc;
727}
728
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000729static void
730tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800731{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000732 u32 adv = 0, lpa = 0;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800733 int reg;
734
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800735 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000736 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000737 if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
738 adv |= ADVERTISED_1000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000739 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_STATUS);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000740 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800741 lpa |= ADVERTISED_1000baseT_Half;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000742 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800743 lpa |= ADVERTISED_1000baseT_Full;
744 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000745 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
746 if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000747 adv |= ADVERTISED_10000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000748 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
749 if (reg & MDIO_AN_10GBT_STAT_LP10G)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800750 lpa |= ADVERTISED_10000baseT_Full;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800751
Ben Hutchings68e7f452009-04-29 08:05:08 +0000752 mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800753
Ben Hutchings188586b2009-10-22 18:31:39 -0700754 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
Ben Hutchingse762cd72009-06-10 05:30:05 +0000755 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000756 ecmd->supported |= (SUPPORTED_100baseT_Full |
757 SUPPORTED_1000baseT_Full);
Ben Hutchingse762cd72009-06-10 05:30:05 +0000758 if (ecmd->speed != SPEED_10000) {
759 ecmd->eth_tp_mdix =
760 (efx_mdio_read(efx, MDIO_MMD_PMAPMD,
761 PMA_PMD_XSTATUS_REG) &
762 (1 << PMA_PMD_XSTAT_MDIX_LBN))
763 ? ETH_TP_MDI_X : ETH_TP_MDI;
764 }
765 }
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000766
767 /* In loopback, the PHY automatically brings up the correct interface,
768 * but doesn't advertise the correct speed. So override it */
769 if (efx->loopback_mode == LOOPBACK_GPHY)
770 ecmd->speed = SPEED_1000;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000771 else if (LOOPBACK_MASK(efx) & efx->phy_op->loopbacks)
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000772 ecmd->speed = SPEED_10000;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100773}
774
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000775static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100776{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000777 if (!ecmd->autoneg)
778 return -EINVAL;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800779
Ben Hutchings68e7f452009-04-29 08:05:08 +0000780 return efx_mdio_set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100781}
782
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000783static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800784{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000785 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
786 MDIO_AN_10GBT_CTRL_ADV10G,
787 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000788}
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800789
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000790static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800791{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000792 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL,
793 1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
794 advertising & ADVERTISED_1000baseT_Full);
795 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
796 MDIO_AN_10GBT_CTRL_ADV10G,
797 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800798}
799
800struct efx_phy_operations falcon_sfx7101_phy_ops = {
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800801 .macs = EFX_XMAC,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100802 .init = tenxpress_phy_init,
803 .reconfigure = tenxpress_phy_reconfigure,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800804 .poll = tenxpress_phy_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100805 .fini = tenxpress_phy_fini,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800806 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000807 .get_settings = tenxpress_get_settings,
808 .set_settings = tenxpress_set_settings,
809 .set_npage_adv = sfx7101_set_npage_adv,
Ben Hutchings307505e2008-12-26 13:48:00 -0800810 .num_tests = ARRAY_SIZE(sfx7101_test_names),
811 .test_names = sfx7101_test_names,
812 .run_tests = sfx7101_run_tests,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100813 .mmds = TENXPRESS_REQUIRED_DEVS,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800814 .loopbacks = SFX7101_LOOPBACKS,
815};
816
817struct efx_phy_operations falcon_sft9001_phy_ops = {
818 .macs = EFX_GMAC | EFX_XMAC,
819 .init = tenxpress_phy_init,
820 .reconfigure = tenxpress_phy_reconfigure,
821 .poll = tenxpress_phy_poll,
822 .fini = tenxpress_phy_fini,
823 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000824 .get_settings = tenxpress_get_settings,
825 .set_settings = tenxpress_set_settings,
826 .set_npage_adv = sft9001_set_npage_adv,
Ben Hutchings307505e2008-12-26 13:48:00 -0800827 .num_tests = ARRAY_SIZE(sft9001_test_names),
828 .test_names = sft9001_test_names,
829 .run_tests = sft9001_run_tests,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800830 .mmds = TENXPRESS_REQUIRED_DEVS,
831 .loopbacks = SFT9001_LOOPBACKS,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100832};