1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007-2008 Solarflare Communications Inc.
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.
10 #include <linux/delay.h>
11 #include <linux/seq_file.h>
16 #include "falcon_hwdefs.h"
18 #include "workarounds.h"
21 /* We expect these MMDs to be in the package. SFT9001 also has a
22 * clause 22 extension MMD, but since it doesn't have all the generic
23 * MMD registers it is pointless to include it here.
25 #define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PMAPMD | \
26 MDIO_MMDREG_DEVS_PCS | \
27 MDIO_MMDREG_DEVS_PHYXS | \
30 #define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
31 (1 << LOOPBACK_PCS) | \
32 (1 << LOOPBACK_PMAPMD) | \
33 (1 << LOOPBACK_NETWORK))
35 #define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \
36 (1 << LOOPBACK_PHYXS) | \
37 (1 << LOOPBACK_PCS) | \
38 (1 << LOOPBACK_PMAPMD) | \
39 (1 << LOOPBACK_NETWORK))
41 /* We complain if we fail to see the link partner as 10G capable this many
42 * times in a row (must be > 1 as sampling the autoneg. registers is racy)
44 #define MAX_BAD_LP_TRIES (5)
47 #define PMA_PMD_LASI_CTRL 36866
48 #define PMA_PMD_LASI_STATUS 36869
49 #define PMA_PMD_LS_ALARM_LBN 0
50 #define PMA_PMD_LS_ALARM_WIDTH 1
51 #define PMA_PMD_TX_ALARM_LBN 1
52 #define PMA_PMD_TX_ALARM_WIDTH 1
53 #define PMA_PMD_RX_ALARM_LBN 2
54 #define PMA_PMD_RX_ALARM_WIDTH 1
55 #define PMA_PMD_AN_ALARM_LBN 3
56 #define PMA_PMD_AN_ALARM_WIDTH 1
58 /* Extended control register */
59 #define PMA_PMD_XCONTROL_REG 49152
60 #define PMA_PMD_EXT_GMII_EN_LBN 1
61 #define PMA_PMD_EXT_GMII_EN_WIDTH 1
62 #define PMA_PMD_EXT_CLK_OUT_LBN 2
63 #define PMA_PMD_EXT_CLK_OUT_WIDTH 1
64 #define PMA_PMD_LNPGA_POWERDOWN_LBN 8 /* SFX7101 only */
65 #define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
66 #define PMA_PMD_EXT_CLK312_LBN 8 /* SFT9001 only */
67 #define PMA_PMD_EXT_CLK312_WIDTH 1
68 #define PMA_PMD_EXT_LPOWER_LBN 12
69 #define PMA_PMD_EXT_LPOWER_WIDTH 1
70 #define PMA_PMD_EXT_SSR_LBN 15
71 #define PMA_PMD_EXT_SSR_WIDTH 1
73 /* extended status register */
74 #define PMA_PMD_XSTATUS_REG 49153
75 #define PMA_PMD_XSTAT_FLP_LBN (12)
77 /* LED control register */
78 #define PMA_PMD_LED_CTRL_REG 49159
79 #define PMA_PMA_LED_ACTIVITY_LBN (3)
81 /* LED function override register */
82 #define PMA_PMD_LED_OVERR_REG 49161
83 /* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
84 #define PMA_PMD_LED_LINK_LBN (0)
85 #define PMA_PMD_LED_SPEED_LBN (2)
86 #define PMA_PMD_LED_TX_LBN (4)
87 #define PMA_PMD_LED_RX_LBN (6)
88 /* Override settings */
89 #define PMA_PMD_LED_AUTO (0) /* H/W control */
90 #define PMA_PMD_LED_ON (1)
91 #define PMA_PMD_LED_OFF (2)
92 #define PMA_PMD_LED_FLASH (3)
93 #define PMA_PMD_LED_MASK 3
94 /* All LEDs under hardware control */
95 #define PMA_PMD_LED_FULL_AUTO (0)
96 /* Green and Amber under hardware control, Red off */
97 #define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
99 #define PMA_PMD_SPEED_ENABLE_REG 49192
100 #define PMA_PMD_100TX_ADV_LBN 1
101 #define PMA_PMD_100TX_ADV_WIDTH 1
102 #define PMA_PMD_1000T_ADV_LBN 2
103 #define PMA_PMD_1000T_ADV_WIDTH 1
104 #define PMA_PMD_10000T_ADV_LBN 3
105 #define PMA_PMD_10000T_ADV_WIDTH 1
106 #define PMA_PMD_SPEED_LBN 4
107 #define PMA_PMD_SPEED_WIDTH 4
109 /* Serdes control registers - SFT9001 only */
110 #define PMA_PMD_CSERDES_CTRL_REG 64258
111 /* Set the 156.25 MHz output to 312.5 MHz to drive Falcon's XMAC */
112 #define PMA_PMD_CSERDES_DEFAULT 0x000f
114 /* Misc register defines - SFX7101 only */
115 #define PCS_CLOCK_CTRL_REG 55297
116 #define PLL312_RST_N_LBN 2
118 #define PCS_SOFT_RST2_REG 55302
119 #define SERDES_RST_N_LBN 13
120 #define XGXS_RST_N_LBN 12
122 #define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
123 #define CLK312_EN_LBN 3
125 /* PHYXS registers */
126 #define PHYXS_XCONTROL_REG 49152
127 #define PHYXS_RESET_LBN 15
128 #define PHYXS_RESET_WIDTH 1
130 #define PHYXS_TEST1 (49162)
131 #define LOOPBACK_NEAR_LBN (8)
132 #define LOOPBACK_NEAR_WIDTH (1)
134 #define PCS_10GBASET_STAT1 32
135 #define PCS_10GBASET_BLKLK_LBN 0
136 #define PCS_10GBASET_BLKLK_WIDTH 1
138 /* Boot status register */
139 #define PCS_BOOT_STATUS_REG 53248
140 #define PCS_BOOT_FATAL_ERR_LBN (0)
141 #define PCS_BOOT_PROGRESS_LBN (1)
142 #define PCS_BOOT_PROGRESS_WIDTH (2)
143 #define PCS_BOOT_COMPLETE_LBN (3)
145 #define PCS_BOOT_MAX_DELAY (100)
146 #define PCS_BOOT_POLL_DELAY (10)
148 /* 100M/1G PHY registers */
149 #define GPHY_XCONTROL_REG 49152
150 #define GPHY_ISOLATE_LBN 10
151 #define GPHY_ISOLATE_WIDTH 1
152 #define GPHY_DUPLEX_LBN 8
153 #define GPHY_DUPLEX_WIDTH 1
154 #define GPHY_LOOPBACK_NEAR_LBN 14
155 #define GPHY_LOOPBACK_NEAR_WIDTH 1
157 #define C22EXT_STATUS_REG 49153
158 #define C22EXT_STATUS_LINK_LBN 2
159 #define C22EXT_STATUS_LINK_WIDTH 1
161 #define C22EXT_MSTSLV_REG 49162
162 #define C22EXT_MSTSLV_1000_HD_LBN 10
163 #define C22EXT_MSTSLV_1000_HD_WIDTH 1
164 #define C22EXT_MSTSLV_1000_FD_LBN 11
165 #define C22EXT_MSTSLV_1000_FD_WIDTH 1
167 /* Time to wait between powering down the LNPGA and turning off the power
169 #define LNPGA_PDOWN_WAIT (HZ / 5)
171 static int crc_error_reset_threshold
= 100;
172 module_param(crc_error_reset_threshold
, int, 0644);
173 MODULE_PARM_DESC(crc_error_reset_threshold
,
174 "Max number of CRC errors before XAUI reset");
176 struct tenxpress_phy_data
{
177 enum efx_loopback_mode loopback_mode
;
178 atomic_t bad_crc_count
;
179 enum efx_phy_mode phy_mode
;
183 void tenxpress_crc_err(struct efx_nic
*efx
)
185 struct tenxpress_phy_data
*phy_data
= efx
->phy_data
;
186 if (phy_data
!= NULL
)
187 atomic_inc(&phy_data
->bad_crc_count
);
190 static ssize_t
show_phy_short_reach(struct device
*dev
,
191 struct device_attribute
*attr
, char *buf
)
193 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
196 reg
= mdio_clause45_read(efx
, efx
->mii
.phy_id
, MDIO_MMD_PMAPMD
,
197 MDIO_PMAPMD_10GBT_TXPWR
);
198 return sprintf(buf
, "%d\n",
199 !!(reg
& (1 << MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN
)));
202 static ssize_t
set_phy_short_reach(struct device
*dev
,
203 struct device_attribute
*attr
,
204 const char *buf
, size_t count
)
206 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
209 mdio_clause45_set_flag(efx
, efx
->mii
.phy_id
, MDIO_MMD_PMAPMD
,
210 MDIO_PMAPMD_10GBT_TXPWR
,
211 MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN
,
212 count
!= 0 && *buf
!= '0');
213 efx_reconfigure_port(efx
);
219 static DEVICE_ATTR(phy_short_reach
, 0644, show_phy_short_reach
,
220 set_phy_short_reach
);
222 /* Check that the C166 has booted successfully */
223 static int tenxpress_phy_check(struct efx_nic
*efx
)
225 int phy_id
= efx
->mii
.phy_id
;
226 int count
= PCS_BOOT_MAX_DELAY
/ PCS_BOOT_POLL_DELAY
;
229 /* Wait for the boot to complete (or not) */
231 boot_stat
= mdio_clause45_read(efx
, phy_id
,
233 PCS_BOOT_STATUS_REG
);
234 if (boot_stat
& (1 << PCS_BOOT_COMPLETE_LBN
))
237 udelay(PCS_BOOT_POLL_DELAY
);
241 EFX_ERR(efx
, "%s: PHY boot timed out. Last status "
243 (boot_stat
>> PCS_BOOT_PROGRESS_LBN
) &
244 ((1 << PCS_BOOT_PROGRESS_WIDTH
) - 1));
251 static int tenxpress_init(struct efx_nic
*efx
)
253 int phy_id
= efx
->mii
.phy_id
;
257 if (efx
->phy_type
== PHY_TYPE_SFX7101
) {
258 /* Enable 312.5 MHz clock */
259 mdio_clause45_write(efx
, phy_id
,
260 MDIO_MMD_PCS
, PCS_TEST_SELECT_REG
,
263 /* Enable 312.5 MHz clock and GMII */
264 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_PMAPMD
,
265 PMA_PMD_XCONTROL_REG
);
266 reg
|= ((1 << PMA_PMD_EXT_GMII_EN_LBN
) |
267 (1 << PMA_PMD_EXT_CLK_OUT_LBN
) |
268 (1 << PMA_PMD_EXT_CLK312_LBN
));
269 mdio_clause45_write(efx
, phy_id
, MDIO_MMD_PMAPMD
,
270 PMA_PMD_XCONTROL_REG
, reg
);
271 mdio_clause45_set_flag(efx
, phy_id
, MDIO_MMD_C22EXT
,
272 GPHY_XCONTROL_REG
, GPHY_ISOLATE_LBN
,
276 rc
= tenxpress_phy_check(efx
);
280 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
281 if (efx
->phy_type
== PHY_TYPE_SFX7101
) {
282 mdio_clause45_set_flag(efx
, phy_id
, MDIO_MMD_PMAPMD
,
283 PMA_PMD_LED_CTRL_REG
,
284 PMA_PMA_LED_ACTIVITY_LBN
,
286 mdio_clause45_write(efx
, phy_id
, MDIO_MMD_PMAPMD
,
287 PMA_PMD_LED_OVERR_REG
, PMA_PMD_LED_DEFAULT
);
293 static int tenxpress_phy_init(struct efx_nic
*efx
)
295 struct tenxpress_phy_data
*phy_data
;
298 phy_data
= kzalloc(sizeof(*phy_data
), GFP_KERNEL
);
301 efx
->phy_data
= phy_data
;
302 phy_data
->phy_mode
= efx
->phy_mode
;
304 if (!(efx
->phy_mode
& PHY_MODE_SPECIAL
)) {
305 if (efx
->phy_type
== PHY_TYPE_SFT9001A
) {
307 reg
= mdio_clause45_read(efx
, efx
->mii
.phy_id
,
309 PMA_PMD_XCONTROL_REG
);
310 reg
|= (1 << PMA_PMD_EXT_SSR_LBN
);
311 mdio_clause45_write(efx
, efx
->mii
.phy_id
,
313 PMA_PMD_XCONTROL_REG
, reg
);
317 rc
= mdio_clause45_wait_reset_mmds(efx
,
318 TENXPRESS_REQUIRED_DEVS
);
322 rc
= mdio_clause45_check_mmds(efx
, TENXPRESS_REQUIRED_DEVS
, 0);
327 rc
= tenxpress_init(efx
);
331 if (efx
->phy_type
== PHY_TYPE_SFT9001B
) {
332 rc
= device_create_file(&efx
->pci_dev
->dev
,
333 &dev_attr_phy_short_reach
);
338 schedule_timeout_uninterruptible(HZ
/ 5); /* 200ms */
340 /* Let XGXS and SerDes out of reset */
341 falcon_reset_xaui(efx
);
346 kfree(efx
->phy_data
);
347 efx
->phy_data
= NULL
;
351 /* Perform a "special software reset" on the PHY. The caller is
352 * responsible for saving and restoring the PHY hardware registers
353 * properly, and masking/unmasking LASI */
354 static int tenxpress_special_reset(struct efx_nic
*efx
)
358 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
359 * a special software reset can glitch the XGMAC sufficiently for stats
360 * requests to fail. Since we don't often special_reset, just lock. */
361 spin_lock(&efx
->stats_lock
);
364 reg
= mdio_clause45_read(efx
, efx
->mii
.phy_id
,
365 MDIO_MMD_PMAPMD
, PMA_PMD_XCONTROL_REG
);
366 reg
|= (1 << PMA_PMD_EXT_SSR_LBN
);
367 mdio_clause45_write(efx
, efx
->mii
.phy_id
, MDIO_MMD_PMAPMD
,
368 PMA_PMD_XCONTROL_REG
, reg
);
372 /* Wait for the blocks to come out of reset */
373 rc
= mdio_clause45_wait_reset_mmds(efx
,
374 TENXPRESS_REQUIRED_DEVS
);
378 /* Try and reconfigure the device */
379 rc
= tenxpress_init(efx
);
383 /* Wait for the XGXS state machine to churn */
386 spin_unlock(&efx
->stats_lock
);
390 static void sfx7101_check_bad_lp(struct efx_nic
*efx
, bool link_ok
)
392 struct tenxpress_phy_data
*pd
= efx
->phy_data
;
393 int phy_id
= efx
->mii
.phy_id
;
400 /* Check that AN has started but not completed. */
401 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_AN
,
403 if (!(reg
& (1 << MDIO_AN_STATUS_LP_AN_CAP_LBN
)))
404 return; /* LP status is unknown */
405 bad_lp
= !(reg
& (1 << MDIO_AN_STATUS_AN_DONE_LBN
));
410 /* Nothing to do if all is well and was previously so. */
411 if (!pd
->bad_lp_tries
)
414 /* Use the RX (red) LED as an error indicator once we've seen AN
415 * failure several times in a row, and also log a message. */
416 if (!bad_lp
|| pd
->bad_lp_tries
== MAX_BAD_LP_TRIES
) {
417 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_PMAPMD
,
418 PMA_PMD_LED_OVERR_REG
);
419 reg
&= ~(PMA_PMD_LED_MASK
<< PMA_PMD_LED_RX_LBN
);
421 reg
|= PMA_PMD_LED_OFF
<< PMA_PMD_LED_RX_LBN
;
423 reg
|= PMA_PMD_LED_FLASH
<< PMA_PMD_LED_RX_LBN
;
424 EFX_ERR(efx
, "appears to be plugged into a port"
425 " that is not 10GBASE-T capable. The PHY"
426 " supports 10GBASE-T ONLY, so no link can"
427 " be established\n");
429 mdio_clause45_write(efx
, phy_id
, MDIO_MMD_PMAPMD
,
430 PMA_PMD_LED_OVERR_REG
, reg
);
431 pd
->bad_lp_tries
= bad_lp
;
435 static bool sfx7101_link_ok(struct efx_nic
*efx
)
437 return mdio_clause45_links_ok(efx
,
438 MDIO_MMDREG_DEVS_PMAPMD
|
439 MDIO_MMDREG_DEVS_PCS
|
440 MDIO_MMDREG_DEVS_PHYXS
);
443 static bool sft9001_link_ok(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
445 int phy_id
= efx
->mii
.phy_id
;
448 if (efx_phy_mode_disabled(efx
->phy_mode
))
450 else if (efx
->loopback_mode
== LOOPBACK_GPHY
)
452 else if (efx
->loopback_mode
)
453 return mdio_clause45_links_ok(efx
,
454 MDIO_MMDREG_DEVS_PMAPMD
|
455 MDIO_MMDREG_DEVS_PHYXS
);
457 /* We must use the same definition of link state as LASI,
458 * otherwise we can miss a link state transition
460 if (ecmd
->speed
== 10000) {
461 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_PCS
,
463 return reg
& (1 << PCS_10GBASET_BLKLK_LBN
);
465 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_C22EXT
,
467 return reg
& (1 << C22EXT_STATUS_LINK_LBN
);
471 static void tenxpress_ext_loopback(struct efx_nic
*efx
)
473 int phy_id
= efx
->mii
.phy_id
;
475 mdio_clause45_set_flag(efx
, phy_id
, MDIO_MMD_PHYXS
,
476 PHYXS_TEST1
, LOOPBACK_NEAR_LBN
,
477 efx
->loopback_mode
== LOOPBACK_PHYXS
);
478 if (efx
->phy_type
!= PHY_TYPE_SFX7101
)
479 mdio_clause45_set_flag(efx
, phy_id
, MDIO_MMD_C22EXT
,
481 GPHY_LOOPBACK_NEAR_LBN
,
482 efx
->loopback_mode
== LOOPBACK_GPHY
);
485 static void tenxpress_low_power(struct efx_nic
*efx
)
487 int phy_id
= efx
->mii
.phy_id
;
489 if (efx
->phy_type
== PHY_TYPE_SFX7101
)
490 mdio_clause45_set_mmds_lpower(
491 efx
, !!(efx
->phy_mode
& PHY_MODE_LOW_POWER
),
492 TENXPRESS_REQUIRED_DEVS
);
494 mdio_clause45_set_flag(
495 efx
, phy_id
, MDIO_MMD_PMAPMD
,
496 PMA_PMD_XCONTROL_REG
, PMA_PMD_EXT_LPOWER_LBN
,
497 !!(efx
->phy_mode
& PHY_MODE_LOW_POWER
));
500 static void tenxpress_phy_reconfigure(struct efx_nic
*efx
)
502 struct tenxpress_phy_data
*phy_data
= efx
->phy_data
;
503 struct ethtool_cmd ecmd
;
504 bool phy_mode_change
, loop_reset
, loop_toggle
, loopback
;
506 if (efx
->phy_mode
& (PHY_MODE_OFF
| PHY_MODE_SPECIAL
)) {
507 phy_data
->phy_mode
= efx
->phy_mode
;
511 tenxpress_low_power(efx
);
513 phy_mode_change
= (efx
->phy_mode
== PHY_MODE_NORMAL
&&
514 phy_data
->phy_mode
!= PHY_MODE_NORMAL
);
515 loopback
= LOOPBACK_MASK(efx
) & efx
->phy_op
->loopbacks
;
516 loop_toggle
= LOOPBACK_CHANGED(phy_data
, efx
, efx
->phy_op
->loopbacks
);
517 loop_reset
= (LOOPBACK_OUT_OF(phy_data
, efx
, efx
->phy_op
->loopbacks
) ||
518 LOOPBACK_CHANGED(phy_data
, efx
, 1 << LOOPBACK_GPHY
));
520 if (loop_reset
|| loop_toggle
|| loopback
|| phy_mode_change
) {
523 efx
->phy_op
->get_settings(efx
, &ecmd
);
525 if (loop_reset
|| phy_mode_change
) {
526 tenxpress_special_reset(efx
);
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 */
532 falcon_reset_xaui(efx
);
535 if (efx
->phy_type
!= PHY_TYPE_SFX7101
) {
536 /* Only change autoneg once, on coming out or
537 * going into loopback */
539 ecmd
.autoneg
= !loopback
;
541 ecmd
.duplex
= DUPLEX_FULL
;
542 if (efx
->loopback_mode
== LOOPBACK_GPHY
)
543 ecmd
.speed
= SPEED_1000
;
545 ecmd
.speed
= SPEED_10000
;
549 rc
= efx
->phy_op
->set_settings(efx
, &ecmd
);
553 mdio_clause45_transmit_disable(efx
);
554 mdio_clause45_phy_reconfigure(efx
);
555 tenxpress_ext_loopback(efx
);
557 phy_data
->loopback_mode
= efx
->loopback_mode
;
558 phy_data
->phy_mode
= efx
->phy_mode
;
560 if (efx
->phy_type
== PHY_TYPE_SFX7101
) {
561 efx
->link_speed
= 10000;
563 efx
->link_up
= sfx7101_link_ok(efx
);
565 efx
->phy_op
->get_settings(efx
, &ecmd
);
566 efx
->link_speed
= ecmd
.speed
;
567 efx
->link_fd
= ecmd
.duplex
== DUPLEX_FULL
;
568 efx
->link_up
= sft9001_link_ok(efx
, &ecmd
);
570 efx
->link_fc
= mdio_clause45_get_pause(efx
);
573 /* Poll PHY for interrupt */
574 static void tenxpress_phy_poll(struct efx_nic
*efx
)
576 struct tenxpress_phy_data
*phy_data
= efx
->phy_data
;
577 bool change
= false, link_ok
;
580 if (efx
->phy_type
== PHY_TYPE_SFX7101
) {
581 link_ok
= sfx7101_link_ok(efx
);
582 if (link_ok
!= efx
->link_up
) {
585 link_fc
= mdio_clause45_get_pause(efx
);
586 if (link_fc
!= efx
->link_fc
)
589 sfx7101_check_bad_lp(efx
, link_ok
);
590 } else if (efx
->loopback_mode
) {
591 bool link_ok
= sft9001_link_ok(efx
, NULL
);
592 if (link_ok
!= efx
->link_up
)
595 u32 status
= mdio_clause45_read(efx
, efx
->mii
.phy_id
,
597 PMA_PMD_LASI_STATUS
);
598 if (status
& (1 << PMA_PMD_LS_ALARM_LBN
))
603 falcon_sim_phy_event(efx
);
605 if (phy_data
->phy_mode
!= PHY_MODE_NORMAL
)
608 if (EFX_WORKAROUND_10750(efx
) &&
609 atomic_read(&phy_data
->bad_crc_count
) > crc_error_reset_threshold
) {
610 EFX_ERR(efx
, "Resetting XAUI due to too many CRC errors\n");
611 falcon_reset_xaui(efx
);
612 atomic_set(&phy_data
->bad_crc_count
, 0);
616 static void tenxpress_phy_fini(struct efx_nic
*efx
)
620 if (efx
->phy_type
== PHY_TYPE_SFT9001B
) {
621 device_remove_file(&efx
->pci_dev
->dev
,
622 &dev_attr_phy_short_reach
);
624 /* Power down the LNPGA */
625 reg
= (1 << PMA_PMD_LNPGA_POWERDOWN_LBN
);
626 mdio_clause45_write(efx
, efx
->mii
.phy_id
, MDIO_MMD_PMAPMD
,
627 PMA_PMD_XCONTROL_REG
, reg
);
629 /* Waiting here ensures that the board fini, which can turn
630 * off the power to the PHY, won't get run until the LNPGA
631 * powerdown has been given long enough to complete. */
632 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT
); /* 200 ms */
635 kfree(efx
->phy_data
);
636 efx
->phy_data
= NULL
;
640 /* Set the RX and TX LEDs and Link LED flashing. The other LEDs
641 * (which probably aren't wired anyway) are left in AUTO mode */
642 void tenxpress_phy_blink(struct efx_nic
*efx
, bool blink
)
647 reg
= (PMA_PMD_LED_FLASH
<< PMA_PMD_LED_TX_LBN
) |
648 (PMA_PMD_LED_FLASH
<< PMA_PMD_LED_RX_LBN
) |
649 (PMA_PMD_LED_FLASH
<< PMA_PMD_LED_LINK_LBN
);
651 reg
= PMA_PMD_LED_DEFAULT
;
653 mdio_clause45_write(efx
, efx
->mii
.phy_id
, MDIO_MMD_PMAPMD
,
654 PMA_PMD_LED_OVERR_REG
, reg
);
657 static int tenxpress_phy_test(struct efx_nic
*efx
)
659 /* BIST is automatically run after a special software reset */
660 return tenxpress_special_reset(efx
);
663 static u32
tenxpress_get_xnp_lpa(struct efx_nic
*efx
)
665 int phy
= efx
->mii
.phy_id
;
669 if (efx
->phy_type
!= PHY_TYPE_SFX7101
) {
670 reg
= mdio_clause45_read(efx
, phy
, MDIO_MMD_C22EXT
,
672 if (reg
& (1 << C22EXT_MSTSLV_1000_HD_LBN
))
673 lpa
|= ADVERTISED_1000baseT_Half
;
674 if (reg
& (1 << C22EXT_MSTSLV_1000_FD_LBN
))
675 lpa
|= ADVERTISED_1000baseT_Full
;
677 reg
= mdio_clause45_read(efx
, phy
, MDIO_MMD_AN
, MDIO_AN_10GBT_STATUS
);
678 if (reg
& (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN
))
679 lpa
|= ADVERTISED_10000baseT_Full
;
683 static void sfx7101_get_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
685 mdio_clause45_get_settings_ext(efx
, ecmd
, ADVERTISED_10000baseT_Full
,
686 tenxpress_get_xnp_lpa(efx
));
687 ecmd
->supported
|= SUPPORTED_10000baseT_Full
;
688 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
691 static void sft9001_get_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
693 int phy_id
= efx
->mii
.phy_id
;
697 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_PMAPMD
,
698 PMA_PMD_SPEED_ENABLE_REG
);
699 if (EFX_WORKAROUND_13204(efx
) && (reg
& (1 << PMA_PMD_100TX_ADV_LBN
)))
700 xnp_adv
|= ADVERTISED_100baseT_Full
;
701 if (reg
& (1 << PMA_PMD_1000T_ADV_LBN
))
702 xnp_adv
|= ADVERTISED_1000baseT_Full
;
703 if (reg
& (1 << PMA_PMD_10000T_ADV_LBN
))
704 xnp_adv
|= ADVERTISED_10000baseT_Full
;
706 mdio_clause45_get_settings_ext(efx
, ecmd
, xnp_adv
,
707 tenxpress_get_xnp_lpa(efx
));
709 ecmd
->supported
|= (SUPPORTED_100baseT_Half
|
710 SUPPORTED_100baseT_Full
|
711 SUPPORTED_1000baseT_Full
);
713 /* Use the vendor defined C22ext register for duplex settings */
714 if (ecmd
->speed
!= SPEED_10000
&& !ecmd
->autoneg
) {
715 reg
= mdio_clause45_read(efx
, phy_id
, MDIO_MMD_C22EXT
,
717 ecmd
->duplex
= (reg
& (1 << GPHY_DUPLEX_LBN
) ?
718 DUPLEX_FULL
: DUPLEX_HALF
);
722 static int sft9001_set_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
724 int phy_id
= efx
->mii
.phy_id
;
727 rc
= mdio_clause45_set_settings(efx
, ecmd
);
731 if (ecmd
->speed
!= SPEED_10000
&& !ecmd
->autoneg
)
732 mdio_clause45_set_flag(efx
, phy_id
, MDIO_MMD_C22EXT
,
733 GPHY_XCONTROL_REG
, GPHY_DUPLEX_LBN
,
734 ecmd
->duplex
== DUPLEX_FULL
);
739 static bool sft9001_set_xnp_advertise(struct efx_nic
*efx
, u32 advertising
)
741 int phy
= efx
->mii
.phy_id
;
742 int reg
= mdio_clause45_read(efx
, phy
, MDIO_MMD_PMAPMD
,
743 PMA_PMD_SPEED_ENABLE_REG
);
746 reg
&= ~((1 << 2) | (1 << 3));
747 if (EFX_WORKAROUND_13204(efx
) &&
748 (advertising
& ADVERTISED_100baseT_Full
))
749 reg
|= 1 << PMA_PMD_100TX_ADV_LBN
;
750 if (advertising
& ADVERTISED_1000baseT_Full
)
751 reg
|= 1 << PMA_PMD_1000T_ADV_LBN
;
752 if (advertising
& ADVERTISED_10000baseT_Full
)
753 reg
|= 1 << PMA_PMD_10000T_ADV_LBN
;
754 mdio_clause45_write(efx
, phy
, MDIO_MMD_PMAPMD
,
755 PMA_PMD_SPEED_ENABLE_REG
, reg
);
757 enabled
= (advertising
&
758 (ADVERTISED_1000baseT_Half
|
759 ADVERTISED_1000baseT_Full
|
760 ADVERTISED_10000baseT_Full
));
761 if (EFX_WORKAROUND_13204(efx
))
762 enabled
|= (advertising
& ADVERTISED_100baseT_Full
);
766 struct efx_phy_operations falcon_sfx7101_phy_ops
= {
768 .init
= tenxpress_phy_init
,
769 .reconfigure
= tenxpress_phy_reconfigure
,
770 .poll
= tenxpress_phy_poll
,
771 .fini
= tenxpress_phy_fini
,
772 .clear_interrupt
= efx_port_dummy_op_void
,
773 .test
= tenxpress_phy_test
,
774 .get_settings
= sfx7101_get_settings
,
775 .set_settings
= mdio_clause45_set_settings
,
776 .mmds
= TENXPRESS_REQUIRED_DEVS
,
777 .loopbacks
= SFX7101_LOOPBACKS
,
780 struct efx_phy_operations falcon_sft9001_phy_ops
= {
781 .macs
= EFX_GMAC
| EFX_XMAC
,
782 .init
= tenxpress_phy_init
,
783 .reconfigure
= tenxpress_phy_reconfigure
,
784 .poll
= tenxpress_phy_poll
,
785 .fini
= tenxpress_phy_fini
,
786 .clear_interrupt
= efx_port_dummy_op_void
,
787 .test
= tenxpress_phy_test
,
788 .get_settings
= sft9001_get_settings
,
789 .set_settings
= sft9001_set_settings
,
790 .set_xnp_advertise
= sft9001_set_xnp_advertise
,
791 .mmds
= TENXPRESS_REQUIRED_DEVS
,
792 .loopbacks
= SFT9001_LOOPBACKS
,