Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: introduce phydev->port

At the moment, PORT_MII is reported in the ethtool ops. This is odd
because it is an interface between the MAC and the PHY and no external
port. Some network card drivers will overwrite the port to twisted pair
or fiber, though. Even worse, the MDI/MDIX setting is only used by
ethtool if the port is twisted pair.

Set the port to PORT_TP by default because most PHY drivers are copper
ones. If there is fibre support and it is enabled, the PHY driver will
set it to PORT_FIBRE.

This will change reporting PORT_MII to either PORT_TP or PORT_FIBRE;
except for the genphy fallback driver.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michael Walle and committed by
David S. Miller
4217a64e e13e4536

+36 -4
+2
drivers/net/phy/broadcom.c
··· 410 410 */ 411 411 if (!(val & BCM54616S_100FX_MODE)) 412 412 phydev->dev_flags |= PHY_BCM_FLAGS_MODE_1000BX; 413 + 414 + phydev->port = PORT_FIBRE; 413 415 } 414 416 415 417 return 0;
+3
drivers/net/phy/dp83822.c
··· 554 554 555 555 dp83822_of_init(phydev); 556 556 557 + if (dp83822->fx_enabled) 558 + phydev->port = PORT_FIBRE; 559 + 557 560 return 0; 558 561 } 559 562
+4
drivers/net/phy/dp83869.c
··· 855 855 if (ret) 856 856 return ret; 857 857 858 + if (dp83869->mode == DP83869_RGMII_100_BASE || 859 + dp83869->mode == DP83869_RGMII_1000_BASE) 860 + phydev->port = PORT_FIBRE; 861 + 858 862 return dp83869_config_init(phydev); 859 863 } 860 864
+1
drivers/net/phy/lxt.c
··· 292 292 phy_write(phydev, MII_BMCR, val); 293 293 /* Remember that the port is in fiber mode. */ 294 294 phydev->priv = lxt973_probe; 295 + phydev->port = PORT_FIBRE; 295 296 } else { 296 297 phydev->priv = NULL; 297 298 }
+1
drivers/net/phy/marvell.c
··· 1552 1552 phydev->asym_pause = 0; 1553 1553 phydev->speed = SPEED_UNKNOWN; 1554 1554 phydev->duplex = DUPLEX_UNKNOWN; 1555 + phydev->port = fiber ? PORT_FIBRE : PORT_TP; 1555 1556 1556 1557 if (phydev->autoneg == AUTONEG_ENABLE) 1557 1558 err = marvell_read_status_page_an(phydev, fiber, status);
+2
drivers/net/phy/marvell10g.c
··· 631 631 phydev->link = 1; 632 632 phydev->speed = SPEED_10000; 633 633 phydev->duplex = DUPLEX_FULL; 634 + phydev->port = PORT_FIBRE; 634 635 635 636 return 0; 636 637 } ··· 691 690 692 691 phydev->duplex = cssr1 & MV_PCS_CSSR1_DUPLEX_FULL ? 693 692 DUPLEX_FULL : DUPLEX_HALF; 693 + phydev->port = PORT_TP; 694 694 phydev->mdix = cssr1 & MV_PCS_CSSR1_MDIX ? 695 695 ETH_TP_MDI_X : ETH_TP_MDI; 696 696
+11 -3
drivers/net/phy/micrel.c
··· 341 341 return kszphy_config_reset(phydev); 342 342 } 343 343 344 + static int ksz8041_fiber_mode(struct phy_device *phydev) 345 + { 346 + struct device_node *of_node = phydev->mdio.dev.of_node; 347 + 348 + return of_property_read_bool(of_node, "micrel,fiber-mode"); 349 + } 350 + 344 351 static int ksz8041_config_init(struct phy_device *phydev) 345 352 { 346 353 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 347 354 348 - struct device_node *of_node = phydev->mdio.dev.of_node; 349 - 350 355 /* Limit supported and advertised modes in fiber mode */ 351 - if (of_property_read_bool(of_node, "micrel,fiber-mode")) { 356 + if (ksz8041_fiber_mode(phydev)) { 352 357 phydev->dev_flags |= MICREL_PHY_FXEN; 353 358 linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, mask); 354 359 linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, mask); ··· 1180 1175 return -EINVAL; 1181 1176 } 1182 1177 } 1178 + 1179 + if (ksz8041_fiber_mode(phydev)) 1180 + phydev->port = PORT_FIBRE; 1183 1181 1184 1182 /* Support legacy board-file configuration */ 1185 1183 if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
+1 -1
drivers/net/phy/phy.c
··· 308 308 if (phydev->interface == PHY_INTERFACE_MODE_MOCA) 309 309 cmd->base.port = PORT_BNC; 310 310 else 311 - cmd->base.port = PORT_MII; 311 + cmd->base.port = phydev->port; 312 312 cmd->base.transceiver = phy_is_internal(phydev) ? 313 313 XCVR_INTERNAL : XCVR_EXTERNAL; 314 314 cmd->base.phy_address = phydev->mdio.addr;
+9
drivers/net/phy/phy_device.c
··· 606 606 dev->pause = 0; 607 607 dev->asym_pause = 0; 608 608 dev->link = 0; 609 + dev->port = PORT_TP; 609 610 dev->interface = PHY_INTERFACE_MODE_GMII; 610 611 611 612 dev->autoneg = AUTONEG_ENABLE; ··· 1403 1402 phydev->interface = interface; 1404 1403 1405 1404 phydev->state = PHY_READY; 1405 + 1406 + /* Port is set to PORT_TP by default and the actual PHY driver will set 1407 + * it to different value depending on the PHY configuration. If we have 1408 + * the generic PHY driver we can't figure it out, thus set the old 1409 + * legacy PORT_MII value. 1410 + */ 1411 + if (using_genphy) 1412 + phydev->port = PORT_MII; 1406 1413 1407 1414 /* Initial carrier state is off as the phy is about to be 1408 1415 * (re)initialized.
+2
include/linux/phy.h
··· 503 503 * 504 504 * @speed: Current link speed 505 505 * @duplex: Current duplex 506 + * @port: Current port 506 507 * @pause: Current pause 507 508 * @asym_pause: Current asymmetric pause 508 509 * @supported: Combined MAC/PHY supported linkmodes ··· 582 581 */ 583 582 int speed; 584 583 int duplex; 584 + int port; 585 585 int pause; 586 586 int asym_pause; 587 587 u8 master_slave_get;