ipq40xx: net: ethernet: edma: use generic ksettings functions
authorRobert Marko <robert.marko@sartura.hr>
Thu, 26 Nov 2020 12:41:54 +0000 (13:41 +0100)
committerPetr Štetiar <ynezz@true.cz>
Wed, 23 Dec 2020 15:36:08 +0000 (16:36 +0100)
Since we now have a proper PHY driver for QCA807x and AR803x has already
been supported properly there is no need for the driver to be poking
on PHY registers for ethtool ops.

So, lets simply use the generic
phy_ethtool_ksettings_get/phy_ethtool_ksettings_set functions.

This also has the advantage of properly populating stuff other than
speeds like, transceiver type, MDI-X etc.

ethtool before:
root@OpenWrt:/# ethtool eth1
Settings for eth1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
                                1000baseX/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
                                1000baseX/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
                                             1000baseT/Full
        Link partner advertised pause frame use: No
        Link partner advertised auto-negotiation: No
        Link partner advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 4
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: d
        Wake-on: d
        Current message level: 0x00000000 (0)

        Link detected: yes

ethtool after:
root@OpenWrt:/# ethtool eth1
Settings for eth1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
                                1000baseX/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
                                1000baseX/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
                                             1000baseT/Full
        Link partner advertised pause frame use: Symmetric Receive-only
        Link partner advertised auto-negotiation: Yes
        Link partner advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 4
        Transceiver: external
        Auto-negotiation: on
        MDI-X: off (auto)
        Supports Wake-on: d
        Wake-on: d
        Current message level: 0x00000000 (0)

        Link detected: yes

Signed-off-by: Robert Marko <robert.marko@sartura.hr>
target/linux/ipq40xx/files/drivers/net/ethernet/qualcomm/essedma/edma_ethtool.c

index 1270e20a90cc115f097fd40b675808913701c407..ac5cb50961e409308e3880efc7fb31979b9abb97 100644 (file)
@@ -186,55 +186,15 @@ static int edma_get_settings(struct net_device *netdev,
        struct edma_adapter *adapter = netdev_priv(netdev);
 
        if (adapter->poll_required) {
-               struct phy_device *phydev = NULL;
-               uint16_t phyreg;
-
                if ((adapter->forced_speed != SPEED_UNKNOWN)
                        && !(adapter->poll_required))
                        return -EPERM;
 
-               phydev = adapter->phydev;
-
-               linkmode_copy(cmd->link_modes.advertising, phydev->advertising);
-               linkmode_copy(cmd->link_modes.supported, phydev->supported);
-
-               cmd->base.autoneg = phydev->autoneg;
-
-               if (adapter->link_state == __EDMA_LINKDOWN) {
-                       cmd->base.speed =  SPEED_UNKNOWN;
-                       cmd->base.duplex = DUPLEX_UNKNOWN;
-               } else {
-                       cmd->base.speed = phydev->speed;
-                       cmd->base.duplex = phydev->duplex;
-               }
-
-               cmd->base.phy_address = adapter->phy_mdio_addr;
-
-               phyreg = (uint16_t)phy_read(adapter->phydev, MII_LPA);
-               if (phyreg & LPA_10HALF)
-                       linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, 
-                                                               cmd->link_modes.lp_advertising);
-
-               if (phyreg & LPA_10FULL)
-                       linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, 
-                                                               cmd->link_modes.lp_advertising);
-
-               if (phyreg & LPA_100HALF)
-                       linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, 
-                                                               cmd->link_modes.lp_advertising);
-
-               if (phyreg & LPA_100FULL)
-                       linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, 
-                                                               cmd->link_modes.lp_advertising);
-
-               phyreg = (uint16_t)phy_read(adapter->phydev, MII_STAT1000);
-               if (phyreg & LPA_1000HALF)
-                       linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, 
-                                                               cmd->link_modes.lp_advertising);
-
-               if (phyreg & LPA_1000FULL)
-                       linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, 
-                                                               cmd->link_modes.lp_advertising);
+               phy_ethtool_ksettings_get(adapter->phydev, cmd);
+               if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, adapter->phydev->advertising))
+                       cmd->base.port = PORT_FIBRE;
+               else
+                       cmd->base.port = PORT_TP;
        } else {
                /* If the speed/duplex for this GMAC is forced and we
                 * are not polling for link state changes, return the
@@ -272,22 +232,12 @@ static int edma_set_settings(struct net_device *netdev,
                            const struct ethtool_link_ksettings *cmd)
 {
        struct edma_adapter *adapter = netdev_priv(netdev);
-       struct phy_device *phydev = NULL;
 
        if ((adapter->forced_speed != SPEED_UNKNOWN) &&
             !adapter->poll_required)
                return -EPERM;
 
-       phydev = adapter->phydev;
-       linkmode_copy(phydev->advertising, cmd->link_modes.advertising);
-       linkmode_copy(phydev->supported, cmd->link_modes.supported);
-       phydev->autoneg = cmd->base.autoneg;
-       phydev->speed = cmd->base.speed;
-       phydev->duplex = cmd->base.duplex;
-
-       genphy_config_aneg(phydev);
-
-       return 0;
+       return phy_ethtool_ksettings_set(adapter->phydev, cmd);
 }
 
 /* edma_get_coalesce