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->loopback_mode == LOOPBACK_GPHY)
450 else if (efx_phy_mode_disabled(efx->phy_mode))
452 else if (efx->loopback_mode)
453 return mdio_clause45_links_ok(efx,
454 MDIO_MMDREG_DEVS_PMAPMD |
455 MDIO_MMDREG_DEVS_PCS |
456 MDIO_MMDREG_DEVS_PHYXS);
458 /* We must use the same definition of link state as LASI,
459 * otherwise we can miss a link state transition
461 if (ecmd->speed == 10000) {
462 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS,
464 return reg & (1 << PCS_10GBASET_BLKLK_LBN);
466 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
468 return reg & (1 << C22EXT_STATUS_LINK_LBN);
472 static void tenxpress_ext_loopback(struct efx_nic *efx)
474 int phy_id = efx->mii.phy_id;
476 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
477 PHYXS_TEST1, LOOPBACK_NEAR_LBN,
478 efx->loopback_mode == LOOPBACK_PHYXS);
479 if (efx->phy_type != PHY_TYPE_SFX7101)
480 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
482 GPHY_LOOPBACK_NEAR_LBN,
483 efx->loopback_mode == LOOPBACK_GPHY);
486 static void tenxpress_low_power(struct efx_nic *efx)
488 int phy_id = efx->mii.phy_id;
490 if (efx->phy_type == PHY_TYPE_SFX7101)
491 mdio_clause45_set_mmds_lpower(
492 efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
493 TENXPRESS_REQUIRED_DEVS);
495 mdio_clause45_set_flag(
496 efx, phy_id, MDIO_MMD_PMAPMD,
497 PMA_PMD_XCONTROL_REG, PMA_PMD_EXT_LPOWER_LBN,
498 !!(efx->phy_mode & PHY_MODE_LOW_POWER));
501 static void tenxpress_phy_reconfigure(struct efx_nic *efx)
503 struct tenxpress_phy_data *phy_data = efx->phy_data;
504 struct ethtool_cmd ecmd;
505 bool phy_mode_change, loop_reset, loop_toggle, loopback;
507 if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
508 phy_data->phy_mode = efx->phy_mode;
512 tenxpress_low_power(efx);
514 phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
515 phy_data->phy_mode != PHY_MODE_NORMAL);
516 loopback = LOOPBACK_MASK(efx) & efx->phy_op->loopbacks;
517 loop_toggle = LOOPBACK_CHANGED(phy_data, efx, efx->phy_op->loopbacks);
518 loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
519 LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
521 if (loop_reset || loop_toggle || loopback || phy_mode_change) {
524 efx->phy_op->get_settings(efx, &ecmd);
526 if (loop_reset || phy_mode_change) {
527 tenxpress_special_reset(efx);
529 /* Reset XAUI if we were in 10G, and are staying
530 * in 10G. If we're moving into and out of 10G
531 * then xaui will be reset anyway */
533 falcon_reset_xaui(efx);
536 if (efx->phy_type != PHY_TYPE_SFX7101) {
537 /* Only change autoneg once, on coming out or
538 * going into loopback */
540 ecmd.autoneg = !loopback;
542 ecmd.duplex = DUPLEX_FULL;
543 if (efx->loopback_mode == LOOPBACK_GPHY)
544 ecmd.speed = SPEED_1000;
546 ecmd.speed = SPEED_10000;
550 rc = efx->phy_op->set_settings(efx, &ecmd);
554 mdio_clause45_transmit_disable(efx);
555 mdio_clause45_phy_reconfigure(efx);
556 tenxpress_ext_loopback(efx);
558 phy_data->loopback_mode = efx->loopback_mode;
559 phy_data->phy_mode = efx->phy_mode;
561 if (efx->phy_type == PHY_TYPE_SFX7101) {
562 efx->link_speed = 10000;
564 efx->link_up = sfx7101_link_ok(efx);
566 efx->phy_op->get_settings(efx, &ecmd);
567 efx->link_speed = ecmd.speed;
568 efx->link_fd = ecmd.duplex == DUPLEX_FULL;
569 efx->link_up = sft9001_link_ok(efx, &ecmd);
571 efx->link_fc = mdio_clause45_get_pause(efx);
574 /* Poll PHY for interrupt */
575 static void tenxpress_phy_poll(struct efx_nic *efx)
577 struct tenxpress_phy_data *phy_data = efx->phy_data;
578 bool change = false, link_ok;
581 if (efx->phy_type == PHY_TYPE_SFX7101) {
582 link_ok = sfx7101_link_ok(efx);
583 if (link_ok != efx->link_up) {
586 link_fc = mdio_clause45_get_pause(efx);
587 if (link_fc != efx->link_fc)
590 sfx7101_check_bad_lp(efx, link_ok);
592 u32 status = mdio_clause45_read(efx, efx->mii.phy_id,
594 PMA_PMD_LASI_STATUS);
595 if (status & (1 << PMA_PMD_LS_ALARM_LBN))
600 falcon_sim_phy_event(efx);
602 if (phy_data->phy_mode != PHY_MODE_NORMAL)
605 if (EFX_WORKAROUND_10750(efx) &&
606 atomic_read(&phy_data->bad_crc_count) > crc_error_reset_threshold) {
607 EFX_ERR(efx, "Resetting XAUI due to too many CRC errors\n");
608 falcon_reset_xaui(efx);
609 atomic_set(&phy_data->bad_crc_count, 0);
613 static void tenxpress_phy_fini(struct efx_nic *efx)
617 if (efx->phy_type == PHY_TYPE_SFT9001B) {
618 device_remove_file(&efx->pci_dev->dev,
619 &dev_attr_phy_short_reach);
621 /* Power down the LNPGA */
622 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
623 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
624 PMA_PMD_XCONTROL_REG, reg);
626 /* Waiting here ensures that the board fini, which can turn
627 * off the power to the PHY, won't get run until the LNPGA
628 * powerdown has been given long enough to complete. */
629 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
632 kfree(efx->phy_data);
633 efx->phy_data = NULL;
637 /* Set the RX and TX LEDs and Link LED flashing. The other LEDs
638 * (which probably aren't wired anyway) are left in AUTO mode */
639 void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
644 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
645 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
646 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
648 reg = PMA_PMD_LED_DEFAULT;
650 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
651 PMA_PMD_LED_OVERR_REG, reg);
654 static int tenxpress_phy_test(struct efx_nic *efx)
656 /* BIST is automatically run after a special software reset */
657 return tenxpress_special_reset(efx);
660 static u32 tenxpress_get_xnp_lpa(struct efx_nic *efx)
662 int phy = efx->mii.phy_id;
666 if (efx->phy_type != PHY_TYPE_SFX7101) {
667 reg = mdio_clause45_read(efx, phy, MDIO_MMD_C22EXT,
669 if (reg & (1 << C22EXT_MSTSLV_1000_HD_LBN))
670 lpa |= ADVERTISED_1000baseT_Half;
671 if (reg & (1 << C22EXT_MSTSLV_1000_FD_LBN))
672 lpa |= ADVERTISED_1000baseT_Full;
674 reg = mdio_clause45_read(efx, phy, MDIO_MMD_AN, MDIO_AN_10GBT_STATUS);
675 if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN))
676 lpa |= ADVERTISED_10000baseT_Full;
680 static void sfx7101_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
682 mdio_clause45_get_settings_ext(efx, ecmd, ADVERTISED_10000baseT_Full,
683 tenxpress_get_xnp_lpa(efx));
684 ecmd->supported |= SUPPORTED_10000baseT_Full;
685 ecmd->advertising |= ADVERTISED_10000baseT_Full;
688 static void sft9001_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
690 int phy_id = efx->mii.phy_id;
694 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
695 PMA_PMD_SPEED_ENABLE_REG);
696 if (EFX_WORKAROUND_13204(efx) && (reg & (1 << PMA_PMD_100TX_ADV_LBN)))
697 xnp_adv |= ADVERTISED_100baseT_Full;
698 if (reg & (1 << PMA_PMD_1000T_ADV_LBN))
699 xnp_adv |= ADVERTISED_1000baseT_Full;
700 if (reg & (1 << PMA_PMD_10000T_ADV_LBN))
701 xnp_adv |= ADVERTISED_10000baseT_Full;
703 mdio_clause45_get_settings_ext(efx, ecmd, xnp_adv,
704 tenxpress_get_xnp_lpa(efx));
706 ecmd->supported |= (SUPPORTED_100baseT_Half |
707 SUPPORTED_100baseT_Full |
708 SUPPORTED_1000baseT_Full);
710 /* Use the vendor defined C22ext register for duplex settings */
711 if (ecmd->speed != SPEED_10000 && !ecmd->autoneg) {
712 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
714 ecmd->duplex = (reg & (1 << GPHY_DUPLEX_LBN) ?
715 DUPLEX_FULL : DUPLEX_HALF);
719 static int sft9001_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
721 int phy_id = efx->mii.phy_id;
724 rc = mdio_clause45_set_settings(efx, ecmd);
728 if (ecmd->speed != SPEED_10000 && !ecmd->autoneg)
729 mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
730 GPHY_XCONTROL_REG, GPHY_DUPLEX_LBN,
731 ecmd->duplex == DUPLEX_FULL);
736 static bool sft9001_set_xnp_advertise(struct efx_nic *efx, u32 advertising)
738 int phy = efx->mii.phy_id;
739 int reg = mdio_clause45_read(efx, phy, MDIO_MMD_PMAPMD,
740 PMA_PMD_SPEED_ENABLE_REG);
743 reg &= ~((1 << 2) | (1 << 3));
744 if (EFX_WORKAROUND_13204(efx) &&
745 (advertising & ADVERTISED_100baseT_Full))
746 reg |= 1 << PMA_PMD_100TX_ADV_LBN;
747 if (advertising & ADVERTISED_1000baseT_Full)
748 reg |= 1 << PMA_PMD_1000T_ADV_LBN;
749 if (advertising & ADVERTISED_10000baseT_Full)
750 reg |= 1 << PMA_PMD_10000T_ADV_LBN;
751 mdio_clause45_write(efx, phy, MDIO_MMD_PMAPMD,
752 PMA_PMD_SPEED_ENABLE_REG, reg);
754 enabled = (advertising &
755 (ADVERTISED_1000baseT_Half |
756 ADVERTISED_1000baseT_Full |
757 ADVERTISED_10000baseT_Full));
758 if (EFX_WORKAROUND_13204(efx))
759 enabled |= (advertising & ADVERTISED_100baseT_Full);
763 struct efx_phy_operations falcon_sfx7101_phy_ops = {
765 .init = tenxpress_phy_init,
766 .reconfigure = tenxpress_phy_reconfigure,
767 .poll = tenxpress_phy_poll,
768 .fini = tenxpress_phy_fini,
769 .clear_interrupt = efx_port_dummy_op_void,
770 .test = tenxpress_phy_test,
771 .get_settings = sfx7101_get_settings,
772 .set_settings = mdio_clause45_set_settings,
773 .mmds = TENXPRESS_REQUIRED_DEVS,
774 .loopbacks = SFX7101_LOOPBACKS,
777 struct efx_phy_operations falcon_sft9001_phy_ops = {
778 .macs = EFX_GMAC | EFX_XMAC,
779 .init = tenxpress_phy_init,
780 .reconfigure = tenxpress_phy_reconfigure,
781 .poll = tenxpress_phy_poll,
782 .fini = tenxpress_phy_fini,
783 .clear_interrupt = efx_port_dummy_op_void,
784 .test = tenxpress_phy_test,
785 .get_settings = sft9001_get_settings,
786 .set_settings = sft9001_set_settings,
787 .set_xnp_advertise = sft9001_set_xnp_advertise,
788 .mmds = TENXPRESS_REQUIRED_DEVS,
789 .loopbacks = SFT9001_LOOPBACKS,