net: lan743x: Add support to ethtool phylink get and set settings
Add support to ethtool phylink functions: - get/set settings like speed, duplex etc - get/set the wake-on-lan (WOL) - get/set the energy-efficient ethernet (EEE) - get/set the pause Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a5f199a8d8
commit
f95f28d794
|
@ -1054,61 +1054,55 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev,
|
||||||
struct ethtool_keee *eee)
|
struct ethtool_keee *eee)
|
||||||
{
|
{
|
||||||
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
||||||
struct phy_device *phydev = netdev->phydev;
|
|
||||||
u32 buf;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!phydev)
|
eee->tx_lpi_timer = lan743x_csr_read(adapter,
|
||||||
return -EIO;
|
MAC_EEE_TX_LPI_REQ_DLY_CNT);
|
||||||
if (!phydev->drv) {
|
|
||||||
netif_err(adapter, drv, adapter->netdev,
|
|
||||||
"Missing PHY Driver\n");
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = phy_ethtool_get_eee(phydev, eee);
|
return phylink_ethtool_get_eee(adapter->phylink, eee);
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
buf = lan743x_csr_read(adapter, MAC_CR);
|
|
||||||
if (buf & MAC_CR_EEE_EN_) {
|
|
||||||
/* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */
|
|
||||||
buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
|
|
||||||
eee->tx_lpi_timer = buf;
|
|
||||||
} else {
|
|
||||||
eee->tx_lpi_timer = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lan743x_ethtool_set_eee(struct net_device *netdev,
|
static int lan743x_ethtool_set_eee(struct net_device *netdev,
|
||||||
struct ethtool_keee *eee)
|
struct ethtool_keee *eee)
|
||||||
{
|
{
|
||||||
struct lan743x_adapter *adapter;
|
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
||||||
struct phy_device *phydev;
|
u32 tx_lpi_timer;
|
||||||
u32 buf = 0;
|
|
||||||
|
|
||||||
if (!netdev)
|
tx_lpi_timer = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
|
||||||
return -EINVAL;
|
if (tx_lpi_timer != eee->tx_lpi_timer) {
|
||||||
adapter = netdev_priv(netdev);
|
u32 mac_cr = lan743x_csr_read(adapter, MAC_CR);
|
||||||
if (!adapter)
|
|
||||||
return -EINVAL;
|
/* Software should only change this field when Energy Efficient
|
||||||
phydev = netdev->phydev;
|
* Ethernet Enable (EEEEN) is cleared.
|
||||||
if (!phydev)
|
* This function will trigger an autonegotiation restart and
|
||||||
return -EIO;
|
* eee will be reenabled during link up if eee was negotiated.
|
||||||
if (!phydev->drv) {
|
*/
|
||||||
netif_err(adapter, drv, adapter->netdev,
|
lan743x_mac_eee_enable(adapter, false);
|
||||||
"Missing PHY Driver\n");
|
lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,
|
||||||
return -EIO;
|
eee->tx_lpi_timer);
|
||||||
|
|
||||||
|
if (mac_cr & MAC_CR_EEE_EN_)
|
||||||
|
lan743x_mac_eee_enable(adapter, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eee->eee_enabled) {
|
return phylink_ethtool_set_eee(adapter->phylink, eee);
|
||||||
buf = (u32)eee->tx_lpi_timer;
|
|
||||||
lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return phy_ethtool_set_eee(phydev, eee);
|
static int
|
||||||
|
lan743x_ethtool_set_link_ksettings(struct net_device *netdev,
|
||||||
|
const struct ethtool_link_ksettings *cmd)
|
||||||
|
{
|
||||||
|
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
||||||
|
|
||||||
|
return phylink_ethtool_ksettings_set(adapter->phylink, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
lan743x_ethtool_get_link_ksettings(struct net_device *netdev,
|
||||||
|
struct ethtool_link_ksettings *cmd)
|
||||||
|
{
|
||||||
|
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
||||||
|
|
||||||
|
return phylink_ethtool_ksettings_get(adapter->phylink, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_PM
|
#ifdef CONFIG_PM
|
||||||
|
@ -1120,8 +1114,7 @@ static void lan743x_ethtool_get_wol(struct net_device *netdev,
|
||||||
wol->supported = 0;
|
wol->supported = 0;
|
||||||
wol->wolopts = 0;
|
wol->wolopts = 0;
|
||||||
|
|
||||||
if (netdev->phydev)
|
phylink_ethtool_get_wol(adapter->phylink, wol);
|
||||||
phy_ethtool_get_wol(netdev->phydev, wol);
|
|
||||||
|
|
||||||
if (wol->supported != adapter->phy_wol_supported)
|
if (wol->supported != adapter->phy_wol_supported)
|
||||||
netif_warn(adapter, drv, adapter->netdev,
|
netif_warn(adapter, drv, adapter->netdev,
|
||||||
|
@ -1162,7 +1155,7 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
|
||||||
!(adapter->phy_wol_supported & WAKE_MAGICSECURE))
|
!(adapter->phy_wol_supported & WAKE_MAGICSECURE))
|
||||||
phy_wol.wolopts &= ~WAKE_MAGIC;
|
phy_wol.wolopts &= ~WAKE_MAGIC;
|
||||||
|
|
||||||
ret = phy_ethtool_set_wol(netdev->phydev, &phy_wol);
|
ret = phylink_ethtool_set_wol(adapter->phylink, wol);
|
||||||
if (ret && (ret != -EOPNOTSUPP))
|
if (ret && (ret != -EOPNOTSUPP))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -1351,44 +1344,16 @@ static void lan743x_get_pauseparam(struct net_device *dev,
|
||||||
struct ethtool_pauseparam *pause)
|
struct ethtool_pauseparam *pause)
|
||||||
{
|
{
|
||||||
struct lan743x_adapter *adapter = netdev_priv(dev);
|
struct lan743x_adapter *adapter = netdev_priv(dev);
|
||||||
struct lan743x_phy *phy = &adapter->phy;
|
|
||||||
|
|
||||||
if (phy->fc_request_control & FLOW_CTRL_TX)
|
phylink_ethtool_get_pauseparam(adapter->phylink, pause);
|
||||||
pause->tx_pause = 1;
|
|
||||||
if (phy->fc_request_control & FLOW_CTRL_RX)
|
|
||||||
pause->rx_pause = 1;
|
|
||||||
pause->autoneg = phy->fc_autoneg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lan743x_set_pauseparam(struct net_device *dev,
|
static int lan743x_set_pauseparam(struct net_device *dev,
|
||||||
struct ethtool_pauseparam *pause)
|
struct ethtool_pauseparam *pause)
|
||||||
{
|
{
|
||||||
struct lan743x_adapter *adapter = netdev_priv(dev);
|
struct lan743x_adapter *adapter = netdev_priv(dev);
|
||||||
struct phy_device *phydev = dev->phydev;
|
|
||||||
struct lan743x_phy *phy = &adapter->phy;
|
|
||||||
|
|
||||||
if (!phydev)
|
return phylink_ethtool_set_pauseparam(adapter->phylink, pause);
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (!phy_validate_pause(phydev, pause))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
phy->fc_request_control = 0;
|
|
||||||
if (pause->rx_pause)
|
|
||||||
phy->fc_request_control |= FLOW_CTRL_RX;
|
|
||||||
|
|
||||||
if (pause->tx_pause)
|
|
||||||
phy->fc_request_control |= FLOW_CTRL_TX;
|
|
||||||
|
|
||||||
phy->fc_autoneg = pause->autoneg;
|
|
||||||
|
|
||||||
if (pause->autoneg == AUTONEG_DISABLE)
|
|
||||||
lan743x_mac_flow_ctrl_set_enables(adapter, pause->tx_pause,
|
|
||||||
pause->rx_pause);
|
|
||||||
else
|
|
||||||
phy_set_asym_pause(phydev, pause->rx_pause, pause->tx_pause);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct ethtool_ops lan743x_ethtool_ops = {
|
const struct ethtool_ops lan743x_ethtool_ops = {
|
||||||
|
@ -1413,8 +1378,8 @@ const struct ethtool_ops lan743x_ethtool_ops = {
|
||||||
.get_ts_info = lan743x_ethtool_get_ts_info,
|
.get_ts_info = lan743x_ethtool_get_ts_info,
|
||||||
.get_eee = lan743x_ethtool_get_eee,
|
.get_eee = lan743x_ethtool_get_eee,
|
||||||
.set_eee = lan743x_ethtool_set_eee,
|
.set_eee = lan743x_ethtool_set_eee,
|
||||||
.get_link_ksettings = phy_ethtool_get_link_ksettings,
|
.get_link_ksettings = lan743x_ethtool_get_link_ksettings,
|
||||||
.set_link_ksettings = phy_ethtool_set_link_ksettings,
|
.set_link_ksettings = lan743x_ethtool_set_link_ksettings,
|
||||||
.get_regs_len = lan743x_get_regs_len,
|
.get_regs_len = lan743x_get_regs_len,
|
||||||
.get_regs = lan743x_get_regs,
|
.get_regs = lan743x_get_regs,
|
||||||
.get_pauseparam = lan743x_get_pauseparam,
|
.get_pauseparam = lan743x_get_pauseparam,
|
||||||
|
|
|
@ -2966,6 +2966,18 @@ static int lan743x_phylink_2500basex_config(struct lan743x_adapter *adapter)
|
||||||
return lan743x_pcs_power_reset(adapter);
|
return lan743x_pcs_power_reset(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lan743x_mac_eee_enable(struct lan743x_adapter *adapter, bool enable)
|
||||||
|
{
|
||||||
|
u32 mac_cr;
|
||||||
|
|
||||||
|
mac_cr = lan743x_csr_read(adapter, MAC_CR);
|
||||||
|
if (enable)
|
||||||
|
mac_cr |= MAC_CR_EEE_EN_;
|
||||||
|
else
|
||||||
|
mac_cr &= ~MAC_CR_EEE_EN_;
|
||||||
|
lan743x_csr_write(adapter, MAC_CR, mac_cr);
|
||||||
|
}
|
||||||
|
|
||||||
static void lan743x_phylink_mac_config(struct phylink_config *config,
|
static void lan743x_phylink_mac_config(struct phylink_config *config,
|
||||||
unsigned int link_an_mode,
|
unsigned int link_an_mode,
|
||||||
const struct phylink_link_state *state)
|
const struct phylink_link_state *state)
|
||||||
|
@ -3014,7 +3026,11 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config,
|
||||||
unsigned int link_an_mode,
|
unsigned int link_an_mode,
|
||||||
phy_interface_t interface)
|
phy_interface_t interface)
|
||||||
{
|
{
|
||||||
|
struct net_device *netdev = to_net_dev(config->dev);
|
||||||
|
struct lan743x_adapter *adapter = netdev_priv(netdev);
|
||||||
|
|
||||||
netif_tx_stop_all_queues(to_net_dev(config->dev));
|
netif_tx_stop_all_queues(to_net_dev(config->dev));
|
||||||
|
lan743x_mac_eee_enable(adapter, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lan743x_phylink_mac_link_up(struct phylink_config *config,
|
static void lan743x_phylink_mac_link_up(struct phylink_config *config,
|
||||||
|
@ -3056,6 +3072,9 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
|
||||||
cap & FLOW_CTRL_TX,
|
cap & FLOW_CTRL_TX,
|
||||||
cap & FLOW_CTRL_RX);
|
cap & FLOW_CTRL_RX);
|
||||||
|
|
||||||
|
if (phydev)
|
||||||
|
lan743x_mac_eee_enable(adapter, phydev->enable_tx_lpi);
|
||||||
|
|
||||||
netif_tx_wake_all_queues(netdev);
|
netif_tx_wake_all_queues(netdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3239,6 +3258,9 @@ static int lan743x_netdev_open(struct net_device *netdev)
|
||||||
goto close_tx;
|
goto close_tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (netdev->phydev)
|
||||||
|
phy_support_eee(netdev->phydev);
|
||||||
|
|
||||||
#ifdef CONFIG_PM
|
#ifdef CONFIG_PM
|
||||||
if (adapter->netdev->phydev) {
|
if (adapter->netdev->phydev) {
|
||||||
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
|
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
|
||||||
|
|
|
@ -1206,5 +1206,6 @@ void lan743x_hs_syslock_release(struct lan743x_adapter *adapter);
|
||||||
void lan743x_mac_flow_ctrl_set_enables(struct lan743x_adapter *adapter,
|
void lan743x_mac_flow_ctrl_set_enables(struct lan743x_adapter *adapter,
|
||||||
bool tx_enable, bool rx_enable);
|
bool tx_enable, bool rx_enable);
|
||||||
int lan743x_sgmii_read(struct lan743x_adapter *adapter, u8 mmd, u16 addr);
|
int lan743x_sgmii_read(struct lan743x_adapter *adapter, u8 mmd, u16 addr);
|
||||||
|
void lan743x_mac_eee_enable(struct lan743x_adapter *adapter, bool enable);
|
||||||
|
|
||||||
#endif /* _LAN743X_H */
|
#endif /* _LAN743X_H */
|
||||||
|
|
Loading…
Reference in New Issue