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 /* Cable diagnostics - SFT9001 only */
110 #define PMA_PMD_CDIAG_CTRL_REG 49213
111 #define CDIAG_CTRL_IMMED_LBN 15
112 #define CDIAG_CTRL_BRK_LINK_LBN 12
113 #define CDIAG_CTRL_IN_PROG_LBN 11
114 #define CDIAG_CTRL_LEN_UNIT_LBN 10
115 #define CDIAG_CTRL_LEN_METRES 1
116 #define PMA_PMD_CDIAG_RES_REG 49174
117 #define CDIAG_RES_A_LBN 12
118 #define CDIAG_RES_B_LBN 8
119 #define CDIAG_RES_C_LBN 4
120 #define CDIAG_RES_D_LBN 0
121 #define CDIAG_RES_WIDTH 4
122 #define CDIAG_RES_OPEN 2
123 #define CDIAG_RES_OK 1
124 #define CDIAG_RES_INVALID 0
125 /* Set of 4 registers for pairs A-D */
126 #define PMA_PMD_CDIAG_LEN_REG 49175
128 /* Serdes control registers - SFT9001 only */
129 #define PMA_PMD_CSERDES_CTRL_REG 64258
130 /* Set the 156.25 MHz output to 312.5 MHz to drive Falcon's XMAC */
131 #define PMA_PMD_CSERDES_DEFAULT 0x000f
133 /* Misc register defines - SFX7101 only */
134 #define PCS_CLOCK_CTRL_REG 55297
135 #define PLL312_RST_N_LBN 2
137 #define PCS_SOFT_RST2_REG 55302
138 #define SERDES_RST_N_LBN 13
139 #define XGXS_RST_N_LBN 12
141 #define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
142 #define CLK312_EN_LBN 3
144 /* PHYXS registers */
145 #define PHYXS_XCONTROL_REG 49152
146 #define PHYXS_RESET_LBN 15
147 #define PHYXS_RESET_WIDTH 1
149 #define PHYXS_TEST1 (49162)
150 #define LOOPBACK_NEAR_LBN (8)
151 #define LOOPBACK_NEAR_WIDTH (1)
153 #define PCS_10GBASET_STAT1 32
154 #define PCS_10GBASET_BLKLK_LBN 0
155 #define PCS_10GBASET_BLKLK_WIDTH 1
157 /* Boot status register */
158 #define PCS_BOOT_STATUS_REG 53248
159 #define PCS_BOOT_FATAL_ERR_LBN (0)
160 #define PCS_BOOT_PROGRESS_LBN (1)
161 #define PCS_BOOT_PROGRESS_WIDTH (2)
162 #define PCS_BOOT_COMPLETE_LBN (3)
164 #define PCS_BOOT_MAX_DELAY (100)
165 #define PCS_BOOT_POLL_DELAY (10)
167 /* 100M/1G PHY registers */
168 #define GPHY_XCONTROL_REG 49152
169 #define GPHY_ISOLATE_LBN 10
170 #define GPHY_ISOLATE_WIDTH 1
171 #define GPHY_DUPLEX_LBN 8
172 #define GPHY_DUPLEX_WIDTH 1
173 #define GPHY_LOOPBACK_NEAR_LBN 14
174 #define GPHY_LOOPBACK_NEAR_WIDTH 1
176 #define C22EXT_STATUS_REG 49153
177 #define C22EXT_STATUS_LINK_LBN 2
178 #define C22EXT_STATUS_LINK_WIDTH 1
180 #define C22EXT_MSTSLV_REG 49162
181 #define C22EXT_MSTSLV_1000_HD_LBN 10
182 #define C22EXT_MSTSLV_1000_HD_WIDTH 1
183 #define C22EXT_MSTSLV_1000_FD_LBN 11
184 #define C22EXT_MSTSLV_1000_FD_WIDTH 1
186 /* Time to wait between powering down the LNPGA and turning off the power
188 #define LNPGA_PDOWN_WAIT (HZ / 5)
190 static int crc_error_reset_threshold = 100;
191 module_param(crc_error_reset_threshold, int, 0644);
192 MODULE_PARM_DESC(crc_error_reset_threshold,
193 "Max number of CRC errors before XAUI reset");
195 struct tenxpress_phy_data {
196 enum efx_loopback_mode loopback_mode;
197 atomic_t bad_crc_count;
198 enum efx_phy_mode phy_mode;
202 void tenxpress_crc_err(struct efx_nic *efx)
204 struct tenxpress_phy_data *phy_data = efx->phy_data;
205 if (phy_data != NULL)
206 atomic_inc(&phy_data->bad_crc_count);
209 static ssize_t show_phy_short_reach(struct device *dev,
210 struct device_attribute *attr, char *buf)
212 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
215 reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
216 MDIO_PMAPMD_10GBT_TXPWR);
217 return sprintf(buf, "%d\n",
218 !!(reg & (1 << MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN)));
221 static ssize_t set_phy_short_reach(struct device *dev,
222 struct device_attribute *attr,
223 const char *buf, size_t count)
225 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
228 mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
229 MDIO_PMAPMD_10GBT_TXPWR,
230 MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN,
231 count != 0 && *buf != '0');
232 efx_reconfigure_port(efx);
238 static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
239 set_phy_short_reach);
241 /* Check that the C166 has booted successfully */
242 static int tenxpress_phy_check(struct efx_nic *efx)
244 int phy_id = efx->mii.phy_id;
245 int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY;
248 /* Wait for the boot to complete (or not) */
250 boot_stat = mdio_clause45_read(efx, phy_id,
252 PCS_BOOT_STATUS_REG);
253 if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN))
256 udelay(PCS_BOOT_POLL_DELAY);
260 EFX_ERR(efx, "%s: PHY boot timed out. Last status "
262 (boot_stat >> PCS_BOOT_PROGRESS_LBN) &
263 ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1));
270 static int tenxpress_init(struct efx_nic *efx)
272 int phy_id = efx->mii.phy_id;
276 if (efx->phy_type == PHY_TYPE_SFX7101) {
277 /* Enable 312.5 MHz clock */
278 mdio_clause45_write(efx, phy_id,
279 MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
282 /* Enable 312.5 MHz clock and GMII */
283 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
284 PMA_PMD_XCONTROL_REG);
285 reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
286 (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
287 (1 << PMA_PMD_EXT_CLK312_LBN));
288 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
289 PMA_PMD_XCONTROL_REG, reg);
290 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
291 GPHY_XCONTROL_REG, GPHY_ISOLATE_LBN,
295 rc = tenxpress_phy_check(efx);
299 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
300 if (efx->phy_type == PHY_TYPE_SFX7101) {
301 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
302 PMA_PMD_LED_CTRL_REG,
303 PMA_PMA_LED_ACTIVITY_LBN,
305 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
306 PMA_PMD_LED_OVERR_REG, PMA_PMD_LED_DEFAULT);
312 static int tenxpress_phy_init(struct efx_nic *efx)
314 struct tenxpress_phy_data *phy_data;
317 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
320 efx->phy_data = phy_data;
321 phy_data->phy_mode = efx->phy_mode;
323 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
324 if (efx->phy_type == PHY_TYPE_SFT9001A) {
326 reg = mdio_clause45_read(efx, efx->mii.phy_id,
328 PMA_PMD_XCONTROL_REG);
329 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
330 mdio_clause45_write(efx, efx->mii.phy_id,
332 PMA_PMD_XCONTROL_REG, reg);
336 rc = mdio_clause45_wait_reset_mmds(efx,
337 TENXPRESS_REQUIRED_DEVS);
341 rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
346 rc = tenxpress_init(efx);
350 if (efx->phy_type == PHY_TYPE_SFT9001B) {
351 rc = device_create_file(&efx->pci_dev->dev,
352 &dev_attr_phy_short_reach);
357 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
359 /* Let XGXS and SerDes out of reset */
360 falcon_reset_xaui(efx);
365 kfree(efx->phy_data);
366 efx->phy_data = NULL;
370 /* Perform a "special software reset" on the PHY. The caller is
371 * responsible for saving and restoring the PHY hardware registers
372 * properly, and masking/unmasking LASI */
373 static int tenxpress_special_reset(struct efx_nic *efx)
377 /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
378 * a special software reset can glitch the XGMAC sufficiently for stats
379 * requests to fail. Since we don't often special_reset, just lock. */
380 spin_lock(&efx->stats_lock);
383 reg = mdio_clause45_read(efx, efx->mii.phy_id,
384 MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
385 reg |= (1 << PMA_PMD_EXT_SSR_LBN);
386 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
387 PMA_PMD_XCONTROL_REG, reg);
391 /* Wait for the blocks to come out of reset */
392 rc = mdio_clause45_wait_reset_mmds(efx,
393 TENXPRESS_REQUIRED_DEVS);
397 /* Try and reconfigure the device */
398 rc = tenxpress_init(efx);
402 /* Wait for the XGXS state machine to churn */
405 spin_unlock(&efx->stats_lock);
409 static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
411 struct tenxpress_phy_data *pd = efx->phy_data;
412 int phy_id = efx->mii.phy_id;
419 /* Check that AN has started but not completed. */
420 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
422 if (!(reg & (1 << MDIO_AN_STATUS_LP_AN_CAP_LBN)))
423 return; /* LP status is unknown */
424 bad_lp = !(reg & (1 << MDIO_AN_STATUS_AN_DONE_LBN));
429 /* Nothing to do if all is well and was previously so. */
430 if (!pd->bad_lp_tries)
433 /* Use the RX (red) LED as an error indicator once we've seen AN
434 * failure several times in a row, and also log a message. */
435 if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
436 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
437 PMA_PMD_LED_OVERR_REG);
438 reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
440 reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
442 reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
443 EFX_ERR(efx, "appears to be plugged into a port"
444 " that is not 10GBASE-T capable. The PHY"
445 " supports 10GBASE-T ONLY, so no link can"
446 " be established\n");
448 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
449 PMA_PMD_LED_OVERR_REG, reg);
450 pd->bad_lp_tries = bad_lp;
454 static bool sfx7101_link_ok(struct efx_nic *efx)
456 return mdio_clause45_links_ok(efx,
457 MDIO_MMDREG_DEVS_PMAPMD |
458 MDIO_MMDREG_DEVS_PCS |
459 MDIO_MMDREG_DEVS_PHYXS);
462 static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
464 int phy_id = efx->mii.phy_id;
467 if (efx_phy_mode_disabled(efx->phy_mode))
469 else if (efx->loopback_mode == LOOPBACK_GPHY)
471 else if (efx->loopback_mode)
472 return mdio_clause45_links_ok(efx,
473 MDIO_MMDREG_DEVS_PMAPMD |
474 MDIO_MMDREG_DEVS_PHYXS);
476 /* We must use the same definition of link state as LASI,
477 * otherwise we can miss a link state transition
479 if (ecmd->speed == 10000) {
480 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS,
482 return reg & (1 << PCS_10GBASET_BLKLK_LBN);
484 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
486 return reg & (1 << C22EXT_STATUS_LINK_LBN);
490 static void tenxpress_ext_loopback(struct efx_nic *efx)
492 int phy_id = efx->mii.phy_id;
494 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
495 PHYXS_TEST1, LOOPBACK_NEAR_LBN,
496 efx->loopback_mode == LOOPBACK_PHYXS);
497 if (efx->phy_type != PHY_TYPE_SFX7101)
498 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
500 GPHY_LOOPBACK_NEAR_LBN,
501 efx->loopback_mode == LOOPBACK_GPHY);
504 static void tenxpress_low_power(struct efx_nic *efx)
506 int phy_id = efx->mii.phy_id;
508 if (efx->phy_type == PHY_TYPE_SFX7101)
509 mdio_clause45_set_mmds_lpower(
510 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
511 TENXPRESS_REQUIRED_DEVS);
513 mdio_clause45_set_flag(
514 efx, phy_id, MDIO_MMD_PMAPMD,
515 PMA_PMD_XCONTROL_REG, PMA_PMD_EXT_LPOWER_LBN,
516 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
519 static void tenxpress_phy_reconfigure(struct efx_nic *efx)
521 struct tenxpress_phy_data *phy_data = efx->phy_data;
522 struct ethtool_cmd ecmd;
523 bool phy_mode_change, loop_reset, loop_toggle, loopback;
525 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
526 phy_data->phy_mode = efx->phy_mode;
530 tenxpress_low_power(efx);
532 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
533 phy_data->phy_mode != PHY_MODE_NORMAL);
534 loopback = LOOPBACK_MASK(efx) & efx->phy_op->loopbacks;
535 loop_toggle = LOOPBACK_CHANGED(phy_data, efx, efx->phy_op->loopbacks);
536 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
537 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
539 if (loop_reset || loop_toggle || loopback || phy_mode_change) {
542 efx->phy_op->get_settings(efx, &ecmd);
544 if (loop_reset || phy_mode_change) {
545 tenxpress_special_reset(efx);
547 /* Reset XAUI if we were in 10G, and are staying
548 * in 10G. If we're moving into and out of 10G
549 * then xaui will be reset anyway */
551 falcon_reset_xaui(efx);
554 if (efx->phy_type != PHY_TYPE_SFX7101) {
555 /* Only change autoneg once, on coming out or
556 * going into loopback */
558 ecmd.autoneg = !loopback;
560 ecmd.duplex = DUPLEX_FULL;
561 if (efx->loopback_mode == LOOPBACK_GPHY)
562 ecmd.speed = SPEED_1000;
564 ecmd.speed = SPEED_10000;
568 rc = efx->phy_op->set_settings(efx, &ecmd);
572 mdio_clause45_transmit_disable(efx);
573 mdio_clause45_phy_reconfigure(efx);
574 tenxpress_ext_loopback(efx);
576 phy_data->loopback_mode = efx->loopback_mode;
577 phy_data->phy_mode = efx->phy_mode;
579 if (efx->phy_type == PHY_TYPE_SFX7101) {
580 efx->link_speed = 10000;
582 efx->link_up = sfx7101_link_ok(efx);
584 efx->phy_op->get_settings(efx, &ecmd);
585 efx->link_speed = ecmd.speed;
586 efx->link_fd = ecmd.duplex == DUPLEX_FULL;
587 efx->link_up = sft9001_link_ok(efx, &ecmd);
589 efx->link_fc = mdio_clause45_get_pause(efx);
592 /* Poll PHY for interrupt */
593 static void tenxpress_phy_poll(struct efx_nic *efx)
595 struct tenxpress_phy_data *phy_data = efx->phy_data;
596 bool change = false, link_ok;
599 if (efx->phy_type == PHY_TYPE_SFX7101) {
600 link_ok = sfx7101_link_ok(efx);
601 if (link_ok != efx->link_up) {
604 link_fc = mdio_clause45_get_pause(efx);
605 if (link_fc != efx->link_fc)
608 sfx7101_check_bad_lp(efx, link_ok);
609 } else if (efx->loopback_mode) {
610 bool link_ok = sft9001_link_ok(efx, NULL);
611 if (link_ok != efx->link_up)
614 u32 status = mdio_clause45_read(efx, efx->mii.phy_id,
616 PMA_PMD_LASI_STATUS);
617 if (status & (1 << PMA_PMD_LS_ALARM_LBN))
622 falcon_sim_phy_event(efx);
624 if (phy_data->phy_mode != PHY_MODE_NORMAL)
627 if (EFX_WORKAROUND_10750(efx) &&
628 atomic_read(&phy_data->bad_crc_count) > crc_error_reset_threshold) {
629 EFX_ERR(efx, "Resetting XAUI due to too many CRC errors\n");
630 falcon_reset_xaui(efx);
631 atomic_set(&phy_data->bad_crc_count, 0);
635 static void tenxpress_phy_fini(struct efx_nic *efx)
639 if (efx->phy_type == PHY_TYPE_SFT9001B)
640 device_remove_file(&efx->pci_dev->dev,
641 &dev_attr_phy_short_reach);
643 if (efx->phy_type == PHY_TYPE_SFX7101) {
644 /* Power down the LNPGA */
645 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
646 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
647 PMA_PMD_XCONTROL_REG, reg);
649 /* Waiting here ensures that the board fini, which can turn
650 * off the power to the PHY, won't get run until the LNPGA
651 * powerdown has been given long enough to complete. */
652 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
655 kfree(efx->phy_data);
656 efx->phy_data = NULL;
660 /* Set the RX and TX LEDs and Link LED flashing. The other LEDs
661 * (which probably aren't wired anyway) are left in AUTO mode */
662 void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
667 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
668 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
669 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
671 reg = PMA_PMD_LED_DEFAULT;
673 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
674 PMA_PMD_LED_OVERR_REG, reg);
677 static const char *const sfx7101_test_names[] = {
682 sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
686 if (!(flags & ETH_TEST_FL_OFFLINE))
689 /* BIST is automatically run after a special software reset */
690 rc = tenxpress_special_reset(efx);
691 results[0] = rc ? -1 : 1;
695 static const char *const sft9001_test_names[] = {
697 "cable.pairA.status",
698 "cable.pairB.status",
699 "cable.pairC.status",
700 "cable.pairD.status",
701 "cable.pairA.length",
702 "cable.pairB.length",
703 "cable.pairC.length",
704 "cable.pairD.length",
707 static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
709 struct ethtool_cmd ecmd;
710 int phy_id = efx->mii.phy_id;
711 int rc = 0, rc2, i, res_reg;
713 if (!(flags & ETH_TEST_FL_OFFLINE))
716 efx->phy_op->get_settings(efx, &ecmd);
718 /* Initialise cable diagnostic results to unknown failure */
719 for (i = 1; i < 9; ++i)
722 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
723 * A cable fault is not a self-test failure, but a timeout is. */
724 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
725 PMA_PMD_CDIAG_CTRL_REG,
726 (1 << CDIAG_CTRL_IMMED_LBN) |
727 (1 << CDIAG_CTRL_BRK_LINK_LBN) |
728 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
730 while (mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
731 PMA_PMD_CDIAG_CTRL_REG) &
732 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
739 res_reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
740 PMA_PMD_CDIAG_RES_REG);
741 for (i = 0; i < 4; i++) {
743 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
744 & ((1 << CDIAG_RES_WIDTH) - 1);
745 int len_reg = mdio_clause45_read(efx, efx->mii.phy_id,
747 PMA_PMD_CDIAG_LEN_REG + i);
748 if (pair_res == CDIAG_RES_OK)
750 else if (pair_res == CDIAG_RES_INVALID)
753 results[1 + i] = -pair_res;
754 if (pair_res != CDIAG_RES_INVALID &&
755 pair_res != CDIAG_RES_OPEN &&
757 results[5 + i] = len_reg;
760 /* We must reset to exit cable diagnostic mode. The BIST will
761 * also run when we do this. */
763 rc2 = tenxpress_special_reset(efx);
764 results[0] = rc2 ? -1 : 1;
768 rc2 = efx->phy_op->set_settings(efx, &ecmd);
775 static u32 tenxpress_get_xnp_lpa(struct efx_nic *efx)
777 int phy = efx->mii.phy_id;
781 if (efx->phy_type != PHY_TYPE_SFX7101) {
782 reg = mdio_clause45_read(efx, phy, MDIO_MMD_C22EXT,
784 if (reg & (1 << C22EXT_MSTSLV_1000_HD_LBN))
785 lpa |= ADVERTISED_1000baseT_Half;
786 if (reg & (1 << C22EXT_MSTSLV_1000_FD_LBN))
787 lpa |= ADVERTISED_1000baseT_Full;
789 reg = mdio_clause45_read(efx, phy, MDIO_MMD_AN, MDIO_AN_10GBT_STATUS);
790 if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN))
791 lpa |= ADVERTISED_10000baseT_Full;
795 static void sfx7101_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
797 mdio_clause45_get_settings_ext(efx, ecmd, ADVERTISED_10000baseT_Full,
798 tenxpress_get_xnp_lpa(efx));
799 ecmd->supported |= SUPPORTED_10000baseT_Full;
800 ecmd->advertising |= ADVERTISED_10000baseT_Full;
803 static void sft9001_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
805 int phy_id = efx->mii.phy_id;
809 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
810 PMA_PMD_SPEED_ENABLE_REG);
811 if (EFX_WORKAROUND_13204(efx) && (reg & (1 << PMA_PMD_100TX_ADV_LBN)))
812 xnp_adv |= ADVERTISED_100baseT_Full;
813 if (reg & (1 << PMA_PMD_1000T_ADV_LBN))
814 xnp_adv |= ADVERTISED_1000baseT_Full;
815 if (reg & (1 << PMA_PMD_10000T_ADV_LBN))
816 xnp_adv |= ADVERTISED_10000baseT_Full;
818 mdio_clause45_get_settings_ext(efx, ecmd, xnp_adv,
819 tenxpress_get_xnp_lpa(efx));
821 ecmd->supported |= (SUPPORTED_100baseT_Half |
822 SUPPORTED_100baseT_Full |
823 SUPPORTED_1000baseT_Full);
825 /* Use the vendor defined C22ext register for duplex settings */
826 if (ecmd->speed != SPEED_10000 && !ecmd->autoneg) {
827 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
829 ecmd->duplex = (reg & (1 << GPHY_DUPLEX_LBN) ?
830 DUPLEX_FULL : DUPLEX_HALF);
834 static int sft9001_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
836 int phy_id = efx->mii.phy_id;
839 rc = mdio_clause45_set_settings(efx, ecmd);
843 if (ecmd->speed != SPEED_10000 && !ecmd->autoneg)
844 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
845 GPHY_XCONTROL_REG, GPHY_DUPLEX_LBN,
846 ecmd->duplex == DUPLEX_FULL);
851 static bool sft9001_set_xnp_advertise(struct efx_nic *efx, u32 advertising)
853 int phy = efx->mii.phy_id;
854 int reg = mdio_clause45_read(efx, phy, MDIO_MMD_PMAPMD,
855 PMA_PMD_SPEED_ENABLE_REG);
858 reg &= ~((1 << 2) | (1 << 3));
859 if (EFX_WORKAROUND_13204(efx) &&
860 (advertising & ADVERTISED_100baseT_Full))
861 reg |= 1 << PMA_PMD_100TX_ADV_LBN;
862 if (advertising & ADVERTISED_1000baseT_Full)
863 reg |= 1 << PMA_PMD_1000T_ADV_LBN;
864 if (advertising & ADVERTISED_10000baseT_Full)
865 reg |= 1 << PMA_PMD_10000T_ADV_LBN;
866 mdio_clause45_write(efx, phy, MDIO_MMD_PMAPMD,
867 PMA_PMD_SPEED_ENABLE_REG, reg);
869 enabled = (advertising &
870 (ADVERTISED_1000baseT_Half |
871 ADVERTISED_1000baseT_Full |
872 ADVERTISED_10000baseT_Full));
873 if (EFX_WORKAROUND_13204(efx))
874 enabled |= (advertising & ADVERTISED_100baseT_Full);
878 struct efx_phy_operations falcon_sfx7101_phy_ops = {
880 .init = tenxpress_phy_init,
881 .reconfigure = tenxpress_phy_reconfigure,
882 .poll = tenxpress_phy_poll,
883 .fini = tenxpress_phy_fini,
884 .clear_interrupt = efx_port_dummy_op_void,
885 .get_settings = sfx7101_get_settings,
886 .set_settings = mdio_clause45_set_settings,
887 .num_tests = ARRAY_SIZE(sfx7101_test_names),
888 .test_names = sfx7101_test_names,
889 .run_tests = sfx7101_run_tests,
890 .mmds = TENXPRESS_REQUIRED_DEVS,
891 .loopbacks = SFX7101_LOOPBACKS,
894 struct efx_phy_operations falcon_sft9001_phy_ops = {
895 .macs = EFX_GMAC | EFX_XMAC,
896 .init = tenxpress_phy_init,
897 .reconfigure = tenxpress_phy_reconfigure,
898 .poll = tenxpress_phy_poll,
899 .fini = tenxpress_phy_fini,
900 .clear_interrupt = efx_port_dummy_op_void,
901 .get_settings = sft9001_get_settings,
902 .set_settings = sft9001_set_settings,
903 .set_xnp_advertise = sft9001_set_xnp_advertise,
904 .num_tests = ARRAY_SIZE(sft9001_test_names),
905 .test_names = sft9001_test_names,
906 .run_tests = sft9001_run_tests,
907 .mmds = TENXPRESS_REQUIRED_DEVS,
908 .loopbacks = SFT9001_LOOPBACKS,