blob: ac9eeab79f202a051dd1000a44ba7d7404d93b20 [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 Hutchings27dd2ca2008-12-12 21:44:14 -080026#define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PMAPMD | \
27 MDIO_MMDREG_DEVS_PCS | \
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080028 MDIO_MMDREG_DEVS_PHYXS | \
29 MDIO_MMDREG_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
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080047/* LASI Control */
48#define PMA_PMD_LASI_CTRL 36866
49#define PMA_PMD_LASI_STATUS 36869
50#define PMA_PMD_LS_ALARM_LBN 0
51#define PMA_PMD_LS_ALARM_WIDTH 1
52#define PMA_PMD_TX_ALARM_LBN 1
53#define PMA_PMD_TX_ALARM_WIDTH 1
54#define PMA_PMD_RX_ALARM_LBN 2
55#define PMA_PMD_RX_ALARM_WIDTH 1
56#define PMA_PMD_AN_ALARM_LBN 3
57#define PMA_PMD_AN_ALARM_WIDTH 1
58
Ben Hutchings8ceee662008-04-27 12:55:59 +010059/* Extended control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080060#define PMA_PMD_XCONTROL_REG 49152
61#define PMA_PMD_EXT_GMII_EN_LBN 1
62#define PMA_PMD_EXT_GMII_EN_WIDTH 1
63#define PMA_PMD_EXT_CLK_OUT_LBN 2
64#define PMA_PMD_EXT_CLK_OUT_WIDTH 1
65#define PMA_PMD_LNPGA_POWERDOWN_LBN 8 /* SFX7101 only */
66#define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
67#define PMA_PMD_EXT_CLK312_LBN 8 /* SFT9001 only */
68#define PMA_PMD_EXT_CLK312_WIDTH 1
69#define PMA_PMD_EXT_LPOWER_LBN 12
70#define PMA_PMD_EXT_LPOWER_WIDTH 1
Steve Hodgson869b5b32009-01-29 17:48:10 +000071#define PMA_PMD_EXT_ROBUST_LBN 14
72#define PMA_PMD_EXT_ROBUST_WIDTH 1
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080073#define PMA_PMD_EXT_SSR_LBN 15
74#define PMA_PMD_EXT_SSR_WIDTH 1
Ben Hutchings8ceee662008-04-27 12:55:59 +010075
76/* extended status register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080077#define PMA_PMD_XSTATUS_REG 49153
Ben Hutchings8ceee662008-04-27 12:55:59 +010078#define PMA_PMD_XSTAT_FLP_LBN (12)
79
80/* LED control register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080081#define PMA_PMD_LED_CTRL_REG 49159
Ben Hutchings8ceee662008-04-27 12:55:59 +010082#define PMA_PMA_LED_ACTIVITY_LBN (3)
83
84/* LED function override register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -080085#define PMA_PMD_LED_OVERR_REG 49161
Ben Hutchings8ceee662008-04-27 12:55:59 +010086/* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
87#define PMA_PMD_LED_LINK_LBN (0)
88#define PMA_PMD_LED_SPEED_LBN (2)
89#define PMA_PMD_LED_TX_LBN (4)
90#define PMA_PMD_LED_RX_LBN (6)
91/* Override settings */
92#define PMA_PMD_LED_AUTO (0) /* H/W control */
93#define PMA_PMD_LED_ON (1)
94#define PMA_PMD_LED_OFF (2)
95#define PMA_PMD_LED_FLASH (3)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080096#define PMA_PMD_LED_MASK 3
Ben Hutchings8ceee662008-04-27 12:55:59 +010097/* All LEDs under hardware control */
98#define PMA_PMD_LED_FULL_AUTO (0)
99/* Green and Amber under hardware control, Red off */
100#define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
101
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800102#define PMA_PMD_SPEED_ENABLE_REG 49192
103#define PMA_PMD_100TX_ADV_LBN 1
104#define PMA_PMD_100TX_ADV_WIDTH 1
105#define PMA_PMD_1000T_ADV_LBN 2
106#define PMA_PMD_1000T_ADV_WIDTH 1
107#define PMA_PMD_10000T_ADV_LBN 3
108#define PMA_PMD_10000T_ADV_WIDTH 1
109#define PMA_PMD_SPEED_LBN 4
110#define PMA_PMD_SPEED_WIDTH 4
Ben Hutchings8ceee662008-04-27 12:55:59 +0100111
Ben Hutchings307505e2008-12-26 13:48:00 -0800112/* Cable diagnostics - SFT9001 only */
113#define PMA_PMD_CDIAG_CTRL_REG 49213
114#define CDIAG_CTRL_IMMED_LBN 15
115#define CDIAG_CTRL_BRK_LINK_LBN 12
116#define CDIAG_CTRL_IN_PROG_LBN 11
117#define CDIAG_CTRL_LEN_UNIT_LBN 10
118#define CDIAG_CTRL_LEN_METRES 1
119#define PMA_PMD_CDIAG_RES_REG 49174
120#define CDIAG_RES_A_LBN 12
121#define CDIAG_RES_B_LBN 8
122#define CDIAG_RES_C_LBN 4
123#define CDIAG_RES_D_LBN 0
124#define CDIAG_RES_WIDTH 4
125#define CDIAG_RES_OPEN 2
126#define CDIAG_RES_OK 1
127#define CDIAG_RES_INVALID 0
128/* Set of 4 registers for pairs A-D */
129#define PMA_PMD_CDIAG_LEN_REG 49175
130
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800131/* Serdes control registers - SFT9001 only */
132#define PMA_PMD_CSERDES_CTRL_REG 64258
133/* Set the 156.25 MHz output to 312.5 MHz to drive Falcon's XMAC */
134#define PMA_PMD_CSERDES_DEFAULT 0x000f
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100135
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800136/* Misc register defines - SFX7101 only */
137#define PCS_CLOCK_CTRL_REG 55297
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138#define PLL312_RST_N_LBN 2
139
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800140#define PCS_SOFT_RST2_REG 55302
Ben Hutchings8ceee662008-04-27 12:55:59 +0100141#define SERDES_RST_N_LBN 13
142#define XGXS_RST_N_LBN 12
143
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800144#define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100145#define CLK312_EN_LBN 3
146
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100147/* PHYXS registers */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800148#define PHYXS_XCONTROL_REG 49152
149#define PHYXS_RESET_LBN 15
150#define PHYXS_RESET_WIDTH 1
151
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100152#define PHYXS_TEST1 (49162)
153#define LOOPBACK_NEAR_LBN (8)
154#define LOOPBACK_NEAR_WIDTH (1)
155
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800156#define PCS_10GBASET_STAT1 32
157#define PCS_10GBASET_BLKLK_LBN 0
158#define PCS_10GBASET_BLKLK_WIDTH 1
159
Ben Hutchings8ceee662008-04-27 12:55:59 +0100160/* Boot status register */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800161#define PCS_BOOT_STATUS_REG 53248
Ben Hutchings8ceee662008-04-27 12:55:59 +0100162#define PCS_BOOT_FATAL_ERR_LBN (0)
163#define PCS_BOOT_PROGRESS_LBN (1)
164#define PCS_BOOT_PROGRESS_WIDTH (2)
165#define PCS_BOOT_COMPLETE_LBN (3)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800166
Ben Hutchings8ceee662008-04-27 12:55:59 +0100167#define PCS_BOOT_MAX_DELAY (100)
168#define PCS_BOOT_POLL_DELAY (10)
169
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800170/* 100M/1G PHY registers */
171#define GPHY_XCONTROL_REG 49152
172#define GPHY_ISOLATE_LBN 10
173#define GPHY_ISOLATE_WIDTH 1
174#define GPHY_DUPLEX_LBN 8
175#define GPHY_DUPLEX_WIDTH 1
176#define GPHY_LOOPBACK_NEAR_LBN 14
177#define GPHY_LOOPBACK_NEAR_WIDTH 1
178
179#define C22EXT_STATUS_REG 49153
180#define C22EXT_STATUS_LINK_LBN 2
181#define C22EXT_STATUS_LINK_WIDTH 1
182
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000183#define C22EXT_MSTSLV_CTRL 49161
184#define C22EXT_MSTSLV_CTRL_ADV_1000_HD_LBN 8
185#define C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN 9
186
187#define C22EXT_MSTSLV_STATUS 49162
188#define C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN 10
189#define C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN 11
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800190
Ben Hutchings8ceee662008-04-27 12:55:59 +0100191/* Time to wait between powering down the LNPGA and turning off the power
192 * rails */
193#define LNPGA_PDOWN_WAIT (HZ / 5)
194
Ben Hutchings8ceee662008-04-27 12:55:59 +0100195struct tenxpress_phy_data {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100196 enum efx_loopback_mode loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100197 enum efx_phy_mode phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100198 int bad_lp_tries;
199};
200
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800201static ssize_t show_phy_short_reach(struct device *dev,
202 struct device_attribute *attr, char *buf)
203{
204 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
205 int reg;
206
207 reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
208 MDIO_PMAPMD_10GBT_TXPWR);
209 return sprintf(buf, "%d\n",
210 !!(reg & (1 << MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN)));
211}
212
213static ssize_t set_phy_short_reach(struct device *dev,
214 struct device_attribute *attr,
215 const char *buf, size_t count)
216{
217 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
218
219 rtnl_lock();
220 mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
221 MDIO_PMAPMD_10GBT_TXPWR,
222 MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN,
223 count != 0 && *buf != '0');
224 efx_reconfigure_port(efx);
225 rtnl_unlock();
226
227 return count;
228}
229
230static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
231 set_phy_short_reach);
232
Ben Hutchings8ceee662008-04-27 12:55:59 +0100233/* Check that the C166 has booted successfully */
234static int tenxpress_phy_check(struct efx_nic *efx)
235{
236 int phy_id = efx->mii.phy_id;
237 int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY;
238 int boot_stat;
239
240 /* Wait for the boot to complete (or not) */
241 while (count) {
242 boot_stat = mdio_clause45_read(efx, phy_id,
243 MDIO_MMD_PCS,
244 PCS_BOOT_STATUS_REG);
245 if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN))
246 break;
247 count--;
248 udelay(PCS_BOOT_POLL_DELAY);
249 }
250
251 if (!count) {
252 EFX_ERR(efx, "%s: PHY boot timed out. Last status "
253 "%x\n", __func__,
254 (boot_stat >> PCS_BOOT_PROGRESS_LBN) &
255 ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1));
256 return -ETIMEDOUT;
257 }
258
259 return 0;
260}
261
Ben Hutchings8ceee662008-04-27 12:55:59 +0100262static int tenxpress_init(struct efx_nic *efx)
263{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800264 int phy_id = efx->mii.phy_id;
265 int reg;
266 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100267
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800268 if (efx->phy_type == PHY_TYPE_SFX7101) {
269 /* Enable 312.5 MHz clock */
270 mdio_clause45_write(efx, phy_id,
271 MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
272 1 << CLK312_EN_LBN);
273 } else {
274 /* Enable 312.5 MHz clock and GMII */
275 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
276 PMA_PMD_XCONTROL_REG);
277 reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
278 (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
Steve Hodgson869b5b32009-01-29 17:48:10 +0000279 (1 << PMA_PMD_EXT_CLK312_LBN) |
280 (1 << PMA_PMD_EXT_ROBUST_LBN));
281
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800282 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
283 PMA_PMD_XCONTROL_REG, reg);
284 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
285 GPHY_XCONTROL_REG, GPHY_ISOLATE_LBN,
286 false);
287 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100288
289 rc = tenxpress_phy_check(efx);
290 if (rc < 0)
291 return rc;
292
293 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800294 if (efx->phy_type == PHY_TYPE_SFX7101) {
295 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
296 PMA_PMD_LED_CTRL_REG,
297 PMA_PMA_LED_ACTIVITY_LBN,
298 true);
299 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
300 PMA_PMD_LED_OVERR_REG, PMA_PMD_LED_DEFAULT);
301 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100302
303 return rc;
304}
305
306static int tenxpress_phy_init(struct efx_nic *efx)
307{
308 struct tenxpress_phy_data *phy_data;
309 int rc = 0;
310
311 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
Ben Hutchings9b7bfc42008-05-16 21:20:20 +0100312 if (!phy_data)
313 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100314 efx->phy_data = phy_data;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100315 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100316
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800317 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
318 if (efx->phy_type == PHY_TYPE_SFT9001A) {
319 int reg;
320 reg = mdio_clause45_read(efx, efx->mii.phy_id,
321 MDIO_MMD_PMAPMD,
322 PMA_PMD_XCONTROL_REG);
323 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
324 mdio_clause45_write(efx, efx->mii.phy_id,
325 MDIO_MMD_PMAPMD,
326 PMA_PMD_XCONTROL_REG, reg);
327 mdelay(200);
328 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100329
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800330 rc = mdio_clause45_wait_reset_mmds(efx,
331 TENXPRESS_REQUIRED_DEVS);
332 if (rc < 0)
333 goto fail;
334
335 rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
336 if (rc < 0)
337 goto fail;
338 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100339
340 rc = tenxpress_init(efx);
341 if (rc < 0)
342 goto fail;
Steve Hodgson4b988282009-01-29 17:50:51 +0000343 mdio_clause45_set_pause(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100344
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 */
378 reg = mdio_clause45_read(efx, efx->mii.phy_id,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800379 MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100380 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
381 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800382 PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100383
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100384 mdelay(200);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100385
386 /* Wait for the blocks to come out of reset */
387 rc = mdio_clause45_wait_reset_mmds(efx,
388 TENXPRESS_REQUIRED_DEVS);
389 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000390 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100391
392 /* Try and reconfigure the device */
393 rc = tenxpress_init(efx);
394 if (rc < 0)
Ben Hutchings1974cc22009-01-29 18:00:07 +0000395 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100396
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800397 /* Wait for the XGXS state machine to churn */
398 mdelay(10);
Ben Hutchings1974cc22009-01-29 18:00:07 +0000399out:
400 efx_stats_enable(efx);
Ben Hutchingsc8fcc492008-09-01 12:49:25 +0100401 return rc;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100402}
403
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800404static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100405{
406 struct tenxpress_phy_data *pd = efx->phy_data;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800407 int phy_id = efx->mii.phy_id;
408 bool bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100409 int reg;
410
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800411 if (link_ok) {
412 bad_lp = false;
413 } else {
414 /* Check that AN has started but not completed. */
415 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
416 MDIO_AN_STATUS);
417 if (!(reg & (1 << MDIO_AN_STATUS_LP_AN_CAP_LBN)))
418 return; /* LP status is unknown */
419 bad_lp = !(reg & (1 << MDIO_AN_STATUS_AN_DONE_LBN));
420 if (bad_lp)
421 pd->bad_lp_tries++;
422 }
423
Ben Hutchings8ceee662008-04-27 12:55:59 +0100424 /* Nothing to do if all is well and was previously so. */
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800425 if (!pd->bad_lp_tries)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100426 return;
427
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800428 /* Use the RX (red) LED as an error indicator once we've seen AN
429 * failure several times in a row, and also log a message. */
430 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
431 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
432 PMA_PMD_LED_OVERR_REG);
433 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
434 if (!bad_lp) {
435 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
436 } else {
437 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
438 EFX_ERR(efx, "appears to be plugged into a port"
439 " that is not 10GBASE-T capable. The PHY"
440 " supports 10GBASE-T ONLY, so no link can"
441 " be established\n");
442 }
443 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
444 PMA_PMD_LED_OVERR_REG, reg);
445 pd->bad_lp_tries = bad_lp;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100446 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100447}
448
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800449static bool sfx7101_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100450{
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800451 return mdio_clause45_links_ok(efx,
452 MDIO_MMDREG_DEVS_PMAPMD |
453 MDIO_MMDREG_DEVS_PCS |
454 MDIO_MMDREG_DEVS_PHYXS);
455}
456
457static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
458{
459 int phy_id = efx->mii.phy_id;
460 u32 reg;
461
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800462 if (efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800463 return false;
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800464 else if (efx->loopback_mode == LOOPBACK_GPHY)
465 return true;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800466 else if (efx->loopback_mode)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800467 return mdio_clause45_links_ok(efx,
468 MDIO_MMDREG_DEVS_PMAPMD |
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800469 MDIO_MMDREG_DEVS_PHYXS);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800470
471 /* We must use the same definition of link state as LASI,
472 * otherwise we can miss a link state transition
473 */
474 if (ecmd->speed == 10000) {
475 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS,
476 PCS_10GBASET_STAT1);
477 return reg & (1 << PCS_10GBASET_BLKLK_LBN);
478 } else {
479 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
480 C22EXT_STATUS_REG);
481 return reg & (1 << C22EXT_STATUS_LINK_LBN);
482 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100483}
484
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800485static void tenxpress_ext_loopback(struct efx_nic *efx)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100486{
487 int phy_id = efx->mii.phy_id;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100488
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800489 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
490 PHYXS_TEST1, LOOPBACK_NEAR_LBN,
491 efx->loopback_mode == LOOPBACK_PHYXS);
492 if (efx->phy_type != PHY_TYPE_SFX7101)
493 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
494 GPHY_XCONTROL_REG,
495 GPHY_LOOPBACK_NEAR_LBN,
496 efx->loopback_mode == LOOPBACK_GPHY);
497}
498
499static void tenxpress_low_power(struct efx_nic *efx)
500{
501 int phy_id = efx->mii.phy_id;
502
503 if (efx->phy_type == PHY_TYPE_SFX7101)
504 mdio_clause45_set_mmds_lpower(
505 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
506 TENXPRESS_REQUIRED_DEVS);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100507 else
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800508 mdio_clause45_set_flag(
509 efx, phy_id, MDIO_MMD_PMAPMD,
510 PMA_PMD_XCONTROL_REG, PMA_PMD_EXT_LPOWER_LBN,
511 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100512}
513
Ben Hutchings8ceee662008-04-27 12:55:59 +0100514static void tenxpress_phy_reconfigure(struct efx_nic *efx)
515{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100516 struct tenxpress_phy_data *phy_data = efx->phy_data;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800517 struct ethtool_cmd ecmd;
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000518 bool phy_mode_change, loop_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100519
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800520 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100521 phy_data->phy_mode = efx->phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100522 return;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100523 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100524
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800525 tenxpress_low_power(efx);
526
527 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
528 phy_data->phy_mode != PHY_MODE_NORMAL);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800529 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
530 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
531
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000532 if (loop_reset || phy_mode_change) {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800533 int rc;
534
535 efx->phy_op->get_settings(efx, &ecmd);
536
537 if (loop_reset || phy_mode_change) {
538 tenxpress_special_reset(efx);
539
540 /* Reset XAUI if we were in 10G, and are staying
541 * in 10G. If we're moving into and out of 10G
542 * then xaui will be reset anyway */
543 if (EFX_IS10G(efx))
544 falcon_reset_xaui(efx);
545 }
546
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800547 rc = efx->phy_op->set_settings(efx, &ecmd);
548 WARN_ON(rc);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100549 }
550
551 mdio_clause45_transmit_disable(efx);
552 mdio_clause45_phy_reconfigure(efx);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800553 tenxpress_ext_loopback(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100554
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100555 phy_data->loopback_mode = efx->loopback_mode;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100556 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800557
558 if (efx->phy_type == PHY_TYPE_SFX7101) {
559 efx->link_speed = 10000;
560 efx->link_fd = true;
561 efx->link_up = sfx7101_link_ok(efx);
562 } else {
563 efx->phy_op->get_settings(efx, &ecmd);
564 efx->link_speed = ecmd.speed;
565 efx->link_fd = ecmd.duplex == DUPLEX_FULL;
566 efx->link_up = sft9001_link_ok(efx, &ecmd);
567 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800568 efx->link_fc = mdio_clause45_get_pause(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100569}
570
Ben Hutchings8ceee662008-04-27 12:55:59 +0100571/* Poll PHY for interrupt */
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800572static void tenxpress_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100573{
574 struct tenxpress_phy_data *phy_data = efx->phy_data;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800575 bool change = false, link_ok;
576 unsigned link_fc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100577
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800578 if (efx->phy_type == PHY_TYPE_SFX7101) {
579 link_ok = sfx7101_link_ok(efx);
580 if (link_ok != efx->link_up) {
581 change = true;
582 } else {
583 link_fc = mdio_clause45_get_pause(efx);
584 if (link_fc != efx->link_fc)
585 change = true;
586 }
587 sfx7101_check_bad_lp(efx, link_ok);
Ben Hutchingscaa8d8b2008-12-26 13:46:12 -0800588 } else if (efx->loopback_mode) {
589 bool link_ok = sft9001_link_ok(efx, NULL);
590 if (link_ok != efx->link_up)
591 change = true;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800592 } else {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800593 u32 status = mdio_clause45_read(efx, efx->mii.phy_id,
594 MDIO_MMD_PMAPMD,
595 PMA_PMD_LASI_STATUS);
596 if (status & (1 << PMA_PMD_LS_ALARM_LBN))
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800597 change = true;
598 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100599
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800600 if (change)
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800601 falcon_sim_phy_event(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100602
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100603 if (phy_data->phy_mode != PHY_MODE_NORMAL)
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800604 return;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100605}
606
607static void tenxpress_phy_fini(struct efx_nic *efx)
608{
609 int reg;
610
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800611 if (efx->phy_type == PHY_TYPE_SFT9001B)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800612 device_remove_file(&efx->pci_dev->dev,
613 &dev_attr_phy_short_reach);
Ben Hutchings2a7e6372009-01-11 00:18:13 -0800614
615 if (efx->phy_type == PHY_TYPE_SFX7101) {
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800616 /* Power down the LNPGA */
617 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
618 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
619 PMA_PMD_XCONTROL_REG, reg);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100620
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800621 /* Waiting here ensures that the board fini, which can turn
622 * off the power to the PHY, won't get run until the LNPGA
623 * powerdown has been given long enough to complete. */
624 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
625 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100626
627 kfree(efx->phy_data);
628 efx->phy_data = NULL;
629}
630
631
632/* Set the RX and TX LEDs and Link LED flashing. The other LEDs
633 * (which probably aren't wired anyway) are left in AUTO mode */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100634void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100635{
636 int reg;
637
638 if (blink)
639 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
640 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
641 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
642 else
643 reg = PMA_PMD_LED_DEFAULT;
644
645 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
646 PMA_PMD_LED_OVERR_REG, reg);
647}
648
Ben Hutchings307505e2008-12-26 13:48:00 -0800649static const char *const sfx7101_test_names[] = {
Ben Hutchings17967212008-12-26 13:47:25 -0800650 "bist"
651};
652
653static int
Ben Hutchings307505e2008-12-26 13:48:00 -0800654sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100655{
Ben Hutchings17967212008-12-26 13:47:25 -0800656 int rc;
657
658 if (!(flags & ETH_TEST_FL_OFFLINE))
659 return 0;
660
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100661 /* BIST is automatically run after a special software reset */
Ben Hutchings17967212008-12-26 13:47:25 -0800662 rc = tenxpress_special_reset(efx);
663 results[0] = rc ? -1 : 1;
664 return rc;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100665}
666
Ben Hutchings307505e2008-12-26 13:48:00 -0800667static const char *const sft9001_test_names[] = {
668 "bist",
669 "cable.pairA.status",
670 "cable.pairB.status",
671 "cable.pairC.status",
672 "cable.pairD.status",
673 "cable.pairA.length",
674 "cable.pairB.length",
675 "cable.pairC.length",
676 "cable.pairD.length",
677};
678
679static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
680{
681 struct ethtool_cmd ecmd;
682 int phy_id = efx->mii.phy_id;
683 int rc = 0, rc2, i, res_reg;
684
685 if (!(flags & ETH_TEST_FL_OFFLINE))
686 return 0;
687
688 efx->phy_op->get_settings(efx, &ecmd);
689
690 /* Initialise cable diagnostic results to unknown failure */
691 for (i = 1; i < 9; ++i)
692 results[i] = -1;
693
694 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
695 * A cable fault is not a self-test failure, but a timeout is. */
696 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
697 PMA_PMD_CDIAG_CTRL_REG,
698 (1 << CDIAG_CTRL_IMMED_LBN) |
699 (1 << CDIAG_CTRL_BRK_LINK_LBN) |
700 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
701 i = 0;
702 while (mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
703 PMA_PMD_CDIAG_CTRL_REG) &
704 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
705 if (++i == 50) {
706 rc = -ETIMEDOUT;
707 goto reset;
708 }
709 msleep(100);
710 }
711 res_reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
712 PMA_PMD_CDIAG_RES_REG);
713 for (i = 0; i < 4; i++) {
714 int pair_res =
715 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
716 & ((1 << CDIAG_RES_WIDTH) - 1);
717 int len_reg = mdio_clause45_read(efx, efx->mii.phy_id,
718 MDIO_MMD_PMAPMD,
719 PMA_PMD_CDIAG_LEN_REG + i);
720 if (pair_res == CDIAG_RES_OK)
721 results[1 + i] = 1;
722 else if (pair_res == CDIAG_RES_INVALID)
723 results[1 + i] = -1;
724 else
725 results[1 + i] = -pair_res;
726 if (pair_res != CDIAG_RES_INVALID &&
727 pair_res != CDIAG_RES_OPEN &&
728 len_reg != 0xffff)
729 results[5 + i] = len_reg;
730 }
731
732 /* We must reset to exit cable diagnostic mode. The BIST will
733 * also run when we do this. */
734reset:
735 rc2 = tenxpress_special_reset(efx);
736 results[0] = rc2 ? -1 : 1;
737 if (!rc)
738 rc = rc2;
739
740 rc2 = efx->phy_op->set_settings(efx, &ecmd);
741 if (!rc)
742 rc = rc2;
743
744 return rc;
745}
746
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000747static void
748tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800749{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000750 int phy_id = efx->mii.phy_id;
751 u32 adv = 0, lpa = 0;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800752 int reg;
753
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800754 if (efx->phy_type != PHY_TYPE_SFX7101) {
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000755 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
756 C22EXT_MSTSLV_CTRL);
757 if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
758 adv |= ADVERTISED_1000baseT_Full;
759 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
760 C22EXT_MSTSLV_STATUS);
761 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800762 lpa |= ADVERTISED_1000baseT_Half;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000763 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800764 lpa |= ADVERTISED_1000baseT_Full;
765 }
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000766 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
767 MDIO_AN_10GBT_CTRL);
768 if (reg & (1 << MDIO_AN_10GBT_CTRL_ADV_10G_LBN))
769 adv |= ADVERTISED_10000baseT_Full;
770 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
771 MDIO_AN_10GBT_STATUS);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800772 if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN))
773 lpa |= ADVERTISED_10000baseT_Full;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800774
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000775 mdio_clause45_get_settings_ext(efx, ecmd, adv, lpa);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800776
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000777 if (efx->phy_type != PHY_TYPE_SFX7101)
778 ecmd->supported |= (SUPPORTED_100baseT_Full |
779 SUPPORTED_1000baseT_Full);
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000780
781 /* In loopback, the PHY automatically brings up the correct interface,
782 * but doesn't advertise the correct speed. So override it */
783 if (efx->loopback_mode == LOOPBACK_GPHY)
784 ecmd->speed = SPEED_1000;
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000785 else if (LOOPBACK_MASK(efx) & efx->phy_op->loopbacks)
Steve Hodgson8b9dc8d2009-01-29 17:49:09 +0000786 ecmd->speed = SPEED_10000;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100787}
788
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000789static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100790{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000791 if (!ecmd->autoneg)
792 return -EINVAL;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800793
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000794 return mdio_clause45_set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100795}
796
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000797static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800798{
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000799 mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_AN,
800 MDIO_AN_10GBT_CTRL,
801 MDIO_AN_10GBT_CTRL_ADV_10G_LBN,
802 advertising & ADVERTISED_10000baseT_Full);
803}
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800804
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000805static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800806{
807 int phy_id = efx->mii.phy_id;
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800808
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000809 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
810 C22EXT_MSTSLV_CTRL,
811 C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
812 advertising & ADVERTISED_1000baseT_Full);
813 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_AN,
814 MDIO_AN_10GBT_CTRL,
815 MDIO_AN_10GBT_CTRL_ADV_10G_LBN,
816 advertising & ADVERTISED_10000baseT_Full);
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800817}
818
819struct efx_phy_operations falcon_sfx7101_phy_ops = {
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800820 .macs = EFX_XMAC,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100821 .init = tenxpress_phy_init,
822 .reconfigure = tenxpress_phy_reconfigure,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800823 .poll = tenxpress_phy_poll,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100824 .fini = tenxpress_phy_fini,
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800825 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000826 .get_settings = tenxpress_get_settings,
827 .set_settings = tenxpress_set_settings,
828 .set_npage_adv = sfx7101_set_npage_adv,
Ben Hutchings307505e2008-12-26 13:48:00 -0800829 .num_tests = ARRAY_SIZE(sfx7101_test_names),
830 .test_names = sfx7101_test_names,
831 .run_tests = sfx7101_run_tests,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100832 .mmds = TENXPRESS_REQUIRED_DEVS,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800833 .loopbacks = SFX7101_LOOPBACKS,
834};
835
836struct efx_phy_operations falcon_sft9001_phy_ops = {
837 .macs = EFX_GMAC | EFX_XMAC,
838 .init = tenxpress_phy_init,
839 .reconfigure = tenxpress_phy_reconfigure,
840 .poll = tenxpress_phy_poll,
841 .fini = tenxpress_phy_fini,
842 .clear_interrupt = efx_port_dummy_op_void,
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000843 .get_settings = tenxpress_get_settings,
844 .set_settings = tenxpress_set_settings,
845 .set_npage_adv = sft9001_set_npage_adv,
Ben Hutchings307505e2008-12-26 13:48:00 -0800846 .num_tests = ARRAY_SIZE(sft9001_test_names),
847 .test_names = sft9001_test_names,
848 .run_tests = sft9001_run_tests,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800849 .mmds = TENXPRESS_REQUIRED_DEVS,
850 .loopbacks = SFT9001_LOOPBACKS,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100851};