blob: 352cc560ed4cc63fcf64ac35f7d60acd4ef96dd1 [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"
17#include "falcon_hwdefs.h"
18#include "boards.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) | \
34 (1 << LOOPBACK_NETWORK))
35
36#define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \
37 (1 << LOOPBACK_PHYXS) | \
38 (1 << LOOPBACK_PCS) | \
39 (1 << LOOPBACK_PMAPMD) | \
40 (1 << LOOPBACK_NETWORK))
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 */
87#define PMA_PMD_LED_FULL_AUTO (0)
88/* Green and Amber under hardware control, Red off */
89#define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
90
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));
203
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 Hutchingse6fa2eb2008-12-12 22:00:17 -0800208 efx_reconfigure_port(efx);
209 rtnl_unlock();
210
211 return count;
212}
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,
295 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
301static int tenxpress_phy_init(struct efx_nic *efx)
302{
303 struct tenxpress_phy_data *phy_data;
Ben Hutchingsc6342632009-10-12 09:27:07 +0000304 u16 old_adv, adv;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100305 int rc = 0;
306
307 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
Ben Hutchings9b7bfc42008-05-16 21:20:20 +0100308 if (!phy_data)
309 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100310 efx->phy_data = phy_data;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100311 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100312
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800313 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
314 if (efx->phy_type == PHY_TYPE_SFT9001A) {
315 int reg;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000316 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
317 PMA_PMD_XCONTROL_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800318 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000319 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
320 PMA_PMD_XCONTROL_REG, reg);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800321 mdelay(200);
322 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100323
Ben Hutchings68e7f452009-04-29 08:05:08 +0000324 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800325 if (rc < 0)
326 goto fail;
327
Ben Hutchings68e7f452009-04-29 08:05:08 +0000328 rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800329 if (rc < 0)
330 goto fail;
331 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100332
333 rc = tenxpress_init(efx);
334 if (rc < 0)
335 goto fail;
336
Ben Hutchingsc6342632009-10-12 09:27:07 +0000337 /* Set pause advertising */
338 old_adv = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
339 adv = ((old_adv & ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM)) |
340 mii_advertise_flowctrl(efx->wanted_fc));
341 if (adv != old_adv) {
342 efx_mdio_write(efx, MDIO_MMD_AN, MDIO_AN_ADVERTISE, adv);
343 mdio45_nway_restart(&efx->mdio);
344 }
345
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800346 if (efx->phy_type == PHY_TYPE_SFT9001B) {
347 rc = device_create_file(&efx->pci_dev->dev,
348 &dev_attr_phy_short_reach);
349 if (rc)
350 goto fail;
351 }
352
Ben Hutchings8ceee662008-04-27 12:55:59 +0100353 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
354
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800355 /* Let XGXS and SerDes out of reset */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100356 falcon_reset_xaui(efx);
357
358 return 0;
359
360 fail:
361 kfree(efx->phy_data);
362 efx->phy_data = NULL;
363 return rc;
364}
365
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800366/* Perform a "special software reset" on the PHY. The caller is
367 * responsible for saving and restoring the PHY hardware registers
368 * properly, and masking/unmasking LASI */
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100369static int tenxpress_special_reset(struct efx_nic *efx)
370{
371 int rc, reg;
372
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100373 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
374 * a special software reset can glitch the XGMAC sufficiently for stats
Ben Hutchings1974cc22009-01-29 18:00:07 +0000375 * requests to fail. */
376 efx_stats_disable(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100377
378 /* Initiate reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000379 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100380 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000381 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100382
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100383 mdelay(200);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100384
385 /* Wait for the blocks to come out of reset */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000386 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100387 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000388 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100389
390 /* Try and reconfigure the device */
391 rc = tenxpress_init(efx);
392 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000393 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100394
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800395 /* Wait for the XGXS state machine to churn */
396 mdelay(10);
Ben Hutchings1974cc22009-01-29 18:00:07 +0000397out:
398 efx_stats_enable(efx);
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100399 return rc;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100400}
401
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800402static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100403{
404 struct tenxpress_phy_data *pd = efx->phy_data;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800405 bool bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100406 int reg;
407
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800408 if (link_ok) {
409 bad_lp = false;
410 } else {
411 /* Check that AN has started but not completed. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000412 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
413 if (!(reg & MDIO_AN_STAT1_LPABLE))
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800414 return; /* LP status is unknown */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000415 bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800416 if (bad_lp)
417 pd->bad_lp_tries++;
418 }
419
Ben Hutchings8ceee662008-04-27 12:55:59 +0100420 /* Nothing to do if all is well and was previously so. */
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800421 if (!pd->bad_lp_tries)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100422 return;
423
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800424 /* Use the RX (red) LED as an error indicator once we've seen AN
425 * failure several times in a row, and also log a message. */
426 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000427 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
428 PMA_PMD_LED_OVERR_REG);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800429 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
430 if (!bad_lp) {
431 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
432 } else {
433 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
434 EFX_ERR(efx, "appears to be plugged into a port"
435 " that is not 10GBASE-T capable. The PHY"
436 " supports 10GBASE-T ONLY, so no link can"
437 " be established\n");
438 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000439 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
440 PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800441 pd->bad_lp_tries = bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100442 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100443}
444
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800445static bool sfx7101_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100446{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000447 return efx_mdio_links_ok(efx,
448 MDIO_DEVS_PMAPMD |
449 MDIO_DEVS_PCS |
450 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800451}
452
453static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
454{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800455 u32 reg;
456
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800457 if (efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800458 return false;
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800459 else if (efx->loopback_mode == LOOPBACK_GPHY)
460 return true;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800461 else if (efx->loopback_mode)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000462 return efx_mdio_links_ok(efx,
463 MDIO_DEVS_PMAPMD |
464 MDIO_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800465
466 /* We must use the same definition of link state as LASI,
467 * otherwise we can miss a link state transition
468 */
469 if (ecmd->speed == 10000) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000470 reg = efx_mdio_read(efx, MDIO_MMD_PCS, MDIO_PCS_10GBRT_STAT1);
471 return reg & MDIO_PCS_10GBRT_STAT1_BLKLK;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800472 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000473 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_STATUS_REG);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800474 return reg & (1 << C22EXT_STATUS_LINK_LBN);
475 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100476}
477
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800478static void tenxpress_ext_loopback(struct efx_nic *efx)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100479{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000480 efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
481 1 << LOOPBACK_NEAR_LBN,
482 efx->loopback_mode == LOOPBACK_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800483 if (efx->phy_type != PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000484 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, GPHY_XCONTROL_REG,
485 1 << GPHY_LOOPBACK_NEAR_LBN,
486 efx->loopback_mode == LOOPBACK_GPHY);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800487}
488
489static void tenxpress_low_power(struct efx_nic *efx)
490{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800491 if (efx->phy_type == PHY_TYPE_SFX7101)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000492 efx_mdio_set_mmds_lpower(
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800493 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
494 TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100495 else
Ben Hutchings68e7f452009-04-29 08:05:08 +0000496 efx_mdio_set_flag(
497 efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG,
498 1 << PMA_PMD_EXT_LPOWER_LBN,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800499 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100500}
501
Ben Hutchings8ceee662008-04-27 12:55:59 +0100502static void tenxpress_phy_reconfigure(struct efx_nic *efx)
503{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100504 struct tenxpress_phy_data *phy_data = efx->phy_data;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800505 struct ethtool_cmd ecmd;
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000506 bool phy_mode_change, loop_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100507
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800508 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100509 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100510 return;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100511 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100512
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800513 tenxpress_low_power(efx);
514
515 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
516 phy_data->phy_mode != PHY_MODE_NORMAL);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800517 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
518 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
519
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000520 if (loop_reset || phy_mode_change) {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800521 int rc;
522
523 efx->phy_op->get_settings(efx, &ecmd);
524
525 if (loop_reset || phy_mode_change) {
526 tenxpress_special_reset(efx);
527
528 /* Reset XAUI if we were in 10G, and are staying
529 * in 10G. If we're moving into and out of 10G
530 * then xaui will be reset anyway */
531 if (EFX_IS10G(efx))
532 falcon_reset_xaui(efx);
533 }
534
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800535 rc = efx->phy_op->set_settings(efx, &ecmd);
536 WARN_ON(rc);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100537 }
538
Ben Hutchings68e7f452009-04-29 08:05:08 +0000539 efx_mdio_transmit_disable(efx);
540 efx_mdio_phy_reconfigure(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800541 tenxpress_ext_loopback(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100542
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100543 phy_data->loopback_mode = efx->loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100544 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800545
546 if (efx->phy_type == PHY_TYPE_SFX7101) {
547 efx->link_speed = 10000;
548 efx->link_fd = true;
549 efx->link_up = sfx7101_link_ok(efx);
550 } else {
551 efx->phy_op->get_settings(efx, &ecmd);
552 efx->link_speed = ecmd.speed;
553 efx->link_fd = ecmd.duplex == DUPLEX_FULL;
554 efx->link_up = sft9001_link_ok(efx, &ecmd);
555 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000556 efx->link_fc = efx_mdio_get_pause(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100557}
558
Ben Hutchings8ceee662008-04-27 12:55:59 +0100559/* Poll PHY for interrupt */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800560static void tenxpress_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100561{
562 struct tenxpress_phy_data *phy_data = efx->phy_data;
Hannes Eder37d37692009-02-14 11:41:03 +0000563 bool change = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100564
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800565 if (efx->phy_type == PHY_TYPE_SFX7101) {
Hannes Eder37d37692009-02-14 11:41:03 +0000566 bool link_ok = sfx7101_link_ok(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800567 if (link_ok != efx->link_up) {
568 change = true;
569 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000570 unsigned int link_fc = efx_mdio_get_pause(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800571 if (link_fc != efx->link_fc)
572 change = true;
573 }
574 sfx7101_check_bad_lp(efx, link_ok);
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800575 } else if (efx->loopback_mode) {
576 bool link_ok = sft9001_link_ok(efx, NULL);
577 if (link_ok != efx->link_up)
578 change = true;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800579 } else {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000580 int status = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
Ben Hutchings6bc50462009-05-15 06:06:16 +0000581 MDIO_PMA_LASI_STAT);
582 if (status & MDIO_PMA_LASI_LSALARM)
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800583 change = true;
584 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100585
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800586 if (change)
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800587 falcon_sim_phy_event(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100588
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100589 if (phy_data->phy_mode != PHY_MODE_NORMAL)
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800590 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100591}
592
593static void tenxpress_phy_fini(struct efx_nic *efx)
594{
595 int reg;
596
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800597 if (efx->phy_type == PHY_TYPE_SFT9001B)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800598 device_remove_file(&efx->pci_dev->dev,
599 &dev_attr_phy_short_reach);
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800600
601 if (efx->phy_type == PHY_TYPE_SFX7101) {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800602 /* Power down the LNPGA */
603 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000604 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100605
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800606 /* Waiting here ensures that the board fini, which can turn
607 * off the power to the PHY, won't get run until the LNPGA
608 * powerdown has been given long enough to complete. */
609 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
610 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100611
612 kfree(efx->phy_data);
613 efx->phy_data = NULL;
614}
615
616
617/* Set the RX and TX LEDs and Link LED flashing. The other LEDs
618 * (which probably aren't wired anyway) are left in AUTO mode */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100619void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100620{
621 int reg;
622
623 if (blink)
624 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
625 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
626 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
627 else
628 reg = PMA_PMD_LED_DEFAULT;
629
Ben Hutchings68e7f452009-04-29 08:05:08 +0000630 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100631}
632
Ben Hutchings307505e2008-12-26 13:48:00 -0800633static const char *const sfx7101_test_names[] = {
Ben Hutchings17967212008-12-26 13:47:25 -0800634 "bist"
635};
636
637static int
Ben Hutchings307505e2008-12-26 13:48:00 -0800638sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100639{
Ben Hutchings17967212008-12-26 13:47:25 -0800640 int rc;
641
642 if (!(flags & ETH_TEST_FL_OFFLINE))
643 return 0;
644
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100645 /* BIST is automatically run after a special software reset */
Ben Hutchings17967212008-12-26 13:47:25 -0800646 rc = tenxpress_special_reset(efx);
647 results[0] = rc ? -1 : 1;
648 return rc;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100649}
650
Ben Hutchings307505e2008-12-26 13:48:00 -0800651static const char *const sft9001_test_names[] = {
652 "bist",
653 "cable.pairA.status",
654 "cable.pairB.status",
655 "cable.pairC.status",
656 "cable.pairD.status",
657 "cable.pairA.length",
658 "cable.pairB.length",
659 "cable.pairC.length",
660 "cable.pairD.length",
661};
662
663static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
664{
665 struct ethtool_cmd ecmd;
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000666 int rc = 0, rc2, i, ctrl_reg, res_reg;
Ben Hutchings307505e2008-12-26 13:48:00 -0800667
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000668 if (flags & ETH_TEST_FL_OFFLINE)
669 efx->phy_op->get_settings(efx, &ecmd);
Ben Hutchings307505e2008-12-26 13:48:00 -0800670
671 /* Initialise cable diagnostic results to unknown failure */
672 for (i = 1; i < 9; ++i)
673 results[i] = -1;
674
675 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
676 * A cable fault is not a self-test failure, but a timeout is. */
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000677 ctrl_reg = ((1 << CDIAG_CTRL_IMMED_LBN) |
678 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
679 if (flags & ETH_TEST_FL_OFFLINE) {
680 /* Break the link in order to run full diagnostics. We
681 * must reset the PHY to resume normal service. */
682 ctrl_reg |= (1 << CDIAG_CTRL_BRK_LINK_LBN);
683 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000684 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG,
685 ctrl_reg);
Ben Hutchings307505e2008-12-26 13:48:00 -0800686 i = 0;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000687 while (efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG) &
Ben Hutchings307505e2008-12-26 13:48:00 -0800688 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
689 if (++i == 50) {
690 rc = -ETIMEDOUT;
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000691 goto out;
Ben Hutchings307505e2008-12-26 13:48:00 -0800692 }
693 msleep(100);
694 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000695 res_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_RES_REG);
Ben Hutchings307505e2008-12-26 13:48:00 -0800696 for (i = 0; i < 4; i++) {
697 int pair_res =
698 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
699 & ((1 << CDIAG_RES_WIDTH) - 1);
Ben Hutchings68e7f452009-04-29 08:05:08 +0000700 int len_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
701 PMA_PMD_CDIAG_LEN_REG + i);
Ben Hutchings307505e2008-12-26 13:48:00 -0800702 if (pair_res == CDIAG_RES_OK)
703 results[1 + i] = 1;
704 else if (pair_res == CDIAG_RES_INVALID)
705 results[1 + i] = -1;
706 else
707 results[1 + i] = -pair_res;
708 if (pair_res != CDIAG_RES_INVALID &&
709 pair_res != CDIAG_RES_OPEN &&
710 len_reg != 0xffff)
711 results[5 + i] = len_reg;
712 }
713
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000714out:
715 if (flags & ETH_TEST_FL_OFFLINE) {
716 /* Reset, running the BIST and then resuming normal service. */
717 rc2 = tenxpress_special_reset(efx);
718 results[0] = rc2 ? -1 : 1;
719 if (!rc)
720 rc = rc2;
Ben Hutchings307505e2008-12-26 13:48:00 -0800721
Ben Hutchings22ef02c2009-02-27 13:04:07 +0000722 rc2 = efx->phy_op->set_settings(efx, &ecmd);
723 if (!rc)
724 rc = rc2;
725 }
Ben Hutchings307505e2008-12-26 13:48:00 -0800726
727 return rc;
728}
729
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000730static void
731tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800732{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000733 u32 adv = 0, lpa = 0;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800734 int reg;
735
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800736 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000737 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000738 if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
739 adv |= ADVERTISED_1000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000740 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_STATUS);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000741 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800742 lpa |= ADVERTISED_1000baseT_Half;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000743 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800744 lpa |= ADVERTISED_1000baseT_Full;
745 }
Ben Hutchings68e7f452009-04-29 08:05:08 +0000746 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
747 if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000748 adv |= ADVERTISED_10000baseT_Full;
Ben Hutchings68e7f452009-04-29 08:05:08 +0000749 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
750 if (reg & MDIO_AN_10GBT_STAT_LP10G)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800751 lpa |= ADVERTISED_10000baseT_Full;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800752
Ben Hutchings68e7f452009-04-29 08:05:08 +0000753 mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800754
Ben Hutchings188586b2009-10-22 18:31:39 -0700755 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
Ben Hutchingse762cd72009-06-10 05:30:05 +0000756 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000757 ecmd->supported |= (SUPPORTED_100baseT_Full |
758 SUPPORTED_1000baseT_Full);
Ben Hutchingse762cd72009-06-10 05:30:05 +0000759 if (ecmd->speed != SPEED_10000) {
760 ecmd->eth_tp_mdix =
761 (efx_mdio_read(efx, MDIO_MMD_PMAPMD,
762 PMA_PMD_XSTATUS_REG) &
763 (1 << PMA_PMD_XSTAT_MDIX_LBN))
764 ? ETH_TP_MDI_X : ETH_TP_MDI;
765 }
766 }
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000767
768 /* In loopback, the PHY automatically brings up the correct interface,
769 * but doesn't advertise the correct speed. So override it */
770 if (efx->loopback_mode == LOOPBACK_GPHY)
771 ecmd->speed = SPEED_1000;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000772 else if (LOOPBACK_MASK(efx) & efx->phy_op->loopbacks)
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000773 ecmd->speed = SPEED_10000;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100774}
775
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000776static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100777{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000778 if (!ecmd->autoneg)
779 return -EINVAL;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800780
Ben Hutchings68e7f452009-04-29 08:05:08 +0000781 return efx_mdio_set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100782}
783
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000784static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800785{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000786 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
787 MDIO_AN_10GBT_CTRL_ADV10G,
788 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000789}
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800790
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000791static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800792{
Ben Hutchings68e7f452009-04-29 08:05:08 +0000793 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL,
794 1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
795 advertising & ADVERTISED_1000baseT_Full);
796 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
797 MDIO_AN_10GBT_CTRL_ADV10G,
798 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800799}
800
801struct efx_phy_operations falcon_sfx7101_phy_ops = {
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800802 .macs = EFX_XMAC,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100803 .init = tenxpress_phy_init,
804 .reconfigure = tenxpress_phy_reconfigure,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800805 .poll = tenxpress_phy_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100806 .fini = tenxpress_phy_fini,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800807 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000808 .get_settings = tenxpress_get_settings,
809 .set_settings = tenxpress_set_settings,
810 .set_npage_adv = sfx7101_set_npage_adv,
Ben Hutchings307505e2008-12-26 13:48:00 -0800811 .num_tests = ARRAY_SIZE(sfx7101_test_names),
812 .test_names = sfx7101_test_names,
813 .run_tests = sfx7101_run_tests,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100814 .mmds = TENXPRESS_REQUIRED_DEVS,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800815 .loopbacks = SFX7101_LOOPBACKS,
816};
817
818struct efx_phy_operations falcon_sft9001_phy_ops = {
819 .macs = EFX_GMAC | EFX_XMAC,
820 .init = tenxpress_phy_init,
821 .reconfigure = tenxpress_phy_reconfigure,
822 .poll = tenxpress_phy_poll,
823 .fini = tenxpress_phy_fini,
824 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000825 .get_settings = tenxpress_get_settings,
826 .set_settings = tenxpress_set_settings,
827 .set_npage_adv = sft9001_set_npage_adv,
Ben Hutchings307505e2008-12-26 13:48:00 -0800828 .num_tests = ARRAY_SIZE(sft9001_test_names),
829 .test_names = sft9001_test_names,
830 .run_tests = sft9001_run_tests,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800831 .mmds = TENXPRESS_REQUIRED_DEVS,
832 .loopbacks = SFT9001_LOOPBACKS,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100833};