mdio: Expose 10GBASE-T MDI-X status via ethtool
[deliverable/linux.git] / drivers / net / sfc / tenxpress.c
CommitLineData
8ceee660 1/****************************************************************************
177dfcd8
BH
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007-2008 Solarflare Communications Inc.
8ceee660
BH
4 *
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>
da3bc071 11#include <linux/rtnetlink.h>
8ceee660
BH
12#include <linux/seq_file.h>
13#include "efx.h"
8ceee660
BH
14#include "mdio_10g.h"
15#include "falcon.h"
16#include "phy.h"
17#include "falcon_hwdefs.h"
18#include "boards.h"
e6fa2eb7
BH
19#include "workarounds.h"
20#include "selftest.h"
8ceee660 21
e6fa2eb7
BH
22/* 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 */
68e7f45e
BH
26#define TENXPRESS_REQUIRED_DEVS (MDIO_DEVS_PMAPMD | \
27 MDIO_DEVS_PCS | \
28 MDIO_DEVS_PHYXS | \
29 MDIO_DEVS_AN)
8ceee660 30
e6fa2eb7
BH
31#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))
3273c2e8 41
8ceee660
BH
42/* 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 */
e6fa2eb7
BH
48#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
869b5b38
SH
59#define PMA_PMD_EXT_ROBUST_LBN 14
60#define PMA_PMD_EXT_ROBUST_WIDTH 1
e6fa2eb7
BH
61#define PMA_PMD_EXT_SSR_LBN 15
62#define PMA_PMD_EXT_SSR_WIDTH 1
8ceee660
BH
63
64/* extended status register */
e6fa2eb7 65#define PMA_PMD_XSTATUS_REG 49153
8ceee660
BH
66#define PMA_PMD_XSTAT_FLP_LBN (12)
67
68/* LED control register */
e6fa2eb7 69#define PMA_PMD_LED_CTRL_REG 49159
8ceee660
BH
70#define PMA_PMA_LED_ACTIVITY_LBN (3)
71
72/* LED function override register */
e6fa2eb7 73#define PMA_PMD_LED_OVERR_REG 49161
8ceee660
BH
74/* 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)
04cc8cac 84#define PMA_PMD_LED_MASK 3
8ceee660
BH
85/* 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
e6fa2eb7
BH
90#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
99
307505e9
BH
100/* 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
e6fa2eb7
BH
119/* 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
123
124/* Misc register defines - SFX7101 only */
125#define PCS_CLOCK_CTRL_REG 55297
8ceee660
BH
126#define PLL312_RST_N_LBN 2
127
e6fa2eb7 128#define PCS_SOFT_RST2_REG 55302
8ceee660
BH
129#define SERDES_RST_N_LBN 13
130#define XGXS_RST_N_LBN 12
131
e6fa2eb7 132#define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
8ceee660
BH
133#define CLK312_EN_LBN 3
134
3273c2e8 135/* PHYXS registers */
e6fa2eb7
BH
136#define PHYXS_XCONTROL_REG 49152
137#define PHYXS_RESET_LBN 15
138#define PHYXS_RESET_WIDTH 1
139
3273c2e8
BH
140#define PHYXS_TEST1 (49162)
141#define LOOPBACK_NEAR_LBN (8)
142#define LOOPBACK_NEAR_WIDTH (1)
143
8ceee660 144/* Boot status register */
190dbcfd
BH
145#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
8ceee660 155
e6fa2eb7
BH
156/* 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
af4ad9bc
BH
169#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
e6fa2eb7 176
8ceee660
BH
177/* Time to wait between powering down the LNPGA and turning off the power
178 * rails */
179#define LNPGA_PDOWN_WAIT (HZ / 5)
180
8ceee660 181struct tenxpress_phy_data {
3273c2e8 182 enum efx_loopback_mode loopback_mode;
f8b87c17 183 enum efx_phy_mode phy_mode;
8ceee660
BH
184 int bad_lp_tries;
185};
186
e6fa2eb7
BH
187static 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
68e7f45e
BH
193 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TXPWR);
194 return sprintf(buf, "%d\n", !!(reg & MDIO_PMA_10GBT_TXPWR_SHORT));
e6fa2eb7
BH
195}
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();
68e7f45e
BH
204 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TXPWR,
205 MDIO_PMA_10GBT_TXPWR_SHORT,
206 count != 0 && *buf != '0');
e6fa2eb7
BH
207 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
190dbcfd 216int sft9001_wait_boot(struct efx_nic *efx)
8ceee660 217{
190dbcfd 218 unsigned long timeout = jiffies + HZ + 1;
8ceee660
BH
219 int boot_stat;
220
190dbcfd 221 for (;;) {
68e7f45e
BH
222 boot_stat = efx_mdio_read(efx, MDIO_MMD_PCS,
223 PCS_BOOT_STATUS_REG);
190dbcfd
BH
224 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 }
259
260 if (time_after_eq(jiffies, timeout))
261 return -ETIMEDOUT;
262
263 msleep(50);
8ceee660 264 }
8ceee660
BH
265}
266
8ceee660
BH
267static int tenxpress_init(struct efx_nic *efx)
268{
e6fa2eb7 269 int reg;
8ceee660 270
e6fa2eb7
BH
271 if (efx->phy_type == PHY_TYPE_SFX7101) {
272 /* Enable 312.5 MHz clock */
68e7f45e
BH
273 efx_mdio_write(efx, MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
274 1 << CLK312_EN_LBN);
e6fa2eb7
BH
275 } else {
276 /* Enable 312.5 MHz clock and GMII */
68e7f45e 277 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
e6fa2eb7
BH
278 reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
279 (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
869b5b38
SH
280 (1 << PMA_PMD_EXT_CLK312_LBN) |
281 (1 << PMA_PMD_EXT_ROBUST_LBN));
282
68e7f45e
BH
283 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);
e6fa2eb7 287 }
8ceee660 288
8ceee660 289 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
e6fa2eb7 290 if (efx->phy_type == PHY_TYPE_SFX7101) {
68e7f45e
BH
291 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);
e6fa2eb7 295 }
8ceee660 296
190dbcfd 297 return 0;
8ceee660
BH
298}
299
300static int tenxpress_phy_init(struct efx_nic *efx)
301{
302 struct tenxpress_phy_data *phy_data;
303 int rc = 0;
304
305 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
9b7bfc4c
BH
306 if (!phy_data)
307 return -ENOMEM;
8ceee660 308 efx->phy_data = phy_data;
f8b87c17 309 phy_data->phy_mode = efx->phy_mode;
8ceee660 310
e6fa2eb7
BH
311 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
312 if (efx->phy_type == PHY_TYPE_SFT9001A) {
313 int reg;
68e7f45e
BH
314 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
315 PMA_PMD_XCONTROL_REG);
e6fa2eb7 316 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
68e7f45e
BH
317 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
318 PMA_PMD_XCONTROL_REG, reg);
e6fa2eb7
BH
319 mdelay(200);
320 }
8ceee660 321
68e7f45e 322 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
e6fa2eb7
BH
323 if (rc < 0)
324 goto fail;
325
68e7f45e 326 rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
e6fa2eb7
BH
327 if (rc < 0)
328 goto fail;
329 }
8ceee660
BH
330
331 rc = tenxpress_init(efx);
332 if (rc < 0)
333 goto fail;
334
e6fa2eb7
BH
335 if (efx->phy_type == PHY_TYPE_SFT9001B) {
336 rc = device_create_file(&efx->pci_dev->dev,
337 &dev_attr_phy_short_reach);
338 if (rc)
339 goto fail;
340 }
341
8ceee660
BH
342 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
343
e6fa2eb7 344 /* Let XGXS and SerDes out of reset */
8ceee660
BH
345 falcon_reset_xaui(efx);
346
347 return 0;
348
349 fail:
350 kfree(efx->phy_data);
351 efx->phy_data = NULL;
352 return rc;
353}
354
e6fa2eb7
BH
355/* Perform a "special software reset" on the PHY. The caller is
356 * responsible for saving and restoring the PHY hardware registers
357 * properly, and masking/unmasking LASI */
3273c2e8
BH
358static int tenxpress_special_reset(struct efx_nic *efx)
359{
360 int rc, reg;
361
c8fcc49c
BH
362 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
363 * a special software reset can glitch the XGMAC sufficiently for stats
1974cc20
BH
364 * requests to fail. */
365 efx_stats_disable(efx);
3273c2e8
BH
366
367 /* Initiate reset */
68e7f45e 368 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
3273c2e8 369 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
68e7f45e 370 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
3273c2e8 371
c8fcc49c 372 mdelay(200);
3273c2e8
BH
373
374 /* Wait for the blocks to come out of reset */
68e7f45e 375 rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
3273c2e8 376 if (rc < 0)
1974cc20 377 goto out;
3273c2e8
BH
378
379 /* Try and reconfigure the device */
380 rc = tenxpress_init(efx);
381 if (rc < 0)
1974cc20 382 goto out;
3273c2e8 383
e6fa2eb7
BH
384 /* Wait for the XGXS state machine to churn */
385 mdelay(10);
1974cc20
BH
386out:
387 efx_stats_enable(efx);
c8fcc49c 388 return rc;
3273c2e8
BH
389}
390
e6fa2eb7 391static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
8ceee660
BH
392{
393 struct tenxpress_phy_data *pd = efx->phy_data;
04cc8cac 394 bool bad_lp;
8ceee660
BH
395 int reg;
396
04cc8cac
BH
397 if (link_ok) {
398 bad_lp = false;
399 } else {
400 /* Check that AN has started but not completed. */
68e7f45e
BH
401 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
402 if (!(reg & MDIO_AN_STAT1_LPABLE))
04cc8cac 403 return; /* LP status is unknown */
68e7f45e 404 bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
04cc8cac
BH
405 if (bad_lp)
406 pd->bad_lp_tries++;
407 }
408
8ceee660 409 /* Nothing to do if all is well and was previously so. */
04cc8cac 410 if (!pd->bad_lp_tries)
8ceee660
BH
411 return;
412
04cc8cac
BH
413 /* Use the RX (red) LED as an error indicator once we've seen AN
414 * failure several times in a row, and also log a message. */
415 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
68e7f45e
BH
416 reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
417 PMA_PMD_LED_OVERR_REG);
04cc8cac
BH
418 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
419 if (!bad_lp) {
420 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
421 } else {
422 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
423 EFX_ERR(efx, "appears to be plugged into a port"
424 " that is not 10GBASE-T capable. The PHY"
425 " supports 10GBASE-T ONLY, so no link can"
426 " be established\n");
427 }
68e7f45e
BH
428 efx_mdio_write(efx, MDIO_MMD_PMAPMD,
429 PMA_PMD_LED_OVERR_REG, reg);
04cc8cac 430 pd->bad_lp_tries = bad_lp;
8ceee660 431 }
8ceee660
BH
432}
433
e6fa2eb7 434static bool sfx7101_link_ok(struct efx_nic *efx)
8ceee660 435{
68e7f45e
BH
436 return efx_mdio_links_ok(efx,
437 MDIO_DEVS_PMAPMD |
438 MDIO_DEVS_PCS |
439 MDIO_DEVS_PHYXS);
e6fa2eb7
BH
440}
441
442static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
443{
e6fa2eb7
BH
444 u32 reg;
445
caa8d8bb 446 if (efx_phy_mode_disabled(efx->phy_mode))
e6fa2eb7 447 return false;
caa8d8bb
BH
448 else if (efx->loopback_mode == LOOPBACK_GPHY)
449 return true;
e6fa2eb7 450 else if (efx->loopback_mode)
68e7f45e
BH
451 return efx_mdio_links_ok(efx,
452 MDIO_DEVS_PMAPMD |
453 MDIO_DEVS_PHYXS);
e6fa2eb7
BH
454
455 /* We must use the same definition of link state as LASI,
456 * otherwise we can miss a link state transition
457 */
458 if (ecmd->speed == 10000) {
68e7f45e
BH
459 reg = efx_mdio_read(efx, MDIO_MMD_PCS, MDIO_PCS_10GBRT_STAT1);
460 return reg & MDIO_PCS_10GBRT_STAT1_BLKLK;
e6fa2eb7 461 } else {
68e7f45e 462 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_STATUS_REG);
e6fa2eb7
BH
463 return reg & (1 << C22EXT_STATUS_LINK_LBN);
464 }
8ceee660
BH
465}
466
e6fa2eb7 467static void tenxpress_ext_loopback(struct efx_nic *efx)
3273c2e8 468{
68e7f45e
BH
469 efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
470 1 << LOOPBACK_NEAR_LBN,
471 efx->loopback_mode == LOOPBACK_PHYXS);
e6fa2eb7 472 if (efx->phy_type != PHY_TYPE_SFX7101)
68e7f45e
BH
473 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, GPHY_XCONTROL_REG,
474 1 << GPHY_LOOPBACK_NEAR_LBN,
475 efx->loopback_mode == LOOPBACK_GPHY);
e6fa2eb7
BH
476}
477
478static void tenxpress_low_power(struct efx_nic *efx)
479{
e6fa2eb7 480 if (efx->phy_type == PHY_TYPE_SFX7101)
68e7f45e 481 efx_mdio_set_mmds_lpower(
e6fa2eb7
BH
482 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
483 TENXPRESS_REQUIRED_DEVS);
3273c2e8 484 else
68e7f45e
BH
485 efx_mdio_set_flag(
486 efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG,
487 1 << PMA_PMD_EXT_LPOWER_LBN,
e6fa2eb7 488 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
3273c2e8
BH
489}
490
8ceee660
BH
491static void tenxpress_phy_reconfigure(struct efx_nic *efx)
492{
3273c2e8 493 struct tenxpress_phy_data *phy_data = efx->phy_data;
e6fa2eb7 494 struct ethtool_cmd ecmd;
8b9dc8dd 495 bool phy_mode_change, loop_reset;
3273c2e8 496
e6fa2eb7 497 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
f8b87c17 498 phy_data->phy_mode = efx->phy_mode;
8ceee660 499 return;
f8b87c17 500 }
8ceee660 501
e6fa2eb7
BH
502 tenxpress_low_power(efx);
503
504 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
505 phy_data->phy_mode != PHY_MODE_NORMAL);
e6fa2eb7
BH
506 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
507 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
508
8b9dc8dd 509 if (loop_reset || phy_mode_change) {
e6fa2eb7
BH
510 int rc;
511
512 efx->phy_op->get_settings(efx, &ecmd);
513
514 if (loop_reset || phy_mode_change) {
515 tenxpress_special_reset(efx);
516
517 /* Reset XAUI if we were in 10G, and are staying
518 * in 10G. If we're moving into and out of 10G
519 * then xaui will be reset anyway */
520 if (EFX_IS10G(efx))
521 falcon_reset_xaui(efx);
522 }
523
e6fa2eb7
BH
524 rc = efx->phy_op->set_settings(efx, &ecmd);
525 WARN_ON(rc);
3273c2e8
BH
526 }
527
68e7f45e
BH
528 efx_mdio_transmit_disable(efx);
529 efx_mdio_phy_reconfigure(efx);
e6fa2eb7 530 tenxpress_ext_loopback(efx);
3273c2e8 531
3273c2e8 532 phy_data->loopback_mode = efx->loopback_mode;
f8b87c17 533 phy_data->phy_mode = efx->phy_mode;
e6fa2eb7
BH
534
535 if (efx->phy_type == PHY_TYPE_SFX7101) {
536 efx->link_speed = 10000;
537 efx->link_fd = true;
538 efx->link_up = sfx7101_link_ok(efx);
539 } else {
540 efx->phy_op->get_settings(efx, &ecmd);
541 efx->link_speed = ecmd.speed;
542 efx->link_fd = ecmd.duplex == DUPLEX_FULL;
543 efx->link_up = sft9001_link_ok(efx, &ecmd);
544 }
68e7f45e 545 efx->link_fc = efx_mdio_get_pause(efx);
8ceee660
BH
546}
547
8ceee660 548/* Poll PHY for interrupt */
766ca0fa 549static void tenxpress_phy_poll(struct efx_nic *efx)
8ceee660
BH
550{
551 struct tenxpress_phy_data *phy_data = efx->phy_data;
37d37695 552 bool change = false;
8ceee660 553
e6fa2eb7 554 if (efx->phy_type == PHY_TYPE_SFX7101) {
37d37695 555 bool link_ok = sfx7101_link_ok(efx);
e6fa2eb7
BH
556 if (link_ok != efx->link_up) {
557 change = true;
558 } else {
68e7f45e 559 unsigned int link_fc = efx_mdio_get_pause(efx);
e6fa2eb7
BH
560 if (link_fc != efx->link_fc)
561 change = true;
562 }
563 sfx7101_check_bad_lp(efx, link_ok);
caa8d8bb
BH
564 } else if (efx->loopback_mode) {
565 bool link_ok = sft9001_link_ok(efx, NULL);
566 if (link_ok != efx->link_up)
567 change = true;
766ca0fa 568 } else {
68e7f45e 569 int status = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
6bc5046e
BH
570 MDIO_PMA_LASI_STAT);
571 if (status & MDIO_PMA_LASI_LSALARM)
766ca0fa
BH
572 change = true;
573 }
8ceee660 574
766ca0fa 575 if (change)
177dfcd8 576 falcon_sim_phy_event(efx);
8ceee660 577
f8b87c17 578 if (phy_data->phy_mode != PHY_MODE_NORMAL)
766ca0fa 579 return;
8ceee660
BH
580}
581
582static void tenxpress_phy_fini(struct efx_nic *efx)
583{
584 int reg;
585
2a7e637d 586 if (efx->phy_type == PHY_TYPE_SFT9001B)
e6fa2eb7
BH
587 device_remove_file(&efx->pci_dev->dev,
588 &dev_attr_phy_short_reach);
2a7e637d
BH
589
590 if (efx->phy_type == PHY_TYPE_SFX7101) {
e6fa2eb7
BH
591 /* Power down the LNPGA */
592 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
68e7f45e 593 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
e6fa2eb7
BH
594
595 /* Waiting here ensures that the board fini, which can turn
596 * off the power to the PHY, won't get run until the LNPGA
597 * powerdown has been given long enough to complete. */
598 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
599 }
8ceee660
BH
600
601 kfree(efx->phy_data);
602 efx->phy_data = NULL;
603}
604
605
606/* Set the RX and TX LEDs and Link LED flashing. The other LEDs
607 * (which probably aren't wired anyway) are left in AUTO mode */
dc8cfa55 608void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
8ceee660
BH
609{
610 int reg;
611
612 if (blink)
613 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
614 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
615 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
616 else
617 reg = PMA_PMD_LED_DEFAULT;
618
68e7f45e 619 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
8ceee660
BH
620}
621
307505e9 622static const char *const sfx7101_test_names[] = {
1796721a
BH
623 "bist"
624};
625
626static int
307505e9 627sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
8c8661e4 628{
1796721a
BH
629 int rc;
630
631 if (!(flags & ETH_TEST_FL_OFFLINE))
632 return 0;
633
8c8661e4 634 /* BIST is automatically run after a special software reset */
1796721a
BH
635 rc = tenxpress_special_reset(efx);
636 results[0] = rc ? -1 : 1;
637 return rc;
8c8661e4
BH
638}
639
307505e9
BH
640static const char *const sft9001_test_names[] = {
641 "bist",
642 "cable.pairA.status",
643 "cable.pairB.status",
644 "cable.pairC.status",
645 "cable.pairD.status",
646 "cable.pairA.length",
647 "cable.pairB.length",
648 "cable.pairC.length",
649 "cable.pairD.length",
650};
651
652static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
653{
654 struct ethtool_cmd ecmd;
22ef02c2 655 int rc = 0, rc2, i, ctrl_reg, res_reg;
307505e9 656
22ef02c2
BH
657 if (flags & ETH_TEST_FL_OFFLINE)
658 efx->phy_op->get_settings(efx, &ecmd);
307505e9
BH
659
660 /* Initialise cable diagnostic results to unknown failure */
661 for (i = 1; i < 9; ++i)
662 results[i] = -1;
663
664 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
665 * A cable fault is not a self-test failure, but a timeout is. */
22ef02c2
BH
666 ctrl_reg = ((1 << CDIAG_CTRL_IMMED_LBN) |
667 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
668 if (flags & ETH_TEST_FL_OFFLINE) {
669 /* Break the link in order to run full diagnostics. We
670 * must reset the PHY to resume normal service. */
671 ctrl_reg |= (1 << CDIAG_CTRL_BRK_LINK_LBN);
672 }
68e7f45e
BH
673 efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG,
674 ctrl_reg);
307505e9 675 i = 0;
68e7f45e 676 while (efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_CTRL_REG) &
307505e9
BH
677 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
678 if (++i == 50) {
679 rc = -ETIMEDOUT;
22ef02c2 680 goto out;
307505e9
BH
681 }
682 msleep(100);
683 }
68e7f45e 684 res_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_CDIAG_RES_REG);
307505e9
BH
685 for (i = 0; i < 4; i++) {
686 int pair_res =
687 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
688 & ((1 << CDIAG_RES_WIDTH) - 1);
68e7f45e
BH
689 int len_reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
690 PMA_PMD_CDIAG_LEN_REG + i);
307505e9
BH
691 if (pair_res == CDIAG_RES_OK)
692 results[1 + i] = 1;
693 else if (pair_res == CDIAG_RES_INVALID)
694 results[1 + i] = -1;
695 else
696 results[1 + i] = -pair_res;
697 if (pair_res != CDIAG_RES_INVALID &&
698 pair_res != CDIAG_RES_OPEN &&
699 len_reg != 0xffff)
700 results[5 + i] = len_reg;
701 }
702
22ef02c2
BH
703out:
704 if (flags & ETH_TEST_FL_OFFLINE) {
705 /* Reset, running the BIST and then resuming normal service. */
706 rc2 = tenxpress_special_reset(efx);
707 results[0] = rc2 ? -1 : 1;
708 if (!rc)
709 rc = rc2;
710
711 rc2 = efx->phy_op->set_settings(efx, &ecmd);
712 if (!rc)
713 rc = rc2;
714 }
307505e9
BH
715
716 return rc;
717}
718
af4ad9bc
BH
719static void
720tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
04cc8cac 721{
af4ad9bc 722 u32 adv = 0, lpa = 0;
04cc8cac
BH
723 int reg;
724
e6fa2eb7 725 if (efx->phy_type != PHY_TYPE_SFX7101) {
68e7f45e 726 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL);
af4ad9bc
BH
727 if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
728 adv |= ADVERTISED_1000baseT_Full;
68e7f45e 729 reg = efx_mdio_read(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_STATUS);
af4ad9bc 730 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
e6fa2eb7 731 lpa |= ADVERTISED_1000baseT_Half;
af4ad9bc 732 if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
e6fa2eb7
BH
733 lpa |= ADVERTISED_1000baseT_Full;
734 }
68e7f45e
BH
735 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
736 if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
af4ad9bc 737 adv |= ADVERTISED_10000baseT_Full;
68e7f45e
BH
738 reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
739 if (reg & MDIO_AN_10GBT_STAT_LP10G)
04cc8cac 740 lpa |= ADVERTISED_10000baseT_Full;
04cc8cac 741
68e7f45e 742 mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
e6fa2eb7 743
af4ad9bc
BH
744 if (efx->phy_type != PHY_TYPE_SFX7101)
745 ecmd->supported |= (SUPPORTED_100baseT_Full |
746 SUPPORTED_1000baseT_Full);
8b9dc8dd
SH
747
748 /* In loopback, the PHY automatically brings up the correct interface,
749 * but doesn't advertise the correct speed. So override it */
750 if (efx->loopback_mode == LOOPBACK_GPHY)
751 ecmd->speed = SPEED_1000;
af4ad9bc 752 else if (LOOPBACK_MASK(efx) & efx->phy_op->loopbacks)
8b9dc8dd 753 ecmd->speed = SPEED_10000;
04cc8cac
BH
754}
755
af4ad9bc 756static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
e6fa2eb7 757{
af4ad9bc
BH
758 if (!ecmd->autoneg)
759 return -EINVAL;
e6fa2eb7 760
68e7f45e 761 return efx_mdio_set_settings(efx, ecmd);
e6fa2eb7
BH
762}
763
af4ad9bc 764static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
e6fa2eb7 765{
68e7f45e
BH
766 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
767 MDIO_AN_10GBT_CTRL_ADV10G,
768 advertising & ADVERTISED_10000baseT_Full);
e6fa2eb7
BH
769}
770
af4ad9bc 771static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
e6fa2eb7 772{
68e7f45e
BH
773 efx_mdio_set_flag(efx, MDIO_MMD_C22EXT, C22EXT_MSTSLV_CTRL,
774 1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
775 advertising & ADVERTISED_1000baseT_Full);
776 efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
777 MDIO_AN_10GBT_CTRL_ADV10G,
778 advertising & ADVERTISED_10000baseT_Full);
e6fa2eb7
BH
779}
780
781struct efx_phy_operations falcon_sfx7101_phy_ops = {
177dfcd8 782 .macs = EFX_XMAC,
8ceee660
BH
783 .init = tenxpress_phy_init,
784 .reconfigure = tenxpress_phy_reconfigure,
766ca0fa 785 .poll = tenxpress_phy_poll,
8ceee660 786 .fini = tenxpress_phy_fini,
766ca0fa 787 .clear_interrupt = efx_port_dummy_op_void,
af4ad9bc
BH
788 .get_settings = tenxpress_get_settings,
789 .set_settings = tenxpress_set_settings,
790 .set_npage_adv = sfx7101_set_npage_adv,
307505e9
BH
791 .num_tests = ARRAY_SIZE(sfx7101_test_names),
792 .test_names = sfx7101_test_names,
793 .run_tests = sfx7101_run_tests,
8ceee660 794 .mmds = TENXPRESS_REQUIRED_DEVS,
e6fa2eb7
BH
795 .loopbacks = SFX7101_LOOPBACKS,
796};
797
798struct efx_phy_operations falcon_sft9001_phy_ops = {
799 .macs = EFX_GMAC | EFX_XMAC,
800 .init = tenxpress_phy_init,
801 .reconfigure = tenxpress_phy_reconfigure,
802 .poll = tenxpress_phy_poll,
803 .fini = tenxpress_phy_fini,
804 .clear_interrupt = efx_port_dummy_op_void,
af4ad9bc
BH
805 .get_settings = tenxpress_get_settings,
806 .set_settings = tenxpress_set_settings,
807 .set_npage_adv = sft9001_set_npage_adv,
307505e9
BH
808 .num_tests = ARRAY_SIZE(sft9001_test_names),
809 .test_names = sft9001_test_names,
810 .run_tests = sft9001_run_tests,
e6fa2eb7
BH
811 .mmds = TENXPRESS_REQUIRED_DEVS,
812 .loopbacks = SFT9001_LOOPBACKS,
8ceee660 813};
This page took 0.31859 seconds and 5 git commands to generate.