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 /* Power down the LNPGA */
644 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
645 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
646 PMA_PMD_XCONTROL_REG, reg);
648 /* Waiting here ensures that the board fini, which can turn
649 * off the power to the PHY, won't get run until the LNPGA
650 * powerdown has been given long enough to complete. */
651 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
654 kfree(efx->phy_data);
655 efx->phy_data = NULL;
659 /* Set the RX and TX LEDs and Link LED flashing. The other LEDs
660 * (which probably aren't wired anyway) are left in AUTO mode */
661 void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
666 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
667 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
668 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
670 reg = PMA_PMD_LED_DEFAULT;
672 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
673 PMA_PMD_LED_OVERR_REG, reg);
676 static const char *const sfx7101_test_names[] = {
681 sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
685 if (!(flags & ETH_TEST_FL_OFFLINE))
688 /* BIST is automatically run after a special software reset */
689 rc = tenxpress_special_reset(efx);
690 results[0] = rc ? -1 : 1;
694 static const char *const sft9001_test_names[] = {
696 "cable.pairA.status",
697 "cable.pairB.status",
698 "cable.pairC.status",
699 "cable.pairD.status",
700 "cable.pairA.length",
701 "cable.pairB.length",
702 "cable.pairC.length",
703 "cable.pairD.length",
706 static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
708 struct ethtool_cmd ecmd;
709 int phy_id = efx->mii.phy_id;
710 int rc = 0, rc2, i, res_reg;
712 if (!(flags & ETH_TEST_FL_OFFLINE))
715 efx->phy_op->get_settings(efx, &ecmd);
717 /* Initialise cable diagnostic results to unknown failure */
718 for (i = 1; i < 9; ++i)
721 /* Run cable diagnostics; wait up to 5 seconds for them to complete.
722 * A cable fault is not a self-test failure, but a timeout is. */
723 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
724 PMA_PMD_CDIAG_CTRL_REG,
725 (1 << CDIAG_CTRL_IMMED_LBN) |
726 (1 << CDIAG_CTRL_BRK_LINK_LBN) |
727 (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
729 while (mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
730 PMA_PMD_CDIAG_CTRL_REG) &
731 (1 << CDIAG_CTRL_IN_PROG_LBN)) {
738 res_reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
739 PMA_PMD_CDIAG_RES_REG);
740 for (i = 0; i < 4; i++) {
742 (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
743 & ((1 << CDIAG_RES_WIDTH) - 1);
744 int len_reg = mdio_clause45_read(efx, efx->mii.phy_id,
746 PMA_PMD_CDIAG_LEN_REG + i);
747 if (pair_res == CDIAG_RES_OK)
749 else if (pair_res == CDIAG_RES_INVALID)
752 results[1 + i] = -pair_res;
753 if (pair_res != CDIAG_RES_INVALID &&
754 pair_res != CDIAG_RES_OPEN &&
756 results[5 + i] = len_reg;
759 /* We must reset to exit cable diagnostic mode. The BIST will
760 * also run when we do this. */
762 rc2 = tenxpress_special_reset(efx);
763 results[0] = rc2 ? -1 : 1;
767 rc2 = efx->phy_op->set_settings(efx, &ecmd);
774 static u32 tenxpress_get_xnp_lpa(struct efx_nic *efx)
776 int phy = efx->mii.phy_id;
780 if (efx->phy_type != PHY_TYPE_SFX7101) {
781 reg = mdio_clause45_read(efx, phy, MDIO_MMD_C22EXT,
783 if (reg & (1 << C22EXT_MSTSLV_1000_HD_LBN))
784 lpa |= ADVERTISED_1000baseT_Half;
785 if (reg & (1 << C22EXT_MSTSLV_1000_FD_LBN))
786 lpa |= ADVERTISED_1000baseT_Full;
788 reg = mdio_clause45_read(efx, phy, MDIO_MMD_AN, MDIO_AN_10GBT_STATUS);
789 if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN))
790 lpa |= ADVERTISED_10000baseT_Full;
794 static void sfx7101_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
796 mdio_clause45_get_settings_ext(efx, ecmd, ADVERTISED_10000baseT_Full,
797 tenxpress_get_xnp_lpa(efx));
798 ecmd->supported |= SUPPORTED_10000baseT_Full;
799 ecmd->advertising |= ADVERTISED_10000baseT_Full;
802 static void sft9001_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
804 int phy_id = efx->mii.phy_id;
808 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
809 PMA_PMD_SPEED_ENABLE_REG);
810 if (EFX_WORKAROUND_13204(efx) && (reg & (1 << PMA_PMD_100TX_ADV_LBN)))
811 xnp_adv |= ADVERTISED_100baseT_Full;
812 if (reg & (1 << PMA_PMD_1000T_ADV_LBN))
813 xnp_adv |= ADVERTISED_1000baseT_Full;
814 if (reg & (1 << PMA_PMD_10000T_ADV_LBN))
815 xnp_adv |= ADVERTISED_10000baseT_Full;
817 mdio_clause45_get_settings_ext(efx, ecmd, xnp_adv,
818 tenxpress_get_xnp_lpa(efx));
820 ecmd->supported |= (SUPPORTED_100baseT_Half |
821 SUPPORTED_100baseT_Full |
822 SUPPORTED_1000baseT_Full);
824 /* Use the vendor defined C22ext register for duplex settings */
825 if (ecmd->speed != SPEED_10000 && !ecmd->autoneg) {
826 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
828 ecmd->duplex = (reg & (1 << GPHY_DUPLEX_LBN) ?
829 DUPLEX_FULL : DUPLEX_HALF);
833 static int sft9001_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
835 int phy_id = efx->mii.phy_id;
838 rc = mdio_clause45_set_settings(efx, ecmd);
842 if (ecmd->speed != SPEED_10000 && !ecmd->autoneg)
843 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
844 GPHY_XCONTROL_REG, GPHY_DUPLEX_LBN,
845 ecmd->duplex == DUPLEX_FULL);
850 static bool sft9001_set_xnp_advertise(struct efx_nic *efx, u32 advertising)
852 int phy = efx->mii.phy_id;
853 int reg = mdio_clause45_read(efx, phy, MDIO_MMD_PMAPMD,
854 PMA_PMD_SPEED_ENABLE_REG);
857 reg &= ~((1 << 2) | (1 << 3));
858 if (EFX_WORKAROUND_13204(efx) &&
859 (advertising & ADVERTISED_100baseT_Full))
860 reg |= 1 << PMA_PMD_100TX_ADV_LBN;
861 if (advertising & ADVERTISED_1000baseT_Full)
862 reg |= 1 << PMA_PMD_1000T_ADV_LBN;
863 if (advertising & ADVERTISED_10000baseT_Full)
864 reg |= 1 << PMA_PMD_10000T_ADV_LBN;
865 mdio_clause45_write(efx, phy, MDIO_MMD_PMAPMD,
866 PMA_PMD_SPEED_ENABLE_REG, reg);
868 enabled = (advertising &
869 (ADVERTISED_1000baseT_Half |
870 ADVERTISED_1000baseT_Full |
871 ADVERTISED_10000baseT_Full));
872 if (EFX_WORKAROUND_13204(efx))
873 enabled |= (advertising & ADVERTISED_100baseT_Full);
877 struct efx_phy_operations falcon_sfx7101_phy_ops = {
879 .init = tenxpress_phy_init,
880 .reconfigure = tenxpress_phy_reconfigure,
881 .poll = tenxpress_phy_poll,
882 .fini = tenxpress_phy_fini,
883 .clear_interrupt = efx_port_dummy_op_void,
884 .get_settings = sfx7101_get_settings,
885 .set_settings = mdio_clause45_set_settings,
886 .num_tests = ARRAY_SIZE(sfx7101_test_names),
887 .test_names = sfx7101_test_names,
888 .run_tests = sfx7101_run_tests,
889 .mmds = TENXPRESS_REQUIRED_DEVS,
890 .loopbacks = SFX7101_LOOPBACKS,
893 struct efx_phy_operations falcon_sft9001_phy_ops = {
894 .macs = EFX_GMAC | EFX_XMAC,
895 .init = tenxpress_phy_init,
896 .reconfigure = tenxpress_phy_reconfigure,
897 .poll = tenxpress_phy_poll,
898 .fini = tenxpress_phy_fini,
899 .clear_interrupt = efx_port_dummy_op_void,
900 .get_settings = sft9001_get_settings,
901 .set_settings = sft9001_set_settings,
902 .set_xnp_advertise = sft9001_set_xnp_advertise,
903 .num_tests = ARRAY_SIZE(sft9001_test_names),
904 .test_names = sft9001_test_names,
905 .run_tests = sft9001_run_tests,
906 .mmds = TENXPRESS_REQUIRED_DEVS,
907 .loopbacks = SFT9001_LOOPBACKS,